use of java.util.zip.InflaterInputStream in project j2objc by google.
the class InflaterInputStreamTest method test_available.
/**
* java.util.zip.InflaterInputStream#available()
*/
public void test_available() throws IOException {
InputStream is = Support_Resources.getStream("hyts_available.tst");
InflaterInputStream iis = new InflaterInputStream(is);
int available;
for (int i = 0; i < 11; i++) {
iis.read();
available = iis.available();
if (available == 0) {
assertEquals("Expected no more bytes to read", -1, iis.read());
} else {
assertEquals("Bytes Available Should Return 1.", 1, available);
}
}
iis.close();
try {
iis.available();
fail("available after close should throw IOException.");
} catch (IOException e) {
// Expected
}
}
use of java.util.zip.InflaterInputStream in project j2objc by google.
the class InflaterInputStreamTest method test_ConstructorLjava_io_InputStreamLjava_util_zip_InflaterI.
/**
* java.util.zip.InflaterInputStream#InflaterInputStream(java.io.InputStream,
*java.util.zip.Inflater, int)
*/
public void test_ConstructorLjava_io_InputStreamLjava_util_zip_InflaterI() throws IOException {
int result = 0;
int[] buffer = new int[500];
InputStream infile = Support_Resources.getStream("hyts_construODI.bin");
Inflater inflate = new Inflater();
InflaterInputStream inflatIP = new InflaterInputStream(infile, inflate, 1);
int i = 0;
while ((result = inflatIP.read()) != -1) {
buffer[i] = result;
i++;
}
inflatIP.close();
}
use of java.util.zip.InflaterInputStream in project j2objc by google.
the class InflaterInputStreamTest method testInflaterInputStreamWithExternalInflater_2ArgConstructor.
// http://b/26462400
public void testInflaterInputStreamWithExternalInflater_2ArgConstructor() throws Exception {
InputStream base = new ByteArrayInputStream(new byte[] { 'h', 'i' });
Inflater inf = new Inflater();
InflaterInputStream iis = new InflaterInputStream(base, inf);
iis.close();
try {
inf.reset();
fail();
} catch (NullPointerException expected) {
// Expected because the inflater should've been closed when the stream was.
}
}
use of java.util.zip.InflaterInputStream in project j2objc by google.
the class InflaterInputStreamTest method test_read$BII.
/**
* java.util.zip.InflaterInputStream#read(byte[], int, int)
*/
public void test_read$BII() throws IOException {
byte[] test = new byte[507];
for (int i = 0; i < 256; i++) {
test[i] = (byte) i;
}
for (int i = 256; i < test.length; i++) {
test[i] = (byte) (256 - i);
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try (DeflaterOutputStream dos = new DeflaterOutputStream(baos)) {
dos.write(test);
}
try (InflaterInputStream iis = new InflaterInputStream(new ByteArrayInputStream(baos.toByteArray()))) {
byte[] outBuf = new byte[530];
int result = 0;
while (true) {
result = iis.read(outBuf, 0, 5);
if (result == -1) {
// "EOF was reached";
break;
}
}
try {
iis.read(outBuf, -1, 10);
fail("should throw IOOBE.");
} catch (IndexOutOfBoundsException e) {
// expected;
}
}
}
use of java.util.zip.InflaterInputStream in project j2objc by google.
the class InflaterInputStreamTest method testAvailableEmptySource.
public void testAvailableEmptySource() throws Exception {
// this byte[] is a deflation of the empty file
byte[] deflated = { 120, -100, 3, 0, 0, 0, 0, 1 };
try (InputStream in = new InflaterInputStream(new ByteArrayInputStream(deflated))) {
assertEquals(-1, in.read());
assertEquals(-1, in.read());
assertEquals(0, in.available());
}
}
Aggregations