Snippets

Vijay Kumar FileProcessCollector

Created by Vijay Kumar
@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")
	public void processFileAndOutput(HttpServletResponse res) {
		//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);
		Path filePath = 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));
		String fileName = "reportFile.txt";
		FileOutputStream output = new FileOutputStream(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 (IOException e) {
				// TODO Auto-generated catch block
				e.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(new FileInputStream(new File(System.getProperty("user.dir")+"/static/"+fileName)), res.getOutputStream());
		}catch(IOException e) {
			throw new RuntimeException("some err");
		}
		//get the configinfo from DB
		
		//perform some calculations
		
		//generate report file based on that
		
		
	}

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.