@Override public int unpack(final byte[] b) throws ISOException { return delegate.unpack(b); }
protected void unpack (ISOMsg m, byte[] b) throws ISOException { m.unpack (b); } protected byte[] pack (ISOMsg m) throws ISOException {
@Override public void unpack(final InputStream in) throws IOException, ISOException { delegate.unpack(in); }
private ISOMsg getMessage (String filename) throws IOException, ISOException { File f = new File (filename); ISOMsg m = null; if (f.canRead()) { try (FileInputStream fis = new FileInputStream (f)) { byte[] b = new byte[fis.available()]; fis.read (b); m = new ISOMsg (); m.setPackager (packager); m.unpack (b); } } return m; } private boolean processResponse
/** * @param channel current ISOChannel instance * @param m ISOMsg to filter * @param evt LogEvent * @return an ISOMsg (possibly parameter m) * @throws VetoException */ public ISOMsg filter (ISOChannel channel, ISOMsg m, LogEvent evt) throws VetoException { try { m.setPackager (packager); ByteArrayOutputStream os = new ByteArrayOutputStream(); if (reread || transformer == null) transformer = tfactory.newTransformer( new StreamSource(xsltfile) ); transformer.transform ( new StreamSource(new ByteArrayInputStream (m.pack())), new StreamResult(os) ); m.unpack (os.toByteArray()); } catch (Exception e) { throw new VetoException(e); } return m; } }
private ISOMsg getMsg (String message) throws Exception { FileInputStream fis = new FileInputStream (PREFIX + message + ".xml"); ISOMsg m = null; try { byte[] b = new byte[fis.available()]; fis.read (b); m = new ISOMsg (); m.setPackager (xmlPackager); m.unpack (b); } finally { fis.close(); } return m; } private byte[] getImage (String message) throws Exception {
private void unpack (byte[] buf, ISOPackager p) throws Exception { ISOMsg m = new ISOMsg(); m.setPackager (p); m.unpack (buf); }
@Test public void testUnpackThrowsNullPointerException() throws Throwable { ISOMsg iSOMsg = new ISOMsg(); byte[] b = new byte[1]; try { iSOMsg.unpack(b); fail("Expected NullPointerException to be thrown"); } catch (NullPointerException ex) { assertNull("ex.getMessage()", ex.getMessage()); assertNull("iSOMsg.packager", iSOMsg.packager); } }
private ISOMsg updatePackAndUnpack (ISOMsg m, ISOPackager p) throws Exception { Date now = new Date(); m.setPackager (p); m.set(7, ISODate.getDateTime(now)); m.set (12, ISODate.formatDate(now, "HHmmss")); m.set (13, ISODate.formatDate (now, "MMdd")); int stan = Integer.parseInt(m.getString(11)) % 1000000; if (++stan == 0L) stan++; m.set (11, Integer.toString(stan)); m.set (4, Integer.toString (stan)); ISOMsg m1 = new ISOMsg(); m1.setPackager(p); m1.unpack (m.pack()); return m1; } private void doTest (ISOPackager packager, String msg, String img)
private void doTest (ISOPackager packager, String msg, String img) throws Exception { // Logger logger = new Logger(); // logger.addListener (new SimpleLogListener (System.out)); // packager.setLogger (logger, msg + "-m"); ISOMsg m = getMsg (msg); m.setPackager (packager); byte[] p = m.pack(); ByteArrayOutputStream out = new ByteArrayOutputStream (); m.pack (out); assertTrue (Arrays.equals (out.toByteArray(), p)); writeImage (img, p); byte[] b = getImage (img); TestUtils.assertEquals(b, p); ISOMsg m1 = new ISOMsg (); // packager.setLogger (logger, msg + "-m1"); m1.setPackager (packager); m1.unpack (b); TestUtils.assertEquals(b, m1.pack()); ISOMsg m2 = new ISOMsg (); m2.setPackager (packager); // packager.setLogger (logger, msg + "-m2"); m2.unpack (new ByteArrayInputStream (out.toByteArray())); TestUtils.assertEquals(b, m2.pack()); }
serverIn.readFully(header); m.unpack (serverIn);
@Test public void testUnpack() throws ISOException { ISOMsg m1 = new ISOMsg(); m1.setPackager(p); m1.unpack(PACKED); assertEquals("0800", m1.getMTI()); assertEquals("000000", m1.getString(3)); assertEquals("000001", m1.getString(11)); assertEquals("29110001", m1.getString(41)); assertArrayEquals(ISOUtil.hex2byte("55AA1122"), m1.getBytes(55)); assertEquals("Test 127.2", m1.getString("127.2")); assertEquals("Test 127.3", m1.getString("127.3")); assertEquals("Test 127.4", m1.getString("127.4")); assertEquals("Test 127.5.1", m1.getString("127.5.1")); } }