org.planx.xmlstore.io
Class LocalFileSystem

java.lang.Object
  extended by org.planx.xmlstore.io.LocalFileSystem
All Implemented Interfaces:
FileSystem

public class LocalFileSystem
extends Object
implements FileSystem

An implementation of FileSystem that uses an on-disk file. It is not synchronized and should thus be synchronized externally.

Author:
Thomas Ambus

Constructor Summary
LocalFileSystem(String name)
          Creates a new file system with the specified file name or recreates a previously persisted one.
 
Method Summary
 LocalLocator all()
          Returns a LocalLocator to all content currently in this FileSystem.
 LocalLocator allocate()
          Returns a LocalLocator to a free write position that can hold size number of bytes.
 LocalLocator allocate(int size)
           
 LocalLocator allocate(int size, FileSystemIdentifier id)
           
 void close()
          Closes the file system and releases all resources.
 void copy(FileSystem fs, LocalLocator fromLoc, LocalLocator locTo)
          Copies the data at fromLoc in the specified FileSystem to toLoc in this FileSystem.
 FileSystemIdentifier currentIdentifier()
           
 void free(LocalLocator l)
          Frees the space occupied by the specified LocalLocator.
 DataInput getInput(LocalLocator l)
          Positions the input at the specified location and returns a DataInput for reading.
 DataOutput getOutput(LocalLocator l)
          Positions the output at the specified location and returns a DataOutpu for writing.
 boolean isContained(LocalLocator loc)
          Returns true if the specified LocalLocator originates from this FileSystem.
 long size()
          Returns the size of the FileSystem.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

LocalFileSystem

public LocalFileSystem(String name)
                throws IOException
Creates a new file system with the specified file name or recreates a previously persisted one.

Throws:
IOException
Method Detail

currentIdentifier

public FileSystemIdentifier currentIdentifier()
Specified by:
currentIdentifier in interface FileSystem

size

public long size()
          throws IOException
Description copied from interface: FileSystem
Returns the size of the FileSystem.

Specified by:
size in interface FileSystem
Throws:
IOException

close

public void close()
           throws IOException
Description copied from interface: FileSystem
Closes the file system and releases all resources.

Specified by:
close in interface FileSystem
Throws:
IOException

copy

public void copy(FileSystem fs,
                 LocalLocator fromLoc,
                 LocalLocator locTo)
          throws IOException,
                 UnknownLocatorException
Description copied from interface: FileSystem
Copies the data at fromLoc in the specified FileSystem to toLoc in this FileSystem.

Specified by:
copy in interface FileSystem
Throws:
IOException
UnknownLocatorException

getInput

public DataInput getInput(LocalLocator l)
                   throws IOException,
                          UnknownLocatorException
Description copied from interface: FileSystem
Positions the input at the specified location and returns a DataInput for reading. The DataInput is shared so if multiple threads operate on the same FileSystem concurrently, external synchronization should be used.

Specified by:
getInput in interface FileSystem
Throws:
IOException
UnknownLocatorException

getOutput

public DataOutput getOutput(LocalLocator l)
                     throws IOException,
                            UnknownLocatorException
Description copied from interface: FileSystem
Positions the output at the specified location and returns a DataOutpu for writing. Note, that this can overwrite existing data. The DataInput is shared so if multiple threads operate on the same FileSystem concurrently, external synchronization should be used. When writing new data FileSystem.allocate() should be called first.

Specified by:
getOutput in interface FileSystem
Throws:
IOException
UnknownLocatorException

all

public LocalLocator all()
                 throws IOException
Description copied from interface: FileSystem
Returns a LocalLocator to all content currently in this FileSystem.

Specified by:
all in interface FileSystem
Throws:
IOException

allocate

public LocalLocator allocate()
                      throws IOException
Description copied from interface: FileSystem
Returns a LocalLocator to a free write position that can hold size number of bytes.

Specified by:
allocate in interface FileSystem
Throws:
IOException

allocate

public LocalLocator allocate(int size)
                      throws IOException
Specified by:
allocate in interface FileSystem
Throws:
IOException

allocate

public LocalLocator allocate(int size,
                             FileSystemIdentifier id)
                      throws IOException
Specified by:
allocate in interface FileSystem
Throws:
IOException

free

public void free(LocalLocator l)
          throws IOException,
                 UnknownLocatorException
Description copied from interface: FileSystem
Frees the space occupied by the specified LocalLocator.

Specified by:
free in interface FileSystem
Throws:
IOException
UnknownLocatorException

isContained

public boolean isContained(LocalLocator loc)
Description copied from interface: FileSystem
Returns true if the specified LocalLocator originates from this FileSystem.

Specified by:
isContained in interface FileSystem

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2010. All Rights Reserved.