How to convert byte[] to InputStream?

Renato Dinhani picture Renato Dinhani · Mar 27, 2012 · Viewed 132.2k times · Source

Possible Duplicate:
Can we convert a byte array into an InputStream in Java?

There is a way to convert an array of bytes (byte[]) to InputStream in Java? I looked at some methods in Apache Commons IO, but found nothing.

Answer

Diego picture Diego · Mar 27, 2012

ByteArrayInputStream extends InputStream:

InputStream myInputStream = new ByteArrayInputStream(myBytes);