简体   繁体   中英

Byte array to string conversion using groovy script in Mule 3.9

I am fetching datasets from redis(Get all from hash) cache and need to do the string comparison. I am trying to use a groovy component inside mule(3.9) flow for having string comparison. The payload, which is extracted from Redis is of type: Object(field=value pair), and I need to convert Byte array to string on all the payload values. I have done this conversion inside mule flow using 'Byte array to string' converter component, however, I would need to do this conversion using Groovy script.

The [payload.values()] is having values as below -

[B@5ef66f56
[B@2649bce9
[B@16e8e092
[B@9006e18
[B@64613cb1
[B@fa47a20

Can someone please help me get the groovy script to convert from byte array to string ? I chose to use Groovy since I need to break from for loop if I find a match. any better option? please suggest. payloads from first 2 loggers Thanks

The most secret and not documented kung-fu to convert a byte[] into String is:

byte[] myBytes = ...
String myString = new String( myBytes )

or if you have a list of byte[] :

List<String> list = myListOfBytes.collect{ new String( it ) }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM