Is there a concise way to create an InputSupplier for an InputStream in Google Guava?

后端 未结 3 1179
被撕碎了的回忆
被撕碎了的回忆 2021-02-12 22:07

There are a few factory methods in Google Guava to create InputSuppliers, e.g. from a byte[]:

ByteStreams.newInputStreamSupplier(bytes);
         


        
3条回答
  •  执笔经年
    2021-02-12 22:33

    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

    public static long copy(InputStream from, OutputStream to)
    from
    ByteStreams
    see:src

提交回复
热议问题