public class StringEncoder extends Object
The cache is controlled via two parameters:
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_MAX_CACHE_ENTRIES
The default maximum number of strings to keep in the trie cache.
|
static int |
DEFAULT_MAX_CACHE_LENGTH
The default maximum length byte array to cache.
|
protected static Log |
LOG
The logger for the
StringEncoder . |
protected int |
myMaxCachEntries
The maximum number of strings to have in the cache.
|
Constructor and Description |
---|
StringEncoder()
Creates a new StringEncoder.
|
Modifier and Type | Method and Description |
---|---|
void |
encode(String string,
OutputStream out)
Writes the string as a UTF-8 string.
|
int |
encodeSize(String string)
Computes the size of the encoded UTF8 String based on the table below.
|
protected byte[] |
fastEncode(String string,
OutputStream out)
Writes the string as a UTF-8 string.
|
int |
getMaxCacheEntries()
Returns the maximum number of strings that can be cached.
|
int |
getMaxCacheLength()
Returns the maximum length for a string that the encoder is allowed to
cache.
|
void |
setMaxCacheEntries(int maxCacheEntries)
Sets the value of maximum number of cached strings.
|
void |
setMaxCacheLength(int maxlength)
Sets the value of length for a string that the encoder is allowed to
cache to the new value.
|
static int |
utf8Size(String string)
Computes the size of the encoded UTF8 String based on the table below.
|
public static final int DEFAULT_MAX_CACHE_ENTRIES
public static final int DEFAULT_MAX_CACHE_LENGTH
protected static final Log LOG
StringEncoder
.protected int myMaxCachEntries
public static int utf8Size(String string)
# Code Points Bytes 1 U+0000..U+007F 1 2 U+0080..U+07FF 2 3 U+0800..U+0FFF 3 U+1000..U+FFFF 4 U+10000..U+3FFFF 4 U+40000..U+FFFFF 4 U+100000..U10FFFF 4
string
- The string to determine the length of.public void encode(String string, OutputStream out) throws IOException
string
- The string to encode.out
- The stream to write to.IOException
- On a failure to write the bytes.public int encodeSize(String string)
# Code Points Bytes 1 U+0000..U+007F 1 2 U+0080..U+07FF 2 3 U+0800..U+0FFF 3 U+1000..U+FFFF 4 U+10000..U+3FFFF 4 U+40000..U+FFFFF 4 U+100000..U10FFFF 4
string
- The string to determine the length of.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 length for a string that the encoder is
allowed to cache.protected byte[] fastEncode(String string, OutputStream out) throws IOException
string
- The string to encode.out
- The stream to write to.IOException
- On a failure to write the bytes.Copyright © 2011–2014 Allanbank Consulting, Inc.. All rights reserved.