ZipPath implements Path { @Override public Path relativize(Path other) { final String otherStr = other.toString(); final int beginIndex = otherStr.indexOf(this.str); if (beginIndex == -1) { return null; } else { return new ZipPath(otherStr.substring(this.str.length()+1)); } } ZipPath(String str); @Override int compareTo(Path other); @Override boolean endsWith(Path other); @Override boolean endsWith(String other); @Override boolean equals(Object obj); @Override Path getFileName(); @Override FileSystem getFileSystem(); @Override Path getName(int index); int getNameCount(); @Override Path getParent(); @Override Path getRoot(); @Override int hashCode(); @Override boolean isAbsolute(); @Override Iterator<Path> iterator(); @Override Path normalize(); @Override WatchKey register(WatchService watcher, Kind<?>... events); @Override WatchKey register(WatchService watcher, Kind<?>[] events, Modifier... modifiers); @Override Path relativize(Path other); @Override Path resolve(Path other); @Override Path resolve(String other); @Override Path resolveSibling(Path other); @Override Path resolveSibling(String other); @Override boolean startsWith(Path other); @Override boolean startsWith(String other); @Override Path subpath(int beginIndex, int endIndex); @Override Path toAbsolutePath(); @Override File toFile(); @Override Path toRealPath(LinkOption... options); @Override String toString(); @Override URI toUri(); final static ZipPath ROOT; }
@Test public void testRelativize() { ZipPath path1 = new ZipPath("/first/second"); ZipPath path2 = new ZipPath("/first/second/third"); Path path3 = path1.relativize(path2); assertEquals("third", path3.toString()); }