当前位置: 首页>>代码示例>>Java>>正文


Java Preferences.flush方法代码示例

本文整理汇总了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()));
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:AuxiliaryConfigBasedPreferencesProviderTest.java

示例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"));
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:ProxyPreferencesTest.java

示例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);
        }
    }
}
 
开发者ID:Hatzen,项目名称:EasyPeasyVPN,代码行数:27,代码来源:GeneralUtilities.java

示例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"));
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:ProxyPreferencesImplTest.java

示例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);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:FormattingSettingsFromNbPreferences.java

示例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);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:32,代码来源:InstancePropertiesManager.java

示例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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:MarkOccurencesPanel.java

示例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();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:9,代码来源:CheckUserPrefLater.java

示例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 );
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:12,代码来源:FactoryImpl.java

示例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));
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:35,代码来源:AuxiliaryConfigBasedPreferencesProviderTest.java

示例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");

}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:28,代码来源:AuxiliaryConfigBasedPreferencesProviderTest.java

示例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");
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:10,代码来源:MarkOccurrencesTest.java

示例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();
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:6,代码来源:CheckUserPrefFirst.java

示例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);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:42,代码来源:ProxyPreferencesTest.java

示例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());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:AuxiliaryConfigBasedPreferencesProviderTest.java


注:本文中的java.util.prefs.Preferences.flush方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。