Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes Issue #320 #324

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -79,24 +79,28 @@ public int unpack(byte[] inStream, int offset, Map<String, String> fields) throw
return i + 1;
}

@Override
public byte[] pack(Map<String, String> fields) throws ISOException {

if (value == null || value.equals("")) {
// if field is not set, make sure to send the delimiter to indicate
// its presence.
return new byte[] { delimiter.byteValue() };
}
if (value.length() <= maxSize) {
byte[] b = new byte[interpreter.getPackedLength(value.length() + 1)];
interpreter.interpret(value, b, 0);
b[b.length - 1] = delimiter.byteValue();

return b;
}
throw new ISOException(String.format("Size [%d] is greater than maxSize[%d] ", value.length(), maxSize));
}

@Override
public byte[] pack(Map<String, String> fields) throws ISOException {

if (value == null || value.equals("")) {
// if field is not set, make sure to send the delimiter to indicate
// its presence.
value = fields.get(getName());
if (value == null || value.equals("")) {
setValue(""); // set this as the hexdump method throws NPE
return new byte[] { delimiter.byteValue() };
}
}

if (value.length() <= maxSize) {
byte[] b = new byte[interpreter.getPackedLength(value.length() + 1)];
interpreter.interpret(value, b, 0);
b[b.length - 1] = delimiter.byteValue();

return b;
}
throw new ISOException(String.format("Size [%d] is greater than maxSize[%d] ", value.length(), maxSize));
}
public VariableFieldPackager(String name, int maxSize, Byte delimiter, Interpreter interpretter) {

this.maxSize = maxSize;
Expand Down