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

public Class ResettableFileInputStream

extends FilterInputStream
Class Inheritance
Imports
java.io.FileInputStream, .FilterInputStream, .IOException, .InputStream, java.nio.channels.FileChannel

A wrapper around a FileInputStream that provides mark-and-reset capabilities.

This allows for retries on a FileInputStream.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
ResettableFileInputStream.AlreadyWrappedState

This is for streams that are already wrapped, i.e. WrappedFileInputStream.

private class
ResettableFileInputStream.NeedsToBeWrappedState

This is for FileInputStreams that are not already wrapped.

private static interface
ResettableFileInputStream.State

State interface for dealing with mark and reset.

Field Summary

Modifier and TypeField and Description
private final boolean
private static final Logger
private final ResettableFileInputStream.State
Inherited from java.io.FilterInputStream:
in

Constructor Summary

AccessConstructor and Description
public
ResettableFileInputStream(FileInputStream
file input stream to wrap
fis
)

Constructor for a file input stream that provides mark-and-reset capabilities.

Method Summary

Modifier and TypeMethod and Description
public static boolean

Returns:

true if it can be wrapped
canBeWrapped
(FileInputStream
the FileInputStream to check
fis
)

Return true if the provided FileInputStream can be wrapped to provide mark-and-reset capabilities.

public static boolean

Returns:

true if it is already wrapped
isAlreadyWrapped
(FileInputStream
the FileInputStream to check
fis
)

Return true if the provided FileInputStream has already been wrapped, and therefore supports mark-and-reset capabilities.

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

Overrides java.io.FilterInputStream.mark.

Marks the current position in this input stream.

public boolean
markSupported()

Overrides java.io.FilterInputStream.markSupported.

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

public synchronized void
reset()

Overrides java.io.FilterInputStream.reset.

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

Inherited from java.io.FilterInputStream:
availableclosereadreadreadskip

Field Detail

alreadyWrappedback to summary
private final boolean alreadyWrapped
LOGback to summary
private static final Logger LOG
stateback to summary
private final ResettableFileInputStream.State state

Constructor Detail

ResettableFileInputStreamback to summary
public ResettableFileInputStream(FileInputStream fis)

Constructor for a file input stream that provides mark-and-reset capabilities.

Parameters
fis:FileInputStream

file input stream to wrap

Exceptions
IllegalArgumentException:
if the file channel of the file input stream does not provide a position

Method Detail

canBeWrappedback to summary
public static boolean canBeWrapped(FileInputStream fis)

Return true if the provided FileInputStream can be wrapped to provide mark-and-reset capabilities.

Parameters
fis:FileInputStream

the FileInputStream to check

Returns:boolean

true if it can be wrapped

isAlreadyWrappedback to summary
public static boolean isAlreadyWrapped(FileInputStream fis)

Return true if the provided FileInputStream has already been wrapped, and therefore supports mark-and-reset capabilities.

Parameters
fis:FileInputStream

the FileInputStream to check

Returns:boolean

true if it is already wrapped

markback to summary
public synchronized void mark(int readlimit)

Overrides java.io.FilterInputStream.mark.

Doc from java.io.FilterInputStream.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 argument tells this input stream to allow that many bytes to be read before the mark position gets invalidated.

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.FilterInputStream.markSupported.

Doc from java.io.FilterInputStream.markSupported.

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

Returns:boolean

true if this stream type supports the mark and reset method; false otherwise.

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

Overrides java.io.FilterInputStream.reset.

Doc from java.io.FilterInputStream.reset.

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

Stream marks are intended to be used in situations where you need to read ahead a little to see what's in the stream. Often this is most easily done by invoking some general parser. If the stream is of the type handled by the parse, it just chugs along happily. If the stream is not of that type, the parser should toss an exception when it fails. If this happens within readlimit bytes, it allows the outer code to reset the stream and try another parser.

Annotations
@Override
Exceptions
IOException:
if this stream has not been marked or if the mark has been invalidated.
com.oracle.bmc.io.internal back to summary

private final Class ResettableFileInputStream.AlreadyWrappedState

extends Object
implements State
Class Inheritance
  • java.lang.Object
  • com.oracle.bmc.io.internal.ResettableFileInputStream.AlreadyWrappedState
All Implemented Interfaces
com.oracle.bmc.io.internal.ResettableFileInputStream.State

This is for streams that are already wrapped, i.e. WrappedFileInputStream.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public synchronized void
public synchronized void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

AlreadyWrappedStateback to summary
private AlreadyWrappedState()

Method Detail

markback to summary
public synchronized void mark(int readlimit)

Implements com.oracle.bmc.io.internal.ResettableFileInputStream.State.mark.

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

Implements com.oracle.bmc.io.internal.ResettableFileInputStream.State.reset.

Annotations
@Override
com.oracle.bmc.io.internal back to summary

private final Class ResettableFileInputStream.NeedsToBeWrappedState

extends Object
implements State
Class Inheritance
  • java.lang.Object
  • com.oracle.bmc.io.internal.ResettableFileInputStream.NeedsToBeWrappedState
All Implemented Interfaces
com.oracle.bmc.io.internal.ResettableFileInputStream.State

This is for FileInputStreams that are not already wrapped.

Field Summary

Modifier and TypeField and Description
private FileChannel
private long

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public synchronized void
public synchronized void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

fileChannelback to summary
private FileChannel fileChannel
markPositionback to summary
private long markPosition

Constructor Detail

NeedsToBeWrappedStateback to summary
public NeedsToBeWrappedState(FileChannel fileChannel)

Method Detail

markback to summary
public synchronized void mark(int readlimit)

Implements com.oracle.bmc.io.internal.ResettableFileInputStream.State.mark.

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

Implements com.oracle.bmc.io.internal.ResettableFileInputStream.State.reset.

Annotations
@Override
com.oracle.bmc.io.internal back to summary

private Interface ResettableFileInputStream.State

Known Direct Implementers
com.oracle.bmc.io.internal.ResettableFileInputStream.AlreadyWrappedState, com.oracle.bmc.io.internal.ResettableFileInputStream.NeedsToBeWrappedState

State interface for dealing with mark and reset.

Method Summary

Modifier and TypeMethod and Description
public void
mark(int readlimit)

public void

Method Detail

markback to summary
public void mark(int readlimit)
See Also
java.io.InputStream#mark(int)
resetback to summary
public void reset() throws IOException
See Also
InputStream#reset()