| Method from java.nio.CharBuffer Detail: |
public static CharBuffer allocate(int capacity) {
return new CharBufferImpl (capacity);
}
Allocates a new CharBuffer object with a given capacity. |
public final char[] array() {
if (backing_buffer == null)
throw new UnsupportedOperationException ();
checkIfReadOnly();
return backing_buffer;
}
Returns the char array that backs this buffer. |
public final int arrayOffset() {
if (backing_buffer == null)
throw new UnsupportedOperationException ();
checkIfReadOnly();
return array_offset;
}
Returns the offset within this buffer's backing array of the first element. |
abstract public CharBuffer asReadOnlyBuffer()
Creates a new read-only CharBuffer that shares this
buffer's content. |
public final char charAt(int index) {
if (index < 0
|| index >= remaining ())
throw new IndexOutOfBoundsException ();
return get (position () + index);
}
Returns the character at position() + index. |
abstract public CharBuffer compact()
|
public int compareTo(Object obj) {
CharBuffer other = (CharBuffer) obj;
int num = Math.min(remaining(), other.remaining());
int pos_this = position();
int pos_other = other.position();
for (int count = 0; count < num; count++)
{
char a = get(pos_this++);
char b = other.get(pos_other++);
if (a == b)
continue;
if (a < b)
return -1;
return 1;
}
return remaining() - other.remaining();
}
Compares two CharBuffer objects. |
abstract public CharBuffer duplicate()
Creates a new CharBuffer that shares this buffer's
content. |
public boolean equals(Object obj) {
if (obj instanceof CharBuffer)
{
return compareTo (obj) == 0;
}
return false;
}
Checks if this buffer is equal to obj. |
abstract public char get()
Reads the char at this buffer's current position,
and then increments the position. |
public CharBuffer get(char[] dst) {
return get (dst, 0, dst.length);
}
This method transfers chars from this buffer into the given
destination array. |
abstract public char get(int index)
|
public CharBuffer get(char[] dst,
int offset,
int length) {
checkArraySize(dst.length, offset, length);
checkForUnderflow(length);
for (int i = offset; i < offset + length; i++)
{
dst [i] = get ();
}
return this;
}
This method transfers chars from this buffer into the given
destination array. Before the transfer, it checks if there are fewer than
length chars remaining in this buffer. |
public final boolean hasArray() {
return (backing_buffer != null
&& !isReadOnly ());
}
Tells whether ot not this buffer is backed by an accessible
char array. |
public int hashCode() {
int hashCode = get(position()) + 31;
int multiplier = 1;
for (int i = position() + 1; i < limit(); ++i)
{
multiplier *= 31;
hashCode += (get(i) + 30)*multiplier;
}
return hashCode;
}
Calculates a hash code for this buffer.
This is done with int arithmetic,
where ** represents exponentiation, by this formula:
s[position()] + 31 + (s[position()+1] + 30)*31**1 + ... +
(s[limit()-1]+30)*31**(limit()-1).
Where s is the buffer data. Note that the hashcode is dependent
on buffer content, and therefore is not useful if the buffer
content may change. |
abstract public boolean isDirect()
Tells wether or not this buffer is direct. |
public final int length() {
return remaining ();
}
Returns the length of the remaining chars in this buffer. |
abstract public ByteOrder order()
Returns the byte order of this buffer. |
public CharBuffer put(CharBuffer src) {
if (src == this)
throw new IllegalArgumentException ();
checkForOverflow(src.remaining());
if (src.remaining () > 0)
{
char[] toPut = new char [src.remaining ()];
src.get (toPut);
put (toPut);
}
return this;
}
Writes the content of the the CharBUFFER src
into the buffer. Before the transfer, it checks if there is fewer than
src.remaining() space remaining in this buffer. |
public final CharBuffer put(char[] src) {
return put (src, 0, src.length);
}
Writes the content of the the char array src
into the buffer. |
abstract public CharBuffer put(char b)
Writes the char at this buffer's current position,
and then increments the position. |
public final CharBuffer put(String str) {
return put (str.toCharArray (), 0, str.length ());
}
|
abstract public CharBuffer put(int index,
char b)
|
public CharBuffer put(char[] src,
int offset,
int length) {
checkArraySize(src.length, offset, length);
checkForOverflow(length);
for (int i = offset; i < offset + length; i++)
put (src [i]);
return this;
}
Writes the content of the the char array src
into the buffer. Before the transfer, it checks if there is fewer than
length space remaining in this buffer. |
public CharBuffer put(String str,
int start,
int length) {
return put (str.toCharArray (), start, length);
}
|
abstract public CharBuffer slice()
Creates a new CharBuffer whose content is a shared
subsequence of this buffer's content. |
abstract public CharSequence subSequence(int start,
int length)
Creates a new character buffer that represents the specified subsequence
of this buffer, relative to the current position. |
public String toString() {
if (hasArray ())
return new String (array (), position (), length ());
char[] buf = new char [length ()];
int pos = position ();
get (buf, 0, buf.length);
position (pos);
return new String (buf);
}
Returns the remaining content of the buffer as a string. |
public static final CharBuffer wrap(CharSequence seq) {
return wrap(seq, 0, seq.length());
}
Wraps a character sequence into a CharBuffer object. |
public static final CharBuffer wrap(char[] array) {
return wrap(array, 0, array.length);
}
Wraps a char array into a CharBuffer
object. |
public static final CharBuffer wrap(char[] array,
int offset,
int length) {
return new CharBufferImpl(array, 0, array.length, offset + length, offset, -1, false);
}
Wraps a char array into a CharBuffer
object. |
public static final CharBuffer wrap(CharSequence seq,
int start,
int end) {
// FIXME: implement better handling of java.lang.String.
// Probably share data with String via reflection.
if ((start < 0)
|| (start > seq.length())
|| (end < start)
|| (end > (seq.length() - start)))
throw new IndexOutOfBoundsException();
int len = end - start;
char[] buffer = new char[len];
for (int i = 0; i < len; i++)
buffer[i] = seq.charAt(i + start);
return wrap(buffer, 0, len).asReadOnlyBuffer();
}
Wraps a character sequence into a CharBuffer object. |