@GetMapping("/reportFile")@ApiOperation(produces=MediaType.APPLICATION_JSON_VALUE,httpMethod="GET",response=String.class,value="GetAll feed back plans based on planMatch and cost",notes="Sample note")publicvoidprocessFileAndOutput(HttpServletResponseres){//Read the file from an FTP server//For now read it from the resource folder// ApplicationHome home = new ApplicationHome(this.getClass());// File dir = home.getDir();// System.out.println("dfs"+dir);PathfilePath=Paths.get(System.getProperty("user.dir")+"/static/test.txt");//Path path =Paths.get("/Users/A634885/STS/workspace/FeedBackAPI/static/test.txt");System.out.println(filePath);try{List<FileReadDTO>list1=fileService.readFileFromFTPAndGenerateObjects(filePath);list1.forEach(item->System.out.println(item));StringfileName="reportFile.txt";FileOutputStreamoutput=newFileOutputStream(System.getProperty("user.dir")+"/static/"+fileName);list1.forEach(item->{System.out.println("IN each iteration");try{output.write(item.getPlanNbr().getBytes());output.write(item.getSsnNumber().getBytes());output.write(item.getDivision().getBytes());output.write(item.getRestOfFile().getBytes());output.write("\n".getBytes());}catch(IOExceptione){// TODO Auto-generated catch blocke.printStackTrace();}});System.out.println("before closing");output.close();res.setContentType(MediaType.TEXT_PLAIN_VALUE);res.setHeader("Content-Disposition","attachment;filename="+fileName);//Path to output file//Path outputFilePath = Paths.get();//return new ResponseEntity<>("sdfds",HttpStatus.OK);FileCopyUtils.copy(newFileInputStream(newFile(System.getProperty("user.dir")+"/static/"+fileName)),res.getOutputStream());}catch(IOExceptione){thrownewRuntimeException("some err");}//get the configinfo from DB//perform some calculations//generate report file based on that}
Comments (0)
HTTPSSSH
You can clone a snippet to your computer for local editing.
Learn more.