English 中文(简体)
用JeS3t向S3号案多载数量不明的档案
原标题:Multiple Uploads of unknown number of files to S3 with JetS3t

from the sample code examples of jetS3t the code that follows: What to do if I don t know the number of files to be downloaded from the beginning? E.g an application with thumbnails in S3, and a client application that the user scrolls through a list of thumbnails.

对当地档案的下载物体

The multi-threading services provide a method to download multiple objects at a time, but to use this you must first prepare somewhere to put the data associated with each object. The most obvious place to put this data is into a file, so let s go through an example of downloading object data into files. To download our objects into files we first must create a DownloadPackage class for each object. This class is a simple container which merely associates an object with a file, to which the object s data will be written. Create a DownloadPackage for each object, to associate the object with an output file.

 DownloadPackage[] downloadPackages = new DownloadPackage[5];
   downloadPackages[0] = new DownloadPackage(objects[0],
       new File(objects[0].getKey()));
   downloadPackages[1] = new DownloadPackage(objects[1],
       new File(objects[1].getKey()));
   downloadPackages[2] = new DownloadPackage(objects[2],
       new File(objects[2].getKey()));
   downloadPackages[3] = new DownloadPackage(objects[3],
       new File(objects[3].getKey()));
   downloadPackages[4] = new DownloadPackage(objects[4],
       new File(objects[4].getKey()));

   // Download the objects.
   simpleMulti.downloadObjects(bucket, downloadPackages);
   System.out.println("Downloaded objects to current working directory");

Any suggestions for that cases? Thanks in advance

Antonis

问题回答

你可以根据你确定的规则,把物体列入你从钥匙中下载和过滤的关键。 然后,你可以开始多部分下载。

get keys from the bucket:


public List getFilesList(String accessKey, String secretKey ,String bucketName ,String directoryPathRelativeToBucket) { List keys = new ArrayList(); org.jets3t.service.model.S3Object[] objects = new org.jets3t.service.model.S3Object[]{}; try { // Create a credentials object and service to access S3 account org.jets3t.service.security.AWSCredentials myCredentials = new org.jets3t.service.security.AWSCredentials(accessKey, secretKey); S3Service service = new RestS3Service(myCredentials); objects = service.listObjects(bucketName ,directoryPathRelativeToBucket, null); log.info("got bucket listing for bucket[" + bucketName + "]"); } catch (S3ServiceException e) { log.error("Failed to get or object listing for bucket[" + bucketName + "] due to exception:", e); } for (org.jets3t.service.model.S3Object s3Object : objects) { if (s3Object.getKey().contains("$") == false) { keys.add(s3Object.getKey()); } } return keys; }

在过滤钥匙之后,你可以下载关键清单的特定部分。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签