@ Nonnull @ Weight ( Weight . Unit . VARIABLE ) public static byte [ ] packData ( @ Nonnull final byte [ ] data ) { final Deflater compressor = new Deflater ( Deflater . BEST_COMPRESSION ) ; compressor . setInput ( Assertions . assertNotNull ( data ) ) ; compressor . finish ( ) ; final ByteArrayOutputStream resultData = new ByteArrayOutputStream ( data . length + 100 ) ; final byte [ ] buffer = new byte [ 1024 ] ; while ( ! compressor . finished ( ) ) { resultData . write ( buffer , 0 , compressor . deflate ( buffer ) ) ; } return resultData . toByteArray ( ) ; }
Pack some binary data .