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());
}
}
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());
}
}
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());
}
}
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;
}
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);
}
}
Aggregations