diff options
author | ralph isenmann | 2022-01-27 11:35:09 +0100 |
---|---|---|
committer | ralph isenmann | 2022-01-27 11:35:09 +0100 |
commit | b0b1d7dc05e27f94cbca2e703eb0c6bfbc562e78 (patch) | |
tree | 855d7620221df4dda6b70550c028573c5f1f7b53 /dozentenmodul/src | |
parent | [CLIENT] fix isPageValid check for container (diff) | |
download | tutor-module-b0b1d7dc05e27f94cbca2e703eb0c6bfbc562e78.tar.gz tutor-module-b0b1d7dc05e27f94cbca2e703eb0c6bfbc562e78.tar.xz tutor-module-b0b1d7dc05e27f94cbca2e703eb0c6bfbc562e78.zip |
[CLIENT,SERVER] move handling of tar into TarArchiveReader and TarArchiveWriter in master-sync-shared
Diffstat (limited to 'dozentenmodul/src')
-rw-r--r-- | dozentenmodul/src/main/java/org/openslx/dozmod/util/ContainerUtils.java | 42 |
1 files changed, 13 insertions, 29 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/util/ContainerUtils.java b/dozentenmodul/src/main/java/org/openslx/dozmod/util/ContainerUtils.java index 5f0dd887..783fb0fa 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/util/ContainerUtils.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/util/ContainerUtils.java @@ -5,9 +5,6 @@ import com.google.gson.JsonParser; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.thrift.TException; -import org.kamranzafar.jtar.TarEntry; -import org.kamranzafar.jtar.TarHeader; -import org.kamranzafar.jtar.TarInputStream; import org.openslx.bwlp.thrift.iface.ImageSummaryRead; import org.openslx.bwlp.thrift.iface.LectureSummary; import org.openslx.dozmod.gui.Gui; @@ -21,6 +18,8 @@ import org.openslx.dozmod.thrift.cache.LectureCache; import org.openslx.thrifthelper.TConst; import org.openslx.thrifthelper.ThriftManager; import org.openslx.util.ThriftUtil; +import org.openslx.util.Util; +import org.openslx.util.TarArchiveUtil.TarArchiveReader; import org.openslx.virtualization.configuration.container.ContainerMeta; import javax.swing.*; @@ -28,7 +27,6 @@ import java.awt.*; import java.io.*; import java.nio.ByteBuffer; import java.nio.charset.StandardCharsets; -import java.util.Arrays; import java.util.ArrayList; import java.util.List; @@ -124,39 +122,25 @@ public class ContainerUtils { JsonArray manifestJson = null; try { - TarInputStream tis = new TarInputStream(new FileInputStream(tarFile)); - ByteArrayOutputStream output = new ByteArrayOutputStream(); - byte[] rawData = new byte[1024]; - TarEntry entry; - - // setDefaultSkip seems to fasten things up while processing the file, - // because we want only to check manifest.json and repositories file - tis.setDefaultSkip(true); - while ((entry = tis.getNextEntry()) != null) { - if (!TarHeader.USTAR_MAGIC.equals(entry.getHeader().magic.toString())) - break; - Arrays.fill(rawData, (byte) 0); - output.reset(); - int count = 0; - - if (entry.getName().equals("manifest.json")) { + TarArchiveReader tarReader = new TarArchiveReader(new FileInputStream(tarFile)); + + while (tarReader.hasNextEntry()) { + if (tarReader.getEntryName().equals("manifest.json")) { containsManifest = true; - while ((count = tis.read(rawData)) != -1) { - output.write(rawData, 0, count); - } - manifestJson = JsonParser.parseString(new String(output.toByteArray(), StandardCharsets.UTF_8)) - .getAsJsonArray(); + manifestJson = JsonParser.parseString(new String(tarReader.readCurrentEntry(), StandardCharsets.UTF_8)) + .getAsJsonArray(); } - - if (entry.getName().equals("repositories")) { + + if (tarReader.getEntryName().equals("repositories")) { containsRepositories = true; - // dont read the file, no checks for the Content + // just check if the file exists } if (containsManifest && containsRepositories) break; } - tis.close(); + Util.safeClose(tarReader); + // check the json files inside the tar file if (containsManifest && containsRepositories && manifestJson.isJsonArray() && manifestJson.size() == 1) { isValid = true; |