public class StringDecoder extends Object
There are two controls on the amount of caching instances of this class will do:
getMaxCacheLength()
limits the length of the encoded bytes this
class will try and retrieve from the cache. Setting this value to zero
disables the cache and limit any memory overhead.getMaxCacheEntries()
controls the number of cached strings in
the trie. Each entry represents a single encoded strings so if you wanted to
cache 100 strings of length 10 bytes each then you would set the value to 100
but there may be up to 1000 nodes in the trie.This class is not thread safe.
Modifier and Type | Class and Description |
---|---|
protected static class |
StringDecoder.Node
Node provides a single node in the trie.
|
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_MAX_CACHE_ENTRIES
The default maximum number of entries to keep in the trie cache.
|
static int |
DEFAULT_MAX_CACHE_LENGTH
The default maximum length byte array to cache.
|
Constructor and Description |
---|
StringDecoder()
Creates a new TrieStringCache.
|
Modifier and Type | Method and Description |
---|---|
String |
decode(byte[] source,
int offset,
int length)
Decode a string of a known length.
|
int |
getMaxCacheEntries()
Returns the maximum node count.
|
int |
getMaxCacheLength()
Returns the maximum depth of the nodes in the trie.
|
void |
setMaxCacheEntries(int maxCacheEntries)
Sets the value of maximum number of cached strings.
|
void |
setMaxCacheLength(int maxlength)
Sets the value of maximum depth of the nodes in the trie to the new
value.
|
public static final int DEFAULT_MAX_CACHE_ENTRIES
public static final int DEFAULT_MAX_CACHE_LENGTH
public String decode(byte[] source, int offset, int length) throws StreamCorruptedException, EOFException
source
- The source of the bytes in the string.offset
- The offset of the first byte to decode.length
- The length of the string to decode with a terminal zero byte.StreamCorruptedException
- On the decoding of the string failing.EOFException
- On the array not containing enough bytes to decoded.public int getMaxCacheEntries()
public int getMaxCacheLength()
public void setMaxCacheEntries(int maxCacheEntries)
maxCacheEntries
- The new value for the maximum number of cached strings.public void setMaxCacheLength(int maxlength)
maxlength
- The new value for the maximum depth of the nodes in the trie.Copyright © 2011–2014 Allanbank Consulting, Inc.. All rights reserved.