/** * Fetches entire contents of an <code>InputStream</code> and represent same data as result * InputStream. * * <p>This method is useful where, * * <ul> * <li>Source InputStream is slow. * <li>It has network resources associated, so we cannot keep it open for long time. * <li>It has network timeout associated. * </ul> * * It can be used in favor of {@link #toByteArray()}, since it avoids unnecessary allocation and * copy of byte[].<br> * This method buffers the input internally, so there is no need to use a <code> * BufferedInputStream</code>. * * @param input Stream to be fully buffered. * @return A fully buffered stream. * @throws java.io.IOException if an I/O error occurs * @since Commons IO 2.0 */ public static InputStream toBufferedInputStream(InputStream input) throws IOException { ByteArrayOutputStream output = new ByteArrayOutputStream(); output.write(input); return output.toBufferedInputStream(); }