mirror of
https://github.com/ysoftdevs/DependencyCheck.git
synced 2026-03-27 11:31:24 +01:00
Replaced StringBuffer with more efficient StringBuilder.
This commit is contained in:
@@ -131,14 +131,13 @@ public class Location implements Serializable {
|
|||||||
* and the empty string for unknown locations.
|
* and the empty string for unknown locations.
|
||||||
*/
|
*/
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuffer buf = new StringBuffer();
|
final StringBuilder buf = new StringBuilder();
|
||||||
|
|
||||||
if (fileName != null) {
|
if (fileName != null) {
|
||||||
buf.append(fileName);
|
buf.append(fileName);
|
||||||
|
|
||||||
if (lineNumber != 0) {
|
if (lineNumber != 0) {
|
||||||
buf.append(":");
|
buf.append(':').append(lineNumber);
|
||||||
buf.append(lineNumber);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
buf.append(": ");
|
buf.append(": ");
|
||||||
|
|||||||
@@ -239,7 +239,7 @@ public final class Locator {
|
|||||||
if (url == null || !("file".equals(url.getProtocol()))) {
|
if (url == null || !("file".equals(url.getProtocol()))) {
|
||||||
throw new IllegalArgumentException(ERROR_NOT_FILE_URI + uri);
|
throw new IllegalArgumentException(ERROR_NOT_FILE_URI + uri);
|
||||||
}
|
}
|
||||||
StringBuffer buf = new StringBuffer(url.getHost());
|
final StringBuilder buf = new StringBuilder(url.getHost());
|
||||||
if (buf.length() > 0) {
|
if (buf.length() > 0) {
|
||||||
buf.insert(0, File.separatorChar).insert(0, File.separatorChar);
|
buf.insert(0, File.separatorChar).insert(0, File.separatorChar);
|
||||||
}
|
}
|
||||||
@@ -336,7 +336,7 @@ public final class Locator {
|
|||||||
int i = 0;
|
int i = 0;
|
||||||
int len = path.length();
|
int len = path.length();
|
||||||
int ch = 0;
|
int ch = 0;
|
||||||
StringBuffer sb = null;
|
StringBuilder sb = null;
|
||||||
for (; i < len; i++) {
|
for (; i < len; i++) {
|
||||||
ch = path.charAt(i);
|
ch = path.charAt(i);
|
||||||
// if it's not an ASCII character, break here, and use UTF-8 encoding
|
// if it's not an ASCII character, break here, and use UTF-8 encoding
|
||||||
@@ -345,7 +345,7 @@ public final class Locator {
|
|||||||
}
|
}
|
||||||
if (gNeedEscaping[ch]) {
|
if (gNeedEscaping[ch]) {
|
||||||
if (sb == null) {
|
if (sb == null) {
|
||||||
sb = new StringBuffer(path.substring(0, i));
|
sb = new StringBuilder(path.substring(0, i));
|
||||||
}
|
}
|
||||||
sb.append('%');
|
sb.append('%');
|
||||||
sb.append(gAfterEscaping1[ch]);
|
sb.append(gAfterEscaping1[ch]);
|
||||||
@@ -359,7 +359,7 @@ public final class Locator {
|
|||||||
// we saw some non-ascii character
|
// we saw some non-ascii character
|
||||||
if (i < len) {
|
if (i < len) {
|
||||||
if (sb == null) {
|
if (sb == null) {
|
||||||
sb = new StringBuffer(path.substring(0, i));
|
sb = new StringBuilder(path.substring(0, i));
|
||||||
}
|
}
|
||||||
// get UTF-8 bytes for the remaining sub-string
|
// get UTF-8 bytes for the remaining sub-string
|
||||||
byte[] bytes = null;
|
byte[] bytes = null;
|
||||||
|
|||||||
@@ -664,9 +664,9 @@ public final class SelectorUtils {
|
|||||||
* @return a String that has had all whitespace removed.
|
* @return a String that has had all whitespace removed.
|
||||||
*/
|
*/
|
||||||
public static String removeWhitespace(String input) {
|
public static String removeWhitespace(String input) {
|
||||||
StringBuffer result = new StringBuffer();
|
final StringBuilder result = new StringBuilder();
|
||||||
if (input != null) {
|
if (input != null) {
|
||||||
StringTokenizer st = new StringTokenizer(input);
|
final StringTokenizer st = new StringTokenizer(input);
|
||||||
while (st.hasMoreTokens()) {
|
while (st.hasMoreTokens()) {
|
||||||
result.append(st.nextToken());
|
result.append(st.nextToken());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -672,8 +672,8 @@ public class FileUtils {
|
|||||||
if (toProcess == null || toProcess.length() == 0) {
|
if (toProcess == null || toProcess.length() == 0) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
StringBuffer path = new StringBuffer(toProcess.length() + EXPAND_SPACE);
|
final StringBuilder path = new StringBuilder(toProcess.length() + EXPAND_SPACE);
|
||||||
PathTokenizer tokenizer = new PathTokenizer(toProcess);
|
final PathTokenizer tokenizer = new PathTokenizer(toProcess);
|
||||||
while (tokenizer.hasMoreTokens()) {
|
while (tokenizer.hasMoreTokens()) {
|
||||||
String pathComponent = tokenizer.nextToken();
|
String pathComponent = tokenizer.nextToken();
|
||||||
pathComponent = pathComponent.replace('/', File.separatorChar);
|
pathComponent = pathComponent.replace('/', File.separatorChar);
|
||||||
@@ -725,7 +725,7 @@ public class FileUtils {
|
|||||||
s.push(thisToken);
|
s.push(thisToken);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
StringBuffer sb = new StringBuffer();
|
final StringBuilder sb = new StringBuilder();
|
||||||
final int size = s.size();
|
final int size = s.size();
|
||||||
for (int i = 0; i < size; i++) {
|
for (int i = 0; i < size; i++) {
|
||||||
if (i > 1) {
|
if (i > 1) {
|
||||||
@@ -765,7 +765,7 @@ public class FileUtils {
|
|||||||
//remove the initial separator; the root has it.
|
//remove the initial separator; the root has it.
|
||||||
next = (ca[next] == sep) ? next + 1 : next;
|
next = (ca[next] == sep) ? next + 1 : next;
|
||||||
|
|
||||||
StringBuffer sbPath = new StringBuffer();
|
final StringBuilder sbPath = new StringBuilder();
|
||||||
// Eliminate consecutive slashes after the drive spec:
|
// Eliminate consecutive slashes after the drive spec:
|
||||||
for (int i = next; i < ca.length; i++) {
|
for (int i = next; i < ca.length; i++) {
|
||||||
if (ca[i] != sep || ca[i - 1] != sep) {
|
if (ca[i] != sep || ca[i - 1] != sep) {
|
||||||
@@ -805,7 +805,7 @@ public class FileUtils {
|
|||||||
&& !name.regionMatches(true, name.length() - 4, ".DIR", 0, 4);
|
&& !name.regionMatches(true, name.length() - 4, ".DIR", 0, 4);
|
||||||
// CheckStyle:MagicNumber ON
|
// CheckStyle:MagicNumber ON
|
||||||
String device = null;
|
String device = null;
|
||||||
StringBuffer directory = null;
|
StringBuilder directory = null;
|
||||||
String file = null;
|
String file = null;
|
||||||
|
|
||||||
int index = 0;
|
int index = 0;
|
||||||
@@ -818,13 +818,13 @@ public class FileUtils {
|
|||||||
device = path.substring(1, index++);
|
device = path.substring(1, index++);
|
||||||
}
|
}
|
||||||
if (isDirectory) {
|
if (isDirectory) {
|
||||||
directory = new StringBuffer(path.substring(index).replace(File.separatorChar, '.'));
|
directory = new StringBuilder(path.substring(index).replace(File.separatorChar, '.'));
|
||||||
} else {
|
} else {
|
||||||
int dirEnd = path.lastIndexOf(File.separatorChar, path.length());
|
int dirEnd = path.lastIndexOf(File.separatorChar, path.length());
|
||||||
if (dirEnd == -1 || dirEnd < index) {
|
if (dirEnd == -1 || dirEnd < index) {
|
||||||
file = path.substring(index);
|
file = path.substring(index);
|
||||||
} else {
|
} else {
|
||||||
directory = new StringBuffer(path.substring(index, dirEnd).
|
directory = new StringBuilder(path.substring(index, dirEnd).
|
||||||
replace(File.separatorChar, '.'));
|
replace(File.separatorChar, '.'));
|
||||||
index = dirEnd + 1;
|
index = dirEnd + 1;
|
||||||
if (path.length() > index) {
|
if (path.length() > index) {
|
||||||
@@ -1016,11 +1016,11 @@ public class FileUtils {
|
|||||||
}
|
}
|
||||||
final char[] buffer = new char[bufferSize];
|
final char[] buffer = new char[bufferSize];
|
||||||
int bufferLength = 0;
|
int bufferLength = 0;
|
||||||
StringBuffer textBuffer = null;
|
StringBuilder textBuffer = null;
|
||||||
while (bufferLength != -1) {
|
while (bufferLength != -1) {
|
||||||
bufferLength = rdr.read(buffer);
|
bufferLength = rdr.read(buffer);
|
||||||
if (bufferLength > 0) {
|
if (bufferLength > 0) {
|
||||||
textBuffer = (textBuffer == null) ? new StringBuffer() : textBuffer;
|
textBuffer = (textBuffer == null) ? new StringBuilder() : textBuffer;
|
||||||
textBuffer.append(new String(buffer, 0, bufferLength));
|
textBuffer.append(new String(buffer, 0, bufferLength));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1632,7 +1632,7 @@ public class FileUtils {
|
|||||||
* @since Ant 1.7
|
* @since Ant 1.7
|
||||||
*/
|
*/
|
||||||
public static String getPath(final List pathStack, final char separatorChar) {
|
public static String getPath(final List pathStack, final char separatorChar) {
|
||||||
final StringBuffer buffer = new StringBuffer();
|
final StringBuilder buffer = new StringBuilder();
|
||||||
|
|
||||||
final Iterator iter = pathStack.iterator();
|
final Iterator iter = pathStack.iterator();
|
||||||
if (iter.hasNext()) {
|
if (iter.hasNext()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user