Subversion Repositories SmartDukaan

Rev

Rev 29598 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 29598 Rev 30728
Line 1... Line 1...
1
package com.spice.profitmandi.common.util;
1
package com.spice.profitmandi.common.util;
2
 
2
 
3
import java.io.File;
-
 
4
import java.io.IOException;
-
 
5
import java.io.InputStreamReader;
3
import com.spice.profitmandi.common.enumuration.ContentType;
6
import java.io.PrintStream;
-
 
7
import java.io.Serializable;
4
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
8
import java.util.List;
-
 
9
 
-
 
10
import org.apache.commons.csv.CSVFormat;
5
import org.apache.commons.csv.CSVFormat;
11
import org.apache.commons.csv.CSVParser;
6
import org.apache.commons.csv.CSVParser;
12
import org.apache.commons.csv.CSVPrinter;
7
import org.apache.commons.csv.CSVPrinter;
13
import org.apache.commons.csv.CSVRecord;
8
import org.apache.commons.csv.CSVRecord;
14
import org.apache.commons.io.output.ByteArrayOutputStream;
9
import org.apache.commons.io.output.ByteArrayOutputStream;
15
import org.apache.logging.log4j.LogManager;
10
import org.apache.logging.log4j.LogManager;
16
import org.apache.logging.log4j.Logger;
11
import org.apache.logging.log4j.Logger;
17
import org.apache.tika.Tika;
12
import org.apache.tika.Tika;
18
import org.springframework.web.multipart.MultipartFile;
13
import org.springframework.web.multipart.MultipartFile;
19
 
14
 
20
import com.spice.profitmandi.common.enumuration.ContentType;
15
import java.io.*;
21
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
16
import java.util.List;
22
 
17
 
23
public class FileUtil {
18
public class FileUtil {
24
 
19
 
25
	private static final Logger LOGGER = LogManager.getLogger(FileUtil.class);
20
	private static final Logger LOGGER = LogManager.getLogger(FileUtil.class);
26
 
21
 
Line 69... Line 64...
69
		List<CSVRecord> records = parser.getRecords();
64
		List<CSVRecord> records = parser.getRecords();
70
		LOGGER.info("records" + records);
65
		LOGGER.info("records" + records);
71
		LOGGER.info("parser" + parser);
66
		LOGGER.info("parser" + parser);
72
		if (records.size() < 2) {
67
		if (records.size() < 2) {
73
			parser.close();
68
			parser.close();
-
 
69
			throw new ProfitMandiBusinessException("Uploaded File", "", "No records Found");
-
 
70
		}
-
 
71
		// Remove header
-
 
72
		records.remove(0);
-
 
73
		parser.close();
-
 
74
		return records;
-
 
75
 
-
 
76
	}
-
 
77
 
-
 
78
	public static List<CSVRecord> readFile(File file) throws IOException, ProfitMandiBusinessException {
-
 
79
		FileReader filereader = new FileReader(file);
-
 
80
		CSVParser parser = new CSVParser(filereader, CSVFormat.DEFAULT);
-
 
81
		List<CSVRecord> records = parser.getRecords();
-
 
82
		LOGGER.info("records" + records);
-
 
83
		LOGGER.info("parser" + parser);
-
 
84
		if (records.size() < 2) {
-
 
85
			parser.close();
74
			throw new ProfitMandiBusinessException("Uploaded File", "", "No records Found");
86
			throw new ProfitMandiBusinessException("Uploaded File", "", "No records Found");
75
		}
87
		}
76
		// Remove header
88
		// Remove header
77
		records.remove(0);
89
		records.remove(0);
78
		parser.close();
90
		parser.close();