Skip to content

io microsphere io FastByteArrayOutputStream

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

FastByteArrayOutputStream

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

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

Overview

A fast, non-thread-safe implementation of ByteArrayOutputStream.

This class is designed for scenarios requiring high-performance byte output operations. It extends the standard ByteArrayOutputStream and optimizes buffer growth and writing operations.

Example Usage

`FastByteArrayOutputStream output = new FastByteArrayOutputStream();
try {
    output.write("Hello, World!".getBytes(StandardCharsets.UTF_8));
    System.out.println(output.toString()); // Output: Hello, World!
` finally {
    output.close();
}
}

Note: Since this implementation is not thread-safe, external synchronization is required in multi-threaded environments.

Declaration

public class FastByteArrayOutputStream extends ByteArrayOutputStream

Author: Mercy

Version Information

  • Introduced in: 1.0.0
  • 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

FastByteArrayOutputStream output = new FastByteArrayOutputStream();
try {
    output.write("Hello, World!".getBytes(StandardCharsets.UTF_8));
    System.out.println(output.toString()); // Output: Hello, World!
} finally {
    output.close();
}

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.FastByteArrayOutputStream;

API Reference

Public Methods

Method Description
write The maximum size of array to allocate.
write {@inheritDoc}
writeTo {@inheritDoc}
reset {@inheritDoc}
toByteArray {@inheritDoc}
size {@inheritDoc}
close {@inheritDoc}

Method Details

write

public void write(int b)

The maximum size of array to allocate. Some VMs reserve some header words in an array. Attempts to allocate larger arrays may result in OutOfMemoryError: Requested array size exceeds VM limit / static final int MAX_ARRAY_SIZE = MAX_VALUE - 8;

/** {@inheritDoc} / public FastByteArrayOutputStream() { this(32); }

/** {@inheritDoc} / public FastByteArrayOutputStream(int size) { if (size < 0) { throw new IllegalArgumentException("Negative initial size: " + size); } buf = new byte[size]; }

/** Increases the capacity if necessary to ensure that it can hold at least the number of elements specified by the minimum capacity argument.

See Also

  • ByteArrayOutputStream

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