Class CsvConfig

java.lang.Object
cloud.opencode.base.csv.CsvConfig

public final class CsvConfig extends Object
CSV Configuration - Immutable configuration for CSV parsing and writing CSV配置 - CSV解析和写入的不可变配置

Holds all parameters that control CSV processing behavior, including delimiters, quoting, character set, size limits, and security options. All instances are immutable and thread-safe.

持有控制CSV处理行为的所有参数,包括分隔符、引用、字符集、大小限制和安全选项。 所有实例都是不可变且线程安全的。

Features | 主要功能:

  • RFC 4180 defaults - RFC 4180 默认值
  • Builder pattern for fluent construction - Builder模式流式构建
  • Configurable size limits for DoS protection - 可配置大小限制防止DoS
  • Formula injection protection toggle - 公式注入保护开关

Usage Examples | 使用示例:

// Use defaults
CsvConfig config = CsvConfig.DEFAULT;

// Custom config
CsvConfig config = CsvConfig.builder()
    .delimiter(';')
    .charset(StandardCharsets.ISO_8859_1)
    .trimFields(true)
    .formulaProtection(true)
    .build();

Security | 安全性:

  • Thread-safe: Yes (immutable) - 线程安全: 是(不可变)
  • Null-safe: Yes (constructor validates) - 空值安全: 是(构造时校验)
Since:
JDK 25, opencode-base-csv V1.0.3
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final class 
    Builder for CsvConfig CsvConfig构建器
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final CsvConfig
    Default configuration instance with RFC 4180 settings 使用RFC 4180设置的默认配置实例
    static final char
    Default delimiter: comma per RFC 4180 | 默认分隔符:逗号(RFC 4180)
    static final char
    Default escape character: double quote per RFC 4180 | 默认转义字符:双引号(RFC 4180)
    static final String
    Default line separator: CRLF per RFC 4180 | 默认行分隔符:CRLF(RFC 4180)
    static final int
    Default max columns | 默认最大列数
    static final int
    Default max field size: 1 MB | 默认最大字段大小:1 MB
    static final int
    Default max rows | 默认最大行数
    static final char
    Default quote character: double quote per RFC 4180 | 默认引用字符:双引号(RFC 4180)
  • Method Summary

    Modifier and Type
    Method
    Description
    Creates a new builder 创建新的构建器
    Gets the character set 获取字符集
    char
    Gets the field delimiter character 获取字段分隔符字符
    boolean
     
    char
    Gets the escape character 获取转义字符
    boolean
    Returns whether formula injection protection is enabled 返回是否启用公式注入保护
    int
     
    boolean
    Returns whether the CSV has a header row 返回CSV是否有标题行
    Gets the line separator 获取行分隔符
    int
    Gets the maximum number of columns allowed 获取允许的最大列数
    int
    Gets the maximum field size in bytes 获取最大字段大小(字节)
    int
    Gets the maximum number of rows allowed 获取允许的最大行数
    Gets the string to write for null values 获取null值的写入字符串
    char
    Gets the quote character 获取引用字符
    boolean
    Returns whether empty rows should be skipped 返回是否应跳过空行
     
    boolean
    Returns whether fields should be trimmed 返回字段是否应被修剪

    Methods inherited from class Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • DEFAULT_DELIMITER

      public static final char DEFAULT_DELIMITER
      Default delimiter: comma per RFC 4180 | 默认分隔符:逗号(RFC 4180)
      See Also:
    • DEFAULT_QUOTE_CHAR

      public static final char DEFAULT_QUOTE_CHAR
      Default quote character: double quote per RFC 4180 | 默认引用字符:双引号(RFC 4180)
      See Also:
    • DEFAULT_ESCAPE_CHAR

      public static final char DEFAULT_ESCAPE_CHAR
      Default escape character: double quote per RFC 4180 | 默认转义字符:双引号(RFC 4180)
      See Also:
    • DEFAULT_LINE_SEPARATOR

      public static final String DEFAULT_LINE_SEPARATOR
      Default line separator: CRLF per RFC 4180 | 默认行分隔符:CRLF(RFC 4180)
      See Also:
    • DEFAULT_MAX_ROWS

      public static final int DEFAULT_MAX_ROWS
      Default max rows | 默认最大行数
      See Also:
    • DEFAULT_MAX_COLUMNS

      public static final int DEFAULT_MAX_COLUMNS
      Default max columns | 默认最大列数
      See Also:
    • DEFAULT_MAX_FIELD_SIZE

      public static final int DEFAULT_MAX_FIELD_SIZE
      Default max field size: 1 MB | 默认最大字段大小:1 MB
      See Also:
    • DEFAULT

      public static final CsvConfig DEFAULT
      Default configuration instance with RFC 4180 settings 使用RFC 4180设置的默认配置实例
  • Method Details

    • delimiter

      public char delimiter()
      Gets the field delimiter character 获取字段分隔符字符
      Returns:
      the delimiter | 分隔符
    • quoteChar

      public char quoteChar()
      Gets the quote character 获取引用字符
      Returns:
      the quote character | 引用字符
    • escapeChar

      public char escapeChar()
      Gets the escape character 获取转义字符
      Returns:
      the escape character | 转义字符
    • lineSeparator

      public String lineSeparator()
      Gets the line separator 获取行分隔符
      Returns:
      the line separator | 行分隔符
    • charset

      public Charset charset()
      Gets the character set 获取字符集
      Returns:
      the charset | 字符集
    • hasHeader

      public boolean hasHeader()
      Returns whether the CSV has a header row 返回CSV是否有标题行
      Returns:
      true if header present | 如果有标题行返回true
    • trimFields

      public boolean trimFields()
      Returns whether fields should be trimmed 返回字段是否应被修剪
      Returns:
      true if trimming enabled | 如果启用修剪返回true
    • skipEmptyRows

      public boolean skipEmptyRows()
      Returns whether empty rows should be skipped 返回是否应跳过空行
      Returns:
      true if skipping empty rows | 如果跳过空行返回true
    • maxRows

      public int maxRows()
      Gets the maximum number of rows allowed 获取允许的最大行数
      Returns:
      the max rows | 最大行数
    • maxColumns

      public int maxColumns()
      Gets the maximum number of columns allowed 获取允许的最大列数
      Returns:
      the max columns | 最大列数
    • maxFieldSize

      public int maxFieldSize()
      Gets the maximum field size in bytes 获取最大字段大小(字节)
      Returns:
      the max field size | 最大字段大小
    • formulaProtection

      public boolean formulaProtection()
      Returns whether formula injection protection is enabled 返回是否启用公式注入保护
      Returns:
      true if protection enabled | 如果启用保护返回true
    • nullString

      public String nullString()
      Gets the string to write for null values 获取null值的写入字符串
      Returns:
      the null string | null值字符串
    • builder

      public static CsvConfig.Builder builder()
      Creates a new builder 创建新的构建器
      Returns:
      a new Builder instance | 新的Builder实例
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object