Module bus.core

Class LineCounter

java.lang.Object
org.miaixz.bus.core.io.stream.LineCounter
All Implemented Interfaces:
Closeable, AutoCloseable

public class LineCounter extends Object implements Closeable
行数计数器
Since:
Java 17+
Author:
Kimi Liu
  • Constructor Details

    • LineCounter

      public LineCounter(InputStream is, int bufferSize)
      构造
      Parameters:
      is - 输入流
      bufferSize - 缓存大小,小于1则使用默认的1024
  • Method Details

    • setLastLineSeparatorAsNewLine

      public LineCounter setLastLineSeparatorAsNewLine(boolean lastLineSeparatorAsNewLine)
      设置是否将最后一行分隔符作为新行,Linux下要求最后一行必须带有换行符,不算一行,此处用户选择
      Parameters:
      lastLineSeparatorAsNewLine - 是否将最后一行分隔符作为新行
      Returns:
      this
    • getCount

      public int getCount()
      获取行数
      Returns:
      行数
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException