Class CsvEncoder
java.lang.Object
com.fasterxml.jackson.dataformat.csv.impl.CsvEncoder
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 Summary
FieldsModifier and TypeFieldDescriptionprotected BufferedValue[]
And if output comes in shuffled order we will need to do bit of ordering.protected boolean
Flag that indicates whether the_outputBuffer
is recyclable (and needs to be returned to recycler once we are done) or not.protected boolean
protected boolean
protected final char
protected final int
protected boolean
protected boolean
protected final char[]
protected final int
protected int
protected final int
Lowest-valued character that is safe to output without using quotes around value, NOT including possible escape character.protected final char[]
protected boolean
Marker flag used to determine if to do optimal (aka "strict") quoting checks or not (looser conservative check)protected final int
protected final char
protected int
Let's keep track of how many bytes have been output, may prove useful when debugging.protected int
protected int
protected final com.fasterxml.jackson.core.io.IOContext
protected int
Index of the last buffered valueprotected int
Index of column we expect to write nextprotected final Writer
UnderlyingWriter
used for output.protected char[]
Intermediate buffer in which contents are buffered before being written using_out
.protected final int
Offset to index after the last valid index in_outputBuffer
.protected int
Pointer to the next available char position in_outputBuffer
private static final char[]
protected static final int
protected final BufferedValue[]
protected static final int
private static final char[]
-
Constructor Summary
ConstructorsConstructorDescriptionCsvEncoder
(com.fasterxml.jackson.core.io.IOContext ctxt, int csvFeatures, Writer out, CsvSchema schema) CsvEncoder
(CsvEncoder base, CsvSchema newSchema) -
Method Summary
Modifier and TypeMethodDescriptionprotected void
_append
(char[] ch) protected void
_buffer
(int index, BufferedValue v) private final int
protected void
private final char
_getQuoteCharEscapeChar
(boolean escapeQuoteCharWithEscapeChar, int quoteCharacter, int escapeCharacter) 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.protected final boolean
_needsQuotingLoose
(String value) NOTE: final since checking is not expected to be changed here; override calling method (_mayNeedQuotes
) instead, if necessary.protected final boolean
_needsQuotingLoose
(String value, int esc) protected boolean
_needsQuotingStrict
(String value) protected boolean
_needsQuotingStrict
(String value, int esc) void
private final void
_writeLongQuoted
(String text, char q) private final void
_writeLongQuotedAndEscaped
(String text, char esc) void
_writeQuoted
(String text) protected void
_writeQuoted
(String text, char q, int i) void
_writeQuotedAndEscaped
(String text, char esc) protected void
_writeQuotedAndEscaped
(String text, char q, char esc, int i) protected void
protected void
protected void
appendRawValue
(String value) protected void
appendValue
(boolean value) protected void
appendValue
(double value) protected void
appendValue
(float value) protected void
appendValue
(int value) protected void
appendValue
(long value) protected void
appendValue
(String value) void
close
(boolean autoClose) void
endRow()
void
flush
(boolean flushStream) int
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.int
overrideFormatFeatures
(int feat) withSchema
(CsvSchema schema) final void
write
(int columnIndex, boolean value) final void
write
(int columnIndex, char[] ch, int offset, int len) final void
write
(int columnIndex, double value) final void
write
(int columnIndex, float value) final void
write
(int columnIndex, int value) final void
write
(int columnIndex, long value) final void
final void
writeColumnName
(String name) final void
writeNonEscaped
(int columnIndex, String rawValue) final void
writeNull
(int columnIndex) void
writeRaw
(char c) void
writeRaw
(char[] text, int offset, int len) void
void
private void
writeRawLong
(String text)
-
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
-
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
UnderlyingWriter
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 _cfgMinSafeCharLowest-valued character that is safe to output without using quotes around value, NOT including possible escape character. -
_csvFeatures
protected int _csvFeatures -
_cfgOptimalQuoting
protected boolean _cfgOptimalQuotingMarker 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 _nextColumnToWriteIndex of column we expect to write next -
_buffered
And if output comes in shuffled order we will need to do bit of ordering. -
_lastBuffered
protected int _lastBufferedIndex of the last buffered value -
_outputBuffer
protected char[] _outputBufferIntermediate buffer in which contents are buffered before being written using_out
. -
_bufferRecyclable
protected boolean _bufferRecyclableFlag that indicates whether the_outputBuffer
is recyclable (and needs to be returned to recycler once we are done) or not. -
_outputTail
protected int _outputTailPointer to the next available char position in_outputBuffer
-
_outputEnd
protected final int _outputEndOffset to index after the last valid index in_outputBuffer
. Typically same as length of the buffer. -
_charsWritten
protected int _charsWrittenLet'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
-
CsvEncoder
-
-
Method Details
-
_getQuoteCharEscapeChar
private final char _getQuoteCharEscapeChar(boolean escapeQuoteCharWithEscapeChar, int quoteCharacter, int escapeCharacter) -
_calcSafeChar
private final int _calcSafeChar() -
withSchema
-
overrideFormatFeatures
-
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
- Throws:
IOException
-
write
- Throws:
IOException
-
write
- Throws:
IOException
-
write
- Throws:
IOException
-
write
- Throws:
IOException
-
write
- Throws:
IOException
-
write
- Throws:
IOException
-
writeNonEscaped
- Throws:
IOException
- Since:
- 2.5
-
writeNull
- Throws:
IOException
-
writeColumnName
- Throws:
IOException
-
endRow
- Throws:
IOException
-
appendValue
- Throws:
IOException
-
appendRawValue
- Throws:
IOException
-
appendValue
- Throws:
IOException
-
appendValue
- Throws:
IOException
-
appendValue
- Throws:
IOException
-
appendValue
- Throws:
IOException
-
appendValue
- Throws:
IOException
-
appendNull
- Throws:
IOException
-
_append
- Throws:
IOException
-
appendColumnSeparator
- Throws:
IOException
-
writeRaw
- Throws:
IOException
-
writeRaw
- Throws:
IOException
-
writeRaw
- Throws:
IOException
-
writeRaw
- Throws:
IOException
-
writeRawLong
- Throws:
IOException
-
_writeQuoted
- Throws:
IOException
-
_writeQuoted
- Throws:
IOException
-
_writeLongQuoted
- Throws:
IOException
-
_writeQuotedAndEscaped
- Throws:
IOException
-
_writeQuotedAndEscaped
- Throws:
IOException
-
_writeLongQuotedAndEscaped
- Throws:
IOException
-
flush
- Throws:
IOException
-
close
- Throws:
IOException
-
_mayNeedQuotes
Helper method that determines whether given String is likely to require quoting; check tries to optimize for speed. -
_needsQuotingLoose
NOTE: final since checking is not expected to be changed here; override calling method (
_mayNeedQuotes
) instead, if necessary.- Since:
- 2.4
-
_needsQuotingLoose
-
_needsQuotingStrict
- Since:
- 2.4
-
_needsQuotingStrict
- Since:
- 2.7
-
_buffer
-
_flushBuffer
- Throws:
IOException
-
_releaseBuffers
public void _releaseBuffers()
-