Search in sources :

Example 1 with ChecksummingInputStream

use of org.commonjava.maven.galley.io.checksum.ChecksummingInputStream in project galley by Commonjava.

the class ChecksummingTransferDecorator method decorateRead.

@Override
public InputStream decorateRead(final InputStream stream, final Transfer transfer, 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);
    logger.trace("SpecialPathInfo for: {} is: {} (decoratable? {})", transfer, specialPathInfo, (specialPathInfo == null ? true : specialPathInfo.isDecoratable()));
    if (force || specialPathInfo == null || specialPathInfo.isDecoratable()) {
        ChecksummingDecoratorAdvisor.ChecksumAdvice advice = readerFilter.getDecorationAdvice(transfer, DOWNLOAD, 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, DOWNLOAD, 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))) {
            return new ChecksummingInputStream(checksumFactories, stream, transfer, consumer, advice == CALCULATE_AND_WRITE);
        }
    }
    logger.trace("NOT decorating read with ChecksummingTransferDecorator for: {}", transfer);
    return stream;
}
Also used : ChecksummingInputStream(org.commonjava.maven.galley.io.checksum.ChecksummingInputStream) ChecksummingDecoratorAdvisor(org.commonjava.maven.galley.io.checksum.ChecksummingDecoratorAdvisor) SpecialPathInfo(org.commonjava.maven.galley.model.SpecialPathInfo)

Aggregations

ChecksummingDecoratorAdvisor (org.commonjava.maven.galley.io.checksum.ChecksummingDecoratorAdvisor)1 ChecksummingInputStream (org.commonjava.maven.galley.io.checksum.ChecksummingInputStream)1 SpecialPathInfo (org.commonjava.maven.galley.model.SpecialPathInfo)1