Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*******************************************************************************
* Copyright 2015 Univocity Software Pty Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
package com.univocity.parsers.csv;
import com.univocity.parsers.common.*;
import com.univocity.parsers.common.input.*;
import java.util.*;
import java.util.Map.*;
/**
* An {@link InputAnalysisProcess} to detect column delimiters, quotes and quote escapes in a CSV input.
*
* @author Univocity Software Pty Ltd - [email protected]
*/
public abstract class CsvFormatDetector implements InputAnalysisProcess {
private final int MAX_ROW_SAMPLES;
private final char comment;
private final char suggestedDelimiter;
private final char normalizedNewLine;
private final int whitespaceRangeStart;
private char[] allowedDelimiters;
private char[] delimiterPreference;
/**
* Builds a new {@code CsvFormatDetector}
*
* @param maxRowSamples the number of row samples to collect before analyzing the statistics
* @param settings the configuration provided by the user with potential defaults in case the detection is unable to discover the proper column
* delimiter or quote character.
* @param whitespaceRangeStart starting range of characters considered to be whitespace.
*/
CsvFormatDetector(int maxRowSamples, CsvParserSettings settings, int whitespaceRangeStart) {
this.MAX_ROW_SAMPLES = maxRowSamples;
this.whitespaceRangeStart = whitespaceRangeStart;
allowedDelimiters = settings.getDelimitersForDetection();
if (allowedDelimiters != null && allowedDelimiters.length > 0) {
suggestedDelimiter = allowedDelimiters[0];
delimiterPreference = allowedDelimiters.clone();
Arrays.sort(allowedDelimiters);
} else {
String delimiter = settings.getFormat().getDelimiterString();
suggestedDelimiter = delimiter.length() > 1 ? ',' : settings.getFormat().getDelimiter();
allowedDelimiters = new char[0];
delimiterPreference = allowedDelimiters;
}
normalizedNewLine = settings.getFormat().getNormalizedNewline();
comment = settings.getFormat().getComment();
}
private Map calculateTotals(List