47 |
{ |
{ |
48 |
private ByteOrder endian = ByteOrder.BIG_ENDIAN; |
private ByteOrder endian = ByteOrder.BIG_ENDIAN; |
49 |
|
|
50 |
protected int offset; |
protected int array_offset; |
51 |
protected byte[] backing_buffer; |
protected byte[] backing_buffer; |
52 |
|
|
53 |
protected ByteBuffer (int capacity, int limit, int position, int mark) |
protected ByteBuffer (int capacity, int limit, int position, int mark) |
54 |
{ |
{ |
55 |
super (capacity, limit, position, mark); |
super (capacity, limit, position, mark); |
56 |
|
array_offset = 0; |
57 |
|
} |
58 |
|
|
59 |
|
protected ByteBuffer (byte[] buffer, int offset, int capacity, int limit, int position, int mark) |
60 |
|
{ |
61 |
|
super (capacity, limit, position, mark); |
62 |
|
this.backing_buffer = buffer; |
63 |
|
this.array_offset = offset; |
64 |
} |
} |
65 |
|
|
66 |
/** |
/** |
76 |
*/ |
*/ |
77 |
public static ByteBuffer allocate (int capacity) |
public static ByteBuffer allocate (int capacity) |
78 |
{ |
{ |
79 |
return new ByteBufferImpl (capacity, 0, capacity); |
return new ByteBufferImpl (capacity); |
80 |
} |
} |
81 |
|
|
82 |
/** |
/** |
88 |
*/ |
*/ |
89 |
final public static ByteBuffer wrap (byte[] array, int offset, int length) |
final public static ByteBuffer wrap (byte[] array, int offset, int length) |
90 |
{ |
{ |
91 |
return new ByteBufferImpl (array, offset, length); |
return new ByteBufferImpl (array, 0, array.length, offset + length, offset, -1, false); |
92 |
} |
} |
93 |
|
|
94 |
/** |
/** |
99 |
{ |
{ |
100 |
return wrap (array, 0, array.length); |
return wrap (array, 0, array.length); |
101 |
} |
} |
102 |
|
|
103 |
/** |
/** |
104 |
* This method transfers <code>bytes<code> from this buffer into the given |
* This method transfers <code>bytes<code> from this buffer into the given |
105 |
* destination array. |
* destination array. |
161 |
if (src == this) |
if (src == this) |
162 |
throw new IllegalArgumentException (); |
throw new IllegalArgumentException (); |
163 |
|
|
164 |
while (src.hasRemaining ()) |
if (src.remaining () > remaining ()) |
165 |
put (src.get ()); |
throw new BufferOverflowException (); |
166 |
|
|
167 |
|
if (src.remaining () > 0) |
168 |
|
{ |
169 |
|
byte[] toPut = new byte [src.remaining ()]; |
170 |
|
src.get (toPut); |
171 |
|
src.put (toPut); |
172 |
|
} |
173 |
|
|
174 |
return this; |
return this; |
175 |
} |
} |
176 |
|
|
261 |
|
|
262 |
if (isReadOnly ()) |
if (isReadOnly ()) |
263 |
throw new ReadOnlyBufferException (); |
throw new ReadOnlyBufferException (); |
264 |
|
|
265 |
return offset; |
return array_offset; |
266 |
} |
} |
267 |
|
|
268 |
/** |
/** |
298 |
{ |
{ |
299 |
ByteBuffer a = (ByteBuffer) obj; |
ByteBuffer a = (ByteBuffer) obj; |
300 |
|
|
301 |
if (a.remaining() != remaining()) |
if (a.remaining () != remaining ()) |
302 |
{ |
return 1; |
303 |
return 1; |
|
304 |
} |
if (! hasArray () || |
305 |
|
! a.hasArray ()) |
|
if (! hasArray() || |
|
|
! a.hasArray()) |
|
306 |
{ |
{ |
307 |
return 1; |
return 1; |
308 |
} |
} |
603 |
* @exception BufferUnderflowException If there are fewer than eight bytes |
* @exception BufferUnderflowException If there are fewer than eight bytes |
604 |
* remaining in this buffer. |
* remaining in this buffer. |
605 |
*/ |
*/ |
606 |
public abstract double getDouble(); |
public abstract double getDouble (); |
607 |
|
|
608 |
/** |
/** |
609 |
* Relative put method for writing a double value. |
* Relative put method for writing a double value. |