Jarrod Roberson Jarrod Roberson - 1 year ago 69
Groovy Question

How do you cast an int to a byte and test against an entry in a byte[]?

Given the following code how do I get rid of the

Method threw
exception. Cannot cast object 'true' with class 'java.lang.Boolean' to
class 'byte'


byte[] pattern = [0x78,0x9C]
int b = 0
while ((b = stream.read()) != -1) {
while ((byte)b != pattern.getAt(j)) {
/* omitted for brevity */

For some reason it is insisting that
is a
when it is specifically declared as an
. This compiles and runs as Java code, but not as Groovy and I need this in a Groovy script.

Answer Source

The following code solves the problem:

b.byteValue() != pattern.getAt(j)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download