public static String toHeader ( final MediaType mediaType ) { requireNonNull ( mediaType , REFERENCE_MEDIA_TYPE_CANNOT_BE_NULL ) ; final StringBuilder builder = new StringBuilder ( ) . append ( mediaType . type ( ) . toLowerCase ( Locale . ENGLISH ) ) . append ( ' ' ) . append ( mediaType . subType ( ) . toLowerCase ( Locale . ENGLISH ) ) ; final String suffix = mediaType . suffix ( ) ; if ( suffix != null ) { builder . append ( ' ' ) . append ( suffix . toLowerCase ( Locale . ENGLISH ) ) ; } final Charset charset = mediaType . charset ( ) ; if ( charset != null ) { builder . append ( ";charset=" ) . append ( charset . name ( ) . toLowerCase ( Locale . ENGLISH ) ) ; } for ( Entry < String , String > entry : mediaType . parameters ( ) . entrySet ( ) ) { final String key = entry . getKey ( ) ; if ( isStandardParameter ( key ) ) { continue ; } builder . append ( ' ' ) . append ( key . toLowerCase ( Locale . ENGLISH ) ) . append ( ' ' ) . append ( entry . getValue ( ) ) ; } return builder . toString ( ) ; }
Format the media type in a HTTP - header compliant manner using preferred format .