- java.lang.Object
-
- com.ibm.jzos.Transcoder
-
public class Transcoder extends java.lang.Object
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
Constructors Constructor Description Transcoder(java.lang.String sourceEncoding, java.lang.String targetEncoding, java.io.OutputStream outputStream)
Construct an instanceTranscoder(java.lang.String sourceEncoding, java.lang.String targetEncoding, java.io.OutputStream outputStream, int byteBufferSize, int charBufferSize, boolean autoFlush)
Construct an instance
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
flush()
Flush the output encoding writerjava.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 CharSetjava.nio.charset.Charset
getTargetCharset()
Answer the target Charsetboolean
isAutoFlush()
Answer true if autoFlush is enabledvoid
reset()
Rest the encoding statevoid
setAutoFlush(boolean autoFlush)
Enable or disable autoflushvoid
translate(byte[] bytes)
Transcode a byte arrayvoid
translate(byte[] bytes, int offset, int length)
Transcode a byte array at a given offset and length
-
-
-
Constructor Detail
-
Transcoder
public Transcoder(java.lang.String sourceEncoding, java.lang.String targetEncoding, java.io.OutputStream outputStream) throws java.nio.charset.UnsupportedCharsetException
Construct an instance- Parameters:
sourceEncoding
- the source codepage nametargetEncoding
- the target codepage nameoutputStream
- the target OutputStream- Throws:
java.nio.charset.UnsupportedCharsetException
-
Transcoder
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
Construct an instance- Parameters:
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- Throws:
java.nio.charset.UnsupportedCharsetException
-
-
Method Detail
-
translate
public void translate(byte[] bytes) throws java.io.IOException
Transcode a byte array- Throws:
java.io.IOException
-
translate
public void translate(byte[] bytes, int offset, int length) throws java.io.IOException
Transcode a byte array at a given offset and length- Throws:
java.io.IOException
-
getDecoder
public java.nio.charset.CharsetDecoder getDecoder()
Return the CharsetDecoder that is in use by this Transcoder. Access is provided so that the CodingErrorActions can be changed or a new unicode replacement string supplied. By default, the decoder REPLACEs malformed input and unmappable bytes with the its default replacement string.
-
getEncoder
public java.nio.charset.CharsetEncoder getEncoder()
Return the CharsetEncoder that is in use by this Transcoder. Access is provided so that the CodingErrorActions can be changed or a new replacement byte sequence supplied. By default, the encoder REPLACEs malformed input and unmappable characters with the its default replacement byte sequence.
-
flush
public void flush() throws java.io.IOException
Flush the output encoding writer- Throws:
java.io.IOException
-
reset
public void reset() throws java.io.IOException
Rest the encoding state- Throws:
java.io.IOException
-
isAutoFlush
public boolean isAutoFlush()
Answer true if autoFlush is enabled
-
setAutoFlush
public void setAutoFlush(boolean autoFlush)
Enable or disable autoflush
-
getSourceCharset
public java.nio.charset.Charset getSourceCharset()
Answer the source CharSet
-
getTargetCharset
public java.nio.charset.Charset getTargetCharset()
Answer the target Charset
-
-