public class FileWriterWithEncoding extends ProxyWriter
This class provides a simple alternative to FileWriter
that allows an encoding to be set. Unfortunately, it cannot subclass FileWriter
.
By default, the file will be overwritten, but this may be changed to append.
The encoding must be specified using either the name of the Charset
, the Charset
, or a CharsetEncoder
. If the default encoding is
required then use the FileWriter
directly, rather than this implementation.
To build an instance, see FileWriterWithEncoding.Builder
.
Modifier and Type | Class and Description |
---|---|
static class |
FileWriterWithEncoding.Builder
Builds a new
FileWriterWithEncoding instance. |
Modifier | Constructor and Description |
---|---|
|
FileWriterWithEncoding(java.io.File file,
java.nio.charset.Charset charset)
Deprecated.
|
|
FileWriterWithEncoding(java.io.File file,
java.nio.charset.Charset encoding,
boolean append)
Deprecated.
|
|
FileWriterWithEncoding(java.io.File file,
java.nio.charset.CharsetEncoder charsetEncoder)
Deprecated.
|
|
FileWriterWithEncoding(java.io.File file,
java.nio.charset.CharsetEncoder charsetEncoder,
boolean append)
Deprecated.
|
|
FileWriterWithEncoding(java.io.File file,
java.lang.String charsetName)
Deprecated.
|
|
FileWriterWithEncoding(java.io.File file,
java.lang.String charsetName,
boolean append)
Deprecated.
|
private |
FileWriterWithEncoding(java.io.OutputStreamWriter outputStreamWriter) |
|
FileWriterWithEncoding(java.lang.String fileName,
java.nio.charset.Charset charset)
Deprecated.
|
|
FileWriterWithEncoding(java.lang.String fileName,
java.nio.charset.Charset charset,
boolean append)
Deprecated.
|
|
FileWriterWithEncoding(java.lang.String fileName,
java.nio.charset.CharsetEncoder encoding)
Deprecated.
|
|
FileWriterWithEncoding(java.lang.String fileName,
java.nio.charset.CharsetEncoder charsetEncoder,
boolean append)
Deprecated.
|
|
FileWriterWithEncoding(java.lang.String fileName,
java.lang.String charsetName)
Deprecated.
|
|
FileWriterWithEncoding(java.lang.String fileName,
java.lang.String charsetName,
boolean append)
Deprecated.
|
Modifier and Type | Method and Description |
---|---|
static FileWriterWithEncoding.Builder |
builder()
Constructs a new
FileWriterWithEncoding.Builder . |
private static java.io.OutputStreamWriter |
initWriter(java.io.File file,
java.lang.Object encoding,
boolean append)
Initializes the wrapped file writer.
|
afterWrite, append, append, append, beforeWrite, close, flush, handleIOException, write, write, write, write, write
@Deprecated public FileWriterWithEncoding(java.io.File file, java.nio.charset.Charset charset) throws java.io.IOException
builder()
, FileWriterWithEncoding.Builder
, and FileWriterWithEncoding.Builder.get()
file
- the file to write to, not nullcharset
- the encoding to use, not nulljava.lang.NullPointerException
- if the file or encoding is nulljava.io.IOException
- in case of an I/O error@Deprecated public FileWriterWithEncoding(java.io.File file, java.nio.charset.Charset encoding, boolean append) throws java.io.IOException
builder()
, FileWriterWithEncoding.Builder
, and FileWriterWithEncoding.Builder.get()
file
- the file to write to, not null.encoding
- the name of the requested charset, null uses the default Charset.append
- true if content should be appended, false to overwrite.java.lang.NullPointerException
- if the file is null.java.io.IOException
- in case of an I/O error.@Deprecated public FileWriterWithEncoding(java.io.File file, java.nio.charset.CharsetEncoder charsetEncoder) throws java.io.IOException
builder()
, FileWriterWithEncoding.Builder
, and FileWriterWithEncoding.Builder.get()
file
- the file to write to, not nullcharsetEncoder
- the encoding to use, not nulljava.lang.NullPointerException
- if the file or encoding is nulljava.io.IOException
- in case of an I/O error@Deprecated public FileWriterWithEncoding(java.io.File file, java.nio.charset.CharsetEncoder charsetEncoder, boolean append) throws java.io.IOException
builder()
, FileWriterWithEncoding.Builder
, and FileWriterWithEncoding.Builder.get()
file
- the file to write to, not null.charsetEncoder
- the encoding to use, null uses the default Charset.append
- true if content should be appended, false to overwrite.java.lang.NullPointerException
- if the file is null.java.io.IOException
- in case of an I/O error.@Deprecated public FileWriterWithEncoding(java.io.File file, java.lang.String charsetName) throws java.io.IOException
builder()
, FileWriterWithEncoding.Builder
, and FileWriterWithEncoding.Builder.get()
file
- the file to write to, not nullcharsetName
- the name of the requested charset, not nulljava.lang.NullPointerException
- if the file or encoding is nulljava.io.IOException
- in case of an I/O error@Deprecated public FileWriterWithEncoding(java.io.File file, java.lang.String charsetName, boolean append) throws java.io.IOException
builder()
, FileWriterWithEncoding.Builder
, and FileWriterWithEncoding.Builder.get()
file
- the file to write to, not null.charsetName
- the name of the requested charset, null uses the default Charset.append
- true if content should be appended, false to overwrite.java.lang.NullPointerException
- if the file is null.java.io.IOException
- in case of an I/O error.private FileWriterWithEncoding(java.io.OutputStreamWriter outputStreamWriter)
@Deprecated public FileWriterWithEncoding(java.lang.String fileName, java.nio.charset.Charset charset) throws java.io.IOException
builder()
, FileWriterWithEncoding.Builder
, and FileWriterWithEncoding.Builder.get()
fileName
- the name of the file to write to, not nullcharset
- the charset to use, not nulljava.lang.NullPointerException
- if the file name or encoding is nulljava.io.IOException
- in case of an I/O error@Deprecated public FileWriterWithEncoding(java.lang.String fileName, java.nio.charset.Charset charset, boolean append) throws java.io.IOException
builder()
, FileWriterWithEncoding.Builder
, and FileWriterWithEncoding.Builder.get()
fileName
- the name of the file to write to, not nullcharset
- the encoding to use, not nullappend
- true if content should be appended, false to overwritejava.lang.NullPointerException
- if the file name or encoding is nulljava.io.IOException
- in case of an I/O error@Deprecated public FileWriterWithEncoding(java.lang.String fileName, java.nio.charset.CharsetEncoder encoding) throws java.io.IOException
builder()
, FileWriterWithEncoding.Builder
, and FileWriterWithEncoding.Builder.get()
fileName
- the name of the file to write to, not nullencoding
- the encoding to use, not nulljava.lang.NullPointerException
- if the file name or encoding is nulljava.io.IOException
- in case of an I/O error@Deprecated public FileWriterWithEncoding(java.lang.String fileName, java.nio.charset.CharsetEncoder charsetEncoder, boolean append) throws java.io.IOException
builder()
, FileWriterWithEncoding.Builder
, and FileWriterWithEncoding.Builder.get()
fileName
- the name of the file to write to, not nullcharsetEncoder
- the encoding to use, not nullappend
- true if content should be appended, false to overwritejava.lang.NullPointerException
- if the file name or encoding is nulljava.io.IOException
- in case of an I/O error@Deprecated public FileWriterWithEncoding(java.lang.String fileName, java.lang.String charsetName) throws java.io.IOException
builder()
, FileWriterWithEncoding.Builder
, and FileWriterWithEncoding.Builder.get()
fileName
- the name of the file to write to, not nullcharsetName
- the name of the requested charset, not nulljava.lang.NullPointerException
- if the file name or encoding is nulljava.io.IOException
- in case of an I/O error@Deprecated public FileWriterWithEncoding(java.lang.String fileName, java.lang.String charsetName, boolean append) throws java.io.IOException
builder()
, FileWriterWithEncoding.Builder
, and FileWriterWithEncoding.Builder.get()
fileName
- the name of the file to write to, not nullcharsetName
- the name of the requested charset, not nullappend
- true if content should be appended, false to overwritejava.lang.NullPointerException
- if the file name or encoding is nulljava.io.IOException
- in case of an I/O errorpublic static FileWriterWithEncoding.Builder builder()
FileWriterWithEncoding.Builder
.FileWriterWithEncoding.Builder
.private static java.io.OutputStreamWriter initWriter(java.io.File file, java.lang.Object encoding, boolean append) throws java.io.IOException
file
- the file to be accessedencoding
- the encoding to use - may be Charset, CharsetEncoder or String, null uses the default Charset.append
- true to appendjava.io.IOException
- if an error occurs