Search in sources :

Example 6 with DeflaterInputStream

use of java.util.zip.DeflaterInputStream in project j2objc by google.

the class DeflaterInputStreamTest method testReadExceptions.

public void testReadExceptions() throws IOException {
    byte[] data = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
    byte[] buffer = new byte[8];
    InputStream in = new DeflaterInputStream(new ByteArrayInputStream(data));
    try {
        in.read(buffer, 0, 10);
        fail();
    } catch (IndexOutOfBoundsException expected) {
    }
    try {
        in.read(null, 0, 5);
        fail();
    } catch (NullPointerException expected) {
    }
    try {
        in.read(buffer, -1, 5);
        fail();
    } catch (IndexOutOfBoundsException expected) {
    }
    in.close();
    try {
        in.read(buffer, 0, 5);
        fail();
    } catch (IOException expected) {
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) DeflaterInputStream(java.util.zip.DeflaterInputStream) InflaterInputStream(java.util.zip.InflaterInputStream) InputStream(java.io.InputStream) DeflaterInputStream(java.util.zip.DeflaterInputStream) IOException(java.io.IOException)

Example 7 with DeflaterInputStream

use of java.util.zip.DeflaterInputStream in project j2objc by google.

the class DeflaterInputStreamTest method testReadByteByByte.

public void testReadByteByByte() throws IOException {
    byte[] data = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
    InputStream in = new DeflaterInputStream(new ByteArrayInputStream(data));
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    assertEquals(1, in.available());
    int b;
    while ((b = in.read()) != -1) {
        out.write(b);
    }
    assertEquals(0, in.available());
    assertEquals(Arrays.toString(data), Arrays.toString(inflate(out.toByteArray())));
    in.close();
    try {
        in.available();
        fail();
    } catch (IOException expected) {
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) DeflaterInputStream(java.util.zip.DeflaterInputStream) InflaterInputStream(java.util.zip.InflaterInputStream) InputStream(java.io.InputStream) DeflaterInputStream(java.util.zip.DeflaterInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 8 with DeflaterInputStream

use of java.util.zip.DeflaterInputStream in project j2objc by google.

the class DeflaterInputStreamTest method testReadWithBuffer.

public void testReadWithBuffer() throws IOException {
    byte[] data = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
    byte[] buffer = new byte[8];
    InputStream in = new DeflaterInputStream(new ByteArrayInputStream(data));
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    assertEquals(1, in.available());
    int count;
    while ((count = in.read(buffer, 0, 5)) != -1) {
        assertTrue(count <= 5);
        out.write(buffer, 0, count);
    }
    assertEquals(0, in.available());
    assertEquals(Arrays.toString(data), Arrays.toString(inflate(out.toByteArray())));
    in.close();
    try {
        in.available();
        fail();
    } catch (IOException expected) {
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) DeflaterInputStream(java.util.zip.DeflaterInputStream) InflaterInputStream(java.util.zip.InflaterInputStream) InputStream(java.io.InputStream) DeflaterInputStream(java.util.zip.DeflaterInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 9 with DeflaterInputStream

use of java.util.zip.DeflaterInputStream in project robovm by robovm.

the class DeflaterInputStreamTest method testReadWithBuffer.

public void testReadWithBuffer() throws IOException {
    byte[] data = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
    byte[] buffer = new byte[8];
    InputStream in = new DeflaterInputStream(new ByteArrayInputStream(data));
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    assertEquals(1, in.available());
    int count;
    while ((count = in.read(buffer, 0, 5)) != -1) {
        assertTrue(count <= 5);
        out.write(buffer, 0, count);
    }
    assertEquals(0, in.available());
    assertEquals(Arrays.toString(data), Arrays.toString(inflate(out.toByteArray())));
    in.close();
    try {
        in.available();
        fail();
    } catch (IOException expected) {
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) DeflaterInputStream(java.util.zip.DeflaterInputStream) InflaterInputStream(java.util.zip.InflaterInputStream) InputStream(java.io.InputStream) DeflaterInputStream(java.util.zip.DeflaterInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Aggregations

DeflaterInputStream (java.util.zip.DeflaterInputStream)9 ByteArrayInputStream (java.io.ByteArrayInputStream)8 InputStream (java.io.InputStream)7 InflaterInputStream (java.util.zip.InflaterInputStream)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 IOException (java.io.IOException)6 ZipFileEntry (com.google.devtools.build.zip.ZipFileEntry)1 Base85x (com.intellij.openapi.diff.impl.patch.lib.base85xjava.Base85x)1 CRC32 (java.util.zip.CRC32)1