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


Java CacheStrategy类代码示例

本文整理汇总了Java中org.apache.commons.vfs2.CacheStrategy的典型用法代码示例。如果您正苦于以下问题:Java CacheStrategy类的具体用法?Java CacheStrategy怎么用?Java CacheStrategy使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


CacheStrategy类属于org.apache.commons.vfs2包,在下文中一共展示了CacheStrategy类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getFileSystemManager

import org.apache.commons.vfs2.CacheStrategy; //导入依赖的package包/类
/**
 * Returns the global filesystem manager
 *
 * @return the global filesystem manager
 */
public static FileSystemManager getFileSystemManager() {
  aLock.readLock().lock();

  try {
    if (fileSystemManager == null) {
      try {
        StandardFileSystemManager fm = new StandardFileSystemManager();
        fm.setCacheStrategy(CacheStrategy.MANUAL);
        fm.init();
        LOGGER.info("Supported schemes: {} ", Joiner.on(", ").join(fm.getSchemes()));
        fileSystemManager = fm;
      } catch (Exception exc) {
        throw new RuntimeException(exc);
      }
    }

    return fileSystemManager;
  } finally {
    aLock.readLock().unlock();
  }
}
 
开发者ID:otros-systems,项目名称:otroslogviewer,代码行数:27,代码来源:VFSUtils.java

示例2: get

import org.apache.commons.vfs2.CacheStrategy; //导入依赖的package包/类
@Override public FileSystemManager get() {
    try {
        final DefaultFileSystemManager manager = new DefaultFileSystemManager();

        manager.setFilesCache(new DefaultFilesCache());
        manager.setCacheStrategy(CacheStrategy.ON_RESOLVE);

        final String baseTmpDir = System.getProperty("java.io.tmpdir");
        final File tempDir = new File(baseTmpDir, "vfs_cache" + new Random().nextLong()).getAbsoluteFile();
        final DefaultFileReplicator replicator = new DefaultFileReplicator(tempDir);
        manager.setTemporaryFileStore(replicator);
        manager.setReplicator(replicator);

        addDefaultProvider(manager);
        addProviders(manager);
        setBaseFile(manager);

        manager.init();

        return manager;
    } catch(FileSystemException e) {
        throw new RuntimeException("Cannot initialize resource service: " + e.getMessage(), e);
    }
}
 
开发者ID:metaborg,项目名称:spoofax,代码行数:25,代码来源:DefaultFileSystemManagerProvider.java

示例3: init

import org.apache.commons.vfs2.CacheStrategy; //导入依赖的package包/类
/**
 * Initializes this manager. Adds the providers and replicator.
 * 
 * @throws FileSystemException
 *             if an error occurs.
 */
@Override
public void init() throws FileSystemException
{
	// Set the replicator and temporary file store (use the same component)
	final DefaultFileReplicator replicator = createDefaultFileReplicator();
	setReplicator(new PrivilegedFileReplicator(replicator));
	setTemporaryFileStore(replicator);

	/*
	 * replaced by findClassLoader if (classLoader == null) { // Use default
	 * classloader classLoader = getClass().getClassLoader(); }
	 */

	if (configUri == null)
	{
		// Use default config
		final URL url = getClass().getResource(CONFIG_RESOURCE);
		if (url == null)
		{
			throw new FileSystemException(
					"vfs.impl/find-config-file.error", CONFIG_RESOURCE);
		}
		configUri = url;
	}

	// Configure
	configure(configUri);

	// Configure Plugins
	// do not use configured plugins. issues when including cifs jars in
	// classpath
	// configurePlugins();
	setCacheStrategy(CacheStrategy.ON_CALL);

	// Initialise super-class
	super.init();
}
 
开发者ID:yajsw,项目名称:yajsw,代码行数:44,代码来源:StandardFileSystemManager.java

示例4: getFileSystemManager

import org.apache.commons.vfs2.CacheStrategy; //导入依赖的package包/类
/**
 * Returns the global filesystem manager
 * @return the global filesystem manager
 */
public static FileSystemManager getFileSystemManager()
{
    aLock.readLock().lock();

    try
    {
        if (fileSystemManager == null)
        {
            try
            {
                StandardFileSystemManager fm = new StandardFileSystemManager();
                fm.setCacheStrategy(CacheStrategy.MANUAL);
                fm.init();
                fileSystemManager = fm;
            }
            catch (Exception exc)
            {
                throw new RuntimeException(exc);
            }
        }

        return fileSystemManager;
    }
    finally
    {
        aLock.readLock().unlock();
    }
}
 
开发者ID:fracpete,项目名称:vfsjfilechooser2,代码行数:33,代码来源:VFSUtils.java

示例5: setUp

import org.apache.commons.vfs2.CacheStrategy; //导入依赖的package包/类
@Override
public void setUp() throws Exception {
    manager = new DefaultFileSystemManager();

    manager.setFilesCache(new SoftRefFilesCache());
    manager.setCacheStrategy(CacheStrategy.ON_RESOLVE);

    manager.addProvider("file", new DefaultLocalFileProvider());
    manager.addProvider("tgz", new TarFileProvider());
    manager.addProvider("tar", new TarFileProvider());

    new File(baseDir).mkdir(); // if test is run standalone
    createLargeFile(largeFilePath, largeFileName);
  }
 
开发者ID:wso2,项目名称:wso2-commons-vfs,代码行数:15,代码来源:LargeTarTestCase.java

示例6: testManualCache

import org.apache.commons.vfs2.CacheStrategy; //导入依赖的package包/类
/**
 * Test the manual cache strategy
 */
public void testManualCache() throws Exception
{
    FileObject scratchFolder = getWriteFolder();
    if (FileObjectUtils.isInstanceOf(getBaseFolder(), RamFileObject.class) ||
        scratchFolder.getFileSystem() instanceof VirtualFileSystem)
    {
        // cant check ram filesystem as every manager holds its own ram filesystem data
        return;
    }

    scratchFolder.delete(Selectors.EXCLUDE_SELF);

    DefaultFileSystemManager fs = createManager();
    fs.setCacheStrategy(CacheStrategy.MANUAL);
    fs.init();
    FileObject foBase2 = getBaseTestFolder(fs);

    FileObject cachedFolder = foBase2.resolveFile(scratchFolder.getName().getPath());

    FileObject[] fos = cachedFolder.getChildren();
    assertContainsNot(fos, "file1.txt");

    scratchFolder.resolveFile("file1.txt").createFile();

    fos = cachedFolder.getChildren();
    assertContainsNot(fos, "file1.txt");

    cachedFolder.refresh();
    fos = cachedFolder.getChildren();
    assertContains(fos, "file1.txt");
}
 
开发者ID:wso2,项目名称:wso2-commons-vfs,代码行数:35,代码来源:ProviderCacheStrategyTests.java

示例7: testOnResolveCache

import org.apache.commons.vfs2.CacheStrategy; //导入依赖的package包/类
/**
 * Test the on_resolve strategy
 */
public void testOnResolveCache() throws Exception
{
    FileObject scratchFolder = getWriteFolder();
    if (FileObjectUtils.isInstanceOf(getBaseFolder(), RamFileObject.class) ||
        scratchFolder.getFileSystem() instanceof VirtualFileSystem)
    {
        // cant check ram filesystem as every manager holds its own ram filesystem data
        return;
    }

    scratchFolder.delete(Selectors.EXCLUDE_SELF);

    DefaultFileSystemManager fs = createManager();
    fs.setCacheStrategy(CacheStrategy.ON_RESOLVE);
    fs.init();
    FileObject foBase2 = getBaseTestFolder(fs);

    FileObject cachedFolder = foBase2.resolveFile(scratchFolder.getName().getPath());

    FileObject[] fos = cachedFolder.getChildren();
    assertContainsNot(fos, "file1.txt");

    scratchFolder.resolveFile("file1.txt").createFile();

    fos = cachedFolder.getChildren();
    assertContainsNot(fos, "file1.txt");

    cachedFolder = foBase2.resolveFile(scratchFolder.getName().getPath());
    fos = cachedFolder.getChildren();
    assertContains(fos, "file1.txt");
}
 
开发者ID:wso2,项目名称:wso2-commons-vfs,代码行数:35,代码来源:ProviderCacheStrategyTests.java

示例8: testOnCallCache

import org.apache.commons.vfs2.CacheStrategy; //导入依赖的package包/类
/**
 * Test the on_call strategy
 */
public void testOnCallCache() throws Exception
{
    FileObject scratchFolder = getWriteFolder();
    if (FileObjectUtils.isInstanceOf(getBaseFolder(), RamFileObject.class) ||
        scratchFolder.getFileSystem() instanceof VirtualFileSystem)
    {
        // cant check ram filesystem as every manager holds its own ram filesystem data
        return;
    }

    scratchFolder.delete(Selectors.EXCLUDE_SELF);

    DefaultFileSystemManager fs = createManager();
    fs.setCacheStrategy(CacheStrategy.ON_CALL);
    fs.init();
    FileObject foBase2 = getBaseTestFolder(fs);

    FileObject cachedFolder = foBase2.resolveFile(scratchFolder.getName().getPath());

    FileObject[] fos = cachedFolder.getChildren();
    assertContainsNot(fos, "file1.txt");

    scratchFolder.resolveFile("file1.txt").createFile();

    fos = cachedFolder.getChildren();
    assertContains(fos, "file1.txt");
}
 
开发者ID:wso2,项目名称:wso2-commons-vfs,代码行数:31,代码来源:ProviderCacheStrategyTests.java

示例9: newFileSystemManager

import org.apache.commons.vfs2.CacheStrategy; //导入依赖的package包/类
@Nonnull
private static FileSystemManager newFileSystemManager() throws FileSystemException {
    StandardFileSystemManager manager = new StandardFileSystemManager();
    manager.setCacheStrategy(CacheStrategy.MANUAL);
    manager.init();
    return manager;
}
 
开发者ID:shevek,项目名称:vfsjfilechooser,代码行数:8,代码来源:CommonsVfs2FileSystemView.java

示例10: setUp

import org.apache.commons.vfs2.CacheStrategy; //导入依赖的package包/类
@Before
public void setUp() throws Exception {

  s3ServiceMock = mock( S3Service.class );
  S3Bucket testBucket = new S3Bucket( BUCKET_NAME );
  S3Object s3Object = new S3Object( OBJECT_NAME );
  StorageObject storageObject = new StorageObject( OBJECT_NAME );

  filename = new S3FileName( SCHEME, HOST, PORT, PORT, awsAccessKey, awsSecretKey, "/" + BUCKET_NAME + "/" + OBJECT_NAME, FileType.FILE, null );
  S3FileName rootFileName = new S3FileName( SCHEME, HOST, PORT, PORT, awsAccessKey, awsSecretKey, "/" + BUCKET_NAME, FileType.FILE, null );
  S3FileSystem fileSystem = new S3FileSystem( rootFileName, new FileSystemOptions() );
  fileSystemSpy = spy( fileSystem );
  VfsComponentContext context = mock( VfsComponentContext.class );
  final DefaultFileSystemManager fsm = new DefaultFileSystemManager();
  FilesCache cache = mock( FilesCache.class );
  fsm.setFilesCache( cache );
  fsm.setCacheStrategy( CacheStrategy.ON_RESOLVE );
  when( context.getFileSystemManager() ).thenReturn( fsm );
  fileSystemSpy.setContext( context );

  S3FileObject s3FileObject = new S3FileObject( filename, fileSystemSpy );
  s3FileObjectSpy = spy( s3FileObject );

  // specify the behaviour of S3 Service
  when( s3ServiceMock.getBucket( BUCKET_NAME ) ).thenReturn( testBucket );
  when( s3ServiceMock.getObject( testBucket, OBJECT_NAME ) ).thenReturn( s3Object );
  when( s3ServiceMock.getObject( BUCKET_NAME, OBJECT_NAME ) ).thenReturn( s3Object );
  when( s3ServiceMock.getObjectDetails( BUCKET_NAME, OBJECT_NAME, null, null, null, null ) ).thenReturn( storageObject );
  when( s3ServiceMock.createBucket( BUCKET_NAME ) ).thenThrow( new S3ServiceException() ); // throw exception if
                                                                                           // bucket exists
  when( fileSystemSpy.getS3Service() ).thenReturn( s3ServiceMock );
  when( s3FileObjectSpy.getS3Bucket() ).thenReturn( testBucket );

}
 
开发者ID:pentaho,项目名称:pentaho-s3-vfs,代码行数:35,代码来源:S3FileObjectTest.java

示例11: processFile

import org.apache.commons.vfs2.CacheStrategy; //导入依赖的package包/类
private synchronized FileObject processFile( FileName name, boolean useCache ) throws FileSystemException {
  if ( !super.getRootName().getRootURI().equals( name.getRootURI() ) ) {
    throw new FileSystemException( "vfs.provider/mismatched-fs-for-name.error",
        new Object[] { name, super.getRootName(), name.getRootURI() } );
  } else {
    FileObject file;
    if ( useCache ) {
      file = super.getFileFromCache( name );
    } else {
      file = null;
    }

    if ( file == null ) {
      try {
        file = this.createFile( (AbstractFileName) name );
      } catch ( Exception var5 ) {
        return null;
      }

      file = super.decorateFileObject( file );
      if ( useCache ) {
        super.putFileToCache( file );
      }
    }

    if ( super.getFileSystemManager().getCacheStrategy().equals( CacheStrategy.ON_RESOLVE ) ) {
      file.refresh();
    }

    return file;
  }
}
 
开发者ID:pentaho,项目名称:pentaho-kettle,代码行数:33,代码来源:GoogleDriveFileSystem.java

示例12: generateVfs

import org.apache.commons.vfs2.CacheStrategy; //导入依赖的package包/类
/**
 * Create a FileSystem manager suitable for our purposes.
 * This manager supports files of the following types:
 * * res - resource files
 * * jar
 * * tar
 * * bz2
 * * tgz
 * * zip
 * * HDFS
 * * FTP
 * * HTTP/S
 * * file
 * @return vfs
 * @throws FileSystemException
 */
public static FileSystemManager generateVfs() throws FileSystemException {
  DefaultFileSystemManager vfs = new DefaultFileSystemManager();
  vfs.addProvider("res", new org.apache.commons.vfs2.provider.res.ResourceFileProvider());
  vfs.addProvider("zip", new org.apache.commons.vfs2.provider.zip.ZipFileProvider());
  vfs.addProvider("gz", new org.apache.commons.vfs2.provider.gzip.GzipFileProvider());
  vfs.addProvider("ram", new org.apache.commons.vfs2.provider.ram.RamFileProvider());
  vfs.addProvider("file", new org.apache.commons.vfs2.provider.local.DefaultLocalFileProvider());
  vfs.addProvider("jar", new org.apache.commons.vfs2.provider.jar.JarFileProvider());
  vfs.addProvider("http", new org.apache.commons.vfs2.provider.http.HttpFileProvider());
  vfs.addProvider("https", new org.apache.commons.vfs2.provider.https.HttpsFileProvider());
  vfs.addProvider("ftp", new org.apache.commons.vfs2.provider.ftp.FtpFileProvider());
  vfs.addProvider("ftps", new org.apache.commons.vfs2.provider.ftps.FtpsFileProvider());
  vfs.addProvider("war", new org.apache.commons.vfs2.provider.jar.JarFileProvider());
  vfs.addProvider("par", new org.apache.commons.vfs2.provider.jar.JarFileProvider());
  vfs.addProvider("ear", new org.apache.commons.vfs2.provider.jar.JarFileProvider());
  vfs.addProvider("sar", new org.apache.commons.vfs2.provider.jar.JarFileProvider());
  vfs.addProvider("ejb3", new org.apache.commons.vfs2.provider.jar.JarFileProvider());
  vfs.addProvider("tmp", new org.apache.commons.vfs2.provider.temp.TemporaryFileProvider());
  vfs.addProvider("tar", new org.apache.commons.vfs2.provider.tar.TarFileProvider());
  vfs.addProvider("tbz2", new org.apache.commons.vfs2.provider.tar.TarFileProvider());
  vfs.addProvider("tgz", new org.apache.commons.vfs2.provider.tar.TarFileProvider());
  vfs.addProvider("bz2", new org.apache.commons.vfs2.provider.bzip2.Bzip2FileProvider());
  vfs.addProvider("hdfs", new HdfsFileProvider());
  vfs.addExtensionMap("jar", "jar");
  vfs.addExtensionMap("zip", "zip");
  vfs.addExtensionMap("gz", "gz");
  vfs.addExtensionMap("tar", "tar");
  vfs.addExtensionMap("tbz2", "tar");
  vfs.addExtensionMap("tgz", "tar");
  vfs.addExtensionMap("bz2", "bz2");
  vfs.addMimeTypeMap("application/x-tar", "tar");
  vfs.addMimeTypeMap("application/x-gzip", "gz");
  vfs.addMimeTypeMap("application/zip", "zip");
  vfs.setFileContentInfoFactory(new FileContentInfoFilenameFactory());
  vfs.setFilesCache(new SoftRefFilesCache());
  vfs.setReplicator(new UniqueFileReplicator(new File(System.getProperty("java.io.tmpdir"))));
  vfs.setCacheStrategy(CacheStrategy.ON_RESOLVE);
  vfs.init();
  return vfs;
}
 
开发者ID:apache,项目名称:metron,代码行数:57,代码来源:VFSClassloaderUtil.java

示例13: resolveFile

import org.apache.commons.vfs2.CacheStrategy; //导入依赖的package包/类
private synchronized FileObject resolveFile(final FileName name, final boolean useCache) throws FileSystemException
{
    FileObject file = null;
    if (name != null) {
        if (!rootName.getRootURI().equals(name.getRootURI()))
        {
            throw new FileSystemException("vfs.provider/mismatched-fs-for-name.error",
                new Object[]{
                    name, rootName, name.getRootURI()});
        }

        // [email protected] ==> use getFileFromCache
        if (useCache)
        {
            file = getFileFromCache(name);
        }
        else
        {
            file = null;
        }
        // FileObject file = (FileObject) files.get(name);
        if (file == null)
        {
            try
            {
                file = createFile((AbstractFileName) name);
            }
            catch (Exception e)
            {
                throw new FileSystemException("vfs.provider/resolve-file.error", name, e);
            }

            file = decorateFileObject(file);

            // [email protected] ==> use putFileToCache
            if (useCache)
            {
                putFileToCache(file);
            }
            // files.put(name, file);
        }

        /**
         * resync the file information if requested
         */
        if (getFileSystemManager().getCacheStrategy().equals(CacheStrategy.ON_RESOLVE))
        {
            file.refresh();
        }
    }
    return file;
}
 
开发者ID:wso2,项目名称:wso2-commons-vfs,代码行数:53,代码来源:AbstractFileSystem.java

示例14: getCacheStrategy

import org.apache.commons.vfs2.CacheStrategy; //导入依赖的package包/类
/**
 * Get the cache strategy used.
 * @return The CacheStrategy.
 */
public CacheStrategy getCacheStrategy()
{
    return fileCacheStrategy;
}
 
开发者ID:wso2,项目名称:wso2-commons-vfs,代码行数:9,代码来源:DefaultFileSystemManager.java

示例15: test

import org.apache.commons.vfs2.CacheStrategy; //导入依赖的package包/类
@Test
public void test()
		// HPFortify FP: unit test not subject to security vulnerability
		throws FileSystemException,
		MalformedURLException {
	DefaultFileSystemManager fsManager = new DefaultFileSystemManager();
	fsManager.setCacheStrategy(CacheStrategy.MANUAL);
	fsManager.setFilesCache(new SoftRefFilesCache());
	fsManager.addProvider(
			"file",
			new DefaultLocalFileProvider());
	fsManager.addProvider(
			"jar",
			new JarFileProvider());
	fsManager.setBaseFile(new File(
			"."));

	// fsManager.addProvider("jar", new JarFileProvider());
	fsManager.init();
	FileObject jarFile = fsManager.resolveFile("jar:src/test/test.jar");

	final VFSClassLoader cl = new VFSClassLoader(
			jarFile,
			fsManager);

	final FileObject[] fileObjs = cl.getFileObjects();
	final URL[] fileUrls = new URL[fileObjs.length];
	for (int i = 0; i < fileObjs.length; i++) {
		fileUrls[i] = new URL(
				fileObjs[i].toString());
	}
	SPIServiceRegistry registry = new SPIServiceRegistry(
			FieldSerializationProviderSpi.class);
	registry.registerLocalClassLoader(java.security.AccessController
			.doPrivileged(new java.security.PrivilegedAction<URLClassLoader>() {
				public URLClassLoader run() {
					final URLClassLoader ucl = new URLClassLoader(
							fileUrls,
							cl);
					return ucl;
				}
			}));

	// Proves that the VFS Classloader SPI loading bug exists
	Iterator<FieldSerializationProviderSpi> it1 = ServiceLoader.load(
			FieldSerializationProviderSpi.class).iterator();
	boolean found = false;
	while (it1.hasNext()) {
		found |= it1.next().getClass().equals(
				BooleanSerializationProvider.class);
	}
	assertFalse(found);

	Iterator<FieldSerializationProviderSpi> it = registry.load(FieldSerializationProviderSpi.class);
	found = false;
	try {
		while (it.hasNext()) {
			found |= it.next().getClass().equals(
					BooleanSerializationProvider.class);
		}
	}
	catch (Throwable ex) {

		assertTrue(ex instanceof NoClassDefFoundError && ex.getLocalizedMessage().contains(
				"FieldSerializationProviderSpi"));
		return;
	}
	assertTrue(
			"The class not found exception is expected since the JAR file was not registered",
			false);
}
 
开发者ID:locationtech,项目名称:geowave,代码行数:72,代码来源:SPIServiceRegistryTest.java


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