/[classpath]/classpath/gnu/java/nio/IntBufferImpl.java
ViewVC logotype

Diff of /classpath/gnu/java/nio/IntBufferImpl.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.13 by mkoch, Tue Mar 11 08:02:22 2003 UTC revision 1.14 by mkoch, Tue Mar 11 11:48:51 2003 UTC
# Line 40  package gnu.java.nio; Line 40  package gnu.java.nio;
40  import java.nio.ByteBuffer;  import java.nio.ByteBuffer;
41  import java.nio.ByteOrder;  import java.nio.ByteOrder;
42  import java.nio.IntBuffer;  import java.nio.IntBuffer;
43    import java.nio.ReadOnlyBufferException;
44    
45    /**
46     * This is a Heap memory implementation
47     */
48  public final class IntBufferImpl extends IntBuffer  public final class IntBufferImpl extends IntBuffer
49  {  {
50    private int array_offset;    private boolean readOnly;
   private boolean ro;  
51        
52    public IntBufferImpl(int cap, int off, int lim)    public IntBufferImpl(int cap, int off, int lim)
53    {    {
54        super (cap, lim, off, 0);
55      this.backing_buffer = new int[cap];      this.backing_buffer = new int[cap];
56      this.cap = cap;      readOnly = false;
     this.limit(lim);  
     this.position(off);  
57    }    }
58    
59    public IntBufferImpl(int[] array, int off, int lim)    public IntBufferImpl(int[] array, int offset, int length)
60    {    {
61        super (array.length, length, offset, 0);
62      this.backing_buffer = array;      this.backing_buffer = array;
63      this.cap = array.length;      readOnly = false;
     this.limit(lim);  
     this.position(off);  
64    }    }
65    
66    public IntBufferImpl(IntBufferImpl copy)    public IntBufferImpl(IntBufferImpl copy)
67    {    {
68        super (copy.capacity (), copy.limit (), copy.position (), 0);
69      backing_buffer = copy.backing_buffer;      backing_buffer = copy.backing_buffer;
70      ro = copy.ro;      readOnly = copy.isReadOnly ();
     limit(copy.limit());  
     position(copy.position());  
   }  
   
   void inc_pos(int a)  
   {  
     position(position() + a);  
71    }    }
72    
73    private static native int[] nio_cast (byte[] copy);    private static native int[] nio_cast (byte[] copy);
74    
75    IntBufferImpl (byte[] copy)    IntBufferImpl (byte[] copy)
76    {    {
77        super (copy.length, copy.length, 0, 0);
78      this.backing_buffer = copy != null ? nio_cast (copy) : null;      this.backing_buffer = copy != null ? nio_cast (copy) : null;
79        readOnly = false;
80    }    }
81    
82    private static native byte nio_get_Byte (IntBufferImpl b, int index, int limit);    private static native byte nio_get_Byte (IntBufferImpl b, int index, int limit);
# Line 95  public final class IntBufferImpl extends Line 92  public final class IntBufferImpl extends
92    
93    public boolean isReadOnly()    public boolean isReadOnly()
94    {    {
95      return ro;      return readOnly;
96    }    }
97    
98    public IntBuffer slice()    public IntBuffer slice()
99    {    {
100      IntBufferImpl A = new IntBufferImpl(this);      return new IntBufferImpl (this);
     A.array_offset = position();  
     return A;  
101    }    }
102    
103    public IntBuffer duplicate()    public IntBuffer duplicate()
# Line 112  public final class IntBufferImpl extends Line 107  public final class IntBufferImpl extends
107    
108    public IntBuffer asReadOnlyBuffer()    public IntBuffer asReadOnlyBuffer()
109    {    {
110      IntBufferImpl a = new IntBufferImpl(this);      IntBufferImpl result = new IntBufferImpl (this);
111      a.ro = true;      result.readOnly = true;
112      return a;      return result;
113    }    }
114    
115    public IntBuffer compact()    public IntBuffer compact()
# Line 124  public final class IntBufferImpl extends Line 119  public final class IntBufferImpl extends
119    
120    public boolean isDirect()    public boolean isDirect()
121    {    {
122      return backing_buffer != null;      return false;
123    }    }
124    
125    final public int get()    final public int get()
# Line 136  public final class IntBufferImpl extends Line 131  public final class IntBufferImpl extends
131    
132    final public IntBuffer put(int b)    final public IntBuffer put(int b)
133    {    {
134        if (readOnly)
135          throw new ReadOnlyBufferException ();
136        
137      backing_buffer[position()] = b;      backing_buffer[position()] = b;
138      position(position()+1);      position(position()+1);
139      return this;      return this;
# Line 148  public final class IntBufferImpl extends Line 146  public final class IntBufferImpl extends
146    
147    final public IntBuffer put(int index, int b)    final public IntBuffer put(int index, int b)
148    {    {
149        if (readOnly)
150          throw new ReadOnlyBufferException ();
151        
152      backing_buffer[index] = b;      backing_buffer[index] = b;
153      return this;      return this;
154    }    }

Legend:
Removed from v.1.13  
changed lines
  Added in v.1.14

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26