package com.dianping.poi.dedup.util;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.nio.charset.Charset;
import java.util.Map;
import org.apache.commons.beanutils.PropertyUtils;
import com.dianping.poi.dedup.model.Poi;
import au.com.bytecode.opencsv.CSVWriter;
public class PoiCsvWriter {
private CSVWriter _writer;
public PoiCsvWriter(String filePath) throws FileNotFoundException {
OutputStreamWriter char_output = new OutputStreamWriter(
new FileOutputStream(filePath), Charset.forName("UTF-8")
.newEncoder());
_writer = new CSVWriter(char_output, '\t', CSVWriter.NO_QUOTE_CHARACTER);
}
public void writeNext(String[] nextLine) {
for (int i = 0; i < nextLine.length; i++) {
if (nextLine[i] != null) {
nextLine[i] = nextLine[i].replaceAll("[\t\n]", " ").replaceAll(
"\\\\N", "");
}
}
_writer.writeNext(nextLine);
}
public void flush() throws IOException {
_writer.flush();
}
public void close() throws IOException {
_writer.close();
}
public static String[] getCsvLineFromPoi(Poi p, String[] fields) throws Exception {
String[] ret = new String[fields.length];
Map<String, String> extendedInfo = p.getExtendedInfo();
for (int i = 0; i < fields.length; i++){
String fieldName = unCapitalizeFirstLetter(fields[i]);
// System.out.println(" i :" +i );
try {
if (PropertyUtils.getProperty(p, fieldName) != null){
ret[i] = PropertyUtils.getProperty(p, fieldName).toString();
} else if (extendedInfo != null && extendedInfo.containsKey(fields[i])) {
ret[i] = extendedInfo.get(fields[i]);
} else {
ret[i] = null;
}
} catch (NoSuchMethodException e) {
if (extendedInfo != null && !extendedInfo.isEmpty()) {
ret[i] = extendedInfo.get(fields[i]);
}
}
}
return ret;
}
private static String unCapitalizeFirstLetter(String input){
return input.substring(0, 1).toLowerCase() + input.substring(1);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.nio.charset.Charset;
import java.util.Map;
import org.apache.commons.beanutils.PropertyUtils;
import com.dianping.poi.dedup.model.Poi;
import au.com.bytecode.opencsv.CSVWriter;
public class PoiCsvWriter {
private CSVWriter _writer;
public PoiCsvWriter(String filePath) throws FileNotFoundException {
OutputStreamWriter char_output = new OutputStreamWriter(
new FileOutputStream(filePath), Charset.forName("UTF-8")
.newEncoder());
_writer = new CSVWriter(char_output, '\t', CSVWriter.NO_QUOTE_CHARACTER);
}
public void writeNext(String[] nextLine) {
for (int i = 0; i < nextLine.length; i++) {
if (nextLine[i] != null) {
nextLine[i] = nextLine[i].replaceAll("[\t\n]", " ").replaceAll(
"\\\\N", "");
}
}
_writer.writeNext(nextLine);
}
public void flush() throws IOException {
_writer.flush();
}
public void close() throws IOException {
_writer.close();
}
public static String[] getCsvLineFromPoi(Poi p, String[] fields) throws Exception {
String[] ret = new String[fields.length];
Map<String, String> extendedInfo = p.getExtendedInfo();
for (int i = 0; i < fields.length; i++){
String fieldName = unCapitalizeFirstLetter(fields[i]);
// System.out.println(" i :" +i );
try {
if (PropertyUtils.getProperty(p, fieldName) != null){
ret[i] = PropertyUtils.getProperty(p, fieldName).toString();
} else if (extendedInfo != null && extendedInfo.containsKey(fields[i])) {
ret[i] = extendedInfo.get(fields[i]);
} else {
ret[i] = null;
}
} catch (NoSuchMethodException e) {
if (extendedInfo != null && !extendedInfo.isEmpty()) {
ret[i] = extendedInfo.get(fields[i]);
}
}
}
return ret;
}
private static String unCapitalizeFirstLetter(String input){
return input.substring(0, 1).toLowerCase() + input.substring(1);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}

被折叠的 条评论
为什么被折叠?



