Search in sources :

Example 86 with BackingStoreException

use of java.util.prefs.BackingStoreException in project org.alloytools.alloy by AlloyTools.

the class MailBug method prepareCrashReport.

/**
 * This method prepares the crash report.
 */
private static String prepareCrashReport(Thread thread, Throwable ex, String email, String problem) {
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    pw.printf("Alloy Analyzer %s crash report (Build Date = %s) (Commit = %s)\n", Version.version(), Version.commit);
    pw.printf("\n========================= Email ============================\n%s\n", Util.convertLineBreak(email).trim());
    pw.printf("\n========================= Problem ==========================\n%s\n", Util.convertLineBreak(problem).trim());
    pw.printf("\n========================= Thread Name ======================\n%s\n", thread.getName().trim());
    if (ex != null)
        pw.printf("\n========================= Stack Trace ======================\n%s\n", dump(ex));
    pw.printf("\n========================= Preferences ======================\n");
    try {
        for (String key : Preferences.userNodeForPackage(Util.class).keys()) {
            String value = Preferences.userNodeForPackage(Util.class).get(key, "");
            pw.printf("%s = %s\n", key.trim(), value.trim());
        }
    } catch (BackingStoreException bse) {
        pw.printf("BackingStoreException occurred: %s\n", bse.toString().trim());
    }
    pw.printf("\n========================= System Properties ================\n");
    pw.println("Runtime.freeMemory() = " + Runtime.getRuntime().freeMemory());
    pw.println("nRuntime.totalMemory() = " + Runtime.getRuntime().totalMemory());
    for (Map.Entry<Object, Object> e : System.getProperties().entrySet()) {
        String k = String.valueOf(e.getKey()), v = String.valueOf(e.getValue());
        pw.printf("%s = %s\n", k.trim(), v.trim());
    }
    pw.printf("\n========================= The End ==========================\n\n");
    pw.close();
    sw.flush();
    return sw.toString();
}
Also used : StringWriter(java.io.StringWriter) BackingStoreException(java.util.prefs.BackingStoreException) Map(java.util.Map) PrintWriter(java.io.PrintWriter)

Example 87 with BackingStoreException

use of java.util.prefs.BackingStoreException in project energy3d by concord-consortium.

the class OneInstance method setActivePort.

/**
 * Remembers an active port number in the preferences.
 *
 * @param mainClass
 *            The main class of the application.
 * @param port
 *            The port number.
 */
private void setActivePort(final Class<?> mainClass, final int port) {
    final Preferences prefs = Preferences.userNodeForPackage(mainClass);
    prefs.putInt(PORT_KEY, port);
    try {
        prefs.flush();
    } catch (final BackingStoreException e) {
        e.printStackTrace();
    }
}
Also used : BackingStoreException(java.util.prefs.BackingStoreException) Preferences(java.util.prefs.Preferences)

Example 88 with BackingStoreException

use of java.util.prefs.BackingStoreException in project energy3d by concord-consortium.

the class OneInstance method unregister.

/**
 * Unregisters this instance of the application. If this is the first instance then the server is closed and the port is removed from the preferences. If this is not the first instance then this method does nothing.
 *
 * This method should be called when the application exits. But it is not a requirement. When you don't do this then the port number will stay in the preferences so on next start of the application this port number must be validated. So by calling this method on application exit you just save the time for this port validation.
 *
 * @param mainClass
 *            The main class of the application. Must not be null. This is used as the user node key for the preferences.
 */
public void unregister(final Class<?> mainClass) {
    if (mainClass == null)
        throw new IllegalArgumentException("mainClass must be set");
    // Nothing to do when no server socket is present
    if (server == null)
        return;
    // Close the server socket
    server.stop();
    server = null;
    // Remove the port from the preferences
    final Preferences prefs = Preferences.userNodeForPackage(mainClass);
    prefs.remove(PORT_KEY);
    try {
        prefs.flush();
    } catch (final BackingStoreException e) {
        e.printStackTrace();
    }
}
Also used : BackingStoreException(java.util.prefs.BackingStoreException) Preferences(java.util.prefs.Preferences)

Example 89 with BackingStoreException

use of java.util.prefs.BackingStoreException in project hale by halestudio.

the class WMSConfiguration method load.

/**
 * Load a WMS configuration with the given name
 *
 * @param name the configuration name
 *
 * @return if loading the configuration succeeded
 */
public boolean load(String name) {
    Preferences preferences = getPreferences();
    try {
        if (preferences.nodeExists(name)) {
            Preferences node = preferences.node(name);
            setName(name);
            loadProperties(node);
            return true;
        } else {
            // $NON-NLS-1$ //$NON-NLS-2$
            log.warn("No configuration named " + name + " found");
            return false;
        }
    } catch (BackingStoreException e) {
        // $NON-NLS-1$
        log.error("Error loading WMS configuration");
        return false;
    }
}
Also used : BackingStoreException(java.util.prefs.BackingStoreException) Preferences(java.util.prefs.Preferences)

Example 90 with BackingStoreException

use of java.util.prefs.BackingStoreException in project hale by halestudio.

the class WMSConfiguration method save.

/**
 * Save the configuration
 *
 * @param overwrite if old settings/servers with the same name shall be
 *            overridden
 */
public void save(boolean overwrite) {
    Preferences preferences = getPreferences();
    try {
        String name = getName();
        if (!overwrite) {
            int i = 1;
            // find unique name
            while (preferences.nodeExists(name)) {
                // $NON-NLS-1$
                name = getName() + "_" + i;
                i++;
            }
        }
        Preferences node = preferences.node(name);
        setName(name);
        saveProperties(node);
        node.flush();
    } catch (BackingStoreException e) {
        // $NON-NLS-1$
        log.error("Error saving map server preferences", e);
    }
}
Also used : BackingStoreException(java.util.prefs.BackingStoreException) Preferences(java.util.prefs.Preferences)

Aggregations

BackingStoreException (java.util.prefs.BackingStoreException)112 Preferences (java.util.prefs.Preferences)95 NbPreferences (org.openide.util.NbPreferences)14 File (java.io.File)11 IOException (java.io.IOException)10 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)4 AutoCompletePreferences (org.jabref.logic.autocompleter.AutoCompletePreferences)4 FieldContentParserPreferences (org.jabref.logic.bibtex.FieldContentParserPreferences)4 LatexFieldFormatterPreferences (org.jabref.logic.bibtex.LatexFieldFormatterPreferences)4 BibtexKeyPatternPreferences (org.jabref.logic.bibtexkeypattern.BibtexKeyPatternPreferences)4 CleanupPreferences (org.jabref.logic.cleanup.CleanupPreferences)4 ImportFormatPreferences (org.jabref.logic.importer.ImportFormatPreferences)4 JournalAbbreviationPreferences (org.jabref.logic.journals.JournalAbbreviationPreferences)4 LayoutFormatterPreferences (org.jabref.logic.layout.LayoutFormatterPreferences)4 FileLinkPreferences (org.jabref.logic.layout.format.FileLinkPreferences)4 NameFormatterPreferences (org.jabref.logic.layout.format.NameFormatterPreferences)4 ProxyPreferences (org.jabref.logic.net.ProxyPreferences)4 OpenOfficePreferences (org.jabref.logic.openoffice.OpenOfficePreferences)4 ProtectedTermsPreferences (org.jabref.logic.protectedterms.ProtectedTermsPreferences)4