Skip to content

IlyaLisov/storage

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Storage

Lines-of-Code Hits-of-Code mvn

codecov

This repository is an open-source Java library for fast and convenient storing and accessing data in your Java applications.

Currently, we support MinIO and Firebase.

Content:

How to use

At first, you need to install this library.

With Maven add dependency to your pom.xml.

<dependency>
    <groupId>io.github.ilyalisov</groupId>
    <artifactId>storage</artifactId>
    <version>0.1.0</version>
</dependency>

This library provides simple and convenient usage.

Instantiate a service

You need to create MinIOStorageService object and pass login data for MinIO to the constructor.

public class Main {
    public static void main(String[] args) {
        String host = "http://localhost:9000";
        String rootUser = "rootUser";
        String rootPassword = "rootPassword";
        String bucket = "bucket";

        StorageService storageService = new MinIOStorageServiceImpl(
                host,
                rootUser,
                rootPassword,
                bucket
        );
    }
}

And for Firebase it is a bit different.

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = new ByteArrayInputStream(
                System.getenv("FIREBASE_SECRET").getBytes()
        );
        String bucket = System.getenv("FIREBASE_BUCKET");

        StorageService storageService = new FirebaseStorageServiceImpl(
                inputStream,
                bucket
        );
    }
}

After, you can call available methods and use library.

Save file

To save file just call method save. It will return path to saved file.

public class Main {
    public static void main(String[] args) {
        StorageFile file = new StorageFile(
                "fileName",
                "text/plain",
                new ByteArrayInputStream("...")
        );

        Path path = storageService.save(file);
    }
}

Delete file

You can delete file by its name, name and path, and you can delete entire folder by path.

public class Main {
    public static void main(String[] args) {
        storageService.delete("file.txt");
        storageService.delete("file.txt", Path.of("folder"));
        storageService.delete(Path.of("folder"));
    }
}

Check if file exists

You can check whether file exists or not.

public class Main {
    public static void main(String[] args) {
        boolean file1 = storageService.exists("file.txt");
        boolean file2 = storageService.delete("file.txt", Path.of("folder"));
    }
}

Get file

You can get file from storage by calling corresponding methods.

public class Main {
    public static void main(String[] args) {
        Optional<StorageFile> file = storageService.find("file.txt");
        Optional<StorageFile> file2 = storageService.find("file.txt", Path.of("folder"));
        List<StorageFile> files = storageService.findAll(
                Path.of("folder"),
                new Page(0, 10)
        );
    }
}

How to contribute

See active issues at issues page

About

Storage library for Java applications.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages