01: //========================================================================
02: //$Id: SimpleBuffers.java,v 1.1 2005/10/05 14:09:25 janb Exp $
03: //Copyright 2004-2005 Mort Bay Consulting Pty. Ltd.
04: //------------------------------------------------------------------------
05: //Licensed under the Apache License, Version 2.0 (the "License");
06: //you may not use this file except in compliance with the License.
07: //You may obtain a copy of the License at
08: //http://www.apache.org/licenses/LICENSE-2.0
09: //Unless required by applicable law or agreed to in writing, software
10: //distributed under the License is distributed on an "AS IS" BASIS,
11: //WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: //See the License for the specific language governing permissions and
13: //limitations under the License.
14: //========================================================================
15:
16: package org.mortbay.io;
17:
18: /* ------------------------------------------------------------ */
19: /** SimpleBuffers.
20: * Simple implementation of Buffers holder.
21: * @author gregw
22: *
23: */
24: public class SimpleBuffers implements Buffers {
25: Buffer[] _buffers;
26:
27: /* ------------------------------------------------------------ */
28: /**
29: *
30: */
31: public SimpleBuffers(Buffer[] buffers) {
32: _buffers = buffers;
33: }
34:
35: /* ------------------------------------------------------------ */
36: /*
37: * @see org.mortbay.io.Buffers#getBuffer(boolean)
38: */
39: public Buffer getBuffer(int size) {
40: if (_buffers != null) {
41: for (int i = 0; i < _buffers.length; i++) {
42: if (_buffers[i] != null
43: && _buffers[i].capacity() == size) {
44: Buffer b = _buffers[i];
45: _buffers[i] = null;
46: return b;
47: }
48: }
49: }
50: return new ByteArrayBuffer(size);
51: }
52:
53: /* ------------------------------------------------------------ */
54: /*
55: * @see org.mortbay.io.Buffers#returnBuffer(org.mortbay.io.Buffer)
56: */
57: public void returnBuffer(Buffer buffer) {
58: buffer.clear();
59: if (_buffers != null) {
60: for (int i = 0; i < _buffers.length; i++) {
61: if (_buffers[i] == null)
62: _buffers[i] = buffer;
63: }
64: }
65: }
66:
67: }
|