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, String encoding) throws IOException 

Source Link

Document

Reads the contents of a file into a String.

Usage

From source file:com.blackducksoftware.integration.hub.detect.tool.bazel.BazelExternalIdExtractionFullRuleJsonProcessor.java

public List<BazelExternalIdExtractionFullRule> load(File jsonFile) throws IOException {
    String json = FileUtils.readFileToString(jsonFile, StandardCharsets.UTF_8);
    BazelExternalIdExtractionFullRule[] rulesArray = gson.fromJson(json,
            BazelExternalIdExtractionFullRule[].class);
    return Arrays.asList(rulesArray);
}

From source file:com.intuit.karate.cucumber.FeatureWrapper.java

public static FeatureWrapper fromFile(File file, ScriptEnv env) {
    try {//from w  ww  . jav  a2 s.  co  m
        String text = FileUtils.readFileToString(file, "utf-8");
        return new FeatureWrapper(text, env);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:de.fosd.jdime.util.parser.ParserTest.java

@Test
public void testParse() throws Exception {
    File file = file(resultsDir, "linebased", "SimpleTests", "Bag", "Bag2.java");
    String code = FileUtils.readFileToString(file, UTF_8);
    ParseResult result = Parser.parse(code);

    assertEquals(11, result.getLinesOfCode());
    assertEquals(1, result.getConflicts());
    assertEquals(7, result.getConflictingLinesOfCode());
    assertEquals(normalize(code), normalize(result.toString()));

    file = file(resultsDir, "linebased", "SimpleTests", "Bag", "Bag3.java");
    code = FileUtils.readFileToString(file, UTF_8);
    result = Parser.parse(code);//from  w  ww.jav  a  2  s .com

    assertEquals(20, result.getLinesOfCode());
    assertEquals(0, result.getConflicts());
    assertEquals(0, result.getConflictingLinesOfCode());
    assertEquals(normalize(code), normalize(result.toString()));

    file = file(resultsDir, "linebased", "ParserTest", "Comments.java");
    code = FileUtils.readFileToString(file, UTF_8);
    result = Parser.parse(code);

    assertEquals(7, result.getLinesOfCode());
    assertEquals(0, result.getConflicts());
    assertEquals(0, result.getConflictingLinesOfCode());
    assertEquals(normalize(code), normalize(result.toString()));

    file = file(resultsDir, "linebased", "ParserTest", "CommentsConflict.java");
    code = FileUtils.readFileToString(file, UTF_8);
    result = Parser.parse(code);

    assertEquals(11, result.getLinesOfCode());
    assertEquals(1, result.getConflicts());
    assertEquals(2, result.getConflictingLinesOfCode());
    assertEquals(normalize(code), normalize(result.toString()));
}

From source file:de.fosd.jdime.stats.parser.ParserTest.java

@Test
public void testParse() throws Exception {
    File file = file("threeway", "linebased", "SimpleTests", "Bag", "Bag2.java");
    String code = FileUtils.readFileToString(file, UTF_8);
    ParseResult result = Parser.parse(code);

    assertEquals(11, result.getLinesOfCode());
    assertEquals(1, result.getConflicts());
    assertEquals(7, result.getConflictingLinesOfCode());
    assertEquals(normalize(code), normalize(result.toString()));

    file = file("threeway", "linebased", "SimpleTests", "Bag", "Bag3.java");
    code = FileUtils.readFileToString(file, UTF_8);
    result = Parser.parse(code);/*from  ww  w. ja va 2 s  . c om*/

    assertEquals(20, result.getLinesOfCode());
    assertEquals(0, result.getConflicts());
    assertEquals(0, result.getConflictingLinesOfCode());
    assertEquals(normalize(code), normalize(result.toString()));

    file = file("threeway", "linebased", "ParserTest", "Comments.java");
    code = FileUtils.readFileToString(file, UTF_8);
    result = Parser.parse(code);

    assertEquals(7, result.getLinesOfCode());
    assertEquals(0, result.getConflicts());
    assertEquals(0, result.getConflictingLinesOfCode());
    assertEquals(normalize(code), normalize(result.toString()));

    file = file("threeway", "linebased", "ParserTest", "CommentsConflict.java");
    code = FileUtils.readFileToString(file, UTF_8);
    result = Parser.parse(code);

    assertEquals(11, result.getLinesOfCode());
    assertEquals(1, result.getConflicts());
    assertEquals(2, result.getConflictingLinesOfCode());
    assertEquals(normalize(code), normalize(result.toString()));
}

From source file:cop.raml.processor.SimpleJavaFileObjectImpl.java

@Override
public CharSequence getCharContent(boolean b) throws IOException {
    return FileUtils.readFileToString(file, StandardCharsets.UTF_8);
}

From source file:com.lynn.controller.FileAction.java

@RequestMapping("/read.do")
@ResponseBody/* ww  w  .  jav  a2s  .  co m*/
public String read() throws IOException {
    File file = initFile();
    //FileUtils ?
    String content = FileUtils.readFileToString(file, encoding);
    List<String> listStrs = FileUtils.readLines(file, encoding);
    //??

    return content;
}

From source file:cat.calidos.morfeu.model.transform.TransformJSONToXMLIntTest.java

@Before
public void setup() throws Exception {

    File inputFile = new File("target/test-classes/test-resources/transform/document1-as-view.json");
    content = FileUtils.readFileToString(inputFile, Config.DEFAULT_CHARSET);

}

From source file:net.rptools.tokentool.AppSetup.java

public static void install(String versionString) {
    System.setProperty("appHome", getAppHome("logs").getAbsolutePath());
    log = LogManager.getLogger(AppSetup.class);

    File overlayVer = new File(getAppHome().getAbsolutePath() + "/version.txt");
    Collection<File> existingOverLays = FileUtils.listFiles(AppConstants.OVERLAY_DIR,
            ImageUtil.SUPPORTED_FILE_FILTER, TrueFileFilter.INSTANCE);
    log.info("Overlays installed: " + existingOverLays.size());

    // Only install overlays once or if version.text is missing or version is newer
    // Overlays are stored in a version packaged structure so we can later install only newer overlays if wanted
    String installedVersion = "0";
    try {/*  w ww  .  j a  v  a 2s . co  m*/
        if (overlayVer.exists()) {
            installedVersion = FileUtils.readFileToString(overlayVer, Charset.defaultCharset());
        } else {
            FileUtils.writeStringToFile(overlayVer, versionString, Charset.defaultCharset());
        }
    } catch (IOException ioe) {
        log.error(ioe);
    }

    if (existingOverLays.isEmpty() || isNewerVersion(TokenTool.getVersion(), installedVersion)) {
        try {
            installDefaultOverlays();
        } catch (IOException e) {
            log.error(e);
        }

        // Update version file to new version
        try {
            FileUtils.writeStringToFile(overlayVer, versionString, Charset.defaultCharset());
        } catch (IOException e) {
            log.error(e);
        }
    }
}

From source file:com.screenslicer.core.scrape.neural.NeuralNetManager.java

public static void add(File config) {
    if (config != null) {
        try {/*  www  . ja  v a  2s  .c  o  m*/
            add(FileUtils.readFileToString(config, "utf-8"));
        } catch (Exception e) {
            Log.exception(e);
            throw new RuntimeException(e);
        }
    }
}

From source file:net.sf.jtmt.tokenizers.SentenceTokenizer.java

/**
 * Instantiates a new sentence tokenizer.
 *
 * @param rulesfile the rulesfile/*ww w .  ja v  a 2 s.  c  o  m*/
 * @throws Exception the exception
 */
public SentenceTokenizer(String rulesfile) throws Exception {
    super();
    this.breakIterator = new RuleBasedBreakIterator(
            FileUtils.readFileToString(new File(getClass().getResource(rulesfile).getFile()), "UTF-8"));
}