/[classpath]/classpath/java/nio/CharBuffer.java
ViewVC logotype

Diff of /classpath/java/nio/CharBuffer.java

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

revision 1.7 by mkoch, Sat Nov 23 10:34:04 2002 UTC revision 1.8 by mkoch, Mon Nov 25 07:42:48 2002 UTC
# Line 49  public abstract class CharBuffer extends Line 49  public abstract class CharBuffer extends
49    
50    protected char [] backing_buffer;    protected char [] backing_buffer;
51    
52    public static CharBuffer allocateDirect (int capacity)    private int array_offset;
53    {  
54      return new CharBufferImpl (capacity, 0, capacity);    /**
55    }     * Allocats a non-direct character buffer.
56         */
57    public static CharBuffer allocate(int capacity)    public static CharBuffer allocate(int capacity)
58    {    {
59      return new CharBufferImpl (capacity, 0, capacity);      return new CharBufferImpl (capacity, 0, capacity);
60    }    }
61        
62      /**
63       * Wraps a character array into a buffer.
64       *
65       * @exception IndexOutOfBoundsException If the preconditions on the offset
66       * and length parameters do not hold
67       */
68    final public static CharBuffer wrap (char[] array, int offset, int length)    final public static CharBuffer wrap (char[] array, int offset, int length)
69    {    {
70      return new CharBufferImpl (array, offset, length);      return new CharBufferImpl (array, offset, offset + length);
71    }    }
72    
73      /**
74       * Wraps a character array into a buffer.
75       */
76    final public static CharBuffer wrap (char[] array)    final public static CharBuffer wrap (char[] array)
77    {    {
78      return wrap (array, 0, array.length);      return wrap (array, 0, array.length);
79    }    }
80        
81      /**
82       * Wraps a character sequence into a buffer.
83       *
84       * @exception IndexOutOfBoundsException If the preconditions on the offset
85       * and length parameters do not hold
86       */
87    final public static CharBuffer wrap (CharSequence cs, int offset, int length)    final public static CharBuffer wrap (CharSequence cs, int offset, int length)
88    {    {
89      return wrap (cs.toString ().toCharArray (), 0, length);      return wrap (cs.toString ().toCharArray (), 0, length);
90    }    }
91        
92      /**
93       * Wraps a character sequence into a buffer.
94       */
95    final public static CharBuffer wrap (CharSequence cs)    final public static CharBuffer wrap (CharSequence cs)
96    {    {
97      return wrap (cs, 0, cs.length ());      return wrap (cs, 0, cs.length ());
98    }    }
99      
100      /**
101       * Relative bulk get method.
102       *
103       * @exception BufferUnderflowException If there are fewer than length
104       * characters remaining in this buffer.
105       * @exception IndexOutOfBoundsException If the preconditions on the offset
106       * and length parameters do not hold.
107       */
108    final public CharBuffer get (char[] dst, int offset, int length)    final public CharBuffer get (char[] dst, int offset, int length)
109    {    {
110        if (offset < 0 ||
111            offset > dst.length ||
112            length < 0 ||
113            length > (dst.length - offset))
114          throw new IndexOutOfBoundsException ();
115    
116      for (int i = offset; i < offset + length; i++)      for (int i = offset; i < offset + length; i++)
117        dst [i] = get ();        dst [i] = get ();
118            
119      return this;      return this;
120    }    }
121    
122      /**
123       * Relative bulk get method.
124       *
125       * @exception BufferUnderflowException If there are fewer than length
126       * characters remaining in this buffer.
127       */
128    final public CharBuffer get (char[] dst)    final public CharBuffer get (char[] dst)
129    {    {
130      return get (dst, 0, dst.length);      return get (dst, 0, dst.length);
131    }    }
132      
133      /**
134       * Relative bulk put method.
135       *
136       * @exception BufferOverflowException If there is insufficient space in this
137       * buffer for the remaining characters in the source buffer.
138       * @exception IllegalArgumentException If the source buffer is this buffer.
139       * @exception ReadOnlyBufferException If this buffer is read-only.
140       */
141    final public CharBuffer put (CharBuffer src)    final public CharBuffer put (CharBuffer src)
142    {    {
143        if (src == this)
144          throw new IllegalArgumentException ();
145    
146      while (src.hasRemaining ())      while (src.hasRemaining ())
147        put (src.get ());        {
148            put (src.get ());
149          }
150    
151      return this;      return this;
152    }    }
153    
154      /**
155       * Relative bulk put method.
156       *
157       * @exception BufferOverflowException If there is insufficient space in this
158       * buffer for the remaining characters in the source buffer.
159       * @exception IndexOutOfBoundsException If the preconditions on the offset
160       * and length parameters do not hold.
161       * @exception ReadOnlyBufferException If this buffer is read-only.
162       */
163    final public CharBuffer put (char[] src, int offset, int length)    final public CharBuffer put (char[] src, int offset, int length)
164    {    {
165        if (offset < 0 ||
166            offset > src.length ||
167            length < 0 ||
168            length > (src.length - offset))
169          throw new IndexOutOfBoundsException ();
170        
171      for (int i = offset; i < offset + length; i++)      for (int i = offset; i < offset + length; i++)
172        put (src[i]);        {
173            put (src[i]);
174          }
175            
176      return this;      return this;
177    }    }
178    
179      /**
180       * Relative bulk put method.
181       *
182       * @exception BufferOverflowException If there is insufficient space in this
183       * buffer for the remaining characters in the source buffer.
184       * @exception IndexOutOfBoundsException If the preconditions on the start and
185       * end parameters do not hold.
186       * @exception ReadOnlyBufferException If this buffer is read-only.
187       */
188      public CharBuffer put(String src, int offset, int length)
189      {
190        return put (src.toCharArray (), offset, length);
191      }
192    
193      /**
194       * Relative bulk put method.
195       *
196       * @exception BufferOverflowException If there is insufficient space in this
197       * buffer for the remaining characters in the source buffer.
198       * @exception ReadOnlyBufferException If this buffer is read-only.
199       */
200    public final CharBuffer put(String src)    public final CharBuffer put(String src)
201    {    {
202      return put (src.toCharArray (), 0, src.length ());      return put (src, 0, src.length ());
203    }    }
204    
205    /**    /**
# Line 128  public abstract class CharBuffer extends Line 217  public abstract class CharBuffer extends
217      return put (src, 0, src.length);      return put (src, 0, src.length);
218    }    }
219    
220      /**
221       * Tells wether this buffer has a backing array or not.
222       */
223    public final boolean hasArray ()    public final boolean hasArray ()
224    {    {
225      return backing_buffer != null;      return backing_buffer != null;
226    }    }
227    
228      /**
229       * Retrieves the backing buffer.
230       *
231       * @exception ReadOnlyBufferException If this buffer is read-only.
232       * @exception UnsupportedOperationException If this buffer is not backed by an accessible array.
233       */
234    public final char[] array ()    public final char[] array ()
235    {    {
236        if (!hasArray ())
237          throw new UnsupportedOperationException ();
238    
239        if (isReadOnly ())
240          throw new ReadOnlyBufferException ();
241    
242      return backing_buffer;      return backing_buffer;
243    }    }
244      
245      /**
246       * Returns the offset within this buffer's backing array of the first element of the buffer.
247       *
248       * @exception ReadOnlyBufferException If this buffer is read-only.
249       * @exception UnsupportedOperationException If this buffer is not backed by an accessible array.
250       */  
251    public final int arrayOffset ()    public final int arrayOffset ()
252    {    {
253      return 0;      if (!hasArray ())
254          throw new UnsupportedOperationException ();
255    
256        if (isReadOnly ())
257          throw new ReadOnlyBufferException ();
258    
259        return array_offset;
260    }    }
261        
262      /**
263       * Returns the current hash code of this buffer.
264       */
265    public int hashCode ()    public int hashCode ()
266    {    {
267        // FIXME
268      return super.hashCode ();      return super.hashCode ();
269    }    }
270        
271      /**
272       * Tells whether or not this buffer is equal to another object.
273       */
274    public boolean equals (Object obj)    public boolean equals (Object obj)
275    {    {
276      if (obj instanceof CharBuffer)      if (obj instanceof CharBuffer)
# Line 156  public abstract class CharBuffer extends Line 279  public abstract class CharBuffer extends
279      return false;      return false;
280    }    }
281    
282      /**
283       * Creates a new character buffer that represents the specified subsequence
284       * of this buffer, relative to the current position.
285       *
286       * @exception IndexOutOfBoundsException If the preconditions on start and end
287       * do not hold.
288       */
289    public abstract CharSequence subSequence (int start, int end);    public abstract CharSequence subSequence (int start, int end);
290    
291      /**
292       * Returns the length of this character buffer.
293       */
294    public final int length ()    public final int length ()
295    {    {
296      return remaining ();      return remaining ();
297    }    }
298    
299    public final char charAt (int i)    /**
300       * Reads the character at the given index relative to the current position.
301       *
302       * @exception IndexOutOfBoundsException If the preconditions on index
303       * do not hold.
304       */
305      public final char charAt (int index)
306    {    {
307      if (i < 0 || i >= length ())      if (index < 0 ||
308            index >= length ())
309        throw new IndexOutOfBoundsException ();        throw new IndexOutOfBoundsException ();
310    
311      return get (position () + i);      return get (position () + index);
312    }    }
313    
314      /**
315       * Retrieves the content of the character buffer as string.
316       */
317    public String toString()    public String toString()
318    {    {
319      if (hasArray ())      if (hasArray ())
# Line 185  public abstract class CharBuffer extends Line 328  public abstract class CharBuffer extends
328    
329      return sb.toString ();      return sb.toString ();
330    }    }
331    
332      /**
333       * Compares this buffer to another object.
334       *
335       * @exception ClassCastException If the argument is not a char buffer.
336       */
337    public int compareTo(Object obj)    public int compareTo(Object obj)
338    {    {
339      CharBuffer a = (CharBuffer) obj;      CharBuffer a = (CharBuffer) obj;
# Line 210  public abstract class CharBuffer extends Line 358  public abstract class CharBuffer extends
358      return 0;      return 0;
359    }    }
360    
361    public final ByteOrder order()    /**
362    {     * Retrieves the current endianess of this buffer.
363      return endian;     */
364    }    public abstract ByteOrder order();
     
   public final CharBuffer order(ByteOrder bo)  
   {  
     endian = bo;  
     return this;  
   }  
365        
366      /**
367       * Relative bulk get method.
368       *
369       * @exception BufferUnderflowException If there are fewer than length
370       * characters remaining in this buffer.
371       */
372    public abstract char get();    public abstract char get();
373      
374      /**
375       * Relative bulk get method.
376       *
377       * @exception BufferOverflowException If this buffer's current position is
378       * not smaller than its limit.
379       * @exception ReadOnlyBufferException If this buffer is read-only.
380       */
381    public abstract CharBuffer put(char b);    public abstract CharBuffer put(char b);
382      
383      /**
384       * Absolute bulk get method.
385       *
386       * @exception IndexOutOfBoundsException If index is negative or not smaller
387       * than the buffer's limit.
388       */
389    public abstract char get(int index);    public abstract char get(int index);
390    
391      /**
392       * Absolute bulk put method.
393       *
394       * @exception IndexOutOfBoundsException If index is negative or not smaller
395       * than the buffer's limit.
396       * @exception ReadOnlyBufferException If this buffer is read-only.
397       */
398    public abstract CharBuffer put(int index, char b);    public abstract CharBuffer put(int index, char b);
399    
400      /**
401       * Compacts this buffer.
402       *
403       * @exception ReadOnlyBufferException If this buffer is read-only.
404       */
405    public abstract CharBuffer compact();    public abstract CharBuffer compact();
406    
407      /**
408       * Tells wether or not this is a direct buffer.
409       */
410    public abstract boolean isDirect();    public abstract boolean isDirect();
411    
412      /**
413       * Creates a new character buffer whose content is a shared subsequence of
414       * this buffer's content.
415       */
416    public abstract CharBuffer slice();    public abstract CharBuffer slice();
417    
418      /**
419       * Creates a new character buffer that shares this buffer's content.
420       */
421    public abstract CharBuffer duplicate();    public abstract CharBuffer duplicate();
422    
423      /**
424       * Creates a new, read-only character buffer that shares this buffer's
425       * content.
426       */
427    public abstract CharBuffer asReadOnlyBuffer();    public abstract CharBuffer asReadOnlyBuffer();
   public abstract ShortBuffer asShortBuffer();  
   public abstract CharBuffer asCharBuffer();  
   public abstract IntBuffer asIntBuffer();  
   public abstract LongBuffer asLongBuffer();  
   public abstract FloatBuffer asFloatBuffer();  
   public abstract DoubleBuffer asDoubleBuffer();  
   public abstract char getChar();  
   public abstract CharBuffer putChar(char value);  
   public abstract char getChar(int index);  
   public abstract CharBuffer putChar(int index, char value);  
   public abstract short getShort();  
   public abstract CharBuffer putShort(short value);  
   public abstract short getShort(int index);  
   public abstract CharBuffer putShort(int index, short value);  
   public abstract int getInt();  
   public abstract CharBuffer putInt(int value);  
   public abstract int getInt(int index);  
   public abstract CharBuffer putInt(int index, int value);  
   public abstract long getLong();  
   public abstract CharBuffer putLong(long value);  
   public abstract long getLong(int index);  
   public abstract CharBuffer putLong(int index, long value);  
   public abstract float getFloat();  
   public abstract CharBuffer putFloat(float value);  
   public abstract float getFloat(int index);  
   public abstract CharBuffer putFloat(int index, float value);  
   public abstract double getDouble();  
   public abstract CharBuffer putDouble(double value);  
   public abstract double getDouble(int index);  
   public abstract CharBuffer putDouble(int index, double value);  
428  }  }

Legend:
Removed from v.1.7  
changed lines
  Added in v.1.8

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