Java Properties Load from File loadOSDependentLibrary()

Here you can find the source of loadOSDependentLibrary()

Description

load OS Dependent Library

License

Apache License

Declaration

public static String loadOSDependentLibrary() throws IOException 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
    public static String loadOSDependentLibrary() throws IOException {
        String osFamily = getOsFamily();
        return osFamily + "." + System.getProperty("os.arch");

    }//w ww  .  j  a  va2s .  c  om

    private static String getOsFamily() throws IOException {
        final String osName = System.getProperty("os.name");
        if (osName.toLowerCase().contains("mac")) {
            return "Darwin";
        } else if (osName.toLowerCase().contains("linux")) {
            return getLinuxDistro();
        }
        throw new IllegalStateException("Unsupported operating system " + osName);
    }

    private static String getLinuxDistro() throws IOException {
        BufferedReader reader = null;
        String release = null;
        String distro = getDistroName();
        try {
            Process process = Runtime.getRuntime().exec("lsb_release -r");
            reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
            String line;
            Pattern releasePattern = Pattern.compile("Release:\\s*(\\d+).*");
            Matcher matcher;
            while ((line = reader.readLine()) != null) {
                matcher = releasePattern.matcher(line);
                if (matcher.matches()) {
                    release = matcher.group(1);
                }
            }
        } finally {
            reader.close();
        }
        if (distro == null || release == null) {
            throw new UnsupportedEncodingException(
                    "Linux distro does not support lsb_release, cannot determine version, distro: " + distro
                            + ", release: " + release);
        }

        return distro.trim().replaceAll(" ", "_") + "." + release;
    }

    private static String getDistroName() throws IOException {
        Pattern distroRegex = Pattern.compile("[^(]+\\([^(]+\\([^(]+\\(([A-Za-z\\s]+).*");
        BufferedReader reader = new BufferedReader(new FileReader("/proc/version"));
        String distro;
        try {
            Matcher line = distroRegex.matcher(reader.readLine());
            distro = line.matches() ? line.group(1) : null;
        } finally {
            reader.close();
        }
        return distro;
    }
}

Related

  1. loadManifest(File bundleLocation)
  2. loadMetaConfiguration()
  3. loadMimeTypes(InputStream inputStream)
  4. loadNative(File nativeLibsFolder)
  5. loadNecessaryPackagePrivateProperties(Class aClass, String aFileName)
  6. loadParamFromFile(String fileName, String param, String defValue)
  7. loadParams(String fileName)
  8. loadPriority()
  9. loadProperties(File directory, String propertiesFileName)