mirror of
https://github.com/github/codeql.git
synced 2026-04-29 10:45:15 +02:00
Migrate Java code to separate QL repo.
This commit is contained in:
32
java/ql/src/Performance/InefficientOutputStreamGood.java
Normal file
32
java/ql/src/Performance/InefficientOutputStreamGood.java
Normal file
@@ -0,0 +1,32 @@
|
||||
public class DigestCheckingFileOutputStream extends OutputStream {
|
||||
private DigestOutputStream digest;
|
||||
private byte[] expectedMD5;
|
||||
|
||||
public DigestCheckingFileOutputStream(File file, byte[] expectedMD5)
|
||||
throws IOException, NoSuchAlgorithmException {
|
||||
this.expectedMD5 = expectedMD5;
|
||||
digest = new DigestOutputStream(new FileOutputStream(file),
|
||||
MessageDigest.getInstance("MD5"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(int b) throws IOException {
|
||||
digest.write(b);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(byte[] b, int off, int len) throws IOException {
|
||||
digest.write(b, off, len);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
super.close();
|
||||
|
||||
digest.close();
|
||||
byte[] md5 = digest.getMessageDigest().digest();
|
||||
if (expectedMD5 != null && !Arrays.equals(expectedMD5, md5)) {
|
||||
throw new InternalError();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user