public void unpack(ISOComponent c, InputStream in)
throws IOException, ISOException {
if (!(c instanceof ISOField))
throw new ISOException
(c.getClass().getName() + " is not an ISOField");
boolean endFound = false;
if (in.markSupported()) {
in.mark(getMaxPackedLength());
}
ByteBuffer buf = ByteBuffer.allocate(getMaxPackedLength());
for (int i = 0; i < getMaxPackedLength() && in.available() > 0; i++) {
byte dataByte = (byte) in.read();
if (dataByte == terminator) {
endFound = true;
break;
} else {
buf.put(dataByte);
}
}
if (endFound) {
byte[] data = byteBufferToBytes(buf);
c.setValue(data);
} else {
if (in.markSupported()) {
in.reset();
}
throw new ISOException("Terminating Backslash does not exist");
}
}