use of com.aliyun.oss.ServiceException in project alluxio by Alluxio.
the class OSSOutputStream method close.
/**
* Closes this output stream. When an output stream is closed, the local temporary file is
* uploaded to OSS Service. Once the file is uploaded, the temporary file is deleted.
*/
@Override
public void close() throws IOException {
if (mClosed.getAndSet(true)) {
return;
}
mLocalOutputStream.close();
try (BufferedInputStream in = new BufferedInputStream(new FileInputStream(mFile))) {
ObjectMetadata objMeta = new ObjectMetadata();
objMeta.setContentLength(mFile.length());
if (mHash != null) {
byte[] hashBytes = mHash.digest();
objMeta.setContentMD5(new String(Base64.encodeBase64(hashBytes)));
}
mOssClient.putObject(mBucketName, mKey, in, objMeta);
} catch (ServiceException e) {
LOG.error("Failed to upload {}.", mKey);
throw new IOException(e);
} finally {
// upload or if the upload failed.
if (!mFile.delete()) {
LOG.error("Failed to delete temporary file @ {}", mFile.getPath());
}
}
}
use of com.aliyun.oss.ServiceException in project alluxio by Alluxio.
the class OSSUnderFileSystem method getObjectStatus.
@Override
protected ObjectStatus getObjectStatus(String key) {
try {
ObjectMetadata meta = mClient.getObjectMetadata(mBucketName, key);
if (meta == null) {
return null;
}
Date lastModifiedDate = meta.getLastModified();
Long lastModifiedTime = lastModifiedDate == null ? null : lastModifiedDate.getTime();
return new ObjectStatus(key, meta.getETag(), meta.getContentLength(), lastModifiedTime);
} catch (ServiceException e) {
return null;
}
}
Aggregations