Skip to content

Commit

Permalink
Add Doc (#510)
Browse files Browse the repository at this point in the history
  • Loading branch information
YangSen-qn authored Dec 11, 2023
1 parent d540bd1 commit bae927d
Show file tree
Hide file tree
Showing 99 changed files with 4,876 additions and 293 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void testQuick(){
@Test
public void testNormal(){
Config.normal();
assertTrue(Config.uploadThreshold == 4*1024);
assertTrue(Config.uploadThreshold == 16*1024);
assertTrue(Config.interval == 10);
}

Expand Down
26 changes: 26 additions & 0 deletions library/src/main/java/com/qiniu/android/bigdata/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,20 @@

/**
* Created by long on 2017/7/25.
*
* @hidden
*/

public final class Configuration implements Cloneable {

/**
* pipelineHost
*/
public String pipelineHost = "https://pipeline.qiniu.com";

/**
* 请求 proxy
*/
public ProxyConfiguration proxy;


Expand All @@ -22,6 +31,18 @@ public final class Configuration implements Cloneable {
*/
public int responseTimeout = 10;

/**
* 构造函数
*/
public Configuration() {
}

/**
* Configuration copy
*
* @param config 待 copy 对象
* @return Configuration
*/
public static Configuration copy(Configuration config) {
if (config == null) {
return new Configuration();
Expand All @@ -33,6 +54,11 @@ public static Configuration copy(Configuration config) {
}
}

/**
* Configuration clone
*
* @return Configuration
*/
public Configuration clone() throws CloneNotSupportedException {
return (Configuration) super.clone();
}
Expand Down
114 changes: 110 additions & 4 deletions library/src/main/java/com/qiniu/android/bigdata/client/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,49 @@

/**
* Created by bailong on 15/11/12.
*
* @hidden
*/
public final class Client {
/**
* HTTP 请求头:Content-Type
*/
public static final String ContentTypeHeader = "Content-Type";

/**
* HTTP 请求默认的 MimeType
*/
public static final String DefaultMime = "application/octet-stream";

/**
* HTTP 请求 Json 的 MimeType
*/
public static final String JsonMime = "application/json";

/**
* HTTP 请求 FormMime 的 MimeType
*/
public static final String FormMime = "application/x-www-form-urlencoded";

private final UrlConverter converter;
private OkHttpClient httpClient;

/**
* 构造方法
*/
public Client() {
this(null, 10, 30, null, null);
}

/**
* 构造函数
*
* @param proxy 请求代理
* @param connectTimeout 请求建立连接超时时间
* @param responseTimeout 请求接收数据超时时间
* @param converter 请求 Url 拦截器
* @param dns 请求的 Dns 解析器
*/
public Client(ProxyConfiguration proxy, int connectTimeout, int responseTimeout, UrlConverter converter, final Dns dns) {
this.converter = converter;
OkHttpClient.Builder builder = new OkHttpClient.Builder();
Expand All @@ -71,9 +101,9 @@ public List<InetAddress> lookup(String hostname) throws UnknownHostException {
List<IDnsNetworkAddress> networkAddressList = DnsPrefetcher.getInstance().getInetAddressByHost(hostname);
if (networkAddressList != null && networkAddressList.size() > 0) {
List<InetAddress> inetAddressList = new ArrayList<>();
for (IDnsNetworkAddress networkAddress : networkAddressList){
for (IDnsNetworkAddress networkAddress : networkAddressList) {
InetAddress address = null;
if (networkAddress.getIpValue() != null && (address = InetAddress.getByName(networkAddress.getIpValue())) != null){
if (networkAddress.getIpValue() != null && (address = InetAddress.getByName(networkAddress.getIpValue())) != null) {
inetAddressList.add(address);
}
}
Expand Down Expand Up @@ -210,6 +240,15 @@ public void run() {
});
}

/**
* 异步请求
*
* @param requestBuilder 请求构造器
* @param headers 请求头
* @param upToken 上传 Token
* @param totalSize 请求体大小
* @param complete 结束回调
*/
public void asyncSend(final Request.Builder requestBuilder, StringMap headers, final UpToken upToken,
final long totalSize, final CompletionHandler complete) {
if (headers != null) {
Expand Down Expand Up @@ -259,13 +298,39 @@ public void onResponse(Call call, okhttp3.Response response) throws IOException
});
}

/**
* 异步 POST 请求
*
* @param url 请求 url
* @param body 请求 body
* @param headers 请求 header
* @param upToken 上传 token
* @param totalSize 请求总大小
* @param progressHandler 请求进度回调
* @param completionHandler 结束回调
* @param c 取消回调
*/
public void asyncPost(String url, byte[] body,
StringMap headers, final UpToken upToken,
final long totalSize, ProgressHandler progressHandler,
CompletionHandler completionHandler, UpCancellationSignal c) {
asyncPost(url, body, 0, body.length, headers, upToken, totalSize, progressHandler, completionHandler, c);
}

/**
* 异步 POST 请求
*
* @param url 请求 Url
* @param body 请求体
* @param offset 请求体偏移量
* @param size 请求体大小
* @param headers 请求 Header
* @param upToken 上传 Token
* @param totalSize 请求体总大小
* @param progressHandler 进度回调
* @param completionHandler 完成回调
* @param c 取消回调
*/
public void asyncPost(String url, byte[] body, int offset, int size,
StringMap headers, final UpToken upToken,
final long totalSize, ProgressHandler progressHandler,
Expand Down Expand Up @@ -295,6 +360,16 @@ public void asyncPost(String url, byte[] body, int offset, int size,
asyncSend(requestBuilder, headers, upToken, totalSize, completionHandler);
}

/**
* 异步表单请求
*
* @param url 请求 Url
* @param args 请求参数
* @param upToken 上传的 Token
* @param progressHandler 进度回调
* @param completionHandler 完成回答
* @param c 取消回调
*/
public void asyncMultipartPost(String url,
PostArgs args,
final UpToken upToken,
Expand Down Expand Up @@ -343,12 +418,27 @@ public void accept(String key, Object value) {
asyncSend(requestBuilder, null, upToken, totalSize, completionHandler);
}

/**
* 异步 GET 请求
*
* @param url 请求 Url
* @param headers 请求 Header
* @param upToken 上传的 Token
* @param completionHandler 请求完成回调
*/
public void asyncGet(String url, StringMap headers, final UpToken upToken,
CompletionHandler completionHandler) {
Request.Builder requestBuilder = new Request.Builder().get().url(url);
asyncSend(requestBuilder, headers, upToken, 0, completionHandler);
}

/**
* 同步 GET 请求
*
* @param url 请求 Url
* @param headers 请求 Header
* @return ResponseInfo
*/
public ResponseInfo syncGet(String url, StringMap headers) {
Request.Builder requestBuilder = new Request.Builder().get().url(url);
return send(requestBuilder, headers);
Expand Down Expand Up @@ -379,8 +469,15 @@ public void accept(String key, Object value) {
return buildResponseInfo(res, tag.ip, tag.duration, null, 0);
}

public ResponseInfo syncMultipartPost(String url, PostArgs args,
final UpToken upToken) {
/**
* 同步表单请求
*
* @param url 请求 Url
* @param args 请求参数
* @param upToken 上传 Token
* @return ResponseInfo
*/
public ResponseInfo syncMultipartPost(String url, PostArgs args, final UpToken upToken) {
RequestBody file;
long totalSize;
if (args.file != null) {
Expand Down Expand Up @@ -414,6 +511,15 @@ public void accept(String key, Object value) {
return syncSend(requestBuilder, null, upToken, totalSize);
}

/**
* 同步请求
*
* @param requestBuilder 请求构造器
* @param headers 请求 Header
* @param upToken 上传的 Token
* @param totalSize 请求体大小
* @return ResponseInfo
*/
public ResponseInfo syncSend(final Request.Builder requestBuilder, StringMap headers,
final UpToken upToken, final long totalSize) {
if (headers != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

/**
* 定义请求完成后续动作的处理接口
*
* @hidden
*/
public interface CompletionHandler {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

/**
* 定义请求参数列表
*
* @hidden
*/
public final class PostArgs {
/**
Expand All @@ -29,4 +31,10 @@ public final class PostArgs {
*/
public String mimeType;

/**
* 构造函数
*/
public PostArgs() {
}

}
Loading

0 comments on commit bae927d

Please sign in to comment.