public abstract class Writer extends AutoCloseable
flush()
method to be called before closing the stream, to ensure all data is
actually written out.
This abstract class does not provide a fully working implementation, so it needs to be subclassed, and at least the
write(char[], int, int)
, close()
and flush()
methods needs to be overridden. Overriding
some of the non-abstract methods is also often advised, since it might result in higher efficiency.Reader
Constructor and Description |
---|
Writer() |
Modifier and Type | Method and Description |
---|---|
abstract void |
close()
Closes this writer.
|
abstract void |
flush()
Flushes this writer.
|
java.lang.String |
getLineSeparator()
Get the line separator being used for this writer.
|
void |
setLineSeparator(java.lang.String lineSeparator)
Set the line separator for this writer.
|
void |
write(char[] buf)
Writes the entire character buffer
buf to the target. |
abstract void |
write(char[] buf,
int offset,
int count)
Writes
count characters starting at offset in buf to the target. |
void |
write(int oneChar)
Writes one character to the target.
|
void |
write(java.lang.String str)
Writes the characters from the specified string to the target.
|
void |
write(java.lang.String str,
int offset,
int count)
Writes
count characters from str starting at offset to the target. |
void |
writeln()
Write the line separator.
|
void |
writeln(java.lang.String str)
Writes the characters from the specified string followed by a line separator.
|
public abstract void close()
close
in interface java.lang.AutoCloseable
close
in class AutoCloseable
IOException
- if an error occurs while closing this writer.public abstract void flush()
IOException
- if an error occurs while flushing this writer.public void write(char[] buf)
buf
to the target.buf
- the non-null array containing characters to writeIOException
- if this writer is closed or another I/O error occurs.public abstract void write(char[] buf, int offset, int count)
count
characters starting at offset
in buf
to the target.buf
- the non-null character array to write.offset
- the index of the first character in buf
to write.count
- the maximum number of characters to write.IOException
- if this writer is closed or another I/O error occurs.public void write(int oneChar)
oneChar
are
written.oneChar
- the character to write to the target.IOException
- if this writer is closed or another I/O error occurs.public void write(java.lang.String str)
str
- the non-null string containing the characters to writeIOException
- if this writer is closed or another I/O error occurspublic void write(java.lang.String str, int offset, int count)
count
characters from str
starting at offset
to the target.str
- the non-null string containing the characters to writeoffset
- the index of the first character in str
to writecount
- the number of characters from str
to write.IOException
- if this writer is closed or another I/O error occurspublic java.lang.String getLineSeparator()
public void setLineSeparator(java.lang.String lineSeparator)
lineSeparator
- line separatorpublic final void writeln()
public final void writeln(java.lang.String str)
str
- string to write