當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。