Class IO
java.lang.Object
org.variantsync.diffdetective.util.IO
Util class for exporting data.
- Author:
- Sören Viegener
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidAppends the given text to the given file.static voidcreateParentDirectories(Path file) Creates all parent directories offile.static voidExports data to a csv-filestatic BufferedOutputStreamnewBufferedOutputStream(Path file, OpenOption... openOptions) Same asFiles.newOutputStream(java.nio.file.Path, java.nio.file.OpenOption...)but creates all parent directories offileand wraps the result in aBufferedOutputStream.static booleantryDeleteFile(Path file) Deletesfileif it exists.tryParseURI(String uri) Parses the stringuriinto anURIobject.static voidWritesdatato the fileoutputPath.static voidWrites the given text to the given file.
-
Field Details
-
CSV_DELIMITER
- See Also:
-
-
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 toheaders- Names of the headers of the tableobjects- 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
Creates all parent directories offile.- Throws:
IOException
-
newBufferedOutputStream
public static BufferedOutputStream newBufferedOutputStream(Path file, OpenOption... openOptions) throws IOException Same asFiles.newOutputStream(java.nio.file.Path, java.nio.file.OpenOption...)but creates all parent directories offileand wraps the result in aBufferedOutputStream.- Throws:
IOException
-
write
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 withtexttext- text to write to the file- Throws:
IOException- ifpalready exists, an I/O error occurs writing to or creating the file, or the text cannot be encoded using UTF-8
-
append
Appends the given text to the given file. Creates a new file and its parent directories if necessary. It the file already existstextis appended to the file.- Parameters:
p- file to create and fill withtexttext- 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
Writesdatato the fileoutputPath.outputPathand its parent directories will be created if necessary. IfoutputPathalready exists, no data is written. -
tryParseURI
Parses the stringuriinto anURIobject.The purpose of this function is to handle parse failures in a functional way (using
Optionalinstead of with exceptions.- Parameters:
uri- theStringto be parsed as anURI- Returns:
- the parsed URI if
uriis valid or an empty optional on parse failures
-
tryDeleteFile
Deletesfileif it exists.- Returns:
falseif the file system signals an error
-