Freigeben über


ByteArrayOutputStream.ToString Method

Definition

Overloads

ToString(Charset)

Converts the buffer's contents into a string by decoding the bytes using the specified java.nio.charset.Charset charset.

ToString(Int32)
Obsolete.

Creates a newly allocated string.

ToString(String)

Converts the buffer's contents into a string by decoding the bytes using the named java.nio.charset.Charset charset.

ToString(Charset)

Converts the buffer's contents into a string by decoding the bytes using the specified java.nio.charset.Charset charset.

[Android.Runtime.Register("toString", "(Ljava/nio/charset/Charset;)Ljava/lang/String;", "GetToString_Ljava_nio_charset_Charset_Handler", ApiSince=33)]
public virtual string ToString (Java.Nio.Charset.Charset charset);
[<Android.Runtime.Register("toString", "(Ljava/nio/charset/Charset;)Ljava/lang/String;", "GetToString_Ljava_nio_charset_Charset_Handler", ApiSince=33)>]
override this.ToString : Java.Nio.Charset.Charset -> string

Parameters

charset
Charset

the java.nio.charset.Charset charset to be used to decode the bytes

Returns

String decoded from the buffer's contents.

Attributes

Remarks

Converts the buffer's contents into a string by decoding the bytes using the specified java.nio.charset.Charset charset. The length of the new String is a function of the charset, and hence may not be equal to the length of the byte array.

This method always replaces malformed-input and unmappable-character sequences with the charset's default replacement string. The java.nio.charset.CharsetDecoder class should be used when more control over the decoding process is required.

Added in 10.

Java documentation for java.io.ByteArrayOutputStream.toString(java.nio.charset.Charset).

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

ToString(Int32)

Caution

deprecated

Creates a newly allocated string.

[Android.Runtime.Register("toString", "(I)Ljava/lang/String;", "GetToString_IHandler")]
[System.Obsolete("deprecated")]
public virtual string ToString (int hibyte);
[<Android.Runtime.Register("toString", "(I)Ljava/lang/String;", "GetToString_IHandler")>]
[<System.Obsolete("deprecated")>]
override this.ToString : int -> string

Parameters

hibyte
Int32

the high byte of each resulting Unicode character.

Returns

the current contents of the output stream, as a string.

Attributes

Remarks

Creates a newly allocated string. Its size is the current size of the output stream and the valid contents of the buffer have been copied into it. Each character c in the resulting string is constructed from the corresponding element b in the byte array such that: <blockquote>

{@code
                c == (char)(((hibyte & 0xff) << 8) | (b & 0xff))
            }

</blockquote>

This member is deprecated. This method does not properly convert bytes into characters. As of JDK&nbsp;1.1, the preferred way to do this is via the #toString(String charsetName) or #toString(Charset charset) method, which takes an encoding-name or charset argument, or the toString() method, which uses the platform's default character encoding.

Java documentation for java.io.ByteArrayOutputStream.toString(int).

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

ToString(String)

Converts the buffer's contents into a string by decoding the bytes using the named java.nio.charset.Charset charset.

[Android.Runtime.Register("toString", "(Ljava/lang/String;)Ljava/lang/String;", "GetToString_Ljava_lang_String_Handler")]
public virtual string ToString (string charsetName);
[<Android.Runtime.Register("toString", "(Ljava/lang/String;)Ljava/lang/String;", "GetToString_Ljava_lang_String_Handler")>]
override this.ToString : string -> string

Parameters

charsetName
String

the name of a supported java.nio.charset.Charset charset

Returns

String decoded from the buffer's contents.

Attributes

Exceptions

if the provided encoding is not supported.

Remarks

Converts the buffer's contents into a string by decoding the bytes using the named java.nio.charset.Charset charset.

This method is equivalent to #toString(charset) that takes a java.nio.charset.Charset charset.

An invocation of this method of the form

{@code
                 ByteArrayOutputStream b = ...
                 b.toString("UTF-8")
                 }

behaves in exactly the same way as the expression

{@code
                 ByteArrayOutputStream b = ...
                 b.toString(StandardCharsets.UTF_8)
                 }

Added in 1.1.

Java documentation for java.io.ByteArrayOutputStream.toString(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