I am developing with Jython and I need to use a Java method that requires a byte[]
as a parameter.
I tried:
def randomBytesArray(length):
data = []
for _ in xrange(length):
data.append(chr(random.getrandbits(8)))
methodThatNeedsBytesArrays(data)
But I get this error:
TypeError: methodThatNeedsBytesArrays(): 1st arg can't be coerced to byte[]
You can simply iterate the byte array and print the byte using System. out. println() method.
The byte keyword is a data type that can store whole numbers from -128 to 127.
Python bytearray() Function The bytearray() function returns a bytearray object. It can convert objects into bytearray objects, or create empty bytearray object of the specified size.
A byte array is simply an area of memory containing a group of contiguous (side by side) bytes, such that it makes sense to talk about them in order: the first byte, the second byte etc..
Sometimes you need to pass a byte array to a function so that the function will fill the byte array with a result. In that case, sending a Python string won't work because Python strings are immutable. Instead, create a Java byte array with the jarray module:
import jarray
bytes = jarray.zeros(100, "b")
length = zlibDeflater.deflate(bytes)
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With