@Test public void testParserNone() throws IOException { List<DataPacket> dataPackets = DataPacketDto.getDataPacketStream(new ByteArrayInputStream(("[]").getBytes(StandardCharsets.UTF_8))).collect(Collectors.toList()); assertEquals(0, dataPackets.size()); }
public static Stream<DataPacket> getDataPacketStream(InputStream inputStream) throws IOException { JsonParser jsonParser = new JsonFactory().createParser(inputStream); if (jsonParser.nextToken() != JsonToken.START_ARRAY) { throw new IOException("Expecting start array token to begin object array."); } jsonParser.setCodec(new ObjectMapper()); return StreamSupport.stream(Spliterators.spliteratorUnknownSize(new Iterator<DataPacket>() { DataPacket next = getNext(); @Override public boolean hasNext() { return next != null; } @Override public DataPacket next() { DataPacket next = this.next; this.next = getNext(); return next; } DataPacket getNext() throws RuntimeException { try { if (jsonParser.nextToken() == JsonToken.END_ARRAY) { return null; } DataPacketDto dataPacketDto = jsonParser.readValueAs(DATA_PACKET_DTO_TYPE_REFERENCE); return dataPacketDto.toDataPacket(); } catch (IOException e) { throw new RuntimeException(e); } } }, Spliterator.ORDERED), false); }
DataPacketDto { public static Stream<DataPacket> getDataPacketStream(InputStream inputStream) throws IOException { JsonParser jsonParser = new JsonFactory().createParser(inputStream); if (jsonParser.nextToken() != JsonToken.START_ARRAY) { throw new IOException("Expecting start array token to begin object array."); } jsonParser.setCodec(new ObjectMapper()); return StreamSupport.stream(Spliterators.spliteratorUnknownSize(new Iterator<DataPacket>() { DataPacket next = getNext(); @Override public boolean hasNext() { return next != null; } @Override public DataPacket next() { DataPacket next = this.next; this.next = getNext(); return next; } DataPacket getNext() throws RuntimeException { try { if (jsonParser.nextToken() == JsonToken.END_ARRAY) { return null; } DataPacketDto dataPacketDto = jsonParser.readValueAs(DATA_PACKET_DTO_TYPE_REFERENCE); return dataPacketDto.toDataPacket(); } catch (IOException e) { throw new RuntimeException(e); } } }, Spliterator.ORDERED), false); } }
DataPacketDto { public static Stream<DataPacket> getDataPacketStream(InputStream inputStream) throws IOException { JsonParser jsonParser = new JsonFactory().createParser(inputStream); if (jsonParser.nextToken() != JsonToken.START_ARRAY) { throw new IOException("Expecting start array token to begin object array."); } jsonParser.setCodec(new ObjectMapper()); return StreamSupport.stream(Spliterators.spliteratorUnknownSize(new Iterator<DataPacket>() { DataPacket next = getNext(); @Override public boolean hasNext() { return next != null; } @Override public DataPacket next() { DataPacket next = this.next; this.next = getNext(); return next; } DataPacket getNext() throws RuntimeException { try { if (jsonParser.nextToken() == JsonToken.END_ARRAY) { return null; } DataPacketDto dataPacketDto = jsonParser.readValueAs(DATA_PACKET_DTO_TYPE_REFERENCE); return dataPacketDto.toDataPacket(); } catch (IOException e) { throw new RuntimeException(e); } } }, Spliterator.ORDERED), false); } DataPacketDto();  DataPacketDto(byte[] data);  DataPacketDto(Map<String, String> attributes, byte[] data);  DataPacketDto(Map<String, String> attributes, String dataFile);  DataPacketDto(Map<String, String> attributes, byte[] data, String dataFile); }
DataPacketDto { public static Stream<DataPacket> getDataPacketStream(InputStream inputStream) throws IOException { JsonParser jsonParser = new JsonFactory().createParser(inputStream); if (jsonParser.nextToken() != JsonToken.START_ARRAY) { throw new IOException("Expecting start array token to begin object array."); } jsonParser.setCodec(new ObjectMapper()); return StreamSupport.stream(Spliterators.spliteratorUnknownSize(new Iterator<DataPacket>() { DataPacket next = getNext(); @Override public boolean hasNext() { return next != null; } @Override public DataPacket next() { DataPacket next = this.next; this.next = getNext(); return next; } DataPacket getNext() throws RuntimeException { try { if (jsonParser.nextToken() == JsonToken.END_ARRAY) { return null; } DataPacketDto dataPacketDto = jsonParser.readValueAs(DATA_PACKET_DTO_TYPE_REFERENCE); return dataPacketDto.toDataPacket(); } catch (IOException e) { throw new RuntimeException(e); } } }, Spliterator.ORDERED), false); } DataPacketDto();  DataPacketDto(byte[] data);  DataPacketDto(Map<String, String> attributes, byte[] data);  DataPacketDto(Map<String, String> attributes, String dataFile);  DataPacketDto(Map<String, String> attributes, byte[] data, String dataFile); static Stream<DataPacket> getDataPacketStream(InputStream inputStream); Map<String, String> getAttributes(); void setAttributes(Map<String, String> attributes); byte[] getData(); void setData(byte[] data); String getDataFile(); void setDataFile(String dataFile); DataPacket toDataPacket(); DataPacketDto putAttribute(String key, String value); }
DataPacketDto { public static Stream<DataPacket> getDataPacketStream(InputStream inputStream) throws IOException { JsonParser jsonParser = new JsonFactory().createParser(inputStream); if (jsonParser.nextToken() != JsonToken.START_ARRAY) { throw new IOException("Expecting start array token to begin object array."); } jsonParser.setCodec(new ObjectMapper()); return StreamSupport.stream(Spliterators.spliteratorUnknownSize(new Iterator<DataPacket>() { DataPacket next = getNext(); @Override public boolean hasNext() { return next != null; } @Override public DataPacket next() { DataPacket next = this.next; this.next = getNext(); return next; } DataPacket getNext() throws RuntimeException { try { if (jsonParser.nextToken() == JsonToken.END_ARRAY) { return null; } DataPacketDto dataPacketDto = jsonParser.readValueAs(DATA_PACKET_DTO_TYPE_REFERENCE); return dataPacketDto.toDataPacket(); } catch (IOException e) { throw new RuntimeException(e); } } }, Spliterator.ORDERED), false); } DataPacketDto();  DataPacketDto(byte[] data);  DataPacketDto(Map<String, String> attributes, byte[] data);  DataPacketDto(Map<String, String> attributes, String dataFile);  DataPacketDto(Map<String, String> attributes, byte[] data, String dataFile); static Stream<DataPacket> getDataPacketStream(InputStream inputStream); Map<String, String> getAttributes(); void setAttributes(Map<String, String> attributes); byte[] getData(); void setData(byte[] data); String getDataFile(); void setDataFile(String dataFile); DataPacket toDataPacket(); DataPacketDto putAttribute(String key, String value); static final TypeReference<DataPacketDto> DATA_PACKET_DTO_TYPE_REFERENCE; }