Class IonReaderBuilder
- java.lang.Object
-
- com.amazon.ion.system.IonReaderBuilder
-
- Direct Known Subclasses:
_Private_IonReaderBuilder
public abstract class IonReaderBuilder extends java.lang.ObjectBuild a newIonReaderfrom the givenIonCatalogand data source. A data source is required, while an IonCatalog is optional. If no IonCatalog is provided, an emptySimpleCatalogwill be used.IonReaders parse incrementally, so syntax errors in the input data will not be detected as side effects of any of thebuildmethods in this class.
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedIonReaderBuilder()protectedIonReaderBuilder(IonReaderBuilder that)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description IonReaderbuild(byte[] ionData)Based on the builder's configuration properties, creates a new IonReader instance over the given block of Ion data, detecting whether it's text or binary data.abstract IonReaderbuild(byte[] ionData, int offset, int length)Based on the builder's configuration properties, creates a new IonReader instance over the given block of Ion data, detecting whether it's text or binary data.abstract IonReaderbuild(IonValue value)abstract IonReaderbuild(java.io.InputStream ionData)Based on the builder's configuration properties, creates a new IonReader instance over the given stream of Ion data, detecting whether it's text or binary data.abstract IonReaderbuild(java.io.Reader ionText)Based on the builder's configuration properties, creates a newIonReaderinstance over Ion text data.abstract IonTextReaderbuild(java.lang.String ionText)Based on the builder's configuration properties, creates an newIonReaderinstance over Ion text data.IonReaderBuildercopy()Creates a mutable copy of this builder.IonBufferConfigurationgetBufferConfiguration()IonCataloggetCatalog()Gets the catalog to use when building anIonReader, or null if none has been manually set.IonReaderBuilderimmutable()Returns an immutable builder configured exactly like this one.booleanisAnnotationIteratorReuseEnabled()booleanisIncrementalReadingEnabled()IonReaderBuildermutable()Returns a mutable builder configured exactly like this one.protected voidmutationCheck()NOT FOR APPLICATION USE!voidsetAnnotationIteratorReuseDisabled()voidsetAnnotationIteratorReuseEnabled()voidsetBufferConfiguration(IonBufferConfiguration configuration)voidsetCatalog(IonCatalog catalog)Sets the catalog to use when building anIonReader.voidsetIncrementalReadingDisabled()voidsetIncrementalReadingEnabled()static IonReaderBuilderstandard()The standard builder ofIonReaders, with all configuration properties having their default values.protected IonCatalogvalidateCatalog()IonReaderBuilderwithAnnotationIteratorReuseEnabled(boolean isEnabled)Determines whether readers will reuse the annotation iterator returned byIonReader.iterateTypeAnnotations().IonReaderBuilderwithBufferConfiguration(IonBufferConfiguration configuration)Sets the buffer configuration.IonReaderBuilderwithCatalog(IonCatalog catalog)Declares the catalog to use when building anIonReader, returning a new mutable builder the current one is immutable.IonReaderBuilderwithIncrementalReadingEnabled(boolean isEnabled)Determines whether the IonReader will allow incremental reading of binary Ion data.
-
-
-
Constructor Detail
-
IonReaderBuilder
protected IonReaderBuilder()
-
IonReaderBuilder
protected IonReaderBuilder(IonReaderBuilder that)
-
-
Method Detail
-
standard
public static IonReaderBuilder standard()
The standard builder ofIonReaders, with all configuration properties having their default values.- Returns:
- a new, mutable builder instance.
-
copy
public IonReaderBuilder copy()
Creates a mutable copy of this builder.- Returns:
- a new builder with the same configuration as
this.
-
immutable
public IonReaderBuilder immutable()
Returns an immutable builder configured exactly like this one.- Returns:
- this builder instance, if immutable; otherwise an immutable copy of this builder.
-
mutable
public IonReaderBuilder mutable()
Returns a mutable builder configured exactly like this one.- Returns:
- this instance, if mutable; otherwise a mutable copy of this instance.
-
mutationCheck
protected void mutationCheck()
NOT FOR APPLICATION USE!
-
withCatalog
public IonReaderBuilder withCatalog(IonCatalog catalog)
Declares the catalog to use when building anIonReader, returning a new mutable builder the current one is immutable.- Parameters:
catalog- the catalog to use in built readers. If null, a newSimpleCatalogwill be used.- Returns:
- this builder instance, if mutable; otherwise a mutable copy of this builder.
- See Also:
setCatalog(IonCatalog),withCatalog(IonCatalog)
-
setCatalog
public void setCatalog(IonCatalog catalog)
Sets the catalog to use when building anIonReader.- Parameters:
catalog- the catalog to use in built readers. If null, a newSimpleCatalogwill be used.- Throws:
java.lang.UnsupportedOperationException- if this builder is immutable.- See Also:
getCatalog(),withCatalog(IonCatalog)
-
getCatalog
public IonCatalog getCatalog()
Gets the catalog to use when building anIonReader, or null if none has been manually set. The catalog is needed to resolve shared symbol table imports.- See Also:
setCatalog(IonCatalog),withCatalog(IonCatalog)
-
validateCatalog
protected IonCatalog validateCatalog()
-
withIncrementalReadingEnabled
public IonReaderBuilder withIncrementalReadingEnabled(boolean isEnabled)
Determines whether the IonReader will allow incremental reading of binary Ion data. When enabled, if
IonReader.next()returnsnullat the top-level, it indicates that there is not enough data in the stream to complete a top-level value. The user may wait for more data to become available in the stream and callIonReader.next()again to continue reading. Unlike the non-incremental reader, the incremental reader will never throw an exception due to unexpected EOF duringnext(). If, however,Closeable.close()is called when an incomplete value is buffered, anIonExceptionwill be raised.There is currently no incremental text IonReader, so for text data a non-incremental IonReader will be returned regardless of the value of this option. If incremental text reading is supported in the future, it may be enabled via this option.
When this option is enabled, auto-detection of GZIP data is not supported; the byte array or InputStream implementation provided to
build(byte[])orbuild(InputStream)must return uncompressed bytes. This can be achieved by wrapping the data in a GZIPInputStream and passing it tobuild(InputStream).Additionally, when this option is enabled, annotation iterators are reused by default, improving performance. See
withAnnotationIteratorReuseEnabled(boolean)for more information and to disable that option.Although the incremental binary IonReader provides performance superior to the non-incremental binary IonReader for both incremental and non-incremental use cases, there is one caveat: the incremental implementation must be able to buffer an entire top-level value and any preceding system values (Ion version marker(s) and symbol table(s)) in memory. This will not be a problem for the vast majority of Ion streams, as it is rare for a single top-level value or symbol table to exceed a few megabytes in size. However, if the size of the stream's values risk exceeding the available memory, then this option must not be enabled.
- Parameters:
isEnabled- true if the option is enabled; otherwise, false.- Returns:
- this builder instance, if mutable; otherwise a mutable copy of this builder.
- See Also:
setIncrementalReadingEnabled(),setIncrementalReadingDisabled()
-
setIncrementalReadingEnabled
public void setIncrementalReadingEnabled()
- See Also:
withIncrementalReadingEnabled(boolean)
-
setIncrementalReadingDisabled
public void setIncrementalReadingDisabled()
- See Also:
withIncrementalReadingEnabled(boolean)
-
isIncrementalReadingEnabled
public boolean isIncrementalReadingEnabled()
- Returns:
- true if incremental reading is enabled; otherwise, false.
- See Also:
withIncrementalReadingEnabled(boolean)
-
withBufferConfiguration
public IonReaderBuilder withBufferConfiguration(IonBufferConfiguration configuration)
Sets the buffer configuration. This can be used, for example, to set a maximum buffer size and receive notifications when values would exceed this size. Currently, this is ignored unless incremental reading has been enabled viawithIncrementalReadingEnabled(boolean)) orsetIncrementalReadingEnabled(). This configuration is optional. If not provided, the buffer size will be limited only by the available memory.- Parameters:
configuration- the configuration.- Returns:
- this builder instance, if mutable; otherwise a mutable copy of this builder.
- See Also:
setBufferConfiguration(IonBufferConfiguration)
-
setBufferConfiguration
public void setBufferConfiguration(IonBufferConfiguration configuration)
-
getBufferConfiguration
public IonBufferConfiguration getBufferConfiguration()
- Returns:
- the current configuration.
- See Also:
withBufferConfiguration(IonBufferConfiguration)
-
withAnnotationIteratorReuseEnabled
public IonReaderBuilder withAnnotationIteratorReuseEnabled(boolean isEnabled)
Determines whether readers will reuse the annotation iterator returned by
IonReader.iterateTypeAnnotations(). When enabled, the returned iterator remains valid only while the reader remains positioned at the current value; storing the iterator and iterating its values after that will cause undefined behavior. This provides improved performance and memory efficiency when frequently iterating annotations. When disabled, the returned iterator may be stored and used to retrieve the annotations that were on the value at the reader's position at the time of the call, regardless of where the reader is currently positioned.Currently, this option only has an effect when incremental reading is enabled (see
withIncrementalReadingEnabled(boolean)). In that case, it is enabled by default. Non-incremental readers always act as if this option were disabled.- Parameters:
isEnabled- true if the option is enabled; otherwise, false.- Returns:
- this builder instance, if mutable; otherwise a mutable copy of this builder.
- See Also:
setAnnotationIteratorReuseEnabled(),setAnnotationIteratorReuseDisabled()
-
setAnnotationIteratorReuseEnabled
public void setAnnotationIteratorReuseEnabled()
-
setAnnotationIteratorReuseDisabled
public void setAnnotationIteratorReuseDisabled()
-
isAnnotationIteratorReuseEnabled
public boolean isAnnotationIteratorReuseEnabled()
- Returns:
- true if annotation iterator reuse is enabled; otherwise, false.
- See Also:
withAnnotationIteratorReuseEnabled(boolean)
-
build
public IonReader build(byte[] ionData)
Based on the builder's configuration properties, creates a new IonReader instance over the given block of Ion data, detecting whether it's text or binary data.This method will auto-detect and uncompress GZIPped Ion data.
- Parameters:
ionData- the source of the Ion data, which may be either Ion binary data or UTF-8 Ion text. The reader retains a reference to the array, so its data must not be modified while the reader is active. Must not be null.- Returns:
- a new
IonReaderinstance; notnull. - See Also:
IonSystem.newReader(byte[])
-
build
public abstract IonReader build(byte[] ionData, int offset, int length)
Based on the builder's configuration properties, creates a new IonReader instance over the given block of Ion data, detecting whether it's text or binary data.This method will auto-detect and uncompress GZIPped Ion data.
- Parameters:
ionData- the source of the Ion data, which is used only within the range of bytes starting atoffsetforlenbytes. The data in that range may be either Ion binary data or UTF-8 Ion text. The reader retains a reference to the array, so its data must not be modified while the reader is active. Must not be null.offset- must be non-negative and less thanionData.length.length- must be non-negative andoffset+lengthmust not exceedionData.length.- See Also:
IonSystem.newReader(byte[], int, int)
-
build
public abstract IonReader build(java.io.InputStream ionData)
Based on the builder's configuration properties, creates a new IonReader instance over the given stream of Ion data, detecting whether it's text or binary data.This method will auto-detect and uncompress GZIPped Ion data.
Because this library performs its own buffering, it's recommended that users avoid adding additional buffering to the given stream.
- Parameters:
ionData- the source of the Ion data, which may be either Ion binary data or UTF-8 Ion text. Must not be null.- Returns:
- a new reader instance.
Callers must call
Closeable.close()when finished with it. - Throws:
IonException- if the source throwsIOException.- See Also:
IonSystem.newReader(InputStream)
-
build
public abstract IonReader build(java.io.Reader ionText)
Based on the builder's configuration properties, creates a newIonReaderinstance over Ion text data.Applications should generally use
build(InputStream)whenever possible, since this library has much faster Unicode decoding than the Java IO framework.Because this library performs its own buffering, it's recommended that you avoid adding additional buffering to the given stream.
- Parameters:
ionText- the source of the Ion text data. Must not be null.- Throws:
IonException- if the source throwsIOException.- See Also:
IonSystem.newReader(Reader)
-
build
public abstract IonReader build(IonValue value)
Based on the builder's configuration properties, creates a newIonReaderinstance over anIonValuedata model. Typically this is used to iterate over a collection, such as anIonStruct. The given value and its children, if any, must not be modified until after the IonReader constructed by this method is closed. Violating this constraint results in undefined behavior.- Parameters:
value- must not be null.- See Also:
IonSystem.newReader(IonValue)
-
build
public abstract IonTextReader build(java.lang.String ionText)
Based on the builder's configuration properties, creates an newIonReaderinstance over Ion text data.- Parameters:
ionText- the source of the Ion text data. Must not be null.- See Also:
IonSystem.newReader(String)
-
-