List of usage examples for java.util Properties store
public void store(OutputStream out, String comments) throws IOException
From source file:com.edgenius.core.DataRoot.java
/** * @param root//from w w w . j a va 2 s . com * @return */ public static String saveDataRoot(String root) { if (StringUtils.isBlank(root)) { log.error("Unable to save blank root:" + root); return root; } String sysRoot = System.getProperty(rootKey); if (sysRoot != null && sysRoot.trim().length() > 0) { log.warn("User set {} in System properties, the persisted system root won't be saved." + " User must ensure the consist while restarting the system", rootKey); return formatRoot(sysRoot); } root = formatRoot(root); FileOutputStream out = null; try { Properties prop = new Properties(); prop.setProperty(rootKey, root); out = FileUtil.getFileOutputStream(rootResource); prop.store(out, "IMPORTANT: The directory must start with file:// and end with /. The path separator is /."); log.info("Classpath geniuswiki properties file is saved."); } catch (Exception e) { log.error("Save system root failed.", e); } finally { IOUtils.closeQuietly(out); } return root; }
From source file:com.moviejukebox.TestLogger.java
/** * Save properties to a file//w w w .j a v a 2 s . c o m * * @param props * @param propertyFile * @param headerText */ public static void saveProperties(Properties props, File propertyFile, String headerText) { try (OutputStream out = new FileOutputStream(propertyFile)) { if (StringUtils.isNotBlank(headerText)) { props.store(out, headerText); } } catch (FileNotFoundException ex) { LOG.warn("Failed to find properties file", ex); } catch (IOException ex) { LOG.warn("Failed to read properties file", ex); } }
From source file:de.ingrid.interfaces.csw.admin.command.AdminManager.java
/** * Read the override configuration and write a new bcrypt-hash password. */// w w w .ja v a 2s. c o m private static void resetPassword(String newPassword) { try { InputStream is = new FileInputStream("conf/config.override.properties"); Properties props = new Properties(); props.load(is); props.setProperty("ingrid.admin.password", BCrypt.hashpw(newPassword, BCrypt.gensalt())); OutputStream os = new FileOutputStream("conf/config.override.properties"); props.store(os, "Override configuration written by the application"); os.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:org.yamj.api.trakttv.TestLogger.java
/** * Save properties to a file//ww w. j a v a2 s.c o m * * @param props * @param propertyFile * @param headerText */ public static void saveProperties(Properties props, File propertyFile, String headerText) { if (StringUtils.isBlank(headerText)) { return; } try (OutputStream out = new FileOutputStream(propertyFile)) { props.store(out, headerText); } catch (FileNotFoundException ex) { LOG.warn("Failed to find properties file", ex); } catch (IOException ex) { LOG.warn("Failed to read properties file", ex); } }
From source file:com.haulmont.cuba.core.entity.LocaleHelper.java
public static String convertPropertiesToString(Properties properties) { StringWriter writer = new StringWriter(); String result = null;// www . ja va 2 s .c om boolean written = false; try { properties.store(writer, ""); written = true; } catch (IOException ignored) { } if (written) { StringBuffer buffer = writer.getBuffer(); Pattern pattern = Pattern.compile("(?m)^#.*\\s\\s"); result = pattern.matcher(buffer).replaceAll(""); } return result; }
From source file:Main.java
/** * Method write.// ww w .j a v a 2s . c o m * * @param filepath * String * @param theProperties * Properties * @param propComments * String * @throws IOException */ public static void write(String filepath, Properties theProperties, String propComments) throws IOException { BufferedOutputStream bos = null; try { File file = new File(filepath); bos = new BufferedOutputStream(new FileOutputStream(file)); theProperties.store(bos, propComments); } finally { if (bos != null) { bos.close(); bos = null; } } }
From source file:ch.vorburger.mifos.wiki.ZWikiScraper.java
private static void saveProperties(Properties properties, File file) throws IOException { FileOutputStream fos = new FileOutputStream(file); try {// www . j av a 2 s.c om properties.store(fos, ZWikiScraper.class.getName()); } finally { fos.close(); } }
From source file:com.adaptris.core.MimeEncoder.java
/** * Get metadata out of an AdaptrisMessage * * @return a byte array representing the adaptris message *///from w w w .j ava 2s. c om private static byte[] getMetadata(AdaptrisMessage msg) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); Properties metadata = convertToProperties(msg.getMetadata()); metadata.store(out, ""); out.close(); return out.toByteArray(); }
From source file:com.baidu.rigel.biplatform.parser.util.PropertiesUtil.java
/** * toString//from w w w .j av a2s .c om * @param props * @param comment * @param encoding * @return * @throws UnsupportedEncodingException */ public static String toString(Properties props, String comment, String encoding) throws UnsupportedEncodingException { ByteArrayOutputStream baos = null; try { baos = new ByteArrayOutputStream(); props.store(baos, comment); baos.flush(); return new String(baos.toByteArray(), encoding); } catch (UnsupportedEncodingException e) { throw e; } catch (IOException e) { throw new Error("An IOException while working with byte array streams?!", e); } finally { IOUtils.closeQuietly(baos); } }
From source file:actors.ConfigUtil.java
/** * Generate the config file in the 'wherehows.app_folder' folder * The file name is {whEtlExecId}.config * * @param whEtlExecId/* www. j a v a 2s .c om*/ * @param props * @return void */ static void generateProperties(long whEtlExecId, Properties props, String outDir) throws IOException { File dir = new File(outDir); if (!dir.exists()) { dir.mkdirs(); } File configFile = new File(dir, whEtlExecId + ".properties"); FileWriter writer = new FileWriter(configFile); props.store(writer, "exec id : " + whEtlExecId + " job configurations"); writer.close(); }