Class IOX

java.lang.Object
org.apache.jena.atlas.io.IOX

public class IOX extends Object
  • Field Details

    • currentDirectory

      public static final Path currentDirectory
  • Constructor Details

    • IOX

      public IOX()
  • Method Details

    • exception

      public static RuntimeIOException exception(IOException ioException)
      Convert an IOException into a RuntimeIOException.

      Idiom:

           catch(IOException ex) { throw new exception(ex); }
       
      Parameters:
      ioException -
      Returns:
      RuntimeIOException
    • exception

      public static RuntimeIOException exception(String message, IOException ioException)
      Convert an IOException into a RuntimeIOException.

      Idiom:

           catch(IOException ex) { throw new exception("Oh dear", ex); }
       
      Parameters:
      message -
      ioException -
      Returns:
      RuntimeIOException
    • run

      public static void run(IOX.ActionIO action)
      Run an action, converting an IOException into a RuntimeIOException.

      Idiom:

           run(()->...));
       
    • safeWrite

      public static boolean safeWrite(Path file, IOX.IOConsumer<OutputStream> writerAction)
      Write a file safely - the change happens (the function returns true) or something went wrong (the function throws a runtime exception) and the file is not changed.
    • safeWrite

      public static boolean safeWrite(Path file, Path tmpFile, IOX.IOConsumer<OutputStream> writerAction)
      Write a file safely - the change happens (the function returns true) or something went wrong (the function throws a runtime exception) and the file is not changed. Note that the tmpfile must be in the same directory as the actual file so an OS-atomic rename can be done.
    • safeWriteOrCopy

      public static boolean safeWriteOrCopy(Path file, Path tmpFile, IOX.IOConsumer<OutputStream> writerAction)
      Write a file safely, but allow system to use copy-delete if the change can not be done atomically. Prefer safeWrite(java.nio.file.Path, org.apache.jena.atlas.io.IOX.IOConsumer<java.io.OutputStream>) which requires an atomic move.
    • delete

      public static void delete(Path path)
      Delete a file.
    • move

      public static void move(Path src, Path dst)
      Atomically move a file.
    • moveAllowCopy

      public static void moveAllowCopy(Path src, Path dst)
      Move a file, allowing the system to copy-delete it if it can not be moved atomically.
    • deleteAll

      public static void deleteAll(String start)
    • deleteAll

      public static void deleteAll(Path start)
      Delete everything from a Path start point, including the path itself. Works on files or directories. Walks down the tree and deletes directories on the way backup.
    • copy

      public static void copy(String srcFilename, String dstFilename)
      Copy a file, not atomic. * Can copy to a directory or over an existing file.
      Parameters:
      srcFilename -
      dstFilename -
    • createDirectory

      public static void createDirectory(Path dir)
      Create a directory - throw a runtime exception if there are any problems. This function wraps Files.createDirectory.
    • readAll

      public static byte[] readAll(Path pathname)
      Read the whole of a file
    • writeAll

      public static void writeAll(Path pathname, byte[] value)
      Write the whole of a file
    • createTempFile

      public static Path createTempFile(Path dir, String prefix, String suffix, FileAttribute<?>... attrs)
      Return a temporary filename path.

      This operation is thread-safe.

    • uniqueDerivedPath

      public static Path uniqueDerivedPath(Path path, Function<String,String> basenameMapping)
      Generate a unique place related to path; Optionally, provide a mapping of old name to new namebase. This method always adds "-1", "-2" etc.
    • checkReadableFile

      public static void checkReadableFile(String file, Function<String,RuntimeException> exceptionMaker)
      Check whether a file name points to a readable, regular file. Generate an exception if not.
    • checkReadableFile

      public static void checkReadableFile(Path path, Function<String,RuntimeException> exceptionMaker)
      Check whether a file path points to a readable, regular file. Generate an exception if not.
    • checkReadableDirectory

      public static void checkReadableDirectory(String directory, Function<String,RuntimeException> exceptionMaker)
      Check whether a file path points to a readable directory. Generate an exception if not.
    • checkReadableDirectory

      public static void checkReadableDirectory(Path path, Function<String,RuntimeException> exceptionMaker)
      Check whether a file path points to a readable directory. Generate an exception if not.