|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.mucommander.file.archiver.Archiver
public abstract class Archiver
Archiver is an abstract class that represents a generic file archiver and abstracts the underlying compression method and specifics of the format.
Subclasses implement specific archive formats (Zip, Tar...) but cannot be instanciated directly.
Instead, the getArchiver methods can be used to retrieve an Archiver
instance for a specified archive format. A list of available archive formats can be dynamically retrieved
using getFormats.
Archive formats fall into 2 categories:
| Field Summary | |
|---|---|
static int |
BZ2_FORMAT
Bzip2 archive format (single entry format) |
protected int |
format
Archive format of this Archiver |
protected java.lang.String |
formatName
Archive format's name of this Archiver |
static int |
GZ_FORMAT
Gzip archive format (single entry format) |
protected java.io.OutputStream |
out
The underlying stream this archiver is writing to |
static int |
TAR_BZ2_FORMAT
Tar archive compressed with Bzip2 format (many entries format) |
static int |
TAR_FORMAT
Tar archive format without any compression (many entries format) |
static int |
TAR_GZ_FORMAT
Tar archive compressed with Gzip format (many entries format) |
static int |
ZIP_FORMAT
Zip archive format (many entries format) |
| Method Summary | |
|---|---|
abstract void |
close()
Closes the underlying OuputStream and ressources used by this Archiver to write the archive. |
protected static java.io.OutputStream |
createBzip2OutputStream(java.io.OutputStream out)
Creates and returns a Bzip2 OutputStream using the given OutputStream as the underlying
stream. |
abstract java.io.OutputStream |
createEntry(java.lang.String entryPath,
AbstractFile file)
Creates a new entry in the archive with the given path. |
static boolean |
formatSupportsComment(int format)
Returns true if the specified archive format can store an optional comment. |
static boolean |
formatSupportsManyFiles(int format)
Returns true if the specified archive format supports storage of more than one entry. |
static Archiver |
getArchiver(AbstractFile file,
int format)
Returns an Archiver for the specified format and that uses the given AbstractFile to write entries to. |
static Archiver |
getArchiver(java.io.OutputStream out,
int format)
Returns an Archiver for the specified format and that uses the given OutputStream to write entries to. |
int |
getFormat()
Returns the archiver format used by this Archiver. |
static java.lang.String |
getFormatExtension(int format)
Returns the default archive format extension. |
java.lang.String |
getFormatName()
Returns the name of the archive format used by this Archiver. |
static java.lang.String |
getFormatName(int format)
Returns the name of the given archive format. |
static int[] |
getFormats(boolean manyEntries)
Returns an array of available archive formats, single entry formats or many entries formats depending on the value of the specified boolean parameter. |
java.io.OutputStream |
getOutputStream()
Returns the OutputStream this Archiver is writing to. |
protected java.lang.String |
normalizePath(java.lang.String entryPath,
boolean isDirectory)
Normalizes the entry path, that is : replace any \ character occurrence by / as this usually is the default separator for archive files if the entry is a directory, add a trailing slash to the path if it doesn't have one already |
void |
setComment(java.lang.String comment)
Sets an optional comment in the archive, the supportsComment() or
formatSupportsComment(int) must first be called to make sure
the archive format supports comment, otherwise calling this method will have no effect. |
boolean |
supportsComment()
Returns true if the format used by this Archiver can store an optional comment. |
boolean |
supportsManyFiles()
Returns true if the format used by this Archiver can store more than one entry. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int ZIP_FORMAT
public static final int GZ_FORMAT
public static final int BZ2_FORMAT
public static final int TAR_FORMAT
public static final int TAR_GZ_FORMAT
public static final int TAR_BZ2_FORMAT
protected java.io.OutputStream out
protected int format
protected java.lang.String formatName
| Method Detail |
|---|
public java.io.OutputStream getOutputStream()
OutputStream this Archiver is writing to.
public int getFormat()
public java.lang.String getFormatName()
public boolean supportsManyFiles()
public boolean supportsComment()
public void setComment(java.lang.String comment)
supportsComment() or
formatSupportsComment(int) must first be called to make sure
the archive format supports comment, otherwise calling this method will have no effect.
Implementation note: Archiver implementations must override this method to handle comments
comment - the comment to be stored in the archive
protected java.lang.String normalizePath(java.lang.String entryPath,
boolean isDirectory)
public static Archiver getArchiver(AbstractFile file,
int format)
throws java.io.IOException
AbstractFile to write entries to.
null is returned if the specified format is not valid.
This method will first attempt to get a RandomAccessOutputStream if the given file is able to supply
one, and if not, fall back to a regular OutputStream. Note that if the file exists, its contents
will be overwritten. Write bufferring is used under the hood to improve performance.
file - the AbstractFile which the returned Archiver will write entries toformat - an archive format
AbstractFile to write entries to ;
null if the specified format is not valid.
java.io.IOException - if the file cannot be opened for write, or if an error occurred while intializing the archiver
public static Archiver getArchiver(java.io.OutputStream out,
int format)
throws java.io.IOException
OutputStream to write entries to.
null is returned if the specified format is not valid. Whenever possible, a
RandomAccessOutputStream should be supplied as some formats take advantage of having a random write access.
out - the OutputStream which the returned Archiver will write entries toformat - an archive format
AbstractFile to write entries to ;
null if the specified format is not valid.
java.io.IOException - if an error occurred while intializing the archiver
protected static java.io.OutputStream createBzip2OutputStream(java.io.OutputStream out)
throws java.io.IOException
OutputStream using the given OutputStream as the underlying
stream.
out - the underlying stream
java.io.IOException - if an error occurred while initializing the Bzip2 OutputStreampublic static int[] getFormats(boolean manyEntries)
manyEntries - if true, a list of many entries formats (a subset of single entry formats) will be returnedpublic static java.lang.String getFormatName(int format)
format - an archive formatpublic static java.lang.String getFormatExtension(int format)
format - an archive formatpublic static boolean formatSupportsManyFiles(int format)
format - an archive formatpublic static boolean formatSupportsComment(int format)
format - an archive format
public abstract java.io.OutputStream createEntry(java.lang.String entryPath,
AbstractFile file)
throws java.io.IOException
If the entry is a regular file (not a directory), an OutputStream which can be used to write the contents
of the entry will be returned, null otherwise. The OutputStream must not be closed once
it has been used (Archiver takes care of this), only the close method has to be called when
all entries have been created.
If this Archiver uses a single entry format, the specified path and file won't be used at all. Also in this case, this method must be invoked only once (single entry), it will throw an IOException if invoked more than once.
entryPath - the path to be used to create the entry in the archive.
This parameter is simply ignored if the archive is a single entry format.file - AbstractFile instance used to determine if the entry is a directory, and to set the entry's date.
This parameter is simply ignored if the archive is a single entry format.
java.io.IOException - if this Archiver failed to write the entry, or in the case of a single entry archiver, if
this method was called more than once.
public abstract void close()
throws java.io.IOException
java.io.IOException
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
This file is part of muCommander - Copyright (C) 2002-2008 Maxence Bernard