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()); }
@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); } }
@SuppressWarnings("deprecation") private void fill0(FloatOption option, boolean doRecover) throws CsvFormatException { if (lineBuffer.hasRemaining()) { try { float value = Float.parseFloat(lineBuffer.toString()); option.modify(value); } catch (NumberFormatException e) { if (doRecover && trimWhitespaces()) { fill0(option, false); return; } throw new CsvFormatException(createStatusInLine(Reason.INVALID_CELL_FORMAT, "float value"), e); } } else { option.setNull(); } }
@SuppressWarnings("deprecation") private void fill0(ShortOption option, boolean doRecover) throws CsvFormatException { if (lineBuffer.hasRemaining()) { try { short value = Short.parseShort(lineBuffer.toString()); option.modify(value); } catch (NumberFormatException e) { if (doRecover && trimWhitespaces()) { fill0(option, false); return; } throw new CsvFormatException(createStatusInLine(Reason.INVALID_CELL_FORMAT, "short value"), e); } } else { option.setNull(); } }
@SuppressWarnings("deprecation") private void fill0(LongOption option, boolean doRecover) throws CsvFormatException { if (lineBuffer.hasRemaining()) { try { long value = Long.parseLong(lineBuffer.toString()); option.modify(value); } catch (NumberFormatException e) { if (doRecover && trimWhitespaces()) { fill0(option, false); return; } throw new CsvFormatException(createStatusInLine(Reason.INVALID_CELL_FORMAT, "long value"), e); } } else { option.setNull(); } }
@SuppressWarnings("deprecation") private void fill0(ByteOption option, boolean doRecover) throws CsvFormatException { if (lineBuffer.hasRemaining()) { try { byte value = Byte.parseByte(lineBuffer.toString()); option.modify(value); } catch (NumberFormatException e) { if (doRecover && trimWhitespaces()) { fill0(option, false); return; } throw new CsvFormatException(createStatusInLine(Reason.INVALID_CELL_FORMAT, "byte value"), e); } } else { option.setNull(); } }
@SuppressWarnings("deprecation") private void fill0(IntOption option, boolean doRecover) throws CsvFormatException { if (lineBuffer.hasRemaining()) { try { int value = Integer.parseInt(lineBuffer.toString()); option.modify(value); } catch (NumberFormatException e) { if (doRecover && trimWhitespaces()) { fill0(option, false); return; } throw new CsvFormatException(createStatusInLine(Reason.INVALID_CELL_FORMAT, "int value"), e); } } else { option.setNull(); } }
@SuppressWarnings("deprecation") private void fill0(DoubleOption option, boolean doRecover) throws CsvFormatException { if (lineBuffer.hasRemaining()) { try { double value = Double.parseDouble(lineBuffer.toString()); option.modify(value); } catch (NumberFormatException e) { if (doRecover && trimWhitespaces()) { fill0(option, false); return; } throw new CsvFormatException(createStatusInLine(Reason.INVALID_CELL_FORMAT, "double value"), e); } } else { option.setNull(); } }
@SuppressWarnings("deprecation") private void fill0(DecimalOption option, boolean doRecover) throws CsvFormatException { if (lineBuffer.hasRemaining()) { try { BigDecimal value = toBigDecimal(); option.modify(value); } catch (NumberFormatException e) { if (doRecover && trimWhitespaces()) { fill0(option, false); return; } throw new CsvFormatException(createStatusInLine(Reason.INVALID_CELL_FORMAT, "decimal value"), e); } } else { option.setNull(); } }
@SuppressWarnings("deprecation") private void fill0(DateTimeOption option, boolean doRecover) throws CsvFormatException { if (lineBuffer.hasRemaining()) { long value = dateTimeFormat.parse(lineBuffer); if (value < 0) { if (doRecover && trimWhitespaces()) { fill0(option, false); return; } throw new CsvFormatException( createStatusInLine(Reason.INVALID_CELL_FORMAT, dateTimeFormat.getPattern()), null); } option.modify(value); } else { option.setNull(); } }
@SuppressWarnings("deprecation") private void fill0(DateOption option, boolean doRecover) throws CsvFormatException { if (lineBuffer.hasRemaining()) { int value = dateFormat.parse(lineBuffer); if (value < 0) { if (doRecover && trimWhitespaces()) { fill0(option, false); return; } throw new CsvFormatException( createStatusInLine(Reason.INVALID_CELL_FORMAT, dateFormat.getPattern()), null); } option.modify(value); } else { option.setNull(); } }
@Override public boolean next() throws CsvFormatException, IOException { exceptionStatus = null; currentRecordNumber++; if (firstLine) { firstLine = false; decodeLine(); if (isEof()) { return false; } if (isHeader()) { decodeLine(); } } else { decodeLine(); } if (exceptionStatus != null) { throw new CsvFormatException(exceptionStatus, null); } return isEof() == false; }