Warning
This interface should not be implemented or extended by code outside of this library.
A value is written via the set of typed write*() methods such as
writeBool(boolean) and writeInt(long).
Each of these methods outputs a single Ion value, and afterwards the writer
is prepared to receive the data for the next sibling value.
Any type annotations must be set before the value is written. Once the value has been written the "pending annotations" are erased, so they are must be set again if they need to be applied to the next value.
Similarly the field name must be set before the value is written (assuming the value is a field in a structure). The field name is also "erased" once used, so it must be set for each field.
To write a container, first write any annotations and/or field name
applicable to the container itself.
Then call stepIn(IonType) with the desired container type.
Then write each child value in order.
Finally, call stepOut() to complete the container.
Once all the top-level values have been written (and stepped-out back to
the starting level), the caller must close() the writer
(or at least flush() or finish() it) before accessing
the data written to the underlying data sink
(for example, via ByteArrayOutputStream#toByteArray()).
The writer may have internal buffers and without closing, flushing, or
finishing it, it may not have written everything to the underlying data
sink.
IonWriter is a generic interface for generating Ion data, and it's
not possible to fully specify the set of exceptions that could be thrown
from the underlying data sink. Thus all failures are thrown as instances
of IonException, wrapping the originating cause. If an application
wants to handle (say) IOExceptions specially, then it needs to
extract that from the wrappers; the documentation of IonException
explains how to do that.
IonStreamUtils, IonTextWriterBuilder
| Modifier and Type | Method and Description |
|---|---|
| public void | addTypeAnnotation(String
string annotation to append to the annotation list annotation)Adds a given string to the list of pending annotations. |
| public void | close()
Redeclares java. Closes this stream and releases any system resources associated with it. |
| public void | 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. |
| public void | flush()
Redeclares java. Flushes this writer by writing any buffered output to the underlying output target without finalizing the stream's local symbol table. |
| public SymbolTable | Returns: current symbol tableGets the symbol table that is currently in use by the writer. |
| public boolean | Returns: true when the parent is a struct.Determines whether values are being written as fields of a struct. |
| public void | |
| public void | setFieldNameSymbol(SymbolToken
text of the field name name)Sets the pending field name to the given token. |
| public void | setTypeAnnotations(String...
string array with the annotations.
If null or empty, any pending annotations are cleared. annotations)Sets the full list of pending annotations to the given text symbols. |
| public void | setTypeAnnotationSymbols(SymbolToken...
If null or empty, any pending annotations are cleared. annotations)Sets the full list of pending annotations to the given symbols. |
| public void | |
| public void | stepOut()
Writes the end of the current container, returning this writer to the context of parent container. |
| public void | writeBlob(byte[]
may be null to represent value)null.blob.write the byte array out as an IonBlob value. |
| public void | writeBlob(byte[]
bytes to be written.
May be value, int null to represent null.blob.offset of the first byte in value to write start, int number of bytes to write from value len)Writes a portion of the byte array out as an IonBlob value. |
| public void | writeBool(boolean
true or false as desired value)writes a non-null boolean value (true or false) as an IonBool to output. |
| public void | writeClob(byte[]
may be null to represent value)null.clob.write the byte array out as an IonClob value. |
| public void | writeClob(byte[]
bytes to be written.
May be value, int null to represent null.clob.offset of the first byte in value to write start, int number of bytes to write from value len)Writes a portion of the byte array out as an IonClob value. |
| public void | writeDecimal(BigDecimal
may be null to represent value)null.decimal.Writes a BigDecimal value as an Ion decimal. |
| public void | writeFloat(double
double to write value)writes a 64 bit binary floating point value, a Java double, as an IonFloat. |
| public void | |
| public void | |
| public void | |
| public void | |
| public void | writeString(String
may be null to represent value)null.string.Writes a |
| public void | writeSymbol(String
may be null to represent content)null.symbol.Writes the text of an Ion symbol value. |
| public void | writeSymbolToken(SymbolToken
may be null to represent content)null.symbol.Writes the content of an Ion symbol value. |
| public void | |
| public void | writeTimestampUTC(Date
java.util Date holding the UTC timestamp;
may be null to represent value)null.timestamp.
Deprecated
Use
IonWriter.Timestamp. instead.
writes the passed in Date (in milliseconds since the epoch) as an IonTimestamp. |
| public void | writeValue(IonValue
may be null, in which case this method does nothing. value)
Deprecated
Use
IonValue#writeTo(IonWriter) instead.
writes the contents of the passed in Ion value to the output. |
| public void | |
| public void | writeValues(IonReader reader)
Writes a reader's current value, and all following values until the end of the current container. |
| addTypeAnnotation | back to summary |
|---|---|
| public void addTypeAnnotation(String annotation) Adds a given string to the list of pending annotations.
The list of pending annotations is cleared when the current value is
written via
| |
| close | back to summary |
|---|---|
| public void close() throws IOException Redeclares java. Closes this stream and releases any system resources associated with it. If the stream is already closed then invoking this method has no effect.
If the cursor is between top-level values, this method will
In other words: unless you're recovering from a failure condition, don't close the writer until you've stepped-out back to the starting level.
| |
| finish | back to summary |
|---|---|
| public void finish() throws IOException 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
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
| |
| flush | back to summary |
|---|---|
| public void flush() throws IOException Redeclares java. Flushes this writer by writing any buffered output to the underlying output target without finalizing the stream's local symbol table. For some implementations this may have no effect even when some data is buffered, because it's not always possible to fully write partial data. In particular, when writing binary Ion data, Ion's length-prefixed encoding requires a complete top-level value to be written at once.
If localSymbolTableAppend is enabled (see
| |
| getSymbolTable | back to summary |
|---|---|
| public SymbolTable 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
| |
| isInStruct | back to summary |
|---|---|
| public boolean isInStruct() Determines whether values are being written as fields of a struct. This is especially useful when it is not clear whether field names need to be written or not.
| |
| setFieldName | back to summary |
|---|---|
| public void setFieldName(String name) Sets the pending field name to the given text.
The pending field name is cleared when the current value is
written via
| |
| setFieldNameSymbol | back to summary |
|---|---|
| public void setFieldNameSymbol(SymbolToken name) Sets the pending field name to the given token.
The pending field name is cleared when the current value is
written via
| |
| setTypeAnnotations | back to summary |
|---|---|
| public void setTypeAnnotations(String... annotations) Sets the full list of pending annotations to the given text symbols.
Any pending annotations are cleared.
The contents of the
The list of pending annotations is cleared when the current value is
written via
| |
| setTypeAnnotationSymbols | back to summary |
|---|---|
| public void setTypeAnnotationSymbols(SymbolToken... annotations) Sets the full list of pending annotations to the given symbols.
Any pending annotations are cleared.
The contents of the
The list of pending annotations is cleared when the current value is
written via This is an "expert method": correct use requires deep understanding of the Ion binary format. You almost certainly don't want to use it.
| |
| stepIn | back to summary |
|---|---|
| public void stepIn(IonType containerType) throws IOException Writes the beginning of a non-null container (list, sexp, or struct).
This must be matched by a call to
This method is not used to write
| |
| stepOut | back to summary |
|---|---|
| public void stepOut() throws IOException Writes the end of the current container, returning this writer to the
context of parent container.
Invocation of this method must match a preceding call to
| |
| writeBlob | back to summary |
|---|---|
| public void writeBlob(byte[] value) throws IOException write the byte array out as an IonBlob value. This copies the byte array.
| |
| writeBlob | back to summary |
|---|---|
| public void writeBlob(byte[] value, int start, int len) throws IOException Writes a portion of the byte array out as an IonBlob value. This copies the portion of the byte array that is written.
| |
| writeBool | back to summary |
|---|---|
| public void writeBool(boolean value) throws IOException writes a non-null boolean value (true or false) as an IonBool to output.
| |
| writeClob | back to summary |
|---|---|
| public void writeClob(byte[] value) throws IOException write the byte array out as an IonClob value. This copies the byte array.
| |
| writeClob | back to summary |
|---|---|
| public void writeClob(byte[] value, int start, int len) throws IOException Writes a portion of the byte array out as an IonClob value. This copies the porition of the byte array that is written.
| |
| writeDecimal | back to summary |
|---|---|
| public void writeDecimal(BigDecimal value) throws IOException Writes a BigDecimal value as an Ion decimal. Ion uses an arbitrarily long sign/value and an arbitrarily long signed exponent to write the value. This preserves all of the BigDecimal digits, the number of significant digits.
To write a negative zero value, pass this method a
| |
| writeFloat | back to summary |
|---|---|
| public void writeFloat(double value) throws IOException writes a 64 bit binary floating point value, a Java double, as an IonFloat. Currently IonFloat values are output as 64 bit IEEE 754 big endian values. IonFloat preserves all valid floating point values, including -0.0, Nan and +/-infinity. It does not guarantee preservation of -Nan or other less less "common" values.
| |
| writeInt | back to summary |
|---|---|
| public void writeInt(long value) throws IOException writes a signed 64 bit value, a Java long, as an IonInt.
| |
| writeInt | back to summary |
|---|---|
| public void writeInt(BigInteger value) throws IOException writes a BigInteger value as an IonInt. If the BigInteger value is null this writes a null int.
| |
| writeNull | back to summary |
|---|---|
| public void writeNull() throws IOException Writes a value of Ion's null type ( | |
| writeNull | back to summary |
|---|---|
| public void writeNull(IonType type) throws IOException Writes a null value of a specified Ion type.
| |
| writeString | back to summary |
|---|---|
| public void writeString(String value) throws IOException Writes a
| |
| writeSymbol | back to summary |
|---|---|
| public void writeSymbol(String content) throws IOException Writes the text of an Ion symbol value.
| |
| writeSymbolToken | back to summary |
|---|---|
| public void writeSymbolToken(SymbolToken content) throws IOException Writes the content of an Ion symbol value.
| |
| writeTimestamp | back to summary |
|---|---|
| public void writeTimestamp(Timestamp value) throws IOException Writes a timestamp value.
| |
| writeTimestampUTC | back to summary |
|---|---|
| public void writeTimestampUTC(Date value) throws IOException
Deprecated Use writes the passed in Date (in milliseconds since the epoch) as an IonTimestamp. The Date value is treated as a UTC value with an unknown timezone offset (a z value).
| |
| writeValue | back to summary |
|---|---|
| public void writeValue(IonValue value) throws IOException
Deprecated Use writes the contents of the passed in Ion value to the output. This method also writes annotations and field names (if in a struct), and performs a deep write, including the contents of any containers encountered.
| |
| writeValue | back to summary |
|---|---|
| public void writeValue(IonReader reader) throws IOException Writes the current value from a reader. This method also writes annotations and field names (if in a struct), and performs a deep write, including the contents of any containers encountered. | |
| writeValues | back to summary |
|---|---|
| public void writeValues(IonReader reader) throws IOException Writes a reader's current value, and all following values until the end
of the current container. If there's no current value then this method
calls
This method iterates until This method also writes annotations and field names (if in a struct), and performs a deep write, including the contents of any containers encountered. | |