A Swiss Army Knife for OSGi

aQute.lib.osgi
Class Jar

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

public class Jar
extends java.lang.Object
implements java.io.Closeable


Field Summary
static java.lang.Object[] EMPTY_ARRAY
           
 
Constructor Summary
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)
           
 
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, 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)
           
 void calcChecksums(java.lang.String[] algorithms)
          Calculate the checksums and set them in the manifest.
 void close()
           
 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.
 java.lang.String getBsn()
           
 java.util.Map<java.lang.String,java.util.Map<java.lang.String,Resource>> getDirectories()
           
 java.util.jar.Manifest getManifest()
           
 java.lang.String getName()
           
 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()
           
 java.lang.String getVersion()
           
 boolean hasDirectory(java.lang.String path)
           
 long lastModified()
           
static void outputManifest(java.util.jar.Manifest manifest, java.io.OutputStream out)
          Main function to output a manifest properly in UTF-8.
 boolean putResource(java.lang.String path, Resource resource)
           
 boolean putResource(java.lang.String path, Resource resource, boolean overwrite)
           
 Resource remove(java.lang.String path)
           
 boolean rename(java.lang.String oldPath, java.lang.String newPath)
           
 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.util.jar.Manifest manifest)
           
 void setName(java.lang.String name)
           
 void setReporter(Reporter reporter)
           
 java.lang.String toString()
           
 void updateModified(long time, java.lang.String reason)
           
 void write(java.io.File file)
           
 void write(java.io.OutputStream out)
           
 void write(java.lang.String file)
           
static void writeManifest(java.util.jar.Manifest manifest, java.io.OutputStream out)
           
 void writeManifest(java.io.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 java.lang.Object[] EMPTY_ARRAY
Constructor Detail

Jar

public Jar(java.lang.String name)

Jar

public Jar(java.lang.String name,
           java.io.File dirOrFile,
           java.util.regex.Pattern doNotCopy)
    throws java.util.zip.ZipException,
           java.io.IOException
Throws:
java.util.zip.ZipException
java.io.IOException

Jar

public Jar(java.lang.String name,
           java.io.InputStream in,
           long lastModified)
    throws java.io.IOException
Throws:
java.io.IOException

Jar

public Jar(java.lang.String name,
           java.lang.String path)
    throws java.io.IOException
Throws:
java.io.IOException

Jar

public Jar(java.io.File f)
    throws java.io.IOException
Throws:
java.io.IOException

Jar

public Jar(java.lang.String string,
           java.io.InputStream resourceAsStream)
    throws java.io.IOException
Throws:
java.io.IOException

Jar

public Jar(java.lang.String string,
           java.io.File file)
    throws java.util.zip.ZipException,
           java.io.IOException
Throws:
java.util.zip.ZipException
java.io.IOException
Method Detail

setName

public void setName(java.lang.String name)

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

putResource

public boolean putResource(java.lang.String path,
                           Resource resource)

putResource

public boolean putResource(java.lang.String path,
                           Resource resource,
                           boolean overwrite)

getResource

public Resource getResource(java.lang.String path)

getDirectories

public java.util.Map<java.lang.String,java.util.Map<java.lang.String,Resource>> getDirectories()

getResources

public java.util.Map<java.lang.String,Resource> getResources()

addDirectory

public boolean addDirectory(java.util.Map<java.lang.String,Resource> directory,
                            boolean overwrite)

getManifest

public java.util.jar.Manifest getManifest()
                                   throws java.lang.Exception
Throws:
java.lang.Exception

exists

public boolean exists(java.lang.String path)

setManifest

public void setManifest(java.util.jar.Manifest manifest)

write

public void write(java.io.File file)
           throws java.lang.Exception
Throws:
java.lang.Exception

write

public void write(java.lang.String file)
           throws java.lang.Exception
Throws:
java.lang.Exception

write

public void write(java.io.OutputStream out)
           throws java.lang.Exception
Throws:
java.lang.Exception

writeManifest

public void writeManifest(java.io.OutputStream out)
                   throws java.lang.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:
java.io.IOException
java.lang.Exception

writeManifest

public static void writeManifest(java.util.jar.Manifest manifest,
                                 java.io.OutputStream out)
                          throws java.io.IOException
Throws:
java.io.IOException

outputManifest

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

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

getName

public java.lang.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,
                      java.lang.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 java.io.Closeable

lastModified

public long lastModified()

updateModified

public void updateModified(long time,
                           java.lang.String reason)

setReporter

public void setReporter(Reporter reporter)

hasDirectory

public boolean hasDirectory(java.lang.String path)

getPackages

public java.util.List<java.lang.String> getPackages()

getSource

public java.io.File getSource()

addAll

public boolean addAll(Jar src)

rename

public boolean rename(java.lang.String oldPath,
                      java.lang.String newPath)

remove

public Resource remove(java.lang.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(java.lang.String[] algorithms)
                   throws java.lang.Exception
Calculate the checksums and set them in the manifest.

Throws:
java.lang.Exception

getBsn

public java.lang.String getBsn()
                        throws java.lang.Exception
Throws:
java.lang.Exception

getVersion

public java.lang.String getVersion()
                            throws java.lang.Exception
Throws:
java.lang.Exception

expand

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

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

ensureManifest

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

Throws:
java.lang.Exception

Licensed under Apache Software License 2.0

Copyright å© aQute SARL (2000, 2011). All Rights Reserved.