Search in sources :

Example 1 with BufferedLineWriter

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;
}
Also used : ZipEntry(java.util.zip.ZipEntry) OutputStream(java.io.OutputStream) ZipOutputStream(java.util.zip.ZipOutputStream) FileOutputStream(java.io.FileOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) CSVWriter(com.talend.csv.CSVWriter) BufferedWriter(java.io.BufferedWriter) CSVWriter(com.talend.csv.CSVWriter) BufferedLineWriter(org.talend.daikon.runtime.BufferedLineWriter) StringWriter(java.io.StringWriter) ZipOutputStream(java.util.zip.ZipOutputStream) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream)

Example 2 with BufferedLineWriter

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;
}
Also used : BufferedLineWriter(org.talend.daikon.runtime.BufferedLineWriter) ZipOutputStream(java.util.zip.ZipOutputStream) FileOutputStream(java.io.FileOutputStream) ZipEntry(java.util.zip.ZipEntry) OutputStream(java.io.OutputStream) ZipOutputStream(java.util.zip.ZipOutputStream) FileOutputStream(java.io.FileOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream) BufferedWriter(java.io.BufferedWriter)

Aggregations

BufferedOutputStream (java.io.BufferedOutputStream)2 BufferedWriter (java.io.BufferedWriter)2 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 OutputStream (java.io.OutputStream)2 OutputStreamWriter (java.io.OutputStreamWriter)2 ZipEntry (java.util.zip.ZipEntry)2 ZipOutputStream (java.util.zip.ZipOutputStream)2 BufferedLineWriter (org.talend.daikon.runtime.BufferedLineWriter)2 CSVWriter (com.talend.csv.CSVWriter)1 StringWriter (java.io.StringWriter)1