public abstract class PlayerData
extends java.lang.Object
Field annotations to be
serialized/deserialized properly| Constructor and Description |
|---|
PlayerData() |
| Modifier and Type | Method and Description |
|---|---|
void |
createDirectory(java.lang.String... path)
Creates a directory within in the game data location
|
boolean |
delete(java.lang.String... path)
Deletes a file or directory within in the game data location
|
protected abstract void |
ensureDataDirectoryExists()
Internal method for setting up the save data directory (if required)
|
protected void |
ensureDirectoryExistsForFile(java.lang.String... filepath) |
FileHandle |
getFileHandle(java.lang.String... filepath)
Returns a
FileHandle of a file or directory in the player data location |
boolean |
hasDirectory(java.lang.String... path)
Checks if the directory exists in the game data location
|
boolean |
hasFile(java.lang.String... filepath)
Checks if the file exists in the game data location
|
java.io.DataInputStream |
readBytes(java.lang.String... filepath)
Reads the contents of a file in the player data location via a
DataInputStream. |
<T> T |
readJson(java.lang.Class<T> clazz,
java.lang.String... filepath)
Converts JSON from a file into an object.
|
java.lang.String |
readString(java.lang.String... filepath)
Reads the contents of a file in the player data location into a
String |
<T> T |
readXml(java.lang.Class<T> clazz,
java.lang.String... filepath)
Converts XML from a file into an object.
|
protected abstract FileHandle |
resolve(java.lang.String[] filepath)
Returns a
FileHandle for a file or directory within the save data directory |
protected abstract FileHandle |
resolveTmp(java.lang.String[] filepath)
Returns a
FileHandle for a temporary file or directory within the save data directory |
abstract void |
wipe()
Wipes all data within the game data location
|
java.io.DataOutputStream |
writeBytes(java.lang.String... filepath)
Writes contents to a file in the player data location.
|
<T> void |
writeJson(T object,
java.lang.String... filepath)
Writes an object as JSON to a file.
|
void |
writeString(java.lang.String content,
java.lang.String... filepath)
Writes a
String to a file in the player data location |
<T> void |
writeXml(T object,
java.lang.String... filepath)
Writes an object as XML to a file.
|
protected abstract FileHandle resolve(java.lang.String[] filepath)
FileHandle for a file or directory within the save data directoryfilepath - The path broken up by directory/fileFileHandle instanceprotected abstract FileHandle resolveTmp(java.lang.String[] filepath)
FileHandle for a temporary file or directory within the save data directoryfilepath - The path broken up by directory/fileFileHandle instanceprotected abstract void ensureDataDirectoryExists()
throws java.io.IOException
java.io.IOExceptionpublic abstract void wipe()
throws PlayerDataException,
java.io.IOException
PlayerDataException - Thrown if the game data location cannot be accessed or the
data could not be wipedjava.io.IOExceptionpublic FileHandle getFileHandle(java.lang.String... filepath)
FileHandle of a file or directory in the player data locationfilepath - The path to the file. This will be resolved as a path within the player data location.FileHandle instance for file or directorypublic <T> T readXml(java.lang.Class<T> clazz,
java.lang.String... filepath)
throws PlayerDataException
T - The type of Class to readclazz - The object Class to convert the XML intofilepath - The path to the XML file. This will be resolved as a path
within the game data location.PlayerDataException - Thrown if the XML is invalid, the file does not exist or the
game data location cannot be accessed.public <T> void writeXml(T object,
java.lang.String... filepath)
throws PlayerDataException
T - The type of Class to writeobject - The object to be written to the filefilepath - The path to the XML file. This will be resolved as a path
within the game data location.PlayerDataException - Thrown if the game data location cannot be accessed or the
data cannot be written to the file.public <T> T readJson(java.lang.Class<T> clazz,
java.lang.String... filepath)
throws PlayerDataException
T - The type of Class to readclazz - The object Class to convert the JSON intofilepath - The path to the JSON file. This will be resolved as a path
within the game data location.PlayerDataException - Thrown if the XML is invalid, the file does not exist or the
game data location cannot be accessed.public <T> void writeJson(T object,
java.lang.String... filepath)
throws PlayerDataException
T - The type of Class to writeobject - The object to be written to the filefilepath - The path to the JSON file. This will be resolved as a path
within the game data location.PlayerDataException - Thrown if the game data location cannot be accessed or the
data cannot be written to the file.public java.io.DataInputStream readBytes(java.lang.String... filepath)
throws PlayerDataException
DataInputStream.
Note: Ensure that FilterInputStream.close() is called when finished reading.filepath - The path to the file. This will be resolved as a path
within the game data location.DataInputStream to read fromPlayerDataException - Thrown if the file does not existpublic java.io.DataOutputStream writeBytes(java.lang.String... filepath)
throws PlayerDataException
FilterOutputStream.close() is called when finished writing.filepath - The path to the file. This will be resolved as a path
within the game data location.DataOutputStream to write toPlayerDataException - Thrown if the game data location cannot be accessed or the
data cannot be written to the file.public java.lang.String readString(java.lang.String... filepath)
throws PlayerDataException
Stringfilepath - The path to the file. This will be resolved as a path
within the game data location.PlayerDataException - Thrown if the file does not existpublic void writeString(java.lang.String content,
java.lang.String... filepath)
throws PlayerDataException
String to a file in the player data locationcontent - The String to be written to the filefilepath - The path to the file. This will be resolved as a path
within the game data location.PlayerDataException - Thrown if the game data location cannot be accessed or the
data cannot be written to the file.public boolean delete(java.lang.String... path)
throws PlayerDataException
path - The path to the file or directory within the game data locationPlayerDataException - Thrown if the game data location cannot be accessed or the
file/directory could not be deletedpublic boolean hasFile(java.lang.String... filepath)
throws PlayerDataException
filepath - The path to the file within the game data locationPlayerDataException - Thrown if the game data location cannot be accessedpublic boolean hasDirectory(java.lang.String... path)
throws PlayerDataException
path - The path to the directory within the game data locationPlayerDataException - Thrown if the game data location cannot be accessedpublic void createDirectory(java.lang.String... path)
throws PlayerDataException
path - The path to the directory within the game data locationPlayerDataException - Thrown if the game data location cannot be accessed or the
directory could not be createdprotected void ensureDirectoryExistsForFile(java.lang.String... filepath)
throws java.io.IOException,
PlayerDataException
java.io.IOExceptionPlayerDataException