Package nl.vpro.util
Class FileCachingInputStream
java.lang.Object
java.io.InputStream
nl.vpro.util.FileCachingInputStream
- All Implemented Interfaces:
Closeable
,AutoCloseable
When wrapping this around your inputstream, it will be read as fast a possible, but you can consume from it slower.
It will first buffer to an internal byte array (if the initial buffer size > 0, defaults to 2048). If that is too small it will buffer the result to a temporary file.
Use this if you want to consume an inputstream as fast as possible, while handing it at a slower pace. The cost is the creation of the temporary file.
- Since:
- 0.50
- Author:
- Michiel Meeuwissen
-
Nested Class Summary
-
Method Summary
Modifier and TypeMethodDescriptionint
builder()
void
close()
protected void
void
int
long
getCount()
Returns the number of bytes consumed from the input stream so farReturns the exception that may have happened.If a temp file is used for buffering, you may obtain it.boolean
isClosed()
boolean
isReady()
Returns whether consuming the inputstream is ready.int
read()
int
read
(byte @NonNull [] b, int off, int len) static Consumer<FileCachingInputStream>
toString()
long
waitForBytesRead
(int atLeast) Wait until the copier thread read at least the number of bytes given.Methods inherited from class java.io.InputStream
mark, markSupported, nullInputStream, read, readAllBytes, readNBytes, readNBytes, reset, skip, skipNBytes, transferTo
-
Method Details
-
available
- Overrides:
available
in classInputStream
- Throws:
IOException
-
getBufferLength
public int getBufferLength() -
read
- Specified by:
read
in classInputStream
- Throws:
IOException
-
read
- Overrides:
read
in classInputStream
- Throws:
IOException
-
closeTempFile
- Throws:
IOException
-
deleteTempFile
public void deleteTempFile() -
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classInputStream
- Throws:
IOException
-
toString
-
waitForBytesRead
Wait until the copier thread read at least the number of bytes given.- Throws:
InterruptedException
-
getCount
public long getCount()Returns the number of bytes consumed from the input stream so far -
isReady
public boolean isReady()Returns whether consuming the inputstream is ready. -
getException
Returns the exception that may have happened. E.g. for use in the call back. -
throttle
-
builder
-
getTempFile
If a temp file is used for buffering, you may obtain it. -
isClosed
public boolean isClosed() -
getExpectedCount
-
getFuture
-