Class IO
java.lang.Object
org.variantsync.diffdetective.util.IO
Util class for exporting data.
- Author:
- Sören Viegener
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
Appends the given text to the given file.static void
createParentDirectories
(Path file) Creates all parent directories offile
.static void
Exports data to a csv-filestatic BufferedOutputStream
newBufferedOutputStream
(Path file, OpenOption... openOptions) Same asFiles.newOutputStream(java.nio.file.Path, java.nio.file.OpenOption...)
but creates all parent directories offile
and wraps the result in aBufferedOutputStream
.static boolean
tryDeleteFile
(Path file) Deletesfile
if it exists.tryParseURI
(String uri) Parses the stringuri
into anURI
object.static void
Writesdata
to the fileoutputPath
.static void
Writes 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 offile
and 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 withtext
text
- text to write to the file- Throws:
IOException
- ifp
already 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 existstext
is appended to the file.- Parameters:
p
- file to create and fill withtext
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
Writesdata
to the fileoutputPath
.outputPath
and its parent directories will be created if necessary. IfoutputPath
already exists, no data is written. -
tryParseURI
Parses the stringuri
into anURI
object.The purpose of this function is to handle parse failures in a functional way (using
Optional
instead of with exceptions.- Parameters:
uri
- theString
to be parsed as anURI
- Returns:
- the parsed URI if
uri
is valid or an empty optional on parse failures
-
tryDeleteFile
Deletesfile
if it exists.- Returns:
false
if the file system signals an error
-