Package org.marketcetera.util.unicode
Class UnicodeFileWriter
- java.lang.Object
-
- java.io.Writer
-
- org.marketcetera.util.unicode.UnicodeOutputStreamWriter
-
- org.marketcetera.util.unicode.UnicodeFileWriter
-
- All Implemented Interfaces:
Closeable,Flushable,Appendable,AutoCloseable
public class UnicodeFileWriter extends UnicodeOutputStreamWriter
AUnicodeOutputStreamWriterwhich directs its output to a file. All constructors pass-thru to aUnicodeOutputStreamWriterconstructor anOutputStreamthat is built using aFileOutputStreamconstructor.Appending to an existing file is safe: if the file exists, and is non-empty, then no signature BOM is recorded (regardless of the specified or deduced signature/charset) because we assume that a BOM is already present. However, this class does not attempt to check that, in this case, the existing signature BOM and associated charset match the one supplied in the constructor.
- Since:
- 0.6.0
- Version:
- $Id: UnicodeFileWriter.java 16154 2012-07-14 16:34:05Z colin $
- Author:
- tlerios@marketcetera.com
-
-
Constructor Summary
Constructors Constructor Description UnicodeFileWriter(File file)Creates a new writer using the given file, and theUnicodeOutputStreamWriter(OutputStream)andFileOutputStream(File)constructors.UnicodeFileWriter(FileDescriptor fd)Creates a new writer using the given file descriptor, and theUnicodeOutputStreamWriter(OutputStream)andFileOutputStream(FileDescriptor)constructors.UnicodeFileWriter(FileDescriptor fd, Reader reader)Creates a new writer using the given file descriptor and reader, and theUnicodeOutputStreamWriter(OutputStream, Reader)andFileOutputStream(FileDescriptor)constructors.UnicodeFileWriter(FileDescriptor fd, SignatureCharset requestedSignatureCharset)Creates a new writer using the given file descriptor and signature/charset, and theUnicodeOutputStreamWriter(OutputStream, SignatureCharset)andFileOutputStream(FileDescriptor)constructors.UnicodeFileWriter(File file, boolean append)Creates a new writer using the given file, and theUnicodeOutputStreamWriter(OutputStream)andFileOutputStream(File,boolean)constructors.UnicodeFileWriter(File file, boolean append, Reader reader)Creates a new writer using the given file and reader, and theUnicodeOutputStreamWriter(OutputStream, Reader)andFileOutputStream(File,boolean)constructors.UnicodeFileWriter(File file, boolean append, SignatureCharset requestedSignatureCharset)Creates a new writer using the given file and signature/charset, and theUnicodeOutputStreamWriter(OutputStream, SignatureCharset)andFileOutputStream(File,boolean)constructors.UnicodeFileWriter(File file, Reader reader)Creates a new writer using the given file and reader, and theUnicodeOutputStreamWriter(OutputStream, Reader)andFileOutputStream(File)constructors.UnicodeFileWriter(File file, SignatureCharset requestedSignatureCharset)Creates a new writer using the given file and signature/charset, and theUnicodeOutputStreamWriter(OutputStream, SignatureCharset)andFileOutputStream(File)constructors.UnicodeFileWriter(String fileName)Creates a new writer using the given file name, and theUnicodeOutputStreamWriter(OutputStream)andFileOutputStream(String)constructors.UnicodeFileWriter(String fileName, boolean append)Creates a new writer using the given file name, and theUnicodeOutputStreamWriter(OutputStream)andFileOutputStream(String,boolean)constructors.UnicodeFileWriter(String fileName, boolean append, Reader reader)Creates a new writer using the given file name and reader, and theUnicodeOutputStreamWriter(OutputStream, Reader)andFileOutputStream(String,boolean)constructors.UnicodeFileWriter(String fileName, boolean append, SignatureCharset requestedSignatureCharset)Creates a new writer using the given file name and signature/charset, and theUnicodeOutputStreamWriter(OutputStream, SignatureCharset)andFileOutputStream(String,boolean)constructors.UnicodeFileWriter(String fileName, Reader reader)Creates a new writer using the given file name and reader, and theUnicodeOutputStreamWriter(OutputStream, Reader)andFileOutputStream(String)constructors.UnicodeFileWriter(String fileName, SignatureCharset requestedSignatureCharset)Creates a new writer using the given file name and signature/charset, and theUnicodeOutputStreamWriter(OutputStream, SignatureCharset)andFileOutputStream(String)constructors.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static booleanshouldWriteSignature(File file, boolean append)Checks whether signature injection should take place for the given file and output mode.private static booleanshouldWriteSignature(String fileName, boolean append)Checks whether signature injection should take place for the given file and output mode.-
Methods inherited from class org.marketcetera.util.unicode.UnicodeOutputStreamWriter
append, append, append, close, flush, getRequestedSignatureCharset, getSignatureCharset, write, write, write, write, write
-
Methods inherited from class java.io.Writer
nullWriter
-
-
-
-
Constructor Detail
-
UnicodeFileWriter
public UnicodeFileWriter(String fileName) throws FileNotFoundException
Creates a new writer using the given file name, and theUnicodeOutputStreamWriter(OutputStream)andFileOutputStream(String)constructors.- Parameters:
fileName- The file name.- Throws:
FileNotFoundException- Propagated from theFileOutputStreamconstructor.
-
UnicodeFileWriter
public UnicodeFileWriter(String fileName, SignatureCharset requestedSignatureCharset) throws FileNotFoundException
Creates a new writer using the given file name and signature/charset, and theUnicodeOutputStreamWriter(OutputStream, SignatureCharset)andFileOutputStream(String)constructors.- Parameters:
fileName- The file name.requestedSignatureCharset- The signature/charset. It may be null to use the default JVM charset.- Throws:
FileNotFoundException- Propagated from theFileOutputStreamconstructor.
-
UnicodeFileWriter
public UnicodeFileWriter(String fileName, Reader reader) throws IOException
Creates a new writer using the given file name and reader, and theUnicodeOutputStreamWriter(OutputStream, Reader)andFileOutputStream(String)constructors.- Parameters:
fileName- The file name.reader- The reader.- Throws:
IOException- Thrown if an I/O error occurs, incl. propagation from theFileOutputStreamconstructor.
-
UnicodeFileWriter
public UnicodeFileWriter(String fileName, boolean append) throws FileNotFoundException
Creates a new writer using the given file name, and theUnicodeOutputStreamWriter(OutputStream)andFileOutputStream(String,boolean)constructors.- Parameters:
fileName- The file name.append- True if data should be appended to the file.- Throws:
FileNotFoundException- Propagated from theFileOutputStreamconstructor.
-
UnicodeFileWriter
public UnicodeFileWriter(String fileName, boolean append, SignatureCharset requestedSignatureCharset) throws FileNotFoundException
Creates a new writer using the given file name and signature/charset, and theUnicodeOutputStreamWriter(OutputStream, SignatureCharset)andFileOutputStream(String,boolean)constructors.- Parameters:
fileName- The file name.append- True if data should be appended to the file.requestedSignatureCharset- The signature/charset. It may be null to use the default JVM charset.- Throws:
FileNotFoundException- Propagated from theFileOutputStreamconstructor.
-
UnicodeFileWriter
public UnicodeFileWriter(String fileName, boolean append, Reader reader) throws IOException
Creates a new writer using the given file name and reader, and theUnicodeOutputStreamWriter(OutputStream, Reader)andFileOutputStream(String,boolean)constructors.- Parameters:
fileName- The file name.append- True if data should be appended to the file.reader- The reader.- Throws:
IOException- Thrown if an I/O error occurs, incl. propagation from theFileOutputStreamconstructor.
-
UnicodeFileWriter
public UnicodeFileWriter(File file) throws FileNotFoundException
Creates a new writer using the given file, and theUnicodeOutputStreamWriter(OutputStream)andFileOutputStream(File)constructors.- Parameters:
file- The file.- Throws:
FileNotFoundException- Propagated from theFileOutputStreamconstructor.
-
UnicodeFileWriter
public UnicodeFileWriter(File file, SignatureCharset requestedSignatureCharset) throws FileNotFoundException
Creates a new writer using the given file and signature/charset, and theUnicodeOutputStreamWriter(OutputStream, SignatureCharset)andFileOutputStream(File)constructors.- Parameters:
file- The file.requestedSignatureCharset- The signature/charset. It may be null to use the default JVM charset.- Throws:
FileNotFoundException- Propagated from theFileOutputStreamconstructor.
-
UnicodeFileWriter
public UnicodeFileWriter(File file, Reader reader) throws IOException
Creates a new writer using the given file and reader, and theUnicodeOutputStreamWriter(OutputStream, Reader)andFileOutputStream(File)constructors.- Parameters:
file- The file.reader- The reader.- Throws:
IOException- Thrown if an I/O error occurs, incl. propagation from theFileOutputStreamconstructor.
-
UnicodeFileWriter
public UnicodeFileWriter(File file, boolean append) throws FileNotFoundException
Creates a new writer using the given file, and theUnicodeOutputStreamWriter(OutputStream)andFileOutputStream(File,boolean)constructors.- Parameters:
file- The file.append- True if data should be appended to the file.- Throws:
FileNotFoundException- Propagated from theFileOutputStreamconstructor.
-
UnicodeFileWriter
public UnicodeFileWriter(File file, boolean append, SignatureCharset requestedSignatureCharset) throws FileNotFoundException
Creates a new writer using the given file and signature/charset, and theUnicodeOutputStreamWriter(OutputStream, SignatureCharset)andFileOutputStream(File,boolean)constructors.- Parameters:
file- The file.append- True if data should be appended to the file.requestedSignatureCharset- The signature/charset. It may be null to use the default JVM charset.- Throws:
FileNotFoundException- Propagated from theFileOutputStreamconstructor.
-
UnicodeFileWriter
public UnicodeFileWriter(File file, boolean append, Reader reader) throws IOException
Creates a new writer using the given file and reader, and theUnicodeOutputStreamWriter(OutputStream, Reader)andFileOutputStream(File,boolean)constructors.- Parameters:
file- The file.append- True if data should be appended to the file.reader- The reader.- Throws:
IOException- Thrown if an I/O error occurs, incl. propagation from theFileOutputStreamconstructor.
-
UnicodeFileWriter
public UnicodeFileWriter(FileDescriptor fd)
Creates a new writer using the given file descriptor, and theUnicodeOutputStreamWriter(OutputStream)andFileOutputStream(FileDescriptor)constructors.- Parameters:
fd- The file descriptor.
-
UnicodeFileWriter
public UnicodeFileWriter(FileDescriptor fd, SignatureCharset requestedSignatureCharset)
Creates a new writer using the given file descriptor and signature/charset, and theUnicodeOutputStreamWriter(OutputStream, SignatureCharset)andFileOutputStream(FileDescriptor)constructors.- Parameters:
fd- The file descriptor.requestedSignatureCharset- The signature/charset. It may be null to use the default JVM charset.
-
UnicodeFileWriter
public UnicodeFileWriter(FileDescriptor fd, Reader reader) throws IOException
Creates a new writer using the given file descriptor and reader, and theUnicodeOutputStreamWriter(OutputStream, Reader)andFileOutputStream(FileDescriptor)constructors.- Parameters:
fd- The file descriptor.reader- The reader.- Throws:
IOException- Thrown if an I/O error occurs.
-
-
Method Detail
-
shouldWriteSignature
private static boolean shouldWriteSignature(File file, boolean append)
Checks whether signature injection should take place for the given file and output mode.- Parameters:
file- The file.append- True if data should be appended to the file.- Returns:
- True if so.
-
shouldWriteSignature
private static boolean shouldWriteSignature(String fileName, boolean append)
Checks whether signature injection should take place for the given file and output mode.- Parameters:
fileName- The file name.append- True if data should be appended to the file.- Returns:
- True if so.
-
-