54 |
* Win32 uses it for the pointer returned by CreateFileMapping. */ |
* Win32 uses it for the pointer returned by CreateFileMapping. */ |
55 |
public long implLen; |
public long implLen; |
56 |
|
|
57 |
public MappedByteBufferImpl (RawData address, int size, boolean readOnly) |
public MappedByteBufferImpl(RawData address, int size, boolean readOnly) |
58 |
throws IOException |
throws IOException |
59 |
{ |
{ |
60 |
super(size, size, 0, -1); |
super(size, size, 0, -1); |
62 |
this.readOnly = readOnly; |
this.readOnly = readOnly; |
63 |
} |
} |
64 |
|
|
65 |
public boolean isReadOnly () |
public boolean isReadOnly() |
66 |
{ |
{ |
67 |
return readOnly; |
return readOnly; |
68 |
} |
} |
69 |
|
|
70 |
public byte get () |
public byte get() |
71 |
{ |
{ |
72 |
checkForUnderflow(); |
checkForUnderflow(); |
73 |
|
|
74 |
int pos = position(); |
int pos = position(); |
75 |
byte result = DirectByteBufferImpl.getImpl(address, pos); |
byte result = VMDirectByteBuffer.get(address, pos); |
76 |
position (pos + 1); |
position(pos + 1); |
77 |
return result; |
return result; |
78 |
} |
} |
79 |
|
|
80 |
public ByteBuffer put (byte value) |
public ByteBuffer put(byte value) |
81 |
{ |
{ |
82 |
checkIfReadOnly(); |
checkIfReadOnly(); |
83 |
checkForOverflow(); |
checkForOverflow(); |
84 |
|
|
85 |
int pos = position(); |
int pos = position(); |
86 |
DirectByteBufferImpl.putImpl(address, pos, value); |
VMDirectByteBuffer.put(address, pos, value); |
87 |
position(pos + 1); |
position(pos + 1); |
88 |
return this; |
return this; |
89 |
} |
} |
90 |
|
|
91 |
public byte get (int index) |
public byte get(int index) |
92 |
{ |
{ |
93 |
checkIndex(index); |
checkIndex(index); |
94 |
|
|
95 |
return DirectByteBufferImpl.getImpl(address, index); |
return VMDirectByteBuffer.get(address, index); |
96 |
} |
} |
97 |
|
|
98 |
public ByteBuffer get (byte[] dst, int offset, int length) |
public ByteBuffer get(byte[] dst, int offset, int length) |
99 |
{ |
{ |
100 |
checkArraySize(dst.length, offset, length); |
checkArraySize(dst.length, offset, length); |
101 |
checkForUnderflow(length); |
checkForUnderflow(length); |
102 |
|
|
103 |
int index = position(); |
int index = position(); |
104 |
DirectByteBufferImpl.getImpl(address, index, dst, offset, length); |
VMDirectByteBuffer.get(address, index, dst, offset, length); |
105 |
position(index+length); |
position(index+length); |
106 |
|
|
107 |
return this; |
return this; |
108 |
} |
} |
109 |
|
|
110 |
public ByteBuffer put (int index, byte value) |
public ByteBuffer put(int index, byte value) |
111 |
{ |
{ |
112 |
checkIfReadOnly(); |
checkIfReadOnly(); |
113 |
checkIndex(index); |
checkIndex(index); |
114 |
|
|
115 |
DirectByteBufferImpl.putImpl(address, index, value); |
VMDirectByteBuffer.put(address, index, value); |
116 |
return this; |
return this; |
117 |
} |
} |
118 |
|
|
119 |
public ByteBuffer compact () |
public ByteBuffer compact() |
120 |
{ |
{ |
121 |
int pos = position(); |
int pos = position(); |
122 |
if (pos > 0) |
if (pos > 0) |
123 |
{ |
{ |
124 |
int count = remaining(); |
int count = remaining(); |
125 |
// Call shiftDown method optimized for direct buffers. |
// Call shiftDown method optimized for direct buffers. |
126 |
DirectByteBufferImpl.shiftDown(address, 0, pos, count); |
VMDirectByteBuffer.shiftDown(address, 0, pos, count); |
127 |
position(count); |
position(count); |
128 |
limit(capacity()); |
limit(capacity()); |
129 |
} |
} |
130 |
return this; |
return this; |
131 |
} |
} |
132 |
|
|
133 |
public boolean isDirect () |
public boolean isDirect() |
134 |
{ |
{ |
135 |
return true; |
return true; |
136 |
} |
} |
137 |
|
|
138 |
public ByteBuffer slice () |
public ByteBuffer slice() |
139 |
{ |
{ |
140 |
int rem = remaining(); |
int rem = remaining(); |
141 |
return new DirectByteBufferImpl (this, |
return new DirectByteBufferImpl |
142 |
DirectByteBufferImpl |
(this, VMDirectByteBuffer.adjustAddress(address, position()), |
143 |
.adjustAddress(address, position()), |
rem, rem, 0, isReadOnly()); |
|
rem, rem, 0, isReadOnly ()); |
|
144 |
} |
} |
145 |
|
|
146 |
private ByteBuffer duplicate (boolean readOnly) |
private ByteBuffer duplicate(boolean readOnly) |
147 |
{ |
{ |
148 |
int pos = position(); |
int pos = position(); |
149 |
reset(); |
reset(); |
150 |
int mark = position(); |
int mark = position(); |
151 |
position(pos); |
position(pos); |
152 |
DirectByteBufferImpl result |
DirectByteBufferImpl result |
153 |
= new DirectByteBufferImpl (this, address, capacity (), limit (), |
= new DirectByteBufferImpl(this, address, capacity(), limit(), |
154 |
pos, readOnly); |
pos, readOnly); |
155 |
if (mark != pos) |
if (mark != pos) |
156 |
{ |
{ |
157 |
result.position(mark); |
result.position(mark); |
161 |
return result; |
return result; |
162 |
} |
} |
163 |
|
|
164 |
public ByteBuffer duplicate () |
public ByteBuffer duplicate() |
165 |
{ |
{ |
166 |
return duplicate(isReadOnly()); |
return duplicate(isReadOnly()); |
167 |
} |
} |
168 |
|
|
169 |
public ByteBuffer asReadOnlyBuffer () |
public ByteBuffer asReadOnlyBuffer() |
170 |
{ |
{ |
171 |
return duplicate(true); |
return duplicate(true); |
172 |
} |
} |
173 |
|
|
174 |
public CharBuffer asCharBuffer () |
public CharBuffer asCharBuffer() |
175 |
{ |
{ |
176 |
return new CharViewBufferImpl (this, remaining() >> 1); |
return new CharViewBufferImpl(this, remaining() >> 1); |
177 |
} |
} |
178 |
|
|
179 |
public ShortBuffer asShortBuffer () |
public ShortBuffer asShortBuffer() |
180 |
{ |
{ |
181 |
return new ShortViewBufferImpl (this, remaining() >> 1); |
return new ShortViewBufferImpl(this, remaining() >> 1); |
182 |
} |
} |
183 |
|
|
184 |
public IntBuffer asIntBuffer () |
public IntBuffer asIntBuffer() |
185 |
{ |
{ |
186 |
return new IntViewBufferImpl (this, remaining() >> 2); |
return new IntViewBufferImpl(this, remaining() >> 2); |
187 |
} |
} |
188 |
|
|
189 |
public LongBuffer asLongBuffer () |
public LongBuffer asLongBuffer() |
190 |
{ |
{ |
191 |
return new LongViewBufferImpl (this, remaining() >> 3); |
return new LongViewBufferImpl(this, remaining() >> 3); |
192 |
} |
} |
193 |
|
|
194 |
public FloatBuffer asFloatBuffer () |
public FloatBuffer asFloatBuffer() |
195 |
{ |
{ |
196 |
return new FloatViewBufferImpl (this, remaining() >> 2); |
return new FloatViewBufferImpl(this, remaining() >> 2); |
197 |
} |
} |
198 |
|
|
199 |
public DoubleBuffer asDoubleBuffer () |
public DoubleBuffer asDoubleBuffer() |
200 |
{ |
{ |
201 |
return new DoubleViewBufferImpl (this, remaining() >> 3); |
return new DoubleViewBufferImpl(this, remaining() >> 3); |
202 |
} |
} |
203 |
|
|
204 |
public char getChar () |
public char getChar() |
205 |
{ |
{ |
206 |
return ByteBufferHelper.getChar(this, order()); |
return ByteBufferHelper.getChar(this, order()); |
207 |
} |
} |
208 |
|
|
209 |
public ByteBuffer putChar (char value) |
public ByteBuffer putChar(char value) |
210 |
{ |
{ |
211 |
ByteBufferHelper.putChar(this, value, order()); |
ByteBufferHelper.putChar(this, value, order()); |
212 |
return this; |
return this; |
213 |
} |
} |
214 |
|
|
215 |
public char getChar (int index) |
public char getChar(int index) |
216 |
{ |
{ |
217 |
return ByteBufferHelper.getChar(this, index, order()); |
return ByteBufferHelper.getChar(this, index, order()); |
218 |
} |
} |
219 |
|
|
220 |
public ByteBuffer putChar (int index, char value) |
public ByteBuffer putChar(int index, char value) |
221 |
{ |
{ |
222 |
ByteBufferHelper.putChar(this, index, value, order()); |
ByteBufferHelper.putChar(this, index, value, order()); |
223 |
return this; |
return this; |
224 |
} |
} |
225 |
|
|
226 |
public short getShort () |
public short getShort() |
227 |
{ |
{ |
228 |
return ByteBufferHelper.getShort(this, order()); |
return ByteBufferHelper.getShort(this, order()); |
229 |
} |
} |
230 |
|
|
231 |
public ByteBuffer putShort (short value) |
public ByteBuffer putShort(short value) |
232 |
{ |
{ |
233 |
ByteBufferHelper.putShort(this, value, order()); |
ByteBufferHelper.putShort(this, value, order()); |
234 |
return this; |
return this; |
235 |
} |
} |
236 |
|
|
237 |
public short getShort (int index) |
public short getShort(int index) |
238 |
{ |
{ |
239 |
return ByteBufferHelper.getShort(this, index, order()); |
return ByteBufferHelper.getShort(this, index, order()); |
240 |
} |
} |
241 |
|
|
242 |
public ByteBuffer putShort (int index, short value) |
public ByteBuffer putShort(int index, short value) |
243 |
{ |
{ |
244 |
ByteBufferHelper.putShort(this, index, value, order()); |
ByteBufferHelper.putShort(this, index, value, order()); |
245 |
return this; |
return this; |
246 |
} |
} |
247 |
|
|
248 |
public int getInt () |
public int getInt() |
249 |
{ |
{ |
250 |
return ByteBufferHelper.getInt(this, order()); |
return ByteBufferHelper.getInt(this, order()); |
251 |
} |
} |
252 |
|
|
253 |
public ByteBuffer putInt (int value) |
public ByteBuffer putInt(int value) |
254 |
{ |
{ |
255 |
ByteBufferHelper.putInt(this, value, order()); |
ByteBufferHelper.putInt(this, value, order()); |
256 |
return this; |
return this; |
257 |
} |
} |
258 |
|
|
259 |
public int getInt (int index) |
public int getInt(int index) |
260 |
{ |
{ |
261 |
return ByteBufferHelper.getInt(this, index, order()); |
return ByteBufferHelper.getInt(this, index, order()); |
262 |
} |
} |
263 |
|
|
264 |
public ByteBuffer putInt (int index, int value) |
public ByteBuffer putInt(int index, int value) |
265 |
{ |
{ |
266 |
ByteBufferHelper.putInt(this, index, value, order()); |
ByteBufferHelper.putInt(this, index, value, order()); |
267 |
return this; |
return this; |
268 |
} |
} |
269 |
|
|
270 |
public long getLong () |
public long getLong() |
271 |
{ |
{ |
272 |
return ByteBufferHelper.getLong(this, order()); |
return ByteBufferHelper.getLong(this, order()); |
273 |
} |
} |
274 |
|
|
275 |
public ByteBuffer putLong (long value) |
public ByteBuffer putLong(long value) |
276 |
{ |
{ |
277 |
ByteBufferHelper.putLong (this, value, order()); |
ByteBufferHelper.putLong(this, value, order()); |
278 |
return this; |
return this; |
279 |
} |
} |
280 |
|
|
281 |
public long getLong (int index) |
public long getLong(int index) |
282 |
{ |
{ |
283 |
return ByteBufferHelper.getLong (this, index, order()); |
return ByteBufferHelper.getLong(this, index, order()); |
284 |
} |
} |
285 |
|
|
286 |
public ByteBuffer putLong (int index, long value) |
public ByteBuffer putLong(int index, long value) |
287 |
{ |
{ |
288 |
ByteBufferHelper.putLong (this, index, value, order()); |
ByteBufferHelper.putLong(this, index, value, order()); |
289 |
return this; |
return this; |
290 |
} |
} |
291 |
|
|
292 |
public float getFloat () |
public float getFloat() |
293 |
{ |
{ |
294 |
return ByteBufferHelper.getFloat (this, order()); |
return ByteBufferHelper.getFloat(this, order()); |
295 |
} |
} |
296 |
|
|
297 |
public ByteBuffer putFloat (float value) |
public ByteBuffer putFloat(float value) |
298 |
{ |
{ |
299 |
ByteBufferHelper.putFloat (this, value, order()); |
ByteBufferHelper.putFloat(this, value, order()); |
300 |
return this; |
return this; |
301 |
} |
} |
302 |
|
|
303 |
public float getFloat (int index) |
public float getFloat(int index) |
304 |
{ |
{ |
305 |
return ByteBufferHelper.getFloat (this, index, order()); |
return ByteBufferHelper.getFloat(this, index, order()); |
306 |
} |
} |
307 |
|
|
308 |
public ByteBuffer putFloat (int index, float value) |
public ByteBuffer putFloat(int index, float value) |
309 |
{ |
{ |
310 |
ByteBufferHelper.putFloat (this, index, value, order()); |
ByteBufferHelper.putFloat(this, index, value, order()); |
311 |
return this; |
return this; |
312 |
} |
} |
313 |
|
|
314 |
public double getDouble () |
public double getDouble() |
315 |
{ |
{ |
316 |
return ByteBufferHelper.getDouble (this, order()); |
return ByteBufferHelper.getDouble(this, order()); |
317 |
} |
} |
318 |
|
|
319 |
public ByteBuffer putDouble (double value) |
public ByteBuffer putDouble(double value) |
320 |
{ |
{ |
321 |
ByteBufferHelper.putDouble (this, value, order()); |
ByteBufferHelper.putDouble(this, value, order()); |
322 |
return this; |
return this; |
323 |
} |
} |
324 |
|
|
325 |
public double getDouble (int index) |
public double getDouble(int index) |
326 |
{ |
{ |
327 |
return ByteBufferHelper.getDouble (this, index, order()); |
return ByteBufferHelper.getDouble(this, index, order()); |
328 |
} |
} |
329 |
|
|
330 |
public ByteBuffer putDouble (int index, double value) |
public ByteBuffer putDouble(int index, double value) |
331 |
{ |
{ |
332 |
ByteBufferHelper.putDouble (this, index, value, order()); |
ByteBufferHelper.putDouble(this, index, value, order()); |
333 |
return this; |
return this; |
334 |
} |
} |
335 |
|
|
336 |
// NOTE: In libgcj these methods are implemented in natFileChannelXxx.cc, |
// NOTE: In libgcj these methods are implemented in natFileChannelXxx.cc, |
337 |
// because they're small, and to put them next to FileChannelImpl::mapImpl. |
// because they're small, and to put them next to FileChannelImpl::mapImpl. |
338 |
native void unmapImpl (); |
native void unmapImpl(); |
339 |
native boolean isLoadedImpl (); |
native boolean isLoadedImpl(); |
340 |
// FIXME: Try to load all pages into memory. |
// FIXME: Try to load all pages into memory. |
341 |
native void loadImpl(); |
native void loadImpl(); |
342 |
|
|