use of java.util.zip.InflaterInputStream in project j2objc by google.
the class InflaterInputStreamTest method test_skipJ2.
/**
* java.util.zip.InflaterInputStream#skip(long)
*/
public void test_skipJ2() throws IOException {
int result = 0;
int[] buffer = new int[100];
byte[] orgBuffer = { 1, 3, 4, 7, 8 };
// testing for negative input to skip
InputStream infile = Support_Resources.getStream("hyts_construOD.bin");
Inflater inflate = new Inflater();
InflaterInputStream inflatIP = new InflaterInputStream(infile, inflate, 10);
long skip;
try {
skip = inflatIP.skip(Integer.MIN_VALUE);
fail("Expected IllegalArgumentException when skip() is called with negative parameter");
} catch (IllegalArgumentException e) {
// Expected
}
inflatIP.close();
// testing for number of bytes greater than input.
InputStream infile2 = Support_Resources.getStream("hyts_construOD.bin");
try (InflaterInputStream inflatIP2 = new InflaterInputStream(infile2)) {
// looked at how many bytes the skip skipped. It is
// 5 and its supposed to be the entire input stream.
skip = inflatIP2.skip(Integer.MAX_VALUE);
// System.out.println(skip);
assertEquals("method skip() returned wrong number of bytes skipped", 5, skip);
inflatIP2.close();
}
// test for skipping of 2 bytes
InputStream infile3 = Support_Resources.getStream("hyts_construOD.bin");
try (InflaterInputStream inflatIP3 = new InflaterInputStream(infile3)) {
skip = inflatIP3.skip(2);
assertEquals("the number of bytes returned by skip did not correspond with its input parameters", 2, skip);
int i = 0;
result = 0;
while ((result = inflatIP3.read()) != -1) {
buffer[i] = result;
i++;
}
}
for (int j = 2; j < orgBuffer.length; j++) {
assertEquals("original compressed data did not equal decompressed data", orgBuffer[j], buffer[j - 2]);
}
}
use of java.util.zip.InflaterInputStream in project j2objc by google.
the class InflaterInputStreamTest method test_read_LBII.
/**
* java.util.zip.InflaterInputStream#read(byte [], int, int)
*/
public void test_read_LBII() throws IOException {
int result = 0;
InputStream infile = Support_Resources.getStream("hyts_construOD.bin");
Inflater inflate = new Inflater();
InflaterInputStream inflatIP = new InflaterInputStream(infile, inflate);
byte[] b = new byte[3];
try {
result = inflatIP.read(null, 0, 1);
fail("NullPointerException expected");
} catch (NullPointerException npe) {
// expected
}
assertEquals(0, inflatIP.read(b, 0, 0));
try {
// offset higher
result = inflatIP.read(b, 5, 2);
fail("IndexOutOfBoundsException expected");
} catch (IndexOutOfBoundsException iobe) {
// expected
}
inflatIP.close();
try {
// read after close
inflatIP.read(b, 0, 1);
fail("IOException expected");
} catch (IOException ioe) {
// expected
}
}
use of java.util.zip.InflaterInputStream in project j2objc by google.
the class FilterInputStreamNullSourceTest method testInflaterInputStream.
public void testInflaterInputStream() throws IOException {
try {
new InflaterInputStream(null);
fail();
} catch (NullPointerException expected) {
}
try {
new InflaterInputStream(null, new Inflater());
fail();
} catch (NullPointerException expected) {
}
try {
new InflaterInputStream(null, new Inflater(), 1024);
fail();
} catch (NullPointerException expected) {
}
}
use of java.util.zip.InflaterInputStream in project j2objc by google.
the class DeflaterInputStreamTest method inflate.
public byte[] inflate(byte[] bytes) throws IOException {
try (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 phonegap-facebook-plugin by Wizcorp.
the class SpdyReader method newNameValueBlockStream.
private DataInputStream newNameValueBlockStream() {
// Limit the inflater input stream to only those bytes in the Name/Value block.
final InputStream throttleStream = new InputStream() {
@Override
public int read() throws IOException {
return Util.readSingleByte(this);
}
@Override
public int read(byte[] buffer, int offset, int byteCount) throws IOException {
byteCount = Math.min(byteCount, compressedLimit);
int consumed = in.read(buffer, offset, byteCount);
compressedLimit -= consumed;
return consumed;
}
@Override
public void close() throws IOException {
in.close();
}
};
// Subclass inflater to install a dictionary when it's needed.
Inflater inflater = new Inflater() {
@Override
public int inflate(byte[] buffer, int offset, int count) throws DataFormatException {
int result = super.inflate(buffer, offset, count);
if (result == 0 && needsDictionary()) {
setDictionary(DICTIONARY);
result = super.inflate(buffer, offset, count);
}
return result;
}
};
return new DataInputStream(new InflaterInputStream(throttleStream, inflater));
}
Aggregations