Brooklyn

brooklyn.util.file
[Java] Class ArchiveBuilder

java.lang.Object
  brooklyn.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 filePath to the archive.

ArchiveBuilder add(java.io.File file)

Add the file to the archive.

ArchiveBuilder add(java.lang.String baseDir, java.lang.String filePath)

Add the file located at the filePath, relative to the baseDir, to the archive.

ArchiveBuilder add(java.lang.Iterable files)

Add the collection of files to the archive.

ArchiveBuilder add(java.lang.String baseDir, java.lang.Iterable files)

Add the collection of files, relative to the baseDir, to the archive.

ArchiveBuilder addDir(java.lang.String dirName)

Add the contents of the directory named dirName to the archive.

ArchiveBuilder addDir(java.io.File dir)

Add the contents of the directory dir to the archive.

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 file to the archive with the path entryPath.

ArchiveBuilder entry(java.lang.String entryPath, java.io.File file)

Add the file to the archive with the path entryPath.

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 key and value.

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

add

public ArchiveBuilder add(java.lang.String filePath)
Add the file located at the filePath to the archive.
See Also:
add(File)


add

public ArchiveBuilder add(java.io.File file)
Add the 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 filePaths 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.

See Also:
entry(String, File)


add

public ArchiveBuilder add(java.lang.String baseDir, java.lang.String filePath)
Add the file located at the 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.

See Also:
entry(String, String)


add

public ArchiveBuilder add(java.lang.Iterable files)
Add the collection of files to the archive.
See Also:
add(String)


add

public ArchiveBuilder add(java.lang.String baseDir, java.lang.Iterable files)
Add the collection of files, relative to the baseDir, to the archive.
See Also:
add(String, String)


addDir

public ArchiveBuilder addDir(java.lang.String dirName)
Add the contents of the directory named dirName to the archive.
See Also:
addDir(File)


addDir

public ArchiveBuilder addDir(java.io.File dir)
Add the contents of the directory dir to the archive.

Uses . as the parent directory name for the contents.

See Also:
entry(String, File)


archive

public static ArchiveBuilder archive(java.lang.String archive)
Create an ArchiveBuilder for an archive with the given name.


create

public java.io.File create(java.lang.String archiveFile)
Generates the archive, saving it with the given name.


create

public java.io.File create()
Generates the archive.

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.


entries

public ArchiveBuilder entries(java.util.Map entries)
Add a java.util.Map of entries to the archive.

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.


entry

public ArchiveBuilder entry(java.lang.String entryPath, java.lang.String filePath)
Add the file to the archive with the path entryPath.
See Also:
entry(String, File)


entry

public ArchiveBuilder entry(java.lang.String entryPath, java.io.File file)
Add the file to the archive with the path entryPath.


jar

public static ArchiveBuilder jar()
Create an ArchiveBuilder for a ArchiveType#JAR#JAR format archive.


manifest

public ArchiveBuilder manifest(java.lang.Object key, java.lang.Object value)
Add a manifest entry with the given key and value.


named

public ArchiveBuilder named(java.lang.String name)
Set the location of the generated archive file.


named

public ArchiveBuilder named(java.io.File file)
See Also:
named(String)


stream

public void stream(java.io.OutputStream output)
Generates the archive and ouputs it to the given stream, ignoring any file name.

This will add a manifest filw if the type is a Jar archive.


zip

public static ArchiveBuilder zip()
Create an ArchiveBuilder for a ArchiveType#ZIP#ZIP format archive.


 

Brooklyn Multi-Cloud Application Management Platform
brooklyncentral.github.com. Apache License. © 2012.