类 StringBuilderWriter

  • 所有已实现的接口:
    java.io.Closeable, java.io.Flushable, java.io.Serializable, java.lang.Appendable, java.lang.AutoCloseable

    public class StringBuilderWriter
    extends java.io.Writer
    implements java.io.Serializable
    Writer implementation that outputs to a StringBuilder.

    NOTE: This implementation, as an alternative to java.io.StringWriter, provides an un-synchronized (i.e. for use in a single thread) implementation for better performance. For safe usage with multiple Threads then java.io.StringWriter should be used.

    从以下版本开始:
    2.0
    另请参阅:
    序列化表格
    • 字段概要

      • 从类继承的字段 java.io.Writer

        lock
    • 构造器概要

      构造器 
      构造器 说明
      StringBuilderWriter()
      www Constructs a new StringBuilder instance with default capacity.
      StringBuilderWriter​(int capacity)
      Constructs a new StringBuilder instance with the specified capacity.
      StringBuilderWriter​(java.lang.StringBuilder builder)
      Constructs a new instance with the specified StringBuilder.
    • 方法概要

      所有方法 实例方法 具体方法 
      修饰符和类型 方法 说明
      java.io.Writer append​(char value)
      Appends a single character to this Writer.
      java.io.Writer append​(java.lang.CharSequence value)
      Appends a character sequence to this Writer.
      java.io.Writer append​(java.lang.CharSequence value, int start, int end)
      Appends a portion of a character sequence to the StringBuilder.
      void close()
      Closing this writer has no effect.
      void flush()
      Flushing this writer has no effect.
      java.lang.StringBuilder getBuilder()
      Returns the underlying builder.
      java.lang.String toString()
      Returns StringBuilder.toString().
      void write​(char[] value, int offset, int length)
      Writes a portion of a character array to the StringBuilder.
      void write​(java.lang.String value)
      Writes a String to the StringBuilder.
      • 从类继承的方法 java.io.Writer

        nullWriter, write, write, write
      • 从类继承的方法 java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • 构造器详细资料

      • StringBuilderWriter

        public StringBuilderWriter()
        www Constructs a new StringBuilder instance with default capacity.
      • StringBuilderWriter

        public StringBuilderWriter​(int capacity)
        Constructs a new StringBuilder instance with the specified capacity.
        参数:
        capacity - The initial capacity of the underlying StringBuilder
      • StringBuilderWriter

        public StringBuilderWriter​(java.lang.StringBuilder builder)
        Constructs a new instance with the specified StringBuilder.

        If builder is null a new instance with default capacity will be created.

        参数:
        builder - The String builder. May be null.
    • 方法详细资料

      • append

        public java.io.Writer append​(char value)
        Appends a single character to this Writer.
        指定者:
        append 在接口中 java.lang.Appendable
        覆盖:
        append 在类中 java.io.Writer
        参数:
        value - The character to append
        返回:
        This writer instance
      • append

        public java.io.Writer append​(java.lang.CharSequence value)
        Appends a character sequence to this Writer.
        指定者:
        append 在接口中 java.lang.Appendable
        覆盖:
        append 在类中 java.io.Writer
        参数:
        value - The character to append
        返回:
        This writer instance
      • append

        public java.io.Writer append​(java.lang.CharSequence value,
                                     int start,
                                     int end)
        Appends a portion of a character sequence to the StringBuilder.
        指定者:
        append 在接口中 java.lang.Appendable
        覆盖:
        append 在类中 java.io.Writer
        参数:
        value - The character to append
        start - The index of the first character
        end - The index of the last character + 1
        返回:
        This writer instance
      • close

        public void close()
        Closing this writer has no effect.
        指定者:
        close 在接口中 java.lang.AutoCloseable
        指定者:
        close 在接口中 java.io.Closeable
        指定者:
        close 在类中 java.io.Writer
      • flush

        public void flush()
        Flushing this writer has no effect.
        指定者:
        flush 在接口中 java.io.Flushable
        指定者:
        flush 在类中 java.io.Writer
      • write

        public void write​(java.lang.String value)
        Writes a String to the StringBuilder.
        覆盖:
        write 在类中 java.io.Writer
        参数:
        value - The value to write
      • write

        public void write​(char[] value,
                          int offset,
                          int length)
        Writes a portion of a character array to the StringBuilder.
        指定者:
        write 在类中 java.io.Writer
        参数:
        value - The value to write
        offset - The index of the first character
        length - The number of characters to write
      • getBuilder

        public java.lang.StringBuilder getBuilder()
        Returns the underlying builder.
        返回:
        The underlying builder
      • toString

        public java.lang.String toString()
        Returns StringBuilder.toString().
        覆盖:
        toString 在类中 java.lang.Object
        返回:
        The contents of the String builder.