@Override
    public Collection<URI> checkFixity(final Collection<String> algorithms) throws UnsupportedAlgorithmException {

        try (InputStream binaryStream = this.getInputStream()) {

            final Map<String, DigestInputStream> digestInputStreams = new HashMap<>();
            InputStream digestStream = binaryStream;
            for (String digestAlg : algorithms) {

                try {
                    digestStream = new DigestInputStream(digestStream, MessageDigest.getInstance(digestAlg));
                    digestInputStreams.put(digestAlg, (DigestInputStream)digestStream);
                } catch (NoSuchAlgorithmException e) {
                    throw new UnsupportedAlgorithmException("Unsupported digest algorithm: " + digestAlg);
                }
            }

            // calculate the digest by consuming the stream
            while (digestStream.read(devNull) != -1) { }

            return digestInputStreams.entrySet().stream()
                .map(entry -> ContentDigest.asURI(entry.getKey(), entry.getValue().getMessageDigest().digest()))
                .collect(Collectors.toSet());
        } catch (final IOException e) {
            LOGGER.debug("Got error closing input stream: {}", e);
            throw new RepositoryRuntimeException(e);
        }
    }
@ Override public Collection < URI > checkFixity ( final Collection < String > algorithms ) throws UnsupportedAlgorithmException { try ( InputStream binaryStream = this . getInputStream ( ) ) { final Map < String , DigestInputStream > digestInputStreams = new HashMap < > ( ) ; InputStream digestStream = binaryStream ; for ( String digestAlg : algorithms ) { try { digestStream = new DigestInputStream ( digestStream , MessageDigest . getInstance ( digestAlg ) ) ; digestInputStreams . put ( digestAlg , ( DigestInputStream ) digestStream ) ; } catch ( NoSuchAlgorithmException e ) { throw new UnsupportedAlgorithmException ( "Unsupported digest algorithm: " + digestAlg ) ; } } while ( digestStream . read ( devNull ) != - 1 ) { } return digestInputStreams . entrySet ( ) . stream ( ) . map ( entry -> ContentDigest . asURI ( entry . getKey ( ) , entry . getValue ( ) . getMessageDigest ( ) . digest ( ) ) ) . collect ( Collectors . toSet ( ) ) ; } catch ( final IOException e ) { LOGGER . debug ( "Got error closing input stream: {}" , e ) ; throw new RepositoryRuntimeException ( e ) ; } }
Calculate fixity with list of digest algorithms of a CacheEntry by piping it through
a simple fixity-calculating InputStream

@param algorithms the digest algorithms to be used
@return the checksums for the digest algorithms
@throws UnsupportedAlgorithmException exception