Beispiel #1
0
 public HashedFile loadHashedFile() throws XMLStreamException {
   String endTag = "file";
   Path path = Paths.get("");
   String md5 = "";
   int type;
   String currentElement;
   boolean done = false;
   while (!done && reader.hasNext()) {
     type = reader.next();
     if (type == XMLStreamReader.END_ELEMENT) {
       done = reader.getLocalName().compareTo(endTag) == 0;
     } else if (type == XMLStreamReader.START_ELEMENT) {
       currentElement = reader.getLocalName();
       do {
         type = reader.next();
       } while (type != XMLStreamReader.CHARACTERS && type != XMLStreamReader.END_ELEMENT);
       if (type == XMLStreamReader.CHARACTERS) {
         switch (currentElement) {
           case "md5":
             md5 = reader.getText();
             break;
           case "filePath":
             path = Paths.get(reader.getText());
             break;
         }
         // Look for the end of the current element and throw an exception if it cannot be found
         do {
           type = reader.next();
         } while (type != XMLStreamReader.END_ELEMENT);
         verifyClosing(currentElement);
       } else {
         verifyClosing(currentElement);
       }
     }
   }
   HashedFile result = new HashedFile(path);
   result.setMd5(md5);
   return result;
 }
Beispiel #2
0
 /** Retrieve the digests */
 public void loadHashes() throws XMLStreamException {
   int workDone = 0;
   String endTag = "hashes";
   digests = new TreeMap<>();
   String currentElement;
   int type;
   boolean done = false;
   while (!done && reader.hasNext()) {
     type = reader.next();
     if (type == XMLStreamReader.END_ELEMENT) {
       done = reader.getLocalName().compareTo(endTag) == 0;
     } else if (type == XMLStreamReader.START_ELEMENT) {
       currentElement = reader.getLocalName();
       if (currentElement.compareTo("file") == 0) {
         HashedFile digest = loadHashedFile();
         digests.put(digest.getPath(), digest);
       }
       workDone++;
       updateProgress(workDone, workMax);
     }
   }
 }