本文整理匯總了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();
}