@Override public void endRecord() throws CsvFormatException, IOException { if (cellBeginPositions.remaining() > 1) { seekBuffer(); throw new CsvFormatException(new Status( Reason.TOO_LONG_RECORD, path, currentPhysicalHeadLine, currentRecordNumber, cellBeginPositions.position(), CHAR_END_OF_RECORD, lineBuffer.toString()), null); } }
private void warn(Status status) { assert status != null; LOG.warn(status.toString()); }
fail(); } catch (CsvFormatException e) { assertThat(e.getStatus().getReason(), is(Reason.UNEXPECTED_EOF));
fail(); } catch (CsvFormatException e) { assertThat(e.getStatus().getReason(), is(Reason.UNEXPECTED_EOF));
/** * record is too short. * @throws Exception if failed */ @Test public void too_short_record() throws Exception { CsvParser parser = create("a,b,c"); assertThat(parser.next(), is(true)); try { assertFill(parser, "a"); assertFill(parser, "b"); assertFill(parser, "c"); parser.fill(new StringOption()); parser.endRecord(); fail(); } catch (CsvFormatException e) { assertThat(e.getStatus().getReason(), is(Reason.TOO_SHORT_RECORD)); } assertThat(parser.next(), is(false)); }
/** * record is too long. * @throws Exception if failed */ @Test public void too_long_record() throws Exception { CsvParser parser = create("a,b,c"); assertThat(parser.next(), is(true)); try { assertFill(parser, "a"); assertFill(parser, "b"); parser.endRecord(); fail(); } catch (CsvFormatException e) { assertThat(e.getStatus().getReason(), is(Reason.TOO_LONG_RECORD)); } assertThat(parser.next(), is(false)); }
/** * test for invalid date values. * @throws Exception if failed */ @Test public void invalid_date() throws Exception { CsvParser parser = create(String.valueOf("?")); assertThat(parser.next(), is(true)); try { parser.fill(new DateOption()); fail(); } catch (CsvFormatException e) { assertThat(e.getStatus().getReason(), is(Reason.INVALID_CELL_FORMAT)); } }
/** * test for invalid double values. * @throws Exception if failed */ @Test public void invalid_double() throws Exception { CsvParser parser = create(String.valueOf("?")); assertThat(parser.next(), is(true)); try { parser.fill(new DoubleOption()); fail(); } catch (CsvFormatException e) { assertThat(e.getStatus().getReason(), is(Reason.INVALID_CELL_FORMAT)); } }
/** * test for invalid bytes. * @throws Exception if failed */ @Test public void invalid_byte() throws Exception { CsvParser parser = create(String.valueOf(Byte.MAX_VALUE + 1)); assertThat(parser.next(), is(true)); try { parser.fill(new ByteOption()); fail(); } catch (CsvFormatException e) { assertThat(e.getStatus().getReason(), is(Reason.INVALID_CELL_FORMAT)); } }
/** * test for invalid datetime values. * @throws Exception if failed */ @Test public void invalid_datetime() throws Exception { CsvParser parser = create(String.valueOf("?")); assertThat(parser.next(), is(true)); try { parser.fill(new DateTimeOption()); fail(); } catch (CsvFormatException e) { assertThat(e.getStatus().getReason(), is(Reason.INVALID_CELL_FORMAT)); } }
/** * test for invalid long values. * @throws Exception if failed */ @Test public void invalid_long() throws Exception { CsvParser parser = create(String.valueOf(Long.MAX_VALUE + "0")); assertThat(parser.next(), is(true)); try { parser.fill(new LongOption()); fail(); } catch (CsvFormatException e) { assertThat(e.getStatus().getReason(), is(Reason.INVALID_CELL_FORMAT)); } }
/** * test for invalid float values. * @throws Exception if failed */ @Test public void invalid_float() throws Exception { CsvParser parser = create(String.valueOf("?")); assertThat(parser.next(), is(true)); try { parser.fill(new FloatOption()); fail(); } catch (CsvFormatException e) { assertThat(e.getStatus().getReason(), is(Reason.INVALID_CELL_FORMAT)); } }
/** * test for invalid short values. * @throws Exception if failed */ @Test public void invalid_short() throws Exception { CsvParser parser = create(String.valueOf(Short.MAX_VALUE + 1)); assertThat(parser.next(), is(true)); try { parser.fill(new ShortOption()); fail(); } catch (CsvFormatException e) { assertThat(e.getStatus().getReason(), is(Reason.INVALID_CELL_FORMAT)); } }
private void seekBuffer() throws CsvFormatException { if (cellBeginPositions.remaining() < 2) { throw new CsvFormatException(new Status( Reason.TOO_SHORT_RECORD, path, currentPhysicalHeadLine, currentRecordNumber, cellBeginPositions.position() + 1, "more cells", "no more cells"), null); } lineBuffer.limit(cellBeginPositions.get(cellBeginPositions.position() + 1)); lineBuffer.position(cellBeginPositions.get()); }
/** * test for invalid decimal values. * @throws Exception if failed */ @Test public void invalid_decimal() throws Exception { CsvParser parser = create(String.valueOf("?")); assertThat(parser.next(), is(true)); try { parser.fill(new DecimalOption()); fail(); } catch (CsvFormatException e) { assertThat(e.getStatus().getReason(), is(Reason.INVALID_CELL_FORMAT)); } }
/** * test for invalid int values. * @throws Exception if failed */ @Test public void invalid_int() throws Exception { CsvParser parser = create(String.valueOf((long) Integer.MAX_VALUE + 1)); assertThat(parser.next(), is(true)); try { parser.fill(new IntOption()); fail(); } catch (CsvFormatException e) { assertThat(e.getStatus().getReason(), is(Reason.INVALID_CELL_FORMAT)); } }
private Status createStatusInDecode(Reason reason, String expected, String actual) { assert reason != null; return new Status( reason, path, currentPhysicalLine, currentRecordNumber, cellBeginPositions.limit(), expected, actual); }
private static String toMessage(Status status) { if (status == null) { throw new IllegalArgumentException("status must not be null"); //$NON-NLS-1$ } return status.toString(); }
private Status createStatusInLine(Reason reason, String expected) { return new Status( reason, path, currentPhysicalHeadLine, currentRecordNumber, cellBeginPositions.position(), expected, lineBuffer.toString()); }
@Override public String toString() { return MessageFormat.format( "{0} (at {1}:{2}, record={3}, column={4}, expected={5}, actual={6})", //$NON-NLS-1$ getReason(), getPath(), getLineNumber(), getRecordNumber(), getColumnNumber(), getExpected(), getActual()); } }