Advertisement
RobertEnglish

checksumFinder2

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