public class SwiftParser extends Object
Modifier and Type | Field and Description |
---|---|
static String |
EOL
Helper constant with the content of
System.getProperty("line.separator", "\n") |
Constructor and Description |
---|
SwiftParser()
default constructor.
NOTE: If this constructor is called, setReader must be called to use the parser |
SwiftParser(File messageFile)
Create a parser and feed it with the contents of the given file
|
SwiftParser(InputStream is)
Constructor with an input stream for parsing a message
|
SwiftParser(Reader r)
Constructor with a reader for parsing a message
|
SwiftParser(String message)
Constructor with a String for parsing a message
|
Modifier and Type | Method and Description |
---|---|
protected SwiftBlock4 |
block4Consume(SwiftBlock4 b,
String s)
Parses a block 4 from an input string.
|
protected SwiftBlock |
consumeBlock()
Deprecated.
use
consumeBlock(UnparsedTextList) instead of this, consumeBlock(null) is acceptable |
protected SwiftBlock |
consumeBlock(UnparsedTextList unparsedReceiver)
Consume the next block of the message on the reader.
|
protected Tag |
consumeTag(String buffer,
String unparsedText)
Process the input as a tag.
|
protected String |
findBlockStart()
read on the reader until a block start character or EOF is reached.
|
SwiftParserConfiguration |
getConfiguration()
Gets the current parse configuration
|
List |
getErrors()
Get a copy of the errors found.
|
protected char |
identifyBlock(String s)
Identify the block to be consumed.
|
boolean |
isLenient()
Deprecated.
use
getConfiguration() instead |
SwiftMessage |
message()
Parse a SWIFT message into a data structure
|
SwiftMessage |
parse(String message)
Sets the parameter string as this parser data and returns the parsed object.
|
static SwiftBlock4 |
parseBlock4(String s)
Parses a string containing the text block of an MT message
|
protected String |
readUntilBlockEnds()
Reads the buffer until end of block is reached.
|
void |
setConfiguration(SwiftParserConfiguration configuration)
Sets a new parse configuration
|
void |
setData(String data)
sets the input data to the received string.
|
void |
setLenient(boolean lenient)
Deprecated.
use
setConfiguration(SwiftParserConfiguration) instead |
void |
setReader(Reader r)
sets the input reader.
NOTE: this resets the internal buffer |
protected SwiftTagListBlock |
tagListBlockConsume(SwiftTagListBlock b,
String s)
consumes a tag list block (i.e: block 3, block 5 or user defined block)
|
protected int |
textTagEndBlock4(String s,
int start,
boolean isTextBlock)
finds the end of a text tag (i.e: ":TAG:VALUE").
|
public static final String EOL
System.getProperty("line.separator", "\n")
public SwiftParser(InputStream is)
is
- stream to readpublic SwiftParser(Reader r)
r
- the Reader with the swift message to readpublic SwiftParser(String message)
message
- the String with the swift message to readpublic SwiftParser()
public SwiftParser(File messageFile) throws IOException
messageFile
- existing, readable file to readIOException
- if an error occurs during readpublic void setReader(Reader r)
r
- the reader to usepublic void setData(String data)
data
- the data to use as inputpublic SwiftMessage message() throws IOException
IOException
public SwiftMessage parse(String message) throws IOException
message
- the String with the swift message to parseIOException
@Deprecated @ProwideDeprecated(phase2=_2017) protected SwiftBlock consumeBlock() throws IOException
IOException
protected SwiftBlock consumeBlock(UnparsedTextList unparsedReceiver) throws IOException
unparsedReceiver
- may be null
, the unparsedTextList that will receive the chunks that can not be identified sas part of the messagenull
if none was found (i.e: end of input)IOException
- if an error occurred during readprotected SwiftTagListBlock tagListBlockConsume(SwiftTagListBlock b, String s) throws IOException
b
- the block to set up tags intos
- the block data to processIOException
protected SwiftBlock4 block4Consume(SwiftBlock4 b, String s) throws IOException
b
- the block to set up tags intos
- the block data to processIOException
protected int textTagEndBlock4(String s, int start, boolean isTextBlock)
s
- the FIN input textstart
- the position to start analysis atprotected Tag consumeTag(String buffer, String unparsedText) throws IOException
buffer
- the buffer containing the tagunparsedText
- the unparsed text to assign (use null
if none is wanted).
This single text is fragmented in multiple texts if there are more than one message.IOException
protected char identifyBlock(String s)
s
- the block identifierprotected String readUntilBlockEnds() throws IOException
This method assumes that the starting block character was consumed because that is required in order to identify the start of a block, and call this method which reads until this block ends.
IOException
protected String findBlockStart() throws IOException
IOException
- if thrown during readpublic List getErrors()
@Deprecated public boolean isLenient()
getConfiguration()
instead@Deprecated public void setLenient(boolean lenient)
setConfiguration(SwiftParserConfiguration)
insteadpublic SwiftParserConfiguration getConfiguration()
SwiftParserConfiguration
public void setConfiguration(SwiftParserConfiguration configuration)
configuration
- new configurationSwiftParserConfiguration
public static SwiftBlock4 parseBlock4(String s) throws IOException
s
- block content starting with "{4:\r\n" and ending with "\r\n-}"IOException