Package net.sf.basedb.util
Class InputStreamTracker
java.lang.Object
java.io.InputStream
net.sf.basedb.util.InputStreamTracker
- All Implemented Interfaces:
Closeable
,AutoCloseable
- Direct Known Subclasses:
ProgressInputStream
This class is used to keep track of the number of bytes read from the
underlying input stream. This is very useful for code that needs to
reporter progress but are having difficulties to know the number of
processed bytes.
- Version:
- 2.4
- Author:
- nicklas
- Last modified
- $Date: 2020-11-09 14:40:05 +0100 (Mon, 09 Nov 2020) $
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Apply a curved scale factor that has a max upper limit.static class
Do not scale number of bytes.static class
Apply a linear scale factor so that when we have read N actual bytes the getNumRead() method return N*scale bytes.static interface
A scale factor can be used to match number of read bytes to something that better resembles actual progress. -
Field Summary
Modifier and TypeFieldDescriptionprivate final InputStream
The source input stream to read from.private long
The number of bytes that has been read from the underlying input stream so far.private long
The number of bytes that had been read whenmark(int)
was called.private final InputStreamTracker.ScaleFactor
A scale factor to apply when counting bytes. -
Constructor Summary
ConstructorDescriptionCreate a new input stream tracker.InputStreamTracker
(InputStream in, InputStreamTracker.ScaleFactor scaleFactor) Create a new input stream tracker. -
Method Summary
Methods inherited from class java.io.InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo
-
Field Details
-
in
The source input stream to read from. -
scaleFactor
A scale factor to apply when counting bytes. -
numRead
private long numReadThe number of bytes that has been read from the underlying input stream so far. -
numReadAtMark
private long numReadAtMarkThe number of bytes that had been read whenmark(int)
was called.
-
-
Constructor Details
-
InputStreamTracker
Create a new input stream tracker.- Parameters:
in
- The input stream to read from
-
InputStreamTracker
Create a new input stream tracker.- Parameters:
in
- The input stream to read fromscaleFactor
- A scale factor to apply when counting bytes- Since:
- 3.17.1
-
-
Method Details
-
available
- Overrides:
available
in classInputStream
- Throws:
IOException
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classInputStream
- Throws:
IOException
-
mark
public void mark(int readlimit) - Overrides:
mark
in classInputStream
-
markSupported
public boolean markSupported()- Overrides:
markSupported
in classInputStream
-
read
- Specified by:
read
in classInputStream
- Throws:
IOException
-
read
- Overrides:
read
in classInputStream
- Throws:
IOException
-
read
- Overrides:
read
in classInputStream
- Throws:
IOException
-
reset
- Overrides:
reset
in classInputStream
- Throws:
IOException
-
skip
- Overrides:
skip
in classInputStream
- Throws:
IOException
-
getNumRead
public long getNumRead()Get the number of bytes read or skipped from the input stream. If the underlying stream supportsreset()
this will also reset the number of read bytes to the latestmark(int)
position.- Returns:
- The number of bytes that has been read so far
-