Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
CoTA
cota-backend
Commits
2dd4adee
Commit
2dd4adee
authored
4 months ago
by
mamunozgil
Browse files
Options
Download
Email Patches
Plain Diff
Included logger and format in FileUtil class
parent
8f2a3683
Pipeline
#10396
passed with stage
in 17 seconds
Changes
1
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/de/hftstuttgart/dtabackend/utils/FileUtil.java
+26
-8
src/main/java/de/hftstuttgart/dtabackend/utils/FileUtil.java
with
26 additions
and
8 deletions
+26
-8
src/main/java/de/hftstuttgart/dtabackend/utils/FileUtil.java
+
26
-
8
View file @
2dd4adee
...
...
@@ -4,17 +4,21 @@ import java.io.File;
import
java.io.IOException
;
import
java.nio.file.Files
;
import
java.nio.file.Path
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
/**
* Helper Class for all file
related tasks.
* Helper Class for all file
-
related tasks.
*
* Created by Marcel Bochtler on 05.01.17.
*/
public
class
FileUtil
{
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
FileUtil
.
class
);
/**
* Delete the folder and all containing files.
* @param folder
Folder to delete
* @param folder Folder to delete
*/
public
static
void
deleteFolderRecursively
(
File
folder
)
{
File
[]
files
=
folder
.
listFiles
();
...
...
@@ -23,22 +27,36 @@ public class FileUtil {
if
(
f
.
isDirectory
())
{
deleteFolderRecursively
(
f
);
}
else
{
f
.
delete
();
System
.
out
.
println
(
String
.
format
(
"Deleted file: %s"
,
f
.
getAbsolutePath
()));
if
(
f
.
delete
())
{
LOG
.
debug
(
"Deleted file: {}"
,
f
.
getAbsolutePath
());
}
else
{
LOG
.
debug
(
"Failed to delete file: {}"
,
f
.
getAbsolutePath
());
}
}
}
}
folder
.
delete
();
System
.
out
.
println
(
String
.
format
(
"Deleted folder: %s"
,
folder
.
getAbsolutePath
()));
if
(
folder
.
delete
())
{
LOG
.
debug
(
"Deleted folder: {}"
,
folder
.
getAbsolutePath
());
}
else
{
LOG
.
debug
(
"Failed to delete folder: {}"
,
folder
.
getAbsolutePath
());
}
}
/**
* Copy the folder and its contents.
* @param src Source folder path
* @param dst Destination folder path
* @throws IOException if an I/O error occurs
*/
public
static
void
copyFolder
(
Path
src
,
Path
dst
)
throws
IOException
{
Files
.
walk
(
src
)
.
forEach
(
source
->
{
try
{
Files
.
copy
(
source
,
dst
.
resolve
(
src
.
relativize
(
source
)));
System
.
out
.
println
(
String
.
format
(
"Copying file from: %s to %s"
,
source
.
toString
(),
dst
.
resolve
(
src
.
relativize
(
source
)).
toString
()));
Path
destination
=
dst
.
resolve
(
src
.
relativize
(
source
));
Files
.
copy
(
source
,
destination
);
LOG
.
debug
(
"Copying file from: {} to {}"
,
source
,
destination
);
}
catch
(
IOException
e
)
{
LOG
.
debug
(
"Error copying file from: {} to {}"
,
source
,
dst
.
resolve
(
src
.
relativize
(
source
)),
e
);
throw
new
RuntimeException
(
e
.
getMessage
(),
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