FlowTableEntry implements FlowTableInterface { @Override public byte[] toByteArray() { int size = (1 + windows.size() * Window.SIZE) + Stats.SIZE; for (AbstractAction a : actions) { size = size + a.getActionLength() + 1; } ByteBuffer target = ByteBuffer.allocate(size); target.put((byte) (windows.size() * Window.SIZE)); windows.stream().forEach((fw) -> { target.put(fw.toByteArray()); }); actions.stream().map((a) -> { target.put((byte) a.getActionLength()); return a; }).forEach((a) -> { target.put(a.toByteArray()); }); target.put(stats.toByteArray()); return target.array(); } FlowTableEntry();  FlowTableEntry(final byte[] entry); static FlowTableEntry fromString(final String s); @Override String toString(); List<Window> getWindows(); void setWindows(final List<Window> w); boolean addWindow(final Window w); List<AbstractAction> getActions(); void setAction(final List<AbstractAction> a); boolean addAction(final AbstractAction a); Stats getStats(); void setStats(final Stats s); @Override byte[] toByteArray(); @Override int hashCode(); boolean equalWindows(final FlowTableEntry other); @Override boolean equals(final Object obj);  }
@Test public void testToByteArray() { String s = "IF (P.TYP == 10 && " + "P.50 == 1 && " + "R.10 > 1 && " + "R.12 < 5) {" + " ASK;" + " SET P.10 = 40 + 1;" + " FUNCTION 1 9 8 7 6 5 4 3 2 1 ;" + " DROP;" + " FORWARD_B;" + " FORWARD_U 3;" + " MATCH;" + " SET P.11 = P.12 + P.13; " + "} (TTL: 254, U: 0)"; FlowTableEntry instance = FlowTableEntry.fromString(s); byte[] expResult = new byte[]{20, 18, 0, 6, 0, 10, 18, 0, 50, 0, 1, 90, 0, 10, 0, 1, 122, 0, 12, 0, 5, 1, 4, 8, 6, 66, 0, 10, 0, 40, 0, 1, 11, 5, 1, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 3, 3, 2, -1, -1, 3, 1, 0, 3, 1, 7, 8, 6, -124, 0, 11, 0, 12, 0, 13, -2, 0}; byte[] result = instance.toByteArray(); assertArrayEquals(expResult, result); }