APISonar


com.google.common.io.Files.newReader

> com > google > common > io > Files > newReader
com APIs google APIs common APIs io APIs Files APIs newReader APIs

Example 1
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();
    }
  }
Example 2
public static LineStream openFile(File file) throws FileNotFoundException {
        // REVIEW do we want to use the default charset?
        return new LineStream(Files.newReader(file, Charset.defaultCharset()));
    }
Example 3
public static void main(String[] args) throws IOException, ScriptException {
        File scriptFile = new File(args[0]);
        ScriptEngineManager sem = new ScriptEngineManager();
        String ext = Files.getFileExtension(scriptFile.getName());
        ScriptEngine engine = sem.getEngineByExtension(ext);
        engine.put("cmdArgs", Arrays.asList(args).subList(1, args.length));
        try (Reader reader = Files.newReader(scriptFile, Charsets.UTF_8)) {
            engine.eval(reader);
        }
    }
Example 4
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;
  }
Example 5
public static Dockerfile parse(File file) throws DockerFileException {
        try {
            return parse(CharStreams.readLines(Files.newReader(file, Charset.defaultCharset())));
        } catch (IOException e) {
            throw new DockerFileException("Error happened parsing the Docker file." + e.getMessage(), e);
        }
    }
Example 6
private Metas loadCache() {
        if (localCache.exists() && localCache.isFile()) {
            try {
                Reader reader = Files.newReader(localCache, Charsets.UTF_8);
                return gson.fromJson(reader, Metas.class).withoutNull();
            } catch (IOException e) {
                throw new RuntimeException(e);
            } catch (JsonParseException e) {
                if (!localCache.delete()) {
                    throw new RuntimeException("cache file has been modified, but can't delete.", e);
                }
            }
        }
        return new Metas();
    }
Example 7
public <T> T load(TypeToken<T> token) {
        T result = null;
        try (Reader reader = Files.newReader(storedFile, Charset.forName("UTF-8"))) {
            result = gson.fromJson(reader, token.getType());
        } catch (JsonSyntaxException e) {
            LOG.warn(storedFile.getName() + " contains invalid JSON content");
        } catch (IOException ioEx) {
            LOG.debug("Impossible to read from " + storedFile.getName());
        }
        return result;
    }