@Override public int read() throws IOException { return _inflateIn.read(); }
@Override public int read(byte[] buffer, int offset, int length) throws IOException { return _inflateIn.read(buffer, offset, length); }
@Override public int read() throws IOException { final int b = super.read(); if (b > -1) { uncompressedCount++; } return b; }
@Override public int read(byte[] b, int off, int len) throws IOException { final int bytes = super.read(b, off, len); if (bytes > -1) { uncompressedCount += bytes; } return bytes; }
@Override public int read(final byte[] b, final int off, final int len) throws IOException { return inflaterInputStream.read(b, off, len); }
@Override public int read(final byte[] b) throws IOException { return inflaterInputStream.read(b); }
@Override public int read() throws IOException { return inflaterInputStream.read(); }
private static byte[] readBytes(InflaterInputStream inflaterInputStream, int length) throws IOException { byte[] buffer = new byte[length]; int bytesRead = 0; while (bytesRead < length) { int len = inflaterInputStream.read(buffer, bytesRead, length - bytesRead); if (len == -1) { throw new IOException("End of compressed data has reached"); } else { bytesRead += len; } } return buffer; }
@Override public int read(byte[] buffer, int byteOffset, int byteCount) throws IOException { final int i; try { i = super.read(buffer, byteOffset, byteCount); } catch (IOException e) { throw new IOException("Error reading data for " + entry.getName() + " near offset " + bytesRead, e); } if (i == -1) { if (entry.size != bytesRead) { throw new IOException("Size mismatch on inflated file: " + bytesRead + " vs " + entry.size); } } else { bytesRead += i; } return i; }
private static byte[] inflate(byte[] input) throws IOException { InflaterInputStream gzis = new InflaterInputStream(new ByteArrayInputStream(input)); ByteArrayOutputStream out = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; while(gzis.available() > 0) { int l = gzis.read(buffer); if(l > 0) out.write(buffer, 0, l); } return out.toByteArray(); }
@Override public int read(byte[] buffer, int byteOffset, int byteCount) throws IOException { final int i; try { i = super.read(buffer, byteOffset, byteCount); } catch (IOException e) { throw new IOException("Error reading data for " + entry.getName() + " near offset " + bytesRead, e); } if (i == -1) { if (entry.size != bytesRead) { throw new IOException("Size mismatch on inflated file: " + bytesRead + " vs " + entry.size); } } else { bytesRead += i; } return i; }
public byte[] decompress(byte[] in) throws IOException { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final ByteArrayInputStream bais = new ByteArrayInputStream(in); final InflaterInputStream gz = new InflaterInputStream(bais); int read; while ((read = gz.read()) != -1) { baos.write(read); } gz.close(); bais.close(); baos.close(); return baos.toByteArray(); }
import java.io.FileInputStream; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; public class Main { public static void main(String[] args) throws Exception { FileInputStream fis = new FileInputStream("c:/inas400.zip"); // this is where you start, with an InputStream containing the bytes from the zip file ZipInputStream zis = new ZipInputStream(fis); ZipEntry entry; // while there are entries I process them while ((entry = zis.getNextEntry()) != null) { System.out.println("entry: " + entry.getName() + ", " + entry.getSize()); // consume all the data from this entry while (zis.available() > 0) zis.read(); // I could close the entry, but getNextEntry does it automatically // zis.closeEntry() } } }
/** * Decompresses the provided data, returning the inflated result. * * @param data the deflated picture data. * @return the inflated picture data. */ private static byte[] inflatePictureData(byte[] data) { try { InflaterInputStream in = new InflaterInputStream(new ByteArrayInputStream(data)); ByteArrayOutputStream out = new ByteArrayOutputStream(); byte[] buf = new byte[4096]; int readBytes; while ((readBytes = in.read(buf)) > 0) { out.write(buf, 0, readBytes); } return out.toByteArray(); } catch (IOException e) { log.log(POILogger.INFO, "Possibly corrupt compression or non-compressed data", e); return data; } }
/** * Decompresses the provided data, returning the inflated result. * * @param data the deflated picture data. * @return the inflated picture data. */ private static byte[] inflatePictureData(byte[] data) { try { InflaterInputStream in = new InflaterInputStream( new ByteArrayInputStream( data ) ); ByteArrayOutputStream out = new ByteArrayOutputStream(); byte[] buf = new byte[4096]; int readBytes; while ((readBytes = in.read(buf)) > 0) { out.write(buf, 0, readBytes); } return out.toByteArray(); } catch (IOException e) { log.log(POILogger.WARN, "Possibly corrupt compression or non-compressed data", e); return data; } }
public static byte[] decompress(byte[] data) { Profiler.enter("time cost on [decompress]"); InflaterInputStream zipIn = new InflaterInputStream(new ByteArrayInputStream(data)); ByteArrayOutputStream out = new ByteArrayOutputStream(data.length * 4); byte[] buffer = new byte[1024]; int length; try { while ((length = zipIn.read(buffer)) != -1) { out.write(buffer, 0, length); } } catch (IOException e) { LOGGER.error("decompress ex", e); return Constants.EMPTY_BYTES; } finally { close(zipIn); Profiler.release(); } return out.toByteArray(); } }
int len = inflaterInputStream.read(uncompressData, 0, uncompressData.length); if (len <= 0) { break;
@Override public int read(byte[] buffer, int byteOffset, int byteCount) throws IOException { if (closed) { throw new IOException("Stream is closed"); } if (eos) { return -1; } Arrays.checkOffsetAndCount(buffer.length, byteOffset, byteCount); int bytesRead; try { bytesRead = super.read(buffer, byteOffset, byteCount); } finally { eos = eof; // update eos after every read(), even when it throws } if (bytesRead != -1) { crc.update(buffer, byteOffset, bytesRead); } if (eos) { verifyCrc(); } return bytesRead; }
byte[] decompressBuffer = new byte[DECOMPRESS_BUFFER_SIZE]; int bytesRead; while ((bytesRead = reader.read(decompressBuffer)) > -1) { uncompressed.write(decompressBuffer, 0, bytesRead);
byte[] buffer = new byte[8*1024]; int read = 0; while ((read = inflater.read(buffer)) != -1) { this.dataOut.write(buffer, 0, read);