Address modern Guava deprecations

pull/218/head
Andrew Gaul 2017-08-21 14:58:32 -07:00
rodzic 456f7c7a0a
commit 51aa2e7fcd
5 zmienionych plików z 19 dodań i 15 usunięć

Wyświetl plik

@ -283,8 +283,8 @@ public final class Main {
} else if (provider.equals("google-cloud-storage")) { } else if (provider.equals("google-cloud-storage")) {
File credentialFile = new File(credential); File credentialFile = new File(credential);
if (credentialFile.exists()) { if (credentialFile.exists()) {
credential = Files.toString(credentialFile, credential = Files.asCharSource(credentialFile,
StandardCharsets.UTF_8); StandardCharsets.UTF_8).read();
} }
properties.remove(Constants.PROPERTY_CREDENTIAL); properties.remove(Constants.PROPERTY_CREDENTIAL);
} }

Wyświetl plik

@ -66,6 +66,7 @@ import com.google.common.collect.Iterables;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.google.common.escape.Escaper; import com.google.common.escape.Escaper;
import com.google.common.hash.HashCode; import com.google.common.hash.HashCode;
import com.google.common.hash.HashFunction;
import com.google.common.hash.Hashing; import com.google.common.hash.Hashing;
import com.google.common.hash.HashingInputStream; import com.google.common.hash.HashingInputStream;
import com.google.common.io.BaseEncoding; import com.google.common.io.BaseEncoding;
@ -175,7 +176,9 @@ public class S3ProxyHandler {
); );
private static final String XML_CONTENT_TYPE = "application/xml"; private static final String XML_CONTENT_TYPE = "application/xml";
/** URLEncoder escapes / which we do not want. */ /** URLEncoder escapes / which we do not want. */
private static Escaper urlEscaper = new PercentEscaper("*-./_", true); private static final Escaper urlEscaper = new PercentEscaper("*-./_", true);
@SuppressWarnings("deprecation")
private static final HashFunction MD5 = Hashing.md5();
private final boolean anonymousIdentity; private final boolean anonymousIdentity;
private final AuthenticationType authenticationType; private final AuthenticationType authenticationType;
@ -1662,7 +1665,7 @@ public class S3ProxyHandler {
} catch (IllegalArgumentException iae) { } catch (IllegalArgumentException iae) {
throw new S3Exception(S3ErrorCode.INVALID_DIGEST, iae); throw new S3Exception(S3ErrorCode.INVALID_DIGEST, iae);
} }
if (contentMD5.bits() != Hashing.md5().bits()) { if (contentMD5.bits() != MD5.bits()) {
throw new S3Exception(S3ErrorCode.INVALID_DIGEST); throw new S3Exception(S3ErrorCode.INVALID_DIGEST);
} }
} }
@ -2276,8 +2279,7 @@ public class S3ProxyHandler {
// part multiple Azure parts. // part multiple Azure parts.
long azureMaximumMultipartPartSize = long azureMaximumMultipartPartSize =
blobStore.getMaximumMultipartPartSize(); blobStore.getMaximumMultipartPartSize();
HashingInputStream his = new HashingInputStream(Hashing.md5(), HashingInputStream his = new HashingInputStream(MD5, is);
is);
for (int offset = 0, subPartNumber = 0; offset < contentLength; for (int offset = 0, subPartNumber = 0; offset < contentLength;
offset += azureMaximumMultipartPartSize, offset += azureMaximumMultipartPartSize,
++subPartNumber) { ++subPartNumber) {
@ -2354,7 +2356,7 @@ public class S3ProxyHandler {
} catch (IllegalArgumentException iae) { } catch (IllegalArgumentException iae) {
throw new S3Exception(S3ErrorCode.INVALID_DIGEST, iae); throw new S3Exception(S3ErrorCode.INVALID_DIGEST, iae);
} }
if (contentMD5.bits() != Hashing.md5().bits()) { if (contentMD5.bits() != MD5.bits()) {
throw new S3Exception(S3ErrorCode.INVALID_DIGEST); throw new S3Exception(S3ErrorCode.INVALID_DIGEST);
} }
} }
@ -2405,8 +2407,7 @@ public class S3ProxyHandler {
// part multiple Azure parts. // part multiple Azure parts.
long azureMaximumMultipartPartSize = long azureMaximumMultipartPartSize =
blobStore.getMaximumMultipartPartSize(); blobStore.getMaximumMultipartPartSize();
HashingInputStream his = new HashingInputStream(Hashing.md5(), HashingInputStream his = new HashingInputStream(MD5, is);
is);
for (int offset = 0, subPartNumber = 0; offset < contentLength; for (int offset = 0, subPartNumber = 0; offset < contentLength;
offset += azureMaximumMultipartPartSize, offset += azureMaximumMultipartPartSize,
++subPartNumber) { ++subPartNumber) {

Wyświetl plik

@ -27,7 +27,6 @@ import java.util.concurrent.TimeUnit;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.hash.Hashing;
import com.google.common.io.ByteSource; import com.google.common.io.ByteSource;
import com.google.common.net.MediaType; import com.google.common.net.MediaType;
import com.google.inject.Module; import com.google.inject.Module;
@ -196,7 +195,7 @@ public final class EventualBlobStoreTest {
.contentEncoding("compress") .contentEncoding("compress")
.contentLength(BYTE_SOURCE.size()) .contentLength(BYTE_SOURCE.size())
.contentType(MediaType.MP4_AUDIO) .contentType(MediaType.MP4_AUDIO)
.contentMD5(BYTE_SOURCE.hash(Hashing.md5())) .contentMD5(BYTE_SOURCE.hash(TestUtils.MD5))
.userMetadata(ImmutableMap.of("key", "value")) .userMetadata(ImmutableMap.of("key", "value"))
.build(); .build();
} }

Wyświetl plik

@ -25,7 +25,6 @@ import java.util.Random;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.hash.Hashing;
import com.google.common.io.ByteSource; import com.google.common.io.ByteSource;
import com.google.common.io.ByteStreams; import com.google.common.io.ByteStreams;
import com.google.common.net.MediaType; import com.google.common.net.MediaType;
@ -181,7 +180,7 @@ public final class NullBlobStoreTest {
.contentEncoding("compress") .contentEncoding("compress")
.contentLength(BYTE_SOURCE.size()) .contentLength(BYTE_SOURCE.size())
.contentType(MediaType.MP4_AUDIO) .contentType(MediaType.MP4_AUDIO)
.contentMD5(BYTE_SOURCE.hash(Hashing.md5())) .contentMD5(BYTE_SOURCE.hash(TestUtils.MD5))
.userMetadata(ImmutableMap.of("key", "value")) .userMetadata(ImmutableMap.of("key", "value"))
.build(); .build();
} }

Wyświetl plik

@ -26,6 +26,8 @@ import java.util.Random;
import com.google.common.base.Strings; import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.hash.HashFunction;
import com.google.common.hash.Hashing;
import com.google.common.io.ByteSource; import com.google.common.io.ByteSource;
import com.google.common.io.Files; import com.google.common.io.Files;
import com.google.common.io.Resources; import com.google.common.io.Resources;
@ -41,6 +43,9 @@ import org.jclouds.blobstore.BlobStoreContext;
import org.jclouds.logging.slf4j.config.SLF4JLoggingModule; import org.jclouds.logging.slf4j.config.SLF4JLoggingModule;
final class TestUtils { final class TestUtils {
@SuppressWarnings("deprecation")
static final HashFunction MD5 = Hashing.md5();
private TestUtils() { private TestUtils() {
throw new AssertionError("intentionally unimplemented"); throw new AssertionError("intentionally unimplemented");
} }
@ -164,8 +169,8 @@ final class TestUtils {
if (provider.equals("google-cloud-storage")) { if (provider.equals("google-cloud-storage")) {
File credentialFile = new File(credential); File credentialFile = new File(credential);
if (credentialFile.exists()) { if (credentialFile.exists()) {
credential = Files.toString(credentialFile, credential = Files.asCharSource(credentialFile,
StandardCharsets.UTF_8); StandardCharsets.UTF_8).read();
} }
info.getProperties().remove(Constants.PROPERTY_CREDENTIAL); info.getProperties().remove(Constants.PROPERTY_CREDENTIAL);
} }