java.lang.Object
org.variantsync.diffdetective.util.IO

public class IO extends Object
Util class for exporting data.
Author:
Sören Viegener
  • Field Details

  • Constructor Details

    • IO

      public IO()
  • Method Details

    • exportCsv

      public static void exportCsv(String fileName, String[] headers, Object[]... objects) throws FileNotFoundException
      Exports data to a csv-file
      Parameters:
      fileName - Name of the file to export to
      headers - Names of the headers of the table
      objects - Array of array of objects. The amount of objects has to equal the length of the headers array
      Throws:
      FileNotFoundException - When the fileName is not a valid file path
    • createParentDirectories

      public static void createParentDirectories(Path file) throws IOException
      Creates all parent directories of file.
      Throws:
      IOException
    • newBufferedOutputStream

      public static BufferedOutputStream newBufferedOutputStream(Path file, OpenOption... openOptions) throws IOException
      Same as Files.newOutputStream(java.nio.file.Path, java.nio.file.OpenOption...) but creates all parent directories of file and wraps the result in a BufferedOutputStream.
      Throws:
      IOException
    • write

      public static void write(Path p, String text) throws IOException
      Writes the given text to the given file. Creates a new file and its parent directories if necessary. It assumes that no file exists yet at the given path.
      Parameters:
      p - file to create and fill with text
      text - text to write to the file
      Throws:
      IOException - if p already exists, an I/O error occurs writing to or creating the file, or the text cannot be encoded using UTF-8
    • append

      public static void append(Path p, String text) throws IOException
      Appends the given text to the given file. Creates a new file and its parent directories if necessary. It the file already exists text is appended to the file.
      Parameters:
      p - file to create and fill with text
      text - text to write to the file
      Throws:
      IOException - if an I/O error occurs appending to or creating the file, or the text cannot be encoded using UTF-8
    • tryWrite

      public static void tryWrite(Path outputPath, String data)
      Writes data to the file outputPath. outputPath and its parent directories will be created if necessary. If outputPath already exists, no data is written.
    • tryParseURI

      public static Optional<URI> tryParseURI(String uri)
      Parses the string uri into an URI object.

      The purpose of this function is to handle parse failures in a functional way (using Optional instead of with exceptions.

      Parameters:
      uri - the String to be parsed as an URI
      Returns:
      the parsed URI if uri is valid or an empty optional on parse failures
    • tryDeleteFile

      public static boolean tryDeleteFile(Path file)
      Deletes file if it exists.
      Returns:
      false if the file system signals an error