/** * 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; }