Source:
<code>private Upload upload(File file, Project project, AWSDeviceFarmUploadType uploadType, Boolean synchronous) throws InterruptedException, IOException, AWSDeviceFarmException { CreateUploadRequest appUploadRequest = new CreateUploadRequest() .withName(file.getName()) .withProjectArn(project.getArn()) .withContentType("application/octet-stream") .withType(uploadType.toString()); Upload upload = api.createUpload(appUploadRequest).getUpload(); CloseableHttpClient httpClient = HttpClients.createSystem(); HttpPut httpPut = new HttpPut(upload.getUrl()); httpPut.setHeader("Content-Type", upload.getContentType()); FileEntity entity = new FileEntity(file); httpPut.setEntity(entity); writeToLog(String.format("Uploading %s to S3", file.getName())); HttpResponse response = httpClient.execute(httpPut); if (response.getStatusLine().getStatusCode() != 200) { throw new AWSDeviceFarmException(String.format("Upload returned non-200 responses: %i", response.getStatusLine().getStatusCode())); } if (synchronous) { while (true) { GetUploadRequest describeUploadRequest = new GetUploadRequest() .withArn(upload.getArn()); GetUploadResult describeUploadResult = api.getUpload(describeUploadRequest); String status = describeUploadResult.getUpload().getStatus(); if ("SUCCEEDED".equalsIgnoreCase(status)) { writeToLog(String.format("Upload %s succeeded", file.getName())); break; } else if ("FAILED".equalsIgnoreCase(status)) { <START> writeToLog(String.format("(Error Message: ) %s)", describeUploadResult.getUpload().getMetadata())); <END> throw new AWSDeviceFarmException(String.format("Upload %s failed!", upload.getName())); } else { try { writeToLog(String.format("Waiting for upload %s to be ready (current status: %s)", file.getName(), status)); Thread.sleep(5000); } catch (InterruptedException e) { writeToLog(String.format("Thread interrupted while waiting for the upload to complete")); throw e; } } } } return upload; }</code><technical_language>Nit: logging in this style format, floating ")". unbalanced, btw. ;)</technical_language>

Target:
private Upload upload(File file, Project project, AWSDeviceFarmUploadType uploadType, Boolean synchronous) throws InterruptedException, IOException, AWSDeviceFarmException { CreateUploadRequest appUploadRequest = new CreateUploadRequest() .withName(file.getName()) .withProjectArn(project.getArn()) .withContentType("application/octet-stream") .withType(uploadType.toString()); Upload upload = api.createUpload(appUploadRequest).getUpload(); CloseableHttpClient httpClient = HttpClients.createSystem(); HttpPut httpPut = new HttpPut(upload.getUrl()); httpPut.setHeader("Content-Type", upload.getContentType()); FileEntity entity = new FileEntity(file); httpPut.setEntity(entity); writeToLog(String.format("Uploading %s to S3", file.getName())); HttpResponse response = httpClient.execute(httpPut); if (response.getStatusLine().getStatusCode() != 200) { throw new AWSDeviceFarmException(String.format("Upload returned non-200 responses: %i", response.getStatusLine().getStatusCode())); } if (synchronous) { while (true) { GetUploadRequest describeUploadRequest = new GetUploadRequest() .withArn(upload.getArn()); GetUploadResult describeUploadResult = api.getUpload(describeUploadRequest); String status = describeUploadResult.getUpload().getStatus(); if ("SUCCEEDED".equalsIgnoreCase(status)) { writeToLog(String.format("Upload %s succeeded", file.getName())); break; } else if ("FAILED".equalsIgnoreCase(status)) { writeToLog(String.format("Error message from device farm: '%s'", describeUploadResult.getUpload().getMetadata())); throw new AWSDeviceFarmException(String.format("Upload %s failed!", upload.getName())); } else { try { writeToLog(String.format("Waiting for upload %s to be ready (current status: %s)", file.getName(), status)); Thread.sleep(5000); } catch (InterruptedException e) { writeToLog(String.format("Thread interrupted while waiting for the upload to complete")); throw e; } } } } return upload; }