|
Brooklyn | |||||||
FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectbrooklyn.util.file.ArchiveBuilder
public class ArchiveBuilder
Build a Zip or Jar archive.
Supports creating temporary archives that will be deleted on exit, if no name is
specified. The created file must be a Java archive type, with the extension .zip
,
.jar
, .war
or .ear
.
Examples:
File zip = ArchiveBuilder.archive("data/archive.zip") .entry("src", applicationDir + "/deploy/" + version + "/src/") .entry("lib", applicationDir + "/deploy/" + version + "/lib/") .entry("etc/config.ini", applicationDir + "/config.ini") .create();
OutputStream remote = ...; Map<String, File> entries = ...; ArchiveBuilder.zip() .add("resources/data.csv") .addAll(entries) .stream(remote);
Method Summary | |
---|---|
ArchiveBuilder
|
add(java.lang.String filePath)
Add the file located at the |
ArchiveBuilder
|
add(java.io.File file)
Add the |
ArchiveBuilder
|
add(java.lang.String baseDir, java.lang.String filePath)
Add the file located at the |
ArchiveBuilder
|
add(java.lang.Iterable files)
Add the collection of |
ArchiveBuilder
|
add(java.lang.String baseDir, java.lang.Iterable files)
Add the collection of |
ArchiveBuilder
|
addDir(java.lang.String dirName)
Add the contents of the directory named |
ArchiveBuilder
|
addDir(java.io.File dir)
Add the contents of the directory |
static ArchiveBuilder
|
archive(java.lang.String archive)
Create an ArchiveBuilder for an archive with the given name. |
java.io.File
|
create(java.lang.String archiveFile)
Generates the archive, saving it with the given name. |
java.io.File
|
create()
Generates the archive. |
ArchiveBuilder
|
entries(java.util.Map entries)
Add a java.util.Map of entries to the archive. |
ArchiveBuilder
|
entry(java.lang.String entryPath, java.lang.String filePath)
Add the |
ArchiveBuilder
|
entry(java.lang.String entryPath, java.io.File file)
Add the |
static ArchiveBuilder
|
jar()
Create an ArchiveBuilder for a ArchiveType#JAR#JAR format archive. |
ArchiveBuilder
|
manifest(java.lang.Object key, java.lang.Object value)
Add a manifest entry with the given |
ArchiveBuilder
|
named(java.lang.String name)
Set the location of the generated archive file. |
ArchiveBuilder
|
named(java.io.File file)
@see #named(String) |
void
|
stream(java.io.OutputStream output)
Generates the archive and ouputs it to the given stream, ignoring any file name. |
static ArchiveBuilder
|
zip()
Create an ArchiveBuilder for a ArchiveType#ZIP#ZIP format archive. |
Methods inherited from class java.lang.Object | |
---|---|
java.lang.Object#wait(long, int), java.lang.Object#wait(long), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll() |
Method Detail |
---|
public ArchiveBuilder add(java.lang.String filePath)
filePath
to the archive.
public ArchiveBuilder add(java.io.File file)
file
to the archive.
If the file path is absolute, or points to a file above the current directory,
the file is added to the archive as a top-level entry, using the file name only.
For relative filePath
s below the current directory, the file is added
using the path given and is assumed to be located relative to the current
working directory.
No checks for file existence are made at this stage.
public ArchiveBuilder add(java.lang.String baseDir, java.lang.String filePath)
filePath
, relative to the baseDir
,
to the archive.
Uses the filePath
as the name of the file in the archive. Note that the
two path components are simply concatenated using Os#mergePaths(String...)
which may not behave as expected if the filePath
is absolute or points to
a location above the current directory.
Use entry(String, String) directly or entries(Map) for complete control over file locations and names in the archive.
public ArchiveBuilder add(java.lang.Iterable files)
files
to the archive.
public ArchiveBuilder add(java.lang.String baseDir, java.lang.Iterable files)
files
, relative to the baseDir
, to
the archive.
public ArchiveBuilder addDir(java.lang.String dirName)
dirName
to the archive.
public ArchiveBuilder addDir(java.io.File dir)
dir
to the archive.
Uses . as the parent directory name for the contents.
public static ArchiveBuilder archive(java.lang.String archive)
public java.io.File create(java.lang.String archiveFile)
public java.io.File create()
If no name has been specified, the archive will be created as a temporary file with a unique name, that is deleted on exit. Otherwise, the given name will be used.
public ArchiveBuilder entries(java.util.Map entries)
The keys should be the names of the file entries to be added to the archive and the value should point to the actual java.io.File to be added.
This allows complete control over the directory structure of the eventual archive, as the entry names do not need to bear any relationship to the name or location of the files on the filesystem.
public ArchiveBuilder entry(java.lang.String entryPath, java.lang.String filePath)
file
to the archive with the path entryPath
.
public ArchiveBuilder entry(java.lang.String entryPath, java.io.File file)
file
to the archive with the path entryPath
.
public static ArchiveBuilder jar()
public ArchiveBuilder manifest(java.lang.Object key, java.lang.Object value)
key
and value
.
public ArchiveBuilder named(java.lang.String name)
public ArchiveBuilder named(java.io.File file)
public void stream(java.io.OutputStream output)
This will add a manifest filw if the type is a Jar archive.
public static ArchiveBuilder zip()
Brooklyn Multi-Cloud Application Management Platform
brooklyncentral.github.com. Apache License. © 2012.