Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ android:
- tools

# The BuildTools version used by your project
- build-tools-21.0.1
- build-tools-21.1.2

# The SDK version used to compile your project
- android-21
Expand All @@ -28,5 +28,5 @@ before_script:
- adb shell input keyevent 82 &

script:
- ./gradlew build
- ./gradlew connectedAndroidTest --info
# - ./gradlew build
- ./gradlew connectedAndroidTest --info
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
#Changelog

## 7.0.2 (2015-01-22)

### 增加
* 记录请求花费时间
* 纪录节点日志,节点对应的IP
* 添加详细注释
* 支持代理
* 重构,增加了默认参数
* 升级构建脚本

### 修正
* mimeType设置不正确的问题
* 当参数出现空字符串时,上传失败
* 出现5xx失败时,应回源站上传

## 7.0.1 (2014-10-29)

### 增加
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
将realease 目录中的jar 复制到项目中去,此版本sdk依赖 http://loopj.com/android-async-http/ 1.4.6及以上版本

### 通过maven
* 如果在Adroid Studio中使用,添加dependencies `compile 'com.qiniu:qiniu-android-sdk:7.0.1'` 或在项目中添加maven依赖
* 如果在Adroid Studio中使用,添加dependencies `compile 'com.qiniu:qiniu-android-sdk:7.0.2'` 或在项目中添加maven依赖
* 如果是eclipse, 也可以直接添加依赖来处理。

## 使用方法
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
classpath 'com.android.tools.build:gradle:1.0.1'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
7 changes: 4 additions & 3 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ int code = versionNameToCode(version)

android {
compileSdkVersion 21
buildToolsVersion '21.1.1'
buildToolsVersion '21.1.2'
defaultConfig {
//applicationId "com.qiniu.android"
minSdkVersion 8
Expand All @@ -32,8 +32,9 @@ android {
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.loopj.android:android-async-http:1.4.6'
// compile 'com.android.support:appcompat-v7:21.0.3'
compile fileTree(include: ['*.jar'], dir: 'libs')
}

task releaseJar(type: Copy, dependsOn: 'build') {
Expand All @@ -46,4 +47,4 @@ task releaseJar(type: Copy, dependsOn: 'build') {
setProperty('VERSION_NAME', version)
setProperty('VERSION_CODE', code)

//apply from: 'https://raw.github.com/chrisbanes/gradle-mvn-push/master/gradle-mvn-push.gradle'
apply from: '../mvn_push.gradle'
1 change: 1 addition & 0 deletions library/library.iml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
<excludeFolder url="file://$MODULE_DIR$/build/libs" />
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
</content>
Expand Down
2 changes: 1 addition & 1 deletion library/src/main/java/com/qiniu/android/common/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Created by bailong on 14/10/8.
*/
public final class Config {
public static final String VERSION = "7.0.1";
public static final String VERSION = "7.0.2";

/**
* 默认上传服务器
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
public interface CompletionHandler {
/**
* 用户自定义的处理对象必须实现的接口方法
* @param info 响应的调试信息
* @param response 响应的数据
*/
void complete(ResponseInfo info, JSONObject response);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
public interface ProgressHandler {
/**
* 用户自定义进度处理对象必须实现的接口方法
* @param bytesWritten 已经写入字节
* @param totalSize 总字节数
*/
void onProgress(int bytesWritten, int totalSize);
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ private static ResponseInfo buildResponseInfo(int statusCode, Header[] headers,
xvia = h.getValue();
} else if ("X-Px".equals(h.getName())){
xvia = h.getValue();
} else if ("Fw-Via".equals(h.getName())){
xvia = h.getValue();
}
}
}
Expand Down Expand Up @@ -153,7 +155,7 @@ public void onStart() {

/**
* hack the method for dns in background before receive msg in main looper
* @param msg
* @param msg 发送的状态信息
*/
@Override
protected void sendMessage(Message msg) {
Expand Down
5 changes: 5 additions & 0 deletions library/src/main/java/com/qiniu/android/storage/Recorder.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,21 @@ public interface Recorder {

/**
* 新建或更新文件分片上传的进度
* @param key 持久化的键
* @param data 持久化的内容
*/
void set(String key, byte[] data);

/**
* 获取文件分片上传的进度信息
* @param key 持久化的键
* @return 对应的信息
*/
byte[] get(String key);

/**
* 删除文件分片上传的进度文件
* @param key 持久化的键
*/
void del(String key);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

/**
* 七牛文件上传管理器
* <p/>
*
* 一般默认可以使用这个类的方法来上传数据和文件。这个类自动检测文件的大小,
* 只要超过了{@link com.qiniu.android.common.Config#PUT_THRESHOLD}
*/
Expand All @@ -29,7 +29,7 @@ public UploadManager(Recorder recorder, KeyGenerator keyGen) {

/**
*
* @param recorder 本地持久化断点上传纪录的类
* @param recorder 本地持久化断点上传纪录的类
* @param keyGen 本地持久化断点上传纪录时需要的key生成器
* @param proxy http 代理
*/
Expand Down
7 changes: 5 additions & 2 deletions library/src/main/java/com/qiniu/android/utils/Crc32.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public final class Crc32 {
* @param data 二进制数据
* @param offset 起始字节索引
* @param length 校验字节长度
* @return 校验码
*/
public static long bytes(byte[] data, int offset, int length) {
CRC32 crc32 = new CRC32();
Expand All @@ -27,16 +28,18 @@ public static long bytes(byte[] data, int offset, int length) {
* 计算二进制字节校验码
*
* @param data 二进制数据
* @return 校验码
*/
public static long bytes(byte[] data) {
return bytes(data, 0, data.length);
}


/**
* 对文件内容计算crc32校验码
*
* @param file 需要计算crc32校验码的文件
* @param f 需要计算crc32校验码的文件
* @return crc校验码
* @throws IOException 读取文件异常
*/
public static long file(File f) throws IOException {
FileInputStream fi = new FileInputStream(f);
Expand Down
11 changes: 11 additions & 0 deletions library/src/main/java/com/qiniu/android/utils/Dns.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
* Dns解析类
*/
public final class Dns {

/**
* 根据域名解析出来 IP数组
* @param hostName 域名
* @return IP 数组
*/
public static String[] getAddresses(String hostName){
InetAddress[] ret = null;
try {
Expand All @@ -22,6 +28,11 @@ public static String[] getAddresses(String hostName){
return r;
}

/**
* 根据域名解析出来IP列表,并合并为一个字符串,通过';'分隔
* @param hostName 域名
* @return IP列表
*/
public static String getAddressesString(String hostName){
return StringUtils.join(getAddresses(hostName), ";");
}
Expand Down
17 changes: 17 additions & 0 deletions library/src/main/java/com/qiniu/android/utils/Etag.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public static String data(byte[] data) {
*
* @param file 文件对象
* @return 文件内容的etag
* @throws IOException 文件读取异常
*/
public static String file(File file) throws IOException {
FileInputStream fi = new FileInputStream(file);
Expand All @@ -60,6 +61,7 @@ public static String file(File file) throws IOException {
*
* @param filePath 文件路径
* @return 文件内容的etag
* @throws IOException 文件读取异常
*/
public static String file(String filePath) throws IOException {
File f = new File(filePath);
Expand All @@ -72,6 +74,7 @@ public static String file(String filePath) throws IOException {
* @param in 数据输入流
* @param len 数据流长度
* @return 数据流的etag值
* @throws IOException 文件读取异常
*/
public static String stream(InputStream in, long len) throws IOException {
if (len == 0) {
Expand All @@ -87,6 +90,14 @@ public static String stream(InputStream in, long len) throws IOException {
return resultEncode(blocks);
}

/**
* 单块计算hash
* @param buffer 数据缓冲区
* @param in 输入数据
* @param len 输入数据长度
* @return 计算结果
* @throws IOException 读取出错
*/
private static byte[] oneBlock(byte[] buffer, InputStream in, int len) throws IOException {
MessageDigest sha1 = null;
try {
Expand All @@ -108,6 +119,12 @@ private static byte[] oneBlock(byte[] buffer, InputStream in, int len) throws IO
return sha1.digest();
}

/**
* 合并结果
* @param sha1s 每块计算结果的列表
* @return 最终的结果
*/

private static String resultEncode(byte[][] sha1s) {
byte head = 0x16;
byte[] finalHash = sha1s[0];
Expand Down
11 changes: 10 additions & 1 deletion library/src/main/java/com/qiniu/android/utils/UrlSafeBase64.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
public final class UrlSafeBase64 {

/**
* 编码数据
* 编码字符串
* @param data 待编码字符串
* @return 结果字符串
*/
public static String encodeToString(String data) {
try {
Expand All @@ -24,12 +26,19 @@ public static String encodeToString(String data) {
return null;
}

/**
* 编码数据
* @param data 字节数组
* @return 结果字符串
*/
public static String encodeToString(byte[] data) {
return Base64.encodeToString(data, Base64.URL_SAFE | Base64.NO_WRAP);
}

/**
* 解码数据
* @param data 编码过的字符串
* @return 原始数据
*/
public static byte[] decode(String data) {
return Base64.decode(data, Base64.URL_SAFE | Base64.NO_WRAP);
Expand Down
Loading