示例#1
0
 @RequestMapping("/ds/{filename}")
 @ResponseBody
 public void displayFile(@PathVariable("filename") String filename, HttpServletResponse response) {
   Result result = this.fileService.displayFile(filename);
   if (result.isSuccess()) {
     InputStream stream = (InputStream) result.getModel("inputStream");
     try {
       OutputStream outputStream = response.getOutputStream();
       if (stream != null) {
         BufferedInputStream bis = new BufferedInputStream(stream, 128);
         while (true) {
           int _current = bis.read();
           if (_current < 0) {
             break;
           }
           outputStream.write((byte) _current);
         }
       }
     } catch (Exception e) {
       //
     } finally {
       try {
         stream.close();
       } catch (Exception e) {
         //
       }
     }
   }
 }
示例#2
0
  @RequestMapping("/ds/{path}/{filename}")
  @ResponseBody
  public void displayImage(
      @PathVariable("filename") String filename,
      @PathVariable("path") String path,
      HttpServletResponse response) {

    Result result = this.fileService.displayImage(filename, path);
    if (result.isSuccess()) {
      InputStream stream = (InputStream) result.getModel("inputStream");
      try {
        OutputStream outputStream = response.getOutputStream();
        if (stream != null) {
          BufferedInputStream bis = new BufferedInputStream(stream, 128);
          while (true) {
            int _current = bis.read();
            if (_current < 0) {
              break;
            }
            outputStream.write((byte) _current);
          }
        }
        //                String timestamp = (String)result.getModel("timestamp");
        //                if(timestamp != null) {
        //                    response.addDateHeader("Last-Modified",Long.valueOf(timestamp));
        //                }
      } catch (Exception e) {
        //
      } finally {
        try {
          stream.close();
        } catch (Exception e) {
          //
        }
      }
    }
  }