Skip to content

Commit

Permalink
Merge changes from commons-io
Browse files Browse the repository at this point in the history
  • Loading branch information
daniellansun committed Nov 3, 2024
1 parent 2974881 commit 958ae3d
Showing 1 changed file with 25 additions and 23 deletions.
48 changes: 25 additions & 23 deletions src/main/java/org/apache/groovy/io/StringBuilderWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,24 @@
import java.io.Writer;

/**
* <p>
* Copied from https://github.com/apache/commons-io/blob/master/src/main/java/org/apache/commons/io/output/StringBuilderWriter.java
*
* </p>
* {@link Writer} implementation that outputs to a {@link StringBuilder}.
* <p>
* <strong>NOTE:</strong> This implementation, as an alternative to
* <code>java.io.StringWriter</code>, provides an <i>un-synchronized</i>
* {@link java.io.StringWriter}, provides an <em>un-synchronized</em>
* (i.e. for use in a single thread) implementation for better performance.
* For safe usage with multiple {@link Thread}s then
* <code>java.io.StringWriter</code> should be used.
*
* {@link java.io.StringWriter} should be used.
* </p>
* @since 2.0
*/
public class StringBuilderWriter extends Writer implements Serializable {

private static final long serialVersionUID = -146927496096066153L;

/** The append target. */
private final StringBuilder builder;

/**
Expand Down Expand Up @@ -120,17 +123,23 @@ public void flush() {
// no-op
}

/**
* Gets the underlying builder.
*
* @return The underlying builder
*/
public StringBuilder getBuilder() {
return builder;
}

/**
* Writes a String to the {@link StringBuilder}.
* Returns {@link StringBuilder#toString()}.
*
* @param value The value to write
* @return The contents of the String builder.
*/
@Override
public void write(final String value) {
if (value != null) {
builder.append(value);
}
public String toString() {
return builder.toString();
}

/**
Expand All @@ -148,21 +157,14 @@ public void write(final char[] value, final int offset, final int length) {
}

/**
* Returns the underlying builder.
*
* @return The underlying builder
*/
public StringBuilder getBuilder() {
return builder;
}

/**
* Returns {@link StringBuilder#toString()}.
* Writes a String to the {@link StringBuilder}.
*
* @return The contents of the String builder.
* @param value The value to write
*/
@Override
public String toString() {
return builder.toString();
public void write(final String value) {
if (value != null) {
builder.append(value);
}
}
}

0 comments on commit 958ae3d

Please sign in to comment.