001    /**
002    The contents of this file are subject to the Mozilla Public License Version 1.1 
003    (the "License"); you may not use this file except in compliance with the License. 
004    You may obtain a copy of the License at http://www.mozilla.org/MPL/ 
005    Software distributed under the License is distributed on an "AS IS" basis, 
006    WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the 
007    specific language governing rights and limitations under the License. 
008    
009    The Initial Developer of the Original Code is University Health Network. Copyright (C) 
010    2001.  All Rights Reserved. 
011    
012    Contributor(s): Jens Kristian Villadsen from Cetrea A/S
013    
014    Alternatively, the contents of this file may be used under the terms of the 
015    GNU General Public License (the "GPL"), in which case the provisions of the GPL are 
016    applicable instead of those above.  If you wish to allow use of your version of this 
017    file only under the terms of the GPL and not to allow others to use your version 
018    of this file under the MPL, indicate your decision by deleting  the provisions above 
019    and replace  them with the notice and other provisions required by the GPL License.  
020    If you do not delete the provisions above, a recipient may use your version of 
021    this file under either the MPL or the GPL. 
022    
023     */
024    
025    package ca.uhn.hl7v2.llp;
026    
027    import java.io.IOException;
028    import java.io.InputStream;
029    import java.io.OutputStream;
030    
031    /**
032     * <p>
033     * Minimal Lower Layer Protocol implementation which is detects the text
034     * character set being used by reading in the MSH-18 value. For example, if
035     * MSH-18 contains "ISO-8859-1", the message is parsed using 8859/1 charset
036     * encoding. If MSH-18 contains "UNICODE UTF-8", the message is parsed using
037     * UTF-8 charset encoding.
038     * </p>
039     * <p>
040     * Please note the following warnings regarding the use of this class:
041     * <ul>
042     * <li>
043     * At present, this class supports only the ER7 (pipe and hat) message style.
044     * Using it to receive an XML style message will result in undefined behaviour.</li>
045     * <li>
046     * This class attempts to detect UTF-16 encoding by searching for a byte order
047     * mark at the beginning of the string. While the BOM is optional in UTF-16
048     * encoding, this class will not correctly detect UTF-16 if it is missing. Both
049     * big-endian and little-endian byte order is supported for UTF-16.
050     * </li>
051     * </ul>
052     * </p>
053     * 
054     * @author Jens Kristian Villadsen from Cetrea A/S
055     */
056    public class ExtendedMinLowerLayerProtocol extends LowerLayerProtocol {
057    
058            /**
059             * {@inheritDoc}
060             */
061            @Override
062            public HL7Reader getReader(InputStream in) throws LLPException {
063                    try {
064                            return new ExtendedMinLLPReader(in);
065                    } catch (IOException e) {
066                            throw new LLPException("Can't create MinLLPReader with the given input stream: " + e.getMessage(), e);
067                    }
068            }
069    
070            /**
071             * {@inheritDoc}
072             */
073            @Override
074            public HL7Writer getWriter(OutputStream theOut) throws LLPException {
075                    return new ExtendedMinLLPWriter(theOut);
076            }
077    }