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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations