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

Diff of /classpath/gnu/java/nio/ShortBufferImpl.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.ShortBuffer;  import java.nio.ShortBuffer;
43    import java.nio.ReadOnlyBufferException;
44    
45    /**
46     * This is a Heap memory implementation
47     */
48  public final class ShortBufferImpl extends ShortBuffer  public final class ShortBufferImpl extends ShortBuffer
49  {  {
50    private int array_offset;    private boolean readOnly;
   private boolean ro;  
51    
52    public ShortBufferImpl(int cap, int off, int lim)    public ShortBufferImpl(int cap, int off, int lim)
53    {    {
54      this.backing_buffer = new short[cap];      super (cap, lim, off, 0);
55      this.cap = cap ;      this.backing_buffer = new short [cap];
56      this.limit(lim);      readOnly = false;
     this.position(off);  
57    }    }
58    
59    public ShortBufferImpl(short[] array, int off, int lim)    public ShortBufferImpl(short[] 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 ShortBufferImpl(ShortBufferImpl copy)    public ShortBufferImpl(ShortBufferImpl 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 short[] nio_cast (byte[] copy);    private static native short[] nio_cast (byte[] copy);
74    
75    ShortBufferImpl (byte[] copy)    ShortBufferImpl (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 (ShortBufferImpl b, int index, int limit);    private static native byte nio_get_Byte (ShortBufferImpl b, int index, int limit);
# Line 95  public final class ShortBufferImpl exten Line 92  public final class ShortBufferImpl exten
92    
93    public boolean isReadOnly()    public boolean isReadOnly()
94    {    {
95      return ro;      return readOnly;
96    }    }
97    
98    public ShortBuffer slice()    public ShortBuffer slice()
99    {    {
100      ShortBufferImpl a = new ShortBufferImpl(this);      return new ShortBufferImpl (this);
     a.array_offset = position();  
     return a;  
101    }    }
102    
103    public ShortBuffer duplicate()    public ShortBuffer duplicate()
# Line 112  public final class ShortBufferImpl exten Line 107  public final class ShortBufferImpl exten
107    
108    public ShortBuffer asReadOnlyBuffer()    public ShortBuffer asReadOnlyBuffer()
109    {    {
110      ShortBufferImpl a = new ShortBufferImpl(this);      ShortBufferImpl result = new ShortBufferImpl (this);
111      a.ro = true;      result.readOnly = true;
112      return a;      return result;
113    }    }
114    
115    public ShortBuffer compact()    public ShortBuffer compact()
# Line 124  public final class ShortBufferImpl exten Line 119  public final class ShortBufferImpl exten
119    
120    public boolean isDirect()    public boolean isDirect()
121    {    {
122      return backing_buffer != null;      return false;
123    }    }
124    
125    final public short get()    final public short get()
# Line 136  public final class ShortBufferImpl exten Line 131  public final class ShortBufferImpl exten
131    
132    final public ShortBuffer put(short b)    final public ShortBuffer put(short 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 ShortBufferImpl exten Line 146  public final class ShortBufferImpl exten
146    
147    final public ShortBuffer put(int index, short b)    final public ShortBuffer put(int index, short 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