mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-03-06 12:20:56 +01:00
improve IOUtil
This commit is contained in:
@@ -292,6 +292,20 @@ public class IOUtil
|
||||
* @throws IOException
|
||||
*/
|
||||
public static void delete(File file) throws IOException
|
||||
{
|
||||
delete(file, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param file
|
||||
* @param silent
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
public static void delete(File file, boolean silent) throws IOException
|
||||
{
|
||||
if (file.isDirectory())
|
||||
{
|
||||
@@ -308,7 +322,16 @@ public class IOUtil
|
||||
|
||||
if (!file.delete())
|
||||
{
|
||||
throw new IOException("could not delete file ".concat(file.getPath()));
|
||||
String message = "could not delete file ".concat(file.getPath());
|
||||
|
||||
if (silent)
|
||||
{
|
||||
logger.error(message);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new IOException(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -326,13 +349,29 @@ public class IOUtil
|
||||
{
|
||||
String name = archive.getName().toLowerCase();
|
||||
|
||||
if (name.endsWith(ZipUnArchiver.EXTENSION))
|
||||
extract(archive, outputDirectory, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param archive
|
||||
* @param outputDirectory
|
||||
* @param type
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
public static void extract(File archive, File outputDirectory, String type)
|
||||
throws IOException
|
||||
{
|
||||
if (type.endsWith(ZipUnArchiver.EXTENSION))
|
||||
{
|
||||
new ZipUnArchiver().extract(archive, outputDirectory);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new IOException("no unarchiver found for ".concat(name));
|
||||
throw new IOException("no unarchiver found for ".concat(type));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user