Search in sources :

Example 66 with InflaterInputStream

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
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InflaterInputStream(java.util.zip.InflaterInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) InflaterInputStream(java.util.zip.InflaterInputStream) IOException(java.io.IOException)

Example 67 with InflaterInputStream

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();
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InflaterInputStream(java.util.zip.InflaterInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) InflaterInputStream(java.util.zip.InflaterInputStream) Inflater(java.util.zip.Inflater)

Example 68 with InflaterInputStream

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.
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InflaterInputStream(java.util.zip.InflaterInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) InflaterInputStream(java.util.zip.InflaterInputStream) Inflater(java.util.zip.Inflater)

Example 69 with InflaterInputStream

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;
        }
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InflaterInputStream(java.util.zip.InflaterInputStream) DeflaterOutputStream(java.util.zip.DeflaterOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 70 with InflaterInputStream

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());
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InflaterInputStream(java.util.zip.InflaterInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) InflaterInputStream(java.util.zip.InflaterInputStream)

Aggregations

InflaterInputStream (java.util.zip.InflaterInputStream)200 ByteArrayInputStream (java.io.ByteArrayInputStream)113 InputStream (java.io.InputStream)100 IOException (java.io.IOException)74 Inflater (java.util.zip.Inflater)66 ByteArrayOutputStream (java.io.ByteArrayOutputStream)50 GZIPInputStream (java.util.zip.GZIPInputStream)39 DataInputStream (java.io.DataInputStream)33 FileInputStream (java.io.FileInputStream)27 BufferedInputStream (java.io.BufferedInputStream)24 InputStreamReader (java.io.InputStreamReader)13 DeflaterOutputStream (java.util.zip.DeflaterOutputStream)13 HttpURLConnection (java.net.HttpURLConnection)12 URL (java.net.URL)11 File (java.io.File)10 BufferedReader (java.io.BufferedReader)9 OutputStream (java.io.OutputStream)9 Point (java.awt.Point)7 EOFException (java.io.EOFException)7 URLConnection (java.net.URLConnection)7