/** * The value of the ETag header is calculated by taking * the ETag value of each segment, concatenating them together, and then returning the MD5 checksum of the result. * * @param checksum Checksum compute service * @param objects Files * @return Concatenated checksum */ public Checksum checksum(final ChecksumCompute checksum, final List<StorageObject> objects) throws ChecksumException { final StringBuilder concatenated = new StringBuilder(); for(StorageObject s : objects) { concatenated.append(s.getMd5sum()); } return checksum.compute(IOUtils.toInputStream(concatenated.toString(), Charset.defaultCharset()), new TransferStatus()); } }
/** * The fingerprint of a public key consists of the output of the MD5 * message-digest algorithm [RFC-1321]. The input to the algorithm is * the public key blob as described in [SSH-TRANS]. The output of the * algorithm is presented to the user as a sequence of 16 octets printed * as hexadecimal with lowercase letters and separated by colons. * <p> * For example: "4b:69:6c:72:6f:79:20:77:61:73:20:68:65:72:65:21" * * @param in Public key blob * @return The fingerprint is the MD5 of the Base64-encoded public key */ public String fingerprint(final InputStream in) throws ChecksumException { final String undelimited = ChecksumComputeFactory.get(HashAlgorithm.md5).compute(in, new TransferStatus()).hash; final StringBuilder fp = new StringBuilder(undelimited.substring(0, 2)); for(int i = 2; i <= undelimited.length() - 2; i += 2) { fp.append(":").append(undelimited.substring(i, i + 2)); } return fp.toString(); } }
@Override public void cleanup(final Transfer download) { // Save checksum before edit try { checksum = ChecksumComputeFactory.get(HashAlgorithm.md5).compute(local.getInputStream(), new TransferStatus()); } catch(BackgroundException e) { log.warn(String.format("Error computing checksum for %s. %s", local, e.getDetail())); } } };
listener.message(MessageFormat.format( LocaleFactory.localizedString("Compute MD5 hash of {0}", "Status"), local.getName())); current = ChecksumComputeFactory.get(HashAlgorithm.md5).compute(local.getInputStream(), new TransferStatus());
current = ChecksumComputeFactory.get(HashAlgorithm.md5).compute(file.getInputStream(), new TransferStatus()); if(log.isDebugEnabled()) { log.debug(String.format("Current checksum for %s is %s", file, current));
if(Checksum.NONE != append.checksum) { final ChecksumCompute compute = ChecksumComputeFactory.get(append.checksum.algorithm); if(compute.compute(local.getInputStream(), parent).equals(append.checksum)) { if(log.isInfoEnabled()) { log.info(String.format("Skip file %s with checksum %s", file, local.attributes().getChecksum()));
ChecksumComputeFactory.get(HashAlgorithm.md5).compute(concat.toString(), new TransferStatus()), completed.size()); final String reference; if(complete.getEtag().startsWith("\"") && complete.getEtag().endsWith("\"")) {
@Override public StorageObject upload(final Path file, final Local local, final BandwidthThrottle throttle, final StreamListener listener, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException { if(Checksum.NONE == status.getChecksum()) { // The client-side checksum is passed to the BlackPearl gateway by supplying the applicable CRC HTTP header. // If this is done, the BlackPearl gateway verifies that the data received matches the checksum provided. // End-to-end data protection requires that the client provide the CRC when uploading the object and then // verify the CRC after downloading the object at a later time (see Get Object). The BlackPearl gateway also // verifies the CRC when reading from physical data stores so the gateway can identify problems before // transmitting data to the client. status.setChecksum(writer.checksum(file).compute(local.getInputStream(), status)); } // Make sure file is available in cache final List<TransferStatus> chunks = bulk.query(Transfer.Type.upload, file, status); StorageObject stored = null; for(TransferStatus chunk : chunks) { chunk.setChecksum(ChecksumComputeFactory.get(HashAlgorithm.md5).compute(local.getInputStream(), chunk)); stored = super.upload(file, local, throttle, listener, chunk, callback); } return stored; }
@Override public B2UploadPartResponse call() throws BackgroundException { final TransferStatus status = new TransferStatus().length(len); final ByteArrayEntity entity = new ByteArrayEntity(content, off, len); final Checksum checksum = ChecksumComputeFactory.get(HashAlgorithm.sha1) .compute(new ByteArrayInputStream(content, off, len), status); try { return session.getClient().uploadLargeFilePart(version.id, segment, entity, checksum.hash); } catch(B2ApiException e) { throw new B2ExceptionMappingService().map("Upload {0} failed", e, file); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map("Upload {0} failed", e, file); } } }, new DisabledProgressListener(), new TransferBackgroundActionState(overall)).call());
public void write(final Path file, final byte[] content, final TransferStatus status) throws BackgroundException { final Write<?> write = session._getFeature(Write.class); status.setLength(content.length); status.setChecksum(write.checksum(file).compute(new ByteArrayInputStream(content), status)); final StatusOutputStream<?> out = write.write(file, status, new DisabledConnectionCallback()); try { IOUtils.write(content, out); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map(e); } finally { new DefaultStreamCloser().close(out); } } }
if(Checksum.NONE != attributes.getChecksum()) { final ChecksumCompute compute = ChecksumComputeFactory.get(attributes.getChecksum().algorithm); if(compute.compute(local.getInputStream(), parent).equals(attributes.getChecksum())) { if(log.isInfoEnabled()) { log.info(String.format("Skip file %s with checksum %s", file, local.attributes().getChecksum()));
case AWS4HMACSHA256: status.setChecksum(ChecksumComputeFactory.get(HashAlgorithm.sha256) .compute(new ByteArrayInputStream(content, off, len), status) ); break;
ChecksumComputeFactory.get(HashAlgorithm.md5).compute(concat.toString(), new TransferStatus()), completed.size()); final String reference; if(complete.getEtag().startsWith("\"") && complete.getEtag().endsWith("\"")) {
@Override public Path mkdir(final Path folder, final String region, final TransferStatus status) throws BackgroundException { if(containerService.isContainer(folder)) { return super.mkdir(folder, region, status); } else { if(Checksum.NONE == status.getChecksum()) { status.setChecksum(writer.checksum(folder).compute(new NullInputStream(0L), status)); } return super.mkdir(folder, region, status); } } }
return delegate.compute(sink, new TransferStatus());
switch(session.getSignatureVersion()) { case AWS4HMACSHA256: status.setChecksum(writer.checksum(file).compute(local.getInputStream(), status)); break;
final TransferStatus status = new TransferStatus().length(len); status.setChecksum(SwiftLargeUploadWriteFeature.this.checksum(file) .compute(new ByteArrayInputStream(content, off, len), status) );
listener.message(MessageFormat.format(LocaleFactory.localizedString("Calculate checksum for {0}", "Status"), file.getName())); final Checksum download = compute.compute(local.getInputStream(), new TransferStatus()); if(!checksum.equals(download)) { throw new ChecksumException(
@Override public Path touch(final Path file, final TransferStatus status) throws BackgroundException { if(Checksum.NONE == status.getChecksum()) { status.setChecksum(writer.checksum(file).compute(new NullInputStream(0L), status)); } status.setTimestamp(System.currentTimeMillis()); final StatusOutputStream<BaseB2Response> out = writer.write(file, status, new DisabledConnectionCallback()); new DefaultStreamCloser().close(out); return new Path(file.getParent(), file.getName(), file.getType(), new B2AttributesFinderFeature(session, fileid).toAttributes((B2FileResponse) out.getStatus())); }
@Override public StorageObject upload(final Path file, final Local local, final BandwidthThrottle throttle, final StreamListener listener, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException { final S3Protocol.AuthenticationHeaderSignatureVersion signatureVersion = session.getSignatureVersion(); switch(signatureVersion) { case AWS4HMACSHA256: if(Checksum.NONE == status.getChecksum()) { status.setChecksum(writer.checksum(file).compute(local.getInputStream(), status)); } break; } try { return super.upload(file, local, throttle, listener, status, callback); } catch(InteroperabilityException e) { if(!session.getSignatureVersion().equals(signatureVersion)) { // Retry if upload fails with Header "x-amz-content-sha256" set to the hex-encoded SHA256 hash of the // request payload is required for AWS Version 4 request signing return this.upload(file, local, throttle, listener, status, callback); } throw e; } }