ImportData is the LineProcessor that reads in the row data in a Table file. Each entry must conform to the format defined in the format row of the Table. There may not be more columns in a data row than there were formats.
| 367 | * formats. |
| 368 | */ |
| 369 | private static class ImportData implements LineProcessor |
| 370 | { |
| 371 | |
| 372 | /** |
| 373 | * The underlying Table to which the data will be loaded. |
| 374 | */ |
| 375 | private final DataTable t; |
| 376 | |
| 377 | /** |
| 378 | * Constructs a new ImportData with the given underlying Table. |
| 379 | * |
| 380 | * @param table |
| 381 | * The underlying Table to which the data will be loaded |
| 382 | */ |
| 383 | public ImportData(DataTable table) |
| 384 | { |
| 385 | t = table; |
| 386 | } |
| 387 | |
| 388 | @Override |
| 389 | public LineProcessor parseLine(LoadContext context, String lstLine, URI sourceURI) |
| 390 | throws PersistenceLayerException |
| 391 | { |
| 392 | ParsingSeparator ps = generateCSVSeparator(lstLine); |
| 393 | int i = 0; |
| 394 | List<Object> rowContents = new ArrayList<>(); |
| 395 | while (ps.hasNext()) |
| 396 | { |
| 397 | String content = unescape(ps.next()); |
| 398 | if (i == 0) |
| 399 | { |
| 400 | if (content.startsWith("STARTTABLE:")) |
| 401 | { |
| 402 | throw new PersistenceLayerException( |
| 403 | "Encountered STARTTABLE: entry before reaching ENDTABLE for " + t.getDisplayName() + " in " |
| 404 | + sourceURI); |
| 405 | } |
| 406 | if (content.startsWith("ENDTABLE:")) |
| 407 | { |
| 408 | ensureEmpty(lstLine, ps); |
| 409 | if (t.getRowCount() == 0) |
| 410 | { |
| 411 | throw new PersistenceLayerException( |
| 412 | "Table " + t.getDisplayName() + " had no data in " + sourceURI); |
| 413 | } |
| 414 | t.trim(); |
| 415 | return new ExpectStartTable(); |
| 416 | } |
| 417 | } |
| 418 | rowContents.add(t.getFormat(i++).convert(content)); |
| 419 | } |
| 420 | t.addRow(rowContents); |
| 421 | return this; |
| 422 | } |
| 423 | } |
| 424 | } |
nothing calls this directly
no outgoing calls
no test coverage detected