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
b312c808
Commit
b312c808
authored
3 months ago
by
Riegel
Browse files
Options
Download
Email Patches
Plain Diff
Refactor: Rework CityGmlArchive to use Streams for parsing
parent
7dea019b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
CityDoctorParent/Extensions/CityDoctorZipLoader/src/main/java/de/hft/stuttgart/citydoctor2/ziploader/CityGmlArchive.java
+15
-15
...e/hft/stuttgart/citydoctor2/ziploader/CityGmlArchive.java
with
15 additions
and
15 deletions
+15
-15
CityDoctorParent/Extensions/CityDoctorZipLoader/src/main/java/de/hft/stuttgart/citydoctor2/ziploader/CityGmlArchive.java
+
15
-
15
View file @
b312c808
...
...
@@ -8,6 +8,7 @@ import org.apache.commons.io.FileUtils;
import
org.apache.logging.log4j.LogManager
;
import
org.apache.logging.log4j.Logger
;
import
java.io.FileInputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.Serial
;
...
...
@@ -17,8 +18,11 @@ import java.nio.file.Paths;
import
java.util.ArrayList
;
import
java.util.Enumeration
;
import
java.util.List
;
import
java.util.stream.Collectors
;
import
java.util.stream.Stream
;
import
java.util.zip.ZipEntry
;
import
java.util.zip.ZipFile
;
import
java.util.zip.ZipInputStream
;
public
class
CityGmlArchive
{
...
...
@@ -31,29 +35,25 @@ public class CityGmlArchive {
public
static
CityGmlArchive
fromZipFile
(
String
zipFile
,
ParserConfiguration
config
)
{
ArrayList
<
CityGmlZipEntry
>
archiveEntries
=
new
ArrayList
<>();
Path
tmpDir
=
null
;
try
(
Zip
File
zipFileObj
=
new
ZipFile
(
zipFile
))
{
tmpDir
=
Files
.
createTempDirectory
(
"zipTmp"
);
tmpDir
.
toFile
().
deleteOnExit
()
;
for
(
Enumeration
<?
extends
ZipEntry
>
entries
=
zipFileObj
.
entries
();
entries
.
hasMoreElements
()
;
)
{
ZipEntry
entry
=
entries
.
nextElement
();
if
(
e
ntry
.
isDirectory
())
{
ZipFile
zip
=
null
;
try
(
Zip
InputStream
zis
=
new
ZipInputStream
(
new
FileInputStream
(
zipFile
))
;)
{
zip
=
new
ZipFile
(
zipFile
);
ZipEntry
ze
;
while
((
ze
=
zis
.
getNextEntry
())
!=
null
)
{
if
(
z
e
.
isDirectory
())
{
continue
;
}
if
(
entry
.
getName
().
endsWith
(
".gml"
))
{
InputStream
is
=
zipFileObj
.
getInputStream
(
entry
);
archiveEntries
.
add
(
CityGmlZipEntry
.
of
(
entry
,
config
,
zipFile
,
tmpDir
,
is
));
if
(
ze
.
getName
().
endsWith
(
".gml"
))
{
archiveEntries
.
add
(
CityGmlZipEntry
.
of
(
ze
,
zip
,
config
));
}
}
}
catch
(
IOException
e
)
{
logger
.
error
(
e
);
}
catch
(
Exception
e
){
// Catch and rethrow other Exceptions to ensure tmpDir deletion in finally block
throw
e
;
}
finally
{
if
(
tmpDir
!=
null
)
{
if
(
zip
!=
null
){
try
{
FileUtils
.
deleteDirectory
(
tmpDir
.
toFil
e
()
)
;
zip
.
clos
e
();
}
catch
(
IOException
e
)
{
logger
.
error
(
e
);
}
...
...
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