Search in sources :

Example 96 with Manifest

use of java.util.jar.Manifest in project felix by apache.

the class BootLoaderTest method createBundle.

private static File createBundle(String manifest) throws IOException {
    File f = File.createTempFile("felix-bundle", ".jar");
    f.deleteOnExit();
    Manifest mf = new Manifest(new ByteArrayInputStream(manifest.getBytes("utf-8")));
    mf.getMainAttributes().putValue("Manifest-Version", "1.0");
    JarOutputStream os = new JarOutputStream(new FileOutputStream(f), mf);
    os.close();
    return f;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) FileOutputStream(java.io.FileOutputStream) JarOutputStream(java.util.jar.JarOutputStream) Manifest(java.util.jar.Manifest) File(java.io.File)

Example 97 with Manifest

use of java.util.jar.Manifest in project felix by apache.

the class CycleDetectionWithWovenClassTest method createBundle.

private static File createBundle(String manifest, Class... classes) throws IOException {
    File f = File.createTempFile("felix-bundle", ".jar");
    f.deleteOnExit();
    Manifest mf = new Manifest(new ByteArrayInputStream(manifest.getBytes("utf-8")));
    JarOutputStream os = new JarOutputStream(new FileOutputStream(f), mf);
    for (Class clazz : classes) {
        String path = clazz.getName().replace('.', '/') + ".class";
        os.putNextEntry(new ZipEntry(path));
        InputStream is = clazz.getClassLoader().getResourceAsStream(path);
        byte[] buffer = new byte[8 * 1024];
        for (int i = is.read(buffer); i != -1; i = is.read(buffer)) {
            os.write(buffer, 0, i);
        }
        is.close();
        os.closeEntry();
    }
    os.close();
    return f;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) FileOutputStream(java.io.FileOutputStream) ZipEntry(java.util.zip.ZipEntry) JarOutputStream(java.util.jar.JarOutputStream) WovenClass(org.osgi.framework.hooks.weaving.WovenClass) Manifest(java.util.jar.Manifest) File(java.io.File)

Example 98 with Manifest

use of java.util.jar.Manifest in project felix by apache.

the class DTOFactoryTest method createBundle.

private File createBundle(String manifest) throws IOException {
    File f = File.createTempFile("felix-bundle" + counter++, ".jar", testDir);
    Manifest mf = new Manifest(new ByteArrayInputStream(manifest.getBytes("utf-8")));
    mf.getMainAttributes().putValue("Manifest-Version", "1.0");
    JarOutputStream os = new JarOutputStream(new FileOutputStream(f), mf);
    os.close();
    return f;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) FileOutputStream(java.io.FileOutputStream) JarOutputStream(java.util.jar.JarOutputStream) Manifest(java.util.jar.Manifest) File(java.io.File)

Example 99 with Manifest

use of java.util.jar.Manifest in project felix by apache.

the class ExtensionManagerTest method createExtensionBundle.

private File createExtensionBundle() throws IOException {
    File f = File.createTempFile("felix-bundle" + counter++, ".jar", testDir);
    Manifest mf = new Manifest();
    mf.getMainAttributes().putValue("Manifest-Version", "1.0");
    mf.getMainAttributes().putValue(Constants.BUNDLE_SYMBOLICNAME, "extension-bundle");
    mf.getMainAttributes().putValue(Constants.BUNDLE_VERSION, "3.2.1");
    mf.getMainAttributes().putValue(Constants.FRAGMENT_HOST, "system.bundle;extension:=framework");
    mf.getMainAttributes().putValue(Constants.BUNDLE_MANIFESTVERSION, "2");
    mf.getMainAttributes().putValue(Constants.EXTENSION_BUNDLE_ACTIVATOR, TestActivator.class.getName());
    JarOutputStream os = new JarOutputStream(new FileOutputStream(f), mf);
    String path = TestActivator.class.getName().replace('.', '/') + ".class";
    os.putNextEntry(new ZipEntry(path));
    InputStream is = TestActivator.class.getClassLoader().getResourceAsStream(path);
    pumpStreams(is, os);
    is.close();
    os.close();
    return f;
}
Also used : InputStream(java.io.InputStream) FileOutputStream(java.io.FileOutputStream) ZipEntry(java.util.zip.ZipEntry) JarOutputStream(java.util.jar.JarOutputStream) Manifest(java.util.jar.Manifest) File(java.io.File)

Example 100 with Manifest

use of java.util.jar.Manifest in project felix by apache.

the class ImplicitBootDelegationTest method createBundle.

private static File createBundle(String manifest, Class... classes) throws IOException {
    File f = File.createTempFile("felix-bundle", ".jar");
    f.deleteOnExit();
    Manifest mf = new Manifest(new ByteArrayInputStream(manifest.getBytes("utf-8")));
    JarOutputStream os = new JarOutputStream(new FileOutputStream(f), mf);
    for (Class clazz : classes) {
        String path = clazz.getName().replace('.', '/') + ".class";
        os.putNextEntry(new ZipEntry(path));
        InputStream is = clazz.getClassLoader().getResourceAsStream(path);
        byte[] buffer = new byte[8 * 1024];
        for (int i = is.read(buffer); i != -1; i = is.read(buffer)) {
            os.write(buffer, 0, i);
        }
        is.close();
        os.closeEntry();
    }
    os.close();
    return f;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) FileOutputStream(java.io.FileOutputStream) ZipEntry(java.util.zip.ZipEntry) JarOutputStream(java.util.jar.JarOutputStream) Manifest(java.util.jar.Manifest) File(java.io.File)

Aggregations

Manifest (java.util.jar.Manifest)1226 Attributes (java.util.jar.Attributes)392 File (java.io.File)391 IOException (java.io.IOException)336 JarFile (java.util.jar.JarFile)231 InputStream (java.io.InputStream)184 URL (java.net.URL)177 JarOutputStream (java.util.jar.JarOutputStream)145 FileOutputStream (java.io.FileOutputStream)131 Test (org.junit.Test)129 FileInputStream (java.io.FileInputStream)119 Jar (aQute.bnd.osgi.Jar)105 JarInputStream (java.util.jar.JarInputStream)104 Builder (aQute.bnd.osgi.Builder)99 ZipEntry (java.util.zip.ZipEntry)99 ByteArrayOutputStream (java.io.ByteArrayOutputStream)96 JarEntry (java.util.jar.JarEntry)96 ByteArrayInputStream (java.io.ByteArrayInputStream)93 ArrayList (java.util.ArrayList)83 Map (java.util.Map)83