Package org.dellroad.hl7.llp
Class MSH18CharsetDecoder
- java.lang.Object
-
- org.dellroad.hl7.llp.MSH18CharsetDecoder
-
- All Implemented Interfaces:
CharsetDecoder
public class MSH18CharsetDecoder extends Object implements CharsetDecoder
Attempts to determine HL7 message character encoding by decoding header fieldMSH.18, if present, or falling back to a configured default as a last resort.Instances are thread safe.
-
-
Field Summary
Fields Modifier and Type Field Description protected CharsetdefaultCharset
-
Constructor Summary
Constructors Constructor Description MSH18CharsetDecoder()Constructor usingISO-8859-1as the default charset.MSH18CharsetDecoder(Charset defaultCharset)Primary constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CharsetcharsetForIncomingMessage(byte[] buf, int off, int len)Determine the character encoding to use for an incoming HL7 message.CharsetcharsetForOutgoingMessage(HL7Message msg)Determine the character encoding to use for an outgoing HL7 message.CharsetdecodeCharsetName(String name)Decode a character encoding name found inMSH.18.protected CharsetdecodeMSH18(MSHSegment msh)Read and decode the character encoding name from MSH.18, if possible.
-
-
-
Field Detail
-
defaultCharset
protected final Charset defaultCharset
-
-
Constructor Detail
-
MSH18CharsetDecoder
public MSH18CharsetDecoder()
Constructor usingISO-8859-1as the default charset.
-
MSH18CharsetDecoder
public MSH18CharsetDecoder(Charset defaultCharset)
Primary constructor.- Parameters:
defaultCharset- default character encoding to use if unable to determine fromMSH.18- Throws:
IllegalArgumentException- ifdefaultCharsetis null
-
-
Method Detail
-
charsetForIncomingMessage
public Charset charsetForIncomingMessage(byte[] buf, int off, int len)
Description copied from interface:CharsetDecoderDetermine the character encoding to use for an incoming HL7 message.- Specified by:
charsetForIncomingMessagein interfaceCharsetDecoder- Parameters:
buf- raw HL7 message bufferoff- HL7 message offset inbuflen- HL7 message length inbuf- Returns:
- character encoding to use for the given message (never null)
-
charsetForOutgoingMessage
public Charset charsetForOutgoingMessage(HL7Message msg)
Description copied from interface:CharsetDecoderDetermine the character encoding to use for an outgoing HL7 message.- Specified by:
charsetForOutgoingMessagein interfaceCharsetDecoder- Parameters:
msg- HL7 message- Returns:
- character encoding to use for the given message (never null)
-
decodeMSH18
protected Charset decodeMSH18(MSHSegment msh)
Read and decode the character encoding name from MSH.18, if possible.- Parameters:
msh- MSH segment- Returns:
- decoded character encoding, or the default if unable
-
decodeCharsetName
public Charset decodeCharsetName(String name)
Decode a character encoding name found inMSH.18.- Parameters:
name- character set name fromMSH.18- Returns:
- decoded
Charset, or null if unable to decode - Throws:
IllegalArgumentException- iflabelis null
-
-