public class RepeatableInputStream extends InputStream implements Repeatable, Serializable
RepeatableInputStream adds functionality to another input stream,
the ability to read repeatedly.
By repeatable-read we mean, after close(), the next invocation of
read() will re-open the input stream.
RepeatableInputStream actually creates a temporary space
to buffer the content, so it can be re-opened again after closed.
Notice that the temporary space (a.k.a., the buffered input stream)
is never closed until garbage-collected.
If the content size of the given input stream is smaller than
the value specified in the system property called
"org.zkoss.io.memoryLimitSize", the content will be buffered in
the memory. If the size exceeds, the content will be buffered in
a temporary file. By default, it is 512KB.
Note: the maximal value is Integer.MAX_VALUE
If the content size of the given input stream is larger than
the value specified in the system property called
"org.zkoss.io.bufferLimitSize", the content won't be buffered,
and it means the read is not repeatable. By default, it is 20MB.
Note: the maximal value is Integer.MAX_VALUE
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes the current access, and the next call of
close()
re-opens the buffered input stream. |
protected void |
finalize() |
static InputStream |
getInstance(File file)
Returns an input stream of a file that can be read repeatedly.
|
static InputStream |
getInstance(InputStream is)
Returns an input stream that can be read repeatedly, or null if the
given input stream is null.
|
static InputStream |
getInstance(String filename)
Returns an input stream of a file that can be read repeatedly.
|
static InputStream |
getInstance(URL url)
Returns an input stream of the resource of the given URL
that can be read repeatedly.
|
int |
read() |
available, mark, markSupported, read, read, reset, skippublic static InputStream getInstance(InputStream is)
close() is called.
By repeatable-read we mean, after close(), the next
invocation of read() will re-open the input stream.
Use this method instead of instantiating RepeatableInputStream
with the constructor.
getInstance(File)public static InputStream getInstance(File file) throws FileNotFoundException
By repeatable-read we mean, after close(), the next
invocation of read() will re-open the input stream.
Note: it is efficient since we don't have to buffer the content of the file to make it repeatable-read.
IllegalArgumentException - if file is null.FileNotFoundException - if file not foundgetInstance(InputStream),
getInstance(String)public static InputStream getInstance(String filename) throws FileNotFoundException
By repeatable-read we mean, after close(), the next
invocation of read() will re-open the input stream.
Note: it is efficient since we don't have to buffer the content of the file to make it repeatable-read.
IllegalArgumentException - if file is null.FileNotFoundExceptiongetInstance(InputStream),
getInstance(File)public static InputStream getInstance(URL url)
By repeatable-read we mean, after close(), the next
invocation of read() will re-open the input stream.
Note: it is efficient since we don't have to buffer the content of the resource to make it repeatable-read.
IllegalArgumentException - if url is null.getInstance(InputStream),
getInstance(String)public int read()
throws IOException
read in class InputStreamIOExceptionpublic void close()
throws IOException
close()
re-opens the buffered input stream.close in interface Closeableclose in interface AutoCloseableclose in class InputStreamIOExceptionCopyright © 2018. All rights reserved.