|
2.17.2: 2011-06-17 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.basedb.util.StreamCacher
public class StreamCacher
Caches the contents of a stream to a local temporary file. The
getNewStream()
method will create a stream that appears
to be reading from the start of the master stream, except that
it will read cached data to begin with and continue with the master
stream only if needed.
This class is useful when you know (or suspect) that you need to read the same stream multiple times, but the stream may be "expensive" to retrieve, either in terms of network capacity or cpu processing.
File.getCachedDownloadStream()
Field Summary | |
---|---|
private File |
cacheFile
|
private OutputStream |
cacheOut
|
private InputStream |
master
|
private InputStream |
splitter
|
Constructor Summary | |
---|---|
StreamCacher(InputStream master)
Create a new stream cacher for reading from the given master stream. |
|
StreamCacher(InputStream master,
File cacheFile)
Create a new stream cacher for reading from the given master stream. |
Method Summary | |
---|---|
void |
close()
Close the master stream and remove the cached file data. |
InputStream |
getNewStream()
Get a new stream that appears to be reading from the start of the master stream. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private final InputStream master
private final InputStream splitter
private final File cacheFile
private final OutputStream cacheOut
Constructor Detail |
---|
public StreamCacher(InputStream master) throws IOException
master
- The master input stream
IOException
public StreamCacher(InputStream master, File cacheFile) throws IOException
master
- The master input streamcacheFile
- Use this file for the cached data, if the file
already exist it will be overwritten, if this parameter is null
a random file will be created in the default temporary directory
IOException
Method Detail |
---|
public void close()
public InputStream getNewStream() throws IOException
IOException
|
2.17.2: 2011-06-17 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |