|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.io.OutputStream
java.io.FilterOutputStream
java.io.PrintStream
com.ibm.jzos.TranscodingPrintStream
public class TranscodingPrintStream
A subclass of PrintStream that sets an encoding on its OutputStreamWriter and also transcodes any write(byte[]) messages that are sent to it when it is treated as an OutputStream. This avoids the problem caused when an application wraps System.out or System.err in its own PrintWriter which would override and lose the PrintStream's encoding.
When both source and target codepages are single byte encodings, (e.g. ISO-8859-1, IBM-1047)
a direct map can be used, and is the most efficient way to transcode. If one
or both of the codepages are multi-byte (e.g. UTF-8) the CharsetEncoder and
CharsetDecoder classes need to be used. For this case, the Transcoder
class
is used. It provides a protocol that accepts an array of source codepage encoded bytes,
and writes the target codepage encoded bytes to a supplied output stream.
Field Summary |
---|
Fields inherited from class java.io.FilterOutputStream |
---|
out |
Constructor Summary | |
---|---|
TranscodingPrintStream(java.io.OutputStream out,
boolean autoFlush,
java.lang.String targetEncoding,
boolean enable)
Create a new transcoding print stream. |
|
TranscodingPrintStream(java.io.OutputStream out,
boolean autoFlush,
java.lang.String sourceEncoding,
java.lang.String targetEncoding,
boolean enable)
Create a new transcoding print stream. |
Method Summary | |
---|---|
void |
flush()
Overridden to flush the transcoder if one is being used. |
byte[] |
getTranslateTable()
Answer the translate table in place. |
boolean |
isActive()
Answer whether this PrintStream is actively transcoding. |
void |
write(byte[] buf,
int off,
int len)
Override PrintStream.write(byte[], int, int)
to transcode bytes from the default encoding to the target encoding. |
void |
write(int b)
Override PrintStream.write(int b)
to transcode bytes from the default encoding to the target encoding. |
Methods inherited from class java.io.PrintStream |
---|
append, append, append, checkError, clearError, close, format, format, print, print, print, print, print, print, print, print, print, printf, printf, println, println, println, println, println, println, println, println, println, println, setError |
Methods inherited from class java.io.FilterOutputStream |
---|
write |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public TranscodingPrintStream(java.io.OutputStream out, boolean autoFlush, java.lang.String targetEncoding, boolean enable) throws java.io.UnsupportedEncodingException
out
- The output stream to which values and objects will be
printedautoFlush
- A boolean; if true, the output buffer will be flushed
whenever a byte array is written, one of the
println
methods is invoked, or a newline
character or byte ('\n'
) is writtentargetEncoding
- The String naming the encoding to use, both
for the internal OutputStreamWriter and for
translating write(byte[]) IOStream messages
sent to this object
java.io.UnsupportedEncodingException
PrintStream.PrintStream(java.io.OutputStream, boolean)
,
PrintWriter.PrintWriter(java.io.OutputStream, boolean)
public TranscodingPrintStream(java.io.OutputStream out, boolean autoFlush, java.lang.String sourceEncoding, java.lang.String targetEncoding, boolean enable) throws java.io.UnsupportedEncodingException
out
- The output stream to which values and objects will be
printedautoFlush
- A boolean; if true, the output buffer will be flushed
whenever a byte array is written, one of the
println
methods is invoked, or a newline
character or byte ('\n'
) is writtensourceEncoding
- The String naming the encoding that is the source
encoding for the transcoder. If null, the default
will be used (the "file.encoding" System property)targetEncoding
- The String naming the encoding to use, both
for the internal OutputStreamWriter and for
translating write(byte[]) IOStream messages
sent to this object
java.io.UnsupportedEncodingException
PrintStream.PrintStream(java.io.OutputStream, boolean)
,
PrintWriter.PrintWriter(java.io.OutputStream, boolean)
Method Detail |
---|
public void write(int b)
PrintStream.write(int b)
to transcode bytes from the default encoding to the target encoding.
write
in class java.io.PrintStream
public void write(byte[] buf, int off, int len)
PrintStream.write(byte[], int, int)
to transcode bytes from the default encoding to the target encoding.
write
in class java.io.PrintStream
public boolean isActive()
public byte[] getTranslateTable()
public void flush()
flush
in interface java.io.Flushable
flush
in class java.io.PrintStream
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |