use of org.apache.commons.vfs2.provider.LocalFileProvider in project commons-vfs by apache.
the class CustomRamProviderTest method testSpecialName.
/**
* Test some special file name symbols.
* <p>
* Use the RamProvider since it has no character limitations like
* the (Windows) LocalFileProvider.
*/
@Test
public void testSpecialName() throws FileSystemException {
// we test with this file name
// does not work with '!'
final String testDir = "/spacialtest/";
final String testFileName = "test:+-_ \"()<>%#.txt";
final String expectedName = testDir + testFileName;
final FileObject dir = prepareSpecialFile(testDir, testFileName);
// DO: verify you can list it:
// includes dir
final FileObject[] findFilesResult = dir.findFiles(new AllFileSelector());
final FileObject[] getChildrenResult = dir.getChildren();
final FileObject getChildResult = dir.getChild(UriParser.encode(testFileName, ENC));
// validate findFiles returns expected result
assertEquals("Unexpected result findFiles: " + Arrays.toString(findFilesResult), 2, findFilesResult.length);
String resultName = findFilesResult[0].getName().getPathDecoded();
assertEquals("findFiles Child name does not match", expectedName, resultName);
assertEquals("Did findFiles but child was no file", FileType.FILE, findFilesResult[0].getType());
// validate getChildren returns expected result
assertEquals("Unexpected result getChildren: " + Arrays.toString(getChildrenResult), 1, getChildrenResult.length);
resultName = getChildrenResult[0].getName().getPathDecoded();
assertEquals("getChildren Child name does not match", expectedName, resultName);
assertEquals("Did getChildren but child was no file", FileType.FILE, getChildrenResult[0].getType());
// validate getChild returns expected child
assertNotNull("Did not find direct child", getChildResult);
resultName = getChildResult.getName().getPathDecoded();
assertEquals("getChild name does not match", expectedName, resultName);
assertEquals("getChild was no file", FileType.FILE, getChildResult.getType());
}
use of org.apache.commons.vfs2.provider.LocalFileProvider in project commons-vfs by apache.
the class DefaultFileSystemManager method resolveURI.
/**
* Resolve the uri to a file name.
*
* @param uri The URI to resolve.
* @return The FileName of the file.
* @throws FileSystemException if an error occurs.
*/
@Override
public FileName resolveURI(final String uri) throws FileSystemException {
UriParser.checkUriEncoding(uri);
if (uri == null) {
throw new IllegalArgumentException();
}
// Extract the scheme
final String scheme = UriParser.extractScheme(getSchemes(), uri);
if (scheme != null) {
// An absolute URI - locate the provider
final FileProvider provider = providers.get(scheme);
if (provider != null) {
return provider.parseUri(null, uri);
}
// Otherwise, assume a local file
}
// Handle absolute file names
if (localFileProvider != null && localFileProvider.isAbsoluteLocalName(uri)) {
return localFileProvider.parseUri(null, uri);
}
if (scheme != null) {
// An unknown scheme - hand it to the default provider
FileSystemException.requireNonNull(defaultProvider, "vfs.impl/unknown-scheme.error", scheme, uri);
return defaultProvider.parseUri(null, uri);
}
// Assume a relative name - use the supplied base file
FileSystemException.requireNonNull(baseFile, "vfs.impl/find-rel-file.error", uri);
return resolveName(baseFile.getName(), uri, NameScope.FILE_SYSTEM);
}
use of org.apache.commons.vfs2.provider.LocalFileProvider in project commons-vfs by apache.
the class DefaultFileSystemManager method resolveFile.
/**
* Resolves a URI, relative to a base file with specified FileSystem configuration.
*
* @param baseFile The base file.
* @param uri The file name. May be a fully qualified or relative path or a url.
* @param fileSystemOptions Options to pass to the file system.
* @return A FileObject representing the target file.
* @throws FileSystemException if an error occurs accessing the file.
*/
public FileObject resolveFile(final FileObject baseFile, final String uri, final FileSystemOptions fileSystemOptions) throws FileSystemException {
final FileObject realBaseFile;
if (baseFile != null && VFS.isUriStyle() && baseFile.getName().isFile()) {
realBaseFile = baseFile.getParent();
} else {
realBaseFile = baseFile;
}
// TODO: use resolveName and use this name to resolve the fileObject
UriParser.checkUriEncoding(uri);
if (uri == null) {
throw new IllegalArgumentException();
}
// Extract the scheme
final String scheme = UriParser.extractScheme(getSchemes(), uri);
if (scheme != null) {
// An absolute URI - locate the provider
final FileProvider provider = providers.get(scheme);
if (provider != null) {
return provider.findFile(realBaseFile, uri, fileSystemOptions);
}
// Otherwise, assume a local file
}
// Handle absolute file names
if (localFileProvider != null && localFileProvider.isAbsoluteLocalName(uri)) {
return localFileProvider.findLocalFile(uri);
}
if (scheme != null) {
// An unknown scheme - hand it to the default provider
FileSystemException.requireNonNull(defaultProvider, "vfs.impl/unknown-scheme.error", scheme, uri);
return defaultProvider.findFile(realBaseFile, uri, fileSystemOptions);
}
// Assume a relative name - use the supplied base file
FileSystemException.requireNonNull(realBaseFile, "vfs.impl/find-rel-file.error", uri);
return realBaseFile.resolveFile(uri);
}
Aggregations