summaryrefslogtreecommitdiff
path: root/src/main/java/com/keuin/kbackupfabric/util/cow/FileCowCopier.java
blob: e52a89332f1f4c7badd9fd28445a586b5b4dd9e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package com.keuin.kbackupfabric.util.cow;

import com.keuin.kbackupfabric.util.PrintUtil;

import java.io.IOException;
import java.util.concurrent.atomic.AtomicBoolean;

public final class FileCowCopier {
    private static final AtomicBoolean initialized = new AtomicBoolean(false);

    static {
        try {
            System.loadLibrary("kbackup_cow");
        } catch (SecurityException | UnsatisfiedLinkError ignored) {
        }
    }

    public static native void init();

    public static native void copy(String dst, String src) throws IOException;

    public static native String getVersion();

    public static FileCopier getInstance() {
        if (initialized.compareAndSet(false, true)) {
            FileCowCopier.init();
            PrintUtil.info("kbackup-cow version: " + FileCowCopier.getVersion());
        }
        return new FileCopier() {
            @Override
            public void copy(String dst, String src) throws IOException {
                FileCowCopier.copy(dst, src);
            }

            @Override
            public boolean isCow() {
                return true;
            }
        };
    }
}