Package org.apache.hadoop.fs
Interface ByteBufferReadable
- All Known Implementing Classes:
FSDataInputStream,HdfsDataInputStream
@Public
@Evolving
public interface ByteBufferReadable
Implementers of this interface provide a read API that writes to a
ByteBuffer, not a byte[].
-
Method Summary
Modifier and TypeMethodDescriptionintread(ByteBuffer buf) Reads up to buf.remaining() bytes into buf.
-
Method Details
-
read
Reads up to buf.remaining() bytes into buf. Callers should use buf.limit(..) to control the size of the desired read.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.READBYTEBUFFERto 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.
- Parameters:
buf- the ByteBuffer to receive the results of the read operation.- Returns:
- the number of bytes read, possibly zero, or -1 if reach end-of-stream
- Throws:
IOException- if there is some error performing the read
-