List of usage examples for java.util Properties store
public void store(OutputStream out, String comments) throws IOException
From source file:de.micromata.genome.gwiki.spi.storage.GWikiFileStorage.java
/** * Store props.// www . j av a 2 s . c om * * @param name the name * @param map the map */ public void storeProps(String name, Map<String, String> map) { Properties props = new Properties(); // no not put all, because properties does not like null values for (Map.Entry<String, String> me : map.entrySet()) { if (me.getKey() != null && me.getValue() != null) { props.setProperty(me.getKey(), me.getValue()); } } ByteArrayOutputStream bout = new ByteArrayOutputStream(); try { props.store(bout, ""); } catch (IOException ex) { throw new RuntimeIOException(ex); } writeBinaryFile(name, bout.toByteArray(), true); }
From source file:com.entertailion.java.fling.FlingFrame.java
private void storeProperties() { Properties prop = new Properties(); try {/* w w w. j a va2 s .co m*/ prop.setProperty(PROPERTY_TRANSCODING_PARAMETERS, transcodingParameterValues); prop.setProperty(PROPERTY_TRANSCODING_EXTENSIONS, transcodingExtensionValues); String manual = ""; for (DialServer dialServer : manualServers) { if (manual.length() > 0) { manual = manual + ":"; } manual = manual + dialServer.getFriendlyName() + ":" + dialServer.getIpAddress().getHostAddress(); } prop.setProperty(PROPERTY_MANUAL_SERVERS, manual); prop.store(new FileOutputStream("config.properties"), null); } catch (Exception ex) { } }
From source file:edu.utah.bmi.ibiomes.lite.IBIOMESLiteManager.java
private void createParsingConfigFile(String configFilePath, String parsingRuleSetFilePath, String softwareContext, int depth) { Properties prop = new Properties(); try {//from w w w .j a va 2s . c om //set the properties value if (parsingRuleSetFilePath != null && parsingRuleSetFilePath.length() > 0) prop.setProperty(PARSER_CONFIG_PROPERTY_RULE_SET_FILE, parsingRuleSetFilePath); if (softwareContext != null && softwareContext.length() > 0) prop.setProperty(PARSER_CONFIG_PROPERTY_SOFTWARE_CONTEXT, softwareContext); if (softwareContext != null && softwareContext.length() > 0) prop.setProperty(PARSER_CONFIG_PROPERTY_DEPTH_INDEPENDENCE, String.valueOf(depth)); //save properties to project root folder prop.store(new FileOutputStream(configFilePath), null); } catch (IOException ex) { ex.printStackTrace(); } }
From source file:org.jahia.services.usermanager.ldap.LdapProviderConfiguration.java
@Override public String create(Map<String, Object> parameters, Map<String, Object> flashScope) throws Exception { String[] propKeys = (String[]) parameters.get("propKey"); String[] propValues = (String[]) parameters.get("propValue"); if (propKeys == null || propValues == null) { throw new Exception("No property has been set"); }/* w w w. ja v a 2 s. c om*/ Properties properties = new Properties(); for (int i = 0; i < propKeys.length; i++) { String propValue = propValues[i]; if (StringUtils.isNotBlank(propValue)) { properties.put(propKeys[i], propValue); } } flashScope.put("ldapProperties", properties); String configName = (String) parameters.get("configName"); if (configName != null) { configName = JCRContentUtils.generateNodeName(configName); } flashScope.put("configName", configName); if (!testConnection(properties)) { throw new Exception("Connection to the LDAP server impossible"); } String providerKey; if (StringUtils.isBlank(configName)) { providerKey = "ldap"; configName = jahiaLDAPConfigFactory.getName() + "-config.cfg"; } else { providerKey = "ldap." + configName; configName = jahiaLDAPConfigFactory.getName() + "-" + configName + ".cfg"; } File file = new File(SettingsBean.getInstance().getJahiaModulesDiskPath()); if (file.exists()) { FileOutputStream out = new FileOutputStream(new File(file, configName)); try { properties.store(out, ""); } finally { IOUtils.closeQuietly(out); } } else { String pid = jahiaLDAPConfigFactory.getConfigPID(providerKey); if (pid != null) { throw new Exception("An LDAP provider with key '" + providerKey + "' already exists"); } Configuration configuration = configurationAdmin .createFactoryConfiguration(jahiaLDAPConfigFactory.getName()); properties.put(JahiaLDAPConfig.LDAP_PROVIDER_KEY_PROP, providerKey); configuration.update((Dictionary) properties); } return providerKey; }
From source file:com.edgenius.wiki.installation.UpgradeServiceImpl.java
@SuppressWarnings("unused") private void up3000To3100() throws Exception { log.info("Version 3.0 to 3.1 is upgarding"); String root = DataRoot.getDataRoot(); if (FileUtil.exist(root + Server.FILE)) { Server server = new Server(); Properties prop = FileUtil.loadProperties(root + Server.FILE); server.syncFrom(prop);// w w w. j a v a 2s. c om if (server.getMqServerEmbedded() == null || BooleanUtils.toBoolean(server.getMqServerEmbedded())) { //embedded if (!server.getMqServerUrl().startsWith("tcp://")) { server.setMqServerUrl( "tcp://" + server.getMqServerUrl() + "?wireFormat.maxInactivityDuration=0"); server.syncTo(prop); prop.store(FileUtil.getFileOutputStream(root + Server.FILE), "save by system program"); } } } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // database - remove all quartz tables - we don't backup Exportable job(backup and remove space) - it is not perfect but not big issue. if (FileUtil.exist(root + Server.FILE)) { Server server = new Server(); Properties prop = FileUtil.loadProperties(root + Server.FILE); server.syncFrom(prop); String dbType = server.getDbType(); String migrateSQL = dbType + "-3000-3100.sql"; DBLoader loader = new DBLoader(); ConnectionProxy con = loader.getConnection(dbType, server.getDbUrl(), server.getDbSchema(), server.getDbUsername(), server.getDbPassword()); loader.runSQLFile(dbType, migrateSQL, con); //reload quartz table log.info("Initialize quartz tables for system..."); Statement stat = con.createStatement(); Statement dropStat = con.createStatement(); List<String> lines = loader.loadSQLFile(dbType, dbType + "-quartz.sql"); for (String sql : lines) { sql = sql.replaceAll("\n", " ").trim(); if (sql.toLowerCase().startsWith("drop ")) { try { dropStat.execute(sql); } catch (Exception e) { log.error("Drop operation failed...." + sql); } continue; } stat.addBatch(sql); } stat.executeBatch(); dropStat.close(); stat.close(); con.close(); } }
From source file:io.sledge.core.impl.installer.SledgePackageConfigurer.java
private void createNewZipfileWithReplacedPlaceholders(InputStream packageStream, Path configurationPackagePath, Properties envProps) throws IOException { // For reading the original configuration package ZipInputStream configPackageZipStream = new ZipInputStream(new BufferedInputStream(packageStream), Charset.forName("UTF-8")); // For outputting the configured (placeholders replaced) version of the package as zip file File outZipFile = configurationPackagePath.toFile(); ZipOutputStream outConfiguredZipStream = new ZipOutputStream(new FileOutputStream(outZipFile)); ZipEntry zipEntry;//w ww. ja v a 2 s . c om while ((zipEntry = configPackageZipStream.getNextEntry()) != null) { if (zipEntry.isDirectory()) { configPackageZipStream.closeEntry(); continue; } else { ByteArrayOutputStream output = new ByteArrayOutputStream(); int length; byte[] buffer = new byte[2048]; while ((length = configPackageZipStream.read(buffer, 0, buffer.length)) >= 0) { output.write(buffer, 0, length); } InputStream zipEntryInputStream = new BufferedInputStream( new ByteArrayInputStream(output.toByteArray())); if (zipEntry.getName().endsWith("instance.properties")) { ByteArrayOutputStream envPropsOut = new ByteArrayOutputStream(); envProps.store(envPropsOut, "Environment configurations"); zipEntryInputStream = new BufferedInputStream( new ByteArrayInputStream(envPropsOut.toByteArray())); } else if (isTextFile(zipEntry.getName(), zipEntryInputStream)) { String configuredContent = StrSubstitutor.replace(output, envProps); zipEntryInputStream = new BufferedInputStream( new ByteArrayInputStream(configuredContent.getBytes())); } // Add to output zip file addToZipFile(zipEntry.getName(), zipEntryInputStream, outConfiguredZipStream); zipEntryInputStream.close(); configPackageZipStream.closeEntry(); } } outConfiguredZipStream.close(); configPackageZipStream.close(); }
From source file:be.ac.ua.comp.scarletnebula.core.Server.java
/** * Saves this server to its savefile./* w w w. ja va2 s. c o m*/ */ public void store() { // Write key to file final String dir = provider.getSaveFileDir(); final File dirFile = new File(dir); // Check if the key dir already exists if (!dirFile.exists()) { // If it does not exist, create the directory if (!dirFile.mkdirs()) { log.fatal("Cannot make server directory!"); return; } } // Write properties file. try { final Properties properties = new Properties(); properties.setProperty("friendlyName", getFriendlyName()); properties.setProperty("keypair", keypair); properties.setProperty("providerClassName", provider.getUnderlyingClassname()); properties.setProperty("sshLogin", sshLogin); properties.setProperty("statisticsCommand", statisticsCommand); properties.setProperty("sshPassword", sshPassword); properties.setProperty("vncPassword", vncPassword); properties.setProperty("useSshPassword", new Boolean(useSshPassword).toString()); properties.setProperty("tags", Utils.implode(new ArrayList<String>(tags), ",")); properties.setProperty("preferredDatastream", preferredDatastream); final FileOutputStream outputstream = new FileOutputStream(getSaveFilename(provider, serverImpl)); properties.store(outputstream, null); outputstream.close(); } catch (final Exception e) { log.error("Properties for " + this + " could not be stored.", e); } }
From source file:edmondskarp.Controller.EdmondsKarpController.java
public void saveConfig() { File newFile = new File("config.properties"); OutputStream os;/*from www .j a v a 2s . c o m*/ try { Properties properties = new Properties(); os = new FileOutputStream(newFile); properties.setProperty("defaultArrow", Config.getConfig().getDefaultArrow().getRGB() + ""); properties.setProperty("selectedArrow", Config.getConfig().getSelectedArrow().getRGB() + ""); properties.setProperty("usedArrow", Config.getConfig().getUsedArrow().getRGB() + ""); properties.setProperty("filledArrow", Config.getConfig().getFilledArrow().getRGB() + ""); properties.setProperty("dimText", Config.getConfig().getDimText() + ""); properties.setProperty("dimCircle", Config.getConfig().getDimCircle() + ""); properties.setProperty("posText", Config.getConfig().getPosText() + ""); properties.setProperty("fixedCapacity", Config.getConfig().getFixedCapacity() + ""); properties.setProperty("strokeCircle", Config.getConfig().getStrokeCircle() + ""); properties.setProperty("strokeArrow", Config.getConfig().getStrokeArrow() + ""); properties.setProperty("randomCapacity", Config.getConfig().isRandomCapacity() + ""); properties.store(os, "Properties File"); } catch (FileNotFoundException ex) { Logger.getLogger(EdmondsKarpController.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(EdmondsKarpController.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.pureinfo.srm.reports.table.data.pinggu.ParameterSetAction.java
/** * @see com.pureinfo.ark.interaction.ActionBase#executeAction() *///from ww w. java2 s . c om public ActionForward executeAction() throws PureException { tempOrgCode = request.getRequiredParameter("tempOrgCode", "code"); propFileName = ClassResourceUtil.mapFullPath(propFileName, true); Properties prop = new Properties(); InputStream iFile = null; FileOutputStream oFile = null; try { iFile = new FileInputStream(propFileName); prop.load(iFile); String codeInSystem = prop.getProperty("parameter.org.code"); if (StringUtils.isEmpty(codeInSystem)) { codeInSystem = tempOrgCode; } else { String[] codeArr = codeInSystem.split(","); Arrays.sort(codeArr); int index = Arrays.binarySearch(codeArr, tempOrgCode); if (index < 0) { codeInSystem += "," + tempOrgCode; } } prop.setProperty("parameter.org.code", codeInSystem); Enumeration e = request.getParameterNames(); while (e.hasMoreElements()) { String name = (String) e.nextElement(); if (!name.startsWith("para.")) { continue; } String value = request.getParameter(name); if (StringUtils.isEmpty(value)) { logger.debug("the value of " + name.substring(5) + " is empty.SKIP."); continue; } value = value.trim(); logger.debug("to set property:" + name.substring(5) + "with[" + value + "]"); prop.setProperty(name.substring(5), value); } oFile = new FileOutputStream(propFileName, false); prop.store(oFile, "parameter for pinggu"); // to reload properties. PureSystem.shutdown(); } catch (Exception ex) { throw new PureException(0, "", ex); } finally { try { if (iFile != null) iFile.close(); if (oFile != null) oFile.close(); prop.clear(); } catch (IOException e) { e.printStackTrace(System.err); } } return mapping.findForward("success"); }
From source file:org.geowebcache.storage.blobstore.file.FileBlobStore.java
/** * @see org.geowebcache.storage.BlobStore#putLayerMetadata(java.lang.String, java.lang.String, * java.lang.String)//from w ww . j a v a 2 s .c om */ public void putLayerMetadata(final String layerName, final String key, final String value) { Properties metadata = getLayerMetadata(layerName); if (null == value) { metadata.remove(key); } else { try { metadata.setProperty(key, URLEncoder.encode(value, "UTF-8")); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } } final File metadataFile = getMetadataFile(layerName); final String lockObj = metadataFile.getAbsolutePath().intern(); synchronized (lockObj) { OutputStream out; try { if (!metadataFile.getParentFile().exists()) { metadataFile.getParentFile().mkdirs(); } out = new FileOutputStream(metadataFile); } catch (FileNotFoundException e) { throw new RuntimeException(e); } try { String comments = "auto generated file, do not edit by hand"; metadata.store(out, comments); } catch (Exception e) { throw new RuntimeException(e); } finally { try { out.close(); } catch (IOException e) { log.warn(e.getMessage(), e); } } } }