@Test public void testOctetStreamToTextConversion() { String text = "Have you ever retired a human by mistake?"; byte[] bytes1 = text.getBytes(); byte[] bytes2 = new byte[]{1, 2, 3}; byte[] result1 = StandardConversions.convertOctetStreamToText(bytes1, TEXT_PLAIN.withCharset(US_ASCII)); byte[] result2 = StandardConversions.convertOctetStreamToText(bytes2, TEXT_PLAIN); assertArrayEquals(text.getBytes(US_ASCII), result1); assertArrayEquals(new String(bytes2).getBytes(UTF_8), result2); }
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); }