Package java.util.zip

Examples of java.util.zip.Inflater


    byte orgBuffer[] = { 1, 3, 4, 7, 8 };

        // 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);
View Full Code Here


  public void test_end() {
    // test method of java.util.zip.inflater.end()
    byte byteArray[] = { 5, 2, 3, 7, 8 };

    int r = 0;
    Inflater inflate = new Inflater();
    inflate.setInput(byteArray);
    inflate.end();
    try {
      inflate.reset();
      inflate.setInput(byteArray);
    } catch (NullPointerException e) {
      r = 1;
    }
    assertEquals("inflate can still be used after end is called", 1, r);

    Inflater i = new Inflater();
    i.end();
    // check for exception
    i.end();
  }
View Full Code Here

   * @tests java.util.zip.Inflater#finished()
   */
  public void test_finished() {
    // test method of java.util.zip.inflater.finished()
    byte byteArray[] = { 1, 3, 4, 7, 8, 'e', 'r', 't', 'y', '5' };
    Inflater inflate = new Inflater(false);
    byte outPutInf[] = new byte[500];
    try {
      while (!(inflate.finished())) {
        if (inflate.needsInput()) {
          inflate.setInput(outPutBuff1);
        }

        inflate.inflate(outPutInf);
      }
      assertTrue(
          "the method finished() returned false when no more data needs to be decompressed",
          inflate.finished());
    } catch (DataFormatException e) {
      fail("Invalid input to be decompressed");
    }
    for (int i = 0; i < byteArray.length; i++) {
      assertTrue(
View Full Code Here

   */
  public void test_getAdler() {
    // test method of java.util.zip.inflater.getAdler()
    byte dictionaryArray[] = { 'e', 'r', 't', 'a', 'b', 2, 3 };

    Inflater inflateDiction = new Inflater();
    inflateDiction.setInput(outPutDiction);
    if (inflateDiction.needsDictionary() == true) {
      // getting the checkSum value through the Adler32 class
      Adler32 adl = new Adler32();
      adl.update(dictionaryArray);
      long checkSumR = adl.getValue();
      assertTrue(
          "the checksum value returned by getAdler() is not the same as the checksum returned by creating the adler32 instance",
          checkSumR == inflateDiction.getAdler());
    }
  }
View Full Code Here

   * @tests java.util.zip.Inflater#getRemaining()
   */
  public void test_getRemaining() {
    // test method of java.util.zip.inflater.getRemaining()
    byte byteArray[] = { 1, 3, 5, 6, 7 };
    Inflater inflate = new Inflater();
    assertEquals("upon creating an instance of inflate, getRemaining returned a non zero value",
        0, inflate.getRemaining());
    inflate.setInput(byteArray);
    assertTrue(
        "getRemaining returned zero when there is input in the input buffer",
        inflate.getRemaining() != 0);
  }
View Full Code Here

    deflate.finish();
    while (!(deflate.finished())) {
      x = x + deflate.deflate(outPutBuf, x, outPutBuf.length - x);
    }

    Inflater inflate = new Inflater();
    try {
      while (!(inflate.finished())) {
        if (inflate.needsInput()) {
          inflate.setInput(outPutBuf);
        }

        inflate.inflate(outPutInf);
      }
    } catch (DataFormatException e) {
      fail("Input to inflate is invalid or corrupted - getTotalIn");
    }
    // System.out.print(deflate.getTotalOut() + " " + inflate.getTotalIn());
    assertTrue(
        "the total byte in outPutBuf did not equal the byte returned in getTotalIn",
        inflate.getTotalIn() == deflate.getTotalOut());

    Inflater inflate2 = new Inflater();
    int offSet = 0;// seems only can start as 0
    int length = 4;
    try {
      // seems no while loops allowed
      if (inflate2.needsInput()) {
        inflate2.setInput(outPutBuff1, offSet, length);
      }

      inflate2.inflate(outPutInf);

    } catch (DataFormatException e) {
      fail("Input to inflate is invalid or corrupted - getTotalIn");
    }
    // System.out.print(inflate2.getTotalIn() + " " + length);
    assertTrue(
        "total byte dictated by length did not equal byte returned in getTotalIn",
        inflate2.getTotalIn() == length);
  }
View Full Code Here

    deflate.finish();
    while (!(deflate.finished())) {
      x = x + deflate.deflate(outPutBuf, x, outPutBuf.length - x);
    }

    Inflater inflate = new Inflater();
    byte outPutInf[] = new byte[500];
    try {
      while (!(inflate.finished())) {
        if (inflate.needsInput()) {
          inflate.setInput(outPutBuf);
        }

        y += inflate.inflate(outPutInf);
      }
    } catch (DataFormatException e) {
      fail("Input to inflate is invalid or corrupted - getTotalIn");
    }

    assertTrue(
        "the sum of the bytes returned from inflate does not equal the bytes of getTotalOut()",
        y == inflate.getTotalOut());
    assertTrue(
        "the total number of bytes to be compressed does not equal the total bytes decompressed",
        inflate.getTotalOut() == deflate.getTotalIn());

    // testing inflate(byte,int,int)
    inflate.reset();
    y = 0;
    int offSet = 0;// seems only can start as 0
    int length = 4;
    try {
      while (!(inflate.finished())) {
        if (inflate.needsInput()) {
          inflate.setInput(outPutBuf);
        }

        y += inflate.inflate(outPutInf, offSet, length);
      }
    } catch (DataFormatException e) {
      System.out
          .println("Input to inflate is invalid or corrupted - getTotalIn");
    }
    assertTrue(
        "the sum of the bytes returned from inflate does not equal the bytes of getTotalOut()",
        y == inflate.getTotalOut());
    assertTrue(
        "the total number of bytes to be compressed does not equal the total bytes decompressed",
        inflate.getTotalOut() == deflate.getTotalIn());
  }
View Full Code Here

  public void test_inflate$B() {
    // test method of java.util.zip.inflater.inflate(byte)

    byte byteArray[] = { 1, 3, 4, 7, 8, 'e', 'r', 't', 'y', '5' };
    byte outPutInf[] = new byte[500];
    Inflater inflate = new Inflater();
    try {
      while (!(inflate.finished())) {
        if (inflate.needsInput()) {
          inflate.setInput(outPutBuff1);
        }
        inflate.inflate(outPutInf);
      }
    } catch (DataFormatException e) {
      fail("Invalid input to be decompressed");
    }
    for (int i = 0; i < byteArray.length; i++) {
      assertTrue(
          "Final decompressed data does not equal the original data",
          byteArray[i] == outPutInf[i]);
    }
    assertEquals("final decompressed data contained more bytes than original - inflateB",
        0, outPutInf[byteArray.length]);
    // testing for an empty input array
    byte outPutBuf[] = new byte[500];
    byte emptyArray[] = new byte[11];
    int x = 0;
    Deflater defEmpty = new Deflater(3);
    defEmpty.setInput(emptyArray);
    while (!(defEmpty.needsInput())) {
      x += defEmpty.deflate(outPutBuf, x, outPutBuf.length - x);
    }
    defEmpty.finish();
    while (!(defEmpty.finished())) {
      x += defEmpty.deflate(outPutBuf, x, outPutBuf.length - x);
    }
    assertTrue(
        "the total number of byte from deflate did not equal getTotalOut - inflate(byte)",
        x == defEmpty.getTotalOut());
    assertTrue(
        "the number of input byte from the array did not correspond with getTotalIn - inflate(byte)",
        defEmpty.getTotalIn() == emptyArray.length);
    Inflater infEmpty = new Inflater();
    try {
      while (!(infEmpty.finished())) {
        if (infEmpty.needsInput()) {
          infEmpty.setInput(outPutBuf);
        }
        infEmpty.inflate(outPutInf);
      }
    } catch (DataFormatException e) {
      fail("Invalid input to be decompressed");
    }
    for (int i = 0; i < emptyArray.length; i++) {
View Full Code Here

                120, -38, 75, -54, 73, -52, 80, 40, 46, 41, -54, -52, 75, 87,
                72, -50, -49, 43, 73, -52, -52, 43, 86, 72, 2, 10, 34, 99,
                -123, -60, -68, 20, -80, 32, 0, -101, -69, 17, 84};
        String codedString = "blah string contains blahblahblahblah and blah";

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

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

        infl1.setInput(codedData, 0, codedData.length);
        try {
            decLen = infl1.inflate(result);
        } catch (DataFormatException e) {
            fail("Unexpected DataFormatException");
        }

        infl1.end();
        assertEquals(codedString, new String(result, 0, decLen));
        codedData[5] = 0;

        infl2.setInput(codedData, 0, codedData.length);
        try {
            decLen = infl2.inflate(result);
            fail("Expected DataFormatException");
        } catch (DataFormatException e) {
            // expected
        }

        infl2.end();
    }
View Full Code Here

    // test method of java.util.zip.inflater.inflate(byte,int,int)

    byte byteArray[] = { 1, 3, 4, 7, 8, 'e', 'r', 't', 'y', '5' };
    byte outPutInf[] = new byte[100];
    int y = 0;
    Inflater inflate = new Inflater();
    try {
      while (!(inflate.finished())) {
        if (inflate.needsInput()) {
          inflate.setInput(outPutBuff1);
        }
        y += inflate.inflate(outPutInf, y, outPutInf.length - y);
      }
    } catch (DataFormatException e) {
      fail("Invalid input to be decompressed");
    }
    for (int i = 0; i < byteArray.length; i++) {
      assertTrue(
          "Final decompressed data does not equal the original data",
          byteArray[i] == outPutInf[i]);
    }
    assertEquals("final decompressed data contained more bytes than original - inflateB",
        0, outPutInf[byteArray.length]);

    // test boundary checks
    inflate.reset();
    int r = 0;
    int offSet = 0;
    int lengthError = 101;
    try {
      if (inflate.needsInput()) {
        inflate.setInput(outPutBuff1);
      }
      inflate.inflate(outPutInf, offSet, lengthError);

    } catch (DataFormatException e) {
      fail("Invalid input to be decompressed");
    } catch (ArrayIndexOutOfBoundsException e) {
      r = 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.