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");
}
}