Methods Summary |
---|
private void | checkClosed()
if (closed) {
throw new IOException("Stream is closed");
}
if (sock.isOutputShutdown()) {
throw new IOException("Output Shutdown");
}
|
public void | close()
if (closed) {
return;
}
closed = true;
try {
selector.close();
selector = null;
sc = null;
} catch (Exception ie) {
if ( logger.isLoggable(Level.FINE) ) {
logger.log(Level.FINE, "" + ie.getMessage(), ie);
}
}
|
protected void | finalize()
try {
close();
} catch (Throwable t) {}
|
public void | flush()
checkClosed();
|
private void | waitForSelect()
java.net.Socket sock = sc.socket();
if (sock.isClosed()) {
close();
throw new IOException("Socket closed");
}
Iterator it;
SelectionKey selKey;
selectorblock:
while (true) {
try {
selector.select();
if (sock.isOutputShutdown() || sock.isClosed()) {
throw new IOException("Output Shutdown");
}
it = selector.selectedKeys().iterator();
while (it.hasNext()) {
selKey = (SelectionKey)it.next();
if (selKey.isValid() && selKey.isWritable()) {
it.remove();
break selectorblock;
}
}
} catch (Exception e) {
throw (IOException) (new IOException()).initCause(e);
}
}
|
public synchronized void | write(int b)
if (b1 == null)
b1 = new byte[1];
b1[0] = (byte)b;
this.write(b1);
|
public synchronized void | write(byte[] bs, int off, int len)
checkClosed();
if ((off < 0) || (off > bs.length) || (len < 0) ||
((off + len) > bs.length) || ((off + len) < 0)) {
throw new IndexOutOfBoundsException();
} else if (len == 0) {
return;
}
ByteBuffer bb = ((this.bs == bs)
? this.bb
: ByteBuffer.wrap(bs));
bb.limit(Math.min(off + len, bb.capacity()));
bb.position(off);
this.bb = bb;
this.bs = bs;
waitForSelect();
while (bb.hasRemaining()) {
sc.write(bb);
}
|