Java Code Examples for org.apache.commons.vfs2.FileSystem#resolveFile()
The following examples show how to use
org.apache.commons.vfs2.FileSystem#resolveFile() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UrlFileProvider.java From commons-vfs with Apache License 2.0 | 6 votes |
/** * Locates a file object, by absolute URI. * * @param baseFile The base FileObject. * @param fileUri The uri of the file to locate. * @param fileSystemOptions The FileSystemOptions * @return The FileObject * @throws FileSystemException if an error occurs. */ @Override public synchronized FileObject findFile(final FileObject baseFile, final String fileUri, final FileSystemOptions fileSystemOptions) throws FileSystemException { try { final URI uri = URI.create(fileUri); final URI rootUri = uri.resolve("/"); final String key = this.getClass().getName() + rootUri.toString(); FileSystem fs = findFileSystem(key, fileSystemOptions); if (fs == null) { final String extForm = rootUri.toString(); final FileName rootName = getContext().parseURI(extForm); // final FileName rootName = // new BasicFileName(rootUrl, FileName.ROOT_PATH); fs = new UrlFileSystem(rootName, fileSystemOptions); addFileSystem(key, fs); } return fs.resolveFile(uri.getPath()); } catch (final Exception e) { throw new FileSystemException("vfs.provider.url/badly-formed-uri.error", fileUri, e); } }
Example 2
Source File: JunctionTests.java From commons-vfs with Apache License 2.0 | 6 votes |
/** * Checks ancestors are created when a junction is created. */ public void testAncestors() throws Exception { final FileSystem fs = getManager().createVirtualFileSystem("vfs://").getFileSystem(); final FileObject baseDir = getBaseDir(); // Make sure the file at the junction point and its ancestors do not exist FileObject file = fs.resolveFile("/a/b"); assertFalse(file.exists()); file = file.getParent(); assertFalse(file.exists()); file = file.getParent(); assertFalse(file.exists()); // Add the junction fs.addJunction("/a/b", baseDir); // Make sure the file at the junction point and its ancestors exist file = fs.resolveFile("/a/b"); assertTrue("Does not exist", file.exists()); file = file.getParent(); assertTrue("Does not exist", file.exists()); file = file.getParent(); assertTrue("Does not exist", file.exists()); }
Example 3
Source File: TemporaryFileProvider.java From commons-vfs with Apache License 2.0 | 5 votes |
/** * Locates a file object, by absolute URI. * * @param baseFile The base FileObject. * @param uri The URI of the file to be located. * @param properties FileSystemOptions to use to locate or create the file. * @return The FileObject. * @throws FileSystemException if an error occurs. */ @Override public synchronized FileObject findFile(final FileObject baseFile, final String uri, final FileSystemOptions properties) throws FileSystemException { // Parse the name final StringBuilder buffer = new StringBuilder(uri); final String scheme = UriParser.extractScheme(getContext().getFileSystemManager().getSchemes(), uri, buffer); UriParser.fixSeparators(buffer); UriParser.normalisePath(buffer); final String path = buffer.toString(); // Create the temp file system if it does not exist // FileSystem filesystem = findFileSystem( this, (Properties) null); FileSystem filesystem = findFileSystem(this, properties); if (filesystem == null) { if (rootFile == null) { rootFile = getContext().getTemporaryFileStore().allocateFile("tempfs"); } final FileName rootName = getContext().parseURI(scheme + ":" + FileName.ROOT_PATH); // final FileName rootName = // new LocalFileName(scheme, scheme + ":", FileName.ROOT_PATH); filesystem = new LocalFileSystem(rootName, rootFile.getAbsolutePath(), properties); addFileSystem(this, filesystem); } // Find the file return filesystem.resolveFile(path); }
Example 4
Source File: AbstractOriginatingFileProvider.java From commons-vfs with Apache License 2.0 | 5 votes |
/** * Locates a file from its parsed URI. * * @param name The file name. * @param fileSystemOptions FileSystem options. * @return A FileObject associated with the file. * @throws FileSystemException if an error occurs. */ protected FileObject findFile(final FileName name, final FileSystemOptions fileSystemOptions) throws FileSystemException { // Check in the cache for the file system final FileName rootName = getContext().getFileSystemManager().resolveName(name, FileName.ROOT_PATH); final FileSystem fs = getFileSystem(rootName, fileSystemOptions); // Locate the file // return fs.resolveFile(name.getPath()); return fs.resolveFile(name); }
Example 5
Source File: JunctionProviderConfig.java From commons-vfs with Apache License 2.0 | 5 votes |
/** * Returns the base folder for tests. */ @Override public FileObject getBaseTestFolder(final FileSystemManager manager) throws Exception { final FileObject baseFolder = config.getBaseTestFolder(manager); // Create an empty file system, then link in the base folder final FileSystem newFs = manager.createVirtualFileSystem("vfs:").getFileSystem(); final String junctionPoint = "/some/dir"; newFs.addJunction(junctionPoint, baseFolder); return newFs.resolveFile(junctionPoint); }
Example 6
Source File: FileObjectSortTestCase.java From commons-vfs with Apache License 2.0 | 4 votes |
private static FileObject resolveFile(final FileSystem fs, final int i) throws FileSystemException { return fs.resolveFile(String.format("%010d", i)); }