Package com.nt.udc.util.state
Class StateBuffer
java.lang.Object
com.nt.udc.util.state.StateBuffer
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
ConstructorsConstructorDescriptionStateBuffer
(File stateBufferFile, boolean isNewFile) Creates a state buffer with the given file. -
Method Summary
Modifier and TypeMethodDescriptionvoid
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
Prints the contents of a state buffer file.void
reset()
Resets the state data to empty.toString()
Converts all state data and meta-data to a String.void
write()
Writes the state data to disk.void
writeTo
(OutputStream output) Writes the state data to the given OutputStream.
-
Constructor Details
-
StateBuffer
Creates a state buffer with the given file.- Parameters:
stateBufferFile
- Output file to useisNewFile
- Should the file be treated as as a new buffer file?- Throws:
IOException
-
-
Method Details
-
addState
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 nametag
- Tag description if state itemdata
- State data
-
write
Writes the state data to disk.- Throws:
IOException
-
writeTo
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
Retrieves a state item's data according to class name and tag descriptor.- Parameters:
className
- Originating class nametag
- Tag descriptor- Returns:
- state data
-
toString
Converts all state data and meta-data to a String. -
main
Prints the contents of a state buffer file.- Parameters:
args
- State buffer file name
-