Search in sources :

Example 1 with WildcardFindFile

use of jodd.io.findfile.WildcardFindFile in project jodd by oblac.

the class LagartoParserTest method testLiveHtmls.

/**
	 * 13s
	 */
@Test
public void testLiveHtmls() throws IOException {
    FindFile ff = new WildcardFindFile().include("**/*.html");
    ff.searchPath(testLiveRoot);
    File file;
    boolean processed = false;
    while ((file = ff.nextFile()) != null) {
        processed = true;
        String name = file.getName();
        System.out.println('+' + name);
        String content = FileUtil.readString(file);
        try {
            _parseEmpty(content);
        } catch (Exception ex) {
            ex.printStackTrace();
            fail(ex.toString());
        }
    }
    assertTrue(processed);
}
Also used : WildcardFindFile(jodd.io.findfile.WildcardFindFile) FindFile(jodd.io.findfile.FindFile) WildcardFindFile(jodd.io.findfile.WildcardFindFile) FindFile(jodd.io.findfile.FindFile) WildcardFindFile(jodd.io.findfile.WildcardFindFile) File(java.io.File) IOException(java.io.IOException) Test(org.junit.Test)

Example 2 with WildcardFindFile

use of jodd.io.findfile.WildcardFindFile in project jodd by oblac.

the class LagartoParserTest method _testHtmls.

private void _testHtmls(String root) throws IOException {
    FindFile ff = new WildcardFindFile().include("**/*.*ml");
    long reps = 1;
    JStopWatch jsw = new JStopWatch();
    boolean processed = false;
    while (reps-- > 0) {
        ff.searchPath(root);
        File file;
        while ((file = ff.nextFile()) != null) {
            processed = true;
            System.out.println('+' + file.getName());
            String content = FileUtil.readString(file);
            content = StringUtil.removeChars(content, '\r');
            String expectedResult = FileUtil.readString(new File(file.getAbsolutePath() + ".txt"));
            String formatted = null;
            File formattedFile = new File(file.getAbsolutePath() + "-fmt.htm");
            if (formattedFile.exists()) {
                formatted = FileUtil.readString(formattedFile);
            }
            if (formatted != null) {
                formatted = StringUtil.removeChars(formatted, '\r');
            }
            boolean isXml = file.getName().endsWith(".xml");
            String[] results = _parse(content, isXml);
            // parsing result
            String result = results[0];
            // tag writer
            String result2 = results[1];
            expectedResult = StringUtil.removeChars(expectedResult, '\r');
            result = StringUtil.removeChars(result, '\r').trim();
            result2 = StringUtil.removeChars(result2, '\r').trim();
            assertEquals(expectedResult, result);
            if (formatted != null) {
                assertEquals(formatted, result2);
            } else {
                assertEquals(content, result2);
            }
        }
    }
    assertTrue(processed);
    System.out.println(jsw);
}
Also used : WildcardFindFile(jodd.io.findfile.WildcardFindFile) FindFile(jodd.io.findfile.FindFile) WildcardFindFile(jodd.io.findfile.WildcardFindFile) FindFile(jodd.io.findfile.FindFile) WildcardFindFile(jodd.io.findfile.WildcardFindFile) File(java.io.File) JStopWatch(jodd.datetime.JStopWatch)

Example 3 with WildcardFindFile

use of jodd.io.findfile.WildcardFindFile in project jodd by oblac.

the class FindFileTest method testWildcardFile.

@Test
public void testWildcardFile() {
    FindFile ff = new WildcardFindFile().include("**/*file/a*").setRecursive(true).setIncludeDirs(true).searchPath(dataRoot);
    int countDirs = 0;
    int countFiles = 0;
    File f;
    while ((f = ff.nextFile()) != null) {
        if (f.isDirectory()) {
            countDirs++;
        } else {
            countFiles++;
            String path = f.getAbsolutePath();
            path = FileNameUtil.separatorsToUnix(path);
            if (!path.startsWith("/")) {
                path = '/' + path;
            }
            boolean matched = path.equals(dataRoot + "/file/a.png") || path.equals(dataRoot + "/file/a.txt");
            assertTrue(matched);
        }
    }
    assertEquals(0, countDirs);
    assertEquals(2, countFiles);
    ff.searchPath(dataRoot);
    countDirs = 0;
    countFiles = 0;
    Iterator<File> iterator = ff.iterator();
    while (iterator.hasNext()) {
        f = iterator.next();
        if (f.isDirectory()) {
            countDirs++;
        } else {
            countFiles++;
            String path = f.getAbsolutePath();
            path = FileNameUtil.separatorsToUnix(path);
            if (!path.startsWith("/")) {
                path = '/' + path;
            }
            boolean matched = path.equals(dataRoot + "/file/a.png") || path.equals(dataRoot + "/file/a.txt");
            assertTrue(matched);
        }
    }
    assertEquals(0, countDirs);
    assertEquals(2, countFiles);
}
Also used : WildcardFindFile(jodd.io.findfile.WildcardFindFile) FindFile(jodd.io.findfile.FindFile) RegExpFindFile(jodd.io.findfile.RegExpFindFile) WildcardFindFile(jodd.io.findfile.WildcardFindFile) FindFile(jodd.io.findfile.FindFile) RegExpFindFile(jodd.io.findfile.RegExpFindFile) WildcardFindFile(jodd.io.findfile.WildcardFindFile) File(java.io.File) Test(org.junit.Test)

Example 4 with WildcardFindFile

use of jodd.io.findfile.WildcardFindFile in project jodd by oblac.

the class FindFileTest method testTwoAccept.

@Test
public void testTwoAccept() {
    FindFile ff = new WildcardFindFile().include("**/*file/a.png").include("**/*file/a.txt").setRecursive(true).setIncludeDirs(true).searchPath(dataRoot);
    final MutableInteger countFiles = new MutableInteger();
    final MutableInteger countDirs = new MutableInteger();
    ff.find(new FileConsumer() {

        @Override
        public boolean onFile(File f) {
            if (f.isDirectory()) {
                countDirs.value++;
            } else {
                countFiles.value++;
                String path = f.getAbsolutePath();
                path = FileNameUtil.separatorsToUnix(path);
                if (!path.startsWith("/")) {
                    path = '/' + path;
                }
                boolean matched = path.equals(dataRoot + "/file/a.png") || path.equals(dataRoot + "/file/a.txt");
                assertTrue(matched);
            }
            return true;
        }
    });
    assertEquals(0, countDirs.value);
    assertEquals(2, countFiles.value);
}
Also used : MutableInteger(jodd.mutable.MutableInteger) WildcardFindFile(jodd.io.findfile.WildcardFindFile) FileConsumer(jodd.io.findfile.FileConsumer) FindFile(jodd.io.findfile.FindFile) RegExpFindFile(jodd.io.findfile.RegExpFindFile) WildcardFindFile(jodd.io.findfile.WildcardFindFile) FindFile(jodd.io.findfile.FindFile) RegExpFindFile(jodd.io.findfile.RegExpFindFile) WildcardFindFile(jodd.io.findfile.WildcardFindFile) File(java.io.File) Test(org.junit.Test)

Example 5 with WildcardFindFile

use of jodd.io.findfile.WildcardFindFile in project jodd by oblac.

the class FindFileTest method testWildcardPath.

@Test
public void testWildcardPath() {
    FindFile ff = new WildcardFindFile().include("**/file/*").setRecursive(true).setIncludeDirs(true).searchPath(dataRoot);
    int countDirs = 0;
    int countFiles = 0;
    File f;
    while ((f = ff.nextFile()) != null) {
        if (f.isDirectory()) {
            countDirs++;
        } else {
            countFiles++;
            String path = f.getAbsolutePath();
            path = FileNameUtil.separatorsToUnix(path);
            if (!path.startsWith("/")) {
                path = '/' + path;
            }
            boolean matched = path.equals(dataRoot + "/file/a.png") || path.equals(dataRoot + "/file/a.txt");
            assertTrue(matched);
        }
    }
    assertEquals(0, countDirs);
    assertEquals(2, countFiles);
}
Also used : WildcardFindFile(jodd.io.findfile.WildcardFindFile) FindFile(jodd.io.findfile.FindFile) RegExpFindFile(jodd.io.findfile.RegExpFindFile) WildcardFindFile(jodd.io.findfile.WildcardFindFile) FindFile(jodd.io.findfile.FindFile) RegExpFindFile(jodd.io.findfile.RegExpFindFile) WildcardFindFile(jodd.io.findfile.WildcardFindFile) File(java.io.File) Test(org.junit.Test)

Aggregations

File (java.io.File)6 FindFile (jodd.io.findfile.FindFile)6 WildcardFindFile (jodd.io.findfile.WildcardFindFile)6 Test (org.junit.Test)5 RegExpFindFile (jodd.io.findfile.RegExpFindFile)3 IOException (java.io.IOException)1 JStopWatch (jodd.datetime.JStopWatch)1 FastCharArrayWriter (jodd.io.FastCharArrayWriter)1 FileConsumer (jodd.io.findfile.FileConsumer)1 MutableInteger (jodd.mutable.MutableInteger)1