public class Jar
extends java.lang.Object
implements java.io.Closeable
Modifier and Type | Class and Description |
---|---|
static class |
Jar.Compression |
Modifier and Type | Field and Description |
---|---|
(package private) java.lang.String[] |
algorithms |
(package private) static java.util.regex.Pattern |
BSN |
(package private) static int |
BUFFER_SIZE |
(package private) boolean |
closed |
(package private) Jar.Compression |
compression |
private static java.util.regex.Pattern |
DEFAULT_DO_NOT_COPY |
(package private) static java.lang.String |
DEFAULT_MANIFEST_NAME |
(package private) java.util.TreeMap<java.lang.String,java.util.Map<java.lang.String,Resource>> |
directories |
(package private) boolean |
doNotTouchManifest |
static java.lang.Object[] |
EMPTY_ARRAY |
private static byte[] |
EOL
Unfortunately we have to write our own manifest :-( because of a stupid
bug in the manifest code.
|
(package private) long |
lastModified |
(package private) java.lang.String |
lastModifiedReason |
(package private) java.util.jar.Manifest |
manifest |
(package private) boolean |
manifestFirst |
(package private) java.lang.String |
manifestName |
(package private) java.lang.String |
name |
(package private) boolean |
nomanifest |
(package private) Reporter |
reporter |
(package private) java.util.TreeMap<java.lang.String,Resource> |
resources |
private static byte[] |
SEPARATOR |
(package private) static java.util.regex.Pattern |
SIGNER_FILES_P |
(package private) java.io.File |
source |
(package private) java.util.zip.ZipFile |
zipFile |
Constructor and Description |
---|
Jar(java.io.File f) |
Jar(java.lang.String name) |
Jar(java.lang.String string,
java.io.File file) |
Jar(java.lang.String name,
java.io.File dirOrFile,
java.util.regex.Pattern doNotCopy) |
Jar(java.lang.String string,
java.io.InputStream resourceAsStream) |
Jar(java.lang.String name,
java.io.InputStream in,
long lastModified) |
Jar(java.lang.String name,
java.lang.String path) |
Modifier and Type | Method and Description |
---|---|
boolean |
addAll(Jar src) |
boolean |
addAll(Jar sub,
Instruction filter)
Add all the resources in the given jar that match the given filter.
|
boolean |
addAll(Jar sub,
Instruction filter,
java.lang.String destination)
Add all the resources in the given jar that match the given filter.
|
boolean |
addDirectory(java.util.Map<java.lang.String,Resource> directory,
boolean overwrite) |
private static void |
attributes(java.util.jar.Attributes value,
java.io.OutputStream out)
Output an Attributes map.
|
private Jar |
buildFromDirectory(java.nio.file.Path baseDir,
java.util.regex.Pattern doNotCopy) |
private Jar |
buildFromInputStream(java.io.InputStream in,
long lastModified) |
private Jar |
buildFromResource(Resource resource) |
private Jar |
buildFromZip(java.io.File file) |
void |
calcChecksums(java.lang.String[] algorithms)
Calculate the checksums and set them in the manifest.
|
(package private) void |
check() |
private static java.util.jar.Manifest |
clean(java.util.jar.Manifest org) |
private static java.lang.String |
clean(java.lang.String s) |
void |
close() |
void |
copy(Jar srce,
java.lang.String path,
boolean overwrite) |
private void |
copyResource(java.io.File dir,
java.lang.String path,
Resource resource) |
(package private) void |
createDirectories(java.util.Set<java.lang.String> directories,
java.util.zip.ZipOutputStream zip,
java.lang.String name) |
void |
doChecksums(java.io.OutputStream out) |
private void |
doManifest(java.util.Set<java.lang.String> done,
java.util.zip.ZipOutputStream jout) |
void |
ensureManifest()
Make sure we have a manifest
|
boolean |
exists(java.lang.String path) |
void |
expand(java.io.File dir)
Expand the JAR file to a directory.
|
static Jar |
fromResource(java.lang.String name,
Resource resource) |
java.lang.String |
getBsn()
Get the jar bsn from the
Constants.BUNDLE_SYMBOLICNAME manifest
header. |
java.net.URI |
getDataURI(java.lang.String path,
java.lang.String mime,
int max)
Return a data uri from the JAR.
|
java.util.Map<java.lang.String,java.util.Map<java.lang.String,Resource>> |
getDirectories() |
private java.lang.String |
getDirectory(java.lang.String path) |
java.util.jar.Manifest |
getManifest() |
java.lang.String |
getName() |
private static java.lang.String |
getName(java.io.File f)
Make the JAR file name the project name if we get a src or bin directory.
|
java.util.List<java.lang.String> |
getPackages() |
Resource |
getResource(java.lang.String path) |
java.util.Map<java.lang.String,Resource> |
getResources() |
java.io.File |
getSource() |
byte[] |
getTimelessDigest() |
java.lang.String |
getVersion()
Get the jar version from the
Constants.BUNDLE_VERSION manifest
header. |
Jar.Compression |
hasCompression() |
boolean |
hasDirectory(java.lang.String path) |
boolean |
isManifestFirst()
Answer if the manifest was the first entry
|
long |
lastModified() |
static void |
outputManifest(java.util.jar.Manifest manifest,
java.io.OutputStream out)
Main function to output a manifest properly in UTF-8.
|
private java.lang.String |
padString(java.lang.String s,
int length,
char pad) |
boolean |
putResource(java.lang.String path,
Resource resource) |
boolean |
putResource(java.lang.String path,
Resource resource,
boolean overwrite) |
Resource |
remove(java.lang.String path) |
void |
removePrefix(java.lang.String prefixLow) |
boolean |
rename(java.lang.String oldPath,
java.lang.String newPath) |
void |
setCompression(Jar.Compression compression) |
void |
setDigestAlgorithms(java.lang.String[] algorithms) |
void |
setDoNotTouchManifest()
Make sure nobody touches the manifest! If the bundle is signed, we do not
want anybody to touch the manifest after the digests have been
calculated.
|
void |
setManifest(java.io.File file) |
void |
setManifest(java.util.jar.Manifest manifest) |
void |
setManifestName(java.lang.String manifestName) |
void |
setName(java.lang.String name) |
void |
setReporter(Reporter reporter) |
void |
stripSignatures() |
java.lang.String |
toString() |
void |
updateModified(long time,
java.lang.String reason) |
void |
write(java.io.File file) |
void |
write(java.io.OutputStream out) |
private static int |
write(java.io.OutputStream out,
int width,
byte[] bytes)
Write the bytes but ensure that the line length does not exceed 72
characters.
|
private static int |
write(java.io.OutputStream out,
int width,
java.lang.String s)
Convert a string to bytes with UTF-8 and then output in max 72 bytes
|
void |
write(java.lang.String file) |
private static void |
writeEntry(java.io.OutputStream out,
java.lang.String name,
java.lang.String value)
Write out an entry, handling proper unicode and line length constraints
|
void |
writeFolder(java.io.File dir) |
static void |
writeManifest(java.util.jar.Manifest manifest,
java.io.OutputStream out) |
void |
writeManifest(java.io.OutputStream out)
Cleanup the manifest for writing.
|
private void |
writeResource(java.util.zip.ZipOutputStream jout,
java.util.Set<java.lang.String> directories,
java.lang.String path,
Resource resource) |
static final int BUFFER_SIZE
static final java.lang.String DEFAULT_MANIFEST_NAME
private static final java.util.regex.Pattern DEFAULT_DO_NOT_COPY
public static final java.lang.Object[] EMPTY_ARRAY
final java.util.TreeMap<java.lang.String,Resource> resources
final java.util.TreeMap<java.lang.String,java.util.Map<java.lang.String,Resource>> directories
java.util.jar.Manifest manifest
boolean manifestFirst
java.lang.String manifestName
java.lang.String name
java.io.File source
java.util.zip.ZipFile zipFile
long lastModified
java.lang.String lastModifiedReason
Reporter reporter
boolean doNotTouchManifest
boolean nomanifest
Jar.Compression compression
boolean closed
java.lang.String[] algorithms
private static final byte[] EOL
'Manifest-Version: 1.0\r\n' main-attributes * \r\n name-section main-attributes ::= attributes attributes ::= key ': ' value '\r\n' name-section ::= 'Name: ' name '\r\n' attributesLines in the manifest should not exceed 72 bytes (! this is where the manifest screwed up as well when 16 bit unicodes were used).
As a bonus, we can now sort the manifest!
private static final byte[] SEPARATOR
static final java.util.regex.Pattern BSN
static java.util.regex.Pattern SIGNER_FILES_P
public Jar(java.lang.String name)
public Jar(java.lang.String name, java.io.File dirOrFile, java.util.regex.Pattern doNotCopy) throws java.util.zip.ZipException, java.io.IOException
java.util.zip.ZipException
java.io.IOException
public Jar(java.lang.String name, java.io.InputStream in, long lastModified) throws java.io.IOException
java.io.IOException
public Jar(java.lang.String name, java.lang.String path) throws java.io.IOException
java.io.IOException
public Jar(java.io.File f) throws java.io.IOException
java.io.IOException
public Jar(java.lang.String string, java.io.InputStream resourceAsStream) throws java.io.IOException
java.io.IOException
public Jar(java.lang.String string, java.io.File file) throws java.util.zip.ZipException, java.io.IOException
java.util.zip.ZipException
java.io.IOException
public static Jar fromResource(java.lang.String name, Resource resource) throws java.lang.Exception
java.lang.Exception
private static java.lang.String getName(java.io.File f)
f
- private Jar buildFromDirectory(java.nio.file.Path baseDir, java.util.regex.Pattern doNotCopy) throws java.io.IOException
java.io.IOException
private Jar buildFromZip(java.io.File file) throws java.io.IOException
java.io.IOException
private Jar buildFromResource(Resource resource) throws java.lang.Exception
java.lang.Exception
private Jar buildFromInputStream(java.io.InputStream in, long lastModified) throws java.io.IOException
java.io.IOException
public void setName(java.lang.String name)
public java.lang.String toString()
toString
in class java.lang.Object
public boolean putResource(java.lang.String path, Resource resource)
public boolean putResource(java.lang.String path, Resource resource, boolean overwrite)
public Resource getResource(java.lang.String path)
private java.lang.String getDirectory(java.lang.String path)
public java.util.Map<java.lang.String,java.util.Map<java.lang.String,Resource>> getDirectories()
public java.util.Map<java.lang.String,Resource> getResources()
public boolean addDirectory(java.util.Map<java.lang.String,Resource> directory, boolean overwrite)
public java.util.jar.Manifest getManifest() throws java.lang.Exception
java.lang.Exception
public boolean exists(java.lang.String path)
public void setManifest(java.util.jar.Manifest manifest)
public void setManifest(java.io.File file) throws java.io.IOException
java.io.IOException
public void setManifestName(java.lang.String manifestName)
public void write(java.io.File file) throws java.lang.Exception
java.lang.Exception
public void write(java.lang.String file) throws java.lang.Exception
java.lang.Exception
public void write(java.io.OutputStream out) throws java.lang.Exception
java.lang.Exception
public void writeFolder(java.io.File dir) throws java.lang.Exception
java.lang.Exception
private void copyResource(java.io.File dir, java.lang.String path, Resource resource) throws java.io.IOException, java.lang.Exception
java.io.IOException
java.lang.Exception
public void doChecksums(java.io.OutputStream out) throws java.io.IOException, java.lang.Exception
java.io.IOException
java.lang.Exception
private java.lang.String padString(java.lang.String s, int length, char pad)
private void doManifest(java.util.Set<java.lang.String> done, java.util.zip.ZipOutputStream jout) throws java.lang.Exception
java.lang.Exception
public void writeManifest(java.io.OutputStream out) throws java.lang.Exception
out
- Outputjava.io.IOException
java.lang.Exception
public static void writeManifest(java.util.jar.Manifest manifest, java.io.OutputStream out) throws java.io.IOException
java.io.IOException
public static void outputManifest(java.util.jar.Manifest manifest, java.io.OutputStream out) throws java.io.IOException
manifest
- The manifest to outputout
- The output streamjava.io.IOException
- when something failsprivate static void writeEntry(java.io.OutputStream out, java.lang.String name, java.lang.String value) throws java.io.IOException
java.io.IOException
private static int write(java.io.OutputStream out, int width, java.lang.String s) throws java.io.IOException
out
- the output stringwidth
- the current widths
- the string to outputjava.io.IOException
- when something failsprivate static int write(java.io.OutputStream out, int width, byte[] bytes) throws java.io.IOException
out
- The output streamwidth
- The nr of characters output in a line before this method
startedbytes
- the bytes to outputjava.io.IOException
- if something failsprivate static void attributes(java.util.jar.Attributes value, java.io.OutputStream out) throws java.io.IOException
value
- the attrbutesout
- the output streamjava.io.IOException
- when something failsprivate static java.util.jar.Manifest clean(java.util.jar.Manifest org)
private static java.lang.String clean(java.lang.String s)
private void writeResource(java.util.zip.ZipOutputStream jout, java.util.Set<java.lang.String> directories, java.lang.String path, Resource resource) throws java.lang.Exception
java.lang.Exception
void createDirectories(java.util.Set<java.lang.String> directories, java.util.zip.ZipOutputStream zip, java.lang.String name) throws java.io.IOException
java.io.IOException
public java.lang.String getName()
public boolean addAll(Jar sub, Instruction filter)
sub
- the jarfilter
- a pattern that should match the resoures in sub to be addedpublic boolean addAll(Jar sub, Instruction filter, java.lang.String destination)
sub
- the jarfilter
- a pattern that should match the resoures in sub to be addedpublic void close()
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
public long lastModified()
public void updateModified(long time, java.lang.String reason)
public void setReporter(Reporter reporter)
public boolean hasDirectory(java.lang.String path)
public java.util.List<java.lang.String> getPackages()
public java.io.File getSource()
public boolean addAll(Jar src)
public boolean rename(java.lang.String oldPath, java.lang.String newPath)
public Resource remove(java.lang.String path)
public void setDoNotTouchManifest()
public void calcChecksums(java.lang.String[] algorithms) throws java.lang.Exception
java.lang.Exception
public java.lang.String getBsn() throws java.lang.Exception
Constants.BUNDLE_SYMBOLICNAME
manifest
header.Constants.BUNDLE_SYMBOLICNAME
header, or when the value
of the header is not a valid bsn according to BSN
.java.lang.Exception
- when the jar is closed or when the manifest could not
be retrieved.public java.lang.String getVersion() throws java.lang.Exception
Constants.BUNDLE_VERSION
manifest
header.Constants.BUNDLE_VERSION
headerjava.lang.Exception
- when the jar is closed or when the manifest could not
be retrieved.public void expand(java.io.File dir) throws java.lang.Exception
dir
- the dst directory, is not required to existjava.lang.Exception
- if anything does not work as expected.public void ensureManifest() throws java.lang.Exception
java.lang.Exception
public boolean isManifestFirst()
public void copy(Jar srce, java.lang.String path, boolean overwrite)
public void setCompression(Jar.Compression compression)
public Jar.Compression hasCompression()
void check()
public java.net.URI getDataURI(java.lang.String path, java.lang.String mime, int max) throws java.lang.Exception
path
- the path in the jarmime
- the mime typejava.lang.Exception
public void setDigestAlgorithms(java.lang.String[] algorithms)
public byte[] getTimelessDigest() throws java.lang.Exception
java.lang.Exception
public void stripSignatures()
public void removePrefix(java.lang.String prefixLow)