Package org.apache.hadoop.hdfs
Interface BlockReader
- All Superinterfaces:
AutoCloseable,org.apache.hadoop.fs.ByteBufferReadable,Closeable
- All Known Implementing Classes:
BlockReaderRemote,ExternalBlockReader
A BlockReader is responsible for reading a single block
from a single datanode.
-
Method Summary
Modifier and TypeMethodDescriptionintReturns an estimate of the number of bytes that can be read (or skipped over) from this input stream without performing network I/O.voidclose()Close the block reader.getClientMmap(EnumSet<org.apache.hadoop.fs.ReadOption> opts) Get a ClientMmap object for this BlockReader.org.apache.hadoop.util.DataChecksumintReturn the network distance between local machine and the remote machine.booleanintread(byte[] buf, int off, int len) intreadAll(byte[] buf, int offset, int len) Similar toreadFully(byte[], int, int)except that it will not throw an exception on EOF.voidreadFully(byte[] buf, int readOffset, int amtToRead) Read exactly the given amount of data, throwing an exception if EOF is reached before that amountlongskip(long n) Skip the given number of bytesMethods inherited from interface org.apache.hadoop.fs.ByteBufferReadable
read
-
Method Details
-
read
- Throws:
IOException
-
skip
Skip the given number of bytes- Throws:
IOException
-
available
int available()Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without performing network I/O. This may return more than what is actually present in the block. -
close
Close the block reader.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
readFully
Read exactly the given amount of data, throwing an exception if EOF is reached before that amount- Throws:
IOException
-
readAll
Similar toreadFully(byte[], int, int)except that it will not throw an exception on EOF. However, it differs from the simpleread(byte[], int, int)call in that it is guaranteed to read the data if it is available. In other words, if this call does not throw an exception, then either the buffer has been filled or the next call will return EOF.- Throws:
IOException
-
isShortCircuit
boolean isShortCircuit()- Returns:
- true only if this is a short-circuit read. All short-circuit reads are also local.
-
getClientMmap
Get a ClientMmap object for this BlockReader.- Parameters:
opts- The read options to use.- Returns:
- The ClientMmap object, or null if mmap is not supported.
-
getDataChecksum
org.apache.hadoop.util.DataChecksum getDataChecksum()- Returns:
- The DataChecksum used by the read block
-
getNetworkDistance
int getNetworkDistance()Return the network distance between local machine and the remote machine.
-