public class StructuredFile extends Object implements StructuredStore
| Modifier and Type | Class and Description |
|---|---|
private class |
StructuredFile.Directory
Maintains the directory of files within a structured file.
|
private class |
StructuredFile.DirEntry
A single entry in a Directory
|
| Modifier and Type | Field and Description |
|---|---|
private StructuredFile.DirEntry |
creatingEnt
Directory entry of the sub-file being created (if
creatingSubfile is true). |
private SubFileWriter |
creatingSubfile
True when creating a sub-file; enforces the rule that only one sub-file
may be created at a time.
|
(package private) Object |
curSubFile
The sub-file that last accessed the file.
|
private StructuredFile.Directory |
dir
Current subfile directory
|
private int |
dirPos
File position of the subfile directory (zero if the directory has been
erased)
|
private File |
file
Actual file path of the structured file
|
private static HashMap |
fileMap
Map of currently open Structured files.
|
private int |
openCount
Number of currently open Structured files
|
private LinkedList |
openSubfiles
List of currently opened subfiles
|
private RandomAccessFile |
realFile
Used to read/write the disk file
|
static Tester |
tester
Regression test to make sure the code works properly.
|
| Modifier | Constructor and Description |
|---|---|
private |
StructuredFile(File file,
boolean create)
Instances should never be created by outside parties, so the constructor
is strictly private.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes the file.
|
(package private) void |
closeReader(SubFileReader subfile)
Called by a subfile reader when its close() method is called.
|
(package private) void |
closeWriter(SubFileWriter subfile)
Called by a subfile when its close() method is called.
|
static StructuredFile |
create(File file)
Create a structured file from scratch.
|
SubStoreWriter |
createSubStore(String name)
Create a new sub-file with the specified name.
|
void |
delete()
Close and delete the entire structured file
|
private void |
eraseDirectory()
Gets rid of the directory at the end of the file, in preparation for
overwriting it with a new subfile.
|
String |
getSystemId()
Get the full path to the file
|
String |
getUserVersion()
Gets the user version (if any) set by
setUserVersion(String). |
static StructuredFile |
open(File file)
Open an existing structured file.
|
SubStoreReader |
openSubStore(String name)
Opens a pre-existing subfile for read (or write).
|
private void |
readHeader()
Reads the file header and directory of the structured file.
|
void |
setUserVersion(String ver)
Sets a user-defined version number for the store.
|
private void |
writeDirectory()
Writes the current directory at the end of the file.
|
private File file
private RandomAccessFile realFile
private int dirPos
private StructuredFile.Directory dir
private SubFileWriter creatingSubfile
private StructuredFile.DirEntry creatingEnt
creatingSubfile is true).private LinkedList openSubfiles
Object curSubFile
private int openCount
private static HashMap fileMap
public static final Tester tester
private StructuredFile(File file,
boolean create)
throws IOException
IOExceptionpublic String getSystemId()
getSystemId in interface StructuredStoreprivate void readHeader()
throws IOException
IOExceptionpublic static StructuredFile create(File file) throws IOException
file - The file path to write to.IOExceptionpublic static StructuredFile open(File file) throws FileNotFoundException, IOException
file - The file to open.FileNotFoundException - If the file doesn't exist.IOExceptionpublic SubStoreWriter createSubStore(String name) throws IOException
createSubStore in interface StructuredStorename - Name of the sub-file to create. Must not exist.IOExceptionpublic SubStoreReader openSubStore(String name) throws IOException
openSubStore in interface StructuredStorename - Name of pre-existing subfile to open.IOExceptionvoid closeReader(SubFileReader subfile) throws IOException
subfile - The sub-file reader being closed.IOExceptionvoid closeWriter(SubFileWriter subfile) throws IOException
subfile - The sub-file being closed.IOExceptionpublic void setUserVersion(String ver)
throws IOException
getUserVersion().setUserVersion in interface StructuredStorever - The version number to set.IOExceptionpublic String getUserVersion()
setUserVersion(String).getUserVersion in interface StructuredStorepublic void close()
throws IOException
close in interface StructuredStoreIOExceptionpublic void delete()
throws IOException
delete in interface StructuredStoreIOExceptionprivate void eraseDirectory()
throws IOException
IOExceptionprivate void writeDirectory()
throws IOException
IOException