There are a few factory methods in Google Guava to create InputSuppliers, e.g. from a byte[]:
ByteStreams.newInputStreamSupplier(bytes);
Or from a File:
Files.newInputStreamSupplier(file);
Is there a similar way to to create an InputSupplier for a given InputStream?
That is, a way that’s more concise than an anonymous class:
new InputSupplier<InputStream>() {
public InputStream getInput() throws IOException {
return inputStream;
}
};
Background: I’d like to use InputStreams with e.g. Files.copy(...) or ByteStreams.equal(...).
No, I haven’t seen anything.
I think you have found the best way.
The only alternative where to store the inputstream in a byte array or a file and create a Supplier with ByteStreams.newInputStreamSupplier() or Files.newInputStreamSupplier(), but I would discourage to do like that.
You could also use
from
see:src