Skip to content
GitLab
Explore
Projects
Groups
Snippets
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
CityDoctor
CityDoctor2
Commits
31fcb511
Commit
31fcb511
authored
3 months ago
by
Riegel
Browse files
Options
Download
Email Patches
Plain Diff
Refactor: Streamline CityGmlZipEntry filesize calculation
parent
b7569651
master
dev
dev_cpp_code_conversion
dev_gui_features_zip_loading
dev_visitor_rework
3.17.0
archive/dev_gui_features_zip_loading
2 merge requests
!28
Version 3.17.0 Release
,
!26
Add ZIP-archive support
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
CityDoctorParent/CityDoctorModel/src/main/java/de/hft/stuttgart/citydoctor2/zip/CityGmlZipEntry.java
+19
-19
...ava/de/hft/stuttgart/citydoctor2/zip/CityGmlZipEntry.java
CityDoctorParent/CityDoctorModel/src/main/java/de/hft/stuttgart/citydoctor2/zip/CityGmlZipEntryFile.java
+14
-9
...de/hft/stuttgart/citydoctor2/zip/CityGmlZipEntryFile.java
with
33 additions
and
28 deletions
+33
-28
CityDoctorParent/CityDoctorModel/src/main/java/de/hft/stuttgart/citydoctor2/zip/CityGmlZipEntry.java
+
19
-
19
View file @
31fcb511
...
...
@@ -68,25 +68,26 @@ public class CityGmlZipEntry implements Serializable {
private
boolean
entrySizeWithinMemoryLimits
()
throws
IOException
{
long
memoryLimit
=
(
long
)
Math
.
ceil
(((
double
)
Runtime
.
getRuntime
().
maxMemory
()
/
MB
)*
0.9
);
if
(
fileSize
!
=
-
1L
)
{
return
memoryLimit
>
fileSize
;
}
try
(
CityGmlZipEntryFile
entryFile
=
new
CityGmlZipEntryFile
(
this
)
){
long
file
s
ize
=
entryFile
.
getFileS
ize
()
;
if
(
filesize
!=
-
1
)
{
this
.
fileSize
=
filesiz
e
;
return
memoryLimit
>
fileSize
;
}
else
{
return
false
;
if
(
fileSize
=
=
-
1L
)
{
try
(
CityGmlZipEntryFile
entryFile
=
new
CityGmlZipEntryFile
(
this
)){
long
filesize
=
entryFile
.
getFileSize
();
if
(
filesize
!=
-
1
){
this
.
file
S
ize
=
files
ize
;
}
else
{
return
fals
e
;
}
}
catch
(
Exception
e
)
{
throw
new
IOException
(
e
)
;
}
}
catch
(
Exception
e
)
{
throw
new
IOException
(
e
);
}
return
memoryLimit
>
fileSize
;
}
protected
CityGmlZipEntry
(
ZipEntry
entry
,
CityGmlZipArchive
parentArchive
,
boolean
decompressed
)
{
this
.
fileName
=
entry
.
getName
();
if
(
entry
.
getSize
()
!=
-
1
){
this
.
fileSize
=
entry
.
getSize
();
}
this
.
model
=
null
;
this
.
decompressed
=
decompressed
;
this
.
parentArchive
=
parentArchive
;
...
...
@@ -113,12 +114,11 @@ public class CityGmlZipEntry implements Serializable {
return
model
;
}
public
long
getFileSize
()
throws
IOException
{
if
(
fileSize
==
-
1L
){
try
(
CityGmlZipInputStream
cgis
=
new
CityGmlZipInputStream
(
this
)){
fileSize
=
cgis
.
getFileSize
();
}
}
public
void
setFileSize
(
long
size
)
{
fileSize
=
size
;
}
public
long
getFileSize
(){
return
fileSize
;
}
}
This diff is collapsed.
Click to expand it.
CityDoctorParent/CityDoctorModel/src/main/java/de/hft/stuttgart/citydoctor2/zip/CityGmlZipEntryFile.java
+
14
-
9
View file @
31fcb511
package
de.hft.stuttgart.citydoctor2.zip
;
import
java.io.ByteArrayOutputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.util.zip.ZipEntry
;
...
...
@@ -10,6 +9,7 @@ public class CityGmlZipEntryFile implements AutoCloseable {
private
final
ZipFile
zip
;
private
final
ZipEntry
zipEntry
;
private
final
CityGmlZipEntry
cgmlZipEntry
;
private
boolean
closed
=
false
;
private
static
final
long
MB
=
1024
*
1024L
;
...
...
@@ -17,6 +17,7 @@ public class CityGmlZipEntryFile implements AutoCloseable {
CityGmlZipArchive
archive
=
entry
.
getArchive
();
zip
=
new
ZipFile
(
archive
.
getArchivePath
().
toFile
());
zipEntry
=
zip
.
getEntry
(
entry
.
getFileName
());
this
.
cgmlZipEntry
=
entry
;
}
public
InputStream
getInputStream
()
throws
IOException
{
...
...
@@ -30,15 +31,19 @@ public class CityGmlZipEntryFile implements AutoCloseable {
if
(
closed
){
throw
new
IOException
(
"Stream closed"
);
}
if
(
zipEntry
.
getSize
()
!=
-
1
){
return
(
long
)
Math
.
ceil
((
double
)
zipEntry
.
getSize
()
/
MB
);
if
(
cgmlZipEntry
.
getFileSize
()
==
-
1L
)
{
if
(
zipEntry
.
getSize
()
==
-
1
)
{
long
bytes
=
0
;
InputStream
is
=
this
.
getInputStream
();
for
(
int
i
=
is
.
read
();
i
!=
-
1
;
i
=
is
.
read
())
{
bytes
++;
}
cgmlZipEntry
.
setFileSize
((
long
)
Math
.
ceil
((
double
)
bytes
/
MB
));
}
else
{
cgmlZipEntry
.
setFileSize
((
long
)
Math
.
ceil
((
double
)
zipEntry
.
getSize
()
/
MB
));
}
}
long
bytes
=
0
;
InputStream
is
=
this
.
getInputStream
();
for
(
int
i
=
is
.
read
();
i
!=
-
1
;
i
=
is
.
read
())
{
bytes
++;
}
return
(
long
)
Math
.
ceil
((
double
)
bytes
/
MB
);
return
cgmlZipEntry
.
getFileSize
();
}
@Override
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Snippets