com.google.common.io.Files#newReader ( )源码实例Demo

下面列出了com.google.common.io.Files#newReader ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: che   文件: CheBootstrap.java
private Map<String, Set<String>> readConfigurationAliases() {
  URL aliasesResource = getClass().getClassLoader().getResource(PROPERTIES_ALIASES_CONFIG_FILE);
  Map<String, Set<String>> aliases = new HashMap<>();
  if (aliasesResource != null) {
    Properties properties = new Properties();
    File aliasesFile = new File(aliasesResource.getFile());
    try (Reader reader = Files.newReader(aliasesFile, Charset.forName("UTF-8"))) {
      properties.load(reader);
    } catch (IOException e) {
      throw new IllegalStateException(
          format("Unable to read configuration aliases from file %s", aliasesFile), e);
    }
    for (Map.Entry<Object, Object> entry : properties.entrySet()) {
      String value = (String) entry.getValue();
      aliases.put(
          (String) entry.getKey(),
          Splitter.on(',').splitToList(value).stream().map(String::trim).collect(toSet()));
    }
  }
  return aliases;
}
 
源代码2 项目: che   文件: CheBootstrap.java
protected void bindConf(File confDir) {
  final File[] files = confDir.listFiles();
  if (files != null) {
    for (File file : files) {
      if (!file.isDirectory()) {
        if ("properties".equals(Files.getFileExtension(file.getName()))) {
          Properties properties = new Properties();
          try (Reader reader = Files.newReader(file, Charset.forName("UTF-8"))) {
            properties.load(reader);
          } catch (IOException e) {
            throw new IllegalStateException(
                format("Unable to read configuration file %s", file), e);
          }
          bindProperties(properties);
        }
      }
    }
  }
}
 
public Reader asReader() {
    try {
        return Files.newReader(asFile(), charset);
    } catch (FileNotFoundException e) {
        throw new UncheckedIOException(e);
    }
}
 
源代码4 项目: twill   文件: TwillContainerMain.java
private static Map<String, Map<String, String>> loadLogLevels() throws IOException {
  File file = new File(Constants.Files.LOG_LEVELS);
  if (file.exists()) {
    try (Reader reader = Files.newReader(file, Charsets.UTF_8)) {
      Gson gson = new GsonBuilder().serializeNulls().create();
      return gson.fromJson(reader, new TypeToken<Map<String, Map<String, String>>>() { }.getType());
    }
  }
  return new HashMap<>();
}
 
源代码5 项目: flashback   文件: SceneReader.java
/**
 * Read scene from file and construct Scene object
 * @param name scene name
 * @return scene object de-serialized from file
 *
 * */
public Scene readScene(String rootPath, String name)
    throws IOException {
  File file = new File(rootPath, name);
  if (file.isFile()) {
    if (file.length() == 0) {
      return new Scene(name, null, rootPath, new ArrayList<>());
    }
    BufferedReader reader = Files.newReader(file, Charset.forName(SceneSerializationConstant.FILE_CHARSET));
    SceneDeserializer sceneDeserializer = new SceneDeserializer();
    return sceneDeserializer.deserialize(reader);
  }
  return null;
}
 
public Reader asReader() {
    try {
        return Files.newReader(asFile(), charset);
    } catch (FileNotFoundException e) {
        throw new UncheckedIOException(e);
    }
}
 
源代码7 项目: che   文件: SeleniumTestConfiguration.java
void addFile(File file) {
  if (!file.isDirectory()) {
    if ("properties".equals(Files.getFileExtension(file.getName()))) {
      Properties properties = new Properties();
      try (Reader reader = Files.newReader(file, Charset.forName("UTF-8"))) {
        properties.load(reader);
      } catch (IOException e) {
        throw new IllegalStateException(
            String.format("Unable to read configuration file %s", file), e);
      }
      addAll(Maps.fromProperties(properties));
    }
  }
}
 
源代码8 项目: j2objc   文件: Options.java
private void addManifest(String manifestFile) throws IOException {
  BufferedReader in = Files.newReader(new File(manifestFile), Charset.forName(fileEncoding));
  try {
    for (String line = in.readLine(); line != null; line = in.readLine()) {
      if (!Strings.isNullOrEmpty(line)) {
        sourceFiles.add(line.trim());
      }
    }
  } finally {
    in.close();
  }
}
 
源代码9 项目: JGiven   文件: ScenarioJsonReader.java
/**
 * @throws JsonReaderException in case there was an error while reading the file.
 */
@Override
public ReportModel apply( File file ) {
    Reader reader = null;
    try {
        reader = Files.newReader( file, Charsets.UTF_8 );
        return new Gson().fromJson( reader, ReportModel.class );
    } catch( Exception e ) {
        throw new JsonReaderException( file, e );
    } finally {
        ResourceUtil.close( reader );
    }
}
 
源代码10 项目: googleads-java-lib   文件: CsvFilesTest.java
@Test
public void testGetCsvDataArray_fromReader() throws IOException {
  Reader reader = Files.newReader(csvStringFile, StandardCharsets.UTF_8);
  List<String[]> actualDataArray = CsvFiles.getCsvDataArray(reader, headerPresent);
  assertEquals(dataList.size(), actualDataArray.size());
  for (int i = 0; i < actualDataArray.size(); i++) {
    assertArrayEquals("Row " + i + " does not match", dataList.get(i), actualDataArray.get(i));
  }

  // Reader should be closed (not ready).
  thrown.expect(IOException.class);
  thrown.expectMessage("Stream closed");
  reader.ready();
}
 
源代码11 项目: j360-dubbo-app-all   文件: FileUtil.java
/**
 * 获取File的BufferedReader
 */
public static BufferedReader asBufferedReader(String fileName) throws FileNotFoundException {
	return Files.newReader(getFileByPath(fileName), Charsets.UTF_8);
}
 
源代码12 项目: twill   文件: TwillRuntimeSpecificationAdapter.java
public TwillRuntimeSpecification fromJson(File file) throws IOException {
  try (Reader reader = Files.newReader(file, Charsets.UTF_8)) {
    return fromJson(reader);
  }
}
 
源代码13 项目: scheduler   文件: Replay.java
/**
 * Replay from a given path.
 *
 * @param cstrs the constraint catalog
 * @param path  the file containing the jsons.
 * @throws IOException if an error occurred while reading the file
 */
public Replay(List<Constraint> cstrs, Path path) throws IOException {
    in = Files.newReader(path.toFile(), Charset.defaultCharset());
    constraints = cstrs;
}