Skip to content

Commit 5b1c443

Browse files
committed
Merge pull request #494 from mziccard/storage-minor
Remove RemoteGcsHelper.create(String, String) and other minor fixes
2 parents 637f156 + 604b1c4 commit 5b1c443

24 files changed

+154
-188
lines changed

TESTING.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ Currently, there isn't an emulator for Google Cloud Storage, so an alternative i
5555
3. Create a `RemoteGcsHelper` object using your project ID and JSON key.
5656
Here is an example that uses the `RemoteGcsHelper` to create a bucket.
5757
```java
58-
RemoteGcsHelper gcsHelper = RemoteGcsHelper.create(PROJECT_ID, "/path/to/my/JSON/key.json");
58+
RemoteGcsHelper gcsHelper =
59+
RemoteGcsHelper.create(PROJECT_ID, new FileInputStream("/path/to/my/JSON/key.json"));
5960
Storage storage = gcsHelper.options().service();
6061
String bucket = RemoteGcsHelper.generateBucketName();
6162
storage.create(BucketInfo.of(bucket));

gcloud-java-storage/src/main/java/com/google/gcloud/spi/DefaultStorageRpc.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -479,8 +479,8 @@ public Tuple<String, byte[]> read(StorageObject from, Map<Option, ?> options, lo
479479
}
480480

481481
@Override
482-
public void write(String uploadId, byte[] toWrite, int toWriteOffset, StorageObject dest,
483-
long destOffset, int length, boolean last) throws StorageException {
482+
public void write(String uploadId, byte[] toWrite, int toWriteOffset, long destOffset, int length,
483+
boolean last) throws StorageException {
484484
try {
485485
GenericUrl url = new GenericUrl(uploadId);
486486
HttpRequest httpRequest = storage.getRequestFactory().buildPutRequest(url,
@@ -571,7 +571,7 @@ private RewriteResponse rewrite(RewriteRequest req, String token) throws Storage
571571
try {
572572
Long maxBytesRewrittenPerCall = req.megabytesRewrittenPerCall != null
573573
? req.megabytesRewrittenPerCall * MEGABYTE : null;
574-
com.google.api.services.storage.model.RewriteResponse rewriteReponse = storage.objects()
574+
com.google.api.services.storage.model.RewriteResponse rewriteResponse = storage.objects()
575575
.rewrite(req.source.getBucket(), req.source.getName(), req.target.getBucket(),
576576
req.target.getName(), req.target.getContentType() != null ? req.target : null)
577577
.setSourceGeneration(req.source.getGeneration())
@@ -590,11 +590,11 @@ private RewriteResponse rewrite(RewriteRequest req, String token) throws Storage
590590
.execute();
591591
return new RewriteResponse(
592592
req,
593-
rewriteReponse.getResource(),
594-
rewriteReponse.getObjectSize().longValue(),
595-
rewriteReponse.getDone(),
596-
rewriteReponse.getRewriteToken(),
597-
rewriteReponse.getTotalBytesRewritten().longValue());
593+
rewriteResponse.getResource(),
594+
rewriteResponse.getObjectSize().longValue(),
595+
rewriteResponse.getDone(),
596+
rewriteResponse.getRewriteToken(),
597+
rewriteResponse.getTotalBytesRewritten().longValue());
598598
} catch (IOException ex) {
599599
throw translate(ex);
600600
}

gcloud-java-storage/src/main/java/com/google/gcloud/spi/StorageRpc.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,8 @@ Tuple<String, byte[]> read(StorageObject from, Map<Option, ?> options, long posi
264264

265265
String open(StorageObject object, Map<Option, ?> options) throws StorageException;
266266

267-
void write(String uploadId, byte[] toWrite, int toWriteOffset, StorageObject dest,
268-
long destOffset, int length, boolean last) throws StorageException;
267+
void write(String uploadId, byte[] toWrite, int toWriteOffset, long destOffset, int length,
268+
boolean last) throws StorageException;
269269

270270
RewriteResponse openRewrite(RewriteRequest rewriteRequest) throws StorageException;
271271

gcloud-java-storage/src/main/java/com/google/gcloud/storage/Acl.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,14 @@ protected String value() {
7373
}
7474

7575
@Override
76-
public boolean equals(Object o) {
77-
if (this == o) {
76+
public boolean equals(Object obj) {
77+
if (this == obj) {
7878
return true;
7979
}
80-
if (o == null || getClass() != o.getClass()) {
80+
if (obj == null || getClass() != obj.getClass()) {
8181
return false;
8282
}
83-
Entity entity = (Entity) o;
83+
Entity entity = (Entity) obj;
8484
return Objects.equals(type, entity.type) && Objects.equals(value, entity.value);
8585
}
8686

@@ -226,7 +226,7 @@ public static final class Project extends Entity {
226226

227227
private static final long serialVersionUID = 7933776866530023027L;
228228

229-
private final ProjectRole pRole;
229+
private final ProjectRole projectRole;
230230
private final String projectId;
231231

232232
public enum ProjectRole {
@@ -236,20 +236,20 @@ public enum ProjectRole {
236236
/**
237237
* Creates a project entity.
238238
*
239-
* @param pRole a role in the project, used to select project's teams
239+
* @param projectRole a role in the project, used to select project's teams
240240
* @param projectId id of the project
241241
*/
242-
public Project(ProjectRole pRole, String projectId) {
243-
super(Type.PROJECT, pRole.name().toLowerCase() + "-" + projectId);
244-
this.pRole = pRole;
242+
public Project(ProjectRole projectRole, String projectId) {
243+
super(Type.PROJECT, projectRole.name().toLowerCase() + "-" + projectId);
244+
this.projectRole = projectRole;
245245
this.projectId = projectId;
246246
}
247247

248248
/**
249249
* Returns the role in the project for this entity.
250250
*/
251251
public ProjectRole projectRole() {
252-
return pRole;
252+
return projectRole;
253253
}
254254

255255
/**
@@ -275,7 +275,7 @@ String toPb() {
275275
}
276276

277277
/**
278-
* Creats an ACL object.
278+
* Creates an ACL object.
279279
*
280280
* @param entity the entity for this ACL object
281281
* @param role the role to associate to the {@code entity} object

gcloud-java-storage/src/main/java/com/google/gcloud/storage/BatchResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ static <T extends Serializable> Result<T> empty() {
113113
}
114114
}
115115

116-
public BatchResponse(List<Result<Boolean>> deleteResult, List<Result<BlobInfo>> updateResult,
116+
BatchResponse(List<Result<Boolean>> deleteResult, List<Result<BlobInfo>> updateResult,
117117
List<Result<BlobInfo>> getResult) {
118118
this.deleteResult = ImmutableList.copyOf(deleteResult);
119119
this.updateResult = ImmutableList.copyOf(updateResult);

gcloud-java-storage/src/main/java/com/google/gcloud/storage/Blob.java

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@
3939
/**
4040
* A Google cloud storage object.
4141
*
42-
* <p>
43-
* Objects of this class are immutable. Operations that modify the blob like {@link #update} and
42+
* <p>Objects of this class are immutable. Operations that modify the blob like {@link #update} and
4443
* {@link #copyTo} return a new object. To get a {@code Blob} object with the most recent
4544
* information use {@link #reload}.
4645
* </p>
@@ -239,13 +238,13 @@ public Blob reload(BlobSourceOption... options) {
239238
* made on the metadata generation of the current blob. If you want to update the information only
240239
* if the current blob metadata are at their latest version use the {@code metagenerationMatch}
241240
* option: {@code blob.update(newInfo, BlobTargetOption.metagenerationMatch())}.
242-
* <p>
243-
* Original metadata are merged with metadata in the provided {@code blobInfo}. To replace
241+
*
242+
* <p>Original metadata are merged with metadata in the provided {@code blobInfo}. To replace
244243
* metadata instead you first have to unset them. Unsetting metadata can be done by setting the
245244
* provided {@code blobInfo}'s metadata to {@code null}.
246245
* </p>
247-
* <p>
248-
* Example usage of replacing blob's metadata:
246+
*
247+
* <p>Example usage of replacing blob's metadata:
249248
* <pre> {@code blob.update(blob.info().toBuilder().metadata(null).build());}
250249
* {@code blob.update(blob.info().toBuilder().metadata(newMetadata).build());}
251250
* </pre>
@@ -261,6 +260,17 @@ public Blob update(BlobInfo blobInfo, BlobTargetOption... options) {
261260
return new Blob(storage, storage.update(blobInfo, options));
262261
}
263262

263+
/**
264+
* Deletes this blob.
265+
*
266+
* @param options blob delete options
267+
* @return {@code true} if blob was deleted, {@code false} if it was not found
268+
* @throws StorageException upon failure
269+
*/
270+
public boolean delete(BlobSourceOption... options) {
271+
return storage.delete(info.blobId(), toSourceOptions(info, options));
272+
}
273+
264274
/**
265275
* Sends a copy request for the current blob to the target blob. Possibly also some of the
266276
* metadata are copied (e.g. content-type).
@@ -277,17 +287,6 @@ public CopyWriter copyTo(BlobId targetBlob, BlobSourceOption... options) {
277287
return storage.copy(copyRequest);
278288
}
279289

280-
/**
281-
* Deletes this blob.
282-
*
283-
* @param options blob delete options
284-
* @return {@code true} if blob was deleted, {@code false} if it was not found
285-
* @throws StorageException upon failure
286-
*/
287-
public boolean delete(BlobSourceOption... options) {
288-
return storage.delete(info.blobId(), toSourceOptions(info, options));
289-
}
290-
291290
/**
292291
* Sends a copy request for the current blob to the target bucket, preserving its name. Possibly
293292
* copying also some of the metadata (e.g. content-type).
@@ -381,8 +380,8 @@ public static List<Blob> get(final Storage storage, BlobId... blobs) {
381380
return Collections.unmodifiableList(Lists.transform(storage.get(blobs),
382381
new Function<BlobInfo, Blob>() {
383382
@Override
384-
public Blob apply(BlobInfo f) {
385-
return f != null ? new Blob(storage, f) : null;
383+
public Blob apply(BlobInfo blobInfo) {
384+
return blobInfo != null ? new Blob(storage, blobInfo) : null;
386385
}
387386
}));
388387
}
@@ -410,8 +409,8 @@ public static List<Blob> update(final Storage storage, BlobInfo... infos) {
410409
return Collections.unmodifiableList(Lists.transform(storage.update(infos),
411410
new Function<BlobInfo, Blob>() {
412411
@Override
413-
public Blob apply(BlobInfo f) {
414-
return f != null ? new Blob(storage, f) : null;
412+
public Blob apply(BlobInfo blobInfo) {
413+
return blobInfo != null ? new Blob(storage, blobInfo) : null;
415414
}
416415
}));
417416
}

gcloud-java-storage/src/main/java/com/google/gcloud/storage/BlobInfo.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ Builder mediaLink(String mediaLink) {
277277
*/
278278
public Builder metadata(Map<String, String> metadata) {
279279
this.metadata = metadata != null
280-
? new HashMap(metadata) : Data.<Map>nullOf(ImmutableEmptyMap.class);
280+
? new HashMap<>(metadata) : Data.<Map<String, String>>nullOf(ImmutableEmptyMap.class);
281281
return this;
282282
}
283283

@@ -576,8 +576,9 @@ public ObjectAccessControl apply(Acl acl) {
576576
Map<String, String> pbMetadata = metadata;
577577
if (metadata != null && !Data.isNull(metadata)) {
578578
pbMetadata = Maps.newHashMapWithExpectedSize(metadata.size());
579-
for (String key : metadata.keySet()) {
580-
pbMetadata.put(key, firstNonNull(metadata.get(key), Data.<String>nullOf(String.class)));
579+
for (Map.Entry<String, String> entry : metadata.entrySet()) {
580+
pbMetadata.put(entry.getKey(),
581+
firstNonNull(entry.getValue(), Data.<String>nullOf(String.class)));
581582
}
582583
}
583584
storageObject.setMetadata(pbMetadata);

gcloud-java-storage/src/main/java/com/google/gcloud/storage/BlobReadChannel.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@
2626
/**
2727
* A channel for reading data from a Google Cloud Storage object.
2828
*
29-
* Implementations of this class may buffer data internally to reduce remote calls. This interface
30-
* implements {@link Restorable} to allow saving the reader's state to continue reading afterwards.
29+
* <p>Implementations of this class may buffer data internally to reduce remote calls. This
30+
* interface implements {@link Restorable} to allow saving the reader's state to continue reading
31+
* afterwards.
32+
* </p>
3133
*/
3234
public interface BlobReadChannel extends ReadableByteChannel, Closeable,
3335
Restorable<BlobReadChannel> {

gcloud-java-storage/src/main/java/com/google/gcloud/storage/BlobWriteChannel.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@
2525
/**
2626
* A channel for writing data to a Google Cloud Storage object.
2727
*
28-
* Implementations of this class may further buffer data internally to reduce remote calls. Written
29-
* data will only be visible after calling {@link #close()}. This interface implements
28+
* <p>Implementations of this class may further buffer data internally to reduce remote calls.
29+
* Written data will only be visible after calling {@link #close()}. This interface implements
3030
* {@link Restorable} to allow saving the writer's state to continue writing afterwards.
31+
* </p>
3132
*/
3233
public interface BlobWriteChannel extends WritableByteChannel, Closeable,
3334
Restorable<BlobWriteChannel> {

gcloud-java-storage/src/main/java/com/google/gcloud/storage/BlobWriteChannelImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ private void flush() {
9191
runWithRetries(callable(new Runnable() {
9292
@Override
9393
public void run() {
94-
storageRpc.write(uploadId, buffer, 0, storageObject, position, length, false);
94+
storageRpc.write(uploadId, buffer, 0, position, length, false);
9595
}
9696
}), options.retryParams(), StorageImpl.EXCEPTION_HANDLER);
9797
} catch (RetryHelper.RetryHelperException e) {
@@ -139,7 +139,7 @@ public void close() throws IOException {
139139
runWithRetries(callable(new Runnable() {
140140
@Override
141141
public void run() {
142-
storageRpc.write(uploadId, buffer, 0, storageObject, position, limit, true);
142+
storageRpc.write(uploadId, buffer, 0, position, limit, true);
143143
}
144144
}), options.retryParams(), StorageImpl.EXCEPTION_HANDLER);
145145
} catch (RetryHelper.RetryHelperException e) {

0 commit comments

Comments
 (0)