@Test public void unpackWithTagFirstZeroLenFixedLenField() throws ISOException { byte[] raw = new byte[] {(byte)0xF6, (byte)0xF0, (byte)0xF1, (byte)0xF2, (byte)0xF3}; ISOFormattableStringFieldPackager packager = new ISOFormattableStringFieldPackager(3, "Should be 60123", EbcdicPrefixer.LL, NullPadder.INSTANCE, EbcdicInterpreter.INSTANCE, NullPrefixer.INSTANCE, IsoFieldHeaderFormatter.TAG_FIRST); ISOField isoField = new ISOField(); assertEquals(raw.length, packager.unpack(isoField, raw, 0)); assertEquals("123", (String) isoField.getValue()); assertEquals(60, isoField.fieldNumber); }
@Override public int unpack(ISOComponent c, byte[] b, int offset) throws ISOException { try{ int tagLen = tagPrefixer.getPackedLength(); c.setFieldNumber(tagPrefixer.decodeLength(b, offset + headerFormatter.getTagIndex(prefixer))); int len = prefixer.decodeLength(b, offset + headerFormatter.getLengthIndex(tagPrefixer)); if (!headerFormatter.isTagFirst()) { len -= tagPrefixer.getPackedLength(); } if (len == -1) { len = getLength(); } else if (getLength() > 0 && len > getLength()) { throw new ISOException("Field length " + len + " too long. Max: " + getLength()); } int lenLen = prefixer.getPackedLength(); String unpacked = interpreter.uninterpret(b, offset + tagPrefixer.getPackedLength() + prefixer.getPackedLength(), len); c.setValue(padder.unpad(unpacked)); return tagLen + lenLen + interpreter.getPackedLength(len); } catch(Exception e){ throw new ISOException(makeExceptionMessage(c, "unpacking"), e); } }
ISOFormattableStringFieldPackager extends ISOFieldPackager { @Override public int unpack(ISOComponent c, byte[] b, int offset) throws ISOException { try{ int tagLen = tagPrefixer.getPackedLength(); c.setFieldNumber(tagPrefixer.decodeLength(b, offset + headerFormatter.getTagIndex(prefixer))); int len = prefixer.decodeLength(b, offset + headerFormatter.getLengthIndex(tagPrefixer)); if (!headerFormatter.isTagFirst()) { len -= tagPrefixer.getPackedLength(); } if (len == -1) { len = getLength(); } else if (getLength() > 0 && len > getLength()) { throw new ISOException("Field length " + len + " too long. Max: " + getLength()); } int lenLen = prefixer.getPackedLength(); String unpacked = interpreter.uninterpret(b, offset + tagPrefixer.getPackedLength() + prefixer.getPackedLength(), len); c.setValue(padder.unpad(unpacked)); return tagLen + lenLen + interpreter.getPackedLength(len); } catch(Exception e){ throw new ISOException(makeExceptionMessage(c, "unpacking"), e); } } }
ISOFormattableStringFieldPackager extends ISOFieldPackager { @Override public int unpack(ISOComponent c, byte[] b, int offset) throws ISOException { try{ int tagLen = tagPrefixer.getPackedLength(); c.setFieldNumber(tagPrefixer.decodeLength(b, offset + headerFormatter.getTagIndex(prefixer))); int len = prefixer.decodeLength(b, offset + headerFormatter.getLengthIndex(tagPrefixer)); if (!headerFormatter.isTagFirst()) { len -= tagPrefixer.getPackedLength(); } if (len == -1) { len = getLength(); } else if (getLength() > 0 && len > getLength()) { throw new ISOException("Field length " + len + " too long. Max: " + getLength()); } int lenLen = prefixer.getPackedLength(); String unpacked = interpreter.uninterpret(b, offset + tagPrefixer.getPackedLength() + prefixer.getPackedLength(), len); c.setValue(padder.unpad(unpacked)); return tagLen + lenLen + interpreter.getPackedLength(len); } catch(Exception e){ throw new ISOException(makeExceptionMessage(c, "unpacking"), e); } } ISOFormattableStringFieldPackager();  ISOFormattableStringFieldPackager(Prefixer tagPrefixer, Padder padder,
                                             Interpreter interpreter, Prefixer lengthPrefixer);  ISOFormattableStringFieldPackager(Prefixer tagPrefixer, Padder padder,
                                             Interpreter interpreter, Prefixer lengthPrefixer,
                                             IsoFieldHeaderFormatter headerFormatter);  ISOFormattableStringFieldPackager(int maxLength, String description, Prefixer tagPrefixer,
                                             Padder padder, Interpreter interpreter, Prefixer lengthPrefixer,
                                             IsoFieldHeaderFormatter headerFormatter); }
ISOFormattableStringFieldPackager extends ISOFieldPackager { @Override public int unpack(ISOComponent c, byte[] b, int offset) throws ISOException { try{ int tagLen = tagPrefixer.getPackedLength(); c.setFieldNumber(tagPrefixer.decodeLength(b, offset + headerFormatter.getTagIndex(prefixer))); int len = prefixer.decodeLength(b, offset + headerFormatter.getLengthIndex(tagPrefixer)); if (!headerFormatter.isTagFirst()) { len -= tagPrefixer.getPackedLength(); } if (len == -1) { len = getLength(); } else if (getLength() > 0 && len > getLength()) { throw new ISOException("Field length " + len + " too long. Max: " + getLength()); } int lenLen = prefixer.getPackedLength(); String unpacked = interpreter.uninterpret(b, offset + tagPrefixer.getPackedLength() + prefixer.getPackedLength(), len); c.setValue(padder.unpad(unpacked)); return tagLen + lenLen + interpreter.getPackedLength(len); } catch(Exception e){ throw new ISOException(makeExceptionMessage(c, "unpacking"), e); } } ISOFormattableStringFieldPackager();  ISOFormattableStringFieldPackager(Prefixer tagPrefixer, Padder padder,
                                             Interpreter interpreter, Prefixer lengthPrefixer);  ISOFormattableStringFieldPackager(Prefixer tagPrefixer, Padder padder,
                                             Interpreter interpreter, Prefixer lengthPrefixer,
                                             IsoFieldHeaderFormatter headerFormatter);  ISOFormattableStringFieldPackager(int maxLength, String description, Prefixer tagPrefixer,
                                             Padder padder, Interpreter interpreter, Prefixer lengthPrefixer,
                                             IsoFieldHeaderFormatter headerFormatter); void setPadder(Padder padder); void setInterpreter(Interpreter interpreter); void setPrefixer(Prefixer prefixer); IsoFieldHeaderFormatter getHeaderFormatter(); void setHeaderFormatter(IsoFieldHeaderFormatter headerFormatter); @Override int getMaxPackedLength(); @Override byte[] pack(ISOComponent c); @Override int unpack(ISOComponent c, byte[] b, int offset); @Override void unpack(ISOComponent c, InputStream in); }
ISOFormattableStringFieldPackager extends ISOFieldPackager { @Override public int unpack(ISOComponent c, byte[] b, int offset) throws ISOException { try{ int tagLen = tagPrefixer.getPackedLength(); c.setFieldNumber(tagPrefixer.decodeLength(b, offset + headerFormatter.getTagIndex(prefixer))); int len = prefixer.decodeLength(b, offset + headerFormatter.getLengthIndex(tagPrefixer)); if (!headerFormatter.isTagFirst()) { len -= tagPrefixer.getPackedLength(); } if (len == -1) { len = getLength(); } else if (getLength() > 0 && len > getLength()) { throw new ISOException("Field length " + len + " too long. Max: " + getLength()); } int lenLen = prefixer.getPackedLength(); String unpacked = interpreter.uninterpret(b, offset + tagPrefixer.getPackedLength() + prefixer.getPackedLength(), len); c.setValue(padder.unpad(unpacked)); return tagLen + lenLen + interpreter.getPackedLength(len); } catch(Exception e){ throw new ISOException(makeExceptionMessage(c, "unpacking"), e); } } ISOFormattableStringFieldPackager();  ISOFormattableStringFieldPackager(Prefixer tagPrefixer, Padder padder,
                                             Interpreter interpreter, Prefixer lengthPrefixer);  ISOFormattableStringFieldPackager(Prefixer tagPrefixer, Padder padder,
                                             Interpreter interpreter, Prefixer lengthPrefixer,
                                             IsoFieldHeaderFormatter headerFormatter);  ISOFormattableStringFieldPackager(int maxLength, String description, Prefixer tagPrefixer,
                                             Padder padder, Interpreter interpreter, Prefixer lengthPrefixer,
                                             IsoFieldHeaderFormatter headerFormatter); void setPadder(Padder padder); void setInterpreter(Interpreter interpreter); void setPrefixer(Prefixer prefixer); IsoFieldHeaderFormatter getHeaderFormatter(); void setHeaderFormatter(IsoFieldHeaderFormatter headerFormatter); @Override int getMaxPackedLength(); @Override byte[] pack(ISOComponent c); @Override int unpack(ISOComponent c, byte[] b, int offset); @Override void unpack(ISOComponent c, InputStream in);  }