WIP: Java implementation of FrostFS SDK
Find a file
Ori Bruk 73d5e6d72d [#29] Provide a InputStream for the putObject method
Signed-off-by: Ori Bruk <o.bruk@yadro.com>
2024-11-22 13:14:20 +03:00
.forgejo/workflows [#21] add forgejo maven verify action 2024-10-29 13:18:18 +03:00
client [#29] Provide a InputStream for the putObject method 2024-11-22 13:14:20 +03:00
cryptography [#23] Update proto api 2024-11-05 11:39:57 +03:00
exceptions [#14] add lombok and refactor exceptions. Provide validator. 2024-09-17 17:47:03 +03:00
models [#27] Add more modules to CheckStyle 2024-11-13 17:17:29 +03:00
protos [#23] Update proto api 2024-11-05 11:39:57 +03:00
.gitignore [#1] Define SDK structure, add operations with container and object 2024-07-24 15:49:11 +03:00
checkstyle.xml [#27] Add more modules to CheckStyle 2024-11-13 17:17:29 +03:00
CONTRIBUTING.md [#1] Define SDK structure, add operations with container and object 2024-07-24 15:49:11 +03:00
LICENSE Initial commit 2024-05-23 10:51:32 +03:00
pom.xml [#23] Update proto api 2024-11-05 11:39:57 +03:00
README.md [#14] code review fix 2024-09-18 10:33:37 +03:00

frostfs-sdk-java

Java implementation of FrostFS SDK

Prerequisites

Get the key for your wallet

  1. Get the address
cat <path_to_your_wallet> | jq .accounts[0].address | tr -d '"'
  1. Get the key
neo-go wallet export -w <path_to_your_wallet> -d <address_from_p1>

Example usage

Container operations

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(new Replica[]{new Replica(1)}, Boolean.TRUE);
        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 operations

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.dto.object.ObjectId;
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
        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, new ObjectFilter.FilterByRootObject());
    }
}