本文整理汇总了Java中java.nio.file.ProviderNotFoundException类的典型用法代码示例。如果您正苦于以下问题:Java ProviderNotFoundException类的具体用法?Java ProviderNotFoundException怎么用?Java ProviderNotFoundException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ProviderNotFoundException类属于java.nio.file包,在下文中一共展示了ProviderNotFoundException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ArchiveContainer
import java.nio.file.ProviderNotFoundException; //导入依赖的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;
}
}
});
}
}
示例2: itShouldReturnNullIfNotValidJarProvider
import java.nio.file.ProviderNotFoundException; //导入依赖的package包/类
@Test
public void itShouldReturnNullIfNotValidJarProvider() {
fileSupport = new FakeFileSupport(set(), set()) {
@Override
public Path getJarFileSystemRoot(Path jarFile) {
super.getJarFileSystemRoot(jarFile);
throw new ProviderNotFoundException();
}
};
fileSupport.setJarFileSystemRoot(null);
target = new JarSourceProvider(fileSupport);
ClassSource result = target.findSource("foobar", new FakeSearchPath("foo/bar"));
Assert.assertEquals(set(mkpath("foo/bar")), fileSupport.getCheckedJarFileSystemRoots());
Assert.assertNull(result);
}
示例3: getFileSystem
import java.nio.file.ProviderNotFoundException; //导入依赖的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() + "'");
}
示例4: handleRequest
import java.nio.file.ProviderNotFoundException; //导入依赖的package包/类
public void handleRequest(TransportChannel channel, Request request) {
Response response = new Response();
Class<?> interfaceClass = request.getInterfaceClass();
response.setRequestId(request.getRequestId());
Object providerInstance = providerContainer.getProvider(interfaceClass);
if (providerInstance == null) {
response.setResult(new ProviderNotFoundException("No Provider For " + request.getClass().getName()));
channel.write(response);
return;
}
MethodAccess methodAccess = methodAccessCache.computeIfAbsent(interfaceClass, key -> MethodAccess.get(key));
try {
Object result = methodAccess.invoke(providerInstance, request.getMethodName(), request.getArgs());
response.setResult(result);
} catch (Throwable t) {
response.setResult(t);
}
channel.write(response);
return;
}
示例5: createSource
import java.nio.file.ProviderNotFoundException; //导入依赖的package包/类
private ClassSource createSource(Path jarFile) {
try {
Path jarRootPath = fileSupport.getJarFileSystemRoot(jarFile);
if (jarRootPath == null) {
return null;
}
ClassLoader classLoader = fileSupport.createClassLoader(jarFile);
return new JarFileSource(jarFile, jarRootPath, classLoader);
} catch (ProviderNotFoundException | MalformedURLException e) {
}
return null;
}
示例6: isAvailable
import java.nio.file.ProviderNotFoundException; //导入依赖的package包/类
public static boolean isAvailable() {
try {
FileSystems.getFileSystem(URI.create("jrt:/"));
return true;
} catch (ProviderNotFoundException | FileSystemNotFoundException e) {
return false;
}
}
示例7: checkNoUOE
import java.nio.file.ProviderNotFoundException; //导入依赖的package包/类
static void checkNoUOE() throws IOException, URISyntaxException {
String dir = System.getProperty("test.dir", ".");
String fileName = dir + File.separator + "foo.bar";
Path path = Paths.get(fileName);
Path file = Files.createFile(path);
try {
URI uri = new URI("jar", file.toUri().toString(), null);
System.out.println(uri);
FileSystem fs = FileSystems.newFileSystem(uri, new HashMap());
fs.close();
} catch (ProviderNotFoundException pnfe) {
System.out.println("Expected ProviderNotFoundException caught: "
+ "\"" + pnfe.getMessage() + "\"");
}
}
示例8: ArchiveContainer
import java.nio.file.ProviderNotFoundException; //导入依赖的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);
this.fileSystem = getJarFSProvider().newFileSystem(archivePath, env);
} else {
this.fileSystem = FileSystems.newFileSystem(archivePath, null);
}
}
示例9: getJarFSProvider
import java.nio.file.ProviderNotFoundException; //导入依赖的package包/类
private FileSystemProvider getJarFSProvider() throws IOException {
if (jarFSProvider != null) {
return jarFSProvider;
}
for (FileSystemProvider provider: FileSystemProvider.installedProviders()) {
if (provider.getScheme().equals("jar")) {
return (jarFSProvider = provider);
}
}
throw new ProviderNotFoundException("no provider found for .jar files");
}
示例10: isPosixCompliant
import java.nio.file.ProviderNotFoundException; //导入依赖的package包/类
private static boolean isPosixCompliant() {
try {
if (FileSystems.getDefault()
.supportedFileAttributeViews()
.contains("posix")) {
return true;
}
return false;
} catch (FileSystemNotFoundException
| ProviderNotFoundException
| SecurityException e) {
return false;
}
}
示例11: bindNativeLibs
import java.nio.file.ProviderNotFoundException; //导入依赖的package包/类
private void bindNativeLibs() {
Set<Path> pathStream;
try {
pathStream = new NativeLibsJarIntrospectSearch().getNativeLibraries();
} catch (ProviderNotFoundException e) {
log.error(e.getMessage());
pathStream = new NativeLibsIDEIntrospectSearch().getNativeLibraries();
}
new NativeLibsBinder().bindLibs(pathStream);
}
示例12: getSplits
import java.nio.file.ProviderNotFoundException; //导入依赖的package包/类
public List<InputSplit> getSplits(
List<InputSplit> splits, Configuration cfg)
throws IOException
{
final List<InputSplit> origSplits = removeIndexFiles(splits);
// Align the splits so that they don't cross blocks.
// addIndexedSplits() requires the given splits to be sorted by file
// path, so do so. Although FileInputFormat.getSplits() does, at the time
// of writing this, generate them in that order, we shouldn't rely on it.
Collections.sort(origSplits, new Comparator<InputSplit>() {
public int compare(InputSplit a, InputSplit b) {
FileSplit fa = (FileSplit)a, fb = (FileSplit)b;
return fa.getPath().compareTo(fb.getPath());
}
});
final List<InputSplit> newSplits =
new ArrayList<InputSplit>(origSplits.size());
for (int i = 0; i < origSplits.size();) {
try {
i = addIndexedSplits (origSplits, i, newSplits, cfg);
} catch (IOException | ProviderNotFoundException e) {
if (cfg.getBoolean(ENABLE_BAI_SPLIT_CALCULATOR, false)) {
try {
i = addBAISplits (origSplits, i, newSplits, cfg);
} catch (IOException | ProviderNotFoundException e2) {
i = addProbabilisticSplits (origSplits, i, newSplits, cfg);
}
} else {
i = addProbabilisticSplits (origSplits, i, newSplits, cfg);
}
}
}
return filterByInterval(newSplits, cfg);
}
示例13: getDefault
import java.nio.file.ProviderNotFoundException; //导入依赖的package包/类
public static synchronized JavaInstallation getDefault() throws IOException {
if (instance == null) {
List<Path> cp;
try {
cp = getJrtFs();
} catch (ProviderNotFoundException e) {
cp = getJava8();
}
instance = new JavaInstallation(cp);
}
return instance;
}
示例14: newFileSystem
import java.nio.file.ProviderNotFoundException; //导入依赖的package包/类
@VisibleForTesting
static FileSystem newFileSystem(URI uri, Configuration config) {
checkArgument(
URI_SCHEME.equals(uri.getScheme()), "uri (%s) must have scheme %s", uri, URI_SCHEME);
try {
// Create the FileSystem. It uses JimfsFileSystemProvider as its provider, as that is
// the provider that actually implements the operations needed for Files methods to work.
JimfsFileSystem fileSystem =
JimfsFileSystems.newFileSystem(JimfsFileSystemProvider.instance(), uri, config);
/*
* Now, call FileSystems.newFileSystem, passing it the FileSystem we just created. This
* allows the system-loaded SystemJimfsFileSystemProvider instance to cache the FileSystem
* so that methods like Paths.get(URI) work.
* We do it in this awkward way to avoid issues when the classes in the API (this class
* and Configuration, for example) are loaded by a different classloader than the one that
* loads SystemJimfsFileSystemProvider using ServiceLoader. See
* https://github.com/google/jimfs/issues/18 for gory details.
*/
try {
ImmutableMap<String, ?> env = ImmutableMap.of(FILE_SYSTEM_KEY, fileSystem);
FileSystems.newFileSystem(uri, env, SystemJimfsFileSystemProvider.class.getClassLoader());
} catch (ProviderNotFoundException | ServiceConfigurationError ignore) {
// See the similar catch block below for why we ignore this.
// We log there rather than here so that there's only typically one such message per VM.
}
return fileSystem;
} catch (IOException e) {
throw new AssertionError(e);
}
}
示例15: addFile
import java.nio.file.ProviderNotFoundException; //导入依赖的package包/类
public void addFile(Path file, boolean warn) {
if (contains(file)) {
// discard duplicates
return;
}
if (!fsInfo.exists(file)) {
/* No such file or directory exists */
if (warn) {
log.warning(Lint.LintCategory.PATH,
Warnings.PathElementNotFound(file));
}
super.add(file);
return;
}
Path canonFile = fsInfo.getCanonicalFile(file);
if (canonicalValues.contains(canonFile)) {
/* Discard duplicates and avoid infinite recursion */
return;
}
if (fsInfo.isFile(file)) {
/* File is an ordinary file. */
if ( !file.getFileName().toString().endsWith(".jmod")
&& !file.endsWith("modules")) {
if (!isArchive(file)) {
/* Not a recognized extension; open it to see if
it looks like a valid zip file. */
try {
FileSystems.newFileSystem(file, null).close();
if (warn) {
log.warning(Lint.LintCategory.PATH,
Warnings.UnexpectedArchiveFile(file));
}
} catch (IOException | ProviderNotFoundException e) {
// FIXME: include e.getLocalizedMessage in warning
if (warn) {
log.warning(Lint.LintCategory.PATH,
Warnings.InvalidArchiveFile(file));
}
return;
}
} else {
if (fsInfo.getJarFSProvider() == null) {
log.error(Errors.NoZipfsForArchive(file));
return ;
}
}
}
}
/* Now what we have left is either a directory or a file name
conforming to archive naming convention */
super.add(file);
canonicalValues.add(canonFile);
if (expandJarClassPaths && fsInfo.isFile(file) && !file.endsWith("modules")) {
addJarClassPath(file, warn);
}
}