Examples of JarInputStream


Examples of java.util.jar.JarInputStream

     * NOT source.
     */
    private void addFromDDJInputStream(InputStream jarInputStream) throws IOException,
        IntegrationException, SAXException
    {
        JarInputStream jos = new JarInputStream( jarInputStream );
       
        Map functions = new HashMap();
        Map others = new HashMap();
        Map invokers = new HashMap();
       
        ByteArrayClassLoader classLoader = new ByteArrayClassLoader(Thread.currentThread().getContextClassLoader());
       
        byte[] ruleSetBytes = null;
        for ( JarEntry entry = jos.getNextJarEntry( ); entry != null; entry = jos.getNextJarEntry( ) )
        {
            String name = entry.getName();           
            if ( !name.endsWith(".conf") )
            {
                //We should only read in .class files and the serialised RuleSet
                ByteArrayOutputStream bos = new ByteArrayOutputStream();
                byte[] data = new byte[1024];
                int byteCount;
                while ( (byteCount = jos.read( data,
                                     0,
                                     1024 )) > -1 )
                {                   
                    bos.write(data, 0, byteCount);
                }
View Full Code Here

Examples of java.util.jar.JarInputStream

 
  private void assertValidArchive(byte[] sarContent)
  {
    try
    {
      JarInputStream is = new JarInputStream(new ByteArrayInputStream(sarContent));
      ZipEntry entry;
      if ((entry = is.getNextEntry()) == null)
        throw new IllegalArgumentException("Not a JAR archive format");

      do
      {
        if (!entry.isDirectory()
            && (entry.getName().equals("WEB-INF/sip.xml") || entry.getName().equals(
                "WEB-INF/web.xml")))
          return;
      }
      while ((entry = is.getNextEntry()) != null);
    }
    catch (IOException e)
    {
      throw new IllegalArgumentException("Not a JAR archive format: " + e.getMessage());
    }
View Full Code Here

Examples of java.util.jar.JarInputStream

        // Make Java class files in the jar reachable from Ruby
        runtime.getJRubyClassLoader().addURL(jarFile);

        try {
            JarInputStream in = new JarInputStream(new BufferedInputStream(jarFile.openStream()));

            Manifest mf = in.getManifest();
            if (mf != null) {
                String rubyInit = mf.getMainAttributes().getValue("Ruby-Init");
                if (rubyInit != null) {
                    JarEntry entry = in.getNextJarEntry();
                    while (entry != null && !entry.getName().equals(rubyInit)) {
                        entry = in.getNextJarEntry();
                    }
                    if (entry != null) {
                        IRubyObject old = runtime.getGlobalVariables().isDefined("$JAR_URL") ? runtime.getGlobalVariables().get("$JAR_URL") : runtime.getNil();
                        try {
                            runtime.getGlobalVariables().set("$JAR_URL", runtime.newString("jar:" + jarFile + "!/"));
                            runtime.loadFile("init", in, wrap);
                        } finally {
                            runtime.getGlobalVariables().set("$JAR_URL", old);
                        }
                    }
                }
            }
            in.close();
        } catch (FileNotFoundException e) {
            throw runtime.newIOErrorFromException(e);
        } catch (IOException e) {
            throw runtime.newIOErrorFromException(e);
        }
View Full Code Here

Examples of java.util.jar.JarInputStream

    writeManifest();
  }

  private void copyResourcesFromJarFile(File jarFile) throws IOException {
    JarInputStream inStream = null;
    try {
      inStream = new JarInputStream(new FileInputStream(jarFile));
      while (true) {
        ZipEntry entry = inStream.getNextEntry();
        if (entry == null) {
          break;
        }

        String filename = entry.getName();
        // System.out.println("? copyResourcesFromJarFile() filename='" + filename +"'");
        if (entry.isDirectory()) {
          writeDirectory(filename, jarFile);
        } else if (acceptResource(filename, false)) {
          byte[] bytes = FileUtil.readAsByteArray(inStream);
          writeResource(filename, bytes, jarFile);
        }

        inStream.closeEntry();
      }
    } finally {
      if (inStream != null) {
        inStream.close();
      }
    }
  }
View Full Code Here

Examples of java.util.jar.JarInputStream

     * @param repoDir directory to write the repository contents of the kar to
     * @param resourceDir directory to write the resource contents of the kar to
     */
    public void extract(File repoDir, File resourceDir) {
        InputStream is = null;
        JarInputStream zipIs = null;
        FeatureDetector featureDetector = new FeatureDetector();
        this.featureRepos = new ArrayList<URI>();
        this.shouldInstallFeatures = true;

        try {
            is = karUri.toURL().openStream();
            repoDir.mkdirs();

            if (!repoDir.isDirectory()) {
                throw new RuntimeException("The KAR file " + karUri + " is already installed");
            }

            LOGGER.debug("Uncompress the KAR file {} into directory {}", karUri, repoDir);
            zipIs = new JarInputStream(is);
            boolean scanForRepos = true;

            Manifest manifest = zipIs.getManifest();
            if (manifest != null) {
                Attributes attr = manifest.getMainAttributes();
                String featureStartSt = (String)attr
                    .get(new Attributes.Name(MANIFEST_ATTR_KARAF_FEATURE_START));
                if ("false".equals(featureStartSt)) {
                    shouldInstallFeatures = false;
                }
                String featureReposAttr = (String)attr
                    .get(new Attributes.Name(MANIFEST_ATTR_KARAF_FEATURE_REPOS));
                if (featureReposAttr != null) {
                    featureRepos.add(new URI(featureReposAttr));
                    scanForRepos = false;
                }
            }

            ZipEntry entry = zipIs.getNextEntry();
            while (entry != null) {
                if (entry.getName().startsWith("repository")) {
                    String path = entry.getName().substring("repository/".length());
                    File destFile = new File(repoDir, path);
                    extract(zipIs, entry, destFile);
                    if (scanForRepos && featureDetector.isFeaturesRepository(destFile)) {
                        featureRepos.add(destFile.toURI());
                    }
                }

                if (entry.getName().startsWith("resource")) {
                    String path = entry.getName().substring("resource/".length());
                    File destFile = new File(resourceDir, path);
                    extract(zipIs, entry, destFile);
                }
                entry = zipIs.getNextEntry();
            }
        } catch (Exception e) {
            throw new RuntimeException("Error extracting kar file " + karUri + " into dir " + repoDir + ": " + e.getMessage(), e);
        } finally {
            closeStream(zipIs);
View Full Code Here

Examples of java.util.jar.JarInputStream

        String jarf = url.getFile();
        jarf = jarf.substring(0, jarf.indexOf("!"));
        url = new URL(jarf);

        byte buffer[] = new byte[4096];
        JarInputStream jin = new JarInputStream(new FileInputStream(url.getFile()));
        List executes = new ArrayList();


        for (JarEntry entry = jin.getNextJarEntry(); entry != null; entry = jin.getNextJarEntry()) {
            if (entry.isDirectory()) {
                if (!entry.getName().startsWith("META-INF")
                    && !entry.getName().startsWith("yokoinstaller")) {
                    if (verbose) {
                        System.out.println("Making directory: " + entry.getName());
                    }
                    File file = new File(outputDir, entry.getName());
                    file.mkdirs();
                    file.setLastModified(entry.getTime());
                }
            } else if (!entry.getName().startsWith("META-INF")
                       && !entry.getName().startsWith("yokoinstaller")) {

                boolean binary = isBinary(entry.getName().toLowerCase());
                if ((entry.getName().indexOf("/bin/") != -1
                    || entry.getName().indexOf("\\bin\\") != -1)
                    && !entry.getName().toLowerCase().endsWith(".bat")) {
                    executes.add(entry.getName());
                }

                File outFile = new File(outputDir, entry.getName());
                if (binary) {
                    if (verbose) {
                        System.out.println("Installing Binary: " + entry.getName());
                    }
                   
                    OutputStream out = new FileOutputStream(outFile);
                    for (int len = jin.read(buffer); len != -1; len = jin.read(buffer)) {
                        out.write(buffer, 0, len);
                    }
                    out.close();
                } else {
                    if (verbose) {
View Full Code Here

Examples of java.util.jar.JarInputStream

            LOGGER.error(e.getMessage());
            throw e;
        }
        try {
            is.mark(256 * 1024);
            JarInputStream jar = new JarInputStream(is);
            Manifest m = jar.getManifest();
            if(m == null) {
                throw new BundleException("Manifest not present in the first entry of the zip " + bundleLocation);
            }
            String sn = m.getMainAttributes().getValue(Constants.BUNDLE_SYMBOLICNAME);
            String vStr = m.getMainAttributes().getValue(Constants.BUNDLE_VERSION);
View Full Code Here

Examples of java.util.jar.JarInputStream

import java.util.jar.Manifest;

public class JarUtils {

    public static Manifest loadJarManifest(InputStream stream) throws IOException {
        JarInputStream jarInputStream = null;
        try {
            jarInputStream = new JarInputStream(stream);
            return jarInputStream.getManifest();
        } finally {
            if (jarInputStream != null) {
                try {
                    jarInputStream.close();
                } catch (IOException e) {
                    /* swallow */
                }
            }
        }
View Full Code Here

Examples of java.util.jar.JarInputStream

        IResource resource = root.findMember(path);
        if (resource != null) {
            bundlePath = resource.getLocation();
        }

        JarInputStream jarStream = null;
        try {
            jarStream = new JarInputStream(new FileInputStream(bundlePath.toFile()), false);
            Manifest manifest = jarStream.getManifest();
            if (manifest == null) {
                return null;
            }

            Domain domain = Domain.domain(manifest);
View Full Code Here

Examples of java.util.jar.JarInputStream

public class JarUtils {

    public static Manifest loadJarManifest(InputStream stream) throws IOException {
        try {
            JarInputStream jarInputStream = new JarInputStream(stream);
            return jarInputStream.getManifest();
        } finally {
            IO.close(stream);
        }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.