Skip to content

Code Generator #610

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 27 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from 23 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
118 changes: 108 additions & 10 deletions CHANGELOG.md

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
# Qiniu Resource Storage SDK for Java

[![@qiniu on weibo](http://img.shields.io/badge/weibo-%40qiniutek-blue.svg)](http://weibo.com/qiniutek)
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg)](LICENSE)
[![Build Status](https://travis-ci.org/qiniu/java-sdk.svg)](https://travis-ci.org/qiniu/java-sdk)
[![GitHub release](https://img.shields.io/github/v/tag/qiniu/java-sdk.svg?label=release)](https://github.com/qiniu/java-sdk/releases)
[![Docs](https://img.shields.io/github/v/tag/qiniu/java-sdk.svg?label=docs&color=yellow)](https://qiniu.github.io/java-sdk/)
[![Coverage Status](https://codecov.io/gh/qiniu/java-sdk/branch/master/graph/badge.svg)](https://codecov.io/gh/qiniu/java-sdk)
[![Latest Stable Version](https://img.shields.io/maven-central/v/com.qiniu/qiniu-java-sdk.svg)](http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22com.qiniu%22%20AND%20a%3A%22qiniu-java-sdk%22)

## 安装

下载 [the latest JAR][1] 或者 通过 Maven:

```xml
<dependency>
<groupId>com.qiniu</groupId>
<artifactId>qiniu-java-sdk</artifactId>
<version>[7.16.0, 7.16.99]</version>
</dependency>
```

或者 Gradle:

```groovy
implementation 'com.qiniu:qiniu-java-sdk:7.16.+'
```
Expand All @@ -28,6 +33,7 @@ JDK 7 及以上
## 使用方法

### 上传

```Java
// 分片上传 v1
import com.qiniu.storage.UploadManager;
Expand Down Expand Up @@ -73,6 +79,7 @@ $ ./gradlew build
```

## 生成Eclipse工程文件

``` bash
$ ./gradlew gen_eclipse
```
Expand Down Expand Up @@ -105,6 +112,9 @@ $ ./gradlew gen_eclipse
The MIT License (MIT).详情见 [License文件](https://github.com/qiniu/java-sdk/blob/master/LICENSE).

[1]: https://search.maven.org/remote_content?g=com.qiniu&a=qiniu-java-sdk&v=LATEST

[2]: https://github.com/Nextpeer/okhttp

[3]: https://raw.githubusercontent.com/qiniu/java-sdk/master/libs/okhttp-2.3.0-SNAPSHOT.jar

[4]: https://raw.githubusercontent.com/qiniu/java-sdk/master/libs/okio-1.3.0-SNAPSHOT.jar
16 changes: 8 additions & 8 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ task getHomeDir {
apply plugin: 'checkstyle'

task apiJavadocs(type: Javadoc) {
source = sourceSets.main.allJava
classpath = sourceSets.main.runtimeClasspath
title = "七牛 Java SDK API 文档"
options {
memberLevel = JavadocMemberLevel.PUBLIC
setEncoding 'UTF-8'
setWindowTitle "七牛 Java SDK API 文档"
}
source = sourceSets.main.allJava
classpath = sourceSets.main.runtimeClasspath
title = "七牛 Java SDK API 文档"
options {
memberLevel = JavadocMemberLevel.PUBLIC
setEncoding 'UTF-8'
setWindowTitle "七牛 Java SDK API 文档"
}
}

def versionName() {
Expand Down
8 changes: 4 additions & 4 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ codecov:
- prow.qiniu.io # prow 里面运行需添加,其他 CI 不要
require_ci_to_pass: no # 改为 no,否则 codecov 会等待其他 GitHub 上所有 CI 通过才会留言。

github_checks: #关闭github checks
github_checks: #关闭github checks
annotations: false

comment:
Expand All @@ -12,13 +12,13 @@ comment:
require_changes: false # if true: only post the comment if coverage changes
require_base: no # [yes :: must have a base report to post]
require_head: yes # [yes :: must have a head report to post]
branches: # branch names that can post comment
branches: # branch names that can post comment
- "master"

coverage:
status: # 评判 pr 通过的标准
status: # 评判 pr 通过的标准
patch: off
project: # project 统计所有代码x
project: # project 统计所有代码x
default:
# basic
target: 60% # 总体通过标准
Expand Down
4 changes: 2 additions & 2 deletions config/checkstyle/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@


<module name="TreeWalker">
<module name="SuppressionCommentFilter" />
<module name="SuppressionCommentFilter"/>
<!-- Checks for Javadoc comments. -->
<!-- See http://checkstyle.sf.net/config_javadoc.html -->
<!--module name="JavadocMethod"/-->
<!--module name="JavadocType"/-->
<!--module name="JavadocVariable"/-->
<module name="JavadocStyle">
<property name="checkFirstSentence" value="false" />
<property name="checkFirstSentence" value="false"/>
</module>


Expand Down
40 changes: 20 additions & 20 deletions examples/CdnRefreshDirsDemo.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,26 @@

//https://developer.qiniu.com/kodo/sdk/java#fusion-refresh-urls

public class CdnRefreshDirsDemo {

Check warning on line 10 in examples/CdnRefreshDirsDemo.java

View check run for this annotation

qiniu-x / stylecheck

examples/CdnRefreshDirsDemo.java#L10

Utility classes should not have a public or default constructor. [HideUtilityClassConstructor]
public static void main(String args[]) {
String accessKey = "your access key";
String secretKey = "your secret key";
Auth auth = Auth.create(accessKey, secretKey);
CdnManager c = new CdnManager(auth);
//待刷新的目录列表,目录必须以 / 结尾
String[] dirs = new String[]{
"http://javasdk.qiniudn.com/gopher1/",
"http://javasdk.qiniudn.com/gopher2/",
//....
};
try {
//单次方法调用刷新的目录不可以超过10个,另外刷新目录权限需要联系技术支持开通
CdnResult.RefreshResult result = c.refreshDirs(dirs);
System.out.println(result.code);
//获取其他的回复内容
} catch (QiniuException e) {
System.err.println(e.response.toString());
}
}
public static void main(String args[]) {

Check warning on line 11 in examples/CdnRefreshDirsDemo.java

View check run for this annotation

qiniu-x / stylecheck

examples/CdnRefreshDirsDemo.java#L11

Missing a Javadoc comment. [MissingJavadocMethod]

Check warning on line 11 in examples/CdnRefreshDirsDemo.java

View check run for this annotation

qiniu-x / stylecheck

examples/CdnRefreshDirsDemo.java#L11

Parameter args should be final. [FinalParameters]

Check warning on line 11 in examples/CdnRefreshDirsDemo.java

View check run for this annotation

qiniu-x / stylecheck

examples/CdnRefreshDirsDemo.java#L11

Array brackets at illegal position. [ArrayTypeStyle]
String accessKey = "your access key";
String secretKey = "your secret key";
Auth auth = Auth.create(accessKey, secretKey);
CdnManager c = new CdnManager(auth);
//待刷新的目录列表,目录必须以 / 结尾
String[] dirs = new String[]{
"http://javasdk.qiniudn.com/gopher1/",
"http://javasdk.qiniudn.com/gopher2/",
//....
};
try {
//单次方法调用刷新的目录不可以超过10个,另外刷新目录权限需要联系技术支持开通
CdnResult.RefreshResult result = c.refreshDirs(dirs);
System.out.println(result.code);
//获取其他的回复内容
} catch (QiniuException e) {
System.err.println(e.response.toString());
}
}

}
5 changes: 2 additions & 3 deletions examples/DomainListDemo.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

import com.qiniu.common.QiniuException;
import com.qiniu.common.Zone;
import com.qiniu.http.Response;

Check warning on line 3 in examples/DomainListDemo.java

View check run for this annotation

qiniu-x / stylecheck

examples/DomainListDemo.java#L3

Unused import - com.qiniu.http.Response. [UnusedImports]
import com.qiniu.util.Auth;

public class DomainListDemo {
Expand All @@ -22,8 +21,8 @@

try {
String[] domainLists = bucketManager.domainList(bucket);
for(String domain : domainLists)
System.out.print(domain);
for (String domain : domainLists)

Check warning on line 24 in examples/DomainListDemo.java

View check run for this annotation

qiniu-x / stylecheck

examples/DomainListDemo.java#L24

'for' construct must use '{}'s. [NeedBraces]
System.out.print(domain);

} catch (QiniuException e) {

Expand Down
18 changes: 9 additions & 9 deletions examples/GetBucketInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,36 @@
import com.qiniu.storage.model.BucketInfo;

public class GetBucketInfo {

//设置需要操作的账号的AK和SK
String ACCESS_KEY = "Access_Key";

Check warning on line 10 in examples/GetBucketInfo.java

View check run for this annotation

qiniu-x / stylecheck

examples/GetBucketInfo.java#L10

Missing a Javadoc comment. [JavadocVariable]

Check warning on line 10 in examples/GetBucketInfo.java

View check run for this annotation

qiniu-x / stylecheck

examples/GetBucketInfo.java#L10

Variable 'ACCESS_KEY' must be private and have accessor methods. [VisibilityModifier]

Check warning on line 10 in examples/GetBucketInfo.java

View check run for this annotation

qiniu-x / stylecheck

examples/GetBucketInfo.java#L10

Name 'ACCESS_KEY' must match pattern '^[a-z][a-zA-Z0-9]*$'. [MemberName]
String SECRET_KEY = "Secret_Key";

Check warning on line 11 in examples/GetBucketInfo.java

View check run for this annotation

qiniu-x / stylecheck

examples/GetBucketInfo.java#L11

Missing a Javadoc comment. [JavadocVariable]

Check warning on line 11 in examples/GetBucketInfo.java

View check run for this annotation

qiniu-x / stylecheck

examples/GetBucketInfo.java#L11

Variable 'SECRET_KEY' must be private and have accessor methods. [VisibilityModifier]

Check warning on line 11 in examples/GetBucketInfo.java

View check run for this annotation

qiniu-x / stylecheck

examples/GetBucketInfo.java#L11

Name 'SECRET_KEY' must match pattern '^[a-z][a-zA-Z0-9]*$'. [MemberName]
Auth auth = Auth.create(ACCESS_KEY, SECRET_KEY);

Check warning on line 12 in examples/GetBucketInfo.java

View check run for this annotation

qiniu-x / stylecheck

examples/GetBucketInfo.java#L12

Missing a Javadoc comment. [JavadocVariable]

Check warning on line 12 in examples/GetBucketInfo.java

View check run for this annotation

qiniu-x / stylecheck

examples/GetBucketInfo.java#L12

Variable 'auth' must be private and have accessor methods. [VisibilityModifier]

//指定区域,可以用 Zone.autoZone() 自动获取
Zone z = Zone.zone0();

Check warning on line 15 in examples/GetBucketInfo.java

View check run for this annotation

qiniu-x / stylecheck

examples/GetBucketInfo.java#L15

Missing a Javadoc comment. [JavadocVariable]

Check warning on line 15 in examples/GetBucketInfo.java

View check run for this annotation

qiniu-x / stylecheck

examples/GetBucketInfo.java#L15

Variable 'z' must be private and have accessor methods. [VisibilityModifier]
Configuration c = new Configuration(z);

Check warning on line 16 in examples/GetBucketInfo.java

View check run for this annotation

qiniu-x / stylecheck

examples/GetBucketInfo.java#L16

Missing a Javadoc comment. [JavadocVariable]

Check warning on line 16 in examples/GetBucketInfo.java

View check run for this annotation

qiniu-x / stylecheck

examples/GetBucketInfo.java#L16

Variable 'c' must be private and have accessor methods. [VisibilityModifier]

//实例化一个BucketManager对象
BucketManager bucketManager = new BucketManager(auth, c);

Check warning on line 19 in examples/GetBucketInfo.java

View check run for this annotation

qiniu-x / stylecheck

examples/GetBucketInfo.java#L19

Missing a Javadoc comment. [JavadocVariable]

Check warning on line 19 in examples/GetBucketInfo.java

View check run for this annotation

qiniu-x / stylecheck

examples/GetBucketInfo.java#L19

Variable 'bucketManager' must be private and have accessor methods. [VisibilityModifier]

// 空间名
String bucket = "BUCKET";

Check warning on line 22 in examples/GetBucketInfo.java

View check run for this annotation

qiniu-x / stylecheck

examples/GetBucketInfo.java#L22

Missing a Javadoc comment. [JavadocVariable]

Check warning on line 22 in examples/GetBucketInfo.java

View check run for this annotation

qiniu-x / stylecheck

examples/GetBucketInfo.java#L22

Variable 'bucket' must be private and have accessor methods. [VisibilityModifier]

public static void main(String[] args) {

Check warning on line 24 in examples/GetBucketInfo.java

View check run for this annotation

qiniu-x / stylecheck

examples/GetBucketInfo.java#L24

Missing a Javadoc comment. [MissingJavadocMethod]

Check warning on line 24 in examples/GetBucketInfo.java

View check run for this annotation

qiniu-x / stylecheck

examples/GetBucketInfo.java#L24

Parameter args should be final. [FinalParameters]
new GetBucketInfo().getBucketInfo();
}

public void getBucketInfo() {

Check warning on line 28 in examples/GetBucketInfo.java

View check run for this annotation

qiniu-x / stylecheck

examples/GetBucketInfo.java#L28

Class 'GetBucketInfo' looks like designed for extension (can be subclassed), but the method 'getBucketInfo' does not have javadoc that explains how to do that safely. If class is not designed for extension consider making the class 'GetBucketInfo' final or making the method 'getBucketInfo' static/final/abstract/empty, or adding allowed annotation for the method. [DesignForExtension]

Check warning on line 28 in examples/GetBucketInfo.java

View check run for this annotation

qiniu-x / stylecheck

examples/GetBucketInfo.java#L28

Missing a Javadoc comment. [MissingJavadocMethod]
try {
BucketInfo bucketInfo = bucketManager.getBucketInfo(bucket);
// 输出空间私有性
System.out.println(bucketInfo.getPrivate());
// 输出空间所述区域
System.out.println(bucketInfo.getZone());
// 其他参数详见 https://github.com/qiniu/java-sdk/blob/master/src/main/java/com/qiniu/storage/model/BucketInfo.java

// 其他参数详见 https://github.com/qiniu/java-sdk/blob/master/src/main/java/com/qiniu/storage/model/BucketInfo.java

Check warning on line 36 in examples/GetBucketInfo.java

View check run for this annotation

qiniu-x / stylecheck

examples/GetBucketInfo.java#L36

Line is longer than 80 characters (found 121). [LineLength]

} catch (Exception e) {
//
}
Expand Down
103 changes: 51 additions & 52 deletions examples/LinkingDemo.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,114 +16,113 @@ public class LinkingDemo {
final static String testHost = "http://linking.qiniuapi.com";
final static String testDeviceName1 = "test1";
final static String testDeviceName2 = "test2";

public static void main(String[] args) {

Auth auth = Auth.create(testAk,testSk);
LinkingDeviceManager deviceManager = new LinkingDeviceManager(auth,testHost);
try{
Auth auth = Auth.create(testAk, testSk);
LinkingDeviceManager deviceManager = new LinkingDeviceManager(auth, testHost);
try {
//创建设备
deviceManager.createDevice(testAppid,testDeviceName1);
} catch (QiniuException e){
deviceManager.createDevice(testAppid, testDeviceName1);
} catch (QiniuException e) {
System.out.println(e.error());
}

try{
try {
//添加dak
DeviceKey[] keys = deviceManager.addDeviceKey(testAppid,testDeviceName1);
DeviceKey[] keys = deviceManager.addDeviceKey(testAppid, testDeviceName1);
System.out.println(keys[0].getAccessKey());
System.out.println(keys[0].getSecretKey());
}catch (QiniuException e){
} catch (QiniuException e) {
System.out.println(e.error());
}

try{
try {
//查询设备
DeviceKey[] keys = deviceManager.queryDeviceKey(testAppid,testDeviceName1);
if (keys.length==1){
throw new QiniuException(new Exception(),"expect one length");
DeviceKey[] keys = deviceManager.queryDeviceKey(testAppid, testDeviceName1);
if (keys.length == 1) {
throw new QiniuException(new Exception(), "expect one length");
}
//删除设备
deviceManager.deleteDeviceKey(testAppid,testDeviceName1,keys[0].getAccessKey());
keys = deviceManager.queryDeviceKey(testAppid,testDeviceName1);
if (keys.length==0){
throw new QiniuException(new Exception(),"expect zero length");
deviceManager.deleteDeviceKey(testAppid, testDeviceName1, keys[0].getAccessKey());
keys = deviceManager.queryDeviceKey(testAppid, testDeviceName1);
if (keys.length == 0) {
throw new QiniuException(new Exception(), "expect zero length");
}
}catch (QiniuException e){
} catch (QiniuException e) {
System.out.println(e.error());
}

try{
try {
//列出设备
DeviceListing deviceslist = deviceManager.listDevice(testAppid,"","", 1,false);
DeviceListing deviceslist = deviceManager.listDevice(testAppid, "", "", 1, false);
System.out.println(deviceslist.items.length);
}catch (QiniuException e){
} catch (QiniuException e) {
System.out.println(e.error());
}



try{
try {
//修改设备字段
PatchOperation[] operations={new PatchOperation("replace","segmentExpireDays",9)};
Device device= deviceManager.updateDevice(testAppid,testDeviceName1,operations);
PatchOperation[] operations = {new PatchOperation("replace", "segmentExpireDays", 9)};
Device device = deviceManager.updateDevice(testAppid, testDeviceName1, operations);
System.out.println(device.getSegmentExpireDays());
}catch (QiniuException e){
} catch (QiniuException e) {
System.out.println(e.error());
}


try{
try {
//查询设备在线历史记录
DeviceHistoryListing history= deviceManager.listDeviceHistory(testAppid,testDeviceName1,
0,(new Date().getTime())/1000,"",0);
}catch (QiniuException e){
DeviceHistoryListing history = deviceManager.listDeviceHistory(testAppid, testDeviceName1,
0, (new Date().getTime()) / 1000, "", 0);
} catch (QiniuException e) {
System.out.println(e.error());
}



try{
try {
//删除设备信息
deviceManager.deleteDevice(testAppid,testDeviceName1);
} catch (QiniuException e){
deviceManager.deleteDevice(testAppid, testDeviceName1);
} catch (QiniuException e) {
System.out.println(e.error());
}

try{
deviceManager.createDevice(testAppid,testDeviceName1);
deviceManager.createDevice(testAppid,testDeviceName2);
try {
deviceManager.createDevice(testAppid, testDeviceName1);
deviceManager.createDevice(testAppid, testDeviceName2);

//添加dak
deviceManager.addDeviceKey(testAppid,testDeviceName1);
DeviceKey[] keys = deviceManager.queryDeviceKey(testAppid,testDeviceName1);
deviceManager.addDeviceKey(testAppid, testDeviceName1);
DeviceKey[] keys = deviceManager.queryDeviceKey(testAppid, testDeviceName1);
String dak = keys[0].getAccessKey();

//移动dak
deviceManager.cloneDeviceKey(testAppid,testDeviceName1,testDeviceName2,true, false,dak);
deviceManager.cloneDeviceKey(testAppid, testDeviceName1, testDeviceName2, true, false, dak);
Device device = deviceManager.getDeviceByAccessKey(dak);
device.getDeviceName();

deviceManager.deleteDeviceKey(testAppid,testDeviceName2,dak);
deviceManager.deleteDeviceKey(testAppid, testDeviceName2, dak);

String token;
//生成具有所有功能的token
String[] actions = new String[]{Auth.DTOKEN_ACTION_STATUS,Auth.DTOKEN_ACTION_VOD,Auth.DTOKEN_ACTION_TUTK};
token = auth.generateLinkingDeviceTokenWithExpires(testAppid,testDeviceName1,1000,actions);
String[] actions = new String[]{Auth.DTOKEN_ACTION_STATUS, Auth.DTOKEN_ACTION_VOD, Auth.DTOKEN_ACTION_TUTK};
token = auth.generateLinkingDeviceTokenWithExpires(testAppid, testDeviceName1, 1000, actions);
//生成视频相关功能的token
token = auth.generateLinkingDeviceVodTokenWithExpires(testAppid,testDeviceName1,1000,actions);
token = auth.generateLinkingDeviceVodTokenWithExpires(testAppid, testDeviceName1, 1000, actions);
//生成获取设备状态的token
token = auth.generateLinkingDeviceStatusTokenWithExpires(testAppid,testDeviceName1,1000,actions);
token = auth.generateLinkingDeviceStatusTokenWithExpires(testAppid, testDeviceName1, 1000, actions);

}catch (QiniuException e){
} catch (QiniuException e) {
System.out.println(e.error());
}finally {
try{
deviceManager.deleteDevice(testAppid,testDeviceName1);
}catch (Exception ignored){
} finally {
try {
deviceManager.deleteDevice(testAppid, testDeviceName1);
} catch (Exception ignored) {
}
try{
deviceManager.deleteDevice(testAppid,testDeviceName2);
}catch (Exception ignored){
try {
deviceManager.deleteDevice(testAppid, testDeviceName2);
} catch (Exception ignored) {
}
}

Expand Down
Loading
Loading