Improved not exist file case.

This commit is contained in:
Christian P. MOMON 2021-04-26 19:53:41 +02:00
parent 25e0fb5f64
commit bb25cfa96d
2 changed files with 75 additions and 42 deletions

View File

@ -392,6 +392,16 @@ public final class Logar
* the source
*/
public static void checkLogFiles(final File source)
{
if (source == null)
{
System.out.println("Undefined source.");
}
else if (source.exists())
{
System.out.println("Missing source to check.");
}
else
{
Files files = FilesUtils.search(source, LOGFILE_PATTERN).sortByName();
@ -400,6 +410,7 @@ public final class Logar
checkLogFile(file);
}
}
}
/**
* Check sort.
@ -409,6 +420,16 @@ public final class Logar
* @throws IOException
*/
public static void checkSort(final File source) throws IOException
{
if (source == null)
{
System.out.println("Undefined source.");
}
else if (source.exists())
{
System.out.println("Missing source to check.");
}
else
{
Files files = FilesUtils.search(source, LOGFILE_PATTERN).sortByName();
@ -417,6 +438,7 @@ public final class Logar
checkSortFile(file);
}
}
}
/**
* Check sort file.
@ -482,6 +504,16 @@ public final class Logar
* Signals that an I/O exception has occurred.
*/
public static void sort(final File source) throws IOException
{
if (source == null)
{
System.out.println("Undefined source.");
}
else if (source.exists())
{
System.out.println("Missing source to sort.");
}
else
{
Files files = FilesUtils.searchEndingWith(source, LOGFILE_PATTERN).removeHidden().sortByName();
@ -491,6 +523,7 @@ public final class Logar
LogFile.sortLogFile(file);
}
}
}
/**
* Check concate.

View File

@ -48,7 +48,7 @@ public class FilesUtils
Files result;
result = new Files();
if (source != null)
if ((source != null) && (source.exists()))
{
if (source.isFile())
{
@ -74,34 +74,6 @@ public class FilesUtils
return result;
}
/**
* List recursively.
*
* @param source
* the source
* @param extensions
* the extensions
* @return the files
*/
public static Files searchEndingWith(final File source, final String... extensions)
{
Files result;
result = new Files();
Files full = listRecursively(source);
for (File file : full)
{
if (StringUtils.endsWithAny(file.getName(), extensions))
{
result.add(file);
}
}
//
return result;
}
/**
* Search recursively.
*
@ -131,4 +103,32 @@ public class FilesUtils
//
return result;
}
/**
* List recursively.
*
* @param source
* the source
* @param extensions
* the extensions
* @return the files
*/
public static Files searchEndingWith(final File source, final String... extensions)
{
Files result;
result = new Files();
Files full = listRecursively(source);
for (File file : full)
{
if (StringUtils.endsWithAny(file.getName(), extensions))
{
result.add(file);
}
}
//
return result;
}
}