Package com.norconex.commons.lang.io
Class CachedStreamFactory
java.lang.Object
com.norconex.commons.lang.io.CachedStreamFactory
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 -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final int -
Constructor Summary
ConstructorsConstructorDescriptionCreates 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
Modifier and TypeMethodDescriptionintintCreates an empty input stream.newInputStream(File file) newInputStream(String content) Creates a new input stream, assuming UTF-8 content.newInputStream(Path path) Creates a new cached input stream.
-
Field Details
-
DEFAULT_MAX_MEM_INSTANCE
public static final int DEFAULT_MAX_MEM_INSTANCE -
DEFAULT_MAX_MEM_POOL
public static final int DEFAULT_MAX_MEM_POOL
-
-
Constructor Details
-
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
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
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 Details
-
getMaxMemoryPool
public int getMaxMemoryPool() -
getMaxMemoryInstance
public int getMaxMemoryInstance() -
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
Creates a new input stream, assuming UTF-8 content.- Parameters:
content- content to stream- Returns:
- cached input stream
-
newInputStream
-
newInputStream
Creates a new cached input stream.- Parameters:
path- path where to cache large files- Returns:
- cached input stream
- Since:
- 2.0.0
-
newInputStream
-
newOuputStream
-
newOuputStream
-