org.eobjects.metamodel.util
Class UnicodeWriter

java.lang.Object
  extended by java.io.Writer
      extended by org.eobjects.metamodel.util.UnicodeWriter
All Implemented Interfaces:
Closeable, Flushable, Appendable

public class UnicodeWriter
extends Writer

Writes Unicode text to an output stream. If the specified encoding is a Unicode, then the text is preceeded by the proper Unicode BOM. If it is any other encoding, this class behaves just like 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. This file is a redistribution of Rubert Futrell from FifeSoft UnicodeWriter (also LGPL licensed).

 UnicodeWriter.java - Writes Unicode output with the proper BOM.
 Copyright (C) 2004 Robert Futrell
 robert_futrell at users.sourceforge.net
 http://fifesoft.com/rsyntaxtextarea
 

Version:
0.7
Author:
Robert Futrell

Field Summary
static byte[] UTF16BE_BOM
           
static byte[] UTF16LE_BOM
           
static byte[] UTF32BE_BOM
           
static byte[] UTF32LE_BOM
           
static byte[] UTF8_BOM
           
 
Fields inherited from class java.io.Writer
lock
 
Constructor Summary
UnicodeWriter(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.
UnicodeWriter(OutputStream outputStream, String encoding)
          Creates a new writer.
UnicodeWriter(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.
 
Method Summary
 void close()
          Closes this writer.
 void flush()
          Flushes the stream.
 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.
 
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
 

Field Detail

UTF8_BOM

public static final byte[] UTF8_BOM

UTF16LE_BOM

public static final byte[] UTF16LE_BOM

UTF16BE_BOM

public static final byte[] UTF16BE_BOM

UTF32LE_BOM

public static final byte[] UTF32LE_BOM

UTF32BE_BOM

public static final byte[] UTF32BE_BOM
Constructor Detail

UnicodeWriter

public UnicodeWriter(String fileName,
                     String encoding)
              throws UnsupportedEncodingException,
                     IOException
This is a utility constructor since the vast majority of the time, this class will be used to write Unicode files.

Parameters:
fileName - The file to which to write the Unicode output.
encoding - The encoding to use.
Throws:
UnsupportedEncodingException - If the specified encoding is not supported.
IOException - If an IO exception occurs.

UnicodeWriter

public UnicodeWriter(File file,
                     String encoding)
              throws UnsupportedEncodingException,
                     IOException
This is a utility constructor since the vast majority of the time, this class will be used to write Unicode files.

Parameters:
file - The file to which to write the Unicode output.
encoding - The encoding to use.
Throws:
UnsupportedEncodingException - If the specified encoding is not supported.
IOException - If an IO exception occurs.

UnicodeWriter

public UnicodeWriter(OutputStream outputStream,
                     String encoding)
              throws UnsupportedEncodingException,
                     IOException
Creates a new writer.

Parameters:
outputStream - The output stream to write.
encoding - The encoding to use.
Throws:
UnsupportedEncodingException - If the specified encoding is not supported.
IOException - If an IO exception occurs.
Method Detail

close

public void close()
           throws IOException
Closes this writer.

Specified by:
close in interface Closeable
Specified by:
close in class Writer
Throws:
IOException - If an IO exception occurs.

flush

public void flush()
           throws IOException
Flushes the stream.

Specified by:
flush in interface Flushable
Specified by:
flush in class Writer
Throws:
IOException - If an IO exception occurs.

write

public void write(char[] cbuf,
                  int off,
                  int len)
           throws IOException
Writes a portion of an array of characters.

Specified by:
write in class Writer
Parameters:
cbuf - The buffer of characters.
off - The offset from which to start writing characters.
len - The number of characters to write.
Throws:
IOException - If an I/O error occurs.

write

public void write(int c)
           throws IOException
Writes a single character.

Overrides:
write in class Writer
Parameters:
c - An integer specifying the character to write.
Throws:
IOException - If an IO error occurs.

write

public void write(String str,
                  int off,
                  int len)
           throws IOException
Writes a portion of a string.

Overrides:
write in class Writer
Parameters:
str - The string from which to write.
off - The offset from which to start writing characters.
len - The number of characters to write.
Throws:
IOException - If an IO error occurs.


Copyright © 2007-2013. All Rights Reserved.