从 ImageInputStream 提供 InputStream 的最佳方式

Best way to provide an InputStream from an ImageInputStream

我有一个 ImageInputStream。我正在使用需要 InputStream 来源的第三方 API。我写了一个包装器 class 传递给 API:

class ImageInputStreamWrapper extends InputStream {

    private ImageInputStream imageInputStream;

    public ImageInputStreamWrapper(ImageInputStream is) {
        imageInputStream = is;
    }

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

}

它可以工作,但速度非常慢。有更好的方法吗?

想通了。我需要添加:

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