class DefaultUriAdapter implements URIAdapter {

  @NonNull
  @Override
  public Uri rewrite(WXSDKInstance instance, String type, Uri uri) {
    if (TextUtils.isEmpty(instance.getBundleUrl())) {
      return uri;
    }

    Uri base = Uri.parse(instance.getBundleUrl());
    Uri.Builder resultBuilder = uri.buildUpon();
    
   if (uri.isRelative()) {
      //When uri is empty, means use the base url instead. Web broswer behave this way.
      if(uri.getEncodedPath().length() == 0){
        if(URIAdapter.IMAGE.equals(type)){
          if(TextUtils.isEmpty(uri.toString())){
            return uri;
          }
        }
        return base;
      } else {
        resultBuilder = buildRelativeURI(resultBuilder, base, uri);
        return resultBuilder.build();
      }
    }
    return uri;
  }

}