use of com.ibm.cloud.sdk.core.service.model.FileWithMetadata in project java-sdk by watson-developer-cloud.
the class TestUtilities method creatMockListFileWithMetadata.
public static List<FileWithMetadata> creatMockListFileWithMetadata() {
List<FileWithMetadata> list = new ArrayList<FileWithMetadata>();
byte[] fileBytes = { (byte) 0xde, (byte) 0xad, (byte) 0xbe, (byte) 0xef };
InputStream inputStream = new ByteArrayInputStream(fileBytes);
FileWithMetadata.Builder builder = new FileWithMetadata.Builder();
builder.data(inputStream);
FileWithMetadata fileWithMetadata = builder.build();
list.add(fileWithMetadata);
return list;
}
use of com.ibm.cloud.sdk.core.service.model.FileWithMetadata in project java-sdk by watson-developer-cloud.
the class TestUtilities method creatMockListFileWithMetadata.
public static List<FileWithMetadata> creatMockListFileWithMetadata() {
List<FileWithMetadata> list = new ArrayList<FileWithMetadata>();
byte[] fileBytes = { (byte) 0xde, (byte) 0xad, (byte) 0xbe, (byte) 0xef };
InputStream inputStream = new ByteArrayInputStream(fileBytes);
FileWithMetadata.Builder builder = new FileWithMetadata.Builder();
builder.data(inputStream);
FileWithMetadata fileWithMetadata = builder.build();
list.add(fileWithMetadata);
return list;
}
use of com.ibm.cloud.sdk.core.service.model.FileWithMetadata in project java-sdk by watson-developer-cloud.
the class TestUtilities method creatMockListFileWithMetadata.
public static List<FileWithMetadata> creatMockListFileWithMetadata() {
List<FileWithMetadata> list = new ArrayList<FileWithMetadata>();
byte[] fileBytes = { (byte) 0xde, (byte) 0xad, (byte) 0xbe, (byte) 0xef };
InputStream inputStream = new ByteArrayInputStream(fileBytes);
FileWithMetadata.Builder builder = new FileWithMetadata.Builder();
builder.data(inputStream);
FileWithMetadata fileWithMetadata = builder.build();
list.add(fileWithMetadata);
return list;
}
use of com.ibm.cloud.sdk.core.service.model.FileWithMetadata in project java-sdk by watson-developer-cloud.
the class VisualRecognition method addImages.
/**
* Add images.
*
* <p>Add images to a collection by URL, by file, or both.
*
* <p>Encode the image and .zip file names in UTF-8 if they contain non-ASCII characters. The
* service assumes UTF-8 encoding if it encounters non-ASCII characters.
*
* @param addImagesOptions the {@link AddImagesOptions} containing the options for the call
* @return a {@link ServiceCall} with a result of type {@link ImageDetailsList}
*/
public ServiceCall<ImageDetailsList> addImages(AddImagesOptions addImagesOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(addImagesOptions, "addImagesOptions cannot be null");
com.ibm.cloud.sdk.core.util.Validator.isTrue((addImagesOptions.imagesFile() != null) || (addImagesOptions.imageUrl() != null) || (addImagesOptions.trainingData() != null), "At least one of imagesFile, imageUrl, or trainingData must be supplied.");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("collection_id", addImagesOptions.collectionId());
RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v4/collections/{collection_id}/images", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("watson_vision_combined", "v4", "addImages");
for (Entry<String, String> header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
}
builder.header("Accept", "application/json");
builder.query("version", String.valueOf(this.version));
MultipartBody.Builder multipartBuilder = new MultipartBody.Builder();
multipartBuilder.setType(MultipartBody.FORM);
if (addImagesOptions.imagesFile() != null) {
for (FileWithMetadata item : addImagesOptions.imagesFile()) {
okhttp3.RequestBody itemBody = RequestUtils.inputStreamBody(item.data(), item.contentType());
multipartBuilder.addFormDataPart("images_file", item.filename(), itemBody);
}
}
if (addImagesOptions.imageUrl() != null) {
for (String item : addImagesOptions.imageUrl()) {
multipartBuilder.addFormDataPart("image_url", item);
}
}
if (addImagesOptions.trainingData() != null) {
multipartBuilder.addFormDataPart("training_data", addImagesOptions.trainingData());
}
builder.body(multipartBuilder.build());
ResponseConverter<ImageDetailsList> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<ImageDetailsList>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
use of com.ibm.cloud.sdk.core.service.model.FileWithMetadata in project java-sdk by watson-developer-cloud.
the class VisualRecognitionIT method testAnalyzeWithFiles.
/**
* Test analyze with files.
*
* @throws FileNotFoundException the file not found exception
*/
@Test
public void testAnalyzeWithFiles() throws FileNotFoundException {
FileWithMetadata giraffeImage = new FileWithMetadata.Builder().data(new File(SINGLE_GIRAFFE_IMAGE_PATH)).contentType("image/jpeg").build();
FileWithMetadata turtleImage = new FileWithMetadata.Builder().data(new File(SINGLE_TURTLE_IMAGE_PATH)).contentType("image/jpeg").build();
List<FileWithMetadata> filesToAnalyze = Arrays.asList(giraffeImage, turtleImage);
List<String> collectionIds = Collections.singletonList(COLLECTION_ID);
AnalyzeOptions options = new AnalyzeOptions.Builder().imagesFile(filesToAnalyze).collectionIds(collectionIds).addFeatures(AnalyzeOptions.Features.OBJECTS).threshold(.5f).build();
AnalyzeResponse response = service.analyze(options).execute().getResult();
assertNotNull(response);
assertEquals(2, response.getImages().size());
}
Aggregations