gomobile Reader.Read should take offset and length params (#3326)

This commit is contained in:
Kaloyan Raev 2019-10-21 18:17:31 +03:00 committed by GitHub
parent 1814fbfa89
commit 244fea774b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 5 deletions

View File

@ -288,7 +288,7 @@ func (bucket *Bucket) NewWriter(path storj.Path, options *WriterOptions) (*Write
// Write writes data.length bytes from data to the underlying data stream.
func (w *Writer) Write(data []byte, offset, length int32) (int32, error) {
// in Java byte array size is max int32
n, err := w.writer.Write(data[offset:length])
n, err := w.writer.Write(data[offset : offset+length])
return int32(n), safeError(err)
}
@ -329,12 +329,12 @@ func (bucket *Bucket) NewReader(path storj.Path, options *ReaderOptions) (*Reade
}
// Read reads data into byte array
func (r *Reader) Read(data []byte) (n int32, err error) {
func (r *Reader) Read(data []byte, offset, length int32) (n int32, err error) {
if r.readError != nil {
err = r.readError
} else {
var read int
read, err = r.reader.Read(data)
read, err = r.reader.Read(data[offset : offset+length])
n = int32(read)
}

View File

@ -187,7 +187,7 @@ public class LibuplinkInstrumentedTest {
ByteArrayOutputStream writer = new ByteArrayOutputStream();
byte[] buf = new byte[256];
int read = 0;
while ((read = reader.read(buf)) != -1) {
while ((read = reader.read(buf, 0, buf.length)) != -1) {
writer.write(buf, 0, read);
}
assertArrayEquals(writer.toByteArray(), expectedData);
@ -251,7 +251,7 @@ public class LibuplinkInstrumentedTest {
ByteArrayOutputStream writer = new ByteArrayOutputStream();
byte[] buf = new byte[4096];
int read = 0;
while ((read = reader.read(buf)) != -1) {
while ((read = reader.read(buf, 0, buf.length)) != -1) {
writer.write(buf, 0, read);
}
assertEquals(expectedData.length, writer.size());