home *** CD-ROM | disk | FTP | other *** search
- package java.io;
-
- public class DataInputStream extends FilterInputStream implements DataInput {
- private char[] lineBuffer;
-
- public DataInputStream(InputStream in) {
- super(in);
- }
-
- public final int read(byte[] b) throws IOException {
- return super.in.read(b, 0, b.length);
- }
-
- public final int read(byte[] b, int off, int len) throws IOException {
- return super.in.read(b, off, len);
- }
-
- public final void readFully(byte[] b) throws IOException {
- this.readFully(b, 0, b.length);
- }
-
- public final void readFully(byte[] b, int off, int len) throws IOException {
- InputStream in = super.in;
-
- int count;
- for(int n = 0; n < len; n += count) {
- count = in.read(b, off + n, len - n);
- if (count < 0) {
- throw new EOFException();
- }
- }
-
- }
-
- public final int skipBytes(int n) throws IOException {
- InputStream in = super.in;
-
- for(int i = 0; i < n; i += (int)in.skip((long)(n - i))) {
- }
-
- return n;
- }
-
- public final boolean readBoolean() throws IOException {
- int ch = super.in.read();
- if (ch < 0) {
- throw new EOFException();
- } else {
- return ch != 0;
- }
- }
-
- public final byte readByte() throws IOException {
- int ch = super.in.read();
- if (ch < 0) {
- throw new EOFException();
- } else {
- return (byte)ch;
- }
- }
-
- public final int readUnsignedByte() throws IOException {
- int ch = super.in.read();
- if (ch < 0) {
- throw new EOFException();
- } else {
- return ch;
- }
- }
-
- public final short readShort() throws IOException {
- InputStream in = super.in;
- int ch1 = in.read();
- int ch2 = in.read();
- if ((ch1 | ch2) < 0) {
- throw new EOFException();
- } else {
- return (short)((ch1 << 8) + ch2);
- }
- }
-
- public final int readUnsignedShort() throws IOException {
- InputStream in = super.in;
- int ch1 = in.read();
- int ch2 = in.read();
- if ((ch1 | ch2) < 0) {
- throw new EOFException();
- } else {
- return (ch1 << 8) + ch2;
- }
- }
-
- public final char readChar() throws IOException {
- InputStream in = super.in;
- int ch1 = in.read();
- int ch2 = in.read();
- if ((ch1 | ch2) < 0) {
- throw new EOFException();
- } else {
- return (char)((ch1 << 8) + ch2);
- }
- }
-
- public final int readInt() throws IOException {
- InputStream in = super.in;
- int ch1 = in.read();
- int ch2 = in.read();
- int ch3 = in.read();
- int ch4 = in.read();
- if ((ch1 | ch2 | ch3 | ch4) < 0) {
- throw new EOFException();
- } else {
- return (ch1 << 24) + (ch2 << 16) + (ch3 << 8) + ch4;
- }
- }
-
- public final long readLong() throws IOException {
- return ((long)this.readInt() << 32) + ((long)this.readInt() & 4294967295L);
- }
-
- public final float readFloat() throws IOException {
- return Float.intBitsToFloat(this.readInt());
- }
-
- public final double readDouble() throws IOException {
- return Double.longBitsToDouble(this.readLong());
- }
-
- public final String readLine() throws IOException {
- InputStream in = super.in;
- char[] buf = this.lineBuffer;
- if (buf == null) {
- buf = this.lineBuffer = new char[128];
- }
-
- int room = buf.length;
- int offset = 0;
-
- while(true) {
- int c;
- switch (c = in.read()) {
- case 13:
- int c2 = in.read();
- if (c2 != 10) {
- if (!(in instanceof PushbackInputStream)) {
- in = super.in = new PushbackInputStream(in);
- }
-
- ((PushbackInputStream)in).unread(c2);
- }
- case -1:
- case 10:
- if (c == -1 && offset == 0) {
- return null;
- }
-
- return String.copyValueOf(buf, 0, offset);
- }
-
- --room;
- if (room < 0) {
- buf = new char[offset + 128];
- room = buf.length - offset - 1;
- System.arraycopy(this.lineBuffer, 0, buf, 0, offset);
- this.lineBuffer = buf;
- }
-
- buf[offset++] = (char)c;
- }
- }
-
- public final String readUTF() throws IOException {
- return readUTF(this);
- }
-
- public static final String readUTF(DataInput in) throws IOException {
- int utflen = in.readUnsignedShort();
- char[] str = new char[utflen];
- int count = 0;
- int strlen = 0;
-
- while(count < utflen) {
- int c = in.readUnsignedByte();
- switch (c >> 4) {
- case 14:
- count += 3;
- if (count > utflen) {
- throw new UTFDataFormatException();
- }
-
- int char2 = in.readUnsignedByte();
- int char3 = in.readUnsignedByte();
- if ((char2 & 192) == 128 && (char3 & 192) == 128) {
- str[strlen++] = (char)((c & 15) << 12 | (char2 & 63) << 6 | char3 & 63);
- break;
- }
-
- throw new UTFDataFormatException();
- case 13:
- case 12:
- count += 2;
- if (count > utflen) {
- throw new UTFDataFormatException();
- }
-
- int char2 = in.readUnsignedByte();
- if ((char2 & 192) != 128) {
- throw new UTFDataFormatException();
- }
-
- str[strlen++] = (char)((c & 31) << 6 | char2 & 63);
- break;
- case 7:
- case 6:
- case 5:
- case 4:
- case 3:
- case 2:
- case 1:
- case 0:
- ++count;
- str[strlen++] = (char)c;
- break;
- default:
- throw new UTFDataFormatException();
- }
- }
-
- return new String(str, 0, strlen);
- }
- }
-