当前位置: 首页>>代码示例>>Java>>正文


Java CSVFormat.withQuote方法代码示例

本文整理汇总了Java中org.apache.commons.csv.CSVFormat.withQuote方法的典型用法代码示例。如果您正苦于以下问题:Java CSVFormat.withQuote方法的具体用法?Java CSVFormat.withQuote怎么用?Java CSVFormat.withQuote使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.csv.CSVFormat的用法示例。


在下文中一共展示了CSVFormat.withQuote方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getActiveFormat

import org.apache.commons.csv.CSVFormat; //导入方法依赖的package包/类
CSVFormat getActiveFormat() {
    CSVFormat answer = format;

    if (commentMarkerDisabled) {
        answer = answer.withCommentMarker(null); // null disables the comment marker
    } else if (commentMarker != null) {
        answer = answer.withCommentMarker(commentMarker);
    }

    if (delimiter != null) {
        answer = answer.withDelimiter(delimiter);
    }

    if (escapeDisabled) {
        answer = answer.withEscape(null); // null disables the escape
    } else if (escape != null) {
        answer = answer.withEscape(escape);
    }

    if (headerDisabled) {
        answer = answer.withHeader((String[]) null); // null disables the header
    } else if (header != null) {
        answer = answer.withHeader(header);
    }

    if (allowMissingColumnNames != null) {
        answer = answer.withAllowMissingColumnNames(allowMissingColumnNames);
    }

    if (ignoreEmptyLines != null) {
        answer = answer.withIgnoreEmptyLines(ignoreEmptyLines);
    }

    if (ignoreSurroundingSpaces != null) {
        answer = answer.withIgnoreSurroundingSpaces(ignoreSurroundingSpaces);
    }

    if (nullStringDisabled) {
        answer = answer.withNullString(null); // null disables the null string replacement
    } else if (nullString != null) {
        answer = answer.withNullString(nullString);
    }

    if (quoteDisabled) {
        answer = answer.withQuote(null); // null disables quotes
    } else if (quote != null) {
        answer = answer.withQuote(quote);
    }

    if (quoteMode != null) {
        answer = answer.withQuoteMode(quoteMode);
    }

    if (recordSeparatorDisabled) {
        answer = answer.withRecordSeparator(null); // null disables the record separator
    } else if (recordSeparator != null) {
        answer = answer.withRecordSeparator(recordSeparator);
    }

    if (skipHeaderRecord != null) {
        answer = answer.withSkipHeaderRecord(skipHeaderRecord);
    }

    return answer;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:66,代码来源:CsvDataFormat.java

示例2: getParser

import org.apache.commons.csv.CSVFormat; //导入方法依赖的package包/类
/**
 * Ritorna il parser costruito secondo i parametri passati per leggere il
 * file
 *
 * @param fileName nome del file da parsare
 * @param delimiter delimitatore delle colonne
 * @param quoting carattere di quoting
 * @param escape carattere di escaping
 * @param lineSeparator separatore di righe
 * @param charset charset UTF o ISO
 * @return Parser per il file CSV
 */
public static CSVParser getParser(String fileName, String delimiter, String quoting, String escape, String lineSeparator, String charset) {
    File csvData = new File(fileName);
    if (!csvData.exists()) {
        int pos = fileName.replace('\\', '/').lastIndexOf('/');
        if (pos != -1) {
            fileName = fileName.substring(pos + 1);
            csvData = new File("./" + fileName);
        }
    }
    if (csvData.exists()) {
        try {

            CSVFormat format;
            if (delimiter != null && delimiter.length() > 0) {
                if (delimiter.length() == 2 && delimiter.startsWith("\\")) {
                    if ("\\t".equalsIgnoreCase(delimiter)) {
                        format = CSVFormat.newFormat('\t');
                    } else {
                        format = CSVFormat.newFormat(delimiter.charAt(0));
                    }
                } else {
                    format = CSVFormat.newFormat(delimiter.charAt(0));
                }
            } else {
                format = CSVFormat.newFormat(CSVFormat.DEFAULT.getDelimiter());
            }
            if (quoting != null && quoting.length() > 0) {
                format = format.withQuote(quoting.charAt(0));
            }
            if (escape != null && escape.length() > 0) {
                format = format.withEscape(escape.charAt(0));
            }
            if (lineSeparator != null && lineSeparator.length() > 0) {
                format = format.withRecordSeparator(lineSeparator);
            }
            return CSVParser.parse(csvData, Charset.forName(charset), format);
        } catch (Exception e) {
            LogGui.printException(e);
        }
    }
    return null;
}
 
开发者ID:fiohol,项目名称:theSemProject,代码行数:55,代码来源:CSVFileParser.java


注:本文中的org.apache.commons.csv.CSVFormat.withQuote方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。