diff --git a/app/build/generated/source/kapt/debug/rxhttp/wrapper/param/RxHttpBodyParam.java b/app/build/generated/source/kapt/debug/rxhttp/wrapper/param/RxHttpBodyParam.java index 4b7e7749..271704f6 100644 --- a/app/build/generated/source/kapt/debug/rxhttp/wrapper/param/RxHttpBodyParam.java +++ b/app/build/generated/source/kapt/debug/rxhttp/wrapper/param/RxHttpBodyParam.java @@ -3,6 +3,7 @@ import android.content.Context; import android.net.Uri; +import rxhttp.wrapper.annotations.Nullable; import rxhttp.wrapper.param.BodyParam; import java.io.File; @@ -20,54 +21,54 @@ public class RxHttpBodyParam extends RxHttpAbstractBodyParam RxHttpBodyParam setJsonBody(T object) { - param.setJsonBody(object); - return this; - } - - public RxHttpBodyParam setBody(MediaType mediaType, String content) { - param.setBody(mediaType, content); + + public RxHttpBodyParam setBody(String content, @Nullable MediaType mediaType) { + param.setBody(content, mediaType); return this; } - - public RxHttpBodyParam setBody(MediaType mediaType, ByteString content) { - param.setBody(mediaType, content); + + public RxHttpBodyParam setBody(ByteString content, @Nullable MediaType mediaType) { + param.setBody(content, mediaType); return this; } - - public RxHttpBodyParam setBody(MediaType mediaType, byte[] content) { - param.setBody(mediaType, content); + + public RxHttpBodyParam setBody(byte[] content, @Nullable MediaType mediaType) { + param.setBody(content, mediaType); return this; } - - public RxHttpBodyParam setBody(MediaType mediaType, byte[] content, int offset, int byteCount) { - param.setBody(mediaType, content, offset, byteCount); + + public RxHttpBodyParam setBody(byte[] content, @Nullable MediaType mediaType, int offset, int byteCount) { + param.setBody(content, mediaType, offset, byteCount); return this; } - + public RxHttpBodyParam setBody(File file) { param.setBody(file); return this; } - public RxHttpBodyParam setBody(MediaType mediaType, File file) { - param.setBody(mediaType, file); + public RxHttpBodyParam setBody(File file, @Nullable MediaType mediaType) { + param.setBody(file, mediaType); return this; } - + public RxHttpBodyParam setBody(Context context, Uri uri) { param.setBody(context, uri); return this; } - - public RxHttpBodyParam setBody(Context context, MediaType contentType, Uri uri) { - param.setBody(context, contentType, uri); + + public RxHttpBodyParam setBody(Context context, Uri uri, @Nullable MediaType contentType) { + param.setBody(context, uri, contentType); + return this; + } + + public RxHttpBodyParam setJsonBody(T object) { + param.setJsonBody(object); return this; } } diff --git a/rxhttp-compiler/src/main/java/com/rxhttp/compiler/ClassHelper.kt b/rxhttp-compiler/src/main/java/com/rxhttp/compiler/ClassHelper.kt index 2e3c8c0e..fb64a5d5 100644 --- a/rxhttp-compiler/src/main/java/com/rxhttp/compiler/ClassHelper.kt +++ b/rxhttp-compiler/src/main/java/com/rxhttp/compiler/ClassHelper.kt @@ -1059,6 +1059,7 @@ object ClassHelper { import android.content.Context; import android.net.Uri; + import rxhttp.wrapper.annotations.Nullable; import rxhttp.wrapper.param.BodyParam; import java.io.File; @@ -1076,54 +1077,54 @@ object ClassHelper { public RxHttpBodyParam(BodyParam param) { super(param); } - + public RxHttpBodyParam setBody(RequestBody requestBody) { param.setBody(requestBody); return this; } - - public RxHttpBodyParam setJsonBody(T object) { - param.setJsonBody(object); - return this; - } - - public RxHttpBodyParam setBody(MediaType mediaType, String content) { - param.setBody(mediaType, content); + + public RxHttpBodyParam setBody(String content, @Nullable MediaType mediaType) { + param.setBody(content, mediaType); return this; } - - public RxHttpBodyParam setBody(MediaType mediaType, ByteString content) { - param.setBody(mediaType, content); + + public RxHttpBodyParam setBody(ByteString content, @Nullable MediaType mediaType) { + param.setBody(content, mediaType); return this; } - - public RxHttpBodyParam setBody(MediaType mediaType, byte[] content) { - param.setBody(mediaType, content); + + public RxHttpBodyParam setBody(byte[] content, @Nullable MediaType mediaType) { + param.setBody(content, mediaType); return this; } - - public RxHttpBodyParam setBody(MediaType mediaType, byte[] content, int offset, int byteCount) { - param.setBody(mediaType, content, offset, byteCount); + + public RxHttpBodyParam setBody(byte[] content, @Nullable MediaType mediaType, int offset, int byteCount) { + param.setBody(content, mediaType, offset, byteCount); return this; } - + public RxHttpBodyParam setBody(File file) { param.setBody(file); return this; } - public RxHttpBodyParam setBody(MediaType mediaType, File file) { - param.setBody(mediaType, file); + public RxHttpBodyParam setBody(File file, @Nullable MediaType mediaType) { + param.setBody(file, mediaType); return this; } - + public RxHttpBodyParam setBody(Context context, Uri uri) { param.setBody(context, uri); return this; } - - public RxHttpBodyParam setBody(Context context, MediaType contentType, Uri uri) { - param.setBody(context, contentType, uri); + + public RxHttpBodyParam setBody(Context context, Uri uri, @Nullable MediaType contentType) { + param.setBody(context, uri, contentType); + return this; + } + + public RxHttpBodyParam setJsonBody(T object) { + param.setJsonBody(object); return this; } } diff --git a/rxhttp/src/main/java/rxhttp/wrapper/param/BodyParam.kt b/rxhttp/src/main/java/rxhttp/wrapper/param/BodyParam.kt index 77ef1f0a..21629e7c 100644 --- a/rxhttp/src/main/java/rxhttp/wrapper/param/BodyParam.kt +++ b/rxhttp/src/main/java/rxhttp/wrapper/param/BodyParam.kt @@ -1,89 +1,86 @@ -package rxhttp.wrapper.param; +package rxhttp.wrapper.param -import android.content.Context; -import android.net.Uri; - -import java.io.File; - -import okhttp3.MediaType; -import okhttp3.RequestBody; -import okio.ByteString; -import rxhttp.wrapper.entity.UriRequestBody; -import rxhttp.wrapper.utils.BuildUtil; +import android.content.Context +import android.net.Uri +import okhttp3.MediaType +import okhttp3.RequestBody +import okio.ByteString +import rxhttp.wrapper.entity.UriRequestBody +import rxhttp.wrapper.utils.BuildUtil +import java.io.File /** * User: ljx * Date: 2019-09-11 * Time: 11:52 + * + * @param url request url + * @param method [Method.POST]、[Method.PUT]、[Method.DELETE]、[Method.PATCH] */ -public class BodyParam extends AbstractBodyParam { - - private RequestBody requestBody; - - /** - * @param url request url - * @param method {@link Method#POST}、{@link Method#PUT}、{@link Method#DELETE}、{@link Method#PATCH} - */ - public BodyParam(String url, Method method) { - super(url, method); - } +class BodyParam( + url: String, + method: Method, +) : AbstractBodyParam(url, method) { - public BodyParam setBody(RequestBody requestBody) { - this.requestBody = requestBody; - return this; - } - - public BodyParam setJsonBody(T object) { - this.requestBody = convert(object); - return this; - } - - public BodyParam setBody(MediaType mediaType, String content) { - requestBody = RequestBody.create(mediaType, content); - return this; - } + private var requestBody: RequestBody? = null - public BodyParam setBody(MediaType mediaType, ByteString content) { - requestBody = RequestBody.create(mediaType, content); - return this; + fun setBody(requestBody: RequestBody): BodyParam { + this.requestBody = requestBody + return this } - public BodyParam setBody(MediaType mediaType, byte[] content) { - requestBody = RequestBody.create(mediaType, content); - return this; + @JvmOverloads + fun setBody(content: String, mediaType: MediaType? = null): BodyParam { + requestBody = RequestBody.create(mediaType, content) + return this } - public BodyParam setBody(MediaType mediaType, byte[] content, int offset, int byteCount) { - requestBody = RequestBody.create(mediaType, content, offset, byteCount); - return this; + @JvmOverloads + fun setBody(content: ByteString, mediaType: MediaType? = null): BodyParam { + requestBody = RequestBody.create(mediaType, content) + return this } - public BodyParam setBody(File file) { - return setBody(BuildUtil.getMediaType(file.getName()), file); + @JvmOverloads + fun setBody( + content: ByteArray, + mediaType: MediaType? = null, + offset: Int = 0, + byteCount: Int = content.size, + ): BodyParam { + requestBody = RequestBody.create(mediaType, content, offset, byteCount) + return this } - public BodyParam setBody(MediaType mediaType, File file) { - requestBody = RequestBody.create(mediaType, file); - return this; + @JvmOverloads + fun setBody( + file: File, + mediaType: MediaType? = BuildUtil.getMediaType(file.name), + ): BodyParam { + requestBody = RequestBody.create(mediaType, file) + return this } - public BodyParam setBody(Context context, Uri uri) { - requestBody = new UriRequestBody(context, uri); - return this; + @JvmOverloads + fun setBody( + context: Context, + uri: Uri, + contentType: MediaType? = null, + ): BodyParam { + requestBody = UriRequestBody(context, uri, contentType) + return this } - public BodyParam setBody(Context context, MediaType contentType, Uri uri) { - requestBody = new UriRequestBody(context, uri, contentType); - return this; + fun setJsonBody(any: T): BodyParam { + requestBody = convert(any) + return this } - @Override - public RequestBody getRequestBody() { - return requestBody; + override fun getRequestBody(): RequestBody { + return requestBody!! } - @Override - public BodyParam add(String key, Object value) { - return this; + override fun add(key: String, value: Any): BodyParam { + return this } -} +} \ No newline at end of file