Class GuardedOutputStream

  • All Implemented Interfaces:
    Closeable, Flushable, AutoCloseable


    public class GuardedOutputStream
    extends MeasuredOutputStream
    This restricts the amount of data that can be written to an underlying OutputStream.

    This is especially useful in unit testing to ensure that certain blocks of data do not exceed their allotted size.

    An IOException is thrown if you attempt to write more data than this stream was told to allow.

    • Constructor Detail

      • GuardedOutputStream

        public GuardedOutputStream(OutputStream out,
                                   long limit)
        Constructs a new GuardedOutputStream.
        Parameters:
        out - the underlying OutputStream to send data to.
        limit - the number of bytes that can be written