Package java.util.zip

Examples of java.util.zip.InflaterInputStream


    }

    public void testAvailableEmptySource() throws Exception {
        // this byte[] is a deflation of the empty file
        byte[] deflated = { 120, -100, 3, 0, 0, 0, 0, 1 };
        InputStream in = new InflaterInputStream(new ByteArrayInputStream(deflated));
        assertEquals(-1, in.read());
        assertEquals(-1, in.read());
        assertEquals(0, in.available());
    }
View Full Code Here


        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        DeflaterOutputStream dos = new DeflaterOutputStream(baos);
        dos.write(test);
        dos.close();
        InputStream is = new ByteArrayInputStream(baos.toByteArray());
        InflaterInputStream iis = new InflaterInputStream(is);
        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;
        }
  }
View Full Code Here

    public void test_read$BII2() throws IOException {
        File resources = Support_Resources.createTempFolder();
        Support_Resources.copyFile(resources, null, "Broken_manifest.jar");
        FileInputStream fis = new FileInputStream(new File(resources,
                "Broken_manifest.jar"));
        InflaterInputStream iis = new InflaterInputStream(fis);
        byte[] outBuf = new byte[530];

        iis.close();
        try {
            iis.read(outBuf, 0, 5);
            fail("IOException expected");
        } catch (IOException ee) {
            // expected.
        }
    }
View Full Code Here

    public void test_read$BII3() throws IOException {
        File resources = Support_Resources.createTempFolder();
        Support_Resources.copyFile(resources, null, "Broken_manifest.jar");
        FileInputStream fis = new FileInputStream(new File(resources,
                "Broken_manifest.jar"));
        InflaterInputStream iis = new InflaterInputStream(fis);
        byte[] outBuf = new byte[530];

        try {
            iis.read();
            fail("IOException expected.");
        } catch (IOException ee) {
            // expected
        }
    }
View Full Code Here

    /**
     * @tests java.util.zip.InflaterInputStream#reset()
     */
    public void test_reset() {
        InputStream is = new ByteArrayInputStream(new byte[10]);
        InflaterInputStream iis = new InflaterInputStream(is);
        try {
            iis.reset();
            fail("Should throw IOException");
        } catch (IOException e) {
            // correct
        }
    }
View Full Code Here

  /**
   * @tests java.util.zip.InflaterInputStream#skip(long)
   */
  public void test_skipJ() throws IOException {
    InputStream is = Support_Resources.getStream("hyts_available.tst");
    InflaterInputStream iis = new InflaterInputStream(is);

    // Tests for skipping a negative number of bytes.
    try {
      iis.skip(-3);
      fail("IllegalArgumentException not thrown");
    } catch (IllegalArgumentException e) {
            // Expected
    }
    assertEquals("Incorrect Byte Returned.", 5, iis.read());

    try {
      iis.skip(Integer.MIN_VALUE);
      fail("IllegalArgumentException not thrown");
    } catch (IllegalArgumentException e) {
            // Expected
    }
    assertEquals("Incorrect Byte Returned.", 4, iis.read());

    // Test to make sure the correct number of bytes were skipped
    assertEquals("Incorrect Number Of Bytes Skipped.", 3, iis.skip(3));

    // Test to see if the number of bytes skipped returned is true.
    assertEquals("Incorrect Byte Returned.", 7, iis.read());

    assertEquals("Incorrect Number Of Bytes Skipped.", 0, iis.skip(0));
    assertEquals("Incorrect Byte Returned.", 0, iis.read());

    // Test for skipping more bytes than available in the stream
    assertEquals("Incorrect Number Of Bytes Skipped.", 2, iis.skip(4));
    assertEquals("Incorrect Byte Returned.", -1, iis.read());
    iis.close();
  }
View Full Code Here

        // testing for negative input to skip
    InputStream infile = Support_Resources
        .getStream("hyts_constru(OD).txt");
    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_constru(OD).txt");
    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);

    // test for skipping of 2 bytes
    InputStream infile3 = Support_Resources
        .getStream("hyts_constru(OD).txt");
    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++;
    }
    inflatIP2.close();
View Full Code Here

  /**
   * @tests 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
    }
  }
View Full Code Here

  /**
   * @tests java.util.zip.InflaterInputStream#close()
   */
  public void test_close() throws IOException {
    InflaterInputStream iin = new InflaterInputStream(
        new ByteArrayInputStream(new byte[0]));
    iin.close();

        // test for exception
    iin.close();
  }
View Full Code Here

      else if (encoding.equalsIgnoreCase("deflate"))
      {
         if (log.isDebugEnabled())
            log.debug("Pushing inflater-input-stream");

         resp.inp_stream = new InflaterInputStream(resp.inp_stream);
         pce.removeElementAt(pce.size() - 1);
         resp.deleteHeader("Content-length");
      }
      else if (encoding.equalsIgnoreCase("compress") || encoding.equalsIgnoreCase("x-compress"))
      {
View Full Code Here

TOP

Related Classes of java.util.zip.InflaterInputStream

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.