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 booleanFlag that indicates whether the_outputBufferis recyclable (and needs to be returned to recycler once we are done) or not.protected booleanprotected booleanprotected final charprotected final intprotected booleanprotected booleanprotected final char[]protected final intprotected intprotected final intLowest-valued character that is safe to output without using quotes around value, NOT including possible escape character.protected final char[]protected booleanMarker flag used to determine if to do optimal (aka "strict") quoting checks or not (looser conservative check)protected final intprotected final charprotected intLet's keep track of how many bytes have been output, may prove useful when debugging.protected intprotected intprotected final com.fasterxml.jackson.core.io.IOContextprotected intIndex of the last buffered valueprotected intIndex of column we expect to write nextprotected final WriterUnderlyingWriterused for output.protected char[]Intermediate buffer in which contents are buffered before being written using_out.protected final intOffset to index after the last valid index in_outputBuffer.protected intPointer to the next available char position in_outputBufferprivate static final char[]protected static final intprotected final BufferedValue[]protected static final intprivate 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 intprotected voidprivate 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) voidprivate 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 voidprotected voidprotected voidappendRawValue(String value) protected voidappendValue(boolean value) protected voidappendValue(double value) protected voidappendValue(float value) protected voidappendValue(int value) protected voidappendValue(long value) protected voidappendValue(String value) voidclose(boolean autoClose) voidendRow()voidflush(boolean flushStream) intNOTE: 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.intoverrideFormatFeatures(int feat) withSchema(CsvSchema schema) final voidwrite(int columnIndex, boolean value) final voidwrite(int columnIndex, char[] ch, int offset, int len) final voidwrite(int columnIndex, double value) final voidwrite(int columnIndex, float value) final voidwrite(int columnIndex, int value) final voidwrite(int columnIndex, long value) final voidfinal voidwriteColumnName(String name) final voidwriteNonEscaped(int columnIndex, String rawValue) final voidwriteNull(int columnIndex) voidwriteRaw(char c) voidwriteRaw(char[] text, int offset, int len) voidvoidprivate voidwriteRawLong(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
UnderlyingWriterused 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_outputBufferis 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()
-