mirror of https://github.com/apache/jclouds.git
Prefer Guava Hashing over MessageDigest
This commit is contained in:
parent
644fbf2052
commit
4c265d3168
|
@ -34,8 +34,6 @@ import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
import java.net.URLDecoder;
|
import java.net.URLDecoder;
|
||||||
import java.security.MessageDigest;
|
|
||||||
import java.security.NoSuchAlgorithmException;
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.zip.GZIPInputStream;
|
import java.util.zip.GZIPInputStream;
|
||||||
|
|
||||||
|
@ -280,23 +278,21 @@ public abstract class BaseHttpCommandExecutorServiceIntegrationTest extends Base
|
||||||
f.deleteOnExit();
|
f.deleteOnExit();
|
||||||
long length = (new Random().nextInt(32) + 1) * 1024 * 1024;
|
long length = (new Random().nextInt(32) + 1) * 1024 * 1024;
|
||||||
|
|
||||||
MessageDigest digester = md5Digest();
|
|
||||||
|
|
||||||
CharSink fileSink = Files.asCharSink(f, Charsets.UTF_8);
|
CharSink fileSink = Files.asCharSink(f, Charsets.UTF_8);
|
||||||
Writer out = null;
|
Writer out = null;
|
||||||
try {
|
try {
|
||||||
out = fileSink.openStream();
|
out = fileSink.openStream();
|
||||||
for (long i = 0; i < length; i++) {
|
for (long i = 0; i < length; i++) {
|
||||||
out.append('a');
|
out.append('a');
|
||||||
digester.update((byte) 'a');
|
|
||||||
}
|
}
|
||||||
out.flush();
|
out.flush();
|
||||||
} finally {
|
} finally {
|
||||||
close(out, true);
|
close(out, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
payload = newByteSourcePayload(asByteSource(f));
|
ByteSource byteSource = asByteSource(f);
|
||||||
byte[] digest = digester.digest();
|
payload = newByteSourcePayload(byteSource);
|
||||||
|
byte[] digest = byteSource.hash(md5()).asBytes();
|
||||||
String strDigest = base64().encode(digest);
|
String strDigest = base64().encode(digest);
|
||||||
|
|
||||||
payload.getContentMetadata().setContentMD5(digest);
|
payload.getContentMetadata().setContentMD5(digest);
|
||||||
|
@ -317,14 +313,6 @@ public abstract class BaseHttpCommandExecutorServiceIntegrationTest extends Base
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private MessageDigest md5Digest() throws AssertionError {
|
|
||||||
try {
|
|
||||||
return MessageDigest.getInstance("MD5");
|
|
||||||
} catch (NoSuchAlgorithmException e) {
|
|
||||||
throw new AssertionError(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPost() throws Exception {
|
public void testPost() throws Exception {
|
||||||
MockWebServer server = mockWebServer(new MockResponse().setBody("fooPOST"));
|
MockWebServer server = mockWebServer(new MockResponse().setBody("fooPOST"));
|
||||||
|
|
Loading…
Reference in New Issue