本文整理了Java中org.apache.commons.vfs2.VFS
类的一些代码示例,展示了VFS
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。VFS
类的具体详情如下:
包路径:org.apache.commons.vfs2.VFS
类名称:VFS
[英]The main entry point for the VFS. Used to create FileSystemManager instances.
[中]VFS的主要入口点。用于创建FileSystemManager实例。
代码示例来源:origin: pentaho/mondrian
FileSystemManager fsManager = VFS.getManager();
if (fsManager == null) {
throw newError("Cannot get virtual file system manager");
return new URL(url).openStream();
} catch (IOException e) {
throw newError(
FileObject file = fsManager.resolveFile(userDir, url);
FileContent fileContent = null;
try {
file.refresh();
&& !file.getName().getURI().equals(url))
fsManager.getFilesCache().removeFile(
file.getFileSystem(), file.getName());
file = fsManager.resolveFile(userDir, url);
return fileContent.getInputStream();
代码示例来源:origin: org.apache.commons/commons-vfs2
@Test
@Ignore
public void testFileNameWithSpaces() throws URISyntaxException, IOException {
final File file = new File("target", "a name.txt");
final String fileURL = file.toURI().toURL().toExternalForm();
assertEquals(file.getAbsoluteFile(), new File(file.toURI().getPath()));
assertEquals(file.getAbsoluteFile(), new File(new URL(fileURL).toURI().getPath()));
final FileSystemManager manager = VFS.getManager();
final FileObject fo = manager.resolveFile(fileURL);
assertEquals(file.getAbsoluteFile(), new File(new URL(fo.getURL().toExternalForm()).toURI().getPath()));
}
代码示例来源:origin: org.apache.commons/commons-configuration2
@Override
public URL getURL(final String basePath, final String file) throws MalformedURLException
{
if ((basePath != null && UriParser.extractScheme(basePath) == null)
|| (basePath == null && UriParser.extractScheme(file) == null))
{
return super.getURL(basePath, file);
}
try
{
final FileSystemManager fsManager = VFS.getManager();
FileName path;
if (basePath != null && UriParser.extractScheme(file) == null)
{
final FileName base = fsManager.resolveURI(basePath);
path = fsManager.resolveName(base, file);
}
else
{
path = fsManager.resolveURI(file);
}
final URLStreamHandler handler = new VFSURLStreamHandler(path);
return new URL(null, path.getURI(), handler);
}
catch (final FileSystemException fse)
{
throw new ConfigurationRuntimeException("Could not parse basePath: " + basePath
+ " and fileName: " + file, fse);
}
}
代码示例来源:origin: org.apache.commons/commons-configuration2
@Override
public InputStream getInputStream(final URL url) throws ConfigurationException
{
FileObject file;
try
{
final FileSystemOptions opts = getOptions(url.getProtocol());
file = (opts == null) ? VFS.getManager().resolveFile(url.toString())
: VFS.getManager().resolveFile(url.toString(), opts);
if (file.getType() != FileType.FILE)
{
throw new ConfigurationException("Cannot load a configuration from a directory");
}
final FileContent content = file.getContent();
if (content == null)
{
final String msg = "Cannot access content of " + file.getName().getFriendlyURI();
throw new ConfigurationException(msg);
}
return content.getInputStream();
}
catch (final FileSystemException fse)
{
final String msg = "Unable to access " + url.toString();
throw new ConfigurationException(msg, fse);
}
}
代码示例来源:origin: org.apache.commons/commons-configuration2
final FileSystemManager fsManager = VFS.getManager();
FileObject base = (opts == null) ? fsManager.resolveFile(basePath)
: fsManager.resolveFile(basePath, opts);
if (base.getType() == FileType.FILE)
base = base.getParent();
file = fsManager.resolveFile(base, fileName);
if (!file.exists())
final FileName path = file.getName();
final URLStreamHandler handler = new VFSURLStreamHandler(path);
return new URL(null, path.getURI(), handler);
代码示例来源:origin: org.apache.commons/commons-configuration2
@Override
public OutputStream getOutputStream(final URL url) throws ConfigurationException
{
try
{
final FileSystemOptions opts = getOptions(url.getProtocol());
final FileSystemManager fsManager = VFS.getManager();
final FileObject file = (opts == null) ? fsManager.resolveFile(url.toString())
: fsManager.resolveFile(url.toString(), opts);
// throw an exception if the target URL is a directory
if (file == null || file.getType() == FileType.FOLDER)
{
throw new ConfigurationException("Cannot save a configuration to a directory");
}
final FileContent content = file.getContent();
if (content == null)
{
throw new ConfigurationException("Cannot access content of " + url);
}
return content.getOutputStream();
}
catch (final FileSystemException fse)
{
throw new ConfigurationException("Unable to access " + url, fse);
}
}
代码示例来源:origin: apache/commons-vfs
@Override
public URL run() throws MalformedURLException, FileSystemException {
final StringBuilder buf = new StringBuilder();
final String scheme = UriParser.extractScheme(VFS.getManager().getSchemes(), fileName.getURI(), buf);
return new URL(scheme, "", -1, buf.toString(),
new DefaultURLStreamHandler(fileSystem.getContext(), fileSystem.getFileSystemOptions()));
}
});
代码示例来源:origin: apache/incubator-gobblin
public SimpleJsonExtractor(WorkUnitState workUnitState) throws FileSystemException {
this.workUnitState = workUnitState;
// Resolve the file to pull
if (workUnitState.getPropAsBoolean(ConfigurationKeys.SOURCE_CONN_USE_AUTHENTICATION, false)) {
// Add authentication credential if authentication is needed
UserAuthenticator auth =
new StaticUserAuthenticator(workUnitState.getProp(ConfigurationKeys.SOURCE_CONN_DOMAIN, ""),
workUnitState.getProp(ConfigurationKeys.SOURCE_CONN_USERNAME), PasswordManager.getInstance(workUnitState)
.readPassword(workUnitState.getProp(ConfigurationKeys.SOURCE_CONN_PASSWORD)));
FileSystemOptions opts = new FileSystemOptions();
DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth);
this.fileObject = VFS.getManager().resolveFile(workUnitState.getProp(SOURCE_FILE_KEY), opts);
} else {
this.fileObject = VFS.getManager().resolveFile(workUnitState.getProp(SOURCE_FILE_KEY));
}
// Open the file for reading
LOGGER.info("Opening file " + this.fileObject.getURL().toString());
this.bufferedReader =
this.closer.register(new BufferedReader(new InputStreamReader(this.fileObject.getContent().getInputStream(),
ConfigurationKeys.DEFAULT_CHARSET_ENCODING)));
}
代码示例来源:origin: org.apache.commons/commons-vfs2
/**
* Tests FindFiles with a filename that has a hash sign in it.
*/
public void testHashFindFiles() throws Exception {
final FileSystemManager fsManager = VFS.getManager();
final FileObject[] foList = getBaseFolder().findFiles(Selectors.SELECT_FILES);
boolean hashFileFound = false;
for (final FileObject fo : foList) {
if (fo.getURL().toString().contains("test-hash")) {
hashFileFound = true;
assertEquals(fo.toString(), UriParser.decode(fo.getURL().toString()));
}
}
if (!hashFileFound) {
fail("Test hash file containing 'test-hash' not found");
}
}
代码示例来源:origin: org.apache.commons/commons-configuration2
/**
* Returns the file that is monitored by this strategy. Note that the return
* value can be <b>null </b> under some circumstances.
*
* @return the monitored file
*/
protected FileObject getFileObject()
{
if (!getFileHandler().isLocationDefined())
{
return null;
}
try
{
final FileSystemManager fsManager = VFS.getManager();
final String uri = resolveFileURI();
if (uri == null)
{
throw new ConfigurationRuntimeException("Unable to determine file to monitor");
}
return fsManager.resolveFile(uri);
}
catch (final FileSystemException fse)
{
final String msg = "Unable to monitor " + getFileHandler().getURL().toString();
log.error(msg);
throw new ConfigurationRuntimeException(msg, fse);
}
}
代码示例来源:origin: org.apache.commons/commons-configuration2
final FileSystemManager fsManager = VFS.getManager();
if (url != null)
final FileName name = fsManager.resolveURI(url.toString());
if (name != null)
final FileName base = fsManager.resolveURI(basePath);
return fsManager.resolveName(base, fileName).getURI();
final FileName name = fsManager.resolveURI(fileName);
final FileName base = name.getParent();
return fsManager.resolveName(base, name.getBaseName()).getURI();
代码示例来源:origin: ManyDesigns/Portofino
protected void listClassFiles(String packageName, List<JavaFileObject> list) throws IOException {
Enumeration<URL> resources = getClassLoader().getResources(packageName.replace('.', '/'));
while (resources.hasMoreElements()) {
URL url = resources.nextElement();
FileObject fileObject = VFS.getManager().resolveFile(url.toString());
if(fileObject.exists() && fileObject.getType() == FileType.FOLDER) {
for(FileObject child : fileObject.getChildren()) {
if(child.getType() == FileType.FILE && "class".equalsIgnoreCase(child.getName().getExtension())) {
try {
String binaryName = FilenameUtils.removeExtension(child.getName().getPath()).replace(File.separatorChar, '.').replace('/', '.');
if (binaryName.startsWith(".")) {
binaryName = binaryName.substring(1);
}
list.add(new VFSJavaFileObject(JavaFileObject.Kind.CLASS, child, binaryName));
} catch (URISyntaxException e) {
throw new IOException(e);
}
}
}
}
}
}
代码示例来源:origin: pentaho/pentaho-hadoop-shims
@Test
public void filterJars_arg_urls_containsOnlyExcludedJars() throws Exception {
HadoopConfigurationLocator locator = new HadoopConfigurationLocator();
FileObject root = VFS.getManager().resolveFile( HADOOP_CONFIGURATIONS_PATH );
List<URL> urls = locator.parseURLs( root, root.toString() );
Iterator<URL> iterator = urls.listIterator();
while ( iterator.hasNext() ) {
URL url = iterator.next();
if ( FileType.FOLDER.equals( root.resolveFile( url.toString().trim() ).getType() ) ) {
iterator.remove();
}
}
List<URL> list = locator.filterJars( urls,
"xercesImpl,xml-apis-1.3.04.jar,xml-apis-ext-1.3.04,xerces-version-1.8.0,xercesImpl2-2.9.1,"
+ "pentaho-hadoop-shims-api-61.2016.04.01-196,commands-3.3.0-I20070605-0010,postgresql,trilead-ssh2-build213"
+ ".jar,trilead-ssh2-build215.jar" );
assertEquals( 0, list.size() );
}
代码示例来源:origin: com.talanlabs/message-manager-server
private FileObject findFileInArchive(String archiveFile, String tgzName, String filename) throws IOException {
DefaultFileSystemManager fsManager = (DefaultFileSystemManager) VFS.getManager();
FileObject jarFile;
try {
String uri = "tgz:" + archiveFile + tgzName + ".tgz" + "!" + File.separator + tgzName + File.separator;
if (LOG.isDebugEnabled()) {
LOG.debug("base file is " + fsManager.getBaseFile().getURL().getPath());
LOG.debug(uri);
}
jarFile = fsManager.resolveFile(uri);
} catch (FileSystemException e) {
if (LOG.isDebugEnabled()) {
LOG.debug("", e);
}
return null;
}
FileObject[] children = jarFile.getChildren();
for (FileObject child : children) {
String baseName = child.getName().getBaseName();
if (filename.equals(baseName)) {
return child;
}
}
return null;
}
代码示例来源:origin: org.apache.commons/commons-vfs2
/**
* Tests https://issues.apache.org/jira/browse/VFS-426
*/
@Test
public void testQueryStringUrls() throws FileSystemException {
final String noQueryStringUrl = "http://commons.apache.org/vfs";
final String queryStringUrl = "http://commons.apache.org/vfs?query=string";
final String queryStringUrl2 = "http://commons.apache.org/vfs?query=string&more=stuff";
final FileSystemManager fileSystemManager = VFS.getManager();
final FileObject noQueryFile = fileSystemManager.resolveFile(noQueryStringUrl);
Assert.assertEquals(noQueryStringUrl, noQueryFile.getURL().toExternalForm());
final FileObject queryFile = fileSystemManager.resolveFile(queryStringUrl);
Assert.assertEquals(queryStringUrl, queryFile.getURL().toExternalForm()); // failed for VFS-426
final FileObject queryFile2 = fileSystemManager.resolveFile(queryStringUrl2);
Assert.assertEquals(queryStringUrl2, queryFile2.getURL().toExternalForm()); // failed for VFS-426
}
}
代码示例来源:origin: pentaho/pentaho-hadoop-shims
@BeforeClass
public static void setup() throws Exception {
// Create a test hadoop configuration
FileObject ramRoot = VFS.getManager().resolveFile( CONFIG_PROPERTY_CLASSPATH );
if ( ramRoot.exists() ) {
ramRoot.delete( new AllFileSelector() );
}
ramRoot.createFolder();
// Create the implementation jars
ramRoot.resolveFile( "hadoop-mapreduce-client-app-2.7.0-mapr-1602.jar" ).createFile();
ramRoot.resolveFile( "hadoop-mapreduce-client-common-2.7.0-mapr-1602.jar" ).createFile();
ramRoot.resolveFile( "hadoop-mapreduce-client-contrib-2.7.0-mapr-1602.jar" ).createFile();
ramRoot.resolveFile( "hadoop-mapreduce-client-core-2.7.0-mapr-1602.jar" ).createFile();
ramRoot.resolveFile( "hadoop-mapreduce-client-hs-2.7.0-mapr-1602.jar" ).createFile();
pmrFolder = tempFolder.newFolder( "pmr" );
urlTestResources = Thread.currentThread().getContextClassLoader().getResource( PMR_PROPERTIES );
Files.copy( Paths.get( urlTestResources.toURI() ), Paths.get( pmrFolder.getAbsolutePath(), PMR_PROPERTIES ) );
}
代码示例来源:origin: pentaho/pentaho-hadoop-shims
@Test
public void parseURLs() throws Exception {
HadoopConfigurationLocator locator = new HadoopConfigurationLocator();
FileObject root = VFS.getManager().resolveFile( HADOOP_CONFIGURATIONS_PATH );
List<URL> urls = locator.parseURLs( root, "a,b" );
assertEquals( 2, urls.size() );
assertEquals( root.getURL().toURI().resolve( "hadoop-configurations/a/" ), urls.get( 0 ).toURI() );
assertEquals( root.getURL().toURI().resolve( "hadoop-configurations/a/a-config.jar" ), urls.get( 1 ).toURI() );
}
}
代码示例来源:origin: ai.h2o/reflections
@Override
public boolean matches(URL url) throws Exception {
try {
final FileSystemManager manager = VFS.getManager();
final FileObject fileObject = manager.resolveFile(url.toExternalForm());
return fileObject.exists() && fileObject.getType() == FileType.FOLDER;
} catch (FileSystemException e) {
Reflections.log.warn("Could not create CommonsVfs2UrlType from url " + url.toExternalForm(), e);
return false;
}
}
代码示例来源:origin: apache/commons-vfs
@Override
protected void parseURL(final URL u, final String spec, final int start, final int limit) {
try {
final FileObject old = context.resolveFile(u.toExternalForm(), fileSystemOptions);
FileObject newURL;
if (start > 0 && spec.charAt(start - 1) == ':') {
newURL = context.resolveFile(old, spec, fileSystemOptions);
} else {
if (old.isFile() && old.getParent() != null) {
// for files we have to resolve relative
newURL = old.getParent().resolveFile(spec);
} else {
newURL = old.resolveFile(spec);
}
}
final String url = newURL.getName().getURI();
final StringBuilder filePart = new StringBuilder();
final String protocolPart = UriParser.extractScheme(VFS.getManager().getSchemes(), url, filePart);
setURL(u, protocolPart, "", -1, null, null, filePart.toString(), null, null);
} catch (final FileSystemException fse) {
// This is rethrown to MalformedURLException in URL anyway
throw new RuntimeException(fse.getMessage());
}
}
代码示例来源:origin: ai.h2o/reflections
@Override
public Vfs.Dir createDir(URL url) throws Exception {
final FileSystemManager manager = VFS.getManager();
final FileObject fileObject = manager.resolveFile(url.toExternalForm());
return new CommonsVfs2UrlType.Dir(fileObject);
}
内容来源于网络,如有侵权,请联系作者删除!