Search in sources :

Example 1 with Action

use of org.alfresco.service.cmr.repository.TransformationOptionPair.Action in project alfresco-repository by Alfresco.

the class AbstractContentReader method getContentInputStream.

/**
 * @see Channels#newInputStream(java.nio.channels.ReadableByteChannel)
 */
public InputStream getContentInputStream() throws ContentIOException {
    try {
        ReadableByteChannel channel = getReadableChannel();
        InputStream is = Channels.newInputStream(channel);
        // If we have a timeout or read limit, intercept the calls.
        if (limits != null) {
            TransformationOptionPair time = limits.getTimePair();
            TransformationOptionPair kBytes = limits.getKBytesPair();
            long timeoutMs = time.getValue();
            long readLimitBytes = kBytes.getValue() * 1024;
            if (timeoutMs > 0 || readLimitBytes > 0) {
                Action timeoutAction = time.getAction();
                Action readLimitAction = kBytes.getAction();
                is = new TimeSizeRestrictedInputStream(is, timeoutMs, timeoutAction, readLimitBytes, readLimitAction, transformerDebug);
            }
        }
        is = new BufferedInputStream(is);
        // done
        return is;
    } catch (Throwable e) {
        throw new ContentIOException("Failed to open stream onto channel: \n" + "   accessor: " + this, e);
    }
}
Also used : ReadableByteChannel(java.nio.channels.ReadableByteChannel) Action(org.alfresco.service.cmr.repository.TransformationOptionPair.Action) BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) TransformationOptionPair(org.alfresco.service.cmr.repository.TransformationOptionPair) ContentIOException(org.alfresco.service.cmr.repository.ContentIOException)

Aggregations

BufferedInputStream (java.io.BufferedInputStream)1 InputStream (java.io.InputStream)1 ReadableByteChannel (java.nio.channels.ReadableByteChannel)1 ContentIOException (org.alfresco.service.cmr.repository.ContentIOException)1 TransformationOptionPair (org.alfresco.service.cmr.repository.TransformationOptionPair)1 Action (org.alfresco.service.cmr.repository.TransformationOptionPair.Action)1