问题
My goal is to upload a image(.jpg
or .png
) from client's folder to tomcat6 server through hessian protocol. And do image processing using opencv on server, then return the image back to client.
Question1. Is the following transfering steps correct?
- put a
test.jpg
image on client's folder-->
convert thetest.jpg
inclient.java
(main.java
) class toBufferedImage
-->
convert theBufferedImage
to mat orIplimage
in server for usingopenCV
.
I have set a hello world sample from Simple Messaging Example using Hessian , and searched from Hessian with large binary data and other websites, but still dont know how to use it!
Question2. Is there a related Java sample code?
(I am using ubuntu12+netbeans7.2)
回答1:
It sounds like you probably want to treat the image as a byte stream on the client, instead of using BufferedImage. After processing, you can do whatever you want, but it'll be easier to use hessian if you just send the file contents.
Hessian understand InputStream as a type. So your minimal method call API can look like
InputStream convert(InputStream upload);
The client would open an input stream to the original file and send that input stream directly:
InputStream is = new FileInputStream("test.jpg");
InputStream resultIs = hessianProxy.convert(is);
.... // save the result
A bit of caution that the hessian response connection will still be live until you finish reading the input stream, so you need to read it immediately. (It's not buffered, which is one reason it can be efficient.)
On the server, you need to read from the input stream (again, immediately). And as a result, return an InputStream that reads from your converted image:
InputStream convert(InputStream is) {
... // read from 'is' to your internal data
InputStream result = ... // process
return result;
}
You'll want to make sure the result input stream closes anything automatically on the end of file. You might want to create a wrapper to call close().
来源:https://stackoverflow.com/questions/12575872/image-ransfer-using-hessian-protocol-from-clients-folder-to-tomcat-server