<commit_before>package JSyndicateFSJNI;

// this is the Java interface to Syndicate

import JSyndicateFSJNI.struct.JSFSConfig;
import JSyndicateFSJNI.struct.JSFSFileInfo;
import JSyndicateFSJNI.struct.JSFSFillDir;
import JSyndicateFSJNI.struct.JSFSStat;
import JSyndicateFSJNI.struct.JSFSStatvfs;
import JSyndicateFSJNI.struct.JSFSUtimbuf;
import java.io.File;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;


public class JSyndicateFS {

    public static final Log LOG = LogFactory.getLog(JSyndicateFS.class);
    
    public static final String LIBRARY_FILE_NAME = "libjsyndicatefs";
    public static final String LIBRARY_FILE_PATH_KEY = "JSyndicateFS.JSyndicateFSJNI.LibraryPath";
    private static boolean isLibraryLoaded = false;
    private static boolean isSyndicateInitialized = false;
    
    static { loadLibrary(); }
    
    protected static void loadLibrary() {
        // check library is already loaded
        if(isLibraryLoaded) return;
        
        String libraryFilename = System.getProperty(LIBRARY_FILE_PATH_KEY, LIBRARY_FILE_NAME);
        
        if(libraryFilename.equals(LIBRARY_FILE_NAME)) {
            // default case -- find in class path
            LOG.info("JSFS Library Load in ClassPath : " + LIBRARY_FILE_NAME);
            
            try {
                System.loadLibrary(libraryFilename);
                isLibraryLoaded = true;
            } catch(Exception ex) {
                isLibraryLoaded = false;

                LOG.error("Library loading failed : " + ex.toString());
                LOG.debug("Classpath used : " + System.getProperty("java.library.path"));

                throw new UnsatisfiedLinkError("Invalid JSyndicateFSNative Library : " + libraryFilename);
            } catch(UnsatisfiedLinkError ex) {
                isLibraryLoaded = false;

                LOG.error("Library loading failed : " + ex.toString());
                LOG.debug("Classpath used : " + System.getProperty("java.library.path"));

                throw new UnsatisfiedLinkError("Invalid JSyndicateFSNative Library : " + libraryFilename);
            }
        } else {
            // path was given
            if((libraryFilename != null) && (!libraryFilename.isEmpty())) {
                File jsfsDLL = new File(libraryFilename);
                LOG.info("JSFS Library Load : " + jsfsDLL.getAbsolutePath());

                if(jsfsDLL.exists() && jsfsDLL.canRead() && jsfsDLL.isFile()) {
                    try {
                        System.load(jsfsDLL.getAbsolutePath());
                        isLibraryLoaded = true;
                    } catch (Exception ex) {
                        isLibraryLoaded = false;

                        LOG.error("Library loading failed : " + ex.toString());

                        throw new UnsatisfiedLinkError("Invalid JSyndicateFSNative Library : " + libraryFilename);
                    } catch (UnsatisfiedLinkError ex) {
                        isLibraryLoaded = false;

                        LOG.error("Library loading failed : " + ex.toString());

                        throw new UnsatisfiedLinkError("Invalid JSyndicateFSNative Library : " + libraryFilename);
                    }
                } else {
                    isLibraryLoaded = false;

                    LOG.error("Library loading failed (path error) : " + libraryFilename);

                    throw new UnsatisfiedLinkError("Invalid JSyndicateFSNative Library : " + libraryFilename);
                }
            } else {
                isLibraryLoaded = false;
                throw new UnsatisfiedLinkError("Invalid JSyndicateFSNative Library : Empty Path");
            }
        }
    }
    
    protected static void checkLibraryLoaded() {
        if(!isLibraryLoaded) {
            throw new UnsatisfiedLinkError("Invalid JSyndicateFSNative Library");
        }
    }
    
    protected static void checkSyndicateInit() {
        if(!isSyndicateInitialized) {
            throw new IllegalStateException("Syndicate is not initialized");
        }
    }
    
    public static int jsyndicatefs_init(JSFSConfig cfg) {
        checkLibraryLoaded();
        if(isSyndicateInitialized) {
            throw new IllegalStateException("Syndicate is already initialized");<commit_msg>Lazy library loading  Now loads native library on initialization time<commit_after>package JSyndicateFSJNI;

// this is the Java interface to Syndicate

import JSyndicateFSJNI.struct.JSFSConfig;
import JSyndicateFSJNI.struct.JSFSFileInfo;
import JSyndicateFSJNI.struct.JSFSFillDir;
import JSyndicateFSJNI.struct.JSFSStat;
import JSyndicateFSJNI.struct.JSFSStatvfs;
import JSyndicateFSJNI.struct.JSFSUtimbuf;
import java.io.File;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;


public class JSyndicateFS {

    public static final Log LOG = LogFactory.getLog(JSyndicateFS.class);
    
    public static final String LIBRARY_FILE_NAME = "libjsyndicatefs";
    public static final String LIBRARY_FILE_PATH_KEY = "JSyndicateFS.JSyndicateFSJNI.LibraryPath";
    private static boolean isLibraryLoaded = false;
    private static boolean isSyndicateInitialized = false;
    private static String userLibraryPath;
    
    protected static void loadLibrary() {
        // check library is already loaded
        if(isLibraryLoaded) return;
        
        if(userLibraryPath != null && !userLibraryPath.isEmpty()) {
            LOG.info("JSFS Library Load in user given path : " + userLibraryPath);

            File jsfsDLL = new File(userLibraryPath);
            if (jsfsDLL.exists() && jsfsDLL.canRead() && jsfsDLL.isFile()) {
                try {
                    System.load(userLibraryPath);
                    isLibraryLoaded = true;
                } catch (Exception ex) {
                    isLibraryLoaded = false;

                    LOG.error("Library loading failed : " + ex.toString());
                    throw new UnsatisfiedLinkError("Invalid JSyndicateFSNative Library : " + userLibraryPath);
                } catch (UnsatisfiedLinkError ex) {
                    isLibraryLoaded = false;

                    LOG.error("Library loading failed : " + ex.toString());
                    throw new UnsatisfiedLinkError("Invalid JSyndicateFSNative Library : " + userLibraryPath);
                }
            } else {
                isLibraryLoaded = false;
                throw new UnsatisfiedLinkError("Invalid JSyndicateFSNative Library : Empty Path");
            }
        } else {
            String libraryFilename = System.getProperty(LIBRARY_FILE_PATH_KEY, LIBRARY_FILE_NAME);

            if (libraryFilename.equals(LIBRARY_FILE_NAME)) {
                // default case -- find in class path
                LOG.info("JSFS Library Load in ClassPath : " + LIBRARY_FILE_NAME);

                try {
                    System.loadLibrary(libraryFilename);
                    isLibraryLoaded = true;
                } catch (Exception ex) {
                    isLibraryLoaded = false;

                    LOG.error("Library loading failed : " + ex.toString());
                    LOG.debug("Classpath used : " + System.getProperty("java.library.path"));

                    throw new UnsatisfiedLinkError("Invalid JSyndicateFSNative Library : " + libraryFilename);
                } catch (UnsatisfiedLinkError ex) {
                    isLibraryLoaded = false;

                    LOG.error("Library loading failed : " + ex.toString());
                    LOG.debug("Classpath used : " + System.getProperty("java.library.path"));

                    throw new UnsatisfiedLinkError("Invalid JSyndicateFSNative Library : " + libraryFilename);
                }
            } else {
                // path was given
                if ((libraryFilename != null) && (!libraryFilename.isEmpty())) {
                    File jsfsDLL = new File(libraryFilename);
                    LOG.info("JSFS Library Load : " + jsfsDLL.getAbsolutePath());

                    if (jsfsDLL.exists() && jsfsDLL.canRead() && jsfsDLL.isFile()) {
                        try {
                            System.load(jsfsDLL.getAbsolutePath());
                            isLibraryLoaded = true;
                        } catch (Exception ex) {
                            isLibraryLoaded = false;

                            LOG.error("Library loading failed : " + ex.toString());

                            throw new UnsatisfiedLinkError("Invalid JSyndicateFSNative Library : " + libraryFilename);
                        } catch (UnsatisfiedLinkError ex) {
                            isLibraryLoaded = false;

                            LOG.error("Library loading failed : " + ex.toString());

                            throw new UnsatisfiedLinkError("Invalid JSyndicateFSNative Library : " + libraryFilename);
                        }
                    } else {
                        isLibraryLoaded = false;

                        LOG.error("Library loading failed (path error) : " + libraryFilename);

                        throw new UnsatisfiedLinkError("Invalid JSyndicateFSNative Library : " + libraryFilename);
                    }
                } else {
                    isLibraryLoaded = false;
                    throw new UnsatisfiedLinkError("Invalid JSyndicateFSNative Library : Empty Path");
                }
            }
        }
    }
    
    protected static void checkLibraryLoaded() {
        if(!isLibraryLoaded) {
            throw new UnsatisfiedLinkError("Invalid JSyndicateFSNative Library");
        }
    }
    
    protected static void checkSyndicateInit() {
        if(!isSyndicateInitialized) {
            throw new IllegalStateException("Syndicate is not initialized");
        }
    }
    
    public static void setLibraryPath(String path) {
        userLibraryPath = path;
    }
    
    public static int jsyndicatefs_init(JSFSConfig cfg) {
        loadLibrary();
        checkLibraryLoaded();
        if(isSyndicateInitialized) {
            throw new IllegalStateException("Syndicate is already initialized");
{'fraction_non_alphanumeric': 0.08362919132149901, 'fraction_numerical': 0.0, 'mean_word_length': 1.935166425470333, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '935174', 'n_tokens_mistral': 2627, 'n_tokens_neox': 2469, 'n_words': 561}