| 376 | |
| 377 | StreamingResponseBody streamingResponseBody = new StreamingResponseBody() { |
| 378 | @Override |
| 379 | public void writeTo(OutputStream outputStream) throws IOException { |
| 380 | try( InputStream inputStream = Files.newInputStream(filePath); |
| 381 | BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream); |
| 382 | ){ |
| 383 | |
| 384 | bufferedInputStream.skip(skip); |
| 385 | byte[] bytes = new byte[1024]; |
| 386 | long readSum = 0; |
| 387 | int readCount = 0; |
| 388 | while ((readCount = bufferedInputStream.read(bytes)) != -1) { |
| 389 | if (readSum + readCount > contentLength) { |
| 390 | outputStream.write(bytes, 0, (int) (contentLength - readSum)); |
| 391 | } else { |
| 392 | outputStream.write(bytes, 0, readCount); |
| 393 | } |
| 394 | readSum = readSum + readCount; |
| 395 | } |
| 396 | outputStream.flush(); |
| 397 | |
| 398 | } |
| 399 | |
| 400 | } |
| 401 | }; |
| 402 | |
| 403 | String header = request.getHeader("User-Agent").toUpperCase(); |