An error occurred while loading the file. Please try again.
-
Lückemeyer authored
Initial commit of the backend for the fork of the Moodle Dockerized Test Agent (MoDTA) from the Moodle Dockerized Test Tool (MoodleDTT)
5372c0e5
package de.hftstuttgart.dtabackend.utils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.io.*;
import java.nio.file.Path;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
public class ArchiveUtil
{
private static final Logger LOG = LogManager.getLogger(ArchiveUtil.class);
public static void extractProjectFromZip (InputStream is, Path outDir) throws IOException
{
LOG.info(String.format("starting archive extraction to %s", outDir.toAbsolutePath().toString()));
try (ZipInputStream stream = new ZipInputStream(is)) {
ZipEntry entry;
while ((entry = stream.getNextEntry()) != null) {
File file = outDir.resolve(entry.getName()).toFile();
LOG.debug(String.format("processing entry %s", file.getAbsolutePath()));
if (!entry.isDirectory()) {
LOG.debug("creating parent folders");
file.getParentFile().mkdirs();
LOG.debug("creating new file");
file.createNewFile();
byte[] buffer = new byte[2048];
try (FileOutputStream fos = new FileOutputStream(file);
BufferedOutputStream bos = new BufferedOutputStream(fos, buffer.length)) {
LOG.debug("writing content from zip entry to file");
int len;
while ((len = stream.read(buffer)) > 0) {
bos.write(buffer, 0, len);
}
}
}
}
}
}
}