aQute.bnd.osgi
Class Jar

java.lang.Object
  extended by aQute.bnd.osgi.Jar
All Implemented Interfaces:
Closeable

public class Jar
extends Object
implements Closeable


Nested Class Summary
static class Jar.Compression
           
 
Field Summary
static Object[] EMPTY_ARRAY
           
 
Constructor Summary
Jar(File f)
           
Jar(String name)
           
Jar(String string, File file)
           
Jar(String name, File dirOrFile, Pattern doNotCopy)
           
Jar(String string, InputStream resourceAsStream)
           
Jar(String name, InputStream in, long lastModified)
           
Jar(String name, String path)
           
 
Method Summary
 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, String destination)
          Add all the resources in the given jar that match the given filter.
 boolean addDirectory(Map<String,Resource> directory, boolean overwrite)
           
 void calcChecksums(String[] algorithms)
          Calculate the checksums and set them in the manifest.
 void close()
           
 void copy(Jar srce, String path, boolean overwrite)
           
 void ensureManifest()
          Make sure we have a manifest
 boolean exists(String path)
           
 void expand(File dir)
          Expand the JAR file to a directory.
 String getBsn()
          Get the jar bsn from the Constants.BUNDLE_SYMBOLICNAME manifest header.
 URI getDataURI(String path, String mime, int max)
          Return a data uri from the JAR.
 Map<String,Map<String,Resource>> getDirectories()
           
 Manifest getManifest()
           
 String getName()
           
 List<String> getPackages()
           
 Resource getResource(String path)
           
 Map<String,Resource> getResources()
           
 File getSource()
           
 byte[] getTimelessDigest()
           
 String getVersion()
          Get the jar version from the Constants.BUNDLE_VERSION manifest header.
 Jar.Compression hasCompression()
           
 boolean hasDirectory(String path)
           
 boolean isManifestFirst()
          Answer if the manifest was the first entry
 long lastModified()
           
static void outputManifest(Manifest manifest, OutputStream out)
          Main function to output a manifest properly in UTF-8.
 boolean putResource(String path, Resource resource)
           
 boolean putResource(String path, Resource resource, boolean overwrite)
           
 Resource remove(String path)
           
 boolean rename(String oldPath, String newPath)
           
 void setCompression(Jar.Compression compression)
           
 void setDigestAlgorithms(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(File file)
           
 void setManifest(Manifest manifest)
           
 void setManifestName(String manifestName)
           
 void setName(String name)
           
 void setReporter(Reporter reporter)
           
 String toString()
           
 void updateModified(long time, String reason)
           
 void write(File file)
           
 void write(OutputStream out)
           
 void write(String file)
           
static void writeManifest(Manifest manifest, OutputStream out)
           
 void writeManifest(OutputStream out)
          Cleanup the manifest for writing.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

EMPTY_ARRAY

public static final Object[] EMPTY_ARRAY
Constructor Detail

Jar

public Jar(String name)

Jar

public Jar(String name,
           File dirOrFile,
           Pattern doNotCopy)
    throws ZipException,
           IOException
Throws:
ZipException
IOException

Jar

public Jar(String name,
           InputStream in,
           long lastModified)
    throws IOException
Throws:
IOException

Jar

public Jar(String name,
           String path)
    throws IOException
Throws:
IOException

Jar

public Jar(File f)
    throws IOException
Throws:
IOException

Jar

public Jar(String string,
           InputStream resourceAsStream)
    throws IOException
Throws:
IOException

Jar

public Jar(String string,
           File file)
    throws ZipException,
           IOException
Throws:
ZipException
IOException
Method Detail

setName

public void setName(String name)

toString

public String toString()
Overrides:
toString in class Object

putResource

public boolean putResource(String path,
                           Resource resource)

putResource

public boolean putResource(String path,
                           Resource resource,
                           boolean overwrite)

getResource

public Resource getResource(String path)

getDirectories

public Map<String,Map<String,Resource>> getDirectories()

getResources

public Map<String,Resource> getResources()

addDirectory

public boolean addDirectory(Map<String,Resource> directory,
                            boolean overwrite)

getManifest

public Manifest getManifest()
                     throws Exception
Throws:
Exception

exists

public boolean exists(String path)

setManifest

public void setManifest(Manifest manifest)

setManifest

public void setManifest(File file)
                 throws IOException
Throws:
IOException

setManifestName

public void setManifestName(String manifestName)

write

public void write(File file)
           throws Exception
Throws:
Exception

write

public void write(String file)
           throws Exception
Throws:
Exception

write

public void write(OutputStream out)
           throws Exception
Throws:
Exception

writeManifest

public void writeManifest(OutputStream out)
                   throws Exception
Cleanup the manifest for writing. Cleaning up consists of adding a space after any \n to prevent the manifest to see this newline as a delimiter.

Parameters:
out - Output
Throws:
IOException
Exception

writeManifest

public static void writeManifest(Manifest manifest,
                                 OutputStream out)
                          throws IOException
Throws:
IOException

outputManifest

public static void outputManifest(Manifest manifest,
                                  OutputStream out)
                           throws IOException
Main function to output a manifest properly in UTF-8.

Parameters:
manifest - The manifest to output
out - The output stream
Throws:
IOException - when something fails

getName

public String getName()

addAll

public boolean addAll(Jar sub,
                      Instruction filter)
Add all the resources in the given jar that match the given filter.

Parameters:
sub - the jar
filter - a pattern that should match the resoures in sub to be added

addAll

public boolean addAll(Jar sub,
                      Instruction filter,
                      String destination)
Add all the resources in the given jar that match the given filter.

Parameters:
sub - the jar
filter - a pattern that should match the resoures in sub to be added

close

public void close()
Specified by:
close in interface Closeable

lastModified

public long lastModified()

updateModified

public void updateModified(long time,
                           String reason)

setReporter

public void setReporter(Reporter reporter)

hasDirectory

public boolean hasDirectory(String path)

getPackages

public List<String> getPackages()

getSource

public File getSource()

addAll

public boolean addAll(Jar src)

rename

public boolean rename(String oldPath,
                      String newPath)

remove

public Resource remove(String path)

setDoNotTouchManifest

public 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.


calcChecksums

public void calcChecksums(String[] algorithms)
                   throws Exception
Calculate the checksums and set them in the manifest.

Throws:
Exception

getBsn

public String getBsn()
              throws Exception
Get the jar bsn from the Constants.BUNDLE_SYMBOLICNAME manifest header.

Returns:
null when the jar has no manifest, when the manifest has no Constants.BUNDLE_SYMBOLICNAME header, or when the value of the header is not a valid bsn according to BSN.
Throws:
Exception - when the jar is closed or when the manifest could not be retrieved.

getVersion

public String getVersion()
                  throws Exception
Get the jar version from the Constants.BUNDLE_VERSION manifest header.

Returns:
null when the jar has no manifest or when the manifest has no Constants.BUNDLE_VERSION header
Throws:
Exception - when the jar is closed or when the manifest could not be retrieved.

expand

public void expand(File dir)
            throws Exception
Expand the JAR file to a directory.

Parameters:
dir - the dst directory, is not required to exist
Throws:
Exception - if anything does not work as expected.

ensureManifest

public void ensureManifest()
                    throws Exception
Make sure we have a manifest

Throws:
Exception

isManifestFirst

public boolean isManifestFirst()
Answer if the manifest was the first entry


copy

public void copy(Jar srce,
                 String path,
                 boolean overwrite)

setCompression

public void setCompression(Jar.Compression compression)

hasCompression

public Jar.Compression hasCompression()

getDataURI

public URI getDataURI(String path,
                      String mime,
                      int max)
               throws Exception
Return a data uri from the JAR. The data must be less than 32k

Parameters:
jar - The jar to load the data from
path - the path in the jar
mime - the mime type
Returns:
a URI or null if conversion could not take place
Throws:
Exception

setDigestAlgorithms

public void setDigestAlgorithms(String[] algorithms)

getTimelessDigest

public byte[] getTimelessDigest()
                         throws Exception
Throws:
Exception


Copyright © 2014 aQute SARL. All rights reserved.