Search in sources :

Example 56 with InflaterInputStream

use of java.util.zip.InflaterInputStream in project DragonProxy by DragonetMC.

the class Zlib method inflate.

public static byte[] inflate(InputStream stream) throws IOException {
    InflaterInputStream inputStream = new InflaterInputStream(stream);
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    byte[] buffer = new byte[1024];
    int length;
    try {
        while ((length = inputStream.read(buffer)) != -1) {
            outputStream.write(buffer, 0, length);
        }
    } finally {
        buffer = outputStream.toByteArray();
        outputStream.flush();
        outputStream.close();
        inputStream.close();
    }
    return buffer;
}
Also used : InflaterInputStream(java.util.zip.InflaterInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 57 with InflaterInputStream

use of java.util.zip.InflaterInputStream in project LibreraReader by foobnix.

the class ZipFile method getInputStream.

/**
 * Returns an InputStream for reading the contents of the given entry.
 *
 * @param ze the entry to get the stream for.
 * @return a stream to read the entry from.
 * @throws IOException if unable to create an input stream from the zipentry
 */
public InputStream getInputStream(final ZipArchiveEntry ze) throws IOException {
    if (!(ze instanceof Entry)) {
        return null;
    }
    // cast validity is checked just above
    ZipUtil.checkRequestedFeatures(ze);
    final long start = ze.getDataOffset();
    // doesn't get closed if the method is not supported - which
    // should never happen because of the checkRequestedFeatures
    // call above
    final InputStream is = // NOSONAR
    new BufferedInputStream(createBoundedInputStream(start, ze.getCompressedSize()));
    switch(ZipMethod.getMethodByCode(ze.getMethod())) {
        case STORED:
            return is;
        case UNSHRINKING:
            return new UnshrinkingInputStream(is);
        case IMPLODING:
            return new ExplodingInputStream(ze.getGeneralPurposeBit().getSlidingDictionarySize(), ze.getGeneralPurposeBit().getNumberOfShannonFanoTrees(), is);
        case DEFLATED:
            final Inflater inflater = new Inflater(true);
            // https://docs.oracle.com/javase/7/docs/api/java/util/zip/Inflater.html#Inflater(boolean)
            return new InflaterInputStream(new SequenceInputStream(is, new ByteArrayInputStream(ONE_ZERO_BYTE)), inflater) {

                @Override
                public void close() throws IOException {
                    try {
                        super.close();
                    } finally {
                        inflater.end();
                    }
                }
            };
        case BZIP2:
            return new BZip2CompressorInputStream(is);
        case ENHANCED_DEFLATED:
            return new Deflate64CompressorInputStream(is);
        case AES_ENCRYPTED:
        case EXPANDING_LEVEL_1:
        case EXPANDING_LEVEL_2:
        case EXPANDING_LEVEL_3:
        case EXPANDING_LEVEL_4:
        case JPEG:
        case LZMA:
        case PKWARE_IMPLODING:
        case PPMD:
        case TOKENIZATION:
        case UNKNOWN:
        case WAVPACK:
        case XZ:
        default:
            throw new ZipException("Found unsupported compression method " + ze.getMethod());
    }
}
Also used : BufferedInputStream(java.io.BufferedInputStream) InflaterInputStream(java.util.zip.InflaterInputStream) Deflate64CompressorInputStream(org.apache.commons.compress.compressors.deflate64.Deflate64CompressorInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) BZip2CompressorInputStream(org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream) SequenceInputStream(java.io.SequenceInputStream) InputStream(java.io.InputStream) InflaterInputStream(java.util.zip.InflaterInputStream) ZipException(java.util.zip.ZipException) SequenceInputStream(java.io.SequenceInputStream) BZip2CompressorInputStream(org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream) BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) Inflater(java.util.zip.Inflater) Deflate64CompressorInputStream(org.apache.commons.compress.compressors.deflate64.Deflate64CompressorInputStream)

Example 58 with InflaterInputStream

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

the class TezUtils method createConfFromByteString.

/**
 * 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;
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) InflaterInputStream(java.util.zip.InflaterInputStream) DAGProtos(org.apache.tez.dag.api.records.DAGProtos)

Example 59 with InflaterInputStream

use of java.util.zip.InflaterInputStream in project activemq-artemis by apache.

the class OpenWireMessageConverter method writeCompressedObjectType.

private static ByteSequence writeCompressedObjectType(final ByteSequence contents) throws IOException {
    try (InputStream ois = new InflaterInputStream(new ByteArrayInputStream(contents));
        org.apache.activemq.util.ByteArrayOutputStream decompressed = new org.apache.activemq.util.ByteArrayOutputStream()) {
        byte[] buf = new byte[1024];
        int n = ois.read(buf);
        while (n != -1) {
            decompressed.write(buf, 0, n);
            n = ois.read();
        }
        // read done
        return decompressed.toByteSequence();
    }
}
Also used : ByteArrayInputStream(org.apache.activemq.util.ByteArrayInputStream) DataInputStream(java.io.DataInputStream) InflaterInputStream(java.util.zip.InflaterInputStream) ByteArrayInputStream(org.apache.activemq.util.ByteArrayInputStream) InputStream(java.io.InputStream) InflaterInputStream(java.util.zip.InflaterInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 60 with InflaterInputStream

use of java.util.zip.InflaterInputStream in project activemq-artemis by apache.

the class OpenWireMessageConverter method writeMapType.

private static void writeMapType(final ByteSequence contents, final boolean messageCompressed, final ActiveMQBuffer body) throws IOException {
    InputStream mis = new ByteArrayInputStream(contents);
    if (messageCompressed) {
        mis = new InflaterInputStream(mis);
    }
    DataInputStream mdataIn = new DataInputStream(mis);
    Map<String, Object> map = MarshallingSupport.unmarshalPrimitiveMap(mdataIn);
    mdataIn.close();
    TypedProperties props = new TypedProperties();
    loadMapIntoProperties(props, map);
    props.encode(body.byteBuf());
}
Also used : ByteArrayInputStream(org.apache.activemq.util.ByteArrayInputStream) DataInputStream(java.io.DataInputStream) InflaterInputStream(java.util.zip.InflaterInputStream) ByteArrayInputStream(org.apache.activemq.util.ByteArrayInputStream) InputStream(java.io.InputStream) InflaterInputStream(java.util.zip.InflaterInputStream) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) DataInputStream(java.io.DataInputStream) TypedProperties(org.apache.activemq.artemis.utils.collections.TypedProperties)

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