@Test public void testDataTypes() throws IOException, ParseException { OutputStream out = new ByteArrayOutputStream(); final List<RecordField> fields = new ArrayList<>(); for (final RecordFieldType fieldType : RecordFieldType.values()) { if (fieldType == RecordFieldType.CHOICE) { final List<DataType> possibleTypes = new ArrayList<>(); possibleTypes.add(RecordFieldType.INT.getDataType()); possibleTypes.add(RecordFieldType.LONG.getDataType()); fields.add(new RecordField(fieldType.name().toLowerCase(), fieldType.getChoiceDataType(possibleTypes))); } else if (fieldType == RecordFieldType.MAP) { fields.add(new RecordField(fieldType.name().toLowerCase(), fieldType.getMapDataType(RecordFieldType.INT.getDataType()))); } else { fields.add(new RecordField(fieldType.name().toLowerCase(), fieldType.getDataType())); } } final RecordSchema schema = new SimpleRecordSchema(fields, SCHEMA_IDENTIFIER_RECORD); final DateFormat df = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss.SSS"); df.setTimeZone(TimeZone.getTimeZone("gmt")); final long time = df.parse("2017/01/01 17:00:00.000").getTime(); final Map<String, Object> map = new LinkedHashMap<>(); map.put("height", 48); map.put("width", 96); final Map<String, Object> valueMap = new LinkedHashMap<>(); valueMap.put("string", "string"); valueMap.put("boolean", true); valueMap.put("byte", (byte) 1); valueMap.put("char", 'c'); valueMap.put("short", (short) 8); valueMap.put("int", 9); valueMap.put("bigint", BigInteger.valueOf(8L)); valueMap.put("long", 8L); valueMap.put("float", 8.0F); valueMap.put("double", 8.0D); valueMap.put("date", new Date(time)); valueMap.put("time", new Time(time)); valueMap.put("timestamp", new Timestamp(time)); valueMap.put("record", null); valueMap.put("array", null); valueMap.put("choice", 48L); valueMap.put("map", map); final Record record = new MapRecord(schema, valueMap); final RecordSet rs = RecordSet.of(schema, record); WriteXMLResult writer = new WriteXMLResult(Mockito.mock(ComponentLog.class), rs.getSchema(), new SchemaNameAsAttribute(), out, true, NEVER_SUPPRESS, NO_WRAPPING, null, "ROOT", "RECORD", "UTF-8", DATE_FORMAT, TIME_FORMAT, TIMESTAMP_FORMAT); writer.write(rs); writer.flush(); String xmlResult = "<ROOT><RECORD><string>string</string><boolean>true</boolean><byte>1</byte><char>c</char><short>8</short>" + "<int>9</int><bigint>8</bigint><long>8</long><float>8.0</float><double>8.0</double><date>2017-01-01</date>" + "<time>17:00:00</time><timestamp>2017-01-01 17:00:00</timestamp><record /><choice>48</choice><array />" + "<map><height>48</height><width>96</width></map></RECORD></ROOT>"; assertThat(xmlResult, CompareMatcher.isSimilarTo(out.toString()).ignoreWhitespace().withNodeMatcher(new DefaultNodeMatcher(ElementSelectors.byNameAndText))); }
@Override public void flush() throws IOException { try { writer.flush(); } catch (XMLStreamException e) { throw new IOException(e.getMessage()); } }
WriteXMLResult extends AbstractRecordSetWriter implements RecordSetWriter, RawRecordWriter { @Override public void flush() throws IOException { try { writer.flush(); } catch (XMLStreamException e) { throw new IOException(e.getMessage()); } } }
WriteXMLResult extends AbstractRecordSetWriter implements RecordSetWriter, RawRecordWriter { @Override public void flush() throws IOException { try { writer.flush(); } catch (XMLStreamException e) { throw new IOException(e.getMessage()); } } WriteXMLResult(final ComponentLog logger, final RecordSchema recordSchema, final SchemaAccessWriter schemaAccess, final OutputStream out, final boolean prettyPrint,
                          final NullSuppression nullSuppression, final ArrayWrapping arrayWrapping, final String arrayTagName, final String rootTagName, final String recordTagName,
                          final String charSet, final String dateFormat, final String timeFormat, final String timestampFormat); }
WriteXMLResult extends AbstractRecordSetWriter implements RecordSetWriter, RawRecordWriter { @Override public void flush() throws IOException { try { writer.flush(); } catch (XMLStreamException e) { throw new IOException(e.getMessage()); } } WriteXMLResult(final ComponentLog logger, final RecordSchema recordSchema, final SchemaAccessWriter schemaAccess, final OutputStream out, final boolean prettyPrint,
                          final NullSuppression nullSuppression, final ArrayWrapping arrayWrapping, final String arrayTagName, final String rootTagName, final String recordTagName,
                          final String charSet, final String dateFormat, final String timeFormat, final String timestampFormat); @Override void close(); @Override void flush(); @Override WriteResult writeRawRecord(Record record); @Override String getMimeType(); }
WriteXMLResult extends AbstractRecordSetWriter implements RecordSetWriter, RawRecordWriter { @Override public void flush() throws IOException { try { writer.flush(); } catch (XMLStreamException e) { throw new IOException(e.getMessage()); } } WriteXMLResult(final ComponentLog logger, final RecordSchema recordSchema, final SchemaAccessWriter schemaAccess, final OutputStream out, final boolean prettyPrint,
                          final NullSuppression nullSuppression, final ArrayWrapping arrayWrapping, final String arrayTagName, final String rootTagName, final String recordTagName,
                          final String charSet, final String dateFormat, final String timeFormat, final String timestampFormat); @Override void close(); @Override void flush(); @Override WriteResult writeRawRecord(Record record); @Override String getMimeType();  }