public Charset getCharset ( Charset defaultCharset ) { String contentType = getHeader ( HttpHeaders . NAME_CONTENT_TYPE ) ; if ( contentType == null ) { return defaultCharset ; } String [ ] items = contentType . split ( ";" ) ; for ( String item : items ) { item = item . trim ( ) ; if ( item . isEmpty ( ) ) { continue ; } int idx = item . indexOf ( ' ' ) ; if ( idx < 0 ) { continue ; } String key = item . substring ( 0 , idx ) . trim ( ) ; if ( key . equalsIgnoreCase ( "charset" ) ) { try { return Charset . forName ( item . substring ( idx + 1 ) . trim ( ) ) ; } catch ( IllegalCharsetNameException | UnsupportedCharsetException e ) { return defaultCharset ; } } } return defaultCharset ; }
Get charset set in content type header .