List of usage examples for java.util.prefs BackingStoreException BackingStoreException
public BackingStoreException(Throwable cause)
From source file:org.pentaho.reporting.designer.core.settings.prefs.BinaryPreferences.java
protected void syncSpi() throws BackingStoreException { final File pathForNode = new File(getPathForNode()); if (pathForNode.exists() == false && properties.isEmpty()) { return;/*from w w w . j a v a 2 s.c o m*/ } load(pathForNode); if (pathForNode.exists() == false) { if (pathForNode.mkdirs() == false) { throw new BackingStoreException("Failed to write config " + pathForNode); //$NON-NLS-1$ } } final File target = new File(pathForNode, "prefs.properties");//NON-NLS if (target.exists() == false || target.lastModified() < lastModificationTime) { try { final OutputStream out = new BufferedOutputStream(new FileOutputStream(target)); try { properties.store(out, ""); } finally { out.close(); } } catch (final Exception e) { throw new BackingStoreException("Failed to write config " + target); //$NON-NLS-1$ } } }
From source file:org.pentaho.reporting.designer.core.settings.prefs.BinaryPreferences.java
private void load(final File pathForNode) throws BackingStoreException { if (pathForNode.exists()) { // load .. final File target = new File(pathForNode, "prefs.properties");//NON-NLS if (target.lastModified() > lastModificationTime) { if (target.exists()) { try { final InputStream out = new BufferedInputStream(new FileInputStream(target)); try { properties.clear(); properties.load(out); lastModificationTime = Math.max(lastModificationTime + 1, System.currentTimeMillis()); } finally { out.close();/*from w w w . j ava 2 s . co m*/ } } catch (final Exception e) { UncaughtExceptionsModel.getInstance().addException(e); throw new BackingStoreException("Failed to write config " + target); //$NON-NLS-1$ } } } } }
From source file:org.pentaho.reporting.designer.core.settings.prefs.BinaryPreferences.java
protected void removeNodeSpi() throws BackingStoreException { // delete the directory .. final File pathForNode = new File(getPathForNode()); if (pathForNode.exists()) { final File target = new File(pathForNode, "prefs.properties");//NON-NLS if (target.delete() == false) { throw new BackingStoreException("Unable to delete node-backend"); }/* w ww . ja va2 s. co m*/ if (pathForNode.delete() == false) { throw new BackingStoreException("Unable to delete node-backend"); } } }
From source file:org.pentaho.reporting.designer.core.settings.prefs.BinaryPreferences.java
/** * Encodes the given configuration path. All non-ascii characters get replaced by an escape sequence. * * @param path the path./* ww w . java 2 s .c o m*/ * @return the translated path. * @throws java.util.prefs.BackingStoreException if something goes wrong. */ private static String decodePath(final String path) throws BackingStoreException { try { final char[] data = path.toCharArray(); final StringBuffer encoded = new StringBuffer(path.length()); int seenDollarIndex = -1; for (int i = 0; i < data.length; i++) { if (seenDollarIndex > -1) { if (data[i] == '$') { encoded.append('$'); seenDollarIndex = -1; continue; } if (i - seenDollarIndex == 4) { final int c = Integer.parseInt(path.substring(seenDollarIndex + 1, i + 1), 16); encoded.append((char) c); seenDollarIndex = -1; continue; } else { continue; } } if (data[i] == '$') { seenDollarIndex = i; } else { encoded.append(data[i]); } } return encoded.toString(); } catch (NumberFormatException nfe) { nfe.printStackTrace(); throw new BackingStoreException("Failed to decode name: " + path); } }
From source file:org.sonatype.nexus.rt.prefs.FilePreferences.java
@Override protected void syncSpi() throws BackingStoreException { if (isRemoved()) { return;/*w w w . j av a 2s . c o m*/ } final File file = FilePreferencesFactory.getPreferencesFile(); if (!file.exists()) { return; } synchronized (file) { Properties p = new Properties(); try { final FileInputStream in = new FileInputStream(file); try { p.load(in); } finally { IOUtils.closeQuietly(in); } StringBuilder sb = new StringBuilder(); getPath(sb); String path = sb.toString(); final Enumeration<?> pnen = p.propertyNames(); while (pnen.hasMoreElements()) { String propKey = (String) pnen.nextElement(); if (propKey.startsWith(path)) { String subKey = propKey.substring(path.length()); // Only load immediate descendants if (subKey.indexOf('.') == -1) { root.put(subKey, p.getProperty(propKey)); } } } } catch (IOException e) { throw new BackingStoreException(e); } } }
From source file:org.sonatype.nexus.rt.prefs.FilePreferences.java
@Override protected void flushSpi() throws BackingStoreException { final File file = FilePreferencesFactory.getPreferencesFile(); synchronized (file) { Properties p = new Properties(); try {//from ww w .j a v a2 s .c o m StringBuilder sb = new StringBuilder(); getPath(sb); String path = sb.toString(); if (file.exists()) { final FileInputStream in = new FileInputStream(file); try { p.load(in); } finally { IOUtils.closeQuietly(in); } List<String> toRemove = new ArrayList<String>(); // Make a list of all direct children of this node to be removed final Enumeration<?> pnen = p.propertyNames(); while (pnen.hasMoreElements()) { String propKey = (String) pnen.nextElement(); if (propKey.startsWith(path)) { String subKey = propKey.substring(path.length()); // Only do immediate descendants if (subKey.indexOf('.') == -1) { toRemove.add(propKey); } } } // Remove them now that the enumeration is done with for (String propKey : toRemove) { p.remove(propKey); } } // If this node hasn't been removed, add back in any values if (!isRemoved) { for (String s : root.keySet()) { p.setProperty(path + s, root.get(s)); } } final FileOutputStream out = new FileOutputStream(file); try { p.store(out, "FilePreferences"); } finally { IOUtils.closeQuietly(out); } } catch (IOException e) { throw new BackingStoreException(e); } } }