Search in sources :

Example 21 with InflaterInputStream

use of java.util.zip.InflaterInputStream in project bazel by bazelbuild.

the class ZipCombiner method addZip.

/**
   * Adds the contents of a ZIP file to the combined ZIP file using the specified
   * {@link ZipEntryFilter} to determine the appropriate action for each file. 
   *
   * @param zipFile the ZIP file to add to the combined ZIP file
   * @throws IOException if there is an error reading the ZIP file or writing entries to the
   *     combined ZIP file
   */
public void addZip(File zipFile) throws IOException {
    try (ZipReader zip = new ZipReader(zipFile)) {
        for (ZipFileEntry entry : zip.entries()) {
            String filename = entry.getName();
            EntryAction action = getAction(filename);
            switch(action.getType()) {
                case SKIP:
                    break;
                case COPY:
                case RENAME:
                    writeEntry(zip, entry, action);
                    break;
                case MERGE:
                    entries.put(filename, null);
                    InputStream in = zip.getRawInputStream(entry);
                    if (entry.getMethod() == Compression.DEFLATED) {
                        in = new InflaterInputStream(in, getInflater());
                    }
                    action.getStrategy().merge(in, action.getMergeBuffer());
                    break;
            }
        }
    }
}
Also used : InflaterInputStream(java.util.zip.InflaterInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) DeflaterInputStream(java.util.zip.DeflaterInputStream) InputStream(java.io.InputStream) InflaterInputStream(java.util.zip.InflaterInputStream) ZipReader(com.google.devtools.build.zip.ZipReader) ZipFileEntry(com.google.devtools.build.zip.ZipFileEntry)

Example 22 with InflaterInputStream

use of java.util.zip.InflaterInputStream in project j2objc by google.

the class DeflaterInputStreamTest method inflate.

public byte[] inflate(byte[] bytes) throws IOException {
    java.io.InputStream in = new InflaterInputStream(new ByteArrayInputStream(bytes));
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    byte[] buffer = new byte[1024];
    int count;
    while ((count = in.read(buffer)) != -1) {
        out.write(buffer, 0, count);
    }
    return out.toByteArray();
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InflaterInputStream(java.util.zip.InflaterInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) InputStream(java.io.InputStream)

Example 23 with InflaterInputStream

use of java.util.zip.InflaterInputStream in project android_frameworks_base by DirtyUnicorns.

the class BlobBackupHelper method inflate.

// Returns null if inflation failed
private byte[] inflate(byte[] compressedData) {
    byte[] result = null;
    if (compressedData != null) {
        try {
            ByteArrayInputStream source = new ByteArrayInputStream(compressedData);
            DataInputStream headerIn = new DataInputStream(source);
            int version = headerIn.readInt();
            if (version > mCurrentBlobVersion) {
                Log.w(TAG, "Saved payload from unrecognized version " + version);
                return null;
            }
            InflaterInputStream in = new InflaterInputStream(source);
            ByteArrayOutputStream inflated = new ByteArrayOutputStream();
            byte[] buffer = new byte[4096];
            int nRead;
            while ((nRead = in.read(buffer)) > 0) {
                inflated.write(buffer, 0, nRead);
            }
            in.close();
            inflated.flush();
            result = inflated.toByteArray();
            if (DEBUG) {
                Log.v(TAG, "Inflated " + compressedData.length + " bytes to " + result.length);
            }
        } catch (IOException e) {
            // result is still null here
            Log.w(TAG, "Unable to process restored payload: " + e.getMessage());
        }
    }
    return result;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InflaterInputStream(java.util.zip.InflaterInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream)

Example 24 with InflaterInputStream

use of java.util.zip.InflaterInputStream in project jdk8u_jdk by JetBrains.

the class MyInputStream method main.

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();
}
Also used : InflaterInputStream(java.util.zip.InflaterInputStream) ZipInputStream(java.util.zip.ZipInputStream) DeflaterOutputStream(java.util.zip.DeflaterOutputStream)

Example 25 with InflaterInputStream

use of java.util.zip.InflaterInputStream in project OpenAM by OpenRock.

the class IOUtils method deserialise.

/**
     * Deserialises an object from a byte array to an object of a specified type.
     *
     * @param bytes The bytes that represent the Object to be deserialized. The classes to be loaded must be from the
     *              set specified in the whitelist maintained in the <code>WhitelistObjectInputStream</code>
     * @param compressed If true, expect that the bytes are compressed.
     * @param classLoader Used in place of the default ClassLoader, default will be used if null.
     * @param <T> The returned object type.
     * @return The Object T representing the deserialized bytes
     * @throws IOException If there was a problem with the ObjectInputStream process.
     * @throws ClassNotFoundException If there was problem loading a class that makes up the bytes to be deserialized.
     */
public static <T> T deserialise(byte[] bytes, boolean compressed, ClassLoader classLoader) throws IOException, ClassNotFoundException {
    final ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
    final ObjectInputStream ois = compressed ? new WhitelistObjectInputStream(new InflaterInputStream(bais), classLoader) : new WhitelistObjectInputStream(bais, classLoader);
    final T result;
    try {
        result = (T) ois.readObject();
    } finally {
        closeIfNotNull(ois);
    }
    return result;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InflaterInputStream(java.util.zip.InflaterInputStream) ObjectInputStream(java.io.ObjectInputStream)

Aggregations

InflaterInputStream (java.util.zip.InflaterInputStream)91 ByteArrayInputStream (java.io.ByteArrayInputStream)49 InputStream (java.io.InputStream)46 IOException (java.io.IOException)38 ByteArrayOutputStream (java.io.ByteArrayOutputStream)33 Inflater (java.util.zip.Inflater)33 GZIPInputStream (java.util.zip.GZIPInputStream)26 DataInputStream (java.io.DataInputStream)16 BufferedInputStream (java.io.BufferedInputStream)11 HttpURLConnection (java.net.HttpURLConnection)9 OutputStream (java.io.OutputStream)8 URL (java.net.URL)8 DeflaterOutputStream (java.util.zip.DeflaterOutputStream)8 BufferedReader (java.io.BufferedReader)6 InputStreamReader (java.io.InputStreamReader)6 URLConnection (java.net.URLConnection)6 EOFException (java.io.EOFException)5 DataOutputStream (java.io.DataOutputStream)4 OutputStreamWriter (java.io.OutputStreamWriter)4 SocketException (java.net.SocketException)4