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 ( ) ) ; }
Compresses given Packet . Note that this can increase the total size when used incorrectly