Package java.util.zip

Examples of java.util.zip.CheckedInputStream


        byte outBuf[] = new byte[100];
        // testing getChecksum for an empty file
        FileOutputStream outEmp = new FileOutputStream("empty.txt");
        outEmp.close();
        InputStream inEmp = new FileInputStream("empty.txt");
        CheckedInputStream checkEmpty = new CheckedInputStream(inEmp, new CRC32());
        while (checkEmpty.read() >= 0) {
        }
        assertEquals("the checkSum value of an empty file is not zero", 0, checkEmpty
                .getChecksum().getValue());
        inEmp.close();

        // testing getChecksum for the file checkInput
        InputStream checkInput = Support_Resources.getStream("hyts_checkInput.txt");
        CheckedInputStream checkIn = new CheckedInputStream(checkInput, new CRC32());
        while (checkIn.read() >= 0) {
        }
        // ran JDK and found that the checkSum value of this is 2036203193
        // System.out.print(" " + checkIn.getChecksum().getValue());
        assertEquals("the checksum value is incorrect", 2036203193, checkIn.getChecksum()
                .getValue());
        checkInput.close();
        // testing getChecksum for file checkInput
        checkInput = Support_Resources.getStream("hyts_checkInput.txt");
        CheckedInputStream checkIn2 = new CheckedInputStream(checkInput, new CRC32());
        checkIn2.read(outBuf, 0, 10);
        // ran JDK and found that the checkSum value of this is 2235765342
        // System.out.print(" " + checkIn2.getChecksum().getValue());
        assertEquals("the checksum value is incorrect", 2235765342L, checkIn2.getChecksum()
                .getValue());
        checkInput.close();
    }
View Full Code Here


   * @tests java.util.zip.CheckedInputStream#skip(long)
   */
  public void test_skipJ() throws Exception {
        // testing that the return by skip is valid
        InputStream checkInput = Support_Resources.getStream("hyts_checkInput.txt");
        CheckedInputStream checkIn = new CheckedInputStream(checkInput, new CRC32());
        long skipValue = 5;
        assertEquals("the value returned by skip(n) is not the same as its parameter",
                skipValue, checkIn.skip(skipValue));
        checkIn.skip(skipValue);
        // ran JDK and found the checkSum value is 2235765342
        // System.out.print(checkIn.getChecksum().getValue());
        assertEquals("checkSum value is not correct", 2235765342L, checkIn.getChecksum()
                .getValue());
        checkInput.close();
    }
View Full Code Here

    public void test_read() throws Exception {
        // testing that the return by skip is valid
        InputStream checkInput = Support_Resources
                .getStream("hyts_checkInput.txt");
        CheckedInputStream checkIn = new CheckedInputStream(checkInput,
                new CRC32());
        checkIn.read();
        checkIn.close();
        try {
            checkIn.read();
            fail("IOException expected.");
        } catch (IOException ee) {
            // expected
        }
        checkInput.close();
View Full Code Here

    public void test_read$byteII() throws Exception {
        // testing that the return by skip is valid
        InputStream checkInput = Support_Resources
                .getStream("hyts_checkInput.txt");
        CheckedInputStream checkIn = new CheckedInputStream(checkInput,
                new CRC32());
        byte buff[] = new byte[50];
        checkIn.read(buff, 10, 5);
        checkIn.close();
        try {
            checkIn.read(buff, 10, 5);
            fail("IOException expected.");
        } catch (IOException ee) {
            // expected
        }
        checkInput.close();
View Full Code Here

        // Get the image bytes
        InputStream in = null;
        try {
            CRC32 checksum = new CRC32();
            in = new CheckedInputStream(url.openStream(), checksum);

            // the contents don't matter, the read just needs a place to go
            byte[] sink = new byte[1024];
            while (true) {
        if (in.read(sink) <= 0) {
View Full Code Here

        this.checksum = null;
      }

      if (this.checksum != null) {
        this.in = new DataInputStream(
            new CheckedInputStream(in, this.checksum));
      } else {
        this.in = in;
      }
      this.limiter = limiter;
      this.cache = new OpInstanceCache();
View Full Code Here

        if (file.isDirectory()) {
            throw new IllegalArgumentException("Checksums can't be computed on directories");
        }
        InputStream in = null;
        try {
            in = new CheckedInputStream(new FileInputStream(file), checksum);
            IOUtils.copy(in, new NullOutputStream());
        } finally {
            IOUtils.closeQuietly(in);
        }
        return checksum;
View Full Code Here

        if (file.isDirectory()) {
            throw new IllegalArgumentException("Checksums can't be computed on directories");
        }
        InputStream in = null;
        try {
            in = new CheckedInputStream(new FileInputStream(file), checksum);
            IOUtils.copy(in, new NullOutputStream());
        } finally {
            IOUtils.closeQuietly(in);
        }
        return checksum;
View Full Code Here

        // System.out.println(inputChecksum.getValue());
    }

    private static StringBuffer readChecksummedFile(final int i) throws Exception {
        final CRC32 inputChecksum = new CRC32();
        final CheckedInputStream in = new CheckedInputStream(new FileInputStream("test" + i % 3 + ".data"), inputChecksum);
        final BufferedReader reader = new BufferedReader(new InputStreamReader(in, Util.ENCODING));

        final StringBuffer buf = new StringBuffer();
        String line;
        while ((line = reader.readLine()) != null) {
View Full Code Here

    private void syncConnection(final Socket connection, final int readTimeout) {
        try {
            final CRC32 crc32 = new CRC32();
            final DataOutput output = new DataOutputStream(connection.getOutputStream());
            final DataInput input = new DataInputStream(new CheckedInputStream(connection.getInputStream(), crc32));

            if (input.readByte() != INIT) {
                return;
            }
View Full Code Here

TOP

Related Classes of java.util.zip.CheckedInputStream

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.