1
0

Use StringBuilder instead of StringBuffer for internal processing

This commit is contained in:
Gary Gregory
2023-03-04 09:18:20 -05:00
parent 21704bc396
commit 6888105f9e
2 changed files with 20 additions and 6 deletions

View File

@@ -808,7 +808,7 @@ public class LogFactoryImpl extends LogFactory {
logCategory, logCategory,
true); true);
if (result == null) { if (result == null) {
final StringBuffer messageBuffer = new StringBuffer("User-specified log class '"); final StringBuilder messageBuffer = new StringBuilder("User-specified log class '");
messageBuffer.append(specifiedLogClassName); messageBuffer.append(specifiedLogClassName);
messageBuffer.append("' cannot be found or is not useable."); messageBuffer.append("' cannot be found or is not useable.");
@@ -876,7 +876,7 @@ public class LogFactoryImpl extends LogFactory {
* @param name the (trimmed) name to be test against the candidate, not null * @param name the (trimmed) name to be test against the candidate, not null
* @param candidate the candidate name (not null) * @param candidate the candidate name (not null)
*/ */
private void informUponSimilarName(final StringBuffer messageBuffer, final String name, private void informUponSimilarName(final StringBuilder messageBuffer, final String name,
final String candidate) { final String candidate) {
if (name.equals(candidate)) { if (name.equals(candidate)) {
// Don't suggest a name that is exactly the same as the one the // Don't suggest a name that is exactly the same as the one the

View File

@@ -19,7 +19,9 @@ package org.apache.commons.logging.impl;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.PrintWriter;
import java.io.Serializable; import java.io.Serializable;
import java.io.StringWriter;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.security.AccessController; import java.security.AccessController;
@@ -277,7 +279,7 @@ public class SimpleLog implements Log, Serializable {
*/ */
protected void log(final int type, final Object message, final Throwable t) { protected void log(final int type, final Object message, final Throwable t) {
// Use a string buffer for better performance // Use a string buffer for better performance
final StringBuffer buf = new StringBuffer(); final StringBuilder buf = new StringBuilder();
// Append date-time if so configured // Append date-time if so configured
if(showDateTime) { if(showDateTime) {
@@ -321,8 +323,8 @@ public class SimpleLog implements Log, Serializable {
buf.append(t.toString()); buf.append(t.toString());
buf.append(">"); buf.append(">");
final java.io.StringWriter sw = new java.io.StringWriter(1024); final StringWriter sw = new StringWriter(1024);
final java.io.PrintWriter pw = new java.io.PrintWriter(sw); final PrintWriter pw = new PrintWriter(sw);
t.printStackTrace(pw); t.printStackTrace(pw);
pw.close(); pw.close();
buf.append(sw.toString()); buf.append(sw.toString());
@@ -344,6 +346,18 @@ public class SimpleLog implements Log, Serializable {
System.err.println(buffer.toString()); System.err.println(buffer.toString());
} }
/**
* Write the content of the message accumulated in the specified
* {@code StringBuffer} to the appropriate output destination. The
* default implementation writes to {@code System.err}.
*
* @param buffer A {@code StringBuffer} containing the accumulated
* text to be logged
*/
private void write(final Object buffer) {
System.err.println(buffer.toString());
}
/** /**
* Is the given log level currently enabled? * Is the given log level currently enabled?
* *