Today, I just finish the file operation on webdav. On the first eye, it will be more efficient for the proxy just set url to the client. But it trun out not more support by Java, may it has another swift operation, but I havenot find it.
Now, I just want to talk about the Stream in Java. After the translation I feel a little familiar will Stream, but it turn out so easy and simple, and have no help to transfer. In Java, there has two file type, one is the text file, the other is binary file. They just operate in a diffrent way. We could read textfile one word by word or line by line, and then some class help us to tranform the to the original Java object, where the write method has the same way. On the other hand, the binary just read or write in a streaming with byte code. And byte array will transfter to the orignal object, we also could use Serializable interface to transform our Object into byte code.
And what I want to do just build a connection betweent the destination resource and local resource. From example we invoke a webDave Service and use it as the from stream and wrap as InputStream, and the request from the client just invoke the response.getOutputStreaming() to write stream. The transfer betweent ftp and http in the same way. I use org.apache.commons.net.ftp to realize the ftp resource get, and use sarding to transfer the resource.
In the end, I find make a fool mistake, and I want to share it with you. I use a buffer(byte[1024*2]) to buffer the stream, and I encluspe the software both inputstream and outputstream. But there is alway something wrong with .gz files, and there is no problem with other file type. With the great seache engine, I found I just forget to statement the length of the buffer, and just the last portion will goes wrong, so it change it into read(buffer,0, buffere.lenght), everything work right.