Class StateBuffer

java.lang.Object
com.nt.udc.util.state.StateBuffer

public class StateBuffer extends Object
The StateBuffer class is responsible for holding small amounts of state data for any number of objects. The user may add state data as needed, and then invoke the write() call to persist the data to disk. The state data is immutable, therefore, it cannot be changed once it has been added to the buffer. The user must either reset() the buffer, or create a new StateBuffer object if he needs to re-write data. This is for efficiency's sake, not flexibility. The user may query a state's data at a later time using the getStateData(...) call.
  • Constructor Summary

    Constructors
    Constructor
    Description
    StateBuffer(File stateBufferFile, boolean isNewFile)
    Creates a state buffer with the given file.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addState(String className, String tag, byte[] data)
    Adds state information for a given item, where the item is described by its originating class, tag description, and state data.
    byte[]
    getStateData(String className, String tag)
    Retrieves a state item's data according to class name and tag descriptor.
    static void
    main(String[] args)
    Prints the contents of a state buffer file.
    void
    Resets the state data to empty.
    Converts all state data and meta-data to a String.
    void
    Writes the state data to disk.
    void
    Writes the state data to the given OutputStream.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • StateBuffer

      public StateBuffer(File stateBufferFile, boolean isNewFile) throws IOException
      Creates a state buffer with the given file.
      Parameters:
      stateBufferFile - Output file to use
      isNewFile - Should the file be treated as as a new buffer file?
      Throws:
      IOException
  • Method Details

    • addState

      public void addState(String className, String tag, byte[] data)
      Adds state information for a given item, where the item is described by its originating class, tag description, and state data.
      Parameters:
      className - Originating class name
      tag - Tag description if state item
      data - State data
    • write

      public void write() throws IOException
      Writes the state data to disk.
      Throws:
      IOException
    • writeTo

      public void writeTo(OutputStream output) throws IOException
      Writes the state data to the given OutputStream.
      Parameters:
      output - Output stream for writing.
      Throws:
      IOException
    • reset

      public void reset()
      Resets the state data to empty.
    • getStateData

      public byte[] getStateData(String className, String tag)
      Retrieves a state item's data according to class name and tag descriptor.
      Parameters:
      className - Originating class name
      tag - Tag descriptor
      Returns:
      state data
    • toString

      public String toString()
      Converts all state data and meta-data to a String.
      Overrides:
      toString in class Object
    • main

      public static void main(String[] args)
      Prints the contents of a state buffer file.
      Parameters:
      args - State buffer file name