Examples of DigestInputStream


Examples of java.security.DigestInputStream

     * @throws NoSuchAlgorithmException
     */
    private String md5(InputStream is) throws IOException,
            NoSuchAlgorithmException {
        MessageDigest digest = MessageDigest.getInstance("MD5");
        DigestInputStream dis = new DigestInputStream(is, digest);

        byte[] buffer = new byte[1024];

        int read = dis.read(buffer);
        while (read > -1) {
            read = dis.read(buffer);
        }

        return new String(encodeHex(dis.getMessageDigest().digest()));
    }
View Full Code Here

Examples of java.security.DigestInputStream

            out.println("  " + url);
            try {
                final String algorithm = "MD5";
                byte[] digest;
                MessageDigest md = MessageDigest.getInstance(algorithm);
                DigestInputStream in = new DigestInputStream(url.openStream(), md);
                try {
                    byte[] buf = new byte[8192];
                    int n;
                    do { n = in.read(buf); } while (n > 0);
                    digest = md.digest();
                } finally {
                    in.close();
                }
                StringBuilder sb = new StringBuilder();
                for (byte b: digest)
                    sb.append(String.format("%02x", b));
                out.println("  " + algorithm + " checksum: " + sb);
View Full Code Here

Examples of java.security.DigestInputStream

    try {
      MessageDigest digest = MessageDigest.getInstance(algorithm);
      fileInputStream = new FileInputStream(file);

      DigestInputStream digestInputStream = new DigestInputStream(fileInputStream, digest);

      if(progressMeter != null){

        progressMeter.setStartTime();
        progressMeter.setFinish(file.length());
      }

      byte[] buffer = new byte[8192];

      int bytesRead = 1;

      if(progressMeter != null){

        while ((bytesRead = digestInputStream.read(buffer)) != -1){

          progressMeter.incrementCurrentPosition(bytesRead);
        }

      }else{

        while ((bytesRead = digestInputStream.read(buffer)) != -1){}
      }

      byte[] hash = digest.digest();

      if(progressMeter != null){
View Full Code Here

Examples of java.security.DigestInputStream

            final MessageDigest md = MessageDigest.getInstance(CHECKSUM_TYPE);
            byte[] buf = new byte[CHECKSUM_BUFFER_SIZE];
            try {
              FileInputStream fis = new FileInputStream(jarFile);
              try {
                DigestInputStream dis = new DigestInputStream(fis, md);
                try {
                  while (dis.read(buf, 0, CHECKSUM_BUFFER_SIZE) != -1) {
                    // NOOP
                  }
                } finally {
                  dis.close();
                }
              } finally {
                fis.close();
              }
            } catch (IOException ioe) {
View Full Code Here

Examples of java.security.DigestInputStream

    InputStream in = null;
    try{
      in = rex.getResolverRegistry().getInputStream(sloc.getURI());
      MessageDigest md = MessageDigest.getInstance("MD5");
      in = new DigestInputStream(in, md);
      byte[] buf = new byte[4096];
      int count;

      while((count = in.read(buf)) != -1){
        result.append(new java.lang.String(buf, 0, count));
View Full Code Here

Examples of java.security.DigestInputStream

   
    InputStream in = null;
    try{
      in = ctx.getResolverRegistry().getInputStream(sloc.getURI());
      MessageDigest md = MessageDigest.getInstance("MD5");
      in = new DigestInputStream(in, md);
      byte[] buf = new byte[4096];
      int count;

      while((count = in.read(buf)) != -1){
        result.append(new java.lang.String(buf, 0, count));
View Full Code Here

Examples of java.security.DigestInputStream

        MessageDigest md = MessageDigest.getInstance("SHA-256");

        // Use a digest inputstream as using byte arrays directly to compute the SHA-256 can
        // have big effects on memory consumption. I.e. you don't want to have to read the
        // entire resource in memory. We rather stream it through...
        DigestInputStream dis = new DigestInputStream(is, md);

        byte[] buffer = new byte[16384];
        while (dis.read(buffer) != -1) {
            // we just drain the stream here to compute the Message Digest
        }

        StringBuilder sb = new StringBuilder(64); // SHA-256 is always 64 hex characters
        for (byte b : md.digest())
View Full Code Here

Examples of java.security.DigestInputStream

  private String readAndGetChecksum(File toRead, StringBuilder fileContent) {
    InputStream in = null;
    try {
      MessageDigest md = MessageDigest.getInstance("MD5");
      in = new FileInputStream(toRead);
      in = new DigestInputStream(in, md);
      Reader rd = new InputStreamReader(in);
      char[] buf = new char[IOUtils.BUFFER_SIZE];
      int num = 0;
      while ((num = rd.read(buf, 0, buf.length)) != -1) {
        fileContent.append(buf, 0, num);
View Full Code Here

Examples of java.security.DigestInputStream

    private static Checksum computeChecksum(File root, File file, MessageDigest digest) throws IOException {
        byte[] buf = new byte[1024 * 1024];
        int bytesRead = 0;
        FileInputStream fis = new FileInputStream(file);
        BufferedInputStream bis = new BufferedInputStream(fis);
        InputStream in = new DigestInputStream(bis, digest);

        /* Read in the entire file */
        do {
            bytesRead = in.read(buf);
        } while (bytesRead != -1);
        in.close();

        /* Compute the checksum with the digest */
        byte[] byteChecksum = digest.digest();
        digest.reset();

View Full Code Here

Examples of java.security.DigestInputStream

        }

        byte[] buf = new byte[1024 * 1024];
        int bytesRead = 0;
        BufferedInputStream bis = new BufferedInputStream(is);
        InputStream in = new DigestInputStream(bis, digest);

        /* Read in the entire file */
        do {
            bytesRead = in.read(buf);
        } while (bytesRead != -1);
        in.close();

        /* Compute the checksum with the digest */
        byte[] byteChecksum = digest.digest();
        digest.reset();

View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.