public class Jar
extends java.lang.Object
| Constructor and Description |
|---|
Jar()
Creates a new, empty, JAR
|
Jar(java.io.File jar)
Reads in the JAR from the given
File. |
Jar(java.io.InputStream jar)
Reads in the JAR from the given
InputStream. |
Jar(java.nio.file.Path jar)
Reads in the JAR from the given
Path. |
Jar(java.lang.String jar)
Reads in the JAR from the given path.
|
| Modifier and Type | Method and Description |
|---|---|
Jar |
addClass(java.lang.Class<?> clazz)
Adds a class entry to this JAR.
|
Jar |
addEntries(java.nio.file.Path path,
java.nio.file.Path dirOrZip)
Adds a directory (with all its subdirectories) or the contents of a zip/JAR to this JAR.
|
Jar |
addEntries(java.nio.file.Path path,
java.util.zip.ZipInputStream zip)
Adds the contents of the zip/JAR contained in the given byte array to this JAR.
|
Jar |
addEntries(java.lang.String path,
java.nio.file.Path dirOrZip)
Adds a directory (with all its subdirectories) or the contents of a zip/JAR to this JAR.
|
Jar |
addEntry(java.nio.file.Path path,
java.io.InputStream is)
Adds an entry to this JAR.
|
Jar |
addEntry(java.nio.file.Path path,
java.nio.file.Path file)
Adds an entry to this JAR.
|
Jar |
addEntry(java.nio.file.Path path,
java.lang.String file)
Adds an entry to this JAR.
|
Jar |
addEntry(java.lang.String path,
byte[] content)
Adds an entry to this JAR.
|
Jar |
addEntry(java.lang.String path,
java.io.File file)
Adds an entry to this JAR.
|
Jar |
addEntry(java.lang.String path,
java.io.InputStream is)
Adds an entry to this JAR.
|
Jar |
addEntry(java.lang.String path,
java.lang.String file)
Adds an entry to this JAR.
|
Jar |
addPackageOf(java.lang.Class<?> clazz)
Adds the contents of a Java package to this JAR.
|
java.lang.String |
getAttribute(java.lang.String name)
Returns an attribute's value from this JAR's manifest's main section.
|
java.lang.String |
getAttribute(java.lang.String section,
java.lang.String name)
Returns an attribute's value from a non-main section of this JAR's manifest.
|
java.util.List<java.lang.String> |
getListAttribute(java.lang.String name)
Returns an attribute's list value from this JAR's manifest's main section.
|
java.util.List<java.lang.String> |
getListAttribute(java.lang.String section,
java.lang.String name)
Returns an attribute's list value from a non-main section of this JAR's manifest.
|
java.util.jar.Manifest |
getManifest()
Returns the manifest of this JAR.
|
java.util.Map<java.lang.String,java.lang.String> |
getMapAttribute(java.lang.String name,
java.lang.String defaultValue)
Returns an attribute's map value from this JAR's manifest's main section.
|
java.util.Map<java.lang.String,java.lang.String> |
getMapAttribute(java.lang.String section,
java.lang.String name,
java.lang.String defaultValue)
Returns an attribute's map value from a non-main section of this JAR's manifest.
|
Jar |
setAttribute(java.lang.String name,
java.lang.String value)
Sets an attribute in the main section of the manifest.
|
Jar |
setAttribute(java.lang.String section,
java.lang.String name,
java.lang.String value)
Sets an attribute in a non-main section of the manifest.
|
Jar |
setJarPrefix(java.nio.file.Path file)
Sets a file whose contents will be prepended to the JAR file's data.
|
Jar |
setJarPrefix(java.lang.String value)
Sets a string that will be prepended to the JAR file's data.
|
Jar |
setListAttribute(java.lang.String name,
java.util.List<java.lang.String> values)
Sets an attribute in the main section of the manifest to a list.
|
Jar |
setListAttribute(java.lang.String section,
java.lang.String name,
java.util.List<java.lang.String> values)
Sets an attribute in a non-main section of the manifest to a list.
|
Jar |
setMapAttribute(java.lang.String name,
java.util.Map<java.lang.String,java.lang.String> values)
Sets an attribute in the main section of the manifest to a map.
|
Jar |
setMapAttribute(java.lang.String section,
java.lang.String name,
java.util.Map<java.lang.String,java.lang.String> values)
Sets an attribute in a non-main section of the manifest to a map.
|
Jar |
setPacker(java.util.jar.Pack200.Packer packer)
Sets a
Pack200 packer to use when writing the JAR. |
Jar |
setReallyExecutable(boolean value)
If set to true true, a header will be added to the JAR file when written, that will make the JAR an executable file in POSIX environments.
|
byte[] |
toByteArray()
Returns this JAR file as an array of bytes.
|
static java.io.InputStream |
toInputStream(java.lang.String str,
java.nio.charset.Charset charset)
Turns a
String into an InputStream containing the string's encoded characters. |
java.io.File |
write(java.io.File file)
Writes this JAR to a file.
|
java.nio.file.Path |
write(java.nio.file.Path path)
Writes this JAR to a file.
|
void |
write(java.lang.String file)
Writes this JAR to a file.
|
<T extends java.io.OutputStream> |
write(T os)
Writes this JAR to an output stream, and closes the stream.
|
public Jar()
public Jar(java.io.InputStream jar)
throws java.io.IOException
InputStream.
Modifications will not be made to the original JAR file, but to a new copy, which is then written with write().java.io.IOExceptionpublic Jar(java.nio.file.Path jar)
throws java.io.IOException
Path.
Modifications will not be made to the original JAR file, but to a new copy, which is then written with write().java.io.IOExceptionpublic Jar(java.io.File jar)
throws java.io.IOException
File.
Modifications will not be made to the original JAR file, but to a new copy, which is then written with write().java.io.IOExceptionpublic Jar(java.lang.String jar)
throws java.io.IOException
write().java.io.IOExceptionpublic java.util.jar.Manifest getManifest()
addEntry().public final Jar setAttribute(java.lang.String name, java.lang.String value)
name - the attribute's namevalue - the attribute's valuethisjava.lang.IllegalStateException - if entries have been added or the JAR has been written prior to calling this methods.public final Jar setAttribute(java.lang.String section, java.lang.String name, java.lang.String value)
section - the section's namename - the attribute's namevalue - the attribute's valuethisjava.lang.IllegalStateException - if entries have been added or the JAR has been written prior to calling this methods.public Jar setListAttribute(java.lang.String name, java.util.List<java.lang.String> values)
name - the attribute's namevalues - the attribute's valuethisjava.lang.IllegalStateException - if entries have been added or the JAR has been written prior to calling this methods.public Jar setListAttribute(java.lang.String section, java.lang.String name, java.util.List<java.lang.String> values)
section - the section's namename - the attribute's namevalues - the attribute's valuethisjava.lang.IllegalStateException - if entries have been added or the JAR has been written prior to calling this methods.public Jar setMapAttribute(java.lang.String name, java.util.Map<java.lang.String,java.lang.String> values)
name - the attribute's namevalues - the attribute's valuethisjava.lang.IllegalStateException - if entries have been added or the JAR has been written prior to calling this methods.public Jar setMapAttribute(java.lang.String section, java.lang.String name, java.util.Map<java.lang.String,java.lang.String> values)
section - the section's namename - the attribute's namevalues - the attribute's valuethisjava.lang.IllegalStateException - if entries have been added or the JAR has been written prior to calling this methods.public java.lang.String getAttribute(java.lang.String name)
name - the attribute's namepublic java.lang.String getAttribute(java.lang.String section,
java.lang.String name)
section - the manifest's sectionname - the attribute's namepublic java.util.List<java.lang.String> getListAttribute(java.lang.String name)
name - the attribute's namepublic java.util.List<java.lang.String> getListAttribute(java.lang.String section,
java.lang.String name)
section - the manifest's sectionname - the attribute's namepublic java.util.Map<java.lang.String,java.lang.String> getMapAttribute(java.lang.String name,
java.lang.String defaultValue)
name - the attribute's namepublic java.util.Map<java.lang.String,java.lang.String> getMapAttribute(java.lang.String section,
java.lang.String name,
java.lang.String defaultValue)
section - the manifest's sectionname - the attribute's namepublic Jar addEntry(java.lang.String path, java.io.InputStream is) throws java.io.IOException
path - the entry's path within the JARis - the entry's contentthisjava.io.IOExceptionpublic Jar addEntry(java.lang.String path, byte[] content) throws java.io.IOException
path - the entry's path within the JARcontent - the entry's contentthisjava.io.IOExceptionpublic Jar addEntry(java.nio.file.Path path, java.io.InputStream is) throws java.io.IOException
path - the entry's path within the JARis - the entry's contentthisjava.io.IOExceptionpublic Jar addEntry(java.nio.file.Path path, java.nio.file.Path file) throws java.io.IOException
path - the entry's path within the JARfile - the file to add as an entrythisjava.io.IOExceptionpublic Jar addEntry(java.nio.file.Path path, java.lang.String file) throws java.io.IOException
path - the entry's path within the JARfile - the path of the file to add as an entrythisjava.io.IOExceptionpublic Jar addEntry(java.lang.String path, java.io.File file) throws java.io.IOException
path - the entry's path within the JARfile - the file to add as an entrythisjava.io.IOExceptionpublic Jar addEntry(java.lang.String path, java.lang.String file) throws java.io.IOException
path - the entry's path within the JARfile - the path of the file to add as an entrythisjava.io.IOExceptionpublic Jar addClass(java.lang.Class<?> clazz) throws java.io.IOException
clazz - the class to add to the JAR.thisjava.io.IOExceptionpublic Jar addEntries(java.nio.file.Path path, java.nio.file.Path dirOrZip) throws java.io.IOException
path - the path within the JAR where the root of the directory will be placed, or null for the JAR's rootdirOrZip - the directory to add as an entry or a zip/JAR file whose contents will be extracted and added as entriesthisjava.io.IOExceptionpublic Jar addEntries(java.lang.String path, java.nio.file.Path dirOrZip) throws java.io.IOException
path - the path within the JAR where the root of the directory/zip will be placed, or null for the JAR's rootdirOrZip - the directory to add as an entry or a zip/JAR file whose contents will be extracted and added as entriesthisjava.io.IOExceptionpublic Jar addEntries(java.nio.file.Path path, java.util.zip.ZipInputStream zip) throws java.io.IOException
path - the path within the JAR where the root of the zip will be placed, or null for the JAR's rootzip - the contents of the zip/JAR filethisjava.io.IOExceptionpublic Jar addPackageOf(java.lang.Class<?> clazz) throws java.io.IOException
clazz - A class whose package we wish to add to the JAR.thisjava.io.IOExceptionpublic Jar setPacker(java.util.jar.Pack200.Packer packer)
Pack200 packer to use when writing the JAR.packer - thispublic Jar setReallyExecutable(boolean value)
value - thispublic Jar setJarPrefix(java.lang.String value)
value - the prefix, or null for none.thispublic Jar setJarPrefix(java.nio.file.Path file)
file - the prefix file, or null for none.thispublic <T extends java.io.OutputStream> T write(T os)
throws java.io.IOException
java.io.IOExceptionpublic java.io.File write(java.io.File file)
throws java.io.IOException
java.io.IOExceptionpublic java.nio.file.Path write(java.nio.file.Path path)
throws java.io.IOException
java.io.IOExceptionpublic void write(java.lang.String file)
throws java.io.IOException
java.io.IOExceptionpublic byte[] toByteArray()
public static java.io.InputStream toInputStream(java.lang.String str,
java.nio.charset.Charset charset)
String into an InputStream containing the string's encoded characters.str - the stringcharset - the Charset to use when encoding the string.InputStream containing the string's encoded characters.