CommandApdu { public byte[] toBytes() { int length = 4; if (mData != null && mData.length != 0) { length += 1; length += mData.length; } if (mLeUsed) { length += 1; } byte[] apdu = new byte[length]; int index = 0; apdu[index] = (byte) mCla; index++; apdu[index] = (byte) mIns; index++; apdu[index] = (byte) mP1; index++; apdu[index] = (byte) mP2; index++; if (mData != null && mData.length != 0) { apdu[index] = (byte) mLc; index++; System.arraycopy(mData, 0, apdu, index, mData.length); index += mData.length; } if (mLeUsed) { apdu[index] += (byte) mLe; } return apdu; } CommandApdu(final CommandEnum pEnum, final byte[] data, final int le);  CommandApdu(final CommandEnum pEnum, final int p1, final int p2, final int le);  CommandApdu(final CommandEnum pEnum, final int p1, final int p2);  CommandApdu(final CommandEnum pEnum, final int p1, final int p2, final byte[] data, final int le); byte[] toBytes();  }
@Test public void testToByte() { Assertions.assertThat(BytesUtils.bytesToString(new CommandApdu(CommandEnum.GPO, 0x01, 0x02, 0x01).toBytes())).isEqualTo( "80 A8 01 02 01"); Assertions.assertThat(BytesUtils.bytesToString(new CommandApdu(CommandEnum.GPO, new byte[] {}, 0x01).toBytes())) .isEqualTo("80 A8 00 00 01"); Assertions.assertThat(BytesUtils.bytesToString(new CommandApdu(CommandEnum.GPO, null, 0x01).toBytes())).isEqualTo( "80 A8 00 00 01"); Assertions.assertThat(BytesUtils.bytesToString(new CommandApdu(CommandEnum.GPO, 0x01, 0x02).toBytes())).isEqualTo( "80 A8 01 02"); }