Class CsvWriter

All Implemented Interfaces:
Closeable, Flushable, Appendable, AutoCloseable

public class CsvWriter extends SerializerWriter
Specialized writer for serializing CSV.
Notes:
  • This class is not intended for external use.
  • Constructor Details

    • CsvWriter

      protected CsvWriter(Writer out, boolean useWhitespace, int maxIndent, char quoteChar, boolean trimStrings, UriResolver uriResolver)
      Constructor.
      Parameters:
      out - The writer being wrapped.
      useWhitespace - If true, tabs and spaces will be used in output.
      maxIndent - The maximum indentation level.
      quoteChar - The quote character to use (i.e. '\'' or '"')
      trimStrings - If true, strings will be trimmed before being serialized.
      uriResolver - The URI resolver for resolving URIs to absolute or root-relative form.
  • Method Details

    • append

      public CsvWriter append(char c)
      Specified by:
      append in interface Appendable
      Overrides:
      append in class SerializerWriter
    • append

      public CsvWriter append(char[] value)
      Description copied from class: SerializerWriter
      Appends the specified characters to this writer.
      Overrides:
      append in class SerializerWriter
      Parameters:
      value - The characters to append to this writer.
      Returns:
      This object.
    • append

      public CsvWriter append(int indent, char c)
      Description copied from class: SerializerWriter
      Writes an indent (if the useWhitespace setting is enabled), followed by text.
      Overrides:
      append in class SerializerWriter
      Parameters:
      indent - The number of tabs to indent.
      c - The character to write.
      Returns:
      This object.
    • append

      public CsvWriter append(int indent, String text)
      Description copied from class: SerializerWriter
      Writes an indent (if the useWhitespace setting is enabled), followed by text.
      Overrides:
      append in class SerializerWriter
      Parameters:
      indent - The number of tabs to indent.
      text - The text to write.
      Returns:
      This object.
    • append

      public CsvWriter append(Object text)
      Description copied from class: SerializerWriter
      Writes the specified text to the writer if it isn't null.
      Overrides:
      append in class SerializerWriter
      Parameters:
      text - The text to write.
      Returns:
      This object.
    • append

      public CsvWriter append(String text)
      Description copied from class: SerializerWriter
      Writes the specified text to the writer if it isn't null.
      Overrides:
      append in class SerializerWriter
      Parameters:
      text - The text to write.
      Returns:
      This object.
    • appendIf

      public CsvWriter appendIf(boolean b, char c)
      Description copied from class: SerializerWriter
      Writes the specified text to the writer if b is true.
      Overrides:
      appendIf in class SerializerWriter
      Parameters:
      b - Boolean flag.
      c - The text to write.
      Returns:
      This object.
    • appendIf

      public CsvWriter appendIf(boolean b, String text)
      Description copied from class: SerializerWriter
      Writes the specified text to the writer if b is true.
      Overrides:
      appendIf in class SerializerWriter
      Parameters:
      b - Boolean flag.
      text - The text to write.
      Returns:
      This object.
    • appendln

      public CsvWriter appendln(int indent, String text)
      Description copied from class: SerializerWriter
      Writes an indent (if the useWhitespace setting is enabled), followed by text, followed by a newline (if the useWhitespace setting is enabled).
      Overrides:
      appendln in class SerializerWriter
      Parameters:
      indent - The number of tabs to indent.
      text - The text to write.
      Returns:
      This object.
    • appendln

      public CsvWriter appendln(String text)
      Description copied from class: SerializerWriter
      Writes the specified text followed by a newline (if the useWhitespace setting is enabled).
      Overrides:
      appendln in class SerializerWriter
      Parameters:
      text - The text to write.
      Returns:
      This object.
    • appendUri

      public CsvWriter appendUri(Object value)
      Description copied from class: SerializerWriter
      Appends the specified object as a URI.

      Object is converted to a String using toString(), so this will work on URL or URI objects, or any other type that returns a URI via it's toString() method.

      The URI is resolved based on the Serializer.Builder.uriRelativity(UriRelativity) and Serializer.Builder.uriResolution(UriResolution) settings and the UriContext that's part of the session.

      Overrides:
      appendUri in class SerializerWriter
      Parameters:
      value - The URI to serialize.
      Returns:
      This object.
    • cr

      public CsvWriter cr(int depth)
      Description copied from class: SerializerWriter
      Performs a carriage return.

      Adds a newline and the specified number of tabs (if the useWhitespace setting is enabled) to the output.

      Overrides:
      cr in class SerializerWriter
      Parameters:
      depth - The indentation.
      Returns:
      This object.
    • cre

      public CsvWriter cre(int depth)
      Description copied from class: SerializerWriter
      Performs a carriage return at the end of a line.

      Adds a newline and the specified number of tabs (if the useWhitespace setting is enabled) to the output.

      Overrides:
      cre in class SerializerWriter
      Parameters:
      depth - The indentation.
      Returns:
      This object.
    • i

      public CsvWriter i(int indent)
      Description copied from class: SerializerWriter
      Writes an indent to the writer if the useWhitespace setting is enabled.
      Overrides:
      i in class SerializerWriter
      Parameters:
      indent - The number of tabs to indent.
      Returns:
      This object.
    • ie

      public CsvWriter ie(int indent)
      Description copied from class: SerializerWriter
      Writes an end-of-line indent to the writer if the useWhitespace setting is enabled.
      Overrides:
      ie in class SerializerWriter
      Parameters:
      indent - The number of tabs to indent.
      Returns:
      This object.
    • nl

      public CsvWriter nl(int indent)
      Description copied from class: SerializerWriter
      Writes a newline to the writer if the useWhitespace setting is enabled.
      Overrides:
      nl in class SerializerWriter
      Parameters:
      indent - The current indentation level.
      Returns:
      This object.
    • nlIf

      public CsvWriter nlIf(boolean flag, int indent)
      Description copied from class: SerializerWriter
      Writes a newline to the writer if the useWhitespace setting is enabled and the boolean flag is true.
      Overrides:
      nlIf in class SerializerWriter
      Parameters:
      flag - The boolean flag.
      indent - The current indentation level.
      Returns:
      This object.
    • q

      public CsvWriter q()
      Description copied from class: SerializerWriter
      Adds the quote character specified by the quoteChar setting to the output.
      Overrides:
      q in class SerializerWriter
      Returns:
      This object.
    • s

      public CsvWriter s()
      Description copied from class: SerializerWriter
      Adds a whitespace character to the output if the useWhitespace setting is enabled.
      Overrides:
      s in class SerializerWriter
      Returns:
      This object.
    • sIf

      public CsvWriter sIf(boolean flag)
      Description copied from class: SerializerWriter
      Writes a space if the boolean expression is true and useWhitespace is false.

      Intended for cases in XML where text should be separated by either a space or newline. This ensures the text is separated by a space if whitespace is disabled.

      Overrides:
      sIf in class SerializerWriter
      Parameters:
      flag - The boolean flag.
      Returns:
      This object.
    • w

      public CsvWriter w(char value)
      Description copied from class: SerializerWriter
      Writes the specified character to the writer.
      Overrides:
      w in class SerializerWriter
      Parameters:
      value - The character to write.
      Returns:
      This object.
    • w

      public CsvWriter w(String value)
      Description copied from class: SerializerWriter
      Writes the specified string to the writer.
      Overrides:
      w in class SerializerWriter
      Parameters:
      value - The string to write.
      Returns:
      This object.
    • writeEntry

      public void writeEntry(Object value)
      Writes an entry to the writer.
      Parameters:
      value - The value to write.