37 |
|
|
38 |
package java.nio; |
package java.nio; |
39 |
|
|
40 |
|
import gnu.java.nio.CharBufferImpl; |
41 |
|
|
42 |
|
/** |
43 |
|
* @since 1.4 |
44 |
|
*/ |
45 |
public abstract class CharBuffer extends Buffer |
public abstract class CharBuffer extends Buffer |
46 |
{ |
{ |
47 |
private ByteOrder endian = ByteOrder.BIG_ENDIAN; |
private ByteOrder endian = ByteOrder.BIG_ENDIAN; |
48 |
|
|
49 |
protected char [] backing_buffer; |
protected char [] backing_buffer; |
50 |
|
|
51 |
public static CharBuffer allocateDirect(int capacity) |
public static CharBuffer allocateDirect (int capacity) |
52 |
{ |
{ |
53 |
CharBuffer b = new gnu.java.nio. CharBufferImpl(capacity, 0, capacity); |
return new CharBufferImpl (capacity, 0, capacity); |
|
return b; |
|
54 |
} |
} |
55 |
|
|
56 |
public static CharBuffer allocate(int capacity) |
public static CharBuffer allocate(int capacity) |
57 |
{ |
{ |
58 |
CharBuffer b = new gnu.java.nio. CharBufferImpl(capacity, 0, capacity); |
return new CharBufferImpl (capacity, 0, capacity); |
|
return b; |
|
59 |
} |
} |
60 |
|
|
61 |
final public static CharBuffer wrap(char[] array, int offset, int length) |
final public static CharBuffer wrap (char[] array, int offset, int length) |
62 |
{ |
{ |
63 |
gnu.java.nio.CharBufferImpl b = new gnu.java.nio. CharBufferImpl(array, offset, length); |
return new CharBufferImpl (array, offset, length); |
|
return b; |
|
64 |
} |
} |
65 |
|
|
66 |
final public static CharBuffer wrap(String a) |
final public static CharBuffer wrap (char[] array) |
67 |
{ |
{ |
68 |
int len = a.length(); |
return wrap (array, 0, array.length); |
|
char[] buffer = new char[len]; |
|
|
for (int i=0;i<len;i++) |
|
|
{ |
|
|
buffer[i] = (char) a.charAt(i); |
|
|
} |
|
|
return wrap(buffer, 0, len); |
|
69 |
} |
} |
70 |
|
|
71 |
final public static CharBuffer wrap(CharSequence cs) |
final public static CharBuffer wrap (CharSequence cs, int offset, int length) |
72 |
{ |
{ |
73 |
return null; |
return wrap (cs.toString ().toCharArray (), 0, length); |
74 |
} |
} |
75 |
|
|
76 |
final public static CharBuffer wrap(char[] array) |
final public static CharBuffer wrap (CharSequence cs) |
77 |
{ |
{ |
78 |
return wrap(array, 0, array.length); |
return wrap (cs, 0, cs.length ()); |
79 |
} |
} |
80 |
|
|
81 |
final public CharBuffer get(char[] dst, int offset, int length) |
final public CharBuffer get (char[] dst, int offset, int length) |
82 |
{ |
{ |
83 |
for (int i = offset; i < offset + length; i++) |
for (int i = offset; i < offset + length; i++) |
84 |
{ |
dst [i] = get (); |
85 |
dst[i] = get(); |
|
|
} |
|
86 |
return this; |
return this; |
87 |
} |
} |
88 |
|
|
89 |
final public CharBuffer get(char[] dst) |
final public CharBuffer get (char[] dst) |
90 |
{ |
{ |
91 |
return get(dst, 0, dst.length); |
return get (dst, 0, dst.length); |
92 |
} |
} |
93 |
|
|
94 |
final public CharBuffer put(CharBuffer src) |
final public CharBuffer put (CharBuffer src) |
95 |
{ |
{ |
96 |
while (src.hasRemaining()) |
while (src.hasRemaining ()) |
97 |
put(src.get()); |
put (src.get ()); |
98 |
|
|
99 |
return this; |
return this; |
100 |
} |
} |
101 |
|
|
102 |
final public CharBuffer put(char[] src, int offset, int length) |
final public CharBuffer put (char[] src, int offset, int length) |
103 |
{ |
{ |
104 |
for (int i = offset; i < offset + length; i++) |
for (int i = offset; i < offset + length; i++) |
105 |
put(src[i]); |
put (src[i]); |
106 |
|
|
107 |
return this; |
return this; |
108 |
} |
} |
109 |
|
|
110 |
public final CharBuffer put(String src) |
public final CharBuffer put(String src) |
111 |
{ |
{ |
112 |
return put(src.toCharArray (), 0, src.length ()); |
return put (src.toCharArray (), 0, src.length ()); |
113 |
} |
} |
114 |
|
|
115 |
public final CharBuffer put(char[] src) |
/** |
116 |
|
* This method transfers the entire content of the given |
117 |
|
* source character array into this buffer. |
118 |
|
* |
119 |
|
* @param src The source character array to transfer. |
120 |
|
* |
121 |
|
* @exception BufferOverflowException If there is insufficient space |
122 |
|
* in this buffer. |
123 |
|
* @exception ReadOnlyBufferException If this buffer is read-only. |
124 |
|
*/ |
125 |
|
public final CharBuffer put (char[] src) |
126 |
{ |
{ |
127 |
return put(src, 0, src.length); |
return put (src, 0, src.length); |
128 |
} |
} |
129 |
|
|
130 |
public final boolean hasArray() |
public final boolean hasArray () |
131 |
{ |
{ |
132 |
return (backing_buffer != null); |
return backing_buffer != null; |
133 |
} |
} |
134 |
|
|
135 |
public final char[] array() |
public final char[] array () |
136 |
{ |
{ |
137 |
return backing_buffer; |
return backing_buffer; |
138 |
} |
} |
139 |
|
|
140 |
public final int arrayOffset() |
public final int arrayOffset () |
141 |
{ |
{ |
142 |
return 0; |
return 0; |
143 |
} |
} |
144 |
|
|
145 |
public int hashCode() |
public int hashCode () |
146 |
{ |
{ |
147 |
return super.hashCode(); |
return super.hashCode (); |
148 |
} |
} |
149 |
|
|
150 |
public boolean equals(Object obj) |
public boolean equals (Object obj) |
151 |
{ |
{ |
152 |
if (obj instanceof CharBuffer) |
if (obj instanceof CharBuffer) |
153 |
{ |
return compareTo (obj) == 0; |
154 |
return compareTo(obj) == 0; |
|
|
} |
|
155 |
return false; |
return false; |
156 |
} |
} |
157 |
|
|
158 |
public int compareTo(Object ob) |
public int compareTo(Object obj) |
159 |
{ |
{ |
160 |
CharBuffer a = (CharBuffer) ob; |
CharBuffer a = (CharBuffer) obj; |
161 |
if (a.remaining() != remaining()) |
|
162 |
|
if (a.remaining () != remaining ()) |
163 |
return 1; |
return 1; |
164 |
if (! hasArray() || |
|
165 |
! a.hasArray()) |
if (! hasArray () || ! a.hasArray ()) |
166 |
{ |
return 1; |
167 |
return 1; |
|
168 |
} |
int r = remaining (); |
169 |
int r = remaining(); |
int i1 = position (); |
170 |
int i1 = pos; |
int i2 = a.position (); |
171 |
int i2 = a.pos; |
|
172 |
for (int i=0;i<r;i++) |
for (int i = 0; i < r; i++) |
173 |
{ |
{ |
174 |
int t = (int) (get(i1)- a.get(i2)); |
int t = (int) (get (i1)- a.get (i2)); |
175 |
|
|
176 |
if (t != 0) |
if (t != 0) |
177 |
{ |
return (int) t; |
|
return (int) t; |
|
|
} |
|
178 |
} |
} |
179 |
return 0; |
return 0; |
180 |
} |
} |