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

Refactor: Move handling of ZipEntry copy to CityGmlZipEntry

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