List of usage examples for java.util Properties store
public void store(OutputStream out, String comments) throws IOException
From source file:hu.petabyte.redflags.engine.tedintf.MaxNumberDeterminer.java
private void saveMaxNumCache() { try {//w w w. j a v a 2 s. c om FileWriter w = new FileWriter(CACHE_FILENAME); Properties p = new Properties(); for (Entry<Integer, Integer> e : maxNumCache.entrySet()) { int year = e.getKey(); int number = e.getValue(); if (year < Calendar.getInstance().get(Calendar.YEAR)) { // should not save current year, because it changes! p.put(Integer.toString(year), Integer.toString(number)); } } p.store(w, "ted max numbers for each year"); w.close(); } catch (IOException e) { LOG.warn("Failed to save max number cache"); LOG.trace("Failed to save max number cache", e); } }
From source file:avoking.com.documentos.scheduler.startup.Main.java
public void saveProps(String depart, int rol) { try {/*from w w w . jav a 2s . c o m*/ Properties props = new Properties(); props.setProperty("departamento", depart); props.setProperty("rol", rol + ""); props.setProperty("pathProcedimiento", pathPro); props.setProperty("pathEspecificacion", pathEsp); props.setProperty("pathPolitica", pathPol); File f = new File("config.properties"); OutputStream out = new FileOutputStream(f); props.store(out, "Configuracion scheduler ak (CRS)"); JOptionPane.showMessageDialog(null, "Configuracin creada en: "); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.att.api.oauth.OAuthToken.java
/** * Saves this token to a file in an asynchronous-safe manner. * * @param fpath file path/* w w w. ja v a2 s . c om*/ * @throws IOException if unable to save token */ public void saveToken(String fpath) throws IOException { FileOutputStream fOutputStream = null; FileLock fLock = null; // save to cached tokens synchronized (LOCK_OBJECT) { // lazy init if (cachedTokens == null) { cachedTokens = new HashMap<String, OAuthToken>(); } OAuthToken.cachedTokens.put(fpath, this); try { fOutputStream = new FileOutputStream(fpath); fLock = fOutputStream.getChannel().lock(); Properties props = new Properties(); props.setProperty("accessToken", accessToken); props.setProperty("creationTime", String.valueOf(creationTime)); props.setProperty("expiresIn", String.valueOf(expiresIn)); props.setProperty("refreshToken", refreshToken); props.store(fOutputStream, "Token Information"); } catch (IOException e) { throw e; // pass along exception } finally { if (fLock != null) { fLock.release(); } if (fOutputStream != null) { fOutputStream.close(); } } } }
From source file:com.opengamma.component.ComponentManager.java
/** * Intelligently sets the property to the merged set of properties. * <p>/*w w w.j a v a 2 s. co m*/ * The key "MANAGER.PROPERTIES" can be used in a properties file to refer to * the entire set of merged properties. This is normally what you want to pass * into other systems (such as Spring) that need a set of properties. * * @param bean the bean, not null * @param mp the property, not null * @throws Exception allowing throwing of a checked exception */ protected void setPropertyMergedProperties(Bean bean, MetaProperty<?> mp) throws Exception { final String desc = MANAGER_PROPERTIES + " for " + mp; final ByteArrayOutputStream out = new ByteArrayOutputStream(1024); Properties props = new Properties(); props.putAll(getProperties()); props.store(out, desc); out.close(); Resource resource = new AbstractResource() { @Override public String getDescription() { return MANAGER_PROPERTIES; } @Override public String getFilename() throws IllegalStateException { return MANAGER_PROPERTIES + ".properties"; } @Override public InputStream getInputStream() throws IOException { return new ByteArrayInputStream(out.toByteArray()); } @Override public String toString() { return desc; } }; mp.set(bean, resource); }
From source file:de.micromata.genome.gwiki.jetty.GWikiInitialSetup.java
protected void storeConfig() { getConfigLocation();/*from ww w . j av a2 s.c o m*/ File propFile = getConfigLocation(gwikiPropFileName); String contextFile = getGWikiContextFile(); props.put("gwiki.contextfile", contextFile); Properties properties = new SortedProperties(); for (Map.Entry<String, String> me : props.entrySet()) { properties.put(me.getKey(), me.getValue()); } try (FileOutputStream fis = new FileOutputStream(propFile)) { properties.store(fis, "Generated by Gwiki"); } catch (IOException ex) { throw new RuntimeException("Failed to write Properties file: " + ex.getMessage(), ex); } message("The settings are stored in " + propFile.getAbsolutePath() + "\nYou can change the settings using a text editor."); message("GWiki Server is now starting"); LocalSettings ls = LocalSettings.get(); ls.getMap().putAll(props); ls.getMap().putAll(this.initialProps); }
From source file:eu.dnetlib.maven.plugin.properties.WritePredefinedProjectProperties.java
/** * Writes properties./* ww w .j av a 2s . co m*/ * @param properties * @param file * @throws MojoExecutionException */ protected void writeProperties(Properties properties, File file) throws MojoExecutionException { OutputStream out = null; try { out = FileUtils.openOutputStream(outputFile); properties.store(out, "Properties"); } catch (IOException e) { throw new MojoExecutionException("Error creating properties file", e); } finally { IOUtils.closeQuietly(out); } }
From source file:com.amazonaws.eclipse.ec2.keypairs.KeyPairManager.java
private void storeRegisteredKeyPairs(String accountId, Properties registeredKeyPairs) throws IOException { File pluginStateLocation = Ec2Plugin.getDefault().getStateLocation().toFile(); File registeredKeyPairsFile = new File(pluginStateLocation, getKeyPropertiesFileName(accountId)); registeredKeyPairsFile.createNewFile(); FileOutputStream fileOutputStream = new FileOutputStream(registeredKeyPairsFile); try {/*w w w . ja v a 2s .co m*/ registeredKeyPairs.store(fileOutputStream, null); } finally { fileOutputStream.close(); } }
From source file:it.greenvulcano.configuration.BaseConfigurationManager.java
@Override public synchronized void saveXMLConfigProperties(Properties xmlConfigProperties) throws IOException { if (xmlConfigProperties != null) { try (OutputStream xmlConfigPropertiesOutputStream = Files.newOutputStream( Paths.get(XMLConfig.getBaseConfigPath(), "XMLConfig.properties"), StandardOpenOption.WRITE, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)) { xmlConfigProperties.store(xmlConfigPropertiesOutputStream, null); }/*from w ww.j av a2s .c o m*/ } }
From source file:com.erudika.scoold.utils.LanguageUtils.java
private void writeLanguageToFile(String langCode, Map<String, String> lang) { if (lang != null && !lang.isEmpty() && langCode != null && langCode.length() == 2) { FileOutputStream fos = null; try {//w w w . java 2s .c o m Properties langProps = new Properties(); langProps.putAll(lang); File file = new File("lang_" + langCode + ".properties"); fos = new FileOutputStream(file); langProps.store(fos, langCode); int progress = 0; for (Map.Entry<String, String> entry : lang.entrySet()) { if (!getDefaultLanguage().get(entry.getKey()).equals(entry.getValue())) { progress++; } } if (progress > 0) { updateTranslationProgressMap(langCode, progress); } } catch (Exception ex) { logger.error("Could not write language to file: ", ex); } finally { try { if (fos != null) { fos.close(); } } catch (IOException ex) { logger.error(null, ex); } } } }
From source file:net.mybox.mybox.ClientSetup.java
/** * Generate the config file after everything has been setup */// w w w .j av a 2 s . c o m private boolean saveConfig() { // TODO: handle existing file Properties config = new Properties(); config.setProperty("serverName", account.serverName); config.setProperty("serverPort", Integer.toString(account.serverPort)); config.setProperty("email", account.email); config.setProperty("salt", account.salt); //if (!account.directory.equals(Client.defaultClientDir)) config.setProperty("directory", account.directory); try { FileOutputStream MyOutputStream = new FileOutputStream(Client.configFile); config.store(MyOutputStream, "Mybox client configuration file"); } catch (Exception e) { Server.printErrorExit(e.getMessage()); } System.out.println("Config file written: " + Client.configFile); return true; }