Search in sources :

Example 76 with JarInputStream

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();
    }
}
Also used : JarInputStream(java.util.jar.JarInputStream) JarEntry(java.util.jar.JarEntry) FileInputStream(java.io.FileInputStream)

Example 77 with JarInputStream

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"));
}
Also used : JarInputStream(java.util.jar.JarInputStream) ArrayList(java.util.ArrayList) JarEntry(java.util.jar.JarEntry) File(java.io.File) FileInputStream(java.io.FileInputStream) AbstractCodeGenTest(org.apache.cxf.tools.wsdlto.AbstractCodeGenTest) Test(org.junit.Test)

Example 78 with JarInputStream

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);
}
Also used : JarInputStream(java.util.jar.JarInputStream) KiePackage(org.kie.api.definition.KiePackage) KnowledgeBuilderConfiguration(org.kie.internal.builder.KnowledgeBuilderConfiguration) ByteArrayOutputStream(java.io.ByteArrayOutputStream) MapBackedClassLoader(org.drools.core.rule.MapBackedClassLoader) JarEntry(java.util.jar.JarEntry) EntryPoint(org.kie.api.runtime.rule.EntryPoint) Test(org.junit.Test)

Example 79 with JarInputStream

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;
}
Also used : JarInputStream(java.util.jar.JarInputStream) ZipEntry(java.util.zip.ZipEntry) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 80 with JarInputStream

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);
}
Also used : JarInputStream(java.util.jar.JarInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) JarEntry(java.util.jar.JarEntry) Test(org.junit.Test)

Aggregations

JarInputStream (java.util.jar.JarInputStream)185 JarEntry (java.util.jar.JarEntry)82 IOException (java.io.IOException)73 FileInputStream (java.io.FileInputStream)66 Manifest (java.util.jar.Manifest)56 File (java.io.File)48 InputStream (java.io.InputStream)45 ZipEntry (java.util.zip.ZipEntry)34 JarOutputStream (java.util.jar.JarOutputStream)29 Test (org.junit.Test)29 FileOutputStream (java.io.FileOutputStream)26 ByteArrayInputStream (java.io.ByteArrayInputStream)24 URL (java.net.URL)20 ArrayList (java.util.ArrayList)15 ByteArrayOutputStream (java.io.ByteArrayOutputStream)14 OutputStream (java.io.OutputStream)14 JarFile (java.util.jar.JarFile)14 BufferedInputStream (java.io.BufferedInputStream)11 Attributes (java.util.jar.Attributes)11 HashSet (java.util.HashSet)9