本文整理汇总了Java中com.aliyun.oss.model.ObjectListing.getObjectSummaries方法的典型用法代码示例。如果您正苦于以下问题:Java ObjectListing.getObjectSummaries方法的具体用法?Java ObjectListing.getObjectSummaries怎么用?Java ObjectListing.getObjectSummaries使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.aliyun.oss.model.ObjectListing
的用法示例。
在下文中一共展示了ObjectListing.getObjectSummaries方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getFolderSize
import com.aliyun.oss.model.ObjectListing; //导入方法依赖的package包/类
/**
* 查看某个路径下的文件所占用的资源的大小
* @param filePath 要查看文件的路径,如 file/image/
* @return 单位:B
*/
public long getFolderSize(String filePath){
ListObjectsRequest listObjectsRequest = new ListObjectsRequest(bucketName);
listObjectsRequest.setPrefix(filePath);
listObjectsRequest.setMaxKeys(1000);
boolean have = true; //是否有下一页
String nextMarker = null;
int size = 0; //总字节大小,单位:B
while(have){
if(nextMarker != null){
listObjectsRequest.setMarker(nextMarker);
}
ObjectListing listO = getOSSClient().listObjects(listObjectsRequest);
for (OSSObjectSummary objectSummary : listO.getObjectSummaries()) {
size += objectSummary.getSize();
}
have = listO.isTruncated();
nextMarker = listO.getNextMarker();
}
return size;
}
示例2: getFolderObjectList
import com.aliyun.oss.model.ObjectListing; //导入方法依赖的package包/类
/**
* 获取 指定目录下的所有文件对象
* @param filePath 要查看文件的路径,如 file/image/
* @return {@link List}
*/
public List<OSSObjectSummary> getFolderObjectList(String filePath){
ListObjectsRequest listObjectsRequest = new ListObjectsRequest(bucketName);
listObjectsRequest.setPrefix(filePath);
listObjectsRequest.setMaxKeys(1000);
List<OSSObjectSummary> list = new ArrayList<OSSObjectSummary>();
boolean have = true; //是否有下一页
String nextMarker = null;
while(have){
if(nextMarker != null){
listObjectsRequest.setMarker(nextMarker);
}
ObjectListing listO = getOSSClient().listObjects(listObjectsRequest);
for (OSSObjectSummary objectSummary : listO.getObjectSummaries()) {
list.add(objectSummary);
}
have = listO.isTruncated();
nextMarker = listO.getNextMarker();
}
return list;
}
示例3: getFolderSize
import com.aliyun.oss.model.ObjectListing; //导入方法依赖的package包/类
/**
* 查看某个路径下的文件所占用的资源的大小
* @param filePath 要查看文件的路径,如 file/image/
* @return 单位:B
*/
public static long getFolderSize(String filePath){
ListObjectsRequest listObjectsRequest = new ListObjectsRequest(bucketName);
listObjectsRequest.setPrefix(filePath);
listObjectsRequest.setMaxKeys(1000);
boolean have = true; //是否有下一页
String nextMarker = null;
int size = 0; //总字节大小,单位:B
while(have){
if(nextMarker != null){
listObjectsRequest.setMarker(nextMarker);
}
ObjectListing listO = OSSUtil.getOSSClient().listObjects(listObjectsRequest);
for (OSSObjectSummary objectSummary : listO.getObjectSummaries()) {
size += objectSummary.getSize();
}
have = listO.isTruncated();
nextMarker = listO.getNextMarker();
}
return size;
}
示例4: getFolderObjectList
import com.aliyun.oss.model.ObjectListing; //导入方法依赖的package包/类
/**
* 获取 指定目录下的所有文件对象
* @param filePath 要查看文件的路径,如 file/image/
* @return {@link List}
*/
public static List<OSSObjectSummary> getFolderObjectList(String filePath){
ListObjectsRequest listObjectsRequest = new ListObjectsRequest(bucketName);
listObjectsRequest.setPrefix(filePath);
listObjectsRequest.setMaxKeys(1000);
List<OSSObjectSummary> list = new ArrayList<OSSObjectSummary>();
boolean have = true; //是否有下一页
String nextMarker = null;
while(have){
if(nextMarker != null){
listObjectsRequest.setMarker(nextMarker);
}
ObjectListing listO = OSSUtil.getOSSClient().listObjects(listObjectsRequest);
for (OSSObjectSummary objectSummary : listO.getObjectSummaries()) {
list.add(objectSummary);
}
have = listO.isTruncated();
nextMarker = listO.getNextMarker();
}
return list;
}
示例5: listAllObjects
import com.aliyun.oss.model.ObjectListing; //导入方法依赖的package包/类
@Test
public void listAllObjects() {
final int maxKeys = 200;
String nextMarker = null;
ObjectListing objectListing=null;
do {
objectListing = ossClient.listObjects(new ListObjectsRequest("minsx-bucket").withMarker(nextMarker).withMaxKeys(maxKeys));
List<OSSObjectSummary> sums = objectListing.getObjectSummaries();
for (OSSObjectSummary s : sums) {
System.out.println("\t" + s.getKey());
}
nextMarker = objectListing.getNextMarker();
} while (objectListing.isTruncated());
}
示例6: getObjectList
import com.aliyun.oss.model.ObjectListing; //导入方法依赖的package包/类
public static List<OSSObjectSummary> getObjectList(String bucketName,
String prefix, int endIndex, int maxKeys) {
// 初始化OSSClient
OSSClient client = getOSSClient();
// 构造ListObjectsRequest请求
ListObjectsRequest listObjectsRequest = new ListObjectsRequest(
bucketName);
// 递归列出fun目录下的所有文件
listObjectsRequest.setPrefix(prefix);
listObjectsRequest.setMaxKeys(maxKeys);
// listObjectsRequest.setMarker("ueditor/jsp/upload/image/20150614/1434267568217077840.jpg");
ObjectListing listing = null;
String nextMarker = null;
// endIndex>maxKeys
int pageNum = endIndex / maxKeys;
for (int i = 0; i < pageNum; i++) {
if (nextMarker != null) {
listObjectsRequest.setMarker(nextMarker);
}
listing = client.listObjects(listObjectsRequest);
nextMarker = listing.getNextMarker();
}
// 遍历所有Object
List<OSSObjectSummary> objectSummarys = listing.getObjectSummaries();
return objectSummarys;
// 遍历所有CommonPrefix
/*
* System.out.println("\nCommonPrefixs:"); for (String commonPrefix :
* listing.getCommonPrefixes()) { System.out.println(commonPrefix); }
*/
}
示例7: listObject
import com.aliyun.oss.model.ObjectListing; //导入方法依赖的package包/类
/**
* 列出Object<br>
*
* @param client
* @param bucketName
* @param delimiter Delimiter 设置为 “/” 时,返回值就只罗列该文件夹下的文件,可以null
* @param prefix Prefix 设为某个文件夹名,就可以罗列以此 Prefix 开头的文件,可以null
* @return
*/
public static List<String> listObject(OSSClient client, String bucketName, String delimiter, String prefix) {
// 是否循环的标识
boolean hasNext = false;
// 设定结果从Marker之后按字母排序的第一个开始返回
String marker = "";
//
// ObjectListing listing = new ObjectListing();
List<String> filePathList = new ArrayList<String>();
// 构造ListObjectsRequest请求
ListObjectsRequest listObjectsRequest = new ListObjectsRequest(bucketName);
// 是一个用于对Object名字进行分组的字符。所有名字包含指定的前缀且第一次出现Delimiter字符之间的object作为一组元素:
// CommonPrefixes
listObjectsRequest.setDelimiter(delimiter);
// 限定此次返回object的最大数,如果不设定,默认为100,MaxKeys取值不能大于1000
listObjectsRequest.setMaxKeys(20);
// 限定返回的object key必须以Prefix作为前缀。注意使用prefix查询时,返回的key中仍会包含Prefix
listObjectsRequest.setPrefix(prefix);
do {
// 设定结果从Marker之后按字母排序的第一个开始返回
listObjectsRequest.setMarker(marker);
// 获取指定bucket下的所有Object信息
ObjectListing sublisting = client.listObjects(listObjectsRequest);
// 如果Bucket中的Object数量大于100,则只会返回100个Object, 且返回结果中 IsTruncated
// 为false
if (sublisting.isTruncated()) {
hasNext = true;
marker = sublisting.getNextMarker();
} else {
hasNext = false;
marker = "";
}
// // 遍历所有Object
for (OSSObjectSummary objectSummary : sublisting.getObjectSummaries()) {
// System.out.println(objectSummary.getKey());
filePathList.add(objectSummary.getKey());
}
} while (hasNext);
return filePathList;
}