How to convert byte[] to InputStream?

JavaByteInputstream

Java Problem Overview


> 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.

Java Solutions


Solution 1 - Java

ByteArrayInputStream extends InputStream:

InputStream myInputStream = new ByteArrayInputStream(myBytes); 

Solution 2 - Java

Should be easy to find in the javadocs...

byte[] byteArr = new byte[] { 0xC, 0xA, 0xF, 0xE };
InputStream is = new ByteArrayInputStream(byteArr);

Solution 3 - Java

Solution 4 - Java

Check out java.io.ByteArrayInputStream

Solution 5 - Java

Theres the ByteArrayInputStream.

It does exactly this.

Solution 6 - Java

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRenato DinhaniView Question on Stackoverflow
Solution 1 - JavaDiegoView Answer on Stackoverflow
Solution 2 - JavadavidView Answer on Stackoverflow
Solution 3 - JavaJakub ZaverkaView Answer on Stackoverflow
Solution 4 - JavaControlAltDelView Answer on Stackoverflow
Solution 5 - JavaWill HartungView Answer on Stackoverflow
Solution 6 - JavaMatthew FarwellView Answer on Stackoverflow