List of usage examples for java.io File isAbsolute
public boolean isAbsolute()
From source file:org.dbgl.test.FilesTest.java
@Test public void testIsAbsolute() { File f1 = new File("c:\\bla.txt"); File f2 = new File("\\bla.txt"); File f3 = new File("c:bla.txt"); File f4 = new File("bla.txt"); assertEquals(f1.isAbsolute(), true); assertEquals(f2.isAbsolute(), false); assertEquals(f3.isAbsolute(), false); assertEquals(f4.isAbsolute(), false); }
From source file:org.gradle.api.internal.file.AbstractBaseDirFileResolver.java
@Override protected File doResolve(Object path) { if (!GUtil.isTrue(path)) { throw new IllegalArgumentException( String.format("path may not be null or empty string. path='%s'", path)); }/* ww w. j a va 2 s. co m*/ File file = convertObjectToFile(path); if (file == null) { throw new IllegalArgumentException(String.format("Cannot convert path to File. path='%s'", path)); } if (!file.isAbsolute()) { File baseDir = getBaseDir(); if (!GUtil.isTrue(baseDir)) { throw new IllegalArgumentException( String.format("baseDir may not be null or empty string. basedir='%s'", baseDir)); } file = new File(baseDir, file.getPath()); } return file; }
From source file:com.oprisnik.simpleconfig.XmlConfig.java
@Override public InputStream getNestedInputStream(String key) throws BadConfigException { File f = null; try {/*from ww w .jav a 2s . co m*/ f = new File(getProperty(key)); if (!f.isAbsolute()) { // relative path -> get correct path f = new File(mFile.getParentFile(), getProperty(key)); } return new FileInputStream(f); } catch (FileNotFoundException e) { throw new BadConfigException("Nested file '" + key + "' not found at '" + f + "'"); } }
From source file:com.funambol.job.config.JobExecutorConfigBean.java
/** * Called by JobExecutorConfiguration to say to the bean the config path. * In this waym the config bean can arrange relative path. * @param configPath the configuration path */// www. j av a 2 s .c om public void fixConfigPath(String configPath) { // // We updated the jgroups configuration files in order to have them // under config dir // if (notificationGroupConfigFileName != null) { File file = new File(notificationGroupConfigFileName); String filePath = file.getPath(); if (!file.isAbsolute()) { File newFile = new File(configPath + File.separator + filePath); notificationGroupConfigFileName = newFile.getPath(); } } }
From source file:com.oprisnik.simpleconfig.XmlConfig.java
@Override public OutputStream getNestedOutputStream(String key) throws BadConfigException { File f = null; try {/*from ww w . j a v a 2 s. co m*/ f = new File(getProperty(key)); if (!f.isAbsolute()) { // relative path -> get correct path f = new File(mFile.getParentFile(), getProperty(key)); } File parent = f.getParentFile(); if (!parent.exists()) { parent.mkdirs(); } return new FileOutputStream(f); } catch (FileNotFoundException e) { throw new BadConfigException("Nested file '" + key + "' not found at '" + f + "'"); } }
From source file:com.boundlessgeo.geoserver.api.controllers.IO.java
private static String source(URL url, GeoServerDataDirectory dataDir) { File baseDirectory = dataDir.getResourceLoader().getBaseDirectory(); if (url.getProtocol().equals("file")) { File file = Files.url(baseDirectory, url.toExternalForm()); if (file != null && !file.isAbsolute()) { return Paths.convert(baseDirectory, file); }/*from w w w. jav a2 s . c o m*/ } return url.toExternalForm(); }
From source file:adalid.util.io.FileBrowser.java
private FileBrowser(String path) { rootFolder = PropertiesHandler.getRootFolder(); if (rootFolder == null) { throw new RuntimeException("root folder is missing or invalid"); }//from w w w.ja va 2 s. c o m rootFolderPath = Paths.get(rootFolder.getPath()); logger.info("root-folder=" + rootFolderPath); if (path == null) { throw new IllegalArgumentException("null folder path"); } else { File file = new File(path); if (file.isAbsolute()) { resourcesFolder = file; } else { resourcesFolder = new File(rootFolder.getAbsolutePath(), path); } } resourcesFolderPath = Paths.get(resourcesFolder.getPath()); logger.info("resources-folder=" + resourcesFolderPath); if (resourcesFolder.isDirectory()) { if (resourcesFolder.isHidden()) { throw new IllegalArgumentException(resourcesFolderPath + " is a hidden directory"); } } else { throw new IllegalArgumentException(resourcesFolderPath + " is not a directory"); } baseFolder = resourcesFolder.getParentFile(); baseFolderPath = Paths.get(baseFolder.getPath()); logger.info("base-folder=" + baseFolderPath); files = new TreeMap<>(); fileTypes = new TreeMap<>(); }
From source file:org.eobjects.analyzer.util.convert.StandardTypeConverter.java
@Override public String toString(Object o) { if (o instanceof Calendar) { // will now be picked up by the date conversion o = ((Calendar) o).getTime(); }/* ww w .jav a 2s . c om*/ final String result; if (o instanceof Boolean || o instanceof Number || o instanceof String || o instanceof Character) { result = o.toString(); } else if (o instanceof File) { File file = (File) o; if (file.isAbsolute()) { result = file.getAbsolutePath().replace('\\', '/'); } else { result = file.getPath().replace('\\', '/'); } } else if (o instanceof Date) { if (o instanceof ExpressionDate) { // preserve the expression if it is an ExpressionDate result = ((ExpressionDate) o).getExpression(); } else { result = new SimpleDateFormat(dateFormatString).format((Date) o); } } else if (o instanceof Pattern) { result = o.toString(); } else if (o instanceof Enum) { return ((Enum<?>) o).name(); } else if (o instanceof Class) { result = ((Class<?>) o).getName(); } else if (o instanceof Serializable) { logger.info("toString(...): No built-in handling of type: {}, using serialization.", o.getClass().getName()); byte[] bytes = SerializationUtils.serialize((Serializable) o); result = parentConverter.toString(bytes); } else { logger.warn("toString(...): Could not convert type: {}", o.getClass().getName()); result = o.toString(); } return result; }
From source file:org.apache.catalina.startup.SetDocBaseRule.java
/** * Handle the beginning of an XML element. * * @param attributes The attributes of this element * * @exception Exception if a processing error occurs *///from ww w. j a v a 2 s . c o m public void begin(Attributes attributes) throws Exception { Context child = (Context) digester.peek(0); Deployer parent = (Deployer) digester.peek(1); Host host = null; if (!(parent instanceof StandardHost)) { Method method = parent.getClass().getMethod("getHost", null); host = (Host) method.invoke(parent, null); } else { host = (Host) parent; } String appBase = host.getAppBase(); boolean unpackWARs = true; if (host instanceof StandardHost) { unpackWARs = ((StandardHost) host).isUnpackWARs(); } if (!unpackWARs && !("true".equals(attributes.getValue("unpackWAR")))) { return; } if ("false".equals(attributes.getValue("unpackWAR"))) { return; } File canonicalAppBase = new File(appBase); if (canonicalAppBase.isAbsolute()) { canonicalAppBase = canonicalAppBase.getCanonicalFile(); } else { canonicalAppBase = new File(System.getProperty("catalina.base"), appBase).getCanonicalFile(); } String docBase = child.getDocBase(); if (docBase == null) { // Trying to guess the docBase according to the path String path = child.getPath(); if (path == null) { return; } if (path.equals("")) { docBase = "ROOT"; } else { if (path.startsWith("/")) { docBase = path.substring(1); } else { docBase = path; } } } File file = new File(docBase); if (!file.isAbsolute()) { docBase = (new File(canonicalAppBase, docBase)).getPath(); } else { docBase = file.getCanonicalPath(); } if (docBase.toLowerCase().endsWith(".war")) { URL war = new URL("jar:" + (new File(docBase)).toURL() + "!/"); String contextPath = child.getPath(); if (contextPath.equals("")) { contextPath = "ROOT"; } docBase = ExpandWar.expand(host, war, contextPath); file = new File(docBase); docBase = file.getCanonicalPath(); } else { File docDir = new File(docBase); if (!docDir.exists()) { File warFile = new File(docBase + ".war"); if (warFile.exists()) { URL war = new URL("jar:" + warFile.toURL() + "!/"); docBase = ExpandWar.expand(host, war, child.getPath()); file = new File(docBase); docBase = file.getCanonicalPath(); } } } if (docBase.startsWith(canonicalAppBase.getPath())) { docBase = docBase.substring(canonicalAppBase.getPath().length()); docBase = docBase.replace(File.separatorChar, '/'); if (docBase.startsWith("/")) { docBase = docBase.substring(1); } } else { docBase = docBase.replace(File.separatorChar, '/'); } child.setDocBase(docBase); }
From source file:com.qspin.qtaste.testsuite.impl.TestDataImpl.java
@Override public String getValue(String key) throws QTasteDataException { if (!hash.containsKey(key)) { if (key.equals("INSTANCE_ID")) { try { return TestBedConfiguration.getInstance().getDefaultInstanceId(); } catch (NoSuchElementException ex) { throw new QTasteDataException("Default instance_id is not defined in TestBed configuration!"); } catch (ConversionException ex) { throw new QTasteDataException("Default instance_id is not valid in TestBed configuration!"); }// w w w . jav a 2 s. c o m } else { throw new QTasteDataException("TestData doesn't contain value for data " + key); } } String value = hash.get(key); if (key.startsWith("FILE_")) { File f = new File(value); if (!f.isAbsolute()) { value = this.getTestCaseDirectory() + File.separator + value; } } return value; }