Search in sources :

Example 1 with SafeFileOutputStream

use of org.eclipse.core.internal.preferences.SafeFileOutputStream in project che by eclipse.

the class ChePreferences method write.

/*
 * Helper method to persist a Properties object to the filesystem. We use this
 * helper so we can remove the date/timestamp that Properties#store always
 * puts in the file.
 */
protected static void write(Properties properties, String location) throws BackingStoreException {
    // create the parent directories if they don't exist
    //        File parentFile = new File(location);
    //        if (parentFile == null)
    //            return;
    //        parentFile.mkdirs();
    OutputStream output = null;
    try {
        File file = new File(location);
        if (!file.exists()) {
            File parentFile = file.getParentFile();
            if (!parentFile.exists()) {
                parentFile.mkdirs();
            }
            file.createNewFile();
        }
        output = new SafeFileOutputStream(file);
        //$NON-NLS-1$
        output.write(removeTimestampFromTable(properties).getBytes("UTF-8"));
        output.flush();
    } catch (IOException e) {
        //            String message = NLS.bind(PrefsMessages.preferences_saveException, location);
        ResourcesPlugin.log(new Status(IStatus.ERROR, PrefsMessages.OWNER_NAME, IStatus.ERROR, "preferences_saveException", e));
        throw new BackingStoreException("preferences_saveException");
    } finally {
        if (output != null)
            try {
                output.close();
            } catch (IOException e) {
            // ignore
            }
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SafeFileOutputStream(org.eclipse.core.internal.preferences.SafeFileOutputStream) OutputStream(java.io.OutputStream) BackingStoreException(org.osgi.service.prefs.BackingStoreException) IOException(java.io.IOException) SafeFileOutputStream(org.eclipse.core.internal.preferences.SafeFileOutputStream) File(java.io.File)

Aggregations

ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 SafeFileOutputStream (org.eclipse.core.internal.preferences.SafeFileOutputStream)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 BackingStoreException (org.osgi.service.prefs.BackingStoreException)1