@Test public void packWithLengthFirstLeftZeroPadder() throws ISOException { ISOBinaryField field = new ISOBinaryField(12, new byte[] {0x30, 0x31}); ISOFormattableBinaryFieldPackager packager = new ISOFormattableBinaryFieldPackager(10, "Should be F0F0F7F1F20000003031", EbcdicPrefixer.LL, LeftPadder.ZERO_PADDER, LiteralBinaryInterpreter.INSTANCE, EbcdicPrefixer.LLL, IsoFieldHeaderFormatter.LENGTH_FIRST); TestUtils.assertEquals(new byte[] {(byte)0xF0, (byte)0xF0, (byte)0xF7, (byte)0xF1, (byte)0xF2, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x30, (byte)0x31}, packager.pack(field)); }
@Override public byte[] pack(ISOComponent c) throws ISOException { try{ byte[] valueBytes = (byte[])c.getValue(); if (valueBytes.length < 0 || valueBytes.length > getLength()) throw new ISOException("Field length " + valueBytes.length + " too long. Max: " + getLength()); int tag = (Integer)c.getKey(); byte[] paddedValueBytes = valueBytes; if (!(padder instanceof NullPadder)) paddedValueBytes = ISOUtil.hex2byte(padder.pad(ISOUtil.hexString(valueBytes), getLength())); byte[] rawData = new byte[tagPrefixer.getPackedLength() + prefixer.getPackedLength() + interpreter.getPackedLength(paddedValueBytes.length)]; byte[] rawTagData = new byte[tagPrefixer.getPackedLength()]; tagPrefixer.encodeLength(tag, rawTagData); byte[] rawLen = new byte[prefixer.getPackedLength()]; prefixer.encodeLength(!headerFormatter.isTagFirst() ? paddedValueBytes.length + tagPrefixer.getPackedLength() : paddedValueBytes.length, rawLen); headerFormatter.format(tagPrefixer, prefixer, rawTagData, rawLen, rawData); interpreter.interpret(paddedValueBytes, rawData, headerFormatter.getTotalLength(tagPrefixer, prefixer)); return rawData; } catch(Exception e) { throw new ISOException(makeExceptionMessage(c, "packing"), e); } }
ISOFormattableBinaryFieldPackager extends ISOFieldPackager { @Override public byte[] pack(ISOComponent c) throws ISOException { try{ byte[] valueBytes = (byte[])c.getValue(); if (valueBytes.length < 0 || valueBytes.length > getLength()) throw new ISOException("Field length " + valueBytes.length + " too long. Max: " + getLength()); int tag = (Integer)c.getKey(); byte[] paddedValueBytes = valueBytes; if (!(padder instanceof NullPadder)) paddedValueBytes = ISOUtil.hex2byte(padder.pad(ISOUtil.hexString(valueBytes), getLength())); byte[] rawData = new byte[tagPrefixer.getPackedLength() + prefixer.getPackedLength() + interpreter.getPackedLength(paddedValueBytes.length)]; byte[] rawTagData = new byte[tagPrefixer.getPackedLength()]; tagPrefixer.encodeLength(tag, rawTagData); byte[] rawLen = new byte[prefixer.getPackedLength()]; prefixer.encodeLength(!headerFormatter.isTagFirst() ? paddedValueBytes.length + tagPrefixer.getPackedLength() : paddedValueBytes.length, rawLen); headerFormatter.format(tagPrefixer, prefixer, rawTagData, rawLen, rawData); interpreter.interpret(paddedValueBytes, rawData, headerFormatter.getTotalLength(tagPrefixer, prefixer)); return rawData; } catch(Exception e) { throw new ISOException(makeExceptionMessage(c, "packing"), e); } } }
ISOFormattableBinaryFieldPackager extends ISOFieldPackager { @Override public byte[] pack(ISOComponent c) throws ISOException { try{ byte[] valueBytes = (byte[])c.getValue(); if (valueBytes.length < 0 || valueBytes.length > getLength()) throw new ISOException("Field length " + valueBytes.length + " too long. Max: " + getLength()); int tag = (Integer)c.getKey(); byte[] paddedValueBytes = valueBytes; if (!(padder instanceof NullPadder)) paddedValueBytes = ISOUtil.hex2byte(padder.pad(ISOUtil.hexString(valueBytes), getLength())); byte[] rawData = new byte[tagPrefixer.getPackedLength() + prefixer.getPackedLength() + interpreter.getPackedLength(paddedValueBytes.length)]; byte[] rawTagData = new byte[tagPrefixer.getPackedLength()]; tagPrefixer.encodeLength(tag, rawTagData); byte[] rawLen = new byte[prefixer.getPackedLength()]; prefixer.encodeLength(!headerFormatter.isTagFirst() ? paddedValueBytes.length + tagPrefixer.getPackedLength() : paddedValueBytes.length, rawLen); headerFormatter.format(tagPrefixer, prefixer, rawTagData, rawLen, rawData); interpreter.interpret(paddedValueBytes, rawData, headerFormatter.getTotalLength(tagPrefixer, prefixer)); return rawData; } catch(Exception e) { throw new ISOException(makeExceptionMessage(c, "packing"), 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 byte[] pack(ISOComponent c) throws ISOException { try{ byte[] valueBytes = (byte[])c.getValue(); if (valueBytes.length < 0 || valueBytes.length > getLength()) throw new ISOException("Field length " + valueBytes.length + " too long. Max: " + getLength()); int tag = (Integer)c.getKey(); byte[] paddedValueBytes = valueBytes; if (!(padder instanceof NullPadder)) paddedValueBytes = ISOUtil.hex2byte(padder.pad(ISOUtil.hexString(valueBytes), getLength())); byte[] rawData = new byte[tagPrefixer.getPackedLength() + prefixer.getPackedLength() + interpreter.getPackedLength(paddedValueBytes.length)]; byte[] rawTagData = new byte[tagPrefixer.getPackedLength()]; tagPrefixer.encodeLength(tag, rawTagData); byte[] rawLen = new byte[prefixer.getPackedLength()]; prefixer.encodeLength(!headerFormatter.isTagFirst() ? paddedValueBytes.length + tagPrefixer.getPackedLength() : paddedValueBytes.length, rawLen); headerFormatter.format(tagPrefixer, prefixer, rawTagData, rawLen, rawData); interpreter.interpret(paddedValueBytes, rawData, headerFormatter.getTotalLength(tagPrefixer, prefixer)); return rawData; } catch(Exception e) { throw new ISOException(makeExceptionMessage(c, "packing"), 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 byte[] pack(ISOComponent c) throws ISOException { try{ byte[] valueBytes = (byte[])c.getValue(); if (valueBytes.length < 0 || valueBytes.length > getLength()) throw new ISOException("Field length " + valueBytes.length + " too long. Max: " + getLength()); int tag = (Integer)c.getKey(); byte[] paddedValueBytes = valueBytes; if (!(padder instanceof NullPadder)) paddedValueBytes = ISOUtil.hex2byte(padder.pad(ISOUtil.hexString(valueBytes), getLength())); byte[] rawData = new byte[tagPrefixer.getPackedLength() + prefixer.getPackedLength() + interpreter.getPackedLength(paddedValueBytes.length)]; byte[] rawTagData = new byte[tagPrefixer.getPackedLength()]; tagPrefixer.encodeLength(tag, rawTagData); byte[] rawLen = new byte[prefixer.getPackedLength()]; prefixer.encodeLength(!headerFormatter.isTagFirst() ? paddedValueBytes.length + tagPrefixer.getPackedLength() : paddedValueBytes.length, rawLen); headerFormatter.format(tagPrefixer, prefixer, rawTagData, rawLen, rawData); interpreter.interpret(paddedValueBytes, rawData, headerFormatter.getTotalLength(tagPrefixer, prefixer)); return rawData; } catch(Exception e) { throw new ISOException(makeExceptionMessage(c, "packing"), 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);  }