From 778501b2d6fcb1bc5e2eb7ec10b6ef99dc52d799 Mon Sep 17 00:00:00 2001 From: Enrique Zamudio Date: Wed, 26 Dec 2012 15:34:09 -0600 Subject: [PATCH] Work on #3 for ALPHA fields --- .../parse/AlphaNumericFieldParseInfo.java | 32 +++++++++++-------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/solab/iso8583/parse/AlphaNumericFieldParseInfo.java b/src/main/java/com/solab/iso8583/parse/AlphaNumericFieldParseInfo.java index 8d3c816..40e239e 100644 --- a/src/main/java/com/solab/iso8583/parse/AlphaNumericFieldParseInfo.java +++ b/src/main/java/com/solab/iso8583/parse/AlphaNumericFieldParseInfo.java @@ -42,20 +42,24 @@ public abstract class AlphaNumericFieldParseInfo extends FieldParseInfo { throw new ParseException(String.format("Insufficient data for %s field of length %d, pos %d", type, length, pos), pos); } - String _v = new String(buf, pos, length, getCharacterEncoding()); - if (_v.length() != length) { - _v = new String(buf, pos, buf.length-pos, getCharacterEncoding()).substring(0, length); - } - if (custom == null) { - return new IsoValue(type, _v, length, null); - } else { - @SuppressWarnings({"unchecked", "rawtypes"}) - IsoValue v = new IsoValue(type, custom.decodeField(_v), length, custom); - if (v.getValue() == null) { - return new IsoValue(type, _v, length, null); - } - return v; - } + try { + String _v = new String(buf, pos, length, getCharacterEncoding()); + if (_v.length() != length) { + _v = new String(buf, pos, buf.length-pos, getCharacterEncoding()).substring(0, length); + } + if (custom == null) { + return new IsoValue(type, _v, length, null); + } else { + @SuppressWarnings({"unchecked", "rawtypes"}) + IsoValue v = new IsoValue(type, custom.decodeField(_v), length, custom); + if (v.getValue() == null) { + return new IsoValue(type, _v, length, null); + } + return v; + } + } catch (StringIndexOutOfBoundsException ex) { + throw new ParseException(String.format("Insufficient data for %s field of length %d, pos %d", type, length, pos), pos); + } } }