Esempio n. 1
1
  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");
    }
  }
 @Override
 public int unpack(ISOComponent c, byte[] b, int offset) throws ISOException {
   byte[] tagBytes = new byte[getMaxPackedLength()];
   System.arraycopy(b, offset, tagBytes, 0, tagBytes.length);
   c.setValue(ISOUtil.byte2hex(tagBytes));
   return tagBytes.length;
 }
Esempio n. 3
0
 /**
  * @param c - the Component to unpack
  * @param b - binary image
  * @param offset - starting offset within the binary image
  * @return consumed bytes
  * @throws org.jpos.iso.ISOException
  */
 public int unpack(ISOComponent c, byte[] b, int offset) throws ISOException {
   if (!(c instanceof ISOField))
     throw new ISOException(c.getClass().getName() + " is not an ISOField");
   int length = -1;
   for (int i = 0; i < getMaxPackedLength(); i++) {
     byte dataByte = b[offset + i];
     if (dataByte == terminator) {
       length = i;
       break;
     }
   }
   if (length >= 0) {
     byte[] value = new byte[length];
     System.arraycopy(b, offset, value, 0, length);
     c.setValue(value);
     return length + 1;
   } else {
     throw new ISOException("Terminating Backslash does not exist");
   }
 }