The key of the map is a long (incremented for each stored block). The default initial value is 0. Before storing blocks into the map, the stream store checks if there is already a block with the next key, and if necessary searches the next free entry using a binary search (0 to Long.MAX_VALUE).
Before storing
The format of the binary id is: An empty id represents 0 bytes of data. In-place data is encoded as 0, the size (a variable size int), then the data. A stored block is encoded as 1, the length of the block (a variable size int), then the key (a variable size long). Multiple ids can be concatenated to concatenate the data. If the id is large, it is stored itself, which is encoded as 2, the total length (a variable size long), and the key of the block that contains the id (a variable size long).
| Modifier and Type | Class and Description |
|---|---|
| pack-priv static class | StreamStore.
A stream backed by a map. |
| Modifier and Type | Field and Description |
|---|---|
| private final Map | |
| private final int | |
| private final int | |
| private final AtomicReference | |
| private final AtomicLong | |
| private final IntConsumer |
| Access | Constructor and Description |
|---|---|
| public | |
| public | |
| public | |
| public |
| Modifier and Type | Method and Description |
|---|---|
| public InputStream | |
| private long | |
| pack-priv byte[] | |
| public Map | |
| public long | Returns: the key, or -1the id id)Get the key of the biggest block, of -1 for inline data. |
| public long | |
| public int | |
| public long | |
| public boolean | Returns: if the id contains the datathe id id)Check whether the id itself contains all the data. |
| public long | Returns: the lengththe id id)Calculate the number of data bytes for the given id. As the length is encoded in the id, this operation does not cause any reads in the map. |
| public byte[] | Returns: the id (potentially an empty array)the stream in)Store the stream, and return the id. The stream is not closed. |
| private boolean | |
| private ByteArrayOutputStream | |
| private static byte[] | |
| public void | |
| public void | |
| public static String | |
| private long |
| map | back to summary |
|---|---|
| private final Map<Long, byte[]> map | |
| maxBlockSize | back to summary |
|---|---|
| private final int maxBlockSize | |
| minBlockSize | back to summary |
|---|---|
| private final int minBlockSize | |
| nextBuffer | back to summary |
|---|---|
| private final AtomicReference<byte[]> nextBuffer | |
| nextKey | back to summary |
|---|---|
| private final AtomicLong nextKey | |
| onStoreCallback | back to summary |
|---|---|
| private final IntConsumer onStoreCallback | |
| StreamStore | back to summary |
|---|---|
| public StreamStore(Map<Long, byte[]> map) Create a stream store instance. | |
| StreamStore | back to summary |
|---|---|
| public StreamStore(Map<Long, byte[]> map, int minBlockSize, int maxBlockSize) | |
| StreamStore | back to summary |
|---|---|
| public StreamStore(Map<Long, byte[]> map, IntConsumer onStoreCallback) | |
| StreamStore | back to summary |
|---|---|
| public StreamStore(Map<Long, byte[]> map, int minBlockSize, int maxBlockSize, IntConsumer onStoreCallback) | |
| get | back to summary |
|---|---|
| public InputStream get(byte[] id) Open an input stream to read data.
| |
| getAndIncrementNextKey | back to summary |
|---|---|
| private long getAndIncrementNextKey() Generate a new key.
| |
| getBlock | back to summary |
|---|---|
| pack-priv byte[] getBlock(long key) Get the block.
| |
| getMap | back to summary |
|---|---|
| public Map | |
| getMaxBlockKey | back to summary |
|---|---|
| public long getMaxBlockKey(byte[] id) Get the key of the biggest block, of -1 for inline data. This method is used to garbage collect orphaned blocks.
| |
| getMaxBlockSize | back to summary |
|---|---|
| public long getMaxBlockSize() | |
| getMinBlockSize | back to summary |
|---|---|
| public int getMinBlockSize() | |
| getNextKey | back to summary |
|---|---|
| public long getNextKey() | |
| isInPlace | back to summary |
|---|---|
| public boolean isInPlace(byte[] id) Check whether the id itself contains all the data. This operation does not cause any reads in the map.
| |
| length | back to summary |
|---|---|
| public long length(byte[] id) Calculate the number of data bytes for the given id. As the length is encoded in the id, this operation does not cause any reads in the map.
| |
| put | back to summary |
|---|---|
| public byte[] put(InputStream in) throws IOException Store the stream, and return the id. The stream is not closed.
| |
| put | back to summary |
|---|---|
| private boolean put(ByteArrayOutputStream id, InputStream in, int level) throws IOException | |
| putIndirectId | back to summary |
|---|---|
| private ByteArrayOutputStream putIndirectId(ByteArrayOutputStream id) throws IOException | |
| read | back to summary |
|---|---|
| private static byte[] read(InputStream in, byte[] target) throws IOException | |
| remove | back to summary |
|---|---|
| public void remove(byte[] id) Remove all stored blocks for the given id.
| |
| setNextKey | back to summary |
|---|---|
| public void setNextKey(long nextKey) | |
| toString | back to summary |
|---|---|
| public static String toString(byte[] id) Convert the id to a human readable string.
| |
| writeBlock | back to summary |
|---|---|
| private long writeBlock(byte[] data) | |
| Modifier and Type | Field and Description |
|---|---|
| private ByteArrayInputStream | |
| private ByteBuffer | |
| private final long | |
| private byte[] | |
| private long | |
| private long | |
| private final StreamStore |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public void | close()
Overrides java. Implements java. Closes this input stream and releases any system resources associated with the stream. |
| private ByteArrayInputStream | |
| public int | read()
Implements abstract java. Reads the next byte of data from the input stream. |
| public int | read(byte[]
the buffer into which the data is read. b, int the start offset in array off, int b
at which the data is written.the maximum number of bytes to read. len)Overrides java. Reads up to |
| public long | skip(long
the number of bytes to be skipped. n)Overrides java. Skips over and discards |
| buffer | back to summary |
|---|---|
| private ByteArrayInputStream buffer | |
| idBuffer | back to summary |
|---|---|
| private ByteBuffer idBuffer | |
| length | back to summary |
|---|---|
| private final long length | |
| oneByteBuffer | back to summary |
|---|---|
| private byte[] oneByteBuffer | |
| pos | back to summary |
|---|---|
| private long pos | |
| skip | back to summary |
|---|---|
| private long skip | |
| store | back to summary |
|---|---|
| private final StreamStore store | |
| Stream | back to summary |
|---|---|
| pack-priv Stream(StreamStore store, byte[] id) | |
| close | back to summary |
|---|---|
| public void close() Overrides java. Implements java. Doc from java. Closes this input stream and releases any system resources associated with the stream.
| |
| nextBuffer | back to summary |
|---|---|
| private ByteArrayInputStream nextBuffer() | |
| read | back to summary |
|---|---|
| public int read() throws IOException Implements abstract java. Doc from java. Reads the next byte of data from the input stream. The value byte is
returned as an
| |
| read | back to summary |
|---|---|
| public int read(byte[] b, int off, int len) throws IOException Overrides java. Doc from java. Reads up to This method blocks until input data is available, end of file is detected, or an exception is thrown. If The first byte read is stored into element In every case, elements
| |
| skip | back to summary |
|---|---|
| public long skip(long n) Overrides java. Doc from java. Skips over and discards
| |