com.aliyun.oss.model.OSSObjectSummary Java Examples

The following examples show how to use com.aliyun.oss.model.OSSObjectSummary. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OSSUtils.java    From xnx3 with Apache License 2.0 6 votes vote down vote up
/**
 * 查看某个路径下的文件所占用的资源的大小
 * @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;
}
 
Example #2
Source File: OSSUtils.java    From xnx3 with Apache License 2.0 6 votes vote down vote up
/**
 * 获取 指定目录下的所有文件对象
 * @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;
}
 
Example #3
Source File: OSSUtil.java    From xnx3 with Apache License 2.0 6 votes vote down vote up
/**
 * 查看某个路径下的文件所占用的资源的大小
 * @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;
}
 
Example #4
Source File: OSSUtil.java    From xnx3 with Apache License 2.0 6 votes vote down vote up
/**
 * 获取 指定目录下的所有文件对象
 * @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;
}
 
Example #5
Source File: OSSNotebookRepo.java    From zeppelin with Apache License 2.0 6 votes vote down vote up
@Override
public void remove(String folderPath, AuthenticationInfo subject) {
  String nextMarker = null;
  ObjectListing objectListing = null;
  do {
    ListObjectsRequest listObjectsRequest = new ListObjectsRequest(bucketName)
            .withPrefix(rootFolder + folderPath + "/")
            .withMarker(nextMarker);
    objectListing = ossClient.listObjects(listObjectsRequest);
    if (objectListing.getObjectSummaries().size() > 0) {
      List<String> keys = new ArrayList();
      for (OSSObjectSummary s : objectListing.getObjectSummaries()) {
        keys.add(s.getKey());
      }
      DeleteObjectsRequest deleteObjectsRequest = new DeleteObjectsRequest(bucketName).withKeys(keys);
      ossClient.deleteObjects(deleteObjectsRequest);
    }

    nextMarker = objectListing.getNextMarker();
  } while (objectListing.isTruncated());
}
 
Example #6
Source File: OSSUtil.java    From anyline with Apache License 2.0 5 votes vote down vote up
/** 
 * 下载prefix目录下的所有文件到本地dir目录 
 * @param dir  dir
 * @param prefix  prefix
 * @return return
 */ 
public boolean download(File dir, String prefix){ 
	if(null == prefix){ 
		prefix = ""; 
	} 
	if(prefix.startsWith("/")){ 
		prefix = prefix.substring(1); 
	} 
	final int maxKeys = 200; 
	String nextMarker = null; 
	ObjectListing objectListing; 
	do { 
	    objectListing = client.listObjects(new ListObjectsRequest(config.BUCKET) 
	    .withPrefix(prefix).withMarker(nextMarker).withMaxKeys(maxKeys)); 
	    List<OSSObjectSummary> sums = objectListing.getObjectSummaries(); 
	    for (OSSObjectSummary s : sums) { 
	    	String key = s.getKey(); 
	    	if(key.endsWith("/")){ 
	    		continue; 
	    	} 
	        File file = new File(dir, key); 
	        File parent = file.getParentFile(); 
	        if(null != parent && !parent.exists()){ 
	        	parent.mkdirs(); 
	        } 
	        try{ 
	        	client.getObject(new GetObjectRequest(config.BUCKET, key), file); 
	        }catch(Exception e){ 
	        	e.printStackTrace(); 
	        } 
	        if(ConfigTable.isDebug() && log.isWarnEnabled()){ 
	        	log.warn("[oss download file][local:{}][remote:{}]",file.getAbsolutePath(),key); 
	        } 
	    } 
	    nextMarker = objectListing.getNextMarker(); 
	     
	} while (objectListing.isTruncated()); 

	return true; 
}
 
Example #7
Source File: OSSInterface.java    From charging_pile_cloud with MIT License 5 votes vote down vote up
/**
 * 查看某个存储区域的所有文件
 *
 * @param bucketName 要查看的存储区域
 * @return
 */
public List<OSSObjectSummary> findObject(String bucketName) {
    if (bucketName == null || bucketName.equals("")) {
        bucketName = bucketName_user;
    }
    ObjectListing objectListing = ossClient.listObjects(bucketName);
    List<OSSObjectSummary> list = objectListing.getObjectSummaries();
    ossClient.shutdown();
    return list;
}
 
Example #8
Source File: AliOSSBlobStore.java    From multiapps-controller with Apache License 2.0 5 votes vote down vote up
private StorageMetadata toStorageMetadata(OSS oss, String container, OSSObjectSummary ossObjectSummary) {
    ObjectMetadata metadata = oss.getObjectMetadata(container, ossObjectSummary.getKey());
    URI url = getPresignedUriForObject(oss, ossObjectSummary);
    return new StorageMetadataImpl(StorageType.BLOB, ossObjectSummary.getKey(), ossObjectSummary.getKey(), defaultLocation.get(),
                                   url, ossObjectSummary.getETag(), ossObjectSummary.getLastModified(),
                                   ossObjectSummary.getLastModified(), metadata.getUserMetadata(), ossObjectSummary.getSize(),
                                   Tier.STANDARD);
}
 
Example #9
Source File: AliOSSBlobStore.java    From multiapps-controller with Apache License 2.0 5 votes vote down vote up
private URI getPresignedUriForObject(OSS oss, OSSObjectSummary ossObjectSummary) {
    Calendar time = Calendar.getInstance();
    time.set(Calendar.HOUR, time.get(Calendar.HOUR) + 1);
    try {
        return oss.generatePresignedUrl(ossObjectSummary.getBucketName(), ossObjectSummary.getKey(), time.getTime())
            .toURI();
    } catch (URISyntaxException e) {
        throw new SLException(e);
    }
}
 
Example #10
Source File: AliOSSBlobStoreTest.java    From multiapps-controller with Apache License 2.0 5 votes vote down vote up
private List<OSSObjectSummary> getObjectSummaries(int count) {
    List<OSSObjectSummary> list = new ArrayList<>();
    for (int i = 0; i < count; i++) {
        OSSObjectSummary ossObjectSummary = new OSSObjectSummary();
        ossObjectSummary.setBucketName(CONTAINER);
        ossObjectSummary.setETag(FILENAME + "-etag-" + i);
        ossObjectSummary.setKey(FILENAME + i);
        ossObjectSummary.setLastModified(new Date());
        ossObjectSummary.setSize(PAYLOAD.length());
        list.add(ossObjectSummary);
    }
    return list;
}
 
Example #11
Source File: OSSNotebookRepo.java    From zeppelin with Apache License 2.0 5 votes vote down vote up
@Override
public Map<String, NoteInfo> list(AuthenticationInfo subject) throws IOException {
  Map<String, NoteInfo> notesInfo = new HashMap<>();
  final int maxKeys = 200;
  String nextMarker = null;
  ObjectListing objectListing = null;
  do {
    objectListing = ossClient.listObjects(
            new ListObjectsRequest(bucketName)
                    .withPrefix(rootFolder + "/")
                    .withMarker(nextMarker)
                    .withMaxKeys(maxKeys));
    List<OSSObjectSummary> sums = objectListing.getObjectSummaries();
    for (OSSObjectSummary s : sums) {
      if (s.getKey().endsWith(".zpln")) {
        try {
          String noteId = getNoteId(s.getKey());
          String notePath = getNotePath(rootFolder, s.getKey());
          notesInfo.put(noteId, new NoteInfo(noteId, notePath));
        } catch (IOException e) {
          LOGGER.warn(e.getMessage());
        }
      } else {
        LOGGER.debug("Skip invalid note file: " + s.getKey());
      }
    }
    nextMarker = objectListing.getNextMarker();
  } while (objectListing.isTruncated());

  return notesInfo;
}
 
Example #12
Source File: OSSNotebookRepo.java    From zeppelin with Apache License 2.0 5 votes vote down vote up
@Override
public void move(String folderPath, String newFolderPath, AuthenticationInfo subject) {
  final int maxKeys = 200;
  String nextMarker = null;
  ObjectListing objectListing = null;
  do {
    objectListing = ossClient.listObjects(
            new ListObjectsRequest(bucketName)
                    .withPrefix(rootFolder + folderPath + "/")
                    .withMarker(nextMarker)
                    .withMaxKeys(maxKeys));
    List<OSSObjectSummary> sums = objectListing.getObjectSummaries();
    for (OSSObjectSummary s : sums) {
      if (s.getKey().endsWith(".zpln")) {
        try {
          String noteId = getNoteId(s.getKey());
          String notePath = getNotePath(rootFolder, s.getKey());
          String newNotePath = newFolderPath + notePath.substring(folderPath.length());
          move(noteId, notePath, newNotePath, subject);
        } catch (IOException e) {
          LOGGER.warn(e.getMessage());
        }
      } else {
        LOGGER.debug("Skip invalid note file: " + s.getKey());
      }
    }
    nextMarker = objectListing.getNextMarker();
  } while (objectListing.isTruncated());

}
 
Example #13
Source File: FileUploadController.java    From code with Apache License 2.0 3 votes vote down vote up
/**
 * @author lastwhisper
 * @desc 查询oss上的所有文件
 * http://localhost:8080/file/list
 * @return List<OSSObjectSummary>
 * @Param
 */
@RequestMapping("file/list")
@ResponseBody
public List<OSSObjectSummary> list()
        throws Exception {
    return this.fileUploadService.list();
}