Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package robertskostalproject;
- import java.io.BufferedReader;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.FileReader;
- import java.io.IOException;
- import javax.swing.JOptionPane;
- /**
- * @author RobertEnglish
- */
- class checksumFinder {
- public static long l1 = 1;
- public static long l2 = 0;
- String HexFinder(File folderFile, String line, String Hex1, String Hex2)
- throws FileNotFoundException, IOException {
- BufferedReader reader = new BufferedReader(new FileReader(folderFile));
- try {
- line = reader.readLine();//Reads all lines up to "[Device|Sensors|Checksum]"
- do {//read line then check if line is "[Device|Sensors|Checksum]" WHILE line isn't ";end of section [Device|Sensors|Checksum]"
- line = reader.readLine();
- if (line.equals("[Device|Sensors|Checksum]")) { //IF line is "[Device|Sensors|Checksum]" then
- //(check if line is "Value") ELSE read next line
- do {// DO read line and (check if line is "Value") WHILE line doesn't contain "Value"
- if (line.contains("Value")) { // IF line is "Value" then retrieve necessary value
- // ELSE read next line
- Hex1 = line.split("=")[1].trim();
- l1 = Long.parseLong(Hex1.substring(2), 16);
- System.out.println("Here's the line read " + line);
- System.out.println("Here's the hex number from the line " + Hex1);
- System.out.println("Here's the integer from the hex number " + l1 + "\n");
- break;
- }
- } while (!"Value".contains(line = reader.readLine()));//while2
- line = reader.readLine(); //Reads the line AFTER the first "Value" has been found
- do {// Read line and check if line has "Value" WHILE line doesn't contain "Value"
- if (line.contains("Value")) { // IF line is "Value" then retrieve necessary value
- // ELSE read next line
- Hex2 = line.split("=")[1].trim();
- l2 = Long.parseLong(Hex2.substring(2), 16);
- System.out.println("Here's the line read " + line);
- System.out.println("Here's the hex number from the line " + Hex2);
- System.out.println("Here's the integer from the hex number " + l2 + "\n");
- break;
- }
- } while (!"Value".contains(line = reader.readLine()));
- while (!";end of section [Device|Sensors|Checksum]".equals(line)){
- line = reader.readLine();
- }
- }
- } while (!";end of section [Device|Sensors|Checksum]".equals(line));
- if (l1 == l2) {
- JOptionPane.showMessageDialog(null, "Both checksum values ARE equal!");
- } else {
- JOptionPane.showMessageDialog(null, "Both checksum values NOT equal");
- }
- } catch (IOException e) {
- System.out.println("IO Exception: Could not read file!\n");
- }
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement