public class OSSToolKit
extends com.aliyun.mbaas.tools.ToolKit
Constructor and Description |
---|
OSSToolKit() |
Modifier and Type | Method and Description |
---|---|
static void |
addMetaHeader(org.apache.http.client.methods.HttpUriRequest request,
ObjectMeta meta)
将构造的meta添加到请求头中
|
static OSSException |
buildInterruptException(String objectKey) |
static OSSException |
buildLocalException(String objectKey,
Exception e)
从Local异常里构造出OSS异常类
|
static OSSException |
buildMd5CheckException(org.apache.http.HttpResponse response,
String objectKey,
String md5sum,
String eTag)
构造MD5校验异常
|
static void |
buildMutilPartUploadRequest(org.apache.http.client.methods.HttpUriRequest request,
OSSObject object,
String resource)
分块上传时构造相关请求头。上传块时不需要带上额外信息如contentType等,所以独立于buildRequestWithSpecRsr
|
static OSSException |
buildNetworkException(org.apache.http.HttpResponse response,
String objectKey)
网络有响应但不是来自OSS服务端,构造异常抛出响应信息,避免意外最大只取前2048个字节
|
static OSSException |
buildOssException(org.apache.http.HttpResponse response,
String objectKey)
从OSS的错误响应里构造出异常类
|
static void |
buildRequest(org.apache.http.client.methods.HttpUriRequest request,
OSSObject object)
构造数据操作相关的请求头
|
static void |
buildRequestWithSpecRsr(org.apache.http.client.methods.HttpUriRequest request,
OSSObject object,
String resource)
指定resource情况下,构造请求头
|
static byte[] |
calFileMd5sum(String filePath)
计算一个文件的MD5sum
|
static void |
checkETagMd5Invalid(String objectKey,
MessageDigest digester,
org.apache.http.HttpResponse response)
上传文件后检查response中的eTag和本地计算得到的MD5sum是否一样,如果不一样,抛出异常
|
static boolean |
checkRequestIsGetOrHead(org.apache.http.client.methods.HttpUriRequest request)
判断一个请求是不是GET或HEAD(即没有副作用的请求)
|
static boolean |
checkRequestIsPutOrPost(org.apache.http.client.methods.HttpUriRequest request)
判断一个请求是不是PUT或POST
|
static String |
generateCanonicalizedHeader(XOSSMeta headers)
生成CanonicalizedHeader, 以\n结束
|
static String |
generateToken(String accessKey,
String screctKey,
String content)
根据ak/sk、content生成token
|
static ObjectMeta |
getObjectMetadataFromResponse(org.apache.http.HttpResponse response)
将meta数据从http响应内容中解析出来
|
static String |
getUserAgent()
获取系统UA值
|
static OSSException |
handleExceptionalResponse(org.apache.http.HttpResponse response,
org.apache.http.client.methods.HttpUriRequest request,
String objectKey)
处理非oss服务端返回的响应,返回处理后的异常信息
|
static boolean |
isEmptyString(String str)
判断一个字符串是否为空
|
static boolean |
isNeedToAuthorize(org.apache.http.client.methods.HttpUriRequest request,
AccessControlList ACL)
判断一个请求是否需要加签
|
static boolean |
isReadOnlyHttpMethod(String method)
判断一个http请求是否是只读的
|
static boolean |
isResponseFromOssServer(org.apache.http.HttpResponse response)
判断一个响应是不是从OSS服务端返回的
|
static void |
parserErrorResponseXML(OSSResponseInfo ossRespInfo,
InputStream in)
解析OSS的错误响应,将解析结果置入ossRespInfo中
|
static String |
parseUploadIdFromXml(InputStream in)
初始化上传事件时,从响应体的XML里parse出uploadID
|
static void |
printRequestHeader(org.apache.http.HttpRequest request)
打印一个request的header,包括requestLine
|
static void |
printResponseHeader(org.apache.http.HttpResponse response)
打印一个response的header,包括statusLine
|
calMd5sum, calMd5sumString, checkFileCanReadArg, checkFileCanWriteArg, checkNotEmptyStringArg, checkNotNullArg, checkNotNullPointer, getBytesFromIS, getDateFromString, getGMTDate, getGMTDate, getGMTDate, getGMTDateFromString, getHmacSha1Signature, getMd5StrFromBytes, getToFileFromIS, readFully, readFullyToBuffer
public static void parserErrorResponseXML(OSSResponseInfo ossRespInfo, InputStream in) throws Exception
ossRespInfo
- in
- Exception
public static String parseUploadIdFromXml(InputStream in)
in
- public static void checkETagMd5Invalid(String objectKey, MessageDigest digester, org.apache.http.HttpResponse response) throws OSSException
digester
- response
- OSSException
public static void addMetaHeader(org.apache.http.client.methods.HttpUriRequest request, ObjectMeta meta)
request
- meta
- public static String generateCanonicalizedHeader(XOSSMeta headers)
public static ObjectMeta getObjectMetadataFromResponse(org.apache.http.HttpResponse response) throws ParseException
response
- ParseException
public static void buildRequest(org.apache.http.client.methods.HttpUriRequest request, OSSObject object)
request
- object
- public static String getUserAgent()
public static boolean isNeedToAuthorize(org.apache.http.client.methods.HttpUriRequest request, AccessControlList ACL)
request
- ACL
- public static boolean isReadOnlyHttpMethod(String method)
request
- public static boolean isResponseFromOssServer(org.apache.http.HttpResponse response)
response
- public static void buildRequestWithSpecRsr(org.apache.http.client.methods.HttpUriRequest request, OSSObject object, String resource)
request
- object
- resource
- public static void buildMutilPartUploadRequest(org.apache.http.client.methods.HttpUriRequest request, OSSObject object, String resource)
request
- resource
- public static OSSException buildOssException(org.apache.http.HttpResponse response, String objectKey) throws Exception
response
- objectKey
- Exception
public static OSSException buildNetworkException(org.apache.http.HttpResponse response, String objectKey) throws Exception
response
- objectKey
- Exception
public static OSSException handleExceptionalResponse(org.apache.http.HttpResponse response, org.apache.http.client.methods.HttpUriRequest request, String objectKey)
response
- request
- objectKey
- public static OSSException buildMd5CheckException(org.apache.http.HttpResponse response, String objectKey, String md5sum, String eTag)
response
- objectKey
- md5sum
- eTag
- public static OSSException buildLocalException(String objectKey, Exception e)
objectKey
- e
- public static OSSException buildInterruptException(String objectKey)
public static boolean isEmptyString(String str)
str
- public static void printRequestHeader(org.apache.http.HttpRequest request)
request
- public static void printResponseHeader(org.apache.http.HttpResponse response)
response
- public static byte[] calFileMd5sum(String filePath) throws NoSuchAlgorithmException, IOException
filePath
- NoSuchAlgorithmException
IOException
public static String generateToken(String accessKey, String screctKey, String content)
accessKey
- screctKey
- content
- public static boolean checkRequestIsGetOrHead(org.apache.http.client.methods.HttpUriRequest request)
request
- public static boolean checkRequestIsPutOrPost(org.apache.http.client.methods.HttpUriRequest request)
request
- Copyright © 2015. All rights reserved.