/** * Transfer java.io.InpuStream to byte array. * @param inStream, input stream of the uploaded file. * @param fileLength, the length of the file. * @return the byte array transferred from java.io.Inputstream. * @throws IOException occurred by the method read(byte[]) of java.io.InputStream. */ private byte[] getFileBuffer(InputStream inStream, long fileLength) throws IOException { byte[] buffer = new byte[256 * 1024]; byte[] fileBuffer = new byte[(int) fileLength]; int count = 0; int length = 0; while((length = inStream.read(buffer)) != -1){ for (int i = 0; i < length; ++i) { fileBuffer[count + i] = buffer[i]; } count += length; } return fileBuffer; }
Java已知InputStream长度,将其转换为byte[]
最新推荐文章于 2023-10-29 15:42:02 发布