List of usage examples for java.util Properties store
public void store(OutputStream out, String comments) throws IOException
From source file:io.redlink.solrlib.embedded.EmbeddedCoreContainer.java
@Override @SuppressWarnings({ "squid:S3725", "squid:S3776" }) protected synchronized void init(ExecutorService executorService) throws IOException { Preconditions.checkState(Objects.isNull(coreContainer), "Already initialized!"); if (solrHome == null) { solrHome = Files.createTempDirectory("solr-home"); log.debug("No solr-home set, using temp directory {}", solrHome); deleteOnShutdown = true;/*from ww w . j ava 2 s . c om*/ } final Path absoluteSolrHome = this.solrHome.toAbsolutePath(); if (Files.isDirectory(absoluteSolrHome)) { log.trace("solr-home exists: {}", absoluteSolrHome); } else { Files.createDirectories(absoluteSolrHome); log.debug("Created solr-home: {}", absoluteSolrHome); } final Path lib = absoluteSolrHome.resolve("lib"); if (Files.isDirectory(lib)) { log.trace("lib-directory exists: {}", lib); } else { Files.createDirectories(lib); log.debug("Created solr-lib directory: {}", lib); } final Path solrXml = absoluteSolrHome.resolve("solr.xml"); if (!Files.exists(solrXml)) { log.info("no solr.xml found, creating new at {}", solrXml); try (PrintStream writer = new PrintStream(Files.newOutputStream(solrXml, StandardOpenOption.CREATE))) { writer.printf("<!-- Generated by %s on %tF %<tT -->%n", getClass().getSimpleName(), new Date()); writer.println("<solr>"); writer.printf(" <str name=\"%s\">%s</str>%n", "sharedLib", absoluteSolrHome.relativize(lib)); writer.println("</solr>"); } } else { log.trace("found solr.xml: {}", solrXml); } for (SolrCoreDescriptor coreDescriptor : coreDescriptors) { final String coreName = coreDescriptor.getCoreName(); if (availableCores.containsKey(coreName)) { log.warn("CoreName-Clash: {} already initialized. Skipping {}", coreName, coreDescriptor.getClass()); continue; } final Path coreDir = absoluteSolrHome.resolve(coreName); Files.createDirectories(coreDir); coreDescriptor.initCoreDirectory(coreDir, lib); final Properties coreProperties = new Properties(); final Path corePropertiesFile = coreDir.resolve("core.properties"); if (Files.exists(corePropertiesFile)) { try (InputStream inStream = Files.newInputStream(corePropertiesFile, StandardOpenOption.CREATE)) { coreProperties.load(inStream); } log.debug("core.properties for {} found, updating", coreName); } else { log.debug("Creating new core {} in {}", coreName, coreDir); } coreProperties.setProperty("name", coreName); try (OutputStream outputStream = Files.newOutputStream(corePropertiesFile)) { coreProperties.store(outputStream, null); } if (coreDescriptor.getNumShards() > 1 || coreDescriptor.getReplicationFactor() > 1) { log.warn("Deploying {} to EmbeddedCoreContainer, ignoring config of shards={},replication={}", coreName, coreDescriptor.getNumShards(), coreDescriptor.getReplicationFactor()); } availableCores.put(coreName, coreDescriptor); } log.info("Starting {} in solr-home '{}'", getClass().getSimpleName(), absoluteSolrHome); coreContainer = CoreContainer.createAndLoad(absoluteSolrHome, solrXml); availableCores.values().forEach(coreDescriptor -> { final String coreName = coreDescriptor.getCoreName(); try (SolrClient solrClient = createSolrClient(coreName)) { final NamedList<Object> coreStatus = CoreAdminRequest.getStatus(coreName, solrClient) .getCoreStatus(coreName); final NamedList<Object> indexStatus = coreStatus == null ? null : (NamedList<Object>) coreStatus.get("index"); final Object lastModified = indexStatus == null ? null : indexStatus.get("lastModified"); // lastModified is null if there was never a update scheduleCoreInit(executorService, coreDescriptor, lastModified == null); } catch (SolrServerException | IOException e) { if (log.isDebugEnabled()) { log.error("Error initializing core {}", coreName, e); } //noinspection ThrowableResultOfMethodCallIgnored coreInitExceptions.put(coreName, e); } }); }
From source file:com.blackducksoftware.tools.commonframework.core.config.ConfigurationFileTest.java
@Test public void testSpecialCharsInNewEncryptedEncodedPassword() throws Exception { final File configFile = File.createTempFile("soleng_framework_core_config_ConfigurationFileTest", "testConfigFileRoundTrip"); filesToDelete.add(configFile);/*from www .j a v a 2 s . c om*/ configFile.deleteOnExit(); final Properties props = new Properties(); final String psw = "P@_H~o$t&h4DSSO%.-J'_'W_ZY2X<QHxtz&Cg'+.g7.s49;8K2MFK~2Ar7]xp/g"; System.out.println("psw: " + psw); props.setProperty("protex.server.name", "servername"); props.setProperty("protex.user.name", "username"); props.setProperty("protex.password", psw); // Write the config file with plain txt password configFile.delete(); props.store(new FileOutputStream(configFile), "test"); // First use will encrypt password ConfigurationManager config = new TestProtexConfigurationManager(configFile.getAbsolutePath()); assertEquals(psw, config.getServerBean(APPLICATION.PROTEX).getPassword()); // Second use will read encrypted password config = new TestProtexConfigurationManager(configFile.getAbsolutePath()); assertEquals(psw, config.getServerBean(APPLICATION.PROTEX).getPassword()); }
From source file:net.pandoragames.far.ui.FARConfigurationFactory.java
/** * Saves the configuration object and returns true if the operation was successfull. * @param config to be saved.//from w ww .j a v a2 s. c o m * @return true if ok */ public boolean saveConfig(FARConfig config) { boolean success = true; // // store the properties // Properties properties = new Properties(); File preferences = new File(getConfigDir(), preferencesFileName); success = findOrCreate(preferences); // write it if (preferences.exists()) { OutputStream outputStream = null; config.writeToProperties(properties); try { outputStream = new BufferedOutputStream(new FileOutputStream(preferences)); writeCommentHeader(outputStream, "FAR - Find And Replace"); properties.store(outputStream, null); } catch (IOException iox) { logger.error("IOException saving preferences: " + iox.getMessage()); success = false; } finally { if (outputStream != null) try { outputStream.close(); } catch (IOException iox) { logger.warn("IOException closing stream: " + iox.getMessage()); } } } // // store the pattern // File storedList = new File(getConfigDir(), fileNamePatternList); success = success & findOrCreate(storedList); if (storedList.exists()) { FileNamePatternParser parser = new FileNamePatternParser(storedList); try { parser.storeList(config.getFileNamePatternList(), "FAR - Find And Replace\nFilename Pattern"); } catch (IOException iox) { logger.error("IOException saving file name pattern: " + iox.getMessage()); success = false; } } // // store the character set // File characterList = new File(getConfigDir(), charactersetList); success = success & findOrCreate(characterList); if (characterList.exists()) { CharacterSetListParser parser = new CharacterSetListParser(characterList); try { if (config.getCharsetList().contains(config.getDefaultCharset()) && (!config.getDefaultCharset().equals(config.getCharsetList().get(0)))) { config.getCharsetList().remove(config.getDefaultCharset()); config.getCharsetList().add(0, config.getDefaultCharset()); } parser.storeList(config.getCharsetList(), "FAR - Find And Replace\nCharacter Sets"); } catch (IOException iox) { logger.error("IOException storing list of character sets: " + iox.getMessage()); success = false; } } // // store the mime types // MimeConfParser mimeParser = new MimeConfParser(); File mimeTypeConf = new File(getConfigDir(), mimeTypesList); FileOutputStream outstream = null; try { outstream = new FileOutputStream(mimeTypeConf); mimeParser.format(outstream); } catch (IOException iox) { logger.error("IOException storing list of mime types: " + iox.getMessage()); success = false; } finally { if (outstream != null) try { outstream.close(); } catch (IOException x) { logger.error("brx"); } } return success; }
From source file:net.doubledoordev.backend.server.Server.java
private void saveProperties() throws IOException { if (!propertiesFile.exists()) propertiesFile.createNewFile();/*from ww w.j av a2s. c om*/ FileOutputStream outputStream = new FileOutputStream(propertiesFile); Properties properties = getProperties(); properties.store(outputStream, "Modified by the backend"); propertiesFileLastModified = propertiesFile.lastModified(); outputStream.close(); }
From source file:eu.optimis.vc.api.IsoCreator.IsoImageCreation.java
private void storeEndpoints() { File endPointDirectory = new File(isoDataDirectory + File.separator + "endpoints"); endPointDirectory.mkdirs();/*from www . j a v a 2s .c om*/ if (virtualMachine.getEndPoints().size() != 0) { for (EndPoint endPoint : virtualMachine.getEndPoints().values()) { String name = endPoint.getName(); String uri = endPoint.getUri(); // Create the end point with the given name File endPointFile = new File(endPointDirectory + File.separator + name + ".properties"); try { LOGGER.debug(ATTEMPTING_TO_CREATE_FILE + endPointFile.getPath()); endPointFile.createNewFile(); LOGGER.debug(CREATED_FILE + endPointFile.getPath()); } catch (IOException e) { LOGGER.error("Failed to create endpoint file with name: " + name + ".properties", e); } Properties props = new Properties(); props.setProperty(name, uri); try { FileOutputStream fileOutputStream = new FileOutputStream(endPointFile); props.store(fileOutputStream, "VMC properties file for service endpoints:"); fileOutputStream.close(); LOGGER.debug("Writing endpoint complete!"); } catch (FileNotFoundException e) { LOGGER.error(FILE_NOT_FOUND_EXCEPTION + e); } catch (IOException e) { LOGGER.error(IO_EXCEPTION + e); } } } else { LOGGER.warn("No end points to write!"); } }
From source file:energy.usef.environment.tool.GenerateDomains.java
private void generateTimeServerFolder() throws IOException, ParserConfigurationException, SAXException, TransformerException { Map<String, Object> timeServerSettings = environmentConfig.getTimeServerConfig(); Map<String, String> globalConfig = environmentConfig.getGlobalConfig(); if (!globalConfig.containsKey(SERVICE_NODE_NAME)) { LOGGER.error("No " + SERVICE_NODE_NAME + " has been defined for the timeserver to run on, please add it to the yaml file!"); System.exit(1);//from ww w .j a v a 2s . c o m } String timeServerNode = globalConfig.get(SERVICE_NODE_NAME).toString(); String timeServerFolder = ToolConfig.getUsefEnvironmentDomainConfigurationFolder(timeServerNode) + File.separator + USEF_TIME; LOGGER.info("Generating domain folder {}.", timeServerFolder); if (FileUtil.isFolderExists(timeServerFolder)) { LOGGER.error( "The folder {} does already exist and will NOT be recreated. Please, run the cleanup-script first!", timeServerFolder); System.exit(1); } else { FileUtil.createFolders(timeServerFolder); generateConfigProperties(timeServerFolder); // copy usef war String fromFilename = ToolConfig.getUsefEnvironmentBuildTimeWarFolder() + File.separator + ToolConfig.TARGET_TIME_WAR; String toWarFilename = ToolConfig.getUsefEnvironmentDomainDeploymentFolder(timeServerNode) + File.separator + ToolConfig.TARGET_TIME_WAR; FileUtil.copyFile(fromFilename, toWarFilename); String configContent = WarUtil.retrieveContentFromWar(toWarFilename, WarUtil.USEF_TIME_CONFIG_PATH); Properties properties = new Properties(); InputStream inStream = new ByteArrayInputStream(configContent.getBytes(FileUtil.DEFAULT_CHARSET)); properties.load(inStream); for (Entry<String, Object> entry : timeServerSettings.entrySet()) { properties.setProperty(entry.getKey(), entry.getValue().toString()); } ByteArrayOutputStream outStream = new ByteArrayOutputStream(); properties.store(outStream, "USEF Time Server Properties"); String newconfigContent = new String(outStream.toByteArray(), FileUtil.DEFAULT_CHARSET); WarUtil.replaceFileInWar(toWarFilename, WarUtil.USEF_TIME_CONFIG, WarUtil.USEF_TIME_CONFIG_PATH, newconfigContent); } }
From source file:com.blackducksoftware.tools.commonframework.core.config.ConfigurationFileTest.java
@Test public void testConfigFileRoundTrip() throws Exception { final File configFile = File.createTempFile("soleng_framework_core_config_ConfigurationFileTest", "testConfigFileRoundTrip"); filesToDelete.add(configFile);/*from w w w. ja v a 2 s . c o m*/ configFile.deleteOnExit(); for (int i = 0; i < 1000; i++) { final Properties props = new Properties(); final String psw = Ascii85EncoderTest.generateRandomPassword(64); System.out.println("psw: " + psw); props.setProperty("protex.server.name", "servername"); props.setProperty("protex.user.name", "username"); props.setProperty("protex.password", psw); // Write the config file with plain txt password configFile.delete(); props.store(new FileOutputStream(configFile), "test"); // First use will encrypt password ConfigurationManager config = new TestProtexConfigurationManager(configFile.getAbsolutePath()); assertEquals(psw, config.getServerBean(APPLICATION.PROTEX).getPassword()); // Second use will read encrypted password config = new TestProtexConfigurationManager(configFile.getAbsolutePath()); assertEquals(psw, config.getServerBean(APPLICATION.PROTEX).getPassword()); System.out.println("=================="); } }
From source file:au.com.jwatmuff.genericp2p.rmi.RMIPeerManager.java
/** * This method is to be called remotely by a peer to determine the ID of the * local client. This ID is unique on an operating system user basis, using * a mechanism such as a user registry (under Windows) or a user * configuration file (under Linux) to store the ID. * /* w w w .j a va 2 s. co m*/ * The ID is a random 128-bit Universally Unique ID, guaranteed to be * globally unique to a very high level of certainty. * * @return The ID of the local client */ @Override public UUID getUUID() { if (uuid != null) { return uuid; } Properties props = new Properties(); try { props.load(new FileInputStream(idFile)); uuid = UUID.fromString(props.getProperty("uuid")); } catch (IOException e) { try { uuid = UUID.randomUUID(); props.setProperty("uuid", uuid.toString()); props.store(new FileOutputStream(idFile), null); } catch (IOException ex) { log.error("Unable to record peer UUID to file", ex); } } return uuid; }
From source file:com.migratebird.integrationtest.MigrateBirdIntegrationTest.java
private File writePropertiesFile(String propertyName, String propertyValue) throws IOException { File propertiesFile = File.createTempFile("scriptParams", "properties"); Properties properties = new Properties(); properties.put(propertyName, propertyValue); properties.store(new FileWriter(propertiesFile), null); return propertiesFile; }
From source file:com.blackducksoftware.tools.commonframework.core.config.ConfigurationFileTest.java
@Test public void testCloseSquareBracketInEncryptedEncodedPassword() throws Exception { final File configFile = File.createTempFile("soleng_framework_core_config_ConfigurationFileTest", "testConfigFileRoundTrip"); filesToDelete.add(configFile);//from w w w . j a v a 2s .co m configFile.deleteOnExit(); final Properties props = new Properties(); // This password has = once encrypted/encoded final String psw = "].}7]\"9-4>m4SLootB^Kk?E@~kk7^e83"; System.out.println("psw: " + psw); props.setProperty("protex.server.name", "servername"); props.setProperty("protex.user.name", "username"); props.setProperty("protex.password", psw); // Write the config file with plain txt password configFile.delete(); props.store(new FileOutputStream(configFile), "test"); // First use will encrypt password ConfigurationManager config = new TestProtexConfigurationManager(configFile.getAbsolutePath()); assertEquals(psw, config.getServerBean(APPLICATION.PROTEX).getPassword()); // Second use will read encrypted password config = new TestProtexConfigurationManager(configFile.getAbsolutePath()); assertEquals(psw, config.getServerBean(APPLICATION.PROTEX).getPassword()); }