List of usage examples for java.nio.file Path relativize
Path relativize(Path other);
From source file:org.opentestsystem.authoring.testitembank.service.impl.ApipZipOutputFileBuilderService.java
private static final String getRelativePath(final File file, final File parentDir) { final Path filePath = Paths.get(file.getAbsolutePath()); final Path parentDirPath = Paths.get(parentDir.getAbsolutePath()); return parentDirPath.relativize(filePath).toString(); }
From source file:com.sldeditor.ui.detail.config.symboltype.externalgraphic.RelativePath.java
/** * Gets the relative path./* w ww . ja va 2 s . co m*/ * * @param file the file * @param folder the folder * @return the relative path */ public static String getRelativePath(File file, File folder) { if (file == null) { return null; } if (folder == null) { return null; } Path filePath = Paths.get(file.getAbsolutePath()); Path folderPath = Paths.get(folder.getAbsolutePath()); Path path = null; try { path = folderPath.relativize(filePath); } catch (Exception e) { path = filePath; } return path.toString(); }
From source file:snake.server.PathUtils.java
public static ArrayList<PathDescriptor> getRelativePathDescriptors(File folder, boolean useSystemCreationTime) { ArrayList<PathDescriptor> descriptors = new ArrayList<PathDescriptor>(); Iterator<File> filesIter = FileUtils.iterateFiles(folder, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE); while (filesIter.hasNext()) { Path folderPath = folder.toPath(); File file = filesIter.next(); Path filePath = file.toPath().toAbsolutePath(); Path relativePath = folderPath.relativize(filePath); PathDescriptor descriptor = new PathDescriptor(); descriptor.relative_path = FilenameUtils.separatorsToUnix(relativePath.toString()); descriptor.status = PathDescriptor.Status.Modified; descriptor.statusTimePoint = new Date(); descriptor.lastModified = new Date(file.lastModified()); if (useSystemCreationTime) { BasicFileAttributes attributes = null; try { attributes = Files.readAttributes(filePath, BasicFileAttributes.class); descriptor.lastCreationTime = new Date(attributes.creationTime().toMillis()); } catch (Exception e) { descriptor.lastCreationTime = descriptor.statusTimePoint; }//from w ww .ja v a 2 s. c o m } else { descriptor.lastCreationTime = descriptor.statusTimePoint; } descriptors.add(descriptor); } return descriptors; }
From source file:net.algart.simagis.live.json.minimal.SimagisLiveUtils.java
private static String toRef(Path scope, Path path) { return scope.relativize(path).toString().replace('\\', '/'); }
From source file:services.PathService.java
public static Path getRelativePath(Path path) { Path pathAbsolute = path;/*from w ww . j a v a 2s .com*/ Path pathBase = getRootImageDirectory(); Path pathRelative = pathBase.relativize(pathAbsolute); return pathRelative; }
From source file:org.roda_project.commons_ip.utils.Utils.java
public static List<String> getFileRelativeFolders(Path basePath, Path filePath) { List<String> res = new ArrayList<>(); Path relativize = basePath.relativize(filePath).getParent(); if (relativize != null) { Iterator<Path> iterator = relativize.iterator(); while (iterator.hasNext()) { res.add(iterator.next().toString()); }//w ww . jav a2s . c o m } return res; }
From source file:de.sanandrew.mods.turretmod.registry.electrolytegen.ElectrolyteRegistry.java
private static boolean processJson(Path root, Path file) { if (!"json".equals(FilenameUtils.getExtension(file.toString())) || root.relativize(file).toString().startsWith("_")) { return true; }/*from w ww. j ava 2 s .c o m*/ try (BufferedReader reader = Files.newBufferedReader(file)) { JsonObject json = JsonUtils.fromJson(reader, JsonObject.class); if (json == null || json.isJsonNull()) { throw new JsonSyntaxException("Json cannot be null"); } NonNullList<ItemStack> inputItems = JsonUtils.getItemStacks(json.get("electrolytes")); float effectiveness = JsonUtils.getFloatVal(json.get("effectiveness")); int ticksProcessing = JsonUtils.getIntVal(json.get("timeProcessing")); ItemStack trash = ItemStackUtils.getEmpty(); ItemStack treasure = ItemStackUtils.getEmpty(); JsonElement elem = json.get("trash"); if (elem != null && !elem.isJsonNull()) { trash = JsonUtils.getItemStack(elem); } elem = json.get("treasure"); if (elem != null && !elem.isJsonNull()) { treasure = JsonUtils.getItemStack(elem); } registerFuels(inputItems, effectiveness, ticksProcessing, trash, treasure); } catch (JsonParseException e) { TmrConstants.LOG.log(Level.ERROR, String.format("Parsing error loading electrolyte generator recipe from %s", file), e); return false; } catch (IOException e) { TmrConstants.LOG.log(Level.ERROR, String.format("Couldn't read recipe from %s", file), e); return false; } return true; }
From source file:es.uvigo.ei.sing.adops.operations.running.tcoffee.TCoffeeDefaultProcessManager.java
private static String shortenPath(String pathString, File basedir) { final Path path = Paths.get(pathString); final Path pathBasedir = basedir.toPath(); final Path relativePath = pathBasedir.relativize(path); final String relativePathString = relativePath.toString(); return relativePathString.length() < pathString.length() ? relativePathString : pathString; }
From source file:objective.taskboard.utils.ZipUtils.java
public static void zip(Path input, Path output) { try (Stream<Path> stream = walk(input)) { File outputParent = output.toFile().getParentFile(); if (outputParent != null && !outputParent.exists()) createDirectories(outputParent.toPath()); try (ZipOutputStream zipOutputStream = new ZipOutputStream(Files.newOutputStream(output))) { stream.filter(path -> path.toFile().isFile()).forEach(path -> { try { Path inputDirectory = input.toFile().isDirectory() ? input : input.getParent(); ZipEntry entry = new ZipEntry(inputDirectory.relativize(path).toString()); zipOutputStream.putNextEntry(entry); copy(path, zipOutputStream); } catch (IOException e) { throw new UncheckedIOException(e); }//from w w w.ja v a2s.c o m }); } } catch (IOException e) { throw new UncheckedIOException(e); } }
From source file:averroes.JarFile.java
/** * Get the relative path for an absolute file path. * /*from www.j a va 2s .c o m*/ * @param dir * @param file * @return * @throws IOException */ public static String relativize(File base, File absolute) { Path pathAbsolute = java.nio.file.Paths.get(absolute.getPath()).normalize(); Path pathBase = java.nio.file.Paths.get(base.getPath()).normalize(); return pathBase.relativize(pathAbsolute).toString(); }