/** * 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; }
/** * Goes through BagIt attribute set, get check sum Attributes and store in a map, keyed by file's path for easy looking * when attribute sets for files are collected. */ private Map<String, Attribute> getAssertedFileChecksumMap(AttributeSet attributeSet) throws StatefulIngestServiceException { PairStringSerializerImpl<String, Checksum> fileChecksumPairSerializer = PairSerializerUtil.getFileChecksumPairSerializer(); if (!attributeSet.getName().equals(AttributeSetName.BAGIT)) { throw new StatefulIngestServiceException("Expected " + AttributeSetName.BAGIT + " attribute set, but given " + attributeSet.getName() + "."); } Map<String, Attribute> assertedFileChecksumMap = new HashMap<String, Attribute>(); java.util.Collection<Attribute> checksumAttributes = attributeSet.getAttributesByName(Metadata.BAGIT_CHECKSUM); for (Attribute attribute : checksumAttributes) { Pair<String, Checksum> checksumKVPair = fileChecksumPairSerializer.deserialize(attribute.getValue()); //file path value used as key = data/.../.../<file-name> assertedFileChecksumMap.put((String) checksumKVPair.getKey(), attribute); } return assertedFileChecksumMap; }
/** * 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; }
String thisFile = manifestChecksumPair.getKey(); File absBaseDirectory = new File(state.getPackage().getSerialization().getExtractDir(), state.getPackage().getSerialization().getBaseDir().getPath()); File fileFullPath = new File(absBaseDirectory, thisFile); String providedAlgorithm = manifestChecksumPair.getValue().getAlgorithm(); String providedValue = manifestChecksumPair.getValue().getValue(); if (fileAttr.getName().equals(Metadata.CALCULATED_CHECKSUM)) { Pair<String, Checksum> fileChecksumPair = fileChecksumPairSerializer.deserialize(fileAttr.getValue()); String calculatedAlgorithm = fileChecksumPair.getValue().getAlgorithm(); String calculatedValue = fileChecksumPair.getValue().getValue();
public Pair<T,U> deserialize(String serializedString) throws IllegalArgumentException{ String keyString = null; String valueString = null; boolean escaped = false; boolean delimiterFound = false; for(int i = 0, n = serializedString.length() ; i < n ; i++) { char c = serializedString.charAt(i); if (!escaped && c == delimiter) { keyString = unescapeString(serializedString.substring(0, i)); valueString = serializedString.substring(i + 1); delimiterFound = true; break; } if (!escaped && c == escapeChar) { escaped = true; } else { escaped = false; } } if(!delimiterFound){ throw new IllegalArgumentException("Could not deserialize the string " + serializedString); } return new Pair(stringSerializerT.deserialize(keyString),stringSerializerU.deserialize(valueString)); }
Pair<String, Checksum> pair = new Pair<String, Checksum>(file.getPath(), fileChecksum); attributes.add(new AttributeImpl("Calculated-Checksum", AttributeValueType.PAIR, fileChecksumPairSerializer.serialize(pair))); Pair<String, Checksum> shaEntry = new Pair<String, Checksum>(file.getPath(), shaChecksum); attributes.add(new AttributeImpl("Calculated-Checksum", AttributeValueType.PAIR, fileChecksumPairSerializer.serialize(shaEntry))); } catch (Exception e) {