Search in sources :

Example 26 with InflaterInputStream

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

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 27 with InflaterInputStream

use of java.util.zip.InflaterInputStream in project voltdb by VoltDB.

the class FileArchiver method unarchive.

public static void unarchive(String infilename, String outfilename, FileAccess storage, int compressionType) throws IOException {
    InputStream f = null;
    OutputStream outstream = null;
    boolean completed = false;
    try {
        if (!storage.isStreamElement(infilename)) {
            return;
        }
        storage.removeElement(outfilename);
        byte[] b = new byte[COPY_BLOCK_SIZE];
        f = storage.openInputStreamElement(infilename);
        switch(compressionType) {
            case COMPRESSION_ZIP:
                f = new InflaterInputStream(f, new Inflater());
                break;
            case COMPRESSION_GZIP:
                f = new GZIPInputStream(f, b.length);
                break;
            case COMPRESSION_NONE:
                break;
            default:
                throw new RuntimeException("FileArchiver: " + compressionType);
        }
        outstream = storage.openOutputStreamElement(outfilename);
        while (true) {
            int l = f.read(b, 0, b.length);
            if (l == -1) {
                break;
            }
            outstream.write(b, 0, l);
        }
        completed = true;
    } catch (Throwable e) {
        throw FileUtil.toIOException(e);
    } finally {
        try {
            if (f != null) {
                f.close();
            }
            if (outstream != null) {
                outstream.flush();
                outstream.close();
            }
            if (!completed && storage.isStreamElement(outfilename)) {
                storage.removeElement(outfilename);
            }
        } catch (Throwable e) {
            throw FileUtil.toIOException(e);
        }
    }
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) GZIPInputStream(java.util.zip.GZIPInputStream) InflaterInputStream(java.util.zip.InflaterInputStream) InputStream(java.io.InputStream) InflaterInputStream(java.util.zip.InflaterInputStream) OutputStream(java.io.OutputStream) GZIPOutputStream(java.util.zip.GZIPOutputStream) DeflaterOutputStream(java.util.zip.DeflaterOutputStream) Inflater(java.util.zip.Inflater)

Example 28 with InflaterInputStream

use of java.util.zip.InflaterInputStream in project voltdb by VoltDB.

the class ScriptReaderZipped method openFile.

protected void openFile() throws IOException {
    InputStream d = db.isFilesInJar() ? getClass().getResourceAsStream(fileName) : db.getFileAccess().openInputStreamElement(fileName);
    dataStreamIn = new DataInputStream(new BufferedInputStream(new InflaterInputStream(d, new Inflater()), 1 << 13));
}
Also used : BufferedInputStream(java.io.BufferedInputStream) DataInputStream(java.io.DataInputStream) BufferedInputStream(java.io.BufferedInputStream) InflaterInputStream(java.util.zip.InflaterInputStream) InputStream(java.io.InputStream) InflaterInputStream(java.util.zip.InflaterInputStream) Inflater(java.util.zip.Inflater) DataInputStream(java.io.DataInputStream)

Example 29 with InflaterInputStream

use of java.util.zip.InflaterInputStream in project voltdb by VoltDB.

the class Encoder method decodeBase64AndDecompressToBytes.

public static byte[] decodeBase64AndDecompressToBytes(String string) {
    byte[] bytes = Base64.decodeFast(string);
    if (string.length() == 0) {
        return new byte[0];
    }
    ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
    InflaterInputStream dis = new InflaterInputStream(bais);
    byte[] buffer = new byte[1024 * 8];
    int length = 0;
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try {
        while ((length = dis.read(buffer)) >= 0) {
            baos.write(buffer, 0, length);
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return baos.toByteArray();
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InflaterInputStream(java.util.zip.InflaterInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 30 with InflaterInputStream

use of java.util.zip.InflaterInputStream in project mc-dev by Bukkit.

the class RegionFile method a.

public synchronized DataInputStream a(int i, int j) {
    if (this.d(i, j)) {
        return null;
    } else {
        try {
            int k = this.e(i, j);
            if (k == 0) {
                return null;
            } else {
                int l = k >> 8;
                int i1 = k & 255;
                if (l + i1 > this.f.size()) {
                    return null;
                } else {
                    this.c.seek((long) (l * 4096));
                    int j1 = this.c.readInt();
                    if (j1 > 4096 * i1) {
                        return null;
                    } else if (j1 <= 0) {
                        return null;
                    } else {
                        byte b0 = this.c.readByte();
                        byte[] abyte;
                        if (b0 == 1) {
                            abyte = new byte[j1 - 1];
                            this.c.read(abyte);
                            return new DataInputStream(new BufferedInputStream(new GZIPInputStream(new ByteArrayInputStream(abyte))));
                        } else if (b0 == 2) {
                            abyte = new byte[j1 - 1];
                            this.c.read(abyte);
                            return new DataInputStream(new BufferedInputStream(new InflaterInputStream(new ByteArrayInputStream(abyte))));
                        } else {
                            return null;
                        }
                    }
                }
            }
        } catch (IOException ioexception) {
            return null;
        }
    }
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InflaterInputStream(java.util.zip.InflaterInputStream) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream)

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