HDFS-14285. libhdfs hdfsRead copies entire array even if its only partially filled. Contributed by Sahil Takiar.
Signed-off-by: Wei-Chiu Chuang <weichiu@apache.org>
This commit is contained in:
parent
9daf43c6fa
commit
f19c844e75
|
@ -1396,7 +1396,6 @@ tSize hdfsRead(hdfsFS fs, hdfsFile f, void* buffer, tSize length)
|
||||||
{
|
{
|
||||||
jobject jInputStream;
|
jobject jInputStream;
|
||||||
jbyteArray jbRarray;
|
jbyteArray jbRarray;
|
||||||
jint noReadBytes = length;
|
|
||||||
jvalue jVal;
|
jvalue jVal;
|
||||||
jthrowable jthr;
|
jthrowable jthr;
|
||||||
JNIEnv* env;
|
JNIEnv* env;
|
||||||
|
@ -1452,7 +1451,12 @@ tSize hdfsRead(hdfsFS fs, hdfsFile f, void* buffer, tSize length)
|
||||||
errno = EINTR;
|
errno = EINTR;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
(*env)->GetByteArrayRegion(env, jbRarray, 0, noReadBytes, buffer);
|
// We only copy the portion of the jbRarray that was actually filled by
|
||||||
|
// the call to FsDataInputStream#read; #read is not guaranteed to fill the
|
||||||
|
// entire buffer, instead it returns the number of bytes read into the
|
||||||
|
// buffer; we use the return value as the input in GetByteArrayRegion to
|
||||||
|
// ensure don't copy more bytes than necessary
|
||||||
|
(*env)->GetByteArrayRegion(env, jbRarray, 0, jVal.i, buffer);
|
||||||
destroyLocalReference(env, jbRarray);
|
destroyLocalReference(env, jbRarray);
|
||||||
if ((*env)->ExceptionCheck(env)) {
|
if ((*env)->ExceptionCheck(env)) {
|
||||||
errno = printPendingExceptionAndFree(env, PRINT_EXC_ALL,
|
errno = printPendingExceptionAndFree(env, PRINT_EXC_ALL,
|
||||||
|
|
Loading…
Reference in New Issue