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;
}
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());
}
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();
}
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();
}
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);
}
}
Aggregations