/* */ package NET.worlds.network; /* */ /* */ import java.io.EOFException; /* */ import java.io.FilterInputStream; /* */ import java.io.IOException; /* */ import java.io.InputStream; /* */ import java.io.UTFDataFormatException; /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ public class ServerInputStream /* */ extends FilterInputStream /* */ { /* */ private int _packetSize; /* */ private int _version; /* */ /* */ public ServerInputStream(InputStream in) /* */ { /* 70 */ super(in); /* 71 */ assert (in != null); /* 72 */ this._packetSize = 0; /* 73 */ this._version = 24; /* */ } /* */ /* */ public ServerInputStream(InputStream in, int vers) { /* 77 */ super(in); /* 78 */ assert (in != null); /* 79 */ this._packetSize = 0; /* 80 */ this._version = vers; /* */ } /* */ /* */ public void setVersion(int vers) { /* 84 */ this._version = vers; /* */ } /* */ /* */ public int getVersion() { /* 88 */ return this._version; /* */ } /* */ /* */ public void readPacketSize() throws IOException { /* 92 */ assert (this._packetSize == 0); /* 93 */ this._packetSize = 1; /* 94 */ this._packetSize = (readUnsignedByte() - 1); /* */ /* */ /* 97 */ if (((this._packetSize & 0x80) != 0) && (getVersion() > 24)) { /* 98 */ this._packetSize = /* 99 */ ((this._packetSize & 0x80) * 256 + readUnsignedByte() - 1); /* */ } /* */ } /* */ /* */ public boolean isEmpty() { /* 104 */ return this._packetSize == 0; /* */ } /* */ /* */ /* */ /* */ /* */ /* */ public int bytesLeft() /* */ { /* 113 */ return this._packetSize; /* */ } /* */ /* */ /* */ /* */ /* */ /* */ /* */ public final int read(byte[] b) /* */ throws IOException /* */ { /* 124 */ assert (this._packetSize >= b.length); /* 125 */ if (b.length == 0) /* 126 */ return 0; /* 127 */ int bytesRead = this.in.read(b, 0, b.length); /* 128 */ if (bytesRead < 0) /* 129 */ throw new EOFException(); /* 130 */ this._packetSize -= bytesRead; /* 131 */ return bytesRead; /* */ } /* */ /* */ /* */ /* */ /* */ /* */ /* */ public final int read(byte[] b, int off, int len) /* */ throws IOException /* */ { /* 142 */ assert (this._packetSize >= len); /* 143 */ int bytesRead = this.in.read(b, off, len); /* 144 */ if (bytesRead < 0) /* 145 */ throw new EOFException(); /* 146 */ this._packetSize -= bytesRead; /* 147 */ return bytesRead; /* */ } /* */ /* */ /* */ /* */ /* */ public final void readFully(byte[] b) /* */ throws IOException /* */ { /* 156 */ assert (this._packetSize >= b.length); /* 157 */ readFully(b, 0, b.length); /* */ } /* */ /* */ /* */ /* */ /* */ /* */ public final void readFully(byte[] b, int off, int len) /* */ throws IOException /* */ { /* 167 */ assert (this._packetSize >= len); /* 168 */ this._packetSize -= len; /* 169 */ InputStream in = this.in; /* 170 */ while (len > 0) { /* 171 */ int bytesRead = in.read(b, off, len); /* 172 */ if (bytesRead < 0) /* 173 */ throw new EOFException(); /* 174 */ len -= bytesRead; /* 175 */ off += bytesRead; /* */ } /* */ } /* */ /* */ /* */ public void skipBytes(int n) /* */ throws IOException /* */ { /* 183 */ assert (this._packetSize >= n); /* 184 */ this._packetSize -= n; /* 185 */ InputStream in = this.in; /* 186 */ while (n > 0) { /* 187 */ int bytesSkipped = (int)in.skip(n); /* 188 */ if (bytesSkipped < 0) /* 189 */ throw new EOFException(); /* 190 */ n -= bytesSkipped; /* */ } /* */ } /* */ /* */ /* */ /* */ /* */ /* */ public final byte readByte() /* */ throws IOException /* */ { /* 201 */ if (this._packetSize < 1) /* 202 */ throw new IOException(); /* 203 */ int ch = this.in.read(); /* 204 */ if (ch < 0) /* 205 */ throw new EOFException(); /* 206 */ this._packetSize -= 1; /* 207 */ return (byte)ch; /* */ } /* */ /* */ /* */ /* */ /* */ /* */ public final int readUnsignedByte() /* */ throws IOException /* */ { /* 217 */ if (this._packetSize < 1) /* 218 */ throw new IOException(); /* 219 */ int ch = this.in.read(); /* 220 */ if (ch < 0) /* 221 */ throw new EOFException(); /* 222 */ this._packetSize -= 1; /* 223 */ return ch; /* */ } /* */ /* */ /* */ /* */ /* */ public final short readShort() /* */ throws IOException /* */ { /* 232 */ assert (this._packetSize >= 2); /* 233 */ InputStream in = this.in; /* 234 */ int ch1 = in.read(); /* 235 */ int ch2 = in.read(); /* 236 */ if ((ch1 | ch2) < 0) /* 237 */ throw new EOFException(); /* 238 */ this._packetSize -= 2; /* 239 */ return (short)((ch1 << 8) + (ch2 << 0)); /* */ } /* */ /* */ /* */ /* */ /* */ public final int readUnsignedShort() /* */ throws IOException /* */ { /* 248 */ assert (this._packetSize >= 2); /* 249 */ InputStream in = this.in; /* 250 */ int ch1 = in.read(); /* 251 */ int ch2 = in.read(); /* 252 */ if ((ch1 | ch2) < 0) /* 253 */ throw new EOFException(); /* 254 */ this._packetSize -= 2; /* 255 */ return (ch1 << 8) + (ch2 << 0); /* */ } /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ public String readUTF() /* */ throws IOException /* */ { /* 267 */ if (this._packetSize < 1) { /* 268 */ throw new IOException(); /* */ } /* 270 */ int utflen = readUnsignedByte(); /* */ /* 272 */ if (this._packetSize < utflen) { /* 273 */ throw new UTFDataFormatException(); /* */ } /* */ /* */ /* 277 */ char[] str = new char[utflen]; /* 278 */ int count = 0; /* 279 */ int strlen = 0; /* 280 */ while (count < utflen) { /* 281 */ int c = readUnsignedByte(); /* */ /* 283 */ switch (c >> 4) /* */ { /* */ case 0: /* */ case 1: /* */ case 2: /* */ case 3: /* */ case 4: /* */ case 5: /* */ case 6: /* */ case 7: /* 293 */ count++; /* 294 */ str[(strlen++)] = ((char)c); /* 295 */ break; /* */ /* */ case 12: /* */ case 13: /* 299 */ count += 2; /* 300 */ if (count > utflen) /* 301 */ throw new UTFDataFormatException(); /* 302 */ int char2 = readUnsignedByte(); /* 303 */ if ((char2 & 0xC0) != 128) /* 304 */ throw new UTFDataFormatException(); /* 305 */ str[(strlen++)] = ((char)((c & 0x1F) << 6 | char2 & 0x3F)); /* 306 */ break; /* */ /* */ case 14: /* 309 */ count += 3; /* 310 */ if (count > utflen) /* 311 */ throw new UTFDataFormatException(); /* 312 */ int char2 = readUnsignedByte(); /* 313 */ int char3 = readUnsignedByte(); /* 314 */ if (((char2 & 0xC0) != 128) || ((char3 & 0xC0) != 128)) /* 315 */ throw new UTFDataFormatException(); /* 316 */ str[(strlen++)] = /* 317 */ ((char)((c & 0xF) << 12 | (char2 & 0x3F) << 6 | (char3 & 0x3F) << 0)); /* 318 */ break; /* */ case 8: case 9: case 10: /* */ case 11: default: /* 321 */ throw new UTFDataFormatException(); /* */ } /* */ } /* 324 */ return new String(str, 0, strlen); /* */ } /* */ } /* Location: C:\Program Files (x86)\Worlds Inc\WorldsPlayer - Win7\lib\worlds.jar!\NET\worlds\network\ServerInputStream.class * Java compiler version: 6 (50.0) * JD-Core Version: 0.7.1 */