use of software.amazon.awssdk.services.mediastoredata.model.GetObjectResponse in project aws-doc-sdk-examples by awsdocs.
the class GetObject method getMediaObject.
// snippet-start:[mediastore.java2.get_object.main]
public static void getMediaObject(MediaStoreDataClient mediaStoreData, String completePath, String savePath) {
try {
GetObjectRequest objectRequest = GetObjectRequest.builder().path(completePath).build();
// Write out the data to a file.
ResponseInputStream<GetObjectResponse> data = mediaStoreData.getObject(objectRequest);
byte[] buffer = new byte[data.available()];
data.read(buffer);
File targetFile = new File(savePath);
OutputStream outStream = new FileOutputStream(targetFile);
outStream.write(buffer);
System.out.println("The data was written to " + savePath);
} catch (MediaStoreDataException | IOException e) {
System.err.println(e.getMessage());
System.exit(1);
}
}
Aggregations