velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Schultz <ch...@christopherschultz.net>
Subject Re: Easy way to print hex rendering of byte[]
Date Sat, 14 Oct 2017 14:15:02 GMT
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: user-unsubscribe@velocity.apache.org
> For additional commands, e-mail: user-help@velocity.apache.org
> 


Mime
View raw message