List of usage examples for java.io File isAbsolute
public boolean isAbsolute()
From source file:io.dstream.tez.utils.ClassPathUtils.java
/** * Will create a JAR file from base dir//from w w w .j a v a2s. c o m * * @param sourceDir * @param jarName * @return */ public static File toJar(File sourceDir, String jarName) { if (!sourceDir.isAbsolute()) { throw new IllegalArgumentException("Source must be expressed through absolute path"); } Manifest manifest = new Manifest(); manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0"); File jarFile = new File(jarName); try { JarOutputStream target = new JarOutputStream(new FileOutputStream(jarFile), manifest); add(sourceDir, sourceDir.getAbsolutePath().length(), target); target.close(); } catch (Exception e) { throw new IllegalStateException( "Failed to create JAR file '" + jarName + "' from " + sourceDir.getAbsolutePath(), e); } return jarFile; }
From source file:jeplus.util.RelativeDirUtil.java
/** * Check the path is absolute or not. If it is not, use the specified BaseDir and calculate absolute path * * @param thispath The Path to check/*from w ww . jav a 2 s .c om*/ * @param BaseDir The Base Directory to which a relative path is associated * @return The absolute (canonical where possible) path */ public static String checkAbsolutePath(String thispath, String BaseDir) { String abspath; File path = new File(thispath); if (!path.isAbsolute()) { path = new File(BaseDir + thispath); } try { abspath = path.getCanonicalPath(); } catch (IOException ex) { Logger.getLogger(RelativeDirUtil.class.getName()).log(Level.WARNING, null, ex); abspath = path.getAbsolutePath(); } return abspath; }
From source file:mujava.cli.testnew.java
public static boolean compileSrc(String srcName) { String session_dir_path = muJavaHomePath + "/" + sessionName; com.sun.tools.javac.Main javac = new com.sun.tools.javac.Main(); // check if absolute path or not File file = new File(srcName + ".java"); String src_dir_path = new String(); if (!file.isAbsolute()) { src_dir_path = muJavaHomePath + "/src" + java.io.File.separator + srcName + ".java"; } else {//from w w w . java2s . co m src_dir_path = srcName + ".java"; } String[] args = new String[] { "-d", session_dir_path + "/classes", src_dir_path }; int status = javac.compile(args); if (status != 0) { Util.Error("Can't compile src file, please compile manually."); return false; } else { Util.Print("Source file is compiled successfully."); } return true; }
From source file:at.gv.egiz.pdfas.common.utils.ImageUtils.java
public static File getImageFile(String imageFile, ISettings settings) throws PdfAsException, IOException { File img_file = new File(imageFile); if (!img_file.isAbsolute()) { logger.debug("Image file declaration is relative. Prepending path of resources directory."); logger.debug("Image Location: " + settings.getWorkingDirectory() + File.separator + imageFile); img_file = new File(settings.getWorkingDirectory() + File.separator + imageFile); } else {/*w ww. jav a 2s . c om*/ logger.debug("Image file declaration is absolute. Skipping file relocation."); } if (!img_file.exists()) { logger.debug("Image file \"" + img_file.getCanonicalPath() + "\" doesn't exist."); throw new PdfAsException("error.pdf.stamp.04"); } return img_file; }
From source file:au.org.ala.delta.util.FileUtils.java
/** * Attempts to make a relative path from path to file. If path and file have different roots (like drives under Windows), then * the path cannot be made relative, and in these cases this function will return null. * //from w w w . j a v a 2 s .c o m * @param path the source path * @param file the file/directory that will be made relative to the source path * @return either relative path from path to file, or null indicating that no common ancestor could be found (i.e. path cannot be made relative). * */ public static String makeRelativeTo(String path, File file) { String relativePath; if (file.isAbsolute()) { File dataSetPath = new File(path); File parent = parent(file, dataSetPath); File commonParent = dataSetPath; String prefix = ""; while (!parent.equals(commonParent) && commonParent != null) { prefix += ".." + File.separatorChar; commonParent = commonParent.getParentFile(); parent = parent(file, commonParent); } if (commonParent == null) { // No common parent, cannot make relative return null; } String filePath = file.getAbsolutePath(); String parentPath = parent.getAbsolutePath(); int relativePathIndex = filePath.indexOf(parentPath) + parentPath.length(); if (!parentPath.endsWith(File.separator)) { relativePathIndex++; } if (relativePathIndex > filePath.length()) { relativePathIndex = filePath.length(); } relativePath = prefix + filePath.substring(relativePathIndex); if (StringUtils.isEmpty(relativePath)) { relativePath = "."; } } else { relativePath = file.getPath(); } return relativePath; }
From source file:org.apache.solr.core.ConfigSolrXml.java
static Properties getCoreProperties(String instanceDir, CoreDescriptor dcore) { String file = dcore.getPropertiesName(); if (file == null) file = "conf" + File.separator + "solrcore.properties"; File corePropsFile = new File(file); if (!corePropsFile.isAbsolute()) { corePropsFile = new File(instanceDir, file); }// ww w . j a v a2 s.co m Properties p = dcore.getCoreProperties(); if (corePropsFile.exists() && corePropsFile.isFile()) { p = new Properties(dcore.getCoreProperties()); InputStream is = null; try { is = new FileInputStream(corePropsFile); p.load(is); } catch (IOException e) { log.warn("Error loading properties ", e); } finally { IOUtils.closeQuietly(is); } } return p; }
From source file:org.apache.flex.utils.FileUtils.java
/** * returns whether the file is absolute//from w w w . j a va 2 s. com * if a security exception is thrown, always returns false */ public static boolean isAbsolute(File f) { boolean absolute = false; try { absolute = f.isAbsolute(); } catch (SecurityException se) { if (Trace.pathResolver) { Trace.trace(se.getMessage()); } } return absolute; }
From source file:com.iblsoft.iwxxm.webservice.Main.java
private static void validateFiles(List<String> files) { Configuration configuration = ConfigManager.getConfiguration(); IwxxmValidator iwxxmValidator = new IwxxmValidator(configuration.getValidationCatalogFile(), configuration.getValidationRulesDir(), configuration.getDefaultIwxxmVersion()); for (String filePath : files) { filePath = filePath.replace("//", "/"); File localFile = new File(filePath); DirectoryScanner scanner = new DirectoryScanner(); if (!localFile.isAbsolute()) { scanner.setBasedir("."); }//from w ww . j av a 2 s . co m scanner.setIncludes(new String[] { filePath }); scanner.scan(); String[] expandedFiles = scanner.getIncludedFiles(); if (expandedFiles.length == 0) { System.out.println("No file matches the pattern " + filePath); } for (String file : expandedFiles) { System.out.print("Validating file " + file + " ... "); try { ValidationResult result = iwxxmValidator.validate( FileUtils.readFileToString(new File(file), StandardCharsets.UTF_8.name()), null); if (result.isValid()) { System.out.println("Validation successful"); } else { System.out.println("Validation failed"); for (ValidationError ve : result.getValidationErrors()) { System.out.println(" " + ve); } } } catch (IOException e) { System.out.println(); System.out.println("Error: " + e.getMessage()); System.exit(1); return; } } } }
From source file:org.apache.openaz.pepapi.std.PepUtils.java
public static Properties loadProperties(String propertyFile) { Properties properties = new Properties(); // Try the location as a file first. File file = new File(propertyFile); InputStream in = null;// w w w.ja v a 2 s.c o m if (file.exists() && file.canRead()) { if (!file.isAbsolute()) { file = file.getAbsoluteFile(); } try { in = new FileInputStream(file); } catch (FileNotFoundException e) { logger.error("Error while accessing file: " + propertyFile); throw new IllegalArgumentException(e); } } else { Set<ClassLoader> classLoaders = new HashSet<>(); classLoaders.add(PepUtils.class.getClassLoader()); classLoaders.add(Thread.currentThread().getContextClassLoader()); for (ClassLoader classLoader : classLoaders) { in = classLoader.getResourceAsStream(propertyFile); if (in != null) { break; } } if (in == null) { logger.error("Invalid classpath or file location: " + propertyFile); throw new IllegalArgumentException("Invalid classpath or file location: " + propertyFile); } } try { properties.load(in); } catch (IOException e) { logger.error(e); throw new IllegalArgumentException(e); } finally { if (in != null) { try { in.close(); } catch (IOException e) { logger.debug("Error closing stream", e); } } } return properties; }
From source file:SystemIDResolver.java
/** * Return true if the local path is an absolute path. * * @param systemId The path string// w ww. j a v a 2 s . c om * @return true if the path is absolute */ public static boolean isAbsolutePath(String systemId) { if (systemId == null) return false; final File file = new File(systemId); return file.isAbsolute(); }