Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Dockerized Testing Toolkit
DTT Backend
Commits
5632b491
Verified
Commit
5632b491
authored
Dec 30, 2020
by
Lukas Wiest
🚂
Browse files
feat(util): add archive extraction utility
parent
0c799d5f
Changes
1
Show whitespace changes
Inline
Side-by-side
src/main/java/de/hftstuttgart/utils/ArchiveUtil.java
0 → 100644
View file @
5632b491
package
de.hftstuttgart.utils
;
import
org.apache.logging.log4j.LogManager
;
import
org.apache.logging.log4j.Logger
;
import
java.io.*
;
import
java.nio.file.Path
;
import
java.util.zip.ZipEntry
;
import
java.util.zip.ZipInputStream
;
public
class
ArchiveUtil
{
private
static
final
Logger
LOG
=
LogManager
.
getLogger
(
ArchiveUtil
.
class
);
public
static
void
extractProjectFromZip
(
InputStream
is
,
Path
outDir
)
throws
IOException
{
LOG
.
info
(
String
.
format
(
"starting archive extraction to %s"
,
outDir
.
toAbsolutePath
().
toString
()));
try
(
ZipInputStream
stream
=
new
ZipInputStream
(
is
))
{
ZipEntry
entry
;
while
((
entry
=
stream
.
getNextEntry
())
!=
null
)
{
File
file
=
outDir
.
resolve
(
entry
.
getName
()).
toFile
();
LOG
.
debug
(
String
.
format
(
"processing entry %s"
,
file
.
getAbsolutePath
()));
if
(!
entry
.
isDirectory
())
{
LOG
.
debug
(
"creating parent folders"
);
file
.
getParentFile
().
mkdirs
();
LOG
.
debug
(
"creating new file"
);
file
.
createNewFile
();
byte
[]
buffer
=
new
byte
[
2048
];
try
(
FileOutputStream
fos
=
new
FileOutputStream
(
file
);
BufferedOutputStream
bos
=
new
BufferedOutputStream
(
fos
,
buffer
.
length
))
{
LOG
.
debug
(
"writing content from zip entry to file"
);
int
len
;
while
((
len
=
stream
.
read
(
buffer
))
>
0
)
{
bos
.
write
(
buffer
,
0
,
len
);
}
}
}
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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