public class OSSToolKit extends ToolKit
Constructor and Description |
---|
OSSToolKit() |
Modifier and Type | Method and Description |
---|---|
static OSSException |
buildInterruptException(String bucketName,
String objectKey)
构造任务被取消时的中断异常
|
static OSSException |
buildLocalException(String bucketName,
String objectKey,
Exception e)
从Local异常里构造出OSS异常类
|
static OSSException |
buildMd5CheckException(HttpResponse response,
String bucketName,
String objectKey,
String md5sum,
String eTag)
构造MD5校验异常
|
static void |
buildMutilPartUploadRequest(HttpUriRequest request,
BaseObject object,
ResourceToQuery resource)
分块上传时构造相关请求头。上传块时不需要带上额外信息如contentType等,所以独立于buildRequestWithSpecRsr
|
static OSSException |
buildNetworkException(HttpResponse response,
String bucketName,
String objectKey)
网络有响应但不是来自OSS服务端,构造异常抛出响应信息,避免意外最大只取前2048个字节
|
static void |
buildObjectListRequest(HttpUriRequest request,
OSSBucket bucket,
ResourceToQuery resource)
构造列举bucket的请求
|
static OSSException |
buildOssException(HttpResponse response,
String bucketName,
String objectKey)
从OSS的错误响应里构造出异常类
|
static void |
buildRequest(HttpUriRequest request,
BaseObject object)
构造数据操作相关的请求头
|
static void |
buildRequestWithCompleteInfo(HttpUriRequest request,
BaseObject object,
ResourceToQuery resource)
指定resource情况下,构造请求头
|
static byte[] |
calFileMd5sum(String filePath)
计算一个文件的MD5sum
|
static String |
checkChildNotNullAndGetValue(Node item)
检查xml单节点有子节点并取值
|
static void |
checkETagMd5Invalid(String bucketName,
String objectKey,
MessageDigest digester,
HttpResponse response)
上传文件后检查response中的eTag和本地计算得到的MD5sum是否一样,如果不一样,抛出异常
|
static boolean |
checkRequestIsGetOrHead(HttpUriRequest request)
判断一个请求是不是GET或HEAD(即没有副作用的请求)
|
static boolean |
checkRequestIsPutOrPost(HttpUriRequest request)
判断一个请求是不是PUT或POST
|
static void |
consumeResponseEntity(HttpResponse response)
如果一个response存在响应body,读尽它
|
static void |
ensureBucketNameValid(String bucketName)
Validate bucket name.
|
static void |
ensureObjectKeyValid(String key)
Validate objecate name
|
static HttpResponse |
executeRequestWithLog(HttpClient client,
HttpUriRequest request)
执行request,打印请求头、响应头
|
static String |
formatContentType(String originContentType) |
static String |
generateCanonicalizedHeader(XOSSMeta headers)
生成CanonicalizedHeader, 以\n结束
|
static String |
generateToken(String accessKey,
String screctKey,
String content)
根据ak/sk、content生成token
|
static ObjectMeta |
getObjectMetadataFromResponse(HttpResponse response)
将meta数据从http响应内容中解析出来
|
static String |
getUserAgent()
获取系统UA值
|
static OSSException |
handleExceptionalResponse(HttpResponse response,
HttpUriRequest request,
String bucketName,
String objectKey)
处理非oss服务端返回的响应,返回处理后的异常信息
|
static boolean |
isEmptyString(String str)
判断一个字符串是否为空
|
static boolean |
isNeedToAuthorize(HttpUriRequest request,
AccessControlList ACL)
判断一个请求是否需要加签
|
static boolean |
isReadOnlyHttpMethod(String method)
判断一个http请求是否是只读的
|
static boolean |
isResponseFromOssServer(HttpResponse response)
判断一个响应是不是从OSS服务端返回的
|
static String |
parseCommonPrefix(NodeList list)
解析commonPrefix
|
static ListObjectResult |
parseObjectListResponse(InputStream in)
解析listObejctInBucket请求的响应体
|
static List<UploadPartInfo> |
parsePartListFromResponse(InputStream inputStream)
解析查看分块上传事件的已上传分块列表
|
static void |
parserErrorResponseXML(OSSResponseInfo ossRespInfo,
InputStream in)
解析OSS的错误响应,将解析结果置入ossRespInfo中
|
static ListObjectResult.ObjectInfo |
parseSingleObjectInfo(NodeList list)
解析bucket list列表的单个元素
|
static String |
parseUploadIdFromXml(InputStream in)
初始化上传事件时,从响应体的XML里parse出uploadID
|
static void |
printRequestHeader(HttpRequest request)
打印一个request的header,包括requestLine
|
static void |
printResponseHeader(HttpResponse response)
打印一个response的header,包括statusLine
|
static void |
setMetaHeader(HttpUriRequest request,
ObjectMeta meta)
将构造的meta添加到请求头中
|
static void |
suspend(long delayMs)
当前线程暂停若干毫秒,不抛出中断异常
|
static boolean |
validateBucketName(String bucketName)
Validate bucket name
|
static boolean |
validateObjectKey(String key)
Validate object name.
|
calMd5sum, calMd5sumString, checkFileReadable, checkFileWritable, checkNotEmptyStringArg, checkNotNullArg, checkNotNullPointer, currentTimeInGMTFormat, date2GMTFormat, detectIfProxyExist, epoch2GMTFormat, getBase64Md5FromFile, getHmacSha1Signature, getMd5StrFromBytes, gmtFormat2Date, isEmptyOrNullString, readFullyToBuffer, readFullyToByteArray, readFullyToLocalFile, readFullyToString, string2DateInSpecifyFormat, trimAndJoin, validateHostName
public static boolean validateBucketName(String bucketName)
public static void ensureBucketNameValid(String bucketName)
bucketName
- public static boolean validateObjectKey(String key)
public static void ensureObjectKeyValid(String key)
key
- public static String checkChildNotNullAndGetValue(Node item)
item
- public static void parserErrorResponseXML(OSSResponseInfo ossRespInfo, InputStream in) throws Exception
ossRespInfo
- in
- Exception
public static ListObjectResult.ObjectInfo parseSingleObjectInfo(NodeList list)
list
- public static String parseCommonPrefix(NodeList list)
list
- public static ListObjectResult parseObjectListResponse(InputStream in) throws Exception
in
- Exception
public static String parseUploadIdFromXml(InputStream in)
in
- public static List<UploadPartInfo> parsePartListFromResponse(InputStream inputStream) throws Exception
inputStream
- Exception
public static void checkETagMd5Invalid(String bucketName, String objectKey, MessageDigest digester, HttpResponse response) throws OSSException
digester
- response
- OSSException
public static void setMetaHeader(HttpUriRequest request, ObjectMeta meta)
request
- meta
- public static String generateCanonicalizedHeader(XOSSMeta headers)
public static ObjectMeta getObjectMetadataFromResponse(HttpResponse response) throws ParseException
response
- ParseException
public static void buildRequest(HttpUriRequest request, BaseObject object)
request
- object
- public static String getUserAgent()
public static boolean isNeedToAuthorize(HttpUriRequest request, AccessControlList ACL)
request
- ACL
- public static boolean isReadOnlyHttpMethod(String method)
method
- public static boolean isResponseFromOssServer(HttpResponse response)
response
- public static void buildRequestWithCompleteInfo(HttpUriRequest request, BaseObject object, ResourceToQuery resource)
request
- object
- resource
- public static void buildMutilPartUploadRequest(HttpUriRequest request, BaseObject object, ResourceToQuery resource)
request
- resource
- public static void buildObjectListRequest(HttpUriRequest request, OSSBucket bucket, ResourceToQuery resource)
public static OSSException buildOssException(HttpResponse response, String bucketName, String objectKey) throws Exception
response
- objectKey
- Exception
public static OSSException buildNetworkException(HttpResponse response, String bucketName, String objectKey) throws Exception
response
- objectKey
- Exception
public static OSSException handleExceptionalResponse(HttpResponse response, HttpUriRequest request, String bucketName, String objectKey)
response
- request
- objectKey
- public static OSSException buildMd5CheckException(HttpResponse response, String bucketName, String objectKey, String md5sum, String eTag)
response
- objectKey
- md5sum
- eTag
- public static OSSException buildLocalException(String bucketName, String objectKey, Exception e)
objectKey
- e
- public static OSSException buildInterruptException(String bucketName, String objectKey)
bucketName
- objectKey
- public static boolean isEmptyString(String str)
str
- public static void printRequestHeader(HttpRequest request)
request
- public static void printResponseHeader(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(HttpUriRequest request)
request
- public static boolean checkRequestIsPutOrPost(HttpUriRequest request)
request
- public static void suspend(long delayMs)
delayMs
- public static void consumeResponseEntity(HttpResponse response)
IOException
public static HttpResponse executeRequestWithLog(HttpClient client, HttpUriRequest request) throws IOException
IOException
Copyright © 2015. All rights reserved.