Search in sources :

Example 1 with StringBuilderWriter

use of org.apache.commons.io.output.StringBuilderWriter in project uPortal by Jasig.

the class LimitingTeeWriterTest method testContentExceedsResetBuffer.

@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());
}
Also used : StringBuilderWriter(org.apache.commons.io.output.StringBuilderWriter) Test(org.junit.Test)

Example 2 with StringBuilderWriter

use of org.apache.commons.io.output.StringBuilderWriter in project uPortal by Jasig.

the class LimitingTeeWriterTest method testContentExceedsClearBuffer.

@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());
}
Also used : StringBuilderWriter(org.apache.commons.io.output.StringBuilderWriter) Test(org.junit.Test)

Example 3 with StringBuilderWriter

use of org.apache.commons.io.output.StringBuilderWriter in project uPortal by Jasig.

the class LimitingTeeWriterTest method testContentExceedsThreshold.

@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());
}
Also used : StringBuilderWriter(org.apache.commons.io.output.StringBuilderWriter) Test(org.junit.Test)

Example 4 with StringBuilderWriter

use of org.apache.commons.io.output.StringBuilderWriter in project uPortal by Jasig.

the class LimitingTeeWriterTest method testControl.

@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());
}
Also used : StringBuilderWriter(org.apache.commons.io.output.StringBuilderWriter) Test(org.junit.Test)

Example 5 with StringBuilderWriter

use of org.apache.commons.io.output.StringBuilderWriter in project uPortal by Jasig.

the class CachingPortletOutputHandler method getPrintWriter.

@Override
public PrintWriter getPrintWriter() throws IOException {
    if (teeStream != null) {
        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
            public Object apply(LimitingTeeWriter input) {
                //Limit hit, clear the cache
                clearCachedWriter();
                return null;
            }
        });
        //Wrap the limiting tee writer in a PrintWriter to return to the caller
        this.printWriter = new PrintWriter(this.teeWriter);
    }
    return this.printWriter;
}
Also used : StringBuilderWriter(org.apache.commons.io.output.StringBuilderWriter) Function(com.google.common.base.Function) PrintWriter(java.io.PrintWriter)

Aggregations

StringBuilderWriter (org.apache.commons.io.output.StringBuilderWriter)7 Test (org.junit.Test)4 PrintWriter (java.io.PrintWriter)2 Function (com.google.common.base.Function)1 JsonWriter (com.google.gson.stream.JsonWriter)1 HiveConf (org.apache.hadoop.hive.conf.HiveConf)1 QueryPlan (org.apache.hadoop.hive.ql.QueryPlan)1 TaskRunner (org.apache.hadoop.hive.ql.exec.TaskRunner)1 Index (org.apache.hadoop.hive.ql.optimizer.lineage.LineageCtx.Index)1 SessionState (org.apache.hadoop.hive.ql.session.SessionState)1 SystemHelper (org.codelibs.fess.helper.SystemHelper)1