Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
CityDoctor
CityDoctor2
Commits
8f91ef99
Commit
8f91ef99
authored
3 months ago
by
Riegel
Browse files
Options
Download
Email Patches
Plain Diff
Refactor: Cleanup code
parent
ea8f25ae
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
CityDoctorParent/CityDoctorModel/src/main/java/de/hft/stuttgart/citydoctor2/zip/CityGmlZipEntry.java
+10
-18
...ava/de/hft/stuttgart/citydoctor2/zip/CityGmlZipEntry.java
with
10 additions
and
18 deletions
+10
-18
CityDoctorParent/CityDoctorModel/src/main/java/de/hft/stuttgart/citydoctor2/zip/CityGmlZipEntry.java
+
10
-
18
View file @
8f91ef99
...
...
@@ -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
m
axM
emory
>
size
;
return
memory
Limit
>
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
>
m
axM
emory
)
{
//Entry
will
exceed
available
memory
if
((
baos
.
size
()
/
MB
)
+
1
>
memory
Limit
)
{
//Entry exceed
s
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
m
axM
emory
>
size
;
size
=
(
long
)
Math
.
ceil
((
double
)
ze
.
getSize
()
/
MB
);
return
memory
Limit
>
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
;
...
...
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