@Override public void writeTo(ProtobufMessageHandler m, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException { entityStream.write(m.createProtobufOutput()); } }
@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.getDeclaredConstructor().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 | NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { throw new WebApplicationException(e); } return obj; } }
@SuppressWarnings("unused") protected byte[] toPB(ProtobufMessageHandler model) { return model.createProtobufOutput(); }
@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.getDeclaredConstructor().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 | NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { throw new WebApplicationException(e); } return obj; } }
@Override public void writeTo(ProtobufMessageHandler m, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException { entityStream.write(m.createProtobufOutput()); } }
@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); } return obj; } }
@Override public void writeTo(ProtobufMessageHandler m, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException { entityStream.write(m.createProtobufOutput()); } }
@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.getDeclaredConstructor().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 | NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { throw new WebApplicationException(e); } return obj; } }
@Override public long getSize(ProtobufMessageHandler m, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { baos.write(m.createProtobufOutput()); } catch (IOException e) { return -1; } byte[] bytes = baos.toByteArray(); buffer.set(bytes); return bytes.length; }
@SuppressWarnings("unused") protected byte[] toPB(ProtobufMessageHandler model) { return model.createProtobufOutput(); }