com.fasterxml.jackson.databind.MappingIterator Java Examples

The following examples show how to use com.fasterxml.jackson.databind.MappingIterator. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ReadJsonBuilder.java    From kite with Apache License 2.0 6 votes vote down vote up
@Override
protected boolean doProcess(Record inputRecord, InputStream in) throws IOException {
  Record template = inputRecord.copy();
  removeAttachments(template);
  MappingIterator iter = reader.readValues(in);
  try {
    while (iter.hasNextValue()) {
      Object rootNode = iter.nextValue();
      incrementNumRecords();
      LOG.trace("jsonObject: {}", rootNode);
      
      Record outputRecord = template.copy();
      outputRecord.put(Fields.ATTACHMENT_BODY, rootNode);
      outputRecord.put(Fields.ATTACHMENT_MIME_TYPE, MIME_TYPE);
  
      // pass record to next command in chain:
      if (!getChild().process(outputRecord)) {
        return false;
      }
    }
    return true;
  } finally {
    iter.close();
  }
}
 
Example #2
Source File: AvroProducerDemo.java    From Kafka-Streams-Real-time-Stream-Processing with The Unlicense 6 votes vote down vote up
/**
 * private static method to read data from given dataFile
 *
 * @param dataFile data file name in resource folder
 * @return List of StockData Instance
 * @throws IOException, NullPointerException
 */
private static List<StockData> getStocks(String dataFile) throws IOException {
    File file = new File(dataFile);
    CsvSchema schema = CsvSchema.builder()
            .addColumn("symbol", CsvSchema.ColumnType.STRING)
            .addColumn("series", CsvSchema.ColumnType.STRING)
            .addColumn("open", CsvSchema.ColumnType.NUMBER)
            .addColumn("high", CsvSchema.ColumnType.NUMBER)
            .addColumn("low", CsvSchema.ColumnType.NUMBER)
            .addColumn("close", CsvSchema.ColumnType.NUMBER)
            .addColumn("last", CsvSchema.ColumnType.NUMBER)
            .addColumn("previousClose", CsvSchema.ColumnType.NUMBER)
            .addColumn("totalTradedQty", CsvSchema.ColumnType.NUMBER)
            .addColumn("totalTradedVal", CsvSchema.ColumnType.NUMBER)
            .addColumn("tradeDate", CsvSchema.ColumnType.STRING)
            .addColumn("totalTrades", CsvSchema.ColumnType.NUMBER)
            .addColumn("isinCode", CsvSchema.ColumnType.STRING)
            .build();
    MappingIterator<StockData> stockDataIterator = new CsvMapper().readerFor(StockData.class).with(schema).readValues(file);
    return stockDataIterator.readAll();
}
 
Example #3
Source File: SocketAppenderTest.java    From logging-log4j2 with Apache License 2.0 6 votes vote down vote up
@Override
public void run() {
    try {
        try (final Socket socket = serverSocket.accept()) {
            if (socket != null) {
                final InputStream is = socket.getInputStream();
                while (!shutdown) {
                    final MappingIterator<LogEvent> mappingIterator = objectMapper.readerFor(Log4jLogEvent.class).readValues(is);
                    while (mappingIterator.hasNextValue()) {
                        queue.add(mappingIterator.nextValue());
                        ++count;
                    }
                }
            }
        }
    } catch (final EOFException eof) {
        // Socket is closed.
    } catch (final Exception e) {
        if (!shutdown) {
            Throwables.rethrow(e);
        }
    }
}
 
Example #4
Source File: PackageMetadataService.java    From spring-cloud-skipper with Apache License 2.0 6 votes vote down vote up
protected List<PackageMetadata> deserializeFromIndexFiles(List<File> indexFiles) {
	List<PackageMetadata> packageMetadataList = new ArrayList<>();
	YAMLMapper yamlMapper = new YAMLMapper();
	yamlMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
	for (File indexFile : indexFiles) {
		try {
			MappingIterator<PackageMetadata> it = yamlMapper.readerFor(PackageMetadata.class).readValues(indexFile);
			while (it.hasNextValue()) {
				PackageMetadata packageMetadata = it.next();
				packageMetadataList.add(packageMetadata);
			}
		}
		catch (IOException e) {
			throw new IllegalArgumentException("Can't parse Release manifest YAML", e);
		}
	}
	return packageMetadataList;
}
 
Example #5
Source File: TruckEventsCsvConverter.java    From registry with Apache License 2.0 6 votes vote down vote up
private MappingIterator<TruckEvent> readTruckEventsFromCsv(InputStream csvStream) throws IOException {
        CsvSchema bootstrap = CsvSchema.builder()
// driverId,truckId,eventTime,eventType,longitude,latitude,eventKey,correlationId,driverName,routeId,routeName,eventDate
                .addColumn("driverId", CsvSchema.ColumnType.NUMBER)
                .addColumn("truckId", CsvSchema.ColumnType.NUMBER)
                .addColumn("eventTime", CsvSchema.ColumnType.STRING)
                .addColumn("eventType", CsvSchema.ColumnType.STRING)
                .addColumn("longitude", CsvSchema.ColumnType.NUMBER)
                .addColumn("latitude", CsvSchema.ColumnType.NUMBER)
                .addColumn("eventKey", CsvSchema.ColumnType.STRING)
                .addColumn("correlationId", CsvSchema.ColumnType.NUMBER)
                .addColumn("driverName", CsvSchema.ColumnType.STRING)
                .addColumn("routeId", CsvSchema.ColumnType.NUMBER)
                .addColumn("routeName", CsvSchema.ColumnType.STRING)
                .addColumn("eventDate", CsvSchema.ColumnType.STRING)
//                .addColumn("miles", CsvSchema.ColumnType.NUMBER)
                .build().withHeader();

        CsvMapper csvMapper = new CsvMapper();
        return csvMapper.readerFor(TruckEvent.class).with(bootstrap).readValues(csvStream);
    }
 
Example #6
Source File: FilePipelineStateStore.java    From datacollector with Apache License 2.0 6 votes vote down vote up
@Override
public List<PipelineState> getHistory(String pipelineName, String rev, boolean fromBeginning) throws PipelineStoreException {
  if (!pipelineDirExists(pipelineName, rev) || !pipelineStateHistoryFileExists(pipelineName, rev)) {
    return Collections.emptyList();
  }
  try (Reader reader = new FileReader(getPipelineStateHistoryFile(pipelineName, rev))){
    ObjectMapper objectMapper = ObjectMapperFactory.get();
    JsonParser jsonParser = objectMapper.getFactory().createParser(reader);
    MappingIterator<PipelineStateJson> pipelineStateMappingIterator =
      objectMapper.readValues(jsonParser, PipelineStateJson.class);
    List<PipelineStateJson> pipelineStateJsons = pipelineStateMappingIterator.readAll();
    Collections.reverse(pipelineStateJsons);
    if (fromBeginning) {
      return BeanHelper.unwrapPipelineStatesNewAPI(pipelineStateJsons);
    } else {
      int toIndex = pipelineStateJsons.size() > 100 ? 100 : pipelineStateJsons.size();
      return BeanHelper.unwrapPipelineStatesNewAPI(pipelineStateJsons.subList(0, toIndex));
    }
  } catch (IOException e) {
    throw new PipelineStoreException(ContainerError.CONTAINER_0115, pipelineName, rev, e.toString(), e);
  }
}
 
Example #7
Source File: StreamControllerTests.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
private SpringCloudDeployerApplicationSpec parseSpec(String yamlString) throws IOException {
	YAMLMapper mapper = new YAMLMapper();
	mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
	MappingIterator<SpringCloudDeployerApplicationManifest> it = mapper
			.readerFor(SpringCloudDeployerApplicationManifest.class).readValues(yamlString);
	return it.next().getSpec();
}
 
Example #8
Source File: ApplicationReporter.java    From cf-butler with Apache License 2.0 5 votes vote down vote up
protected AppUsageReport readAppUsageReport(String filename) throws JsonParseException, JsonMappingException, IOException {
    String content = readFile(filename);
    if (filename.endsWith(".json")) {
        return mapper.readValue(content, AppUsageReport.class);
    } else if (filename.endsWith(".csv")) {
        CsvMapper csvMapper = new CsvMapper();
        csvMapper.enable(CsvParser.Feature.WRAP_AS_ARRAY);
        File csvFile = new File(filename);
        MappingIterator<String[]> it = csvMapper.readerFor(String[].class).readValues(csvFile);
        AppUsageReportBuilder builder = AppUsageReport.builder();
        List<AppUsageMonthly> reports = new ArrayList<>();
        int rowNum = 0;
        while (it.hasNext()) {
            String[] row = it.next();
            if (rowNum > 0) {
                AppUsageMonthlyBuilder amb = AppUsageMonthly.builder();
                for (int i = 0; i < row.length; i++) {
                    if (i == 0) {
                        String[] period = row[i].split("-");
                        if (period.length == 2) {
                            amb.month(Integer.valueOf(period[1]));
                        }
                        amb.year(Integer.valueOf(period[0]));
                    }
                    if (i == 1) {
                        amb.averageAppInstances(Double.valueOf(row[i]));
                    }
                    if (i == 2) {
                        amb.maximumAppInstances(Integer.valueOf(row[i]));
                    }
                    if (i == 3) {
                        amb.appInstanceHours(Double.valueOf(row[i]));
                    }
                }
                reports.add(amb.build());
            }
            rowNum++;
        }
        builder.monthlyReports(reports);
        return builder.build();
    } else {
        return AppUsageReport.builder().build();
    }
}
 
Example #9
Source File: DAOCSVRepair.java    From BART with MIT License 5 votes vote down vote up
public Map<String, Repair> loadRepairMap(String fileName) throws DAOException {
    Map<String, Repair> result = new HashMap<String, Repair>();
    try {
        BufferedReader reader = utility.getBufferedReader(fileName);
        MappingIterator<String[]> it = getMappingIterator(reader);
        while (it.hasNext()) {
            String[] tokens = it.next();
            if (tokens.length == 0 || tokens[0].startsWith("+++++++++++++++")) {
                continue;
            }
            String tid = tokens[0];
            String oldValue;
            String newValue;
            if (tokens.length == 2) {
                oldValue = null;
                newValue = tokens[1];
            } else if (tokens.length == 3) {
                oldValue = tokens[1];
                newValue = tokens[2];
            } else {
                throw new DAOException("Malformed file " + fileName + ".\nCSV file must contains at least two column (cell, newValue)");
            }
            Repair repair = new Repair(tid, oldValue, newValue);
            result.put(repair.getCellId(), repair);
        }
    } catch (IOException exception) {
        throw new DAOException("Unable to load file: " + fileName + "\n" + exception);
    }
    return result;
}
 
Example #10
Source File: SPARQLManagerTest.java    From java-client-api with Apache License 2.0 5 votes vote down vote up
@Test
public void testInference() throws Exception {
  gmgr.write("/ontology", new StringHandle(ontology).withMimetype("application/n-triples"));
  SPARQLQueryDefinition qdef = smgr.newQueryDefinition(
    "SELECT ?s { ?s a <http://example.org/C1>  }");
  qdef.setIncludeDefaultRulesets(false);
  StringHandle handle = new StringHandle().withMimetype(SPARQLMimeTypes.SPARQL_CSV);
  String results = smgr.executeSelect(qdef, handle).get();
  assertEquals("%0D%0A", URLEncoder.encode(results, "utf8"));

  qdef.setRulesets(SPARQLRuleset.RANGE);
  results = smgr.executeSelect(qdef, handle).get();
  assertEquals(1, countLines(parseCsv(results)));

  qdef.setRulesets(SPARQLRuleset.RANGE, SPARQLRuleset.DOMAIN);
  results = smgr.executeSelect(qdef, handle).get();
  MappingIterator<Map<String,String>> csvRows = parseCsv(results);
  assertTrue(csvRows.hasNext());
  Map<String,String> row = csvRows.next();
  assertEquals("http://example.org/o1", row.get("s"));
  assertTrue(csvRows.hasNext());
  row = csvRows.next();
  assertEquals("http://example.org/s2", row.get("s"));
  assertFalse(csvRows.hasNext());

  gmgr.delete("/ontology");
}
 
Example #11
Source File: SPARQLManagerTest.java    From java-client-api with Apache License 2.0 5 votes vote down vote up
private int countLines(MappingIterator<?> iter) {
  int numLines = 0;
  while (iter.hasNext()) {
    iter.next();
    numLines++;
  }
  return numLines;
}
 
Example #12
Source File: Defaults.java    From data-prep with Apache License 2.0 5 votes vote down vote up
public static <T, S> BiFunction<HttpRequestBase, HttpResponse, S> iterate(Class<T> clazz, ObjectMapper mapper,
        Function<Iterator<T>, S> convert) {
    return (request, response) -> {
        try (InputStream content = response.getEntity().getContent()) {
            try (MappingIterator<T> objects = mapper.readerFor(clazz).readValues(content)) {
                return convert.apply(objects);
            }
        } catch (Exception e) {
            throw new TDPException(CommonErrorCodes.UNEXPECTED_EXCEPTION, e);
        } finally {
            request.releaseConnection();
        }
    };
}
 
Example #13
Source File: APIClientTest.java    From data-prep with Apache License 2.0 5 votes vote down vote up
public Folder getFolderByPath(String path) throws IOException {
    InputStream inputStream = with().queryParam("path", path).get("/api/folders/search").asInputStream();
    MappingIterator<Folder> foldersIterator = mapper.readerFor(Folder.class).readValues(inputStream);
    List<Folder> folders = foldersIterator.readAll();
    assertTrue(folders.size() == 1);
    return folders.iterator().next();
}
 
Example #14
Source File: CSVStreamConnector.java    From syncope with Apache License 2.0 5 votes vote down vote up
public MappingIterator<Map<String, String>> reader() throws IOException {
    synchronized (this) {
        if (reader == null) {
            reader = new CsvMapper().
                    enable(CsvParser.Feature.SKIP_EMPTY_LINES).
                    readerFor(Map.class).with(schemaBuilder.build()).readValues(in);
        }
    }
    return reader;
}
 
Example #15
Source File: TCSV.java    From Llunatic with GNU General Public License v3.0 5 votes vote down vote up
public void test() throws IOException {
        CsvMapper mapper = new CsvMapper();
        mapper.enable(CsvParser.Feature.WRAP_AS_ARRAY);
        CsvSchema schema = CsvSchema.emptySchema();
//        schema = schema.withHeader();
//        schema = schema.withQuoteChar('\'');
//        File csvFile = new File("/Temp/llunatic/doctors/10k/doctor.csv");
        File csvFile = new File("/Users/donatello/Temp/chaseBench-workspace/LUBM/data/01k/src-emailAddress.csv");
        long start = new Date().getTime();
        MappingIterator<String[]> it = mapper.readerFor(String[].class).with(schema).readValues(csvFile);
        String[] row = it.next();
        System.out.println(Arrays.asList(row));
        long end = new Date().getTime();
        System.out.println("**** " + (end - start) + " ms");
//        while (it.hasNext()) {
//            String[] row = it.next();
//            System.out.println(Arrays.asList(row));
//        }
    }
 
Example #16
Source File: GitHubAuthFilter.java    From para with Apache License 2.0 5 votes vote down vote up
private String fetchUserEmail(Integer githubId, String accessToken) {
	HttpGet emailsGet = new HttpGet(PROFILE_URL + "/emails");
	emailsGet.setHeader(HttpHeaders.AUTHORIZATION, "token " + accessToken);
	emailsGet.setHeader(HttpHeaders.ACCEPT, "application/json");
	String defaultEmail = githubId + "@github.com";
	try (CloseableHttpResponse resp = httpclient.execute(emailsGet)) {
		HttpEntity respEntity = resp.getEntity();
		if (respEntity != null) {
			try (InputStream is = respEntity.getContent()) {
				MappingIterator<Map<String, Object>> emails = jreader.readValues(is);
				if (emails != null) {
					String email = null;
					while (emails.hasNext()) {
						Map<String, Object> next = emails.next();
						email = (String) next.get("email");
						if (next.containsKey("primary") && (Boolean) next.get("primary")) {
							break;
						}
					}
					return email;
				}
			}
			EntityUtils.consumeQuietly(respEntity);
		}
	} catch (IOException e) {
		logger.warn("Failed to fetch user email from GitHub, using default: " + defaultEmail);
	}
	return defaultEmail;
}
 
Example #17
Source File: DefaultInvocationBuilder.java    From docker-java with Apache License 2.0 5 votes vote down vote up
@Override
public void accept(DockerHttpClient.Response response) {
    try {
        InputStream body = response.getBody();
        MappingIterator<Object> iterator = objectMapper.readerFor(typeReference).readValues(body);
        while (iterator.hasNextValue()) {
            resultCallback.onNext((T) iterator.nextValue());
        }
    } catch (Exception e) {
        resultCallback.onError(e);
    }
}
 
Example #18
Source File: JsonSerialization.java    From Cardshifter with Apache License 2.0 5 votes vote down vote up
@Override
public void read(InputStream in, MessageHandler onReceived) throws CardshifterSerializationException {
       try {
           MappingIterator<Message> values;
           values = mapper.readValues(new JsonFactory().createParser(in), Message.class);
           while (values.hasNextValue()) {
               Message message = values.next();
               if (!onReceived.messageReceived(message)) {
                   return;
               }
           }
       } catch (IOException ex) {
           throw new CardshifterSerializationException(ex);
       }
}
 
Example #19
Source File: TestClient.java    From Cardshifter with Apache License 2.0 5 votes vote down vote up
private void listen() {
	try {
		MappingIterator<Message> values = mapper.readValues(new JsonFactory().createParser(in), Message.class);
		while (values.hasNext()) {
			Message msg = values.next();
			System.out.println("Incoming message " + msg);
			messages.offer(msg);
		}
	} catch (IOException e) {
		e.printStackTrace();
	}
	
}
 
Example #20
Source File: JsonCsvConverter.java    From tutorials with MIT License 5 votes vote down vote up
public static void csvToJson(File csvFile, File jsonFile) throws IOException {
    CsvSchema orderLineSchema = CsvSchema.emptySchema().withHeader();
    CsvMapper csvMapper = new CsvMapper();
    MappingIterator<OrderLine> orderLines = csvMapper.readerFor(OrderLine.class)
        .with(orderLineSchema)
        .readValues(csvFile);
    
    new ObjectMapper()
        .configure(SerializationFeature.INDENT_OUTPUT, true)
        .writeValue(jsonFile, orderLines.readAll());
}
 
Example #21
Source File: CSVLineParser.java    From crate with Apache License 2.0 5 votes vote down vote up
public void parseHeader(String header) throws IOException {
    MappingIterator<String> iterator = csvReader.readValues(header.getBytes(StandardCharsets.UTF_8));
    iterator.readAll(keyList);
    HashSet<String> keySet = new HashSet<>(keyList);
    keySet.remove("");
    if (keySet.size() != keyList.size() || keySet.size() == 0) {
        throw new IllegalArgumentException("Invalid header: duplicate entries or no entries present");
    }
}
 
Example #22
Source File: CSVLineParser.java    From crate with Apache License 2.0 5 votes vote down vote up
public byte[] parse(String row) throws IOException {
    MappingIterator<Object> iterator = csvReader.readValues(row.getBytes(StandardCharsets.UTF_8));
    out.reset();
    XContentBuilder jsonBuilder = new XContentBuilder(JsonXContent.JSON_XCONTENT, out).startObject();
    int i = 0;
    while (iterator.hasNext()) {
        if (i >= keyList.size()) {
            throw new IllegalArgumentException("Number of values exceeds number of keys");
        }
        jsonBuilder.field(keyList.get(i), iterator.next());
        i++;
    }
    jsonBuilder.endObject().close();
    return out.toByteArray();
}
 
Example #23
Source File: JsonTemplateLayoutTest.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
    try {
        try (final Socket socket = serverSocket.accept()) {
            final InputStream inputStream = socket.getInputStream();
            while (!closed) {
                final MappingIterator<JsonNode> iterator = JacksonFixture
                        .getObjectMapper()
                        .readerFor(JsonNode.class)
                        .readValues(inputStream);
                while (iterator.hasNextValue()) {
                    final JsonNode value = iterator.nextValue();
                    synchronized (this) {
                        final boolean added = receivedNodes.offer(value);
                        if (!added) {
                            droppedNodeCount++;
                        }
                    }
                }
            }
        }
    } catch (final EOFException ignored) {
        // Socket is closed.
    } catch (final Exception error) {
        if (!closed) {
            throw new RuntimeException(error);
        }
    }
}
 
Example #24
Source File: MappingEventReader.java    From fahrschein with Apache License 2.0 5 votes vote down vote up
@Override
public List<T> read(JsonParser jsonParser) throws IOException {
    expectToken(jsonParser, JsonToken.START_ARRAY);
    jsonParser.clearCurrentToken();

    final MappingIterator<T> eventIterator = eventReader.readValues(jsonParser);

    final List<T> events = new ArrayList<>();
    while (true) {
        try {
            // MappingIterator#hasNext can theoretically also throw RuntimeExceptions, that's why we use this strange loop structure
            if (eventIterator.hasNext()) {
                events.add(eventClass.cast(eventIterator.next()));
            } else {
                break;
            }
        } catch (RuntimeException e) {
            final Throwable cause = e.getCause();
            if (cause instanceof JsonMappingException) {
                onMappingException((JsonMappingException) cause);
            } else if (cause instanceof IOException) {
                throw (IOException)cause;
            } else {
                throw e;
            }
        }
    }
    return events;

}
 
Example #25
Source File: TruckEventsCsvConverter.java    From registry with Apache License 2.0 5 votes vote down vote up
public void convertToJsonRecords(String payloadFile, String outputFileName) throws IOException {
    try (InputStream csvStream = new FileInputStream(payloadFile);
         FileWriter fos = new FileWriter(outputFileName)) {
        MappingIterator<TruckEvent> csvTruckEvents = readTruckEventsFromCsv(csvStream);
        for (TruckEvent truckEvent : csvTruckEvents.readAll()) {
            truckEvent.setMiles((long) new Random().nextInt(500));
            String output = new ObjectMapper().writeValueAsString(truckEvent);
            fos.write(output);
            fos.write(System.lineSeparator());
        }
    }
}
 
Example #26
Source File: CsvReader.java    From graphql-java-demo with MIT License 5 votes vote down vote up
public static <T> List<T> loadObjectList(Class<T> type, String fileName) throws IOException {
    CsvSchema bootstrapSchema = CsvSchema.emptySchema().withHeader();

    CsvMapper mapper = new CsvMapper();
    InputStream is = new ClassPathResource(fileName).getInputStream();
    MappingIterator<T> readValues = mapper.readerFor(type).with(bootstrapSchema).readValues(is);
    return readValues.readAll();
}
 
Example #27
Source File: TruckEventsCsvConverter.java    From registry with Apache License 2.0 5 votes vote down vote up
public List<String> convertToJsonRecords(InputStream payloadStream, int limit) throws Exception {
    MappingIterator<TruckEvent> csvTruckEvents = readTruckEventsFromCsv(payloadStream);
    List<String> jsons = new ArrayList<>();
    int ct = 0;
    for (TruckEvent truckEvent : csvTruckEvents.readAll()) {
        truckEvent.setMiles((long) new Random().nextInt(500));
        String json = new ObjectMapper().writeValueAsString(truckEvent);
        jsons.add(json);
        if (++ct == limit) {
            break;
        }
    }

    return jsons;
}
 
Example #28
Source File: Funktions.java    From funktion-connectors with Apache License 2.0 5 votes vote down vote up
static <T> List<T> parseYamlValues(File file, Class<T> clazz) throws IOException {
    ObjectMapper mapper = createObjectMapper();
    MappingIterator<T> iter = mapper.readerFor(clazz).readValues(file);
    List<T> answer = new ArrayList<>();
    while (iter.hasNext()) {
        answer.add(iter.next());
    }
    return answer;
}
 
Example #29
Source File: InventoryReportLineMapper.java    From s3-inventory-usage-examples with Apache License 2.0 5 votes vote down vote up
/**
 * Map each line of the inventory report into a POJO
 * @return List<InventoryReportLine> which is a list of POJOs
 * @throws IOException when mapping with schema fails
 */
public List<InventoryReportLine> mapInventoryReportLine(List<String> inventoryReportLine) throws IOException{
    CsvMapper mapper = new CsvMapper();
    List<InventoryReportLine> inventoryReportLines = new ArrayList();

    for (String eachLine : inventoryReportLine) {
        MappingIterator<InventoryReportLine> iterator =
                mapper.readerFor(InventoryReportLine.class).with(schema).readValues(eachLine);
        List<InventoryReportLine> rowValue = iterator.readAll();
        inventoryReportLines.add(rowValue.get(0));
    }
    return inventoryReportLines;
}
 
Example #30
Source File: NodeDtos.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
protected static <T> List<T> toList(MappingIterator<T> iter) throws java.io.IOException {
    List<T> answer = new ArrayList<>();
    while (iter != null && iter.hasNextValue()) {
        T value = iter.nextValue();
        answer.add(value);
    }
    return answer;
}