public class CombineArchive extends MetaDataHolder implements Closeable
We directly operate on the ZIP file, which will be kept open. Therefore, do not forget to finally close the CombineArchive when you're finished.
Modifier and Type | Field and Description |
---|---|
static String |
MANIFEST_LOCATION
The Constant MANIFEST_LOCATION.
|
static String |
METADATA_LOCATION
The Constant METADATA_LOCATION.
|
descriptions
Constructor and Description |
---|
CombineArchive(File zipFile)
Instantiates a new empty combine archive.
|
CombineArchive(File zipFile,
boolean continueOnError)
Instantiates a new empty combine archive.
|
Modifier and Type | Method and Description |
---|---|
ArchiveEntry |
addEntry(File baseDir,
File file,
String format)
Adds an entry to the archive.
|
ArchiveEntry |
addEntry(File baseDir,
File file,
String format,
boolean mainEntry)
Adds an entry to the archive.
|
ArchiveEntry |
addEntry(File baseDir,
File file,
String format,
OmexDescription description)
Deprecated.
as of version 0.5, replaced by
addEntry(java.io.File,java.io.File,java.lang.String) |
ArchiveEntry |
addEntry(File baseDir,
File file,
String format,
OmexDescription description,
boolean mainEntry)
Deprecated.
as of version 0.5, replaced by
addEntry(java.io.File,java.io.File,java.lang.String,boolean) |
ArchiveEntry |
addEntry(File toInsert,
String targetName,
String format)
Adds an entry to the archive.
|
ArchiveEntry |
addEntry(File toInsert,
String targetName,
String format,
boolean mainEntry)
Adds an entry to the archive.
|
void |
clearErrors()
Clear all errors.
|
void |
close() |
File |
extract(Path archivePath,
File destination)
Extract an entry from this archive.
|
File |
extractTo(File destination)
Extract the whole archive to the disk.
|
String |
getEntityPath()
Gets the path to this entity.
|
Collection<ArchiveEntry> |
getEntries()
Retrieves all entries.
|
List<ArchiveEntry> |
getEntriesWithFormat(String format)
Gets entries sharing a certain format.
|
ArchiveEntry |
getEntry(String location)
Retrieves an entry stored at a specified location.
|
ArchiveEntry |
getEntryByLocation(String location)
Retireves an entry by its location.
|
Iterator<ArchiveEntry> |
getEnumerator()
Gets the enumerator of entries.
|
List<String> |
getErrors()
Gets the errors that occurred during creating/reading of an archive.
|
ArchiveEntry |
getMainEntry()
Gets the main entry of this archive.
|
int |
getNumEntries()
Gets the number of entries stored in this archive.
|
int |
getNumEntriesWithFormat(String format)
Counts entries with a certain format.
|
boolean |
HasEntriesWithFormat(String format)
Checks whether there are entries with a certain format.
|
boolean |
hasErrors()
Checks for errors.
|
void |
moveEntry(String oldPath,
String newPath)
Move an entry.
|
void |
pack()
Pack this archive.
|
void |
pack(boolean multipleMetaFiles)
Pack this archive: generates manifest and meta data files.
|
boolean |
removeEntry(ArchiveEntry entry)
Removes an entry from the archive.
|
boolean |
removeEntry(String location)
Removes an entry defined by its relative location from the archive.
|
void |
setMainEntry(ArchiveEntry mainEntry)
Sets the main entry of the archive.
|
addDescription, addDescription, getDescriptions, removeDescription
public static final String MANIFEST_LOCATION
public static final String METADATA_LOCATION
public CombineArchive(File zipFile) throws IOException, org.jdom2.JDOMException, ParseException, CombineArchiveException
zipFile
- the archive to read, will be created if non-existentIOException
- if we cannot create a temporary directoryCombineArchiveException
ParseException
org.jdom2.JDOMException
public CombineArchive(File zipFile, boolean continueOnError) throws IOException, org.jdom2.JDOMException, ParseException, CombineArchiveException
continueOnError
is true we won't raise an exception
in case of errors. So you can continue working on the archive even
if a file is missing. But handle with care! You
might worsen the whole situation. In any case you should make sure
that there are no errors using hasErrors()
. The list of
occurred errors can then be obtained using getErrors()
.zipFile
- the archive to read, will be created if non-existentcontinueOnError
- ignore errors and continue (as far as possible)IOException
- if we cannot create a temporary directoryCombineArchiveException
ParseException
org.jdom2.JDOMException
public ArchiveEntry getMainEntry()
null
if there is no main entrypublic void setMainEntry(ArchiveEntry mainEntry)
mainEntry
- the new main entrypublic ArchiveEntry getEntry(String location)
/
(the root of the archive).location
- the locationpublic boolean removeEntry(String location) throws IOException
/
(the root of the archive).location
- the location of the corresponding fileIOException
public boolean removeEntry(ArchiveEntry entry) throws IOException
entry
- the entry to removeIOException
public ArchiveEntry getEntryByLocation(String location)
location
- the location of the entry, should start with /
(root
of the archive).location
, or null
if
there is no such entrypublic ArchiveEntry addEntry(File toInsert, String targetName, String format) throws IOException
The current version of the concerning file will be copied immediately.
Thus, upcoming modifications of the source file won't affect the version in
our archive. The path of this file in the archive will be
targetName
, it may include sub directories, e.g.
/path/in/archive/file.ext
. If there is already a file in the
archive having the same path we'll overwrite it.
toInsert
- the file to inserttargetName
- the target name of the file in the archiveformat
- the format, see CombineFormats
IOException
- Signals that an I/O exception has occurred.public ArchiveEntry addEntry(File toInsert, String targetName, String format, boolean mainEntry) throws IOException
The current version of the concerning file will be copied immediately.
Thus, upcoming modifications of the source file won't affect the version in
our archive. The path of this file in the archive will be
targetName
, it may include sub directories, e.g.
/path/in/archive/file.ext
. If there is already a file in the
archive having the same path we'll overwrite it.
toInsert
- the file to inserttargetName
- the target name of the file in the archiveformat
- the format, see CombineFormats
mainEntry
- the main entryIOException
- Signals that an I/O exception has occurred.public ArchiveEntry addEntry(File baseDir, File file, String format, boolean mainEntry) throws IOException
The current version of the concerning file will be copied immediately.
Thus, upcoming modifications of the source file won't affect the version in
our archive. The path of this file in the archive will be the path of
file
relative to baseDir
. If there is already a
file in the archive having the same relative path we'll overwrite it.
baseDir
- the base dirfile
- the fileformat
- the format, see CombineFormats
mainEntry
- is this the main entry of the archive? (default:
false
)IOException
- Signals that an I/O exception has occurred.public ArchiveEntry addEntry(File baseDir, File file, String format) throws IOException
file
relative to baseDir
.
If there is already a file in the archive having the same relative path
we'll delete it.baseDir
- the base dirfile
- the fileformat
- the format, see CombineFormats
IOException
- Signals that an I/O exception has occurred.@Deprecated public ArchiveEntry addEntry(File baseDir, File file, String format, OmexDescription description, boolean mainEntry) throws IOException
addEntry(java.io.File,java.io.File,java.lang.String,boolean)
file
relative to baseDir
.
If there is already a file in the archive having the same relative path
we'll delete it.baseDir
- the base dirfile
- the fileformat
- the format, see CombineFormats
description
- the descriptionmainEntry
- is this the main entry of the archive? (default:
false
)IOException
- Signals that an I/O exception has occurred.@Deprecated public ArchiveEntry addEntry(File baseDir, File file, String format, OmexDescription description) throws IOException
addEntry(java.io.File,java.io.File,java.lang.String)
file
relative to baseDir
.
If there is already a file in the archive having the same relative path
we'll delete it.baseDir
- the base dirfile
- the fileformat
- the format, see CombineFormats
description
- the descriptionIOException
- Signals that an I/O exception has occurred.public List<ArchiveEntry> getEntriesWithFormat(String format)
format
- the format of interest, see CombineFormats
public int getNumEntriesWithFormat(String format)
format
- the format of interest, see CombineFormats
public boolean HasEntriesWithFormat(String format)
format
- the format of interest, see CombineFormats
public Collection<ArchiveEntry> getEntries()
public int getNumEntries()
public Iterator<ArchiveEntry> getEnumerator()
public String getEntityPath()
MetaDataHolder
getEntityPath
in class MetaDataHolder
public void pack(boolean multipleMetaFiles) throws IOException, TransformerException
While we're working directly in the ZIP this generates manifest and meta
data files. If multipleMetaFiles
is set to true
(default: false
, see pack()
) we will generate one
meta data file for each archive entry (instead of combining all meta data
in a single file).
multipleMetaFiles
- should we create one meta file per archive entry or combine all
meta data in a single file?TransformerException
IOException
public void pack() throws IOException, TransformerException
While we're working directly in the ZIP this generates manifest and meta
data files. This method will generate a single meta data file for all meta
data associated to the entries in this archive. See pack(boolean)
if you prefer creating multiple meta data files.
TransformerException
IOException
public void moveEntry(String oldPath, String newPath) throws IOException
oldPath
- the old path to the entrynewPath
- the target pathIOException
- Signals that an I/O exception has occurred.public File extract(Path archivePath, File destination) throws IOException
archivePath
- the path of the entry in our archive, should start with an
/
destination
- the destination to write the entry todestination
)IOException
- Signals that an I/O exception has occurred.public File extractTo(File destination) throws IOException
destination
- the destinationIOException
public List<String> getErrors()
public boolean hasErrors()
public void clearErrors()
public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
IOException
Copyright © 2014. All rights reserved.