diff --git a/google-cloud-storage/src/main/java/com/google/cloud/storage/Blob.java b/google-cloud-storage/src/main/java/com/google/cloud/storage/Blob.java index 865c5f71c1..6762d42f48 100644 --- a/google-cloud-storage/src/main/java/com/google/cloud/storage/Blob.java +++ b/google-cloud-storage/src/main/java/com/google/cloud/storage/Blob.java @@ -19,9 +19,7 @@ import static com.google.cloud.storage.Blob.BlobSourceOption.toGetOptions; import static com.google.cloud.storage.Blob.BlobSourceOption.toSourceOptions; import static com.google.common.base.Preconditions.checkNotNull; -import static java.util.concurrent.Executors.callable; -import com.google.api.gax.retrying.ResultRetryAlgorithm; import com.google.api.services.storage.model.StorageObject; import com.google.auth.ServiceAccountSigner; import com.google.auth.ServiceAccountSigner.SigningException; @@ -34,7 +32,6 @@ import com.google.cloud.storage.Storage.SignUrlOption; import com.google.cloud.storage.spi.v1.StorageRpc; import com.google.common.io.BaseEncoding; -import com.google.common.io.CountingOutputStream; import java.io.IOException; import java.io.ObjectInputStream; import java.io.OutputStream; @@ -47,7 +44,6 @@ import java.util.Map; import java.util.Objects; import java.util.concurrent.TimeUnit; -import java.util.function.Function; /** * An object in Google Cloud Storage. A {@code Blob} object includes the {@code BlobId} instance, diff --git a/google-cloud-storage/src/main/java/com/google/cloud/storage/Storage.java b/google-cloud-storage/src/main/java/com/google/cloud/storage/Storage.java index 97fbb61cfc..b6705c74bb 100644 --- a/google-cloud-storage/src/main/java/com/google/cloud/storage/Storage.java +++ b/google-cloud-storage/src/main/java/com/google/cloud/storage/Storage.java @@ -2676,6 +2676,7 @@ Blob createFrom( /** * Downloads the given blob to the given path using specified blob read options. + * * @param blob * @param path * @param options @@ -2683,7 +2684,8 @@ Blob createFrom( void downloadTo(BlobId blob, Path path, Blob.BlobSourceOption... options); /** - * Downloads the given blob to the given output stream using specified blob read options. + * Downloads the given blob to the given output stream using specified blob read options. + * * @param blob * @param outputStream * @param options diff --git a/google-cloud-storage/src/main/java/com/google/cloud/storage/StorageImpl.java b/google-cloud-storage/src/main/java/com/google/cloud/storage/StorageImpl.java index 0e5b2e5828..21f89b91a2 100644 --- a/google-cloud-storage/src/main/java/com/google/cloud/storage/StorageImpl.java +++ b/google-cloud-storage/src/main/java/com/google/cloud/storage/StorageImpl.java @@ -550,7 +550,7 @@ public ReadChannel reader(BlobId blob, BlobSourceOption... options) { @Override public void downloadTo(BlobId blob, Path path, Blob.BlobSourceOption... options) { try (OutputStream outputStream = Files.newOutputStream(path)) { - downloadTo(blob,outputStream, options); + downloadTo(blob, outputStream, options); } catch (IOException e) { throw new StorageException(e); } diff --git a/google-cloud-storage/src/test/java/com/google/cloud/storage/BlobTest.java b/google-cloud-storage/src/test/java/com/google/cloud/storage/BlobTest.java index 4802e21b86..97a9b7e231 100644 --- a/google-cloud-storage/src/test/java/com/google/cloud/storage/BlobTest.java +++ b/google-cloud-storage/src/test/java/com/google/cloud/storage/BlobTest.java @@ -16,14 +16,11 @@ package com.google.cloud.storage; -import static org.easymock.EasyMock.anyObject; import static org.easymock.EasyMock.capture; import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.createNiceMock; import static org.easymock.EasyMock.createStrictMock; import static org.easymock.EasyMock.eq; import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.getCurrentArguments; import static org.easymock.EasyMock.replay; import static org.easymock.EasyMock.verify; import static org.junit.Assert.assertArrayEquals; @@ -32,11 +29,9 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; import com.google.api.core.ApiClock; import com.google.api.gax.retrying.RetrySettings; -import com.google.api.services.storage.model.StorageObject; import com.google.cloud.ReadChannel; import com.google.cloud.storage.Acl.Project; import com.google.cloud.storage.Acl.Project.ProjectRole; @@ -45,21 +40,16 @@ import com.google.cloud.storage.Blob.BlobSourceOption; import com.google.cloud.storage.Storage.BlobWriteOption; import com.google.cloud.storage.Storage.CopyRequest; -import com.google.cloud.storage.spi.v1.StorageRpc; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.io.BaseEncoding; -import java.io.File; -import java.io.OutputStream; import java.net.URL; -import java.nio.file.Files; import java.security.Key; import java.util.List; import java.util.Map; import java.util.concurrent.TimeUnit; import javax.crypto.spec.SecretKeySpec; import org.easymock.Capture; -import org.easymock.IAnswer; import org.junit.After; import org.junit.Before; import org.junit.Test; diff --git a/google-cloud-storage/src/test/java/com/google/cloud/storage/StorageImplTest.java b/google-cloud-storage/src/test/java/com/google/cloud/storage/StorageImplTest.java index 1aefa13dbd..ae3682414b 100644 --- a/google-cloud-storage/src/test/java/com/google/cloud/storage/StorageImplTest.java +++ b/google-cloud-storage/src/test/java/com/google/cloud/storage/StorageImplTest.java @@ -20,7 +20,6 @@ import static com.google.cloud.storage.testing.ApiPolicyMatcher.eqApiPolicy; import static java.nio.charset.StandardCharsets.UTF_8; import static org.easymock.EasyMock.anyObject; -import static org.easymock.EasyMock.createNiceMock; import static org.easymock.EasyMock.eq; import static org.easymock.EasyMock.expect; import static org.easymock.EasyMock.getCurrentArguments; @@ -2280,11 +2279,11 @@ public void testDownloadTo() throws Exception { storage = options.toBuilder().build().getService(); final byte[] expected = {1, 2}; EasyMock.expect( - storageRpcMock.read( - anyObject(StorageObject.class), - anyObject(Map.class), - eq(0l), - anyObject(OutputStream.class))) + storageRpcMock.read( + anyObject(StorageObject.class), + anyObject(Map.class), + eq(0l), + anyObject(OutputStream.class))) .andAnswer( new IAnswer() { @Override @@ -2303,17 +2302,19 @@ public Long answer() throws Throwable { @Test public void testDownloadToWithRetries() throws Exception { BlobId blob = BlobId.of(BUCKET_NAME1, BLOB_NAME1); - storage = options.toBuilder() - .setRetrySettings(RetrySettings.newBuilder().setMaxAttempts(2).build()) - .build() - .getService(); + storage = + options + .toBuilder() + .setRetrySettings(RetrySettings.newBuilder().setMaxAttempts(2).build()) + .build() + .getService(); final byte[] expected = {1, 2}; expect( - storageRpcMock.read( - anyObject(StorageObject.class), - anyObject(Map.class), - eq(0l), - anyObject(OutputStream.class))) + storageRpcMock.read( + anyObject(StorageObject.class), + anyObject(Map.class), + eq(0l), + anyObject(OutputStream.class))) .andAnswer( new IAnswer() { @Override @@ -2323,11 +2324,11 @@ public Long answer() throws Throwable { } }); expect( - storageRpcMock.read( - anyObject(StorageObject.class), - anyObject(Map.class), - eq(1l), - anyObject(OutputStream.class))) + storageRpcMock.read( + anyObject(StorageObject.class), + anyObject(Map.class), + eq(1l), + anyObject(OutputStream.class))) .andAnswer( new IAnswer() { @Override @@ -2349,11 +2350,11 @@ public void testDownloadToWithException() throws Exception { storage = options.toBuilder().build().getService(); Exception exception = new IllegalStateException("test"); expect( - storageRpcMock.read( - anyObject(StorageObject.class), - anyObject(Map.class), - eq(0l), - anyObject(OutputStream.class))) + storageRpcMock.read( + anyObject(StorageObject.class), + anyObject(Map.class), + eq(0l), + anyObject(OutputStream.class))) .andThrow(exception); replay(storageRpcMock); File file = File.createTempFile("blob", ".tmp"); diff --git a/google-cloud-storage/src/test/java/com/google/cloud/storage/it/ITStorageTest.java b/google-cloud-storage/src/test/java/com/google/cloud/storage/it/ITStorageTest.java index b81f40fa6d..bf55915f0b 100644 --- a/google-cloud-storage/src/test/java/com/google/cloud/storage/it/ITStorageTest.java +++ b/google-cloud-storage/src/test/java/com/google/cloud/storage/it/ITStorageTest.java @@ -884,13 +884,15 @@ public void testGetBlobRawInput() throws IOException { Path rawInputGzippedFile = File.createTempFile("rawinputgzippedfile", ".txt").toPath(); - storage.downloadTo(blobId, rawInputGzippedFile, Blob.BlobSourceOption.shouldReturnRawInputStream(true)); + storage.downloadTo( + blobId, rawInputGzippedFile, Blob.BlobSourceOption.shouldReturnRawInputStream(true)); assertArrayEquals( Files.readAllBytes(gzippedFile.toPath()), Files.readAllBytes(rawInputGzippedFile)); Path unzippedFile = File.createTempFile("unzippedfile", ".txt").toPath(); - storage.downloadTo(blobId, unzippedFile, Blob.BlobSourceOption.shouldReturnRawInputStream(false)); + storage.downloadTo( + blobId, unzippedFile, Blob.BlobSourceOption.shouldReturnRawInputStream(false)); assertArrayEquals("hello world".getBytes(), Files.readAllBytes(unzippedFile)); }