Class CsvEncoder

java.lang.Object
com.fasterxml.jackson.dataformat.csv.impl.CsvEncoder

public class CsvEncoder extends Object
Helper class that handles actual low-level construction of CSV output, based only on indexes given without worrying about reordering, or binding from logical properties.
  • Field Details

    • SHORT_WRITE

      protected static final int SHORT_WRITE
      See Also:
    • MAX_QUOTE_CHECK

      protected static final int MAX_QUOTE_CHECK
      See Also:
    • NO_BUFFERED

      protected final BufferedValue[] NO_BUFFERED
    • TRUE_CHARS

      private static final char[] TRUE_CHARS
    • FALSE_CHARS

      private static final char[] FALSE_CHARS
    • _ioContext

      protected final com.fasterxml.jackson.core.io.IOContext _ioContext
    • _out

      protected final Writer _out
      Underlying Writer used for output.
    • _cfgColumnSeparator

      protected final char _cfgColumnSeparator
    • _cfgQuoteCharacter

      protected final int _cfgQuoteCharacter
    • _cfgEscapeCharacter

      protected final int _cfgEscapeCharacter
      Since:
      2.7
    • _cfgLineSeparator

      protected final char[] _cfgLineSeparator
    • _cfgNullValue

      protected final char[] _cfgNullValue
      Since:
      2.5
    • _cfgLineSeparatorLength

      protected final int _cfgLineSeparatorLength
    • _cfgMaxQuoteCheckChars

      protected int _cfgMaxQuoteCheckChars
    • _cfgMinSafeChar

      protected final int _cfgMinSafeChar
      Lowest-valued character that is safe to output without using quotes around value, NOT including possible escape character.
    • _csvFeatures

      protected int _csvFeatures
    • _cfgOptimalQuoting

      protected boolean _cfgOptimalQuoting
      Marker flag used to determine if to do optimal (aka "strict") quoting checks or not (looser conservative check)
      Since:
      2.4
    • _cfgIncludeMissingTail

      protected boolean _cfgIncludeMissingTail
      Since:
      2.4
    • _cfgAlwaysQuoteStrings

      protected boolean _cfgAlwaysQuoteStrings
      Since:
      2.5
    • _cfgAlwaysQuoteEmptyStrings

      protected boolean _cfgAlwaysQuoteEmptyStrings
    • _cfgEscapeQuoteCharWithEscapeChar

      protected boolean _cfgEscapeQuoteCharWithEscapeChar
    • _cfgQuoteCharEscapeChar

      protected final char _cfgQuoteCharEscapeChar
    • _columnCount

      protected int _columnCount
      Since:
      2.4
    • _nextColumnToWrite

      protected int _nextColumnToWrite
      Index of column we expect to write next
    • _buffered

      protected BufferedValue[] _buffered
      And if output comes in shuffled order we will need to do bit of ordering.
    • _lastBuffered

      protected int _lastBuffered
      Index of the last buffered value
    • _outputBuffer

      protected char[] _outputBuffer
      Intermediate buffer in which contents are buffered before being written using _out.
    • _bufferRecyclable

      protected boolean _bufferRecyclable
      Flag that indicates whether the _outputBuffer is recyclable (and needs to be returned to recycler once we are done) or not.
    • _outputTail

      protected int _outputTail
      Pointer to the next available char position in _outputBuffer
    • _outputEnd

      protected final int _outputEnd
      Offset to index after the last valid index in _outputBuffer. Typically same as length of the buffer.
    • _charsWritten

      protected int _charsWritten
      Let's keep track of how many bytes have been output, may prove useful when debugging. This does not include bytes buffered in the output buffer, just bytes that have been written using underlying stream writer.
  • Constructor Details

    • CsvEncoder

      public CsvEncoder(com.fasterxml.jackson.core.io.IOContext ctxt, int csvFeatures, Writer out, CsvSchema schema)
    • CsvEncoder

      public CsvEncoder(CsvEncoder base, CsvSchema newSchema)
  • Method Details

    • _getQuoteCharEscapeChar

      private final char _getQuoteCharEscapeChar(boolean escapeQuoteCharWithEscapeChar, int quoteCharacter, int escapeCharacter)
    • _calcSafeChar

      private final int _calcSafeChar()
    • withSchema

      public CsvEncoder withSchema(CsvSchema schema)
    • overrideFormatFeatures

      public CsvEncoder overrideFormatFeatures(int feat)
    • getOutputTarget

      public Object getOutputTarget()
    • getOutputBuffered

      public int getOutputBuffered()
      NOTE: while value does indeed indicate amount that has been written in the buffer, there may be more intermediate data that is buffered as values but not yet in buffer.
    • nextColumnIndex

      public int nextColumnIndex()
    • write

      public final void write(int columnIndex, String value) throws IOException
      Throws:
      IOException
    • write

      public final void write(int columnIndex, char[] ch, int offset, int len) throws IOException
      Throws:
      IOException
    • write

      public final void write(int columnIndex, int value) throws IOException
      Throws:
      IOException
    • write

      public final void write(int columnIndex, long value) throws IOException
      Throws:
      IOException
    • write

      public final void write(int columnIndex, float value) throws IOException
      Throws:
      IOException
    • write

      public final void write(int columnIndex, double value) throws IOException
      Throws:
      IOException
    • write

      public final void write(int columnIndex, boolean value) throws IOException
      Throws:
      IOException
    • writeNonEscaped

      public final void writeNonEscaped(int columnIndex, String rawValue) throws IOException
      Throws:
      IOException
      Since:
      2.5
    • writeNull

      public final void writeNull(int columnIndex) throws IOException
      Throws:
      IOException
    • writeColumnName

      public final void writeColumnName(String name) throws IOException
      Throws:
      IOException
    • endRow

      public void endRow() throws IOException
      Throws:
      IOException
    • appendValue

      protected void appendValue(String value) throws IOException
      Throws:
      IOException
    • appendRawValue

      protected void appendRawValue(String value) throws IOException
      Throws:
      IOException
    • appendValue

      protected void appendValue(int value) throws IOException
      Throws:
      IOException
    • appendValue

      protected void appendValue(long value) throws IOException
      Throws:
      IOException
    • appendValue

      protected void appendValue(float value) throws IOException
      Throws:
      IOException
    • appendValue

      protected void appendValue(double value) throws IOException
      Throws:
      IOException
    • appendValue

      protected void appendValue(boolean value) throws IOException
      Throws:
      IOException
    • appendNull

      protected void appendNull() throws IOException
      Throws:
      IOException
    • _append

      protected void _append(char[] ch) throws IOException
      Throws:
      IOException
    • appendColumnSeparator

      protected void appendColumnSeparator() throws IOException
      Throws:
      IOException
    • writeRaw

      public void writeRaw(String text) throws IOException
      Throws:
      IOException
    • writeRaw

      public void writeRaw(String text, int start, int len) throws IOException
      Throws:
      IOException
    • writeRaw

      public void writeRaw(char[] text, int offset, int len) throws IOException
      Throws:
      IOException
    • writeRaw

      public void writeRaw(char c) throws IOException
      Throws:
      IOException
    • writeRawLong

      private void writeRawLong(String text) throws IOException
      Throws:
      IOException
    • _writeQuoted

      public void _writeQuoted(String text) throws IOException
      Throws:
      IOException
    • _writeQuoted

      protected void _writeQuoted(String text, char q, int i) throws IOException
      Throws:
      IOException
    • _writeLongQuoted

      private final void _writeLongQuoted(String text, char q) throws IOException
      Throws:
      IOException
    • _writeQuotedAndEscaped

      public void _writeQuotedAndEscaped(String text, char esc) throws IOException
      Throws:
      IOException
    • _writeQuotedAndEscaped

      protected void _writeQuotedAndEscaped(String text, char q, char esc, int i) throws IOException
      Throws:
      IOException
    • _writeLongQuotedAndEscaped

      private final void _writeLongQuotedAndEscaped(String text, char esc) throws IOException
      Throws:
      IOException
    • flush

      public void flush(boolean flushStream) throws IOException
      Throws:
      IOException
    • close

      public void close(boolean autoClose) throws IOException
      Throws:
      IOException
    • _mayNeedQuotes

      protected boolean _mayNeedQuotes(String value, int length)
      Helper method that determines whether given String is likely to require quoting; check tries to optimize for speed.
    • _needsQuotingLoose

      protected final boolean _needsQuotingLoose(String value)

      NOTE: final since checking is not expected to be changed here; override calling method (_mayNeedQuotes) instead, if necessary.

      Since:
      2.4
    • _needsQuotingLoose

      protected final boolean _needsQuotingLoose(String value, int esc)
    • _needsQuotingStrict

      protected boolean _needsQuotingStrict(String value)
      Since:
      2.4
    • _needsQuotingStrict

      protected boolean _needsQuotingStrict(String value, int esc)
      Since:
      2.7
    • _buffer

      protected void _buffer(int index, BufferedValue v)
    • _flushBuffer

      protected void _flushBuffer() throws IOException
      Throws:
      IOException
    • _releaseBuffers

      public void _releaseBuffers()