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
|
2024-07-23 19:24:17 +00:00
|
|
|
import info.frostfs.sdk.dto.container.Container;
|
|
|
|
import info.frostfs.sdk.dto.netmap.PlacementPolicy;
|
|
|
|
import info.frostfs.sdk.dto.netmap.Replica;
|
|
|
|
import info.frostfs.sdk.enums.BasicAcl;
|
|
|
|
import info.frostfs.sdk.jdo.ClientSettings;
|
2024-07-24 11:41:42 +00:00
|
|
|
import info.frostfs.sdk.FrostFSClient;
|
2024-06-11 14:34:39 +00:00
|
|
|
|
|
|
|
public class ContainerExample {
|
|
|
|
|
|
|
|
public void example() {
|
2024-07-23 16:30:07 +00:00
|
|
|
ClientSettings clientSettings = new ClientSettings(<your_key>, <your_host>);
|
|
|
|
FrostFSClient frostFSClient = new FrostFSClient(clientSettings);
|
2024-06-11 14:34:39 +00:00
|
|
|
|
|
|
|
// Create container
|
|
|
|
var placementPolicy = new PlacementPolicy(true, new Replica[]{new Replica(1)});
|
2024-07-22 16:13:52 +00:00
|
|
|
var containerId = frostFSClient.createContainer(new Container(BasicAcl.PUBLIC_RW, placementPolicy));
|
2024-06-11 14:34:39 +00:00
|
|
|
|
|
|
|
// Get container
|
2024-07-22 16:13:52 +00:00
|
|
|
var container = frostFSClient.getContainer(containerId);
|
2024-06-11 14:34:39 +00:00
|
|
|
|
|
|
|
// List containers
|
2024-07-22 16:13:52 +00:00
|
|
|
var containerIds = frostFSClient.listContainers();
|
2024-06-11 14:34:39 +00:00
|
|
|
|
|
|
|
// Delete container
|
2024-07-22 16:13:52 +00:00
|
|
|
frostFSClient.deleteContainer(containerId);
|
2024-06-11 14:34:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
### Object
|
|
|
|
|
|
|
|
```java
|
2024-07-23 19:24:17 +00:00
|
|
|
import info.frostfs.sdk.enums.ObjectType;
|
|
|
|
import info.frostfs.sdk.dto.container.ContainerId;
|
|
|
|
import info.frostfs.sdk.dto.object.ObjectAttribute;
|
|
|
|
import info.frostfs.sdk.dto.object.ObjectFilter;
|
|
|
|
import info.frostfs.sdk.dto.object.ObjectHeader;
|
|
|
|
import info.frostfs.sdk.jdo.PutObjectParameters;
|
2024-07-24 11:41:42 +00:00
|
|
|
import info.frostfs.sdk.FrostFSClient;
|
2024-06-11 14:34:39 +00:00
|
|
|
|
|
|
|
import java.io.FileInputStream;
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
public class ObjectExample {
|
|
|
|
|
|
|
|
public void example() {
|
2024-07-23 16:30:07 +00:00
|
|
|
ClientSettings clientSettings = new ClientSettings(<your_key>, <your_host>);
|
|
|
|
FrostFSClient frostFSClient = new FrostFSClient(clientSettings);
|
2024-06-11 14:34:39 +00:00
|
|
|
|
|
|
|
// Put object
|
2024-07-23 19:24:17 +00:00
|
|
|
info.frostfs.sdk.dto.object.ObjectId objectId;
|
2024-06-11 14:34:39 +00:00
|
|
|
try (FileInputStream fis = new FileInputStream("cat.jpg")) {
|
|
|
|
var cat = new ObjectHeader(
|
|
|
|
containerId, ObjectType.REGULAR, new ObjectAttribute[]{new ObjectAttribute("Filename", "cat.jpg")}
|
|
|
|
);
|
2024-07-23 16:30:07 +00:00
|
|
|
|
|
|
|
var params = new PutObjectParameters(cat, fis);
|
|
|
|
objectId = frostFSClient.putObject(params);
|
2024-06-11 14:34:39 +00:00
|
|
|
} catch (IOException e) {
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get object
|
2024-07-22 16:13:52 +00:00
|
|
|
var obj = frostFSClient.getObject(containerId, objectId);
|
2024-06-11 14:34:39 +00:00
|
|
|
|
|
|
|
// Get object header
|
2024-07-22 16:13:52 +00:00
|
|
|
var objectHeader = frostFSClient.getObjectHead(containerId, objectId);
|
2024-06-11 14:34:39 +00:00
|
|
|
|
|
|
|
// Search regular objects
|
2024-07-22 16:13:52 +00:00
|
|
|
var objectIds = frostFSClient.searchObjects(containerId, ObjectFilter.RootFilter());
|
2024-06-11 14:34:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|