/** * Write data to the stream as content of DataPhase (StartData -> [Data] -> EndData) * * @param transactionID * @param data * @throws IOException */ public void writeData(UINT32 transactionID, byte[] data) throws IOException { // Send StartData StartDataPacket startDataPacket = new StartDataPacket(transactionID, new UINT64(data.length)); write(startDataPacket); long packetLength = UINT32.SIZE_IN_BYTES + PtpIpPacket.Type.SIZE_IN_BYTES + UINT32.SIZE_IN_BYTES + data.length; // Send EndData os.write(new UINT32(packetLength)); os.write(PtpIpPacket.Type.END_DATA.value()); os.write(transactionID); os.write(data); os.flush(); }
public final byte[] bytes() { UINT32 length = new UINT32(UINT32.SIZE_IN_BYTES + Type.SIZE_IN_BYTES + getPayload().length); final Closer closer = new Closer(); try { final ByteArrayOutputStream baos = closer.push(new ByteArrayOutputStream()); final PtpOutputStream pos = closer.push(new PtpOutputStream(baos)); pos.write(length); pos.write(getType().value); pos.write(getPayload()); return baos.toByteArray(); } catch (IOException e) { throw new AssertionError(e); } finally { closer.close(); } }
@Override public void close() throws IOException { os.close(); }
/** * Write PTP-IP Packet to the stream. * * @param packet * @throws IOException */ public void write(PtpIpPacket packet) throws IOException { os.write(packet.bytes()); os.flush(); }