Search in sources :

Example 86 with FileReader

use of java.io.FileReader in project camel by apache.

the class FileApiMethodGeneratorMojo method getSignatureList.

@Override
public List<String> getSignatureList() throws MojoExecutionException {
    // get signatureFile as a list of Strings
    List<String> result = new ArrayList<String>();
    try {
        BufferedReader reader = new BufferedReader(new FileReader(this.signatureFile));
        String line = reader.readLine();
        while (line != null) {
            result.add(line);
            line = reader.readLine();
        }
        reader.close();
    } catch (FileNotFoundException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    } catch (IOException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }
    if (result.isEmpty()) {
        throw new MojoExecutionException("Signature file " + signatureFile.getPath() + " is empty");
    }
    return result;
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArrayList(java.util.ArrayList) BufferedReader(java.io.BufferedReader) FileNotFoundException(java.io.FileNotFoundException) FileReader(java.io.FileReader) IOException(java.io.IOException)

Example 87 with FileReader

use of java.io.FileReader in project camel by apache.

the class BomGeneratorMojo method writeFileIfChanged.

private void writeFileIfChanged(String content, File file) throws IOException {
    boolean write = true;
    if (file.exists()) {
        try (FileReader fr = new FileReader(file)) {
            String oldContent = IOUtils.toString(fr);
            if (!content.equals(oldContent)) {
                getLog().debug("Writing new file " + file.getAbsolutePath());
                fr.close();
            } else {
                getLog().debug("File " + file.getAbsolutePath() + " left unchanged");
                write = false;
            }
        }
    } else {
        File parent = file.getParentFile();
        parent.mkdirs();
    }
    if (write) {
        try (FileWriter fw = new FileWriter(file)) {
            IOUtils.write(content, fw);
        }
    }
}
Also used : FileWriter(java.io.FileWriter) FileReader(java.io.FileReader) File(java.io.File)

Example 88 with FileReader

use of java.io.FileReader in project spring-boot by spring-projects.

the class FullyExecutableJarTests method readLines.

private List<String> readLines(File file) throws IOException {
    BufferedReader reader = new BufferedReader(new FileReader(file));
    List<String> lines = new ArrayList<>();
    try {
        String line = reader.readLine();
        while (line != null && lines.size() < 50) {
            lines.add(line);
            line = reader.readLine();
        }
    } finally {
        reader.close();
    }
    return lines;
}
Also used : BufferedReader(java.io.BufferedReader) ArrayList(java.util.ArrayList) FileReader(java.io.FileReader)

Example 89 with FileReader

use of java.io.FileReader in project spring-boot by spring-projects.

the class Versions method evaluateExpression.

private static String evaluateExpression(String expression) {
    try {
        XPathFactory xPathFactory = XPathFactory.newInstance();
        XPath xpath = xPathFactory.newXPath();
        XPathExpression expr = xpath.compile(expression);
        String version = expr.evaluate(new InputSource(new FileReader("target/dependencies-pom.xml")));
        return version;
    } catch (Exception ex) {
        throw new IllegalStateException("Failed to evaluate expression", ex);
    }
}
Also used : XPath(javax.xml.xpath.XPath) XPathExpression(javax.xml.xpath.XPathExpression) XPathFactory(javax.xml.xpath.XPathFactory) InputSource(org.xml.sax.InputSource) FileReader(java.io.FileReader)

Example 90 with FileReader

use of java.io.FileReader in project spring-boot by spring-projects.

the class ApplicationPidTests method writePid.

@Test
public void writePid() throws Exception {
    ApplicationPid pid = new ApplicationPid("123");
    File file = this.temporaryFolder.newFile();
    pid.write(file);
    String actual = FileCopyUtils.copyToString(new FileReader(file));
    assertThat(actual).isEqualTo("123");
}
Also used : FileReader(java.io.FileReader) File(java.io.File) Test(org.junit.Test)

Aggregations

FileReader (java.io.FileReader)1873 BufferedReader (java.io.BufferedReader)1289 IOException (java.io.IOException)893 File (java.io.File)811 FileNotFoundException (java.io.FileNotFoundException)304 ArrayList (java.util.ArrayList)274 Test (org.junit.Test)197 FileWriter (java.io.FileWriter)148 HashMap (java.util.HashMap)116 Reader (java.io.Reader)99 BufferedWriter (java.io.BufferedWriter)98 Properties (java.util.Properties)66 InputStreamReader (java.io.InputStreamReader)64 LineNumberReader (java.io.LineNumberReader)61 Matcher (java.util.regex.Matcher)61 Map (java.util.Map)59 List (java.util.List)56 PrintWriter (java.io.PrintWriter)51 StringTokenizer (java.util.StringTokenizer)51 HashSet (java.util.HashSet)50