public static Checksum parse(final String hash) { if(StringUtils.isBlank(hash)) { return Checksum.NONE; } if(hash.matches("[a-fA-F0-9]{32}")) { return new Checksum(HashAlgorithm.md5, hash); } if(hash.matches("[a-fA-F0-9]{40}")) { return new Checksum(HashAlgorithm.sha1, hash); } if(hash.matches("[A-Fa-f0-9]{64}")) { return new Checksum(HashAlgorithm.sha256, hash); } if(hash.matches("[A-Fa-f0-9]{128}")) { return new Checksum(HashAlgorithm.sha512, hash); } if(hash.matches("[a-fA-F0-9]{8}")) { return new Checksum(HashAlgorithm.crc32, hash); } log.warn(String.format("Failure to detect algorithm for checksum %s", hash)); return Checksum.NONE; }
@Override public Checksum compute(final InputStream in, final TransferStatus status) throws ChecksumException { return new Checksum(HashAlgorithm.sha256, Hex.encodeHexString(this.digest("SHA-256", this.normalize(in, status)))); } }
@Override public Checksum compute(final InputStream in, final TransferStatus status) throws ChecksumException { return new Checksum(HashAlgorithm.sha1, Hex.encodeHexString(this.digest("SHA-1", this.normalize(in, status)))); } }
@Override public Checksum compute(final InputStream in, final TransferStatus status) throws ChecksumException { return new Checksum(HashAlgorithm.sha512, Hex.encodeHexString(this.digest("SHA-512", this.normalize(in, status)))); } }
@Override public Checksum compute(final InputStream in, final TransferStatus status) throws ChecksumException { return new Checksum(HashAlgorithm.md5, Hex.encodeHexString(this.digest("MD5", this.normalize(in, status)))); }
@Override public Checksum compute(final InputStream in, final TransferStatus status) throws ChecksumException { return new Checksum(HashAlgorithm.md5, Hex.encodeHexString(this.digest("MD5", this.normalize(in, status)))); } }
@Override public Checksum compute(final InputStream in, final TransferStatus status) throws ChecksumException { final InputStream normalized = this.normalize(in, status); final CRC32 crc32 = new CRC32(); try { byte[] buffer = new byte[16384]; int bytesRead; while((bytesRead = normalized.read(buffer, 0, buffer.length)) != -1) { crc32.update(buffer, 0, bytesRead); } } catch(IOException e) { throw new ChecksumException(LocaleFactory.localizedString("Checksum failure", "Error"), e.getMessage(), e); } finally { IOUtils.closeQuietly(normalized); } return new Checksum(HashAlgorithm.crc32, Long.toHexString(crc32.getValue())); } }
final Checksum previous = new Checksum(HashAlgorithm.md5, preferences.getProperty(String.format("%s.checksum", this.getConfiguration()))); if(log.isDebugEnabled()) {
final byte[] md5Bytes = object.getMd5Bytes(); if(md5Bytes != null) { attributes.setChecksum(new Checksum(HashAlgorithm.md5, Hex.encodeHexString(md5Bytes)));