Skip to content

Commit

Permalink
add some doc
Browse files Browse the repository at this point in the history
  • Loading branch information
YangSen-qn committed Nov 27, 2023
1 parent 190d736 commit e1ed20d
Show file tree
Hide file tree
Showing 45 changed files with 1,423 additions and 155 deletions.
18 changes: 18 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 @@ -7,8 +7,15 @@
*/

public final class Configuration implements Cloneable {

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

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


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

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

/**
* Configuration clone
*
* @return Configuration
*/
public Configuration clone() throws CloneNotSupportedException {
return (Configuration) super.clone();
}
Expand Down
91 changes: 87 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 @@ -43,17 +43,45 @@
* Created by bailong on 15/11/12.
*/
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 +99,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 @@ -266,6 +294,20 @@ public void asyncPost(String url, byte[] body,
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 +337,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 +395,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 +446,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 +488,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
30 changes: 27 additions & 3 deletions library/src/main/java/com/qiniu/android/common/AutoZone.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,44 @@ public final class AutoZone extends Zone {
.setVersion("v1")
.builder();

//私有云可能改变ucServer
/**
* 配置 UC 域名,此 UC 域名用于根据上传 bucket 查询对应的区域。
* 公有云不用配置
*
* @param ucServer UC 域名
*/
public void setUcServer(String ucServer) {
if (ucServer != null) {
this.ucServers = new String[]{ucServer};
}
}

/**
* 配置 UC 域名,此 UC 域名用于根据上传 bucket 查询对应的区域。
* 公有云不用配置
*
* @param ucServers UC 域名,可以是多个,多个会进行主备重试
*/
public void setUcServers(String[] ucServers) {
if (ucServers != null && ucServers.length > 0) {
this.ucServers = ucServers;
}
}

/**
* 配置默认区域,在使用 AutoZone 进行上传时,当根据 bucket 查询 Zone 信息失败时如果默认区域存在会尝试使用默认区域进行上传。
*
* @param zones 默认区域,可以是多个
*/
public void setDefaultZones(FixedZone[] zones) {
defaultZone = FixedZone.combineZones(zones);
}

/**
* 获取 UC 域名列表
*
* @return UC 域名列表
*/
public List<String> getUcServerList() {
if (ucServers != null && ucServers.length > 0) {
ArrayList<String> serverList = new ArrayList<>();
Expand All @@ -67,6 +88,9 @@ public List<String> getUcServerList() {
}
}

/**
* 清除区域存储缓存
*/
public static void clearCache() {
zoneCache.clearMemoryCache();
zoneCache.clearDiskCache();
Expand Down Expand Up @@ -106,7 +130,7 @@ public void preQuery(final UpToken token, final QueryHandler completeHandler) {
UploadRegionRequestMetrics localMetrics = new UploadRegionRequestMetrics(null);
localMetrics.start();

final String cacheKey = makeCacheKey(token.index()) ;
final String cacheKey = makeCacheKey(token.index());

ZonesInfo zonesInfo = null;
Cache.Object object = zoneCache.cacheForKey(cacheKey);
Expand Down Expand Up @@ -197,7 +221,7 @@ private String makeCacheKey(String akAndBucket) {
hosts.append(host).append(":");
}

return UrlSafeBase64.encodeToString(hosts+akAndBucket);
return UrlSafeBase64.encodeToString(hosts + akAndBucket);
}

private RequestTransaction createUploadRequestTransaction(UpToken token) {
Expand Down
24 changes: 22 additions & 2 deletions library/src/main/java/com/qiniu/android/common/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public final class Config {

/**
* 记录上传信息文件最大值,单位:字节。
*
* <p>
* 记录文件大于此值后暂停记录上传信息。
*/
public static int maxRecordFileSize = 20 * 1024 * 1024;
Expand All @@ -69,10 +69,27 @@ public final class Config {
* preQuery host
*/
public static String preQueryHost00 = "uc.qiniuapi.com";

/**
* preQuery host
*/
public static String preQueryHost01 = "kodo-config.qiniuapi.com";

/**
* preQuery host
*/
public static String preQueryHost02 = "uc.qbox.me";

/**
* preQuery host
*/
public static String preQueryHost03 = "api.qiniu.com";

/**
* 获取 preQuery hosts
*
* @return preQuery hosts
*/
public static String[] preQueryHosts() {
return new String[]{preQueryHost00, preQueryHost01, preQueryHost02, preQueryHost03};
}
Expand All @@ -85,8 +102,11 @@ public static void quick() {
interval = 2;
}

/**
* 标准设置
*/
public static void normal() {
uploadThreshold = 4 * 1024;
uploadThreshold = 16 * 1024;
interval = 10;
}

Expand Down
10 changes: 10 additions & 0 deletions library/src/main/java/com/qiniu/android/common/Constants.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
package com.qiniu.android.common;


/**
* 常量定义
*/
public final class Constants {

/**
* SDK 版本号
*/
public static final String VERSION = "8.7.0";

/**
* UTF-8 编码
*/
public static final String UTF_8 = "utf-8";
}
26 changes: 26 additions & 0 deletions library/src/main/java/com/qiniu/android/common/FixedZone.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ public static FixedZone createWithRegionId(String regionId) {

private ZonesInfo zonesInfo;

/**
* 获取 SDK 中使用的 zone,用于重试,外部不可使用
*
* @return FixedZone
*/
@Deprecated
public static FixedZone localsZoneInfo() {
FixedZone[] localsZone = new FixedZone[]{
Expand Down Expand Up @@ -121,20 +126,41 @@ public static FixedZone combineZones(FixedZone[] zones) {
return new FixedZone(zonesInfo);
}

/**
* 构造方法
*
* @param zoneInfo zone 信息
*/
public FixedZone(ZoneInfo zoneInfo) {
ArrayList<ZoneInfo> zoneInfoList = new ArrayList<>();
zoneInfoList.add(zoneInfo);
this.zonesInfo = new ZonesInfo(zoneInfoList);
}

/**
* 构造方法
*
* @param zonesInfo zones 信息
*/
public FixedZone(ZonesInfo zonesInfo) {
this.zonesInfo = zonesInfo;
}

/**
* 构造方法
*
* @param upDomains 上传域名
*/
public FixedZone(String[] upDomains) {
this(upDomains, null);
}

/**
* 构造方法
*
* @param upDomains 上传域名
* @param regionId 区域 ID
*/
public FixedZone(String[] upDomains, String regionId) {
this(upDomains, null, regionId);
}
Expand Down
Loading

0 comments on commit e1ed20d

Please sign in to comment.