Here you can find the source of getBytes(int length, InputStream inStream)
Parameter | Description |
---|---|
length | is length of file |
inStream | input stream of input file |
private static byte[] getBytes(int length, InputStream inStream)
//package com.java2s; // Licensed under the Apache License, Version 2.0 (the "License"); import java.io.IOException; import java.io.InputStream; public class Main { /**//from ww w . j a v a 2s .c o m * @param length is length of file * @param inStream input stream of input file * @return array of byte representing a input file */ private static byte[] getBytes(int length, InputStream inStream) { int bytesRead = 0; byte[] content = new byte[length]; while (bytesRead < length) { int result; try { result = inStream.read(content, bytesRead, length - bytesRead); if (result == -1) break; bytesRead += result; } catch (IOException e) { e.printStackTrace(); } } return content; } }