use of java.util.jar.JarInputStream in project ignite by apache.
the class GridJarClassLoader method readJarFile.
/**
* Reads JAR file and stored classes locally.
*
* @param fileName Name of file to read.
* @throws IOException If read failed.
*/
private void readJarFile(String fileName) throws IOException {
JarEntry je;
JarInputStream jis = new JarInputStream(new FileInputStream(fileName));
while ((je = jis.getNextJarEntry()) != null) {
String jarName = je.getName();
if (jarName.endsWith(".class"))
loadClassBytes(jis, jarName);
// Else ignore it; it could be an image or audio file.
jis.closeEntry();
}
}
use of java.util.jar.JarInputStream in project cxf by apache.
the class CodeGenTest method testClientJar.
@Test
public void testClientJar() throws Exception {
env.put(ToolConstants.CFG_WSDLURL, getLocation("/wsdl2java_wsdl/hello_world_wsdl_import.wsdl"));
env.put(ToolConstants.CFG_CLIENT_JAR, "test-client.jar");
processor.setContext(env);
processor.execute();
File clientjarFile = new File(output, "test-client.jar");
assertTrue(clientjarFile.exists());
List<String> jarEntries = new ArrayList<>();
JarInputStream jarIns = new JarInputStream(new FileInputStream(clientjarFile));
JarEntry entry = null;
while ((entry = jarIns.getNextJarEntry()) != null) {
if (entry.getName().endsWith(".wsdl") || entry.getName().endsWith(".class")) {
jarEntries.add(entry.getName());
}
}
jarIns.close();
assertEquals("15 files including wsdl and class files are expected", 15, jarEntries.size());
assertTrue("hello_world_messages.wsdl is expected", jarEntries.contains("hello_world_messages.wsdl"));
assertTrue("org/apache/cxf/w2j/hello_world/SOAPService.class is expected", jarEntries.contains("org/apache/cxf/w2j/hello_world/SOAPService.class"));
}
use of java.util.jar.JarInputStream in project drools by kiegroup.
the class MarshallingTest method testSerializabilityWithJarFacts.
/**
* In this case we are dealing with facts which are not on the systems classpath.
*/
@Test
public void testSerializabilityWithJarFacts() throws Exception {
MapBackedClassLoader loader = new MapBackedClassLoader(this.getClass().getClassLoader());
JarInputStream jis = new JarInputStream(this.getClass().getResourceAsStream("/billasurf.jar"));
JarEntry entry = null;
byte[] buf = new byte[1024];
int len = 0;
while ((entry = jis.getNextJarEntry()) != null) {
if (!entry.isDirectory()) {
ByteArrayOutputStream out = new ByteArrayOutputStream();
while ((len = jis.read(buf)) >= 0) {
out.write(buf, 0, len);
}
loader.addResource(entry.getName(), out.toByteArray());
}
}
String drl = "package foo.bar \n" + "import com.billasurf.Board\n" + "rule 'MyGoodRule' \n dialect 'mvel' \n when " + " Board() " + "then \n" + " System.err.println(42); \n" + "end\n";
KnowledgeBuilderConfiguration kbuilderConf = KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration(null, loader);
Collection<KiePackage> kpkgs = loadKnowledgePackagesFromString(kbuilderConf, drl);
kpkgs = SerializationHelper.serializeObject(kpkgs, loader);
}
use of java.util.jar.JarInputStream in project drools by kiegroup.
the class MemoryFileSystem method readFromJar.
public static MemoryFileSystem readFromJar(InputStream jarFile) {
MemoryFileSystem mfs = new MemoryFileSystem();
JarInputStream zipFile = null;
try {
zipFile = new JarInputStream(jarFile);
ZipEntry entry;
while ((entry = zipFile.getNextEntry()) != null) {
// entry.getSize() is not accurate according to documentation, so have to read bytes until -1 is found
ByteArrayOutputStream content = new ByteArrayOutputStream();
int b;
while ((b = zipFile.read()) != -1) {
content.write(b);
}
mfs.write(entry.getName(), content.toByteArray(), true);
}
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
if (zipFile != null) {
try {
zipFile.close();
} catch (IOException e) {
log.error(e.getMessage(), e);
}
}
}
return mfs;
}
use of java.util.jar.JarInputStream in project drools by kiegroup.
the class JeneratorTest method testRoundTrip.
@Test
public void testRoundTrip() throws Exception {
Fact f = new Fact();
f.name = "Foobar";
Field f1 = new Field();
f1.name = "name";
f1.type = "java.lang.String";
f.fields.add(f1);
Field f2 = new Field();
f2.name = "age";
f2.type = "java.lang.Integer";
f.fields.add(f2);
Fact f_ = new Fact();
f_.name = "Baz";
Field f1_ = new Field();
f1_.name = "name";
f1_.type = "java.lang.String";
f_.fields.add(f1_);
Jenerator jen = new Jenerator();
byte[] data = jen.createJar(new Fact[] { f, f_ }, "whee.waa");
JarInputStream jis = new JarInputStream(new ByteArrayInputStream(data));
JarEntry je = jis.getNextJarEntry();
assertNotNull(je);
System.err.println(je.getName());
assertEquals("factmodel.xml", je.getName());
je = jis.getNextJarEntry();
assertNotNull(je);
System.err.println(je.getName());
assertEquals("whee/waa/Foobar.class", je.getName());
je = jis.getNextJarEntry();
assertNotNull(je);
System.err.println(je.getName());
assertEquals("whee/waa/Baz.class", je.getName());
Fact[] facts = jen.loadMetaModel(new JarInputStream(new ByteArrayInputStream(data)));
assertEquals(2, facts.length);
assertEquals("Foobar", facts[0].name);
assertEquals("Baz", facts[1].name);
}
Aggregations