When zipping files, rename the outer folder to "data" instead of using the original folder name. This means that the data can be accessed deterministically without the need to first lookup the folder name.

This commit is contained in:
CalDescent 2021-06-23 08:09:59 +01:00
parent 1c6428dd3b
commit 3f20fadb81
2 changed files with 6 additions and 3 deletions

View File

@ -131,7 +131,7 @@ public class DataResource {
// Firstly zip up the directory
String outputFilePath = "temp/zipped.zip";
try {
ZipUtils.zip(directoryPath, outputFilePath);
ZipUtils.zip(directoryPath, outputFilePath, "data");
} catch (IOException e) {
LOGGER.info("Unable to zip directory", e);
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.INVALID_DATA);

View File

@ -18,11 +18,14 @@ import java.util.zip.ZipOutputStream;
public class ZipUtils {
public static void zip(String sourcePath, String destFilePath) throws IOException {
public static void zip(String sourcePath, String destFilePath, String fileName) throws IOException {
File sourceFile = new File(sourcePath);
if (fileName == null) {
fileName = sourceFile.getName();
}
FileOutputStream fileOutputStream = new FileOutputStream(destFilePath);
ZipOutputStream zipOutputStream = new ZipOutputStream(fileOutputStream);
ZipUtils.zip(sourceFile, sourceFile.getName(), zipOutputStream);
ZipUtils.zip(sourceFile, fileName, zipOutputStream);
zipOutputStream.close();
fileOutputStream.close();
}