Git Product home page Git Product logo

Comments (7)

luben avatar luben commented on August 16, 2024 1

You can make it a little bit shorter as the load method will do nothing if it is already loaded:

    public static boolean zstdAvailable() {
        try {
            Native.load();
            return Native.isLoaded();
        }
        catch (Throwable t) {
            return false;
        }
    }

from zstd-jni.

luben avatar luben commented on August 16, 2024

Yes, looks reasonable... I will look how to make it possible.

from zstd-jni.

DavyLandman avatar DavyLandman commented on August 16, 2024

Thanks!

Perhaps for inspiration (in case you weren't aware) checkout the jpountz/lz4-java bindings that automatically switch between native and java implementation.

from zstd-jni.

luben avatar luben commented on August 16, 2024

Yes, thanks. The loader is actually based on the same code from lz4-java.

from zstd-jni.

luben avatar luben commented on August 16, 2024

BTW, can you try something like this:

InputStream is = null;
try {
  com.github.luben.zstd.util.Native.load();
  is = ZstdInputStream(....);
} catch (Throwable e) {
  is = GzipInputStream(....);
}

I think it should work as the static initialization is not executed if the class is never used. BTW, it's the same mechanism used by the LZ4

from zstd-jni.

DavyLandman avatar DavyLandman commented on August 16, 2024

You are completely right, I was confused on when exactly static blocks are executed.
I now mangled the jar to exclude the binaries for my platform and indeed it works.

    public static boolean zstdAvailable() {
        try {
            if (Native.isLoaded()) {
                return true;
            }
            Native.load();
            return Native.isLoaded();
        }
        catch (Throwable t) {
            return false;
        }
    }

this is the method I constructed, and indeed doesn't fail, as long as it is called before any construction of the zstd classes.

Sorry for the issue, I think you could close it, or perhaps add a boolean method to the Native class that signals it can't be loaded?

from zstd-jni.

DavyLandman avatar DavyLandman commented on August 16, 2024

ah yes, due to the:

        if (loaded) {
            return;
        }

from zstd-jni.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.