mirror of https://github.com/apache/jclouds.git
Merge pull request #593 from andrewgaul/string-builder
Prefer unsynchronized StringBuilder
This commit is contained in:
commit
af65dbbac3
|
@ -107,7 +107,7 @@ public abstract class TerremarkClientLiveTest<S extends TerremarkVCloudClient, A
|
||||||
|
|
||||||
public TerremarkClientLiveTest() {
|
public TerremarkClientLiveTest() {
|
||||||
this.provider = "trmk-vcloudexpress";
|
this.provider = "trmk-vcloudexpress";
|
||||||
StringBuffer name = new StringBuffer();
|
StringBuilder name = new StringBuilder();
|
||||||
for (int i = 0; i < 15; i++)
|
for (int i = 0; i < 15; i++)
|
||||||
name.append("d");
|
name.append("d");
|
||||||
serverName = name.toString();// "adriantest";
|
serverName = name.toString();// "adriantest";
|
||||||
|
@ -287,7 +287,7 @@ public abstract class TerremarkClientLiveTest<S extends TerremarkVCloudClient, A
|
||||||
assert successTester.apply(connection.powerOffVApp(vApp.getHref()).getHref());
|
assert successTester.apply(connection.powerOffVApp(vApp.getHref()).getHref());
|
||||||
System.out.printf("%d: done powering off vApp%n", System.currentTimeMillis());
|
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++)
|
for (int i = 0; i < 15; i++)
|
||||||
name.append("b");
|
name.append("b");
|
||||||
String newName = name.toString();
|
String newName = name.toString();
|
||||||
|
|
|
@ -160,7 +160,7 @@ public class Sha512Crypt {
|
||||||
byte[] s_bytes = null;
|
byte[] s_bytes = null;
|
||||||
int cnt, cnt2;
|
int cnt, cnt2;
|
||||||
int rounds = ROUNDS_DEFAULT; // Default number of rounds.
|
int rounds = ROUNDS_DEFAULT; // Default number of rounds.
|
||||||
StringBuffer buffer;
|
StringBuilder buffer;
|
||||||
|
|
||||||
/* -- */
|
/* -- */
|
||||||
|
|
||||||
|
@ -181,7 +181,7 @@ public class Sha512Crypt {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
java.util.Random randgen = new java.util.Random();
|
java.util.Random randgen = new java.util.Random();
|
||||||
StringBuffer saltBuf = new StringBuffer();
|
StringBuilder saltBuf = new StringBuilder();
|
||||||
|
|
||||||
while (saltBuf.length() < 16) {
|
while (saltBuf.length() < 16) {
|
||||||
int index = (int) (randgen.nextFloat() * SALTCHARS.length());
|
int index = (int) (randgen.nextFloat() * SALTCHARS.length());
|
||||||
|
@ -286,7 +286,7 @@ public class Sha512Crypt {
|
||||||
alt_result = ctx.digest();
|
alt_result = ctx.digest();
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer = new StringBuffer(sha512_salt_prefix);
|
buffer = new StringBuilder(sha512_salt_prefix);
|
||||||
|
|
||||||
if (rounds != 5000) {
|
if (rounds != 5000) {
|
||||||
buffer.append(sha512_rounds_prefix);
|
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) {
|
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);
|
int v = ((((int) B2) & 0xFF) << 16) | ((((int) B1) & 0xFF) << 8) | ((int) B0 & 0xff);
|
||||||
|
|
||||||
StringBuffer result = new StringBuffer();
|
StringBuilder result = new StringBuilder();
|
||||||
|
|
||||||
while (--size >= 0) {
|
while (--size >= 0) {
|
||||||
result.append(itoa64.charAt((int) (v & 0x3f)));
|
result.append(itoa64.charAt((int) (v & 0x3f)));
|
||||||
|
|
|
@ -353,7 +353,7 @@ public class HttpUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String sortAndConcatHeadersIntoString(Multimap<String, String> headers) {
|
public static String sortAndConcatHeadersIntoString(Multimap<String, String> headers) {
|
||||||
StringBuffer buffer = new StringBuffer();
|
StringBuilder buffer = new StringBuilder();
|
||||||
SortedSetMultimap<String, String> sortedMap = TreeMultimap.create();
|
SortedSetMultimap<String, String> sortedMap = TreeMultimap.create();
|
||||||
sortedMap.putAll(headers);
|
sortedMap.putAll(headers);
|
||||||
for (Entry<String, String> header : sortedMap.entries()) {
|
for (Entry<String, String> header : sortedMap.entries()) {
|
||||||
|
|
|
@ -72,7 +72,7 @@ public class ParseXMLWithJAXB<T> implements Function<HttpResponse, T> {
|
||||||
try {
|
try {
|
||||||
return apply(xml);
|
return apply(xml);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
StringBuffer message = new StringBuffer();
|
StringBuilder message = new StringBuilder();
|
||||||
message.append("Error parsing input");
|
message.append("Error parsing input");
|
||||||
logger.error(e, message.toString());
|
logger.error(e, message.toString());
|
||||||
throw new HttpResponseException(message.toString() + "\n" + from, null, from, e);
|
throw new HttpResponseException(message.toString() + "\n" + from, null, from, e);
|
||||||
|
|
|
@ -51,10 +51,10 @@ public enum PasswordGenerator implements Supplier<String> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String get() {
|
public String get() {
|
||||||
StringBuffer sb = new StringBuffer();
|
StringBuilder sb = new StringBuilder();
|
||||||
for (int i = 0; i < MIN_LENGTH; i++) {
|
for (int i = 0; i < MIN_LENGTH; i++) {
|
||||||
sb.append(goodChar[r.nextInt(goodChar.length)]);
|
sb.append(goodChar[r.nextInt(goodChar.length)]);
|
||||||
}
|
}
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -175,7 +175,7 @@ public abstract class BaseJettyTest {
|
||||||
client = context.getApi();
|
client = context.getApi();
|
||||||
assert client != null;
|
assert client != null;
|
||||||
|
|
||||||
assert client.newStringBuffer() != null;
|
assert client.newStringBuilder() != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void handlePost(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
private static void handlePost(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
||||||
|
|
|
@ -202,6 +202,6 @@ public interface IntegrationTestAsyncClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
StringBuffer newStringBuffer();
|
StringBuilder newStringBuilder();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,5 +68,5 @@ public interface IntegrationTestClient {
|
||||||
String downloadAndParse(String id);
|
String downloadAndParse(String id);
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
StringBuffer newStringBuffer();
|
StringBuilder newStringBuilder();
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,7 +68,7 @@ public class WireLiveTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
static class BufferLogger implements Logger {
|
static class BufferLogger implements Logger {
|
||||||
StringBuffer buff = new StringBuffer();
|
StringBuilder buff = new StringBuilder();
|
||||||
|
|
||||||
public void debug(String message, Object... args) {
|
public void debug(String message, Object... args) {
|
||||||
buff.append(message);
|
buff.append(message);
|
||||||
|
|
|
@ -35,7 +35,7 @@ import org.testng.annotations.Test;
|
||||||
public class WireTest {
|
public class WireTest {
|
||||||
|
|
||||||
class BufferLogger implements Logger {
|
class BufferLogger implements Logger {
|
||||||
StringBuffer buff = new StringBuffer();
|
StringBuilder buff = new StringBuilder();
|
||||||
|
|
||||||
public void debug(String message, Object... args) {
|
public void debug(String message, Object... args) {
|
||||||
buff.append(message);
|
buff.append(message);
|
||||||
|
|
|
@ -2474,7 +2474,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
Function<HttpResponse, TestJAXBDomain> parser = (Function<HttpResponse, TestJAXBDomain>) RestAnnotationProcessor
|
Function<HttpResponse, TestJAXBDomain> parser = (Function<HttpResponse, TestJAXBDomain>) RestAnnotationProcessor
|
||||||
.createResponseParser(parserFactory, injector, method, request);
|
.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>");
|
payload.append("<test><elem>Hello World</elem></test>");
|
||||||
TestJAXBDomain domain = parser.apply(new HttpResponse(200, "ok", newStringPayload(payload.toString())));
|
TestJAXBDomain domain = parser.apply(new HttpResponse(200, "ok", newStringPayload(payload.toString())));
|
||||||
assertEquals(domain.getElem(), "Hello World");
|
assertEquals(domain.getElem(), "Hello World");
|
||||||
|
@ -2492,7 +2492,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
Function<HttpResponse, TestJAXBDomain> parser = (Function<HttpResponse, TestJAXBDomain>) RestAnnotationProcessor
|
Function<HttpResponse, TestJAXBDomain> parser = (Function<HttpResponse, TestJAXBDomain>) RestAnnotationProcessor
|
||||||
.createResponseParser(parserFactory, injector, method, request);
|
.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>");
|
payload.append("<test><elem>Hello World</elem></test>");
|
||||||
TestJAXBDomain domain = parser.apply(new HttpResponse(200, "ok", newStringPayload(payload.toString())));
|
TestJAXBDomain domain = parser.apply(new HttpResponse(200, "ok", newStringPayload(payload.toString())));
|
||||||
assertEquals(domain.getElem(), "Hello World");
|
assertEquals(domain.getElem(), "Hello World");
|
||||||
|
|
|
@ -54,7 +54,7 @@ public class IMachineToIpAddress implements Function<IMachine, String> {
|
||||||
String macAddress = machine.getNetworkAdapter(0l).getMACAddress();
|
String macAddress = machine.getNetworkAdapter(0l).getMACAddress();
|
||||||
int offset = 0, step = 2;
|
int offset = 0, step = 2;
|
||||||
for (int j = 1; j <= 5; j++) {
|
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++;
|
offset++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,14 +64,14 @@ public class IMachineToIpAddress implements Function<IMachine, String> {
|
||||||
IMachine hostMachine = manager.getVBox().findMachine(hostId);
|
IMachine hostMachine = manager.getVBox().findMachine(hostId);
|
||||||
if (isOSX(hostMachine)) {
|
if (isOSX(hostMachine)) {
|
||||||
if (simplifiedMacAddressOfClonedVM.contains("00"))
|
if (simplifiedMacAddressOfClonedVM.contains("00"))
|
||||||
simplifiedMacAddressOfClonedVM = new StringBuffer(simplifiedMacAddressOfClonedVM).delete(
|
simplifiedMacAddressOfClonedVM = new StringBuilder(simplifiedMacAddressOfClonedVM).delete(
|
||||||
simplifiedMacAddressOfClonedVM.indexOf("00"), simplifiedMacAddressOfClonedVM.indexOf("00") + 1)
|
simplifiedMacAddressOfClonedVM.indexOf("00"), simplifiedMacAddressOfClonedVM.indexOf("00") + 1)
|
||||||
.toString();
|
.toString();
|
||||||
|
|
||||||
if (simplifiedMacAddressOfClonedVM.contains("0"))
|
if (simplifiedMacAddressOfClonedVM.contains("0"))
|
||||||
if (simplifiedMacAddressOfClonedVM.indexOf("0") + 1 != ':'
|
if (simplifiedMacAddressOfClonedVM.indexOf("0") + 1 != ':'
|
||||||
&& 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)
|
simplifiedMacAddressOfClonedVM.indexOf("0"), simplifiedMacAddressOfClonedVM.indexOf("0") + 1)
|
||||||
.toString();
|
.toString();
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,7 +85,7 @@ public class SDNAsyncClientTest extends RestClientTest<SDNAsyncClient> {
|
||||||
assertRequestLineEquals(request,
|
assertRequestLineEquals(request,
|
||||||
"POST http://uploader/Upload.ashx?output=json&destFolderPath=adriansmovies&uploadToken=token HTTP/1.1");
|
"POST http://uploader/Upload.ashx?output=json&destFolderPath=adriansmovies&uploadToken=token HTTP/1.1");
|
||||||
assertNonPayloadHeadersEqual(request, "");
|
assertNonPayloadHeadersEqual(request, "");
|
||||||
StringBuffer expects = new StringBuffer();
|
StringBuilder expects = new StringBuilder();
|
||||||
expects.append("----JCLOUDS--\r\n");
|
expects.append("----JCLOUDS--\r\n");
|
||||||
expects.append("Content-Disposition: form-data; name=\"hello\"\r\n");
|
expects.append("Content-Disposition: form-data; name=\"hello\"\r\n");
|
||||||
expects.append("Content-Type: text/plain\r\n\r\n");
|
expects.append("Content-Type: text/plain\r\n\r\n");
|
||||||
|
|
Loading…
Reference in New Issue