Class CsvGenerator
java.lang.Object
com.fasterxml.jackson.core.JsonGenerator
com.fasterxml.jackson.core.base.GeneratorBase
com.fasterxml.jackson.dataformat.csv.CsvGenerator
- All Implemented Interfaces:
com.fasterxml.jackson.core.Versioned
,Closeable
,Flushable
,AutoCloseable
public class CsvGenerator
extends com.fasterxml.jackson.core.base.GeneratorBase
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
Enumeration that defines all togglable features for CSV writers (if any: currently none) -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected StringBuilder
Accumulated contents of an array cell, if anyprotected int
Additional counter that indicates number of value entries in the array.protected String
Separator to use during writing of (simple) array value, to be encoded as a single column value, if any.protected int
Bit flag composed of bits that indicate whichCsvGenerator.Feature
s are enabled.protected boolean
Flag that indicates that we need to write header line, if one is needed.protected final com.fasterxml.jackson.core.io.IOContext
protected int
Index of column that we will be getting next, based on field name call that was made.protected CsvSchema
Definition of columns being written, if available.protected boolean
Flag set when property to write is unknown, and the matching value is to be skipped quietly.protected com.fasterxml.jackson.core.json.JsonWriteContext
When skipping output (for "unknown" output), outermost write context where skipping should occurprotected CsvEncoder
private static final CsvSchema
protected static final long
protected static final long
Fields inherited from class com.fasterxml.jackson.core.base.GeneratorBase
_cfgNumbersAsStrings, _closed, _features, _objectCodec, _writeContext, DERIVED_FEATURES_MASK, MAX_BIG_DECIMAL_SCALE, SURR1_FIRST, SURR1_LAST, SURR2_FIRST, SURR2_LAST, WRITE_BINARY, WRITE_BOOLEAN, WRITE_NULL, WRITE_NUMBER, WRITE_RAW, WRITE_STRING
Fields inherited from class com.fasterxml.jackson.core.JsonGenerator
_cfgPrettyPrinter
-
Constructor Summary
ConstructorsConstructorDescriptionCsvGenerator
(com.fasterxml.jackson.core.io.IOContext ctxt, int jsonFeatures, int csvFeatures, com.fasterxml.jackson.core.ObjectCodec codec, CsvEncoder csvWriter) CsvGenerator
(com.fasterxml.jackson.core.io.IOContext ctxt, int jsonFeatures, int csvFeatures, com.fasterxml.jackson.core.ObjectCodec codec, Writer out, CsvSchema schema) -
Method Summary
Modifier and TypeMethodDescriptionprotected void
_addToArray
(char[] value) protected void
_addToArray
(String value) protected final int
protected void
protected void
protected void
Method called when there is a problem related to mapping data (compared to a low-level generation); if so, should be surfaced asprotected final void
_verifyValueWrite
(String typeMsg) private final void
_writeFieldName
(String name) boolean
boolean
canUseSchema
(com.fasterxml.jackson.core.FormatSchema schema) boolean
void
close()
configure
(CsvGenerator.Feature f, boolean state) protected void
Method called when the current row is complete; typically will flush possibly buffered column values, append linefeed and reset state appropriately.final void
flush()
int
int
NOTE: while this method will return some information on amount of data buffered, it may be an incomplete view as some buffering happens at a higher level, as not-yet-serialized values.final boolean
com.fasterxml.jackson.core.JsonGenerator
overrideFormatFeatures
(int values, int mask) setPrettyPrinter
(com.fasterxml.jackson.core.PrettyPrinter pp) No way (or need) to indent anything, so let's block any attempts.void
setSchema
(com.fasterxml.jackson.core.FormatSchema schema) No way (or need) to indent anything, so let's block any attempts.com.fasterxml.jackson.core.Version
version()
void
writeBinary
(com.fasterxml.jackson.core.Base64Variant b64variant, byte[] data, int offset, int len) void
writeBoolean
(boolean state) final void
final void
final void
writeFieldName
(com.fasterxml.jackson.core.SerializableString name) final void
writeFieldName
(String name) void
void
writeNumber
(double v) void
writeNumber
(float v) void
writeNumber
(int v) void
writeNumber
(long v) void
writeNumber
(String encodedValue) void
void
void
writeOmittedField
(String fieldName) void
writeRaw
(char c) void
writeRaw
(char[] text, int offset, int len) void
void
void
writeRawUTF8String
(byte[] text, int offset, int len) void
writeRawValue
(char[] text, int offset, int len) void
writeRawValue
(String text) void
writeRawValue
(String text, int offset, int len) final void
final void
void
writeString
(char[] text, int offset, int len) final void
writeString
(com.fasterxml.jackson.core.SerializableString sstr) void
writeString
(String text) final void
writeStringField
(String fieldName, String value) void
writeUTF8String
(byte[] text, int offset, int len) Methods inherited from class com.fasterxml.jackson.core.base.GeneratorBase
_asString, _checkStdFeatureChanges, _constructDefaultPrettyPrinter, _decodeSurrogate, disable, enable, getCodec, getCurrentValue, getFeatureMask, getOutputContext, isClosed, isEnabled, overrideStdFeatures, setCodec, setCurrentValue, setFeatureMask, writeBinary, writeObject, writeRawValue, writeStartObject, writeTree
Methods inherited from class com.fasterxml.jackson.core.JsonGenerator
_copyCurrentContents, _reportError, _reportUnsupportedOperation, _throwInternal, _verifyOffsets, _writeSimpleObject, canWriteBinaryNatively, canWriteObjectId, canWriteTypeId, configure, copyCurrentEvent, copyCurrentStructure, getCharacterEscapes, getHighestEscapedChar, getPrettyPrinter, getSchema, isEnabled, setCharacterEscapes, setHighestNonEscapedChar, setRootValueSeparator, writeArray, writeArray, writeArray, writeArray, writeArrayFieldStart, writeBinary, writeBinary, writeBinary, writeBinaryField, writeBooleanField, writeEmbeddedObject, writeFieldId, writeNullField, writeNumber, writeNumber, writeNumberField, writeNumberField, writeNumberField, writeNumberField, writeNumberField, writeNumberField, writeNumberField, writeObjectField, writeObjectFieldStart, writeObjectId, writeObjectRef, writeRaw, writeStartArray, writeStartArray, writeStartArray, writeStartObject, writeString, writeTypeId, writeTypePrefix, writeTypeSuffix
-
Field Details
-
MIN_INT_AS_LONG
protected static final long MIN_INT_AS_LONG- See Also:
-
MAX_INT_AS_LONG
protected static final long MAX_INT_AS_LONG- See Also:
-
EMPTY_SCHEMA
-
_ioContext
protected final com.fasterxml.jackson.core.io.IOContext _ioContext -
_formatFeatures
protected int _formatFeaturesBit flag composed of bits that indicate whichCsvGenerator.Feature
s are enabled. -
_schema
Definition of columns being written, if available. -
_writer
-
_handleFirstLine
protected boolean _handleFirstLineFlag that indicates that we need to write header line, if one is needed. Used because schema may be specified after instance is constructed. -
_nextColumnByName
protected int _nextColumnByNameIndex of column that we will be getting next, based on field name call that was made. -
_skipValue
protected boolean _skipValueFlag set when property to write is unknown, and the matching value is to be skipped quietly.- Since:
- 2.5
-
_arraySeparator
Separator to use during writing of (simple) array value, to be encoded as a single column value, if any.- Since:
- 2.5
-
_arrayContents
Accumulated contents of an array cell, if any -
_arrayElements
protected int _arrayElementsAdditional counter that indicates number of value entries in the array. Needed because `null` entries do not add content, but need to be separated by array cell separator- Since:
- 2.7
-
_skipWithin
protected com.fasterxml.jackson.core.json.JsonWriteContext _skipWithinWhen skipping output (for "unknown" output), outermost write context where skipping should occur- Since:
- 2.7
-
-
Constructor Details
-
CsvGenerator
public CsvGenerator(com.fasterxml.jackson.core.io.IOContext ctxt, int jsonFeatures, int csvFeatures, com.fasterxml.jackson.core.ObjectCodec codec, Writer out, CsvSchema schema) - Since:
- 2.4
-
CsvGenerator
public CsvGenerator(com.fasterxml.jackson.core.io.IOContext ctxt, int jsonFeatures, int csvFeatures, com.fasterxml.jackson.core.ObjectCodec codec, CsvEncoder csvWriter)
-
-
Method Details
-
version
public com.fasterxml.jackson.core.Version version()- Specified by:
version
in interfacecom.fasterxml.jackson.core.Versioned
- Overrides:
version
in classcom.fasterxml.jackson.core.base.GeneratorBase
-
useDefaultPrettyPrinter
No way (or need) to indent anything, so let's block any attempts. (should we throw an exception instead?)- Overrides:
useDefaultPrettyPrinter
in classcom.fasterxml.jackson.core.base.GeneratorBase
-
setPrettyPrinter
No way (or need) to indent anything, so let's block any attempts. (should we throw an exception instead?)- Overrides:
setPrettyPrinter
in classcom.fasterxml.jackson.core.JsonGenerator
-
getOutputTarget
- Overrides:
getOutputTarget
in classcom.fasterxml.jackson.core.JsonGenerator
-
getOutputBuffered
public int getOutputBuffered()NOTE: while this method will return some information on amount of data buffered, it may be an incomplete view as some buffering happens at a higher level, as not-yet-serialized values.- Overrides:
getOutputBuffered
in classcom.fasterxml.jackson.core.JsonGenerator
-
setSchema
public void setSchema(com.fasterxml.jackson.core.FormatSchema schema) - Overrides:
setSchema
in classcom.fasterxml.jackson.core.JsonGenerator
-
getFormatFeatures
public int getFormatFeatures()- Overrides:
getFormatFeatures
in classcom.fasterxml.jackson.core.JsonGenerator
-
overrideFormatFeatures
public com.fasterxml.jackson.core.JsonGenerator overrideFormatFeatures(int values, int mask) - Overrides:
overrideFormatFeatures
in classcom.fasterxml.jackson.core.JsonGenerator
-
canUseSchema
public boolean canUseSchema(com.fasterxml.jackson.core.FormatSchema schema) - Overrides:
canUseSchema
in classcom.fasterxml.jackson.core.JsonGenerator
-
canOmitFields
public boolean canOmitFields()- Overrides:
canOmitFields
in classcom.fasterxml.jackson.core.JsonGenerator
-
canWriteFormattedNumbers
public boolean canWriteFormattedNumbers()- Overrides:
canWriteFormattedNumbers
in classcom.fasterxml.jackson.core.JsonGenerator
-
writeFieldName
- Specified by:
writeFieldName
in classcom.fasterxml.jackson.core.JsonGenerator
- Throws:
IOException
-
writeFieldName
public final void writeFieldName(com.fasterxml.jackson.core.SerializableString name) throws IOException - Overrides:
writeFieldName
in classcom.fasterxml.jackson.core.base.GeneratorBase
- Throws:
IOException
-
writeStringField
- Overrides:
writeStringField
in classcom.fasterxml.jackson.core.JsonGenerator
- Throws:
IOException
-
_writeFieldName
- Throws:
IOException
-
isEnabled
-
configure
-
enable
-
disable
-
flush
- Specified by:
flush
in interfaceFlushable
- Specified by:
flush
in classcom.fasterxml.jackson.core.base.GeneratorBase
- Throws:
IOException
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classcom.fasterxml.jackson.core.base.GeneratorBase
- Throws:
IOException
-
writeStartArray
- Specified by:
writeStartArray
in classcom.fasterxml.jackson.core.JsonGenerator
- Throws:
IOException
-
writeEndArray
- Specified by:
writeEndArray
in classcom.fasterxml.jackson.core.JsonGenerator
- Throws:
IOException
-
writeStartObject
- Specified by:
writeStartObject
in classcom.fasterxml.jackson.core.JsonGenerator
- Throws:
IOException
-
writeEndObject
- Specified by:
writeEndObject
in classcom.fasterxml.jackson.core.JsonGenerator
- Throws:
IOException
-
writeString
- Specified by:
writeString
in classcom.fasterxml.jackson.core.JsonGenerator
- Throws:
IOException
-
writeString
- Specified by:
writeString
in classcom.fasterxml.jackson.core.JsonGenerator
- Throws:
IOException
-
writeString
public final void writeString(com.fasterxml.jackson.core.SerializableString sstr) throws IOException - Overrides:
writeString
in classcom.fasterxml.jackson.core.base.GeneratorBase
- Throws:
IOException
-
writeRawUTF8String
- Specified by:
writeRawUTF8String
in classcom.fasterxml.jackson.core.JsonGenerator
- Throws:
IOException
-
writeUTF8String
- Specified by:
writeUTF8String
in classcom.fasterxml.jackson.core.JsonGenerator
- Throws:
IOException
-
writeRaw
- Specified by:
writeRaw
in classcom.fasterxml.jackson.core.JsonGenerator
- Throws:
IOException
-
writeRaw
- Specified by:
writeRaw
in classcom.fasterxml.jackson.core.JsonGenerator
- Throws:
IOException
-
writeRaw
- Specified by:
writeRaw
in classcom.fasterxml.jackson.core.JsonGenerator
- Throws:
IOException
-
writeRaw
- Specified by:
writeRaw
in classcom.fasterxml.jackson.core.JsonGenerator
- Throws:
IOException
-
writeRawValue
- Overrides:
writeRawValue
in classcom.fasterxml.jackson.core.base.GeneratorBase
- Throws:
IOException
-
writeRawValue
- Overrides:
writeRawValue
in classcom.fasterxml.jackson.core.base.GeneratorBase
- Throws:
IOException
-
writeRawValue
- Overrides:
writeRawValue
in classcom.fasterxml.jackson.core.base.GeneratorBase
- Throws:
IOException
-
writeBinary
public void writeBinary(com.fasterxml.jackson.core.Base64Variant b64variant, byte[] data, int offset, int len) throws IOException, com.fasterxml.jackson.core.JsonGenerationException - Specified by:
writeBinary
in classcom.fasterxml.jackson.core.JsonGenerator
- Throws:
IOException
com.fasterxml.jackson.core.JsonGenerationException
-
writeBoolean
- Specified by:
writeBoolean
in classcom.fasterxml.jackson.core.JsonGenerator
- Throws:
IOException
-
writeNull
- Specified by:
writeNull
in classcom.fasterxml.jackson.core.JsonGenerator
- Throws:
IOException
-
writeNumber
- Specified by:
writeNumber
in classcom.fasterxml.jackson.core.JsonGenerator
- Throws:
IOException
-
writeNumber
- Specified by:
writeNumber
in classcom.fasterxml.jackson.core.JsonGenerator
- Throws:
IOException
-
writeNumber
- Specified by:
writeNumber
in classcom.fasterxml.jackson.core.JsonGenerator
- Throws:
IOException
-
writeNumber
- Specified by:
writeNumber
in classcom.fasterxml.jackson.core.JsonGenerator
- Throws:
IOException
-
writeNumber
- Specified by:
writeNumber
in classcom.fasterxml.jackson.core.JsonGenerator
- Throws:
IOException
-
writeNumber
- Specified by:
writeNumber
in classcom.fasterxml.jackson.core.JsonGenerator
- Throws:
IOException
-
writeNumber
- Specified by:
writeNumber
in classcom.fasterxml.jackson.core.JsonGenerator
- Throws:
IOException
-
writeOmittedField
- Overrides:
writeOmittedField
in classcom.fasterxml.jackson.core.JsonGenerator
- Throws:
IOException
-
_verifyValueWrite
- Specified by:
_verifyValueWrite
in classcom.fasterxml.jackson.core.base.GeneratorBase
- Throws:
IOException
-
_releaseBuffers
protected void _releaseBuffers()- Specified by:
_releaseBuffers
in classcom.fasterxml.jackson.core.base.GeneratorBase
-
_reportMappingError
protected void _reportMappingError(String msg) throws com.fasterxml.jackson.core.JsonProcessingException Method called when there is a problem related to mapping data (compared to a low-level generation); if so, should be surfaced as- Throws:
com.fasterxml.jackson.core.JsonProcessingException
- Since:
- 2.7
-
_columnIndex
protected final int _columnIndex() -
finishRow
Method called when the current row is complete; typically will flush possibly buffered column values, append linefeed and reset state appropriately.- Throws:
IOException
-
_handleFirstLine
- Throws:
IOException
-
_addToArray
-
_addToArray
protected void _addToArray(char[] value)
-