diff --git a/gcloud-java-examples/src/main/java/com/google/gcloud/examples/StorageExample.java b/gcloud-java-examples/src/main/java/com/google/gcloud/examples/StorageExample.java index 7786c124f6cf..76016a1c8790 100644 --- a/gcloud-java-examples/src/main/java/com/google/gcloud/examples/StorageExample.java +++ b/gcloud-java-examples/src/main/java/com/google/gcloud/examples/StorageExample.java @@ -22,10 +22,10 @@ import com.google.gcloud.spi.StorageRpc.Tuple; import com.google.gcloud.storage.BatchRequest; import com.google.gcloud.storage.BatchResponse; -import com.google.gcloud.storage.Blob; +import com.google.gcloud.storage.BlobInfo; import com.google.gcloud.storage.BlobReadChannel; import com.google.gcloud.storage.BlobWriteChannel; -import com.google.gcloud.storage.Bucket; +import com.google.gcloud.storage.BucketInfo; import com.google.gcloud.storage.Storage; import com.google.gcloud.storage.Storage.ComposeRequest; import com.google.gcloud.storage.Storage.CopyRequest; @@ -86,21 +86,21 @@ private static abstract class StorageAction { abstract void run(Storage storage, T request) throws Exception; - abstract T parse(String... args) throws Exception; + abstract T parse(String... args) throws Exception; protected String params() { return ""; } } - private static abstract class BlobAction extends StorageAction { + private static abstract class BlobAction extends StorageAction { @Override - Blob parse(String... args) { + BlobInfo parse(String... args) { if (args.length != 2) { throw new IllegalArgumentException(); } - return Blob.of(args[0], args[1]); + return BlobInfo.of(args[0], args[1]); } @Override @@ -109,18 +109,18 @@ public String params() { } } - private static abstract class BlobsAction extends StorageAction { + private static abstract class BlobsAction extends StorageAction { @Override - Blob[] parse(String... args) { + BlobInfo[] parse(String... args) { if (args.length < 2) { throw new IllegalArgumentException(); } - Blob[] blobs = new Blob[args.length - 1]; + BlobInfo[] blobInfos = new BlobInfo[args.length - 1]; for (int i = 1; i < args.length; i++) { - blobs[i - 1] = Blob.of(args[0], args[i]); + blobInfos[i - 1] = BlobInfo.of(args[0], args[i]); } - return blobs; + return blobInfos; } @Override @@ -138,34 +138,34 @@ public String params() { */ private static class InfoAction extends BlobsAction { @Override - public void run(Storage storage, Blob... blobs) { - if (blobs.length == 1) { - if (blobs[0].name().isEmpty()) { + public void run(Storage storage, BlobInfo... blobInfos) { + if (blobInfos.length == 1) { + if (blobInfos[0].name().isEmpty()) { // get Bucket - Bucket bucket = storage.get(blobs[0].bucket()); - System.out.println("Bucket info: " + bucket); + BucketInfo bucketInfo = storage.get(blobInfos[0].bucket()); + System.out.println("Bucket info: " + bucketInfo); } else { // get Blob - Blob blob = storage.get(blobs[0].bucket(), blobs[0].name()); - System.out.println("Blob info: " + blob); + BlobInfo blobInfo = storage.get(blobInfos[0].bucket(), blobInfos[0].name()); + System.out.println("Blob info: " + blobInfo); } } else { // use batch to get multiple blobs. BatchRequest.Builder batch = BatchRequest.builder(); - for (Blob blob : blobs) { - batch.get(blob.bucket(), blob.name()); + for (BlobInfo blobInfo : blobInfos) { + batch.get(blobInfo.bucket(), blobInfo.name()); } BatchResponse response = storage.apply(batch.build()); - for (BatchResponse.Result result : response.gets()) { + for (BatchResponse.Result result : response.gets()) { System.out.println(result.get()); } } } @Override - Blob[] parse(String... args) { + BlobInfo[] parse(String... args) { if (args.length < 2) { - return new Blob[] {Blob.of(args[0], "")}; + return new BlobInfo[] {BlobInfo.of(args[0], "")}; } return super.parse(args); } @@ -185,24 +185,24 @@ public String params() { */ private static class DeleteAction extends BlobsAction { @Override - public void run(Storage storage, Blob... blobs) { - if (blobs.length == 1) { - boolean wasDeleted = storage.delete(blobs[0].bucket(), blobs[0].name()); + public void run(Storage storage, BlobInfo... blobInfos) { + if (blobInfos.length == 1) { + boolean wasDeleted = storage.delete(blobInfos[0].bucket(), blobInfos[0].name()); if (wasDeleted) { - System.out.println("Blob " + blobs[0] + " was deleted"); + System.out.println("Blob " + blobInfos[0] + " was deleted"); } } else { // use batch operation BatchRequest.Builder batch = BatchRequest.builder(); - for (Blob blob : blobs) { - batch.delete(blob.bucket(), blob.name()); + for (BlobInfo blobInfo : blobInfos) { + batch.delete(blobInfo.bucket(), blobInfo.name()); } int index = 0; BatchResponse response = storage.apply(batch.build()); for (BatchResponse.Result result : response.deletes()) { if (result.get()) { // request order is maintained - System.out.println("Blob " + blobs[index] + " was deleted"); + System.out.println("Blob " + blobInfos[index] + " was deleted"); } index++; } @@ -232,12 +232,12 @@ String parse(String... args) { public void run(Storage storage, String bucket) { if (bucket == null) { // list buckets - for (Bucket b : storage.list()) { + for (BucketInfo b : storage.list()) { System.out.println(b); } } else { // list a bucket's blobs - for (Blob b : storage.list(bucket)) { + for (BlobInfo b : storage.list(bucket)) { System.out.println(b); } } @@ -254,17 +254,17 @@ public String params() { * * @see Objects: insert */ - private static class UploadAction extends StorageAction> { + private static class UploadAction extends StorageAction> { @Override - public void run(Storage storage, Tuple tuple) throws Exception { + public void run(Storage storage, Tuple tuple) throws Exception { run(storage, tuple.x(), tuple.y()); } - private void run(Storage storage, Path uploadFrom, Blob blob) throws IOException { + private void run(Storage storage, Path uploadFrom, BlobInfo blobInfo) throws IOException { if (Files.size(uploadFrom) > 1_000_000) { // When content is not available or large (1MB or more) it is recommended // to write it in chunks via the blob's channel writer. - try (BlobWriteChannel writer = storage.writer(blob)) { + try (BlobWriteChannel writer = storage.writer(blobInfo)) { byte[] buffer = new byte[1024]; try (InputStream input = Files.newInputStream(uploadFrom)) { int limit; @@ -280,20 +280,20 @@ private void run(Storage storage, Path uploadFrom, Blob blob) throws IOException } else { byte[] bytes = Files.readAllBytes(uploadFrom); // create the blob in one request. - storage.create(blob, bytes); + storage.create(blobInfo, bytes); } System.out.println("Blob was created"); } @Override - Tuple parse(String... args) throws IOException { + Tuple parse(String... args) throws IOException { if (args.length < 2 || args.length > 3) { throw new IllegalArgumentException(); } Path path = Paths.get(args[0]); String contentType = Files.probeContentType(path); String blob = args.length < 3 ? path.getFileName().toString() : args[2]; - return Tuple.of(path, Blob.builder(args[1], blob).contentType(contentType).build()); + return Tuple.of(path, BlobInfo.builder(args[1], blob).contentType(contentType).build()); } @Override @@ -309,17 +309,17 @@ public String params() { * * @see Objects: get */ - private static class DownloadAction extends StorageAction> { + private static class DownloadAction extends StorageAction> { @Override - public void run(Storage storage, Tuple tuple) throws IOException { + public void run(Storage storage, Tuple tuple) throws IOException { run(storage, tuple.x().bucket(), tuple.x().name(), tuple.y()); } private void run(Storage storage, String bucket, String blobName, Path downloadTo) throws IOException { - Blob blob = storage.get(bucket, blobName); - if (blob == null) { + BlobInfo blobInfo = storage.get(bucket, blobName); + if (blobInfo == null) { System.out.println("No such object"); return; } @@ -327,13 +327,13 @@ private void run(Storage storage, String bucket, String blobName, Path downloadT if (downloadTo != null) { writeTo = new PrintStream(new FileOutputStream(downloadTo.toFile())); } - if (blob.size() < 1_000_000) { + if (blobInfo.size() < 1_000_000) { // Blob is small read all its content in one request - byte[] content = storage.load(blob.bucket(), blob.name()); + byte[] content = storage.load(blobInfo.bucket(), blobInfo.name()); writeTo.write(content); } else { // When Blob size is big or unknown use the blob's channel reader. - try (BlobReadChannel reader = storage.reader(blob.bucket(), blob.name())) { + try (BlobReadChannel reader = storage.reader(blobInfo.bucket(), blobInfo.name())) { WritableByteChannel channel = Channels.newChannel(writeTo); ByteBuffer bytes = ByteBuffer.allocate(64 * 1024); while (reader.read(bytes) > 0) { @@ -351,7 +351,7 @@ private void run(Storage storage, String bucket, String blobName, Path downloadT } @Override - Tuple parse(String... args) { + Tuple parse(String... args) { if (args.length < 2 || args.length > 3) { throw new IllegalArgumentException(); } @@ -364,7 +364,7 @@ Tuple parse(String... args) { } else { path = null; } - return Tuple.of(Blob.of(args[0], args[1]), path); + return Tuple.of(BlobInfo.of(args[0], args[1]), path); } @Override @@ -381,8 +381,8 @@ public String params() { private static class CopyAction extends StorageAction { @Override public void run(Storage storage, CopyRequest request) { - Blob copiedBlob = storage.copy(request); - System.out.println("Copied " + copiedBlob); + BlobInfo copiedBlobInfo = storage.copy(request); + System.out.println("Copied " + copiedBlobInfo); } @Override @@ -390,7 +390,7 @@ CopyRequest parse(String... args) { if (args.length != 4) { throw new IllegalArgumentException(); } - return CopyRequest.of(args[0], args[1], Blob.of(args[2], args[3])); + return CopyRequest.of(args[0], args[1], BlobInfo.of(args[2], args[3])); } @Override @@ -407,8 +407,8 @@ public String params() { private static class ComposeAction extends StorageAction { @Override public void run(Storage storage, ComposeRequest request) { - Blob composedBlob = storage.compose(request); - System.out.println("Composed " + composedBlob); + BlobInfo composedBlobInfo = storage.compose(request); + System.out.println("Composed " + composedBlobInfo); } @Override @@ -417,7 +417,7 @@ ComposeRequest parse(String... args) { throw new IllegalArgumentException(); } ComposeRequest.Builder request = ComposeRequest.builder(); - request.target(Blob.of(args[0], args[args.length - 1])); + request.target(BlobInfo.of(args[0], args[args.length - 1])); for (int i = 1; i < args.length - 1; i++) { request.addSource(args[i]); } @@ -435,31 +435,31 @@ public String params() { * * @see Objects: update */ - private static class UpdateMetadataAction extends StorageAction>> { + private static class UpdateMetadataAction extends StorageAction>> { @Override - public void run(Storage storage, Tuple> tuple) + public void run(Storage storage, Tuple> tuple) throws IOException { run(storage, tuple.x().bucket(), tuple.x().name(), tuple.y()); } private void run(Storage storage, String bucket, String blobName, Map metadata) { - Blob blob = storage.get(bucket, blobName); - if (blob == null) { + BlobInfo blobInfo = storage.get(bucket, blobName); + if (blobInfo == null) { System.out.println("No such object"); return; } - blob = storage.update(blob.toBuilder().metadata(metadata).build()); - System.out.println("Updated " + blob); + blobInfo = storage.update(blobInfo.toBuilder().metadata(metadata).build()); + System.out.println("Updated " + blobInfo); } @Override - Tuple> parse(String... args) { + Tuple> parse(String... args) { if (args.length < 2) { throw new IllegalArgumentException(); } - Blob blob = Blob.of(args[0], args[1]); + BlobInfo blobInfo = BlobInfo.of(args[0], args[1]); Map metadata = new HashMap<>(); for (int i = 2; i < args.length; i++) { int idx = args[i].indexOf('='); @@ -469,7 +469,7 @@ Tuple> parse(String... args) { metadata.put(args[i].substring(0, idx), args[i].substring(idx + 1)); } } - return Tuple.of(blob, metadata); + return Tuple.of(blobInfo, metadata); } @Override @@ -485,27 +485,27 @@ public String params() { * @see Signed URLs */ private static class SignUrlAction extends - StorageAction> { + StorageAction> { private static final char[] PASSWORD = "notasecret".toCharArray(); @Override - public void run(Storage storage, Tuple tuple) + public void run(Storage storage, Tuple tuple) throws Exception { run(storage, tuple.x(), tuple.y()); } - private void run(Storage storage, ServiceAccountAuthCredentials cred, Blob blob) + private void run(Storage storage, ServiceAccountAuthCredentials cred, BlobInfo blobInfo) throws IOException { Calendar cal = Calendar.getInstance(); cal.add(Calendar.DATE, 1); long expiration = cal.getTimeInMillis() / 1000; System.out.println("Signed URL: " + - storage.signUrl(blob, expiration, SignUrlOption.serviceAccount(cred))); + storage.signUrl(blobInfo, expiration, SignUrlOption.serviceAccount(cred))); } @Override - Tuple parse(String... args) + Tuple parse(String... args) throws IOException, KeyStoreException, CertificateException, NoSuchAlgorithmException, UnrecoverableKeyException { if (args.length != 4) { @@ -515,7 +515,7 @@ Tuple parse(String... args) keystore.load(Files.newInputStream(Paths.get(args[0])), PASSWORD); PrivateKey privateKey = (PrivateKey) keystore.getKey("privatekey", PASSWORD); ServiceAccountAuthCredentials cred = AuthCredentials.createFor(args[1], privateKey); - return Tuple.of(cred, Blob.of(args[2], args[3])); + return Tuple.of(cred, BlobInfo.of(args[2], args[3])); } @Override diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BatchRequest.java b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BatchRequest.java index 5cea321b0071..6959388f34ef 100644 --- a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BatchRequest.java +++ b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BatchRequest.java @@ -33,15 +33,15 @@ public final class BatchRequest implements Serializable { private static final long serialVersionUID = -1527992265939800345L; - private final Map> toDelete; - private final Map> toUpdate; - private final Map> toGet; + private final Map> toDelete; + private final Map> toUpdate; + private final Map> toGet; public static class Builder { - private Map> toDelete = new LinkedHashMap<>(); - private Map> toUpdate = new LinkedHashMap<>(); - private Map> toGet = new LinkedHashMap<>(); + private Map> toDelete = new LinkedHashMap<>(); + private Map> toUpdate = new LinkedHashMap<>(); + private Map> toGet = new LinkedHashMap<>(); private Builder() {} @@ -49,15 +49,15 @@ private Builder() {} * Delete the given blob. */ public Builder delete(String bucket, String blob, BlobSourceOption... options) { - toDelete.put(Blob.of(bucket, blob), Lists.newArrayList(options)); + toDelete.put(BlobInfo.of(bucket, blob), Lists.newArrayList(options)); return this; } /** * Update the given blob. */ - public Builder update(Blob blob, BlobTargetOption... options) { - toUpdate.put(blob, Lists.newArrayList(options)); + public Builder update(BlobInfo blobInfo, BlobTargetOption... options) { + toUpdate.put(blobInfo, Lists.newArrayList(options)); return this; } @@ -65,7 +65,7 @@ public Builder update(Blob blob, BlobTargetOption... options) { * Retrieve metadata for the given blob. */ public Builder get(String bucket, String blob, BlobSourceOption... options) { - toGet.put(Blob.of(bucket, blob), Lists.newArrayList(options)); + toGet.put(BlobInfo.of(bucket, blob), Lists.newArrayList(options)); return this; } @@ -96,15 +96,15 @@ public boolean equals(Object obj) { && Objects.equals(toGet, other.toGet); } - public Map> toDelete() { + public Map> toDelete() { return toDelete; } - public Map> toUpdate() { + public Map> toUpdate() { return toUpdate; } - public Map> toGet() { + public Map> toGet() { return toGet; } 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 1a05fba819c4..45aa1674b03c 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 @@ -31,8 +31,8 @@ public final class BatchResponse implements Serializable { private static final long serialVersionUID = 1057416839397037706L; private final List> deleteResult; - private final List> updateResult; - private final List> getResult; + private final List> updateResult; + private final List> getResult; public static class Result implements Serializable { @@ -112,8 +112,8 @@ static Result empty() { } } - public BatchResponse(List> deleteResult, List> updateResult, - List> getResult) { + public BatchResponse(List> deleteResult, List> updateResult, + List> getResult) { this.deleteResult = ImmutableList.copyOf(deleteResult); this.updateResult = ImmutableList.copyOf(updateResult); this.getResult = ImmutableList.copyOf(getResult); @@ -145,14 +145,14 @@ public List> deletes() { /** * Returns the results for the update operations using the request order. */ - public List> updates() { + public List> updates() { return updateResult; } /** * Returns the results for the get operations using the request order. */ - public List> gets() { + public List> gets() { return getResult; } } 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/BlobInfo.java similarity index 93% rename from gcloud-java-storage/src/main/java/com/google/gcloud/storage/Blob.java rename to gcloud-java-storage/src/main/java/com/google/gcloud/storage/BlobInfo.java index 31b88981187d..3ef01af8d1f3 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/BlobInfo.java @@ -41,24 +41,25 @@ * * @see Concepts and Terminology */ -public final class Blob implements Serializable { +public final class BlobInfo implements Serializable { private static final long serialVersionUID = 2228487739943277159L; - static final Function FROM_PB_FUNCTION = - new Function() { + static final Function FROM_PB_FUNCTION = + new Function() { @Override - public Blob apply(StorageObject pb) { - return Blob.fromPb(pb); + public BlobInfo apply(StorageObject pb) { + return BlobInfo.fromPb(pb); } }; - static final Function TO_PB_FUNCTION = new Function() { - @Override - public StorageObject apply(Blob blob) { - return blob.toPb(); - } - }; + static final Function TO_PB_FUNCTION = + new Function() { + @Override + public StorageObject apply(BlobInfo blobInfo) { + return blobInfo.toPb(); + } + }; private final String bucket; private final String id; @@ -220,14 +221,14 @@ Builder updateTime(Long updateTime) { return this; } - public Blob build() { + public BlobInfo build() { checkNotNull(bucket); checkNotNull(name); - return new Blob(this); + return new BlobInfo(this); } } - private Blob(Builder builder) { + private BlobInfo(Builder builder) { bucket = builder.bucket; name = builder.name; id = builder.id; @@ -377,12 +378,12 @@ public String toString() { .toString(); } - public static Blob of(String bucket, String name) { + public static BlobInfo of(String bucket, String name) { return builder(bucket, name).build(); } - public static Builder builder(Bucket bucket, String name) { - return builder(bucket.name(), name); + public static Builder builder(BucketInfo bucketInfo, String name) { + return builder(bucketInfo.name(), name); } public static Builder builder(String bucket, String name) { @@ -396,10 +397,10 @@ public int hashCode() { @Override public boolean equals(Object obj) { - if (!(obj instanceof Blob)) { + if (!(obj instanceof BlobInfo)) { return false; } - return Objects.equals(toPb(), ((Blob) obj).toPb()); + return Objects.equals(toPb(), ((BlobInfo) obj).toPb()); } StorageObject toPb() { @@ -444,7 +445,7 @@ public ObjectAccessControl apply(Acl acl) { return storageObject; } - static Blob fromPb(StorageObject storageObject) { + static BlobInfo fromPb(StorageObject storageObject) { Builder builder = new Builder() .bucket(storageObject.getBucket()) .cacheControl(storageObject.getCacheControl()) diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BlobReadChannelImpl.java b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BlobReadChannelImpl.java index 5a5d165751c4..9d1d37f93ab1 100644 --- a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BlobReadChannelImpl.java +++ b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BlobReadChannelImpl.java @@ -37,7 +37,7 @@ class BlobReadChannelImpl implements BlobReadChannel { private static final long serialVersionUID = 4821762590742862669L; private final StorageOptions serviceOptions; - private final Blob blob; + private final BlobInfo blobInfo; private final Map requestOptions; private int position; private boolean isOpen; @@ -49,10 +49,10 @@ class BlobReadChannelImpl implements BlobReadChannel { private transient int bufferPos; private transient byte[] buffer; - BlobReadChannelImpl(StorageOptions serviceOptions, Blob blob, + BlobReadChannelImpl(StorageOptions serviceOptions, BlobInfo blobInfo, Map requestOptions) { this.serviceOptions = serviceOptions; - this.blob = blob; + this.blobInfo = blobInfo; this.requestOptions = requestOptions; isOpen = true; initTransients(); @@ -75,7 +75,7 @@ private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundE private void initTransients() { storageRpc = serviceOptions.storageRpc(); - storageObject = blob.toPb(); + storageObject = blobInfo.toPb(); } @Override diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BlobWriterChannelImpl.java b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BlobWriterChannelImpl.java index 5e41ed00fc54..27cd807f043f 100644 --- a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BlobWriterChannelImpl.java +++ b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BlobWriterChannelImpl.java @@ -39,7 +39,7 @@ class BlobWriterChannelImpl implements BlobWriteChannel { private static final int DEFAULT_CHUNK_SIZE = 8 * MIN_CHUNK_SIZE; private final StorageOptions options; - private final Blob blob; + private final BlobInfo blobInfo; private final String uploadId; private int position; private byte[] buffer = new byte[0]; @@ -50,10 +50,10 @@ class BlobWriterChannelImpl implements BlobWriteChannel { private transient StorageRpc storageRpc; private transient StorageObject storageObject; - public BlobWriterChannelImpl(StorageOptions options, Blob blob, + public BlobWriterChannelImpl(StorageOptions options, BlobInfo blobInfo, Map optionsMap) { this.options = options; - this.blob = blob; + this.blobInfo = blobInfo; initTransients(); uploadId = options.storageRpc().open(storageObject, optionsMap); } @@ -91,7 +91,7 @@ private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundE private void initTransients() { storageRpc = options.storageRpc(); - storageObject = blob.toPb(); + storageObject = blobInfo.toPb(); } private void validateOpen() throws IOException { 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/BucketInfo.java similarity index 96% rename from gcloud-java-storage/src/main/java/com/google/gcloud/storage/Bucket.java rename to gcloud-java-storage/src/main/java/com/google/gcloud/storage/BucketInfo.java index 85d601487c28..60926e01dbb2 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/BucketInfo.java @@ -48,7 +48,7 @@ * * @see Concepts and Terminology */ -public final class Bucket implements Serializable { +public final class BucketInfo implements Serializable { private static final long serialVersionUID = -3946094202176916586L; @@ -69,19 +69,19 @@ public final class Bucket implements Serializable { private final Location location; private final StorageClass storageClass; - static final Function FROM_PB_FUNCTION = - new Function() { + static final Function FROM_PB_FUNCTION = + new Function() { @Override - public Bucket apply(com.google.api.services.storage.model.Bucket pb) { - return Bucket.fromPb(pb); + public BucketInfo apply(com.google.api.services.storage.model.Bucket pb) { + return BucketInfo.fromPb(pb); } }; - static final Function TO_PB_FUNCTION = - new Function() { + static final Function TO_PB_FUNCTION = + new Function() { @Override - public com.google.api.services.storage.model.Bucket apply(Bucket bucket) { - return bucket.toPb(); + public com.google.api.services.storage.model.Bucket apply(BucketInfo bucketInfo) { + return bucketInfo.toPb(); } }; @@ -491,13 +491,13 @@ public Builder defaultAcl(Iterable acl) { return this; } - public Bucket build() { + public BucketInfo build() { checkNotNull(name); - return new Bucket(this); + return new BucketInfo(this); } } - private Bucket(Builder builder) { + private BucketInfo(Builder builder) { id = builder.id; name = builder.name; etag = builder.etag; @@ -607,10 +607,10 @@ public int hashCode() { @Override public boolean equals(Object obj) { - if (!(obj instanceof Bucket)) { + if (!(obj instanceof BucketInfo)) { return false; } - return Objects.equals(toPb(), ((Bucket) obj).toPb()); + return Objects.equals(toPb(), ((BucketInfo) obj).toPb()); } @Override @@ -620,7 +620,7 @@ public String toString() { .toString(); } - public static Bucket of(String name) { + public static BucketInfo of(String name) { return builder(name).build(); } @@ -691,7 +691,7 @@ public Rule apply(DeleteRule deleteRule) { return bucketPb; } - static Bucket fromPb(com.google.api.services.storage.model.Bucket bucketPb) { + static BucketInfo fromPb(com.google.api.services.storage.model.Bucket bucketPb) { Builder builder = new Builder() .name(bucketPb.getName()) .id(bucketPb.getId()) 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 fb5cab108f30..770a5a924ff6 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 @@ -278,7 +278,7 @@ class ComposeRequest implements Serializable { private static final long serialVersionUID = -7385681353748590911L; private final List sourceBlobs; - private final Blob target; + private final BlobInfo target; private final List targetOptions; public static class SourceBlob implements Serializable { @@ -309,7 +309,7 @@ public Long generation() { public static class Builder { private final List sourceBlobs = new LinkedList<>(); - private Blob target; + private BlobInfo target; private final Set targetOptions = new LinkedHashSet<>(); public Builder addSource(Iterable blobs) { @@ -331,7 +331,7 @@ public Builder addSource(String blob, long generation) { return this; } - public Builder target(Blob target) { + public Builder target(BlobInfo target) { this.target = target; return this; } @@ -358,7 +358,7 @@ public List sourceBlobs() { return sourceBlobs; } - public Blob target() { + public BlobInfo target() { return target; } @@ -366,12 +366,12 @@ public List targetOptions() { return targetOptions; } - public static ComposeRequest of(Iterable sources, Blob target) { + public static ComposeRequest of(Iterable sources, BlobInfo target) { return builder().target(target).addSource(sources).build(); } public static ComposeRequest of(String bucket, Iterable sources, String target) { - return of(sources, Blob.of(bucket, target)); + return of(sources, BlobInfo.of(bucket, target)); } public static Builder builder() { @@ -386,7 +386,7 @@ class CopyRequest implements Serializable { private final String sourceBucket; private final String sourceBlob; private final List sourceOptions; - private final Blob target; + private final BlobInfo target; private final List targetOptions; public static class Builder { @@ -394,7 +394,7 @@ public static class Builder { private String sourceBucket; private String sourceBlob; private final Set sourceOptions = new LinkedHashSet<>(); - private Blob target; + private BlobInfo target; private final Set targetOptions = new LinkedHashSet<>(); public Builder source(String bucket, String blob) { @@ -408,7 +408,7 @@ public Builder sourceOptions(BlobSourceOption... options) { return this; } - public Builder target(Blob target) { + public Builder target(BlobInfo target) { this.target = target; return this; } @@ -446,7 +446,7 @@ public List sourceOptions() { return sourceOptions; } - public Blob target() { + public BlobInfo target() { return target; } @@ -454,12 +454,12 @@ public List targetOptions() { return targetOptions; } - public static CopyRequest of(String sourceBucket, String sourceBlob, Blob target) { + public static CopyRequest of(String sourceBucket, String sourceBlob, BlobInfo target) { return builder().source(sourceBucket, sourceBlob).target(target).build(); } public static CopyRequest of(String sourceBucket, String sourceBlob, String targetBlob) { - return of(sourceBucket, sourceBlob, Blob.of(sourceBucket, targetBlob)); + return of(sourceBucket, sourceBlob, BlobInfo.of(sourceBucket, targetBlob)); } public static Builder builder() { @@ -473,7 +473,7 @@ public static Builder builder() { * @return a complete bucket information. * @throws StorageException upon failure */ - Bucket create(Bucket bucket, BucketTargetOption... options); + BucketInfo create(BucketInfo bucketInfo, BucketTargetOption... options); /** * Create a new blob. @@ -481,35 +481,35 @@ public static Builder builder() { * @return a complete blob information. * @throws StorageException upon failure */ - Blob create(Blob blob, byte[] content, BlobTargetOption... options); + BlobInfo create(BlobInfo blobInfo, byte[] content, BlobTargetOption... options); /** * Return the requested bucket or {@code null} if not found. * * @throws StorageException upon failure */ - Bucket get(String bucket, BucketSourceOption... options); + BucketInfo get(String bucket, BucketSourceOption... options); /** * Return the requested blob or {@code null} if not found. * * @throws StorageException upon failure */ - Blob get(String bucket, String blob, BlobSourceOption... options); + BlobInfo get(String bucket, String blob, BlobSourceOption... options); /** * List the project's buckets. * * @throws StorageException upon failure */ - ListResult list(BucketListOption... options); + ListResult list(BucketListOption... options); /** * List the bucket's blobs. * * @throws StorageException upon failure */ - ListResult list(String bucket, BlobListOption... options); + ListResult list(String bucket, BlobListOption... options); /** * Update bucket information. @@ -517,7 +517,7 @@ public static Builder builder() { * @return the updated bucket * @throws StorageException upon failure */ - Bucket update(Bucket bucket, BucketTargetOption... options); + BucketInfo update(BucketInfo bucketInfo, BucketTargetOption... options); /** * Update blob information. @@ -525,7 +525,7 @@ public static Builder builder() { * @return the updated blob * @throws StorageException upon failure */ - Blob update(Blob blob, BlobTargetOption... options); + BlobInfo update(BlobInfo blobInfo, BlobTargetOption... options); /** * Delete the requested bucket. @@ -549,7 +549,7 @@ public static Builder builder() { * @return the composed blob. * @throws StorageException upon failure */ - Blob compose(ComposeRequest composeRequest); + BlobInfo compose(ComposeRequest composeRequest); /** * Send a copy request. @@ -557,7 +557,7 @@ public static Builder builder() { * @return the copied blob. * @throws StorageException upon failure */ - Blob copy(CopyRequest copyRequest); + BlobInfo copy(CopyRequest copyRequest); /** * Load the content of the given blob. @@ -587,7 +587,7 @@ public static Builder builder() { * * @throws StorageException upon failure */ - BlobWriteChannel writer(Blob blob, BlobTargetOption... options); + BlobWriteChannel writer(BlobInfo blobInfo, BlobTargetOption... options); /** * Generates a signed URL for a blob. @@ -597,9 +597,9 @@ public static Builder builder() { * This is particularly useful if you don't want publicly * accessible blobs, but don't want to require users to explicitly log in. * - * @param blob the blob associated with the signed url + * @param blobInfo the blob associated with the signed url * @param expirationTimeInSeconds the signed URL expiration (using epoch time) * @see Signed-URLs */ - URL signUrl(Blob blob, long expirationTimeInSeconds, SignUrlOption... options); + URL signUrl(BlobInfo blobInfo, long expirationTimeInSeconds, SignUrlOption... options); } 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 29db26481935..44c940f1c64a 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 @@ -99,10 +99,10 @@ public RetryResult beforeEval(Exception exception) { } @Override - public Bucket create(Bucket bucket, BucketTargetOption... options) { - final com.google.api.services.storage.model.Bucket bucketPb = bucket.toPb(); - final Map optionsMap = optionMap(bucket, options); - return Bucket.fromPb(runWithRetries( + public BucketInfo create(BucketInfo bucketInfo, BucketTargetOption... options) { + final com.google.api.services.storage.model.Bucket bucketPb = bucketInfo.toPb(); + final Map optionsMap = optionMap(bucketInfo, options); + return BucketInfo.fromPb(runWithRetries( new Callable() { @Override public com.google.api.services.storage.model.Bucket call() { @@ -112,10 +112,10 @@ public com.google.api.services.storage.model.Bucket call() { } @Override - public Blob create(Blob blob, final byte[] content, BlobTargetOption... options) { - final StorageObject blobPb = blob.toPb(); - final Map optionsMap = optionMap(blob, options); - return Blob.fromPb(runWithRetries(new Callable() { + public BlobInfo create(BlobInfo blobInfo, final byte[] content, BlobTargetOption... options) { + final StorageObject blobPb = blobInfo.toPb(); + final Map optionsMap = optionMap(blobInfo, options); + return BlobInfo.fromPb(runWithRetries(new Callable() { @Override public StorageObject call() { return storageRpc.create(blobPb, firstNonNull(content, EMPTY_BYTE_ARRAY), optionsMap); @@ -124,8 +124,8 @@ public StorageObject call() { } @Override - public Bucket get(String bucket, BucketSourceOption... options) { - final com.google.api.services.storage.model.Bucket bucketPb = Bucket.of(bucket).toPb(); + public BucketInfo get(String bucket, BucketSourceOption... options) { + final com.google.api.services.storage.model.Bucket bucketPb = BucketInfo.of(bucket).toPb(); final Map optionsMap = optionMap(options); com.google.api.services.storage.model.Bucket answer = runWithRetries( new Callable() { @@ -141,12 +141,12 @@ public com.google.api.services.storage.model.Bucket call() { } } }, options().retryParams(), EXCEPTION_HANDLER); - return answer == null ? null : Bucket.fromPb(answer); + return answer == null ? null : BucketInfo.fromPb(answer); } @Override - public Blob get(String bucket, String blob, BlobSourceOption... options) { - final StorageObject storedObject = Blob.of(bucket, blob).toPb(); + public BlobInfo get(String bucket, String blob, BlobSourceOption... options) { + final StorageObject storedObject = BlobInfo.of(bucket, blob).toPb(); final Map optionsMap = optionMap(options); StorageObject storageObject = runWithRetries(new Callable() { @Override @@ -161,7 +161,7 @@ public StorageObject call() { } } }, options().retryParams(), EXCEPTION_HANDLER); - return storageObject == null ? null : Blob.fromPb(storageObject); + return storageObject == null ? null : BlobInfo.fromPb(storageObject); } private static abstract class BasePageFetcher @@ -185,7 +185,7 @@ private static abstract class BasePageFetcher } } - private static class BucketPageFetcher extends BasePageFetcher { + private static class BucketPageFetcher extends BasePageFetcher { private static final long serialVersionUID = -5490616010200159174L; @@ -195,12 +195,12 @@ private static class BucketPageFetcher extends BasePageFetcher { } @Override - public ListResult nextPage() { + public ListResult nextPage() { return listBuckets(serviceOptions, requestOptions); } } - private static class BlobPageFetcher extends BasePageFetcher { + private static class BlobPageFetcher extends BasePageFetcher { private static final long serialVersionUID = -5490616010200159174L; private final String bucket; @@ -212,17 +212,17 @@ private static class BlobPageFetcher extends BasePageFetcher { } @Override - public ListResult nextPage() { + public ListResult nextPage() { return listBlobs(bucket, serviceOptions, requestOptions); } } @Override - public ListResult list(BucketListOption... options) { + public ListResult list(BucketListOption... options) { return listBuckets(options(), optionMap(options)); } - private static ListResult listBuckets(final StorageOptions serviceOptions, + private static ListResult listBuckets(final StorageOptions serviceOptions, final Map optionsMap) { Tuple> result = runWithRetries( new Callable>>() { @@ -234,20 +234,20 @@ public Tuple> cal String cursor = result.x(); return new ListResult<>(new BucketPageFetcher(serviceOptions, cursor, optionsMap), cursor, Iterables.transform(result.y(), - new Function() { + new Function() { @Override - public Bucket apply(com.google.api.services.storage.model.Bucket bucketPb) { - return Bucket.fromPb(bucketPb); + public BucketInfo apply(com.google.api.services.storage.model.Bucket bucketPb) { + return BucketInfo.fromPb(bucketPb); } })); } @Override - public ListResult list(final String bucket, BlobListOption... options) { + public ListResult list(final String bucket, BlobListOption... options) { return listBlobs(bucket, options(), optionMap(options)); } - private static ListResult listBlobs(final String bucket, + private static ListResult listBlobs(final String bucket, final StorageOptions serviceOptions, final Map optionsMap) { Tuple> result = runWithRetries( new Callable>>() { @@ -259,19 +259,19 @@ public Tuple> call() { String cursor = result.x(); return new ListResult<>(new BlobPageFetcher(bucket, serviceOptions, cursor, optionsMap), cursor, Iterables.transform(result.y(), - new Function() { + new Function() { @Override - public Blob apply(StorageObject storageObject) { - return Blob.fromPb(storageObject); + public BlobInfo apply(StorageObject storageObject) { + return BlobInfo.fromPb(storageObject); } })); } @Override - public Bucket update(Bucket bucket, BucketTargetOption... options) { - final com.google.api.services.storage.model.Bucket bucketPb = bucket.toPb(); - final Map optionsMap = optionMap(bucket, options); - return Bucket.fromPb(runWithRetries( + public BucketInfo update(BucketInfo bucketInfo, BucketTargetOption... options) { + final com.google.api.services.storage.model.Bucket bucketPb = bucketInfo.toPb(); + final Map optionsMap = optionMap(bucketInfo, options); + return BucketInfo.fromPb(runWithRetries( new Callable() { @Override public com.google.api.services.storage.model.Bucket call() { @@ -281,10 +281,10 @@ public com.google.api.services.storage.model.Bucket call() { } @Override - public Blob update(Blob blob, BlobTargetOption... options) { - final StorageObject storageObject = blob.toPb(); - final Map optionsMap = optionMap(blob, options); - return Blob.fromPb(runWithRetries(new Callable() { + public BlobInfo update(BlobInfo blobInfo, BlobTargetOption... options) { + final StorageObject storageObject = blobInfo.toPb(); + final Map optionsMap = optionMap(blobInfo, options); + return BlobInfo.fromPb(runWithRetries(new Callable() { @Override public StorageObject call() { return storageRpc.patch(storageObject, optionsMap); @@ -294,7 +294,7 @@ public StorageObject call() { @Override public boolean delete(String bucket, BucketSourceOption... options) { - final com.google.api.services.storage.model.Bucket bucketPb = Bucket.of(bucket).toPb(); + final com.google.api.services.storage.model.Bucket bucketPb = BucketInfo.of(bucket).toPb(); final Map optionsMap = optionMap(options); return runWithRetries(new Callable() { @Override @@ -306,7 +306,7 @@ public Boolean call() { @Override public boolean delete(String bucket, String blob, BlobSourceOption... options) { - final StorageObject storageObject = Blob.of(bucket, blob).toPb(); + final StorageObject storageObject = BlobInfo.of(bucket, blob).toPb(); final Map optionsMap = optionMap(options); return runWithRetries(new Callable() { @Override @@ -317,17 +317,17 @@ public Boolean call() { } @Override - public Blob compose(final ComposeRequest composeRequest) { + public BlobInfo compose(final ComposeRequest composeRequest) { final List sources = Lists.newArrayListWithCapacity(composeRequest.sourceBlobs().size()); for (ComposeRequest.SourceBlob sourceBlob : composeRequest.sourceBlobs()) { - sources.add(Blob.builder(composeRequest.target().bucket(), sourceBlob.name()) + sources.add(BlobInfo.builder(composeRequest.target().bucket(), sourceBlob.name()) .generation(sourceBlob.generation()).build().toPb()); } final StorageObject target = composeRequest.target().toPb(); final Map targetOptions = optionMap(composeRequest.target().generation(), composeRequest.target().metageneration(), composeRequest.targetOptions()); - return Blob.fromPb(runWithRetries(new Callable() { + return BlobInfo.fromPb(runWithRetries(new Callable() { @Override public StorageObject call() { return storageRpc.compose(sources, target, targetOptions); @@ -336,16 +336,16 @@ public StorageObject call() { } @Override - public Blob copy(CopyRequest copyRequest) { + public BlobInfo copy(CopyRequest copyRequest) { final StorageObject source = - Blob.of(copyRequest.sourceBucket(), copyRequest.sourceBlob()).toPb(); + BlobInfo.of(copyRequest.sourceBucket(), copyRequest.sourceBlob()).toPb(); copyRequest.sourceOptions(); final Map sourceOptions = optionMap(null, null, copyRequest.sourceOptions(), true); final StorageObject target = copyRequest.target().toPb(); final Map targetOptions = optionMap(copyRequest.target().generation(), copyRequest.target().metageneration(), copyRequest.targetOptions()); - return Blob.fromPb(runWithRetries(new Callable() { + return BlobInfo.fromPb(runWithRetries(new Callable() { @Override public StorageObject call() { return storageRpc.copy(source, sourceOptions, target, targetOptions); @@ -355,7 +355,7 @@ public StorageObject call() { @Override public byte[] load(String bucket, String blob, BlobSourceOption... options) { - final StorageObject storageObject = Blob.of(bucket, blob).toPb(); + final StorageObject storageObject = BlobInfo.of(bucket, blob).toPb(); final Map optionsMap = optionMap(options); return runWithRetries(new Callable() { @Override @@ -369,37 +369,37 @@ public byte[] call() { public BatchResponse apply(BatchRequest batchRequest) { List>> toDelete = Lists.newArrayListWithCapacity(batchRequest.toDelete().size()); - for (Map.Entry> entry : batchRequest.toDelete().entrySet()) { - Blob blob = entry.getKey(); + for (Map.Entry> entry : batchRequest.toDelete().entrySet()) { + BlobInfo blobInfo = entry.getKey(); Map optionsMap = - optionMap(blob.generation(), blob.metageneration(), entry.getValue()); - StorageObject storageObject = blob.toPb(); + optionMap(blobInfo.generation(), blobInfo.metageneration(), entry.getValue()); + StorageObject storageObject = blobInfo.toPb(); toDelete.add(Tuple.>of(storageObject, optionsMap)); } List>> toUpdate = Lists.newArrayListWithCapacity(batchRequest.toUpdate().size()); - for (Map.Entry> entry : batchRequest.toUpdate().entrySet()) { - Blob blob = entry.getKey(); + for (Map.Entry> entry : batchRequest.toUpdate().entrySet()) { + BlobInfo blobInfo = entry.getKey(); Map optionsMap = - optionMap(blob.generation(), blob.metageneration(), entry.getValue()); - toUpdate.add(Tuple.>of(blob.toPb(), optionsMap)); + optionMap(blobInfo.generation(), blobInfo.metageneration(), entry.getValue()); + toUpdate.add(Tuple.>of(blobInfo.toPb(), optionsMap)); } List>> toGet = Lists.newArrayListWithCapacity(batchRequest.toGet().size()); - for (Map.Entry> entry : batchRequest.toGet().entrySet()) { - Blob blob = entry.getKey(); + for (Map.Entry> entry : batchRequest.toGet().entrySet()) { + BlobInfo blobInfo = entry.getKey(); Map optionsMap = - optionMap(blob.generation(), blob.metageneration(), entry.getValue()); - toGet.add(Tuple.>of(blob.toPb(), optionsMap)); + optionMap(blobInfo.generation(), blobInfo.metageneration(), entry.getValue()); + toGet.add(Tuple.>of(blobInfo.toPb(), optionsMap)); } StorageRpc.BatchResponse response = storageRpc.batch(new StorageRpc.BatchRequest(toDelete, toUpdate, toGet)); List> deletes = transformBatchResult( toDelete, response.deletes, Functions.identity()); - List> updates = transformBatchResult( - toUpdate, response.updates, Blob.FROM_PB_FUNCTION); - List> gets = transformBatchResult( - toGet, response.gets, Blob.FROM_PB_FUNCTION, HTTP_NOT_FOUND); + List> updates = transformBatchResult( + toUpdate, response.updates, BlobInfo.FROM_PB_FUNCTION); + List> gets = transformBatchResult( + toGet, response.gets, BlobInfo.FROM_PB_FUNCTION, HTTP_NOT_FOUND); return new BatchResponse(deletes, updates, gets); } @@ -429,17 +429,17 @@ private List> transformBatch @Override public BlobReadChannel reader(String bucket, String blob, BlobSourceOption... options) { Map optionsMap = optionMap(options); - return new BlobReadChannelImpl(options(), Blob.of(bucket, blob), optionsMap); + return new BlobReadChannelImpl(options(), BlobInfo.of(bucket, blob), optionsMap); } @Override - public BlobWriteChannel writer(Blob blob, BlobTargetOption... options) { - final Map optionsMap = optionMap(blob, options); - return new BlobWriterChannelImpl(options(), blob, optionsMap); + public BlobWriteChannel writer(BlobInfo blobInfo, BlobTargetOption... options) { + final Map optionsMap = optionMap(blobInfo, options); + return new BlobWriterChannelImpl(options(), blobInfo, optionsMap); } @Override - public URL signUrl(Blob blob, long expiration, SignUrlOption... options) { + public URL signUrl(BlobInfo blobInfo, long expiration, SignUrlOption... options) { EnumMap optionMap = Maps.newEnumMap(SignUrlOption.Option.class); for (SignUrlOption option : options) { optionMap.put(option.option(), option.value()); @@ -460,28 +460,28 @@ public URL signUrl(Blob blob, long expiration, SignUrlOption... options) { } stBuilder.append('\n'); if (firstNonNull((Boolean) optionMap.get(SignUrlOption.Option.MD5) , false)) { - checkArgument(blob.md5() != null, "Blob is missing a value for md5"); - stBuilder.append(blob.md5()); + checkArgument(blobInfo.md5() != null, "Blob is missing a value for md5"); + stBuilder.append(blobInfo.md5()); } stBuilder.append('\n'); if (firstNonNull((Boolean) optionMap.get(SignUrlOption.Option.CONTENT_TYPE) , false)) { - checkArgument(blob.contentType() != null, "Blob is missing a value for content-type"); - stBuilder.append(blob.contentType()); + checkArgument(blobInfo.contentType() != null, "Blob is missing a value for content-type"); + stBuilder.append(blobInfo.contentType()); } stBuilder.append('\n'); stBuilder.append(expiration).append('\n'); StringBuilder path = new StringBuilder(); - if (!blob.bucket().startsWith("/")) { + if (!blobInfo.bucket().startsWith("/")) { path.append('/'); } - path.append(blob.bucket()); - if (!blob.bucket().endsWith("/")) { + path.append(blobInfo.bucket()); + if (!blobInfo.bucket().endsWith("/")) { path.append('/'); } - if (blob.name().startsWith("/")) { + if (blobInfo.name().startsWith("/")) { path.setLength(stBuilder.length() - 1); } - path.append(blob.name()); + path.append(blobInfo.name()); stBuilder.append(path); try { Signature signer = Signature.getInstance("SHA256withRSA"); @@ -558,11 +558,11 @@ private static void addToOptionMap(StorageRpc.Option getOption, StorageRpc.O return optionMap(generation, metaGeneration, Arrays.asList(options)); } - private Map optionMap(Bucket bucket, Option... options) { - return optionMap(null, bucket.metageneration(), options); + private Map optionMap(BucketInfo bucketInfo, Option... options) { + return optionMap(null, bucketInfo.metageneration(), options); } - private Map optionMap(Blob blob, Option... options) { - return optionMap(blob.generation(), blob.metageneration(), options); + private Map optionMap(BlobInfo blobInfo, Option... options) { + return optionMap(blobInfo.generation(), blobInfo.metageneration(), 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 c648ea88e39d..f689d264a828 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 @@ -22,9 +22,9 @@ * StorageOptions options = StorageOptions.builder().projectId("project").build(); * Storage storage = StorageFactory.instance().get(options); * byte[] content = readContent(); - * Blob blob = storage.get("bucket", "blob_name"); - * if (blob == null) { - * storage.create(Blob.of("bucket", "blob_name"), content); + * BlobInfo blobInfo = storage.get("bucket", "blob_name"); + * if (blobInfo == null) { + * storage.create(BlobInfo.of("bucket", "blob_name"), content); * } else { * byte[] prevContent = storage.load("bucket", "blob_name"); * content = mergeContent(prevContent, content); diff --git a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BatchRequestTest.java b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BatchRequestTest.java index 29be5b87e08f..9cafd64afaa8 100644 --- a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BatchRequestTest.java +++ b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BatchRequestTest.java @@ -38,47 +38,47 @@ public void testBatchRequest() { .delete("b1", "o1") .delete("b1", "o2", BlobSourceOption.generationMatch(1), BlobSourceOption.metagenerationMatch(2)) - .update(Blob.of("b2", "o1"), BlobTargetOption.predefinedAcl(PUBLIC_READ)) - .update(Blob.of("b2", "o2")) + .update(BlobInfo.of("b2", "o1"), BlobTargetOption.predefinedAcl(PUBLIC_READ)) + .update(BlobInfo.of("b2", "o2")) .get("b3", "o1") .get("b3", "o2", BlobSourceOption.generationMatch(1)) .get("b3", "o3") .build(); - Iterator>> deletes = request + Iterator>> deletes = request .toDelete().entrySet().iterator(); - Entry> delete = deletes.next(); - assertEquals(Blob.of("b1", "o1"), delete.getKey()); + Entry> delete = deletes.next(); + assertEquals(BlobInfo.of("b1", "o1"), delete.getKey()); assertTrue(Iterables.isEmpty(delete.getValue())); delete = deletes.next(); - assertEquals(Blob.of("b1", "o2"), delete.getKey()); + assertEquals(BlobInfo.of("b1", "o2"), delete.getKey()); assertEquals(2, Iterables.size(delete.getValue())); assertFalse(deletes.hasNext()); - Iterator>> updates = request + Iterator>> updates = request .toUpdate().entrySet().iterator(); - Entry> update = updates.next(); - assertEquals(Blob.of("b2", "o1"), update.getKey()); + Entry> update = updates.next(); + assertEquals(BlobInfo.of("b2", "o1"), update.getKey()); assertEquals(1, Iterables.size(update.getValue())); assertEquals(BlobTargetOption.predefinedAcl(PUBLIC_READ), Iterables.getFirst(update.getValue(), null)); update = updates.next(); - assertEquals(Blob.of("b2", "o2"), update.getKey()); + assertEquals(BlobInfo.of("b2", "o2"), update.getKey()); assertTrue(Iterables.isEmpty(update.getValue())); assertFalse(updates.hasNext()); - Iterator>> gets = request + Iterator>> gets = request .toGet().entrySet().iterator(); - Entry> get = gets.next(); - assertEquals(Blob.of("b3", "o1"), get.getKey()); + Entry> get = gets.next(); + assertEquals(BlobInfo.of("b3", "o1"), get.getKey()); assertTrue(Iterables.isEmpty(get.getValue())); get = gets.next(); - assertEquals(Blob.of("b3", "o2"), get.getKey()); + assertEquals(BlobInfo.of("b3", "o2"), get.getKey()); assertEquals(1, Iterables.size(get.getValue())); assertEquals(BlobSourceOption.generationMatch(1), Iterables.getFirst(get.getValue(), null)); get = gets.next(); - assertEquals(Blob.of("b3", "o3"), get.getKey()); + assertEquals(BlobInfo.of("b3", "o3"), get.getKey()); assertTrue(Iterables.isEmpty(get.getValue())); assertFalse(gets.hasNext()); } diff --git a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BatchResponseTest.java b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BatchResponseTest.java index 277c46860ef1..7e774a77c739 100644 --- a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BatchResponseTest.java +++ b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BatchResponseTest.java @@ -27,15 +27,15 @@ public class BatchResponseTest { - private static final Blob BLOB1 = Blob.of("b", "o1"); - private static final Blob BLOB2 = Blob.of("b", "o2"); - private static final Blob BLOB3 = Blob.of("b", "o3"); + private static final BlobInfo BLOB_INFO_1 = BlobInfo.of("b", "o1"); + private static final BlobInfo BLOB_INFO_2 = BlobInfo.of("b", "o2"); + private static final BlobInfo BLOB_INFO_3 = BlobInfo.of("b", "o3"); @Test public void testBatchResponse() { List> deletes = ImmutableList.of(Result.of(true), Result.of(false)); - List> updates = ImmutableList.of(Result.of(BLOB1), Result.of(BLOB2)); - List> gets = ImmutableList.of(Result.of(BLOB2), Result.of(BLOB3)); + List> updates = ImmutableList.of(Result.of(BLOB_INFO_1), Result.of(BLOB_INFO_2)); + List> gets = ImmutableList.of(Result.of(BLOB_INFO_2), Result.of(BLOB_INFO_3)); BatchResponse response = new BatchResponse(deletes, updates, gets); assertEquals(deletes, response.deletes()); diff --git a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BlobTest.java b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BlobInfoTest.java similarity index 70% rename from gcloud-java-storage/src/test/java/com/google/gcloud/storage/BlobTest.java rename to gcloud-java-storage/src/test/java/com/google/gcloud/storage/BlobInfoTest.java index 6fb8f0243987..018a59c9cfc4 100644 --- a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BlobTest.java +++ b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BlobInfoTest.java @@ -31,7 +31,7 @@ import java.util.List; import java.util.Map; -public class BlobTest { +public class BlobInfoTest { private static final List ACL = ImmutableList.of( new Acl(User.ofAllAuthenticatedUsers(), READER), @@ -55,7 +55,7 @@ public class BlobTest { private static final String SELF_LINK = "http://storage/b/n"; private static final Long SIZE = 1024L; private static final Long UPDATE_TIME = DELETE_TIME - 1L; - private static final Blob BLOB = Blob.builder("b", "n") + private static final BlobInfo BLOB_INFO = BlobInfo.builder("b", "n") .acl(ACL) .componentCount(COMPONENT_COUNT) .contentType(CONTENT_TYPE) @@ -80,49 +80,49 @@ public class BlobTest { @Test public void testToBuilder() { - compareBlobs(BLOB, BLOB.toBuilder().build()); - Blob blob = BLOB.toBuilder().name("n2").bucket("b2").size(200L).build(); - assertEquals("n2", blob.name()); - assertEquals("b2", blob.bucket()); - assertEquals(Long.valueOf(200), blob.size()); - blob = blob.toBuilder().name("n").bucket("b").size(SIZE).build(); - compareBlobs(BLOB, blob); + compareBlobs(BLOB_INFO, BLOB_INFO.toBuilder().build()); + BlobInfo blobInfo = BLOB_INFO.toBuilder().name("n2").bucket("b2").size(200L).build(); + assertEquals("n2", blobInfo.name()); + assertEquals("b2", blobInfo.bucket()); + assertEquals(Long.valueOf(200), blobInfo.size()); + blobInfo = blobInfo.toBuilder().name("n").bucket("b").size(SIZE).build(); + compareBlobs(BLOB_INFO, blobInfo); } @Test public void testOf() { - Blob blob = Blob.of("b", "n"); - assertEquals("b", blob.bucket()); - assertEquals("n", blob.name()); + BlobInfo blobInfo = BlobInfo.of("b", "n"); + assertEquals("b", blobInfo.bucket()); + assertEquals("n", blobInfo.name()); } @Test public void testBuilder() { - assertEquals("b", BLOB.bucket()); - assertEquals("n", BLOB.name()); - assertEquals(ACL, BLOB.acl()); - assertEquals(COMPONENT_COUNT, BLOB.componentCount()); - assertEquals(CONTENT_TYPE, BLOB.contentType()); - assertEquals(CACHE_CONTROL, BLOB.cacheControl() ); - assertEquals(CONTENT_DISPOSITION, BLOB.contentDisposition()); - assertEquals(CONTENT_ENCODING, BLOB.contentEncoding()); - assertEquals(CONTENT_LANGUAGE, BLOB.contentLanguage()); - assertEquals(CRC32, BLOB.crc32c()); - assertEquals(DELETE_TIME, BLOB.deleteTime()); - assertEquals(ETAG, BLOB.etag()); - assertEquals(GENERATION, BLOB.generation()); - assertEquals(ID, BLOB.id()); - assertEquals(MD5, BLOB.md5()); - assertEquals(MEDIA_LINK, BLOB.mediaLink()); - assertEquals(METADATA, BLOB.metadata()); - assertEquals(META_GENERATION, BLOB.metageneration()); - assertEquals(OWNER, BLOB.owner()); - assertEquals(SELF_LINK, BLOB.selfLink()); - assertEquals(SIZE, BLOB.size()); - assertEquals(UPDATE_TIME, BLOB.updateTime()); + assertEquals("b", BLOB_INFO.bucket()); + assertEquals("n", BLOB_INFO.name()); + assertEquals(ACL, BLOB_INFO.acl()); + assertEquals(COMPONENT_COUNT, BLOB_INFO.componentCount()); + assertEquals(CONTENT_TYPE, BLOB_INFO.contentType()); + assertEquals(CACHE_CONTROL, BLOB_INFO.cacheControl() ); + assertEquals(CONTENT_DISPOSITION, BLOB_INFO.contentDisposition()); + assertEquals(CONTENT_ENCODING, BLOB_INFO.contentEncoding()); + assertEquals(CONTENT_LANGUAGE, BLOB_INFO.contentLanguage()); + assertEquals(CRC32, BLOB_INFO.crc32c()); + assertEquals(DELETE_TIME, BLOB_INFO.deleteTime()); + assertEquals(ETAG, BLOB_INFO.etag()); + assertEquals(GENERATION, BLOB_INFO.generation()); + assertEquals(ID, BLOB_INFO.id()); + assertEquals(MD5, BLOB_INFO.md5()); + assertEquals(MEDIA_LINK, BLOB_INFO.mediaLink()); + assertEquals(METADATA, BLOB_INFO.metadata()); + assertEquals(META_GENERATION, BLOB_INFO.metageneration()); + assertEquals(OWNER, BLOB_INFO.owner()); + assertEquals(SELF_LINK, BLOB_INFO.selfLink()); + assertEquals(SIZE, BLOB_INFO.size()); + assertEquals(UPDATE_TIME, BLOB_INFO.updateTime()); } - private void compareBlobs(Blob expected, Blob value) { + private void compareBlobs(BlobInfo expected, BlobInfo value) { assertEquals(expected, value); assertEquals(expected.bucket(), value.bucket()); assertEquals(expected.name(), value.name()); @@ -150,6 +150,6 @@ private void compareBlobs(Blob expected, Blob value) { @Test public void testToPbAndFromPb() { - compareBlobs(BLOB, Blob.fromPb(BLOB.toPb())); + compareBlobs(BLOB_INFO, BlobInfo.fromPb(BLOB_INFO.toPb())); } } diff --git a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BucketTest.java b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BucketInfoTest.java similarity index 72% rename from gcloud-java-storage/src/test/java/com/google/gcloud/storage/BucketTest.java rename to gcloud-java-storage/src/test/java/com/google/gcloud/storage/BucketInfoTest.java index c095a6291e49..27a5b4014f3f 100644 --- a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BucketTest.java +++ b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BucketInfoTest.java @@ -26,22 +26,22 @@ import com.google.gcloud.storage.Acl.Project; import com.google.gcloud.storage.Acl.Role; import com.google.gcloud.storage.Acl.User; -import com.google.gcloud.storage.Bucket.AgeDeleteRule; -import com.google.gcloud.storage.Bucket.CreatedBeforeDeleteRule; -import com.google.gcloud.storage.Bucket.DeleteRule; -import com.google.gcloud.storage.Bucket.DeleteRule.Type; -import com.google.gcloud.storage.Bucket.IsLiveDeleteRule; -import com.google.gcloud.storage.Bucket.Location; -import com.google.gcloud.storage.Bucket.NumNewerVersionsDeleteRule; -import com.google.gcloud.storage.Bucket.RawDeleteRule; -import com.google.gcloud.storage.Bucket.StorageClass; +import com.google.gcloud.storage.BucketInfo.AgeDeleteRule; +import com.google.gcloud.storage.BucketInfo.CreatedBeforeDeleteRule; +import com.google.gcloud.storage.BucketInfo.DeleteRule; +import com.google.gcloud.storage.BucketInfo.DeleteRule.Type; +import com.google.gcloud.storage.BucketInfo.IsLiveDeleteRule; +import com.google.gcloud.storage.BucketInfo.Location; +import com.google.gcloud.storage.BucketInfo.NumNewerVersionsDeleteRule; +import com.google.gcloud.storage.BucketInfo.RawDeleteRule; +import com.google.gcloud.storage.BucketInfo.StorageClass; import org.junit.Test; import java.util.Collections; import java.util.List; -public class BucketTest { +public class BucketInfoTest { private static final List ACL = ImmutableList.of( new Acl(User.ofAllAuthenticatedUsers(), Role.READER), @@ -62,7 +62,7 @@ public class BucketTest { private static final Location LOCATION = Location.asia(); private static final StorageClass STORAGE_CLASS = StorageClass.standard(); private static final Boolean VERSIONING_ENABLED = true; - private static final Bucket BUCKET = Bucket.builder("b") + private static final BucketInfo BUCKET_INFO = BucketInfo.builder("b") .acl(ACL) .etag(ETAG) .id(ID) @@ -82,46 +82,46 @@ public class BucketTest { @Test public void testToBuilder() { - compareBuckets(BUCKET, BUCKET.toBuilder().build()); - Bucket bucket = BUCKET.toBuilder().name("B").id("id").build(); - assertEquals("B", bucket.name()); - assertEquals("id", bucket.id()); - bucket = bucket.toBuilder().name("b").id(ID).build(); - compareBuckets(BUCKET, bucket); + compareBuckets(BUCKET_INFO, BUCKET_INFO.toBuilder().build()); + BucketInfo bucketInfo = BUCKET_INFO.toBuilder().name("B").id("id").build(); + assertEquals("B", bucketInfo.name()); + assertEquals("id", bucketInfo.id()); + bucketInfo = bucketInfo.toBuilder().name("b").id(ID).build(); + compareBuckets(BUCKET_INFO, bucketInfo); } @Test public void testOf() { - Bucket bucket = Bucket.of("bucket"); - assertEquals("bucket", bucket.name()); + BucketInfo bucketInfo = BucketInfo.of("bucket"); + assertEquals("bucket", bucketInfo.name()); } @Test public void testBuilder() { - assertEquals("b", BUCKET.name()); - assertEquals(ACL, BUCKET.acl()); - assertEquals(ETAG, BUCKET.etag()); - assertEquals(ID, BUCKET.id()); - assertEquals(META_GENERATION, BUCKET.metageneration()); - assertEquals(OWNER, BUCKET.owner()); - assertEquals(SELF_LINK, BUCKET.selfLink()); - assertEquals(CREATE_TIME, BUCKET.createTime()); - assertEquals(CORS, BUCKET.cors()); - assertEquals(DEFAULT_ACL, BUCKET.defaultAcl()); - assertEquals(DELETE_RULES, BUCKET.deleteRules()); - assertEquals(INDEX_PAGE, BUCKET.indexPage()); - assertEquals(NOT_FOUND_PAGE, BUCKET.notFoundPage()); - assertEquals(LOCATION, BUCKET.location()); - assertEquals(STORAGE_CLASS, BUCKET.storageClass()); - assertEquals(VERSIONING_ENABLED, BUCKET.versioningEnabled()); + assertEquals("b", BUCKET_INFO.name()); + assertEquals(ACL, BUCKET_INFO.acl()); + assertEquals(ETAG, BUCKET_INFO.etag()); + assertEquals(ID, BUCKET_INFO.id()); + assertEquals(META_GENERATION, BUCKET_INFO.metageneration()); + assertEquals(OWNER, BUCKET_INFO.owner()); + assertEquals(SELF_LINK, BUCKET_INFO.selfLink()); + assertEquals(CREATE_TIME, BUCKET_INFO.createTime()); + assertEquals(CORS, BUCKET_INFO.cors()); + assertEquals(DEFAULT_ACL, BUCKET_INFO.defaultAcl()); + assertEquals(DELETE_RULES, BUCKET_INFO.deleteRules()); + assertEquals(INDEX_PAGE, BUCKET_INFO.indexPage()); + assertEquals(NOT_FOUND_PAGE, BUCKET_INFO.notFoundPage()); + assertEquals(LOCATION, BUCKET_INFO.location()); + assertEquals(STORAGE_CLASS, BUCKET_INFO.storageClass()); + assertEquals(VERSIONING_ENABLED, BUCKET_INFO.versioningEnabled()); } @Test public void testToPbAndFromPb() { - compareBuckets(BUCKET, Bucket.fromPb(BUCKET.toPb())); + compareBuckets(BUCKET_INFO, BucketInfo.fromPb(BUCKET_INFO.toPb())); } - private void compareBuckets(Bucket expected, Bucket value) { + private void compareBuckets(BucketInfo expected, BucketInfo value) { assertEquals(expected, value); assertEquals(expected.name(), value.name()); assertEquals(expected.acl(), value.acl()); diff --git a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/SerializationTest.java b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/SerializationTest.java index d765b0189c96..e79163da3a7e 100644 --- a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/SerializationTest.java +++ b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/SerializationTest.java @@ -40,18 +40,18 @@ public class SerializationTest { private static final Acl.Project ACL_PROJECT_ = new Acl.Project(ProjectRole.VIEWERS, "pid"); private static final Acl.User ACL_USER = new Acl.User("user"); private static final Acl.RawEntity ACL_RAW = new Acl.RawEntity("raw"); - private static final Blob BLOB = Blob.of("b", "n"); - private static final Bucket BUCKET = Bucket.of("b"); + private static final BlobInfo BLOB_INFO = BlobInfo.of("b", "n"); + private static final BucketInfo BUCKET_INFO = BucketInfo.of("b"); private static final Cors.Origin ORIGIN = Cors.Origin.any(); private static final Cors CORS = Cors.builder().maxAgeSeconds(1).origins(Collections.singleton(ORIGIN)).build(); private static final BatchRequest BATCH_REQUEST = BatchRequest.builder().delete("B", "N").build(); private static final BatchResponse BATCH_RESPONSE = new BatchResponse( Collections.singletonList(BatchResponse.Result.of(true)), - Collections.>emptyList(), - Collections.>emptyList()); - private static final ListResult LIST_RESULT = - new ListResult<>(null, "c", Collections.singletonList(Blob.of("b", "n"))); + Collections.>emptyList(), + Collections.>emptyList()); + private static final ListResult LIST_RESULT = + new ListResult<>(null, "c", Collections.singletonList(BlobInfo.of("b", "n"))); private static Storage.BlobListOption BLOB_LIST_OPTIONS = Storage.BlobListOption.maxResults(100); private static Storage.BlobSourceOption BLOB_SOURCE_OPTIONS = @@ -86,7 +86,8 @@ public void testServiceOptions() throws Exception { @Test public void testModelAndRequests() throws Exception { - Serializable[] objects = {ACL_DOMAIN, ACL_GROUP, ACL_PROJECT_, ACL_USER, ACL_RAW, BLOB, BUCKET, + Serializable[] objects = {ACL_DOMAIN, ACL_GROUP, ACL_PROJECT_, ACL_USER, ACL_RAW, BLOB_INFO, + BUCKET_INFO, ORIGIN, CORS, BATCH_REQUEST,BATCH_RESPONSE, LIST_RESULT, BLOB_LIST_OPTIONS, BLOB_SOURCE_OPTIONS, BLOB_TARGET_OPTIONS, BUCKET_LIST_OPTIONS, BUCKET_SOURCE_OPTIONS, BUCKET_TARGET_OPTIONS};