Example usage for org.apache.commons.io IOUtils toCharArray

List of usage examples for org.apache.commons.io IOUtils toCharArray

Introduction

In this page you can find the example usage for org.apache.commons.io IOUtils toCharArray.

Prototype

public static char[] toCharArray(Reader input) throws IOException 

Source Link

Document

Get the contents of a Reader as a character array.

Usage

From source file:nl.surfnet.coin.teams.control.AddMemberController.java

/**
 * Combines the input of the emails field and the csv file
 *
 * @param form {@link InvitationForm}//from ww  w  .j av a2s. co m
 * @return String with the emails
 * @throws IOException if the CSV file cannot be read
 */
private String getAllEmailAddresses(InvitationForm form) throws IOException {
    StringBuilder sb = new StringBuilder();

    MultipartFile csvFile = form.getCsvFile();
    String emailString = form.getEmails();
    boolean appendEmails = StringUtils.hasText(emailString);
    if (form.hasCsvFile()) {
        sb.append(IOUtils.toCharArray(csvFile.getInputStream()));
        if (appendEmails) {
            sb.append(',');
        }
    }
    if (appendEmails) {
        sb.append(emailString);
    }

    return sb.toString();
}

From source file:org.apache.cxf.xjc.javadoc.JavadocPluginTest.java

private CompilationUnit parseSourceFile(String fileName) throws IOException, FileNotFoundException {
    FileReader inputFile = new FileReader(new File(OUTPUT_DIR + "/" + PACKAGE_DIR, fileName));
    char[] classChars = IOUtils.toCharArray(inputFile);
    inputFile.close();//from  w  w  w . java  2s  .c o  m
    ASTParser parser = ASTParser.newParser(AST.JLS3);
    @SuppressWarnings("rawtypes")
    Map options = JavaCore.getOptions();
    JavaCore.setComplianceOptions(JavaCore.VERSION_1_5, options);
    parser.setCompilerOptions(options);
    parser.setSource(classChars);
    CompilationUnit compilationUnit = (CompilationUnit) parser.createAST(null);

    return compilationUnit;
}

From source file:org.apache.hadoop.gateway.filter.rewrite.impl.html.HtmlFilterReaderBaseTest.java

@Test
public void testSimple() throws IOException, ParserConfigurationException {
    String inputXml = "<root/>";
    StringReader inputReader = new StringReader(inputXml);
    HtmlFilterReaderBase filterReader = new NoopXmlFilterReader(inputReader);
    String outputHtml = new String(IOUtils.toCharArray(filterReader));
    assertThat(the(outputHtml), hasXPath("/root"));
}

From source file:org.apache.hadoop.gateway.filter.rewrite.impl.html.HtmlFilterReaderBaseTest.java

@Test
public void testSimpleNested() throws IOException, ParserConfigurationException {
    String inputXml = "<root><child1><child11/><child12/></child1><child2><child21/><child22/></child2></root>";
    StringReader inputReader = new StringReader(inputXml);
    HtmlFilterReaderBase filterReader = new NoopXmlFilterReader(inputReader);
    String outputHtml = new String(IOUtils.toCharArray(filterReader));
    assertThat(the(outputHtml), hasXPath("/root"));
    assertThat(the(outputHtml), hasXPath("/root/child1"));
    assertThat(the(outputHtml), hasXPath("/root/child1/child11"));
    assertThat(the(outputHtml), hasXPath("/root/child1/child12"));
    assertThat(the(outputHtml), hasXPath("/root/child2"));
    assertThat(the(outputHtml), hasXPath("/root/child2/child21"));
    assertThat(the(outputHtml), hasXPath("/root/child2/child22"));
}

From source file:org.apache.hadoop.gateway.filter.rewrite.impl.html.HtmlFilterReaderBaseTest.java

@Test
public void testSimpleWithNamespace() throws IOException, ParserConfigurationException {
    String inputXml = "<ns:root xmlns:ns='http://hortonworks.com/xml/ns'></ns:root>";
    StringReader inputReader = new StringReader(inputXml);
    HtmlFilterReaderBase filterReader = new NoopXmlFilterReader(inputReader);
    String outputHtml = new String(IOUtils.toCharArray(filterReader));

    //System.out.println( outputHtml );
    SimpleNamespaceContext ns = new SimpleNamespaceContext();
    ns.bind("ns", "http://hortonworks.com/xml/ns");
    assertThat(the(outputHtml), hasXPath("/ns:root", ns));
}

From source file:org.apache.hadoop.gateway.filter.rewrite.impl.html.HtmlFilterReaderBaseTest.java

@Test
public void testSimpleTextNode() throws IOException, ParserConfigurationException {
    String inputXml = "<root>text</root>";
    StringReader inputReader = new StringReader(inputXml);
    HtmlFilterReaderBase filterReader = new NoopXmlFilterReader(inputReader);
    String outputHtml = new String(IOUtils.toCharArray(filterReader));
    //System.out.println( outputHtml );
    assertThat(the(outputHtml), hasXPath("/root/text()", equalTo("text")));
}

From source file:org.apache.hadoop.gateway.filter.rewrite.impl.html.HtmlFilterReaderBaseTest.java

@Test
public void testSimpleAttribute() throws IOException, ParserConfigurationException {
    String inputXml = "<root name='value'/>";
    StringReader inputReader = new StringReader(inputXml);
    HtmlFilterReaderBase filterReader = new NoopXmlFilterReader(inputReader);
    String outputHtml = new String(IOUtils.toCharArray(filterReader));
    //System.out.println( outputHtml );
    assertThat(the(outputHtml), hasXPath("/root/@name", equalTo("value")));
}

From source file:org.apache.hadoop.gateway.filter.rewrite.impl.html.HtmlFilterReaderBaseTest.java

@Test
public void testMappedText() throws IOException, ParserConfigurationException {
    Map<String, String> map = new HashMap<String, String>();
    map.put("input-text", "output-text");
    String inputXml = "<root>input-text</root>";
    StringReader inputReader = new StringReader(inputXml);
    HtmlFilterReaderBase filterReader = new MapXmlFilterReader(inputReader, map);
    String outputHtml = new String(IOUtils.toCharArray(filterReader));
    //System.out.println( outputHtml );
    assertThat(the(outputHtml), hasXPath("/root/text()", equalTo("output-text")));
}

From source file:org.apache.hadoop.gateway.filter.rewrite.impl.html.HtmlFilterReaderBaseTest.java

@Test
public void testMappedAttribute() throws IOException, ParserConfigurationException {
    Map<String, String> map = new HashMap<String, String>();
    map.put("input-text", "output-text");
    String inputXml = "<root attribute='input-text'/>";
    StringReader inputReader = new StringReader(inputXml);
    HtmlFilterReaderBase filterReader = new MapXmlFilterReader(inputReader, map);
    String outputHtml = new String(IOUtils.toCharArray(filterReader));
    //System.out.println( outputHtml );
    assertThat(the(outputHtml), hasXPath("/root/@attribute", equalTo("output-text")));
}

From source file:org.apache.hadoop.gateway.filter.rewrite.impl.html.HtmlFilterReaderBaseTest.java

@Test
public void testCombined() throws IOException, ParserConfigurationException {
    Map<String, String> map = new HashMap<String, String>();
    map.put("attr1-input", "attr1-output");
    map.put("attr2-input", "attr2-output");
    map.put("attr3-input", "attr3-output");
    map.put("attr4-input", "attr4-output");
    map.put("attr5-input", "attr5-output");
    map.put("attr6-input", "attr6-output");
    map.put("attr7-input", "attr7-output");
    map.put("root-input1", "root-output1");
    map.put("root-input2", "root-output2");
    map.put("root-input3", "root-output3");
    map.put("child1-input", "child1-output");
    map.put("child2-input", "child2-output");

    String inputXml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" + "<!-- Comment -->\n"
            + "<ns1:root xmlns:ns1='http://hortonworks.com/xml/ns1' attr1='attr1-input' ns1:attr2='attr2-input'>\n"
            + "  root-input1\n" + "  <child1 attr3='attr3-input' ns1:attr4='attr4-input'>\n"
            + "    child1-input\n" + "  </child1>\n" + "  root-input2\n"
            + "  <ns2:child2 xmlns:ns2='http://hortonworks.com/xml/ns2' attr5='attr5-input' ns1:attr6='attr6-input' ns2:attr7='attr7-input'>\n"
            + "    child2-input\n" + "  </ns2:child2>\n" + "  root-input3\n" + "</ns1:root>";
    //System.out.println( inputXml );

    StringReader inputReader = new StringReader(inputXml);
    HtmlFilterReaderBase filterReader = new MapXmlFilterReader(inputReader, map);
    String outputXml = new String(IOUtils.toCharArray(filterReader));
    //System.out.println( outputXml );
    //System.out.flush();

    SimpleNamespaceContext ns = new SimpleNamespaceContext();
    ns.bind("n1", "http://hortonworks.com/xml/ns1");
    ns.bind("n2", "http://hortonworks.com/xml/ns2");

    assertThat(the(outputXml), hasXPath("/n1:root", ns));
    assertThat(the(outputXml), hasXPath("/n1:root/@attr1", ns, equalTo("attr1-output")));
    assertThat(the(outputXml), hasXPath("/n1:root/@n1:attr2", ns, equalTo("attr2-output")));
    assertThat(the(outputXml), hasXPath("/n1:root/text()[1]", ns, equalTo("root-output1")));
    assertThat(the(outputXml), hasXPath("/n1:root/text()[2]", ns, equalTo("root-output2")));
    assertThat(the(outputXml), hasXPath("/n1:root/text()[3]", ns, equalTo("root-output3")));
    assertThat(the(outputXml), hasXPath("/n1:root/child1", ns));
    assertThat(the(outputXml), hasXPath("/n1:root/child1/@attr3", ns, equalTo("attr3-output")));
    assertThat(the(outputXml), hasXPath("/n1:root/child1/@n1:attr4", ns, equalTo("attr4-output")));
    assertThat(the(outputXml), hasXPath("/n1:root/child1/text()", ns, equalTo("child1-output")));
    assertThat(the(outputXml), hasXPath("/n1:root/n2:child2", ns));
    assertThat(the(outputXml), hasXPath("/n1:root/n2:child2/@attr5", ns, equalTo("attr5-output")));
    assertThat(the(outputXml), hasXPath("/n1:root/n2:child2/@n1:attr6", ns, equalTo("attr6-output")));
    assertThat(the(outputXml), hasXPath("/n1:root/n2:child2/@n2:attr7", ns, equalTo("attr7-output")));
    assertThat(the(outputXml), hasXPath("/n1:root/n2:child2/text()", ns, equalTo("child2-output")));
}