Here is the source from the Java 1.3 release. Your guess is as good as mine
as to why this class should be private. I see that it extends
FileInputStream which has the method getFD() to return the FileDescriptor...
which may not make sense for a Socket InputStream. Interesting, no? :-)
~akb
--------------------------
/*
* @(#)SocketInputStream.java 1.23 00/02/02
*
* Copyright 1995-2000 Sun Microsystems, Inc. All Rights Reserved.
*
* This software is the proprietary information of Sun Microsystems, Inc.
* Use is subject to license terms.
*
*/
package java.net;
import java.io.IOException;
import java.io.FileInputStream;
/**
* This stream extends FileInputStream to implement a
* SocketInputStream. Note that this class should <b>NOT</b> be
* public.
*
* @version 1.23, 02/02/00
* @author Jonathan Payne
* @author Arthur van Hoff
*/
class SocketInputStream extends FileInputStream
{
static {
init();
}
private boolean eof;
private SocketImpl impl;
private byte temp[];
/**
* Creates a new SocketInputStream. Can only be called
* by a Socket. This method needs to hang on to the owner Socket so
* that the fd will not be closed.
* @param impl the implemented socket input stream
*/
SocketInputStream(SocketImpl impl) throws IOException {
super(impl.getFileDescriptor());
this.impl = impl;
}
/**
* Reads into an array of bytes at the specified offset using
* the received socket primitive.
* @param b the buffer into which the data is read
* @param off the start offset of the data
* @param len the maximum number of bytes read
* @return the actual number of bytes read, -1 is
* returned when the end of the stream is reached.
* @exception IOException If an I/O error has occurred.
*/
private native int socketRead(byte b[], int off, int len)
throws IOException;
/**
* Reads into a byte array data from the socket.
* @param b the buffer into which the data is read
* @return the actual number of bytes read, -1 is
* returned when the end of the stream is reached.
* @exception IOException If an I/O error has occurred.
*/
public int read(byte b[]) throws IOException {
return read(b, 0, b.length);
}
/**
* Reads into a byte array <i>b</i> at offset <i>off</i>,
* <i>length</i> bytes of data.
* @param b the buffer into which the data is read
* @param off the start offset of the data
* @param len the maximum number of bytes read
* @return the actual number of bytes read, -1 is
* returned when the end of the stream is reached.
* @exception IOException If an I/O error has occurred.
*/
public int read(byte b[], int off, int length) throws IOException {
if (eof) {
return -1;
}
if (length == 0)
return 0;
int n = socketRead(b, off, length);
if (n <= 0) {
eof = true;
return -1;
}
return n;
}
/**
* Reads a single byte from the socket.
*/
public int read() throws IOException {
if (eof) {
return -1;
}
temp = new byte[1];
int n = read(temp, 0, 1);
if (n <= 0) {
return -1;
}
return temp[0] & 0xff;
}
/**
* Skips n bytes of input.
* @param n the number of bytes to skip
* @return the actual number of bytes skipped.
* @exception IOException If an I/O error has occurred.
*/
public long skip(long numbytes) throws IOException {
if (numbytes <= 0) {
return 0;
}
long n = numbytes;
int buflen = (int) Math.min(1024, n);
byte data[] = new byte[buflen];
while (n > 0) {
int r = read(data, 0, (int) Math.min((long) buflen, n));
if (r < 0) {
break;
}
n -= r;
}
return numbytes - n;
}
/**
* Returns the number of bytes that can be read without blocking.
* @return the number of immediately available bytes
*/
public int available() throws IOException {
return impl.available();
}
/**
* Closes the stream.
*/
public void close() throws IOException {
impl.close();
}
void setEOF(boolean eof) {
this.eof = eof;
}
/**
* Overrides finalize, the fd is closed by the Socket.
*/
protected void finalize() {}
/**
* Perform class load-time initializations.
*/
private native static void init();
}
| -----Original Message-----
| From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
| Behalf Of Richard O. Hammer
| Sent: Thursday, June 19, 2003 1:07 PM
| To: Java Users Group
| Subject: [Juglist] documentation for java.net.SocketInputStream
|
|
| I gather there is a class java.net.SocketInputStream, since that is
| the type I find returned by Socket.getInputStream(). I'd like to know
| more about this class, but it is not mentioned in the java.net
| Javadoc. I am surprised to learn that there are classes in the
| standard packages not mentioned in the Javadoc.
|
| Can anyone tell me if this class is documented somewhere?
|
| I am using java version 1.4.0 on Windows 2000.
|
| Here is the code which tells me of the existence of
| java.net.SocketInputStream.
|
| /* Testing what type of InputStream a Socket gives me.
| */
|
| import java.io.*;
| import java.net.*;
|
| class SocketStreamPeeker{
| public static void main(String[] args) throws Exception{
| Socket so = new Socket("trijug.org", 80);
| InputStream in = so.getInputStream();
| Class cl = in.getClass();
| System.out.println(cl.getName());
| so.close();
| }
| }
|
|
| Rich Hammer
|
|
| _______________________________________________
| Juglist mailing list
| [EMAIL PROTECTED]
| http://trijug.org/mailman/listinfo/juglist_trijug.org
_______________________________________________
Juglist mailing list
[EMAIL PROTECTED]
http://trijug.org/mailman/listinfo/juglist_trijug.org