本文整理汇总了Java中edu.umd.cs.findbugs.charsets.UTF8.fileReader方法的典型用法代码示例。如果您正苦于以下问题:Java UTF8.fileReader方法的具体用法?Java UTF8.fileReader怎么用?Java UTF8.fileReader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类edu.umd.cs.findbugs.charsets.UTF8
的用法示例。
在下文中一共展示了UTF8.fileReader方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: fix
import edu.umd.cs.findbugs.charsets.UTF8; //导入方法依赖的package包/类
static void fix(File fileToUpdate, boolean partial) throws IOException {
boolean anyChanges = false;
BufferedReader in = new BufferedReader(UTF8.fileReader(fileToUpdate));
examined++;
StringWriter stringWriter = new StringWriter();
PrintWriter out = new PrintWriter(stringWriter);
int consecutiveFixes = 0;
try {
while (true) {
String s = in.readLine();
if (s == null)
break;
if (s.trim().length() > 0)
lines++;
String s2 = fix(s);
if (!s2.equals(s)) {
consecutiveFixes++;
if (consecutiveFixes > 3 && partial) {
s2 = s;
consecutiveFixes = 0;
} else
anyChanges = true;
} else
consecutiveFixes = 0;
out.println(s2);
}
} finally {
in.close();
}
if (!anyChanges)
return;
updated++;
if (!performUpdate) {
System.out.println("Would update " + fileToUpdate);
return;
}
System.out.println("Updating " + fileToUpdate);
StringReader stringReader = new StringReader(stringWriter.toString());
Writer outFile = SourceCharset.fileWriter(fileToUpdate);
char[] buffer = new char[4000];
try {
while (true) {
int sz = stringReader.read(buffer);
if (sz < 0)
break;
outFile.write(buffer, 0, sz);
}
} finally {
outFile.close();
}
}