|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.io.InputStream
jut.io.InputStreamCache
public class InputStreamCache
InputStream caching the data read and providing them as new InputStream on
request. caching is done in memory and/or in file.
| Nested Class Summary | |
|---|---|
static interface |
InputStreamCache.ByteArrayCache
provider interface for large byte arrays that can be used as memory cache. |
| Field Summary | |
|---|---|
protected byte[] |
cache
the current memory cache or null if none. |
protected File |
cacheDir
cache file directory, null for no file caching. |
protected File |
cacheFile
cache file to use ( null if none). |
protected OutputStream |
cacheFileOut
cache file output stream ( null if none). |
protected boolean |
cacheOK
cache state of the stream. |
protected int |
cachePtr
the current memory cache pointer. if cache is null, contains size of the last byte
array cache used. |
protected ArrayList<byte[]> |
caches
the memory caches used. |
protected InputStreamCache.ByteArrayCache |
cacheSource
the source for memory cache arrays. |
protected boolean |
closed
current state of the stream. |
static InputStreamCache.ByteArrayCache |
defCacheSource
default source for memory cache arrays, returning 1MB blocks if more than 10MB free memory is available. |
protected ParamRunnable<Iterable<byte[]>> |
overflowHandler
overflow handler for memory-only stream caches or null if none. |
protected InputStream |
source
the source input stream. |
| Constructor Summary | |
|---|---|
InputStreamCache(InputStream source)
create a new InputStreamCache that only uses in-memory caching. |
|
InputStreamCache(InputStream source,
boolean fileCache)
create a new InputStreamCache. as cache directory, the directory from the system property
java.io.tmpdir is used. |
|
InputStreamCache(InputStream source,
File cacheDir)
create a new InputStreamCache. |
|
| Method Summary | |
|---|---|
int |
available()
|
void |
close()
|
protected void |
finalize()
|
InputStream |
getData()
returns an InputStream for the data cached. this method may only be called after
calling close(). if the data was discarded because it didn't fit into the cache,
returns null. |
int |
read()
|
int |
read(byte[] buffer)
|
int |
read(byte[] buffer,
int off,
int len)
|
void |
release()
release resources, i.e., release memory buffers and delete temp cache file. if the temp file exists but can not be deleted, a message is written to stderr. this may occur due to a couple of reasons - search the Internet e.g. for "java delete file system.gc". |
void |
setOverflowHandler(ParamRunnable<Iterable<byte[]>> overflowHandler)
set the overflow handler to run if a memory-only stream cache surpasses its size limit. |
protected void |
write(byte[] data,
int off,
int len)
write data into the internal cache if applicable. |
| Methods inherited from class java.io.InputStream |
|---|
mark, markSupported, reset, skip |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static InputStreamCache.ByteArrayCache defCacheSource
protected final InputStreamCache.ByteArrayCache cacheSource
protected final InputStream source
protected final ArrayList<byte[]> caches
protected byte[] cache
null if none.
protected int cachePtr
null, contains size of the last byte
array cache used.
protected boolean closed
protected boolean cacheOK
false if data do not fit into cache.
protected File cacheDir
null for no file caching.
protected File cacheFile
null if none).
protected OutputStream cacheFileOut
null if none).
protected ParamRunnable<Iterable<byte[]>> overflowHandler
null if none.
| Constructor Detail |
|---|
public InputStreamCache(InputStream source)
InputStreamCache that only uses in-memory caching.
source - - the source input stream to use.
public InputStreamCache(InputStream source,
boolean fileCache)
InputStreamCache. as cache directory, the directory from the system property
java.io.tmpdir is used.
source - - the source input stream to use.fileCache - - true if to use a file cache if necessary.
public InputStreamCache(InputStream source,
File cacheDir)
InputStreamCache.
source - - the source input stream to use.cacheDir - - the directory to store the cache temp file in.| Method Detail |
|---|
public int available()
throws IOException
available in class InputStreamIOException
public void close()
throws IOException
close in interface Closeableclose in class InputStreamIOException
public int read()
throws IOException
read in class InputStreamIOException
public int read(byte[] buffer)
throws IOException
read in class InputStreamIOException
public int read(byte[] buffer,
int off,
int len)
throws IOException
read in class InputStreamIOException
protected void write(byte[] data,
int off,
int len)
throws IOException
data - - the data byte array.off - - the data offset within the byte array.len - - the length of the data in bytes.
IOException - if problems occur while writing to the cache file.public void setOverflowHandler(ParamRunnable<Iterable<byte[]>> overflowHandler)
overflowHandler - - the overflow handler to run if a memory-only stream cache surpasses
its size limit.public void release()
public InputStream getData()
throws IOException,
IllegalStateException
InputStream for the data cached. this method may only be called after
calling close(). if the data was discarded because it didn't fit into the cache,
returns null.
InputStream for the data cached. if the data was discarded because it didn't
fit into the cache, returns null.
IOException - if an I/O error occurs when opening the cache file.
IllegalStateException - if called for a stream that is not closed.
protected void finalize()
throws Throwable
finalize in class ObjectThrowable
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||