* 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

@@ -106,7 +106,7 @@ public class DataMessage extends I2NPMessageImpl {
@Override
public String toString() {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append("[DataMessage: ");
buf.append("\n\tData: ").append(DataHelper.toString(getData(), 64));
buf.append("]");

View File

@@ -238,7 +238,7 @@ public class DatabaseLookupMessage extends I2NPMessageImpl {
@Override
public String toString() {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append("[DatabaseLookupMessage: ");
buf.append("\n\tSearch Key: ").append(getSearchKey());
buf.append("\n\tFrom: ").append(getFrom());

View File

@@ -131,7 +131,7 @@ public class DatabaseSearchReplyMessage extends I2NPMessageImpl {
@Override
public String toString() {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append("[DatabaseSearchReplyMessage: ");
buf.append("\n\tSearch Key: ").append(getSearchKey());
buf.append("\n\tReplies: # = ").append(getNumReplies());

View File

@@ -260,7 +260,7 @@ public class DatabaseStoreMessage extends I2NPMessageImpl {
@Override
public String toString() {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append("[DatabaseStoreMessage: ");
buf.append("\n\tExpiration: ").append(getMessageExpiration());
buf.append("\n\tUnique ID: ").append(getUniqueId());

View File

@@ -70,7 +70,7 @@ public class DateMessage extends I2NPMessageImpl {
@Override
public String toString() {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append("[DateMessage: ");
buf.append("Now: ").append(_now);
buf.append("]");

View File

@@ -377,7 +377,7 @@ public class DeliveryInstructions extends DataStructureImpl {
@Override
public String toString() {
StringBuffer buf = new StringBuffer(128);
StringBuilder buf = new StringBuilder(128);
buf.append("[DeliveryInstructions: ");
buf.append("\n\tDelivery mode: ");
switch (getDeliveryMode()) {

View File

@@ -82,7 +82,7 @@ public class DeliveryStatusMessage extends I2NPMessageImpl {
@Override
public String toString() {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append("[DeliveryStatusMessage: ");
buf.append("\n\tMessage ID: ").append(getMessageId());
buf.append("\n\tArrival: ").append(_context.clock().now() - _arrival);

View File

@@ -107,25 +107,25 @@ public class GarlicClove extends DataStructureImpl {
public void writeBytes(OutputStream out) throws DataFormatException, IOException {
StringBuffer error = null;
StringBuilder error = null;
if (_instructions == null) {
if (error == null) error = new StringBuffer();
if (error == null) error = new StringBuilder();
error.append("No instructions ");
}
if (_msg == null) {
if (error == null) error = new StringBuffer();
if (error == null) error = new StringBuilder();
error.append("No message ");
}
if (_cloveId < 0) {
if (error == null) error = new StringBuffer();
if (error == null) error = new StringBuilder();
error.append("CloveID < 0 [").append(_cloveId).append("] ");
}
if (_expiration == null) {
if (error == null) error = new StringBuffer();
if (error == null) error = new StringBuilder();
error.append("Expiration is null ");
}
if (_certificate == null) {
if (error == null) error = new StringBuffer();
if (error == null) error = new StringBuilder();
error.append("Certificate is null ");
}
@@ -210,7 +210,7 @@ public class GarlicClove extends DataStructureImpl {
@Override
public String toString() {
StringBuffer buf = new StringBuffer(128);
StringBuilder buf = new StringBuilder(128);
buf.append("[GarlicClove: ");
buf.append("\n\tInstructions: ").append(getInstructions());
buf.append("\n\tCertificate: ").append(getCertificate());

View File

@@ -90,7 +90,7 @@ public class GarlicMessage extends I2NPMessageImpl {
@Override
public String toString() {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append("[GarlicMessage: ");
buf.append("\n\tData length: ").append(getData().length).append(" bytes");
buf.append("]");

View File

@@ -263,7 +263,7 @@ public class TunnelCreateMessage extends I2NPMessageImpl {
@Override
public String toString() {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append("[TunnelCreateMessage: ");
buf.append("\n\tNext Router: ").append(getNextRouter());
buf.append("\n\tNext Tunnel: ").append(getNextTunnelId());

View File

@@ -108,7 +108,7 @@ public class TunnelCreateStatusMessage extends I2NPMessageImpl {
@Override
public String toString() {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append("[TunnelCreateStatusMessage: ");
buf.append("\n\tTunnel ID: ").append(getReceiveTunnelId());
buf.append("\n\tStatus: ").append(getStatus());

View File

@@ -139,7 +139,7 @@ public class TunnelDataMessage extends I2NPMessageImpl {
@Override
public String toString() {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append("[TunnelDataMessage:");
buf.append(" MessageId: ").append(getUniqueId());
buf.append(" Tunnel ID: ").append(getTunnelId());

View File

@@ -131,7 +131,7 @@ public class TunnelGatewayMessage extends I2NPMessageImpl {
@Override
public String toString() {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append("[TunnelGatewayMessage:");
buf.append(" Tunnel ID: ").append(getTunnelId());
buf.append(" Message: ").append(_msg);

View File

@@ -188,7 +188,7 @@ public class Blocklist {
FileInputStream in = null;
try {
in = new FileInputStream(BLFile);
StringBuffer buf = new StringBuffer(128);
StringBuilder buf = new StringBuilder(128);
while (DataHelper.readLine(in, buf) && count < maxSize) {
Entry e = parse(buf, true);
buf.setLength(0);
@@ -267,7 +267,7 @@ public class Blocklist {
}
}
private Entry parse(StringBuffer buf, boolean bitch) {
private Entry parse(StringBuilder buf, boolean bitch) {
byte[] ip1;
byte[] ip2;
int start1 = 0;
@@ -378,7 +378,7 @@ public class Blocklist {
FileInputStream in = null;
try {
in = new FileInputStream(BLFile);
StringBuffer buf = new StringBuffer(128);
StringBuilder buf = new StringBuilder(128);
while (DataHelper.readLine(in, buf)) {
lines++;
buf.setLength(0);
@@ -628,7 +628,7 @@ public class Blocklist {
}
private static String toStr(long entry) {
StringBuffer buf = new StringBuffer(32);
StringBuilder buf = new StringBuilder(32);
for (int i = 7; i >= 0; i--) {
buf.append((entry >> (8*i)) & 0xff);
if (i == 4)
@@ -640,7 +640,7 @@ public class Blocklist {
}
private static String toStr(int ip) {
StringBuffer buf = new StringBuffer(16);
StringBuilder buf = new StringBuilder(16);
for (int i = 3; i >= 0; i--) {
buf.append((ip >> (8*i)) & 0xff);
if (i > 0)
@@ -719,7 +719,7 @@ public class Blocklist {
FileInputStream in = null;
try {
in = new FileInputStream(BLFile);
StringBuffer buf = new StringBuffer(128);
StringBuilder buf = new StringBuilder(128);
// assume the file is unsorted, so go through the whole thing
while (DataHelper.readLine(in, buf)) {
Entry e = parse(buf, false);

View File

@@ -46,7 +46,7 @@ public class ClientTunnelSettings {
@Override
public String toString() {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
Properties p = new Properties();
writeToProperties(p);
buf.append("Client tunnel settings:\n");

View File

@@ -35,7 +35,7 @@ public abstract class JobImpl implements Job {
@Override
public String toString() {
StringBuffer buf = new StringBuffer(128);
StringBuilder buf = new StringBuilder(128);
buf.append(super.toString());
buf.append(": Job ").append(_id).append(": ").append(getName());
return buf.toString();

View File

@@ -245,7 +245,7 @@ public class JobQueue {
_jobLock.notifyAll();
}
if (_log.shouldLog(Log.WARN)) {
StringBuffer buf = new StringBuffer(1024);
StringBuilder buf = new StringBuilder(1024);
buf.append("current jobs: \n");
for (Iterator iter = _queueRunners.values().iterator(); iter.hasNext(); ) {
JobQueueRunner runner = (JobQueueRunner)iter.next();
@@ -587,7 +587,7 @@ public class JobQueue {
numRunners = _queueRunners.size();
}
StringBuffer str = new StringBuffer(128);
StringBuilder str = new StringBuilder(128);
str.append("<!-- after queueRunner sync: states: ");
for (int i = 0; states != null && i < states.length; i++)
str.append(states[i]).append(" ");
@@ -606,7 +606,7 @@ public class JobQueue {
out.write("<!-- jobQueue rendering: after jobLock sync -->\n");
out.flush();
StringBuffer buf = new StringBuffer(32*1024);
StringBuilder buf = new StringBuilder(32*1024);
buf.append("<h2>JobQueue</h2>");
buf.append("# runners: ").append(numRunners).append(" [states=");
if (states != null)
@@ -667,7 +667,7 @@ public class JobQueue {
}
/** render the HTML for the job stats */
private void getJobStats(StringBuffer buf) {
private void getJobStats(StringBuilder buf) {
buf.append("<table border=\"1\">\n");
buf.append("<tr><th>Job</th><th>Runs</th>");
buf.append("<th>Time</th><th><i>Avg</i></th><th><i>Max</i></th><th><i>Min</i></th>");

View File

@@ -77,7 +77,7 @@ class JobStats {
@Override
public String toString() {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append("Over ").append(getRuns()).append(" runs, job <b>").append(getName()).append("</b> took ");
buf.append(getTotalTime()).append("ms (").append(getAvgTime()).append("ms/").append(getMaxTime()).append("ms/");
buf.append(getMinTime()).append("ms avg/max/min) after a total lag of ");

View File

@@ -144,7 +144,7 @@ public class MessageHistory {
*/
public void requestTunnelCreate(TunnelId createTunnel, TunnelId outTunnel, Hash peerRequested, Hash nextPeer, TunnelId replyTunnel, Hash replyThrough) {
if (!_doLog) return;
StringBuffer buf = new StringBuffer(128);
StringBuilder buf = new StringBuilder(128);
buf.append(getPrefix());
buf.append("request [").append(getName(peerRequested)).append("] to create tunnel [");
buf.append(createTunnel.getTunnelId()).append("] ");
@@ -169,7 +169,7 @@ public class MessageHistory {
*/
public void receiveTunnelCreate(TunnelId createTunnel, Hash nextPeer, Date expire, boolean ok, Hash sourceRoutePeer) {
if (!_doLog) return;
StringBuffer buf = new StringBuffer(128);
StringBuilder buf = new StringBuilder(128);
buf.append(getPrefix());
buf.append("receive tunnel create [").append(createTunnel.getTunnelId()).append("] ");
if (nextPeer != null)
@@ -187,7 +187,7 @@ public class MessageHistory {
public void tunnelJoined(String state, TunnelInfo tunnel) {
if (!_doLog) return;
if (tunnel == null) return;
StringBuffer buf = new StringBuffer(128);
StringBuilder buf = new StringBuilder(128);
buf.append(getPrefix());
buf.append("joining as [").append(state);
buf.append("] to tunnel: ").append(tunnel.toString());
@@ -203,7 +203,7 @@ public class MessageHistory {
public void tunnelJoined(String state, HopConfig tunnel) {
if (!_doLog) return;
if (tunnel == null) return;
StringBuffer buf = new StringBuffer(128);
StringBuilder buf = new StringBuilder(128);
buf.append(getPrefix());
buf.append("joining as [").append(state);
buf.append("] to tunnel: ").append(tunnel.toString());
@@ -242,7 +242,7 @@ public class MessageHistory {
public void tunnelFailed(TunnelId tunnel) {
if (!_doLog) return;
if (tunnel == null) return;
StringBuffer buf = new StringBuffer(128);
StringBuilder buf = new StringBuilder(128);
buf.append(getPrefix());
buf.append("failing tunnel [").append(tunnel.getTunnelId()).append("]");
addEntry(buf.toString());
@@ -258,7 +258,7 @@ public class MessageHistory {
public void tunnelValid(TunnelInfo tunnel, long timeToTest) {
if (!_doLog) return;
if (tunnel == null) return;
StringBuffer buf = new StringBuffer(128);
StringBuilder buf = new StringBuilder(128);
buf.append(getPrefix());
buf.append("tunnel ").append(tunnel).append(" tested ok after ").append(timeToTest).append("ms");
addEntry(buf.toString());
@@ -271,7 +271,7 @@ public class MessageHistory {
public void tunnelRejected(Hash peer, TunnelId tunnel, Hash replyThrough, String reason) {
if (!_doLog) return;
if ( (tunnel == null) || (peer == null) ) return;
StringBuffer buf = new StringBuffer(128);
StringBuilder buf = new StringBuilder(128);
buf.append(getPrefix());
buf.append("tunnel [").append(tunnel.getTunnelId()).append("] was rejected by [");
buf.append(getName(peer)).append("] for [").append(reason).append("]");
@@ -283,7 +283,7 @@ public class MessageHistory {
public void tunnelParticipantRejected(Hash peer, String msg) {
if (!_doLog) return;
if (peer == null) return;
StringBuffer buf = new StringBuffer(128);
StringBuilder buf = new StringBuilder(128);
buf.append(getPrefix());
buf.append("tunnel participation rejected by [");
buf.append(getName(peer)).append("]: ").append(msg);
@@ -298,7 +298,7 @@ public class MessageHistory {
public void tunnelRequestTimedOut(Hash peer, TunnelId tunnel) {
if (!_doLog) return;
if ( (tunnel == null) || (peer == null) ) return;
StringBuffer buf = new StringBuffer(128);
StringBuilder buf = new StringBuilder(128);
buf.append(getPrefix());
buf.append("tunnel [").append(tunnel.getTunnelId()).append("] timed out on [");
buf.append(getName(peer)).append("]");
@@ -314,7 +314,7 @@ public class MessageHistory {
*/
public void droppedTunnelMessage(TunnelId id, long msgId, Date expiration, Hash from) {
if (!_doLog) return;
StringBuffer buf = new StringBuffer(128);
StringBuilder buf = new StringBuilder(128);
buf.append(getPrefix());
buf.append("dropped message ").append(msgId).append(" for unknown tunnel [").append(id.getTunnelId());
buf.append("] from [").append(getName(from)).append("]").append(" expiring on ");
@@ -328,7 +328,7 @@ public class MessageHistory {
public void droppedOtherMessage(I2NPMessage message, Hash from) {
if (!_doLog) return;
if (message == null) return;
StringBuffer buf = new StringBuffer(512);
StringBuilder buf = new StringBuilder(512);
buf.append(getPrefix());
buf.append("dropped [").append(message.getClass().getName()).append("] ").append(message.getUniqueId());
buf.append(" [").append(message.toString()).append("] from [");
@@ -342,7 +342,7 @@ public class MessageHistory {
public void droppedInboundMessage(long messageId, Hash from, String info) {
if (!_doLog) return;
StringBuffer buf = new StringBuffer(512);
StringBuilder buf = new StringBuilder(512);
buf.append(getPrefix());
buf.append("dropped inbound message ").append(messageId);
buf.append(" from ");
@@ -364,7 +364,7 @@ public class MessageHistory {
public void replyTimedOut(OutNetMessage sentMessage) {
if (!_doLog) return;
if (sentMessage == null) return;
StringBuffer buf = new StringBuffer(512);
StringBuilder buf = new StringBuilder(512);
buf.append(getPrefix());
buf.append("timed out waiting for a reply to [").append(sentMessage.getMessageType());
buf.append("] [").append(sentMessage.getMessageId()).append("] expiring on [");
@@ -383,7 +383,7 @@ public class MessageHistory {
*/
public void messageProcessingError(long messageId, String messageType, String error) {
if (!_doLog) return;
StringBuffer buf = new StringBuffer(128);
StringBuilder buf = new StringBuilder(128);
buf.append(getPrefix());
buf.append("Error processing [").append(messageType).append("] [").append(messageId).append("] failed with [").append(error).append("]");
addEntry(buf.toString());
@@ -420,7 +420,7 @@ public class MessageHistory {
public void sendMessage(String messageType, long messageId, long expiration, Hash peer, boolean sentOk, String info) {
if (!_doLog) return;
if (false) return;
StringBuffer buf = new StringBuffer(256);
StringBuilder buf = new StringBuilder(256);
buf.append(getPrefix());
buf.append("send [").append(messageType).append("] message [").append(messageId).append("] ");
buf.append("to [").append(getName(peer)).append("] ");
@@ -448,7 +448,7 @@ public class MessageHistory {
public void receiveMessage(String messageType, long messageId, long expiration, Hash from, boolean isValid) {
if (!_doLog) return;
if (false) return;
StringBuffer buf = new StringBuffer(256);
StringBuilder buf = new StringBuilder(256);
buf.append(getPrefix());
buf.append("receive [").append(messageType).append("] with id [").append(messageId).append("] ");
if (from != null)
@@ -470,7 +470,7 @@ public class MessageHistory {
*/
public void wrap(String bodyMessageType, long bodyMessageId, String containerMessageType, long containerMessageId) {
if (!_doLog) return;
StringBuffer buf = new StringBuffer(128);
StringBuilder buf = new StringBuilder(128);
buf.append(getPrefix());
buf.append("Wrap message [").append(bodyMessageType).append("] id [").append(bodyMessageId).append("] ");
buf.append("in [").append(containerMessageType).append("] id [").append(containerMessageId).append("]");
@@ -483,7 +483,7 @@ public class MessageHistory {
*/
public void receivePayloadMessage(long messageId) {
if (!_doLog) return;
StringBuffer buf = new StringBuffer(64);
StringBuilder buf = new StringBuilder(64);
buf.append(getPrefix());
buf.append("Receive payload message [").append(messageId).append("]");
addEntry(buf.toString());
@@ -498,7 +498,7 @@ public class MessageHistory {
*/
public void sendPayloadMessage(long messageId, boolean successfullySent, long timeToSend) {
if (!_doLog) return;
StringBuffer buf = new StringBuffer(128);
StringBuilder buf = new StringBuilder(128);
buf.append(getPrefix());
buf.append("Send payload message in [").append(messageId).append("] in [").append(timeToSend).append("] successfully? ").append(successfullySent);
addEntry(buf.toString());
@@ -507,7 +507,7 @@ public class MessageHistory {
public void receiveTunnelFragment(long messageId, int fragmentId, Object status) {
if (!_doLog) return;
if (messageId == -1) throw new IllegalArgumentException("why are you -1?");
StringBuffer buf = new StringBuffer(48);
StringBuilder buf = new StringBuilder(48);
buf.append(getPrefix());
buf.append("Receive fragment ").append(fragmentId).append(" in ").append(messageId);
buf.append(" status: ").append(status.toString());
@@ -516,7 +516,7 @@ public class MessageHistory {
public void receiveTunnelFragmentComplete(long messageId) {
if (!_doLog) return;
if (messageId == -1) throw new IllegalArgumentException("why are you -1?");
StringBuffer buf = new StringBuffer(48);
StringBuilder buf = new StringBuilder(48);
buf.append(getPrefix());
buf.append("Receive fragmented message completely: ").append(messageId);
addEntry(buf.toString());
@@ -524,7 +524,7 @@ public class MessageHistory {
public void droppedFragmentedMessage(long messageId, String status) {
if (!_doLog) return;
if (messageId == -1) throw new IllegalArgumentException("why are you -1?");
StringBuffer buf = new StringBuffer(48);
StringBuilder buf = new StringBuilder(48);
buf.append(getPrefix());
buf.append("Fragmented message dropped: ").append(messageId);
buf.append(" ").append(status);
@@ -533,7 +533,7 @@ public class MessageHistory {
public void fragmentMessage(long messageId, int numFragments, int totalLength, List messageIds, String msg) {
if (!_doLog) return;
//if (messageId == -1) throw new IllegalArgumentException("why are you -1?");
StringBuffer buf = new StringBuffer(48);
StringBuilder buf = new StringBuilder(48);
buf.append(getPrefix());
buf.append("Break message ").append(messageId).append(" into fragments: ").append(numFragments);
buf.append(" total size ").append(totalLength);
@@ -545,7 +545,7 @@ public class MessageHistory {
public void fragmentMessage(long messageId, int numFragments, int totalLength, List messageIds, Object tunnel, String msg) {
if (!_doLog) return;
//if (messageId == -1) throw new IllegalArgumentException("why are you -1?");
StringBuffer buf = new StringBuffer(48);
StringBuilder buf = new StringBuilder(48);
buf.append(getPrefix());
buf.append("Break message ").append(messageId).append(" into fragments: ").append(numFragments);
buf.append(" total size ").append(totalLength);
@@ -559,7 +559,7 @@ public class MessageHistory {
public void droppedTunnelDataMessageUnknown(long msgId, long tunnelId) {
if (!_doLog) return;
if (msgId == -1) throw new IllegalArgumentException("why are you -1?");
StringBuffer buf = new StringBuffer(48);
StringBuilder buf = new StringBuilder(48);
buf.append(getPrefix());
buf.append("Dropped data message ").append(msgId).append(" for unknown tunnel ").append(tunnelId);
addEntry(buf.toString());
@@ -567,7 +567,7 @@ public class MessageHistory {
public void droppedTunnelGatewayMessageUnknown(long msgId, long tunnelId) {
if (!_doLog) return;
if (msgId == -1) throw new IllegalArgumentException("why are you -1?");
StringBuffer buf = new StringBuffer(48);
StringBuilder buf = new StringBuilder(48);
buf.append(getPrefix());
buf.append("Dropped gateway message ").append(msgId).append(" for unknown tunnel ").append(tunnelId);
addEntry(buf.toString());
@@ -585,7 +585,7 @@ public class MessageHistory {
}
private final String getPrefix() {
StringBuffer buf = new StringBuffer(48);
StringBuilder buf = new StringBuilder(48);
buf.append(getTime(_context.clock().now()));
buf.append(' ').append(_localIdent).append(": ");
return buf.toString();

View File

@@ -77,7 +77,7 @@ public class MultiRouterBuilder {
buildStartupScriptNix(args);
}
private static void buildStartupScriptNix(String args[]) {
StringBuffer buf = new StringBuffer(4096);
StringBuilder buf = new StringBuilder(4096);
buf.append("#!/bin/sh\n");
buf.append("export CP=.; for LIB in lib/* ; do export CP=$CP:$LIB ; done\n");
buf.append("nohup java -cp $CP ");
@@ -106,7 +106,7 @@ public class MultiRouterBuilder {
File baseDir = new File(dir);
baseDir.mkdirs();
File cfgFile = new File(baseDir, "router.config");
StringBuffer buf = new StringBuffer(8*1024);
StringBuilder buf = new StringBuilder(8*1024);
buf.append("router.profileDir=").append(baseDir.getPath()).append("/peerProfiles\n");
buf.append("router.historyFilename=").append(baseDir.getPath()).append("/messageHistory.txt\n");
buf.append("router.sessionKeys.location=").append(baseDir.getPath()).append("/sessionKeys.dat\n");

View File

@@ -287,7 +287,7 @@ public class OutNetMessage {
public void finalize() throws Throwable {
if (_message != null) {
if (_log.shouldLog(Log.WARN)) {
StringBuffer buf = new StringBuffer(1024);
StringBuilder buf = new StringBuilder(1024);
buf.append("Undiscarded ").append(_messageSize).append("byte ");
buf.append(_messageType).append(" message created ");
buf.append((_context.clock().now() - _created)).append("ms ago: ");
@@ -304,7 +304,7 @@ public class OutNetMessage {
*/
@Override
public String toString() {
StringBuffer buf = new StringBuffer(128);
StringBuilder buf = new StringBuilder(128);
buf.append("[OutNetMessage contains ");
if (_message == null) {
buf.append("*no message*");
@@ -334,7 +334,7 @@ public class OutNetMessage {
return buf.toString();
}
private void renderTimestamps(StringBuffer buf) {
private void renderTimestamps(StringBuilder buf) {
if (_log.shouldLog(Log.INFO)) {
synchronized (this) {
long lastWhen = -1;

View File

@@ -66,7 +66,7 @@ public class PersistentKeyRing extends KeyRing {
@Override
public void renderStatusHTML(Writer out) throws IOException {
StringBuffer buf = new StringBuffer(1024);
StringBuilder buf = new StringBuilder(1024);
buf.append("\n<table border=\"1\"><tr><th align=\"left\">Destination Hash<th align=\"left\">Name or Dest.<th align=\"left\">Session Key</tr>");
for (Entry<Hash, SessionKey> e : entrySet()) {
buf.append("\n<tr><td>");

View File

@@ -589,7 +589,7 @@ public class Router {
"</select> <input type=\"submit\" value=\"GO\" /> </form>" +
"<hr />\n");
StringBuffer buf = new StringBuffer(32*1024);
StringBuilder buf = new StringBuilder(32*1024);
if ( (_routerInfo != null) && (_routerInfo.getIdentity() != null) )
buf.append("<b>Router: </b> ").append(_routerInfo.getIdentity().getHash().toBase64()).append("<br />\n");
@@ -762,7 +762,7 @@ public class Router {
}
private static int MAX_MSG_LENGTH = 120;
private static final void appendLogMessage(StringBuffer buf, String msg) {
private static final void appendLogMessage(StringBuilder buf, String msg) {
// disable this code for the moment because i think it
// looks ugly (on the router console)
if (true) {
@@ -804,7 +804,7 @@ public class Router {
/** main-ish method for testing appendLogMessage */
private static final void testAppendLog() {
StringBuffer buf = new StringBuffer(1024);
StringBuilder buf = new StringBuilder(1024);
Router.appendLogMessage(buf, "hi\nhow are you\nh0h0h0");
System.out.println("line: [" + buf.toString() + "]");
buf.setLength(0);
@@ -1005,7 +1005,7 @@ public class Router {
FileOutputStream fos = null;
try {
fos = new FileOutputStream(_configFilename);
StringBuffer buf = new StringBuffer(8*1024);
StringBuilder buf = new StringBuilder(8*1024);
synchronized (_config) {
TreeSet ordered = new TreeSet(_config.keySet());
for (Iterator iter = ordered.iterator() ; iter.hasNext(); ) {

View File

@@ -268,7 +268,7 @@ public class RouterContext extends I2PAppContext {
@Override
public String toString() {
StringBuffer buf = new StringBuffer(512);
StringBuilder buf = new StringBuilder(512);
buf.append("RouterContext: ").append(super.toString()).append('\n');
buf.append(_router).append('\n');
buf.append(_clientManagerFacade).append('\n');

View File

@@ -252,7 +252,7 @@ public class Shitlist {
}
public void renderStatusHTML(Writer out) throws IOException {
StringBuffer buf = new StringBuffer(1024);
StringBuilder buf = new StringBuilder(1024);
buf.append("<h2>Shitlist</h2>");
Map<Hash, Entry> entries = new TreeMap(new HashComparator());

View File

@@ -200,7 +200,7 @@ public class StatisticsManager implements Service {
}
private String renderRate(Rate rate, boolean fudgeQuantity) {
StringBuffer buf = new StringBuffer(128);
StringBuilder buf = new StringBuilder(128);
buf.append(num(rate.getAverageValue())).append(';');
buf.append(num(rate.getExtremeAverageValue())).append(';');
buf.append(pct(rate.getPercentageOfLifetimeValue())).append(';');
@@ -259,7 +259,7 @@ public class StatisticsManager implements Service {
}
private String renderRate(Rate rate, double fudgeQuantity) {
StringBuffer buf = new StringBuffer(128);
StringBuilder buf = new StringBuilder(128);
buf.append(num(rate.getAverageValue())).append(';');
buf.append(num(rate.getExtremeAverageValue())).append(';');
buf.append(pct(rate.getPercentageOfLifetimeValue())).append(';');

View File

@@ -187,7 +187,7 @@ public class TunnelPoolSettings {
@Override
public String toString() {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
Properties p = new Properties();
writeToProperties("", p);
buf.append("Tunnel pool settings:\n");

View File

@@ -73,7 +73,7 @@ class AdminRunner implements Runnable {
}
private void reply(OutputStream out, String content) throws IOException {
StringBuffer reply = new StringBuffer(10240);
StringBuilder reply = new StringBuilder(10240);
reply.append("HTTP/1.1 200 OK\n");
reply.append("Connection: close\n");
reply.append("Cache-control: no-cache\n");
@@ -90,7 +90,7 @@ class AdminRunner implements Runnable {
}
private void replyText(OutputStream out, String content) throws IOException {
StringBuffer reply = new StringBuffer(10240);
StringBuilder reply = new StringBuilder(10240);
reply.append("HTTP/1.1 200 OK\n");
reply.append("Connection: close\n");
reply.append("Cache-control: no-cache\n");

View File

@@ -28,7 +28,7 @@ public class StatsGenerator {
}
public void generateStatsPage(Writer out) throws IOException {
StringBuffer buf = new StringBuffer(16*1024);
StringBuilder buf = new StringBuilder(16*1024);
buf.append("<h1>Router statistics</h1><hr />");
buf.append("<form action=\"/oldstats.jsp\">");
buf.append("<select name=\"go\" onChange='location.href=this.value'>");
@@ -94,7 +94,7 @@ public class StatsGenerator {
out.flush();
}
private void renderFrequency(String name, StringBuffer buf) {
private void renderFrequency(String name, StringBuilder buf) {
FrequencyStat freq = _context.statManager().getFrequency(name);
buf.append("<i>");
buf.append(freq.getDescription());
@@ -130,7 +130,7 @@ public class StatsGenerator {
buf.append("<br />");
}
private void renderRate(String name, StringBuffer buf) {
private void renderRate(String name, StringBuilder buf) {
RateStat rate = _context.statManager().getRate(name);
String d = rate.getDescription();
if (! "".equals(d)) {
@@ -223,7 +223,7 @@ public class StatsGenerator {
buf.append("<br />");
}
private static void renderPeriod(StringBuffer buf, long period, String name) {
private static void renderPeriod(StringBuilder buf, long period, String name) {
buf.append("<b>");
buf.append(DataHelper.formatDuration(period));
buf.append(" ");

View File

@@ -387,7 +387,7 @@ public class ClientManager {
}
public void renderStatusHTML(Writer out) throws IOException {
StringBuffer buf = new StringBuffer(8*1024);
StringBuilder buf = new StringBuilder(8*1024);
buf.append("<u><b>Local destinations</b></u><br />");
Map runners = null;

View File

@@ -44,7 +44,7 @@ public class CloveSet {
@Override
public String toString() {
StringBuffer buf = new StringBuffer(128);
StringBuilder buf = new StringBuilder(128);
buf.append("{");
for (int i = 0; i < _cloves.size(); i++) {
GarlicClove clove = (GarlicClove)_cloves.get(i);

View File

@@ -158,7 +158,7 @@ public class GarlicConfig {
private final static String NL = System.getProperty("line.separator");
@Override
public String toString() {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append("<garlicConfig>").append(NL);
buf.append("<certificate>").append(getCertificate()).append("</certificate>").append(NL);
buf.append("<instructions>").append(getDeliveryInstructions()).append("</instructions>").append(NL);

View File

@@ -35,7 +35,7 @@ public class PayloadGarlicConfig extends GarlicConfig {
@Override
protected String getSubData() {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append("<payloadMessage>").append(_payload).append("</payloadMessage>");
return buf.toString();
}

View File

@@ -330,7 +330,7 @@ class KBucketImpl implements KBucket {
@Override
public String toString() {
StringBuffer buf = new StringBuffer(1024);
StringBuilder buf = new StringBuilder(1024);
buf.append("KBucketImpl: ");
synchronized (_entries) {
buf.append(_entries.toString()).append("\n");
@@ -380,7 +380,7 @@ class KBucketImpl implements KBucket {
}
private static void testRand() {
StringBuffer buf = new StringBuffer(2048);
StringBuilder buf = new StringBuilder(2048);
int low = 1;
int high = 3;
Log log = I2PAppContext.getGlobalContext().logManager().getLog(KBucketImpl.class);
@@ -416,7 +416,7 @@ class KBucketImpl implements KBucket {
private static void testRand2() {
Log log = I2PAppContext.getGlobalContext().logManager().getLog(KBucketImpl.class);
StringBuffer buf = new StringBuffer(1024*1024*16);
StringBuilder buf = new StringBuilder(1024*1024*16);
int low = 1;
int high = 200;
byte hash[] = new byte[Hash.HASH_LENGTH];
@@ -452,7 +452,7 @@ class KBucketImpl implements KBucket {
private final static String toString(byte b[]) {
if (true) return DataHelper.toHexString(b);
StringBuffer buf = new StringBuffer(b.length);
StringBuilder buf = new StringBuilder(b.length);
for (int i = 0; i < b.length; i++) {
buf.append(toString(b[i]));
buf.append(" ");
@@ -461,7 +461,7 @@ class KBucketImpl implements KBucket {
}
private final static String toString(byte b) {
StringBuffer buf = new StringBuffer(8);
StringBuilder buf = new StringBuilder(8);
for (int i = 7; i >= 0; i--) {
boolean bb = (0 != (b & (1<<i)));
if (bb)

View File

@@ -141,7 +141,7 @@ class KBucketSet {
@Override
public String toString() {
BigInteger us = new BigInteger(1, _us.getData());
StringBuffer buf = new StringBuffer(1024);
StringBuilder buf = new StringBuilder(1024);
buf.append("Bucket set rooted on: ").append(us.toString()).append(" (aka ").append(us.toString(2)).append("): \n");
for (int i = 0; i < NUM_BUCKETS; i++) {
buf.append("* Bucket ").append(i).append("/").append(NUM_BUCKETS-1).append(": )\n");
@@ -159,7 +159,7 @@ class KBucketSet {
System.arraycopy(b, 0, val, Hash.HASH_LENGTH-b.length-1, b.length);
else
System.arraycopy(b, Hash.HASH_LENGTH-b.length, val, 0, val.length);
StringBuffer buf = new StringBuffer(KEYSIZE_BITS);
StringBuilder buf = new StringBuilder(KEYSIZE_BITS);
for (int i = 0; i < val.length; i++) {
for (int j = 7; j >= 0; j--) {
boolean bb = (0 != (val[i] & (1<<j)));

View File

@@ -910,7 +910,7 @@ public class KademliaNetworkDatabaseFacade extends NetworkDatabaseFacade {
@Override
public void renderRouterInfoHTML(Writer out, String routerPrefix) throws IOException {
StringBuffer buf = new StringBuffer(4*1024);
StringBuilder buf = new StringBuilder(4*1024);
buf.append("<h2>Network Database RouterInfo Lookup</h2>\n");
if (".".equals(routerPrefix)) {
renderRouterInfo(buf, _context.router().getRouterInfo(), true, true);
@@ -938,7 +938,7 @@ public class KademliaNetworkDatabaseFacade extends NetworkDatabaseFacade {
@Override
public void renderLeaseSetHTML(Writer out) throws IOException {
StringBuffer buf = new StringBuffer(4*1024);
StringBuilder buf = new StringBuilder(4*1024);
buf.append("<h2>Network Database Contents</h2>\n");
buf.append("<a href=\"netdb.jsp\">View RouterInfo</a>");
buf.append("<h3>LeaseSets</h3>\n");
@@ -992,7 +992,7 @@ public class KademliaNetworkDatabaseFacade extends NetworkDatabaseFacade {
int size = getKnownRouters() * 512;
if (full)
size *= 4;
StringBuffer buf = new StringBuffer(size);
StringBuilder buf = new StringBuilder(size);
out.write("<h2>Network Database Contents</h2>\n");
if (!_initialized) {
buf.append("<i>Not initialized</i>\n");
@@ -1073,7 +1073,7 @@ public class KademliaNetworkDatabaseFacade extends NetworkDatabaseFacade {
out.flush();
}
private void renderRouterInfo(StringBuffer buf, RouterInfo info, boolean isUs, boolean full) {
private void renderRouterInfo(StringBuilder buf, RouterInfo info, boolean isUs, boolean full) {
String hash = info.getIdentity().getHash().toBase64();
buf.append("<a name=\"").append(hash.substring(0, 6)).append("\" />");
if (isUs) {

View File

@@ -168,7 +168,7 @@ class SearchState {
@Override
public String toString() {
StringBuffer buf = new StringBuffer(256);
StringBuilder buf = new StringBuilder(256);
buf.append("Searching for ").append(_searchKey);
buf.append(" ");
if (_completed <= 0)

View File

@@ -57,7 +57,7 @@ class StoreMessageSelector implements MessageSelector {
@Override
public String toString() {
StringBuffer rv = new StringBuffer(64);
StringBuilder rv = new StringBuilder(64);
rv.append("Waiting for netDb confirm from ").append(_peer.toBase64()).append(", found? ");
rv.append(_found).append(" waiting for ").append(_waitingForId);
return rv.toString();

View File

@@ -149,7 +149,7 @@ class StoreState {
@Override
public String toString() {
StringBuffer buf = new StringBuffer(256);
StringBuilder buf = new StringBuilder(256);
buf.append("Storing ").append(_key);
buf.append(" ");
if (_completed <= 0)

View File

@@ -147,7 +147,7 @@ class TransientDataStore implements DataStore {
}
@Override
public String toString() {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append("Transient DataStore: ").append(_data.size()).append("\nKeys: ");
for (Map.Entry<Hash, DataStructure> e : _data.entrySet()) {
Hash key = e.getKey();

View File

@@ -165,7 +165,7 @@ public class DBHistory {
private final static String NL = System.getProperty("line.separator");
public void store(OutputStream out) throws IOException {
StringBuffer buf = new StringBuffer(512);
StringBuilder buf = new StringBuilder(512);
buf.append(NL);
buf.append("#################").append(NL);
buf.append("# DB history").append(NL);
@@ -186,7 +186,7 @@ public class DBHistory {
_invalidReplyRate.store(out, "dbHistory.invalidReplyRate");
}
private void add(StringBuffer buf, String name, long val, String description) {
private void add(StringBuilder buf, String name, long val, String description) {
buf.append("# ").append(name.toUpperCase()).append(NL).append("# ").append(description).append(NL);
buf.append("dbHistory.").append(name).append('=').append(val).append(NL).append(NL);
}

View File

@@ -297,7 +297,7 @@ public class PeerProfile {
}
if (_log.shouldLog(Log.DEBUG) ) {
StringBuffer buf = new StringBuffer(128);
StringBuilder buf = new StringBuilder(128);
buf.append("Updating 1m throughput after ").append(size).append(" to ");
for (int i = 0; i < THROUGHPUT_COUNT; i++)
buf.append(_peakTunnel1mThroughput[i]).append(',');
@@ -509,7 +509,7 @@ public class PeerProfile {
fmt.setPositivePrefix("+");
ProfilePersistenceHelper helper = new ProfilePersistenceHelper(ctx);
try { Thread.sleep(5*1000); } catch (InterruptedException e) {}
StringBuffer buf = new StringBuffer(1024);
StringBuilder buf = new StringBuilder(1024);
for (int i = 0; i < args.length; i++) {
PeerProfile profile = helper.readProfile(new File(args[i]));
if (profile == null) {

View File

@@ -224,7 +224,7 @@ public class PeerTestJob extends JobImpl {
public boolean matchFound() { return _matchFound; }
@Override
public String toString() {
StringBuffer buf = new StringBuffer(64);
StringBuilder buf = new StringBuilder(64);
buf.append("Test peer ").append(_peer.toBase64().substring(0,4));
buf.append(" with nonce ").append(_nonce);
return buf.toString();

View File

@@ -304,7 +304,7 @@ public class ProfileManagerImpl implements ProfileManager {
PeerProfile prof = getProfile(peer);
if (prof == null) continue;
StringBuffer buf = new StringBuffer(64);
StringBuilder buf = new StringBuilder(64);
buf.append("status: ");
if (_context.profileOrganizer().isFast(peer)) {

View File

@@ -676,7 +676,7 @@ public class ProfileOrganizer {
+ ", capacity: " + _thresholdCapacityValue + ", speed: " + _thresholdSpeedValue + "]");
/*****
if (_log.shouldLog(Log.DEBUG)) {
StringBuffer buf = new StringBuffer(512);
StringBuilder buf = new StringBuilder(512);
for (Iterator iter = _strictCapacityOrder.iterator(); iter.hasNext(); ) {
PeerProfile prof = (PeerProfile)iter.next();
buf.append('[').append(prof.toString()).append('=').append(prof.getCapacityValue()).append("] ");

View File

@@ -56,7 +56,7 @@ class ProfileOrganizerRenderer {
int reliable = 0;
int integrated = 0;
int failing = 0;
StringBuffer buf = new StringBuffer(16*1024);
StringBuilder buf = new StringBuilder(16*1024);
buf.append("<h2>Peer Profiles</h2>\n");
buf.append("<p>Showing ").append(order.size()).append(" recent profiles, hiding ").append(peers.size()-order.size()).append(" older profiles</p>");
buf.append("<table border=\"1\">");

View File

@@ -89,7 +89,7 @@ class ProfilePersistenceHelper {
groups = groups + ", well integrated";
}
StringBuffer buf = new StringBuffer(512);
StringBuilder buf = new StringBuilder(512);
buf.append("########################################################################").append(NL);
buf.append("# profile for ").append(profile.getPeer().toBase64()).append(NL);
if (_us != null)

View File

@@ -131,7 +131,7 @@ public class TunnelHistory {
private final static String NL = System.getProperty("line.separator");
public void store(OutputStream out) throws IOException {
StringBuffer buf = new StringBuffer(512);
StringBuilder buf = new StringBuilder(512);
buf.append(NL);
buf.append("#################").append(NL);
buf.append("# Tunnel history").append(NL);
@@ -150,7 +150,7 @@ public class TunnelHistory {
_failRate.store(out, "tunnelHistory.failRate");
}
private void add(StringBuffer buf, String name, long val, String description) {
private void add(StringBuilder buf, String name, long val, String description) {
buf.append("# ").append(name.toUpperCase()).append(NL).append("# ").append(description).append(NL);
buf.append("tunnels.").append(name).append('=').append(val).append(NL).append(NL);
}

View File

@@ -99,7 +99,7 @@ public class ClientAppConfig {
FileOutputStream fos = null;
try {
fos = new FileOutputStream(cfgFile);
StringBuffer buf = new StringBuffer(2048);
StringBuilder buf = new StringBuilder(2048);
for(int i = 0; i < apps.size(); i++) {
ClientAppConfig app = (ClientAppConfig) apps.get(i);
buf.append(PREFIX).append(i).append(".main=").append(app.className).append("\n");

View File

@@ -64,7 +64,7 @@ public class LoadClientAppsJob extends JobImpl {
List argList = new ArrayList(4);
if (args != null) {
char data[] = args.toCharArray();
StringBuffer buf = new StringBuffer(32);
StringBuilder buf = new StringBuilder(32);
boolean isQuoted = false;
for (int i = 0; i < data.length; i++) {
switch (data[i]) {
@@ -74,7 +74,7 @@ public class LoadClientAppsJob extends JobImpl {
String str = buf.toString().trim();
if (str.length() > 0)
argList.add(str);
buf = new StringBuffer(32);
buf = new StringBuilder(32);
} else {
isQuoted = true;
}
@@ -89,7 +89,7 @@ public class LoadClientAppsJob extends JobImpl {
String str = buf.toString().trim();
if (str.length() > 0)
argList.add(str);
buf = new StringBuffer(32);
buf = new StringBuilder(32);
}
break;
default:

View File

@@ -448,7 +448,7 @@ public class CommSystemFacadeImpl extends CommSystemFacade {
/** Provide a consistent "look" for displaying router IDs in the console */
public String renderPeerHTML(Hash peer) {
String h = peer.toBase64().substring(0, 4);
StringBuffer buf = new StringBuffer(128);
StringBuilder buf = new StringBuilder(128);
String c = getCountry(peer);
if (c != null) {
buf.append("<img alt=\"").append(c.toUpperCase()).append("\" title=\"");

View File

@@ -199,8 +199,8 @@ public class FIFOBandwidthLimiter {
void setInboundBurstBytes(int bytes) { _maxInboundBurst = bytes; }
void setOutboundBurstBytes(int bytes) { _maxOutboundBurst = bytes; }
StringBuffer getStatus() {
StringBuffer rv = new StringBuffer(64);
StringBuilder getStatus() {
StringBuilder rv = new StringBuilder(64);
rv.append("Available: ").append(_availableInbound).append('/').append(_availableOutbound).append(' ');
rv.append("Max: ").append(_maxInbound).append('/').append(_maxOutbound).append(' ');
rv.append("Burst: ").append(_unavailableInboundBurst).append('/').append(_unavailableOutboundBurst).append(' ');
@@ -618,7 +618,7 @@ public class FIFOBandwidthLimiter {
public void renderStatusHTML(Writer out) throws IOException {
long now = now();
StringBuffer buf = new StringBuffer(4096);
StringBuilder buf = new StringBuilder(4096);
buf.append("<p><b id=\"bwlim\">Limiter Status:</b><br />").append(getStatus().toString()).append("</p>\n");
buf.append("<p><b>Pending bandwidth requests:</b><ul>");
buf.append("<li>Inbound requests: <ol>");

View File

@@ -140,7 +140,7 @@ public class GeoIP {
FileInputStream in = null;
try {
in = new FileInputStream(GeoFile);
StringBuffer buf = new StringBuffer(128);
StringBuilder buf = new StringBuilder(128);
while (DataHelper.readLine(in, buf)) {
try {
if (buf.charAt(0) == '#') {
@@ -202,7 +202,7 @@ public class GeoIP {
FileInputStream in = null;
try {
in = new FileInputStream(GeoFile);
StringBuffer buf = new StringBuffer(128);
StringBuilder buf = new StringBuilder(128);
while (DataHelper.readLine(in, buf) && idx < search.length) {
try {
if (buf.charAt(0) == '#') {

View File

@@ -364,7 +364,7 @@ public abstract class TransportImpl implements Transport {
if (msToReceive > 5000)
level = Log.WARN;
if (_log.shouldLog(level)) {
StringBuffer buf = new StringBuffer(128);
StringBuilder buf = new StringBuilder(128);
buf.append("Message received: ").append(inMsg.getClass().getName());
buf.append(" / ").append(inMsg.getUniqueId());
buf.append(" in ").append(msToReceive).append("ms containing ");

View File

@@ -486,7 +486,7 @@ public class TransportManager implements TransportEventListener {
Transport t= (Transport)iter.next();
t.renderStatusHTML(out, urlBase, sortFlags);
}
StringBuffer buf = new StringBuffer(4*1024);
StringBuilder buf = new StringBuilder(4*1024);
buf.append("<p><b>Router Transport Addresses:</b><br /><pre>\n");
for (int i = 0; i < _transports.size(); i++) {
Transport t = (Transport)_transports.get(i);

View File

@@ -662,7 +662,7 @@ public class EstablishState {
private String prefix() { return toString(); }
@Override
public String toString() {
StringBuffer buf = new StringBuffer(64);
StringBuilder buf = new StringBuilder(64);
buf.append("est").append(System.identityHashCode(this));
if (_con.isInbound()) buf.append(" inbound");
else buf.append(" outbound");

View File

@@ -643,7 +643,7 @@ public class NTCPTransport extends TransportImpl {
long totalSend = 0;
long totalRecv = 0;
StringBuffer buf = new StringBuffer(512);
StringBuilder buf = new StringBuilder(512);
buf.append("<p><b id=\"ntcpcon\">NTCP connections: ").append(peers.size());
buf.append(" limit: ").append(getMaxConnections());
buf.append(" timeout: ").append(DataHelper.formatDuration(_pumper.getIdleTimeout()));

View File

@@ -181,7 +181,7 @@ public class InboundEstablishState {
_sentSignature = _context.dsa().sign(signed, _context.keyManager().getSigningPrivateKey());
if (_log.shouldLog(Log.DEBUG)) {
StringBuffer buf = new StringBuffer(128);
StringBuilder buf = new StringBuilder(128);
buf.append("Signing sessionCreated:");
buf.append(" ReceivedX: ").append(Base64.encode(_receivedX));
buf.append(" SentY: ").append(Base64.encode(_sentY));
@@ -333,7 +333,7 @@ public class InboundEstablishState {
@Override
public String toString() {
StringBuffer buf = new StringBuffer(128);
StringBuilder buf = new StringBuilder(128);
buf.append(super.toString());
if (_receivedX != null)
buf.append(" ReceivedX: ").append(Base64.encode(_receivedX, 0, 4));

View File

@@ -140,7 +140,7 @@ public class InboundMessageState {
@Override
public String toString() {
StringBuffer buf = new StringBuffer(64);
StringBuilder buf = new StringBuilder(64);
buf.append("Partial ACK of ");
buf.append(_bitfieldMessageId);
buf.append(" with ACKs for: ");
@@ -165,7 +165,7 @@ public class InboundMessageState {
@Override
public String toString() {
StringBuffer buf = new StringBuffer(32);
StringBuilder buf = new StringBuilder(32);
buf.append("Message: ").append(_messageId);
if (isComplete()) {
buf.append(" completely received with ");

View File

@@ -291,7 +291,7 @@ public class OutboundEstablishState {
DataHelper.toLong(signed, off, 4, _receivedSignedOnTime);
boolean valid = _context.dsa().verifySignature(_receivedSignature, signed, _remotePeer.getSigningPublicKey());
if (!valid || _log.shouldLog(Log.DEBUG)) {
StringBuffer buf = new StringBuffer(128);
StringBuilder buf = new StringBuilder(128);
buf.append("Signed sessionCreated:");
buf.append(" AliceIP: ").append(Base64.encode(_aliceIP));
buf.append(" AlicePort: ").append(_alicePort);

View File

@@ -295,7 +295,7 @@ public class OutboundMessageState {
public String toString() {
short sends[] = _fragmentSends;
ByteArray messageBuf = _messageBuf;
StringBuffer buf = new StringBuffer(64);
StringBuilder buf = new StringBuilder(64);
buf.append("Message ").append(_messageId);
if (sends != null)
buf.append(" with ").append(sends.length).append(" fragments");

View File

@@ -61,10 +61,10 @@ public class PacketBuilder {
public UDPPacket buildPacket(OutboundMessageState state, int fragment, PeerState peer, List ackIdsRemaining, List partialACKsRemaining) {
UDPPacket packet = UDPPacket.acquire(_context, false);
StringBuffer msg = null;
StringBuilder msg = null;
boolean acksIncluded = false;
if (_log.shouldLog(Log.INFO)) {
msg = new StringBuffer(128);
msg = new StringBuilder(128);
msg.append("Send to ").append(peer.getRemotePeer().toBase64());
msg.append(" msg ").append(state.getMessageId()).append(":").append(fragment);
if (fragment == state.getFragmentCount() - 1)
@@ -219,9 +219,9 @@ public class PacketBuilder {
public UDPPacket buildACK(PeerState peer, List ackBitfields) {
UDPPacket packet = UDPPacket.acquire(_context, false);
StringBuffer msg = null;
StringBuilder msg = null;
if (_log.shouldLog(Log.DEBUG)) {
msg = new StringBuffer(128);
msg = new StringBuilder(128);
msg.append("building ACK packet to ").append(peer.getRemotePeer().toBase64().substring(0,6));
}
@@ -379,7 +379,7 @@ public class PacketBuilder {
off += 8;
if (_log.shouldLog(Log.DEBUG)) {
StringBuffer buf = new StringBuffer(128);
StringBuilder buf = new StringBuilder(128);
buf.append("Sending sessionCreated:");
buf.append(" AliceIP: ").append(Base64.encode(sentIP));
buf.append(" AlicePort: ").append(state.getSentPort());

View File

@@ -93,7 +93,7 @@ public class PacketHandler {
}
String getHandlerStatus() {
StringBuffer rv = new StringBuffer();
StringBuilder rv = new StringBuilder();
int size = _handlers.size();
rv.append("Handlers: ").append(size);
for (int i = 0; i < size; i++) {
@@ -324,7 +324,7 @@ public class PacketHandler {
private void receivePacket(UDPPacketReader reader, UDPPacket packet, InboundEstablishState state, boolean allowFallback) {
_state = 31;
if ( (state != null) && (_log.shouldLog(Log.DEBUG)) ) {
StringBuffer buf = new StringBuffer(128);
StringBuilder buf = new StringBuilder(128);
buf.append("Attempting to receive a packet on a known inbound state: ");
buf.append(state);
buf.append(" MAC key: ").append(state.getMACKey());
@@ -362,7 +362,7 @@ public class PacketHandler {
private void receivePacket(UDPPacketReader reader, UDPPacket packet, OutboundEstablishState state) {
_state = 35;
if ( (state != null) && (_log.shouldLog(Log.DEBUG)) ) {
StringBuffer buf = new StringBuffer(128);
StringBuilder buf = new StringBuilder(128);
buf.append("Attempting to receive a packet on a known outbound state: ");
buf.append(state);
buf.append(" MAC key: ").append(state.getMACKey());
@@ -470,7 +470,7 @@ public class PacketHandler {
if (state != null) {
UDPPacketReader.DataReader dr = reader.getDataReader();
if (_log.shouldLog(Log.INFO)) {
StringBuffer msg = new StringBuffer();
StringBuilder msg = new StringBuilder();
msg.append("Receive ").append(System.identityHashCode(packet));
msg.append(" from ").append(state.getRemotePeer().toBase64()).append(" ").append(state.getRemoteHostId());
for (int i = 0; i < dr.readFragmentCount(); i++) {

View File

@@ -1555,7 +1555,7 @@ public class PeerState {
@Override
public String toString() {
StringBuffer buf = new StringBuffer(64);
StringBuilder buf = new StringBuilder(64);
buf.append(_remoteHostId.toString());
if (_remotePeer != null)
buf.append(" ").append(_remotePeer.toBase64().substring(0,6));

View File

@@ -98,7 +98,7 @@ class PeerTestState {
@Override
public synchronized String toString() {
StringBuffer buf = new StringBuffer(512);
StringBuilder buf = new StringBuilder(512);
buf.append("Role: ");
if (_ourRole == ALICE) buf.append("Alice");
else if (_ourRole == BOB) buf.append("Bob");

View File

@@ -60,7 +60,7 @@ final class RemoteHostId {
}
}
public static String toString(byte ip[]) {
StringBuffer buf = new StringBuffer(ip.length+5);
StringBuilder buf = new StringBuilder(ip.length+5);
for (int i = 0; i < ip.length; i++) {
buf.append(ip[i]&0xFF);
if (i + 1 < ip.length)

View File

@@ -42,7 +42,7 @@ public class UDPAddress {
@Override
public String toString() {
StringBuffer rv = new StringBuffer(64);
StringBuilder rv = new StringBuilder(64);
if (_introHosts != null) {
for (int i = 0; i < _introHosts.length; i++) {
rv.append("ssu://");

View File

@@ -168,7 +168,7 @@ public class UDPPacket {
Hash hmac = _context.hmac().calculate(macKey, buf.getData(), 0, off);
if (_log.shouldLog(Log.DEBUG)) {
StringBuffer str = new StringBuffer(128);
StringBuilder str = new StringBuilder(128);
str.append(_packet.getLength()).append(" byte packet received, payload length ");
str.append(payloadLength);
str.append("\nIV: ").append(Base64.encode(buf.getData(), payloadLength, IV_SIZE));
@@ -237,7 +237,7 @@ public class UDPPacket {
@Override
public String toString() {
verifyNotReleased();
StringBuffer buf = new StringBuffer(64);
StringBuilder buf = new StringBuilder(64);
buf.append(_packet.getLength());
buf.append(" byte packet with ");
buf.append(_packet.getAddress().getHostAddress()).append(":");

View File

@@ -129,7 +129,7 @@ public class UDPPacketReader {
}
}
public void toRawString(StringBuffer buf) {
public void toRawString(StringBuilder buf) {
if (_message != null)
buf.append(Base64.encode(_message, _payloadBeginOffset, _payloadLength));
}
@@ -401,7 +401,7 @@ public class UDPPacketReader {
@Override
public String toString() {
StringBuffer buf = new StringBuffer(256);
StringBuilder buf = new StringBuilder(256);
long msAgo = _context.clock().now() - readTimestamp()*1000;
buf.append("Data packet sent ").append(msAgo).append("ms ago ");
buf.append("IV ");
@@ -463,7 +463,7 @@ public class UDPPacketReader {
return buf.toString();
}
public void toRawString(StringBuffer buf) {
public void toRawString(StringBuilder buf) {
UDPPacketReader.this.toRawString(buf);
buf.append(" payload: ");
@@ -506,7 +506,7 @@ public class UDPPacketReader {
}
@Override
public String toString() {
StringBuffer buf = new StringBuffer(64);
StringBuilder buf = new StringBuilder(64);
buf.append("Read partial ACK of ");
buf.append(getMessageId());
buf.append(" with ACKs for: ");

View File

@@ -164,7 +164,7 @@ public class UDPReceiver {
packet.release();
_context.statManager().addRateData("udp.droppedInbound", queueSize, headPeriod);
if (_log.shouldLog(Log.WARN)) {
StringBuffer msg = new StringBuffer();
StringBuilder msg = new StringBuilder();
msg.append("Dropping inbound packet with ");
msg.append(queueSize);
msg.append(" queued for ");

View File

@@ -760,7 +760,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
private void dropPeer(PeerState peer, boolean shouldShitlist, String why) {
if (_log.shouldLog(Log.WARN)) {
long now = _context.clock().now();
StringBuffer buf = new StringBuffer(4096);
StringBuilder buf = new StringBuilder(4096);
long timeSinceSend = now - peer.getLastSendTime();
long timeSinceRecv = now - peer.getLastReceiveTime();
long timeSinceAck = now - peer.getLastACKSend();
@@ -1282,7 +1282,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
OutNetMessage m = msg.getMessage();
PeerState p = msg.getPeer();
StringBuffer buf = new StringBuffer(64);
StringBuilder buf = new StringBuilder(64);
buf.append(" lifetime: ").append(msg.getLifetime());
buf.append(" sends: ").append(sends);
buf.append(" pushes: ").append(pushCount);
@@ -1727,7 +1727,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
}
}
private void appendSortLinks(StringBuffer buf, String urlBase, int sortFlags, String descr, int ascending) {
private void appendSortLinks(StringBuilder buf, String urlBase, int sortFlags, String descr, int ascending) {
if (sortFlags == ascending) {
buf.append(" <a href=\"").append(urlBase).append("?sort=").append(0-ascending);
buf.append("\" title=\"").append(descr).append("\">V</a><b>^</b> ");
@@ -1763,7 +1763,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
long dupRecvTotal = 0;
int numPeers = 0;
StringBuffer buf = new StringBuffer(512);
StringBuilder buf = new StringBuilder(512);
buf.append("<p><b id=\"udpcon\">UDP connections: ").append(peers.size());
buf.append(" limit: ").append(getMaxConnections());
buf.append(" timeout: ").append(DataHelper.formatDuration(_expireTimeout));

View File

@@ -65,10 +65,10 @@ public class BatchedPreprocessor extends TrivialPreprocessor {
@Override
public boolean preprocessQueue(List pending, TunnelGateway.Sender sender, TunnelGateway.Receiver rec) {
StringBuffer timingBuf = null;
StringBuilder timingBuf = null;
if (_log.shouldLog(Log.DEBUG)) {
_log.debug("Preprocess queue with " + pending.size() + " to send");
timingBuf = new StringBuffer(128);
timingBuf = new StringBuilder(128);
timingBuf.append("Preprocess with " + pending.size() + " to send. ");
}
if (DISABLE_BATCHING) {
@@ -246,7 +246,7 @@ public class BatchedPreprocessor extends TrivialPreprocessor {
private void display(long allocated, List pending, String title) {
if (_log.shouldLog(Log.INFO)) {
long highestDelay = 0;
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append(_name).append(": ");
buf.append(title);
buf.append(" allocated: ").append(allocated);
@@ -286,7 +286,7 @@ public class BatchedPreprocessor extends TrivialPreprocessor {
// generate the final preprocessed data
if (offset <= 0) {
StringBuffer buf = new StringBuffer(128);
StringBuilder buf = new StringBuilder(128);
buf.append("wtf, written offset is ").append(offset);
buf.append(" for ").append(startAt).append(" through ").append(sendThrough);
for (int i = startAt; i <= sendThrough; i++) {

View File

@@ -275,7 +275,7 @@ public class FragmentedMessage {
@Override
public String toString() {
StringBuffer buf = new StringBuffer(128);
StringBuilder buf = new StringBuilder(128);
buf.append("Fragments for ").append(_messageId).append(": ");
for (int i = 0; i <= _highFragmentNum; i++) {
ByteArray ba = _fragments[i];

View File

@@ -137,7 +137,7 @@ public class HopConfig {
@Override
public String toString() {
StringBuffer buf = new StringBuffer(64);
StringBuilder buf = new StringBuilder(64);
if (_receiveTunnelId != null) {
buf.append("recv on ");
buf.append(DataHelper.fromLong(_receiveTunnelId, 0, 4));

View File

@@ -43,9 +43,9 @@ public class TrivialPreprocessor implements TunnelGateway.QueuePreprocessor {
*/
public boolean preprocessQueue(List pending, TunnelGateway.Sender sender, TunnelGateway.Receiver rec) {
long begin = System.currentTimeMillis();
StringBuffer buf = null;
StringBuilder buf = null;
if (_log.shouldLog(Log.DEBUG)) {
buf = new StringBuffer(256);
buf = new StringBuilder(256);
buf.append("Trivial preprocessing of ").append(pending.size()).append(" ");
}
while (pending.size() > 0) {

View File

@@ -166,7 +166,7 @@ public class TunnelCreatorConfig implements TunnelInfo {
@Override
public String toString() {
// H0:1235-->H1:2345-->H2:2345
StringBuffer buf = new StringBuffer(128);
StringBuilder buf = new StringBuilder(128);
if (_isInbound)
buf.append("inbound");
else

View File

@@ -238,7 +238,7 @@ public class TunnelGateway {
@Override
public String toString() {
StringBuffer buf = new StringBuffer(64);
StringBuilder buf = new StringBuilder(64);
buf.append("Message ").append(_messageId).append(" on ");
buf.append(TunnelGateway.this.toString());
if (_toRouter != null) {

View File

@@ -221,7 +221,7 @@ public class TunnelParticipant {
@Override
public String toString() {
if (_config != null) {
StringBuffer buf = new StringBuffer(64);
StringBuilder buf = new StringBuilder(64);
buf.append("participant at ").append(_config.toString());
return buf.toString();
} else {

View File

@@ -206,7 +206,7 @@ class BuildHandler {
long replyMessageId = state.msg.getUniqueId();
PooledTunnelCreatorConfig cfg = null;
List building = _exec.locked_getCurrentlyBuilding();
StringBuffer buf = null;
StringBuilder buf = null;
synchronized (building) {
for (int i = 0; i < building.size(); i++) {
PooledTunnelCreatorConfig cur = (PooledTunnelCreatorConfig)building.get(i);
@@ -217,7 +217,7 @@ class BuildHandler {
}
}
if ( (cfg == null) && (_log.shouldLog(Log.DEBUG)) )
buf = new StringBuffer(building.toString());
buf = new StringBuilder(building.toString());
}
if (cfg == null) {

View File

@@ -252,7 +252,7 @@ class TestJob extends JobImpl {
@Override
public String toString() {
StringBuffer rv = new StringBuffer(64);
StringBuilder rv = new StringBuilder(64);
rv.append("Testing tunnel ").append(_cfg.toString()).append(" waiting for ");
rv.append(_id).append(" found? ").append(_found);
return rv.toString();
@@ -284,7 +284,7 @@ class TestJob extends JobImpl {
@Override
public String toString() {
StringBuffer rv = new StringBuffer(64);
StringBuilder rv = new StringBuilder(64);
rv.append("Testing tunnel ").append(_cfg.toString());
rv.append(" successful after ").append(_successTime);
return rv.toString();
@@ -310,7 +310,7 @@ class TestJob extends JobImpl {
@Override
public String toString() {
StringBuffer rv = new StringBuffer(64);
StringBuilder rv = new StringBuilder(64);
rv.append("Testing tunnel ").append(_cfg.toString());
rv.append(" timed out");
return rv.toString();

View File

@@ -129,7 +129,7 @@ public abstract class TunnelPeerSelector {
rv.remove(0);
if (log.shouldLog(Log.INFO)) {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
if (settings.getDestinationNickname() != null)
buf.append("peers for ").append(settings.getDestinationNickname());
else if (settings.getDestination() != null)

View File

@@ -892,7 +892,7 @@ public class TunnelPool {
else
return "Outbound exploratory pool";
} else {
StringBuffer rv = new StringBuffer(32);
StringBuilder rv = new StringBuilder(32);
if (_settings.isInbound())
rv.append("Inbound client pool for ");
else