|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjava.io.Writer
java.io.OutputStreamWriter
org.pfsw.text.TextFileWriter
org.pfsw.text.UncheckedTextFileWriter
public class UncheckedTextFileWriter
Convenience class for writing text files with throwing IORuntimeException
rather than IOException in its methods that extend Writer functionality.
Sometimes (often with lambda expressions) it is very annoying having to explicitly catch
checked exceptions. It often "pollutes" the source code so heavily that the actual program logic
is hard to be recognized. In such cases it is often much better to write the code straight
forward and put one try-catch for RuntimeException around it on a much higher level.
All 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| Field Summary |
|---|
| Fields inherited from class org.pfsw.text.TextFileWriter |
|---|
DEFAULT_CHARSET, DEFAULT_NEWLINE |
| Fields inherited from class java.io.Writer |
|---|
lock |
| Constructor Summary | |
|---|---|
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. |
|
| Method Summary | |
|---|---|
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(org.pfsw.bif.text.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(org.pfsw.bif.text.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...). |
| Methods inherited from class org.pfsw.text.TextFileWriter |
|---|
closeQuietly, closeUnchecked, getNewline |
| Methods inherited from class java.io.OutputStreamWriter |
|---|
close, flush, getEncoding, write, write, write |
| Methods inherited from class java.io.Writer |
|---|
append, append, append, write, write |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
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.| Method Detail |
|---|
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).
org.pfsw.bif.exceptions.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).
org.pfsw.bif.exceptions.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).
org.pfsw.bif.exceptions.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).
org.pfsw.bif.exceptions.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 TextFileWritertext - The text message that might contain placeholders (must not be null).args - Optional arguments to replace placeholders in the given text.
org.pfsw.bif.exceptions.IORuntimeException - In any case of writing problem.public UncheckedTextFileWriter write(org.pfsw.bif.text.IStringRepresentation object)
IStringRepresentation.asString().
write in class TextFileWriterobject - The object of which to write its string representation (must not be null).
org.pfsw.bif.exceptions.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 TextFileWritertext - The text message that might contain placeholders (must not be null).args - Optional arguments to replace placeholders in the given text.
org.pfsw.bif.exceptions.IORuntimeException - In any case of writing problem.public UncheckedTextFileWriter writeln(org.pfsw.bif.text.IStringRepresentation object)
IStringRepresentation.asString() followed
by newline character(s).
writeln in class TextFileWriterobject - The object of which to write its string representation (must not be null).
org.pfsw.bif.exceptions.IORuntimeException - In any case of writing problem.public UncheckedTextFileWriter newLine()
newLine in class TextFileWriterorg.pfsw.bif.exceptions.IORuntimeException - In any case of writing problem.public UncheckedTextFileWriter setNewline(NewLine newline)
TextFileWriter
setNewline in class TextFileWriter
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||