Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public SeekableByteChannel position(long newPosition) throws IOException {
if (newPosition == position) {
return this;
}
channel.seek((int) newPosition);
channel.seek(newPosition);
position = newPosition;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public interface ReadChannel extends ReadableByteChannel, Closeable, Restorable<
@Override
void close();

void seek(int position) throws IOException;
void seek(long position) throws IOException;

/**
* Sets the minimum size that will be read by a single RPC.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public WorkUnit(SeekableByteChannel chan, int blockSize, int blockIndex) {

@Override
public WorkUnit call() throws IOException {
int pos = blockSize * blockIndex;
long pos = ((long)blockSize) * blockIndex;
if (pos > chan.size()) {
return this;
}
Expand All @@ -90,6 +90,7 @@ public WorkUnit resetForIndex(int blockIndex) {
return this;
}


public void close() throws IOException {
chan.close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class BlobReadChannel implements ReadChannel {
private final BlobId blob;
private final Map<StorageRpc.Option, ?> requestOptions;
private String lastEtag;
private int position;
private long position;
private boolean isOpen;
private boolean endOfStream;
private int chunkSize = DEFAULT_CHUNK_SIZE;
Expand Down Expand Up @@ -99,7 +99,7 @@ private void validateOpen() throws ClosedChannelException {
}

@Override
public void seek(int position) throws IOException {
public void seek(long position) throws IOException {
validateOpen();
this.position = position;
buffer = null;
Expand Down Expand Up @@ -164,7 +164,7 @@ static class StateImpl implements RestorableState<ReadChannel>, Serializable {
private final BlobId blob;
private final Map<StorageRpc.Option, ?> requestOptions;
private final String lastEtag;
private final int position;
private final long position;
private final boolean isOpen;
private final boolean endOfStream;
private final int chunkSize;
Expand All @@ -185,7 +185,7 @@ static class Builder {
private final BlobId blob;
private final Map<StorageRpc.Option, ?> requestOptions;
private String lastEtag;
private int position;
private long position;
private boolean isOpen;
private boolean endOfStream;
private int chunkSize;
Expand All @@ -201,7 +201,7 @@ Builder lastEtag(String lastEtag) {
return this;
}

Builder position(int position) {
Builder position(long position) {
this.position = position;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import static com.google.cloud.storage.spi.StorageRpc.Option.PREFIX;
import static com.google.cloud.storage.spi.StorageRpc.Option.VERSIONS;
import static com.google.common.base.MoreObjects.firstNonNull;
import static com.google.common.base.Preconditions.checkArgument;
import static java.net.HttpURLConnection.HTTP_NOT_FOUND;
import static javax.servlet.http.HttpServletResponse.SC_REQUESTED_RANGE_NOT_SATISFIABLE;

Expand Down Expand Up @@ -467,10 +468,11 @@ public Tuple<String, byte[]> read(StorageObject from, Map<Option, ?> options, lo
.setIfMetagenerationNotMatch(IF_METAGENERATION_NOT_MATCH.getLong(options))
.setIfGenerationMatch(IF_GENERATION_MATCH.getLong(options))
.setIfGenerationNotMatch(IF_GENERATION_NOT_MATCH.getLong(options));
checkArgument(position >= 0, "Position should be non-negative, is %d", position);
StringBuilder range = new StringBuilder();
range.append("bytes=").append(position).append("-").append(position + bytes - 1);
req.getRequestHeaders().setRange(range.toString());
ByteArrayOutputStream output = new ByteArrayOutputStream();
ByteArrayOutputStream output = new ByteArrayOutputStream(bytes);
req.executeMedia().download(output);
String etag = req.getLastResponseHeaders().getETag();
return Tuple.of(etag, output.toByteArray());
Expand Down