On my java server I get from an iOS client an InputStream, which looks like this:

```
--0xKhTmLbOuNdArY
Content-Disposition: form-data; filename="Image001"
Content-Type: image/png

âPNG
IHDR���@���@���™iqﬁ���gAMA��Ø»7äÈ���tEXtSoftware�Adobe ImageReadyq…e<��IDATx⁄‰;iê]Uôﬂπ˜Ω◊Ø;ΩB::õY
ê6LÄ“Õ¿
... etc. ...
≠Yy<‘_˜øüYmc˚æØ…ægﬂóÏK$å±çe0ˆΩleIë¢êH¢Tñê–Üd
≠≤§àä6D¸>˙÷˜˚<øÁ˘˝˜˚º^sÁ=Áû{ÓπÁ‹œπ˜úÄÎ:!44¡@
--0xKhTmLbOuNdArY--

```

The first and last line are my HTTP Boundary. In line 2 and 3 are Information about the image file. And from line 5 until the penultimate line there is the image file which I need as a byte array.

**So how do I get the image information as a String and the image file as a byte array from the InputStream?**
The solution should be fast and efficient (The file size can be several megabytes / < 10 MB ).

*My approach:*

I convert the InputStream to a String, then split it and convert the second String to byte array...

```
String str = org.apache.commons.io.IOUtils.toString( inputStream );
String[] strArray1 = str.split( "\r\n\r\n", 2 );
byte[] bytes = strArray1[1].getBytes();

```

That way is very fast, but the byte array seems to be damaged. I can not create an image file from that byte array... Some characters are incorrectly converted.

Perhaps someone can help?