* Move almost all uses of StringBuffer to StringBuilder,

for efficiency (thanks Arsene for the suggestion)
This commit is contained in:
zzz
2009-07-01 16:00:43 +00:00
parent 055cd99dde
commit abc23e9a49
198 changed files with 407 additions and 368 deletions

View File

@ -179,7 +179,7 @@ public class I2PTunnelConnectClient extends I2PTunnelClientBase implements Runna
out = s.getOutputStream();
in = s.getInputStream();
String line, method = null, host = null, destination = null, restofline = null;
StringBuffer newRequest = new StringBuffer();
StringBuilder newRequest = new StringBuilder();
int ahelper = 0;
while (true) {
// Use this rather than BufferedReader because we can't have readahead,

View File

@ -240,7 +240,7 @@ public class I2PTunnelHTTPClient extends I2PTunnelClientBase implements Runnable
out = s.getOutputStream();
InputReader reader = new InputReader(s.getInputStream());
String line, method = null, protocol = null, host = null, destination = null;
StringBuffer newRequest = new StringBuffer();
StringBuilder newRequest = new StringBuilder();
int ahelper = 0;
while ((line = reader.readLine(method)) != null) {
line = line.trim();

View File

@ -71,7 +71,7 @@ public class I2PTunnelHTTPServer extends I2PTunnelServer {
InputStream in = socket.getInputStream();
StringBuffer command = new StringBuffer(128);
StringBuilder command = new StringBuilder(128);
Properties headers = readHeaders(in, command);
headers.setProperty(HASH_HEADER, socket.getPeerDestination().calculateHash().toBase64());
if ( (_spoofHost != null) && (_spoofHost.trim().length() > 0) )
@ -303,8 +303,8 @@ public class I2PTunnelHTTPServer extends I2PTunnelServer {
}
}
private String formatHeaders(Properties headers, StringBuffer command) {
StringBuffer buf = new StringBuffer(command.length() + headers.size() * 64);
private String formatHeaders(Properties headers, StringBuilder command) {
StringBuilder buf = new StringBuilder(command.length() + headers.size() * 64);
buf.append(command.toString().trim()).append("\r\n");
for (Iterator iter = headers.keySet().iterator(); iter.hasNext(); ) {
String name = (String)iter.next();
@ -315,9 +315,9 @@ public class I2PTunnelHTTPServer extends I2PTunnelServer {
return buf.toString();
}
private Properties readHeaders(InputStream in, StringBuffer command) throws IOException {
private Properties readHeaders(InputStream in, StringBuilder command) throws IOException {
Properties headers = new Properties();
StringBuffer buf = new StringBuffer(128);
StringBuilder buf = new StringBuilder(128);
boolean ok = DataHelper.readLine(in, command);
if (!ok) throw new IOException("EOF reached while reading the HTTP command [" + command.toString() + "]");

View File

@ -82,7 +82,7 @@ public class I2PTunnelIRCClient extends I2PTunnelClientBase implements Runnable
try {
i2ps = createI2PSocket(dest);
i2ps.setReadTimeout(readTimeout);
StringBuffer expectedPong = new StringBuffer();
StringBuilder expectedPong = new StringBuilder();
Thread in = new I2PThread(new IrcInboundFilter(s,i2ps, expectedPong), "IRC Client " + __clientId + " in");
in.start();
Thread out = new I2PThread(new IrcOutboundFilter(s,i2ps, expectedPong), "IRC Client " + __clientId + " out");
@ -121,9 +121,9 @@ public class I2PTunnelIRCClient extends I2PTunnelClientBase implements Runnable
private Socket local;
private I2PSocket remote;
private StringBuffer expectedPong;
private StringBuilder expectedPong;
IrcInboundFilter(Socket _local, I2PSocket _remote, StringBuffer pong) {
IrcInboundFilter(Socket _local, I2PSocket _remote, StringBuilder pong) {
local=_local;
remote=_remote;
expectedPong=pong;
@ -195,9 +195,9 @@ public class I2PTunnelIRCClient extends I2PTunnelClientBase implements Runnable
private Socket local;
private I2PSocket remote;
private StringBuffer expectedPong;
private StringBuilder expectedPong;
IrcOutboundFilter(Socket _local, I2PSocket _remote, StringBuffer pong) {
IrcOutboundFilter(Socket _local, I2PSocket _remote, StringBuilder pong) {
local=_local;
remote=_remote;
expectedPong=pong;
@ -266,7 +266,7 @@ public class I2PTunnelIRCClient extends I2PTunnelClientBase implements Runnable
*
*/
public String inboundFilter(String s, StringBuffer expectedPong) {
public String inboundFilter(String s, StringBuilder expectedPong) {
String field[]=s.split(" ",4);
String command;
@ -353,7 +353,7 @@ public class I2PTunnelIRCClient extends I2PTunnelClientBase implements Runnable
return null;
}
public String outboundFilter(String s, StringBuffer expectedPong) {
public String outboundFilter(String s, StringBuilder expectedPong) {
String field[]=s.split(" ",3);
String command;

View File

@ -135,7 +135,7 @@ public class I2PTunnelIRCServer extends I2PTunnelServer implements Runnable {
/** keep reading until we see USER or SERVER */
private String filterRegistration(InputStream in, String newHostname) throws IOException {
StringBuffer buf = new StringBuffer(128);
StringBuilder buf = new StringBuilder(128);
int lineCount = 0;
while (true) {

View File

@ -211,7 +211,7 @@ public class I2Ping extends I2PTunnelTask implements Runnable {
int fail = 0;
long totalTime = 0;
int cnt = countPing ? CPING_COUNT : PING_COUNT;
StringBuffer pingResults = new StringBuffer(2 * cnt + destination.length() + 3);
StringBuilder pingResults = new StringBuilder(2 * cnt + destination.length() + 3);
for (int i = 0; i < cnt; i++) {
boolean sent;
sent = ping(dest);

View File

@ -385,7 +385,7 @@ public class TunnelController implements Logging {
public String getI2CPHost() { return _config.getProperty("i2cpHost"); }
public String getI2CPPort() { return _config.getProperty("i2cpPort"); }
public String getClientOptions() {
StringBuffer opts = new StringBuffer(64);
StringBuilder opts = new StringBuilder(64);
for (Iterator iter = _config.keySet().iterator(); iter.hasNext(); ) {
String key = (String)iter.next();
String val = _config.getProperty(key);
@ -447,7 +447,7 @@ public class TunnelController implements Logging {
return true;
}
public void getSummary(StringBuffer buf) {
public void getSummary(StringBuilder buf) {
String type = getType();
if ("httpclient".equals(type))
getHttpClientSummary(buf);
@ -461,7 +461,7 @@ public class TunnelController implements Logging {
buf.append("Unknown type ").append(type);
}
private void getHttpClientSummary(StringBuffer buf) {
private void getHttpClientSummary(StringBuilder buf) {
String description = getDescription();
if ( (description != null) && (description.trim().length() > 0) )
buf.append("<i>").append(description).append("</i><br />\n");
@ -482,7 +482,7 @@ public class TunnelController implements Logging {
getOptionSummary(buf);
}
private void getClientSummary(StringBuffer buf) {
private void getClientSummary(StringBuilder buf) {
String description = getDescription();
if ( (description != null) && (description.trim().length() > 0) )
buf.append("<i>").append(description).append("</i><br />\n");
@ -499,7 +499,7 @@ public class TunnelController implements Logging {
getOptionSummary(buf);
}
private void getServerSummary(StringBuffer buf) {
private void getServerSummary(StringBuilder buf) {
String description = getDescription();
if ( (description != null) && (description.trim().length() > 0) )
buf.append("<i>").append(description).append("</i><br />\n");
@ -510,7 +510,7 @@ public class TunnelController implements Logging {
getOptionSummary(buf);
}
private void getHttpServerSummary(StringBuffer buf) {
private void getHttpServerSummary(StringBuilder buf) {
String description = getDescription();
if ( (description != null) && (description.trim().length() > 0) )
buf.append("<i>").append(description).append("</i><br />\n");
@ -522,7 +522,7 @@ public class TunnelController implements Logging {
getOptionSummary(buf);
}
private void getOptionSummary(StringBuffer buf) {
private void getOptionSummary(StringBuilder buf) {
String opts = getClientOptions();
if ( (opts != null) && (opts.length() > 0) )
buf.append("Network options: ").append(opts).append("<br />\n");

View File

@ -245,7 +245,7 @@ public class TunnelControllerGroup {
map.putAll(cur);
}
StringBuffer buf = new StringBuffer(1024);
StringBuilder buf = new StringBuilder(1024);
for (Iterator iter = map.keySet().iterator(); iter.hasNext(); ) {
String key = (String)iter.next();
String val = (String)map.get(key);

View File

@ -123,7 +123,7 @@ public class SOCKS4aServer extends SOCKSServer {
}
private String readString(DataInputStream in) throws IOException {
StringBuffer sb = new StringBuffer(16);
StringBuilder sb = new StringBuilder(16);
char c;
while ((c = (char) (in.readByte() & 0xff)) != 0)
sb.append(c);

View File

@ -223,7 +223,7 @@ public class EditBean extends IndexBean {
if (tun != null) {
Properties opts = getOptions(tun);
if (opts == null) return "";
StringBuffer buf = new StringBuffer(64);
StringBuilder buf = new StringBuilder(64);
int i = 0;
for (Iterator iter = opts.keySet().iterator(); iter.hasNext(); ) {
String key = (String)iter.next();

View File

@ -302,7 +302,7 @@ public class IndexBean {
if (_group == null)
return "";
StringBuffer buf = new StringBuffer(512);
StringBuilder buf = new StringBuilder(512);
if (_action != null) {
try {
buf.append(processAction()).append("\n");
@ -927,11 +927,11 @@ public class IndexBean {
}
private String getMessages(List msgs) {
StringBuffer buf = new StringBuffer(128);
StringBuilder buf = new StringBuilder(128);
getMessages(msgs, buf);
return buf.toString();
}
private void getMessages(List msgs, StringBuffer buf) {
private void getMessages(List msgs, StringBuilder buf) {
if (msgs == null) return;
for (int i = 0; i < msgs.size(); i++) {
buf.append((String)msgs.get(i)).append("\n");