public class ODSFile extends java.lang.Object implements ODSInternal
Constructor and Description |
---|
ODSFile(java.io.File file,
Compressor compression)
The file to be saved to
|
Modifier and Type | Method and Description |
---|---|
void |
append(Tag<?> tag)
Append tags to the end of the file.
|
void |
appendAll(java.util.List<Tag<?>> tags)
Append a list of tags to the end of the file.
|
void |
clear()
Clears all the data from a file.
|
boolean |
delete(java.lang.String key)
Remove a tag from the list.
|
byte[] |
export(Compressor compressor) |
boolean |
find(java.lang.String key)
Find if a key exists within the file.
|
<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.
|
void |
importFile(java.io.File file,
Compressor compressor)
Import a file into this 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.
|
void |
saveToFile(java.io.File file,
Compressor compressor)
Export to another file.
|
void |
set(java.lang.String key,
Tag<?> value)
This method can append, delete, and set tags.
|
public ODSFile(java.io.File file, Compressor compression)
file
- The file.compression
- What compression the file should use.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");
get
in interface ODSInternal
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()
getAll
in interface ODSInternal
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 file. To append tags see append(Tag)
and appendAll(List)
save
in interface ODSInternal
tags
- The list of tags to save.public void append(Tag<?> tag)
append
in interface ODSInternal
tag
- The tag to be appended.public void appendAll(java.util.List<Tag<?>> tags)
appendAll
in interface ODSInternal
tags
- The list of tags.public boolean find(java.lang.String key)
This will not throw ODSException if an IOException occurs.
find
in interface ODSInternal
key
- They key to findpublic boolean delete(java.lang.String key)
delete
in interface ODSInternal
key
- The key to remove.public boolean replaceData(java.lang.String key, Tag<?> replacement)
replaceData
in interface ODSInternal
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.
set
in interface ODSInternal
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.
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)
export
in interface ODSInternal
public void importFile(java.io.File file, Compressor compressor)
This basically copies one file to another.
This will overwrite the current file.
importFile
in interface ODSInternal
file
- The file to copy from.compressor
- The compression of the other file.public void saveToFile(java.io.File file, Compressor compressor)
This basically copies the current file into another one.
saveToFile
in interface ODSInternal
file
- The other file to copy to.compressor
- The desired compression of the copy file.public void clear()
This works internally by overwriting a file.
clear
in interface ODSInternal