Class FixedWidthReaderBuilder

java.lang.Object
io.leandev.appfuse.csv.FixedWidthReaderBuilder

public class FixedWidthReaderBuilder extends Object

固定寬度讀取器建構器

使用 Builder 模式建構 FixedWidthReader,提供流暢的 API。

使用範例

FixedWidthReader reader = FixedWidthReaderBuilder.of(inputStream)
    .withFieldLengths(10, 20, 15, 10)
    .setTrimValues(true)
    .setCharset(Charset.forName("Big5"))
    .build();
Since:
1.0
  • Method Details

    • of

      public static FixedWidthReaderBuilder of(InputStream inputStream)
      建立建構器實例
      Parameters:
      inputStream - 輸入串流
      Returns:
      建構器實例
    • of

      public static FixedWidthReaderBuilder of(InputStream inputStream, Charset charset)
      建立建構器實例(指定字元編碼)
      Parameters:
      inputStream - 輸入串流
      charset - 字元編碼
      Returns:
      建構器實例
    • withFieldLengths

      public FixedWidthReaderBuilder withFieldLengths(int... lengths)
      設定欄位寬度(可變參數)
      Parameters:
      lengths - 欄位寬度陣列
      Returns:
      建構器實例(支援鏈式呼叫)
    • skipEmptyLines

      public FixedWidthReaderBuilder skipEmptyLines(boolean skipEmptyLines)
      設定是否跳過空白行
      Parameters:
      skipEmptyLines - 是否跳過空白行
      Returns:
      建構器實例(支援鏈式呼叫)
    • trimValues

      public FixedWidthReaderBuilder trimValues(boolean trimValues)
      設定是否修剪欄位值的前後空白
      Parameters:
      trimValues - 是否修剪空白
      Returns:
      建構器實例(支援鏈式呼叫)
    • emptyStringsAsNull

      public FixedWidthReaderBuilder emptyStringsAsNull(boolean emptyStringsAsNull)
      設定是否將空字串視為 null
      Parameters:
      emptyStringsAsNull - 是否將空字串視為 null
      Returns:
      建構器實例(支援鏈式呼叫)
    • lineSeparator

      public FixedWidthReaderBuilder lineSeparator(String lineSeparator)
      設定行分隔符號
      Parameters:
      lineSeparator - 行分隔符號
      Returns:
      建構器實例(支援鏈式呼叫)
    • withCharset

      public FixedWidthReaderBuilder withCharset(Charset charset)
      設定字元編碼
      Parameters:
      charset - 字元編碼
      Returns:
      建構器實例(支援鏈式呼叫)
    • withHeader

      public FixedWidthReaderBuilder withHeader(List<String> headers)
      設定 Header(不從檔案讀取)
      Parameters:
      headers - Header 欄位列表
      Returns:
      建構器實例(支援鏈式呼叫)
    • build

      public FixedWidthReader build() throws IOException
      建構 FixedWidthReader 實例
      Returns:
      FixedWidthReader 實例
      Throws:
      IOException - 建構失敗