Skip to content

Commit

Permalink
fix: don't use deprecated ioutils.copy
Browse files Browse the repository at this point in the history
  • Loading branch information
justenwalker committed Jun 5, 2024
1 parent 70d9de4 commit 2edc605
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/main/java/tech/justen/concord/goodwill/TarUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,32 @@
import java.util.zip.GZIPInputStream;
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
import org.apache.commons.compress.utils.IOUtils;
import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class TarUtils {

private static final Logger log = LoggerFactory.getLogger(TarUtils.class);

@SuppressWarnings("ResultOfMethodCallIgnored")
private static void makeAllDirs(File file) {
file.mkdirs();
}

public static void extractTarball(Path tarBall, Path out) throws IOException {
try (FileInputStream fis = new FileInputStream(tarBall.toFile())) {
try (GZIPInputStream gzip = new GZIPInputStream(fis)) {
try (TarArchiveInputStream tar = new TarArchiveInputStream(gzip)) {
TarArchiveEntry entry;
while ((entry = (TarArchiveEntry) tar.getNextEntry()) != null) {
while ((entry = tar.getNextEntry()) != null) {
final File outputFile = new File(out.toFile(), entry.getName());
if (entry.isDirectory()) {
if (!outputFile.exists()) {
outputFile.mkdirs();
makeAllDirs(outputFile);
}
} else {
outputFile.getParentFile().mkdirs();
makeAllDirs(outputFile.getParentFile());
log.debug("tar.gz extract {} => {}", entry.getName(), outputFile);
try (OutputStream outputFileStream = new FileOutputStream(outputFile)) {
IOUtils.copy(tar, outputFileStream);
Expand Down

0 comments on commit 2edc605

Please sign in to comment.