Condividi tramite


IDataOutput.WriteUTF(String) Method

Definition

Writes two bytes of length information to the output stream, followed by the modified UTF-8 representation of every character in the string s.

[Android.Runtime.Register("writeUTF", "(Ljava/lang/String;)V", "GetWriteUTF_Ljava_lang_String_Handler:Java.IO.IDataOutputInvoker, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null")]
public void WriteUTF (string? s);
[<Android.Runtime.Register("writeUTF", "(Ljava/lang/String;)V", "GetWriteUTF_Ljava_lang_String_Handler:Java.IO.IDataOutputInvoker, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null")>]
abstract member WriteUTF : string -> unit

Parameters

s
String

the string value to be written.

Attributes

Exceptions

if an I/O error occurs while writing.

Remarks

Writes two bytes of length information to the output stream, followed by the modified UTF-8 representation of every character in the string s. If s is null, a NullPointerException is thrown. Each character in the string s is converted to a group of one, two, or three bytes, depending on the value of the character.

If a character c is in the range &#92;u0001 through &#92;u007f, it is represented by one byte:

(byte)c

If a character c is &#92;u0000 or is in the range &#92;u0080 through &#92;u07ff, then it is represented by two bytes, to be written in the order shown:

{@code
            (byte)(0xc0 | (0x1f & (c >> 6)))
            (byte)(0x80 | (0x3f & c))
            }

If a character c is in the range &#92;u0800 through uffff, then it is represented by three bytes, to be written in the order shown:

{@code
            (byte)(0xe0 | (0x0f & (c >> 12)))
            (byte)(0x80 | (0x3f & (c >>  6)))
            (byte)(0x80 | (0x3f & c))
            }

First, the total number of bytes needed to represent all the characters of s is calculated. If this number is larger than 65535, then a UTFDataFormatException is thrown. Otherwise, this length is written to the output stream in exactly the manner of the writeShort method; after this, the one-, two-, or three-byte representation of each character in the string s is written.

The bytes written by this method may be read by the readUTF method of interface DataInput , which will then return a String equal to s.

Java documentation for java.io.DataOutput.writeUTF(java.lang.String).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

See also