Example usage for org.springframework.core.io FileSystemResource contentLength

List of usage examples for org.springframework.core.io FileSystemResource contentLength

Introduction

In this page you can find the example usage for org.springframework.core.io FileSystemResource contentLength.

Prototype

@Override
public long contentLength() throws IOException 

Source Link

Document

This implementation returns the underlying File/Path length.

Usage

From source file:com.anuz.dummyapi.controller.ClientController.java

@RequestMapping(value = "/contents_file/{id}", method = RequestMethod.GET)
public ResponseEntity<InputStreamResource> downloadFiles(@PathVariable("id") int id) throws IOException {

    List<Content> contentList = contentUpdateService.getUnsynchronizedContentList(id);
    if (!contentList.isEmpty()) {
        String fileName = "zipFile" + new Date().getTime() + ".zip";
        ZipUtil zipFile = new ZipUtil();
        for (Content content : contentList) {
            System.out.println(CONSTANTS.CONTENTS + content.getContentLocation());
            zipFile.generateFileList(new File(CONSTANTS.CONTENTS + content.getContentLocation()));
        }/*from   w  ww . j  a va2  s  . c o m*/
        String finalZip = zipFile.zipIt(CONSTANTS.CONTENTS + fileName);
        //            System.out.println(finalZip);
        //            if(finalZip!=null){
        //                contentUpdateService.updateContentStatus(id,Boolean.FALSE);
        //            }

        FileSystemResource file = new FileSystemResource(finalZip);

        //            return ResponseEntity.ok().contentLength(file.contentLength())
        //                    .contentType(MediaType.parseMediaType("application/octet-stream"))
        //                    .header("Content-Disposition", "attachment; filename=" + fileName)
        //                    .body(new InputStreamResource(file.getInputStream()));

        return ResponseEntity.ok().contentLength(file.contentLength())
                .contentType(MediaType.parseMediaType("application/zip"))
                .header("Content-Disposition", "attachment; filename=" + fileName)
                .body(new InputStreamResource(file.getInputStream()));

    }
    return ResponseEntity.ok().body(null);

}