class SeekableByteArrayOutputStream extends ByteArrayOutputStream implements Seekable {

    long position;

    @Override public void seek(long position, int whence) {
        if (position < 0 || position > count || whence != 0)
            throw new IllegalArgumentException();
        this.position = position;
    }

    @Override public synchronized void write(int b) {
        if (position < count) {
            buf[(int) position] = (byte) b; // position < count <= MAX_INT
        } else {
            super.write(b);
        }
        position++;
    }

    @Override public synchronized void write(byte[] b, int off, int len) {<FILL_FUNCTION_BODY>}
}

        if (position < count) {
            for (int i = 0 ; i < len ; i++) {
                write(b[off + i]); // should be changed for bigegr arrays
            }
        } else {
            super.write(b, off, len);
            position = count;
        }
    
<methods>public void <init>() ,public void <init>(int) ,public void close() throws java.io.IOException,public synchronized void reset() ,public synchronized int size() ,public synchronized byte[] toByteArray() ,public synchronized java.lang.String toString() ,public synchronized java.lang.String toString(java.lang.String) throws java.io.UnsupportedEncodingException,public synchronized java.lang.String toString(java.nio.charset.Charset) ,public synchronized java.lang.String toString(int) ,public synchronized void write(int) ,public synchronized void write(byte[], int, int) ,public void writeBytes(byte[]) ,public synchronized void writeTo(java.io.OutputStream) throws java.io.IOException<variables>protected byte[] buf,protected int count