Serializes the {@code message} into an {@link OutputStream} using the given {@code schema}.
170687
public static <T> void writeTo(OutputStream out, T message, Schema<T> schema,
            XMLOutputFactory outFactory) throws IOException
    {
        XMLStreamWriter writer = null;
        try
        {
            writer = outFactory.createXMLStreamWriter(out, XML_ENCODING);

            writer.writeStartDocument(XML_ENCODING, XML_VERSION);
            writeTo(writer, message, schema);
            writer.writeEndDocument();

            writer.flush();
        }
        catch (XMLStreamException e)
        {
            throw new XmlOutputException(e);
        }
        finally
        {
            if (writer != null)
            {
                try
                {
                    writer.close();
                }
                catch (XMLStreamException e)
                {
                    // ignore
                }
            }
        }
    }
369479
public static <T> void mergeFrom(byte[] data, T message, Schema<T> schema,
            boolean numeric) throws IOException
    {
        mergeFrom(data, 0, data.length, message, schema, numeric);
    }
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;
    }
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();
    }
1295033
public static String serialize(StreamSchema schema) {
    StringBuilder builder = new StringBuilder();
    int fieldCount = 1;
    for (GDATField field : schema.getFields()) {
      builder.append(field.getType().getTypeName()).append(" ").append(field.getName()).append(" get_gdat_")
        .append(field.getType().getTypeName()).append("_pos").append(fieldCount);
      builder.append(field.getSlidingWindowType().getAttribute());
      builder.append(";").append(Constants.NEWLINE);
      fieldCount++;
    }
    return builder.toString();
  }
534294
public static <T> void writeListTo(MessagePacker packer, List<T> messages,
            Schema<T> schema, boolean numeric) throws IOException
    {
        MsgpackGenerator generator = new MsgpackGenerator(numeric);
        MsgpackOutput output = new MsgpackOutput(generator, schema);

        for (T m : messages)
        {
            schema.writeTo(output, m);
            generator.writeTo(packer);
            generator.reset();
        }

    }
278268
public static <T> void writeListTo(XMLStreamWriter writer, List<T> messages, Schema<T> schema)
            throws IOException, XMLStreamException
    {
        writer.writeStartElement("list");

        if (messages.isEmpty())
        {
            writer.writeEndElement();
            return;
        }

        final String simpleName = schema.messageName();
        final XmlOutput output = new XmlOutput(writer, schema);
        for (T m : messages)
        {
            writer.writeStartElement(simpleName);
            schema.writeTo(output, m);
            writer.writeEndElement();
        }

        writer.writeEndElement();
    }
40476
public static <T> void mergeFrom(Reader r, T message, Schema<T> schema)
            throws IOException
    {
        mergeFrom(r, message, schema, DEFAULT_INPUT_FACTORY);
    }
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;
    }
143167
public <Message extends PMessage<Message, Field>, Field extends PField>
    void formatTo(OutputStream out, Message message) {
        IndentedPrintWriter builder = new IndentedPrintWriter(out, indent, newline);
        if (message == null) {
            builder.append(null);
        } else {
            builder.append(message.descriptor().getQualifiedName())
                   .append(space);
            appendMessage(builder, message);
        }
        builder.flush();
    }
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);
    }
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);
    }
651347
public static void mergeFrom(byte[] data, Object message, Schema schema)
    {
        mergeFrom(data, 0, data.length, message, schema);
    }
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);
    }
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());
    }
1216472
public static <T> int mergeDelimitedFrom(InputStream in, T message, Schema<T> schema)
            throws IOException
    {
        final int size = in.read();
        if (size == -1)
            throw ProtobufException.truncatedMessage();

        final int len = 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)
            {
                // message too big
                final CodedInput input = new CodedInput(new LimitedInputStream(in, len),
                        true);
                final GraphCodedInput graphInput = new GraphCodedInput(input);
                schema.mergeFrom(graphInput, message);
                input.checkLastTagWas(0);
                return len;
            }

            final byte[] buf = new byte[len];
            IOUtil.fillBufferFrom(in, buf, 0, len);
            final ByteArrayInput input = new ByteArrayInput(buf, 0, len,
                    true);
            final GraphByteArrayInput graphInput = new GraphByteArrayInput(input);
            try
            {
                schema.mergeFrom(graphInput, message);
            }
            catch (ArrayIndexOutOfBoundsException e)
            {
                throw ProtobufException.truncatedMessage(e);
            }
            input.checkLastTagWas(0);
        }

        return len;
    }
744166
private static void serializeDocToStream(final OutputStream output, final Document doc) throws IOException {
        final OutputFormat format = OutputFormat.createPrettyPrint();
        final XMLWriter writer = new XMLWriter(output, format);
        writer.write(doc);
        writer.flush();
    }