Java Code Examples for org.apache.commons.configuration.PropertiesConfiguration#save()
The following examples show how to use
org.apache.commons.configuration.PropertiesConfiguration#save() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StarTreeIndexMapUtils.java From incubator-pinot with Apache License 2.0 | 6 votes |
/** * Stores the index maps for multiple star-trees into a file. */ public static void storeToFile(List<Map<IndexKey, IndexValue>> indexMaps, File indexMapFile) throws ConfigurationException { Preconditions.checkState(!indexMapFile.exists(), "Star-tree index map file already exists"); PropertiesConfiguration configuration = new PropertiesConfiguration(indexMapFile); int numStarTrees = indexMaps.size(); for (int i = 0; i < numStarTrees; i++) { Map<IndexKey, IndexValue> indexMap = indexMaps.get(i); for (Map.Entry<IndexKey, IndexValue> entry : indexMap.entrySet()) { IndexKey key = entry.getKey(); IndexValue value = entry.getValue(); configuration.addProperty(key.getPropertyName(i, OFFSET_SUFFIX), value._offset); configuration.addProperty(key.getPropertyName(i, SIZE_SUFFIX), value._size); } } configuration.save(); }
Example 2
Source File: DictionaryToRawIndexConverter.java From incubator-pinot with Apache License 2.0 | 6 votes |
/** * Helper method to update the metadata.properties for the converted segment. * * @param segmentDir Segment directory * @param columns Converted columns * @param tableName New table name to be written in the meta-data. Skipped if null. * @throws IOException * @throws ConfigurationException */ private void updateMetadata(File segmentDir, String[] columns, String tableName) throws IOException, ConfigurationException { File metadataFile = new File(segmentDir, V1Constants.MetadataKeys.METADATA_FILE_NAME); PropertiesConfiguration properties = new PropertiesConfiguration(metadataFile); if (tableName != null) { properties.setProperty(V1Constants.MetadataKeys.Segment.TABLE_NAME, tableName); } for (String column : columns) { properties.setProperty( V1Constants.MetadataKeys.Column.getKeyFor(column, V1Constants.MetadataKeys.Column.HAS_DICTIONARY), false); properties.setProperty( V1Constants.MetadataKeys.Column.getKeyFor(column, V1Constants.MetadataKeys.Column.BITS_PER_ELEMENT), -1); } properties.save(); }
Example 3
Source File: PropertyFileManipulator.java From ankush with GNU Lesser General Public License v3.0 | 6 votes |
/** * Delete conf value. * * @param file * the file * @param propertyName * the property name * @return true, if successful */ @Override public boolean deleteConfValue(String file, String propertyName) { boolean status = false; try { // read conf file File confFile = new File(file); if (!confFile.exists()) { System.err.println("File " + file + " does not exists."); status = false; } PropertiesConfiguration props = new PropertiesConfiguration(file); props.getLayout().setSeparator(propertyName, "="); if (props.getProperty(propertyName) != null) { props.clearProperty(propertyName); props.save(); status = true; } } catch (Exception e) { System.err.println(e.getMessage()); } return status; }
Example 4
Source File: PropertyFileManipulator.java From ankush with GNU Lesser General Public License v3.0 | 6 votes |
/** * Edits the conf value. * * @param file * the file * @param propertyName * the property name * @param newPropertyValue * the new property value * @return true, if successful */ @Override public boolean editConfValue(String file, String propertyName, String newPropertyValue) { boolean status = false; try { // read conf file File confFile = new File(file); if (!confFile.exists()) { System.err.println("File " + file + " does not exists."); status = false; } PropertiesConfiguration props = new PropertiesConfiguration(file); props.setProperty(propertyName, newPropertyValue); props.getLayout().setSeparator(propertyName, "="); props.save(); status = true; } catch (Exception e) { System.err.println(e.getMessage()); } return status; }
Example 5
Source File: TestDbSetup.java From cloudstack with Apache License 2.0 | 6 votes |
public static void updateSqlPort(int port, String propertyFileOverride) throws Exception { PropertiesConfiguration config = new PropertiesConfiguration(propertyFileOverride); System.out.println("File: " + propertyFileOverride + "; old: db.properties port: " + config.getProperty("db.cloud.port") + ", new port: " + port); config.setProperty("db.cloud.port", "" + port); config.setProperty("db.cloud.username", System.getProperty("user.name")); config.setProperty("db.cloud.password", ""); config.setProperty("db.usage.port", "" + port); config.setProperty("db.usage.username", System.getProperty("user.name")); config.setProperty("db.usage.password", ""); config.setProperty("db.simulator.port", "" + port); config.setProperty("db.simulator.username", System.getProperty("user.name")); config.setProperty("db.simulator.password", ""); config.save(); }
Example 6
Source File: GraphContextImpl.java From windup with Eclipse Public License 1.0 | 5 votes |
private void writeToPropertiesFile(Configuration conf, File file) { try { PropertiesConfiguration propConf = new PropertiesConfiguration(file); propConf.append(conf); propConf.save(); } catch (ConfigurationException ex) { throw new RuntimeException("Failed writing Titan config to " + file.getAbsolutePath() + ": " + ex.getMessage(), ex); } }
Example 7
Source File: BaseSecurityTest.java From atlas with Apache License 2.0 | 5 votes |
protected void generateTestProperties(Properties props) throws ConfigurationException, IOException { PropertiesConfiguration config = new PropertiesConfiguration(System.getProperty("user.dir") + "/../src/conf/" + ApplicationProperties.APPLICATION_PROPERTIES); for (String propName : props.stringPropertyNames()) { config.setProperty(propName, props.getProperty(propName)); } File file = new File(System.getProperty("user.dir"), ApplicationProperties.APPLICATION_PROPERTIES); file.deleteOnExit(); Writer fileWriter = new FileWriter(file); config.save(fileWriter); }
Example 8
Source File: SegmentV1V2ToV3FormatConverter.java From incubator-pinot with Apache License 2.0 | 5 votes |
private void createMetadataFile(File currentDir, File v3Dir) throws ConfigurationException { File v2MetadataFile = new File(currentDir, V1Constants.MetadataKeys.METADATA_FILE_NAME); File v3MetadataFile = new File(v3Dir, V1Constants.MetadataKeys.METADATA_FILE_NAME); final PropertiesConfiguration properties = new PropertiesConfiguration(v2MetadataFile); // update the segment version properties.setProperty(V1Constants.MetadataKeys.Segment.SEGMENT_VERSION, SegmentVersion.v3.toString()); properties.save(v3MetadataFile); }
Example 9
Source File: EncryptionSecretKeyChanger.java From cloudstack with Apache License 2.0 | 5 votes |
private boolean migrateProperties(File dbPropsFile, Properties dbProps, String newMSKey, String newDBKey) { System.out.println("Migrating db.properties.."); StandardPBEStringEncryptor msEncryptor = new StandardPBEStringEncryptor(); ; initEncryptor(msEncryptor, newMSKey); try { PropertiesConfiguration newDBProps = new PropertiesConfiguration(dbPropsFile); if (newDBKey != null && !newDBKey.isEmpty()) { newDBProps.setProperty("db.cloud.encrypt.secret", "ENC(" + msEncryptor.encrypt(newDBKey) + ")"); } String prop = dbProps.getProperty("db.cloud.password"); if (prop != null && !prop.isEmpty()) { newDBProps.setProperty("db.cloud.password", "ENC(" + msEncryptor.encrypt(prop) + ")"); } prop = dbProps.getProperty("db.usage.password"); if (prop != null && !prop.isEmpty()) { newDBProps.setProperty("db.usage.password", "ENC(" + msEncryptor.encrypt(prop) + ")"); } newDBProps.save(dbPropsFile.getAbsolutePath()); } catch (Exception e) { e.printStackTrace(); return false; } System.out.println("Migrating db.properties Done."); return true; }
Example 10
Source File: TestUtils.java From incubator-atlas with Apache License 2.0 | 5 votes |
public static void writeConfiguration(PropertiesConfiguration configuration, String fileName) throws Exception { LOG.debug("Storing configuration in file {}", fileName); File file = new File(fileName); File parentFile = file.getParentFile(); if (!parentFile.exists() && !parentFile.mkdirs()) { throw new Exception("Failed to create dir " + parentFile.getAbsolutePath()); } file.createNewFile(); configuration.save(new FileWriter(file)); }
Example 11
Source File: BaseSecurityTest.java From incubator-atlas with Apache License 2.0 | 5 votes |
protected void generateTestProperties(Properties props) throws ConfigurationException, IOException { PropertiesConfiguration config = new PropertiesConfiguration(System.getProperty("user.dir") + "/../src/conf/" + ApplicationProperties.APPLICATION_PROPERTIES); for (String propName : props.stringPropertyNames()) { config.setProperty(propName, props.getProperty(propName)); } File file = new File(System.getProperty("user.dir"), ApplicationProperties.APPLICATION_PROPERTIES); file.deleteOnExit(); Writer fileWriter = new FileWriter(file); config.save(fileWriter); }
Example 12
Source File: PropertiesConfigurationWrapper.java From StatsAgg with Apache License 2.0 | 5 votes |
public static void savePropertiesConfigurationFile(File propertyFile, PropertiesConfiguration propertiesConfiguration) { try { propertiesConfiguration.save(propertyFile); } catch (Exception e) { logger.error(e.toString() + System.lineSeparator() + StackTrace.getStringFromStackTrace(e)); } }
Example 13
Source File: PropertiesConfigurationWrapper.java From StatsAgg with Apache License 2.0 | 5 votes |
public static void savePropertiesConfigurationFile(String filePath, String filename, PropertiesConfiguration propertiesConfiguration) { try { File propertyFile = new File(filePath + File.separator + filename); propertiesConfiguration.save(propertyFile); } catch (Exception e) { logger.error(e.toString() + System.lineSeparator() + StackTrace.getStringFromStackTrace(e)); } }
Example 14
Source File: ConfigUtil.java From big-c with Apache License 2.0 | 5 votes |
static void dump(String header, Configuration c, PrintStream out) { PropertiesConfiguration p = new PropertiesConfiguration(); p.copy(c); if (header != null) { out.println(header); } try { p.save(out); } catch (Exception e) { throw new RuntimeException("Error saving config", e); } }
Example 15
Source File: MetricsConfig.java From big-c with Apache License 2.0 | 5 votes |
static String toString(Configuration c) { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); try { PrintStream ps = new PrintStream(buffer, false, "UTF-8"); PropertiesConfiguration tmp = new PropertiesConfiguration(); tmp.copy(c); tmp.save(ps); return buffer.toString("UTF-8"); } catch (Exception e) { throw new MetricsConfigException(e); } }
Example 16
Source File: MetricsSystemImpl.java From big-c with Apache License 2.0 | 5 votes |
@Override public synchronized String currentConfig() { PropertiesConfiguration saver = new PropertiesConfiguration(); StringWriter writer = new StringWriter(); saver.copy(config); try { saver.save(writer); } catch (Exception e) { throw new MetricsConfigException("Error stringify config", e); } return writer.toString(); }
Example 17
Source File: ConfigUtil.java From hadoop with Apache License 2.0 | 5 votes |
static void dump(String header, Configuration c, PrintStream out) { PropertiesConfiguration p = new PropertiesConfiguration(); p.copy(c); if (header != null) { out.println(header); } try { p.save(out); } catch (Exception e) { throw new RuntimeException("Error saving config", e); } }
Example 18
Source File: MetricsConfig.java From hadoop with Apache License 2.0 | 5 votes |
static String toString(Configuration c) { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); try { PrintStream ps = new PrintStream(buffer, false, "UTF-8"); PropertiesConfiguration tmp = new PropertiesConfiguration(); tmp.copy(c); tmp.save(ps); return buffer.toString("UTF-8"); } catch (Exception e) { throw new MetricsConfigException(e); } }
Example 19
Source File: MetricsSystemImpl.java From hadoop with Apache License 2.0 | 5 votes |
@Override public synchronized String currentConfig() { PropertiesConfiguration saver = new PropertiesConfiguration(); StringWriter writer = new StringWriter(); saver.copy(config); try { saver.save(writer); } catch (Exception e) { throw new MetricsConfigException("Error stringify config", e); } return writer.toString(); }
Example 20
Source File: TestUtils.java From atlas with Apache License 2.0 | 5 votes |
public static void writeConfiguration(PropertiesConfiguration configuration, String fileName) throws Exception { LOG.debug("Storing configuration in file {}", fileName); File file = new File(fileName); File parentFile = file.getParentFile(); if (!parentFile.exists() && !parentFile.mkdirs()) { throw new Exception("Failed to create dir " + parentFile.getAbsolutePath()); } file.createNewFile(); configuration.save(new FileWriter(file)); }