Subversion Repositories SmartDukaan

Rev

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

Rev 25840 Rev 29598
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;
3
import java.io.File;
4
import java.io.IOException;
4
import java.io.IOException;
-
 
5
import java.io.InputStreamReader;
5
import java.io.PrintStream;
6
import java.io.PrintStream;
6
import java.io.Serializable;
7
import java.io.Serializable;
7
import java.util.List;
8
import java.util.List;
8
 
9
 
9
import org.apache.commons.csv.CSVFormat;
10
import org.apache.commons.csv.CSVFormat;
-
 
11
import org.apache.commons.csv.CSVParser;
10
import org.apache.commons.csv.CSVPrinter;
12
import org.apache.commons.csv.CSVPrinter;
-
 
13
import org.apache.commons.csv.CSVRecord;
11
import org.apache.commons.io.output.ByteArrayOutputStream;
14
import org.apache.commons.io.output.ByteArrayOutputStream;
12
import org.apache.logging.log4j.LogManager;
15
import org.apache.logging.log4j.LogManager;
13
import org.apache.logging.log4j.Logger;
16
import org.apache.logging.log4j.Logger;
14
import org.apache.tika.Tika;
17
import org.apache.tika.Tika;
-
 
18
import org.springframework.web.multipart.MultipartFile;
15
 
19
 
16
import com.spice.profitmandi.common.enumuration.ContentType;
20
import com.spice.profitmandi.common.enumuration.ContentType;
17
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
21
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
18
 
22
 
19
public class FileUtil {
23
public class FileUtil {
Line 56... Line 60...
56
				csvPrinter.printRecord(row);
60
				csvPrinter.printRecord(row);
57
			}
61
			}
58
			return baos;
62
			return baos;
59
		}
63
		}
60
	}
64
	}
-
 
65
 
-
 
66
	public static List<CSVRecord> readFile(MultipartFile file) throws IOException, ProfitMandiBusinessException {
-
 
67
 
-
 
68
		CSVParser parser = new CSVParser(new InputStreamReader(file.getInputStream()), CSVFormat.DEFAULT);
-
 
69
		List<CSVRecord> records = parser.getRecords();
-
 
70
		LOGGER.info("records" + records);
-
 
71
		LOGGER.info("parser" + parser);
-
 
72
		if (records.size() < 2) {
-
 
73
			parser.close();
-
 
74
			throw new ProfitMandiBusinessException("Uploaded File", "", "No records Found");
-
 
75
		}
-
 
76
		// Remove header
-
 
77
		records.remove(0);
-
 
78
		parser.close();
-
 
79
		return records;
-
 
80
 
-
 
81
	}
61
}
82
}