📄 bundlearchiveimpl.java
字号:
*/ public InputStream getInputStream(String component) { return getInputStream(component, -1); } /** * Get an specific InputStream to named entry inside a bundle. * Leading '/' is stripped. * * @param component Entry to get reference to. * @param ix index of jar. 0 means the top level. -1 means any * @return InputStream to entry or null if it doesn't exist. */ public InputStream getInputStream(String component, int ix) { if (component.startsWith("/")) { component = component.substring(1); } if(ix == -1) { for (int i = 0; i < archives.length; i++) { InputStream res = archives[i].getInputStream(component); if (res != null) { return res; } } return null; } else { return archives[ix].getInputStream(component); } } /** * Get native library from JAR. * * @param component Name of Jar file to get. * @return A string with path to native library. */ public String getNativeLibrary(String component) { if (nativeLibs != null) { try {//XXX - start L-3 modification String key = (String)mapLibraryName.invoke(null, new Object[] {component}); String val = (String)nativeLibs.get(key); File file1 = new File(val); if (file1.exists() && file1.isFile()) { if (renameLibs.containsKey(key)) { File file2 = new File((String)renameLibs.get(key)); if (file1.renameTo(file2)) { val = file2.getAbsolutePath(); nativeLibs.put(key, val); } } StringBuffer rename = new StringBuffer(val); int index0 = val.lastIndexOf(File.separatorChar) + 1; int index1 = val.indexOf("_", index0); if((index1 > index0) && (index1 == val.length() - key.length() - 1)) { try { int prefix = Integer.parseInt(val.substring(index0, index1)); rename.replace(index0, index1, Integer.toString(prefix + 1)); } catch (Throwable t) { rename.insert(index0, "0_"); } } else { rename.insert(index0, "0_"); } renameLibs.put(key, rename.toString()); } return val;//XXX - end L-3 modification } catch (Exception ignore) { } } return null; } /** * Get state of start on launch flag. * * @return Boolean value for start on launch flag. */ public boolean getStartOnLaunchFlag() { return startOnLaunch; } /** * Set state of start on launch flag. * * @param value Boolean value for start on launch flag. */ public void setStartOnLaunchFlag(boolean value) throws IOException { if (startOnLaunch != value) { startOnLaunch = value; putContent(STOP_FILE, new Boolean(!startOnLaunch).toString()); } } /** * Remove bundle archive from persistent storage. If we removed * the active revision also remove bundle status files. */ public void purge() { close(); if (storage.removeArchive(this)) { (new File(bundleDir, LOCATION_FILE)).delete(); (new File(bundleDir, STOP_FILE)).delete(); (new File(bundleDir, REV_FILE)).delete(); } archive.purge(); if (bundleDir.list().length == 0) { bundleDir.delete(); } } /** * Close archive for further access. It should still be possible * to get attributes. */ public void close() { for (int i = 0; i < archives.length; i++) { archives[i].close(); } archive.close(); } // // Private methods // /** * Read content of file as a string. * * @param f File to write too * @return contenet String to write */ private String getContent(String f) { DataInputStream in = null; try { in = new DataInputStream(new FileInputStream(new File(bundleDir, f))); return in.readUTF(); } catch (IOException ignore) { } finally { if (in != null) { try { in.close(); } catch (IOException ignore) { } } } return null; } /** * Statically check if a directory contains info that a bundle * is uninstalled. * * <p> * Uninstalled is marked via a startlevel of -2 * </p> */ static boolean isUninstalled(File dir) { String s = getContent(dir, STARTLEVEL_FILE); int n = -1; try { n = Integer.parseInt(s); } catch (Exception e) { } return n == -2; } static String getContent(File dir, String f) { DataInputStream in = null; try { in = new DataInputStream(new FileInputStream(new File(dir, f))); return in.readUTF(); } catch (IOException ignore) { } finally { if (in != null) { try { in.close(); } catch (IOException ignore) { } } } return null; } /** * Write string to named file. * * @param f File to write too * @param contenet String to write * @exception IOException if we fail to save our string */ private void putContent(String f, String content) throws IOException { DataOutputStream out = null; try { out = new DataOutputStream(new FileOutputStream(new File(bundleDir, f))); out.writeUTF(content); } finally { if (out != null) { out.close(); } } } private void setClassPath() throws IOException { String bcp = getAttribute(Constants.BUNDLE_CLASSPATH); if (!bFake && (bcp != null)) { ArrayList a = new ArrayList(); StringTokenizer st = new StringTokenizer(bcp, ","); while (st.hasMoreTokens()) { String path = st.nextToken().trim(); if (".".equals(path)) { a.add(archive); } else { a.add(archive.getSubArchive(path)); } } archives = (Archive [])a.toArray(new Archive[a.size()]); } else { archives = new Archive[] { archive }; } } /** * Check for native code libraries. * * @param bnc Is the Bundle-NativeCode string. * @return A List of Strings with pathname to native code libraries or * null if input was null. * @exception IllegalArgumentException If syntax error in input string. * @exception Exception If can not find an entry that match this JVM. */ private Map getNativeCode() throws Exception { String bnc = getAttribute(Constants.BUNDLE_NATIVECODE); if (bnc != null) { if (mapLibraryName == null) { throw new Exception("Native-Code: Not supported on non Java 2 platforms."); } Map best = null; List perfectVer = new ArrayList(); List okVer = new ArrayList(); List noVer = new ArrayList(); for (Iterator i = Util.parseEntries(Constants.BUNDLE_NATIVECODE, bnc, false); i.hasNext(); ) { Map params = (Map)i.next(); String p = Framework.getProperty(Constants.FRAMEWORK_PROCESSOR); List pl = (List)params.get(Constants.BUNDLE_NATIVECODE_PROCESSOR); String o = Framework.getProperty(Constants.FRAMEWORK_OS_NAME); List ol = (List)params.get(Constants.BUNDLE_NATIVECODE_OSNAME); if ((containsIgnoreCase(pl, p) || containsIgnoreCase(pl, Alias.unifyProcessor(p))) && (containsIgnoreCase(ol, o) || containsIgnoreCase(ol, Alias.unifyOsName(o)))) { String fosVer = Framework.getProperty(Constants.FRAMEWORK_OS_VERSION); List ver = (List)params.get(Constants.BUNDLE_NATIVECODE_OSVERSION); // Skip if we require a newer OS version. if (ver != null) { for (Iterator v = ver.iterator(); v.hasNext(); ) { String nov = (String)v.next(); int cmp = Util.compareStringVersion(nov, fosVer); if (cmp == 0) { // Found perfect OS version perfectVer.add(params); break; } if (cmp < 0 && !okVer.contains(params)) { // Found lower OS version okVer.add(params); } } } else { // Found unspecfied OS version noVer.add(params); } } } List langSearch = null; if (perfectVer.size() == 1) { best = (Map)perfectVer.get(0); } else if (perfectVer.size() > 1) { langSearch = perfectVer; } else if (okVer.size() == 1) { best = (Map)okVer.get(0); } else if (okVer.size() > 1) { langSearch = okVer; } else if (noVer.size() == 1) { best = (Map)noVer.get(0); } else if (noVer.size() > 1) { langSearch = noVer; } if (langSearch != null) { String fosLang = Framework.getProperty(Constants.FRAMEWORK_LANGUAGE); lloop: for (Iterator i = langSearch.iterator(); i.hasNext(); ) { Map params = (Map)i.next(); List lang = (List)params.get(Constants.BUNDLE_NATIVECODE_LANGUAGE); if (lang != null) { for (Iterator l = lang.iterator(); l.hasNext(); ) { if (fosLang.equalsIgnoreCase((String)l.next())) { // Found specfied language version, search no more best = params; break lloop; } } } else { // Found unspecfied language version best = params; } } } if (best == null) { throw new Exception("Native-Code: No matching libraries found."); }//XXX - start L-3 modification renameLibs = new HashMap();//XXX - end L-3 modification HashMap res = new HashMap(); for (Iterator p = ((List)best.get("keys")).iterator(); p.hasNext();) { String name = (String)p.next(); int sp = name.lastIndexOf('/'); String key = (sp != -1) ? name.substring(sp+1) : name; res.put(key, archive.getNativeLibrary(name)); } return res; } else { // No native code in this bundle return null; } } /** * Check if a string exists in a list. Ignore case when comparing. */ private boolean containsIgnoreCase(List l, String s) { for (Iterator i = l.iterator(); i.hasNext(); ) { if (s.equalsIgnoreCase((String)i.next())) { return true; } } return false; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -