/** * @param c - the Component to unpack * @param b - binary image * @param offset - starting offset within the binary image * @return consumed bytes * @exception ISOException */ public int unpack (ISOComponent c, byte[] b, int offset) throws ISOException { int len = prefixer.decodeLength(b, offset); c.setValue (interpreter.uninterpret(b, offset + 2, len)); return 2 + (++len >> 1); } public void unpack (ISOComponent c, InputStream in)
public void testUninterpret() throws Exception { byte[] b = new byte[] {49, 50, 51}; assertEquals("123", inter.uninterpret(b, 0, 3)); }
public void testUninterpret() throws Exception { byte[] b = new byte[] {49, 50, 51}; assertEquals("123", inter.uninterpret(b, 0, 3)); }
public void testUninterpret() throws Exception { byte[] b = new byte[] {(byte)0xF1, (byte)0xF2, (byte)0xF3}; assertEquals("123", inter.uninterpret(b, 0, 3)); }
} else if ((i - offset) <= maxSize) { System.arraycopy(inStream, offset, dest, 0, i - offset); value = interpreter.uninterpret(dest, 0, i - offset);
public void unpack (ISOComponent c, InputStream in) throws IOException, ISOException { int len = prefixer.decodeLength(readBytes (in, 2), 2); c.setValue (interpreter.uninterpret(readBytes (in, len+2 >> 1), 0, len)); } public int getMaxPackedLength() {
@Override public int unpack(byte[] inStream, int offset, Map<String, String> fields) throws ISOException { int packedSize = interpretter.getPackedLength(size); if (inStream.length - offset < packedSize) { throw new ISOException(String.format("Field [%s] at offset [%d]:Expecting %d bytes found %d", getName(),offset,packedSize, inStream.length - offset)); } String interprettedvalue = interpretter.uninterpret(inStream, offset, size); if (getValue() != null) { if (!getValue().equals(interprettedvalue)) { throw new ISOException(String.format("Field [%s] at offset [%d]:Expected %s but found %s", getName(),offset,getValue(), interprettedvalue)); } } fields.put(getName(),interprettedvalue); value = interprettedvalue; return offset + packedSize; }
public void testReversability() throws Exception { String origin = "Abc123:.-"; byte[] b = new byte[origin.length()]; inter.interpret(origin, b, 0); assertEquals(origin, inter.uninterpret(b, 0, b.length)); } }
public void testReversability() throws Exception { String origin = "Abc123:.-"; byte[] b = new byte[origin.length()]; inter.interpret(origin, b, 0); assertEquals(origin, inter.uninterpret(b, 0, b.length)); } }
public void testReversability() throws Exception { String origin = "Abc123:.-"; byte[] b = new byte[origin.length()]; inter.interpret(origin, b, 0); assertEquals(origin, inter.uninterpret(b, 0, b.length)); } }
String unpacked = interpreter.uninterpret(readBytes (in, packedLen), 0, len); c.setValue(unpacked); in.skip(interpreter.getPackedLength(getLength()) - packedLen);
/** * Unpacks the byte array into the component. * @param c The component to unpack into. * @param b The byte array to unpack. * @param offset The index in the byte array to start unpacking from. * @return The number of bytes consumed unpacking the component. */ public int unpack(ISOComponent c, byte[] b, int offset) throws ISOException { try { int len = prefixer.decodeLength(b, offset); if (len == -1) { // The prefixer doesn't know how long the field is, so use // maxLength instead len = getLength(); } else if (getLength() > 0 && len > getLength()) throw new ISOException("Field length " + len + " too long. Max: " + getLength()); int lenLen = prefixer.getPackedLength(); String unpacked = interpreter.uninterpret(b, offset + lenLen, len); c.setValue(unpacked); return lenLen + interpreter.getPackedLength(len); } catch(Exception e) { throw new ISOException(makeExceptionMessage(c, "unpacking"), e); } }
/** * Unpacks the byte array into the component. * @param c The component to unpack into. * @param b The byte array to unpack. * @param offset The index in the byte array to start unpacking from. * @return The number of bytes consumed unpacking the component. */ public int unpack(ISOComponent c, byte[] b, int offset) throws ISOException { try { int len = prefixer.decodeLength(b, offset); if (len == -1) { // The prefixer doesn't know how long the field is, so use // maxLength instead len = getLength(); } else if (getLength() > 0 && len > getLength()) throw new ISOException("Field length " + len + " too long. Max: " + getLength()); int lenLen = prefixer.getPackedLength(); String unpacked = interpreter.uninterpret(b, offset + lenLen, len); c.setValue(unpacked); return lenLen + interpreter.getPackedLength(len); } catch(Exception e) { throw new ISOException(makeExceptionMessage(c, "unpacking"), e); } }
/** * Unpacks the byte array into the component. * @param c The component to unpack into. * @param b The byte array to unpack. * @param offset The index in the byte array to start unpacking from. * @return The number of bytes consumed unpacking the component. */ public int unpack(ISOComponent c, byte[] b, int offset) throws ISOException { try { int len = prefixer.decodeLength(b, offset); if (len == -1) { // The prefixer doesn't know how long the field is, so use // maxLength instead len = getLength(); } else if (getLength() > 0 && len > getLength()) throw new ISOException("Field length " + len + " too long. Max: " + getLength()); int lenLen = prefixer.getPackedLength(); String unpacked = interpreter.uninterpret(b, offset + lenLen, len); c.setValue(unpacked); return lenLen + interpreter.getPackedLength(getLength()); } catch(Exception e) { throw new ISOException(makeExceptionMessage(c, "unpacking"), e); } }
/** * Unpack the input stream into the component. * @param c The Component to unpack into. * @param in Input stream where the packed bytes come from. * @exception IOException Thrown if there's a problem reading the input stream. */ public void unpack (ISOComponent c, InputStream in) throws IOException, ISOException { try { int lenLen = prefixer.getPackedLength (); int len; if (lenLen == 0) { len = getLength(); } else { len = prefixer.decodeLength (readBytes (in, lenLen), 0); if (getLength() > 0 && len > 0 && len > getLength()) throw new ISOException("Field length " + len + " too long. Max: " + getLength()); } int packedLen = interpreter.getPackedLength(len); String unpacked = interpreter.uninterpret(readBytes (in, packedLen), 0, len); c.setValue(unpacked); } catch(ISOException e) { throw new ISOException(makeExceptionMessage(c, "unpacking"), e); } }
/** * Unpack the input stream into the component. * @param c The Component to unpack into. * @param in Input stream where the packed bytes come from. * @exception IOException Thrown if there's a problem reading the input stream. */ public void unpack (ISOComponent c, InputStream in) throws IOException, ISOException { try { int lenLen = prefixer.getPackedLength (); int len; if (lenLen == 0) { len = getLength(); } else { len = prefixer.decodeLength (readBytes (in, lenLen), 0); if (getLength() > 0 && len > 0 && len > getLength()) throw new ISOException("Field length " + len + " too long. Max: " + getLength()); } int packedLen = interpreter.getPackedLength(len); String unpacked = interpreter.uninterpret(readBytes (in, packedLen), 0, len); c.setValue(unpacked); } catch(ISOException e) { throw new ISOException(makeExceptionMessage(c, "unpacking"), e); } }
/** * Unpacks the byte array into the component. * @param c The component to unpack into. * @param b The byte array to unpack. * @param offset The index in the byte array to start unpacking from. * @return The number of bytes consumed unpacking the component. */ public int unpack(ISOComponent c, byte[] b, int offset) throws ISOException { try{ int tagLen = tagPrefixer.getPackedLength(); c.setFieldNumber(tagPrefixer.decodeLength(b, offset)); int len = prefixer.decodeLength(b, offset + tagLen); if (len == -1) { // The prefixer doesn't know how long the field is, so use // maxLength instead len = getLength(); } else if (getLength() > 0 && len > getLength()) throw new ISOException("Field length " + len + " too long. Max: " + getLength()); int lenLen = prefixer.getPackedLength(); String unpacked = interpreter.uninterpret(b, offset + tagLen + lenLen, len); c.setValue(unpacked); return tagLen + lenLen + interpreter.getPackedLength(len); } catch(Exception e){ throw new ISOException(makeExceptionMessage(c, "unpacking"), e); } }
/** * Unpack the input stream into the component. * @param c The Component to unpack into. * @param in Input stream where the packed bytes come from. * @exception IOException Thrown if there's a problem reading the input stream. */ @Override public void unpack (ISOComponent c, InputStream in) throws IOException, ISOException { try{ int tagLen = tagPrefixer.getPackedLength(); c.setFieldNumber(tagPrefixer.decodeLength(readBytes (in, tagLen), 0)); int lenLen = prefixer.getPackedLength (); int len; if (lenLen == 0) len = getLength(); else { len = prefixer.decodeLength (readBytes (in, lenLen), 0); if (getLength() > 0 && len > 0 && len > getLength()) throw new ISOException("Field length " + len + " too long. Max: " + getLength()); } int packedLen = interpreter.getPackedLength(len); String unpacked = interpreter.uninterpret(readBytes (in, packedLen), 0, len); c.setValue(unpacked); } catch(ISOException e){ throw new ISOException(makeExceptionMessage(c, "unpacking"), e); } }