devinsy-utils/test/FileIteratorSandbox.java

119 lines
3.7 KiB
Java
Raw Normal View History

2023-11-27 11:00:33 +01:00
/*
2023-11-27 11:00:33 +01:00
* Copyright (C) 2013-2023 Christian Pierre MOMON <christian@momon.org>
*
* This file is part of Devinsy-utils.
*
* Devinsy-utils is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Devinsy-utils is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Devinsy-utils. If not, see <http://www.gnu.org/licenses/>
*/
2013-06-25 02:31:19 +02:00
import java.io.File;
2023-11-27 11:00:33 +01:00
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.core.config.Configurator;
import org.apache.logging.log4j.core.config.DefaultConfiguration;
2013-06-26 16:40:18 +02:00
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
2013-06-25 02:31:19 +02:00
import fr.devinsy.util.FileIterator;
/**
* The Class FileIteratorSandbox.
2013-06-25 02:31:19 +02:00
*/
public class FileIteratorSandbox
2013-06-25 02:31:19 +02:00
{
private static Logger logger;
2013-06-25 02:31:19 +02:00
static
{
// Initialize logger.
2023-11-27 11:00:33 +01:00
Configurator.initialize(new DefaultConfiguration());
Configurator.setRootLevel(Level.DEBUG);
2013-06-25 02:31:19 +02:00
logger = LoggerFactory.getLogger(FileIteratorSandbox.class);
2013-06-25 02:31:19 +02:00
//
2023-11-27 11:00:33 +01:00
// org.apache.log4j.Logger defaultLogger =
// org.apache.log4j.Logger.getRootLogger();
// defaultLogger.removeAllAppenders();
// defaultLogger.addAppender(new ConsoleAppender(new
// PatternLayout("%d{ISO8601} - dutils [%-5p] %34.34c.%-25M - %m%n")));
2013-06-25 02:31:19 +02:00
//
logger.debug("Log initialized.");
}
2013-06-25 02:31:19 +02:00
/**
* The main method.
2013-06-25 02:31:19 +02:00
*
* @param args
* the arguments
2013-06-25 02:31:19 +02:00
*/
public static void main(final String[] args)
{
test();
}
2013-06-25 02:31:19 +02:00
/**
* Test.
2013-06-25 02:31:19 +02:00
*/
protected static void test()
{
System.out.println("user.dir=" + System.getProperty("user.dir"));
2013-06-25 02:31:19 +02:00
try
{
// File f = new File("TestTree/DirectoryOne/titi2");
// File f = new File("/home/cpm/.kde//cache-cpmstar");
File f = new File("tests/TestTree/xine.jpg");
System.out.println("exists=" + f.exists());
System.out.println("canonical path = " + f.getCanonicalPath());
System.out.println("absolute path = " + f.getAbsolutePath());
System.out.println("name = " + f.getName());
System.out.println("parent = " + f.getParent());
System.out.println("path = " + f.getPath());
System.out.println("path = " + f.lastModified());
System.out.println("path = " + f.length());
System.out.println("path = " + f.isFile());
System.out.println("path = " + f.isDirectory());
System.out.println("list = " + f.list());
2013-06-25 02:31:19 +02:00
System.out.println("----");
// FileIterator i = new FileIterator(new File("tests/TestTree"));
FileIterator i = new FileIterator(new File("tests/TestTree/xine.jpg"), null, true);
// FileIterator i = new FileIterator(new
// File("/home/cpm/.kde/cache-cpmstar"), ".*cache.*", false);
// FileIterator i = new FileIterator(new File("tests/TestTree"),
// ".*dsc.*", false);
// FileIterator i = new FileIterator(new
// File("/home/cpm/Images/Photos/"));
// FileIterator i = new FileIterator(new
// File("/home/cpm/Images/Photos/"), ".*\\.(JPG|jpg)", false);
// FileIterator i = new FileIterator(new
// File("/home/cpm/Images/Photos/"), ".*anni_moi.*", false);
2013-06-25 02:31:19 +02:00
while (i.hasNext())
{
// System.out.println(i.toString());
System.out.println("File=[" + i.next().getPath() + "]");
}
i.reset();
System.out.println("Cardinal=" + i.finalCountdown());
}
catch (Exception exception)
{
System.out.println("ERROR:" + exception.getMessage());
}
}
2013-06-25 02:31:19 +02:00
}