Use non-JNI method for read(byte[])

This commit is contained in:
Taro L. Saito 2016-03-30 16:56:53 -07:00
parent 29bfc49473
commit 00f53c49e4
1 changed files with 19 additions and 2 deletions

View File

@ -157,10 +157,27 @@ public class SnappyInputStream
* @see java.io.InputStream#read(byte[], int, int)
*/
@Override
public int read(byte[] b, int off, int len)
public int read(byte[] b, int byteOffset, int byteLength)
throws IOException
{
return rawRead(b, off, len);
int writtenBytes = 0;
for (; writtenBytes < byteLength; ) {
if (uncompressedCursor >= uncompressedLimit) {
if (hasNextChunk()) {
continue;
}
else {
return writtenBytes == 0 ? -1 : writtenBytes;
}
}
int bytesToWrite = Math.min(uncompressedLimit - uncompressedCursor, byteLength - writtenBytes);
System.arraycopy(uncompressed, uncompressedCursor, b, byteOffset + writtenBytes, bytesToWrite);
writtenBytes += bytesToWrite;
uncompressedCursor += bytesToWrite;
}
return writtenBytes;
}
/**