use of org.nutz.lang.util.FileVisitor in project nutz by nutzam.
the class CleanCode method removeTabs.
public static int removeTabs(String path) {
final int[] re = new int[1];
Disks.visitFile(new File(path), new FileVisitor() {
public void visit(File file) {
if (file.isDirectory())
return;
if (!file.getName().endsWith(".java"))
return;
String str = Files.read(file);
if (!str.contains("\t"))
return;
str = str.replaceAll("\t", " ");
Files.write(file, str);
re[0]++;
}
}, null);
return re[0];
}
use of org.nutz.lang.util.FileVisitor in project nutz by nutzam.
the class UTF8_BOM method main.
public static void main(String[] args) {
final byte[] UTF_BOM = new byte[] { (byte) 0xEF, (byte) 0xBB, (byte) 0xBF };
final byte[] bom = new byte[3];
Disks.visitFile(new File("."), new FileVisitor() {
public void visit(File file) {
try {
FileInputStream fis = new FileInputStream(file);
fis.read(bom);
if (bom[0] == UTF_BOM[0] && bom[1] == UTF_BOM[1] && bom[2] == UTF_BOM[2]) {
System.out.println("Found BOM --> " + file);
byte[] data = Streams.readBytes(fis);
fis.close();
Files.write(file, data);
System.out.println("Fixed");
}
} catch (Throwable e) {
e.printStackTrace();
}
}
}, new FileFilter() {
public boolean accept(File pathname) {
if (pathname.isDirectory())
return true;
return pathname.getName().endsWith(".java") && pathname.length() > 3;
}
});
}
use of org.nutz.lang.util.FileVisitor in project nutz by nutzam.
the class PropertiesProxy method joinByKey.
/**
* 根据自身的一个键对应的值扩展自身的属性。
* <p>
* 本函数假设你可能有下面的键值:
*
* <pre>
* ...
* files:
* path/to_a.properties
* path/to_b.properties
* #End files
* </pre>
*
* 那么如果你调用 <code>joinByKey("files");</code> <br>
* 则会将其值的两个属性文件展开,加入到自身。
* <p>
* 属性文件的路径可以是磁盘全路径,或者在 CLASSPATH 里的路径
*
* @param key
* 键
* @return 自身
*/
public PropertiesProxy joinByKey(String key) {
String str = get(key);
final PropertiesProxy me = this;
if (!Strings.isBlank(str)) {
String[] ss = Strings.splitIgnoreBlank(str, "\n");
for (String s : ss) {
File f = Files.findFile(s);
if (null == f) {
throw Lang.makeThrow("Fail to found path '%s' in CLASSPATH or File System!", s);
}
// 如果是一个包,引用全部 Files
if (f.isDirectory()) {
Disks.visitFile(f, new FileVisitor() {
public void visit(File f) {
me.joinAndClose(Streams.fileInr(f));
}
}, new FileFilter() {
public boolean accept(File f) {
if (f.isDirectory())
return !f.isHidden() && !f.getName().startsWith(".");
return f.getName().endsWith(".properties");
}
});
} else // 否则引用单个文件
if (f.isFile()) {
this.joinAndClose(Streams.fileInr(f));
}
}
}
return this;
}
Aggregations