Skip to content

Release 6.1.3 #109

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 41 commits into from
Apr 28, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
597d2cd
设置httpclient超时参数
sxci Feb 12, 2014
abf1eb6
测试后Config配置恢复原值
sxci Feb 12, 2014
c30ad84
测试后设置Http静态值client为null
sxci Feb 12, 2014
96017bb
测试套件不测试 HttpClientTimeOutTest,即其相关改动不对其它测试产生影响
sxci Feb 12, 2014
05deb3e
修改格式
sxci Feb 12, 2014
d1d2120
修改格式,调整测试时间
sxci Feb 12, 2014
724050c
去掉多余的打印
sxci Feb 19, 2014
999098b
用户自定义参数
sxci Feb 19, 2014
4b57e2f
add xvar
Feb 19, 2014
084bac4
去掉引入的junit4
sxci Feb 20, 2014
370b15a
去掉项目对junit4的classpath配置,maven中有对junit3的依赖
sxci Feb 20, 2014
145edad
Merge pull request #101 from longshanksmo/bug/xvar
longshanksmo Feb 20, 2014
7fc94be
Update README.md
longbai Apr 3, 2014
55f98a2
修改超时测试网址为http://www.qiniu.com
sxci Apr 3, 2014
0f18b52
去掉javase1.6标记
sxci Apr 3, 2014
61da8ad
Merge pull request #102 from simon-liubin/feature/custom_field_name
longbai Apr 3, 2014
1c99b9f
分片上传,断点续传
sxci Apr 11, 2014
118febd
版本信息及地址qobx.me --> qiniu.com
sxci Apr 11, 2014
820e61b
config添加CHARSET,EncodeUtils内修改
sxci Apr 14, 2014
6da50d1
PutPolicy 内修改
sxci Apr 14, 2014
cdea5da
IoApi 内修改
sxci Apr 14, 2014
5d56ba7
修复:普通流上传,key为空对象导致错误
sxci Apr 15, 2014
1100f05
== 改为 !=
sxci Apr 15, 2014
7d8857f
删除测试上传的文件
sxci Apr 15, 2014
8940680
key 1.随机,2.删除
sxci Apr 15, 2014
2e6b402
Merge pull request #100 from simon-liubin/feature/http_client_timeout
longbai Apr 16, 2014
3b9f911
Merge pull request #106 from simon-liubin/bug_fix/up_is_nullkey
longbai Apr 21, 2014
8406286
Revert " 版本信息及地址qobx.me --> qiniu.com"
sxci Apr 21, 2014
87b2a88
Merge branch 'develop' of github.com:qiniu/java-sdk into update/chars…
sxci Apr 21, 2014
d469c56
add mimetype limit
sxci Apr 21, 2014
bba8fb0
Merge pull request #108 from simon-liubin/bug-fix/mimetype-limit
longbai Apr 21, 2014
360a1c4
Merge pull request #107 from simon-liubin/update/charset_utf8
longbai Apr 21, 2014
05e4153
reslove conflict
sxci Apr 22, 2014
665bae7
remove Authorization
sxci Apr 22, 2014
337ae03
check exception
sxci Apr 22, 2014
82e16f3
删除断点记录
sxci Apr 23, 2014
338120b
忽略删除是否成功
sxci Apr 23, 2014
9f9ebe9
fileoptest
sxci Apr 23, 2014
1d2f5a0
调整
sxci Apr 24, 2014
46d90f7
Merge pull request #103 from simon-liubin/feature/resume
longbai Apr 26, 2014
c961af0
update change log
longbai Apr 28, 2014
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
3 changes: 1 addition & 2 deletions .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6">
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
Expand Down
3 changes: 0 additions & 3 deletions .settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.6
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
## CHANGE LOG

### v6.1.3

2014-04-28 [#109](https://github.com/qiniu/java-sdk/pull/109)

- [#101] [#102] 用户自定义参数
- [#103] 分片上传,断点续传
- [#106] bugfix: 普通流上传,key为空对象导致错误
- [#107] bugfix: 指明为utf8字符集
- [#108] 限定上传文件类型

### v6.1.2

2014-2-10 [#98](https://github.com/qiniu/java-sdk/pull/98)
Expand All @@ -13,7 +23,7 @@
- bugfix: PutExtra.mimeType 不生效问题
- PutPolicy 补充字段

### v6.0.7
### v6.0.7

2013-11-7 [#85](https://github.com/qiniu/java-sdk/pull/85)

Expand Down
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: Java SDK
title: Java SDK | 七牛云存储
---

# Java SDK 使用指南
Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/qiniu/api/auth/digest/Mac.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public Mac(String accessKey, String secretKey) {
* @throws AuthException
*/
public String sign(byte[] data) throws AuthException {
System.out.println("data : " + new String(data));
javax.crypto.Mac mac = null;
try {
mac = javax.crypto.Mac.getInstance("HmacSHA1");
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/com/qiniu/api/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* side only.
*/
public class Config {
public static final String CHARSET = "utf-8";

public static String USER_AGENT="qiniu java-sdk v6.0.0";

Expand All @@ -25,5 +26,24 @@ public class Config {
public static String UP_HOST = "http://up.qbox.me";

public static String RSF_HOST = "http://rsf.qbox.me";

/**
* HTTP连接超时的时间毫秒(ms)
* Determines the timeout in milliseconds until a connection is established.
* A timeout value of zero is interpreted as an infinite timeout.
*
* Please note this parameter can only be applied to connections that
* are bound to a particular local address.
*/
public static int CONNECTION_TIMEOUT = 30 * 1000;
/**
* 读取response超时的时间毫秒(ms)
* Defines the socket timeout (<code>SO_TIMEOUT</code>) in milliseconds,
* which is the timeout for waiting for data or, put differently,
* a maximum period inactivity between two consecutive data packets).
* A timeout value of zero is interpreted as an infinite timeout.
* @see java.net.SocketOptions#SO_TIMEOUT
*/
public static int SO_TIMEOUT = 30 * 1000;

}
43 changes: 34 additions & 9 deletions src/main/java/com/qiniu/api/io/IoApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.util.Map;
import java.util.zip.CRC32;
import java.util.zip.CheckedInputStream;

Expand Down Expand Up @@ -38,12 +39,19 @@ private static PutRet put(String uptoken, String key, File file,
AbstractContentBody fileBody = buildFileBody(file, extra);
requestEntity.addPart("file", fileBody);
setKey(requestEntity, key);
setParam(requestEntity, extra.params);
if (extra.checkCrc != NO_CRC32) {
if (extra.crc32 == 0) {
return new PutRet(new CallRet(400, new Exception("no crc32 specified!")));
}
requestEntity.addPart("crc32", new StringBody(extra.crc32 + ""));
}
}

if (extra.params != null) {
for (Map.Entry<String, String> xvar : extra.params.entrySet()) {
requestEntity.addPart(xvar.getKey(), new StringBody(xvar.getValue(), Charset.forName(Config.CHARSET)));
}
}
} catch (Exception e) {
e.printStackTrace();
return new PutRet(new CallRet(400, e));
Expand All @@ -64,17 +72,27 @@ private static FileBody buildFileBody(File file,PutExtra extra){

private static void setKey(MultipartEntity requestEntity, String key) throws UnsupportedEncodingException{
if(key != null){
requestEntity.addPart("key", new StringBody(key,Charset.forName("utf-8")));
requestEntity.addPart("key", new StringBody(key,Charset.forName(Config.CHARSET)));
}
}

private static void setParam(MultipartEntity requestEntity, Map<String, String> params) throws UnsupportedEncodingException{
if(params == null){
return;
}
for(String name : params.keySet()){
requestEntity.addPart(name, new StringBody(params.get(name),Charset.forName(Config.CHARSET)));
}
}

private static PutRet putStream(String uptoken, String key, InputStream reader,PutExtra extra) {
private static PutRet putStream(String uptoken, String key, InputStream reader,PutExtra extra, String fileName) {
MultipartEntity requestEntity = new MultipartEntity();
try {
requestEntity.addPart("token", new StringBody(uptoken));
AbstractContentBody inputBody = buildInputStreamBody(reader, extra, key);
AbstractContentBody inputBody = buildInputStreamBody(reader, extra, fileName != null ? fileName : "null");
requestEntity.addPart("file", inputBody);
setKey(requestEntity, key);
setParam(requestEntity, extra.params);
if (extra.checkCrc != NO_CRC32) {
if (extra.crc32 == 0) {
return new PutRet(new CallRet(400, new Exception("no crc32 specified!")));
Expand All @@ -91,19 +109,26 @@ private static PutRet putStream(String uptoken, String key, InputStream reader,P
return new PutRet(ret);
}

private static InputStreamBody buildInputStreamBody(InputStream reader,PutExtra extra, String key){
private static InputStreamBody buildInputStreamBody(InputStream reader,PutExtra extra, String fileName){
if(extra.mimeType != null){
return new InputStreamBody(reader, extra.mimeType, key);
return new InputStreamBody(reader, extra.mimeType, fileName);
}else{
return new InputStreamBody(reader, key);
return new InputStreamBody(reader, fileName);
}
}

public static PutRet put(String uptoken,String key,InputStream reader,PutExtra extra){
return putStream(uptoken,key,reader,extra, null);
}

public static PutRet put(String uptoken,String key,InputStream reader,PutExtra extra, String fileName){
return putStream(uptoken,key,reader,extra, fileName);
}


public static PutRet Put(String uptoken,String key,InputStream reader,PutExtra extra)
{
PutRet ret = putStream(uptoken,key,reader,extra);
return ret;
return put(uptoken,key,reader,extra);
}


Expand Down
27 changes: 23 additions & 4 deletions src/main/java/com/qiniu/api/net/EncodeUtils.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.qiniu.api.net;

import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
Expand All @@ -10,6 +11,8 @@
import org.apache.http.client.utils.URLEncodedUtils;
import org.apache.http.message.BasicNameValuePair;

import com.qiniu.api.config.Config;

/**
* URLEncoding is the alternate base64 encoding defined in RFC 4648. It is
* typically used in URLs and file names.
Expand Down Expand Up @@ -38,7 +41,7 @@ public static byte[] urlsafeEncodeBytes(byte[] src) {
}

public static byte[] urlsafeBase64Decode(String encoded){
byte[] rawbs = encoded.getBytes();
byte[] rawbs = toByte(encoded);
for(int i=0;i<rawbs.length;i++){
if(rawbs[i] == '_'){
rawbs[i] = '/';
Expand All @@ -50,11 +53,11 @@ public static byte[] urlsafeBase64Decode(String encoded){
}

public static String urlsafeEncodeString(byte[] src) {
return new String(urlsafeEncodeBytes(src));
return toString(urlsafeEncodeBytes(src));
}

public static String urlsafeEncode(String text) {
return new String(urlsafeEncodeBytes(text.getBytes()));
return toString(urlsafeEncodeBytes(toByte(text)));
}

// replace '/' with '_', '+" with '-'
Expand Down Expand Up @@ -84,8 +87,24 @@ public static String encodeParams(Object params) {
list.add(new BasicNameValuePair(entry.getKey(), entry
.getValue()));
}
return URLEncodedUtils.format(list, "UTF-8");
return URLEncodedUtils.format(list, Config.CHARSET);
}
return null;
}

public static byte[] toByte(String s){
try {
return s.getBytes(Config.CHARSET);
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
}

public static String toString(byte[] bs){
try {
return new String(bs, Config.CHARSET);
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
}
}
9 changes: 8 additions & 1 deletion src/main/java/com/qiniu/api/net/Http.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.conn.PoolingClientConnectionManager;
import org.apache.http.params.CoreConnectionPNames;

import com.qiniu.api.config.Config;

/**
* The class Http provides a default HttpConnectionPool implementation. Anyway,
Expand Down Expand Up @@ -54,6 +57,10 @@ private static HttpClient makeDefaultClient() {
HttpHost localhost = new HttpHost("locahost", 80);
cm.setMaxPerRoute(new HttpRoute(localhost), 50);

return new DefaultHttpClient(cm);
HttpClient client = new DefaultHttpClient(cm);
client.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, Config.CONNECTION_TIMEOUT);
client.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, Config.SO_TIMEOUT);

return client;
}
}
74 changes: 74 additions & 0 deletions src/main/java/com/qiniu/api/resumableio/ChunkUploadCallRet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package com.qiniu.api.resumableio;

import org.json.JSONException;
import org.json.JSONObject;

import com.qiniu.api.net.CallRet;

public class ChunkUploadCallRet extends CallRet {
protected String ctx;
protected String checksum;
protected int offset;
protected String host;
protected long crc32;

public ChunkUploadCallRet(CallRet ret) {
super(ret);
doUnmarshal();
}

public ChunkUploadCallRet(int statusCode, String response) {
super(statusCode, response);
doUnmarshal();
}

public ChunkUploadCallRet(int statusCode, Exception e) {
super(statusCode, e);
}

private void doUnmarshal() {
if (this.exception != null || this.response == null
|| !this.response.trim().startsWith("{")) {
return;
}
try {
unmarshal();
} catch (Exception e) {
e.printStackTrace();
if (this.exception == null) {
this.exception = e;
}
}

}

protected void unmarshal() throws JSONException{
JSONObject jsonObject = new JSONObject(this.response);
ctx = jsonObject.optString("ctx", null);
checksum = jsonObject.optString("checksum", null);
offset = jsonObject.optInt("offset", 0);
host = jsonObject.optString("host", null);
crc32 = jsonObject.optLong("crc32", 0);
}

public String getCtx() {
return ctx;
}

public String getChecksum() {
return checksum;
}

public long getOffset() {
return offset;
}

public String getHost() {
return host;
}

public long getCrc32() {
return crc32;
}

}
Loading