List of usage examples for java.util Properties store
public void store(OutputStream out, String comments) throws IOException
From source file:com.github.harti2006.neo4j.StartNeo4jServerMojo.java
private void configureNeo4jServer() throws MojoExecutionException { final Path serverLocation = getServerLocation(); final Path serverPropertiesPath = serverLocation.resolve(Paths.get("conf", "neo4j-server.properties")); final Properties serverProperties = PropertyUtils.loadProperties(serverPropertiesPath.toFile()); serverProperties.setProperty("org.neo4j.server.webserver.port", port); serverProperties.setProperty("org.neo4j.server.webserver.https.enabled", "false"); try {//from www .j a v a 2 s .c o m serverProperties.store(newBufferedWriter(serverPropertiesPath, TRUNCATE_EXISTING, WRITE), "Generated by Neo4j Server Maven Plugin"); } catch (IOException e) { throw new MojoExecutionException("Could not configure Neo4j server", e); } }
From source file:com.amazon.aws.samplecode.travellog.util.DataExtractor.java
public void run() { try {//from ww w . j a v a 2 s .com //Create temporary directory File tmpDir = File.createTempFile("travellog", ""); tmpDir.delete(); //Wipe out temporary file to replace with a directory tmpDir.mkdirs(); logger.log(Level.INFO, "Extract temp dir: " + tmpDir); //Store journal to props file Journal journal = dao.getJournal(); Properties journalProps = buildProps(journal); File journalFile = new File(tmpDir, "journal"); journalProps.store(new FileOutputStream(journalFile), ""); //Iterate through entries and grab related photos List<Entry> entries = dao.getEntries(journal); int entryIndex = 1; int imageFileIndex = 1; for (Entry entry : entries) { Properties entryProps = buildProps(entry); File entryFile = new File(tmpDir, "entry." + (entryIndex++)); entryProps.store(new FileOutputStream(entryFile), ""); List<Photo> photos = dao.getPhotos(entry); int photoIndex = 1; for (Photo photo : photos) { Properties photoProps = buildProps(photo); InputStream photoData = S3PhotoUtil.loadOriginalPhoto(photo); String imageFileName = "imgdata." + (imageFileIndex++); File imageFile = new File(tmpDir, imageFileName); FileOutputStream outputStream = new FileOutputStream(imageFile); IOUtils.copy(photoData, outputStream); photoProps.setProperty("file", imageFileName); outputStream.close(); photoData.close(); File photoFile = new File(tmpDir, "photo." + (entryIndex - 1) + "." + (photoIndex++)); photoProps.store(new FileOutputStream(photoFile), ""); } List<Comment> comments = dao.getComments(entry); int commentIndex = 1; for (Comment comment : comments) { Properties commentProps = buildProps(comment); File commentFile = new File(tmpDir, "comment." + (entryIndex - 1) + "." + commentIndex++); commentProps.store(new FileOutputStream(commentFile), ""); } } //Bundle up the folder as a zip final File zipOut; //If we have an output path store locally if (outputPath != null) { zipOut = new File(outputPath); } else { //storing to S3 zipOut = File.createTempFile("export", ".zip"); } zipOut.getParentFile().mkdirs(); //make sure directory structure is in place ZipArchiveOutputStream zaos = new ZipArchiveOutputStream(zipOut); //Create the zip file File[] files = tmpDir.listFiles(); for (File file : files) { ZipArchiveEntry archiveEntry = new ZipArchiveEntry(file.getName()); byte[] fileData = FileUtils.readFileToByteArray(file); archiveEntry.setSize(fileData.length); zaos.putArchiveEntry(archiveEntry); zaos.write(fileData); zaos.flush(); zaos.closeArchiveEntry(); } zaos.close(); //If outputpath if (outputPath == null) { TravelLogStorageObject obj = new TravelLogStorageObject(); obj.setBucketName(bucketName); obj.setStoragePath(storagePath); obj.setData(FileUtils.readFileToByteArray(zipOut)); obj.setMimeType("application/zip"); S3StorageManager mgr = new S3StorageManager(); mgr.store(obj, false, null); //Store with full redundancy and default permissions } } catch (Exception e) { logger.log(Level.SEVERE, e.getMessage(), e); } }
From source file:com.htmlhifive.tools.codeassist.ui.config.CodeAssistConfig.java
/** * ???./*from ww w. j a v a 2 s . c o m*/ * * @return ???????? */ public boolean saveConfig() { Properties properties = new Properties(); properties.setProperty(KEY_OPTION_PATH, configBean.getOptionFilePath()); ByteArrayOutputStream output = new ByteArrayOutputStream(); InputStream input = null; try { properties.store(output, ""); output.flush(); input = new ByteArrayInputStream(output.toByteArray()); configProp.refreshLocal(IResource.DEPTH_ZERO, null); if (configProp.exists()) { configProp.setContents(input, false, false, null); } else { configProp.create(input, false, null); } return true; } catch (CoreException e) { logger.log(UIMessages.UIEM0002, e); ErrorDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), UIMessages.UIDT0002.getText(), UIMessages.UIEM0002.getText(), e.getStatus()); } catch (IOException e) { logger.log(UIMessages.UIEM0002, e); ErrorDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), UIMessages.UIDT0002.getText(), UIMessages.UIEM0002.getText(), new Status(IStatus.ERROR, H5CodeAssistUIPlugin.PLUGIN_ID, e.getMessage())); } finally { IOUtils.closeQuietly(input); IOUtils.closeQuietly(output); } return false; }
From source file:com.panet.imeta.trans.steps.propertyoutput.PropertyOutput.java
private void saveProperties(Properties p, String fileName) { OutputStream propsFile = null; try {/*from ww w . ja v a2 s . co m*/ propsFile = new FileOutputStream(fileName); p.store(propsFile, environmentSubstitute(meta.getComment())); propsFile.close(); if (meta.AddToResult()) { // Add this to the result file names... ResultFile resultFile = new ResultFile(ResultFile.FILE_TYPE_GENERAL, KettleVFS.getFileObject(fileName), getTransMeta().getName(), getStepname()); resultFile.setComment(Messages.getString("PropertyOutput.Log.FileAddedResult")); addResultFile(resultFile); } } catch (IOException ioe) { System.out.println("I/O Exception."); ioe.printStackTrace(); System.exit(0); } finally { if (propsFile != null) { try { propsFile.close(); propsFile = null; } catch (Exception e) { } } } }
From source file:br.com.elotech.sits.config.form.ConfigForm.java
private void save() { Properties config = new Properties(loadConfigFile()); config.setProperty("ISS.serviceType", "elotech"); try {//w w w . j av a2 s. c o m saveFields(config); saveKeyAlias(config); config.store(new FileOutputStream(new File(CONFIG_FILE)), "Arquivo gerado pelo configurador"); close(); } catch (Exception e) { LogFactory.getLog(getClass()).error(e.getLocalizedMessage(), e); JOptionPane.showMessageDialog(getFrame(), e.getLocalizedMessage(), "Erro durante gravao", JOptionPane.CLOSED_OPTION + JOptionPane.ERROR_MESSAGE); } }
From source file:com.enonic.cms.core.boot.ConfigBuilderTest.java
private void setupHomeProperties() throws Exception { Properties props = new Properties(); props.setProperty("home.param", "value"); props.setProperty("override", "home"); File file = new File(this.homeDir, "config/cms.properties"); file.getParentFile().mkdirs();/* w w w . j ava 2 s . c om*/ FileOutputStream out = new FileOutputStream(file); props.store(out, ""); out.close(); }
From source file:com.redhat.rcm.nexus.security.NxSecConfiguration.java
public void save() throws ConfigurationException { File configFile = new File(appConfiguration.getConfigurationDirectory(), NX_SEC_CONFIG_FILE); FileOutputStream fos = null;// w w w . j a v a 2 s. c o m try { Properties props = new Properties(); props.setProperty(KEY_AUTOCREATE_ENABLED, Boolean.toString(autoCreateEnabled)); props.setProperty(KEY_AUTOCREATE_EMAIL_DOMAIN, autoCreateEmailDomain); fos = new FileOutputStream(configFile); props.store(fos, "Saved on: " + new Date()); } catch (IOException e) { throw new ConfigurationException("Cannot write " + configFile + ". Reason: " + e.getMessage(), e); } finally { closeQuietly(fos); } }
From source file:ezbake.helpers.cdh.Cdh2EzProperties.java
@Override public void run() { RootResourceV3 apiRoot;/* w ww . ja va2s. c om*/ if (!tls) { apiRoot = new ClouderaManagerClientBuilder().withHost(host).withUsernamePassword(username, password) .build().getRootV3(); } else { apiRoot = new ClouderaManagerClientBuilder().withHost(host).withUsernamePassword(username, password) .withPort(7183).enableTLS().disableTlsCertValidation().disableTlsCnValidation().build() .getRootV3(); } ClustersResourceV3 clusterResource = apiRoot.getClustersResource(); if (Strings.isNullOrEmpty(clusterName)) { ApiClusterList clusters = apiRoot.getClustersResource().readClusters(DataView.SUMMARY); List<ApiCluster> clusterList = clusters.getClusters(); if (clusterList == null || clusterList.isEmpty()) { final CmdLineParser cmdLineParser = new CmdLineParser(this); cmdLineParser.printUsage(System.err); System.exit(-1); } clusterName = clusterList.get(0).getName(); } if (verbose) System.err.println("Using cluster '" + clusterName + "'."); ServicesResourceV3 serviceResource = clusterResource.getServicesResource(clusterName); InputStreamDataSource configStream = serviceResource.getClientConfig("HDFS"); try { Configuration configuration = getConfiguration(configStream); Properties properties = new Properties(); for (Map.Entry<String, String> prop : configuration) { properties.setProperty(prop.getKey(), prop.getValue()); } if (Strings.isNullOrEmpty(output) || output.equals("-")) { properties.store(System.out, getFileComment()); } else { try (OutputStream outputStream = new FileOutputStream(output, false)) { properties.store(outputStream, getFileComment()); } } } catch (IOException e) { throw new RuntimeException(e); } }
From source file:com.impetus.ankush.agent.AgentConf.java
/** * Save the specified properties values in given file. * /*from w ww . j a va2s. c om*/ * @param properties * Properties * @param fileName * String * @throws IOException * * @throws FileNotFoundException */ public void save(Properties properties, String fileName) throws IOException { OutputStream outputStream = new FileOutputStream(fileName); properties.store(outputStream, "Updated at" + System.currentTimeMillis()); outputStream.close(); }
From source file:com.migratebird.script.repository.impl.ArchiveScriptLocation.java
/** * @param properties A properties map// w w w . j a v a 2s . co m * @return The given properties as a reader to a properties file * @throws IOException if a problem occurs opening the reader */ protected Reader getPropertiesAsFile(Properties properties) throws IOException { Writer propertiesFileWriter = new StringWriter(); properties.store(new WriterOutputStream(propertiesFileWriter), null); return new StringReader(propertiesFileWriter.toString()); }