Package java.util.zip

Examples of java.util.zip.Inflater


   * @tests java.util.zip.Inflater#setInput(byte[])
   */
  public void test_setInput$B() {
    // test method of java.util.zip.inflater.setInput(byte)
    byte byteArray[] = { 2, 3, 4, 't', 'y', 'u', 'e', 'w', 7, 6, 5, 9 };
    Inflater inflate = new Inflater();
    inflate.setInput(byteArray);
    assertTrue("setInputB did not deliver any byte to the input buffer",
        inflate.getRemaining() != 0);
  }
View Full Code Here


  public void test_setInput$BII() {
    // test method of java.util.zip.inflater.setInput(byte,int,int)
    byte byteArray[] = { 2, 3, 4, 't', 'y', 'u', 'e', 'w', 7, 6, 5, 9 };
    int offSet = 6;
    int length = 6;
    Inflater inflate = new Inflater();
    inflate.setInput(byteArray, offSet, length);
    assertTrue(
        "setInputBII did not deliver the right number of bytes to the input buffer",
        inflate.getRemaining() == length);
    // boundary check
    inflate.reset();
    int r = 0;
    try {
      inflate.setInput(byteArray, 100, 100);
    } catch (ArrayIndexOutOfBoundsException e) {
      r = 1;
    }
    assertEquals("boundary check is not present for setInput", 1, r);
  }
View Full Code Here

     */
    public void test_getBytesRead() throws DataFormatException,
            UnsupportedEncodingException {
        // Regression test for HARMONY-158
        Deflater def = new Deflater();
        Inflater inf = new Inflater();
        assertEquals(0, def.getTotalIn());
        assertEquals(0, def.getTotalOut());
        assertEquals(0, def.getBytesRead());
        // Encode a String into bytes
        String inputString = "blahblahblah??";
        byte[] input = inputString.getBytes("UTF-8");

        // Compress the bytes
        byte[] output = new byte[100];
        def.setInput(input);
        def.finish();
        def.deflate(output);
        inf.setInput(output);
        int compressedDataLength =inf.inflate(input);
        assertEquals(16, inf.getTotalIn());
        assertEquals(compressedDataLength, inf.getTotalOut());
        assertEquals(16, inf.getBytesRead());
    }
View Full Code Here

     * @tests java.util.zip.Deflater#getBytesRead()
     */
    public void test_getBytesWritten() throws DataFormatException, UnsupportedEncodingException {
        // Regression test for HARMONY-158
        Deflater def = new Deflater();
        Inflater inf = new Inflater();
        assertEquals(0, def.getTotalIn());
        assertEquals(0, def.getTotalOut());
        assertEquals(0, def.getBytesWritten());
        // Encode a String into bytes
        String inputString = "blahblahblah??";
        byte[] input = inputString.getBytes("UTF-8");

        // Compress the bytes
        byte[] output = new byte[100];
        def.setInput(input);
        def.finish();
        def.deflate(output);
        inf.setInput(output);
        int compressedDataLength =inf.inflate(input);
        assertEquals(16, inf.getTotalIn());
        assertEquals(compressedDataLength, inf.getTotalOut());
        assertEquals(14, inf.getBytesWritten());
    }
View Full Code Here

    /**
     * @tests java.util.zip.Deflater#inflate(byte[], int, int)
     */
    public void testInflate() throws Exception {
        // Regression for HARMONY-81
        Inflater inf = new Inflater();
        int res = inf.inflate(new byte[0], 0, 0);

        assertEquals(0, res);

        // Regression for HARMONY-2508
        Inflater inflater = new Inflater();
        byte[] b = new byte[1024];
        assertEquals(0, inflater.inflate(b));
        inflater.end();

        // Regression for HARMONY-2510
        inflater = new Inflater();
        inflater.setInput(new byte[] { -1 });
        try {
            inflater.inflate(b);

            // The RI detects malformed data on the malformed input { -1 }. Both
            // this implementation and the native zlib API return "need input"
            // on that data. This is an error if the stream is exhausted, but
            // not one that results in an exception in the Inflater API.
            assertTrue(inflater.needsInput());
        } catch (DataFormatException e) {
            // expected
        }

        inflater = new Inflater();
        inflater.setInput(new byte[] { -1, -1, -1 });
        try {
            inflater.inflate(b);
        } catch (DataFormatException e) {
            // expected
        }
    }
View Full Code Here

                passNo2);
        assertTrue(
                "Compressed data the same for stream with different dictionaries.",
                pass12);

        Inflater inflNo = new Inflater();
        Inflater infl1 = new Inflater();
        Inflater infl2 = new Inflater();

        byte[] result = new byte[100];
        int decLen;

        inflNo.setInput(outputNo, 0, dataLenNo);
        decLen = inflNo.inflate(result);

        assertFalse(inflNo.needsDictionary());
        inflNo.end();
        assertEquals(inputString, new String(result, 0, decLen));

        infl1.setInput(output1, 0, dataLen1);
        decLen = infl1.inflate(result);

        assertTrue(infl1.needsDictionary());
        infl1.setDictionary(dictionary1.getBytes());
        decLen = infl1.inflate(result);
        infl1.end();
        assertEquals(inputString, new String(result, 0, decLen));

        infl2.setInput(output2, 0, dataLen2);
        decLen = infl2.inflate(result);

        assertTrue(infl2.needsDictionary());
        infl2.setDictionary(dictionary2.getBytes());
        decLen = infl2.inflate(result);
        infl2.end();
        assertEquals(inputString, new String(result, 0, decLen));


        inflNo = new Inflater();
        infl1 = new Inflater();
        inflNo.setInput(outputNo, 0, dataLenNo);
        try {
            infl1.setDictionary(dictionary1.getBytes());
            fail("IllegalArgumentException expected.");
        } catch (IllegalArgumentException ee) {
View Full Code Here

                pass23);
        assertTrue(
                "Compressed data the differs for stream with the same dictionaries.",
                pass13);

        Inflater infl1 = new Inflater();
        Inflater infl2 = new Inflater();
        Inflater infl3 = new Inflater();

        byte[] result = new byte[100];
        int decLen;

        infl1.setInput(output1, 0, dataLen1);
        decLen = infl1.inflate(result);

        assertTrue(infl1.needsDictionary());
        infl1.setDictionary(dictionary2.getBytes(), 4, 4);
        decLen = infl1.inflate(result);
        infl1.end();
        assertEquals(inputString, new String(result, 0, decLen));

        infl2.setInput(output2, 0, dataLen2);
        decLen = infl2.inflate(result);

        assertTrue(infl2.needsDictionary());
        try {
            infl2.setDictionary(dictionary1.getBytes());
            fail("IllegalArgumentException expected.");
        } catch (IllegalArgumentException ee) {
            // expected
        }
        infl2.end();

        infl3.setInput(output3, 0, dataLen3);
        decLen = infl3.inflate(result);

        assertTrue(infl3.needsDictionary());
        infl3.setDictionary(dictionary1.getBytes());
        decLen = infl3.inflate(result);
        infl3.end();
        assertEquals(inputString, new String(result, 0, decLen));

    }
View Full Code Here

   *        java.util.zip.Inflater)
   */
  public void test_ConstructorLjava_io_InputStreamLjava_util_zip_Inflater() throws IOException {
    byte byteArray[] = new byte[100];
    InputStream infile = Support_Resources.getStream("hyts_constru(OD).txt");
    Inflater inflate = new Inflater();
    InflaterInputStream inflatIP = new InflaterInputStream(infile,
        inflate);

    inflatIP.read(byteArray, 0, 5);// only suppose to read in 5 bytes
    inflatIP.close();
View Full Code Here

   */
  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_constru(ODI).txt");
    Inflater inflate = new Inflater();
    InflaterInputStream inflatIP = new InflaterInputStream(infile,
        inflate, 1);

    int i = 0;
    while ((result = inflatIP.read()) != -1) {
View Full Code Here

    int result = 0;
    int buffer[] = new int[500];
    byte orgBuffer[] = { 1, 3, 4, 7, 8 };
    InputStream infile = Support_Resources
        .getStream("hyts_constru(OD).txt");
    Inflater inflate = new Inflater();
    InflaterInputStream inflatIP = new InflaterInputStream(infile,
        inflate);

    int i = 0;
    while ((result = inflatIP.read()) != -1) {
View Full Code Here

TOP

Related Classes of java.util.zip.Inflater

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.