public class UnicodeBOMWriter extends Writer
OutputStreamWriter.
This class is here because Java's OutputStreamWriter apparently
doesn't believe in writing BOMs.
For optimum performance, it is recommended that you wrap all instances of
UnicodeWriter with a java.io.BufferedWriter.
| Modifier and Type | Field and Description |
|---|---|
static String |
PROPERTY_WRITE_UTF8_BOM
If this system property evaluates to "
false", ignoring
case, files written out as UTF-8 will not have a BOM written for them. |
| Constructor and Description |
|---|
UnicodeBOMWriter(File file,
String encoding)
This is a utility constructor since the vast majority of the time, this
class will be used to write Unicode files.
|
UnicodeBOMWriter(OutputStream out,
String encoding)
Creates a new writer.
|
UnicodeBOMWriter(String fileName,
String encoding)
This is a utility constructor since the vast majority of the time, this
class will be used to write Unicode files.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes this writer.
|
void |
flush()
Flushes the stream.
|
String |
getEncoding()
Returns the encoding being used to write this output stream (i.e., the
encoding of the file).
|
void |
write(char[] cbuf,
int off,
int len)
Writes a portion of an array of characters.
|
void |
write(int c)
Writes a single character.
|
void |
write(String str,
int off,
int len)
Writes a portion of a string.
|
public static final String PROPERTY_WRITE_UTF8_BOM
false", ignoring
case, files written out as UTF-8 will not have a BOM written for them.
Otherwise (even if the property is not set), UTF-8 files will have a
BOM written.public UnicodeBOMWriter(String fileName, String encoding) throws UnsupportedEncodingException, IOException
fileName - The file to which to write the Unicode output.encoding - The encoding to use.UnsupportedEncodingException - If the specified encoding is not
supported.IOException - If an IO exception occurs.public UnicodeBOMWriter(File file, String encoding) throws UnsupportedEncodingException, IOException
file - The file to which to write the Unicode output.encoding - The encoding to use.UnsupportedEncodingException - If the specified encoding is not
supported.IOException - If an IO exception occurs.public UnicodeBOMWriter(OutputStream out, String encoding) throws UnsupportedEncodingException, IOException
out - The output stream to write.encoding - The encoding to use.UnsupportedEncodingException - If the specified encoding is not
supported.IOException - If an IO exception occurs.public void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableclose in class WriterIOException - If an IO exception occurs.public void flush()
throws IOException
flush in interface Flushableflush in class WriterIOException - If an IO exception occurs.public String getEncoding()
public void write(char[] cbuf,
int off,
int len)
throws IOException
write in class Writercbuf - The buffer of characters.off - The offset from which to start writing characters.len - The number of characters to write.IOException - If an I/O error occurs.public void write(int c)
throws IOException
write in class Writerc - An integer specifying the character to write.IOException - If an IO error occurs.public void write(String str, int off, int len) throws IOException
write in class Writerstr - The string from which to write.off - The offset from which to start writing characters.len - The number of characters to write.IOException - If an IO error occurs.Copyright © 2021. All rights reserved.