private static void writeYarnProperties(Properties properties, File propertiesFile) { try (final OutputStream out = new FileOutputStream(propertiesFile)) { properties.store(out, "Generated YARN properties file"); } catch (IOException e) { throw new RuntimeException("Error writing the properties file", e); } propertiesFile.setReadable(true, false); // readable for all. }
/** * Stores the data in {@code config} into {@code writer} in a standard java * {@link Properties} format. * * @param config the data to store in the properties file. * @param writer the {@link Writer} to store the properties in. * @throws IOException IO error. */ public static void store( Map<String, String> config, Writer writer ) throws IOException { Properties properties = new Properties(); properties.putAll( config ); properties.store( writer, null ); }
FileInputStream in = new FileInputStream("First.properties"); Properties props = new Properties(); props.load(in); in.close(); FileOutputStream out = new FileOutputStream("First.properties"); props.setProperty("country", "america"); props.store(out, null); out.close();
private void writeProperties(Properties props, String file) throws IOException { File propFile = new File(file); try (OutputStream os = new FileOutputStream(propFile)) { props.store(os, "Docker ports"); } catch (IOException e) { throw new IOException("Cannot write properties to " + file + ": " + e, e); } } }
public void gen() throws Exception { addTinkerID(); Properties newProperties = new Properties(); for (String key : config.mPackageFields.keySet()) { newProperties.put(key, config.mPackageFields.get(key)); } String comment = "base package config field"; OutputStream os = null; try { os = new BufferedOutputStream(new FileOutputStream(packageInfoFile, false)); newProperties.store(os, comment); } finally { StreamUtil.closeQuietly(os); } } }
private static void storeSettings() { FileOutputStream st = null; try { st = new FileOutputStream(PROPERTIES_FILE_NAME); PROPERTIES.store(st, null); } catch (final IOException e) { // ignore } finally { try { if (st != null) { st.close(); } } catch (final IOException ex) { // ignore } } }
Properties props = new Properties() { @Override public Set<Object> keySet(){ return Collections.unmodifiableSet(new TreeSet<Object>(super.keySet())); } @Override public synchronized Enumeration<Object> keys() { return Collections.enumeration(new TreeSet<Object>(super.keySet())); } }; props.put("B", "Should come second"); props.put("A", "Should come first"); props.storeToXML(new FileOutputStream(new File("sortedProps.xml")), null); props.store(new FileOutputStream(new File("sortedProps.properties")), null);
/** * Stores the data in {@code config} into {@code stream} in a standard java * {@link Properties} format. * @param config the data to store in the properties file. * @param stream the {@link OutputStream} to store the properties in. * @throws IOException IO error. */ public static void store( Map<String, String> config, OutputStream stream ) throws IOException { Properties properties = new Properties(); for ( Map.Entry<String, String> property : config.entrySet() ) { properties.setProperty( property.getKey(), property.getValue() ); } properties.store( stream, null ); }
@Test public void testNoManifest() throws Exception { File dir = new File(System.getProperty("test.build.dir", "target/test-dir"), TestJarFinder.class.getName() + "-testNoManifest"); delete(dir); dir.mkdirs(); File propsFile = new File(dir, "props.properties"); Writer writer = new FileWriter(propsFile); new Properties().store(writer, ""); writer.close(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); JarOutputStream zos = new JarOutputStream(baos); JarFinder.jarDir(dir, "", zos); JarInputStream jis = new JarInputStream(new ByteArrayInputStream(baos.toByteArray())); Assert.assertNotNull(jis.getManifest()); jis.close(); } }
byte[] defaultConfigurationData) throws IOException { Properties clientProperties = new Properties(); clientProperties.load(clientPropertiesStream); clientProperties.store(baos, "");
public static void write(String propertyFile, String key, String value) throws IOException { Properties props = getProperty(propertyFile); OutputStream fos = new FileOutputStream(propertyFile); props.setProperty(key, value); props.store(fos, "Update '" + key + "' value"); }
@Override public synchronized void persist(String key, String value) { if (!loadFromFile(_file)) { s_logger.error("Failed to load changes and then write to them"); } _properties.setProperty(key, value); FileOutputStream output = null; try { output = new FileOutputStream(_file); _properties.store(output, _name); output.flush(); output.close(); } catch (IOException e) { s_logger.error("Uh-oh: ", e); } finally { IOUtils.closeQuietly(output); } }
@Override public void load() { try (InputStream stream = new FileInputStream(path)) { properties.load(stream); } catch (FileNotFoundException ignored) { } catch (IOException e) { try (OutputStream output = new FileOutputStream(path)) { properties.store(output, "Don't put comments; they get removed"); } catch (IOException e) { log.log(Level.WARNING, "Failed to write configuration", e);
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { resp.setHeader("Plugins-Status", status); pluginProps.setProperty("Active Mock Bundle 1", "1.1.1"); pluginProps.setProperty("Active Mock Bundle 2", "2.2.2"); ByteArrayOutputStream baos = new ByteArrayOutputStream(); pluginProps.store(baos, "Go Plugins for Testing"); resp.getOutputStream().write(baos.toByteArray()); baos.close(); } }
public static void updateTerm(long term) throws Exception { File file = new File(META_FILE_NAME); if (!file.exists() && !file.getParentFile().mkdirs() && !file.createNewFile()) { throw new IllegalStateException("failed to create meta file"); } try (FileOutputStream outStream = new FileOutputStream(file)) { // write meta meta.setProperty("term", String.valueOf(term)); meta.store(outStream, null); } }
File lockfile = new File(file.getAbsolutePath() + ".lock"); if (!lockfile.exists()) { lockfile.createNewFile(); file.createNewFile(); try (FileOutputStream outputFile = new FileOutputStream(file)) { properties.store(outputFile, "Dubbo Registry Cache");
Map<String, String> ldapContent = new HashMap<String, String>(); Properties properties = new Properties(); for (Map.Entry<String,String> entry : ldapContent.entrySet()) { properties.put(entry.getKey(), entry.getValue()); } properties.store(new FileOutputStream("data.properties"), null);
@Override public void save(String key, String value) throws IOException { if (file != null) { synchronized (this) { properties.put(key, value); final FileOutputStream out = new FileOutputStream(file); properties.store(out, null); out.flush(); out.close(); } } else { throw new IOException(location + " is not writeable"); } }
public void putDatabaseVersion(SystemProperties config, Integer version) { final File versionFile = getDatabaseVersionFile(config); versionFile.getParentFile().mkdirs(); try (Writer writer = new FileWriter(versionFile)) { Properties prop = new Properties(); prop.setProperty("databaseVersion", version.toString()); prop.store(writer, "Generated database version"); } catch (Exception e) { throw new Error("Problem writing current database version ", e); } }
private void writeCassandraSnitchProperties() { final NodeType nodeType = dseConfig.getNodeType(); if (nodeType == NodeType.REAL_TIME_QUERY) return; Reader reader = null; try { String filePath = config.getCassHome() + "/conf/" + RACKDC_PROPERTY_FILENAME; reader = new FileReader(filePath); Properties properties = new Properties(); properties.load(reader); String suffix = ""; if (nodeType == NodeType.SEARCH) suffix = "_solr"; if (nodeType == NodeType.ANALYTIC_HADOOP) suffix = "_hadoop"; if (nodeType == NodeType.ANALYTIC_HADOOP_SPARK) suffix = "_hadoop_spark"; if (nodeType == NodeType.ANALYTIC_SPARK) suffix = "_spark"; properties.put("dc_suffix", suffix); properties.store(new FileWriter(filePath), ""); } catch (Exception e) { throw new RuntimeException("Unable to read " + RACKDC_PROPERTY_FILENAME, e); } finally { FileUtils.closeQuietly(reader); } }