Class ProgressTrackingOutputStream

java.lang.Object
java.io.OutputStream
java.io.FilterOutputStream
org.saidone.misc.ProgressTrackingOutputStream
All Implemented Interfaces:
Closeable, Flushable, AutoCloseable

public class ProgressTrackingOutputStream extends FilterOutputStream
OutputStream wrapper that logs upload progress for debugging purposes.

Bytes written to the underlying stream are counted and progress is logged in 10% increments when trace logging is enabled.

  • Constructor Details

    • ProgressTrackingOutputStream

      public ProgressTrackingOutputStream(OutputStream out, String nodeId, long contentLength)
      Creates a new progress tracking output stream.
      Parameters:
      out - the underlying output stream
      nodeId - identifier of the node being written
      contentLength - total expected length of the stream in bytes
  • Method Details

    • write

      public void write(int b) throws IOException
      Writes a single byte and updates the write progress.
      Overrides:
      write in class FilterOutputStream
      Parameters:
      b - the byte to be written
      Throws:
      IOException - if an I/O error occurs
    • write

      public void write(byte[] b, int off, int len) throws IOException
      Writes bytes from a buffer and updates the write progress.
      Overrides:
      write in class FilterOutputStream
      Parameters:
      b - the data
      off - the start offset in the data
      len - the number of bytes to write
      Throws:
      IOException - if an I/O error occurs