Advertisement
RobertEnglish

checksumFinderCode

Sep 9th, 2013
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.33 KB | None | 0 0
  1. package robertskostalproject;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.File;
  5. import java.io.FileNotFoundException;
  6. import java.io.FileReader;
  7. import java.io.IOException;
  8. import javax.swing.JOptionPane;
  9.  
  10. /**
  11. * @author RobertEnglish
  12. */
  13. class checksumFinder {
  14.  
  15.  
  16. public static long l1 = 1;
  17. public static long l2 = 0;
  18.  
  19. String HexFinder(File folderFile, String line, String Hex1, String Hex2)
  20. throws FileNotFoundException, IOException {
  21.  
  22.  
  23.  
  24. BufferedReader reader = new BufferedReader(new FileReader(folderFile));
  25. try {
  26. line = reader.readLine();//Reads all lines up to "[Device|Sensors|Checksum]"
  27.  
  28. do {//read line then check if line is "[Device|Sensors|Checksum]" WHILE line isn't ";end of section [Device|Sensors|Checksum]"
  29.  
  30. line = reader.readLine();
  31.  
  32. if (line.equals("[Device|Sensors|Checksum]")) { //IF line is "[Device|Sensors|Checksum]" then
  33. //(check if line is "Value") ELSE read next line
  34. do {// DO read line and (check if line is "Value") WHILE line doesn't contain "Value"
  35.  
  36. if (line.contains("Value")) { // IF line is "Value" then retrieve necessary value
  37. // ELSE read next line
  38.  
  39. Hex1 = line.split("=")[1].trim();
  40. l1 = Long.parseLong(Hex1.substring(2), 16);
  41.  
  42. System.out.println("Here's the line read " + line);
  43. System.out.println("Here's the hex number from the line " + Hex1);
  44. System.out.println("Here's the integer from the hex number " + l1 + "\n");
  45.  
  46. break;
  47. }
  48. } while (!"Value".contains(line = reader.readLine()));//while2
  49.  
  50. line = reader.readLine(); //Reads the line AFTER the first "Value" has been found
  51.  
  52. do {// Read line and check if line has "Value" WHILE line doesn't contain "Value"
  53.  
  54. if (line.contains("Value")) { // IF line is "Value" then retrieve necessary value
  55. // ELSE read next line
  56.  
  57. Hex2 = line.split("=")[1].trim();
  58. l2 = Long.parseLong(Hex2.substring(2), 16);
  59.  
  60. System.out.println("Here's the line read " + line);
  61. System.out.println("Here's the hex number from the line " + Hex2);
  62. System.out.println("Here's the integer from the hex number " + l2 + "\n");
  63.  
  64. break;
  65. }
  66. } while (!"Value".contains(line = reader.readLine()));
  67.  
  68. while (!";end of section [Device|Sensors|Checksum]".equals(line)){
  69. line = reader.readLine();
  70. }
  71. }
  72. } while (!";end of section [Device|Sensors|Checksum]".equals(line));
  73.  
  74.  
  75. if (l1 == l2) {
  76. JOptionPane.showMessageDialog(null, "Both checksum values ARE equal!");
  77. } else {
  78. JOptionPane.showMessageDialog(null, "Both checksum values NOT equal");
  79. }
  80.  
  81. } catch (IOException e) {
  82. System.out.println("IO Exception: Could not read file!\n");
  83. }
  84. return null;
  85. }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement