@NotThreadSafe public class BlockInStream extends InputStream implements BoundedStream, Seekable, PositionedReadable
InputStream
implementation that is based on DataReader
s to
stream data chunk by chunk.Modifier and Type | Class and Description |
---|---|
static class |
BlockInStream.BlockInStreamSource
the source tracking where the block is from.
|
Modifier | Constructor and Description |
---|---|
protected |
BlockInStream(DataReader.Factory dataReaderFactory,
AlluxioConfiguration conf,
WorkerNetAddress address,
BlockInStream.BlockInStreamSource blockSource,
long id,
long length)
Creates an instance of
BlockInStream . |
Modifier and Type | Method and Description |
---|---|
void |
close() |
static BlockInStream |
create(FileSystemContext context,
BlockInfo info,
WorkerNetAddress dataSource,
BlockInStream.BlockInStreamSource dataSourceType,
InStreamOptions options)
Creates a
BlockInStream . |
static BlockInStream |
createRemoteBlockInStream(FileSystemContext context,
long blockId,
WorkerNetAddress address,
BlockInStream.BlockInStreamSource blockSource,
long blockSize,
Protocol.OpenUfsBlockOptions ufsOptions)
Creates a
BlockInStream to read from a specific remote server. |
WorkerNetAddress |
getAddress() |
DataReader.Factory |
getDataReaderFactory() |
long |
getId() |
long |
getPos() |
BlockInStream.BlockInStreamSource |
getSource() |
int |
positionedRead(long pos,
byte[] b,
int off,
int len)
Reads up to the specified number of bytes, from a given position within a file, and return the
number of bytes read.
|
int |
read() |
int |
read(byte[] b) |
int |
read(byte[] b,
int off,
int len) |
int |
read(ByteBuffer byteBuffer,
int off,
int len)
Reads up to len bytes of data from the input stream into the byte buffer.
|
long |
remaining() |
void |
seek(long pos)
Moves the starting read position of the stream to the specified position which is relative to
the start of the stream.
|
long |
skip(long n) |
available, mark, markSupported, reset
protected BlockInStream(DataReader.Factory dataReaderFactory, AlluxioConfiguration conf, WorkerNetAddress address, BlockInStream.BlockInStreamSource blockSource, long id, long length)
BlockInStream
.dataReaderFactory
- the data reader factoryconf
- the Alluxio configurationaddress
- the address of the gRPC data serverblockSource
- the source location of the blockid
- the ID (either block ID or UFS file ID)length
- the lengthpublic static BlockInStream create(FileSystemContext context, BlockInfo info, WorkerNetAddress dataSource, BlockInStream.BlockInStreamSource dataSourceType, InStreamOptions options) throws IOException
BlockInStream
.
One of several read behaviors:
1. Domain socket - if the data source is the local worker and the local worker has a domain
socket server
2. Short-Circuit - if the data source is the local worker
3. Local Loopback Read - if the data source is the local worker and short circuit is disabled
4. Read from remote worker - if the data source is a remote worker
5. UFS Read from worker - if the data source is UFS, read from the UFS policy's designated
worker (ufs -> local or remote worker -> client)context
- the file system contextinfo
- the block infodataSource
- the Alluxio worker which should read the datadataSourceType
- the source location of the blockoptions
- the instream optionsBlockInStream
objectIOException
public static BlockInStream createRemoteBlockInStream(FileSystemContext context, long blockId, WorkerNetAddress address, BlockInStream.BlockInStreamSource blockSource, long blockSize, Protocol.OpenUfsBlockOptions ufsOptions)
BlockInStream
to read from a specific remote server. Should only be used
in cases where the data source and method of reading is known, ie. worker - worker
communication.context
- the file system contextblockId
- the block idaddress
- the address of the gRPC data serverblockSource
- the source location of the blockblockSize
- the size of the blockufsOptions
- the ufs read optionsBlockInStream
createdpublic long getPos()
getPos
in interface Positioned
public int read() throws IOException
read
in class InputStream
IOException
public int read(byte[] b) throws IOException
read
in class InputStream
IOException
public int read(byte[] b, int off, int len) throws IOException
read
in class InputStream
IOException
public int read(ByteBuffer byteBuffer, int off, int len) throws IOException
byteBuffer
- the buffer into which the data is readoff
- the start offset in the buffer at which the data is writtenlen
- the maximum number of bytes to readIOException
public int positionedRead(long pos, byte[] b, int off, int len) throws IOException
PositionedReadable
positionedRead
in interface PositionedReadable
pos
- position within fileb
- destination bufferoff
- offset in the bufferlen
- number of bytes to readIOException
public long remaining()
remaining
in interface BoundedStream
public void seek(long pos) throws IOException
Seekable
seek
in interface Seekable
pos
- the position to seek to, it must be between 0 and the end of the stream - 1IOException
public long skip(long n) throws IOException
skip
in class InputStream
IOException
public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
close
in class InputStream
IOException
public DataReader.Factory getDataReaderFactory()
public WorkerNetAddress getAddress()
public BlockInStream.BlockInStreamSource getSource()
public long getId()
Copyright © 2023. All Rights Reserved.