Example usage for org.apache.commons.io FileUtils readFileToString

List of usage examples for org.apache.commons.io FileUtils readFileToString

Introduction

In this page you can find the example usage for org.apache.commons.io FileUtils readFileToString.

Prototype

public static String readFileToString(File file) throws IOException 

Source Link

Document

Reads the contents of a file into a String using the default encoding for the VM.

Usage

From source file:com.blazemeter.bamboo.MockedAPI.java

public static void ping() throws IOException {
    File jsonFile = new File(TestConstants.RESOURCES + "/ping_true.json");
    String ping_true = FileUtils.readFileToString(jsonFile);

    mockServer/*from   w  ww  .  j  a va2 s  . c  om*/
            .when(request().withMethod("GET").withPath("/api/latest/web/version").withHeader("Accept",
                    "application/json"), unlimited())
            .respond(response().withHeader("application/json").withStatusCode(200).withBody(ping_true));

}

From source file:com.l2jfree.tools.NewLineChecker.java

private static void parse(File f) throws IOException {
    if (f.isDirectory()) {
        for (File f2 : f.listFiles(FILTER))
            parse(f2);/*from   w  ww. java2  s . c  o  m*/
        return;
    }

    final String input = FileUtils.readFileToString(f);
    final List<String> inputLines = FileUtils.readLines(f);

    final int r = StringUtils.countMatches(input, "\r");
    final int n = StringUtils.countMatches(input, "\n");
    final int rn = StringUtils.countMatches(input, "\r\n");

    final char lastChar = input.charAt(input.length() - 1);
    boolean missingNewline = false;

    if (lastChar != '\r' && lastChar != '\n') {
        System.out.println("--- " + f.getCanonicalPath());
        System.out.println(lastChar);

        MISSING_NEWLINE++;

        missingNewline = true;
    }

    // fully "\r\n"
    if (r == n && r == rn && n == rn) {
        RN++;
        if (missingNewline)
            FileUtils.writeLines(f, inputLines, "\r\n");
        return;
    }

    // fully "\n"
    if (r == 0 && rn == 0) {
        N++;
        System.out.println("n " + f.getName());
        if (missingNewline)
            FileUtils.writeLines(f, inputLines, "\n");
        return;
    }

    System.out.println("--- " + f.getCanonicalPath());
    System.out.println("r: " + r);
    System.out.println("n: " + n);
    System.out.println("rn: " + rn);

    FileUtils.writeLines(f, inputLines, f.getName().endsWith(".sh") ? "\n" : "\r\n");

    // fully "\r"
    if (n == 0 && rn == 0) {
        R++;
        return;
    }

    // mixed
    MIXED++;
}

From source file:com.sangupta.pep.Parser.java

public String parse() {
    try {// ww  w .j  av  a  2  s.com
        String contents = FileUtils.readFileToString(this.inputFile);
        if (contents.startsWith("\ufeff")) { // check for Unicode BOM
            contents = contents.substring(1);
        }

        MarkdownProcessor markdownProcessor = new MarkdownProcessor();
        String html = markdownProcessor.markdown(contents);
        return html;
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return null;
}

From source file:hu.bme.mit.incqueryd.engine.util.EObjectSerializer.java

public static String serializeToString(final EObject eObject) throws IOException {
    Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("json", new JsonResourceFactory());

    final File tempFile = createTempFile();
    serializeToFile(eObject, tempFile.getAbsolutePath());
    final String modelString = FileUtils.readFileToString(tempFile);

    return modelString;
}

From source file:com.legstar.cobol.CompleteProgramsParserTest.java

/**
 * Try the LSFILEAE sample./*from w  w  w .  j a  v  a 2s  .  co  m*/
 * @throws Exception if test fails
 */
public void testLsfileae() throws Exception {
    parseAndCheck(FileUtils.readFileToString(new File(sampleFolder, "LSFILEAE")),
            "(DATA_ITEM (LEVEL 01) (NAME FILEA))" + " (DATA_ITEM (LEVEL 77) (NAME RESPONSE) (PICTURE S9(8)))"
                    + " (DATA_ITEM (LEVEL 01) (NAME DFHCOMMAREA)"
                    + " (DATA_ITEM (LEVEL 05) (NAME COM-NUMBER) (PICTURE 9(6)))"
                    + " (DATA_ITEM (LEVEL 05) (NAME COM-PERSONAL)"
                    + " (DATA_ITEM (LEVEL 10) (NAME COM-NAME) (PICTURE X(20)))"
                    + " (DATA_ITEM (LEVEL 10) (NAME COM-ADDRESS) (PICTURE X(20)))"
                    + " (DATA_ITEM (LEVEL 10) (NAME COM-PHONE) (PICTURE X(8))))"
                    + " (DATA_ITEM (LEVEL 05) (NAME COM-DATE) (PICTURE X(8)))"
                    + " (DATA_ITEM (LEVEL 05) (NAME COM-AMOUNT) (PICTURE X(8)))"
                    + " (DATA_ITEM (LEVEL 05) (NAME COM-COMMENT) (PICTURE X(9))))");
}

From source file:com.mirth.connect.model.converters.tests.NCPDPSerializerTest.java

@Test
public void test51RequestToXml() throws Exception {
    String input = FileUtils.readFileToString(new File("tests/test-ncpdp-51-request-input.txt"));
    String output = FileUtils.readFileToString(new File("tests/test-ncpdp-51-request-output.xml"));
    NCPDPSerializer serializer = new NCPDPSerializer(defaultProperties);
    Assert.assertEquals(output, TestUtil.prettyPrintXml(serializer.toXML(input)));
}

From source file:com.legstar.cob2xsd.antlr.CompleteProgramsParserTest.java

/**
 * Try the LSFILEAE sample.//w  w  w  .j a  va  2s  .c o m
 * @throws Exception if test fails
 */
@Test
public void testLsfileae() throws Exception {
    parseAndCheck(FileUtils.readFileToString(new File(sampleFolder, "LSFILEAE")),
            "(DATA_ITEM (LEVEL 01) (NAME FILEA))" + " (DATA_ITEM (LEVEL 77) (NAME RESPONSE) (PICTURE S9(8)))"
                    + " (DATA_ITEM (LEVEL 01) (NAME DFHCOMMAREA)"
                    + " (DATA_ITEM (LEVEL 05) (NAME COM-NUMBER) (PICTURE 9(6)))"
                    + " (DATA_ITEM (LEVEL 05) (NAME COM-PERSONAL)"
                    + " (DATA_ITEM (LEVEL 10) (NAME COM-NAME) (PICTURE X(20)))"
                    + " (DATA_ITEM (LEVEL 10) (NAME COM-ADDRESS) (PICTURE X(20)))"
                    + " (DATA_ITEM (LEVEL 10) (NAME COM-PHONE) (PICTURE X(8))))"
                    + " (DATA_ITEM (LEVEL 05) (NAME COM-DATE) (PICTURE X(8)))"
                    + " (DATA_ITEM (LEVEL 05) (NAME COM-AMOUNT) (PICTURE X(8)))"
                    + " (DATA_ITEM (LEVEL 05) (NAME COM-COMMENT) (PICTURE X(9))))");
}

From source file:com.sangupta.har.HarUtils.java

/**
 * Read the HAR file and create an {@link Har} model instance from the same.
 * // w ww . j  a  v a 2 s .  co  m
 * @param file
 *            the file to be read
 * 
 * @return the {@link Har} instance
 * 
 * @throws JsonSyntaxException
 *             if the JSON is not well formed
 * 
 * @throws IOException
 *             if reading the file fails
 * 
 * @throws IllegalArgumentException
 *             if the file does not exist, is a directory or is not a valid
 *             file
 */
public static Har read(File file) throws JsonSyntaxException, IOException {
    CheckUtils.checkFileExists(file);

    return GsonUtils.getGson().fromJson(FileUtils.readFileToString(file), Har.class);
}

From source file:com.sillelien.dollar.DocTest.java

@Test
public void test() throws IOException {
    PegDownProcessor processor = new PegDownProcessor(Extensions.FENCED_CODE_BLOCKS);
    RootNode rootNode = processor/*from   ww  w.  ja va 2s  . c  o m*/
            .parseMarkdown(FileUtils.readFileToString(new File("README.tmpl.md")).toCharArray());
    rootNode.accept(new DocTestingVisitor());
}

From source file:github.srlee309.lessWrongBookCreator.bookGeneration.PostHtmlCreatorTest.java

@Test
public void createPostsPages_PostSection_OutputHtmlAsExpected() throws Exception {
    String expectedHtmlString = FileUtils
            .readFileToString(new File(this.getClass().getResource("/FeelingRational.html").toURI()));
    String title = "Feeling Rational";
    String url = "http://lesswrong.com/lw/hp/feeling_rational/?all=true";
    String postContent = FileUtils.readFileToString(
            new File(this.getClass().getResource("/Feeling Rational PostSection content.txt").toURI()));
    PostSection postSection = new PostSection(title, url, postContent);
    ArrayList<PostSection> postSections = new ArrayList<PostSection>();
    postSections.add(postSection);/*w ww .ja  v a 2  s.  c  om*/
    PostHtmlCreator instance = new PostHtmlCreator();
    instance.createPostsPages(postSections);
    String resultHtmlString = FileUtils.readFileToString(new File("htmlOutput/FeelingRational.html"));

    assertTrue(resultHtmlString.equals(expectedHtmlString));
}