public String getClassType() { return getParameter(CLASS_TYPE_PARAM_NAME).orElse(null); }
public Charset getCharset() { return getParameter(CHARSET_PARAM_NAME).map(Charset::forName).orElse(DEFAULT_CHARSET); }
/** * Decode a octet-stream content that is not a byte[]. For this, it uses a special * param called "encoding" in the "application/octet-stream" MediaType. * The "encoding" param supports only the "hex" value that represents an octet-stream * as a hexadecimal representation, for example "0xdeadbeef". * * In the absence of the "encoding" param, it will assume base64 encoding. * * @param input Object representing the binary content. * @param octetStream The MediaType describing the input. * @return a byte[] with the decoded content. */ public static byte[] decodeOctetStream(Object input, MediaType octetStream) { if (input == null) { throw new NullPointerException("input must not be null"); } if (input instanceof byte[]) return (byte[]) input; if (input instanceof String) { String encoding = octetStream.getParameter("encoding").orElse("hex"); String src = input.toString(); return encoding.equals("hex") ? hexToBytes(src) : getUrlDecoder().decode(src); } throw new EncodingException("Cannot decode binary content " + input.getClass()); }
private void assertMediaTypeWithParams(MediaType mediaType, String type, String subType, String[] paramNames, String[] paramValues) { assertEquals(type, mediaType.getType()); assertEquals(subType, mediaType.getSubType()); assertTrue(mediaType.hasParameters()); for (int i = 0; i < paramNames.length; i++) { String paramName = paramNames[i]; String paramValue = paramValues[i]; assertEquals(Optional.of(paramValue), mediaType.getParameter(paramName)); } }
private void assertMediaTypeNoParams(MediaType mediaType, String type, String subType) { assertEquals(type, mediaType.getType()); assertEquals(subType, mediaType.getSubType()); assertFalse(mediaType.hasParameters()); assertEquals(Optional.empty(), mediaType.getParameter("a")); }