use of com.amazon.ion.IonWriter in project ion-java by amzn.
the class IonReaderBinaryIncrementalTest method timestamps.
@Test
public void timestamps() throws Exception {
final List<Timestamp> timestamps = new ArrayList<Timestamp>();
timestamps.add(Timestamp.valueOf("2000T"));
timestamps.add(Timestamp.valueOf("2000-01T"));
timestamps.add(Timestamp.valueOf("2000-01-02T"));
timestamps.add(Timestamp.valueOf("2000-01-02T03:04Z"));
timestamps.add(Timestamp.valueOf("2000-01-02T03:04:05Z"));
timestamps.add(Timestamp.valueOf("2000-01-02T03:04:05.6Z"));
timestamps.add(Timestamp.valueOf("2000-01-02T03:04:05.06Z"));
timestamps.add(Timestamp.valueOf("2000-01-02T03:04:05.006Z"));
timestamps.add(Timestamp.valueOf("2000-01-02T03:04:05.600Z"));
timestamps.add(Timestamp.valueOf("2000-01-02T03:04:05.060Z"));
timestamps.add(Timestamp.valueOf("2000-01-02T03:04:05.060-07:00"));
timestamps.add(Timestamp.valueOf("2000-01-02T03:04:05.060+07:00"));
timestamps.add(Timestamp.valueOf("2000-01-02T03:04:05+07:00"));
timestamps.add(Timestamp.valueOf("2000-01-02T03:04+07:00"));
timestamps.add(Timestamp.valueOf("2000-01-02T03:04:05.9999999Z"));
IonReaderBinaryIncremental reader = readerFor(new WriterFunction() {
@Override
public void write(IonWriter writer) throws IOException {
for (Timestamp timestamp : timestamps) {
writer.writeTimestamp(timestamp);
}
}
});
for (Timestamp timestamp : timestamps) {
assertEquals(IonType.TIMESTAMP, reader.next());
assertEquals(timestamp, reader.timestampValue());
}
assertNull(reader.next());
assertNull(reader.getType());
reader.close();
}
use of com.amazon.ion.IonWriter in project ion-java by amzn.
the class IonReaderLookaheadBufferTest method toBytes.
@Override
byte[] toBytes(String textIon) throws IOException {
ByteArrayOutputStream output = new ByteArrayOutputStream();
_Private_IonSystem system = (_Private_IonSystem) IonSystemBuilder.standard().build();
IonReader reader = system.newSystemReader(textIon);
IonWriter writer = IonBinaryWriterBuilder.standard().build(output);
writer.writeValues(reader);
reader.close();
writer.close();
return output.toByteArray();
}
use of com.amazon.ion.IonWriter in project ion-java by amzn.
the class IonReaderBinaryRawStringTest method testReadShortStrings.
@Test
public void testReadShortStrings() throws Exception {
// This test constructs some strings with non-ascii text that are short enough to fit in
// IonBinaryReaderRawX's reusable decoding buffers and then round-trips them.
// Laughing face with tears
String adage = "Brevity is the soul of wit. \uD83D\uDE02";
// Airplane/fork+knife+plate
String observation = "What's the deal with airline food? \u2708\uFE0F\uD83C\uDF7D️";
// Thumbs up
String litotes = "Not bad. \uD83D\uDC4D";
ByteArrayOutputStream out = new ByteArrayOutputStream();
IonWriter writer = IonBinaryWriterBuilder.standard().build(out);
writer.writeString(adage);
writer.writeString(observation);
writer.writeString(litotes);
writer.close();
byte[] data = out.toByteArray();
IonReader reader = IonReaderBuilder.standard().build(data);
reader.next();
assertEquals(adage, reader.stringValue());
reader.next();
assertEquals(observation, reader.stringValue());
reader.next();
assertEquals(litotes, reader.stringValue());
}
use of com.amazon.ion.IonWriter in project ion-java by amzn.
the class IonReaderBinaryRawStringTest method testReadLargeStrings.
@Test
public void testReadLargeStrings() throws Exception {
// This test constructs some strings with non-ascii text that are large enough to exceed the size
// of IonBinaryReaderRawX's reusable decoding buffers and then round-trips them.
String verse = // Musical notes emoji
"\uD83C\uDFB6 This is the song that never ends\n" + "\uD83C\uDFB5 Yes it goes on and on, my friends!\n" + "\uD83C\uDFB6 Some people started singing it not knowing what it was\n" + "\uD83C\uDFB5 And they'll continue singing it forever just because...\n";
final int numberOfVerses = 1024;
StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i < numberOfVerses; i++) {
stringBuilder.append(verse);
}
String longSong = stringBuilder.toString();
for (int i = 0; i < numberOfVerses; i++) {
stringBuilder.append(verse);
}
String longerSong = stringBuilder.toString();
for (int i = 0; i < numberOfVerses; i++) {
stringBuilder.append(verse);
}
String longestSong = stringBuilder.toString();
ByteArrayOutputStream out = new ByteArrayOutputStream();
IonWriter writer = IonBinaryWriterBuilder.standard().build(out);
writer.writeString(longSong);
writer.writeString(longerSong);
writer.writeString(longestSong);
writer.close();
byte[] songData = out.toByteArray();
IonReader reader = IonReaderBuilder.standard().build(songData);
reader.next();
assertEquals(longSong, reader.stringValue());
reader.next();
assertEquals(longerSong, reader.stringValue());
reader.next();
assertEquals(longestSong, reader.stringValue());
}
use of com.amazon.ion.IonWriter in project ion-java by amzn.
the class IonMarkupWriterFilesTest method testPrintingStandard.
/**
* Tests to make sure that the type, the output stream, and the
* annotation/field name aren't null for all the files. This will fail if
* the callback type isn't being set.
* {@link IonMarkupWriterTest#testStandardCallback()} should verify they're
* set correctly.
*/
@Test
public void testPrintingStandard() throws Exception {
// Just ignore the output, since we're not checking it
OutputStream out = new NullOutputStream();
InputStream in = new FileInputStream(myTestFile);
// Get a Test markup writer
_Private_IonTextWriterBuilder builder = (_Private_IonTextWriterBuilder) IonTextWriterBuilder.standard();
IonWriter ionWriter = builder.withCallbackBuilder(new TestMarkupCallback.Builder()).build(out);
// Load file into a reader
IonReader ionReader = system().newReader(in);
assertNotNull("ionReader is null", ionReader);
assertNotNull("ionWriter is null", ionWriter);
// Write data to the writer
ionWriter.writeValues(ionReader);
// Close the writer and reader
ionWriter.close();
ionReader.close();
}
Aggregations