@Test public void testReadInputStream() throws IOException { final InputStream input = new ByteArrayInputStream(new byte[1]); final InputStream result = EntityUtils.readEntity(InputStream.class, null, null, null, null, input); assertEquals(input, result); }
@SuppressWarnings("unchecked") public static <T> T readEntity( final Class<T> entityClass, final Type genericType, final Annotation[] annotations, final MediaType mediaType, final MinijaxRequestContext context, final InputStream entityStream) throws IOException { if (entityClass == InputStream.class) { return (T) entityStream; } if (entityClass == String.class) { return (T) IOUtils.toString(entityStream, StandardCharsets.UTF_8); } if (context != null) { final MinijaxApplicationContext appCtx = context.getApplicationContext(); final MessageBodyReader<T> reader = appCtx.getProviders().getMessageBodyReader( entityClass, genericType, annotations, mediaType); if (reader != null) { return reader.readFrom( entityClass, genericType, annotations, mediaType, context.getHeaders(), entityStream); } } throw new MinijaxException("Unknown entity type (" + entityClass + ")"); }
EntityUtils { @SuppressWarnings("unchecked") public static <T> T readEntity( final Class<T> entityClass, final Type genericType, final Annotation[] annotations, final MediaType mediaType, final MinijaxRequestContext context, final InputStream entityStream) throws IOException { if (entityClass == InputStream.class) { return (T) entityStream; } if (entityClass == String.class) { return (T) IOUtils.toString(entityStream, StandardCharsets.UTF_8); } if (context != null) { final MinijaxApplicationContext appCtx = context.getApplicationContext(); final MessageBodyReader<T> reader = appCtx.getProviders().getMessageBodyReader( entityClass, genericType, annotations, mediaType); if (reader != null) { return reader.readFrom( entityClass, genericType, annotations, mediaType, context.getHeaders(), entityStream); } } throw new MinijaxException("Unknown entity type (" + entityClass + ")"); } }
EntityUtils { @SuppressWarnings("unchecked") public static <T> T readEntity( final Class<T> entityClass, final Type genericType, final Annotation[] annotations, final MediaType mediaType, final MinijaxRequestContext context, final InputStream entityStream) throws IOException { if (entityClass == InputStream.class) { return (T) entityStream; } if (entityClass == String.class) { return (T) IOUtils.toString(entityStream, StandardCharsets.UTF_8); } if (context != null) { final MinijaxApplicationContext appCtx = context.getApplicationContext(); final MessageBodyReader<T> reader = appCtx.getProviders().getMessageBodyReader( entityClass, genericType, annotations, mediaType); if (reader != null) { return reader.readFrom( entityClass, genericType, annotations, mediaType, context.getHeaders(), entityStream); } } throw new MinijaxException("Unknown entity type (" + entityClass + ")"); } EntityUtils(); }
EntityUtils { @SuppressWarnings("unchecked") public static <T> T readEntity( final Class<T> entityClass, final Type genericType, final Annotation[] annotations, final MediaType mediaType, final MinijaxRequestContext context, final InputStream entityStream) throws IOException { if (entityClass == InputStream.class) { return (T) entityStream; } if (entityClass == String.class) { return (T) IOUtils.toString(entityStream, StandardCharsets.UTF_8); } if (context != null) { final MinijaxApplicationContext appCtx = context.getApplicationContext(); final MessageBodyReader<T> reader = appCtx.getProviders().getMessageBodyReader( entityClass, genericType, annotations, mediaType); if (reader != null) { return reader.readFrom( entityClass, genericType, annotations, mediaType, context.getHeaders(), entityStream); } } throw new MinijaxException("Unknown entity type (" + entityClass + ")"); } EntityUtils(); @SuppressWarnings("unchecked") static T readEntity(
            final Class<T> entityClass,
            final Type genericType,
            final Annotation[] annotations,
            final MediaType mediaType,
            final MinijaxRequestContext context,
            final InputStream entityStream); @SuppressWarnings({ "rawtypes", "unchecked" }) static void writeEntity(
            final Object entity,
            final MediaType mediaType,
            final MinijaxApplicationContext context,
            final OutputStream outputStream); static InputStream writeEntity(
            final Entity<T> entity,
            final MinijaxApplicationContext context); }
EntityUtils { @SuppressWarnings("unchecked") public static <T> T readEntity( final Class<T> entityClass, final Type genericType, final Annotation[] annotations, final MediaType mediaType, final MinijaxRequestContext context, final InputStream entityStream) throws IOException { if (entityClass == InputStream.class) { return (T) entityStream; } if (entityClass == String.class) { return (T) IOUtils.toString(entityStream, StandardCharsets.UTF_8); } if (context != null) { final MinijaxApplicationContext appCtx = context.getApplicationContext(); final MessageBodyReader<T> reader = appCtx.getProviders().getMessageBodyReader( entityClass, genericType, annotations, mediaType); if (reader != null) { return reader.readFrom( entityClass, genericType, annotations, mediaType, context.getHeaders(), entityStream); } } throw new MinijaxException("Unknown entity type (" + entityClass + ")"); } EntityUtils(); @SuppressWarnings("unchecked") static T readEntity(
            final Class<T> entityClass,
            final Type genericType,
            final Annotation[] annotations,
            final MediaType mediaType,
            final MinijaxRequestContext context,
            final InputStream entityStream); @SuppressWarnings({ "rawtypes", "unchecked" }) static void writeEntity(
            final Object entity,
            final MediaType mediaType,
            final MinijaxApplicationContext context,
            final OutputStream outputStream); static InputStream writeEntity(
            final Entity<T> entity,
            final MinijaxApplicationContext context);  }