Package org.basex.io

Class IO

java.lang.Object
org.basex.io.IO
Direct Known Subclasses:
IOContent, IOFile, IOStream, IOUrl

public abstract class IO extends Object
Generic representation for inputs and outputs. The underlying source can be a local file (IOFile), a URL (IOUrl), a byte array (IOContent), or a stream (IOStream).
Author:
BaseX Team 2005-21, BSD License, Christian Gruen
  • Field Details

  • Method Details

    • get

      public static IO get(String location)

      Returns a class instance for the specified location string. The type of the returned instance depends on the string value:

      • IOFile: if the string starts with file:, or if it does not contain the substring ://, it is interpreted as local file instance
      • IOUrl: if it starts with a valid scheme, it is handled as URL
      • IOContent: otherwise, it is interpreted as XML fragment and internally represented as byte array
      If the content of the string value is known in advance, it is advisable to call the direct constructors of the correspondent sub class.
      Parameters:
      location - location
      Returns:
      IO reference
    • read

      public abstract byte[] read() throws IOException
      Returns the binary contents.
      Returns:
      binary contents
      Throws:
      IOException - I/O exception
    • string

      public final String string() throws IOException
      Returns the contents as string. The input encoding will be guessed by analyzing the first bytes. UTF-8 will be used as fallback.
      Returns:
      string contents
      Throws:
      IOException - I/O exception
    • exists

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

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

      public boolean isAbsolute()
      Tests if this is an absolute path.
      Returns:
      result of check
    • hasSuffix

      public final boolean hasSuffix(String... suffixes)
      Tests if the file suffix matches the specified suffixes.
      Parameters:
      suffixes - suffixes to compare with
      Returns:
      result of check
    • timeStamp

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

      public final void length(long length)
      Sets the input length.
      Parameters:
      length - length
    • length

      public long length()
      Returns the file length.
      Returns:
      file length
    • inputSource

      public abstract InputSource inputSource()
      Returns an input source.
      Returns:
      input source
    • streamSource

      public abstract StreamSource streamSource()
      Returns a stream source.
      Returns:
      stream source
    • inputStream

      public abstract InputStream inputStream() throws IOException
      Returns an input stream.
      Returns:
      input stream
      Throws:
      IOException - I/O exception
    • merge

      public final IO merge(String path)
      Merges two paths.
      Parameters:
      path - path to be merged
      Returns:
      resulting reference
    • isArchive

      public final boolean isArchive()
      Checks if this file is an archive.
      Returns:
      result of check
    • dbName

      public final String dbName()
      Generates a database name from the name of this resource. The path will be chopped and special characters from the remaining name will be removed.
      Returns:
      database name
    • name

      public final String name()
      Returns the name of the resource.
      Returns:
      file name
    • name

      public final void name(String name)
      Sets the name of the resource.
      Parameters:
      name - file name
    • path

      public final String path()
      Returns the full path. The path uses forward slashes, no matter which OS is used.
      Returns:
      path
    • dir

      public final String dir()
      Returns the directory path (all characters up to the last slash). No check will be performed if the directory exists.
      Returns:
      directory path
    • url

      public String url()
      Creates a URL from the specified path. Returns the original path for IO instances other than IOFile.
      Returns:
      URL
    • eq

      public boolean eq(IO io)
      Compares the filename of the specified IO reference.
      Parameters:
      io - io reference
      Returns:
      result of check
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • checkSuffix

      public static boolean checkSuffix(String path, String... suffixes)
      Tests if the file suffix of a path matches the specified suffixes.
      Parameters:
      path - path
      suffixes - suffixes to compare with
      Returns:
      result of check