apache-comnons系列之commons-vfs2 学习笔记

本文介绍Apache Commons VFS2的基本概念及其组件结构,包括主要接口如FileSystemManager和FileObject的功能与实现原理。深入探讨了VFS2如何通过不同类型的文件提供者(FileProvider)管理和操作文件系统。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

apache-comnons系列之commons-vfs2 学习笔记

概述

VFS

  • The main entry point for the VFS. Used to create {@link FileSystemManager} instances.

FileSystemManager

  • A FileSystemManager manages a set of file systems. This interface is used to locate a {@link FileObject} by name from one of those file systems.
  • A file system manager can recognise several types of file names
    • Absolute URI(file:/c:/somefile)
    • Absolute local file name(/home/someuser/a-file)
    • Relative path(../somefile)

StandardFileSystemManager—->DefaultFileSystemManager—->FileSystemManager

  • A {@link org.apache.commons.vfs2.FileSystemManager} that configures itself from an XML (Default: providers.xml) configuration file.

FileSystem

  • A file system, made up of a hierarchy of files.

LocalFileSystem—->AbstractFileSystem—->FileSystem

  • A local file system.
  • String rootFile
  • resolveFile(委托底层文件系统创建/解析文件)
    • org.apache.commons.vfs2.provider.local.LocalFileSystem.createFile

FileObject

  • Represents a file, and is used to access the content and structure of the file

LocalFile—->AbstractFileObject—->FileObject

  • A file object implementation which uses direct file access.
  • String rootFile;
  • File file;
  • org.apache.commons.vfs2.provider.local.LocalFile.doAttach(核心方法,将路径与文件绑定)
  • org.apache.commons.vfs2.provider.local.LocalFile.doGetInputStream(底层获取输入流,fs委托其获取)
  • org.apache.commons.vfs2.provider.local.LocalFile.doGetOutputStream(底层获取输出流,fs委托其获取)

HdfsFileObject—->AbstractFileObject—->FileObject

  • A VFS representation of an HDFS file.
  • FileSystem hdfs;(委托给hadoop进行底层操作)

FileProvider

  • A file provider. Each file provider is responsible for handling files for a particular URI scheme.

DefaultLocalFileProvider—->LocalFileProvider

  • DefaultLocalFileProvider—->AbstractOriginatingFileProvider—->AbstractFileProvider
  • A file system provider, which uses direct file access.

VfsComponent

  • This interface is used to manage the lifecycle of all VFS components.
  • init/close
  • This includes all implementations of the following interfaces:
    • org.apache.commons.vfs2.provider.FileProvider
    • org.apache.commons.vfs2.FileSystem
    • org.apache.commons.vfs2.provider.FileReplicator
    • org.apache.commons.vfs2.provider.TemporaryFileStore

FileReplicator

  • Responsible for making local replicas of files.

DefaultFileReplicator

VfsComponentContext

  • Allows VFS components to access the services they need, such as the file replicator. A VFS component is supplied with a context as part of its initialisation.

DefaultVfsComponentContext

  • DefaultFileSystemManager manager

测试

  • org.apache.commons.vfs2.VFS(入口)
    • org.apache.commons.vfs2.VFS.getManager
    • createManager(“org.apache.commons.vfs2.impl.StandardFileSystemManager”)
  • org.apache.commons.vfs2.impl.test.DefaultFileSystemManagerTest
    • providers = new HashMap();
    • components = new ArrayList();
    • LocalFileProvider localFileProvider;
    • FileProvider defaultProvider;
    • org.apache.commons.vfs2.impl.StandardFileSystemManager.init(初始化方法从providers.xml或者META-INF/vfs-providers.xml进行provider等信息的加载与配置)
    • org.apache.commons.vfs2.impl.StandardFileSystemManager.configure(org.w3c.dom.Element)
    • org.apache.commons.vfs2.impl.DefaultFileSystemManager.resolveFile(java.lang.String)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值