Class LimitedStreamCopier


  • public final class LimitedStreamCopier
    extends Object
    This class is a simple utility to copy bytes from an InputStream to an OutputStream. The copy can be performed with an optional byte limit and as soon as this limit is reached, the copy will be stopped immediately and a ContentLimitViolationException will be thrown.
    Since:
    Thor
    • Constructor Detail

      • LimitedStreamCopier

        public LimitedStreamCopier()
    • Method Detail

      • copyStreams

        public final int copyStreams​(InputStream in,
                                     OutputStream out,
                                     long sizeLimit)
                              throws IOException
        Copy of the the Spring FileCopyUtils, but does not silently absorb IOExceptions when the streams are closed. We require the stream write to happen successfully.

        Both streams are closed but any IOExceptions are thrown

        Parameters:
        in - the stream from which to read content.
        out - the stream to which to write content.
        sizeLimit - the maximum number of bytes that will be copied between the streams before a ContentLimitViolationException will be thrown. A negative number or zero will be deemed to mean 'no limit'.
        Throws:
        IOException