- All Implemented Interfaces:
Closeable
,AutoCloseable
ZipDocWriter
or one of its subclasses.
A number of file formats are based on the Zip archive format
including Java JAR files and Open Document files. The file
format supported by this class is one in which documents based
on Zip archives are self-labeled with their Media types.
The Zip Document format is a Zip archive whose initial entry is a directory name, "META-INF/", with a size of 0, and with an extra field for that initial entry denoting a media type. By convention, the first element in the extra field for the first entry should be the one providing the media type, with a two-byte header ID of 0xFACE (stored in little-endian order). The media type uses UTF-8 encoding but legal characters in a media type make this compatible with U.S. ASCII. The media type is not null-terminated. This results in the following byte sequences for the first portion of a file:
Bytes 0 to 3: 50 4B 03 04 Bytes 8 to 9: 00 00 Bytes 14 to 25: 00 00 00 00 00 00 00 00 00 00 00 00 Bytes 26 to 27: 09 00 Bytes 28 to 29: (4 + the length of the media type) in little-endian byte order; a larger value if other information is included Bytes 30 to 38: the characters "META-INF/" (in UTF-8 encoding) Bytes 39 to 40: CE FA (0xFACE in little-endian byte order) Bytes 41 to 42: the length of the media type in little-endian order Bytes 43 to (43 + mtlen): the characters making up the media type encoded using UTF-8, where mtlen is the number of characters in the media type
The file can be read by any software that can process ZIP files. Applications using this file format can store data in the META-INF directory, typically meta data. The rationale for this format is to make it easy for classing engines or similar software to determine the a document type.
In a few cases (e.g., the files generated by
ImageSequenceWriter
), the zip file
represent a sequence of objects, and some subsequences may consist
of the same object repeated multiple times. To store these
efficiently, the ZIP entry for the first can be tagged with a
repetition count, provided in the method
ZipDocWriter.nextOutputStream(String,boolean,int,int)
.
The names chosen
for the entry should normally be such that the missing items can be
filled in without risk of a name conflict. The tag is a ZIP-file
extra header whose ID is 0xFCDA, whose length is 4, and whose value
is a 32-bit positive integer, with all three fields stored in
little-endian byte order, the normal convention for ZIP files.
When creating a ZipDocFile, several entry names are reserved. These are "META-INF/", "META-INF/counters", and "META-INF/repetitionMap". The entry META-INF/counters contains two 32-bit two's complement integers in little-endian byte order. The first of these two integers contains the actual number of ZIP entries in the ZIP file, excluding those whose names start with "META-INF/". The second contains the number of entries, excluding those whose names start with "META-INF/", and including repetitions.
The reserved entry "META-INF/repetitionMap" is a US-ASCII file using CRLF as a newline separator. The line contains two values: an entry name and the actual entry name, separated by a space. Each of these names is URL encoded with the unencoded names using a UTF-8 character set. The repetitionMap entry might not be present if the repetition count is 1 for all entries. A repetition count of 1 is the default value - the count includes the original entry. Entries for which the repetition count is 1 are not present in a repetitionMap entry.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final long
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final long
static final int
static final int
static final int
static final int
static final int
static final int
static final long
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final long
static final int
static final int
static final int
Fields inherited from class java.util.zip.ZipFile
OPEN_DELETE, OPEN_READ
-
Constructor Summary
ConstructorsConstructorDescriptionZipDocFile
(File file) Open a ZipDocFile for reading given the specified File object.ZipDocFile
(File file, int mode) Open a ZipDocFile for reading given the specified File object and a specified mode.ZipDocFile
(File file, int mode, Charset charset) Open a ZipDocFile for reading given the specified File object and a specified mode.ZipDocFile
(File file, Charset charset) Open a ZipDocFile for reading given the specified File object and charset.ZipDocFile
(String name) Open a ZipDocFile for reading given the name of a file.ZipDocFile
(String name, Charset charset) Open a ZipDocFile for reading given the name of a file and a charset. -
Method Summary
Modifier and TypeMethodDescriptionEnumeration<? extends ZipEntry>
entries()
int
Get the number of entries stored in this file.static String
getActualName
(ZipEntry entry) Get the actual name of a ZIP entry.getInputStream
(ZipEntry entry) Get this ZipDocFile's media type.static int
getRepetitionCount
(ZipEntry entry) Get the repetition count for a specific zip-file entry.int
Get the number of entries in this file including repetitions.static boolean
isActualEntry
(ZipEntry entry) Test if an entry is an actual entry in the ZIP file.
-
Field Details
-
LOCSIG
static final long LOCSIG- See Also:
-
EXTSIG
static final long EXTSIG- See Also:
-
CENSIG
static final long CENSIG- See Also:
-
ENDSIG
static final long ENDSIG- See Also:
-
LOCHDR
static final int LOCHDR- See Also:
-
EXTHDR
static final int EXTHDR- See Also:
-
CENHDR
static final int CENHDR- See Also:
-
ENDHDR
static final int ENDHDR- See Also:
-
LOCVER
static final int LOCVER- See Also:
-
LOCFLG
static final int LOCFLG- See Also:
-
LOCHOW
static final int LOCHOW- See Also:
-
LOCTIM
static final int LOCTIM- See Also:
-
LOCCRC
static final int LOCCRC- See Also:
-
LOCSIZ
static final int LOCSIZ- See Also:
-
LOCLEN
static final int LOCLEN- See Also:
-
LOCNAM
static final int LOCNAM- See Also:
-
LOCEXT
static final int LOCEXT- See Also:
-
EXTCRC
static final int EXTCRC- See Also:
-
EXTSIZ
static final int EXTSIZ- See Also:
-
EXTLEN
static final int EXTLEN- See Also:
-
CENVEM
static final int CENVEM- See Also:
-
CENVER
static final int CENVER- See Also:
-
CENFLG
static final int CENFLG- See Also:
-
CENHOW
static final int CENHOW- See Also:
-
CENTIM
static final int CENTIM- See Also:
-
CENCRC
static final int CENCRC- See Also:
-
CENSIZ
static final int CENSIZ- See Also:
-
CENLEN
static final int CENLEN- See Also:
-
CENNAM
static final int CENNAM- See Also:
-
CENEXT
static final int CENEXT- See Also:
-
CENCOM
static final int CENCOM- See Also:
-
CENDSK
static final int CENDSK- See Also:
-
CENATT
static final int CENATT- See Also:
-
CENATX
static final int CENATX- See Also:
-
CENOFF
static final int CENOFF- See Also:
-
ENDSUB
static final int ENDSUB- See Also:
-
ENDTOT
static final int ENDTOT- See Also:
-
ENDSIZ
static final int ENDSIZ- See Also:
-
ENDOFF
static final int ENDOFF- See Also:
-
ENDCOM
static final int ENDCOM- See Also:
-
-
Constructor Details
-
ZipDocFile
Open a ZipDocFile for reading given the specified File object.- Parameters:
file
- - the file to be opened for reading- Throws:
ZipException
- - if a ZIP format error has occurredIOException
- - if an I/O error has occurred
-
ZipDocFile
Open a ZipDocFile for reading given the specified File object and charset.- Parameters:
file
- - the file to be opened for readingcharset
- - the charset used to decode the Zip entry names and comments (ignored if the language-encoding bit of the ZIP entry's general-purpose flag is set)- Throws:
ZipException
- - if a ZIP format error has occurredIOException
- - if an I/O error has occurred
-
ZipDocFile
Open a ZipDocFile for reading given the specified File object and a specified mode.- Parameters:
file
- - the file to be opened for readingmode
- - the mode in which the file is to be opened (ZipFile.OPEN_READ
orZipFile.OPEN_READ
|ZipFile.OPEN_DELETE
)- Throws:
ZipException
- - if a ZIP format error has occurredIOException
- - if an I/O error has occurredIllegalArgumentException
- - if the mode argument is invalid
-
ZipDocFile
Open a ZipDocFile for reading given the specified File object and a specified mode.- Parameters:
file
- - the file to be opened for readingmode
- - the mode in which the file is to be opened (ZipFile.OPEN_READ
orZipFile.OPEN_READ
|ZipFile.OPEN_DELETE
)charset
- - the charset used to decode the Zip entry names and comments (ignored if the language-encoding bit of the ZIP entry's general-purpose flag is set)- Throws:
ZipException
- - if a ZIP format error has occurredIOException
- - if an I/O error has occurredIllegalArgumentException
- - if the mode argument is invalid
-
ZipDocFile
Open a ZipDocFile for reading given the name of a file.- Parameters:
name
- - the name of the file to be opened for reading- Throws:
ZipException
- - if a ZIP format error has occurredIOException
- - if an I/O error has occurred
-
ZipDocFile
Open a ZipDocFile for reading given the name of a file and a charset.- Parameters:
name
- - the name of a file to be opened for readingcharset
- - the charset used to decode the Zip entry names and comments (ignored if the language-encoding bit of the ZIP entry's general-purpose flag is set)- Throws:
ZipException
- - if a ZIP format error has occurredIOException
- - if an I/O error has occurred
-
-
Method Details
-
getMimeType
Get this ZipDocFile's media type. The value is the media type embedded in this file.- Returns:
- the media type (MIME type) specified when the file was created
-
getInputStream
- Overrides:
getInputStream
in classZipFile
- Throws:
IOException
-
getEntry
- Overrides:
getEntry
in classZipFile
- Throws:
IllegalStateException
-
entries
- Overrides:
entries
in classZipFile
- Throws:
IllegalStateException
-
getRequestedEntryCount
Get the number of entries in this file including repetitions. The count excludes entries whose names begin with "META-INF/". Those entries, meeting the criteria given above, that have a repetition count of n contribute a value of n to the count returned.- Returns:
- the number of entries
- Throws:
IOException
- if an IO error occurred
-
getActualEntryCount
Get the number of entries stored in this file. The count excludes entries whose names begin with "META-INF/". The repetition count associated with each of these entries is ignored.- Returns:
- the number of entries
- Throws:
IOException
- if an IO error occurred
-
isActualEntry
Test if an entry is an actual entry in the ZIP file. The entry must be one associated with an instance of a ZipDocFile. The argument must not be null.- Parameters:
entry
- a ZIP-file entry- Returns:
- true if the entry is one that exists in the ZIP file; false if it corresponds to an alternate name for an existing entry
-
getActualName
Get the actual name of a ZIP entry. If an entry was created by calling theZipDocWriter
methodZipDocWriter.repeatFile(String)
, this method will return the name of the entry repeated, not the name passed toZipDocWriter.repeatFile(String)
.- Parameters:
entry
- a ZIP-file entry- Returns:
- the name of corresponding entry that actually exists in the ZIP file
-
getRepetitionCount
Get the repetition count for a specific zip-file entry. Repetition counts default to 1, but alternative values may be specified by calls to theZipDocWriter
methodZipDocWriter.nextOutputStream(String,boolean,int,int)
.- Parameters:
entry
- a zip entry- Returns:
- the repetition count for the actual entry corresponding to this entry
-