List of usage examples for java.util.prefs Preferences flush
public abstract void flush() throws BackingStoreException;
From source file:net.sf.ginp.setup.SetupManagerImpl.java
/** * @see net.sf.ginp.setup.SetupManager#deleteConfiguration(java.net.URL) *//*from www. jav a 2 s .co m*/ public final void deleteConfiguration(final URL configUrl) { Preferences preferences = Preferences.userNodeForPackage(SetupManagerImpl.class); preferences.remove(configUrl.toExternalForm()); try { preferences.flush(); } catch (BackingStoreException e) { log.error("No big deal if we couldn't delete", e); } }
From source file:org.pentaho.reporting.ui.datasources.jdbc.connection.JdbcConnectionDefinitionManager.java
/** * Adds or updates the source list with the specified source entry. If the entry exists (has the same name), the new * entry will replace the old entry. If the enrty does not already exist, the new entry will be added to the list. <br> * Since the definition of the ConnectionDefintion ensures that it will be valid, no testing will be performed on the * contents of the ConnectionDefintion./*from w w w . j a va 2s . com*/ * * @param source * the entry to add/update in the list * @throws IllegalArgumentException * indicates the source is <code>null</code> */ private boolean updateSourceList(final JndiConnectionDefinition source) throws IllegalArgumentException { if (source == null) { throw new IllegalArgumentException("The provided source is null"); } // Update the node in the list final boolean updateExisting = (connectionDefinitions.put(source.getName(), source) != null); // Update the information in the preferences try { final Preferences node = userPreferences.node(source.getName()); put(node, TYPE_KEY, "jndi"); put(node, JNDI_LOCATION, source.getJndiName()); put(node, USERNAME_KEY, null); put(node, PASSWORD_KEY, null); put(node, DATABASE_TYPE_KEY, source.getDatabaseType()); node.flush(); } catch (BackingStoreException e) { log.error("Could not add/update connection entry [" + source.getName() + ']', e); } return updateExisting; }
From source file:verdandi.ui.settings.DefaultSettingsPanel.java
public void storePrefs() { Preferences prefs = Preferences.userNodeForPackage(DurationFormatter.class); if (radioFormatHHQuarters.isSelected()) { prefs.putInt(DurationFormatter.PREF_DISPLAY_MODE, DurationFormatter.DISPLAY_DURATION_HH_QUARTER); } else if (radioFormatHHMM.isSelected()) { prefs.putInt(DurationFormatter.PREF_DISPLAY_MODE, DurationFormatter.DISPLAY_DURATION_HHMM); }// w w w .j a va2 s . c o m try { prefs.flush(); } catch (BackingStoreException e) { LOG.error("Cannot store Prefs: ", e); } conf.setStorePasswd(storePasswordCheckBox.isSelected()); conf.setShowTimerOnStartup(showTimerOnStartupCheckBox.isSelected()); for (Entry<String, JTextField> pt : persistenceFields.entrySet()) { conf.setConfigProperty(pt.getKey(), pt.getValue().getText()); } conf.setConfigProperty(AnnotatedWorkRecordView.PREF_RESTORE_ON_INIT, Boolean.toString(initAnnotatedWorkRecordsOnStartup.isSelected())); workDaySettingsPanel.commit(); }
From source file:org.esa.snap.smart.configurator.PerformanceParameters.java
/** * Save the actual configuration/*from ww w .j a va 2s . co m*/ * * @param confToSave The configuration to save */ synchronized static void saveConfiguration(PerformanceParameters confToSave) throws IOException, BackingStoreException { if (!loadConfiguration().getVMParameters().equals(confToSave.getVMParameters())) { confToSave.vmParameters.save(); } Config configuration = EngineConfig.instance().load(); Preferences preferences = configuration.preferences(); Path cachePath = confToSave.getCachePath(); if (!Files.exists(cachePath)) { Files.createDirectories(cachePath); } if (Files.exists(cachePath)) { preferences.put(SystemUtils.SNAP_CACHE_DIR_PROPERTY_NAME, cachePath.toAbsolutePath().toString()); } else { SystemUtils.LOG.severe("Directory for cache path does not exist"); } JAI ff = JAI.getDefaultInstance(); int parallelism = confToSave.getNbThreads(); //int defaultTileSize = confToSave.getDefaultTileSize(); int jaiCacheSize = confToSave.getCacheSize(); String tileWidth = confToSave.getTileWidth(); String tileHeight = confToSave.getTileHeight(); preferences.putInt(SystemUtils.SNAP_PARALLELISM_PROPERTY_NAME, parallelism); /*if(tileWidth == null) { preferences.remove(SYSPROP_READER_TILE_WIDTH); } else { preferences.put(SYSPROP_READER_TILE_WIDTH,tileWidth); } if(tileHeight == null) { preferences.remove(SYSPROP_READER_TILE_HEIGHT); } else { preferences.put(SYSPROP_READER_TILE_HEIGHT,tileHeight); }*/ preferences.putInt(PROPERTY_JAI_CACHE_SIZE, jaiCacheSize); preferences.flush(); // effective change of jai parameters JAIUtils.setDefaultTileCacheCapacity(jaiCacheSize); JAI.getDefaultInstance().getTileScheduler().setParallelism(parallelism); }
From source file:com.concursive.connect.config.ApplicationPrefs.java
/** * Save a name/value pair to the Java Preferences store * * @param instanceName Description of the Parameter * @param fileLibraryLocation Description of the Parameter * @return Description of the Return Value *///from w w w. j a v a 2s .c om public static boolean saveFileLibraryLocation(String instanceName, String fileLibraryLocation) { try { if (instanceName == null || fileLibraryLocation == null) { LOG.error("Invalid parameters: " + instanceName + "=" + fileLibraryLocation); } Preferences javaPrefs = Preferences.userNodeForPackage(ApplicationPrefs.class); if (javaPrefs == null) { LOG.error("Couldn't create java preferences for: " + ApplicationPrefs.class); } if (instanceName.length() <= Preferences.MAX_KEY_LENGTH) { javaPrefs.put(instanceName, fileLibraryLocation); } else { javaPrefs.put(instanceName.substring(instanceName.length() - Preferences.MAX_KEY_LENGTH), fileLibraryLocation); } javaPrefs.flush(); return true; } catch (Exception e) { LOG.error("saveFileLibraryLocation", e); e.printStackTrace(System.out); return false; } }
From source file:com.trifork.riak.RiakClient.java
/** * helper method to use a reasonable default client id * //from w w w. ja v a 2 s .c om * @throws IOException */ public void prepareClientID() throws IOException { Preferences prefs = Preferences.userNodeForPackage(RiakClient.class); String clid = prefs.get("client_id", null); if (clid == null) { SecureRandom sr; try { sr = SecureRandom.getInstance("SHA1PRNG"); } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e); } byte[] data = new byte[6]; sr.nextBytes(data); clid = Base64Coder.encodeLines(data); prefs.put("client_id", clid); try { prefs.flush(); } catch (BackingStoreException e) { throw new IOException(e); } } setClientID(clid); }
From source file:verdandi.ui.ProjectViewerPanel.java
private void importProjects() { Preferences prefs = Preferences.userNodeForPackage(getClass()); File importDir = new File(prefs.get("import.dir", System.getProperty("user.home"))); JFileChooser chooser = new JFileChooser(importDir); chooser.setDialogTitle(RB.getString("projectviewer.import.filechooser.title")); chooser.setMultiSelectionEnabled(false); if (chooser.showOpenDialog(this) != JFileChooser.APPROVE_OPTION) { LOG.debug("User cancelled"); return;/* w w w .j a va2 s. c om*/ } File importFile = chooser.getSelectedFile(); prefs.put("import.dir", importFile.getParent()); try { prefs.flush(); } catch (BackingStoreException e) { LOG.error("Cannot write export file preference", e); } ObjectInputStream projectsIn = null; try { setCursor(CURSOR_WAIT); projectsIn = new ObjectInputStream(new FileInputStream(importFile)); Object o = projectsIn.readObject(); if (!(o instanceof Collection)) { LOG.error("The file does not contain a valid verdandi project list"); return; } Collection<?> importcoll = (Collection<?>) o; @SuppressWarnings("unchecked") List<CostUnit> projects = (List<CostUnit>) o; new ProjectImporter(projects).start(); } catch (FileNotFoundException e) { LOG.error("", e); } catch (IOException e) { LOG.error("No verdandi project list?", e); } catch (ClassNotFoundException e) { LOG.error("", e); } finally { setCursor(CURSOR_DEFAULT); if (projectsIn != null) { try { projectsIn.close(); } catch (Throwable t) { LOG.error("Cannot close stream: ", t); } } } }
From source file:verdandi.ui.action.ImportPluginAction.java
/** * Ask the import file from the user/*w ww. j av a 2 s .c o m*/ */ private File getFile() { File res = null; Preferences prefs = Preferences.userNodeForPackage(getClass()); File importDir = new File(prefs.get(KEY_CWD, System.getProperty("user.home"))); JFileChooser chooser = new JFileChooser(importDir); chooser.setFileFilter(new FileFilter() { @Override public boolean accept(File f) { return f.getName().toLowerCase().endsWith(".jar") || f.isDirectory(); } @Override public String getDescription() { return RC.getString("pluginimportaction.filechooser.jarfilter.description"); } }); chooser.setDialogTitle(RC.getString("pluginimportaction.filechooser.title")); chooser.setMultiSelectionEnabled(false); if (chooser.showOpenDialog(parent) != JFileChooser.APPROVE_OPTION) { LOG.debug("User cancelled"); return null; } res = chooser.getSelectedFile(); prefs.put("import.dir", res.getParent()); try { prefs.flush(); } catch (BackingStoreException e) { LOG.error("Cannot write export file preference", e); } return res; }
From source file:edu.umass.cs.msocket.proxy.console.ConsoleModule.java
/** * Store the current command history/*from w w w. j a va 2 s .co m*/ */ public void storeHistory() { List history = console.getHistory().getHistoryList(); try { Preferences prefs = Preferences.userRoot().node(this.getClass().getName()); prefs.clear(); int historySize = history.size(); int start = Math.max(0, historySize - 100); // save up to the last 100th history items only // witht the stored index starting at 0 for (int i = start; i < historySize; i++) { prefs.put(String.valueOf(i - start), (String) history.get(i + start)); } prefs.flush(); } catch (Exception e) { // unable to store prefs: do nothing } }
From source file:org.pentaho.reporting.ui.datasources.jdbc.connection.JdbcConnectionDefinitionManager.java
/** * Adds or updates the source list with the specified source entry. If the entry exists (has the same name), the new * entry will replace the old entry. If the enrty does not already exist, the new entry will be added to the list. <br> * Since the definition of the ConnectionDefintion ensures that it will be valid, no testing will be performed on the * contents of the ConnectionDefintion.//from w ww .j a va 2s.c o m * * @param source * the entry to add/update in the list * @throws IllegalArgumentException * indicates the source is <code>null</code> */ private boolean updateSourceList(final DriverConnectionDefinition source) throws IllegalArgumentException { if (source == null) { throw new IllegalArgumentException("The provided source is null"); } // Update the node in the list final boolean updateExisting = (connectionDefinitions.put(source.getName(), source) != null); // Update the information in the preferences try { final Preferences node = userPreferences.node(source.getName()); put(node, TYPE_KEY, "local"); put(node, DRIVER_KEY, source.getDriverClass()); put(node, URL_KEY, source.getConnectionString()); put(node, USERNAME_KEY, source.getUsername()); put(node, PASSWORD_KEY, source.getPassword()); put(node, HOSTNAME_KEY, source.getHostName()); put(node, PORT_KEY, source.getPort()); put(node, DATABASE_TYPE_KEY, source.getDatabaseType()); put(node, DATABASE_NAME_KEY, source.getDatabaseName()); final Preferences preferences = node.node("properties"); final Properties properties = source.getProperties(); final Iterator entryIterator = properties.entrySet().iterator(); while (entryIterator.hasNext()) { final Map.Entry entry = (Map.Entry) entryIterator.next(); put(preferences, String.valueOf(entry.getKey()), String.valueOf(entry.getValue())); } node.flush(); } catch (BackingStoreException e) { log.error("Could not add/update connection entry [" + source.getName() + ']', e); } return updateExisting; }