Search in sources :

Example 6 with CloudSDKException

use of com.mizhousoft.cloudsdk.CloudSDKException in project cloud-sdk by mizhousoft.

the class TestSensitiveWordsRecognitionServiceImpl method testRecognizes.

@Test
public void testRecognizes() {
    String text1 = "ddddddddddddddddddd";
    String text2 = "ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd我的敏感词包二奶仓井空";
    text1 = StringUtils.leftPad(text1, 1950, "0");
    try {
        RecognitionResult result = this.sensitiveWordsRecognitionService.recognize(text1, text2);
        Assert.assertTrue(result.isContainSensitiveWord());
    } catch (CloudSDKException e) {
        Assert.fail(e.getMessage());
    }
}
Also used : CloudSDKException(com.mizhousoft.cloudsdk.CloudSDKException) RecognitionResult(com.mizhousoft.cloudsdk.nlp.RecognitionResult) Test(org.junit.Test)

Example 7 with CloudSDKException

use of com.mizhousoft.cloudsdk.CloudSDKException in project cloud-sdk by mizhousoft.

the class TestCOSObjectStorageServiceImpl method testputObject.

@Test
public void testputObject() {
    String filePath = TestCOSObjectStorageServiceImpl.class.getClassLoader().getResource("test.txt").getPath();
    File localFile = new File(filePath);
    try {
        objectStoreageService.putObject(BUCKETNAME, OBJECTNAME, localFile);
    } catch (CloudSDKException e) {
        Assert.fail(e.getMessage());
    }
}
Also used : CloudSDKException(com.mizhousoft.cloudsdk.CloudSDKException) File(java.io.File) Test(org.junit.Test)

Example 8 with CloudSDKException

use of com.mizhousoft.cloudsdk.CloudSDKException in project cloud-sdk by mizhousoft.

the class TestCOSObjectStorageServiceImpl method testgenPresignedDownloadUrl.

@Test
public void testgenPresignedDownloadUrl() {
    try {
        long signExpired = 60 * 1000;
        URL url = objectStoreageService.genPresignedDownloadUrl(BUCKETNAME, OBJECTNAME, signExpired);
        System.out.println(url.toString());
    } catch (CloudSDKException e) {
        Assert.fail(e.getMessage());
    }
}
Also used : CloudSDKException(com.mizhousoft.cloudsdk.CloudSDKException) URL(java.net.URL) Test(org.junit.Test)

Example 9 with CloudSDKException

use of com.mizhousoft.cloudsdk.CloudSDKException in project cloud-sdk by mizhousoft.

the class SensitiveWordsRecognitionServiceImpl method recognizeOne.

public RecognitionResult recognizeOne(String text) throws CloudSDKException {
    RecognitionResult result = new RecognitionResult();
    if (StringUtils.isBlank(text)) {
        return result;
    }
    try {
        SensitiveWordsRecognitionRequest request = new SensitiveWordsRecognitionRequest();
        request.setText(text);
        SensitiveWordsRecognitionResponse resp = nlpClient.SensitiveWordsRecognition(request);
        String[] words = resp.getSensitiveWords();
        if (!ArrayUtils.isEmpty(words)) {
            result.setSensitiveWords(Arrays.asList(words));
        }
    } catch (TencentCloudSDKException e) {
        throw new CloudSDKException(e.getMessage(), e);
    }
    return result;
}
Also used : TencentCloudSDKException(com.tencentcloudapi.common.exception.TencentCloudSDKException) CloudSDKException(com.mizhousoft.cloudsdk.CloudSDKException) TencentCloudSDKException(com.tencentcloudapi.common.exception.TencentCloudSDKException) SensitiveWordsRecognitionRequest(com.tencentcloudapi.nlp.v20190408.models.SensitiveWordsRecognitionRequest) SensitiveWordsRecognitionResponse(com.tencentcloudapi.nlp.v20190408.models.SensitiveWordsRecognitionResponse) RecognitionResult(com.mizhousoft.cloudsdk.nlp.RecognitionResult)

Example 10 with CloudSDKException

use of com.mizhousoft.cloudsdk.CloudSDKException in project cloud-sdk by mizhousoft.

the class COSObjectStorageServiceImpl method doDeleteObjects.

private void doDeleteObjects(String bucketName, Collection<String> objectNames) throws CloudSDKException {
    DeleteObjectsRequest deleteObjectsRequest = new DeleteObjectsRequest(bucketName);
    Set<String> names = new HashSet<>(objectNames);
    // 设置要删除的key列表, 最多一次删除1000个
    List<KeyVersion> keyList = new ArrayList<>();
    for (String objectName : names) {
        // 传入要删除的文件名
        keyList.add(new KeyVersion(objectName));
    }
    deleteObjectsRequest.setKeys(keyList);
    try {
        cosClient.deleteObjects(deleteObjectsRequest);
    // List<DeletedObject> deletedObjects = deleteResult.getDeletedObjects();
    } catch (MultiObjectDeleteException e) {
        // List<DeleteError> deleteErrors = mde.getErrors();
        throw new CloudSDKException(e.getMessage(), e);
    } catch (CosServiceException e) {
        throw new CloudSDKException(e.getMessage(), e);
    } catch (Throwable e) {
        throw new CloudSDKException(e.getMessage(), e);
    }
}
Also used : CloudSDKException(com.mizhousoft.cloudsdk.CloudSDKException) CosServiceException(com.qcloud.cos.exception.CosServiceException) KeyVersion(com.qcloud.cos.model.DeleteObjectsRequest.KeyVersion) MultiObjectDeleteException(com.qcloud.cos.exception.MultiObjectDeleteException) ArrayList(java.util.ArrayList) DeleteObjectsRequest(com.qcloud.cos.model.DeleteObjectsRequest) HashSet(java.util.HashSet)

Aggregations

CloudSDKException (com.mizhousoft.cloudsdk.CloudSDKException)44 TencentCloudSDKException (com.tencentcloudapi.common.exception.TencentCloudSDKException)14 Test (org.junit.Test)13 URL (java.net.URL)8 ObjectMetadata (com.mizhousoft.cloudsdk.oss.ObjectMetadata)6 File (java.io.File)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 RecognitionResult (com.mizhousoft.cloudsdk.nlp.RecognitionResult)3 Date (java.util.Date)3 GeneratePresignedUrlRequest (com.aliyun.oss.model.GeneratePresignedUrlRequest)2 TempCredential (com.mizhousoft.cloudsdk.TempCredential)2 OSSTempCredential (com.mizhousoft.cloudsdk.oss.OSSTempCredential)2 MediaMeta (com.mizhousoft.cloudsdk.vod.MediaMeta)2 CoverTypeEnum (com.mizhousoft.tencent.vod.constants.CoverTypeEnum)2 MediaTypeEnum (com.mizhousoft.tencent.vod.constants.MediaTypeEnum)2 GeneratePresignedUrlRequest (com.qcloud.cos.model.GeneratePresignedUrlRequest)2 VinOCRRequest (com.tencentcloudapi.ocr.v20181119.models.VinOCRRequest)2 VinOCRResponse (com.tencentcloudapi.ocr.v20181119.models.VinOCRResponse)2 CoverBySnapshotTaskInput (com.tencentcloudapi.vod.v20180717.models.CoverBySnapshotTaskInput)2