java.util.zip.InflaterInputStream

Here are the examples of the java api class java.util.zip.InflaterInputStream taken from open source projects.

1. Compresser#inflate()

Project: zstack
File: Compresser.java
public static byte[] inflate(byte[] input, int bufferSize) throws IOException {
    ByteArrayInputStream in = new ByteArrayInputStream(input);
    Inflater inf = new Inflater();
    InflaterInputStream iis = new InflaterInputStream(in, inf, bufferSize);
    ByteArrayOutputStream out = new ByteArrayOutputStream(input.length * 5);
    for (int c = iis.read(); c != -1; c = iis.read()) {
        out.write(c);
    }
    in.close();
    iis.close();
    byte[] ret = out.toByteArray();
    out.close();
    return ret;
}

2. DeflateUtils#decompress()

Project: Resteasy
File: DeflateUtils.java
/**
	 * Decompresses the specified byte array according to the DEFLATE
	 * specification (RFC 1951).
	 *
	 * @param bytes The byte array to decompress. Must not be {@code null}.
	 *
	 * @return The decompressed bytes.
	 *
	 * @throws java.io.IOException If decompression failed.
	 */
public static byte[] decompress(final byte[] bytes) throws IOException {
    InflaterInputStream inf = new InflaterInputStream(new ByteArrayInputStream(bytes), new Inflater(NOWRAP));
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    // Transfer bytes from the compressed array to the output
    byte[] buf = new byte[1024];
    int len;
    while ((len = inf.read(buf)) > 0) {
        out.write(buf, 0, len);
    }
    inf.close();
    out.close();
    return out.toByteArray();
}

3. SerializerCompressionDeflateWrapper#deserialize()

Project: mapdb
File: SerializerCompressionDeflateWrapper.java
@Override
public E deserialize(DataInput2 in, int available) throws IOException {
    final int unpackedSize = in.unpackInt() - 1;
    if (unpackedSize == -1) {
        //was not compressed
        return serializer.deserialize(in, available > 0 ? available - 1 : available);
    }
    Inflater inflater = new Inflater();
    if (dictionary != null) {
        inflater.setDictionary(dictionary);
    }
    InflaterInputStream in4 = new InflaterInputStream(new DataInput2.DataInputToStream(in), inflater);
    byte[] unpacked = new byte[unpackedSize];
    in4.read(unpacked, 0, unpackedSize);
    DataInput2.ByteArray in2 = new DataInput2.ByteArray(unpacked);
    E ret = serializer.deserialize(in2, unpackedSize);
    if (CC.ASSERT && !(in2.pos == unpackedSize))
        throw new DBException.DataCorruption("data were not fully read");
    return ret;
}

4. PNGFile#parse_iCCP_chunk()

Project: xml-graphics-commons
File: PNGFile.java
private void parse_iCCP_chunk(PNGChunk chunk) {
    int length = chunk.getLength();
    int textIndex = 0;
    while (chunk.getByte(textIndex++) != 0) {
    //NOP
    }
    textIndex++;
    byte[] profile = new byte[length - textIndex];
    System.arraycopy(chunk.getData(), textIndex, profile, 0, length - textIndex);
    ByteArrayInputStream bais = new ByteArrayInputStream(profile);
    InflaterInputStream iis = new InflaterInputStream(bais, new Inflater());
    try {
        iccProfile = ICC_Profile.getInstance(iis);
    } catch (IOException ioe) {
    }
}

5. ContentEncodedTest#verifyResponseDeflateContentEncodedForRepeatedStrings()

Project: wink
File: ContentEncodedTest.java
private static void verifyResponseDeflateContentEncodedForRepeatedStrings(ClientResponse response) throws IOException {
    assertEquals(200, response.getStatusCode());
    InputStream is = response.getEntity(InputStream.class);
    InflaterInputStream inflaterIS = new InflaterInputStream(is);
    StringProvider sp = new StringProvider();
    String responseEntity = sp.readFrom(String.class, String.class, new Annotation[] {}, MediaType.TEXT_PLAIN_TYPE, null, inflaterIS);
    assertEquals(getRepeatedString(), responseEntity);
    assertEquals("deflate", response.getHeaders().getFirst(HttpHeaders.CONTENT_ENCODING));
    assertEquals(1, response.getHeaders().get(HttpHeaders.CONTENT_ENCODING).size());
    assertEquals(HttpHeaders.ACCEPT_ENCODING, response.getHeaders().getFirst(HttpHeaders.VARY));
    assertEquals(1, response.getHeaders().get(HttpHeaders.VARY).size());
}

6. Encoder#decodeBase64AndDecompressToBytes()

Project: voltdb
File: Encoder.java
public static byte[] decodeBase64AndDecompressToBytes(String string) {
    byte bytes[] = Base64.decodeFast(string);
    if (string.length() == 0) {
        return new byte[0];
    }
    ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
    InflaterInputStream dis = new InflaterInputStream(bais);
    byte buffer[] = new byte[1024 * 8];
    int length = 0;
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try {
        while ((length = dis.read(buffer)) >= 0) {
            baos.write(buffer, 0, length);
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return baos.toByteArray();
}

7. ArchiveTool#extract()

Project: ThriftyPaxos
File: ArchiveTool.java
private static void extract(String fromFile, String toDir) throws IOException {
    long start = System.currentTimeMillis();
    long size = new File(fromFile).length();
    System.out.println("Extracting " + size / MB + " MB");
    InputStream in = new BufferedInputStream(new FileInputStream(fromFile), 1024 * 1024);
    String temp = fromFile + ".temp";
    Inflater inflater = new Inflater();
    in = new InflaterInputStream(in, inflater, 1024 * 1024);
    OutputStream out = getDirectoryOutputStream(toDir);
    combine(in, out, temp);
    inflater.end();
    in.close();
    out.close();
    System.out.println();
    System.out.println("Extracted in " + (System.currentTimeMillis() - start) / 1000 + " seconds");
}

8. CompressionUtils#decodeByteArrayToString()

Project: passport
File: CompressionUtils.java
/**
     * Decode the byte[] in base64 to a string.
     *
     * @param bytes the data to encode
     * @return the new string in {@link #UTF8_ENCODING}.
     */
public static String decodeByteArrayToString(final byte[] bytes) {
    final ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final byte[] buf = new byte[bytes.length];
    try (final InflaterInputStream iis = new InflaterInputStream(bais)) {
        int count = iis.read(buf);
        while (count != -1) {
            baos.write(buf, 0, count);
            count = iis.read(buf);
        }
        return new String(baos.toByteArray(), Charset.forName(UTF8_ENCODING));
    } catch (final Exception e) {
        LOGGER.error("Base64 decoding failed", e);
        return null;
    }
}

9. CompressionUtils#decodeByteArrayToString()

Project: passport
File: CompressionUtils.java
/**
     * Decode the byte[] in base64 to a string.
     *
     * @param bytes the data to encode
     * @return the new string in {@link #UTF8_ENCODING}.
     */
public static String decodeByteArrayToString(final byte[] bytes) {
    final ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final byte[] buf = new byte[bytes.length];
    try (final InflaterInputStream iis = new InflaterInputStream(bais)) {
        int count = iis.read(buf);
        while (count != -1) {
            baos.write(buf, 0, count);
            count = iis.read(buf);
        }
        return new String(baos.toByteArray(), Charset.forName(UTF8_ENCODING));
    } catch (final Exception e) {
        LOGGER.error("Base64 decoding failed", e);
        return null;
    }
}

10. RedirectSAML2ClientTests#getInflatedAuthnRequest()

Project: pac4j
File: RedirectSAML2ClientTests.java
private String getInflatedAuthnRequest(final String location) throws Exception {
    final List<NameValuePair> pairs = URLEncodedUtils.parse(java.net.URI.create(location), "UTF-8");
    final Inflater inflater = new Inflater(true);
    final byte[] decodedRequest = Base64.getDecoder().decode(pairs.get(0).getValue());
    final ByteArrayInputStream is = new ByteArrayInputStream(decodedRequest);
    final InflaterInputStream inputStream = new InflaterInputStream(is, inflater);
    final BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, HttpConstants.UTF8_ENCODING));
    String line;
    final StringBuilder bldr = new StringBuilder();
    while ((line = reader.readLine()) != null) {
        bldr.append(line);
    }
    return bldr.toString();
}

11. RefCountingStorage#internalReadStream()

Project: intellij-community
File: RefCountingStorage.java
private BufferExposingByteArrayOutputStream internalReadStream(int record) throws IOException {
    waitForPendingWriteForRecord(record);
    byte[] result;
    synchronized (myLock) {
        result = super.readBytes(record);
    }
    InflaterInputStream in = new CustomInflaterInputStream(result);
    try {
        final BufferExposingByteArrayOutputStream outputStream = new BufferExposingByteArrayOutputStream();
        StreamUtil.copyStreamContent(in, outputStream);
        return outputStream;
    } finally {
        in.close();
    }
}

12. SourceCodeCompressor#decompress()

Project: intellij-community
File: SourceCodeCompressor.java
public static byte[] decompress(final byte[] compressed, final int len, final int off) throws IOException {
    INFLATER.reset();
    InflaterInputStream input = null;
    try {
        input = new InflaterInputStream(new ByteArrayInputStream(compressed, off, len), INFLATER);
        final int b = input.read();
        if (b == -1) {
            INFLATER.setDictionary(PRESET_BUF);
        } else {
            OUTPUT.write(b);
        }
        int readBytes;
        while ((readBytes = input.read(INFLATE_BUFFER)) > 0) {
            OUTPUT.write(INFLATE_BUFFER, 0, readBytes);
        }
        return OUTPUT.toByteArray();
    } finally {
        if (input != null) {
            input.close();
        }
        OUTPUT.reset();
    }
}

13. PatchList#readObject()

Project: gerrit
File: PatchList.java
private void readObject(final ObjectInputStream input) throws IOException {
    final ByteArrayInputStream buf = new ByteArrayInputStream(readBytes(input));
    try (InflaterInputStream in = new InflaterInputStream(buf)) {
        oldId = readCanBeNull(in);
        newId = readNotNull(in);
        againstParent = readVarInt32(in) != 0;
        insertions = readVarInt32(in);
        deletions = readVarInt32(in);
        final int cnt = readVarInt32(in);
        final PatchListEntry[] all = new PatchListEntry[cnt];
        for (int i = 0; i < all.length; i++) {
            all[i] = PatchListEntry.readFrom(in);
        }
        patches = all;
    }
}

14. RefCountingStorage#internalReadStream()

Project: consulo
File: RefCountingStorage.java
private BufferExposingByteArrayOutputStream internalReadStream(int record) throws IOException {
    waitForPendingWriteForRecord(record);
    byte[] result;
    synchronized (myLock) {
        result = super.readBytes(record);
    }
    InflaterInputStream in = new CustomInflaterInputStream(result);
    try {
        final BufferExposingByteArrayOutputStream outputStream = new BufferExposingByteArrayOutputStream();
        StreamUtil.copyStreamContent(in, outputStream);
        return outputStream;
    } finally {
        in.close();
    }
}

15. SourceCodeCompressor#decompress()

Project: consulo
File: SourceCodeCompressor.java
public static byte[] decompress(final byte[] compressed, final int len, final int off) throws IOException {
    INFLATER.reset();
    InflaterInputStream input = null;
    try {
        input = new InflaterInputStream(new ByteArrayInputStream(compressed, off, len), INFLATER);
        final int b = input.read();
        if (b == -1) {
            INFLATER.setDictionary(PRESET_BUF);
        } else {
            OUTPUT.write(b);
        }
        int readBytes;
        while ((readBytes = input.read(INFLATE_BUFFER)) > 0) {
            OUTPUT.write(INFLATE_BUFFER, 0, readBytes);
        }
        return OUTPUT.toByteArray();
    } finally {
        if (input != null) {
            input.close();
        }
        OUTPUT.reset();
    }
}

16. PdfReader#FlateDecode()

Project: clj-pdf
File: PdfReader.java
/** A helper to FlateDecode.
     * @param in the input data
     * @param strict <CODE>true</CODE> to read a correct stream. <CODE>false</CODE>
     * to try to read a corrupted stream
     * @return the decoded data
     */
public static byte[] FlateDecode(byte in[], boolean strict) {
    ByteArrayInputStream stream = new ByteArrayInputStream(in);
    InflaterInputStream zip = new InflaterInputStream(stream);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    byte b[] = new byte[strict ? 4092 : 1];
    try {
        int n;
        while ((n = zip.read(b)) >= 0) {
            out.write(b, 0, n);
        }
        zip.close();
        out.close();
        return out.toByteArray();
    } catch (Exception e) {
        if (strict)
            return null;
        return out.toByteArray();
    }
}

17. CompressionUtils#decodeByteArrayToString()

Project: cas
File: CompressionUtils.java
/**
     * Decode the byte[] in base64 to a string.
     *
     * @param bytes the data to encode
     * @return the new string in {@link #UTF8_ENCODING}.
     */
public static String decodeByteArrayToString(final byte[] bytes) {
    final ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final byte[] buf = new byte[bytes.length];
    try (final InflaterInputStream iis = new InflaterInputStream(bais)) {
        int count = iis.read(buf);
        while (count != -1) {
            baos.write(buf, 0, count);
            count = iis.read(buf);
        }
        return new String(baos.toByteArray(), Charset.forName(UTF8_ENCODING));
    } catch (final Exception e) {
        LOGGER.error("Base64 decoding failed", e);
        return null;
    }
}

18. ZipDataFormat#unmarshal()

Project: camel
File: ZipDataFormat.java
public Object unmarshal(final Exchange exchange, final InputStream inputStream) throws Exception {
    InflaterInputStream inflaterInputStream = new InflaterInputStream(inputStream);
    OutputStreamBuilder osb = OutputStreamBuilder.withExchange(exchange);
    try {
        IOHelper.copy(inflaterInputStream, osb);
        return osb.build();
    } finally {
        // must close input streams
        IOHelper.close(osb, inflaterInputStream, inputStream);
    }
}

19. ZlibCodec#decompress()

Project: bioformats
File: ZlibCodec.java
/* @see Codec#decompress(RandomAccessInputStream, CodecOptions) */
@Override
public byte[] decompress(RandomAccessInputStream in, CodecOptions options) throws FormatException, IOException {
    InflaterInputStream i = new InflaterInputStream(in);
    ByteVector bytes = new ByteVector();
    byte[] buf = new byte[8192];
    int r = 0;
    // read until eof reached
    try {
        while ((r = i.read(buf, 0, buf.length)) > 0) bytes.add(buf, 0, r);
    } catch (EOFException e) {
    }
    return bytes.toByteArray();
}

20. EscherBlipWMFRecord#decompress()

Project: bioformats
File: EscherBlipWMFRecord.java
/**
     * Decompresses a byte array.
     *
     * @param data   The compressed byte array
     * @param pos    The starting position into the byte array
     * @param length The number of compressed bytes to decompress
     * @return An uncompressed byte array
     * @see InflaterInputStream#read
     */
public static byte[] decompress(byte[] data, int pos, int length) {
    byte[] compressedData = new byte[length];
    System.arraycopy(data, pos + 50, compressedData, 0, length);
    InputStream compressedInputStream = new ByteArrayInputStream(compressedData);
    InflaterInputStream inflaterInputStream = new InflaterInputStream(compressedInputStream);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    int c;
    try {
        while ((c = inflaterInputStream.read()) != -1) out.write(c);
    } catch (IOException e) {
        throw new RecordFormatException(e.toString());
    }
    return out.toByteArray();
}

21. DeflateUtils#inflate()

Project: anthelion
File: DeflateUtils.java
/**
   * Returns an inflated copy of the input array.  
   * @throws IOException if the input cannot be properly decompressed
   */
public static final byte[] inflate(byte[] in) throws IOException {
    // decompress using InflaterInputStream 
    ByteArrayOutputStream outStream = new ByteArrayOutputStream(EXPECTED_COMPRESSION_RATIO * in.length);
    InflaterInputStream inStream = new InflaterInputStream(new ByteArrayInputStream(in));
    byte[] buf = new byte[BUF_SIZE];
    while (true) {
        int size = inStream.read(buf);
        if (size <= 0)
            break;
        outStream.write(buf, 0, size);
    }
    outStream.close();
    return outStream.toByteArray();
}

22. Message#doDecompress()

Project: activemq-openwire
File: Message.java
protected Buffer doDecompress() throws IOException {
    // TODO
    ByteArrayInputStream input = new ByteArrayInputStream(this.content.getData(), this.content.getOffset(), this.content.getLength());
    InflaterInputStream inflater = new InflaterInputStream(input);
    DataByteArrayOutputStream output = new DataByteArrayOutputStream();
    try {
        byte[] buffer = new byte[8 * 1024];
        int read = 0;
        while ((read = inflater.read(buffer)) != -1) {
            output.write(buffer, 0, read);
        }
    } finally {
        inflater.close();
        output.close();
    }
    return output.toBuffer();
}

23. ReadParams#main()

Project: openjdk
File: ReadParams.java
public static void main(String args[]) throws Exception {
    /* initialise stuff */
    File fn = new File("x.ReadBounds");
    FileOutputStream fout = new FileOutputStream(fn);
    for (int i = 0; i < 32; i++) {
        fout.write(i);
    }
    fout.close();
    byte b[] = new byte[64];
    for (int i = 0; i < 64; i++) {
        b[i] = 1;
    }
    /* test all input streams */
    FileInputStream fis = new FileInputStream(fn);
    doTest(fis);
    doTest1(fis);
    fis.close();
    BufferedInputStream bis = new BufferedInputStream(new MyInputStream(1024));
    doTest(bis);
    doTest1(bis);
    bis.close();
    ByteArrayInputStream bais = new ByteArrayInputStream(b);
    doTest(bais);
    doTest1(bais);
    bais.close();
    FileOutputStream fos = new FileOutputStream(fn);
    ObjectOutputStream oos = new ObjectOutputStream(fos);
    oos.writeInt(12345);
    oos.writeObject("Today");
    oos.writeObject(new Integer(32));
    oos.close();
    ObjectInputStream ois = new ObjectInputStream(new FileInputStream(fn));
    doTest(ois);
    doTest1(ois);
    ois.close();
    DataInputStream dis = new DataInputStream(new MyInputStream(1024));
    doTest(dis);
    doTest1(dis);
    dis.close();
    LineNumberInputStream lis = new LineNumberInputStream(new MyInputStream(1024));
    doTest(lis);
    doTest1(lis);
    lis.close();
    PipedOutputStream pos = new PipedOutputStream();
    PipedInputStream pis = new PipedInputStream();
    pos.connect(pis);
    pos.write(b, 0, 64);
    doTest(pis);
    doTest1(pis);
    pis.close();
    PushbackInputStream pbis = new PushbackInputStream(new MyInputStream(1024));
    doTest(pbis);
    doTest1(pbis);
    pbis.close();
    StringBufferInputStream sbis = new StringBufferInputStream(new String(b));
    doTest(sbis);
    doTest1(sbis);
    sbis.close();
    SequenceInputStream sis = new SequenceInputStream(new MyInputStream(1024), new MyInputStream(1024));
    doTest(sis);
    doTest1(sis);
    sis.close();
    ZipInputStream zis = new ZipInputStream(new FileInputStream(fn));
    doTest(zis);
    doTest1(zis);
    zis.close();
    byte[] data = new byte[256];
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    DeflaterOutputStream dos = new DeflaterOutputStream(bos);
    dos.write(data, 0, data.length);
    dos.close();
    InflaterInputStream ifs = new InflaterInputStream(new ByteArrayInputStream(bos.toByteArray()));
    doTest(ifs);
    doTest1(ifs);
    ifs.close();
    /* cleanup */
    fn.delete();
}

24. SerializerCompressionDeflateWrapper#valueArrayDeserialize()

Project: mapdb
File: SerializerCompressionDeflateWrapper.java
@Override
public Object valueArrayDeserialize(DataInput2 in, int size) throws IOException {
    if (size == 0) {
        return serializer.valueArrayEmpty();
    }
    //decompress all values in single blob, it has better compressibility
    final int unpackedSize = in.unpackInt() - 1;
    if (unpackedSize == -1) {
        //was not compressed
        return serializer.valueArrayDeserialize(in, size);
    }
    Inflater inflater = new Inflater();
    if (dictionary != null) {
        inflater.setDictionary(dictionary);
    }
    InflaterInputStream in4 = new InflaterInputStream(new DataInput2.DataInputToStream(in), inflater);
    byte[] unpacked = new byte[unpackedSize];
    in4.read(unpacked, 0, unpackedSize);
    //now got data unpacked, so use serializer to deal with it
    DataInput2.ByteArray in2 = new DataInput2.ByteArray(unpacked);
    Object ret = serializer.valueArrayDeserialize(in2, size);
    if (CC.ASSERT && !(in2.pos == unpackedSize))
        throw new DBException.DataCorruption("data were not fully read");
    return ret;
}

25. ReadParams#main()

Project: jdk7u-jdk
File: ReadParams.java
public static void main(String args[]) throws Exception {
    /* initialise stuff */
    File fn = new File("x.ReadBounds");
    FileOutputStream fout = new FileOutputStream(fn);
    for (int i = 0; i < 32; i++) {
        fout.write(i);
    }
    fout.close();
    byte b[] = new byte[64];
    for (int i = 0; i < 64; i++) {
        b[i] = 1;
    }
    /* test all input streams */
    FileInputStream fis = new FileInputStream(fn);
    doTest(fis);
    doTest1(fis);
    fis.close();
    BufferedInputStream bis = new BufferedInputStream(new MyInputStream(1024));
    doTest(bis);
    doTest1(bis);
    bis.close();
    ByteArrayInputStream bais = new ByteArrayInputStream(b);
    doTest(bais);
    doTest1(bais);
    bais.close();
    FileOutputStream fos = new FileOutputStream(fn);
    ObjectOutputStream oos = new ObjectOutputStream(fos);
    oos.writeInt(12345);
    oos.writeObject("Today");
    oos.writeObject(new Integer(32));
    oos.close();
    ObjectInputStream ois = new ObjectInputStream(new FileInputStream(fn));
    doTest(ois);
    doTest1(ois);
    ois.close();
    DataInputStream dis = new DataInputStream(new MyInputStream(1024));
    doTest(dis);
    doTest1(dis);
    dis.close();
    LineNumberInputStream lis = new LineNumberInputStream(new MyInputStream(1024));
    doTest(lis);
    doTest1(lis);
    lis.close();
    PipedOutputStream pos = new PipedOutputStream();
    PipedInputStream pis = new PipedInputStream();
    pos.connect(pis);
    pos.write(b, 0, 64);
    doTest(pis);
    doTest1(pis);
    pis.close();
    PushbackInputStream pbis = new PushbackInputStream(new MyInputStream(1024));
    doTest(pbis);
    doTest1(pbis);
    pbis.close();
    StringBufferInputStream sbis = new StringBufferInputStream(new String(b));
    doTest(sbis);
    doTest1(sbis);
    sbis.close();
    SequenceInputStream sis = new SequenceInputStream(new MyInputStream(1024), new MyInputStream(1024));
    doTest(sis);
    doTest1(sis);
    sis.close();
    ZipInputStream zis = new ZipInputStream(new FileInputStream(fn));
    doTest(zis);
    doTest1(zis);
    zis.close();
    byte[] data = new byte[256];
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    DeflaterOutputStream dos = new DeflaterOutputStream(bos);
    dos.write(data, 0, data.length);
    dos.close();
    InflaterInputStream ifs = new InflaterInputStream(new ByteArrayInputStream(bos.toByteArray()));
    doTest(ifs);
    doTest1(ifs);
    ifs.close();
    /* cleanup */
    fn.delete();
}

26. DeflaterOutputStreamTest#testSyncFlushDeflater()

Project: j2objc
File: DeflaterOutputStreamTest.java
/**
     * Confirm that a DeflaterOutputStream constructed with Deflater
     * with flushParm == SYNC_FLUSH does not need to to be flushed.
     *
     * http://b/4005091
     */
public void testSyncFlushDeflater() throws Exception {
    Deflater def = new Deflater();
    Field f = def.getClass().getDeclaredField("flushParm");
    f.setAccessible(true);
    f.setInt(def, Deflater.SYNC_FLUSH);
    final int deflaterBufferSize = 512;
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    DeflaterOutputStream dos = new DeflaterOutputStream(baos, def, deflaterBufferSize);
    // make output buffer large enough that even if compressed it
    // won't all fit within the deflaterBufferSize.
    final int outputBufferSize = 128 * deflaterBufferSize;
    byte[] output = new byte[outputBufferSize];
    for (int i = 0; i < output.length; i++) {
        output[i] = (byte) i;
    }
    dos.write(output);
    byte[] compressed = baos.toByteArray();
    // this main reason for this assert is to make sure that the
    // compressed byte count is larger than the
    // deflaterBufferSize. However, when the original bug exists,
    // it will also fail because the compressed length will be
    // exactly the length of the deflaterBufferSize.
    assertTrue("compressed=" + compressed.length + " but deflaterBufferSize=" + deflaterBufferSize, compressed.length > deflaterBufferSize);
    // assert that we returned data matches the input exactly.
    ByteArrayInputStream bais = new ByteArrayInputStream(compressed);
    InflaterInputStream iis = new InflaterInputStream(bais);
    byte[] input = new byte[output.length];
    int total = 0;
    while (true) {
        int n = iis.read(input, total, input.length - total);
        if (n == -1) {
            break;
        }
        total += n;
        if (total == input.length) {
            try {
                iis.read();
                fail();
            } catch (EOFException expected) {
                break;
            }
        }
    }
    assertEquals(output.length, total);
    assertTrue(Arrays.equals(input, output));
    // ensure Deflater.finish has not been called at any point
    // during the test, since that would lead to the results being
    // flushed even without SYNC_FLUSH being used
    assertFalse(def.finished());
    // Quieten CloseGuard.
    def.end();
    iis.close();
}

27. BaseSerializingTranscoder#zipDecompress()

Project: xmemcached
File: BaseSerializingTranscoder.java
private byte[] zipDecompress(byte[] in) {
    int size = in.length * COMPRESS_RATIO;
    ByteArrayInputStream bais = new ByteArrayInputStream(in);
    InflaterInputStream is = new InflaterInputStream(bais);
    ByteArrayOutputStream baos = new ByteArrayOutputStream(size);
    try {
        byte[] uncompressMessage = new byte[size];
        while (true) {
            int len = is.read(uncompressMessage);
            if (len <= 0) {
                break;
            }
            baos.write(uncompressMessage, 0, len);
        }
        baos.flush();
        return baos.toByteArray();
    } catch (IOException e) {
        log.error("Failed to decompress data", e);
    } finally {
        try {
            is.close();
        } catch (IOException e) {
            log.error("failed to close InflaterInputStream");
        }
        try {
            bais.close();
        } catch (IOException e) {
            log.error("failed to close ByteArrayInputStream");
        }
        try {
            baos.close();
        } catch (IOException e) {
            log.error("failed to close ByteArrayOutputStream");
        }
    }
    return baos == null ? null : baos.toByteArray();
}

28. BinaryCasSerDes6#setupReadStream()

Project: uima-uimaj
File: BinaryCasSerDes6.java
private void setupReadStream(int slotIndex, int bytesCompr, int bytesOrig) throws IOException {
    byte[] b = new byte[bytesCompr + 1];
    // this leaves 1 extra 0 byte at the end
    deserIn.readFully(b, 0, bytesCompr);
    // which may be required by Inflater with nowrap option - see Inflater javadoc
    // testing inflate speed
    //      long startTime = System.currentTimeMillis();
    //      inflater.reset();
    //      inflater.setInput(b);
    //      byte[] uncompressed = new byte[bytesOrig];
    //      int uncompressedLength = 0;
    //      try {
    //        uncompressedLength = inflater.inflate(uncompressed);
    //      } catch (DataFormatException e) {
    //        throw new RuntimeException(e);
    //      }
    //      if (uncompressedLength != bytesOrig) {
    //        throw new RuntimeException();
    //      }
    //      System.out.format("Decompress %s took %,d ms%n", 
    //          SlotKind.values()[slotIndex], System.currentTimeMillis() - startTime); 
    //      
    //      dataInputs[slotIndex] = new DataInputStream(new ByteArrayInputStream(uncompressed));
    Inflater inflater = new Inflater(true);
    // save to be able to call end() when done. 
    inflaters[slotIndex] = inflater;
    ByteArrayInputStream baiStream = new ByteArrayInputStream(b);
    // 32768 == 1<< 15.  Tuned by trials on 2015 intel i7
    int zipBufSize = Math.max(1 << 10, bytesCompr);
    // caches: L1 = 128KB    L2 = 1M     L3 = 6M
    // increasing the max causes cache dumping on this machine, and things slow down
    InflaterInputStream iis = new InflaterInputStream(baiStream, inflater, zipBufSize);
    // increasing the following buffer stream buffer size also seems to slow things down
    dataInputs[slotIndex] = new DataInputStream(new BufferedInputStream(iis, zipBufSize * 1));
}

29. TezUtils#createConfFromByteString()

Project: tez
File: TezUtils.java
/**
   * Convert a byte string to a Configuration object
   *
   * @param byteString byteString representation of the conf created using {@link
   *                   #createByteStringFromConf(org.apache.hadoop.conf.Configuration)}
   * @return Configuration
   * @throws java.io.IOException
   */
public static Configuration createConfFromByteString(ByteString byteString) throws IOException {
    Preconditions.checkNotNull(byteString, "ByteString must be specified");
    // SnappyInputStream uncompressIs = new
    // SnappyInputStream(byteString.newInput());
    InflaterInputStream uncompressIs = new InflaterInputStream(byteString.newInput());
    DAGProtos.ConfigurationProto confProto = DAGProtos.ConfigurationProto.parseFrom(uncompressIs);
    Configuration conf = new Configuration(false);
    readConfFromPB(confProto, conf);
    return conf;
}

30. TezCommonUtils#decompressByteStringToByteArray()

Project: tez
File: TezCommonUtils.java
@Private
public static byte[] decompressByteStringToByteArray(ByteString byteString) throws IOException {
    InflaterInputStream in = new InflaterInputStream(byteString.newInput());
    byte[] bytes = IOUtils.toByteArray(in);
    return bytes;
}

31. ZLibUtils#inflate()

Project: sanselan
File: ZLibUtils.java
public final byte[] inflate(byte bytes[]) throws IOException // slow, probably.
{
    ByteArrayInputStream in = new ByteArrayInputStream(bytes);
    InflaterInputStream zIn = new InflaterInputStream(in);
    return getStreamBytes(zIn);
}

32. UtilAll#uncompress()

Project: rocketmq-all
File: UtilAll.java
public static byte[] uncompress(final byte[] src) throws IOException {
    byte[] result = src;
    byte[] uncompressData = new byte[src.length];
    ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(src);
    InflaterInputStream inflaterInputStream = new InflaterInputStream(byteArrayInputStream);
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(src.length);
    try {
        while (true) {
            int len = inflaterInputStream.read(uncompressData, 0, uncompressData.length);
            if (len <= 0) {
                break;
            }
            byteArrayOutputStream.write(uncompressData, 0, len);
        }
        byteArrayOutputStream.flush();
        result = byteArrayOutputStream.toByteArray();
    } catch (IOException e) {
        throw e;
    } finally {
        try {
            byteArrayInputStream.close();
        } catch (IOException e) {
        }
        try {
            inflaterInputStream.close();
        } catch (IOException e) {
        }
        try {
            byteArrayOutputStream.close();
        } catch (IOException e) {
        }
    }
    return result;
}

33. UtilAll#uncompress()

Project: RocketMQ
File: UtilAll.java
public static byte[] uncompress(final byte[] src) throws IOException {
    byte[] result = src;
    byte[] uncompressData = new byte[src.length];
    ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(src);
    InflaterInputStream inflaterInputStream = new InflaterInputStream(byteArrayInputStream);
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(src.length);
    try {
        while (true) {
            int len = inflaterInputStream.read(uncompressData, 0, uncompressData.length);
            if (len <= 0) {
                break;
            }
            byteArrayOutputStream.write(uncompressData, 0, len);
        }
        byteArrayOutputStream.flush();
        result = byteArrayOutputStream.toByteArray();
    } catch (IOException e) {
        throw e;
    } finally {
        try {
            byteArrayInputStream.close();
        } catch (IOException e) {
        }
        try {
            inflaterInputStream.close();
        } catch (IOException e) {
        }
        try {
            byteArrayOutputStream.close();
        } catch (IOException e) {
        }
    }
    return result;
}

34. DeflateSerializer#read()

Project: kryo
File: DeflateSerializer.java
public Object read(Kryo kryo, Input input, Class type) {
    // The inflater would read from input beyond the compressed bytes if chunked enoding wasn't used.
    InflaterInputStream inflaterStream = new InflaterInputStream(new InputChunked(input, 256), new Inflater(noHeaders));
    return kryo.readObject(new Input(inflaterStream, 256), type, serializer);
}

35. SWFInputStream#uncompressByteArray()

Project: jpexs-decompiler
File: SWFInputStream.java
public static byte[] uncompressByteArray(byte[] data, int offset, int length) throws IOException {
    InflaterInputStream dis = new InflaterInputStream(new ByteArrayInputStream(data, offset, length));
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    byte[] buf = new byte[4096];
    int c;
    while ((c = dis.read(buf)) > 0) {
        baos.write(buf, 0, c);
    }
    return baos.toByteArray();
}

36. FbxReader#inflate()

Project: jmonkeyengine
File: FbxReader.java
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();
}

37. TezUtils#createConfFromByteString()

Project: incubator-tez
File: TezUtils.java
/**
   * Convert compressed byte string to a Configuration object using protocol
   * buffer
   * 
   * @param byteString
   *          :compressed conf in Protocol buffer
   * @return Configuration
   * @throws IOException
   */
public static Configuration createConfFromByteString(ByteString byteString) throws IOException {
    Preconditions.checkNotNull(byteString, "ByteString must be specified");
    // SnappyInputStream uncompressIs = new
    // SnappyInputStream(byteString.newInput());
    InflaterInputStream uncompressIs = new InflaterInputStream(byteString.newInput());
    ConfigurationProto confProto = ConfigurationProto.parseFrom(uncompressIs);
    Configuration conf = new Configuration(false);
    readConfFromPB(confProto, conf);
    return conf;
}

38. TezCommonUtils#decompressByteStringToByteArray()

Project: incubator-tez
File: TezCommonUtils.java
@Private
public static byte[] decompressByteStringToByteArray(ByteString byteString) throws IOException {
    InflaterInputStream in = new InflaterInputStream(byteString.newInput());
    byte[] bytes = IOUtils.toByteArray(in);
    return bytes;
}

39. ObjectUtils#readCompressedObject()

Project: hivemall
File: ObjectUtils.java
public static void readCompressedObject(@Nonnull final byte[] src, final int offset, final int length, @Nonnull final Externalizable dst) throws IOException, ClassNotFoundException {
    FastByteArrayInputStream bis = new FastByteArrayInputStream(src, offset, length);
    final InflaterInputStream iis = new InflaterInputStream(bis);
    try {
        readObject(iis, dst);
    } finally {
        IOUtils.closeQuietly(iis);
    }
}

40. ObjectUtils#readCompressedObject()

Project: hivemall
File: ObjectUtils.java
public static void readCompressedObject(@Nonnull final byte[] src, @Nonnull final Externalizable dst) throws IOException, ClassNotFoundException {
    FastByteArrayInputStream bis = new FastByteArrayInputStream(src);
    final InflaterInputStream iis = new InflaterInputStream(bis);
    try {
        readObject(iis, dst);
    } finally {
        IOUtils.closeQuietly(iis);
    }
}

41. ObjectUtils#readCompressedObject()

Project: hivemall
File: ObjectUtils.java
public static <T> T readCompressedObject(@Nonnull final byte[] obj) throws IOException, ClassNotFoundException {
    FastByteArrayInputStream bis = new FastByteArrayInputStream(obj);
    final InflaterInputStream iis = new InflaterInputStream(bis);
    try {
        return readObject(iis);
    } finally {
        IOUtils.closeQuietly(iis);
    }
}

42. Tools#decompressZlib()

Project: graylog2-server
File: Tools.java
/**
     * Decompress ZLIB (RFC 1950) compressed data
     *
     * @return A string containing the decompressed data
     */
public static String decompressZlib(byte[] compressedData) throws IOException {
    try (final ByteArrayInputStream dataStream = new ByteArrayInputStream(compressedData);
        final InflaterInputStream in = new InflaterInputStream(dataStream)) {
        return new String(ByteStreams.toByteArray(in), StandardCharsets.UTF_8);
    }
}

43. DictionaryFactory#loadWordList()

Project: freeplane
File: DictionaryFactory.java
/**
	 * Load the directory from a compressed list of words with UTF8 encoding. The words must be delimmited with
	 * newlines. This method can be called multiple times.
	 * 
	 * @param filename
	 *            the name of the file
	 * @throws IOException
	 *             If an I/O error occurs.
	 * @throws NullPointerException
	 *             If filename is null.
	 */
public void loadWordList(final URL filename) throws IOException {
    final URLConnection conn = filename.openConnection();
    conn.setReadTimeout(5000);
    InputStream input = conn.getInputStream();
    input = new InflaterInputStream(input);
    input = new BufferedInputStream(input);
    loadPlainWordList(input, "UTF8");
}

44. ImageEncoderPNG#writeTo()

Project: fop
File: ImageEncoderPNG.java
/** {@inheritDoc} */
public void writeTo(OutputStream out) throws IOException {
    // TODO: refactor this code with equivalent PDF code
    InputStream in = ((ImageRawStream) image).createInputStream();
    InflaterInputStream infStream = null;
    DataInputStream dataStream = null;
    ByteArrayOutputStream baos = null;
    DeflaterOutputStream dos = null;
    try {
        if (numberOfInterleavedComponents == 1 || numberOfInterleavedComponents == 3) {
            // means we have Gray, RGB, or Palette
            IOUtils.copy(in, out);
        } else {
            // means we have Gray + alpha or RGB + alpha
            // 1 for Gray, 3 for RGB
            int numBytes = numberOfInterleavedComponents - 1;
            int numColumns = image.getSize().getWidthPx();
            infStream = new InflaterInputStream(in, new Inflater());
            dataStream = new DataInputStream(infStream);
            int offset = 0;
            int bytesPerRow = numberOfInterleavedComponents * numColumns;
            int filter;
            // here we need to inflate the PNG pixel data, which includes alpha, separate the alpha
            // channel and then deflate the RGB channels back again
            // TODO: not using the baos below and using the original out instead (as happens in PDF)
            // would be preferable but that does not work with the rest of the postscript code; this
            // needs to be revisited
            baos = new ByteArrayOutputStream();
            dos = new DeflaterOutputStream(/* out */
            baos, new Deflater());
            while ((filter = dataStream.read()) != -1) {
                byte[] bytes = new byte[bytesPerRow];
                dataStream.readFully(bytes, 0, bytesPerRow);
                dos.write((byte) filter);
                for (int j = 0; j < numColumns; j++) {
                    dos.write(bytes, offset, numBytes);
                    offset += numberOfInterleavedComponents;
                }
                offset = 0;
            }
            dos.close();
            IOUtils.copy(new ByteArrayInputStream(baos.toByteArray()), out);
        }
    } finally {
        IOUtils.closeQuietly(dos);
        IOUtils.closeQuietly(baos);
        IOUtils.closeQuietly(dataStream);
        IOUtils.closeQuietly(infStream);
        IOUtils.closeQuietly(in);
    }
}

45. BiDiGzipHandler#wrapDeflatedRequest()

Project: dropwizard
File: BiDiGzipHandler.java
private WrappedServletRequest wrapDeflatedRequest(HttpServletRequest request) throws IOException {
    final Inflater inflater = buildInflater();
    final InflaterInputStream input = new InflaterInputStream(request.getInputStream(), inflater, inputBufferSize) {

        @Override
        public void close() throws IOException {
            super.close();
            localInflater.set(inflater);
        }
    };
    return new WrappedServletRequest(request, input);
}

46. CAFS#getSha1Stream()

Project: bnd
File: CAFS.java
private InputStream getSha1Stream(final SHA1 sha1, byte[] buffer, final int total) throws NoSuchAlgorithmException {
    ByteArrayInputStream in = new ByteArrayInputStream(buffer);
    InflaterInputStream iin = new InflaterInputStream(in) {

        int count = 0;

        final MessageDigest digestx = MessageDigest.getInstance(ALGORITHM);

        final AtomicBoolean calculated = new AtomicBoolean();

        @Override
        public int read(byte[] data, int offset, int length) throws IOException {
            int size = super.read(data, offset, length);
            if (size <= 0)
                eof();
            else {
                count += size;
                this.digestx.update(data, offset, size);
            }
            return size;
        }

        @Override
        public int read() throws IOException {
            int c = super.read();
            if (c < 0)
                eof();
            else {
                count++;
                this.digestx.update((byte) c);
            }
            return c;
        }

        void eof() throws IOException {
            if (calculated.getAndSet(true))
                return;
            if (count != total)
                throw new IOException("Counts do not match. Expected to read: " + total + " Actually read: " + count);
            SHA1 calculatedSha1 = new SHA1(digestx.digest());
            if (!sha1.equals(calculatedSha1))
                throw (new IOException("SHA1 caclulated and asked mismatch, asked: " + sha1 + ", \nfound: " + calculatedSha1));
        }

        @Override
        public void close() throws IOException {
            eof();
            super.close();
        }
    };
    return iin;
}

47. DeflateUtils#inflateBestEffort()

Project: anthelion
File: DeflateUtils.java
/**
   * Returns an inflated copy of the input array, truncated to
   * <code>sizeLimit</code> bytes, if necessary.  If the deflated input
   * has been truncated or corrupted, a best-effort attempt is made to
   * inflate as much as possible.  If no data can be extracted
   * <code>null</code> is returned.
   */
public static final byte[] inflateBestEffort(byte[] in, int sizeLimit) {
    // decompress using InflaterInputStream 
    ByteArrayOutputStream outStream = new ByteArrayOutputStream(EXPECTED_COMPRESSION_RATIO * in.length);
    // "true" because HTTP does not provide zlib headers
    Inflater inflater = new Inflater(true);
    InflaterInputStream inStream = new InflaterInputStream(new ByteArrayInputStream(in), inflater);
    byte[] buf = new byte[BUF_SIZE];
    int written = 0;
    while (true) {
        try {
            int size = inStream.read(buf);
            if (size <= 0)
                break;
            if ((written + size) > sizeLimit) {
                outStream.write(buf, 0, sizeLimit - written);
                break;
            }
            outStream.write(buf, 0, size);
            written += size;
        } catch (Exception e) {
            LOG.info("Caught Exception in inflateBestEffort", e);
            break;
        }
    }
    try {
        outStream.close();
    } catch (IOException e) {
    }
    return outStream.toByteArray();
}