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

brooklyn.util.stream.KnownSizeInputStream Maven / Gradle / Ivy

Go to download

Utility classes and methods developed for Brooklyn but not dependendent on Brooklyn or much else

There is a newer version: 0.7.0-M1
Show newest version
package brooklyn.util.stream;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;

/** an input stream, whose size we know */
public class KnownSizeInputStream extends InputStream {

    final long length;
    final InputStream target;
    
    public KnownSizeInputStream(InputStream target, long length) {
        this.target = target;
        this.length = length;
    }
    
    public long length() {
        return length;
    }
    
    public InputStream getTarget() {
        return target;
    }

    public int read() throws IOException {
        return target.read();
    }

    public int hashCode() {
        return target.hashCode();
    }

    public int read(byte[] b) throws IOException {
        return target.read(b);
    }

    public boolean equals(Object obj) {
        return target.equals(obj);
    }

    public int read(byte[] b, int off, int len) throws IOException {
        return target.read(b, off, len);
    }

    public long skip(long n) throws IOException {
        return target.skip(n);
    }

    public int available() throws IOException {
        return target.available();
    }

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

    public void close() throws IOException {
        target.close();
    }

    public void mark(int readlimit) {
        target.mark(readlimit);
    }

    public void reset() throws IOException {
        target.reset();
    }

    public boolean markSupported() {
        return target.markSupported();
    }

    public static KnownSizeInputStream of(String contents) {
        return of(contents.getBytes());
    }

    public static KnownSizeInputStream of(byte[] contents) {
        return new KnownSizeInputStream(new ByteArrayInputStream(contents), contents.length);
    }
    
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy