Class TestFileUtils

java.lang.Object
org.eclipse.aether.internal.test.util.TestFileUtils

public class TestFileUtils extends Object
Provides utility methods to read and write (temporary) files.
  • Method Details

    • deleteTempFiles

      @Deprecated public static void deleteTempFiles() throws IOException
      Deprecated.
      use the JUnit 5 @TempDir extension instead, which cleans up after itself
      Deletes the files created by the temp-file helpers of this class.
      Throws:
      IOException - if an I/O error occurs
    • deleteFile

      public static void deleteFile(File file) throws IOException
      Throws:
      IOException
    • mkdirs

      @Deprecated public static boolean mkdirs(File directory)
      Deprecated.
      use Files.createDirectories(Path) instead
      Creates a directory and its missing parents.
      Parameters:
      directory - the directory to create
      Returns:
      true if the directory exists afterwards
    • createTempFile

      @Deprecated public static File createTempFile(String contents) throws IOException
      Deprecated.
      use the JUnit 5 @TempDir extension instead
      Creates a temporary file with the given UTF-8 content.
      Parameters:
      contents - the content to write
      Returns:
      the temporary file
      Throws:
      IOException - if an I/O error occurs
    • createTempFile

      @Deprecated public static File createTempFile(byte[] pattern, int repeat) throws IOException
      Deprecated.
      use the JUnit 5 @TempDir extension instead
      Creates a temporary file holding the byte pattern the given number of times.
      Parameters:
      pattern - the bytes to repeat
      repeat - how many times the pattern is written
      Returns:
      the temporary file
      Throws:
      IOException - if an I/O error occurs
    • createTempDir

      @Deprecated public static File createTempDir() throws IOException
      Deprecated.
      use the JUnit 5 @TempDir extension instead
      Creates a temporary directory.
      Returns:
      the temporary directory
      Throws:
      IOException - if an I/O error occurs
    • createTempDir

      @Deprecated public static File createTempDir(String suffix) throws IOException
      Deprecated.
      use the JUnit 5 @TempDir extension instead
      Creates a temporary directory.
      Returns:
      the temporary directory
      Throws:
      IOException - if an I/O error occurs
    • copyFile

      public static long copyFile(File source, File target) throws IOException
      Throws:
      IOException
    • readBytes

      @Deprecated public static byte[] readBytes(File file) throws IOException
      Deprecated.
      use Files.readAllBytes(Path) instead
      Reads the contents of a file into a byte array.
      Parameters:
      file - the file to read
      Returns:
      the contents of the file as a byte array
      Throws:
      IOException - if an I/O error occurs
    • writeBytes

      @Deprecated public static void writeBytes(File file, byte[] pattern, int repeat) throws IOException
      Deprecated.
      use Files.write(Path, byte[]) instead; it writes the array once, so for repeat > 1 build the repeated bytes first
      Writes a byte pattern to a file the given number of times.
      Parameters:
      file - the file to write
      pattern - the bytes to repeat
      repeat - how many times the pattern is written
      Throws:
      IOException - if an I/O error occurs
    • readString

      public static String readString(File file) throws IOException
      Throws:
      IOException
    • writeString

      @Deprecated public static void writeString(File file, String content) throws IOException
      Deprecated.
      use Files.write(Path, byte[]) instead
      Writes a UTF-8 string to a file.
      Parameters:
      file - the file to write
      content - the content to write
      Throws:
      IOException - if an I/O error occurs
    • writeString

      @Deprecated public static void writeString(File file, String content, long timestamp) throws IOException
      Deprecated.
      use Files.write(Path, byte[]) and Files.setLastModifiedTime(Path, FileTime) instead
      Writes a UTF-8 string to a file and sets its last-modified time.
      Parameters:
      file - the file to write
      content - the content to write
      timestamp - the last-modified time to set, in milliseconds since the epoch
      Throws:
      IOException - if an I/O error occurs
    • readProps

      public static void readProps(File file, Properties props) throws IOException
      Throws:
      IOException
    • writeProps

      public static void writeProps(File file, Properties props) throws IOException
      Throws:
      IOException