|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.mucommander.file.impl.zip.provider.ZipFile
public class ZipFile
This class is a replacement for java.util.ZipFile with some extra functionalities:
addEntry(ZipEntry), UTF-8 is always used and declared as such in the Zip headers.
This class doesn't extend java.util.zip.ZipFile as it would have to reimplement all methods anyway.
Like java.util.ZipFile, it supports compressed (DEFLATED) and uncompressed (STORED) entries.
Random read access is required to instanciate a ZipFile and retrieve its entries. Furthermore, random
write access is required for methods that modify the Zip file.
The method signatures mimic the ones of java.util.zip.ZipFile with a few exceptions:
getName method.close method: underlying input and output streams are opened and closed automatically
as they are needed.entries has been renamed to getEntries().size has been renamed to getNbEntries().--------------------------------------------------------------------------------------------------------------
This class is based off the org.apache.tools.zip package of the Apache Ant project. The Ant
code has been modified under the terms of the Apache License which you can find in the bundled muCommander license
file. It was forked at version 1.7.0 of Ant.
| Field Summary |
|---|
| Fields inherited from interface com.mucommander.file.impl.zip.provider.ZipConstants |
|---|
CFH_SIG, DD_SIG, DEFAULT_DEFLATER_BUFFER_SIZE, DEFAULT_DEFLATER_COMPRESSION, DEFLATED, EOCD_SIG, LFH_SIG, STORED, UTF_8, WRITE_BUFFER_SIZE |
| Constructor Summary | |
|---|---|
ZipFile(AbstractFile f)
Opens the given Zip file and parses information about the entries it contains. |
|
| Method Summary | |
|---|---|
java.io.OutputStream |
addEntry(ZipEntry entry)
Appends the given entry to the end of this zip file and returns an OutputStream that allows to write
the contents of the entry. |
void |
defragment()
Removes free space fragments from this zip file, thus reducing the size of the zip file. |
void |
deleteEntry(ZipEntry ze)
Deletes the given entry from this zip file. |
java.lang.String |
getDefaultEncoding()
Returns the default encoding to use for parsing filenames and comments. |
java.util.Enumeration |
getEntries()
Returns all entries as an enumeration of ZipEntry instances. |
ZipEntry |
getEntry(java.lang.String name)
Returns a named entry or null if no entry by that name exists. |
java.io.InputStream |
getInputStream(ZipEntry ze)
Returns an InputStream for reading the contents of the given entry. |
int |
getNbEntries()
Returns the number of entries contained by this Zip file. |
void |
setDefaultEncoding(java.lang.String defaultEncoding)
Sets the default encoding to use for parsing filenames and comments. |
void |
updateEntry(ZipEntry entry)
Updates the date and permissions of the entry designated by the given ZipEntry object. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public ZipFile(AbstractFile f)
throws java.io.IOException,
java.util.zip.ZipException
The given AbstractFile must have random read access. If not, an IOException will be
thrown.
f - the archive file
java.io.IOException - if a RandomAccessInputStream could not retrieved, or if an error occurred while reading the
Zip file.
java.util.zip.ZipException - if this file is not a valid Zip file| Method Detail |
|---|
public java.lang.String getDefaultEncoding()
By default, this method returns null to indicate that automatic encoding detection is used.
Although it is not 100% accurate, encoding detection is the preferred approach, unless the encoding is known
in advance which is rather uncommon.
Note that this value only affects entries parsing. Written entries are systematically encoded in
UTF-8 and declared as such in the general purpose bit flag so that proper zip unpackers know what
encoding to expect.
public void setDefaultEncoding(java.lang.String defaultEncoding)
By default, the encoding is null to indicate that automatic encoding detection is used.
Although it is not 100% accurate, encoding detection is the preferred approach, unless the encoding is known
in advance which is rather uncommon.
Note that this value only affects entries parsing. Written entries are systematically encoded in
UTF-8 and declared as such in the general purpose bit flag so that proper zip unpackers know what
encoding to expect.
defaultEncoding - the default encoding to use for parsing filenames and commentspublic java.util.Enumeration getEntries()
ZipEntry instances.
public int getNbEntries()
public ZipEntry getEntry(java.lang.String name)
null if no entry by that name exists.
name - name of the entry.
null if not present.
public java.io.InputStream getInputStream(ZipEntry ze)
throws java.io.IOException,
java.util.zip.ZipException
ze - the entry to get the stream for.
java.io.IOException - if unable to create an input stream from the zipenty
java.util.zip.ZipException - if the zipentry has an unsupported compression method
public void deleteEntry(ZipEntry ze)
throws java.io.IOException,
java.util.zip.ZipException
defragment() method
can be called to reclaim the free space.
There is one case where this method reclaims the free space: when the specified entry is the last one in the zip file. In this case, the resulting zip file will be smaller.
Note that 'fragmented' zip files are perfectly valid zip files, any zip parser should be able to cope with such files.
The underlying AbstractFile must have random write access. If not, an IOException will be
thrown.
ze - the ZipEntry to delete
java.io.IOException - if the underlying AbstractFile does not have random write access or if an I/O error occurred
java.util.zip.ZipException - if the specified ZipEntry cannot be found in this zip file
public java.io.OutputStream addEntry(ZipEntry entry)
throws java.io.IOException
OutputStream that allows to write
the contents of the entry. The returned OutputStream must always be closed for the zip file to be
properly modified. Not doing will leave this zip file in a inconsistent, corrupted state.
The underlying AbstractFile must have random write access. If not, an IOException will be
thrown.
entry - the entry to add to this zip file
java.io.IOException - if the underlying AbstractFile does not have random write access or if an I/O error occurred
public void updateEntry(ZipEntry entry)
throws java.io.IOException
The underlying AbstractFile must have random write access. If not, an IOException will be
thrown.
entry - the entry to update
java.io.IOException - if the underlying AbstractFile does not have random write access or if an I/O error occurred
public void defragment()
throws java.io.IOException
Fragmentation occurs when deleting entries with deleteEntry(ZipEntry). When deleting several entries,
this method should be called once after all entries have deleted.
The underlying AbstractFile must have random write access. If not, an IOException will be
thrown.
java.io.IOException - if the underlying AbstractFile does not have random write access or if an I/O error occurred
|
|||||||||
| 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