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

org.wings.io.CachingDevice Maven / Gradle / Ivy

The newest version!
// (c) copyright 2006 by eXXcellent solutions, Ulm. Author: bschmid

package org.wings.io;

import java.io.IOException;

/**
 * This device buffers all input in an internal {@link java.lang.StringBuilder}
 * until {@link Device#flush()} or {@link Device#close()}
 * is called.
 */
public class CachingDevice  implements Device {
    private final StringBuilderDevice bufferDevice = new StringBuilderDevice(4096);
    private final Device finalDevice ;

    public CachingDevice(Device finalDevice) {
        this.finalDevice = finalDevice;
    }

    public String toString() {
        return bufferDevice.toString();
    }

    @Override
    public boolean isSizePreserving() {
        return bufferDevice.isSizePreserving();
    }

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

    @Override
    public void close() throws IOException {
        bufferDevice.flush();
        finalDevice.print(bufferDevice.toString());
        bufferDevice.close();
    }

    public void reset() {
        bufferDevice.reset();
    }

    @Override
    public Device print(String s) {
        return bufferDevice.print(s);
    }

    @Override
    public Device print(char c) {
        return bufferDevice.print(c);
    }

    @Override
    public Device print(char... c) throws IOException {
        return bufferDevice.print(c);
    }

    @Override
    public Device print(char[] c, int start, int len) throws IOException {
        return bufferDevice.print(c, start, len);
    }

    @Override
    public Device print(int i) {
        return bufferDevice.print(i);
    }

    @Override
    public Device print(Object o) {
        return bufferDevice.print(o);
    }

    @Override
    public Device write(int c) throws IOException {
        return bufferDevice.write(c);
    }

    @Override
    public Device write(byte... b) throws IOException {
        return bufferDevice.write(b);
    }

    @Override
    public Device write(byte[] b, int off, int len) throws IOException {
        return bufferDevice.write(b, off, len);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy