Top Fields Constructors Methods
com.amazon.ion.impl

pack-priv abstract Class IonWriterSystem

extends _Private_IonWriterBase
Class Inheritance
Known Direct Subclasses
com.amazon.ion.impl.IonWriterSystemBinary, com.amazon.ion.impl.IonWriterSystemText, com.amazon.ion.impl.IonWriterSystemTree
Static Imports
com.amazon.ion.SymbolTable.UNKNOWN_SYMBOL_ID, com.amazon.ion.impl._Private_Utils.newSymbolToken, ._Private_Utils.newSymbolTokens

Field Summary

Modifier and TypeField and Description
private int
private SymbolToken[]
private boolean
_anything_written

Indicates whether we've written anything at all.

pack-priv final SymbolTable
_default_system_symbol_table

The system symtab used when resetting the stream.

private String
private int
private IonType
_field_name_type

really ion type is only used for int, string or null (unknown)

private IonWriterBuilder.InitialIvmHandling
_initial_ivm_handling

What to do about IVMs at the start of the stream.

private final IonWriterBuilder.IvmMinimizing
_ivm_minimizing

What to do about non-initial IVMs.

private boolean
_previous_value_was_ivm

Indicates whether the (immediately previous emitted value was an IVM.

private SymbolTable
_symbol_table

Must be either local or system table, and never null.

private static final int
Inherited from com.amazon.ion.impl._Private_IonWriterBase:
ERROR_FINISH_NOT_AT_TOP_LEVELERROR_MISSING_FIELD_NAME

Constructor Summary

AccessConstructor and Description
pack-priv
IonWriterSystem(SymbolTable
must not be null.
defaultSystemSymbolTable
,
IonWriterBuilder.InitialIvmHandling initialIvmHandling, IonWriterBuilder.IvmMinimizing ivmMinimizing, boolean requireSymbolValidation)

Method Summary

Modifier and TypeMethod and Description
pack-priv final int
public final void
addTypeAnnotation(String
string annotation to append to the annotation list
annotation
)

Implements com.amazon.ion.IonWriter.addTypeAnnotation.

Adds a given string to the list of pending annotations.

pack-priv final int
public <T> T
asFacet(Class<T>
The type token of the requested facet type.
facetType
)

Overrides com.amazon.ion.impl._Private_IonWriterBase.asFacet.

Implements com.amazon.ion.facet.Faceted.asFacet.

Returns a facet of this subject if supported.

pack-priv final SymbolToken
pack-priv final String
assumeKnownSymbol(int sid)

Implements abstract com.amazon.ion.impl._Private_IonWriterBase.assumeKnownSymbol.

Translates a symbol using the current symtab.

pack-priv final void
pack-priv final void
pack-priv void
pack-priv final void
ensureAnnotationCapacity(int length)

Ensures that our _annotations and _annotation_sids arrays have enough capacity to hold the given number of annotations.

pack-priv final int
findAnnotation(String
the annotation to find.
name
)

Implements abstract com.amazon.ion.impl._Private_IonWriterBase.findAnnotation.

Returns the given annotation's index in the value's annotations list, or -1 if not present.

public void
finish()

Implements com.amazon.ion.IonWriter.finish.

Indicates that writing is completed and all buffered data should be written and flushed as if this were the end of the Ion data stream.

pack-priv final SymbolTable
pack-priv final int

Returns:

symbol id of the name of the field about to be written or -1 if it is not set
getFieldId
()

Returns the symbol id of the current field name, if the field name has been set.

public final SymbolTable
getSymbolTable()

Implements com.amazon.ion.IonWriter.getSymbolTable.

Gets the symbol table that is currently in use by the writer.

pack-priv final int[]
getTypeAnnotationIds()

Implements abstract com.amazon.ion.impl._Private_IonWriterBase.getTypeAnnotationIds.

Gets the current list of pending annotations.

pack-priv final String[]
getTypeAnnotations()

Implements abstract com.amazon.ion.impl._Private_IonWriterBase.getTypeAnnotations.

Gets the current list of pending annotations.

pack-priv final SymbolToken[]
pack-priv final boolean
pack-priv SymbolTable

Returns:

not null.
inject_local_symbol_table
()

Builds a new local symbol table from the current contextual symtab (a system symtab).

pack-priv final int[]
public final boolean
isFieldNameSet()

Implements abstract com.amazon.ion.impl._Private_IonWriterBase.isFieldNameSet.

Returns true if the field name has been set either through setFieldName or setFieldId.

public final void
setFieldName(String
text of the field name
name
)

Implements com.amazon.ion.IonWriter.setFieldName.

Sets the pending field name to the given text.

public final void
setFieldNameSymbol(SymbolToken
text of the field name
name
)

Implements com.amazon.ion.IonWriter.setFieldNameSymbol.

Sets the pending field name to the given token.

public final void
setSymbolTable(SymbolTable
base symbol table for encoding. Must not be null.
symbols
)

Implements abstract com.amazon.ion.impl._Private_IonWriterBase.setSymbolTable.

Sets the symbol table to use for encoding to be the passed in symbol table.

public final void
setTypeAnnotations(String...
string array with the annotations. If null or empty, any pending annotations are cleared.
annotations
)

Implements com.amazon.ion.IonWriter.setTypeAnnotations.

Sets the full list of pending annotations to the given text symbols.

public final void
setTypeAnnotationSymbols(SymbolToken...
If null or empty, any pending annotations are cleared.
annotations
)

Implements com.amazon.ion.IonWriter.setTypeAnnotationSymbols.

Sets the full list of pending annotations to the given symbols.

pack-priv boolean
pack-priv void
pack-priv final void
public final void
writeIonVersionMarker()

Implements abstract com.amazon.ion.impl._Private_IonWriterBase.writeIonVersionMarker.

Write an Ion version marker symbol to the output.

pack-priv abstract void
writeIonVersionMarkerAsIs(SymbolTable systemSymtab)

Writes an IVM without checking preconditions or InitialIVMHandling.

pack-priv void
pack-priv final void
writeSymbol(int
symbol table id to write
symbolId
)

Implements abstract com.amazon.ion.impl._Private_IonWriterBase.writeSymbol.

Write symbolId out as an IonSymbol value.

public final void
writeSymbol(String
may be null to represent null.symbol.
value
)

Implements com.amazon.ion.IonWriter.writeSymbol.

Writes the text of an Ion symbol value.

pack-priv abstract void
writeSymbolAsIs(int symbolId)

Writes a symbol without checking for system ID.

pack-priv abstract void
writeSymbolAsIs(String value)

Writes a symbol without checking for system ID.

Inherited from com.amazon.ion.impl._Private_IonWriterBase:
getDepthisStreamCopyOptimizedpop_passed_symbol_tablevalidateSymbolIdwriteBlobwriteClobwriteDecimalwriteFloatwriteNullwriteSymbolTokenwriteTimestampUTCwriteValuewriteValuewriteValueRecursivelywriteValues

Field Detail

_annotation_countback to summary
private int _annotation_count
_annotationsback to summary
private SymbolToken[] _annotations
_anything_writtenback to summary
private boolean _anything_written

Indicates whether we've written anything at all.

_default_system_symbol_tableback to summary
pack-priv final SymbolTable _default_system_symbol_table

The system symtab used when resetting the stream. Must not be null.

_field_nameback to summary
private String _field_name
_field_name_sidback to summary
private int _field_name_sid
_field_name_typeback to summary
private IonType _field_name_type

really ion type is only used for int, string or null (unknown)

_initial_ivm_handlingback to summary
private IonWriterBuilder.InitialIvmHandling _initial_ivm_handling

What to do about IVMs at the start of the stream. Becomes null as soon as we write anything. After a finish() this becomes InitialIVMHandling#ENSURE because we must force another IVM to be emitted.

_ivm_minimizingback to summary
private final IonWriterBuilder.IvmMinimizing _ivm_minimizing

What to do about non-initial IVMs.

_previous_value_was_ivmback to summary
private boolean _previous_value_was_ivm

Indicates whether the (immediately previous emitted value was an IVM. This is cleared by endValue().

_symbol_tableback to summary
private SymbolTable _symbol_table

Must be either local or system table, and never null. May only be changed between top-level values.

DEFAULT_ANNOTATION_COUNTback to summary
private static final int DEFAULT_ANNOTATION_COUNT

Constructor Detail

IonWriterSystemback to summary
pack-priv IonWriterSystem(SymbolTable defaultSystemSymbolTable, IonWriterBuilder.InitialIvmHandling initialIvmHandling, IonWriterBuilder.IvmMinimizing ivmMinimizing, boolean requireSymbolValidation)
Parameters
defaultSystemSymbolTable:SymbolTable

must not be null.

Method Detail

add_symbolback to summary
pack-priv final int add_symbol(String name) throws IOException
addTypeAnnotationback to summary
public final void addTypeAnnotation(String annotation)

Implements com.amazon.ion.IonWriter.addTypeAnnotation.

Doc from com.amazon.ion.IonWriter.addTypeAnnotation.

Adds a given string to the list of pending annotations.

The list of pending annotations is cleared when the current value is written via stepIn() or one of the write*() methods.

Parameters
annotation:String

string annotation to append to the annotation list

annotationCountback to summary
pack-priv final int annotationCount()
asFacetback to summary
public <T> T asFacet(Class<T> facetType)

Overrides com.amazon.ion.impl._Private_IonWriterBase.asFacet.

Implements com.amazon.ion.facet.Faceted.asFacet.

Doc from com.amazon.ion.facet.Faceted.asFacet.

Returns a facet of this subject if supported.

Parameters
<T>
The requested facet type.
facetType:Class<T>

The type token of the requested facet type.

Returns:T

An instance of T representing the facet of the subject, or null if the facet is not supported by the subject.

assumeFieldNameSymbolback to summary
pack-priv final SymbolToken assumeFieldNameSymbol()
assumeKnownSymbolback to summary
pack-priv final String assumeKnownSymbol(int sid)

Implements abstract com.amazon.ion.impl._Private_IonWriterBase.assumeKnownSymbol.

Doc from com.amazon.ion.impl._Private_IonWriterBase.assumeKnownSymbol.

Translates a symbol using the current symtab.

Returns:String

not null.

Annotations
@Override
clearAnnotationsback to summary
pack-priv final void clearAnnotations()
clearFieldNameback to summary
pack-priv final void clearFieldName()
endValueback to summary
pack-priv void endValue()
ensureAnnotationCapacityback to summary
pack-priv final void ensureAnnotationCapacity(int length)

Ensures that our _annotations and _annotation_sids arrays have enough capacity to hold the given number of annotations. Does not increase _annotation_count.

findAnnotationback to summary
pack-priv final int findAnnotation(String name)

Implements abstract com.amazon.ion.impl._Private_IonWriterBase.findAnnotation.

Doc from com.amazon.ion.impl._Private_IonWriterBase.findAnnotation.

Returns the given annotation's index in the value's annotations list, or -1 if not present.

Parameters
name:String

the annotation to find.

Returns:int

the index or -1.

Annotations
@Override
finishback to summary
public void finish() throws IOException

Implements com.amazon.ion.IonWriter.finish.

Doc from com.amazon.ion.IonWriter.finish.

Indicates that writing is completed and all buffered data should be written and flushed as if this were the end of the Ion data stream. For example, an Ion binary writer will finalize any local symbol table, write all top-level values, and then flush.

This method may only be called when all top-level values are completely written and stepped-out.

Implementations should allow the application to continue writing further top-level values following the semantics for concatenating Ion data streams. If another top-level value is written, the result must behave as if it were preceded by an Ion version marker, resetting the stream context as if this were a new stream. (Whether or not an IVM is written may depend upon the writer's configuration; see IvmMinimizing.)

This feature can be used to flush buffered data and reset the local symbol table before writing more values. Applications that produce long streams of binary Ion may wish to finish occasionally to relieve memory pressure, then continue writing data using a new local symbol table. This is particularly useful for streams that contain an ever-growing number of unique symbols to avoid unbounded growth of the symbol table, which may degrade performance and bloat the encoding. Applications that produce long streams with a limited number of unique symbols should enable localSymbolTableAppend (see com.amazon.ion.system.IonBinaryWriterBuilder#withLocalSymbolTableAppendEnabled) and flush() instead to avoid re-declaring the local symbol table unnecessarily.

Exceptions
IOException:
if thrown by the underlying output target.
getDefaultSystemSymtabback to summary
pack-priv final SymbolTable getDefaultSystemSymtab()
getFieldIdback to summary
pack-priv final int getFieldId()

Returns the symbol id of the current field name, if the field name has been set. If the name has not been set, either as either a String or a symbol id value, this returns -1 (undefined symbol).

Returns:int

symbol id of the name of the field about to be written or -1 if it is not set

getSymbolTableback to summary
public final SymbolTable getSymbolTable()

Implements com.amazon.ion.IonWriter.getSymbolTable.

Doc from com.amazon.ion.IonWriter.getSymbolTable.

Gets the symbol table that is currently in use by the writer. While writing a number of values the symbol table will be populated with any added symbols.

Note that the table may be replaced during processing. For example, the stream may start out with a system table that's later replaced by a local table in order to store newly-encountered symbols.

When this method returns a local table, it may be mutable, meaning that additional symbols may be interned until it is made read-only. Note that manually mutating local symbol tables is a deprecated feature; please instead use IonSystem#newBinaryWriter(java.io.OutputStream, SymbolTable...) or IonSystem#newTextWriter(java.io.OutputStream, SymbolTable...) to provide custom symbol table(s) to writers upon construction.

Returns:SymbolTable

current symbol table

getTypeAnnotationIdsback to summary
pack-priv final int[] getTypeAnnotationIds()

Implements abstract com.amazon.ion.impl._Private_IonWriterBase.getTypeAnnotationIds.

Doc from com.amazon.ion.impl._Private_IonWriterBase.getTypeAnnotationIds.

Gets the current list of pending annotations. This is the contents of the current annotations array of this writer.

If the annotations were set as string they will be converted to symbol IDs (ints) if a symbol table is available. In the event a symbol table is not available a null array will be returned. If no annotations are set a 0 length array will be returned.

Returns:int[]

pending type annotations as symbol ID ints, null if the annotations cannot be expressed as IDs.

Annotations
@Override
getTypeAnnotationsback to summary
pack-priv final String[] getTypeAnnotations()

Implements abstract com.amazon.ion.impl._Private_IonWriterBase.getTypeAnnotations.

Doc from com.amazon.ion.impl._Private_IonWriterBase.getTypeAnnotations.

Gets the current list of pending annotations. This is the contents of the current annotations array of this writer.

If the annotations were set as IDs they will be converted if a symbol table is available. In the event a symbol table is not available a null array will be returned. If no annotations are set a 0 length array will be returned.

Returns:String[]

pending type annotations as strings, null if the annotations cannot be expressed as strings.

Annotations
@Override
getTypeAnnotationSymbolsback to summary
pack-priv final SymbolToken[] getTypeAnnotationSymbols()
hasAnnotationsback to summary
pack-priv final boolean hasAnnotations()
inject_local_symbol_tableback to summary
pack-priv SymbolTable inject_local_symbol_table() throws IOException

Builds a new local symbol table from the current contextual symtab (a system symtab).

Returns:SymbolTable

not null.

internAnnotationsAndGetSidsback to summary
pack-priv final int[] internAnnotationsAndGetSids() throws IOException
isFieldNameSetback to summary
public final boolean isFieldNameSet()

Implements abstract com.amazon.ion.impl._Private_IonWriterBase.isFieldNameSet.

Doc from com.amazon.ion.impl._Private_IonWriterBase.isFieldNameSet.

Returns true if the field name has been set either through setFieldName or setFieldId. This is generally more efficient than calling getFieldName or getFieldId and checking the return type as it does not need to resolve the name through a symbol table. This returns false if the field name has not been set.

Returns:boolean

true if a field name has been set false otherwise

Annotations
@Override
setFieldNameback to summary
public final void setFieldName(String name)

Implements com.amazon.ion.IonWriter.setFieldName.

Doc from com.amazon.ion.IonWriter.setFieldName.

Sets the pending field name to the given text.

The pending field name is cleared when the current value is written via stepIn() or one of the write*() methods.

Parameters
name:String

text of the field name

setFieldNameSymbolback to summary
public final void setFieldNameSymbol(SymbolToken name)

Implements com.amazon.ion.IonWriter.setFieldNameSymbol.

Doc from com.amazon.ion.IonWriter.setFieldNameSymbol.

Sets the pending field name to the given token.

The pending field name is cleared when the current value is written via stepIn() or one of the write*() methods.

Parameters
name:SymbolToken

text of the field name

setSymbolTableback to summary
public final void setSymbolTable(SymbolTable symbols) throws IOException

Implements abstract com.amazon.ion.impl._Private_IonWriterBase.setSymbolTable.

Doc from com.amazon.ion.impl._Private_IonWriterBase.setSymbolTable.

Sets the symbol table to use for encoding to be the passed in symbol table. The can only be done between top-level values. As symbols are written this symbol table is used to resolve them. If the symbols are undefined this symbol table is updated to include them as local symbols. The updated symbol table will be written before any of the local values are emitted.

If the symbol table is the system symbol table an Ion version marker will be written to the output. If symbols not in the system symbol table are written a local symbol table will be created and written before the current top level value.

This implementation simply validates that the argument is not a shared symbol table, and assigns it to _symbol_table.

Parameters
symbols:SymbolTable

base symbol table for encoding. Must not be null.

Annotations
@Override
setTypeAnnotationsback to summary
public final void setTypeAnnotations(String... annotations)

Implements com.amazon.ion.IonWriter.setTypeAnnotations.

Doc from com.amazon.ion.IonWriter.setTypeAnnotations.

Sets the full list of pending annotations to the given text symbols. Any pending annotations are cleared. The contents of the annotations array are copied into this writer, so the caller does not need to preserve the array.

The list of pending annotations is cleared when the current value is written via stepIn() or one of the write*() methods.

Parameters
annotations:String[]

string array with the annotations. If null or empty, any pending annotations are cleared.

setTypeAnnotationSymbolsback to summary
public final void setTypeAnnotationSymbols(SymbolToken... annotations)

Implements com.amazon.ion.IonWriter.setTypeAnnotationSymbols.

Doc from com.amazon.ion.IonWriter.setTypeAnnotationSymbols.

Sets the full list of pending annotations to the given symbols. Any pending annotations are cleared. The contents of the annotations array are copied into this writer, so the caller does not need to preserve the array.

The list of pending annotations is cleared when the current value is written via stepIn() or one of the write*() methods.

This is an "expert method": correct use requires deep understanding of the Ion binary format. You almost certainly don't want to use it.

Parameters
annotations:SymbolToken[]

If null or empty, any pending annotations are cleared.

shouldWriteIvmback to summary
pack-priv boolean shouldWriteIvm()
startValueback to summary
pack-priv void startValue() throws IOException
writeIonVersionMarkerback to summary
pack-priv final void writeIonVersionMarker(SymbolTable systemSymtab) throws IOException

Sets _symbol_table and clears _initial_ivm_handling. Subclasses should override to generate output.

writeIonVersionMarkerback to summary
public final void writeIonVersionMarker() throws IOException

Implements abstract com.amazon.ion.impl._Private_IonWriterBase.writeIonVersionMarker.

Doc from com.amazon.ion.impl._Private_IonWriterBase.writeIonVersionMarker.

Write an Ion version marker symbol to the output. This is the $ion_1_0 value currently (in later versions the number may change). In text output this appears as the text symbol. In binary this will be the symbol id if the writer is in a list, sexp or struct. If the writer is currently at the top level this will write the "magic cookie" value. Writing a version marker will reset the symbol table to be the system symbol table.

Annotations
@Override
writeIonVersionMarkerAsIsback to summary
pack-priv abstract void writeIonVersionMarkerAsIs(SymbolTable systemSymtab) throws IOException

Writes an IVM without checking preconditions or InitialIVMHandling.

writeLocalSymtabback to summary
pack-priv void writeLocalSymtab(SymbolTable symtab) throws IOException
writeSymbolback to summary
pack-priv final void writeSymbol(int symbolId) throws IOException

Implements abstract com.amazon.ion.impl._Private_IonWriterBase.writeSymbol.

Doc from com.amazon.ion.impl._Private_IonWriterBase.writeSymbol.

Write symbolId out as an IonSymbol value. The value must be valid in the symbol table.

Parameters
symbolId:int

symbol table id to write

Annotations
@Override
writeSymbolback to summary
public final void writeSymbol(String value) throws IOException

Implements com.amazon.ion.IonWriter.writeSymbol.

Doc from com.amazon.ion.IonWriter.writeSymbol.

Writes the text of an Ion symbol value.

Parameters
value:String

may be null to represent null.symbol.

writeSymbolAsIsback to summary
pack-priv abstract void writeSymbolAsIs(int symbolId) throws IOException

Writes a symbol without checking for system ID.

writeSymbolAsIsback to summary
pack-priv abstract void writeSymbolAsIs(String value) throws IOException

Writes a symbol without checking for system ID.