Class StringCache
java.lang.Object
org.apache.tomcat.util.buf.StringCache
This class implements a String cache for ByteChunk and CharChunk.
- Author:
- Remy Maucherat
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classprotected static class -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static intAccess count.protected static StringCache.ByteEntry[]Cache for byte chunk.protected static inttoString count for byte chunk.protected static final HashMap<StringCache.ByteEntry, int[]> Statistics hash map for byte chunk.protected static booleanEnabled ?protected static intprotected static StringCache.CharEntry[]Cache for char chunk.protected static inttoString count for char chunk.protected static final HashMap<StringCache.CharEntry, int[]> Statistics hash map for char chunk.protected static booleanprotected static intHit count.protected static final intprotected static int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected static intCompare given byte chunk with byte array.protected static intCompare given char chunk with char array.protected static final StringDeprecated.Unused.protected static Stringfind(ByteChunk name, CodingErrorAction malformedInputAction, CodingErrorAction unmappableCharacterAction) Find an entry given its name in the cache and return the associated String.protected static StringFind an entry given its name in the cache and return the associated String.protected static intfindClosest(ByteChunk name, StringCache.ByteEntry[] array, int len) Find an entry given its name in a sorted array of map elements.protected static intfindClosest(CharChunk name, StringCache.CharEntry[] array, int len) Find an entry given its name in a sorted array of map elements.intbooleanintbooleanintintvoidreset()voidsetByteEnabled(boolean byteEnabled) voidsetCacheSize(int cacheSize) voidsetCharEnabled(boolean charEnabled) voidsetTrainThreshold(int trainThreshold) static Stringstatic StringtoString(ByteChunk bc, CodingErrorAction malformedInputAction, CodingErrorAction unmappableCharacterAction) static String
-
Field Details
-
byteEnabled
protected static boolean byteEnabledEnabled ? -
charEnabled
protected static boolean charEnabled -
trainThreshold
protected static int trainThreshold -
cacheSize
protected static int cacheSize -
maxStringSize
protected static final int maxStringSize -
bcStats
Statistics hash map for byte chunk. -
bcCount
protected static int bcCounttoString count for byte chunk. -
bcCache
Cache for byte chunk. -
ccStats
Statistics hash map for char chunk. -
ccCount
protected static int ccCounttoString count for char chunk. -
ccCache
Cache for char chunk. -
accessCount
protected static int accessCountAccess count. -
hitCount
protected static int hitCountHit count.
-
-
Constructor Details
-
StringCache
public StringCache()
-
-
Method Details
-
getCacheSize
public int getCacheSize()- Returns:
- Returns the cacheSize.
-
setCacheSize
public void setCacheSize(int cacheSize) - Parameters:
cacheSize- The cacheSize to set.
-
getByteEnabled
public boolean getByteEnabled()- Returns:
- Returns the enabled.
-
setByteEnabled
public void setByteEnabled(boolean byteEnabled) - Parameters:
byteEnabled- The enabled to set.
-
getCharEnabled
public boolean getCharEnabled()- Returns:
- Returns the enabled.
-
setCharEnabled
public void setCharEnabled(boolean charEnabled) - Parameters:
charEnabled- The enabled to set.
-
getTrainThreshold
public int getTrainThreshold()- Returns:
- Returns the trainThreshold.
-
setTrainThreshold
public void setTrainThreshold(int trainThreshold) - Parameters:
trainThreshold- The trainThreshold to set.
-
getAccessCount
public int getAccessCount()- Returns:
- Returns the accessCount.
-
getHitCount
public int getHitCount()- Returns:
- Returns the hitCount.
-
reset
public void reset() -
toString
-
toString
public static String toString(ByteChunk bc, CodingErrorAction malformedInputAction, CodingErrorAction unmappableCharacterAction) throws CharacterCodingException - Throws:
CharacterCodingException
-
toString
-
compare
Compare given byte chunk with byte array.- Parameters:
name- The name to comparecompareTo- The compared to data- Returns:
- -1, 0 or +1 if inferior, equal, or superior to the String.
-
find
Deprecated.Unused. Will be removed in Tomcat 11. Usefind(ByteChunk, CodingErrorAction, CodingErrorAction)Find an entry given its name in the cache and return the associated String.- Parameters:
name- The name to find- Returns:
- the corresponding value
-
find
protected static String find(ByteChunk name, CodingErrorAction malformedInputAction, CodingErrorAction unmappableCharacterAction) Find an entry given its name in the cache and return the associated String.- Parameters:
name- The name to findmalformedInputAction- Action to take if a malformed input is encounteredunmappableCharacterAction- Action to take if an unmappable character is encountered- Returns:
- the corresponding value
-
findClosest
Find an entry given its name in a sorted array of map elements. This will return the index for the closest inferior or equal item in the given array.- Parameters:
name- The name to findarray- The array in which to looklen- The effective length of the array- Returns:
- the position of the best match
-
compare
Compare given char chunk with char array.- Parameters:
name- The name to comparecompareTo- The compared to data- Returns:
- -1, 0 or +1 if inferior, equal, or superior to the String.
-
find
-
findClosest
Find an entry given its name in a sorted array of map elements. This will return the index for the closest inferior or equal item in the given array.- Parameters:
name- The name to findarray- The array in which to looklen- The effective length of the array- Returns:
- the position of the best match
-