/** * Return a string representation of the given list of {@code MediaType} objects. * * <p>This method can be used to for an {@code Accept} or {@code Content-Type} header. * * @param mediaTypes the string to parse * @return the list of media types * @throws IllegalArgumentException if the String cannot be parsed */ public static String toString(Collection<MediaType> mediaTypes) { StringBuilder builder = new StringBuilder(); for (Iterator<MediaType> iterator = mediaTypes.iterator(); iterator.hasNext(); ) { MediaType mediaType = iterator.next(); mediaType.appendTo(builder); if (iterator.hasNext()) { builder.append(", "); } } return builder.toString(); }
private void appendTo(StringBuilder builder) { builder.append(this.type); builder.append('/'); builder.append(this.subtype); appendTo(this.parameters, builder); }
@Override public String toString() { StringBuilder builder = new StringBuilder(); appendTo(builder); return builder.toString(); }