Exemplo n.º 1
0
func (self *Environment) ToIntArray(arrayObj *Object) (array []int) {
	alen := C.envGetArrayLength(self.env, arrayObj.object)
	_false := C.jboolean(C.JNI_FALSE)
	ptr := C.envGetIntArrayElements(self.env, arrayObj.object, &_false)
	defer C.envReleaseIntArrayElements(self.env, arrayObj.object, ptr, 0)
	bytes := C.GoBytes(unsafe.Pointer(ptr), C.int(alen)*4)
	array = (*(*[1024 * 1024]int)(unsafe.Pointer(&bytes)))[0:int(alen)]
	return
}
Exemplo n.º 2
0
func (self *Environment) ToObjectArray(arrayObj *Object) []*Object {
	var glen int
	if arrayObj.object == nil {
		glen = 0
	} else {
		jlen := C.envGetArrayLength(self.env, arrayObj.object)
		glen = int(jlen)
	}
	objs := make([]*Object, glen)
	for i := 0; i < glen; i++ {
		objs[i] = &Object{C.envGetObjectArrayElement(self.env, arrayObj.object, C.jsize(i))}
	}
	return objs
}
Exemplo n.º 3
0
func (self *Environment) ToString(strobj *Object) (str string, isNull bool, err error) {
	var bytesObj *Object
	bytesObj, err = self.CallObjectObj(strobj, false, "getBytes", types.Array{types.Basic(types.ByteKind)}, self.utf8())
	if err == nil && bytesObj == nil {
		isNull = true
		return
	}
	if err == nil {
		defer self.DeleteLocalRef(bytesObj)
		alen := C.envGetArrayLength(self.env, bytesObj.object)
		_false := C.jboolean(C.JNI_FALSE)
		ptr := C.envGetByteArrayElements(self.env, bytesObj.object, &_false)
		defer C.envReleaseByteArrayElements(self.env, bytesObj.object, ptr, 0)
		str = string(C.GoBytes(unsafe.Pointer(ptr), C.int(alen)))
	}
	return
}