/** * @param c - a component * @return packed component * @exception ISOException */ public byte[] pack (ISOComponent c) throws ISOException { String s = (String) c.getValue(); int len = s.length(); if (len > getLength() || len>99) // paranoia settings throw new ISOException ( "invalid len "+len +" packing IFA_LLBNUM field " + c.getKey() ); byte[] b = new byte[3 + (len >> 1)]; prefixer.encodeLength(len + 1 >> 1 << 1, b); interpreter.interpret(s, b, 2); return b; }
/** * Convert the component into a byte[]. */ public byte[] pack(ISOComponent c) throws ISOException { try{ String data = (String)c.getValue(); if (data.length() > getLength()) throw new ISOException("Field length " + data.length() + " too long. Max: " + getLength()); int tag = (Integer)c.getKey(); String paddedData = padder.pad(data, getLength()); byte[] rawData = new byte[tagPrefixer.getPackedLength()+prefixer.getPackedLength() + interpreter.getPackedLength(paddedData.length())]; tagPrefixer.encodeLength(tag, rawData); byte[] rawLen = new byte[prefixer.getPackedLength()]; prefixer.encodeLength(paddedData.length(), rawLen); System.arraycopy(rawLen, 0, rawData, tagPrefixer.getPackedLength(), rawLen.length); interpreter.interpret(paddedData, rawData, tagPrefixer.getPackedLength()+rawLen.length); return rawData; } catch(Exception e) { throw new ISOException(makeExceptionMessage(c, "packing"), e); } }
/** * Convert the component into a byte[]. */ public byte[] pack(ISOComponent c) throws ISOException { try { String data = (String)c.getValue(); if (data.length() > getLength()) { throw new ISOException("Field length " + data.length() + " too long. Max: " + getLength()); } String paddedData = padder.pad(data, getLength()); byte[] rawData = new byte[prefixer.getPackedLength() + interpreter.getPackedLength(paddedData.length())]; prefixer.encodeLength(data.length(), rawData); interpreter.interpret(paddedData, rawData, prefixer.getPackedLength()); return rawData; } catch(Exception e) { throw new ISOException(makeExceptionMessage(c, "packing"), e); } }
/** * Packs the component into a byte[]. */ public byte[] pack(ISOComponent c) throws ISOException { try { String data = (String)c.getValue(); if (data.length() > getLength()) { throw new ISOException("Field length " + data.length() + " too long. Max: " + getLength()); } String sign = data.substring(0, 1); String amount = data.substring(1); String paddedData = padder.pad(amount, getLength()-1); int signLength = interpreter.getPackedLength(1); byte[] rawData = new byte[prefixer.getPackedLength() + signLength + interpreter.getPackedLength(paddedData.length())]; prefixer.encodeLength(paddedData.length(), rawData); interpreter.interpret(sign, rawData, prefixer.getPackedLength()); interpreter.interpret(paddedData, rawData, prefixer.getPackedLength() + signLength); return rawData; } catch(Exception e) { throw new ISOException(makeExceptionMessage(c, "packing"), e); } }
/** * Convert the component into a byte[]. * @return byte array representation of component * @throws org.jpos.iso.ISOException */ @Override public byte[] pack(ISOComponent c) throws ISOException { try { String data; if(c.getValue() instanceof byte[]) data = new String(c.getBytes(), ISOUtil.CHARSET); // transparent handling of complex fields else data = (String)c.getValue(); if (data.length() > getLength()) { throw new ISOException("Field length " + data.length() + " too long. Max: " + getLength()); } String paddedData = padder.pad(data, getLength()); byte[] rawData = new byte[prefixer.getPackedLength() + interpreter.getPackedLength(paddedData.length())]; prefixer.encodeLength(paddedData.length(), rawData); interpreter.interpret(paddedData, rawData, prefixer.getPackedLength()); return rawData; } catch(Exception e) { throw new ISOException(makeExceptionMessage(c, "packing"), e); } }
/** * Convert the component into a byte[]. */ @Override public byte[] pack(ISOComponent c) throws ISOException { try{ byte[] data = (byte[])c.getValue(); if (data.length > getLength()) throw new ISOException("Field length " + data.length + " too long. Max: " + getLength()); int tag = (Integer)c.getKey(); byte[] paddedData = data; if (!(padder instanceof NullPadder)) //for save few cycles paddedData = ISOUtil.hex2byte(padder.pad(ISOUtil.hexString(data), getLength())); byte[] rawData = new byte[tagPrefixer.getPackedLength()+prefixer.getPackedLength() + interpreter.getPackedLength(paddedData.length)]; tagPrefixer.encodeLength(tag, rawData); byte[] rawLen = new byte[prefixer.getPackedLength()]; prefixer.encodeLength(paddedData.length, rawLen); System.arraycopy(rawLen, 0, rawData, tagPrefixer.getPackedLength(), rawLen.length); interpreter.interpret(paddedData, rawData, tagPrefixer.getPackedLength()+rawLen.length); return rawData; } catch(Exception e) { throw new ISOException(makeExceptionMessage(c, "packing"), e); } }
/** * Convert the component into a byte[]. */ public byte[] pack(ISOComponent c) throws ISOException { try { byte[] data = c.getBytes(); int packedLength = prefixer.getPackedLength(); if (packedLength == 0 && data.length != getLength()) { throw new ISOException("Binary data length not the same as the packager length (" + data.length + "/" + getLength() + ")"); } byte[] ret = new byte[interpreter.getPackedLength(data.length) + packedLength]; prefixer.encodeLength(data.length, ret); interpreter.interpret(data, ret, packedLength); return ret; } catch(Exception e) { throw new ISOException(makeExceptionMessage(c, "packing"), e); } }