List of usage examples for java.util Properties store
public void store(OutputStream out, String comments) throws IOException
From source file:io.sledge.core.impl.installer.SledgePackageConfigurer.java
@Override public Properties mergeProperties(String envFileContent, Properties propsForMerge) { Properties mergedProps = new Properties(); try {/*from ww w. ja v a2s . com*/ // Support internal property references for application package provided properties Properties origProps = new Properties(); origProps.load(new StringReader(envFileContent)); String configuredEnvironmentFileContent = StrSubstitutor.replace(envFileContent, origProps); mergedProps.load(new StringReader(configuredEnvironmentFileContent)); // Support internal property references for overwrite properties StringWriter propsForMergeWriter = new StringWriter(); propsForMerge.store(propsForMergeWriter, ""); String propsForMergeAsString = propsForMergeWriter.getBuffer().toString(); String configuredPropsForMerge = StrSubstitutor.replace(propsForMergeAsString, propsForMerge); Properties reconfiguredPropsForMerge = new Properties(); reconfiguredPropsForMerge.load(new StringReader(configuredPropsForMerge)); mergedProps.putAll(reconfiguredPropsForMerge); } catch (IOException e) { throw new InstallationException("Could not load environment properties.", e); } return mergedProps; }
From source file:gov.guilin.controller.admin.SettingController.java
/** * /*from w ww . ja v a2 s . c o m*/ */ @RequestMapping(value = "/update", method = RequestMethod.POST) public String update(Setting setting, MultipartFile watermarkImageFile, RedirectAttributes redirectAttributes) { if (!isValid(setting)) { return ERROR_VIEW; } if (setting.getUsernameMinLength() > setting.getUsernameMaxLength() || setting.getPasswordMinLength() > setting.getPasswordMinLength()) { return ERROR_VIEW; } Setting srcSetting = SettingUtils.get(); if (StringUtils.isEmpty(setting.getSmtpPassword())) { setting.setSmtpPassword(srcSetting.getSmtpPassword()); } if (watermarkImageFile != null && !watermarkImageFile.isEmpty()) { if (!fileService.isValid(FileType.image, watermarkImageFile)) { addFlashMessage(redirectAttributes, Message.error("admin.upload.invalid")); return "redirect:edit.jhtml"; } String watermarkImage = fileService.uploadLocal(FileType.image, watermarkImageFile); setting.setWatermarkImage(watermarkImage); } else { setting.setWatermarkImage(srcSetting.getWatermarkImage()); } setting.setCnzzSiteId(srcSetting.getCnzzSiteId()); setting.setCnzzPassword(srcSetting.getCnzzPassword()); SettingUtils.set(setting); cacheService.clear(); staticService.buildIndex(); staticService.buildOther(); OutputStream outputStream = null; try { org.springframework.core.io.Resource resource = new ClassPathResource(CommonAttributes.PROPERTIES_PATH); Properties properties = PropertiesLoaderUtils.loadProperties(resource); String templateUpdateDelay = properties.getProperty("template.update_delay"); String messageCacheSeconds = properties.getProperty("message.cache_seconds"); if (setting.getIsDevelopmentEnabled()) { if (!templateUpdateDelay.equals("0") || !messageCacheSeconds.equals("0")) { outputStream = new FileOutputStream(resource.getFile()); properties.setProperty("template.update_delay", "0"); properties.setProperty("message.cache_seconds", "0"); properties.store(outputStream, "PROPERTIES"); } } else { if (templateUpdateDelay.equals("0") || messageCacheSeconds.equals("0")) { outputStream = new FileOutputStream(resource.getFile()); properties.setProperty("template.update_delay", "3600"); properties.setProperty("message.cache_seconds", "3600"); properties.store(outputStream, "PROPERTIES"); } } } catch (Exception e) { e.printStackTrace(); } finally { IOUtils.closeQuietly(outputStream); } addFlashMessage(redirectAttributes, SUCCESS_MESSAGE); return "redirect:edit.jhtml"; }
From source file:net.groupbuy.controller.admin.SettingController.java
/** * /*from w w w .j a va 2 s . c o m*/ */ @RequestMapping(value = "/update", method = RequestMethod.POST) public String update(Setting setting, MultipartFile watermarkImageFile, RedirectAttributes redirectAttributes) { if (!isValid(setting)) { return ERROR_VIEW; } if (setting.getUsernameMinLength() > setting.getUsernameMaxLength() || setting.getPasswordMinLength() > setting.getPasswordMinLength()) { return ERROR_VIEW; } Setting srcSetting = SettingUtils.get(); if (StringUtils.isEmpty(setting.getSmtpPassword())) { setting.setSmtpPassword(srcSetting.getSmtpPassword()); } if (watermarkImageFile != null && !watermarkImageFile.isEmpty()) { if (!fileService.isValid(FileType.image, watermarkImageFile)) { addFlashMessage(redirectAttributes, Message.error("admin.upload.invalid")); return "redirect:edit.jhtml"; } String watermarkImage = fileService.uploadLocal(FileType.image, watermarkImageFile); setting.setWatermarkImage(watermarkImage); } else { setting.setWatermarkImage(srcSetting.getWatermarkImage()); } setting.setCnzzSiteId(srcSetting.getCnzzSiteId()); setting.setCnzzPassword(srcSetting.getCnzzPassword()); SettingUtils.set(setting); cacheService.clear(); staticService.buildIndex(); staticService.buildOther(); OutputStream outputStream = null; try { org.springframework.core.io.Resource resource = new ClassPathResource( CommonAttributes.SHOPXX_PROPERTIES_PATH); Properties properties = PropertiesLoaderUtils.loadProperties(resource); String templateUpdateDelay = properties.getProperty("template.update_delay"); String messageCacheSeconds = properties.getProperty("message.cache_seconds"); if (setting.getIsDevelopmentEnabled()) { if (!templateUpdateDelay.equals("0") || !messageCacheSeconds.equals("0")) { outputStream = new FileOutputStream(resource.getFile()); properties.setProperty("template.update_delay", "0"); properties.setProperty("message.cache_seconds", "0"); properties.store(outputStream, "SHOP++ PROPERTIES"); } } else { if (templateUpdateDelay.equals("0") || messageCacheSeconds.equals("0")) { outputStream = new FileOutputStream(resource.getFile()); properties.setProperty("template.update_delay", "3600"); properties.setProperty("message.cache_seconds", "3600"); properties.store(outputStream, "SHOP++ PROPERTIES"); } } } catch (Exception e) { e.printStackTrace(); } finally { IOUtils.closeQuietly(outputStream); } addFlashMessage(redirectAttributes, SUCCESS_MESSAGE); return "redirect:edit.jhtml"; }
From source file:com.redhat.rcm.version.CliTest.java
@Test public void modify_BOMofBOMs() throws Exception { System.out.println("BOM-of-BOMS test (normalize to BOM usage)..."); final File srcRepo = getResourceFile("bom-of-boms"); copyDirectory(srcRepo, repo);/*from ww w.jav a2 s .c o m*/ final File pom = new File(repo, "project/pom.xml"); final File bom = new File(repo, "bom.xml"); final File remoteRepo = new File(repo, "repo"); final Properties props = new Properties(); props.setProperty(Cli.REMOTE_REPOSITORIES_PROPERTY, remoteRepo.toURI().normalize().toURL().toExternalForm()); props.setProperty(Cli.BOMS_LIST_PROPERTY, bom.getAbsolutePath()); final File config = new File(repo, "vman.properties"); FileOutputStream out = null; try { out = new FileOutputStream(config); props.store(out, "bom-of-boms test"); } finally { closeQuietly(out); } final String[] args = { "-Z", "-C", config.getPath(), pom.getPath() }; Cli.main(args); assertExitValue(); // FIXME // assertPOMsNormalizedToBOMs( Collections.singleton( pom ), Collections.singleton( bom ), session, fixture ); System.out.println("\n\n"); }
From source file:immf.StatusManager.java
public synchronized void save() throws IOException { Properties prop = new Properties(); for (Cookie cookie : this.cookies) { prop.setProperty("cookie_" + cookie.getName(), cookie.getValue() + ";path=" + cookie.getPath() + ";domain=" + cookie.getDomain()); }// ww w .jav a 2 s .c om if (this.lastMailId != null) { prop.setProperty("lastmailid", this.lastMailId); } if (this.pushCredentials != null && this.pushCredentials.length() > 0) { prop.setProperty("push_credentials", this.pushCredentials); } if (this.needConnect != null) { prop.setProperty("needconnect", this.needConnect); } FileOutputStream fos = null; try { fos = new FileOutputStream(this.f); prop.store(fos, "IMMF cookie info."); } finally { Util.safeclose(fos); } }
From source file:com.grantingersoll.intell.clustering.KMeansClusteringEngine.java
private void writeJobDetails(ClusterJob clusterJob) throws IOException { File nowFile = new File(clusterBaseDir, "lastJob"); Properties props = new Properties(); props.put("jobDir", clusterJob.jobDir); props.put("k", clusterJob.k); props.put("clustersIn", clusterJob.clustersIn); props.put("output", clusterJob.output); props.put("input", clusterJob.input); props.put("dictionary", clusterJob.dictionary); FileWriter fWriter = new FileWriter(nowFile); props.store(fWriter, "lastJob"); fWriter.close();//from ww w . j a va 2 s. co m }
From source file:com.vimeo.VimeoUploadClient.java
public VimeoUploadClient(String apiKey, String secret) throws IOException, APIException { saveToken = false; // no save token verbose = true; // be verbose checkStatusOnly = false; // we want upload this.apiKey = apiKey; this.secret = secret; /**// ww w . j a v a2 s . c om * read .vimeo-uploader */ FileInputStream in1 = null; Properties properties = null; try { File f = new File(System.getProperty("user.home"), VimeoUploadClient.CONFIG_FILE); properties = new Properties(); if (f.createNewFile()) { properties.put("apiKey", apiKey); properties.put("secret", secret); properties.store(new FileOutputStream(f), "vimeo-uploader configuration file"); } in1 = new FileInputStream(f); properties.load(in1); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { in1.close(); } try { service = new ServiceBuilder().provider(VimeoApi.class).apiKey(properties.getProperty("apiKey")) .apiSecret(properties.getProperty("secret")).build(); } catch (Exception e) { System.out.println(e.getMessage() + "\nCheck Your configuration file (" + CONFIG_FILE + ")"); return; } /** * try read saved token */ accessToken = readToken(); if (accessToken == null) { if (verbose) System.out.println("Fetching the Request Token..."); Token token = service.getRequestToken(); System.out.println("Got the Request Token!"); System.out.println(); if (verbose) System.out.println("Fetching the Authorization URL..."); String authURL = service.getAuthorizationUrl(token); if (verbose) System.out.println("Got the Authorization URL!"); System.out.println("Now go and authorize Scribe here:"); System.out.println(authURL + "&permission=write"); System.out.println("And paste the authorization code here"); System.out.print(">>"); // TODO: SCRIBE AUTHORIZATION GETTED THE FIRST TIME Verifier verifier = new Verifier("land-5zbo4"); System.out.println(); // Trade the Request Token and Verfier for the Access Token if (verbose) System.out.println("Trading the Request Token for an Access Token..."); accessToken = service.getAccessToken(token, verifier); if (verbose) System.out.println("Got the Access Token!"); if (saveToken) { saveToken(accessToken); } if (verbose) { System.out.println("(if your curious it looks like this [token, secret]: " + accessToken + " )"); System.out.println(); } } // get logged username ResponseWrapper response = call("vimeo.test.login", null); String username = (((Node) path(response.getResponse().getBody(), "//username", XPathConstants.NODE)) .getTextContent()); System.out.printf("%-30S: %s\n", "Logged", username); // TODO: Get User name from Vimeo: xstain1981 -> user14301672 // get free storage space in bytes response = call("vimeo.videos.upload.getQuota", null); String free = ((Node) path(response.getResponse().getBody(), "//upload_space", XPathConstants.NODE)) .getAttributes().getNamedItem("free").getNodeValue(); System.out.printf("%-30S: %s MB\n", "Free Storage Space", Double.parseDouble(free) / 1024 / 1024); // TODO: Get free storage (new Vimeo Account has 500.MB (January 2013)) }
From source file:com.dp2345.controller.admin.SettingController.java
/** * /* ww w . ja va 2s. c om*/ */ @RequestMapping(value = "/update", method = RequestMethod.POST) public String update(Setting setting, MultipartFile watermarkImageFile, RedirectAttributes redirectAttributes) { if (!isValid(setting)) { return ERROR_VIEW; } if (setting.getUsernameMinLength() > setting.getUsernameMaxLength() || setting.getPasswordMinLength() > setting.getPasswordMinLength()) { return ERROR_VIEW; } Setting srcSetting = SettingUtils.get(); if (StringUtils.isEmpty(setting.getSmtpPassword())) { setting.setSmtpPassword(srcSetting.getSmtpPassword()); } if (watermarkImageFile != null && !watermarkImageFile.isEmpty()) { if (!fileService.isValid(FileType.image, watermarkImageFile)) { addFlashMessage(redirectAttributes, Message.error("admin.upload.invalid")); return "redirect:edit.jhtml"; } String watermarkImage = fileService.uploadLocal(FileType.image, watermarkImageFile); setting.setWatermarkImage(watermarkImage); } else { setting.setWatermarkImage(srcSetting.getWatermarkImage()); } setting.setCnzzSiteId(srcSetting.getCnzzSiteId()); setting.setCnzzPassword(srcSetting.getCnzzPassword()); SettingUtils.set(setting); cacheService.clear(); staticService.buildIndex(); staticService.buildOther(); OutputStream outputStream = null; try { org.springframework.core.io.Resource resource = new ClassPathResource( CommonAttributes.DP2345_PROPERTIES_PATH); Properties properties = PropertiesLoaderUtils.loadProperties(resource); String templateUpdateDelay = properties.getProperty("template.update_delay"); String messageCacheSeconds = properties.getProperty("message.cache_seconds"); if (setting.getIsDevelopmentEnabled()) { if (!templateUpdateDelay.equals("0") || !messageCacheSeconds.equals("0")) { outputStream = new FileOutputStream(resource.getFile()); properties.setProperty("template.update_delay", "0"); properties.setProperty("message.cache_seconds", "0"); properties.store(outputStream, "DP2345 PROPERTIES"); } } else { if (templateUpdateDelay.equals("0") || messageCacheSeconds.equals("0")) { outputStream = new FileOutputStream(resource.getFile()); properties.setProperty("template.update_delay", "3600"); properties.setProperty("message.cache_seconds", "3600"); properties.store(outputStream, "DP2345 PROPERTIES"); } } } catch (Exception e) { e.printStackTrace(); } finally { IOUtils.closeQuietly(outputStream); } addFlashMessage(redirectAttributes, SUCCESS_MESSAGE); return "redirect:edit.jhtml"; }
From source file:eu.europa.esig.dss.tsl.TrustedListsCertificateSource.java
/** * @param properties/*from w w w . jav a 2s . c o m*/ * @param propertiesFileName */ public void saveProperties(final Properties properties, final String propertiesFileName) { final File file = new File(tslPropertyCacheFolder, propertiesFileName); try { final FileOutputStream fileOutputStream = new FileOutputStream(file); properties.store(fileOutputStream, null); } catch (Exception e) { logger.error("Impossible to save: '{}'", file.getAbsolutePath(), e); } }
From source file:de.akquinet.gomobile.androlog.test.MailReporterTest.java
public void setUp() { try {//from w w w . j a va 2 s .c o m Assert.assertTrue("No SDCard or not the permission to write", Environment.getExternalStorageDirectory().canWrite()); // Create files Properties propsDefault = new Properties(); propsDefault.setProperty(Constants.ANDROLOG_ACTIVE, "true"); propsDefault.setProperty(Constants.ANDROLOG_REPORT_ACTIVE, "true"); propsDefault.setProperty(Constants.ANDROLOG_REPORT_REPORTERS, "de.akquinet.android.androlog.reporter.NoopReporter"); Properties propsActive = new Properties(); propsActive.setProperty(Constants.ANDROLOG_ACTIVE, "true"); propsActive.setProperty(Constants.ANDROLOG_REPORT_ACTIVE, "true"); propsActive.setProperty(Constants.ANDROLOG_REPORT_REPORTERS, "de.akquinet.android.androlog.reporter.MailReporter"); propsActive.setProperty(MailReporter.ANDROLOG_REPORTER_MAIL_ADDRESS, "clement.escoffier@gmail.com"); testContext = new File(Environment.getExternalStorageDirectory(), getContext().getPackageName() + ".properties"); testContext.createNewFile(); (new File(Environment.getExternalStorageDirectory(), "tmp")).mkdir(); FileOutputStream out = new FileOutputStream(testContext); propsActive.store(out, "Enable Androlog file"); out.close(); } catch (Exception e) { e.printStackTrace(); Assert.fail(e.getMessage()); } }