Package org.saidone.misc
Class ProgressTrackingInputStream
java.lang.Object
java.io.InputStream
java.io.FilterInputStream
org.saidone.misc.ProgressTrackingInputStream
- All Implemented Interfaces:
Closeable
,AutoCloseable
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.
-
Field Summary
Fields inherited from class java.io.FilterInputStream
in
-
Constructor Summary
ConstructorsConstructorDescriptionProgressTrackingInputStream
(InputStream in, String nodeId, long contentLength) Creates a new progress tracking stream. -
Method Summary
Methods inherited from class java.io.FilterInputStream
available, close, mark, markSupported, read, reset, skip
Methods inherited from class java.io.InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo
-
Constructor Details
-
ProgressTrackingInputStream
Creates a new progress tracking stream.- Parameters:
in
- the wrapped input streamnodeId
- identifier of the node being readcontentLength
- total expected length of the stream in bytes
-
-
Method Details
-
read
Reads a single byte from the stream and updates the progress.- Overrides:
read
in classFilterInputStream
- Returns:
- the byte read or
-1
if the end of the stream is reached - Throws:
IOException
- if an I/O error occurs
-
read
Reads bytes into an array and updates the read progress.- Overrides:
read
in classFilterInputStream
- Parameters:
b
- the buffer into which the data is readoff
- the start offset in the destination arraylen
- 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
-