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

        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

      final int size = partitions * MAP_OUTPUT_INDEX_RECORD_LENGTH;

      buf = ByteBuffer.allocate(size);
      if (crc != null) {
        crc.reset();
        CheckedInputStream chk = new CheckedInputStream(in, crc);
        IOUtils.readFully(chk, buf.array(), 0, size);
        if (chk.getChecksum().getValue() != in.readLong()) {
          throw new ChecksumException("Checksum error reading spill index: " +
                                indexFileName, -1);
        }
      } else {
        IOUtils.readFully(in, buf.array(), 0, size);
View Full Code Here

    @Override
    public String write(InputStream in) throws MicroKernelException {
        try {
            final Hasher hasher = Hashing.sha256().newHasher();
            Blob blob = store.createBlob(
                    new CheckedInputStream(in, new Checksum() {
                        @Override
                        public void update(byte[] b, int off, int len) {
                            hasher.putBytes(b, off, len);
                        }
                        @Override
View Full Code Here

    final ByteArrayInputStream in = new ByteArrayInputStream(StringUtil.getBytesUtf8(s));
    write(in, out);
  }

  public static long crc32(final InputStream in) throws IOException {
    final CheckedInputStream cis = new CheckedInputStream(in, new CRC32());
    final byte[] buf = new byte[BUFFER_SIZE];
    while (cis.read(buf) != -1) {
    }
    return cis.getChecksum().getValue();
  }
View Full Code Here

      final int size = partitions * MAP_OUTPUT_INDEX_RECORD_LENGTH;

      buf = ByteBuffer.allocate(size);
      if (crc != null) {
        crc.reset();
        CheckedInputStream chk = new CheckedInputStream(in, crc);
        IOUtils.readFully(chk, buf.array(), 0, size);
        if (chk.getChecksum().getValue() != in.readLong()) {
          throw new ChecksumException("Checksum error reading spill index: " +
                                indexFileName, -1);
        }
      } else {
        IOUtils.readFully(in, buf.array(), 0, size);
View Full Code Here

    private boolean getCheckSum(FileSnap snap, File snapFile) throws IOException {
        DataTree dt = new DataTree();
        Map<Long, Integer> sessions = new ConcurrentHashMap<Long, Integer>();
        InputStream snapIS = new BufferedInputStream(new FileInputStream(
                snapFile));
        CheckedInputStream crcIn = new CheckedInputStream(snapIS, new Adler32());
        InputArchive ia = BinaryInputArchive.getArchive(crcIn);
        try {
            snap.deserialize(dt, sessions, ia);
        } catch (IOException ie) {
            // we failed on the most recent snapshot
            // must be incomplete
            // try reading the next one
            // after corrupting
            snapIS.close();
            crcIn.close();
            throw ie;
        }

        long checksum = crcIn.getChecksum().getValue();
        long val = ia.readLong("val");
        snapIS.close();
        crcIn.close();
        return (val != checksum);
    }
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

    private boolean getCheckSum(FileSnap snap, File snapFile) throws IOException {
        DataTree dt = new DataTree();
        Map<Long, Integer> sessions = new ConcurrentHashMap<Long, Integer>();
        InputStream snapIS = new BufferedInputStream(new FileInputStream(
                snapFile));
        CheckedInputStream crcIn = new CheckedInputStream(snapIS, new Adler32());
        InputArchive ia = BinaryInputArchive.getArchive(crcIn);
        try {
            snap.deserialize(dt, sessions, ia);
        } catch (IOException ie) {
            // we failed on the most recent snapshot
            // must be incomplete
            // try reading the next one
            // after corrupting
            snapIS.close();
            crcIn.close();
            throw ie;
        }

        long checksum = crcIn.getChecksum().getValue();
        long val = ia.readLong("val");
        snapIS.close();
        crcIn.close();
        return (val != checksum);
    }
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.