@InterfaceAudience.Public @InterfaceStability.Stable public class FSDataInputStream extends DataInputStream implements Seekable, PositionedReadable, org.apache.hadoop.fs.ByteBufferReadable, org.apache.hadoop.fs.HasFileDescriptor, CanSetDropBehind, CanSetReadahead, org.apache.hadoop.fs.HasEnhancedByteBufferAccess, CanUnbuffer
FSInputStream in a DataInputStream
and buffers input through a BufferedInputStream.in| Constructor and Description |
|---|
FSDataInputStream(InputStream in) |
| Modifier and Type | Method and Description |
|---|---|
FileDescriptor |
getFileDescriptor() |
long |
getPos()
Get the current position in the input stream.
|
int |
read(ByteBuffer buf)
Reads up to buf.remaining() bytes into buf.
|
ByteBuffer |
read(ByteBufferPool bufferPool,
int maxLength) |
ByteBuffer |
read(ByteBufferPool bufferPool,
int maxLength,
EnumSet<ReadOption> opts)
Get a ByteBuffer containing file data.
|
int |
read(long position,
byte[] buffer,
int offset,
int length)
Read bytes from the given position in the stream to the given buffer.
|
void |
readFully(long position,
byte[] buffer)
|
void |
readFully(long position,
byte[] buffer,
int offset,
int length)
Read bytes from the given position in the stream to the given buffer.
|
void |
releaseBuffer(ByteBuffer buffer)
Release a ByteBuffer which was created by the enhanced ByteBuffer read
function.
|
void |
seek(long desired)
Seek to the given offset.
|
boolean |
seekToNewSource(long targetPos)
Seek to the given position on an alternate copy of the data.
|
void |
setDropBehind(Boolean dropBehind)
Configure whether the stream should drop the cache.
|
void |
setReadahead(Long readahead)
Set the readahead on this stream.
|
void |
unbuffer()
Reduce the buffering.
|
read, read, readBoolean, readByte, readChar, readDouble, readFloat, readFully, readFully, readInt, readLine, readLong, readShort, readUnsignedByte, readUnsignedShort, readUTF, readUTF, skipBytesavailable, close, mark, markSupported, read, reset, skippublic FSDataInputStream(InputStream in)
public void seek(long desired) throws IOException
seek in interface Seekabledesired - offset to seek toIOExceptionpublic long getPos() throws IOException
getPos in interface SeekableIOExceptionpublic int read(long position, byte[] buffer, int offset, int length) throws IOException
read in interface PositionedReadableposition - position in the input stream to seekbuffer - buffer into which data is readoffset - offset into the buffer in which data is writtenlength - maximum number of bytes to read-1
if there is no more data because the end of the stream has been
reachedIOExceptionpublic void readFully(long position, byte[] buffer, int offset, int length) throws IOException
length bytes have been read.readFully in interface PositionedReadableposition - position in the input stream to seekbuffer - buffer into which data is readoffset - offset into the buffer in which data is writtenlength - the number of bytes to readEOFException - If the end of stream is reached while reading.
If an exception is thrown an undetermined number
of bytes in the buffer may have been written.IOExceptionpublic void readFully(long position, byte[] buffer) throws IOException
readFully in interface PositionedReadableIOExceptionpublic boolean seekToNewSource(long targetPos) throws IOException
targetPos - position to seek toIOExceptionpublic int read(ByteBuffer buf) throws IOException
org.apache.hadoop.fs.ByteBufferReadableUnsupportedOperationException, so
callers that are not confident in support for this method from the
underlying filesystem should be prepared to handle that exception.
Implementations should treat 0-length requests as legitimate, and must not
signal an error upon their receipt.read in interface org.apache.hadoop.fs.ByteBufferReadablebuf - the ByteBuffer to receive the results of the read operation.IOException - if there is some error performing the readpublic FileDescriptor getFileDescriptor() throws IOException
getFileDescriptor in interface org.apache.hadoop.fs.HasFileDescriptorIOExceptionpublic void setReadahead(Long readahead) throws IOException, UnsupportedOperationException
CanSetReadaheadsetReadahead in interface CanSetReadaheadreadahead - The readahead to use. null means to use the default.IOException - If there was an error changing the dropBehind
setting.
UnsupportedOperationException If this stream doesn't support
setting readahead.UnsupportedOperationExceptionpublic void setDropBehind(Boolean dropBehind) throws IOException, UnsupportedOperationException
CanSetDropBehindsetDropBehind in interface CanSetDropBehinddropBehind - Whether to drop the cache. null means to use the
default value.IOException - If there was an error changing the dropBehind
setting.
UnsupportedOperationException If this stream doesn't support
setting the drop-behind.UnsupportedOperationExceptionpublic ByteBuffer read(ByteBufferPool bufferPool, int maxLength, EnumSet<ReadOption> opts) throws IOException, UnsupportedOperationException
org.apache.hadoop.fs.HasEnhancedByteBufferAccessread in interface org.apache.hadoop.fs.HasEnhancedByteBufferAccessbufferPool - If this is non-null, it will be used to create a fallback
ByteBuffer when the stream itself cannot create one.maxLength - The maximum length of buffer to return. We may return a buffer
which is shorter than this.opts - Options to use when reading.IOExceptionUnsupportedOperationExceptionpublic final ByteBuffer read(ByteBufferPool bufferPool, int maxLength) throws IOException, UnsupportedOperationException
public void releaseBuffer(ByteBuffer buffer)
org.apache.hadoop.fs.HasEnhancedByteBufferAccessreleaseBuffer in interface org.apache.hadoop.fs.HasEnhancedByteBufferAccessbuffer - The ByteBuffer to release.public void unbuffer()
CanUnbufferunbuffer in interface CanUnbufferCopyright © 2018 Apache Software Foundation. All rights reserved.