📄 env.java
字号:
r.load(CONSTANTS); } catch (ResourceNotFoundException rnfe) { if (Logging.SHOW_SEVERE && LOG.isLoggable(Level.SEVERE)) { LOG.log(Level.SEVERE, "Caught unexpected Exception", rnfe); } } c.set(Constants.NAME, r.get(Constants.NAME, c.get(Constants.NAME))); c.set(Constants.VERSION, r.get(Constants.VERSION, c.get(Constants.NAME))); c.set(Constants.BUILD, r.get(Constants.BUILD, c.get(Constants.BUILD))); c.save(); String ph = System.getProperty(HTTP_PROXY_HOST); String pp = System.getProperty(HTTP_PROXY_PORT, String.valueOf(Constants.DEFAULT_HTTP_PROXY_PORT)); if (ph != null) {// URL pu = null; try { c.set(Constants.PROXY_HTTP, new URL(Constants.PROTOCOL_HTTP + URL_DELIMITER + ph + COLON + pp).toString()); } catch (MalformedURLException mue) { if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) { LOG.log(Level.FINE, "invalid url: " + ph + " " + pp, mue); } } } // xxx: hack; in time, support loading multiple networks String nid = c.get(Constants.NETWORK_ID, "").trim(); if (nid.length() > 0) { Properties p = new Properties(); p.put(Constants.NET_PEER_GROUP_ID_KEY, nid); p.put(Constants.NET_PEER_GROUP_NAME_KEY, c.get(Constants.NETWORK_NAME, "").trim()); p.put(Constants.NET_PEER_GROUP_DESCRIPTION_KEY, c.get(Constants.NETWORK_DESCRIPTION, "").trim()); try { p.store(new FileOutputStream(new File(home + Env.PLATFORM_CONFIG)), Env.PLATFORM_CONFIG_COMMENT); } catch (FileNotFoundException fnfe) { if (Logging.SHOW_SEVERE && LOG.isLoggable(Level.SEVERE)) { LOG.log(Level.SEVERE, "can\'t write " + Env.PLATFORM_CONFIG + " file", fnfe); } } catch (IOException ioe) { if (Logging.SHOW_SEVERE && LOG.isLoggable(Level.SEVERE)) { LOG.log(Level.SEVERE, "can\'t write " + Env.PLATFORM_CONFIG + " file", ioe); } } } initPreferences(home); // xxx: drop the cm for a period of time; see issue #331// delete(new File(home + JXTA_CACHE)); } private static void initPreferences(String home) { File f = new File(home + PREFS); if (!f.exists()) { try { createFile(f, DEFAULT_PREFS); } catch (IOException e) { LOG.log(Level.SEVERE, "Unable to create file " + f.getAbsolutePath(), e); } } } /** * Returns the URI path of the Home Directory. */ public static URI getHome() { return myjxta; } /** * Returns the {@link File#getCanonicalPath() Canonical} path of the Home Directory if possible; otherwise, * returns the {@link File#getAbsolutePath() Absolute} path. */ public static String getHomeDirPath() { String p = null; if (myjxta != null) { try { p = Conversion.toFile(myjxta).getCanonicalPath(); } catch (ConversionException ce) { if (Logging.SHOW_SEVERE && LOG.isLoggable(Level.SEVERE)) { LOG.log(Level.SEVERE, "home path", ce); } } catch (IOException ioe) { if (Logging.SHOW_SEVERE && LOG.isLoggable(Level.SEVERE)) { LOG.log(Level.SEVERE, "home path", ioe); } } } return p; } /** * Returns the URL of the current configuration file. */ public static URL getConfiguration() { URL u = null; try { u = new URL(getHome() + CONFIGURATION); } catch (MalformedURLException mue) { if (Logging.SHOW_SEVERE && LOG.isLoggable(Level.SEVERE)) { LOG.log(Level.SEVERE, "Caught unexpected Exception", mue); } } return u; } /** * Return the path to platform specific configuration * file * * @return the path to the platform specific configuration file */ public static URL getPlatform() { URL u = null; try { u = new URL(getHome() + PLATFORM); } catch (MalformedURLException mue) { if (Logging.SHOW_SEVERE && LOG.isLoggable(Level.SEVERE)) { LOG.log(Level.SEVERE, "Caught unexpected Exception", mue); } } return u; } /** * Creates or deletes a Reconfigure file (home/reconf) depending on * whether the reconfigure param is true or false, respectively. * * @param reconfigure If true, a new Reconfigure file is created; * otherwise, the existing Reconfigure file is deleted. */ public static void setReconfigure(boolean reconfigure) { File r = new File(new File(myjxta), RECONFIGURE); if (reconfigure) { try { r.createNewFile(); } catch (IOException ioe) { if (Logging.SHOW_SEVERE && LOG.isLoggable(Level.SEVERE)) { LOG.log(Level.SEVERE, "Caught unexpected Exception", ioe); } } } else { delete(r); } } /** * @return The log4jConfigFilePath. */ public static String getLog4jConfigFilePath() { return log4jConfigFilePath; } /** * @return true if the log4j config file pointed to by log4jConfigFilePath has a ".xml" extension, and false * otherwise. */ public static boolean isLog4jConfigFileXml() { return log4jConfigFileXml; } public static void delete(File f) { if (f.exists()) { if (f.isFile()) { f.delete(); } else { File[] files = f.listFiles(); for (File file : files) { delete(file); } f.delete(); } } } private static void createFile(File newFile, String sourceFilePath) throws IOException { File p = newFile.getParentFile(); if (p != null) { p.mkdirs(); } ResourceManager rm = ResourceManager.getInstance(); InputStream is = rm.getResourceAsStream(sourceFilePath); if (is != null) { newFile.createNewFile(); FileOutputStream os = new FileOutputStream(newFile); BufferedOutputStream out = new BufferedOutputStream(os); int c; while ((c = is.read()) > -1) { out.write(c); } out.flush(); is.close(); out.close(); } } /** * Returns the URL of the current preferences file. */ public static URL getPreferences() { URL url = null; try { url = new URL(getHome() + PREFS); } catch (MalformedURLException mue) { if (Logging.SHOW_SEVERE && LOG.isLoggable(Level.SEVERE)) { LOG.log(Level.SEVERE, "Caught unexpected Exception", mue); } } return url; } public static boolean savePreferences(String prefDoc) { boolean ret = false; try { updateFile(getPreferences(), new ByteArrayInputStream(prefDoc.getBytes())); } catch (IOException iox) { if (Logging.SHOW_SEVERE && LOG.isLoggable(Level.SEVERE)) { LOG.log(Level.SEVERE, "Caught unexpected Exception", iox); } } return ret; } private static void updateFile(URL currentFile, InputStream in) throws IOException { File f; try { f = new File(currentFile.toURI()); if (!f.exists()) { if (Logging.SHOW_SEVERE && LOG.isLoggable(Level.SEVERE)) { LOG.severe("File does not exist. Creating"); } File p = f.getParentFile(); if (p != null) { p.mkdirs(); } f.createNewFile(); } FileOutputStream os = new FileOutputStream(f); BufferedOutputStream out = new BufferedOutputStream(os); int c; while ((c = in.read()) > -1) { out.write(c); } out.flush(); in.close(); out.close(); } catch (URISyntaxException ex) { if (Logging.SHOW_SEVERE && LOG.isLoggable(Level.SEVERE)) { LOG.log(Level.SEVERE, "Caught unexpected Exception", ex); } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -