Search in sources :

Example 1 with TransferOutputStream

use of org.commonjava.maven.galley.util.TransferOutputStream in project galley by Commonjava.

the class Transfer method openOutputStream.

public OutputStream openOutputStream(final TransferOperation accessType, final boolean fireEvents, final EventMetadata eventMetadata) throws IOException {
    provider.waitForWriteUnlock(resource);
    try {
        provider.lockWrite(resource);
        OutputStream stream = provider.openOutputStream(resource);
        if (stream == null) {
            return null;
        }
        final TransferUnlocker unlocker = new TransferUnlocker(resource, provider);
        if (fireEvents) {
            logger.info("Wrapping output stream to: {} using event metadata: {}", this, eventMetadata);
            stream = new TransferOutputStream(stream, unlocker, new FileStorageEvent(accessType, this, eventMetadata), fileEventManager);
        } else {
            logger.info("Wrapping output stream to: {} WITHOUT event metadata", this);
            stream = new TransferOutputStream(stream, unlocker);
        }
        stream = decorator == null ? stream : decorator.decorateWrite(stream, this, accessType, eventMetadata);
        return stream;
    } catch (final IOException e) {
        if (fireEvents) {
            fileEventManager.fire(new FileErrorEvent(this, e, eventMetadata));
        }
        throw e;
    }
}
Also used : FileStorageEvent(org.commonjava.maven.galley.event.FileStorageEvent) OutputStream(java.io.OutputStream) TransferOutputStream(org.commonjava.maven.galley.util.TransferOutputStream) FileErrorEvent(org.commonjava.maven.galley.event.FileErrorEvent) IOException(java.io.IOException) TransferOutputStream(org.commonjava.maven.galley.util.TransferOutputStream)

Aggregations

IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 FileErrorEvent (org.commonjava.maven.galley.event.FileErrorEvent)1 FileStorageEvent (org.commonjava.maven.galley.event.FileStorageEvent)1 TransferOutputStream (org.commonjava.maven.galley.util.TransferOutputStream)1