47 |
{ |
{ |
48 |
protected int array_offset = 0; |
protected int array_offset = 0; |
49 |
protected char [] backing_buffer; |
protected char [] backing_buffer; |
50 |
|
|
51 |
protected CharBuffer (int cap, int lim, int pos, int mark) |
protected CharBuffer (int capacity, int limit, int position, int mark) |
52 |
{ |
{ |
53 |
super (cap, lim, pos, mark); |
super (capacity, limit, position, mark); |
54 |
|
array_offset = 0; |
55 |
} |
} |
56 |
|
|
57 |
|
protected CharBuffer (char[] buffer, int offset, int capacity, int limit, int position, int mark) |
58 |
|
{ |
59 |
|
super (capacity, limit, position, mark); |
60 |
|
this.backing_buffer = buffer; |
61 |
|
this.array_offset = offset; |
62 |
|
} |
63 |
|
|
64 |
/** |
/** |
65 |
* Allocates a new <code>CharBuffer</code> object with a given capacity. |
* Allocates a new <code>CharBuffer</code> object with a given capacity. |
66 |
*/ |
*/ |
67 |
public static CharBuffer allocate (int capacity) |
public static CharBuffer allocate (int capacity) |
68 |
{ |
{ |
69 |
return new CharBufferImpl (capacity, 0, capacity); |
return new CharBufferImpl (capacity); |
70 |
} |
} |
71 |
|
|
72 |
/** |
/** |
78 |
*/ |
*/ |
79 |
final public static CharBuffer wrap (char[] array, int offset, int length) |
final public static CharBuffer wrap (char[] array, int offset, int length) |
80 |
{ |
{ |
81 |
return new CharBufferImpl (array, offset, length); |
return new CharBufferImpl (array, 0, array.length, offset + length, offset, -1, false); |
82 |
} |
} |
83 |
|
|
84 |
/** |
/** |
113 |
buffer [i] = a.charAt (i); |
buffer [i] = a.charAt (i); |
114 |
} |
} |
115 |
|
|
|
// FIXME: make it read-only. |
|
|
//return wrap (buffer, offset, length); |
|
116 |
return wrap (buffer, offset, length).asReadOnlyBuffer (); |
return wrap (buffer, offset, length).asReadOnlyBuffer (); |
117 |
} |
} |
118 |
|
|
124 |
{ |
{ |
125 |
return wrap (array, 0, array.length); |
return wrap (array, 0, array.length); |
126 |
} |
} |
127 |
|
|
128 |
/** |
/** |
129 |
* This method transfers <code>chars<code> from this buffer into the given |
* This method transfers <code>chars<code> from this buffer into the given |
130 |
* destination array. |
* destination array. |
180 |
if (src == this) |
if (src == this) |
181 |
throw new IllegalArgumentException (); |
throw new IllegalArgumentException (); |
182 |
|
|
183 |
if (src.length () > 0) |
if (src.remaining () > remaining ()) |
184 |
|
throw new BufferOverflowException (); |
185 |
|
|
186 |
|
if (src.remaining () > 0) |
187 |
{ |
{ |
188 |
char [] toPut = new char [src.length ()]; |
char[] toPut = new char [src.remaining ()]; |
189 |
src.get (toPut); |
src.get (toPut); |
190 |
src.put (toPut); |
src.put (toPut); |
191 |
} |
} |
214 |
if (offset < 0 |
if (offset < 0 |
215 |
|| offset >= src.length |
|| offset >= src.length |
216 |
|| length < 0 |
|| length < 0 |
217 |
|| length >= (src.length - offset)) |
|| length > (src.length - offset)) |
218 |
throw new IndexOutOfBoundsException (); |
throw new IndexOutOfBoundsException (); |
219 |
|
|
220 |
// Put nothing into this buffer when not enough space left. |
// Put nothing into this buffer when not enough space left. |
347 |
} |
} |
348 |
|
|
349 |
/** |
/** |
350 |
|
* Returns the byte order of this buffer. |
351 |
|
*/ |
352 |
|
public abstract ByteOrder order (); |
353 |
|
|
354 |
|
/** |
355 |
* Reads the <code>char</code> at this buffer's current position, |
* Reads the <code>char</code> at this buffer's current position, |
356 |
* and then increments the position. |
* and then increments the position. |
357 |
* |
* |
422 |
*/ |
*/ |
423 |
public String toString () |
public String toString () |
424 |
{ |
{ |
425 |
char[] data = new char [length ()]; |
if (hasArray ()) |
426 |
get (data, 0, length ()); |
return new String (array (), position (), length ()); |
427 |
return new String (data, position (), length ()); |
|
428 |
|
char[] buf = new char [length ()]; |
429 |
|
int pos = position (); |
430 |
|
get (buf, 0, buf.length); |
431 |
|
position (pos); |
432 |
|
return new String (buf); |
433 |
} |
} |
434 |
|
|
435 |
/** |
/** |
441 |
} |
} |
442 |
|
|
443 |
/** |
/** |
|
* Returns the byte order of this buffer. |
|
|
*/ |
|
|
public abstract ByteOrder order (); |
|
|
|
|
|
/** |
|
444 |
* Creates a new character buffer that represents the specified subsequence |
* Creates a new character buffer that represents the specified subsequence |
445 |
* of this buffer, relative to the current position. |
* of this buffer, relative to the current position. |
446 |
* |
* |
472 |
*/ |
*/ |
473 |
public final CharBuffer put (String str) |
public final CharBuffer put (String str) |
474 |
{ |
{ |
475 |
return put (str, 0, str.length ()); |
return put (str.toCharArray (), 0, str.length ()); |
476 |
} |
} |
477 |
|
|
478 |
/** |
/** |