Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/sun/nio/fs/AbstractPath.java
38918 views
/*1* Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.nio.fs;2627import java.nio.file.*;28import java.io.File;29import java.io.IOException;30import java.util.Iterator;31import java.util.NoSuchElementException;3233/**34* Base implementation class of {@code Path}.35*/3637abstract class AbstractPath implements Path {38protected AbstractPath() { }3940@Override41public final boolean startsWith(String other) {42return startsWith(getFileSystem().getPath(other));43}4445@Override46public final boolean endsWith(String other) {47return endsWith(getFileSystem().getPath(other));48}4950@Override51public final Path resolve(String other) {52return resolve(getFileSystem().getPath(other));53}5455@Override56public final Path resolveSibling(Path other) {57if (other == null)58throw new NullPointerException();59Path parent = getParent();60return (parent == null) ? other : parent.resolve(other);61}6263@Override64public final Path resolveSibling(String other) {65return resolveSibling(getFileSystem().getPath(other));66}6768@Override69public final Iterator<Path> iterator() {70return new Iterator<Path>() {71private int i = 0;72@Override73public boolean hasNext() {74return (i < getNameCount());75}76@Override77public Path next() {78if (i < getNameCount()) {79Path result = getName(i);80i++;81return result;82} else {83throw new NoSuchElementException();84}85}86@Override87public void remove() {88throw new UnsupportedOperationException();89}90};91}9293@Override94public final File toFile() {95return new File(toString());96}9798@Override99public final WatchKey register(WatchService watcher,100WatchEvent.Kind<?>... events)101throws IOException102{103return register(watcher, events, new WatchEvent.Modifier[0]);104}105}106107108