use of java.util.prefs.BackingStoreException in project JMRI by JMRI.
the class RosterConfigManager method savePreferences.
@Override
public void savePreferences(Profile profile) {
Preferences preferences = ProfileUtils.getPreferences(profile, this.getClass(), true);
preferences.put(DIRECTORY, FileUtil.getPortableFilename(this.getDirectory()));
preferences.put(DEFAULT_OWNER, this.getDefaultOwner());
try {
preferences.sync();
} catch (BackingStoreException ex) {
log.error("Unable to save preferences", ex);
}
}
use of java.util.prefs.BackingStoreException in project JMRI by JMRI.
the class LnTcpPreferences method savePreferences.
public void savePreferences() {
Preferences sharedPreferences = ProfileUtils.getPreferences(this.getProfile(), this.getClass(), true);
sharedPreferences.putInt(PORT, this.getPort());
try {
sharedPreferences.sync();
// Resets only when stored
setIsDirty(false);
} catch (BackingStoreException ex) {
log.error("Exception while saving web server preferences", ex);
}
}
use of java.util.prefs.BackingStoreException in project JMRI by JMRI.
the class LnTcpPreferences method readPreferences.
private void readPreferences(Preferences sharedPreferences) {
boolean migrate = false;
try {
if (sharedPreferences.keys().length == 0) {
log.debug("No LocoNetOverTCP preferences exist.");
migrate = true;
}
} catch (BackingStoreException ex) {
log.debug("No preferences file exists.");
migrate = true;
}
if (!migrate) {
this.port = sharedPreferences.getInt(PORT, this.getPort());
this.setIsDirty(false);
} else {
Properties settings = new Properties();
File file = new File(FileUtil.getUserFilesPath(), SETTINGS_FILE_NAME);
log.debug("Opening settings file {}", file);
try (FileInputStream stream = new FileInputStream(file)) {
settings.load(stream);
this.port = Integer.parseInt(settings.getProperty(PORT_NUMBER_KEY, Integer.toString(this.getPort())));
this.setIsDirty(true);
} catch (FileNotFoundException ex) {
log.debug("old preferences file not found");
} catch (IOException ex) {
log.debug("exception reading old preferences file", ex);
}
}
}
use of java.util.prefs.BackingStoreException in project JMRI by JMRI.
the class WebServerPreferences method save.
public void save() {
Preferences sharedPreferences = ProfileUtils.getPreferences(this.getProfile(), this.getClass(), true);
sharedPreferences.putInt(PORT, this.getPort());
sharedPreferences.putInt(CLICK_DELAY, this.getClickDelay());
sharedPreferences.putInt(REFRESH_DELAY, this.getRefreshDelay());
sharedPreferences.putBoolean(USE_AJAX, this.isUseAjax());
sharedPreferences.putBoolean(SIMPLE, this.isSimple());
sharedPreferences.putBoolean(ALLOW_REMOTE_CONFIG, this.allowRemoteConfig());
sharedPreferences.putBoolean(READONLY_POWER, this.isReadonlyPower());
sharedPreferences.put(RAILROAD_NAME, getRailRoadName());
sharedPreferences.putBoolean(DISABLE_FRAME_SERVER, this.isDisableFrames());
sharedPreferences.putBoolean(REDIRECT_FRAMES, this.redirectFramesToPanels);
try {
Preferences node = sharedPreferences.node(DISALLOWED_FRAMES);
this.disallowedFrames.stream().forEach((frame) -> {
node.put(Integer.toString(this.disallowedFrames.indexOf(frame)), frame);
});
if (this.disallowedFrames.size() < node.keys().length) {
for (int i = node.keys().length - 1; i >= this.disallowedFrames.size(); i--) {
node.remove(Integer.toString(i));
}
}
sharedPreferences.sync();
// Resets only when stored
setIsDirty(false);
} catch (BackingStoreException ex) {
log.error("Exception while saving web server preferences", ex);
}
}
use of java.util.prefs.BackingStoreException in project JMRI by JMRI.
the class WebServerPreferences method readPreferences.
private void readPreferences(Preferences sharedPreferences) {
this.allowRemoteConfig = sharedPreferences.getBoolean(ALLOW_REMOTE_CONFIG, this.allowRemoteConfig);
this.clickDelay = sharedPreferences.getInt(CLICK_DELAY, this.clickDelay);
this.simple = sharedPreferences.getBoolean(SIMPLE, this.simple);
this.railRoadName = sharedPreferences.get(RAILROAD_NAME, this.railRoadName);
this.readonlyPower = sharedPreferences.getBoolean(READONLY_POWER, this.readonlyPower);
this.refreshDelay = sharedPreferences.getInt(REFRESH_DELAY, this.refreshDelay);
this.useAjax = sharedPreferences.getBoolean(USE_AJAX, this.useAjax);
this.disableFrames = sharedPreferences.getBoolean(DISABLE_FRAME_SERVER, this.disableFrames);
this.redirectFramesToPanels = sharedPreferences.getBoolean(REDIRECT_FRAMES, this.redirectFramesToPanels);
try {
Preferences frames = sharedPreferences.node(DISALLOWED_FRAMES);
if (frames.keys().length != 0) {
this.disallowedFrames.clear();
for (String key : frames.keys()) {
// throws BackingStoreException
String frame = frames.get(key, null);
if (frame != null && !frame.trim().isEmpty()) {
this.disallowedFrames.add(frame);
}
}
}
} catch (BackingStoreException ex) {
// this is expected if sharedPreferences have not been written previously,
// so do nothing.
}
this.port = sharedPreferences.getInt(PORT, this.port);
this.setIsDirty(false);
}
Aggregations