本文整理汇总了Java中java.nio.file.FileSystemNotFoundException类的典型用法代码示例。如果您正苦于以下问题:Java FileSystemNotFoundException类的具体用法?Java FileSystemNotFoundException怎么用?Java FileSystemNotFoundException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FileSystemNotFoundException类属于java.nio.file包,在下文中一共展示了FileSystemNotFoundException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: create
import java.nio.file.FileSystemNotFoundException; //导入依赖的package包/类
public static Path create( URI uri )
{
try
{
return Paths.get( uri );
}
catch( FileSystemNotFoundException nfe )
{
try
{
Map<String, String> env = new HashMap<>();
env.put( "create", "true" ); // creates zip/jar file if not already exists
FileSystem fs = FileSystems.newFileSystem( uri, env );
return fs.provider().getPath( uri );
}
catch( IOException e )
{
throw new RuntimeException( e );
}
}
}
示例2: listFiles
import java.nio.file.FileSystemNotFoundException; //导入依赖的package包/类
public List<Path> listFiles(Path dirPath)
{
List<Path> files = new ArrayList<>();
if (!getFS().isPresent()) {
throw new FileSystemNotFoundException("");
}
FileStatus[] fileStatuses = new FileStatus[0];
try {
fileStatuses = getFS().get().listStatus(dirPath);
}
catch (IOException e) {
log.error(e);
}
for (FileStatus f : fileStatuses) {
if (f.isFile()) {
files.add(f.getPath());
}
}
return files;
}
示例3: open
import java.nio.file.FileSystemNotFoundException; //导入依赖的package包/类
static SystemImage open() throws IOException {
if (modulesImageExists) {
// open a .jimage and build directory structure
final ImageReader image = ImageReader.open(moduleImageFile);
image.getRootDirectory();
return new SystemImage() {
@Override
Node findNode(String path) throws IOException {
return image.findNode(path);
}
@Override
byte[] getResource(Node node) throws IOException {
return image.getResource(node);
}
@Override
void close() throws IOException {
image.close();
}
};
}
if (Files.notExists(explodedModulesDir))
throw new FileSystemNotFoundException(explodedModulesDir.toString());
return new ExplodedImage(explodedModulesDir);
}
示例4: getFileSystem
import java.nio.file.FileSystemNotFoundException; //导入依赖的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() + "'");
}
示例5: createDetectorsRepo
import java.nio.file.FileSystemNotFoundException; //导入依赖的package包/类
static Repository createDetectorsRepo(Class<?> clazz, String pluginName, Set<Path> paths) {
CodeSource codeSource = clazz.getProtectionDomain().getCodeSource();
if (codeSource == null) {
throw new RuntimeException(format("Initializing plugin '%s' could not get code source for class %s", pluginName, clazz.getName()));
}
URL url = codeSource.getLocation();
try {
Path path = Paths.get(url.toURI());
if(paths.add(path)) {
if(Files.isDirectory(path)) {
return new DirRepository(path);
} else {
return new JarRepository(new JarFile(path.toFile()));
}
} else {
return createNullRepository();
}
} catch (URISyntaxException | FileSystemNotFoundException | IllegalArgumentException
| IOException | UnsupportedOperationException e) {
String errorMessage = format("Error creating detector repository for plugin '%s'", pluginName);
throw new RuntimeException(errorMessage, e);
}
}
示例6: getInformation
import java.nio.file.FileSystemNotFoundException; //导入依赖的package包/类
public MCRIIIFImageInformation getInformation(String identifier)
throws MCRIIIFImageNotFoundException, MCRIIIFImageProvidingException, MCRAccessException {
try {
Path tiledFile = tileFileProvider.getTiledFile(identifier);
MCRTiledPictureProps tiledPictureProps = getTiledPictureProps(tiledFile);
MCRIIIFImageInformation imageInformation = new MCRIIIFImageInformation(MCRIIIFBase.API_IMAGE_2,
buildURL(identifier), DEFAULT_PROTOCOL, tiledPictureProps.getWidth(), tiledPictureProps.getHeight());
MCRIIIFImageTileInformation tileInformation = new MCRIIIFImageTileInformation(256, 256);
for (int i = 0; i < tiledPictureProps.getZoomlevel(); i++) {
tileInformation.scaleFactors.add((int) Math.pow(2, i));
}
imageInformation.tiles.add(tileInformation);
return imageInformation;
} catch (FileSystemNotFoundException e) {
LOGGER.error("Could not find Iview ZIP for {}", identifier, e);
throw new MCRIIIFImageNotFoundException(identifier);
}
}
示例7: getFileSystem
import java.nio.file.FileSystemNotFoundException; //导入依赖的package包/类
public static FileSystem getFileSystem(Path iviewFile) throws IOException {
URI uri = URI.create("jar:" + iviewFile.toUri());
try {
return FileSystems.newFileSystem(uri, Collections.emptyMap(),
MCRIView2Tools.class.getClassLoader());
} catch (FileSystemAlreadyExistsException exc) {
// block until file system is closed
try {
FileSystem fileSystem = FileSystems.getFileSystem(uri);
while (fileSystem.isOpen()) {
try {
Thread.sleep(10);
} catch (InterruptedException ie) {
// get out of here
throw new IOException(ie);
}
}
} catch (FileSystemNotFoundException fsnfe) {
// seems closed now -> do nothing and try to return the file system again
LOGGER.debug("Filesystem not found", fsnfe);
}
return getFileSystem(iviewFile);
}
}
示例8: getInstance
import java.nio.file.FileSystemNotFoundException; //导入依赖的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");
}
示例9: getPath
import java.nio.file.FileSystemNotFoundException; //导入依赖的package包/类
@Override
public Path getPath(final URI uri) {
if (!FS_URI.getScheme().equals(Objects.requireNonNull(uri).getScheme())) {
throw new FileSystemNotFoundException("Unkown filesystem: " + uri);
}
String path = uri.getPath().substring(1);//URI path is absolute -> remove first slash
String owner = null;
for (int i = 0; i < path.length(); i++) {
if (path.charAt(i) == MCRAbstractFileSystem.SEPARATOR) {
break;
}
if (path.charAt(i) == ':') {
owner = path.substring(0, i);
path = path.substring(i + 1);
break;
}
}
return MCRAbstractFileSystem.getPath(owner, path, getFileSystemFromPathURI(FS_URI));
}
示例10: getLocalSystem
import java.nio.file.FileSystemNotFoundException; //导入依赖的package包/类
private JFileSystem getLocalSystem()
{
synchronized (_localSystem) {
JFileSystem localSystem = _localSystem.getLevel();
if (localSystem == null) {
BartenderFileSystem fileSystem = BartenderFileSystem.getCurrent();
if (fileSystem == null) {
throw new FileSystemNotFoundException(L.l("cannot find local bfs file system"));
}
ServiceRef root = fileSystem.getRootServiceRef();
localSystem = new JFileSystem(this, root);
_localSystem.set(localSystem);
}
return localSystem;
}
}
示例11: getPomPath
import java.nio.file.FileSystemNotFoundException; //导入依赖的package包/类
private Path getPomPath() throws URISyntaxException {
try {
String className = getClass().getName();
String classfileName = "/" + className.replace('.', '/') + ".class";
URL classfileResource = getClass().getResource(classfileName);
if (classfileResource != null) {
Path absolutePackagePath = Paths.get(classfileResource.toURI())
.getParent();
int packagePathSegments = className.length()
- className.replace(".", "").length();
Path path = absolutePackagePath;
for (int i = 0, segmentsToRemove = packagePathSegments + 2;
i < segmentsToRemove; i++) {
path = path.getParent();
}
return path.resolve("pom.xml");
}
} catch (FileSystemNotFoundException e) {
log.log(Level.INFO,
"Not in Filesystem-Mode: "
+ e.getMessage(), e);
}
return null;
}
示例12: getFileSystem
import java.nio.file.FileSystemNotFoundException; //导入依赖的package包/类
@Override
public BundleFileSystem getFileSystem(URI uri) {
synchronized (openFilesystems) {
URI baseURI = baseURIFor(uri);
WeakReference<BundleFileSystem> ref = openFilesystems.get(baseURI);
if (ref == null) {
throw new FileSystemNotFoundException(uri.toString());
}
BundleFileSystem fs = ref.get();
if (fs == null) {
openFilesystems.remove(baseURI);
throw new FileSystemNotFoundException(uri.toString());
}
return fs;
}
}
示例13: AbstractTarFileSystem
import java.nio.file.FileSystemNotFoundException; //导入依赖的package包/类
protected AbstractTarFileSystem(AbstractTarFileSystemProvider provider,
Path tfpath, Map<String, ?> env) throws IOException {
// configurable env setup
createNew = "true".equals(env.get("create"));
defaultDir = env.containsKey("default.dir") ? (String) env
.get("default.dir") : "/";
entriesToData = new HashMap<>();
if (defaultDir.charAt(0) != '/') {
throw new IllegalArgumentException("default dir should be absolute");
}
this.provider = provider;
this.tfpath = tfpath;
if (Files.notExists(tfpath)) {
if (!createNew) {
throw new FileSystemNotFoundException(tfpath.toString());
}
}
// sm and existence check
tfpath.getFileSystem().provider().checkAccess(tfpath, AccessMode.READ);
if (!Files.isWritable(tfpath)) {
readOnly = true;
}
defaultdir = new TarPath(this, defaultDir.getBytes());
outputStreams = new ArrayList<>();
mapEntries();
}
示例14: getFileSystem
import java.nio.file.FileSystemNotFoundException; //导入依赖的package包/类
public FileSystem getFileSystem( URI uri ) {
checkURI( uri );
String id = uriMapper.getSchemeSpecificPart( uri );
FileSystem ret = fileSystems.get( id );
if( ret == null ) {
throw new FileSystemNotFoundException( uri.toString() );
}
if( !ret.isOpen() ) {
fileSystems.remove( id ); // for GC
throw new FileSystemNotFoundException( uri.toString() );
}
return ret;
}
示例15: asPath
import java.nio.file.FileSystemNotFoundException; //导入依赖的package包/类
/**
* Convert the given path {@link URI} to a {@link Path} object.
* @param uri the path to convert
* @return a {@link Path} object
*/
public static Path asPath(URI uri) {
try {
return Paths.get(uri);
} catch (FileSystemNotFoundException e) {
ClassLoader cl = Thread.currentThread().getContextClassLoader();
if (cl == null) {
throw e;
}
try {
return FileSystems.newFileSystem(uri, new HashMap<>(), cl).provider().getPath(uri);
} catch (IOException ex) {
throw new RuntimeException("Cannot create filesystem for " + uri, ex);
}
}
}