Package org.apache.hadoop.fs
Class FSInputStream
java.lang.Object
java.io.InputStream
org.apache.hadoop.fs.FSInputStream
- All Implemented Interfaces:
Closeable,AutoCloseable,PositionedReadable,Seekable
@Public
@Evolving
public abstract class FSInputStream
extends InputStream
implements Seekable, PositionedReadable
FSInputStream is a generic old InputStream with a little bit
of RAF-style seek ability.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract longgetPos()Return the current offset from the start of the fileintread(long position, byte[] buffer, int offset, int length) Read up to the specified number of bytes, from a given position within a file, and return the number of bytes read.voidreadFully(long position, byte[] buffer) Read number of bytes equal to the length of the buffer, from a given position within a file.voidreadFully(long position, byte[] buffer, int offset, int length) Read the specified number of bytes, from a given position within a file.abstract voidseek(long pos) Seek to the given offset from the start of the file.abstract booleanseekToNewSource(long targetPos) Seeks a different copy of the data.toString()toString method returns the superclass toString, but if the subclass implementsIOStatisticsSourcethen those statistics are extracted and included in the output.protected voidvalidatePositionedReadArgs(long position, byte[] buffer, int offset, int length) Validation code, available for use in subclasses.Methods inherited from class java.io.InputStream
available, close, mark, markSupported, nullInputStream, read, read, read, readAllBytes, readNBytes, readNBytes, reset, skip, skipNBytes, transferToMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.hadoop.fs.PositionedReadable
maxReadSizeForVectorReads, minSeekForVectorReads, readVectored, readVectored
-
Constructor Details
-
FSInputStream
public FSInputStream()
-
-
Method Details
-
seek
Seek to the given offset from the start of the file. The next read() will be from that location. Can't seek past the end of the file.- Specified by:
seekin interfaceSeekable- Parameters:
pos- offset from the start of the file.- Throws:
IOException- raised on errors performing I/O.
-
getPos
Return the current offset from the start of the file- Specified by:
getPosin interfaceSeekable- Returns:
- offset from the start of the file.
- Throws:
IOException- raised on errors performing I/O.
-
seekToNewSource
Seeks a different copy of the data. Returns true if found a new source, false otherwise.- Specified by:
seekToNewSourcein interfaceSeekable- Parameters:
targetPos- target position.- Returns:
- true if found a new source, false otherwise.
- Throws:
IOException- raised on errors performing I/O.
-
read
Description copied from interface:PositionedReadableRead up to the specified number of bytes, from a given position within a file, and return the number of bytes read. This does not change the current offset of a file, and is thread-safe. Warning: Not all filesystems satisfy the thread-safety requirement.- Specified by:
readin interfacePositionedReadable- Parameters:
position- position within filebuffer- destination bufferoffset- offset in the bufferlength- number of bytes to read- Returns:
- actual number of bytes read; -1 means "none"
- Throws:
IOException- IO problems.
-
validatePositionedReadArgs
protected void validatePositionedReadArgs(long position, byte[] buffer, int offset, int length) throws EOFException Validation code, available for use in subclasses.- Parameters:
position- position: if negative an EOF exception is raisedbuffer- destination bufferoffset- offset within the bufferlength- length of bytes to read- Throws:
EOFException- if the position is negativeIndexOutOfBoundsException- if there isn't space for the amount of data requested.IllegalArgumentException- other arguments are invalid.
-
readFully
Description copied from interface:PositionedReadableRead the specified number of bytes, from a given position within a file. This does not change the current offset of a file, and is thread-safe. Warning: Not all filesystems satisfy the thread-safety requirement.- Specified by:
readFullyin interfacePositionedReadable- Parameters:
position- position within filebuffer- destination bufferoffset- offset in the bufferlength- number of bytes to read- Throws:
IOException- IO problems.EOFException- the end of the data was reached before the read operation completed
-
readFully
Description copied from interface:PositionedReadableRead number of bytes equal to the length of the buffer, from a given position within a file. This does not change the current offset of a file, and is thread-safe. Warning: Not all filesystems satisfy the thread-safety requirement.- Specified by:
readFullyin interfacePositionedReadable- Parameters:
position- position within filebuffer- destination buffer- Throws:
IOException- IO problems.EOFException- the end of the data was reached before the read operation completed
-
toString
toString method returns the superclass toString, but if the subclass implementsIOStatisticsSourcethen those statistics are extracted and included in the output. That is: statistics of subclasses are automatically reported.
-