Package com.norconex.commons.lang.io
Class CachedOutputStream
java.lang.Object
java.io.OutputStream
com.norconex.commons.lang.io.CachedOutputStream
- All Implemented Interfaces:
ICachedStream,Closeable,Flushable,AutoCloseable
OutputStream wrapper that caches the output so it can be retrieved
once as a CachedInputStream. Invoking getInputStream()
effectively close() this stream and it can no longer be written
to. Obtaining an input stream before or instead of calling the close
method will not delete the cache content, but rather pass the reference
to it to the CachedInputStream.
To create new instances of
CachedOutputStream, use the
CachedStreamFactory class. Reusing the same factory
will ensure all CachedOutputStream instances created share the same
combined maximum memory. Invoking one of the
newOutputStream(...) methods on this class have the same effect.
The internal cache stores written bytes into memory, up to to the specified maximum cache size. If content exceeds the cache limit, the cache transforms itself into a file-based cache of unlimited size. Default memory cache size is 128 KB.
- Since:
- 1.5
- Author:
- Pascal Essiembre
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvoidclose()protected voidfinalize()final PathGets the cache directory where temporary cache files are created.longbooleanReturnstrueif was nothing to cache (no writing was performed) or if the stream was closed.voidwrite(byte[] b, int off, int len) voidwrite(int b) Methods inherited from class java.io.OutputStream
flush, nullOutputStream, write
-
Method Details
-
write
- Specified by:
writein classOutputStream- Throws:
IOException
-
write
- Overrides:
writein classOutputStream- Throws:
IOException
-
getInputStream
- Throws:
IOException
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classOutputStream- Throws:
IOException
-
getCacheDirectory
Gets the cache directory where temporary cache files are created.- Specified by:
getCacheDirectoryin interfaceICachedStream- Returns:
- the cache directory
-
getStreamFactory
-
isCacheEmpty
public boolean isCacheEmpty()Returnstrueif was nothing to cache (no writing was performed) or if the stream was closed.- Returns:
trueif empty
-
newOuputStream
-
newOuputStream
-
getMemCacheSize
public long getMemCacheSize()- Specified by:
getMemCacheSizein interfaceICachedStream
-
finalize
-