All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.n2oapp.framework.mvc.api.CachingPrintWriter Maven / Gradle / Ivy

There is a newer version: 7.28.2
Show newest version
package net.n2oapp.framework.mvc.api;

import java.io.CharArrayWriter;
import java.io.IOException;
import java.io.Writer;

/**
 * @author iryabov
 * @since 17.12.2015
 */
public class CachingPrintWriter extends Writer {
    private final Writer origin;
    private final CharArrayWriter cache = new CharArrayWriter();

    public CachingPrintWriter(Writer origin) {
        this.origin = origin;
    }

    @Override
    public void write(char[] cbuf, int off, int len) throws IOException {
        origin.write(cbuf, off, len);
        cache.write(cbuf, off, len);
    }

    @Override
    public void flush() throws IOException {
        origin.flush();
    }

    @Override
    public void close() throws IOException {
        origin.close();
    }

    public String getCache() {
        return cache.toString();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy