@Test public void testCreateLine() { assertEquals(":040000000201BB320C", createLine(DATA, 0, new byte[]{0x02, 0x01, (byte) 0xbb, 0x32})); }
public static String createLine(RecordType recordType, int address, byte[] data) { if(recordType != DATA && recordType != END_OF_FILE) { throw new RuntimeException("Un-supported record type: " + recordType + "."); } StringBuilder builder = new StringBuilder(9 + data.length * 2); builder.append(':') .append(UsbUtil.toHexString((byte) data.length)) .append(UsbUtil.toHexString((short) address)) .append('0') .append(recordType.id); int checksum = (byte) data.length + (short) address + recordType.id; for (byte b : data) { builder.append(UsbUtil.toHexString(b)); checksum += b; } return builder.append(UsbUtil.toHexString((byte) -(checksum & 0xff))).toString().toUpperCase(); }
IntelHex { public static String createLine(RecordType recordType, int address, byte[] data) { if(recordType != DATA && recordType != END_OF_FILE) { throw new RuntimeException("Un-supported record type: " + recordType + "."); } StringBuilder builder = new StringBuilder(9 + data.length * 2); builder.append(':') .append(UsbUtil.toHexString((byte) data.length)) .append(UsbUtil.toHexString((short) address)) .append('0') .append(recordType.id); int checksum = (byte) data.length + (short) address + recordType.id; for (byte b : data) { builder.append(UsbUtil.toHexString(b)); checksum += b; } return builder.append(UsbUtil.toHexString((byte) -(checksum & 0xff))).toString().toUpperCase(); } }
IntelHex { public static String createLine(RecordType recordType, int address, byte[] data) { if(recordType != DATA && recordType != END_OF_FILE) { throw new RuntimeException("Un-supported record type: " + recordType + "."); } StringBuilder builder = new StringBuilder(9 + data.length * 2); builder.append(':') .append(UsbUtil.toHexString((byte) data.length)) .append(UsbUtil.toHexString((short) address)) .append('0') .append(recordType.id); int checksum = (byte) data.length + (short) address + recordType.id; for (byte b : data) { builder.append(UsbUtil.toHexString(b)); checksum += b; } return builder.append(UsbUtil.toHexString((byte) -(checksum & 0xff))).toString().toUpperCase(); }  }
IntelHex { public static String createLine(RecordType recordType, int address, byte[] data) { if(recordType != DATA && recordType != END_OF_FILE) { throw new RuntimeException("Un-supported record type: " + recordType + "."); } StringBuilder builder = new StringBuilder(9 + data.length * 2); builder.append(':') .append(UsbUtil.toHexString((byte) data.length)) .append(UsbUtil.toHexString((short) address)) .append('0') .append(recordType.id); int checksum = (byte) data.length + (short) address + recordType.id; for (byte b : data) { builder.append(UsbUtil.toHexString(b)); checksum += b; } return builder.append(UsbUtil.toHexString((byte) -(checksum & 0xff))).toString().toUpperCase(); }  static List<IntelHexPacket> openIntelHexFile(final File file); static List<IntelHexPacket> openIntelHexFile(final InputStream is); static String createLine(RecordType recordType, int address, byte[] data); static IntelHexPacket parseLine(int lineNo, String line); }
IntelHex { public static String createLine(RecordType recordType, int address, byte[] data) { if(recordType != DATA && recordType != END_OF_FILE) { throw new RuntimeException("Un-supported record type: " + recordType + "."); } StringBuilder builder = new StringBuilder(9 + data.length * 2); builder.append(':') .append(UsbUtil.toHexString((byte) data.length)) .append(UsbUtil.toHexString((short) address)) .append('0') .append(recordType.id); int checksum = (byte) data.length + (short) address + recordType.id; for (byte b : data) { builder.append(UsbUtil.toHexString(b)); checksum += b; } return builder.append(UsbUtil.toHexString((byte) -(checksum & 0xff))).toString().toUpperCase(); }  static List<IntelHexPacket> openIntelHexFile(final File file); static List<IntelHexPacket> openIntelHexFile(final InputStream is); static String createLine(RecordType recordType, int address, byte[] data); static IntelHexPacket parseLine(int lineNo, String line);  }