diff options
author | Michael Koch <konqueror@gmx.de> | 2002-11-13 12:21:26 +0000 |
---|---|---|
committer | Michael Koch <mkoch@gcc.gnu.org> | 2002-11-13 12:21:26 +0000 |
commit | 93f93f9f2865f06a0929d5311101c5bc4b6565bc (patch) | |
tree | db3be97532ba927b2d999315ce0cc17581fbbaa3 /libjava/java/nio/Buffer.java | |
parent | 7b53becc108e717109ebf7541b1af06083d8e95c (diff) | |
download | gcc-93f93f9f2865f06a0929d5311101c5bc4b6565bc.zip gcc-93f93f9f2865f06a0929d5311101c5bc4b6565bc.tar.gz gcc-93f93f9f2865f06a0929d5311101c5bc4b6565bc.tar.bz2 |
Buffer.java: Implemented.
2002-11-13 Michael Koch <konqueror@gmx.de>
* java/nio/Buffer.java: Implemented.
* java/nio/CharBuffer.java: New file.
* java/nio/InvalidMarkException.java: New file.
* java/nio/channels/DatagramChannel.java: Implemented.
* java/nio/channels/ServerSocketChannel.java: Implemented.
* java/nio/channels/SocketChannel.java: Implemented.
* java/nio/channels/spi/AbstractChannel.java: Removed.
* java/nio/channels/spi/AbstractSelectableChannel.java:
Implemented.
* java/nio/charset/Charset.java:
Merge from Classpath.
* java/nio/charset/CharsetDecoder.java: New file.
* java/nio/charset/CharsetEncoder.java: New file.
* java/nio/charset/CoderResult.java: New file.
* Makefile.am (ordinary_java_source_files): Added new files.
* Makefile.in: Regenerated.
From-SVN: r59075
Diffstat (limited to 'libjava/java/nio/Buffer.java')
-rw-r--r-- | libjava/java/nio/Buffer.java | 151 |
1 files changed, 151 insertions, 0 deletions
diff --git a/libjava/java/nio/Buffer.java b/libjava/java/nio/Buffer.java index 4e18cbd..9474fb4 100644 --- a/libjava/java/nio/Buffer.java +++ b/libjava/java/nio/Buffer.java @@ -39,4 +39,155 @@ package java.nio; public abstract class Buffer { + int cap = 0; + int limit = 0; + int pos = 0; + int mark = -1; + + /** + * Retrieves the capacity of the buffer. + */ + public final int capacity () + { + return cap; + } + + /** + * Clears the buffer. + */ + public final Buffer clear () + { + limit = cap; + pos = 0; + mark = -1; + return this; + } + + /** + * Flips the buffer. + */ + public final Buffer flip () + { + limit = pos; + pos = 0; + mark = -1; + return this; + } + + /** + * Tells whether the buffer has remaining data to read or not. + */ + public final boolean hasRemaining () + { + return limit > pos; + } + + /** + * Tells whether this buffer is read only or not. + */ + public abstract boolean isReadOnly (); + + /** + * Retrieves the current limit of the buffer. + */ + public final int limit () + { + return limit; + } + + /** + * Sets this buffer's limit. + * + * @param newLimit The new limit value; must be non-negative and no larger + * than this buffer's capacity. + * + * @exception IllegalArgumentException If the preconditions on newLimit + * do not hold. + */ + public final Buffer limit (int newLimit) + { + if ((newLimit < 0) || (newLimit > cap)) + throw new IllegalArgumentException (); + + if (newLimit <= mark) + mark = -1; + + if (pos > newLimit) + pos = newLimit - 1; + + limit = newLimit; + return this; + } + + /** + * Sets this buffer's mark at its position. + */ + public final Buffer mark () + { + mark = pos; + return this; + } + + /** + * Retrieves the current position of this buffer. + */ + public final int position () + { + return pos; + } + + /** + * Sets this buffer's position. If the mark is defined and larger than the + * new position then it is discarded. + * + * @param newPosition The new position value; must be non-negative and no + * larger than the current limit. + * + * @exception IllegalArgumentException If the preconditions on newPosition + * do not hold + */ + public final Buffer position (int newPosition) + { + if ((newPosition < 0) || (newPosition > limit)) + throw new IllegalArgumentException (); + + if (newPosition <= mark) + mark = -1; + + pos = newPosition; + return this; + } + + /** + * Returns the number of elements between the current position and the limit. + */ + public final int remaining() + { + return limit - pos; + } + + /** + * Resets this buffer's position to the previously-marked position. + * + * @exception InvalidMarkException If the mark has not been set. + */ + public final Buffer reset() + { + if (mark == -1) + throw new InvalidMarkException (); + + pos = mark; + return this; + } + + /** + * Rewinds this buffer. The position is set to zero and the mark + * is discarded. + */ + public final Buffer rewind() + { + pos = 0; + mark = -1; + return this; + } } |