Re: Easy way to print hex rendering of byte[]
Claude Brisson <[email protected]> Sat, 14 Oct 2017 01:08:53 +0200
| Newsgroups | gmane.comp.jakarta.velocity.user |
|---|---|
| Message-ID | <[email protected]> |
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
Claude
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
>