Skip to content

Commit

Permalink
Merge pull request #32 from JoshuaYin/master
Browse files Browse the repository at this point in the history
2.2.1
  • Loading branch information
joshua.yin authored Sep 24, 2019
2 parents 423e3bb + fffaff0 commit 5e833ce
Show file tree
Hide file tree
Showing 40 changed files with 531 additions and 449 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<dependency>
<groupId>cn.ucloud.ufile</groupId>
<artifactId>ufile-client-java</artifactId>
<version>2.1.5</version>
<version>2.2.1</version>
</dependency>
```

Expand All @@ -36,7 +36,7 @@
/*
* your other dependencies
*/
implementation 'cn.ucloud.ufile:ufile-client-java:2.1.5'
implementation 'cn.ucloud.ufile:ufile-client-java:2.2.1'
}
```

Expand Down
2 changes: 1 addition & 1 deletion ufile-sample-java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<dependency>
<groupId>cn.ucloud.ufile</groupId>
<artifactId>ufile-client-java</artifactId>
<version>2.1.5</version>
<version>2.2.1</version>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import cn.ucloud.ufile.UfileClient;
import cn.ucloud.ufile.api.ApiError;
import cn.ucloud.ufile.api.object.ObjectConfig;
import cn.ucloud.ufile.api.object.policy.PolicyParam;
import cn.ucloud.ufile.api.object.policy.PutPolicy;
import cn.ucloud.ufile.api.object.policy.PutPolicyForCallback;
import cn.ucloud.ufile.bean.PutObjectResultBean;
import cn.ucloud.ufile.bean.UfileErrorBean;
import cn.ucloud.ufile.exception.UfileClientException;
Expand All @@ -15,7 +18,6 @@
import okhttp3.Request;

import java.io.*;
import java.net.URLEncoder;

/**
* @author: joshua
Expand All @@ -38,10 +40,22 @@ public static void main(String[] args) {

public static void putFile(File file, String mimeType, String nameAs, String toBucket) {
try {
/**
* 上传回调策略
* 必须填写回调接口url(目前仅支持http,不支持https),可选填回调参数,回调参数请自行决定是否需要urlencode
* 若配置上传回调,则上传接口的回调将会透传回调接口的response,包括httpCode
*/
PutPolicy putPolicy = new PutPolicyForCallback.Builder("http://xxx.xxx.xxx.xxx[:port][/path]")
.addCallbackBody(new PolicyParam("key", "value"))
.build();
PutObjectResultBean response = UfileClient.object(Constants.OBJECT_AUTHORIZER, config)
.putObject(file, mimeType)
.nameAs(nameAs)
.toBucket(toBucket)
/**
* 配置上传回调策略
*/
// .withPutPolicy(putPolicy)
/**
* 是否上传校验MD5
*/
Expand Down Expand Up @@ -72,11 +86,23 @@ public void onProgress(long bytesWritten, long contentLength) {
}
}

public static void putFileAsync(File file, String mimeType, String nameAs, String toBucket) {
public static void putFileAsync(File file, String mimeType, String nameAs, String toBucket) throws UfileClientException {
/**
* 上传回调策略
* 必须填写回调接口url(目前仅支持http,不支持https),可选填回调参数,回调参数请自行决定是否需要urlencode
* 若配置上传回调,则上传接口的回调将会透传回调接口的response,包括httpCode
*/
PutPolicy putPolicy = new PutPolicyForCallback.Builder("http://xxx.xxx.xxx.xxx[:port][/path]")
.addCallbackBody(new PolicyParam("key", "value"))
.build();
UfileClient.object(Constants.OBJECT_AUTHORIZER, config)
.putObject(file, mimeType)
.nameAs(nameAs)
.toBucket(toBucket)
/**
* 配置上传回调策略
*/
// .withPutPolicy(putPolicy)
/**
* 是否上传校验MD5
*/
Expand Down Expand Up @@ -111,10 +137,22 @@ public void onError(Request request, ApiError error, UfileErrorBean response) {

public static void putStream(InputStream stream, String mimeType, String nameAs, String toBucket) {
try {
/**
* 上传回调策略
* 必须填写回调接口url(目前仅支持http,不支持https),可选填回调参数,回调参数请自行决定是否需要urlencode
* 若配置上传回调,则上传接口的回调将会透传回调接口的response,包括httpCode
*/
PutPolicy putPolicy = new PutPolicyForCallback.Builder("http://xxx.xxx.xxx.xxx[:port][/path]")
.addCallbackBody(new PolicyParam("key", "value"))
.build();
PutObjectResultBean response = UfileClient.object(Constants.OBJECT_AUTHORIZER, config)
.putObject(stream, mimeType)
.nameAs(nameAs)
.toBucket(toBucket)
/**
* 配置上传回调策略
*/
// .withPutPolicy(putPolicy)
/**
* 是否上传校验MD5
*/
Expand Down Expand Up @@ -145,11 +183,23 @@ public void onProgress(long bytesWritten, long contentLength) {
}
}

public static void putStreamAsync(InputStream stream, String mimeType, String nameAs, String toBucket) {
public static void putStreamAsync(InputStream stream, String mimeType, String nameAs, String toBucket) throws UfileClientException {
/**
* 上传回调策略
* 必须填写回调接口url(目前仅支持http,不支持https),可选填回调参数,回调参数请自行决定是否需要urlencode
* 若配置上传回调,则上传接口的回调将会透传回调接口的response,包括httpCode
*/
PutPolicy putPolicy = new PutPolicyForCallback.Builder("http://xxx.xxx.xxx.xxx[:port][/path]")
.addCallbackBody(new PolicyParam("key", "value"))
.build();
UfileClient.object(Constants.OBJECT_AUTHORIZER, config)
.putObject(stream, mimeType)
.nameAs(nameAs)
.toBucket(toBucket)
/**
* 配置上传回调策略
*/
// .withPutPolicy(putPolicy)
/**
* 是否上传校验MD5
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import cn.ucloud.ufile.api.object.ObjectConfig;
import cn.ucloud.ufile.api.object.multi.MultiUploadPartState;
import cn.ucloud.ufile.api.object.multi.MultiUploadInfo;
import cn.ucloud.ufile.api.object.policy.PolicyParam;
import cn.ucloud.ufile.api.object.policy.PutPolicy;
import cn.ucloud.ufile.api.object.policy.PutPolicyForCallback;
import cn.ucloud.ufile.bean.MultiUploadResponse;
import cn.ucloud.ufile.bean.base.BaseResponseBean;
import cn.ucloud.ufile.exception.UfileClientException;
Expand All @@ -18,7 +21,6 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.*;

/**
* @author: joshua
Expand Down Expand Up @@ -150,8 +152,20 @@ public static void abortMultiUpload(MultiUploadInfo info) {

public static MultiUploadResponse finishMultiUpload(MultiUploadInfo state, List<MultiUploadPartState> partStates) {
try {
/**
* 上传回调策略
* 必须填写回调接口url(目前仅支持http,不支持https),可选填回调参数,回调参数请自行决定是否需要urlencode。
* 若配置上传回调,则上传接口的回调将会透传回调接口的response,包括httpCode
*/
PutPolicy putPolicy = new PutPolicyForCallback.Builder("http://xxx.xxx.xxx.xxx[:port][/path]")
.addCallbackBody(new PolicyParam("key", "value"))
.build();
MultiUploadResponse res = UfileClient.object(Constants.OBJECT_AUTHORIZER, config)
.finishMultiUpload(state, partStates)
/**
* 配置上传回调策略
*/
// .withPutPolicy(putPolicy)
.execute();
JLog.D(TAG, "finish->" + res.toString());
return res;
Expand Down
2 changes: 1 addition & 1 deletion ufile/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<groupId>cn.ucloud.ufile</groupId>
<artifactId>ufile</artifactId>
<packaging>pom</packaging>
<version>2.1.5</version>
<version>2.2.1</version>

<modules>
<module>ufile-core</module>
Expand Down
Binary file modified ufile/ufile-client-java/apidocs.zip
Binary file not shown.
6 changes: 3 additions & 3 deletions ufile/ufile-client-java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
<parent>
<artifactId>ufile</artifactId>
<groupId>cn.ucloud.ufile</groupId>
<version>2.1.5</version>
<version>2.2.1</version>
</parent>

<artifactId>ufile-client-java</artifactId>
<version>2.1.5</version>
<version>2.2.1</version>

<dependencies>
<dependency>
Expand All @@ -26,7 +26,7 @@
<dependency>
<groupId>cn.ucloud.ufile</groupId>
<artifactId>ufile-core</artifactId>
<version>2.1.5</version>
<version>2.2.1</version>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,9 @@
import cn.ucloud.ufile.UfileConstants;
import cn.ucloud.ufile.api.ApiError;
import cn.ucloud.ufile.auth.ObjectAuthorizer;
import cn.ucloud.ufile.auth.UfileAuthorizationException;
import cn.ucloud.ufile.auth.sign.UfileSignatureException;
import cn.ucloud.ufile.bean.DownloadFileBean;
import cn.ucloud.ufile.bean.ObjectProfile;
import cn.ucloud.ufile.bean.UfileErrorBean;
import cn.ucloud.ufile.compat.base64.Base64UrlEncoderCompat;
import cn.ucloud.ufile.compat.base64.DefaultBase64UrlEncoderCompat;
import cn.ucloud.ufile.exception.UfileClientException;
import cn.ucloud.ufile.exception.UfileIOException;
import cn.ucloud.ufile.exception.UfileParamException;
Expand Down Expand Up @@ -121,11 +117,6 @@ public class DownloadFileApi extends UfileObjectApi<DownloadFileBean> {
* 流读取的buffer大小,Default = 256 KB
*/
private int bufferSize = UfileConstants.DEFAULT_BUFFER_SIZE;
/**
* 兼容Java 1.8以下的Base64 编码器接口
*/
@Deprecated
private Base64UrlEncoderCompat base64;

/**
* 构造方法
Expand Down Expand Up @@ -210,19 +201,6 @@ public DownloadFileApi withProgressConfig(ProgressConfig config) {
return this;
}

/**
* 配置Base64 Url编码器,不调用该方法将会默认使用Java 1.8的Base64类
* (若您的运行环境在Java 1.8以下,请使用该方法)
*
* @param base64 兼容Java 1.8以下的Base64 Url编码器接口
* @return {@link DownloadFileApi}
*/
@Deprecated
public DownloadFileApi withBase64UrlEncoder(Base64UrlEncoderCompat base64) {
this.base64 = base64;
return this;
}

/**
* 配置签名可选参数
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@
import cn.ucloud.ufile.auth.UfileAuthorizationException;
import cn.ucloud.ufile.auth.sign.UfileSignatureException;
import cn.ucloud.ufile.bean.ObjectProfile;
import cn.ucloud.ufile.compat.base64.DefaultBase64UrlEncoderCompat;
import cn.ucloud.ufile.exception.UfileClientException;
import cn.ucloud.ufile.exception.UfileIOException;
import cn.ucloud.ufile.exception.UfileRequiredParamNotFoundException;
import cn.ucloud.ufile.exception.UfileServerException;
import cn.ucloud.ufile.compat.base64.Base64UrlEncoderCompat;
import cn.ucloud.ufile.util.Etag;

import java.io.*;
Expand Down Expand Up @@ -272,23 +270,8 @@ public ObjectRestoreApi objectRestore(String keyName, String bucketName) {
*/
public boolean compareEtag(File localFile, String keyName, String bucketName)
throws UfileClientException, UfileServerException {
return compareEtag(localFile, keyName, bucketName, new DefaultBase64UrlEncoderCompat());
}

/**
* 比对ETag值 (若您的运行环境在Java 1.8以下,请使用该方法)
*
* @param localFile 要对比的本地文件
* @param keyName 要对比的云端文件名
* @param bucketName 要对比的云端文件的所属空间
* @param base64 兼容Java 1.8以下的Base64 Url编码器接口
* @return ETag是否一致
* @throws UfileClientException
*/
public boolean compareEtag(File localFile, String keyName, String bucketName, Base64UrlEncoderCompat base64)
throws UfileClientException, UfileServerException {
try {
return compareEtag(new FileInputStream(localFile), keyName, bucketName, base64);
return compareEtag(new FileInputStream(localFile), keyName, bucketName);
} catch (FileNotFoundException e) {
throw new UfileIOException(e);
}
Expand All @@ -305,24 +288,9 @@ public boolean compareEtag(File localFile, String keyName, String bucketName, Ba
*/
public boolean compareEtag(InputStream localStream, String keyName, String bucketName)
throws UfileClientException, UfileServerException {
return compareEtag(localStream, keyName, bucketName, new DefaultBase64UrlEncoderCompat());
}

/**
* 比对ETag值 (若您的运行环境在Java 1.8以下,请使用该方法)
*
* @param localStream 要对比的本地流
* @param keyName 要对比的云端文件名
* @param bucketName 要对比的云端文件的所属空间
* @param base64 兼容Java 1.8以下的Base64 Url编码器接口
* @return ETag是否一致
* @throws UfileClientException
*/
public boolean compareEtag(InputStream localStream, String keyName, String bucketName,
Base64UrlEncoderCompat base64) throws UfileClientException, UfileServerException {
ObjectProfile res = objectProfile(keyName, bucketName).execute();
try {
Etag eTag = Etag.etag(localStream, base64);
Etag eTag = Etag.etag(localStream);
return eTag.geteTag().equals(res.geteTag());
} catch (IOException e) {
throw new UfileIOException(e);
Expand Down
Loading

0 comments on commit 5e833ce

Please sign in to comment.