URLConnection.GuessContentTypeFromStream(Stream) Method

Definition

Tries to determine the type of an input stream based on the characters at the beginning of the input stream.

[Android.Runtime.Register("guessContentTypeFromStream", "(Ljava/io/InputStream;)Ljava/lang/String;", "")]
public static string? GuessContentTypeFromStream (System.IO.Stream? is);
[<Android.Runtime.Register("guessContentTypeFromStream", "(Ljava/io/InputStream;)Ljava/lang/String;", "")>]
static member GuessContentTypeFromStream : System.IO.Stream -> string

Parameters

is
Stream

an input stream that supports marks.

Returns

a guess at the content type, or null if none can be determined.

Attributes

Exceptions

if an I/O error occurs while reading from the input stream.

Remarks

Tries to determine the type of an input stream based on the characters at the beginning of the input stream. This method can be used by subclasses that override the getContentType method.

Ideally, this routine would not be needed. But many http servers return the incorrect content type; in addition, there are many nonstandard extensions. Direct inspection of the bytes to determine the content type is often more accurate than believing the content type claimed by the http server.

Java documentation for java.net.URLConnection.guessContentTypeFromStream(java.io.InputStream).

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