|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.ibm.jzos.Transcoder
public class Transcoder
This class provides conversions from a source Charset (Codepage) to a target Charset. A byte array encoded in the source Charset is accepted as input. These bytes are decoded to unicode with the source Charset decoder. The resulting CharBuffer is written to the supplied outputStream through an OutputStreamWriter encoded with the target Charset.
This class is not threadsafe; the decoder and ByteBuffer used for processing the input are stateful. This is due to the fact that the source byte array may be encoded with a multi-byte Charset (e.g. UTF-8), and a call to translate() may deliver a byte array that has an incomplete byte sequence. Subsequent call(s) to translate() are expected to deliver the remaining bytes in the sequence. Once these bytes arrive, the incomplete sequence can be decoded. A direct ByteBuffer is used (rather than wrapping the input byte array) so that the incomplete byte sequence can be preserved between calls.
The errorActions taken for both the decoder and encoder are CodingErrorAction.REPLACE. The default replacement will be used, but can be overridden.
Constructor Summary | |
---|---|
Transcoder(java.lang.String sourceEncoding,
java.lang.String targetEncoding,
java.io.OutputStream outputStream)
Construct an instnace |
|
Transcoder(java.lang.String sourceEncoding,
java.lang.String targetEncoding,
java.io.OutputStream outputStream,
int byteBufferSize,
int charBufferSize,
boolean autoFlush)
Construct an instance |
Method Summary | |
---|---|
void |
flush()
Flush the output encoding writer |
java.nio.charset.CharsetDecoder |
getDecoder()
Return the CharsetDecoder that is in use by this Transcoder. |
java.nio.charset.CharsetEncoder |
getEncoder()
Return the CharsetEncoder that is in use by this Transcoder. |
java.nio.charset.Charset |
getSourceCharset()
Answer the source CharSet |
java.nio.charset.Charset |
getTargetCharset()
Answer the target Charset |
boolean |
isAutoFlush()
Answer true if autoFlush is enabled |
void |
reset()
Rest the encoding state |
void |
setAutoFlush(boolean autoFlush)
Enable or disable autoflush |
void |
translate(byte[] bytes)
Transcode a byte array |
void |
translate(byte[] bytes,
int offset,
int length)
Transcode a byte array at a given offset and length |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Transcoder(java.lang.String sourceEncoding, java.lang.String targetEncoding, java.io.OutputStream outputStream) throws java.nio.charset.UnsupportedCharsetException
sourceEncoding
- the source codepage nametargetEncoding
- the target codepage nameoutputStream
- the target OutputStream
java.nio.charset.UnsupportedCharsetException
public Transcoder(java.lang.String sourceEncoding, java.lang.String targetEncoding, java.io.OutputStream outputStream, int byteBufferSize, int charBufferSize, boolean autoFlush) throws java.nio.charset.UnsupportedCharsetException
sourceEncoding
- the source codepage nametargetEncoding
- the target codepage nameoutputStream
- the target OutputStreambyteBufferSize
- the byte/input buffer sizecharBufferSize
- the character/output buffersizeautoFlush
- if true, autoflush the output stream
java.nio.charset.UnsupportedCharsetException
Method Detail |
---|
public void translate(byte[] bytes) throws java.io.IOException
java.io.IOException
public void translate(byte[] bytes, int offset, int length) throws java.io.IOException
java.io.IOException
public java.nio.charset.CharsetDecoder getDecoder()
public java.nio.charset.CharsetEncoder getEncoder()
public void flush() throws java.io.IOException
java.io.IOException
public void reset() throws java.io.IOException
java.io.IOException
public boolean isAutoFlush()
public void setAutoFlush(boolean autoFlush)
public java.nio.charset.Charset getSourceCharset()
public java.nio.charset.Charset getTargetCharset()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |