Package org.dellroad.hl7.io
Class HL7FileReader
- java.lang.Object
-
- org.dellroad.hl7.io.HL7FileReader
-
- All Implemented Interfaces:
Closeable,AutoCloseable,HL7Reader
public class HL7FileReader extends Object implements HL7Reader, Closeable
Reads in HL7 messages in "file format".The "file format" is as follows:
- Each message begins with an
MSHsegment - Each segment is terminated by a CR, LF, or CR-LF
- Blank and whitespace-only lines are ignored
- Lines starting with '#' are ignored
-
-
Field Summary
Fields Modifier and Type Field Description protected BufferedReaderreader
-
Constructor Summary
Constructors Constructor Description HL7FileReader(InputStream in)Convenience constructor.HL7FileReader(Reader in)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Closes the underlying reader.protected StringnextLine()Read next non-ignorable line.protected voidpushback(String line)Save the line for next time.HL7MessagereadMessage()Read next message from the underlying stream.
-
-
-
Field Detail
-
reader
protected final BufferedReader reader
-
-
Constructor Detail
-
HL7FileReader
public HL7FileReader(Reader in)
Constructor.- Parameters:
in- underlying reader
-
HL7FileReader
public HL7FileReader(InputStream in)
Convenience constructor. Equivalent to:HL7FileReader(new InputStreamReader(in, StandardCharsets.ISO_8859_1))- Parameters:
in- underlying input stream
-
-
Method Detail
-
readMessage
public HL7Message readMessage() throws IOException, HL7ContentException
Read next message from the underlying stream.- Specified by:
readMessagein interfaceHL7Reader- Returns:
- next message read
- Throws:
EOFException- if there is no more inputHL7ContentException- if a malformed message is readIOException- if an error occurs on the underlying stream
-
pushback
protected void pushback(String line)
Save the line for next time.- Parameters:
line- line to push back- Throws:
RuntimeException- if there is already one saved
-
nextLine
protected String nextLine() throws IOException
Read next non-ignorable line.- Returns:
- next relevant line, or null for EOF
- Throws:
IOException- if an I/O error occurs
-
close
public void close() throws IOExceptionCloses the underlying reader.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
-