A glace on Java Stream

     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. 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值