Class ProgressOutputStream

  • All Implemented Interfaces:
    Disposable, java.io.Closeable, java.io.Flushable, java.lang.AutoCloseable

    public class ProgressOutputStream
    extends OutputStreamDecorator<java.io.OutputStream>
    An output stream that provides progres events for bytes written.
    Author:
    Garret Wilson
    • Constructor Detail

      • ProgressOutputStream

        public ProgressOutputStream​(java.io.OutputStream outputStream)
        Decorates the given output stream.
        Parameters:
        outputStream - The output stream to decorate.
        Throws:
        java.lang.NullPointerException - if the given stream is null.
    • Method Detail

      • write

        public void write​(int b)
                   throws java.io.IOException
        Writes the specified byte to the decorated output stream. This version delegates to write(int) to ensure that no bytes written are noted more than once
        Overrides:
        write in class OutputStreamDecorator<java.io.OutputStream>
        Parameters:
        b - The byte to write.
        Throws:
        java.io.IOException - if an I/O error occurs.
      • write

        public void write​(byte[] bytes)
                   throws java.io.IOException
        Writes all the bytes from the specified byte array to the decorated output stream. This version delegates to write(byte[], int, int) to ensure that no bytes written are noted more than once
        Overrides:
        write in class OutputStreamDecorator<java.io.OutputStream>
        Parameters:
        bytes - The bytes to write.
        Throws:
        java.lang.NullPointerException - if the given byte array is null.
        java.io.IOException - if an I/O error occurs.
      • write

        public void write​(byte[] bytes,
                          int offset,
                          int length)
                   throws java.io.IOException
        Writes specified number of bytes from the specified byte array to the decorated output stream starting at the given offset.
        Overrides:
        write in class OutputStreamDecorator<java.io.OutputStream>
        Parameters:
        bytes - The bytes to write.
        offset - The start offset in the data.
        length - The number of bytes to write.
        Throws:
        java.lang.NullPointerException - if the given byte array is null.
        java.lang.IndexOutOfBoundsException - if the given offset is negative, or the given offset plus the given length is greater than the length of the given array.
        java.io.IOException - if an I/O error occurs.
      • addProgressListener

        public void addProgressListener​(ProgressListener progressListener)
        Adds a progress listener.
        Parameters:
        progressListener - The progress listener to add.
      • removeProgressListener

        public void removeProgressListener​(ProgressListener progressListener)
        Removes an progress listener.
        Parameters:
        progressListener - The progress listener to remove.
      • fireProgressed

        public void fireProgressed​(long delta,
                                   long value,
                                   long maximum)
        Fires a progress event to all registered progress listeners. This method delegates to fireProgressed(ProgressEvent).
        Parameters:
        delta - The amount of recent progress, or -1 if not known.
        value - The total progress to this point, or -1 if not known.
        maximum - The goal, or -1 if not known.
        See Also:
        ProgressListener, ProgressEvent
      • fireProgressed

        protected void fireProgressed​(ProgressEvent progressEvent)
        Fires a given progress event to all registered progress listeners.
        Parameters:
        progressEvent - The progress event to fire.