Beispiel #1
0
 private void checkStatus(String fileName, FileStatus fileStatus, Identifier overlayId) {
   File dataFile, hashFile;
   String fileNoExt;
   try {
     fileNoExt = LibraryUtil.removeExtension(fileName);
   } catch (IllegalArgumentException ex) {
     LOG.error("bad file name:{}", fileName);
     throw ex;
   }
   switch (fileStatus) {
     case NONE:
       break;
     case DOWNLOADING:
       // TODO hash check - continue
       // for the moment we delete and start anew
       dataFile = new File(libPath + File.separator + fileName);
       dataFile.delete();
       hashFile = new File(libPath + File.separator + fileNoExt + ".hash");
       hashFile.delete();
       fileMap.remove(fileName);
       break;
     case UPLOADING:
       hashFile = new File(libPath + File.separator + fileNoExt + ".hash");
       if (hashFile.exists()) {
         fileMap.put(fileName, Pair.with(fileStatus, overlayId));
       } else {
         LOG.warn("no hash:{} file for uploading file:{}", hashFile, fileNoExt);
       }
       break;
     default:
       LOG.error(
           "logic error - introduced new FileStatus:"
               + fileStatus.toString()
               + " and did not add it to the checkStatusFile");
       throw new RuntimeException(
           "logic error - introduced new FileStatus:"
               + fileStatus.toString()
               + " and did not add it to the checkStatusFile");
   }
 }
Beispiel #2
0
 private void readStatusFile() {
   FileReader fr = null;
   BufferedReader br = null;
   try {
     fr = new FileReader(libPath + File.separator + STATUS_FILE);
     br = new BufferedReader(fr);
     String line;
     while ((line = br.readLine()) != null) {
       StringTokenizer st = new StringTokenizer(line, ":");
       String fileName = st.nextToken();
       FileStatus fileStatus = FileStatus.valueOf(st.nextToken());
       Identifier overlayId = null;
       if (st.hasMoreElements()) {
         overlayId = new IntIdentifier(Integer.parseInt(st.nextToken()));
       }
       checkStatus(fileName, fileStatus, overlayId);
     }
   } catch (FileNotFoundException ex) {
     LOG.error("could not find status check file - should not get here");
     throw new RuntimeException("could not find status check file - should not get here", ex);
   } catch (IOException ex) {
     LOG.error("IO problem on read status check file");
     throw new RuntimeException("IO problem on read status check file", ex);
   } catch (IllegalArgumentException ex) {
     LOG.error("bad file status");
     throw new RuntimeException("bad file status", ex);
   } catch (NoSuchElementException ex) {
     LOG.error("bad status format");
     throw new RuntimeException("bad status format", ex);
   } finally {
     try {
       if (br != null) {
         br.close();
       } else if (fr != null) {
         fr.close();
       }
     } catch (IOException ex) {
       LOG.error("error closing status file - read");
       throw new RuntimeException("error closing status file - read", ex);
     }
   }
 }