use of com.plivo.api.exceptions.ResourceNotFoundException in project plivo-java by plivo.
the class MediaUploader method getFilesForFilenames.
private RequestBody getFilesForFilenames(String[] fileNames) throws ResourceNotFoundException {
Builder builder = new MultipartBody.Builder().setType(MultipartBody.FORM);
for (int i = 0; i < fileNames.length; i++) {
File tempFile = new File(fileNames[i]);
boolean exists = tempFile.exists();
if (!exists)
throw new ResourceNotFoundException("File missing " + fileNames[i]);
try {
System.out.println(tempFile);
System.out.println(tempFile.toPath());
// handle for java 8
String content_type = "";
if (Files.probeContentType(tempFile.toPath()) != null) {
content_type = Files.probeContentType(tempFile.toPath());
} else {
Path source = Paths.get(fileNames[i]);
MimetypesFileTypeMap m = new MimetypesFileTypeMap(source.toString());
content_type = m.getContentType(tempFile);
}
builder.addFormDataPart("file", fileNames[i], RequestBody.create(MediaType.parse(content_type), tempFile));
} catch (IOException e) {
throw new ResourceNotFoundException("Unable to read file " + fileNames[i]);
}
}
return builder.build();
}
use of com.plivo.api.exceptions.ResourceNotFoundException in project plivo-java by plivo.
the class ComplianceDocumentCreator method setFile.
public void setFile(String file) throws ResourceNotFoundException {
this.file = file;
File tempFile = new File(file);
boolean exists = tempFile.exists();
if (!exists)
throw new ResourceNotFoundException("File missing " + file);
try {
System.out.println(tempFile);
System.out.println(tempFile.toPath());
// handle for java 8
String content_type = "";
if (Files.probeContentType(tempFile.toPath()) != null) {
content_type = Files.probeContentType(tempFile.toPath());
} else {
Path source = Paths.get(file);
MimetypesFileTypeMap m = new MimetypesFileTypeMap(source.toString());
content_type = m.getContentType(tempFile);
}
this.body.addFormDataPart("file", file, RequestBody.create(MediaType.parse(content_type), tempFile));
} catch (IOException e) {
throw new ResourceNotFoundException("Unable to read file " + file);
}
}
use of com.plivo.api.exceptions.ResourceNotFoundException in project plivo-java by plivo.
the class ComplianceDocumentUpdater method setFile.
public ComplianceDocumentUpdater setFile(String file) throws ResourceNotFoundException {
this.file = file;
File tempFile = new File(file);
boolean exists = tempFile.exists();
if (!exists)
throw new ResourceNotFoundException("File missing " + file);
try {
System.out.println(tempFile);
System.out.println(tempFile.toPath());
// handle for java 8
String content_type = "";
if (Files.probeContentType(tempFile.toPath()) != null) {
content_type = Files.probeContentType(tempFile.toPath());
} else {
Path source = Paths.get(file);
MimetypesFileTypeMap m = new MimetypesFileTypeMap(source.toString());
content_type = m.getContentType(tempFile);
}
this.body.addFormDataPart("file", file, RequestBody.create(MediaType.parse(content_type), tempFile));
} catch (IOException e) {
throw new ResourceNotFoundException("Unable to read file " + file);
}
return this;
}
Aggregations