Search in sources :

Example 1 with ChecksummingOutputStream

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;
}
Also used : ChecksummingOutputStream(org.commonjava.maven.galley.io.checksum.ChecksummingOutputStream) 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 ChecksummingOutputStream (org.commonjava.maven.galley.io.checksum.ChecksummingOutputStream)1 SpecialPathInfo (org.commonjava.maven.galley.model.SpecialPathInfo)1