@Test public void unpackWithTagFirst() throws ISOException { byte[] raw = new byte[] {(byte)0xF1, (byte)0xF2,(byte)0xF0, (byte)0xF2, (byte)0x30, (byte)0x31}; ISOFormattableBinaryFieldPackager packager = new ISOFormattableBinaryFieldPackager(999, "Should be 1234", EbcdicPrefixer.LL, NullPadder.INSTANCE, LiteralBinaryInterpreter.INSTANCE, EbcdicPrefixer.LL, IsoFieldHeaderFormatter.TAG_FIRST); ISOBinaryField isoField = new ISOBinaryField(); assertEquals(raw.length, packager.unpack(isoField, raw, 0)); TestUtils.assertEquals (new byte[] {(byte)0x30, (byte)0x31}, (byte[]) isoField.getValue()); assertEquals(12, 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(); byte[] unpacked = interpreter.uninterpret(b, offset + tagPrefixer.getPackedLength() + prefixer.getPackedLength(), len); byte[] paddedValueBytes = unpacked; if (!(padder instanceof NullPadder)) paddedValueBytes = ISOUtil.hex2byte(padder.unpad(ISOUtil.hexString(unpacked))); c.setValue(paddedValueBytes); return tagLen + lenLen + interpreter.getPackedLength(len); } catch(Exception e){ throw new ISOException(makeExceptionMessage(c, "unpacking"), e); } }
ISOFormattableBinaryFieldPackager 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(); byte[] unpacked = interpreter.uninterpret(b, offset + tagPrefixer.getPackedLength() + prefixer.getPackedLength(), len); byte[] paddedValueBytes = unpacked; if (!(padder instanceof NullPadder)) paddedValueBytes = ISOUtil.hex2byte(padder.unpad(ISOUtil.hexString(unpacked))); c.setValue(paddedValueBytes); return tagLen + lenLen + interpreter.getPackedLength(len); } catch(Exception e){ throw new ISOException(makeExceptionMessage(c, "unpacking"), e); } } }
ISOFormattableBinaryFieldPackager 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(); byte[] unpacked = interpreter.uninterpret(b, offset + tagPrefixer.getPackedLength() + prefixer.getPackedLength(), len); byte[] paddedValueBytes = unpacked; if (!(padder instanceof NullPadder)) paddedValueBytes = ISOUtil.hex2byte(padder.unpad(ISOUtil.hexString(unpacked))); c.setValue(paddedValueBytes); return tagLen + lenLen + interpreter.getPackedLength(len); } catch(Exception e){ throw new ISOException(makeExceptionMessage(c, "unpacking"), e); } } ISOFormattableBinaryFieldPackager();  ISOFormattableBinaryFieldPackager(Prefixer tagPrefixer, Padder padder,
                                             BinaryInterpreter interpreter, Prefixer prefixer);  ISOFormattableBinaryFieldPackager(Prefixer tagPrefixer, Padder padder,
                                             BinaryInterpreter interpreter, Prefixer lengthPrefixer,
                                             IsoFieldHeaderFormatter headerFormatter);  ISOFormattableBinaryFieldPackager(int maxLength, String description, Prefixer tagPrefixer,
                                             Padder padder, BinaryInterpreter interpreter, Prefixer lengthPrefixer,
                                             IsoFieldHeaderFormatter headerFormatter); }
ISOFormattableBinaryFieldPackager 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(); byte[] unpacked = interpreter.uninterpret(b, offset + tagPrefixer.getPackedLength() + prefixer.getPackedLength(), len); byte[] paddedValueBytes = unpacked; if (!(padder instanceof NullPadder)) paddedValueBytes = ISOUtil.hex2byte(padder.unpad(ISOUtil.hexString(unpacked))); c.setValue(paddedValueBytes); return tagLen + lenLen + interpreter.getPackedLength(len); } catch(Exception e){ throw new ISOException(makeExceptionMessage(c, "unpacking"), e); } } ISOFormattableBinaryFieldPackager();  ISOFormattableBinaryFieldPackager(Prefixer tagPrefixer, Padder padder,
                                             BinaryInterpreter interpreter, Prefixer prefixer);  ISOFormattableBinaryFieldPackager(Prefixer tagPrefixer, Padder padder,
                                             BinaryInterpreter interpreter, Prefixer lengthPrefixer,
                                             IsoFieldHeaderFormatter headerFormatter);  ISOFormattableBinaryFieldPackager(int maxLength, String description, Prefixer tagPrefixer,
                                             Padder padder, BinaryInterpreter interpreter, Prefixer lengthPrefixer,
                                             IsoFieldHeaderFormatter headerFormatter); void setPadder(Padder padder); void setInterpreter(BinaryInterpreter 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); }
ISOFormattableBinaryFieldPackager 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(); byte[] unpacked = interpreter.uninterpret(b, offset + tagPrefixer.getPackedLength() + prefixer.getPackedLength(), len); byte[] paddedValueBytes = unpacked; if (!(padder instanceof NullPadder)) paddedValueBytes = ISOUtil.hex2byte(padder.unpad(ISOUtil.hexString(unpacked))); c.setValue(paddedValueBytes); return tagLen + lenLen + interpreter.getPackedLength(len); } catch(Exception e){ throw new ISOException(makeExceptionMessage(c, "unpacking"), e); } } ISOFormattableBinaryFieldPackager();  ISOFormattableBinaryFieldPackager(Prefixer tagPrefixer, Padder padder,
                                             BinaryInterpreter interpreter, Prefixer prefixer);  ISOFormattableBinaryFieldPackager(Prefixer tagPrefixer, Padder padder,
                                             BinaryInterpreter interpreter, Prefixer lengthPrefixer,
                                             IsoFieldHeaderFormatter headerFormatter);  ISOFormattableBinaryFieldPackager(int maxLength, String description, Prefixer tagPrefixer,
                                             Padder padder, BinaryInterpreter interpreter, Prefixer lengthPrefixer,
                                             IsoFieldHeaderFormatter headerFormatter); void setPadder(Padder padder); void setInterpreter(BinaryInterpreter 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);  }