I want to do cleanup of files after creating zip file. One of those action is to delete the zip file itself.
@RequestMapping(path = "/downloadZip", method = RequestMethod.GET)
public ResponseEntity<Resource> download(String fileName) throws IOException {
//Create a zip file and add entries
Path path = Paths.get(file.getAbsolutePath());
ByteArrayResource resource = new ByteArrayResource(Files.readAllBytes(path));
return ResponseEntity.ok()
.headers(headers)
.contentLength(file.length())
.contentType(MediaType.parseMediaType("application/octet-stream"))
.body(resource);
//Call a cleanup method
//cleanUp();
}
In the Junit tests, I was able to delete the zip file using static method AfterClass .
Question: How to define a method which gets after the return.
Thanks!