Skip to content

Commit 00f53c4

Browse files
committed
Use non-JNI method for read(byte[])
1 parent 29bfc49 commit 00f53c4

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

src/main/java/org/xerial/snappy/SnappyInputStream.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,27 @@ protected void readFully(byte[] fragment, int fragmentLength)
157157
* @see java.io.InputStream#read(byte[], int, int)
158158
*/
159159
@Override
160-
public int read(byte[] b, int off, int len)
160+
public int read(byte[] b, int byteOffset, int byteLength)
161161
throws IOException
162162
{
163-
return rawRead(b, off, len);
163+
int writtenBytes = 0;
164+
for (; writtenBytes < byteLength; ) {
165+
166+
if (uncompressedCursor >= uncompressedLimit) {
167+
if (hasNextChunk()) {
168+
continue;
169+
}
170+
else {
171+
return writtenBytes == 0 ? -1 : writtenBytes;
172+
}
173+
}
174+
int bytesToWrite = Math.min(uncompressedLimit - uncompressedCursor, byteLength - writtenBytes);
175+
System.arraycopy(uncompressed, uncompressedCursor, b, byteOffset + writtenBytes, bytesToWrite);
176+
writtenBytes += bytesToWrite;
177+
uncompressedCursor += bytesToWrite;
178+
}
179+
180+
return writtenBytes;
164181
}
165182

166183
/**

0 commit comments

Comments
 (0)