List of usage examples for java.io File isAbsolute
public boolean isAbsolute()
From source file:org.geoserver.security.password.URLMasterPasswordProvider.java
static OutputStream output(URL url, File configDir) throws IOException { //check for file url if ("file".equalsIgnoreCase(url.getProtocol())) { File f = DataUtilities.urlToFile(url); if (!f.isAbsolute()) { //make relative to config dir f = new File(configDir, f.getPath()); }//from w w w . j a va2 s. c o m return new FileOutputStream(f); } else { URLConnection cx = url.openConnection(); cx.setDoOutput(true); return cx.getOutputStream(); } }
From source file:com.adobe.acs.commons.dam.audio.impl.AbstractFFMpegAudioProcess.java
private static File resolveWorkingDir(String slingHome, String path) { if (path == null) { path = ""; }/*from ww w . j ava 2 s. c om*/ // ensure proper separator in the path (esp. for systems, which do // not use "slash" as a separator, e.g Windows) path = path.replace('/', File.separatorChar); // create a file instance and check whether this is absolute. If not // create a new absolute file instance with the base dir (sling.home or // working dir of current JVM) and get the absolute path name from that File workingDir = new File(path); if (!workingDir.isAbsolute()) { File baseDir; if (slingHome == null) { /* use jvm working dir */ baseDir = new File("").getAbsoluteFile(); } else { baseDir = new File(slingHome).getAbsoluteFile(); } workingDir = new File(baseDir, path).getAbsoluteFile(); } try { log.info("ffmpeg working directory: {}", workingDir.getCanonicalPath()); } catch (IOException e) { log.info("ffmpeg working directory: {}", workingDir.getAbsolutePath()); } return workingDir; }
From source file:webfx.URLVerifier.java
public static URL verifyURL(String location) throws MalformedURLException { URL url;/*from w w w .j a va 2s .com*/ try { url = new URL(location); } catch (MalformedURLException e) { File f = new File(location.trim()); if (f.isAbsolute() && f.exists()) { url = f.toURI().toURL(); } else { url = new URL("http://" + location); } } return url; }
From source file:it.greenvulcano.util.file.FileManager.java
/** * Delete the file/directory from the local file system.<br> * The filePattern may be a regular expression: in this case, all * the file names matching the pattern will be deleted.<br> * * @param targetPath/*from ww w. j a v a 2 s . c o m*/ * Absolute pathname of the target file/directory. * @param filePattern * A regular expression defining the name of the files to be deleted. Used only if * targetPath identify a directory. * @throws Exception */ public static void rm(String targetPath, String filePattern) throws Exception { File target = new File(targetPath); if (!target.isAbsolute()) { throw new IllegalArgumentException("The pathname of the target file is NOT absolute: " + targetPath); } if (target.isDirectory()) { if ((filePattern == null) || filePattern.equals("")) { logger.debug("Removing directory " + target.getAbsolutePath()); FileUtils.deleteDirectory(target); } else if (filePattern.equals(".*")) { logger.debug("Removing directory " + target.getAbsolutePath() + " content."); FileUtils.cleanDirectory(target); } else { Set<FileProperties> files = ls(targetPath, filePattern); for (FileProperties file : files) { logger.debug("Removing file/directory " + file.getName() + " from directory " + target.getAbsolutePath()); FileUtils.forceDelete(new File(target, file.getName())); } } } else { logger.debug("Removing file " + target.getAbsolutePath()); FileUtils.forceDelete(target); } }
From source file:org.geoserver.gwc.config.GeoserverXMLResourceProvider.java
/** * Helper method that infers the directory that contains or will contain GWC configuration. First we will * check if a specific location was set using properties GEOWEBCACHE_CONFIG_DIR and GEOWEBCACHE_CACHE_DIR, * then we will check if a location was provided and then fallback on the default location. *//* w ww . j a v a 2s . c om*/ private static Resource inferConfigDirectory(ResourceStore resourceStore, String providedConfigDirectory) { // check if a specific location was provided using a context property otherwise use the provided directory String configDirectoryPath = findFirstDefined(GEOWEBCACHE_CONFIG_DIR_PROPERTY, GEOWEBCACHE_CACHE_DIR_PROPERTY).orElse(providedConfigDirectory); // if the configuration directory stills not defined we use the default location if (configDirectoryPath == null) { configDirectoryPath = DEFAULT_CONFIGURATION_DIR_NAME; } // instantiate a resource for the configuration directory File configurationDirectory = new File(configDirectoryPath); if (configurationDirectory.isAbsolute()) { return Resources.fromPath(configurationDirectory.getAbsolutePath()); } // configuration directory path is relative to geoserver data directory return resourceStore.get(configDirectoryPath); }
From source file:Main.java
private static URI makeURIFromFilespec(final String filespec, final String relativePrefix) { // make sure the file is absolute & canonical file url File file = new File(decode(filespec)); // if we have a prefix and the file is not abs then prepend if (relativePrefix != null && !file.isAbsolute()) { file = new File(relativePrefix, filespec); }/* w ww. jav a 2 s . c om*/ return file.toURI(); }
From source file:it.greenvulcano.util.file.FileManager.java
/** * Check if the file actually exists on the local file system. * The filename may be a regular expression. The return value * is a <code>java.util.Set</code> of <code>FileProperties</code> objects, * holding informations about the matching files. * * @param parentDirectory/*from w w w . j a va2 s . com*/ * Absolute pathname of the parent directory of the file to be searched. * @param filePattern * the name of the file. May be a regular expression. * @return a <code>java.util.Set</code> of * <code>FileProperties</code> objects. * @throws IOException */ public static Set<FileProperties> ls(String parentDirectory, String filePattern) throws IOException { File targetDir = new File(parentDirectory); if (!targetDir.isAbsolute()) { throw new IllegalArgumentException( "The pathname of the parent directory is NOT absolute: " + parentDirectory); } if (!targetDir.exists()) { throw new IllegalArgumentException( "Parent directory (" + targetDir.getAbsolutePath() + ") NOT found on local file system."); } if (!targetDir.isDirectory()) { throw new IllegalArgumentException( "Parent directory (" + targetDir.getAbsolutePath() + ") is NOT a directory."); } File[] files = targetDir.listFiles(new RegExFileFilter(filePattern, RegExFileFilter.ALL)); Set<FileProperties> matchingFiles = new HashSet<FileProperties>(files.length); for (File file : files) { matchingFiles.add(new FileProperties(file)); } return matchingFiles; }
From source file:ca.uviccscu.lp.persistence.GamelistStorage.java
public static synchronized int verifyConfig(Object[] vals, boolean edit) { boolean a = ((String) vals[0] != null) && !((String) vals[0]).equals(""); if (!edit) {/* www . j av a 2 s.c o m*/ a = a && (getGame((String) vals[0]) == null); } File fl = new File((String) vals[1]); boolean b = fl.canRead() && fl.isDirectory() && fl.isAbsolute(); fl = new File((String) vals[2]); boolean c = fl.canRead() && fl.isFile() && fl.isAbsolute(); boolean d = true; //boolean d = ((String) vals[3]).([]()/\+{}?*+.^$); boolean e = true; String ss1 = ((String) vals[4]); /* String[] sa1 = ((String) vals[4]).split("\\r?\\n"); for (String s : sa1) { * */ String[] ss1split = ss1.split("\\r?\\n"); for (String sss : ss1split) { if (!sss.equals("")) { if (!ss1.endsWith(".bat")) { e = false; l.trace("File location \"" + ss1 + "\" doesnt end with .bat"); } File f = new File(sss); if (!f.exists()) { e = false; l.trace("File location \"" + ss1 + "\" doesnt exist"); } } } if (a && b && c && d && e) { return -1; } else { if (a != true) { return 0; } else if (b != true) { return 1; } else if (c != true) { return 2; } else if (d != true) { return 3; } else if (e != true) { return 4; } else { return -1; } } }
From source file:Main.java
/** A helper to make a URL from a filespec. */ private static URL makeURLFromFilespec(final String filespec, final String relativePrefix) throws IOException { // make sure the file is absolute & canonical file url File file = new File(decode(filespec)); // if we have a prefix and the file is not abs then prepend if (relativePrefix != null && !file.isAbsolute()) { file = new File(relativePrefix, filespec); }//w ww .j a v a 2 s . co m // make sure it is canonical (no ../ and such) file = file.getCanonicalFile(); return file.toURI().toURL(); }
From source file:org.apache.pig.parser.QueryParserUtils.java
static BufferedReader getImportScriptAsReader(String scriptPath) throws FileNotFoundException { File f = new File(scriptPath); if (f.exists() || f.isAbsolute() || scriptPath.startsWith("./") || scriptPath.startsWith("../")) { return new BufferedReader(new FileReader(f)); }/*from ww w. ja v a 2 s . c o m*/ ScriptState state = ScriptState.get(); if (state != null && state.getPigContext() != null) { String srchPath = state.getPigContext().getProperties().getProperty("pig.import.search.path"); if (srchPath != null) { String[] paths = srchPath.split(","); for (String path : paths) { File f1 = new File(path + File.separator + scriptPath); if (f1.exists()) { return new BufferedReader(new FileReader(f1)); } } } } throw new FileNotFoundException("Can't find the Specified file " + scriptPath); }