|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object de.hpi.fgis.dude.util.data.storage.AbstractDuDeStorage<T> de.hpi.fgis.dude.util.data.storage.FileBasedStorage<T>
T
- The Jsonable
type whose instances are stored.public class FileBasedStorage<T extends Jsonable>
FileBasedStorage
stores Jsonable
instances in files.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class de.hpi.fgis.dude.util.data.storage.AbstractDuDeStorage |
---|
AbstractDuDeStorage.AbstractJsonableWriter<T extends Jsonable> |
Field Summary | |
---|---|
static String |
JSON_FILE_EXTENSION
The file extension that is used for each file. |
Constructor Summary | |
---|---|
|
FileBasedStorage(Class<T> type,
File f)
Initializes a FileBasedStorage instance with the type information, the underlying file, and the initial content. |
protected |
FileBasedStorage(Class<T> type,
File f,
Collection<T> initialContent)
Initializes a FileBasedStorage instance with the type information, the underlying file, and the initial content. |
|
FileBasedStorage(Class<T> type,
String name)
Initializes a FileBasedStorage instance with the passed type information and a name. |
|
FileBasedStorage(Class<T> type,
String name,
Collection<T> initialContent)
Initializes a FileBasedStorage instance with the passed type information, its name, and the initial content. |
|
FileBasedStorage(Class<T> type,
String dir,
String name)
Initializes a FileBasedStorage instance with the type information, a directory and its name. |
|
FileBasedStorage(Class<T> type,
String dir,
String name,
Collection<T> initialContent)
Initializes a FileBasedStorage instance with the type information, a directory, its name, and the initial content. |
|
FileBasedStorage(String name)
Initializes a FileBasedStorage instance with the passed name. |
|
FileBasedStorage(String name,
Collection<T> initialContent)
Initializes a FileBasedStorage instance with the passed name, and the initial content. |
|
FileBasedStorage(String dir,
String name)
Initializes a FileBasedStorage instance with the type information, a directory and its name. |
|
FileBasedStorage(String dir,
String name,
Collection<T> initialContent)
Initializes a FileBasedStorage instance with the type information, a directory, its name, and the initial content. |
Method Summary | |
---|---|
void |
delete()
Deletes the underlying file. |
protected void |
generateEmptyJsonFile()
Overwrites any existing file and initializes a new one containing an empty Json array. |
File |
getFile()
Returns the underlying file. |
JsonableReader<T> |
getReader()
Returns the JsonableReader that can be used to access the content of this DuDeStorage . |
JsonableWriter<T> |
getWriter()
Returns the JsonableWriter that can be used to add instances to this DuDeStorage . |
void |
renameTo(String newFilename)
Renames the underlying file. |
int |
size()
Returns the number of instances that are contained. |
Methods inherited from class de.hpi.fgis.dude.util.data.storage.AbstractDuDeStorage |
---|
disableFormattedJson, enableFormattedJson, isFormattedJson |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String JSON_FILE_EXTENSION
Constructor Detail |
---|
public FileBasedStorage(String name) throws IOException
FileBasedStorage
instance with the passed name. The underlying file will be placed in the default directory. The
reader will return JsonValue
instances.
name
- The name of the underlying file.
IOException
- If an error occurs while initializing the file.GlobalConfig#getWorkingDirectory()}
public FileBasedStorage(Class<T> type, String name) throws IOException
FileBasedStorage
instance with the passed type information and a name. The underlying file will be placed in the
default directory.
type
- The type of instances that are stored. This type is equal to the generic type of this instance.name
- The name of the underlying file.
IOException
- If an error occurs while initializing the file.GlobalConfig#getWorkingDirectory()}
public FileBasedStorage(String name, Collection<T> initialContent) throws IOException
FileBasedStorage
instance with the passed name, and the initial content. The underlying file will be placed in the
default directory. The initial content will be overwritten if getWriter()
is called. The return type of the JsonableReader
is
JsonValue
.
name
- The name of the underlying file.initialContent
- The initial content that shall be added to that storage.
IOException
- If an error occurs while initializing the file.GlobalConfig#getWorkingDirectory()}
public FileBasedStorage(Class<T> type, String name, Collection<T> initialContent) throws IOException
FileBasedStorage
instance with the passed type information, its name, and the initial content. The underlying file
will be placed in the default directory. The initial content will be overwritten if getWriter()
is called.
type
- The type of instances that are stored. This type is equal to the generic type of this instance.name
- The name of the underlying file.initialContent
- The initial content that shall be added to that storage.
IOException
- If an error occurs while initializing the file.GlobalConfig#getWorkingDirectory()}
public FileBasedStorage(String dir, String name) throws IOException
FileBasedStorage
instance with the type information, a directory and its name. The return type of the
JsonableReader
is JsonValue
since no type is passed.
dir
- The directory where the file shall be placed in.name
- The name of the underlying file.
IOException
- If an error occurs while initializing the file.public FileBasedStorage(Class<T> type, String dir, String name) throws IOException
FileBasedStorage
instance with the type information, a directory and its name.
type
- The type of instances that are stored. This type is equal to the generic type of this instance.dir
- The directory where the file shall be placed in.name
- The name of the underlying file.
IOException
- If an error occurs while initializing the file.public FileBasedStorage(String dir, String name, Collection<T> initialContent) throws IOException
FileBasedStorage
instance with the type information, a directory, its name, and the initial content. The initial
content will be overwritten if getWriter()
is called.The return type of the JsonableReader
is JsonValue
since no type
is passed.
dir
- The directory where the file shall be placed in.name
- The name of the underlying file.initialContent
- The initial content that shall be added to that storage.
IOException
- If an error occurs while initializing the file.public FileBasedStorage(Class<T> type, String dir, String name, Collection<T> initialContent) throws IOException
FileBasedStorage
instance with the type information, a directory, its name, and the initial content. The initial
content will be overwritten if getWriter()
is called.
type
- The type of instances that are stored. This type is equal to the generic type of this instance.dir
- The directory where the file shall be placed in.name
- The name of the underlying file.initialContent
- The initial content that shall be added to that storage.
IOException
- If an error occurs while initializing the file.protected FileBasedStorage(Class<T> type, File f, Collection<T> initialContent) throws IOException
FileBasedStorage
instance with the type information, the underlying file, and the initial content. The initial
content will be overwritten getWriter()
is called.
type
- The type of instances that are stored. This type is equal to the generic type of this instance.f
- The underlying file.initialContent
- The initial content that shall be added to that storage.
IOException
- If an error occurs while initializing the file.public FileBasedStorage(Class<T> type, File f) throws IOException
FileBasedStorage
instance with the type information, the underlying file, and the initial content. The initial
content will be overwritten getWriter()
is called.
type
- The type of instances that are stored. This type is equal to the generic type of this instance.f
- The underlying file.
IOException
- If an error occurs while initializing the file.Method Detail |
---|
protected void generateEmptyJsonFile() throws IOException
IOException
- If an error occurs while initializing the new file.public JsonableReader<T> getReader()
JsonReadable
JsonableReader
that can be used to access the content of this DuDeStorage
.
JsonableReader
for iterating over the content.public JsonableWriter<T> getWriter() throws IOException
JsonWritable
JsonableWriter
that can be used to add instances to this DuDeStorage
.
JsonableWriter
for adding content to this storage.
IOException
- If an error occurs while writing data.public int size()
JsonReadable
public void renameTo(String newFilename)
newFilename
- The new name of the file.public File getFile()
public void delete()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |