Package org.basex.io

Class IOFile

java.lang.Object
org.basex.io.IO
org.basex.io.IOFile

public final class IOFile extends IO
IO reference, representing a local file or directory path.
Author:
BaseX Team 2005-21, BSD License, Christian Gruen
  • Field Details

    • NO_HIDDEN

      public static final FileFilter NO_HIDDEN
      Ignore files starting with a dot.
  • Constructor Details

    • IOFile

      public IOFile(File file)
      Constructor.
      Parameters:
      file - file reference
    • IOFile

      public IOFile(String path)
      Constructor.
      Parameters:
      path - file path
    • IOFile

      public IOFile(String dir, String child)
      Constructor.
      Parameters:
      dir - parent directory string
      child - child directory string
    • IOFile

      public IOFile(IOFile dir, String child)
      Constructor.
      Parameters:
      dir - directory string
      child - child path string
  • Method Details

    • file

      public File file()
      Returns the file reference.
      Returns:
      file reference
    • touch

      public boolean touch()
      Creates a new instance of this file.
      Returns:
      success flag
    • read

      public byte[] read() throws IOException
      Description copied from class: IO
      Returns the binary contents.
      Specified by:
      read in class IO
      Returns:
      binary contents
      Throws:
      IOException - I/O exception
    • exists

      public boolean exists()
      Description copied from class: IO
      Tests if the reference exists. Returns true for IO instances other than IOFile.
      Overrides:
      exists in class IO
      Returns:
      result of check
    • isDir

      public boolean isDir()
      Description copied from class: IO
      Tests if this is a local directory instance, or if the path ends with a slash.
      Overrides:
      isDir in class IO
      Returns:
      result of check
    • isAbsolute

      public boolean isAbsolute()
      Description copied from class: IO
      Tests if this is an absolute path.
      Overrides:
      isAbsolute in class IO
      Returns:
      result of check
    • timeStamp

      public long timeStamp()
      Description copied from class: IO
      Returns the time stamp (modification date) of this file. Returns the current time for IO instances other than IOFile.
      Overrides:
      timeStamp in class IO
      Returns:
      time stamp
    • length

      public long length()
      Description copied from class: IO
      Returns the file length.
      Overrides:
      length in class IO
      Returns:
      file length
    • inputSource

      public InputSource inputSource()
      Description copied from class: IO
      Returns an input source.
      Specified by:
      inputSource in class IO
      Returns:
      input source
    • streamSource

      public StreamSource streamSource()
      Description copied from class: IO
      Returns a stream source.
      Specified by:
      streamSource in class IO
      Returns:
      stream source
    • inputStream

      public FileInputStream inputStream() throws IOException
      Description copied from class: IO
      Returns an input stream.
      Specified by:
      inputStream in class IO
      Returns:
      input stream
      Throws:
      IOException - I/O exception
    • outputStream

      public FileOutputStream outputStream() throws IOException
      Returns an output stream.
      Returns:
      output stream
      Throws:
      IOException - I/O exception
    • resolve

      public IOFile resolve(String path)
      Resolves two paths.
      Parameters:
      path - file path (relative or absolute)
      Returns:
      resulting path
    • md

      public boolean md()
      Recursively creates the directory if it does not exist yet.
      Returns:
      true if the directory exists or has been created
    • parent

      public IOFile parent()
      Returns the parent of this file or directory or null if there is no parent directory.
      Returns:
      directory or null
    • children

      public IOFile[] children()
      Returns the children of the path.
      Returns:
      children
    • children

      public IOFile[] children(String regex)
      Returns the children of the path that match the specified regular expression.
      Parameters:
      regex - regular expression pattern
      Returns:
      children
    • children

      public IOFile[] children(FileFilter filter)
      Returns the children of the path that match the specified filter.
      Parameters:
      filter - file filter
      Returns:
      children
    • descendants

      public StringList descendants()
      Returns the relative paths of all descendant files (excluding directories).
      Returns:
      relative paths
    • descendants

      public StringList descendants(FileFilter filter)
      Returns the relative paths of all descendant non-filtered files (excluding directories).
      Parameters:
      filter - file filter
      Returns:
      relative paths
    • write

      public void write(String string) throws IOException
      Writes the specified string as UTF8.
      Parameters:
      string - string
      Throws:
      IOException - I/O exception
    • write

      public void write(byte[] bytes) throws IOException
      Writes the specified byte array.
      Parameters:
      bytes - bytes
      Throws:
      IOException - I/O exception
    • write

      public void write(InputStream is) throws IOException
      Writes the specified input. The specified input stream is eventually closed.
      Parameters:
      is - input stream
      Throws:
      IOException - I/O exception
    • delete

      public boolean delete()
      Deletes the file, or the directory and its children.
      Returns:
      true if the file does not exist or has been deleted
    • rename

      public boolean rename(IOFile target)
      Renames a file to the specified path. The path must not exist yet.
      Parameters:
      target - target reference
      Returns:
      success flag
    • copyTo

      public void copyTo(IOFile target) throws IOException
      Copies a file to another target.
      Parameters:
      target - target
      Throws:
      IOException - I/O exception
    • eq

      public boolean eq(IO io)
      Description copied from class: IO
      Compares the filename of the specified IO reference.
      Overrides:
      eq in class IO
      Parameters:
      io - io reference
      Returns:
      result of check
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • url

      public String url()
      Description copied from class: IO
      Creates a URL from the specified path. Returns the original path for IO instances other than IOFile.
      Overrides:
      url in class IO
      Returns:
      URL
    • open

      public void open() throws IOException
      Opens the file externally.
      Throws:
      IOException - I/O exception
    • normalize

      public IOFile normalize()
      Returns a native file path representation. If normalization fails, returns the original path.
      Returns:
      path
    • isHidden

      public boolean isHidden()
      Checks if a file is hidden.
      Returns:
      result of check
    • ignore

      public boolean ignore()
      Checks if the parent directory of this file can be ignored.
      Returns:
      result of check
    • isValidName

      public static boolean isValidName(String name)
      Checks if the specified string is a valid file name.
      Parameters:
      name - file name
      Returns:
      result of check
    • isValid

      public static boolean isValid(String path)
      Checks if the specified string is a valid file reference.
      Parameters:
      path - path string
      Returns:
      result of check
    • regex

      public static String regex(String glob)
      Converts a name filter (glob) to a regular expression.
      Parameters:
      glob - filter
      Returns:
      regular expression
    • regex

      public static String regex(String glob, boolean substring)
      Converts a file filter (glob) to a regular expression. A filter may contain asterisks (*) and question marks (?); commas (,) are used to separate multiple filters.
      Parameters:
      glob - filter
      substring - accept substring in the result
      Returns:
      regular expression