Skip to content

Commit

Permalink
feat: Download snapshots natively (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
Anush008 authored Dec 9, 2023
1 parent b317244 commit 7f26bd5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 25 deletions.
7 changes: 1 addition & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>io.qdrant</groupId>
<artifactId>client</artifactId>
<!-- UPDATE THE VERSION IN README.MD TOO-->
<!-- UPDATE THE VERSION IN README.MD-->
<version>1.0</version>

<dependencies>
Expand Down Expand Up @@ -40,11 +40,6 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.13</version>
</dependency>
</dependencies>

<build>
Expand Down
34 changes: 15 additions & 19 deletions src/main/java/io/qdrant/client/QdrantClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,18 @@
import io.qdrant.client.grpc.SnapshotsService;
import io.qdrant.client.grpc.SnapshotsService.SnapshotDescription;
import io.qdrant.client.utils.PointUtil;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.time.Duration;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import javax.annotation.Nullable;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

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

HttpClient httpClient = HttpClients.createDefault();
HttpGet httpGet = new HttpGet(uri);
URL url = new URL(uri);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();

HttpResponse response = httpClient.execute(httpGet);
if (connection.getResponseCode() == 200) {
try (InputStream in = connection.getInputStream();
FileOutputStream fileOut = new FileOutputStream(outPath.toFile())) {

byte[] buffer = new byte[8192];
int bytesRead;
while ((bytesRead = in.read(buffer)) != -1) {
fileOut.write(buffer, 0, bytesRead);
}

if (response.getStatusLine().getStatusCode() == 200) {
HttpEntity entity = response.getEntity();
if (entity != null) {
Files.write(outPath, EntityUtils.toByteArray(entity), StandardOpenOption.CREATE_NEW);
System.out.println("Downloaded successfully");
} else {
System.err.println("No response body");
}
} else {
System.err.println(
"Download failed. HTTP Status Code: " + response.getStatusLine().getStatusCode());
System.err.println("Download failed. HTTP Status Code: " + connection.getResponseCode());
}
} catch (IOException e) {
throw new RuntimeException("Error downloading snapshot " + e.getMessage());
Expand Down

0 comments on commit 7f26bd5

Please sign in to comment.