< prev index next >

src/java.xml/share/classes/com/sun/xml/internal/stream/util/BufferAllocator.java

Print this page




  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.xml.internal.stream.util;
  27 
  28 import java.lang.ref.*;
  29 
  30 /**
  31  * Buffer allocator for buffers of sizes 128 B, 2 KB and 8 KB. Includes
  32  * methods for allocating and freeing buffers.
  33  *
  34  * @author Binu.John@sun.com
  35  * @author Santiago.PericasGeertsen@sun.com
  36  */
  37 public class BufferAllocator {
  38     private static final int SMALL_SIZE_LIMIT = 128;
  39     private static final int MEDIUM_SIZE_LIMIT = 2048;
  40     private static final int LARGE_SIZE_LIMIT = 8192;
  41 
  42     char[] smallCharBuffer;
  43     char[] mediumCharBuffer;
  44     char[] largeCharBuffer;
  45 
  46     byte[] smallByteBuffer;
  47     byte[] mediumByteBuffer;
  48     byte[] largeByteBuffer;
  49 
  50     public BufferAllocator() {
  51     }
  52 
  53     public char[] getCharBuffer(int size) {
  54         if (size <= SMALL_SIZE_LIMIT) {
  55             char[] buffer = smallCharBuffer;




  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.xml.internal.stream.util;
  27 
  28 import java.lang.ref.*;
  29 
  30 /**
  31  * Buffer allocator for buffers of sizes 128 B, 2 KB and 8 KB. Includes
  32  * methods for allocating and freeing buffers.
  33  *
  34  * @author Binu John
  35  * @author Santiago PericasGeertsen
  36  */
  37 public class BufferAllocator {
  38     private static final int SMALL_SIZE_LIMIT = 128;
  39     private static final int MEDIUM_SIZE_LIMIT = 2048;
  40     private static final int LARGE_SIZE_LIMIT = 8192;
  41 
  42     char[] smallCharBuffer;
  43     char[] mediumCharBuffer;
  44     char[] largeCharBuffer;
  45 
  46     byte[] smallByteBuffer;
  47     byte[] mediumByteBuffer;
  48     byte[] largeByteBuffer;
  49 
  50     public BufferAllocator() {
  51     }
  52 
  53     public char[] getCharBuffer(int size) {
  54         if (size <= SMALL_SIZE_LIMIT) {
  55             char[] buffer = smallCharBuffer;


< prev index next >