Class ProgressTrackingInputStream

java.lang.Object
java.io.InputStream
java.io.FilterInputStream
org.saidone.misc.ProgressTrackingInputStream
All Implemented Interfaces:
Closeable, AutoCloseable

public class ProgressTrackingInputStream extends FilterInputStream
InputStream wrapper that logs read progress for debugging purposes.

The wrapper counts the number of bytes read from the underlying stream and logs the progress in 10% increments when trace logging is enabled.

  • Constructor Details

    • ProgressTrackingInputStream

      public ProgressTrackingInputStream(InputStream in, String nodeId, long contentLength)
      Creates a new progress tracking stream.
      Parameters:
      in - the wrapped input stream
      nodeId - identifier of the node being read
      contentLength - total expected length of the stream in bytes
  • Method Details

    • read

      public int read() throws IOException
      Reads a single byte from the stream and updates the progress.
      Overrides:
      read in class FilterInputStream
      Returns:
      the byte read or -1 if the end of the stream is reached
      Throws:
      IOException - if an I/O error occurs
    • read

      public int read(byte[] b, int off, int len) throws IOException
      Reads bytes into an array and updates the read progress.
      Overrides:
      read in class FilterInputStream
      Parameters:
      b - the buffer into which the data is read
      off - the start offset in the destination array
      len - the maximum number of bytes to read
      Returns:
      the number of bytes read or -1 if the end of the stream is reached
      Throws:
      IOException - if an I/O error occurs