Class FSDMsg
java.lang.Object
org.jpos.util.FSDMsg
General purpose, Field Separator delimited message.
How to use
The message format (or schema) is defined in xml files containing a schema element, with an optional id attribute, and multiple field elements. A field element is made up of the following attributes:
- id
- The name of the field. This is used in calls to
set(String, String). It should be unique amongst the fields in an FSDMsg. - length
- The maximum length of the data allowed in this field. Fixed length fields will be padded to this length. A zero length is allowed, and can be useful to define extra separator characters in the message.
- type
- The type of the included data, including an optional separator for marking the end of the field and the beginning of the next one. The data type is defined by the first char of the type, and the separator is defined by the following chars. If a field separator is specified, then no padding is done on values for this field.
- key
- If this optional attribute has a value of "true", then fields from another schema, specified by the value, are appended to this schema.
- separator
- An optional attribute containing the separator for the field. This is the preferred method of specifying the separator. See the list of optional
Possible types are:
- A
- Alphanumeric. Padding if any is done with spaces to the right.
- B
- Binary. Padding, if any, is done with zeros to the left.
- K
- Constant. The value is specified by the field content. No padding is done.
- N
- Numeric. Padding, if any, is done with zeros to the left.
Supported field separators are:
- FS
- Field separator using '034' as the separator.
- US
- Field separator using '037' as the separator.
- GS
- Group separator using '035' as the separator.
- RS
- Row separator using '036' as the separator.
- PIPE
- Field separator using '|' as the separator.
- EOF
- End of File - no separator character is emitted, but also no padding is done. Also if the end of file is reached parsing a message, then no exception is thrown.
- DS
- A dummy separator. This is similar to EOF, but the message stream must not end before it is allowed.
- EOM
- End of message separator. This reads all bytes available in the stream.
Key fields allow you to specify a tree of possible message formats. The key fields are the fork points of the tree. Multiple key fields are supported. It is also possible to have more key fields specified in appended schemas.
- Since:
- 1.4.7
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionclone()voidvoidvoiddump(PrintStream p, String indent) booleanprotected Stringprotected Stringbyte[]byte[]getHexBytes(String name) intintgetMap()protected org.jdom2.Elementprotected org.jdom2.Elementprotected org.jdom2.ElementbooleaninthashCode()booleanisSeparator(byte b) protected org.jdom2.ElementloadSchema(String uri, boolean throwex) voidpack()protected voidpack(org.jdom2.Element schema, StringBuilder sb) byte[]protected Stringread(InputStreamReader r, int len, String type, String separator) protected StringreadField(InputStreamReader r, String fieldName, int len, String type, String separator) protected InputStreamschemaResouceInputStream(String resource) voidvoidsetCharset(Charset charset) voidsetHeader(byte[] h) voidvoidsetSeparator(String separatorName, char separator) org.jdom2.ElementtoXML()voidunpack(byte[] b) parse message.voidunpack(InputStream is) parse message.protected voidunpack(InputStreamReader r, org.jdom2.Element schema) voidunsetSeparator(String separatorName)
-
Field Details
-
FS
-
US
-
GS
-
RS
-
EOF
-
PIPE
-
EOM
-
-
Constructor Details
-
FSDMsg
-
FSDMsg
Creates a FSDMsg with a specific base path for the message format schema, and a base schema name. For instance, FSDMsg("file:src/data/NDC-", "root") will look for a file: src/data/NDC-root.xml- Parameters:
basePath- schema pathbaseSchema- schema name
-
-
Method Details
-
getBasePath
-
getBaseSchema
-
setCharset
-
setSeparator
-
unsetSeparator
-
unpack
parse message. If the stream ends before the message is completely read, then the method adds an EOF field.- Parameters:
is- input stream- Throws:
IOExceptionorg.jdom2.JDOMException
-
unpack
parse message. If the stream ends before the message is completely read, then the method adds an EOF field.- Parameters:
b- message image- Throws:
IOExceptionorg.jdom2.JDOMException
-
pack
- Returns:
- message string
- Throws:
org.jdom2.JDOMExceptionIOExceptionISOException
-
packToBytes
- Throws:
org.jdom2.JDOMExceptionIOExceptionISOException
-
get
protected String get(String id, String type, int length, String defValue, String separator) throws ISOException - Throws:
ISOException
-
get
protected String get(String id, String type, int length, String defValue, String separator, boolean unPad) throws ISOException - Throws:
ISOException
-
isSeparator
-
pack
protected void pack(org.jdom2.Element schema, StringBuilder sb) throws org.jdom2.JDOMException, IOException, ISOException - Throws:
org.jdom2.JDOMExceptionIOExceptionISOException
-
unpack
protected void unpack(InputStreamReader r, org.jdom2.Element schema) throws IOException, org.jdom2.JDOMException - Throws:
IOExceptionorg.jdom2.JDOMException
-
read
protected String read(InputStreamReader r, int len, String type, String separator) throws IOException - Throws:
IOException
-
readField
protected String readField(InputStreamReader r, String fieldName, int len, String type, String separator) throws IOException - Throws:
IOException
-
set
-
setHeader
-
getHeader
-
getHexHeader
-
get
-
get
-
copy
-
copy
-
getHexBytes
-
getInt
-
getInt
-
toXML
-
getSchema
- Throws:
org.jdom2.JDOMExceptionIOException
-
getSchema
- Throws:
org.jdom2.JDOMExceptionIOException
-
getSchema
protected org.jdom2.Element getSchema(String prefix, String suffix, String defSuffix) throws org.jdom2.JDOMException, IOException - Throws:
org.jdom2.JDOMExceptionIOException
-
loadSchema
protected org.jdom2.Element loadSchema(String uri, boolean throwex) throws org.jdom2.JDOMException, IOException - Throws:
org.jdom2.JDOMExceptionIOException
-
schemaResouceInputStream
protected InputStream schemaResouceInputStream(String resource) throws org.jdom2.JDOMException, IOException - Throws:
org.jdom2.JDOMExceptionIOException
-
getMap
-
setMap
-
dump
-
hasField
-
clone
-
merge
-
equals
-
hashCode
-