summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2023-11-16 11:14:53 +0100
committerHenning Baldersheim <balder@yahoo-inc.com>2023-11-16 11:14:53 +0100
commit5b164fda4b6b2740ddddfe3578c8326199b890ce (patch)
tree47eb8033c4046d357a9b5e1581bb5f45626f98fa
parent32360c001a360cf0fee88a0127c18ff6957f96e8 (diff)
Follow API changes
-rw-r--r--application-model/src/main/java/com/yahoo/vespa/archive/ArchiveStreamReader.java5
-rw-r--r--configserver/src/test/java/com/yahoo/vespa/config/server/application/CompressedApplicationInputStreamTest.java12
-rw-r--r--filedistribution/src/main/java/com/yahoo/vespa/filedistribution/FileReferenceCompressor.java51
3 files changed, 32 insertions, 36 deletions
diff --git a/application-model/src/main/java/com/yahoo/vespa/archive/ArchiveStreamReader.java b/application-model/src/main/java/com/yahoo/vespa/archive/ArchiveStreamReader.java
index 2f8b73839da..b7ad4ac6279 100644
--- a/application-model/src/main/java/com/yahoo/vespa/archive/ArchiveStreamReader.java
+++ b/application-model/src/main/java/com/yahoo/vespa/archive/ArchiveStreamReader.java
@@ -15,7 +15,6 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.io.UncheckedIOException;
import java.util.Objects;
-import java.util.OptionalLong;
import java.util.function.Predicate;
import java.util.zip.GZIPInputStream;
@@ -26,13 +25,13 @@ import java.util.zip.GZIPInputStream;
*/
public class ArchiveStreamReader implements AutoCloseable {
- private final ArchiveInputStream archiveInputStream;
+ private final ArchiveInputStream<? extends ArchiveEntry> archiveInputStream;
private final Options options;
private long totalRead = 0;
private long entriesRead = 0;
- private ArchiveStreamReader(ArchiveInputStream archiveInputStream, Options options) {
+ private <T extends ArchiveEntry> ArchiveStreamReader(ArchiveInputStream<T> archiveInputStream, Options options) {
this.archiveInputStream = Objects.requireNonNull(archiveInputStream);
this.options = Objects.requireNonNull(options);
}
diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/application/CompressedApplicationInputStreamTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/application/CompressedApplicationInputStreamTest.java
index 5a244b4b4b4..93c41f1b087 100644
--- a/configserver/src/test/java/com/yahoo/vespa/config/server/application/CompressedApplicationInputStreamTest.java
+++ b/configserver/src/test/java/com/yahoo/vespa/config/server/application/CompressedApplicationInputStreamTest.java
@@ -4,6 +4,7 @@ package com.yahoo.vespa.config.server.application;
import com.google.common.io.ByteStreams;
import com.yahoo.vespa.config.server.http.InternalServerException;
import com.yahoo.yolean.Exceptions;
+import org.apache.commons.compress.archivers.ArchiveEntry;
import org.apache.commons.compress.archivers.ArchiveOutputStream;
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream;
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
@@ -19,6 +20,7 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.List;
+import java.util.Objects;
import java.util.zip.GZIPOutputStream;
import static org.junit.Assert.assertEquals;
@@ -33,13 +35,13 @@ public class CompressedApplicationInputStreamTest {
@Rule
public TemporaryFolder temporaryFolder = new TemporaryFolder();
- private static void writeFileToTar(ArchiveOutputStream taos, File file) throws IOException {
+ private static <T extends ArchiveEntry> void writeFileToTar(ArchiveOutputStream<T> taos, File file) throws IOException {
taos.putArchiveEntry(taos.createArchiveEntry(file, file.getName()));
ByteStreams.copy(new FileInputStream(file), taos);
taos.closeArchiveEntry();
}
- private static File createArchiveFile(ArchiveOutputStream taos, File outFile) throws IOException {
+ private static <T extends ArchiveEntry> File createArchiveFile(ArchiveOutputStream<T> taos, File outFile) throws IOException {
File app = new File("src/test/resources/deploy/validapp");
writeFileToTar(taos, new File(app, "services.xml"));
writeFileToTar(taos, new File(app, "hosts.xml"));
@@ -50,13 +52,13 @@ public class CompressedApplicationInputStreamTest {
public static File createTarFile(Path dir) throws IOException {
File outFile = Files.createTempFile(dir, "testapp", ".tar.gz").toFile();
- ArchiveOutputStream archiveOutputStream = new TarArchiveOutputStream(new GZIPOutputStream(new FileOutputStream(outFile)));
+ var archiveOutputStream = new TarArchiveOutputStream(new GZIPOutputStream(new FileOutputStream(outFile)));
return createArchiveFile(archiveOutputStream, outFile);
}
private File createZipFile(Path dir) throws IOException {
File outFile = Files.createTempFile(dir, "testapp", ".tar.gz").toFile();
- ArchiveOutputStream archiveOutputStream = new ZipArchiveOutputStream(new FileOutputStream(outFile));
+ var archiveOutputStream = new ZipArchiveOutputStream(new FileOutputStream(outFile));
return createArchiveFile(archiveOutputStream, outFile);
}
@@ -102,7 +104,7 @@ public class CompressedApplicationInputStreamTest {
try (CompressedApplicationInputStream unpacked = streamFromTarGz(gzFile)) {
outApp = unpacked.decompress();
}
- List<File> files = Arrays.asList(outApp.listFiles());
+ List<File> files = Arrays.asList(Objects.requireNonNull(outApp.listFiles()));
assertEquals(5, files.size());
assertTrue(files.contains(new File(outApp, "services.xml")));
assertTrue(files.contains(new File(outApp, "hosts.xml")));
diff --git a/filedistribution/src/main/java/com/yahoo/vespa/filedistribution/FileReferenceCompressor.java b/filedistribution/src/main/java/com/yahoo/vespa/filedistribution/FileReferenceCompressor.java
index bcfeddacff3..080db640dfe 100644
--- a/filedistribution/src/main/java/com/yahoo/vespa/filedistribution/FileReferenceCompressor.java
+++ b/filedistribution/src/main/java/com/yahoo/vespa/filedistribution/FileReferenceCompressor.java
@@ -6,7 +6,6 @@ import com.yahoo.compress.ZstdOutputStream;
import net.jpountz.lz4.LZ4BlockInputStream;
import net.jpountz.lz4.LZ4BlockOutputStream;
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.TarArchiveInputStream;
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream;
@@ -18,7 +17,6 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
-import java.nio.file.Paths;
import java.util.List;
import java.util.Objects;
import java.util.logging.Level;
@@ -52,24 +50,23 @@ public class FileReferenceCompressor {
}
public File compress(File directory, File outputFile) throws IOException {
- return compress(directory,
- Files.find(Paths.get(directory.getAbsolutePath()),
- recurseDepth,
- (p, basicFileAttributes) -> basicFileAttributes.isRegularFile())
- .map(Path::toFile).toList(),
- outputFile);
+ try (var paths = Files.find(Path.of(directory.getAbsolutePath()), recurseDepth,
+ (p, basicFileAttributes) -> basicFileAttributes.isRegularFile()))
+ {
+ return compress(directory, paths.map(Path::toFile).toList(), outputFile);
+ }
}
public void decompress(File inputFile, File outputDir) throws IOException {
log.log(Level.FINEST, () -> "Decompressing '" + inputFile + "' into '" + outputDir + "'");
- try (ArchiveInputStream ais = new TarArchiveInputStream(decompressedInputStream(inputFile))) {
+ try (TarArchiveInputStream ais = new TarArchiveInputStream(decompressedInputStream(inputFile))) {
decompress(ais, outputDir);
} catch (IllegalArgumentException e) {
throw new RuntimeException("Unable to decompress '" + inputFile.getAbsolutePath() + "': " + e.getMessage());
}
}
- private static void decompress(ArchiveInputStream archiveInputStream, File outputFile) throws IOException {
+ private static void decompress(TarArchiveInputStream archiveInputStream, File outputFile) throws IOException {
int entries = 0;
ArchiveEntry entry;
while ((entry = archiveInputStream.getNextEntry()) != null) {
@@ -99,7 +96,7 @@ public class FileReferenceCompressor {
}
}
- private static void createArchiveFile(ArchiveOutputStream archiveOutputStream, File baseDir, List<File> inputFiles) throws IOException {
+ private static <T extends ArchiveEntry> void createArchiveFile(ArchiveOutputStream<T> archiveOutputStream, File baseDir, List<File> inputFiles) throws IOException {
inputFiles.forEach(file -> {
try {
writeFileToTar(archiveOutputStream, baseDir, file);
@@ -110,7 +107,7 @@ public class FileReferenceCompressor {
archiveOutputStream.close();
}
- private static void writeFileToTar(ArchiveOutputStream taos, File baseDir, File file) throws IOException {
+ private static <T extends ArchiveEntry> void writeFileToTar(ArchiveOutputStream<T> taos, File baseDir, File file) throws IOException {
taos.putArchiveEntry(taos.createArchiveEntry(file, baseDir.toPath().relativize(file.toPath()).toString()));
try (FileInputStream inputStream = new FileInputStream(file)) {
inputStream.transferTo(taos);
@@ -119,35 +116,33 @@ public class FileReferenceCompressor {
}
private OutputStream compressedOutputStream(File outputFile) throws IOException {
- switch (type) {
- case compressed:
+ return switch (type) {
+ case compressed -> {
log.log(Level.FINEST, () -> "Compressing with compression type " + compressionType);
- return switch (compressionType) {
+ yield switch (compressionType) {
case gzip -> new GZIPOutputStream(new FileOutputStream(outputFile));
case lz4 -> new LZ4BlockOutputStream(new FileOutputStream(outputFile));
case zstd -> new ZstdOutputStream(new FileOutputStream(outputFile));
};
- case file:
- return new FileOutputStream(outputFile);
- default:
- throw new RuntimeException("Unknown file reference type " + type);
- }
+ }
+ case file -> new FileOutputStream(outputFile);
+ default -> throw new RuntimeException("Unknown file reference type " + type);
+ };
}
private InputStream decompressedInputStream(File inputFile) throws IOException {
- switch (type) {
- case compressed:
+ return switch (type) {
+ case compressed -> {
log.log(Level.FINEST, () -> "Decompressing with compression type " + compressionType);
- return switch (compressionType) {
+ yield switch (compressionType) {
case gzip -> new GZIPInputStream(new FileInputStream(inputFile));
case lz4 -> new LZ4BlockInputStream(new FileInputStream(inputFile));
case zstd -> new ZstdInputStream(new FileInputStream(inputFile));
};
- case file:
- return new FileInputStream(inputFile);
- default:
- throw new RuntimeException("Unknown file reference type " + type);
- }
+ }
+ case file -> new FileInputStream(inputFile);
+ default -> throw new RuntimeException("Unknown file reference type " + type);
+ };
}
}