Interface ByteBufferPositionedReadable
- All Known Implementing Classes:
FSDataInputStream,HdfsDataInputStream
ByteBuffer rather than a byte[].- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionintread(long position, ByteBuffer buf) Reads up tobuf.remaining()bytes into buf from a given position in the file and returns the number of bytes read.voidreadFully(long position, ByteBuffer buf) Readsbuf.remaining()bytes into buf from a given position in the file or until the end of the data was reached before the read operation completed.
-
Method Details
-
read
Reads up tobuf.remaining()bytes into buf from a given position in the file and returns the number of bytes read. Callers should usebuf.limit(...)to control the size of the desired read andbuf.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 andbuf.limit()will be unchanged.In the case of an exception, the state of the buffer (the contents of the buffer, the
buf.position(), thebuf.limit(), etc.) is undefined, and callers should be prepared to recover from this eventuality.Callers should use
StreamCapabilities.hasCapability(String)withStreamCapabilities.PREADBYTEBUFFERto check if the underlying stream supports this interface, otherwise they might get aUnsupportedOperationException.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.
- Parameters:
position- position within filebuf- the ByteBuffer to receive the results of the read operation.- Returns:
- the number of bytes read, possibly zero, or -1 if reached end-of-stream
- Throws:
IOException- if there is some error performing the read
-
readFully
Readsbuf.remaining()bytes into buf from a given position in the file or until the end of the data was reached before the read operation completed. Callers should usebuf.limit(...)to control the size of the desired read andbuf.position(...)to control the offset into the buffer the data should be written to.This operation provides similar semantics to
read(long, ByteBuffer), the difference is that this method is guaranteed to read data until theByteBufferis full, or until the end of the data stream is reached.- Parameters:
position- position within filebuf- the ByteBuffer to receive the results of the read operation.- Throws:
IOException- if there is some error performing the readEOFException- the end of the data was reached before the read operation completed- See Also:
-