Skip to content

update doc #133

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 1 commit into from
Jul 14, 2014
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

[![Qiniu Logo](http://qiniutek.com/images/logo-2.png)](http://qiniu.com/)

此 Java SDK 适用于 Java 6 及以上版本,基于 [七牛云存储官方API](http://docs.qiniutek.com/v2/api/) 构建。使用此 SDK 构建您的网络应用程序,能让您以非常便捷地方式将数据安全地存储到七牛云存储上。无论您的网络应用是一个网站程序,还是包括从云端(服务端程序)到终端(手持设备应用)的架构的服务或应用,通过七牛云存储及其 SDK,都能让您应用程序的终端用户高速上传和下载,同时也让您的服务端更加轻盈。
此 Java SDK 适用于 Java 6 及以上版本,基于 [七牛云存储官方API](http://developer.qiniu.com/docs/v6/sdk/java-sdk.html) 构建。使用此 SDK 构建您的网络应用程序,能让您以非常便捷地方式将数据安全地存储到七牛云存储上。无论您的网络应用是一个网站程序,还是包括从云端(服务端程序)到终端(手持设备应用)的架构的服务或应用,通过七牛云存储及其 SDK,都能让您应用程序的终端用户高速上传和下载,同时也让您的服务端更加轻盈。


## 安装
Expand Down Expand Up @@ -38,7 +38,7 @@

## 许可证

Copyright (c) 2012 qiniutek.com
Copyright (c) 2012-2014 qiniu.com

基于 MIT 协议发布:

Expand Down
12 changes: 6 additions & 6 deletions src/test/java/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Qiniu Resource (Cloud) Storage SDK demo for Java
# Qiniu Resource (Cloud) Storage SDK demo for Java

# 关于
这些demo都是基于 Qiniu Resource (Cloud) Storage SDK for Java 开发的。其中RSDemo.java演示了服务端进行资源上传,下载,删除,发布,取消发布等功能的演示。
其中Notifier.java 和 UpDemo.java 演示了客户端进行断点续上传。
其中Notifier.java 和 UpDemo.java 演示了客户端进行断点续上传。
在ResumableNotifier.java和ResumablePutDemo.java中对客户端在断点续上传过程中的状态进行了序列化,使客户在上传过程中即使程序崩溃或者退出在下次重新启动时还可以接着上次继续上次。
ResumableGUINotifier.java 和 ResumableGUIputDemo.java 则添加了客户在断点续上传时的UI,使上传更加直观。

Expand All @@ -13,15 +13,15 @@

## 使用
要接入七牛云存储,您需要拥有一对有效的 Access Key 和 Secret Key 用来进行签名认证。可以通过如下步骤获得:
[开通七牛开发者账号](https://dev.qiniutek.com/signup)
[登录七牛开发者自助平台,查看Access Key 和 Secret Key](https://dev.qiniutek.com/account/keys)
[开通七牛开发者账号](https://portal.qiniu.com/signup)
[登录七牛开发者自助平台,查看Access Key 和 Secret Key](https://portal.qiniu.com/setting/key)
然后把得到的Access Key 和 Secret Key 写入每个demo中后。
1.RSDemo可以直接运行。
2.ResumablePutDemo 和 ResumableGUIPutDemo 则需要传入 要上传文件的具体路径加文件名 作为参数。
在eclipse中您可以这样添加:选中您要运行的demo-->右键-->选中 Build Path-->Run/Debug Settings-->双击你要运行的demo-->选中 ‘(x)=Arguments’ 选项卡-->在Program arguments中加入要传入的参数。
在命令窗口下:”java 您要运行的demo 参数” 把参数改成你的实际参数。
(你也可以在demo中把 String inputFile = args[0];中的args[0]换成你的参数)
参考文档:[七牛云存储 Java SDK 使用指南](http://docs.qiniutek.com/v2/sdk/java/)
参考文档:[七牛云存储 Java SDK 使用指南](http://developer.qiniu.com/docs/v6/sdk/java-sdk.html)

## 贡献代码

Expand All @@ -33,7 +33,7 @@

## 许可证

Copyright (c) 2012 qiniutek.com
Copyright (c) 2012-2014 qiniu.com

基于 MIT 协议发布:

Expand Down
30 changes: 15 additions & 15 deletions src/test/java/com/qiniu/testing/IOTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,53 +106,53 @@ private String getJsonValue(JSONObject jsonObject, String name){
return null;
}
}

public void testNoLengthStream() throws Exception {
PutPolicy p = new PutPolicy(bucketName);
p.returnBody = "{\"key\": $(key), \"hash\": $(etag),\"mimeType\": $(mimeType)}";
String upToken = p.token(mac);
HttpEntity en = getHttpEntity("http://qiniuphotos.qiniudn.com/gogopher.jpg");

HttpEntity en = getHttpEntity("http://testres.qiniudn.com/gogopher.jpg");

class MyInputStream extends InputStream{
InputStream in;
MyInputStream(InputStream is){
this.in = is;
}

@Override
public int read() throws IOException {
// TODO Auto-generated method stub
return in.read();
}

public int available() throws IOException {
throw new IOException();
}

public void close() throws IOException {
in.close();
}

}





PutRet ret = IoApi.Put(upToken, key, new MyInputStream(en.getContent()), null);

assertTrue(ret.ok());
}

public void testSetLengthStream() throws Exception {
PutPolicy p = new PutPolicy(bucketName);
p.returnBody = "{\"key\": $(key), \"hash\": $(etag),\"mimeType\": $(mimeType)}";
String upToken = p.token(mac);
HttpEntity en = getHttpEntity("http://qiniuphotos.qiniudn.com/gogopher.jpg");

HttpEntity en = getHttpEntity("http://testres.qiniudn.com/gogopher.jpg");
PutExtra extra = new PutExtra();
extra.mimeType = en.getContentType().getValue();
PutRet ret = IoApi.Put(upToken, key, en.getContent(), extra, en.getContentLength());

assertTrue(ret.ok());
}

Expand Down
18 changes: 6 additions & 12 deletions src/test/java/com/qiniu/testing/RSFTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class RSFTest extends TestCase {
public final String expectedHash = "FmDZwqadA4-ib_15hYfQpb7UXUYR";

public String bucketName;

public Mac mac;
@Override
public void setUp() {
Expand All @@ -41,7 +41,6 @@ public void setUp() {
mac = new Mac(Config.ACCESS_KEY, Config.SECRET_KEY);
}

// just upload an image in testdata.
public void testRSF() throws Exception {
{
String uptoken = new PutPolicy(bucketName).token(mac);
Expand All @@ -56,14 +55,14 @@ public void testRSF() throws Exception {
assertTrue(ret.ok());
assertTrue(expectedHash.equals(ret.getHash()));
}

}
// we don't checkout the result of how may items are in the buckets.
// not very convient, it's better, although.
{
RSFClient client = new RSFClient(mac);
String marker = "";

List<ListItem> all = new ArrayList<ListItem>();
ListPrefixRet ret = null;
while (true) {
Expand All @@ -77,14 +76,9 @@ public void testRSF() throws Exception {
}
if (ret.exception.getClass() != RSFEofException.class) {
// error handler
}
}

assertTrue(all.size() >= 3);
}
}

@Override
public void tearDown() {
// do nothing here.
}
}
}
8 changes: 4 additions & 4 deletions src/test/java/com/qiniu/testing/ResumeableioTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,15 @@ private void uploadStream() throws AuthException, JSONException, FileNotFoundExc
assertEquals(mimeType, mt);
}
}

public void testStream() throws Exception {
PutPolicy p = new PutPolicy(bucketName);
p.returnBody = "{\"key\": $(key), \"hash\": $(etag),\"mimeType\": $(mimeType)}";
String upToken = p.token(mac);
HttpEntity en = getHttpEntity("http://qiniuphotos.qiniudn.com/gogopher.jpg");

HttpEntity en = getHttpEntity("http://testres.qiniudn.com/gogopher.jpg");
PutRet ret = ResumeableIoApi.put(en.getContent(), upToken, currentKey, en.getContentType().getValue(), en.getContentLength());

assertTrue(ret.ok());
}

Expand Down
7 changes: 0 additions & 7 deletions src/test/java/com/qiniu/testing/UtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,11 @@
import com.qiniu.api.net.EncodeUtils;

public class UtilTest extends TestCase {

// just upload an image in testdata.
public void test() throws Exception {
String expectString = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ~!@#$%^&*()_+}{:?><-=,./;'[]";
String encodedString = "MTIzNDU2Nzg5MGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6QUJDREVGR0hJSktMTU5PUFFSU1RVVldYWVp-IUAjJCVeJiooKV8rfXs6Pz48LT0sLi87J1td";
byte[] rawBytes = EncodeUtils.urlsafeBase64Decode(encodedString);
String decoded = new String(rawBytes);
assertTrue(expectString.equals(decoded));
}

@Override
public void tearDown() {
// do nothing here.
}
}