Search in sources :

Example 1 with MediaStoreDataException

use of software.amazon.awssdk.services.mediastoredata.model.MediaStoreDataException in project aws-doc-sdk-examples by awsdocs.

the class DeleteObject method deleteMediaObject.

// snippet-start:[mediastore.java2.delete_object.main]
public static void deleteMediaObject(MediaStoreDataClient mediaStoreData, String completePath) {
    try {
        DeleteObjectRequest deleteObjectRequest = DeleteObjectRequest.builder().path(completePath).build();
        mediaStoreData.deleteObject(deleteObjectRequest);
    } catch (MediaStoreDataException e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
}
Also used : DeleteObjectRequest(software.amazon.awssdk.services.mediastoredata.model.DeleteObjectRequest) MediaStoreDataException(software.amazon.awssdk.services.mediastoredata.model.MediaStoreDataException)

Example 2 with MediaStoreDataException

use of software.amazon.awssdk.services.mediastoredata.model.MediaStoreDataException in project aws-doc-sdk-examples by awsdocs.

the class ListItems method listAllItems.

// snippet-start:[mediastore.java2.list_items.main]
public static void listAllItems(MediaStoreDataClient mediaStoreData, String completePath) {
    try {
        ListItemsRequest itemsRequest = ListItemsRequest.builder().path(completePath).build();
        ListItemsResponse itemsResponse = mediaStoreData.listItems(itemsRequest);
        Boolean hasItems = itemsResponse.hasItems();
        if (hasItems) {
            List<Item> items = itemsResponse.items();
            for (Item item : items) {
                System.out.println("Item name is: " + item.name());
                System.out.println("Content type is:  " + item.contentType());
            }
        } else {
            System.out.println("There are no items");
        }
    } catch (MediaStoreDataException e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
}
Also used : Item(software.amazon.awssdk.services.mediastoredata.model.Item) MediaStoreDataException(software.amazon.awssdk.services.mediastoredata.model.MediaStoreDataException) ListItemsRequest(software.amazon.awssdk.services.mediastoredata.model.ListItemsRequest) ListItemsResponse(software.amazon.awssdk.services.mediastoredata.model.ListItemsResponse)

Example 3 with MediaStoreDataException

use of software.amazon.awssdk.services.mediastoredata.model.MediaStoreDataException in project aws-doc-sdk-examples by awsdocs.

the class PutObject method putMediaObject.

// snippet-start:[mediastore.java2.put_object.main]
public static void putMediaObject(MediaStoreDataClient mediaStoreData, String filePath, String completePath) {
    try {
        File myFile = new File(filePath);
        RequestBody requestBody = RequestBody.fromFile(myFile);
        PutObjectRequest objectRequest = PutObjectRequest.builder().path(completePath).contentType("video/mp4").build();
        PutObjectResponse response = mediaStoreData.putObject(objectRequest, requestBody);
        System.out.println("The saved object is " + response.storageClass().toString());
    } catch (MediaStoreDataException e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
}
Also used : MediaStoreDataException(software.amazon.awssdk.services.mediastoredata.model.MediaStoreDataException) PutObjectResponse(software.amazon.awssdk.services.mediastoredata.model.PutObjectResponse) File(java.io.File) PutObjectRequest(software.amazon.awssdk.services.mediastoredata.model.PutObjectRequest) RequestBody(software.amazon.awssdk.core.sync.RequestBody)

Example 4 with MediaStoreDataException

use of software.amazon.awssdk.services.mediastoredata.model.MediaStoreDataException 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

MediaStoreDataException (software.amazon.awssdk.services.mediastoredata.model.MediaStoreDataException)4 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 RequestBody (software.amazon.awssdk.core.sync.RequestBody)1 DeleteObjectRequest (software.amazon.awssdk.services.mediastoredata.model.DeleteObjectRequest)1 GetObjectRequest (software.amazon.awssdk.services.mediastoredata.model.GetObjectRequest)1 GetObjectResponse (software.amazon.awssdk.services.mediastoredata.model.GetObjectResponse)1 Item (software.amazon.awssdk.services.mediastoredata.model.Item)1 ListItemsRequest (software.amazon.awssdk.services.mediastoredata.model.ListItemsRequest)1 ListItemsResponse (software.amazon.awssdk.services.mediastoredata.model.ListItemsResponse)1 PutObjectRequest (software.amazon.awssdk.services.mediastoredata.model.PutObjectRequest)1 PutObjectResponse (software.amazon.awssdk.services.mediastoredata.model.PutObjectResponse)1