Serializes the {@code messages} (delimited) into an {@link OutputStream}
using the given schema.

@return the bytes written
423095
public static int writeListTo(final OutputStream out, final Vector messages, 
            final Schema schema, final LinkedBuffer buffer) throws IOException
    {
        if(buffer.start != buffer.offset)
            throw new IllegalArgumentException("Buffer previously used and had not been reset.");
        
        final int size = messages.size();
        if(size == 0)
            return 0;
        
        final ProtostuffOutput output = new ProtostuffOutput(buffer, out);
        output.sink.writeVarInt32(size, output, buffer);

        for(int i = 0; i < messages.size(); i++)
        {
        	Object m = messages.elementAt(i);
            schema.writeTo(output, m);
            output.sink.writeByte((byte)WireFormat.WIRETYPE_TAIL_DELIMITER, output, 
                    buffer);
        }
        
        LinkedBuffer.writeTo(out, buffer);
        
        return output.size;
    }
1196436
public static <T> int writeTo(LinkedBuffer buffer, T message, Schema<T> schema)
    {
        if (buffer.start != buffer.offset)
            throw new IllegalArgumentException("Buffer previously used and had not been reset.");

        final ProtobufOutput output = new ProtobufOutput(buffer);
        try
        {
            schema.writeTo(output, message);
        }
        catch (IOException e)
        {
            throw new RuntimeException("Serializing to a LinkedBuffer threw an IOException " +
                    "(should never happen).", e);
        }

        return output.getSize();
    }
148091
public static <T> int writeTo(OutputStream out, T message, Schema<T> schema,
            LinkedBuffer buffer) throws IOException
    {
        if (buffer.start != buffer.offset)
            throw new IllegalArgumentException("Buffer previously used and had not been reset.");

        final YamlOutput output = new YamlOutput(buffer, out, schema);

        output.tail = YamlOutput.writeTag(
                schema.messageName(),
                false,
                output.sink,
                output,
                output.sink.writeByteArray(
                        START_DIRECTIVE,
                        output,
                        buffer));

        schema.writeTo(output, message);

        LinkedBuffer.writeTo(out, buffer);

        return output.getSize();
    }
1329508
public byte[] toBytes(final DefinedRuntimes definedRuntimes){
    final DatumWriter<DefinedRuntimes> configurationWriter =
            new SpecificDatumWriter<>(DefinedRuntimes.class);
    try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) {
      final BinaryEncoder binaryEncoder = EncoderFactory.get().binaryEncoder(out, null);
      configurationWriter.write(definedRuntimes, binaryEncoder);
      binaryEncoder.flush();
      out.flush();
      return out.toByteArray();
    } catch (final IOException e) {
      throw new RuntimeException("Unable to serialize DefinedRuntimes", e);
    }
  }
35076
public static int writeTo(OutputStream out, Object message, Schema 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);
        schema.writeTo(output, message);
        return LinkedBuffer.writeTo(out, buffer);
    }
1247706
public static <T> byte[] toByteArray(T message, Schema<T> schema, boolean numeric)
    {
        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
        try
        {
            writeTo(baos, message, schema, numeric);
        }
        catch (IOException e)
        {
            throw new RuntimeException("Serializing to a byte array threw an IOException " +
                    "(should never happen).", e);
        }
        return baos.toByteArray();
    }
787755
@Override
	public ByteArray encodeAsByteArray() throws IOException {
		final int size = messages.size();
		if(size == 0) return ByteArray.EMPTY_BYTE_ARRAY;

		AoByteArrayOutputStream bout = new AoByteArrayOutputStream();
		try {
			try (DataOutputStream out = new DataOutputStream(bout)) {
				out.writeInt(size);
				int count = 0;
				for(Message message : messages) {
					count++;
					ByteArray byteArray = message.encodeAsByteArray();
					final int capacity = byteArray.size;
					out.writeByte(message.getMessageType().getTypeByte());
					out.writeInt(capacity);
					out.write(byteArray.array, 0, capacity);
				}
				if(count != size) throw new ConcurrentModificationException();
			}
		} finally {
			bout.close();
		}
		return new ByteArray(bout.getInternalByteArray(), bout.size());
	}
1083334
public static <T> void writeListTo(OutputStream out, List<T> messages, Schema<T> schema)
            throws IOException
    {
        writeListTo(out, messages, schema, DEFAULT_OUTPUT_FACTORY);
    }
769518
@Override
    public void serialize(Map<MetadataType, MetadataComponent> components, DataOutputPlus out) throws IOException
    {
        ValidationMetadata validation = (ValidationMetadata) components.get(MetadataType.VALIDATION);
        StatsMetadata stats = (StatsMetadata) components.get(MetadataType.STATS);
        CompactionMetadata compaction = (CompactionMetadata) components.get(MetadataType.COMPACTION);

        assert validation != null && stats != null && compaction != null && validation.partitioner != null;

        EstimatedHistogram.serializer.serialize(stats.estimatedRowSize, out);
        EstimatedHistogram.serializer.serialize(stats.estimatedColumnCount, out);
        ReplayPosition.serializer.serialize(stats.replayPosition, out);
        out.writeLong(stats.minTimestamp);
        out.writeLong(stats.maxTimestamp);
        out.writeInt(stats.maxLocalDeletionTime);
        out.writeDouble(validation.bloomFilterFPChance);
        out.writeDouble(stats.compressionRatio);
        out.writeUTF(validation.partitioner);
        out.writeInt(compaction.ancestors.size());
        for (Integer g : compaction.ancestors)
            out.writeInt(g);
        StreamingHistogram.serializer.serialize(stats.estimatedTombstoneDropTime, out);
        out.writeInt(stats.sstableLevel);
        out.writeInt(stats.minColumnNames.size());
        for (ByteBuffer columnName : stats.minColumnNames)
            ByteBufferUtil.writeWithShortLength(columnName, out);
        out.writeInt(stats.maxColumnNames.size());
        for (ByteBuffer columnName : stats.maxColumnNames)
            ByteBufferUtil.writeWithShortLength(columnName, out);
    }
580364
public byte[] write(final SpecificRecord message, final long sequence) {

    final String classId = getClassId(message.getClass());
    try (final ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {

      LOG.log(Level.FINEST, "Serializing message: {0}", classId);

      final IMessageSerializer serializer = this.nameToSerializerMap.get(classId);
      if (serializer != null) {
        serializer.serialize(outputStream, message, sequence);
      }

      return outputStream.toByteArray();

    } catch (final IOException e) {
      throw new RuntimeException("Failure writing message: " + classId, e);
    }
  }
232584
private byte[] getBytesFromStream(final InputStream dstream)
			throws IOException {
		final ByteArrayOutputStream baos = new ByteArrayOutputStream();
		final byte[] buffer = new byte[1024];
		int read;
		while ((read = dstream.read(buffer)) > 0) {
			baos.write(buffer, 0, read);
		}
		return baos.toByteArray();
	}
359704
static JmsMessageImpl messageToJmsMessageImpl(Message message) throws JMSException {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(tc, "messageToJmsMessageImpl", message);

        JmsMessageImpl jmsMessage = null;

        if (message instanceof BytesMessage) {
            jmsMessage = new JmsBytesMessageImpl((BytesMessage) message);
        }
        else if (message instanceof MapMessage) {
            jmsMessage = new JmsMapMessageImpl((MapMessage) message);
        }
        else if (message instanceof ObjectMessage) {
            jmsMessage = new JmsObjectMessageImpl((ObjectMessage) message);
        }
        else if (message instanceof StreamMessage) {
            jmsMessage = new JmsStreamMessageImpl((StreamMessage) message);
        }
        else if (message instanceof TextMessage) {
            jmsMessage = new JmsTextMessageImpl((TextMessage) message);
        }
        else if (message instanceof Message) {
            jmsMessage = new JmsMessageImpl(message);
        }

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(tc, "messageToJmsMessageImpl", jmsMessage);
        return jmsMessage;
    }
459504
static int mergeDelimitedFrom(DataInput in, Object message, Schema schema, 
            boolean decodeNestedMessageAsGroup) throws IOException
    {
        final byte size = in.readByte();
        final int len = 0 == (size & 0x80) ? size : CodedInput.readRawVarint32(in, size);
        
        if(len < 0)
            throw ProtobufException.negativeSize();
        
        if(len != 0)
        {
            // not an empty message
            if(len > CodedInput.DEFAULT_BUFFER_SIZE && in instanceof InputStream)
            {
                // message too big
                final CodedInput input = new CodedInput(new LimitedInputStream((InputStream)in, len), 
                        decodeNestedMessageAsGroup);
                schema.mergeFrom(input, message);
                input.checkLastTagWas(0);
            }
            else
            {
                final byte[] buf = new byte[len];
                in.readFully(buf, 0, len);
                final ByteArrayInput input = new ByteArrayInput(buf, 0, len, 
                        decodeNestedMessageAsGroup);
                try
                {
                    schema.mergeFrom(input, message);
                }
                catch(ArrayIndexOutOfBoundsException e)
                {
                    throw ProtobufException.truncatedMessage(e);
                }
                input.checkLastTagWas(0);
            }
        }

        // check it since this message is embedded in the DataInput.
        if(!schema.isInitialized(message))
            throw new UninitializedMessageException(message, schema);
        
        return len;
    }
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();
        }
    }
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);
    }
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;
    }
1065831
public static <T> int writeListTo(final OutputStream out, final List<T> messages, 
            final Schema<T> schema, final LinkedBuffer buffer) throws IOException
    {
        if(buffer.start != buffer.offset)
            throw new IllegalArgumentException("Buffer previously used and had not been reset.");
        
        final int size = messages.size();
        if(size == 0)
            return 0;
        
        final ProtostuffOutput output = new ProtostuffOutput(buffer, out);
        output.sink.writeVarInt32(size, output, buffer);

        for(T m : messages)
        {
            schema.writeTo(output, m);
            output.sink.writeByte((byte)WireFormat.WIRETYPE_TAIL_DELIMITER, output, 
                    buffer);
        }
        
        LinkedBuffer.writeTo(out, buffer);
        
        return output.size;
    }