diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Acl.java b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Acl.java index fd75e10d92fa..39eb3a1107a8 100644 --- a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Acl.java +++ b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Acl.java @@ -73,14 +73,14 @@ protected String value() { } @Override - public boolean equals(Object o) { - if (this == o) { + public boolean equals(Object obj) { + if (this == obj) { return true; } - if (o == null || getClass() != o.getClass()) { + if (obj == null || getClass() != obj.getClass()) { return false; } - Entity entity = (Entity) o; + Entity entity = (Entity) obj; return Objects.equals(type, entity.type) && Objects.equals(value, entity.value); } @@ -226,7 +226,7 @@ public static final class Project extends Entity { private static final long serialVersionUID = 7933776866530023027L; - private final ProjectRole pRole; + private final ProjectRole projectRole; private final String projectId; public enum ProjectRole { @@ -236,12 +236,12 @@ public enum ProjectRole { /** * Creates a project entity. * - * @param pRole a role in the project, used to select project's teams + * @param projectRole a role in the project, used to select project's teams * @param projectId id of the project */ - public Project(ProjectRole pRole, String projectId) { - super(Type.PROJECT, pRole.name().toLowerCase() + "-" + projectId); - this.pRole = pRole; + public Project(ProjectRole projectRole, String projectId) { + super(Type.PROJECT, projectRole.name().toLowerCase() + "-" + projectId); + this.projectRole = projectRole; this.projectId = projectId; } @@ -249,7 +249,7 @@ public Project(ProjectRole pRole, String projectId) { * Returns the role in the project for this entity. */ public ProjectRole projectRole() { - return pRole; + return projectRole; } /** diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BatchResponse.java b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BatchResponse.java index 9ac799e74a15..98e7ce09cef0 100644 --- a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BatchResponse.java +++ b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BatchResponse.java @@ -113,7 +113,7 @@ static Result empty() { } } - public BatchResponse(List> deleteResult, List> updateResult, + BatchResponse(List> deleteResult, List> updateResult, List> getResult) { this.deleteResult = ImmutableList.copyOf(deleteResult); this.updateResult = ImmutableList.copyOf(updateResult); diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Blob.java b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Blob.java index 6bbc3843f97e..c39a0aa73871 100644 --- a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Blob.java +++ b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Blob.java @@ -39,8 +39,7 @@ /** * A Google cloud storage object. * - *

- * Objects of this class are immutable. Operations that modify the blob like {@link #update} and + *

Objects of this class are immutable. Operations that modify the blob like {@link #update} and * {@link #copyTo} return a new object. To get a {@code Blob} object with the most recent * information use {@link #reload}. *

@@ -239,13 +238,13 @@ public Blob reload(BlobSourceOption... options) { * made on the metadata generation of the current blob. If you want to update the information only * if the current blob metadata are at their latest version use the {@code metagenerationMatch} * option: {@code blob.update(newInfo, BlobTargetOption.metagenerationMatch())}. - *

- * Original metadata are merged with metadata in the provided {@code blobInfo}. To replace + * + *

Original metadata are merged with metadata in the provided {@code blobInfo}. To replace * metadata instead you first have to unset them. Unsetting metadata can be done by setting the * provided {@code blobInfo}'s metadata to {@code null}. *

- *

- * Example usage of replacing blob's metadata: + * + *

Example usage of replacing blob's metadata: *

    {@code blob.update(blob.info().toBuilder().metadata(null).build());}
    *    {@code blob.update(blob.info().toBuilder().metadata(newMetadata).build());}
    * 
@@ -261,6 +260,17 @@ public Blob update(BlobInfo blobInfo, BlobTargetOption... options) { return new Blob(storage, storage.update(blobInfo, options)); } + /** + * Deletes this blob. + * + * @param options blob delete options + * @return {@code true} if blob was deleted, {@code false} if it was not found + * @throws StorageException upon failure + */ + public boolean delete(BlobSourceOption... options) { + return storage.delete(info.blobId(), toSourceOptions(info, options)); + } + /** * Sends a copy request for the current blob to the target blob. Possibly also some of the * metadata are copied (e.g. content-type). @@ -277,17 +287,6 @@ public CopyWriter copyTo(BlobId targetBlob, BlobSourceOption... options) { return storage.copy(copyRequest); } - /** - * Deletes this blob. - * - * @param options blob delete options - * @return {@code true} if blob was deleted, {@code false} if it was not found - * @throws StorageException upon failure - */ - public boolean delete(BlobSourceOption... options) { - return storage.delete(info.blobId(), toSourceOptions(info, options)); - } - /** * Sends a copy request for the current blob to the target bucket, preserving its name. Possibly * copying also some of the metadata (e.g. content-type). @@ -381,8 +380,8 @@ public static List get(final Storage storage, BlobId... blobs) { return Collections.unmodifiableList(Lists.transform(storage.get(blobs), new Function() { @Override - public Blob apply(BlobInfo f) { - return f != null ? new Blob(storage, f) : null; + public Blob apply(BlobInfo blobInfo) { + return blobInfo != null ? new Blob(storage, blobInfo) : null; } })); } @@ -410,8 +409,8 @@ public static List update(final Storage storage, BlobInfo... infos) { return Collections.unmodifiableList(Lists.transform(storage.update(infos), new Function() { @Override - public Blob apply(BlobInfo f) { - return f != null ? new Blob(storage, f) : null; + public Blob apply(BlobInfo blobInfo) { + return blobInfo != null ? new Blob(storage, blobInfo) : null; } })); } diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BlobReadChannel.java b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BlobReadChannel.java index 54d39649cb70..106d18466dac 100644 --- a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BlobReadChannel.java +++ b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BlobReadChannel.java @@ -26,8 +26,10 @@ /** * A channel for reading data from a Google Cloud Storage object. * - * Implementations of this class may buffer data internally to reduce remote calls. This interface - * implements {@link Restorable} to allow saving the reader's state to continue reading afterwards. + *

Implementations of this class may buffer data internally to reduce remote calls. This + * interface implements {@link Restorable} to allow saving the reader's state to continue reading + * afterwards. + *

*/ public interface BlobReadChannel extends ReadableByteChannel, Closeable, Restorable { diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BlobWriteChannel.java b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BlobWriteChannel.java index fe9164532120..9682c6345659 100644 --- a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BlobWriteChannel.java +++ b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BlobWriteChannel.java @@ -25,9 +25,10 @@ /** * A channel for writing data to a Google Cloud Storage object. * - * Implementations of this class may further buffer data internally to reduce remote calls. Written - * data will only be visible after calling {@link #close()}. This interface implements + *

Implementations of this class may further buffer data internally to reduce remote calls. + * Written data will only be visible after calling {@link #close()}. This interface implements * {@link Restorable} to allow saving the writer's state to continue writing afterwards. + *

*/ public interface BlobWriteChannel extends WritableByteChannel, Closeable, Restorable { diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Bucket.java b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Bucket.java index 38a767508356..1aa273c4ca95 100644 --- a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Bucket.java +++ b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Bucket.java @@ -46,8 +46,7 @@ /** * A Google cloud storage bucket. * - *

- * Objects of this class are immutable. Operations that modify the bucket like {@link #update} + *

Objects of this class are immutable. Operations that modify the bucket like {@link #update} * return a new object. To get a {@code Bucket} object with the most recent information use * {@link #reload}. *

diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/CopyWriter.java b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/CopyWriter.java index 5f2632b2acde..1e5427a847d4 100644 --- a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/CopyWriter.java +++ b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/CopyWriter.java @@ -55,8 +55,8 @@ public class CopyWriter implements Restorable { /** * Returns the updated information for the written blob. Calling this method when {@code isDone()} * is {@code false} will block until all pending chunks are copied. - *

- * This method has the same effect of doing: + * + *

This method has the same effect of doing: *

    {@code while (!copyWriter.isDone()) {
    *        copyWriter.copyChunk();
    *    }}
diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Option.java b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Option.java
index 798db688c8ec..2ec8426bfa9f 100644
--- a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Option.java
+++ b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Option.java
@@ -25,7 +25,7 @@
 import java.util.Objects;
 
 /**
- * Base class for Storage operation option
+ * Base class for Storage operation option.
  */
 class Option implements Serializable {
 
diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Storage.java b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Storage.java
index 23c3c19a6676..c8e5474b16fa 100644
--- a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Storage.java
+++ b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Storage.java
@@ -488,6 +488,14 @@ public static BlobSourceOption generationMatch() {
       return new BlobSourceOption(StorageRpc.Option.IF_GENERATION_MATCH, null);
     }
 
+    /**
+     * Returns an option for blob's data generation match. If this option is used the request will
+     * fail if blob's generation does not match the provided value.
+     */
+    public static BlobSourceOption generationMatch(long generation) {
+      return new BlobSourceOption(StorageRpc.Option.IF_GENERATION_MATCH, generation);
+    }
+
     /**
      * Returns an option for blob's data generation mismatch. If this option is used the request
      * will fail if blob's generation matches. The generation value to compare with the actual
@@ -499,10 +507,6 @@ public static BlobSourceOption generationNotMatch() {
       return new BlobSourceOption(StorageRpc.Option.IF_GENERATION_NOT_MATCH, null);
     }
 
-    public static BlobSourceOption generationMatch(long generation) {
-      return new BlobSourceOption(StorageRpc.Option.IF_GENERATION_MATCH, generation);
-    }
-
     /**
      * Returns an option for blob's data generation mismatch. If this option is used the request
      * will fail if blob's generation matches the provided value.
@@ -554,6 +558,14 @@ public static BlobGetOption generationMatch() {
       return new BlobGetOption(StorageRpc.Option.IF_GENERATION_MATCH, (Long) null);
     }
 
+    /**
+     * Returns an option for blob's data generation match. If this option is used the request will
+     * fail if blob's generation does not match the provided value.
+     */
+    public static BlobGetOption generationMatch(long generation) {
+      return new BlobGetOption(StorageRpc.Option.IF_GENERATION_MATCH, generation);
+    }
+
     /**
      * Returns an option for blob's data generation mismatch. If this option is used the request
      * will fail if blob's generation matches. The generation value to compare with the actual
@@ -565,10 +577,6 @@ public static BlobGetOption generationNotMatch() {
       return new BlobGetOption(StorageRpc.Option.IF_GENERATION_NOT_MATCH, (Long) null);
     }
 
-    public static BlobGetOption generationMatch(long generation) {
-      return new BlobGetOption(StorageRpc.Option.IF_GENERATION_MATCH, generation);
-    }
-
     /**
      * Returns an option for blob's data generation mismatch. If this option is used the request
      * will fail if blob's generation matches the provided value.
@@ -1287,8 +1295,8 @@ private static void checkContentType(BlobInfo blobInfo) throws IllegalArgumentEx
    * Update blob information. Original metadata are merged with metadata in the provided
    * {@code blobInfo}. To replace metadata instead you first have to unset them. Unsetting metadata
    * can be done by setting the provided {@code blobInfo}'s metadata to {@code null}.
-   * 

- * Example usage of replacing blob's metadata: + * + *

Example usage of replacing blob's metadata: *

    {@code service.update(BlobInfo.builder("bucket", "name").metadata(null).build());}
    *    {@code service.update(BlobInfo.builder("bucket", "name").metadata(newMetadata).build());}
    * 
@@ -1302,8 +1310,8 @@ private static void checkContentType(BlobInfo blobInfo) throws IllegalArgumentEx * Update blob information. Original metadata are merged with metadata in the provided * {@code blobInfo}. To replace metadata instead you first have to unset them. Unsetting metadata * can be done by setting the provided {@code blobInfo}'s metadata to {@code null}. - *

- * Example usage of replacing blob's metadata: + * + *

Example usage of replacing blob's metadata: *

    {@code service.update(BlobInfo.builder("bucket", "name").metadata(null).build());}
    *    {@code service.update(BlobInfo.builder("bucket", "name").metadata(newMetadata).build());}
    * 
@@ -1360,8 +1368,8 @@ private static void checkContentType(BlobInfo blobInfo) throws IllegalArgumentEx * returns, regardless of the {@link CopyRequest#megabytesCopiedPerChunk} parameter. * If source and destination have different location or storage class {@link CopyWriter#result()} * might issue multiple RPC calls depending on blob's size. - *

- * Example usage of copy: + * + *

Example usage of copy: *

    {@code BlobInfo blob = service.copy(copyRequest).result();}
    * 
* To explicitly issue chunk copy requests use {@link CopyWriter#copyChunk()} instead: @@ -1449,8 +1457,8 @@ private static void checkContentType(BlobInfo blobInfo) throws IllegalArgumentEx * is only valid within a certain time period. * This is particularly useful if you don't want publicly * accessible blobs, but don't want to require users to explicitly log in. - *

- * Example usage of creating a signed URL that is valid for 2 weeks: + * + *

Example usage of creating a signed URL that is valid for 2 weeks: *

   {@code
    *     service.signUrl(BlobInfo.builder("bucket", "name").build(), 14, TimeUnit.DAYS);
    * }
diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/StorageImpl.java b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/StorageImpl.java index d1535c92dfdb..85e0b02025af 100644 --- a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/StorageImpl.java +++ b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/StorageImpl.java @@ -269,6 +269,11 @@ public Page list(BucketListOption... options) { return listBuckets(options(), optionMap(options)); } + @Override + public Page list(final String bucket, BlobListOption... options) { + return listBlobs(bucket, options(), optionMap(options)); + } + private static Page listBuckets(final StorageOptions serviceOptions, final Map optionsMap) { try { @@ -295,11 +300,6 @@ public BucketInfo apply(com.google.api.services.storage.model.Bucket bucketPb) { } } - @Override - public Page list(final String bucket, BlobListOption... options) { - return listBlobs(bucket, options(), optionMap(options)); - } - private static Page listBlobs(final String bucket, final StorageOptions serviceOptions, final Map optionsMap) { try { @@ -554,8 +554,6 @@ private BlobWriteChannel writer(BlobInfo blobInfo, BlobTargetOption... options) @Override public URL signUrl(BlobInfo blobInfo, long duration, TimeUnit unit, SignUrlOption... options) { - long expiration = TimeUnit.SECONDS.convert( - options().clock().millis() + unit.toMillis(duration), TimeUnit.MILLISECONDS); EnumMap optionMap = Maps.newEnumMap(SignUrlOption.Option.class); for (SignUrlOption option : options) { optionMap.put(option.option(), option.value()); @@ -588,6 +586,8 @@ public URL signUrl(BlobInfo blobInfo, long duration, TimeUnit unit, SignUrlOptio stBuilder.append(blobInfo.contentType()); } stBuilder.append('\n'); + long expiration = TimeUnit.SECONDS.convert( + options().clock().millis() + unit.toMillis(duration), TimeUnit.MILLISECONDS); stBuilder.append(expiration).append('\n'); StringBuilder path = new StringBuilder(); if (!blobInfo.bucket().startsWith("/")) { @@ -606,9 +606,9 @@ public URL signUrl(BlobInfo blobInfo, long duration, TimeUnit unit, SignUrlOptio Signature signer = Signature.getInstance("SHA256withRSA"); signer.initSign(cred.getPrivateKey()); signer.update(stBuilder.toString().getBytes(UTF_8)); + stBuilder = new StringBuilder("https://storage.googleapis.com").append(path); String signature = URLEncoder.encode(BaseEncoding.base64().encode(signer.sign()), UTF_8.name()); - stBuilder = new StringBuilder("https://storage.googleapis.com").append(path); stBuilder.append("?GoogleAccessId=").append(cred.getClientEmail()); stBuilder.append("&Expires=").append(expiration); stBuilder.append("&Signature=").append(signature); @@ -654,12 +654,29 @@ private static List transformResultList( List> results, final T errorValue) { return Lists.transform(results, new Function, T>() { @Override - public T apply(BatchResponse.Result f) { - return f.failed() ? errorValue : f.get(); + public T apply(BatchResponse.Result result) { + return result.failed() ? errorValue : result.get(); } }); } + private static void addToOptionMap(StorageRpc.Option option, T defaultValue, + Map map) { + addToOptionMap(option, option, defaultValue, map); + } + + private static void addToOptionMap(StorageRpc.Option getOption, StorageRpc.Option putOption, + T defaultValue, Map map) { + if (map.containsKey(getOption)) { + @SuppressWarnings("unchecked") + T value = (T) map.remove(getOption); + checkArgument(value != null || defaultValue != null, + "Option " + getOption.value() + " is missing a value"); + value = firstNonNull(value, defaultValue); + map.put(putOption, value); + } + } + private Map optionMap(Long generation, Long metaGeneration, Iterable options) { return optionMap(generation, metaGeneration, options, false); @@ -691,23 +708,6 @@ public T apply(BatchResponse.Result f) { return ImmutableMap.copyOf(temp); } - private static void addToOptionMap(StorageRpc.Option option, T defaultValue, - Map map) { - addToOptionMap(option, option, defaultValue, map); - } - - private static void addToOptionMap(StorageRpc.Option getOption, StorageRpc.Option putOption, - T defaultValue, Map map) { - if (map.containsKey(getOption)) { - @SuppressWarnings("unchecked") - T value = (T) map.remove(getOption); - checkArgument(value != null || defaultValue != null, - "Option " + getOption.value() + " is missing a value"); - value = firstNonNull(value, defaultValue); - map.put(putOption, value); - } - } - private Map optionMap(Option... options) { return optionMap(null, null, Arrays.asList(options)); } diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/package-info.java b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/package-info.java index 137afd38b6ae..a55b23c3666c 100644 --- a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/package-info.java +++ b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/package-info.java @@ -34,7 +34,7 @@ * channel.close(); * }}
* - * When using gcloud-java from outside of App/Compute Engine, you have to When using gcloud-java from outside of App/Compute Engine, you have to specify a * project ID and * provide diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/testing/RemoteGcsHelper.java b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/testing/RemoteGcsHelper.java index cfdbf7ac2a77..77cb5661a614 100644 --- a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/testing/RemoteGcsHelper.java +++ b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/testing/RemoteGcsHelper.java @@ -23,8 +23,6 @@ import com.google.gcloud.storage.StorageException; import com.google.gcloud.storage.StorageOptions; -import java.io.FileInputStream; -import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.util.UUID; diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/testing/package-info.java b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/testing/package-info.java index 064712ca7a81..8afdd8a9660d 100644 --- a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/testing/package-info.java +++ b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/testing/package-info.java @@ -18,6 +18,7 @@ * A testing helper for Google Cloud Storage. * *

A simple usage example: + * *

Before the test: *

 {@code
  * RemoteGcsHelper gcsHelper = RemoteGcsHelper.create();