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.playonlinux.bash.ScriptLegacyTest.java

@Test
public void testDetectType_passALegacyScriptCRLFSeparator_FormatIsDetected() throws IOException {
    assertEquals(Script.Type.LEGACY, Script.detectScriptType(FileUtils
            .readFileToString(new File(this.getClass().getResource("legacyScriptExampleCRLF.sh").getPath()))));
}

From source file:com.bhuwan.eventregistration.business.boundary.EventRegistrationResource.java

@GET
public Response getAllEventData() throws FileNotFoundException, IOException {
    String path = getClass().getClassLoader().getResource("/eventdata/").getPath();
    File eventDataDirectory = new File(path);
    String[] list = eventDataDirectory.list();
    JsonArray array = new JsonArray();
    for (String fileName : list) {
        array.add(new JsonParser().parse(FileUtils.readFileToString(Paths.get(path + fileName).toFile())));
    }//from  w  w  w .j a  va2s. c  om
    return Response.ok(array.toString()).header("Access-Control-Allow-Origin", "*").build();
}

From source file:au.csiro.casda.sodalint.ValidateServiceDescriptorTest.java

/**
 * Test method forau.csiro.casda.sodalint.ValidateServiceDescriptor#verifyServiceDescriptor
 * .//from  ww w.  jav  a2s  . c o m
 * 
 * @throws IOException
 *             If the data file cannot be read.
 */
@Test
public void testVerifyV13ServiceDescriptor() throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PrintStream ps = new PrintStream(baos, false, CHARSET_UTF_8);
    Reporter reporter = new TextOutputReporter(ps, ReportType.values(), 10, false, 1024);
    String xmlContent = FileUtils
            .readFileToString(new File("src/test/resources/service-descriptor-v1_3-good.xml"));
    vsd.verifyServiceDescriptor(reporter, xmlContent);

    String result = baos.toString(CHARSET_UTF_8);
    System.out.println(result);
    assertEquals("No message should have been reported", "", result);
}

From source file:com.jamespot.glifpix.wrappers.SampleHtmlTestService.java

protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    response.setStatus(HttpServletResponse.SC_OK);

    PrintWriter out = response.getWriter();

    String htmlPage = FileUtils.readFileToString(new File(props.getProperty("tagsServer.testPage")));

    out.println(htmlPage);/*from  w  w  w .j a va2  s .co  m*/
}

From source file:com.meltmedia.cadmium.core.meta.AlternateContentConfigProcessor.java

@Override
public void processFromDirectory(String metaDir) throws Exception {
    Configuration newStagedConfig = new Configuration();
    if (metaDir != null) {
        String configFile = FileSystemManager.getFileIfCanRead(metaDir, CONFIG_FILE_NAME);
        if (configFile != null) {
            newStagedConfig.metaDir = new File(metaDir);
            String contents = FileUtils.readFileToString(new File(configFile));
            logger.debug("Parsing {}/{}", new Object[] { newStagedConfig.metaDir, CONFIG_FILE_NAME });
            Collection<AlternateContent> parsedConfigs = new Gson().fromJson(contents,
                    new TypeToken<Collection<AlternateContent>>() {
                    }.getType());//  w w w .j a v a2s  .  c  om
            for (AlternateContent config : parsedConfigs) {
                config.compiledPattern = Pattern.compile(config.getPattern());
                newStagedConfig.configs.add(config);
            }
        }
    }
    stagedConfig = newStagedConfig;
}

From source file:io.fabric8.runsh.RunShLoaderTest.java

@Test
public void checkCopyScript() throws IOException {
    File dest = File.createTempFile("run", ".sh");
    RunShLoader.copyRunScript(dest);//w  w  w  .j ava 2 s .  com
    String orig = RunShLoader.getRunScript();
    String copied = FileUtils.readFileToString(dest);
    assertEquals(orig, copied);
}

From source file:io.proleap.cobol.preprocessor.sub.line.writer.CobolLineWriterTest.java

@Test
public void testSerializeLinesLineContinuation() throws Exception {
    final CobolLineWriter writer = new CobolLineWriterImpl();
    final List<CobolLine> lines = new ArrayList<CobolLine>();

    lines.add(new CobolLine("123456", " ", "77  ", "WS-TEST-12-DATA", "NC2054.2", CobolSourceFormatEnum.FIXED,
            null, 0, CobolLineTypeEnum.NORMAL));
    lines.add(new CobolLine("123456", " ", "    ", "                   PIC S9(", "NC2054.2",
            CobolSourceFormatEnum.FIXED, null, 1, CobolLineTypeEnum.NORMAL));
    lines.add(new CobolLine("123456", "-", "6)V9", "(6).", "NC2054.2", CobolSourceFormatEnum.FIXED, null, 2,
            CobolLineTypeEnum.CONTINUATION));
    lines.add(new CobolLine("123456", " ", "77  ", "WS-TEST-13-DATA", "NC2054.2", CobolSourceFormatEnum.FIXED,
            null, 3, CobolLineTypeEnum.NORMAL));

    final String serializedInput = writer.serialize(lines);

    final File expectedFile = new File(
            "src/test/resources/io/proleap/cobol/preprocessor/sub/line/writer/LineContinuation.cbl.preprocessed");
    final String expected = FileUtils.readFileToString(expectedFile);
    assertEquals(expected, serializedInput);
}

From source file:com.meltmedia.cadmium.core.meta.RedirectConfigProcessor.java

@Override
public void processFromDirectory(String metaDir) throws Exception {
    List<Redirect> newStagedRedirects = new ArrayList<Redirect>();
    if (metaDir != null) {
        String redirectFile = FileSystemManager.getFileIfCanRead(metaDir, CONFIG_FILE_NAME);
        if (redirectFile != null) {
            Gson gson = new Gson();
            Collection<Redirect> redirs = null;
            try {
                redirs = gson.fromJson(FileUtils.readFileToString(new File(redirectFile)),
                        new TypeToken<Collection<Redirect>>() {
                        }.getType());//  www. ja v a 2s.co m
            } catch (Exception e) {
                log.error("Invalid " + CONFIG_FILE_NAME + "!", e);
                throw e;
            }
            if (redirs != null && !redirs.isEmpty()) {
                for (Redirect redir : redirs) {
                    redir.setPath(redir.getPath());
                    newStagedRedirects.add((Redirect) redir.clone());
                }
            }
        }
    }
    stagedRedirects = newStagedRedirects;
}

From source file:de.eidottermihi.rpicheck.test.LoadAverageTest.java

@Test
public void load_avg_fifteen_minutes() throws IOException, RaspiQueryException {
    String output = FileUtils.readFileToString(
            FileUtils.getFile("src/test/java/de/eidottermihi/rpicheck/test/proc_loadavg.txt"));
    sessionMocker.withCommand(COMMAND, new CommandMocker().withResponse(output).mock());
    double queryLoadAverage = raspiQuery.queryLoadAverage(LoadAveragePeriod.FIFTEEN_MINUTES);
    assertEquals(0.53D, queryLoadAverage, 0.001D);
}

From source file:be.idamediafoundry.sofa.livecycle.maven.GenerateComponentXmlMojoTest.java

@Test
public void testExecuteDoclet() throws Exception {
    String sourcePath = this.getClass().getResource("/pckg/doclet").getFile();
    mojo = new GenerateComponentXmlMojo("host", "port", "protocol", "username", "password", original, result,
            sourcePath, "doclets");
    mojo.execute();//from  w  w  w.  j  a  v a2  s . co  m

    System.out.println(FileUtils.readFileToString(result));
}