### Question:
ServiceUtils { public static void downloadObjectToFile(S3Object s3Object, File destinationFile, boolean performIntegrityCheck, boolean appendData) { final File parentDirectory = destinationFile.getParentFile(); if (parentDirectory != null && !parentDirectory.exists()) { parentDirectory.mkdirs(); } OutputStream outputStream = null; try { outputStream = new BufferedOutputStream(new FileOutputStream( destinationFile, appendData)); final byte[] buffer = new byte[DEAFAULT_BYTE_SIZE]; int bytesRead; while ((bytesRead = s3Object.getObjectContent().read(buffer)) > -1) { outputStream.write(buffer, 0, bytesRead); } } catch (final IOException e) { s3Object.getObjectContent().abort(); throw new AmazonClientException( "Unable to store object contents to disk: " + e.getMessage(), e); } finally { try { outputStream.close(); } catch (final Exception e) { log.debug("Caught exception. Ignoring."); } try { s3Object.getObjectContent().close(); } catch (final Exception e) { log.debug("Caught exception. Ignoring."); } } byte[] clientSideHash = null; byte[] serverSideHash = null; try { if (!ServiceUtils.isMultipartUploadETag(s3Object.getObjectMetadata().getETag())) { clientSideHash = Md5Utils.computeMD5Hash(new FileInputStream(destinationFile)); serverSideHash = BinaryUtils.fromHex(s3Object.getObjectMetadata().getETag()); } } catch (final Exception e) { log.warn("Unable to calculate MD5 hash to validate download: " + e.getMessage(), e); } if (performIntegrityCheck && clientSideHash != null && serverSideHash != null && !Arrays.equals(clientSideHash, serverSideHash)) { throw new AmazonClientException("Unable to verify integrity of data download. " + "Client calculated content hash didn't match hash calculated by Amazon S3. " + "The data stored in '" + destinationFile.getAbsolutePath() + "' may be corrupt."); } }  static Date parseIso8601Date(String dateString); static String formatIso8601Date(Date date); static Date parseRfc822Date(String dateString); static String formatRfc822Date(Date date); static boolean isMultipartUploadETag(String eTag); static byte[] toByteArray(String s); static String removeQuotes(String s); static URL convertRequestToUrl(Request<?> request); static URL convertRequestToUrl(Request<?> request,
            boolean removeLeadingSlashInResourcePath); static String join(List<String> strings); static void downloadObjectToFile(S3Object s3Object,
            File destinationFile, boolean performIntegrityCheck,
            boolean appendData); static S3Object retryableDownloadS3ObjectToFile(File file,
            RetryableS3DownloadTask retryableS3DownloadTask, boolean appendData); static boolean skipMd5CheckPerResponse(ObjectMetadata metadata); static boolean skipMd5CheckPerResponse(ObjectMetadata metadata, S3ClientOptions clientOptions); static boolean skipMd5CheckPerRequest(AmazonWebServiceRequest request); static boolean skipMd5CheckPerRequest(AmazonWebServiceRequest request, S3ClientOptions clientOptions); static final boolean APPEND_MODE; static final boolean OVERWRITE_MODE; }### Answer:
@Test public void downloadObjectToFileTest() throws Throwable { final S3Object s3Object = new S3Object(); final String input = "test input"; s3Object.setObjectContent(new StringInputStream(input)); final ObjectMetadata metadata = new ObjectMetadata(); metadata.setHeader(Headers.ETAG, "5eed650258ee02f6a77c87b748b764ec"); s3Object.setObjectMetadata(metadata); ServiceUtils.downloadObjectToFile(s3Object, File.createTempFile("temp1", "temp2"), true, false); }