@Override
public ProtobufMessageHandler readFrom(Class<ProtobufMessageHandler> type, Type genericType,
Annotation[] annotations, MediaType mediaType,
MultivaluedMap<String, String> httpHeaders, InputStream inputStream)
throws IOException, WebApplicationException {
ProtobufMessageHandler obj = null;
try {
obj = type.newInstance();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buffer = new byte[4096];
int read;
do {
read = inputStream.read(buffer, 0, buffer.length);
if (read > 0) {
baos.write(buffer, 0, read);
}
} while (read > 0);
if (LOG.isDebugEnabled()) {
LOG.debug(getClass() + ": read " + baos.size() + " bytes from " +
inputStream);
}
obj = obj.getObjectFromMessage(baos.toByteArray());
} catch (InstantiationException e) {
throw new WebApplicationException(e);
} catch (IllegalAccessException e) {
throw new WebApplicationException(e);
}