Class _Private_IonBinaryWriterImpl
- All Implemented Interfaces:
Faceted,_Private_IonWriter,_Private_ListWriter,_Private_ReaderWriter,IonBinaryWriter,IonWriter,Closeable,Flushable,AutoCloseable
Adapts the binary IonWriter implementation to the deprecated
IonBinaryWriter interface.
-
Field Summary
Fields inherited from class com.amazon.ion.impl._Private_IonWriterBase
ERROR_MISSING_FIELD_NAME -
Method Summary
Modifier and TypeMethodDescriptionvoidaddTypeAnnotation(String annotation) Adds a given string to the list of pending annotations.intbyteSize()Deprecated.Gets the size in bytes of this binary data.voidclose()Closes this stream and releases any system resources associated with it.final voidfinish()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.voidflush()Flushes this writer by writing any buffered output to the underlying output target without finalizing the stream's local symbol table.byte[]getBytes()Deprecated.Copies the current contents of this writer as a new byte array holding Ion binary-encoded data.intgetBytes(byte[] bytes, int offset, int len) Deprecated.Copies the current contents of the writer to a given byte array array.Mostly for testing at this point, but could be useful public API.intgetDepth()Returns the current depth of containers the writer is at.final SymbolTableGets the symbol table that is currently in use by the writer.final booleanReturns true if the field name has been set either through setFieldName or setFieldId.booleanDetermines whether values are being written as fields of a struct.booleanIndicates whether the writer is stream copy optimized throughIonWriter.writeValue(com.amazon.ion.IonReader).final voidsetFieldName(String name) Sets the pending field name to the given text.final voidSets the pending field name to the given token.final voidsetSymbolTable(SymbolTable symbols) Sets the symbol table to use for encoding to be the passed in symbol table.voidsetTypeAnnotations(String... annotations) Sets the full list of pending annotations to the given text symbols.voidsetTypeAnnotationSymbols(SymbolToken... annotations) Sets the full list of pending annotations to the given symbols.voidWrites the beginning of a non-null container (list, sexp, or struct).voidstepOut()Writes the end of the current container, returning this writer to the context of parent container.voidwriteBlob(byte[] value, int start, int len) Writes a portion of the byte array out as an IonBlob value.voidwriteBool(boolean value) writes a non-null boolean value (true or false) as an IonBool to output.voidwriteBoolList(boolean[] values) intwriteBytes(OutputStream userstream) Deprecated.Writes the current contents of the writer to the output stream.voidwriteClob(byte[] value, int start, int len) Writes a portion of the byte array out as an IonClob value.voidwriteDecimal(BigDecimal value) Writes a BigDecimal value as an Ion decimal.voidwriteFloat(double value) writes a 64 bit binary floating point value, a Java double, as an IonFloat.voidwriteFloatList(double[] values) voidwriteFloatList(float[] values) voidwriteInt(int value) voidwriteInt(long value) writes a signed 64 bit value, a Java long, as an IonInt.voidwriteInt(BigInteger value) writes a BigInteger value as an IonInt.voidwriteIntList(byte[] values) voidwriteIntList(int[] values) voidwriteIntList(long[] values) voidwriteIntList(short[] values) final voidWrite an Ion version marker symbol to the output.voidWrites a null value of a specified Ion type.voidwriteString(String value) Writes aStringas an Ion string.voidwriteStringList(String[] values) final voidwriteSymbol(String value) Writes the text of an Ion symbol value.voidwriteTimestamp(Timestamp value) Writes a timestamp value.voidwriteValue(IonReader reader) Overrides can optimize special cases.Methods inherited from class com.amazon.ion.impl._Private_IonWriterBase
asFacet, pop_passed_symbol_table, writeBlob, writeClob, writeFloat, writeNull, writeSymbolToken, writeTimestampUTC, writeValue, writeValuesMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.amazon.ion.IonWriter
addTypeAnnotation, close, finish, flush, getSymbolTable, isInStruct, setFieldName, setFieldNameSymbol, setTypeAnnotations, setTypeAnnotationSymbols, stepIn, stepOut, writeBlob, writeBlob, writeBool, writeClob, writeClob, writeDecimal, writeFloat, writeInt, writeInt, writeNull, writeNull, writeString, writeSymbol, writeSymbolToken, writeTimestamp, writeTimestampUTC, writeValue, writeValue, writeValues
-
Method Details
-
byteSize
public int byteSize()Deprecated.Description copied from interface:IonBinaryWriterGets the size in bytes of this binary data. This is generally needed before callingIonBinaryWriter.getBytes()orIonBinaryWriter.getBytes(byte[], int, int).- Specified by:
byteSizein interfaceIonBinaryWriter- Returns:
- the size in bytes.
-
getBytes
Deprecated.Description copied from interface:IonBinaryWriterCopies the current contents of this writer as a new byte array holding Ion binary-encoded data. This allocates an array of the size needed to exactly hold the output and copies the entire value to it.- Specified by:
getBytesin interfaceIonBinaryWriter- Returns:
- the byte array with the writers output
- Throws:
IOException
-
getBytes
Deprecated.Description copied from interface:IonBinaryWriterCopies the current contents of the writer to a given byte array array. This starts writing to the array at offset and writes up to maxlen bytes. If this writer is not able to stop in the middle of its work this may overwrite the array and later throw and exception.- Specified by:
getBytesin interfaceIonBinaryWriter- Parameters:
bytes- users byte array to write intooffset- initial offset in the array to write intolen- maximum number of bytes to write- Returns:
- number of bytes written
- Throws:
IOException
-
writeBytes
Deprecated.Description copied from interface:IonBinaryWriterWrites the current contents of the writer to the output stream. This is only valid if the writer is not in the middle of writing a container.- Specified by:
writeBytesin interfaceIonBinaryWriter- Parameters:
userstream- OutputStream to write the bytes to- Returns:
- int length of bytes written
- Throws:
IOException
-
isStreamCopyOptimized
public boolean isStreamCopyOptimized()Description copied from interface:_Private_IonWriterIndicates whether the writer is stream copy optimized throughIonWriter.writeValue(com.amazon.ion.IonReader).- Specified by:
isStreamCopyOptimizedin interface_Private_IonWriter- Overrides:
isStreamCopyOptimizedin class_Private_IonWriterBase
-
writeValue
Description copied from class:_Private_IonWriterBaseOverrides can optimize special cases.- Specified by:
writeValuein interfaceIonWriter- Overrides:
writeValuein class_Private_IonWriterBase- Throws:
IOException
-
writeBoolList
- Specified by:
writeBoolListin interface_Private_ListWriter- Throws:
IOException
-
writeFloatList
- Specified by:
writeFloatListin interface_Private_ListWriter- Throws:
IOException
-
writeFloatList
- Specified by:
writeFloatListin interface_Private_ListWriter- Throws:
IOException
-
writeIntList
- Specified by:
writeIntListin interface_Private_ListWriter- Throws:
IOException
-
writeIntList
- Specified by:
writeIntListin interface_Private_ListWriter- Throws:
IOException
-
writeIntList
- Specified by:
writeIntListin interface_Private_ListWriter- Throws:
IOException
-
writeIntList
- Specified by:
writeIntListin interface_Private_ListWriter- Throws:
IOException
-
writeStringList
- Specified by:
writeStringListin interface_Private_ListWriter- Throws:
IOException
-
getCatalog
Description copied from interface:_Private_IonWriterMostly for testing at this point, but could be useful public API.- Specified by:
getCatalogin interface_Private_IonWriter
-
getDepth
public int getDepth()Description copied from class:_Private_IonWriterBaseReturns the current depth of containers the writer is at. This is 0 if the writer is at top-level.- Specified by:
getDepthin interface_Private_IonWriter- Specified by:
getDepthin class_Private_IonWriterBase- Returns:
- int depth of container nesting
-
isInStruct
public boolean isInStruct()Description copied from interface:IonWriterDetermines 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.- Specified by:
isInStructin interfaceIonWriter- Returns:
- true when the parent is a struct.
-
flush
Description copied from interface:IonWriterFlushes 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
IonBinaryWriterBuilder.withLocalSymbolTableAppendEnabled()), this feature can be used to flush buffered data before writing more values without subsequently having to redeclare the current local symbol table. Applications that produce long streams of binary Ion may wish to flush occasionally to relieve memory pressure, then continue writing data using the same local symbol table. The symbol table will be appended with newly-encountered symbols as necessary.- Specified by:
flushin interfaceFlushable- Specified by:
flushin interfaceIonWriter- Throws:
IOException- if thrown by the underlying output target.- See Also:
-
close
Description copied from interface:IonWriterCloses 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
IonWriter.finish()before closing the underlying output stream. If not, the resulting data may be incomplete and invalid Ion.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.
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceIonWriter- Throws:
IOException- if thrown by the underlying output target.- See Also:
-
finish
Description copied from interface:IonWriterIndicates 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
IonBinaryWriterBuilder.withLocalSymbolTableAppendEnabled()) andIonWriter.flush()instead to avoid re-declaring the local symbol table unnecessarily.- Specified by:
finishin interfaceIonWriter- Throws:
IOException- if thrown by the underlying output target.- See Also:
-
setSymbolTable
Description copied from class:_Private_IonWriterBaseSets 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.
- Specified by:
setSymbolTablein class_Private_IonWriterBase- Parameters:
symbols- base symbol table for encoding. Must not be null.- Throws:
IOException
-
getSymbolTable
Description copied from interface:IonWriterGets 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...)orIonSystem.newTextWriter(java.io.OutputStream, SymbolTable...)to provide custom symbol table(s) to writers upon construction.- Specified by:
getSymbolTablein interfaceIonWriter- Returns:
- current symbol table
-
setFieldName
Description copied from interface:IonWriterSets 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 thewrite*()methods.- Specified by:
setFieldNamein interfaceIonWriter- Parameters:
name- text of the field name
-
setFieldNameSymbol
Description copied from interface:IonWriterSets 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 thewrite*()methods.- Specified by:
setFieldNameSymbolin interfaceIonWriter- Parameters:
name- text of the field name
-
isFieldNameSet
public final boolean isFieldNameSet()Description copied from class:_Private_IonWriterBaseReturns 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.- Specified by:
isFieldNameSetin interface_Private_IonWriter- Specified by:
isFieldNameSetin class_Private_IonWriterBase- Returns:
- true if a field name has been set false otherwise
-
addTypeAnnotation
Description copied from interface:IonWriterAdds 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 thewrite*()methods.- Specified by:
addTypeAnnotationin interfaceIonWriter- Parameters:
annotation- string annotation to append to the annotation list
-
setTypeAnnotations
Description copied from interface:IonWriterSets the full list of pending annotations to the given text symbols. Any pending annotations are cleared. The contents of theannotationsarray 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 thewrite*()methods.- Specified by:
setTypeAnnotationsin interfaceIonWriter- Parameters:
annotations- string array with the annotations. If null or empty, any pending annotations are cleared.
-
setTypeAnnotationSymbols
Description copied from interface:IonWriterSets the full list of pending annotations to the given symbols. Any pending annotations are cleared. The contents of theannotationsarray 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 thewrite*()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.
- Specified by:
setTypeAnnotationSymbolsin interfaceIonWriter- Parameters:
annotations- If null or empty, any pending annotations are cleared.
-
stepIn
Description copied from interface:IonWriterWrites the beginning of a non-null container (list, sexp, or struct). This must be matched by a call toIonWriter.stepOut()after the last child value.This method is not used to write
null.listet al. To write null values useIonWriter.writeNull(IonType).- Specified by:
stepInin interfaceIonWriter- Parameters:
containerType- must be one ofIonType.LIST,IonType.SEXP, orIonType.STRUCT.- Throws:
IOException
-
stepOut
Description copied from interface:IonWriterWrites the end of the current container, returning this writer to the context of parent container. Invocation of this method must match a preceding call toIonWriter.stepIn(IonType).- Specified by:
stepOutin interfaceIonWriter- Throws:
IOException
-
writeBlob
Description copied from interface:IonWriterWrites a portion of the byte array out as an IonBlob value. This copies the portion of the byte array that is written.- Specified by:
writeBlobin interfaceIonWriter- Parameters:
value- bytes to be written. May benullto representnull.blob.start- offset of the first byte in value to writelen- number of bytes to write from value- Throws:
IOException
-
writeBool
Description copied from interface:IonWriterwrites a non-null boolean value (true or false) as an IonBool to output.- Specified by:
writeBoolin interfaceIonWriter- Parameters:
value- true or false as desired- Throws:
IOException
-
writeClob
Description copied from interface:IonWriterWrites a portion of the byte array out as an IonClob value. This copies the porition of the byte array that is written.- Specified by:
writeClobin interfaceIonWriter- Parameters:
value- bytes to be written. May benullto representnull.clob.start- offset of the first byte in value to writelen- number of bytes to write from value- Throws:
IOException
-
writeDecimal
Description copied from interface:IonWriterWrites 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
Decimalinstance.- Specified by:
writeDecimalin interfaceIonWriter- Specified by:
writeDecimalin class_Private_IonWriterBase- Parameters:
value- may be null to representnull.decimal.- Throws:
IOException
-
writeFloat
Description copied from interface:IonWriterwrites 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.- Specified by:
writeFloatin interfaceIonWriter- Parameters:
value- double to write- Throws:
IOException
-
writeInt
- Throws:
IOException
-
writeInt
Description copied from interface:IonWriterwrites a signed 64 bit value, a Java long, as an IonInt.- Specified by:
writeIntin interfaceIonWriter- Parameters:
value- signed int to write- Throws:
IOException
-
writeInt
Description copied from interface:IonWriterwrites a BigInteger value as an IonInt. If the BigInteger value is null this writes a null int.- Specified by:
writeIntin interfaceIonWriter- Parameters:
value- BigInteger to write- Throws:
IOException
-
writeNull
Description copied from interface:IonWriterWrites a null value of a specified Ion type.- Specified by:
writeNullin interfaceIonWriter- Parameters:
type- type of the null to be written- Throws:
IOException
-
writeString
Description copied from interface:IonWriterWrites aStringas an Ion string. Since Ion strings are UTF-8 and Java Strings are Unicode 16. As such the resulting lengths may not match. In addition some Java strings are not valid as they may contain only one of the two needed surrogate code units necessary to define the Unicode code point to be output, an exception will be raised if this case is encountered.- Specified by:
writeStringin interfaceIonWriter- Parameters:
value- may be null to representnull.string.- Throws:
IOException
-
writeSymbol
Description copied from interface:IonWriterWrites the text of an Ion symbol value.- Specified by:
writeSymbolin interfaceIonWriter- Parameters:
value- may be null to representnull.symbol.- Throws:
IOException
-
writeIonVersionMarker
Description copied from interface:_Private_IonWriterWrite 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.- Specified by:
writeIonVersionMarkerin interface_Private_IonWriter- Throws:
IOException
-
writeTimestamp
Description copied from interface:IonWriterWrites a timestamp value.- Specified by:
writeTimestampin interfaceIonWriter- Parameters:
value- may be null to representnull.timestamp.- Throws:
IOException
-