com.mmoui.manager.services
Class Extractor

java.lang.Object
  extended by com.mmoui.manager.services.Extractor

public abstract class Extractor
extends java.lang.Object

Defines a class which can be used to extract an archive (such as a ZIP or RAR archive). Extractor objects should be created via an ExtractorFactoryService in most cases. This allows modules to focus on the behavior required without need to reimplement the various extraction capabilities for different types of archives.

Version:
$Id: Extractor.java 170 2009-04-22 06:48:10Z mpdelbuono $
Author:
Matthew P. Del Buono

Constructor Summary
Extractor()
           
 
Method Summary
 void extract(java.io.File directory, UpdateStatusListener listener)
          Extracts all files in the archive into the specified directory, overwriting any conflicting files.
 java.io.File extract(UpdateStatusListener listener)
          Extracts all files in the archive which is represented by this Extractor into a new temporary directory
protected abstract  void getEntry(java.io.File outputFile)
          Extracts the current entry into the specified outputFile
abstract  java.lang.String[] getFileNames()
          Gets a listing of all file and directory names found inside the archive.
protected abstract  java.lang.String getNextEntry()
          Gets the next available entry in the archive, terminating extraction of the current entry if it exists.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Extractor

public Extractor()
Method Detail

getFileNames

public abstract java.lang.String[] getFileNames()
                                         throws java.io.IOException
Gets a listing of all file and directory names found inside the archive. Directory names are always terminated with a trailing forward slash; file names are never terminated with a trailing slash.

Returns:
the list of all files and directories present in the archive
Throws:
java.io.IOException - if an error occurs while reading the archive

getNextEntry

protected abstract java.lang.String getNextEntry()
                                          throws java.io.IOException
Gets the next available entry in the archive, terminating extraction of the current entry if it exists. The implementation should remember which entry is to be extracted so that future calls to extractEntry() can be supported.

Returns:
the path, relative to the archive, of the new entry in the archive, or null if no more entries are available
Throws:
java.io.IOException - if an error occurs while reading the archive

getEntry

protected abstract void getEntry(java.io.File outputFile)
                          throws java.io.IOException,
                                 java.lang.IllegalArgumentException,
                                 java.lang.IllegalStateException
Extracts the current entry into the specified outputFile

Parameters:
outputFile - the file to which data should be extracted
Throws:
java.io.IOException - if an I/O error occurs while extracting the data from the archive
java.lang.IllegalArgumentException - if outputFile is not a file
java.lang.IllegalStateException - if the current entry is a directory or there is no current entry
See Also:
getNextEntry()

extract

public java.io.File extract(UpdateStatusListener listener)
                     throws java.io.IOException
Extracts all files in the archive which is represented by this Extractor into a new temporary directory

Parameters:
listener - the UpdateStatusListener object which can be used to update the extraction status
Returns:
the created temporary directory which is filled with the extracted contents
Throws:
java.io.IOException - if an I/O or archive exception occurs while extracting
See Also:
extract(java.io.File, com.mmoui.manager.services.UpdateStatusListener)

extract

public void extract(java.io.File directory,
                    UpdateStatusListener listener)
             throws java.io.IOException,
                    java.lang.IllegalArgumentException
Extracts all files in the archive into the specified directory, overwriting any conflicting files. Files which were present before but are not present in the archive are not removed.

Parameters:
directory - the directory to which contents should be extracted
listener - the UpdateStatusListener object which can be used to update the extraction status
Throws:
java.io.IOException - if an I/O error occurs while extracting
java.lang.IllegalArgumentException - if the specified parameter is not a directory