com.zipxap.vfs
Class LowLevelManager

java.lang.Object
  extended by com.zipxap.vfs.LowLevelManager

public class LowLevelManager
extends java.lang.Object

Provides random access to the archive file. This is ABSOLUTELY single threaded. A VFS file begins "VFS[version][compressed][password hint][expected text]", where the version is two bytes, compressed is either 'C' for compressed or 'U' for uncompressed, 128 bytes of password hint, and 128 bytes of expected text.

MilestoneWhoDate, Time
Initial VersionK PenroseJune 2009

** Note that this table is not intended as an exhaustive list of subtle changes. It is intended to list changes that break the compatibility of older code, or major enhancements/rewrites


Method Summary
 void addReindexListener(VFSReindexListener listener)
          Add a reindex listener
 void close()
          Closes this random access file stream and releases any system resources associated with the stream.
 void copyArchive(java.io.File outputFile, CipherSettings cipherSettings)
          Create a new copy of this archive.
 Entry createEntry(Entry parent, java.lang.String name, byte[] data)
          This method is used to create a file entry.
 Entry createEntry(Entry parent, java.lang.String name, EntryType entryType)
          This method is used to save an entry that has no associated data (such as a repository), but it can also be used when creating a new File that does yet have data associated with it.
 Entry createEntry(Entry parent, java.lang.String name, java.io.File sourceFile)
          This method is used to create a file entry.
 Entry createEntry(Entry parent, java.lang.String name, java.io.InputStream inputStream)
          This method is used to create a file entry.
 void defrag()
          This does a hard-core defrag of this virtual file system by copying it, entry by entry, to a new file, and then replacing the original file with the copy.
 void deleteEntry(Entry entry, boolean recursive)
          Delete the specified entry.
 java.io.File getArchiveFile()
           
 VFSSector getEmptySector(SectorType sectorType)
          This method retrieves an empty sector from the list, changes its type from empty to non-empty, and removes it from the list of empty sectors.
 java.util.List<Entry> getEntries()
           
 long getFirstSectorLocation()
           
 java.lang.String getPasswordHint()
           
 java.io.RandomAccessFile getRandomAccessFile()
           
 VFSReindexListener[] getReindexListeners()
          Get all of the reindex listeners.
 java.lang.String getUserId()
           
 boolean isClosed()
          Determine if the RandomAccessFile resource associated with this LowLevelManager has been closed.
 boolean isCompressed()
          Determine if the File associated with this instance of the LowLevelManager is using (GZIP) compression.
static boolean isLocked(java.io.File archiveFile)
          Determine if the specified archive file has already been locked by another instance of the VFS.
 boolean isValidated()
           
 boolean isVirtualFileSystem()
          Determine if the File associated with this instance of the LowLevelManager is a valid virtual file system.
static void removeLock(java.io.File archiveFile)
          Be careful with this method, it does no checking and is thus very dangerous.
 boolean removeReindexListener(VFSReindexListener listener)
          Remove a reindex listener.
 void setCipherSettings(CipherSettings newCipherSettings)
          Change the encryption of this vfs.
 void setPassword(java.lang.String password)
           
 void setPasswordHint(java.lang.String passwordHint)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

isLocked

public static boolean isLocked(java.io.File archiveFile)
Determine if the specified archive file has already been locked by another instance of the VFS.

Returns:
true if the specified archive file has already been locked by another instance of the VFS, else false.

removeLock

public static void removeLock(java.io.File archiveFile)
Be careful with this method, it does no checking and is thus very dangerous.

Parameters:
archiveFile -

createEntry

public Entry createEntry(Entry parent,
                         java.lang.String name,
                         EntryType entryType)
This method is used to save an entry that has no associated data (such as a repository), but it can also be used when creating a new File that does yet have data associated with it.

Parameters:
parent -
name -
Returns:
the newly created Entry

createEntry

public Entry createEntry(Entry parent,
                         java.lang.String name,
                         java.io.File sourceFile)
This method is used to create a file entry.

Parameters:
parent -
name -
sourceFile -

createEntry

public Entry createEntry(Entry parent,
                         java.lang.String name,
                         java.io.InputStream inputStream)
This method is used to create a file entry.

Parameters:
parent -
name -
inputStream -

createEntry

public Entry createEntry(Entry parent,
                         java.lang.String name,
                         byte[] data)
This method is used to create a file entry.

Parameters:
parent -
name -
data -
Returns:
the newly created Entry

deleteEntry

public void deleteEntry(Entry entry,
                        boolean recursive)
Delete the specified entry. If this entry is a repository that has child repositories or files, then the recursive argument must be true, else an exception will be thrown.

Parameters:
entry -
recursive -

isValidated

public boolean isValidated()

setCipherSettings

public void setCipherSettings(CipherSettings newCipherSettings)
Change the encryption of this vfs.

Parameters:
newCipherSettings -

defrag

public void defrag()
This does a hard-core defrag of this virtual file system by copying it, entry by entry, to a new file, and then replacing the original file with the copy. It creates


setPassword

public void setPassword(java.lang.String password)

copyArchive

public void copyArchive(java.io.File outputFile,
                        CipherSettings cipherSettings)
Create a new copy of this archive. This method has the side effect of defragmenting a virtual file system.

Parameters:
outputFile -
cipherSettings -

getPasswordHint

public java.lang.String getPasswordHint()

setPasswordHint

public void setPasswordHint(java.lang.String passwordHint)

close

public void close()
Closes this random access file stream and releases any system resources associated with the stream. A closed random access file cannot perform input or output operations and cannot be reopened.


getEntries

public java.util.List<Entry> getEntries()
Returns:
the entries within this VFS archive

getUserId

public java.lang.String getUserId()
Returns:
the User ID associated with this instance of the LowLevelManager

getArchiveFile

public java.io.File getArchiveFile()
Returns:
the archive File associated with this instance of the LowLevelManager

isClosed

public boolean isClosed()
Determine if the RandomAccessFile resource associated with this LowLevelManager has been closed.

Returns:
true if the RandomAccessFile associated with this LowLevelManager has been closed, else false.

getRandomAccessFile

public java.io.RandomAccessFile getRandomAccessFile()
Returns:
the RandomAccessFile associated with this instance of the LowLevelManager

getEmptySector

public VFSSector getEmptySector(SectorType sectorType)
This method retrieves an empty sector from the list, changes its type from empty to non-empty, and removes it from the list of empty sectors. If it doesn't get used, put it back or else you will develop a file size leak.

Returns:
a sector that can be used to write data

isVirtualFileSystem

public boolean isVirtualFileSystem()
Determine if the File associated with this instance of the LowLevelManager is a valid virtual file system.

Returns:
true if the File associated with this instance of the LowLevelManager is a valid virtual file system, else false.

isCompressed

public boolean isCompressed()
Determine if the File associated with this instance of the LowLevelManager is using (GZIP) compression.

Returns:
true if the File associated with this instance of the LowLevelManager is using (GZIP) compression, else false.

getFirstSectorLocation

public long getFirstSectorLocation()

addReindexListener

public void addReindexListener(VFSReindexListener listener)
Add a reindex listener

Parameters:
listener -

getReindexListeners

public VFSReindexListener[] getReindexListeners()
Get all of the reindex listeners.

Returns:
An array of VFSReindexListener objects.

removeReindexListener

public boolean removeReindexListener(VFSReindexListener listener)
Remove a reindex listener.

Parameters:
listener -
Returns:
true if the specified Listener was registered to this LowLevelManager, and was in fact removed. false is returned if the specified Listener was not registered to this LowLevelManager.