• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java ObjectMetadata类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.aliyun.oss.model.ObjectMetadata的典型用法代码示例。如果您正苦于以下问题:Java ObjectMetadata类的具体用法?Java ObjectMetadata怎么用?Java ObjectMetadata使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ObjectMetadata类属于com.aliyun.oss.model包,在下文中一共展示了ObjectMetadata类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: putObject

import com.aliyun.oss.model.ObjectMetadata; //导入依赖的package包/类
/**
 * 上传Object
 *
 * @param client
 * @param bucketName
 * @param key
 * @param filePath
 * @return
 * @throws FileNotFoundException
 */
public static PutObjectResult putObject(OSSClient client, String bucketName, String key, String filePath) throws FileNotFoundException {

	// 获取指定文件的输入流
	File file = new File(filePath);
	InputStream content = new FileInputStream(file);

	// 创建上传Object的Metadata
	ObjectMetadata meta = new ObjectMetadata();

	// 必须设置ContentLength
	meta.setContentLength(file.length());
	// 用户自定义文件名称
	meta.addUserMetadata("filename", key);

	// 上传Object.
	PutObjectResult result = client.putObject(bucketName, key, content, meta);

	return result;
}
 
开发者ID:funtl,项目名称:framework,代码行数:30,代码来源:ObjectService.java


示例2: putObject

import com.aliyun.oss.model.ObjectMetadata; //导入依赖的package包/类
public static void putObject(String bucketName, File file, String fileName)
		throws IOException {

	// 初始化OSSClient
	OSSClient client = getOSSClient();

	// 获取指定文件的输入流
	// File file = new File(fileRealPath + fileName);
	InputStream content = new FileInputStream(file);

	// 创建上传Object的Metadata
	ObjectMetadata meta = new ObjectMetadata();

	// 必须设置ContentLength
	// meta.setContentLength(file.length());
	meta.setContentEncoding("UTF-8");
	// 上传Object.
	String key = fileName;
	PutObjectResult result = client.putObject(bucketName, key, content,
			meta);
	content.close();
}
 
开发者ID:wkeyuan,项目名称:DWSurvey,代码行数:23,代码来源:AliyunOSS.java


示例3: createEmptyObject

import com.aliyun.oss.model.ObjectMetadata; //导入依赖的package包/类
/**
 * Create empty object with content length is 0L
 *
 * @param bucketName
 * @param objectName
 * @throws ClientException
 * @throws OSSException
 */
private void createEmptyObject(final String bucketName, final String objectName)
        throws ClientException, OSSException {

  final InputStream nullStream = new InputStream() {
    @Override
    public int read() throws IOException {
      return -1;
    }
  };

  final ObjectMetadata om = new ObjectMetadata();
  om.setContentLength(0L);

  PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, objectName, nullStream, om);
  client.putObject(putObjectRequest);
  statistics.incrementWriteOps(1);
}
 
开发者ID:aliyun-beta,项目名称:aliyun-oss-hadoop-fs,代码行数:26,代码来源:OSSFileSystem.java


示例4: uploadFile

import com.aliyun.oss.model.ObjectMetadata; //导入依赖的package包/类
public static String uploadFile(String fileName, String path, boolean img, String contentType) throws OSSException,
		ClientException, FileNotFoundException {
	if (client == null) throw new OSSException("OssKit must init before use");

	File file = new File(path);

	ObjectMetadata objectMeta = new ObjectMetadata();
	objectMeta.setContentLength(file.length());
	if (contentType != null) objectMeta.setContentType(contentType);

	InputStream input = new FileInputStream(file);

	client.putObject(buketName, fileName, input, objectMeta);

	if (img) return getImgUrl(fileName);
	else return getUrl(fileName);
}
 
开发者ID:jayqqaa12,项目名称:jbase,代码行数:18,代码来源:OSSKit.java


示例5: putObject

import com.aliyun.oss.model.ObjectMetadata; //导入依赖的package包/类
@Override
protected UploadResult putObject(MultipartFile file, String path,
		String originalName, String resultName) throws IOException,
		UploadException {
	
	if(ossClient==null){
		throw new UploadException("OSS Client is null.");
	}
	
	ObjectMetadata objectMeta = new ObjectMetadata();
	objectMeta.setContentType(file.getContentType());
	
	InputStream is = file.getInputStream();
	objectMeta.setContentLength(is.available());
	
	UploadResult result = new UploadResult(path, originalName, resultName);
	ossClient.putObject(bucket, result.getFullPath(), is, objectMeta);
	//PutObjectResult ossResult = 
	return result;
}
 
开发者ID:yysoft,项目名称:yy-utils,代码行数:21,代码来源:OssUploader.java


示例6: putObject

import com.aliyun.oss.model.ObjectMetadata; //导入依赖的package包/类
/**
 * 上传文件
 *
 * @param path 文件路径
 * @param file 文件对象
 * @param meta 媒体类型
 */
public static void putObject(String path, File file, ObjectMetadata meta) {
    OSSClient ossClient = newOSSClient();
    try {
        ossClient.putObject(bucketName, path, file, meta);
    } finally {
        ossClient.shutdown();
    }
}
 
开发者ID:tech-microworld,项目名称:maven-cdn-alioss-plugin,代码行数:16,代码来源:AliyunOssUtills.java


示例7: uploadCode

import com.aliyun.oss.model.ObjectMetadata; //导入依赖的package包/类
public String uploadCode(LanguageEnum lang, String code) {
    InputStream is = new ByteArrayInputStream(code.getBytes());
    StringBuilder fileName = new StringBuilder(UUID.randomUUID().toString());
    switch (lang) {
        case JAVA8:
            fileName.append(".java");
            break;
        case C:
            fileName.append(".c");
            break;
        case CPP:
            fileName.append(".cpp");
            break;
        default:
            fileName.append(".py");
            break;
    }
    ObjectMetadata metadata = new ObjectMetadata();
    metadata.setContentType("text/plain");
    String filePath = generateFilePath(fileName.toString());
    try {
        ossClient.putObject(BUCKET, filePath, is, metadata);
        return "/"+filePath;
    } catch (Exception e) {
        return null;
    }
}
 
开发者ID:Eagle-OJ,项目名称:eagle-oj-api,代码行数:28,代码来源:FileUtil.java


示例8: parseToCCSObjectMetadata

import com.aliyun.oss.model.ObjectMetadata; //导入依赖的package包/类
/**
 * OSSObjectMetadata到CCSObjectMetadata
 */
public static CCSObjectMetadata parseToCCSObjectMetadata(ObjectMetadata ossObjectMetadata) {
	CCSObjectMetadata ccsObjectMetadata = new CCSObjectMetadata();
	ccsObjectMetadata.setContentEncoding(ossObjectMetadata.getContentEncoding());
	ccsObjectMetadata.setContentLength(ossObjectMetadata.getContentLength());
	ccsObjectMetadata.setContentMD5(ossObjectMetadata.getContentMD5());
	ccsObjectMetadata.setContentType(ossObjectMetadata.getContentType());
	ccsObjectMetadata.setETag(ossObjectMetadata.getETag());
	ccsObjectMetadata.setLastModified(ossObjectMetadata.getLastModified());
	ccsObjectMetadata.setObjectType(ossObjectMetadata.getObjectType());
	ccsObjectMetadata.setStorgeClass(ossObjectMetadata.getObjectStorageClass().name());
	ccsObjectMetadata.setUserMetaData(ossObjectMetadata.getUserMetadata());
	return ccsObjectMetadata;
}
 
开发者ID:MinsxCloud,项目名称:minsx-ccs,代码行数:17,代码来源:AliyunOSSParseUtil.java


示例9: parseToObjectMetadata

import com.aliyun.oss.model.ObjectMetadata; //导入依赖的package包/类
/**
 * CCSObjectMetadata 到 OSS ObjectMetadata
 */
public static ObjectMetadata parseToObjectMetadata(CCSObjectMetadata ccsObjectMetadata) {
	ObjectMetadata objectMetadata = new ObjectMetadata();
	if (ccsObjectMetadata!=null) {
		objectMetadata.setUserMetadata(ccsObjectMetadata.getUserMetaData());
		objectMetadata.setLastModified(ccsObjectMetadata.getLastModified());
		objectMetadata.setContentType(ccsObjectMetadata.getContentType());
		objectMetadata.setContentMD5(ccsObjectMetadata.getContentMD5());
		objectMetadata.setContentLength(ccsObjectMetadata.getContentLength());
		objectMetadata.setContentEncoding(ccsObjectMetadata.getContentEncoding());
	}
	return objectMetadata;
}
 
开发者ID:MinsxCloud,项目名称:minsx-ccs,代码行数:16,代码来源:AliyunOSSParseUtil.java


示例10: copyFile

import com.aliyun.oss.model.ObjectMetadata; //导入依赖的package包/类
/**
 * Copy an existing file to another place.
 *
 * @param srcKey source object key
 * @param dstKey destination object key
 * @throws IOException
 */
private void copyFile(String srcKey, String dstKey) throws IOException {
  if (LOG.isDebugEnabled()) {
    LOG.debug("copyFile " + srcKey + " -> " + dstKey);
  }

  ObjectMetadata om = client.getObjectMetadata(bucket, srcKey);
  CopyObjectRequest copyObjectRequest = new CopyObjectRequest(bucket, srcKey, bucket, dstKey);
  copyObjectRequest.setNewObjectMetadata(om);
  copyObjectRequest.setProgressListener(new ProgressListener() {
    public void progressChanged(ProgressEvent progressEvent) {
      switch (progressEvent.getEventType()) {
        case TRANSFER_PART_COMPLETED_EVENT:
          statistics.incrementWriteOps(1);
          break;
        default:
          break;
      }
    }
  });
  try {
    client.copyObject(copyObjectRequest);
    statistics.incrementWriteOps(1);
  } catch (OSSException | ClientException e) {
    throw new IOException("Got interrupted, cancelling");
  }
}
 
开发者ID:aliyun-beta,项目名称:aliyun-oss-hadoop-fs,代码行数:34,代码来源:OSSFileSystem.java


示例11: copyObject

import com.aliyun.oss.model.ObjectMetadata; //导入依赖的package包/类
/**
 * Enhanced to auto choose simple or multipart copy via multipart copy threshold.
 *
 * @param copyObjectRequest
 * @return
 * @throws OSSException
 * @throws ClientException
 */
@Override
public CopyObjectResult copyObject(CopyObjectRequest copyObjectRequest)
        throws OSSException, ClientException {

  ObjectMetadata metadata = this.getObjectMetadata(copyObjectRequest.getSourceBucketName(), copyObjectRequest.getSourceKey());
  if (!isMultipartCopy(metadata)) {
    return super.copyObject(copyObjectRequest); //simple copy
  } else {
    return doMultiPartCopy(copyObjectRequest, metadata);  //multi-part copy
  }
}
 
开发者ID:aliyun-beta,项目名称:aliyun-oss-hadoop-fs,代码行数:20,代码来源:SmartOSSClient.java


示例12: testCopyFromLocalFile

import com.aliyun.oss.model.ObjectMetadata; //导入依赖的package包/类
/**
 * Test high performance copyFromLocal.
 *
 * @throws Exception
 */
public void testCopyFromLocalFile() throws Exception {
  final File sampleFile = createSampleFile(1100); //48.83 MB
  fileSystem.copyFromLocalFile(false, true, new Path(sampleFile.getAbsolutePath()), path("test/test-copyFromLocalFile"));

  ObjectMetadata metaData = client.getObjectMetadata("hadoop-intg", "user/shawguo/test/test-copyFromLocalFile");
  assertEquals(sampleFile.length(), metaData.getContentLength());
}
 
开发者ID:aliyun-beta,项目名称:aliyun-oss-hadoop-fs,代码行数:13,代码来源:ExtraOSSAPIsTest.java


示例13: set

import com.aliyun.oss.model.ObjectMetadata; //导入依赖的package包/类
public void set(@Nonnull String bucketName, @Nonnull String folder, @Nonnull String name,
                @Nonnull InputStream inputStream, @Nonnull ObjectMetadata objectMetadata) {
    checkNotNull(bucketName);
    checkNotNull(folder);
    checkNotNull(name);
    checkNotNull(inputStream);
    checkNotNull(objectMetadata);

    String key = formatKey(folder, name);

    ossClient.putObject(bucketName, key, inputStream, objectMetadata);
}
 
开发者ID:srarcbrsent,项目名称:tc,代码行数:13,代码来源:TcAliyunOssService.java


示例14: store

import com.aliyun.oss.model.ObjectMetadata; //导入依赖的package包/类
public ObjectOperation store(File file, ObjectMetadata meta){
	if(!file.exists()){
		throw new BaseException("file is not exists!");
	}
	putObject(new PutObjectRequest(bucketName, key, file, meta));
	return this;
}
 
开发者ID:wayshall,项目名称:onetwo,代码行数:8,代码来源:OssClientWrapper.java


示例15: storeAsJson

import com.aliyun.oss.model.ObjectMetadata; //导入依赖的package包/类
/****
 * 
 * @author wayshall
 * @param object
 * @param contentType example: MediaType.APPLICATION_OCTET_STREAM_VALUE
 * @return
 */
public ObjectOperation storeAsJson(Object object, String contentType){
	String json = JsonMapper.DEFAULT_MAPPER.toJson(object);
	StringReader sr = new StringReader(json);
	ObjectMetadata meta = new ObjectMetadata();
	meta.setContentType(contentType);
	return store(new ReaderInputStream(sr), meta);
}
 
开发者ID:wayshall,项目名称:onetwo,代码行数:15,代码来源:OssClientWrapper.java


示例16: copyFromLocalFile

import com.aliyun.oss.model.ObjectMetadata; //导入依赖的package包/类
/**
 * The src file is on the local disk.  Add it to FS at
 * the given dst name.
 * <p/>
 * This version doesn't need to create a temporary file to calculate the md5.
 * Sadly this doesn't seem to be used by the shell cp :(
 * <p/>
 * delSrc indicates if the source should be removed
 *
 * @param delSrc    whether to delete the src
 * @param overwrite whether to overwrite an existing file
 * @param src       path
 * @param dst       path
 */
@Override
public void copyFromLocalFile(boolean delSrc, boolean overwrite, Path src,
                              Path dst) throws IOException {
  String key = pathToKey(dst);

  if (!overwrite && exists(dst)) {
    throw new IOException(dst + " already exists");
  }
  if (LOG.isDebugEnabled()) {
    LOG.debug("Copying local file from " + src + " to " + dst);
  }

  // Since we have a local file, we don't need to stream into a temporary file
  LocalFileSystem local = getLocal(getConf());
  File srcfile = local.pathToFile(src);

  final ObjectMetadata om = new ObjectMetadata();
  PutObjectRequest putObjectRequest = new PutObjectRequest(bucket, key, srcfile);
  putObjectRequest.setMetadata(om);
  putObjectRequest.setProgressListener(new ProgressListener() {
    public void progressChanged(ProgressEvent progressEvent) {
      switch (progressEvent.getEventType()) {
        case TRANSFER_PART_COMPLETED_EVENT:
          statistics.incrementWriteOps(1);
          break;
        default:
          break;
      }
    }
  });

  try {
    client.putObject(putObjectRequest);
    statistics.incrementWriteOps(1);
  } catch (OSSException | ClientException e) {
    throw new IOException("Got interrupted, cancelling");
  }
  // This will delete unnecessary fake parent directories
  finishedWrite(key);
  if (delSrc) {
    local.delete(src, false);
  }
}
 
开发者ID:aliyun-beta,项目名称:aliyun-oss-hadoop-fs,代码行数:58,代码来源:OSSFileSystem.java


示例17: close

import com.aliyun.oss.model.ObjectMetadata; //导入依赖的package包/类
@Override
public synchronized void close() throws IOException {
  if (closed) {
    return;
  }

  backupStream.close();
  if (LOG.isDebugEnabled()) {
    LOG.debug("OutputStream for key '" + key + "' closed. Now beginning upload");
  }
  try {
    final ObjectMetadata om = new ObjectMetadata();
    PutObjectRequest putObjectRequest = new PutObjectRequest(bucket, key, backupFile);
    putObjectRequest.setMetadata(om);
    putObjectRequest.setProgressListener(new ProgressListener() {
      public void progressChanged(ProgressEvent progressEvent) {
        switch (progressEvent.getEventType()) {
          case TRANSFER_PART_COMPLETED_EVENT:
            statistics.incrementWriteOps(1);
            break;
          default:
            break;
        }
      }
    });

    fs.getOSSClient().putObject(putObjectRequest);

    // This will delete unnecessary fake parent directories
    fs.finishedWrite(key);
  } catch (OSSException | ClientException e) {
    throw new IOException(e);
  } finally {
    if (!backupFile.delete()) {
      LOG.warn("Could not delete temporary oss file: {}", backupFile);
    }
    super.close();
    closed = true;
  }
  if (LOG.isDebugEnabled()) {
    LOG.debug("OutputStream for key '" + key + "' upload complete");
  }
}
 
开发者ID:aliyun-beta,项目名称:aliyun-oss-hadoop-fs,代码行数:44,代码来源:OSSOutputStream.java


示例18: doMultiPartCopy

import com.aliyun.oss.model.ObjectMetadata; //导入依赖的package包/类
private CopyObjectResult doMultiPartCopy(CopyObjectRequest copyObjectRequest, ObjectMetadata metadata) {

    //Claim a new upload id for your target bucket
    InitiateMultipartUploadRequest initiateMultipartUploadRequest =
            new InitiateMultipartUploadRequest(copyObjectRequest.getDestinationBucketName(), copyObjectRequest.getDestinationKey());
    InitiateMultipartUploadResult initiateMultipartUploadResult = this.initiateMultipartUpload(initiateMultipartUploadRequest);
    String uploadId = initiateMultipartUploadResult.getUploadId();

    //Calculate how many parts to be divided
    long optimalPartSize = calculateOptimalPartSizeForCopy(configuration, metadata.getContentLength());
    long objectSize = metadata.getContentLength();
    int totalParts = (int) Math.ceil((double) objectSize / optimalPartSize);

    //Upload multi-parts by copy mode
    System.out.println("Begin to upload multiparts by copy mode to OSS\n");
    List<Future<PartETag>> futures = new ArrayList<Future<PartETag>>();
    for (int i = 0; i < totalParts; i++) {
      long startPos = i * optimalPartSize;
      long curPartSize = (i + 1 == totalParts) ? (objectSize - startPos) : optimalPartSize;

      //Construct UploadPartCopyRequest
      UploadPartCopyRequest uploadPartCopyRequest = new UploadPartCopyRequest(
              copyObjectRequest.getSourceBucketName(), copyObjectRequest.getSourceKey(), copyObjectRequest.getDestinationBucketName(), copyObjectRequest.getDestinationKey());
      uploadPartCopyRequest.setUploadId(uploadId);
      uploadPartCopyRequest.setPartSize(curPartSize);
      uploadPartCopyRequest.setBeginIndex(startPos);
      uploadPartCopyRequest.setPartNumber(i + 1);
      futures.add(threadPoolExecutor.submit(new PartCopyCallable(uploadPartCopyRequest)));
    }

    List<PartETag> partETags = collectPartETags(futures);
    //Verify whether all parts are finished
    if (partETags.size() != totalParts) {
      throw new IllegalStateException("Upload multi-parts fail due to some parts are not finished yet");
    } else {
      LOG.info("Succeed to complete multi-parts copy from object named {} to {}", copyObjectRequest.getSourceKey(), copyObjectRequest.getDestinationKey());
    }

    //Complete to upload multi-parts
    System.out.println("Completing to upload multiparts\n");
    CompleteMultipartUploadRequest completeMultipartUploadRequest = new CompleteMultipartUploadRequest(
            copyObjectRequest.getDestinationBucketName(), copyObjectRequest.getDestinationKey(), uploadId, partETags);
    CompleteMultipartUploadResult completeMultipartUploadResult = this.completeMultipartUpload(completeMultipartUploadRequest);
    CopyObjectResult result = new CopyObjectResult();
    result.setEtag(completeMultipartUploadResult.getETag());
    return result;
  }
 
开发者ID:aliyun-beta,项目名称:aliyun-oss-hadoop-fs,代码行数:48,代码来源:SmartOSSClient.java


示例19: isMultipartCopy

import com.aliyun.oss.model.ObjectMetadata; //导入依赖的package包/类
private boolean isMultipartCopy(ObjectMetadata metadata) {
  return (metadata.getContentLength() > configuration.getMultipartCopyThreshold());
}
 
开发者ID:aliyun-beta,项目名称:aliyun-oss-hadoop-fs,代码行数:4,代码来源:SmartOSSClient.java


示例20: storeWithFileName

import com.aliyun.oss.model.ObjectMetadata; //导入依赖的package包/类
public String storeWithFileName(String bucketName, File file, ObjectMetadata meta){
	String key = FileUtils.getFileName(file.getPath());
	objectOperation(bucketName, key).store(file, meta);
	return getUrl(true, bucketName, key);
}
 
开发者ID:wayshall,项目名称:onetwo,代码行数:6,代码来源:OssClientWrapper.java



注:本文中的com.aliyun.oss.model.ObjectMetadata类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java DotsPageIndicator类代码示例发布时间:2022-05-21
下一篇:
Java EnumeratedAttribute类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap