return newFileCall(request);
}
- public byte[] downloadPartial(String collectionUuid, String filePathName, long offset) throws IOException {
+ public InputStream get(String collectionUuid, String filePathName, long start, Long end) throws IOException {
Request.Builder builder = this.getRequestBuilder();
- if (offset > 0) {
- builder.addHeader("Range", "bytes=" + offset + "-");
+ String rangeValue = "bytes=" + start + "-";
+ if (end != null) {
+ rangeValue += end;
}
+ builder.addHeader("Range", rangeValue);
Request request = builder.url(this.getUrlBuilder(collectionUuid, filePathName).build()).get().build();
- try (Response response = client.newCall(request).execute()) {
- if (!response.isSuccessful()) {
- throw new IOException("Failed to download file: " + response);
- }
- try (ResponseBody body = response.body()) {
- if (body != null) {
- return body.bytes();
- } else {
- throw new IOException("Response body is null for request: " + request);
- }
- }
+ Response response = client.newCall(request).execute();
+ if (!response.isSuccessful()) {
+ response.close();
+ throw new IOException("Failed to download file: " + response);
}
+ ResponseBody body = response.body();
+ if (body == null) {
+ response.close();
+ throw new IOException("Response body is null for request: " + request);
+ }
+ return body.byteStream();
}
public String delete(String collectionUuid, String filePathName) {