286N/A/*
286N/A * reserved comment block
286N/A * DO NOT REMOVE OR ALTER!
286N/A */
286N/A/*
286N/A * Copyright 1999-2004 The Apache Software Foundation.
286N/A *
286N/A * Licensed under the Apache License, Version 2.0 (the "License");
286N/A * you may not use this file except in compliance with the License.
286N/A * You may obtain a copy of the License at
286N/A *
286N/A * http://www.apache.org/licenses/LICENSE-2.0
286N/A *
286N/A * Unless required by applicable law or agreed to in writing, software
286N/A * distributed under the License is distributed on an "AS IS" BASIS,
286N/A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
286N/A * See the License for the specific language governing permissions and
286N/A * limitations under the License.
286N/A */
286N/A/*
286N/A * $Id: StringBufferPool.java,v 1.2.4.1 2005/09/15 08:15:54 suresh_emailid Exp $
286N/A */
286N/Apackage com.sun.org.apache.xml.internal.utils;
286N/A
286N/A/**
286N/A * This class pools string buffers, since they are reused so often.
286N/A * String buffers are good candidates for pooling, because of
286N/A * their supporting character arrays.
286N/A * @xsl.usage internal
286N/A */
286N/Apublic class StringBufferPool
286N/A{
286N/A
286N/A /** The global pool of string buffers. */
286N/A private static ObjectPool m_stringBufPool =
286N/A new ObjectPool(com.sun.org.apache.xml.internal.utils.FastStringBuffer.class);
286N/A
286N/A /**
286N/A * Get the first free instance of a string buffer, or create one
286N/A * if there are no free instances.
286N/A *
286N/A * @return A string buffer ready for use.
286N/A */
286N/A public synchronized static FastStringBuffer get()
286N/A {
286N/A return (FastStringBuffer) m_stringBufPool.getInstance();
286N/A }
286N/A
286N/A /**
286N/A * Return a string buffer back to the pool.
286N/A *
286N/A * @param sb Must be a non-null reference to a string buffer.
286N/A */
286N/A public synchronized static void free(FastStringBuffer sb)
286N/A {
286N/A // Since this isn't synchronized, setLength must be
286N/A // done before the instance is freed.
286N/A // Fix attributed to Peter Speck <speck@ruc.dk>.
286N/A sb.setLength(0);
286N/A m_stringBufPool.freeInstance(sb);
286N/A }
286N/A}