Search in sources :

Example 1 with GetObjectResponse

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);
    }
}
Also used : MediaStoreDataException(software.amazon.awssdk.services.mediastoredata.model.MediaStoreDataException) GetObjectResponse(software.amazon.awssdk.services.mediastoredata.model.GetObjectResponse) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) GetObjectRequest(software.amazon.awssdk.services.mediastoredata.model.GetObjectRequest) File(java.io.File)

Aggregations

File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 GetObjectRequest (software.amazon.awssdk.services.mediastoredata.model.GetObjectRequest)1 GetObjectResponse (software.amazon.awssdk.services.mediastoredata.model.GetObjectResponse)1 MediaStoreDataException (software.amazon.awssdk.services.mediastoredata.model.MediaStoreDataException)1