View difference between Paste ID: JPEEE48u and QNiiRLjx
SHOW: | | - or go back to the newest paste.
1
Download video file: 
2
3
http://www.filedropper.com/backup_11
4
5
Call: 
6
7
serve(response, Paths.get("/path/to/" + "backup" + ".mp4").toFile());
8
9
Method:
10
11
public static void serve(HttpServletResponse response, File file) throws IOException {
12
                response.setContentType("application/octet-stream");
13
                // response.setHeader  ("Content-Disposition", "attachment;filename=filename.mp4");
14
                response.setHeader("Content-Type", "video/mp4");
15
                
16
                int BUFFER_SIZE = 512;
17
                try (
18
                        BufferedInputStream input  = new BufferedInputStream(new FileInputStream(file), BUFFER_SIZE);
19
                        BufferedOutputStream output = new BufferedOutputStream(response.getOutputStream(), BUFFER_SIZE);
20
                ) {
21
                        byte[] bytes = new byte[BUFFER_SIZE];
22
                        int length;
23
                        while ((length = input.read(bytes)) > 0) {
24
                                output.write(bytes, 0, length);
25
                        }
26
                }
27
        }