当前位置: 首页>>代码示例>>Java>>正文


Java ObjectMetadata类代码示例

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


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


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