Write message to writer.

@param writer The binary writer.
@param message The message to write.
@param <Message> The message type.
@param <Field> The field type.
@return The number of bytes written.
@throws IOException If write failed.
971674
public static <Message extends PMessage<Message, Field>, Field extends PField>
    int writeMessage(BigEndianBinaryWriter writer, Message message)
            throws IOException {
        if (message instanceof BinaryWriter) {
            return ((BinaryWriter) message).writeBinary(writer);
        }

        int len = 0;
        if (message instanceof PUnion) {
            if (((PUnion) message).unionFieldIsSet()) {
                PField field = ((PUnion) message).unionField();
                len += writeFieldSpec(writer, forType(field.getDescriptor().getType()), field.getId());
                len += writeFieldValue(writer,
                                       message.get(field.getId()),
                                       field.getDescriptor());
            }
        } else {
            for (PField field : message.descriptor().getFields()) {
                if (message.has(field.getId())) {
                    len += writeFieldSpec(writer, forType(field.getDescriptor().getType()), field.getId());
                    len += writeFieldValue(writer,
                                           message.get(field.getId()),
                                           field.getDescriptor());
                }
            }
        }
        len += writer.writeUInt8(BinaryType.STOP);
        return len;
    }
1373514
public void writeHeader(Writer writer) throws IOException
    {
        if (_state != __MSG_EDITABLE) throw new IllegalStateException("Not MSG_EDITABLE");

        _state = __MSG_BAD;
        writeRequestLine(writer);
        writer.write(HttpFields.__CRLF);
        _header.write(writer);
        _state = __MSG_SENDING;
    }
1345257
@Override
  public void write(final T message) {
    LOG.log(Level.FINEST, "write {0} :: {1}", new Object[] {channel, message});
    final ChannelFuture future = channel.writeAndFlush(Unpooled.wrappedBuffer(encoder.encode(message)));
    if (listener !=  null) {
      future.addListener(new NettyChannelFutureListener<>(message, listener));
    }
  }
626294
public void write(Writer out)
         throws IOException
    {
        for (int i=0; i <elements.size() ; i++)
        {
            Object element = elements.get(i);
          
            if (element instanceof Element)
                ((Element)element).write(out);
            else if (element==null)
                out.write("null");
            else 
                out.write(element.toString());
        }
    }
109517
public static void write(Message message, File toFile) {
    OutputStream out = null;
    try {
      out = new BufferedOutputStream(new FileOutputStream(toFile, false));
      message.writeTo(out);
    } catch (Exception e) {
      throw ContextException.of("Unable to write message", e).addContext("file", toFile);
    } finally {
      IOUtils.closeQuietly(out);
    }
  }
371783
@Override
  public void write(int b) throws IOException {
    if (!writtenHeader) {
      writeHeader();
      writtenHeader = true;
    }
    cipherStream.write(b);
  }
368568
public void toRfc5425SyslogMessage(Writer out) throws IOException {

        String rfc5424Message = toRfc5424SyslogMessage();
        int length = rfc5424Message.getBytes(StandardCharsets.UTF_8).length;
        out.write(String.valueOf(length));
        out.write(SP);
        out.write(rfc5424Message);
    }
328919
public void write(Writer out)
         throws IOException
    {
        if (reader==null)
            return;
        
        try{
            IO.copy(reader,out);
        }
        finally
        {
            reader.close();
            reader=null;
        }
    }
919786
private void write(final DataInputStream stream, final Writer outputWriter, final int numberOfBytes)
      throws IOException {
    final byte[] buf = new byte[65535];
    int lenRemaining = numberOfBytes;
    while (lenRemaining > 0) {
      final int len = stream.read(buf, 0, lenRemaining > 65535 ? 65535 : lenRemaining);
      if (len > 0) {
        outputWriter.write(new String(buf, 0, len, "UTF-8"));
        lenRemaining -= len;
      } else {
        break;
      }
    }
  }
804350
public static <T> void writeTo(XMLStreamWriter writer, T message, Schema<T> schema)
            throws IOException, XMLStreamException, XmlOutputException
    {
        writer.writeStartElement(schema.messageName());

        schema.writeTo(new XmlOutput(writer, schema), message);

        writer.writeEndElement();
    }
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();
  }
93849
public void write(Writer writer) throws IOException {
    final Properties properties = new Properties();

    for (Map.Entry<DictionaryAttribute, String> e : getAttributes().entrySet()) {
      properties.setProperty(e.getKey().propertyName, e.getValue());
    }

    properties.store(writer, "# " + getClass().getName());
  }
1134969
@Override
	public int writeTo(BitWriter writer) {
		if (writer == null) throw new IllegalArgumentException("null writer");
		return writer.write(bits, 64);
	}
1372447
@Override
	public void writeBytes(byte[] value, int offset, int length) throws JMSException
    {
        try
        {
            getOutput().write(value,offset,length);
        }
        catch (IOException e)
        {
            throw new FFMQException("Cannot write message body","IO_ERROR",e);
        }
    }
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
                }
            }
        }
    }
423060
@Override
    public final void write(final byte[] b) throws IOException {
        file.write(b);
        counter = counter + b.length;
    }
868758
public void writeMessageSetTo(final CodedOutputStream output)
                                throws IOException {
    for (int i = 0; i < fields.getNumArrayEntries(); i++) {
      writeMessageSetTo(fields.getArrayEntryAt(i), output);
    }
    for (final Map.Entry<FieldDescriptorType, Object> entry :
             fields.getOverflowEntries()) {
      writeMessageSetTo(entry, output);
    }
  }