Example usage for java.util.zip InflaterInputStream InflaterInputStream

List of usage examples for java.util.zip InflaterInputStream InflaterInputStream

Introduction

In this page you can find the example usage for java.util.zip InflaterInputStream InflaterInputStream.

Prototype

public InflaterInputStream(InputStream in) 

Source Link

Document

Creates a new input stream with a default decompressor and buffer size.

Usage

From source file:org.projectnyx.network.mcpe.mcpe.LoginPacket.java

@Override
@SneakyThrows({ IOException.class })
public void read() {
    protocol = readInt();//  www . j av a2 s . co m
    byte[] deflated = readBytes(Math.min(readLInt(), 64 << 20));
    setBuffer(
            ByteBuffer.wrap(IOUtils.toByteArray(new InflaterInputStream(new ByteArrayInputStream(deflated)))));

    byte[] json = readBytes(readLInt());
    System.err.println(new String(json));
    JSONObject object = new JSONObject();
}

From source file:ubicrypt.core.crypto.AESGCMTest.java

@Test
public void testName() throws Exception {
    final byte[] key = AESGCM.rndKey();
    final ByteArrayInputStream bis = new ByteArrayInputStream("Ciao".getBytes());
    final InputStream cipherStream = new DeflaterInputStream(encryptIs(key, bis));
    final InputStream decrypt2InputStream = decryptIs(key, new InflaterInputStream(cipherStream));
    Assertions.assertThat(IOUtils.toString(decrypt2InputStream)).isEqualTo("Ciao");
}

From source file:org.apache.pig.impl.util.ObjectSerializer.java

public static Object deserialize(String str) throws IOException {
    if (str == null || str.length() == 0)
        return null;
    ObjectInputStream objStream = null;
    try {/*from   w  w  w .  jav  a  2 s  . c o  m*/
        ByteArrayInputStream serialObj = new ByteArrayInputStream(decodeBytes(str));
        objStream = new ClassLoaderObjectInputStream(Thread.currentThread().getContextClassLoader(),
                new InflaterInputStream(serialObj));
        return objStream.readObject();
    } catch (Exception e) {
        throw new IOException("Deserialization error: " + e.getMessage(), e);
    } finally {
        IOUtils.closeQuietly(objStream);
    }
}

From source file:org.fejoa.library.messages.ZipEnvelope.java

static public byte[] unzip(JSONObject header, InputStream inputStream) throws IOException, JSONException {
    // verify//w  w w  .j  a  v  a2s.  c o  m
    if (!header.getString(ZIP_FORMAT_KEY).equals(ZIP_FORMAT))
        throw new IOException("Unsupported zip format: " + header.getString(ZIP_FORMAT_KEY));

    InflaterInputStream inflaterInputStream = new InflaterInputStream(inputStream);
    ByteArrayOutputStream outStream = new ByteArrayOutputStream();
    StreamHelper.copy(inflaterInputStream, outStream);
    return outStream.toByteArray();
}

From source file:org.droidparts.http.worker.HTTPInputStream.java

private static InputStream getUnpackedInputStream(String contentEncoding, InputStream is) throws IOException {
    L.d("Content-Encoding: " + contentEncoding);
    if (isNotEmpty(contentEncoding)) {
        contentEncoding = contentEncoding.toLowerCase();
        if (contentEncoding.contains("gzip")) {
            return new GZIPInputStream(is);
        } else if (contentEncoding.contains("deflate")) {
            return new InflaterInputStream(is);
        }//from  ww  w . j a va2 s . c  o m
    }
    return is;
}

From source file:org.wso2.carbon.identity.sso.saml.tomcat.agent.Util.java

/**
 * Decoding and deflating the encoded AuthReq
 *
 * @param encodedStr//from   w ww . j a v a  2 s.  co m
 *            encoded AuthReq
 * @return decoded AuthReq
 */
public static String decode(String encodedStr) throws SSOAgentException {
    try {
        org.apache.commons.codec.binary.Base64 base64Decoder = new org.apache.commons.codec.binary.Base64();
        byte[] xmlBytes = encodedStr.getBytes("UTF-8");
        byte[] base64DecodedByteArray = base64Decoder.decode(xmlBytes);

        try {
            Inflater inflater = new Inflater(true);
            inflater.setInput(base64DecodedByteArray);
            byte[] xmlMessageBytes = new byte[5000];
            int resultLength = inflater.inflate(xmlMessageBytes);

            if (inflater.getRemaining() > 0) {
                throw new RuntimeException("didn't allocate enough space to hold " + "decompressed data");
            }

            inflater.end();
            return new String(xmlMessageBytes, 0, resultLength, "UTF-8");

        } catch (DataFormatException e) {
            ByteArrayInputStream bais = new ByteArrayInputStream(base64DecodedByteArray);
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            InflaterInputStream iis = new InflaterInputStream(bais);
            byte[] buf = new byte[1024];
            int count = iis.read(buf);
            while (count != -1) {
                baos.write(buf, 0, count);
                count = iis.read(buf);
            }
            iis.close();
            return new String(baos.toByteArray());
        }
    } catch (IOException e) {
        throw new SSOAgentException("Error when decoding the SAML Request.", e);
    }
}

From source file:co.freeside.betamax.message.AbstractMessage.java

/**
 * A default implementation that decodes the byte stream from `getBodyAsBinary`. Implementations can override this
 * if they have a simpler way of doing it.
 *///from ww  w  .  ja  v a 2 s  .  c om
public Reader getBodyAsText() throws IOException {
    InputStream stream;
    String encoding = getEncoding();
    if ("gzip".equals(encoding)) {
        stream = new GZIPInputStream(getBodyAsBinary());
    } else if ("deflate".equals(encoding)) {
        stream = new InflaterInputStream(getBodyAsBinary());
    } else {
        stream = getBodyAsBinary();
    }
    return new InputStreamReader(stream, getCharset());
}

From source file:com.faceye.feature.util.http.DeflateUtils.java

/**
 * Returns an inflated copy of the input array.  
 * @throws IOException if the input cannot be properly decompressed
 *///from ww  w. j  a  va 2 s. c o  m
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();
}

From source file:org.taverna.server.master.common.Workflow.java

@Override
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
    try {/* w  w  w .java2 s  .  c o m*/
        int len = in.readInt();
        byte[] bytes = new byte[len];
        in.readFully(bytes);
        Reader r = new InputStreamReader(new InflaterInputStream(new ByteArrayInputStream(bytes)), ENCODING);
        Workflow w = (Workflow) unmarshaller.unmarshal(r);
        r.close();
        this.content = w.content;
        return;
    } catch (JAXBException e) {
        throw new IOException("failed to unmarshal", e);
    } catch (ClassCastException e) {
        throw new IOException("bizarre result of unmarshalling", e);
    }
}

From source file:com.eviware.soapui.impl.wsdl.support.CompressionSupport.java

public static InputStream createCompressionInputStream(String alg, byte[] content) throws Exception {
    checkAlg(alg);/*from  w w  w.j av a 2 s  .c  o m*/
    ByteArrayInputStream bais = new ByteArrayInputStream(content);
    if (ALG_GZIP.equals(alg)) {
        return new GZIPInputStream(bais);
    } else if (ALG_DEFLATE.equals(alg)) {
        return new InflaterInputStream(bais);
    } else {
        return null;
    }
}