if(set.size()>0){
goods = set.get(0);
String path = StorageAddress.getValue(siteid)+goods.getEISBN()+"/"+goods.getFileName();
try {
HttpServletResponse response = za.getResponse();
long haveLength=0;
LogUtil.info("文件地址为:"+path);
File file = new File(path);
if(file.exists()){
result.put("result", 1);
long bookFileLength = file.length();
if ( $V("Range") != null){
response.setStatus(HttpServletResponse.SC_PARTIAL_CONTENT);//206
haveLength = Long.parseLong(za.getRequest().getHeader("Range").replaceAll("bytes=","").replaceAll("-",""));
}
response.addHeader("Content-Length", new Long(bookFileLength - haveLength).toString());
response.addHeader("Content-Range","bytes " + new Long(haveLength).toString() + "-" + new Long(bookFileLength -1).toString() + "/" + new Long(bookFileLength).toString());
response.setContentType("applicatio" + "n/octet-stream");
response.setHeader("Content-Disposition", "attachment;filename=\"" + file.getName() + "\"");
FileInputStream fis = new FileInputStream(file);
fis.skip(haveLength);
byte[] b = new byte[1024];
int i;
while ( (i = fis.read(b)) != -1 ){
response.getOutputStream().write(b,0,i);
}
fis.close();
return;
}else{
result.put("result", 0);
result.put("message", "EISBN对应的电子书不存在");
}
} catch (Exception e) {
e.printStackTrace();
}