List of usage examples for java.util.zip Inflater reset
public void reset()
From source file:Main.java
public static byte[] decompress(byte[] data) { byte[] output = new byte[0]; Inflater decompresser = new Inflater(); decompresser.reset(); decompresser.setInput(data);/* w ww.ja va 2 s. c om*/ ByteArrayOutputStream bos = new ByteArrayOutputStream(2 * data.length); try { byte[] buf = new byte[1024]; while (!decompresser.finished()) { int length = decompresser.inflate(buf); bos.write(buf, 0, length); } output = bos.toByteArray(); bos.close(); } catch (Exception e) { output = data; e.printStackTrace(); } decompresser.end(); return output; }
From source file:Main.java
public static byte[] decompress(byte[] data, int off, int len) { byte[] output = null; Inflater decompresser = new Inflater(); decompresser.reset(); decompresser.setInput(data, off, len); ByteArrayOutputStream out = new ByteArrayOutputStream(data.length); try {//from w w w . j a va 2 s . c om byte[] result = new byte[1024]; while (!decompresser.finished()) { int i = decompresser.inflate(result); out.write(result, 0, i); } output = out.toByteArray(); } catch (Exception e) { throw new RuntimeException(e); } finally { try { out.close(); } catch (Exception e) { } decompresser.end(); } return output; }
From source file:Main.java
public static byte[] zlibDecompress(byte[] data, int offset, int length) { byte[] output = null; Inflater decompresser = new Inflater(); decompresser.reset(); try {/* w ww . ja va 2 s .c o m*/ decompresser.setInput(data, offset, length); } catch (Exception e) { return null; } ByteArrayOutputStream o = new ByteArrayOutputStream(data.length); try { byte[] buf = new byte[1024]; while (!decompresser.finished()) { int i = decompresser.inflate(buf); o.write(buf, 0, i); } output = o.toByteArray(); } catch (Exception e) { output = data; e.printStackTrace(); } finally { try { o.close(); } catch (IOException e) { e.printStackTrace(); } } decompresser.end(); return output; }
From source file:Main.java
public static void decompress(byte[] data, int off, int len, OutputStream out) { Inflater decompresser = new Inflater(); decompresser.reset(); decompresser.setInput(data, off, len); byte[] buf = new byte[1024]; try {// www. j a va2s .co m while (!decompresser.finished()) { int i = decompresser.inflate(buf); out.write(buf, 0, i); out.flush(); } } catch (Exception ex) { throw new RuntimeException(ex); } finally { decompresser.end(); } }
From source file:Main.java
public static byte[] decompress(byte[] data, int off, int len) { byte[] output = null; Inflater decompresser = new Inflater(); decompresser.reset(); // decompresser.setInput(data); decompresser.setInput(data, off, len); ByteArrayOutputStream o = new ByteArrayOutputStream(data.length); try {// w ww. ja va2s. c o m byte[] buf = new byte[1024]; while (!decompresser.finished()) { int i = decompresser.inflate(buf); o.write(buf, 0, i); } output = o.toByteArray(); } catch (Exception e) { throw new RuntimeException(e); } finally { try { o.close(); decompresser.end(); } catch (Exception e) { } } return output; }
From source file:Main.java
public static byte[] decompress(byte[] data, int off, int len, int srcLen) { byte[] output = null; Inflater decompresser = new Inflater(); decompresser.reset(); // decompresser.setInput(data); decompresser.setInput(data, off, len); ByteArrayOutputStream o = new ByteArrayOutputStream(srcLen); try {/*from w ww . j a v a 2 s . c om*/ o.reset(); byte[] buf = new byte[1024]; while (!decompresser.finished()) { int i = decompresser.inflate(buf); o.write(buf, 0, i); } output = o.toByteArray(); } catch (Exception e) { throw new RuntimeException(e); } finally { try { o.close(); decompresser.end(); } catch (Exception e) { } } return output; }
From source file:org.apache.tez.common.TezCommonUtils.java
@Private public static byte[] decompressByteStringToByteArray(ByteString byteString, Inflater inflater) throws IOException { inflater.reset(); try (InflaterInputStream inflaterInputStream = new InflaterInputStream(byteString.newInput(), inflater)) { return IOUtils.toByteArray(inflaterInputStream); }// w w w . jav a2 s . c om }