public int write(ByteBuffer buffer) throws IOException {
        if (disconnected)
            return -1;    // TODO: not by the JavaDoc API spec
        if (throwExceptionOnSend)
            throw new IOException("text IO exception");
        // we could write remaining bytes, but for test this is enough
        if (buffer.remaining() > writeBuffer.remaining())
            return 0;
        int startPos = buffer.position();
        writeBuffer.put(buffer);
        return buffer.position() - startPos;
    }
public int write(ByteBuffer buffer) throws IOException {
        if (disconnected)
            return -1;   
        if (throwExceptionOnSend)
            throw new IOException("text IO exception");
       
        if (buffer.remaining() > writeBuffer.remaining())
            return 0;
        int startPos = buffer.position();
        writeBuffer.put(buffer);
        return buffer.position() - startPos;
    }
public int write(bytebuffer buffer) throws ioexception { if (disconnected) return -1; if (throwexceptiononsend) throw new ioexception("text io exception"); if (buffer.remaining() > writebuffer.remaining()) return 0; int startpos = buffer.position(); writebuffer.put(buffer); return buffer.position() - startpos; }