private Set<DcsFixity> createFixitySet(int size) { Set<DcsFixity> set = new HashSet<DcsFixity>(); for (int i = 0; i < size; i++) { DcsFixity fix = new DcsFixity(); fix.setAlgorithm(randomString(10, false)); fix.setValue(randomString(10, false)); set.add(fix); } return set; }
/** * Copy constructor for a DcsFixity. The state of <code>toCopy</code> is copied * to this. * * @param toCopy the dcs fixity to copy */ public DcsFixity(DcsFixity toCopy) { this.algorithm = toCopy.getAlgorithm(); this.value = toCopy.getValue(); }
@Override public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { final DcsFixity fixity = new DcsFixity(); final String algo = reader.getAttribute(A_ALGO); final String value = reader.getValue(); // inside the <fixity> element if (!isEmptyOrNull(algo)) { fixity.setAlgorithm(algo); } if (!isEmptyOrNull(value)) { fixity.setValue(value); } return fixity; }
private static void addFixitySet(SolrInputDocument doc, Collection<DcsFixity> set) { if (set == null || set.size() == 0) { return; } for (DcsFixity fix : set) { setadd(doc, FixityField.ALGORITHM, fix.getAlgorithm()); setadd(doc, FixityField.VALUE, fix.getValue()); } }
@Override public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { final DcsFixity fixity = new DcsFixity(); final String algo = reader.getAttribute(A_ALGO); final String value = reader.getValue(); // inside the <fixity> element if (!isEmptyOrNull(algo)) { fixity.setAlgorithm(algo); } if (!isEmptyOrNull(value)) { fixity.setValue(value); } return fixity; }
@Override public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) { super.marshal(source, writer, context); final DcsFixity fixity = (DcsFixity) source; if (!isEmptyOrNull(fixity.getAlgorithm())) { writer.addAttribute(A_ALGO, fixity.getAlgorithm()); } if (!isEmptyOrNull(fixity.getValue())) { writer.setValue(fixity.getValue()); } }
private static Set<DcsFixity> getFixitySet(SolrDocument doc) { Set<DcsFixity> set = new HashSet<DcsFixity>(); String[] algs = setgetAll(doc, FixityField.ALGORITHM); String[] values = setgetAll(doc, FixityField.VALUE); for (int i = 0; i < algs.length; i++) { DcsFixity fix = new DcsFixity(); if (!Util.isEmptyOrNull(algs[i])) { fix.setAlgorithm(algs[i]); } if (!Util.isEmptyOrNull(values[i])) { fix.setValue(values[i]); } set.add(fix); } return set; }
@Override public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) { super.marshal(source, writer, context); final DcsFixity fixity = (DcsFixity) source; if (!isEmptyOrNull(fixity.getAlgorithm())) { writer.addAttribute(A_ALGO, fixity.getAlgorithm()); } if (!isEmptyOrNull(fixity.getValue())) { writer.setValue(fixity.getValue()); } }
/** * Calculates fixity over an InputStream according to the supplied algorithm. * * @param in the InputStream * @param digestAlgo the algorithm used to calculate fixity * @return a DcsFixity object encapsulating the calculated fixity and algorithm * @throws IOException if there is an error calculating the fixity */ private DcsFixity calculateFixity(InputStream in, MessageDigest digestAlgo) throws IOException { final HexEncodingDigestListener digestListener = new HexEncodingDigestListener(); final NullOutputStream devNull = new NullOutputStream(); final DigestNotificationStream digestIn = new DigestNotificationStream(in, digestAlgo, digestListener); IOUtils.copy(digestIn, devNull); final String digest = digestListener.getDigest(); if (digest == null || digest.isEmpty()) { throw new IOException("Error calculating fixity for stream: the digest was empty or null."); } DcsFixity fixity = new DcsFixity(); fixity.setAlgorithm(digestAlgo.getAlgorithm()); fixity.setValue(digest); return fixity; }
DcsFixity fixity = new DcsFixity(); fixity.setAlgorithm(checksumAlgorithm); fixity.setValue(new String(Hex.encodeHex(digest))); file.addFixity(fixity);
DcsFixity fileFixity = new DcsFixity(); fileFixity.setAlgorithm("SHA-1"); fileFixity.setValue("039523059823u58902"); fixities.add(fileFixity); metadataFileOne.setFixities(fixities); DcsFixity fileFixityTwo = new DcsFixity(); fileFixityTwo.setAlgorithm("MD5"); fileFixityTwo.setValue("039523059823u58902"); fixitiesTwo.add(fileFixityTwo); metadataFileTwo.setFixities(fixitiesTwo);
DcsFixity fileFixity = new DcsFixity(); fileFixity.setAlgorithm("SHA-1"); fileFixity.setValue("039523059823u58902"); fixities.add(fileFixity); metadataFileOne.setFixities(fixities); DcsFixity fileFixityTwo = new DcsFixity(); fileFixityTwo.setAlgorithm("MD5"); fileFixityTwo.setValue("039523059823u58902"); fixitiesTwo.add(fileFixityTwo); metadataFileTwo.setFixities(fixitiesTwo);