java.io.Closeable, java.io.DataInput, java.lang.AutoCloseable, ByteBufferPositionedReadable, ByteBufferReadable, CanSetDropBehind, CanSetReadahead, CanUnbuffer, HasEnhancedByteBufferAccess, HasFileDescriptor, PositionedReadable, Seekable, IOStatisticsSource, StreamCapabilitiesCryptoFSDataInputStream@Public @Stable public class FSDataInputStream extends java.io.DataInputStream implements Seekable, PositionedReadable, ByteBufferReadable, HasFileDescriptor, CanSetDropBehind, CanSetReadahead, HasEnhancedByteBufferAccess, CanUnbuffer, StreamCapabilities, ByteBufferPositionedReadable, IOStatisticsSource
FSInputStream in a DataInputStream
and buffers input through a BufferedInputStream.| Modifier and Type | Class | Description |
|---|---|---|
static class |
FSDataInputStream.FadviseType |
Type of file advise to be passed on to the underlying file system.
|
StreamCapabilities.StreamCapabilityABORTABLE_STREAM, DROPBEHIND, HFLUSH, HSYNC, IOSTATISTICS, IOSTATISTICS_CONTEXT, PREADBYTEBUFFER, READAHEAD, READBYTEBUFFER, UNBUFFER, VECTOREDIO| Constructor | Description |
|---|---|
FSDataInputStream(java.io.InputStream in) |
| Modifier and Type | Method | Description |
|---|---|---|
void |
adviseFile(FSDataInputStream.FadviseType type,
long offset,
long count) |
Specifies the kind of advise to provide for this stream and the file
offsets to which they apply.
|
long |
getChunkSize() |
Returns the file chunk size.
|
long[] |
getFidServers() |
Returns the server IPs in which the file is stored.
|
java.lang.String |
getFidStr() |
Returns the file id as string.
|
java.io.FileDescriptor |
getFileDescriptor() |
|
long |
getFileLength() |
Returns the file length.
|
IOStatistics |
getIOStatistics() |
Get the IO Statistics of the nested stream, falling back to
null if the stream does not implement the interface
IOStatisticsSource. |
long |
getPos() |
Get the current position in the input stream.
|
java.io.InputStream |
getWrappedStream() |
Get a reference to the wrapped input stream.
|
boolean |
hasCapability(java.lang.String capability) |
Query the stream for a specific capability.
|
int |
maxReadSizeForVectorReads() |
What is the largest size that we should group ranges together as?
|
int |
minSeekForVectorReads() |
What is the smallest reasonable seek?
|
int |
read(long position,
byte[] buffer,
int offset,
int length) |
Read bytes from the given position in the stream to the given buffer.
|
int |
read(long position,
java.nio.ByteBuffer buf) |
Reads up to
buf.remaining() bytes into buf from a given position
in the file and returns the number of bytes read. |
int |
read(java.nio.ByteBuffer buf) |
Reads up to buf.remaining() bytes into buf.
|
java.nio.ByteBuffer |
read(ByteBufferPool bufferPool,
int maxLength) |
|
java.nio.ByteBuffer |
read(ByteBufferPool bufferPool,
int maxLength,
java.util.EnumSet<ReadOption> opts) |
Get a ByteBuffer containing file data.
|
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 |
readFully(long position,
java.nio.ByteBuffer buf) |
Delegate to the underlying stream.
|
void |
readVectored(java.util.List<? extends FileRange> ranges,
java.util.function.IntFunction<java.nio.ByteBuffer> allocate) |
Read fully a list of file ranges asynchronously from this file.
|
void |
releaseBuffer(java.nio.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(java.lang.Boolean dropBehind) |
Configure whether the stream should drop the cache.
|
void |
setReadahead(java.lang.Long readahead) |
Set the readahead on this stream.
|
java.lang.String |
toString() |
String value.
|
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 void seek(long desired)
throws java.io.IOException
public long getPos()
throws java.io.IOException
public int read(long position,
byte[] buffer,
int offset,
int length)
throws java.io.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
reachedjava.io.IOException - IO problems.public void readFully(long position,
byte[] buffer,
int offset,
int length)
throws java.io.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 readjava.io.IOException - IO problemsjava.io.EOFException - 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.public void readFully(long position,
byte[] buffer)
throws java.io.IOException
readFully in interface PositionedReadableposition - position within filebuffer - destination bufferjava.io.IOException - IO problems.java.io.EOFException - the end of the data was reached before
the read operation completedpublic boolean seekToNewSource(long targetPos)
throws java.io.IOException
seekToNewSource in interface SeekabletargetPos - position to seek tojava.io.IOException - raised on errors performing I/O.@Public @Stable public java.io.InputStream getWrappedStream()
public int read(java.nio.ByteBuffer buf)
throws java.io.IOException
ByteBufferReadable
After a successful call, buf.position() will be advanced by the
number of bytes read and buf.limit() will be unchanged.
In the case of an exception, the state of the buffer (the contents of the
buffer, the buf.position(), the buf.limit(), etc.) is
undefined, and callers should be prepared to recover from this
eventuality.
Callers should use StreamCapabilities.hasCapability(String) with
StreamCapabilities.READBYTEBUFFER to check if the underlying
stream supports this interface, otherwise they might get a
UnsupportedOperationException.
Implementations should treat 0-length requests as legitimate, and must not signal an error upon their receipt.
read in interface ByteBufferReadablebuf - the ByteBuffer to receive the results of the read operation.java.io.IOException - if there is some error performing the readpublic java.io.FileDescriptor getFileDescriptor()
throws java.io.IOException
getFileDescriptor in interface HasFileDescriptorjava.io.IOException - raised on errors performing I/O.public void setReadahead(java.lang.Long readahead)
throws java.io.IOException,
java.lang.UnsupportedOperationException
CanSetReadaheadsetReadahead in interface CanSetReadaheadreadahead - The readahead to use. null means to use the default.java.io.IOException - If there was an error changing the dropBehind
setting.
UnsupportedOperationException If this stream doesn't support
setting readahead.java.lang.UnsupportedOperationExceptionpublic void setDropBehind(java.lang.Boolean dropBehind)
throws java.io.IOException,
java.lang.UnsupportedOperationException
CanSetDropBehindsetDropBehind in interface CanSetDropBehinddropBehind - Whether to drop the cache. null means to use the
default value.java.io.IOException - If there was an error changing the dropBehind
setting.
UnsupportedOperationException If this stream doesn't support
setting the drop-behind.java.lang.UnsupportedOperationExceptionpublic java.nio.ByteBuffer read(ByteBufferPool bufferPool, int maxLength, java.util.EnumSet<ReadOption> opts) throws java.io.IOException, java.lang.UnsupportedOperationException
HasEnhancedByteBufferAccessread in interface 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.java.io.IOException - if there was an error reading.java.lang.UnsupportedOperationException - if factory was null,
and we needed an external byte buffer.public final java.nio.ByteBuffer read(ByteBufferPool bufferPool, int maxLength) throws java.io.IOException, java.lang.UnsupportedOperationException
java.io.IOExceptionjava.lang.UnsupportedOperationExceptionpublic void releaseBuffer(java.nio.ByteBuffer buffer)
HasEnhancedByteBufferAccessreleaseBuffer in interface HasEnhancedByteBufferAccessbuffer - The ByteBuffer to release.public void unbuffer()
CanUnbufferunbuffer in interface CanUnbufferpublic boolean hasCapability(java.lang.String capability)
StreamCapabilitieshasCapability in interface StreamCapabilitiescapability - string to query the stream support for.public java.lang.String toString()
toString in class java.lang.Objectpublic int read(long position,
java.nio.ByteBuffer buf)
throws java.io.IOException
ByteBufferPositionedReadablebuf.remaining() bytes into buf from a given position
in the file and returns the number of bytes read. Callers should use
buf.limit(...) to control the size of the desired read and
buf.position(...) to control the offset into the buffer the data
should be written to.
After a successful call, buf.position() will be advanced by the
number of bytes read and buf.limit() will be unchanged.
In the case of an exception, the state of the buffer (the contents of the
buffer, the buf.position(), the buf.limit(), etc.) is
undefined, and callers should be prepared to recover from this
eventuality.
Callers should use StreamCapabilities.hasCapability(String) with
StreamCapabilities.PREADBYTEBUFFER to check if the underlying
stream supports this interface, otherwise they might get a
UnsupportedOperationException.
Implementations should treat 0-length requests as legitimate, and must not signal an error upon their receipt.
This does not change the current offset of a file, and is thread-safe.
read in interface ByteBufferPositionedReadableposition - position within filebuf - the ByteBuffer to receive the results of the read operation.java.io.IOException - if there is some error performing the readpublic void readFully(long position,
java.nio.ByteBuffer buf)
throws java.io.IOException
readFully in interface ByteBufferPositionedReadableposition - position within filebuf - the ByteBuffer to receive the results of the read operation.java.io.IOException - on a failure from the nested stream.java.lang.UnsupportedOperationException - if the inner stream does not
support this operation.ByteBufferPositionedReadable.read(long, ByteBuffer)public IOStatistics getIOStatistics()
IOStatisticsSource.getIOStatistics in interface IOStatisticsSourcepublic int minSeekForVectorReads()
PositionedReadableminSeekForVectorReads in interface PositionedReadablepublic int maxReadSizeForVectorReads()
PositionedReadablemaxReadSizeForVectorReads in interface PositionedReadablepublic void readVectored(java.util.List<? extends FileRange> ranges, java.util.function.IntFunction<java.nio.ByteBuffer> allocate) throws java.io.IOException
PositionedReadableThe 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.
readVectored in interface PositionedReadableranges - the byte ranges to readallocate - the function to allocate ByteBufferjava.io.IOException - any IOE.public void adviseFile(FSDataInputStream.FadviseType type, long offset, long count) throws java.io.IOException
type - advise typeoffset - starting file offsetcount - number of bytes starting from the offsetjava.io.IOExceptionpublic long getFileLength()
throws java.io.IOException
java.io.IOExceptionpublic java.lang.String getFidStr()
public long[] getFidServers()
public long getChunkSize()
Copyright © 2008–2025 Apache Software Foundation. All rights reserved.