code: public static boolean isTruncatedMessageException(IOException e) {
      if (!(e instanceof InvalidProtocolBufferException)) {
        return false;
      }
      String truncatedMessage;
      try {
        Method method = InvalidProtocolBufferException.class.getMethod("truncatedMessage");
        method.setAccessible(true);
        truncatedMessage = (String) method.invoke(null);
      } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException ee) {
        throw new RuntimeException(ee);
      }
      return e.getMessage().equals(truncatedMessage);
    }
docs: Checks whether the exception is an {@link InvalidProtocolBufferException} thrown because of
  a truncated message.
  
  @param e the exception
  @return whether the exception is an {@link InvalidProtocolBufferException} thrown because of
  a truncated message.