Package com.norconex.commons.lang.io
Class CachedStreamFactory
- java.lang.Object
-
- com.norconex.commons.lang.io.CachedStreamFactory
-
public class CachedStreamFactory extends Object
Factory for input/output streams caching values for repeat usage.
When using a constructor without all arguments, default values are used. System properties are first checked for such values under these keys:
cachedstream.mem.pool: Pool max memory.cachedstream.mem.instance: Instances max memory.cachedstream.dir: Cache directory.
The following are default initialization values when not supplied via constructor arguments or System properties:
- Pool max memory: 1 GB
- Instances max memory: : 100 MB
- Cache directory: Uses the system temporary directory.
Initialization values passed in constructor always take precedence.
- Author:
- Pascal Essiembre
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classCachedStreamFactory.MemoryTracker
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_MAX_MEM_INSTANCEstatic intDEFAULT_MAX_MEM_POOL
-
Constructor Summary
Constructors Constructor Description CachedStreamFactory()Creates a new instance with default values (see class documentation)CachedStreamFactory(int maxMemoryPool, int maxMemoryInstance)Constructor.CachedStreamFactory(int maxMemoryPool, int maxMemoryInstance, Path cacheDirectory)Constructor.CachedStreamFactory(Path cacheDirectory)Creates a new instance with default memory values (see class documentation).
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intgetMaxMemoryInstance()intgetMaxMemoryPool()CachedInputStreamnewInputStream()Creates an empty input stream.CachedInputStreamnewInputStream(File file)CachedInputStreamnewInputStream(InputStream is)CachedInputStreamnewInputStream(String content)Creates a new input stream, assuming UTF-8 content.CachedInputStreamnewInputStream(Path path)Creates a new cached input stream.CachedOutputStreamnewOuputStream()CachedOutputStreamnewOuputStream(OutputStream os)
-
-
-
Constructor Detail
-
CachedStreamFactory
public CachedStreamFactory(int maxMemoryPool, int maxMemoryInstance)Constructor.- Parameters:
maxMemoryPool- maximum number of bytes used for memory caching by all instances created by this factory combinedmaxMemoryInstance- maximum number of bytes used for memory by each cached stream instance created
-
CachedStreamFactory
public CachedStreamFactory(int maxMemoryPool, int maxMemoryInstance, Path cacheDirectory)Constructor.- Parameters:
maxMemoryPool- maximum number of bytes used for memory caching by all instances created by this factory combinedmaxMemoryInstance- maximum number of bytes used for memory by each cached stream instance createdcacheDirectory- location where file-based caching takes place- Since:
- 2.0.0
-
CachedStreamFactory
public CachedStreamFactory(Path cacheDirectory)
Creates a new instance with default memory values (see class documentation).- Parameters:
cacheDirectory- location where file-based caching takes place- Since:
- 2.0.0
-
CachedStreamFactory
public CachedStreamFactory()
Creates a new instance with default values (see class documentation)- Since:
- 2.0.0
-
-
Method Detail
-
getMaxMemoryPool
public int getMaxMemoryPool()
-
getMaxMemoryInstance
public int getMaxMemoryInstance()
-
newInputStream
public CachedInputStream newInputStream()
Creates an empty input stream. Useful when you need an input stream but null is not accepted.- Returns:
- an empty cached input stream
-
newInputStream
public CachedInputStream newInputStream(String content)
Creates a new input stream, assuming UTF-8 content.- Parameters:
content- content to stream- Returns:
- cached input stream
-
newInputStream
public CachedInputStream newInputStream(File file)
-
newInputStream
public CachedInputStream newInputStream(Path path)
Creates a new cached input stream.- Parameters:
path- path where to cache large files- Returns:
- cached input stream
- Since:
- 2.0.0
-
newInputStream
public CachedInputStream newInputStream(InputStream is)
-
newOuputStream
public CachedOutputStream newOuputStream(OutputStream os)
-
newOuputStream
public CachedOutputStream newOuputStream()
-
-