public static Object convertTextToText ( Object source , MediaType sourceType , MediaType destinationType ) { if ( source == null ) return null ; if ( sourceType == null ) throw new NullPointerException ( "MediaType cannot be null!" ) ; if ( ! sourceType . match ( MediaType . TEXT_PLAIN ) ) throw log . invalidMediaType ( TEXT_PLAIN_TYPE , sourceType . toString ( ) ) ; boolean asString = destinationType . hasStringType ( ) ; Charset sourceCharset = sourceType . getCharset ( ) ; Charset destinationCharset = destinationType . getCharset ( ) ; if ( sourceCharset . equals ( destinationCharset ) ) return convertTextClass ( source , destinationType , asString ) ; byte [ ] byteContent = source instanceof byte [ ] ? ( byte [ ] ) source : source . toString ( ) . getBytes ( sourceCharset ) ; return convertTextClass ( convertCharset ( byteContent , sourceCharset , destinationCharset ) , destinationType , asString ) ; }
Convert text content to a different encoding .