summaryrefslogtreecommitdiffstats
path: root/dozentenmodulserver/src
diff options
context:
space:
mode:
authorralph isenmann2022-01-27 11:35:09 +0100
committerralph isenmann2022-01-27 11:35:09 +0100
commitb0b1d7dc05e27f94cbca2e703eb0c6bfbc562e78 (patch)
tree855d7620221df4dda6b70550c028573c5f1f7b53 /dozentenmodulserver/src
parent[CLIENT] fix isPageValid check for container (diff)
downloadtutor-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 'dozentenmodulserver/src')
-rw-r--r--dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/web/WebServer.java33
1 files changed, 8 insertions, 25 deletions
diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/web/WebServer.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/web/WebServer.java
index 088cf5b0..f90a246a 100644
--- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/web/WebServer.java
+++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/web/WebServer.java
@@ -4,7 +4,6 @@ import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
-import java.nio.charset.StandardCharsets;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
@@ -13,14 +12,10 @@ import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
-import java.util.zip.GZIPOutputStream;
import org.apache.commons.io.output.ByteArrayOutputStream;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
-import org.kamranzafar.jtar.TarEntry;
-import org.kamranzafar.jtar.TarHeader;
-import org.kamranzafar.jtar.TarOutputStream;
import org.openslx.bwlp.sat.database.mappers.DbImage;
import org.openslx.bwlp.sat.database.mappers.DbLecture;
import org.openslx.bwlp.sat.database.mappers.DbLecture.LaunchData;
@@ -34,6 +29,7 @@ import org.openslx.bwlp.thrift.iface.TNotFoundException;
import org.openslx.util.GrowingThreadPoolExecutor;
import org.openslx.util.Json;
import org.openslx.util.Util;
+import org.openslx.util.TarArchiveUtil.TarArchiveWriter;
import org.simpleframework.xml.Serializer;
import org.simpleframework.xml.core.Persister;
@@ -130,19 +126,6 @@ public class WebServer extends NanoHTTPD {
Json.serialize(FileServer.instance().getStatus()));
}
- private static void tarPutFile(TarOutputStream output, String fileName, String data) throws IOException {
- if (data == null)
- return;
- tarPutFile(output, fileName, data.getBytes(StandardCharsets.UTF_8));
- }
-
- private static void tarPutFile(TarOutputStream output, String fileName, byte[] data) throws IOException {
- if (data == null)
- return;
- output.putNextEntry(new TarEntry(TarHeader.createHeader(fileName, data.length, Util.unixTime(), false, 0644)));
- output.write(data);
- }
-
/**
* Return meta data (eg. *.vmx) required to start the given lecture.
*
@@ -152,7 +135,7 @@ public class WebServer extends NanoHTTPD {
private Response serveMetaData(final String lectureId) {
PipedInputStream sink = new PipedInputStream(10000);
try {
- final TarOutputStream output = new TarOutputStream(new GZIPOutputStream(new PipedOutputStream(sink)));
+ final TarArchiveWriter tarArchiveWriter = new TarArchiveWriter(new PipedOutputStream(sink));
final LaunchData ld;
try {
ld = DbLecture.getClientLaunchData(lectureId);
@@ -167,20 +150,20 @@ public class WebServer extends NanoHTTPD {
@Override
public void run() {
try {
- tarPutFile(output, "vmx", ld.configuration);
- tarPutFile(output, "runscript", ld.legacyRunScript);
- tarPutFile(output, "netshares", serializeNetShares(ld.netShares));
+ tarArchiveWriter.writeFile("vmx", ld.configuration);
+ tarArchiveWriter.writeFile("runscript", ld.legacyRunScript);
+ tarArchiveWriter.writeFile("netshares", serializeNetShares(ld.netShares));
if (ld.runScript != null) {
int cnt = 0;
for (RunScript rs : ld.runScript) {
- tarPutFile(output, String.format("adminrun/%04d-%d-%d.%s", cnt++, rs.visibility,
- rs.passCreds ? 1 : 0, rs.extension), rs.content);
+ tarArchiveWriter.writeFile(String.format("adminrun/%04d-%d-%d.%s", cnt++, rs.visibility,
+ rs.passCreds ? 1 : 0, rs.extension), rs.content);
}
}
} catch (IOException e) {
LOGGER.warn("Error writing to tar stream", e);
} finally {
- Util.safeClose(output);
+ Util.safeClose(tarArchiveWriter);
}
}
});