Ejemplo n.º 1
0
  @Override
  public int unpack(ISOComponent m, byte[] b) throws ISOException {
    LogEvent evt = new LogEvent(this, "unpack");
    int consumed = 0;
    ISOComponent c;

    // Unpack the fields
    while (consumed < b.length) {
      // Determine current tag
      int i = consumed == 0 && fld[0] != null ? 0 : tagPrefixer.decodeLength(b, consumed);

      if (!(i < fld.length) || fld[i] == null)
        throw new ISOException("Unsupported sub-field " + i + " unpacking field " + m.getKey());

      c = fld[i].createComponent(i);
      consumed += fld[i].unpack(c, b, consumed);
      if (logger != null) {
        evt.addMessage(
            "<unpack fld=\"" + i + "\" packager=\"" + fld[i].getClass().getName() + "\">");
        evt.addMessage("  <value>" + c.getValue().toString() + "</value>");
        evt.addMessage("</unpack>");
      }
      m.set(c);
    }
    Logger.log(evt);
    return consumed;
  }
Ejemplo n.º 2
0
  /**
   * @param c - a component
   * @return packed component
   * @throws org.jpos.iso.ISOException
   */
  public byte[] pack(ISOComponent c) throws ISOException {
    int len;
    byte[] s = c.getBytes();

    if ((len = s.length) > getLength()) {
      throw new ISOException(
          "Invalid length "
              + len
              + " packing IF_FSTBINARY field "
              + c.getKey()
              + " max length="
              + getLength());
    }
    byte[] b = new byte[s.length + 1];
    System.arraycopy(s, 0, b, 0, s.length);
    b[b.length - 2] = terminator;
    return b;
  }
Ejemplo n.º 3
0
  @Override
  public byte[] pack(ISOComponent c) throws ISOException {
    LogEvent evt = new LogEvent(this, "pack");
    try {
      int len = 0;
      Map tab = c.getChildren();
      List<byte[]> l = new ArrayList();

      for (Map.Entry ent : (Set<Map.Entry>) tab.entrySet()) {
        Integer i = (Integer) ent.getKey();
        if (i < 0) continue;
        if (fld[i] == null)
          throw new ISOException("Unsupported sub-field " + i + " packing field " + c.getKey());
        if (ent.getValue() instanceof ISOComponent)
          try {
            ISOComponent f = (ISOComponent) ent.getValue();
            byte[] b = fld[i].pack(f);
            len += b.length;
            l.add(b);
          } catch (Exception e) {
            evt.addMessage("error packing subfield " + i);
            evt.addMessage(c);
            evt.addMessage(e);
            throw e;
          }
      }
      int k = 0;
      byte[] d = new byte[len];
      for (byte[] b : l) {
        System.arraycopy(b, 0, d, k, b.length);
        k += b.length;
      }
      if (logger != null) // save a few CPU cycle if no logger available
      evt.addMessage(ISOUtil.hexString(d));
      return d;
    } catch (Exception ex) {
      throw new ISOException(ex);
    }
  }