Package alluxio.worker.block.io
Class DelegatingBlockReader
- java.lang.Object
-
- alluxio.worker.block.io.BlockClient
-
- alluxio.worker.block.io.BlockReader
-
- alluxio.worker.block.io.DelegatingBlockReader
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
public class DelegatingBlockReader extends BlockReader
An delegating reader class.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class alluxio.worker.block.io.BlockClient
BlockClient.Type
-
-
Constructor Summary
Constructors Constructor Description DelegatingBlockReader(BlockReader blockReader, java.io.Closeable closeable)
Default constructor for the abstract reader implementations.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
java.nio.channels.ReadableByteChannel
getChannel()
Returns a readable byte channel of the block.BlockReader
getDelegate()
long
getLength()
Gets the length of the block in bytes.java.lang.String
getLocation()
boolean
isClosed()
java.nio.ByteBuffer
read(long offset, long length)
Reads data from the block.java.lang.String
toString()
int
transferTo(io.netty.buffer.ByteBuf buf)
Transfers data (up to buf.writableBytes()) from this reader to the buffer.
-
-
-
Constructor Detail
-
DelegatingBlockReader
public DelegatingBlockReader(BlockReader blockReader, java.io.Closeable closeable)
Default constructor for the abstract reader implementations.- Parameters:
blockReader
- block readercloseable
- closer
-
-
Method Detail
-
getDelegate
public BlockReader getDelegate()
- Returns:
- the delegate
-
read
public java.nio.ByteBuffer read(long offset, long length) throws java.io.IOException
Description copied from class:BlockReader
Reads data from the block.Implementation Note
Since this method needs to allocate a buffer inside its implementation, it must not choose a ByteBuffer that needs any kind of explicit de-allocation, e.g. a pooled buffer, because the caller has no means of knowing how and when to properly deallocate the returned buffer.
If explicit de-allocation is desired, use an externally allocatedByteBuf
and callBlockReader.transferTo(ByteBuf)
instead. It is then the caller's responsibility to de-allocate the buffer.- Specified by:
read
in classBlockReader
- Parameters:
offset
- the offset from starting of the block file in byteslength
- the length of data to read in bytes. If offset + length exceeds the block size, the part of data from offset to the end of block is returned.- Returns:
ByteBuffer
the data that was read, empty buffer ifoffset
is at the end of block- Throws:
java.io.IOException
-
getLength
public long getLength()
Description copied from class:BlockReader
Gets the length of the block in bytes.- Specified by:
getLength
in classBlockReader
- Returns:
- the length of the block in bytes
-
getChannel
public java.nio.channels.ReadableByteChannel getChannel()
Description copied from class:BlockReader
Returns a readable byte channel of the block.- Specified by:
getChannel
in classBlockReader
- Returns:
- channel
-
transferTo
public int transferTo(io.netty.buffer.ByteBuf buf) throws java.io.IOException
Description copied from class:BlockReader
Transfers data (up to buf.writableBytes()) from this reader to the buffer.- Specified by:
transferTo
in classBlockReader
- Parameters:
buf
- the byte buffer- Returns:
- the number of bytes transferred, -1 if the end of the block is reached
- Throws:
java.io.IOException
-
isClosed
public boolean isClosed()
- Specified by:
isClosed
in classBlockReader
- Returns:
- true if this reader is closed
-
getLocation
public java.lang.String getLocation()
- Specified by:
getLocation
in classBlockReader
- Returns:
- an informational string of the location the reader is reading from
-
toString
public java.lang.String toString()
- Overrides:
toString
in classBlockClient
-
close
public void close() throws java.io.IOException
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Overrides:
close
in classBlockClient
- Throws:
java.io.IOException
-
-