) () -> {
- String s = System.getProperty(
- "jdk.lang.Process.launchMechanism");
- LaunchMechanism lm;
- if (s == null) {
- lm = defaultLaunchMechanism;
- s = lm.name().toLowerCase(Locale.ENGLISH);
- } else {
- try {
- lm = LaunchMechanism.valueOf(
- s.toUpperCase(Locale.ENGLISH));
- } catch (IllegalArgumentException e) {
- lm = null;
- }
- }
- if (lm == null || !validLaunchMechanisms.contains(lm)) {
- throw new Error(
- s + " is not a supported " +
- "process launch mechanism on this platform."
- );
- }
- return lm;
- }
- );
- }
-
- static Platform get() {
- String osName = AccessController.doPrivileged(
- (PrivilegedAction) () -> System.getProperty("os.name")
- );
-
- if (osName.equals("Linux")) { return LINUX; }
- if (osName.contains("OS X")) { return BSD; }
- if (osName.equals("SunOS")) { return SOLARIS; }
- if (osName.equals("AIX")) { return AIX; }
-
- throw new Error(osName + " is not a supported OS platform.");
- }
- }
-
- private static final Platform platform = Platform.get();
- private static final LaunchMechanism launchMechanism = platform.launchMechanism();
- private static final byte[] helperpath = toCString(platform.helperPath());
-
- private static byte[] toCString(String s) {
- if (s == null)
- return null;
- byte[] bytes = s.getBytes();
- byte[] result = new byte[bytes.length + 1];
- System.arraycopy(bytes, 0,
- result, 0,
- bytes.length);
- result[result.length-1] = (byte)0;
- return result;
- }
-
- /* this is for the reaping thread */
- private native int waitForProcessExit(int pid);
-
- /**
- * Creates a process. Depending on the {@code mode} flag, this is done by
- * one of the following mechanisms:
- *
- * 1 - fork(2) and exec(2)
- * 2 - posix_spawn(3P)
- * 3 - vfork(2) and exec(2)
- *
- * (4 - clone(2) and exec(2) - obsolete and currently disabled in native code)
- *
- * @param fds an array of three file descriptors.
- * Indexes 0, 1, and 2 correspond to standard input,
- * standard output and standard error, respectively. On
- * input, a value of -1 means to create a pipe to connect
- * child and parent processes. On output, a value which
- * is not -1 is the parent pipe fd corresponding to the
- * pipe which has been created. An element of this array
- * is -1 on input if and only if it is not -1 on
- * output.
- * @return the pid of the subprocess
- */
- private native int forkAndExec(int mode, byte[] helperpath,
- byte[] prog,
- byte[] argBlock, int argc,
- byte[] envBlock, int envc,
- byte[] dir,
- int[] fds,
- boolean redirectErrorStream)
- throws IOException;
-
- /**
- * The thread pool of "process reaper" daemon threads.
- */
- private static final Executor processReaperExecutor =
- doPrivileged((PrivilegedAction) () -> {
-
- ThreadGroup tg = Thread.currentThread().getThreadGroup();
- while (tg.getParent() != null) tg = tg.getParent();
- ThreadGroup systemThreadGroup = tg;
-
- ThreadFactory threadFactory = grimReaper -> {
- long stackSize = Boolean.getBoolean("jdk.lang.processReaperUseDefaultStackSize") ? 0 : 32768;
- Thread t = new Thread(systemThreadGroup, grimReaper,"process reaper", stackSize);
- t.setDaemon(true);
- // A small attempt (probably futile) to avoid priority inversion
- t.setPriority(Thread.MAX_PRIORITY);
- return t;
- };
-
- return Executors.newCachedThreadPool(threadFactory);
- });
-
- UNIXProcess(final byte[] prog,
- final byte[] argBlock, final int argc,
- final byte[] envBlock, final int envc,
- final byte[] dir,
- final int[] fds,
- final boolean redirectErrorStream)
- throws IOException {
-
- pid = forkAndExec(launchMechanism.ordinal() + 1,
- helperpath,
- prog,
- argBlock, argc,
- envBlock, envc,
- dir,
- fds,
- redirectErrorStream);
-
- try {
- doPrivileged((PrivilegedExceptionAction) () -> {
- initStreams(fds);
- return null;
- });
- } catch (PrivilegedActionException ex) {
- throw (IOException) ex.getException();
- }
- }
-
- static FileDescriptor newFileDescriptor(int fd) {
- FileDescriptor fileDescriptor = new FileDescriptor();
- fdAccess.set(fileDescriptor, fd);
- return fileDescriptor;
- }
-
- void initStreams(int[] fds) throws IOException {
- switch (platform) {
- case LINUX:
- case BSD:
- stdin = (fds[0] == -1) ?
- ProcessBuilder.NullOutputStream.INSTANCE :
- new ProcessPipeOutputStream(fds[0]);
-
- stdout = (fds[1] == -1) ?
- ProcessBuilder.NullInputStream.INSTANCE :
- new ProcessPipeInputStream(fds[1]);
-
- stderr = (fds[2] == -1) ?
- ProcessBuilder.NullInputStream.INSTANCE :
- new ProcessPipeInputStream(fds[2]);
-
- processReaperExecutor.execute(() -> {
- int exitcode = waitForProcessExit(pid);
-
- synchronized (this) {
- this.exitcode = exitcode;
- this.hasExited = true;
- this.notifyAll();
- }
-
- if (stdout instanceof ProcessPipeInputStream)
- ((ProcessPipeInputStream) stdout).processExited();
-
- if (stderr instanceof ProcessPipeInputStream)
- ((ProcessPipeInputStream) stderr).processExited();
-
- if (stdin instanceof ProcessPipeOutputStream)
- ((ProcessPipeOutputStream) stdin).processExited();
- });
- break;
-
- case SOLARIS:
- stdin = (fds[0] == -1) ?
- ProcessBuilder.NullOutputStream.INSTANCE :
- new BufferedOutputStream(
- new FileOutputStream(newFileDescriptor(fds[0])));
-
- stdout = (fds[1] == -1) ?
- ProcessBuilder.NullInputStream.INSTANCE :
- new BufferedInputStream(
- stdout_inner_stream =
- new DeferredCloseInputStream(
- newFileDescriptor(fds[1])));
-
- stderr = (fds[2] == -1) ?
- ProcessBuilder.NullInputStream.INSTANCE :
- new DeferredCloseInputStream(newFileDescriptor(fds[2]));
-
- /*
- * For each subprocess forked a corresponding reaper task
- * is submitted. That task is the only thread which waits
- * for the subprocess to terminate and it doesn't hold any
- * locks while doing so. This design allows waitFor() and
- * exitStatus() to be safely executed in parallel (and they
- * need no native code).
- */
- processReaperExecutor.execute(() -> {
- int exitcode = waitForProcessExit(pid);
-
- synchronized (this) {
- this.exitcode = exitcode;
- this.hasExited = true;
- this.notifyAll();
- }
- });
- break;
-
- case AIX:
- stdin = (fds[0] == -1) ?
- ProcessBuilder.NullOutputStream.INSTANCE :
- new ProcessPipeOutputStream(fds[0]);
-
- stdout = (fds[1] == -1) ?
- ProcessBuilder.NullInputStream.INSTANCE :
- new DeferredCloseProcessPipeInputStream(fds[1]);
-
- stderr = (fds[2] == -1) ?
- ProcessBuilder.NullInputStream.INSTANCE :
- new DeferredCloseProcessPipeInputStream(fds[2]);
-
- processReaperExecutor.execute(() -> {
- int exitcode = waitForProcessExit(pid);
-
- synchronized (this) {
- this.exitcode = exitcode;
- this.hasExited = true;
- this.notifyAll();
- }
-
- if (stdout instanceof DeferredCloseProcessPipeInputStream)
- ((DeferredCloseProcessPipeInputStream) stdout).processExited();
-
- if (stderr instanceof DeferredCloseProcessPipeInputStream)
- ((DeferredCloseProcessPipeInputStream) stderr).processExited();
-
- if (stdin instanceof ProcessPipeOutputStream)
- ((ProcessPipeOutputStream) stdin).processExited();
- });
- break;
-
- default: throw new AssertionError("Unsupported platform: " + platform);
- }
- }
-
- public OutputStream getOutputStream() {
- return stdin;
- }
-
- public InputStream getInputStream() {
- return stdout;
- }
-
- public InputStream getErrorStream() {
- return stderr;
- }
-
- public synchronized int waitFor() throws InterruptedException {
- while (!hasExited) {
- wait();
- }
- return exitcode;
- }
-
- @Override
- public synchronized boolean waitFor(long timeout, TimeUnit unit)
- throws InterruptedException
- {
- if (hasExited) return true;
- if (timeout <= 0) return false;
-
- long remainingNanos = unit.toNanos(timeout);
- long deadline = System.nanoTime() + remainingNanos;
-
- do {
- // Round up to next millisecond
- wait(TimeUnit.NANOSECONDS.toMillis(remainingNanos + 999_999L));
- if (hasExited) {
- return true;
- }
- remainingNanos = deadline - System.nanoTime();
- } while (remainingNanos > 0);
- return hasExited;
- }
-
- public synchronized int exitValue() {
- if (!hasExited) {
- throw new IllegalThreadStateException("process hasn't exited");
- }
- return exitcode;
- }
-
- private static native void destroyProcess(int pid, boolean force);
-
- private void destroy(boolean force) {
- switch (platform) {
- case LINUX:
- case BSD:
- case AIX:
- // There is a risk that pid will be recycled, causing us to
- // kill the wrong process! So we only terminate processes
- // that appear to still be running. Even with this check,
- // there is an unavoidable race condition here, but the window
- // is very small, and OSes try hard to not recycle pids too
- // soon, so this is quite safe.
- synchronized (this) {
- if (!hasExited)
- destroyProcess(pid, force);
- }
- try { stdin.close(); } catch (IOException ignored) {}
- try { stdout.close(); } catch (IOException ignored) {}
- try { stderr.close(); } catch (IOException ignored) {}
- break;
-
- case SOLARIS:
- // There is a risk that pid will be recycled, causing us to
- // kill the wrong process! So we only terminate processes
- // that appear to still be running. Even with this check,
- // there is an unavoidable race condition here, but the window
- // is very small, and OSes try hard to not recycle pids too
- // soon, so this is quite safe.
- synchronized (this) {
- if (!hasExited)
- destroyProcess(pid, force);
- try {
- stdin.close();
- if (stdout_inner_stream != null)
- stdout_inner_stream.closeDeferred(stdout);
- if (stderr instanceof DeferredCloseInputStream)
- ((DeferredCloseInputStream) stderr)
- .closeDeferred(stderr);
- } catch (IOException e) {
- // ignore
- }
- }
- break;
-
- default: throw new AssertionError("Unsupported platform: " + platform);
- }
- }
-
- public void destroy() {
- destroy(false);
- }
-
- @Override
- public Process destroyForcibly() {
- destroy(true);
- return this;
- }
-
- @Override
- public synchronized boolean isAlive() {
- return !hasExited;
- }
-
- private static native void init();
-
- static {
- init();
- }
-
- /**
- * A buffered input stream for a subprocess pipe file descriptor
- * that allows the underlying file descriptor to be reclaimed when
- * the process exits, via the processExited hook.
- *
- * This is tricky because we do not want the user-level InputStream to be
- * closed until the user invokes close(), and we need to continue to be
- * able to read any buffered data lingering in the OS pipe buffer.
- */
- private static class ProcessPipeInputStream extends BufferedInputStream {
- private final Object closeLock = new Object();
-
- ProcessPipeInputStream(int fd) {
- super(new FileInputStream(newFileDescriptor(fd)));
- }
- private static byte[] drainInputStream(InputStream in)
- throws IOException {
- int n = 0;
- int j;
- byte[] a = null;
- while ((j = in.available()) > 0) {
- a = (a == null) ? new byte[j] : Arrays.copyOf(a, n + j);
- n += in.read(a, n, j);
- }
- return (a == null || n == a.length) ? a : Arrays.copyOf(a, n);
- }
-
- /** Called by the process reaper thread when the process exits. */
- synchronized void processExited() {
- synchronized (closeLock) {
- try {
- InputStream in = this.in;
- // this stream is closed if and only if: in == null
- if (in != null) {
- byte[] stragglers = drainInputStream(in);
- in.close();
- this.in = (stragglers == null) ?
- ProcessBuilder.NullInputStream.INSTANCE :
- new ByteArrayInputStream(stragglers);
- }
- } catch (IOException ignored) {}
- }
- }
-
- @Override
- public void close() throws IOException {
- // BufferedInputStream#close() is not synchronized unlike most other
- // methods. Synchronizing helps avoid race with processExited().
- synchronized (closeLock) {
- super.close();
- }
- }
- }
-
- /**
- * A buffered output stream for a subprocess pipe file descriptor
- * that allows the underlying file descriptor to be reclaimed when
- * the process exits, via the processExited hook.
- */
- private static class ProcessPipeOutputStream extends BufferedOutputStream {
- ProcessPipeOutputStream(int fd) {
- super(new FileOutputStream(newFileDescriptor(fd)));
- }
-
- /** Called by the process reaper thread when the process exits. */
- synchronized void processExited() {
- OutputStream out = this.out;
- if (out != null) {
- try {
- out.close();
- } catch (IOException ignored) {
- // We know of no reason to get an IOException, but if
- // we do, there's nothing else to do but carry on.
- }
- this.out = ProcessBuilder.NullOutputStream.INSTANCE;
- }
- }
- }
-
- // A FileInputStream that supports the deferment of the actual close
- // operation until the last pending I/O operation on the stream has
- // finished. This is required on Solaris because we must close the stdin
- // and stdout streams in the destroy method in order to reclaim the
- // underlying file descriptors. Doing so, however, causes any thread
- // currently blocked in a read on one of those streams to receive an
- // IOException("Bad file number"), which is incompatible with historical
- // behavior. By deferring the close we allow any pending reads to see -1
- // (EOF) as they did before.
- //
- private static class DeferredCloseInputStream extends FileInputStream
- {
- DeferredCloseInputStream(FileDescriptor fd) {
- super(fd);
- }
-
- private Object lock = new Object(); // For the following fields
- private boolean closePending = false;
- private int useCount = 0;
- private InputStream streamToClose;
-
- private void raise() {
- synchronized (lock) {
- useCount++;
- }
- }
-
- private void lower() throws IOException {
- synchronized (lock) {
- useCount--;
- if (useCount == 0 && closePending) {
- streamToClose.close();
- }
- }
- }
-
- // stc is the actual stream to be closed; it might be this object, or
- // it might be an upstream object for which this object is downstream.
- //
- private void closeDeferred(InputStream stc) throws IOException {
- synchronized (lock) {
- if (useCount == 0) {
- stc.close();
- } else {
- closePending = true;
- streamToClose = stc;
- }
- }
- }
-
- public void close() throws IOException {
- synchronized (lock) {
- useCount = 0;
- closePending = false;
- }
- super.close();
- }
-
- public int read() throws IOException {
- raise();
- try {
- return super.read();
- } finally {
- lower();
- }
- }
-
- public int read(byte[] b) throws IOException {
- raise();
- try {
- return super.read(b);
- } finally {
- lower();
- }
- }
-
- public int read(byte[] b, int off, int len) throws IOException {
- raise();
- try {
- return super.read(b, off, len);
- } finally {
- lower();
- }
- }
-
- public long skip(long n) throws IOException {
- raise();
- try {
- return super.skip(n);
- } finally {
- lower();
- }
- }
-
- public int available() throws IOException {
- raise();
- try {
- return super.available();
- } finally {
- lower();
- }
- }
- }
-
- /**
- * A buffered input stream for a subprocess pipe file descriptor
- * that allows the underlying file descriptor to be reclaimed when
- * the process exits, via the processExited hook.
- *
- * This is tricky because we do not want the user-level InputStream to be
- * closed until the user invokes close(), and we need to continue to be
- * able to read any buffered data lingering in the OS pipe buffer.
- *
- * On AIX this is especially tricky, because the 'close()' system call
- * will block if another thread is at the same time blocked in a file
- * operation (e.g. 'read()') on the same file descriptor. We therefore
- * combine 'ProcessPipeInputStream' approach used on Linux and Bsd
- * with the DeferredCloseInputStream approach used on Solaris. This means
- * that every potentially blocking operation on the file descriptor
- * increments a counter before it is executed and decrements it once it
- * finishes. The 'close()' operation will only be executed if there are
- * no pending operations. Otherwise it is deferred after the last pending
- * operation has finished.
- *
- */
- private static class DeferredCloseProcessPipeInputStream
- extends BufferedInputStream {
-
- private final Object closeLock = new Object();
- private int useCount = 0;
- private boolean closePending = false;
-
- DeferredCloseProcessPipeInputStream(int fd) {
- super(new FileInputStream(newFileDescriptor(fd)));
- }
-
- private InputStream drainInputStream(InputStream in)
- throws IOException {
- int n = 0;
- int j;
- byte[] a = null;
- synchronized (closeLock) {
- if (buf == null) // asynchronous close()?
- return null; // discard
- j = in.available();
- }
- while (j > 0) {
- a = (a == null) ? new byte[j] : Arrays.copyOf(a, n + j);
- synchronized (closeLock) {
- if (buf == null) // asynchronous close()?
- return null; // discard
- n += in.read(a, n, j);
- j = in.available();
- }
- }
- return (a == null) ?
- ProcessBuilder.NullInputStream.INSTANCE :
- new ByteArrayInputStream(n == a.length ? a : Arrays.copyOf(a, n));
- }
-
- /** Called by the process reaper thread when the process exits. */
- synchronized void processExited() {
- try {
- InputStream in = this.in;
- if (in != null) {
- InputStream stragglers = drainInputStream(in);
- in.close();
- this.in = stragglers;
- }
- } catch (IOException ignored) { }
- }
-
- private void raise() {
- synchronized (closeLock) {
- useCount++;
- }
- }
-
- private void lower() throws IOException {
- synchronized (closeLock) {
- useCount--;
- if (useCount == 0 && closePending) {
- closePending = false;
- super.close();
- }
- }
- }
-
- @Override
- public int read() throws IOException {
- raise();
- try {
- return super.read();
- } finally {
- lower();
- }
- }
-
- @Override
- public int read(byte[] b) throws IOException {
- raise();
- try {
- return super.read(b);
- } finally {
- lower();
- }
- }
-
- @Override
- public int read(byte[] b, int off, int len) throws IOException {
- raise();
- try {
- return super.read(b, off, len);
- } finally {
- lower();
- }
- }
-
- @Override
- public long skip(long n) throws IOException {
- raise();
- try {
- return super.skip(n);
- } finally {
- lower();
- }
- }
-
- @Override
- public int available() throws IOException {
- raise();
- try {
- return super.available();
- } finally {
- lower();
- }
- }
-
- @Override
- public void close() throws IOException {
- // BufferedInputStream#close() is not synchronized unlike most other
- // methods. Synchronizing helps avoid racing with drainInputStream().
- synchronized (closeLock) {
- if (useCount == 0) {
- super.close();
- }
- else {
- closePending = true;
- }
- }
- }
- }
-}
diff --git a/src/IKVM.Java/local/java/lang/UNIXProcessEnvironment.java b/src/IKVM.Java/local/java/lang/UNIXProcessEnvironment.java
deleted file mode 100644
index fbe4f37ef2..0000000000
--- a/src/IKVM.Java/local/java/lang/UNIXProcessEnvironment.java
+++ /dev/null
@@ -1,450 +0,0 @@
-/*
- * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation. Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-/* We use APIs that access the standard Unix environ array, which
- * is defined by UNIX98 to look like:
- *
- * char **environ;
- *
- * These are unsorted, case-sensitive, null-terminated arrays of bytes
- * of the form FOO=BAR\000 which are usually encoded in the user's
- * default encoding (file.encoding is an excellent choice for
- * encoding/decoding these). However, even though the user cannot
- * directly access the underlying byte representation, we take pains
- * to pass on the child the exact byte representation we inherit from
- * the parent process for any environment name or value not created by
- * Javaland. So we keep track of all the byte representations.
- *
- * Internally, we define the types Variable and Value that exhibit
- * String/byteArray duality. The internal representation of the
- * environment then looks like a Map. But we don't
- * expose this to the user -- we only provide a Map
- * view, although we could also provide a Map view.
- *
- * The non-private methods in this class are not for general use even
- * within this package. Instead, they are the system-dependent parts
- * of the system-independent method of the same name. Don't even
- * think of using this class unless your method's name appears below.
- *
- * @author Martin Buchholz
- * @since 1.5
- */
-
- // IKVM Largely a copy of the UNIX version of ProcessEnvironment. Used currently to provide the toEnvironmentBlock method needed by JNI for UNIXProcess.
-
-package java.lang;
-
-import java.io.*;
-import java.util.*;
-
-
-final class UNIXProcessEnvironment
-{
- private static final HashMap theEnvironment;
- private static final Map theUnmodifiableEnvironment;
- static final int MIN_NAME_LENGTH = 0;
-
- static {
- // We cache the C environment. This means that subsequent calls
- // to putenv/setenv from C will not be visible from Java code.
- byte[][] environ = environ();
- theEnvironment = new HashMap<>(environ.length/2 + 3);
- // Read environment variables back to front,
- // so that earlier variables override later ones.
- for (int i = environ.length-1; i > 0; i-=2)
- theEnvironment.put(Variable.valueOf(environ[i-1]),
- Value.valueOf(environ[i]));
-
- theUnmodifiableEnvironment
- = Collections.unmodifiableMap
- (new StringEnvironment(theEnvironment));
- }
-
- /* Only for use by System.getenv(String) */
- static String getenv(String name) {
- return theUnmodifiableEnvironment.get(name);
- }
-
- /* Only for use by System.getenv() */
- static Map getenv() {
- return theUnmodifiableEnvironment;
- }
-
- /* Only for use by ProcessBuilder.environment() */
- @SuppressWarnings("unchecked")
- static Map environment() {
- return new StringEnvironment
- ((Map)(theEnvironment.clone()));
- }
-
- /* Only for use by Runtime.exec(...String[]envp...) */
- static Map emptyEnvironment(int capacity) {
- return new StringEnvironment(new HashMap(capacity));
- }
-
- private static native byte[][] environ();
-
- // This class is not instantiable.
- private UNIXProcessEnvironment() {}
-
- // Check that name is suitable for insertion into Environment map
- private static void validateVariable(String name) {
- if (name.indexOf('=') != -1 ||
- name.indexOf('\u0000') != -1)
- throw new IllegalArgumentException
- ("Invalid environment variable name: \"" + name + "\"");
- }
-
- // Check that value is suitable for insertion into Environment map
- private static void validateValue(String value) {
- if (value.indexOf('\u0000') != -1)
- throw new IllegalArgumentException
- ("Invalid environment variable value: \"" + value + "\"");
- }
-
- // A class hiding the byteArray-String duality of
- // text data on Unixoid operating systems.
- private static abstract class ExternalData {
- protected final String str;
- protected final byte[] bytes;
-
- protected ExternalData(String str, byte[] bytes) {
- this.str = str;
- this.bytes = bytes;
- }
-
- public byte[] getBytes() {
- return bytes;
- }
-
- public String toString() {
- return str;
- }
-
- public boolean equals(Object o) {
- return o instanceof ExternalData
- && arrayEquals(getBytes(), ((ExternalData) o).getBytes());
- }
-
- public int hashCode() {
- return arrayHash(getBytes());
- }
- }
-
- private static class Variable
- extends ExternalData implements Comparable
- {
- protected Variable(String str, byte[] bytes) {
- super(str, bytes);
- }
-
- public static Variable valueOfQueryOnly(Object str) {
- return valueOfQueryOnly((String) str);
- }
-
- public static Variable valueOfQueryOnly(String str) {
- return new Variable(str, str.getBytes());
- }
-
- public static Variable valueOf(String str) {
- validateVariable(str);
- return valueOfQueryOnly(str);
- }
-
- public static Variable valueOf(byte[] bytes) {
- return new Variable(new String(bytes), bytes);
- }
-
- public int compareTo(Variable variable) {
- return arrayCompare(getBytes(), variable.getBytes());
- }
-
- public boolean equals(Object o) {
- return o instanceof Variable && super.equals(o);
- }
- }
-
- private static class Value
- extends ExternalData implements Comparable
- {
- protected Value(String str, byte[] bytes) {
- super(str, bytes);
- }
-
- public static Value valueOfQueryOnly(Object str) {
- return valueOfQueryOnly((String) str);
- }
-
- public static Value valueOfQueryOnly(String str) {
- return new Value(str, str.getBytes());
- }
-
- public static Value valueOf(String str) {
- validateValue(str);
- return valueOfQueryOnly(str);
- }
-
- public static Value valueOf(byte[] bytes) {
- return new Value(new String(bytes), bytes);
- }
-
- public int compareTo(Value value) {
- return arrayCompare(getBytes(), value.getBytes());
- }
-
- public boolean equals(Object o) {
- return o instanceof Value && super.equals(o);
- }
- }
-
- // This implements the String map view the user sees.
- private static class StringEnvironment
- extends AbstractMap
- {
- private Map m;
- private static String toString(Value v) {
- return v == null ? null : v.toString();
- }
- public StringEnvironment(Map m) {this.m = m;}
- public int size() {return m.size();}
- public boolean isEmpty() {return m.isEmpty();}
- public void clear() { m.clear();}
- public boolean containsKey(Object key) {
- return m.containsKey(Variable.valueOfQueryOnly(key));
- }
- public boolean containsValue(Object value) {
- return m.containsValue(Value.valueOfQueryOnly(value));
- }
- public String get(Object key) {
- return toString(m.get(Variable.valueOfQueryOnly(key)));
- }
- public String put(String key, String value) {
- return toString(m.put(Variable.valueOf(key),
- Value.valueOf(value)));
- }
- public String remove(Object key) {
- return toString(m.remove(Variable.valueOfQueryOnly(key)));
- }
- public Set keySet() {
- return new StringKeySet(m.keySet());
- }
- public Set> entrySet() {
- return new StringEntrySet(m.entrySet());
- }
- public Collection values() {
- return new StringValues(m.values());
- }
-
- // It is technically feasible to provide a byte-oriented view
- // as follows:
- // public Map asByteArrayMap() {
- // return new ByteArrayEnvironment(m);
- // }
-
-
- // Convert to Unix style environ as a monolithic byte array
- // inspired by the Windows Environment Block, except we work
- // exclusively with bytes instead of chars, and we need only
- // one trailing NUL on Unix.
- // This keeps the JNI as simple and efficient as possible.
- public byte[] toEnvironmentBlock(int[]envc) {
- int count = m.size() * 2; // For added '=' and NUL
- for (Map.Entry entry : m.entrySet()) {
- count += entry.getKey().getBytes().length;
- count += entry.getValue().getBytes().length;
- }
-
- byte[] block = new byte[count];
-
- int i = 0;
- for (Map.Entry entry : m.entrySet()) {
- byte[] key = entry.getKey ().getBytes();
- byte[] value = entry.getValue().getBytes();
- System.arraycopy(key, 0, block, i, key.length);
- i+=key.length;
- block[i++] = (byte) '=';
- System.arraycopy(value, 0, block, i, value.length);
- i+=value.length + 1;
- // No need to write NUL byte explicitly
- //block[i++] = (byte) '\u0000';
- }
- envc[0] = m.size();
- return block;
- }
- }
-
- static byte[] toEnvironmentBlock(Map map, int[]envc) {
- if (map == null) {
- return null;
- }
-
- StringEnvironment env = new StringEnvironment(new HashMap(map.size()));
- for (Map.Entry entry : map.entrySet()) {
- env.put(entry.getKey(), entry.getValue());
- }
-
- return env.toEnvironmentBlock(envc);
- }
-
-
- private static class StringEntry
- implements Map.Entry
- {
- private final Map.Entry e;
- public StringEntry(Map.Entry e) {this.e = e;}
- public String getKey() {return e.getKey().toString();}
- public String getValue() {return e.getValue().toString();}
- public String setValue(String newValue) {
- return e.setValue(Value.valueOf(newValue)).toString();
- }
- public String toString() {return getKey() + "=" + getValue();}
- public boolean equals(Object o) {
- return o instanceof StringEntry
- && e.equals(((StringEntry)o).e);
- }
- public int hashCode() {return e.hashCode();}
- }
-
- private static class StringEntrySet
- extends AbstractSet>
- {
- private final Set> s;
- public StringEntrySet(Set> s) {this.s = s;}
- public int size() {return s.size();}
- public boolean isEmpty() {return s.isEmpty();}
- public void clear() { s.clear();}
- public Iterator> iterator() {
- return new Iterator>() {
- Iterator> i = s.iterator();
- public boolean hasNext() {return i.hasNext();}
- public Map.Entry next() {
- return new StringEntry(i.next());
- }
- public void remove() {i.remove();}
- };
- }
- private static Map.Entry vvEntry(final Object o) {
- if (o instanceof StringEntry)
- return ((StringEntry)o).e;
- return new Map.Entry() {
- public Variable getKey() {
- return Variable.valueOfQueryOnly(((Map.Entry)o).getKey());
- }
- public Value getValue() {
- return Value.valueOfQueryOnly(((Map.Entry)o).getValue());
- }
- public Value setValue(Value value) {
- throw new UnsupportedOperationException();
- }
- };
- }
- public boolean contains(Object o) { return s.contains(vvEntry(o)); }
- public boolean remove(Object o) { return s.remove(vvEntry(o)); }
- public boolean equals(Object o) {
- return o instanceof StringEntrySet
- && s.equals(((StringEntrySet) o).s);
- }
- public int hashCode() {return s.hashCode();}
- }
-
- private static class StringValues
- extends AbstractCollection
- {
- private final Collection c;
- public StringValues(Collection c) {this.c = c;}
- public int size() {return c.size();}
- public boolean isEmpty() {return c.isEmpty();}
- public void clear() { c.clear();}
- public Iterator iterator() {
- return new Iterator() {
- Iterator i = c.iterator();
- public boolean hasNext() {return i.hasNext();}
- public String next() {return i.next().toString();}
- public void remove() {i.remove();}
- };
- }
- public boolean contains(Object o) {
- return c.contains(Value.valueOfQueryOnly(o));
- }
- public boolean remove(Object o) {
- return c.remove(Value.valueOfQueryOnly(o));
- }
- public boolean equals(Object o) {
- return o instanceof StringValues
- && c.equals(((StringValues)o).c);
- }
- public int hashCode() {return c.hashCode();}
- }
-
- private static class StringKeySet extends AbstractSet {
- private final Set s;
- public StringKeySet(Set s) {this.s = s;}
- public int size() {return s.size();}
- public boolean isEmpty() {return s.isEmpty();}
- public void clear() { s.clear();}
- public Iterator iterator() {
- return new Iterator() {
- Iterator i = s.iterator();
- public boolean hasNext() {return i.hasNext();}
- public String next() {return i.next().toString();}
- public void remove() { i.remove();}
- };
- }
- public boolean contains(Object o) {
- return s.contains(Variable.valueOfQueryOnly(o));
- }
- public boolean remove(Object o) {
- return s.remove(Variable.valueOfQueryOnly(o));
- }
- }
-
- // Replace with general purpose method someday
- private static int arrayCompare(byte[]x, byte[] y) {
- int min = x.length < y.length ? x.length : y.length;
- for (int i = 0; i < min; i++)
- if (x[i] != y[i])
- return x[i] - y[i];
- return x.length - y.length;
- }
-
- // Replace with general purpose method someday
- private static boolean arrayEquals(byte[] x, byte[] y) {
- if (x.length != y.length)
- return false;
- for (int i = 0; i < x.length; i++)
- if (x[i] != y[i])
- return false;
- return true;
- }
-
- // Replace with general purpose method someday
- private static int arrayHash(byte[] x) {
- int hash = 0;
- for (int i = 0; i < x.length; i++)
- hash = 31 * hash + x[i];
- return hash;
- }
-
-}
diff --git a/src/IKVM.Java/local/java/lang/Win32Process.java b/src/IKVM.Java/local/java/lang/Win32Process.java
deleted file mode 100644
index 9f804716be..0000000000
--- a/src/IKVM.Java/local/java/lang/Win32Process.java
+++ /dev/null
@@ -1,46 +0,0 @@
-package java.lang;
-
-import java.io.*;
-import java.util.*;
-
-final class Win32Process extends Process {
-
- cli.System.Diagnostics.Process process;
- OutputStream outputStream;
- InputStream inputStream;
- InputStream errorStream;
-
- static native Process start(String cmdarray[], java.util.Map environment, String dir, ProcessBuilder.Redirect[] redirects, boolean redirectErrorStream) throws IOException;
-
- private Win32Process(cli.System.Diagnostics.Process process, OutputStream outputStream, InputStream inputStream, InputStream errorStream) {
- this.process = process;
- this.outputStream = outputStream;
- this.inputStream = inputStream;
- this.errorStream = errorStream;
- }
-
- @Override
- public OutputStream getOutputStream() {
- return outputStream;
- }
-
- @Override
- public InputStream getInputStream() {
- return inputStream;
- }
-
- @Override
- public InputStream getErrorStream() {
- return errorStream;
- }
-
- @Override
- public native int waitFor() throws InterruptedException;
-
- @Override
- public native int exitValue();
-
- @Override
- public native void destroy();
-
-}
diff --git a/src/IKVM.Java/local/sun/management/ManagementFactoryHelper.java b/src/IKVM.Java/local/sun/management/ManagementFactoryHelper.java
index 68f9724611..211d32a11e 100644
--- a/src/IKVM.Java/local/sun/management/ManagementFactoryHelper.java
+++ b/src/IKVM.Java/local/sun/management/ManagementFactoryHelper.java
@@ -293,7 +293,7 @@ public static HashMap getPlatformDynamicMBeans() {
}
static void registerInternalMBeans(MBeanServer mbs) {
-
+
}
private static void unregisterMBean(MBeanServer mbs, String mbeanName) {
@@ -319,10 +319,17 @@ public Void run() throws MBeanRegistrationException,
}
static void unregisterInternalMBeans(MBeanServer mbs) {
-
+
}
static {
+ AccessController.doPrivileged(
+ new java.security.PrivilegedAction() {
+ public Void run() {
+ System.loadLibrary("management");
+ return null;
+ }
+ });
jvm = new VMManagementImpl();
}
diff --git a/src/IKVM.Java/local/sun/misc/FileURLMapper.java b/src/IKVM.Java/local/sun/misc/FileURLMapper.java
deleted file mode 100644
index 94caff650e..0000000000
--- a/src/IKVM.Java/local/sun/misc/FileURLMapper.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * This is a merged version of the Windows & Solaris platform specific versions.
- * Since the IKVM class library binary can be used both on Windows and on *nix,
- * I've merged the platform specific classes into a generic class that at
- * runtime determines if it runs on Windows or not.
- */
-
-package sun.misc;
-
-import java.net.URL;
-import java.io.File;
-
-import sun.net.www.ParseUtil;
-
-public class FileURLMapper {
-
- URL url;
- String file;
-
- public FileURLMapper(URL url) {
- this.url = url;
- }
-
- /**
- * @returns the platform specific path corresponding to the URL, and in particular returns a UNC when the authority contains a hostname
- */
- public String getPath () {
- if (file != null) {
- return file;
- }
-
- if (cli.IKVM.Runtime.RuntimeUtil.get_IsWindows()) {
- String host = url.getHost();
- if (host != null && !host.equals("") &&
- !"localhost".equalsIgnoreCase(host)) {
- String rest = url.getFile();
- String s = host + ParseUtil.decode (url.getFile());
- file = "\\\\"+ s.replace('/', '\\');
- return file;
- }
- String path = url.getFile().replace('/', '\\');
- file = ParseUtil.decode(path);
- return file;
- } else {
- String host = url.getHost();
- if (host == null || "".equals(host) || "localhost".equalsIgnoreCase (host)) {
- file = url.getFile();
- file = ParseUtil.decode (file);
- }
- return file;
- }
- }
-
- public boolean exists() {
- String s = getPath();
- if (s == null) {
- return false;
- } else {
- File f = new File(s);
- return f.exists();
- }
- }
-
-}
diff --git a/src/IKVM.Java/local/sun/misc/OSEnvironment.java b/src/IKVM.Java/local/sun/misc/OSEnvironment.java
index d51ac0f12c..2fea318f52 100644
--- a/src/IKVM.Java/local/sun/misc/OSEnvironment.java
+++ b/src/IKVM.Java/local/sun/misc/OSEnvironment.java
@@ -1,32 +1,12 @@
-/*
- Copyright (C) 2007 Jeroen Frijters
+// Licensed to the IKVM project under one or more agreements.
+// The IKVM project licenses this file to you under the Zlib license.
- 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:
+package sun.misc;
- 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.
+public class OSEnvironment {
- Jeroen Frijters
- jeroen@frijters.net
-
-*/
+ public static void initialize() {
-package sun.misc;
-
-public class OSEnvironment
-{
- public static void initialize()
- {
}
+
}
diff --git a/src/IKVM.Java/local/sun/net/dns/ResolverConfigurationImpl.java b/src/IKVM.Java/local/sun/net/dns/ResolverConfigurationImpl.java
deleted file mode 100644
index d0e3acbcf7..0000000000
--- a/src/IKVM.Java/local/sun/net/dns/ResolverConfigurationImpl.java
+++ /dev/null
@@ -1,223 +0,0 @@
-/*
- * Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation. Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-package sun.net.dns;
-
-import java.util.List;
-import java.util.LinkedList;
-import java.util.StringTokenizer;
-import java.io.IOException;
-import cli.System.Net.NetworkInformation.IPAddressCollection;
-import cli.System.Net.NetworkInformation.IPInterfaceProperties;
-import cli.System.Net.NetworkInformation.NetworkInterface;
-
-/*
- * An implementation of sun.net.ResolverConfiguration for Windows.
- */
-
-public class ResolverConfigurationImpl
- extends ResolverConfiguration
-{
- // Lock helds whilst loading configuration or checking
- private static Object lock = new Object();
-
- // Resolver options
- private final Options opts;
-
- // Addreses have changed
- private static boolean changed = false;
-
- // Time of last refresh.
- private static long lastRefresh = -1;
-
- // Cache timeout (120 seconds) - should be converted into property
- // or configured as preference in the future.
- private static final int TIMEOUT = 120000;
-
- // DNS suffix list and name servers populated by native method
- private static String os_searchlist;
- private static String os_nameservers;
-
- // Cached lists
- private static LinkedList searchlist;
- private static LinkedList nameservers;
-
- // Parse string that consists of token delimited by space or commas
- // and return LinkedHashMap
- private LinkedList stringToList(String str) {
- LinkedList ll = new LinkedList<>();
-
- // comma and space are valid delimites
- StringTokenizer st = new StringTokenizer(str, ", ");
- while (st.hasMoreTokens()) {
- String s = st.nextToken();
- if (!ll.contains(s)) {
- ll.add(s);
- }
- }
- return ll;
- }
-
- // Load DNS configuration from OS
-
- private void loadConfig() {
- assert Thread.holdsLock(lock);
-
- // if address have changed then DNS probably changed aswell;
- // otherwise check if cached settings have expired.
- //
- if (changed) {
- changed = false;
- } else {
- if (lastRefresh >= 0) {
- long currTime = System.currentTimeMillis();
- if ((currTime - lastRefresh) < TIMEOUT) {
- return;
- }
- }
- }
-
- // load DNS configuration, update timestamp, create
- // new HashMaps from the loaded configuration
- //
- loadDNSconfig0();
-
- lastRefresh = System.currentTimeMillis();
- searchlist = stringToList(os_searchlist);
- nameservers = stringToList(os_nameservers);
- os_searchlist = null; // can be GC'ed
- os_nameservers = null;
- }
-
- ResolverConfigurationImpl() {
- opts = new OptionsImpl();
- }
-
- @SuppressWarnings("unchecked") // clone()
- public List searchlist() {
- synchronized (lock) {
- loadConfig();
-
- // List is mutable so return a shallow copy
- return (List)searchlist.clone();
- }
- }
-
- @SuppressWarnings("unchecked") // clone()
- public List nameservers() {
- synchronized (lock) {
- loadConfig();
-
- // List is mutable so return a shallow copy
- return (List)nameservers.clone();
- }
- }
-
- public Options options() {
- return opts;
- }
-
- // --- Address Change Listener
-
- static class AddressChangeListener extends Thread {
- public void run() {
- for (;;) {
- // wait for configuration to change
- if (notifyAddrChange0() != 0)
- return;
- synchronized (lock) {
- changed = true;
- }
- }
- }
- }
-
-
- // --- Native methods --
-
- static void init0() {
- }
-
- static void loadDNSconfig0() {
- String searchlist = "";
- String nameservers = "";
- for (NetworkInterface iface : NetworkInterface.GetAllNetworkInterfaces()) {
- IPInterfaceProperties props = iface.GetIPProperties();
- IPAddressCollection addresses = props.get_DnsAddresses();
- for (int i = 0; i < addresses.get_Count(); i++) {
- cli.System.Net.IPAddress addr = addresses.get_Item(i);
- // no IPv6 support
- if (addr.get_AddressFamily().Value == cli.System.Net.Sockets.AddressFamily.InterNetwork) {
- nameservers = strAppend(nameservers, addr.toString());
- }
- }
- try {
- if (false) throw new cli.System.PlatformNotSupportedException();
- searchlist = strAppend(searchlist, props.get_DnsSuffix());
- }
- catch (cli.System.PlatformNotSupportedException _) {
- }
- }
- os_searchlist = searchlist;
- os_nameservers = nameservers;
- }
-
- private static String strAppend(String s, String app) {
- if (s.equals("")) {
- return app;
- }
- if (app.equals("")) {
- return s;
- }
- return s + " " + app;
- }
-
- static int notifyAddrChange0() {
- // TODO we could use System.Net.NetworkInformation.NetworkChange to detect changes
- return -1;
- }
-
- static {
- java.security.AccessController.doPrivileged(
- new java.security.PrivilegedAction() {
- public Void run() {
- System.loadLibrary("net");
- return null;
- }
- });
- init0();
-
- // start the address listener thread
- AddressChangeListener thr = new AddressChangeListener();
- thr.setDaemon(true);
- thr.start();
- }
-}
-
-/**
- * Implementation of {@link ResolverConfiguration.Options}
- */
-class OptionsImpl extends ResolverConfiguration.Options {
-}
diff --git a/src/IKVM.Java/local/sun/net/sdp/SdpSupport.java b/src/IKVM.Java/local/sun/net/sdp/SdpSupport.java
deleted file mode 100644
index 9a7437e0c5..0000000000
--- a/src/IKVM.Java/local/sun/net/sdp/SdpSupport.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation. Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-package sun.net.sdp;
-
-import java.io.IOException;
-import java.io.FileDescriptor;
-
-
-/**
- * This class defines methods for creating SDP sockets or "converting" existing
- * file descriptors, referencing (unbound) TCP sockets, to SDP.
- */
-
-public final class SdpSupport {
-
- private SdpSupport() { }
-
- /**
- * Creates a SDP socket, returning file descriptor referencing the socket.
- */
- public static FileDescriptor createSocket() throws IOException {
- throw new UnsupportedOperationException("SDP not supported on this platform");
- }
-
- /**
- * Converts an existing file descriptor, that references an unbound TCP socket,
- * to SDP.
- */
- public static void convertSocket(FileDescriptor fd) throws IOException {
- throw new UnsupportedOperationException("SDP not supported on this platform");
- }
-}
diff --git a/src/IKVM.Java/local/sun/net/www/protocol/file/FileURLConnection.java b/src/IKVM.Java/local/sun/net/www/protocol/file/FileURLConnection.java
deleted file mode 100644
index 43c94b317e..0000000000
--- a/src/IKVM.Java/local/sun/net/www/protocol/file/FileURLConnection.java
+++ /dev/null
@@ -1,238 +0,0 @@
-/*
- * Copyright (c) 1995, 2010, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation. Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-/**
- * Open an file input stream given a URL.
- * @author James Gosling
- * @author Steven B. Byrne
- */
-
-package sun.net.www.protocol.file;
-
-import java.net.URL;
-import java.net.FileNameMap;
-import java.io.*;
-import java.text.Collator;
-import java.security.Permission;
-import sun.net.*;
-import sun.net.www.*;
-import java.util.*;
-import java.text.SimpleDateFormat;
-
-import sun.security.action.GetPropertyAction;
-import sun.security.action.GetIntegerAction;
-import sun.security.action.GetBooleanAction;
-
-public class FileURLConnection extends URLConnection {
-
- static String CONTENT_LENGTH = "content-length";
- static String CONTENT_TYPE = "content-type";
- static String TEXT_PLAIN = "text/plain";
- static String LAST_MODIFIED = "last-modified";
-
- String contentType;
- InputStream is;
-
- File file;
- String filename;
- boolean isDirectory = false;
- boolean exists = false;
- List files;
-
- long length = -1;
- long lastModified = 0;
-
- protected FileURLConnection(URL u, File file) {
- super(u);
- this.file = file;
- }
-
- /*
- * Note: the semantics of FileURLConnection object is that the
- * results of the various URLConnection calls, such as
- * getContentType, getInputStream or getContentLength reflect
- * whatever was true when connect was called.
- */
- public void connect() throws IOException {
- if (!connected) {
- try {
- filename = file.toString();
- isDirectory = file.isDirectory();
- if (isDirectory) {
- String[] fileList = file.list();
- if (fileList == null)
- throw new FileNotFoundException(filename + " exists, but is not accessible");
- files = Arrays.asList(fileList);
- } else {
-
- is = new BufferedInputStream(new FileInputStream(filename));
-
- // Check if URL should be metered
- boolean meteredInput = ProgressMonitor.getDefault().shouldMeterInput(url, "GET");
- if (meteredInput) {
- ProgressSource pi = new ProgressSource(url, "GET", file.length());
- is = new MeteredStream(is, pi, file.length());
- }
- }
- } catch (IOException e) {
- throw e;
- }
- connected = true;
- }
- }
-
- private boolean initializedHeaders = false;
-
- private void initializeHeaders() {
- try {
- connect();
- exists = file.exists();
- } catch (IOException e) {
- }
- if (!initializedHeaders || !exists) {
- length = file.length();
- lastModified = file.lastModified();
-
- if (!isDirectory) {
- FileNameMap map = java.net.URLConnection.getFileNameMap();
- contentType = map.getContentTypeFor(filename);
- if (contentType != null) {
- properties.add(CONTENT_TYPE, contentType);
- }
- properties.add(CONTENT_LENGTH, String.valueOf(length));
-
- /*
- * Format the last-modified field into the preferred
- * Internet standard - ie: fixed-length subset of that
- * defined by RFC 1123
- */
- if (lastModified != 0) {
- Date date = new Date(lastModified);
- SimpleDateFormat fo =
- new SimpleDateFormat ("EEE, dd MMM yyyy HH:mm:ss 'GMT'", Locale.US);
- fo.setTimeZone(TimeZone.getTimeZone("GMT"));
- properties.add(LAST_MODIFIED, fo.format(date));
- }
- } else {
- properties.add(CONTENT_TYPE, TEXT_PLAIN);
- }
- initializedHeaders = true;
- }
- }
-
- public String getHeaderField(String name) {
- initializeHeaders();
- return super.getHeaderField(name);
- }
-
- public String getHeaderField(int n) {
- initializeHeaders();
- return super.getHeaderField(n);
- }
-
- public int getContentLength() {
- initializeHeaders();
- if (length > Integer.MAX_VALUE)
- return -1;
- return (int) length;
- }
-
- public long getContentLengthLong() {
- initializeHeaders();
- return length;
- }
-
- public String getHeaderFieldKey(int n) {
- initializeHeaders();
- return super.getHeaderFieldKey(n);
- }
-
- public MessageHeader getProperties() {
- initializeHeaders();
- return super.getProperties();
- }
-
- public long getLastModified() {
- initializeHeaders();
- return lastModified;
- }
-
- public synchronized InputStream getInputStream()
- throws IOException {
-
- int iconHeight;
- int iconWidth;
-
- connect();
-
- if (is == null) {
- if (isDirectory) {
- FileNameMap map = java.net.URLConnection.getFileNameMap();
-
- StringBuffer buf = new StringBuffer();
-
- if (files == null) {
- throw new FileNotFoundException(filename);
- }
-
- sort(files);
-
- for (int i = 0 ; i < files.size() ; i++) {
- String fileName = files.get(i);
- buf.append(fileName);
- buf.append("\n");
- }
- // Put it into a (default) locale-specific byte-stream.
- is = new ByteArrayInputStream(buf.toString().getBytes());
- } else {
- throw new FileNotFoundException(filename);
- }
- }
- return is;
- }
-
- // IKVM specific method (sorting moved here to delay java.text.Collator dependency)
- private static void sort(List files) {
- Collections.sort(files, Collator.getInstance());
- }
-
- Permission permission;
-
- /* since getOutputStream isn't supported, only read permission is
- * relevant
- */
- public Permission getPermission() throws IOException {
- if (permission == null) {
- String decodedPath = ParseUtil.decode(url.getPath());
- if (File.separatorChar == '/') {
- permission = new FilePermission(decodedPath, "read");
- } else {
- permission = new FilePermission(
- decodedPath.replace('/',File.separatorChar), "read");
- }
- }
- return permission;
- }
-}
diff --git a/src/IKVM.Java/local/sun/net/www/protocol/file/Handler.java b/src/IKVM.Java/local/sun/net/www/protocol/file/Handler.java
deleted file mode 100644
index 3ea4412558..0000000000
--- a/src/IKVM.Java/local/sun/net/www/protocol/file/Handler.java
+++ /dev/null
@@ -1,160 +0,0 @@
-/*
- * Copyright (c) 1999, 2003, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation. Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-package sun.net.www.protocol.file;
-
-import java.net.InetAddress;
-import java.net.URLConnection;
-import java.net.URL;
-import java.net.Proxy;
-import java.net.MalformedURLException;
-import java.net.URLStreamHandler;
-import java.io.InputStream;
-import java.io.IOException;
-import sun.net.www.ParseUtil;
-import java.io.File;
-
-/**
- * Open an file input stream given a URL.
- * @author James Gosling
- */
-public class Handler extends URLStreamHandler {
-
- private String getHost(URL url) {
- String host = url.getHost();
- if (host == null)
- host = "";
- return host;
- }
-
-
- protected void parseURL(URL u, String spec, int start, int limit) {
- /*
- * Ugly backwards compatibility. Flip any file separator
- * characters to be forward slashes. This is a nop on Unix
- * and "fixes" win32 file paths. According to RFC 2396,
- * only forward slashes may be used to represent hierarchy
- * separation in a URL but previous releases unfortunately
- * performed this "fixup" behavior in the file URL parsing code
- * rather than forcing this to be fixed in the caller of the URL
- * class where it belongs. Since backslash is an "unwise"
- * character that would normally be encoded if literally intended
- * as a non-seperator character the damage of veering away from the
- * specification is presumably limited.
- */
- super.parseURL(u, spec.replace(File.separatorChar, '/'), start, limit);
- }
-
- public synchronized URLConnection openConnection(URL url)
- throws IOException {
- return openConnection(url, null);
- }
-
- public synchronized URLConnection openConnection(URL url, Proxy p)
- throws IOException {
-
- String path;
- String file = url.getFile();
- String host = url.getHost();
-
- if (cli.IKVM.Runtime.RuntimeUtil.get_IsWindows()) {
- path = ParseUtil.decode(file);
- path = path.replace('/', '\\');
- path = path.replace('|', ':');
- } else {
- path = ParseUtil.decode(url.getPath());
- }
-
- if ((host == null) || host.equals("") ||
- host.equalsIgnoreCase("localhost") ||
- host.equals("~")) {
- return createFileURLConnection(url, new File(path));
- }
-
- /*
- * attempt to treat this as a UNC path. See 4180841
- */
- if (cli.IKVM.Runtime.RuntimeUtil.get_IsWindows()) {
- path = "\\\\" + host + path;
- File f = new File(path);
- if (f.exists()) {
- return createFileURLConnection(url, f);
- }
- }
-
- /*
- * Now attempt an ftp connection.
- */
- URLConnection uc;
- URL newurl;
-
- try {
- newurl = new URL("ftp", host, file +
- (url.getRef() == null ? "":
- "#" + url.getRef()));
- if (p != null) {
- uc = newurl.openConnection(p);
- } else {
- uc = newurl.openConnection();
- }
- } catch (IOException e) {
- uc = null;
- }
- if (uc == null) {
- throw new IOException("Unable to connect to: " +
- url.toExternalForm());
- }
- return uc;
- }
-
- /**
- * Template method to be overriden by Java Plug-in. [stanleyh]
- */
- protected URLConnection createFileURLConnection(URL url, File file) {
- return new FileURLConnection(url, file);
- }
-
- /**
- * Compares the host components of two URLs.
- * @param u1 the URL of the first host to compare
- * @param u2 the URL of the second host to compare
- * @return true if and only if they
- * are equal, false otherwise.
- */
- protected boolean hostsEqual(URL u1, URL u2) {
- /*
- * Special case for file: URLs
- * per RFC 1738 no hostname is equivalent to 'localhost'
- * i.e. file:///path is equal to file://localhost/path
- */
- String s1 = u1.getHost();
- String s2 = u2.getHost();
- if ("localhost".equalsIgnoreCase(s1) && ( s2 == null || "".equals(s2)))
- return true;
- if ("localhost".equalsIgnoreCase(s2) && ( s1 == null || "".equals(s1)))
- return true;
- return super.hostsEqual(u1, u2);
- }
-}
diff --git a/src/IKVM.Java/local/sun/net/www/protocol/jar/JarFileFactory.java b/src/IKVM.Java/local/sun/net/www/protocol/jar/JarFileFactory.java
deleted file mode 100644
index 74398f6af5..0000000000
--- a/src/IKVM.Java/local/sun/net/www/protocol/jar/JarFileFactory.java
+++ /dev/null
@@ -1,184 +0,0 @@
-/*
- * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation. Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-/*IKVM*/
-/*
- * Modified for IKVM by Jeroen Frijters on May 22, 2007.
- *
- * This is a merged version of the Windows & Solaris platform specific versions.
- * Since the IKVM class library binary can be used both on Windows and on *nix,
- * I've merged the platform specific classes into a generic class that at
- * runtime determines if it runs on Windows or not.
- *
-/*IKVM*/
-
-package sun.net.www.protocol.jar;
-
-import java.io.IOException;
-import java.io.FileNotFoundException;
-import java.net.URL;
-import java.net.URLConnection;
-import java.util.HashMap;
-import java.util.jar.JarFile;
-import java.security.Permission;
-import sun.net.util.URLUtil;
-
-/* A factory for cached JAR file. This class is used to both retrieve
- * and cache Jar files.
- *
- * @author Benjamin Renaud
- * @since JDK1.2
- */
-class JarFileFactory implements URLJarFile.URLJarFileCloseController {
-
- /* the url to file cache */
- private static final HashMap fileCache = new HashMap<>();
-
- /* the file to url cache */
- private static final HashMap urlCache = new HashMap<>();
-
- private static final JarFileFactory instance = new JarFileFactory();
-
- private JarFileFactory() { }
-
- public static JarFileFactory getInstance() {
- return instance;
- }
-
- URLConnection getConnection(JarFile jarFile) throws IOException {
- URL u;
- synchronized (instance) {
- u = urlCache.get(jarFile);
- }
- if (u != null)
- return u.openConnection();
-
- return null;
- }
-
- public JarFile get(URL url) throws IOException {
- return get(url, true);
- }
-
- JarFile get(URL url, boolean useCaches) throws IOException {
- if (cli.IKVM.Runtime.RuntimeUtil.get_IsWindows() && url.getProtocol().equalsIgnoreCase("file")) {
- // Deal with UNC pathnames specially. See 4180841
-
- String host = url.getHost();
- if (host != null && !host.equals("") &&
- !host.equalsIgnoreCase("localhost")) {
-
- url = new URL("file", "", "//" + host + url.getPath());
- }
- }
-
- JarFile result;
- JarFile local_result;
-
- if (useCaches) {
- synchronized (instance) {
- result = getCachedJarFile(url);
- }
- if (result == null) {
- local_result = URLJarFile.getJarFile(url, this);
- synchronized (instance) {
- result = getCachedJarFile(url);
- if (result == null) {
- fileCache.put(URLUtil.urlNoFragString(url), local_result);
- urlCache.put(local_result, url);
- result = local_result;
- } else {
- if (local_result != null) {
- local_result.close();
- }
- }
- }
- }
- } else {
- result = URLJarFile.getJarFile(url, this);
- }
- if (result == null)
- throw new FileNotFoundException(url.toString());
-
- return result;
- }
-
- /**
- * Callback method of the URLJarFileCloseController to
- * indicate that the JarFile is close. This way we can
- * remove the JarFile from the cache
- */
- public void close(JarFile jarFile) {
- synchronized (instance) {
- URL urlRemoved = urlCache.remove(jarFile);
- if (urlRemoved != null)
- fileCache.remove(URLUtil.urlNoFragString(urlRemoved));
- }
- }
-
- private JarFile getCachedJarFile(URL url) {
- assert Thread.holdsLock(instance);
- JarFile result = fileCache.get(URLUtil.urlNoFragString(url));
-
- /* if the JAR file is cached, the permission will always be there */
- if (result != null) {
- Permission perm = getPermission(result);
- if (perm != null) {
- SecurityManager sm = System.getSecurityManager();
- if (sm != null) {
- try {
- sm.checkPermission(perm);
- } catch (SecurityException se) {
- // fallback to checkRead/checkConnect for pre 1.2
- // security managers
- if ((perm instanceof java.io.FilePermission) &&
- perm.getActions().indexOf("read") != -1) {
- sm.checkRead(perm.getName());
- } else if ((perm instanceof
- java.net.SocketPermission) &&
- perm.getActions().indexOf("connect") != -1) {
- sm.checkConnect(url.getHost(), url.getPort());
- } else {
- throw se;
- }
- }
- }
- }
- }
- return result;
- }
-
- private Permission getPermission(JarFile jarFile) {
- try {
- URLConnection uc = getConnection(jarFile);
- if (uc != null)
- return uc.getPermission();
- } catch (IOException ioe) {
- // gulp
- }
-
- return null;
- }
-}
diff --git a/src/IKVM.Java/local/sun/nio/ch/DatagramDispatcher.java b/src/IKVM.Java/local/sun/nio/ch/DatagramDispatcher.java
deleted file mode 100644
index a200ef4c72..0000000000
--- a/src/IKVM.Java/local/sun/nio/ch/DatagramDispatcher.java
+++ /dev/null
@@ -1,21 +0,0 @@
-package sun.nio.ch;
-
-import java.io.*;
-
-class DatagramDispatcher extends NativeDispatcher {
-
- static {
- IOUtil.load();
- }
-
- native int read(FileDescriptor fd, long address, int len) throws IOException;
-
- native long readv(FileDescriptor fd, long address, int len) throws IOException;
-
- native int write(FileDescriptor fd, long address, int len) throws IOException;
-
- native long writev(FileDescriptor fd, long address, int len) throws IOException;
-
- native void close(FileDescriptor fd) throws IOException;
-
-}
diff --git a/src/IKVM.Java/local/sun/nio/ch/DefaultAsynchronousChannelProvider.java b/src/IKVM.Java/local/sun/nio/ch/DefaultAsynchronousChannelProvider.java
deleted file mode 100644
index 25f33fdf87..0000000000
--- a/src/IKVM.Java/local/sun/nio/ch/DefaultAsynchronousChannelProvider.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package sun.nio.ch;
-
-import java.nio.channels.spi.AsynchronousChannelProvider;
-
-public class DefaultAsynchronousChannelProvider {
-
- private DefaultAsynchronousChannelProvider() {
-
- }
-
- public static AsynchronousChannelProvider create() {
- return new DotNetAsynchronousChannelProvider();
- }
-
-}
diff --git a/src/IKVM.Java/local/sun/nio/ch/DefaultSelectorProvider.java b/src/IKVM.Java/local/sun/nio/ch/DefaultSelectorProvider.java
deleted file mode 100644
index 4e6bebb736..0000000000
--- a/src/IKVM.Java/local/sun/nio/ch/DefaultSelectorProvider.java
+++ /dev/null
@@ -1,21 +0,0 @@
-package sun.nio.ch;
-
-import java.io.IOException;
-import java.nio.channels.spi.AbstractSelector;
-import java.nio.channels.spi.SelectorProvider;
-
-public class DefaultSelectorProvider {
-
- private DefaultSelectorProvider() {
-
- }
-
- public static SelectorProvider create() {
- return new SelectorProviderImpl() {
- public AbstractSelector openSelector() throws IOException {
- return new DotNetSelectorImpl(this);
- }
- };
- }
-
-}
diff --git a/src/IKVM.Java/local/sun/nio/ch/DotNetAsynchronousChannelGroup.java b/src/IKVM.Java/local/sun/nio/ch/DotNetAsynchronousChannelGroup.java
deleted file mode 100644
index f86b7e98ec..0000000000
--- a/src/IKVM.Java/local/sun/nio/ch/DotNetAsynchronousChannelGroup.java
+++ /dev/null
@@ -1,61 +0,0 @@
-package sun.nio.ch;
-
-import java.nio.channels.*;
-import java.nio.channels.spi.AsynchronousChannelProvider;
-import java.io.Closeable;
-import java.io.IOException;
-import java.io.FileDescriptor;
-import java.util.*;
-import java.util.concurrent.*;
-import java.util.concurrent.locks.ReadWriteLock;
-import java.util.concurrent.locks.ReentrantReadWriteLock;
-
-import ikvm.internal.NotYetImplementedError;
-
-/**
- * .NET implementation of AsynchronousChannelGroup.
- */
-class DotNetAsynchronousChannelGroup extends AsynchronousChannelGroupImpl {
-
- private boolean closed;
-
- DotNetAsynchronousChannelGroup(AsynchronousChannelProvider provider, ThreadPool pool) throws IOException {
- super(provider, pool);
- }
-
- // release all resources
- synchronized void implClose() {
- closed = true;
- }
-
- @Override
- boolean isEmpty() {
- return true;
- }
-
- @Override
- final Object attachForeignChannel(final Channel channel, FileDescriptor fdObj) throws IOException {
- throw new NotYetImplementedError();
- }
-
- @Override
- final void detachForeignChannel(Object key) {
- throw new NotYetImplementedError();
- }
-
- @Override
- void closeAllChannels() {
-
- }
-
- @Override
- void executeOnHandlerTask(Runnable task) {
- throw new NotYetImplementedError();
- }
-
- @Override
- void shutdownHandlerTasks() {
-
- }
-
-}
diff --git a/src/IKVM.Java/local/sun/nio/ch/DotNetAsynchronousChannelProvider.java b/src/IKVM.Java/local/sun/nio/ch/DotNetAsynchronousChannelProvider.java
deleted file mode 100644
index d096956056..0000000000
--- a/src/IKVM.Java/local/sun/nio/ch/DotNetAsynchronousChannelProvider.java
+++ /dev/null
@@ -1,60 +0,0 @@
-package sun.nio.ch;
-
-import java.nio.channels.*;
-import java.nio.channels.spi.AsynchronousChannelProvider;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.ThreadFactory;
-import java.io.IOException;
-
-public class DotNetAsynchronousChannelProvider extends AsynchronousChannelProvider {
-
- private static volatile DotNetAsynchronousChannelGroup defaultGroup;
-
- public DotNetAsynchronousChannelProvider() {
- // nothing to do
- }
-
- private DotNetAsynchronousChannelGroup defaultGroup() throws IOException {
- if (defaultGroup == null) {
- synchronized (DotNetAsynchronousChannelProvider.class) {
- if (defaultGroup == null) {
- defaultGroup = new DotNetAsynchronousChannelGroup(this, ThreadPool.getDefault());
- }
- }
- }
-
- return defaultGroup;
- }
-
- @Override
- public AsynchronousChannelGroup openAsynchronousChannelGroup(int nThreads, ThreadFactory factory) throws IOException {
- return new DotNetAsynchronousChannelGroup(this, ThreadPool.create(nThreads, factory));
- }
-
- @Override
- public AsynchronousChannelGroup openAsynchronousChannelGroup(ExecutorService executor, int initialSize) throws IOException {
- return new DotNetAsynchronousChannelGroup(this, ThreadPool.wrap(executor, initialSize));
- }
-
- private DotNetAsynchronousChannelGroup toDotNet(AsynchronousChannelGroup group) throws IOException {
- if (group == null) {
- return defaultGroup();
- } else {
- if (!(group instanceof DotNetAsynchronousChannelGroup))
- throw new IllegalChannelGroupException();
-
- return (DotNetAsynchronousChannelGroup)group;
- }
- }
-
- @Override
- public AsynchronousServerSocketChannel openAsynchronousServerSocketChannel(AsynchronousChannelGroup group) throws IOException {
- return new DotNetAsynchronousServerSocketChannelImpl(toDotNet(group));
- }
-
- @Override
- public AsynchronousSocketChannel openAsynchronousSocketChannel(AsynchronousChannelGroup group) throws IOException {
- return new DotNetAsynchronousSocketChannelImpl(toDotNet(group));
- }
-
-}
diff --git a/src/IKVM.Java/local/sun/nio/ch/DotNetAsynchronousFileChannelImpl.java b/src/IKVM.Java/local/sun/nio/ch/DotNetAsynchronousFileChannelImpl.java
deleted file mode 100644
index 3b27cef592..0000000000
--- a/src/IKVM.Java/local/sun/nio/ch/DotNetAsynchronousFileChannelImpl.java
+++ /dev/null
@@ -1,134 +0,0 @@
-package sun.nio.ch;
-
-import java.io.*;
-import java.nio.*;
-import java.nio.channels.*;
-import java.util.concurrent.*;
-
-/**
- * .NET implementation of AsynchronousFileChannel.
- */
-public class DotNetAsynchronousFileChannelImpl extends AsynchronousFileChannelImpl implements Cancellable, Groupable {
-
- private static class DefaultGroupHolder {
-
- static final DotNetAsynchronousChannelGroup defaultGroup = defaultGroup();
-
- private static DotNetAsynchronousChannelGroup defaultGroup() {
- try {
- return new DotNetAsynchronousChannelGroup(null, ThreadPool.createDefault());
- } catch (IOException ioe) {
- throw new InternalError(ioe);
- }
- }
-
- }
-
- public static AsynchronousFileChannel open(FileDescriptor fdo, boolean reading, boolean writing, ThreadPool pool) throws IOException
- {
- DotNetAsynchronousChannelGroup group;
- boolean isDefaultGroup;
-
- if (pool == null) {
- group = DefaultGroupHolder.defaultGroup;
- isDefaultGroup = true;
- } else {
- group = new DotNetAsynchronousChannelGroup(null, pool);
- isDefaultGroup = false;
- }
- try {
- return new DotNetAsynchronousFileChannelImpl(fdo, reading, writing, group, isDefaultGroup);
- } catch (IOException x) {
- // error binding to port so need to close it (if created for this channel)
- if (!isDefaultGroup)
- group.implClose();
-
- throw x;
- }
- }
-
- protected final DotNetAsynchronousChannelGroup group;
- protected final boolean isDefaultGroup;
-
- private DotNetAsynchronousFileChannelImpl(FileDescriptor fdObj, boolean reading, boolean writing, DotNetAsynchronousChannelGroup group, boolean isDefaultGroup) throws IOException {
- super(fdObj, reading, writing, group.executor());
- this.group = group;
- this.isDefaultGroup = isDefaultGroup;
- }
-
- @Override
- public AsynchronousChannelGroupImpl group() {
- return group;
- }
-
- @Override
- public void onCancel(PendingFuture, ?> task) {
- onCancel0(task);
- }
-
- @Override
- public void close() throws IOException {
- close0();
- }
-
- @Override
- public long size() throws IOException {
- return size0();
- }
-
- @Override
- public AsynchronousFileChannel truncate(long size) throws IOException {
- return truncate0(size);
- }
-
- @Override
- public void force(boolean metaData) throws IOException {
- force0(metaData);
- }
-
- @Override
- Future implLock(final long position, final long size, final boolean shared, A attachment, final CompletionHandler handler) {
- return implLock0(position, size, shared, attachment, handler);
- }
-
- @Override
- public FileLock tryLock(long position, long size, boolean shared) throws IOException {
- return tryLock0(position, size, shared);
- }
-
- @Override
- protected void implRelease(FileLockImpl fli) throws IOException {
- implRelease0(fli);
- }
-
- @Override
- Future implRead(ByteBuffer dst, long position, A attachment, CompletionHandler handler)
- {
- return implRead0(dst, position, attachment, handler);
- }
-
- Future implWrite(ByteBuffer src, long position, A attachment, CompletionHandler handler) {
- return implWrite0(src, position, attachment, handler);
- }
-
- private native void onCancel0(PendingFuture, ?> task);
-
- private native void close0();
-
- private native long size0();
-
- private native AsynchronousFileChannel truncate0(long size);
-
- private native void force0(boolean metaData);
-
- private native Future implLock0(final long position, final long size, final boolean shared, A attachment, final CompletionHandler handler);
-
- private native FileLock tryLock0(long position, long size, boolean shared);
-
- private native void implRelease0(FileLockImpl fli);
-
- private native Future implRead0(ByteBuffer dst, long position, A attachment, CompletionHandler handler);
-
- private native Future implWrite0(ByteBuffer src, long position, A attachment, CompletionHandler handler);
-
-}
diff --git a/src/IKVM.Java/local/sun/nio/ch/DotNetAsynchronousServerSocketChannelImpl.java b/src/IKVM.Java/local/sun/nio/ch/DotNetAsynchronousServerSocketChannelImpl.java
deleted file mode 100644
index 5b726c0c30..0000000000
--- a/src/IKVM.Java/local/sun/nio/ch/DotNetAsynchronousServerSocketChannelImpl.java
+++ /dev/null
@@ -1,40 +0,0 @@
-package sun.nio.ch;
-
-import java.io.IOException;
-import java.nio.channels.*;
-import java.util.concurrent.Future;
-import java.util.concurrent.atomic.AtomicBoolean;
-
-/**
- * .NET implementation of AsynchronousServerSocketChannel using overlapped I/O.
- */
-class DotNetAsynchronousServerSocketChannelImpl extends AsynchronousServerSocketChannelImpl {
-
- protected final DotNetAsynchronousChannelGroup group;
- protected AtomicBoolean accepting = new AtomicBoolean();
-
- DotNetAsynchronousServerSocketChannelImpl(DotNetAsynchronousChannelGroup group) throws IOException {
- super(group);
- this.group = group;
- }
-
- @Override
- public AsynchronousChannelGroupImpl group() {
- return group;
- }
-
- @Override
- void implClose() throws IOException {
- implClose0();
- }
-
- @Override
- Future implAccept(Object attachment, final CompletionHandler handler) {
- return implAccept0(attachment, handler);
- }
-
- private native Future implAccept0(Object attachment, final CompletionHandler handler);
-
- private native void implClose0() throws IOException;
-
-}
diff --git a/src/IKVM.Java/local/sun/nio/ch/DotNetAsynchronousSocketChannelImpl.java b/src/IKVM.Java/local/sun/nio/ch/DotNetAsynchronousSocketChannelImpl.java
deleted file mode 100644
index 45525e0e8b..0000000000
--- a/src/IKVM.Java/local/sun/nio/ch/DotNetAsynchronousSocketChannelImpl.java
+++ /dev/null
@@ -1,70 +0,0 @@
-package sun.nio.ch;
-
-import java.io.*;
-import java.net.*;
-import java.nio.*;
-import java.nio.channels.*;
-import java.util.concurrent.*;
-
-/**
- * .NET implementation of AsynchronousSocketChannelImpl.
- */
-class DotNetAsynchronousSocketChannelImpl extends AsynchronousSocketChannelImpl {
-
- private final DotNetAsynchronousChannelGroup group;
-
- DotNetAsynchronousSocketChannelImpl(DotNetAsynchronousChannelGroup group, boolean failIfGroupShutdown) throws IOException {
- super(group);
- this.group = group;
- }
-
- DotNetAsynchronousSocketChannelImpl(DotNetAsynchronousChannelGroup group) throws IOException {
- this(group, true);
- }
-
- DotNetAsynchronousSocketChannelImpl(DotNetAsynchronousChannelGroup group, FileDescriptor fd, InetSocketAddress remote) throws IOException {
- super(group, fd, remote);
- this.group = group;
- }
-
- @Override
- public AsynchronousChannelGroupImpl group() {
- return group;
- }
-
- @Override
- public void onCancel(PendingFuture, ?> task) {
- onCancel0(task);
- }
-
- @Override
- void implClose() throws IOException {
- implClose0();
- }
-
- @Override
- Future implConnect(SocketAddress remote, A attachment, CompletionHandler handler) {
- return implConnect0(remote, attachment, handler);
- }
-
- @Override
- Future implRead(boolean isScatteringRead, ByteBuffer dst, ByteBuffer[] dsts, long timeout, TimeUnit unit, A attachment, CompletionHandler handler) {
- return implRead0(isScatteringRead, dst, dsts, timeout, unit, attachment, handler);
- }
-
- @Override
- Future implWrite(boolean gatheringWrite, ByteBuffer src, ByteBuffer[] srcs, long timeout, TimeUnit unit, A attachment, CompletionHandler handler) {
- return implWrite0(gatheringWrite, src, srcs, timeout, unit, attachment, handler);
- }
-
- private native void onCancel0(PendingFuture, ?> task);
-
- private native void implClose0();
-
- private native Future implConnect0(SocketAddress remote, A attachment, CompletionHandler handler);
-
- private native Future implRead0(boolean isScatteringRead, ByteBuffer dst, ByteBuffer[] dsts, long timeout, TimeUnit unit, A attachment, CompletionHandler handler);
-
- private native Future implWrite0(boolean gatheringWrite, ByteBuffer src, ByteBuffer[] srcs, long timeout, TimeUnit unit, A attachment, CompletionHandler handler);
-
-}
diff --git a/src/IKVM.Java/local/sun/nio/ch/DotNetSelectorImpl.java b/src/IKVM.Java/local/sun/nio/ch/DotNetSelectorImpl.java
deleted file mode 100644
index e86e1dda97..0000000000
--- a/src/IKVM.Java/local/sun/nio/ch/DotNetSelectorImpl.java
+++ /dev/null
@@ -1,303 +0,0 @@
-/*
- * Copyright (c) 2002, 2007, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation. Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-// Parts Copyright (C) 2002-2007 Jeroen Frijters
-
-package sun.nio.ch;
-
-import java.io.IOException;
-import java.nio.channels.ClosedSelectorException;
-import java.nio.channels.Pipe;
-import java.nio.channels.SelectableChannel;
-import java.nio.channels.SelectionKey;
-import java.nio.channels.Selector;
-import java.nio.channels.spi.AbstractSelectableChannel;
-import java.nio.channels.spi.AbstractSelector;
-import java.nio.channels.spi.SelectorProvider;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
-
-import cli.System.Net.Sockets.Socket;
-import cli.System.Net.Sockets.SocketException;
-import cli.System.Net.Sockets.AddressFamily;
-import cli.System.Net.Sockets.SocketType;
-import cli.System.Net.Sockets.ProtocolType;
-import cli.System.Net.Sockets.SelectMode;
-import cli.System.Collections.ArrayList;
-
-final class DotNetSelectorImpl extends SelectorImpl {
-
- // class for fdMap entries
- private final static class MapEntry {
-
- SelectionKeyImpl ski;
- long updateCount = 0;
- long clearedCount = 0;
-
- MapEntry(SelectionKeyImpl ski) {
- this.ski = ski;
- }
-
- }
-
- private ArrayList channelArray = new ArrayList();
- private long updateCount = 0;
-
- // pipe used as a wakeup object
- private final Pipe wakeupPipe;
-
- // file descriptors corresponding to source and sink
- private final Socket wakeupSourceFd, wakeupSinkFd;
-
- // lock for interrupt triggering and clearing
- private final Object interruptLock = new Object();
- private volatile boolean interruptTriggered = false;
-
- private final HashMap fdMap = new HashMap();
-
- DotNetSelectorImpl(SelectorProvider sp) throws IOException {
- super(sp);
-
- wakeupPipe = Pipe.open();
- wakeupSourceFd = ((SelChImpl)wakeupPipe.source()).getFD().getSocket();
-
- // disable the Nagle algorithm so that the wakeup is more immediate
- SinkChannelImpl sink = (SinkChannelImpl)wakeupPipe.sink();
- (sink.sc).socket().setTcpNoDelay(true);
- wakeupSinkFd = ((SelChImpl)sink).getFD().getSocket();
- }
-
- protected int doSelect(long timeout) throws IOException {
- if (channelArray == null)
- throw new ClosedSelectorException();
-
- processDeregisterQueue();
- if (interruptTriggered) {
- resetWakeupSocket();
- return 0;
- }
-
- ArrayList read = new ArrayList();
- ArrayList write = new ArrayList();
- ArrayList error = new ArrayList();
- for (int i = 0; i < channelArray.get_Count(); i++) {
- SelectionKeyImpl ski = (SelectionKeyImpl)channelArray.get_Item(i);
- int ops = ski.interestOps();
- if (ski.channel() instanceof SocketChannelImpl) {
- // TODO there's a race condition here...
- if (((SocketChannelImpl)ski.channel()).isConnected()) {
- ops &= SelectionKey.OP_READ | SelectionKey.OP_WRITE;
- } else {
- ops &= SelectionKey.OP_CONNECT;
- }
- }
-
- if ((ops & (SelectionKey.OP_READ | SelectionKey.OP_ACCEPT)) != 0) {
- read.Add(((SelChImpl)ski.channel()).getFD().getSocket());
- }
-
- if ((ops & (SelectionKey.OP_WRITE | SelectionKey.OP_CONNECT)) != 0) {
- write.Add(((SelChImpl)ski.channel()).getFD().getSocket());
- }
-
- if ((ops & SelectionKey.OP_CONNECT) != 0) {
- error.Add(((SelChImpl)ski.channel()).getFD().getSocket());
- }
- }
-
- read.Add(wakeupSourceFd);
-
- try
- {
- begin();
- int microSeconds = 1000 * (int)Math.min(Integer.MAX_VALUE / 1000, timeout);
- try {
- if (false) throw new SocketException();
- // FXBUG docs say that -1 is infinite timeout, but that doesn't appear to work
- Socket.Select(read, write, error, timeout < 0 ? Integer.MAX_VALUE : microSeconds);
- } catch (SocketException _) {
- read.Clear();
- write.Clear();
- error.Clear();
- }
- } finally {
- end();
- }
-
- processDeregisterQueue();
- int updated = updateSelectedKeys(read, write, error);
-
- // done with poll(), set wakeupSocket to nonsignaled for the next run.
- resetWakeupSocket();
- return updated;
- }
-
- private int updateSelectedKeys(ArrayList read, ArrayList write, ArrayList error) {
- updateCount++;
- int keys = processFDSet(updateCount, read, Net.POLLIN);
- keys += processFDSet(updateCount, write, Net.POLLCONN | Net.POLLOUT);
- keys += processFDSet(updateCount, error, Net.POLLIN | Net.POLLCONN | Net.POLLOUT);
- return keys;
- }
-
- private int processFDSet(long updateCount, ArrayList sockets, int rOps) {
- int numKeysUpdated = 0;
-
- for (int i = 0; i < sockets.get_Count(); i++) {
- Socket desc = (Socket)sockets.get_Item(i);
- if (desc == wakeupSourceFd) {
- synchronized (interruptLock) {
- interruptTriggered = true;
- }
-
- continue;
- }
-
- // if me is null, the key was deregistered in the previous processDeregisterQueue
- MapEntry me = fdMap.get(desc);
- if (me == null)
- continue;
- SelectionKeyImpl sk = me.ski;
- if (selectedKeys.contains(sk)) {
- if (me.clearedCount != updateCount) {
- // key in selected set
- if (sk.channel.translateAndSetReadyOps(rOps, sk) && (me.updateCount != updateCount)) {
- me.updateCount = updateCount;
- numKeysUpdated++;
- }
- } else {
- // the readyOps have been set; now add
- if (sk.channel.translateAndUpdateReadyOps(rOps, sk) && (me.updateCount != updateCount)) {
- me.updateCount = updateCount;
- numKeysUpdated++;
- }
- }
-
- me.clearedCount = updateCount;
- } else {
- if (me.clearedCount != updateCount) {
- // Key is not in selected set yet
- sk.channel.translateAndSetReadyOps(rOps, sk);
- if ((sk.nioReadyOps() & sk.nioInterestOps()) != 0) {
- selectedKeys.add(sk);
- me.updateCount = updateCount;
- numKeysUpdated++;
- }
- } else {
- // The readyOps have been set; now add
- sk.channel.translateAndUpdateReadyOps(rOps, sk);
- if ((sk.nioReadyOps() & sk.nioInterestOps()) != 0) {
- selectedKeys.add(sk);
- me.updateCount = updateCount;
- numKeysUpdated++;
- }
- }
-
- me.clearedCount = updateCount;
- }
- }
-
- return numKeysUpdated;
- }
-
- protected void implClose() throws IOException {
- if (channelArray != null) {
- // prevent further wakeup
- synchronized (interruptLock) {
- interruptTriggered = true;
- }
-
- wakeupPipe.sink().close();
- wakeupPipe.source().close();
- for (int i = 0; i < channelArray.get_Count(); i++) {
- // Deregister channels
- SelectionKeyImpl ski = (SelectionKeyImpl)channelArray.get_Item(i);
- deregister(ski);
- SelectableChannel selch = ski.channel();
- if (!selch.isOpen() && !selch.isRegistered())
- ((SelChImpl)selch).kill();
- }
- selectedKeys = null;
- channelArray = null;
- }
- }
-
- protected void implRegister(SelectionKeyImpl ski) {
- channelArray.Add(ski);
- fdMap.put(((SelChImpl)ski.channel()).getFD().getSocket(), new MapEntry(ski));
- keys.add(ski);
- }
-
- protected void implDereg(SelectionKeyImpl ski) throws IOException {
- channelArray.Remove(ski);
- fdMap.remove(((SelChImpl)ski.channel()).getFD().getSocket());
- keys.remove(ski);
- selectedKeys.remove(ski);
- deregister(ski);
-
- SelectableChannel selch = ski.channel();
- if (!selch.isOpen() && !selch.isRegistered()) {
- ((SelChImpl)selch).kill();
- }
- }
-
- public Selector wakeup() {
- synchronized (interruptLock) {
- if (!interruptTriggered) {
- setWakeupSocket();
- interruptTriggered = true;
- }
- }
-
- return this;
- }
-
- // Sets Windows wakeup socket to a signaled state.
- private void setWakeupSocket() {
- wakeupSinkFd.Send(new byte[1]);
- }
-
- // Sets Windows wakeup socket to a non-signaled state.
- private void resetWakeupSocket() {
- synchronized (interruptLock) {
- if (interruptTriggered == false)
- return;
-
- resetWakeupSocket0(wakeupSourceFd);
- interruptTriggered = false;
- }
- }
-
- private static void resetWakeupSocket0(Socket wakeupSourceFd) {
- while (wakeupSourceFd.get_Available() > 0) {
- wakeupSourceFd.Receive(new byte[1]);
- }
- }
-
-}
diff --git a/src/IKVM.Java/local/sun/nio/ch/FileDispatcherImpl.java b/src/IKVM.Java/local/sun/nio/ch/FileDispatcherImpl.java
deleted file mode 100644
index a22cc59f37..0000000000
--- a/src/IKVM.Java/local/sun/nio/ch/FileDispatcherImpl.java
+++ /dev/null
@@ -1,141 +0,0 @@
-package sun.nio.ch;
-
-import java.io.FileDescriptor;
-import java.io.IOException;
-import java.security.PrivilegedAction;
-
-import sun.misc.SharedSecrets;
-import sun.misc.JavaIOFileDescriptorAccess;
-
-class FileDispatcherImpl extends FileDispatcher {
-
- // set to true if fast file transmission (TransmitFile) is enabled
- private static final boolean fastFileTransfer;
-
- /**
- * Indicates if the dispatcher should first advance the file position
- * to the end of file when writing.
- */
- private final boolean append;
-
- FileDispatcherImpl(boolean append) {
- this.append = append;
- }
-
- FileDispatcherImpl() {
- this(false);
- }
-
- @Override
- boolean needsPositionLock() {
- return true;
- }
-
- int read(FileDescriptor fd, long address, int len) throws IOException {
- return read0(fd, address, len);
- }
-
- static native int read0(FileDescriptor fd, long address, int len) throws IOException;
-
- int pread(FileDescriptor fd, long address, int len, long position) throws IOException {
- return pread0(fd, address, len, position);
- }
-
- static native int pread0(FileDescriptor fd, long address, int len, long position) throws IOException;
-
- long readv(FileDescriptor fd, long address, int len) throws IOException {
- return readv0(fd, address, len);
- }
-
- static native long readv0(FileDescriptor fd, long address, int len) throws IOException;
-
- int write(FileDescriptor fd, long address, int len) throws IOException {
- return write0(fd, address, len, append);
- }
-
- static native int write0(FileDescriptor fd, long address, int len, boolean append) throws IOException;
-
- int pwrite(FileDescriptor fd, long address, int len, long position) throws IOException {
- return pwrite0(fd, address, len, position);
- }
-
- static native int pwrite0(FileDescriptor fd, long address, int len, long position) throws IOException;
-
- long writev(FileDescriptor fd, long address, int len) throws IOException {
- return writev0(fd, address, len, append);
- }
-
- static native long writev0(FileDescriptor fd, long address, int len, boolean append) throws IOException;
-
- int force(FileDescriptor fd, boolean metaData) throws IOException {
- return force0(fd, metaData);
- }
-
- static native int force0(FileDescriptor fd, boolean metaData) throws IOException;
-
- int truncate(FileDescriptor fd, long size) throws IOException {
- return truncate0(fd, size);
- }
-
- static native int truncate0(FileDescriptor fd, long size) throws IOException;
-
- long size(FileDescriptor fd) throws IOException {
- return size0(fd);
- }
-
- static native long size0(FileDescriptor fd) throws IOException;
-
- int lock(FileDescriptor fd, boolean blocking, long pos, long size, boolean shared) throws IOException {
- return lock0(fd, blocking, pos, size, shared);
- }
-
- static native int lock0(FileDescriptor fd, boolean blocking, long pos, long size, boolean shared) throws IOException;
-
- void release(FileDescriptor fd, long pos, long size) throws IOException {
- release0(fd, pos, size);
- }
-
- static native void release0(FileDescriptor fd, long pos, long size) throws IOException;
-
- void close(FileDescriptor fd) throws IOException {
- close0(fd);
- }
-
- static native void close0(FileDescriptor fd) throws IOException;
-
- native FileDescriptor duplicateForMapping(FileDescriptor fd) throws IOException;
-
- boolean canTransferToDirectly(java.nio.channels.SelectableChannel sc) {
- return fastFileTransfer && sc.isBlocking();
- }
-
- boolean transferToDirectlyNeedsPositionLock() {
- return transferToDirectlyNeedsPositionLock0();
- }
-
- static native boolean transferToDirectlyNeedsPositionLock0();
-
- static boolean isFastFileTransferRequested() {
- String fileTransferProp = java.security.AccessController.doPrivileged(new PrivilegedAction() {
- @Override
- public String run() {
- return System.getProperty("jdk.nio.enableFastFileTransfer");
- }
- });
-
- boolean enable;
- if ("".equals(fileTransferProp)) {
- enable = true;
- } else {
- enable = Boolean.parseBoolean(fileTransferProp);
- }
-
- return enable;
- }
-
- static {
- IOUtil.load();
- fastFileTransfer = isFastFileTransferRequested();
- }
-
-}
diff --git a/src/IKVM.Java/local/sun/nio/ch/FileKey.java b/src/IKVM.Java/local/sun/nio/ch/FileKey.java
deleted file mode 100644
index 4feec5d318..0000000000
--- a/src/IKVM.Java/local/sun/nio/ch/FileKey.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- Copyright (C) 2007 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.ch;
-
-import java.io.File;
-import java.io.FileDescriptor;
-import java.io.IOException;
-
-public class FileKey
-{
- private String path;
-
- public static FileKey create(FileDescriptor fd)
- {
- FileKey fk = new FileKey();
- fk.path = ((cli.System.IO.FileStream)fd.getStream()).get_Name();
- try
- {
- fk.path = new File(fk.path).getCanonicalPath();
- }
- catch (IOException x)
- {
- }
- return fk;
- }
-
- public int hashCode()
- {
- return path.hashCode();
- }
-
- public boolean equals(Object obj)
- {
- return obj == this || (obj instanceof FileKey && ((FileKey)obj).path.equals(path));
- }
-}
diff --git a/src/IKVM.Java/local/sun/nio/ch/PipeImpl.java b/src/IKVM.Java/local/sun/nio/ch/PipeImpl.java
deleted file mode 100644
index b86580dcca..0000000000
--- a/src/IKVM.Java/local/sun/nio/ch/PipeImpl.java
+++ /dev/null
@@ -1,184 +0,0 @@
-/*
- * Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation. Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-/*
- */
-
-package sun.nio.ch;
-
-import java.io.IOException;
-import java.net.InetAddress;
-import java.net.InetSocketAddress;
-import java.nio.*;
-import java.nio.channels.*;
-import java.nio.channels.spi.*;
-import java.security.AccessController;
-import java.security.PrivilegedExceptionAction;
-import java.security.PrivilegedActionException;
-import java.util.Random;
-
-
-/**
- * A simple Pipe implementation based on a socket connection.
- */
-
-class PipeImpl
- extends Pipe
-{
-
- // Source and sink channels
- private SourceChannel source;
- private SinkChannel sink;
-
- // Random object for handshake values
- private static final Random rnd;
-
- static {
- byte[] someBytes = new byte[8];
- boolean resultOK = IOUtil.randomBytes(someBytes);
- if (resultOK) {
- rnd = new Random(ByteBuffer.wrap(someBytes).getLong());
- } else {
- rnd = new Random();
- }
- }
-
- private class Initializer
- implements PrivilegedExceptionAction
- {
-
- private final SelectorProvider sp;
-
- private IOException ioe = null;
-
- private Initializer(SelectorProvider sp) {
- this.sp = sp;
- }
-
- @Override
- public Void run() throws IOException {
- LoopbackConnector connector = new LoopbackConnector();
- connector.run();
- if (ioe instanceof ClosedByInterruptException) {
- ioe = null;
- Thread connThread = new Thread(connector) {
- @Override
- public void interrupt() {}
- };
- connThread.start();
- for (;;) {
- try {
- connThread.join();
- break;
- } catch (InterruptedException ex) {}
- }
- Thread.currentThread().interrupt();
- }
-
- if (ioe != null)
- throw new IOException("Unable to establish loopback connection", ioe);
-
- return null;
- }
-
- private class LoopbackConnector implements Runnable {
-
- @Override
- public void run() {
- ServerSocketChannel ssc = null;
- SocketChannel sc1 = null;
- SocketChannel sc2 = null;
-
- try {
- // Loopback address
- InetAddress lb = InetAddress.getByName("127.0.0.1");
- assert(lb.isLoopbackAddress());
- InetSocketAddress sa = null;
- for(;;) {
- // Bind ServerSocketChannel to a port on the loopback
- // address
- if (ssc == null || !ssc.isOpen()) {
- ssc = ServerSocketChannel.open();
- ssc.socket().bind(new InetSocketAddress(lb, 0));
- sa = new InetSocketAddress(lb, ssc.socket().getLocalPort());
- }
-
- // Establish connection (assume connections are eagerly
- // accepted)
- sc1 = SocketChannel.open(sa);
- ByteBuffer bb = ByteBuffer.allocate(8);
- long secret = rnd.nextLong();
- bb.putLong(secret).flip();
- sc1.write(bb);
-
- // Get a connection and verify it is legitimate
- sc2 = ssc.accept();
- bb.clear();
- sc2.read(bb);
- bb.rewind();
- if (bb.getLong() == secret)
- break;
- sc2.close();
- sc1.close();
- }
-
- // Create source and sink channels
- source = new SourceChannelImpl(sp, sc1);
- sink = new SinkChannelImpl(sp, sc2);
- } catch (IOException e) {
- try {
- if (sc1 != null)
- sc1.close();
- if (sc2 != null)
- sc2.close();
- } catch (IOException e2) {}
- ioe = e;
- } finally {
- try {
- if (ssc != null)
- ssc.close();
- } catch (IOException e2) {}
- }
- }
- }
- }
-
- PipeImpl(final SelectorProvider sp) throws IOException {
- try {
- AccessController.doPrivileged(new Initializer(sp));
- } catch (PrivilegedActionException x) {
- throw (IOException)x.getCause();
- }
- }
-
- public SourceChannel source() {
- return source;
- }
-
- public SinkChannel sink() {
- return sink;
- }
-
-}
diff --git a/src/IKVM.Java/local/sun/nio/ch/PollArrayWrapper.java b/src/IKVM.Java/local/sun/nio/ch/PollArrayWrapper.java
deleted file mode 100644
index f05f2b5cd7..0000000000
--- a/src/IKVM.Java/local/sun/nio/ch/PollArrayWrapper.java
+++ /dev/null
@@ -1,87 +0,0 @@
-package sun.nio.ch;
-
-import java.lang.annotation.Native;
-
-/**
- * Manipulates a native array of structs corresponding to (fd, events) pairs.
- *
- * typedef struct pollfd {
- * SOCKET fd; // 4 bytes
- * short events; // 2 bytes
- * } pollfd_t;
- *
- * @author Konstantin Kladko
- * @author Mike McCloskey
- */
-
-class PollArrayWrapper {
-
- private AllocatedNativeObject pollArray; // The fd array
-
- long pollArrayAddress; // pollArrayAddress
-
- @Native private static final short FD_OFFSET = 0; // fd offset in pollfd
- @Native private static final short EVENT_OFFSET = 4; // events offset in pollfd
-
- static short SIZE_POLLFD = 8; // sizeof pollfd struct
-
- private int size; // Size of the pollArray
-
- PollArrayWrapper(int newSize) {
- int allocationSize = newSize * SIZE_POLLFD;
- pollArray = new AllocatedNativeObject(allocationSize, true);
- pollArrayAddress = pollArray.address();
- this.size = newSize;
- }
-
- // Prepare another pollfd struct for use.
- void addEntry(int index, SelectionKeyImpl ski) {
- putDescriptor(index, ski.channel.getFDVal());
- }
-
- // Writes the pollfd entry from the source wrapper at the source index
- // over the entry in the target wrapper at the target index.
- void replaceEntry(PollArrayWrapper source, int sindex, PollArrayWrapper target, int tindex) {
- target.putDescriptor(tindex, source.getDescriptor(sindex));
- target.putEventOps(tindex, source.getEventOps(sindex));
- }
-
- // Grows the pollfd array to new size
- void grow(int newSize) {
- PollArrayWrapper temp = new PollArrayWrapper(newSize);
- for (int i = 0; i < size; i++)
- replaceEntry(this, i, temp, i);
- pollArray.free();
- pollArray = temp.pollArray;
- this.size = temp.size;
- pollArrayAddress = pollArray.address();
- }
-
- void free() {
- pollArray.free();
- }
-
- // Access methods for fd structures
- void putDescriptor(int i, int fd) {
- pollArray.putInt(SIZE_POLLFD * i + FD_OFFSET, fd);
- }
-
- void putEventOps(int i, int event) {
- pollArray.putShort(SIZE_POLLFD * i + EVENT_OFFSET, (short)event);
- }
-
- int getEventOps(int i) {
- return pollArray.getShort(SIZE_POLLFD * i + EVENT_OFFSET);
- }
-
- int getDescriptor(int i) {
- return pollArray.getInt(SIZE_POLLFD * i + FD_OFFSET);
- }
-
- // Adds Windows wakeup socket at a given index.
- void addWakeupSocket(int fdVal, int index) {
- putDescriptor(index, fdVal);
- putEventOps(index, Net.POLLIN);
- }
-
-}
diff --git a/src/IKVM.Java/local/sun/nio/ch/SinkChannelImpl.java b/src/IKVM.Java/local/sun/nio/ch/SinkChannelImpl.java
deleted file mode 100644
index 57e88ac38c..0000000000
--- a/src/IKVM.Java/local/sun/nio/ch/SinkChannelImpl.java
+++ /dev/null
@@ -1,142 +0,0 @@
-/*
- * Copyright (c) 2002, 2006, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation. Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-/*
- */
-
-package sun.nio.ch;
-
-import java.io.IOException;
-import java.io.FileDescriptor;
-import java.nio.ByteBuffer;
-import java.nio.channels.*;
-import java.nio.channels.spi.*;
-
-
-/**
- * Pipe.SinkChannel implementation based on socket connection.
- */
-
-class SinkChannelImpl
- extends Pipe.SinkChannel
- implements SelChImpl
-{
- // The SocketChannel assoicated with this pipe
- SocketChannel sc;
-
- public FileDescriptor getFD() {
- return ((SocketChannelImpl)sc).getFD();
- }
-
- public int getFDVal() {
- return ((SocketChannelImpl)sc).getFDVal();
- }
-
- SinkChannelImpl(SelectorProvider sp, SocketChannel sc) {
- super(sp);
- this.sc = sc;
- }
-
- protected void implCloseSelectableChannel() throws IOException {
- if (!isRegistered())
- kill();
- }
-
- public void kill() throws IOException {
- sc.close();
- }
-
- protected void implConfigureBlocking(boolean block) throws IOException {
- sc.configureBlocking(block);
- }
-
- public boolean translateReadyOps(int ops, int initialOps,
- SelectionKeyImpl sk) {
- int intOps = sk.nioInterestOps(); // Do this just once, it synchronizes
- int oldOps = sk.nioReadyOps();
- int newOps = initialOps;
-
- if ((ops & Net.POLLNVAL) != 0)
- throw new Error("POLLNVAL detected");
-
- if ((ops & (Net.POLLERR | Net.POLLHUP)) != 0) {
- newOps = intOps;
- sk.nioReadyOps(newOps);
- return (newOps & ~oldOps) != 0;
- }
-
- if (((ops & Net.POLLOUT) != 0) &&
- ((intOps & SelectionKey.OP_WRITE) != 0))
- newOps |= SelectionKey.OP_WRITE;
-
- sk.nioReadyOps(newOps);
- return (newOps & ~oldOps) != 0;
- }
-
- public boolean translateAndUpdateReadyOps(int ops, SelectionKeyImpl sk) {
- return translateReadyOps(ops, sk.nioReadyOps(), sk);
- }
-
- public boolean translateAndSetReadyOps(int ops, SelectionKeyImpl sk) {
- return translateReadyOps(ops, 0, sk);
- }
-
- public void translateAndSetInterestOps(int ops, SelectionKeyImpl sk) {
- if ((ops & SelectionKey.OP_WRITE) != 0)
- ops = Net.POLLOUT;
- sk.selector.putEventOps(sk, ops);
- }
-
- public int write(ByteBuffer src) throws IOException {
- try {
- return sc.write(src);
- } catch (AsynchronousCloseException x) {
- close();
- throw x;
- }
- }
-
- public long write(ByteBuffer[] srcs) throws IOException {
- try {
- return sc.write(srcs);
- } catch (AsynchronousCloseException x) {
- close();
- throw x;
- }
- }
-
- public long write(ByteBuffer[] srcs, int offset, int length)
- throws IOException
- {
- if ((offset < 0) || (length < 0) || (offset > srcs.length - length))
- throw new IndexOutOfBoundsException();
- try {
- return write(Util.subsequence(srcs, offset, length));
- } catch (AsynchronousCloseException x) {
- close();
- throw x;
- }
- }
-}
diff --git a/src/IKVM.Java/local/sun/nio/ch/SocketDispatcher.java b/src/IKVM.Java/local/sun/nio/ch/SocketDispatcher.java
deleted file mode 100644
index bfeaf9889f..0000000000
--- a/src/IKVM.Java/local/sun/nio/ch/SocketDispatcher.java
+++ /dev/null
@@ -1,23 +0,0 @@
-package sun.nio.ch;
-
-import java.io.*;
-
-class SocketDispatcher extends NativeDispatcher {
-
- static {
- IOUtil.load();
- }
-
- native int read(FileDescriptor fd, long address, int len) throws IOException;
-
- native long readv(FileDescriptor fd, long address, int len) throws IOException;
-
- native int write(FileDescriptor fd, long address, int len) throws IOException;
-
- native long writev(FileDescriptor fd, long address, int len) throws IOException;
-
- native void preClose(FileDescriptor fd) throws IOException;
-
- native void close(FileDescriptor fd) throws IOException;
-
-}
diff --git a/src/IKVM.Java/local/sun/nio/ch/SocketOptionRegistry.java b/src/IKVM.Java/local/sun/nio/ch/SocketOptionRegistry.java
deleted file mode 100644
index d94d36efeb..0000000000
--- a/src/IKVM.Java/local/sun/nio/ch/SocketOptionRegistry.java
+++ /dev/null
@@ -1,92 +0,0 @@
-package sun.nio.ch;
-
-import java.net.SocketOption;
-import java.net.StandardSocketOptions;
-import java.net.ProtocolFamily;
-import java.net.StandardProtocolFamily;
-import java.util.Map;
-import java.util.HashMap;
-
-import cli.System.Net.Sockets.SocketOptionLevel;
-import cli.System.Net.Sockets.SocketOptionName;
-
-class SocketOptionRegistry
-{
-
- private SocketOptionRegistry()
- {
-
- }
-
- private static class RegistryKey
- {
-
- private final SocketOption> name;
- private final ProtocolFamily family;
-
- RegistryKey(SocketOption> name, ProtocolFamily family)
- {
- this.name = name;
- this.family = family;
- }
-
- public int hashCode()
- {
- return name.hashCode() + family.hashCode();
- }
-
- public boolean equals(Object ob)
- {
- if (ob == null)
- return false;
- if (!(ob instanceof RegistryKey))
- return false;
-
- RegistryKey other = (RegistryKey)ob;
- if (this.name != other.name)
- return false;
- if (this.family != other.family)
- return false;
-
- return true;
- }
-
- }
-
- private static class LazyInitialization
- {
-
- static final Map options = options();
-
- private static Map options()
- {
- Map map = new HashMap();
- map.put(new RegistryKey(StandardSocketOptions.SO_BROADCAST, Net.UNSPEC), new OptionKey(SocketOptionLevel.Socket, SocketOptionName.Broadcast));
- map.put(new RegistryKey(StandardSocketOptions.SO_KEEPALIVE, Net.UNSPEC), new OptionKey(SocketOptionLevel.Socket, SocketOptionName.KeepAlive));
- map.put(new RegistryKey(StandardSocketOptions.SO_LINGER, Net.UNSPEC), new OptionKey(SocketOptionLevel.Socket, SocketOptionName.Linger));
- map.put(new RegistryKey(StandardSocketOptions.SO_SNDBUF, Net.UNSPEC), new OptionKey(SocketOptionLevel.Socket, SocketOptionName.SendBuffer));
- map.put(new RegistryKey(StandardSocketOptions.SO_RCVBUF, Net.UNSPEC), new OptionKey(SocketOptionLevel.Socket, SocketOptionName.ReceiveBuffer));
- map.put(new RegistryKey(StandardSocketOptions.SO_REUSEADDR, Net.UNSPEC), new OptionKey(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress));
- map.put(new RegistryKey(StandardSocketOptions.TCP_NODELAY, Net.UNSPEC), new OptionKey(SocketOptionLevel.Tcp, SocketOptionName.NoDelay));
- map.put(new RegistryKey(StandardSocketOptions.IP_TOS, StandardProtocolFamily.INET), new OptionKey(SocketOptionLevel.IP, SocketOptionName.TypeOfService));
- map.put(new RegistryKey(StandardSocketOptions.IP_MULTICAST_IF, StandardProtocolFamily.INET), new OptionKey(SocketOptionLevel.IP, SocketOptionName.MulticastInterface));
- map.put(new RegistryKey(StandardSocketOptions.IP_MULTICAST_TTL, StandardProtocolFamily.INET), new OptionKey(SocketOptionLevel.IP, SocketOptionName.IpTimeToLive));
- map.put(new RegistryKey(StandardSocketOptions.IP_MULTICAST_LOOP, StandardProtocolFamily.INET), new OptionKey(SocketOptionLevel.IP, SocketOptionName.MulticastLoopback));
- map.put(new RegistryKey(StandardSocketOptions.IP_TOS, StandardProtocolFamily.INET6), new OptionKey(SocketOptionLevel.IPv6, 39)); // TODO this whole file needs to be auto generated for OS
- map.put(new RegistryKey(StandardSocketOptions.IP_MULTICAST_IF, StandardProtocolFamily.INET6), new OptionKey(SocketOptionLevel.IPv6, SocketOptionName.MulticastInterface));
- map.put(new RegistryKey(StandardSocketOptions.IP_MULTICAST_TTL, StandardProtocolFamily.INET6), new OptionKey(SocketOptionLevel.IPv6, SocketOptionName.IpTimeToLive));
- map.put(new RegistryKey(StandardSocketOptions.IP_MULTICAST_LOOP, StandardProtocolFamily.INET6), new OptionKey(SocketOptionLevel.IPv6, SocketOptionName.MulticastLoopback));
- map.put(new RegistryKey(ExtendedSocketOption.SO_OOBINLINE, Net.UNSPEC), new OptionKey(SocketOptionLevel.Socket, SocketOptionName.OutOfBandInline));
- return map;
- }
- }
-
- public static OptionKey findOption(SocketOption> name, ProtocolFamily family)
- {
-
- RegistryKey key = new RegistryKey(name, family);
- return LazyInitialization.options.get(key);
-
- }
-
-}
diff --git a/src/IKVM.Java/local/sun/nio/ch/SourceChannelImpl.java b/src/IKVM.Java/local/sun/nio/ch/SourceChannelImpl.java
deleted file mode 100644
index 2605d61b47..0000000000
--- a/src/IKVM.Java/local/sun/nio/ch/SourceChannelImpl.java
+++ /dev/null
@@ -1,142 +0,0 @@
-/*
- * Copyright (c) 2002, 2006, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation. Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-/*
- */
-
-package sun.nio.ch;
-
-import java.io.IOException;
-import java.io.FileDescriptor;
-import java.nio.ByteBuffer;
-import java.nio.channels.*;
-import java.nio.channels.spi.*;
-
-/**
- * Pipe.SourceChannel implementation based on socket connection.
- */
-
-class SourceChannelImpl
- extends Pipe.SourceChannel
- implements SelChImpl
-{
- // The SocketChannel assoicated with this pipe
- SocketChannel sc;
-
- public FileDescriptor getFD() {
- return ((SocketChannelImpl) sc).getFD();
- }
-
- public int getFDVal() {
- return ((SocketChannelImpl) sc).getFDVal();
- }
-
- SourceChannelImpl(SelectorProvider sp, SocketChannel sc) {
- super(sp);
- this.sc = sc;
- }
-
- protected void implCloseSelectableChannel() throws IOException {
- if (!isRegistered())
- kill();
- }
-
- public void kill() throws IOException {
- sc.close();
- }
-
- protected void implConfigureBlocking(boolean block) throws IOException {
- sc.configureBlocking(block);
- }
-
- public boolean translateReadyOps(int ops, int initialOps,
- SelectionKeyImpl sk) {
- int intOps = sk.nioInterestOps(); // Do this just once, it synchronizes
- int oldOps = sk.nioReadyOps();
- int newOps = initialOps;
-
- if ((ops & Net.POLLNVAL) != 0)
- throw new Error("POLLNVAL detected");
-
- if ((ops & (Net.POLLERR | Net.POLLHUP)) != 0) {
- newOps = intOps;
- sk.nioReadyOps(newOps);
- return (newOps & ~oldOps) != 0;
- }
-
- if (((ops & Net.POLLIN) != 0) &&
- ((intOps & SelectionKey.OP_READ) != 0))
- newOps |= SelectionKey.OP_READ;
-
- sk.nioReadyOps(newOps);
- return (newOps & ~oldOps) != 0;
- }
-
- public boolean translateAndUpdateReadyOps(int ops, SelectionKeyImpl sk) {
- return translateReadyOps(ops, sk.nioReadyOps(), sk);
- }
-
- public boolean translateAndSetReadyOps(int ops, SelectionKeyImpl sk) {
- return translateReadyOps(ops, 0, sk);
- }
-
- public void translateAndSetInterestOps(int ops, SelectionKeyImpl sk) {
- if ((ops & SelectionKey.OP_READ) != 0)
- ops = Net.POLLIN;
- sk.selector.putEventOps(sk, ops);
- }
-
- public int read(ByteBuffer dst) throws IOException {
- try {
- return sc.read(dst);
- } catch (AsynchronousCloseException x) {
- close();
- throw x;
- }
- }
-
- public long read(ByteBuffer[] dsts, int offset, int length)
- throws IOException
- {
- if ((offset < 0) || (length < 0) || (offset > dsts.length - length))
- throw new IndexOutOfBoundsException();
- try {
- return read(Util.subsequence(dsts, offset, length));
- } catch (AsynchronousCloseException x) {
- close();
- throw x;
- }
- }
-
- public long read(ByteBuffer[] dsts) throws IOException {
- try {
- return sc.read(dsts);
- } catch (AsynchronousCloseException x) {
- close();
- throw x;
- }
- }
-
-}
diff --git a/src/IKVM.Java/local/sun/nio/ch/sctp/SctpChannelImpl.java b/src/IKVM.Java/local/sun/nio/ch/sctp/SctpChannelImpl.java
deleted file mode 100644
index 53ac4846d8..0000000000
--- a/src/IKVM.Java/local/sun/nio/ch/sctp/SctpChannelImpl.java
+++ /dev/null
@@ -1,115 +0,0 @@
-package sun.nio.ch.sctp;
-
-import java.net.SocketAddress;
-import java.net.InetAddress;
-import java.io.IOException;
-import java.util.Set;
-import java.nio.ByteBuffer;
-import java.nio.channels.spi.SelectorProvider;
-
-import com.sun.nio.sctp.Association;
-import com.sun.nio.sctp.MessageInfo;
-import com.sun.nio.sctp.NotificationHandler;
-import com.sun.nio.sctp.SctpChannel;
-import com.sun.nio.sctp.SctpSocketOption;
-
-public class SctpChannelImpl extends SctpChannel {
-
- private static final String message = "SCTP not supported on this platform";
-
- public SctpChannelImpl(SelectorProvider provider) {
- super(provider);
- throw new UnsupportedOperationException(message);
- }
-
- @Override
- public Association association() {
- throw new UnsupportedOperationException(message);
- }
-
- @Override
- public SctpChannel bind(SocketAddress local) throws IOException {
- throw new UnsupportedOperationException(message);
- }
-
- @Override
- public SctpChannel bindAddress(InetAddress address) throws IOException {
- throw new UnsupportedOperationException(message);
- }
-
- @Override
- public SctpChannel unbindAddress(InetAddress address) throws IOException {
- throw new UnsupportedOperationException(message);
- }
-
- @Override
- public boolean connect(SocketAddress remote) throws IOException {
- throw new UnsupportedOperationException(message);
- }
-
- @Override
- public boolean connect(SocketAddress remote, int maxOutStreams, int maxInStreams) throws IOException {
- throw new UnsupportedOperationException(message);
- }
-
- @Override
- public boolean isConnectionPending() {
- throw new UnsupportedOperationException(message);
- }
-
- @Override
- public boolean finishConnect() throws IOException {
- throw new UnsupportedOperationException(message);
- }
-
- @Override
- public Set getAllLocalAddresses() throws IOException {
- throw new UnsupportedOperationException(message);
- }
-
- @Override
- public Set getRemoteAddresses() throws IOException {
- throw new UnsupportedOperationException(message);
- }
-
- @Override
- public SctpChannel shutdown() throws IOException {
- throw new UnsupportedOperationException(message);
- }
-
- @Override
- public T getOption(SctpSocketOption name) throws IOException {
- throw new UnsupportedOperationException(message);
- }
-
- @Override
- public SctpChannel setOption(SctpSocketOption name, T value) throws IOException {
- throw new UnsupportedOperationException(message);
- }
-
- @Override
- public Set> supportedOptions() {
- throw new UnsupportedOperationException(message);
- }
-
- @Override
- public MessageInfo receive(ByteBuffer dst, T attachment, NotificationHandler handler) throws IOException {
- throw new UnsupportedOperationException(message);
- }
-
- @Override
- public int send(ByteBuffer src, MessageInfo messageInfo) throws IOException {
- throw new UnsupportedOperationException(message);
- }
-
- @Override
- protected void implConfigureBlocking(boolean block) throws IOException {
- throw new UnsupportedOperationException(message);
- }
-
- @Override
- public void implCloseSelectableChannel() throws IOException {
- throw new UnsupportedOperationException(message);
- }
-
-}
diff --git a/src/IKVM.Java/local/sun/nio/ch/sctp/SctpMultiChannelImpl.java b/src/IKVM.Java/local/sun/nio/ch/sctp/SctpMultiChannelImpl.java
deleted file mode 100644
index bab2870f5a..0000000000
--- a/src/IKVM.Java/local/sun/nio/ch/sctp/SctpMultiChannelImpl.java
+++ /dev/null
@@ -1,101 +0,0 @@
-package sun.nio.ch.sctp;
-
-import java.net.SocketAddress;
-import java.net.InetAddress;
-import java.io.IOException;
-import java.util.Set;
-import java.nio.ByteBuffer;
-import java.nio.channels.spi.SelectorProvider;
-
-import com.sun.nio.sctp.Association;
-import com.sun.nio.sctp.SctpChannel;
-import com.sun.nio.sctp.MessageInfo;
-import com.sun.nio.sctp.NotificationHandler;
-import com.sun.nio.sctp.SctpMultiChannel;
-import com.sun.nio.sctp.SctpSocketOption;
-
-public class SctpMultiChannelImpl extends SctpMultiChannel {
-
- private static final String message = "SCTP not supported on this platform";
-
- public SctpMultiChannelImpl(SelectorProvider provider) {
- super(provider);
- throw new UnsupportedOperationException(message);
- }
-
- @Override
- public Set associations() {
- throw new UnsupportedOperationException(message);
- }
-
- @Override
- public SctpMultiChannel bind(SocketAddress local, int backlog) throws IOException {
- throw new UnsupportedOperationException(message);
- }
-
- @Override
- public SctpMultiChannel bindAddress(InetAddress address) throws IOException {
- throw new UnsupportedOperationException(message);
- }
-
- @Override
- public SctpMultiChannel unbindAddress(InetAddress address) throws IOException {
- throw new UnsupportedOperationException(message);
- }
-
- @Override
- public Set getAllLocalAddresses() throws IOException {
- throw new UnsupportedOperationException(message);
- }
-
- @Override
- public Set getRemoteAddresses (Association association) throws IOException {
- throw new UnsupportedOperationException(message);
- }
-
- @Override
- public SctpMultiChannel shutdown(Association association) throws IOException {
- throw new UnsupportedOperationException(message);
- }
-
- @Override
- public T getOption(SctpSocketOption name, Association association) throws IOException {
- throw new UnsupportedOperationException(message);
- }
-
- @Override
- public SctpMultiChannel setOption(SctpSocketOption name, T value, Association association) throws IOException {
- throw new UnsupportedOperationException(message);
- }
-
- @Override
- public Set> supportedOptions() {
- throw new UnsupportedOperationException(message);
- }
-
- @Override
- public MessageInfo receive(ByteBuffer buffer, T attachment, NotificationHandler handler) throws IOException {
- throw new UnsupportedOperationException(message);
- }
-
- @Override
- public int send(ByteBuffer buffer, MessageInfo messageInfo) throws IOException {
- throw new UnsupportedOperationException(message);
- }
-
- @Override
- public SctpChannel branch(Association association) throws IOException {
- throw new UnsupportedOperationException(message);
- }
-
- @Override
- protected void implConfigureBlocking(boolean block) throws IOException {
- throw new UnsupportedOperationException(message);
- }
-
- @Override
- public void implCloseSelectableChannel() throws IOException {
- throw new UnsupportedOperationException(message);
- }
-
-}
diff --git a/src/IKVM.Java/local/sun/nio/ch/sctp/SctpServerChannelImpl.java b/src/IKVM.Java/local/sun/nio/ch/sctp/SctpServerChannelImpl.java
deleted file mode 100644
index d8b1afbfb4..0000000000
--- a/src/IKVM.Java/local/sun/nio/ch/sctp/SctpServerChannelImpl.java
+++ /dev/null
@@ -1,72 +0,0 @@
-package sun.nio.ch.sctp;
-
-import java.net.SocketAddress;
-import java.net.InetAddress;
-import java.io.IOException;
-import java.util.Set;
-import java.nio.channels.spi.SelectorProvider;
-
-import com.sun.nio.sctp.SctpChannel;
-import com.sun.nio.sctp.SctpServerChannel;
-import com.sun.nio.sctp.SctpSocketOption;
-
-public class SctpServerChannelImpl extends SctpServerChannel {
-
- private static final String message = "SCTP not supported on this platform";
-
- public SctpServerChannelImpl(SelectorProvider provider) {
- super(provider);
- throw new UnsupportedOperationException(message);
- }
-
- @Override
- public SctpChannel accept() throws IOException {
- throw new UnsupportedOperationException(message);
- }
-
- @Override
- public SctpServerChannel bind(SocketAddress local, int backlog) throws IOException {
- throw new UnsupportedOperationException(message);
- }
-
- @Override
- public SctpServerChannel bindAddress(InetAddress address) throws IOException {
- throw new UnsupportedOperationException(message);
- }
-
- @Override
- public SctpServerChannel unbindAddress(InetAddress address) throws IOException {
- throw new UnsupportedOperationException(message);
- }
-
- @Override
- public Set getAllLocalAddresses() throws IOException {
- throw new UnsupportedOperationException(message);
- }
-
- @Override
- public T getOption(SctpSocketOption name) throws IOException {
- throw new UnsupportedOperationException(message);
- }
-
- @Override
- public SctpServerChannel setOption(SctpSocketOption name, T value) throws IOException {
- throw new UnsupportedOperationException(message);
- }
-
- @Override
- public Set> supportedOptions() {
- throw new UnsupportedOperationException(message);
- }
-
- @Override
- protected void implConfigureBlocking(boolean block) throws IOException {
- throw new UnsupportedOperationException(message);
- }
-
- @Override
- public void implCloseSelectableChannel() throws IOException {
- throw new UnsupportedOperationException(message);
- }
-
-}
diff --git a/src/IKVM.Java/local/sun/nio/fs/DefaultFileSystemProvider.java b/src/IKVM.Java/local/sun/nio/fs/DefaultFileSystemProvider.java
deleted file mode 100644
index e8eea74c82..0000000000
--- a/src/IKVM.Java/local/sun/nio/fs/DefaultFileSystemProvider.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package sun.nio.fs;
-
-import java.nio.file.spi.FileSystemProvider;
-
-public class DefaultFileSystemProvider {
-
- public static FileSystemProvider create() {
- return new DotNetFileSystemProvider();
-
- //if (cli.IKVM.Runtime.RuntimeUtil.get_IsWindows()) {
- // return new WindowsFileSystemProvider();
- //} else if (cli.IKVM.Runtime.RuntimeUtil.get_IsLinux()) {
- // return new LinuxFileSystemProvider();
- //} else {
- // return new DotNetFileSystemProvider();
- //}
- }
-
-}
diff --git a/src/IKVM.Java/local/sun/nio/fs/DefaultFileTypeDetector.java b/src/IKVM.Java/local/sun/nio/fs/DefaultFileTypeDetector.java
deleted file mode 100644
index f488b3fc26..0000000000
--- a/src/IKVM.Java/local/sun/nio/fs/DefaultFileTypeDetector.java
+++ /dev/null
@@ -1,32 +0,0 @@
-package sun.nio.fs;
-
-import java.io.IOException;
-import java.nio.file.FileSystems;
-import java.nio.file.Path;
-import java.nio.file.spi.FileTypeDetector;
-import java.nio.file.spi.FileSystemProvider;
-
-public class DefaultFileTypeDetector {
-
- public static FileTypeDetector create() {
- return new AbstractFileTypeDetector() {
- public String implProbeContentType(Path obj) throws IOException {
- return null;
- }
- };
-
- //FileSystemProvider provider = FileSystems.getDefault().provider();
- //if (provider instanceof UnixFileSystemProvider) {
- // return ((UnixFileSystemProvider)provider).getFileTypeDetector();
- //} else if (cli.IKVM.Runtime.RuntimeUtil.get_IsWindows()) {
- // return new RegistryFileTypeDetector();
- //} else {
- // return new AbstractFileTypeDetector() {
- // public String implProbeContentType(Path obj) throws IOException {
- // return null;
- // }
- // };
- //}
- }
-
-}
diff --git a/src/IKVM.Java/local/sun/nio/fs/DotNetBasicFileAttributeView.java b/src/IKVM.Java/local/sun/nio/fs/DotNetBasicFileAttributeView.java
deleted file mode 100644
index 4002df5f67..0000000000
--- a/src/IKVM.Java/local/sun/nio/fs/DotNetBasicFileAttributeView.java
+++ /dev/null
@@ -1,29 +0,0 @@
-package sun.nio.fs;
-
-import java.io.*;
-import java.nio.file.*;
-import java.nio.file.attribute.*;
-
-class DotNetBasicFileAttributeView extends AbstractBasicFileAttributeView {
-
- static cli.System.DateTime toDateTime(FileTime fileTime) {
- if (fileTime != null) {
- return new cli.System.DateTime(fileTime.to(java.util.concurrent.TimeUnit.MICROSECONDS) * 10 + 621355968000000000L);
- } else {
- return cli.System.DateTime.MinValue;
- }
- }
-
- protected final String path;
-
- DotNetBasicFileAttributeView(String path) {
- this.path = path;
- }
-
- public BasicFileAttributes readAttributes() throws IOException {
- return DotNetDosFileAttributes.read(path);
- }
-
- public native void setTimes(FileTime lastModifiedTime, FileTime lastAccessTime, FileTime createTime) throws IOException;
-
-}
diff --git a/src/IKVM.Java/local/sun/nio/fs/DotNetDirectoryStream.java b/src/IKVM.Java/local/sun/nio/fs/DotNetDirectoryStream.java
deleted file mode 100644
index e1b07bae1b..0000000000
--- a/src/IKVM.Java/local/sun/nio/fs/DotNetDirectoryStream.java
+++ /dev/null
@@ -1,24 +0,0 @@
-package sun.nio.fs;
-
-import java.util.*;
-import java.nio.file.*;
-
-final class DotNetDirectoryStream implements DirectoryStream {
-
- private final DotNetPath path;
- private final cli.System.Collections.IEnumerable files;
- private final DirectoryStream.Filter filter;
-
- DotNetDirectoryStream(final DotNetPath path, final cli.System.Collections.IEnumerable files, final DirectoryStream.Filter filter) {
- this.path = path;
- this.files = files;
- this.filter = filter;
- }
-
- @Override
- public native Iterator iterator();
-
- @Override
- public native void close();
-
-}
diff --git a/src/IKVM.Java/local/sun/nio/fs/DotNetDosFileAttributeView.java b/src/IKVM.Java/local/sun/nio/fs/DotNetDosFileAttributeView.java
deleted file mode 100644
index 13040f5880..0000000000
--- a/src/IKVM.Java/local/sun/nio/fs/DotNetDosFileAttributeView.java
+++ /dev/null
@@ -1,96 +0,0 @@
-package sun.nio.fs;
-
-import java.io.*;
-import java.nio.file.*;
-import java.nio.file.attribute.*;
-import java.util.*;
-
-import cli.System.IO.FileInfo;
-
-class DotNetDosFileAttributeView extends DotNetBasicFileAttributeView implements DosFileAttributeView {
-
- private static final String READONLY_NAME = "readonly";
- private static final String ARCHIVE_NAME = "archive";
- private static final String SYSTEM_NAME = "system";
- private static final String HIDDEN_NAME = "hidden";
- private static final Set dosAttributeNames = Util.newSet(basicAttributeNames, READONLY_NAME, ARCHIVE_NAME, SYSTEM_NAME, HIDDEN_NAME);
-
- DotNetDosFileAttributeView(String path) {
- super(path);
- }
-
- public String name() {
- return "dos";
- }
-
- public DosFileAttributes readAttributes() throws IOException {
- return DotNetDosFileAttributes.read(path);
- }
-
- public void setArchive(boolean value) throws IOException {
- setAttribute(cli.System.IO.FileAttributes.Archive, value);
- }
-
- public void setHidden(boolean value) throws IOException {
- setAttribute(cli.System.IO.FileAttributes.Hidden, value);
- }
-
- public void setReadOnly(boolean value) throws IOException {
- setAttribute(cli.System.IO.FileAttributes.ReadOnly, value);
- }
-
- public void setSystem(boolean value) throws IOException {
- setAttribute(cli.System.IO.FileAttributes.System, value);
- }
-
- private void setAttribute(int attr, boolean value) throws IOException {
- setAttribute0(path, attr, value);
- }
-
- private static native void setAttribute0(String path, int attr, boolean value) throws IOException;
-
- public Map readAttributes(String[] attributes) throws IOException {
- AttributesBuilder builder = AttributesBuilder.create(dosAttributeNames, attributes);
- DotNetDosFileAttributes attrs = DotNetDosFileAttributes.read(path);
- addRequestedBasicAttributes(attrs, builder);
-
- if (builder.match(READONLY_NAME)) {
- builder.add(READONLY_NAME, attrs.isReadOnly());
- }
-
- if (builder.match(ARCHIVE_NAME)) {
- builder.add(ARCHIVE_NAME, attrs.isArchive());
- }
-
- if (builder.match(SYSTEM_NAME)) {
- builder.add(SYSTEM_NAME, attrs.isSystem());
- }
-
- if (builder.match(HIDDEN_NAME)) {
- builder.add(HIDDEN_NAME, attrs.isHidden());
- }
-
- return builder.unmodifiableMap();
- }
-
- public void setAttribute(String attribute, Object value) throws IOException {
- switch (attribute) {
- case READONLY_NAME:
- setReadOnly((Boolean)value);
- break;
- case ARCHIVE_NAME:
- setArchive((Boolean)value);
- break;
- case SYSTEM_NAME:
- setSystem((Boolean)value);
- break;
- case HIDDEN_NAME:
- setHidden((Boolean)value);
- break;
- default:
- super.setAttribute(attribute, value);
- break;
- }
- }
-
-}
diff --git a/src/IKVM.Java/local/sun/nio/fs/DotNetDosFileAttributes.java b/src/IKVM.Java/local/sun/nio/fs/DotNetDosFileAttributes.java
deleted file mode 100644
index bd9a97e8ca..0000000000
--- a/src/IKVM.Java/local/sun/nio/fs/DotNetDosFileAttributes.java
+++ /dev/null
@@ -1,94 +0,0 @@
-package sun.nio.fs;
-
-import java.io.*;
-import java.nio.file.*;
-import java.nio.file.attribute.*;
-import java.util.*;
-
-class DotNetDosFileAttributes implements DosFileAttributes {
-
- public native static DotNetDosFileAttributes read(String path) throws IOException;
-
- private final FileTime creationTime;
- private final FileTime lastAccessTime;
- private final FileTime lastModifiedTime;
- private Object fileKey;
- private boolean isDirectory;
- private boolean isOther;
- private boolean isRegularFile;
- private boolean isSymbolicLink;
- private long size;
- private boolean isReadOnly;
- private boolean isHidden;
- private boolean isArchive;
- private boolean isSystem;
-
- public DotNetDosFileAttributes(FileTime creationTime, FileTime lastAccessTime, FileTime lastModifiedTime, Object fileKey, boolean isDirectory, boolean isOther, boolean isRegularFile, boolean isSymbolicLink, long size, boolean isReadOnly, boolean isHidden, boolean isArchive, boolean isSystem) {
- this.creationTime = creationTime;
- this.lastAccessTime = lastAccessTime;
- this.lastModifiedTime = lastModifiedTime;
- this.fileKey = fileKey;
- this.isDirectory = isDirectory;
- this.isOther = isOther;
- this.isRegularFile = isRegularFile;
- this.isSymbolicLink = isSymbolicLink;
- this.size = size;
- this.isReadOnly = isReadOnly;
- this.isHidden = isHidden;
- this.isArchive = isArchive;
- this.isSystem = isSystem;
- }
-
- public FileTime creationTime() {
- return creationTime;
- }
-
- public FileTime lastAccessTime() {
- return lastAccessTime;
- }
-
- public FileTime lastModifiedTime() {
- return lastModifiedTime;
- }
-
- public Object fileKey() {
- return fileKey;
- }
-
- public boolean isDirectory() {
- return isDirectory;
- }
-
- public boolean isOther() {
- return isOther;
- }
-
- public boolean isRegularFile() {
- return isRegularFile;
- }
-
- public boolean isSymbolicLink() {
- return isSymbolicLink;
- }
-
- public long size() {
- return size;
- }
-
- public boolean isReadOnly() {
- return isReadOnly;
- }
-
- public boolean isHidden() {
- return isHidden;
- }
-
- public boolean isArchive() {
- return isArchive;
- }
-
- public boolean isSystem() {
- return isSystem;
- }
-
-}
diff --git a/src/IKVM.Java/local/sun/nio/fs/DotNetFileSystem.java b/src/IKVM.Java/local/sun/nio/fs/DotNetFileSystem.java
deleted file mode 100644
index 250d354979..0000000000
--- a/src/IKVM.Java/local/sun/nio/fs/DotNetFileSystem.java
+++ /dev/null
@@ -1,446 +0,0 @@
-/*
- 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 cli.System.IO.DriveInfo;
-import cli.System.IO.ErrorEventArgs;
-import cli.System.IO.ErrorEventHandler;
-import cli.System.IO.FileSystemEventArgs;
-import cli.System.IO.FileSystemEventHandler;
-import cli.System.IO.FileSystemWatcher;
-import cli.System.IO.WatcherChangeTypes;
-
-import java.io.IOException;
-import java.nio.file.*;
-import java.nio.file.attribute.*;
-import java.nio.file.spi.FileSystemProvider;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.concurrent.LinkedBlockingQueue;
-import java.util.concurrent.TimeUnit;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-import java.util.regex.Pattern;
-
-final class DotNetFileSystem extends FileSystem {
-
- private static final Set attributes = Collections.unmodifiableSet(new HashSet(Arrays.asList("basic")));
- private final DotNetFileSystemProvider provider;
- private final String separator = Character.toString(cli.System.IO.Path.DirectorySeparatorChar);
-
- DotNetFileSystem(DotNetFileSystemProvider 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 getRootDirectories() {
- SecurityManager sm = System.getSecurityManager();
- ArrayList list = new ArrayList<>();
- for (DriveInfo info : DriveInfo.GetDrives()) {
- try {
- if (sm != null) {
- sm.checkRead(info.get_Name());
- }
- } catch (SecurityException _) {
- continue;
- }
-
- list.add(getPath(info.get_Name()));
- }
-
- return list;
- }
-
- public Iterable getFileStores() {
- SecurityManager sm = System.getSecurityManager();
- if (sm != null) {
- try {
- sm.checkPermission(new RuntimePermission("getFileStoreAttributes"));
- } catch (SecurityException _) {
- return Collections.emptyList();
- }
- }
-
- ArrayList list = new ArrayList<>();
- for (DriveInfo info : DriveInfo.GetDrives()) {
- try {
- if (sm != null) {
- sm.checkRead(info.get_Name());
- }
- } catch (SecurityException _) {
- continue;
- }
- try {
- list.add(provider.getFileStore(info));
- } catch (IOException _) {
-
- }
- }
-
- return list;
- }
-
- public Set supportedFileAttributeViews() {
- return attributes;
- }
-
- public Path getPath(String first, String... more) {
- if (more.length == 0) {
- return new DotNetPath(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 DotNetPath(this, sb.toString());
- }
- }
-
- public PathMatcher getPathMatcher(String syntaxAndPattern) {
- String regex;
- if (syntaxAndPattern.startsWith("glob:")) {
- String pattern = syntaxAndPattern.substring(5);
- if (cli.IKVM.Runtime.RuntimeUtil.get_IsWindows()) {
- regex = Globs.toWindowsRegexPattern(pattern);
- } else {
- regex = Globs.toUnixRegexPattern(pattern);
- }
- } else if (syntaxAndPattern.startsWith("regex:")) {
- regex = syntaxAndPattern.substring(6);
- } else if (syntaxAndPattern.indexOf(':') <= 0) {
- throw new IllegalArgumentException();
- } else {
- throw new UnsupportedOperationException();
- }
-
- final Pattern pattern = Pattern.compile(regex, cli.IKVM.Runtime.RuntimeUtil.get_IsWindows() ? Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE : 0);
- return new PathMatcher() {
- @Override
- public boolean matches(Path path) {
- return pattern.matcher(path.toString()).matches();
- }
- };
- }
-
- public UserPrincipalLookupService getUserPrincipalLookupService() {
- throw new UnsupportedOperationException();
- }
-
- static final class NetWatchService implements WatchService {
-
- static final WatchEvent> overflowEvent = new WatchEvent