本文整理匯總了Java中java.util.prefs.Preferences.flush方法的典型用法代碼示例。如果您正苦於以下問題:Java Preferences.flush方法的具體用法?Java Preferences.flush怎麽用?Java Preferences.flush使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.prefs.Preferences
的用法示例。
在下文中一共展示了Preferences.flush方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: doTestStorage
import java.util.prefs.Preferences; //導入方法依賴的package包/類
private void doTestStorage() throws IOException, BackingStoreException {
AuxiliaryConfiguration ac = p.getLookup().lookup(AuxiliaryConfiguration.class);
AuxiliaryProperties ap = p.getLookup().lookup(AuxiliaryProperties.class);
assertTrue(ac != null || ap != null);
AuxiliaryConfigBasedPreferencesProvider provider = new AuxiliaryConfigBasedPreferencesProvider(p, ac, ap, true);
Preferences pref = provider.findModule("test");
pref.put("test", "test");
pref.node("subnode1/subnode2").put("somekey", "somevalue");
assertEquals(Arrays.asList("somekey"), Arrays.asList(pref.node("subnode1/subnode2").keys()));
pref.flush();
provider = new AuxiliaryConfigBasedPreferencesProvider(p, ac, ap, true);
pref = provider.findModule("test");
assertEquals("test", pref.get("test", null));
assertEquals("somevalue", pref.node("subnode1/subnode2").get("somekey", null));
assertEquals(Arrays.asList("somekey"), Arrays.asList(pref.node("subnode1/subnode2").keys()));
pref.node("subnode1/subnode2").remove("somekey");
assertEquals(Arrays.<String>asList(), Arrays.asList(pref.node("subnode1/subnode2").keys()));
}
示例2: testRemoveNode
import java.util.prefs.Preferences; //導入方法依賴的package包/類
public void testRemoveNode() throws BackingStoreException {
Preferences orig = Preferences.userRoot().node(getName());
Preferences origChild = orig.node("child");
Preferences test = ProxyPreferences.getProxyPreferences(this, orig);
assertTrue("Test child shoculd exist", test.nodeExists("child"));
Preferences testChild = test.node("child");
testChild.removeNode();
assertFalse("Removed test child should not exist", testChild.nodeExists(""));
assertFalse("Removed test child should not exist in parent", test.nodeExists("child"));
test.flush();
assertFalse("Test.flush did not remove orig child", origChild.nodeExists(""));
assertFalse("Test.flush did not remove orig child from parent", orig.nodeExists("child"));
}
示例3: isAdmin
import java.util.prefs.Preferences; //導入方法依賴的package包/類
/**
* Checks if the program was launched with admin permissions.
* https://stackoverflow.com/questions/4350356/detect-if-java-application-was-run-as-a-windows-admin
* @return true if program has admin permissions.
*/
public static boolean isAdmin(){
Preferences preferences = Preferences.systemRoot();
PrintStream systemErr = System.err;
// Better synchronize to avoid problems with other threads that access System.err.
synchronized(systemErr){
System.setErr(null);
try {
// SecurityException on Windows.
preferences.put("foo", "bar");
preferences.remove("foo");
// BackingStoreException on Linux.
preferences.flush();
return true;
} catch(Exception e) {
return false;
} finally{
System.setErr(systemErr);
}
}
}
示例4: testRemoveNode
import java.util.prefs.Preferences; //導入方法依賴的package包/類
public void testRemoveNode() throws BackingStoreException {
Preferences orig = Preferences.userRoot().node(getName());
Preferences origChild = orig.node("child");
Preferences test = ProxyPreferencesImpl.getProxyPreferences(this, orig);
assertTrue("Test child shoculd exist", test.nodeExists("child"));
Preferences testChild = test.node("child");
testChild.removeNode();
assertFalse("Removed test child should not exist", testChild.nodeExists(""));
assertFalse("Removed test child should not exist in parent", test.nodeExists("child"));
test.flush();
assertFalse("Test.flush did not remove orig child", origChild.nodeExists(""));
assertFalse("Test.flush did not remove orig child from parent", orig.nodeExists("child"));
}
示例5: beforeSave
import java.util.prefs.Preferences; //導入方法依賴的package包/類
@Override
public void beforeSave(Map<String, TypedValue> map, MimePath mimePath, String profile, boolean defaults) throws IOException {
if (defaults || mimePath.size() != 1 || !affectedMimeTypes.containsKey(mimePath.getPath())) {
return;
}
try {
Preferences nbprefs = getNbPreferences(mimePath.getPath());
if (nbprefs != null && nbprefs.nodeExists("CodeStyle/default")) { //NOI18N
// We loaded the settings from NbPreferences in beforeLoad,
// they are in the map (maybe modified somehow) and they are
// going to be saved to MimeLookup. So we can safely clean them up from NbPreferences.
nbprefs.node("CodeStyle").removeNode(); //NOI18N
nbprefs.flush();
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("Cleaning up NbPreferences/CodeStyle node for '" + mimePath.getPath() + "'"); //NOI18N
}
}
} catch (BackingStoreException bse) {
// ignore
LOG.log(Level.FINE, null, bse);
}
}
示例6: getProperties
import java.util.prefs.Preferences; //導入方法依賴的package包/類
/**
* Returns all existing properties created in the given namespace.
*
* @param namespace string identifying the namespace
* @return list of all existing properties created in the given namespace
*/
public List<InstanceProperties> getProperties(String namespace) {
Preferences prefs = NbPreferences.forModule(InstancePropertiesManager.class);
try {
prefs = prefs.node(namespace);
prefs.flush();
List<InstanceProperties> allProperties = new ArrayList<InstanceProperties>();
synchronized (this) {
for (String id : prefs.childrenNames()) {
Preferences child = prefs.node(id);
InstanceProperties props = cache.get(child);
if (props == null) {
props = new DefaultInstanceProperties(id, this, child);
cache.put(child, props);
}
allProperties.add(props);
}
}
return allProperties;
} catch (BackingStoreException ex) {
LOGGER.log(Level.INFO, null, ex);
throw new IllegalStateException(ex);
}
}
示例7: store
import java.util.prefs.Preferences; //導入方法依賴的package包/類
public void store( ) {
Preferences node = MarkOccurencesSettings.getCurrentNode();
for (javax.swing.JCheckBox box : boxes) {
boolean value = box.isSelected();
boolean original = node.getBoolean(box.getActionCommand(),
DEFAULT_VALUE);
if (value != original) {
node.putBoolean(box.getActionCommand(), value);
}
}
try {
node.flush();
}
catch (BackingStoreException ex) {
Exceptions.printStackTrace(ex);
}
changed = false;
}
示例8: main
import java.util.prefs.Preferences; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
Preferences prefs = Preferences.userNodeForPackage(CheckUserPrefFirst.class);
String result = prefs.get("Check", null);
if ((result == null) || !(result.equals("Success")))
throw new RuntimeException("User pref not stored!");
prefs.remove("Check");
prefs.flush();
}
示例9: addFile
import java.util.prefs.Preferences; //導入方法依賴的package包/類
public void addFile ( final String fileName ) throws Exception
{
final File file = new File ( fileName ).getAbsoluteFile ();
final Preferences newChild = this.prefs.node ( UUID.randomUUID ().toString () );
newChild.put ( "file", file.toString () );
newChild.flush ();
this.files.add ( fileName );
loadFile ( fileName );
}
示例10: doTestSubnodes
import java.util.prefs.Preferences; //導入方法依賴的package包/類
private void doTestSubnodes() throws IOException, BackingStoreException {
AuxiliaryConfiguration ac = p.getLookup().lookup(AuxiliaryConfiguration.class);
AuxiliaryProperties ap = p.getLookup().lookup(AuxiliaryProperties.class);
assertTrue(ac != null || ap != null);
AuxiliaryConfigBasedPreferencesProvider provider = new AuxiliaryConfigBasedPreferencesProvider(p, ac, ap, true);
Preferences pref = provider.findModule("test");
pref.put("test", "test");
pref.node("subnode1/subnode2").put("somekey", "somevalue1");
pref.node("subnode1").put("somekey", "somevalue2");
pref.flush();
provider = new AuxiliaryConfigBasedPreferencesProvider(p, ac, ap, true);
pref = provider.findModule("test");
assertTrue(pref.node("subnode1").nodeExists("subnode2"));
assertEquals("somevalue1", pref.node("subnode1/subnode2").get("somekey", null));
assertEquals("somevalue2", pref.node("subnode1").get("somekey", null));
pref.node("subnode1").removeNode();
assertEquals(null, pref.node("subnode1/subnode2").get("somekey", null));
assertEquals(null, pref.node("subnode1").get("somekey", null));
pref.flush();
provider = new AuxiliaryConfigBasedPreferencesProvider(p, ac, ap, true);
pref = provider.findModule("test");
assertEquals(null, pref.node("subnode1/subnode2").get("somekey", null));
assertEquals(null, pref.node("subnode1").get("somekey", null));
}
示例11: testTooLong
import java.util.prefs.Preferences; //導入方法依賴的package包/類
public void testTooLong() throws IOException, BackingStoreException {
lookup.setDelegates(Lookups.fixed(new TestAuxiliaryConfigurationImpl()));
AuxiliaryConfiguration ac = p.getLookup().lookup(AuxiliaryConfiguration.class);
assertNotNull(ac);
AuxiliaryConfigBasedPreferencesProvider toSync = new AuxiliaryConfigBasedPreferencesProvider(p, ac, null, true);
Preferences pref = toSync.findModule("test");
//test length of key
char[] keyChars = new char[100];
Arrays.fill(keyChars, 'X');
String key = new String(keyChars);
pref.put(key, "test");
//test length of value
char[] valChars = new char[10 * 1024];
Arrays.fill(valChars, 'X');
String value = new String(valChars);
pref.put("test", value);
pref.flush();
assertEquals(pref.get("test", null), value);
assertEquals(pref.get(key, null), "test");
}
示例12: setAndFlush
import java.util.prefs.Preferences; //導入方法依賴的package包/類
private void setAndFlush(String key,boolean value) {
try {
Preferences pref = MarkOccurencesSettings.getCurrentNode();
pref.putBoolean(key, value);
pref.flush();
} catch (BackingStoreException ex) {
fail("Error while storing settings");
}
}
示例13: main
import java.util.prefs.Preferences; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
Preferences prefs = Preferences.userNodeForPackage(CheckUserPrefFirst.class);
prefs.put("Check", "Success");
prefs.flush();
}
示例14: testRemoveHierarchy
import java.util.prefs.Preferences; //導入方法依賴的package包/類
public void testRemoveHierarchy() throws BackingStoreException {
String [] origTree = new String [] {
"R.CodeStyle.project.expand-tabs=true",
"R.CodeStyle.project.indent-shift-width=6",
"R.CodeStyle.project.spaces-per-tab=6",
"R.CodeStyle.project.tab-size=7",
"R.CodeStyle.project.text-limit-width=88",
"R.CodeStyle.usedProfile=project",
"R.text.x-ruby.CodeStyle.project.indent-shift-width=2",
"R.text.x-ruby.CodeStyle.project.spaces-per-tab=2",
"R.text.x-ruby.CodeStyle.project.tab-size=2",
};
String [] newTree = new String [] {
"R.CodeStyle.project.expand-tabs=true",
"R.CodeStyle.project.indent-shift-width=3",
"R.CodeStyle.project.spaces-per-tab=3",
"R.CodeStyle.project.tab-size=5",
"R.CodeStyle.project.text-limit-width=77",
"R.CodeStyle.usedProfile=project",
"R.text.x-ruby.CodeStyle.project.indent-shift-width=2",
"R.text.x-ruby.CodeStyle.project.spaces-per-tab=2",
"R.text.x-ruby.CodeStyle.project.tab-size=2",
};
Preferences orig = Preferences.userRoot().node(getName());
write(orig, origTree);
checkContains(orig, origTree, "Orig");
Preferences test = ProxyPreferences.getProxyPreferences(this, orig);
checkEquals("Test should be the same as Orig", orig, test);
Preferences testRoot = test.node("R");
removeAllKidsAndKeys(testRoot);
write(test, newTree);
checkContains(test, newTree, "Test");
test.flush();
checkEquals("Test didn't flush to Orig", test, orig);
}
示例15: testNoSaveWhenNotModified
import java.util.prefs.Preferences; //導入方法依賴的package包/類
public void testNoSaveWhenNotModified() throws IOException, BackingStoreException {
lookup.setDelegates(Lookups.fixed(new TestAuxiliaryConfigurationImpl()));
AuxiliaryConfiguration ac = p.getLookup().lookup(AuxiliaryConfiguration.class);
assertNotNull(ac);
final AtomicInteger putCount = new AtomicInteger();
ac = new CountingAuxiliaryConfiguration(ac, putCount);
AuxiliaryConfigBasedPreferencesProvider provider = new AuxiliaryConfigBasedPreferencesProvider(p, ac, null, true);
Preferences pref = provider.findModule("test");
pref.put("test", "test");
pref.node("subnode1/subnode2").put("somekey", "somevalue");
assertEquals(0, putCount.get());
pref.flush();
assertEquals(1, putCount.get());
pref.flush();
assertEquals(1, putCount.get());
}