Top Description Fields Constructors Methods
com.oracle.bmc.io.internal

public Class WrappedFileInputStream

extends FileInputStream
implements DuplicatableInputStream
Class Inheritance
All Implemented Interfaces
com.oracle.bmc.http.client.io.DuplicatableInputStream
Imports
java.io.File, .FileInputStream, .FileNotFoundException, .IOException, .InputStream, com.oracle.bmc.http.client.io.DuplicatableInputStream

Simple wrapper over FileInputStream that also exposes the File used to create the stream.

This version also support mark/reset.

Field Summary

Modifier and TypeField and Description
private static final Logger
private long
private final File

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static WrappedFileInputStream

Returns:

a new stream.
create
(File
the file to read from.
file
)

Same as calling the ctor, except will throw an unchecked IllegalArgumentException if the file isn't found.

public InputStream
duplicate()

Implements com.oracle.bmc.http.client.io.DuplicatableInputStream.duplicate.

Produces a duplicate stream of the source (from its start) that can be used in parallel to the original stream (ie, thread safe).

public File
public synchronized void
mark(int
the maximum limit of bytes that can be read before the mark position becomes invalid.
readlimit
)

Overrides java.io.InputStream.mark.

Marks the current position in this input stream.

public boolean
markSupported()

Overrides java.io.InputStream.markSupported.

Tests if this input stream supports the mark and reset methods.

public synchronized void
reset()

Overrides java.io.InputStream.reset.

Repositions this stream to the position at the time the mark method was last called on this input stream.

Inherited from java.io.FileInputStream:
availableclosegetChannelgetFDreadreadreadreadAllBytesreadNBytesskiptransferTo

Field Detail

LOGback to summary
private static final Logger LOG
markPositionback to summary
private long markPosition
sourceFileback to summary
private final File sourceFile

Constructor Detail

WrappedFileInputStreamback to summary
public WrappedFileInputStream(File file) throws FileNotFoundException

Method Detail

createback to summary
public static WrappedFileInputStream create(File file)

Same as calling the ctor, except will throw an unchecked IllegalArgumentException if the file isn't found.

Parameters
file:File

the file to read from.

Returns:WrappedFileInputStream

a new stream.

duplicateback to summary
public InputStream duplicate()

Implements com.oracle.bmc.http.client.io.DuplicatableInputStream.duplicate.

Doc from com.oracle.bmc.http.client.io.DuplicatableInputStream.duplicate.

Produces a duplicate stream of the source (from its start) that can be used in parallel to the original stream (ie, thread safe).

Returns:InputStream

A new input stream instance.

Annotations
@Override
getSourceFileback to summary
public File getSourceFile()
markback to summary
public synchronized void mark(int readlimit)

Overrides java.io.InputStream.mark.

Doc from java.io.InputStream.mark.

Marks the current position in this input stream. A subsequent call to the reset method repositions this stream at the last marked position so that subsequent reads re-read the same bytes.

The readlimit arguments tells this input stream to allow that many bytes to be read before the mark position gets invalidated.

The general contract of mark is that, if the method markSupported returns true, the stream somehow remembers all the bytes read after the call to mark and stands ready to supply those same bytes again if and whenever the method reset is called. However, the stream is not required to remember any data at all if more than readlimit bytes are read from the stream before reset is called.

Marking a closed stream should not have any effect on the stream.

Parameters
readlimit:int

the maximum limit of bytes that can be read before the mark position becomes invalid.

Annotations
@Override
markSupportedback to summary
public boolean markSupported()

Overrides java.io.InputStream.markSupported.

Doc from java.io.InputStream.markSupported.

Tests if this input stream supports the mark and reset methods. Whether or not mark and reset are supported is an invariant property of a particular input stream instance.

Returns:boolean

true if this stream instance supports the mark and reset methods; false otherwise.

Annotations
@Override
resetback to summary
public synchronized void reset() throws IOException

Overrides java.io.InputStream.reset.

Doc from java.io.InputStream.reset.

Repositions this stream to the position at the time the mark method was last called on this input stream.

The general contract of reset is:

  • If the method markSupported returns true, then:
    • If the method mark has not been called since the stream was created, or the number of bytes read from the stream since mark was last called is larger than the argument to mark at that last call, then an IOException might be thrown.
    • If such an IOException is not thrown, then the stream is reset to a state such that all the bytes read since the most recent call to mark (or since the start of the file, if mark has not been called) will be resupplied to subsequent callers of the read method, followed by any bytes that otherwise would have been the next input data as of the time of the call to reset.
  • If the method markSupported returns false, then:
    • The call to reset may throw an IOException.
    • If an IOException is not thrown, then the stream is reset to a fixed state that depends on the particular type of the input stream and how it was created. The bytes that will be supplied to subsequent callers of the read method depend on the particular type of the input stream.
Annotations
@Override
Exceptions
IOException:
if this stream has not been marked or if the mark has been invalidated.