@Override public void addChecksum(String hash, String file, String checksum) { List<Checksum> existingChecksums = checksums.get(file); if (existingChecksums != null) { existingChecksums.add(new ChecksumImpl(hash, checksum)); } else { List<Checksum> newChecksums = new ArrayList<Checksum>(); newChecksums.add(new ChecksumImpl(hash, checksum)); checksums.put(file, newChecksums); } }
@Override public Checksum deserialize(String s) throws IllegalArgumentException { String algorithmString = null; String valueString = null; boolean delimiterFound = false; for (int i = 0, n = s.length(); i < n; i++) { char c = s.charAt(i); if (c == delimiter) { algorithmString = s.substring(0, i); valueString = s.substring(i + 1); delimiterFound = true; break; } } if(!delimiterFound){ throw new IllegalArgumentException("Could not deserialize the string " + s); } return new ChecksumImpl(algorithmString, valueString); }
/** * Given the map of manifest file asserted file paths and checksums, along with the checksum algorithm, * this method returns a List of Pair objects, whose keys are the file path with file system's specific File Separators, * and values are ChecksumImpl objects. * * @param fileChecksumMap * @param alg * @return */ protected List<Pair<String, Checksum>> parseData(Map<String, String> fileChecksumMap, String alg) { List<Pair<String, Checksum>> checksumPairList = new ArrayList<Pair<String, Checksum>>(); for (String key : fileChecksumMap.keySet()) { String checksumValue = fileChecksumMap.get(key); key = key.replace("/", File.separator); checksumPairList.add(new Pair<String, Checksum>(key, new ChecksumImpl(alg, checksumValue))); } return checksumPairList; }
/** * Given the map of manifest file asserted file paths and checksums, along with the checksum algorithm, * this method returns a List of Pair objects, whose keys are the file path with file system's specific File Separators, * and values are ChecksumImpl objects. * * @param fileChecksumMap * @param alg * @return */ protected List<Pair<String, Checksum>> parseData(Map<String, String> fileChecksumMap, String alg) { List<Pair<String, Checksum>> checksumPairList = new ArrayList<Pair<String, Checksum>>(); for (String key : fileChecksumMap.keySet()) { String checksumValue = fileChecksumMap.get(key); key = key.replace("/", File.separator); checksumPairList.add(new Pair<String, Checksum>(key, new ChecksumImpl(alg, checksumValue))); } return checksumPairList; }
checksum = new ChecksumImpl(algorithm, fixity);
@Override public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { String algorithm = reader.getAttribute(A_ALGORITHM); String value = reader.getAttribute(A_VALUE); Checksum checksum = new ChecksumImpl(algorithm, value); return checksum; }
fisTwo.close(); Checksum fileChecksum = new ChecksumImpl(Checksum.MD5, md5Checksum); Pair<String, Checksum> pair = new Pair<String, Checksum>(file.getPath(), fileChecksum); attributes.add(new AttributeImpl("Calculated-Checksum", AttributeValueType.PAIR, fileChecksumPairSerializer.serialize(pair))); Checksum shaChecksum = new ChecksumImpl(Checksum.SHA1, sha1Checksum); Pair<String, Checksum> shaEntry = new Pair<String, Checksum>(file.getPath(), shaChecksum); attributes.add(new AttributeImpl("Calculated-Checksum", AttributeValueType.PAIR, fileChecksumPairSerializer.serialize(shaEntry)));