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:org.apache.hadoop.gateway.filter.rewrite.impl.xml.XmlFilterReaderTest.java

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

From source file:org.apache.hadoop.gateway.filter.rewrite.impl.xml.XmlFilterReaderTest.java

@Test
public void testSimpleStreaming() throws IOException, ParserConfigurationException, XMLStreamException {
    UrlRewriteRulesDescriptor rulesConfig = UrlRewriteRulesDescriptorFactory.create();
    UrlRewriteFilterDescriptor filterConfig = rulesConfig.addFilter("filter-1");
    UrlRewriteFilterContentDescriptor contentConfig = filterConfig.addContent("text/xml");

    String inputXml = "<root/>";
    StringReader inputReader = new StringReader(inputXml);
    XmlFilterReader filterReader = new NoopXmlFilterReader(inputReader, contentConfig);
    String outputHtml = new String(IOUtils.toCharArray(filterReader));
    assertThat(the(outputHtml), hasXPath("/root"));
}

From source file:org.apache.hadoop.gateway.filter.rewrite.impl.xml.XmlFilterReaderTest.java

@Test
public void testSimpleBuffered() throws IOException, ParserConfigurationException, XMLStreamException {
    UrlRewriteRulesDescriptor rulesConfig = UrlRewriteRulesDescriptorFactory.create();
    UrlRewriteFilterDescriptor filterConfig = rulesConfig.addFilter("filter-1");
    UrlRewriteFilterContentDescriptor contentConfig = filterConfig.addContent("text/xml");
    UrlRewriteFilterBufferDescriptor scopeConfig = contentConfig.addBuffer("/root");

    String input = "<root/>";
    //System.out.println( "INPUT=" + input );
    StringReader inputReader = new StringReader(input);
    XmlFilterReader filterReader = new NoopXmlFilterReader(inputReader, contentConfig);
    String output = new String(IOUtils.toCharArray(filterReader));
    //System.out.println( "OUTPUT=" + output );
    assertThat(the(output), hasXPath("/root"));
}

From source file:org.apache.hadoop.gateway.filter.rewrite.impl.xml.XmlFilterReaderTest.java

@Test
public void testSimpleNested() throws IOException, ParserConfigurationException, XMLStreamException {
    String inputXml = "<root><child1><child11/><child12/></child1><child2><child21/><child22/></child2></root>";
    StringReader inputReader = new StringReader(inputXml);
    XmlFilterReader filterReader = new NoopXmlFilterReader(inputReader, null);
    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.xml.XmlFilterReaderTest.java

@Test
public void testSimpleWithNamespace() throws IOException, ParserConfigurationException, XMLStreamException {
    String inputXml = "<ns:root xmlns:ns='http://hortonworks.com/xml/ns'></ns:root>";
    StringReader inputReader = new StringReader(inputXml);
    XmlFilterReader filterReader = new NoopXmlFilterReader(inputReader, null);
    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.xml.XmlFilterReaderTest.java

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

From source file:org.apache.hadoop.gateway.filter.rewrite.impl.xml.XmlFilterReaderTest.java

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

From source file:org.apache.hadoop.gateway.filter.rewrite.impl.xml.XmlFilterReaderTest.java

@Test
public void testSimpleTextNodeBuffered() throws IOException, ParserConfigurationException, XMLStreamException {
    UrlRewriteRulesDescriptor rulesConfig = UrlRewriteRulesDescriptorFactory.create();
    UrlRewriteFilterDescriptor filterConfig = rulesConfig.addFilter("filter-1");
    UrlRewriteFilterContentDescriptor contentConfig = filterConfig.addContent("text/xml");
    UrlRewriteFilterBufferDescriptor scopeConfig = contentConfig.addBuffer("/root");

    String inputXml = "<root>text</root>";
    StringReader inputReader = new StringReader(inputXml);
    XmlFilterReader filterReader = new NoopXmlFilterReader(inputReader, contentConfig);
    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.xml.XmlFilterReaderTest.java

@Test
public void testSimpleAttributeBuffered() throws IOException, ParserConfigurationException, XMLStreamException {
    UrlRewriteRulesDescriptor rulesConfig = UrlRewriteRulesDescriptorFactory.create();
    UrlRewriteFilterDescriptor filterConfig = rulesConfig.addFilter("filter-1");
    UrlRewriteFilterContentDescriptor contentConfig = filterConfig.addContent("text/xml");
    UrlRewriteFilterBufferDescriptor scopeConfig = contentConfig.addBuffer("/root");

    String inputXml = "<root name='value'/>";
    StringReader inputReader = new StringReader(inputXml);
    XmlFilterReader filterReader = new NoopXmlFilterReader(inputReader, contentConfig);
    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.xml.XmlFilterReaderTest.java

@Test
public void testMappedText() throws IOException, ParserConfigurationException, XMLStreamException {
    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);
    XmlFilterReader 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")));
}