@Test public void bytes() { PtpIpPacket packet = new PtpIpPacket() { @Override public Type getType() { return TYPE; } @Override public byte[] getPayload() { return PAYLOAD; } }; byte[] expected = PtpIpPacketTestUtils.bytes(TYPE, PAYLOAD); byte[] actual = packet.bytes(); assertThat(actual, is(expected)); }
public final byte[] bytes() { UINT32 length = new UINT32(UINT32.SIZE_IN_BYTES + Type.SIZE_IN_BYTES + getPayload().length); try (final ByteArrayOutputStream baos = new ByteArrayOutputStream()) { final PtpOutputStream pos = new PtpOutputStream(baos); pos.write(length); pos.write(getType().value); pos.write(getPayload()); return baos.toByteArray(); } catch (IOException e) { throw new AssertionError(e); } }
PtpIpPacket { public final byte[] bytes() { UINT32 length = new UINT32(UINT32.SIZE_IN_BYTES + Type.SIZE_IN_BYTES + getPayload().length); try (final ByteArrayOutputStream baos = new ByteArrayOutputStream()) { final PtpOutputStream pos = new PtpOutputStream(baos); pos.write(length); pos.write(getType().value); pos.write(getPayload()); return baos.toByteArray(); } catch (IOException e) { throw new AssertionError(e); } } }
PtpIpPacket { public final byte[] bytes() { UINT32 length = new UINT32(UINT32.SIZE_IN_BYTES + Type.SIZE_IN_BYTES + getPayload().length); try (final ByteArrayOutputStream baos = new ByteArrayOutputStream()) { final PtpOutputStream pos = new PtpOutputStream(baos); pos.write(length); pos.write(getType().value); pos.write(getPayload()); return baos.toByteArray(); } catch (IOException e) { throw new AssertionError(e); } } PtpIpPacket(); }
PtpIpPacket { public final byte[] bytes() { UINT32 length = new UINT32(UINT32.SIZE_IN_BYTES + Type.SIZE_IN_BYTES + getPayload().length); try (final ByteArrayOutputStream baos = new ByteArrayOutputStream()) { final PtpOutputStream pos = new PtpOutputStream(baos); pos.write(length); pos.write(getType().value); pos.write(getPayload()); return baos.toByteArray(); } catch (IOException e) { throw new AssertionError(e); } } PtpIpPacket(); final byte[] bytes(); }
PtpIpPacket { public final byte[] bytes() { UINT32 length = new UINT32(UINT32.SIZE_IN_BYTES + Type.SIZE_IN_BYTES + getPayload().length); try (final ByteArrayOutputStream baos = new ByteArrayOutputStream()) { final PtpOutputStream pos = new PtpOutputStream(baos); pos.write(length); pos.write(getType().value); pos.write(getPayload()); return baos.toByteArray(); } catch (IOException e) { throw new AssertionError(e); } } PtpIpPacket(); final byte[] bytes();  }