Skip to content

Commit c5fbd22

Browse files
committed
---
yaml --- r: 5969 b: refs/heads/tswast-patch-1 c: dc253c4 h: refs/heads/master i: 5967: 0a8c650
1 parent 6b3e7d6 commit c5fbd22

7 files changed

Lines changed: 32 additions & 4 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,5 @@ refs/tags/v0.18.0: 9d193c4c4b9d1c6f21515dd8e50836b9194ec9bb
5757
refs/tags/v0.19.0: e67b56e4d8dad5f9a7b38c9b2107c23c828f2ed5
5858
refs/tags/v0.20.0: 839f7fb7156535146aa1cb2c5aadd8d375d854e8
5959
refs/tags/v0.20.1: 370471f437f1f4f68a11e068df5cd6bf39edb1fa
60-
refs/heads/tswast-patch-1: bf089292e2926f32ec3a38153a0aaef14ff2752d
60+
refs/heads/tswast-patch-1: dc253c4f2798aac21c145f7bbe68fab93b438af7
6161
refs/heads/pubsub-streaming-pull: 19262b752ee874eb2ca3b950eb2aef44d5a5267b

branches/tswast-patch-1/src/main/java/com/google/gcloud/datastore/DatastoreServiceOptions.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,10 @@ DatastoreRpc datastoreRpc() {
199199
return ServiceRpcProvider.datastore(this);
200200
}
201201

202+
public static DatastoreServiceOptions defaultIntance() {
203+
return builder().build();
204+
}
205+
202206
public static Builder builder() {
203207
return new Builder();
204208
}

branches/tswast-patch-1/src/main/java/com/google/gcloud/examples/StorageExample.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.google.gcloud.storage.BatchResponse;
2424
import com.google.gcloud.storage.Blob;
2525
import com.google.gcloud.storage.BlobReadChannel;
26+
import com.google.gcloud.storage.BlobWriteChannel;
2627
import com.google.gcloud.storage.Bucket;
2728
import com.google.gcloud.storage.StorageService;
2829
import com.google.gcloud.storage.StorageService.ComposeRequest;
@@ -311,6 +312,15 @@ public static void printUsage() {
311312
@SuppressWarnings("unchecked")
312313
public static void main(String... args) throws Exception {
313314
if (args.length < 1) {
315+
316+
System.out.println("KOKO.start -------------------------------");
317+
StorageService storage =
318+
StorageServiceFactory.instance().get(StorageServiceOptions.defaultInstnace());
319+
BlobWriteChannel writer = storage
320+
.writer(Blob.of("ozarov-javamrsample.appspot.com", "bla"));
321+
writer.write(ByteBuffer.wrap("hello world".getBytes()));
322+
writer.close();
323+
System.out.println("KOKO.end -------------------------------");
314324
System.out.println("Missing required project id and action");
315325
printUsage();
316326
return;

branches/tswast-patch-1/src/main/java/com/google/gcloud/spi/DefaultStorageRpc.java

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

branches/tswast-patch-1/src/main/java/com/google/gcloud/spi/StorageRpc.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
/* * Copyright 2015 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package com.google.gcloud.spi;import com.google.api.services.storage.model.Bucket;import com.google.api.services.storage.model.StorageObject;import com.google.common.collect.ImmutableList;import com.google.common.collect.ImmutableMap;import com.google.gcloud.storage.StorageServiceException;import java.util.List;import java.util.Map;public interface StorageRpc { enum Option { PREDEFINED_ACL("predefinedAcl"), PREDEFINED_DEFAULT_OBJECT_ACL("predefinedDefaultObjectAcl"), IF_METAGENERATION_MATCH("ifMetagenerationMatch"), IF_METAGENERATION_NOT_MATCH("ifMetagenerationNotMatch"), IF_GENERATION_NOT_MATCH("ifGenerationMatch"), IF_GENERATION_MATCH("ifGenerationNotMatch"), IF_SOURCE_METAGENERATION_MATCH("ifSourceMetagenerationMatch"), IF_SOURCE_METAGENERATION_NOT_MATCH("ifSourceMetagenerationNotMatch"), IF_SOURCE_GENERATION_MATCH("ifSourceGenerationMatch"), IF_SOURCE_GENERATION_NOT_MATCH("ifSourceGenerationNotMatch"), PREFIX("prefix"), MAX_RESULTS("maxResults"), PAGE_TOKEN("pageToken"), DELIMITER("delimiter"), VERSIONS("versions"); private final String value; Option(String value) { this.value = value; } public String value() { return value; } @SuppressWarnings("unchecked") <T> T get(Map<Option, ?> options) { return (T) options.get(this); } String getString(Map<Option, ?> options) { return get(options); } Long getLong(Map<Option, ?> options) { return get(options); } Boolean getBoolean(Map<Option, ?> options) { return get(options); } } class Tuple<X, Y> { private final X x; private final Y y; private Tuple(X x, Y y) { this.x = x; this.y = y; } public static <X, Y> Tuple<X, Y> of(X x, Y y) { return new Tuple<>(x, y); } public X x() { return x; } public Y y() { return y; } } class BatchRequest { public final List<Tuple<StorageObject, Map<Option, ?>>> toDelete; public final List<Tuple<StorageObject, Map<Option, ?>>> toUpdate; public final List<Tuple<StorageObject, Map<Option, ?>>> toGet; public BatchRequest(Iterable<Tuple<StorageObject, Map<Option, ?>>> toDelete, Iterable<Tuple<StorageObject, Map<Option, ?>>> toUpdate, Iterable<Tuple<StorageObject, Map<Option, ?>>> toGet) { this.toDelete = ImmutableList.copyOf(toDelete); this.toUpdate = ImmutableList.copyOf(toUpdate); this.toGet = ImmutableList.copyOf(toGet); } } class BatchResponse { public final Map<StorageObject, Tuple<Boolean, StorageServiceException>> deletes; public final Map<StorageObject, Tuple<StorageObject, StorageServiceException>> updates; public final Map<StorageObject, Tuple<StorageObject, StorageServiceException>> gets; public BatchResponse(Map<StorageObject, Tuple<Boolean, StorageServiceException>> deletes, Map<StorageObject, Tuple<StorageObject, StorageServiceException>> updates, Map<StorageObject, Tuple<StorageObject, StorageServiceException>> gets) { this.deletes = ImmutableMap.copyOf(deletes); this.updates = ImmutableMap.copyOf(updates); this.gets = ImmutableMap.copyOf(gets); } } Bucket create(Bucket bucket, Map<Option, ?> options) throws StorageServiceException; StorageObject create(StorageObject object, byte[] content, Map<Option, ?> options) throws StorageServiceException; Tuple<String, Iterable<Bucket>> list(Map<Option, ?> options) throws StorageServiceException; Tuple<String, Iterable<StorageObject>> list(String bucket, Map<Option, ?> options) throws StorageServiceException; Bucket get(Bucket bucket, Map<Option, ?> options) throws StorageServiceException; StorageObject get(StorageObject object, Map<Option, ?> options) throws StorageServiceException; Bucket patch(Bucket bucket, Map<Option, ?> options) throws StorageServiceException; StorageObject patch(StorageObject storageObject, Map<Option, ?> options) throws StorageServiceException; boolean delete(Bucket bucket, Map<Option, ?> options) throws StorageServiceException; boolean delete(StorageObject object, Map<Option, ?> options) throws StorageServiceException; BatchResponse batch(BatchRequest request) throws StorageServiceException; StorageObject compose(Iterable<StorageObject> sources, StorageObject target, Map<Option, ?> targetOptions) throws StorageServiceException; StorageObject copy(StorageObject source, Map<Option, ?> sourceOptions, StorageObject target, Map<Option, ?> targetOptions) throws StorageServiceException; byte[] load(StorageObject storageObject, Map<Option, ?> options) throws StorageServiceException; byte[] read(StorageObject from, Map<Option, ?> options, int position, int bytes) throws StorageServiceException; String write(byte[] bytes, StorageObject to, Map<Option, ?> options) throws StorageServiceException; void append(byte[] bytes, StorageObject to, String uploadId, int position, boolean last) throws StorageServiceException;}
1+
/* * Copyright 2015 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package com.google.gcloud.spi;import com.google.api.services.storage.model.Bucket;import com.google.api.services.storage.model.StorageObject;import com.google.common.collect.ImmutableList;import com.google.common.collect.ImmutableMap;import com.google.gcloud.storage.StorageServiceException;import java.util.List;import java.util.Map;public interface StorageRpc { enum Option { PREDEFINED_ACL("predefinedAcl"), PREDEFINED_DEFAULT_OBJECT_ACL("predefinedDefaultObjectAcl"), IF_METAGENERATION_MATCH("ifMetagenerationMatch"), IF_METAGENERATION_NOT_MATCH("ifMetagenerationNotMatch"), IF_GENERATION_NOT_MATCH("ifGenerationMatch"), IF_GENERATION_MATCH("ifGenerationNotMatch"), IF_SOURCE_METAGENERATION_MATCH("ifSourceMetagenerationMatch"), IF_SOURCE_METAGENERATION_NOT_MATCH("ifSourceMetagenerationNotMatch"), IF_SOURCE_GENERATION_MATCH("ifSourceGenerationMatch"), IF_SOURCE_GENERATION_NOT_MATCH("ifSourceGenerationNotMatch"), PREFIX("prefix"), MAX_RESULTS("maxResults"), PAGE_TOKEN("pageToken"), DELIMITER("delimiter"), VERSIONS("versions"); private final String value; Option(String value) { this.value = value; } public String value() { return value; } @SuppressWarnings("unchecked") <T> T get(Map<Option, ?> options) { return (T) options.get(this); } String getString(Map<Option, ?> options) { return get(options); } Long getLong(Map<Option, ?> options) { return get(options); } Boolean getBoolean(Map<Option, ?> options) { return get(options); } } class Tuple<X, Y> { private final X x; private final Y y; private Tuple(X x, Y y) { this.x = x; this.y = y; } public static <X, Y> Tuple<X, Y> of(X x, Y y) { return new Tuple<>(x, y); } public X x() { return x; } public Y y() { return y; } } class BatchRequest { public final List<Tuple<StorageObject, Map<Option, ?>>> toDelete; public final List<Tuple<StorageObject, Map<Option, ?>>> toUpdate; public final List<Tuple<StorageObject, Map<Option, ?>>> toGet; public BatchRequest(Iterable<Tuple<StorageObject, Map<Option, ?>>> toDelete, Iterable<Tuple<StorageObject, Map<Option, ?>>> toUpdate, Iterable<Tuple<StorageObject, Map<Option, ?>>> toGet) { this.toDelete = ImmutableList.copyOf(toDelete); this.toUpdate = ImmutableList.copyOf(toUpdate); this.toGet = ImmutableList.copyOf(toGet); } } class BatchResponse { public final Map<StorageObject, Tuple<Boolean, StorageServiceException>> deletes; public final Map<StorageObject, Tuple<StorageObject, StorageServiceException>> updates; public final Map<StorageObject, Tuple<StorageObject, StorageServiceException>> gets; public BatchResponse(Map<StorageObject, Tuple<Boolean, StorageServiceException>> deletes, Map<StorageObject, Tuple<StorageObject, StorageServiceException>> updates, Map<StorageObject, Tuple<StorageObject, StorageServiceException>> gets) { this.deletes = ImmutableMap.copyOf(deletes); this.updates = ImmutableMap.copyOf(updates); this.gets = ImmutableMap.copyOf(gets); } } Bucket create(Bucket bucket, Map<Option, ?> options) throws StorageServiceException; StorageObject create(StorageObject object, byte[] content, Map<Option, ?> options) throws StorageServiceException; Tuple<String, Iterable<Bucket>> list(Map<Option, ?> options) throws StorageServiceException; Tuple<String, Iterable<StorageObject>> list(String bucket, Map<Option, ?> options) throws StorageServiceException; Bucket get(Bucket bucket, Map<Option, ?> options) throws StorageServiceException; StorageObject get(StorageObject object, Map<Option, ?> options) throws StorageServiceException; Bucket patch(Bucket bucket, Map<Option, ?> options) throws StorageServiceException; StorageObject patch(StorageObject storageObject, Map<Option, ?> options) throws StorageServiceException; boolean delete(Bucket bucket, Map<Option, ?> options) throws StorageServiceException; boolean delete(StorageObject object, Map<Option, ?> options) throws StorageServiceException; BatchResponse batch(BatchRequest request) throws StorageServiceException; StorageObject compose(Iterable<StorageObject> sources, StorageObject target, Map<Option, ?> targetOptions) throws StorageServiceException; StorageObject copy(StorageObject source, Map<Option, ?> sourceOptions, StorageObject target, Map<Option, ?> targetOptions) throws StorageServiceException; byte[] load(StorageObject storageObject, Map<Option, ?> options) throws StorageServiceException; byte[] read(StorageObject from, Map<Option, ?> options, int position, int bytes) throws StorageServiceException; String open(StorageObject object, Map<Option, ?> options) throws StorageServiceException; void write(byte[] bytes, StorageObject object, String uploadId, int position, boolean last) throws StorageServiceException;}

branches/tswast-patch-1/src/main/java/com/google/gcloud/storage/StorageServiceImpl.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,18 +430,28 @@ private static class BlobWriterChannelImpl implements BlobWriteChannel {
430430
private final StorageServiceOptions options;
431431
private final Blob blob;
432432
private final Map<StorageRpc.Option, ?> optionsMap;
433+
private final String uploadId;
434+
private int position;
433435

434436
public BlobWriterChannelImpl(StorageServiceOptions options, Blob blob,
435437
Map<StorageRpc.Option, ?> optionsMap) {
436438
this.options = options;
437439
this.blob = blob;
438440
this.optionsMap = optionsMap;
441+
System.out.println("Koko. BlobWriterChannelImpl.init");
442+
uploadId = options.storageRpc().open(blob.toPb(), optionsMap);
439443
}
440444

441445
@Override
442446
public int write(ByteBuffer byteBuffer) throws IOException {
447+
int size = Math.min(byteBuffer.remaining(), 1024 * 1024);
448+
byte[] bytes = new byte[size];
449+
byteBuffer.get(bytes);
443450
// todo: Use retry helper on retriable failures
444-
return 0;
451+
System.out.println("Koko. BlobWriterChannelImpl.write");
452+
options.storageRpc().write(bytes, blob.toPb(), uploadId, position, false);
453+
position += size;
454+
return size;
445455
}
446456

447457
@Override

branches/tswast-patch-1/src/main/java/com/google/gcloud/storage/StorageServiceOptions.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ private static String defaultProject() {
121121
return projectId != null ? projectId : googleCloudProjectId();
122122
}
123123

124+
public static StorageServiceOptions defaultInstnace() {
125+
return builder().build();
126+
}
127+
124128
public static Builder builder() {
125129
return new Builder();
126130
}

0 commit comments

Comments
 (0)