2
* Licensed to the Apache Software Foundation (ASF) under one
3
* or more contributor license agreements. See the NOTICE file
4
* distributed with this work for additional information
5
* regarding copyright ownership. The ASF licenses this file
6
* to you under the Apache License, Version 2.0 (the "License");
7
* you may not use this file except in compliance with the License.
8
* You may obtain a copy of the License at
10
* http://www.apache.org/licenses/LICENSE-2.0
12
* Unless required by applicable law or agreed to in writing, software
13
* distributed under the License is distributed on an "AS IS" BASIS,
14
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
* See the License for the specific language governing permissions and
16
* limitations under the License.
19
* $Id: StringBufferPool.java,v 1.2 2009/12/10 03:18:23 matthewoliver Exp $
21
package org.apache.xml.utils;
24
* This class pools string buffers, since they are reused so often.
25
* String buffers are good candidates for pooling, because of
26
* their supporting character arrays.
29
public class StringBufferPool
32
/** The global pool of string buffers. */
33
private static ObjectPool m_stringBufPool =
34
new ObjectPool(org.apache.xml.utils.FastStringBuffer.class);
37
* Get the first free instance of a string buffer, or create one
38
* if there are no free instances.
40
* @return A string buffer ready for use.
42
public synchronized static FastStringBuffer get()
44
return (FastStringBuffer) m_stringBufPool.getInstance();
48
* Return a string buffer back to the pool.
50
* @param sb Must be a non-null reference to a string buffer.
52
public synchronized static void free(FastStringBuffer sb)
54
// Since this isn't synchronized, setLength must be
55
// done before the instance is freed.
56
// Fix attributed to Peter Speck <speck@ruc.dk>.
58
m_stringBufPool.freeInstance(sb);