@Override String getPattern() { return next.getPattern(); }
@Override long parse(CharSequence sequence) { long value = DateUtil.parseDateTime( sequence, dateSegmentSeparator, dateTimeSeparator, timeSegmentSeparator); if (value >= 0) { return value; } return next.parse(sequence); }
@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(); } }
/** * Creates a new instance. * @param stream the target stream * @param path the destination path * @param config current configuration * @throws IllegalArgumentException if some parameters were {@code null} */ public CsvEmitter(OutputStream stream, String path, CsvConfiguration config) { if (stream == null) { throw new IllegalArgumentException("stream must not be null"); //$NON-NLS-1$ } if (config == null) { throw new IllegalArgumentException("config must not be null"); //$NON-NLS-1$ } this.writer = new OutputStreamWriter(stream, config.getCharset()); this.separator = config.getSeparatorChar(); this.escapePattern = Pattern.compile( "[" + ESCAPE + separator + LINE_DELIMITER + "]"); //$NON-NLS-1$ //$NON-NLS-2$ this.trueFormat = escape(config.getTrueFormat()); this.escapeTrue = hasEscapeTarget(config.getTrueFormat()); this.falseFormat = escape(config.getFalseFormat()); this.escapeFalse = hasEscapeTarget(config.getFalseFormat()); this.dateFormat = DateFormatter.newInstance(config.getDateFormat()); this.escapeDate = hasMetaCharacter(dateFormat.getPattern()); this.dateTimeFormat = DateTimeFormatter.newInstance(config.getDateTimeFormat()); this.escapeDateTime = hasMetaCharacter(dateTimeFormat.getPattern()); this.headerCellsFormat = config.getHeaderCells(); this.forceEscapeMask = buildQuoteMask(config.getForceQuoteColumns()); this.columnIndex = 0; }
@Override public void emit(DateTimeOption option) throws IOException { addCellDelimiter(); if (option.isNull() == false) { CharSequence string = dateTimeFormat.format(option.get().getElapsedSeconds()); if (escapeDateTime || isEscapeTarget()) { appendEscaped(lineBuffer, string); } else { lineBuffer.append(string); } } }
/** * Creates a new instance. * @param stream the source stream * @param path the source path * @param config current configuration * @throws IllegalArgumentException if some parameters were {@code null} */ public CsvParser(InputStream stream, String path, CsvConfiguration config) { if (stream == null) { throw new IllegalArgumentException("stream must not be null"); //$NON-NLS-1$ } if (config == null) { throw new IllegalArgumentException("config must not be null"); //$NON-NLS-1$ } this.reader = new InputStreamReader(stream, config.getCharset()); this.path = path; this.separator = config.getSeparatorChar(); this.trueFormat = config.getTrueFormat(); this.dateFormat = DateFormatter.newInstance(config.getDateFormat()); this.dateTimeFormat = DateTimeFormatter.newInstance(config.getDateTimeFormat()); this.headerCellsFormat = config.getHeaderCells(); this.forceConsumeHeader = config.isForceConsumeHeader(); this.allowLineBreakInValue = config.isLineBreakInValue(); readerBuffer.clear(); readerBuffer.flip(); }
@Override long parse(CharSequence sequence) { if (sequence.length() != LENGTH) { return next.parse(sequence); } int year = getNumericValue(sequence, POS_YEAR, 4); int month = getNumericValue(sequence, POS_MONTH, 2); int day = getNumericValue(sequence, POS_DAY, 2); int hour = getNumericValue(sequence, POS_HOUR, 2); int minute = getNumericValue(sequence, POS_MINUTE, 2); int second = getNumericValue(sequence, POS_SECOND, 2); if (year < 0 || month < 0 || day < 0 || hour < 0 || minute < 0 || second < 0) { return next.parse(sequence); } int date = DateUtil.getDayFromDate(year, month, day); int secondsInDay = DateUtil.getSecondFromTime(hour, minute, second); return (long) date * 86400 + secondsInDay; } }
@Override String getPattern() { return next.getPattern(); }