/** * Read some source in from the given reader * @param in the input stream to pass into a buffered reader. * @param name the name to use in error messages * @param charset the encoding for the reader, may be null. */ private void readSource(InputStream in, String name, Charset charset) { try (Reader reader = new BufferedReader(new InputStreamReader(in, charset))) { script += FileUtils.safeReadFully(reader); } catch (IOException ex) { throw new BuildException("Failed to read " + name, ex); } }
private boolean multilineReplace(Reader r, Writer w, int options) throws IOException { return replaceAndWrite(FileUtils.safeReadFully(r), w, options); }
/** * set the text using a file * @param file the file to use * @throws BuildException if the file does not exist, or cannot be * read */ public void setFile(File file) throws BuildException { // non-existing files are not allowed if (!file.exists()) { throw new BuildException("File %s does not exist.", file); } BufferedReader reader = null; try { if (this.encoding == null) { reader = new BufferedReader(new FileReader(file)); } else { reader = new BufferedReader( new InputStreamReader(Files.newInputStream(file.toPath()), this.encoding)); } value = FileUtils.safeReadFully(reader); } catch (IOException ex) { throw new BuildException(ex); } finally { FileUtils.close(reader); } }
private int postProcess(final File file, final String fixData) throws IOException { final String enc = docEncoding != null ? docEncoding : FILE_UTILS.getDefaultEncoding(); // we load the whole file as one String (toc/index files are // generally small, because they only contain frameset declaration): String fileContents; try (InputStreamReader reader = new InputStreamReader(Files.newInputStream(file.toPath()), enc)) { fileContents = fixLineFeeds(FileUtils.safeReadFully(reader)); } // check if file may be vulnerable because it was not // patched with "validURL(url)": if (!fileContents.contains("function validURL(url) {")) { // we need to patch the file! final String patchedFileContents = patchContent(fileContents, fixData); if (!patchedFileContents.equals(fileContents)) { try (final OutputStreamWriter w = new OutputStreamWriter(Files.newOutputStream(file.toPath()), enc)) { w.write(patchedFileContents); w.close(); return 1; } } } return 0; }
String contents = FileUtils.safeReadFully(reader); String sub = substring; if (!casesensitive) {
filterChains.add(this); helper.setFilterChains(filterChains); String result = FileUtils.safeReadFully(helper.getAssembledReader()); if (result.isEmpty()) { return null;