diff options
Diffstat (limited to 'luni/src/main/native/java_io_ObjectInputStream.cpp')
-rw-r--r-- | luni/src/main/native/java_io_ObjectInputStream.cpp | 281 |
1 files changed, 281 insertions, 0 deletions
diff --git a/luni/src/main/native/java_io_ObjectInputStream.cpp b/luni/src/main/native/java_io_ObjectInputStream.cpp new file mode 100644 index 0000000..57f8afe --- /dev/null +++ b/luni/src/main/native/java_io_ObjectInputStream.cpp @@ -0,0 +1,281 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "JNIHelp.h" + +static void java_setFieldBool (JNIEnv* env, jclass, + jobject targetObject, + jclass declaringClass, + jstring fieldName, + jboolean newValue) { + const char *fieldNameInC; + jfieldID fid; + if(targetObject == NULL) { + return; + } + fieldNameInC = env->GetStringUTFChars(fieldName, NULL); + fid = env->GetFieldID(declaringClass, fieldNameInC, "Z"); + env->ReleaseStringUTFChars(fieldName, fieldNameInC); + + /* + * Two options now. Maybe getFieldID caused an exception, + * or maybe it returned the real value + */ + if(fid != 0) { + env->SetBooleanField(targetObject, fid, newValue); + } +} + +static void java_setFieldChar (JNIEnv* env, jclass, + jobject targetObject, + jclass declaringClass, + jstring fieldName, + jchar newValue) { + const char *fieldNameInC; + jfieldID fid; + if(targetObject == NULL) { + return; + } + fieldNameInC = env->GetStringUTFChars(fieldName, NULL); + fid = env->GetFieldID(declaringClass, fieldNameInC, "C"); + env->ReleaseStringUTFChars(fieldName, fieldNameInC); + + /* + * Two options now. Maybe getFieldID caused an exception, + * or maybe it returned the real value + */ + if(fid != 0) { + env->SetCharField(targetObject, fid, newValue); + } +} + +static void java_setFieldInt (JNIEnv* env, jclass, + jobject targetObject, + jclass declaringClass, + jstring fieldName, + jint newValue) { + const char *fieldNameInC; + jfieldID fid; + if(targetObject == NULL) { + return; + } + fieldNameInC = env->GetStringUTFChars(fieldName, NULL); + fid = env->GetFieldID(declaringClass, fieldNameInC, "I"); + env->ReleaseStringUTFChars(fieldName, fieldNameInC); + + /* + * Two options now. Maybe getFieldID caused an exception, + * or maybe it returned the real value + */ + if(fid != 0) { + env->SetIntField(targetObject, fid, newValue); + } +} + +static void java_setFieldFloat (JNIEnv* env, jclass, + jobject targetObject, + jclass declaringClass, + jstring fieldName, + jfloat newValue) { + const char *fieldNameInC; + jfieldID fid; + if(targetObject == NULL) { + return; + } + fieldNameInC = env->GetStringUTFChars(fieldName, NULL); + fid = env->GetFieldID(declaringClass, fieldNameInC, "F"); + env->ReleaseStringUTFChars(fieldName, fieldNameInC); + + /* + * Two options now. Maybe getFieldID caused an exception, + * or maybe it returned the real value + */ + if(fid != 0) { + env->SetFloatField(targetObject, fid, newValue); + } +} + +static void java_setFieldDouble (JNIEnv* env, jclass, + jobject targetObject, + jclass declaringClass, + jstring fieldName, + jdouble newValue) { + const char *fieldNameInC; + jfieldID fid; + if(targetObject == NULL) { + return; + } + fieldNameInC = env->GetStringUTFChars(fieldName, NULL); + fid = env->GetFieldID(declaringClass, fieldNameInC, "D"); + env->ReleaseStringUTFChars(fieldName, fieldNameInC); + + /* + * Two options now. Maybe getFieldID caused an exception, + * or maybe it returned the real value + */ + if(fid != 0) { + env->SetDoubleField(targetObject, fid, newValue); + } + +} + +static void java_setFieldShort (JNIEnv* env, jclass, + jobject targetObject, + jclass declaringClass, + jstring fieldName, + jshort newValue) { + const char *fieldNameInC; + jfieldID fid; + if(targetObject == NULL) { + return; + } + fieldNameInC = env->GetStringUTFChars(fieldName, NULL); + fid = env->GetFieldID(declaringClass, fieldNameInC, "S"); + env->ReleaseStringUTFChars(fieldName, fieldNameInC); + + /* + * Two options now. Maybe getFieldID caused an exception, + * or maybe it returned the real value + */ + if(fid != 0) { + env->SetShortField(targetObject, fid, newValue); + } + +} + +static void java_setFieldLong (JNIEnv* env, jclass, + jobject targetObject, + jclass declaringClass, + jstring fieldName, + jlong newValue) { + const char *fieldNameInC; + jfieldID fid; + if(targetObject == NULL) { + return; + } + fieldNameInC = env->GetStringUTFChars(fieldName, NULL); + fid = env->GetFieldID(declaringClass, fieldNameInC, "J"); + env->ReleaseStringUTFChars(fieldName, fieldNameInC); + + /* + * Two options now. Maybe getFieldID caused an exception, + * or maybe it returned the real value + */ + if(fid != 0) { + env->SetLongField(targetObject, fid, newValue); + } +} + +static jobject java_newInstance (JNIEnv* env, jclass, + jclass instantiationClass, + jclass constructorClass) { + jmethodID mid = + env->GetMethodID(constructorClass, "<init>", "()V"); + + if(mid == 0) { + /* Cant newInstance,No empty constructor... */ + return (jobject) 0; + } else { + /* Instantiate an object of a given class */ + return (jobject) env->NewObject(instantiationClass, mid); + } + +} + +static void java_setFieldByte (JNIEnv* env, jclass, + jobject targetObject, + jclass declaringClass, + jstring fieldName, + jbyte newValue){ + const char *fieldNameInC; + jfieldID fid; + if(targetObject == NULL) { + return; + } + fieldNameInC = env->GetStringUTFChars(fieldName, NULL); + fid = env->GetFieldID(declaringClass, fieldNameInC, "B"); + env->ReleaseStringUTFChars(fieldName, fieldNameInC); + + /* Two options now. Maybe getFieldID caused an exception, or maybe it returned the real value */ + if(fid != 0) { + env->SetByteField(targetObject, fid, newValue); + } +} + +static void java_setFieldObj (JNIEnv* env, jclass, + jobject targetObject, + jclass declaringClass, + jstring fieldName, + jstring fieldTypeName, + jobject newValue) { + const char *fieldNameInC, *fieldTypeNameInC; + jfieldID fid; + if(targetObject == NULL) { + return; + } + fieldNameInC = env->GetStringUTFChars(fieldName, NULL); + fieldTypeNameInC = env->GetStringUTFChars(fieldTypeName, NULL); + fid = env->GetFieldID(declaringClass, + fieldNameInC, fieldTypeNameInC); + env->ReleaseStringUTFChars(fieldName, fieldNameInC); + env->ReleaseStringUTFChars(fieldTypeName, fieldTypeNameInC); + + /* + * Two options now. Maybe getFieldID caused an exception, + * or maybe it returned the real value + */ + if(fid != 0) { + env->SetObjectField(targetObject, fid, newValue); + } +} + +static JNINativeMethod gMethods[] = { + { "setField", + "(Ljava/lang/Object;Ljava/lang/Class;Ljava/lang/String;J)V", + (void*) java_setFieldLong }, + { "setField", + "(Ljava/lang/Object;Ljava/lang/Class;Ljava/lang/String;S)V", + (void*) java_setFieldShort }, + { "setField", + "(Ljava/lang/Object;Ljava/lang/Class;Ljava/lang/String;D)V", + (void*) java_setFieldDouble }, + { "setField", + "(Ljava/lang/Object;Ljava/lang/Class;Ljava/lang/String;Z)V", + (void*) java_setFieldBool }, + { "setField", + "(Ljava/lang/Object;Ljava/lang/Class;Ljava/lang/String;B)V", + (void*) java_setFieldByte }, + { "setField", + "(Ljava/lang/Object;Ljava/lang/Class;Ljava/lang/String;F)V", + (void*) java_setFieldFloat }, + { "setField", + "(Ljava/lang/Object;Ljava/lang/Class;Ljava/lang/String;C)V", + (void*) java_setFieldChar }, + { "setField", + "(Ljava/lang/Object;Ljava/lang/Class;Ljava/lang/String;I)V", + (void*) java_setFieldInt }, + { "newInstance", + "(Ljava/lang/Class;Ljava/lang/Class;)Ljava/lang/Object;", + (void*) java_newInstance }, + { "objSetField", + "(Ljava/lang/Object;Ljava/lang/Class;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Object;)V", + (void*) java_setFieldObj } + +}; +int register_java_io_ObjectInputStream(JNIEnv* env) { + return jniRegisterNativeMethods(env, "java/io/ObjectInputStream", gMethods, NELEM(gMethods)); +} |