-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from JoshuaYin/master
## 2.4.1 * ObjectProfileApi新增CreateTime字段 * 所有Object的API均添加response headers Map<String,String> * ObjectProfileSample新增批量调用demo * 生成下载链接的API加入配置Content-Disposition的filename
- Loading branch information
Showing
51 changed files
with
647 additions
and
184 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,9 +11,9 @@ | |
import cn.ucloud.ufile.http.UfileCallback; | ||
import cn.ucloud.ufile.sample.Constants; | ||
import cn.ucloud.ufile.util.JLog; | ||
import cn.ucloud.ufile.util.MimeTypeUtil; | ||
import okhttp3.Request; | ||
|
||
|
||
/** | ||
* @author: joshua | ||
* @E-mail: [email protected] | ||
|
@@ -25,8 +25,8 @@ public class AppendObjectSample { | |
|
||
public static void main(String[] args) { | ||
byte[] appendData = new byte[]{0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00}; | ||
String mimeType = ""; | ||
String keyName = ""; | ||
String mimeType = MimeTypeUtil.getMimeType(keyName); | ||
String bucketName = ""; | ||
long posistion = 0; | ||
appendObject(appendData, mimeType, bucketName, keyName, posistion); | ||
|
@@ -59,7 +59,7 @@ public void onProgress(long bytesWritten, long contentLength) { | |
} | ||
}) | ||
.execute(); | ||
JLog.D(TAG, String.format("[res] = %s", (response == null ? "null" : response.toString()))); | ||
JLog.D(TAG, String.format("[res]: %s", (response == null ? "null" : response.toString()))); | ||
} catch (UfileClientException e) { | ||
e.printStackTrace(); | ||
} catch (UfileServerException e) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,11 @@ | |
import cn.ucloud.ufile.util.JLog; | ||
import okhttp3.Request; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.concurrent.*; | ||
|
||
/** | ||
* @author: joshua | ||
* @E-mail: [email protected] | ||
|
@@ -25,15 +30,108 @@ public static void main(String[] args) { | |
String keyName = ""; | ||
String bucketName = ""; | ||
|
||
execute(keyName, bucketName); | ||
// execute(keyName, bucketName); | ||
List<Info> infos = new ArrayList<>(); | ||
infos.add(new Info(bucketName).setKeyName("")); | ||
infos.add(new Info(bucketName).setKeyName("")); | ||
infos.add(new Info(bucketName).setKeyName("")); | ||
infos.add(new Info(bucketName).setKeyName("")); | ||
infos.add(new Info(bucketName).setKeyName("")); | ||
batch(infos); | ||
} | ||
|
||
private static class Info { | ||
private String bucket; | ||
private String keyName; | ||
|
||
public Info(String bucket) { | ||
this.bucket = bucket; | ||
} | ||
|
||
public String getBucket() { | ||
return bucket; | ||
} | ||
|
||
public Info setBucket(String bucket) { | ||
this.bucket = bucket; | ||
return this; | ||
} | ||
|
||
public String getKeyName() { | ||
return keyName; | ||
} | ||
|
||
public Info setKeyName(String keyName) { | ||
this.keyName = keyName; | ||
return this; | ||
} | ||
} | ||
|
||
public static void batch(List<Info> infos) { | ||
if (infos == null || infos.isEmpty()) | ||
return; | ||
|
||
ExecutorService threadPool = new ThreadPoolExecutor(5, 10, | ||
0L, TimeUnit.MILLISECONDS, | ||
new LinkedBlockingQueue<Runnable>()); | ||
|
||
List<ObjectProfileCallable> callables = new ArrayList<>(); | ||
for (Info info : infos) { | ||
callables.add(new ObjectProfileCallable(info)); | ||
} | ||
|
||
try { | ||
List<Future<ObjectProfile>> futures = threadPool.invokeAll(callables); | ||
for (Future<ObjectProfile> future : futures) { | ||
try { | ||
JLog.D(TAG, "=====================================================================\n"); | ||
ObjectProfile objectProfile = future.get(); | ||
JLog.D(TAG, String.format("[res]: %s", (objectProfile == null ? "null" : objectProfile.toString()))); | ||
Map<String, String> headers = objectProfile.getHeaders(); | ||
if (headers != null) { | ||
for (Map.Entry<String, String> entry : headers.entrySet()) { | ||
JLog.D(TAG, "\t\t[key]:" + entry.getKey() + "\t[val]:" + entry.getValue()); | ||
} | ||
} | ||
} catch (ExecutionException e) { | ||
JLog.D(TAG, String.format("[err]: %s", e.getMessage())); | ||
} | ||
} | ||
} catch (InterruptedException e) { | ||
e.printStackTrace(); | ||
} finally { | ||
threadPool.shutdownNow(); | ||
} | ||
} | ||
|
||
private static class ObjectProfileCallable implements Callable<ObjectProfile> { | ||
private Info info; | ||
|
||
public ObjectProfileCallable(Info info) { | ||
this.info = info; | ||
} | ||
|
||
@Override | ||
public ObjectProfile call() throws Exception { | ||
Thread.sleep(5000); | ||
return UfileClient.object(Constants.OBJECT_AUTHORIZER, config) | ||
.objectProfile(info.getKeyName(), info.getBucket()) | ||
.execute(); | ||
} | ||
} | ||
|
||
public static void execute(String keyName, String bucketName) { | ||
try { | ||
ObjectProfile objectProfile = UfileClient.object(Constants.OBJECT_AUTHORIZER, config) | ||
.objectProfile(keyName, bucketName) | ||
.execute(); | ||
JLog.D(TAG, String.format("[res] = %s", (objectProfile == null ? "null" : objectProfile.toString()))); | ||
JLog.D(TAG, String.format("[res]: %s", (objectProfile == null ? "null" : objectProfile.toString()))); | ||
Map<String, String> headers = objectProfile.getHeaders(); | ||
if (headers != null) { | ||
for (Map.Entry<String, String> entry : headers.entrySet()) { | ||
JLog.D(TAG, "[key]:" + entry.getKey() + " [val]:" + entry.getValue()); | ||
} | ||
} | ||
} catch (UfileClientException e) { | ||
e.printStackTrace(); | ||
} catch (UfileServerException e) { | ||
|
@@ -49,6 +147,12 @@ public static void executeAsync(String keyName, String bucketName) { | |
@Override | ||
public void onResponse(ObjectProfile response) { | ||
JLog.D(TAG, String.format("[res] = %s", (response == null ? "null" : response.toString()))); | ||
Map<String, String> headers = response.getHeaders(); | ||
if (headers != null) { | ||
for (Map.Entry<String, String> entry : headers.entrySet()) { | ||
JLog.D(TAG, "[key]:" + entry.getKey() + " [val]:" + entry.getValue()); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.