public File getAbsoluteFile () { if (isAbsolute()) { return this; } if (parent == null) { return new File(ROOT, name); } return new File(parent.getAbsoluteFile(), name); }
private static File resolve(File base, String relative) { File rel = new File(relative); if(rel.isAbsolute()) return rel; else return new File(base.getParentFile(),relative); }
private static final String getAbsolutePath(final File configParent, String file) { File storedir = new File(file); if (!storedir.isAbsolute()) { String newFile = configParent.getAbsolutePath() + File.separator + file; log.debug("Overwrote relative path: was {}, now {}", file, newFile); return newFile; } else { log.debug("Loaded absolute path for key: {}", file); return file; } }
private String makeAbsolute(String possiblyRelativePath) { if (possiblyRelativePath.contains("://") || possiblyRelativePath.startsWith("http:") || possiblyRelativePath.startsWith("https:") || possiblyRelativePath.startsWith("file:")) { return possiblyRelativePath; } if (base == null) { return possiblyRelativePath; } if (new File(possiblyRelativePath).isAbsolute()) { return possiblyRelativePath; } return new File(base.getParentFile(), possiblyRelativePath).getAbsolutePath(); }
private boolean isExistingAbsoluteFile(String name) { File f = new File(name); return f.isAbsolute() && f.exists(); }
public static File applyBaseDirIfRelative(File baseDir, File actualFileToUse) { if (actualFileToUse == null) { return baseDir; } if (actualFileToUse.isAbsolute()) { return actualFileToUse; } if (StringUtils.isBlank(baseDir.getPath())) { return actualFileToUse; } return new File(baseDir, actualFileToUse.getPath()); }
@Override public String alignToBaseDirectory( String path, File basedir ) { String result = path; if ( path != null && basedir != null ) { path = path.replace( '\\', File.separatorChar ).replace( '/', File.separatorChar ); File file = new File( path ); if ( file.isAbsolute() ) { // path was already absolute, just normalize file separator and we're done result = file.getPath(); } else if ( file.getPath().startsWith( File.separator ) ) { // drive-relative Windows path, don't align with project directory but with drive root result = file.getAbsolutePath(); } else { // an ordinary relative path, align with project directory result = new File( new File( basedir, path ).toURI().normalize() ).getAbsolutePath(); } } return result; }
private void forceRemoveDataFile(DataFile dataFile) throws IOException { accessorPool.disposeDataFileAccessors(dataFile); totalLength.addAndGet(-dataFile.getLength()); if (archiveDataLogs) { File directoryArchive = getDirectoryArchive(); if (directoryArchive.exists()) { LOG.debug("Archive directory exists: {}", directoryArchive); } else { if (directoryArchive.isAbsolute()) if (LOG.isDebugEnabled()) { LOG.debug("Archive directory [{}] does not exist - creating it now", directoryArchive.getAbsolutePath()); } IOHelper.mkdirs(directoryArchive); } LOG.debug("Moving data file {} to {} ", dataFile, directoryArchive.getCanonicalPath()); dataFile.move(directoryArchive); LOG.debug("Successfully moved data file"); } else { LOG.debug("Deleting data file: {}", dataFile); if (dataFile.delete()) { LOG.debug("Discarded data file: {}", dataFile); } else { LOG.warn("Failed to discard data file : {}", dataFile.getFile()); } } if (dataFileRemovedListener != null) { dataFileRemovedListener.fileRemoved(dataFile); } }
private static String loadAbsoluteDirectoryPath(String name, String prop, boolean mustExistAndBeAbsolute) { String s = System.getProperty(prop); if (null == s) { s = Joiner.on(File.separator).join(System.getProperty("user.dir"), "target", "cassandra", name, "localhost-bop"); log.info("Set default Cassandra {} directory path {}", name, s); } else { log.info("Loaded Cassandra {} directory path {} from system property {}", new Object[] { name, s, prop }); } if (mustExistAndBeAbsolute) { File dir = new File(s); Preconditions.checkArgument(dir.isDirectory(), "Path %s must be a directory", s); Preconditions.checkArgument(dir.isAbsolute(), "Path %s must be absolute", s); } return s; }
@Override public void transferTo(File dest) throws IOException, IllegalStateException { this.part.write(dest.getPath()); if (dest.isAbsolute() && !dest.exists()) { // Servlet 3.0 Part.write is not guaranteed to support absolute file paths: // may translate the given path to a relative location within a temp dir // (e.g. on Jetty whereas Tomcat and Undertow detect absolute paths). // At least we offloaded the file from memory storage; it'll get deleted // from the temp dir eventually in any case. And for our user's purposes, // we can manually copy it to the requested location as a fallback. FileCopyUtils.copy(this.part.getInputStream(), Files.newOutputStream(dest.toPath())); } }
@Override public FilePredicate is(File ioFile) { if (ioFile.isAbsolute()) { return hasAbsolutePath(ioFile.getAbsolutePath()); } return hasRelativePath(ioFile.getPath()); }
private void doWarnForRelativePath(File file) { if(file.isAbsolute()) return; if(file.getPath().substring(0, 2).equals("."+File.separator)) return; log.warn(file.getPath()+" is relative. Prepend ." +File.separator+" to indicate that you're sure!"); }
public static Path get(java.io.File file) { String[] names = path(file, 0); if (file.isAbsolute()) { return new Absolute(file.isDirectory(), names); } else { return new Relative(file.isDirectory(), names); } }
/** * Utility method to help find the root directory of the store * * @param dir * @return */ public static File findParentDirectory(File dir) { if (dir != null) { String dirPath = dir.getAbsolutePath(); if (!dir.isAbsolute()) { dir = new File(dirPath); } while (dir != null && !dir.isDirectory()) { dir = dir.getParentFile(); } } return dir; } }
static List<File> extractRoots(File root, List<String> includes) { return includes.stream().map(s -> { if (s.startsWith("*")) { return root.getAbsolutePath(); } if (s.contains("*")) { s = s.substring(0, s.indexOf("*")); } File file = new File(s); if (file.isAbsolute()) { return file.getAbsolutePath(); } else { return new File(root, s).getAbsolutePath(); } }).collect(Collectors.toSet()).stream().map(File::new).collect(Collectors.toList()); }
public void addAll(String key, Collection<String> values) { if (values != null) { String root = null; if (key.equals("platform.compiler") || key.equals("platform.sysroot") || key.equals("platform.toolchain") || key.equals("platform.includepath") || key.equals("platform.linkpath")) { root = platformRoot; } List<String> values2 = get(key); for (String value : values) { if (value == null) { continue; } if (root != null && !new File(value).isAbsolute() && new File(root + value).exists()) { value = root + value; } if (!values2.contains(value)) { values2.add(value); } } } }
@CheckForNull private static File initModuleBuildDir(File moduleBaseDir, Map<String, String> moduleProperties) { String buildDir = moduleProperties.get(PROPERTY_PROJECT_BUILDDIR); if (StringUtils.isBlank(buildDir)) { return null; } File customBuildDir = new File(buildDir); if (customBuildDir.isAbsolute()) { return customBuildDir; } return new File(moduleBaseDir, customBuildDir.getPath()); }
public File getAbsoluteFile () { if (isAbsolute()) { return this; } if (parent == null) { return new File(ROOT, name); } return new File(parent.getAbsoluteFile(), name); }
private String extractDockerFilePath(DockerComposeServiceWrapper mapper, File parentDir) { if (mapper.requiresBuild()) { File buildDir = new File(mapper.getBuildDir()); String dockerFile = mapper.getDockerfile(); if (dockerFile == null) { dockerFile = "Dockerfile"; } File ret = new File(buildDir, dockerFile); return ret.isAbsolute() ? ret.getAbsolutePath() : new File(parentDir, ret.getPath()).getAbsolutePath(); } else { return null; } }
/** * Creates a human readable message that describe the provided {@link File} object in terms of * its properties. * * <p>Useful for creating meaningful log messages. * * @param file the {@link File} object to create a descriptive message for * @return a {@link String} containing a descriptive message about the provided {@link File}. */ public static String getFileInfo(final File file) { final StringBuilder builder = new StringBuilder(); builder.append("Checking file:") .append(FilenameUtils.getFullPath(file.getAbsolutePath())) .append("\n"); builder.append("isHidden:").append(file.isHidden()).append("\n"); builder.append("exists:").append(file.exists()).append("\n"); builder.append("isFile").append(file.isFile()).append("\n"); builder.append("canRead:").append(file.canRead()).append("\n"); builder.append("canWrite").append(file.canWrite()).append("\n"); builder.append("canExecute:").append(file.canExecute()).append("\n"); builder.append("isAbsolute:").append(file.isAbsolute()).append("\n"); builder.append("lastModified:").append(file.lastModified()).append("\n"); builder.append("length:").append(file.length()); final String message = builder.toString(); return message; }