TrueZIP Kernel 7.0-rc2

de.schlichtherle.truezip.fs.archive
Class FsArchiveFileSystem<E extends FsArchiveEntry>

java.lang.Object
  extended by de.schlichtherle.truezip.fs.archive.FsArchiveFileSystem<E>
Type Parameters:
E - The type of the archive entries.
All Implemented Interfaces:
Iterable<FsArchiveFileSystemEntry<E>>
Direct Known Subclasses:
FsReadOnlyArchiveFileSystem

@NotThreadSafe
@DefaultAnnotation(value=edu.umd.cs.findbugs.annotations.NonNull.class)
 class FsArchiveFileSystem<E extends FsArchiveEntry>
extends Object
implements Iterable<FsArchiveFileSystemEntry<E>>

A read/write virtual file system for archive entries.

Author:
Christian Schlichtherle

Nested Class Summary
private static class FsArchiveFileSystem.DefaultEntryTable<E extends FsArchiveEntry>
           
private static class FsArchiveFileSystem.MasterEntryTable<E extends FsArchiveEntry>
          Splits a given path name into its parent path name and base name.
private  class FsArchiveFileSystem.PathLink
          TODO: This implementation yields a potential issue: The state of the file system may be altered between the construction of an instance and the call to the FsArchiveFileSystem.PathLink.run() method, which may render the operation illegal and corrupt the file system.
private static class FsArchiveFileSystem.SegmentLink<E extends FsArchiveEntry>
          A data class which represents a segment for use by FsArchiveFileSystem.PathLink.
private static class FsArchiveFileSystem.Splitter
           
private static class FsArchiveFileSystem.ZipOrTarEntryTable<E extends FsArchiveEntry>
           
 
Field Summary
private  EntryFactory<E> factory
           
private  FsArchiveFileSystem.MasterEntryTable<E> master
           
private  FsArchiveFileSystem.Splitter splitter
           
private  boolean touched
          Whether or not this file system has been modified (touched).
private  LinkedHashSet<FsArchiveFileSystemTouchListener<? super E>> touchListeners
           
 
Constructor Summary
private FsArchiveFileSystem(EntryFactory<E> factory)
           
(package private) FsArchiveFileSystem(EntryFactory<E> factory, EntryContainer<E> archive, Entry rootTemplate)
           
 
Method Summary
(package private)  void addFsArchiveFileSystemTouchListener(FsArchiveFileSystemTouchListener<? super E> listener)
          Adds the given listener to the set of archive file system listeners.
(package private)  E copy(E entry)
           
private  void fix(FsEntryName name)
          Called from a constructor to fix the parent directories of the file system entry identified by name, ensuring that all parent directories of the file system entry exist and that they contain the respective base.
(package private)  FsArchiveFileSystemEntry<E> getEntry(FsEntryName name)
           
(package private)  Set<FsArchiveFileSystemTouchListener<? super E>> getFsArchiveFileSystemTouchListeners()
          Returns a protective copy of the set of archive file system listeners.
(package private)  int getSize()
           
(package private)  boolean isReadOnly()
          Returns true if and only if this archive file system is read-only.
(package private)  boolean isTouched()
          Returns true if and only if this archive file system has been modified since its time of creation.
 boolean isWritable(FsEntryName name)
           
 Iterator<FsArchiveFileSystemEntry<E>> iterator()
           
 FsArchiveFileSystemOperation<E> mknod(FsEntryName name, Entry.Type type, BitField<FsOutputOption> options, Entry template)
          Begins a transaction to create or replace and finally link a chain of one or more archive entries for the given path into this archive file system.
(package private) static
<AE extends FsArchiveEntry>
FsArchiveFileSystem<AE>
newArchiveFileSystem(EntryFactory<AE> factory)
          Returns a new archive file system and ensures its integrity.
(package private) static
<E extends FsArchiveEntry>
FsArchiveFileSystem<E>
newArchiveFileSystem(EntryFactory<E> factory, EntryContainer<E> archive, Entry rootTemplate, boolean readOnly)
          Returns a new archive file system which populates its entries from the given archive and ensures its integrity.
private  FsArchiveFileSystemEntry<E> newEntryChecked(FsEntryName name, Entry.Type type, Entry template)
          Returns a new file system entry for this (virtual) archive file system.
private  FsArchiveFileSystemEntry<E> newEntryUnchecked(FsEntryName name, Entry.Type type, Entry template)
          Like newEntryChecked(path, type, null), but wraps any CharConversionException in an AssertionError.
private static
<E extends FsArchiveEntry>
FsArchiveFileSystem.MasterEntryTable<E>
newMasterEntryTable(FsArchiveFileSystemEntry<E> root, int initialCapacity)
           
(package private)  void removeFsArchiveFileSystemTouchListener(FsArchiveFileSystemTouchListener<? super E> listener)
          Removes the given listener from the set of archive file system listeners.
 void setReadOnly(FsEntryName name)
           
 boolean setTime(FsEntryName name, BitField<Entry.Access> types, long value)
           
private  void touch()
          Ensures that the controller's data structures required to output entries are properly initialized and marks this (virtual) archive file system as touched.
 void unlink(FsEntryName name)
          If this method returns, the file system entry identified by the given path has been successfully deleted from this archive file system.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

splitter

private final FsArchiveFileSystem.Splitter splitter

factory

private final EntryFactory<E extends FsArchiveEntry> factory

master

private final FsArchiveFileSystem.MasterEntryTable<E extends FsArchiveEntry> master

touched

private boolean touched
Whether or not this file system has been modified (touched).


touchListeners

private LinkedHashSet<FsArchiveFileSystemTouchListener<? super E extends FsArchiveEntry>> touchListeners
Constructor Detail

FsArchiveFileSystem

private FsArchiveFileSystem(EntryFactory<E> factory)

FsArchiveFileSystem

FsArchiveFileSystem(EntryFactory<E> factory,
                    EntryContainer<E> archive,
                    @CheckForNull
                    Entry rootTemplate)
Method Detail

newArchiveFileSystem

static <AE extends FsArchiveEntry> FsArchiveFileSystem<AE> newArchiveFileSystem(EntryFactory<AE> factory)
Returns a new archive file system and ensures its integrity. The root directory is created with its last modification time set to the system's current time. The file system is modifiable and marked as touched!

Parameters:
factory - the archive entry factory to use.
Throws:
NullPointerException - If factory is null.

newArchiveFileSystem

static <E extends FsArchiveEntry> FsArchiveFileSystem<E> newArchiveFileSystem(EntryFactory<E> factory,
                                                                              EntryContainer<E> archive,
                                                                              @CheckForNull
                                                                              Entry rootTemplate,
                                                                              boolean readOnly)
Returns a new archive file system which populates its entries from the given archive and ensures its integrity.

First, the entries from the archive are loaded into the file system.

Second, a root directory with the given last modification time is created and linked into the filesystem (so it's never loaded from the archive).

Finally, the file system integrity is checked and fixed: Any missing parent directories are created using the system's current time as their last modification time - existing directories will never be replaced.

Note that the entries in the file system are shared with the given archive entry container.

Parameters:
archive - The archive entry container to read the entries for the population of the archive file system.
factory - the archive entry factory to use.
rootTemplate - The last modification time of the root of the populated file system in milliseconds since the epoch.
readOnly - If and only if true, any subsequent modifying operation on the file system will result in a FsReadOnlyArchiveFileSystemException.
Throws:
NullPointerException - If container, factory or rootTemplate are null.
IllegalArgumentException - If rootTemplate is an instance of FsArchiveFileSystemEntry.

newMasterEntryTable

private static <E extends FsArchiveEntry> FsArchiveFileSystem.MasterEntryTable<E> newMasterEntryTable(FsArchiveFileSystemEntry<E> root,
                                                                                                      int initialCapacity)

fix

private void fix(FsEntryName name)
Called from a constructor to fix the parent directories of the file system entry identified by name, ensuring that all parent directories of the file system entry exist and that they contain the respective base. If a parent directory does not exist, it is created using an unkown time as the last modification time - this is defined to be a ghost directory. If a parent directory does exist, the respective base is added (possibly yet again) and the process is continued.

Parameters:
name - the archive file system entry name.

isReadOnly

boolean isReadOnly()
Returns true if and only if this archive file system is read-only. This method is provided for inheritance - the implementation in this class always returns false.


isTouched

boolean isTouched()
Returns true if and only if this archive file system has been modified since its time of creation.


touch

private void touch()
            throws FsArchiveFileSystemException
Ensures that the controller's data structures required to output entries are properly initialized and marks this (virtual) archive file system as touched.

Throws:
ArchiveReadOnlyExceptionn - If this (virtual) archive file system is read only.
FsArchiveFileSystemException - If the listener vetoed the beforeTouch operation for any reason.

getFsArchiveFileSystemTouchListeners

Set<FsArchiveFileSystemTouchListener<? super E>> getFsArchiveFileSystemTouchListeners()
Returns a protective copy of the set of archive file system listeners.

Returns:
A clone of the set of archive file system listeners.

addFsArchiveFileSystemTouchListener

final void addFsArchiveFileSystemTouchListener(FsArchiveFileSystemTouchListener<? super E> listener)
Adds the given listener to the set of archive file system listeners.

Parameters:
listener - the listener for archive file system events.

removeFsArchiveFileSystemTouchListener

final void removeFsArchiveFileSystemTouchListener(@Nullable
                                                  FsArchiveFileSystemTouchListener<? super E> listener)
Removes the given listener from the set of archive file system listeners.

Parameters:
listener - the listener for archive file system events.

getSize

int getSize()

iterator

public Iterator<FsArchiveFileSystemEntry<E>> iterator()
Specified by:
iterator in interface Iterable<FsArchiveFileSystemEntry<E extends FsArchiveEntry>>

getEntry

@Nullable
final FsArchiveFileSystemEntry<E> getEntry(FsEntryName name)

newEntryUnchecked

private FsArchiveFileSystemEntry<E> newEntryUnchecked(FsEntryName name,
                                                      Entry.Type type,
                                                      @CheckForNull
                                                      Entry template)
Like newEntryChecked(path, type, null), but wraps any CharConversionException in an AssertionError.

Parameters:
name - the archive file system entry name.
type - the type of the archive file system entry to create.
template - the nullable template for the archive file system entry to create.
Throws:
AssertionError - if a CharConversionException occurs. The original exception is wrapped as its cause.

newEntryChecked

private FsArchiveFileSystemEntry<E> newEntryChecked(FsEntryName name,
                                                    Entry.Type type,
                                                    @CheckForNull
                                                    Entry template)
                                                                    throws FsArchiveFileSystemException
Returns a new file system entry for this (virtual) archive file system. This is only a factory method, i.e. the returned file system entry is not yet linked into this (virtual) archive file system.

Parameters:
name - the archive file system entry name.
type - the type of the archive file system entry to create.
template - the nullable template for the archive file system entry to create.
Throws:
FsArchiveFileSystemException
See Also:
mknod(de.schlichtherle.truezip.fs.FsEntryName, de.schlichtherle.truezip.entry.Entry.Type, de.schlichtherle.truezip.util.BitField, de.schlichtherle.truezip.entry.Entry)

copy

final E copy(E entry)

mknod

public FsArchiveFileSystemOperation<E> mknod(FsEntryName name,
                                             Entry.Type type,
                                             BitField<FsOutputOption> options,
                                             @CheckForNull
                                             Entry template)
                                                             throws FsArchiveFileSystemException
Begins a transaction to create or replace and finally link a chain of one or more archive entries for the given path into this archive file system.

To commit the transaction, you need to call FsArchiveFileSystemOperation.run() on the returned object, which will mark this archive file system as touched and set the last modification time of the created and linked archive file system entries to the system's current time at the moment of the call to this method.

Parameters:
name - the archive file system entry name.
type - the type of the archive file system entry to create.
options - if CREATE_PARENTS is set, any missing parent directories will be created and linked into this file system with its last modification time set to the system's current time.
template - if not null, then the archive file system entry at the end of the chain shall inherit as much properties from this entry as possible - with the exception of its name and type.
Returns:
A new archive file system operation on a chain of one or more archive file system entries for the given path name which will be linked into this archive file system upon a call to its FsArchiveFileSystemOperation.run() method.
Throws:
NullPointerException - if path or type are null.
ArchiveReadOnlyExceptionn - If this archive file system is read only.
FsArchiveFileSystemException - If one of the following is true:
  • The file system is read only.
  • name contains characters which are not supported by the file system.
  • TODO: type is not FILE or DIRECTORY.
  • The entry already exists and either the option FsOutputOption.EXCLUSIVE is set or the entry is a directory.
  • The entry exists as a different type.
  • A parent entry exists but is not a directory.
  • A parent entry is missing and createParents is false.

unlink

public void unlink(FsEntryName name)
            throws FsArchiveFileSystemException
If this method returns, the file system entry identified by the given path has been successfully deleted from this archive file system. If the file system entry is a directory, it must be empty for successful deletion.

Parameters:
name - the archive file system entry name.
Throws:
ArchiveReadOnlyExceptionn - If this (virtual) archive file system is read-only.
FsArchiveFileSystemException - If the operation fails for some other reason.

setTime

public boolean setTime(FsEntryName name,
                       BitField<Entry.Access> types,
                       long value)
                throws FsArchiveFileSystemException
Throws:
FsArchiveFileSystemException

isWritable

public boolean isWritable(FsEntryName name)

setReadOnly

public void setReadOnly(FsEntryName name)
                 throws FsArchiveFileSystemException
Throws:
FsArchiveFileSystemException

TrueZIP Kernel 7.0-rc2

Copyright © 2005-2011 Schlichtherle IT Services. All Rights Reserved.