@Test public void writeData() throws IOException { UINT32 transactionID = new UINT32(2); byte[] given = new byte[]{0x12, 0x34}; byte[] expected = ArrayUtils.join( new StartDataPacket(transactionID, new UINT64(given.length)).bytes(), new EndDataPacket(transactionID, given).bytes() ); pos.writeData(transactionID, given); byte[] actual = baos.toByteArray(); assertThat(actual, is(expected)); }
public void writeData(UINT32 transactionID, byte[] data) throws IOException { StartDataPacket startDataPacket = new StartDataPacket(transactionID, new UINT64(data.length)); write(startDataPacket); long packetLength = (long) UINT32.SIZE_IN_BYTES + PtpIpPacket.Type.SIZE_IN_BYTES + UINT32.SIZE_IN_BYTES + data.length; os.write(new UINT32(packetLength)); os.write(PtpIpPacket.Type.END_DATA.value()); os.write(transactionID); os.write(data); os.flush(); }
PtpIpOutputStream implements Closeable { public void writeData(UINT32 transactionID, byte[] data) throws IOException { StartDataPacket startDataPacket = new StartDataPacket(transactionID, new UINT64(data.length)); write(startDataPacket); long packetLength = (long) UINT32.SIZE_IN_BYTES + PtpIpPacket.Type.SIZE_IN_BYTES + UINT32.SIZE_IN_BYTES + data.length; os.write(new UINT32(packetLength)); os.write(PtpIpPacket.Type.END_DATA.value()); os.write(transactionID); os.write(data); os.flush(); } }
PtpIpOutputStream implements Closeable { public void writeData(UINT32 transactionID, byte[] data) throws IOException { StartDataPacket startDataPacket = new StartDataPacket(transactionID, new UINT64(data.length)); write(startDataPacket); long packetLength = (long) UINT32.SIZE_IN_BYTES + PtpIpPacket.Type.SIZE_IN_BYTES + UINT32.SIZE_IN_BYTES + data.length; os.write(new UINT32(packetLength)); os.write(PtpIpPacket.Type.END_DATA.value()); os.write(transactionID); os.write(data); os.flush(); } PtpIpOutputStream(OutputStream os); }
PtpIpOutputStream implements Closeable { public void writeData(UINT32 transactionID, byte[] data) throws IOException { StartDataPacket startDataPacket = new StartDataPacket(transactionID, new UINT64(data.length)); write(startDataPacket); long packetLength = (long) UINT32.SIZE_IN_BYTES + PtpIpPacket.Type.SIZE_IN_BYTES + UINT32.SIZE_IN_BYTES + data.length; os.write(new UINT32(packetLength)); os.write(PtpIpPacket.Type.END_DATA.value()); os.write(transactionID); os.write(data); os.flush(); } PtpIpOutputStream(OutputStream os); void write(PtpIpPacket packet); void writeData(UINT32 transactionID, byte[] data); @Override void close(); }
PtpIpOutputStream implements Closeable { public void writeData(UINT32 transactionID, byte[] data) throws IOException { StartDataPacket startDataPacket = new StartDataPacket(transactionID, new UINT64(data.length)); write(startDataPacket); long packetLength = (long) UINT32.SIZE_IN_BYTES + PtpIpPacket.Type.SIZE_IN_BYTES + UINT32.SIZE_IN_BYTES + data.length; os.write(new UINT32(packetLength)); os.write(PtpIpPacket.Type.END_DATA.value()); os.write(transactionID); os.write(data); os.flush(); } PtpIpOutputStream(OutputStream os); void write(PtpIpPacket packet); void writeData(UINT32 transactionID, byte[] data); @Override void close();  }