1
Index: modules/jetty/pom.xml
2
===================================================================
3
--- modules/jetty/pom.xml (revision 4733)
4
+++ modules/jetty/pom.xml (working copy)
9
+ <artifactId>maven-compiler-plugin</artifactId>
11
+ <source>1.5</source>
12
+ <target>1.5</target>
16
<artifactId>maven-antrun-plugin</artifactId>
19
Index: modules/jetty/src/main/java/org/mortbay/io/AbstractBuffer.java
20
===================================================================
21
--- modules/jetty/src/main/java/org/mortbay/io/AbstractBuffer.java (revision 4733)
22
+++ modules/jetty/src/main/java/org/mortbay/io/AbstractBuffer.java (working copy)
25
public String toDetailString()
27
- StringBuffer buf = new StringBuffer();
28
+ StringBuilder buf = new StringBuilder();
30
buf.append(super.hashCode());
32
Index: modules/jetty/src/main/java/org/mortbay/io/BufferUtil.java
33
===================================================================
34
--- modules/jetty/src/main/java/org/mortbay/io/BufferUtil.java (revision 4733)
35
+++ modules/jetty/src/main/java/org/mortbay/io/BufferUtil.java (working copy)
38
return new String(bytes,buffer.getIndex(),buffer.length(),StringUtil.__ISO_8859_1);
40
- StringBuffer b = new StringBuffer(buffer.length());
41
+ StringBuilder b = new StringBuilder(buffer.length());
42
for (int i=buffer.getIndex(),c=0;c<buffer.length();i++,c++)
43
b.append((char)(0x7f&buffer.peek(i)));
45
Index: modules/jetty/src/main/java/org/mortbay/jetty/handler/ContextHandler.java
46
===================================================================
47
--- modules/jetty/src/main/java/org/mortbay/jetty/handler/ContextHandler.java (revision 4733)
48
+++ modules/jetty/src/main/java/org/mortbay/jetty/handler/ContextHandler.java (working copy)
51
URLClassLoader loader = (URLClassLoader)_classLoader;
52
URL[] urls =loader.getURLs();
53
- StringBuffer classpath=new StringBuffer();
54
+ StringBuilder classpath=new StringBuilder();
55
for (int i=0;i<urls.length;i++)
58
Index: modules/jetty/src/main/java/org/mortbay/jetty/HttpGenerator.java
59
===================================================================
60
--- modules/jetty/src/main/java/org/mortbay/jetty/HttpGenerator.java (revision 4733)
61
+++ modules/jetty/src/main/java/org/mortbay/jetty/HttpGenerator.java (working copy)
63
HttpFields.Field transfer_encoding = null;
64
boolean keep_alive = false;
66
- StringBuffer connection = null;
67
+ StringBuilder connection = null;
75
- connection=new StringBuffer();
76
+ connection=new StringBuilder();
78
connection.append(',');
79
connection.append(values[i]);
84
- connection=new StringBuffer();
85
+ connection=new StringBuilder();
87
connection.append(',');
88
connection.append(values[i]);
93
- connection=new StringBuffer();
94
+ connection=new StringBuilder();
96
connection.append(',');
97
connection.append(field.getValue());
98
Index: modules/jetty/src/main/java/org/mortbay/jetty/InclusiveByteRange.java
99
===================================================================
100
--- modules/jetty/src/main/java/org/mortbay/jetty/InclusiveByteRange.java (revision 4733)
101
+++ modules/jetty/src/main/java/org/mortbay/jetty/InclusiveByteRange.java (working copy)
103
/* ------------------------------------------------------------ */
104
public String toHeaderRangeString(long size)
106
- StringBuffer sb = new StringBuffer(40);
107
+ StringBuilder sb = new StringBuilder(40);
109
sb.append(getFirst(size));
112
/* ------------------------------------------------------------ */
113
public static String to416HeaderRangeString(long size)
115
- StringBuffer sb = new StringBuffer(40);
116
+ StringBuilder sb = new StringBuilder(40);
117
sb.append("bytes */");
119
return sb.toString();
121
/* ------------------------------------------------------------ */
122
public String toString()
124
- StringBuffer sb = new StringBuffer(60);
125
+ StringBuilder sb = new StringBuilder(60);
126
sb.append(Long.toString(first));
128
sb.append(Long.toString(last));
129
Index: modules/jetty/src/main/java/org/mortbay/jetty/Request.java
130
===================================================================
131
--- modules/jetty/src/main/java/org/mortbay/jetty/Request.java (revision 4733)
132
+++ modules/jetty/src/main/java/org/mortbay/jetty/Request.java (working copy)
133
@@ -1763,25 +1763,22 @@
135
* @return "scheme://host:port"
137
- public StringBuffer getRootURL()
138
+ public StringBuilder getRootURL()
140
- StringBuffer url = new StringBuffer(48);
143
- String scheme = getScheme();
144
- int port = getServerPort();
145
+ StringBuilder url = new StringBuilder(48);
146
+ String scheme = getScheme();
147
+ int port = getServerPort();
149
- url.append(scheme);
151
- url.append(getServerName());
153
- if (port > 0 && ((scheme.equalsIgnoreCase("http") && port != 80) || (scheme.equalsIgnoreCase("https") && port != 443)))
159
+ url.append(scheme);
161
+ url.append(getServerName());
163
+ if (port > 0 && ((scheme.equalsIgnoreCase("http") && port != 80) || (scheme.equalsIgnoreCase("https") && port != 443)))
171
/* ------------------------------------------------------------ */
172
Index: modules/jetty/src/main/java/org/mortbay/jetty/Response.java
173
===================================================================
174
--- modules/jetty/src/main/java/org/mortbay/jetty/Response.java (revision 4733)
175
+++ modules/jetty/src/main/java/org/mortbay/jetty/Response.java (working copy)
178
if (!URIUtil.hasScheme(location))
180
- StringBuffer buf = _connection.getRequest().getRootURL();
181
+ StringBuilder buf = _connection.getRequest().getRootURL();
182
if (location.startsWith("/"))
183
buf.append(URIUtil.canonicalPath(location));
185
Index: modules/jetty/src/main/java/org/mortbay/jetty/security/HTAccessHandler.java
186
===================================================================
187
--- modules/jetty/src/main/java/org/mortbay/jetty/security/HTAccessHandler.java (revision 4733)
188
+++ modules/jetty/src/main/java/org/mortbay/jetty/security/HTAccessHandler.java (working copy)
190
/* ------------------------------------------------------------ */
191
public String toString()
193
- StringBuffer buf=new StringBuffer();
194
+ StringBuilder buf=new StringBuilder();
196
buf.append("AuthUserFile=");
197
buf.append(_userFile);
198
Index: modules/jetty/src/main/java/org/mortbay/jetty/security/Password.java
199
===================================================================
200
--- modules/jetty/src/main/java/org/mortbay/jetty/security/Password.java (revision 4733)
201
+++ modules/jetty/src/main/java/org/mortbay/jetty/security/Password.java (working copy)
202
@@ -122,31 +122,29 @@
203
/* ------------------------------------------------------------ */
204
public static String obfuscate(String s)
206
- StringBuffer buf = new StringBuffer();
207
+ StringBuilder buf = new StringBuilder();
208
byte[] b = s.getBytes();
212
+ buf.append(__OBFUSCATE);
213
+ for (int i=0;i<b.length;i++)
215
- buf.append(__OBFUSCATE);
216
- for (int i=0;i<b.length;i++)
219
- byte b2 = b[s.length()-(i+1)];
223
- String x=Integer.toString(i0,36);
225
+ byte b2 = b[s.length()-(i+1)];
229
+ String x=Integer.toString(i0,36);
233
- case 1:buf.append('0');
234
- case 2:buf.append('0');
235
- case 3:buf.append('0');
236
- default:buf.append(x);
240
+ case 1:buf.append('0');
241
+ case 2:buf.append('0');
242
+ case 3:buf.append('0');
243
+ default:buf.append(x);
245
- return buf.toString();
247
+ return buf.toString();
251
/* ------------------------------------------------------------ */
252
Index: modules/jetty/src/main/java/org/mortbay/jetty/servlet/DefaultServlet.java
253
===================================================================
254
--- modules/jetty/src/main/java/org/mortbay/jetty/servlet/DefaultServlet.java (revision 4733)
255
+++ modules/jetty/src/main/java/org/mortbay/jetty/servlet/DefaultServlet.java (working copy)
256
@@ -423,19 +423,22 @@
257
if (!endsWithSlash || (pathInContext.length()==1 && request.getAttribute("org.mortbay.jetty.nullPathInfo")!=null))
259
StringBuffer buf=request.getRequestURL();
260
- int param=buf.lastIndexOf(";");
264
- buf.insert(param,'/');
265
- String q=request.getQueryString();
266
- if (q!=null&&q.length()!=0)
271
+ int param=buf.lastIndexOf(";");
275
+ buf.insert(param,'/');
276
+ String q=request.getQueryString();
277
+ if (q!=null&&q.length()!=0)
282
+ response.setContentLength(0);
283
+ response.sendRedirect(response.encodeRedirectURL(buf.toString()));
285
- response.setContentLength(0);
286
- response.sendRedirect(response.encodeRedirectURL(buf.toString()));
288
// else look for a welcome file
289
else if (null!=(welcome=getWelcomeFile(resource)))
290
Index: modules/jetty/src/main/java/org/mortbay/jetty/servlet/HashSessionIdManager.java
291
===================================================================
292
--- modules/jetty/src/main/java/org/mortbay/jetty/servlet/HashSessionIdManager.java (revision 4733)
293
+++ modules/jetty/src/main/java/org/mortbay/jetty/servlet/HashSessionIdManager.java (working copy)
295
import org.mortbay.jetty.SessionIdManager;
296
import org.mortbay.jetty.servlet.AbstractSessionManager.Session;
297
import org.mortbay.log.Log;
298
-import org.mortbay.util.MultiMap;
299
+import org.mortbay.util.ConcurrentMultiMap;
301
/* ------------------------------------------------------------ */
304
protected final static String SESSION_ID_RANDOM_ALGORITHM = "SHA1PRNG";
305
protected final static String SESSION_ID_RANDOM_ALGORITHM_ALT = "IBMSecureRandom";
307
- MultiMap _sessions;
308
+ ConcurrentMultiMap _sessions;
309
protected Random _random;
310
private boolean _weakRandom;
311
private String _workerName;
315
_random.setSeed(_random.nextLong()^System.currentTimeMillis()^hashCode()^Runtime.getRuntime().freeMemory());
316
- _sessions=new MultiMap();
317
+ _sessions=new ConcurrentMultiMap();
320
/* ------------------------------------------------------------ */
323
public void addSession(HttpSession session)
325
- synchronized (this)
327
- _sessions.add(getClusterId(session.getId()),session);
329
+ _sessions.add(getClusterId(session.getId()),session);
332
/* ------------------------------------------------------------ */
335
public void removeSession(HttpSession session)
337
- synchronized (this)
339
- _sessions.removeValue(getClusterId(session.getId()),session);
341
+ _sessions.removeValue(getClusterId(session.getId()),session);
344
/* ------------------------------------------------------------ */
345
@@ -187,19 +181,16 @@
347
public void invalidateAll(String id)
349
- synchronized (this)
351
- // Do not use interators as this method tends to be called recursively
352
- // by the invalidate calls.
353
- while (_sessions.containsKey(id))
355
- Session session=(Session)_sessions.getValue(id,0);
356
- if (session.isValid())
357
- session.invalidate();
359
- _sessions.removeValue(id,session);
362
+ // Do not use interators as this method tends to be called recursively
363
+ // by the invalidate calls.
364
+ while (_sessions.containsKey(id))
366
+ Session session=(Session)_sessions.getValue(id,0);
367
+ if (session.isValid())
368
+ session.invalidate();
370
+ _sessions.removeValue(id,session);
374
/* ------------------------------------------------------------ */
380
\ No newline at end of file
382
Index: modules/jetty/src/main/java/org/mortbay/jetty/servlet/HashSessionManager.java
383
===================================================================
384
--- modules/jetty/src/main/java/org/mortbay/jetty/servlet/HashSessionManager.java (revision 4733)
385
+++ modules/jetty/src/main/java/org/mortbay/jetty/servlet/HashSessionManager.java (working copy)
387
import java.util.Timer;
388
import java.util.TimerTask;
390
+import java.util.concurrent.ConcurrentHashMap;
392
import javax.servlet.http.HttpServletRequest;
394
import org.mortbay.log.Log;
397
public class HashSessionManager extends AbstractSessionManager
399
+ private static int __id;
400
private Timer _timer;
401
private TimerTask _task;
402
private int _scavengePeriodMs=30000;
405
public void doStart() throws Exception
407
- _sessions=new HashMap();
408
+ _sessions=new ConcurrentHashMap(); // TODO: use syncronizedMap for JDK 1.4
411
- _timer=new Timer(true);
412
+ _timer=new Timer("HashSessionScavenger-"+__id++, true);
414
setScavengePeriod(getScavengePeriod());
416
Index: modules/jetty/src/main/java/org/mortbay/jetty/servlet/ServletHandler.java
417
===================================================================
418
--- modules/jetty/src/main/java/org/mortbay/jetty/servlet/ServletHandler.java (revision 4733)
419
+++ modules/jetty/src/main/java/org/mortbay/jetty/servlet/ServletHandler.java (working copy)
421
import java.util.HashMap;
422
import java.util.List;
423
import java.util.Map;
424
+import java.util.concurrent.ConcurrentHashMap;
426
import javax.servlet.Filter;
427
import javax.servlet.FilterChain;
429
private transient Map _servletNameMap=new HashMap();
430
private transient PathMap _servletPathMap;
432
- protected transient HashMap _chainCache[];
433
+ protected transient ConcurrentHashMap _chainCache[];
436
/* ------------------------------------------------------------ */
440
if(_filterChainsCached)
441
- _chainCache= new HashMap[]{null,new HashMap(),new HashMap(),null,new HashMap(),null,null,null,new HashMap()};
442
+ _chainCache= new ConcurrentHashMap[]{null,new ConcurrentHashMap(),new ConcurrentHashMap(),null,new ConcurrentHashMap(),null,null,null,new ConcurrentHashMap()};
448
if (_filterChainsCached && _chainCache!=null)
452
- if(_chainCache[requestType].containsKey(key))
453
- return (FilterChain)_chainCache[requestType].get(key);
455
+ FilterChain chain = (FilterChain)_chainCache[requestType].get(key);
460
// Build list of filters
463
if (LazyList.size(filters) > 0)
464
chain= new CachedChain(filters, servletHolder);
467
- if (_maxFilterChainsCacheSize>0 && _chainCache[requestType].size()>_maxFilterChainsCacheSize)
468
- _chainCache[requestType].clear();
469
- _chainCache[requestType].put(key,chain);
471
+ if (_maxFilterChainsCacheSize>0 && _chainCache[requestType].size()>_maxFilterChainsCacheSize)
472
+ _chainCache[requestType].clear();
473
+ _chainCache[requestType].put(key,chain);
475
else if (LazyList.size(filters) > 0)
476
chain = new Chain(filters, servletHolder);
477
@@ -1205,7 +1201,7 @@
478
/* ------------------------------------------------------------ */
479
public String toString()
481
- StringBuffer b = new StringBuffer();
482
+ StringBuilder b = new StringBuilder();
483
for (int i=0; i<LazyList.size(_chain);i++)
485
b.append(LazyList.get(_chain, i).toString());
486
Index: modules/jetty/src/main/java/org/mortbay/resource/Resource.java
487
===================================================================
488
--- modules/jetty/src/main/java/org/mortbay/resource/Resource.java (revision 4733)
489
+++ modules/jetty/src/main/java/org/mortbay/resource/Resource.java (working copy)
491
String decodedBase = URIUtil.decodePath(base);
492
String title = "Directory: "+decodedBase;
494
- StringBuffer buf=new StringBuffer(4096);
495
+ StringBuilder buf=new StringBuilder(4096);
496
buf.append("<HTML><HEAD><TITLE>");
498
buf.append("</TITLE></HEAD><BODY>\n<H1>");
499
Index: modules/jetty/src/main/java/org/mortbay/xml/XmlConfiguration.java
500
===================================================================
501
--- modules/jetty/src/main/java/org/mortbay/xml/XmlConfiguration.java (revision 4733)
502
+++ modules/jetty/src/main/java/org/mortbay/xml/XmlConfiguration.java (working copy)
503
@@ -838,16 +838,13 @@
506
// Get the multiple items as a single string
507
- StringBuffer buf = new StringBuffer();
509
+ StringBuilder buf = new StringBuilder();
510
+ for (int i = first; i <= last; i++)
512
- for (int i = first; i <= last; i++)
514
- Object item = node.get(i);
515
- buf.append(itemValue(obj, item));
517
- value = buf.toString();
518
+ Object item = node.get(i);
519
+ buf.append(itemValue(obj, item));
521
+ value = buf.toString();
525
Index: modules/jetty/src/main/java/org/mortbay/xml/XmlParser.java
526
===================================================================
527
--- modules/jetty/src/main/java/org/mortbay/xml/XmlParser.java (revision 4733)
528
+++ modules/jetty/src/main/java/org/mortbay/xml/XmlParser.java (working copy)
531
public synchronized String toString(boolean tag)
533
- StringBuffer buf = new StringBuffer();
536
- toString(buf, tag);
537
- return buf.toString();
539
+ StringBuilder buf = new StringBuilder();
540
+ toString(buf, tag);
541
+ return buf.toString();
544
/* ------------------------------------------------------------ */
548
/* ------------------------------------------------------------ */
549
- private synchronized void toString(StringBuffer buf, boolean tag)
550
+ private synchronized void toString(StringBuilder buf, boolean tag)
554
Index: modules/jetty/src/test/java/org/mortbay/jetty/HttpServerTestBase.java
555
===================================================================
556
--- modules/jetty/src/test/java/org/mortbay/jetty/HttpServerTestBase.java (revision 4733)
557
+++ modules/jetty/src/test/java/org/mortbay/jetty/HttpServerTestBase.java (working copy)
561
int[] points=new int[pointCount];
562
- StringBuffer message=new StringBuffer();
563
+ StringBuilder message=new StringBuilder();
565
message.append("iteration #"+(i+1));
568
for (int i=0; i<bytes.length; i+=3)
570
int[] points=new int[] { i };
571
- StringBuffer message=new StringBuffer();
572
+ StringBuilder message=new StringBuilder();
574
message.append("iteration #"+(i+1));
578
Socket client=new Socket(HOST,port);
579
OutputStream os=client.getOutputStream();
580
- StringBuffer message=new StringBuffer();
581
+ StringBuilder message=new StringBuilder();
583
message.append("iteration #"+(i+1));
584
writeFragments(bytes,badPoints[i],message,os);
587
br=new BufferedReader(new InputStreamReader(client.getInputStream()));
589
- StringBuffer sb=new StringBuffer();
590
+ StringBuilder sb=new StringBuilder();
593
while ((line=br.readLine())!=null)
598
- private void writeFragments(byte[] bytes, int[] points, StringBuffer message, OutputStream os) throws IOException, InterruptedException
599
+ private void writeFragments(byte[] bytes, int[] points, StringBuilder message, OutputStream os) throws IOException, InterruptedException
603
Index: modules/util/pom.xml
604
===================================================================
605
--- modules/util/pom.xml (revision 4733)
606
+++ modules/util/pom.xml (working copy)
611
+ <artifactId>maven-compiler-plugin</artifactId>
613
+ <source>1.5</source>
614
+ <target>1.5</target>
618
<artifactId>maven-antrun-plugin</artifactId>
621
Index: modules/util/src/main/java/org/mortbay/servlet/CGI.java
622
===================================================================
623
--- modules/util/src/main/java/org/mortbay/servlet/CGI.java (revision 4733)
624
+++ modules/util/src/main/java/org/mortbay/servlet/CGI.java (working copy)
626
* @throws IOException
628
private String getTextLineFromStream( InputStream is ) throws IOException {
629
- StringBuffer buffer = new StringBuffer();
630
+ StringBuilder buffer = new StringBuilder();
633
while( (b = is.read()) != -1 && b != (int) '\n' ) {
634
Index: modules/util/src/main/java/org/mortbay/servlet/GzipFilter.java
635
===================================================================
636
--- modules/util/src/main/java/org/mortbay/servlet/GzipFilter.java (revision 4733)
637
+++ modules/util/src/main/java/org/mortbay/servlet/GzipFilter.java (working copy)
640
catch (IOException e)
642
- throw new IllegalStateException();
643
+ throw new IllegalStateException(e);
647
Index: modules/util/src/main/java/org/mortbay/servlet/UserAgentFilter.java
648
===================================================================
649
--- modules/util/src/main/java/org/mortbay/servlet/UserAgentFilter.java (revision 4733)
650
+++ modules/util/src/main/java/org/mortbay/servlet/UserAgentFilter.java (working copy)
652
import java.util.HashMap;
653
import java.util.List;
654
import java.util.Map;
655
+import java.util.concurrent.ConcurrentHashMap;
656
import java.util.regex.Matcher;
657
import java.util.regex.Pattern;
660
public class UserAgentFilter implements Filter
662
private Pattern _pattern;
663
- private Map _agentCache = new HashMap();
664
+ private Map _agentCache = new ConcurrentHashMap();
665
private int _agentCacheSize=1024;
666
private String _attribute;
673
- synchronized(_agentCache)
675
- tag = (String)_agentCache.get(ua);
677
+ String tag = (String)_agentCache.get(ua);
686
- synchronized(_agentCache)
688
- if (_agentCache.size()>=_agentCacheSize)
689
+ if (_agentCache.size()>=_agentCacheSize)
691
_agentCache.put(ua,tag);
696
Index: modules/util/src/main/java/org/mortbay/thread/Timeout.java
697
===================================================================
698
--- modules/util/src/main/java/org/mortbay/thread/Timeout.java (revision 4733)
699
+++ modules/util/src/main/java/org/mortbay/thread/Timeout.java (working copy)
701
/* ------------------------------------------------------------ */
702
public String toString()
704
- StringBuffer buf = new StringBuffer();
705
+ StringBuilder buf = new StringBuilder();
706
buf.append(super.toString());
708
Task task = _head._next;
709
Index: modules/util/src/main/java/org/mortbay/util/ajax/JSON.java
710
===================================================================
711
--- modules/util/src/main/java/org/mortbay/util/ajax/JSON.java (revision 4733)
712
+++ modules/util/src/main/java/org/mortbay/util/ajax/JSON.java (working copy)
713
@@ -1031,7 +1031,7 @@
717
- StringBuffer buffer=null;
718
+ StringBuilder buffer=null;
720
longLoop: while (source.hasNext())
722
@@ -1063,7 +1063,7 @@
726
- buffer=new StringBuffer(16);
727
+ buffer=new StringBuilder(16);
730
buffer.append(number);
731
@@ -1079,8 +1079,6 @@
733
return TypeUtil.newLong(minus?-1*number:number);
735
- synchronized (buffer)
737
doubleLoop: while (source.hasNext())
739
char c=source.peek();
740
@@ -1110,7 +1108,6 @@
743
return new Double(buffer.toString());
747
protected void seekTo(char seek, Source source)
748
Index: modules/util/src/main/java/org/mortbay/util/ConcurrentMultiMap.java
749
===================================================================
750
--- modules/util/src/main/java/org/mortbay/util/ConcurrentMultiMap.java (revision 0)
751
+++ modules/util/src/main/java/org/mortbay/util/ConcurrentMultiMap.java (revision 0)
753
+// ========================================================================
754
+// Copyright 2004-2005 Mort Bay Consulting Pty. Ltd.
755
+// ------------------------------------------------------------------------
756
+// Licensed under the Apache License, Version 2.0 (the "License");
757
+// you may not use this file except in compliance with the License.
758
+// You may obtain a copy of the License at
759
+// http://www.apache.org/licenses/LICENSE-2.0
760
+// Unless required by applicable law or agreed to in writing, software
761
+// distributed under the License is distributed on an "AS IS" BASIS,
762
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
763
+// See the License for the specific language governing permissions and
764
+// limitations under the License.
765
+// ========================================================================
767
+package org.mortbay.util;
769
+import java.util.Arrays;
770
+import java.util.concurrent.ConcurrentHashMap;
771
+import java.util.HashMap;
772
+import java.util.Iterator;
773
+import java.util.List;
774
+import java.util.Map;
776
+/* ------------------------------------------------------------ */
777
+/** A multi valued Map.
778
+ * This Map specializes HashMap and provides methods
779
+ * that operate on multi valued items.
781
+ * Implemented as a map of LazyList values
784
+ * @author Greg Wilkins (gregw)
786
+public class ConcurrentMultiMap extends ConcurrentHashMap
787
+ implements Cloneable
789
+ /* ------------------------------------------------------------ */
792
+ public ConcurrentMultiMap()
795
+ /* ------------------------------------------------------------ */
797
+ * @param size Capacity of the map
799
+ public ConcurrentMultiMap(int size)
804
+ /* ------------------------------------------------------------ */
808
+ public ConcurrentMultiMap(Map map)
810
+ super((map.size()*3)/2);
814
+ /* ------------------------------------------------------------ */
815
+ /** Get multiple values.
816
+ * Single valued entries are converted to singleton lists.
817
+ * @param name The entry key.
818
+ * @return Unmodifieable List of values.
820
+ public List getValues(Object name)
822
+ return LazyList.getList(super.get(name),true);
825
+ /* ------------------------------------------------------------ */
826
+ /** Get a value from a multiple value.
827
+ * If the value is not a multivalue, then index 0 retrieves the
829
+ * @param name The entry key.
830
+ * @param i Index of element to get.
831
+ * @return Unmodifieable List of values.
833
+ public Object getValue(Object name,int i)
835
+ Object l=super.get(name);
836
+ if (i==0 && LazyList.size(l)==0)
838
+ return LazyList.get(l,i);
842
+ /* ------------------------------------------------------------ */
843
+ /** Get value as String.
844
+ * Single valued items are converted to a String with the toString()
845
+ * Object method. Multi valued entries are converted to a comma separated
846
+ * List. No quoting of commas within values is performed.
847
+ * @param name The entry key.
848
+ * @return String value.
850
+ public String getString(Object name)
852
+ Object l=super.get(name);
853
+ switch(LazyList.size(l))
858
+ Object o=LazyList.get(l,0);
859
+ return o==null?null:o.toString();
861
+ StringBuffer values=new StringBuffer(128);
862
+ synchronized(values)
864
+ for (int i=0; i<LazyList.size(l); i++)
866
+ Object e=LazyList.get(l,i);
869
+ if (values.length()>0)
870
+ values.append(',');
871
+ values.append(e.toString());
874
+ return values.toString();
879
+ /* ------------------------------------------------------------ */
880
+ public Object get(Object name)
882
+ Object l=super.get(name);
883
+ switch(LazyList.size(l))
888
+ Object o=LazyList.get(l,0);
891
+ return LazyList.getList(l,true);
895
+ /* ------------------------------------------------------------ */
896
+ /** Put and entry into the map.
897
+ * @param name The entry key.
898
+ * @param value The entry value.
899
+ * @return The previous value or null.
901
+ public Object put(Object name, Object value)
903
+ return super.put(name,LazyList.add(null,value));
906
+ /* ------------------------------------------------------------ */
907
+ /** Put multi valued entry.
908
+ * @param name The entry key.
909
+ * @param values The List of multiple values.
910
+ * @return The previous value or null.
912
+ public Object putValues(Object name, List values)
914
+ return super.put(name,values);
917
+ /* ------------------------------------------------------------ */
918
+ /** Put multi valued entry.
919
+ * @param name The entry key.
920
+ * @param values The String array of multiple values.
921
+ * @return The previous value or null.
923
+ public Object putValues(Object name, String[] values)
926
+ for (int i=0;i<values.length;i++)
927
+ list=LazyList.add(list,values[i]);
928
+ return put(name,list);
932
+ /* ------------------------------------------------------------ */
933
+ /** Add value to multi valued entry.
934
+ * If the entry is single valued, it is converted to the first
935
+ * value of a multi valued entry.
936
+ * @param name The entry key.
937
+ * @param value The entry value.
939
+ public void add(Object name, Object value)
941
+ Object lo = super.get(name);
942
+ Object ln = LazyList.add(lo,value);
944
+ super.put(name,ln);
947
+ /* ------------------------------------------------------------ */
948
+ /** Add values to multi valued entry.
949
+ * If the entry is single valued, it is converted to the first
950
+ * value of a multi valued entry.
951
+ * @param name The entry key.
952
+ * @param values The List of multiple values.
954
+ public void addValues(Object name, List values)
956
+ Object lo = super.get(name);
957
+ Object ln = LazyList.addCollection(lo,values);
959
+ super.put(name,ln);
962
+ /* ------------------------------------------------------------ */
963
+ /** Add values to multi valued entry.
964
+ * If the entry is single valued, it is converted to the first
965
+ * value of a multi valued entry.
966
+ * @param name The entry key.
967
+ * @param values The String array of multiple values.
969
+ public void addValues(Object name, String[] values)
971
+ Object lo = super.get(name);
972
+ Object ln = LazyList.addCollection(lo,Arrays.asList(values));
974
+ super.put(name,ln);
977
+ /* ------------------------------------------------------------ */
979
+ * @param name The entry key.
980
+ * @param value The entry value.
981
+ * @return true if it was removed.
983
+ public boolean removeValue(Object name,Object value)
985
+ Object lo = super.get(name);
987
+ int s=LazyList.size(lo);
990
+ ln=LazyList.remove(lo,value);
992
+ super.remove(name);
994
+ super.put(name, ln);
996
+ return LazyList.size(ln)!=s;
999
+ /* ------------------------------------------------------------ */
1000
+ /** Put all contents of map.
1003
+ public void putAll(Map m)
1005
+ Iterator i = m.entrySet().iterator();
1006
+ boolean multi=m instanceof MultiMap;
1007
+ while(i.hasNext())
1010
+ (Map.Entry)i.next();
1012
+ super.put(entry.getKey(),LazyList.clone(entry.getValue()));
1014
+ put(entry.getKey(),entry.getValue());
1018
+ /* ------------------------------------------------------------ */
1020
+ * @return Map of String arrays
1022
+ public Map toStringArrayMap()
1024
+ HashMap map = new HashMap(size()*3/2);
1026
+ Iterator i = super.entrySet().iterator();
1027
+ while(i.hasNext())
1029
+ Map.Entry entry = (Map.Entry)i.next();
1030
+ Object l = entry.getValue();
1031
+ String[] a = LazyList.toStringArray(l);
1032
+ // for (int j=a.length;j-->0;)
1033
+ // if (a[j]==null)
1035
+ map.put(entry.getKey(),a);
1040
+ /* ------------------------------------------------------------ */
1041
+ public Object clone()
1042
+ throws CloneNotSupportedException
1044
+ ConcurrentMultiMap mm = (ConcurrentMultiMap) super.clone();
1046
+ Iterator iter = mm.entrySet().iterator();
1047
+ while (iter.hasNext())
1049
+ Map.Entry entry = (Map.Entry)iter.next();
1050
+ entry.setValue(LazyList.clone(entry.getValue()));
1056
Index: modules/util/src/main/java/org/mortbay/util/DateCache.java
1057
===================================================================
1058
--- modules/util/src/main/java/org/mortbay/util/DateCache.java (revision 4733)
1059
+++ modules/util/src/main/java/org/mortbay/util/DateCache.java (working copy)
1061
String ss2 = _formatString.substring( zIndex+3 );
1062
int tzOffset = tz.getRawOffset();
1064
- StringBuffer sb = new StringBuffer(_formatString.length()+10);
1065
+ StringBuilder sb = new StringBuilder(_formatString.length()+10);
1069
@@ -254,17 +254,15 @@
1071
// Always format if we get here
1072
_lastSeconds = seconds;
1073
- StringBuffer sb=new StringBuffer(_secFormatString.length());
1076
- sb.append(_secFormatString0);
1077
- int s=(int)(seconds%60);
1081
- sb.append(_secFormatString1);
1082
- _lastResult=sb.toString();
1084
+ StringBuilder sb=new StringBuilder(_secFormatString.length());
1085
+ sb.append(_secFormatString0);
1086
+ int s=(int)(seconds%60);
1090
+ sb.append(_secFormatString1);
1091
+ _lastResult=sb.toString();
1097
/* ------------------------------------------------------------ */
1098
/** Format to string buffer.
1099
* @param inDate Date the format
1100
- * @param buffer StringBuffer
1101
+ * @param buffer StringBuilder
1103
- public void format(long inDate, StringBuffer buffer)
1104
+ public void format(long inDate, StringBuilder buffer)
1106
buffer.append(format(inDate));
1108
Index: modules/util/src/main/java/org/mortbay/util/MultiMap.java
1109
===================================================================
1110
--- modules/util/src/main/java/org/mortbay/util/MultiMap.java (revision 4733)
1111
+++ modules/util/src/main/java/org/mortbay/util/MultiMap.java (working copy)
1112
@@ -105,21 +105,20 @@
1113
Object o=LazyList.get(l,0);
1114
return o==null?null:o.toString();
1116
- StringBuffer values=new StringBuffer(128);
1117
- synchronized(values)
1119
+ StringBuilder values=new StringBuilder(128);
1120
+ for (int i=0; i<LazyList.size(l); i++)
1122
- for (int i=0; i<LazyList.size(l); i++)
1123
+ Object e=LazyList.get(l,i);
1126
- Object e=LazyList.get(l,i);
1129
- if (values.length()>0)
1130
- values.append(',');
1131
- values.append(e.toString());
1134
- return values.toString();
1136
+ if (values.length()>0)
1137
+ values.append(',');
1138
+ values.append(e.toString());
1141
+ return values.toString();
1146
Index: modules/util/src/main/java/org/mortbay/util/RolloverFileOutputStream.java
1147
===================================================================
1148
--- modules/util/src/main/java/org/mortbay/util/RolloverFileOutputStream.java (revision 4733)
1149
+++ modules/util/src/main/java/org/mortbay/util/RolloverFileOutputStream.java (working copy)
1151
synchronized(RolloverFileOutputStream.class)
1153
if (__rollover==null)
1154
- __rollover=new Timer(true);
1155
+ __rollover=new Timer(RolloverFileOutputStream.class.getName(),true);
1157
_rollTask=new RollTask();
1159
Index: modules/util/src/main/java/org/mortbay/util/Scanner.java
1160
===================================================================
1161
--- modules/util/src/main/java/org/mortbay/util/Scanner.java (revision 4733)
1162
+++ modules/util/src/main/java/org/mortbay/util/Scanner.java (working copy)
1165
public class Scanner
1167
+ private static int __scannerId=0;
1168
private int _scanInterval;
1169
private List _listeners = Collections.synchronizedList(new ArrayList());
1170
private Map _prevScan = new HashMap();
1173
public Timer newTimer ()
1175
- return new Timer(true);
1176
+ return new Timer("Scanner-"+__scannerId++, true);
1179
public void schedule ()
1180
Index: modules/util/src/main/java/org/mortbay/util/StringMap.java
1181
===================================================================
1182
--- modules/util/src/main/java/org/mortbay/util/StringMap.java (revision 4733)
1183
+++ modules/util/src/main/java/org/mortbay/util/StringMap.java (working copy)
1184
@@ -613,15 +613,12 @@
1185
public Object setValue(Object o){Object old=_value;_value=o;return old;}
1186
public String toString()
1188
- StringBuffer buf=new StringBuffer();
1193
+ StringBuilder buf=new StringBuilder();
1195
return buf.toString();
1198
- private void toString(StringBuffer buf)
1199
+ private void toString(StringBuilder buf)
1203
Index: modules/util/src/main/java/org/mortbay/util/StringUtil.java
1204
===================================================================
1205
--- modules/util/src/main/java/org/mortbay/util/StringUtil.java (revision 4733)
1206
+++ modules/util/src/main/java/org/mortbay/util/StringUtil.java (working copy)
1207
@@ -191,22 +191,20 @@
1211
- StringBuffer buf = new StringBuffer(s.length()+with.length());
1212
+ StringBuilder buf = new StringBuilder(s.length()+with.length());
1219
- buf.append(s.substring(c,i));
1222
- } while ((i=s.indexOf(sub,c))!=-1);
1225
- buf.append(s.substring(c,s.length()));
1227
- return buf.toString();
1229
+ buf.append(s.substring(c,i));
1232
+ } while ((i=s.indexOf(sub,c))!=-1);
1235
+ buf.append(s.substring(c,s.length()));
1237
+ return buf.toString();
1242
@@ -220,13 +218,13 @@
1245
/* ------------------------------------------------------------ */
1246
- /** Append substring to StringBuffer
1247
- * @param buf StringBuffer to append to
1248
+ /** Append substring to StringBuilder
1249
+ * @param buf StringBuilder to append to
1250
* @param s String to append from
1251
* @param offset The offset of the substring
1252
* @param length The length of the substring
1254
- public static void append(StringBuffer buf,
1255
+ public static void append(StringBuilder buf,
1263
- public static void append(StringBuffer buf,byte b,int base)
1264
+ public static void append(StringBuilder buf,byte b,int base)
1267
int c='0'+(bi/base)%base;
1269
buf.append((char)c);
1273
/* ------------------------------------------------------------ */
1274
public static void append2digits(StringBuffer buf,int i)
1276
@@ -274,6 +271,16 @@
1279
/* ------------------------------------------------------------ */
1280
+ public static void append2digits(StringBuilder buf,int i)
1284
+ buf.append((char)(i/10+'0'));
1285
+ buf.append((char)(i%10+'0'));
1289
+ /* ------------------------------------------------------------ */
1290
/** Return a non null string.
1292
* @return The string passed in or empty string if it is null.
1297
- StringBuffer buf = new StringBuffer(name.length());
1298
+ StringBuilder buf = new StringBuilder(name.length());
1299
for (int i=0;i<name.length();i++)
1301
char c=name.charAt(i);
1302
Index: modules/util/src/main/java/org/mortbay/util/TypeUtil.java
1303
===================================================================
1304
--- modules/util/src/main/java/org/mortbay/util/TypeUtil.java (revision 4733)
1305
+++ modules/util/src/main/java/org/mortbay/util/TypeUtil.java (working copy)
1307
/* ------------------------------------------------------------ */
1308
public static String toString(byte[] bytes, int base)
1310
- StringBuffer buf = new StringBuffer();
1311
+ StringBuilder buf = new StringBuilder();
1312
for (int i=0;i<bytes.length;i++)
1314
int bi=0xff&bytes[i];
1316
/* ------------------------------------------------------------ */
1317
public static String toHexString(byte[] b)
1319
- StringBuffer buf = new StringBuffer();
1320
+ StringBuilder buf = new StringBuilder();
1321
for (int i=0;i<b.length;i++)
1325
/* ------------------------------------------------------------ */
1326
public static String toHexString(byte[] b,int offset,int length)
1328
- StringBuffer buf = new StringBuffer();
1329
+ StringBuilder buf = new StringBuilder();
1330
for (int i=offset;i<offset+length;i++)
1333
Index: modules/util/src/main/java/org/mortbay/util/URIUtil.java
1334
===================================================================
1335
--- modules/util/src/main/java/org/mortbay/util/URIUtil.java (revision 4733)
1336
+++ modules/util/src/main/java/org/mortbay/util/URIUtil.java (working copy)
1338
if (path==null || path.length()==0)
1341
- StringBuffer buf = encodePath(null,path);
1342
+ StringBuilder buf = encodePath(null,path);
1343
return buf==null?path:buf.toString();
1346
/* ------------------------------------------------------------ */
1347
/** Encode a URI path.
1348
* @param path The path the encode
1349
- * @param buf StringBuffer to encode path into (or null)
1350
- * @return The StringBuffer or null if no substitutions required.
1351
+ * @param buf StringBuilder to encode path into (or null)
1352
+ * @return The StringBuilder or null if no substitutions required.
1354
- public static StringBuffer encodePath(StringBuffer buf, String path)
1355
+ public static StringBuilder encodePath(StringBuilder buf, String path)
1363
- buf=new StringBuffer(path.length()<<1);
1364
+ buf=new StringBuilder(path.length()<<1);
1368
@@ -124,13 +124,13 @@
1369
/* ------------------------------------------------------------ */
1370
/** Encode a URI path.
1371
* @param path The path the encode
1372
- * @param buf StringBuffer to encode path into (or null)
1373
+ * @param buf StringBuilder to encode path into (or null)
1374
* @param encode String of characters to encode. % is always encoded.
1375
- * @return The StringBuffer or null if no substitutions required.
1376
+ * @return The StringBuilder or null if no substitutions required.
1378
- public static StringBuffer encodeString(StringBuffer buf,
1381
+ public static StringBuilder encodeString(StringBuilder buf,
1388
char c=path.charAt(i);
1389
if (c=='%' || encode.indexOf(c)>=0)
1391
- buf=new StringBuffer(path.length()<<1);
1392
+ buf=new StringBuilder(path.length()<<1);
1397
/* ------------------------------------------------------------ */
1398
/* Decode a URI path.
1399
* @param path The path the encode
1400
- * @param buf StringBuffer to encode path into
1401
+ * @param buf StringBuilder to encode path into
1403
public static String decodePath(String path)
1406
/* ------------------------------------------------------------ */
1407
/* Decode a URI path.
1408
* @param path The path the encode
1409
- * @param buf StringBuffer to encode path into
1410
+ * @param buf StringBuilder to encode path into
1412
public static String decodePath(byte[] buf, int offset, int length)
1418
- StringBuffer buf = new StringBuffer(p1.length()+p2.length()+2);
1419
+ StringBuilder buf = new StringBuilder(p1.length()+p2.length()+2);
1422
if (buf.charAt(split-1)=='/')
1427
- StringBuffer buf = new StringBuffer(path);
1428
+ StringBuilder buf = new StringBuilder(path);
1432
Index: modules/util/src/main/java/org/mortbay/util/UrlEncoded.java
1433
===================================================================
1434
--- modules/util/src/main/java/org/mortbay/util/UrlEncoded.java (revision 4733)
1435
+++ modules/util/src/main/java/org/mortbay/util/UrlEncoded.java (working copy)
1436
@@ -116,57 +116,56 @@
1439
charset=StringUtil.__UTF8;
1441
- StringBuffer result = new StringBuffer(128);
1442
- synchronized(result)
1444
+ StringBuilder result = new StringBuilder(128);
1446
+ Iterator iter = map.entrySet().iterator();
1447
+ while(iter.hasNext())
1449
- Iterator iter = map.entrySet().iterator();
1450
- while(iter.hasNext())
1451
+ Map.Entry entry = (Map.Entry)iter.next();
1453
+ String key = entry.getKey().toString();
1454
+ Object list = entry.getValue();
1455
+ int s=LazyList.size(list);
1459
- Map.Entry entry = (Map.Entry)iter.next();
1461
- String key = entry.getKey().toString();
1462
- Object list = entry.getValue();
1463
- int s=LazyList.size(list);
1466
+ result.append(encodeString(key,charset));
1467
+ if(equalsForNullValue)
1468
+ result.append('=');
1472
+ for (int i=0;i<s;i++)
1475
+ result.append('&');
1476
+ Object val=LazyList.get(list,i);
1477
result.append(encodeString(key,charset));
1478
- if(equalsForNullValue)
1479
- result.append('=');
1483
- for (int i=0;i<s;i++)
1486
- result.append('&');
1487
- Object val=LazyList.get(list,i);
1488
- result.append(encodeString(key,charset));
1493
+ String str=val.toString();
1494
+ if (str.length()>0)
1496
- String str=val.toString();
1497
- if (str.length()>0)
1499
- result.append('=');
1500
- result.append(encodeString(str,charset));
1502
- else if (equalsForNullValue)
1503
- result.append('=');
1504
+ result.append('=');
1505
+ result.append(encodeString(str,charset));
1507
else if (equalsForNullValue)
1510
+ else if (equalsForNullValue)
1511
+ result.append('=');
1513
- if (iter.hasNext())
1514
- result.append('&');
1516
- return result.toString();
1517
+ if (iter.hasNext())
1518
+ result.append('&');
1520
+ return result.toString();
1525
/* -------------------------------------------------------------- */
1526
/** Decoded parameters to Map.
1527
* @param content the string containing the encoded parameters
1528
Index: modules/util/src/main/java/org/mortbay/util/Utf8StringBuffer.java
1529
===================================================================
1530
--- modules/util/src/main/java/org/mortbay/util/Utf8StringBuffer.java (revision 4733)
1531
+++ modules/util/src/main/java/org/mortbay/util/Utf8StringBuffer.java (working copy)
1533
* The UTF-8 decoding is done by this class and no additional buffers or Readers are used.
1534
* The UTF-8 code was inspired by http://javolution.org
1536
+ * This class is not synchronized and should probably be called Utf8StringBuilder
1538
public class Utf8StringBuffer
1540
Index: modules/util/src/test/java/org/mortbay/util/StringMapTest.java
1541
===================================================================
1542
--- modules/util/src/test/java/org/mortbay/util/StringMapTest.java (revision 4733)
1543
+++ modules/util/src/test/java/org/mortbay/util/StringMapTest.java (working copy)
1546
m5i.put("AbC", "x");
1548
- StringBuffer buffer=new StringBuffer();
1549
+ StringBuilder buffer=new StringBuilder();
1550
buffer.append("aBc");
1551
assertEquals("2",m5.get("abc"));
1552
assertEquals("x",m5.get(buffer));
1553
Index: modules/util/src/test/java/org/mortbay/util/StringUtilTest.java
1554
===================================================================
1555
--- modules/util/src/test/java/org/mortbay/util/StringUtilTest.java (revision 4733)
1556
+++ modules/util/src/test/java/org/mortbay/util/StringUtilTest.java (working copy)
1559
public void testAppend()
1561
- StringBuffer buf = new StringBuffer();
1562
+ StringBuilder buf = new StringBuilder();
1564
StringUtil.append(buf, "abc", 1, 1);
1565
StringUtil.append(buf, (byte)12, 16);
1566
Index: modules/util/src/test/java/org/mortbay/util/URITest.java
1567
===================================================================
1568
--- modules/util/src/test/java/org/mortbay/util/URITest.java (revision 4733)
1569
+++ modules/util/src/test/java/org/mortbay/util/URITest.java (working copy)
1571
public void testEncodePath()
1573
// test basic encode/decode
1574
- StringBuffer buf = new StringBuffer();
1575
+ StringBuilder buf = new StringBuilder();