/** Convert the component into a byte[]. */ public byte[] pack(IField<?> c) throws MessageException { try { byte[] data = (byte[]) c.getValue(); int packedLength = prefixer.getPackedLength(); if (packedLength == 0) { if (data.length != getLength()) { throw new MessageException( "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 MessageException(makeExceptionMessage(c, "packing"), e); } }
@Test public void interpret() { byte[] result = new byte[binaryData.length]; interpreter.interpret(binaryData, result, 0); assertThat(result, is(EBCDICDATA)); }