Java Code Examples for org.apache.maven.shared.utils.io.FileUtils#fileRead()

The following examples show how to use org.apache.maven.shared.utils.io.FileUtils#fileRead() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XtendCompilerMojoIT.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
public void assertFileContainsUTF16(Verifier verifier, String file, String contained) {
	verifier.assertFilePresent(file);
	try {
		String content = FileUtils.fileRead(new File(file), "UTF-16");
		if (!content.contains(contained)) {
			Assert.fail("Content of " + file + " does not contain " + contained + " but: " + content);
		}
	} catch (IOException e) {
		Assert.fail(e.getMessage());
	}
}
 
Example 2
Source File: XtendCompilerMojoIT.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
public void assertFileDoesNotContain(Verifier verifier, String file, String contained) {
	verifier.assertFilePresent(file);
	try {
		String content = FileUtils.fileRead(new File(file), "UTF-8");
		if (content.contains(contained)) {
			Assert.fail("Content of " + file + " does contain " + contained + ", but it should not. Contents: " + content);
		}
	} catch (IOException e) {
		Assert.fail(e.getMessage());
	}
}
 
Example 3
Source File: EnvUtil.java    From docker-maven-plugin with Apache License 2.0 5 votes vote down vote up
public static Date loadTimestamp(File tsFile) throws IOException {
    try {
        if (tsFile.exists()) {
            String ts = FileUtils.fileRead(tsFile);
            return new Date(Long.parseLong(ts));
        } else {
            return null;
        }
    } catch (IOException e) {
        throw new IOException("Cannot read timestamp " + tsFile,e);
    }
}
 
Example 4
Source File: Bug504Test.java    From sarl with Apache License 2.0 4 votes vote down vote up
@Test
public void compile() throws Exception {
	Verifier verifier = executeMojo("bug504", "compile");
	Path path = FileSystems.getDefault().getPath(
			"src", "main", "generated-sources", "sarl",
			"io", "sarl", "elevatorsim", "SimulatorInteraction.java");
	assertNotNull(path);
	verifier.assertFilePresent(path.toString());
	File file = new File(verifier.getBasedir(), path.toString());
	String fileContent = FileUtils.fileRead(file);
	assertEquals(multilineString(
			"package io.sarl.elevatorsim;",
			"",
			"import io.sarl.elevatorsim.SimulatorPush;",
			"import io.sarl.elevatorsim.events.SendCarAction;",
			"import io.sarl.lang.annotation.SarlElementType;",
			"import io.sarl.lang.annotation.SarlSpecification;",
			"import io.sarl.lang.annotation.SyntheticMember;",
			"import io.sarl.lang.core.Agent;",
			"import io.sarl.lang.core.Skill;",
			"import java.io.IOException;",
			"import org.eclipse.xtext.xbase.lib.Exceptions;",
			"",
			"@SarlSpecification(\"" + SARLVersion.SPECIFICATION_RELEASE_VERSION_STRING + "\")",
			"@SarlElementType(" + SarlPackage.SARL_SKILL + ")",
			"@SuppressWarnings(\"all\")",
			"public class SimulatorInteraction extends Skill implements SimulatorPush {",
			"  public void sendCar(final int a, final int b, final int c, final Object d, final Object e) {",
			"  }",
			"  ",
			"  @Override",
			"  public void pushSendCarAction(final SendCarAction action) {",
			"    try {",
			"      this.sendCar(action.car, action.floor, action.nextDirection, ",
			"        null, null);",
			"    } catch (final Throwable _t) {",
			"      if (_t instanceof IOException) {",
			"        final IOException e = (IOException)_t;",
			"        e.printStackTrace();",
			"      } else {",
			"        throw Exceptions.sneakyThrow(_t);",
			"      }",
			"    }",
			"  }",
			"  ",
			"  @SyntheticMember",
			"  public SimulatorInteraction() {",
			"    super();",
			"  }",
			"  ",
			"  @SyntheticMember",
			"  public SimulatorInteraction(final Agent arg0) {",
			"    super(arg0);",
			"  }",
			"}"), fileContent);
}