public class CombineArchive extends Object 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.
|
Constructor and Description |
---|
CombineArchive(File zipFile)
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 |
close() |
File |
extract(Path archivePath,
File destination)
Extract an entry from this archive.
|
File |
extractTo(File destination)
Extract the whole archive to the disk.
|
Collection<ArchiveEntry> |
getEntries()
Retrieves all entries.
|
List<ArchiveEntry> |
getEntriesWithFormat(String format)
Gets entries sharing a certain format.
|
ArchiveEntry |
getEntryByLocation(String location)
Retireves an entry by its location.
|
Iterator<ArchiveEntry> |
getEnumerator()
Gets the enumerator of entries.
|
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.
|
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.
|
org.json.simple.JSONObject |
toJsonDescription()
Export a JSON description of this archive.
|
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 ArchiveEntry getMainEntry()
null
if there is no main entrypublic 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 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 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 org.json.simple.JSONObject toJsonDescription()
public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
IOException
Copyright © 2014. All rights reserved.