FieldParseInfo is now an abstract class, with a concrete subclass for each IsoType. This greatly improves the parsing speed.

git-svn-id: https://j8583.svn.sourceforge.net/svnroot/j8583/j8583@66 db60a039-f72e-0410-b1d2-baa000846441
This commit is contained in:
chochos
2011-02-21 19:53:47 +00:00
parent 3b36a1dfe9
commit d291d41bbc
16 changed files with 781 additions and 395 deletions
@@ -0,0 +1,44 @@
package com.solab.iso8583.parse;
import java.math.BigInteger;
import java.text.ParseException;
import com.solab.iso8583.CustomField;
import com.solab.iso8583.IsoType;
import com.solab.iso8583.IsoValue;
/** This class is used to parse NUMERIC fields.
*
* @author Enrique Zamudio
*/
public class NumericParseInfo extends AlphaNumericFieldParseInfo {
public NumericParseInfo(int len) {
super(IsoType.NUMERIC, len);
}
public <T extends Object> IsoValue<?> parseBinary(byte[] buf, int pos, CustomField<T> custom) throws ParseException {
//A long covers up to 18 digits
if (length < 19) {
long l = 0;
long power = 1L;
for (int i = pos + (length / 2) + (length % 2) - 1; i >= pos; i--) {
l += (buf[i] & 0x0f) * power;
power *= 10L;
l += ((buf[i] & 0xf0) >> 4) * power;
power *= 10L;
}
return new IsoValue<Number>(IsoType.NUMERIC, l, length, null);
} else {
//Use a BigInteger
char[] digits = new char[length];
int start = 0;
for (int i = pos; i < pos + (length / 2) + (length % 2); i++) {
digits[start++] = (char)(((buf[i] & 0xf0) >> 4) + 48);
digits[start++] = (char)((buf[i] & 0x0f) + 48);
}
return new IsoValue<Number>(IsoType.NUMERIC, new BigInteger(new String(digits)), length, null);
}
}
}