I'm having an issue with the following code.
byte[] array = data as byte[]; // compile error - unable to use built-in conversion
if (array != null) { ...
I only want to assign the data to array variable if the data is actually a byte array.
In order to determine if an object is an Object is an array in Java, we use the isArray() and getClass() methods. The getClass() method method returns the runtime class of an object.
Read the image using the read() method of the ImageIO class. Create a ByteArrayOutputStream object. Write the image to the ByteArrayOutputStream object created above using the write() method of the ImageIO class. Finally convert the contents of the ByteArrayOutputStream to a byte array using the toByteArray() method.
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..
The bytearray type is a mutable sequence of integers in the range between 0 and 255. It allows you to work directly with binary data. It can be used to work with low-level data such as that inside of images or arriving directly from the network. Bytearray type inherits methods from both list and str types.
Try
if(data.GetType().Name == "Byte[]")
{
// assign to array
}
How about this:
byte[] array = new byte[arrayLength];
if (array is byte[])
{
// Your code
}
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