Class MllpCodec

java.lang.Object
com.framed.interop.hl7.mllp.MllpCodec

public final class MllpCodec extends Object
Minimal Lower Layer Protocol (MLLP) framing.

An HL7 message is wrapped as <VT> message <FS><CR>, i.e. a start-block byte (0x0B), the message bytes, an end-block byte (0x1C) and a carriage return (0x0D). This is the de-facto transport framing for HL7 v2 over TCP.

  • Field Details

    • START_BLOCK

      public static final int START_BLOCK
      Start-of-block marker (vertical tab, 0x0B).
      See Also:
    • END_BLOCK

      public static final int END_BLOCK
      End-of-block marker (file separator, 0x1C).
      See Also:
    • CARRIAGE_RETURN

      public static final int CARRIAGE_RETURN
      Trailing carriage return (0x0D).
      See Also:
  • Method Details

    • frame

      public static byte[] frame(String message)
      Frames an HL7 message for MLLP transport.
      Parameters:
      message - the HL7 message text
      Returns:
      the MLLP-framed bytes
    • readMessage

      public static String readMessage(InputStream in) throws IOException
      Reads a single MLLP-framed message from a stream, blocking until a full frame arrives.

      Leading bytes before START_BLOCK are skipped. The terminating END_BLOCK (and the trailing CARRIAGE_RETURN, if present) are consumed but not returned. Tolerant of fragmented reads, since the stream is consumed one byte at a time until the frame completes.

      Parameters:
      in - the input stream
      Returns:
      the message text, or null on clean EOF / truncated frame (connection closed)
      Throws:
      IOException - if the underlying stream fails