关注JEECG发展历程 关注最新动态和版本, 记录JEECG成长点滴 更新日志 - 技术支持 - 招聘英才

JEECG最新版本下载 JEECG智能开发平台 - 显著提高开发效率 常见问题 - 入门视频 - 参与开源团队

商务QQ: 69893005、418799587 商务热线(5*8小时): 010-64808099 官方邮箱: jeecgos@163.com

查看: 4431|回复: 0

下载视频的时候内存溢出

[复制链接]
发表于 2016-2-1 11:12:52 | 显示全部楼层 |阅读模式
本帖最后由 jeecgadmin 于 2016-2-1 11:13 编辑

Exception in thread "http-apr-8080-exec-7"
java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOf(Arrays.java:2271)
at java.io.ByteArrayOutputStream.grow(ByteArrayOutputStream.java:113)
at java.io.ByteArrayOutputStream.ensureCapacity(ByteArrayOutputStream.java:93)
at java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:140)
at java.util.zip.GZIPOutputStream.finish(GZIPOutputStream.java:169)
at java.util.zip.DeflaterOutputStream.close(DeflaterOutputStream.java:238)
at org.jeecgframework.core.aop.GZipFilter.gzip(GZipFilter.java:120)
at org.jeecgframework.core.aop.GZipFilter.doFilter(GZipFilter.java:50)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at com.alibaba.druid.support.http.WebStatFilter.doFilter(WebStatFilter.java:140)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.springframework.orm.hibernate4.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:119)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2522)




------代码如下:
public HttpServletResponse doviewOrDownloadFile(UploadFileWdgl uploadFile,ReflectHelper reflectHelper) {
  uploadFile.getResponse().setContentType("UTF-8");
  uploadFile.getResponse().setCharacterEncoding("UTF-8");
  InputStream bis = null;
  BufferedOutputStream bos = null;
  HttpServletResponse response = uploadFile.getResponse();
  HttpServletRequest request = uploadFile.getRequest();
  
  long fileLength = 0;
  String downLoadPath = "";
  String videoType = "mp4,wmv,avi,rmvb,rm,mts";
  if(videoType.contains(uploadFile.getExtend())){
   String rootPath = ResourceUtil.getConfigByName("file_home");
   String videoPath = ResourceUtil.getConfigByName("video_home");
   downLoadPath = rootPath +"/"+ videoPath + uploadFile.getRealPath();
   if (uploadFile.getRealPath() != null && uploadFile.getContent() == null) {
    fileLength = new File(downLoadPath).length();
   
    try {
     if(fileLength == 0)return response;
     bis = new BufferedInputStream(new FileInputStream(downLoadPath));
    } catch (FileNotFoundException e) {
     e.printStackTrace();
    }
   }
  }
  try {
   if (!uploadFile.isView() && uploadFile.getExtend() != null) {
    if (uploadFile.getExtend().equals("text")) {
     response.setContentType("text/plain;");
    } else if (uploadFile.getExtend().equals("doc")) {
     response.setContentType("application/msword;");
    } else if (uploadFile.getExtend().equals("xls")) {
     response.setContentType("application/ms-excel;");
    } else if (uploadFile.getExtend().equals("pdf")) {
     response.setContentType("application/pdf;");
    } else if (uploadFile.getExtend().equals("jpg") || uploadFile.getExtend().equals("jpeg")) {
     response.setContentType("image/jpeg;");
    } else {
     response.setContentType("application/x-msdownload;");
    }                 
    response.setHeader("Content-disposition", "attachment; filename=" + new String((uploadFile.getTitleField() + "." + uploadFile.getExtend()).getBytes("GBK"), "ISO8859-1"));
    response.setHeader("Content-Length", String.valueOf(fileLength));
   }
   bos = new BufferedOutputStream(response.getOutputStream());
   byte[] buff = new byte[2048];
   int bytesRead;
   while (-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
    bos.write(buff, 0, bytesRead);
   }
   
  } catch (IOException e) {
   e.printStackTrace();
  } finally {
   try {
    if (bis != null) {
     bis.close();
    }
    if (bos != null) {
     bos.close();
    }
   } catch (IOException e) {
    e.printStackTrace();
   }
  }
  return response;
}

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表