Example usage for com.google.common.net MediaType withParameter

List of usage examples for com.google.common.net MediaType withParameter

Introduction

In this page you can find the example usage for com.google.common.net MediaType withParameter.

Prototype

public MediaType withParameter(String attribute, String value) 

Source Link

Document

Replaces all parameters with the given attribute with a single parameter with the given value.

Usage

From source file:org.mule.module.apikit.RestContentTypeParser.java

@Deprecated
private static MediaType getMediaType(MimeType mimeType) {
    MediaType mediaType = MediaType.parse(mimeType.getType());
    return mediaType.withParameter("q", "1");
}

From source file:com.tinspx.util.net.MultipartBody.java

private MultipartBody setContentType(@NonNull MediaType contentType, @Nullable String boundary, boolean init) {
    if (boundary != null) {
        contentType = contentType.withParameter(BOUNDARY, boundary);
    } else {/* w  w w. j a  va2 s.c  o  m*/
        List<String> b = contentType.parameters().get(BOUNDARY);
        if (b.isEmpty()) {
            boundary = init ? generateBoundary() : this.boundary;
            contentType = contentType.withParameter(BOUNDARY, boundary);
        } else if (b.size() > 1) {
            throw new IllegalArgumentException(
                    String.format("type (%s) has multiple boundary parameters", contentType));
        } else {
            boundary = b.get(0);
        }
    }
    checkBoundary(boundary);
    boundaryBytes = CharUtils.encodeAscii(boundary);
    this.boundary = boundary;
    headers.replaceValues(HttpHeaders.CONTENT_TYPE, Collections.singleton(contentType.toString()));
    type = contentType;
    valid = false;
    return this;
}