Bruk Ori
5cd397e35b
Some checks failed
DCO / DCO (pull_request) Failing after 27s
Signed-off-by: Ori Bruk <o.bruk@yadro.com>
96 lines
No EOL
2.8 KiB
Markdown
96 lines
No EOL
2.8 KiB
Markdown
# frostfs-sdk-java
|
|
|
|
Java implementation of FrostFS SDK
|
|
|
|
## 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.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;
|
|
import info.frostfs.sdk.FrostFSClient;
|
|
|
|
public class ContainerExample {
|
|
|
|
public void example() {
|
|
ClientSettings clientSettings = new ClientSettings(<your_key>, <your_host>);
|
|
FrostFSClient frostFSClient = new FrostFSClient(clientSettings);
|
|
|
|
// Create container
|
|
var placementPolicy = new PlacementPolicy(true, new Replica[]{new Replica(1)});
|
|
var containerId = frostFSClient.createContainer(new Container(BasicAcl.PUBLIC_RW, placementPolicy));
|
|
|
|
// Get container
|
|
var container = frostFSClient.getContainer(containerId);
|
|
|
|
// List containers
|
|
var containerIds = frostFSClient.listContainers();
|
|
|
|
// Delete container
|
|
frostFSClient.deleteContainer(containerId);
|
|
}
|
|
}
|
|
```
|
|
|
|
### Object
|
|
|
|
```java
|
|
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;
|
|
import info.frostfs.sdk.FrostFSClient;
|
|
|
|
import java.io.FileInputStream;
|
|
import java.io.IOException;
|
|
|
|
public class ObjectExample {
|
|
|
|
public void example() {
|
|
ClientSettings clientSettings = new ClientSettings(<your_key>, <your_host>);
|
|
FrostFSClient frostFSClient = new FrostFSClient(clientSettings);
|
|
|
|
// Put object
|
|
info.frostfs.sdk.dto.object.ObjectId objectId;
|
|
try (FileInputStream fis = new FileInputStream("cat.jpg")) {
|
|
var cat = new ObjectHeader(
|
|
containerId, ObjectType.REGULAR, new ObjectAttribute[]{new ObjectAttribute("Filename", "cat.jpg")}
|
|
);
|
|
|
|
var params = new PutObjectParameters(cat, fis);
|
|
objectId = frostFSClient.putObject(params);
|
|
} catch (IOException e) {
|
|
throw new RuntimeException(e);
|
|
}
|
|
|
|
// Get object
|
|
var obj = frostFSClient.getObject(containerId, objectId);
|
|
|
|
// Get object header
|
|
var objectHeader = frostFSClient.getObjectHead(containerId, objectId);
|
|
|
|
// Search regular objects
|
|
var objectIds = frostFSClient.searchObjects(containerId, ObjectFilter.RootFilter());
|
|
}
|
|
}
|
|
``` |