Package software.amazon.awssdk.core.io
Class ReleasableInputStream
java.lang.Object
java.io.InputStream
java.io.FilterInputStream
software.amazon.awssdk.core.io.SdkFilterInputStream
software.amazon.awssdk.core.io.ReleasableInputStream
- All Implemented Interfaces:
Closeable
,AutoCloseable
,Releasable
- Direct Known Subclasses:
ResettableInputStream
An input stream that can have the close operation disabled (to avoid
accidentally being closed). This is necessary, for example, when an input
stream needs to be marked-and-reset multiple times but only as long as the
input stream has not been closed. To survive not being accidentally closed,
the close method can be disabled via
disableClose()
.
The creator of this input stream should therefore always call
release()
in a finally block to truly release the underlying
resources.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionfinal void
close()
IfcloseDisabled
is false, closes this input stream and releases any system resources associated with the stream.final <T extends ReleasableInputStream>
TUsed to disable the close method.final boolean
Returns true if the close method has been disabled; false otherwise.final void
release()
Closes the underlying stream file and releases any system resources associated.static ReleasableInputStream
wrap
(InputStream is) Wraps the given input stream into aReleasableInputStream
if necessary.Methods inherited from class software.amazon.awssdk.core.io.SdkFilterInputStream
available, mark, markSupported, read, read, reset, skip
Methods inherited from class java.io.FilterInputStream
read
-
Method Details
-
wrap
Wraps the given input stream into aReleasableInputStream
if necessary. Note if the given input stream is aFileInputStream
, aResettableInputStream
which is a specific subclass ofReleasableInputStream
will be returned. -
close
public final void close()IfcloseDisabled
is false, closes this input stream and releases any system resources associated with the stream. Otherwise, this method does nothing.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classSdkFilterInputStream
-
release
public final void release()Closes the underlying stream file and releases any system resources associated.- Specified by:
release
in interfaceReleasable
- Overrides:
release
in classSdkFilterInputStream
-
isCloseDisabled
public final boolean isCloseDisabled()Returns true if the close method has been disabled; false otherwise. Once the close method is disabled, caller would be responsible to release resources viarelease()
. -
disableClose
Used to disable the close method. Once the close method is disabled, caller would be responsible to release resources viarelease()
.
-