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, Inflater inf) 

Source Link

Document

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

Usage

From source file:com.atlassian.extras.decoder.v2.Version2LicenseDecoder.java

private Reader unzipText(byte[] licenseText) {
    ByteArrayInputStream in = new ByteArrayInputStream(licenseText);
    in.skip(LICENSE_PREFIX.length);/*from w ww.ja  v a2  s. co m*/
    InflaterInputStream zipIn = new InflaterInputStream(in, new Inflater());
    try {
        return new InputStreamReader(zipIn, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        throw new LicenseException(e);
    }
}

From source file:org.apache.fop.render.ps.ImageEncoderPNG.java

/** {@inheritDoc} */
public void writeTo(OutputStream out) throws IOException {
    // TODO: refactor this code with equivalent PDF code
    InputStream in = ((ImageRawStream) image).createInputStream();
    try {//from  ww w . j  a  va 2s  .c o  m
        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
            int numBytes = numberOfInterleavedComponents - 1; // 1 for Gray, 3 for RGB
            int numColumns = image.getSize().getWidthPx();
            InflaterInputStream infStream = new InflaterInputStream(in, new Inflater());
            DataInputStream 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
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            DeflaterOutputStream 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(in);
    }
}

From source file:com.nesscomputing.tinyhttp.HttpContentResponseHandler.java

/**
 * Processes the client response.//from w  ww. j  a v a 2s. com
 */
public T handle(final HttpRequest request, final HttpResponse response) throws IOException {
    // Find the response stream - the error stream may be valid in cases
    // where the input stream is not.
    InputStream is = null;
    try {
        final HttpEntity httpEntity = response.getEntity();
        if (httpEntity != null) {
            is = httpEntity.getContent();
        }
    } catch (IOException e) {
        log.warn("Could not locate response body stream", e);
        // normal for 401, 403 and 404 responses, for example...
    }

    if (is == null) {
        // Fall back to zero length response.
        is = new NullInputStream(0);
    }

    final Header header = response.getFirstHeader("Content-Encoding");
    if (header != null) {
        final String encoding = StringUtils.trimToEmpty(header.getValue());

        if (StringUtils.equalsIgnoreCase(encoding, "gzip")
                || StringUtils.equalsIgnoreCase(encoding, "x-gzip")) {
            log.debug("Found GZIP stream");
            is = new GZIPInputStream(is);
        } else if (StringUtils.equalsIgnoreCase(encoding, "deflate")) {
            log.debug("Found deflate stream");
            final Inflater inflater = new Inflater(true);
            is = new InflaterInputStream(is, inflater);
        }
    }
    return contentConverter.convert(request, response, is);
}

From source file:org.slc.sli.sandbox.idp.saml.SamlRequestDecoder.java

public SamlRequest decode(String encodedSamlRequest) {
    byte[] decodedCompressed = Base64.decodeBase64(encodedSamlRequest);
    Inflater inflater = new Inflater(true);
    InflaterInputStream xmlInputStream = new InflaterInputStream(new ByteArrayInputStream(decodedCompressed),
            inflater);//from   ww  w. ja  v a 2s  . com
    Document doc;

    try {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        factory.setFeature("http://xml.org/sax/features/external-general-entities", false);
        factory.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
        factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
        DocumentBuilder docBuilder = factory.newDocumentBuilder();

        doc = docBuilder.parse(xmlInputStream);
    } catch (ParserConfigurationException e) {
        throw new SamlProcessException(e);
    } catch (SAXException e) {
        throw new SamlProcessException(e);
    } catch (IOException e) {
        throw new SamlProcessException(e);
    }
    Element element = doc.getDocumentElement();
    String id = element.getAttribute("ID");
    boolean forceAuthn = Boolean.valueOf(element.getAttribute("ForceAuthn"));
    String simpleIDPDestination = element.getAttribute("Destination");
    NodeList nodes = element.getElementsByTagName("saml:Issuer");
    String issuer = null;
    if (nodes.getLength() > 0) {
        Node item = nodes.item(0);
        issuer = item.getFirstChild().getNodeValue();
    } else {
        throw new IllegalArgumentException("No Issuer element on AuthnRequest");
    }

    if (id == null) {
        throw new IllegalArgumentException("No ID attribute on AuthnRequest.");
    }
    String responseDestination = cot.get(issuer);
    if (responseDestination == null) {
        throw new IllegalArgumentException("Issuer of AuthnRequest is unknown.");
    }

    return new SamlRequest(responseDestination, simpleIDPDestination, id, forceAuthn);
}

From source file:org.resthub.rpc.AMQPProxy.java

/**
 * Handles the object invocation.//from  www  .  j av a 2 s.c o m
 *
 * @param proxy  the proxy object to invoke
 * @param method the method to call
 * @param args   the arguments to the proxy object
 */
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    String methodName = method.getName();
    Class<?>[] params = method.getParameterTypes();

    // equals and hashCode are special cased
    if (methodName.equals("equals") && params.length == 1 && params[0].equals(Object.class)) {
        Object value = args[0];
        if (value == null || !Proxy.isProxyClass(value.getClass())) {
            return Boolean.FALSE;
        }

        AMQPProxy handler = (AMQPProxy) Proxy.getInvocationHandler(value);

        return _factory.equals(handler._factory);
    } else if (methodName.equals("hashCode") && params.length == 0) {
        return _factory.hashCode();
    } else if (methodName.equals("toString") && params.length == 0) {
        return "[HessianProxy " + proxy.getClass() + "]";
    }

    ConnectionFactory connectionFactory = _factory.getConnectionFactory();

    Message response = sendRequest(connectionFactory, method, args);

    if (response == null) {
        throw new TimeoutException();
    }

    MessageProperties props = response.getMessageProperties();
    boolean compressed = "deflate".equals(props.getContentEncoding());

    InputStream is = new ByteArrayInputStream(response.getBody());
    if (compressed) {
        is = new InflaterInputStream(is, new Inflater(true));
    }

    return _factory.getSerializationHandler().readObject(method.getReturnType(), is);
}

From source file:com.vimukti.accounter.license.LicenseManager.java

private Reader unzipText(byte[] licenseText) {
    ByteArrayInputStream in = new ByteArrayInputStream(licenseText);
    InflaterInputStream zipIn = new InflaterInputStream(in, new Inflater());
    try {//w  ww  .  ja v  a2 s . co m
        return new InputStreamReader(zipIn, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        throw new LicenseException(e);
    }

}

From source file:Decoder.java

private Reader unzipText(byte[] licenseText) throws Exception {
    ByteArrayInputStream in = new ByteArrayInputStream(licenseText);
    in.skip(LICENSE_PREFIX.length);//from  w  w  w . ja va 2s  .c  o  m
    InflaterInputStream zipIn = new InflaterInputStream(in, new Inflater());
    try {
        return new InputStreamReader(zipIn, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        throw new Exception(e);
    }
}

From source file:cn.vko.hessian.core.VkoHessianProxy.java

@Override
protected InputStream getInputStream(HessianConnection conn) throws IOException {
    InputStream is = conn.getInputStream();
    byte[] content = IOUtils.toByteArray(is);
    is.close();// w  w w .  ja v a2 s . c om
    if (factory.isEncrypt()) {
        // 
        content = factory.getEncrypt().decrypt(content);
    }
    if ("lz4".equals(conn.getContentEncoding())) {
        content = Lz4Compress.uncompress(content);
        is = new ByteArrayInputStream(content);
    } else if ("deflate".equals(conn.getContentEncoding())) {
        is = new InflaterInputStream(new ByteArrayInputStream(content), new Inflater(true));
    }
    return is;
}

From source file:org.resthub.rpc.AMQPHessianProxy.java

/**
 * Handles the object invocation.//  w ww .  j a v a  2 s .  c  o  m
 *
 * @param proxy  the proxy object to invoke
 * @param method the method to call
 * @param args   the arguments to the proxy object
 */
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    String methodName = method.getName();
    Class<?>[] params = method.getParameterTypes();

    // equals and hashCode are special cased
    if (methodName.equals("equals") && params.length == 1 && params[0].equals(Object.class)) {
        Object value = args[0];
        if (value == null || !Proxy.isProxyClass(value.getClass())) {
            return Boolean.FALSE;
        }

        AMQPHessianProxy handler = (AMQPHessianProxy) Proxy.getInvocationHandler(value);

        return _factory.equals(handler._factory);
    } else if (methodName.equals("hashCode") && params.length == 0) {
        return _factory.hashCode();
    } else if (methodName.equals("toString") && params.length == 0) {
        return "[HessianProxy " + proxy.getClass() + "]";
    }

    ConnectionFactory connectionFactory = _factory.getConnectionFactory();

    try {
        Message response = sendRequest(connectionFactory, method, args);

        if (response == null) {
            throw new TimeoutException();
        }

        MessageProperties props = response.getMessageProperties();
        boolean compressed = "deflate".equals(props.getContentEncoding());

        AbstractHessianInput in;

        InputStream is = new ByteArrayInputStream(response.getBody());
        if (compressed) {
            is = new InflaterInputStream(is, new Inflater(true));
        }

        int code = is.read();

        if (code == 'H') {
            int major = is.read();
            int minor = is.read();

            in = _factory.getHessian2Input(is);

            return in.readReply(method.getReturnType());
        } else if (code == 'r') {
            int major = is.read();
            int minor = is.read();

            in = _factory.getHessianInput(is);

            in.startReplyBody();

            Object value = in.readObject(method.getReturnType());

            in.completeReply();

            return value;
        } else {
            throw new HessianProtocolException("'" + (char) code + "' is an unknown code");
        }
    } catch (HessianProtocolException e) {
        throw new HessianRuntimeException(e);
    }
}

From source file:Version2LicenseDecoder.java

private Reader unzipText(byte[] licenseText) {
    ByteArrayInputStream in = new ByteArrayInputStream(licenseText);
    in.skip((long) LICENSE_PREFIX.length);
    InflaterInputStream zipIn = new InflaterInputStream(in, new Inflater());

    try {/*from   www.j a v  a 2 s.  c  om*/
        return new InputStreamReader(zipIn, "UTF-8");
    } catch (UnsupportedEncodingException var5) {
        throw new LicenseException(var5);
    }
}