public class ObjectDataStructure
extends java.lang.Object
ObjectDataStructure has two storage types: File and Memory. File reads from a file while memory deals with an array (or buffer) of bytes. This class deals with both types. The type is dependent on the constructor.
Most methods in ODS use what is called a key to reference objects within the file/buffer. A key allows you to grab specific information within the file/buffer. For example: If you wanted a specific string inside of an object with lots of information, you can get that specific string without any other data. If you have an object named Car and you wanted to get a string tag named owner from the inside the object, then the key for that would be:
Car.owner
Let's say that the owner is an object called 'Owner' and you want to get the age of the owner, you could do:
Car.Owner.age
You can obtain any tag using the key system, including ObjectTags. So the key `Car.Owner` would be valid.
ODSException
is thrown when an IOException is encountered or the file/buffer is not in the ODS format / is corrupted.
For exact information on the methods depending on storage type (viz. File or Memory) please visit the respective internal classes.
Constructor and Description |
---|
ObjectDataStructure()
Create ODS using the memory storage type.
|
ObjectDataStructure(byte[] data,
Compressor compressor)
Create ODS using the memory storage type.
|
ObjectDataStructure(java.nio.ByteBuffer data,
Compressor compressor)
Create ODS using the memory storage type.
|
ObjectDataStructure(java.io.File file)
Create ODS using the file storage type.
|
ObjectDataStructure(java.io.File file,
Compressor compression)
Create ODS using the file storage type.
|
Modifier and Type | Method and Description |
---|---|
void |
append(Tag<?> tag)
Append tags to the end of the data.
|
void |
appendAll(java.util.List<Tag<?>> tags)
Append a list of tags to the end of the data.
|
void |
clear()
Clear all data from the file / memory.
|
boolean |
delete(java.lang.String key)
Remove a tag from the list.
|
byte[] |
export(Compressor compressor)
Get the array of bytes in any compression format.
|
boolean |
find(java.lang.String key)
Find if a key exists within the data.
|
<T extends Tag<?>> |
get(java.lang.String key)
Grab a tag based upon an object key.
|
java.util.List<Tag<?>> |
getAll()
Get all of the tags in the file/buffer.
|
void |
importFile(java.io.File file,
Compressor compressor)
Import the data from an ODS file.
|
boolean |
replaceData(java.lang.String key,
Tag<?> replacement)
Replace a key with another tag.
|
void |
save(java.util.List<? extends Tag<?>> tags)
Save tags to the file/buffer.
|
void |
saveToFile(java.io.File file,
Compressor compressor)
Save the data to a file.
|
void |
set(java.lang.String key,
Tag<?> value)
This method can append, delete, and set tags.
|
public ObjectDataStructure(java.io.File file)
This uses the GZIP compression format by default.
file
- The file.public ObjectDataStructure(java.io.File file, Compressor compression)
file
- The file.compression
- What compression the file should use.public ObjectDataStructure(byte[] data, Compressor compressor)
data
- Pre-existing data that should be inserted into the buffer.compressor
- The compression format the data uses.public ObjectDataStructure(java.nio.ByteBuffer data, Compressor compressor)
data
- Pre-existing data should be inserted into the buffer.compressor
- The compression format the data uses.public ObjectDataStructure()
An empty buffer is created.
public <T extends Tag<?>> T get(java.lang.String key)
This method allows you to directly get sub-objects with little overhead.
get("Object1.Object2.valuetag");
T
- The tag type.key
- The key to use.This will return null if the requested sub-object does not exist, or if the file does not exist.
public java.util.List<Tag<?>> getAll()
This will return null if there are no tags, or if the file does not exist.
public void save(java.util.List<? extends Tag<?>> tags)
This will overwrite the existing data. To append tags see append(Tag)
and appendAll(List)
tags
- The list of tags to save.public void append(Tag<?> tag)
tag
- The tag to be appended.public void appendAll(java.util.List<Tag<?>> tags)
tags
- The list of tags.public boolean find(java.lang.String key)
This will not throw ODSException if an IOException occurs.
key
- They key to findpublic boolean delete(java.lang.String key)
key
- The key to remove.public boolean replaceData(java.lang.String key, Tag<?> replacement)
key
- The keyreplacement
- The data to replacepublic void set(java.lang.String key, Tag<?> value)
A note on keys when appending: ObjectOne.ObjectTwo.tagName
When appending data tagName will not be the actual tag name.
The tag name written to the file is the name of the specified tag in the value parameter. Any parent objects that do not exist will be created. For example:
ObjectOne.ObjectTwo.NewObject.tagName
If in the example above NewObject does not exist, than the object will be created with the value tag inside
of it. Please see the wiki for a more detailed explanation on this.
When value is null, the specified key is deleted. The key MUST exist or an ODSException
will be thrown.
key
- The key of the tag to append, delete, or set.
When appending the key does not need to exist. ObjectTags that don't exist will be created automatically.
When the key is set to "" (An empty string) than it is assumed you want to append to the parent file/buffer.
Valid Tags:
ObjectOne.tagToDelete
ObjectOne.NewObject.tagToAppend
ObjectOne.tagToSet
value
- The tag to append or replace the key with. If this parameter is null than the key is deleted.
public byte[] export(Compressor compressor)
compressor
- The compression format.public void importFile(java.io.File file, Compressor compressor)
See ODSMem.importFile(File, Compressor)
and ODSFile.importFile(File, Compressor)
for the specifics.
file
- The file to import from.compressor
- The compressor.public void saveToFile(java.io.File file, Compressor compressor)
See ODSMem.saveToFile(File, Compressor)
and ODSFile.saveToFile(File, Compressor)
for
the specifics.
file
- The file.compressor
- The Compressor.public void clear()