use of org.talend.daikon.runtime.BufferedLineWriter in project components by Talend.
the class FileOutputDelimitedRuntime method getCsvWriter.
public CSVWriter getCsvWriter() throws IOException {
com.talend.csv.CSVWriter csvWriter = null;
if (!useStream) {
if (!props.split.getValue()) {
if (props.compress.getValue() && !props.append.getValue()) {
// compress the dest file
file = new File(fileName);
String zipName = fullName + ".zip";
zipFile = new File(zipName);
if (zipFile.exists()) {
zipFile.delete();
}
zipOut = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(zipName)));
zipOut.putNextEntry(new ZipEntry(file.getName()));
this.streamWriter = new OutputStreamWriter(zipOut, encoding);
} else {
if (!props.append.getValue()) {
File fileToDelete = new File(fileName);
if (fileToDelete.exists()) {
fileToDelete.delete();
}
}
streamWriter = new OutputStreamWriter(new FileOutputStream(fileName, props.append.getValue()), encoding);
}
} else {
file = new File(fullName + splitedFileNo + extension);
if (!props.append.getValue()) {
if (file.exists()) {
file.delete();
}
}
streamWriter = new OutputStreamWriter(new FileOutputStream(fullName + splitedFileNo + extension, props.append.getValue()), encoding);
splitedFileNo++;
}
if (props.rowMode.getValue()) {
this.writer = new BufferedLineWriter(streamWriter);
this.strWriter = new StringWriter();
csvWriter = new CSVWriter(strWriter);
} else {
csvWriter = new CSVWriter(new BufferedWriter(streamWriter));
}
} else {
if (props.compress.getValue()) {
// compress the dest output stream
zipOut = new ZipOutputStream(new BufferedOutputStream((OutputStream) props.fileName.getValue()));
zipOut.putNextEntry(new ZipEntry("TalendOutputDelimited"));
streamWriter = new OutputStreamWriter(zipOut, encoding);
} else {
streamWriter = new OutputStreamWriter((OutputStream) props.fileName.getValue(), encoding);
}
if (props.rowMode.getValue()) {
this.writer = new BufferedLineWriter(streamWriter);
this.strWriter = new StringWriter();
csvWriter = new com.talend.csv.CSVWriter(strWriter);
} else {
BufferedWriter bufferWriter = new BufferedWriter(streamWriter);
csvWriter = new com.talend.csv.CSVWriter(bufferWriter);
}
}
csvWriter.setSeparator(fieldSeparator.charAt(0));
if (!props.useOsRowSeparator.getValue()) {
csvWriter.setLineEnd(rowSeparator);
} else {
if (!"\r\n".equals(rowSeparator) && rowSeparator.charAt(0) != '\r' && rowSeparator.charAt(0) != '\n') {
csvWriter.setLineEnd(rowSeparator);
}
}
// This would set after write header
if (!props.includeHeader.getValue()) {
csvWriter.setEscapeChar(escapeChar);
csvWriter.setQuoteChar(textEnclosureChar);
csvWriter.setQuoteStatus(com.talend.csv.CSVWriter.QuoteStatus.FORCE);
}
return csvWriter;
}
use of org.talend.daikon.runtime.BufferedLineWriter in project components by Talend.
the class FileOutputDelimitedRuntime method getWriter.
public Writer getWriter() throws IOException {
if (!props.targetIsStream.getValue()) {
if (!props.split.getValue()) {
if (props.compress.getValue() && !props.append.getValue()) {
// compress the dest file
file = new File(fileName);
String zipName = fullName + ".zip";
zipFile = new File(zipName);
if (zipFile.exists()) {
zipFile.delete();
}
zipOut = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(zipName)));
zipOut.putNextEntry(new ZipEntry(file.getName()));
streamWriter = new OutputStreamWriter(zipOut, encoding);
} else {
if (!props.append.getValue()) {
File fileToDelete = new File(fileName);
if (fileToDelete.exists()) {
fileToDelete.delete();
}
}
streamWriter = new OutputStreamWriter(new FileOutputStream(fileName, props.append.getValue()), encoding);
}
} else {
file = new File(fullName + splitedFileNo + extension);
if (!props.append.getValue()) {
if (file.exists()) {
file.delete();
}
}
streamWriter = new OutputStreamWriter(new FileOutputStream(fullName + splitedFileNo + extension, props.append.getValue()), encoding);
splitedFileNo++;
}
} else {
if (props.compress.getValue()) {
// compress the dest output stream
zipOut = new ZipOutputStream(new BufferedOutputStream((OutputStream) props.fileName.getValue()));
zipOut.putNextEntry(new ZipEntry("TalendOutputDelimited"));
streamWriter = new OutputStreamWriter(zipOut, encoding);
} else {
streamWriter = new OutputStreamWriter((OutputStream) props.fileName.getValue(), encoding);
}
}
if (props.rowMode.getValue()) {
writer = new BufferedLineWriter(streamWriter);
} else {
writer = new BufferedWriter(streamWriter);
}
return writer;
}
Aggregations