package co.phoenixlab.dn.dngearsim.bootstrap;

import javafx.concurrent.Task;

import java.lang.reflect.Method;
import java.util.function.Consumer;

public class BootstrapTask extends Task<Method> {

    private final Consumer<Method> onBootstrapOk;
    private final Runnable onBootstrapSelfUpdateRequired;
    private volatile boolean selfUpdateRequred;

    public BootstrapTask(Consumer<Method> onBootstrapOk, Runnable onBootstrapSelfUpdateRequired) {
        this.onBootstrapOk = onBootstrapOk;
        this.onBootstrapSelfUpdateRequired = onBootstrapSelfUpdateRequired;
        this.selfUpdateRequred = false;
    }

    @Override
    protected Method call() throws Exception {
        //  TODO
        return null;
    }

    @Override
    protected void succeeded() {
        if (selfUpdateRequred) {
            onBootstrapSelfUpdateRequired.run();
        } else {
            onBootstrapOk.accept(getValue());
        }
    }
}

@@ -72,16 +72,44 @@
 .Task;%0A%0A
+import java.io.IOException;%0A
 import j
@@ -149,814 +149,2590 @@
 ava.
-util.function.Consumer;%0A%0Apublic class BootstrapTask extends Task%3CMethod%3E %7B%0A%0A    private final Consumer%3CMethod%3E onBootstrapOk;%0A    private final Runnable onBootstrapSelfUpdateRequired;%0A    private volatile boolean selfUpdateRequred;%0A%0A    public BootstrapTask(Consumer%3CMethod%3E onBootstrapOk, Runnable onBootstrapSelfUpdateRequired) %7B%0A        this.onBootstrapOk = onBootstrapOk;%0A        this.onBootstrapSelfUpdateRequired = onBootstrapSelfUpdateRequired;%0A        this.selfUpdateRequred = false;%0A    %7D%0A%0A    @Override%0A    protected Method call() throws Exception %7B%0A        //  TODO%0A        return null;%0A    %7D%0A%0A    @Override%0A    protected void succeeded() %7B%0A        if (selfUpdateRequred) %7B%0A            onBootstrapSelfUpdateRequired.run();%0A        %7D else %7B%0A            onBootstrapOk.accept(getValue());%0A        %7D
+nio.ByteBuffer;%0Aimport java.nio.channels.ByteChannel;%0Aimport java.nio.file.Files;%0Aimport java.nio.file.Path;%0Aimport java.security.MessageDigest;%0Aimport java.security.NoSuchAlgorithmException;%0Aimport java.util.function.Consumer;%0A%0Aimport static java.nio.file.StandardOpenOption.READ;%0A%0Apublic class BootstrapTask extends Task%3CMethod%3E %7B%0A%0A    private static final int DIGEST_BUFFER_SIZE = 8192;%0A%0A    /**%0A     * Listener to call on successful load%0A     */%0A    private final Consumer%3CMethod%3E onBootstrapOk;%0A%0A    /**%0A     * Listener to call when the bootstrapper itself needs to be updated externally%0A     */%0A    private final Runnable onBootstrapSelfUpdateRequired;%0A%0A    /**%0A     * Whether or not the bootstrapper itself needs to be updated externally%0A     */%0A    private volatile boolean selfUpdateRequred;%0A%0A    /**%0A     * The MessageDigest using SHA-256 to use to hash%0A     */%0A    private final MessageDigest sha256Digest;%0A%0A    /**%0A     * Reusable buffer for computing digests%0A     */%0A    private final ByteBuffer digestBuffer;%0A%0A    public BootstrapTask(Consumer%3CMethod%3E onBootstrapOk, Runnable onBootstrapSelfUpdateRequired) %7B%0A        this.onBootstrapOk = onBootstrapOk;%0A        this.onBootstrapSelfUpdateRequired = onBootstrapSelfUpdateRequired;%0A        this.selfUpdateRequred = false;%0A        updateTitle(%22BootstrapTask%22);%0A%0A        try %7B%0A            sha256Digest = MessageDigest.getInstance(%22SHA-256%22);%0A        %7D catch (NoSuchAlgorithmException nsae) %7B%0A            //  This shouldn't happen, since SHA-256 MUST be present on all implementations of Java%0A            throw new AssertionError(%22MessageDigest.getInstance(SHA-256) should never throw NoSuchAlgorithmnExcepton%22);%0A        %7D%0A        digestBuffer = ByteBuffer.allocateDirect(DIGEST_BUFFER_SIZE);%0A    %7D%0A%0A    @Override%0A    protected Method call() throws Exception %7B%0A        //  TODO%0A        return null;%0A    %7D%0A%0A    @Override%0A    protected void succeeded() %7B%0A        if (selfUpdateRequred) %7B%0A            onBootstrapSelfUpdateRequired.run();%0A        %7D else %7B%0A            onBootstrapOk.accept(getValue());%0A        %7D%0A    %7D%0A%0A    @Override%0A    protected void failed() %7B%0A%0A    %7D%0A%0A    @Override%0A    protected void cancelled() %7B%0A%0A    %7D%0A%0A    private byte%5B%5D computeFileHash(Path path) throws IOException %7B%0A        sha256Digest.reset();%0A        digestBuffer.rewind();%0A        try (ByteChannel channel = Files.newByteChannel(path, READ)) %7B%0A            while (channel.read(digestBuffer) %3E -1) %7B%0A                digestBuffer.flip();%0A                sha256Digest.update(digestBuffer);%0A            %7D%0A        %7D%0A        return sha256Digest.digest();
 %0A   

Add more framework to bootstrap task