public static byte [ ] getBytes ( InputStream is ) { if ( is == null ) { return null ; } ByteArrayOutputStream buffer = new ByteArrayOutputStream ( ) ; int nRead ; byte [ ] data = new byte [ BUFFER_SIZE ] ; try { while ( ( nRead = is . read ( data , 0 , data . length ) ) != - 1 ) { buffer . write ( data , 0 , nRead ) ; } buffer . flush ( ) ; } catch ( IOException ignored ) { } return buffer . toByteArray ( ) ; }
Load input stream into byte array