/** * Opens the text file at <code>path</code> for reading using charset * {@link java.nio.charset.StandardCharsets#UTF_8}. * @param path Path to the file to open for reading. * @throws IOException if the file at <code>path</code> cannot be opened for * reading. */ public LinesStream(@Nonnull Path path) throws IOException { in = Files.newBufferedReader(path); // uses UTF-8 by default }
protected Reader reader(String path) throws IOException { return Files.newBufferedReader(Paths.get(path)); }
public static BufferedReader asBufferedReader(Path path) throws IOException { Validate.notNull(path, "path is null"); return Files.newBufferedReader(path, Charsets.UTF_8); }
public Map<String, Object> loadSidebar() throws IOException { try (Reader reader = Files.newBufferedReader(sidebarPath, StandardCharsets.UTF_8)) { Yaml yaml = new Yaml(); @SuppressWarnings("unchecked") Map<String, Object> sidebar = (Map<String, Object>) yaml.load(reader); return sidebar; } }
public static String readToString(Path path) throws IOException { BufferedReader bufferedReader = Files.newBufferedReader(path); return bufferedReader.lines().collect(Collectors.joining(System.lineSeparator())); }
public static String readToString(Path path) throws IOException { BufferedReader bufferedReader = Files.newBufferedReader(path); return bufferedReader.lines().collect(Collectors.joining(System.lineSeparator())); }
/** * Reads path content. */ public static String readString(Path path) throws IOException { BufferedReader reader = Files.newBufferedReader(path, StandardCharsets.UTF_8); StringWriter writer = new StringWriter(); StreamUtil.copy(reader, writer); return writer.toString(); }
/** * @param path Path. * @return Read line. * @throws IOException If failed. */ @Nullable private static String readLine(@NotNull Path path) throws IOException { try (BufferedReader reader = Files.newBufferedReader(path, StandardCharsets.UTF_8)) { return reader.readLine(); } }
/** * Reads the entire contents and returns it. */ public String read() throws IOException { StringWriter out = new StringWriter(); PrintWriter w = new PrintWriter(out); try (BufferedReader in = Files.newBufferedReader(Util.fileToPath(file), StandardCharsets.UTF_8)) { String line; while ((line = in.readLine()) != null) w.println(line); } catch (Exception e) { throw new IOException("Failed to fully read " + file, e); } return out.toString(); }
public FileIterable(File file) { try { lineReader = new LineNumberReader(Files.newBufferedReader(file.toPath(), Charset.defaultCharset())); } catch (IOException e) { throw new IllegalStateException(e); } }
public static void smaliFile(Path path, DexFileVisitor dcv) throws IOException { try (Reader reader = Files.newBufferedReader(path, StandardCharsets.UTF_8)) { ANTLRInputStream is = new ANTLRInputStream(reader); is.name = path.toString(); smali0(dcv, is); } }
public static ClassNode parse(Path file) throws IOException { try (BufferedReader bufferedReader = Files.newBufferedReader(file, StandardCharsets.UTF_8)) { return parse(file.toString(), bufferedReader); } catch (RecognitionException e) { throw new RuntimeException("Fail to assemble " + file, e); } }
@VisibleForTesting public List<Delta<String>> diff(Path actual, Charset actualCharset, Path expected, Charset expectedCharset) throws IOException { return diff(newBufferedReader(actual, actualCharset), newBufferedReader(expected, expectedCharset)); }
public Report parse() { try (Reader reader = Files.newBufferedReader(filePath, StandardCharsets.UTF_8)) { return validate(gson.fromJson(reader, Report.class)); } catch (JsonIOException | IOException e) { throw new IllegalStateException("Failed to read external issues report '" + filePath + "'", e); } catch (JsonSyntaxException e) { throw new IllegalStateException("Failed to read external issues report '" + filePath + "': invalid JSON syntax", e); } }
/** * Reads path content. */ public static String readString(final Path path) throws IOException { try (BufferedReader reader = Files.newBufferedReader(path, StandardCharsets.UTF_8)) { StringWriter writer = new StringWriter(); // flush & close not needed for StringWriter-instance StreamUtil.copy(reader, writer); return writer.toString(); } }
public static GameManifest load(Path filePath) throws IOException { try (BufferedReader reader = Files.newBufferedReader(filePath, TerasologyConstants.CHARSET)) { return createGson().fromJson(reader, GameManifest.class); } }
@Override public String getSinkContents() throws IOException { Path file = getPath(); try (Reader reader = java.nio.file.Files.newBufferedReader(file, Charsets.UTF_8)) { StringBuilder builder = new StringBuilder(); for (int c = reader.read(); c != -1; c = reader.read()) { builder.append((char) c); } return builder.toString(); } } }
@VisibleForTesting public List<Delta<String>> diff(Path actual, String expected, Charset charset) throws IOException { return diff(newBufferedReader(actual, charset), readerFor(expected)); }
private void addToIndex(File file) throws IOException { List<Block> blocks = bridge.chunk(file.getAbsolutePath(), file.getAbsolutePath(), Files.newBufferedReader(file.toPath(), StandardCharsets.UTF_8)); for (Block block : blocks) { index.insert(block); } }
public static void main(final String[] args) throws Exception { final String propsFile = System.getenv("JOB_PROP_FILE"); final Properties prop = new Properties(); prop.load(Files.newBufferedReader(Paths.get(propsFile), StandardCharsets.UTF_8)); final String jobName = System.getenv("JOB_NAME"); final SleepJavaJob job = new SleepJavaJob(jobName, prop); job.run(); }