/** * clear incorrect file. * * @param clearFlag the clear flag, which supports VAMConstants.FILE_CLEAR_FLAG_ERROR, * VAMConstants.FILE_CLEAR_FLAG_NOT_READY, VAMConstants.FILE_CLEAR_FLAG_NOT_FIND_DATA, * VAMConstants.FILE_CLEAR_FLAG_NOT_FIND_FILE, VAMConstants.FILE_CLEAR_FLAG_NOT_FIND_PARENT, * it can use or operation, * @throws Exception */ public void clearFile(int clearFlag) throws Exception { VAFileDao fileDao = DaoFactory.getVAFileDao(); List<VAFile> fileList = getAllFile(); // clear the file whose data can't be found in the database if ((clearFlag & VAMConstants.FILE_CLEAR_FLAG_NOT_FIND_DATA) != 0) { Map<String, String> pathMap = new HashMap<String, String>(); for (int i = 0; i < fileList.size(); i++) { VAFile va = (VAFile) fileList.get(i); pathMap.put(va.getSavePath(), "ok"); } File fileDir = new File(VAMConfig.getFileDirLocation()); if (fileDir.exists() && fileDir.isDirectory()) { checkFile(fileDir, pathMap); } } // clear the file whose physical file can't be found if ((clearFlag & VAMConstants.FILE_CLEAR_FLAG_NOT_FIND_FILE) != 0) { File fileDir = new File(VAMConfig.getFileDirLocation()); if (fileDir.exists() && fileDir.isDirectory()) { for (int i = 0; i < fileList.size(); i++) { VAFile va = (VAFile) fileList.get(i); File file = new File(va.getSavePath()); if (!file.exists()) { fileDao.remove(va.getGuid()); } } } } // clear the file whose state is error if ((clearFlag & VAMConstants.FILE_CLEAR_FLAG_ERROR) != 0) { List<VAObject> errorFiles = fileDao.getErrorFiles(); for (int i = 0; i < errorFiles.size(); i++) { try { removeFile(null, null, errorFiles.get(i).getGuid()); } catch (Exception e) { e.printStackTrace(); } } } // clear the file whose state is not ready if ((clearFlag & VAMConstants.FILE_CLEAR_FLAG_NOT_READY) != 0) { List<VAObject> notReadyFiles = fileDao.getNotReadyFiles(); for (int i = 0; i < notReadyFiles.size(); i++) { VAFile va = new VAFile(notReadyFiles.get(i)); if (VAMUtil.getTimestamp() - va.getTimestamp() > VAMConstants.HOUR / 2) { removeFile(null, null, va.getGuid()); } } } // clear the file whose parent can't be found if ((clearFlag & VAMConstants.FILE_CLEAR_FLAG_NOT_FIND_PARENT) != 0) { fileList = getAllFile(); Map<String, String> guidMap = new HashMap<String, String>(); for (int i = 0; i < fileList.size(); i++) { VAFile va = (VAFile) fileList.get(i); guidMap.put(va.getGuid(), "ok"); } for (int i = 0; i < fileList.size(); i++) { VAFile va = (VAFile) fileList.get(i); if (!va.getParent().equals(VAMConstants.NULL) && guidMap.get(va.getParent()) == null && va.getRef() == 0) { removeFile(null, null, va.getGuid()); } } } }