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;
}
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);
}
}
}
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));
}
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();
}
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;
}
}
}
Aggregations