42 |
|
|
43 |
abstract class DirectByteBufferImpl extends ByteBuffer |
abstract class DirectByteBufferImpl extends ByteBuffer |
44 |
{ |
{ |
45 |
/** The owner is used to keep alive the object that actually owns the |
/** |
46 |
* memory. There are three possibilities: |
* The owner is used to keep alive the object that actually owns the |
47 |
* 1) owner == this: We allocated the memory and we should free it, |
* memory. There are three possibilities: |
48 |
* but *only* in finalize (if we've been sliced |
* 1) owner == this: We allocated the memory and we should free it, |
49 |
* other objects will also have access to the |
* but *only* in finalize (if we've been sliced |
50 |
* memory). |
* other objects will also have access to the |
51 |
* 2) owner == null: The byte buffer was created thru |
* memory). |
52 |
* JNI.NewDirectByteBuffer. The JNI code is |
* 2) owner == null: The byte buffer was created thru |
53 |
* responsible for freeing the memory. |
* JNI.NewDirectByteBuffer. The JNI code is |
54 |
* 3) owner == some other object: The other object allocated the |
* responsible for freeing the memory. |
55 |
* memory and should free it. |
* 3) owner == some other object: The other object allocated the |
56 |
*/ |
* memory and should free it. |
57 |
|
*/ |
58 |
private final Object owner; |
private final Object owner; |
|
final RawData address; |
|
59 |
|
|
60 |
final static class ReadOnly extends DirectByteBufferImpl |
static final class ReadOnly extends DirectByteBufferImpl |
61 |
{ |
{ |
62 |
ReadOnly(Object owner, RawData address, |
ReadOnly(Object owner, RawData address, |
63 |
int capacity, int limit, |
int capacity, int limit, |
82 |
} |
} |
83 |
} |
} |
84 |
|
|
85 |
final static class ReadWrite extends DirectByteBufferImpl |
static final class ReadWrite extends DirectByteBufferImpl |
86 |
{ |
{ |
87 |
ReadWrite(int capacity) |
ReadWrite(int capacity) |
88 |
{ |
{ |
186 |
|
|
187 |
public ByteBuffer compact() |
public ByteBuffer compact() |
188 |
{ |
{ |
189 |
|
checkIfReadOnly(); |
190 |
|
mark = -1; |
191 |
int pos = position(); |
int pos = position(); |
192 |
if (pos > 0) |
if (pos > 0) |
193 |
{ |
{ |
196 |
position(count); |
position(count); |
197 |
limit(capacity()); |
limit(capacity()); |
198 |
} |
} |
199 |
|
else |
200 |
|
{ |
201 |
|
position(limit()); |
202 |
|
limit(capacity()); |
203 |
|
} |
204 |
return this; |
return this; |
205 |
} |
} |
206 |
|
|