Package java.util.jar

Examples of java.util.jar.JarFile$JarFileInputStream


  private JarFile jar;

  private JarEntry entry;

  public JarEntryResource(JarEntryInfo jeInfo) throws IOException {
    this.jar = new JarFile(jeInfo.getJarPath());
    this.entry = jar.getJarEntry(jeInfo.getEntryName());
    if (null == this.entry)
      throw new IOException("Invalid JarEntry :" + jeInfo);
    this.name = jeInfo.getEntryName();
  }
View Full Code Here


  }
 
  public static NutResource makeJarNutResource(String filePath) {
    JarEntryInfo jeInfo = new JarEntryInfo(filePath);
    try {
      JarFile jar = new JarFile(jeInfo.getJarPath());
      JarEntry entry = jar.getJarEntry(jeInfo.getEntryName());
      if (entry != null) {
        // JDK里面判断实体是否为文件夹的方法非常不靠谱 by wendal
        if (entry.getName().endsWith("/"))// 明显是文件夹
          return null;
        JarEntry e2 = jar.getJarEntry(jeInfo.getEntryName() + "/");
        if (e2 != null) // 加个/,还是能找到?! 那肯定是文件夹了!
          return null;
        return new JarEntryResource(jeInfo);
      }
    }
View Full Code Here

      if (log.isDebugEnabled())
        log.debugf"Scan resources in JarFile( %s ) by regex( %s ) base on src ( %s )",
              jarPath,
              regex,
              src);
      JarFile jar = new JarFile(jarPath);
      Enumeration<JarEntry> ens = jar.entries();
      while (ens.hasMoreElements()) {
        JarEntry jen = ens.nextElement();
        if (jen.isDirectory())
          continue;
        String name = jen.getName();
View Full Code Here

      // pr112830, allow variations on aspectjrt.jar of the form aspectjrtXXXXXX.jar
      if (p.isFile() && p.getName().startsWith("aspectjrt") && p.getName().endsWith(".jar")) {

        try {
          String version = null;
          Manifest manifest = new JarFile(p).getManifest();
          if (manifest == null) {
            ret = "no manifest found in " + p.getAbsolutePath() + ", expected " + Version.text;
            continue;
          }
          Attributes attr = manifest.getAttributes("org/aspectj/lang/");
View Full Code Here

            if (!new File(filePath).exists()) {
                throw new FileNotFoundException(path);
            }
           
            JarFile jf = new JarFile(filePath);
            ZipEntry zf = jf.getEntry(internalPath);

            if(zf == null) {
                throw new FileNotFoundException(path);
            }

            InputStream is = jf.getInputStream(zf);
            // FIXME: don't use RubyIO for this
            return new ChannelDescriptor(Channels.newChannel(is), RubyIO.getNewFileno(), flags, new FileDescriptor());
        } else {
            JRubyFile theFile = JRubyFile.create(cwd,path);
View Full Code Here

                }

                st = new File(newStringFromUTF8(bytes, begin+5, ix-5));
                String jar = newStringFromUTF8(bytes, begin+ix+1, end-(ix+1));
                try {
                    JarFile jf = new JarFile(st);
                   
                    if (jar.startsWith("/")) jar = jar.substring(1);
                    if (jf.getEntry(jar + "/") != null) jar = jar + "/";
                    if (jf.getEntry(jar) != null) {
                        status = func.call(bytes, begin, end, arg);
                    }
                } catch(Exception e) {}
            } else if ((end - begin) > 0) { // Length check is a hack.  We should not be reeiving "" as a filename ever.
                if (new File(cwd, newStringFromUTF8(bytes, begin, end - begin)).exists()) {
                    status = func.call(bytes, begin, end - begin, arg);
                }
            }

            return status;
        }
       
        ByteList buf = new ByteList(20);
        List<ByteList> link = new ArrayList<ByteList>();
        mainLoop: while(p != -1 && status == 0) {
            if (bytes[p] == '/') p++;

            m = strchr(bytes, p, end, (byte)'/');
            if(has_magic(bytes, p, m == -1 ? end : m, flags)) {
                finalize: do {
                    byte[] base = extract_path(bytes, begin, p);
                    byte[] dir = begin == p ? new byte[]{'.'} : base;
                    byte[] magic = extract_elem(bytes,p,end);
                    boolean recursive = false;
                    String jar = null;
                    JarFile jf = null;

                    if(dir[0] == '/'  || (DOSISH && 2<dir.length && dir[1] == ':' && isdirsep(dir[2]))) {
                        st = new File(newStringFromUTF8(dir));
                    } else if(isJarFilePath(dir, 0, dir.length)) {
                        int ix = -1;
                        for(int i = 0;i<dir.length;i++) {
                            if(dir[i] == '!') {
                                ix = i;
                                break;
                            }
                        }

                        st = new File(newStringFromUTF8(dir, 5, ix-5));
                        jar = newStringFromUTF8(dir, ix+1, dir.length-(ix+1));
                        try {
                            jf = new JarFile(st);

                            if (jar.startsWith("/")) jar = jar.substring(1);
                            if (jf.getEntry(jar + "/") != null) jar = jar + "/";
                        } catch(Exception e) {
                            jar = null;
                            jf = null;
                        }
                    } else {
                        st = new File(cwd, newStringFromUTF8(dir));
                    }

                    if((jf != null && ("".equals(jar) || (jf.getJarEntry(jar) != null && jf.getJarEntry(jar).isDirectory()))) || st.isDirectory()) {
                        if(m != -1 && Arrays.equals(magic, DOUBLE_STAR)) {
                            int n = base.length;
                            recursive = true;
                            buf.length(0);
                            buf.append(base);
                            buf.append(bytes, (base.length > 0 ? m : m + 1), end - (base.length > 0 ? m : m + 1));
                            status = glob_helper(cwd, buf.bytes, buf.begin, buf.realSize, n, flags, func, arg);
                            if(status != 0) {
                                break finalize;
                            }
                        }
                    } else {
                        break mainLoop;
                    }

                    if(jar == null) {
                        String[] dirp = files(st);

                        for(int i=0;i<dirp.length;i++) {
                            if(recursive) {
                                byte[] bs = getBytesInUTF8(dirp[i]);
                                if (fnmatch(STAR,0,1,bs,0,bs.length,flags) != 0) {
                                    continue;
                                }
                                buf.length(0);
                                buf.append(base);
                                buf.append( BASE(base) ? SLASH : EMPTY );
                                buf.append(getBytesInUTF8(dirp[i]));
                                if (buf.bytes[0] == '/' || (DOSISH && 2<buf.realSize && buf.bytes[1] == ':' && isdirsep(buf.bytes[2]))) {
                                    st = new File(newStringFromUTF8(buf.bytes, buf.begin, buf.realSize));
                                } else {
                                    st = new File(cwd, newStringFromUTF8(buf.bytes, buf.begin, buf.realSize));
                                }
                                if(st.isDirectory() && !".".equals(dirp[i]) && !"..".equals(dirp[i])) {
                                    int t = buf.realSize;
                                    buf.append(SLASH);
                                    buf.append(DOUBLE_STAR);
                                    buf.append(bytes, m, end - m);
                                    status = glob_helper(cwd, buf.bytes, buf.begin, buf.realSize, t, flags, func, arg);
                                    if(status != 0) {
                                        break;
                                    }
                                }
                                continue;
                            }
                            byte[] bs = getBytesInUTF8(dirp[i]);
                            if(fnmatch(magic,0,magic.length,bs,0, bs.length,flags) == 0) {
                                buf.length(0);
                                buf.append(base);
                                buf.append( BASE(base) ? SLASH : EMPTY );
                                buf.append(getBytesInUTF8(dirp[i]));
                                if(m == -1) {
                                    status = func.call(buf.bytes,0,buf.realSize,arg);
                                    if(status != 0) {
                                        break;
                                    }
                                    continue;
                                }
                                link.add(buf);
                                buf = new ByteList(20);
                            }
                        }
                    } else {
                        try {
                            List<JarEntry> dirp = new ArrayList<JarEntry>();
                            for(Enumeration<JarEntry> eje = jf.entries(); eje.hasMoreElements(); ) {
                                JarEntry je = eje.nextElement();
                                String name = je.getName();
                                int ix = name.indexOf('/', jar.length());
                                if((!name.startsWith("META-INF") && (ix == -1 || ix == name.length()-1))) {
                                    if("/".equals(jar) || (name.startsWith(jar) && name.length()>jar.length())) {
View Full Code Here

                } catch (MalformedURLException e) {
                    throw runtime.newIOErrorFromException(e);
                }
            } else if(namePlusSuffix.startsWith("file:") && namePlusSuffix.indexOf("!/") != -1) {
                try {
                    JarFile file = new JarFile(namePlusSuffix.substring(5, namePlusSuffix.indexOf("!/")));
                    String filename = namePlusSuffix.substring(namePlusSuffix.indexOf("!/") + 2);
                    if(file.getJarEntry(filename) != null) {
                        foundResource = new LoadServiceResource(new URL("jar:" + namePlusSuffix), namePlusSuffix);
                    }
                } catch(Exception e) {}
            }   
            if (foundResource != null) {
View Full Code Here

    }
   
    private LoadServiceResource tryResourceFromJarURLWithLoadPath(String namePlusSuffix, String loadPathEntry) {
        LoadServiceResource foundResource = null;
       
        JarFile current = jarFiles.get(loadPathEntry);
        boolean isFileJarUrl = loadPathEntry.startsWith("file:") && loadPathEntry.indexOf("!/") != -1;
        String after = isFileJarUrl ? loadPathEntry.substring(loadPathEntry.indexOf("!/") + 2) + "/" : "";
        String before = isFileJarUrl ? loadPathEntry.substring(0, loadPathEntry.indexOf("!/")) : loadPathEntry;

        if(null == current) {
            try {
                if(loadPathEntry.startsWith("jar:")) {
                    current = new JarFile(loadPathEntry.substring(4));
                } else if (loadPathEntry.endsWith(".jar")) {
                    current = new JarFile(loadPathEntry);
                } else {
                    current = new JarFile(loadPathEntry.substring(5,loadPathEntry.indexOf("!/")));
                }
                jarFiles.put(loadPathEntry,current);
            } catch (ZipException ignored) {
                if (runtime.getInstanceConfig().isVerbose()) {
                    runtime.getErr().println("ZipException trying to access " + loadPathEntry + ", stack trace follows:");
                    ignored.printStackTrace(runtime.getErr());
                }
            } catch (FileNotFoundException ignored) {
            } catch (IOException e) {
                throw runtime.newIOErrorFromException(e);
            }
        }
        String canonicalEntry = after+namePlusSuffix;
        if(after.length()>0) {
            try {
                canonicalEntry = new File(after+namePlusSuffix).getCanonicalPath().substring(new File(".")
                                                     .getCanonicalPath().length()+1).replaceAll("\\\\","/");
            } catch(Exception e) {}
        }
        if (current != null && current.getJarEntry(canonicalEntry) != null) {
            try {
                if (loadPathEntry.endsWith(".jar")) {
                    foundResource = new LoadServiceResource(new URL("jar:file:" + loadPathEntry + "!/" + canonicalEntry), "/" + namePlusSuffix);
                } else if (loadPathEntry.startsWith("file:")) {
                    foundResource = new LoadServiceResource(new URL("jar:" + before + "!/" + canonicalEntry), loadPathEntry + "/" + namePlusSuffix);
View Full Code Here

    }
   
    static void addClasspathFromManifest(StringBuilder classPath, File file)
        throws URISyntaxException, IOException {
       
        JarFile jar = new JarFile(file);
        Attributes attr = null;
        if (jar.getManifest() != null) {
            attr = jar.getManifest().getMainAttributes();
        }
        if (attr != null) {
            String cp = attr.getValue("Class-Path");
            while (cp != null) {
                String fileName = cp;
View Full Code Here

       
        if (deploymentExists(contextPath))
            return;
       
        // Checking for a nested /META-INF/context.xml
        JarFile jar = null;
        JarEntry entry = null;
        InputStream istream = null;
        BufferedOutputStream ostream = null;
        File xml = new File
            (configBase, file.substring(0, file.lastIndexOf(".")) + ".xml");
        if (deployXML && !xml.exists()) {
            try {
                jar = new JarFile(war);
                entry = jar.getJarEntry(Constants.ApplicationContextXml);
                if (entry != null) {
                    istream = jar.getInputStream(entry);
                   
                    configBase.mkdirs();
                   
                    ostream =
                        new BufferedOutputStream
                        (new FileOutputStream(xml), 1024);
                    byte buffer[] = new byte[1024];
                    while (true) {
                        int n = istream.read(buffer);
                        if (n < 0) {
                            break;
                        }
                        ostream.write(buffer, 0, n);
                    }
                    ostream.flush();
                    ostream.close();
                    ostream = null;
                    istream.close();
                    istream = null;
                    entry = null;
                    jar.close();
                    jar = null;
                }
            } catch (Exception e) {
                // Ignore and continue
                if (ostream != null) {
                    try {
                        ostream.close();
                    } catch (Throwable t) {
                        ;
                    }
                    ostream = null;
                }
                if (istream != null) {
                    try {
                        istream.close();
                    } catch (Throwable t) {
                        ;
                    }
                    istream = null;
                }
            } finally {
                entry = null;
                if (jar != null) {
                    try {
                        jar.close();
                    } catch (Throwable t) {
                        ;
                    }
                    jar = null;
                }
View Full Code Here

TOP

Related Classes of java.util.jar.JarFile$JarFileInputStream

Copyright © 2018 www.massapicom. 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.