Here you can find the source of deflate(String inString)
Parameter | Description |
---|---|
inString | the String to deflate |
public static byte[] deflate(String inString) throws IOException
//package com.java2s; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.zip.Deflater; public class Main { /**// w w w . j a va 2s .c o m * */ protected static final int IO_BUFFER_SIZE = 4 * 1024; /** * Applies a standard deflate algo to the input String * @param inString the String to deflate * @return the deflated byte array * */ public static byte[] deflate(String inString) throws IOException { Deflater deflater = new Deflater(Deflater.DEFAULT_COMPRESSION, true); byte[] inBytes = inString.getBytes("UTF-8"); deflater.setInput(inBytes); ByteArrayOutputStream outputStream = new ByteArrayOutputStream( inBytes.length); deflater.finish(); byte[] buffer = new byte[IO_BUFFER_SIZE]; while (!deflater.finished()) { int count = deflater.deflate(buffer); // returns the generated code... index outputStream.write(buffer, 0, count); } outputStream.close(); byte[] output = outputStream.toByteArray(); return output; } }