Read in binary file into byte[] ?

145 views
Skip to first unread message

Carsten

unread,
May 22, 2012, 3:42:26 PM5/22/12
to Google Web Toolkit
Hi,

is it possible to read in a binary file in my GWT Java-code and
convert it into a byte[] ?

Thanks!
Carsten

Jim Douglas

unread,
May 22, 2012, 10:53:59 PM5/22/12
to Google Web Toolkit
Not in GWT proper, and not reliably in all browsers. Start your
reading here:

http://www.google.com/search?q=javascript+file+api

Carsten

unread,
May 23, 2012, 11:30:25 AM5/23/12
to Google Web Toolkit
I think I should have been more clear. I don't want to load a file
from the users computer. I want to read a file from the directory on
the server where my GWT app lives. I just want to know the options I
have to read this binary file into a byte[]. I am very new with GWT :)

Sebastian Gurin

unread,
May 23, 2012, 9:26:22 AM5/23/12
to google-we...@googlegroups.com
in general you don't use byte[] or the bynary content of a file directly in the client side, unless you are making something *really special* like implementing image filters using html canvas or somthing like that. What are you trying to do or better, why do you have to read a file into a byte[] in the client side?
> --
> You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
> To post to this group, send email to google-we...@googlegroups.com.
> To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
>


--
Sebastian Gurin <sgu...@softpoint.org>

Carsten

unread,
May 23, 2012, 12:39:03 PM5/23/12
to Google Web Toolkit
Well, it is a binary file with point/spline-data. I need to construct
eventually Path objects out of this data and draw it on a canvas. A
byte[] would be the perfect data structure to hold this data.
> > For more options, visit this group athttp://groups.google.com/group/google-web-toolkit?hl=en.
>
> --
> Sebastian Gurin <sgu...@softpoint.org>

Jim Douglas

unread,
May 23, 2012, 1:02:04 PM5/23/12
to Google Web Toolkit
If the goal is to read a file and perform computations on the data,
then that process belongs on the server, where it can be done in Java,
and on a machine that has significantly more horsepower. Process the
data as much as makes sense for your application, then ship the
processed data over to the client as the final step.

Sebastian Gurin

unread,
May 23, 2012, 10:10:56 AM5/23/12
to google-we...@googlegroups.com
so I guess it is an array of points and you wish to represent them as byte[]. In the client side, I think byte[], int[] or double[] are the same internally, since javascript only support a single Number type. Most charting / graphics libraries will accept a native javascript array of numbers as the input I suppose that is your case. Also I suspect you have already the points prepared, at the server side in binary format. What I sould do is create a servlet that reads those files in the server side and return a JSON array of numbers. Then in javascript (client side) you call this servlet with ajax, perform eval() for obtaining the javascript array of values, and do the drawing using that javsacript array of numbers. Hope that helps.
> For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
>


--
Sebastian Gurin <sgu...@softpoint.org>

Joseph Lust

unread,
May 23, 2012, 1:18:12 PM5/23/12
to google-we...@googlegroups.com
See the Google IO games lecture @ 33:50, they discuss this issue in GWT with binary data transfers:


Sincerely,
Joseph

Sebastian Gurin

unread,
May 23, 2012, 11:24:32 AM5/23/12
to google-we...@googlegroups.com
they mention passing the binary data using utf strings. I wonder if in the server side we can use TextResource.getText().getBytes("UTF-8") safely for that.

Also it uses JavaScript typed arrays (new FLoat32Array) for accssing the array in javascript but I wonder if that is really neccesary.

Very nice video thanks for sharing.
> --
> You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
> To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/s-mnpgM9x3MJ.
Reply all
Reply to author
Forward
0 new messages