本文整理汇总了Java中com.google.common.io.CharSource.openBufferedStream方法的典型用法代码示例。如果您正苦于以下问题:Java CharSource.openBufferedStream方法的具体用法?Java CharSource.openBufferedStream怎么用?Java CharSource.openBufferedStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.io.CharSource
的用法示例。
在下文中一共展示了CharSource.openBufferedStream方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadCorpusEventFrames
import com.google.common.io.CharSource; //导入方法依赖的package包/类
@Override
public CorpusEventLinking loadCorpusEventFrames(final CharSource source)
throws IOException {
int lineNo = 1;
try (final BufferedReader in = source.openBufferedStream()) {
final ImmutableSet.Builder<CorpusEventFrame> ret = ImmutableSet.builder();
String line;
while ((line = in.readLine()) != null) {
if (!line.isEmpty() && !line.startsWith("#")) {
// check for blank or comment lines
ret.add(parseLine(line));
}
}
return CorpusEventLinking.of(ret.build());
} catch (Exception e) {
throw new IOException("Error on line " + lineNo + " of " + source, e);
}
}
示例2: loadDictionary
import com.google.common.io.CharSource; //导入方法依赖的package包/类
/**
* Load the word frequency list, skipping words that are not in the given white list.
*
* @param whitelist The white list.
* @return A Dictomation dictionary with the word probabilities.
* @throws IOException
* @throws DictionaryBuilderException
*/
public static DictomatonDictionary loadDictionary(Set<String> whitelist) throws IOException, DictionaryBuilderException {
CharSource source = getResource(WORD_FREQUENCIES_FILE);
DictomatonDictionary dictomatonDictionary;
BufferedReader reader = source.openBufferedStream();
try {
if (whitelist == null) {
dictomatonDictionary = DictomatonDictionary.read(reader);
} else {
dictomatonDictionary = DictomatonDictionary.read(reader, whitelist);
}
} finally {
reader.close();
}
return dictomatonDictionary;
}
示例3: StableCssSubstitutionMapProvider
import com.google.common.io.CharSource; //导入方法依赖的package包/类
/**
* @param backingFile a file that need not exist, but if it does, contains
* the content of the renaming map as formatted by
* {@link OutputRenamingMapFormat#JSON}..
*/
public StableCssSubstitutionMapProvider(File backingFile)
throws IOException {
CharSource renameMapJson = Files.asCharSource(backingFile, Charsets.UTF_8);
RecordingSubstitutionMap.Builder substitutionMapBuilder =
new RecordingSubstitutionMap.Builder()
.withSubstitutionMap(
new MinimalSubstitutionMap());
ImmutableMap<String, String> mappings = ImmutableMap.of();
try {
try (Reader reader = renameMapJson.openBufferedStream()) {
mappings = OutputRenamingMapFormat.JSON.readRenamingMap(reader);
}
} catch (@SuppressWarnings("unused") FileNotFoundException ex) {
// Ok. Start with an empty map.
}
substitutionMapBuilder.withMappings(mappings);
this.substitutionMap = substitutionMapBuilder.build();
this.backingFile = backingFile;
this.originalMappings = mappings;
}
示例4: AG501PosFileHeader
import com.google.common.io.CharSource; //导入方法依赖的package包/类
public AG501PosFileHeader(File file) throws IOException {
CharSource source = Files.asCharSource(file, Charsets.UTF_8);
BufferedReader stream = source.openBufferedStream();
while (lines.size() < NUM_LINES) {
String line = stream.readLine();
lines.add(line);
}
// set number of channels
matcher = LINE_3.matcher(lines.get(2));
matcher.find();
numChannels = Integer.parseInt(matcher.group(1));
// set sampling frequency
matcher = LINE_4.matcher(lines.get(3));
matcher.find();
samplingFrequency = Integer.parseInt(matcher.group(1));
}
示例5: asBufferedReader
import com.google.common.io.CharSource; //导入方法依赖的package包/类
public static BufferedReader asBufferedReader(String resource) {
URL url = com.google.common.io.Resources.getResource(resource);
try {
CharSource charSource = com.google.common.io.Resources.asCharSource(url, Charsets.UTF_8);
return charSource.openBufferedStream();
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
示例6: parse
import com.google.common.io.CharSource; //导入方法依赖的package包/类
public <T> T parse(CharSource source, Class<T> targetType) {
try (Reader reader = source.openBufferedStream()) {
return parse(reader, targetType);
} catch (IOException e) {
throw new ConfigurationException("Unable to read configuration data from source", e);
}
}
示例7: process
import com.google.common.io.CharSource; //导入方法依赖的package包/类
private void process(Context context, String templateName, String targetPath) throws IOException {
URL templateUrl = Resources.getResource(IpmiCommandNameTest.class, templateName);
CharSource source = Resources.asCharSource(templateUrl, StandardCharsets.UTF_8);
File file = new File(targetPath);
CharSink sink = Files.asCharSink(file, StandardCharsets.UTF_8);
try (Reader r = source.openBufferedStream()) {
try (Writer w = sink.openBufferedStream()) {
engine.evaluate(context, w, file.getName(), r);
}
}
}
示例8: parseCompileTimeGlobals
import com.google.common.io.CharSource; //导入方法依赖的package包/类
/**
* Parses a globals file in the format created by {@link #generateCompileTimeGlobalsFile} into a
* map from global name to primitive value.
*
* @param inputSource A source that returns a reader for the globals file.
* @return The parsed globals map.
* @throws IOException If an error occurs while reading the globals file.
* @throws IllegalStateException If the globals file is not in the correct format.
*/
public static ImmutableMap<String, PrimitiveData> parseCompileTimeGlobals(CharSource inputSource)
throws IOException {
Builder<String, PrimitiveData> compileTimeGlobalsBuilder = ImmutableMap.builder();
ErrorReporter errorReporter = ErrorReporter.exploding();
try (BufferedReader reader = inputSource.openBufferedStream()) {
int lineNum = 1;
for (String line = reader.readLine(); line != null; line = reader.readLine(), ++lineNum) {
if (line.startsWith("//") || line.trim().length() == 0) {
continue;
}
SourceLocation sourceLocation = new SourceLocation("globals", lineNum, 1, lineNum, 1);
Matcher matcher = COMPILE_TIME_GLOBAL_LINE.matcher(line);
if (!matcher.matches()) {
errorReporter.report(sourceLocation, INVALID_FORMAT, line);
continue;
}
String name = matcher.group(1);
String valueText = matcher.group(2).trim();
ExprNode valueExpr = SoyFileParser.parseExprOrDie(valueText);
// Record error for non-primitives.
// TODO: Consider allowing non-primitives (e.g. list/map literals).
if (!(valueExpr instanceof PrimitiveNode)) {
if (valueExpr instanceof GlobalNode || valueExpr instanceof VarRefNode) {
errorReporter.report(sourceLocation, INVALID_VALUE, valueExpr.toSourceString());
} else {
errorReporter.report(sourceLocation, NON_PRIMITIVE_VALUE, valueExpr.toSourceString());
}
continue;
}
// Default case.
compileTimeGlobalsBuilder.put(
name, InternalValueUtils.convertPrimitiveExprToData((PrimitiveNode) valueExpr));
}
}
return compileTimeGlobalsBuilder.build();
}