Skip to content

Commit 145048b

Browse files
committed
---
yaml --- r: 6329 b: refs/heads/tswast-patch-1 c: 71604bb h: refs/heads/master i: 6327: ba182e4
1 parent 5aed362 commit 145048b

2 files changed

Lines changed: 9 additions & 15 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: dcbe37fab40c070d58155fdaa8b8fee673a40582
60+
refs/heads/tswast-patch-1: 71604bba52031a8609b682903ada37943f158b1b
6161
refs/heads/pubsub-streaming-pull: 19262b752ee874eb2ca3b950eb2aef44d5a5267b

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

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -73,18 +73,17 @@ class BlobWriteChannelImpl implements BlobWriteChannel {
7373
@Override
7474
public RestorableState<BlobWriteChannel> save() {
7575
if (isOpen) {
76-
flush(true);
76+
flush();
7777
}
7878
return StateImpl.builder(options, blobInfo, uploadId)
7979
.position(position)
80-
.buffer(buffer)
81-
.limit(limit)
80+
.buffer(Arrays.copyOf(buffer, limit))
8281
.isOpen(isOpen)
8382
.chunkSize(chunkSize).build();
8483
}
8584

86-
private void flush(boolean compact) {
87-
if (limit >= chunkSize || compact && limit >= MIN_CHUNK_SIZE) {
85+
private void flush() {
86+
if (limit >= chunkSize) {
8887
final int length = limit - limit % MIN_CHUNK_SIZE;
8988
try {
9089
runWithRetries(callable(new Runnable() {
@@ -98,7 +97,7 @@ public void run() {
9897
}
9998
position += length;
10099
limit -= length;
101-
byte[] temp = new byte[compact ? limit : chunkSize];
100+
byte[] temp = new byte[chunkSize];
102101
System.arraycopy(buffer, length, temp, 0, limit);
103102
buffer = temp;
104103
}
@@ -122,7 +121,7 @@ public int write(ByteBuffer byteBuffer) throws IOException {
122121
byteBuffer.get(buffer, limit, toWrite);
123122
}
124123
limit += toWrite;
125-
flush(false);
124+
flush();
126125
return toWrite;
127126
}
128127

@@ -175,7 +174,7 @@ static class StateImpl implements RestorableState<BlobWriteChannel>, Serializabl
175174
this.uploadId = builder.uploadId;
176175
this.position = builder.position;
177176
this.buffer = builder.buffer;
178-
this.limit = builder.limit;
177+
this.limit = this.buffer.length;
179178
this.isOpen = builder.isOpen;
180179
this.chunkSize = builder.chunkSize;
181180
}
@@ -202,12 +201,7 @@ Builder position(int position) {
202201
}
203202

204203
Builder buffer(byte[] buffer) {
205-
this.buffer = buffer.clone();
206-
return this;
207-
}
208-
209-
Builder limit(int limit) {
210-
this.limit = limit;
204+
this.buffer = buffer;
211205
return this;
212206
}
213207

0 commit comments

Comments
 (0)