Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void serve(HttpServletResponse response, File file) throws IOException {
- response.setContentType("application/octet-stream");
- // response.setHeader ("Content-Disposition", "attachment;filename=filename.mp4");
- response.setHeader("Content-Type", "video/mp4");
- int BUFFER_SIZE = 512;
- try (
- BufferedInputStream input = new BufferedInputStream(new FileInputStream(file), BUFFER_SIZE);
- BufferedOutputStream output = new BufferedOutputStream(response.getOutputStream(), BUFFER_SIZE);
- ) {
- byte[] bytes = new byte[BUFFER_SIZE];
- int length;
- while ((length = input.read(bytes)) > 0) {
- output.write(bytes, 0, length);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement