SocketInputStreampublic class SocketInputStream extends InputStream
Fields Summary |
---|
private static final int | TMP_BUFFER_SIZE | private InputStream | in | private SessionServicePacket | ssp | private int | tot | private int | bip | private int | n | private byte[] | header | private byte[] | tmp |
Constructors Summary |
---|
SocketInputStream(InputStream in)
this.in = in;
header = new byte[4];
tmp = new byte[TMP_BUFFER_SIZE];
|
Methods Summary |
---|
public int | available()
if( bip > 0 ) {
return bip;
}
return in.available();
| public void | close()
in.close();
| public synchronized int | read()
if( read( tmp, 0, 1 ) < 0 ) {
return -1;
}
return tmp[0] & 0xFF;
| public synchronized int | read(byte[] b)
return read( b, 0, b.length );
| public synchronized int | read(byte[] b, int off, int len)
if( len == 0 ) {
return 0;
}
tot = 0;
while( true ) {
while( bip > 0 ) {
n = in.read( b, off, Math.min( len, bip ));
if( n == -1 ) {
return tot > 0 ? tot : -1;
}
tot += n;
off += n;
len -= n;
bip -= n;
if( len == 0 ) {
return tot;
}
}
switch( SessionServicePacket.readPacketType( in, header, 0 )) {
case SessionServicePacket.SESSION_KEEP_ALIVE:
break;
case SessionServicePacket.SESSION_MESSAGE:
bip = SessionServicePacket.readLength( header, 0 );
break;
case -1:
if( tot > 0 ) {
return tot;
}
return -1;
}
}
| public synchronized long | skip(long numbytes)
if( numbytes <= 0 ) {
return 0;
}
long n = numbytes;
while( n > 0 ) {
int r = read( tmp, 0, (int)Math.min( (long)TMP_BUFFER_SIZE, n ));
if (r < 0) {
break;
}
n -= r;
}
return numbytes - n;
|
|