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