Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

- Fixed a bug in the method getBytesInBufferAvailable() #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 @@ -2,6 +2,7 @@

import com.amazonaws.services.s3.model.GetObjectRequest;
import com.amazonaws.services.s3.model.S3Object;
import com.amazonaws.services.s3.model.S3ObjectInputStream;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
Expand All @@ -27,7 +28,7 @@ public class S3ReadOnlySeekableByteChannel implements SeekableByteChannel {
private S3Path path;
private Set<? extends OpenOption> options;
private long length;
private ExtBufferedInputStream bufferedStream;
private ExtBufferedInputStream bufferedStream = null;
private ReadableByteChannel rbc;
private long position = 0;

Expand Down Expand Up @@ -72,6 +73,9 @@ public S3ReadOnlySeekableByteChannel(S3Path path, Set<? extends OpenOption> opti
}

private void openStreamAt(long position) throws IOException {
if (bufferedStream != null) {
bufferedStream.getObjectStream().abort();
}
if (rbc != null) {
rbc.close();
}
Expand Down Expand Up @@ -143,18 +147,28 @@ public long size() {
}

public void close() throws IOException {
if (bufferedStream != null) {
bufferedStream.getObjectStream().abort();
}
rbc.close();
}

private class ExtBufferedInputStream extends BufferedInputStream {
private ExtBufferedInputStream(final InputStream inputStream, final int size) {
super(inputStream, size);
S3ObjectInputStream objectStream;

private ExtBufferedInputStream(final S3ObjectInputStream objectStream, final int size) {
super(objectStream, size);

this.objectStream = objectStream;
}

private S3ObjectInputStream getObjectStream() {
return this.objectStream ;
}

/** Returns the number of bytes that can be read from the buffer without reading more into the buffer. */
int getBytesInBufferAvailable() {
if (this.count == this.pos) return 0;
else return this.buf.length - this.pos;
return (this.count - this.pos);
}
}
}