Class FastStringReader

java.lang.Object
java.io.Reader
org.miaixz.bus.core.io.FastStringReader
All Implemented Interfaces:
Closeable, AutoCloseable, Readable

public class FastStringReader extends Reader
快速字符串读取,相比jdk的StringReader非线程安全,速度更快。
Since:
Java 17+
Author:
Kimi Liu
  • Constructor Details

    • FastStringReader

      public FastStringReader(String s)
      构造
      Parameters:
      s - 供读取的String
  • Method Details

    • read

      public int read() throws IOException
      读取单个字符
      Overrides:
      read in class Reader
      Returns:
      读取的字符, -1表示读取结束
      Throws:
      IOException - IO异常
    • read

      public int read(char[] charBuffer, int off, int len) throws IOException
      将多个字符读取到提供的字符数组中
      Specified by:
      read in class Reader
      Parameters:
      charBuffer - 目标buffer
      off - 开始位置
      len - 读取最大长度
      Returns:
      读取的字符长度, -1表示读取到了末尾
      Throws:
      IOException - IO异常
    • skip

      public long skip(long ns) throws IOException
      跳过指定长度,返回跳过的字符数。

      ns 参数可能为负数, 负数表示向前跳过,跳到开头则停止

      如果字符串所有字符被读取或跳过, 此方法无效,始终返回0.

      Overrides:
      skip in class Reader
      Throws:
      IOException - IO异常
    • ready

      public boolean ready() throws IOException
      Overrides:
      ready in class Reader
      Throws:
      IOException
    • markSupported

      public boolean markSupported()
      Overrides:
      markSupported in class Reader
    • mark

      public void mark(int readAheadLimit) throws IOException
      Overrides:
      mark in class Reader
      Throws:
      IOException
    • reset

      public void reset() throws IOException
      Overrides:
      reset in class Reader
      Throws:
      IOException
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in class Reader