src/main/java/org/java_websocket/SocketChannelIOHelper.java
public static boolean batch( WebSocketImpl ws, ByteChannel sockchannel ) throws IOException {
		if (ws == null) {
			return false;
		}
		ByteBuffer buffer = ws.outQueue.peek();
		WrappedByteChannel c = null;

		if( buffer == null ) {
			if( sockchannel instanceof WrappedByteChannel ) {
				c = (WrappedByteChannel) sockchannel;
				if( c.isNeedWrite() ) {
					c.writeMore();
				}
			}
		} else {
			do {// FIXME writing as much as possible is unfair!!
				/*int written = */sockchannel.write( buffer );
				if( buffer.remaining() > 0 ) {
					return false;
				} else {
					ws.outQueue.poll(); // Buffer finished. Remove it.
					buffer = ws.outQueue.peek();
				}
			} while ( buffer != null );
		}

		if( ws.outQueue.isEmpty() && ws.isFlushAndClose() && ws.getDraft() != null && ws.getDraft().getRole() != null && ws.getDraft().getRole() == Role.SERVER ) {//
			ws.closeConnection();
		}
		return c == null || !((WrappedByteChannel) sockchannel).isNeedWrite();
	}
public static boolean batch( WebSocketImpl ws, ByteChannel sockchannel ) throws IOException {
		if (ws == null) {
			return false;
		}
		ByteBuffer buffer = ws.outQueue.peek();
		WrappedByteChannel c = null;

		if( buffer == null ) {
			if( sockchannel instanceof WrappedByteChannel ) {
				c = (WrappedByteChannel) sockchannel;
				if( c.isNeedWrite() ) {
					c.writeMore();
				}
			}
		} else {
			do {// FIXME writing as much as possible is unfair!!
				/*int written = */sockchannel.write( buffer );
				if( buffer.remaining() > 0 ) {
					return false;
				} else {
					ws.outQueue.poll(); // Buffer finished. Remove it.
					buffer = ws.outQueue.peek();
				}
			} while ( buffer != null );
		}

		if( ws.outQueue.isEmpty() && ws.isFlushAndClose() && ws.getDraft() != null && ws.getDraft().getRole() != null && ws.getDraft().getRole() == Role.SERVER ) {//
			ws.closeConnection();
		}
		return c == null || !((WrappedByteChannel) sockchannel).isNeedWrite();
	}
Returns whether the whole outQueue has been flushed
@param ws The WebSocketImpl associated with the channels
@param sockchannel The channel to write to
@throws IOException May be thrown by {@link WrappedByteChannel#writeMore()}
@return returns Whether there is more data to write