### Question:
PrimitiveTextProvider extends AbstractConfigurableProvider implements MessageBodyReader<T>, MessageBodyWriter<T> { public T readFrom(Class<T> type, Type genType, Annotation[] anns, MediaType mt, MultivaluedMap<String, String> headers, InputStream is) throws IOException { String string = IOUtils.toString(is, HttpUtils.getEncoding(mt, StandardCharsets.UTF_8.name())); if (StringUtils.isEmpty(string)) { reportEmptyContentLength(); } if (type == Character.class) { char character = string.charAt(0); return type.cast(Character.valueOf(character)); } return InjectionUtils.handleParameter( string, false, type, genType, anns, ParameterType.REQUEST_BODY, null); }  boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mt); T readFrom(Class<T> type, Type genType, Annotation[] anns, MediaType mt,
                      MultivaluedMap<String, String> headers, InputStream is); long getSize(T t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mt); boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mt); void writeTo(T obj, Class<?> type, Type genType, Annotation[] anns,
                        MediaType mt, MultivaluedMap<String, Object> headers,
                        OutputStream os);  }### Answer:
@SuppressWarnings("unchecked") @Test public void testReadByte() throws Exception { MessageBodyReader<?> p = new PrimitiveTextProvider<>(); @SuppressWarnings("rawtypes") Byte valueRead = (Byte)p.readFrom((Class)Byte.TYPE, null, null, null, null, new ByteArrayInputStream("1".getBytes())); assertEquals(1, valueRead.byteValue()); }
@SuppressWarnings({ "unchecked", "rawtypes" }) @Test(expected = NoContentException.class) public void testReadEmptyByte() throws Exception { MessageBodyReader<?> p = new PrimitiveTextProvider<>(); p.readFrom((Class)Byte.TYPE, null, null, null, null, new ByteArrayInputStream("".getBytes())); }
@SuppressWarnings({ "unchecked", "rawtypes" }) @Test public void testReadBoolean() throws Exception { MessageBodyReader p = new PrimitiveTextProvider(); boolean valueRead = (Boolean)p.readFrom(Boolean.TYPE, null, null, null, null, new ByteArrayInputStream("true".getBytes())); assertTrue(valueRead); }
@Test public void testReadChineeseChars() throws Exception { String s = "中文"; MessageBodyReader<String> p = new PrimitiveTextProvider<>(); String value = p.readFrom(String.class, null, new Annotation[]{}, MediaType.valueOf(MediaType.APPLICATION_XML + ";charset=UTF-8"), null, new ByteArrayInputStream(s.getBytes(StandardCharsets.UTF_8))); assertEquals(s, value); }