Example usage for java.io CharArrayWriter CharArrayWriter

List of usage examples for java.io CharArrayWriter CharArrayWriter

Introduction

In this page you can find the example usage for java.io CharArrayWriter CharArrayWriter.

Prototype

public CharArrayWriter() 

Source Link

Document

Creates a new CharArrayWriter.

Usage

From source file:Main.java

public static char[] toCharArray(InputStream input) throws IOException {
    CharArrayWriter output = new CharArrayWriter();
    write(input, output);/*w  ww.  j  a  va2s .  c  om*/
    return output.toCharArray();
}

From source file:Main.java

public static char[] toCharArray(InputStream input, String encoding) throws IOException {
    CharArrayWriter output = new CharArrayWriter();
    write(input, output, encoding);//from ww w.ja  va 2  s  . com
    return output.toCharArray();
}

From source file:Main.java

/**
 * Reads an XML document and returns it as a {@link String}.
 * /* w w  w  . j  a va 2 s .  c om*/
 * @param source the input source for the XML document
 * 
 * @return the XML document, as a {@link String}
 * 
 * @throws IOException
 */
public static String readXmlDocument(InputSource source) throws IOException {
    CharArrayWriter out = new CharArrayWriter();
    FileCopyUtils.copy(source.getCharacterStream(), out);
    return out.toString();
}

From source file:Main.java

public static char[] toCharArray(Reader input) throws IOException {
    CharArrayWriter output = new CharArrayWriter();
    write(input, output);/*w ww  . j  a  v  a2s  .  c  om*/
    return output.toCharArray();
}

From source file:Main.java

/**
 * Filters an XML document.//from  www. ja v a2  s .c om
 * 
 * @param source the input source for the XML document
 * @param filter the filter
 * 
 * @return an input source for the resulting document
 * 
 * @throws Exception
 */
public static InputSource filterXml(InputSource source, XMLFilter filter) throws Exception {
    // Create filter, which uses a "real" XMLReader but also removes the
    // attributes
    XMLReader reader = XMLReaderFactory.createXMLReader();
    filter.setParent(reader);

    // Create a Transformer
    TransformerFactory tf = TransformerFactory.newInstance();
    Transformer t = tf.newTransformer();

    // Transform the source tree, applying the filter, and store the result
    // tree in a character array
    CharArrayWriter writer = new CharArrayWriter();
    t.transform(new SAXSource(filter, source), new StreamResult(writer));

    // Return a new InputSource using the result tree
    return new InputSource(new CharArrayReader(writer.toCharArray()));
}

From source file:com.sap.prd.mobile.ios.mios.OTAManagerTest.java

@Test
public void testOtaUrlIsNull() throws Exception {
    OTAManager otaManager = new OTAManager(null, "", "", "", "", "", "", null);

    Assert.assertFalse(otaManager.generateOtaHTML());

    CharArrayWriter charWriter = new CharArrayWriter();
    try {//from w  w w. j a va 2s .  c  o  m
        otaManager.writeOtaHtml(new PrintWriter(charWriter));
        assertTrue(charWriter.size() == 0);
    } finally {
        closeQuietly(charWriter);
    }
}

From source file:UpperCaseFilter.java

public CharResponseWrapper(HttpServletResponse response) {
    super(response);

    charWriter = new CharArrayWriter();
}

From source file:org.opennaas.extensions.ofertie.ncl.provisioner.components.UserManager.java

private static String readXMLFile(String filePath) throws IOException {

    log.debug("Reading content of file " + filePath);

    InputStreamReader reader = null;
    BufferedReader bufferReader = null;
    try {//from w  w  w.  j  a v  a2s.  c  om
        URL url = new URL(filePath);
        reader = new InputStreamReader(url.openStream());
        bufferReader = new BufferedReader(reader);
    } catch (MalformedURLException ignore) {
        // They try a file
        File file = new File(filePath);
        bufferReader = new BufferedReader(new FileReader(file));
    }
    CharArrayWriter w = new CharArrayWriter();
    int n;
    char[] buf = new char[8192];
    while ((n = bufferReader.read(buf)) > 0) {
        w.write(buf, 0, n);
    }
    bufferReader.close();
    String fileContent = w.toString();
    log.debug("Readed content of file " + filePath);

    return fileContent;
}

From source file:org.gm4java.engine.support.AbstractGMConnectionTest.java

@Before
public void setup() throws Exception {
    MockitoAnnotations.initMocks(this);
    writer = new CharArrayWriter();
    when(process.getWriter()).thenReturn(writer);
    when(process.getReader()).thenReturn(reader);
}

From source file:org.displaytag.filter.BufferedResponseWrapper13Impl.java

/**
 * @param httpServletResponse the response to wrap
 *//* w  w  w . j a  va 2  s  .  co  m*/
public BufferedResponseWrapper13Impl(HttpServletResponse httpServletResponse) {
    super(httpServletResponse);
    this.outputWriter = new CharArrayWriter();
    this.servletOutputStream = new SimpleServletOutputStream();
}