Skip to content

Commit

Permalink
Fix wrapping, remove limit from write channel StateImpl
Browse files Browse the repository at this point in the history
  • Loading branch information
mziccard committed Oct 19, 2015
1 parent 71604bb commit 2060526
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -237,13 +237,13 @@ public boolean equals(Object obj) {
return false;
}
final StateImpl other = (StateImpl) obj;
return Objects.equals(this.serviceOptions, other.serviceOptions) &&
Objects.equals(this.blob, other.blob) &&
Objects.equals(this.requestOptions, other.requestOptions) &&
this.position == other.position &&
this.isOpen == other.isOpen &&
this.endOfStream == other.endOfStream &&
this.chunkSize == other.chunkSize;
return Objects.equals(this.serviceOptions, other.serviceOptions)
&& Objects.equals(this.blob, other.blob)
&& Objects.equals(this.requestOptions, other.requestOptions)
&& this.position == other.position
&& this.isOpen == other.isOpen
&& this.endOfStream == other.endOfStream
&& this.chunkSize == other.chunkSize;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,17 @@ class BlobWriteChannelImpl implements BlobWriteChannel {

@Override
public RestorableState<BlobWriteChannel> save() {
byte[] bufferToSave = null;
if (isOpen) {
flush();
bufferToSave = Arrays.copyOf(buffer, limit);
}
return StateImpl.builder(options, blobInfo, uploadId)
.position(position)
.buffer(Arrays.copyOf(buffer, limit))
.buffer(bufferToSave)
.isOpen(isOpen)
.chunkSize(chunkSize).build();
.chunkSize(chunkSize)
.build();
}

private void flush() {
Expand Down Expand Up @@ -164,7 +167,6 @@ static class StateImpl implements RestorableState<BlobWriteChannel>, Serializabl
private final String uploadId;
private final int position;
private final byte[] buffer;
private final int limit;
private final boolean isOpen;
private final int chunkSize;

Expand All @@ -174,7 +176,6 @@ static class StateImpl implements RestorableState<BlobWriteChannel>, Serializabl
this.uploadId = builder.uploadId;
this.position = builder.position;
this.buffer = builder.buffer;
this.limit = this.buffer.length;
this.isOpen = builder.isOpen;
this.chunkSize = builder.chunkSize;
}
Expand All @@ -185,7 +186,6 @@ static class Builder {
private final String uploadId;
private int position;
private byte[] buffer;
private int limit;
private boolean isOpen;
private int chunkSize;

Expand Down Expand Up @@ -229,15 +229,15 @@ public BlobWriteChannel restore() {
BlobWriteChannelImpl channel = new BlobWriteChannelImpl(serviceOptions, blobInfo, uploadId);
channel.position = position;
channel.buffer = buffer.clone();
channel.limit = limit;
channel.limit = buffer.length;

This comment has been minimized.

Copy link
@aozarov

aozarov Oct 19, 2015

Contributor

if isOpen is false, buffer could be null (would be a problem here and above).

This comment has been minimized.

Copy link
@mziccard

mziccard Oct 19, 2015

Author Contributor

Sure, you are right

channel.isOpen = isOpen;
channel.chunkSize = chunkSize;
return channel;
}

@Override
public int hashCode() {
return Objects.hash(serviceOptions, blobInfo, uploadId, position, limit, isOpen, chunkSize,
return Objects.hash(serviceOptions, blobInfo, uploadId, position, isOpen, chunkSize,
Arrays.hashCode(buffer));
}

Expand All @@ -250,14 +250,13 @@ public boolean equals(Object obj) {
return false;
}
final StateImpl other = (StateImpl) obj;
return Objects.equals(this.serviceOptions, other.serviceOptions) &&
Objects.equals(this.blobInfo, other.blobInfo) &&
Objects.equals(this.uploadId, other.uploadId) &&
Objects.deepEquals(this.buffer, other.buffer) &&
this.position == other.position &&
this.limit == other.limit &&
this.isOpen == other.isOpen &&
this.chunkSize == other.chunkSize;
return Objects.equals(this.serviceOptions, other.serviceOptions)
&& Objects.equals(this.blobInfo, other.blobInfo)
&& Objects.equals(this.uploadId, other.uploadId)
&& Objects.deepEquals(this.buffer, other.buffer)
&& this.position == other.position
&& this.isOpen == other.isOpen
&& this.chunkSize == other.chunkSize;
}

@Override
Expand Down

0 comments on commit 2060526

Please sign in to comment.