private void write(SelectionKey key) throws IOException {
		SocketChannel socketChannel = (SocketChannel) key.channel();
		
		synchronized (this.pendingData){
			List queue = (List) this.pendingData.get(socketChannel);
			
			//write until there's no more data
			while(!queue.isEmpty()) {
				ByteBuffer buff = (ByteBuffer) queue.get(0);
				socketChannel.write(buff);
				if(buff.remaining() > 0){
					// or the socket's buffer is full
					break;
				}
				queue.remove(0);
			}
			if(queue.isEmpty()){
				// we wrote away all data, so we're not interested
				// in writing more data from this socket.
				//switch back to waiting
				key.interestOps(SelectionKey.OP_READ);
			}
		}
	}