Skip to content

Commit 7f26bd5

Browse files
authored
feat: Download snapshots natively (#6)
1 parent b317244 commit 7f26bd5

File tree

2 files changed

+16
-25
lines changed

2 files changed

+16
-25
lines changed

pom.xml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>io.qdrant</groupId>
88
<artifactId>client</artifactId>
9-
<!-- UPDATE THE VERSION IN README.MD TOO-->
9+
<!-- UPDATE THE VERSION IN README.MD-->
1010
<version>1.0</version>
1111

1212
<dependencies>
@@ -40,11 +40,6 @@
4040
<scope>test</scope>
4141
</dependency>
4242

43-
<dependency>
44-
<groupId>org.apache.httpcomponents</groupId>
45-
<artifactId>httpclient</artifactId>
46-
<version>4.5.13</version>
47-
</dependency>
4843
</dependencies>
4944

5045
<build>

src/main/java/io/qdrant/client/QdrantClient.java

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,18 @@
1414
import io.qdrant.client.grpc.SnapshotsService;
1515
import io.qdrant.client.grpc.SnapshotsService.SnapshotDescription;
1616
import io.qdrant.client.utils.PointUtil;
17+
import java.io.FileOutputStream;
1718
import java.io.IOException;
19+
import java.io.InputStream;
20+
import java.net.HttpURLConnection;
1821
import java.net.MalformedURLException;
1922
import java.net.URL;
20-
import java.nio.file.Files;
2123
import java.nio.file.Path;
22-
import java.nio.file.StandardOpenOption;
2324
import java.time.Duration;
2425
import java.util.List;
2526
import java.util.Map;
2627
import java.util.concurrent.TimeUnit;
2728
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;
3429

3530
/** Client for interfacing with the Qdrant service. */
3631
public class QdrantClient implements AutoCloseable {
@@ -1366,22 +1361,23 @@ public void downloadSnapshot(
13661361
collectionName, resolvedSnapshotName);
13671362
}
13681363

1369-
HttpClient httpClient = HttpClients.createDefault();
1370-
HttpGet httpGet = new HttpGet(uri);
1364+
URL url = new URL(uri);
1365+
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
13711366

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+
}
13731376

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);
13781377
System.out.println("Downloaded successfully");
1379-
} else {
1380-
System.err.println("No response body");
13811378
}
13821379
} 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());
13851381
}
13861382
} catch (IOException e) {
13871383
throw new RuntimeException("Error downloading snapshot " + e.getMessage());

0 commit comments

Comments
 (0)