Class IonTextWriterBuilder
- java.lang.Object
-
- com.amazon.ion.system.IonWriterBuilder
-
- com.amazon.ion.system.IonTextWriterBuilder
-
- Direct Known Subclasses:
_Private_IonTextWriterBuilder
public abstract class IonTextWriterBuilder extends IonWriterBuilder
The builder for creatingIonWriter
s emitting the Ion text syntax.WARNING: This class should not be extended by code outside of this library.
Builders may be configured once and reused to construct multiple objects.
Instances of this class are not not safe for use by multiple threads unless they are immutable.
The most general and correct approach is to use the
standard()
builder:IonWriter w = IonTextWriterBuilder.standard().build(outputStream);
The standard configuration gives a direct representation of what's written, including version markers and local symbol tables. That's good for diagnostics but it may be more than you want in many situations. In such cases theminimal()
orpretty()
builders (or a combination) may give more satisfying output:IonWriter w = IonTextWriterBuilder.minimal() .withPrettyPrinting() .build(outputStream);
Configuration properties follow the standard JavaBeans idiom in order to be friendly to dependency injection systems. They also provide alternative
with...()
mutation methods that enable a more fluid style.Auto-flushing
IonWriter
s created by this builder auto-flush to the underlying data sink after writing each top-level value in the context of the writer.Currently, there is no configuration point available to disable the auto-flushing mechanism. Please vote on issue amazon-ion/ion-java/issues/32 if you require it.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
IonTextWriterBuilder.LstMinimizing
A strategy for minimizing the output of local symbol tables.static class
IonTextWriterBuilder.NewLineType
Represents common new-line separators that are valid in Ion.-
Nested classes/interfaces inherited from class com.amazon.ion.system.IonWriterBuilder
IonWriterBuilder.InitialIvmHandling, IonWriterBuilder.IvmMinimizing
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
IonTextWriterBuilder()
NOT FOR APPLICATION USE!protected
IonTextWriterBuilder(IonTextWriterBuilder that)
NOT FOR APPLICATION USE!
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract IonWriter
build(java.lang.Appendable out)
Creates a new writer that will write text to the given output stream.abstract IonTextWriterBuilder
copy()
IonCatalog
getCatalog()
Gets the catalog to use when building anIonWriter
.java.nio.charset.Charset
getCharset()
Gets the charset denoting the output encoding.SymbolTable[]
getImports()
Gets the imports that will be used to construct the initial local symbol table.IonWriterBuilder.InitialIvmHandling
getInitialIvmHandling()
Gets the strategy for emitting Ion version markers at the start of the stream.IonWriterBuilder.IvmMinimizing
getIvmMinimizing()
Gets the strategy for eliminating Ion version markers mid-stream.int
getLongStringThreshold()
Gets the length beyond which string and clob content will be rendered as triple-quoted "long strings".IonTextWriterBuilder.LstMinimizing
getLstMinimizing()
Gets the strategy for reducing or eliminating local symbol tables.IonTextWriterBuilder.NewLineType
getNewLineType()
Gets the character sequence that will be written as a line separator.boolean
getWriteTopLevelValuesOnNewLines()
Gets whether each top level value for standard printing should start on a new line.abstract IonTextWriterBuilder
immutable()
static IonTextWriterBuilder
json()
Creates a builder preconfigured for JSON compatibility.static IonTextWriterBuilder
minimal()
Creates a builder configured to minimize system data, eliminating local symbol tables and minimizing version markers.abstract IonTextWriterBuilder
mutable()
protected void
mutationCheck()
NOT FOR APPLICATION USE!static IonTextWriterBuilder
pretty()
Creates a builder preconfigured for basic pretty-printing.void
setCatalog(IonCatalog catalog)
Sets the catalog to use when building anIonWriter
.void
setCharset(java.nio.charset.Charset charset)
Sets the charset denoting the output encoding.void
setImports(SymbolTable... imports)
Sets the shared symbol tables that will be used to construct the initial local symbol table.void
setInitialIvmHandling(IonWriterBuilder.InitialIvmHandling handling)
Sets the strategy for emitting Ion version markers at the start of the stream.void
setIvmMinimizing(IonWriterBuilder.IvmMinimizing minimizing)
Sets the strategy for reducing or eliminating non-initial Ion version markers.void
setLongStringThreshold(int threshold)
Sets the length beyond which string and clob content will be rendered as triple-quoted "long strings".void
setLstMinimizing(IonTextWriterBuilder.LstMinimizing minimizing)
Sets the strategy for reducing or eliminating local symbol tables.void
setNewLineType(IonTextWriterBuilder.NewLineType newLineType)
Sets the character sequence that will be written as a line separator.void
setWriteTopLevelValuesOnNewLines(boolean writeTopLevelValuesOnNewLines)
Sets whether each top level value for standard printing should start on a new line.static IonTextWriterBuilder
standard()
The standard builder of textIonWriter
s, with all configuration properties having their default values.IonTextWriterBuilder
withCatalog(IonCatalog catalog)
Declares the catalog to use when building anIonWriter
, returning a new mutable builder if this is immutable.IonTextWriterBuilder
withCharset(java.nio.charset.Charset charset)
Declares the charset denoting the output encoding, returning a new mutable builder if this is immutable.IonTextWriterBuilder
withCharsetAscii()
Declares the output encoding to beUS-ASCII
.IonTextWriterBuilder
withImports(SymbolTable... imports)
Declares the imports to use when building anIonWriter
, returning a new mutable builder if this is immutable.IonTextWriterBuilder
withInitialIvmHandling(IonWriterBuilder.InitialIvmHandling handling)
Declares the strategy for emitting Ion version markers at the start of the stream, returning a new mutable builder if this is immutable.IonTextWriterBuilder
withIvmMinimizing(IonWriterBuilder.IvmMinimizing minimizing)
Declares the strategy for reducing or eliminating non-initial Ion version markers, returning a new mutable builder if this is immutable.abstract IonTextWriterBuilder
withJsonDowngrade()
Declares that this builder should downgrade the writers' output to JSON compatibility.IonTextWriterBuilder
withLongStringThreshold(int threshold)
Declares the length beyond which string and clob content will be rendered as triple-quoted "long strings".IonTextWriterBuilder
withLstMinimizing(IonTextWriterBuilder.LstMinimizing minimizing)
Sets the strategy for reducing or eliminating local symbol tables.IonTextWriterBuilder
withMinimalSystemData()
Declares that this builder should minimize system-level output (Ion version markers and local symbol tables).IonTextWriterBuilder
withNewLineType(IonTextWriterBuilder.NewLineType newLineType)
Declares the character sequence that will be written as a line separator.abstract IonTextWriterBuilder
withPrettyPrinting()
Declares that this builder should use basic pretty-printing.IonTextWriterBuilder
withWriteTopLevelValuesOnNewLines(boolean writeTopLevelValuesOnNewLines)
Declares whether each top level value for standard printing should start on a new line.-
Methods inherited from class com.amazon.ion.system.IonWriterBuilder
build
-
-
-
-
Constructor Detail
-
IonTextWriterBuilder
protected IonTextWriterBuilder()
NOT FOR APPLICATION USE!
-
IonTextWriterBuilder
protected IonTextWriterBuilder(IonTextWriterBuilder that)
NOT FOR APPLICATION USE!
-
-
Method Detail
-
standard
public static IonTextWriterBuilder standard()
The standard builder of textIonWriter
s, with all configuration properties having their default values. The resulting output is a direct representation of what's written to the writer, including version markers and local symbol tables.
-
minimal
public static IonTextWriterBuilder minimal()
Creates a builder configured to minimize system data, eliminating local symbol tables and minimizing version markers.- Returns:
- a new, mutable builder instance.
- See Also:
withMinimalSystemData()
-
pretty
public static IonTextWriterBuilder pretty()
Creates a builder preconfigured for basic pretty-printing.The specifics of this configuration may change between releases of this library, so automated processes should not depend on the exact output formatting. In particular, there's currently no promise regarding handling of system data.
- Returns:
- a new, mutable builder instance.
- See Also:
withPrettyPrinting()
-
json
public static IonTextWriterBuilder json()
Creates a builder preconfigured for JSON compatibility.- Returns:
- a new, mutable builder instance.
- See Also:
withJsonDowngrade()
-
copy
public abstract IonTextWriterBuilder copy()
-
immutable
public abstract IonTextWriterBuilder immutable()
-
mutable
public abstract IonTextWriterBuilder mutable()
-
withCatalog
public final IonTextWriterBuilder withCatalog(IonCatalog catalog)
Declares the catalog to use when building anIonWriter
, returning a new mutable builder if this is immutable.- Parameters:
catalog
- the catalog to use in built writers. If null, the writer will be unable to resolve manually-written imports and may throw an exception.- Returns:
- this instance, if mutable; otherwise a mutable copy of this instance.
- See Also:
getCatalog()
,setCatalog(IonCatalog)
-
withImports
public final IonTextWriterBuilder withImports(SymbolTable... imports)
Declares the imports to use when building anIonWriter
, returning a new mutable builder if this is immutable.If the imports sequence is not null and not empty, the output stream will be bootstrapped with a local symbol table that uses the given
imports
.- Parameters:
imports
- a sequence of shared symbol tables. The first (and only the first) may be a system table.- Returns:
- this instance, if mutable; otherwise a mutable copy of this instance.
- See Also:
getImports()
,setImports(SymbolTable...)
-
getCharset
public final java.nio.charset.Charset getCharset()
Gets the charset denoting the output encoding. Only ASCII and UTF-8 are supported.- Returns:
- may be null, denoting the default of UTF-8.
- See Also:
setCharset(Charset)
,withCharset(Charset)
-
setCharset
public void setCharset(java.nio.charset.Charset charset)
Sets the charset denoting the output encoding. Only ASCII and UTF-8 are supported; applications can use the helper constantsASCII
andUTF8
.- Parameters:
charset
- may be null, denoting the default of UTF-8.- Throws:
java.lang.UnsupportedOperationException
- if this is immutable.- See Also:
getCharset()
,withCharset(Charset)
-
withCharset
public final IonTextWriterBuilder withCharset(java.nio.charset.Charset charset)
Declares the charset denoting the output encoding, returning a new mutable builder if this is immutable. Only ASCII and UTF-8 are supported; applications can use the helper constantsASCII
andUTF8
.- Parameters:
charset
- may be null, denoting the default of UTF-8.- Returns:
- this instance, if mutable; otherwise a mutable copy of this instance.
- See Also:
getCharset()
,setCharset(Charset)
-
withCharsetAscii
public final IonTextWriterBuilder withCharsetAscii()
Declares the output encoding to beUS-ASCII
.- Returns:
- this instance, if mutable; otherwise a mutable copy of this instance.
-
withMinimalSystemData
public final IonTextWriterBuilder withMinimalSystemData()
Declares that this builder should minimize system-level output (Ion version markers and local symbol tables).This is equivalent to:
- Returns:
- this instance, if mutable; otherwise a mutable copy of this instance.
-
withPrettyPrinting
public abstract IonTextWriterBuilder withPrettyPrinting()
Declares that this builder should use basic pretty-printing. Does not alter the handling of system data. Calling this method alters several other configuration properties, so code should call it first, then make any necessary overrides.The specifics of this configuration may change between releases of this library, so automated processes should not depend on the exact output formatting.
- Returns:
- this instance, if mutable; otherwise a mutable copy of this instance.
-
withJsonDowngrade
public abstract IonTextWriterBuilder withJsonDowngrade()
Declares that this builder should downgrade the writers' output to JSON compatibility. This format cannot round-trip back to Ion with full fidelity.The specific conversions are as follows:
- System data is suppressed per
withMinimalSystemData()
. - All annotations are suppressed.
- Nulls of any type are printed as JSON
null
. - Blobs are printed as strings, containing Base64.
- Clobs are printed as strings, containing only Unicode code points U+00 through U+FF.
- Sexps are printed as lists.
- Symbols are printed as strings.
- Timestamps are printed as strings, using Ion timestamp format.
- Returns:
- this instance, if mutable; otherwise a mutable copy of this instance.
- System data is suppressed per
-
getInitialIvmHandling
public final IonWriterBuilder.InitialIvmHandling getInitialIvmHandling()
Gets the strategy for emitting Ion version markers at the start of the stream. By default, IVMs are emitted only when explicitly written or when necessary (for example, before data that's not Ion 1.0, or at the start of Ion binary output).- Specified by:
getInitialIvmHandling
in classIonWriterBuilder
- Returns:
- the initial IVM strategy.
The default value (
null
) indicates that an initial IVM is emitted if and only if it is received by the writer. - See Also:
setInitialIvmHandling(IonWriterBuilder.InitialIvmHandling)
,withInitialIvmHandling(IonWriterBuilder.InitialIvmHandling)
-
setInitialIvmHandling
public void setInitialIvmHandling(IonWriterBuilder.InitialIvmHandling handling)
Sets the strategy for emitting Ion version markers at the start of the stream. By default, IVMs are emitted only when explicitly written or when necessary (for example, before data that's not Ion 1.0).- Parameters:
handling
- the initial IVM strategy. Null indicates that explicitly-written IVMs will be emitted.- Throws:
java.lang.UnsupportedOperationException
- if this is immutable.- See Also:
getInitialIvmHandling()
,withInitialIvmHandling(IonWriterBuilder.InitialIvmHandling)
-
withInitialIvmHandling
public final IonTextWriterBuilder withInitialIvmHandling(IonWriterBuilder.InitialIvmHandling handling)
Declares the strategy for emitting Ion version markers at the start of the stream, returning a new mutable builder if this is immutable. By default, IVMs are emitted only when explicitly written or when necessary (for example, before data that's not Ion 1.0).- Parameters:
handling
- the initial IVM strategy. Null indicates that explicitly-written IVMs will be emitted.- Returns:
- this instance, if mutable; otherwise a mutable copy of this instance.
- See Also:
setInitialIvmHandling(IonWriterBuilder.InitialIvmHandling)
,withInitialIvmHandling(IonWriterBuilder.InitialIvmHandling)
-
getIvmMinimizing
public final IonWriterBuilder.IvmMinimizing getIvmMinimizing()
Gets the strategy for eliminating Ion version markers mid-stream. By default, IVMs are emitted as received or when necessary.This strategy does not affect handling of IVMs at the start of the stream; that's the job of
IonWriterBuilder.InitialIvmHandling
.- Specified by:
getIvmMinimizing
in classIonWriterBuilder
- Returns:
- the IVM minimizing strategy.
The default value (
null
) indicates that no minimization occurs and IVMs are emitted as received by the writer. - See Also:
setIvmMinimizing(IonWriterBuilder.IvmMinimizing)
,withIvmMinimizing(IonWriterBuilder.IvmMinimizing)
-
setIvmMinimizing
public void setIvmMinimizing(IonWriterBuilder.IvmMinimizing minimizing)
Sets the strategy for reducing or eliminating non-initial Ion version markers. When null, IVMs are emitted as they are written.- Parameters:
minimizing
- the IVM minimization strategy. Null indicates that all explicitly-written IVMs will be emitted.- Throws:
java.lang.UnsupportedOperationException
- if this is immutable.- See Also:
getIvmMinimizing()
,withIvmMinimizing(IonWriterBuilder.IvmMinimizing)
-
withIvmMinimizing
public final IonTextWriterBuilder withIvmMinimizing(IonWriterBuilder.IvmMinimizing minimizing)
Declares the strategy for reducing or eliminating non-initial Ion version markers, returning a new mutable builder if this is immutable. When null, IVMs are emitted as they are written.- Parameters:
minimizing
- the IVM minimization strategy. Null indicates that all explicitly-written IVMs will be emitted.- Returns:
- this instance, if mutable; otherwise a mutable copy of this instance.
- See Also:
setIvmMinimizing(IonWriterBuilder.IvmMinimizing)
,getIvmMinimizing()
-
getLstMinimizing
public final IonTextWriterBuilder.LstMinimizing getLstMinimizing()
Gets the strategy for reducing or eliminating local symbol tables. By default, LST data is emitted as received or when necessary (for example, binary data will always collect and emit local symbols).
-
setLstMinimizing
public void setLstMinimizing(IonTextWriterBuilder.LstMinimizing minimizing)
Sets the strategy for reducing or eliminating local symbol tables. By default, LST data is emitted as received or when necessary (for example, binary data will always collect and emit local symbols).- Parameters:
minimizing
- the LST minimization strategy. Null indicates that LSTs will be emitted as received.- Throws:
java.lang.UnsupportedOperationException
- if this is immutable.- See Also:
getLstMinimizing()
,withLstMinimizing(LstMinimizing)
-
withLstMinimizing
public final IonTextWriterBuilder withLstMinimizing(IonTextWriterBuilder.LstMinimizing minimizing)
Sets the strategy for reducing or eliminating local symbol tables. By default, LST data is emitted as received or when necessary (for example, binary data will always collect and emit local symbols).- Parameters:
minimizing
- the LST minimization strategy. Null indicates that LSTs will be emitted as received.- Returns:
- this instance, if mutable; otherwise a mutable copy of this instance.
- See Also:
getLstMinimizing()
,setLstMinimizing(LstMinimizing)
-
getLongStringThreshold
public final int getLongStringThreshold()
Gets the length beyond which string and clob content will be rendered as triple-quoted "long strings". At present, such content will only line-break on extant newlines.- Returns:
- the threshold for printing triple-quoted strings and clobs. Zero means no limit.
- See Also:
setLongStringThreshold(int)
,withLongStringThreshold(int)
-
setLongStringThreshold
public void setLongStringThreshold(int threshold)
Sets the length beyond which string and clob content will be rendered as triple-quoted "long strings". At present, such content will only line-break on extant newlines.- Parameters:
threshold
- the new threshold; zero means none.- Throws:
java.lang.UnsupportedOperationException
- if this is immutable.- See Also:
getLongStringThreshold()
,withLongStringThreshold(int)
-
withLongStringThreshold
public final IonTextWriterBuilder withLongStringThreshold(int threshold)
Declares the length beyond which string and clob content will be rendered as triple-quoted "long strings". At present, such content will only line-break on extant newlines.- Parameters:
threshold
- the new threshold; zero means none.- Returns:
- this instance, if mutable; otherwise a mutable copy of this instance.
- See Also:
getLongStringThreshold()
,setLongStringThreshold(int)
-
getNewLineType
public final IonTextWriterBuilder.NewLineType getNewLineType()
Gets the character sequence that will be written as a line separator. The default isIonTextWriterBuilder.NewLineType.PLATFORM_DEPENDENT
- Returns:
- the character sequence to be written between top-level values; null means the default should be used.
- See Also:
setNewLineType(NewLineType)
,withNewLineType(NewLineType)
-
setNewLineType
public void setNewLineType(IonTextWriterBuilder.NewLineType newLineType)
Sets the character sequence that will be written as a line separator. The default isIonTextWriterBuilder.NewLineType.PLATFORM_DEPENDENT
- Parameters:
newLineType
- the character sequence to be written between top-level values; null means the default should be used.- Throws:
java.lang.UnsupportedOperationException
- if this is immutable.- See Also:
getNewLineType()
,withNewLineType(NewLineType)
-
withNewLineType
public final IonTextWriterBuilder withNewLineType(IonTextWriterBuilder.NewLineType newLineType)
Declares the character sequence that will be written as a line separator. The default isIonTextWriterBuilder.NewLineType.PLATFORM_DEPENDENT
- Parameters:
newLineType
- the character sequence to be written between top-level values; null means the default should be used.- Returns:
- this instance, if mutable; otherwise a mutable copy of this instance.
- See Also:
getNewLineType()
,setNewLineType(NewLineType)
-
getWriteTopLevelValuesOnNewLines
public final boolean getWriteTopLevelValuesOnNewLines()
Gets whether each top level value for standard printing should start on a new line. The default value isfalse
. When false, the IonTextWriter will insert a single space character (U+0020) between top-level values. When pretty-printing, this setting is ignored; the pretty printer will always start top-level values on a new line.- Returns:
- value indicating whether standard printing will insert a newline between top-level values
- See Also:
setWriteTopLevelValuesOnNewLines(boolean)
,withWriteTopLevelValuesOnNewLines(boolean)
-
setWriteTopLevelValuesOnNewLines
public void setWriteTopLevelValuesOnNewLines(boolean writeTopLevelValuesOnNewLines)
Sets whether each top level value for standard printing should start on a new line. The default value isfalse
. When false, the IonTextWriter will insert a single space character (U+0020) between top-level values. When pretty-printing, this setting is ignored; the pretty printer will always start top-level values on a new line.- Parameters:
writeTopLevelValuesOnNewLines
- value indicating whether standard printing will insert a newline between top-level values- See Also:
getWriteTopLevelValuesOnNewLines()
,withWriteTopLevelValuesOnNewLines(boolean)
-
withWriteTopLevelValuesOnNewLines
public final IonTextWriterBuilder withWriteTopLevelValuesOnNewLines(boolean writeTopLevelValuesOnNewLines)
Declares whether each top level value for standard printing should start on a new line. The default value isfalse
. When false, the IonTextWriter will insert a single space character (U+0020) between top-level values. When pretty-printing, this setting is ignored; the pretty printer will always start top-level values on a new line.- Parameters:
writeTopLevelValuesOnNewLines
- value indicating whether standard printing will insert a newline between top-level values- See Also:
getWriteTopLevelValuesOnNewLines()
,setWriteTopLevelValuesOnNewLines(boolean)
-
build
public abstract IonWriter build(java.lang.Appendable out)
Creates a new writer that will write text to the given output stream.If you have an
OutputStream
, you'll get better performance usingIonWriterBuilder.build(OutputStream)
as opposed to wrapping your stream in anAppendable
and calling this method.- Parameters:
out
- the stream that will receive Ion text data. Must not be null.- Returns:
- a new
IonWriter
instance; notnull
.
-
mutationCheck
protected void mutationCheck()
NOT FOR APPLICATION USE!
-
getCatalog
public final IonCatalog getCatalog()
Gets the catalog to use when building anIonWriter
. The catalog is needed to resolve manually-written imports (not common). By default, this property is null.- See Also:
setCatalog(IonCatalog)
,withCatalog(IonCatalog)
-
setCatalog
public void setCatalog(IonCatalog catalog)
Sets the catalog to use when building anIonWriter
.- Parameters:
catalog
- the catalog to use in built writers. If null, the writer will be unable to resolve manually-written imports and may throw an exception.- Throws:
java.lang.UnsupportedOperationException
- if this is immutable.- See Also:
getCatalog()
,withCatalog(IonCatalog)
-
getImports
public final SymbolTable[] getImports()
Gets the imports that will be used to construct the initial local symbol table.- Returns:
- may be null or empty.
- See Also:
setImports(SymbolTable...)
,withImports(SymbolTable...)
-
setImports
public void setImports(SymbolTable... imports)
Sets the shared symbol tables that will be used to construct the initial local symbol table.If the imports sequence is not null and not empty, the output stream will be bootstrapped with a local symbol table that uses the given
imports
.- Parameters:
imports
- a sequence of shared symbol tables. The first (and only the first) may be a system table.- Throws:
java.lang.UnsupportedOperationException
- if this is immutable.- See Also:
getImports()
,withImports(SymbolTable...)
-
-