Class IoUtils

java.lang.Object
io.quarkus.bootstrap.util.IoUtils

public class IoUtils extends Object
Author:
Alexey Loubyansky
  • Constructor Details

    • IoUtils

      public IoUtils()
  • Method Details

    • createTmpDir

      public static Path createTmpDir(String name)
    • createRandomTmpDir

      public static Path createRandomTmpDir()
    • createRandomDir

      public static Path createRandomDir(Path parentDir)
    • mkdirs

      public static Path mkdirs(Path dir)
    • recursiveDelete

      public static void recursiveDelete(Path root)
      Recursively delete the file or directory given by root. The implementation will attempt to do so in a secure manner. Any problems encountered will be logged at DEBUG level.
      Parameters:
      root - the root path (must not be null)
    • createOrEmptyDir

      public static void createOrEmptyDir(Path dir) throws IOException
      Creates a new empty directory or empties an existing one. Any problems encountered while emptying the directory will be logged at DEBUG level.
      Parameters:
      dir - directory
      Throws:
      IOException - if creating or accessing the directory itself fails
    • copy

      public static Path copy(Path source, Path target) throws IOException
      Throws:
      IOException
    • readFile

      @Deprecated(forRemoval=true) public static String readFile(Path file) throws IOException
      Deprecated, for removal: This API element is subject to removal in a future version.
      Read the contents of a file as a string.
      Parameters:
      file - the file to read (must not be null)
      Returns:
      the file content, as a string (not null)
      Throws:
      IOException - if an error occurs when reading the file
    • copy

      public static void copy(OutputStream out, InputStream in) throws IOException
      Copy the input stream to the given output stream. Calling this method is identical to calling in.transferTo(out).
      Parameters:
      out - the output stream (must not be null)
      in - the input stream (must not be null)
      Throws:
      IOException - if an error occurs during the copy
      See Also:
    • writeFile

      public static void writeFile(Path file, String content) throws IOException
      Write a string to a file using UTF-8 encoding. The file will be created if it does not exist, and truncated if it is not empty.
      Parameters:
      file - the file to write (must not be null)
      content - the string to write to the file (must not be null)
      Throws:
      IOException - if an error occurs when writing the file