diff --git a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/keyvalue/TarContainerPacker.java b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/keyvalue/TarContainerPacker.java index cdb3230a9b25..8f43b5c235f2 100644 --- a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/keyvalue/TarContainerPacker.java +++ b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/keyvalue/TarContainerPacker.java @@ -20,8 +20,6 @@ import java.io.BufferedOutputStream; import java.io.ByteArrayOutputStream; import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -42,6 +40,7 @@ import org.apache.commons.compress.archivers.ArchiveEntry; import org.apache.commons.compress.archivers.ArchiveInputStream; import org.apache.commons.compress.archivers.ArchiveOutputStream; +import org.apache.commons.compress.archivers.tar.TarArchiveEntry; import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; import org.apache.commons.io.FileUtils; @@ -124,7 +123,7 @@ private void extractEntry(ArchiveEntry entry, InputStream input, long size, Files.createDirectories(parent); } - try (OutputStream fileOutput = new FileOutputStream(path.toFile()); + try (OutputStream fileOutput = Files.newOutputStream(path); OutputStream output = new BufferedOutputStream(fileOutput)) { int bufferSize = 1024; byte[] buffer = new byte[bufferSize + 1]; @@ -157,7 +156,7 @@ public void pack(Container container, KeyValueContainerData containerData = container.getContainerData(); - try (ArchiveOutputStream archiveOutput = tar(compress(output))) { + try (ArchiveOutputStream archiveOutput = tar(compress(output))) { includeFile(container.getContainerFile(), CONTAINER_FILE_NAME, archiveOutput); @@ -172,7 +171,7 @@ public void pack(Container container, @Override public byte[] unpackContainerDescriptor(InputStream input) throws IOException { - try (ArchiveInputStream archiveInput = untar(decompress(input))) { + try (ArchiveInputStream archiveInput = untar(decompress(input))) { ArchiveEntry entry = archiveInput.getNextEntry(); while (entry != null) { @@ -219,9 +218,7 @@ public static Path getDbPath(Path baseDir, public static Path getChunkPath(Path baseDir, KeyValueContainerData containerData) { - Path chunkDir = KeyValueContainerLocationUtil.getChunksLocationPath( - baseDir.toString()).toPath(); - return chunkDir; + return KeyValueContainerLocationUtil.getChunksLocationPath(baseDir.toString()).toPath(); } private byte[] readEntry(InputStream input, final long size) @@ -240,11 +237,11 @@ private byte[] readEntry(InputStream input, final long size) } private void includePath(Path dir, String subdir, - ArchiveOutputStream archiveOutput) throws IOException { + ArchiveOutputStream archiveOutput) throws IOException { // Add a directory entry before adding files, in case the directory is // empty. - ArchiveEntry entry = archiveOutput.createArchiveEntry(dir.toFile(), subdir); + TarArchiveEntry entry = archiveOutput.createArchiveEntry(dir.toFile(), subdir); archiveOutput.putArchiveEntry(entry); archiveOutput.closeArchiveEntry(); @@ -258,20 +255,20 @@ private void includePath(Path dir, String subdir, } static void includeFile(File file, String entryName, - ArchiveOutputStream archiveOutput) throws IOException { - ArchiveEntry entry = archiveOutput.createArchiveEntry(file, entryName); + ArchiveOutputStream archiveOutput) throws IOException { + TarArchiveEntry entry = archiveOutput.createArchiveEntry(file, entryName); archiveOutput.putArchiveEntry(entry); - try (InputStream input = new FileInputStream(file)) { + try (InputStream input = Files.newInputStream(file.toPath())) { IOUtils.copy(input, archiveOutput); } archiveOutput.closeArchiveEntry(); } - private static ArchiveInputStream untar(InputStream input) { + private static ArchiveInputStream untar(InputStream input) { return new TarArchiveInputStream(input); } - private static ArchiveOutputStream tar(OutputStream output) { + private static ArchiveOutputStream tar(OutputStream output) { TarArchiveOutputStream os = new TarArchiveOutputStream(output); os.setBigNumberMode(TarArchiveOutputStream.BIGNUMBER_POSIX); return os; @@ -290,7 +287,7 @@ OutputStream compress(OutputStream output) throws IOException { private byte[] innerUnpack(InputStream input, Path dbRoot, Path chunksRoot) throws IOException { byte[] descriptorFileContent = null; - try (ArchiveInputStream archiveInput = untar(decompress(input))) { + try (ArchiveInputStream archiveInput = untar(decompress(input))) { ArchiveEntry entry = archiveInput.getNextEntry(); while (entry != null) { String name = entry.getName(); diff --git a/hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/replication/TestContainerImporter.java b/hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/replication/TestContainerImporter.java index 2992520f85cf..1f6e808e9aec 100644 --- a/hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/replication/TestContainerImporter.java +++ b/hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/replication/TestContainerImporter.java @@ -18,13 +18,15 @@ package org.apache.hadoop.ozone.container.replication; import java.io.File; -import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; +import java.nio.file.Files; import java.util.concurrent.CompletableFuture; import java.util.concurrent.Semaphore; -import org.apache.commons.compress.archivers.ArchiveEntry; + +import org.apache.commons.compress.archivers.ArchiveOutputStream; +import org.apache.commons.compress.archivers.tar.TarArchiveEntry; import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; import org.apache.commons.io.IOUtils; import org.apache.hadoop.hdds.conf.OzoneConfiguration; @@ -146,11 +148,11 @@ private File containerTarFile( File tarFile = new File(tempDir, ContainerUtils.getContainerTarName(containerId)); try (FileOutputStream output = new FileOutputStream(tarFile)) { - TarArchiveOutputStream archive = new TarArchiveOutputStream(output); - ArchiveEntry entry = archive.createArchiveEntry(yamlFile, + ArchiveOutputStream archive = new TarArchiveOutputStream(output); + TarArchiveEntry entry = archive.createArchiveEntry(yamlFile, "container.yaml"); archive.putArchiveEntry(entry); - try (InputStream input = new FileInputStream(yamlFile)) { + try (InputStream input = Files.newInputStream(yamlFile.toPath())) { IOUtils.copy(input, archive); } archive.closeArchiveEntry(); diff --git a/pom.xml b/pom.xml index 0c29ffe2f4f1..54026ae36efe 100644 --- a/pom.xml +++ b/pom.xml @@ -116,7 +116,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xs 1.6.0 1.15 3.2.2 - 1.21 + 1.25.0 2.1.1 1.5.2-5 1.0.13