Merge pull request #593 from andrewgaul/string-builder

Prefer unsynchronized StringBuilder
This commit is contained in:
Adrian Cole 2012-04-30 10:46:21 -07:00
commit af65dbbac3
13 changed files with 21 additions and 21 deletions

View File

@ -107,7 +107,7 @@ public abstract class TerremarkClientLiveTest<S extends TerremarkVCloudClient, A
public TerremarkClientLiveTest() {
this.provider = "trmk-vcloudexpress";
StringBuffer name = new StringBuffer();
StringBuilder name = new StringBuilder();
for (int i = 0; i < 15; i++)
name.append("d");
serverName = name.toString();// "adriantest";
@ -287,7 +287,7 @@ public abstract class TerremarkClientLiveTest<S extends TerremarkVCloudClient, A
assert successTester.apply(connection.powerOffVApp(vApp.getHref()).getHref());
System.out.printf("%d: done powering off vApp%n", System.currentTimeMillis());
StringBuffer name = new StringBuffer();
StringBuilder name = new StringBuilder();
for (int i = 0; i < 15; i++)
name.append("b");
String newName = name.toString();

View File

@ -160,7 +160,7 @@ public class Sha512Crypt {
byte[] s_bytes = null;
int cnt, cnt2;
int rounds = ROUNDS_DEFAULT; // Default number of rounds.
StringBuffer buffer;
StringBuilder buffer;
/* -- */
@ -181,7 +181,7 @@ public class Sha512Crypt {
}
} else {
java.util.Random randgen = new java.util.Random();
StringBuffer saltBuf = new StringBuffer();
StringBuilder saltBuf = new StringBuilder();
while (saltBuf.length() < 16) {
int index = (int) (randgen.nextFloat() * SALTCHARS.length());
@ -286,7 +286,7 @@ public class Sha512Crypt {
alt_result = ctx.digest();
}
buffer = new StringBuffer(sha512_salt_prefix);
buffer = new StringBuilder(sha512_salt_prefix);
if (rounds != 5000) {
buffer.append(sha512_rounds_prefix);
@ -333,7 +333,7 @@ public class Sha512Crypt {
private static final String b64_from_24bit(byte B2, byte B1, byte B0, int size) {
int v = ((((int) B2) & 0xFF) << 16) | ((((int) B1) & 0xFF) << 8) | ((int) B0 & 0xff);
StringBuffer result = new StringBuffer();
StringBuilder result = new StringBuilder();
while (--size >= 0) {
result.append(itoa64.charAt((int) (v & 0x3f)));

View File

@ -353,7 +353,7 @@ public class HttpUtils {
}
public static String sortAndConcatHeadersIntoString(Multimap<String, String> headers) {
StringBuffer buffer = new StringBuffer();
StringBuilder buffer = new StringBuilder();
SortedSetMultimap<String, String> sortedMap = TreeMultimap.create();
sortedMap.putAll(headers);
for (Entry<String, String> header : sortedMap.entries()) {

View File

@ -72,7 +72,7 @@ public class ParseXMLWithJAXB<T> implements Function<HttpResponse, T> {
try {
return apply(xml);
} catch (Exception e) {
StringBuffer message = new StringBuffer();
StringBuilder message = new StringBuilder();
message.append("Error parsing input");
logger.error(e, message.toString());
throw new HttpResponseException(message.toString() + "\n" + from, null, from, e);

View File

@ -51,10 +51,10 @@ public enum PasswordGenerator implements Supplier<String> {
@Override
public String get() {
StringBuffer sb = new StringBuffer();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < MIN_LENGTH; i++) {
sb.append(goodChar[r.nextInt(goodChar.length)]);
}
return sb.toString();
}
}
}

View File

@ -175,7 +175,7 @@ public abstract class BaseJettyTest {
client = context.getApi();
assert client != null;
assert client.newStringBuffer() != null;
assert client.newStringBuilder() != null;
}
private static void handlePost(HttpServletRequest request, HttpServletResponse response) throws IOException {

View File

@ -202,6 +202,6 @@ public interface IntegrationTestAsyncClient {
}
@Provides
StringBuffer newStringBuffer();
StringBuilder newStringBuilder();
}

View File

@ -68,5 +68,5 @@ public interface IntegrationTestClient {
String downloadAndParse(String id);
@Provides
StringBuffer newStringBuffer();
StringBuilder newStringBuilder();
}

View File

@ -68,7 +68,7 @@ public class WireLiveTest {
}
static class BufferLogger implements Logger {
StringBuffer buff = new StringBuffer();
StringBuilder buff = new StringBuilder();
public void debug(String message, Object... args) {
buff.append(message);

View File

@ -35,7 +35,7 @@ import org.testng.annotations.Test;
public class WireTest {
class BufferLogger implements Logger {
StringBuffer buff = new StringBuffer();
StringBuilder buff = new StringBuilder();
public void debug(String message, Object... args) {
buff.append(message);

View File

@ -2474,7 +2474,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
Function<HttpResponse, TestJAXBDomain> parser = (Function<HttpResponse, TestJAXBDomain>) RestAnnotationProcessor
.createResponseParser(parserFactory, injector, method, request);
StringBuffer payload = new StringBuffer(XMLParser.DEFAULT_XML_HEADER);
StringBuilder payload = new StringBuilder(XMLParser.DEFAULT_XML_HEADER);
payload.append("<test><elem>Hello World</elem></test>");
TestJAXBDomain domain = parser.apply(new HttpResponse(200, "ok", newStringPayload(payload.toString())));
assertEquals(domain.getElem(), "Hello World");
@ -2492,7 +2492,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
Function<HttpResponse, TestJAXBDomain> parser = (Function<HttpResponse, TestJAXBDomain>) RestAnnotationProcessor
.createResponseParser(parserFactory, injector, method, request);
StringBuffer payload = new StringBuffer(XMLParser.DEFAULT_XML_HEADER);
StringBuilder payload = new StringBuilder(XMLParser.DEFAULT_XML_HEADER);
payload.append("<test><elem>Hello World</elem></test>");
TestJAXBDomain domain = parser.apply(new HttpResponse(200, "ok", newStringPayload(payload.toString())));
assertEquals(domain.getElem(), "Hello World");

View File

@ -54,7 +54,7 @@ public class IMachineToIpAddress implements Function<IMachine, String> {
String macAddress = machine.getNetworkAdapter(0l).getMACAddress();
int offset = 0, step = 2;
for (int j = 1; j <= 5; j++) {
macAddress = new StringBuffer(macAddress).insert(j * step + offset, ":").toString().toLowerCase();
macAddress = new StringBuilder(macAddress).insert(j * step + offset, ":").toString().toLowerCase();
offset++;
}
@ -64,14 +64,14 @@ public class IMachineToIpAddress implements Function<IMachine, String> {
IMachine hostMachine = manager.getVBox().findMachine(hostId);
if (isOSX(hostMachine)) {
if (simplifiedMacAddressOfClonedVM.contains("00"))
simplifiedMacAddressOfClonedVM = new StringBuffer(simplifiedMacAddressOfClonedVM).delete(
simplifiedMacAddressOfClonedVM = new StringBuilder(simplifiedMacAddressOfClonedVM).delete(
simplifiedMacAddressOfClonedVM.indexOf("00"), simplifiedMacAddressOfClonedVM.indexOf("00") + 1)
.toString();
if (simplifiedMacAddressOfClonedVM.contains("0"))
if (simplifiedMacAddressOfClonedVM.indexOf("0") + 1 != ':'
&& simplifiedMacAddressOfClonedVM.indexOf("0") - 1 != ':')
simplifiedMacAddressOfClonedVM = new StringBuffer(simplifiedMacAddressOfClonedVM).delete(
simplifiedMacAddressOfClonedVM = new StringBuilder(simplifiedMacAddressOfClonedVM).delete(
simplifiedMacAddressOfClonedVM.indexOf("0"), simplifiedMacAddressOfClonedVM.indexOf("0") + 1)
.toString();
}

View File

@ -85,7 +85,7 @@ public class SDNAsyncClientTest extends RestClientTest<SDNAsyncClient> {
assertRequestLineEquals(request,
"POST http://uploader/Upload.ashx?output=json&destFolderPath=adriansmovies&uploadToken=token HTTP/1.1");
assertNonPayloadHeadersEqual(request, "");
StringBuffer expects = new StringBuffer();
StringBuilder expects = new StringBuilder();
expects.append("----JCLOUDS--\r\n");
expects.append("Content-Disposition: form-data; name=\"hello\"\r\n");
expects.append("Content-Type: text/plain\r\n\r\n");