@Test public void testWriteInputStream() throws IOException { final InputStream input = new ByteArrayInputStream(new byte[1]); assertEquals(input, EntityUtils.writeEntity(Entity.entity(input, "text/plain"), null)); }
@SuppressWarnings({ "rawtypes", "unchecked" }) public static void writeEntity( final Object entity, final MediaType mediaType, final MinijaxApplicationContext context, final OutputStream outputStream) throws IOException { if (entity == null) { return; } if (entity instanceof byte[]) { outputStream.write((byte[]) entity); return; } if (entity instanceof InputStream) { IOUtils.copy((InputStream) entity, outputStream); return; } if (entity instanceof String) { outputStream.write(((String) entity).getBytes(StandardCharsets.UTF_8)); return; } if (entity instanceof Form) { final String str = UrlUtils.urlEncodeMultivaluedParams(((Form) entity).asMap()); outputStream.write(str.getBytes(StandardCharsets.UTF_8)); return; } if (entity instanceof Multipart) { MultipartUtils.serializeMultipartForm((Multipart) entity, outputStream); return; } if (context != null) { final MinijaxProviders providers = context.getProviders(); final MessageBodyWriter writer = providers.getMessageBodyWriter(entity.getClass(), null, null, mediaType); if (writer != null) { writer.writeTo(entity, entity.getClass(), null, null, mediaType, null, outputStream); return; } } throw new MinijaxException("No writer found for " + entity.getClass() + " and " + mediaType); }
EntityUtils { @SuppressWarnings({ "rawtypes", "unchecked" }) public static void writeEntity( final Object entity, final MediaType mediaType, final MinijaxApplicationContext context, final OutputStream outputStream) throws IOException { if (entity == null) { return; } if (entity instanceof byte[]) { outputStream.write((byte[]) entity); return; } if (entity instanceof InputStream) { IOUtils.copy((InputStream) entity, outputStream); return; } if (entity instanceof String) { outputStream.write(((String) entity).getBytes(StandardCharsets.UTF_8)); return; } if (entity instanceof Form) { final String str = UrlUtils.urlEncodeMultivaluedParams(((Form) entity).asMap()); outputStream.write(str.getBytes(StandardCharsets.UTF_8)); return; } if (entity instanceof Multipart) { MultipartUtils.serializeMultipartForm((Multipart) entity, outputStream); return; } if (context != null) { final MinijaxProviders providers = context.getProviders(); final MessageBodyWriter writer = providers.getMessageBodyWriter(entity.getClass(), null, null, mediaType); if (writer != null) { writer.writeTo(entity, entity.getClass(), null, null, mediaType, null, outputStream); return; } } throw new MinijaxException("No writer found for " + entity.getClass() + " and " + mediaType); } }
EntityUtils { @SuppressWarnings({ "rawtypes", "unchecked" }) public static void writeEntity( final Object entity, final MediaType mediaType, final MinijaxApplicationContext context, final OutputStream outputStream) throws IOException { if (entity == null) { return; } if (entity instanceof byte[]) { outputStream.write((byte[]) entity); return; } if (entity instanceof InputStream) { IOUtils.copy((InputStream) entity, outputStream); return; } if (entity instanceof String) { outputStream.write(((String) entity).getBytes(StandardCharsets.UTF_8)); return; } if (entity instanceof Form) { final String str = UrlUtils.urlEncodeMultivaluedParams(((Form) entity).asMap()); outputStream.write(str.getBytes(StandardCharsets.UTF_8)); return; } if (entity instanceof Multipart) { MultipartUtils.serializeMultipartForm((Multipart) entity, outputStream); return; } if (context != null) { final MinijaxProviders providers = context.getProviders(); final MessageBodyWriter writer = providers.getMessageBodyWriter(entity.getClass(), null, null, mediaType); if (writer != null) { writer.writeTo(entity, entity.getClass(), null, null, mediaType, null, outputStream); return; } } throw new MinijaxException("No writer found for " + entity.getClass() + " and " + mediaType); } EntityUtils(); }
EntityUtils { @SuppressWarnings({ "rawtypes", "unchecked" }) public static void writeEntity( final Object entity, final MediaType mediaType, final MinijaxApplicationContext context, final OutputStream outputStream) throws IOException { if (entity == null) { return; } if (entity instanceof byte[]) { outputStream.write((byte[]) entity); return; } if (entity instanceof InputStream) { IOUtils.copy((InputStream) entity, outputStream); return; } if (entity instanceof String) { outputStream.write(((String) entity).getBytes(StandardCharsets.UTF_8)); return; } if (entity instanceof Form) { final String str = UrlUtils.urlEncodeMultivaluedParams(((Form) entity).asMap()); outputStream.write(str.getBytes(StandardCharsets.UTF_8)); return; } if (entity instanceof Multipart) { MultipartUtils.serializeMultipartForm((Multipart) entity, outputStream); return; } if (context != null) { final MinijaxProviders providers = context.getProviders(); final MessageBodyWriter writer = providers.getMessageBodyWriter(entity.getClass(), null, null, mediaType); if (writer != null) { writer.writeTo(entity, entity.getClass(), null, null, mediaType, null, outputStream); return; } } throw new MinijaxException("No writer found for " + entity.getClass() + " and " + mediaType); } 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({ "rawtypes", "unchecked" }) public static void writeEntity( final Object entity, final MediaType mediaType, final MinijaxApplicationContext context, final OutputStream outputStream) throws IOException { if (entity == null) { return; } if (entity instanceof byte[]) { outputStream.write((byte[]) entity); return; } if (entity instanceof InputStream) { IOUtils.copy((InputStream) entity, outputStream); return; } if (entity instanceof String) { outputStream.write(((String) entity).getBytes(StandardCharsets.UTF_8)); return; } if (entity instanceof Form) { final String str = UrlUtils.urlEncodeMultivaluedParams(((Form) entity).asMap()); outputStream.write(str.getBytes(StandardCharsets.UTF_8)); return; } if (entity instanceof Multipart) { MultipartUtils.serializeMultipartForm((Multipart) entity, outputStream); return; } if (context != null) { final MinijaxProviders providers = context.getProviders(); final MessageBodyWriter writer = providers.getMessageBodyWriter(entity.getClass(), null, null, mediaType); if (writer != null) { writer.writeTo(entity, entity.getClass(), null, null, mediaType, null, outputStream); return; } } throw new MinijaxException("No writer found for " + entity.getClass() + " and " + mediaType); } 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);  }