diff --git a/tooling/camel-tooling-util/src/main/java/org/apache/camel/tooling/util/JavadocHelper.java b/tooling/camel-tooling-util/src/main/java/org/apache/camel/tooling/util/JavadocHelper.java index e448b48e0ae77..e5ad01baf9088 100644 --- a/tooling/camel-tooling-util/src/main/java/org/apache/camel/tooling/util/JavadocHelper.java +++ b/tooling/camel-tooling-util/src/main/java/org/apache/camel/tooling/util/JavadocHelper.java @@ -37,7 +37,7 @@ public static String sanitizeDescription(String javadoc, boolean summary) { } // lets just use what java accepts as identifiers - StringBuilder sb = new StringBuilder(); + StringBuilder sb = new StringBuilder(javadoc.length()); // split into lines String[] lines = javadoc.split("\n"); @@ -101,7 +101,7 @@ public static String sanitizeDescription(String javadoc, boolean summary) { s = s.replaceAll("\\{@\\w+\\s#?([\\w.#(\\d,)]+)}", "$1"); // create a new line - StringBuilder cb = new StringBuilder(); + StringBuilder cb = new StringBuilder(s.length() + 16); for (char c : s.toCharArray()) { if (Character.isJavaIdentifierPart(c) || VALID_CHARS.indexOf(c) != -1) { cb.append(c); diff --git a/tooling/camel-tooling-util/src/main/java/org/apache/camel/tooling/util/Strings.java b/tooling/camel-tooling-util/src/main/java/org/apache/camel/tooling/util/Strings.java index 25dbb75006fe4..4220b514d9a58 100644 --- a/tooling/camel-tooling-util/src/main/java/org/apache/camel/tooling/util/Strings.java +++ b/tooling/camel-tooling-util/src/main/java/org/apache/camel/tooling/util/Strings.java @@ -141,7 +141,7 @@ public static String between(String text, String after, String before) { * @return as a title */ public static String asTitle(String name) { - StringBuilder sb = new StringBuilder(); + StringBuilder sb = new StringBuilder(name.length() + 16); for (char c : name.toCharArray()) { boolean upper = Character.isUpperCase(c); boolean first = sb.isEmpty(); @@ -170,7 +170,7 @@ public static String before(String text, String before) { } public static String indentCollection(String indent, Collection list) { - StringBuilder sb = new StringBuilder(); + StringBuilder sb = new StringBuilder(256); for (String text : list) { sb.append(indent).append(text); } diff --git a/tooling/camel-tooling-util/src/main/java/org/apache/camel/tooling/util/srcgen/Annotation.java b/tooling/camel-tooling-util/src/main/java/org/apache/camel/tooling/util/srcgen/Annotation.java index 96a930413b97e..989afece4b84e 100644 --- a/tooling/camel-tooling-util/src/main/java/org/apache/camel/tooling/util/srcgen/Annotation.java +++ b/tooling/camel-tooling-util/src/main/java/org/apache/camel/tooling/util/srcgen/Annotation.java @@ -82,7 +82,7 @@ public static String quote(String value) { char c = value.charAt(i); if (c == '"' || c == '\\') { if (sb == null) { - sb = new StringBuilder(); + sb = new StringBuilder(value.length() + 8); sb.append("\""); sb.append("\\"); sb.append(c); diff --git a/tooling/camel-tooling-util/src/main/java/org/apache/camel/tooling/util/srcgen/GenericType.java b/tooling/camel-tooling-util/src/main/java/org/apache/camel/tooling/util/srcgen/GenericType.java index 88990b9ddca7c..deb322d952acb 100644 --- a/tooling/camel-tooling-util/src/main/java/org/apache/camel/tooling/util/srcgen/GenericType.java +++ b/tooling/camel-tooling-util/src/main/java/org/apache/camel/tooling/util/srcgen/GenericType.java @@ -161,7 +161,7 @@ public String toString() { if (parameters.length == 0 && boundType == BoundType.Extends && clazz == Object.class) { return "?"; } - StringBuilder sb = new StringBuilder(); + StringBuilder sb = new StringBuilder(128); if (boundType == BoundType.Extends) { sb.append("? extends "); } else if (boundType == BoundType.Super) { diff --git a/tooling/camel-tooling-util/src/main/java/org/apache/camel/tooling/util/srcgen/JavaClass.java b/tooling/camel-tooling-util/src/main/java/org/apache/camel/tooling/util/srcgen/JavaClass.java index 731df82944e39..7cd7bc8fa5e0f 100644 --- a/tooling/camel-tooling-util/src/main/java/org/apache/camel/tooling/util/srcgen/JavaClass.java +++ b/tooling/camel-tooling-util/src/main/java/org/apache/camel/tooling/util/srcgen/JavaClass.java @@ -256,7 +256,7 @@ public String printClass() { } public String printClass(boolean innerClassesLast) { - StringBuilder sb = new StringBuilder(); + StringBuilder sb = new StringBuilder(4096); Set imports = new TreeSet<>(Comparator.comparing(JavaClass::importOrder)); imports.addAll(this.imports); @@ -311,7 +311,7 @@ private void printClass(boolean innerClassesLast, StringBuilder sb, String inden } - StringBuilder sb2 = new StringBuilder(); + StringBuilder sb2 = new StringBuilder(4096); sb2.append(indent); if (isPublic) { sb2.append("public "); @@ -464,7 +464,7 @@ private void printMethod(StringBuilder sb, String indent, Method method) { sb.append(" {"); } } else { - StringBuilder sb2 = new StringBuilder(); + StringBuilder sb2 = new StringBuilder(2048); sb2.append(indent); if (method.isPublic) { sb2.append("public "); diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/AbstractGenerateConfigurerMojo.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/AbstractGenerateConfigurerMojo.java index a8714a9c18420..c99904b2274b6 100644 --- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/AbstractGenerateConfigurerMojo.java +++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/AbstractGenerateConfigurerMojo.java @@ -487,7 +487,7 @@ private void generateMetaInfConfigurer(String fqn, String targetFqn, File resour String pn = targetFqn.substring(0, pos); String en = targetFqn.substring(pos + 1); - StringBuilder w = new StringBuilder(); + StringBuilder w = new StringBuilder(256); w.append("# ").append(GENERATED_MSG).append("\n"); w.append("class=").append(pn).append(".").append(en).append("Configurer").append("\n"); String fileName = "META-INF/services/org/apache/camel/configurer/" + fqn; diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/ComponentDslMojo.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/ComponentDslMojo.java index bac9e35488b2d..0e33a8ec749b7 100644 --- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/ComponentDslMojo.java +++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/ComponentDslMojo.java @@ -223,7 +223,7 @@ public String xmlEncode(String str) { } public String javadoc(String indent, String doc) { - StringBuilder sb = new StringBuilder(); + StringBuilder sb = new StringBuilder(doc.length() * 2); sb.append("/**\n"); int len = 78 - indent.length(); String rem = xmlEncode(doc); diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/EndpointDslMojo.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/EndpointDslMojo.java index 63344754a472c..ba4e3d76735e8 100644 --- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/EndpointDslMojo.java +++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/EndpointDslMojo.java @@ -417,7 +417,7 @@ public String xmlEncode(String str) { } public String javadoc(String indent, String doc) { - StringBuilder sb = new StringBuilder(); + StringBuilder sb = new StringBuilder(doc.length() * 2); List lines = formatJavadocOrCommentStringAsList(doc, indent); if (!lines.isEmpty()) { sb.append("/**\n"); diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/EndpointSchemaGeneratorMojo.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/EndpointSchemaGeneratorMojo.java index 47d9b8b22f1e2..055e5943f16f2 100644 --- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/EndpointSchemaGeneratorMojo.java +++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/EndpointSchemaGeneratorMojo.java @@ -665,8 +665,9 @@ private boolean filterOutOption(ComponentModel component, BaseOptionModel option } public String getDocumentationWithNotes(BaseOptionModel option) { - StringBuilder sb = new StringBuilder(); - sb.append(option.getDescription()); + String description = option.getDescription(); + StringBuilder sb = new StringBuilder(description.length() * 64); + sb.append(description); if (!Strings.isNullOrEmpty(option.getDefaultValueNote())) { if (sb.charAt(sb.length() - 1) != '.') { @@ -1680,7 +1681,7 @@ protected void generatePropertyConfigurer( } protected void generateMetaInfConfigurer(String name, String fqn) { - StringBuilder w = new StringBuilder(); + StringBuilder w = new StringBuilder(256); w.append("# ").append(GENERATED_MSG).append("\n"); w.append("class=").append(fqn).append("\n"); diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PackageDataFormatMojo.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PackageDataFormatMojo.java index 807f2824443bd..1a271dd938f76 100644 --- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PackageDataFormatMojo.java +++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PackageDataFormatMojo.java @@ -139,7 +139,7 @@ public int prepareDataFormat() throws MojoExecutionException { Map javaTypes = new HashMap<>(); - StringBuilder buffer = new StringBuilder(); + StringBuilder buffer = new StringBuilder(256); int count = 0; File f = new File(project.getBasedir(), "target/classes"); diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PackageLanguageMojo.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PackageLanguageMojo.java index 81b8adf5b0c39..65a12eba6ab5c 100644 --- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PackageLanguageMojo.java +++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PackageLanguageMojo.java @@ -125,7 +125,7 @@ public int prepareLanguage() throws MojoExecutionException { Map javaTypes = new HashMap<>(); - StringBuilder buffer = new StringBuilder(); + StringBuilder buffer = new StringBuilder(256); int count = 0; File f = new File(project.getBasedir(), "target/classes"); diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PackageModelMojo.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PackageModelMojo.java index bcca5804dfcb1..9097083b14d86 100644 --- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PackageModelMojo.java +++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PackageModelMojo.java @@ -78,7 +78,7 @@ public void execute() throws MojoExecutionException, MojoFailureException { } if (!models.isEmpty()) { - StringBuilder sb = new StringBuilder(); + StringBuilder sb = new StringBuilder(256); sb.append("# ").append(GENERATED_MSG).append(NL); for (String name : models) { sb.append(name).append(NL); diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareCamelMainDocMojo.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareCamelMainDocMojo.java index f6ecc217f24e8..52f8e2b9ff8b0 100644 --- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareCamelMainDocMojo.java +++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareCamelMainDocMojo.java @@ -98,7 +98,7 @@ public void execute() throws MojoExecutionException, MojoFailureException { } private static String evaluateTemplate(final String templateName, final MainModel model) throws MojoExecutionException { - StringBuilder sb = new StringBuilder(); + StringBuilder sb = new StringBuilder(256); try (InputStream templateStream = UpdateReadmeMojo.class.getClassLoader().getResourceAsStream(templateName)) { String template = PackageHelper.loadText(templateStream); diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareComponentMojo.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareComponentMojo.java index 1e9fda500007d..4665f8b9c6da0 100644 --- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareComponentMojo.java +++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareComponentMojo.java @@ -345,7 +345,7 @@ public int hashCode() { } public String asString(String pad) { - StringBuilder sb = new StringBuilder(); + StringBuilder sb = new StringBuilder(256); sb.append(pad).append("\n"); sb.append(pad).append(" ").append(groupId).append("\n"); sb.append(pad).append(" ").append(artifactId).append("\n"); diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/SchemaHelper.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/SchemaHelper.java index 73964caedf6ba..faaf0f35c4540 100644 --- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/SchemaHelper.java +++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/SchemaHelper.java @@ -48,7 +48,7 @@ public static String dashToCamelCase(String text) { return text; } - StringBuilder sb = new StringBuilder(); + StringBuilder sb = new StringBuilder(text.length()); for (int i = 0; i < text.length(); i++) { char c = text.charAt(i); @@ -73,7 +73,7 @@ public static String camelCaseToDash(String text) { return text; } - StringBuilder answer = new StringBuilder(); + StringBuilder answer = new StringBuilder(text.length()); Character prev = null; Character next; diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/SpiGeneratorMojo.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/SpiGeneratorMojo.java index 6b4f4ad906a79..1d4ee73cc087b 100644 --- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/SpiGeneratorMojo.java +++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/SpiGeneratorMojo.java @@ -150,7 +150,7 @@ public void execute() throws MojoExecutionException, MojoFailureException { } for (String pval : pvals.split(",")) { pval = sanitizeFileName(pval); - StringBuilder sb = new StringBuilder(); + StringBuilder sb = new StringBuilder(256); sb.append("# ").append(GENERATED_MSG).append(NL).append("class=").append(className).append(NL); if (ServiceFactory.JDK_SERVICE.equals(sfa.value().asString())) { updateResource(resourcesOutputDir.toPath(), diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/UpdateSensitizeHelper.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/UpdateSensitizeHelper.java index e388986414eed..928f02b2b9ef2 100644 --- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/UpdateSensitizeHelper.java +++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/UpdateSensitizeHelper.java @@ -205,7 +205,7 @@ private boolean updateSensitiveHelperPatterns(File camelDir, Set secrets StringJoiner sb = new StringJoiner("\n"); boolean first = true; for (String name : secrets) { - StringBuilder line = new StringBuilder(); + StringBuilder line = new StringBuilder(name.length() + 32); line.append(spaces52); line.append("+ \""); if (!first) { diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/generics/JavadocUtil.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/generics/JavadocUtil.java index 3a785d83cbe48..645513a711d90 100644 --- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/generics/JavadocUtil.java +++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/generics/JavadocUtil.java @@ -121,7 +121,7 @@ public static String extractJavaDoc(String sourceCode, MethodSource ms) throw String doc = sourceCode.substring(pos, pos + len); LineNumberReader ln = new LineNumberReader(new StringReader(doc)); String line; - StringBuilder sb = new StringBuilder(); + StringBuilder sb = new StringBuilder(256); while ((line = ln.readLine()) != null) { line = line.trim(); if (line.startsWith("/**") || line.startsWith("*/")) { diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/generics/PackagePluginUtils.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/generics/PackagePluginUtils.java index 271b2bcddc3a2..22b7505f685a6 100644 --- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/generics/PackagePluginUtils.java +++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/generics/PackagePluginUtils.java @@ -66,8 +66,9 @@ public static Index readJandexIndexIgnoreMissing(MavenProject project, Log log) } public static String joinHeaderAndSource(String licenseHeader, String source) { - StringBuilder sb = new StringBuilder(licenseHeader); + StringBuilder sb = new StringBuilder(licenseHeader.length() + source.length() + 8); + sb.append(licenseHeader); sb.append("\n"); sb.append(source); return sb.toString();