work on #3 - catch IOOBE
This commit is contained in:
@@ -43,16 +43,21 @@ public class AlphaParseInfo extends AlphaNumericFieldParseInfo {
|
||||
throw new ParseException(String.format("Insufficient data for bin %s field of length %d, pos %d",
|
||||
type, length, pos), pos);
|
||||
}
|
||||
if (custom == null) {
|
||||
return new IsoValue<String>(type, new String(buf, pos, length, getCharacterEncoding()), length, null);
|
||||
} else {
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
IsoValue<?> v = new IsoValue(type, custom.decodeField(new String(buf, pos, length, getCharacterEncoding())), length, custom);
|
||||
if (v.getValue() == null) {
|
||||
return new IsoValue<String>(type, new String(buf, pos, length, getCharacterEncoding()), length, null);
|
||||
}
|
||||
return v;
|
||||
}
|
||||
try {
|
||||
if (custom == null) {
|
||||
return new IsoValue<String>(type, new String(buf, pos, length, getCharacterEncoding()), length, null);
|
||||
} else {
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
IsoValue<?> v = new IsoValue(type, custom.decodeField(new String(buf, pos, length, getCharacterEncoding())), length, custom);
|
||||
if (v.getValue() == null) {
|
||||
return new IsoValue<String>(type, new String(buf, pos, length, getCharacterEncoding()), length, null);
|
||||
}
|
||||
return v;
|
||||
}
|
||||
} catch (IndexOutOfBoundsException ex) {
|
||||
throw new ParseException(String.format("Insufficient data for bin %s field of length %d, pos %d",
|
||||
type, length, pos), pos);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -50,6 +50,8 @@ public class AmountParseInfo extends FieldParseInfo {
|
||||
return new IsoValue<BigDecimal>(type, new BigDecimal(c).movePointLeft(2), null);
|
||||
} catch (NumberFormatException ex) {
|
||||
throw new ParseException(String.format("Cannot read amount '%s' pos %d", c, pos), pos);
|
||||
} catch (IndexOutOfBoundsException ex) {
|
||||
throw new ParseException(String.format("Insufficient data for AMOUNT field, pos %d", pos), pos);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,6 +70,8 @@ public class AmountParseInfo extends FieldParseInfo {
|
||||
return new IsoValue<BigDecimal>(IsoType.AMOUNT, new BigDecimal(new String(digits)), null);
|
||||
} catch (NumberFormatException ex) {
|
||||
throw new ParseException(String.format("Cannot read amount '%s' pos %d", new String(digits), pos), pos);
|
||||
} catch (IndexOutOfBoundsException ex) {
|
||||
throw new ParseException(String.format("Insufficient data for AMOUNT field, pos %d", pos), pos);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -54,13 +54,17 @@ public class LlbinParseInfo extends FieldParseInfo {
|
||||
if (custom == null) {
|
||||
return new IsoValue<byte[]>(type, binval, binval.length, null);
|
||||
} else {
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
IsoValue<?> v = new IsoValue(type, custom.decodeField(
|
||||
new String(buf, pos + 2, length)), binval.length, custom);
|
||||
if (v.getValue() == null) {
|
||||
return new IsoValue<byte[]>(type, binval, binval.length, null);
|
||||
}
|
||||
return v;
|
||||
try {
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
IsoValue<?> v = new IsoValue(type, custom.decodeField(
|
||||
new String(buf, pos + 2, length)), binval.length, custom);
|
||||
if (v.getValue() == null) {
|
||||
return new IsoValue<byte[]>(type, binval, binval.length, null);
|
||||
}
|
||||
return v;
|
||||
} catch (IndexOutOfBoundsException ex) {
|
||||
throw new ParseException(String.format("Insufficient data for LLBIN field, pos %d (LEN states '%s')", pos, new String(buf, pos, 2)), pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -56,14 +56,18 @@ public class LllbinParseInfo extends FieldParseInfo {
|
||||
if (custom == null) {
|
||||
return new IsoValue<byte[]>(type, binval, binval.length, null);
|
||||
} else {
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
IsoValue<?> v = new IsoValue(type, custom.decodeField(
|
||||
length == 0 ? "" : new String(buf, pos + 3, length)), length, custom);
|
||||
if (v.getValue() == null) {
|
||||
//problems decoding? return the string
|
||||
return new IsoValue<byte[]>(type, binval, binval.length, null);
|
||||
}
|
||||
return v;
|
||||
try {
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
IsoValue<?> v = new IsoValue(type, custom.decodeField(
|
||||
length == 0 ? "" : new String(buf, pos + 3, length)), length, custom);
|
||||
if (v.getValue() == null) {
|
||||
//problems decoding? return the string
|
||||
return new IsoValue<byte[]>(type, binval, binval.length, null);
|
||||
}
|
||||
return v;
|
||||
} catch (IndexOutOfBoundsException ex) {
|
||||
throw new ParseException(String.format("Insufficient data for LLLBIN field, pos %d", pos), pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -53,7 +53,12 @@ public class LllvarParseInfo extends FieldParseInfo {
|
||||
} else if (length+pos+3 > buf.length) {
|
||||
throw new ParseException(String.format("Insufficient data for LLLVAR field, pos %d", pos), pos);
|
||||
}
|
||||
String _v = length == 0 ? "" : new String(buf, pos + 3, length, getCharacterEncoding());
|
||||
String _v;
|
||||
try {
|
||||
_v = length == 0 ? "" : new String(buf, pos + 3, length, getCharacterEncoding());
|
||||
} catch (IndexOutOfBoundsException ex) {
|
||||
throw new ParseException(String.format("Insufficient data for LLLVAR header, pos %d", pos), pos);
|
||||
}
|
||||
//This is new: if the String's length is different from the specified length in the buffer,
|
||||
//there are probably some extended characters. So we create a String from the rest of the buffer,
|
||||
//and then cut it to the specified length.
|
||||
|
||||
@@ -48,7 +48,12 @@ public class LlvarParseInfo extends FieldParseInfo {
|
||||
} else if (length+pos+2 > buf.length) {
|
||||
throw new ParseException(String.format("Insufficient data for LLVAR field, pos %d", pos), pos);
|
||||
}
|
||||
String _v = length == 0 ? "" : new String(buf, pos + 2, length, getCharacterEncoding());
|
||||
String _v;
|
||||
try {
|
||||
_v = length == 0 ? "" : new String(buf, pos + 2, length, getCharacterEncoding());
|
||||
} catch (IndexOutOfBoundsException ex) {
|
||||
throw new ParseException(String.format("Insufficient data for LLVAR header, pos %d", pos), pos);
|
||||
}
|
||||
//This is new: if the String's length is different from the specified length in the buffer,
|
||||
//there are probably some extended characters. So we create a String from the rest of the buffer,
|
||||
//and then cut it to the specified length.
|
||||
|
||||
@@ -57,10 +57,15 @@ public class NumericParseInfo extends AlphaNumericFieldParseInfo {
|
||||
//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);
|
||||
}
|
||||
try {
|
||||
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);
|
||||
}
|
||||
} catch (IndexOutOfBoundsException ex) {
|
||||
throw new ParseException(String.format("Insufficient data for bin %s field of length %d, pos %d",
|
||||
type, length, pos), pos);
|
||||
}
|
||||
return new IsoValue<Number>(IsoType.NUMERIC, new BigInteger(new String(digits)), length, null);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user