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:de.tsystems.mms.apm.performancesignature.dynatrace.MemoryDumpTest.java

@Test
public void testJenkinsConfiguration() throws Exception {
    FreeStyleProject project = j.createFreeStyleProject();
    PerfSigMemoryDump memoryDump = new PerfSigMemoryDump(dynatraceConfigurations.get(0).name,
            "CustomerFrontend_easyTravel_8080", "wum192202");
    memoryDump.setType("extended");
    project.getBuildersList().add(memoryDump);
    FreeStyleBuild build = j.assertBuildStatusSuccess(project.scheduleBuild2(0));

    String s = FileUtils.readFileToString(build.getLogFile());
    assertTrue(s.contains("successfully created memory dump on"));
}

From source file:com.github.wesoly.happy.builder.generator.writer.AbstractWiterTest.java

public void setUp() throws Exception {
    URL url = this.getClass().getResource("/testBuilderClass.txt");
    assertThat(url).isNotNull();/*from  w ww  . jav a2  s  .  c om*/
    File testBuilder = new File(url.getFile());
    expectedTestBuilder = FileUtils.readFileToString(testBuilder);
    expectedTestBuilderNorm = normalize(expectedTestBuilder);
}

From source file:be.idamediafoundry.sofa.livecycle.dsc.util.DelegatingComponentGeneratorTest.java

@Test
public void test() throws Exception {
    File file = File.createTempFile("test", "xml");
    File original = new File(this.getClass().getResource("/base/base-component.xml").getFile());
    generator.generateComponentXML(original, file);
    System.out.println(FileUtils.readFileToString(file));
}

From source file:com.foo.bar.si.file.demo.starter.TransformationHandler.java

/**
 * Actual Spring Integration transformation handler.
 *
 * @param inputMessage Spring Integration input message
 * @return New Spring Integration message with updated headers
 *///w  ww  . j  av a2s .c  o  m
@Transformer
public Message<String> handleFile(final Message<File> inputMessage) {

    final File inputFile = inputMessage.getPayload();
    final String filename = inputFile.getName();
    final String fileExtension = FilenameUtils.getExtension(filename);

    final String inputAsString;

    try {
        inputAsString = FileUtils.readFileToString(inputFile);
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }

    final Message<String> message = MessageBuilder.withPayload(inputAsString.toUpperCase(Locale.ENGLISH))
            .setHeader(FileHeaders.FILENAME, filename).setHeader(FileHeaders.ORIGINAL_FILE, inputFile)
            .setHeader("file_size", inputFile.length()).setHeader("file_extension", fileExtension).build();

    return message;
}

From source file:egovframework.mgt.fit.library.parser.SourceParser.java

/**
 *  ? ?? ?.//from   ww  w . j  a  v a  2s  . c  o m
 * @param path   (?)
 * @param project ? ?
 * @return ?  
 */
public static boolean registerClass(String path, Project project) {

    if (project == null) {
        return false;
    }

    try {

        String source = FileUtils.readFileToString(new File(path));
        ASTParser parser = ASTParser.newParser(AST.JLS3);
        parser.setSource(source.toCharArray());
        CompilationUnit cu = (CompilationUnit) parser.createAST(null);

        /*      for (ImportDeclaration id : (List<ImportDeclaration>) cu.imports()) {
                 if (!project
          .hasClass(StringHelper.concatNameWithDot(project
                .getKey(), id.getName().getFullyQualifiedName()))) {
                    resolveClass((QualifiedName) id.getName(), project);
                 }
                         
              }*/

        for (AbstractTypeDeclaration type : (List<AbstractTypeDeclaration>) cu.types()) {
            if (type.getNodeType() == ASTNode.TYPE_DECLARATION) {
                UnitList<JavaClass> imports = new UnitList<JavaClass>();
                for (ImportDeclaration id : (List<ImportDeclaration>) cu.imports()) {
                    JavaClass ic = project.resolveClass(id.getName().toString());
                    imports.addUnit(ic);
                }

                resolveClass(cu.getPackage(), (TypeDeclaration) type, imports, project).setProjectClass(true)
                        .setPosition(new Directory(path));
            }
        }

    } catch (IOException ie) {
        ie.printStackTrace();
        return false;
    }
    /*
     * JavaSourceFactory jsf = new JavaSourceFactory(); try { JavaParser jp
     * = new JavaParser(jsf);
     * 
     * BufferedReader br = new BufferedReader(new InputStreamReader( new
     * BOMInputStream(new FileInputStream(new File(path)))));
     * 
     * jp.parse(br); } catch (RecognitionException re) {
     * re.printStackTrace(); return false; } catch (FileNotFoundException
     * fnfe) { fnfe.printStackTrace(); return false; } catch
     * (TokenStreamException tse) { tse.printStackTrace(); return false; }
     * catch (Exception e) { e.printStackTrace(); return false; }
     * 
     * if (!jsf.getJavaSources().hasNext()) { return false; }
     * 
     * for (Iterator iter = jsf.getJavaSources(); iter.hasNext();) {
     * JavaSource js = (JavaSource) iter.next(); resolveClass(js, project);
     * }
     */

    return true;
}

From source file:com.jdom.word.playdough.model.DefaultCacheHandler.java

public void addCachedLockStatus(String user, String pack, boolean lockStatus) {
    String existingLine = null;/*from ww  w.ja  v  a  2  s . c om*/
    try {
        existingLine = FileUtils.readFileToString(new File(directory, "cachedLockStatus"));
    } catch (IOException e) {

    }

    existingLine = (existingLine == null) ? pack : existingLine + SPLIT + pack;

    try {
        FileUtils.write(new File(directory, "cachedLockStatus"), existingLine);
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }
}

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

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

From source file:mase.stat.RunStatistics.java

@Override
public void preInitializationStatistics(EvolutionState state) {
    super.preInitializationStatistics(state);

    state.output.println("# " + getComputerName(), log);
    state.output.println("# Generation " + state.generation + " " + new Date().toString(), log);

    // Fetch config file
    String[] args = state.runtimeArguments;
    String f = null;/*from  w w  w.j a va  2  s . com*/
    for (int i = 0; i < args.length; i++) {
        if (args[i].equalsIgnoreCase("-file")) {
            f = args[i + 1];
            break;
        }
    }
    File file = f != null ? new File(f) : null;
    // Write config file to log
    if (file != null && file.exists()) {
        try {
            state.output.println("\n# " + file.getName(), log);
            String content = FileUtils.readFileToString(file);
            state.output.println(content + "\n", log);
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
}

From source file:cc.recommenders.io.ZipFolderTest.java

@Test
public void FolderMarkersContainMetaData() throws IOException {
    _sut = new ZipFolder(_root.getAbsolutePath(), "xyz");
    _sut.createNewArchive();/*w  w w . ja  v a  2s .c  om*/

    String actual = FileUtils.readFileToString(file(_root, ZipFolder.MARKER_FILE_NAME));
    assertEquals("xyz", actual);
}