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; ...@@ -9,6 +9,7 @@ import de.hft.stuttgart.citydoctor2.parser.ParserConfiguration;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.nio.file.Files; import java.nio.file.Files;
...@@ -45,7 +46,7 @@ public class CityGmlZipEntry { ...@@ -45,7 +46,7 @@ public class CityGmlZipEntry {
try { try {
Files.copy(is, Path.of(tempDir.toString(), entry.getName())); Files.copy(is, Path.of(tempDir.toString(), entry.getName()));
CityGmlParser.gagLogger(true); 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) { } catch (CityGmlParseException | InvalidGmlFileException e) {
logger.error(e); logger.error(e);
cgzEntry.erroneousEntry = true; cgzEntry.erroneousEntry = true;
......
...@@ -11,6 +11,7 @@ import java.io.*; ...@@ -11,6 +11,7 @@ import java.io.*;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream; import java.util.zip.ZipOutputStream;
...@@ -34,7 +35,7 @@ public class ArchivePacker { ...@@ -34,7 +35,7 @@ public class ArchivePacker {
continue; continue;
} }
CityDoctorModel model = entry.getModel(); CityDoctorModel model = entry.getModel();
String filename = tmpDir.toString() + "\\" + entry.getFileName(); String filename = tmpDir.toString() + File.separator + entry.getFileName();
model.saveAs(filename, entry.isValidated()); model.saveAs(filename, entry.isValidated());
} }
zipDirectory(targetPath, tmpDir.toString()); zipDirectory(targetPath, tmpDir.toString());
...@@ -53,15 +54,11 @@ public class ArchivePacker { ...@@ -53,15 +54,11 @@ public class ArchivePacker {
} }
private static void zipDirectory(String targetPath, String sourcePath){ private static void zipDirectory(String targetPath, String sourcePath){
List<String> fileList = new ArrayList<>();
File directory = new File(sourcePath); File directory = new File(sourcePath);
for (String file : directory.list()){ List<String> fileList = new ArrayList<>(Arrays.asList(directory.list()));
fileList.add(file);
}
byte[] buffer = new byte[1024]; byte[] buffer = new byte[1024];
String source = new File(sourcePath).getName(); FileOutputStream fos;
FileOutputStream fos = null;
ZipOutputStream zos = null; ZipOutputStream zos = null;
try { try {
fos = new FileOutputStream(targetPath); fos = new FileOutputStream(targetPath);
...@@ -71,7 +68,8 @@ public class ArchivePacker { ...@@ -71,7 +68,8 @@ public class ArchivePacker {
ZipEntry ze = new ZipEntry(file); ZipEntry ze = new ZipEntry(file);
zos.putNextEntry(ze); zos.putNextEntry(ze);
try { try {
in = new FileInputStream(sourcePath +"\\" + file); Path sourceFile = Path.of(sourcePath+File.separator+file);
in = new FileInputStream(sourceFile.toAbsolutePath().toString());
int len; int len;
while ((len = in.read(buffer)) > 0) { while ((len = in.read(buffer)) > 0) {
zos.write(buffer, 0, len); zos.write(buffer, 0, len);
...@@ -87,10 +85,12 @@ public class ArchivePacker { ...@@ -87,10 +85,12 @@ public class ArchivePacker {
} catch (IOException e) { } catch (IOException e) {
logger.error(e); logger.error(e);
} finally { } finally {
try { if (zos != null) {
zos.close(); try {
} catch (IOException e) { zos.close();
logger.error(e); } 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