Java Code Examples for javax.swing.ProgressMonitorInputStream

The following examples show how to use javax.swing.ProgressMonitorInputStream. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: zencash-swing-wallet-ui   Source File: ProvingKeyFetcher.java    License: MIT License 6 votes vote down vote up
private static boolean checkSHA256(File provingKey, Component parent) throws IOException {
    MessageDigest sha256;
    try {
        sha256 = MessageDigest.getInstance("SHA-256");
    } catch (NoSuchAlgorithmException impossible) {
        throw new IOException(impossible);
    }
    try (InputStream is = new BufferedInputStream(new FileInputStream(provingKey))) {
        ProgressMonitorInputStream pmis = new ProgressMonitorInputStream(parent,
                LanguageUtil.instance().getString("proving.key.fetcher.option.pane.verify.progress.monitor.text"),
                is);
        pmis.getProgressMonitor().setMaximum(PROVING_KEY_SIZE);
        pmis.getProgressMonitor().setMillisToPopup(10);
        DigestInputStream dis = new DigestInputStream(pmis, sha256);
        byte [] temp = new byte[0x1 << 13];
        while(dis.read(temp) >= 0);
        byte [] digest = sha256.digest();

        return SHA256.equalsIgnoreCase(Util.bytesToHex(digest));
    }
}
 
Example 2
Source Project: zencash-swing-wallet-ui   Source File: ProvingKeyFetcher.java    License: MIT License 6 votes vote down vote up
private static boolean checkSHA256SG(File sproutGroth, Component parent) throws IOException {
    MessageDigest sha256;
    try {
        sha256 = MessageDigest.getInstance("SHA-256");
    } catch (NoSuchAlgorithmException impossible) {
        throw new IOException(impossible);
    }
    try (InputStream is = new BufferedInputStream(new FileInputStream(sproutGroth))) {
        ProgressMonitorInputStream pmis = new ProgressMonitorInputStream(parent,
                LanguageUtil.instance().getString("sprout.groth.fetcher.option.pane.verify.progress.monitor.text"),
                is);
        pmis.getProgressMonitor().setMaximum(SPROUT_GROTH_SIZE);
        pmis.getProgressMonitor().setMillisToPopup(10);
        DigestInputStream dis = new DigestInputStream(pmis, sha256);
        byte [] temp = new byte[0x1 << 13];
        while(dis.read(temp) >= 0);
        byte [] digest = sha256.digest();
        
        return SHA256SG.equalsIgnoreCase(Util.bytesToHex(digest));
    }
}
 
Example 3
Source Project: zencash-swing-wallet-ui   Source File: ProvingKeyFetcher.java    License: MIT License 6 votes vote down vote up
private static boolean checkSHA256SS(File saplingSpend, Component parent) throws IOException {
    MessageDigest sha256;
    try {
        sha256 = MessageDigest.getInstance("SHA-256");
    } catch (NoSuchAlgorithmException impossible) {
        throw new IOException(impossible);
    }
    try (InputStream is = new BufferedInputStream(new FileInputStream(saplingSpend))) {
        ProgressMonitorInputStream pmis = new ProgressMonitorInputStream(parent,
                LanguageUtil.instance().getString("sapling.spend.fetcher.option.pane.verify.progress.monitor.text"),
                is);
        pmis.getProgressMonitor().setMaximum(SAPLING_SPEND_SIZE);
        pmis.getProgressMonitor().setMillisToPopup(10);
        DigestInputStream dis = new DigestInputStream(pmis, sha256);
        byte [] temp = new byte[0x1 << 13];
        while(dis.read(temp) >= 0);
        byte [] digest = sha256.digest();

        return SHA256SS.equalsIgnoreCase(Util.bytesToHex(digest));
    }
}
 
Example 4
@Override
public InputStream getProgressMonitorInputStream(InputStream in, int length, String msg) {
    ProgressMonitorInputStream pmin = new ProgressMonitorInputStream(parent, msg, in);
    ProgressMonitor pm = pmin.getProgressMonitor();

    if (length > 0) {
        pm.setMaximum(length);
    }
    return pmin;
}
 
Example 5
Source Project: swift-explorer   Source File: FileUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static InputStream getInputStreamWithProgressMonitor(InputStream input, Component parentComponent, String message)
{
	if (input == null)
		return null ;
	Frame owner = null;
	if (parentComponent == null) 
		owner = SwingUtils.tryFindSuitableFrameOwner () ;
	InputStream in = new BufferedInputStream(
			new ProgressMonitorInputStream(
					(parentComponent == null) ? (owner) : (parentComponent),
					message, input));
	return in;
}