use of com.amazon.ion.IonWriter in project jackson-dataformats-binary by FasterXML.
the class IonObjectMapper method writeValueAsIonValue.
/**
* Method that can be used to map any Java value to an IonValue.
*/
public IonValue writeValueAsIonValue(Object value) throws IOException {
// 04-Jan-2017, tatu: Bit of incompatiblity wrt 2.x handling: should this result in
// Java `null`, or Ion null marker? For now, choose latter
/*
if (value == null) {
return null;
}
*/
IonFactory f = tokenStreamFactory();
IonDatagram container = f._system.newDatagram();
try (IonWriter writer = f._system.newWriter(container)) {
writeValue(writer, value);
IonValue result = container.get(0);
result.removeFromContainer();
return result;
}
}
use of com.amazon.ion.IonWriter in project ion-java by amzn.
the class SymtabApp method processFiles.
@Override
public void processFiles(String[] filePaths) {
super.processFiles(filePaths);
SymbolTable[] importArray = new SymbolTable[myImports.size()];
myImports.toArray(importArray);
SymbolTable mySymtab = mySystem.newSharedSymbolTable(mySymtabName, mySymtabVersion, mySymbols.iterator(), importArray);
IonWriter w = mySystem.newTextWriter((OutputStream) System.out);
try {
// TODO ensure IVM is printed
mySymtab.writeTo(w);
System.out.println();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
use of com.amazon.ion.IonWriter in project ion-java by amzn.
the class _Private_IonWriterFactory method makeWriter.
/**
* @param container must not be null.
*/
public static IonWriter makeWriter(IonContainer container) {
IonSystem sys = container.getSystem();
IonCatalog cat = sys.getCatalog();
IonWriter writer = makeWriter(cat, container);
return writer;
}
use of com.amazon.ion.IonWriter in project ion-java by amzn.
the class _Private_CommandLine method doPrintVersion.
private static void doPrintVersion() throws IOException {
IonTextWriterBuilder b = IonTextWriterBuilder.pretty();
b.setCharset(IonTextWriterBuilder.ASCII);
IonWriter w = b.build((Appendable) System.out);
w.stepIn(IonType.STRUCT);
{
w.setFieldName("version");
w.writeString(info.getProjectVersion());
w.setFieldName("build_time");
w.writeTimestamp(info.getBuildTime());
}
w.stepOut();
w.finish();
System.out.println();
}
use of com.amazon.ion.IonWriter in project ion-java by amzn.
the class IonReaderLookaheadBufferTest method rewindToValueStartWithLstAppend.
@Test
public void rewindToValueStartWithLstAppend() throws Exception {
ByteArrayOutputStream out = new ByteArrayOutputStream();
IonWriter writer = IonBinaryWriterBuilder.standard().withLocalSymbolTableAppendEnabled().build(out);
writer.writeSymbol("abc");
writer.flush();
writer.writeSymbol("def");
writer.close();
InputStream input = new ByteArrayInputStream(out.toByteArray());
IonReaderLookaheadBuffer lookahead = new IonReaderLookaheadBuffer(builder.build(), input);
lookahead.fillInput();
IonReader reader = lookahead.newIonReader(IonReaderBuilder.standard());
assertEquals(IonType.SYMBOL, reader.next());
assertEquals("abc", reader.stringValue());
assertTrue(lookahead.moreDataRequired());
lookahead.fillInput();
assertFalse(lookahead.moreDataRequired());
assertEquals(IonType.SYMBOL, reader.next());
assertEquals("def", reader.stringValue());
lookahead.rewindToValueStart();
// 2-byte value (0x71 0x0B). No IVM or symbol table.
assertEquals(2, lookahead.available());
assertEquals(IonType.SYMBOL, reader.next());
assertEquals("def", reader.stringValue());
// Note: if mark() / rewind() is used instead of rewindToValueStart(), the following lines will fail; there
// will be 12 local symbols and "def" will occur twice in the symbol table. That's because mark() includes
// the symbol table (in this case an LST append), and rewinding past the symbol table causes the append
// to be processed a second time by IonReader.next().
SymbolTable symbolTable = reader.getSymbolTable();
assertEquals(symbolTable.getSystemSymbolTable().getMaxId() + 2, reader.getSymbolTable().getMaxId());
List<String> symbols = new ArrayList<String>(2);
Iterator<String> iterator = symbolTable.iterateDeclaredSymbolNames();
while (iterator.hasNext()) {
symbols.add(iterator.next());
}
assertEquals(Arrays.asList("abc", "def"), symbols);
input.close();
}
Aggregations