Class StringCache

java.lang.Object
org.apache.tomcat.util.buf.StringCache

public class StringCache extends Object
This class implements a String cache for ByteChunk and CharChunk.
Author:
Remy Maucherat
  • Field Details Link icon

    • byteEnabled Link icon

      protected static boolean byteEnabled
      Enabled ?
    • charEnabled Link icon

      protected static boolean charEnabled
    • trainThreshold Link icon

      protected static int trainThreshold
    • cacheSize Link icon

      protected static int cacheSize
    • maxStringSize Link icon

      protected static final int maxStringSize
    • bcStats Link icon

      protected static final HashMap<StringCache.ByteEntry, int[]> bcStats
      Statistics hash map for byte chunk.
    • bcCount Link icon

      protected static int bcCount
      toString count for byte chunk.
    • bcCache Link icon

      protected static volatile StringCache.ByteEntry[] bcCache
      Cache for byte chunk.
    • ccStats Link icon

      protected static final HashMap<StringCache.CharEntry, int[]> ccStats
      Statistics hash map for char chunk.
    • ccCount Link icon

      protected static int ccCount
      toString count for char chunk.
    • ccCache Link icon

      protected static volatile StringCache.CharEntry[] ccCache
      Cache for char chunk.
    • accessCount Link icon

      protected static int accessCount
      Access count.
    • hitCount Link icon

      protected static int hitCount
      Hit count.
  • Constructor Details Link icon

    • StringCache Link icon

      public StringCache()
  • Method Details Link icon

    • getCacheSize Link icon

      public int getCacheSize()
      Returns:
      Returns the cacheSize.
    • setCacheSize Link icon

      public void setCacheSize(int cacheSize)
      Parameters:
      cacheSize - The cacheSize to set.
    • getByteEnabled Link icon

      public boolean getByteEnabled()
      Returns:
      Returns the enabled.
    • setByteEnabled Link icon

      public void setByteEnabled(boolean byteEnabled)
      Parameters:
      byteEnabled - The enabled to set.
    • getCharEnabled Link icon

      public boolean getCharEnabled()
      Returns:
      Returns the enabled.
    • setCharEnabled Link icon

      public void setCharEnabled(boolean charEnabled)
      Parameters:
      charEnabled - The enabled to set.
    • getTrainThreshold Link icon

      public int getTrainThreshold()
      Returns:
      Returns the trainThreshold.
    • setTrainThreshold Link icon

      public void setTrainThreshold(int trainThreshold)
      Parameters:
      trainThreshold - The trainThreshold to set.
    • getAccessCount Link icon

      public int getAccessCount()
      Returns:
      Returns the accessCount.
    • getHitCount Link icon

      public int getHitCount()
      Returns:
      Returns the hitCount.
    • reset Link icon

      public void reset()
    • toString Link icon

      public static String toString(ByteChunk bc)
    • toString Link icon

      public static String toString(ByteChunk bc, CodingErrorAction malformedInputAction, CodingErrorAction unmappableCharacterAction) throws CharacterCodingException
      Throws:
      CharacterCodingException
    • toString Link icon

      public static String toString(CharChunk cc)
    • compare Link icon

      protected static int compare(ByteChunk name, byte[] compareTo)
      Compare given byte chunk with byte array.
      Parameters:
      name - The name to compare
      compareTo - The compared to data
      Returns:
      -1, 0 or +1 if inferior, equal, or superior to the String.
    • find Link icon

      @Deprecated protected static final String find(ByteChunk name)
      Deprecated.
      Unused. Will be removed in Tomcat 11. Use find(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 Link icon

      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 find
      malformedInputAction - Action to take if a malformed input is encountered
      unmappableCharacterAction - Action to take if an unmappable character is encountered
      Returns:
      the corresponding value
    • findClosest Link icon

      protected static int findClosest(ByteChunk name, StringCache.ByteEntry[] array, int len)
      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 find
      array - The array in which to look
      len - The effective length of the array
      Returns:
      the position of the best match
    • compare Link icon

      protected static int compare(CharChunk name, char[] compareTo)
      Compare given char chunk with char array.
      Parameters:
      name - The name to compare
      compareTo - The compared to data
      Returns:
      -1, 0 or +1 if inferior, equal, or superior to the String.
    • find Link icon

      protected static String find(CharChunk name)
      Find an entry given its name in the cache and return the associated String.
      Parameters:
      name - The name to find
      Returns:
      the corresponding value
    • findClosest Link icon

      protected static int findClosest(CharChunk name, StringCache.CharEntry[] array, int len)
      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 find
      array - The array in which to look
      len - The effective length of the array
      Returns:
      the position of the best match