Commit 7720966b authored by Riegel's avatar Riegel
Browse files

Refactor: Move handling of ZipEntry copy to CityGmlZipEntry

parent a2e711c1
Showing with 29 additions and 9 deletions
+29 -9
......@@ -42,13 +42,13 @@ public class CityGmlArchive {
}
if (entry.getName().endsWith(".gml")) {
InputStream is = zipFileObj.getInputStream(entry);
Files.copy(is, Path.of( tmpDir.toString(),entry.getName()));
archiveEntries.add(CityGmlZipEntry.of(entry, config, zipFile, tmpDir));
archiveEntries.add(CityGmlZipEntry.of(entry, config, zipFile, tmpDir, is));
}
}
} catch (IOException e) {
throw new RuntimeException(e);
} catch (Exception e){
// Catch and rethrow Exception to ensure tmpDir deletion
throw e;
} finally {
if (tmpDir != null) {
......
......@@ -10,15 +10,20 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
public class CityGmlZipEntry {
private static final Logger logger = LogManager.getLogger(CityGmlZipEntry.class);
public enum ZipEntryErrorType {
INVALID_CITY_GML_FILE, EXCESSIVE_FILESIZE, IO_ERROR
}
private String fileName;
private String archivePath;
......@@ -27,18 +32,29 @@ public class CityGmlZipEntry {
private boolean erroneousEntry = false;
private boolean isLibraryObject = false;
private boolean validated = false;
private ZipEntryErrorType errorType = null;
public static CityGmlZipEntry of(ZipEntry entry, ParserConfiguration config, String archivePath, Path tempDir){
public static CityGmlZipEntry of(ZipEntry entry, ParserConfiguration config, String archivePath, Path tempDir, InputStream is){
CityGmlZipEntry cgzEntry = new CityGmlZipEntry();
cgzEntry.fileName = entry.getName();
cgzEntry.archivePath = archivePath;
try {
CityGmlParser.gagLogger(true);
cgzEntry.model = CityGmlParser.parseCityGmlFile(tempDir.toString() +"\\" +entry.getName(), config);
}
catch (CityGmlParseException | InvalidGmlFileException e) {
logger.error(e);
if ((double) entry.getSize() /1024/1024 > 20) {
cgzEntry.erroneousEntry = true;
cgzEntry.errorType = ZipEntryErrorType.EXCESSIVE_FILESIZE;
} else {
try {
Files.copy(is, Path.of(tempDir.toString(), entry.getName()));
CityGmlParser.gagLogger(true);
cgzEntry.model = CityGmlParser.parseCityGmlFile(tempDir.toString() + "\\" + entry.getName(), config);
} catch (CityGmlParseException | InvalidGmlFileException e) {
logger.error(e);
cgzEntry.erroneousEntry = true;
cgzEntry.errorType = ZipEntryErrorType.INVALID_CITY_GML_FILE;
} catch (IOException e){
logger.error(e);
cgzEntry.erroneousEntry = true;
cgzEntry.errorType = ZipEntryErrorType.IO_ERROR;
}
}
return cgzEntry;
}
......@@ -72,6 +88,10 @@ public class CityGmlZipEntry {
return model;
}
public ZipEntryErrorType getErrorType() {
return errorType;
}
public boolean isLibraryObject() {
return isLibraryObject;
}
......
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