|
Java example source code file (SNIServerName.java)
The SNIServerName.java Java example source code/* * Copyright (c) 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 javax.net.ssl; import java.util.Arrays; /** * Instances of this class represent a server name in a Server Name * Indication (SNI) extension. * <P> * The SNI extension is a feature that extends the SSL/TLS protocols to * indicate what server name the client is attempting to connect to during * handshaking. See section 3, "Server Name Indication", of <A * HREF="http://www.ietf.org/rfc/rfc6066.txt">TLS Extensions (RFC 6066)</A>. * <P> * {@code SNIServerName} objects are immutable. Subclasses should not provide * methods that can change the state of an instance once it has been created. * * @see SSLParameters#getServerNames() * @see SSLParameters#setServerNames(List) * * @since 1.8 */ public abstract class SNIServerName { // the type of the server name private final int type; // the encoded value of the server name private final byte[] encoded; // the hex digitals private static final char[] HEXES = "0123456789ABCDEF".toCharArray(); /** * Creates an {@code SNIServerName} using the specified name type and * encoded value. * <P> * Note that the {@code encoded} byte array is cloned to protect against * subsequent modification. * * @param type * the type of the server name * @param encoded * the encoded value of the server name * * @throws IllegalArgumentException if {@code type} is not in the range * of 0 to 255, inclusive. * @throws NullPointerException if {@code encoded} is null */ protected SNIServerName(int type, byte[] encoded) { if (type < 0) { throw new IllegalArgumentException( "Server name type cannot be less than zero"); } else if (type > 255) { throw new IllegalArgumentException( "Server name type cannot be greater than 255"); } this.type = type; if (encoded == null) { throw new NullPointerException( "Server name encoded value cannot be null"); } this.encoded = encoded.clone(); } /** * Returns the name type of this server name. * * @return the name type of this server name */ public final int getType() { return type; } /** * Returns a copy of the encoded server name value of this server name. * * @return a copy of the encoded server name value of this server name */ public final byte[] getEncoded() { return encoded.clone(); } /** * Indicates whether some other object is "equal to" this server name. * * @return true if, and only if, {@code other} is of the same class * of this object, and has the same name type and * encoded value as this server name. */ @Override public boolean equals(Object other) { if (this == other) { return true; } if (this.getClass() != other.getClass()) { return false; } SNIServerName that = (SNIServerName)other; return (this.type == that.type) && Arrays.equals(this.encoded, that.encoded); } /** * Returns a hash code value for this server name. * <P> * The hash code value is generated using the name type and encoded * value of this server name. * * @return a hash code value for this server name. */ @Override public int hashCode() { int result = 17; // 17/31: prime number to decrease collisions result = 31 * result + type; result = 31 * result + Arrays.hashCode(encoded); return result; } /** * Returns a string representation of this server name, including the server * name type and the encoded server name value in this * {@code SNIServerName} object. * <P> * The exact details of the representation are unspecified and subject * to change, but the following may be regarded as typical: * <pre> * "type={@literal <name type>}, value={@literal Other Java examples (source code examples)Here is a short list of links related to this Java SNIServerName.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.