TrueZIP Kernel 7.0-rc2

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

java.lang.Object
  extended by de.schlichtherle.truezip.fs.FsController<FsConcurrentModel>
      extended by de.schlichtherle.truezip.fs.archive.FsArchiveController<E>
Type Parameters:
E - The type of the archive entries.
Direct Known Subclasses:
FsFileSystemArchiveController

@NotThreadSafe
@DefaultAnnotation(value=edu.umd.cs.findbugs.annotations.NonNull.class)
public abstract class FsArchiveController<E extends FsArchiveEntry>
extends FsController<FsConcurrentModel>

An abstract archive controller which is the super class for any archive controller, providing all the essential services required for accessing an archive file. It encapsulates all the code which is not depending on a particular archive update strategy and the corresponding state of the controller.

Each instance of this class manages an archive file - the target file - in order to allow random access to it as if it were a regular directory in its parent file system.

Note that in general all of the methods in this class are reentrant on exceptions. This is important because client applications may repeatedly call them. Of course, depending on the calling context, some or all of the archive file's data may be lost in this case.

Author:
Christian Schlichtherle

Nested Class Summary
private  class FsArchiveController.Input
           
private  class FsArchiveController.Output
           
private static class FsArchiveController.ProxyEntry
           
 
Field Summary
private static BitField<FsOutputOption> AUTO_MOUNT_OPTIONS
           
private static Logger logger
           
private  FsConcurrentModel model
           
private static BitField<FsSyncOption> UNLINK_SYNC_OPTIONS
           
 
Constructor Summary
protected FsArchiveController(FsConcurrentModel model)
          Constructs a new basic archive controller.
 
Method Summary
(package private)  FsArchiveFileSystem<E> autoMount()
           
(package private) abstract  FsArchiveFileSystem<E> autoMount(boolean autoCreate, BitField<FsOutputOption> options)
          Returns the (virtual) archive file system mounted from the target archive file.
(package private) abstract  boolean autoSync(FsEntryName name, Entry.Access intention)
          Synchronizes the archive file only if the archive file has new data for the file system entry with the given path path.
 FsEntry getEntry(FsEntryName name)
           
 InputSocket<?> getInputSocket(FsEntryName name, BitField<FsInputOption> options)
          Returns an input socket for reading the contents of the entry addressed by the given name from the file system.
(package private) abstract  InputSocket<?> getInputSocket(String name)
           
 FsConcurrentModel getModel()
          Returns the file system model.
(package private) abstract  OutputSocket<?> getOutputSocket(E entry)
           
 OutputSocket<?> getOutputSocket(FsEntryName name, BitField<FsOutputOption> options, Entry template)
          Returns an output socket for writing the contents of the entry addressed by the given name to the file system.
 boolean isReadable(FsEntryName name)
           
 boolean isReadOnly()
           
 boolean isWritable(FsEntryName name)
           
 void mknod(FsEntryName name, Entry.Type type, BitField<FsOutputOption> options, Entry template)
          Creates or replaces and finally links a chain of one or more entries for the given entry name into the file system.
 void setReadOnly(FsEntryName name)
           
 boolean setTime(FsEntryName name, BitField<Entry.Access> types, long value)
           
 void unlink(FsEntryName name)
           
 
Methods inherited from class de.schlichtherle.truezip.fs.FsController
equals, getClosedIcon, getOpenIcon, getParent, hashCode, sync, sync, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

logger

private static final Logger logger

AUTO_MOUNT_OPTIONS

private static final BitField<FsOutputOption> AUTO_MOUNT_OPTIONS

UNLINK_SYNC_OPTIONS

private static final BitField<FsSyncOption> UNLINK_SYNC_OPTIONS

model

private final FsConcurrentModel model
Constructor Detail

FsArchiveController

protected FsArchiveController(FsConcurrentModel model)
Constructs a new basic archive controller.

Parameters:
model - the non-null archive model.
Method Detail

getModel

public final FsConcurrentModel getModel()
Description copied from class: FsController
Returns the file system model.

Specified by:
getModel in class FsController<FsConcurrentModel>

autoMount

final FsArchiveFileSystem<E> autoMount()
                                                       throws IOException
Throws:
IOException

autoMount

abstract FsArchiveFileSystem<E> autoMount(boolean autoCreate,
                                          BitField<FsOutputOption> options)
                                                          throws IOException
Returns the (virtual) archive file system mounted from the target archive file. This method is reentrant with respect to any exceptions it may throw.

Warning: Either the read or the write lock of this controller must be acquired while this method is called! If only a read lock is acquired, but a write lock is required, this method will temporarily release all locks, so any preconditions must be checked again upon return to protect against concurrent modifications!

Parameters:
autoCreate - If the archive file does not exist and this is true, a new file system with only a (virtual) root directory is created with its last modification time set to the system's current time.
Returns:
A valid archive file system - null is never returned.
Throws:
FsFalsePositiveException
IOException

isReadOnly

public final boolean isReadOnly()
                         throws IOException
Specified by:
isReadOnly in class FsController<FsConcurrentModel>
Throws:
IOException

getEntry

public final FsEntry getEntry(FsEntryName name)
                       throws IOException
Specified by:
getEntry in class FsController<FsConcurrentModel>
Throws:
IOException

isReadable

public final boolean isReadable(FsEntryName name)
                         throws IOException
Specified by:
isReadable in class FsController<FsConcurrentModel>
Throws:
IOException

isWritable

public final boolean isWritable(FsEntryName name)
                         throws IOException
Specified by:
isWritable in class FsController<FsConcurrentModel>
Throws:
IOException

setReadOnly

public final void setReadOnly(FsEntryName name)
                       throws IOException
Specified by:
setReadOnly in class FsController<FsConcurrentModel>
Throws:
IOException

setTime

public final boolean setTime(FsEntryName name,
                             BitField<Entry.Access> types,
                             long value)
                      throws IOException
Specified by:
setTime in class FsController<FsConcurrentModel>
Throws:
IOException

getInputSocket

public final InputSocket<?> getInputSocket(FsEntryName name,
                                           BitField<FsInputOption> options)
Description copied from class: FsController
Returns an input socket for reading the contents of the entry addressed by the given name from the file system.

Specified by:
getInputSocket in class FsController<FsConcurrentModel>
Parameters:
name - a file system entry name.
Returns:
An InputSocket.

getInputSocket

abstract InputSocket<?> getInputSocket(String name)
                                throws IOException
Throws:
IOException

getOutputSocket

public final OutputSocket<?> getOutputSocket(FsEntryName name,
                                             BitField<FsOutputOption> options,
                                             @CheckForNull
                                             Entry template)
Description copied from class: FsController
Returns an output socket for writing the contents of the entry addressed by the given name to the file system. If template is not null, then the output entry shall have as many of its properties copied as reasonable, e.g. the last modification time.

Specified by:
getOutputSocket in class FsController<FsConcurrentModel>
Parameters:
name - a file system entry name.
template - a nullable template for the properties of the output entry.
Returns:
An OutputSocket.

getOutputSocket

abstract OutputSocket<?> getOutputSocket(E entry)
                                  throws IOException
Throws:
IOException

mknod

public final void mknod(FsEntryName name,
                        Entry.Type type,
                        BitField<FsOutputOption> options,
                        @CheckForNull
                        Entry template)
                 throws IOException
Description copied from class: FsController
Creates or replaces and finally links a chain of one or more entries for the given entry name into the file system.

Specified by:
mknod in class FsController<FsConcurrentModel>
Parameters:
name - the file system entry name.
type - the file system entry type.
options - the file system output 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 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.
Throws:
IOException - for some other I/O related reason, including but not exclusively upon one or more of the following conditions:
  • The file system is read only.
  • name contains characters which are not supported by the file system.
  • 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 IOException
Specified by:
unlink in class FsController<FsConcurrentModel>
Throws:
IOException

autoSync

abstract boolean autoSync(FsEntryName name,
                          @CheckForNull
                          Entry.Access intention)
                   throws FsSyncException,
                          FsException
Synchronizes the archive file only if the archive file has new data for the file system entry with the given path path.

Warning: As a side effect, all data structures may get reset (filesystem, entries, streams, etc.)! This method may require synchronization on the write lock!

Parameters:
name - the non-null entry name.
intention - the intended operation on the entry. If null, a pure file system operation with no I/O is intended.
Returns:
Whether or not a synchronization has been performed.
Throws:
IOException - if any exceptional condition occurs throughout the synchronization of the target archive file.
FsSyncException
FsException
See Also:
FsController.sync(de.schlichtherle.truezip.util.BitField)

TrueZIP Kernel 7.0-rc2

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