List of usage examples for java.util.zip Inflater finished
boolean finished
To view the source code for java.util.zip Inflater finished.
Click Source Link
From source file:Main.java
public static byte[] decompress(byte[] data) throws IOException, DataFormatException { Inflater decompresser = new Inflater(); decompresser.setInput(data);/*from w ww . jav a 2 s. co m*/ ByteArrayOutputStream outputStream = new ByteArrayOutputStream(data.length); byte[] buffer = new byte[1024]; while (!decompresser.finished()) { int count = decompresser.inflate(buffer); outputStream.write(buffer, 0, count); } decompresser.end(); outputStream.close(); return outputStream.toByteArray(); }
From source file:Main.java
private static byte[] uncompressBytesInflateDeflate(byte[] inBytes) throws IOException { Inflater inflater = new Inflater(); inflater.setInput(inBytes);//from ww w . j av a 2 s . c o m ByteArrayOutputStream bos = new ByteArrayOutputStream(inBytes.length); byte[] buffer = new byte[1024 * 8]; while (!inflater.finished()) { int count; try { count = inflater.inflate(buffer); } catch (DataFormatException e) { throw new IOException(e); } bos.write(buffer, 0, count); } byte[] output = bos.toByteArray(); 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();//from ww w.jav a 2 s . com decompresser.setInput(data, off, len); byte[] buf = new byte[1024]; try { 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[] decompressInZlib(byte[] compressData, int offset, int length) throws Exception { Inflater decompresser = new Inflater(); decompresser.setInput(compressData, 0, compressData.length); ByteArrayOutputStream bos = new ByteArrayOutputStream(length); int count;// w ww . ja va2s .co m byte[] buf = new byte[1024]; while (!decompresser.finished()) { count = decompresser.inflate(buf); bos.write(buf, 0, count); } byte[] originalData = bos.toByteArray(); decompresser.end(); return originalData; }
From source file:org.xdi.zip.CompressionHelper.java
public static byte[] inflate(byte[] data, boolean nowrap) throws IOException, DataFormatException { Inflater inflater = new Inflater(nowrap); inflater.setInput(data);//w ww . j av a 2 s .c o m ByteArrayOutputStream os = new ByteArrayOutputStream(data.length); try { byte[] buffer = new byte[1024]; while (!inflater.finished()) { int count = inflater.inflate(buffer); os.write(buffer, 0, count); } } finally { IOUtils.closeQuietly(os); } return os.toByteArray(); }
From source file:Main.java
/** * @param data -- the data to decompress * @param uncompressedChunkSize -- an estimate of the uncompressed chunk size. This need not be exact. * @return//from w ww. ja v a2 s .co m */ public static byte[] decompress(byte[] data, int uncompressedChunkSize) { // mpd: new code int rem = data.length; // Create an expandable byte array to hold the decompressed data ByteArrayOutputStream bos = new ByteArrayOutputStream(uncompressedChunkSize); // Decompress the data byte[] outbuf = new byte[uncompressedChunkSize]; Inflater decompressor = new Inflater(); decompressor.setInput(data); while (rem > 0) { // If we are finished with the current chunk start a new one if (decompressor.finished()) { decompressor = new Inflater(); int offset = data.length - rem; decompressor.setInput(data, offset, rem); } try { int count = decompressor.inflate(outbuf, 0, outbuf.length); rem = decompressor.getRemaining(); bos.write(outbuf, 0, count); } catch (Exception e) { e.printStackTrace(); } } try { bos.close(); } catch (IOException e) { // Ignore -- no resources open } // Return the decompressed data return bos.toByteArray(); }
From source file:Main.java
public static byte[] decompress(byte[] compressedBuffer) { Inflater inflater = new Inflater(); inflater.setInput(compressedBuffer); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(compressedBuffer.length); try {//w ww.java2 s. co m byte[] buffer = new byte[1024]; while (!inflater.finished()) { int count = inflater.inflate(buffer); outputStream.write(buffer, 0, count); } byte[] output = outputStream.toByteArray(); return output; } catch (DataFormatException e) { throw new RuntimeException(e); } finally { try { inflater.end(); outputStream.close(); } catch (IOException e) { throw new RuntimeException(e); } } }
From source file:Main.java
public static byte[] decompress(byte[] data) { byte[] output = new byte[0]; Inflater decompresser = new Inflater(); decompresser.reset();// ww w . ja va 2 s.c o m decompresser.setInput(data); 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:org.ojbc.util.helper.ZipUtils.java
public static byte[] unzip(byte[] data) { Inflater inflater = new Inflater(); inflater.setInput(data);// w w w . j a v a 2 s . co m ByteArrayOutputStream outputStream = new ByteArrayOutputStream(data.length); byte[] buffer = new byte[1024]; try { while (!inflater.finished()) { int count; count = inflater.inflate(buffer); outputStream.write(buffer, 0, count); } outputStream.close(); } catch (Exception e) { log.error("Failed to unzip data", e); } byte[] output = outputStream.toByteArray(); log.debug("Original: " + data.length + " bytes"); log.debug("Decompressed: " + output.length + " bytes"); 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();//from www . ja v a 2 s . c o m decompresser.setInput(data, off, len); ByteArrayOutputStream out = new ByteArrayOutputStream(data.length); try { 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; }