JSP如何以二进制形式、以分块的形式返回数据
lfyos 2016-08-15 06:40:33 文件是视频文件很大,由于权限限制,不能让客户直接下载。因此自己写了下面三个函数。
public void set_content_type(String content_type) //设置返回数据的格式
{
response.setContentType(content_type);
}
public boolean do_response_binary_data(byte data_buf[],int length) ///向客户返回数据
{
try{
if(output_stream==null)
output_stream=response.getOutputStream();
output_stream.write(data_buf,0,length);
return false;
}catch(Exception e){
return true;
}
}
public void terminate_response_binary_data() //读写完毕后执行该函数
{
if(output_stream!=null){
try{
response.flushBuffer();
out.clear();
}catch(Exception e){
;
}
out=pagecontext.pushBody();
}
}
对于小文件工作很好。大文件就不行了。
对于大型视频文件,文件太大,肯定是分块传输的。怎么实现分块传输呢?
谢谢!