code: public static <T extends MessageLite> T parseAndClose(
        InputStream inputStream, Class<T> messageClass) throws IOException {
      try {
        Method newBuilder = messageClass.getDeclaredMethod("parseFrom", InputStream.class);
        return messageClass.cast(newBuilder.invoke(null, inputStream));
      } catch (Exception e) {
        Throwables.propagateIfPossible(e, IOException.class);
        IOException io = new IOException("Error parsing message of type " + messageClass);
        io.initCause(e);
        throw io;
      } finally {
        inputStream.close();
      }
    }
docs: Parses protocol buffer content from an input stream (closing the input stream) into a protocol
  buffer message.
  
  @param <T> destination message type
  @param messageClass destination message class that has a {@code parseFrom(InputStream)} public
  static method
  @return new instance of the parsed destination message class