List of usage examples for java.util Properties store
public void store(OutputStream out, String comments) throws IOException
From source file:net.sf.nmedit.nomad.core.service.initService.ExplorerLocationMemory.java
public void shutdown() { Enumeration<TreeNode> nodes = Nomad.sharedInstance().getExplorer().getRoot().children(); List<FileContext> locations = new ArrayList<FileContext>(); TempDir tempDir = TempDir.generalTempDir(); File userPatches = tempDir.getTempFile("patches"); String canonicalPatches = null; try {//w ww .j a v a2 s. c o m canonicalPatches = userPatches.getCanonicalPath(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } while (nodes.hasMoreElements()) { TreeNode node = nodes.nextElement(); if (node instanceof FileContext) { FileContext fc = (FileContext) node; try { if (!fc.getFile().getCanonicalPath().equals(canonicalPatches)) locations.add(fc); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } Properties p = new Properties(); writeProperties(p, locations); File file = getTempFile(); BufferedOutputStream out = null; try { out = new BufferedOutputStream(new FileOutputStream(file)); p.store(out, "this file is generated, do not edit it"); } catch (IOException e) { // ignore } finally { try { out.flush(); out.close(); } catch (IOException e) { // ignore } } }
From source file:org.duracloud.duradmin.spaces.controller.SnapshotControllerTest.java
@Test public void testGetSnapshot() throws Exception { setupGetContentStore();/*w w w . j a v a2 s.c om*/ EasyMock.expect(store.contentExists(EasyMock.isA(String.class), EasyMock.isA(String.class))) .andReturn(true); EasyMock.expect(store.getContent(EasyMock.isA(String.class), EasyMock.isA(String.class))) .andReturn(content); Properties props = new Properties(); ByteArrayOutputStream os = new ByteArrayOutputStream(); props.store(os, null); EasyMock.expect(content.getStream()).andReturn(new ByteArrayInputStream(os.toByteArray())); replayAll(); SnapshotController controller = createController(); Assert.assertNotNull(controller.get("storeId", "spaceId")); }
From source file:annis.security.ANNISUserConfigurationManager.java
/** * Writes the user to the disk/*from w w w . j av a 2s.c om*/ * @param user * @return True if successful. */ public boolean writeUser(User user) { // save user info to file if (resourcePath != null) { lock.writeLock().lock(); try { File userDir = new File(resourcePath, "users"); if (userDir.isDirectory()) { // get the file which corresponds to the user File userFile = new File(userDir.getAbsolutePath(), user.getName()); Properties props = user.toProperties(); try (FileOutputStream out = new FileOutputStream(userFile)) { props.store(out, ""); return true; } catch (IOException ex) { log.error("Could not write users file", ex); } } } finally { lock.writeLock().unlock(); } } // end if resourcePath not null return false; }
From source file:com.haulmont.cuba.desktop.sys.MainWindowProperties.java
public void save() { Properties properties = new Properties(); saveProperties(properties);//from w ww.j a v a 2s .com try { File file = new File(AppBeans.get(Configuration.class).getConfig(GlobalConfig.class).getDataDir(), "main-window.properties"); FileOutputStream stream = FileUtils.openOutputStream(file); try { properties.store(stream, "Main window properties"); } finally { IOUtils.closeQuietly(stream); } } catch (IOException e) { log.error("Error saving main window location", e); } }
From source file:gobblin.scheduler.JobConfigFileMonitorTest.java
@Test(dependsOnMethods = { "testAddNewJobConfigFile" }) public void testChangeJobConfigFile() throws Exception { final Logger log = LoggerFactory.getLogger("testChangeJobConfigFile"); log.info("testChangeJobConfigFile: start"); Assert.assertEquals(this.jobScheduler.getScheduledJobs().size(), 4); // Make a change to the new job configuration file Properties jobProps = new Properties(); jobProps.load(new FileReader(this.newJobConfigFile)); jobProps.setProperty(ConfigurationKeys.JOB_COMMIT_POLICY_KEY, "partial"); jobProps.setProperty(ConfigurationKeys.JOB_NAME_KEY, "Gobblin-test-new2"); jobProps.store(new FileWriter(this.newJobConfigFile), null); AssertWithBackoff.create().logger(log).timeoutMs(30000).assertEquals(new GetNumScheduledJobs(), 4, "4 scheduled jobs"); final Set<String> expectedJobNames = ImmutableSet.<String>builder() .add("GobblinTest1", "GobblinTest2", "GobblinTest3", "Gobblin-test-new2").build(); AssertWithBackoff.create().logger(log).timeoutMs(30000).assertEquals(new Function<Void, Set<String>>() { @Override//from ww w. j a va2s . c om public Set<String> apply(Void input) { return Sets.newHashSet(JobConfigFileMonitorTest.this.jobScheduler.getScheduledJobs()); } }, expectedJobNames, "Job change detected"); log.info("testChangeJobConfigFile: end"); }
From source file:edu.kit.dama.staging.handlers.impl.DownloadPreparationHandler.java
@Override public final void prepareEnvironment(TransferClientProperties pProperties, IAuthorizationContext pSecurityContext) throws TransferPreparationException { LOGGER.debug("Preparing data download tree"); LOGGER.debug(" - Obtaining AccessPoint"); AbstractStagingAccessPoint accessPoint = StagingConfigurationManager.getSingleton() .getAccessPointById(pProperties.getStagingAccessPointId()); LOGGER.debug(" - Getting access URL"); URL accessUrl = accessPoint.getAccessUrl(getTransferInformation(), pSecurityContext); LOGGER.debug(" - Access URL: {}. Getting local staging folder.", accessUrl); File localStagingFolder = accessPoint.getLocalPathForUrl(accessUrl, pSecurityContext); LOGGER.debug(" - Local staging folder: {}", localStagingFolder); File localSettingsFolder = AbstractStagingAccessPoint.getSettingsFolder(localStagingFolder); LOGGER.debug(" - Local settings folder: {}. Obtaining file tree destination file.", localSettingsFolder); String treeFile = FilenameUtils.concat(localSettingsFolder.getPath(), DATA_FILENAME); if (new File(treeFile).exists() && !StagingService.getSingleton().isTransferDeleted(getTransferInformation())) { throw new TransferPreparationException( "Download for this object is still in preparation. Please try again later"); }//from www .j av a2s. c om LOGGER.debug("Writing tree data to {}", treeFile); DataOrganizationUtils.writeTreeToFile(treeToDownload, new File(treeFile)); if (pProperties.isSendMailNotification()) { LOGGER.debug("Writing mail notification information to file"); MailNotificationHelper.storeProperties(localSettingsFolder, pProperties.getReceiverMail()); } LOGGER.debug("Storing access point properties."); Properties props = TransferClientPropertiesUtils.propertiesToProperties(pProperties); FileOutputStream fout = null; try { fout = new FileOutputStream( new File(localSettingsFolder, pProperties.getStagingAccessPointId() + ".properties")); props.store(fout, null); } catch (IOException ioe) { LOGGER.error("Failed to store access point properies", ioe); } finally { if (fout != null) { try { fout.close(); } catch (IOException ex) { } } } LOGGER.debug("Environment preparation successfully finished"); }
From source file:org.sventon.appl.ApplicationTest.java
private OutputStream storeProperties(File configFile, Properties properties) throws IOException { OutputStream os = null;/*from ww w . j a v a 2 s .co m*/ try { os = new FileOutputStream(configFile); properties.store(os, null); return os; } finally { IOUtils.closeQuietly(os); } }
From source file:org.duracloud.snapshottask.snapshot.CreateSnapshotTaskRunner.java
/** * Constructs the contents of a properties file given a set of * key/value pairs/*from w ww .j a v a 2s . c o m*/ * * @param props snapshot properties * @return Properties-file formatted key/value pairs */ protected String buildSnapshotProps(Map<String, String> props) { Properties snapshotProperties = new Properties(); for (String key : props.keySet()) { snapshotProperties.setProperty(key, props.get(key)); } StringWriter writer = new StringWriter(); try { snapshotProperties.store(writer, null); } catch (IOException e) { throw new TaskException("Could not write snapshot properties: " + e.getMessage(), e); } writer.flush(); return writer.toString(); }
From source file:com.fer.hr.service.datasource.ClassPathResourceDatasourceManager.java
public SaikuDatasource addDatasource(SaikuDatasource datasource) { try {//from ww w . j a va2 s. c o m String uri = repoURL.toURI().toString(); if (uri != null && datasource != null) { uri += datasource.getName().replace(" ", "_"); File dsFile = new File(new URI(uri)); if (dsFile.exists()) { dsFile.delete(); } else { dsFile.createNewFile(); } FileWriter fw = new FileWriter(dsFile); Properties props = datasource.getProperties(); props.store(fw, null); fw.close(); datasources.put(datasource.getName(), datasource); return datasource; } else { throw new SaikuServiceException( "Cannot save datasource because uri or datasource is null uri(" + (uri == null) + ")"); } } catch (Exception e) { throw new SaikuServiceException("Error saving datasource", e); } }
From source file:com.pivotal.gemfire.tools.pulse.internal.data.DataBrowser.java
/** * generateQueryKey method stores queries in query history file. * /*w w w . ja v a 2 s .c om*/ * @return Boolean true is operation is successful, false otherwise * @param properties * a collection queries in form of key and values */ private boolean storeQueriesInFile(Properties properties) { boolean operationStatus = false; FileOutputStream fileOut = null; File file = new File(queryHistoryFile); try { fileOut = new FileOutputStream(file); properties.store(fileOut, resourceBundle.getString("LOG_MSG_DATA_BROWSER_QUERY_HISTORY_FILE_DESCRIPTION")); operationStatus = true; } catch (FileNotFoundException e) { if (LOGGER.infoEnabled()) { LOGGER.info(resourceBundle.getString("LOG_MSG_DATA_BROWSER_QUERY_HISTORY_FILE_NOT_FOUND") + " : " + e.getMessage()); } } catch (IOException e) { if (LOGGER.infoEnabled()) { LOGGER.info(e.getMessage()); } } finally { if (fileOut != null) { try { fileOut.close(); } catch (IOException e) { if (LOGGER.infoEnabled()) { LOGGER.info(e.getMessage()); } } } } return operationStatus; }