public class StreamStore extends Object
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).
Constructor and Description |
---|
StreamStore(Map<Long,byte[]> map)
Create a stream store instance.
|
Modifier and Type | Method and Description |
---|---|
InputStream |
get(byte[] id)
Open an input stream to read data.
|
Map<Long,byte[]> |
getMap() |
long |
getMaxBlockKey(byte[] id)
Get the key of the biggest block, of -1 for inline data.
|
long |
getMaxBlockSize() |
int |
getMinBlockSize() |
long |
getNextKey() |
boolean |
isInPlace(byte[] id)
Check whether the id itself contains all the data.
|
long |
length(byte[] id)
Calculate the number of data bytes for the given id.
|
protected void |
onStore(int len)
This method is called after a block of data is stored.
|
byte[] |
put(InputStream in)
Store the stream, and return the id.
|
void |
remove(byte[] id)
Remove all stored blocks for the given id.
|
void |
setMaxBlockSize(int maxBlockSize)
Set the maximum block size.
|
void |
setMinBlockSize(int minBlockSize)
Set the minimum block size.
|
void |
setNextKey(long nextKey) |
static String |
toString(byte[] id)
Convert the id to a human readable string.
|
public void setNextKey(long nextKey)
public long getNextKey()
public void setMinBlockSize(int minBlockSize)
minBlockSize
- the new valuepublic int getMinBlockSize()
public void setMaxBlockSize(int maxBlockSize)
maxBlockSize
- the new valuepublic long getMaxBlockSize()
public byte[] put(InputStream in) throws IOException
in
- the streamIOException
protected void onStore(int len)
len
- the length of the stored block.public long getMaxBlockKey(byte[] id)
id
- the idpublic void remove(byte[] id)
id
- the idpublic static String toString(byte[] id)
id
- the stream idpublic long length(byte[] id)
id
- the idpublic boolean isInPlace(byte[] id)
id
- the idpublic InputStream get(byte[] id)
id
- the idCopyright © 2020 JBoss by Red Hat. All rights reserved.