Class StringTable


  • public class StringTable
    extends java.lang.Object
    A offset-to-String string table backed by a simple byte array (encoded as UTF-8).

    Requested strings are instantiated when requested.

    • Constructor Summary

      Constructors 
      Constructor Description
      StringTable​(byte[] bytes)
      Creates a StringTable using the bytes contained in the supplied array.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(int offset, java.lang.String s)
      Modifies the string table to add a string at a specified offset, growing the internal byte[] storage as necessary to accommodate the string at the offset.
      void clear()  
      int getByteCount()  
      java.lang.String getStringAtOffset​(long offset)
      Returns the string found at offset, or throws an IOException if the offset is out of bounds.
      boolean isValid​(long offset)
      Returns true if the specified offset is a valid offset for this string table.
      static StringTable readStringTable​(ByteProvider bp)
      Create a StringTable by reading the entire contents of a ByteProvider into memory.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • StringTable

        public StringTable​(byte[] bytes)
        Creates a StringTable using the bytes contained in the supplied array.
    • Method Detail

      • readStringTable

        public static StringTable readStringTable​(ByteProvider bp)
                                           throws java.io.IOException
        Create a StringTable by reading the entire contents of a ByteProvider into memory.

        If the specified ByteProvider is null, an empty string table will be constructed.

        Parameters:
        bp -
        Returns:
        Throws:
        java.io.IOException
      • isValid

        public boolean isValid​(long offset)
        Returns true if the specified offset is a valid offset for this string table.

        Parameters:
        offset -
        Returns:
      • clear

        public void clear()
      • getStringAtOffset

        public java.lang.String getStringAtOffset​(long offset)
                                           throws java.io.IOException
        Returns the string found at offset, or throws an IOException if the offset is out of bounds.
        Parameters:
        offset -
        Returns:
        a string, never null.
        Throws:
        java.io.IOException - if not found
      • getByteCount

        public int getByteCount()
      • add

        public void add​(int offset,
                        java.lang.String s)
        Modifies the string table to add a string at a specified offset, growing the internal byte[] storage as necessary to accommodate the string at the offset.

        Used for unit tests to construct a custom string table for test cases.

        Parameters:
        offset - where to place the string in the table
        s - string to insert into table