|
14 | 14 | import io.qdrant.client.grpc.SnapshotsService; |
15 | 15 | import io.qdrant.client.grpc.SnapshotsService.SnapshotDescription; |
16 | 16 | import io.qdrant.client.utils.PointUtil; |
| 17 | +import java.io.FileOutputStream; |
17 | 18 | import java.io.IOException; |
| 19 | +import java.io.InputStream; |
| 20 | +import java.net.HttpURLConnection; |
18 | 21 | import java.net.MalformedURLException; |
19 | 22 | import java.net.URL; |
20 | | -import java.nio.file.Files; |
21 | 23 | import java.nio.file.Path; |
22 | | -import java.nio.file.StandardOpenOption; |
23 | 24 | import java.time.Duration; |
24 | 25 | import java.util.List; |
25 | 26 | import java.util.Map; |
26 | 27 | import java.util.concurrent.TimeUnit; |
27 | 28 | import javax.annotation.Nullable; |
28 | | -import org.apache.http.HttpEntity; |
29 | | -import org.apache.http.HttpResponse; |
30 | | -import org.apache.http.client.HttpClient; |
31 | | -import org.apache.http.client.methods.HttpGet; |
32 | | -import org.apache.http.impl.client.HttpClients; |
33 | | -import org.apache.http.util.EntityUtils; |
34 | 29 |
|
35 | 30 | /** Client for interfacing with the Qdrant service. */ |
36 | 31 | public class QdrantClient implements AutoCloseable { |
@@ -1366,22 +1361,23 @@ public void downloadSnapshot( |
1366 | 1361 | collectionName, resolvedSnapshotName); |
1367 | 1362 | } |
1368 | 1363 |
|
1369 | | - HttpClient httpClient = HttpClients.createDefault(); |
1370 | | - HttpGet httpGet = new HttpGet(uri); |
| 1364 | + URL url = new URL(uri); |
| 1365 | + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); |
1371 | 1366 |
|
1372 | | - HttpResponse response = httpClient.execute(httpGet); |
| 1367 | + if (connection.getResponseCode() == 200) { |
| 1368 | + try (InputStream in = connection.getInputStream(); |
| 1369 | + FileOutputStream fileOut = new FileOutputStream(outPath.toFile())) { |
| 1370 | + |
| 1371 | + byte[] buffer = new byte[8192]; |
| 1372 | + int bytesRead; |
| 1373 | + while ((bytesRead = in.read(buffer)) != -1) { |
| 1374 | + fileOut.write(buffer, 0, bytesRead); |
| 1375 | + } |
1373 | 1376 |
|
1374 | | - if (response.getStatusLine().getStatusCode() == 200) { |
1375 | | - HttpEntity entity = response.getEntity(); |
1376 | | - if (entity != null) { |
1377 | | - Files.write(outPath, EntityUtils.toByteArray(entity), StandardOpenOption.CREATE_NEW); |
1378 | 1377 | System.out.println("Downloaded successfully"); |
1379 | | - } else { |
1380 | | - System.err.println("No response body"); |
1381 | 1378 | } |
1382 | 1379 | } else { |
1383 | | - System.err.println( |
1384 | | - "Download failed. HTTP Status Code: " + response.getStatusLine().getStatusCode()); |
| 1380 | + System.err.println("Download failed. HTTP Status Code: " + connection.getResponseCode()); |
1385 | 1381 | } |
1386 | 1382 | } catch (IOException e) { |
1387 | 1383 | throw new RuntimeException("Error downloading snapshot " + e.getMessage()); |
|
0 commit comments