Java 类org.jivesoftware.smackx.caps.cache.SimpleDirectoryPersistentCache 实例源码

项目:Smack    文件:EntityCapsManagerTest.java   
private void testSimpleDirectoryCache(StringEncoder stringEncoder) throws IOException {

        EntityCapsPersistentCache cache = new SimpleDirectoryPersistentCache(createTempDirectory());
        EntityCapsManager.setPersistentCache(cache);

        DiscoverInfo di = createComplexSamplePacket();
        CapsVersionAndHash versionAndHash = EntityCapsManager.generateVerificationString(di, StringUtils.SHA1);
        String nodeVer = di.getNode() + "#" + versionAndHash.version;

        // Save the data in EntityCapsManager
        EntityCapsManager.addDiscoverInfoByNode(nodeVer, di);

        // Lose all the data
        EntityCapsManager.clearMemoryCache();

        DiscoverInfo restored_di = EntityCapsManager.getDiscoveryInfoByNodeVer(nodeVer);
        assertNotNull(restored_di);
        assertEquals(di.toXML().toString(), restored_di.toXML().toString());
    }
项目:desktopclient-java    文件:Client.java   
private Client(Control control, Path appDir) {
    mControl = control;
    //mLimited = limited;

    mMessageSender = new KonMessageSender(this);

    // enable Smack debugging (print raw XML packets)
    //SmackConfiguration.DEBUG = true;

    mFeatures = new EnumMap<>(FeatureDiscovery.Feature.class);

    // setting caps cache
    // NOTE: the cache is actually not used right now: only client entity requests (==full JIDs)
    // can be cached
    File cacheDir = appDir.resolve(CAPS_CACHE_DIR).toFile();
    if (cacheDir.mkdir())
        LOGGER.info("created caps cache directory");

    if (!cacheDir.isDirectory()) {
        LOGGER.warning("invalid cache directory: "+cacheDir);
        return;
    }

    EntityCapsManager.setPersistentCache(
            new SimpleDirectoryPersistentCache(cacheDir));
}