Package net.sf.basedb.util
Class ProgressInputStream
- java.lang.Object
-
- java.io.InputStream
-
- net.sf.basedb.util.InputStreamTracker
-
- net.sf.basedb.util.ProgressInputStream
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
public class ProgressInputStream extends InputStreamTracker
Input stream wrapper that calls a progress reporter at regular intervals. The default interval is 1MB of processed data. The default progress message is simply to write the number of bytes processed. If a different message is required theprogressReport(String)
method should be overridden.- Since:
- 3.9
- Author:
- nicklas
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class net.sf.basedb.util.InputStreamTracker
InputStreamTracker.CurvedScaleFactor, InputStreamTracker.IdentityScaleFactor, InputStreamTracker.LinearScaleFactor, InputStreamTracker.ScaleFactor
-
-
Field Summary
Fields Modifier and Type Field Description protected long
interval
protected long
nextProgress
protected AbsoluteProgressReporter
progress
-
Constructor Summary
Constructors Constructor Description ProgressInputStream(InputStream in, AbsoluteProgressReporter progress)
Create a new input stream using the default 1MB interval.ProgressInputStream(InputStream in, AbsoluteProgressReporter progress, long interval)
Create a new input stream using the specified interval.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
progressReport(String message)
Send a progress report with the given message.int
read(byte[] b, int off, int len)
-
Methods inherited from class net.sf.basedb.util.InputStreamTracker
available, close, getNumRead, mark, markSupported, read, read, reset, skip
-
Methods inherited from class java.io.InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, transferTo
-
-
-
-
Field Detail
-
progress
protected final AbsoluteProgressReporter progress
-
interval
protected final long interval
-
nextProgress
protected long nextProgress
-
-
Constructor Detail
-
ProgressInputStream
public ProgressInputStream(InputStream in, AbsoluteProgressReporter progress)
Create a new input stream using the default 1MB interval.
-
ProgressInputStream
public ProgressInputStream(InputStream in, AbsoluteProgressReporter progress, long interval)
Create a new input stream using the specified interval.
-
-
Method Detail
-
read
public int read(byte[] b, int off, int len) throws IOException
- Overrides:
read
in classInputStreamTracker
- Throws:
IOException
-
progressReport
protected void progressReport(String message)
Send a progress report with the given message. This method is called automatically at the given intervals. The default message is the number of bytes read so far (formatted as a string withValues.formatBytes(Long, int)
). Subclasses may override this method to generate a different message.
-
-