Apache VFS (1): Basic Introduction

Source: Internet
Author: User
Tags ftp file
Navigation of this series of articles

Apache VFS (1): Basic Introduction

Apache VFS (2): file monitoring and monitoring

Apache VFS (3): file filter and Selector

Apache VFS (4): Events

Apache VFS (5): use it!

Apache VFS (6): several important conceptual Interfaces

Apache VFS (7): File Manager File Parsing Method

Apache

VFS

It provides a virtual file system that allows you to easily deal with local file systems, FTP file systems, and HTTP files through programs.

In Apache

VFS

CoreFileObject Interface

.
It represents a file, and Java
File has more extended functions and information. There are many file objects implementing the FileObject interface: for example, the AbstractFileObjet abstract class provides some
FileObject implementation. Most FileObject implementation classes inherit the AbstractFileObject class:

  1. LocalFile: (it's strange why it's not LocalFileObject)
  2. Ftpfileobject
  3. Httpfileobject
  4. Sftpfileobject
  5. Zipfileobject
  6. Tarfileobject
  7. Ramfileobject
  8. Urlfileobject
  9. Delegatefileobject
  10. Compressedfileobject

FileObject represents a file that can be used to access the file content and structure. Files are organized in hierarchies. Each hierarchies forms a file system. A file system is like a file system in a local operating system, such as a Windows File System, an Http server, or a Zip file package.

There are two types of files:Directory

AndCommon File

. Common files have data or content, while directories do not include content. They can only contain other files. Common files cannot contain other files.

File Name

FileObject has a FileName object. The object name is processed as an independent object. The file name is unchangeable. There are many methods for object names:

  1. Getbasename
  2. Getdepth
  3. Getextension
  4. Getfriendlyuri
  5. Getparent
  6. Getpath
  7. Getroot
  8. And so on.


File Content reading

Note: Unlike Java File, FileObject hasFilecontent object

To access the file content, use the FileObject. getFileContent () method. This method returns a FileContent object. FileContent indicates the content of a file.

To put it simply, use: FileContent.Getinputstream ()

Use: FileContent.Getoutputstream ()

There isFinal abstractfileobject

.

Important FileContent methods include:

  1. Close all resources used to close the file content, including all open file streams.Be careful !!

  2. GET/set attribute/attributes: it cannot be used currently. Unless you rewrite it yourself, you actually call the doget/setattribute method of abstractfileobject.
  3. Getcontentinfo returnsContentInfo object

    The ContentInfo OBJECT records the content type and encoding information.

  4. Getinputstream Read File Content
  5. Getoutputstream Write File Content
  6. IsOpen check to see if the file has opened the file stream
  7. GetFile returns the FileObject object.
  8. Get/setLastModifiedTime


File Operations

You can use FileObject to create, delete, rename, and copy basic file operations.

  1. CopyFrom (FileObject src, FileSelector selector) copies from the source file in other places to this file, including the source file sub-files, there is a file selector parameter and the source file parameter
  2. Delete () delete this file
  3. Delete (FileSelector selector) deletes all sub-files of the file that match the file selector.
  4. CreateFile () if this file does not exist, create it
  5. CreateFolder () If this directory does not exist, create it

VFS

To support advanced operations, such as working with version control tools, FileOperation objects are provided, but VFS

There is no implementation at all. If you want to play, you can do it yourself.

Criticize VFS here

: VFS

Of
Some aspects of development are unreasonable. For example, FileObject supports setting attributes for files. Later, it was found that its AbstractFileObject
The getAttributes () method returns only one empty Map, and the setAttribute () method throws an unsupported exception. This function is very simple. If you
If necessary, change it. Therefore, use VFS

Pay attention to these traps.On your own risk!

 

Source: http://alartin.javaeye.com/blog/92053

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.