/** * Creates a media type with the "text" type and the given subtype. * * @throws IllegalArgumentException if subtype is invalid */ static MediaType createTextType(String subtype) { return create(TEXT_TYPE, subtype); }
/** * Creates a media type with the "application" type and the given subtype. * * @throws IllegalArgumentException if subtype is invalid */ static MediaType createApplicationType(String subtype) { return create(APPLICATION_TYPE, subtype); }
/** * Creates a media type with the "image" type and the given subtype. * * @throws IllegalArgumentException if subtype is invalid */ static MediaType createImageType(String subtype) { return create(IMAGE_TYPE, subtype); }
/** * Creates a media type with the "audio" type and the given subtype. * * @throws IllegalArgumentException if subtype is invalid */ static MediaType createAudioType(String subtype) { return create(AUDIO_TYPE, subtype); }
/** * Creates a media type with the "video" type and the given subtype. * * @throws IllegalArgumentException if subtype is invalid */ static MediaType createVideoType(String subtype) { return create(VIDEO_TYPE, subtype); }
private static MediaType create(String subtype) { return MediaType.create("application", subtype); }
@Override protected Set<Entry> entries() { return ImmutableSet.of( new Entry("gproto", create("application", "grpc"), create("application", "grpc+proto")), new Entry("gjson", create("application", "grpc+json")), new Entry("gproto-web", create("application", "grpc-web+proto"), create("application", "grpc-web")), new Entry("gjson-web", create("application", "grpc-web+json"))); } }
/** * Returns a new instance with the same type and subtype as this instance, but without any * parameters. */ public MediaType withoutParameters() { return parameters.isEmpty() ? this : create(type, subtype); }
/** * Creates a new media type with the given type and subtype. * * @throws IllegalArgumentException if type or subtype is invalid or if a wildcard is used for the * type, but not the subtype. */ public static MediaType create(String type, String subtype) { MediaType mediaType = create(type, subtype, ImmutableListMultimap.of()); mediaType.parsedCharset = Optional.empty(); return mediaType; }
/** * <em>Replaces</em> all parameters with the given parameters. * * @throws IllegalArgumentException if any parameter or value is invalid */ public MediaType withParameters(Map<String, ? extends Iterable<String>> parameters) { final ImmutableListMultimap.Builder<String, String> builder = ImmutableListMultimap.builder(); for (Map.Entry<String, ? extends Iterable<String>> e : parameters.entrySet()) { final String k = e.getKey(); for (String v : e.getValue()) { builder.put(k, v); } } return create(type, subtype, builder.build()); }
return create(type, subtype, parameters.build()); } catch (IllegalStateException e) { throw new IllegalArgumentException("Could not parse '" + input + '\'', e);
private static MediaType create(String subtype) { return MediaType.create("application", subtype); }
private static MediaType create(String subtype) { return MediaType.create("application", subtype); }
private static MediaType create(String subtype) { return MediaType.create("application", subtype); }
@Override protected Set<Entry> entries() { return ImmutableSet.of( new Entry("gproto", create("application", "grpc"), create("application", "grpc+proto")), new Entry("gjson", create("application", "grpc+json")), new Entry("gproto-web", create("application", "grpc-web+proto"), create("application", "grpc-web")), new Entry("gjson-web", create("application", "grpc-web+json"))); } }