本文整理匯總了Java中com.google.common.io.CharStreams.readLines方法的典型用法代碼示例。如果您正苦於以下問題:Java CharStreams.readLines方法的具體用法?Java CharStreams.readLines怎麽用?Java CharStreams.readLines使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.common.io.CharStreams
的用法示例。
在下文中一共展示了CharStreams.readLines方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: withLineNumbers
import com.google.common.io.CharStreams; //導入方法依賴的package包/類
private String withLineNumbers(String code) {
try {
return CharStreams.readLines(new StringReader(code), new LineProcessor<String>() {
private final StringBuilder lines = new StringBuilder();
private int lineNo = 1;
@Override
public boolean processLine(String line) throws IOException {
lines.append(Strings.padStart(String.valueOf(lineNo++), 3, ' ')).append(": ").append(line)
.append("\n");
return true;
}
@Override
public String getResult() {
return lines.toString();
}
});
} catch (IOException e) {
throw new IllegalStateException(e.getMessage());
}
}
示例2: parse
import com.google.common.io.CharStreams; //導入方法依賴的package包/類
@Override
public Script parse(InputStream in, URI uriToUse, Map<?, ?> options, ResourceSet resourceSet) {
if (active) {
if (in instanceof LazyStringInputStream) {
try {
String string = ((LazyStringInputStream) in).getString();
if (string.length() < 1000 && seen.add(string)) {
List<String> lines = CharStreams.readLines(new StringReader(string));
if (lines.size() < 50) {
System.out.println("\[email protected]");
System.out.format("\tdef void test_%04d() {", counter++);
System.out.println();
System.out.println("\t\t'''");
for (String s : lines) {
System.out.print("\t\t\t");
System.out.println(s);
}
System.out.println("\t\t'''.assertNoException");
System.out.println("\t}");
System.out.println();
}
}
} catch (IOException e) {
// ignore
}
}
}
return super.parse(in, uriToUse, options, resourceSet);
}
示例3: getFileLines
import com.google.common.io.CharStreams; //導入方法依賴的package包/類
/**
* @param resourceName
* the classpath-relative location of the to-be-read resource
*/
private static List<String> getFileLines(final String resourceName) throws IOException {
InputSupplier<InputStreamReader> readerSupplier = CharStreams.newReaderSupplier(
new InputSupplier<InputStream>() {
@Override
public InputStream getInput() throws IOException {
return Thread.currentThread().getContextClassLoader().getResourceAsStream(resourceName);
}
}, Charsets.UTF_8);
return CharStreams.readLines(readerSupplier);
}
示例4: parseText
import com.google.common.io.CharStreams; //導入方法依賴的package包/類
static
public Iterator<String> parseText(InputStream is) throws IOException {
Reader reader = new InputStreamReader(is, "US-ASCII");
List<String> lines = CharStreams.readLines(reader);
return lines.iterator();
}