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


Java FileSystemProvider类代码示例

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


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

示例1: ArchiveContainer

import java.nio.file.spi.FileSystemProvider; //导入依赖的package包/类
public ArchiveContainer(Path archivePath) throws IOException, ProviderNotFoundException, SecurityException {
    this.archivePath = archivePath;
    if (multiReleaseValue != null && archivePath.toString().endsWith(".jar")) {
        Map<String,String> env = Collections.singletonMap("multi-release", multiReleaseValue);
        FileSystemProvider jarFSProvider = fsInfo.getJarFSProvider();
        Assert.checkNonNull(jarFSProvider, "should have been caught before!");
        this.fileSystem = jarFSProvider.newFileSystem(archivePath, env);
    } else {
        this.fileSystem = FileSystems.newFileSystem(archivePath, null);
    }
    packages = new HashMap<>();
    for (Path root : fileSystem.getRootDirectories()) {
        Files.walkFileTree(root, EnumSet.noneOf(FileVisitOption.class), Integer.MAX_VALUE,
                new SimpleFileVisitor<Path>() {
                    @Override
                    public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) {
                        if (isValid(dir.getFileName())) {
                            packages.put(new RelativeDirectory(root.relativize(dir).toString()), dir);
                            return FileVisitResult.CONTINUE;
                        } else {
                            return FileVisitResult.SKIP_SUBTREE;
                        }
                    }
                });
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:27,代码来源:JavacFileManager.java

示例2: getJRTFS

import java.nio.file.spi.FileSystemProvider; //导入依赖的package包/类
@CheckForNull
public static Path getJRTFS() throws IOException {
    final File java9 = getJava9Home();
    if (java9 == null) {
        return null;
    }
    final File jrtFsProvider = new File(java9,"jrt-fs.jar"); //NOI18N
    if (jrtFsProvider.exists() && jrtFsProvider.isFile() && jrtFsProvider.canRead()) {
        final ClassLoader cl = new URLClassLoader(new URL[]{
            BaseUtilities.toURI(jrtFsProvider).toURL()
        });
        final ServiceLoader<FileSystemProvider> sl = ServiceLoader.load(FileSystemProvider.class, cl);
        FileSystemProvider jrtp = null;
        for (FileSystemProvider fsp : sl) {
            if ("jrt".equals(fsp.getScheme())) {    //NOI18N
                jrtp = fsp;
                break;
            }
        }
        if (jrtp != null) {
            return jrtp.getPath(URI.create("jrt:/"));   //NOI18N
        }
    }
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:TestUtilities.java

示例3: newFileSystem

import java.nio.file.spi.FileSystemProvider; //导入依赖的package包/类
private FileSystem newFileSystem(String targetHome, URI uri, Map<String, ?> env)
        throws IOException {
    Objects.requireNonNull(targetHome);
    Path jrtfs = FileSystems.getDefault().getPath(targetHome, "lib", JRT_FS_JAR);
    if (Files.notExists(jrtfs)) {
        throw new IOException(jrtfs.toString() + " not exist");
    }
    Map<String,?> newEnv = new HashMap<>(env);
    newEnv.remove("java.home");
    ClassLoader cl = newJrtFsLoader(jrtfs);
    try {
        Class<?> c = Class.forName(JrtFileSystemProvider.class.getName(), false, cl);
        @SuppressWarnings("deprecation")
        Object tmp = c.newInstance();
        return ((FileSystemProvider)tmp).newFileSystem(uri, newEnv);
    } catch (ClassNotFoundException |
             IllegalAccessException |
             InstantiationException e) {
        throw new IOException(e);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:JrtFileSystemProvider.java

示例4: newFileSystem

import java.nio.file.spi.FileSystemProvider; //导入依赖的package包/类
private FileSystem newFileSystem(String targetHome, URI uri, Map<String, ?> env)
        throws IOException {
    Objects.requireNonNull(targetHome);
    Path jrtfs = FileSystems.getDefault().getPath(targetHome, JRT_FS_JAR);
    if (Files.notExists(jrtfs)) {
        throw new IOException(jrtfs.toString() + " not exist");
    }
    Map<String,?> newEnv = new HashMap<>(env);
    newEnv.remove("java.home");
    ClassLoader cl = newJrtFsLoader(jrtfs);
    try {
        Class<?> c = Class.forName(JrtFileSystemProvider.class.getName(), false, cl);
        @SuppressWarnings("deprecation")
        Object tmp = c.newInstance();
        return ((FileSystemProvider)tmp).newFileSystem(uri, newEnv);
    } catch (ClassNotFoundException |
             IllegalAccessException |
             InstantiationException e) {
        throw new IOException(e);
    }
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:22,代码来源:JrtFileSystemProvider.java

示例5: deletePath

import java.nio.file.spi.FileSystemProvider; //导入依赖的package包/类
private boolean deletePath(FileSystemProvider provider, Path path) {
	// Simple file delete
   	try {
		if (provider.deleteIfExists(path)) {
			System.out.println("Deleted path '" + path.toAbsolutePath() + "'");
		} else {
			System.err.println("Could not delete path '" + path.toAbsolutePath() + "', it may not exist");
		}
	} catch (Exception e) {
		System.err.println("Could not delete path '" + path.toAbsolutePath() + "': " + e.getMessage());
		e.printStackTrace();
		return false;
	}
   	
   	return true;
}
 
开发者ID:brdara,项目名称:java-cloud-filesystem-provider,代码行数:17,代码来源:DeleteCommand.java

示例6: createCloudFileSystem

import java.nio.file.spi.FileSystemProvider; //导入依赖的package包/类
@Override
public CloudFileSystem createCloudFileSystem(FileSystemProvider provider, URI uri, Map<String, ?> env) {
	String cloudType = (String)env.get(CLOUD_TYPE_ENV);
	if (StringUtils.isBlank(cloudType)) {
		throw new IllegalArgumentException("The file system map must contain a '" + CLOUD_TYPE_ENV + "' which identifies the " +
				"cloud type to target. Accepted cloud types are: " + CloudHostConfigurationBuilder.getAllCloudHostSettingTypes());
	}

	// Filter out the cloudType parameter
    Map<String,?> remainingEnv = 
    		env.entrySet()
            .stream()
            .filter(p -> !p.getKey().equals(CLOUD_TYPE_ENV))
            .collect(Collectors.toMap(p -> p.getKey(), p -> p.getValue()));

    LOG.debug("Creating cloud host settings for environment type '{}', filesystem host '{}'", cloudType, uri.getHost());
    CloudHostConfiguration config = new CloudHostConfigurationBuilder()
		.setType(cloudType)
		.setName(uri.getHost())
		.setAttributes(remainingEnv)
		.build();
    LOG.debug("Created cloud host settings for environment type '{}', filesystem host '{}'", cloudType, uri.getHost());

    return createCloudFilesystemInternal(provider, config);
}
 
开发者ID:brdara,项目名称:java-cloud-filesystem-provider,代码行数:26,代码来源:JCloudsCloudHostProvider.java

示例7: getFileSystem

import java.nio.file.spi.FileSystemProvider; //导入依赖的package包/类
/**
 * Retrieves a file system using the default {@link FileSystems#getFileSystem(URI)}. If this
 * throws a 
 * @param uri
 * @return
 */
public static FileSystem getFileSystem(URI uri) {
	try {
		return FileSystems.getFileSystem(uri);
	} catch (FileSystemNotFoundException | ProviderNotFoundException e) {
		LOG.debug("File system scheme " + uri.getScheme() +
				" not found in the default installed providers list, attempting to find this in the "
				+ "list of additional providers");
	}

	for (WeakReference<FileSystemProvider> providerRef : providers) {
		FileSystemProvider provider = providerRef.get();
		
		if (provider != null && uri.getScheme().equals(provider.getScheme())) {
			return provider.getFileSystem(uri);
		}
	}
	
	throw new ProviderNotFoundException("Could not find provider for scheme '" + uri.getScheme() + "'");
}
 
开发者ID:brdara,项目名称:java-cloud-filesystem-provider,代码行数:26,代码来源:FileSystemProviderHelper.java

示例8: testCreateCloudFileSystemInternalWillCreateTheFileSystemIfItHasntBeenCreatedYet

import java.nio.file.spi.FileSystemProvider; //导入依赖的package包/类
@Test
public void testCreateCloudFileSystemInternalWillCreateTheFileSystemIfItHasntBeenCreatedYet() {
	CloudHostConfiguration config = context.mock(CloudHostConfiguration.class);
	FileSystemProvider provider = context.mock(FileSystemProvider.class);
	BlobStoreContext blobStoreContext = context.mock(BlobStoreContext.class);

	context.checking(new Expectations() {{
		allowing(config).getName();
		will(returnValue("test-config"));
		
		exactly(1).of(config).createBlobStoreContext();
		will(returnValue(blobStoreContext));
	}});

	Assert.assertTrue(((Map<?,?>)WhiteboxImpl.getInternalState(impl, "cloudFileSystems")).isEmpty());
	impl.createCloudFilesystemInternal(provider, config);
	Map<String,CloudFileSystem> cloudFileSystemsMap =
			((Map<String,CloudFileSystem>)WhiteboxImpl.getInternalState(impl, "cloudFileSystems"));
	Assert.assertTrue(cloudFileSystemsMap.containsKey("test-config"));
	Assert.assertNotNull(cloudFileSystemsMap.get("test-config"));
}
 
开发者ID:brdara,项目名称:java-cloud-filesystem-provider,代码行数:22,代码来源:JCloudsCloudHostProviderTest.java

示例9: testCreateCloudFileSystemInternalWillThrowAnErrorIfAnAttemptIsMadeToCreateTheFilesystemMoreThanOnce

import java.nio.file.spi.FileSystemProvider; //导入依赖的package包/类
@Test
public void testCreateCloudFileSystemInternalWillThrowAnErrorIfAnAttemptIsMadeToCreateTheFilesystemMoreThanOnce() {
	CloudHostConfiguration config = context.mock(CloudHostConfiguration.class);
	FileSystemProvider provider = context.mock(FileSystemProvider.class);
	BlobStoreContext blobStoreContext = context.mock(BlobStoreContext.class);

	context.checking(new Expectations() {{
		allowing(config).getName();
		will(returnValue("test-config"));
		
		exactly(1).of(config).createBlobStoreContext();
		will(returnValue(blobStoreContext));
	}});

	impl.createCloudFilesystemInternal(provider, config);
	
	try {
		impl.createCloudFilesystemInternal(provider, config);
		Assert.fail("Expected an exception");
	} catch (DuplicateCloudHostnameException e) {
		// OK
	}
}
 
开发者ID:brdara,项目名称:java-cloud-filesystem-provider,代码行数:24,代码来源:JCloudsCloudHostProviderTest.java

示例10: testCreateCloudFileSystemInternalWillAllowTheFileSystemToBeCreatedAgainAfterItHasBeenClosed

import java.nio.file.spi.FileSystemProvider; //导入依赖的package包/类
@Test
public void testCreateCloudFileSystemInternalWillAllowTheFileSystemToBeCreatedAgainAfterItHasBeenClosed() throws IOException {
	CloudHostConfiguration config = context.mock(CloudHostConfiguration.class);
	FileSystemProvider provider = context.mock(FileSystemProvider.class);
	BlobStoreContext blobStoreContext = context.mock(BlobStoreContext.class);

	context.checking(new Expectations() {{
		allowing(config).getName();
		will(returnValue("test-config"));
		
		exactly(2).of(config).createBlobStoreContext();
		will(returnValue(blobStoreContext));
		
		exactly(1).of(blobStoreContext).close();
	}});

	// Create and close
	CloudFileSystem fs = impl.createCloudFilesystemInternal(provider, config);
	fs.close();
	
	// Should now be able to create again
	CloudFileSystem fs2 = impl.createCloudFilesystemInternal(provider, config);
	Assert.assertNotEquals(fs, fs2);
}
 
开发者ID:brdara,项目名称:java-cloud-filesystem-provider,代码行数:25,代码来源:JCloudsCloudHostProviderTest.java

示例11: testCreateCloudFileSystemWillUseTheCloudHostConfigurationBuilderToCreateACloudFileSystem

import java.nio.file.spi.FileSystemProvider; //导入依赖的package包/类
@Test
public void testCreateCloudFileSystemWillUseTheCloudHostConfigurationBuilderToCreateACloudFileSystem() throws URISyntaxException, IOException {
	FileSystemProvider provider = context.mock(FileSystemProvider.class);
	URI uri = new URI("cloud", "mock-fs", "/path", "fragment"); // The host holds the name
	Map<String,Object> env = new HashMap<>();
	env.put(JCloudsCloudHostProvider.CLOUD_TYPE_ENV, "mock-test");

	// Test we can create the FS
	Assert.assertTrue(((Map<?,?>)WhiteboxImpl.getInternalState(impl, "cloudFileSystems")).isEmpty());
	impl.createCloudFileSystem(provider, uri, env);
	Map<String,CloudFileSystem> cloudFileSystemsMap =
			((Map<String,CloudFileSystem>)WhiteboxImpl.getInternalState(impl, "cloudFileSystems"));
	Assert.assertTrue(cloudFileSystemsMap.containsKey("mock-fs"));
	Assert.assertNotNull(cloudFileSystemsMap.get("mock-fs"));

	// Now get the FS back
	CloudFileSystem cloudFileSystem = impl.getCloudFileSystem(uri);
	Assert.assertNotNull(cloudFileSystem);
	Assert.assertEquals(provider, cloudFileSystem.provider());
	Assert.assertEquals(MockCloudHostConfiguration.class, cloudFileSystem.getCloudHostConfiguration().getClass());
	Assert.assertEquals("mock-fs", cloudFileSystem.getCloudHostConfiguration().getName());
	
	// Close it and make sure we don't get it back
	cloudFileSystem.close();
	Assert.assertNull(impl.getCloudFileSystem(uri));
}
 
开发者ID:brdara,项目名称:java-cloud-filesystem-provider,代码行数:27,代码来源:JCloudsCloudHostProviderTest.java

示例12: mockStorageTypeAttributes

import java.nio.file.spi.FileSystemProvider; //导入依赖的package包/类
protected CloudBasicFileAttributes mockStorageTypeAttributes(CloudFileSystem fs, final StorageType storageType, final Path path) throws IOException {
	final FileSystemProvider provider = context.mock(FileSystemProvider.class);
	final CloudBasicFileAttributes basicAttributes = storageType == null ? null : context.mock(CloudBasicFileAttributes.class);
	
	context.checking(new Expectations() {{
		allowing(fs).provider();
		will(returnValue(provider));

		if (basicAttributes == null) {
			exactly(1).of(provider).readAttributes(path, CloudBasicFileAttributes.class);
			will(throwException(new FileNotFoundException()));
		} else {
			exactly(1).of(provider).readAttributes(path, CloudBasicFileAttributes.class);
			will(returnValue(basicAttributes));

			allowing(basicAttributes).getStorageType();
			will(returnValue(storageType));
		}
	}});

	return basicAttributes;
}
 
开发者ID:brdara,项目名称:java-cloud-filesystem-provider,代码行数:23,代码来源:CloudFileTest.java

示例13: AbstractLocalFileSystem

import java.nio.file.spi.FileSystemProvider; //导入依赖的package包/类
public AbstractLocalFileSystem( URI uri, FileSystemProvider provider, Path cachePath, Map<String, Object> env,
                                BiFunction<Path, Map<String, ?>, FileSystemIO> fileSystemIO )
        throws IOException
{
    super( uri, provider, env, cachePath, fileSystemIO );

    this.cachePath = getFileSystemIO().getBaseDirectory();

    if( Files.notExists( cachePath ) ) {
        Files.createDirectories( cachePath );
    }

    // sm and existence check
    cachePath.getFileSystem().provider().checkAccess( cachePath, AccessMode.READ );
    if( !Files.isWritable( cachePath ) ) {
        setReadOnly( true );
    }
}
 
开发者ID:peter-mount,项目名称:filesystem,代码行数:19,代码来源:AbstractLocalFileSystem.java

示例14: getInstance

import java.nio.file.spi.FileSystemProvider; //导入依赖的package包/类
/**
 * Returns any subclass that implements and handles the given scheme.
 * @param scheme a valid {@link URI} scheme
 * @see FileSystemProvider#getScheme()
 * @throws FileSystemNotFoundException if no filesystem handles this scheme
 */
public static MCRAbstractFileSystem getInstance(String scheme) {
    URI uri;
    try {
        uri = MCRPaths.getURI(scheme, "helper", SEPARATOR_STRING);
    } catch (URISyntaxException e) {
        throw new MCRException(e);
    }
    for (FileSystemProvider provider : Iterables.concat(MCRPaths.webAppProvider,
        FileSystemProvider.installedProviders())) {
        if (provider.getScheme().equals(scheme)) {
            return (MCRAbstractFileSystem) provider.getFileSystem(uri);
        }
    }
    throw new FileSystemNotFoundException("Provider \"" + scheme + "\" not found");
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:22,代码来源:MCRAbstractFileSystem.java

示例15: HadoopFileSystem

import java.nio.file.spi.FileSystemProvider; //导入依赖的package包/类
public HadoopFileSystem(FileSystemProvider provider, String host, int uriPort) throws IOException {
	
	this.provider = provider;
	
	int port = uriPort;
	if (port == -1) {
	  port = 8020; // Default Hadoop port
	}

	// Create dynamic configuration
	Configuration conf = new Configuration();
   if (host == null) {
     String defaultScheme =
         org.apache.hadoop.fs.FileSystem.getDefaultUri(conf).getScheme();
     if (!"hdfs".equals(defaultScheme)) {
       throw new NullPointerException("Null host not permitted if default " +
           "Hadoop filesystem is not HDFS.");
     }
   } else {
     conf.set("fs.defaultFS", "hdfs://" + host + ":" + port + "/");
   }

       this.fs = org.apache.hadoop.fs.FileSystem.get(conf);
       
       this.userPrincipalLookupService = new HadoopUserPrincipalLookupService(this);
}
 
开发者ID:damiencarol,项目名称:jsr203-hadoop,代码行数:27,代码来源:HadoopFileSystem.java


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