2024-05-23 07:51:32 +00:00
|
|
|
# frostfs-sdk-java
|
|
|
|
|
|
|
|
Java implementation of FrostFS SDK
|
2024-06-11 14:34:39 +00:00
|
|
|
|
|
|
|
## Prerequisites
|
|
|
|
|
|
|
|
### Get the key for your wallet
|
|
|
|
|
|
|
|
1. Get the address
|
|
|
|
```bash
|
|
|
|
cat <path_to_your_wallet> | jq .accounts[0].address | tr -d '"'
|
|
|
|
```
|
|
|
|
|
|
|
|
2. Get the key
|
|
|
|
```bash
|
|
|
|
neo-go wallet export -w <path_to_your_wallet> -d <address_from_p1>
|
|
|
|
```
|
|
|
|
|
|
|
|
## Example usage
|
|
|
|
|
|
|
|
### Container
|
|
|
|
|
|
|
|
```java
|
|
|
|
import info.FrostFS.sdk.enums.BasicAcl;
|
|
|
|
import info.FrostFS.sdk.jdo.Container;
|
|
|
|
import info.FrostFS.sdk.jdo.netmap.PlacementPolicy;
|
|
|
|
import info.FrostFS.sdk.jdo.netmap.Replica;
|
2024-07-16 12:00:17 +00:00
|
|
|
import info.FrostFS.sdk.services.FrostFSClient;
|
2024-06-11 14:34:39 +00:00
|
|
|
|
|
|
|
public class ContainerExample {
|
|
|
|
|
|
|
|
public void example() {
|
|
|
|
Client client = new Client( < your_key >);
|
|
|
|
GrpcClient grpcClient = new GrpcClient( < your_host >);
|
|
|
|
FrostFSClient frostFSClient = new FrostFSClient(grpcClient, client);
|
|
|
|
|
|
|
|
// Create container
|
|
|
|
var placementPolicy = new PlacementPolicy(true, new Replica[]{new Replica(1)});
|
|
|
|
var containerId = frostFSClient.createContainerAsync(new Container(BasicAcl.PUBLIC_RW, placementPolicy));
|
|
|
|
|
|
|
|
// Get container
|
|
|
|
var container = frostFSClient.getContainerAsync(containerId);
|
|
|
|
|
|
|
|
// List containers
|
|
|
|
var containerIds = frostFSClient.listContainersAsync();
|
|
|
|
|
|
|
|
// Delete container
|
|
|
|
frostFSClient.deleteContainerAsync(containerId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
### Object
|
|
|
|
|
|
|
|
```java
|
|
|
|
import info.FrostFS.sdk.enums.ObjectType;
|
|
|
|
import info.FrostFS.sdk.jdo.ContainerId;
|
|
|
|
import info.FrostFS.sdk.jdo.ObjectAttribute;
|
|
|
|
import info.FrostFS.sdk.jdo.ObjectFilter;
|
|
|
|
import info.FrostFS.sdk.jdo.ObjectHeader;
|
2024-07-16 12:00:17 +00:00
|
|
|
import info.FrostFS.sdk.services.FrostFSClient;
|
2024-06-11 14:34:39 +00:00
|
|
|
|
|
|
|
import java.io.FileInputStream;
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
public class ObjectExample {
|
|
|
|
|
|
|
|
public void example() {
|
|
|
|
Client client = new Client( < your_key >);
|
|
|
|
GrpcClient grpcClient = new GrpcClient( < your_host >);
|
|
|
|
FrostFSClient frostFSClient = new FrostFSClient(grpcClient, client);
|
|
|
|
|
|
|
|
// Put object
|
|
|
|
info.FrostFS.sdk.jdo.ObjectId objectId;
|
|
|
|
try (FileInputStream fis = new FileInputStream("cat.jpg")) {
|
|
|
|
var cat = new ObjectHeader(
|
|
|
|
containerId, ObjectType.REGULAR, new ObjectAttribute[]{new ObjectAttribute("Filename", "cat.jpg")}
|
|
|
|
);
|
|
|
|
objectId = frostFSClient.putObjectAsync(cat, fis);
|
|
|
|
} catch (IOException e) {
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get object
|
|
|
|
var obj = frostFSClient.getObjectAsync(containerId, objectId);
|
|
|
|
|
|
|
|
// Get object header
|
|
|
|
var objectHeader = frostFSClient.getObjectHeadAsync(containerId, objectId);
|
|
|
|
|
|
|
|
// Search regular objects
|
|
|
|
var objectIds = frostFSClient.searchObjectsAsync(containerId, ObjectFilter.RootFilter());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|