| Total Complexity | 2 |
| Total Lines | 28 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | package com.osomapps.pt.admin.program; |
||
| 13 | @RestController |
||
| 14 | @RequestMapping("api/v1/admin/program-file") |
||
| 15 | class AdminProgramFileResource { |
||
| 16 | |||
| 17 | private final AdminProgramService programService; |
||
| 18 | |||
| 19 | @Autowired |
||
| 20 | AdminProgramFileResource(AdminProgramService programService) { |
||
| 21 | this.programService = programService; |
||
| 22 | } |
||
| 23 | |||
| 24 | @GetMapping(value = "{id}/{fileName}") |
||
| 25 | @ResponseBody |
||
| 26 | Object findOne( |
||
| 27 | @PathVariable Long id, @PathVariable String fileName, HttpServletResponse response) |
||
| 28 | throws IOException { |
||
| 29 | try (FastByteArrayOutputStream outputStream = new FastByteArrayOutputStream()) { |
||
| 30 | final ProgramResponseDTO programResponseDTO = programService.findOne(id); |
||
| 31 | programService.dataUrlToOutputStream(programResponseDTO.dataUrl, outputStream); |
||
| 32 | response.setContentType(programResponseDTO.getFileType()); |
||
| 33 | response.setHeader( |
||
| 34 | "Content-disposition", |
||
| 35 | "attachment; filename=" + programResponseDTO.getFileName()); |
||
| 36 | outputStream.writeTo(response.getOutputStream()); |
||
| 37 | response.getOutputStream().close(); |
||
| 38 | outputStream.reset(); |
||
| 39 | } |
||
| 40 | return null; |
||
| 41 | } |
||
| 43 |