Java Code Examples for com.aliyun.oss.model.ObjectListing#getNextMarker()

The following examples show how to use com.aliyun.oss.model.ObjectListing#getNextMarker() . 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: 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 8
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());

}