@Test public void testParseEOFLine() throws Exception { IntelHexPacket hexPacket = IntelHex.parseLine(2, ":00000001FF"); assertNotNull(hexPacket); assertEquals(3, hexPacket.lineNo); assertEquals(END_OF_FILE, hexPacket.recordType); assertEquals(0x0000, hexPacket.address); assertEquals(0, hexPacket.data.length); }
public static IntelHexPacket parseLine(int lineNo, String line) throws IOException { if (line.length() < 9) { throw new IOException("line " + lineNo + ": the line must contain at least 9 characters."); } lineNo++; char startCode = line.charAt(0); int count = parseInt(line.substring(1, 3), 16); int address = parseInt(line.substring(3, 7), 16); int r = parseInt(line.substring(7, 9), 16); if (startCode != ':') { throw new IOException("line " + lineNo + ": The first character must be ':'."); } RecordType recordType = lookup(r); if (recordType == DATA) { int expectedLineLength = 9 + count * 2 + 2; if (line.length() != expectedLineLength) { throw new IOException("line " + lineNo + ": Expected line to be " + expectedLineLength + " characters, was " + line.length() + "."); } byte data[] = new byte[count]; int x = 9; for (int i = 0; i < count; i++) { data[i] = (byte) parseInt(line.substring(x, x + 2), 16); x += 2; } return new IntelHexPacket(lineNo, recordType, address, data); } else if(recordType == END_OF_FILE) { return new IntelHexPacket(lineNo, recordType, address, new byte[0]); } throw new IOException("line " + lineNo + ": Unknown record type: 0x" + Long.toHexString(r) + "."); }
IntelHex { public static IntelHexPacket parseLine(int lineNo, String line) throws IOException { if (line.length() < 9) { throw new IOException("line " + lineNo + ": the line must contain at least 9 characters."); } lineNo++; char startCode = line.charAt(0); int count = parseInt(line.substring(1, 3), 16); int address = parseInt(line.substring(3, 7), 16); int r = parseInt(line.substring(7, 9), 16); if (startCode != ':') { throw new IOException("line " + lineNo + ": The first character must be ':'."); } RecordType recordType = lookup(r); if (recordType == DATA) { int expectedLineLength = 9 + count * 2 + 2; if (line.length() != expectedLineLength) { throw new IOException("line " + lineNo + ": Expected line to be " + expectedLineLength + " characters, was " + line.length() + "."); } byte data[] = new byte[count]; int x = 9; for (int i = 0; i < count; i++) { data[i] = (byte) parseInt(line.substring(x, x + 2), 16); x += 2; } return new IntelHexPacket(lineNo, recordType, address, data); } else if(recordType == END_OF_FILE) { return new IntelHexPacket(lineNo, recordType, address, new byte[0]); } throw new IOException("line " + lineNo + ": Unknown record type: 0x" + Long.toHexString(r) + "."); } }
IntelHex { public static IntelHexPacket parseLine(int lineNo, String line) throws IOException { if (line.length() < 9) { throw new IOException("line " + lineNo + ": the line must contain at least 9 characters."); } lineNo++; char startCode = line.charAt(0); int count = parseInt(line.substring(1, 3), 16); int address = parseInt(line.substring(3, 7), 16); int r = parseInt(line.substring(7, 9), 16); if (startCode != ':') { throw new IOException("line " + lineNo + ": The first character must be ':'."); } RecordType recordType = lookup(r); if (recordType == DATA) { int expectedLineLength = 9 + count * 2 + 2; if (line.length() != expectedLineLength) { throw new IOException("line " + lineNo + ": Expected line to be " + expectedLineLength + " characters, was " + line.length() + "."); } byte data[] = new byte[count]; int x = 9; for (int i = 0; i < count; i++) { data[i] = (byte) parseInt(line.substring(x, x + 2), 16); x += 2; } return new IntelHexPacket(lineNo, recordType, address, data); } else if(recordType == END_OF_FILE) { return new IntelHexPacket(lineNo, recordType, address, new byte[0]); } throw new IOException("line " + lineNo + ": Unknown record type: 0x" + Long.toHexString(r) + "."); }  }
IntelHex { public static IntelHexPacket parseLine(int lineNo, String line) throws IOException { if (line.length() < 9) { throw new IOException("line " + lineNo + ": the line must contain at least 9 characters."); } lineNo++; char startCode = line.charAt(0); int count = parseInt(line.substring(1, 3), 16); int address = parseInt(line.substring(3, 7), 16); int r = parseInt(line.substring(7, 9), 16); if (startCode != ':') { throw new IOException("line " + lineNo + ": The first character must be ':'."); } RecordType recordType = lookup(r); if (recordType == DATA) { int expectedLineLength = 9 + count * 2 + 2; if (line.length() != expectedLineLength) { throw new IOException("line " + lineNo + ": Expected line to be " + expectedLineLength + " characters, was " + line.length() + "."); } byte data[] = new byte[count]; int x = 9; for (int i = 0; i < count; i++) { data[i] = (byte) parseInt(line.substring(x, x + 2), 16); x += 2; } return new IntelHexPacket(lineNo, recordType, address, data); } else if(recordType == END_OF_FILE) { return new IntelHexPacket(lineNo, recordType, address, new byte[0]); } throw new IOException("line " + lineNo + ": Unknown record type: 0x" + Long.toHexString(r) + "."); }  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 IntelHexPacket parseLine(int lineNo, String line) throws IOException { if (line.length() < 9) { throw new IOException("line " + lineNo + ": the line must contain at least 9 characters."); } lineNo++; char startCode = line.charAt(0); int count = parseInt(line.substring(1, 3), 16); int address = parseInt(line.substring(3, 7), 16); int r = parseInt(line.substring(7, 9), 16); if (startCode != ':') { throw new IOException("line " + lineNo + ": The first character must be ':'."); } RecordType recordType = lookup(r); if (recordType == DATA) { int expectedLineLength = 9 + count * 2 + 2; if (line.length() != expectedLineLength) { throw new IOException("line " + lineNo + ": Expected line to be " + expectedLineLength + " characters, was " + line.length() + "."); } byte data[] = new byte[count]; int x = 9; for (int i = 0; i < count; i++) { data[i] = (byte) parseInt(line.substring(x, x + 2), 16); x += 2; } return new IntelHexPacket(lineNo, recordType, address, data); } else if(recordType == END_OF_FILE) { return new IntelHexPacket(lineNo, recordType, address, new byte[0]); } throw new IOException("line " + lineNo + ": Unknown record type: 0x" + Long.toHexString(r) + "."); }  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);  }