use of org.jpos.util.LogEvent in project jPOS by jpos.
the class CTCSubElementPackager method unpack.
public int unpack(ISOComponent m, byte[] b) throws ISOException {
LogEvent evt = new LogEvent(this, "unpack");
int consumed = 0;
for (int i = 0; consumed < b.length; i++) {
ISOComponent 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() + "\">");
if (c.getValue() instanceof ISOMsg)
evt.addMessage(c.getValue());
else
evt.addMessage(" <value>" + c.getValue().toString() + "</value>");
evt.addMessage("</unpack>");
}
m.set(c);
}
Logger.log(evt);
return consumed;
}
use of org.jpos.util.LogEvent in project jPOS by jpos.
the class CTCSubFieldPackager method unpack.
public int unpack(ISOComponent m, byte[] b) throws ISOException {
LogEvent evt = new LogEvent(this, "unpack");
int consumed = 0;
for (int i = 0; consumed < b.length; i++) {
ISOComponent 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;
}
use of org.jpos.util.LogEvent in project jPOS by jpos.
the class GenericSubFieldPackager method pack.
/**
* Pack the subfield into a byte array
*/
public byte[] pack(ISOComponent m) throws ISOException {
LogEvent evt = new LogEvent(this, "pack");
try {
ISOComponent c;
List<byte[]> l = new ArrayList<byte[]>();
Map fields = m.getChildren();
int len = 0;
if (emitBitMap()) {
// BITMAP (-1 in HashTable)
c = (ISOComponent) fields.get(-1);
byte[] b = getBitMapfieldPackager().pack(c);
len += b.length;
l.add(b);
}
for (int i = getFirstField(); i <= m.getMaxField(); i++) {
c = (ISOComponent) fields.get(i);
if (c == null && !emitBitMap())
c = new ISOField(i, "");
if (c != null) {
try {
byte[] b = fld[i].pack(c);
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 (// save a few CPU cycle if no logger available
logger != null)
evt.addMessage(ISOUtil.hexString(d));
return d;
} catch (ISOException e) {
evt.addMessage(e);
throw e;
} catch (Exception e) {
evt.addMessage(e);
throw new ISOException(e);
} finally {
Logger.log(evt);
}
}
use of org.jpos.util.LogEvent in project jPOS by jpos.
the class GenericTaggedFieldsPackager method unpack.
@Override
public void unpack(ISOComponent m, InputStream in) throws IOException, ISOException {
LogEvent evt = new LogEvent(this, "unpack");
try {
if (m.getComposite() != m)
throw new ISOException("Can't call packager on non Composite");
// if ISOMsg and headerLength defined
if (m instanceof ISOMsg && ((ISOMsg) m).getHeader() == null && headerLength > 0) {
byte[] h = new byte[headerLength];
in.read(h, 0, headerLength);
((ISOMsg) m).setHeader(h);
}
if (!(fld[0] instanceof ISOMsgFieldPackager) && !(fld[0] instanceof ISOBitMapPackager)) {
ISOComponent mti = fld[0].createComponent(0);
fld[0].unpack(mti, in);
m.set(mti);
}
int maxField = fld.length;
for (int i = getFirstField(); i < maxField; i++) {
if (fld[i] == null)
continue;
ISOComponent c = fld[i].createComponent(i);
fld[i].unpack(c, in);
if (logger != null) {
evt.addMessage("<unpack fld=\"" + i + "\" packager=\"" + fld[i].getClass().getName() + "\">");
if (c.getValue() instanceof ISOMsg)
evt.addMessage(c.getValue());
else
evt.addMessage(" <value>" + c.getValue().toString() + "</value>");
evt.addMessage("</unpack>");
}
m.set(c);
}
} catch (ISOException e) {
evt.addMessage(e);
throw e;
} catch (EOFException e) {
throw e;
} catch (Exception e) {
evt.addMessage(e);
throw new ISOException(e);
} finally {
Logger.log(evt);
}
}
use of org.jpos.util.LogEvent in project jPOS by jpos.
the class GenericTaggedFieldsPackager method pack.
/**
* Pack the subfield into a byte array
*
* @return packed array of bytes
* @throws org.jpos.iso.ISOException
*/
@Override
public byte[] pack(ISOComponent m) throws ISOException {
LogEvent evt = new LogEvent(this, "pack");
try {
ISOComponent c;
List<byte[]> l = new ArrayList<byte[]>();
Map fields = m.getChildren();
int len = 0;
for (int i = getFirstField(); i <= m.getMaxField(); i++) {
c = (ISOComponent) fields.get(i);
if (c != null) {
try {
byte[] b = fld[i].pack(c);
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 (// save a few CPU cycle if no logger available
logger != null)
evt.addMessage(ISOUtil.hexString(d));
return d;
} catch (ISOException e) {
evt.addMessage(e);
throw e;
} catch (Exception e) {
evt.addMessage(e);
throw new ISOException(e);
} finally {
Logger.log(evt);
}
}
Aggregations