credentialProvider/src/main/java/nl/nn/credentialprovider/util/Misc.java
/**
	 *  Compresses the input string using the Deflater class of Java.
	 *<p>
	 *     Example:
	 *     <pre>
	 *         String s = "#!@#$#!@#$#!@#$#!@#$#!@#$#!@#$#!@#$#!@#$#!@#$#!@#$#!@#$#!@#$#!@#$#!@#$#!@#$#!@#$#!@#$#!@#$#!@#$#!@#$#!@#$#!@#$#!@#$#!@#$";
	 *         byte[] compressedSymbols = Misc.compress(s);
	 *         assertTrue(compressedSymbols.length < s1.length()); // will assertTrue as compressed one's length should be less than the normal string. However, this may not be the case for shorter strings.
	 *     </pre>
	 * </p>
	 */
Compresses the input string using the Deflater class of Java.
Compresses the input string using the Deflater class of Java .
public static byte[] compress(byte[] input) throws IOException {
		Deflater compressor = new Deflater();
		compressor.setLevel(Deflater.BEST_COMPRESSION);
		compressor.setInput(input);
		compressor.finish();
		ByteArrayOutputStream bos = new ByteArrayOutputStream(input.length);
		byte[] buf = new byte[1024];
		while (!compressor.finished()) {
			int count = compressor.deflate(buf);
			bos.write(buf, 0, count);
		}
		bos.close();
		return bos.toByteArray();
	}
public static byte [ ] compress ( byte [ ] input ) throws IOException { Deflater compressor = new Deflater ( ) ; compressor . setLevel ( Deflater . BEST_COMPRESSION ) ; compressor . setInput ( input ) ; compressor . finish ( ) ; ByteArrayOutputStream bos = new ByteArrayOutputStream ( input . length ) ; byte [ ] buf = new byte [ 1024 ] ; while ( ! compressor . finished ( ) ) { int count = compressor . deflate ( buf ) ; bos . write ( buf , 0 , count ) ; } bos . close ( ) ; return bos . toByteArray ( ) ; }
Compresses the input string using the Deflater class of Java.
Compresses the input string using the Deflater class of Java .
// Create the compressor with highest level of compression // Give the compressor the data to compress // Create an expandable byte array to hold the compressed data. // You cannot use an array that's the same size as the orginal because // there is no guarantee that the compressed data will be smaller than // the uncompressed data. // Compress the data // Get the compressed data