Search in sources :

Example 61 with JarOutputStream

use of java.util.jar.JarOutputStream 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 62 with JarOutputStream

use of java.util.jar.JarOutputStream 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 63 with JarOutputStream

use of java.util.jar.JarOutputStream 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 64 with JarOutputStream

use of java.util.jar.JarOutputStream 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)

Example 65 with JarOutputStream

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

the class MultiReleaseVersionTest method createBundle.

private static File createBundle(String manifest, File tempDir) throws IOException {
    File f = File.createTempFile("felix-bundle", ".jar", tempDir);
    Manifest mf = new Manifest(new ByteArrayInputStream(manifest.getBytes("utf-8")));
    mf.getMainAttributes().putValue("Manifest-Version", "1.0");
    // mf.getMainAttributes().putValue(Constants.BUNDLE_ACTIVATOR, StartStopBundleTest.TestBundleActivator.class.getName());
    JarOutputStream os = new JarOutputStream(new FileOutputStream(f), mf);
    String path = Test.class.getName().replace('.', '/') + ".class";
    os.putNextEntry(new ZipEntry("META-INF/versions/9/" + path));
    InputStream is = Test.class.getClassLoader().getResourceAsStream(path);
    byte[] b = new byte[is.available()];
    is.read(b);
    is.close();
    os.write(b);
    os.putNextEntry(new ZipEntry("META-INF/versions/9/OSGI-INF/MANIFEST.MF"));
    Manifest subMF = new Manifest();
    subMF.getMainAttributes().putValue("Import-Package", "org.osgi.framework");
    subMF.getMainAttributes().putValue("Manifest-Version", "1.0");
    subMF.write(os);
    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

JarOutputStream (java.util.jar.JarOutputStream)485 FileOutputStream (java.io.FileOutputStream)308 File (java.io.File)265 JarEntry (java.util.jar.JarEntry)194 Manifest (java.util.jar.Manifest)140 IOException (java.io.IOException)130 ZipEntry (java.util.zip.ZipEntry)116 InputStream (java.io.InputStream)89 FileInputStream (java.io.FileInputStream)84 JarFile (java.util.jar.JarFile)82 ByteArrayOutputStream (java.io.ByteArrayOutputStream)76 ByteArrayInputStream (java.io.ByteArrayInputStream)55 Test (org.junit.Test)55 BufferedOutputStream (java.io.BufferedOutputStream)47 Path (java.nio.file.Path)42 JarInputStream (java.util.jar.JarInputStream)41 OutputStream (java.io.OutputStream)36 Attributes (java.util.jar.Attributes)36 ArrayList (java.util.ArrayList)35 Map (java.util.Map)27