二进制数据和GWT [英] Binary Data and GWT

查看:175
本文介绍了二进制数据和GWT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有几个关于二进制数据和GWT已经问题。阅读后我仍然不知道,如果以下是可能的或不是(我是一个完整的GWT初学者虽然!)

There are a couple of questions about binary data and GWT already. After reading them I am still not sure if the following is possible or not (I am a complete GWT beginner though!):

我有一些非常复杂的数据文件只以二进制形式存在,我无法将它们转换为像XML或JSON。我有一个封闭源代码库,虽然接受一个byte [],并返回一个Java对象,我可以使用。为了让我的GWT应用程序内运行I'打印'在一个.java文件,我从我的GWT应用code访问这些二进制数据文件和硬codeD生成的字节[]之一。一切工作正常。显然,这只是一个测试,并在部署应用程序,我不能硬code的数据文件。我想将它们放在我的GWT应用所在的目录和负荷他们与我的GWT应用程序。

I have some very complicated data-files with only exist in binary form and I cannot convert them to something like XML or JSON. I have a closed source library though that accepts a byte[] and returns a Java object I can use. To get my GWT-app running I 'printed out' one of those binary data files and hard-coded the resulting byte[] in a .java file I access from my GWT-app code. Everything works fine. Obviously this is only a test and in the deployed app I cannot hard-code those data-files. I want to place them in the directory my GWT-app resides and the 'load' them with my GWT app.

我把它我可以负载的文本文件,从我与GWT的服务器,对不对?为什么我不能读取GWT二进制数据?或者我可以读取二进制数据文件为文本和字符串转换为字节[]?我读了很多关于base64编码和GWT可以读取它,但我真的不明白他们在说什么。我可以配置我的服务器服务于那些二进制数据文件为base64 EN codeD,然后使用GWT读?

I take it I can 'load' text files from my server with GWT, right? Why can't I read binary data with GWT? Or can I read the binary-data-files as text and the String into a byte[]? I read a lot about base64 encoding and that GWT can read it, although I don't really understand what they are talking about. Can I configure my server to serve those binary-data-files as base64 encoded and then read them with GWT?

或者是有一些其他的解决办法?我不想接触任何JS code,如果我能帮助它。这就是为什么我开始使用GWT)

Or is there some other solution? I wouldn't like to touch any JS code if I can help it. That's why I started using GWT ;)

感谢您的帮助:)

推荐答案

让我们presume我们对HTML 4。

Let's presume we are on HTML 4.

GWT客户端不能读的文件。 GWT客户端的JavaScript是在浏览器中运行。浏览器安全性不允许你读本地文件。你必须得到该servlet代理读取文件在服务器上。

GWT client cannot "read" files. GWT client is javascript running on a browser. Browser security does not allow you to read local files. You have to get the servlet to proxy read the file for you on the server.

由于您希望浏览器下载文件并调用本地PC来调用相应的软件您可以设置一个文件的MIME类型 - 例如PDF援引PDF阅读器或XLS调用MS Excel中。无关GWT的Java或Javascript(除了启用下载)。

You set the mime type for a file because you want the browser to download a file and invoke the local PC to invoke the appropriate software - for example, pdf to invoke pdf reader or xls to invoke ms excel. Nothing to do with GWT Java or Javascript (except to enable the download).

为什么需要GWT客户端读取的二进制文件?如果你这样做,你的架构可能是错误的。 错是一个无情的话。也许,错位是一个更好的词。你瘦AJAX客户端 - 服务器的概念是错位。放下你的桌面处理概念和习惯在门口,当你进入GWT的门。

Why do you need GWT client to read the binary file? If you do, your architecture is probably wrong. "Wrong" is an unkind word. Perhaps, misaligned is a better word. Your concept of AJAX thin client-server is misaligned. Drop your desktop processing concepts and habits at the door when you enter the door of GWT.

GWT是Java,但不是Java

我一直有提醒人们,GWT的Java仅仅是JavaScript的一个更加一致的再presentation。当你code在GWT的Java,永远记住你是在Javascript不是Java编码的实际。所有的Java源代码翻译为Javascript

I keep having to remind people that GWT Java is merely a more coherent representation of Javascript. When you code in GWT Java, always remember you are actually coding in Javascript not Java. All Java source is translated to Javascript

因此​​,GWT编译器需要在源$ C ​​$ C中提供的所有Java类。 GWT编译器有没有能力为Java字节code JAR /类文件翻译成JavaScript。如果你的库是在字节code或源库调用一个字节code库下的任何地方调用链,编译将会失败。

Therefore, the GWT compiler needs all Java classes to be supplied in source code. The GWT compiler has no ability to translate Java bytecode jar/class files into Javascript. If your library is in bytecode or your source library calls a bytecode library anywhere down the calling chain, the compilation will fail.

服务器端和客户端之间的GWT混乱

GWT RPC有时是GWT新手混乱的根源。他们似乎没有意识到远程的servlet是因为它是在服务器上运行的是编译成字节code中的一部分。尤其如此,如果你正在使用Vaadin - 因为他们有这么故意模糊了服务器和浏览器之间的界限。这样一来,GWT新手熄灭疑惑,为什么我的字节code库的应用程序的某些部分只工作?

GWT RPC is sometimes source of confusion for GWT newbies. They don't seem to realise that the remote servlet is the only part that is compiled into bytecode because it is running on the server. Especially so, if you are using Vaadin - because they have so intentionally blurred the line between server and browser. And so the GWT newbie goes off wondering, "why do my bytecode libraries work at certain parts of the app only?"

Ajax客户端服务器架构

GWT仅仅是一个网络功能的UI。你为什么不能做你想要做的服务器上,并让服务器反映无论它是什么做或做的UI?为什么一定要它在浏览器上做了什么?

GWT is merely a web enabled UI. Why can't you do whatever you want to do on the server and let the server reflect what it is doing or has done to the UI? Why must it be done on the browser?

试想一下,你的GWT接口作为改装成了JSP。想象一下你正在编写一个JSP。你得到你的JSP到你的二进制数据吮吸到浏览器,并获得JSP生成JavaScript来有分析二进制数据?

Just imagine your GWT interface as a souped up JSP. Imagine you are writing a JSP. Do you get your JSP to suck your binary data into the browser and get the JSP to generate Javascript to analyse the binary data there?

我已经写复杂的统计分析和我只是使用的浏览器作为正在服务器上做什么的反映。工程师认为他/她在运行分析他/她的PC上。图表/生成报表。但是这一切都在服务器上通过调用SAS完成。

I have written complex statistical analyses and I merely used the browser as a reflection of what is being done on the server. The engineer thinks he/she is running the analysis on his/her PC. Charts/reports are generated. But it's all done on the server by calling SAS.

面向服务的模式/架构

您服务器将present服务。您的浏览器客户端GWT将这些服务请求。
打开文件,读取文件,分析文件,生成分析的可视化/ MIME重新presentation并把它传递给浏览器。简单地认为GWT的浏览器客户端为您的基于服务器的操作显示屏中。 GWT是一个魔术师的把戏来帮我想象的错觉,让工程师们觉得他们在本地PC上进行分析。作为工程师,当然,大多数人知道浏览器是不实际做的工作。

Your server will present services. Your browser GWT client will request for those services. Open a file, read the file, analyse the file, generate a visual/mime representation of analysis and pass it to the browser. Simply think of the GWT browser client as the display monitor for your server based manipulation. GWT is a magician's trick to help me conjure the illusion to let the engineers feel they are performing analysis on the local PC. Being engineers, of course, most of them know the browser is not actually doing the work.

当你的用户是满意的分析,让您的服​​务生成结果的MIME-RE presentation这样就可以通过浏览器下载的哑剧为映射来调用相应的本地PC软件。

When your user is satisfied with the analysis, get your service to generate a mime-representation of the results so that it could be downloaded by the browser to invoke the appropriate local PC software as mapped by the mime.

不要在服务器上,并反映其在浏览器上。

Do it on the server and reflect it on the browser.

进一步修改:关于二进制数据...

Further Edits: Concerning binary data ...

背后base64编码的动机在Web应用程序中使用:身份验证令牌,图片,音频文件传输 - 让自己的二进制重新presentation和测序不会受到建筑的细微差别像字节序被搞砸了。

The motivation behind base64 encoding being used in web apps: transmission of auth tokens, picture, audio files - so that their binary representation and sequencing would not be messed up by architectural nuances like endianness.

例如,不要试图写一个浏览器应用程序读取原始二进制US preadsheet - 始终让服务器把它翻译成XML或JSON(preferably JSON),其中任何二进制元素应使用base64 EN codeD,将其发送给浏览器应用程序之前。或者,如果你的人生的目的是攀登珠穆朗玛峰,创造一个体系结构无关的编码到位的base64来传输二进制数据。

e.g., do not attempt writing a browser app to read a raw binary spreadsheet - always have the server translate it into XML or JSON (preferably JSON) where any binary element should be base64 encoded, before sending it to the browser app. Or if the purpose of your life is to climb Mt Everest, invent an architecture-agnostic encoding in place of base64 to transmit binary data.

使用二进制只有当信息它是浏览器的操作系统的处理(如音频,图片,PDF文件)。在发送二进制数据没有一点用JavaScript例程单独进行处理。的JavaScript程序必须使用外部处理时间(除非再次,如果在你的生活目的就是爬......)翻译。

Use only binary info if it was for the browser's OS processing (like audio, pictures, pdfs). No point in sending binary data to be processed solely by a javascript routine. The javascript routine would have to use extraneous processing time to translate it (unless again, if the purpose in your life is to climb ... ).

这篇关于二进制数据和GWT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆