public static void write(SelectionKey key) throws IOException {
		loggerServer.info("WRITE: ");

		SocketChannel socketChannel = (SocketChannel) key.channel();

		ArrayList<byte[]> wbuf = null;
		int offset;
		int toWrite;
		
		synchronized(key) {
			wbuf = writeBuffers.get(key);

			while (wbuf.size() > 0) {
				byte[] bbuf = wbuf.get(0);
				wbuf.remove(0);
				
				//write all the array
				if (bbuf.length < NetworkInfo.BUF_SIZE) {
					wBuffer.clear();
					wBuffer.put(bbuf);
					wBuffer.flip();
				} else {
					//write only the size of the buffer
					offset = 0;
					toWrite = (bbuf.length - offset < NetworkInfo.BUF_SIZE)? bbuf.length - offset: NetworkInfo.BUF_SIZE;
					wBuffer.clear();
					wBuffer.put(bbuf, offset, toWrite);
					wBuffer.flip();
				}
	
				int numWritten = socketChannel.write(wBuffer);
				loggerServer.info("wrote " + numWritten + " bytes on the socket associated with the key" + key);
	
				if (numWritten < bbuf.length) {
					byte[] newBuf = new byte[bbuf.length - numWritten];
	
					// Copy data which is still unwritten into newBuf
					for (int i = numWritten; i < bbuf.length; i++) {
						newBuf[i - numWritten] = bbuf[i];
					}
					
					wbuf.add(0, newBuf);
					break;
				}
			}
			
			if (wbuf.size() == 0) {
				key.interestOps(SelectionKey.OP_READ);
			}
		}
	}