class ByteEntityProvider implements EntityProvider<byte[]> {

    @Override
    public byte[] readFrom(Class<byte[]> type,
                           Type genericType,
                           Annotation[] annotations,
                           MediaType mediaType,
                           MultivaluedMap<String, String> httpHeaders,
                           InputStream entityStream) throws IOException {
        int length = getContentLength(httpHeaders);
        ByteArrayOutputStream out = length > 0 ? new NoSyncByteArrayOutputStream(length) : new NoSyncByteArrayOutputStream();
        ByteStreams.copy(entityStream, out);
        return out.toByteArray();
    }

}