@JsonIgnore public boolean isComplete() { if (status.equals(STATUS.QUEUED) || status.equals(STATUS.RUNNING)) return false; return true; }
public static void main(String[] args) throws Exception { String digestType = args[0]; String digestFile = args[1]; Vector<String> digestListFiles = new Vector<String>(); Vector<byte[]> calcDigests = new Vector<byte[]>(); BufferedReader reader = null; byte[] fileContent; int i; for (i = 2; i < args.length; i++) { digestListFiles.add(args[i]); } // le os arquivos e calcula o digest de seus conteudos. for (i = 0; i < digestListFiles.size(); i++) { File file = new File(digestListFiles.get(i)); fileContent = readFile(file); MessageDigest messageDigest; try { messageDigest = MessageDigest.getInstance(digestType); } catch (Exception e) { System.out.println("Inexistant cryptography algorithm given!"); return; } messageDigest.update(fileContent); calcDigests.add(messageDigest.digest()); } File digestListFile = new File(digestFile); // verifica se o arquivo existe. // caso nao exista, cria um novo. if (!digestListFile.exists()) digestListFile.createNewFile(); // lista dos arquivos ja lidos Vector<String> fileNames = new Vector<String>(); // lista do tipos dos digest dos arquivos Vector<String> fileTypes = new Vector<String>(); // lista dos digest dos conteudos dos arquivos Vector<String> fileDigests = new Vector<String>(); try { reader = new BufferedReader(new FileReader(digestListFile)); String line; String[] splitLine; while ((line = reader.readLine()) != null) { splitLine = line.split(" "); fileNames.add(splitLine[0]); // le o nome do arquivo fileTypes.add(splitLine[1]); // le o tipo do digest fileDigests.add(splitLine[2]); // le o digest em hex } } catch (IOException e) { System.out.println("Problems reading digest file! " + e.getStackTrace().toString()); } STATUS status; int pos; for (i = 0; i < digestListFiles.size(); i++) { // procura pos = find(fileNames, digestListFiles.get(i), fileTypes, digestType); if (pos != -1) { // achou // verifica se o conteudo eh igual if (fileDigests.get(pos).contentEquals(calcHex(calcDigests.get(i)))) { status = STATUS.OK; // conteudo igual } else { status = STATUS.NOTOK; // conteudo diferente } } else { // nao achou! // insere no arquivo writeToEOF( digestListFiles.get(i) + " " + digestType + " " + calcHex(calcDigests.get(i)) + "\n", digestListFile); fileNames.add(digestListFiles.get(i)); fileTypes.add(digestType); fileDigests.add(calcHex(calcDigests.get(i))); status = STATUS.NOTFOUND; } System.out.println( digestListFiles.get(i) + " " + digestType + " " + calcHex(calcDigests.get(i)) + " (" + status.toString() + ")"); } }