ReaderUTF16public class ReaderUTF16 extends Reader UTF-16 encoded stream reader. |
Fields Summary |
---|
private InputStream | is | private char | bo |
Constructors Summary |
---|
public ReaderUTF16(InputStream is, char bo)Constructor.
Byte order argument can be: 'l' for little-endian or 'b' for big-endian.
switch (bo) {
case 'l":
break;
case 'b":
break;
default:
throw new IllegalArgumentException("");
}
this.bo = bo;
this.is = is;
|
Methods Summary |
---|
public void | close()Closes the stream.
is.close();
| public int | read(char[] cbuf, int off, int len)Reads characters into a portion of an array.
int num = 0;
int val;
if (bo == 'b") {
while (num < len) {
if ((val = is.read()) < 0)
return (num != 0)? num: -1;
cbuf[off++] = (char)((val << 8) | (is.read() & 0xff));
num++;
}
} else {
while (num < len) {
if ((val = is.read()) < 0)
return (num != 0)? num: -1;
cbuf[off++] = (char)((is.read() << 8) | (val & 0xff));
num++;
}
}
return num;
| public int | read()Reads a single character.
int val;
if ((val = is.read()) < 0)
return -1;
if (bo == 'b") {
val = (char)((val << 8) | (is.read() & 0xff));
} else {
val = (char)((is.read() << 8) | (val & 0xff));
}
return val;
|
|