List of usage examples for java.util Properties store
public void store(OutputStream out, String comments) throws IOException
From source file:emperior.Main.java
public static void updateStartedWithTask(String task) { if (!adminmode) { Properties properties = new Properties(); try {/* w w w . j av a 2 s . c o m*/ BufferedInputStream stream = new BufferedInputStream(new FileInputStream("Emperior.properties")); properties.load(stream); properties.setProperty("startedwith", task); BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream("Emperior.properties")); properties.store(out, ""); out.close(); stream.close(); } catch (Exception e) { } } }
From source file:com.bcmcgroup.flare.client.ClientUtil.java
/** * Set the value of a property for a specific property name. * * @param property the property name with its value to be set in the config.properties * @param value the value to be set in the config.properties * *///from w w w . j a va2 s .c o m public static void setProperty(String property, String value) { Properties properties = new Properties(); InputStream inputStream = null; OutputStream outputStream = null; File file = new File("config.properties"); try { inputStream = new FileInputStream(file); properties.load(inputStream); properties.setProperty(property, value); outputStream = new FileOutputStream(file); properties.store(outputStream, ""); } catch (IOException e) { logger.error("IOException when attempting to set a configuration property. "); } finally { if (inputStream != null) { try { inputStream.close(); } catch (IOException e) { logger.error("IOException when attempting to set a configuration property. "); } } if (outputStream != null) { try { outputStream.close(); } catch (IOException e) { logger.error("IOException when attempting to set a configuration property. "); } } } }
From source file:com.piusvelte.taplock.server.TapLockServer.java
private static void initialize() { (new File(APP_PATH)).mkdir(); if (OS == OS_WIN) Security.addProvider(new BouncyCastleProvider()); System.out.println("APP_PATH: " + APP_PATH); try {/*from www.j a va 2 s . c om*/ sLogFileHandler = new FileHandler(sLog); } catch (SecurityException e) { writeLog("sLogFileHandler init: " + e.getMessage()); } catch (IOException e) { writeLog("sLogFileHandler init: " + e.getMessage()); } File propertiesFile = new File(sProperties); if (!propertiesFile.exists()) { try { propertiesFile.createNewFile(); } catch (IOException e) { writeLog("propertiesFile.createNewFile: " + e.getMessage()); } } Properties prop = new Properties(); try { prop.load(new FileInputStream(sProperties)); if (prop.isEmpty()) { prop.setProperty(sPassphraseKey, sPassphrase); prop.setProperty(sDisplaySystemTrayKey, Boolean.toString(sDisplaySystemTray)); prop.setProperty(sDebuggingKey, Boolean.toString(sDebugging)); prop.store(new FileOutputStream(sProperties), null); } else { if (prop.containsKey(sPassphraseKey)) sPassphrase = prop.getProperty(sPassphraseKey); else prop.setProperty(sPassphraseKey, sPassphrase); if (prop.containsKey(sDisplaySystemTrayKey)) sDisplaySystemTray = Boolean.parseBoolean(prop.getProperty(sDisplaySystemTrayKey)); else prop.setProperty(sDisplaySystemTrayKey, Boolean.toString(sDisplaySystemTray)); if (prop.containsKey(sDebuggingKey)) sDebugging = Boolean.parseBoolean(prop.getProperty(sDebuggingKey)); else prop.setProperty(sDebuggingKey, Boolean.toString(sDebugging)); } } catch (FileNotFoundException e) { writeLog("prop load: " + e.getMessage()); } catch (IOException e) { writeLog("prop load: " + e.getMessage()); } if (sLogFileHandler != null) { sLogger = Logger.getLogger("TapLock"); sLogger.setUseParentHandlers(false); sLogger.addHandler(sLogFileHandler); SimpleFormatter sf = new SimpleFormatter(); sLogFileHandler.setFormatter(sf); writeLog("service starting"); } if (sDisplaySystemTray && SystemTray.isSupported()) { final SystemTray systemTray = SystemTray.getSystemTray(); Image trayIconImg = Toolkit.getDefaultToolkit() .getImage(TapLockServer.class.getResource("/systemtrayicon.png")); final TrayIcon trayIcon = new TrayIcon(trayIconImg, "Tap Lock"); trayIcon.setImageAutoSize(true); PopupMenu popupMenu = new PopupMenu(); MenuItem aboutItem = new MenuItem("About"); CheckboxMenuItem toggleSystemTrayIcon = new CheckboxMenuItem("Display Icon in System Tray"); toggleSystemTrayIcon.setState(sDisplaySystemTray); CheckboxMenuItem toggleDebugging = new CheckboxMenuItem("Debugging"); toggleDebugging.setState(sDebugging); MenuItem shutdownItem = new MenuItem("Shutdown Tap Lock Server"); popupMenu.add(aboutItem); popupMenu.add(toggleSystemTrayIcon); if (OS == OS_WIN) { MenuItem setPasswordItem = new MenuItem("Set password"); popupMenu.add(setPasswordItem); setPasswordItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JPanel panel = new JPanel(); JLabel label = new JLabel("Enter your Windows account password:"); JPasswordField passField = new JPasswordField(32); panel.add(label); panel.add(passField); String[] options = new String[] { "OK", "Cancel" }; int option = JOptionPane.showOptionDialog(null, panel, "Tap Lock", JOptionPane.NO_OPTION, JOptionPane.PLAIN_MESSAGE, null, options, options[0]); if (option == 0) { String password = encryptString(new String(passField.getPassword())); if (password != null) { Properties prop = new Properties(); try { prop.load(new FileInputStream(sProperties)); prop.setProperty(sPasswordKey, password); prop.store(new FileOutputStream(sProperties), null); } catch (FileNotFoundException e1) { writeLog("prop load: " + e1.getMessage()); } catch (IOException e1) { writeLog("prop load: " + e1.getMessage()); } } } } }); } popupMenu.add(toggleDebugging); popupMenu.add(shutdownItem); trayIcon.setPopupMenu(popupMenu); try { systemTray.add(trayIcon); } catch (AWTException e) { writeLog("systemTray.add: " + e.getMessage()); } aboutItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String newline = System.getProperty("line.separator"); newline += newline; JOptionPane.showMessageDialog(null, "Tap Lock" + newline + "Copyright (c) 2012 Bryan Emmanuel" + newline + "This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version." + newline + "This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details." + newline + "You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>." + newline + "Bryan Emmanuel piusvelte@gmail.com"); } }); toggleSystemTrayIcon.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { setTrayIconDisplay(e.getStateChange() == ItemEvent.SELECTED); if (!sDisplaySystemTray) systemTray.remove(trayIcon); } }); toggleDebugging.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { setDebugging(e.getStateChange() == ItemEvent.SELECTED); } }); shutdownItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { shutdown(); } }); } synchronized (sConnectionThreadLock) { (sConnectionThread = new ConnectionThread()).start(); } }
From source file:com.edgenius.wiki.Shell.java
public static void save() { try {// w w w.j a va 2 s. co m filelock.writeLock().lock(); //write this key to shell.properties String root = DataRoot.getDataRoot(); Properties props = FileUtil.loadProperties(root + Shell.FILE); props.setProperty("shell.key", StringUtils.trimToEmpty(Shell.key)); props.setProperty("shell.enabled", Boolean.toString(Shell.enabled)); //fix to add end slash if (!Shell.rootUrl.endsWith("/")) Shell.rootUrl += "/"; props.setProperty("shell.url", StringUtils.trimToEmpty(Shell.rootUrl)); props.setProperty("connection.timeout", String.valueOf(Shell.timeout)); updateUrl(); FileOutputStream os = FileUtil.getFileOutputStream(root + Shell.FILE); props.store(os, "Shell is update by system."); } catch (Exception e) { log.error("Unable to save shell.properties", e); } finally { filelock.writeLock().unlock(); } }
From source file:com.px100systems.data.browser.controller.DbBrowserUserDetailsService.java
/** * Save user file content// ww w . j av a2 s .co m * @param users user/password pairs * @throws Exception */ public void saveUsers(Properties users) throws Exception { users.store(new FileWriter(usersFile), null); }
From source file:brooklyn.util.os.Os.java
public static File writePropertiesToTempFile(Properties props, File tempDir, String prefix, String suffix) { Preconditions.checkNotNull(props, "Properties required to create temp file for %s*%s", prefix, suffix); File tempFile;/*from w ww .j a v a 2 s . c om*/ try { tempFile = File.createTempFile(prefix, suffix, tempDir); } catch (IOException e) { throw Throwables.propagate(e); } tempFile.deleteOnExit(); OutputStream out = null; try { out = new FileOutputStream(tempFile); props.store(out, "Auto-generated by Brooklyn"); } catch (IOException e) { throw Throwables.propagate(e); } finally { Streams.closeQuietly(out); } return tempFile; }
From source file:com.streamsets.datacollector.main.RuntimeInfo.java
/** * Store configuration from control hub in persistent manner inside data directory. This configuration will be * loaded on data collector start and will override any configuration from sdc.properties. * * This method call is able to remove existing properties if the value is "null". Please note that the removal will * only happen from the 'override' file. This method does not have the capability to remove configuration directly * from sdc.properties./*from w w w. j a va 2 s. c o m*/ * * @param runtimeInfo RuntimeInfo instance * @param newConfigs New set of config properties * @throws IOException */ public static void storeControlHubConfigs(RuntimeInfo runtimeInfo, Map<String, String> newConfigs) throws IOException { File configFile = new File(runtimeInfo.getDataDir(), SCH_CONF_OVERRIDE); Properties properties = new Properties(); // Load existing properties from disk if they exists if (configFile.exists()) { try (FileReader reader = new FileReader(configFile)) { properties.load(reader); } } // Propagate updated configuration for (Map.Entry<String, String> entry : newConfigs.entrySet()) { if (entry.getValue() == null) { properties.remove(entry.getKey()); } else { properties.setProperty(entry.getKey(), entry.getValue()); } } // Store the new updated configuration back to disk try (FileWriter writer = new FileWriter(configFile)) { properties.store(writer, null); } }
From source file:de.avanux.livetracker.mobile.ConfigurationProvider.java
/** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) *///from w w w . j av a 2s .c o m protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { log.debug("Configuration request received."); response.setContentType("text/plain"); PrintWriter out = response.getWriter(); Properties configuration = buildConfiguration(); configuration.store(out, null); out.close(); log.debug("Configuration returned."); }
From source file:com.xiongyingqi.util.DefaultPropertiesPersister.java
@Override public void store(Properties props, Writer writer, String header) throws IOException { props.store(writer, header); }
From source file:com.xiongyingqi.util.DefaultPropertiesPersister.java
@Override public void store(Properties props, OutputStream os, String header) throws IOException { props.store(os, header); }