@NotThreadSafe public class BlockInStream extends java.io.InputStream implements BoundedStream, Seekable, PositionedReadable
InputStream implementation that is based on DataReaders 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,
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(java.nio.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) |
long |
skip(long n) |
protected BlockInStream(DataReader.Factory dataReaderFactory, WorkerNetAddress address, BlockInStream.BlockInStreamSource blockSource, long id, long length)
BlockInStream.dataReaderFactory - the data reader factoryaddress - 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 java.io.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 objectjava.io.IOExceptionpublic 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, i.e. 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 Positionedpublic int read()
throws java.io.IOException
read in class java.io.InputStreamjava.io.IOExceptionpublic int read(byte[] b)
throws java.io.IOException
read in class java.io.InputStreamjava.io.IOExceptionpublic int read(byte[] b,
int off,
int len)
throws java.io.IOException
read in class java.io.InputStreamjava.io.IOExceptionpublic int read(java.nio.ByteBuffer byteBuffer,
int off,
int len)
throws java.io.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 readjava.io.IOExceptionpublic int positionedRead(long pos,
byte[] b,
int off,
int len)
throws java.io.IOException
PositionedReadablepositionedRead in interface PositionedReadablepos - position within fileb - destination bufferoff - offset in the bufferlen - number of bytes to readjava.io.IOExceptionpublic long remaining()
remaining in interface BoundedStreampublic void seek(long pos)
throws java.io.IOException
public long skip(long n)
throws java.io.IOException
skip in class java.io.InputStreamjava.io.IOExceptionpublic void close()
throws java.io.IOException
close in interface java.io.Closeableclose in interface java.lang.AutoCloseableclose in class java.io.InputStreamjava.io.IOExceptionpublic DataReader.Factory getDataReaderFactory()
public WorkerNetAddress getAddress()
public BlockInStream.BlockInStreamSource getSource()
public long getId()
Copyright © 2022. All Rights Reserved.