Package java.io

Examples of java.io.CharArrayWriter


            }
        }

        public void clearBuffer() throws IOException {
            if(buf != null) {
                buf = new CharArrayWriter();
            }
            else {
                throw new IOException("Can't clear");
            }
        }
View Full Code Here


    public TelnetPrintWriter(OutputStream os, TelnetStateMachine tsm,
            TelnetSession ts) {
        super(os);
        this.ts = ts;
        Writer w1 = super.out; // get the underlaying writer
        caw = new CharArrayWriter(); // intermediate array writer
        super.out = caw; // replace underlying Writer with a CharArrayWriter
        pw2 = new PrintWriter(w1); // a private PrintWriter
    }
View Full Code Here

        try
        {
            DOMSource source = new DOMSource(_cipangoConfig);

            CharArrayWriter writer = new CharArrayWriter();
            StreamResult result = new StreamResult(writer);
            TransformerFactory factory = TransformerFactory.newInstance();
            Transformer transformer = factory.newTransformer();
            transformer.transform(source, result);
            String _xmlConfigString = writer.toString();

            // get rid of the first line, as this will be prepended by
            // the XmlConfiguration
            int index = _xmlConfigString.indexOf("?>");
            if (index >= 0)
View Full Code Here

    throws ServletException, IOException
  {
    if (_embedError && res.isCommitted()) {
      _app.log(e.getMessage(), e);
     
      CharArrayWriter writer = new CharArrayWriter();
      PrintWriter pw = new PrintWriter(writer);
      e.printStackTrace(pw);
      pw.flush();
     
      res.getWriter().print(writer.toCharArray());
    }
    else if (e instanceof ServletException)
      throw (ServletException) e;
    else if (e instanceof IOException)
      throw (IOException) e;
View Full Code Here

    public void response_sent() throws IOException
    {
        String encoding = "UTF-8";
        Response response = mockResponse();

        CharArrayWriter writer = new CharArrayWriter();
        PrintWriter pw = new PrintWriter(writer);

        expect(response.getPrintWriter("application/json;charset=UTF-8")).andReturn(pw);

        replay();

        JSONArray array = new JSONArray("   [ \"fred\", \"barney\" \n\n]");

        JSONArrayEventResultProcessor p = new JSONArrayEventResultProcessor(response, encoding);

        p.processResultValue(array);

        verify();

        assertEquals(writer.toString(), "[\n  \"fred\",\n  \"barney\"\n]");
    }
View Full Code Here

    @Test
    public void array_print_and_pretty_print()
    {
        JSONArray a = new JSONArray("fred", "barney");

        CharArrayWriter caw = new CharArrayWriter();
        PrintWriter pw = new PrintWriter(caw);

        a.print(pw);

        String compact = caw.toString();

        caw.reset();

        a.prettyPrint(pw);

        String pretty = caw.toString();

        assertEquals(compact, "[\"fred\",\"barney\"]");
        assertEquals(pretty, "[\n  \"fred\",\n  \"barney\"\n]");
    }
View Full Code Here

     *         brace)</small>.
     */
    @Override
    public String toString()
    {
        CharArrayWriter caw = new CharArrayWriter();
        PrintWriter pw = new PrintWriter(caw);

        JSONPrintSession session = new PrettyPrintSession(pw);

        print(session);

        pw.close();

        return caw.toString();
    }
View Full Code Here

     * Prints the JSONObject as a compact string (not extra punctuation). This is, essentially, what
     * Tapestry 5.1 did inside {@link #toString()}.
     */
    public String toCompactString()
    {
        CharArrayWriter caw = new CharArrayWriter();
        PrintWriter pw = new PrintWriter(caw);

        print(pw);

        pw.close();

        return caw.toString();
    }
View Full Code Here

     * @throws NullPointerException if the input is null
     * @throws IOException if an I/O error occurs
     * @since Commons IO 1.1
     */
    public static char[] toCharArray(InputStream is) throws IOException {
        CharArrayWriter output = new CharArrayWriter();
        copy(is, output);
        return output.toCharArray();
    }
View Full Code Here

     * @throws IOException if an I/O error occurs
     * @since Commons IO 1.1
     */
    public static char[] toCharArray(InputStream is, String encoding)
            throws IOException {
        CharArrayWriter output = new CharArrayWriter();
        copy(is, output, encoding);
        return output.toCharArray();
    }
View Full Code Here

TOP

Related Classes of java.io.CharArrayWriter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.