From 3340c3ec767964506d96e311b40c5fe2268f4e7f Mon Sep 17 00:00:00 2001 From: YangSen-qn Date: Tue, 28 Nov 2023 19:10:14 +0800 Subject: [PATCH] add some doc --- .../qiniu/android/bigdata/Configuration.java | 6 + .../qiniu/android/bigdata/client/Client.java | 21 + .../android/bigdata/client/PostArgs.java | 6 + .../android/bigdata/pipeline/Pipeline.java | 67 ++- .../android/bigdata/pipeline/Points.java | 47 +- .../qiniu/android/collect/ReportConfig.java | 14 +- .../com/qiniu/android/collect/ReportItem.java | 456 ++++++++++++++++-- .../android/collect/UploadInfoReporter.java | 19 +- .../com/qiniu/android/common/AutoZone.java | 6 + .../java/com/qiniu/android/common/Config.java | 7 + .../com/qiniu/android/common/Constants.java | 3 + .../com/qiniu/android/common/FixedZone.java | 6 + .../java/com/qiniu/android/common/Zone.java | 13 + .../com/qiniu/android/common/ZoneInfo.java | 115 ++++- .../com/qiniu/android/common/ZonesInfo.java | 52 ++ .../android/http/CancellationHandler.java | 6 + .../java/com/qiniu/android/http/Headers.java | 8 +- .../java/com/qiniu/android/http/HttpDate.java | 4 + .../android/http/ProxyConfiguration.java | 38 ++ .../com/qiniu/android/http/ResponseInfo.java | 209 +++++++- .../com/qiniu/android/http/UrlConverter.java | 10 + .../com/qiniu/android/http/UserAgent.java | 21 +- .../http/connectCheck/ConnectChecker.java | 3 + .../qiniu/android/http/dns/DnsCacheInfo.java | 11 + .../http/dns/DnsPrefetchTransaction.java | 3 + .../com/qiniu/android/http/dns/DnsSource.java | 3 + .../com/qiniu/android/http/dns/HttpDns.java | 15 + .../com/qiniu/android/http/dns/SystemDns.java | 22 + .../com/qiniu/android/http/dns/UdpDns.java | 15 + .../android/http/metrics/UploadMetrics.java | 34 +- .../metrics/UploadRegionRequestMetrics.java | 40 +- .../metrics/UploadSingleRequestMetrics.java | 347 +++++++++++++ .../http/metrics/UploadTaskMetrics.java | 77 ++- .../networkStatus/NetworkStatusManager.java | 64 +++ .../UploadServerNetworkStatus.java | 22 +- .../android/http/request/IRequestClient.java | 6 + .../android/http/request/IUploadServer.java | 17 +- .../qiniu/android/http/request/Request.java | 84 ++++ .../http/request/RequestTransaction.java | 137 ++++++ .../http/request/UploadRequestState.java | 33 +- .../handler/RequestProgressHandler.java | 10 + .../handler/RequestShouldRetryHandler.java | 11 + .../request/httpclient/MultipartBody.java | 135 +++++- .../request/httpclient/SystemHttpClient.java | 51 ++ .../http/serverRegion/HttpServerManager.java | 3 + .../http/serverRegion/UploadDomainRegion.java | 44 +- .../http/serverRegion/UploadServer.java | 47 ++ .../UploadServerFreezeManager.java | 25 + .../serverRegion/UploadServerFreezeUtil.java | 32 ++ .../qiniu/android/storage/Configuration.java | 6 + .../android/storage/GlobalConfiguration.java | 21 + .../android/storage/NetReadyHandler.java | 4 + .../storage/UpProgressBytesHandler.java | 4 + .../com/qiniu/android/storage/UpToken.java | 65 +++ .../qiniu/android/storage/UploadManager.java | 25 +- .../qiniu/android/storage/UploadOptions.java | 41 +- .../storage/serverConfig/ServerConfig.java | 151 ++++++ .../serverConfig/ServerConfigMonitor.java | 32 +- .../serverConfig/ServerUserConfig.java | 33 ++ .../transaction/TransactionManager.java | 113 ++++- .../qiniu/android/utils/AndroidNetwork.java | 3 + .../com/qiniu/android/utils/AsyncRun.java | 3 + .../com/qiniu/android/utils/BytesUtils.java | 3 + .../com/qiniu/android/utils/Constants.java | 3 +- .../qiniu/android/utils/ContextGetter.java | 3 + .../java/com/qiniu/android/utils/Crc32.java | 3 + .../java/com/qiniu/android/utils/Etag.java | 3 + .../com/qiniu/android/utils/GZipUtil.java | 6 + .../qiniu/android/utils/GroupTaskThread.java | 19 +- .../qiniu/android/utils/IPAddressUtil.java | 11 +- .../java/com/qiniu/android/utils/Json.java | 3 + .../com/qiniu/android/utils/ListVector.java | 8 + .../java/com/qiniu/android/utils/LogUtil.java | 3 + .../java/com/qiniu/android/utils/MD5.java | 14 + .../com/qiniu/android/utils/SingleFlight.java | 35 ++ .../com/qiniu/android/utils/StringMap.java | 94 ++++ .../com/qiniu/android/utils/StringUtils.java | 76 ++- .../qiniu/android/utils/UrlSafeBase64.java | 5 +- .../com/qiniu/android/utils/UrlUtils.java | 18 +- .../java/com/qiniu/android/utils/Utils.java | 118 ++++- .../java/com/qiniu/android/utils/Wait.java | 19 +- 81 files changed, 3238 insertions(+), 132 deletions(-) diff --git a/library/src/main/java/com/qiniu/android/bigdata/Configuration.java b/library/src/main/java/com/qiniu/android/bigdata/Configuration.java index e52c9cf5c..6440609cb 100644 --- a/library/src/main/java/com/qiniu/android/bigdata/Configuration.java +++ b/library/src/main/java/com/qiniu/android/bigdata/Configuration.java @@ -29,6 +29,12 @@ public final class Configuration implements Cloneable { */ public int responseTimeout = 10; + /** + * 构造函数 + */ + public Configuration() { + } + /** * Configuration copy * diff --git a/library/src/main/java/com/qiniu/android/bigdata/client/Client.java b/library/src/main/java/com/qiniu/android/bigdata/client/Client.java index 7f947eb30..fec36cede 100644 --- a/library/src/main/java/com/qiniu/android/bigdata/client/Client.java +++ b/library/src/main/java/com/qiniu/android/bigdata/client/Client.java @@ -238,6 +238,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) { @@ -287,6 +296,18 @@ 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, diff --git a/library/src/main/java/com/qiniu/android/bigdata/client/PostArgs.java b/library/src/main/java/com/qiniu/android/bigdata/client/PostArgs.java index 5486dd304..d7a316fec 100644 --- a/library/src/main/java/com/qiniu/android/bigdata/client/PostArgs.java +++ b/library/src/main/java/com/qiniu/android/bigdata/client/PostArgs.java @@ -29,4 +29,10 @@ public final class PostArgs { */ public String mimeType; + /** + * 构造函数 + */ + public PostArgs() { + } + } diff --git a/library/src/main/java/com/qiniu/android/bigdata/pipeline/Pipeline.java b/library/src/main/java/com/qiniu/android/bigdata/pipeline/Pipeline.java index 9ad6fec10..96b1b295c 100644 --- a/library/src/main/java/com/qiniu/android/bigdata/pipeline/Pipeline.java +++ b/library/src/main/java/com/qiniu/android/bigdata/pipeline/Pipeline.java @@ -15,45 +15,101 @@ /** * Created by long on 2017/7/25. */ - public final class Pipeline { private static final String HTTPHeaderAuthorization = "Authorization"; private static final String TEXT_PLAIN = "text/plain"; private final Configuration config; private final Client client; + /** + * 构造函数 + * + * @param config config + */ public Pipeline(Configuration config) { this.config = Configuration.copy(config); this.client = new Client(this.config.proxy, this.config.connectTimeout, this.config.responseTimeout, null, null); } + /** + * pump + * + * @param repo repo + * @param data data + * @param token token + * @param handler handler + * @param V + */ public void pump(String repo, Map data, String token, PumpCompleteHandler handler) { StringBuilder b = new StringBuilder(); Points.formatPoint(data, b); send(repo, b, token, handler); } + /** + * pump + * + * @param repo repo + * @param data data + * @param token token + * @param handler handler + */ public void pump(String repo, Object data, String token, PumpCompleteHandler handler) { StringBuilder b = new StringBuilder(); Points.formatPoint(data, b); send(repo, b, token, handler); } + /** + * pumpMulti + * + * @param repo repo + * @param data data + * @param token token + * @param handler handler + * @param V + */ public void pumpMulti(String repo, Map[] data, String token, PumpCompleteHandler handler) { StringBuilder b = Points.formatPoints(data); send(repo, b, token, handler); } + /** + * pumpMultiObjects + * + * @param repo repo + * @param data data + * @param token token + * @param handler handler + */ public void pumpMultiObjects(String repo, Object[] data, String token, PumpCompleteHandler handler) { StringBuilder b = Points.formatPoints(data); send(repo, b, token, handler); } + /** + * pumpMultiObjects + * + * @param repo repo + * @param data data + * @param token token + * @param handler handler + * @param V + */ public void pumpMultiObjects(String repo, List data, String token, PumpCompleteHandler handler) { StringBuilder b = Points.formatPointsObjects(data); send(repo, b, token, handler); } + /** + * pumpMulti + * + * @param repo repo + * @param data data + * @param token token + * @param handler handler + * @param V + */ public void pumpMulti(String repo, List> data, String token, PumpCompleteHandler handler) { StringBuilder b = Points.formatPoints(data); send(repo, b, token, handler); @@ -86,7 +142,16 @@ private String url(String repo) { return config.pipelineHost + "/v2/repos/" + repo + "/data"; } + /** + * Pump 完成回调 + */ public interface PumpCompleteHandler { + + /** + * Pump 完成回调 + * + * @param info info + */ void complete(ResponseInfo info); } diff --git a/library/src/main/java/com/qiniu/android/bigdata/pipeline/Points.java b/library/src/main/java/com/qiniu/android/bigdata/pipeline/Points.java index c7099e892..b93352384 100644 --- a/library/src/main/java/com/qiniu/android/bigdata/pipeline/Points.java +++ b/library/src/main/java/com/qiniu/android/bigdata/pipeline/Points.java @@ -19,6 +19,10 @@ * 数据点 */ public final class Points { + + private Points() { + } + private static String buildString(Object v) { if (v == null) { return null; @@ -41,6 +45,14 @@ private static String buildString(Object v) { return str; } + /** + * formatPoint + * + * @param data data + * @param builder builder + * @return StringBuilder + * @param V + */ public static StringBuilder formatPoint(Map data, StringBuilder builder) { for (Map.Entry it : data.entrySet()) { builder.append(it.getKey()).append("=").append(buildString(it.getValue())).append("\t"); @@ -49,6 +61,13 @@ public static StringBuilder formatPoint(Map data, StringBuilder b return builder; } + /** + * formatPoint + * + * @param obj obj + * @param builder builder + * @return StringBuilder + */ public static StringBuilder formatPoint(Object obj, StringBuilder builder) { Class cls = obj.getClass(); java.lang.reflect.Field[] fields = cls.getDeclaredFields(); @@ -67,6 +86,13 @@ public static StringBuilder formatPoint(Object obj, StringBuilder builder) { return formatPoint(map, builder); } + /** + * formatPoint + * + * @param data data + * @return StringBuilder + * @param V + */ public static StringBuilder formatPoints(Map[] data) { StringBuilder builder = new StringBuilder(); for (Map aData : data) { @@ -75,7 +101,12 @@ public static StringBuilder formatPoints(Map[] data) { return builder; } - + /** + * formatPoint + * + * @param data data + * @return StringBuilder + */ public static StringBuilder formatPoints(Object[] data) { StringBuilder builder = new StringBuilder(); for (Object aData : data) { @@ -84,6 +115,13 @@ public static StringBuilder formatPoints(Object[] data) { return builder; } + /** + * formatPoints + * + * @param data data + * @return StringBuilder + * @param V + */ public static StringBuilder formatPoints(List> data) { StringBuilder builder = new StringBuilder(); for (Map aData : data) { @@ -93,6 +131,13 @@ public static StringBuilder formatPoints(List> data) { } + /** + * formatPointsObjects + * + * @param data data + * @return StringBuilder + * @param V + */ public static StringBuilder formatPointsObjects(List data) { StringBuilder builder = new StringBuilder(); for (Object aData : data) { diff --git a/library/src/main/java/com/qiniu/android/collect/ReportConfig.java b/library/src/main/java/com/qiniu/android/collect/ReportConfig.java index f41cad1a5..61b66459b 100644 --- a/library/src/main/java/com/qiniu/android/collect/ReportConfig.java +++ b/library/src/main/java/com/qiniu/android/collect/ReportConfig.java @@ -3,6 +3,9 @@ import com.qiniu.android.common.Config; import com.qiniu.android.utils.Utils; +/** + * 记录配置 + */ public class ReportConfig { /** @@ -16,7 +19,7 @@ public class ReportConfig { public double interval; /** - * 记录文件大于 uploadThreshold 会触发上传,单位:字节 默认为16 * 1024 + * 记录文件大于 uploadThreshold 会触发上传,单位:字节 默认为16 * 1024 */ public long uploadThreshold; @@ -42,7 +45,7 @@ public class ReportConfig { private static ReportConfig instance = new ReportConfig(); - private ReportConfig(){ + private ReportConfig() { this.isReportEnable = Config.isRecord; this.interval = Config.interval; this.serverURL = Config.upLogURL; @@ -56,7 +59,12 @@ private ReportConfig(){ this.timeoutInterval = 10; } - public static ReportConfig getInstance(){ + /** + * 获取配置单例 + * + * @return 配置单例 + */ + public static ReportConfig getInstance() { return instance; } } diff --git a/library/src/main/java/com/qiniu/android/collect/ReportItem.java b/library/src/main/java/com/qiniu/android/collect/ReportItem.java index 97a2ba372..d164e4987 100644 --- a/library/src/main/java/com/qiniu/android/collect/ReportItem.java +++ b/library/src/main/java/com/qiniu/android/collect/ReportItem.java @@ -6,14 +6,27 @@ import java.util.HashMap; +/** + * 记录信息 + */ public class ReportItem { private HashMap keyValues = new HashMap<>(); - public ReportItem(){} + /** + * 构造函数 + */ + public ReportItem() { + } - public void setReport(Object value, String key){ - if (key == null || value == null){ + /** + * 天机记录内容 + * + * @param value 记录的内容 + * @param key 记录的 key + */ + public void setReport(Object value, String key) { + if (key == null || value == null) { return; } if (value instanceof String && ((String) value).length() > 1024) { @@ -22,161 +35,530 @@ public void setReport(Object value, String key){ keyValues.put(key, value); } - public void removeReportValue(String key){ - if (key == null){ + /** + * 移除记录 + * + * @param key 待移除记录的 key + */ + public void removeReportValue(String key) { + if (key == null) { return; } keyValues.remove(key); } - public String toJson(){ + /** + * 转 json + * + * @return Json 数据 + */ + public String toJson() { String jsonString = "{}"; - if (keyValues == null || keyValues.size() == 0){ + if (keyValues == null || keyValues.size() == 0) { return jsonString; } jsonString = new JSONObject(keyValues).toString(); return jsonString; } - // 日志类型 + /** + * request 记录类型 + */ public static final String LogTypeRequest = "request"; + + /** + * block 记录类型 + */ public static final String LogTypeBlock = "block"; + + /** + * quality 记录类型 + */ public static final String LogTypeQuality = "quality"; // 请求信息打点⽇志 + /** + * 请求记录 key:记录类型 + */ public static final String RequestKeyLogType = "log_type"; + + /** + * 请求记录 key:请求时间 + */ public static final String RequestKeyUpTime = "up_time"; + + /** + * 请求记录 key:请求状态码 + */ public static final String RequestKeyStatusCode = "status_code"; + + /** + * 请求记录 key:请求 ID + */ public static final String RequestKeyRequestId = "req_id"; + + /** + * 请求记录 key:请求域名 + */ public static final String RequestKeyHost = "host"; + + /** + * 请求记录 key:请求的 HTTP 版本 + */ public static final String RequestKeyHttpVersion = "http_version"; + + /** + * 请求记录 key:请求的服务端地址 + */ public static final String RequestKeyRemoteIp = "remote_ip"; + + /** + * 请求记录 key:请求的端口号 + */ public static final String RequestKeyPort = "port"; + + /** + * 请求记录 key:上传的 bucket + */ public static final String RequestKeyTargetBucket = "target_bucket"; + + /** + * 请求记录 key:上传保存的 key + */ public static final String RequestKeyTargetKey = "target_key"; + + /** + * 请求记录 key:请求总耗时 + */ public static final String RequestKeyTotalElapsedTime = "total_elapsed_time"; + + /** + * 请求记录 key:dns 耗时 + */ public static final String RequestKeyDnsElapsedTime = "dns_elapsed_time"; + + /** + * 请求记录 key:请求建立连接耗时 + */ public static final String RequestKeyConnectElapsedTime = "connect_elapsed_time"; + + /** + * 请求记录 key:请求 tls 耗时 + */ public static final String RequestKeyTLSConnectElapsedTime = "tls_connect_elapsed_time"; + + /** + * 请求记录 key:请求耗时 + */ public static final String RequestKeyRequestElapsedTime = "request_elapsed_time"; + + /** + * 请求记录 key:等待响应耗时 + */ public static final String RequestKeyWaitElapsedTime = "wait_elapsed_time"; + + /** + * 请求记录 key:响应耗时 + */ public static final String RequestKeyResponseElapsedTime = "response_elapsed_time"; + + /** + * 请求记录 key:上传文件偏移量 + */ public static final String RequestKeyFileOffset = "file_offset"; + + /** + * 请求记录 key:请求发送大小 + */ public static final String RequestKeyBytesSent = "bytes_sent"; + + /** + * 请求记录 key:请求大小 + */ public static final String RequestKeyBytesTotal = "bytes_total"; + + /** + * 请求记录 key:pid + */ public static final String RequestKeyPid = "pid"; + + /** + * 请求记录 key:tid + */ public static final String RequestKeyTid = "tid"; + + /** + * 请求记录 key:文件上传的目标区域 + */ public static final String RequestKeyTargetRegionId = "target_region_id"; + + /** + * 请求记录 key:当前上传的区域 + */ public static final String RequestKeyCurrentRegionId = "current_region_id"; + + /** + * 请求记录 key:请求错误类型 + */ public static final String RequestKeyErrorType = "error_type"; + + /** + * 请求记录 key:请求错误信息 + */ public static final String RequestKeyErrorDescription = "error_description"; + + /** + * 请求记录 key:上传类型 + */ public static final String RequestKeyUpType = "up_type"; + + /** + * 请求记录 key:操作系统 + */ public static final String RequestKeyOsName = "os_name"; + + /** + * 请求记录 key:操作系统版本 + */ public static final String RequestKeyOsVersion = "os_version"; + + /** + * 请求记录 key:SDK 名称 + */ public static final String RequestKeySDKName = "sdk_name"; + + /** + * 请求记录 key:SDK 版本 + */ public static final String RequestKeySDKVersion = "sdk_version"; + + /** + * 请求记录 key:客户端时间 + */ public static final String RequestKeyClientTime = "client_time"; + + /** + * 请求记录 key:客户端类型 + */ public static final String RequestKeyHttpClient = "http_client"; + + /** + * 请求记录 key:客户端版本 + */ public static final String RequestKeyHttpClientVersion = "http_client_version"; + + /** + * 请求记录 key:网络类型 + */ public static final String RequestKeyNetworkType = "network_type"; + + /** + * 请求记录 key:信号强度 + */ public static final String RequestKeySignalStrength = "signal_strength"; + + /** + * 请求记录 key:上次 DNS 解析源 + */ public static final String RequestKeyPrefetchedDnsSource = "prefetched_dns_source"; + + /** + * 请求记录 key:DNS 解析源 + */ public static final String RequestKeyDnsSource = "dns_source"; + + /** + * 请求记录 key:DNS 解析错误信息 + */ public static final String RequestKeyDnsErrorMessage = "dns_error_message"; + + /** + * 请求记录 key:是否为劫持 + */ public static final String RequestKeyHijacking = "hijacking"; + + /** + * 请求记录 key:DNS 解析时间 + */ public static final String RequestKeyPrefetchedBefore = "prefetched_before"; + + /** + * 请求记录 key:DNS 解析错误信息 + */ public static final String RequestKeyPrefetchedErrorMessage = "prefetched_error_message"; + + /** + * 请求记录 key:网络情况 + */ public static final String RequestKeyNetworkMeasuring = "network_measuring"; + + /** + * 请求记录 key:网络上传速度 + */ public static final String RequestKeyPerceptiveSpeed = "perceptive_speed"; // 分块上传统计⽇志 + /** + * 分块记录 key:日志类型 + */ public static final String BlockKeyLogType = "log_type"; + + /** + * 分块记录 key:上传时间 + */ public static final String BlockKeyUpTime = "up_time"; + + /** + * 分块记录 key:目标 Bucket + */ public static final String BlockKeyTargetBucket = "target_bucket"; + + /** + * 分块记录 key:存储的 key + */ public static final String BlockKeyTargetKey = "target_key"; + + /** + * 分块记录 key:目标区域 ID + */ public static final String BlockKeyTargetRegionId = "target_region_id"; + + /** + * 分块记录 key:当前区域 ID + */ public static final String BlockKeyCurrentRegionId = "current_region_id"; + + /** + * 分块记录 key:总耗时 + */ public static final String BlockKeyTotalElapsedTime = "total_elapsed_time"; + + /** + * 分块记录 key:上传字节大小 + */ public static final String BlockKeyBytesSent = "bytes_sent"; + + /** + * 分块记录 key:断点续传开始偏移 + */ public static final String BlockKeyRecoveredFrom = "recovered_from"; + + /** + * 分块记录 key:上传文件大小 + */ public static final String BlockKeyFileSize = "file_size"; + + /** + * 分块记录 key:pid + */ public static final String BlockKeyPid = "pid"; + + /** + * 分块记录 key:tid + */ public static final String BlockKeyTid = "tid"; + + /** + * 分块记录 key:上传的 api + */ public static final String BlockKeyUpApiVersion = "up_api_version"; + + /** + * 分块记录 key:客户端时间 + */ public static final String BlockKeyClientTime = "client_time"; + + /** + * 分块记录 key:系统名称 + */ public static final String BlockKeyOsName = "os_name"; + + /** + * 分块记录 key:系统版本 + */ public static final String BlockKeyOsVersion = "os_version"; + + /** + * 分块记录 key:SDK 名 + */ public static final String BlockKeySDKName = "sdk_name"; + + /** + * 分块记录 key:SDK 版本 + */ public static final String BlockKeySDKVersion = "sdk_version"; + + /** + * 分块记录 key:上传速度 + */ public static final String BlockKeyPerceptiveSpeed = "perceptive_speed"; + + /** + * 分块记录 key:是否被劫持 + */ public static final String BlockKeyHijacking = "hijacking"; // 上传质量统计 + /** + * 上传质量记录 key:日志类型 + */ public static final String QualityKeyLogType = "log_type"; + + /** + * 上传质量记录 key:上传类型 + */ public static final String QualityKeyUpType = "up_type"; + + /** + * 上传质量记录 key:上传时间 + */ public static final String QualityKeyUpTime = "up_time"; + + /** + * 上传质量记录 key:上传结果 + */ public static final String QualityKeyResult = "result"; + + /** + * 上传质量记录 key:上传的目标 Bucket + */ public static final String QualityKeyTargetBucket = "target_bucket"; + + /** + * 上传质量记录 key:存储的 key + */ public static final String QualityKeyTargetKey = "target_key"; + + /** + * 上传质量记录 key:上传总耗时 + */ public static final String QualityKeyTotalElapsedTime = "total_elapsed_time"; + + /** + * 上传质量记录 key:上传中 UC query 耗时 + */ public static final String QualityKeyUcQueryElapsedTime = "uc_query_elapsed_time"; + + /** + * 上传质量记录 key:上传使用的请求数量 + */ public static final String QualityKeyRequestsCount = "requests_count"; + + /** + * 上传质量记录 key:上传使用的区域数量 + */ public static final String QualityKeyRegionsCount = "regions_count"; + + /** + * 上传质量记录 key:上传的文件大小 + */ public static final String QualityKeyFileSize = "file_size"; + + /** + * 上传质量记录 key:上传发送的字节数 + */ public static final String QualityKeyBytesSent = "bytes_sent"; + + /** + * 上传质量记录 key:cloud 类型 + */ public static final String QualityKeyCloudType = "cloud_type"; + + /** + * 上传质量记录 key:上传的错误类型 + */ public static final String QualityKeyErrorType = "error_type"; + + /** + * 上传质量记录 key:上传的错误信息 + */ public static final String QualityKeyErrorDescription = "error_description"; + + /** + * 上传质量记录 key:操作系统名称 + */ public static final String QualityKeyOsName = "os_name"; + + /** + * 上传质量记录 key:操作系统版本 + */ public static final String QualityKeyOsVersion = "os_version"; + + /** + * 上传质量记录 key:SDK 名 + */ public static final String QualityKeySDKName = "sdk_name"; + + /** + * 上传质量记录 key:SDK 版本 + */ public static final String QualityKeySDKVersion = "sdk_version"; + + /** + * 上传质量记录 key:上传速度 + */ public static final String QualityKeyPerceptiveSpeed = "perceptive_speed"; + + /** + * 上传质量记录 key:是否劫持 + */ public static final String QualityKeyHijacking = "hijacking"; - public static String requestReportStatusCode(ResponseInfo responseInfo){ - if (responseInfo == null){ + /** + * 获取请求的状态码 + * + * @param responseInfo 请求响应 + * @return 请求的状态码 + */ + public static String requestReportStatusCode(ResponseInfo responseInfo) { + if (responseInfo == null) { return null; } else { return responseInfo.statusCode + ""; } } - public static String requestReportErrorType(ResponseInfo responseInfo){ - if (responseInfo == null){ + /** + * 获取请求错误类型 + * + * @param responseInfo 请求响应 + * @return 请求的错误类型 + */ + public static String requestReportErrorType(ResponseInfo responseInfo) { + if (responseInfo == null) { return "unknown_error"; } String errorType = null; if (responseInfo.statusCode > 199 && responseInfo.statusCode < 300) { - } else if (responseInfo.statusCode > 299){ + } else if (responseInfo.statusCode > 299) { errorType = "response_error"; - } else if (responseInfo.statusCode == ResponseInfo.NetworkError){ + } else if (responseInfo.statusCode == ResponseInfo.NetworkError) { errorType = "network_error"; - } else if (responseInfo.statusCode == ResponseInfo.TimedOut){ + } else if (responseInfo.statusCode == ResponseInfo.TimedOut) { errorType = "timeout"; - } else if (responseInfo.statusCode == ResponseInfo.UnknownHost){ + } else if (responseInfo.statusCode == ResponseInfo.UnknownHost) { errorType = "unknown_host"; - } else if (responseInfo.statusCode == ResponseInfo.CannotConnectToHost){ + } else if (responseInfo.statusCode == ResponseInfo.CannotConnectToHost) { errorType = "cannot_connect_to_host"; - } else if (responseInfo.statusCode == ResponseInfo.NetworkConnectionLost){ + } else if (responseInfo.statusCode == ResponseInfo.NetworkConnectionLost) { errorType = "transmission_error"; - } else if (responseInfo.statusCode == ResponseInfo.NetworkSSLError){ + } else if (responseInfo.statusCode == ResponseInfo.NetworkSSLError) { errorType = "ssl_error"; - } else if (responseInfo.statusCode == ResponseInfo.ParseError){ + } else if (responseInfo.statusCode == ResponseInfo.ParseError) { errorType = "parse_error"; - } else if (responseInfo.statusCode == ResponseInfo.MaliciousResponseError){ + } else if (responseInfo.statusCode == ResponseInfo.MaliciousResponseError) { errorType = "malicious_response"; - } else if (responseInfo.statusCode == ResponseInfo.Cancelled){ + } else if (responseInfo.statusCode == ResponseInfo.Cancelled) { errorType = "user_canceled"; - } else if (responseInfo.statusCode == ResponseInfo.LocalIOError){ + } else if (responseInfo.statusCode == ResponseInfo.LocalIOError) { errorType = "local_io_error"; - } else if (responseInfo.statusCode == ResponseInfo.NetworkProtocolError){ + } else if (responseInfo.statusCode == ResponseInfo.NetworkProtocolError) { errorType = "protocol_error"; - } else if (responseInfo.statusCode == ResponseInfo.NetworkSlow){ + } else if (responseInfo.statusCode == ResponseInfo.NetworkSlow) { errorType = "network_slow"; } else { errorType = "unknown_error"; @@ -184,8 +566,14 @@ public static String requestReportErrorType(ResponseInfo responseInfo){ return errorType; } - public static String qualityResult(ResponseInfo responseInfo){ - if (responseInfo == null){ + /** + * 获取上传的结果 + * + * @param responseInfo 请求响应 + * @return 上传的结果 + */ + public static String qualityResult(ResponseInfo responseInfo) { + if (responseInfo == null) { return "unknown_error"; } @@ -194,20 +582,20 @@ public static String qualityResult(ResponseInfo responseInfo){ if (responseInfo.statusCode > 199 && responseInfo.statusCode < 300) { result = "ok"; } else if (responseInfo.statusCode > 399 && - (responseInfo.statusCode < 500 || responseInfo.statusCode == 573 || responseInfo.statusCode == 579 || - responseInfo.statusCode == 608 || responseInfo.statusCode == 612 || responseInfo.statusCode == 614 || responseInfo.statusCode == 630 || responseInfo.statusCode == 631 || - responseInfo.statusCode == 701)) { + (responseInfo.statusCode < 500 || responseInfo.statusCode == 573 || responseInfo.statusCode == 579 || + responseInfo.statusCode == 608 || responseInfo.statusCode == 612 || responseInfo.statusCode == 614 || responseInfo.statusCode == 630 || responseInfo.statusCode == 631 || + responseInfo.statusCode == 701)) { result = "bad_request"; - } else if (responseInfo.statusCode == ResponseInfo.ZeroSizeFile){ + } else if (responseInfo.statusCode == ResponseInfo.ZeroSizeFile) { result = "zero_size_file"; - } else if (responseInfo.statusCode == ResponseInfo.InvalidFile){ + } else if (responseInfo.statusCode == ResponseInfo.InvalidFile) { result = "invalid_file"; } else if (responseInfo.statusCode == ResponseInfo.InvalidToken - || responseInfo.statusCode == ResponseInfo.InvalidArgument){ + || responseInfo.statusCode == ResponseInfo.InvalidArgument) { result = "invalid_args"; } - if (result == null){ + if (result == null) { result = requestReportErrorType(responseInfo); } diff --git a/library/src/main/java/com/qiniu/android/collect/UploadInfoReporter.java b/library/src/main/java/com/qiniu/android/collect/UploadInfoReporter.java index 0c25a6019..032482b95 100644 --- a/library/src/main/java/com/qiniu/android/collect/UploadInfoReporter.java +++ b/library/src/main/java/com/qiniu/android/collect/UploadInfoReporter.java @@ -29,6 +29,9 @@ import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; +/** + * 记录上报 + */ public class UploadInfoReporter { private static final String DelayReportTransactionName = "com.qiniu.uplog"; private ReportConfig config = ReportConfig.getInstance(); @@ -50,10 +53,21 @@ public class UploadInfoReporter { private UploadInfoReporter() { } + /** + * 获取上报单例 + * + * @return 上报单例 + */ public static UploadInfoReporter getInstance() { return instance; } + /** + * 上报记录 + * + * @param reportItem 记录信息 + * @param tokenString Token + */ public synchronized void report(final ReportItem reportItem, final String tokenString) { if (!checkReportAvailable() || reportItem == null || tokenString == null || tokenString.length() == 0) { return; @@ -76,6 +90,9 @@ public void run() { }); } + /** + * 清理 + */ public void clean() { cleanRecorderFile(); cleanTempLogFile(); @@ -151,7 +168,7 @@ private void saveReportJsonString(final String jsonString) { private void reportToServerIfNeeded(final String tokenString) { boolean needToReport = false; long currentTime = Utils.currentSecondTimestamp(); - final long interval = (long)(config.interval * 60); + final long interval = (long) (config.interval * 60); if (recorderTempFile.exists()) { needToReport = true; } else if ((lastReportTime == 0 || (currentTime - lastReportTime) >= interval || recorderFile.length() > config.uploadThreshold) && diff --git a/library/src/main/java/com/qiniu/android/common/AutoZone.java b/library/src/main/java/com/qiniu/android/common/AutoZone.java index 6194f4bc3..22d22fd8c 100644 --- a/library/src/main/java/com/qiniu/android/common/AutoZone.java +++ b/library/src/main/java/com/qiniu/android/common/AutoZone.java @@ -40,6 +40,12 @@ public final class AutoZone extends Zone { .setVersion("v1") .builder(); + /** + * 构造函数 + */ + public AutoZone() { + } + /** * 配置 UC 域名,此 UC 域名用于根据上传 bucket 查询对应的区域。 * 公有云不用配置 diff --git a/library/src/main/java/com/qiniu/android/common/Config.java b/library/src/main/java/com/qiniu/android/common/Config.java index 6422a1343..592bc354c 100644 --- a/library/src/main/java/com/qiniu/android/common/Config.java +++ b/library/src/main/java/com/qiniu/android/common/Config.java @@ -6,10 +6,12 @@ * Created by Simon on 11/22/16. */ public final class Config { + /** * 上传信息收集文件的地址 只保留域名部分 eg:uplog.qbox.me */ public final static String upLogURL = "uplog.qbox.me"; + /** * 是否记录上传状态信息。 true 表示记录,false 表示不记录。 *

@@ -20,6 +22,7 @@ public final class Config { * 记录文件大小 大于 maxRecordFileSize 时, 则暂停记录信息。 */ public static boolean isRecord = true; + /** * 是否上传记录的上传状态信息。true 表示上传,false 表示不上传。 *

@@ -32,6 +35,7 @@ public final class Config { * 上传成功后,清空记录文件文件 */ public static boolean isUpload = true; + /** * 上传信息记录文件保存的目录, 绝对路径。 * 默认使用当前应用的缓存目录: getCacheDir() @@ -117,4 +121,7 @@ public static void slow() { uploadThreshold = 150 * 1024; interval = 300; } + + private Config() { + } } diff --git a/library/src/main/java/com/qiniu/android/common/Constants.java b/library/src/main/java/com/qiniu/android/common/Constants.java index 8d71795e3..88977b8de 100644 --- a/library/src/main/java/com/qiniu/android/common/Constants.java +++ b/library/src/main/java/com/qiniu/android/common/Constants.java @@ -15,4 +15,7 @@ public final class Constants { * UTF-8 编码 */ public static final String UTF_8 = "utf-8"; + + private Constants() { + } } diff --git a/library/src/main/java/com/qiniu/android/common/FixedZone.java b/library/src/main/java/com/qiniu/android/common/FixedZone.java index c291f3d43..6ae125c07 100644 --- a/library/src/main/java/com/qiniu/android/common/FixedZone.java +++ b/library/src/main/java/com/qiniu/android/common/FixedZone.java @@ -110,6 +110,12 @@ public static FixedZone localsZoneInfo() { return zone; } + /** + * 把多个 Zone 合并成一个 Zone Group,重试时会依次切换不同 Zone 进行重试 + * + * @param zones zones + * @return Zone Group + */ public static FixedZone combineZones(FixedZone[] zones) { if (zones == null || zones.length == 0) { return null; diff --git a/library/src/main/java/com/qiniu/android/common/Zone.java b/library/src/main/java/com/qiniu/android/common/Zone.java index 5fd652898..c2e6bb3aa 100644 --- a/library/src/main/java/com/qiniu/android/common/Zone.java +++ b/library/src/main/java/com/qiniu/android/common/Zone.java @@ -9,6 +9,12 @@ */ public abstract class Zone { + /** + * 构造函数 + */ + protected Zone() { + } + /** * 根据上传 token 获取 zone * @@ -29,6 +35,13 @@ public abstract class Zone { * 预查询结束回调 */ public interface QueryHandler { + /** + * 预查询结束回调 + * + * @param code 状态码 + * @param responseInfo 查询响应 + * @param metrics 查询指标 + */ void complete(int code, ResponseInfo responseInfo, UploadRegionRequestMetrics metrics); } } diff --git a/library/src/main/java/com/qiniu/android/common/ZoneInfo.java b/library/src/main/java/com/qiniu/android/common/ZoneInfo.java index 9a3374b3c..641e611c1 100644 --- a/library/src/main/java/com/qiniu/android/common/ZoneInfo.java +++ b/library/src/main/java/com/qiniu/android/common/ZoneInfo.java @@ -15,32 +15,83 @@ /** * Created by jemy on 17/04/2017. */ - public class ZoneInfo implements Cloneable { - // 只允许内部使用 + /** + * 默认 io host + * 只允许内部使用 + */ public final static String SDKDefaultIOHost = "sdkDefaultIOHost"; + + /** + * 未知 region id + */ public final static String EmptyRegionId = "unknown"; private static int DOMAIN_FROZEN_SECONDS = 10 * 60; + /** + * 有效时间 + */ public final int ttl; + + /** + * 是否允许 HTTP/3 + */ public final boolean http3Enabled; + + /** + * 是否是 IPv6 + */ public final boolean ipv6; + + /** + * 主要域名 + */ public final List domains; + + /** + * 备用域名 + */ public final List old_domains; + /** + * regionId + */ public final String regionId; + + /** + * 所有域名 + */ public List allHosts; + + /** + * detailInfo + */ public JSONObject detailInfo; private final Date buildDate; + /** + * 构造函数 + * + * @param mainHosts 主要域名 + * @param regionId 区域 ID + * @return ZoneInfo + */ public static ZoneInfo buildInfo(List mainHosts, String regionId) { return buildInfo(mainHosts, null, regionId); } + /** + * 构造函数 + * + * @param mainHosts 主要域名 + * @param oldHosts 备用域名 + * @param regionId 区域 ID + * @return ZoneInfo + */ public static ZoneInfo buildInfo(List mainHosts, List oldHosts, String regionId) { @@ -98,9 +149,11 @@ private ZoneInfo(int ttl, } /** + * 构造函数 + * * @param obj Not allowed to be null - * @return - * @throws JSONException + * @return ZoneInfo + * @throws JSONException 异常 */ public static ZoneInfo buildFromJson(JSONObject obj) throws JSONException { if (obj == null) { @@ -169,10 +222,20 @@ public static ZoneInfo buildFromJson(JSONObject obj) throws JSONException { return zoneInfo; } + /** + * 获取区域 ID + * + * @return 区域 ID + */ public String getRegionId() { return regionId; } + /** + * 转字符串 + * + * @return 字符串 + */ @Override public String toString() { Map m = new HashMap(); @@ -181,6 +244,11 @@ public String toString() { return new JSONObject(m).toString(); } + /** + * 是否有效 + * + * @return 是否有效 + */ public boolean isValid() { if (buildDate == null) { return false; @@ -191,6 +259,12 @@ public boolean isValid() { return ttl > (currentTimestamp - buildTimestamp); } + /** + * clone + * + * @return Object + * @throws CloneNotSupportedException 异常 + */ @Override protected Object clone() throws CloneNotSupportedException { ZoneInfo info = new ZoneInfo(ttl, http3Enabled, ipv6, regionId, domains, old_domains, buildDate); @@ -198,13 +272,38 @@ protected Object clone() throws CloneNotSupportedException { return info; } + /** + * server group + */ @Deprecated public static class UploadServerGroup { + + /** + * 备注信息 + */ public final String info; + + /** + * 主要域名 + */ public final ArrayList main; + + /** + * 备用域名 + */ public final ArrayList backup; + + /** + * 所有域名 + */ public final ArrayList allHosts; + /** + * 构造函数 + * + * @param jsonObject json + * @return UploadServerGroup + */ public static UploadServerGroup buildInfoFromJson(JSONObject jsonObject) { if (jsonObject == null) { return null; @@ -243,6 +342,14 @@ public static UploadServerGroup buildInfoFromJson(JSONObject jsonObject) { return new UploadServerGroup(info, main, backup, allHosts); } + /** + * 构造函数 + * + * @param info 备注信息 + * @param main 主要域名 + * @param backup 备用域名 + * @param allHosts 所有域名 + */ public UploadServerGroup(String info, ArrayList main, ArrayList backup, diff --git a/library/src/main/java/com/qiniu/android/common/ZonesInfo.java b/library/src/main/java/com/qiniu/android/common/ZonesInfo.java index 087dc334f..0160aecb8 100644 --- a/library/src/main/java/com/qiniu/android/common/ZonesInfo.java +++ b/library/src/main/java/com/qiniu/android/common/ZonesInfo.java @@ -8,15 +8,26 @@ import java.util.ArrayList; import java.util.List; +/** + * ZonesInfo + */ public class ZonesInfo implements Cloneable, Cache.Object { // 临时 zone,不建议长期使用 private boolean isTemporary; + /** + * zonesInfo + */ public final ArrayList zonesInfo = new ArrayList<>(); private JSONObject jsonInfo; + /** + * 构造函数 + * + * @param jsonObject jsonObject + */ public ZonesInfo(JSONObject jsonObject) { if (jsonObject == null) { return; @@ -40,19 +51,41 @@ public ZonesInfo(JSONObject jsonObject) { } } + /** + * 构造函数 + * + * @param zonesInfo zonesInfo + */ public ZonesInfo(List zonesInfo) { this(zonesInfo, false); } + /** + * 构造函数,内部使用 + * + * @param zonesInfo zonesInfo + * @param isTemporary 是否临时对象 + */ public ZonesInfo(List zonesInfo, boolean isTemporary) { this(createJsonWithZoneInfoList(zonesInfo)); this.isTemporary = isTemporary; } + /** + * 构造函数 + * + * @param jsonObject json + * @return ZonesInfo + */ public static ZonesInfo createZonesInfo(JSONObject jsonObject) { return new ZonesInfo(jsonObject); } + /** + * 是否有效 + * + * @return 是否有效 + */ public boolean isValid() { if (zonesInfo == null || zonesInfo.isEmpty()) { return false; @@ -68,17 +101,31 @@ public boolean isValid() { return valid; } + /** + * 是否是临时对象 + * + * @return 是否是临时对象 + */ @Deprecated // 是否为临时 zone, 临时 zone,不建议长期使用 public boolean isTemporary() { return isTemporary; } + /** + * 转为临时对象 + */ @Deprecated public void toTemporary() { isTemporary = true; } + /** + * clone + * + * @return Object + * @throws CloneNotSupportedException 异常 + */ @Override protected Object clone() throws CloneNotSupportedException { ArrayList infos = new ArrayList<>(); @@ -92,6 +139,11 @@ protected Object clone() throws CloneNotSupportedException { return info; } + /** + * 转 json + * + * @return json + */ @Override public JSONObject toJson() { return jsonInfo; diff --git a/library/src/main/java/com/qiniu/android/http/CancellationHandler.java b/library/src/main/java/com/qiniu/android/http/CancellationHandler.java index 7e1ad8951..8bacb8fbc 100644 --- a/library/src/main/java/com/qiniu/android/http/CancellationHandler.java +++ b/library/src/main/java/com/qiniu/android/http/CancellationHandler.java @@ -18,5 +18,11 @@ public interface CancellationHandler { * 取消异常 */ class CancellationException extends IOException { + + /** + * 构造函数 + */ + public CancellationException() { + } } } diff --git a/library/src/main/java/com/qiniu/android/http/Headers.java b/library/src/main/java/com/qiniu/android/http/Headers.java index db8a4f139..3f74100d9 100644 --- a/library/src/main/java/com/qiniu/android/http/Headers.java +++ b/library/src/main/java/com/qiniu/android/http/Headers.java @@ -306,7 +306,7 @@ public String toString() { /** * toMultimap * - * @return Map> + * @return Map */ public Map> toMultimap() { Map> result = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); @@ -328,6 +328,12 @@ public Map> toMultimap() { public static final class Builder { final List namesAndValues = new ArrayList<>(20); + /** + * 构造函数 + */ + public Builder() { + } + /** * Add a header line without any validation. Only appropriate for headers from the remote peer * or cache. diff --git a/library/src/main/java/com/qiniu/android/http/HttpDate.java b/library/src/main/java/com/qiniu/android/http/HttpDate.java index fa836ef03..0dae42047 100644 --- a/library/src/main/java/com/qiniu/android/http/HttpDate.java +++ b/library/src/main/java/com/qiniu/android/http/HttpDate.java @@ -61,6 +61,9 @@ protected DateFormat initialValue() { /** * Returns the date for {@code value}. Returns null if the value couldn't be parsed. + * + * @param value value + * @return Date */ public static Date parse(String value) { if (TextUtils.isEmpty(value)) { @@ -102,6 +105,7 @@ public static Date parse(String value) { /** * Returns the string for {@code value}. * + * @param value Date * @return the string for {@code value}. */ public static String format(Date value) { diff --git a/library/src/main/java/com/qiniu/android/http/ProxyConfiguration.java b/library/src/main/java/com/qiniu/android/http/ProxyConfiguration.java index da9d12845..fac127e20 100644 --- a/library/src/main/java/com/qiniu/android/http/ProxyConfiguration.java +++ b/library/src/main/java/com/qiniu/android/http/ProxyConfiguration.java @@ -13,17 +13,39 @@ */ public final class ProxyConfiguration { + /** + * hostAddress + */ public final String hostAddress; + + /** + * port + */ public final int port; + + /** + * user + */ public final String user; + + /** + * password + */ public final String password; + + /** + * type + */ public final Proxy.Type type; /** + * 构造函数 + * * @param hostAddress 服务器域名或IP,比如proxy.com, 192.168.1.1 * @param port 端口 * @param user 用户名,无则填null * @param password 用户密码,无则填null + * @param type proxy type */ public ProxyConfiguration(String hostAddress, int port, String user, String password, java.net.Proxy.Type type) { this.hostAddress = hostAddress; @@ -33,14 +55,30 @@ public ProxyConfiguration(String hostAddress, int port, String user, String pass this.type = type; } + /** + * 构造函数 + * + * @param hostAddress 服务器域名或IP,比如proxy.com, 192.168.1.1 + * @param port 端口 + */ public ProxyConfiguration(String hostAddress, int port) { this(hostAddress, port, null, null, Proxy.Type.HTTP); } + /** + * 获取 proxy + * + * @return proxy + */ public Proxy proxy() { return new Proxy(type, new InetSocketAddress(hostAddress, port)); } + /** + * 获取 authenticator + * + * @return Authenticator + */ public Authenticator authenticator() { return new Authenticator() { @Override diff --git a/library/src/main/java/com/qiniu/android/http/ResponseInfo.java b/library/src/main/java/com/qiniu/android/http/ResponseInfo.java index 780ac6802..2396986ef 100644 --- a/library/src/main/java/com/qiniu/android/http/ResponseInfo.java +++ b/library/src/main/java/com/qiniu/android/http/ResponseInfo.java @@ -31,12 +31,15 @@ public final class ResponseInfo { */ public static final int UnexpectedSysCallError = -10; + /** + * 无可用于上传的 host, 所有主备 host 均已尝试 + */ @Deprecated public static final int NoUsableHostError = -9; /** * 在上传时,SDK 内部业务逻辑非预期。正常情况下,此错误并会被抛掷应用层。 - * + *

* 此错误出现的原因一般为某个上传流程异常请求导致,实际应该抛出请求,但因为调用异常未被抛出。 */ public static final int SDKInteriorError = -9; @@ -81,9 +84,15 @@ public final class ResponseInfo { */ public static final int NetworkError = -1; + /** + * 上传数据 crc32 校验失败 + */ @Deprecated public static final int Crc32NotMatch = -406; + /** + * 未知错误 + */ @Deprecated public static final int UnknownError = 10000; @@ -129,6 +138,9 @@ public final class ResponseInfo { */ public static final int ParseError = -1015; + /** + * 响应解析异常 + */ @Deprecated public static final int PasrseError = -1015; @@ -147,22 +159,27 @@ public final class ResponseInfo { * response 信息 */ public String message; + /** * 七牛日志扩展头 */ public final String reqId; + /** * 七牛日志扩展头 */ public final String xlog; + /** * cdn日志扩展头 */ public final String xvia; + /** * 错误信息 */ public final String error; + /** * 服务器域名 */ @@ -222,61 +239,148 @@ private ResponseInfo(JSONObject json, } } + /** + * 构造成功响应 + * + * @return ResponseInfo + */ public static ResponseInfo successResponse() { ResponseInfo responseInfo = new ResponseInfo(null, null, null, RequestSuccess, "inter:reqid", "inter:xlog", "inter:xvia", null, null); return responseInfo; } + /** + * 构造文件为空响应 + * + * @param desc 描述信息 + * @return ResponseInfo + */ public static ResponseInfo zeroSize(String desc) { return errorInfo(ZeroSizeFile, (desc != null ? desc : "data size is 0")); } + /** + * 构造取消响应 + * + * @return ResponseInfo + */ public static ResponseInfo cancelled() { return errorInfo(Cancelled, "cancelled by user"); } + /** + * 构造无效参数响应 + * + * @param desc 描述信息 + * @return ResponseInfo + */ public static ResponseInfo invalidArgument(String desc) { return errorInfo(InvalidArgument, desc); } + /** + * 构造无效 Token 响应 + * + * @param desc 描述信息 + * @return ResponseInfo + */ public static ResponseInfo invalidToken(String desc) { return errorInfo(InvalidToken, desc); } + /** + * 构造文件异常响应 + * + * @param e 异常信息 + * @return ResponseInfo + */ public static ResponseInfo fileError(Exception e) { return errorInfo(InvalidFile, e != null ? e.getMessage() : null); } + /** + * 构造网络异常响应 + * + * @param desc 描述信息 + * @return ResponseInfo + */ public static ResponseInfo networkError(String desc) { return errorInfo(NetworkError, desc); } + /** + * 构造本地调用异常响应 + * + * @param desc 描述信息 + * @return ResponseInfo + */ public static ResponseInfo localIOError(String desc) { return errorInfo(LocalIOError, desc); } + /** + * 构造异常响应 + * + * @param desc 描述信息 + * @return ResponseInfo + */ public static ResponseInfo maliciousResponseError(String desc) { return errorInfo(MaliciousResponseError, desc); } + /** + * 构造无上传域名异常响应 + * + * @param desc 描述信息 + * @return ResponseInfo + */ @Deprecated public static ResponseInfo noUsableHostError(String desc) { return errorInfo(NoUsableHostError, desc); } + /** + * 构造 SDK 内部异常响应 + * + * @param desc 描述信息 + * @return ResponseInfo + */ public static ResponseInfo sdkInteriorError(String desc) { return errorInfo(SDKInteriorError, desc); } + /** + * 构造系统调用异常响应 + * + * @param desc 描述信息 + * @return ResponseInfo + */ public static ResponseInfo unexpectedSysCallError(String desc) { return errorInfo(UnexpectedSysCallError, desc); } + /** + * 构造异常响应 + * + * @param statusCode 状态码 + * @param error 错误信息 + * @return ResponseInfo + */ public static ResponseInfo errorInfo(int statusCode, String error) { ResponseInfo responseInfo = new ResponseInfo(null, null, "", statusCode, null, null, null, null, error); return responseInfo; } + /** + * 构造响应 + * + * @param request 请求对象 + * @param responseCode 响应码 + * @param responseHeader 响应头 + * @param response 响应信息 + * @param errorMessage 错误信息 + * @return ResponseInfo + */ public static ResponseInfo create(Request request, int responseCode, Map responseHeader, @@ -285,6 +389,17 @@ public static ResponseInfo create(Request request, return create(request, null, responseCode, responseHeader, response, errorMessage); } + /** + * 构造响应 + * + * @param request 请求对象 + * @param httpVersion 请求版本信息 + * @param responseCode 响应码 + * @param responseHeader 响应头 + * @param response 响应信息 + * @param errorMessage 错误信息 + * @return ResponseInfo + */ public static ResponseInfo create(Request request, String httpVersion, int responseCode, @@ -312,6 +427,11 @@ public static ResponseInfo create(Request request, return responseInfo; } + /** + * 价差是否是异常请求 + * + * @return ResponseInfo + */ public ResponseInfo checkMaliciousResponse() { if (statusCode == 200 && (reqId == null && xlog == null)) { return new ResponseInfo(null, responseHeader, httpVersion, MaliciousResponseError, reqId, xlog, xvia, host, "this is a malicious response"); @@ -320,20 +440,41 @@ public ResponseInfo checkMaliciousResponse() { } } + /** + * 检查请求是否因网络问题而失败 + * + * @param code 请求响应的状态码 + * @return 是否因网络问题而失败 + */ public static boolean isStatusCodeForBrokenNetwork(int code) { return code == NetworkError || code == UnknownHost || code == CannotConnectToHost || code == TimedOut || code == NetworkConnectionLost; } + /** + * 请求是否被取消 + * + * @return 请求是否被取消 + */ public boolean isCancelled() { return statusCode == Cancelled; } + /** + * 请求是否成功 + * + * @return 请求是否成功 + */ public boolean isOK() { return statusCode == RequestSuccess && error == null && (hasReqId() || xlog != null); } + /** + * 请求是否需要重试 + * + * @return 请求是否需要重试 + */ public boolean couldRetry() { if (isNotQiniu()) { return true; @@ -357,6 +498,11 @@ public boolean couldRetry() { } } + /** + * 请求是否需要在区域间重试 + * + * @return 请求是否需要重试 + */ public boolean couldRegionRetry() { if (isNotQiniu()) { return true; @@ -376,6 +522,11 @@ public boolean couldRegionRetry() { } } + /** + * 请求是否需要在域名之间重试 + * + * @return 请求是否需要重试 + */ public boolean couldHostRetry() { if (isNotQiniu()) { return true; @@ -396,6 +547,11 @@ public boolean couldHostRetry() { } } + /** + * 请求是否发生 tls 异常 + * + * @return 是否发生 tls 异常 + */ public boolean isTlsError() { if (statusCode == NetworkSSLError) { return true; @@ -404,6 +560,11 @@ public boolean isTlsError() { } } + /** + * 请求是否连接到了服务 + * + * @return 是否连接到了服务 + */ public boolean canConnectToHost() { if (statusCode > 99 || isCancelled()) { return true; @@ -412,6 +573,11 @@ public boolean canConnectToHost() { } } + /** + * 请求的 host 是否不可用 + * + * @return host 是否不可用 + */ public boolean isHostUnavailable() { // 基本不可恢复,注:会影响下次请求,范围太大可能会造成大量的timeout if (statusCode == 502 || statusCode == 503 || statusCode == 504 || statusCode == 599) { @@ -421,28 +587,57 @@ public boolean isHostUnavailable() { } } - // 在断点续上传过程中,ctx 信息已过期。 + /** + * 在断点续上传过程中,ctx 信息是否已过期 + * + * @return ctx 信息是否已过期 + */ public boolean isCtxExpiredError() { return statusCode == 701 || (statusCode == 612 && error != null && error.contains("no such uploadId")); } + /** + * 请求是否因网络问题而失败 + * + * @return 请求是否因网络问题而失败 + */ public boolean isNetworkBroken() { return statusCode == NetworkError || statusCode == NetworkSlow; } + /** + * 请求是否是为服务端异常 + * + * @return 请求是否是为服务端异常 + */ public boolean isServerError() { return (statusCode >= 500 && statusCode < 600 && statusCode != 579) || statusCode == 996; } + /** + * 重试是否需要切换域名 + * + * @return 是否需要切换域名 + */ public boolean needSwitchServer() { return isNetworkBroken() || isServerError(); } + /** + * 是否需要重试 + * + * @return 是否需要重试 + */ public boolean needRetry() { return !isCancelled() && (needSwitchServer() || statusCode == 406 || (statusCode == 200 && error != null) || isNotQiniu()); } + /** + * 请求是否未到达七牛服务 + * + * @return 请求是否未到达七牛服务 + */ public boolean isNotQiniu() { return (statusCode == MaliciousResponseError) || (statusCode > 0 && (!hasReqId() && xlog == null)); } @@ -451,11 +646,21 @@ private boolean isQiniu() { return !isNotQiniu(); } + /** + * 获取 string 信息 + * + * @return string 信息 + */ public String toString() { return String.format(Locale.ENGLISH, "{ver:%s,ResponseInfo:%s,status:%d, reqId:%s, xlog:%s, xvia:%s, host:%s, time:%d,error:%s}", Constants.VERSION, id, statusCode, reqId, xlog, xvia, host, timeStamp, error); } + /** + * 是否有 reqId + * + * @return 是否有 reqId + */ public boolean hasReqId() { return reqId != null && reqId.length() > 0; } diff --git a/library/src/main/java/com/qiniu/android/http/UrlConverter.java b/library/src/main/java/com/qiniu/android/http/UrlConverter.java index 4a2a55f80..1b5d4600e 100644 --- a/library/src/main/java/com/qiniu/android/http/UrlConverter.java +++ b/library/src/main/java/com/qiniu/android/http/UrlConverter.java @@ -1,5 +1,15 @@ package com.qiniu.android.http; +/** + * url 拦截器 + */ public interface UrlConverter { + + /** + * url 拦截器,可以转换 url + * + * @param url url + * @return 转换后的 url + */ String convert(String url); } diff --git a/library/src/main/java/com/qiniu/android/http/UserAgent.java b/library/src/main/java/com/qiniu/android/http/UserAgent.java index bd20d21d5..9035e6b7e 100644 --- a/library/src/main/java/com/qiniu/android/http/UserAgent.java +++ b/library/src/main/java/com/qiniu/android/http/UserAgent.java @@ -18,7 +18,15 @@ */ public final class UserAgent { private static UserAgent _instance = new UserAgent(); + + /** + * id + */ public final String id; + + /** + * UserAgent + */ public final String ua; private UserAgent() { @@ -26,6 +34,11 @@ private UserAgent() { ua = getUserAgent(id); } + /** + * UserAgent + * + * @return UserAgent + */ public static UserAgent instance() { return _instance; } @@ -37,10 +50,16 @@ private static String genId() { static String getUserAgent(String id) { String addition = Utils.isDebug() ? "_Debug" : ""; - return format("QiniuAndroid%s/%s (%s; %s; %s",addition, Constants.VERSION, + return format("QiniuAndroid%s/%s (%s; %s; %s", addition, Constants.VERSION, Utils.systemVersion(), Utils.systemName(), id); } + /** + * UserAgent + * + * @param part part + * @return UserAgent + */ public String getUa(String part) { String _part = ("" + part).trim(); if (_part.length() > 15) { diff --git a/library/src/main/java/com/qiniu/android/http/connectCheck/ConnectChecker.java b/library/src/main/java/com/qiniu/android/http/connectCheck/ConnectChecker.java index 7f4228f9d..15305b31a 100644 --- a/library/src/main/java/com/qiniu/android/http/connectCheck/ConnectChecker.java +++ b/library/src/main/java/com/qiniu/android/http/connectCheck/ConnectChecker.java @@ -25,6 +25,9 @@ public class ConnectChecker { private static ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor(); private static SingleFlight singleFlight = new SingleFlight<>(); + private ConnectChecker() { + } + /** * 根据请求 metrics 判断网络是否正常连接 * diff --git a/library/src/main/java/com/qiniu/android/http/dns/DnsCacheInfo.java b/library/src/main/java/com/qiniu/android/http/dns/DnsCacheInfo.java index 0af6b3ee6..1d1ef9cc4 100644 --- a/library/src/main/java/com/qiniu/android/http/dns/DnsCacheInfo.java +++ b/library/src/main/java/com/qiniu/android/http/dns/DnsCacheInfo.java @@ -14,8 +14,19 @@ */ public class DnsCacheInfo implements java.io.Serializable { + /** + * DNS 缓存时间 + */ private String currentTime; + + /** + * 本地 IP + */ private String localIp; + + /** + * DNS 解析结果 + */ private ConcurrentHashMap> info; /** diff --git a/library/src/main/java/com/qiniu/android/http/dns/DnsPrefetchTransaction.java b/library/src/main/java/com/qiniu/android/http/dns/DnsPrefetchTransaction.java index e93f11728..42188c989 100644 --- a/library/src/main/java/com/qiniu/android/http/dns/DnsPrefetchTransaction.java +++ b/library/src/main/java/com/qiniu/android/http/dns/DnsPrefetchTransaction.java @@ -11,6 +11,9 @@ public class DnsPrefetchTransaction { private static boolean isDnsLoaded = false; + private DnsPrefetchTransaction() { + } + /** * 将 SDK 内部使用域名的 Dns 预解析操作添加到周期性的事务中 * diff --git a/library/src/main/java/com/qiniu/android/http/dns/DnsSource.java b/library/src/main/java/com/qiniu/android/http/dns/DnsSource.java index 8640d3858..a4728d3b9 100644 --- a/library/src/main/java/com/qiniu/android/http/dns/DnsSource.java +++ b/library/src/main/java/com/qiniu/android/http/dns/DnsSource.java @@ -35,6 +35,9 @@ public class DnsSource { */ public static final String None = "none"; + private DnsSource() { + } + /** * 判断解析源是否为 Doh * diff --git a/library/src/main/java/com/qiniu/android/http/dns/HttpDns.java b/library/src/main/java/com/qiniu/android/http/dns/HttpDns.java index a16de94ff..ccae65622 100644 --- a/library/src/main/java/com/qiniu/android/http/dns/HttpDns.java +++ b/library/src/main/java/com/qiniu/android/http/dns/HttpDns.java @@ -15,11 +15,19 @@ import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; +/** + * Http Dns + */ public class HttpDns extends BaseDns implements Dns { private IResolver httpIpv4Resolver; private IResolver httpIpv6Resolver; + /** + * 构造函数 + * + * @param timeout 解析超时时间 + */ public HttpDns(int timeout) { String[] dohIpv4Servers = GlobalConfiguration.getInstance().getDohIpv4Servers(); if (dohIpv4Servers != null && dohIpv4Servers.length > 0) { @@ -32,6 +40,13 @@ public HttpDns(int timeout) { } } + /** + * Dns 解析函数 + * + * @param hostname host 域名 + * @return 解析结果 + * @throws UnknownHostException 异常 + */ @Override public List lookup(String hostname) throws UnknownHostException { if (!GlobalConfiguration.getInstance().dohEnable) { diff --git a/library/src/main/java/com/qiniu/android/http/dns/SystemDns.java b/library/src/main/java/com/qiniu/android/http/dns/SystemDns.java index a89d0b292..6a24ca9f7 100644 --- a/library/src/main/java/com/qiniu/android/http/dns/SystemDns.java +++ b/library/src/main/java/com/qiniu/android/http/dns/SystemDns.java @@ -21,13 +21,28 @@ */ public class SystemDns extends BaseDns implements Dns { + /** + * 构造函数 + */ public SystemDns() { } + /** + * 构造函数 + * + * @param timeout DNS 解析超时时间 + */ public SystemDns(int timeout) { this.timeout = timeout; } + /** + * DNS 解析域名 + * + * @param hostname 域名 + * @return 解析结果 + * @throws UnknownHostException 异常 + */ public List lookupInetAddress(final String hostname) throws UnknownHostException { if (hostname == null) { throw new UnknownHostException("hostname is null"); @@ -49,6 +64,13 @@ public List call() throws Exception { } } + /** + * DNS 解析域名 + * + * @param hostname 域名 + * @return 解析结果 + * @throws UnknownHostException 异常 + */ @Override public List lookup(String hostname) throws UnknownHostException { long timestamp = new Date().getTime() / 1000; diff --git a/library/src/main/java/com/qiniu/android/http/dns/UdpDns.java b/library/src/main/java/com/qiniu/android/http/dns/UdpDns.java index 48d7ca0e8..237b6a95b 100644 --- a/library/src/main/java/com/qiniu/android/http/dns/UdpDns.java +++ b/library/src/main/java/com/qiniu/android/http/dns/UdpDns.java @@ -15,10 +15,18 @@ import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; +/** + * udp dns + */ public class UdpDns extends BaseDns implements Dns { private IResolver udpIpv4Resolver; private IResolver udpIpv6Resolver; + /** + * 构造函数 + * + * @param timeout 超时时间,单位:秒 + */ public UdpDns(int timeout) { String[] udpIpv4Servers = GlobalConfiguration.getInstance().getUdpDnsIpv4Servers(); if (udpIpv4Servers != null && udpIpv4Servers.length > 0) { @@ -31,6 +39,13 @@ public UdpDns(int timeout) { } } + /** + * 解析域名 + * + * @param hostname host 域名 + * @return 解析结果 + * @throws UnknownHostException 异常 + */ @Override public List lookup(String hostname) throws UnknownHostException { if (!GlobalConfiguration.getInstance().udpDnsEnable) { diff --git a/library/src/main/java/com/qiniu/android/http/metrics/UploadMetrics.java b/library/src/main/java/com/qiniu/android/http/metrics/UploadMetrics.java index ecfd51da2..6fbc7b4cf 100644 --- a/library/src/main/java/com/qiniu/android/http/metrics/UploadMetrics.java +++ b/library/src/main/java/com/qiniu/android/http/metrics/UploadMetrics.java @@ -4,24 +4,56 @@ import java.util.Date; +/** + * 上传指标 + */ public class UploadMetrics { + /** + * 开始时间 + */ protected Date startDate = null; + + /** + * 结束时间 + */ protected Date endDate = null; + /** + * 构造函数 + */ + protected UploadMetrics() { + } + + /** + * 开始 + */ public void start() { startDate = new Date(); } + /** + * 结束 + */ public void end() { endDate = new Date(); } + /** + * 获取开始时间 + * + * @return 开始时间 + */ public Date getStartDate() { return startDate; } - public long totalElapsedTime(){ + /** + * 获取总耗时 + * + * @return 总耗时 + */ + public long totalElapsedTime() { if (startDate == null || endDate == null) { return 0; } diff --git a/library/src/main/java/com/qiniu/android/http/metrics/UploadRegionRequestMetrics.java b/library/src/main/java/com/qiniu/android/http/metrics/UploadRegionRequestMetrics.java index 1d7b2b1e0..c31c8ff5e 100644 --- a/library/src/main/java/com/qiniu/android/http/metrics/UploadRegionRequestMetrics.java +++ b/library/src/main/java/com/qiniu/android/http/metrics/UploadRegionRequestMetrics.java @@ -7,23 +7,44 @@ import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; +/** + * 区域上传事务 + */ public class UploadRegionRequestMetrics extends UploadMetrics { + /** + * 上传区域 + */ public final IUploadRegion region; private List metricsList = new CopyOnWriteArrayList<>(); + /** + * 构造函数 + * + * @param region 上传区域 + */ public UploadRegionRequestMetrics(IUploadRegion region) { this.region = region; } + /** + * 请求的次数 + * + * @return 请求的次数 + */ public Integer requestCount() { return metricsList.size(); } + /** + * 发送数据的大小 + * + * @return 发送数据的大小 + */ public Long bytesSend() { - if (metricsList.size() == 0) { - return 0l; + if (metricsList.isEmpty()) { + return 0L; } long bytes = 0; for (UploadSingleRequestMetrics metrics : metricsList) { @@ -34,11 +55,21 @@ public Long bytesSend() { return bytes; } + /** + * 获取最后一个请求指标 + * + * @return 最后一个请求指标 + */ public UploadSingleRequestMetrics lastMetrics() { int size = metricsList.size(); return size < 1 ? null : metricsList.get(size - 1); } + /** + * 添加新的上传请求指标 + * + * @param metricsList 新的上传请求指标 + */ public void addMetricsList(List metricsList) { if (metricsList == null || metricsList.size() == 0) { return; @@ -50,6 +81,11 @@ public void addMetricsList(List metricsList) { } } + /** + * 添加新的上传请求指标 + * + * @param metrics 新的上传请求指标 + */ public void addMetrics(UploadRegionRequestMetrics metrics) { if (metrics == null || metrics.region == null || metrics.region.getZoneInfo() == null || metrics.region.getZoneInfo().regionId == null diff --git a/library/src/main/java/com/qiniu/android/http/metrics/UploadSingleRequestMetrics.java b/library/src/main/java/com/qiniu/android/http/metrics/UploadSingleRequestMetrics.java index 2534733e8..991d2d910 100644 --- a/library/src/main/java/com/qiniu/android/http/metrics/UploadSingleRequestMetrics.java +++ b/library/src/main/java/com/qiniu/android/http/metrics/UploadSingleRequestMetrics.java @@ -8,17 +8,44 @@ import java.util.Date; +/** + * 单请求的指标 + */ public class UploadSingleRequestMetrics extends UploadMetrics { + + /** + * 请求被劫持标识 + */ public static final String RequestHijacked = "forsure"; + + /** + * 请求可能被劫持标识 + */ public static final String RequestMaybeHijacked = "maybe"; // 请求是否劫持【内部使用】 private String hijacked; + /** + * 构造函数 + */ + public UploadSingleRequestMetrics() { + } + + /** + * 请求是否劫持 + * + * @return hijacked + */ public String getHijacked() { return hijacked; } + /** + * 设置 hijacked + * + * @param hijacked hijacked + */ public void setHijacked(String hijacked) { this.hijacked = hijacked; } @@ -26,10 +53,20 @@ public void setHijacked(String hijacked) { // 同步 Dns 解析源【内部使用】 private String syncDnsSource; + /** + * 获取同步安全 DNS 解析的源 + * + * @return 安全 DNS 解析的源 + */ public String getSyncDnsSource() { return syncDnsSource; } + /** + * 设置同步安全 DNS 解析的源 + * + * @param syncDnsSource 安全 DNS 解析的源 + */ public void setSyncDnsSource(String syncDnsSource) { this.syncDnsSource = syncDnsSource; } @@ -37,10 +74,20 @@ public void setSyncDnsSource(String syncDnsSource) { // 同步 Dns 解析错误信息【内部使用】 private String syncDnsError; + /** + * 获取同步 DNS 解析错误信息 + * + * @return 同步 DNS 解析错误信息 + */ public String getSyncDnsError() { return syncDnsError; } + /** + * 设置同步 DNS 解析错误信息 + * + * @param syncDnsError 同步 DNS 解析错误信息 + */ public void setSyncDnsError(String syncDnsError) { this.syncDnsError = syncDnsError; } @@ -48,10 +95,20 @@ public void setSyncDnsError(String syncDnsError) { // 网络检测信息,只有进行网络检测才会有 connectCheckMetrics 【内部使用】 private UploadSingleRequestMetrics connectCheckMetrics; + /** + * 获取网络检测指标 + * + * @return 网络检测指标 + */ public UploadSingleRequestMetrics getConnectCheckMetrics() { return connectCheckMetrics; } + /** + * 设置网络检测指标 + * + * @param connectCheckMetrics 网络检测指标 + */ public void setConnectCheckMetrics(UploadSingleRequestMetrics connectCheckMetrics) { this.connectCheckMetrics = connectCheckMetrics; } @@ -59,10 +116,20 @@ public void setConnectCheckMetrics(UploadSingleRequestMetrics connectCheckMetric // 请求对象【自定义对象,请保证对象的此属性不为空】 private Request request; + /** + * 获取请求 + * + * @return 请求 + */ public Request getRequest() { return request; } + /** + * 设置请求 + * + * @param request 请求 + */ public void setRequest(Request request) { if (request != null) { this.request = request.copyWithoutBody(); @@ -81,10 +148,20 @@ public void setRequest(Request request) { // 请求的响应对象【自定义对象,请保证对象的此属性不为空】 private ResponseInfo response; + /** + * 获取请求响应 + * + * @return 请求响应 + */ public ResponseInfo getResponse() { return response; } + /** + * 设置请求响应 + * + * @param response 设置请求响应 + */ public void setResponse(ResponseInfo response) { this.response = response; } @@ -92,10 +169,20 @@ public void setResponse(ResponseInfo response) { // 实际请求使用的 httpVersion【自定义对象,请保证对象的此属性不为空】 private String httpVersion; + /** + * 获取请求 HTTP 版本 + * + * @return 请求 HTTP 版本 + */ public String getHttpVersion() { return httpVersion; } + /** + * 设置请求 HTTP 版本 + * + * @param httpVersion 请求 HTTP 版本 + */ public void setHttpVersion(String httpVersion) { this.httpVersion = httpVersion; } @@ -103,10 +190,20 @@ public void setHttpVersion(String httpVersion) { // 请求使用的 Client 名称 private String clientName = "customized"; + /** + * 获取 client 名 + * + * @return client 名 + */ public String getClientName() { return clientName; } + /** + * 设置 client 名 + * + * @param clientName client 名 + */ public void setClientName(String clientName) { this.clientName = clientName; } @@ -114,10 +211,20 @@ public void setClientName(String clientName) { // 请求使用的 Client 的版本信息 private String clientVersion = "unknown"; + /** + * 获取 client 版本 + * + * @return client 版本 + */ public String getClientVersion() { return clientVersion; } + /** + * 设置 client 版本 + * + * @param clientVersion client 版本 + */ public void setClientVersion(String clientVersion) { this.clientVersion = clientVersion; } @@ -125,10 +232,20 @@ public void setClientVersion(String clientVersion) { // dns 解析开始时间 【自定义对象,请保证对象的此属性不为空】 private Date domainLookupStartDate; + /** + * 获取 dns 解析开始时间 + * + * @return dns 解析开始时间 + */ public Date getDomainLookupStartDate() { return domainLookupStartDate; } + /** + * 配置 dns 解析开始时间 + * + * @param domainLookupStartDate dns 解析开始时间 + */ public void setDomainLookupStartDate(Date domainLookupStartDate) { this.domainLookupStartDate = domainLookupStartDate; } @@ -136,10 +253,20 @@ public void setDomainLookupStartDate(Date domainLookupStartDate) { // dns 解析结束时间 【自定义对象,请保证对象的此属性不为空】 private Date domainLookupEndDate; + /** + * 获取 dns 解析结束时间 + * + * @return dns 解析结束时间 + */ public Date getDomainLookupEndDate() { return domainLookupEndDate; } + /** + * 设置 dns 解析结束时间 + * + * @param domainLookupEndDate dns 解析结束时间 + */ public void setDomainLookupEndDate(Date domainLookupEndDate) { this.domainLookupEndDate = domainLookupEndDate; } @@ -147,10 +274,20 @@ public void setDomainLookupEndDate(Date domainLookupEndDate) { // connect 开始时间 【自定义对象,请保证对象的此属性不为空】 private Date connectStartDate; + /** + * 获取链接建立开始时间 + * + * @return 链接建立开始时间 + */ public Date getConnectStartDate() { return connectStartDate; } + /** + * 设置链接建立开始时间 + * + * @param connectStartDate 链接建立开始时间 + */ public void setConnectStartDate(Date connectStartDate) { this.connectStartDate = connectStartDate; } @@ -158,10 +295,20 @@ public void setConnectStartDate(Date connectStartDate) { // connect 结束时间 【自定义对象,请保证对象的此属性不为空】 private Date connectEndDate; + /** + * 获取链接建立结束时间 + * + * @return 链接建立结束时间 + */ public Date getConnectEndDate() { return connectEndDate; } + /** + * 设置链接建立结束时间 + * + * @param connectEndDate 链接建立结束时间 + */ public void setConnectEndDate(Date connectEndDate) { this.connectEndDate = connectEndDate; } @@ -169,10 +316,20 @@ public void setConnectEndDate(Date connectEndDate) { // secure connect 开始时间 【自定义对象,请保证对象的此属性不为空】 private Date secureConnectionStartDate; + /** + * 获取 tls 建立开始时间 + * + * @return tls 建立开始时间 + */ public Date getSecureConnectionStartDate() { return secureConnectionStartDate; } + /** + * 设置 tls 建立开始时间 + * + * @param secureConnectionStartDate tls 建立开始时间 + */ public void setSecureConnectionStartDate(Date secureConnectionStartDate) { this.secureConnectionStartDate = secureConnectionStartDate; } @@ -180,10 +337,20 @@ public void setSecureConnectionStartDate(Date secureConnectionStartDate) { // secure connect 结束时间 【自定义对象,请保证对象的此属性不为空】 private Date secureConnectionEndDate; + /** + * 获取 tls 建立结束时间 + * + * @return tls 建立结束时间 + */ public Date getSecureConnectionEndDate() { return secureConnectionEndDate; } + /** + * 设置 tls 建立结束时间 + * + * @param secureConnectionEndDate tls 建立结束时间 + */ public void setSecureConnectionEndDate(Date secureConnectionEndDate) { this.secureConnectionEndDate = secureConnectionEndDate; } @@ -191,10 +358,20 @@ public void setSecureConnectionEndDate(Date secureConnectionEndDate) { // http 请求头发送开始时间 【自定义对象,请保证对象的此属性不为空】 private Date requestStartDate; + /** + * 获取请求开始时间 + * + * @return 请求开始时间 + */ public Date getRequestStartDate() { return requestStartDate; } + /** + * 设置请求开始时间 + * + * @param requestStartDate 请求开始时间 + */ public void setRequestStartDate(Date requestStartDate) { this.requestStartDate = requestStartDate; } @@ -202,10 +379,20 @@ public void setRequestStartDate(Date requestStartDate) { // http 请求体发送结束时间 【自定义对象,请保证对象的此属性不为空】 private Date requestEndDate; + /** + * 获取请求结束时间 + * + * @return 请求结束时间 + */ public Date getRequestEndDate() { return requestEndDate; } + /** + * 设置请求结束时间 + * + * @param requestEndDate 请求结束时间 + */ public void setRequestEndDate(Date requestEndDate) { this.requestEndDate = requestEndDate; } @@ -213,10 +400,20 @@ public void setRequestEndDate(Date requestEndDate) { // http 收到响应的时间 【自定义对象,请保证对象的此属性不为空】 private Date responseStartDate; + /** + * 获取响应开始时间 + * + * @return 响应开始时间 + */ public Date getResponseStartDate() { return responseStartDate; } + /** + * 设置响应开始时间 + * + * @param responseStartDate 响应开始时间 + */ public void setResponseStartDate(Date responseStartDate) { this.responseStartDate = responseStartDate; } @@ -224,10 +421,20 @@ public void setResponseStartDate(Date responseStartDate) { // http 响应的结束时间 【自定义对象,请保证对象的此属性不为空】 private Date responseEndDate; + /** + * 获取响应结束时间 + * + * @return 响应结束时间 + */ public Date getResponseEndDate() { return responseEndDate; } + /** + * 设置响应结束时间 + * + * @param responseEndDate 响应结束时间 + */ public void setResponseEndDate(Date responseEndDate) { this.responseEndDate = responseEndDate; } @@ -235,10 +442,20 @@ public void setResponseEndDate(Date responseEndDate) { // http 请求头大小【自定义对象,请保证对象的此属性不为空】 private long countOfRequestHeaderBytesSent = 0; + /** + * 获取请求头发送的大小 + * + * @return 请求头发送的大小 + */ public long getCountOfRequestHeaderBytesSent() { return countOfRequestHeaderBytesSent; } + /** + * 设置请求头发送的大小 + * + * @param countOfRequestHeaderBytesSent 请求头发送的大小 + */ public void setCountOfRequestHeaderBytesSent(long countOfRequestHeaderBytesSent) { this.countOfRequestHeaderBytesSent = countOfRequestHeaderBytesSent; } @@ -246,10 +463,20 @@ public void setCountOfRequestHeaderBytesSent(long countOfRequestHeaderBytesSent) // http 请求头体【自定义对象,请保证对象的此属性不为空】 private long countOfRequestBodyBytesSent = 0; + /** + * 获取请求体发送的大小 + * + * @return 请求体发送的大小 + */ public long getCountOfRequestBodyBytesSent() { return countOfRequestBodyBytesSent; } + /** + * 设置请求体发送的大小 + * + * @param countOfRequestBodyBytesSent 请求体发送的大小 + */ public void setCountOfRequestBodyBytesSent(long countOfRequestBodyBytesSent) { this.countOfRequestBodyBytesSent = countOfRequestBodyBytesSent; } @@ -257,10 +484,20 @@ public void setCountOfRequestBodyBytesSent(long countOfRequestBodyBytesSent) { // http 响应头大小【自定义对象,请保证对象的此属性不为空】 private long countOfResponseHeaderBytesReceived = 0; + /** + * 获取响应头大小 + * + * @return 响应头大小 + */ public long getCountOfResponseHeaderBytesReceived() { return countOfResponseHeaderBytesReceived; } + /** + * 设置响应头大小 + * + * @param countOfResponseHeaderBytesReceived 响应头大小 + */ public void setCountOfResponseHeaderBytesReceived(long countOfResponseHeaderBytesReceived) { this.countOfResponseHeaderBytesReceived = countOfResponseHeaderBytesReceived; } @@ -268,10 +505,20 @@ public void setCountOfResponseHeaderBytesReceived(long countOfResponseHeaderByte // http 响应体大小【自定义对象,请保证对象的此属性不为空】 private long countOfResponseBodyBytesReceived = 0; + /** + * 获取响应体接收的大小 + * + * @return 响应体接收的大小 + */ public long getCountOfResponseBodyBytesReceived() { return countOfResponseBodyBytesReceived; } + /** + * 设置响应体接收的大小 + * + * @param countOfResponseBodyBytesReceived 响应体接收的大小 + */ public void setCountOfResponseBodyBytesReceived(long countOfResponseBodyBytesReceived) { this.countOfResponseBodyBytesReceived = countOfResponseBodyBytesReceived; } @@ -279,10 +526,20 @@ public void setCountOfResponseBodyBytesReceived(long countOfResponseBodyBytesRec // http 请求本地 IP【自定义对象,请保证对象的此属性不为空】 private String localAddress; + /** + * 获取 localAddress + * + * @return localAddress + */ public String getLocalAddress() { return localAddress; } + /** + * 设置 localAddress + * + * @param localAddress localAddress + */ public void setLocalAddress(String localAddress) { this.localAddress = localAddress; } @@ -290,10 +547,20 @@ public void setLocalAddress(String localAddress) { // http 请求本地端口【自定义对象,请保证对象的此属性不为空】 private Integer localPort; + /** + * 获取 local port + * + * @return local port + */ public Integer getLocalPort() { return localPort; } + /** + * 设置 local port + * + * @param localPort local port + */ public void setLocalPort(Integer localPort) { this.localPort = localPort; } @@ -301,10 +568,20 @@ public void setLocalPort(Integer localPort) { // http 请求远程 IP【自定义对象,请保证对象的此属性不为空】 private String remoteAddress; + /** + * 获取 server address + * + * @return server address + */ public String getRemoteAddress() { return remoteAddress; } + /** + * 设置 server address + * + * @param remoteAddress server address + */ public void setRemoteAddress(String remoteAddress) { this.remoteAddress = remoteAddress; } @@ -312,44 +589,94 @@ public void setRemoteAddress(String remoteAddress) { // http 请求远程端口【自定义对象,请保证对象的此属性不为空】 private Integer remotePort; + /** + * 获取 server port + * + * @return server port + */ public Integer getRemotePort() { return remotePort; } + /** + * 设置 server port + * + * @param remotePort server port + */ public void setRemotePort(Integer remotePort) { this.remotePort = remotePort; } private long totalBytes = 0; + /** + * 获取 dns 耗时时间 + * + * @return dns 耗时时间 + */ public long totalDnsTime() { return time(domainLookupStartDate, domainLookupEndDate); } + /** + * 获取 建立连接耗时时间 + * + * @return 建立连接耗时时间 + */ public long totalConnectTime() { return time(connectStartDate, connectEndDate); } + /** + * 获取 tls 耗时时间 + * + * @return tls 耗时时间 + */ public long totalSecureConnectTime() { return time(secureConnectionStartDate, secureConnectionEndDate); } + /** + * 获取请求耗时时间 + * + * @return 请求耗时时间 + */ public long totalRequestTime() { return time(requestStartDate, requestEndDate); } + /** + * 获取请求等待耗时时间 + * + * @return 请求等待耗时时间 + */ public long totalWaitTime() { return time(requestEndDate, responseStartDate); } + /** + * 获取响应耗时时间 + * + * @return 响应耗时时间 + */ public long totalResponseTime() { return time(responseStartDate, responseEndDate); } + /** + * 获取请求总大小 + * + * @return 请求总大小 + */ public long totalBytes() { return totalBytes; } + /** + * 获取请求发送数据大小 + * + * @return 请求发送数据大小 + */ public Long bytesSend() { long totalBytes = totalBytes(); long bytesSend = countOfRequestHeaderBytesSent + countOfRequestBodyBytesSent; @@ -359,6 +686,11 @@ public Long bytesSend() { return bytesSend; } + /** + * 获取请求接收数据大小 + * + * @return 请求接收数据大小 + */ public Long bytesReceived() { long bytesReceived = countOfResponseHeaderBytesReceived + countOfResponseBodyBytesReceived; if (bytesReceived < 0) { @@ -367,14 +699,29 @@ public Long bytesReceived() { return bytesReceived; } + /** + * 获取请求速度 + * + * @return 请求速度 + */ public Long perceptiveSpeed() { return Utils.calculateSpeed(bytesSend() + bytesReceived(), totalElapsedTime()); } + /** + * 获取请求是否被劫持 + * + * @return 请求是否被劫持 + */ public boolean isForsureHijacked() { return hijacked != null && hijacked.contains(RequestHijacked); } + /** + * 获取请求是否可能被劫持 + * + * @return 请求是否可能被劫持 + */ public boolean isMaybeHijacked() { return hijacked != null && hijacked.contains(RequestMaybeHijacked); } diff --git a/library/src/main/java/com/qiniu/android/http/metrics/UploadTaskMetrics.java b/library/src/main/java/com/qiniu/android/http/metrics/UploadTaskMetrics.java index 11ab395b8..55627136d 100644 --- a/library/src/main/java/com/qiniu/android/http/metrics/UploadTaskMetrics.java +++ b/library/src/main/java/com/qiniu/android/http/metrics/UploadTaskMetrics.java @@ -10,8 +10,14 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.CopyOnWriteArrayList; +/** + * upload task metrics + */ public class UploadTaskMetrics extends UploadMetrics { + /** + * 上传的 regions + */ public ArrayList regions; private String upType; @@ -19,45 +25,70 @@ public class UploadTaskMetrics extends UploadMetrics { private List metricsKeys = new CopyOnWriteArrayList<>(); private Map metricsInfo = new ConcurrentHashMap<>(); + /** + * 构造函数 + * + * @param upType 上传类型 + */ public UploadTaskMetrics(String upType) { this.upType = upType; } - public Long requestCount(){ + /** + * 获取请求次数 + * + * @return 请求次数 + */ + public Long requestCount() { long count = 0; - for (String key : metricsInfo.keySet()){ + for (String key : metricsInfo.keySet()) { UploadRegionRequestMetrics metrics = metricsInfo.get(key); - if (metrics != null){ + if (metrics != null) { count += metrics.requestCount(); } } return count; } - public Long bytesSend(){ + /** + * 获取发送数据大小 + * + * @return 发送数据大小 + */ + public Long bytesSend() { long bytesSend = 0; - for (String key : metricsInfo.keySet()){ + for (String key : metricsInfo.keySet()) { UploadRegionRequestMetrics metrics = metricsInfo.get(key); - if (metrics != null){ + if (metrics != null) { bytesSend += metrics.bytesSend(); } } return bytesSend; } - public Long regionCount(){ + /** + * 获取上传使用区域个数 + * + * @return 上传使用区域个数 + */ + public Long regionCount() { long count = 0; - for (String key : metricsInfo.keySet()){ + for (String key : metricsInfo.keySet()) { UploadRegionRequestMetrics metrics = metricsInfo.get(key); - if (metrics !=null + if (metrics != null && metrics.region != null && metrics.region.getZoneInfo() != null - && !metrics.region.getZoneInfo().regionId.equals(ZoneInfo.EmptyRegionId)){ + && !metrics.region.getZoneInfo().regionId.equals(ZoneInfo.EmptyRegionId)) { count += 1; } } return count; } + /** + * 获取最后一个区域请求指标 + * + * @return 最后一个区域请求指标 + */ public UploadRegionRequestMetrics lastMetrics() { int size = metricsKeys.size(); if (size < 1) { @@ -68,14 +99,19 @@ public UploadRegionRequestMetrics lastMetrics() { return metricsInfo.get(key); } - public void addMetrics(UploadRegionRequestMetrics metrics){ + /** + * 添加区域请求指标 + * + * @param metrics 区域请求指标 + */ + public void addMetrics(UploadRegionRequestMetrics metrics) { if (metrics == null || metrics.region == null || metrics.region.getZoneInfo() == null - || metrics.region.getZoneInfo().regionId == null){ + || metrics.region.getZoneInfo().regionId == null) { return; } String regionId = metrics.region.getZoneInfo().regionId; UploadRegionRequestMetrics metricsOld = metricsInfo.get(regionId); - if (metricsOld != null){ + if (metricsOld != null) { metricsOld.addMetrics(metrics); } else { metricsKeys.add(regionId); @@ -83,14 +119,29 @@ public void addMetrics(UploadRegionRequestMetrics metrics){ } } + /** + * 获取上传类型 + * + * @return 上传类型 + */ public String getUpType() { return upType; } + /** + * 获取 uc query 请求指标 + * + * @return uc query 请求指标 + */ public UploadRegionRequestMetrics getUcQueryMetrics() { return ucQueryMetrics; } + /** + * 设置 uc query 请求指标 + * + * @param ucQueryMetrics uc query 请求指标 + */ public void setUcQueryMetrics(UploadRegionRequestMetrics ucQueryMetrics) { this.ucQueryMetrics = ucQueryMetrics; addMetrics(ucQueryMetrics); diff --git a/library/src/main/java/com/qiniu/android/http/networkStatus/NetworkStatusManager.java b/library/src/main/java/com/qiniu/android/http/networkStatus/NetworkStatusManager.java index 9ec112f15..b9d70b56d 100644 --- a/library/src/main/java/com/qiniu/android/http/networkStatus/NetworkStatusManager.java +++ b/library/src/main/java/com/qiniu/android/http/networkStatus/NetworkStatusManager.java @@ -6,6 +6,9 @@ import org.json.JSONObject; +/** + * 网络状态管理器 + */ public class NetworkStatusManager { private static final NetworkStatusManager networkStatusManager = new NetworkStatusManager(); @@ -15,19 +18,48 @@ public class NetworkStatusManager { .setFlushCount(10) .builder(); + /** + * 获取单例 + * + * @return NetworkStatusManager 单例 + */ public static NetworkStatusManager getInstance() { return networkStatusManager; } + private NetworkStatusManager() { + } + + /** + * 获取网络状态唯一标识 + * + * @param host host + * @param ip ip + * @return 唯一标识 + */ @Deprecated public static String getNetworkStatusType(String host, String ip) { return Utils.getIpType(ip, host); } + /** + * 获取网络状态唯一标识 + * + * @param httpVersion httpVersion + * @param host host + * @param ip ip + * @return 唯一标识 + */ public static String getNetworkStatusType(String httpVersion, String host, String ip) { return Utils.getIpType(httpVersion, ip, host); } + /** + * 获取网络状态 + * + * @param type 网络状态唯一标识 + * @return 网络状态 + */ public NetworkStatus getNetworkStatus(String type) { if (type == null || type.isEmpty()) { return null; @@ -41,6 +73,12 @@ public NetworkStatus getNetworkStatus(String type) { } } + /** + * 更新网络状态 + * + * @param type 网络状态唯一标识 + * @param speed 网速 + */ public void updateNetworkStatus(String type, int speed) { if (type == null || type.isEmpty()) { return; @@ -51,16 +89,32 @@ public void updateNetworkStatus(String type, int speed) { this.cache.cache(type, status, false); } + /** + * default speed + */ protected static final int DefaultSpeed = 600; + /** + * 网络状态 + */ public static class NetworkStatus implements Cache.Object { private int speed = DefaultSpeed; + /** + * 获取速度 + * + * @return 速度 + */ public int getSpeed() { return speed; } + /** + * 设置速度 + * + * @param speed speed + */ public void setSpeed(int speed) { this.speed = speed; } @@ -68,6 +122,11 @@ public void setSpeed(int speed) { private NetworkStatus() { } + /** + * 构造函数 + * + * @param jsonObject 网络状态 json 数据 + */ public NetworkStatus(JSONObject jsonObject) { if (jsonObject == null) { return; @@ -79,6 +138,11 @@ public NetworkStatus(JSONObject jsonObject) { } } + /** + * 获取 json 数据 + * + * @return json 数据 + */ @Override public JSONObject toJson() { JSONObject jsonObject = new JSONObject(); diff --git a/library/src/main/java/com/qiniu/android/http/networkStatus/UploadServerNetworkStatus.java b/library/src/main/java/com/qiniu/android/http/networkStatus/UploadServerNetworkStatus.java index 589ed8b78..c9e64a284 100644 --- a/library/src/main/java/com/qiniu/android/http/networkStatus/UploadServerNetworkStatus.java +++ b/library/src/main/java/com/qiniu/android/http/networkStatus/UploadServerNetworkStatus.java @@ -2,13 +2,33 @@ import com.qiniu.android.http.request.IUploadServer; +/** + * UploadServerNetworkStatus + */ public class UploadServerNetworkStatus { + private UploadServerNetworkStatus() { + } + + /** + * 获取网络状态较好的 server + * + * @param serverA serverA + * @param serverB serverB + * @return 网络状态较好的 server + */ public static IUploadServer getBetterNetworkServer(IUploadServer serverA, IUploadServer serverB) { return isServerNetworkBetter(serverA, serverB) ? serverA : serverB; } - // 如果两个 Server 网速相同且类别相同优先使用 serverA,类别不同优先使用 Http3 + /** + * serverA 网络状态是否较 serverB 好 + * 如果两个 Server 网速相同且类别相同优先使用 serverA,类别不同 HTTP/3 较好 + * + * @param serverA serverA + * @param serverB serverB + * @return 是否较好 + */ public static boolean isServerNetworkBetter(IUploadServer serverA, IUploadServer serverB) { if (serverA == null) { return false; diff --git a/library/src/main/java/com/qiniu/android/http/request/IRequestClient.java b/library/src/main/java/com/qiniu/android/http/request/IRequestClient.java index 8088a3532..ad1f6e8d7 100644 --- a/library/src/main/java/com/qiniu/android/http/request/IRequestClient.java +++ b/library/src/main/java/com/qiniu/android/http/request/IRequestClient.java @@ -40,6 +40,12 @@ public interface CompleteHandler { void complete(ResponseInfo responseInfo, UploadSingleRequestMetrics metrics, JSONObject response); } + /** + * 构造函数 + */ + protected IRequestClient() { + } + /** * 触发请求 * diff --git a/library/src/main/java/com/qiniu/android/http/request/IUploadServer.java b/library/src/main/java/com/qiniu/android/http/request/IUploadServer.java index b39f314ff..53ef366d8 100644 --- a/library/src/main/java/com/qiniu/android/http/request/IUploadServer.java +++ b/library/src/main/java/com/qiniu/android/http/request/IUploadServer.java @@ -23,8 +23,15 @@ public abstract class IUploadServer { */ public static String HttpVersion3 = "http_version_3"; + /** + * 构造函数 + */ + protected IUploadServer() { + } + /** * 是否使用 HTTP/3 + * * @return 是否使用 HTTP/3 */ public boolean isHttp3() { @@ -37,6 +44,7 @@ public boolean isHttp3() { /** * 是否使用 HTTP/2 + * * @return 是否使用 HTTP/2 */ public boolean isHttp2() { @@ -49,45 +57,52 @@ public boolean isHttp2() { /** * 获取 ServerId + * * @return ServerId */ public abstract String getServerId(); /** * 获取 HttpVersion + * * @return HttpVersion */ public abstract String getHttpVersion(); /** * 获取 Host + * * @return Host */ public abstract String getHost(); /** * 获取 IP + * * @return IP */ public abstract String getIp(); /** * 获取 DNS 解析 Source + * * @return DNS 解析 Source */ public abstract String getSource(); /** * 获取 DNS 解析时间戳 + * * @return DNS 解析时间戳 */ public abstract Long getIpPrefetchedTime(); /** * 获取 DNS 解析信息 + * * @return DNS 解析信息 */ - public InetAddress getInetAddress(){ + public InetAddress getInetAddress() { String ip = getIp(); String host = getHost(); if (getHost() == null || ip == null || ip.length() == 0) { diff --git a/library/src/main/java/com/qiniu/android/http/request/Request.java b/library/src/main/java/com/qiniu/android/http/request/Request.java index 0519daae6..c87553b7b 100644 --- a/library/src/main/java/com/qiniu/android/http/request/Request.java +++ b/library/src/main/java/com/qiniu/android/http/request/Request.java @@ -3,24 +3,82 @@ import java.util.HashMap; import java.util.Map; +/** + * request + */ public class Request { + /** + * 请求方式:HEAD + */ public static final String HttpMethodHEAD = "HEAD"; + + /** + * 请求方式:GET + */ public static final String HttpMethodGet = "GET"; + + /** + * 请求方式:POST + */ public static final String HttpMethodPOST = "POST"; + + /** + * 请求方式:PUT + */ public static final String HttpMethodPUT = "PUT"; + /** + * 请求 Url + */ public final String urlString; + + /** + * 请求方式 + */ public final String httpMethod; + + /** + * 请求 header + */ public final Map allHeaders; + + /** + * 请求超时时间 + */ public final int timeout; + + /** + * 请求建立连接超时时间 + */ public final int connectTimeout; + + /** + * 请求读超时时间 + */ public final int readTimeout; + + /** + * 请求写超时时间 + */ public final int writeTimeout; + + /** + * 请求 body + */ public byte[] httpBody; private String host; + /** + * 构造函数 + * + * @param urlString 请求 url + * @param httpMethod 请求方式 + * @param allHeaders 请求头 + * @param httpBody 请求体 + * @param timeout 请求超时时间 + */ public Request(String urlString, String httpMethod, Map allHeaders, @@ -31,6 +89,17 @@ public Request(String urlString, (timeout - 10) >> 1); } + /** + * 构造函数 + * + * @param urlString 请求 url + * @param httpMethod 请求方式 + * @param allHeaders 请求头 + * @param httpBody 请求体 + * @param connectTimeout 请求建立连接超时时间 + * @param readTimeout 请求读超时时间 + * @param writeTimeout 请求写超时时间 + */ public Request(String urlString, String httpMethod, Map allHeaders, @@ -62,14 +131,29 @@ void setHost(String host) { this.host = host; } + /** + * 获取 host + * + * @return host + */ public String getHost() { return host; } + /** + * 请求是否有效 + * + * @return 是否有效 + */ protected boolean isValid() { return this.urlString == null || httpMethod == null; } + /** + * copy 请求,但是不 copy body + * + * @return 新的请求对象 + */ public Request copyWithoutBody() { Request request = new Request(urlString, httpMethod, allHeaders, null, connectTimeout, readTimeout, writeTimeout); diff --git a/library/src/main/java/com/qiniu/android/http/request/RequestTransaction.java b/library/src/main/java/com/qiniu/android/http/request/RequestTransaction.java index 1dce75c9f..56344cb4c 100644 --- a/library/src/main/java/com/qiniu/android/http/request/RequestTransaction.java +++ b/library/src/main/java/com/qiniu/android/http/request/RequestTransaction.java @@ -26,6 +26,9 @@ import java.util.Map; import java.util.Set; +/** + * 请求事务 + */ public class RequestTransaction { private final Configuration config; @@ -39,17 +42,40 @@ public class RequestTransaction { private HttpRegionRequest regionRequest; + /** + * 构造函数 + * + * @param hosts hosts + * @param token token + */ public RequestTransaction(List hosts, UpToken token) { this(new Configuration.Builder().build(), UploadOptions.defaultOptions(), hosts, null, null, token); } + /** + * 构造函数 + * + * @param hosts hosts + * @param regionId 区域 ID + * @param token 上传 Token + */ public RequestTransaction(List hosts, String regionId, UpToken token) { this(new Configuration.Builder().build(), UploadOptions.defaultOptions(), hosts, regionId, null, token); } + /** + * 构造函数 + * + * @param config 配置信息 + * @param uploadOption 上传选项 + * @param hosts hosts + * @param regionId 区域 ID + * @param key 上传保存的 key + * @param token 上传的 Token + */ public RequestTransaction(Configuration config, UploadOptions uploadOption, List hosts, @@ -62,6 +88,16 @@ public RequestTransaction(Configuration config, this.initData(region, region); } + /** + * 构造函数 + * + * @param config 请求事务配置 + * @param uploadOption 请求选项 + * @param targetRegion 请求的区域 + * @param currentRegion 当前的区域 + * @param key 保存的 key + * @param token 上传的 token + */ public RequestTransaction(Configuration config, UploadOptions uploadOption, IUploadRegion targetRegion, @@ -101,6 +137,12 @@ private void initData(IUploadRegion targetRegion, } + /** + * 查询上传域名 + * + * @param isAsync 是否为同步请求 + * @param completeHandler 请求结束回调 + */ public void queryUploadHosts(boolean isAsync, final RequestCompleteHandler completeHandler) { requestInfo.requestType = UploadRequestInfo.RequestTypeUCQuery; @@ -123,6 +165,15 @@ public void complete(ResponseInfo responseInfo, UploadRegionRequestMetrics reque }); } + /** + * 上传表单接口 + * + * @param data 上传数据 + * @param fileName 文件名 + * @param isAsync 是否为同步 + * @param progressHandler 进度回调 + * @param completeHandler 结束回调 + */ public void uploadFormData(byte[] data, String fileName, boolean isAsync, @@ -194,6 +245,16 @@ public void complete(ResponseInfo responseInfo, UploadRegionRequestMetrics reque }); } + /** + * make block api + * + * @param blockOffset block offset + * @param blockSize block 大小 + * @param firstChunkData 第一块数据 + * @param isAsync 是否为异步 + * @param progressHandler 进度回调 + * @param completeHandler 结束回调 + */ public void makeBlock(long blockOffset, long blockSize, byte[] firstChunkData, @@ -239,6 +300,17 @@ public void complete(ResponseInfo responseInfo, UploadRegionRequestMetrics reque }); } + /** + * upload chunk api + * + * @param blockContext block ctx + * @param blockOffset block offset + * @param chunkData chunk data + * @param chunkOffset chunk offset + * @param isAsync 是佛为异步 + * @param progressHandler 进度回调 + * @param completeHandler 结束回调 + */ public void uploadChunk(String blockContext, long blockOffset, byte[] chunkData, @@ -286,6 +358,15 @@ public void complete(ResponseInfo responseInfo, UploadRegionRequestMetrics reque }); } + /** + * make file api + * + * @param fileSize 文件大小 + * @param fileName 文件名 + * @param blockContexts block ctxs + * @param isAsync 是否为异步 + * @param completeHandler 结束回调 + */ public void makeFile(long fileSize, String fileName, String[] blockContexts, @@ -355,6 +436,12 @@ public void complete(ResponseInfo responseInfo, UploadRegionRequestMetrics reque } + /** + * init part api + * + * @param isAsync 是否为异步 + * @param completeHandler 结束回调 + */ public void initPart(boolean isAsync, final RequestCompleteHandler completeHandler) { requestInfo.requestType = UploadRequestInfo.RequestTypeInitParts; @@ -385,6 +472,16 @@ public void complete(ResponseInfo responseInfo, UploadRegionRequestMetrics reque } + /** + * upload part api + * + * @param isAsync 是否为异步 + * @param uploadId 上传 ID + * @param partIndex part index + * @param partData part data + * @param progressHandler 进度回调 + * @param completeHandler 完成回调 + */ public void uploadPart(boolean isAsync, String uploadId, int partIndex, @@ -437,6 +534,15 @@ public void complete(ResponseInfo responseInfo, UploadRegionRequestMetrics reque }); } + /** + * complete part api + * + * @param isAsync 是否为同步 + * @param fileName 文件名 + * @param uploadId 上传 ID + * @param partInfoArray part info + * @param completeHandler 结束回调 + */ public void completeParts(boolean isAsync, String fileName, String uploadId, @@ -501,6 +607,14 @@ public void complete(ResponseInfo responseInfo, UploadRegionRequestMetrics reque }); } + /** + * report log api + * + * @param logData 日志数据 + * @param logClientId 日志 client id + * @param isAsync 是否为同步 + * @param completeHandler 结束回调 + */ public void reportLog(byte[] logData, String logClientId, boolean isAsync, @@ -533,6 +647,12 @@ public void complete(ResponseInfo responseInfo, UploadRegionRequestMetrics reque }); } + /** + * server config + * + * @param isAsync 是否为异步 + * @param completeHandler 结束回调 + */ public void serverConfig(boolean isAsync, final RequestCompleteHandler completeHandler) { requestInfo.requestType = UploadRequestInfo.RequestTypeServerConfig; @@ -556,6 +676,12 @@ public void complete(ResponseInfo responseInfo, UploadRegionRequestMetrics reque }); } + /** + * server user config + * + * @param isAsync 是否为异步 + * @param completeHandler 完成回调 + */ public void serverUserConfig(boolean isAsync, final RequestCompleteHandler completeHandler) { requestInfo.requestType = UploadRequestInfo.RequestTypeServerUserConfig; @@ -604,7 +730,18 @@ private void completeAction(ResponseInfo responseInfo, } } + /** + * 请求结束回调 + */ public interface RequestCompleteHandler { + + /** + * 请求结束回调 + * + * @param responseInfo 请求响应信息 + * @param requestMetrics 请求指标 + * @param response 请求响应 + */ void complete(ResponseInfo responseInfo, UploadRegionRequestMetrics requestMetrics, JSONObject response); diff --git a/library/src/main/java/com/qiniu/android/http/request/UploadRequestState.java b/library/src/main/java/com/qiniu/android/http/request/UploadRequestState.java index 811e610d3..2ed862021 100644 --- a/library/src/main/java/com/qiniu/android/http/request/UploadRequestState.java +++ b/library/src/main/java/com/qiniu/android/http/request/UploadRequestState.java @@ -1,12 +1,26 @@ package com.qiniu.android.http.request; +/** + * 上传状态 + */ public class UploadRequestState { private boolean couldUseHttp3; private boolean isUseOldServer; private boolean isUserCancel; - public boolean couldUseHttp3(){ + /** + * 构造函数 + */ + public UploadRequestState() { + } + + /** + * 是否可以使用 HTTP/3 + * + * @return 是否可以使用 HTTP/3 + */ + public boolean couldUseHttp3() { return couldUseHttp3; } @@ -14,7 +28,7 @@ void setCouldUseHttp3(boolean couldUseHttp3) { this.couldUseHttp3 = couldUseHttp3; } - boolean isUserCancel(){ + boolean isUserCancel() { return isUserCancel; } @@ -22,14 +36,29 @@ void setUserCancel(boolean isUserCancel) { this.isUserCancel = isUserCancel; } + /** + * 是否使用支持 sni 的域名 + * + * @return 是否使用支持 sni 的域名 + */ public boolean isUseOldServer() { return isUseOldServer; } + /** + * 设置是否使用支持 sni 的域名 + * + * @param useOldServer 是否使用支持 sni 的域名 + */ public void setUseOldServer(boolean useOldServer) { isUseOldServer = useOldServer; } + /** + * clone + * + * @return clone 后的对象 + */ protected UploadRequestState clone() { UploadRequestState state = new UploadRequestState(); state.isUseOldServer = isUseOldServer; diff --git a/library/src/main/java/com/qiniu/android/http/request/handler/RequestProgressHandler.java b/library/src/main/java/com/qiniu/android/http/request/handler/RequestProgressHandler.java index ca5765aab..9b4e21782 100644 --- a/library/src/main/java/com/qiniu/android/http/request/handler/RequestProgressHandler.java +++ b/library/src/main/java/com/qiniu/android/http/request/handler/RequestProgressHandler.java @@ -1,5 +1,15 @@ package com.qiniu.android.http.request.handler; +/** + * 请求进度回调 + */ public interface RequestProgressHandler { + + /** + * 请求进度回调 + * + * @param totalBytesWritten 已发送数据大小 + * @param totalBytesExpectedToWrite 总数据大小 + */ void progress(long totalBytesWritten, long totalBytesExpectedToWrite); } diff --git a/library/src/main/java/com/qiniu/android/http/request/handler/RequestShouldRetryHandler.java b/library/src/main/java/com/qiniu/android/http/request/handler/RequestShouldRetryHandler.java index 39efcbe8e..4ab833173 100644 --- a/library/src/main/java/com/qiniu/android/http/request/handler/RequestShouldRetryHandler.java +++ b/library/src/main/java/com/qiniu/android/http/request/handler/RequestShouldRetryHandler.java @@ -4,6 +4,17 @@ import org.json.JSONObject; +/** + * 请求重试回调 + */ public interface RequestShouldRetryHandler { + + /** + * 请求重试回调 + * + * @param responseInfo 上次请求的响应信息 + * @param response 上次请求的响应信息 + * @return 是否可以重试 + */ boolean shouldRetry(ResponseInfo responseInfo, JSONObject response); } diff --git a/library/src/main/java/com/qiniu/android/http/request/httpclient/MultipartBody.java b/library/src/main/java/com/qiniu/android/http/request/httpclient/MultipartBody.java index 8cdcb3f17..c60f088c3 100644 --- a/library/src/main/java/com/qiniu/android/http/request/httpclient/MultipartBody.java +++ b/library/src/main/java/com/qiniu/android/http/request/httpclient/MultipartBody.java @@ -34,7 +34,9 @@ import okio.BufferedSink; import okio.ByteString; -/** An RFC 2387-compliant request body. */ +/** + * An RFC 2387-compliant request body. + */ public final class MultipartBody extends RequestBody { /** * The "mixed" subtype of "multipart" is intended for use when the body parts are independent and @@ -120,28 +122,55 @@ static StringBuilder appendQuotedString(StringBuilder target, String key) { return target; } + /** + * 获取 type + * + * @return MediaType + */ public MediaType type() { return originalType; } + /** + * 获取 boundary + * + * @return boundary + */ public String boundary() { return boundary.utf8(); } - /** The number of parts in this multipart body. */ + /** + * The number of parts in this multipart body. + * + * @return size + */ public int size() { return parts.size(); } + /** + * 获取 parts + * + * @return parts + */ public List parts() { return parts; } + /** + * 构造函数 + * + * @param index index + * @return Part + */ public Part part(int index) { return parts.get(index); } - /** A combination of {@link #type()} and {@link #boundary()}. */ + /** + * A combination of {@link #type()} and {@link #boundary()}. + */ @Override public MediaType contentType() { return contentType; @@ -233,6 +262,9 @@ private long writeOrCountBytes(BufferedSink sink, boolean countBytes) throws IOE return byteCount; } + /** + * Part + */ public static final class Part { final Headers headers; final RequestBody body; @@ -242,10 +274,23 @@ private Part(Headers headers, RequestBody body) { this.body = body; } + /** + * 构造函数 + * + * @param body body + * @return Part + */ public static Part create(RequestBody body) { return create(null, body); } + /** + * 构造函数 + * + * @param headers headers + * @param body body + * @return Part + */ public static Part create(Headers headers, RequestBody body) { if (body == null) { throw new NullPointerException("body == null"); @@ -259,10 +304,25 @@ public static Part create(Headers headers, RequestBody body) { return new Part(headers, body); } + /** + * 构造函数 + * + * @param name name + * @param value value + * @return Part + */ public static Part createFormData(String name, String value) { return createFormData(name, null, RequestBody.create(null, value)); } + /** + * 构造函数 + * + * @param name name + * @param filename filename + * @param body body + * @return Part + */ public static Part createFormData(String name, String filename, RequestBody body) { if (name == null) { throw new NullPointerException("name == null"); @@ -278,24 +338,45 @@ public static Part createFormData(String name, String filename, RequestBody body return create(Headers.of("Content-Disposition", disposition.toString()), body); } + /** + * header + * + * @return header + */ public Headers headers() { return headers; } + /** + * body + * + * @return body + */ public RequestBody body() { return body; } } + /** + * Builder + */ public static final class Builder { private final ByteString boundary; private final List parts = new ArrayList<>(); private MediaType type = MIXED; + /** + * 构造方法 + */ public Builder() { this(UUID.randomUUID().toString()); } + /** + * 构造方法 + * + * @param boundary boundary + */ public Builder(String boundary) { this.boundary = ByteString.encodeUtf8(boundary); } @@ -303,6 +384,9 @@ public Builder(String boundary) { /** * Set the MIME type. Expected values for {@code type} are {@link #MIXED} (the default), {@link * #ALTERNATIVE}, {@link #DIGEST}, {@link #PARALLEL} and {@link #FORM}. + * + * @param type MediaType + * @return Builder */ public Builder setType(MediaType type) { if (type == null) { @@ -315,34 +399,67 @@ public Builder setType(MediaType type) { return this; } - /** Add a part to the body. */ + /** + * Add a part to the body. + * + * @param body body + * @return Builder + */ public Builder addPart(RequestBody body) { return addPart(Part.create(body)); } - /** Add a part to the body. */ + /** + * Add a part to the body. + * + * @param headers headers + * @param body body + * @return Builder + */ public Builder addPart(Headers headers, RequestBody body) { return addPart(Part.create(headers, body)); } - /** Add a form data part to the body. */ + /** + * Add a form data part to the body. + * + * @param name name + * @param value value + * @return Builder + */ public Builder addFormDataPart(String name, String value) { return addPart(Part.createFormData(name, value)); } - /** Add a form data part to the body. */ + /** + * Add a form data part to the body. + * + * @param name name + * @param filename filename + * @param body body + * @return Builder + */ public Builder addFormDataPart(String name, String filename, RequestBody body) { return addPart(Part.createFormData(name, filename, body)); } - /** Add a part to the body. */ + /** + * Add a part to the body. + * + * @param part part + * @return Builder + */ public Builder addPart(Part part) { if (part == null) throw new NullPointerException("part == null"); parts.add(part); return this; } - /** Assemble the specified parts into a request body. */ + /** + * Assemble the specified parts into a request body. + * + * @return MultipartBody + */ public MultipartBody build() { if (parts.isEmpty()) { throw new IllegalStateException("Multipart body must have at least one part."); diff --git a/library/src/main/java/com/qiniu/android/http/request/httpclient/SystemHttpClient.java b/library/src/main/java/com/qiniu/android/http/request/httpclient/SystemHttpClient.java index a01eb13d7..1ec7daa43 100644 --- a/library/src/main/java/com/qiniu/android/http/request/httpclient/SystemHttpClient.java +++ b/library/src/main/java/com/qiniu/android/http/request/httpclient/SystemHttpClient.java @@ -15,6 +15,7 @@ import com.qiniu.android.utils.StringUtils; +import org.jetbrains.annotations.NotNull; import org.json.JSONObject; import java.io.IOException; @@ -50,11 +51,29 @@ import static com.qiniu.android.http.ResponseInfo.NetworkError; +/** + * system client + */ public class SystemHttpClient extends IRequestClient { + /** + * 请求头 key:Content-Type + */ public static final String ContentTypeHeader = "Content-Type"; + + /** + * 默认请求的 Content-Type + */ public static final String DefaultMime = "application/octet-stream"; + + /** + * 请求体为 Json 的 Content-Type + */ public static final String JsonMime = "application/json"; + + /** + * 表单请求的 Content-Type + */ public static final String FormMime = "application/x-www-form-urlencoded"; private boolean hasHandleComplete = false; @@ -68,6 +87,22 @@ public class SystemHttpClient extends IRequestClient { private Progress requestProgress; private CompleteHandler completeHandler; + /** + * 构造函数 + * 内部使用,禁止外部调用 + */ + public SystemHttpClient() { + } + + /** + * 构造函数 + * + * @param request 请求 + * @param isAsync 是否异步 + * @param connectionProxy 代理 + * @param progress 进度回调 + * @param complete 完成回调 + */ public void request(Request request, boolean isAsync, ProxyConfiguration connectionProxy, @@ -76,6 +111,14 @@ public void request(Request request, request(request, new Options(null, isAsync, connectionProxy), progress, complete); } + /** + * 构造函数 + * + * @param request 请求信息 + * @param options 可选信息 + * @param progress 进度回调 + * @param complete 完成回调 + */ @Override public void request(Request request, Options options, @@ -156,6 +199,9 @@ public void run() { } } + /** + * 取消请求 + */ @Override public synchronized void cancel() { if (call != null && !call.isCanceled()) { @@ -163,6 +209,11 @@ public synchronized void cancel() { } } + /** + * client id + * + * @return client id + */ @Override public String getClientId() { return "okhttp"; diff --git a/library/src/main/java/com/qiniu/android/http/serverRegion/HttpServerManager.java b/library/src/main/java/com/qiniu/android/http/serverRegion/HttpServerManager.java index 631fec727..72ff4c34b 100644 --- a/library/src/main/java/com/qiniu/android/http/serverRegion/HttpServerManager.java +++ b/library/src/main/java/com/qiniu/android/http/serverRegion/HttpServerManager.java @@ -12,6 +12,9 @@ public class HttpServerManager { private ConcurrentHashMap serversInfo = new ConcurrentHashMap<>(); private final static HttpServerManager manager = new HttpServerManager(); + private HttpServerManager() { + } + /** * 单例对象 * diff --git a/library/src/main/java/com/qiniu/android/http/serverRegion/UploadDomainRegion.java b/library/src/main/java/com/qiniu/android/http/serverRegion/UploadDomainRegion.java index 8b31a7dd1..1d5ad2969 100644 --- a/library/src/main/java/com/qiniu/android/http/serverRegion/UploadDomainRegion.java +++ b/library/src/main/java/com/qiniu/android/http/serverRegion/UploadDomainRegion.java @@ -17,7 +17,9 @@ import java.util.HashMap; import java.util.List; - +/** + * region domain 管理对象 + */ public class UploadDomainRegion implements IUploadRegion { private final static int Http3FrozenTime = 3600 * 24; @@ -39,6 +41,18 @@ public class UploadDomainRegion implements IUploadRegion { private HashMap oldDomainHashMap; private ZoneInfo zoneInfo; + /** + * 构造函数 + */ + public UploadDomainRegion() { + } + + /** + * 是否和另一个 region 相同 + * + * @param region 另一个 region + * @return 是否相同 + */ @Override public boolean isEqual(IUploadRegion region) { if (region == null) { @@ -68,16 +82,31 @@ public boolean isEqual(IUploadRegion region) { } } + /** + * 是否有效 + * + * @return 是否有效 + */ @Override public boolean isValid() { return !isAllFrozen && (domainHostList.size() > 0 || oldDomainHostList.size() > 0); } + /** + * 获取 zone info + * + * @return zone info + */ @Override public ZoneInfo getZoneInfo() { return zoneInfo; } + /** + * 设置 zone info + * + * @param zoneInfo ZoneInfo + */ @Override public void setupRegionData(ZoneInfo zoneInfo) { if (zoneInfo == null) { @@ -118,6 +147,14 @@ private HashMap createDomainDictionary(List return domainHashMap; } + /** + * 获取下一个可重试的 Server + * + * @param requestState 请求状态 + * @param responseInfo 请求响应信息 + * @param freezeServer 冻结的 Server 信息 + * @return 下一个可重试的 Server + */ @Override public IUploadServer getNextServer(UploadRequestState requestState, ResponseInfo responseInfo, IUploadServer freezeServer) { if (isAllFrozen || requestState == null) { @@ -241,6 +278,11 @@ public boolean condition(String host, UploadServer serverP, UploadServer filterS return server; } + /** + * 更新 host 的 ip 列表 + * + * @param host host + */ @Override public void updateIpListFormHost(String host) { if (host == null) { diff --git a/library/src/main/java/com/qiniu/android/http/serverRegion/UploadServer.java b/library/src/main/java/com/qiniu/android/http/serverRegion/UploadServer.java index dabb9cd89..22bc3073c 100644 --- a/library/src/main/java/com/qiniu/android/http/serverRegion/UploadServer.java +++ b/library/src/main/java/com/qiniu/android/http/serverRegion/UploadServer.java @@ -2,6 +2,9 @@ import com.qiniu.android.http.request.IUploadServer; +/** + * 上传服务 + */ public class UploadServer extends IUploadServer { private final String serverId; @@ -11,6 +14,15 @@ public class UploadServer extends IUploadServer { private final Long ipPrefetchedTime; private String httpVersion; + /** + * 构造函数 + * + * @param serverId server id + * @param host host + * @param ip ip + * @param source dns 解析源 + * @param ipPrefetchedTime dns 解析时间 + */ public UploadServer(String serverId, String host, String ip, @@ -23,35 +35,70 @@ public UploadServer(String serverId, this.ipPrefetchedTime = ipPrefetchedTime; } + /** + * 获取 server id + * + * @return server id + */ @Override public String getServerId() { return this.serverId; } + /** + * 获取 HTTP version + * + * @return HTTP version + */ @Override public String getHttpVersion() { return httpVersion; } + /** + * 配置 HTTP version + * + * @param httpVersion HTTP version + */ public void setHttpVersion(String httpVersion) { this.httpVersion = httpVersion; } + /** + * 获取 IP + * + * @return IP + */ @Override public String getIp() { return ip; } + /** + * 获取 dns 解析源 + * + * @return dns 解析源 + */ @Override public String getSource() { return source; } + /** + * 获取 dns 解析时间 + * + * @return dns 解析时间 + */ @Override public Long getIpPrefetchedTime() { return ipPrefetchedTime; } + /** + * 获取服务域名 + * + * @return 服务域名 + */ @Override public String getHost() { return host; diff --git a/library/src/main/java/com/qiniu/android/http/serverRegion/UploadServerFreezeManager.java b/library/src/main/java/com/qiniu/android/http/serverRegion/UploadServerFreezeManager.java index c21bdb1f2..fe93e4be5 100644 --- a/library/src/main/java/com/qiniu/android/http/serverRegion/UploadServerFreezeManager.java +++ b/library/src/main/java/com/qiniu/android/http/serverRegion/UploadServerFreezeManager.java @@ -13,13 +13,27 @@ public class UploadServerFreezeManager { private ConcurrentHashMap frozenInfo = new ConcurrentHashMap<>(); private final static UploadServerFreezeManager manager = new UploadServerFreezeManager(); + /** + * 构造函数 + */ public UploadServerFreezeManager() { } + /** + * 获取单例 + * + * @return 单例 + */ public static UploadServerFreezeManager getInstance() { return manager; } + /** + * 查看 type 是否冻结 + * + * @param type type + * @return 是否冻结 + */ public boolean isTypeFrozen(String type) { if (type == null || type.length() == 0) { return true; @@ -32,6 +46,12 @@ public boolean isTypeFrozen(String type) { return isFrozen; } + /** + * 冻结 type + * + * @param type type + * @param frozenTime 冻结时间 + */ public void freezeType(String type, int frozenTime) { if (type == null || type.length() == 0) { return; @@ -44,6 +64,11 @@ public void freezeType(String type, int frozenTime) { item.freeze(frozenTime); } + /** + * 解冻 type + * + * @param type type + */ public void unfreezeType(String type) { if (type == null || type.length() == 0) { return; diff --git a/library/src/main/java/com/qiniu/android/http/serverRegion/UploadServerFreezeUtil.java b/library/src/main/java/com/qiniu/android/http/serverRegion/UploadServerFreezeUtil.java index 96cb93103..dcd06bbfb 100644 --- a/library/src/main/java/com/qiniu/android/http/serverRegion/UploadServerFreezeUtil.java +++ b/library/src/main/java/com/qiniu/android/http/serverRegion/UploadServerFreezeUtil.java @@ -2,17 +2,42 @@ import com.qiniu.android.utils.Utils; +/** + * UploadServerFreezeUtil + */ public class UploadServerFreezeUtil { private final static UploadServerFreezeManager globalHttp3Freezer = new UploadServerFreezeManager(); + + private UploadServerFreezeUtil() { + } + + /** + * 获取 HTTP/3 冻结管理单例 + * + * @return 单例 + */ public static UploadServerFreezeManager globalHttp3Freezer() { return globalHttp3Freezer; } private final static UploadServerFreezeManager globalHttp2Freezer = new UploadServerFreezeManager(); + + /** + * 获取 HTTP/2 冻结管理单例 + * + * @return 单例 + */ public static UploadServerFreezeManager globalHttp2Freezer() { return globalHttp2Freezer; } + /** + * 查看 type 是否被冻结管理者冻结 + * + * @param type type + * @param freezeManagerList 结管理者 + * @return 是否冻结 + */ public static boolean isTypeFrozenByFreezeManagers(String type, UploadServerFreezeManager[] freezeManagerList) { if (type == null || type.length() == 0) { return true; @@ -31,6 +56,13 @@ public static boolean isTypeFrozenByFreezeManagers(String type, UploadServerFree return isFrozen; } + /** + * 获取 type + * + * @param host host + * @param ip ip + * @return type + */ public static String getFrozenType(String host, String ip) { String ipType = Utils.getIpType(ip, host); return String.format("%s-%s", host, ipType); diff --git a/library/src/main/java/com/qiniu/android/storage/Configuration.java b/library/src/main/java/com/qiniu/android/storage/Configuration.java index cbcfbffdf..5b12eb8c4 100644 --- a/library/src/main/java/com/qiniu/android/storage/Configuration.java +++ b/library/src/main/java/com/qiniu/android/storage/Configuration.java @@ -206,6 +206,12 @@ public static class Builder { private int resumeUploadVersion = RESUME_UPLOAD_VERSION_V1; private int concurrentTaskCount = 3; + /** + * 构造函数 + */ + public Builder() { + } + /** * Builder 构造方法 * diff --git a/library/src/main/java/com/qiniu/android/storage/GlobalConfiguration.java b/library/src/main/java/com/qiniu/android/storage/GlobalConfiguration.java index e771c2574..3c28ed65e 100644 --- a/library/src/main/java/com/qiniu/android/storage/GlobalConfiguration.java +++ b/library/src/main/java/com/qiniu/android/storage/GlobalConfiguration.java @@ -173,10 +173,20 @@ public class GlobalConfiguration { private GlobalConfiguration() { } + /** + * 获取全局配置单例 + * + * @return 单例 + */ public static GlobalConfiguration getInstance() { return configuration; } + /** + * 获取 UDP dns ipv4 server 列表 + * + * @return server 列表 + */ public String[] getUdpDnsIpv4Servers() { if (udpDnsIpv4Servers != null) { return udpDnsIpv4Servers; @@ -185,6 +195,11 @@ public String[] getUdpDnsIpv4Servers() { } } + /** + * 获取 UDP dns ipv6 server 列表 + * + * @return server 列表 + */ public String[] getUdpDnsIpv6Servers() { if (udpDnsIpv6Servers != null) { return udpDnsIpv6Servers; @@ -193,6 +208,11 @@ public String[] getUdpDnsIpv6Servers() { } } + /** + * 获取 Doh ipv4 server 列表 + * + * @return server 列表 + */ public String[] getDohIpv4Servers() { if (dohIpv4Servers != null) { return dohIpv4Servers; @@ -230,6 +250,7 @@ public String[] getConnectCheckUrls() { /** * 解析 Base64 数据为字符串数组 * + * @param data base64 data * @return 字符串数组 */ public static String[] parseBase64Array(String data) { diff --git a/library/src/main/java/com/qiniu/android/storage/NetReadyHandler.java b/library/src/main/java/com/qiniu/android/storage/NetReadyHandler.java index cbb550e6c..f0b598feb 100644 --- a/library/src/main/java/com/qiniu/android/storage/NetReadyHandler.java +++ b/library/src/main/java/com/qiniu/android/storage/NetReadyHandler.java @@ -4,5 +4,9 @@ * Created by bailong on 16/9/7. */ public interface NetReadyHandler { + + /** + * 等待网络正常连接 + */ void waitReady(); } diff --git a/library/src/main/java/com/qiniu/android/storage/UpProgressBytesHandler.java b/library/src/main/java/com/qiniu/android/storage/UpProgressBytesHandler.java index 35b2ef445..9ad23e726 100644 --- a/library/src/main/java/com/qiniu/android/storage/UpProgressBytesHandler.java +++ b/library/src/main/java/com/qiniu/android/storage/UpProgressBytesHandler.java @@ -1,6 +1,10 @@ package com.qiniu.android.storage; +/** + * UpProgressBytesHandler + */ public interface UpProgressBytesHandler extends UpProgressHandler { + /** * 用户自定义进度处理类必须实现的方法 * 注: diff --git a/library/src/main/java/com/qiniu/android/storage/UpToken.java b/library/src/main/java/com/qiniu/android/storage/UpToken.java index 5e23de4e1..5ad38e3e3 100644 --- a/library/src/main/java/com/qiniu/android/storage/UpToken.java +++ b/library/src/main/java/com/qiniu/android/storage/UpToken.java @@ -11,8 +11,19 @@ */ public final class UpToken { + /** + * token + */ public final String token; + + /** + * accessKey + */ public final String accessKey; + + /** + * bucket + */ public final String bucket; private long deadline = -1; @@ -25,6 +36,12 @@ private UpToken(String returnUrl, String token, String accessKey, String bucket) this.bucket = bucket; } + /** + * 构造函数 + * + * @param token token + * @return UpToken + */ public static UpToken parse(String token) { if (token == null) { return null; @@ -70,28 +87,59 @@ public static UpToken parse(String token) { return upToken; } + /** + * 获取无效 Token + * + * @return UpToken + */ public static UpToken getInvalidToken() { UpToken token = new UpToken("", "", "", ""); token.deadline = -1; return token; } + /** + * 判断 Token 是否有效 + * + * @param token Token + * @return 是否有效 + */ public static boolean isInvalid(UpToken token) { return token == null || !token.isValid(); } + /** + * 判断当前 Token 是否有效 + * + * @return 是否有效 + */ public boolean isValid() { return accessKey != null && !accessKey.isEmpty() && bucket != null && !bucket.isEmpty(); } + /** + * 获取 Token 字符串 + * + * @return Token 字符串 + */ public String toString() { return token; } + /** + * 判断 Token 中是否有 return url + * + * @return Token 中是否有 return url + */ public boolean hasReturnUrl() { return !returnUrl.equals(""); } + /** + * Token 标识 + * + * @return Token 标识 + */ public String index() { String index = ""; if (accessKey != null) { @@ -103,14 +151,31 @@ public String index() { return index; } + /** + * 获取 Token 有效期 + * + * @return Token 有效期 + */ public long getDeadline() { return deadline; } + /** + * 在未来时间段中,Token 是否有效 + * + * @param duration 未来时间段 + * @return Token 是否有效 + */ public boolean isValidForDuration(long duration) { return isValidBeforeTimestamp((new Date().getTime() / 1000) + duration); } + /** + * 在时间之前,Token 是否有效 + * + * @param date 时间 + * @return 是否有效 + */ public boolean isValidBeforeDate(Date date) { if (date == null) { return false; diff --git a/library/src/main/java/com/qiniu/android/storage/UploadManager.java b/library/src/main/java/com/qiniu/android/storage/UploadManager.java index c08c6944a..a51adbba6 100644 --- a/library/src/main/java/com/qiniu/android/storage/UploadManager.java +++ b/library/src/main/java/com/qiniu/android/storage/UploadManager.java @@ -26,29 +26,44 @@ import java.io.InputStream; import java.util.ArrayList; - +/** + * 上传类 + */ public class UploadManager { private final Configuration config; - + /** + * 构造函数 + * + * @param recorder 文件上传进度记录,可实现断点续传 + */ public UploadManager(Recorder recorder) { this(recorder, null); } + /** + * 构造函数 + * + * @param recorder 文件上传进度记录,可实现断点续传 + * @param keyGen 上文件传进度记录的 key 生成器 + */ public UploadManager(Recorder recorder, KeyGenerator keyGen) { this(new Configuration.Builder().recorder(recorder, keyGen).build()); } /** - * default 1 Threads + * 构造函数 + * 默认为串行 */ public UploadManager() { this(new Configuration.Builder().build()); } /** - * @param config Configuration, default 1 Thread + * 构造函数 + * + * @param config Configuration, 默认为串行 */ public UploadManager(Configuration config) { this.config = config != null ? config : new Configuration.Builder().build(); @@ -522,7 +537,7 @@ private void reportQuality(String key, } else if (source instanceof byte[]) { fileSize = ((byte[]) source).length; } - item.setReport((Long)fileSize, ReportItem.QualityKeyFileSize); + item.setReport((Long) fileSize, ReportItem.QualityKeyFileSize); // 统计当前文件上传速度,也即用户感知速度: 总文件大小 / 总耗时 if (source != null && responseInfo.isOK() && taskMetrics.totalElapsedTime() > 0) { diff --git a/library/src/main/java/com/qiniu/android/storage/UploadOptions.java b/library/src/main/java/com/qiniu/android/storage/UploadOptions.java index 47e6b8c79..b43d0ffd9 100644 --- a/library/src/main/java/com/qiniu/android/storage/UploadOptions.java +++ b/library/src/main/java/com/qiniu/android/storage/UploadOptions.java @@ -48,6 +48,15 @@ public final class UploadOptions { */ public final NetReadyHandler netReadyHandler; + /** + * 构造函数 + * + * @param params 参数 + * @param mimeType mime type + * @param checkCrc 是否上传前后文件验证一致性 + * @param progressHandler 进度回调 + * @param cancellationSignal 取消函数 + */ public UploadOptions(Map params, String mimeType, boolean checkCrc, @@ -56,15 +65,36 @@ public UploadOptions(Map params, this(params, mimeType, checkCrc, progressHandler, cancellationSignal, null); } + /** + * 构造函数 + * + * @param params 参数 + * @param mimeType mime type + * @param checkCrc 是否上传前后文件验证一致性 + * @param progressHandler 进度回调 + * @param cancellationSignal 取消函数 + * @param netReadyHandler 网络准备回调 + */ public UploadOptions(final Map params, String mimeType, boolean checkCrc, UpProgressHandler progressHandler, UpCancellationSignal cancellationSignal, NetReadyHandler netReadyHandler) { - this(params, null, mimeType, checkCrc, progressHandler, cancellationSignal, netReadyHandler); + this(params, null, mimeType, checkCrc, progressHandler, cancellationSignal, netReadyHandler); } + /** + * 构造函数 + * + * @param params 参数 + * @param metaDataParam meta data + * @param mimeType mime type + * @param checkCrc 是否上传前后文件验证一致性 + * @param progressHandler 进度回调 + * @param cancellationSignal 取消函数 + * @param netReadyHandler 网络准备回调 + */ public UploadOptions(final Map params, final Map metaDataParam, String mimeType, @@ -79,7 +109,8 @@ public UploadOptions(final Map params, if (netCheckTime != null) { netReadyCheckTime = Integer.parseInt(netCheckTime); } - } catch (Exception e) {} + } catch (Exception e) { + } this.params = filterParam(params); this.metaDataParam = filterMetaDataParam(metaDataParam); this.mimeType = mime(mimeType); @@ -157,7 +188,11 @@ private static Map filterMetaDataParam(Map param return ret; } - + /** + * 默认可选属性 + * + * @return UploadOptions + */ public static UploadOptions defaultOptions() { return new UploadOptions(null, null, false, null, null); } diff --git a/library/src/main/java/com/qiniu/android/storage/serverConfig/ServerConfig.java b/library/src/main/java/com/qiniu/android/storage/serverConfig/ServerConfig.java index eb5ab073d..a0a1795df 100644 --- a/library/src/main/java/com/qiniu/android/storage/serverConfig/ServerConfig.java +++ b/library/src/main/java/com/qiniu/android/storage/serverConfig/ServerConfig.java @@ -10,6 +10,9 @@ import java.util.ArrayList; import java.util.List; +/** + * server config + */ public class ServerConfig implements Cache.Object { private long timestamp; @@ -19,6 +22,11 @@ public class ServerConfig implements Cache.Object { private DnsConfig dnsConfig; private ConnectCheckConfig connectCheckConfig; + /** + * 构造函数 + * + * @param info json info + */ public ServerConfig(JSONObject info) { if (info == null) { return; @@ -48,31 +56,64 @@ public ServerConfig(JSONObject info) { } } + /** + * 获取 json 数据 + * + * @return JSONObject + */ @Override public JSONObject toJson() { return info; } + /** + * 获取 json 数据 + * + * @return JSONObject + */ public JSONObject getInfo() { return toJson(); } + /** + * 获取区域配置 + * + * @return 区域配置 + */ public RegionConfig getRegionConfig() { return regionConfig; } + /** + * 获取 DNS 配置 + * + * @return DNS 配置 + */ public DnsConfig getDnsConfig() { return dnsConfig; } + /** + * 获取网络连接检测配置 + * + * @return 网络连接检测配置 + */ public ConnectCheckConfig getConnectCheckConfig() { return connectCheckConfig; } + /** + * 配置信息是否有效 + * + * @return 配置信息是否有效 + */ public boolean isValid() { return Utils.currentSecondTimestamp() < (this.timestamp + this.ttl); } + /** + * 区域配置 + */ public static class RegionConfig { private long clearId; private boolean clearCache; @@ -86,15 +127,28 @@ public static class RegionConfig { this.clearCache = info.optBoolean("clear_cache", false); } + /** + * 获取 clearId + * + * @return clearId + */ public long getClearId() { return clearId; } + /** + * 获取 clearCache + * + * @return clearCache + */ public boolean getClearCache() { return clearCache; } } + /** + * DNS 配置 + */ public static class DnsConfig { private Boolean enable; private long clearId; @@ -116,27 +170,55 @@ public static class DnsConfig { this.dohDnsConfig = new DohDnsConfig(info.optJSONObject("doh")); } + /** + * DNS 是否生效 + * + * @return DNS 是否生效 + */ public Boolean getEnable() { return enable; } + /** + * 获取 clearId + * + * @return clearId + */ public long getClearId() { return clearId; } + /** + * 获取 clearCache + * + * @return clearCache + */ public boolean getClearCache() { return clearCache; } + /** + * 获取 udp dns 配置信息 + * + * @return udp dns 配置信息 + */ public UdpDnsConfig getUdpDnsConfig() { return udpDnsConfig; } + /** + * 获取 doh 配置信息 + * + * @return doh 配置信息 + */ public DohDnsConfig getDohDnsConfig() { return dohDnsConfig; } } + /** + * dns server + */ public static class DnsServer { private boolean isOverride; private String[] servers; @@ -165,15 +247,28 @@ public static class DnsServer { this.servers = servers.toArray(new String[0]); } + /** + * 是否覆盖配置 + * + * @return 是否覆盖配置 + */ public boolean getIsOverride() { return isOverride; } + /** + * 获取 servers + * + * @return servers + */ public String[] getServers() { return servers; } } + /** + * udp dns 配置 + */ public static class UdpDnsConfig { private Boolean enable; private DnsServer ipv4Server; @@ -192,19 +287,37 @@ public static class UdpDnsConfig { this.ipv6Server = new DnsServer(info.optJSONObject("ipv6")); } + /** + * 配置是否生效 + * + * @return 配置是否生效 + */ public Boolean getEnable() { return enable; } + /** + * 获取 ipv4 server + * + * @return ipv4 server + */ public DnsServer getIpv4Server() { return ipv4Server; } + /** + * 获取 ipv6 server + * + * @return ipv6 server + */ public DnsServer getIpv6Server() { return ipv6Server; } } + /** + * doh 配置 + */ public static class DohDnsConfig { private Boolean enable; private DnsServer ipv4Server; @@ -223,19 +336,37 @@ public static class DohDnsConfig { this.ipv6Server = new DnsServer(info.optJSONObject("ipv6")); } + /** + * 配置是否生效 + * + * @return 配置是否生效 + */ public Boolean getEnable() { return enable; } + /** + * 获取 ipv4 server + * + * @return ipv4 server + */ public DnsServer getIpv4Server() { return ipv4Server; } + /** + * 获取 ipv6 server + * + * @return ipv6 server + */ public DnsServer getIpv6Server() { return ipv6Server; } } + /** + * connect check config + */ public static class ConnectCheckConfig { private Boolean isOverride; private Boolean enable; @@ -273,18 +404,38 @@ public static class ConnectCheckConfig { } } + /** + * 是否覆盖配置 + * + * @return 是否覆盖配置 + */ public Boolean getOverride() { return isOverride; } + /** + * 配置是否生效 + * + * @return 配置是否生效 + */ public Boolean getEnable() { return enable; } + /** + * 获取超时时间 + * + * @return 超时时间 + */ public Integer getTimeoutMs() { return timeoutMs; } + /** + * 获取网络检测的 url 列表 + * + * @return 网络检测的 url 列表 + */ public String[] getUrls() { return urls; } diff --git a/library/src/main/java/com/qiniu/android/storage/serverConfig/ServerConfigMonitor.java b/library/src/main/java/com/qiniu/android/storage/serverConfig/ServerConfigMonitor.java index 68ded4152..31d434111 100644 --- a/library/src/main/java/com/qiniu/android/storage/serverConfig/ServerConfigMonitor.java +++ b/library/src/main/java/com/qiniu/android/storage/serverConfig/ServerConfigMonitor.java @@ -8,6 +8,9 @@ import java.util.List; import java.util.Random; +/** + * server config monitor + */ public class ServerConfigMonitor { private static final String TransactionKey = "ServerConfig"; @@ -15,23 +18,46 @@ public class ServerConfigMonitor { private final ServerConfigCache cache = new ServerConfigCache(); private static final ServerConfigMonitor configMonitor = new ServerConfigMonitor(); + private ServerConfigMonitor() { + } + + /** + * 是否开启 + * + * @param enable 是否开启 + */ public static void setEnable(boolean enable) { configMonitor.enable = enable; } + /** + * 配置上传 Token,SDK 会在上传文件时自动配置 + * + * @param token 上传 Token + */ public static void setToken(String token) { ServerConfigSynchronizer.setToken(token); } + /** + * 配置 server hosts + * + * @param hosts hosts + */ public static void setServerHosts(String[] hosts) { ServerConfigSynchronizer.setHosts(hosts); } + /** + * 清理配置缓存 + */ public static void removeConfigCache() { configMonitor.cache.removeConfigCache(); } - // 开始监控 + /** + * 开始监控 + */ public synchronized static void startMonitor() { if (!configMonitor.enable) { return; @@ -54,7 +80,9 @@ public void run() { transactionManager.addTransaction(transaction); } - // 停止监控 + /** + * 停止监控 + */ public synchronized static void endMonitor() { TransactionManager transactionManager = TransactionManager.getInstance(); List transactions = transactionManager.transactionsForName(TransactionKey); diff --git a/library/src/main/java/com/qiniu/android/storage/serverConfig/ServerUserConfig.java b/library/src/main/java/com/qiniu/android/storage/serverConfig/ServerUserConfig.java index 27c113e8a..c40d82e82 100644 --- a/library/src/main/java/com/qiniu/android/storage/serverConfig/ServerUserConfig.java +++ b/library/src/main/java/com/qiniu/android/storage/serverConfig/ServerUserConfig.java @@ -6,6 +6,9 @@ import org.json.JSONException; import org.json.JSONObject; +/** + * server user config + */ public class ServerUserConfig implements Cache.Object { private long timestamp; @@ -15,6 +18,11 @@ public class ServerUserConfig implements Cache.Object { private JSONObject info; + /** + * 构造函数 + * + * @param info json 数据 + */ public ServerUserConfig(JSONObject info) { if (info == null) { return; @@ -46,23 +54,48 @@ public ServerUserConfig(JSONObject info) { } } + /** + * 获取 json 数据 + * + * @return json 数据 + */ @Override public JSONObject toJson() { return info; } + /** + * HTTP/3 是否开启 + * + * @return HTTP/3 是否开启 + */ public Boolean getHttp3Enable() { return http3Enable; } + /** + * 网络检测是否开启 + * + * @return 网络检测是否开启 + */ public Boolean getNetworkCheckEnable() { return networkCheckEnable; } + /** + * 获取 json 信息 + * + * @return json 信息 + */ public JSONObject getInfo() { return toJson(); } + /** + * 配置是否有效 + * + * @return 配置是否有效 + */ public boolean isValid() { return Utils.currentSecondTimestamp() < (this.timestamp + this.ttl); } diff --git a/library/src/main/java/com/qiniu/android/transaction/TransactionManager.java b/library/src/main/java/com/qiniu/android/transaction/TransactionManager.java index 10a721e9d..fc30b9d1f 100644 --- a/library/src/main/java/com/qiniu/android/transaction/TransactionManager.java +++ b/library/src/main/java/com/qiniu/android/transaction/TransactionManager.java @@ -12,11 +12,19 @@ */ public class TransactionManager { - /// 事务链表 + /** + * 事务链表 + */ protected final ConcurrentLinkedQueue transactionList = new ConcurrentLinkedQueue<>(); - /// 事务定时器 + + /** + * 事务定时器 + */ private Timer timer; + /** + * action 数量 + */ protected long actionCount = 0; private static final TransactionManager transactionManager = new TransactionManager(); @@ -24,11 +32,21 @@ public class TransactionManager { private TransactionManager() { } + /** + * 获取事务管理器单例 + * + * @return 事务管理器单例 + */ public static TransactionManager getInstance() { return transactionManager; } - /// 根据name查找事务 + /** + * 根据 name 查找事务 + * + * @param name name + * @return 事务列表 + */ public ArrayList transactionsForName(String name) { ArrayList arrayList = new ArrayList<>(); for (Transaction transaction : transactionList) { @@ -39,7 +57,12 @@ public ArrayList transactionsForName(String name) { return arrayList; } - /// 是否存在某个名称的事务 + /** + * 是否存在某个名称的事务 + * + * @param name 事务名称 + * @return 是否存在 + */ public boolean existTransactionsForName(String name) { boolean isExist = false; for (Transaction transaction : transactionList) { @@ -51,7 +74,11 @@ public boolean existTransactionsForName(String name) { return isExist; } - /// 添加一个事务 + /** + * 添加一个事务 + * + * @param transaction 事务 + */ public void addTransaction(Transaction transaction) { if (transaction == null) { return; @@ -60,7 +87,11 @@ public void addTransaction(Transaction transaction) { createTimer(); } - /// 移除一个事务 + /** + * 移除一个事务 + * + * @param transaction 事务 + */ public void removeTransaction(Transaction transaction) { if (transaction == null) { return; @@ -68,7 +99,11 @@ public void removeTransaction(Transaction transaction) { transactionList.remove(transaction); } - /// 在下一次循环执行事务, 该事务如果未被添加到事务列表,会自动添加 + /** + * 在下一次循环执行事务, 该事务如果未被添加到事务列表,会自动添加 + * + * @param transaction 事务 + */ public synchronized void performTransaction(Transaction transaction) { if (transaction == null) { return; @@ -80,7 +115,9 @@ public synchronized void performTransaction(Transaction transaction) { transaction.nextExecutionTime = Utils.currentSecondTimestamp(); } - /// 销毁资源 清空事务链表 销毁常驻线程 + /** + * 销毁资源 清空事务链表 销毁常驻线程 + */ public synchronized void destroyResource() { invalidateTimer(); transactionList.clear(); @@ -124,16 +161,25 @@ private void timerAction() { handleAllTransaction(); } - + /** + * Transaction + */ public static class Transaction { - // 事务名称 + /** + * 事务名称 + */ public final String name; - // 事务延迟执行时间 单位:秒 + + /** + * 事务延迟执行时间 单位:秒 + */ public final int after; - // 事务内容 - public final Runnable actionHandler; + /** + * 事务内容 + */ + public final Runnable actionHandler; // 普通类型事务,事务体仅会执行一次 private static final int TransactionTypeNormal = 0; @@ -145,14 +191,25 @@ public static class Transaction { private final int interval; // 创建时间 private long createTime; - // 下一次需要执行的时间 + + /** + * 下一次需要执行的时间 + */ protected long nextExecutionTime; - // 已执行次数 + /** + * 已执行次数 + */ protected long executedCount = 0; private boolean isExecuting = false; - + /** + * 构造函数 + * + * @param name 名称 + * @param after 执行延迟时间 + * @param actionHandler 执行体 + */ public Transaction(String name, int after, Runnable actionHandler) { @@ -166,7 +223,14 @@ public Transaction(String name, this.nextExecutionTime = this.createTime + after; } - + /** + * 构造函数 + * + * @param name 名称 + * @param after 执行延迟时间 + * @param interval 周期执行时间间隔 + * @param actionHandler 执行体 + */ public Transaction(String name, int after, int interval, @@ -181,6 +245,11 @@ public Transaction(String name, this.nextExecutionTime = this.createTime + after; } + /** + * 是否需要执行 + * + * @return 是否需要执行 + */ protected boolean shouldAction() { long currentTime = Utils.currentSecondTimestamp(); if (this.type == TransactionTypeNormal) { @@ -192,6 +261,11 @@ protected boolean shouldAction() { } } + /** + * 是否已经结束 + * + * @return 是否已经结束 + */ protected boolean maybeCompleted() { if (this.type == TransactionTypeNormal) { return executedCount > 0; @@ -220,6 +294,11 @@ private synchronized void handleAction() { } } + /** + * 是否正在执行 + * + * @return 是否正在执行 + */ public boolean isExecuting() { return isExecuting; } diff --git a/library/src/main/java/com/qiniu/android/utils/AndroidNetwork.java b/library/src/main/java/com/qiniu/android/utils/AndroidNetwork.java index c321d8de2..1b2265bb2 100644 --- a/library/src/main/java/com/qiniu/android/utils/AndroidNetwork.java +++ b/library/src/main/java/com/qiniu/android/utils/AndroidNetwork.java @@ -29,6 +29,9 @@ */ public final class AndroidNetwork { + private AndroidNetwork() { + } + /** * 网络是否正常连接 * diff --git a/library/src/main/java/com/qiniu/android/utils/AsyncRun.java b/library/src/main/java/com/qiniu/android/utils/AsyncRun.java index e37e1a3b1..ab1f70a0a 100644 --- a/library/src/main/java/com/qiniu/android/utils/AsyncRun.java +++ b/library/src/main/java/com/qiniu/android/utils/AsyncRun.java @@ -25,6 +25,9 @@ public final class AsyncRun { 1000L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue()); + private AsyncRun() { + } + /** * 主线程执行任务 * diff --git a/library/src/main/java/com/qiniu/android/utils/BytesUtils.java b/library/src/main/java/com/qiniu/android/utils/BytesUtils.java index acf6294ee..627038434 100644 --- a/library/src/main/java/com/qiniu/android/utils/BytesUtils.java +++ b/library/src/main/java/com/qiniu/android/utils/BytesUtils.java @@ -7,6 +7,9 @@ */ public class BytesUtils { + private BytesUtils() { + } + /** * 获取 byte 数组的子数组 * diff --git a/library/src/main/java/com/qiniu/android/utils/Constants.java b/library/src/main/java/com/qiniu/android/utils/Constants.java index 17b6196d2..92c2836fe 100644 --- a/library/src/main/java/com/qiniu/android/utils/Constants.java +++ b/library/src/main/java/com/qiniu/android/utils/Constants.java @@ -30,5 +30,6 @@ public class Constants { */ public static final String NETWORK_CLASS_4_G = "4g"; - + private Constants() { + } } diff --git a/library/src/main/java/com/qiniu/android/utils/ContextGetter.java b/library/src/main/java/com/qiniu/android/utils/ContextGetter.java index 33213f243..3e4feadbe 100644 --- a/library/src/main/java/com/qiniu/android/utils/ContextGetter.java +++ b/library/src/main/java/com/qiniu/android/utils/ContextGetter.java @@ -11,6 +11,9 @@ public final class ContextGetter { private static Context context = applicationContext(); + private ContextGetter() { + } + /** * application Context * diff --git a/library/src/main/java/com/qiniu/android/utils/Crc32.java b/library/src/main/java/com/qiniu/android/utils/Crc32.java index 52fbd84ba..65e79d38e 100644 --- a/library/src/main/java/com/qiniu/android/utils/Crc32.java +++ b/library/src/main/java/com/qiniu/android/utils/Crc32.java @@ -10,6 +10,9 @@ */ public final class Crc32 { + private Crc32() { + } + /** * 计算二进制字节校验码 * diff --git a/library/src/main/java/com/qiniu/android/utils/Etag.java b/library/src/main/java/com/qiniu/android/utils/Etag.java index 38ceef761..85e3fa5d4 100644 --- a/library/src/main/java/com/qiniu/android/utils/Etag.java +++ b/library/src/main/java/com/qiniu/android/utils/Etag.java @@ -16,6 +16,9 @@ */ public final class Etag { + private Etag() { + } + /** * 计算二进制数据的etag * diff --git a/library/src/main/java/com/qiniu/android/utils/GZipUtil.java b/library/src/main/java/com/qiniu/android/utils/GZipUtil.java index 776018f95..00eb1c185 100644 --- a/library/src/main/java/com/qiniu/android/utils/GZipUtil.java +++ b/library/src/main/java/com/qiniu/android/utils/GZipUtil.java @@ -11,8 +11,12 @@ */ public class GZipUtil { + private GZipUtil() { + } + /** * 压缩字符串 + * * @param string 带压缩数据 * @return 压缩后的数据 */ @@ -25,6 +29,7 @@ public static byte[] gZip(String string) { /** * 压缩 byte 数组 + * * @param bytes 带压缩数据 * @return 压缩后的数据 */ @@ -56,6 +61,7 @@ public static byte[] gZip(byte[] bytes) { /** * 解压缩 byte 数组 + * * @param bytes 待解压缩数据 * @return 解压缩后的数据 */ diff --git a/library/src/main/java/com/qiniu/android/utils/GroupTaskThread.java b/library/src/main/java/com/qiniu/android/utils/GroupTaskThread.java index 93302bbd4..fbadcb687 100644 --- a/library/src/main/java/com/qiniu/android/utils/GroupTaskThread.java +++ b/library/src/main/java/com/qiniu/android/utils/GroupTaskThread.java @@ -106,14 +106,29 @@ private void completeAction() { */ public abstract static class GroupTask { + /** + * task 状态 + */ protected enum State { + /** + * 等待执行 + */ Waiting, + + /** + * 执行中 + */ Running, + + /** + * 执行完成 + */ Complete } - ; - + /** + * task 状态 + */ protected State state = State.Waiting; /** diff --git a/library/src/main/java/com/qiniu/android/utils/IPAddressUtil.java b/library/src/main/java/com/qiniu/android/utils/IPAddressUtil.java index bebc8ea2c..3b31a7a17 100644 --- a/library/src/main/java/com/qiniu/android/utils/IPAddressUtil.java +++ b/library/src/main/java/com/qiniu/android/utils/IPAddressUtil.java @@ -1,10 +1,16 @@ package com.qiniu.android.utils; +/** + * ip util + */ public class IPAddressUtil { private final static int INADDR4SZ = 4; private final static int INADDR16SZ = 16; private final static int INT16SZ = 2; + private IPAddressUtil() { + } + /** * Converts IPv4 address in its textual presentation form * into its numeric binary form. @@ -81,11 +87,10 @@ public static byte[] textToNumericFormatV4(String src) { return res; } - /* + /** * Convert IPv6 presentation level address to network order binary form. * credit: - * Converted from C code from Solaris 8 (inet_pton) - * + * Converted from C code from Solaris 8 (inet_pton) * Any component of the string following a per-cent % is ignored. * * @param src a String representing an IPv6 address in textual format diff --git a/library/src/main/java/com/qiniu/android/utils/Json.java b/library/src/main/java/com/qiniu/android/utils/Json.java index 7787820d3..e3b0d9e34 100644 --- a/library/src/main/java/com/qiniu/android/utils/Json.java +++ b/library/src/main/java/com/qiniu/android/utils/Json.java @@ -11,6 +11,9 @@ */ public final class Json { + private Json() { + } + /** * map 转 json * diff --git a/library/src/main/java/com/qiniu/android/utils/ListVector.java b/library/src/main/java/com/qiniu/android/utils/ListVector.java index d84745518..38eed84c3 100644 --- a/library/src/main/java/com/qiniu/android/utils/ListVector.java +++ b/library/src/main/java/com/qiniu/android/utils/ListVector.java @@ -72,9 +72,17 @@ public synchronized ListVector subList(int fromIndex, int toIndex) { /** * EnumeratorHandler + * * @param enumerate 对象的类型 */ public interface EnumeratorHandler { + + /** + * enumerate + * + * @param t T + * @return stop + */ boolean enumerate(T t); } } diff --git a/library/src/main/java/com/qiniu/android/utils/LogUtil.java b/library/src/main/java/com/qiniu/android/utils/LogUtil.java index 6f9e9f97c..13665f9cb 100644 --- a/library/src/main/java/com/qiniu/android/utils/LogUtil.java +++ b/library/src/main/java/com/qiniu/android/utils/LogUtil.java @@ -15,6 +15,9 @@ public class LogUtil { private static boolean enableFile = true; private static boolean enableFunction = false; + private LogUtil() { + } + /** * 开启日志 * diff --git a/library/src/main/java/com/qiniu/android/utils/MD5.java b/library/src/main/java/com/qiniu/android/utils/MD5.java index f6ca47eb6..23278c44d 100644 --- a/library/src/main/java/com/qiniu/android/utils/MD5.java +++ b/library/src/main/java/com/qiniu/android/utils/MD5.java @@ -1,9 +1,23 @@ package com.qiniu.android.utils; + import java.security.MessageDigest; + import com.qiniu.android.dns.util.Hex; +/** + * MD5 util + */ public class MD5 { + private MD5() { + } + + /** + * MD5 加密 + * + * @param data 带加密数据 + * @return 已加密数据 + */ public static String encrypt(byte[] data) { try { MessageDigest digest = MessageDigest.getInstance("MD5"); diff --git a/library/src/main/java/com/qiniu/android/utils/SingleFlight.java b/library/src/main/java/com/qiniu/android/utils/SingleFlight.java index db6e5a632..7c15478cc 100644 --- a/library/src/main/java/com/qiniu/android/utils/SingleFlight.java +++ b/library/src/main/java/com/qiniu/android/utils/SingleFlight.java @@ -5,16 +5,28 @@ import java.util.List; import java.util.Map; +/** + * single flight + * + * @param T + */ public class SingleFlight { private Map> callInfo = new HashMap<>(); + /** + * 构造函数 + */ + public SingleFlight() { + } + /** * 异步 SingleFlight 执行函数 * * @param key actionHandler 对应的 key,同一时刻同一个 key 最多只有一个对应的 actionHandler 在执行 * @param actionHandler 执行函数,注意:actionHandler 中,【完成回调】和【抛出异常】二者有且有一个,且只能出现一次 * @param completeHandler single flight 执行 actionHandler 后的完成回调 + * @throws Exception 异常 */ public void perform(String key, ActionHandler actionHandler, CompleteHandler completeHandler) throws Exception { if (actionHandler == null) { @@ -124,11 +136,34 @@ private static class SingleFlightCall { private Exception exception; } + /** + * 结束回调 + * + * @param T + */ public interface CompleteHandler { + + /** + * 结束回调 + * + * @param value value + */ void complete(T value); } + /** + * action 回调 + * + * @param T + */ public interface ActionHandler { + + /** + * action 回调 + * + * @param completeHandler 结束回调 + * @throws Exception 异常 + */ void action(CompleteHandler completeHandler) throws Exception; } } diff --git a/library/src/main/java/com/qiniu/android/utils/StringMap.java b/library/src/main/java/com/qiniu/android/utils/StringMap.java index e410f302c..b0a2f7b12 100644 --- a/library/src/main/java/com/qiniu/android/utils/StringMap.java +++ b/library/src/main/java/com/qiniu/android/utils/StringMap.java @@ -5,22 +5,47 @@ import java.util.HashMap; import java.util.Map; +/** + * string map + */ public final class StringMap { private Map map; + /** + * 构造函数 + */ public StringMap() { this(new HashMap()); } + /** + * 构造函数 + * + * @param map map + */ public StringMap(Map map) { this.map = map; } + /** + * 新增键值对 + * + * @param key 键 + * @param value 值 + * @return StringMap + */ public StringMap put(String key, Object value) { map.put(key, value); return this; } + /** + * 新增非空键值对 + * + * @param key 键 + * @param value 值 + * @return StringMap + */ public StringMap putNotEmpty(String key, String value) { if (!StringUtils.isNullOrEmpty(value)) { map.put(key, value); @@ -28,6 +53,13 @@ public StringMap putNotEmpty(String key, String value) { return this; } + /** + * 新增非空键值对 + * + * @param key 键 + * @param value 值 + * @return StringMap + */ public StringMap putNotNull(String key, Object value) { if (value != null) { map.put(key, value); @@ -36,6 +68,14 @@ public StringMap putNotNull(String key, Object value) { } + /** + * 新增键值对 + * + * @param key 键 + * @param val 值 + * @param when 条件 + * @return StringMap + */ public StringMap putWhen(String key, Object val, boolean when) { if (when) { map.put(key, val); @@ -43,39 +83,83 @@ public StringMap putWhen(String key, Object val, boolean when) { return this; } + /** + * 新增键值对 + * + * @param map map + * @return StringMap + */ public StringMap putAll(Map map) { this.map.putAll(map); return this; } + /** + * 新增键值对 + * + * @param map map + * @return StringMap + */ public StringMap putFileds(Map map) { this.map.putAll(map); return this; } + /** + * 新增键值对 + * + * @param map map + * @return StringMap + */ public StringMap putAll(StringMap map) { this.map.putAll(map.map); return this; } + /** + * 遍历 + * + * @param imp Consumer + */ public void forEach(Consumer imp) { for (Map.Entry i : map.entrySet()) { imp.accept(i.getKey(), i.getValue()); } } + /** + * 获取 map 大小 + * + * @return map 大小 + */ public int size() { return map.size(); } + /** + * 获取 map + * + * @return map + */ public Map map() { return this.map; } + /** + * 获取 value + * + * @param key key + * @return value + */ public Object get(String key) { return map.get(key); } + /** + * 获取 string + * + * @return string + */ public String formString() { final StringBuilder b = new StringBuilder(); forEach(new Consumer() { @@ -98,7 +182,17 @@ public void accept(String key, Object value) { return b.toString(); } + /** + * 遍历回调 + */ public interface Consumer { + + /** + * 遍历回调 + * + * @param key key + * @param value value + */ void accept(String key, Object value); } } diff --git a/library/src/main/java/com/qiniu/android/utils/StringUtils.java b/library/src/main/java/com/qiniu/android/utils/StringUtils.java index 9b349044c..885aa06bf 100644 --- a/library/src/main/java/com/qiniu/android/utils/StringUtils.java +++ b/library/src/main/java/com/qiniu/android/utils/StringUtils.java @@ -15,9 +15,11 @@ */ public final class StringUtils { + private StringUtils() { + } + /** * 以指定的分隔符来进行字符串元素连接 - *

* 例如有字符串数组array和连接符为逗号(,) * * String[] array = new String[] { "hello", "world", "qiniu", "cloud","storage" }; @@ -26,7 +28,6 @@ public final class StringUtils { * * hello,world,qiniu,cloud,storage * - *

* * @param array 需要连接的字符串数组 * @param sep 元素连接之间的分隔符 @@ -59,7 +60,6 @@ public static String join(String[] array, String sep) { /** * 以json元素的方式连接字符串中元素 - *

* 例如有字符串数组array * * String[] array = new String[] { "hello", "world", "qiniu", "cloud","storage" }; @@ -68,7 +68,6 @@ public static String join(String[] array, String sep) { * * "hello","world","qiniu","cloud","storage" * - *

* * @param array 需要连接的字符串数组 * @return 以json元素方式连接好的新字符串 @@ -92,11 +91,22 @@ public static String jsonJoin(String[] array) { return buf.toString(); } - + /** + * json join + * + * @param array Long 数组 + * @return json string + */ public static String jsonJoin(Long[] array) { return jsonJoin(longToString(array)); } + /** + * Long 数组转 String 数组 + * + * @param longArray Long 数组 + * @return String 数组 + */ public static String[] longToString(Long longArray[]) { String stringArray[] = new String[longArray.length]; for (int i = 0; i < stringArray.length; i++) { @@ -111,6 +121,12 @@ public static String[] longToString(Long longArray[]) { } + /** + * 获取 utf8 数据 + * + * @param data 原数据 + * @return utf8 数据 + */ public static byte[] utf8Bytes(String data) { try { return data.getBytes(Constants.UTF_8); @@ -119,18 +135,42 @@ public static byte[] utf8Bytes(String data) { } } + /** + * 判断字符串是否为空 + * + * @param s 字符串 + * @return 是否为空 + */ public static boolean isNullOrEmpty(String s) { return s == null || "".equals(s); } + /** + * 转换成非空字符串 + * + * @param s 待转对象 + * @return String + */ public static String toNonnullString(Object s) { return s == null ? "" : "" + s; } + /** + * 判断字符串是否为空或者仅包含空格 + * + * @param s 字符串 + * @return 判断结果 + */ public static boolean isBlank(String s) { return s == null || s.trim().equals(""); } + /** + * strip + * + * @param s 待处理字符串 + * @return strip 后的字符串 + */ public static String strip(String s) { StringBuilder b = new StringBuilder(); for (int i = 0, length = s.length(); i < length; i++) { @@ -145,8 +185,8 @@ public static String strip(String s) { /** * 对象转数组 * - * @param obj - * @return + * @param obj obj + * @return byte array */ public static byte[] toByteArray(Object obj) { byte[] bytes = null; @@ -173,8 +213,8 @@ public static byte[] toByteArray(Object obj) { /** * 数组转对象 * - * @param bytes - * @return + * @param bytes bytes + * @return Object */ public static Object toObject(byte[] bytes) { Object obj = null; @@ -195,6 +235,12 @@ public static Object toObject(byte[] bytes) { return obj; } + /** + * 获取 Token 中的 AK + Scope + * + * @param token 上传的 Token + * @return Token 中的 AK + Scope + */ public static String getAkAndScope(String token) { String[] strings = token.split(":"); String ak = strings[0]; @@ -211,6 +257,12 @@ public static String getAkAndScope(String token) { return null; } + /** + * 获取 Token 中的 Bucket + * + * @param token 上传 Token + * @return Bucket + */ public static String getBucket(String token) { String[] strings = token.split(":"); String policy = null; @@ -226,6 +278,12 @@ public static String getBucket(String token) { return ""; } + /** + * 转大写 + * + * @param str str + * @return 转之后的字符串 + */ public static String upperCase(String str) { if (str.length() <= 0 || str == null) { return ""; diff --git a/library/src/main/java/com/qiniu/android/utils/UrlSafeBase64.java b/library/src/main/java/com/qiniu/android/utils/UrlSafeBase64.java index 8aa455abd..5b5c671e5 100644 --- a/library/src/main/java/com/qiniu/android/utils/UrlSafeBase64.java +++ b/library/src/main/java/com/qiniu/android/utils/UrlSafeBase64.java @@ -11,6 +11,9 @@ */ public final class UrlSafeBase64 { + private UrlSafeBase64() { + } + /** * 编码字符串 * @@ -46,7 +49,7 @@ public static String encodeToString(byte[] data) { public static byte[] decode(String data) { try { return Base64.decode(data, Base64.URL_SAFE | Base64.NO_WRAP); - } catch (RuntimeException e){ + } catch (RuntimeException e) { return null; } } diff --git a/library/src/main/java/com/qiniu/android/utils/UrlUtils.java b/library/src/main/java/com/qiniu/android/utils/UrlUtils.java index ecd125390..0efbf9b56 100644 --- a/library/src/main/java/com/qiniu/android/utils/UrlUtils.java +++ b/library/src/main/java/com/qiniu/android/utils/UrlUtils.java @@ -1,7 +1,19 @@ package com.qiniu.android.utils; +/** + * UrlUtils + */ public class UrlUtils { + private UrlUtils() { + } + + /** + * 移除 host 中的 scheme + * + * @param host host + * @return host + */ public static String removeHostScheme(String host) { if (host == null || StringUtils.isNullOrEmpty(host)) { return null; @@ -16,13 +28,17 @@ public static String removeHostScheme(String host) { /** * 如果 host 包含 scheme 则优先使用 host 中包含的 scheme * 如果 host 不包含 scheme 则按照 useHttps 增加 scheme + * + * @param host host + * @param useHttps 是否使用 https 请求 + * @return url */ public static String setHostScheme(String host, boolean useHttps) { if (StringUtils.isNullOrEmpty(host)) { return null; } - if (host.startsWith("http://") || host.startsWith("https://") ) { + if (host.startsWith("http://") || host.startsWith("https://")) { return host; } diff --git a/library/src/main/java/com/qiniu/android/utils/Utils.java b/library/src/main/java/com/qiniu/android/utils/Utils.java index e571a4fe4..81e41b544 100644 --- a/library/src/main/java/com/qiniu/android/utils/Utils.java +++ b/library/src/main/java/com/qiniu/android/utils/Utils.java @@ -11,9 +11,21 @@ import java.util.Date; import java.util.Locale; +/** + * utils + */ public class Utils { private static Boolean isDebug = null; + + private Utils() { + } + + /** + * 是否是 Debug + * + * @return 是否是 Debug + */ public static boolean isDebug() { if (isDebug != null) { return isDebug; @@ -33,23 +45,48 @@ public static boolean isDebug() { } } + /** + * SDK Version + * + * @return SDK Version + */ public static String sdkVerion() { return Constants.VERSION; } + /** + * SDK Language + * + * @return SDK Language + */ public static String sdkLanguage() { return "Android"; } + /** + * 获取 PID + * + * @return PID + */ public static Integer getCurrentProcessID() { return android.os.Process.myPid(); } + /** + * 获取 TID + * + * @return TID + */ public static Long getCurrentThreadID() { Thread thread = Thread.currentThread(); return thread.getId(); } + /** + * 获取系统名 + * + * @return 系统名 + */ public static String systemName() { try { String model = android.os.Build.MODEL != null ? android.os.Build.MODEL.trim() : ""; @@ -78,6 +115,11 @@ private static String deviceName(String manufacturer, String model) { return manufacturer; } + /** + * 获取系统版本 + * + * @return 系统版本 + */ public static String systemVersion() { try { String v = android.os.Build.VERSION.RELEASE; @@ -90,10 +132,21 @@ public static String systemVersion() { } } + /** + * 获取信号强度 + * + * @return 信号强度 + */ + @Deprecated public static Integer getCurrentSignalStrength() { return null; } + /** + * 获取网络类型 + * + * @return 网络类型 + */ public static String getCurrentNetworkType() { Context context = ContextGetter.applicationContext(); if (context == null) { @@ -102,19 +155,35 @@ public static String getCurrentNetworkType() { return AndroidNetwork.networkType(context); } - /// 单位:毫秒 + /** + * 获取当前时间戳 + * 单位:毫秒 + * + * @return 当前时间戳 + */ public static long currentTimestamp() { return new Date().getTime(); } - // 单位:秒 + /** + * 获取当前时间戳 + * 单位:秒 + * + * @return 当前时间戳 + */ public static long currentSecondTimestamp() { return currentTimestamp() / 1000; } - /// 两个时间的时间段 单位:毫秒 - public static long dateDuration(Date startDate, Date endDate){ - if (startDate != null && endDate != null){ + /** + * 两个时间的时间间隔 单位:毫秒 + * + * @param startDate 开始时间 + * @param endDate 结束时间 + * @return 时间间隔 + */ + public static long dateDuration(Date startDate, Date endDate) { + if (startDate != null && endDate != null) { return (endDate.getTime() - startDate.getTime()); } else { return 0l; @@ -123,17 +192,23 @@ public static long dateDuration(Date startDate, Date endDate){ /** * 计算 上传 或 下载 速度 单位:B/s - * @param bytes 单位: B - * @param totalTime 单位:ms + * + * @param bytes 单位: B + * @param totalTime 单位:ms * @return 速度 */ - public static Long calculateSpeed(Long bytes, Long totalTime){ + public static Long calculateSpeed(Long bytes, Long totalTime) { if (bytes == null || bytes < 0 || totalTime == null || totalTime == 0) { return null; } return bytes * 1000 / totalTime; } + /** + * SDK 路径 + * + * @return SDK 路径 + */ public static String sdkDirectory() { Context context = ContextGetter.applicationContext(); if (context == null) { @@ -143,6 +218,12 @@ public static String sdkDirectory() { return directory; } + /** + * Escape 字符串 + * + * @param string 字符串 + * @return Escape 后的字符串 + */ public static String formEscape(String string) { if (string == null) { return null; @@ -153,6 +234,13 @@ public static String formEscape(String string) { return ret; } + /** + * 获取 ip 类型 + * + * @param ip ip + * @param host host + * @return ip 类型 + */ @Deprecated public static String getIpType(String ip, String host) { String type = host; @@ -167,6 +255,14 @@ public static String getIpType(String ip, String host) { return type; } + /** + * 获取 ip 类型 + * + * @param httpVersion HTTP version + * @param ip ip + * @param host host + * @return ip 类型 + */ public static String getIpType(String httpVersion, String ip, String host) { if (httpVersion == null) { httpVersion = ""; @@ -184,6 +280,12 @@ public static String getIpType(String httpVersion, String ip, String host) { return httpVersion + "-" + type; } + /** + * 判断 IP 是否为 IPv6 + * + * @param ip ip + * @return 是否为 IPv6 + */ public static boolean isIpv6(String ip) { if (StringUtils.isNullOrEmpty(ip)) { return false; diff --git a/library/src/main/java/com/qiniu/android/utils/Wait.java b/library/src/main/java/com/qiniu/android/utils/Wait.java index 60c02b08b..87677cc5b 100644 --- a/library/src/main/java/com/qiniu/android/utils/Wait.java +++ b/library/src/main/java/com/qiniu/android/utils/Wait.java @@ -2,11 +2,23 @@ import java.util.concurrent.CountDownLatch; +/** + * wait + */ public class Wait { final CountDownLatch completeSingle = new CountDownLatch(1); - public void startWait(){ + /** + * 构造函数 + */ + public Wait() { + } + + /** + * 开始等待 + */ + public void startWait() { while (completeSingle.getCount() > 0) { try { completeSingle.await(); @@ -16,7 +28,10 @@ public void startWait(){ } } - public void stopWait(){ + /** + * 停止等待 + */ + public void stopWait() { completeSingle.countDown(); }