Skip to content

Commit 2060526

Browse files
committed
Fix wrapping, remove limit from write channel StateImpl
1 parent 71604bb commit 2060526

File tree

2 files changed

+21
-22
lines changed

2 files changed

+21
-22
lines changed

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -237,13 +237,13 @@ public boolean equals(Object obj) {
237237
return false;
238238
}
239239
final StateImpl other = (StateImpl) obj;
240-
return Objects.equals(this.serviceOptions, other.serviceOptions) &&
241-
Objects.equals(this.blob, other.blob) &&
242-
Objects.equals(this.requestOptions, other.requestOptions) &&
243-
this.position == other.position &&
244-
this.isOpen == other.isOpen &&
245-
this.endOfStream == other.endOfStream &&
246-
this.chunkSize == other.chunkSize;
240+
return Objects.equals(this.serviceOptions, other.serviceOptions)
241+
&& Objects.equals(this.blob, other.blob)
242+
&& Objects.equals(this.requestOptions, other.requestOptions)
243+
&& this.position == other.position
244+
&& this.isOpen == other.isOpen
245+
&& this.endOfStream == other.endOfStream
246+
&& this.chunkSize == other.chunkSize;
247247
}
248248

249249
@Override

gcloud-java-storage/src/main/java/com/google/gcloud/storage/BlobWriteChannelImpl.java

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,17 @@ class BlobWriteChannelImpl implements BlobWriteChannel {
7272

7373
@Override
7474
public RestorableState<BlobWriteChannel> save() {
75+
byte[] bufferToSave = null;
7576
if (isOpen) {
7677
flush();
78+
bufferToSave = Arrays.copyOf(buffer, limit);
7779
}
7880
return StateImpl.builder(options, blobInfo, uploadId)
7981
.position(position)
80-
.buffer(Arrays.copyOf(buffer, limit))
82+
.buffer(bufferToSave)
8183
.isOpen(isOpen)
82-
.chunkSize(chunkSize).build();
84+
.chunkSize(chunkSize)
85+
.build();
8386
}
8487

8588
private void flush() {
@@ -164,7 +167,6 @@ static class StateImpl implements RestorableState<BlobWriteChannel>, Serializabl
164167
private final String uploadId;
165168
private final int position;
166169
private final byte[] buffer;
167-
private final int limit;
168170
private final boolean isOpen;
169171
private final int chunkSize;
170172

@@ -174,7 +176,6 @@ static class StateImpl implements RestorableState<BlobWriteChannel>, Serializabl
174176
this.uploadId = builder.uploadId;
175177
this.position = builder.position;
176178
this.buffer = builder.buffer;
177-
this.limit = this.buffer.length;
178179
this.isOpen = builder.isOpen;
179180
this.chunkSize = builder.chunkSize;
180181
}
@@ -185,7 +186,6 @@ static class Builder {
185186
private final String uploadId;
186187
private int position;
187188
private byte[] buffer;
188-
private int limit;
189189
private boolean isOpen;
190190
private int chunkSize;
191191

@@ -229,15 +229,15 @@ public BlobWriteChannel restore() {
229229
BlobWriteChannelImpl channel = new BlobWriteChannelImpl(serviceOptions, blobInfo, uploadId);
230230
channel.position = position;
231231
channel.buffer = buffer.clone();
232-
channel.limit = limit;
232+
channel.limit = buffer.length;
233233
channel.isOpen = isOpen;
234234
channel.chunkSize = chunkSize;
235235
return channel;
236236
}
237237

238238
@Override
239239
public int hashCode() {
240-
return Objects.hash(serviceOptions, blobInfo, uploadId, position, limit, isOpen, chunkSize,
240+
return Objects.hash(serviceOptions, blobInfo, uploadId, position, isOpen, chunkSize,
241241
Arrays.hashCode(buffer));
242242
}
243243

@@ -250,14 +250,13 @@ public boolean equals(Object obj) {
250250
return false;
251251
}
252252
final StateImpl other = (StateImpl) obj;
253-
return Objects.equals(this.serviceOptions, other.serviceOptions) &&
254-
Objects.equals(this.blobInfo, other.blobInfo) &&
255-
Objects.equals(this.uploadId, other.uploadId) &&
256-
Objects.deepEquals(this.buffer, other.buffer) &&
257-
this.position == other.position &&
258-
this.limit == other.limit &&
259-
this.isOpen == other.isOpen &&
260-
this.chunkSize == other.chunkSize;
253+
return Objects.equals(this.serviceOptions, other.serviceOptions)
254+
&& Objects.equals(this.blobInfo, other.blobInfo)
255+
&& Objects.equals(this.uploadId, other.uploadId)
256+
&& Objects.deepEquals(this.buffer, other.buffer)
257+
&& this.position == other.position
258+
&& this.isOpen == other.isOpen
259+
&& this.chunkSize == other.chunkSize;
261260
}
262261

263262
@Override

0 commit comments

Comments
 (0)