Class BufferedFSInputStream
- All Implemented Interfaces:
Closeable,AutoCloseable,HasFileDescriptor,PositionedReadable,Seekable,IOStatisticsSource,StreamCapabilities
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.hadoop.fs.StreamCapabilities
StreamCapabilities.StreamCapability -
Field Summary
Fields inherited from class java.io.FilterInputStream
inFields inherited from interface org.apache.hadoop.fs.StreamCapabilities
ABORTABLE_STREAM, DROPBEHIND, HFLUSH, HSYNC, IOSTATISTICS, IOSTATISTICS_CONTEXT, PREADBYTEBUFFER, READAHEAD, READBYTEBUFFER, UNBUFFER, VECTOREDIO, VECTOREDIO_BUFFERS_SLICED -
Constructor Summary
ConstructorsConstructorDescriptionBufferedFSInputStream(FSInputStream in, int size) Creates aBufferedFSInputStreamwith the specified buffer size, and saves its argument, the input streamin, for later use. -
Method Summary
Modifier and TypeMethodDescriptionReturn a statistics instance.longgetPos()Return the current offset from the start of the filebooleanhasCapability(String capability) If the inner stream supportsStreamCapabilities, forward the probe to it.intWhat is the largest size that we should group ranges together as?intWhat is the smallest reasonable seek?intread(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.voidreadVectored(List<? extends FileRange> ranges, IntFunction<ByteBuffer> allocate) Read fully a list of file ranges asynchronously from this file.voidreadVectored(List<? extends FileRange> ranges, IntFunction<ByteBuffer> allocate, Consumer<ByteBuffer> release) Extension ofPositionedReadable.readVectored(List, IntFunction)where arelease(buffer)operation may be invoked if problems surface during reads.voidseek(long pos) Seek to the given offset from the start of the file.booleanseekToNewSource(long targetPos) Seeks a different copy of the data.longskip(long n) toString()Methods inherited from class java.io.BufferedInputStream
available, close, mark, markSupported, read, read, resetMethods inherited from class java.io.FilterInputStream
readMethods inherited from class java.io.InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo
-
Constructor Details
-
BufferedFSInputStream
Creates aBufferedFSInputStreamwith the specified buffer size, and saves its argument, the input streamin, for later use. An internal buffer array of lengthsizeis created and stored inbuf.- Parameters:
in- the underlying input stream.size- the buffer size.- Throws:
IllegalArgumentException- if size <= 0.
-
-
Method Details
-
getPos
Description copied from interface:SeekableReturn 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.
-
skip
- Overrides:
skipin classBufferedInputStream- Throws:
IOException
-
seek
Description copied from interface:SeekableSeek 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.
-
seekToNewSource
Description copied from interface:SeekableSeeks 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.
-
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
-
getFileDescriptor
- Specified by:
getFileDescriptorin interfaceHasFileDescriptor- Returns:
- the FileDescriptor
- Throws:
IOException- raised on errors performing I/O.
-
hasCapability
If the inner stream supportsStreamCapabilities, forward the probe to it. Otherwise: return false.- Specified by:
hasCapabilityin interfaceStreamCapabilities- Parameters:
capability- string to query the stream support for.- Returns:
- true if a capability is known to be supported.
-
getIOStatistics
Description copied from interface:IOStatisticsSourceReturn a statistics instance.It is not a requirement that the same instance is returned every time.
IOStatisticsSource.If the object implementing this is Closeable, this method may return null if invoked on a closed object, even if it returns a valid instance when called earlier.
- Specified by:
getIOStatisticsin interfaceIOStatisticsSource- Returns:
- an IOStatistics instance or null
-
toString
-
minSeekForVectorReads
public int minSeekForVectorReads()Description copied from interface:PositionedReadableWhat is the smallest reasonable seek?- Specified by:
minSeekForVectorReadsin interfacePositionedReadable- Returns:
- the minimum number of bytes
-
maxReadSizeForVectorReads
public int maxReadSizeForVectorReads()Description copied from interface:PositionedReadableWhat is the largest size that we should group ranges together as?- Specified by:
maxReadSizeForVectorReadsin interfacePositionedReadable- Returns:
- the number of bytes to read at once
-
readVectored
public void readVectored(List<? extends FileRange> ranges, IntFunction<ByteBuffer> allocate) throws IOException Description copied from interface:PositionedReadableRead fully a list of file ranges asynchronously from this file. The default iterates through the ranges to read each synchronously, but the intent is that FSDataInputStream subclasses can make more efficient readers. As a result of the call, each range will have FileRange.setData(CompletableFuture) called with a future that when complete will have a ByteBuffer with the data from the file's range.The position returned by getPos() after readVectored() is undefined.
If a file is changed while the readVectored() operation is in progress, the output is undefined. Some ranges may have old data, some may have new and some may have both.
While a readVectored() operation is in progress, normal read api calls may block.
- Specified by:
readVectoredin interfacePositionedReadable- Parameters:
ranges- the byte ranges to readallocate- the function to allocate ByteBuffer- Throws:
IOException- any IOE.
-
readVectored
public void readVectored(List<? extends FileRange> ranges, IntFunction<ByteBuffer> allocate, Consumer<ByteBuffer> release) throws IOException Description copied from interface:PositionedReadableExtension ofPositionedReadable.readVectored(List, IntFunction)where arelease(buffer)operation may be invoked if problems surface during reads.The
releaseoperation is invoked after an IOException to return the actively buffer to a pool before reporting a failure in the future.The default implementation calls
PositionedReadable.readVectored(List, IntFunction).pImplementations SHOULD override this method if they can release buffers as part of their error handling.
- Specified by:
readVectoredin interfacePositionedReadable- Parameters:
ranges- the byte ranges to readallocate- function to allocate ByteBufferrelease- callable to release a ByteBuffer.- Throws:
IOException- any IOE.
-