|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
ObjectStructuredFile
public class StructuredFile
A simple structured file with a flat top-level directory. Subfiles can be added to an existing file.
Nested Class Summary | |
---|---|
private class |
StructuredFile.Directory
Maintains the directory of files within a structured file. |
private class |
StructuredFile.DirEntry
A single entry in a Directory |
Field Summary | |
---|---|
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. |
Constructor Summary | |
---|---|
private |
StructuredFile(File file,
boolean create)
Instances should never be created by outside parties, so the constructor is strictly private. |
Method Summary | |
---|---|
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. |
Methods inherited from class Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
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
Constructor Detail |
---|
private StructuredFile(File file, boolean create) throws IOException
IOException
Method Detail |
---|
public String getSystemId()
getSystemId
in interface StructuredStore
private void readHeader() throws IOException
IOException
public static StructuredFile create(File file) throws IOException
file
- The file path to write to.
IOException
public static StructuredFile open(File file) throws FileNotFoundException, IOException
file
- The file to open.
FileNotFoundException
- If the file doesn't exist.
IOException
public SubStoreWriter createSubStore(String name) throws IOException
createSubStore
in interface StructuredStore
name
- Name of the sub-file to create. Must not exist.
IOException
public SubStoreReader openSubStore(String name) throws IOException
openSubStore
in interface StructuredStore
name
- Name of pre-existing subfile to open.
IOException
void closeReader(SubFileReader subfile) throws IOException
subfile
- The sub-file reader being closed.
IOException
void closeWriter(SubFileWriter subfile) throws IOException
subfile
- The sub-file being closed.
IOException
public void setUserVersion(String ver) throws IOException
getUserVersion()
.
setUserVersion
in interface StructuredStore
ver
- The version number to set.
IOException
public String getUserVersion()
setUserVersion(String)
.
getUserVersion
in interface StructuredStore
public void close() throws IOException
close
in interface StructuredStore
IOException
public void delete() throws IOException
delete
in interface StructuredStore
IOException
private void eraseDirectory() throws IOException
IOException
private void writeDirectory() throws IOException
IOException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |