public static void runExample(
DfaServices dfaServices, DfaSession session, String assetName, String pathToFile,
long creativeId, String assetToReplace) throws Exception {
// Request the creative service from the service client factory.
CreativeRemote creativeService = dfaServices.get(session, CreativeRemote.class);
// Create the In-Stream creative asset.
CreativeAsset inStreamVideoAsset = new CreativeAsset();
inStreamVideoAsset.setName(assetName);
inStreamVideoAsset.setContent(Media.getMediaDataFromFile(pathToFile));
// Create an upload request to make this asset a companion ad file for an
// existing In-Stream video creative.
InStreamAssetUploadRequest inStreamAssetUploadRequest = new InStreamAssetUploadRequest();
inStreamAssetUploadRequest.setCompanion(true);
inStreamAssetUploadRequest.setInStreamAsset(inStreamVideoAsset);
inStreamAssetUploadRequest.setCreativeId(creativeId);
// Replace the existing asset with a newly uploaded asset.
InStreamVideoCreative inStreamVideoCreative =
creativeService.replaceInStreamAsset(assetToReplace, inStreamAssetUploadRequest);
// Display a success message.
System.out.printf("Replaced companion ad asset \"%s\" in In-Stream video creative "
+ "with ID \"%s\".%n", assetToReplace, inStreamVideoCreative.getId());
}