# Class HttpMediaType (2.1.0)

<button class="button button-with-icon cloud-select-dropdown__button " aria-haspopup="true">Version latest</button>

- [2.1.0 (latest)](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.HttpMediaType)
- [2.0.3](https://docs.cloud.google.com/java/docs/reference/google-http-client/2.0.3/com.google.api.client.http.HttpMediaType)
- [1.47.1](https://docs.cloud.google.com/java/docs/reference/google-http-client/1.47.1/com.google.api.client.http.HttpMediaType)
- [1.46.3](https://docs.cloud.google.com/java/docs/reference/google-http-client/1.46.3/com.google.api.client.http.HttpMediaType)
- [1.45.3](https://docs.cloud.google.com/java/docs/reference/google-http-client/1.45.3/com.google.api.client.http.HttpMediaType)
- [1.44.2](https://docs.cloud.google.com/java/docs/reference/google-http-client/1.44.2/com.google.api.client.http.HttpMediaType)
- [1.43.2](https://docs.cloud.google.com/java/docs/reference/google-http-client/1.43.2/com.google.api.client.http.HttpMediaType)
- [1.42.3](https://docs.cloud.google.com/java/docs/reference/google-http-client/1.42.3/com.google.api.client.http.HttpMediaType)
- [1.41.8](https://docs.cloud.google.com/java/docs/reference/google-http-client/1.41.8/com.google.api.client.http.HttpMediaType)

    public final class HttpMediaType

HTTP Media-type as specified in the [HTTP RFC](https://datatracker.ietf.org/doc/html/rfc2616#section-3.7).

Implementation is not thread-safe.

## Inheritance

[Object](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html) \> HttpMediaType

## Inherited Members

[Object.clone()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#clone--) [Object.equals(Object)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#equals-java.lang.Object-) [Object.finalize()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#finalize--) [Object.getClass()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#getClass--) [Object.hashCode()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode--) [Object.notify()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notify--) [Object.notifyAll()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notifyAll--) [Object.toString()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#toString--) [Object.wait()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait--) [Object.wait(long)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-) [Object.wait(long,int)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-int-)

## Static Methods

### equalsIgnoreParameters(String mediaTypeA, String mediaTypeB)

    public static boolean equalsIgnoreParameters(String mediaTypeA, String mediaTypeB)

Returns `true` if the two specified media types have the same type and subtype, or if
both types are `null`.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `mediaTypeA` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |
| `mediaTypeB` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

## Constructors

### HttpMediaType(String mediaType)

    public HttpMediaType(String mediaType)

Creates a [HttpMediaType](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.HttpMediaType) by parsing the specified media type string.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `mediaType` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` full media type string, for example `"text/plain; charset=utf-8"` |

### HttpMediaType(String type, String subType)

    public HttpMediaType(String type, String subType)

Initializes the [HttpMediaType](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.HttpMediaType) by setting the specified media type.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `type` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` main media type, for example `"text"` |
| `subType` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` sub media type, for example `"plain"` |

## Methods

### build()

    public String build()

Builds the full media type string which can be passed in the Content-Type header.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |   |

### clearParameters()

    public void clearParameters()

Removes all set parameters from this media type.

### equals(Object obj)

    public boolean equals(Object obj)

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `obj` | `https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

**Overrides** [Object.equals(Object)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#equals-java.lang.Object-)

### equalsIgnoreParameters(HttpMediaType mediaType)

    public boolean equalsIgnoreParameters(HttpMediaType mediaType)

Returns `true` if the specified media type has both the same type and subtype, or `
false` if they don't match or the media type is `null`.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `mediaType` | `https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.HttpMediaType` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

### getCharsetParameter()

    public Charset getCharsetParameter()

Returns the specified charset or `null` if unset.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/nio/charset/Charset.html` |   |

### getParameter(String name)

    public String getParameter(String name)

Returns the value of the specified parameter or `null` if not found.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `name` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` name of the parameter |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |   |

### getParameters()

    public Map<String,String> getParameters()

Returns an unmodifiable map of all specified parameters. Parameter names will be stored in
lower-case in this map.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/util/Map.html<https://docs.oracle.com/javase/8/docs/api/java/lang/String.html,https://docs.oracle.com/javase/8/docs/api/java/lang/String.html>` |   |

### getSubType()

    public String getSubType()

Returns the sub media type, for example `"plain"` when using `"text"`.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |   |

### getType()

    public String getType()

Returns the main media type, for example `"text"`, or `null` for '\*'.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |   |

### hashCode()

    public int hashCode()

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

**Overrides** [Object.hashCode()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode--)

### removeParameter(String name)

    public HttpMediaType removeParameter(String name)

Removes the specified media parameter.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `name` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` parameter to remove |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.HttpMediaType` |   |

### setCharsetParameter(Charset charset)

    public HttpMediaType setCharsetParameter(Charset charset)

Sets the charset parameter of the media type.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `charset` | `https://docs.oracle.com/javase/8/docs/api/java/nio/charset/Charset.html` new value for the charset parameter or `null` to remove |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.HttpMediaType` |   |

### setParameter(String name, String value)

    public HttpMediaType setParameter(String name, String value)

Sets the media parameter to the specified value.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `name` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` case-insensitive name of the parameter |
| `value` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` value of the parameter or `null` to remove |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.HttpMediaType` |   |

### setSubType(String subType)

    public HttpMediaType setSubType(String subType)

Sets the sub media type, for example `"plain"` when using `"text"`.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `subType` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` sub media type |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.HttpMediaType` |   |

### setType(String type)

    public HttpMediaType setType(String type)

Sets the (main) media type, for example `"text"`.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `type` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` main/major media type |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.HttpMediaType` |   |

### toString()

    public String toString()

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |   |

**Overrides** [Object.toString()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#toString--)