home *** CD-ROM | disk | FTP | other *** search
- package java.net;
-
- import java.io.FileInputStream;
- import java.io.IOException;
-
- class SocketInputStream extends FileInputStream {
- private boolean eof;
- private SocketImpl impl;
- private byte[] temp = new byte[1];
-
- SocketInputStream(SocketImpl impl) throws IOException {
- super(impl.getFileDescriptor());
- this.impl = impl;
- }
-
- private native int socketRead(byte[] var1, int var2, int var3) throws IOException;
-
- public int read(byte[] b) throws IOException {
- return this.read(b, 0, b.length);
- }
-
- public int read(byte[] b, int off, int length) throws IOException {
- if (this.eof) {
- return -1;
- } else {
- int n = this.socketRead(b, off, length);
- if (n <= 0) {
- this.eof = true;
- return -1;
- } else {
- return n;
- }
- }
- }
-
- public int read() throws IOException {
- if (this.eof) {
- return -1;
- } else {
- int n = this.read(this.temp, 0, 1);
- return n <= 0 ? -1 : this.temp[0] & 255;
- }
- }
-
- public int skip(int numbytes) throws IOException {
- int n = numbytes;
-
- for(byte[] data = new byte[numbytes]; n > 0; n -= this.read(data, 0, n)) {
- }
-
- return numbytes;
- }
-
- public int available() throws IOException {
- return this.impl.available();
- }
-
- public void close() throws IOException {
- this.impl.close();
- }
-
- protected void finalize() {
- }
- }
-