Commit 8f91ef99 authored by Riegel's avatar Riegel
Browse files

Refactor: Cleanup code

parent ea8f25ae
Showing with 10 additions and 18 deletions
+10 -18
......@@ -24,6 +24,7 @@ public class CityGmlZipEntry {
private boolean validated = false;
private boolean decompressed = false;
private long size = -1L;
private static final long MB = 1024 * 1024L;
public static CityGmlZipEntry of(ZipEntry entry, ZipFile archive, ParserConfiguration config){
CityGmlZipEntry ze = CityGmlZipEntry.register(entry);
......@@ -57,45 +58,36 @@ public class CityGmlZipEntry {
}
private boolean entrySizeWithinMemoryLimits(ZipEntry ze, ZipFile zip) throws IOException {
long mb = 1024 * 1024L;
long maxMemory = (long) Math.ceil(((double) Runtime.getRuntime().maxMemory() / mb)*0.9);
long memoryLimit = (long) Math.ceil(((double) Runtime.getRuntime().maxMemory() / MB)*0.9);
if (size != -1L){
return maxMemory > size;
return memoryLimit > size;
}
if (ze.getSize() == -1L){
//unknown filesize, check by streaming file
InputStream is = zip.getInputStream(ze);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
for(int i = is.read(); i != -1;i=is.read()) {
for(int i = is.read(); i != -1; i=is.read()) {
baos.write(i);
if ((baos.size() / mb) + 1 > maxMemory) {
//Entry will exceed available memory
if ((baos.size() / MB) + 1 > memoryLimit) {
//Entry exceeds memory limit
return false;
}
}
// end of stream reached
// end of stream reached without exceeding memory limit
this.size = baos.size();
return true;
} else {
size = (long) Math.ceil((double) ze.getSize() / mb);
return maxMemory > size;
size = (long) Math.ceil((double) ze.getSize() / MB);
return memoryLimit > size;
}
}
private CityGmlZipEntry(ZipEntry entry, CityDoctorModel model){
this.fileName = entry.getName();
this.model = model;
}
protected CityGmlZipEntry(ZipEntry entry, boolean decompressed) {
this.fileName = entry.getName();
this.model = null;
this.decompressed = decompressed;
}
private static int calculateEntrySize(ZipEntry entry, ZipFile archive) {
try {
InputStream is = archive.getInputStream(entry);
public void setArchive(CityGmlZipArchive archive){
parentArchive = archive;
......
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