Serializes the {@code message} into an {@link OutputStream} via {@link MsgpackXOutput} with the supplied buffer.
175596
public static <T extends Message<T>> void writeTo(OutputStream out, T message, boolean numeric,
            LinkedBuffer buffer)
            throws IOException
    {
        writeTo(out, message, message.cachedSchema(), numeric, buffer);
    }
141592
@Override
    public void serialize(Message message, OutputStream out) throws IOException {
        String name = names.get(message.getClass());
        if (name == null) {
            throw new Error("BitcoinSerializer doesn't currently know how to serialize " + message.getClass());
        }
        serialize(name, message.bitcoinSerialize(), out);
    }
6144
public void encode(OutputStream out) throws IOException {
        // Nothing for default
        if (version == V1) {
            return;
        }
        DerOutputStream tmp = new DerOutputStream();
        tmp.putInteger(version);

        DerOutputStream seq = new DerOutputStream();
        seq.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0),
                  tmp);

        out.write(seq.toByteArray());
    }
66526
@Override
    public void serialize(String name, byte[] message, OutputStream out) throws IOException {
        byte[] header = new byte[4 + COMMAND_LEN + 4 + 4 /* checksum */];
        uint32ToByteArrayBE(params.getPacketMagic(), header, 0);

        // The header array is initialized to zero by Java so we don't have to worry about
        // NULL terminating the string here.
        for (int i = 0; i < name.length() && i < COMMAND_LEN; i++) {
            header[4 + i] = (byte) (name.codePointAt(i) & 0xFF);
        }

        Utils.uint32ToByteArrayLE(message.length, header, 4 + COMMAND_LEN);

        byte[] hash = Sha256Hash.hashTwice(message);
        System.arraycopy(hash, 0, header, 4 + COMMAND_LEN + 4, 4);
        out.write(header);
        out.write(message);

        if (log.isDebugEnabled())
            log.debug("Sending {} message: {}", name, HEX.encode(header) + HEX.encode(message));
    }
341323
public static InputStream toInputStream(SOAPMessage msg){
        if(msg==null)
            return null;
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        try {
            msg.writeTo(os);
        } catch (Exception e) {
            throw S1SystemError.wrap(e);
        }
        return new ByteArrayInputStream(os.toByteArray());
    }
562638
public static <T extends Serializable> void serializeToStream(T obj, OutputStream out) throws IOException
	{
		ObjectOutputStream objOut;

		if(out instanceof ObjectOutputStream)
			objOut = (ObjectOutputStream)out;
		else
			objOut = new ObjectOutputStream(out);
		objOut.writeObject(obj);
		objOut.close();
	}
192361
private static void serialize(Serializable object, OutputStream output) throws IOException {
        BufferedOutputStream bos = new BufferedOutputStream(output);
        ObjectOutputStream oos = new ObjectOutputStream(bos);
        oos.writeObject(object);
        bos.flush();
    }
1026421
public static void writeTo(ByteBuffer buffer, OutputStream out) throws IOException {
        if (buffer.hasArray()) {
            out.write(buffer.array(), buffer.arrayOffset() + buffer.position(), buffer.remaining());
            // update buffer position, in way similar to non-array version of writeTo
            buffer.position(buffer.position() + buffer.remaining());
        } else {
            byte[] bytes = new byte[TEMP_BUFFER_SIZE];
            while (buffer.hasRemaining()) {
                int byteCountToWrite = Math.min(buffer.remaining(), TEMP_BUFFER_SIZE);
                buffer.get(bytes, 0, byteCountToWrite);
                out.write(bytes, 0, byteCountToWrite);
            }
        }
    }
602973
public void transmit(Object message) {
		try {
			boolean commandFlushed = false;
			byte[] b = (byte[]) message;
			for (int i = 0; i < b.length; i++) {
				byte b2 = b[i];
				if ((b2 == 10 || b2 == 13) && !commandFlushed) //NEWLINE / RETURN
				{
					commandFlushed = true;
					if ("exit".equals(command.toString().trim())) {
						close();
					}
					else {
						command.append((char) 10);//.append((char)13);
						proc.getOutputStream().write(command.toString().getBytes());
						proc.getOutputStream().flush();
						command = new StringBuffer();
					}
				}
				else// if (b2 != 13)
				{
					command = command.append((char) b2);
				}
			}
		}
		catch (IOException e) {
//			e.printStackTrace();
			close();
		}
	}
129620
public static <T> int writeListTo(OutputStream out, List<T> messages, Schema<T> schema,
            LinkedBuffer buffer) throws IOException
    {
        if (buffer.start != buffer.offset)
            throw new IllegalArgumentException("Buffer previously used and had not been reset.");

        final ProtobufOutput output = new ProtobufOutput(buffer);
        int totalSize = 0;
        for (T m : messages)
        {
            schema.writeTo(output, m);
            final int size = output.getSize();
            ProtobufOutput.writeRawVarInt32Bytes(out, size);
            final int msgSize = LinkedBuffer.writeTo(out, buffer);

            assert size == msgSize;

            totalSize += size;
            output.clear();
        }
        return totalSize;
    }
606026
public static void serializeTo( AbstractPacket packet , RawDataBuffer out )
    {
        out.writeByte(packet.getType());
        packet.serializeTo(out);
    }
1222564
public static <T> void writeTo(MessageBufferOutput out, T message, Schema<T> schema, boolean numeric)
            throws IOException
    {

        MessagePacker packer = MessagePack.newDefaultPacker(out);

        try
        {
            writeTo(packer, message, schema, numeric);
        }
        finally
        {
            packer.flush();
        }
    }
573326
public static int writeDelimitedTo(DataOutput out, Object message, Schema schema) 
    throws IOException
    {
        final LinkedBuffer buffer = new LinkedBuffer(LinkedBuffer.MIN_BUFFER_SIZE);
        final ProtobufOutput output = new ProtobufOutput(buffer);
        schema.writeTo(output, message);
        final int size = output.getSize();
        ProtobufOutput.writeRawVarInt32Bytes(out, size);
        
        LinkedBuffer.writeTo(out, buffer);
        //final int msgSize = LinkedBuffer.writeTo(out, buffer);
        //assert size == msgSize;
        
        return size;
    }
858301
public static Writer getOutputStreamWriter(OutputStream out) {
    try {
      return new OutputStreamWriter(out, "UTF-8");
    }
    catch (UnsupportedEncodingException ex) {
      throw new RuntimeException(ex); // shouldn't happen since UTF-8 is supported by all JVMs per spec
    }
  }
640751
public static void writeToOutputStream(String s, OutputStream output) throws IOException {
		writeToOutputStream(s, output, null);
	}
217172
private static void writeField(final OutputStream out, final byte[] bytes)
      throws IOException {
    // All protocol messages are prefixed with their length in bytes, encoded
    // as a 32 bit unsigned integer.
    final ByteBuffer buffer = ByteBuffer.allocate(INT_BYTES + bytes.length);
    buffer.putInt(bytes.length);
    buffer.put(bytes);
    out.write(buffer.array());
    out.flush();
  }
166575
@Override
    @SuppressWarnings("unchecked")
    public void onMessage(StreamMessage message)
    {
        String endopointUri = getEndpointUri();

        Map<String, Object> resultMap;

        try
        {
            resultMap = this.converter.toMap(message);
        }
        catch (ConvertFailException ex)
        {
            String logFormat = "Fail convert to jdbc record. Dispose received message. : Message={0}";
            logger.warn(MessageFormat.format(logFormat, message), ex);
            ack();
            return;
        }

        List<Object> valueList = Lists.newArrayList();

        valueList.add(resultMap.get("messageId"));
        valueList.add(resultMap.get("timestamp"));
        valueList.add(resultMap.get("source"));

        List<String> bodyList = (List<String>) resultMap.get("body");

        valueList.addAll(bodyList);

        insert(endopointUri, valueList);
        ack();
    }