am b4b431b0: am d2133079: am 7c0dfed5: Merge "Pass int32_t for JNI calls to java Input/Output streams."
* commit 'b4b431b0d2f6d57afe80c4119e5f41e4fb72e7d9': Pass int32_t for JNI calls to java Input/Output streams.
This commit is contained in:
@@ -63,9 +63,14 @@ private:
|
|||||||
size_t bytesRead = 0;
|
size_t bytesRead = 0;
|
||||||
// read the bytes
|
// read the bytes
|
||||||
do {
|
do {
|
||||||
size_t requested = size;
|
jint requested = 0;
|
||||||
if (requested > fCapacity)
|
if (size > static_cast<size_t>(fCapacity)) {
|
||||||
requested = fCapacity;
|
requested = fCapacity;
|
||||||
|
} else {
|
||||||
|
// This is safe because requested is clamped to (jint)
|
||||||
|
// fCapacity.
|
||||||
|
requested = static_cast<jint>(size);
|
||||||
|
}
|
||||||
|
|
||||||
jint n = env->CallIntMethod(fJavaInputStream,
|
jint n = env->CallIntMethod(fJavaInputStream,
|
||||||
gInputStream_readMethodID, fJavaByteArray, 0, requested);
|
gInputStream_readMethodID, fJavaByteArray, 0, requested);
|
||||||
@@ -120,7 +125,7 @@ private:
|
|||||||
JNIEnv* fEnv;
|
JNIEnv* fEnv;
|
||||||
jobject fJavaInputStream; // the caller owns this object
|
jobject fJavaInputStream; // the caller owns this object
|
||||||
jbyteArray fJavaByteArray; // the caller owns this object
|
jbyteArray fJavaByteArray; // the caller owns this object
|
||||||
size_t fCapacity;
|
jint fCapacity;
|
||||||
size_t fBytesRead;
|
size_t fBytesRead;
|
||||||
bool fIsAtEnd;
|
bool fIsAtEnd;
|
||||||
};
|
};
|
||||||
@@ -174,14 +179,18 @@ public:
|
|||||||
fCapacity = env->GetArrayLength(storage);
|
fCapacity = env->GetArrayLength(storage);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool write(const void* buffer, size_t size) {
|
virtual bool write(const void* buffer, size_t size) {
|
||||||
JNIEnv* env = fEnv;
|
JNIEnv* env = fEnv;
|
||||||
jbyteArray storage = fJavaByteArray;
|
jbyteArray storage = fJavaByteArray;
|
||||||
|
|
||||||
while (size > 0) {
|
while (size > 0) {
|
||||||
size_t requested = size;
|
jint requested = 0;
|
||||||
if (requested > fCapacity) {
|
if (size > static_cast<size_t>(fCapacity)) {
|
||||||
requested = fCapacity;
|
requested = fCapacity;
|
||||||
|
} else {
|
||||||
|
// This is safe because requested is clamped to (jint)
|
||||||
|
// fCapacity.
|
||||||
|
requested = static_cast<jint>(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
env->SetByteArrayRegion(storage, 0, requested,
|
env->SetByteArrayRegion(storage, 0, requested,
|
||||||
@@ -216,7 +225,7 @@ private:
|
|||||||
JNIEnv* fEnv;
|
JNIEnv* fEnv;
|
||||||
jobject fJavaOutputStream; // the caller owns this object
|
jobject fJavaOutputStream; // the caller owns this object
|
||||||
jbyteArray fJavaByteArray; // the caller owns this object
|
jbyteArray fJavaByteArray; // the caller owns this object
|
||||||
size_t fCapacity;
|
jint fCapacity;
|
||||||
};
|
};
|
||||||
|
|
||||||
SkWStream* CreateJavaOutputStreamAdaptor(JNIEnv* env, jobject stream,
|
SkWStream* CreateJavaOutputStreamAdaptor(JNIEnv* env, jobject stream,
|
||||||
|
|||||||
Reference in New Issue
Block a user