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;
}
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);
}
}
}
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;
}
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);
}
}
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");
}
Aggregations