Skip to content

Commit 71604bb

Browse files
committed
Remove compact param from write channel flush, restore limit from array length
1 parent dcbe37f commit 71604bb

1 file changed

Lines changed: 8 additions & 14 deletions

File tree

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)