Advertisement
Guest User

Untitled

a guest
Feb 11th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.93 KB | None | 0 0
  1. public static void serve(HttpServletResponse response, File file) throws IOException {
  2.                 response.setContentType("application/octet-stream");
  3.                 // response.setHeader  ("Content-Disposition", "attachment;filename=filename.mp4");
  4.                 response.setHeader("Content-Type", "video/mp4");
  5.                
  6.                 int BUFFER_SIZE = 512;
  7.                 try (
  8.                         BufferedInputStream input  = new BufferedInputStream(new FileInputStream(file), BUFFER_SIZE);
  9.                         BufferedOutputStream output = new BufferedOutputStream(response.getOutputStream(), BUFFER_SIZE);
  10.                 ) {
  11.                         byte[] bytes = new byte[BUFFER_SIZE];
  12.                         int length;
  13.                         while ((length = input.read(bytes)) > 0) {
  14.                                 output.write(bytes, 0, length);
  15.                         }
  16.                 }
  17.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement