45 |
public abstract class ByteBuffer extends Buffer implements Comparable |
public abstract class ByteBuffer extends Buffer implements Comparable |
46 |
{ |
{ |
47 |
private ByteOrder endian = ByteOrder.BIG_ENDIAN; |
private ByteOrder endian = ByteOrder.BIG_ENDIAN; |
48 |
|
|
49 |
protected byte [] backing_buffer; |
int offset; |
50 |
|
byte[] backing_buffer; |
51 |
|
|
52 |
/** |
/** |
53 |
* Allocates a new direct byte buffer. |
* Allocates a new direct byte buffer. |
54 |
*/ |
*/ |
55 |
public static ByteBuffer allocateDirect (int capacity) |
public static ByteBuffer allocateDirect (int capacity) |
56 |
{ |
{ |
57 |
ByteBuffer b = new gnu.java.nio. ByteBufferImpl(capacity, 0, capacity); |
throw new Error ("direct buffers are not implemented"); |
|
return b; |
|
58 |
} |
} |
59 |
|
|
60 |
/** |
/** |
75 |
{ |
{ |
76 |
return new ByteBufferImpl (array, offset, length); |
return new ByteBufferImpl (array, offset, length); |
77 |
} |
} |
78 |
|
|
79 |
/** |
/** |
80 |
* Wraps a byte array into a buffer. |
* Wraps a byte array into a buffer. |
81 |
*/ |
*/ |
101 |
*/ |
*/ |
102 |
public ByteBuffer get (byte[] dst, int offset, int length) |
public ByteBuffer get (byte[] dst, int offset, int length) |
103 |
{ |
{ |
104 |
if ((offset < 0) || |
if ((offset < 0) |
105 |
(offset > dst.length) || |
|| (offset > dst.length) |
106 |
(length < 0) || |
|| (length < 0) |
107 |
(length > (dst.length - offset))) |
|| (length > (dst.length - offset))) |
108 |
throw new IndexOutOfBoundsException (); |
throw new IndexOutOfBoundsException (); |
109 |
|
|
110 |
for (int i = offset; i < offset + length; i++) |
for (int i = offset; i < offset + length; i++) |
145 |
throw new IllegalArgumentException (); |
throw new IllegalArgumentException (); |
146 |
|
|
147 |
while (src.hasRemaining ()) |
while (src.hasRemaining ()) |
148 |
{ |
put (src.get ()); |
|
put (src.get ()); |
|
|
} |
|
149 |
|
|
150 |
return this; |
return this; |
151 |
} |
} |
174 |
throw new IndexOutOfBoundsException (); |
throw new IndexOutOfBoundsException (); |
175 |
|
|
176 |
for (int i = offset; i < offset + length; i++) |
for (int i = offset; i < offset + length; i++) |
177 |
{ |
put (src [i]); |
178 |
put (src [i]); |
|
|
} |
|
|
|
|
179 |
return this; |
return this; |
180 |
} |
} |
181 |
|
|
196 |
/** |
/** |
197 |
* Tells whether or not this buffer is backed by an accessible byte array. |
* Tells whether or not this buffer is backed by an accessible byte array. |
198 |
*/ |
*/ |
199 |
public final boolean hasArray() |
public final boolean hasArray () |
200 |
{ |
{ |
201 |
return (backing_buffer != null); |
return (backing_buffer != null |
202 |
|
&& !isReadOnly ()); |
203 |
} |
} |
204 |
|
|
205 |
/** |
/** |
210 |
* @exception UnsupportedOperationException If this buffer is not backed |
* @exception UnsupportedOperationException If this buffer is not backed |
211 |
* by an accessible array. |
* by an accessible array. |
212 |
*/ |
*/ |
213 |
public final byte[] array() |
public final byte[] array () |
214 |
{ |
{ |
215 |
if (backing_buffer == null) |
if (backing_buffer == null) |
216 |
throw new UnsupportedOperationException (); |
throw new UnsupportedOperationException (); |
230 |
* @exception UnsupportedOperationException If this buffer is not backed |
* @exception UnsupportedOperationException If this buffer is not backed |
231 |
* by an accessible array. |
* by an accessible array. |
232 |
*/ |
*/ |
233 |
public final int arrayOffset() |
public final int arrayOffset () |
234 |
{ |
{ |
235 |
if (backing_buffer == null) |
if (backing_buffer == null) |
236 |
throw new UnsupportedOperationException (); |
throw new UnsupportedOperationException (); |
238 |
if (isReadOnly ()) |
if (isReadOnly ()) |
239 |
throw new ReadOnlyBufferException (); |
throw new ReadOnlyBufferException (); |
240 |
|
|
241 |
// FIXME: Return correct value |
return offset; |
|
return 0; |
|
242 |
} |
} |
243 |
|
|
244 |
/** |
/** |
606 |
*/ |
*/ |
607 |
public String toString () |
public String toString () |
608 |
{ |
{ |
609 |
return ""; |
return getClass ().getName () + |
610 |
|
"[pos=" + position () + |
611 |
|
" lim=" + limit () + |
612 |
|
" cap=" + capacity () + "]"; |
613 |
} |
} |
614 |
} |
} |