Serialize a message to the given output stream
322785
public static void serializeTo( AbstractMessage message , RawDataBuffer out )
    {
        // Do we have a cached version of the raw message ?
    	RawDataBuffer rawMsg = message.getRawMessage();
        if (rawMsg != null)
        {
        	out.writeInt(rawMsg.size());
        	rawMsg.writeTo(out);
        }
        else
        {
            // Serialize the message
        	out.writeInt(0); // Write a dummy size
        	int startPos = out.size();
            out.writeByte(message.getType());
            message.serializeTo(out);
            int endPos = out.size();
            out.writeInt(endPos-startPos,startPos-4); // Update the actual size
        }
    }
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);
    }
1120389
def serialize(message):
        
        fmt = "!BBH"

        if message.token is None or message.token == "":
            tkl = 0
        else:
            tkl = len(message.token)
        tmp = (defines.VERSION << 2)
        tmp |= message.type
        tmp <<= 4
        tmp |= tkl

        values = [tmp, message.code, message.mid]

        if message.token is not None and tkl > 0:

            for b in str(message.token):
                fmt += "c"
                values.append(bytes(b, "utf-8"))

        options = Serializer.as_sorted_list(message.options)  # already sorted
        lastoptionnumber = 0
        for option in options:

            # write 4-bit option delta
            optiondelta = option.number - lastoptionnumber
            optiondeltanibble = Serializer.get_option_nibble(optiondelta)
            tmp = (optiondeltanibble << defines.OPTION_DELTA_BITS)

            # write 4-bit option length
            optionlength = option.length
            optionlengthnibble = Serializer.get_option_nibble(optionlength)
            tmp |= optionlengthnibble
            fmt += "B"
            values.append(tmp)

            # write extended option delta field (0 - 2 bytes)
            if optiondeltanibble == 13:
                fmt += "B"
                values.append(optiondelta - 13)
            elif optiondeltanibble == 14:
                fmt += "H"
                values.append(optiondelta - 269)

            # write extended option length field (0 - 2 bytes)
            if optionlengthnibble == 13:
                fmt += "B"
                values.append(optionlength - 13)
            elif optionlengthnibble == 14:
                fmt += "H"
                values.append(optionlength - 269)

            # write option value
            if optionlength > 0:
                opt_type = defines.OptionRegistry.LIST[option.number].value_type
                if opt_type == defines.INTEGER:
                    words = Serializer.int_to_words(option.value, optionlength, 8)
                    for num in range(0, optionlength):
                        fmt += "B"
                        values.append(words[num])
                elif opt_type == defines.STRING:
                    fmt += str(len(bytes(option.value, "utf-8"))) + "s"
                    values.append(bytes(option.value, "utf-8"))

                else:  # OPAQUE
                    for b in option.value:
                        fmt += "B"
                        values.append(b)

            # update last option number
            lastoptionnumber = option.number

        payload = message.payload

        if payload is not None and len(payload) > 0:
            # if payload is present and of non-zero length, it is prefixed by
            # an one-byte Payload Marker (0xFF) which indicates the end of
            # options and the start of the payload

            fmt += "B"
            values.append(defines.PAYLOAD_MARKER)

            if isinstance(payload, bytes):
                fmt += str(len(payload)) + "s"
                values.append(payload)
            else:
                fmt += str(len(bytes(payload, "utf-8"))) + "s"
                values.append(bytes(payload, "utf-8"))
            # for b in str(payload):
            #     fmt += "c"
            #     values.append(bytes(b, "utf-8"))

        datagram = None
        if values[1] is None:
            values[1] = 0
        if values[2] is None:
            values[2] = 0
        try:
            s = struct.Struct(fmt)
            datagram = ctypes.create_string_buffer(s.size)
            s.pack_into(datagram, 0, *values)
        except struct.error:
            # The .exception method will report on the exception encountered
            # and provide a traceback.
            logger.debug(fmt)
            logger.debug(values)
            logging.exception('Failed to pack structure')

        return datagram
702292
@Override
    public void dump(OutputStream output) {
        try (PrintWriter out = new PrintWriter(new OutputStreamWriter(output, UTF_8))) {
            for (long value : values) {
                out.printf("%d%n", value);
            }
        }
    }
59198
public void writeToStream(OutputStream stream, Object object) throws SerializationException {
        try {
            mapper.writeValue(stream, object);
        } catch (IOException ex) {
            throw new SerializationException("Exception during serialization", ex);
        }
    }
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));
    }
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();
	}
315099
public static void serialize(OutputStream out, BloomKFilter bloomFilter) throws IOException
  {
    /**
     * Serialized BloomKFilter format:
     * 1 byte for the number of hash functions.
     * 1 big endian int(That is how OutputStream works) for the number of longs in the bitset
     * big endina longs in the BloomKFilter bitset
     */
    DataOutputStream dataOutputStream = new DataOutputStream(out);
    dataOutputStream.writeByte(bloomFilter.k);
    dataOutputStream.writeInt(bloomFilter.getBitSet().length);
    for (long value : bloomFilter.getBitSet()) {
      dataOutputStream.writeLong(value);
    }
  }
842827
@Override
	protected void serializeTo(RawDataBuffer out)
    {
        super.serializeTo(out);
        out.writeInt(browserId.asInt());
        DestinationSerializer.serializeTo(queue, out);
        out.writeNullableUTF(messageSelector);
    }
118535
public static void writeToOutputStream(String s, OutputStream output, String encoding) throws IOException {
		BufferedReader reader = new BufferedReader(new StringReader(s));
		PrintStream writer;
		if (encoding != null) {
			writer = new PrintStream(output, true, encoding);
		}
		else {
			writer = new PrintStream(output, true);
		}
		String line;
		while ((line = reader.readLine()) != null) {
			writer.println(line);
		}
	}
9540
def output_message(text, file=sys.stderr):
    """"""
    if file.encoding is None:
        # If the output file does not support Unicode, encode it to a byte
        # string. On some machines, this occurs when Python is redirecting to
        # file (or piping to something like Vim).
        text = text.encode('utf-8')

    print(text, file=file)
511687
def output(stream):
    """"""
    while True:
        content = stream.read(1024)
        if len(content) == 0: break
        sys.stdout.write(content)
215737
def serialize_message(self, message: SegmentSequence) -> bytes:
        """"""
        if isinstance(message, FinTS3Segment):
            message = SegmentSequence([message])
        if isinstance(message, (list, tuple, Iterable)):
            message = SegmentSequence(list(message))

        result = []

        for segment in message.segments:
            result.append(self.serialize_segment(segment))

        return self.implode_segments(result)
1091362
public void dump(YamlNode data, OutputStream output) {
        getDelegate().dump(data, new OutputStreamWriter(output, Charset
                                                        .forName("UTF-8")));
    }
766713
@GwtIncompatible("Unnecessary")
  private Writer streamToOutputWriter2(OutputStream stream) {
    if (outputCharset2 == null) {
      return new BufferedWriter(new OutputStreamWriter(stream, UTF_8));
    } else {
      return new BufferedWriter(
          new OutputStreamWriter(stream, outputCharset2));
    }
  }
476344
@GwtIncompatible("Unnecessary")
  private Writer streamToLegacyOutputWriter(OutputStream stream) throws IOException {
    if (legacyOutputCharset == null) {
      return new BufferedWriter(new OutputStreamWriter(stream, UTF_8));
    } else {
      return new BufferedWriter(
          new OutputStreamWriter(stream, legacyOutputCharset));
    }
  }
192956
public function serialize($resource, OutputStream $out): OutputStream
    {
        if (is_object($resource) && method_exists($resource, '__toString')) {
            $out->write((string) $resource);
        } elseif (is_object($resource) || is_array($resource)) {
            $out->write(var_export($resource, true));
        } elseif (is_bool($resource) && $resource) {
            $out->write('true');
        } elseif (is_bool($resource) && !$resource) {
            $out->write('false');
        } else {
            $out->write((string) $resource);
        }

        return $out;
    }