Class MeasuredOutputStream

  • All Implemented Interfaces:
    Closeable, Flushable, AutoCloseable
    Direct Known Subclasses:
    GuardedOutputStream


    public class MeasuredOutputStream
    extends OutputStream
    This OutputStream passes information along to an underlying OutputStream while counting how many bytes are written.

    At any point calling getWrittenCount() tells how the amount of data that has been written since this object was constructed.

    Also you can add a ChangeListener to this stream to be notified every time a specific amount of bytes are written.

    • Field Detail

      • written

        protected long written
    • Constructor Detail

      • MeasuredOutputStream

        public MeasuredOutputStream(OutputStream out)
    • Method Detail

      • addChangeListener

        public void addChangeListener(ChangeListener l,
                                      long interval,
                                      boolean consumeExceptions)
        Parameters:
        l - the listener to add
        interval - the amount of bytes to write before notifying the listener. Must be 1 or greater. The listener will be notified each time this threshold is crossed, or when this stream is closed.
        consumeExceptions - is true, then exceptions that occur while calling ChangeListener.stateChanged(..) are printed to the console. If false: they are allowed to ripple outward and interrupt calls to OutputStream.write(..) or OutputStream.close().
      • removeChangeListener

        public void removeChangeListener(ChangeListener l)
      • fireListeners

        protected void fireListeners(boolean skipThreshold)
      • getBytesWritten

        public long getBytesWritten()
        Returns the number of bytes written since this object was constructed.
        Returns:
        the number of bytes written since this object was constructed.
      • isClosed

        public boolean isClosed()