Use constant from jgit

This commit is contained in:
Rene Pfeuffer
2019-10-09 13:56:44 +02:00
parent 5eab6f5af4
commit 38f0ed3bbd

View File

@@ -4,6 +4,7 @@ import com.google.common.io.ByteStreams;
import org.eclipse.jgit.attributes.FilterCommand; import org.eclipse.jgit.attributes.FilterCommand;
import org.eclipse.jgit.lfs.LfsPointer; import org.eclipse.jgit.lfs.LfsPointer;
import org.eclipse.jgit.lfs.lib.AnyLongObjectId; import org.eclipse.jgit.lfs.lib.AnyLongObjectId;
import org.eclipse.jgit.lfs.lib.Constants;
import org.eclipse.jgit.lfs.lib.LongObjectId; import org.eclipse.jgit.lfs.lib.LongObjectId;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@@ -17,10 +18,6 @@ import java.io.OutputStream;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.security.DigestOutputStream; import java.security.DigestOutputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import static org.eclipse.jgit.lfs.lib.Constants.LONG_HASH_FUNCTION;
/** /**
* Adapted version of JGit's {@link org.eclipse.jgit.lfs.CleanFilter} to write the * Adapted version of JGit's {@link org.eclipse.jgit.lfs.CleanFilter} to write the
@@ -75,21 +72,12 @@ class LfsBlobStoreCleanFilter extends FilterCommand {
} }
} }
// Suppress warning for RuntimeException after check for wrong size, because hash alg for sha256 is built in
@SuppressWarnings("squid:S00112")
private DigestOutputStream createDigestStream() { private DigestOutputStream createDigestStream() {
MessageDigest md ;
try {
md = MessageDigest.getInstance(LONG_HASH_FUNCTION);
} catch (NoSuchAlgorithmException e) {
// Yes there is such a hash function (should be sha256)
throw new RuntimeException(e);
}
return new DigestOutputStream(new OutputStream() { return new DigestOutputStream(new OutputStream() {
@Override @Override
public void write(int b) { public void write(int b) {
// no further target here, we are just interested in the digest // no further target here, we are just interested in the digest
} }
}, md); }, Constants.newMessageDigest());
} }
} }