List of utility methods to do InputStream to Byte Array Convert
byte[] | getBytes(InputStream inputStream) get Bytes ByteArrayOutputStream byteBuffer = new ByteArrayOutputStream(); int bufferSize = 1024; byte[] buffer = new byte[bufferSize]; int len = 0; while ((len = inputStream.read(buffer)) != -1) { byteBuffer.write(buffer, 0, len); return byteBuffer.toByteArray(); ... |
byte[] | getFileByte(InputStream inputStream) get File Byte InputStream fis = null; ByteArrayOutputStream sb = null; try { fis = inputStream; sb = new ByteArrayOutputStream(); byte[] bytes = new byte[128]; int n = -1; n = fis.read(bytes); ... |
byte[] | readBytes(InputStream s) read fully the contents of s and return a byte array holding the result if (s == null) { throw new IllegalArgumentException("null s"); ByteArrayOutputStream out = new ByteArrayOutputStream(); byte[] b = new byte[1024]; int n = s.read(b); while (n != -1) { out.write(b, 0, n); ... |
String | readFile(InputStream in, String encoding) Reads the given input stream to a string content. try { byte[] b = new byte[in.available()]; in.read(b); return new String(b, encoding); } finally { if (in != null) { in.close(); |
byte[] | readFile(InputStream in, int size) Reads bytes from given input stream with specified length. byte[] b = new byte[size]; try { in.read(b, 0, size); } finally { if (in != null) { in.close(); return b; |
byte[] | stream2byte(InputStream inStream) streambyte ByteArrayOutputStream swapStream = new ByteArrayOutputStream(); byte[] buff = new byte[100]; int rc = 0; while ((rc = inStream.read(buff, 0, 100)) > 0) { swapStream.write(buff, 0, rc); byte[] in2b = swapStream.toByteArray(); return in2b; ... |
byte[] | inStream2byte(InputStream inStream) in Streambyte ByteArrayOutputStream outStream = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int len = 0; while ((len = inStream.read(buffer)) != -1) { outStream.write(buffer, 0, len); inStream.close(); return outStream.toByteArray(); ... |
byte[] | inStream2byte(InputStream inStream) in Streambyte ByteArrayOutputStream outStream = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int len = 0; while ((len = inStream.read(buffer)) != -1) { outStream.write(buffer, 0, len); inStream.close(); return outStream.toByteArray(); ... |
byte[] | InputStram2byteArray(InputStream in) Input Strambyte Array try { ByteArrayOutputStream out = new ByteArrayOutputStream(); if (in != null) { byte[] buffer = new byte[1024]; int length = 0; while ((length = in.read(buffer)) != -1) { out.write(buffer, 0, length); out.close(); in.close(); return out.toByteArray(); } catch (Exception e) { e.printStackTrace(); return null; |
byte[] | getBytes(InputStream is) get Bytes int len; int size = 1024; byte[] buf; if (is instanceof ByteArrayInputStream) { size = is.available(); buf = new byte[size]; len = is.read(buf, 0, size); } else { ... |