Package com.compomics.util.io.flat
Class SimpleFileWriter
java.lang.Object
com.compomics.util.io.flat.SimpleFileWriter
- All Implemented Interfaces:
AutoCloseable
public class SimpleFileWriter extends Object implements AutoCloseable
Simple gz file writer that is thread safe and throws exceptions as runtime
exceptions.
- Author:
- Marc Vaudel
-
Constructor Summary
Constructors Constructor Description SimpleFileWriter(File file, boolean gz)
Constructor. -
Method Summary
Modifier and Type Method Description void
close()
BufferedWriter
getWriter()
Returns the underlying buffered writer.void
newLine()
Appends a new line to the output.void
write(char[] buffer, int offset, int length)
Writes a a buffer of characters to the file.void
write(String text)
Writes text.void
write(String text, boolean newLine)
Writes text.void
writeLine(String line)
Writes a new line.void
writeLine(String... elements)
Writes a new line using the give elements.
-
Constructor Details
-
SimpleFileWriter
Constructor.- Parameters:
file
- The file to write to.gz
- Boolean indicating whether the output should be gzipped.
-
-
Method Details
-
writeLine
Writes a new line using the give elements. Elements are separated using the separator in the properties class.- Parameters:
elements
- The line elements to write.
-
writeLine
Writes a new line.- Parameters:
line
- The line to write.
-
write
public void write(char[] buffer, int offset, int length)Writes a a buffer of characters to the file.- Parameters:
buffer
- The buffer to write.offset
- The offset from which to start reading characters.length
- The maximal number of characters to write
-
newLine
public void newLine()Appends a new line to the output. -
write
Writes text.- Parameters:
text
- The text to write.
-
write
Writes text.- Parameters:
text
- The text to write.newLine
- Boolean indicating whether an end of line should be appended.
-
close
public void close()- Specified by:
close
in interfaceAutoCloseable
-
getWriter
Returns the underlying buffered writer.- Returns:
- The underlying buffered writer.
-