jdk/src/share/classes/sun/nio/ch/Secrets.java
author alanb
Wed, 06 Apr 2011 20:51:55 +0100
changeset 9237 cbb5753e87e7
parent 6525 56be41b86ef8
permissions -rw-r--r--
7034155: (ch) NullPointerException in sun.io.ch.IOUtil when OOM is thrown Reviewed-by: forax
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6525
56be41b86ef8 6965072: Need API to create SDP sockets
alanb
parents:
diff changeset
     1
/*
56be41b86ef8 6965072: Need API to create SDP sockets
alanb
parents:
diff changeset
     2
 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
56be41b86ef8 6965072: Need API to create SDP sockets
alanb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
56be41b86ef8 6965072: Need API to create SDP sockets
alanb
parents:
diff changeset
     4
 *
56be41b86ef8 6965072: Need API to create SDP sockets
alanb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
56be41b86ef8 6965072: Need API to create SDP sockets
alanb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
56be41b86ef8 6965072: Need API to create SDP sockets
alanb
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
56be41b86ef8 6965072: Need API to create SDP sockets
alanb
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
56be41b86ef8 6965072: Need API to create SDP sockets
alanb
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
56be41b86ef8 6965072: Need API to create SDP sockets
alanb
parents:
diff changeset
    10
 *
56be41b86ef8 6965072: Need API to create SDP sockets
alanb
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
56be41b86ef8 6965072: Need API to create SDP sockets
alanb
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
56be41b86ef8 6965072: Need API to create SDP sockets
alanb
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
56be41b86ef8 6965072: Need API to create SDP sockets
alanb
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
56be41b86ef8 6965072: Need API to create SDP sockets
alanb
parents:
diff changeset
    15
 * accompanied this code).
56be41b86ef8 6965072: Need API to create SDP sockets
alanb
parents:
diff changeset
    16
 *
56be41b86ef8 6965072: Need API to create SDP sockets
alanb
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
56be41b86ef8 6965072: Need API to create SDP sockets
alanb
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
56be41b86ef8 6965072: Need API to create SDP sockets
alanb
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
56be41b86ef8 6965072: Need API to create SDP sockets
alanb
parents:
diff changeset
    20
 *
56be41b86ef8 6965072: Need API to create SDP sockets
alanb
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
56be41b86ef8 6965072: Need API to create SDP sockets
alanb
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
56be41b86ef8 6965072: Need API to create SDP sockets
alanb
parents:
diff changeset
    23
 * questions.
56be41b86ef8 6965072: Need API to create SDP sockets
alanb
parents:
diff changeset
    24
 */
56be41b86ef8 6965072: Need API to create SDP sockets
alanb
parents:
diff changeset
    25
56be41b86ef8 6965072: Need API to create SDP sockets
alanb
parents:
diff changeset
    26
package sun.nio.ch;
56be41b86ef8 6965072: Need API to create SDP sockets
alanb
parents:
diff changeset
    27
56be41b86ef8 6965072: Need API to create SDP sockets
alanb
parents:
diff changeset
    28
import java.nio.channels.SocketChannel;
56be41b86ef8 6965072: Need API to create SDP sockets
alanb
parents:
diff changeset
    29
import java.nio.channels.ServerSocketChannel;
56be41b86ef8 6965072: Need API to create SDP sockets
alanb
parents:
diff changeset
    30
import java.nio.channels.spi.SelectorProvider;
56be41b86ef8 6965072: Need API to create SDP sockets
alanb
parents:
diff changeset
    31
import java.io.FileDescriptor;
56be41b86ef8 6965072: Need API to create SDP sockets
alanb
parents:
diff changeset
    32
import java.io.IOException;
56be41b86ef8 6965072: Need API to create SDP sockets
alanb
parents:
diff changeset
    33
56be41b86ef8 6965072: Need API to create SDP sockets
alanb
parents:
diff changeset
    34
/**
56be41b86ef8 6965072: Need API to create SDP sockets
alanb
parents:
diff changeset
    35
 * Provides access to implementation private constructors and methods.
56be41b86ef8 6965072: Need API to create SDP sockets
alanb
parents:
diff changeset
    36
 */
56be41b86ef8 6965072: Need API to create SDP sockets
alanb
parents:
diff changeset
    37
56be41b86ef8 6965072: Need API to create SDP sockets
alanb
parents:
diff changeset
    38
public final class Secrets {
56be41b86ef8 6965072: Need API to create SDP sockets
alanb
parents:
diff changeset
    39
    private Secrets() { }
56be41b86ef8 6965072: Need API to create SDP sockets
alanb
parents:
diff changeset
    40
56be41b86ef8 6965072: Need API to create SDP sockets
alanb
parents:
diff changeset
    41
    private static SelectorProvider provider() {
56be41b86ef8 6965072: Need API to create SDP sockets
alanb
parents:
diff changeset
    42
        SelectorProvider p = SelectorProvider.provider();
56be41b86ef8 6965072: Need API to create SDP sockets
alanb
parents:
diff changeset
    43
        if (!(p instanceof SelectorProviderImpl))
56be41b86ef8 6965072: Need API to create SDP sockets
alanb
parents:
diff changeset
    44
            throw new UnsupportedOperationException();
56be41b86ef8 6965072: Need API to create SDP sockets
alanb
parents:
diff changeset
    45
        return p;
56be41b86ef8 6965072: Need API to create SDP sockets
alanb
parents:
diff changeset
    46
    }
56be41b86ef8 6965072: Need API to create SDP sockets
alanb
parents:
diff changeset
    47
56be41b86ef8 6965072: Need API to create SDP sockets
alanb
parents:
diff changeset
    48
    public static SocketChannel newSocketChannel(FileDescriptor fd) {
56be41b86ef8 6965072: Need API to create SDP sockets
alanb
parents:
diff changeset
    49
        try {
56be41b86ef8 6965072: Need API to create SDP sockets
alanb
parents:
diff changeset
    50
            return new SocketChannelImpl(provider(), fd, false);
56be41b86ef8 6965072: Need API to create SDP sockets
alanb
parents:
diff changeset
    51
        } catch (IOException ioe) {
56be41b86ef8 6965072: Need API to create SDP sockets
alanb
parents:
diff changeset
    52
            throw new AssertionError(ioe);
56be41b86ef8 6965072: Need API to create SDP sockets
alanb
parents:
diff changeset
    53
        }
56be41b86ef8 6965072: Need API to create SDP sockets
alanb
parents:
diff changeset
    54
    }
56be41b86ef8 6965072: Need API to create SDP sockets
alanb
parents:
diff changeset
    55
56be41b86ef8 6965072: Need API to create SDP sockets
alanb
parents:
diff changeset
    56
    public static ServerSocketChannel newServerSocketChannel(FileDescriptor fd) {
56be41b86ef8 6965072: Need API to create SDP sockets
alanb
parents:
diff changeset
    57
        try {
56be41b86ef8 6965072: Need API to create SDP sockets
alanb
parents:
diff changeset
    58
            return new ServerSocketChannelImpl(provider(), fd, false);
56be41b86ef8 6965072: Need API to create SDP sockets
alanb
parents:
diff changeset
    59
        } catch (IOException ioe) {
56be41b86ef8 6965072: Need API to create SDP sockets
alanb
parents:
diff changeset
    60
            throw new AssertionError(ioe);
56be41b86ef8 6965072: Need API to create SDP sockets
alanb
parents:
diff changeset
    61
        }
56be41b86ef8 6965072: Need API to create SDP sockets
alanb
parents:
diff changeset
    62
    }
56be41b86ef8 6965072: Need API to create SDP sockets
alanb
parents:
diff changeset
    63
}