Use System.arraycopy for write(byte[]) apache/spark#12074

This commit is contained in:
Taro L. Saito 2016-03-30 20:32:09 -07:00
parent 7d384a6fd6
commit 29bfc49473
1 changed files with 19 additions and 2 deletions

View File

@ -109,10 +109,27 @@ public class SnappyOutputStream
* @see java.io.OutputStream#write(byte[], int, int)
*/
@Override
public void write(byte[] b, int off, int len)
public void write(byte[] b, int byteOffset, int byteLength)
throws IOException
{
rawWrite(b, off, len);
if (closed) {
throw new IOException("Stream is closed");
}
int cursor = 0;
while (cursor < byteLength) {
int readLen = Math.min(byteLength - cursor, blockSize - inputCursor);
// copy the input data to uncompressed buffer
if (readLen > 0) {
System.arraycopy(b, byteOffset + cursor, inputBuffer, inputCursor, readLen);
inputCursor += readLen;
}
if (inputCursor < blockSize) {
return;
}
compressInput();
cursor += readLen;
}
}
/**