@Override public Reader openReader(boolean ignoreEncodingErrors) throws IOException { return Files.newReader(file, Charset.defaultCharset()); }
public void testNewReader() throws IOException { File asciiFile = getTestFile("ascii.txt"); try { Files.newReader(asciiFile, null); fail("expected exception"); } catch (NullPointerException expected) { } try { Files.newReader(null, Charsets.UTF_8); fail("expected exception"); } catch (NullPointerException expected) { } BufferedReader r = Files.newReader(asciiFile, Charsets.US_ASCII); try { assertEquals(ASCII, r.readLine()); } finally { r.close(); } }
/** * Open a delimited text stream as a file. * * @param file The file to open. * @return The stream. * @throws FileNotFoundException if there is an error opening the file. */ 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())); }
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); } } }
/** * 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; } }
@Override public Reader openReader(boolean ignoreEncodingErrors) throws IOException { return Files.newReader(file, Charset.defaultCharset()); }
@Override public Reader openReader(boolean ignoreEncodingErrors) throws IOException { return Files.newReader(file, Charset.defaultCharset()); }
private Properties readReportTaskProperties() { File reportTaskFile = new File(workDir, "report-task.txt"); Properties properties = new Properties(); try { properties.load(Files.newReader(reportTaskFile, StandardCharsets.UTF_8)); } catch (IOException e) { throw new IllegalStateException("Unable to load properties from file " + reportTaskFile, e); } return properties; }
/** * Parses the given file and returns a list of dependency information that it * contained. * * @param filePath Path to the file to parse. * @return A list of DependencyInfo objects. * @throws IOException Thrown if the file could not be read. */ public List<DependencyInfo> parseFile(String filePath) throws IOException { return parseFileReader(filePath, Files.newReader(new File(filePath), StandardCharsets.UTF_8)); }
@Override public void loadAccessTransformer(File file) throws IOException { // because SS doesnt close its freaking reader... BufferedReader reader = Files.newReader(file, Constants.CHARSET); loadAccessTransformer(reader); reader.close(); }
public Iterator<String> getIterator() throws IOException { CloseableIterator itr = new CloseableIterator(Files.newReader(sortedFile, charset)); openedIterators.add(itr); return itr; }
/** * Parses the given file and returns a list of dependency information that it * contained. * * @param filePath Path to the file to parse. * @return A list of DependencyInfo objects. * @throws IOException Thrown if the file could not be read. */ public List<DependencyInfo> parseFile(String filePath) throws IOException { return parseFileReader(filePath, Files.newReader(new File(filePath), StandardCharsets.UTF_8)); }
/** * 获取File的BufferedReader */ public static BufferedReader asBufferedReader(String fileName) throws FileNotFoundException { return Files.newReader(getFileByPath(fileName), Charsets.UTF_8); }
@Nullable private UserAccessToken getSavedAccessToken(String hostname) { File file = getAccessTokenFile(hostname); try (BufferedReader reader = Files.newReader(file, Charsets.UTF_8)) { return GSON.fromJson(reader, UserAccessToken.class); } catch (IOException | JsonSyntaxException ignored) { // Fall through } return null; }
public TwillRuntimeSpecification fromJson(File file) throws IOException { try (Reader reader = Files.newReader(file, Charsets.UTF_8)) { return fromJson(reader); } }
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<>(); }
@SuppressWarnings("unused") public void setFile(String lookup) throws IOException { if (lookup.matches(".*\\.json")) { readJsonData(Files.newReader(new File(lookup), Charsets.UTF_8)); } else { List<String> lines = Files.readLines(new File(lookup), Charsets.UTF_8); readDelimitedData(lookup, lines); } setupIndex(); }
public static Reader newReader(File file, String errorMessage) { try { return Files.newReader(file, Charsets.UTF_8); } catch (FileNotFoundException e) { throw new ApplicationTechnicalException(t(errorMessage, file), e); } }
private Map<String, Object> parseAttributesFile(Optional<File> attrsFile, Map<String, Object> cmdlineAttrs) { if (attrsFile.isPresent()) { try { return parseAttributes(Files.newReader(attrsFile.get(), docletOptions.encoding()), cmdlineAttrs); } catch (Exception e) { errorReporter.printWarning("Cannot read attributes file: " + e); } } return cmdlineAttrs; }
public Reader asReader() { File file = asFile(); try { return Files.newReader(asFile(), charset); } catch (FileNotFoundException e) { throw ResourceExceptions.readMissing(file, e); } }