Example usage for java.io File pathSeparator

List of usage examples for java.io File pathSeparator

Introduction

In this page you can find the example usage for java.io File pathSeparator.

Prototype

String pathSeparator

To view the source code for java.io File pathSeparator.

Click Source Link

Document

The system-dependent path-separator character, represented as a string for convenience.

Usage

From source file:org.geoserver.platform.GeoServerResourceLoader.java

/**
 * Check that required files exist and throw {@link IllegalArgumentException} if they do not.
 * /*w  w w . j  av  a2 s .  c  o m*/
 * @param files either a single file name or a list of file names separated by {@link File#pathSeparator}
 * @param source description of source from which file name(s) obtained
 */
static void requireFile(String files, String source) {
    if (files == null || files.isEmpty()) {
        return;
    } else {
        for (String file : files.split(File.pathSeparator)) {
            if (!(new File(file)).exists()) {
                throw new IllegalArgumentException(
                        "Missing required file: " + file + " From: " + source + ": " + files);
            }
        }
    }
}

From source file:com.igniva.filemanager.activities.MainActivity.java

/**
 * Returns all available SD-Cards in the system (include emulated)
 * <p>//ww  w .  j a  v a  2  s.co  m
 * Warning: Hack! Based on Android source code of version 4.3 (API 18)
 * Because there is no standard way to get it.
 * TODO: Test on future Android versions 4.4+
 *
 * @return paths to all available SD-Cards in the system (include emulated)
 */

public List<String> getStorageDirectories() {
    // Final set of paths
    final ArrayList<String> rv = new ArrayList<>();
    // Primary physical SD-CARD (not emulated)
    final String rawExternalStorage = System.getenv("EXTERNAL_STORAGE");
    // All Secondary SD-CARDs (all exclude primary) separated by ":"
    final String rawSecondaryStoragesStr = System.getenv("SECONDARY_STORAGE");
    // Primary emulated SD-CARD
    final String rawEmulatedStorageTarget = System.getenv("EMULATED_STORAGE_TARGET");
    if (TextUtils.isEmpty(rawEmulatedStorageTarget)) {
        // Device has physical external storage; use plain paths.
        if (TextUtils.isEmpty(rawExternalStorage)) {
            // EXTERNAL_STORAGE undefined; falling back to default.
            rv.add("/storage/sdcard0");
        } else {
            rv.add(rawExternalStorage);
        }
    } else {
        // Device has emulated storage; external storage paths should have
        // userId burned into them.
        final String rawUserId;
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
            rawUserId = "";
        } else {
            final String path = Environment.getExternalStorageDirectory().getAbsolutePath();
            final String[] folders = DIR_SEPARATOR.split(path);
            final String lastFolder = folders[folders.length - 1];
            boolean isDigit = false;
            try {
                Integer.valueOf(lastFolder);
                isDigit = true;
            } catch (NumberFormatException ignored) {
            }
            rawUserId = isDigit ? lastFolder : "";
        }
        // /storage/emulated/0[1,2,...]
        if (TextUtils.isEmpty(rawUserId)) {
            rv.add(rawEmulatedStorageTarget);
        } else {
            rv.add(rawEmulatedStorageTarget + File.separator + rawUserId);
        }
    }
    // Add all secondary storages
    if (!TextUtils.isEmpty(rawSecondaryStoragesStr)) {
        // All Secondary SD-CARDs splited into array
        final String[] rawSecondaryStorages = rawSecondaryStoragesStr.split(File.pathSeparator);
        Collections.addAll(rv, rawSecondaryStorages);
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && checkStoragePermission())
        rv.clear();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        String strings[] = FileUtil.getExtSdCardPathsForActivity(this);
        for (String s : strings) {
            File f = new File(s);
            if (!rv.contains(s) && utils.canListFiles(f))
                rv.add(s);
        }
    }
    if (BaseActivity.rootMode)
        rv.add("/");
    File usb = getUsbDrive();
    if (usb != null && !rv.contains(usb.getPath()))
        rv.add(usb.getPath());
    return rv;
}

From source file:org.codehaus.mojo.exec.ExecMojo.java

private static List<String> getExecutableExtensions() {
    final String pathExt = System.getenv("PATHEXT");
    return pathExt == null ? Arrays.asList(".bat", ".cmd")
            : Arrays.asList(StringUtils.split(pathExt.toLowerCase(), File.pathSeparator));
}

From source file:io.hops.hopsworks.api.zeppelin.server.ZeppelinConfig.java

private boolean createZeppelinConfFiles(String interpreterConf) throws IOException {
    File zeppelin_env_file = new File(confDirPath + ZEPPELIN_ENV_SH);
    File zeppelin_site_xml_file = new File(confDirPath + ZEPPELIN_SITE_XML);
    File interpreter_file = new File(confDirPath + INTERPRETER_JSON);
    String home = settings.getZeppelinDir() + File.separator + Settings.DIR_ROOT + File.separator
            + this.projectName;
    String notebookDir = File.separator + Settings.DIR_ROOT + File.separator + this.projectName;
    String resourceDir = File.separator + Settings.DIR_ROOT + File.separator + this.projectName + File.separator
            + Settings.BaseDataset.RESOURCES.getName();
    boolean createdSh = false;
    boolean createdLog4j = false;
    boolean createdXml = false;

    String log4jPath = settings.getSparkLog4JPath();
    String zeppelinPythonPath = settings.getAnacondaProjectDir(this.projectName) + File.separator + "bin"
            + File.separator + "python";
    if (!zeppelin_env_file.exists()) {

        String ldLibraryPath = "";
        if (System.getenv().containsKey("LD_LIBRARY_PATH")) {
            ldLibraryPath = System.getenv("LD_LIBRARY_PATH");
        }/*from   w  w w . j  av  a2 s .co m*/
        String javaHome = settings.getJavaHome();
        if (System.getenv().containsKey("JAVA_HOME")) {
            javaHome = System.getenv("JAVA_HOME");
        }

        StringBuilder zeppelin_env = ConfigFileGenerator.instantiateFromTemplate(
                ConfigFileGenerator.ZEPPELIN_ENV_TEMPLATE, "spark_dir", settings.getSparkDir(), "hadoop_dir",
                settings.getHadoopSymbolicLinkDir(), "anaconda_env_dir",
                settings.getAnacondaDir() + "/envs/" + this.projectName, "hadoop_username",
                this.projectName + Settings.PROJECT_GENERIC_USER_SUFFIX, "java_home", javaHome, "cuda_dir",
                settings.getCudaDir(), "ld_library_path", ldLibraryPath, "hadoop_classpath",
                HopsUtils.getHadoopClasspathGlob(settings.getHadoopSymbolicLinkDir() + "/bin/hadoop",
                        "classpath", "--glob"),
                "spark_options", "--files " + log4jPath);
        createdSh = ConfigFileGenerator.createConfigFile(zeppelin_env_file, zeppelin_env.toString());
    }

    if (!zeppelin_site_xml_file.exists()) {
        StringBuilder zeppelin_site_xml = ConfigFileGenerator.instantiateFromTemplate(
                ConfigFileGenerator.ZEPPELIN_CONFIG_TEMPLATE, "zeppelin_home", home, "livy_url",
                settings.getLivyUrl(), "livy_master", settings.getLivyYarnMode(), "zeppelin_home_dir", home,
                "zeppelin_notebook_dir", notebookDir, "zeppelin_interpreters",
                settings.getZeppelinInterpreters());
        createdXml = ConfigFileGenerator.createConfigFile(zeppelin_site_xml_file, zeppelin_site_xml.toString());
    }

    //get interpreter string from db
    if (interpreter_file.exists()) {
        interpreter_file.delete();
    }

    //Set Hopsworks properties to be available in Zeppelin
    String logstashID = "-D" + Settings.LOGSTASH_JOB_INFO + "=" + this.projectName.toLowerCase() + ",zeppelin,"
            + "notebook,?";
    String restEndpointProp = " -D" + Settings.HOPSWORKS_REST_ENDPOINT_PROPERTY + "="
            + settings.getRestEndpoint();
    String elasticEndpointProp = " -D" + Settings.HOPSWORKS_ELASTIC_ENDPOINT_PROPERTY + "="
            + settings.getElasticRESTEndpoint();
    String projectIdProp = " -D" + Settings.HOPSWORKS_PROJECTID_PROPERTY + "=" + this.projectId;
    String projectNameProp = " -D" + Settings.HOPSWORKS_PROJECTNAME_PROPERTY + "=" + this.projectName;
    String userProp = " -D" + Settings.HOPSWORKS_PROJECTUSER_PROPERTY + "=" + this.projectName
            + Settings.PROJECT_GENERIC_USER_SUFFIX;
    String jobType = " -D" + Settings.HOPSWORKS_JOBTYPE_PROPERTY + "=" + JobType.SPARK;
    String kafkaBrokers = " -D" + Settings.KAFKA_BROKERADDR_PROPERTY + "=" + settings.getKafkaBrokersStr();

    String extraJavaOptions = " -Dlog4j.configuration=./log4j.properties " + logstashID + restEndpointProp
            + elasticEndpointProp + projectIdProp + projectNameProp + userProp + jobType + kafkaBrokers;
    String hdfsResourceDir = "hdfs://" + resourceDir + File.separator;
    // Comma-separated files to be added as local resources to Spark/Livy interpreter
    String driverExtraClassPath = settings.getHopsLeaderElectionJarPath() + File.pathSeparator
            + settings.getHopsUtilFilename();
    String executorExtraClassPath = settings.getHopsLeaderElectionJarPath() + File.pathSeparator
            + settings.getHopsUtilFilename();

    StringBuilder distFiles = new StringBuilder();
    // When Hops RPC TLS is enabled, Yarn will take care of application certificate
    if (!settings.getHopsRpcTls()) {
        distFiles
                // KeyStore
                .append("hdfs://").append(settings.getHdfsTmpCertDir()).append(File.separator)
                .append(projectName).append(Settings.PROJECT_GENERIC_USER_SUFFIX).append(File.separator)
                .append(projectName).append(Settings.PROJECT_GENERIC_USER_SUFFIX).append("__kstore.jks#")
                .append(Settings.K_CERTIFICATE).append(",")
                // TrustStore
                .append("hdfs://").append(settings.getHdfsTmpCertDir()).append(File.separator)
                .append(projectName).append(Settings.PROJECT_GENERIC_USER_SUFFIX).append(File.separator)
                .append(projectName).append(Settings.PROJECT_GENERIC_USER_SUFFIX).append("__tstore.jks#")
                .append(Settings.T_CERTIFICATE).append(",")
                // Material password
                .append("hdfs://").append(settings.getHdfsTmpCertDir()).append(File.separator)
                .append(projectName).append(Settings.PROJECT_GENERIC_USER_SUFFIX).append(File.separator)
                .append(projectName).append(Settings.PROJECT_GENERIC_USER_SUFFIX).append("__cert.key#")
                .append(Settings.CRYPTO_MATERIAL_PASSWORD).append(",");
    }
    distFiles
            // Glassfish domain truststore
            .append(settings.getGlassfishTrustStoreHdfs()).append("#").append(Settings.DOMAIN_CA_TRUSTSTORE)
            .append(",")
            // Add HopsUtil
            .append(settings.getHopsUtilHdfsPath()).append("#").append(settings.getHopsUtilFilename());

    if (interpreterConf == null) {
        StringBuilder interpreter_json = ConfigFileGenerator.instantiateFromTemplate(
                ConfigFileGenerator.INTERPRETER_TEMPLATE, "projectName", this.projectName, "zeppelin_home_dir",
                home, "hdfs_user", this.projectName + Settings.PROJECT_GENERIC_USER_SUFFIX, "hadoop_home",
                settings.getHadoopSymbolicLinkDir(), "livy_url", settings.getLivyUrl(), "dist_files",
                log4jPath + "," + distFiles.toString(), "extra_spark_java_options", extraJavaOptions,
                "driver_extraClassPath", driverExtraClassPath, "executor_extraClassPath",
                executorExtraClassPath, "spark.sql.warehouse.dir", hdfsResourceDir + "spark-warehouse",
                "spark.yarn.stagingDir", hdfsResourceDir, "livy.spark.sql.warehouse.dir",
                hdfsResourceDir + "spark-warehouse", "livy.spark.yarn.stagingDir", hdfsResourceDir,
                "hadoop_version", settings.getHadoopVersion(), "zeppelin.python_conda_path", zeppelinPythonPath,
                "livy_session_timeout", settings.getLivyZeppelinSessionTimeout(), "spark.yarn.dist.files",
                distFiles.toString(), "hive.server", settings.getHiveServerHostName(false), "hive.db",
                this.projectName);
        interpreterConf = interpreter_json.toString();
    }
    createdXml = ConfigFileGenerator.createConfigFile(interpreter_file, interpreterConf);

    return createdSh || createdXml || createdLog4j;
}

From source file:com.twinsoft.convertigo.engine.localbuild.BuildLocally.java

/***
 * //from  w w w .  j  a v  a 2s .  c  om
 * @param paths
 * @param command
 * @return
 * @throws IOException
 */
private static String getFullPath(String paths, String command) throws IOException {
    for (String path : paths.split(Pattern.quote(File.pathSeparator))) {
        File candidate = new File(path, command);
        if (candidate.exists()) {
            return candidate.getCanonicalPath();
        }
    }
    return null;
}

From source file:net.hasor.maven.ExecMojo.java

private List<String> getExecutablePaths(Map<String, String> enviro) {
    List<String> paths = new ArrayList<String>();
    paths.add("");
    String path = enviro.get("PATH");
    if (path != null) {
        paths.addAll(Arrays.asList(StringUtils.split(path, File.pathSeparator)));
    }//  w  ww.j av a2 s  .c  om
    return paths;
}

From source file:kr.motd.maven.exec.ExecMojo.java

CommandLine getExecutablePath(Map<String, String> enviro, File dir) {
    File execFile = new File(executable);
    String exec = null;//  w ww  . j a v  a  2  s  .  co m
    if (execFile.isFile()) {
        getLog().debug("Toolchains are ignored, 'executable' parameter is set to " + executable);
        exec = execFile.getAbsolutePath();
    }

    if (exec == null) {
        Toolchain tc = getToolchain();

        // if the file doesn't exist & toolchain is null, the exec is probably in the PATH...
        // we should probably also test for isFile and canExecute, but the second one is only
        // available in SDK 6.
        if (tc != null) {
            getLog().info("Toolchain in exec-maven-plugin: " + tc);
            exec = tc.findTool(executable);
        } else {
            if (OS.isFamilyWindows()) {
                String ex = !executable.contains(".") ? executable + ".bat" : executable;
                File f = new File(dir, ex);
                if (f.isFile()) {
                    exec = ex;
                }

                if (exec == null) {
                    // now try to figure the path from PATH, PATHEXT env vars
                    // if bat file, wrap in cmd /c
                    String path = enviro.get("PATH");
                    if (path != null) {
                        String[] elems = StringUtils.split(path, File.pathSeparator);
                        for (String elem : elems) {
                            f = new File(new File(elem), ex);
                            if (f.isFile()) {
                                exec = ex;
                                break;
                            }
                        }
                    }
                }
            }
        }
    }

    if (exec == null) {
        exec = executable;
    }

    CommandLine toRet;
    if (OS.isFamilyWindows() && exec.toLowerCase(Locale.getDefault()).endsWith(".bat")) {
        toRet = new CommandLine("cmd");
        toRet.addArgument("/c");
        toRet.addArgument(exec);
    } else {
        toRet = new CommandLine(exec);
    }

    return toRet;
}

From source file:org.apache.geode.management.internal.cli.commands.GfshCommandJUnitTest.java

@Test
public void testToClasspath() {
    final boolean EXCLUDE_SYSTEM_CLASSPATH = false;
    final boolean INCLUDE_SYSTEM_CLASSPATH = true;
    String[] jarFilePathnames = { "/path/to/user/libs/A.jar", "/path/to/user/libs/B.jar",
            "/path/to/user/libs/C.jar" };
    String[] userClasspaths = { "/path/to/classes:/path/to/libs/1.jar:/path/to/libs/2.jar",
            "/path/to/ext/libs/1.jar:/path/to/ext/classes:/path/to/ext/lib/10.jar" };
    String expectedClasspath = StartMemberUtils.GEODE_JAR_PATHNAME.concat(File.pathSeparator)
            .concat(toClasspath(userClasspaths)).concat(File.pathSeparator)
            .concat(toClasspath(jarFilePathnames));
    assertEquals(expectedClasspath,/*from   w  w  w .  j a v a 2s  .  c om*/
            StartMemberUtils.toClasspath(EXCLUDE_SYSTEM_CLASSPATH, jarFilePathnames, userClasspaths));
    expectedClasspath = StartMemberUtils.GEODE_JAR_PATHNAME.concat(File.pathSeparator)
            .concat(toClasspath(userClasspaths)).concat(File.pathSeparator)
            .concat(System.getProperty("java.class.path")).concat(File.pathSeparator)
            .concat(toClasspath(jarFilePathnames));
    assertEquals(expectedClasspath,
            StartMemberUtils.toClasspath(INCLUDE_SYSTEM_CLASSPATH, jarFilePathnames, userClasspaths));
    expectedClasspath = StartMemberUtils.GEODE_JAR_PATHNAME.concat(File.pathSeparator)
            .concat(System.getProperty("java.class.path"));
    assertEquals(expectedClasspath,
            StartMemberUtils.toClasspath(INCLUDE_SYSTEM_CLASSPATH, null, (String[]) null));
    assertEquals(StartMemberUtils.GEODE_JAR_PATHNAME,
            StartMemberUtils.toClasspath(EXCLUDE_SYSTEM_CLASSPATH, null, (String[]) null));
    assertEquals(StartMemberUtils.GEODE_JAR_PATHNAME,
            StartMemberUtils.toClasspath(EXCLUDE_SYSTEM_CLASSPATH, new String[0], ""));
}

From source file:net.metanotion.sqlc.SQLC.java

public static void main(final String[] args) throws Exception {
    final String outputFolder = args[0];
    final String sqlFileName = args[1];

    Iterable<String> srcPathes = java.util.Collections.emptyList();
    if (args.length > 3) {
        srcPathes = java.util.Arrays.asList(args[3].split(File.pathSeparator));
    }/*from  w  w  w .  ja va2s.co  m*/

    final ClassInfo ir = new ClassInfo();
    final File f = new File(sqlFileName);
    if (f.isDirectory()) {
        treewalk(ir, f, srcPathes);
    } else {
        processFile(ir, sqlFileName, srcPathes);
    }
    for (final SQLClass q : ir.classes) {
        SQLC.compile(outputFolder, q, ir.sm, srcPathes);
    }
    if (ir.implicits.size() > 0) {
        SQLC.generateStructs(outputFolder, ir.sm, ir.implicits, ir.implicitDocs, ir.implicitVisibility,
                srcPathes);
        SQLC.generateExceptions(outputFolder, ir.exceptions, ir.inheritanceMap, ir.implicits, ir.implicitDocs,
                ir.implicitVisibility);
    }
}