Skip to content

Commit 9e147ba

Browse files
committed
update qcloud sdk to 1.5.26
1 parent 4df22ed commit 9e147ba

32 files changed

+282
-1572
lines changed
Binary file not shown.

QCloudFoundation/.idea/compiler.xml

Lines changed: 0 additions & 16 deletions
This file was deleted.

QCloudFoundation/.idea/gradle.xml

Lines changed: 0 additions & 22 deletions
This file was deleted.

QCloudFoundation/.idea/jarRepositories.xml

Lines changed: 0 additions & 40 deletions
This file was deleted.

QCloudFoundation/.idea/misc.xml

Lines changed: 0 additions & 14 deletions
This file was deleted.

QCloudFoundation/.idea/modules.xml

Lines changed: 0 additions & 10 deletions
This file was deleted.

QCloudFoundation/.idea/vcs.xml

Lines changed: 0 additions & 6 deletions
This file was deleted.

QCloudFoundation/foundation/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ android {
77
minSdkVersion 15
88
targetSdkVersion 27
99

10-
versionCode 10525
11-
versionName "1.5.25"
10+
versionCode 10526
11+
versionName "1.5.26"
1212

1313
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
1414

QCloudFoundation/foundation/src/main/java/com/tencent/qcloud/core/http/HttpRequest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,11 @@ public Builder<T> encodedQuery(String key, String value) {
272272
return this;
273273
}
274274

275+
public Builder<T> encodedQuery(String queryString) {
276+
httpUrlBuilder.encodedQuery(queryString);
277+
return this;
278+
}
279+
275280
public Builder<T> query(Map<String, String> nameValues) {
276281
if (nameValues != null) {
277282
for (Map.Entry<String, String> entry : nameValues.entrySet()) {

QCloudFoundation/foundation/src/main/java/com/tencent/qcloud/core/http/ResponseFileConverter.java

Lines changed: 66 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,18 @@
2323
package com.tencent.qcloud.core.http;
2424

2525

26+
import android.content.ContentResolver;
27+
import android.net.Uri;
28+
import android.text.TextUtils;
29+
2630
import com.tencent.qcloud.core.common.QCloudClientException;
2731
import com.tencent.qcloud.core.common.QCloudProgressListener;
2832
import com.tencent.qcloud.core.common.QCloudServiceException;
2933
import com.tencent.qcloud.core.util.QCloudHttpUtils;
3034

3135
import java.io.*;
3236

37+
import okhttp3.Response;
3338
import okhttp3.ResponseBody;
3439
import okhttp3.internal.Util;
3540
import okio.Buffer;
@@ -38,6 +43,9 @@
3843
public class ResponseFileConverter<T> extends ResponseBodyConverter<T> implements ProgressBody {
3944

4045
private String filePath;
46+
private Uri contentUri;
47+
private ContentResolver contentResolver;
48+
4149
private long offset;
4250

4351
protected boolean isQuic = false;
@@ -51,6 +59,12 @@ public ResponseFileConverter(String filePath, long offset) {
5159
this.offset = offset;
5260
}
5361

62+
public ResponseFileConverter(Uri contentUri, ContentResolver contentResolver, long offset) {
63+
this.contentUri = contentUri;
64+
this.contentResolver = contentResolver;
65+
this.offset = offset;
66+
}
67+
5468
@Override
5569
public void setProgressListener(QCloudProgressListener progressListener) {
5670
this.progressListener = progressListener;
@@ -80,6 +94,39 @@ public T convert(HttpResponse<T> response) throws QCloudClientException, QCloudS
8094
contentLength = response.contentLength();
8195
}
8296

97+
if (!TextUtils.isEmpty(filePath)) {
98+
return downloadToAbsolutePath(response, contentLength);
99+
} else if (contentUri != null) {
100+
return pipeToContentUri(response, contentLength);
101+
}
102+
103+
throw new QCloudClientException(new IllegalArgumentException("filePath or ContentUri are both null"));
104+
}
105+
106+
private T pipeToContentUri(HttpResponse<T> response, long contentLength)
107+
throws QCloudClientException, QCloudServiceException {
108+
OutputStream output = getOutputStream();
109+
InputStream input = response.byteStream();
110+
111+
byte[] buffer = new byte[8192];
112+
countingSink = new CountingSink(new Buffer(), contentLength, progressListener);
113+
int len;
114+
try {
115+
while ((len = input.read(buffer)) != -1) {
116+
output.write(buffer, 0, len);
117+
countingSink.writeBytesInternal(len);
118+
}
119+
return null;
120+
} catch (IOException e) {
121+
e.printStackTrace();
122+
throw new QCloudClientException("write local uri error for " + e.toString(), e);
123+
} finally {
124+
Util.closeQuietly(output);
125+
}
126+
}
127+
128+
private T downloadToAbsolutePath(HttpResponse<T> response, long contentLength)
129+
throws QCloudClientException, QCloudServiceException {
83130
File downloadFilePath = new File(filePath);
84131
File parentDir = downloadFilePath.getParentFile();
85132
if(parentDir != null && !parentDir.exists() && !parentDir.mkdirs()){
@@ -121,16 +168,25 @@ private void writeRandomAccessFile(File downloadFilePath, InputStream inputStrea
121168
}
122169

123170
public OutputStream getOutputStream() throws QCloudClientException {
124-
File downloadFilePath = new File(filePath);
125-
File parentDir = downloadFilePath.getParentFile();
126-
if(parentDir != null && !parentDir.exists() && !parentDir.mkdirs()){
127-
throw new QCloudClientException(new IOException("local file directory can not create."));
128-
}
129-
try {
130-
OutputStream outputStream = new FileOutputStream(downloadFilePath);
131-
return outputStream;
132-
} catch (FileNotFoundException e) {
133-
throw new QCloudClientException(e);
171+
if (!TextUtils.isEmpty(filePath)) {
172+
File downloadFilePath = new File(filePath);
173+
File parentDir = downloadFilePath.getParentFile();
174+
if(parentDir != null && !parentDir.exists() && !parentDir.mkdirs()){
175+
throw new QCloudClientException(new IOException("local file directory can not create."));
176+
}
177+
try {
178+
return new FileOutputStream(downloadFilePath);
179+
} catch (FileNotFoundException e) {
180+
throw new QCloudClientException(e);
181+
}
182+
} else if (contentUri != null){
183+
try {
184+
return contentResolver.openOutputStream(contentUri);
185+
} catch (FileNotFoundException e) {
186+
throw new QCloudClientException(e);
187+
}
188+
} else {
189+
throw new QCloudClientException(new IllegalArgumentException("filePath or ContentUri are both null"));
134190
}
135191
}
136192

0 commit comments

Comments
 (0)