Class Exporter<O>

java.lang.Object
org.nuiton.csv.Exporter<O>

public class Exporter<O> extends Object
Exporter contains a configuration and is ready to export some data.

Exporter construction

To create a new exporter, you need to use an ExporterBuilder.

There is some useful methods such as of(ExporterConfiguration) or of(ExportModel) to obtain directly an exporter from a legacy export model or a exporter configuration.

There is also other method to create a new export builder such as builder(), builder(ExporterConfiguration) or builder(ExportModel). Once this is done, use the ExporterBuilder API.

Exporter usage

Once you have an exporter, use one of the method exportTo...(...) methods. You can export to
  • File
  • String
  • OutputStream
  • Writer
  • InputStream
  • Reader
Created on 09/12/15.
Since:
3.0
Author:
Tony Chemit - chemit@codelutin.com
  • Field Details

  • Constructor Details

  • Method Details

    • of

      public static <O> Exporter<O> of(ExportModel<O> model)
      Creates an exporter from the given model, and using default configuration values.
      Type Parameters:
      O - type of data to export
      Parameters:
      model - model of export
      Returns:
      the exporter ready to use
    • of

      public static <O> Exporter<O> of(ExporterConfiguration<O> configuration)
      Creates an exporter from the given configuration.
      Type Parameters:
      O - type of data to export
      Parameters:
      configuration - export configuration
      Returns:
      the exporter ready to use
    • builder

      public static <O> ExporterBuilder<O> builder(ExportModel<O> model)
      Creates a new exporter builder from the given model.
      Type Parameters:
      O - type of data to export
      Parameters:
      model - model of export
      Returns:
      the exporter builder
    • builder

      public static <O> ExporterBuilder<O> builder(ExporterConfiguration<O> configuration)
      Creates a new exporter builder from the given configuration.
      Type Parameters:
      O - type of data to export
      Parameters:
      configuration - configuration of export
      Returns:
      the exporter builder
    • builder

      public static <O> ExporterBuilder<O> builder()
      Creates a new empty exporter builder.
      Returns:
      the exporter builder
    • toOutputStream

      public void toOutputStream(Iterable<O> data, OutputStream outputStream) throws IOException
      Produces the cvs of the given data into the given outputStream.
      Parameters:
      data - data to export
      outputStream - where to perform the export
      Throws:
      IOException
    • toOutputStreamWithoutHeader

      public void toOutputStreamWithoutHeader(Iterable<O> data, OutputStream outputStream) throws IOException
      Produces the cvs (without header) of the given data into the given outputStream.
      Parameters:
      data - data to export
      outputStream - where to perform the export
      Throws:
      IOException
    • toOutputStream

      public void toOutputStream(Iterable<O> data, boolean writeHeader, OutputStream outputStream) throws IOException
      Produces the cvs of the given data into the given outputStream.
      Parameters:
      data - data to export
      writeHeader - write or not header (first line of the export)
      outputStream - where to perform the export
      Throws:
      IOException
    • toWriter

      public void toWriter(Iterable<O> data, Writer writer) throws IOException
      Produces the cvs of the given data into the given writer.
      Parameters:
      data - data to export
      writer - where to perform the export
      Throws:
      IOException
    • toWriterWithoutHeader

      public void toWriterWithoutHeader(Iterable<O> data, Writer writer) throws IOException
      Produces the cvs (without header) of the given data into the given writer.
      Parameters:
      data - data to export
      writer - where to perform the export
      Throws:
      IOException
    • toWriter

      public void toWriter(Iterable<O> data, boolean writeHeader, Writer writer) throws IOException
      Produces the cvs of the given data into the given writer.
      Parameters:
      data - data to export
      writeHeader - write or not header (first line of the export)
      writer - where to perform the export
      Throws:
      IOException
    • toFile

      public void toFile(Iterable<O> data, File file) throws IOException
      Produces the cvs of the given data into the given file.
      Parameters:
      data - data to export
      file - where to perform the export
      Throws:
      IOException
    • toFileWithoutHeader

      public void toFileWithoutHeader(Iterable<O> data, File file) throws IOException
      Produces the cvs (without header) of the given data into the given file.
      Parameters:
      data - data to export
      file - where to perform the export
      Throws:
      IOException
    • toFile

      public void toFile(Iterable<O> data, boolean writeHeader, File file) throws IOException
      Produces the cvs of the given data into the given file.
      Parameters:
      data - data to export
      writeHeader - write or not header (first line of the export)
      file - where to perform the export
      Throws:
      IOException
    • toString

      public String toString(Iterable<O> data) throws IOException
      Produces the cvs of the given data and returns it as a String.
      Parameters:
      data - data to export
      Returns:
      the string of the csv
      Throws:
      IOException
    • toStringWithoutHeader

      public String toStringWithoutHeader(Iterable<O> data) throws IOException
      Produces the cvs (without header) of the given data and returns it as a String.
      Parameters:
      data - data to export
      Returns:
      the string of the csv
      Throws:
      IOException
    • toString

      public String toString(Iterable<O> data, boolean writeHeader) throws IOException
      Produces the cvs of the given data and returns it as a String.
      Parameters:
      data - data to export
      writeHeader - write or not header (first line of the export)
      Returns:
      the string of the csv
      Throws:
      IOException
    • toReader

      public Reader toReader(Iterable<O> data) throws IOException
      Produces the cvs of the given data and returns it as a Reader.
      Parameters:
      data - data to export
      Returns:
      the string of the csv
      Throws:
      IOException
    • toReaderWithoutHeader

      public Reader toReaderWithoutHeader(Iterable<O> data) throws IOException
      Produces the cvs (without header) of the given data and returns it as a Reader.
      Parameters:
      data - data to export
      Returns:
      the string of the csv
      Throws:
      IOException
    • toReader

      public Reader toReader(Iterable<O> data, boolean writeHeader) throws IOException
      Produces the cvs (without header) of the given data and returns it as a Reader.
      Parameters:
      data - data to export
      writeHeader - write or not header (first line of the export)
      Returns:
      the string of the csv
      Throws:
      IOException
    • toInputStream

      public InputStream toInputStream(Iterable<O> data) throws IOException
      Produces the cvs of the given data and returns it as a InputStream.
      Parameters:
      data - data to export
      Returns:
      the string of the csv
      Throws:
      IOException
    • toInputStreamWithoutHeader

      public InputStream toInputStreamWithoutHeader(Iterable<O> data) throws IOException
      Produces the cvs (without header) of the given data and returns it as a InputStream.
      Parameters:
      data - data to export
      Returns:
      the string of the csv
      Throws:
      IOException
    • toInputStream

      public InputStream toInputStream(Iterable<O> data, boolean writeHeader) throws IOException
      Produces the cvs (without header) of the given data and returns it as a InputStream.
      Parameters:
      data - data to export
      Returns:
      the string of the csv
      Throws:
      IOException
    • toBuilder

      public ExporterBuilder<O> toBuilder()
      Creates a new exporter builder from this exporter (to reuse his configuration).
      Returns:
      the exporter builder