Top Description Fields Constructors Methods
com.fasterxml.jackson.dataformat.csv.impl

public Class CsvEncoder

extends Object
Class Inheritance
Imports
com.fasterxml.jackson.core.io.CharTypes, .IOContext, .NumberOutput, com.fasterxml.jackson.dataformat.csv.CsvGenerator, .CsvGenerator.Feature, .CsvSchema, java.io.IOException, .Writer, java.math.BigDecimal, .BigInteger, java.util.Arrays

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

Modifier and TypeField and Description
protected BufferedValue[]
_buffered

And if output comes in shuffled order we will need to do bit of ordering.

protected boolean
_bufferRecyclable

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

protected final boolean
protected boolean
protected boolean
protected boolean
protected final char
protected final char
protected final int
protected boolean
protected boolean
protected boolean
protected final char[]
protected final int
protected final int
protected final int
_cfgMinSafeChar

Lowest-valued character that is safe to output without using quotes around value, NOT including possible escape character.

protected final char[]
protected boolean
_cfgOptimalQuoting

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 boolean
protected int
_charsWritten

Let's keep track of how many bytes have been output, may prove useful when debugging.

protected int
protected int
protected final IOContext
protected int
_lastBuffered

Index of the last buffered value

protected int
_nextColumnToWrite

Index of column we expect to write next

protected final Writer
_out

Underlying Writer used for output.

protected char[]
_outputBuffer

Intermediate buffer in which contents are buffered before being written using _out.

protected final int
_outputEnd

Offset to index after the last valid index in _outputBuffer.

protected int[]
_outputEscapes

Currently active set of output escape code definitions (whether and how to escape or not).

protected int
_outputTail

Pointer to the next available char position in _outputBuffer

protected boolean
private static final char[]
protected static final char[]
protected static final int
MAX_QUOTE_CHECK

Also: only do check for optional quotes for short values; longer ones will always be quoted.

protected final BufferedValue[]
protected static final int
SHORT_WRITE

As an optimization we try coalescing short writes into buffer; but pass longer directly.

private static final int[]
private static final char[]

Constructor Summary

AccessConstructor and Description
public
CsvEncoder(IOContext ctxt, int csvFeatures, Writer out, CsvSchema schema)
Deprecated

public
CsvEncoder(IOContext ctxt, int csvFeatures, Writer out, CsvSchema schema, boolean useFastDoubleWriter)

public
CsvEncoder(CsvEncoder base, CsvSchema newSchema)

Method Summary

Modifier and TypeMethod and Description
protected void
_append(char[] ch)

private void
_appendCharacterEscape(char ch, int escCode)

Method called to append escape sequence for given character, at the end of standard output buffer; or if not possible, write out directly.

protected void
_buffer(int index, BufferedValue v)

private final int
protected void
private final char
_getQuoteCharEscapeChar(final boolean escapeQuoteCharWithEscapeChar, final int quoteCharacter, final int escapeCharacter)

protected boolean
_mayNeedQuotes(String value, int length, int columnIndex)

Helper method that determines whether given String is likely to require quoting; check tries to optimize for speed.

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

protected boolean
protected boolean
_needsQuotingStrict(String value, int esc)

public void
private void
private final void
_writeLongQuoted(String text, char q)

private final void
public void
protected void
_writeQuoted(String text, char q, int i)

public void
protected void
_writeQuotedAndEscaped(String text, char q, char esc, int i)

protected void
protected void
protected void
protected void
protected void
protected void
appendValue(int value)

protected void
appendValue(long value)

protected void
appendValue(float value)

protected void
appendValue(double value)

protected void
appendValue(boolean value)

public void
close(boolean autoClose, boolean flushStream)

public void
public void
flush(boolean flushStream)

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.

public Object
public int
public CsvEncoder
public CsvEncoder
setOutputEscapes(int[] esc)

public CsvEncoder
public final void
write(int columnIndex, String value)

public final void
write(int columnIndex, char[] ch, int offset, int len)

public final void
write(int columnIndex, int value)

public final void
write(int columnIndex, long value)

public final void
write(int columnIndex, BigInteger value)

public final void
write(int columnIndex, float value)

public final void
write(int columnIndex, double value)

public final void
write(int columnIndex, BigDecimal value, boolean plain)

public final void
write(int columnIndex, boolean value)

public final void
public final void
writeNonEscaped(int columnIndex, String rawValue)

public final void
writeNull(int columnIndex)

private void
public void
public void
writeRaw(String text, int start, int len)

public void
writeRaw(char[] text, int offset, int len)

public void
writeRaw(char c)

private void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

_bufferedback to summary
protected BufferedValue[] _buffered

And if output comes in shuffled order we will need to do bit of ordering.

_bufferRecyclableback to summary
protected boolean _bufferRecyclable

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

_cfgAllowsCommentsback to summary
protected final boolean _cfgAllowsComments
_cfgAlwaysQuoteEmptyStringsback to summary
protected boolean _cfgAlwaysQuoteEmptyStrings
_cfgAlwaysQuoteNumbersback to summary
protected boolean _cfgAlwaysQuoteNumbers
_cfgAlwaysQuoteStringsback to summary
protected boolean _cfgAlwaysQuoteStrings
Since
2.5
_cfgColumnSeparatorback to summary
protected final char _cfgColumnSeparator
_cfgControlCharEscapeCharback to summary
protected final char _cfgControlCharEscapeChar
Since
2.9.9
_cfgEscapeCharacterback to summary
protected final int _cfgEscapeCharacter
Since
2.7
_cfgEscapeControlCharWithEscapeCharback to summary
protected boolean _cfgEscapeControlCharWithEscapeChar
Since
2.9.9
_cfgEscapeQuoteCharWithEscapeCharback to summary
protected boolean _cfgEscapeQuoteCharWithEscapeChar
_cfgIncludeMissingTailback to summary
protected boolean _cfgIncludeMissingTail
Since
2.4
_cfgLineSeparatorback to summary
protected final char[] _cfgLineSeparator
_cfgLineSeparatorLengthback to summary
protected final int _cfgLineSeparatorLength
_cfgMaxQuoteCheckCharsback to summary
protected final int _cfgMaxQuoteCheckChars
_cfgMinSafeCharback to summary
protected final int _cfgMinSafeChar

Lowest-valued character that is safe to output without using quotes around value, NOT including possible escape character.

_cfgNullValueback to summary
protected final char[] _cfgNullValue
Since
2.5
_cfgOptimalQuotingback to summary
protected boolean _cfgOptimalQuoting

Marker flag used to determine if to do optimal (aka "strict") quoting checks or not (looser conservative check)

Since
2.4
_cfgQuoteCharacterback to summary
protected final int _cfgQuoteCharacter
_cfgQuoteCharEscapeCharback to summary
protected final char _cfgQuoteCharEscapeChar
_cfgUseFastDoubleWriterback to summary
protected boolean _cfgUseFastDoubleWriter
Since
2.14
_charsWrittenback to summary
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.

_columnCountback to summary
protected int _columnCount
Since
2.4
_csvFeaturesback to summary
protected int _csvFeatures
_ioContextback to summary
protected final IOContext _ioContext
_lastBufferedback to summary
protected int _lastBuffered

Index of the last buffered value

_nextColumnToWriteback to summary
protected int _nextColumnToWrite

Index of column we expect to write next

_outback to summary
protected final Writer _out

Underlying Writer used for output.

_outputBufferback to summary
protected char[] _outputBuffer

Intermediate buffer in which contents are buffered before being written using _out.

_outputEndback to summary
protected final int _outputEnd

Offset to index after the last valid index in _outputBuffer. Typically same as length of the buffer.

_outputEscapesback to summary
protected int[] _outputEscapes

Currently active set of output escape code definitions (whether and how to escape or not).

_outputTailback to summary
protected int _outputTail

Pointer to the next available char position in _outputBuffer

_trailingLFRemovedback to summary
protected boolean _trailingLFRemoved
FALSE_CHARSback to summary
private static final char[] FALSE_CHARS
HEX_CHARSback to summary
protected static final char[] HEX_CHARS
MAX_QUOTE_CHECKback to summary
protected static final int MAX_QUOTE_CHECK

Also: only do check for optional quotes for short values; longer ones will always be quoted.

NO_BUFFEREDback to summary
protected final BufferedValue[] NO_BUFFERED
SHORT_WRITEback to summary
protected static final int SHORT_WRITE

As an optimization we try coalescing short writes into buffer; but pass longer directly.

sOutputEscapesback to summary
private static final int[] sOutputEscapes
TRUE_CHARSback to summary
private static final char[] TRUE_CHARS

Constructor Detail

CsvEncoderback to summary
public CsvEncoder(IOContext ctxt, int csvFeatures, Writer out, CsvSchema schema)

Deprecated

Annotations
@Deprecated
CsvEncoderback to summary
public CsvEncoder(IOContext ctxt, int csvFeatures, Writer out, CsvSchema schema, boolean useFastDoubleWriter)
CsvEncoderback to summary
public CsvEncoder(CsvEncoder base, CsvSchema newSchema)

Method Detail

_appendback to summary
protected void _append(char[] ch) throws IOException
_appendCharacterEscapeback to summary
private void _appendCharacterEscape(char ch, int escCode) throws IOException

Method called to append escape sequence for given character, at the end of standard output buffer; or if not possible, write out directly.

_bufferback to summary
protected void _buffer(int index, BufferedValue v)
_calcSafeCharback to summary
private final int _calcSafeChar()
_flushBufferback to summary
protected void _flushBuffer() throws IOException
_getQuoteCharEscapeCharback to summary
private final char _getQuoteCharEscapeChar(final boolean escapeQuoteCharWithEscapeChar, final int quoteCharacter, final int escapeCharacter)
_mayNeedQuotesback to summary
protected boolean _mayNeedQuotes(String value, int length, int columnIndex)

Helper method that determines whether given String is likely to require quoting; check tries to optimize for speed.

_needsQuotingLooseback to summary
protected final boolean _needsQuotingLoose(String value)
Since
2.4
_needsQuotingLooseback to summary
protected final boolean _needsQuotingLoose(String value, int esc)
_needsQuotingStrictback to summary
protected boolean _needsQuotingStrict(String value)
Since
2.4
_needsQuotingStrictback to summary
protected boolean _needsQuotingStrict(String value, int esc)
Since
2.7
_releaseBuffersback to summary
public void _releaseBuffers()
_removeTrailingLFback to summary
private void _removeTrailingLF() throws IOException
_writeLongQuotedback to summary
private final void _writeLongQuoted(String text, char q) throws IOException
_writeLongQuotedAndEscapedback to summary
private final void _writeLongQuotedAndEscaped(String text, char esc) throws IOException
_writeQuotedback to summary
public void _writeQuoted(String text) throws IOException
_writeQuotedback to summary
protected void _writeQuoted(String text, char q, int i) throws IOException
_writeQuotedAndEscapedback to summary
public void _writeQuotedAndEscaped(String text, char esc) throws IOException
_writeQuotedAndEscapedback to summary
protected void _writeQuotedAndEscaped(String text, char q, char esc, int i) throws IOException
appendColumnSeparatorback to summary
protected void appendColumnSeparator() throws IOException
appendNullback to summary
protected void appendNull() throws IOException
appendNumberValueback to summary
protected void appendNumberValue(String numStr) throws IOException
appendRawValueback to summary
protected void appendRawValue(String value) throws IOException
appendValueback to summary
protected void appendValue(String value) throws IOException
appendValueback to summary
protected void appendValue(int value) throws IOException
appendValueback to summary
protected void appendValue(long value) throws IOException
appendValueback to summary
protected void appendValue(float value) throws IOException
appendValueback to summary
protected void appendValue(double value) throws IOException
appendValueback to summary
protected void appendValue(boolean value) throws IOException
closeback to summary
public void close(boolean autoClose, boolean flushStream) throws IOException
endRowback to summary
public void endRow() throws IOException
flushback to summary
public void flush(boolean flushStream) throws IOException
getOutputBufferedback to summary
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.

getOutputTargetback to summary
public Object getOutputTarget()
nextColumnIndexback to summary
public int nextColumnIndex()
overrideFormatFeaturesback to summary
public CsvEncoder overrideFormatFeatures(int feat)
setOutputEscapesback to summary
public CsvEncoder setOutputEscapes(int[] esc)
withSchemaback to summary
public CsvEncoder withSchema(CsvSchema schema)
writeback to summary
public final void write(int columnIndex, String value) throws IOException
writeback to summary
public final void write(int columnIndex, char[] ch, int offset, int len) throws IOException
writeback to summary
public final void write(int columnIndex, int value) throws IOException
writeback to summary
public final void write(int columnIndex, long value) throws IOException
writeback to summary
public final void write(int columnIndex, BigInteger value) throws IOException
writeback to summary
public final void write(int columnIndex, float value) throws IOException
writeback to summary
public final void write(int columnIndex, double value) throws IOException
writeback to summary
public final void write(int columnIndex, BigDecimal value, boolean plain) throws IOException
writeback to summary
public final void write(int columnIndex, boolean value) throws IOException
writeColumnNameback to summary
public final void writeColumnName(String name) throws IOException
writeNonEscapedback to summary
public final void writeNonEscaped(int columnIndex, String rawValue) throws IOException
Since
2.5
writeNullback to summary
public final void writeNull(int columnIndex) throws IOException
writeNumberback to summary
private void writeNumber(String text) throws IOException
writeRawback to summary
public void writeRaw(String text) throws IOException
writeRawback to summary
public void writeRaw(String text, int start, int len) throws IOException
writeRawback to summary
public void writeRaw(char[] text, int offset, int len) throws IOException
writeRawback to summary
public void writeRaw(char c) throws IOException
writeRawLongback to summary
private void writeRawLong(String text) throws IOException