Package adams.core.io
Class BufferedFileWriter
- java.lang.Object
-
- java.io.Writer
-
- adams.core.io.BufferedFileWriter
-
- All Implemented Interfaces:
Closeable
,Flushable
,Appendable
,AutoCloseable
public class BufferedFileWriter extends Writer
Combines aBufferedWriter
and aFileWriter
.- Author:
- FracPete (fracpete at waikato dot ac dot nz)
-
-
Field Summary
Fields Modifier and Type Field Description protected BufferedWriter
m_BufferedWriter
the buffered writer.protected FileWriter
m_FileWriter
the file writer.
-
Constructor Summary
Constructors Constructor Description BufferedFileWriter(File file)
Initializes the writer with the given file.BufferedFileWriter(String file)
Initializes the writer with the given file.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Closes the stream, flushing it first.void
flush()
Flushes the stream.void
newLine()
Writes a line separator.void
write(char[] cbuf, int off, int len)
Writes a portion of an array of characters.void
write(String s, int off, int len)
Writes a portion of a string.
-
-
-
Field Detail
-
m_FileWriter
protected FileWriter m_FileWriter
the file writer.
-
m_BufferedWriter
protected BufferedWriter m_BufferedWriter
the buffered writer.
-
-
Method Detail
-
write
public void write(char[] cbuf, int off, int len) throws IOException
Writes a portion of an array of characters.- Specified by:
write
in classWriter
- Parameters:
cbuf
- Array of charactersoff
- Offset from which to start writing characterslen
- Number of characters to write- Throws:
IOException
- If an I/O error occurs
-
write
public void write(String s, int off, int len) throws IOException
Writes a portion of a string.- Overrides:
write
in classWriter
- Parameters:
s
- A Stringoff
- Offset from which to start writing characterslen
- Number of characters to write- Throws:
IndexOutOfBoundsException
- If off is negative, or len is negative, or off+len is negative or greater than the length of the given stringIOException
- If an I/O error occurs
-
newLine
public void newLine() throws IOException
Writes a line separator. The line separator string is defined by the system property line.separator, and is not necessarily a single newline ('\n') character.- Throws:
IOException
-
flush
public void flush() throws IOException
Flushes the stream. If the stream has saved any characters from the various write() methods in a buffer, write them immediately to their intended destination. Then, if that destination is another character or byte stream, flush it. Thus one flush() invocation will flush all the buffers in a chain of Writers and OutputStreams.- Specified by:
flush
in interfaceFlushable
- Specified by:
flush
in classWriter
- Throws:
IOException
- If an I/O error occurs
-
close
public void close() throws IOException
Closes the stream, flushing it first. Once the stream has been closed, further write() or flush() invocations will cause an IOException to be thrown. Closing a previously closed stream has no effect.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in classWriter
- Throws:
IOException
- If an I/O error occurs
-
-