|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
Helper class to work with cached streams.
A CachedStream should normally/allways be obtained through the CachedStreamFactory.
A cached stream is a stream that is cached in memory or some other place like in a file.They should basically be used when the same stream will be use (emptied) a multitude of times and it is important to do this without a lot of work.
Use it when you need to get data from an external source and reuse it.
CachedStreamFactory factory = CachedStreamFactory.newInstance();
CachedStream cache = factory.getCachedStream();
OutputStream os = cache.getOutputStream();
// Let external write to it
ftp.get("filename",os);
// Get a reusable input stream
CachedInputStream is = cache.getInputStream( os );
This is also possible when you get an InputStream.
InputStream is = url.openStream(); CachedInputStream cis = cache.getInputStream( is );
The getInputStream know if it gets a CachedInputStream and will return that, so in situations where stuff takes an InputStream which might already be a CachedInput stream, just use getInputStream. The helper method rewind will rewind the stream, if only if the stream is really rewindable: otherwise it will raise an exception.
CachedInputStreams are not possible to close through the normal close method because there are a lot of utilities out there that will close your stream for you under the hood. Use CachedInputStream.close(boolean) to really close the stream.
| Method Summary | |
CachedInputStream |
getInputStream(CachedOutputStream cout)
Get a rewindable input stream from the given CacheOutputStream. |
CachedInputStream |
getInputStream(java.io.InputStream is)
Get a rewindable inputstream from the given input stream, if the stream is a Rewindable input stream, it is just returned. |
CachedOutputStream |
getOutputStream()
Get a CachedOutputStream. |
java.lang.String |
getProperty(java.lang.String name)
Chech if property is set. |
void |
rewind(java.io.InputStream is)
Rewind this stream if it is rewindable, otherwise throw an IOException. |
void |
setProperty(java.lang.String name,
java.lang.String value)
Set a CacheStream specific property. |
| Method Detail |
public CachedOutputStream getOutputStream()
throws java.io.IOException
The typical usecase for this is to later use it to get a CachedInputStream from it.
java.io.IOException
public CachedInputStream getInputStream(CachedOutputStream cout)
throws java.io.IOException
java.io.IOException - if the CachedOutputStream is not of the correct type (not from the same cache) or if an underlying IOException happens.
public CachedInputStream getInputStream(java.io.InputStream is)
throws java.io.IOException
java.io.IOException
public void rewind(java.io.InputStream is)
throws java.io.IOException
java.io.IOException
public void setProperty(java.lang.String name,
java.lang.String value)
public java.lang.String getProperty(java.lang.String name)
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||