Search in sources :

Example 1 with ProtobufMessageHandler

use of org.apache.hadoop.hbase.rest.ProtobufMessageHandler in project hbase by apache.

the class ProtobufMessageBodyConsumer method readFrom.

@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.isTraceEnabled()) {
            LOG.trace(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);
    }
    return obj;
}
Also used : ProtobufMessageHandler(org.apache.hadoop.hbase.rest.ProtobufMessageHandler) WebApplicationException(javax.ws.rs.WebApplicationException) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Aggregations

ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 ProtobufMessageHandler (org.apache.hadoop.hbase.rest.ProtobufMessageHandler)1