Package de.aristaflow.adept2.util.io
Class BufferedRereadableContent
- java.lang.Object
-
- de.aristaflow.adept2.util.io.BufferedRereadableContent
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
@Deprecated(since="15.0.0", forRemoval=true) public class BufferedRereadableContent extends Object implements Closeable
Deprecated, for removal: This API element is subject to removal in a future version.UseRereadableContent
instead.TheBufferedRereadableContent
can be used when the content of anInputStream
needs to be processed multiple times. Depending on its eventual size the whole content of the input stream is buffered in-memory - up to a certain threshold - or in a temporary file.The
BufferedRereadableContent
as well as the provided input streams must beclosed
after use! This can be ensured by adhering to the following template:try (BufferedRereadableContent input = new BufferedRereadableContent(inputStream)) { ... try (InputStream is = input.getInputStream()) { ... } ... try (InputStream is = input.getInputStream()) { ... } ... }
BufferedRereadableContent
will also close the underlyingInputStream
(unless it has already been read and closed in the constructor). Also created streams that have not been closed will also be closed.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
BufferedRereadableContent.BrcCleanup
Deprecated, for removal: This API element is subject to removal in a future version.The clean-up task deleting the temporary file if appropriate
-
Field Summary
Fields Modifier and Type Field Description protected Cleanup<RuntimeException>
cleanup
Deprecated, for removal: This API element is subject to removal in a future version.The clean-up for closing thecreatedStreams
and the temporary file.protected Collection<Closeable>
createdStreams
Deprecated, for removal: This API element is subject to removal in a future version.All streams that have been created by thisBufferedRereadableContent
.protected static int
DEFAULT_THRESHOLD
Deprecated, for removal: This API element is subject to removal in a future version.protected long
length
Deprecated, for removal: This API element is subject to removal in a future version.The size of the content.protected Logger
logger
Deprecated, for removal: This API element is subject to removal in a future version.The logger for problems with the handling of the created input streams.protected static DateTimeFormatter
TIMESTAMP_FORMATTER
Deprecated, for removal: This API element is subject to removal in a future version.
-
Constructor Summary
Constructors Constructor Description BufferedRereadableContent(InputStream inputStream)
Deprecated, for removal: This API element is subject to removal in a future version.Creates a newBufferedRereadableContent
and immediately reads the givenInputStream
.BufferedRereadableContent(InputStream inputStream, int threshold, String tempFileTag, File tempDir)
Deprecated, for removal: This API element is subject to removal in a future version.Creates a newBufferedRereadableContent
and immediately reads the givenInputStream
.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
close()
Deprecated, for removal: This API element is subject to removal in a future version.Releases all resources and deletes the temporary file if one has been created.InputStream
getInputStream()
Deprecated, for removal: This API element is subject to removal in a future version.Returns an input stream for the data.long
getLength()
Deprecated, for removal: This API element is subject to removal in a future version.Returns the total length of the content.
-
-
-
Field Detail
-
DEFAULT_THRESHOLD
protected static final int DEFAULT_THRESHOLD
Deprecated, for removal: This API element is subject to removal in a future version.- See Also:
- Constant Field Values
-
TIMESTAMP_FORMATTER
protected static final DateTimeFormatter TIMESTAMP_FORMATTER
Deprecated, for removal: This API element is subject to removal in a future version.
-
logger
protected final Logger logger
Deprecated, for removal: This API element is subject to removal in a future version.The logger for problems with the handling of the created input streams.
-
length
protected final long length
Deprecated, for removal: This API element is subject to removal in a future version.The size of the content.
-
createdStreams
protected final Collection<Closeable> createdStreams
Deprecated, for removal: This API element is subject to removal in a future version.All streams that have been created by thisBufferedRereadableContent
.
-
cleanup
protected final Cleanup<RuntimeException> cleanup
Deprecated, for removal: This API element is subject to removal in a future version.The clean-up for closing thecreatedStreams
and the temporary file.
-
-
Constructor Detail
-
BufferedRereadableContent
public BufferedRereadableContent(InputStream inputStream) throws IOException
Deprecated, for removal: This API element is subject to removal in a future version.Creates a newBufferedRereadableContent
and immediately reads the givenInputStream
.- Parameters:
inputStream
- The input stream to read. This will be closed when its content has been read. If it is already re-readable,it will be closed when closing thisBufferedRereadableContent
.- Throws:
IOException
- if an I/O error occurs
-
BufferedRereadableContent
public BufferedRereadableContent(InputStream inputStream, int threshold, String tempFileTag, File tempDir) throws IOException
Deprecated, for removal: This API element is subject to removal in a future version.Creates a newBufferedRereadableContent
and immediately reads the givenInputStream
.- Parameters:
inputStream
- The input stream to read. This will be closed when its content has been read. If it is already re-readable,it will be closed when closing thisBufferedRereadableContent
.threshold
- the number of bytes after which to store the content in a file instead; negative values will result in thedefault threshold
tempFileTag
- an optional tag that will be incorporated into the name of the temp file if one is created; may be nulltempDir
- the directory where temp files should be created; may be null to use the default temp directory of the JVM; will be created if it doesn't exist- Throws:
IOException
- if an I/O error occurs
-
-
Method Detail
-
getLength
public long getLength()
Deprecated, for removal: This API element is subject to removal in a future version.Returns the total length of the content.- Returns:
- the total length of the content
-
getInputStream
public InputStream getInputStream() throws IOException
Deprecated, for removal: This API element is subject to removal in a future version.Returns an input stream for the data. This method may be called multiple times. The returned stream must be closed properly after use!- Returns:
- an input stream for the data
- Throws:
IOException
- if an I/O error occurs
-
close
public void close()
Deprecated, for removal: This API element is subject to removal in a future version.Releases all resources and deletes the temporary file if one has been created.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
-