Writes variable-length string to a data buffer or IO stream.
 If data is given, appends to a data.
 If stream is given, writes to a stream.
 Returns the binary representation of the var-length string.
964775
def write_string(string, data: nil, stream: nil)
      raise ArgumentError, "String must be present" if !string

      intbuf = write_varint(string.bytesize, data: data, stream: stream)

      stringbuf = BTC::Data.ensure_binary_encoding(string)

      data << stringbuf if data
      stream.write(stringbuf) if stream

      intbuf + stringbuf
    end
241805
def write(self, buf):
        """"""
        if not isinstance(buf, six.binary_type):
            raise TypeError('buf: must be a bytes instance')
        # Be careful not to write zero-length chunks as they indicate the end of a body.
        if len(buf) == 0:
            return
        if self._content_length and self._bytes_written > self._content_length:
            raise RuntimeError('wrote too many bytes ({} > {})'
                                    .format(self._bytes_written, self._content_length))
        self._bytes_written += len(buf)
        if self._chunked:
            buf = create_chunk(buf)
        self._protocol.writer.write(buf)
1244666
public static void writeUTF8WithLength(OutputStream out, String str) throws IOException {
        byte[] s = str.getBytes(UTF8);
        writeInt4(out, s.length);
        out.write(s);
    }
715054
function stringToBuffer(str) {
    var buf = new Buffer(str.length);
    for (var i = 0; i < buf.length; i++) {
      buf.writeUInt8(str.charCodeAt(i), i);
    }
    return buf;
  }
252017
public void writeBytes(byte[] buffer, int offset, int length)
        throws IOException
    {
        if (buffer == null) {
            if (SIZE < _offset + 16)
                flushBuffer();

            _buffer[_offset++] = (byte) 'N';
        }
        else {
            while (SIZE - _offset - 3 < length) {
                int sublen = SIZE - _offset - 3;

                if (sublen < 16) {
                    flushBuffer();

                    sublen = SIZE - _offset - 3;

                    if (length < sublen)
                        sublen = length;
                }

                _buffer[_offset++] = (byte) BC_BINARY_CHUNK;
                _buffer[_offset++] = (byte) (sublen >> 8);
                _buffer[_offset++] = (byte) sublen;

                System.arraycopy(buffer, offset, _buffer, _offset, sublen);
                _offset += sublen;

                length -= sublen;
                offset += sublen;

                flushBuffer();
            }

            if (SIZE < _offset + 16)
                flushBuffer();

            if (length <= BINARY_DIRECT_MAX) {
                _buffer[_offset++] = (byte) (BC_BINARY_DIRECT + length);
            }
            else if (length <= BINARY_SHORT_MAX) {
                _buffer[_offset++] = (byte) (BC_BINARY_SHORT + (length >> 8));
                _buffer[_offset++] = (byte) (length);
            }
            else {
                _buffer[_offset++] = (byte) 'B';
                _buffer[_offset++] = (byte) (length >> 8);
                _buffer[_offset++] = (byte) (length);
            }

            System.arraycopy(buffer, offset, _buffer, _offset, length);

            _offset += length;
        }
    }
683498
@Override
    public void write(DataOutput out)
            throws IOException {
        ensureTextSet();
        // Write a variable int with the length
        WritableUtils.writeVInt(out, _text.limit());
        // Write the bytes.  For efficiency directly access the buffer's array.
        out.write(_text.array(), 0, _text.limit());
    }
1233424
def make_var_string(string):
    
    s = None
    if isinstance(string, str) and re.match('^[0-9a-fA-F]*$', string):
        # convert from hex to bin, safely
        s = binascii.unhexlify(string)
    else:
        s = string[:]

    buf = encoding.num_to_var_int(len(s)) + s
    return buf.encode('hex')
1311993
public static void writeString(String value, ByteBuffer buf) {
        if (value == null) {
            buf.putInt(VoltType.NULL_STRING_LENGTH);
            return;
        }

        byte[] strbytes = value.getBytes(Constants.UTF8ENCODING);
        int len = strbytes.length;

        buf.putInt(len);
        buf.put(strbytes);
    }
865541
public void writeStringSmallLength(byte[] value) {
    int length = value.length;
    while (remaining() < length + 1) {
      grow();
    }
    buf[position++] = (byte) length;
    System.arraycopy(value, 0, buf, position, length);
    position += length;
  }
444730
@Override
	public void writeShort(short v) throws IOException {
		outputStream.write(0xFF & v);
		outputStream.write(0xFF & (v >> 8));
		bytesWritten += 2;
	}
293860
def write_as_string
      @stream = StringIO.new
      write_init(@linker.cpu_init)
      write_debug
      write_objects
      write_code
      log.debug "Assembled 0x#{stream_position.to_s(16)} bytes"
      return @stream.string
    end
696554
@Override
	public void write(char[] cbuf, int off, int len) throws IOException {
		for (int count = 0; count < len; ++off, ++count) {
			char c = cbuf[off];

			switch (state) {
			case TEXT:
				if (c == '$') {
					state = State.VARIABLE_MARK;
				} else {
					targetWriter.write(c);
				}
				break;

			case VARIABLE_MARK:
				if (c == '{') {
					state = State.VARIABLE;
					variableBuilder.setLength(0);
				} else {
					targetWriter.write('$');
					targetWriter.write(c);
					state = State.TEXT;
				}
				break;

			case VARIABLE:
				if (c == '}') {
					String variable = variables.get(variableBuilder.toString());
					if (variable == null) {
						// if variable not found it should be an internal variable used by processing file
						// for example ${BUILD} from ant files; copy as it is
						targetWriter.write("${");
						targetWriter.write(variableBuilder.toString());
						targetWriter.write('}');
					} else {
						targetWriter.write(variable);
					}
					state = State.TEXT;
				} else {
					variableBuilder.append(c);
				}
				break;

			default:
				throw new IllegalStateException();
			}
		}
	}
1091180
void write(Writable value) throws IOException {
    byte[] bval;
    int valSize;
    if (value instanceof BytesWritable) {
      BytesWritable val = (BytesWritable) value;
      bval = val.get();
      valSize = val.getSize();
    } else if (value instanceof Text) {
      Text val = (Text) value;
      bval = val.getBytes();
      valSize = val.getLength();
    } else {
      String sval = value.toString();
      bval = sval.getBytes("UTF-8");
      valSize = bval.length;
    }
    clientOut_.write(bval, 0, valSize);
  }
15932
def writeBytes(self, b):
        
        self.stream.write(TYPE_STRING)

        self.serialiseBytes(b)
1320098
def _read_stream_as_string(stream, encoding):
    
    output = io.BytesIO()
    try:
        for data in stream:
            output.write(data)
        if encoding is None:
            encoding = 'utf-8'
        return output.getvalue().decode(encoding)
    finally:
        output.close()
    raise RuntimeError('could not write data to stream or decode bytes')
107073
public int writeVarint(int varint) throws IOException {
        int b = 1;
        boolean c = (varint ^ (varint & 0x7f)) != 0;
        out.write((c ? 0x80 : 0x00) | (varint & 0x7f));
        while (c) {
            ++b;
            varint >>>= 7;
            c = (varint ^ (varint & 0x7f)) != 0;
            out.write((c ? 0x80 : 0x00) | (varint & 0x7f));
        }
        return b;
    }
874089
def write(self, b):
        """"""
        self._checkClosed()
        if isinstance(b, str):
            raise TypeError("can't write str to binary stream")

        with self._write_lock:
            self._write_buf.extend(b)
            self._flush_unlocked()
            return len(b)