code: public static Packet compress(final Packet packet) throws IOException
      {
          final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
          final GZIPOutputStream gzipOutputStream = new GZIPOutputStream(byteArrayOutputStream)
          {
              {
                  def.setLevel(Deflater.BEST_COMPRESSION);
              }
          };
  
          // Deflate all data
          gzipOutputStream.write(packet.getData());
          gzipOutputStream.close();
  
          return new Packet(
                  packet.getPacketType(),
                  packet.getPacketID(),
                  byteArrayOutputStream.toByteArray()
          );
      }
docs: Compresses given Packet. Note that this can increase the total size when used incorrectly
  @param packet Packet to compress
  @return Compressed Packet
  @throws IOException when unable to compress