Skip to content

Commit e1edb53

Browse files
committed
Revert changes that were applied on a different branch.
1 parent a43992a commit e1edb53

11 files changed

Lines changed: 233 additions & 28 deletions

File tree

src/main/java/com/google/gcloud/AuthCredentials.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ private Object readResolve() throws ObjectStreamException {
6262
}
6363
}
6464

65-
private static class ServiceAccountAuthCredentials extends AuthCredentials {
65+
public static class ServiceAccountAuthCredentials extends AuthCredentials {
6666

6767
private static final long serialVersionUID = 8007708734318445901L;
6868
private final String account;
@@ -94,6 +94,14 @@ protected HttpRequestInitializer httpRequestInitializer(
9494
return builder.build();
9595
}
9696

97+
public String account() {
98+
return account;
99+
}
100+
101+
public PrivateKey privateKey() {
102+
return privateKey;
103+
}
104+
97105
@Override
98106
public int hashCode() {
99107
return Objects.hash(account, privateKey);
@@ -187,7 +195,7 @@ public static AuthCredentials createApplicationDefaults() throws IOException {
187195
return new ApplicationDefaultAuthCredentials();
188196
}
189197

190-
public static AuthCredentials createFor(String account, PrivateKey privateKey) {
198+
public static ServiceAccountAuthCredentials createFor(String account, PrivateKey privateKey) {
191199
return new ServiceAccountAuthCredentials(account, privateKey);
192200
}
193201

src/main/java/com/google/gcloud/examples/StorageExample.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ public String params() {
479479
}
480480

481481
public static void printUsage() {
482-
StringBuilder actionAndParams = new StringBuilder("");
482+
StringBuilder actionAndParams = new StringBuilder();
483483
for (Map.Entry<String, StorageAction> entry : ACTIONS.entrySet()) {
484484
actionAndParams.append("\n\t").append(entry.getKey());
485485

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,11 @@ public interface BlobReadChannel extends ReadableByteChannel, Serializable, Clos
3939
void close();
4040

4141
void seek(int position) throws IOException;
42+
43+
/**
44+
* Sets the minimum size that will be read by a single RPC.
45+
* Read data will be locally buffered until consumed.
46+
*/
47+
void chunkSize(int chunkSize);
48+
4249
}

src/main/java/com/google/gcloud/storage/BlobReadChannelImpl.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
*/
3434
class BlobReadChannelImpl implements BlobReadChannel {
3535

36-
private static final int MIN_BUFFER_SIZE = 2 * 1024 * 1024;
36+
private static final int DEFAULT_CHUNK_SIZE = 2 * 1024 * 1024;
3737
private static final long serialVersionUID = 4821762590742862669L;
3838

3939
private final StorageServiceOptions serviceOptions;
@@ -42,6 +42,7 @@ class BlobReadChannelImpl implements BlobReadChannel {
4242
private int position;
4343
private boolean isOpen;
4444
private boolean endOfStream;
45+
private int chunkSize = DEFAULT_CHUNK_SIZE;
4546

4647
private transient StorageRpc storageRpc;
4748
private transient StorageObject storageObject;
@@ -105,14 +106,19 @@ public void seek(int position) throws IOException {
105106
endOfStream = false;
106107
}
107108

109+
@Override
110+
public void chunkSize(int chunkSize) {
111+
this.chunkSize = chunkSize <= 0 ? DEFAULT_CHUNK_SIZE : chunkSize;
112+
}
113+
108114
@Override
109115
public int read(ByteBuffer byteBuffer) throws IOException {
110116
validateOpen();
111117
if (buffer == null) {
112118
if (endOfStream) {
113119
return -1;
114120
}
115-
final int toRead = Math.max(byteBuffer.remaining(), MIN_BUFFER_SIZE);
121+
final int toRead = Math.max(byteBuffer.remaining(), chunkSize);
116122
buffer = runWithRetries(new Callable<byte[]>() {
117123
@Override
118124
public byte[] call() {

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,9 @@
2929
*/
3030
public interface BlobWriteChannel extends WritableByteChannel, Serializable, Closeable {
3131

32+
/**
33+
* Sets the minimum size that will be written by a single RPC.
34+
* Written data will be buffered and only flushed upon reaching this size or closing the channel.
35+
*/
36+
void chunkSize(int chunkSize);
3237
}

src/main/java/com/google/gcloud/storage/BlobWriterChannelImpl.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535
class BlobWriterChannelImpl implements BlobWriteChannel {
3636

3737
private static final long serialVersionUID = 8675286882724938737L;
38-
private static final int CHUNK_SIZE = 256 * 1024;
39-
private static final int MIN_BUFFER_SIZE = 8 * CHUNK_SIZE;
38+
private static final int MIN_CHUNK_SIZE = 256 * 1024;
39+
private static final int DEFAULT_CHUNK_SIZE = 8 * MIN_CHUNK_SIZE;
4040

4141
private final StorageServiceOptions options;
4242
private final Blob blob;
@@ -45,6 +45,7 @@ class BlobWriterChannelImpl implements BlobWriteChannel {
4545
private byte[] buffer = new byte[0];
4646
private int limit;
4747
private boolean isOpen = true;
48+
private int chunkSize = DEFAULT_CHUNK_SIZE;
4849

4950
private transient StorageRpc storageRpc;
5051
private transient StorageObject storageObject;
@@ -65,8 +66,8 @@ private void writeObject(ObjectOutputStream out) throws IOException {
6566
}
6667

6768
private void flush(boolean compact) {
68-
if (limit >= MIN_BUFFER_SIZE || compact && limit >= CHUNK_SIZE) {
69-
final int length = limit - limit % CHUNK_SIZE;
69+
if (limit >= chunkSize || compact && limit >= MIN_CHUNK_SIZE) {
70+
final int length = limit - limit % MIN_CHUNK_SIZE;
7071
runWithRetries(callable(new Runnable() {
7172
@Override
7273
public void run() {
@@ -75,7 +76,7 @@ public void run() {
7576
}), options.retryParams(), StorageServiceImpl.EXCEPTION_HANDLER);
7677
position += length;
7778
limit -= length;
78-
byte[] temp = new byte[compact ? limit : MIN_BUFFER_SIZE];
79+
byte[] temp = new byte[compact ? limit : chunkSize];
7980
System.arraycopy(buffer, length, temp, 0, limit);
8081
buffer = temp;
8182
}
@@ -107,8 +108,7 @@ public int write(ByteBuffer byteBuffer) throws IOException {
107108
if (spaceInBuffer >= toWrite) {
108109
byteBuffer.get(buffer, limit, toWrite);
109110
} else {
110-
buffer = Arrays.copyOf(buffer,
111-
Math.max(MIN_BUFFER_SIZE, buffer.length + toWrite - spaceInBuffer));
111+
buffer = Arrays.copyOf(buffer, Math.max(chunkSize, buffer.length + toWrite - spaceInBuffer));
112112
byteBuffer.get(buffer, limit, toWrite);
113113
}
114114
limit += toWrite;
@@ -135,4 +135,10 @@ public void run() {
135135
buffer = null;
136136
}
137137
}
138+
139+
@Override
140+
public void chunkSize(int chunkSize) {
141+
chunkSize = (chunkSize / MIN_CHUNK_SIZE) * MIN_CHUNK_SIZE;
142+
this.chunkSize = Math.max(MIN_CHUNK_SIZE, chunkSize);
143+
}
138144
}

src/main/java/com/google/gcloud/storage/Cors.java

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,10 @@ public Bucket.Cors apply(Cors cors) {
5353
};
5454

5555
private final Integer maxAgeSeconds;
56-
private final ImmutableList<Method> methods;
56+
private final ImmutableList<HttpMethod> methods;
5757
private final ImmutableList<Origin> origins;
5858
private final ImmutableList<String> responseHeaders;
5959

60-
public enum Method {
61-
ANY, GET, HEAD, PUT, POST, DELETE
62-
}
63-
6460
public static final class Origin implements Serializable {
6561

6662
private static final long serialVersionUID = -4447958124895577993L;
@@ -118,7 +114,7 @@ public String value() {
118114
public static final class Builder {
119115

120116
private Integer maxAgeSeconds;
121-
private ImmutableList<Method> methods;
117+
private ImmutableList<HttpMethod> methods;
122118
private ImmutableList<Origin> origins;
123119
private ImmutableList<String> responseHeaders;
124120

@@ -129,7 +125,7 @@ public Builder maxAgeSeconds(Integer maxAgeSeconds) {
129125
return this;
130126
}
131127

132-
public Builder methods(Iterable<Method> methods) {
128+
public Builder methods(Iterable<HttpMethod> methods) {
133129
this.methods = methods != null ? ImmutableList.copyOf(methods) : null;
134130
return this;
135131
}
@@ -160,7 +156,7 @@ public Integer maxAgeSeconds() {
160156
return maxAgeSeconds;
161157
}
162158

163-
public List<Method> methods() {
159+
public List<HttpMethod> methods() {
164160
return methods;
165161
}
166162

@@ -217,10 +213,10 @@ Bucket.Cors toPb() {
217213
static Cors fromPb(Bucket.Cors cors) {
218214
Builder builder = builder().maxAgeSeconds(cors.getMaxAgeSeconds());
219215
if (cors.getMethod() != null) {
220-
builder.methods(transform(cors.getMethod(), new Function<String, Method>() {
216+
builder.methods(transform(cors.getMethod(), new Function<String, HttpMethod>() {
221217
@Override
222-
public Method apply(String name) {
223-
return Method.valueOf(name.toUpperCase());
218+
public HttpMethod apply(String name) {
219+
return HttpMethod.valueOf(name.toUpperCase());
224220
}
225221
}));
226222
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright 2015 Google Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.gcloud.storage;
18+
19+
/**
20+
*
21+
*/
22+
public enum HttpMethod {
23+
GET, HEAD, PUT, POST, DELETE
24+
}

0 commit comments

Comments
 (0)