Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
131 changes: 124 additions & 7 deletions ion/src/main/java/com/fasterxml/jackson/dataformat/ion/IonFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,31 @@ public class IonFactory extends JsonFactory {
* Whether we will produce binary or text Ion writers: default is textual.
*/
protected boolean _cfgCreateBinaryWriters = false;


/**
* Bitfield (set of flags) of all parser features that are enabled
* by default.
*/
protected final static int DEFAULT_ION_PARSER_FEATURE_FLAGS = IonParser.Feature.collectDefaults();

/**
* Bitfield (set of flags) of all generator features that are enabled
* by default.
*/
protected final static int DEFAULT_ION_GENERATOR_FEATURE_FLAGS = IonGenerator.Feature.collectDefaults();

protected int _ionParserFeatures = DEFAULT_ION_PARSER_FEATURE_FLAGS;

protected int _ionGeneratorFeatures = DEFAULT_ION_GENERATOR_FEATURE_FLAGS;

public IonFactory() {
this((ObjectCodec) null);
}

public IonFactory(ObjectCodec mapper) {
this(mapper, IonSystemBuilder.standard().build());
}

public IonFactory(ObjectCodec mapper, IonSystem system) {
super(mapper);
_system = system;
Expand Down Expand Up @@ -110,7 +126,7 @@ public static IonFactory forBinaryWriters() {
public static IonFactoryBuilder builderForBinaryWriters() {
return new IonFactoryBuilder(true);
}

/**
* Method for creating {@link IonFactory} that will
* create textual (not binary) writers.
Expand Down Expand Up @@ -144,7 +160,7 @@ public Version version() {
public String getFormatName() {
return FORMAT_NAME_ION;
}

public void setCreateBinaryWriters(boolean b) {
_cfgCreateBinaryWriters = b;
}
Expand All @@ -164,6 +180,107 @@ public boolean canUseCharArrays() {
return false;
}

/*
/**********************************************************
/* Configuration, parser settings
/**********************************************************
*/

/**
* Method for enabling or disabling specified parser feature
* (check {@link IonParser.Feature} for list of features)
*/
public final IonFactory configure(IonParser.Feature f, boolean state)
{
if (state) {
enable(f);
} else {
disable(f);
}
return this;
}

/**
* Method for enabling specified parser feature
* (check {@link IonParser.Feature} for list of features)
*/
public IonFactory enable(IonParser.Feature f) {
_ionParserFeatures |= f.getMask();
return this;
}

/**
* Method for disabling specified parser features
* (check {@link IonParser.Feature} for list of features)
*/
public IonFactory disable(IonParser.Feature f) {
_ionParserFeatures &= ~f.getMask();
return this;
}

/**
* Checked whether specified parser feature is enabled.
*/
public final boolean isEnabled(IonParser.Feature f) {
return (_ionParserFeatures & f.getMask()) != 0;
}

@Override
public int getFormatParserFeatures() {
return _ionParserFeatures;
}

/*
/**********************************************************
/* Configuration, generator settings
/**********************************************************
*/

/**
* Method for enabling or disabling specified generator feature
* (check {@link IonGenerator.Feature} for list of features)
*/
public final IonFactory configure(IonGenerator.Feature f, boolean state) {
if (state) {
enable(f);
} else {
disable(f);
}
return this;
}


/**
* Method for enabling specified generator features
* (check {@link IonGenerator.Feature} for list of features)
*/
public IonFactory enable(IonGenerator.Feature f) {
_ionGeneratorFeatures |= f.getMask();
return this;
}

/**
* Method for disabling specified generator feature
* (check {@link IonGenerator.Feature} for list of features)
*/
public IonFactory disable(IonGenerator.Feature f) {
_ionGeneratorFeatures &= ~f.getMask();
return this;
}

/**
* Check whether specified generator feature is enabled.
*/
public final boolean isEnabled(IonGenerator.Feature f) {
return (_ionGeneratorFeatures & f.getMask()) != 0;
}

@Override
public int getFormatGeneratorFeatures() {
return _ionGeneratorFeatures;
}


/*
***************************************************************
* Extended API
Expand Down Expand Up @@ -305,7 +422,7 @@ protected String _readAll(Reader r, IOContext ctxt) throws IOException

main_loop:
while (true) {

while (offset < buf.length) {
int count = r.read(buf, offset, buf.length - offset);
if (count < 0) {
Expand Down Expand Up @@ -355,6 +472,6 @@ protected IonGenerator _createGenerator(OutputStream out, JsonEncoding enc, bool

protected IonGenerator _createGenerator(IonWriter ion, boolean ionWriterIsManaged, IOContext ctxt, Closeable dst)
{
return new IonGenerator(_generatorFeatures, _objectCodec, ion, ionWriterIsManaged, ctxt, dst);
}
return new IonGenerator(_generatorFeatures, _ionGeneratorFeatures, _objectCodec, ion, ionWriterIsManaged, ctxt, dst);
}
}
Loading