Package org.apache.commons.io.output

Examples of org.apache.commons.io.output.StringBuilderWriter


     * @return result of evaluating script.
     */
    public Object eval(WebDriver driver, String script, String cast) {
        VarsMap varsMap = context.getVarsMap();
        boolean hasStoredVars = script.matches(".*\\bstoredVars\\b.*");
        StringBuilderWriter writer = new StringBuilderWriter();
        if (hasStoredVars) {
            writer.append("return (function(){var storedVars = ");
            try {
                new JSONObject(varsMap).write(writer);
            } catch (JSONException e) {
                throw new RuntimeException(e);
            }
            writer.append(";\n");
        }
        writer.append("return [");
        if (cast != null)
            writer.append(cast);
        writer.append("((function(){");
        mutator.mutate(script, writer.getBuilder());
        writer.append("})())");
        if (hasStoredVars)
            writer.append(", storedVars];})();");
        else
            writer.append("];");
        Object result = ((JavascriptExecutor) driver).executeScript(writer.toString());
        if (!(result instanceof List))
            throw new SeleniumException(result.toString());
        List<?> list = (List<?>) result;
        switch (list.size()) {
        case 0:
View Full Code Here


     * @throws NullPointerException if the input is null
     * @throws IOException if an I/O error occurs
     */
    public static String toString(InputStream input, String encoding)
            throws IOException {
        StringBuilderWriter sw = new StringBuilderWriter();
        copy(input, sw, encoding);
        return sw.toString();
    }
View Full Code Here

     * @return the requested String
     * @throws NullPointerException if the input is null
     * @throws IOException if an I/O error occurs
     */
    public static String toString(Reader input) throws IOException {
        StringBuilderWriter sw = new StringBuilderWriter();
        copy(input, sw);
        return sw.toString();
    }
View Full Code Here

     * @param patch the patch to serialize
     * @param namespaces the namespaces to use
     * @return String representation of the given patch.
     */
    public static String toString(List<PatchLine> patch, Map<String, String> namespaces) {
        StringBuilderWriter sbw = new StringBuilderWriter();
        writePatch(sbw, patch, namespaces);
        return sbw.toString();
    }
View Full Code Here

public class LimitingTeeWriterTest {

  @Test
  public void testControl() throws IOException {
    final String content = "<p>Simple content</p>";
    StringBuilderWriter stringWriter = new StringBuilderWriter();
    LimitingTeeWriter writer = new LimitingTeeWriter(content.length(), NullWriter.NULL_WRITER, stringWriter);
    writer.write(content);

    Assert.assertFalse(writer.isLimitReached());
    Assert.assertEquals(content, stringWriter.toString());
  }
View Full Code Here

  }
 
  @Test
  public void testContentExceedsThreshold() throws IOException {
    final String content = "<p>Simple content</p>";
    StringBuilderWriter stringWriter = new StringBuilderWriter();
        LimitingTeeWriter writer = new LimitingTeeWriter(content.length() - 1, NullWriter.NULL_WRITER, stringWriter);
    writer.write(content);

    Assert.assertTrue(writer.isLimitReached());
    Assert.assertEquals("", stringWriter.toString());
    // try to write more and see no results
    writer.write("a");
    Assert.assertEquals("", stringWriter.toString());
  }
View Full Code Here

  }
 
  @Test
  public void testContentExceedsClearBuffer() throws IOException {
    final String content = "<p>Simple content</p>";
    final StringBuilderWriter stringWriter = new StringBuilderWriter();
        LimitingTeeWriter writer = new LimitingTeeWriter(content.length() - 1, NullWriter.NULL_WRITER, stringWriter,
                new Function<LimitingTeeWriter, Object>() {
                    @Override
                    public Object apply(LimitingTeeWriter input) {
                        final StringBuilder builder = stringWriter.getBuilder();
                        builder.delete(0, builder.length());
                        return null;
                    }
        });
    // write the first few chars
    writer.write(content.substring(0, 5));
    // verify content successfully buffered
    Assert.assertFalse(writer.isLimitReached());
    Assert.assertEquals(content.substring(0,5), stringWriter.toString());

    // now write the remainder
    writer.write(content.substring(5, content.length()));
   
    Assert.assertTrue(writer.isLimitReached());
    Assert.assertEquals("", stringWriter.toString());
    // try to write more and see no results
    writer.write("a");
    Assert.assertEquals("", stringWriter.toString());
  }
View Full Code Here

  }
   
    @Test
    public void testContentExceedsResetBuffer() throws IOException {
        final String content = "<p>Simple content</p>";
        StringBuilderWriter stringWriter = new StringBuilderWriter();
        LimitingTeeWriter writer = new LimitingTeeWriter(content.length() - 1, NullWriter.NULL_WRITER, stringWriter);
        writer.write(content);

        Assert.assertTrue(writer.isLimitReached());
        Assert.assertEquals("", stringWriter.toString());
       
        writer.resetByteCount();
       
        // try to write more and see results
        writer.write("a");
        Assert.assertEquals("a", stringWriter.toString());
    }
View Full Code Here

            throw new IllegalStateException("getOutputStream() has already been called");
        }

        if (this.printWriter == null) {
            final PrintWriter delegateWriter = this.portletOutputHandler.getPrintWriter();
            this.cachingWriter = new StringBuilderWriter();
           
            //Create the limiting tee writer to write to the actual PrintWriter and the cachingWriter
            this.teeWriter = new LimitingTeeWriter(this.maximumSize, delegateWriter,
                    this.cachingWriter, new Function<LimitingTeeWriter, Object>() {
                        @Override
View Full Code Here

      try{
        accept(inner);
      }catch(Exception e){
        Textifier t = new Textifier();
        accept(new TraceMethodVisitor(t));
        StringBuilderWriter sw = new StringBuilderWriter();
        PrintWriter pw = new PrintWriter(sw);
        t.print(pw);
        pw.flush();
        String bytecode = sw.getBuilder().toString();
        logger.error(String.format("Failure while rendering method %s, %s, %s.  ByteCode:\n %s", name, desc, signature, bytecode), e);
        throw new RuntimeException(String.format("Failure while rendering method %s, %s, %s.  ByteCode:\n %s", name, desc, signature, bytecode), e);
      }

    }
View Full Code Here

TOP

Related Classes of org.apache.commons.io.output.StringBuilderWriter

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.