Search in sources :

Example 1 with FileWriterSettings

use of org.knime.base.node.io.csvwriter.FileWriterSettings in project knime-cloud by knime.

the class AbstractAmazonPersonalizeDataUploadNodeModel method writeCSV.

@SuppressWarnings("resource")
private static URI writeCSV(final BufferedDataTable table, final ExecutionContext exec) throws IOException, CanceledExecutionException {
    final File createTempDir = FileUtil.createTempFile("KNIME_amazon_personalize_", ".csv");
    final BufferedOutputStream tempOut = new BufferedOutputStream(new FileOutputStream(createTempDir));
    final FileWriterSettings settings = new FileWriterSettings();
    settings.setWriteColumnHeader(true);
    try (CSVWriter tableWriter = new CSVWriter(new OutputStreamWriter(tempOut, "UTF-8"), settings)) {
        tableWriter.write(table, exec);
    }
    return createTempDir.toURI();
}
Also used : FileWriterSettings(org.knime.base.node.io.csvwriter.FileWriterSettings) FileOutputStream(java.io.FileOutputStream) CSVWriter(org.knime.base.node.io.csvwriter.CSVWriter) OutputStreamWriter(java.io.OutputStreamWriter) RemoteFile(org.knime.base.filehandling.remote.files.RemoteFile) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream)

Example 2 with FileWriterSettings

use of org.knime.base.node.io.csvwriter.FileWriterSettings in project knime-cloud by knime.

the class RedshiftCsvWriter method writeData.

@Override
protected FSPath writeData(final ExecutionMonitor exec, final ExecutionParameters<RedshiftLoaderNodeSettings> parameters, final FSPath rootFolder) throws IOException, CanceledExecutionException {
    final RedshiftLoaderNodeSettings customSettings = parameters.getCustomSettings();
    final FileWriterSettings fileWriterSettings = customSettings.getFileFormatModel().getFileWriterSettings();
    final boolean useGzip = !RedshiftLoaderFileFormat.NONE_COMPRESSION.equals(customSettings.getCompressionModel().getStringValue());
    final String fileExtension;
    if (useGzip) {
        fileExtension = FILE_EXTENSION + ".gz";
    } else {
        fileExtension = FILE_EXTENSION;
    }
    final FSPath tempFile = createTempFile(rootFolder, fileExtension);
    try (OutputStream outputStream = DBFileLoadUtil.createOutputStream(tempFile);
        OutputStream os = useGzip ? new GZIPOutputStream(outputStream) : outputStream) {
        writeCsv(parameters.getRowInput(), os, fileWriterSettings, exec);
        exec.setMessage("Uploading file (no progress available)...");
    }
    return tempFile;
}
Also used : FileWriterSettings(org.knime.base.node.io.csvwriter.FileWriterSettings) GZIPOutputStream(java.util.zip.GZIPOutputStream) OutputStream(java.io.OutputStream) GZIPOutputStream(java.util.zip.GZIPOutputStream) FSPath(org.knime.filehandling.core.connections.FSPath) RedshiftLoaderNodeSettings(org.knime.cloud.aws.redshift.connector2.loader.RedshiftLoaderNodeSettings)

Aggregations

FileWriterSettings (org.knime.base.node.io.csvwriter.FileWriterSettings)2 BufferedOutputStream (java.io.BufferedOutputStream)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 OutputStream (java.io.OutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 GZIPOutputStream (java.util.zip.GZIPOutputStream)1 RemoteFile (org.knime.base.filehandling.remote.files.RemoteFile)1 CSVWriter (org.knime.base.node.io.csvwriter.CSVWriter)1 RedshiftLoaderNodeSettings (org.knime.cloud.aws.redshift.connector2.loader.RedshiftLoaderNodeSettings)1 FSPath (org.knime.filehandling.core.connections.FSPath)1