Module bus.http

Interface DiskLruCache.DiskFile

Enclosing class:
DiskLruCache

public static interface DiskLruCache.DiskFile
Access to read and write files on a hierarchical data store. Most callers should use the SYSTEM implementation, which uses the host machine's local file system. Alternate implementations may be used to inject faults (for testing) or to transform stored data (to add encryption, for example).

All operations on a file system are racy. For example, guarding a call to source(java.io.File) with exists(java.io.File) does not guarantee that FileNotFoundException will not be thrown. The file may be moved between the two calls!

This interface is less ambitious than FileSystem introduced in Java 7. It lacks important features like file watching, metadata, permissions, and disk space information. In exchange for these limitations, this interface is easier to implement and works on all versions of Java and Android.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    The host machine's local file system.
  • Method Summary

    Modifier and Type
    Method
    Description
    org.miaixz.bus.core.io.sink.Sink
    Writes to file, appending if data is already present.
    void
    delete(File file)
    Deletes file if it exists.
    void
    deleteContents(File directory)
    Recursively delete the contents of directory.
    boolean
    exists(File file)
    Returns true if file exists on the file system.
    void
    rename(File from, File to)
    Renames from to to.
    org.miaixz.bus.core.io.sink.Sink
    sink(File file)
    Writes to file, discarding any data already present.
    long
    size(File file)
    Returns the number of bytes stored in file, or 0 if it does not exist.
    org.miaixz.bus.core.io.source.Source
    source(File file)
    Reads from file.
  • Field Details

  • Method Details

    • source

      org.miaixz.bus.core.io.source.Source source(File file) throws FileNotFoundException
      Reads from file.
      Parameters:
      file - the file to read from.
      Returns:
      a source for the file.
      Throws:
      FileNotFoundException - if the file does not exist.
    • sink

      org.miaixz.bus.core.io.sink.Sink sink(File file) throws FileNotFoundException
      Writes to file, discarding any data already present. Creates parent directories if necessary.
      Parameters:
      file - the file to write to.
      Returns:
      a sink for the file.
      Throws:
      FileNotFoundException - if the file cannot be created.
    • appendingSink

      org.miaixz.bus.core.io.sink.Sink appendingSink(File file) throws FileNotFoundException
      Writes to file, appending if data is already present. Creates parent directories if necessary.
      Parameters:
      file - the file to append to.
      Returns:
      a sink for the file.
      Throws:
      FileNotFoundException - if the file cannot be created.
    • delete

      void delete(File file) throws IOException
      Deletes file if it exists. Throws if the file exists and cannot be deleted.
      Parameters:
      file - the file to delete.
      Throws:
      IOException - if the file cannot be deleted.
    • exists

      boolean exists(File file)
      Returns true if file exists on the file system.
      Parameters:
      file - the file to check.
      Returns:
      true if the file exists.
    • size

      long size(File file)
      Returns the number of bytes stored in file, or 0 if it does not exist.
      Parameters:
      file - the file to measure.
      Returns:
      the size of the file in bytes.
    • rename

      void rename(File from, File to) throws IOException
      Renames from to to. Throws if the file cannot be renamed.
      Parameters:
      from - the source file.
      to - the destination file.
      Throws:
      IOException - if the file cannot be renamed.
    • deleteContents

      void deleteContents(File directory) throws IOException
      Recursively delete the contents of directory. Throws an IOException if any file could not be deleted, or if dir is not a readable directory.
      Parameters:
      directory - the directory to delete.
      Throws:
      IOException - if the contents cannot be deleted.