public class UncheckedTextFileWriter extends TextFileWriter
IORuntimeException
rather than IOException
in its methods that extend Writer
functionality.
RuntimeException
around it on a much higher level.
Writer
methods still throw IOException
.
In contrary to FileWriter
the constructors of this class support defining
character encoding.
Furthermore it allows specifying the new line character(s) to be used.
UncheckedTextFileWriter
is meant for writing streams of characters.
For writing streams of raw bytes, consider using a FileOutputStream
.
OutputStreamWriter
,
FileOutputStream
,
FileWriter
,
TextFileWriter
DEFAULT_CHARSET, DEFAULT_NEWLINE
Constructor and Description |
---|
UncheckedTextFileWriter(java.io.File file)
Creates a new UncheckedTextFileWriter, given the File
to write to with the default character encoding (UTF-8).
|
UncheckedTextFileWriter(java.io.File file,
java.nio.charset.Charset charset)
Creates a new UncheckedTextFileWriter, given the File
to write to with the encoding specified by the given charset.
|
UncheckedTextFileWriter(java.lang.String filename)
Creates a new UncheckedTextFileWriter on the file with the given filename
to write to with the default character encoding (UTF-8).
|
UncheckedTextFileWriter(java.lang.String filename,
java.nio.charset.Charset charset)
Creates a new UncheckedTextFileWriter on the file with the given filename
to write to with the encoding specified by the given charset.
|
Modifier and Type | Method and Description |
---|---|
static UncheckedTextFileWriter |
create(java.io.File file)
Creates a new UncheckedTextFileWriter, given the File
to write to with the default character encoding (UTF-8).
|
static UncheckedTextFileWriter |
create(java.io.File file,
java.nio.charset.Charset charset)
Creates a new UncheckedTextFileWriter, given the File
to write to with the encoding specified by the given charset.
|
static UncheckedTextFileWriter |
create(java.lang.String filename)
Creates a new UncheckedTextFileWriter on the file with the given filename
to write to with the default character encoding (UTF-8).
|
static UncheckedTextFileWriter |
create(java.lang.String filename,
java.nio.charset.Charset charset)
Creates a new UncheckedTextFileWriter on the file with the given filename
to write to with the encoding specified by the given charset.
|
UncheckedTextFileWriter |
newLine()
Writes the newline character(s).
|
UncheckedTextFileWriter |
setNewline(NewLine newline)
Sets the new line definition to be used by this writer.
|
UncheckedTextFileWriter |
write(IStringRepresentation object)
Writes the given object's
IStringRepresentation.asString() . |
UncheckedTextFileWriter |
writef(java.lang.String text,
java.lang.Object... args)
Allows writing with placeholder replacement as provided by
String.format(String, Object...) . |
UncheckedTextFileWriter |
writeln(IStringRepresentation object)
Writes the given object's
IStringRepresentation.asString() followed
by newline character(s). |
UncheckedTextFileWriter |
writeln(java.lang.String text,
java.lang.Object... args)
Writes the text with placeholder replacement as provided by
String.format(String, Object...) . |
closeQuietly, closeUnchecked, getNewline
public UncheckedTextFileWriter(java.io.File file, java.nio.charset.Charset charset) throws java.io.FileNotFoundException
file
- the File to write to (must not be null).charset
- The encoding to be used (must not be null).java.io.FileNotFoundException
- if the file does not exist,
is a directory rather than a regular file,
or for some other reason cannot be opened for
writing.public UncheckedTextFileWriter(java.io.File file) throws java.io.FileNotFoundException
If you want to have the platform encoding instead, use FileWriter
instead.
If you want to have another encoding, use UncheckedTextFileWriter(File, Charset)
.
file
- the File to write to (must not be null).java.io.FileNotFoundException
- if the file does not exist,
is a directory rather than a regular file,
or for some other reason cannot be opened for
writing.public UncheckedTextFileWriter(java.lang.String filename, java.nio.charset.Charset charset) throws java.io.FileNotFoundException
filename
- The name of the file to write to (must not be null).charset
- The encoding to be used (must not be null).java.io.FileNotFoundException
- if the file does not exist,
is a directory rather than a regular file,
or for some other reason cannot be opened for
writing.public UncheckedTextFileWriter(java.lang.String filename) throws java.io.FileNotFoundException
If you want to have the platform encoding instead, use FileWriter
instead.
If you want to have another encoding, use UncheckedTextFileWriter(String, Charset)
.
filename
- The name of the file to write to (must not be null).java.io.FileNotFoundException
- if the file does not exist,
is a directory rather than a regular file,
or for some other reason cannot be opened for
writing.public static UncheckedTextFileWriter create(java.io.File file, java.nio.charset.Charset charset)
file
- the File to write to (must not be null).charset
- The encoding to be used (must not be null).IORuntimeException
- if the file does not exist,
is a directory rather than a regular file,
or for some other reason cannot be opened for
writing.public static UncheckedTextFileWriter create(java.io.File file)
If you want to have the platform encoding instead, use FileWriter
instead.
If you want to have another encoding, use create(File, Charset)
.
file
- the File to write to (must not be null).IORuntimeException
- if the file does not exist,
is a directory rather than a regular file,
or for some other reason cannot be opened for
writing.public static UncheckedTextFileWriter create(java.lang.String filename, java.nio.charset.Charset charset)
filename
- The name of the file to write to (must not be null).charset
- The encoding to be used (must not be null).IORuntimeException
- if the file does not exist,
is a directory rather than a regular file,
or for some other reason cannot be opened for
writing.public static UncheckedTextFileWriter create(java.lang.String filename)
If you want to have the platform encoding instead, use FileWriter
instead.
If you want to have another encoding, use create(String, Charset)
.
filename
- The name of the file to write to (must not be null).IORuntimeException
- if the file does not exist,
is a directory rather than a regular file,
or for some other reason cannot be opened for
writing.public UncheckedTextFileWriter writef(java.lang.String text, java.lang.Object... args)
String.format(String, Object...)
.
Use this method instead if Writer.write(String)
if IOException
checking should be avoided.writef
in class TextFileWriter
text
- The text message that might contain placeholders (must not be null).args
- Optional arguments to replace placeholders in the given text.IORuntimeException
- In any case of writing problem.public UncheckedTextFileWriter write(IStringRepresentation object)
IStringRepresentation.asString()
.write
in class TextFileWriter
object
- The object of which to write its string representation (must not be null).IORuntimeException
- In any case of writing problem.public UncheckedTextFileWriter writeln(java.lang.String text, java.lang.Object... args)
String.format(String, Object...)
.
followed by newline character(s).writeln
in class TextFileWriter
text
- The text message that might contain placeholders (must not be null).args
- Optional arguments to replace placeholders in the given text.IORuntimeException
- In any case of writing problem.public UncheckedTextFileWriter writeln(IStringRepresentation object)
IStringRepresentation.asString()
followed
by newline character(s).writeln
in class TextFileWriter
object
- The object of which to write its string representation (must not be null).IORuntimeException
- In any case of writing problem.public UncheckedTextFileWriter newLine()
newLine
in class TextFileWriter
IORuntimeException
- In any case of writing problem.public UncheckedTextFileWriter setNewline(NewLine newline)
TextFileWriter
setNewline
in class TextFileWriter