0N/A/*
2362N/A * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A/*
0N/A *
0N/A *
0N/A * A collection of utility methods used by the SelectorProvider.inheritedChannel
0N/A * unit tests.
0N/A */
0N/Aimport java.net.*;
0N/Aimport java.io.*;
0N/Aimport java.nio.channels.*;
0N/Aimport java.lang.reflect.*;
0N/A
0N/A// dependency on Sun implementation
0N/Aimport sun.nio.ch.*;
0N/A
0N/Apublic class Util {
0N/A
0N/A private static Object get(String className, String fieldName, Object o) throws Exception {
0N/A Class cl = Class.forName(className);
0N/A Field fld = cl.getDeclaredField(fieldName);
0N/A fld.setAccessible(true);
0N/A return fld.get(o);
0N/A }
0N/A
0N/A private static int fdVal(FileDescriptor fdObj) throws Exception {
0N/A Object fdVal = get("java.io.FileDescriptor", "fd", fdObj);
0N/A return ((Integer)fdVal).intValue();
0N/A }
0N/A
0N/A /*
0N/A * Return the file descriptor underlying a given SocketChannel
0N/A */
0N/A public static int getFD(SocketChannel sc) {
0N/A try {
0N/A Object fdObj = get("sun.nio.ch.SocketChannelImpl", "fd", sc);
0N/A return fdVal((FileDescriptor)fdObj);
0N/A } catch (Exception x) {
0N/A x.printStackTrace();
0N/A throw new InternalError(x.getMessage());
0N/A }
0N/A }
0N/A
0N/A /*
0N/A * Return the file descriptor underlying a given ServerSocketChannel
0N/A */
0N/A public static int getFD(ServerSocketChannel ssc) {
0N/A try {
0N/A Object fdObj = get("sun.nio.ch.ServerSocketChannelImpl", "fd", ssc);
0N/A return fdVal((FileDescriptor)fdObj);
0N/A } catch (Exception x) {
0N/A x.printStackTrace();
0N/A throw new InternalError(x.getMessage());
0N/A }
0N/A }
0N/A
0N/A /*
0N/A * Return the file descriptor underlying a given DatagramChannel
0N/A */
0N/A public static int getFD(DatagramChannel dc) {
0N/A try {
0N/A Object fdObj = get("sun.nio.ch.DatagramChannelImpl", "fd", dc);
0N/A return fdVal((FileDescriptor)fdObj);
0N/A } catch (Exception x) {
0N/A x.printStackTrace();
0N/A throw new InternalError(x.getMessage());
0N/A }
0N/A }
0N/A
0N/A /*
0N/A * Return the "java" command and any initial arguments to start the runtime
0N/A * in the current configuration.
0N/A *
0N/A * Typically it will return something like :-
0N/A * cmd[0] = "/usr/local/java/solaris-sparc/bin/java"
0N/A * or
0N/A * cmd[0] = "/usr/local/java/solaris-sparc/bin/sparcv9/java"
0N/A * cmd[1] = "-d64"
0N/A */
0N/A public static String[] javaCommand() {
0N/A String exe = System.getProperty("java.home") + File.separator + "bin" +
0N/A File.separator;
0N/A String arch = System.getProperty("os.arch");
0N/A if (arch.equals("sparcv9")) {
0N/A String cmd[] = new String[2];
0N/A cmd[0] = exe + "sparcv9/java";
0N/A cmd[1] = "-d64";
0N/A return cmd;
0N/A } else {
0N/A String cmd[] = new String[1];
0N/A cmd[0] = exe += "java";
0N/A return cmd;
0N/A }
0N/A }
0N/A}