Here you can find the source of getFileContentByte(InputStream inputStream, long offset, int length)
public static byte[] getFileContentByte(InputStream inputStream, long offset, int length) throws Exception
//package com.java2s; //License from project: Open Source License import java.io.InputStream; public class Main { public static byte[] getFileContentByte(InputStream inputStream, long offset, int length) throws Exception { if (offset < 0 || length < 0) { throw new Exception("getFileContent param error"); }/*from w ww. j a va 2 s .co m*/ byte[] fileContent = null; byte[] tempBuf = new byte[length]; inputStream.skip(offset); int readLen = inputStream.read(tempBuf); if (readLen < 0) { fileContent = new byte[0]; return fileContent; } if (readLen < length) { fileContent = new byte[readLen]; System.arraycopy(tempBuf, 0, fileContent, 0, readLen); } else { fileContent = tempBuf; } return fileContent; } }