summaryrefslogtreecommitdiffstats
path: root/controller-server/src/main
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@oath.com>2021-06-18 10:18:58 +0200
committerGitHub <noreply@github.com>2021-06-18 10:18:58 +0200
commit535c296b9c51a1c8b94a3afbc8c38bed57c95cc2 (patch)
tree644859d3eb4d3a0bdc888c1b8e4544e39e0947ab /controller-server/src/main
parent0aa18d7fd68f42b778652f9e9e75034515b84b82 (diff)
parentc8a5556d50ac960f48c25067fd0ffd6ee64994fd (diff)
Merge pull request #18312 from vespa-engine/mpolden/faster-tests
Minor performance improvements to controller-server tests
Diffstat (limited to 'controller-server/src/main')
-rw-r--r--controller-server/src/main/java/com/yahoo/vespa/hosted/controller/application/ZipStreamReader.java17
1 files changed, 8 insertions, 9 deletions
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/application/ZipStreamReader.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/application/ZipStreamReader.java
index 2322b251fe0..4f01df21430 100644
--- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/application/ZipStreamReader.java
+++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/application/ZipStreamReader.java
@@ -1,15 +1,14 @@
// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.controller.application;
-import com.google.common.collect.ImmutableList;
-
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UncheckedIOException;
import java.nio.file.Path;
-import java.util.Arrays;
+import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import java.util.function.Predicate;
import java.util.zip.ZipEntry;
@@ -21,19 +20,19 @@ import java.util.zip.ZipOutputStream;
*/
public class ZipStreamReader {
- private final ImmutableList<ZipEntryWithContent> entries;
+ private final List<ZipEntryWithContent> entries = new ArrayList<>();
private final int maxEntrySizeInBytes;
public ZipStreamReader(InputStream input, Predicate<String> entryNameMatcher, int maxEntrySizeInBytes) {
this.maxEntrySizeInBytes = maxEntrySizeInBytes;
try (ZipInputStream zipInput = new ZipInputStream(input)) {
- ImmutableList.Builder<ZipEntryWithContent> builder = new ImmutableList.Builder<>();
ZipEntry zipEntry;
+
while (null != (zipEntry = zipInput.getNextEntry())) {
if (!entryNameMatcher.test(requireName(zipEntry.getName()))) continue;
- builder.add(new ZipEntryWithContent(zipEntry, readContent(zipInput)));
+ entries.add(new ZipEntryWithContent(zipEntry, readContent(zipInput)));
}
- entries = builder.build();
+
} catch (IOException e) {
throw new UncheckedIOException("IO error reading zip content", e);
}
@@ -79,10 +78,10 @@ public class ZipStreamReader {
}
}
- public List<ZipEntryWithContent> entries() { return entries; }
+ public List<ZipEntryWithContent> entries() { return Collections.unmodifiableList(entries); }
private static String requireName(String name) {
- if (Arrays.asList(name.split("/")).contains("..") ||
+ if (List.of(name.split("/")).contains("..") ||
!trimTrailingSlash(name).equals(Path.of(name).normalize().toString())) {
throw new IllegalArgumentException("Unexpected non-normalized path found in zip content: '" + name + "'");
}