use of org.commonjava.maven.galley.io.checksum.ChecksummingOutputStream in project galley by Commonjava.
the class ChecksummingTransferDecorator method decorateWrite.
public OutputStream decorateWrite(final OutputStream stream, final Transfer transfer, final TransferOperation op, final EventMetadata eventMetadata) throws IOException {
Object forceObj = eventMetadata.get(FORCE_CHECKSUM);
boolean force = Boolean.TRUE.equals(forceObj) || Boolean.parseBoolean(String.valueOf(forceObj));
SpecialPathInfo specialPathInfo = specialPathManager.getSpecialPathInfo(transfer, eventMetadata.getPackageType());
logger.trace("SpecialPathInfo for: {} is: {} (decoratable? {})", transfer, specialPathInfo, (specialPathInfo == null || specialPathInfo.isDecoratable()));
if (force || specialPathInfo == null || specialPathInfo.isDecoratable()) {
ChecksummingDecoratorAdvisor.ChecksumAdvice advice = writerFilter.getDecorationAdvice(transfer, op, eventMetadata);
if (force && advice == NO_DECORATE) {
advice = CALCULATE_NO_WRITE;
}
boolean consumerNeedsIt = (consumer == null || consumer.needsMetadataFor(transfer));
logger.trace("Advice is: {} for {} of: {} (and consumer is missing or needs it? {})", advice, op, transfer, consumerNeedsIt);
// 2. if we have a metadata consumer AND the consumer needs metadata for this transfer
if (advice != NO_DECORATE && (consumer == null || consumer.needsMetadataFor(transfer))) {
logger.trace("Wrapping output stream to: {} for checksum generation.", transfer);
return new ChecksummingOutputStream(checksumFactories, stream, transfer, consumer, advice == CALCULATE_AND_WRITE);
}
}
logger.trace("NOT decorating write with ChecksummingTransferDecorator for: {}", transfer);
return stream;
}
Aggregations