aQute.libg.cryptography.Digester Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bnd Show documentation
Show all versions of bnd Show documentation
A command line utility and Ant plugin to wrap, build, or examine bundles.
package aQute.libg.cryptography;
import java.io.*;
import java.security.*;
import aQute.lib.io.*;
public abstract class Digester extends OutputStream {
protected MessageDigest md;
OutputStream out[];
public Digester(MessageDigest instance, OutputStream... out) {
md = instance;
this.out = out;
}
@Override
public void write(byte[] buffer, int offset, int length) throws IOException {
md.update(buffer, offset, length);
for (OutputStream o : out) {
o.write(buffer, offset, length);
}
}
@Override
public void write(int b) throws IOException {
md.update((byte) b);
for (OutputStream o : out) {
o.write(b);
}
}
public MessageDigest getMessageDigest() throws Exception {
return md;
}
public T from(InputStream in) throws Exception {
IO.copy(in, this);
return digest();
}
public void setOutputs(OutputStream... out) {
this.out = out;
}
public abstract T digest() throws Exception;
public abstract T digest(byte[] bytes) throws Exception;
public abstract String getAlgorithm();
public T from(File f) throws Exception {
IO.copy(f, this);
return digest();
}
public T from(byte[] f) throws Exception {
IO.copy(f, this);
return digest();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy