TrueZIP 6.8.3

de.schlichtherle.io
Class UpdatingArchiveController

java.lang.Object
  extended by de.schlichtherle.io.ArchiveController
      extended by de.schlichtherle.io.ArchiveFileSystemController
          extended by de.schlichtherle.io.UpdatingArchiveController
All Implemented Interfaces:
Archive, Entry

final class UpdatingArchiveController
extends ArchiveFileSystemController

This archive controller implements the mounting/unmounting strategy by performing a full update of the target archive file.

Since:
TrueZIP 6.0
Author:
Christian Schlichtherle

Nested Class Summary
 
Nested classes/interfaces inherited from class de.schlichtherle.io.ArchiveController
ArchiveController.ArchiveEntryFalsePositiveException, ArchiveController.ArchiveEntryNotFoundException, ArchiveController.ArchiveFileNotFoundException, ArchiveController.DirectoryArchiveEntryFalsePositiveException, ArchiveController.FalsePositiveException, ArchiveController.FileArchiveEntryFalsePositiveException, ArchiveController.RfsEntryFalsePositiveException
 
Field Summary
private static String CLASS_NAME
           
private  InputArchive inArchive
          An InputArchive object used to mount the virtual file system and read the entries from the archive file.
private  File inFile
          The actual archive file as a plain java.io.File object which serves as the input file for the virtual file system managed by this ArchiveController object.
private static Logger logger
           
private  boolean needsReassembly
          Whether or not nesting this archive file to its enclosing archive file has been deferred.
private  OutputArchive outArchive
          The (possibly temporary) OutputArchive we are writing newly created or modified entries to.
private  File outFile
          Plain java.io.File object used for temporary output.
(package private) static String TEMP_FILE_PREFIX
          Prefix for temporary files created by this class.
(package private) static String TEMP_FILE_SUFFIX
          Suffix for temporary files created by this class - should not be null for enhanced unit tests.
 
Fields inherited from interface de.schlichtherle.io.Entry
ROOT_NAME, SEPARATOR, SEPARATOR_CHAR
 
Constructor Summary
UpdatingArchiveController(File target, ArchiveController enclController, String enclEntryName, ArchiveDriver driver)
           
 
Method Summary
private  ArchiveException checkNoDeletedEntriesWithNewData(ArchiveException exceptionChain)
           
(package private)  InputStream createInputStream(ArchiveEntry entry, ArchiveEntry dstEntry)
          Important: This controller's read or write lock must be acquired.
(package private)  OutputStream createOutputStream(ArchiveEntry entry, ArchiveEntry srcEntry)
          Important: This controller's write lock must be acquired.
private  void ensureOutArchive()
           
(package private)  boolean hasNewData(String entryName)
          Tests if the archive entry with the given name has received or is currently receiving new data via an output stream.
private  void initInArchive(File inFile)
          Initializes inArchive with a newly created InputArchive for reading inFile.
private  void initOutArchive(File outFile)
          Initializes outArchive with a newly created OutputArchive for writing outFile.
(package private)  void mount(boolean autoCreate)
          Mounts the virtual file system from the target file.
private  void mount0(boolean autoCreate)
           
private  ArchiveException reassemble(ArchiveException exceptionChain)
          Uses the updated output archive file to reassemble the target archive file, which may be an entry in an enclosing archive file.
(package private)  void reset()
          Resets the archive controller to its initial state - all changes to the archive file which have not yet been updated get lost!
private  ArchiveException shutdownStep1(ArchiveException exceptionChain)
          Closes and disconnects all entry streams of the output and input archive.
private  void shutdownStep2(ArchiveException exceptionChain)
          Discards the file system and closes the output and input archive.
private  void shutdownStep3(boolean deleteOutFile)
          Cleans up temporary files.
(package private)  void touch()
          Called by this controller's ArchiveFileSystem to notify it that the file system has been touched.
(package private)  void umount(ArchiveException exceptionChain, boolean waitInputStreams, boolean closeInputStreams, boolean waitOutputStreams, boolean closeOutputStreams, boolean umount, boolean reassemble)
          Synchronizes the contents of the target archive file managed by this archive controller to the real file system.
private  void umount0(ArchiveException exceptionChain, boolean waitInputStreams, boolean closeInputStreams, boolean waitOutputStreams, boolean closeOutputStreams, boolean umount, boolean reassemble)
           
private  void unwrap(ArchiveController controller, String entryName, boolean autoCreate)
           
private  void unwrapFromLockedController(ArchiveController controller, String entryName, boolean autoCreate)
           
private  ArchiveException update(ArchiveException exceptionChain)
          Updates all nodes in the virtual file system to the (temporary) output archive file.
(package private)  int waitAllInputStreamsByOtherThreads(long timeout)
           
(package private)  int waitAllOutputStreamsByOtherThreads(long timeout)
           
private  void wrap(ArchiveController controller, String entryName)
           
private  void wrapToWriteLockedController(ArchiveController controller, String entryName)
           
 
Methods inherited from class de.schlichtherle.io.ArchiveFileSystemController
autoMount, createArchiveEntry, getFileSystem, isTouched, setFileSystem
 
Methods inherited from class de.schlichtherle.io.ArchiveController
autoUmount, canRead, canWrite, createInputStream, createInputStream0, createNewFile, createOutputStream, createOutputStream0, delete, enclEntryName, exists, getClosedIcon, getDriver, getEnclArchive, getEnclController, getEnclEntryName, getOpenIcon, getPath, getTarget, isDirectory, isFile, isRfsEntryTarget, isRoot, lastModified, length, list, list, listFiles, listFiles, mkdir, readLock, runWriteLocked, setDriver, setLastModified, setReadOnly, setScheduled, toString, writeLock
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CLASS_NAME

private static final String CLASS_NAME
See Also:
Constant Field Values

logger

private static final Logger logger

TEMP_FILE_PREFIX

static final String TEMP_FILE_PREFIX
Prefix for temporary files created by this class.

See Also:
Constant Field Values

TEMP_FILE_SUFFIX

static final String TEMP_FILE_SUFFIX
Suffix for temporary files created by this class - should not be null for enhanced unit tests.

See Also:
Constant Field Values

inFile

private File inFile
The actual archive file as a plain java.io.File object which serves as the input file for the virtual file system managed by this ArchiveController object. Note that this will be set to a tempory file if the archive file is enclosed within another archive file.


inArchive

private InputArchive inArchive
An InputArchive object used to mount the virtual file system and read the entries from the archive file.


outFile

private File outFile
Plain java.io.File object used for temporary output. Maybe identical to inFile.


outArchive

private OutputArchive outArchive
The (possibly temporary) OutputArchive we are writing newly created or modified entries to.


needsReassembly

private boolean needsReassembly
Whether or not nesting this archive file to its enclosing archive file has been deferred.

Constructor Detail

UpdatingArchiveController

UpdatingArchiveController(File target,
                          ArchiveController enclController,
                          String enclEntryName,
                          ArchiveDriver driver)
Method Detail

mount

void mount(boolean autoCreate)
     throws IOException
Description copied from class: ArchiveFileSystemController
Mounts the virtual file system from the target file. This method is called while the write lock to mount the file system for this controller is acquired.

Upon normal termination, this method is expected to have called ArchiveFileSystemController.ResetFileSystem to assign the fully initialized file system to this controller. Other than this, the method must not have any side effects on the state of this class or its super class. It may, however, have side effects on the state of the sub class.

Specified by:
mount in class ArchiveFileSystemController
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.
Throws:
IOException - On any other I/O related issue with the target file or the target file of any enclosing archive file's controller.

mount0

private void mount0(boolean autoCreate)
             throws IOException
Throws:
IOException

unwrap

private void unwrap(ArchiveController controller,
                    String entryName,
                    boolean autoCreate)
             throws IOException
Throws:
IOException

unwrapFromLockedController

private void unwrapFromLockedController(ArchiveController controller,
                                        String entryName,
                                        boolean autoCreate)
                                 throws IOException
Throws:
IOException

initInArchive

private void initInArchive(File inFile)
                    throws IOException
Initializes inArchive with a newly created InputArchive for reading inFile.

Throws:
IOException - On any I/O related issue with inFile.

createInputStream

InputStream createInputStream(ArchiveEntry entry,
                              ArchiveEntry dstEntry)
                        throws IOException
Description copied from class: ArchiveController
Important:

createOutputStream

OutputStream createOutputStream(ArchiveEntry entry,
                                ArchiveEntry srcEntry)
                          throws IOException
Description copied from class: ArchiveController
Important:

touch

void touch()
     throws IOException
Description copied from class: ArchiveFileSystemController
Called by this controller's ArchiveFileSystem to notify it that the file system has been touched. A file system is touched if an operation has been performed on it which modifies it.

Warning: The write lock of this controller must be acquired while this method is called!

Overrides:
touch in class ArchiveFileSystemController
Throws:
IOException

ensureOutArchive

private void ensureOutArchive()
                       throws IOException
Throws:
IOException

initOutArchive

private void initOutArchive(File outFile)
                     throws IOException
Initializes outArchive with a newly created OutputArchive for writing outFile. This method will delete outFile if it has successfully opened it for overwriting, but failed to write the archive file header.

Throws:
IOException - On any I/O related issue with outFile.

hasNewData

boolean hasNewData(String entryName)
Description copied from class: ArchiveController
Tests if the archive entry with the given name has received or is currently receiving new data via an output stream. As an implication, the entry cannot receive new data from another output stream before the next call to ArchiveController.umount(de.schlichtherle.io.ArchiveException, boolean, boolean, boolean, boolean, boolean, boolean). Note that for directories this method will always return false!

Specified by:
hasNewData in class ArchiveController

umount

void umount(ArchiveException exceptionChain,
            boolean waitInputStreams,
            boolean closeInputStreams,
            boolean waitOutputStreams,
            boolean closeOutputStreams,
            boolean umount,
            boolean reassemble)
      throws ArchiveException
Description copied from class: ArchiveController
Synchronizes the contents of the target archive file managed by this archive controller to the real file system.

Warning: As a side effect, all data structures returned by this controller get reset (filesystem, entries, streams, etc.)! As an implication, this method requires external synchronization on this controller's write lock!

Specified by:
umount in class ArchiveController
waitInputStreams - See ArchiveControllers.umount(java.lang.String, boolean, boolean, boolean, boolean, boolean).
closeInputStreams - See ArchiveControllers.umount(java.lang.String, boolean, boolean, boolean, boolean, boolean).
waitOutputStreams - See ArchiveControllers.umount(java.lang.String, boolean, boolean, boolean, boolean, boolean).
closeOutputStreams - See ArchiveControllers.umount(java.lang.String, boolean, boolean, boolean, boolean, boolean).
umount - See ArchiveControllers.umount(java.lang.String, boolean, boolean, boolean, boolean, boolean).
reassemble - Let's assume this archive file is enclosed in another archive file. Then if this parameter is true, the updated archive file is also written to its enclosing archive file. Note that this parameter must be set if umount is set as well. Failing to comply to this requirement may throw a AssertionError and will incur loss of data!
Throws:
ArchiveException - If any exception condition occurs throughout the course of this method, an ArchiveException is created, prepended to exceptionChain and finally thrown.
See Also:
ArchiveController.autoUmount(java.lang.String), ArchiveException

umount0

private void umount0(ArchiveException exceptionChain,
                     boolean waitInputStreams,
                     boolean closeInputStreams,
                     boolean waitOutputStreams,
                     boolean closeOutputStreams,
                     boolean umount,
                     boolean reassemble)
              throws ArchiveException
Throws:
ArchiveException

waitAllInputStreamsByOtherThreads

final int waitAllInputStreamsByOtherThreads(long timeout)
Specified by:
waitAllInputStreamsByOtherThreads in class ArchiveController

waitAllOutputStreamsByOtherThreads

final int waitAllOutputStreamsByOtherThreads(long timeout)
Specified by:
waitAllOutputStreamsByOtherThreads in class ArchiveController

update

private ArchiveException update(ArchiveException exceptionChain)
                         throws ArchiveException
Updates all nodes in the virtual file system to the (temporary) output archive file.

This method is intended to be called by update() only!

Parameters:
exceptionChain - the head of a chain of exceptions created so far.
Returns:
If any warning exception condition occurs throughout the course of this method, an ArchiveWarningException is created (but not thrown), prepended to exceptionChain and finally returned. If multiple warning exception conditions occur, the prepended exceptions are ordered by appearance so that the last exception created is the head of the returned exception chain.
Throws:
ArchiveException - If any exception condition occurs throughout the course of this method, an ArchiveException is created, prepended to exceptionChain and finally thrown unless it's an ArchiveWarningException.

checkNoDeletedEntriesWithNewData

private ArchiveException checkNoDeletedEntriesWithNewData(ArchiveException exceptionChain)

reassemble

private ArchiveException reassemble(ArchiveException exceptionChain)
                             throws ArchiveException
Uses the updated output archive file to reassemble the target archive file, which may be an entry in an enclosing archive file.

This method is intended to be called by update() only!

Parameters:
exceptionChain - the head of a chain of exceptions created so far.
Returns:
If any warning condition occurs throughout the course of this method, a ArchiveWarningException is created (but not thrown), prepended to exceptionChain and finally returned. If multiple warning conditions occur, the prepended exceptions are ordered by appearance so that the last exception created is the head of the returned exception chain.
Throws:
ArchiveException - If any exception condition occurs throughout the course of this method, an ArchiveException is created, prepended to exceptionChain and finally thrown unless it's an ArchiveWarningException.

wrap

private void wrap(ArchiveController controller,
                  String entryName)
           throws IOException
Throws:
IOException

wrapToWriteLockedController

private void wrapToWriteLockedController(ArchiveController controller,
                                         String entryName)
                                  throws IOException
Throws:
IOException

reset

void reset()
     throws IOException
Resets the archive controller to its initial state - all changes to the archive file which have not yet been updated get lost!

Thereafter, the archive controller will behave as if it has just been created and any subsequent operations on its entries will remount the virtual file system from the archive file again.

Overrides:
reset in class ArchiveFileSystemController
Throws:
IOException

shutdownStep1

private ArchiveException shutdownStep1(ArchiveException exceptionChain)
Closes and disconnects all entry streams of the output and input archive.


shutdownStep2

private void shutdownStep2(ArchiveException exceptionChain)
                    throws IOException
Discards the file system and closes the output and input archive.

Throws:
IOException

shutdownStep3

private void shutdownStep3(boolean deleteOutFile)
Cleans up temporary files.

Parameters:
deleteOutFile - If this parameter is true, this method also deletes the temporary output file unless it's the target archive file (i.e. unless the archive file has been newly created).

TrueZIP 6.8.3

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