Search in sources :

Example 91 with JarOutputStream

use of java.util.jar.JarOutputStream in project knime-core by knime.

the class JavaSnippet method createJSnippetJarFile.

/**
 * Give jar file with all *.class files returned by getManipulators(ALL_CATEGORY).
 *
 * @return file object of a jar file with all compiled manipulators
 * @throws IOException if jar file cannot be created
 */
private static File createJSnippetJarFile() throws IOException {
    Collection<Object> classes = new ArrayList<>();
    classes.add(AbstractJSnippet.class);
    classes.add(Abort.class);
    classes.add(Cell.class);
    classes.add(ColumnException.class);
    classes.add(FlowVariableException.class);
    classes.add(Type.class);
    classes.add(TypeException.class);
    classes.add(NodeLogger.class);
    classes.add(KNIMEConstants.class);
    // create tree structure for classes
    DefaultMutableTreeNode root = createTree(classes);
    File jarFile = FileUtil.createTempFile("jsnippet", ".jar", new File(KNIMEConstants.getKNIMETempDir()), true);
    try (JarOutputStream jar = new JarOutputStream(new FileOutputStream(jarFile))) {
        createJar(root, jar, null);
    }
    return jarFile;
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) FileOutputStream(java.io.FileOutputStream) ArrayList(java.util.ArrayList) JarOutputStream(java.util.jar.JarOutputStream) EclipseFileObject(org.eclipse.jdt.internal.compiler.tool.EclipseFileObject) JavaFileObject(javax.tools.JavaFileObject) File(java.io.File) BundleFile(org.eclipse.osgi.storage.bundlefile.BundleFile)

Example 92 with JarOutputStream

use of java.util.jar.JarOutputStream in project OpenGrok by OpenGrok.

the class AnalyzerGuruTest method testJar.

@Test
public void testJar() throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    JarOutputStream jos = new JarOutputStream(baos);
    jos.putNextEntry(new JarEntry("dummy"));
    jos.closeEntry();
    jos.close();
    InputStream in = new ByteArrayInputStream(baos.toByteArray());
    FileAnalyzer fa = AnalyzerGuru.getAnalyzer(in, "dummy");
    assertSame(JarAnalyzer.class, fa.getClass());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) JarOutputStream(java.util.jar.JarOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) JarEntry(java.util.jar.JarEntry) Test(org.junit.Test)

Example 93 with JarOutputStream

use of java.util.jar.JarOutputStream in project drools by kiegroup.

the class Jenerator method createJar.

public byte[] createJar(Fact[] facts, String packageName) throws SecurityException, IllegalArgumentException, IOException, ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException, NoSuchFieldException {
    ByteArrayOutputStream result = new ByteArrayOutputStream();
    JarOutputStream jout = new JarOutputStream(result);
    JarEntry metaModel = new JarEntry("factmodel.xml");
    jout.putNextEntry(metaModel);
    jout.write(toXML(facts));
    jout.closeEntry();
    String packagePath = packageName.replace('.', '/');
    for (int i = 0; i < facts.length; i++) {
        ClassBuilder cb = new ClassBuilderFactory().getBeanClassBuilder();
        ClassDefinition classDef = new ClassDefinition(packageName, null, new String[] { "java.io.Serializable" });
        for (int j = 0; j < facts[i].fields.size(); j++) {
            Field fd = (Field) facts[i].fields.get(j);
            classDef.addField(new FieldDefinition(fd.name, fd.type));
        }
        JarEntry je = new JarEntry(packagePath + "/" + facts[i].name + ".class");
        jout.putNextEntry(je);
        jout.write(cb.buildClass(classDef, classLoader));
        jout.closeEntry();
    }
    jout.flush();
    jout.close();
    return result.toByteArray();
}
Also used : JarOutputStream(java.util.jar.JarOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) JarEntry(java.util.jar.JarEntry)

Example 94 with JarOutputStream

use of java.util.jar.JarOutputStream in project drools by kiegroup.

the class ClassBuilderTest method writeJar.

/**
 * how to write to a jar.
 * @param data
 * @throws FileNotFoundException
 * @throws IOException
 */
private void writeJar(byte[] data) throws FileNotFoundException, IOException {
    FileOutputStream out = new FileOutputStream(new File("/Users/michaelneale/edson.jar"));
    JarOutputStream jout = new JarOutputStream(out);
    JarEntry je = new JarEntry("br/com/auster/TestClass1.class");
    jout.putNextEntry(je);
    jout.write(data);
    jout.closeEntry();
    jout.close();
}
Also used : FileOutputStream(java.io.FileOutputStream) JarOutputStream(java.util.jar.JarOutputStream) JarEntry(java.util.jar.JarEntry) File(java.io.File)

Example 95 with JarOutputStream

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

the class KarServiceImpl method create.

@Override
public void create(String repoName, List<String> features, PrintStream console) {
    FileOutputStream fos = null;
    JarOutputStream jos = null;
    try {
        Repository repo = featuresService.getRepository(repoName);
        if (repo == null) {
            throw new RuntimeException("Could not find a repository with name " + repoName);
        }
        String karPath = storage + File.separator + repoName + ".kar";
        File karFile = new File(karPath);
        karFile.getParentFile().mkdirs();
        fos = new FileOutputStream(karFile);
        Manifest manifest = createNonAutoStartManifest(repo.getURI());
        jos = new JarOutputStream(new BufferedOutputStream(fos, 100000), manifest);
        Map<URI, Integer> locationMap = new HashMap<>();
        copyResourceToJar(jos, repo.getURI(), locationMap);
        Map<String, Feature> featureMap = new HashMap<>();
        for (Feature feature : repo.getFeatures()) {
            featureMap.put(feature.getName(), feature);
        }
        Set<Feature> featuresToCopy = getFeatures(featureMap, features, 1);
        for (Feature feature : featuresToCopy) {
            if (console != null)
                console.println("Adding feature " + feature.getName());
            copyFeatureToJar(jos, feature, locationMap);
        }
        if (console != null)
            console.println("Kar file created : " + karPath);
    } catch (Exception e) {
        throw new RuntimeException("Error creating kar: " + e.getMessage(), e);
    } finally {
        closeStream(jos);
        closeStream(fos);
    }
}
Also used : HashMap(java.util.HashMap) JarOutputStream(java.util.jar.JarOutputStream) Manifest(java.util.jar.Manifest) URI(java.net.URI) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) FileOutputStream(java.io.FileOutputStream) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream)

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