OpenCores
URL https://opencores.org/ocsvn/scarts/scarts/trunk

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gcc/] [gcc-4.1.1/] [libjava/] [classpath/] [java/] [nio/] [ByteBufferImpl.java] - Blame information for rev 14

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 14 jlechner
/* ByteBufferImpl.java --
2
   Copyright (C) 2002, 2003, 2004, 2005  Free Software Foundation, Inc.
3
 
4
This file is part of GNU Classpath.
5
 
6
GNU Classpath is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2, or (at your option)
9
any later version.
10
 
11
GNU Classpath is distributed in the hope that it will be useful, but
12
WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
General Public License for more details.
15
 
16
You should have received a copy of the GNU General Public License
17
along with GNU Classpath; see the file COPYING.  If not, write to the
18
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19
02110-1301 USA.
20
 
21
Linking this library statically or dynamically with other modules is
22
making a combined work based on this library.  Thus, the terms and
23
conditions of the GNU General Public License cover the whole
24
combination.
25
 
26
As a special exception, the copyright holders of this library give you
27
permission to link this library with independent modules to produce an
28
executable, regardless of the license terms of these independent
29
modules, and to copy and distribute the resulting executable under
30
terms of your choice, provided that you also meet, for each linked
31
independent module, the terms and conditions of the license of that
32
module.  An independent module is a module which is not derived from
33
or based on this library.  If you modify this library, you may extend
34
this exception to your version of the library, but you are not
35
obligated to do so.  If you do not wish to do so, delete this
36
exception statement from your version. */
37
 
38
 
39
package java.nio;
40
 
41
/**
42
 * This is a Heap memory implementation
43
 */
44
final class ByteBufferImpl extends ByteBuffer
45
{
46
  private boolean readOnly;
47
 
48
  ByteBufferImpl (byte[] buffer, int offset, int capacity, int limit, int position, int mark, boolean readOnly)
49
  {
50
    super (capacity, limit, position, mark);
51
    this.backing_buffer = buffer;
52
    this.array_offset = offset;
53
    this.readOnly = readOnly;
54
  }
55
 
56
  public CharBuffer asCharBuffer ()
57
  {
58
    return new CharViewBufferImpl (this, remaining() >> 1);
59
  }
60
 
61
  public ShortBuffer asShortBuffer ()
62
  {
63
    return new ShortViewBufferImpl (this, remaining() >> 1);
64
  }
65
 
66
  public IntBuffer asIntBuffer ()
67
  {
68
    return new IntViewBufferImpl (this, remaining() >> 2);
69
  }
70
 
71
  public LongBuffer asLongBuffer ()
72
  {
73
    return new LongViewBufferImpl (this, remaining() >> 3);
74
  }
75
 
76
  public FloatBuffer asFloatBuffer ()
77
  {
78
    return new FloatViewBufferImpl (this, remaining() >> 2);
79
  }
80
 
81
  public DoubleBuffer asDoubleBuffer ()
82
  {
83
    return new DoubleViewBufferImpl (this, remaining() >> 3);
84
  }
85
 
86
  public boolean isReadOnly ()
87
  {
88
    return readOnly;
89
  }
90
 
91
  public ByteBuffer slice ()
92
  {
93
    return new ByteBufferImpl (backing_buffer, array_offset + position (), remaining (), remaining (), 0, -1, isReadOnly ());
94
  }
95
 
96
  public ByteBuffer duplicate ()
97
  {
98
    return new ByteBufferImpl (backing_buffer, array_offset, capacity (), limit (), position (), mark, isReadOnly ());
99
  }
100
 
101
  public ByteBuffer asReadOnlyBuffer ()
102
  {
103
    return new ByteBufferImpl (backing_buffer, array_offset, capacity (), limit (), position (), mark, true);
104
  }
105
 
106
  void shiftDown (int dst_offset, int src_offset, int count)
107
  {
108
    System.arraycopy(backing_buffer, array_offset + src_offset,
109
                     backing_buffer, array_offset + dst_offset,
110
                     count);
111
  }
112
 
113
  public ByteBuffer compact ()
114
  {
115
    checkIfReadOnly();
116
    mark = -1;
117
    int pos = position();
118
    if (pos > 0)
119
      {
120
        int count = remaining();
121
        shiftDown(0, pos, count);
122
        position(count);
123
        limit(capacity());
124
      }
125
    else
126
      {
127
        position(limit());
128
        limit(capacity());
129
      }
130
    return this;
131
  }
132
 
133
  public boolean isDirect ()
134
  {
135
    return false;
136
  }
137
 
138
  /**
139
   * Reads the <code>byte</code> at this buffer's current position,
140
   * and then increments the position.
141
   *
142
   * @exception BufferUnderflowException If there are no remaining
143
   * <code>bytes</code> in this buffer.
144
   */
145
  public byte get ()
146
  {
147
    if (pos >= limit)
148
        throw new BufferUnderflowException();
149
 
150
    return backing_buffer [(pos++) + array_offset];
151
  }
152
 
153
  /**
154
   * Bulk get
155
   */
156
  public ByteBuffer get (byte[] dst, int offset, int length)
157
  {
158
    checkArraySize(dst.length, offset, length);
159
    if ( (limit - pos) < length) // check for overflow
160
      throw new BufferUnderflowException();
161
 
162
    System.arraycopy(backing_buffer, pos + array_offset,
163
                     dst, offset, length);
164
    pos += length;
165
 
166
    return this;
167
  }
168
 
169
  /**
170
   * Relative bulk put(), overloads the ByteBuffer impl.
171
   */
172
  public ByteBuffer put (byte[] src, int offset, int length)
173
  {
174
    if ( (limit - pos) < length) // check for overflow
175
      throw new BufferOverflowException();
176
    checkArraySize(src.length, offset, length);
177
 
178
    System.arraycopy(src, offset, backing_buffer, pos + array_offset, length);
179
    pos += length;
180
 
181
    return this;
182
  }
183
 
184
  /**
185
   * Relative put method. Writes <code>value</code> to the next position
186
   * in the buffer.
187
   *
188
   * @exception BufferOverflowException If there is no remaining
189
   * space in this buffer.
190
   * @exception ReadOnlyBufferException If this buffer is read-only.
191
   */
192
  public ByteBuffer put (byte value)
193
  {
194
    if (readOnly)
195
        throw new ReadOnlyBufferException();
196
    if (pos >= limit)
197
        throw new BufferOverflowException();
198
 
199
    backing_buffer [(pos++) + array_offset] = value;
200
    return this;
201
  }
202
 
203
  /**
204
   * Absolute get method. Reads the <code>byte</code> at position
205
   * <code>index</code>.
206
   *
207
   * @exception IndexOutOfBoundsException If index is negative or not smaller
208
   * than the buffer's limit.
209
   */
210
  public byte get (int index)
211
  {
212
    checkIndex(index);
213
 
214
    return backing_buffer [index + array_offset];
215
  }
216
 
217
  /**
218
   * Absolute put method. Writes <code>value</code> to position
219
   * <code>index</code> in the buffer.
220
   *
221
   * @exception IndexOutOfBoundsException If index is negative or not smaller
222
   * than the buffer's limit.
223
   * @exception ReadOnlyBufferException If this buffer is read-only.
224
   */
225
  public ByteBuffer put (int index, byte value)
226
  {
227
    checkIfReadOnly();
228
    checkIndex(index);
229
 
230
    backing_buffer [index + array_offset] = value;
231
    return this;
232
  }
233
 
234
  public char getChar ()
235
  {
236
    return ByteBufferHelper.getChar(this, order());
237
  }
238
 
239
  public ByteBuffer putChar (char value)
240
  {
241
    if (readOnly)
242
      throw new ReadOnlyBufferException ();
243
    if ( (limit-pos) < 2)
244
      throw new BufferOverflowException();
245
 
246
    if (endian == ByteOrder.LITTLE_ENDIAN)
247
      {
248
        backing_buffer [(pos++) + array_offset] = (byte)(value&0xFF);
249
        backing_buffer [(pos++) + array_offset] = (byte)(value>>8);
250
      }
251
    else
252
      {
253
        backing_buffer [(pos++) + array_offset] = (byte)(value>>8);
254
        backing_buffer [(pos++) + array_offset] = (byte)(value&0xFF);
255
      }
256
    return this;
257
  }
258
 
259
  public char getChar (int index)
260
  {
261
    return ByteBufferHelper.getChar(this, index, order());
262
  }
263
 
264
  public ByteBuffer putChar (int index, char value)
265
  {
266
    ByteBufferHelper.putChar(this, index, value, order());
267
    return this;
268
  }
269
 
270
  public short getShort ()
271
  {
272
    return ByteBufferHelper.getShort(this, order());
273
  }
274
 
275
  public ByteBuffer putShort (short value)
276
  {
277
    ByteBufferHelper.putShort(this, value, order());
278
    return this;
279
  }
280
 
281
  public short getShort (int index)
282
  {
283
    return ByteBufferHelper.getShort(this, index, order());
284
  }
285
 
286
  public ByteBuffer putShort (int index, short value)
287
  {
288
    ByteBufferHelper.putShort(this, index, value, order());
289
    return this;
290
  }
291
 
292
  public int getInt ()
293
  {
294
    return ByteBufferHelper.getInt(this, order());
295
  }
296
 
297
  public ByteBuffer putInt (int value)
298
  {
299
    ByteBufferHelper.putInt(this, value, order());
300
    return this;
301
  }
302
 
303
  public int getInt (int index)
304
  {
305
    return ByteBufferHelper.getInt(this, index, order());
306
  }
307
 
308
  public ByteBuffer putInt (int index, int value)
309
  {
310
    ByteBufferHelper.putInt(this, index, value, order());
311
    return this;
312
  }
313
 
314
  public long getLong ()
315
  {
316
    return ByteBufferHelper.getLong(this, order());
317
  }
318
 
319
  public ByteBuffer putLong (long value)
320
  {
321
    ByteBufferHelper.putLong (this, value, order());
322
    return this;
323
  }
324
 
325
  public long getLong (int index)
326
  {
327
    return ByteBufferHelper.getLong (this, index, order());
328
  }
329
 
330
  public ByteBuffer putLong (int index, long value)
331
  {
332
    ByteBufferHelper.putLong (this, index, value, order());
333
    return this;
334
  }
335
 
336
  public float getFloat ()
337
  {
338
    return ByteBufferHelper.getFloat (this, order());
339
  }
340
 
341
  public ByteBuffer putFloat (float value)
342
  {
343
    ByteBufferHelper.putFloat (this, value, order());
344
    return this;
345
  }
346
 
347
  public float getFloat (int index)
348
  {
349
    return ByteBufferHelper.getFloat (this, index, order());
350
  }
351
 
352
  public ByteBuffer putFloat (int index, float value)
353
  {
354
    ByteBufferHelper.putFloat (this, index, value, order());
355
    return this;
356
  }
357
 
358
  public double getDouble ()
359
  {
360
    return ByteBufferHelper.getDouble (this, order());
361
  }
362
 
363
  public ByteBuffer putDouble (double value)
364
  {
365
    ByteBufferHelper.putDouble (this, value, order());
366
    return this;
367
  }
368
 
369
  public double getDouble (int index)
370
  {
371
    return ByteBufferHelper.getDouble (this, index, order());
372
  }
373
 
374
  public ByteBuffer putDouble (int index, double value)
375
  {
376
    ByteBufferHelper.putDouble (this, index, value, order());
377
    return this;
378
  }
379
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.