diff options
author | jfrijters <jfrijters> | 2011-07-12 09:58:28 +0400 |
---|---|---|
committer | jfrijters <jfrijters> | 2011-07-12 09:58:28 +0400 |
commit | 4d2501e0afa4c4c160d13f4c3b8262fe21718f57 (patch) | |
tree | 7c621813d1b2aae1634b28977e6d955704493b26 /openjdk/sun | |
parent | a97a2b83777343e030b1b474097d1a441e10c3f8 (diff) |
First small steps in java.nio.file implementation. Update sun.util.calendar.ZoneInfoFile to OpenJDK 7, because it can now use our java.nio.file implementation.
Diffstat (limited to 'openjdk/sun')
-rw-r--r-- | openjdk/sun/nio/fs/DefaultFileSystemProvider.java | 2 | ||||
-rw-r--r-- | openjdk/sun/nio/fs/NetFileSystem.java | 121 | ||||
-rw-r--r-- | openjdk/sun/nio/fs/NetFileSystemProvider.java | 125 | ||||
-rw-r--r-- | openjdk/sun/nio/fs/NetPath.java | 239 |
4 files changed, 486 insertions, 1 deletions
diff --git a/openjdk/sun/nio/fs/DefaultFileSystemProvider.java b/openjdk/sun/nio/fs/DefaultFileSystemProvider.java index ad4975a8..6ef8d07d 100644 --- a/openjdk/sun/nio/fs/DefaultFileSystemProvider.java +++ b/openjdk/sun/nio/fs/DefaultFileSystemProvider.java @@ -30,6 +30,6 @@ public class DefaultFileSystemProvider { public static FileSystemProvider create() { - throw new ikvm.internal.NotYetImplementedError(); + return new NetFileSystemProvider(); } } diff --git a/openjdk/sun/nio/fs/NetFileSystem.java b/openjdk/sun/nio/fs/NetFileSystem.java new file mode 100644 index 00000000..1e9946bd --- /dev/null +++ b/openjdk/sun/nio/fs/NetFileSystem.java @@ -0,0 +1,121 @@ +/* + Copyright (C) 2011 Jeroen Frijters + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. + + Jeroen Frijters + jeroen@frijters.net + +*/ + +package sun.nio.fs; + +import ikvm.internal.NotYetImplementedError; +import java.io.IOException; +import java.nio.file.*; +import java.nio.file.attribute.*; +import java.nio.file.spi.FileSystemProvider; +import java.util.Set; + +final class NetFileSystem extends FileSystem +{ + private final NetFileSystemProvider provider; + private final String separator = Character.toString(cli.System.IO.Path.DirectorySeparatorChar); + + NetFileSystem(NetFileSystemProvider provider) + { + this.provider = provider; + } + + public FileSystemProvider provider() + { + return provider; + } + + public void close() throws IOException + { + throw new UnsupportedOperationException(); + } + + public boolean isOpen() + { + return true; + } + + public boolean isReadOnly() + { + return false; + } + + public String getSeparator() + { + return separator; + } + + public Iterable<Path> getRootDirectories() + { + throw new NotYetImplementedError(); + } + + public Iterable<FileStore> getFileStores() + { + throw new NotYetImplementedError(); + } + + public Set<String> supportedFileAttributeViews() + { + throw new NotYetImplementedError(); + } + + public Path getPath(String first, String... more) + { + if (more.length == 0) + { + return new NetPath(this, first); + } + else + { + StringBuilder sb = new StringBuilder(first); + String sep = sb.length() == 0 ? "" : separator; + for (String s : more) + { + if (s.length() != 0) + { + sb.append(sep); + sb.append(s); + sep = separator; + } + } + return new NetPath(this, sb.toString()); + } + } + + public PathMatcher getPathMatcher(String syntaxAndPattern) + { + throw new NotYetImplementedError(); + } + + public UserPrincipalLookupService getUserPrincipalLookupService() + { + throw new NotYetImplementedError(); + } + + public WatchService newWatchService() throws IOException + { + throw new NotYetImplementedError(); + } +} diff --git a/openjdk/sun/nio/fs/NetFileSystemProvider.java b/openjdk/sun/nio/fs/NetFileSystemProvider.java new file mode 100644 index 00000000..ca588f86 --- /dev/null +++ b/openjdk/sun/nio/fs/NetFileSystemProvider.java @@ -0,0 +1,125 @@ +/* + Copyright (C) 2011 Jeroen Frijters + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. + + Jeroen Frijters + jeroen@frijters.net + +*/ + +package sun.nio.fs; + +import ikvm.internal.NotYetImplementedError; +import java.io.IOException; +import java.net.URI; +import java.nio.channels.*; +import java.nio.file.*; +import java.nio.file.attribute.*; +import java.nio.file.spi.FileSystemProvider; +import java.util.Map; +import java.util.Set; + +final class NetFileSystemProvider extends AbstractFileSystemProvider +{ + private final NetFileSystem fs = new NetFileSystem(this); + + public String getScheme() + { + return "file"; + } + + public FileSystem newFileSystem(URI uri, Map<String, ?> env) throws IOException + { + throw new FileSystemAlreadyExistsException(); + } + + public FileSystem getFileSystem(URI uri) + { + return fs; + } + + public Path getPath(URI uri) + { + throw new NotYetImplementedError(); + } + + public SeekableByteChannel newByteChannel(Path path, Set<? extends OpenOption> options, FileAttribute<?>... attrs) throws IOException + { + throw new NotYetImplementedError(); + } + + public DirectoryStream<Path> newDirectoryStream(Path dir, DirectoryStream.Filter<? super Path> filter) throws IOException + { + throw new NotYetImplementedError(); + } + + public void createDirectory(Path dir, FileAttribute<?>... attrs) throws IOException + { + throw new NotYetImplementedError(); + } + + public void copy(Path source, Path target, CopyOption... options) throws IOException + { + throw new NotYetImplementedError(); + } + + public void move(Path source, Path target, CopyOption... options) throws IOException + { + throw new NotYetImplementedError(); + } + + public boolean isSameFile(Path path, Path path2) throws IOException + { + throw new NotYetImplementedError(); + } + + public boolean isHidden(Path path) throws IOException + { + throw new NotYetImplementedError(); + } + + public FileStore getFileStore(Path path) throws IOException + { + throw new NotYetImplementedError(); + } + + public void checkAccess(Path path, AccessMode... modes) throws IOException + { + throw new NotYetImplementedError(); + } + + public <V extends FileAttributeView> V getFileAttributeView(Path path, Class<V> type, LinkOption... options) + { + throw new NotYetImplementedError(); + } + + public <A extends BasicFileAttributes> A readAttributes(Path path, Class<A> type, LinkOption... options) throws IOException + { + throw new NotYetImplementedError(); + } + + DynamicFileAttributeView getFileAttributeView(Path file, String name, LinkOption... options) + { + return null; + } + + boolean implDelete(Path file, boolean failIfNotExists) throws IOException + { + throw new NotYetImplementedError(); + } +} diff --git a/openjdk/sun/nio/fs/NetPath.java b/openjdk/sun/nio/fs/NetPath.java new file mode 100644 index 00000000..30cdbe5b --- /dev/null +++ b/openjdk/sun/nio/fs/NetPath.java @@ -0,0 +1,239 @@ +/* + Copyright (C) 2011 Jeroen Frijters + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. + + Jeroen Frijters + jeroen@frijters.net + +*/ + +package sun.nio.fs; + +import ikvm.internal.NotYetImplementedError; +import java.io.File; +import java.io.IOException; +import java.net.URI; +import java.nio.file.*; +import java.util.Iterator; +import static ikvm.internal.Util.MACOSX; +import static ikvm.internal.Util.WINDOWS; + +final class NetPath extends AbstractPath +{ + private static final char[] invalid = cli.System.IO.Path.GetInvalidFileNameChars(); + private final NetFileSystem fs; + private final String path; + + NetPath(NetFileSystem fs, String path) + { + StringBuilder sb = null; + int separatorCount = 0; + boolean prevWasSeparator = false; + for (int i = 0; i < path.length(); i++) + { + char c = path.charAt(i); + if (c == cli.System.IO.Path.AltDirectorySeparatorChar) + { + if (sb == null) + { + sb = new StringBuilder(); + sb.append(path, 0, i); + } + c = cli.System.IO.Path.DirectorySeparatorChar; + } + if (c == cli.System.IO.Path.DirectorySeparatorChar) + { + if (prevWasSeparator && (i != 1 || c != '\\')) + { + if (sb == null) + { + sb = new StringBuilder(); + sb.append(path, 0, i); + } + continue; + } + separatorCount++; + prevWasSeparator = true; + } + else + { + prevWasSeparator = false; + } + if (sb != null) + { + sb.append(c); + } + if (c == cli.System.IO.Path.DirectorySeparatorChar) + { + continue; + } + else if (c == ':' && i > 0) + { + char d = path.charAt(0); + if (((d >= 'a' && d <= 'z') || (d >= 'A' && d <= 'Z')) && i == 1 && WINDOWS) + { + continue; + } + else if (MACOSX) + { + continue; + } + } + for (char inv : invalid) + { + if (inv == c) + { + throw new InvalidPathException(path, "Illegal char <" + c + ">", i); + } + } + } + if (sb != null) + { + path = sb.toString(); + } + if (path.startsWith("\\\\") && WINDOWS) + { + if (separatorCount == 2 || (separatorCount == 3 && path.endsWith("\\"))) + { + throw new InvalidPathException(path, "UNC path is missing sharename"); + } + else if (separatorCount == 3) + { + path += '\\'; + } + } + else if (path.length() > 0 && path.charAt(path.length() - 1) == cli.System.IO.Path.DirectorySeparatorChar) + { + path = path.substring(0, path.length() - 1); + } + this.fs = fs; + this.path = path; + } + + public FileSystem getFileSystem() + { + return fs; + } + + public boolean isAbsolute() + { + return cli.System.IO.Path.IsPathRooted(path) + && (!WINDOWS || path.startsWith("\\\\") || (path.length() >= 3 && path.charAt(1) == ':' && path.charAt(2) == '\\')); + } + + public Path getRoot() + { + throw new NotYetImplementedError(); + } + + public Path getFileName() + { + throw new NotYetImplementedError(); + } + + public Path getParent() + { + throw new NotYetImplementedError(); + } + + public int getNameCount() + { + throw new NotYetImplementedError(); + } + + public Path getName(int index) + { + throw new NotYetImplementedError(); + } + + public Path subpath(int beginIndex, int endIndex) + { + throw new NotYetImplementedError(); + } + + public boolean startsWith(Path other) + { + throw new NotYetImplementedError(); + } + + public boolean endsWith(Path other) + { + throw new NotYetImplementedError(); + } + + public Path normalize() + { + throw new NotYetImplementedError(); + } + + public Path resolve(Path other) + { + throw new NotYetImplementedError(); + } + + public Path relativize(Path other) + { + throw new NotYetImplementedError(); + } + + public URI toUri() + { + throw new NotYetImplementedError(); + } + + public Path toAbsolutePath() + { + if (isAbsolute()) + { + return this; + } + return new NetPath(fs, cli.System.IO.Path.GetFullPath(cli.System.IO.Path.Combine(System.getProperty("user.dir"), path))); + } + + public Path toRealPath(LinkOption... options) throws IOException + { + return new NetPath(fs, toRealPathImpl(path)); + } + + private static native String toRealPathImpl(String path); + + public WatchKey register(WatchService watcher, WatchEvent.Kind<?>[] events, WatchEvent.Modifier... modifiers) throws IOException + { + throw new NotYetImplementedError(); + } + + public int compareTo(Path other) + { + throw new NotYetImplementedError(); + } + + public boolean equals(Object other) + { + throw new NotYetImplementedError(); + } + + public int hashCode() + { + throw new NotYetImplementedError(); + } + + public String toString() + { + return path; + } +} |