Sends send the result of {@link Serializer#serialize(List)} to a destination.

@param buffer the bytes to send.
@param destination The peer to send to.
506359
private void send(final byte[] buffer, final Session destination) {
        synchronized (connections) {
            // execute asynchronously to avoid slower clients from interfering with faster clients
            final ExecutorService connectionThread = connectionThreads.get(destination);
            if (connectionThread == null) {
                // Maybe the client has disconnected in the mean time.
                return;
            }
            connectionThread.execute(new Runnable() {
                @Override
                public void run() {
                    try {
                        // for the case that the runnable was committed shortly before the connection was closed.
                        if (destination.isOpen()) {
                            // FIXME replace with getAsyncRemote and removeconnectionThreads as soon as
                            // getAsyncRemote on tomcat is thread-safe
                            destination.getBasicRemote().sendBinary(ByteBuffer.wrap(buffer));
                        }
                    } catch (final IOException e) {
                        try {
                            if (destination.isOpen()) {
                                destination.close(new CloseReason(CloseCodes.PROTOCOL_ERROR, "Failed to send data."));
                            }
                        } catch (final IOException e1) {
                            // The outer exception already indicated that something went wrong.
                            ignore(e1);
                        }
                        handleClientError(destination, e);
                        connectionCloses(destination);
                    }
                }
            });
        }
    }
410337
public static void writeBuffer(DataOutput out, ByteBuffer buffer) throws IOException {
        if (buffer.hasArray()) {
            out.write(buffer.array(), buffer.arrayOffset() + buffer.position(), buffer.remaining());
            buffer.position(buffer.limit());
        } else {
            final byte[] array = new byte[buffer.remaining()];
            buffer.get(array);
            assert buffer.remaining() == 0 && buffer.position() == buffer.limit();
            out.write(array);
        }
    }
937026
public void send(RoxPayload payload) {		
		try {
			if (isStarted()) {
				ByteArrayOutputStream baos = new ByteArrayOutputStream();

				new JsonSerializer().serializePayload(new OutputStreamWriter(baos), payload, false);

				socket.emit("payload", new String(baos.toByteArray()));
			}
			else {
				LOGGER.warn("Minirox is not available to send the test results");
			}
		}
		catch (Exception e) {
			LOGGER.warn("Unable to send the result to MINI ROX. Cause: {}", e.getMessage());
			
			if (LOGGER.isDebugEnabled()) {
				LOGGER.debug("Exception: ", e);
			}
		}
	}
1247379
public static void transfer(URLConnection c, byte[] bytes) throws IOException
    {
        try (OutputStream out = new BufferedOutputStream(c.getOutputStream()))
        {
            out.write(bytes);
        }
    }
908033
private void send(Message message, Destination destination, TestContext context) {
        if (log.isDebugEnabled()) {
            log.debug("Sending JMS message to destination: '" + endpointConfiguration.getDestinationName(destination) + "'");
        }

        endpointConfiguration.getJmsTemplate().send(destination, session -> {
            javax.jms.Message jmsMessage = endpointConfiguration.getMessageConverter().createJmsMessage(message, session, endpointConfiguration, context);
            endpointConfiguration.getMessageConverter().convertOutbound(jmsMessage, message, endpointConfiguration, context);
            return jmsMessage;
        });

        log.info("Message was sent to JMS destination: '" + endpointConfiguration.getDestinationName(destination) + "'");
    }
1337880
public void send(ByteArrayOutputStream bos) {
    try {
      if (this.isDisabled) {
        return;
      }
      if (available.tryAcquire(WAIT_NEXT_BUFFER_TIME_OUT_SECONDS, TimeUnit.SECONDS)) {
        tasks.add(sendExecutor.submit(new SendWorker(bos, segmentId++, false)));
      } else {
        setErrorStatus("Number of chunks in the queue to be send exceeded the configured number " 
             + maxBufferedChunks, null);
      }
    } catch (Exception e) {
      setErrorStatus("Exception when submitting a task", e);
    }
  }
1342018
public void send(byte[] buf) {
        if (log.isTraceEnabled()) {
            log.trace("send binary: {}", Arrays.toString(buf));
        }
        // send the incoming bytes
        send(Packet.build(buf));
    }
1086522
public void sendPing(byte[] buf) {
        if (log.isTraceEnabled()) {
            log.trace("send ping: {}", buf);
        }
        // send ping
        send(Packet.build(buf, MessageType.PING));
    }
520111
@Override
	protected void serializeTo(RawDataBuffer out)
    {
        super.serializeTo(out);
        out.writeInt(consumerId.asInt());
        DestinationSerializer.serializeTo(topic, out);
        out.writeNullableUTF(messageSelector);
        out.writeBoolean(noLocal);
        out.writeUTF(name);
    }
758958
private void sendMessage(BeanMessageID type, Buffer payload) {
        Buffer buffer = new Buffer();
        buffer.writeByte((type.getRawValue() >> 8) & 0xff);
        buffer.writeByte(type.getRawValue() & 0xff);
        if (payload != null) {
            try {
                buffer.writeAll(payload);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        GattSerialMessage serialMessage = GattSerialMessage.fromPayload(buffer.readByteArray());
        gattClient.getSerialProfile().sendMessage(serialMessage.getBuffer());
    }
502158
@Override
	public final void send(Message message, int deliveryMode, int priority, long timeToLive) throws JMSException
    {
    	if (this.destination == null)
    		throw new UnsupportedOperationException("Destination was not set at creation time");

        // Setup message fields
    	setupMessage(destination,message,deliveryMode,priority,timeToLive);
    	
    	// Handle foreign message implementations
        message = MessageTools.normalize(message);
        
    	sendToDestination(destination,false,message,deliveryMode,priority,timeToLive);
    }
432386
public void send(String channel, String message) {
		// CAUSE: Assignment to method parameter
		Pair<Boolean, String> sendValidation = isSendValid(channel, message, null, null);

		//String lMessage = message.replace("\n", "\\n");

		if (sendValidation != null && sendValidation.first) {
			try {
				String messageId = Strings.randomString(8);
				ArrayList<Pair<String, String>> messagesToSend = multiPartMessage(
						message, messageId);
				for (Pair<String, String> messageToSend : messagesToSend) {
					send(channel, messageToSend.second, messageToSend.first,
							sendValidation.second);
				}
			} catch (IOException e) {
				raiseOrtcEvent(EventEnum.OnException, this, e);
			}
		}
	}
888067
public void sendSerialMessage(byte[] value) {
        Buffer buffer = new Buffer();
        buffer.write(value);
        sendMessage(BeanMessageID.SERIAL_DATA, buffer);
    }
404836
@Override
	protected void serializeTo(RawDataBuffer out)
    {
    	super.serializeTo(out);
    	if (deliveredMessageIDs != null)
        {
    		int len = deliveredMessageIDs.size(); 
            out.writeInt(len);
            for (int i = 0; i < len; i++)
            	out.writeUTF(deliveredMessageIDs.get(i));
        }
        else
            out.writeInt(0);
    }
922087
@Override
    public void write(ByteBuffer buffer) {
//        if (obj instanceof Persistable)
//            ((Persistable) obj).write(buffer);
//        else {
        if (obj != null)
            buffer.put(getSerialized());
        tmpBuffer = null;
//        }
    }
606026
public static void serializeTo( AbstractPacket packet , RawDataBuffer out )
    {
        out.writeByte(packet.getType());
        packet.serializeTo(out);
    }
188019
@Override
    public int read(final ByteBuffer destination) throws IOException {

        // Precondition checks
        this.checkClosed();
        if (destination == null) {
            throw new IllegalArgumentException("Destination buffer must be supplied");
        }

        // Init
        final int spaceInBuffer = destination.remaining();
        final int numBytesRemainingInContent, numBytesToRead;

        // Sync up before getting at shared mutable state
        synchronized (this) {
            numBytesRemainingInContent = this.contents.length - this.position;

            // Set position was greater than the size? Just return.
            if (numBytesRemainingInContent <= 0) {
                return -1;
            }

            // We'll read in either the number of bytes remaining in content or the amount of space in the buffer,
            // whichever is smaller
            numBytesToRead = numBytesRemainingInContent >= spaceInBuffer ? spaceInBuffer : numBytesRemainingInContent;
            // Copy a sub-array of the bytes we'll put into the buffer
            destination.put(this.contents, this.position, numBytesToRead);

            // Set the new position
            this.position += numBytesToRead;
        }

        // Return the number of bytes read
        return numBytesToRead;
    }