List of usage examples for java.util Properties store
public void store(OutputStream out, String comments) throws IOException
From source file:SystemInfo.java
public static void main(String args[]) { try {/*from ww w. ja va 2 s . c om*/ Properties sysprops = System.getProperties(); sysprops.store(System.out, "System Properties"); } catch (IOException e) { e.printStackTrace(); } }
From source file:Main.java
public static void main(String args[]) throws Exception { Properties p = new Properties(); p.load(new FileInputStream("test.txt")); p.store(new FileOutputStream("t.txt"), "no comments"); }
From source file:List.java
public static void main(String args[]) throws Exception { Properties p = System.getProperties(); p.list(System.out);/*from ww w . jav a2s. c om*/ FileOutputStream fos = new FileOutputStream("sys.out"); p.store(fos, null); fos.close(); Map map = new TreeMap(p); System.out.println(map); }
From source file:dpfmanager.shell.core.util.VersionUtil.java
public static void main(String[] args) { String version = args[0];//w ww . jav a 2 s .com String baseDir = args[1]; String issPath = baseDir + "/package/windows/DPF Manager.iss"; String rpmPath = baseDir + "/package/linux/DPFManager.old.spec"; String propOutput = baseDir + "/target/classes/version.properties"; try { // Windows iss File issFile = new File(issPath); String issContent = FileUtils.readFileToString(issFile); String newIssContent = replaceLine(StringUtils.split(issContent, '\n'), "AppVersion=", version); if (!newIssContent.isEmpty()) { FileUtils.writeStringToFile(issFile, newIssContent); System.out.println("New version information updated! (iss)"); } // RPM spec File rpmFile = new File(rpmPath); String rpmContent = FileUtils.readFileToString(rpmFile); String newRpmContent = replaceLine(StringUtils.split(rpmContent, '\n'), "Version: ", version); if (!newRpmContent.isEmpty()) { FileUtils.writeStringToFile(rpmFile, newRpmContent); System.out.println("New version information updated! (spec)"); } // Java properties file OutputStream output = new FileOutputStream(propOutput); Properties prop = new Properties(); prop.setProperty("version", version); prop.store(output, "Version autoupdated"); output.close(); System.out.println("New version information updated! (properties)"); } catch (Exception e) { System.out.println("Exception ocurred, no version changed."); e.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) throws Exception { Properties prop = new Properties(); prop.setProperty("Chapter Count", "200"); prop.put("Tutorial Count", "1500"); prop.put("tutorial", "java2s.com"); // print the list System.out.println(prop);//from w w w . j a va 2 s .c om // store the properties list in an output stream prop.store(System.out, "Main"); }
From source file:Main.java
public static void main(String[] args) throws Exception { Properties prop = new Properties(); StringWriter sw = new StringWriter(); prop.setProperty("Chapter Count", "200"); prop.put("Tutorial Count", "1500"); prop.put("tutorial", "java2s.com"); // print the list System.out.println(prop);//from ww w . ja v a 2 s. c o m // store the properties list in an output writer prop.store(sw, "Main"); System.out.println(sw.toString()); }
From source file:com.jivesoftware.os.routing.bird.deployable.config.extractor.ConfigExtractor.java
public static void main(String[] args) { String configHost = args[0];/*from w ww.ja va2s .c om*/ String configPort = args[1]; String instanceKey = args[2]; String instanceVersion = args[3]; String setPath = args[4]; String getPath = args[5]; HttpRequestHelper buildRequestHelper = buildRequestHelper(null, configHost, Integer.parseInt(configPort)); try { Set<URL> packages = new HashSet<>(); for (int i = 5; i < args.length; i++) { packages.addAll(ClasspathHelper.forPackage(args[i])); } Reflections reflections = new Reflections(new ConfigurationBuilder().setUrls(packages) .setScanners(new SubTypesScanner(), new TypesScanner())); Set<Class<? extends Config>> subTypesOf = reflections.getSubTypesOf(Config.class); File configDir = new File("./config"); configDir.mkdirs(); Set<Class<? extends Config>> serviceConfig = new HashSet<>(); Set<Class<? extends Config>> healthConfig = new HashSet<>(); for (Class<? extends Config> type : subTypesOf) { if (HealthCheckConfig.class.isAssignableFrom(type)) { healthConfig.add(type); } else { serviceConfig.add(type); } } Map<String, String> defaultServiceConfig = extractAndPublish(serviceConfig, new File(configDir, "default-service-config.properties"), "default", instanceKey, instanceVersion, buildRequestHelper, setPath); DeployableConfig getServiceOverrides = new DeployableConfig("override", instanceKey, instanceVersion, defaultServiceConfig); DeployableConfig gotSerivceConfig = buildRequestHelper.executeRequest(getServiceOverrides, getPath, DeployableConfig.class, null); if (gotSerivceConfig == null) { System.out.println("Failed to publish default service config for " + Arrays.deepToString(args)); } else { Properties override = createKeySortedProperties(); override.putAll(gotSerivceConfig.properties); override.store(new FileOutputStream("config/override-service-config.properties"), ""); } Map<String, String> defaultHealthConfig = extractAndPublish(healthConfig, new File(configDir, "default-health-config.properties"), "default-health", instanceKey, instanceVersion, buildRequestHelper, setPath); DeployableConfig getHealthOverrides = new DeployableConfig("override-health", instanceKey, instanceVersion, defaultHealthConfig); DeployableConfig gotHealthConfig = buildRequestHelper.executeRequest(getHealthOverrides, getPath, DeployableConfig.class, null); if (gotHealthConfig == null) { System.out.println("Failed to publish default health config for " + Arrays.deepToString(args)); } else { Properties override = createKeySortedProperties(); override.putAll(gotHealthConfig.properties); override.store(new FileOutputStream("config/override-health-config.properties"), ""); } Properties instanceProperties = createKeySortedProperties(); File configFile = new File("config/instance.properties"); if (configFile.exists()) { instanceProperties.load(new FileInputStream(configFile)); } Properties serviceOverrideProperties = createKeySortedProperties(); configFile = new File("config/override-service-config.properties"); if (configFile.exists()) { serviceOverrideProperties.load(new FileInputStream(configFile)); } Properties healthOverrideProperties = createKeySortedProperties(); configFile = new File("config/override-health-config.properties"); if (configFile.exists()) { healthOverrideProperties.load(new FileInputStream(configFile)); } Properties properties = createKeySortedProperties(); properties.putAll(defaultServiceConfig); properties.putAll(defaultHealthConfig); properties.putAll(serviceOverrideProperties); properties.putAll(healthOverrideProperties); properties.putAll(instanceProperties); properties.store(new FileOutputStream("config/config.properties"), ""); System.exit(0); } catch (Exception x) { x.printStackTrace(); System.exit(1); } }
From source file:PersistentEcho.java
public static void main(String[] args) { String argString = ""; boolean notProperty = true; // Are there arguments? // If so retrieve them. if (args.length > 0) { for (String arg : args) { argString += arg + " "; }// w ww. j ava 2s . c om argString = argString.trim(); } // No arguments, is there // an environment variable? // If so, //retrieve it. else if ((argString = System.getenv("PERSISTENTECHO")) != null) { } // No environment variable // either. Retrieve property value. else { notProperty = false; // Set argString to null. // If it's still null after // we exit the try block, // we've failed to retrieve // the property value. argString = null; FileInputStream fileInputStream = null; try { fileInputStream = new FileInputStream("PersistentEcho.txt"); Properties inProperties = new Properties(); inProperties.load(fileInputStream); argString = inProperties.getProperty("argString"); } catch (IOException e) { System.err.println("Can't read property file."); System.exit(1); } finally { if (fileInputStream != null) { try { fileInputStream.close(); } catch (IOException e) { } ; } } } if (argString == null) { System.err.println("Couldn't find argString property"); System.exit(1); } // Somehow, we got the // value. Echo it already! System.out.println(argString); // If we didn't retrieve the // value from the property, // save it //in the property. if (notProperty) { Properties outProperties = new Properties(); outProperties.setProperty("argString", argString); FileOutputStream fileOutputStream = null; try { fileOutputStream = new FileOutputStream("PersistentEcho.txt"); outProperties.store(fileOutputStream, "PersistentEcho properties"); } catch (IOException e) { } finally { if (fileOutputStream != null) { try { fileOutputStream.close(); } catch (IOException e) { } ; } } } }
From source file:com.adobe.aem.demomachine.Checksums.java
public static void main(String[] args) { String rootFolder = null;// w w w . j ava2 s . com // Command line options for this tool Options options = new Options(); options.addOption("f", true, "Demo Machine root folder"); CommandLineParser parser = new BasicParser(); try { CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("f")) { rootFolder = cmd.getOptionValue("f"); } } catch (Exception e) { System.exit(-1); } Properties md5properties = new Properties(); List<String[]> listPaths = Arrays.asList(AemDemoConstants.demoPaths); for (String[] path : listPaths) { if (path.length == 5) { logger.debug(path[1]); File pathFolder = new File(rootFolder + (path[1].length() > 0 ? (File.separator + path[1]) : "")); if (pathFolder.exists()) { String md5 = AemDemoUtils.calcMD5HashForDir(pathFolder, Boolean.parseBoolean(path[3]), false); logger.debug("MD5 is: " + md5); md5properties.setProperty("demo.path." + path[0], path[1]); md5properties.setProperty("demo.md5." + path[0], md5); } else { logger.error("Folder cannot be found"); } } } File md5 = new File(rootFolder + File.separator + "conf" + File.separator + "checksums.properties"); try { @SuppressWarnings("serial") Properties tmpProperties = new Properties() { @Override public synchronized Enumeration<Object> keys() { return Collections.enumeration(new TreeSet<Object>(super.keySet())); } }; tmpProperties.putAll(md5properties); tmpProperties.store(new FileOutputStream(md5), null); } catch (Exception e) { logger.error(e.getMessage()); } System.out.println("MD5 checkums generated"); }
From source file:se.vgregion.portal.cs.util.CryptoUtilImpl.java
/** * Main method used for creating initial key file. * // ww w. j a va2s . c o m * @param args * - not used */ public static void main(String[] args) { final String keyFile = "./howto.key"; final String pwdFile = "./howto.properties"; CryptoUtilImpl cryptoUtils = new CryptoUtilImpl(); cryptoUtils.setKeyFile(new File(keyFile)); String clearPwd = "my_cleartext_pwd"; Properties p1 = new Properties(); Writer w = null; try { p1.put("user", "liferay"); String encryptedPwd = cryptoUtils.encrypt(clearPwd); p1.put("pwd", encryptedPwd); w = new FileWriter(pwdFile); p1.store(w, ""); } catch (GeneralSecurityException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { if (w != null) { try { w.close(); } catch (IOException e) { e.printStackTrace(); } } } // ================== Properties p2 = new Properties(); Reader r = null; try { r = new FileReader(pwdFile); p2.load(r); String encryptedPwd = p2.getProperty("pwd"); System.out.println(encryptedPwd); System.out.println(cryptoUtils.decrypt(encryptedPwd)); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (GeneralSecurityException e) { e.printStackTrace(); } finally { if (r != null) { try { r.close(); } catch (IOException e) { e.printStackTrace(); } } } }