GcsPath implements Path, Serializable { @Override public GcsPath subpath(int beginIndex, int endIndex) { checkArgument(beginIndex >= 0); checkArgument(endIndex > beginIndex); Iterator<Path> iterator = iterator(); for (int i = 0; i < beginIndex; ++i) { checkArgument(iterator.hasNext()); iterator.next(); } GcsPath path = null; while (beginIndex < endIndex) { checkArgument(iterator.hasNext()); if (path == null) { path = (GcsPath) iterator.next(); } else { path = path.resolve(iterator.next()); } ++beginIndex; } return path; } GcsPath(@Nullable FileSystem fs, @Nullable String bucket, @Nullable String object); static GcsPath fromUri(URI uri); static GcsPath fromUri(String uri); static GcsPath fromResourceName(String name); static GcsPath fromObject(StorageObject object); static GcsPath fromComponents(@Nullable String bucket, @Nullable String object); String getBucket(); String getObject(); void setFileSystem(FileSystem fs); @Override FileSystem getFileSystem(); @Override boolean isAbsolute(); @Override GcsPath getRoot(); @Override GcsPath getFileName(); @Override GcsPath getParent(); @Override int getNameCount(); @Override GcsPath getName(int count); @Override GcsPath subpath(int beginIndex, int endIndex); @Override boolean startsWith(Path other); @Override boolean startsWith(String prefix); @Override boolean endsWith(Path other); @Override boolean endsWith(String suffix); @Override GcsPath normalize(); @Override GcsPath resolve(Path other); @Override GcsPath resolve(String other); @Override Path resolveSibling(Path other); @Override Path resolveSibling(String other); @Override Path relativize(Path other); @Override GcsPath toAbsolutePath(); @Override GcsPath toRealPath(LinkOption... options); @Override File toFile(); @Override WatchKey register(
      WatchService watcher, WatchEvent.Kind<?>[] events, WatchEvent.Modifier... modifiers); @Override WatchKey register(WatchService watcher, WatchEvent.Kind<?>... events); @Override Iterator<Path> iterator(); @Override int compareTo(Path other); @Override boolean equals(@Nullable Object o); @Override int hashCode(); @Override String toString(); String toResourceName(); @Override URI toUri(); static final String SCHEME; static final Pattern GCS_URI; }
@Test public void testSubpath() { GcsPath a = GcsPath.fromComponents("bucket", "a/b/c/d"); assertThat(a.subpath(0, 1).toString(), Matchers.equalTo("gs: assertThat(a.subpath(0, 2).toString(), Matchers.equalTo("gs: assertThat(a.subpath(0, 3).toString(), Matchers.equalTo("gs: assertThat(a.subpath(0, 4).toString(), Matchers.equalTo("gs: assertThat(a.subpath(1, 2).toString(), Matchers.equalTo("a")); assertThat(a.subpath(2, 3).toString(), Matchers.equalTo("b")); assertThat(a.subpath(2, 4).toString(), Matchers.equalTo("b/c")); assertThat(a.subpath(2, 5).toString(), Matchers.equalTo("b/c/d")); }