Skip to content

io microsphere io StringBuilderWriter

github-actions[bot] edited this page Mar 21, 2026 · 1 revision

StringBuilderWriter

Type: Class | Module: microsphere-java-core | Package: io.microsphere.io

Source: microsphere-java-core/src/main/java/io/microsphere/io/StringBuilderWriter.java

Overview

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 `Thread`s then `StringWriter` should be used.

- 
    the write methods do not throw any `java.io.IOException` declaration:
    
        - `#write(int)`
        - `#write(char[])`
        - `#write(char[], int, int)`
        - `#write(String)`
        - `#write(String, int, int)`

Example Usage

`StringBuilderWriter writer = new StringBuilderWriter();
    writer.write("Hello, World!");
    System.out.println(writer.toString()); // Output: Hello, World!
`

The class can also be used with a pre-defined capacity:

`StringBuilderWriter writer = new StringBuilderWriter(1024);
    writer.write("Data");
`

Declaration

public class StringBuilderWriter extends Writer

Author: Mercy

Version Information

  • Introduced in: 0.1.10-SNAPSHOT (current)
  • Current Project Version: 0.1.10-SNAPSHOT

Version Compatibility

This component is tested and compatible with the following Java versions:

Java Version Status
Java 8 ✅ Compatible
Java 11 ✅ Compatible
Java 17 ✅ Compatible
Java 21 ✅ Compatible
Java 25 ✅ Compatible

Examples

Example 1

StringBuilderWriter writer = new StringBuilderWriter();
    writer.write("Hello, World!");
    System.out.println(writer.toString()); // Output: Hello, World!

Example 2

StringBuilderWriter writer = new StringBuilderWriter(1024);
    writer.write("Data");

Usage

Maven Dependency

Add the following dependency to your pom.xml:

<dependency>
    <groupId>io.github.microsphere-projects</groupId>
    <artifactId>microsphere-java-core</artifactId>
    <version>${microsphere-java.version}</version>
</dependency>

Tip: Use the BOM (microsphere-java-dependencies) for consistent version management. See the Getting Started guide.

Import

import io.microsphere.io.StringBuilderWriter;

API Reference

Public Methods

Method Description
write Constructs a new StringBuilder instance with default capacity.
write Writes an array of characters to the StringBuilder.
write Writes a portion of a character array to the StringBuilder.
write Writes a String to the StringBuilder.
write
append Appends a single character to this Writer.
append Appends a character sequence to this Writer.
append Appends a portion of a character sequence to the StringBuilder.
close Closing this writer has no effect.
flush Flushing this writer has no effect.
getBuilder Returns the underlying builder.

Method Details

write

public void write(int c)

Constructs a new StringBuilder instance with default capacity. / public StringBuilderWriter() { this(null); }

/** Constructs a new StringBuilder instance with the specified capacity.

write

public void write(char[] value)

Writes an array of characters to the StringBuilder.

write

public void write(final char[] value, final int offset, final int length)

Writes a portion of a character array to the StringBuilder.

append

public Writer append(final CharSequence value, final int start, final int end)

Appends a portion of a character sequence to the StringBuilder.

See Also

  • StringWriter
  • Writer

This documentation was auto-generated from the source code of microsphere-java.

Home

java-annotations

java-core

jdk-tools

lang-model

annotation-processor

java-test

Clone this wiki locally