private String untarFolder(InputStream compressedFileInputStream, String destinationFolder, List<String> possibleFilenames) throws IOException { String executablePath = ""; ArchiveEntry currentFile; ArchiveInputStream archiveInputStream = new TarArchiveInputStream(compressedFileInputStream); CloseShieldInputStream notClosableArchiveInputStream = new CloseShieldInputStream(archiveInputStream); try { while ((currentFile = archiveInputStream.getNextEntry()) != null) { String name = currentFile.getName(); name = this.handlePathCreation(name, destinationFolder); if (name.length() > 0) { String extractedFile = copyFileToDisk(notClosableArchiveInputStream, destinationFolder, name); for (String expectedFileName : possibleFilenames) { if (extractedFile.endsWith(expectedFileName)) { executablePath = extractedFile; } } } } } finally { compressedFileInputStream.close(); notClosableArchiveInputStream.close(); } return executablePath; }