
org.aktin.broker.query.io.MultipartTableWriter Maven / Gradle / Ivy
package org.aktin.broker.query.io;
import java.io.BufferedWriter;
import java.io.IOException;
import java.nio.charset.Charset;
import org.aktin.broker.query.io.table.TableExport;
import org.aktin.broker.query.io.table.TableWriter;
/**
* Write text table data into a {@link MultipartOutputStream}.
*
* @author R.W.Majeed
*
*/
public class MultipartTableWriter implements TableExport {
public static final String MEDIA_TYPE_TAB = "text/tab-separated-values";
public static final String MEDIA_TYPE_CSV = "text/comma-separated-values";
private String fieldSeparator;
private String recordSeparator;
/** String to write to the file instead of a {@code null} value. Defaults to empty string. */
private String nullString;
private Charset charset;
private MultipartOutputStream output;
/**
* Create an instance by wrapping a {@link MultipartOutputStream}. Important: the underlying
* stream is not closed, when the table export is closed.
* @param output underlying stream, will not be closed by this class.
* @param charset charset to use for producing text files
*/
public MultipartTableWriter(MultipartOutputStream output, Charset charset) {
this.output = output;
this.charset = charset;
this.fieldSeparator = "\t";
this.recordSeparator = "\r\n";
this.nullString = "";
}
private class TableWriterImpl implements TableWriter{
private BufferedWriter writer;
public TableWriterImpl(BufferedWriter writer) {
this.writer = writer;
}
private void writeRecord(String[] values) throws IOException{
for( int i=0; i
© 2015 - 2025 Weber Informatics LLC | Privacy Policy