Class LocalFileSystem

  • All Implemented Interfaces:
    FileSystem

    public class LocalFileSystem
    extends java.lang.Object
    implements FileSystem
    基于操作系统本地文件系统的驱动.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void copy​(java.lang.String source, java.lang.String destination, boolean replaceExisting)
      复制文件或目录,PathMeta保持不变。
      void createDirectory​(java.lang.String path)
      创建目录。目录已存在则忽略。
      void createSymbolicLink​(java.lang.String link, java.lang.String path)
      创建文件软链接,软链接文件不存在则创建,否则替换
      void delete​(java.lang.String path)
      删除文件或目录。
      java.util.stream.Stream<? extends PathMeta> directories​(java.lang.String path, java.lang.String search, boolean recursive, int offset, int limit, PathMetaSort sort)
      获取目录下子目录。
      boolean exists​(java.lang.String path)
      检查路径是否存在。
      java.util.stream.Stream<? extends PathMeta> files​(java.lang.String path, java.lang.String search, boolean recursive, int offset, int limit, PathMetaSort sort)
      获取目录下文件。
      <M extends PathMeta>
      M
      meta​(java.lang.String path)
      获取路径的元信息。
      void move​(java.lang.String source, java.lang.String destination, boolean replaceExisting)
      移动文件或目录,PathMeta保持不变。
      java.io.InputStream openReadStream​(java.lang.String path)
      用流的方式读取文件内容,调用方负责流的关闭。
      java.io.OutputStream openWriteStream​(java.lang.String path)
      用流的方式写入文件内容,调用方负责流的关闭。 当文件不存在时会自动创建。 以Append的方式写入。
      void put​(java.lang.String path, java.io.InputStream stream)
      如果文件未存在,则创建;否则替换。
      void put​(java.lang.String path, java.lang.CharSequence txt)
      如果文件未存在,则创建;否则替换。
      void touchCreation​(java.lang.String path)
      刷新文件或目录的 PathMeta.getCreationTime()
      void touchLastAccess​(java.lang.String path)
      刷新文件或目录的 PathMeta.getLastAccessTime()
      void touchLastModified​(java.lang.String path)
      刷新文件或目录的 PathMeta.getLastModifiedTime()
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • createDirectory

        public void createDirectory​(java.lang.String path)
        Description copied from interface: FileSystem
        创建目录。目录已存在则忽略。
        Specified by:
        createDirectory in interface FileSystem
        Parameters:
        path - 路径
      • put

        public void put​(java.lang.String path,
                        java.io.InputStream stream)
                 throws InvalidFileException
        Description copied from interface: FileSystem
        如果文件未存在,则创建;否则替换。
        Specified by:
        put in interface FileSystem
        Parameters:
        path - 要写入的路径
        stream - 输入流
        Throws:
        InvalidFileException - 无效文件
      • put

        public void put​(java.lang.String path,
                        java.lang.CharSequence txt)
                 throws InvalidFileException
        Description copied from interface: FileSystem
        如果文件未存在,则创建;否则替换。
        Specified by:
        put in interface FileSystem
        Parameters:
        path - 要写入的路径
        txt - 输入文本
        Throws:
        InvalidFileException - 无效文件
      • exists

        public boolean exists​(java.lang.String path)
        Description copied from interface: FileSystem
        检查路径是否存在。
        Specified by:
        exists in interface FileSystem
        Parameters:
        path - 路径
      • openWriteStream

        public java.io.OutputStream openWriteStream​(java.lang.String path)
                                             throws InvalidFileException
        Description copied from interface: FileSystem
        用流的方式写入文件内容,调用方负责流的关闭。
        • 当文件不存在时会自动创建。
        • 以Append的方式写入。
        Specified by:
        openWriteStream in interface FileSystem
        Parameters:
        path - 路径
        Throws:
        InvalidFileException - 无效文件
      • move

        public void move​(java.lang.String source,
                         java.lang.String destination,
                         boolean replaceExisting)
                  throws FileSystemException
        Description copied from interface: FileSystem
        移动文件或目录,PathMeta保持不变。
        Specified by:
        move in interface FileSystem
        Parameters:
        source - 源路径
        destination - 目标路径
        replaceExisting - 如果true,替换现存的文件,否则忽略移动。
        Throws:
        PathNotFoundException - 源路径不存在
        FileSystemException - 文件系统操作失败
      • copy

        public void copy​(java.lang.String source,
                         java.lang.String destination,
                         boolean replaceExisting)
                  throws FileSystemException
        Description copied from interface: FileSystem
        复制文件或目录,PathMeta保持不变。
        Specified by:
        copy in interface FileSystem
        Parameters:
        source - 源路径
        destination - 目标路径
        replaceExisting - 如果true,替换现存的文件,否则忽略复制。
        Throws:
        PathNotFoundException - 源路径不存在
        FileSystemException - 文件系统操作失败
      • delete

        public void delete​(java.lang.String path)
        Description copied from interface: FileSystem
        删除文件或目录。
        Specified by:
        delete in interface FileSystem
        Parameters:
        path - 路径
      • meta

        public <M extends PathMeta> M meta​(java.lang.String path)
        Description copied from interface: FileSystem
        获取路径的元信息。
        Specified by:
        meta in interface FileSystem
        Parameters:
        path - 路径
        Returns:
        路径不存在时,返回null。
      • directories

        public java.util.stream.Stream<? extends PathMeta> directories​(java.lang.String path,
                                                                       java.lang.String search,
                                                                       boolean recursive,
                                                                       int offset,
                                                                       int limit,
                                                                       PathMetaSort sort)
                                                                throws PathNotFoundException
        Description copied from interface: FileSystem
        获取目录下子目录。
        Specified by:
        directories in interface FileSystem
        Parameters:
        path - 目录路径
        search - 以contains方式查找目录名。如果为空,返回所有结果。
        recursive - 如果true,则递归搜索所有子目录。
        offset - 开始位置索引。小于0则忽略。
        limit - 数量限制。小于0则忽略。
        sort - 排序选项。选项之间是互斥的。
        Throws:
        PathNotFoundException - 目录不存在
      • files

        public java.util.stream.Stream<? extends PathMeta> files​(java.lang.String path,
                                                                 java.lang.String search,
                                                                 boolean recursive,
                                                                 int offset,
                                                                 int limit,
                                                                 PathMetaSort sort)
                                                          throws PathNotFoundException
        Description copied from interface: FileSystem
        获取目录下文件。
        Specified by:
        files in interface FileSystem
        Parameters:
        path - 目录路径
        search - 以contains方式查找文件名。如果为空,返回所有结果。
        recursive - 如果true,则递归搜索所有子目录。
        offset - 开始位置索引。小于0则忽略。
        limit - 数量限制。小于0则忽略。
        sort - 排序选项。选项之间是互斥的。
        Throws:
        PathNotFoundException - 目录不存在
      • createSymbolicLink

        public void createSymbolicLink​(java.lang.String link,
                                       java.lang.String path)
                                throws InvalidFileException
        Description copied from interface: FileSystem
        创建文件软链接,软链接文件不存在则创建,否则替换
        Specified by:
        createSymbolicLink in interface FileSystem
        Parameters:
        link - 软链接路径
        path - 目标路径
        Throws:
        InvalidFileException - 无效文件