From 36d4669b735c0e6f665e9a83bdd0848e23fc6662 Mon Sep 17 00:00:00 2001 From: Michael Koch Date: Mon, 12 May 2003 20:45:20 +0000 Subject: ByteBufferImpl.java: Reformatted. 2003-05-12 Michael Koch * gnu/java/nio/ByteBufferImpl.java: Reformatted. (nio_get_*): Removed. (nio_put_*): Removed. (as*Buffer): Implemented. (compact): Implemented. (get): Documentation added. (put): Documentation added. (get*): Newly implemented. (put*): Newly implemented. * gnu/java/nio/CharBufferImpl.java: Reformatted. (CharBufferImpl): Revised. (slice): New implementation. (duplicate): New implementation. (compact): New implementation. (asReadOnlyBuffer): New implementation. (get): Documentation revised. (order): Return native byte order. * gnu/java/nio/DirectByteBufferImpl.java (allocateDirect): objects can be null not 0. * gnu/java/nio/DoubleBufferImpl.java: Reformatted. (DoubleBufferImpl): Revised. (slice): New implementation. (duplicate): New implementation. (compact): New implementation. (asReadOnlyBuffer): New implementation. (get): Documentation revised. (order): Return native byte order. * gnu/java/nio/FloatBufferImpl.java: Reformatted. (FloatBufferImpl): Revised. (slice): New implementation. (duplicate): New implementation. (compact): New implementation. (asReadOnlyBuffer): New implementation. (get): Documentation revised. (order): Return native byte order. * gnu/java/nio/IntBufferImpl.java: Reformatted. (IntBufferImpl): Revised. (slice): New implementation. (duplicate): New implementation. (compact): New implementation. (asReadOnlyBuffer): New implementation. (get): Documentation revised. (order): Return native byte order. * gnu/java/nio/LongBufferImpl.java: Reformatted. (LongBufferImpl): Revised. (slice): New implementation. (duplicate): New implementation. (compact): New implementation. (asReadOnlyBuffer): New implementation. (get): Documentation revised. (order): Return native byte order. * gnu/java/nio/ShortBufferImpl.java: Reformatted. (ShortBufferImpl): Revised. (slice): New implementation. (duplicate): New implementation. (compact): New implementation. (asReadOnlyBuffer): New implementation. (get): Documentation revised. (order): Return native byte order. * java/nio/CharBuffer.java: Reformatted, much documentation rewritten. (CharBuffer): Revised. (order): Removed. * java/nio/DoubleBuffer.java: Reformatted, much documentation rewritten. (DoubleBuffer): Revised. (allocateDirect): Removed. (order): Removed. * java/nio/FloatBuffer.java: Reformatted, much documentation rewritten. (FloatBuffer): Revised. (allocateDirect): Removed. (order): Removed. * java/nio/IntBuffer.java: Reformatted, much documentation rewritten. (IntBuffer): Revised. (allocateDirect): Removed. (order): Removed. * java/nio/LongBuffer.java: Reformatted, much documentation rewritten. (LongBuffer): Revised. (allocateDirect): Removed. (order): Removed. * java/nio/ShortBuffer.java: Reformatted, much documentation rewritten. (ShortBuffer): Revised. (allocateDirect): Removed. (order): Removed. * gnu/java/nio/natByteBufferImpl.cc: Removed. * gnu/java/nio/natCharBufferImpl.cc: Removed. * Makefile.am (ordinary_java_source_files): Added the following files: gnu/java/nio/CharViewBufferImpl.java, gnu/java/nio/DoubleViewBufferImpl.java, gnu/java/nio/FloatViewBufferImpl.java, gnu/java/nio/IntViewBufferImpl.java, gnu/java/nio/LongViewBufferImpl.java, gnu/java/nio/ShortViewBufferImpl.java (nat_source_files): Removed the following files: gnu/java/nio/natByteBufferImpl.cc, gnu/java/nio/natCharBufferImpl.cc * Makefile.in: Regenerated. From-SVN: r66733 --- libjava/gnu/java/nio/IntBufferImpl.java | 124 +++++++++++++++++++------------- 1 file changed, 73 insertions(+), 51 deletions(-) (limited to 'libjava/gnu/java/nio/IntBufferImpl.java') diff --git a/libjava/gnu/java/nio/IntBufferImpl.java b/libjava/gnu/java/nio/IntBufferImpl.java index cfa3efe597a..573e5e0372b 100644 --- a/libjava/gnu/java/nio/IntBufferImpl.java +++ b/libjava/gnu/java/nio/IntBufferImpl.java @@ -1,5 +1,5 @@ /* IntBufferImpl.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; @@ -48,93 +49,114 @@ import java.nio.ReadOnlyBufferException; public final class IntBufferImpl extends IntBuffer { private boolean readOnly; - - public IntBufferImpl(int cap, int off, int lim) - { - super (cap, lim, off, 0); - this.backing_buffer = new int[cap]; - readOnly = false; - } - public IntBufferImpl(int[] array, int offset, int length) + IntBufferImpl (int capacity) { - super (array.length, length, offset, 0); - this.backing_buffer = array; - readOnly = false; + this (new int [capacity], 0, capacity, capacity, 0, -1, false); } - - public IntBufferImpl(IntBufferImpl copy) + + IntBufferImpl (int[] 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 IntBuffer slice() + + public IntBuffer slice () { - return new IntBufferImpl (this); + return new IntBufferImpl (backing_buffer, array_offset + position (), remaining (), remaining (), 0, -1, isReadOnly ()); } - - public IntBuffer duplicate() + + public IntBuffer duplicate () { - return new IntBufferImpl(this); + return new IntBufferImpl (backing_buffer, array_offset, capacity (), limit (), position (), mark, isReadOnly ()); } - - public IntBuffer asReadOnlyBuffer() + + public IntBuffer asReadOnlyBuffer () { - IntBufferImpl result = new IntBufferImpl (this); - result.readOnly = true; - return result; + return new IntBufferImpl (backing_buffer, array_offset, capacity (), limit (), position (), mark, true); } - - public IntBuffer compact() + + public IntBuffer 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 int get() + /** + * Relative get method. Reads the next int from the buffer. + */ + final public int get () { - int e = backing_buffer[position()]; - position(position()+1); - return e; + int result = backing_buffer [position ()]; + position (position () + 1); + return result; } - - final public IntBuffer put(int b) + + /** + * Relative put method. Writes value to the next position + * in the buffer. + * + * @exception ReadOnlyBufferException If this buffer is read-only. + */ + final public IntBuffer put (int value) { if (readOnly) throw new ReadOnlyBufferException (); - - backing_buffer[position()] = b; - position(position()+1); + + backing_buffer [position ()] = value; + position (position () + 1); return this; } - - final public int get(int index) + + /** + * Absolute get method. Reads the int at position + * index. + * + * @exception IndexOutOfBoundsException If index is negative or not smaller + * than the buffer's limit. + */ + final public int get (int index) { - return backing_buffer[index]; + return backing_buffer [index]; } - - final public IntBuffer put(int index, int b) + + /** + * Absolute put method. Writes value to position + * index 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 IntBuffer put (int index, int 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 (); } } -- cgit v1.2.3