Search in sources :

Example 71 with InflaterInputStream

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]);
    }
}
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 72 with InflaterInputStream

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
    }
}
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) IOException(java.io.IOException)

Example 73 with InflaterInputStream

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

Example 74 with InflaterInputStream

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

Example 75 with InflaterInputStream

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

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