### Question:
BinaryDataProvider extends AbstractConfigurableProvider implements MessageBodyReader<T>, MessageBodyWriter<T> { public void writeTo(T o, Class<?> clazz, Type genericType, Annotation[] annotations, MediaType type, MultivaluedMap<String, Object> headers, OutputStream os) throws IOException { if (InputStream.class.isAssignableFrom(o.getClass())) { copyInputToOutput((InputStream)o, os, annotations, headers); } else if (File.class.isAssignableFrom(o.getClass())) { copyInputToOutput(new BufferedInputStream( Files.newInputStream(((File)o).toPath())), os, annotations, headers); } else if (byte[].class.isAssignableFrom(o.getClass())) { copyInputToOutput(new ByteArrayInputStream((byte[])o), os, annotations, headers); } else if (Reader.class.isAssignableFrom(o.getClass())) { try { Writer writer = new OutputStreamWriter(os, getEncoding(type)); IOUtils.copy((Reader)o, writer, bufferSize); writer.flush(); } finally { ((Reader)o).close(); } } else if (StreamingOutput.class.isAssignableFrom(o.getClass())) { ((StreamingOutput)o).write(os); } else { throw new IOException("Unrecognized class"); } }  boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mt); T readFrom(Class<T> clazz, Type genericType, Annotation[] annotations, MediaType type,
                           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 o, Class<?> clazz, Type genericType, Annotation[] annotations,
                        MediaType type, MultivaluedMap<String, Object> headers, OutputStream os); void setReportByteArraySize(boolean report); void setCloseResponseInputStream(boolean closeResponseInputStream); void setBufferSize(int bufferSize);  }### Answer:
@SuppressWarnings({ "unchecked", "rawtypes" }) @Test public void testWriteTo() throws Exception { MessageBodyWriter p = new BinaryDataProvider(); ByteArrayOutputStream os = new ByteArrayOutputStream(); p.writeTo(new byte[]{'h', 'i'}, null, null, null, null, null, os); assertArrayEquals(new String("hi").getBytes(), os.toByteArray()); ByteArrayInputStream is = new ByteArrayInputStream("hi".getBytes()); os = new ByteArrayOutputStream(); p.writeTo(is, null, null, null, null, null, os); assertArrayEquals(os.toByteArray(), new String("hi").getBytes()); Reader r = new StringReader("hi"); os = new ByteArrayOutputStream(); p.writeTo(r, null, null, null, MediaType.valueOf("text/xml"), null, os); assertArrayEquals(os.toByteArray(), new String("hi").getBytes()); os = new ByteArrayOutputStream(); p.writeTo(new StreamingOutputImpl(), null, null, null, MediaType.valueOf("text/xml"), null, os); assertArrayEquals(os.toByteArray(), new String("hi").getBytes()); }