@Test public void testGetFormattedTagAndLength() throws Exception { byte[] data = BytesUtils.fromString("9f6b01"); Assertions.assertThat(TlvUtil.getFormattedTagAndLength(data, 1)).isEqualTo(" 9F 6B 01 -- Track 2 Data"); }
public static String getFormattedTagAndLength(final byte[] data, final int indentLength) { StringBuilder buf = new StringBuilder(); String indent = getSpaces(indentLength); TLVInputStream stream = new TLVInputStream(new ByteArrayInputStream(data)); boolean firstLine = true; try { while (stream.available() > 0) { if (firstLine) { firstLine = false; } else { buf.append("\n"); } buf.append(indent); ITag tag = searchTagById(stream.readTag()); int length = stream.readLength(); buf.append(prettyPrintHex(tag.getTagBytes())); buf.append(" "); buf.append(String.format("%02x", length)); buf.append(" -- "); buf.append(tag.getName()); } } catch (IOException e) { LOGGER.error(e.getMessage(), e); } finally { IOUtils.closeQuietly(stream); } return buf.toString(); }
TlvUtil { public static String getFormattedTagAndLength(final byte[] data, final int indentLength) { StringBuilder buf = new StringBuilder(); String indent = getSpaces(indentLength); TLVInputStream stream = new TLVInputStream(new ByteArrayInputStream(data)); boolean firstLine = true; try { while (stream.available() > 0) { if (firstLine) { firstLine = false; } else { buf.append("\n"); } buf.append(indent); ITag tag = searchTagById(stream.readTag()); int length = stream.readLength(); buf.append(prettyPrintHex(tag.getTagBytes())); buf.append(" "); buf.append(String.format("%02x", length)); buf.append(" -- "); buf.append(tag.getName()); } } catch (IOException e) { LOGGER.error(e.getMessage(), e); } finally { IOUtils.closeQuietly(stream); } return buf.toString(); } }
TlvUtil { public static String getFormattedTagAndLength(final byte[] data, final int indentLength) { StringBuilder buf = new StringBuilder(); String indent = getSpaces(indentLength); TLVInputStream stream = new TLVInputStream(new ByteArrayInputStream(data)); boolean firstLine = true; try { while (stream.available() > 0) { if (firstLine) { firstLine = false; } else { buf.append("\n"); } buf.append(indent); ITag tag = searchTagById(stream.readTag()); int length = stream.readLength(); buf.append(prettyPrintHex(tag.getTagBytes())); buf.append(" "); buf.append(String.format("%02x", length)); buf.append(" -- "); buf.append(tag.getName()); } } catch (IOException e) { LOGGER.error(e.getMessage(), e); } finally { IOUtils.closeQuietly(stream); } return buf.toString(); } private  TlvUtil(); }
TlvUtil { public static String getFormattedTagAndLength(final byte[] data, final int indentLength) { StringBuilder buf = new StringBuilder(); String indent = getSpaces(indentLength); TLVInputStream stream = new TLVInputStream(new ByteArrayInputStream(data)); boolean firstLine = true; try { while (stream.available() > 0) { if (firstLine) { firstLine = false; } else { buf.append("\n"); } buf.append(indent); ITag tag = searchTagById(stream.readTag()); int length = stream.readLength(); buf.append(prettyPrintHex(tag.getTagBytes())); buf.append(" "); buf.append(String.format("%02x", length)); buf.append(" -- "); buf.append(tag.getName()); } } catch (IOException e) { LOGGER.error(e.getMessage(), e); } finally { IOUtils.closeQuietly(stream); } return buf.toString(); } 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); }
TlvUtil { public static String getFormattedTagAndLength(final byte[] data, final int indentLength) { StringBuilder buf = new StringBuilder(); String indent = getSpaces(indentLength); TLVInputStream stream = new TLVInputStream(new ByteArrayInputStream(data)); boolean firstLine = true; try { while (stream.available() > 0) { if (firstLine) { firstLine = false; } else { buf.append("\n"); } buf.append(indent); ITag tag = searchTagById(stream.readTag()); int length = stream.readLength(); buf.append(prettyPrintHex(tag.getTagBytes())); buf.append(" "); buf.append(String.format("%02x", length)); buf.append(" -- "); buf.append(tag.getName()); } } catch (IOException e) { LOGGER.error(e.getMessage(), e); } finally { IOUtils.closeQuietly(stream); } return buf.toString(); } 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);  }