@ThreadSafe public class BufferFromInputStream extends Object implements ChannelFactory<Seekable>
| Modifier and Type | Class and Description |
|---|---|
static class |
BufferFromInputStream.BucketPointer |
class |
BufferFromInputStream.ByteArrayChannel |
| Modifier and Type | Field and Description |
|---|---|
protected BufferFromInputStream.BucketPointer |
activeEnd
End marker with two components (idx, pos)
it is wrapped in an object to enable atomic replacement of the reference
The pointer is monotonous in the sense that the end marker's logical linear location is only increased
Reading an old version while a new one has been set will only cause a read
to return on the old boundary, but a subsequent synchronized check for whether loading
of additional data is needed is then made anyway
|
protected byte[][] |
buckets
The buffered data
|
protected InputStream |
dataSupplier
Supplier for additional data
|
protected boolean |
isDataSupplierConsumed
Flag to indicate that the dataSupplier has been consumed
This is the case when dataSupplier(buffer) returns -1
|
protected long |
knownDataSize
The number of cached bytes.
|
protected int |
maxReadSize
Maximum number to read from the dataSupplier in one request
|
protected int |
minReadSize |
| Constructor and Description |
|---|
BufferFromInputStream(int initialBucketSize,
InputStream dataSupplier) |
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
static BufferFromInputStream |
create(InputStream in,
int maxReadSize,
int... preconfiguredBucketSizes) |
int |
doRead(BufferFromInputStream.ByteArrayChannel reader,
ByteBuffer dst) |
protected void |
ensureCapacityInActiveBucket() |
static BufferFromInputStream.BucketPointer |
getPointer(byte[][] buckets,
BufferFromInputStream.BucketPointer end,
long pos) |
static long |
getPosition(byte[][] buckets,
int idx,
int pos) |
protected void |
loadData(int needed)
fetch a chunk from the input stream
|
protected void |
loadDataUpTo(long requestedPos) |
static void |
main(String[] args) |
Seekable |
newChannel() |
protected int |
nextBucketSize() |
protected byte[][] buckets
protected BufferFromInputStream.BucketPointer activeEnd
protected long knownDataSize
protected InputStream dataSupplier
protected int minReadSize
protected int maxReadSize
protected boolean isDataSupplierConsumed
public BufferFromInputStream(int initialBucketSize,
InputStream dataSupplier)
public static BufferFromInputStream create(InputStream in, int maxReadSize, int... preconfiguredBucketSizes)
maxReadSize - Maximum number of bytes to request form the input stream at oncein - maxReadSize - preconfiguredBucketSizes - public static long getPosition(byte[][] buckets,
int idx,
int pos)
public static BufferFromInputStream.BucketPointer getPointer(byte[][] buckets, BufferFromInputStream.BucketPointer end, long pos)
buckets - pos - public Seekable newChannel()
newChannel in interface ChannelFactory<Seekable>protected int nextBucketSize()
public int doRead(BufferFromInputStream.ByteArrayChannel reader, ByteBuffer dst)
protected void loadDataUpTo(long requestedPos)
protected void loadData(int needed)
protected void ensureCapacityInActiveBucket()
public void close()
throws Exception
close in interface AutoCloseableExceptionCopyright © 2020. All rights reserved.