public class UnicodeWriter
extends java.io.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
.
限定符和类型 | 字段和说明 |
---|---|
static java.lang.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. |
构造器和说明 |
---|
UnicodeWriter(java.io.File file,
java.lang.String encoding)
This is a utility constructor since the vast majority of the time, this
class will be used to write Unicode files.
|
UnicodeWriter(java.io.OutputStream out,
java.lang.String encoding)
Creates a new writer.
|
UnicodeWriter(java.lang.String fileName,
java.lang.String encoding)
This is a utility constructor since the vast majority of the time, this
class will be used to write Unicode files.
|
限定符和类型 | 方法和说明 |
---|---|
void |
close()
Closes this writer.
|
void |
flush()
Flushes the stream.
|
java.lang.String |
getEncoding()
Returns the encoding being used to write this output stream (i.e., the
encoding of the file).
|
static boolean |
getWriteUtf8BOM()
Returns whether UTF-8 files should have a BOM in them when written.
|
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(java.lang.String str,
int off,
int len)
Writes a portion of a string.
|
public static final java.lang.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 UnicodeWriter(java.lang.String fileName, java.lang.String encoding) throws java.io.UnsupportedEncodingException, java.io.IOException
fileName
- The file to which to write the Unicode output.encoding
- The encoding to use.java.io.UnsupportedEncodingException
- If the specified encoding is not
supported.java.io.IOException
- If an IO exception occurs.public UnicodeWriter(java.io.File file, java.lang.String encoding) throws java.io.UnsupportedEncodingException, java.io.IOException
file
- The file to which to write the Unicode output.encoding
- The encoding to use.java.io.UnsupportedEncodingException
- If the specified encoding is not
supported.java.io.IOException
- If an IO exception occurs.public UnicodeWriter(java.io.OutputStream out, java.lang.String encoding) throws java.io.UnsupportedEncodingException, java.io.IOException
out
- The output stream to write.encoding
- The encoding to use.java.io.UnsupportedEncodingException
- If the specified encoding is not
supported.java.io.IOException
- If an IO exception occurs.public void close() throws java.io.IOException
close
在接口中 java.io.Closeable
close
在接口中 java.lang.AutoCloseable
close
在类中 java.io.Writer
java.io.IOException
- If an IO exception occurs.public void flush() throws java.io.IOException
flush
在接口中 java.io.Flushable
flush
在类中 java.io.Writer
java.io.IOException
- If an IO exception occurs.public java.lang.String getEncoding()
public static boolean getWriteUtf8BOM()
public void write(char[] cbuf, int off, int len) throws java.io.IOException
write
在类中 java.io.Writer
cbuf
- The buffer of characters.off
- The offset from which to start writing characters.len
- The number of characters to write.java.io.IOException
- If an I/O error occurs.public void write(int c) throws java.io.IOException
write
在类中 java.io.Writer
c
- An integer specifying the character to write.java.io.IOException
- If an IO error occurs.public void write(java.lang.String str, int off, int len) throws java.io.IOException
write
在类中 java.io.Writer
str
- The string from which to write.off
- The offset from which to start writing characters.len
- The number of characters to write.java.io.IOException
- If an IO error occurs.