提交 da9b7119 编写于 作者: V vinnie

Merge

......@@ -87,9 +87,6 @@ build: $(FILES_genout_extcs) $(CHARSETS_JAR)
#
# Extra rules to build character converters.
SERVICE_DESCRIPTION = java.nio.charset.spi.CharsetProvider
SERVICE_DESCRIPTION_PATH = META-INF/services/$(SERVICE_DESCRIPTION)
GENCSDATASRC = $(BUILDDIR)/tools/CharsetMapping
GENCSSRCDIR = $(BUILDDIR)/tools/src/build/tools/charsetmapping
GENCSEXT = $(GENSRCDIR)/sun/nio/cs/ext
......@@ -118,10 +115,6 @@ $(FILES_genout_extcs): \
$(GENCSSRCDIR)/HKSCS.java
$(BOOT_JAVA_CMD) -jar $(CHARSETMAPPING_JARFILE) $(GENCSDATASRC) $(GENCSEXT) dbcs
$(CLASSDESTDIR)/$(SERVICE_DESCRIPTION_PATH): \
$(SHARE_SRC)/classes/sun/nio/cs/ext/$(SERVICE_DESCRIPTION_PATH)
$(install-file)
# no compression unless requested
ifndef COMPRESS_JARS
CREATE_JAR_OPTS_NOMANIFEST = cf0
......@@ -129,10 +122,9 @@ else
CREATE_JAR_OPTS_NOMANIFEST = cf
endif
$(CHARSETS_JAR): $(FILES_class) $(CLASSDESTDIR)/$(SERVICE_DESCRIPTION_PATH) $(FILES_DAT)
$(CHARSETS_JAR): $(FILES_class) $(FILES_DAT)
$(BOOT_JAR_CMD) $(CREATE_JAR_OPTS_NOMANIFEST) $(CHARSETS_JAR) \
-C $(CLASSDESTDIR) sun \
-C $(CLASSDESTDIR) $(SERVICE_DESCRIPTION_PATH) \
$(BOOT_JAR_JFLAGS)
@$(java-vm-cleanup)
......
......@@ -201,7 +201,6 @@ RT_JAR_EXCLUDES += \
META-INF/services/com.sun.jdi.connect.spi.TransportService \
META-INF/services/com.sun.tools.attach.spi.AttachProvider \
META-INF/services/com.sun.tools.xjc.Plugin \
META-INF/services/java.nio.charset.spi.CharsetProvider \
META-INF/services/sun.net.spi.nameservice.NameServiceDescriptor \
org/relaxng/datatype \
sun/awt/HKSCS.class \
......@@ -416,8 +415,7 @@ $(eval $(call SetupArchive,BUILD_CHARSETS_JAR,,\
SUFFIXES:=.class .dat,\
INCLUDES:=sun/nio/cs/ext,\
EXTRA_FILES := sun/awt/HKSCS.class \
$(CHARSETS_EXTRA_FILES) \
META-INF/services/java.nio.charset.spi.CharsetProvider, \
$(CHARSETS_EXTRA_FILES), \
JAR:=$(IMAGES_OUTPUTDIR)/lib/charsets.jar, \
SKIP_METAINF := true, \
CHECK_COMPRESS_JAR:=true))
......
/*
* Copyright (c) 1994, 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1994, 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
......@@ -25,6 +25,7 @@
package java.lang;
import java.util.Arrays;
/**
* A thread-safe, mutable sequence of characters.
......@@ -98,6 +99,12 @@ package java.lang;
implements java.io.Serializable, CharSequence
{
/**
* A cache of the last value returned by toString. Cleared
* whenever the StringBuffer is modified.
*/
private transient char[] toStringCache;
/** use serialVersionUID from JDK 1.0.2 for interoperability */
static final long serialVersionUID = 3388685877147921107L;
......@@ -183,6 +190,7 @@ package java.lang;
*/
@Override
public synchronized void setLength(int newLength) {
toStringCache = null;
super.setLength(newLength);
}
......@@ -247,17 +255,20 @@ package java.lang;
public synchronized void setCharAt(int index, char ch) {
if ((index < 0) || (index >= count))
throw new StringIndexOutOfBoundsException(index);
toStringCache = null;
value[index] = ch;
}
@Override
public synchronized StringBuffer append(Object obj) {
toStringCache = null;
super.append(String.valueOf(obj));
return this;
}
@Override
public synchronized StringBuffer append(String str) {
toStringCache = null;
super.append(str);
return this;
}
......@@ -287,6 +298,7 @@ package java.lang;
* @since 1.4
*/
public synchronized StringBuffer append(StringBuffer sb) {
toStringCache = null;
super.append(sb);
return this;
}
......@@ -296,6 +308,7 @@ package java.lang;
*/
@Override
synchronized StringBuffer append(AbstractStringBuilder asb) {
toStringCache = null;
super.append(asb);
return this;
}
......@@ -325,6 +338,7 @@ package java.lang;
public StringBuffer append(CharSequence s) {
// Note, synchronization achieved via invocations of other StringBuffer methods after
// narrowing of s to specific type
// Ditto for toStringCache clearing
super.append(s);
return this;
}
......@@ -336,12 +350,14 @@ package java.lang;
@Override
public synchronized StringBuffer append(CharSequence s, int start, int end)
{
toStringCache = null;
super.append(s, start, end);
return this;
}
@Override
public synchronized StringBuffer append(char[] str) {
toStringCache = null;
super.append(str);
return this;
}
......@@ -351,24 +367,28 @@ package java.lang;
*/
@Override
public synchronized StringBuffer append(char[] str, int offset, int len) {
toStringCache = null;
super.append(str, offset, len);
return this;
}
@Override
public synchronized StringBuffer append(boolean b) {
toStringCache = null;
super.append(b);
return this;
}
@Override
public synchronized StringBuffer append(char c) {
toStringCache = null;
super.append(c);
return this;
}
@Override
public synchronized StringBuffer append(int i) {
toStringCache = null;
super.append(i);
return this;
}
......@@ -378,24 +398,28 @@ package java.lang;
*/
@Override
public synchronized StringBuffer appendCodePoint(int codePoint) {
toStringCache = null;
super.appendCodePoint(codePoint);
return this;
}
@Override
public synchronized StringBuffer append(long lng) {
toStringCache = null;
super.append(lng);
return this;
}
@Override
public synchronized StringBuffer append(float f) {
toStringCache = null;
super.append(f);
return this;
}
@Override
public synchronized StringBuffer append(double d) {
toStringCache = null;
super.append(d);
return this;
}
......@@ -406,6 +430,7 @@ package java.lang;
*/
@Override
public synchronized StringBuffer delete(int start, int end) {
toStringCache = null;
super.delete(start, end);
return this;
}
......@@ -416,6 +441,7 @@ package java.lang;
*/
@Override
public synchronized StringBuffer deleteCharAt(int index) {
toStringCache = null;
super.deleteCharAt(index);
return this;
}
......@@ -426,6 +452,7 @@ package java.lang;
*/
@Override
public synchronized StringBuffer replace(int start, int end, String str) {
toStringCache = null;
super.replace(start, end, str);
return this;
}
......@@ -465,6 +492,7 @@ package java.lang;
public synchronized StringBuffer insert(int index, char[] str, int offset,
int len)
{
toStringCache = null;
super.insert(index, str, offset, len);
return this;
}
......@@ -474,6 +502,7 @@ package java.lang;
*/
@Override
public synchronized StringBuffer insert(int offset, Object obj) {
toStringCache = null;
super.insert(offset, String.valueOf(obj));
return this;
}
......@@ -483,6 +512,7 @@ package java.lang;
*/
@Override
public synchronized StringBuffer insert(int offset, String str) {
toStringCache = null;
super.insert(offset, str);
return this;
}
......@@ -492,6 +522,7 @@ package java.lang;
*/
@Override
public synchronized StringBuffer insert(int offset, char[] str) {
toStringCache = null;
super.insert(offset, str);
return this;
}
......@@ -504,6 +535,7 @@ package java.lang;
public StringBuffer insert(int dstOffset, CharSequence s) {
// Note, synchronization achieved via invocations of other StringBuffer methods
// after narrowing of s to specific type
// Ditto for toStringCache clearing
super.insert(dstOffset, s);
return this;
}
......@@ -516,6 +548,7 @@ package java.lang;
public synchronized StringBuffer insert(int dstOffset, CharSequence s,
int start, int end)
{
toStringCache = null;
super.insert(dstOffset, s, start, end);
return this;
}
......@@ -527,6 +560,7 @@ package java.lang;
public StringBuffer insert(int offset, boolean b) {
// Note, synchronization achieved via invocation of StringBuffer insert(int, String)
// after conversion of b to String by super class method
// Ditto for toStringCache clearing
super.insert(offset, b);
return this;
}
......@@ -536,6 +570,7 @@ package java.lang;
*/
@Override
public synchronized StringBuffer insert(int offset, char c) {
toStringCache = null;
super.insert(offset, c);
return this;
}
......@@ -547,6 +582,7 @@ package java.lang;
public StringBuffer insert(int offset, int i) {
// Note, synchronization achieved via invocation of StringBuffer insert(int, String)
// after conversion of i to String by super class method
// Ditto for toStringCache clearing
super.insert(offset, i);
return this;
}
......@@ -558,6 +594,7 @@ package java.lang;
public StringBuffer insert(int offset, long l) {
// Note, synchronization achieved via invocation of StringBuffer insert(int, String)
// after conversion of l to String by super class method
// Ditto for toStringCache clearing
super.insert(offset, l);
return this;
}
......@@ -569,6 +606,7 @@ package java.lang;
public StringBuffer insert(int offset, float f) {
// Note, synchronization achieved via invocation of StringBuffer insert(int, String)
// after conversion of f to String by super class method
// Ditto for toStringCache clearing
super.insert(offset, f);
return this;
}
......@@ -580,6 +618,7 @@ package java.lang;
public StringBuffer insert(int offset, double d) {
// Note, synchronization achieved via invocation of StringBuffer insert(int, String)
// after conversion of d to String by super class method
// Ditto for toStringCache clearing
super.insert(offset, d);
return this;
}
......@@ -623,13 +662,17 @@ package java.lang;
*/
@Override
public synchronized StringBuffer reverse() {
toStringCache = null;
super.reverse();
return this;
}
@Override
public synchronized String toString() {
return new String(value, 0, count);
if (toStringCache == null) {
toStringCache = Arrays.copyOfRange(value, 0, count);
}
return new String(toStringCache, true);
}
/**
......
......@@ -607,9 +607,9 @@ class ServerSocket implements java.io.Closeable {
}
/**
* Enable/disable SO_TIMEOUT with the specified timeout, in
* milliseconds. With this option set to a non-zero timeout,
* a call to accept() for this ServerSocket
* Enable/disable {@link SocketOptions#SO_TIMEOUT SO_TIMEOUT} with the
* specified timeout, in milliseconds. With this option set to a non-zero
* timeout, a call to accept() for this ServerSocket
* will block for only this amount of time. If the timeout expires,
* a <B>java.net.SocketTimeoutException</B> is raised, though the
* ServerSocket is still valid. The option <B>must</B> be enabled
......@@ -629,9 +629,9 @@ class ServerSocket implements java.io.Closeable {
}
/**
* Retrieve setting for SO_TIMEOUT. 0 returns implies that the
* option is disabled (i.e., timeout of infinity).
* @return the SO_TIMEOUT value
* Retrieve setting for {@link SocketOptions#SO_TIMEOUT SO_TIMEOUT}.
* 0 returns implies that the option is disabled (i.e., timeout of infinity).
* @return the {@link SocketOptions#SO_TIMEOUT SO_TIMEOUT} value
* @exception IOException if an I/O error occurs
* @since JDK1.1
* @see #setSoTimeout(int)
......@@ -649,7 +649,8 @@ class ServerSocket implements java.io.Closeable {
}
/**
* Enable/disable the SO_REUSEADDR socket option.
* Enable/disable the {@link SocketOptions#SO_REUSEADDR SO_REUSEADDR}
* socket option.
* <p>
* When a TCP connection is closed the connection may remain
* in a timeout state for a period of time after the connection
......@@ -660,24 +661,23 @@ class ServerSocket implements java.io.Closeable {
* <tt>SocketAddress</tt> if there is a connection in the
* timeout state involving the socket address or port.
* <p>
* Enabling <tt>SO_REUSEADDR</tt> prior to binding the socket
* using {@link #bind(SocketAddress)} allows the socket to be
* bound even though a previous connection is in a timeout
* state.
* Enabling {@link SocketOptions#SO_REUSEADDR SO_REUSEADDR} prior to
* binding the socket using {@link #bind(SocketAddress)} allows the socket
* to be bound even though a previous connection is in a timeout state.
* <p>
* When a <tt>ServerSocket</tt> is created the initial setting
* of <tt>SO_REUSEADDR</tt> is not defined. Applications can
* use {@link #getReuseAddress()} to determine the initial
* setting of <tt>SO_REUSEADDR</tt>.
* of {@link SocketOptions#SO_REUSEADDR SO_REUSEADDR} is not defined.
* Applications can use {@link #getReuseAddress()} to determine the initial
* setting of {@link SocketOptions#SO_REUSEADDR SO_REUSEADDR}.
* <p>
* The behaviour when <tt>SO_REUSEADDR</tt> is enabled or
* disabled after a socket is bound (See {@link #isBound()})
* The behaviour when {@link SocketOptions#SO_REUSEADDR SO_REUSEADDR} is
* enabled or disabled after a socket is bound (See {@link #isBound()})
* is not defined.
*
* @param on whether to enable or disable the socket option
* @exception SocketException if an error occurs enabling or
* disabling the <tt>SO_RESUEADDR</tt> socket option,
* or the socket is closed.
* disabling the {@link SocketOptions#SO_REUSEADDR SO_REUSEADDR}
* socket option, or the socket is closed.
* @since 1.4
* @see #getReuseAddress()
* @see #bind(SocketAddress)
......@@ -691,9 +691,10 @@ class ServerSocket implements java.io.Closeable {
}
/**
* Tests if SO_REUSEADDR is enabled.
* Tests if {@link SocketOptions#SO_REUSEADDR SO_REUSEADDR} is enabled.
*
* @return a <code>boolean</code> indicating whether or not SO_REUSEADDR is enabled.
* @return a <code>boolean</code> indicating whether or not
* {@link SocketOptions#SO_REUSEADDR SO_REUSEADDR} is enabled.
* @exception SocketException if there is an error
* in the underlying protocol, such as a TCP error.
* @since 1.4
......@@ -768,15 +769,16 @@ class ServerSocket implements java.io.Closeable {
}
/**
* Sets a default proposed value for the SO_RCVBUF option for sockets
* Sets a default proposed value for the
* {@link SocketOptions#SO_RCVBUF SO_RCVBUF} option for sockets
* accepted from this <tt>ServerSocket</tt>. The value actually set
* in the accepted socket must be determined by calling
* {@link Socket#getReceiveBufferSize()} after the socket
* is returned by {@link #accept()}.
* <p>
* The value of SO_RCVBUF is used both to set the size of the internal
* socket receive buffer, and to set the size of the TCP receive window
* that is advertized to the remote peer.
* The value of {@link SocketOptions#SO_RCVBUF SO_RCVBUF} is used both to
* set the size of the internal socket receive buffer, and to set the size
* of the TCP receive window that is advertized to the remote peer.
* <p>
* It is possible to change the value subsequently, by calling
* {@link Socket#setReceiveBufferSize(int)}. However, if the application
......@@ -812,15 +814,16 @@ class ServerSocket implements java.io.Closeable {
}
/**
* Gets the value of the SO_RCVBUF option for this <tt>ServerSocket</tt>,
* that is the proposed buffer size that will be used for Sockets accepted
* from this <tt>ServerSocket</tt>.
* Gets the value of the {@link SocketOptions#SO_RCVBUF SO_RCVBUF} option
* for this <tt>ServerSocket</tt>, that is the proposed buffer size that
* will be used for Sockets accepted from this <tt>ServerSocket</tt>.
*
* <p>Note, the value actually set in the accepted socket is determined by
* calling {@link Socket#getReceiveBufferSize()}.
* @return the value of the SO_RCVBUF option for this <tt>Socket</tt>.
* @return the value of the {@link SocketOptions#SO_RCVBUF SO_RCVBUF}
* option for this <tt>Socket</tt>.
* @exception SocketException if there is an error
* in the underlying protocol, such as a TCP error.
* in the underlying protocol, such as a TCP error.
* @see #setReceiveBufferSize(int)
* @since 1.4
*/
......
......@@ -924,7 +924,8 @@ class Socket implements java.io.Closeable {
}
/**
* Enable/disable TCP_NODELAY (disable/enable Nagle's algorithm).
* Enable/disable {@link SocketOptions#TCP_NODELAY TCP_NODELAY}
* (disable/enable Nagle's algorithm).
*
* @param on <code>true</code> to enable TCP_NODELAY,
* <code>false</code> to disable.
......@@ -943,9 +944,10 @@ class Socket implements java.io.Closeable {
}
/**
* Tests if TCP_NODELAY is enabled.
* Tests if {@link SocketOptions#TCP_NODELAY TCP_NODELAY} is enabled.
*
* @return a <code>boolean</code> indicating whether or not TCP_NODELAY is enabled.
* @return a <code>boolean</code> indicating whether or not
* {@link SocketOptions#TCP_NODELAY TCP_NODELAY} is enabled.
* @exception SocketException if there is an error
* in the underlying protocol, such as a TCP error.
* @since JDK1.1
......@@ -958,8 +960,9 @@ class Socket implements java.io.Closeable {
}
/**
* Enable/disable SO_LINGER with the specified linger time in seconds.
* The maximum timeout value is platform specific.
* Enable/disable {@link SocketOptions#SO_LINGER SO_LINGER} with the
* specified linger time in seconds. The maximum timeout value is platform
* specific.
*
* The setting only affects socket close.
*
......@@ -987,12 +990,13 @@ class Socket implements java.io.Closeable {
}
/**
* Returns setting for SO_LINGER. -1 returns implies that the
* Returns setting for {@link SocketOptions#SO_LINGER SO_LINGER}.
* -1 returns implies that the
* option is disabled.
*
* The setting only affects socket close.
*
* @return the setting for SO_LINGER.
* @return the setting for {@link SocketOptions#SO_LINGER SO_LINGER}.
* @exception SocketException if there is an error
* in the underlying protocol, such as a TCP error.
* @since JDK1.1
......@@ -1027,7 +1031,8 @@ class Socket implements java.io.Closeable {
}
/**
* Enable/disable OOBINLINE (receipt of TCP urgent data)
* Enable/disable {@link SocketOptions#SO_OOBINLINE SO_OOBINLINE}
* (receipt of TCP urgent data)
*
* By default, this option is disabled and TCP urgent data received on a
* socket is silently discarded. If the user wishes to receive urgent data, then
......@@ -1039,8 +1044,9 @@ class Socket implements java.io.Closeable {
* and there is no capability to distinguish between normal data and urgent
* data unless provided by a higher level protocol.
*
* @param on <code>true</code> to enable OOBINLINE,
* <code>false</code> to disable.
* @param on <code>true</code> to enable
* {@link SocketOptions#SO_OOBINLINE SO_OOBINLINE},
* <code>false</code> to disable.
*
* @exception SocketException if there is an error
* in the underlying protocol, such as a TCP error.
......@@ -1056,9 +1062,11 @@ class Socket implements java.io.Closeable {
}
/**
* Tests if OOBINLINE is enabled.
* Tests if {@link SocketOptions#SO_OOBINLINE SO_OOBINLINE} is enabled.
*
* @return a <code>boolean</code> indicating whether or not
* {@link SocketOptions#SO_OOBINLINE SO_OOBINLINE}is enabled.
*
* @return a <code>boolean</code> indicating whether or not OOBINLINE is enabled.
* @exception SocketException if there is an error
* in the underlying protocol, such as a TCP error.
* @since 1.4
......@@ -1071,15 +1079,16 @@ class Socket implements java.io.Closeable {
}
/**
* Enable/disable SO_TIMEOUT with the specified timeout, in
* milliseconds. With this option set to a non-zero timeout,
* a read() call on the InputStream associated with this Socket
* will block for only this amount of time. If the timeout expires,
* a <B>java.net.SocketTimeoutException</B> is raised, though the
* Enable/disable {@link SocketOptions#SO_TIMEOUT SO_TIMEOUT}
* with the specified timeout, in milliseconds. With this option set
* to a non-zero timeout, a read() call on the InputStream associated with
* this Socket will block for only this amount of time. If the timeout
* expires, a <B>java.net.SocketTimeoutException</B> is raised, though the
* Socket is still valid. The option <B>must</B> be enabled
* prior to entering the blocking operation to have effect. The
* timeout must be > 0.
* A timeout of zero is interpreted as an infinite timeout.
*
* @param timeout the specified timeout, in milliseconds.
* @exception SocketException if there is an error
* in the underlying protocol, such as a TCP error.
......@@ -1096,11 +1105,13 @@ class Socket implements java.io.Closeable {
}
/**
* Returns setting for SO_TIMEOUT. 0 returns implies that the
* option is disabled (i.e., timeout of infinity).
* @return the setting for SO_TIMEOUT
* Returns setting for {@link SocketOptions#SO_TIMEOUT SO_TIMEOUT}.
* 0 returns implies that the option is disabled (i.e., timeout of infinity).
*
* @return the setting for {@link SocketOptions#SO_TIMEOUT SO_TIMEOUT}
* @exception SocketException if there is an error
* in the underlying protocol, such as a TCP error.
*
* @since JDK1.1
* @see #setSoTimeout(int)
*/
......@@ -1117,14 +1128,15 @@ class Socket implements java.io.Closeable {
}
/**
* Sets the SO_SNDBUF option to the specified value for this
* <tt>Socket</tt>. The SO_SNDBUF option is used by the platform's
* networking code as a hint for the size to set
* the underlying network I/O buffers.
* Sets the {@link SocketOptions#SO_SNDBUF SO_SNDBUF} option to the
* specified value for this <tt>Socket</tt>.
* The {@link SocketOptions#SO_SNDBUF SO_SNDBUF} option is used by the
* platform's networking code as a hint for the size to set the underlying
* network I/O buffers.
*
* <p>Because SO_SNDBUF is a hint, applications that want to
* verify what size the buffers were set to should call
* {@link #getSendBufferSize()}.
* <p>Because {@link SocketOptions#SO_SNDBUF SO_SNDBUF} is a hint,
* applications that want to verify what size the buffers were set to
* should call {@link #getSendBufferSize()}.
*
* @exception SocketException if there is an error
* in the underlying protocol, such as a TCP error.
......@@ -1149,10 +1161,11 @@ class Socket implements java.io.Closeable {
}
/**
* Get value of the SO_SNDBUF option for this <tt>Socket</tt>,
* that is the buffer size used by the platform
* Get value of the {@link SocketOptions#SO_SNDBUF SO_SNDBUF} option
* for this <tt>Socket</tt>, that is the buffer size used by the platform
* for output on this <tt>Socket</tt>.
* @return the value of the SO_SNDBUF option for this <tt>Socket</tt>.
* @return the value of the {@link SocketOptions#SO_SNDBUF SO_SNDBUF}
* option for this <tt>Socket</tt>.
*
* @exception SocketException if there is an error
* in the underlying protocol, such as a TCP error.
......@@ -1172,25 +1185,26 @@ class Socket implements java.io.Closeable {
}
/**
* Sets the SO_RCVBUF option to the specified value for this
* <tt>Socket</tt>. The SO_RCVBUF option is used by the platform's
* networking code as a hint for the size to set
* Sets the {@link SocketOptions#SO_RCVBUF SO_RCVBUF} option to the
* specified value for this <tt>Socket</tt>. The
* {@link SocketOptions#SO_RCVBUF SO_RCVBUF} option is
* used by the platform's networking code as a hint for the size to set
* the underlying network I/O buffers.
*
* <p>Increasing the receive buffer size can increase the performance of
* network I/O for high-volume connection, while decreasing it can
* help reduce the backlog of incoming data.
*
* <p>Because SO_RCVBUF is a hint, applications that want to
* verify what size the buffers were set to should call
* {@link #getReceiveBufferSize()}.
* <p>Because {@link SocketOptions#SO_RCVBUF SO_RCVBUF} is a hint,
* applications that want to verify what size the buffers were set to
* should call {@link #getReceiveBufferSize()}.
*
* <p>The value of SO_RCVBUF is also used to set the TCP receive window
* that is advertized to the remote peer. Generally, the window size
* can be modified at any time when a socket is connected. However, if
* a receive window larger than 64K is required then this must be requested
* <B>before</B> the socket is connected to the remote peer. There are two
* cases to be aware of:<p>
* <p>The value of {@link SocketOptions#SO_RCVBUF SO_RCVBUF} is also used
* to set the TCP receive window that is advertized to the remote peer.
* Generally, the window size can be modified at any time when a socket is
* connected. However, if a receive window larger than 64K is required then
* this must be requested <B>before</B> the socket is connected to the
* remote peer. There are two cases to be aware of:<p>
* <ol>
* <li>For sockets accepted from a ServerSocket, this must be done by calling
* {@link ServerSocket#setReceiveBufferSize(int)} before the ServerSocket
......@@ -1221,11 +1235,12 @@ class Socket implements java.io.Closeable {
}
/**
* Gets the value of the SO_RCVBUF option for this <tt>Socket</tt>,
* that is the buffer size used by the platform for
* input on this <tt>Socket</tt>.
* Gets the value of the {@link SocketOptions#SO_RCVBUF SO_RCVBUF} option
* for this <tt>Socket</tt>, that is the buffer size used by the platform
* for input on this <tt>Socket</tt>.
*
* @return the value of the SO_RCVBUF option for this <tt>Socket</tt>.
* @return the value of the {@link SocketOptions#SO_RCVBUF SO_RCVBUF}
* option for this <tt>Socket</tt>.
* @exception SocketException if there is an error
* in the underlying protocol, such as a TCP error.
* @see #setReceiveBufferSize(int)
......@@ -1244,9 +1259,9 @@ class Socket implements java.io.Closeable {
}
/**
* Enable/disable SO_KEEPALIVE.
* Enable/disable {@link SocketOptions#SO_KEEPALIVE SO_KEEPALIVE}.
*
* @param on whether or not to have socket keep alive turned on.
* @param on whether or not to have socket keep alive turned on.
* @exception SocketException if there is an error
* in the underlying protocol, such as a TCP error.
* @since 1.3
......@@ -1259,9 +1274,10 @@ class Socket implements java.io.Closeable {
}
/**
* Tests if SO_KEEPALIVE is enabled.
* Tests if {@link SocketOptions#SO_KEEPALIVE SO_KEEPALIVE} is enabled.
*
* @return a <code>boolean</code> indicating whether or not SO_KEEPALIVE is enabled.
* @return a <code>boolean</code> indicating whether or not
* {@link SocketOptions#SO_KEEPALIVE SO_KEEPALIVE} is enabled.
* @exception SocketException if there is an error
* in the underlying protocol, such as a TCP error.
* @since 1.3
......@@ -1317,6 +1333,7 @@ class Socket implements java.io.Closeable {
* traffic class or type-of-service
* @since 1.4
* @see #getTrafficClass
* @see SocketOptions#IP_TOS
*/
public void setTrafficClass(int tc) throws SocketException {
if (tc < 0 || tc > 255)
......@@ -1341,13 +1358,15 @@ class Socket implements java.io.Closeable {
* traffic class or type-of-service value.
* @since 1.4
* @see #setTrafficClass(int)
* @see SocketOptions#IP_TOS
*/
public int getTrafficClass() throws SocketException {
return ((Integer) (getImpl().getOption(SocketOptions.IP_TOS))).intValue();
}
/**
* Enable/disable the SO_REUSEADDR socket option.
* Enable/disable the {@link SocketOptions#SO_REUSEADDR SO_REUSEADDR}
* socket option.
* <p>
* When a TCP connection is closed the connection may remain
* in a timeout state for a period of time after the connection
......@@ -1358,22 +1377,22 @@ class Socket implements java.io.Closeable {
* <tt>SocketAddress</tt> if there is a connection in the
* timeout state involving the socket address or port.
* <p>
* Enabling <tt>SO_REUSEADDR</tt> prior to binding the socket
* using {@link #bind(SocketAddress)} allows the socket to be
* bound even though a previous connection is in a timeout
* Enabling {@link SocketOptions#SO_REUSEADDR SO_REUSEADDR}
* prior to binding the socket using {@link #bind(SocketAddress)} allows
* the socket to be bound even though a previous connection is in a timeout
* state.
* <p>
* When a <tt>Socket</tt> is created the initial setting
* of <tt>SO_REUSEADDR</tt> is disabled.
* of {@link SocketOptions#SO_REUSEADDR SO_REUSEADDR} is disabled.
* <p>
* The behaviour when <tt>SO_REUSEADDR</tt> is enabled or
* disabled after a socket is bound (See {@link #isBound()})
* The behaviour when {@link SocketOptions#SO_REUSEADDR SO_REUSEADDR} is
* enabled or disabled after a socket is bound (See {@link #isBound()})
* is not defined.
*
* @param on whether to enable or disable the socket option
* @exception SocketException if an error occurs enabling or
* disabling the <tt>SO_RESUEADDR</tt> socket option,
* or the socket is closed.
* disabling the {@link SocketOptions#SO_REUSEADDR SO_REUSEADDR}
* socket option, or the socket is closed.
* @since 1.4
* @see #getReuseAddress()
* @see #bind(SocketAddress)
......@@ -1387,9 +1406,10 @@ class Socket implements java.io.Closeable {
}
/**
* Tests if SO_REUSEADDR is enabled.
* Tests if {@link SocketOptions#SO_REUSEADDR SO_REUSEADDR} is enabled.
*
* @return a <code>boolean</code> indicating whether or not SO_REUSEADDR is enabled.
* @return a <code>boolean</code> indicating whether or not
* {@link SocketOptions#SO_REUSEADDR SO_REUSEADDR} is enabled.
* @exception SocketException if there is an error
* in the underlying protocol, such as a TCP error.
* @since 1.4
......
......@@ -427,46 +427,38 @@ public abstract class Charset
}
/* The extended set of charsets */
private static Object extendedProviderLock = new Object();
private static boolean extendedProviderProbed = false;
private static CharsetProvider extendedProvider = null;
private static void probeExtendedProvider() {
AccessController.doPrivileged(new PrivilegedAction<Object>() {
public Object run() {
try {
Class<?> epc
= Class.forName("sun.nio.cs.ext.ExtendedCharsets");
extendedProvider = (CharsetProvider)epc.newInstance();
} catch (ClassNotFoundException x) {
// Extended charsets not available
// (charsets.jar not present)
} catch (InstantiationException x) {
throw new Error(x);
} catch (IllegalAccessException x) {
throw new Error(x);
}
return null;
}
});
private static class ExtendedProviderHolder {
static final CharsetProvider extendedProvider = extendedProvider();
// returns ExtendedProvider, if installed
private static CharsetProvider extendedProvider() {
return AccessController.doPrivileged(
new PrivilegedAction<CharsetProvider>() {
public CharsetProvider run() {
try {
Class<?> epc
= Class.forName("sun.nio.cs.ext.ExtendedCharsets");
return (CharsetProvider)epc.newInstance();
} catch (ClassNotFoundException x) {
// Extended charsets not available
// (charsets.jar not present)
} catch (InstantiationException |
IllegalAccessException x) {
throw new Error(x);
}
return null;
}
});
}
}
private static Charset lookupExtendedCharset(String charsetName) {
CharsetProvider ecp = null;
synchronized (extendedProviderLock) {
if (!extendedProviderProbed) {
probeExtendedProvider();
extendedProviderProbed = true;
}
ecp = extendedProvider;
}
CharsetProvider ecp = ExtendedProviderHolder.extendedProvider;
return (ecp != null) ? ecp.charsetForName(charsetName) : null;
}
private static Charset lookup(String charsetName) {
if (charsetName == null)
throw new IllegalArgumentException("Null charset name");
Object[] a;
if ((a = cache1) != null && charsetName.equals(a[0]))
return (Charset)a[1];
......@@ -483,7 +475,6 @@ public abstract class Charset
cache1 = a;
return (Charset)a[1];
}
Charset cs;
if ((cs = standardProvider.charsetForName(charsetName)) != null ||
(cs = lookupExtendedCharset(charsetName)) != null ||
......@@ -589,6 +580,9 @@ public abstract class Charset
new TreeMap<String,Charset>(
ASCIICaseInsensitiveComparator.CASE_INSENSITIVE_ORDER);
put(standardProvider.charsets(), m);
CharsetProvider ecp = ExtendedProviderHolder.extendedProvider;
if (ecp != null)
put(ecp.charsets(), m);
for (Iterator<CharsetProvider> i = providers(); i.hasNext();) {
CharsetProvider cp = i.next();
put(cp.charsets(), m);
......
......@@ -625,7 +625,8 @@ public class Base64 {
* character(s) padded), they are decoded as if followed by padding
* character(s). If there is padding character present in the
* final unit, the correct number of padding character(s) must be
* present, otherwise {@code IllegalArgumentException} is thrown
* present, otherwise {@code IllegalArgumentException} (
* {@code IOException} when reading from a Base64 stream) is thrown
* during decoding.
*
* <p> Instances of {@link Decoder} class are safe for use by
......@@ -1306,7 +1307,12 @@ public class Base64 {
return off - oldOff;
}
if (v == '=') { // padding byte(s)
if (nextin != 6 && nextin != 0) {
// = shiftto==18 unnecessary padding
// x= shiftto==12 invalid unit
// xx= shiftto==6 && missing last '='
// xx=y or last is not '='
if (nextin == 18 || nextin == 12 ||
nextin == 6 && is.read() != '=') {
throw new IOException("Illegal base64 ending sequence:" + nextin);
}
b[off++] = (byte)(bits >> (16));
......
......@@ -47,17 +47,17 @@ public class ISO2022_JP_2 extends ISO2022_JP
}
public CharsetDecoder newDecoder() {
return new Decoder(this, Decoder.DEC0208, DEC0212);
return new Decoder(this, Decoder.DEC0208, CoderHolder.DEC0212);
}
public CharsetEncoder newEncoder() {
return new Encoder(this, Encoder.ENC0208, ENC0212, true);
return new Encoder(this, Encoder.ENC0208, CoderHolder.ENC0212, true);
}
private final static DoubleByte.Decoder DEC0212 =
(DoubleByte.Decoder)new JIS_X_0212().newDecoder();
private final static DoubleByte.Encoder ENC0212 =
(DoubleByte.Encoder)new JIS_X_0212().newEncoder();
private static class CoderHolder {
final static DoubleByte.Decoder DEC0212 =
(DoubleByte.Decoder)new JIS_X_0212().newDecoder();
final static DoubleByte.Encoder ENC0212 =
(DoubleByte.Encoder)new JIS_X_0212().newEncoder();
}
}
# NIO charset SPI extended charset provider
sun.nio.cs.ext.ExtendedCharsets
......@@ -46,16 +46,17 @@ public class MSISO2022JP extends ISO2022_JP
}
public CharsetDecoder newDecoder() {
return new Decoder(this, DEC0208, null);
return new Decoder(this, CoderHolder.DEC0208, null);
}
public CharsetEncoder newEncoder() {
return new Encoder(this, ENC0208, null, true);
return new Encoder(this, CoderHolder.ENC0208, null, true);
}
private final static DoubleByte.Decoder DEC0208 =
(DoubleByte.Decoder)new JIS_X_0208_MS932().newDecoder();
private final static DoubleByte.Encoder ENC0208 =
(DoubleByte.Encoder)new JIS_X_0208_MS932().newEncoder();
private static class CoderHolder {
final static DoubleByte.Decoder DEC0208 =
(DoubleByte.Decoder)new JIS_X_0208_MS932().newDecoder();
final static DoubleByte.Encoder ENC0208 =
(DoubleByte.Encoder)new JIS_X_0208_MS932().newEncoder();
}
}
/*
* Copyright (c) 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.
*
* 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.
*/
/* @test
* @bug 8013395
* @summary Test StringBuffer.toString caching
*/
public class ToStringCache {
// we can't test that we actually use a cached value (the benchmarks
// verify that) but we have to test that the cache is cleared when
// expected
public static void main(String[] args) throws Exception {
String original = "The original String";
StringBuffer sb = new StringBuffer(original);
String a = sb.toString();
checkEqual(a, original);
String b = sb.toString();
checkEqual(a, b);
// mutating methods
sb.setLength(12);
b = sb.toString();
checkUnequal(a, b);
a = b;
sb.setCharAt(0, 'X');
b = sb.toString();
checkUnequal(a, b);
a = b;
sb.append(new Character('X'));
b = sb.toString();
checkUnequal(a, b);
a = b;
sb.append("More text");
b = sb.toString();
checkUnequal(a, b);
a = b;
sb.append(sb);
b = sb.toString();
checkUnequal(a, b);
a = b;
sb.append(new StringBuilder("Build"));
b = sb.toString();
checkUnequal(a, b);
a = b;
sb.append(new StringBuilder("Build2"), 0, 1);
b = sb.toString();
checkUnequal(a, b);
a = b;
sb.append(new char[] { 'a', 'b' });
b = sb.toString();
checkUnequal(a, b);
a = b;
sb.append(true);
b = sb.toString();
checkUnequal(a, b);
a = b;
sb.append('c');
b = sb.toString();
checkUnequal(a, b);
a = b;
sb.append(23);
b = sb.toString();
checkUnequal(a, b);
a = b;
sb.appendCodePoint(Character.codePointAt(new char[] { 'X'}, 0));
b = sb.toString();
checkUnequal(a, b);
a = b;
sb.append(1L);
b = sb.toString();
checkUnequal(a, b);
a = b;
sb.append(1.0f);
b = sb.toString();
checkUnequal(a, b);
a = b;
sb.append(1.0d);
b = sb.toString();
checkUnequal(a, b);
a = b;
sb.delete(0, 5);
b = sb.toString();
checkUnequal(a, b);
a = b;
sb.deleteCharAt(0);
b = sb.toString();
checkUnequal(a, b);
a = b;
sb.replace(0,2, "123");
b = sb.toString();
checkUnequal(a, b);
a = b;
sb.insert(0, new char[] { 'a', 'b', 'c'}, 0, 3);
b = sb.toString();
checkUnequal(a, b);
a = b;
sb.insert(0, new Object());
b = sb.toString();
checkUnequal(a, b);
a = b;
sb.insert(0, "abc");
b = sb.toString();
checkUnequal(a, b);
a = b;
sb.insert(0, new char[] { 'a', 'b', 'c' });
b = sb.toString();
checkUnequal(a, b);
a = b;
sb.insert(0, new StringBuilder("Build"));
b = sb.toString();
checkUnequal(a, b);
a = b;
sb.insert(0, new StringBuilder("Build"), 0, 1);
b = sb.toString();
checkUnequal(a, b);
a = b;
sb.insert(0, false);
b = sb.toString();
checkUnequal(a, b);
a = b;
sb.insert(0, 'X');
b = sb.toString();
checkUnequal(a, b);
a = b;
sb.insert(0, 1);
b = sb.toString();
checkUnequal(a, b);
a = b;
sb.insert(0, 1L);
b = sb.toString();
checkUnequal(a, b);
a = b;
sb.insert(0, 1.0f);
b = sb.toString();
checkUnequal(a, b);
a = b;
sb.insert(0, 1.0d);
b = sb.toString();
checkUnequal(a, b);
a = b;
sb.reverse();
b = sb.toString();
checkUnequal(a, b);
// non-mutating methods
// Reset to known value
sb = new StringBuffer(original);
a = sb.toString();
b = sb.toString();
checkEqual(a, b);
int l = sb.length();
b = sb.toString();
checkEqual(a, b);
int cap = sb.capacity();
b = sb.toString();
checkEqual(a, b);
sb.ensureCapacity(100);
b = sb.toString();
checkEqual(a, b);
sb.trimToSize();
b = sb.toString();
checkEqual(a, b);
char c = sb.charAt(1);
b = sb.toString();
checkEqual(a, b);
int cp = sb.codePointAt(1);
b = sb.toString();
checkEqual(a, b);
cp = sb.codePointBefore(2);
b = sb.toString();
checkEqual(a, b);
int count = sb.codePointCount(0,1);
b = sb.toString();
checkEqual(a, b);
count = sb.offsetByCodePoints(0, 1);
b = sb.toString();
checkEqual(a, b);
sb.getChars(0, 1, new char[2], 0);
b = sb.toString();
checkEqual(a, b);
String sub = sb.substring(0);
b = sb.toString();
checkEqual(a, b);
CharSequence cs = sb.subSequence(0,1);
b = sb.toString();
checkEqual(a, b);
sub = sb.substring(0, 3);
b = sb.toString();
checkEqual(a, b);
int index = sb.indexOf("rig");
b = sb.toString();
checkEqual(a, b);
index = sb.indexOf("rig", 2);
b = sb.toString();
checkEqual(a, b);
index = sb.lastIndexOf("rig");
b = sb.toString();
checkEqual(a, b);
index = sb.lastIndexOf("rig", 3);
b = sb.toString();
checkEqual(a, b);
}
private static void checkEqual(String s1, String s2) {
if (!s1.equals(s2))
throw new RuntimeException("Unmatched strings: s1 = "
+ s1 + " s2 = " + s2);
}
private static void checkUnequal(String s1, String s2) {
if (s1.equals(s2))
throw new RuntimeException("Unexpected matched strings: " + s1);
}
}
......@@ -23,6 +23,7 @@
/**
* @test 4235519 8004212 8005394 8007298 8006295 8006315 8006530 8007379 8008925
* 8014217
* @summary tests java.util.Base64
*/
......@@ -110,6 +111,14 @@ public class TestBase64 {
// illegal ending unit
checkIAE(new Runnable() { public void run() { Base64.getMimeDecoder().decode("$=#"); }});
checkIOE(new Testable() { public void test() throws IOException {
byte[] bytes = "AA=".getBytes("ASCII");
try (InputStream stream =
Base64.getDecoder().wrap(new ByteArrayInputStream(bytes))) {
while (stream.read() != -1);
}
}});
// test return value from decode(ByteBuffer, ByteBuffer)
testDecBufRet();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册