本文整理汇总了Java中com.aliyun.oss.OSSException类的典型用法代码示例。如果您正苦于以下问题:Java OSSException类的具体用法?Java OSSException怎么用?Java OSSException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
OSSException类属于com.aliyun.oss包,在下文中一共展示了OSSException类的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: uploadImg2Oss
import com.aliyun.oss.OSSException; //导入依赖的package包/类
public String uploadImg2Oss(MultipartFile file) {
if (file.getSize() > 1024 * 1024) {
throw new OSSException("上传图片大小不能超过1M!");
}
String originalFilename = file.getOriginalFilename();
String substring = originalFilename.substring(originalFilename.lastIndexOf(".")).toLowerCase();
Random random = new Random();
String name = random.nextInt(10000) + System.currentTimeMillis() + substring;
try {
InputStream inputStream = file.getInputStream();
this.uploadFile2OSS(inputStream, name);
return name;
} catch (Exception e) {
throw new OSSException("图片上传失败");
}
}
开发者ID:NeilRen,项目名称:NEILREN4J,代码行数:17,代码来源:AliyunOSSClientUtil.java
示例2: createEmptyObject
import com.aliyun.oss.OSSException; //导入依赖的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
示例3: putObject
import com.aliyun.oss.OSSException; //导入依赖的package包/类
/**
* Enhanced to auto choose simple or multipart upload via multipart upload threshold.
*
* @param putObjectRequest
* @return
* @throws OSSException
* @throws ClientException
*/
@Override
public PutObjectResult putObject(PutObjectRequest putObjectRequest)
throws OSSException, ClientException {
if (putObjectRequest.getInputStream() != null) {
return super.putObject(putObjectRequest);
} else if (putObjectRequest.getFile() != null) {
File backupFile = putObjectRequest.getFile();
if (!isMultipartUpload(backupFile)) {
return super.putObject(putObjectRequest); ////simple upload
} else {
return this.doMultiPartUpload(putObjectRequest); //multi-part upload
}
}
return super.putObject(putObjectRequest);
}
开发者ID:aliyun-beta,项目名称:aliyun-oss-hadoop-fs,代码行数:25,代码来源:SmartOSSClient.java
示例4: uploadFile
import com.aliyun.oss.OSSException; //导入依赖的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: test
import com.aliyun.oss.OSSException; //导入依赖的package包/类
@Test
public void test() throws OSSException, ClientException, IOException {
OSSClient client = new OSSClient("oss-cn-hangzhou.aliyuncs.com", "", "", "");
// BucketInfo info = client.getBucketInfo("edrmry");
boolean exists = client.doesBucketExist("edrmry");
System.out.println(exists);
// System.out.println(client.listBuckets().size());
// client.createBucket("dzh1");
PutObjectResult r = client.putObject("edrmry", "dzh1.jpg", new FileInputStream("/Users/dzh/Pictures/8.pic.jpg"));
System.out.println(r.getETag());
OSSObject o = client.getObject("edrmry", "dzh1");
InputStream is = o.getObjectContent();
FileOutputStream fos = new FileOutputStream("/Users/dzh/Pictures/8.pic.2.jpg");
int len = 0;
byte[] buf = new byte[32];
while ((len = is.read(buf)) != -1) {
fos.write(buf, 0, len);
}
fos.flush();
fos.close();
}
开发者ID:dzh,项目名称:jframe,代码行数:23,代码来源:TestOSSService.java
示例6: copyFile
import com.aliyun.oss.OSSException; //导入依赖的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
示例7: deleteUnnecessaryEmptyDirectories
import com.aliyun.oss.OSSException; //导入依赖的package包/类
private void deleteUnnecessaryEmptyDirectories(Path f) throws IOException {
while (true) {
try {
String key = pathToKey(f);
if (key.isEmpty()) {
break;
}
OSSFileStatus status = getFileStatus(f);
if (status.isDirectory() && status.isEmptyDirectory()) {
if (LOG.isDebugEnabled()) {
LOG.debug("Deleting fake directory " + key + "/");
}
client.deleteObject(bucket, key + "/");
statistics.incrementWriteOps(1);
}
} catch (FileNotFoundException | OSSException e) {
throw new IOException("Got interrupted, cancelling");
}
if (f.isRoot()) {
break;
}
f = f.getParent();
}
}
开发者ID:aliyun-beta,项目名称:aliyun-oss-hadoop-fs,代码行数:29,代码来源:OSSFileSystem.java
示例8: createEmptyDirectory
import com.aliyun.oss.OSSException; //导入依赖的package包/类
/**
* Create an empty folder without request body, and the object key must be suffixed with a slash
*
* @param bucketName
* @param objectName
* @throws ClientException
* @throws OSSException
*/
private void createEmptyDirectory(final String bucketName, final String objectName)
throws ClientException, OSSException {
if (!objectName.endsWith("/")) {
createEmptyObject(bucketName, objectName + "/");
} else {
createEmptyObject(bucketName, objectName);
}
}
开发者ID:aliyun-beta,项目名称:aliyun-oss-hadoop-fs,代码行数:17,代码来源:OSSFileSystem.java
示例9: copyObject
import com.aliyun.oss.OSSException; //导入依赖的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
示例10: getImgUrl
import com.aliyun.oss.OSSException; //导入依赖的package包/类
private static String getImgUrl(String fileName) {
if (imgDomainUrl == null) throw new OSSException("OssKit must init set img domain Url");
String url = getUrl(fileName);
if (url != null) url = url.replace(buketName + ".", "").replace(endponit, imgDomainUrl);
if (url != null) url = url.replace(domainUrl, imgDomainUrl);
return url;
}
开发者ID:jayqqaa12,项目名称:jbase,代码行数:10,代码来源:OSSKit.java
示例11: copyFromLocalFile
import com.aliyun.oss.OSSException; //导入依赖的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
示例12: close
import com.aliyun.oss.OSSException; //导入依赖的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
示例13: getClient
import com.aliyun.oss.OSSException; //导入依赖的package包/类
public OSSClient getClient() {
if (client == null) throw new OSSException("OssKit must init before use");
return client;
}
开发者ID:jayqqaa12,项目名称:jbase,代码行数:5,代码来源:OSSKit.java
示例14: downloadFile
import com.aliyun.oss.OSSException; //导入依赖的package包/类
public static void downloadFile(String key, String filename) throws OSSException, ClientException {
if (client == null) throw new OSSException("OssKit must init before use");
client.getObject(new GetObjectRequest(buketName, key), new File(filename));
}
开发者ID:jayqqaa12,项目名称:jbase,代码行数:6,代码来源:OSSKit.java
示例15: deleteFile
import com.aliyun.oss.OSSException; //导入依赖的package包/类
public void deleteFile(String key) {
if (client == null) throw new OSSException("OssKit must init before use");
client.deleteObject(buketName, key);
}
开发者ID:jayqqaa12,项目名称:jbase,代码行数:6,代码来源:OSSKit.java
示例16: getUrl
import com.aliyun.oss.OSSException; //导入依赖的package包/类
/**
* 获取到 url 通过 key
*
* @param fileName
* @return
*/
public static String getUrl(String fileName) {
if (client == null) throw new OSSException("OssKit must init before use");
String url = client.generatePresignedUrl(buketName, fileName, new Date(2020, 1, 1)).toString().split("\\?")[0];
if (domainUrl != null)url= url.replace(buketName + ".", "").replace(endponit, domainUrl);
return url;
}
开发者ID:jayqqaa12,项目名称:jbase,代码行数:16,代码来源:OSSKit.java
注:本文中的com.aliyun.oss.OSSException类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论