package de.flapdoodle.embed.process.store;

import de.flapdoodle.embed.process.config.store.IDownloadConfig;
import de.flapdoodle.embed.process.distribution.Distribution;

import java.io.File;
import java.io.IOException;

/**
 * Verifies downloaded files (typically for integrity) before returning their references.
 *
 * @author [[mailto:michael@ahlers.consulting Michael Ahlers]]
 */
public class VerifyingDownloader
        implements IDownloader {

    private final IDownloadVerifier verifier;

    private final IDownloader delegate;

    /**
     * @param verifier Verification strategy.
     * @param delegate Specific download strategy.
     */
    public VerifyingDownloader(final IDownloadVerifier verifier, final IDownloader delegate) {
        this.verifier = verifier;
        this.delegate = delegate;
    }

    @Override
    public String getDownloadUrl(final IDownloadConfig runtime, final Distribution distribution) {
        return delegate.getDownloadUrl(runtime, distribution);
    }

    @Override
    public File download(final IDownloadConfig runtime, final Distribution distribution) throws IOException {
        final File file = delegate.download(runtime, distribution);

        if (!verifier.isValid(file)) {
            throw new InvalidDownloadException(file);
        }

        return file;
    }

}

@@ -1205,50 +1205,284 @@
     
-if (!verifier.isValid(file)) %7B%0A           
+final boolean isValid;%0A%0A        try %7B%0A            isValid = verifier.isValid(file);%0A        %7D catch (final Exception e) %7B%0A            throw new RuntimeException(String.format(%22Can't verify downloaded file %5C%22%25s%5C%22.%22, file.getAbsolutePath()), e);%0A        %7D%0A%0A        if (!isValid)
  thr
@@ -1516,35 +1516,24 @@
 tion(file);%0A
-        %7D%0A%0A
         retu

Update for exception (for #33)