Commit cdc6fd14 authored by Riegel's avatar Riegel
Browse files

Fix: Make parsing of path OS-agnostic

2 merge requests!28Version 3.17.0 Release,!26Add ZIP-archive support
Showing with 14 additions and 13 deletions
+14 -13
......@@ -9,6 +9,7 @@ import de.hft.stuttgart.citydoctor2.parser.ParserConfiguration;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
......@@ -45,7 +46,7 @@ public class CityGmlZipEntry {
try {
Files.copy(is, Path.of(tempDir.toString(), entry.getName()));
CityGmlParser.gagLogger(true);
cgzEntry.model = CityGmlParser.parseCityGmlFile(tempDir.toString() + "\\" + entry.getName(), config);
cgzEntry.model = CityGmlParser.parseCityGmlFile(tempDir.toString() + File.separator + entry.getName(), config);
} catch (CityGmlParseException | InvalidGmlFileException e) {
logger.error(e);
cgzEntry.erroneousEntry = true;
......
......@@ -11,6 +11,7 @@ import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
......@@ -34,7 +35,7 @@ public class ArchivePacker {
continue;
}
CityDoctorModel model = entry.getModel();
String filename = tmpDir.toString() + "\\" + entry.getFileName();
String filename = tmpDir.toString() + File.separator + entry.getFileName();
model.saveAs(filename, entry.isValidated());
}
zipDirectory(targetPath, tmpDir.toString());
......@@ -53,15 +54,11 @@ public class ArchivePacker {
}
private static void zipDirectory(String targetPath, String sourcePath){
List<String> fileList = new ArrayList<>();
File directory = new File(sourcePath);
for (String file : directory.list()){
fileList.add(file);
}
List<String> fileList = new ArrayList<>(Arrays.asList(directory.list()));
byte[] buffer = new byte[1024];
String source = new File(sourcePath).getName();
FileOutputStream fos = null;
FileOutputStream fos;
ZipOutputStream zos = null;
try {
fos = new FileOutputStream(targetPath);
......@@ -71,7 +68,8 @@ public class ArchivePacker {
ZipEntry ze = new ZipEntry(file);
zos.putNextEntry(ze);
try {
in = new FileInputStream(sourcePath +"\\" + file);
Path sourceFile = Path.of(sourcePath+File.separator+file);
in = new FileInputStream(sourceFile.toAbsolutePath().toString());
int len;
while ((len = in.read(buffer)) > 0) {
zos.write(buffer, 0, len);
......@@ -87,10 +85,12 @@ public class ArchivePacker {
} catch (IOException e) {
logger.error(e);
} finally {
try {
zos.close();
} catch (IOException e) {
logger.error(e);
if (zos != null) {
try {
zos.close();
} catch (IOException e) {
logger.error(e);
}
}
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment