TlvUtil { public static List<TLV> getlistTLV(final byte[] pData, final ITag pTag, final boolean pAdd) { List<TLV> list = new ArrayList<TLV>(); TLVInputStream stream = new TLVInputStream(new ByteArrayInputStream(pData)); try { while (stream.available() > 0) { TLV tlv = TlvUtil.getNextTLV(stream); if (tlv == null) { break; } if (pAdd) { list.add(tlv); } else if (tlv.getTag().isConstructed()) { list.addAll(TlvUtil.getlistTLV(tlv.getValueBytes(), pTag, tlv.getTag() == pTag)); } } } catch (IOException e) { LOGGER.error(e.getMessage(), e); } finally { IOUtils.closeQuietly(stream); } return list; } private  TlvUtil(); static String getFormattedTagAndLength(final byte[] data, final int indentLength); static TLV getNextTLV(final TLVInputStream stream); static List<TagAndLength> parseTagAndLength(final byte[] data); static String prettyPrintAPDUResponse(final byte[] data); static List<TLV> getlistTLV(final byte[] pData, final ITag pTag, final boolean pAdd); static List<TLV> getlistTLV(final byte[] pData, final ITag... pTag); static byte[] getValue(final byte[] pData, final ITag... pTag); static String prettyPrintAPDUResponse(final byte[] data, final int indentLength); static String getSpaces(final int length); static String prettyPrintHex(final String in, final int indent); static String prettyPrintHex(final byte[] data); static String prettyPrintHex(final String in, final int indent, final boolean wrapLines); static String getSafePrintChars(final byte[] byteArray); static String getSafePrintChars(final byte[] byteArray, final int startPos, final int length); static int getLength(final List<TagAndLength> pList);  }
@Test public void testListTLV() throws Exception { Assertions.assertThat(TlvUtil.getlistTLV(DATA, EmvTags.APPLICATION_TEMPLATE, false).size()).isEqualTo(12); Assertions.assertThat(TlvUtil.getlistTLV(DATA, EmvTags.RECORD_TEMPLATE, false).size()).isEqualTo(4); Assertions.assertThat(TlvUtil.getlistTLV(DATA, EmvTags.TRANSACTION_CURRENCY_CODE, false).size()).isEqualTo(0); }