Subversion Repositories SmartDukaan

Rev

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

Rev 24593 Rev 24809
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.PrintStream;
5
import java.io.PrintStream;
-
 
6
import java.io.Serializable;
6
import java.util.List;
7
import java.util.List;
7
 
8
 
8
import org.apache.commons.csv.CSVFormat;
9
import org.apache.commons.csv.CSVFormat;
9
import org.apache.commons.csv.CSVPrinter;
10
import org.apache.commons.csv.CSVPrinter;
10
import org.apache.commons.io.output.ByteArrayOutputStream;
11
import org.apache.commons.io.output.ByteArrayOutputStream;
Line 44... Line 45...
44
	public static void main(String[] args) {
45
	public static void main(String[] args) {
45
		// detectFileType(new File("/hsps-docs/1499163441532"));
46
		// detectFileType(new File("/hsps-docs/1499163441532"));
46
		// System.out.println("he");
47
		// System.out.println("he");
47
	}
48
	}
48
 
49
 
49
	public static ByteArrayOutputStream getCSVByteStream(List<String> headers, List<List<?>> rows) throws Exception {
50
	public static ByteArrayOutputStream getCSVByteStream(List<String> headers, List<List<? extends Serializable>> rows) throws Exception {
50
		try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
51
		try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
51
				PrintStream writer = new PrintStream(baos);
52
				PrintStream writer = new PrintStream(baos);
52
				CSVPrinter csvPrinter = new CSVPrinter(writer,
53
				CSVPrinter csvPrinter = new CSVPrinter(writer,
53
						CSVFormat.EXCEL.withTrim().withHeader(headers.toArray(new String[] {})));) {
54
						CSVFormat.EXCEL.withTrim().withHeader(headers.toArray(new String[] {})));) {
54
			for (List<?> row : rows) {
55
			for (List<? extends Serializable> row : rows) {
55
				csvPrinter.printRecord(row);
56
				csvPrinter.printRecord(row);
56
			}
57
			}
57
			return baos;
58
			return baos;
58
		}
59
		}
59
	}
60
	}