Re: Easy way to print hex rendering of byte[]

Christopher Schultz <[email protected]> Sat, 14 Oct 2017 10:15:02 -0400
Newsgroups gmane.comp.jakarta.velocity.user
Message-ID <[email protected]>
Claude,

On 10/13/17 7:08 PM, Claude Brisson wrote:
> For very short arrays, I guess that this would do the trick:
> 
> #set($str = 'dummy string') ## to access String static methods
> #foreach($b in $bytes)$str.format('%02x',$b)#end

*facepalm*

I keep forgetting that Java finally added string-formatting :)

Thanks,
-chris

> On 13/10/2017 23:39, Christopher Schultz wrote:
>> All,
>>
>> Before I spend a whole lot of time on this, is there a dead-simple way
>> in VTL + stock Velocity Tools to take a byte[] reference and print-out a
>> hex-rendering of it? Like:
>>
>> Java (roughly):
>> byte[] bytes = new byte[] { 0xa, 0xb, 0x12 };
>> ctx.put("bytes", bytes);
>> template.render(ctc);
>>
>> VTL:
>> my array in hex: magic($bytes)
>>
>> Where the output is:
>> 0a0b12
>>
>> What could "magic" be?
>>
>> I have a static method in Java that can easily do it, so I could pop the
>> java.lang.Class object into the context, but I was wondering if there
>> was an easy way to do it without changing my Java code.
>>
>>
>> Thanks,
>> -chris
>>
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
signature.asc (application/pgp-signature, 938 B)
-----BEGIN PGP SIGNATURE-----
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQIzBAEBCAAdFiEEMmKgYcQvxMe7tcJcHPApP6U8pFgFAlniG+YACgkQHPApP6U8
pFgv5hAAgDRrSRXuVD+sDmePypW2T7UDhh9Ty9YXVjZMIiaA7Ewj/hku2yWJCCe6
8dSJGNr9kLhVR1A4iAAgGan/2PCyvmQO0fcxz/kprMwQK9A+AopAji8xzA/LfvrP
3RDiqvxNA69m2NK0TEFD2QioOMMIIF9gLyJzqil0oXqNan/eUSjR/Beaqo2iHtrY
reyRTgmJJU/JjaCBXLI1w8w4ysmQ2/SenUTYpU9xqulu5yU52sv2by01fk2J2Nwy
y4EI1/pcyAuuqnUaeExUDBsb3S+4AV5NGRR4Fw1g6a9P1z1n4m23wAWlW4O0ut31
SnmQbe5gBLtHuxuoUK/6chG0SnLYnDViE2uYnLcz0L5NQMkCauesQciV67hIFaoc
2ZGDDXAqa6xiywLqodwtkeG55MzCPNAd6De2WEsRZa8I+/ogwcqUdcIMHIaEspz8
TqIyCWgn6HyA26N4RdkZ1hMVr1Cf6sY6SqhMVa5I6o6NkLE0oCqTMvZnls1tf4YV
I60SE4MAbdzcq/o6bB/4b8S7C/ZxeuMrKL+YWtQrNeoMMkrIX54EL10/cMBloqTR
dDDLqW8AYcF9FBARRQAmImAm1bvTXuqFcvND4YLY2vvh9e+e/Yu6LhIH3ACOMS5g
bzdo/VnZdaQ/F5sXGfvt1TOXjqPtvjxNpRAZoy5cwE/LaexPl0o=
=NPBr
-----END PGP SIGNATURE-----