devinsy-utils/tests/FileIteratorTester.java

93 lines
2.7 KiB
Java
Raw Normal View History

2010-06-21 03:15:31 +02:00
import java.io.File;
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.ConsoleAppender;
import org.apache.log4j.Logger;
import org.apache.log4j.PatternLayout;
import fr.devinsy.util.FileIterator;
/**
*
*/
public class FileIteratorTester
{
static private org.apache.log4j.Logger logger;
static
2013-06-20 01:08:32 +02:00
{
2010-06-21 03:15:31 +02:00
// Initialize logger.
2013-06-20 01:08:32 +02:00
BasicConfigurator.configure();
Logger defaultLogger = org.apache.log4j.Logger.getRootLogger();
defaultLogger.setLevel(org.apache.log4j.Level.DEBUG);
2010-06-21 03:15:31 +02:00
defaultLogger.removeAllAppenders();
defaultLogger.addAppender(new ConsoleAppender(new PatternLayout("%d{ISO8601} - FIT [%-5p] %34.34c.%-25M - %m%n")));
2013-06-20 01:08:32 +02:00
defaultLogger.debug("Log initialized.");
2010-06-21 03:15:31 +02:00
2013-06-20 01:08:32 +02:00
logger = org.apache.log4j.Logger.getLogger(FileIteratorTester.class.getName());
}
/**
*
*/
public static void main(final String[] args)
{
test();
2010-06-21 03:15:31 +02:00
}
/**
*
*/
protected static void test()
{
System.out.println("user.dir=" + System.getProperty("user.dir"));
try
{
2013-06-20 01:08:32 +02:00
// File f = new File("TestTree/DirectoryOne/titi2");
// File f = new File("/home/cpm/.kde//cache-cpmstar");
2010-06-21 04:29:09 +02:00
File f = new File("tests/TestTree/xine.jpg");
2010-06-21 03:15:31 +02:00
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-20 01:08:32 +02:00
2010-06-21 03:15:31 +02:00
System.out.println("----");
2013-06-20 01:08:32 +02:00
// FileIterator i = new FileIterator(new File("tests/TestTree"));
2010-06-21 04:29:09 +02:00
FileIterator i = new FileIterator(new File("tests/TestTree/xine.jpg"), null, true);
2013-06-20 01:08:32 +02:00
// 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);
2010-06-21 04:29:09 +02:00
2010-06-21 03:15:31 +02:00
while (i.hasNext())
{
2013-06-20 01:08:32 +02:00
// System.out.println(i.toString());
2010-06-21 03:15:31 +02:00
System.out.println("File=[" + i.next().getPath() + "]");
}
i.reset();
System.out.println("Cardinal=" + i.finalCountdown());
}
2013-06-20 01:08:32 +02:00
catch (Exception exception)
2010-06-21 03:15:31 +02:00
{
System.out.println("ERROR:" + exception.getMessage());
}
}
}