diff options
Diffstat (limited to 'libjava/gnu/java/nio/LongBufferImpl.java')
| -rw-r--r-- | libjava/gnu/java/nio/LongBufferImpl.java | 126 |
1 files changed, 74 insertions, 52 deletions
diff --git a/libjava/gnu/java/nio/LongBufferImpl.java b/libjava/gnu/java/nio/LongBufferImpl.java index 8a295fa5a35..e37ac8e4b2c 100644 --- a/libjava/gnu/java/nio/LongBufferImpl.java +++ b/libjava/gnu/java/nio/LongBufferImpl.java @@ -1,5 +1,5 @@ /* LongBufferImpl.java -- - Copyright (C) 2002 Free Software Foundation, Inc. + Copyright (C) 2002, 2003 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -35,6 +35,7 @@ this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ + package gnu.java.nio; import java.nio.ByteBuffer; @@ -49,92 +50,113 @@ public final class LongBufferImpl extends LongBuffer { private boolean readOnly; - public LongBufferImpl(int cap, int off, int lim) - { - super (cap, lim, off, 0); - this.backing_buffer = new long[cap]; - readOnly = false; - } - - public LongBufferImpl(long[] array, int offset, int length) + LongBufferImpl (int capacity) { - super (array.length, length, offset, 0); - this.backing_buffer = array; - readOnly = false; + this (new long [capacity], 0, capacity, capacity, 0, -1, false); } - - public LongBufferImpl(LongBufferImpl copy) + + LongBufferImpl (long[] buffer, int offset, int capacity, int limit, int position, int mark, boolean readOnly) { - super (copy.capacity (), copy.limit (), copy.position (), 0); - backing_buffer = copy.backing_buffer; - readOnly = copy.isReadOnly (); + super (buffer, offset, capacity, limit, position, mark); + this.readOnly = readOnly; } - - public boolean isReadOnly() + + public boolean isReadOnly () { return readOnly; } - - public LongBuffer slice() + + public LongBuffer slice () { - return new LongBufferImpl (this); + return new LongBufferImpl (backing_buffer, array_offset + position (), remaining (), remaining (), 0, -1, isReadOnly ()); } - - public LongBuffer duplicate() + + public LongBuffer duplicate () { - return new LongBufferImpl(this); + return new LongBufferImpl (backing_buffer, array_offset, capacity (), limit (), position (), mark, isReadOnly ()); } - - public LongBuffer asReadOnlyBuffer() + + public LongBuffer asReadOnlyBuffer () { - LongBufferImpl result = new LongBufferImpl (this); - result.readOnly = true; - return result; + return new LongBufferImpl (backing_buffer, array_offset, capacity (), limit (), position (), mark, true); } - - public LongBuffer compact() + + public LongBuffer compact () { + int copied = 0; + + while (remaining () > 0) + { + put (copied, get ()); + copied++; + } + + position (copied); return this; } - - public boolean isDirect() + + public boolean isDirect () { return false; } - final public long get() + /** + * Relative get method. Reads the next <code>long</code> from the buffer. + */ + final public long get () { - long e = backing_buffer[position()]; - position(position()+1); - return e; + long result = backing_buffer [position ()]; + position (position () + 1); + return result; } - - final public LongBuffer put(long b) + + /** + * Relative put method. Writes <code>value</code> to the next position + * in the buffer. + * + * @exception ReadOnlyBufferException If this buffer is read-only. + */ + final public LongBuffer put (long value) { if (readOnly) throw new ReadOnlyBufferException (); - - backing_buffer[position()] = b; - position(position()+1); + + backing_buffer [position ()] = value; + position (position () + 1); return this; } - - final public long get(int index) + + /** + * Absolute get method. Reads the <code>long</code> at position + * <code>index</code>. + * + * @exception IndexOutOfBoundsException If index is negative or not smaller + * than the buffer's limit. + */ + final public long get (int index) { - return backing_buffer[index]; + return backing_buffer [index]; } - - final public LongBuffer put(int index, long b) + + /** + * Absolute put method. Writes <code>value</value> to position + * <code>index</code> in the buffer. + * + * @exception IndexOutOfBoundsException If index is negative or not smaller + * than the buffer's limit. + * @exception ReadOnlyBufferException If this buffer is read-only. + */ + final public LongBuffer put (int index, long value) { if (readOnly) throw new ReadOnlyBufferException (); - - backing_buffer[index] = b; + + backing_buffer [index] = value; return this; } - + final public ByteOrder order () { - return ByteOrder.BIG_ENDIAN; + return ByteOrder.nativeOrder (); } } |
