mirror of https://github.com/kivy/pyjnius.git
supports bytearray as argument for byte[]. Useful for socket/bluetooth reading (no need to read one by one)
This commit is contained in:
parent
5b4378ac85
commit
5bb7e6cfdb
|
@ -97,7 +97,7 @@ cdef void populate_args(JNIEnv *j_env, tuple definition_args, jvalue *j_args, ar
|
|||
if isinstance(py_arg, ByteArray) and argtype != '[B':
|
||||
raise JavaException(
|
||||
'Cannot use ByteArray for signature {}'.format(argtype))
|
||||
if not isinstance(py_arg, (list, tuple, ByteArray)):
|
||||
if not isinstance(py_arg, (bytearray, list, tuple, ByteArray)):
|
||||
raise JavaException('Expecting a python list/tuple, got '
|
||||
'{0!r}'.format(py_arg))
|
||||
j_args[index].l = convert_pyarray_to_java(
|
||||
|
|
|
@ -332,7 +332,7 @@ cdef int calculate_score(sign_args, args, is_varargs=False) except *:
|
|||
score += 10
|
||||
continue
|
||||
|
||||
if r == '[B' and isinstance(arg, ByteArray):
|
||||
if r == '[B' and isinstance(arg, (bytearray, ByteArray)):
|
||||
score += 10
|
||||
continue
|
||||
|
||||
|
|
|
@ -19,3 +19,11 @@ class StringArgumentForByteArrayTest(unittest.TestCase):
|
|||
self.assertEquals(
|
||||
arr,
|
||||
[127, 1, -127])
|
||||
|
||||
def test_create_bytearray(self):
|
||||
StringBufferInputStream = autoclass('java.io.StringBufferInputStream')
|
||||
nis = StringBufferInputStream("Hello world")
|
||||
barr = bytearray("\x00" * 5)
|
||||
self.assertEquals(nis.read(barr, 0, 5), 5)
|
||||
self.assertEquals(barr, "Hello")
|
||||
|
||||
|
|
Loading…
Reference in New Issue