Search in sources :

Example 86 with InflaterInputStream

use of java.util.zip.InflaterInputStream in project gerrit by GerritCodeReview.

the class PatchList method readObject.

private void readObject(ObjectInputStream input) throws IOException {
    final ByteArrayInputStream buf = new ByteArrayInputStream(readBytes(input));
    try (InflaterInputStream in = new InflaterInputStream(buf)) {
        oldId = read(in);
        newId = readWithoutMarker(in);
        isMerge = readVarInt32(in) != 0;
        comparisonType = ComparisonType.readFrom(in);
        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;
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InflaterInputStream(java.util.zip.InflaterInputStream)

Example 87 with InflaterInputStream

use of java.util.zip.InflaterInputStream in project okio by square.

the class DeflaterSinkTest method inflate.

/**
 * Uses streaming decompression to inflate {@code deflated}. The input must
 * either be finished or have a trailing sync flush.
 */
private Buffer inflate(Buffer deflated) throws IOException {
    InputStream deflatedIn = deflated.inputStream();
    Inflater inflater = new Inflater();
    InputStream inflatedIn = new InflaterInputStream(deflatedIn, inflater);
    Buffer result = new Buffer();
    byte[] buffer = new byte[8192];
    while (!inflater.needsInput() || deflated.size() > 0 || deflatedIn.available() > 0) {
        int count = inflatedIn.read(buffer, 0, buffer.length);
        if (count != -1) {
            result.write(buffer, 0, count);
        }
    }
    return result;
}
Also used : InflaterInputStream(java.util.zip.InflaterInputStream) InputStream(java.io.InputStream) InflaterInputStream(java.util.zip.InflaterInputStream) Inflater(java.util.zip.Inflater)

Example 88 with InflaterInputStream

use of java.util.zip.InflaterInputStream in project ddf by codice.

the class SamlSecurity method inflateBase64.

@Override
public String inflateBase64(String base64EncodedValue) throws IOException {
    if (base64EncodedValue == null) {
        return "";
    }
    byte[] deflatedValue = Base64.getMimeDecoder().decode(base64EncodedValue.getBytes(StandardCharsets.UTF_8));
    InputStream is = new InflaterInputStream(new ByteArrayInputStream(deflatedValue), new Inflater(GZIP_COMPATIBLE));
    return IOUtils.toString(is, StandardCharsets.UTF_8.name());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InflaterInputStream(java.util.zip.InflaterInputStream) InputStream(java.io.InputStream) InflaterInputStream(java.util.zip.InflaterInputStream) Inflater(java.util.zip.Inflater)

Example 89 with InflaterInputStream

use of java.util.zip.InflaterInputStream in project ddf by codice.

the class SamlSecurityTest method testInflateDeflateWithTokenDuplication.

@Test
public void testInflateDeflateWithTokenDuplication() throws Exception {
    String token = "valid_grant valid_grant valid_grant valid_grant valid_grant valid_grant";
    DeflateEncoderDecoder deflateEncoderDecoder = new DeflateEncoderDecoder();
    byte[] deflatedToken = deflateEncoderDecoder.deflateToken(token.getBytes());
    String cxfInflatedToken = IOUtils.toString(deflateEncoderDecoder.inflateToken(deflatedToken));
    String streamInflatedToken = IOUtils.toString(new InflaterInputStream(new ByteArrayInputStream(deflatedToken), new Inflater(true)));
    assertNotSame(cxfInflatedToken, token);
    assertEquals(streamInflatedToken, token);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InflaterInputStream(java.util.zip.InflaterInputStream) Inflater(java.util.zip.Inflater) DeflateEncoderDecoder(org.apache.cxf.rs.security.saml.DeflateEncoderDecoder) Test(org.junit.Test)

Example 90 with InflaterInputStream

use of java.util.zip.InflaterInputStream in project nutch by apache.

the class DeflateUtils method inflate.

/**
 * Returns an inflated copy of the input array.
 * @param in Deflated byte array
 * @return An inflated copy of the input array, otherwise null
 * @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();
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InflaterInputStream(java.util.zip.InflaterInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Aggregations

InflaterInputStream (java.util.zip.InflaterInputStream)200 ByteArrayInputStream (java.io.ByteArrayInputStream)113 InputStream (java.io.InputStream)100 IOException (java.io.IOException)74 Inflater (java.util.zip.Inflater)66 ByteArrayOutputStream (java.io.ByteArrayOutputStream)50 GZIPInputStream (java.util.zip.GZIPInputStream)39 DataInputStream (java.io.DataInputStream)33 FileInputStream (java.io.FileInputStream)27 BufferedInputStream (java.io.BufferedInputStream)24 InputStreamReader (java.io.InputStreamReader)13 DeflaterOutputStream (java.util.zip.DeflaterOutputStream)13 HttpURLConnection (java.net.HttpURLConnection)12 URL (java.net.URL)11 File (java.io.File)10 BufferedReader (java.io.BufferedReader)9 OutputStream (java.io.OutputStream)9 Point (java.awt.Point)7 EOFException (java.io.EOFException)7 URLConnection (java.net.URLConnection)7