Class ResettableInputStream
- java.lang.Object
-
- java.io.InputStream
-
- java.io.FilterInputStream
-
- software.amazon.awssdk.core.io.SdkFilterInputStream
-
- software.amazon.awssdk.core.io.ReleasableInputStream
-
- software.amazon.awssdk.core.io.ResettableInputStream
-
- All Implemented Interfaces:
Closeable,AutoCloseable,Releasable
@NotThreadSafe public class ResettableInputStream extends ReleasableInputStream
A mark-and-resettable input stream that can be used on files or file input streams. In particular, aResettableInputStreamallows the close operation to be disabled viaReleasableInputStream.disableClose()(to avoid accidentally being closed). This is necessary when such input stream needs to be marked-and-reset multiple times but only as long as the stream has not been closed.The creator of this input stream should therefore always call
ReleasableInputStream.release()in a finally block to truly release the underlying resources.- See Also:
ReleasableInputStream
-
-
Field Summary
-
Fields inherited from class java.io.FilterInputStream
in
-
-
Constructor Summary
Constructors Constructor Description ResettableInputStream(File file)ResettableInputStream(FileInputStream fis)Note the creation of aResettableInputStreamwould entail physically opening a file.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intavailable()FilegetFile()Returns the underlying file, if known; or null if not;voidmark(int ignored)Marks the current position in this input stream.booleanmarkSupported()static ResettableInputStreamnewResettableInputStream(File file)Convenient factory method to construct a new resettable input stream for the given file, converting any IOException into SdkClientException.static ResettableInputStreamnewResettableInputStream(FileInputStream fis)Convenient factory method to construct a new resettable input stream for the given file input stream, converting any IOException into SdkClientException.static ResettableInputStreamnewResettableInputStream(FileInputStream fis, String errmsg)Convenient factory method to construct a new resettable input stream for the given file input stream, converting any IOException into SdkClientException with the given error message.static ResettableInputStreamnewResettableInputStream(File file, String errmsg)Convenient factory method to construct a new resettable input stream for the given file, converting any IOException into SdkClientException with the given error message.intread()intread(byte[] arg0, int arg1, int arg2)voidreset()Repositions this stream to the position at the time themarkmethod was last called on this input stream.longskip(long n)-
Methods inherited from class software.amazon.awssdk.core.io.ReleasableInputStream
close, disableClose, isCloseDisabled, release, wrap
-
Methods inherited from class software.amazon.awssdk.core.io.SdkFilterInputStream
abort, abortIfNeeded
-
Methods inherited from class java.io.FilterInputStream
read
-
-
-
-
Constructor Detail
-
ResettableInputStream
public ResettableInputStream(File file) throws IOException
- Parameters:
file- must not be null. Upon successful construction the the file will be opened with an input stream automatically marked at the starting position of the given file.Note the creation of a
ResettableInputStreamwould entail physically opening a file. If the opened file is meant to be closed only (in a finally block) by the very same code block that created it, then it is necessary that the release method must not be called while the execution is made in other stack frames. In such case, as other stack frames may inadvertently or indirectly call the close method of the stream, the creator of the stream would need to explicitly disable the accidental closing viaReleasableInputStream.disableClose(), so that the release method becomes the only way to truly close the opened file.- Throws:
IOException
-
ResettableInputStream
public ResettableInputStream(FileInputStream fis) throws IOException
Note the creation of a
ResettableInputStreamwould entail physically opening a file. If the opened file is meant to be closed only (in a finally block) by the very same code block that created it, then it is necessary that the release method must not be called while the execution is made in other stack frames. In such case, as other stack frames may inadvertently or indirectly call the close method of the stream, the creator of the stream would need to explicitly disable the accidental closing viaReleasableInputStream.disableClose(), so that the release method becomes the only way to truly close the opened file.- Parameters:
fis- file input stream; must not be null. Upon successful construction the input stream will be automatically marked at the current position of the given file input stream.- Throws:
IOException
-
-
Method Detail
-
newResettableInputStream
public static ResettableInputStream newResettableInputStream(File file)
Convenient factory method to construct a new resettable input stream for the given file, converting any IOException into SdkClientException.Note the creation of a
ResettableInputStreamwould entail physically opening a file. If the opened file is meant to be closed only (in a finally block) by the very same code block that created it, then it is necessary that the release method must not be called while the execution is made in other stack frames. In such case, as other stack frames may inadvertently or indirectly call the close method of the stream, the creator of the stream would need to explicitly disable the accidental closing viaReleasableInputStream.disableClose(), so that the release method becomes the only way to truly close the opened file.
-
newResettableInputStream
public static ResettableInputStream newResettableInputStream(File file, String errmsg)
Convenient factory method to construct a new resettable input stream for the given file, converting any IOException into SdkClientException with the given error message.Note the creation of a
ResettableInputStreamwould entail physically opening a file. If the opened file is meant to be closed only (in a finally block) by the very same code block that created it, then it is necessary that the release method must not be called while the execution is made in other stack frames. In such case, as other stack frames may inadvertently or indirectly call the close method of the stream, the creator of the stream would need to explicitly disable the accidental closing viaReleasableInputStream.disableClose(), so that the release method becomes the only way to truly close the opened file.
-
newResettableInputStream
public static ResettableInputStream newResettableInputStream(FileInputStream fis)
Convenient factory method to construct a new resettable input stream for the given file input stream, converting any IOException into SdkClientException.Note the creation of a
ResettableInputStreamwould entail physically opening a file. If the opened file is meant to be closed only (in a finally block) by the very same code block that created it, then it is necessary that the release method must not be called while the execution is made in other stack frames. In such case, as other stack frames may inadvertently or indirectly call the close method of the stream, the creator of the stream would need to explicitly disable the accidental closing viaReleasableInputStream.disableClose(), so that the release method becomes the only way to truly close the opened file.
-
newResettableInputStream
public static ResettableInputStream newResettableInputStream(FileInputStream fis, String errmsg)
Convenient factory method to construct a new resettable input stream for the given file input stream, converting any IOException into SdkClientException with the given error message.Note the creation of a
ResettableInputStreamwould entail physically opening a file. If the opened file is meant to be closed only (in a finally block) by the very same code block that created it, then it is necessary that the release method must not be called while the execution is made in other stack frames. In such case, as other stack frames may inadvertently or indirectly call the close method of the stream, the creator of the stream would need to explicitly disable the accidental closing viaReleasableInputStream.disableClose(), so that the release method becomes the only way to truly close the opened file.
-
markSupported
public final boolean markSupported()
- Overrides:
markSupportedin classSdkFilterInputStream
-
mark
public void mark(int ignored)
Marks the current position in this input stream. A subsequent call to theresetmethod repositions this stream at the last marked position so that subsequent reads re-read the same bytes. This method works as long as the underlying file has not been closed.Note the creation of a
ResettableInputStreamwould entail physically opening a file. If the opened file is meant to be closed only (in a finally block) by the very same code block that created it, then it is necessary that the release method must not be called while the execution is made in other stack frames. In such case, as other stack frames may inadvertently or indirectly call the close method of the stream, the creator of the stream would need to explicitly disable the accidental closing viaReleasableInputStream.disableClose(), so that the release method becomes the only way to truly close the opened file.- Overrides:
markin classSdkFilterInputStream- Parameters:
ignored- ignored
-
reset
public void reset() throws IOExceptionRepositions this stream to the position at the time themarkmethod was last called on this input stream. This method works as long as the underlying file has not been closed.Note the creation of a
ResettableInputStreamwould entail physically opening a file. If the opened file is meant to be closed only (in a finally block) by the very same code block that created it, then it is necessary that the release method must not be called while the execution is made in other stack frames. In such case, as other stack frames may inadvertently or indirectly call the close method of the stream, the creator of the stream would need to explicitly disable the accidental closing viaReleasableInputStream.disableClose(), so that the release method becomes the only way to truly close the opened file.- Overrides:
resetin classSdkFilterInputStream- Throws:
IOException
-
available
public int available() throws IOException- Overrides:
availablein classSdkFilterInputStream- Throws:
IOException
-
read
public int read() throws IOException- Overrides:
readin classSdkFilterInputStream- Throws:
IOException
-
skip
public long skip(long n) throws IOException- Overrides:
skipin classSdkFilterInputStream- Throws:
IOException
-
read
public int read(byte[] arg0, int arg1, int arg2) throws IOException- Overrides:
readin classSdkFilterInputStream- Throws:
IOException
-
getFile
public File getFile()
Returns the underlying file, if known; or null if not;
-
-