Package java.util.zip

Examples of java.util.zip.CheckedInputStream


        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


        this.checksum = null;
      }

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

    public void setInputStream(DataInputStream in) {
      this.in = in;
      if (this.checksum != null) {
        checksum.reset();
        this.in = new DataInputStream(
            new CheckedInputStream(in, this.checksum));
      } else {
        this.in = in;
      }
    }
View Full Code Here

          NameNodeLayoutVersion.Feature.EDITLOG_LENGTH, logVersion)
          || logVersion < NameNodeLayoutVersion.CURRENT_LAYOUT_VERSION;

      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

              ZipEntry zipEntry = (ZipEntry) e.nextElement();
             
              CRC32 crc = new CRC32();
             
              BufferedInputStream bis = new BufferedInputStream(zipFile.getInputStream(zipEntry));
              CheckedInputStream cis = new CheckedInputStream(bis, crc);
             
              while(cis.read(buffer, 0, buffer.length) != -1) {
                // scroll through zip entry
              }
             
              if (crc.getValue() != zipEntry.getCrc()) {
                return false; // CRC match failed, corrupt zip
View Full Code Here

    }



    private long calcChecksum(File f, Checksum cksum) throws IOException {
        CheckedInputStream in = new CheckedInputStream(new BufferedInputStream(
                new FileInputStream(f)), cksum);
        while (in.read() != -1)
            ;
        in.close();
        return cksum.getValue();
    }
View Full Code Here

    }

    public static long computeChecksum(InputStream stream, Checksum verify,
            boolean close) throws IOException {

        InputStream in = new CheckedInputStream(
                new BufferedInputStream(stream), verify);
        try {
            while (in.read() != -1)
                ; // do nothing
        } finally {
            if (close)
                in.close();
        }

        return verify.getValue();
    }
View Full Code Here

    }

    public static long getCRC(final InputStream is) {
        try {
            // Computer CRC32 checksum
            final CheckedInputStream cis = new CheckedInputStream(
                    is, new CRC32());

            byte[] buf = new byte[128];
            while (cis.read(buf) >= 0) {
            }
            long checksum = cis.getChecksum().getValue();
            // System.out.println(checksum + " " + fileSize + " " + fileName);
            return checksum;
        } catch (Throwable t) {
        }
        return 0;
View Full Code Here

     * @throws IOException
     */
    public static long getCRC(final String fileName)
            throws FileNotFoundException, IOException {
        // Computer CRC32 checksum
        final CheckedInputStream cis = new CheckedInputStream(
                new FileInputStream(fileName), new CRC32());

        byte[] buf = new byte[128];
        while (cis.read(buf) >= 0) {
        }
        long checksum = cis.getChecksum().getValue();
        // System.out.println(checksum + " " + fileSize + " " + fileName);
        return 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.