Interface PathProcessor

All Known Implementing Classes:
DefaultPathProcessor, TestPathProcessor

public interface PathProcessor
A utility component to perform file-based operations.
Since:
2.0.0
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static interface 
    A listener object that is notified for every progress made while copying files.
  • Method Summary

    Modifier and Type
    Method
    Description
    default void
    copy(Path source, Path target)
    Copies the specified source file to the given target file.
    long
    copy(Path source, Path target, PathProcessor.ProgressListener listener)
    Copies the specified source file to the given target file.
    default void
    copyWithTimestamp(Path source, Path target)
    Same as copy(Path, Path) but sets source file last modified timestamp on target as well.
    default long
    lastModified(Path path, long defValue)
    Returns last modified of path in milliseconds, if exists.
    void
    move(Path source, Path target)
    Moves the specified source file to the given target file.
    void
    setLastModified(Path path, long value)
    Sets last modified of path in milliseconds, if exists.
    default long
    size(Path path, long defValue)
    Returns size of file, if exists.
    void
    write(Path target, InputStream source)
    Writes the given stream to a file.
    void
    write(Path target, String data)
    Writes the given data to a file.
  • Method Details

    • lastModified

      default long lastModified(Path path, long defValue)
      Returns last modified of path in milliseconds, if exists.
      Parameters:
      path - The path, may be null.
      Throws:
      UncheckedIOException - If an I/O error occurs.
    • setLastModified

      void setLastModified(Path path, long value) throws IOException
      Sets last modified of path in milliseconds, if exists.
      Parameters:
      path - The path, may be null.
      Throws:
      IOException - If an I/O error occurs. Some exceptions/reasons of failure to set mtime may be swallowed, and can be multiple, ranging from "file not found" to cases when FS does not support the setting the mtime.
      Since:
      2.0.0
    • size

      default long size(Path path, long defValue)
      Returns size of file, if exists.
      Parameters:
      path - The path, may be null.
      Throws:
      UncheckedIOException - If an I/O error occurs.
    • write

      void write(Path target, String data) throws IOException
      Writes the given data to a file. UTF-8 is assumed as encoding for the data. Creates the necessary directories for the target file. In case of an error, the created directories will be left on the file system.
      Parameters:
      target - The file to write to, must not be null. This file will be overwritten.
      data - The data to write, may be null.
      Throws:
      IOException - If an I/O error occurs.
    • write

      void write(Path target, InputStream source) throws IOException
      Writes the given stream to a file. Creates the necessary directories for the target file. In case of an error, the created directories will be left on the file system.
      Parameters:
      target - The file to write to, must not be null. This file will be overwritten.
      source - The stream to write to the file, must not be null.
      Throws:
      IOException - If an I/O error occurs.
    • move

      void move(Path source, Path target) throws IOException
      Moves the specified source file to the given target file. If the target file already exists, it is overwritten. Creates the necessary directories for the target file. In case of an error, the created directories will be left on the file system.
      Parameters:
      source - The file to move from, must not be null.
      target - The file to move to, must not be null.
      Throws:
      IOException - If an I/O error occurs.
    • copy

      default void copy(Path source, Path target) throws IOException
      Copies the specified source file to the given target file. Creates the necessary directories for the target file. In case of an error, the created directories will be left on the file system.
      Parameters:
      source - The file to copy from, must not be null.
      target - The file to copy to, must not be null.
      Throws:
      IOException - If an I/O error occurs.
    • copyWithTimestamp

      default void copyWithTimestamp(Path source, Path target) throws IOException
      Same as copy(Path, Path) but sets source file last modified timestamp on target as well.
      Parameters:
      source - The file to copy from, must not be null.
      target - The file to copy to, must not be null.
      Throws:
      IOException - If an I/O error occurs.
      Since:
      2.0.0
      See Also:
    • copy

      long copy(Path source, Path target, PathProcessor.ProgressListener listener) throws IOException
      Copies the specified source file to the given target file. Creates the necessary directories for the target file. In case of an error, the created directories will be left on the file system.
      Parameters:
      source - The file to copy from, must not be null.
      target - The file to copy to, must not be null.
      listener - The listener to notify about the copy progress, may be null.
      Returns:
      The number of copied bytes.
      Throws:
      IOException - If an I/O error occurs.