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
7b4cf959
Commit
7b4cf959
authored
3 months ago
by
Riegel
Browse files
Options
Download
Email Patches
Plain Diff
Refactor: Use try-with-resources
parent
31399b0d
master
dev
dev_cpp_code_conversion
dev_gui_features_zip_loading
3.17.0
archive/dev_gui_features_zip_loading
2 merge requests
!28
Version 3.17.0 Release
,
!26
Add ZIP-archive support
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
CityDoctorParent/CityDoctorModel/src/main/java/de/hft/stuttgart/citydoctor2/utils/ArchivePacker.java
+9
-24
...ava/de/hft/stuttgart/citydoctor2/utils/ArchivePacker.java
with
9 additions
and
24 deletions
+9
-24
CityDoctorParent/CityDoctorModel/src/main/java/de/hft/stuttgart/citydoctor2/utils/ArchivePacker.java
+
9
-
24
View file @
7b4cf959
...
...
@@ -36,7 +36,7 @@ public class ArchivePacker {
}
CityDoctorModel
model
=
entry
.
getModel
();
String
filename
=
tmpDir
.
toString
()
+
File
.
separator
+
entry
.
getFileName
();
model
.
saveAs
(
filename
,
entry
.
isValidated
());
model
.
saveAs
(
filename
,
model
.
isValidated
());
}
zipDirectory
(
targetPath
,
tmpDir
.
toString
());
...
...
@@ -55,43 +55,28 @@ public class ArchivePacker {
private
static
void
zipDirectory
(
String
targetPath
,
String
sourcePath
){
File
directory
=
new
File
(
sourcePath
);
if
(!
directory
.
exists
()){
throw
new
IllegalStateException
(
"Directory "
+
sourcePath
+
" does not exist"
);
}
List
<
String
>
fileList
=
new
ArrayList
<>(
Arrays
.
asList
(
directory
.
list
()));
byte
[]
buffer
=
new
byte
[
1024
];
FileOutputStream
fos
;
ZipOutputStream
zos
=
null
;
try
{
fos
=
new
FileOutputStream
(
targetPath
);
zos
=
new
ZipOutputStream
(
fos
);
FileInputStream
in
=
null
;
try
(
FileOutputStream
fos
=
new
FileOutputStream
(
targetPath
);
ZipOutputStream
zos
=
new
ZipOutputStream
(
fos
)){
for
(
String
file
:
fileList
){
ZipEntry
ze
=
new
ZipEntry
(
file
);
zos
.
putNextEntry
(
ze
);
try
{
Path
sourceFile
=
Path
.
of
(
sourcePath
+
File
.
separator
+
file
);
in
=
new
FileInputStream
(
sourceFile
.
toAbsolutePath
().
toString
());
Path
sourceFile
=
Path
.
of
(
sourcePath
+
File
.
separator
+
file
);
try
(
FileInputStream
in
=
new
FileInputStream
(
sourceFile
.
toAbsolutePath
().
toString
())){
int
len
;
while
((
len
=
in
.
read
(
buffer
))
>
0
)
{
zos
.
write
(
buffer
,
0
,
len
);
}
}
finally
{
if
(
in
!=
null
)
{
in
.
close
();
}
}
}
zos
.
closeEntry
();
logger
.
info
(
"Successfully created zip-archive"
);
}
catch
(
IOException
e
)
{
logger
.
error
(
e
);
}
finally
{
if
(
zos
!=
null
)
{
try
{
zos
.
close
();
}
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
Menu
Explore
Projects
Groups
Snippets