List of usage examples for java.io File pathSeparator
String pathSeparator
To view the source code for java.io File pathSeparator.
Click Source Link
From source file:com.holycityaudio.SpinCAD.SpinCADFile.java
private void loadRecentPatchFileList() { Preferences p = Preferences.userNodeForPackage(RecentFileList.class); String listOfFiles = p.get("RecentPatchFileList.fileList", null); if (fc == null) { String savedPath = prefs.get("MRUPatchFolder", ""); File MRUPatchFolder = new File(savedPath); fc = new JFileChooser(MRUPatchFolder); recentPatchFileList = new RecentFileList(fc); if (listOfFiles != null) { String[] files = listOfFiles.split(File.pathSeparator); for (String fileRef : files) { File file = new File(fileRef); if (file.exists()) { recentPatchFileList.listModel.add(file); }/*from www . j a v a2s . c o m*/ } } fc.setAccessory(recentPatchFileList); fc.setFileSelectionMode(JFileChooser.FILES_ONLY); } }
From source file:net.lightbody.bmp.proxy.jetty.http.HttpContext.java
/** Get the file classpath of the context. * This method makes a best effort to return a complete file * classpath for the context.//from www. java 2s .c o m * It is obtained by walking the classloader hierarchy and looking for * URLClassLoaders. The system property java.class.path is also checked for * file elements not already found in the loader hierarchy. * @return Path of files and directories for loading classes. * @exception IllegalStateException HttpContext.initClassLoader * has not been called. */ public String getFileClassPath() throws IllegalStateException { ClassLoader loader = getClassLoader(); if (loader == null) throw new IllegalStateException("Context classloader not initialized"); LinkedList paths = new LinkedList(); LinkedList loaders = new LinkedList(); // Walk the loader hierarchy while (loader != null) { loaders.add(0, loader); loader = loader.getParent(); } // Try to handle java2compliant modes loader = getClassLoader(); if (loader instanceof ContextLoader && !((ContextLoader) loader).isJava2Compliant()) { loaders.remove(loader); loaders.add(0, loader); } for (int i = 0; i < loaders.size(); i++) { loader = (ClassLoader) loaders.get(i); if (log.isDebugEnabled()) log.debug("extract paths from " + loader); if (loader instanceof URLClassLoader) { URL[] urls = ((URLClassLoader) loader).getURLs(); for (int j = 0; urls != null && j < urls.length; j++) { try { Resource path = Resource.newResource(urls[j]); if (log.isTraceEnabled()) log.trace("path " + path); File file = path.getFile(); if (file != null) paths.add(file.getAbsolutePath()); } catch (Exception e) { LogSupport.ignore(log, e); } } } } // Add the system classpath elements from property. String jcp = System.getProperty("java.class.path"); if (jcp != null) { StringTokenizer tok = new StringTokenizer(jcp, File.pathSeparator); while (tok.hasMoreTokens()) { String path = tok.nextToken(); if (!paths.contains(path)) { if (log.isTraceEnabled()) log.trace("PATH=" + path); paths.add(path); } else if (log.isTraceEnabled()) log.trace("done=" + path); } } StringBuffer buf = new StringBuffer(); Iterator iter = paths.iterator(); while (iter.hasNext()) { if (buf.length() > 0) buf.append(File.pathSeparator); buf.append(iter.next().toString()); } if (log.isDebugEnabled()) log.debug("fileClassPath=" + buf); return buf.toString(); }
From source file:org.apache.hadoop.mapreduce.v2.util.MRApps.java
@Public @Unstable// ww w . j av a2 s. com public static void addToEnvironment(Map<String, String> environment, String variable, String value, Configuration conf) { String classPathSeparator = conf.getBoolean(MRConfig.MAPREDUCE_APP_SUBMISSION_CROSS_PLATFORM, MRConfig.DEFAULT_MAPREDUCE_APP_SUBMISSION_CROSS_PLATFORM) ? ApplicationConstants.CLASS_PATH_SEPARATOR : File.pathSeparator; Apps.addToEnvironment(environment, variable, value, classPathSeparator); }
From source file:com.holycityaudio.SpinCAD.SpinCADFile.java
private void saveRecentBankFileList() { StringBuilder sb = new StringBuilder(128); if (recentBankFileList != null) { int k = recentBankFileList.listModel.getSize() - 1; for (int index = 0; index <= k; index++) { File file = recentBankFileList.listModel.getElementAt(k - index); if (sb.length() > 0) { sb.append(File.pathSeparator); }/* w w w . jav a 2 s . c om*/ sb.append(file.getPath()); } Preferences p = Preferences.userNodeForPackage(RecentFileList.class); p.put("RecentBankFileList.fileList", sb.toString()); } }
From source file:com.zigabyte.stock.stratplot.StrategyPlotter.java
/** Loads strategy class and creates instance by calling constructor. @param strategyText contains full class name followed by parameter list for constructor. Constructor parameters may be int, double, boolean, String. Constructor parameters are parsed by splitting on commas and trimming whitespace. <pre>/*from w ww.j a v a 2 s. c o m*/ mypkg.MyStrategy(12, -345.67, true, false, Alpha Strategy) </pre> **/ protected TradingStrategy loadStrategy(String strategyText) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, ExceptionInInitializerError, InstantiationException, InvocationTargetException { Pattern strategyPattern = // matches full.class.Name(args...) Pattern.compile("^([A-Za-z](?:[A-Za-z0-9_.]*))\\s*[(](.*)[)]$"); Matcher matcher = strategyPattern.matcher(strategyText); if (!matcher.matches()) throw new IllegalArgumentException( "Bad Strategy: " + strategyText + "\n" + "Expected: full.class.name(-123.45, 67, true, false)"); final String strategyClassName = matcher.group(1).trim(); String parameters[] = matcher.group(2).split(","); // clean parameters for (int i = 0; i < parameters.length; i++) parameters[i] = parameters[i].trim(); if (parameters.length == 1 && parameters[0].length() == 0) parameters = new String[] {}; // 0 parameters // build classpath String[] classPath = System.getProperty("java.class.path").split(File.pathSeparator); ArrayList<URL> classPathURLs = new ArrayList<URL>(); for (int i = 0; i < classPath.length; i++) { String path = classPath[i]; if (".".equals(path)) path = System.getProperty("user.dir"); path = path.replace(File.separatorChar, '/'); if (!path.endsWith("/") && !path.endsWith(".jar")) path += "/"; try { classPathURLs.add(new File(path).toURL()); } catch (MalformedURLException e) { // bad directory in class path, skip } } final String strategyPackagePrefix = strategyClassName.substring(0, Math.max(0, strategyClassName.lastIndexOf('.') + 1)); ClassLoader loader = new URLClassLoader(classPathURLs.toArray(new URL[] {}), this.getClass().getClassLoader()) { /** Don't search parent for classes with strategyPackagePrefix. Exception: interface TradingStrategy **/ protected Class<?> loadClass(String className, boolean resolve) throws ClassNotFoundException { Class<?> loadedClass = findLoadedClass(className); if (loadedClass != null) return loadedClass; if (!className.startsWith(strategyPackagePrefix) || className.equals(TradingStrategy.class.getName())) { loadedClass = this.getParent().loadClass(className); if (loadedClass != null) return loadedClass; } loadedClass = findClass(className); if (loadedClass != null) { if (resolve) resolveClass(loadedClass); return loadedClass; } else throw new ClassNotFoundException(className); } }; // load class. Throws ClassNotFoundException if not found. Class<?> strategyClass = loader.loadClass(strategyClassName); // Make sure it is a TradingStrategy. if (!TradingStrategy.class.isAssignableFrom(strategyClass)) throw new ClassCastException(strategyClass.getName() + " does not implement TradingStrategy"); // Find constructor compatible with parameters Constructor[] constructors = strategyClass.getConstructors(); findConstructor: for (Constructor constructor : constructors) { Class<?>[] parameterTypes = constructor.getParameterTypes(); if (parameterTypes.length != parameters.length) continue; Object[] values = new Object[parameterTypes.length]; for (int i = 0; i < parameterTypes.length; i++) { if (boolean.class.equals(parameterTypes[i])) { String parameter = parameters[i].toLowerCase(); if ("false".equals(parameter)) values[i] = Boolean.FALSE; else if ("true".equals(parameter)) values[i] = Boolean.TRUE; else continue findConstructor; } else if (int.class.equals(parameterTypes[i])) { try { values[i] = new Integer(parameters[i]); } catch (NumberFormatException e) { continue findConstructor; } } else if (double.class.equals(parameterTypes[i])) { try { values[i] = new Double(parameters[i]); } catch (NumberFormatException e) { continue findConstructor; } } else if (String.class.equals(parameterTypes[i])) { values[i] = parameters[i]; } else continue findConstructor; // unsupported parameter type, skip } // all values matched types, so create instance return (TradingStrategy) constructor.newInstance(values); } throw new NoSuchMethodException(strategyText); }
From source file:org.jsweet.plugin.builder.JSweetBuilder.java
private void createJSweetTranspiler(BuildingContext context) throws CoreException { if (context.USE_WATCH_MODE && context.transpiler != null) { Log.info("stopping tsc watch mode"); context.transpiler.setTscWatchMode(false); Log.info("tsc watch mode stopped"); }//from w ww .j a va 2 s . c om StringBuilder classPath = new StringBuilder(); if (context.project.isNatureEnabled("org.eclipse.jdt.core.javanature")) { IJavaProject javaProject = JavaCore.create(context.project); IClasspathEntry[] classPathEntries = javaProject.getResolvedClasspath(true); for (IClasspathEntry e : classPathEntries) { classPath.append(resolve(context.project, e.getPath()).toString()); classPath.append(File.pathSeparator); } } Log.info("compiling with classpath: " + classPath.toString()); File jsOutputFolder = new File(context.project.getLocation().toFile(), Preferences.getJsOutputFolder(context.project, context.profile)); try { context.transpiler = new JSweetTranspiler( new File(context.project.getLocation().toFile(), JSweetTranspiler.TMP_WORKING_DIR_NAME), new File(context.project.getLocation().toFile(), Preferences.getTsOutputFolder(context.project, context.profile)), jsOutputFolder, new File(context.project.getLocation().toFile(), Preferences.getCandyJsOutputFolder(context.project, context.profile)), classPath.toString()); context.transpiler .setPreserveSourceLineNumbers(Preferences.isJavaDebugMode(context.project, context.profile)); String moduleString = Preferences.getModuleKind(context.project, context.profile); context.transpiler.setModuleKind( StringUtils.isBlank(moduleString) ? ModuleKind.none : ModuleKind.valueOf(moduleString)); String bundleDirectory = Preferences.getBundlesDirectory(context.project, context.profile); if (!StringUtils.isBlank(bundleDirectory)) { File f = new File(bundleDirectory); if (!f.isAbsolute()) { f = new File(context.project.getLocation().toFile(), bundleDirectory); } context.transpiler.setBundlesDirectory(f); } context.transpiler.setBundle(Preferences.getBundle(context.project, context.profile)); context.transpiler .setGenerateDeclarations(Preferences.getDeclaration(context.project, context.profile)); String declarationDirectory = Preferences.getDeclarationDirectory(context.project, context.profile); if (!StringUtils.isBlank(declarationDirectory)) { File f = new File(declarationDirectory); if (!f.isAbsolute()) { f = new File(context.project.getLocation().toFile(), declarationDirectory); } context.transpiler.setDeclarationsOutputDir(f); } // transpiler.setTsDefDirs(new // File(context.project.getLocation().toFile(), // Preferences // .getTsOutputFolder(context.project))); if (context.USE_WATCH_MODE) { context.transpiler.setTscWatchMode(true); } } catch (NoClassDefFoundError error) { new JSweetTranspilationHandler(context).report(JSweetProblem.JAVA_COMPILER_NOT_FOUND, null, JSweetProblem.JAVA_COMPILER_NOT_FOUND.getMessage()); } }
From source file:org.kie.workbench.common.services.backend.compiler.impl.external339.ReusableAFMavenCli.java
protected List<File> parseExtClasspath(AFCliRequest cliRequest) { String extClassPath = cliRequest.getUserProperties().getProperty(EXT_CLASS_PATH); if (extClassPath == null) { extClassPath = cliRequest.getSystemProperties().getProperty(EXT_CLASS_PATH); }//ww w . jav a 2 s .c om List<File> jars = new ArrayList<File>(); if (StringUtils.isNotEmpty(extClassPath)) { for (String jar : StringUtils.split(extClassPath, File.pathSeparator)) { File file = resolveFile(new File(jar), cliRequest.getWorkingDirectory()); reusableSlf4jLogger.debug(" Included " + file); jars.add(file); } } return jars; }
From source file:com.holycityaudio.SpinCAD.SpinCADFile.java
private void loadRecentBankFileList() { Preferences p = Preferences.userNodeForPackage(RecentFileList.class); String listOfFiles = p.get("RecentBankFileList.fileList", null); if (fc == null) { String savedPath = prefs.get("MRUBankFolder", ""); File MRUBankFolder = new File(savedPath); fc = new JFileChooser(MRUBankFolder); recentBankFileList = new RecentFileList(fc); if (listOfFiles != null) { String[] files = listOfFiles.split(File.pathSeparator); for (String fileRef : files) { File file = new File(fileRef); if (file.exists()) { recentBankFileList.listModel.add(file); }//from w ww. ja va2s . c om } } fc.setAccessory(recentBankFileList); fc.setFileSelectionMode(JFileChooser.FILES_ONLY); } }
From source file:com.amaze.carbonfilemanager.activities.MainActivity.java
/** * Returns all available SD-Cards in the system (include emulated) * <p>/* w w w.jav a 2 s. c om*/ * 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 synchronized ArrayList<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 (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 (SDK_INT >= Build.VERSION_CODES.M && checkStoragePermission()) rv.clear(); if (SDK_INT >= Build.VERSION_CODES.KITKAT) { String strings[] = FileUtil.getExtSdCardPathsForActivity(this); for (String s : strings) { File f = new File(s); if (!rv.contains(s) && Futils.canListFiles(f)) rv.add(s); } } if (BaseActivity.rootMode) rv.add("/"); File usb = getUsbDrive(); if (usb != null && !rv.contains(usb.getPath())) rv.add(usb.getPath()); if (SDK_INT >= Build.VERSION_CODES.KITKAT) { if (isUsbDeviceConnected()) rv.add(OTGUtil.PREFIX_OTG + "/"); } return rv; }
From source file:org.apache.struts2.jasper.JspC.java
/** * Initializes the classloader as/if needed for the given * compilation context./* w w w .ja v a 2s . co m*/ * * @param clctxt The compilation context * @throws IOException If an error occurs */ private void initClassLoader(JspCompilationContext clctxt) throws IOException { classPath = getClassPath(); ClassLoader jspcLoader = getClass().getClassLoader(); // Turn the classPath into URLs ArrayList urls = new ArrayList(); StringTokenizer tokenizer = new StringTokenizer(classPath, File.pathSeparator); while (tokenizer.hasMoreTokens()) { String path = tokenizer.nextToken(); try { File libFile = new File(path); urls.add(libFile.toURL()); } catch (IOException ioe) { // Failing a toCanonicalPath on a file that // exists() should be a JVM regression test, // therefore we have permission to freak uot throw new RuntimeException(ioe.toString()); } } //TODO: add .tld files to the URLCLassLoader URL urlsA[] = new URL[urls.size()]; urls.toArray(urlsA); loader = new URLClassLoader(urlsA, this.getClass().getClassLoader()); }