List of usage examples for java.util Properties store
public void store(OutputStream out, String comments) throws IOException
From source file:com.properned.model.MultiLanguageProperties.java
public void save() throws IOException { logger.info("Save the multi language properties instance"); Set<Locale> setLocale = mapPropertiesFileByLocale.keySet(); for (Locale locale : setLocale) { PropertiesFile propertiesFile = mapPropertiesFileByLocale.get(locale); Properties properties = mapPropertiesByLocale.get(locale); if (properties == null) { continue; }/*from w w w . j a v a 2s. co m*/ logger.info("For the locale '" + locale + "', there is " + properties.size() + " properties to save"); OutputStream fileOutputStream = null; try { fileOutputStream = new BufferedOutputStream(new FileOutputStream(propertiesFile)); properties.store(fileOutputStream, ""); } finally { IOUtils.closeQuietly(fileOutputStream); } } this.setIsDirty(false); }
From source file:de.codesourcery.jasm16.ide.ApplicationConfig.java
@Override public void saveConfiguration() throws IOException { final Properties props = new Properties(); LOG.info("saveConfiguration(): Saving application config."); for (Map.Entry<String, String> keyValue : configProperties.entrySet()) { props.put(keyValue.getKey(), keyValue.getValue()); }/*from ww w .j ava 2 s .c o m*/ final String comments = "jASM16 workspace configuration -- automatically generated, do NOT edit"; try { final FileOutputStream out = new FileOutputStream(configFile); try { props.store(out, comments); } finally { IOUtils.closeQuietly(out); } } catch (IOException e) { LOG.fatal( "createDefaultConfiguration(): Failed to save configuration to " + configFile.getAbsolutePath(), e); throw e; } }
From source file:com.aionemu.gameserver.dataholders.loadingutils.XmlMerger.java
private void storeFileModifications(Properties props, File file) throws IOException { FileWriter writer = null;/*ww w . j a v a2 s .c o m*/ try { writer = new FileWriter(file, false); props.store(writer, " This file is machine-generated. DO NOT EDIT!"); } catch (IOException e) { logger.error("Failed to store file modification data."); throw e; } finally { IOUtils.closeQuietly(writer); } }
From source file:com.tcloud.bee.key.server.service.impl.KeyManageServiceImpl.java
@Override public QueryResult createKey(Param param, String owner) throws NoSuchAlgorithmException, FileNotFoundException, IOException { logger.info("User is trying to create key. userName:" + owner + ", keyName:" + param.getKeyName()); File newKeyfile = new File(env.getProperty("keyfile.path") + param.getKeyName()); if (newKeyfile.exists()) { logger.info("keyName \"" + param.getKeyName() + "\" exists, please choose another keyName."); return new QueryResult(BeeConstants.ResponseStatus.FAIL, BeeConstants.ErrorMap.get(BeeConstants.ResponseCode.ERROR_KM_KEYNAME_EXISTS), null); }//from www .j av a 2s. c o m KeyGenerator keyGen = KeyGenerator.getInstance("AES"); keyGen.init(256); SecretKey secretKey = keyGen.generateKey(); String hexkey = Hex.encodeHexString(secretKey.getEncoded()); Properties prop = new Properties(); prop.setProperty("owner", owner); prop.setProperty("keyName", param.getKeyName()); prop.setProperty("hexkey", hexkey); prop.setProperty("users", param.getUsers()); File keyFileFolder = new File(env.getProperty("keyfile.path")); if (!keyFileFolder.exists()) { keyFileFolder.mkdirs(); Runtime.getRuntime().exec("chmod 700 " + env.getProperty("keyfile.path")); } prop.store(new FileOutputStream(env.getProperty("keyfile.path") + param.getKeyName()), null); Runtime.getRuntime().exec("chmod 600 " + env.getProperty("keyfile.path") + param.getKeyName()); logger.info("save keyfile \"{}\" to keyfile folder: {}", param.getKeyName(), env.getProperty("keyfile.path")); return new QueryResult(BeeConstants.ResponseStatus.SUCCESS, "Key(" + param.getKeyName() + ") created", null); }
From source file:net.geoprism.FileMerger.java
public void mergeProperties(File base, File override, File export) throws IOException { if (!export.exists()) { export.createNewFile();/*from ww w .jav a2 s . co m*/ } if (!base.exists()) { if (override != export) { FileUtils.copyFile(override, export); } return; } Properties baseProps = new Properties(); baseProps.load(new FileInputStream(base)); Properties overrideProps = new Properties(); overrideProps.load(new FileInputStream(override)); Iterator<Object> i = overrideProps.keySet().iterator(); while (i.hasNext()) { String key = (String) i.next(); String value = overrideProps.getProperty(key); if (value.equals("$REMOVE$")) { baseProps.remove(key); } else { baseProps.setProperty(key, value); } } baseProps.store(new FileOutputStream(export), null); }
From source file:org.gvnix.dynamic.configuration.roo.addon.config.PropertiesDynamicConfiguration.java
/** * {@inheritDoc}//from w ww .ja v a2s.c o m */ public void write(DynPropertyList dynProps) { OutputStream outputStream = null; try { // Get the properties file path MutableFile file = getFile(); if (file != null) { Properties props = new Properties(); props.load(file.getInputStream()); for (DynProperty dynProp : dynProps) { if (props.containsKey(dynProp.getKey())) { props.put(dynProp.getKey(), dynProp.getValue()); } else { logger.log(Level.WARNING, "Property key ".concat(dynProp.getKey()) .concat(" to put value not exists on file")); } } outputStream = file.getOutputStream(); props.store(outputStream, null); } else if (!dynProps.isEmpty()) { logger.log(Level.WARNING, "File ".concat(getFilePath()) .concat(" not exists and there are dynamic properties to set it")); } } catch (IOException ioe) { throw new IllegalStateException(ioe); } finally { if (outputStream != null) { IOUtils.closeQuietly(outputStream); } } }
From source file:com.ibm.jaggr.core.impl.options.OptionsImpl.java
/** * Saves the specified Options properties to the properties file for the * aggregator.//from w w w. j a v a 2s . c om * * @param props * The properties to save * @throws IOException */ protected void saveProps(Properties props) throws IOException { // Persist the change to the properties file. File file = getPropsFile(); if (file != null) { FileWriter writer = new FileWriter(file); try { props.store(writer, null); } finally { writer.close(); } } }
From source file:org.onebusaway.nyc.presentation.impl.NycConfigurationServiceImpl.java
private void saveSettings(ConfigurationBean bean) { if (_path == null) return;/* w ww . j a v a 2 s .c o m*/ try { Properties properties = new Properties(); BeanInfo beanInfo = Introspector.getBeanInfo(ConfigurationBean.class); for (PropertyDescriptor desc : beanInfo.getPropertyDescriptors()) { String name = desc.getName(); if (name.equals("class")) continue; Method m = desc.getReadMethod(); Object value = m.invoke(bean); if (value != null) { properties.setProperty(name, value.toString()); } } properties.store(new FileWriter(_path), "onebusaway-nyc configuration"); } catch (Exception ex) { throw new IllegalStateException("error saving configuration to properties file " + _path, ex); } }
From source file:com.blackducksoftware.integration.hub.detect.interactive.mode.InteractiveMode.java
public void saveOptionsToApplicationProperties() { final Properties properties = optionsToProperties(); final File directory = new File(System.getProperty("user.dir")); String fileName = "application.properties"; if (profileName != null) { fileName = "application-" + profileName + ".properties"; }// www. j av a2 s . c o m final File applicationsProperty = new File(directory, fileName); final OutputStream outputStream; try { outputStream = new FileOutputStream(applicationsProperty); properties.store(outputStream, "Automatically generated during Detect Interactive Mode."); printStream.println(); printStream.println("Successfully saved to '" + applicationsProperty.getCanonicalPath() + "'!"); outputStream.close(); } catch (final IOException e) { printStream.println(e); printStream.println("Failed to write to application.properties."); throw new RuntimeException(e); } }
From source file:com.streamsets.datacollector.MiniSDCTestingUtility.java
private void rewriteProperties(File sdcPropertiesFile, ExecutionMode executionMode) throws IOException { InputStream sdcInStream = null; OutputStream sdcOutStream = null; Properties sdcProperties = new Properties(); try {/*from w w w .j av a 2 s .c o m*/ sdcInStream = new FileInputStream(sdcPropertiesFile); sdcProperties.load(sdcInStream); for (Map.Entry<String, String> mapEntry : getCommonProperties().entrySet()) { sdcProperties.setProperty(mapEntry.getKey(), mapEntry.getValue()); } sdcOutStream = new FileOutputStream(sdcPropertiesFile); sdcProperties.store(sdcOutStream, null); sdcOutStream.flush(); sdcOutStream.close(); } finally { if (sdcInStream != null) { IOUtils.closeQuietly(sdcInStream); } if (sdcOutStream != null) { IOUtils.closeQuietly(sdcOutStream); } } }