Monday, May 30, 2016

Re: Convert Bytes from byte[] to data types

Maybe you can use this for inspiration... we used this to read binary files and decode in the client side. We transform the field in a byte[], after that converting to strings (new String(b, "ISO-8859-1")) or ints are trivial. You can do something as simple as int x = byte[0]; or are more advanced like.
public static long convertIntoUnsigned4ByteInt(byte[] b) {
long l = 0;

long al = ( ( (long)b[ 0 ] ) & 0xff ) << 24 ;
long bl = ( ( (long)b[ 1 ] ) & 0xff ) << 16 ;
long cl = ( ( (long)b[ 2 ] ) & 0xff ) << 8 ;

int di = ( b[ 3 ] & 0xff );
long dl = ( (long)di ) << 0;

l = al + bl + cl + dl;

return l;
All this just work. I have a file drag&drop example here Not sure if useful, but is the original point of the other example (gist). Transforming it to a byte[] is not very performant (byte are emulated in gwt), but is easier and our library already exists and use byte[] everywhere. 

On Sunday, May 29, 2016 at 7:15:21 PM UTC+2, Jens wrote:
Never done it but I would say so. GWT supports new String(byte[]) with UTF-8, LATIN-1, ISO_8859_1 charsets. For numbers you probably have to use BigInteger or do the conversion yourself as GWT does not emulate ByteBuffer.wrap(..).get...() for now.

-- J.

You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To post to this group, send email to
Visit this group at
For more options, visit

No comments:

Post a Comment