日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Apache VFS:基本介绍

發(fā)布時間:2024/4/17 编程问答 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Apache VFS:基本介绍 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

http://alartin.iteye.com/blog/92053

Apache VFS提供了一種虛擬文件系統,能夠讓你通過程序很方便的和位于本地文件系統,FTP文件系統,HTTP文件打交道。
在Apache VFS中核心是FileObject接口。它代表一個文件,和Java File不同,它具有更多延伸的功能和信息。實現FileObject接口的文件對象有很多:例如AbstractFileObjet抽象類提供了部分FileObject實現。大部分FileObject實現類都繼承AbstractFileObject類:
  • LocalFile:(很奇怪為什么不是LocalFileObject)
  • FtpFileObject
  • HttpFileObject
  • SftpFileObject
  • ZipFileObject
  • TarFileObject
  • RamFileObject
  • UrlFileObject
  • DelegateFileObject
  • CompressedFileObject
  • FileObject代表一個文件,能夠用來訪問文件內容和結構。文件是以層次結構組織的,每個層次組織形成一個文件系統。一個文件系統就像本地操作系統中的文件系統一樣,例如Windows文件系統,或者一個Http服務器,或者一個Zip文件包。

    文件有兩種類型: 目錄普通文件。普通文件擁有數據或者說內容,而目錄不含有內容,只能包含其他文件,普通文件不能包含其他文件。

    文件名
    FileObject擁有一個FileName對象,將文件名字作為一個獨立的對象處理。文件名是不可變的。文件名對象有很多方法:
  • getBaseName
  • getDepth
  • getExtension
  • getFriendlyURI
  • getParent
  • getPath
  • getRoot
  • 等等

  • 文件內容的讀取
    注意:和Java File不同的是FileObject擁有一個 FileContent對象,如果想訪問文件內容的話,需要使用FileObject.getFileContent()方法,這個方法返回一個FileContent對象。FileContent代表一個文件的內容。
    簡單的說讀取文件內容使用:FileContent. getInputStream()
    寫內容使用:FileContent. getOutputStream()
    FileContent內部有一個 final AbstractFileObject的引用。

    FileContent的重要方法有:
  • close 關閉文件內容使用的所有資源,包括所有打開的文件流。當心!!
  • get/set Attribute/Attributes: 不能用目前,除非自己重寫,其實調用AbstractFileObject的doGet/SetAttribute方法
  • getContentInfo 返回一個ContentInfo對象, ContentInfo對象記錄了內容的類型和編碼信息
  • getInputStream 讀文件內容
  • getOutputStream 寫文件內容
  • isOpen 檢查看看該文件有沒有打開的文件流
  • getFile 返回FileObject對象
  • get/setLastModifiedTime

  • 文件的操作
    基本的文件操作例如創(chuàng)建,刪除,重命名,拷貝都可以通過FileObject來完成。
  • copyFrom(FileObject src,FileSelector selector) 從其他地方的源文件拷貝到這個文件中,包括源文件的子文件,有一個文件選擇器參數和源文件參數
  • delete() 刪除此文件
  • delete(FileSelector selector) 刪除符合文件選擇器的所有該文件的子文件
  • createFile() 如果這個文件不存在,創(chuàng)建它
  • createFolder() 如果這個目錄不存在,創(chuàng)建它
  • VFS為了支持高級的操作例如和版本控制工具配合,提供了FileOperation對象,不過VFS根本沒有任何實現,如果你想玩,自己玩去吧。
    在這里批判一下VFS: VFS的開發(fā)有些地方非常不合理,例如FileObject號稱支持對文件設置屬性,后來發(fā)現其AbstractFileObject的getAttributes()方法只返回一個空Map,而setAttribute()更離譜,干脆直接拋出不支持的異常。這個功能非常簡單啊,如果你需要的話,自己改一下吧。因此,使用VFS時,千萬注意這些陷阱,誰讓這是開源軟件那 ON YOUR OWN RISK!

    ?

    =============

    Commons VFS currently supports the following file systems:

    ·???????? FTP

    ·???????? Local Files

    ·???????? HTTP and HTTPS

    ·???????? SFTP

    ·???????? Temporary Files

    ·???????? Zip, Jar and Tar (uncompressed, tgz or tbz2)

    ·???????? gzip and bzip2

    ·???????? res

    ·???????? ram

    ·???????? mime

    Things from the sandbox

    The following file systems are in development:

    ·???????? WebDAV
    We can't release WebDAV as we depend on an snapshot, thus it is in our sandbox.

    ·???????? CIFS

    ·???????? mime

    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 needet. This is done automatically, but might be reflected in the filename.

    Examples

    ·???????? file:///somedir/some%25file.txt

    Local Files

    Provides access to the files on the local physical file system.

    URI Format

    [file://] absolute-path

    Where absolute-pathis a valid absolute file name for the local platform. UNC names are supported under Windows.

    Examples

    ·???????? file:///home/someuser/somedir

    ·???????? file:///C:/Documents and Settings

    ·???????? file:/somehost/someshare/afile.txt

    ·???????? /home/someuser/somedir

    ·???????? c:\program files\some dir

    ·???????? c:/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 ]

    Where arch-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.mf

    ·???????? zip:http://somehost/downloads/somefile.zip

    ·???????? jar:zip:outer.zip!/nested.jar!/somedir

    ·???????? jar:zip:outer.zip!/nested.jar!/some%21dir

    ·???????? tar:gz:http://anyhost/dir/mytar.tar.gz!/mytar.tar!/path/in/tar/README.txt

    ·???????? tgz: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

    Where compressed-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

    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 ]

    Examples

    ·???????? http://somehost:8080/downloads/somefile.jar

    ·???????? http://myusername@somehost/index.html

    WebDAV

    Provides access to files on a WebDAV server.

    URI Format

    webdav://[ username [: password ]@] hostname [: port ][ absolute-path ]

    Examples

    ·???????? webdav://somehost:8080/dist

    ?

    • WebDAV(“Web-based?Distributed?Authoring?and?Versioning”?的縮寫)是一個標準HTTP協議的擴展,把web變成一個可讀寫的媒體,作為當今基本的只讀媒體的替代。原理就是目錄和文件時可以共享的?都是可讀寫的對象?通過web。RFCs2518和3253描述了WebDAV/DeltaV?對于HTTP的擴展,存放于(隨之有許多其它有用的信息)http://www.webdav.org/。

      已經有一些操作系統文件瀏覽器可以使用WebDAV裝配網絡目錄,在Win32中,Windows瀏覽器可以像普通共享文件夾一樣瀏覽叫做網絡文件夾(只是一個設置好WebDAV的網絡位置)的目錄,在Mac?OS?X也有這個能力,就像Nautilus和Konqueror作的(分別對應GNOME和KDE)。?

    FTP

    Provides access to the files on an FTP server.

    URI Format

    ftp://[ username [: password ]@] hostname [: port ][ absolute-path ]

    Examples

    ·???????? ftp://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 ][ absolute-path ]

    Examples

    ·???????? sftp://myusername:mypassword@somehost/pub/downloads/somefile.tgz

    CIFS

    Provides access to the files on 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

    res

    This is not really a filesystem, it just tries to lookup 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 in
    jar:file://my/path/to/images.jar!/path/in/classpath/image.png

    ram

    A filesystem which stores all the data in memory. You can configure the max size and a predicate (FileSelector). The predicate will be used to check if it is allowed to add a given file.

    URI Format

    ram://[ path ]

    Examples

    ·???????? ram:///any/path/to/file.txt

    mime

    This 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.pdf

    ·???????? mime:file:///your/path/mail/anymail.mime!/_body_part_0

    ?

    ?

    總結

    以上是生活随笔為你收集整理的Apache VFS:基本介绍的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。