public static Object convertUrlEncodedToText(Object content, MediaType destinationType) { return convertTextToText(urlDecode(content), TEXT_PLAIN, destinationType); }
@Test public void textToTextConversion() { String source = "All those moments will be lost in time, like tears in rain."; byte[] sourceAs8859 = source.getBytes(ISO_8859_1); byte[] sourceAsASCII = source.getBytes(US_ASCII); Object result = StandardConversions.convertTextToText(sourceAs8859, TEXT_PLAIN.withCharset(ISO_8859_1), TEXT_PLAIN.withCharset(US_ASCII)); assertArrayEquals(sourceAsASCII, (byte[]) result); }
private Object convertToTextPlain(Object content, MediaType contentType, MediaType destinationType) { if (contentType.match(APPLICATION_UNKNOWN)) { try { return StandardConversions.convertJavaToOctetStream(content, APPLICATION_OBJECT, javaMarshaller); } catch (IOException | InterruptedException e) { throw log.unsupportedContent(content); } } if (contentType.match(APPLICATION_OCTET_STREAM)) { byte[] decoded = StandardConversions.decodeOctetStream(content, destinationType); return StandardConversions.convertOctetStreamToText(decoded, destinationType); } if (contentType.match(APPLICATION_OBJECT)) { return StandardConversions.convertJavaToText(content, contentType, destinationType); } if (contentType.match(TEXT_PLAIN)) { return StandardConversions.convertTextToText(content, contentType, destinationType); } if (contentType.match(APPLICATION_WWW_FORM_URLENCODED)) { return StandardConversions.convertUrlEncodedToText(content, destinationType); } throw log.unsupportedContent(content); }