### Question:
ReconUtils { public static File createTarFile(Path sourcePath) throws IOException { TarArchiveOutputStream tarOs = null; FileOutputStream fileOutputStream = null; GZIPOutputStream gzipOutputStream = null; try { String sourceDir = sourcePath.toString(); String fileName = sourceDir.concat(".tar.gz"); fileOutputStream = new FileOutputStream(fileName); gzipOutputStream = new GZIPOutputStream(new BufferedOutputStream(fileOutputStream)); tarOs = new TarArchiveOutputStream(gzipOutputStream); File folder = new File(sourceDir); File[] filesInDir = folder.listFiles(); if (filesInDir != null) { for (File file : filesInDir) { addFilesToArchive(file.getName(), file, tarOs); } } return new File(fileName); } finally { try { org.apache.hadoop.io.IOUtils.closeStream(tarOs); org.apache.hadoop.io.IOUtils.closeStream(fileOutputStream); org.apache.hadoop.io.IOUtils.closeStream(gzipOutputStream); } catch (Exception e) { LOG.error("Exception encountered when closing " + "TAR file output stream: " + e); } } } ReconUtils(); static File getReconScmDbDir(ConfigurationSource conf); File getReconDbDir(ConfigurationSource conf, String dirConfigKey); static File createTarFile(Path sourcePath); void untarCheckpointFile(File tarFile, Path destPath); HttpURLConnection makeHttpCall(URLConnectionFactory connectionFactory,
                                  String url, boolean isSpnego); File getLastKnownDB(File reconDbDir, String fileNamePrefix); static void upsertGlobalStatsTable(Configuration sqlConfiguration,
                                            GlobalStatsDao globalStatsDao,
                                            String key,
                                            Long count);  }### Answer:
@Test public void testCreateTarFile() throws Exception { File tempSnapshotDir = null; FileInputStream fis = null; FileOutputStream fos = null; File tarFile = null; try { String testDirName = System.getProperty("java.io.tmpdir"); if (!testDirName.endsWith("/")) { testDirName += "/"; } testDirName += "TestCreateTarFile_Dir" + System.currentTimeMillis(); tempSnapshotDir = new File(testDirName); tempSnapshotDir.mkdirs(); File file = new File(testDirName + "/temp1.txt"); FileWriter writer = new FileWriter(file); writer.write("Test data 1"); writer.close(); file = new File(testDirName + "/temp2.txt"); writer = new FileWriter(file); writer.write("Test data 2"); writer.close(); tarFile = createTarFile(Paths.get(testDirName)); Assert.assertNotNull(tarFile); } finally { org.apache.hadoop.io.IOUtils.closeStream(fis); org.apache.hadoop.io.IOUtils.closeStream(fos); FileUtils.deleteDirectory(tempSnapshotDir); FileUtils.deleteQuietly(tarFile); } }