List of usage examples for org.apache.commons.configuration PropertiesConfiguration save
public void save(Writer writer) throws ConfigurationException
From source file:com.linkedin.pinot.core.segment.index.converter.SegmentV1V2ToV3FormatConverter.java
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); }
From source file:com.liferay.ide.project.core.upgrade.UpgradeMetadataHandler.java
private void updateProperties(IFile file, String propertyName, String propertiesValue) throws Exception { File osfile = new File(file.getLocation().toOSString()); PropertiesConfiguration pluginPackageProperties = new PropertiesConfiguration(); pluginPackageProperties.load(osfile); pluginPackageProperties.setProperty(propertyName, propertiesValue); FileWriter output = new FileWriter(osfile); try {/*from ww w. j ava2 s. co m*/ pluginPackageProperties.save(output); } finally { output.close(); } file.refreshLocal(IResource.DEPTH_ZERO, new NullProgressMonitor()); }
From source file:com.linkedin.pinot.core.segment.index.converter.SegmentFormatConverterV1ToV2.java
@Override public void convert(File indexSegmentDir) throws Exception { SegmentMetadataImpl segmentMetadataImpl = new SegmentMetadataImpl(indexSegmentDir); SegmentDirectory segmentDirectory = SegmentDirectory.createFromLocalFS(indexSegmentDir, segmentMetadataImpl, ReadMode.mmap);//from w w w .ja va 2 s. c o m Set<String> columns = segmentMetadataImpl.getAllColumns(); SegmentDirectory.Writer segmentWriter = segmentDirectory.createWriter(); for (String column : columns) { ColumnMetadata columnMetadata = segmentMetadataImpl.getColumnMetadataFor(column); if (columnMetadata.isSorted()) { // no need to change sorted forward index continue; } PinotDataBuffer fwdIndexBuffer = segmentWriter.getIndexFor(column, ColumnIndexType.FORWARD_INDEX); if (columnMetadata.isSingleValue() && !columnMetadata.isSorted()) { // since we use dictionary to encode values, we wont have any negative values in forward // index boolean signed = false; SingleColumnSingleValueReader v1Reader = new com.linkedin.pinot.core.io.reader.impl.v1.FixedBitSingleValueReader( fwdIndexBuffer, segmentMetadataImpl.getTotalDocs(), columnMetadata.getBitsPerElement(), false); File convertedFwdIndexFile = new File(indexSegmentDir, column + V1Constants.Indexes.UN_SORTED_SV_FWD_IDX_FILE_EXTENTION + ".tmp"); SingleColumnSingleValueWriter v2Writer = new com.linkedin.pinot.core.io.writer.impl.v2.FixedBitSingleValueWriter( convertedFwdIndexFile, segmentMetadataImpl.getTotalDocs(), columnMetadata.getBitsPerElement()); for (int row = 0; row < segmentMetadataImpl.getTotalDocs(); row++) { int value = v1Reader.getInt(row); v2Writer.setInt(row, value); } v1Reader.close(); v2Writer.close(); File fwdIndexFileCopy = new File(indexSegmentDir, column + V1Constants.Indexes.UN_SORTED_SV_FWD_IDX_FILE_EXTENTION + ".orig"); segmentWriter.removeIndex(column, ColumnIndexType.FORWARD_INDEX); // FIXME PinotDataBuffer newIndexBuffer = segmentWriter.newIndexFor(column, ColumnIndexType.FORWARD_INDEX, (int) convertedFwdIndexFile.length()); newIndexBuffer.readFrom(convertedFwdIndexFile); convertedFwdIndexFile.delete(); } if (!columnMetadata.isSingleValue()) { // since we use dictionary to encode values, we wont have any negative values in forward // index boolean signed = false; SingleColumnMultiValueReader v1Reader = new com.linkedin.pinot.core.io.reader.impl.v1.FixedBitMultiValueReader( fwdIndexBuffer, segmentMetadataImpl.getTotalDocs(), columnMetadata.getTotalNumberOfEntries(), columnMetadata.getBitsPerElement(), signed); File convertedFwdIndexFile = new File(indexSegmentDir, column + V1Constants.Indexes.UN_SORTED_MV_FWD_IDX_FILE_EXTENTION + ".tmp"); SingleColumnMultiValueWriter v2Writer = new com.linkedin.pinot.core.io.writer.impl.v2.FixedBitMultiValueWriter( convertedFwdIndexFile, segmentMetadataImpl.getTotalDocs(), columnMetadata.getTotalNumberOfEntries(), columnMetadata.getBitsPerElement()); int[] values = new int[columnMetadata.getMaxNumberOfMultiValues()]; for (int row = 0; row < segmentMetadataImpl.getTotalDocs(); row++) { int length = v1Reader.getIntArray(row, values); int[] copy = new int[length]; System.arraycopy(values, 0, copy, 0, length); v2Writer.setIntArray(row, copy); } v1Reader.close(); v2Writer.close(); segmentWriter.removeIndex(column, ColumnIndexType.FORWARD_INDEX); PinotDataBuffer newIndexBuffer = segmentWriter.newIndexFor(column, ColumnIndexType.FORWARD_INDEX, (int) convertedFwdIndexFile.length()); newIndexBuffer.readFrom(convertedFwdIndexFile); convertedFwdIndexFile.delete(); } } File metadataFile = new File(indexSegmentDir, V1Constants.MetadataKeys.METADATA_FILE_NAME); File metadataFileCopy = new File(indexSegmentDir, V1Constants.MetadataKeys.METADATA_FILE_NAME + ".orig"); bis = new BufferedInputStream(new FileInputStream(metadataFile)); bos = new BufferedOutputStream(new FileOutputStream(metadataFileCopy)); IOUtils.copy(bis, bos); bis.close(); bos.close(); final PropertiesConfiguration properties = new PropertiesConfiguration(metadataFileCopy); // update the segment version properties.setProperty(V1Constants.MetadataKeys.Segment.SEGMENT_VERSION, SegmentVersion.v2.toString()); metadataFile.delete(); properties.save(metadataFile); }
From source file:com.zavakid.mushroom.impl.MetricsSystemImpl.java
@Override public synchronized String currentConfig() { PropertiesConfiguration saver = new PropertiesConfiguration(); StringWriter writer = new StringWriter(); saver.copy(config);/*from www .j ava 2 s. c om*/ try { saver.save(writer); } catch (Exception e) { throw new MetricsConfigException("Error stringify config", e); } return writer.toString(); }
From source file:it.geosolutions.opensdi2.configurations.dao.PropertiesDAO.java
@Override public void save(OSDIConfiguration newConfig) throws OSDIConfigurationDuplicatedIDException, OSDIConfigurationNotFoundException, OSDIConfigurationInternalErrorException { if (isThisConfigIsAlreadyPresent(newConfig.getScopeID(), newConfig.getInstanceID())) { throw new OSDIConfigurationDuplicatedIDException( "A configuration with scopeID '" + newConfig.getScopeID() + "' and instanceID '" + newConfig.getInstanceID() + "' is already present."); }/*from w w w . j a v a 2s .c o m*/ Object configAsParamsSet = configConverter.buildConfig(newConfig); PropertiesConfiguration propertiesConfig = (PropertiesConfiguration) configAsParamsSet; PropertiesDirFiltersFactory factory = new PropertiesDirFiltersFactory(); File[] moduleList = propertiesConfigDir .listFiles(factory.getFilter(FILTER_TYPE.MODULE, newConfig.getScopeID())); File instanceConfig = new File(moduleList[0], factory.INSTANCE_CONFIGNAME_PREFIX + newConfig.getInstanceID() + factory.INSTANCE_CONFIGNAME_EXTENSION); try { propertiesConfig.save(instanceConfig); } catch (ConfigurationException e) { throw new OSDIConfigurationInternalErrorException( "Error occurred while saving a new configuration, exception msg is: '" + e.getMessage() + "'"); } }
From source file:com.kylinolap.rest.service.AdminService.java
/** * Get Java Env info as string//from w w w .j a v a 2 s . com * * @return */ @PreAuthorize(Constant.ACCESS_HAS_ROLE_ADMIN) public String getEnv() { logger.debug("Get Kylin Runtime environment"); PropertiesConfiguration tempConfig = new PropertiesConfiguration(); // Add Java Env try { String content = ""; ByteArrayOutputStream baos = new ByteArrayOutputStream(); // env Map<String, String> env = System.getenv(); for (String envName : env.keySet()) { tempConfig.addProperty(envName, env.get(envName)); } // properties Properties properteis = System.getProperties(); for (Object propName : properteis.keySet()) { tempConfig.setProperty((String) propName, properteis.get(propName)); } // do save tempConfig.save(baos); content = baos.toString(); return content; } catch (ConfigurationException e) { logger.debug("Failed to get Kylin Runtime env", e); throw new InternalErrorException("Failed to get Kylin env Config", e); } }
From source file:com.liferay.ide.project.core.tests.ProjectCoreBase.java
private void persistAppServerProperties() throws FileNotFoundException, IOException, ConfigurationException { Properties initProps = new Properties(); initProps.put("app.server.type", "tomcat"); initProps.put("app.server.tomcat.dir", getLiferayRuntimeDir().toPortableString()); initProps.put("app.server.tomcat.deploy.dir", getLiferayRuntimeDir().append("webapps").toPortableString()); initProps.put("app.server.tomcat.lib.global.dir", getLiferayRuntimeDir().append("lib/ext").toPortableString()); initProps.put("app.server.parent.dir", getLiferayRuntimeDir().removeLastSegments(1).toPortableString()); initProps.put("app.server.tomcat.portal.dir", getLiferayRuntimeDir().append("webapps/ROOT").toPortableString()); IPath loc = getLiferayPluginsSdkDir(); String userName = System.getProperty("user.name"); //$NON-NLS-1$ File userBuildFile = loc.append("build." + userName + ".properties").toFile(); //$NON-NLS-1$ //$NON-NLS-2$ try (FileOutputStream fileOutput = new FileOutputStream(userBuildFile)) { if (userBuildFile.exists()) { PropertiesConfiguration propsConfig = new PropertiesConfiguration(userBuildFile); for (Object key : initProps.keySet()) { propsConfig.setProperty((String) key, initProps.get(key)); }/*from w ww .ja va2 s .c o m*/ propsConfig.setHeader(""); propsConfig.save(fileOutput); } else { Properties props = new Properties(); props.putAll(initProps); props.store(fileOutput, StringPool.EMPTY); } } }
From source file:com.francetelecom.clara.cloud.logicalmodel.LogicalConfigServiceUtils.java
public void dumpConfigContent(StructuredLogicalConfigServiceContent content, Writer writer) throws InvalidConfigServiceException { try {//from w ww . j ava 2 s. co m ValidatorUtil.validate(content); } catch (TechnicalException e) { throw new InvalidConfigServiceException("Invalid structured content:" + e, e); } PropertiesConfiguration propertiesConfiguration = new PropertiesConfiguration(); PropertiesConfigurationLayout layout = propertiesConfiguration.getLayout(); layout.setLineSeparator("\n"); String headerComment = content.getHeaderComment(); if (headerComment != null) { layout.setHeaderComment(headerComment); } for (ConfigEntry configEntry : content.configEntries) { String key = configEntry.getKey(); propertiesConfiguration.addProperty(key, configEntry.getValue()); String comment = configEntry.getComment(); layout.setSeparator(key, "="); if (comment != null) { layout.setComment(key, comment); } } try { propertiesConfiguration.save(writer); } catch (ConfigurationException e) { throw new InvalidConfigServiceException("Invalid structured content or output:" + e, e); } }
From source file:com.cloud.utils.crypt.EncryptionSecretKeyChanger.java
private boolean migrateProperties(File dbPropsFile, Properties dbProps, String newMSKey, String newDBKey) { System.out.println("Migrating db.properties.."); StandardPBEStringEncryptor msEncryptor = new StandardPBEStringEncryptor(); ;/*from w w w . java 2s . c om*/ 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; }
From source file:com.liferay.portal.deploy.hot.ExtHotDeployListener.java
protected void mergePortalProperties(String portalWebDir, ServletContext servletContext) throws Exception { URL pluginPropsURL = servletContext .getResource("WEB-INF/ext-web/docroot/WEB-INF/classes/portal-ext.properties"); if (pluginPropsURL == null) { if (_log.isDebugEnabled()) { _log.debug("Ext Plugin's portal-ext.properties not found"); }//from w w w . ja v a 2 s . c o m return; } if (_log.isDebugEnabled()) { _log.debug("Loading portal-ext.properties from " + pluginPropsURL); } PropertiesConfiguration pluginProps = new PropertiesConfiguration(pluginPropsURL); PropertiesConfiguration portalProps = new PropertiesConfiguration( this.getClass().getClassLoader().getResource("portal.properties")); File extPluginPropsFile = new File(portalWebDir + "WEB-INF/classes/portal-ext-plugin.properties"); PropertiesConfiguration extPluginPortalProps = new PropertiesConfiguration(); if (extPluginPropsFile.exists()) { extPluginPortalProps.load(extPluginPropsFile); } for (Iterator it = pluginProps.getKeys(); it.hasNext();) { String key = (String) it.next(); List value = pluginProps.getList(key); if (key.endsWith("+")) { key = key.substring(0, key.length() - 1); List newValue = new ArrayList(); if (extPluginPortalProps.containsKey(key)) { // already rewrited newValue.addAll(extPluginPortalProps.getList(key)); } else { newValue.addAll(portalProps.getList(key)); } newValue.addAll(value); extPluginPortalProps.setProperty(key, newValue); } else { extPluginPortalProps.setProperty(key, value); } } extPluginPortalProps.save(extPluginPropsFile); }