Author: zothar
Date: 2006-07-09 22:47:52 +0000 (Sun, 09 Jul 2006)
New Revision: 9532

Modified:
   trunk/freenet/src/freenet/clients/http/DarknetConnectionsToadlet.java
   trunk/freenet/src/freenet/clients/http/filter/HTMLFilter.java
   trunk/freenet/src/freenet/node/fcp/AddPeer.java
Log:
StringBuffer.append()s instead of String +=

Modified: trunk/freenet/src/freenet/clients/http/DarknetConnectionsToadlet.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/DarknetConnectionsToadlet.java       
2006-07-09 22:41:26 UTC (rev 9531)
+++ trunk/freenet/src/freenet/clients/http/DarknetConnectionsToadlet.java       
2006-07-09 22:47:52 UTC (rev 9532)
@@ -484,7 +484,7 @@
                                reftext = reftext.trim();
                        }

-                       String ref = "";
+                       StringBuffer ref = new StringBuffer(1024);
                        if (urltext.length() > 0) {
                                // fetch reference from a URL
                                BufferedReader in = null;
@@ -494,7 +494,7 @@
                                        in = new BufferedReader(new 
InputStreamReader(uc.getInputStream()));
                                        String line;
                                        while ( (line = in.readLine()) != null) 
{
-                                               ref += line+"\n";
+                                               ref.append( line ).append( "\n" 
);
                                        }
                                } catch (IOException e) {
                                        this.sendErrorPage(ctx, 200, "Failed To 
Add Node", "Unable to retrieve node reference from " + 
HTMLEncoder.encode(urltext) + ".<br /> <a href=\".\">Please try again</a>.");
@@ -507,32 +507,32 @@
                        } else if (reftext.length() > 0) {
                                // read from post data or file upload
                                // this slightly scary looking regexp chops any 
extra characters off the beginning or ends of lines and removes extra line 
breaks
-                               ref = 
reftext.replaceAll(".*?((?:[\\w,\\.]+\\=[^\r\n]+?)|(?:End))[ 
\\t]*(?:\\r?\\n)+", "$1\n");
+                               ref = new 
StringBuffer(reftext.replaceAll(".*?((?:[\\w,\\.]+\\=[^\r\n]+?)|(?:End))[ 
\\t]*(?:\\r?\\n)+", "$1\n"));
                        } else {
                                this.sendErrorPage(ctx, 200, "Failed To Add 
Node", "Could not detect either a node reference or a URL.<br /> <a 
href=\".\">Please try again</a>.");
                                request.freeParts();
                                return;
                        }
-                       ref = ref.trim();
+                       ref = new StringBuffer(ref.toString().trim());

                        request.freeParts();
                        // we have a node reference in ref
                        SimpleFieldSet fs;

                        try {
-                               fs = new SimpleFieldSet(ref, true);
+                               fs = new SimpleFieldSet(ref.toString(), true);
                        } catch (IOException e) {
-                               this.sendErrorPage(ctx, 200, "Failed To Add 
Node", "Unable to parse the given text: <pre>" + HTMLEncoder.encode(ref) + 
"</pre> as a node reference: "+HTMLEncoder.encode(e.toString())+".<br /> <a 
href=\".\">Please try again</a>.");
+                               this.sendErrorPage(ctx, 200, "Failed To Add 
Node", "Unable to parse the given text: <pre>" + 
HTMLEncoder.encode(ref.toString()) + "</pre> as a node reference: 
"+HTMLEncoder.encode(e.toString())+".<br /> <a href=\".\">Please try 
again</a>.");
                                return;
                        }
                        PeerNode pn;
                        try {
                                pn = new PeerNode(fs, this.node, false);
                        } catch (FSParseException e1) {
-                               this.sendErrorPage(ctx, 200, "Failed To Add 
Node", "Unable to parse the given text: <pre>" + HTMLEncoder.encode(ref) + 
"</pre> as a node reference: " + HTMLEncoder.encode(e1.toString()) + ".<br /> 
Please <a href=\".\">Try again</a>");
+                               this.sendErrorPage(ctx, 200, "Failed To Add 
Node", "Unable to parse the given text: <pre>" + 
HTMLEncoder.encode(ref.toString()) + "</pre> as a node reference: " + 
HTMLEncoder.encode(e1.toString()) + ".<br /> Please <a href=\".\">Try 
again</a>");
                                return;
                        } catch (PeerParseException e1) {
-                               this.sendErrorPage(ctx, 200, "Failed To Add 
Node", "Unable to parse the given text: <pre>" + HTMLEncoder.encode(ref) + 
"</pre> as a node reference: " + HTMLEncoder.encode(e1.toString()) + ".<br /> 
Please <a href=\".\">Try again</a>");
+                               this.sendErrorPage(ctx, 200, "Failed To Add 
Node", "Unable to parse the given text: <pre>" + 
HTMLEncoder.encode(ref.toString()) + "</pre> as a node reference: " + 
HTMLEncoder.encode(e1.toString()) + ".<br /> Please <a href=\".\">Try 
again</a>");
                                return;
                        }
                        if(pn.getIdentityHash()==node.getIdentityHash()) {

Modified: trunk/freenet/src/freenet/clients/http/filter/HTMLFilter.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/filter/HTMLFilter.java       
2006-07-09 22:41:26 UTC (rev 9531)
+++ trunk/freenet/src/freenet/clients/http/filter/HTMLFilter.java       
2006-07-09 22:47:52 UTC (rev 9532)
@@ -234,8 +234,8 @@
                                                                                
// End tag now
                                                                        } else {
                                                                                
killTag = true;
-                                                                               
writeAfterTag
-                                                                               
        += "<!-- Tags in string attribute -->";
+                                                                               
writeAfterTag.append(
+                                                                               
        "<!-- Tags in string attribute -->");
                                                                                
// Wait for end of tag then zap it
                                                                        }
                                                                }
@@ -263,12 +263,12 @@
                                                                                
// End tag now
                                                                        } else {
                                                                                
killTag = true;
-                                                                               
writeAfterTag
-                                                                               
        += "<!-- Tags in string attribute -->";
+                                                                               
writeAfterTag.append(
+                                                                               
        "<!-- Tags in string attribute -->");
                                                                                
// Wait for end of tag then zap it
                                                                        }
-                                                                       
writeAfterTag
-                                                                               
+= "<!-- Tags in string attribute -->";
+                                                                       
writeAfterTag.append(
+                                                                               
"<!-- Tags in string attribute -->");
                                                                        killTag 
= true;
                                                                }
                                                        } else {
@@ -361,7 +361,7 @@
                boolean killStyle = false;
                int styleScriptRecurseCount = 0;
                String currentStyleScriptChunk = new String();
-               String writeAfterTag = "";
+               StringBuffer writeAfterTag = new StringBuffer(1024);
        }


@@ -418,15 +418,15 @@
                                        pc.writeStyleScriptWithTag = false;
                                        String style = 
pc.currentStyleScriptChunk;
                                        if ((style == null) || (style.length() 
== 0))
-                                               pc.writeAfterTag += "<!-- 
deleted unknown style -->";
+                                               pc.writeAfterTag.append("<!-- 
deleted unknown style -->");
                                        else
                                                w.write(style);
                                        pc.currentStyleScriptChunk = "";
                                }
                                t.write(w);
                                if (pc.writeAfterTag.length() > 0) {
-                                       w.write(pc.writeAfterTag);
-                                       pc.writeAfterTag = "";
+                                       w.write(pc.writeAfterTag.toString());
+                                       pc.writeAfterTag = new 
StringBuffer(1024);
                                }
                        } else
                                pc.writeStyleScriptWithTag = false;
@@ -1182,10 +1182,10 @@
                                        y = (String) o;
                                else
                                        y = null;
-                               String out = x;
+                               StringBuffer out = new StringBuffer(x);
                                if (y != null)
-                                       out += "=\"" + y + '"';
-                               outAttrs[i++] = out;
+                                       out.append( "=\"" ).append( y ).append( 
'"' );
+                               outAttrs[i++] = out.toString();
                        }
                        return new ParsedTag(t, outAttrs);
                }
@@ -1291,8 +1291,8 @@
                        pc.styleScriptRecurseCount--;
                        if (pc.styleScriptRecurseCount < 0) {
                                if (deleteErrors)
-                                       pc.writeAfterTag
-                                               += "<!-- Too many nested style 
or script tags - ambiguous or invalid parsing -->";
+                                       pc.writeAfterTag.append(
+                                               "<!-- Too many nested style or 
script tags - ambiguous or invalid parsing -->");
                                else
                                        throwFilterException("Too many nested 
</style> tags - ambiguous or invalid parsing, can't reliably filter so removing 
the inner tags - garbage may appear in browser");
                                return null;
@@ -1314,8 +1314,8 @@
                        pc.styleScriptRecurseCount++;
                        if (pc.styleScriptRecurseCount > 1) {
                                if (deleteErrors)
-                                       pc.writeAfterTag
-                                               += "<!-- Too many nested style 
or script tags -->";
+                                       pc.writeAfterTag.append(
+                                               "<!-- Too many nested style or 
script tags -->");
                                else
                                        throwFilterException("Too many nested 
</style> tags - ambiguous or invalid parsing, can't reliably filter so removing 
the inner tags - garbage may appear in browser");
                                return null;

Modified: trunk/freenet/src/freenet/node/fcp/AddPeer.java
===================================================================
--- trunk/freenet/src/freenet/node/fcp/AddPeer.java     2006-07-09 22:41:26 UTC 
(rev 9531)
+++ trunk/freenet/src/freenet/node/fcp/AddPeer.java     2006-07-09 22:47:52 UTC 
(rev 9532)
@@ -37,18 +37,18 @@
        public void run(FCPConnectionHandler handler, Node node) throws 
MessageInvalidException {
                String urlString = fs.get("URL");
                String fileString = fs.get("File");
-               String ref = null;
+               StringBuffer ref = null;
                BufferedReader in;
                if(urlString != null) {
                        try {
                                URL url = new URL(urlString);
                                URLConnection uc = url.openConnection();
                                in = new BufferedReader( new 
InputStreamReader(uc.getInputStream()));
-                               ref = "";
+                               ref = new StringBuffer(1024);
                                String line;
                                while((line = in.readLine()) != null) {
                                        line = line.trim();
-                                       ref += line+"\n";
+                                       ref.append( line ).append( "\n" );
                                }
                                in.close();
                        } catch (MalformedURLException e) {
@@ -56,7 +56,7 @@
                        } catch (IOException e) {
                                throw new 
MessageInvalidException(ProtocolErrorMessage.URL_PARSE_ERROR, "IO error while 
retrieving ref URL <"+urlString+">: "+e.getMessage(), null);
                        }
-                       ref = ref.trim();
+                       ref = new StringBuffer(ref.toString().trim());
                        if(ref == null) {
                                throw new 
MessageInvalidException(ProtocolErrorMessage.REF_PARSE_ERROR, "Error parsing 
ref from URL <"+urlString+">", null);
                        }
@@ -64,7 +64,7 @@
                                throw new 
MessageInvalidException(ProtocolErrorMessage.REF_PARSE_ERROR, "Error parsing 
ref from URL <"+urlString+">", null);
                        }
                        try {
-                               fs = new SimpleFieldSet(ref, true);
+                               fs = new SimpleFieldSet(ref.toString(), true);
                        } catch (IOException e) {
                                throw new 
MessageInvalidException(ProtocolErrorMessage.REF_PARSE_ERROR, "Error parsing 
ref from URL <"+urlString+">: "+e.getMessage(), null);
                        }
@@ -75,11 +75,11 @@
                        }
                        try {
                                in = new BufferedReader(new FileReader(f));
-                               ref = "";
+                               ref = new StringBuffer(1024);
                                String line;
                                while((line = in.readLine()) != null) {
                                        line = line.trim();
-                                       ref += line+"\n";
+                                       ref.append( line ).append( "\n" );
                                }
                                in.close();
                        } catch (FileNotFoundException e) {
@@ -87,7 +87,7 @@
                        } catch (IOException e) {
                                throw new 
MessageInvalidException(ProtocolErrorMessage.FILE_PARSE_ERROR, "IO error while 
retrieving ref file <"+fileString+">: "+e.getMessage(), null);
                        }
-                       ref = ref.trim();
+                       ref = new StringBuffer(ref.toString().trim());
                        if(ref == null) {
                                throw new 
MessageInvalidException(ProtocolErrorMessage.REF_PARSE_ERROR, "Error parsing 
ref from file <"+fileString+">", null);
                        }
@@ -95,7 +95,7 @@
                                throw new 
MessageInvalidException(ProtocolErrorMessage.REF_PARSE_ERROR, "Error parsing 
ref from file <"+fileString+">", null);
                        }
                        try {
-                               fs = new SimpleFieldSet(ref, true);
+                               fs = new SimpleFieldSet(ref.toString(), true);
                        } catch (IOException e) {
                                throw new 
MessageInvalidException(ProtocolErrorMessage.REF_PARSE_ERROR, "Error parsing 
ref from file <"+fileString+">: "+e.getMessage(), null);
                        }


Reply via email to