View Javadoc

1   // ========================================================================
2   // Copyright (c) 2008-2009 Mort Bay Consulting Pty. Ltd.
3   // ------------------------------------------------------------------------
4   // All rights reserved. This program and the accompanying materials
5   // are made available under the terms of the Eclipse Public License v1.0
6   // and Apache License v2.0 which accompanies this distribution.
7   // The Eclipse Public License is available at 
8   // http://www.eclipse.org/legal/epl-v10.html
9   // The Apache License v2.0 is available at
10  // http://www.opensource.org/licenses/apache2.0.php
11  // You may elect to redistribute this code under either of these licenses. 
12  // ========================================================================
13  package org.eclipse.jetty.io.nio;
14  
15  import java.nio.ByteBuffer;
16  
17  import org.eclipse.jetty.io.ByteArrayBuffer;
18  
19  public class IndirectNIOBuffer extends ByteArrayBuffer implements NIOBuffer
20  {
21      protected final ByteBuffer _buf;
22  
23      /* ------------------------------------------------------------ */
24      public IndirectNIOBuffer(int size)
25      {
26          super(size,READWRITE,NON_VOLATILE);
27          _buf = ByteBuffer.wrap(_bytes);
28          _buf.position(0);
29          _buf.limit(_buf.capacity());
30      }
31  
32      /* ------------------------------------------------------------ */
33      public IndirectNIOBuffer(ByteBuffer buffer,boolean immutable)
34      {
35          super(buffer.array(),0,0, immutable?IMMUTABLE:READWRITE,NON_VOLATILE);
36          if (buffer.isDirect())
37              throw new IllegalArgumentException();
38          _buf = buffer;
39          _get=buffer.position();
40          _put=buffer.limit();
41          buffer.position(0);
42          buffer.limit(buffer.capacity());
43      }
44      
45      /* ------------------------------------------------------------ */
46      public ByteBuffer getByteBuffer()
47      {
48          return _buf;
49      }
50  
51      /* ------------------------------------------------------------ */
52      public boolean isDirect()
53      {
54          return false;
55      }
56  }