Supported File Systems – Apache Commons VFS (original) (raw)
Commons VFS directly supports the following file systems with the listedcapabilities:
| File System | Directory Contents | Authentication | Read | Write | Create/Delete | Random | Version | Rename |
|---|---|---|---|---|---|---|---|---|
| BZIP2 | No | No | Yes | Yes | No | No | No | No |
| File | No | No | Yes | Yes | Yes | Read/Write | No | Yes |
| FTP | No | Yes | Yes | Yes | Yes | Read | No | Yes |
| FTPS | No | Yes | Yes | Yes | Yes | Read | No | Yes |
| GZIP | No | No | Yes | Yes | No | No | No | No |
| HDFS | Yes | No | Yes | No | No | Read | No | No |
| HTTP | Yes | Yes | Yes | No | No | Read | No | No |
| HTTPS | Yes | Yes | Yes | No | No | Read | No | No |
| Jar | No | No | Yes | No | No | No | No | No |
| RAM | No | No | Yes | Yes | Yes | Read/Write | No | Yes |
| RES | No | No | Yes | Yes | Yes | Read/Write | No | Yes |
| SFTP | No | Yes | Yes | Yes | Yes | Read | No | Yes |
| Tar | No | No | Yes | No | No | No | No | No |
| Temp | No | No | Yes | Yes | Yes | Read/Write | No | Yes |
| WebDAV | Yes | Yes | Yes | Yes | Yes | Read/Write | Yes | Yes |
| Zip | No | No | Yes | No | No | No | No | No |
Things from the sandbox
The following file systems are in development:
| File System | Directory Contents | Authentication | Read | Write | Create/Delete | Random | Version | Rename |
|---|---|---|---|---|---|---|---|---|
| CIFS | No | Yes | Yes | Yes | Yes | Read/Write | No | Yes |
| mime | No | No | Yes | No | No | No | No | No |
Naming
All filenames are treated as URIs. One of the consequences of this is you have to encode the '%' character using %25.
Depending on the filesystem additional characters are encoded if needed. This is done automatically, but might be reflected in the filename.
Examples
file:///somedir/some%25file.txt
Many file systems accept a userid and password as part of the url. However, storing a password in clear text in a file is usually unacceptable. To help with that Commons VFS provides a mechanism to encrypt the password. It should be noted though, that this is not completely secure since the password needs to be unencrypted before Commons VFS can use it.
To create an encrypted password do:
java -cp commons-vfs-2.0.jar org.apache.commons.vfs2.util.EncryptUtil encrypt mypassword
where mypassword is the password you want to encrypt. The result of this will be a single line of output containing uppercase hex characters. For example,
java -cp commons-vfs-2.0.jar org.apache.commons.vfs2.util.EncryptUtil encrypt WontUBee9 D7B82198B272F5C93790FEB38A73C7B8
Then cut the output returned and paste it into the URL as:
https://testuser:{D7B82198B272F5C93790FEB38A73C7B8}@myhost.com/svn/repos/vfstest/trunk
VFS treats a password enclosed in {} as being encrypted and will decrypt the password before using it.
Local Files
Provides access to the files on the local physical file system.
URI Format
[file://]_absolute-path_
Where_absolute-path_ is a valid absolute file name for the local platform. UNC names are supported under Windows.
Examples
file:///home/someuser/somedirfile:///C:/Documents and Settingsfile://///somehost/someshare/afile.txt/home/someuser/somedirc:\program files\some dirc:/program files/some dir
Zip, Jar and Tar
Provides read-only access to the contents of Zip, Jar and Tar files.
URI Format
zip://_arch-file-uri_[!_absolute-path_]
jar://_arch-file-uri_[!_absolute-path_]
tar://_arch-file-uri_[!_absolute-path_]
tgz://_arch-file-uri_[!_absolute-path_]
tbz2://_arch-file-uri_[!_absolute-path_]
Wherearch-file-uri refers to a file of any supported type, including other zip files. Note: if you would like to use the ! as normal character it must be escaped using %21.tgz and tbz2 are convenience for tar:gz and tar:bz2.
Examples
jar:../lib/classes.jar!/META-INF/manifest.mfzip:http://somehost/downloads/somefile.zipjar:zip:outer.zip!/nested.jar!/somedirjar:zip:outer.zip!/nested.jar!/some%21dirtar:gz:http://anyhost/dir/mytar.tar.gz!/mytar.tar!/path/in/tar/README.txttgz:file://anyhost/dir/mytar.tgz!/somepath/somefile
gzip and bzip2
Provides read-only access to the contents of gzip and bzip2 files.
URI Format
gz://_compressed-file-uri_
bz2://_compressed-file-uri_
Wherecompressed-file-uri refers to a file of any supported type. There is no need to add a ! part to the URI if you read the content of the file you always will get the uncompressed version.
Examples
gz:/my/gz/file.gz
HDFS
Provides (read-only) access to files in an Apache Hadoop File System (HDFS). On Windows the integration test is disabled by default, as it requires binaries.
URI Format
hdfs://_hostname_[:_port_][_absolute-path_]
Examples
hdfs://somehost:8080/downloads/some_dirhdfs://somehost:8080/downloads/some_file.ext
HTTP and HTTPS
Provides access to files on an HTTP server.
URI Format
http://[_username_[:_password_]@]_hostname_[:_port_][_absolute-path_]
https://[_username_[:_password_]@]_hostname_[:_port_][_absolute-path_]
File System Options
- proxyHost The proxy host to connect through.
- proxyPort The proxy port to use.
- proxyScheme The proxy scheme (http/https) to use.
- cookies An array of Cookies to add to the request.
- maxConnectionsPerHost The maximum number of connections allowed to a specific host and port. The default is 5.
- maxTotalConnections The maximum number of connections allowed to all hosts. The default is 50.
- keystoreFile The keystore file for SSL connections.
- keystorePass The keystore password.
- keystoreType The keystore type.
Examples
http://somehost:8080/downloads/somefile.jarhttp://myusername@somehost/index.html
WebDAV
Provides access to files on a WebDAV server through the modulescommons-vfs2-jackrabbit1 and commons-vfs2-jackrabbit2.
URI Format
webdav://[_username_[:_password_]@]_hostname_[:_port_][_absolute-path_]
File System Options
- versioning true if versioning should be enabled
- creatorName the user name to be identified with changes to a file. If not set the user name used to authenticate will be used.
Examples
webdav://somehost:8080/dist
FTP
Provides access to the files on an FTP server.
URI Format
ftp://[_username_[:_password_]@]_hostname_[:_port_][_relative-path_]
Examples
ftp://myusername:mypassword@somehost/pub/downloads/somefile.tgz
By default, the path is relative to the user's home directory. This can be changed with:
FtpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(options, false);
FTPS
Provides access to the files on an FTP server over SSL.
URI Format
ftps://[_username_[:_password_]@]_hostname_[:_port_][_absolute-path_]
Examples
ftps://myusername:mypassword@somehost/pub/downloads/somefile.tgz
SFTP
Provides access to the files on an SFTP server (that is, an SSH or SCP server).
URI Format
sftp://[_username_[:_password_]@]_hostname_[:_port_][_relative-path_]
Examples
sftp://myusername:mypassword@somehost/pub/downloads/somefile.tgz
By default, the path is relative to the user's home directory. This can be changed with:
FtpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(options, false);
CIFS
The CIFS (sandbox) filesystem provides access to a CIFS server, such as a Samba server, or a Windows share.
URI Format
smb://[_username_[:_password_]@]_hostname_[:_port_][_absolute-path_]
Examples
smb://somehost/home
Temporary Files
Provides access to a temporary file system, or scratchpad, that is deleted when Commons VFS shuts down. The temporary file system is backed by a local file system.
URI Format
tmp://[_absolute-path_]
Examples
tmp://dir/somefile.txt
Resource
This is not really a filesystem, it just tries to look up a resource using javas ClassLoader.getResource() and creates a VFS url for further processing.
URI Format
res://[_path_]
Examples
res://path/in/classpath/image.png
might result injar:file://my/path/to/images.jar!/path/in/classpath/image.png
RAM
A filesystem which stores all the data in memory (one byte array for each file content).
URI Format
ram://[_path_]
File System Options
- maxsize Maximum filesystem size (total bytes of all file contents).
Examples
ram:///any/path/to/file.txt
MIME
This (sandbox) filesystem can read mails and its attachements like archives.
If a part in the parsed mail has no name, a dummy name will be generated. The dummy name is: _body_part_X where X will be replaced by the part number.
URI Format
mime://_mime-file-uri_[!_absolute-path_]
Examples
mime:file:///your/path/mail/anymail.mime!/mime:file:///your/path/mail/anymail.mime!/filename.pdfmime:file:///your/path/mail/anymail.mime!/_body_part_0