List of usage examples for java.util.zip Inflater setInput
public void setInput(ByteBuffer input)
From source file:Main.java
public static void main(String[] argv) throws Exception { byte[] compressedData = null; Inflater decompressor = new Inflater(); decompressor.setInput(compressedData); ByteArrayOutputStream bos = new ByteArrayOutputStream(compressedData.length); byte[] buf = new byte[1024]; while (!decompressor.finished()) { int count = decompressor.inflate(buf); bos.write(buf, 0, count);/*from w w w.j av a 2 s . c o m*/ } bos.close(); byte[] decompressedData = bos.toByteArray(); }
From source file:Main.java
public static void main(String[] args) throws Exception { // main method // Encode a String into bytes String inputString = "this is a test"; byte[] input = inputString.getBytes("UTF-8"); // Compress the bytes byte[] output1 = new byte[input.length]; Deflater compresser = new Deflater(); compresser.setInput(input);//from w w w .jav a 2 s .com compresser.finish(); int compressedDataLength = compresser.deflate(output1); compresser.end(); String str = new String(Base64.getEncoder().encode(output1)); System.out.println("Deflated String:" + str); byte[] output2 = Base64.getDecoder().decode(str); // Decompress the bytes Inflater decompresser = new Inflater(); decompresser.setInput(output2); byte[] result = str.getBytes(); int resultLength = decompresser.inflate(result); decompresser.end(); // Decode the bytes into a String String outputString = new String(result, 0, resultLength, "UTF-8"); System.out.println("Deflated String:" + outputString); }
From source file:Main.java
public static void main(String[] argv) throws Exception { byte[] input = "this is a test".getBytes(); Deflater compressor = new Deflater(); compressor.setLevel(Deflater.BEST_COMPRESSION); compressor.setInput(input);/*from ww w . j ava 2 s . c o m*/ 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(); byte[] compressedData = bos.toByteArray(); Inflater decompressor = new Inflater(); decompressor.setInput(compressedData); bos = new ByteArrayOutputStream(compressedData.length); buf = new byte[1024]; while (!decompressor.finished()) { int count = decompressor.inflate(buf); bos.write(buf, 0, count); } bos.close(); byte[] decompressedData = bos.toByteArray(); System.out.println(new String(decompressedData)); }
From source file:net.awl.edoc.pdfa.compression.FlateDecode.java
public static void main(String[] args) throws Exception { Inflater inf = new Inflater(false); File f = new File("resources/content_2_0.ufd"); FileInputStream fis = new FileInputStream(f); ByteArrayOutputStream baos = new ByteArrayOutputStream(); IOUtils.copy(fis, baos);/*w w w .java 2 s .c o m*/ IOUtils.closeQuietly(fis); IOUtils.closeQuietly(baos); byte[] buf = baos.toByteArray(); inf.setInput(buf); byte[] res = new byte[buf.length]; int size = inf.inflate(res); String s = new String(res, 0, size, "utf8"); System.err.println(s); }
From source file:Main.java
public static byte[] decompress(byte[] input, boolean GZIPFormat) throws IOException, DataFormatException { Inflater decompressor = new Inflater(GZIPFormat); decompressor.setInput(input); ByteArrayOutputStream bao = new ByteArrayOutputStream(); byte[] readBuffer = new byte[1024]; int readCount = 0; while (!decompressor.finished()) { readCount = decompressor.inflate(readBuffer); if (readCount > 0) { bao.write(readBuffer, 0, readCount); }/* www. j a v a 2 s . c o m*/ } decompressor.end(); return bao.toByteArray(); }
From source file:Main.java
public static String uncompress(byte[] data) throws IOException, DataFormatException { Inflater inflater = new Inflater(); inflater.setInput(data); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(data.length); byte[] buffer = new byte[1024]; while (!inflater.finished()) { int count = inflater.inflate(buffer); outputStream.write(buffer, 0, count); }/* w w w .ja va 2s.co m*/ outputStream.close(); byte[] output = outputStream.toByteArray(); // Decode the bytes into a String return new String(output, 0, output.length, "UTF-8"); }
From source file:Main.java
public static byte[] decompress(byte[] data) throws IOException, DataFormatException { Inflater inflater = new Inflater(); inflater.setInput(data); inflater.finished();//from www .j av a2 s.c om ByteArrayOutputStream outputStream = new ByteArrayOutputStream(data.length); byte[] buffer = new byte[1024]; while (!inflater.finished()) { int count = inflater.inflate(buffer); outputStream.write(buffer, 0, count); } outputStream.close(); byte[] output = outputStream.toByteArray(); inflater.end(); return output; }
From source file:Main.java
public static byte[] decompress(byte[] data) throws IOException, DataFormatException { Inflater inflater = new Inflater(); inflater.setInput(data); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(data.length); byte[] buffer = new byte[1024]; while (!inflater.finished()) { int count = inflater.inflate(buffer); outputStream.write(buffer, 0, count); }// w ww. j a va 2 s . c o m outputStream.close(); byte[] output = outputStream.toByteArray(); /* LOG.debug("Original: " + data.length); LOG.debug("Compressed: " + output.length); */ return output; }
From source file:Main.java
public static byte[] decompress(byte[] data) throws IOException, DataFormatException { Inflater inflater = new Inflater(); inflater.setInput(data); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(data.length); byte[] buffer = new byte[1024]; while (!inflater.finished()) { int count = inflater.inflate(buffer); outputStream.write(buffer, 0, count); }// w ww . j a va2 s . c om outputStream.close(); byte[] output = outputStream.toByteArray(); System.out.println("Original: " + data.length); System.out.println("Compressed: " + output.length); return output; }
From source file:Main.java
private static byte[] decompress(byte[] data) throws IOException, DataFormatException { Inflater inflater = new Inflater(); inflater.setInput(data); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(data.length); byte[] buffer = new byte[1024]; while (!inflater.finished()) { int count = inflater.inflate(buffer); outputStream.write(buffer, 0, count); }/*from ww w . j a va 2s . c o m*/ outputStream.close(); byte[] output = outputStream.toByteArray(); inflater.end(); // System.out.println("Original: " + data.length + " bytes."); // System.out.println("Decompressed: " + output.length + " bytes."); return output; }