package com.aliyun.oss;
import com.aliyun.oss.ClientConfiguration;
import com.aliyun.oss.ClientException;
import com.aliyun.oss.HttpMethod;
import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSException;
import com.aliyun.oss.common.auth.Credentials;
import com.aliyun.oss.common.auth.CredentialsProvider;
import com.aliyun.oss.common.auth.DefaultCredentialProvider;
import com.aliyun.oss.common.auth.ServiceSignature;
import com.aliyun.oss.common.comm.DefaultServiceClient;
import com.aliyun.oss.common.comm.RequestMessage;
import com.aliyun.oss.common.comm.ResponseMessage;
import com.aliyun.oss.common.comm.ServiceClient;
import com.aliyun.oss.common.comm.TimeoutServiceClient;
import com.aliyun.oss.common.utils.BinaryUtil;
import com.aliyun.oss.common.utils.CodingUtils;
import com.aliyun.oss.common.utils.DateUtil;
import com.aliyun.oss.common.utils.HttpUtil;
import com.aliyun.oss.common.utils.IOUtils;
import com.aliyun.oss.common.utils.LogUtils;
import com.aliyun.oss.internal.CORSOperation;
import com.aliyun.oss.internal.LiveChannelOperation;
import com.aliyun.oss.internal.OSSBucketOperation;
import com.aliyun.oss.internal.OSSDownloadOperation;
import com.aliyun.oss.internal.OSSMultipartOperation;
import com.aliyun.oss.internal.OSSObjectOperation;
import com.aliyun.oss.internal.OSSUdfOperation;
import com.aliyun.oss.internal.OSSUploadOperation;
import com.aliyun.oss.internal.OSSUtils;
import com.aliyun.oss.internal.SignUtils;
import com.aliyun.oss.model.AbortMultipartUploadRequest;
import com.aliyun.oss.model.AccessControlList;
import com.aliyun.oss.model.AddBucketCnameRequest;
import com.aliyun.oss.model.AddBucketReplicationRequest;
import com.aliyun.oss.model.AppendObjectRequest;
import com.aliyun.oss.model.AppendObjectResult;
import com.aliyun.oss.model.Bucket;
import com.aliyun.oss.model.BucketInfo;
import com.aliyun.oss.model.BucketList;
import com.aliyun.oss.model.BucketLoggingResult;
import com.aliyun.oss.model.BucketProcess;
import com.aliyun.oss.model.BucketReferer;
import com.aliyun.oss.model.BucketReplicationProgress;
import com.aliyun.oss.model.BucketStat;
import com.aliyun.oss.model.BucketWebsiteResult;
import com.aliyun.oss.model.CannedAccessControlList;
import com.aliyun.oss.model.CnameConfiguration;
import com.aliyun.oss.model.CompleteMultipartUploadRequest;
import com.aliyun.oss.model.CompleteMultipartUploadResult;
import com.aliyun.oss.model.CopyObjectRequest;
import com.aliyun.oss.model.CopyObjectResult;
import com.aliyun.oss.model.CreateBucketRequest;
import com.aliyun.oss.model.CreateLiveChannelRequest;
import com.aliyun.oss.model.CreateLiveChannelResult;
import com.aliyun.oss.model.CreateSymlinkRequest;
import com.aliyun.oss.model.CreateUdfApplicationRequest;
import com.aliyun.oss.model.CreateUdfRequest;
import com.aliyun.oss.model.DeleteBucketCnameRequest;
import com.aliyun.oss.model.DeleteBucketReplicationRequest;
import com.aliyun.oss.model.DeleteObjectsRequest;
import com.aliyun.oss.model.DeleteObjectsResult;
import com.aliyun.oss.model.DownloadFileRequest;
import com.aliyun.oss.model.DownloadFileResult;
import com.aliyun.oss.model.GeneratePresignedUrlRequest;
import com.aliyun.oss.model.GenerateRtmpUriRequest;
import com.aliyun.oss.model.GenerateVodPlaylistRequest;
import com.aliyun.oss.model.GenericRequest;
import com.aliyun.oss.model.GenericResult;
import com.aliyun.oss.model.GetBucketImageResult;
import com.aliyun.oss.model.GetBucketReplicationProgressRequest;
import com.aliyun.oss.model.GetImageStyleResult;
import com.aliyun.oss.model.GetObjectRequest;
import com.aliyun.oss.model.GetUdfApplicationLogRequest;
import com.aliyun.oss.model.HeadObjectRequest;
import com.aliyun.oss.model.InitiateMultipartUploadRequest;
import com.aliyun.oss.model.InitiateMultipartUploadResult;
import com.aliyun.oss.model.LifecycleRule;
import com.aliyun.oss.model.ListBucketsRequest;
import com.aliyun.oss.model.ListLiveChannelsRequest;
import com.aliyun.oss.model.ListMultipartUploadsRequest;
import com.aliyun.oss.model.ListObjectsRequest;
import com.aliyun.oss.model.ListPartsRequest;
import com.aliyun.oss.model.LiveChannel;
import com.aliyun.oss.model.LiveChannelGenericRequest;
import com.aliyun.oss.model.LiveChannelInfo;
import com.aliyun.oss.model.LiveChannelListing;
import com.aliyun.oss.model.LiveChannelStat;
import com.aliyun.oss.model.LiveChannelStatus;
import com.aliyun.oss.model.LiveRecord;
import com.aliyun.oss.model.MultipartUploadListing;
import com.aliyun.oss.model.OSSObject;
import com.aliyun.oss.model.OSSSymlink;
import com.aliyun.oss.model.ObjectAcl;
import com.aliyun.oss.model.ObjectListing;
import com.aliyun.oss.model.ObjectMetadata;
import com.aliyun.oss.model.OptionsRequest;
import com.aliyun.oss.model.PartListing;
import com.aliyun.oss.model.PolicyConditions;
import com.aliyun.oss.model.ProcessObjectRequest;
import com.aliyun.oss.model.PutBucketImageRequest;
import com.aliyun.oss.model.PutImageStyleRequest;
import com.aliyun.oss.model.PutObjectRequest;
import com.aliyun.oss.model.PutObjectResult;
import com.aliyun.oss.model.ReplicationRule;
import com.aliyun.oss.model.ResizeUdfApplicationRequest;
import com.aliyun.oss.model.RestoreObjectResult;
import com.aliyun.oss.model.SetBucketAclRequest;
import com.aliyun.oss.model.SetBucketCORSRequest;
import com.aliyun.oss.model.SetBucketLifecycleRequest;
import com.aliyun.oss.model.SetBucketLoggingRequest;
import com.aliyun.oss.model.SetBucketProcessRequest;
import com.aliyun.oss.model.SetBucketRefererRequest;
import com.aliyun.oss.model.SetBucketStorageCapacityRequest;
import com.aliyun.oss.model.SetBucketTaggingRequest;
import com.aliyun.oss.model.SetBucketWebsiteRequest;
import com.aliyun.oss.model.SetLiveChannelRequest;
import com.aliyun.oss.model.SetObjectAclRequest;
import com.aliyun.oss.model.SimplifiedObjectMeta;
import com.aliyun.oss.model.Style;
import com.aliyun.oss.model.TagSet;
import com.aliyun.oss.model.UdfApplicationInfo;
import com.aliyun.oss.model.UdfApplicationLog;
import com.aliyun.oss.model.UdfGenericRequest;
import com.aliyun.oss.model.UdfImageInfo;
import com.aliyun.oss.model.UdfInfo;
import com.aliyun.oss.model.UpgradeUdfApplicationRequest;
import com.aliyun.oss.model.UploadFileRequest;
import com.aliyun.oss.model.UploadFileResult;
import com.aliyun.oss.model.UploadPartCopyRequest;
import com.aliyun.oss.model.UploadPartCopyResult;
import com.aliyun.oss.model.UploadPartRequest;
import com.aliyun.oss.model.UploadPartResult;
import com.aliyun.oss.model.UploadUdfImageRequest;
import com.aliyun.oss.model.UserQos;
import com.aliyun.oss.model.SetBucketCORSRequest.CORSRule;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.InetAddress;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.UnknownHostException;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
public class OSSClient implements OSS {
private CredentialsProvider credsProvider;
private URI endpoint;
private ServiceClient serviceClient;
private OSSBucketOperation bucketOperation;
private OSSObjectOperation objectOperation;
private OSSMultipartOperation multipartOperation;
private CORSOperation corsOperation;
private OSSUploadOperation uploadOperation;
private OSSDownloadOperation downloadOperation;
private LiveChannelOperation liveChannelOperation;
private OSSUdfOperation udfOperation;
/** @deprecated */
@Deprecated
public OSSClient(String accessKeyId, String secretAccessKey) {
this("http://oss.aliyuncs.com", (CredentialsProvider)(new DefaultCredentialProvider(accessKeyId, secretAccessKey)));
}
public OSSClient(String endpoint, String accessKeyId, String secretAccessKey) {
this(endpoint, (CredentialsProvider)(new DefaultCredentialProvider(accessKeyId, secretAccessKey)), (ClientConfiguration)null);
}
public OSSClient(String endpoint, String accessKeyId, String secretAccessKey, String securityToken) {
this(endpoint, (CredentialsProvider)(new DefaultCredentialProvider(accessKeyId, secretAccessKey, securityToken)), (ClientConfiguration)null);
}
public OSSClient(String endpoint, String accessKeyId, String secretAccessKey, ClientConfiguration config) {
this(endpoint, (CredentialsProvider)(new DefaultCredentialProvider(accessKeyId, secretAccessKey)), (ClientConfiguration)config);
}
public OSSClient(String endpoint, String accessKeyId, String secretAccessKey, String securityToken, ClientConfiguration config) {
this(endpoint, (CredentialsProvider)(new DefaultCredentialProvider(accessKeyId, secretAccessKey, securityToken)), (ClientConfiguration)config);
}
public OSSClient(String endpoint, CredentialsProvider credsProvider) {
this(endpoint, (CredentialsProvider)credsProvider, (ClientConfiguration)null);
}
public OSSClient(String endpoint, CredentialsProvider credsProvider, ClientConfiguration config) {
this.credsProvider = credsProvider;
config = config == null?new ClientConfiguration():config;
if(config.isRequestTimeoutEnabled()) {
this.serviceClient = new TimeoutServiceClient(config);
} else {
this.serviceClient = new DefaultServiceClient(config);
}
this.initOperations();
this.setEndpoint(endpoint);
}
public synchronized URI getEndpoint() {
return URI.create(this.endpoint.toString());
}
public synchronized void setEndpoint(String endpoint) {
URI uri = this.toURI(endpoint);
this.endpoint = uri;
if(this.isIpOrLocalhost(uri)) {
this.serviceClient.getClientConfiguration().setSLDEnabled(true);
}
this.bucketOperation.setEndpoint(uri);
this.objectOperation.setEndpoint(uri);
this.multipartOperation.setEndpoint(uri);
this.corsOperation.setEndpoint(uri);
this.liveChannelOperation.setEndpoint(uri);
this.udfOperation.setEndpoint(uri);
}
private boolean isIpOrLocalhost(URI uri) {
if(uri.getHost().equals("localhost")) {
return true;
} else {
InetAddress ia;
try {
ia = InetAddress.getByName(uri.getHost());
} catch (UnknownHostException var4) {
return false;
}
return ia.getHostName().equals(ia.getHostAddress());
}
}
private URI toURI(String endpoint) throws IllegalArgumentException {
if(!endpoint.contains("://")) {
ClientConfiguration e = this.serviceClient.getClientConfiguration();
endpoint = e.getProtocol().toString() + "://" + endpoint;
}
try {
return new URI(endpoint);
} catch (URISyntaxException var3) {
throw new IllegalArgumentException(var3);
}
}
private void initOperations() {
this.bucketOperation = new OSSBucketOperation(this.serviceClient, this.credsProvider);
this.objectOperation = new OSSObjectOperation(this.serviceClient, this.credsProvider);
this.multipartOperation = new OSSMultipartOperation(this.serviceClient, this.credsProvider);
this.corsOperation = new CORSOperation(this.serviceClient, this.credsProvider);
this.uploadOperation = new OSSUploadOperation(this.multipartOperation);
this.downloadOperation = new OSSDownloadOperation(this.objectOperation);
this.liveChannelOperation = new LiveChannelOperation(this.serviceClient, this.credsProvider);
this.udfOperation = new OSSUdfOperation(this.serviceClient, this.credsProvider);
}
public void switchCredentials(Credentials creds) {
if(creds == null) {
throw new IllegalArgumentException("creds should not be null.");
} else {
this.credsProvider.setCredentials(creds);
}
}
public CredentialsProvider getCredentialsProvider() {
return this.credsProvider;
}
public ClientConfiguration getClientConfiguration() {
return this.serviceClient.getClientConfiguration();
}
public Bucket createBucket(String bucketName) throws OSSException, ClientException {
return this.createBucket(new CreateBucketRequest(bucketName));
}
public Bucket createBucket(CreateBucketRequest createBucketRequest) throws OSSException, ClientException {
return this.bucketOperation.createBucket(createBucketRequest);
}
public void deleteBucket(String bucketName) throws OSSException, ClientException {
this.deleteBucket(new GenericRequest(bucketName));
}
public void deleteBucket(GenericRequest genericRequest) throws OSSException, ClientException {
this.bucketOperation.deleteBucket(genericRequest);
}
public List<Bucket> listBuckets() throws OSSException, ClientException {
return this.bucketOperation.listBuckets();
}
public BucketList listBuckets(ListBucketsRequest listBucketsRequest) throws OSSException, ClientException {
return this.bucketOperation.listBuckets(listBucketsRequest);
}
public BucketList listBuckets(String prefix, String marker, Integer maxKeys) throws OSSException, ClientException {
return this.bucketOperation.listBuckets(new ListBucketsRequest(prefix, marker, maxKeys));
}
public void setBucketAcl(String bucketName, CannedAccessControlList cannedACL) throws OSSException, ClientException {
this.setBucketAcl(new SetBucketAclRequest(bucketName, cannedACL));
}
public void setBucketAcl(SetBucketAclRequest setBucketAclRequest) throws OSSException, ClientException {
this.bucketOperation.setBucketAcl(setBucketAclRequest);
}
public AccessControlList getBucketAcl(String bucketName) throws OSSException, ClientException {
return this.getBucketAcl(new GenericRequest(bucketName));
}
public AccessControlList getBucketAcl(GenericRequest genericRequest) throws OSSException, ClientException {
return this.bucketOperation.getBucketAcl(genericRequest);
}
public void setBucketReferer(String bucketName, BucketReferer referer) throws OSSException, ClientException {
this.setBucketReferer(new SetBucketRefererRequest(bucketName, referer));
}
public void setBucketReferer(SetBucketRefererRequest setBucketRefererRequest) throws OSSException, ClientException {
this.bucketOperation.setBucketReferer(setBucketRefererRequest);
}
public BucketReferer getBucketReferer(String bucketName) throws OSSException, ClientException {
return this.getBucketReferer(new GenericRequest(bucketName));
}
public BucketReferer getBucketReferer(GenericRequest genericRequest) throws OSSException, ClientException {
return this.bucketOperation.getBucketReferer(genericRequest);
}
public String getBucketLocation(String bucketName) throws OSSException, ClientException {
return this.getBucketLocation(new GenericRequest(bucketName));
}
public String getBucketLocation(GenericRequest genericRequest) throws OSSException, ClientException {
return this.bucketOperation.getBucketLocation(genericRequest);
}
public boolean doesBucketExist(String bucketName) throws OSSException, ClientException {
return this.doesBucketExist(new GenericRequest(bucketName));
}
public boolean doesBucketExist(GenericRequest genericRequest) throws OSSException, ClientException {
return this.bucketOperation.doesBucketExists(genericRequest);
}
/** @deprecated */
@Deprecated
public boolean isBucketExist(String bucketName) throws OSSException, ClientException {
return this.doesBucketExist(bucketName);
}
public ObjectListing listObjects(String bucketName) throws OSSException, ClientException {
return this.listObjects(new ListObjectsRequest(bucketName, (String)null, (String)null, (String)null, (Integer)null));
}
public ObjectListing listObjects(String bucketName, String prefix) throws OSSException, ClientException {
return this.listObjects(new ListObjectsRequest(bucketName, prefix, (String)null, (String)null, (Integer)null));
}
public ObjectListing listObjects(ListObjectsRequest listObjectsRequest) throws OSSException, ClientException {
return this.bucketOperation.listObjects(listObjectsRequest);
}
public PutObjectResult putObject(String bucketName, String key, InputStream input) throws OSSException, ClientException {
return this.putObject(bucketName, key, (InputStream)input, (ObjectMetadata)null);
}
public PutObjectResult putObject(String bucketName, String key, InputStream input, ObjectMetadata metadata) throws OSSException, ClientException {
return this.putObject(new PutObjectRequest(bucketName, key, input, metadata));
}
public PutObjectResult putObject(String bucketName, String key, File file, ObjectMetadata metadata) throws OSSException, ClientException {
return this.putObject(new PutObjectRequest(bucketName, key, file, metadata));
}
public PutObjectResult putObject(String bucketName, String key, File file) throws OSSException, ClientException {
return this.putObject(bucketName, key, (File)file, (ObjectMetadata)null);
}
public PutObjectResult putObject(PutObjectRequest putObjectRequest) throws OSSException, ClientException {
return this.objectOperation.putObject(putObjectRequest);
}
public PutObjectResult putObject(URL signedUrl, String filePath, Map<String, String> requestHeaders) throws OSSException, ClientException {
return this.putObject(signedUrl, filePath, requestHeaders, false);
}
public PutObjectResult putObject(URL signedUrl, String filePath, Map<String, String> requestHeaders, boolean useChunkEncoding) throws OSSException, ClientException {
FileInputStream requestContent = null;
PutObjectResult var9;
try {
File e = new File(filePath);
if(!IOUtils.checkFile(e)) {
throw new IllegalArgumentException("Illegal file path: " + filePath);
}
long fileSize = e.length();
requestContent = new FileInputStream(e);
var9 = this.putObject(signedUrl, requestContent, fileSize, requestHeaders, useChunkEncoding);
} catch (FileNotFoundException var18) {
throw new ClientException(var18);
} finally {
if(requestContent != null) {
try {
requestContent.close();
} catch (IOException var17) {
;
}
}
}
return var9;
}
public PutObjectResult putObject(URL signedUrl, InputStream requestContent, long contentLength, Map<String, String> requestHeaders) throws OSSException, ClientException {
return this.putObject(signedUrl, requestContent, contentLength, requestHeaders, false);
}
public PutObjectResult putObject(URL signedUrl, InputStream requestContent, long contentLength, Map<String, String> requestHeaders, boolean useChunkEncoding) throws OSSException, ClientException {
return this.objectOperation.putObject(signedUrl, requestContent, contentLength, requestHeaders, useChunkEncoding);
}
public CopyObjectResult copyObject(String sourceBucketName, String sourceKey, String destinationBucketName, String destinationKey) throws OSSException, ClientException {
return this.copyObject(new CopyObjectRequest(sourceBucketName, sourceKey, destinationBucketName, destinationKey));
}
public CopyObjectResult copyObject(CopyObjectRequest copyObjectRequest) throws OSSException, ClientException {
return this.objectOperation.copyObject(copyObjectRequest);
}
public OSSObject getObject(String bucketName, String key) throws OSSException, ClientException {
return this.getObject(new GetObjectRequest(bucketName, key));
}
public ObjectMetadata getObject(GetObjectRequest getObjectRequest, File file) throws OSSException, ClientException {
return this.objectOperation.getObject(getObjectRequest, file);
}
public OSSObject getObject(GetObjectRequest getObjectRequest) throws OSSException, ClientException {
return this.objectOperation.getObject(getObjectRequest);
}
public OSSObject getObject(URL signedUrl, Map<String, String> requestHeaders) throws OSSException, ClientException {
GetObjectRequest getObjectRequest = new GetObjectRequest(signedUrl, requestHeaders);
return this.objectOperation.getObject(getObjectRequest);
}
public SimplifiedObjectMeta getSimplifiedObjectMeta(String bucketName, String key) throws OSSException, ClientException {
return this.getSimplifiedObjectMeta(new GenericRequest(bucketName, key));
}
public SimplifiedObjectMeta getSimplifiedObjectMeta(GenericRequest genericRequest) throws OSSException, ClientException {
return this.objectOperation.getSimplifiedObjectMeta(genericRequest);
}
public ObjectMetadata getObjectMetadata(String bucketName, String key) throws OSSException, ClientException {
return this.getObjectMetadata(new GenericRequest(bucketName, key));
}
public ObjectMetadata getObjectMetadata(GenericRequest genericRequest) throws OSSException, ClientException {
return this.objectOperation.getObjectMetadata(genericRequest);
}
public AppendObjectResult appendObject(AppendObjectRequest appendObjectRequest) throws OSSException, ClientException {
return this.objectOperation.appendObject(appendObjectRequest);
}
public void deleteObject(String bucketName, String key) throws OSSException, ClientException {
this.deleteObject(new GenericRequest(bucketName, key));
}
public void deleteObject(GenericRequest genericRequest) throws OSSException, ClientException {
this.objectOperation.deleteObject(genericRequest);
}
public DeleteObjectsResult deleteObjects(DeleteObjectsRequest deleteObjectsRequest) throws OSSException, ClientException {
return this.objectOperation.deleteObjects(deleteObjectsRequest);
}
public boolean doesObjectExist(String bucketName, String key) throws OSSException, ClientException {
return this.doesObjectExist(new GenericRequest(bucketName, key));
}
public boolean doesObjectExist(String bucketName, String key, boolean isOnlyInOSS) {
return isOnlyInOSS?this.doesObjectExist(bucketName, key):this.objectOperation.doesObjectExistWithRedirect(bucketName, key);
}
/** @deprecated */
@Deprecated
public boolean doesObjectExist(HeadObjectRequest headObjectRequest) throws OSSException, ClientException {
return this.doesObjectExist(new GenericRequest(headObjectRequest.getBucketName(), headObjectRequest.getKey()));
}
public boolean doesObjectExist(GenericRequest genericRequest) throws OSSException, ClientException {
return this.objectOperation.doesObjectExist(genericRequest);
}
public void setObjectAcl(String bucketName, String key, CannedAccessControlList cannedACL) throws OSSException, ClientException {
this.setObjectAcl(new SetObjectAclRequest(bucketName, key, cannedACL));
}
public void setObjectAcl(SetObjectAclRequest setObjectAclRequest) throws OSSException, ClientException {
this.objectOperation.setObjectAcl(setObjectAclRequest);
}
public ObjectAcl getObjectAcl(String bucketName, String key) throws OSSException, ClientException {
return this.getObjectAcl(new GenericRequest(bucketName, key));
}
public ObjectAcl getObjectAcl(GenericRequest genericRequest) throws OSSException, ClientException {
return this.objectOperation.getObjectAcl(genericRequest);
}
public RestoreObjectResult restoreObject(String bucketName, String key) throws OSSException, ClientException {
return this.restoreObject(new GenericRequest(bucketName, key));
}
public RestoreObjectResult restoreObject(GenericRequest genericRequest) throws OSSException, ClientException {
return this.objectOperation.restoreObject(genericRequest);
}
public URL generatePresignedUrl(String bucketName, String key, Date expiration) throws ClientException {
return this.generatePresignedUrl(bucketName, key, expiration, HttpMethod.GET);
}
public URL generatePresignedUrl(String bucketName, String key, Date expiration, HttpMethod method) throws ClientException {
GeneratePresignedUrlRequest request = new GeneratePresignedUrlRequest(bucketName, key);
request.setExpiration(expiration);
request.setMethod(method);
return this.generatePresignedUrl(request);
}
public URL generatePresignedUrl(GeneratePresignedUrlRequest request) throws ClientException {
CodingUtils.assertParameterNotNull(request, "request");
String bucketName = request.getBucketName();
if(request.getBucketName() == null) {
throw new IllegalArgumentException(OSSUtils.OSS_RESOURCE_MANAGER.getString("MustSetBucketName"));
} else {
OSSUtils.ensureBucketNameValid(request.getBucketName());
if(request.getExpiration() == null) {
throw new IllegalArgumentException(OSSUtils.OSS_RESOURCE_MANAGER.getString("MustSetExpiration"));
} else {
Credentials currentCreds = this.credsProvider.getCredentials();
String accessId = currentCreds.getAccessKeyId();
String accessKey = currentCreds.getSecretAccessKey();
boolean useSecurityToken = currentCreds.useSecurityToken();
HttpMethod method = request.getMethod() != null?request.getMethod():HttpMethod.GET;
String expires = String.valueOf(request.getExpiration().getTime() / 1000L);
String key = request.getKey();
ClientConfiguration config = this.serviceClient.getClientConfiguration();
String resourcePath = OSSUtils.determineResourcePath(bucketName, key, config.isSLDEnabled());
RequestMessage requestMessage = new RequestMessage();
requestMessage.setEndpoint(OSSUtils.determineFinalEndpoint(this.endpoint, bucketName, config));
requestMessage.setMethod(method);
requestMessage.setResourcePath(resourcePath);
requestMessage.setHeaders(request.getHeaders());
requestMessage.addHeader("Date", expires);
if(request.getContentType() != null && !request.getContentType().trim().equals("")) {
requestMessage.addHeader("Content-Type", request.getContentType());
}
if(request.getContentMD5() != null && request.getContentMD5().trim().equals("")) {
requestMessage.addHeader("Content-MD5", request.getContentMD5());
}
Iterator responseHeaderParams = request.getUserMetadata().entrySet().iterator();
while(responseHeaderParams.hasNext()) {
Entry canonicalResource = (Entry)responseHeaderParams.next();
requestMessage.addHeader("x-oss-meta-" + (String)canonicalResource.getKey(), (String)canonicalResource.getValue());
}
HashMap responseHeaderParams1 = new HashMap();
OSSUtils.populateResponseHeaderParameters(responseHeaderParams1, request.getResponseHeaders());
if(responseHeaderParams1.size() > 0) {
requestMessage.setParameters(responseHeaderParams1);
}
if(request.getQueryParameter() != null && request.getQueryParameter().size() > 0) {
Iterator canonicalResource1 = request.getQueryParameter().entrySet().iterator();
while(canonicalResource1.hasNext()) {
Entry canonicalString = (Entry)canonicalResource1.next();
requestMessage.addParameter((String)canonicalString.getKey(), (String)canonicalString.getValue());
}
}
if(request.getProcess() != null && !request.getProcess().trim().equals("")) {
requestMessage.addParameter("x-oss-process", request.getProcess());
}
if(useSecurityToken) {
requestMessage.addParameter("security-token", currentCreds.getSecurityToken());
}
String canonicalResource2 = "/" + (bucketName != null?bucketName:"") + (key != null?"/" + key:"");
String canonicalString1 = SignUtils.buildCanonicalString(method.toString(), canonicalResource2, requestMessage, expires);
String signature = ServiceSignature.create().computeSignature(accessKey, canonicalString1);
LinkedHashMap params = new LinkedHashMap();
params.put("Expires", expires);
params.put("OSSAccessKeyId", accessId);
params.put("Signature", signature);
params.putAll(requestMessage.getParameters());
String queryString = HttpUtil.paramToQueryString(params, "utf-8");
String url = requestMessage.getEndpoint().toString();
if(!url.endsWith("/")) {
url = url + "/";
}
url = url + resourcePath + "?" + queryString;
try {
return new URL(url);
} catch (MalformedURLException var21) {
throw new ClientException(var21);
}
}
}
}
public void abortMultipartUpload(AbortMultipartUploadRequest request) throws OSSException, ClientException {
this.multipartOperation.abortMultipartUpload(request);
}
public CompleteMultipartUploadResult completeMultipartUpload(CompleteMultipartUploadRequest request) throws OSSException, ClientException {
return this.multipartOperation.completeMultipartUpload(request);
}
public InitiateMultipartUploadResult initiateMultipartUpload(InitiateMultipartUploadRequest request) throws OSSException, ClientException {
return this.multipartOperation.initiateMultipartUpload(request);
}
public MultipartUploadListing listMultipartUploads(ListMultipartUploadsRequest request) throws OSSException, ClientException {
return this.multipartOperation.listMultipartUploads(request);
}
public PartListing listParts(ListPartsRequest request) throws OSSException, ClientException {
return this.multipartOperation.listParts(request);
}
public UploadPartResult uploadPart(UploadPartRequest request) throws OSSException, ClientException {
return this.multipartOperation.uploadPart(request);
}
public UploadPartCopyResult uploadPartCopy(UploadPartCopyRequest request) throws OSSException, ClientException {
return this.multipartOperation.uploadPartCopy(request);
}
public void setBucketCORS(SetBucketCORSRequest request) throws OSSException, ClientException {
this.corsOperation.setBucketCORS(request);
}
public List<CORSRule> getBucketCORSRules(String bucketName) throws OSSException, ClientException {
return this.getBucketCORSRules(new GenericRequest(bucketName));
}
public List<CORSRule> getBucketCORSRules(GenericRequest genericRequest) throws OSSException, ClientException {
return this.corsOperation.getBucketCORSRules(genericRequest);
}
public void deleteBucketCORSRules(String bucketName) throws OSSException, ClientException {
this.deleteBucketCORSRules(new GenericRequest(bucketName));
}
public void deleteBucketCORSRules(GenericRequest genericRequest) throws OSSException, ClientException {
this.corsOperation.deleteBucketCORS(genericRequest);
}
public ResponseMessage optionsObject(OptionsRequest request) throws OSSException, ClientException {
return this.corsOperation.optionsObject(request);
}
public void setBucketLogging(SetBucketLoggingRequest request) throws OSSException, ClientException {
this.bucketOperation.setBucketLogging(request);
}
public BucketLoggingResult getBucketLogging(String bucketName) throws OSSException, ClientException {
return this.getBucketLogging(new GenericRequest(bucketName));
}
public BucketLoggingResult getBucketLogging(GenericRequest genericRequest) throws OSSException, ClientException {
return this.bucketOperation.getBucketLogging(genericRequest);
}
public void deleteBucketLogging(String bucketName) throws OSSException, ClientException {
this.deleteBucketLogging(new GenericRequest(bucketName));
}
public void deleteBucketLogging(GenericRequest genericRequest) throws OSSException, ClientException {
this.bucketOperation.deleteBucketLogging(genericRequest);
}
public void putBucketImage(PutBucketImageRequest request) throws OSSException, ClientException {
this.bucketOperation.putBucketImage(request);
}
public GetBucketImageResult getBucketImage(String bucketName) throws OSSException, ClientException {
return this.bucketOperation.getBucketImage(bucketName, new GenericRequest());
}
public GetBucketImageResult getBucketImage(String bucketName, GenericRequest genericRequest) throws OSSException, ClientException {
return this.bucketOperation.getBucketImage(bucketName, genericRequest);
}
public void deleteBucketImage(String bucketName) throws OSSException, ClientException {
this.bucketOperation.deleteBucketImage(bucketName, new GenericRequest());
}
public void deleteBucketImage(String bucketName, GenericRequest genericRequest) throws OSSException, ClientException {
this.bucketOperation.deleteBucketImage(bucketName, genericRequest);
}
public void putImageStyle(PutImageStyleRequest putImageStyleRequest) throws OSSException, ClientException {
this.bucketOperation.putImageStyle(putImageStyleRequest);
}
public void deleteImageStyle(String bucketName, String styleName) throws OSSException, ClientException {
this.bucketOperation.deleteImageStyle(bucketName, styleName, new GenericRequest());
}
public void deleteImageStyle(String bucketName, String styleName, GenericRequest genericRequest) throws OSSException, ClientException {
this.bucketOperation.deleteImageStyle(bucketName, styleName, genericRequest);
}
public GetImageStyleResult getImageStyle(String bucketName, String styleName) throws OSSException, ClientException {
return this.bucketOperation.getImageStyle(bucketName, styleName, new GenericRequest());
}
public GetImageStyleResult getImageStyle(String bucketName, String styleName, GenericRequest genericRequest) throws OSSException, ClientException {
return this.bucketOperation.getImageStyle(bucketName, styleName, genericRequest);
}
public List<Style> listImageStyle(String bucketName) throws OSSException, ClientException {
return this.bucketOperation.listImageStyle(bucketName, new GenericRequest());
}
public List<Style> listImageStyle(String bucketName, GenericRequest genericRequest) throws OSSException, ClientException {
return this.bucketOperation.listImageStyle(bucketName, genericRequest);
}
public void setBucketProcess(SetBucketProcessRequest setBucketProcessRequest) throws OSSException, ClientException {
this.bucketOperation.setBucketProcess(setBucketProcessRequest);
}
public BucketProcess getBucketProcess(String bucketName) throws OSSException, ClientException {
return this.getBucketProcess(new GenericRequest(bucketName));
}
public BucketProcess getBucketProcess(GenericRequest genericRequest) throws OSSException, ClientException {
return this.bucketOperation.getBucketProcess(genericRequest);
}
public void setBucketWebsite(SetBucketWebsiteRequest setBucketWebSiteRequest) throws OSSException, ClientException {
this.bucketOperation.setBucketWebsite(setBucketWebSiteRequest);
}
public BucketWebsiteResult getBucketWebsite(String bucketName) throws OSSException, ClientException {
return this.getBucketWebsite(new GenericRequest(bucketName));
}
public BucketWebsiteResult getBucketWebsite(GenericRequest genericRequest) throws OSSException, ClientException {
return this.bucketOperation.getBucketWebsite(genericRequest);
}
public void deleteBucketWebsite(String bucketName) throws OSSException, ClientException {
this.deleteBucketWebsite(new GenericRequest(bucketName));
}
public void deleteBucketWebsite(GenericRequest genericRequest) throws OSSException, ClientException {
this.bucketOperation.deleteBucketWebsite(genericRequest);
}
public String generatePostPolicy(Date expiration, PolicyConditions conds) {
String formatedExpiration = DateUtil.formatIso8601Date(expiration);
String jsonizedExpiration = String.format("\"expiration\":\"%s\"", new Object[]{formatedExpiration});
String jsonizedConds = conds.jsonize();
StringBuilder postPolicy = new StringBuilder();
postPolicy.append(String.format("{%s,%s}", new Object[]{jsonizedExpiration, jsonizedConds}));
return postPolicy.toString();
}
public String calculatePostSignature(String postPolicy) throws ClientException {
try {
byte[] ex = postPolicy.getBytes("utf-8");
String encPolicy = BinaryUtil.toBase64String(ex);
return ServiceSignature.create().computeSignature(this.credsProvider.getCredentials().getSecretAccessKey(), encPolicy);
} catch (UnsupportedEncodingException var4) {
throw new ClientException("Unsupported charset: " + var4.getMessage());
}
}
public void setBucketLifecycle(SetBucketLifecycleRequest setBucketLifecycleRequest) throws OSSException, ClientException {
this.bucketOperation.setBucketLifecycle(setBucketLifecycleRequest);
}
public List<LifecycleRule> getBucketLifecycle(String bucketName) throws OSSException, ClientException {
return this.getBucketLifecycle(new GenericRequest(bucketName));
}
public List<LifecycleRule> getBucketLifecycle(GenericRequest genericRequest) throws OSSException, ClientException {
return this.bucketOperation.getBucketLifecycle(genericRequest);
}
public void deleteBucketLifecycle(String bucketName) throws OSSException, ClientException {
this.deleteBucketLifecycle(new GenericRequest(bucketName));
}
public void deleteBucketLifecycle(GenericRequest genericRequest) throws OSSException, ClientException {
this.bucketOperation.deleteBucketLifecycle(genericRequest);
}
public void setBucketTagging(String bucketName, Map<String, String> tags) throws OSSException, ClientException {
this.setBucketTagging(new SetBucketTaggingRequest(bucketName, tags));
}
public void setBucketTagging(String bucketName, TagSet tagSet) throws OSSException, ClientException {
this.setBucketTagging(new SetBucketTaggingRequest(bucketName, tagSet));
}
public void setBucketTagging(SetBucketTaggingRequest setBucketTaggingRequest) throws OSSException, ClientException {
this.bucketOperation.setBucketTagging(setBucketTaggingRequest);
}
public TagSet getBucketTagging(String bucketName) throws OSSException, ClientException {
return this.getBucketTagging(new GenericRequest(bucketName));
}
public TagSet getBucketTagging(GenericRequest genericRequest) throws OSSException, ClientException {
return this.bucketOperation.getBucketTagging(genericRequest);
}
public void deleteBucketTagging(String bucketName) throws OSSException, ClientException {
this.deleteBucketTagging(new GenericRequest(bucketName));
}
public void deleteBucketTagging(GenericRequest genericRequest) throws OSSException, ClientException {
this.bucketOperation.deleteBucketTagging(genericRequest);
}
public void addBucketReplication(AddBucketReplicationRequest addBucketReplicationRequest) throws OSSException, ClientException {
this.bucketOperation.addBucketReplication(addBucketReplicationRequest);
}
public List<ReplicationRule> getBucketReplication(String bucketName) throws OSSException, ClientException {
return this.getBucketReplication(new GenericRequest(bucketName));
}
public List<ReplicationRule> getBucketReplication(GenericRequest genericRequest) throws OSSException, ClientException {
return this.bucketOperation.getBucketReplication(genericRequest);
}
public void deleteBucketReplication(String bucketName, String replicationRuleID) throws OSSException, ClientException {
this.deleteBucketReplication(new DeleteBucketReplicationRequest(bucketName, replicationRuleID));
}
public void deleteBucketReplication(DeleteBucketReplicationRequest deleteBucketReplicationRequest) throws OSSException, ClientException {
this.bucketOperation.deleteBucketReplication(deleteBucketReplicationRequest);
}
public BucketReplicationProgress getBucketReplicationProgress(String bucketName, String replicationRuleID) throws OSSException, ClientException {
return this.getBucketReplicationProgress(new GetBucketReplicationProgressRequest(bucketName, replicationRuleID));
}
public BucketReplicationProgress getBucketReplicationProgress(GetBucketReplicationProgressRequest getBucketReplicationProgressRequest) throws OSSException, ClientException {
return this.bucketOperation.getBucketReplicationProgress(getBucketReplicationProgressRequest);
}
public List<String> getBucketReplicationLocation(String bucketName) throws OSSException, ClientException {
return this.getBucketReplicationLocation(new GenericRequest(bucketName));
}
public List<String> getBucketReplicationLocation(GenericRequest genericRequest) throws OSSException, ClientException {
return this.bucketOperation.getBucketReplicationLocation(genericRequest);
}
public void addBucketCname(AddBucketCnameRequest addBucketCnameRequest) throws OSSException, ClientException {
this.bucketOperation.addBucketCname(addBucketCnameRequest);
}
public List<CnameConfiguration> getBucketCname(String bucketName) throws OSSException, ClientException {
return this.getBucketCname(new GenericRequest(bucketName));
}
public List<CnameConfiguration> getBucketCname(GenericRequest genericRequest) throws OSSException, ClientException {
return this.bucketOperation.getBucketCname(genericRequest);
}
public void deleteBucketCname(String bucketName, String domain) throws OSSException, ClientException {
this.deleteBucketCname(new DeleteBucketCnameRequest(bucketName, domain));
}
public void deleteBucketCname(DeleteBucketCnameRequest deleteBucketCnameRequest) throws OSSException, ClientException {
this.bucketOperation.deleteBucketCname(deleteBucketCnameRequest);
}
public BucketInfo getBucketInfo(String bucketName) throws OSSException, ClientException {
return this.getBucketInfo(new GenericRequest(bucketName));
}
public BucketInfo getBucketInfo(GenericRequest genericRequest) throws OSSException, ClientException {
return this.bucketOperation.getBucketInfo(genericRequest);
}
public BucketStat getBucketStat(String bucketName) throws OSSException, ClientException {
return this.getBucketStat(new GenericRequest(bucketName));
}
public BucketStat getBucketStat(GenericRequest genericRequest) throws OSSException, ClientException {
return this.bucketOperation.getBucketStat(genericRequest);
}
public void setBucketStorageCapacity(String bucketName, UserQos userQos) throws OSSException, ClientException {
this.setBucketStorageCapacity((new SetBucketStorageCapacityRequest(bucketName)).withUserQos(userQos));
}
public void setBucketStorageCapacity(SetBucketStorageCapacityRequest setBucketStorageCapacityRequest) throws OSSException, ClientException {
this.bucketOperation.setBucketStorageCapacity(setBucketStorageCapacityRequest);
}
public UserQos getBucketStorageCapacity(String bucketName) throws OSSException, ClientException {
return this.getBucketStorageCapacity(new GenericRequest(bucketName));
}
public UserQos getBucketStorageCapacity(GenericRequest genericRequest) throws OSSException, ClientException {
return this.bucketOperation.getBucketStorageCapacity(genericRequest);
}
public UploadFileResult uploadFile(UploadFileRequest uploadFileRequest) throws Throwable {
return this.uploadOperation.uploadFile(uploadFileRequest);
}
public DownloadFileResult downloadFile(DownloadFileRequest downloadFileRequest) throws Throwable {
return this.downloadOperation.downloadFile(downloadFileRequest);
}
public CreateLiveChannelResult createLiveChannel(CreateLiveChannelRequest createLiveChannelRequest) throws OSSException, ClientException {
return this.liveChannelOperation.createLiveChannel(createLiveChannelRequest);
}
public void setLiveChannelStatus(String bucketName, String liveChannel, LiveChannelStatus status) throws OSSException, ClientException {
this.setLiveChannelStatus(new SetLiveChannelRequest(bucketName, liveChannel, status));
}
public void setLiveChannelStatus(SetLiveChannelRequest setLiveChannelRequest) throws OSSException, ClientException {
this.liveChannelOperation.setLiveChannelStatus(setLiveChannelRequest);
}
public LiveChannelInfo getLiveChannelInfo(String bucketName, String liveChannel) throws OSSException, ClientException {
return this.getLiveChannelInfo(new LiveChannelGenericRequest(bucketName, liveChannel));
}
public LiveChannelInfo getLiveChannelInfo(LiveChannelGenericRequest liveChannelGenericRequest) throws OSSException, ClientException {
return this.liveChannelOperation.getLiveChannelInfo(liveChannelGenericRequest);
}
public LiveChannelStat getLiveChannelStat(String bucketName, String liveChannel) throws OSSException, ClientException {
return this.getLiveChannelStat(new LiveChannelGenericRequest(bucketName, liveChannel));
}
public LiveChannelStat getLiveChannelStat(LiveChannelGenericRequest liveChannelGenericRequest) throws OSSException, ClientException {
return this.liveChannelOperation.getLiveChannelStat(liveChannelGenericRequest);
}
public void deleteLiveChannel(String bucketName, String liveChannel) throws OSSException, ClientException {
this.deleteLiveChannel(new LiveChannelGenericRequest(bucketName, liveChannel));
}
public void deleteLiveChannel(LiveChannelGenericRequest liveChannelGenericRequest) throws OSSException, ClientException {
this.liveChannelOperation.deleteLiveChannel(liveChannelGenericRequest);
}
public List<LiveChannel> listLiveChannels(String bucketName) throws OSSException, ClientException {
return this.liveChannelOperation.listLiveChannels(bucketName);
}
public LiveChannelListing listLiveChannels(ListLiveChannelsRequest listLiveChannelRequest) throws OSSException, ClientException {
return this.liveChannelOperation.listLiveChannels(listLiveChannelRequest);
}
public List<LiveRecord> getLiveChannelHistory(String bucketName, String liveChannel) throws OSSException, ClientException {
return this.getLiveChannelHistory(new LiveChannelGenericRequest(bucketName, liveChannel));
}
public List<LiveRecord> getLiveChannelHistory(LiveChannelGenericRequest liveChannelGenericRequest) throws OSSException, ClientException {
return this.liveChannelOperation.getLiveChannelHistory(liveChannelGenericRequest);
}
public void generateVodPlaylist(String bucketName, String liveChannelName, String PlaylistName, long startTime, long endTime) throws OSSException, ClientException {
this.generateVodPlaylist(new GenerateVodPlaylistRequest(bucketName, liveChannelName, PlaylistName, startTime, endTime));
}
public void generateVodPlaylist(GenerateVodPlaylistRequest generateVodPlaylistRequest) throws OSSException, ClientException {
this.liveChannelOperation.generateVodPlaylist(generateVodPlaylistRequest);
}
public String generateRtmpUri(String bucketName, String liveChannelName, String PlaylistName, long expires) throws OSSException, ClientException {
return this.generateRtmpUri(new GenerateRtmpUriRequest(bucketName, liveChannelName, PlaylistName, expires));
}
public String generateRtmpUri(GenerateRtmpUriRequest generateRtmpUriRequest) throws OSSException, ClientException {
return this.liveChannelOperation.generateRtmpUri(generateRtmpUriRequest);
}
public void createSymlink(String bucketName, String symLink, String targetObject) throws OSSException, ClientException {
this.createSymlink(new CreateSymlinkRequest(bucketName, symLink, targetObject));
}
public void createSymlink(CreateSymlinkRequest createSymlinkRequest) throws OSSException, ClientException {
this.objectOperation.createSymlink(createSymlinkRequest);
}
public OSSSymlink getSymlink(String bucketName, String symLink) throws OSSException, ClientException {
return this.getSymlink(new GenericRequest(bucketName, symLink));
}
public OSSSymlink getSymlink(GenericRequest genericRequest) throws OSSException, ClientException {
return this.objectOperation.getSymlink(genericRequest);
}
public GenericResult processObject(ProcessObjectRequest processObjectRequest) throws OSSException, ClientException {
return this.objectOperation.processObject(processObjectRequest);
}
public void createUdf(CreateUdfRequest createUdfRequest) throws OSSException, ClientException {
this.udfOperation.createUdf(createUdfRequest);
}
public UdfInfo getUdfInfo(UdfGenericRequest genericRequest) throws OSSException, ClientException {
return this.udfOperation.getUdfInfo(genericRequest);
}
public List<UdfInfo> listUdfs() throws OSSException, ClientException {
return this.udfOperation.listUdfs();
}
public void deleteUdf(UdfGenericRequest genericRequest) throws OSSException, ClientException {
this.udfOperation.deleteUdf(genericRequest);
}
public void uploadUdfImage(UploadUdfImageRequest uploadUdfImageRequest) throws OSSException, ClientException {
this.udfOperation.uploadUdfImage(uploadUdfImageRequest);
}
public List<UdfImageInfo> getUdfImageInfo(UdfGenericRequest genericRequest) throws OSSException, ClientException {
return this.udfOperation.getUdfImageInfo(genericRequest);
}
public void deleteUdfImage(UdfGenericRequest genericRequest) throws OSSException, ClientException {
this.udfOperation.deleteUdfImage(genericRequest);
}
public void createUdfApplication(CreateUdfApplicationRequest createUdfApplicationRequest) throws OSSException, ClientException {
this.udfOperation.createUdfApplication(createUdfApplicationRequest);
}
public UdfApplicationInfo getUdfApplicationInfo(UdfGenericRequest genericRequest) throws OSSException, ClientException {
return this.udfOperation.getUdfApplicationInfo(genericRequest);
}
public List<UdfApplicationInfo> listUdfApplications() throws OSSException, ClientException {
return this.udfOperation.listUdfApplication();
}
public void deleteUdfApplication(UdfGenericRequest genericRequest) throws OSSException, ClientException {
this.udfOperation.deleteUdfApplication(genericRequest);
}
public void upgradeUdfApplication(UpgradeUdfApplicationRequest upgradeUdfApplicationRequest) throws OSSException, ClientException {
this.udfOperation.upgradeUdfApplication(upgradeUdfApplicationRequest);
}
public void resizeUdfApplication(ResizeUdfApplicationRequest resizeUdfApplicationRequest) throws OSSException, ClientException {
this.udfOperation.resizeUdfApplication(resizeUdfApplicationRequest);
}
public UdfApplicationLog getUdfApplicationLog(GetUdfApplicationLogRequest getUdfApplicationLogRequest) throws OSSException, ClientException {
return this.udfOperation.getUdfApplicationLog(getUdfApplicationLogRequest);
}
public void shutdown() {
try {
this.serviceClient.shutdown();
} catch (Exception var2) {
LogUtils.logException("shutdown throw exception: ", var2);
}
}
}