@Test public void overwriteExistingFileWhenExtractingFromTar() throws Exception { FileExtractor fileExtractor = new FileExtractor(OVERWRITE_EXISTING_FILES); fileExtractor.extractFileFromArchive(new File(testTarGZFile.getFile()), tempDir, BinaryType.PHANTOMJS); long lastModified = phantomJSTestFile.lastModified(); Thread.sleep(1000); fileExtractor.extractFileFromArchive(new File(testTarGZFile.getFile()), tempDir, BinaryType.PHANTOMJS); assertThat(phantomJSTestFile.lastModified(), is(not(equalTo(lastModified)))); }
public String extractFileFromArchive(File downloadedCompressedFile, String extractedToFilePath, BinaryType possibleFilenames) throws IOException, IllegalArgumentException, MojoFailureException { DownloadableFileType fileType = DownloadableFileType.valueOf(FilenameUtils.getExtension(downloadedCompressedFile.getName()).toUpperCase()); LOG.debug("Determined archive type: " + fileType); LOG.debug("Overwrite files that exist: " + overwriteFilesThatExist); switch (fileType) { case GZ: case BZ2: CompressedFile compressedFile = new CompressedFile(downloadedCompressedFile); if (null != compressedFile.getArchiveType() && compressedFile.getArchiveType().equals(TAR)) { return untarFile(compressedFile.getInputStream(), extractedToFilePath, possibleFilenames); } else { return copyFileToDisk(compressedFile.getInputStream(), extractedToFilePath, compressedFile.getDecompressedFilename()); } case ZIP: return unzipFile(downloadedCompressedFile, extractedToFilePath, possibleFilenames); case EXE: if (possibleFilenames.getBinaryFilenames().contains(downloadedCompressedFile.getName())) { return copyFileToDisk(new FileInputStream(downloadedCompressedFile), extractedToFilePath, downloadedCompressedFile.getName()); } default: throw new IllegalArgumentException("." + fileType + " is an unsupported archive type"); } }
FileExtractor { public String extractFileFromArchive(File downloadedCompressedFile, String extractedToFilePath, BinaryType possibleFilenames) throws IOException, IllegalArgumentException, MojoFailureException { DownloadableFileType fileType = DownloadableFileType.valueOf(FilenameUtils.getExtension(downloadedCompressedFile.getName()).toUpperCase()); LOG.debug("Determined archive type: " + fileType); LOG.debug("Overwrite files that exist: " + overwriteFilesThatExist); switch (fileType) { case GZ: case BZ2: CompressedFile compressedFile = new CompressedFile(downloadedCompressedFile); if (null != compressedFile.getArchiveType() && compressedFile.getArchiveType().equals(TAR)) { return untarFile(compressedFile.getInputStream(), extractedToFilePath, possibleFilenames); } else { return copyFileToDisk(compressedFile.getInputStream(), extractedToFilePath, compressedFile.getDecompressedFilename()); } case ZIP: return unzipFile(downloadedCompressedFile, extractedToFilePath, possibleFilenames); case EXE: if (possibleFilenames.getBinaryFilenames().contains(downloadedCompressedFile.getName())) { return copyFileToDisk(new FileInputStream(downloadedCompressedFile), extractedToFilePath, downloadedCompressedFile.getName()); } default: throw new IllegalArgumentException("." + fileType + " is an unsupported archive type"); } } }
FileExtractor { public String extractFileFromArchive(File downloadedCompressedFile, String extractedToFilePath, BinaryType possibleFilenames) throws IOException, IllegalArgumentException, MojoFailureException { DownloadableFileType fileType = DownloadableFileType.valueOf(FilenameUtils.getExtension(downloadedCompressedFile.getName()).toUpperCase()); LOG.debug("Determined archive type: " + fileType); LOG.debug("Overwrite files that exist: " + overwriteFilesThatExist); switch (fileType) { case GZ: case BZ2: CompressedFile compressedFile = new CompressedFile(downloadedCompressedFile); if (null != compressedFile.getArchiveType() && compressedFile.getArchiveType().equals(TAR)) { return untarFile(compressedFile.getInputStream(), extractedToFilePath, possibleFilenames); } else { return copyFileToDisk(compressedFile.getInputStream(), extractedToFilePath, compressedFile.getDecompressedFilename()); } case ZIP: return unzipFile(downloadedCompressedFile, extractedToFilePath, possibleFilenames); case EXE: if (possibleFilenames.getBinaryFilenames().contains(downloadedCompressedFile.getName())) { return copyFileToDisk(new FileInputStream(downloadedCompressedFile), extractedToFilePath, downloadedCompressedFile.getName()); } default: throw new IllegalArgumentException("." + fileType + " is an unsupported archive type"); } } FileExtractor(boolean overwriteFilesThatExist); }
FileExtractor { public String extractFileFromArchive(File downloadedCompressedFile, String extractedToFilePath, BinaryType possibleFilenames) throws IOException, IllegalArgumentException, MojoFailureException { DownloadableFileType fileType = DownloadableFileType.valueOf(FilenameUtils.getExtension(downloadedCompressedFile.getName()).toUpperCase()); LOG.debug("Determined archive type: " + fileType); LOG.debug("Overwrite files that exist: " + overwriteFilesThatExist); switch (fileType) { case GZ: case BZ2: CompressedFile compressedFile = new CompressedFile(downloadedCompressedFile); if (null != compressedFile.getArchiveType() && compressedFile.getArchiveType().equals(TAR)) { return untarFile(compressedFile.getInputStream(), extractedToFilePath, possibleFilenames); } else { return copyFileToDisk(compressedFile.getInputStream(), extractedToFilePath, compressedFile.getDecompressedFilename()); } case ZIP: return unzipFile(downloadedCompressedFile, extractedToFilePath, possibleFilenames); case EXE: if (possibleFilenames.getBinaryFilenames().contains(downloadedCompressedFile.getName())) { return copyFileToDisk(new FileInputStream(downloadedCompressedFile), extractedToFilePath, downloadedCompressedFile.getName()); } default: throw new IllegalArgumentException("." + fileType + " is an unsupported archive type"); } } FileExtractor(boolean overwriteFilesThatExist); String extractFileFromArchive(File downloadedCompressedFile, String extractedToFilePath, BinaryType possibleFilenames); }
FileExtractor { public String extractFileFromArchive(File downloadedCompressedFile, String extractedToFilePath, BinaryType possibleFilenames) throws IOException, IllegalArgumentException, MojoFailureException { DownloadableFileType fileType = DownloadableFileType.valueOf(FilenameUtils.getExtension(downloadedCompressedFile.getName()).toUpperCase()); LOG.debug("Determined archive type: " + fileType); LOG.debug("Overwrite files that exist: " + overwriteFilesThatExist); switch (fileType) { case GZ: case BZ2: CompressedFile compressedFile = new CompressedFile(downloadedCompressedFile); if (null != compressedFile.getArchiveType() && compressedFile.getArchiveType().equals(TAR)) { return untarFile(compressedFile.getInputStream(), extractedToFilePath, possibleFilenames); } else { return copyFileToDisk(compressedFile.getInputStream(), extractedToFilePath, compressedFile.getDecompressedFilename()); } case ZIP: return unzipFile(downloadedCompressedFile, extractedToFilePath, possibleFilenames); case EXE: if (possibleFilenames.getBinaryFilenames().contains(downloadedCompressedFile.getName())) { return copyFileToDisk(new FileInputStream(downloadedCompressedFile), extractedToFilePath, downloadedCompressedFile.getName()); } default: throw new IllegalArgumentException("." + fileType + " is an unsupported archive type"); } } FileExtractor(boolean overwriteFilesThatExist); String extractFileFromArchive(File downloadedCompressedFile, String extractedToFilePath, BinaryType possibleFilenames);  }