@Test public void packWithTagFirstZeroLenFixedLenField() throws ISOException { ISOField field = new ISOField(60, "123"); ISOFormattableStringFieldPackager ttllPackager = new ISOFormattableStringFieldPackager(3, "Should be 60123", EbcdicPrefixer.LL, NullPadder.INSTANCE, EbcdicInterpreter.INSTANCE, NullPrefixer.INSTANCE, IsoFieldHeaderFormatter.TAG_FIRST); TestUtils.assertEquals(new byte[] {(byte)0xF6, (byte)0xF0, (byte)0xF1, (byte)0xF2, (byte)0xF3}, ttllPackager.pack(field)); }
@Override public byte[] pack(ISOComponent c) throws ISOException { try{ String value = (String)c.getValue(); int valueLength = value.length(); if (valueLength < 0 || valueLength > getLength()) throw new ISOException("Field length " + valueLength + " too long. Max: " + getLength()); int tag = (Integer)c.getKey(); String paddedValue = padder.pad(value, getLength()); byte[] rawData = new byte[tagPrefixer.getPackedLength() + prefixer.getPackedLength() + interpreter.getPackedLength(paddedValue.length())]; byte[] rawTagData = new byte[tagPrefixer.getPackedLength()]; tagPrefixer.encodeLength(tag, rawTagData); byte[] rawLen = new byte[prefixer.getPackedLength()]; prefixer.encodeLength(!headerFormatter.isTagFirst() ? paddedValue.length() + tagPrefixer.getPackedLength() : paddedValue.length(), rawLen); headerFormatter.format(tagPrefixer, prefixer, rawTagData, rawLen, rawData); interpreter.interpret(paddedValue, rawData, tagPrefixer.getPackedLength() + prefixer.getPackedLength()); return rawData; } catch(Exception e) { throw new ISOException(makeExceptionMessage(c, "packing"), e); } }
ISOFormattableStringFieldPackager extends ISOFieldPackager { @Override public byte[] pack(ISOComponent c) throws ISOException { try{ String value = (String)c.getValue(); int valueLength = value.length(); if (valueLength < 0 || valueLength > getLength()) throw new ISOException("Field length " + valueLength + " too long. Max: " + getLength()); int tag = (Integer)c.getKey(); String paddedValue = padder.pad(value, getLength()); byte[] rawData = new byte[tagPrefixer.getPackedLength() + prefixer.getPackedLength() + interpreter.getPackedLength(paddedValue.length())]; byte[] rawTagData = new byte[tagPrefixer.getPackedLength()]; tagPrefixer.encodeLength(tag, rawTagData); byte[] rawLen = new byte[prefixer.getPackedLength()]; prefixer.encodeLength(!headerFormatter.isTagFirst() ? paddedValue.length() + tagPrefixer.getPackedLength() : paddedValue.length(), rawLen); headerFormatter.format(tagPrefixer, prefixer, rawTagData, rawLen, rawData); interpreter.interpret(paddedValue, rawData, tagPrefixer.getPackedLength() + prefixer.getPackedLength()); return rawData; } catch(Exception e) { throw new ISOException(makeExceptionMessage(c, "packing"), e); } } }
ISOFormattableStringFieldPackager extends ISOFieldPackager { @Override public byte[] pack(ISOComponent c) throws ISOException { try{ String value = (String)c.getValue(); int valueLength = value.length(); if (valueLength < 0 || valueLength > getLength()) throw new ISOException("Field length " + valueLength + " too long. Max: " + getLength()); int tag = (Integer)c.getKey(); String paddedValue = padder.pad(value, getLength()); byte[] rawData = new byte[tagPrefixer.getPackedLength() + prefixer.getPackedLength() + interpreter.getPackedLength(paddedValue.length())]; byte[] rawTagData = new byte[tagPrefixer.getPackedLength()]; tagPrefixer.encodeLength(tag, rawTagData); byte[] rawLen = new byte[prefixer.getPackedLength()]; prefixer.encodeLength(!headerFormatter.isTagFirst() ? paddedValue.length() + tagPrefixer.getPackedLength() : paddedValue.length(), rawLen); headerFormatter.format(tagPrefixer, prefixer, rawTagData, rawLen, rawData); interpreter.interpret(paddedValue, rawData, tagPrefixer.getPackedLength() + prefixer.getPackedLength()); return rawData; } catch(Exception e) { throw new ISOException(makeExceptionMessage(c, "packing"), 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 byte[] pack(ISOComponent c) throws ISOException { try{ String value = (String)c.getValue(); int valueLength = value.length(); if (valueLength < 0 || valueLength > getLength()) throw new ISOException("Field length " + valueLength + " too long. Max: " + getLength()); int tag = (Integer)c.getKey(); String paddedValue = padder.pad(value, getLength()); byte[] rawData = new byte[tagPrefixer.getPackedLength() + prefixer.getPackedLength() + interpreter.getPackedLength(paddedValue.length())]; byte[] rawTagData = new byte[tagPrefixer.getPackedLength()]; tagPrefixer.encodeLength(tag, rawTagData); byte[] rawLen = new byte[prefixer.getPackedLength()]; prefixer.encodeLength(!headerFormatter.isTagFirst() ? paddedValue.length() + tagPrefixer.getPackedLength() : paddedValue.length(), rawLen); headerFormatter.format(tagPrefixer, prefixer, rawTagData, rawLen, rawData); interpreter.interpret(paddedValue, rawData, tagPrefixer.getPackedLength() + prefixer.getPackedLength()); return rawData; } catch(Exception e) { throw new ISOException(makeExceptionMessage(c, "packing"), 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 byte[] pack(ISOComponent c) throws ISOException { try{ String value = (String)c.getValue(); int valueLength = value.length(); if (valueLength < 0 || valueLength > getLength()) throw new ISOException("Field length " + valueLength + " too long. Max: " + getLength()); int tag = (Integer)c.getKey(); String paddedValue = padder.pad(value, getLength()); byte[] rawData = new byte[tagPrefixer.getPackedLength() + prefixer.getPackedLength() + interpreter.getPackedLength(paddedValue.length())]; byte[] rawTagData = new byte[tagPrefixer.getPackedLength()]; tagPrefixer.encodeLength(tag, rawTagData); byte[] rawLen = new byte[prefixer.getPackedLength()]; prefixer.encodeLength(!headerFormatter.isTagFirst() ? paddedValue.length() + tagPrefixer.getPackedLength() : paddedValue.length(), rawLen); headerFormatter.format(tagPrefixer, prefixer, rawTagData, rawLen, rawData); interpreter.interpret(paddedValue, rawData, tagPrefixer.getPackedLength() + prefixer.getPackedLength()); return rawData; } catch(Exception e) { throw new ISOException(makeExceptionMessage(c, "packing"), 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);  }