提交 75f827bf 编写于 作者: Y yan

Merge

...@@ -43,3 +43,5 @@ a50217eb3ee10b9f9547e0708e5c9625405083ef jdk7-b64 ...@@ -43,3 +43,5 @@ a50217eb3ee10b9f9547e0708e5c9625405083ef jdk7-b64
bd31b30a5b21f20e42965b1633f18a5c7946d398 jdk7-b66 bd31b30a5b21f20e42965b1633f18a5c7946d398 jdk7-b66
a952aafd5181af953b0ef3010dbd2fcc28460e8a jdk7-b67 a952aafd5181af953b0ef3010dbd2fcc28460e8a jdk7-b67
b23d905cb5d3b382295240d28ab0bfb266b4503c jdk7-b68 b23d905cb5d3b382295240d28ab0bfb266b4503c jdk7-b68
226b20019b1f020c09ea97d137d98e011ce65d76 jdk7-b69
893bcca951b747ddcf6986362b877f0e1dbb835b jdk7-b70
...@@ -32,7 +32,7 @@ USE OR OTHER DEALINGS IN THE SOFTWARE. ...@@ -32,7 +32,7 @@ USE OR OTHER DEALINGS IN THE SOFTWARE.
--- end of LICENSE file --- --- end of LICENSE file ---
%% This notice is provided with respect to ASM, which may be included with this software: %% This notice is provided with respect to ASM, which may be included with this software:
Copyright (c) 2000-2005 INRIA, France Telecom Copyright (c) 2000-2007 INRIA, France Telecom
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
......
...@@ -77,6 +77,7 @@ JAVA_JAVA_java = \ ...@@ -77,6 +77,7 @@ JAVA_JAVA_java = \
java/lang/Compiler.java \ java/lang/Compiler.java \
java/lang/Throwable.java \ java/lang/Throwable.java \
java/lang/Exception.java \ java/lang/Exception.java \
java/lang/ReflectiveOperationException.java \
java/lang/IllegalAccessException.java \ java/lang/IllegalAccessException.java \
java/lang/InstantiationException.java \ java/lang/InstantiationException.java \
java/lang/ClassNotFoundException.java \ java/lang/ClassNotFoundException.java \
...@@ -250,6 +251,8 @@ JAVA_JAVA_java = \ ...@@ -250,6 +251,8 @@ JAVA_JAVA_java = \
java/util/IdentityHashMap.java \ java/util/IdentityHashMap.java \
java/util/EnumMap.java \ java/util/EnumMap.java \
java/util/Arrays.java \ java/util/Arrays.java \
java/util/TimSort.java \
java/util/ComparableTimSort.java \
java/util/ConcurrentModificationException.java \ java/util/ConcurrentModificationException.java \
java/util/ServiceLoader.java \ java/util/ServiceLoader.java \
java/util/ServiceConfigurationError.java \ java/util/ServiceConfigurationError.java \
......
...@@ -41,6 +41,7 @@ FILES_java = \ ...@@ -41,6 +41,7 @@ FILES_java = \
sun/net/NetProperties.java \ sun/net/NetProperties.java \
sun/net/NetHooks.java \ sun/net/NetHooks.java \
sun/net/util/IPAddressUtil.java \ sun/net/util/IPAddressUtil.java \
sun/net/util/URLUtil.java \
sun/net/dns/ResolverConfiguration.java \ sun/net/dns/ResolverConfiguration.java \
sun/net/dns/ResolverConfigurationImpl.java \ sun/net/dns/ResolverConfigurationImpl.java \
sun/net/ftp/FtpClient.java \ sun/net/ftp/FtpClient.java \
......
# #
# Copyright 1996-2007 Sun Microsystems, Inc. All Rights Reserved. # Copyright 1996-2009 Sun Microsystems, Inc. All Rights Reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
# #
# This code is free software; you can redistribute it and/or modify it # This code is free software; you can redistribute it and/or modify it
...@@ -60,7 +60,7 @@ ifeq ($(PLATFORM), windows) ...@@ -60,7 +60,7 @@ ifeq ($(PLATFORM), windows)
endif endif
endif endif
SUBDIRS = other action util tools jgss krb5 smartcardio $(PKCS11) \ SUBDIRS = ec other action util tools jgss krb5 smartcardio $(PKCS11) \
$(JGSS_WRAPPER) $(MSCAPI) $(JGSS_WRAPPER) $(MSCAPI)
all build clean clobber:: all build clean clobber::
......
#
# Copyright 2009 Sun Microsystems, Inc. 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. Sun designates this
# particular file as subject to the "Classpath" exception as provided
# by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
# CA 95054 USA or visit www.sun.com if you need additional information or
# have any questions.
#
FILES_c = \
ec.c \
ec2_163.c \
ec2_193.c \
ec2_233.c \
ec2_aff.c \
ec2_mont.c \
ecdecode.c \
ecl.c \
ecl_curve.c \
ecl_gf.c \
ecl_mult.c \
ec_naf.c \
ecp_192.c \
ecp_224.c \
ecp_256.c \
ecp_384.c \
ecp_521.c \
ecp_aff.c \
ecp_jac.c \
ecp_jm.c \
ecp_mont.c \
mp_gf2m.c \
mpi.c \
mplogic.c \
mpmontg.c \
oid.c \
secitem.c
#
# Copyright 2009 Sun Microsystems, Inc. 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. Sun designates this
# particular file as subject to the "Classpath" exception as provided
# by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
# CA 95054 USA or visit www.sun.com if you need additional information or
# have any questions.
#
#
# Makefile for building sunec.jar and sunecc native library.
#
# This file was derived from make/com/sun/crypto/provider/Makefile.
#
#
# (The terms "OpenJDK" and "JDK" below refer to OpenJDK and Sun JDK builds
# respectively.)
#
# JCE builds are very different between OpenJDK and JDK. The OpenJDK JCE
# jar files do not require signing, but those for JDK do. If an unsigned
# jar file is installed into JDK, things will break when the crypto
# routines are called.
#
# This Makefile does the "real" build of the JCE files. For OpenJDK,
# the jar files built here are installed directly into the OpenJDK.
#
# For JDK, the binaries use pre-built/pre-signed binary files stored in
# the closed workspace that are not shipped in the OpenJDK workspaces.
# We still build the JDK files here to verify the files compile, and in
# preparation for possible signing. Developers working on JCE in JDK
# must sign the JCE files before testing. The JCE signing key is kept
# separate from the JDK workspace to prevent its disclosure.
#
# SPECIAL NOTE TO JCE/JDK developers: The source files must eventually
# be built, signed, and then the resulting jar files MUST BE CHECKED
# INTO THE CLOSED PART OF THE WORKSPACE*. This separate step *MUST NOT
# BE FORGOTTEN*, otherwise a bug fixed in the source code will not be
# reflected in the shipped binaries. The "release" target should be
# used to generate the required files.
#
# There are a number of targets to help both JDK/OpenJDK developers.
#
# Main Targets (JDK/OPENJDK):
#
# all/clobber/clean The usual, plus the native libraries.
# If OpenJDK, installs sunec.jar.
# If JDK, installs prebuilt
# sunec.jar.
#
# jar Builds/installs sunec.jar
# If OpenJDK, does not sign.
# If JDK, tries to sign.
#
# Other lesser-used Targets (JDK/OPENJDK):
#
# build-jar Builds sunec.jar
# (does not sign/install)
#
# install-jar Alias for "jar" above.
#
# Other targets (JDK only):
#
# sign Alias for sign-jar
# sign-jar Builds/signs sunec.jar (no install)
#
# release Builds all targets in preparation
# for workspace integration.
#
# install-prebuilt Installs the pre-built jar files
#
# This makefile was written to support parallel target execution.
#
BUILDDIR = ../../..
PACKAGE = sun.security.ec
PRODUCT = sun
#
# The following is for when we need to do postprocessing
# (signing) against a read-only build. If the OUTPUTDIR
# isn't writable, the build currently crashes out.
#
ifndef OPENJDK
ifdef ALT_JCE_BUILD_DIR
# =====================================================
# Where to place the output, in case we're building from a read-only
# build area. (e.g. a release engineering build.)
JCE_BUILD_DIR=${ALT_JCE_BUILD_DIR}
IGNORE_WRITABLE_OUTPUTDIR_TEST=true
else
JCE_BUILD_DIR=${TEMPDIR}
endif
endif
include $(BUILDDIR)/common/Defs.gmk
#
# Location for the newly built classfiles.
#
CLASSDESTDIR = $(TEMPDIR)/classes
#
# Java files
#
AUTO_FILES_JAVA_DIRS = $(PKGDIR)
include $(BUILDDIR)/common/Classes.gmk
#
# Some licensees do not get the native ECC sources, but we still need to
# be able to build "all" for them. Check here to see if the sources are
# available. If not, then skip them.
#
NATIVE_ECC_AVAILABLE := $(shell \
if [ -d $(SHARE_SRC)/native/$(PKGDIR) ] ; then \
$(ECHO) true; \
else \
$(ECHO) false; \
fi)
ifeq ($(NATIVE_ECC_AVAILABLE), true)
LIBRARY = sunecc
#
# Java files that define native methods
#
FILES_export = \
$(PKGDIR)/ECDHKeyAgreement.java \
$(PKGDIR)/ECDSASignature.java \
$(PKGDIR)/ECKeyPairGenerator.java
JAVAHFLAGS += -classpath $(CLASSDESTDIR)
#
# C and C++ files
#
include FILES_c.gmk
FILES_cpp = ECC_JNI.cpp
CPLUSPLUSLIBRARY=true
FILES_m = mapfile-vers
#
# Find native code
#
vpath %.cpp $(SHARE_SRC)/native/$(PKGDIR)
vpath %.c $(SHARE_SRC)/native/$(PKGDIR)
#
# Find include files
#
OTHER_INCLUDES += -I$(SHARE_SRC)/native/$(PKGDIR)
#
# Compiler flags
#
OTHER_CFLAGS += -DMP_API_COMPATIBLE -DNSS_ECC_MORE_THAN_SUITE_B
#
# Libraries to link
#
ifeq ($(PLATFORM), windows)
OTHER_LDLIBS += $(JVMLIB)
else
OTHER_LDLIBS = -ldl $(JVMLIB) $(LIBCXX)
endif
include $(BUILDDIR)/common/Mapfile-vers.gmk
include $(BUILDDIR)/common/Library.gmk
endif # NATIVE_ECC_AVAILABLE
#
# We use a variety of subdirectories in the $(TEMPDIR) depending on what
# part of the build we're doing. Both OPENJDK/JDK builds are initially
# done in the unsigned area. When files are signed in JDK,
# they will be placed in the appropriate area.
#
UNSIGNED_DIR = $(TEMPDIR)/unsigned
include $(BUILDDIR)/javax/crypto/Defs-jce.gmk
#
# Rules
#
ifdef OPENJDK
all: build-jar install-jar
else
all: build-jar install-prebuilt
$(build-warning)
endif
# =====================================================
# Build the unsigned sunec.jar file.
#
JAR_DESTFILE = $(EXTDIR)/sunec.jar
#
# Since the -C option to jar is used below, each directory entry must be
# preceded with the appropriate directory to "cd" into.
#
JAR_DIRS = $(patsubst %, -C $(CLASSDESTDIR) %, $(AUTO_FILES_JAVA_DIRS))
build-jar: $(UNSIGNED_DIR)/sunec.jar
#
# Build sunec.jar.
#
$(UNSIGNED_DIR)/sunec.jar: build
$(prep-target)
$(BOOT_JAR_CMD) cf $@ $(JAR_DIRS) \
$(BOOT_JAR_JFLAGS)
@$(java-vm-cleanup)
ifndef OPENJDK
# =====================================================
# Sign the provider jar file. Not needed for OpenJDK.
#
SIGNED_DIR = $(JCE_BUILD_DIR)/signed
sign: sign-jar
sign-jar: $(SIGNED_DIR)/sunec.jar
ifndef ALT_JCE_BUILD_DIR
$(SIGNED_DIR)/sunec.jar: $(UNSIGNED_DIR)/sunec.jar
else
#
# We have to remove the build dependency, otherwise, we'll try to rebuild it
# which we can't do on a read-only filesystem.
#
$(SIGNED_DIR)/sunec.jar:
@if [ ! -r $(UNSIGNED_DIR)/sunec.jar ] ; then \
$(ECHO) "Couldn't find $(UNSIGNED_DIR)/sunec.jar"; \
exit 1; \
fi
endif
$(call sign-file, $(UNSIGNED_DIR)/sunec.jar)
# =====================================================
# Create the Release Engineering files. Signed builds, etc.
#
release: $(SIGNED_DIR)/sunec.jar
$(RM) $(JCE_BUILD_DIR)/release/sunec.jar
$(MKDIR) -p $(JCE_BUILD_DIR)/release
$(CP) $(SIGNED_DIR)/sunec.jar $(JCE_BUILD_DIR)/release
$(release-warning)
endif # OPENJDK
# =====================================================
# Install routines.
#
#
# Install sunec.jar, depending on which type is requested.
#
install-jar jar: $(JAR_DESTFILE)
ifndef OPENJDK
$(release-warning)
endif
ifdef OPENJDK
$(JAR_DESTFILE): $(UNSIGNED_DIR)/sunec.jar
else
$(JAR_DESTFILE): $(SIGNED_DIR)/sunec.jar
endif
$(install-file)
ifndef OPENJDK
install-prebuilt:
@$(ECHO) "\n>>>Installing prebuilt SunEC provider..."
$(RM) $(JAR_DESTFILE)
$(CP) $(PREBUILT_DIR)/ec/sunec.jar $(JAR_DESTFILE)
endif
# =====================================================
# Support routines.
#
clobber clean::
$(RM) -r $(JAR_DESTFILE) $(TEMPDIR) $(JCE_BUILD_DIR)
.PHONY: build-jar jar install-jar
ifndef OPENJDK
.PHONY: sign sign-jar release install-prebuilt
endif
#
# Copyright 2009 Sun Microsystems, Inc. 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. Sun designates this
# particular file as subject to the "Classpath" exception as provided
# by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
# CA 95054 USA or visit www.sun.com if you need additional information or
# have any questions.
#
# Define public interface.
SUNWprivate_1.1 {
global:
Java_sun_security_ec_ECKeyPairGenerator_generateECKeyPair;
Java_sun_security_ec_ECKeyPairGenerator_getEncodedBytes;
Java_sun_security_ec_ECDSASignature_signDigest;
Java_sun_security_ec_ECDSASignature_verifySignedDigest;
Java_sun_security_ec_ECDHKeyAgreement_deriveKey;
local:
*;
};
# #
# Copyright 1996-2007 Sun Microsystems, Inc. All Rights Reserved. # Copyright 1996-2009 Sun Microsystems, Inc. All Rights Reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
# #
# This code is free software; you can redistribute it and/or modify it # This code is free software; you can redistribute it and/or modify it
...@@ -33,7 +33,6 @@ include $(BUILDDIR)/common/Defs.gmk ...@@ -33,7 +33,6 @@ include $(BUILDDIR)/common/Defs.gmk
# #
AUTO_FILES_JAVA_DIRS = \ AUTO_FILES_JAVA_DIRS = \
sun/security/acl \ sun/security/acl \
sun/security/ec \
sun/security/jca \ sun/security/jca \
sun/security/pkcs \ sun/security/pkcs \
sun/security/pkcs12 \ sun/security/pkcs12 \
......
0x15 U+0085 #
# The diff of 01A434B0.TXMAP110 and 34B001A4.RXMAP110
#
# Added: 0x15 U+0085
#
0x15 U+0085
0x42 U+FE7C
0x46 U+FE80
0x47 U+FE81
0x49 U+FE83
0x4B U+066C
0x4B U+FF0E
0x4C U+FF1C
0x4D U+FF08
0x4E U+FF0B
0x4F U+FF5C
0x50 U+FF06
0x52 U+FE85
0x52 U+FE86
0x55 U+FE89
0x55 U+FE8A
0x55 U+FE8B
0x55 U+FE8C
0x56 U+0625
0x56 U+FE87
0x56 U+FE8D
0x57 U+FE88
0x58 U+FE8F
0x58 U+FE90
0x59 U+FE92
0x5A U+FF01
0x5B U+FF04
0x5C U+066D
0x5C U+FF0A
0x5D U+FF09
0x5E U+FF1B
0x60 U+FF0D
0x61 U+FF0F
0x62 U+FE93
0x62 U+FE94
0x63 U+FE95
0x63 U+FE96
0x64 U+FE98
0x65 U+FE99
0x65 U+FE9A
0x66 U+FE9C
0x67 U+FE9D
0x67 U+FE9E
0x68 U+FEA0
0x69 U+FEA1
0x69 U+FEA2
0x6B U+066B
0x6B U+FF0C
0x6C U+066A
0x6C U+FF05
0x6D U+FF3F
0x6E U+FF1E
0x6F U+FF1F
0x70 U+FEA4
0x71 U+FEA5
0x71 U+FEA6
0x72 U+FEA8
0x73 U+FEA9
0x73 U+FEAA
0x74 U+FEAB
0x74 U+FEAC
0x75 U+FEAD
0x75 U+FEAE
0x76 U+FEAF
0x76 U+FEB0
0x77 U+FEB1
0x77 U+FEB2
0x78 U+FEB4
0x7A U+FF1A
0x7B U+FF03
0x7C U+FF20
0x7D U+FF07
0x7E U+FF1D
0x7F U+FF02
0x80 U+FEB5
0x80 U+FEB6
0x81 U+FF41
0x82 U+FF42
0x83 U+FF43
0x84 U+FF44
0x85 U+FF45
0x86 U+FF46
0x87 U+FF47
0x88 U+FF48
0x89 U+FF49
0x8A U+FEB8
0x8B U+FEB9
0x8B U+FEBA
0x8C U+FEBC
0x8D U+FEBD
0x8D U+FEBE
0x8E U+FEC0
0x8F U+FEC1
0x8F U+FEC2
0x8F U+FEC3
0x8F U+FEC4
0x90 U+FEC5
0x90 U+FEC6
0x90 U+FEC7
0x90 U+FEC8
0x91 U+FF4A
0x92 U+FF4B
0x93 U+FF4C
0x94 U+FF4D
0x95 U+FF4E
0x96 U+FF4F
0x97 U+FF50
0x98 U+FF51
0x99 U+FF52
0x9A U+FEC9
0x9E U+FECD
0xA2 U+FF53
0xA3 U+FF54
0xA4 U+FF55
0xA5 U+FF56
0xA6 U+FF57
0xA7 U+FF58
0xA8 U+FF59
0xA9 U+FF5A
0xAB U+FED1
0xAB U+FED2
0xAC U+FED4
0xAD U+FED5
0xAD U+FED6
0xAE U+FED8
0xAF U+FED9
0xAF U+FEDA
0xB0 U+FEDC
0xB1 U+FEDD
0xB1 U+FEDE
0xB8 U+FEF9
0xB9 U+FEFA
0xBA U+FEE0
0xBB U+FEE1
0xBB U+FEE2
0xBC U+FEE4
0xBD U+FEE5
0xBD U+FEE6
0xBE U+FEE8
0xBF U+FEE9
0xBF U+FEEA
0xC1 U+FF21
0xC2 U+FF22
0xC3 U+FF23
0xC4 U+FF24
0xC5 U+FF25
0xC6 U+FF26
0xC7 U+FF27
0xC8 U+FF28
0xC9 U+FF29
0xCF U+FEED
0xCF U+FEEE
0xD1 U+FF2A
0xD2 U+FF2B
0xD3 U+FF2C
0xD4 U+FF2D
0xD5 U+FF2E
0xD6 U+FF2F
0xD7 U+FF30
0xD8 U+FF31
0xD9 U+FF32
0xDA U+FEEF
0xDC U+FEF1
0xDE U+FEF4
0xE2 U+FF33
0xE3 U+FF34
0xE4 U+FF35
0xE5 U+FF36
0xE6 U+FF37
0xE7 U+FF38
0xE8 U+FF39
0xE9 U+FF3A
0xF0 U+FF10
0xF1 U+FF11
0xF2 U+FF12
0xF3 U+FF13
0xF4 U+FF14
0xF5 U+FF15
0xF6 U+FF16
0xF7 U+FF17
0xF8 U+FF18
0xF9 U+FF19
#Generated from IBM420.java #
0x00 U+0000 # Frm IBMCDC datatable 01A434B0.TXMAP110
0x01 U+0001 #
0x02 U+0002 # Changed
0x03 U+0003 # 0x15 U+0085 -> 0x15 U+000a
0x04 U+009c #
0x05 U+0009 0x00 U+0000
0x06 U+0086 0x01 U+0001
0x07 U+007f 0x02 U+0002
0x08 U+0097 0x03 U+0003
0x09 U+008d 0x04 U+009C
0x0a U+008e 0x05 U+0009
0x0b U+000b 0x06 U+0086
0x0c U+000c 0x07 U+007F
0x0d U+000d 0x08 U+0097
0x0e U+000e 0x09 U+008D
0x0f U+000f 0x0A U+008E
0x10 U+0010 0x0B U+000B
0x11 U+0011 0x0C U+000C
0x12 U+0012 0x0D U+000D
0x13 U+0013 0x0E U+000E
0x14 U+009d 0x0F U+000F
0x15 U+000a 0x10 U+0010
0x16 U+0008 0x11 U+0011
0x17 U+0087 0x12 U+0012
0x18 U+0018 0x13 U+0013
0x19 U+0019 0x14 U+009D
0x1a U+0092 0x15 U+000A
0x1b U+008f 0x16 U+0008
0x1c U+001c 0x17 U+0087
0x1d U+001d 0x18 U+0018
0x1e U+001e 0x19 U+0019
0x1f U+001f 0x1A U+0092
0x20 U+0080 0x1B U+008F
0x21 U+0081 0x1C U+001C
0x22 U+0082 0x1D U+001D
0x23 U+0083 0x1E U+001E
0x24 U+0084 0x1F U+001F
0x25 U+000a 0x20 U+0080
0x26 U+0017 0x21 U+0081
0x27 U+001b 0x22 U+0082
0x28 U+0088 0x23 U+0083
0x29 U+0089 0x24 U+0084
0x2a U+008a 0x25 U+000A
0x2b U+008b 0x26 U+0017
0x2c U+008c 0x27 U+001B
0x2d U+0005 0x28 U+0088
0x2e U+0006 0x29 U+0089
0x2f U+0007 0x2A U+008A
0x30 U+0090 0x2B U+008B
0x31 U+0091 0x2C U+008C
0x32 U+0016 0x2D U+0005
0x33 U+0093 0x2E U+0006
0x34 U+0094 0x2F U+0007
0x35 U+0095 0x30 U+0090
0x36 U+0096 0x31 U+0091
0x37 U+0004 0x32 U+0016
0x38 U+0098 0x33 U+0093
0x39 U+0099 0x34 U+0094
0x3a U+009a 0x35 U+0095
0x3b U+009b 0x36 U+0096
0x3c U+0014 0x37 U+0004
0x3d U+0015 0x38 U+0098
0x3e U+009e 0x39 U+0099
0x3f U+001a 0x3A U+009A
0x40 U+0020 0x3B U+009B
0x41 U+00a0 0x3C U+0014
0x42 U+fe7c 0x3D U+0015
0x43 U+fe7d 0x3E U+009E
0x44 U+0640 0x3F U+001A
0x45 U+f8fc 0x40 U+0020
0x46 U+fe80 0x41 U+00A0
0x47 U+fe81 0x42 U+0651
0x48 U+fe82 0x43 U+FE7D
0x49 U+fe83 0x44 U+0640
0x4a U+00a2 0x45 U+200B
0x4b U+002e 0x46 U+0621
0x4c U+003c 0x47 U+0622
0x4d U+0028 0x48 U+FE82
0x4e U+002b 0x49 U+0623
0x4f U+007c 0x4A U+00A2
0x50 U+0026 0x4B U+002E
0x51 U+fe84 0x4C U+003C
0x52 U+fe85 0x4D U+0028
0x53 U+fffd 0x4E U+002B
0x54 U+fffd 0x4F U+007C
0x55 U+fe8b 0x50 U+0026
0x56 U+fe8d 0x51 U+FE84
0x57 U+fe8e 0x52 U+0624
0x58 U+fe8f 0x55 U+0626
0x59 U+fe91 0x56 U+0627
0x5a U+0021 0x57 U+FE8E
0x5b U+0024 0x58 U+0628
0x5c U+002a 0x59 U+FE91
0x5d U+0029 0x5A U+0021
0x5e U+003b 0x5B U+0024
0x5f U+00ac 0x5C U+002A
0x60 U+002d 0x5D U+0029
0x61 U+002f 0x5E U+003B
0x62 U+fe93 0x5F U+00AC
0x63 U+fe95 0x60 U+002D
0x64 U+fe97 0x61 U+002F
0x65 U+fe99 0x62 U+0629
0x66 U+fe9b 0x63 U+062A
0x67 U+fe9d 0x64 U+FE97
0x68 U+fe9f 0x65 U+062B
0x69 U+fea1 0x66 U+FE9B
0x6a U+00a6 0x67 U+062C
0x6b U+002c 0x68 U+FE9F
0x6c U+0025 0x69 U+062D
0x6d U+005f 0x6A U+00A6
0x6e U+003e 0x6B U+002C
0x6f U+003f 0x6C U+0025
0x70 U+fea3 0x6D U+005F
0x71 U+fea5 0x6E U+003E
0x72 U+fea7 0x6F U+003F
0x73 U+fea9 0x70 U+FEA3
0x74 U+feab 0x71 U+062E
0x75 U+fead 0x72 U+FEA7
0x76 U+feaf 0x73 U+062F
0x77 U+f8f6 0x74 U+0630
0x78 U+feb3 0x75 U+0631
0x79 U+060c 0x76 U+0632
0x7a U+003a 0x77 U+0633
0x7b U+0023 0x78 U+FEB3
0x7c U+0040 0x79 U+060C
0x7d U+0027 0x7A U+003A
0x7e U+003d 0x7B U+0023
0x7f U+0022 0x7C U+0040
0x80 U+f8f5 0x7D U+0027
0x81 U+0061 0x7E U+003D
0x82 U+0062 0x7F U+0022
0x83 U+0063 0x80 U+0634
0x84 U+0064 0x81 U+0061
0x85 U+0065 0x82 U+0062
0x86 U+0066 0x83 U+0063
0x87 U+0067 0x84 U+0064
0x88 U+0068 0x85 U+0065
0x89 U+0069 0x86 U+0066
0x8a U+feb7 0x87 U+0067
0x8b U+f8f4 0x88 U+0068
0x8c U+febb 0x89 U+0069
0x8d U+f8f7 0x8A U+FEB7
0x8e U+febf 0x8B U+0635
0x8f U+fec3 0x8C U+FEBB
0x90 U+fec7 0x8D U+0636
0x91 U+006a 0x8E U+FEBF
0x92 U+006b 0x8F U+0637
0x93 U+006c 0x90 U+0638
0x94 U+006d 0x91 U+006A
0x95 U+006e 0x92 U+006B
0x96 U+006f 0x93 U+006C
0x97 U+0070 0x94 U+006D
0x98 U+0071 0x95 U+006E
0x99 U+0072 0x96 U+006F
0x9a U+fec9 0x97 U+0070
0x9b U+feca 0x98 U+0071
0x9c U+fecb 0x99 U+0072
0x9d U+fecc 0x9A U+0639
0x9e U+fecd 0x9B U+FECA
0x9f U+fece 0x9C U+FECB
0xa0 U+fecf 0x9D U+FECC
0xa1 U+00f7 0x9E U+063A
0xa2 U+0073 0x9F U+FECE
0xa3 U+0074 0xA0 U+FECF
0xa4 U+0075 0xA1 U+00F7
0xa5 U+0076 0xA2 U+0073
0xa6 U+0077 0xA3 U+0074
0xa7 U+0078 0xA4 U+0075
0xa8 U+0079 0xA5 U+0076
0xa9 U+007a 0xA6 U+0077
0xaa U+fed0 0xA7 U+0078
0xab U+fed1 0xA8 U+0079
0xac U+fed3 0xA9 U+007A
0xad U+fed5 0xAA U+FED0
0xae U+fed7 0xAB U+0641
0xaf U+fed9 0xAC U+FED3
0xb0 U+fedb 0xAD U+0642
0xb1 U+fedd 0xAE U+FED7
0xb2 U+fef5 0xAF U+0643
0xb3 U+fef6 0xB0 U+FEDB
0xb4 U+fef7 0xB1 U+0644
0xb5 U+fef8 0xB2 U+FEF5
0xb6 U+fffd 0xB3 U+FEF6
0xb7 U+fffd 0xB4 U+FEF7
0xb8 U+fefb 0xB5 U+FEF8
0xb9 U+fefc 0xB8 U+FEFB
0xba U+fedf 0xB9 U+FEFC
0xbb U+fee1 0xBA U+FEDF
0xbc U+fee3 0xBB U+0645
0xbd U+fee5 0xBC U+FEE3
0xbe U+fee7 0xBD U+0646
0xbf U+fee9 0xBE U+FEE7
0xc0 U+061b 0xBF U+0647
0xc1 U+0041 0xC0 U+061B
0xc2 U+0042 0xC1 U+0041
0xc3 U+0043 0xC2 U+0042
0xc4 U+0044 0xC3 U+0043
0xc5 U+0045 0xC4 U+0044
0xc6 U+0046 0xC5 U+0045
0xc7 U+0047 0xC6 U+0046
0xc8 U+0048 0xC7 U+0047
0xc9 U+0049 0xC8 U+0048
0xca U+00ad 0xC9 U+0049
0xcb U+feeb 0xCA U+00AD
0xcc U+fffd 0xCB U+FEEB
0xcd U+feec 0xCD U+FEEC
0xce U+fffd 0xCF U+0648
0xcf U+feed 0xD0 U+061F
0xd0 U+061f 0xD1 U+004A
0xd1 U+004a 0xD2 U+004B
0xd2 U+004b 0xD3 U+004C
0xd3 U+004c 0xD4 U+004D
0xd4 U+004d 0xD5 U+004E
0xd5 U+004e 0xD6 U+004F
0xd6 U+004f 0xD7 U+0050
0xd7 U+0050 0xD8 U+0051
0xd8 U+0051 0xD9 U+0052
0xd9 U+0052 0xDA U+0649
0xda U+feef 0xDB U+FEF0
0xdb U+fef0 0xDC U+064A
0xdc U+fef1 0xDD U+FEF2
0xdd U+fef2 0xDE U+FEF3
0xde U+fef3 0xDF U+0660
0xdf U+0660 0xE0 U+00D7
0xe0 U+00d7 0xE2 U+0053
0xe1 U+2007 0xE3 U+0054
0xe2 U+0053 0xE4 U+0055
0xe3 U+0054 0xE5 U+0056
0xe4 U+0055 0xE6 U+0057
0xe5 U+0056 0xE7 U+0058
0xe6 U+0057 0xE8 U+0059
0xe7 U+0058 0xE9 U+005A
0xe8 U+0059 0xEA U+0661
0xe9 U+005a 0xEB U+0662
0xea U+0661 0xED U+0663
0xeb U+0662 0xEE U+0664
0xec U+fffd 0xEF U+0665
0xed U+0663 0xF0 U+0030
0xee U+0664 0xF1 U+0031
0xef U+0665 0xF2 U+0032
0xf0 U+0030 0xF3 U+0033
0xf1 U+0031 0xF4 U+0034
0xf2 U+0032 0xF5 U+0035
0xf3 U+0033 0xF6 U+0036
0xf4 U+0034 0xF7 U+0037
0xf5 U+0035 0xF8 U+0038
0xf6 U+0036 0xF9 U+0039
0xf7 U+0037 0xFB U+0666
0xf8 U+0038 0xFC U+0667
0xf9 U+0039 0xFD U+0668
0xfa U+fffd 0xFE U+0669
0xfb U+0666 0xFF U+009F
0xfc U+0667
0xfd U+0668
0xfe U+0669
0xff U+009f
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
package build.tools.charsetmapping; package build.tools.charsetmapping;
import java.io.*; import java.io.*;
import java.util.Arrays;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Scanner; import java.util.Scanner;
import java.util.Formatter; import java.util.Formatter;
...@@ -54,33 +55,19 @@ public class GenerateSBCS { ...@@ -54,33 +55,19 @@ public class GenerateSBCS {
String pkgName = fields[4]; String pkgName = fields[4];
System.out.printf("%s,%s,%s,%b,%s%n", clzName, csName, hisName, isASCII, pkgName); System.out.printf("%s,%s,%s,%b,%s%n", clzName, csName, hisName, isASCII, pkgName);
StringBuilder b2c = new StringBuilder(); genClass(args[0], args[1], "SingleByte-X.java",
int c2bLen = genB2C( clzName, csName, hisName, pkgName, isASCII);
new FileInputStream(new File(args[0], clzName+".map")), b2c);
String b2cNR = null;
File nrF = new File(args[0], clzName+".nr");
if (nrF.exists()) {
b2cNR = genNR(new FileInputStream(nrF));
}
String c2bNR = null;
File c2bF = new File(args[0], clzName+".c2b");
if (c2bF.exists()) {
c2bNR = genC2BNR(new FileInputStream(c2bF));
}
genSBCSClass(args[0], args[1], "SingleByte-X.java",
clzName, csName, hisName, pkgName, isASCII,
b2c.toString(), b2cNR, c2bNR, c2bLen);
} }
} }
private static void toString(char[] sb, int off, int end, private static void toString(char[] sb, int off, int end,
Formatter out, String closure) { Formatter out, String closure,
boolean comment) {
while (off < end) { while (off < end) {
out.format(" \""); out.format(" \"");
for (int j = 0; j < 8; j++) { for (int j = 0; j < 8; j++) {
if (off == end)
break;
char c = sb[off++]; char c = sb[off++];
switch (c) { switch (c) {
case '\b': case '\b':
...@@ -103,101 +90,124 @@ public class GenerateSBCS { ...@@ -103,101 +90,124 @@ public class GenerateSBCS {
out.format("\\u%04X", c & 0xffff); out.format("\\u%04X", c & 0xffff);
} }
} }
if (off == end) if (comment) {
out.format("\" %s // 0x%02x - 0x%02x%n", closure, off-8, off-1); if (off == end)
else out.format("\" %s // 0x%02x - 0x%02x%n",
out.format("\" + // 0x%02x - 0x%02x%n", off-8, off-1); closure, off-8, off-1);
else
out.format("\" + // 0x%02x - 0x%02x%n",
off-8, off-1);
} else {
if (off == end)
out.format("\"%s%n", closure);
else
out.format("\" +%n");
}
} }
} }
static Pattern sbmap = Pattern.compile("0x(\\p{XDigit}++)\\s++U\\+(\\p{XDigit}++)(\\s++#.*)?"); static Pattern sbmap = Pattern.compile("0x(\\p{XDigit}++)\\s++U\\+(\\p{XDigit}++)(\\s++#.*)?");
private static int genB2C(InputStream in, StringBuilder out)
private static void genClass(String srcDir, String dstDir,
String template,
String clzName,
String csName,
String hisName,
String pkgName,
boolean isASCII)
throws Exception throws Exception
{ {
char[] sb = new char[0x100]; StringBuilder b2cSB = new StringBuilder();
int[] indexC2B = new int[0x100]; StringBuilder b2cNRSB = new StringBuilder();
StringBuilder c2bNRSB = new StringBuilder();
for (int i = 0; i < sb.length; i++) char[] sb = new char[0x100];
sb[i] = UNMAPPABLE_DECODING; char[] c2bIndex = new char[0x100];
int c2bOff = 0;
Arrays.fill(sb, UNMAPPABLE_DECODING);
Arrays.fill(c2bIndex, UNMAPPABLE_DECODING);
// parse the b2c mapping table // (1)read in .map to parse all b->c entries
FileInputStream in = new FileInputStream(
new File(srcDir, clzName + ".map"));
Parser p = new Parser(in, sbmap); Parser p = new Parser(in, sbmap);
Entry e = null; Entry e = null;
int off = 0;
while ((e = p.next()) != null) { while ((e = p.next()) != null) {
sb[e.bs] = (char)e.cp; sb[e.bs] = (char)e.cp;
if (indexC2B[e.cp>>8] == 0) { if (c2bIndex[e.cp>>8] == UNMAPPABLE_DECODING) {
off += 0x100; c2bOff += 0x100;
indexC2B[e.cp>>8] = 1; c2bIndex[e.cp>>8] = 1;
} }
} }
Formatter fm = new Formatter(out); Formatter fm = new Formatter(b2cSB);
fm.format("%n"); fm.format("%n");
// vm -server shows cc[byte + 128] access is much faster than // vm -server shows cc[byte + 128] access is much faster than
// cc[byte&0xff] so we output the upper segment first // cc[byte&0xff] so we output the upper segment first
toString(sb, 0x80, 0x100, fm, "+"); toString(sb, 0x80, 0x100, fm, "+", true);
toString(sb, 0x00, 0x80, fm, ";"); toString(sb, 0x00, 0x80, fm, ";", true);
fm.close(); fm.close();
return off;
}
// generate non-roundtrip entries from xxx.nr file // (2)now the .nr file which includes "b->c" non-roundtrip entries
private static String genNR(InputStream in) throws Exception File f = new File(srcDir, clzName + ".nr");
{ if (f.exists()) {
StringBuilder sb = new StringBuilder(); in = new FileInputStream(f);
Formatter fm = new Formatter(sb); fm = new Formatter(b2cNRSB);
Parser p = new Parser(in, sbmap); p = new Parser(in, sbmap);
Entry e = null; e = null;
fm.format("// remove non-roundtrip entries%n");
fm.format(" b2cMap = b2cTable.toCharArray();%n");
while ((e = p.next()) != null) {
fm.format(" b2cMap[%d] = UNMAPPABLE_DECODING;%n",
(e.bs>=0x80)?(e.bs-0x80):(e.bs+0x80));
}
fm.close();
return sb.toString();
}
// generate c2b only entries from xxx.c2b file fm.format("// remove non-roundtrip entries%n");
private static String genC2BNR(InputStream in) throws Exception fm.format(" b2cMap = b2cTable.toCharArray();%n");
{ while ((e = p.next()) != null) {
StringBuilder sb = new StringBuilder(); fm.format(" b2cMap[%d] = UNMAPPABLE_DECODING;%n",
Formatter fm = new Formatter(sb); (e.bs>=0x80)?(e.bs-0x80):(e.bs+0x80));
Parser p = new Parser(in, sbmap); }
ArrayList<Entry> es = new ArrayList<Entry>(); fm.close();
Entry e = null;
while ((e = p.next()) != null) {
es.add(e);
} }
fm.format("// non-roundtrip c2b only entries%n"); // (3)finally the .c2b file which includes c->b non-roundtrip entries
fm.format(" c2bNR = new char[%d];%n", es.size() * 2); f = new File(srcDir, clzName + ".c2b");
int i = 0; if (f.exists()) {
for (Entry entry: es) { in = new FileInputStream(f);
fm.format(" c2bNR[%d] = 0x%x; c2bNR[%d] = 0x%x;%n", fm = new Formatter(c2bNRSB);
i++, entry.bs, i++, entry.cp); p = new Parser(in, sbmap);
e = null;
ArrayList<Entry> es = new ArrayList<Entry>();
while ((e = p.next()) != null) {
if (c2bIndex[e.cp>>8] == UNMAPPABLE_DECODING) {
c2bOff += 0x100;
c2bIndex[e.cp>>8] = 1;
}
es.add(e);
}
fm.format("// non-roundtrip c2b only entries%n");
if (es.size() < 100) {
fm.format(" c2bNR = new char[%d];%n", es.size() * 2);
int i = 0;
for (Entry entry: es) {
fm.format(" c2bNR[%d] = 0x%x; c2bNR[%d] = 0x%x;%n",
i++, entry.bs, i++, entry.cp);
}
} else {
char[] cc = new char[es.size() * 2];
int i = 0;
for (Entry entry: es) {
cc[i++] = (char)entry.bs;
cc[i++] = (char)entry.cp;
}
fm.format(" c2bNR = (%n");
toString(cc, 0, i, fm, ").toCharArray();", false);
}
fm.close();
} }
fm.close();
return sb.toString();
}
private static void genSBCSClass(String srcDir, // (4)it's time to generate the source file
String dstDir, String b2c = b2cSB.toString();
String template, String b2cNR = b2cNRSB.toString();
String clzName, String c2bNR = c2bNRSB.toString();
String csName,
String hisName,
String pkgName,
boolean isASCII,
String b2c,
String b2cNR,
String c2bNR,
int c2blen)
throws Exception
{
Scanner s = new Scanner(new File(srcDir, template)); Scanner s = new Scanner(new File(srcDir, template));
PrintStream out = new PrintStream(new FileOutputStream( PrintStream out = new PrintStream(new FileOutputStream(
new File(dstDir, clzName + ".java"))); new File(dstDir, clzName + ".java")));
...@@ -239,16 +249,16 @@ public class GenerateSBCS { ...@@ -239,16 +249,16 @@ public class GenerateSBCS {
line = line.replace("$B2CTABLE$", b2c); line = line.replace("$B2CTABLE$", b2c);
} }
if (line.indexOf("$C2BLENGTH$") != -1) { if (line.indexOf("$C2BLENGTH$") != -1) {
line = line.replace("$C2BLENGTH$", "0x" + Integer.toString(c2blen, 16)); line = line.replace("$C2BLENGTH$", "0x" + Integer.toString(c2bOff, 16));
} }
if (line.indexOf("$NONROUNDTRIP_B2C$") != -1) { if (line.indexOf("$NONROUNDTRIP_B2C$") != -1) {
if (b2cNR == null) if (b2cNR.length() == 0)
continue; continue;
line = line.replace("$NONROUNDTRIP_B2C$", b2cNR); line = line.replace("$NONROUNDTRIP_B2C$", b2cNR);
} }
if (line.indexOf("$NONROUNDTRIP_C2B$") != -1) { if (line.indexOf("$NONROUNDTRIP_C2B$") != -1) {
if (c2bNR == null) if (c2bNR.length() == 0)
continue; continue;
line = line.replace("$NONROUNDTRIP_C2B$", c2bNR); line = line.replace("$NONROUNDTRIP_C2B$", c2bNR);
} }
......
...@@ -51,7 +51,7 @@ public class BMPImageReaderSpi extends ImageReaderSpi { ...@@ -51,7 +51,7 @@ public class BMPImageReaderSpi extends ImageReaderSpi {
entensions, entensions,
mimeType, mimeType,
"com.sun.imageio.plugins.bmp.BMPImageReader", "com.sun.imageio.plugins.bmp.BMPImageReader",
STANDARD_INPUT_TYPE, new Class[] { ImageInputStream.class },
writerSpiNames, writerSpiNames,
false, false,
null, null, null, null, null, null, null, null,
......
...@@ -32,6 +32,7 @@ import java.awt.image.SinglePixelPackedSampleModel; ...@@ -32,6 +32,7 @@ import java.awt.image.SinglePixelPackedSampleModel;
import javax.imageio.spi.ImageWriterSpi; import javax.imageio.spi.ImageWriterSpi;
import javax.imageio.spi.ServiceRegistry; import javax.imageio.spi.ServiceRegistry;
import javax.imageio.spi.IIORegistry; import javax.imageio.spi.IIORegistry;
import javax.imageio.stream.ImageOutputStream;
import javax.imageio.ImageWriter; import javax.imageio.ImageWriter;
import javax.imageio.ImageTypeSpecifier; import javax.imageio.ImageTypeSpecifier;
import javax.imageio.IIOException; import javax.imageio.IIOException;
...@@ -55,7 +56,7 @@ public class BMPImageWriterSpi extends ImageWriterSpi { ...@@ -55,7 +56,7 @@ public class BMPImageWriterSpi extends ImageWriterSpi {
entensions, entensions,
mimeType, mimeType,
"com.sun.imageio.plugins.bmp.BMPImageWriter", "com.sun.imageio.plugins.bmp.BMPImageWriter",
STANDARD_OUTPUT_TYPE, new Class[] { ImageOutputStream.class },
readerSpiNames, readerSpiNames,
false, false,
null, null, null, null, null, null, null, null,
......
...@@ -60,7 +60,7 @@ public class GIFImageReaderSpi extends ImageReaderSpi { ...@@ -60,7 +60,7 @@ public class GIFImageReaderSpi extends ImageReaderSpi {
suffixes, suffixes,
MIMETypes, MIMETypes,
readerClassName, readerClassName,
STANDARD_INPUT_TYPE, new Class[] { ImageInputStream.class },
writerSpiNames, writerSpiNames,
true, true,
GIFStreamMetadata.nativeMetadataFormatName, GIFStreamMetadata.nativeMetadataFormatName,
......
...@@ -31,6 +31,7 @@ import java.util.Locale; ...@@ -31,6 +31,7 @@ import java.util.Locale;
import javax.imageio.ImageTypeSpecifier; import javax.imageio.ImageTypeSpecifier;
import javax.imageio.ImageWriter; import javax.imageio.ImageWriter;
import javax.imageio.spi.ImageWriterSpi; import javax.imageio.spi.ImageWriterSpi;
import javax.imageio.stream.ImageOutputStream;
import com.sun.imageio.plugins.common.PaletteBuilder; import com.sun.imageio.plugins.common.PaletteBuilder;
public class GIFImageWriterSpi extends ImageWriterSpi { public class GIFImageWriterSpi extends ImageWriterSpi {
...@@ -59,7 +60,7 @@ public class GIFImageWriterSpi extends ImageWriterSpi { ...@@ -59,7 +60,7 @@ public class GIFImageWriterSpi extends ImageWriterSpi {
suffixes, suffixes,
MIMETypes, MIMETypes,
writerClassName, writerClassName,
STANDARD_OUTPUT_TYPE, new Class[] { ImageOutputStream.class },
readerSpiNames, readerSpiNames,
true, true,
GIFWritableStreamMetadata.NATIVE_FORMAT_NAME, GIFWritableStreamMetadata.NATIVE_FORMAT_NAME,
......
...@@ -46,7 +46,7 @@ public class JPEGImageReaderSpi extends ImageReaderSpi { ...@@ -46,7 +46,7 @@ public class JPEGImageReaderSpi extends ImageReaderSpi {
JPEG.suffixes, JPEG.suffixes,
JPEG.MIMETypes, JPEG.MIMETypes,
"com.sun.imageio.plugins.jpeg.JPEGImageReader", "com.sun.imageio.plugins.jpeg.JPEGImageReader",
STANDARD_INPUT_TYPE, new Class[] { ImageInputStream.class },
writerSpiNames, writerSpiNames,
true, true,
JPEG.nativeStreamMetadataFormatName, JPEG.nativeStreamMetadataFormatName,
......
...@@ -28,6 +28,7 @@ package com.sun.imageio.plugins.jpeg; ...@@ -28,6 +28,7 @@ package com.sun.imageio.plugins.jpeg;
import javax.imageio.spi.ImageWriterSpi; import javax.imageio.spi.ImageWriterSpi;
import javax.imageio.spi.ServiceRegistry; import javax.imageio.spi.ServiceRegistry;
import javax.imageio.spi.IIORegistry; import javax.imageio.spi.IIORegistry;
import javax.imageio.stream.ImageOutputStream;
import javax.imageio.ImageWriter; import javax.imageio.ImageWriter;
import javax.imageio.ImageTypeSpecifier; import javax.imageio.ImageTypeSpecifier;
import javax.imageio.IIOException; import javax.imageio.IIOException;
...@@ -49,7 +50,7 @@ public class JPEGImageWriterSpi extends ImageWriterSpi { ...@@ -49,7 +50,7 @@ public class JPEGImageWriterSpi extends ImageWriterSpi {
JPEG.suffixes, JPEG.suffixes,
JPEG.MIMETypes, JPEG.MIMETypes,
"com.sun.imageio.plugins.jpeg.JPEGImageWriter", "com.sun.imageio.plugins.jpeg.JPEGImageWriter",
STANDARD_OUTPUT_TYPE, new Class[] { ImageOutputStream.class },
readerSpiNames, readerSpiNames,
true, true,
JPEG.nativeStreamMetadataFormatName, JPEG.nativeStreamMetadataFormatName,
......
...@@ -60,7 +60,7 @@ public class PNGImageReaderSpi extends ImageReaderSpi { ...@@ -60,7 +60,7 @@ public class PNGImageReaderSpi extends ImageReaderSpi {
suffixes, suffixes,
MIMETypes, MIMETypes,
readerClassName, readerClassName,
STANDARD_INPUT_TYPE, new Class[] { ImageInputStream.class },
writerSpiNames, writerSpiNames,
false, false,
null, null, null, null,
......
...@@ -34,6 +34,7 @@ import javax.imageio.ImageTypeSpecifier; ...@@ -34,6 +34,7 @@ import javax.imageio.ImageTypeSpecifier;
import javax.imageio.metadata.IIOMetadataFormat; import javax.imageio.metadata.IIOMetadataFormat;
import javax.imageio.metadata.IIOMetadataFormatImpl; import javax.imageio.metadata.IIOMetadataFormatImpl;
import javax.imageio.spi.ImageWriterSpi; import javax.imageio.spi.ImageWriterSpi;
import javax.imageio.stream.ImageOutputStream;
public class PNGImageWriterSpi extends ImageWriterSpi { public class PNGImageWriterSpi extends ImageWriterSpi {
...@@ -61,7 +62,7 @@ public class PNGImageWriterSpi extends ImageWriterSpi { ...@@ -61,7 +62,7 @@ public class PNGImageWriterSpi extends ImageWriterSpi {
suffixes, suffixes,
MIMETypes, MIMETypes,
writerClassName, writerClassName,
STANDARD_OUTPUT_TYPE, new Class[] { ImageOutputStream.class },
readerSpiNames, readerSpiNames,
false, false,
null, null, null, null,
......
...@@ -55,7 +55,7 @@ public class WBMPImageReaderSpi extends ImageReaderSpi { ...@@ -55,7 +55,7 @@ public class WBMPImageReaderSpi extends ImageReaderSpi {
entensions, entensions,
mimeType, mimeType,
"com.sun.imageio.plugins.wbmp.WBMPImageReader", "com.sun.imageio.plugins.wbmp.WBMPImageReader",
STANDARD_INPUT_TYPE, new Class[] { ImageInputStream.class },
writerSpiNames, writerSpiNames,
true, true,
null, null, null, null, null, null, null, null,
......
...@@ -28,6 +28,7 @@ package com.sun.imageio.plugins.wbmp; ...@@ -28,6 +28,7 @@ package com.sun.imageio.plugins.wbmp;
import javax.imageio.spi.ImageWriterSpi; import javax.imageio.spi.ImageWriterSpi;
import javax.imageio.spi.ServiceRegistry; import javax.imageio.spi.ServiceRegistry;
import javax.imageio.spi.IIORegistry; import javax.imageio.spi.IIORegistry;
import javax.imageio.stream.ImageOutputStream;
import javax.imageio.ImageWriter; import javax.imageio.ImageWriter;
import javax.imageio.ImageTypeSpecifier; import javax.imageio.ImageTypeSpecifier;
import javax.imageio.IIOException; import javax.imageio.IIOException;
...@@ -54,7 +55,7 @@ public class WBMPImageWriterSpi extends ImageWriterSpi { ...@@ -54,7 +55,7 @@ public class WBMPImageWriterSpi extends ImageWriterSpi {
entensions, entensions,
mimeType, mimeType,
"com.sun.imageio.plugins.wbmp.WBMPImageWriter", "com.sun.imageio.plugins.wbmp.WBMPImageWriter",
STANDARD_OUTPUT_TYPE, new Class[] { ImageOutputStream.class },
readerSpiNames, readerSpiNames,
true, true,
null, null, null, null, null, null, null, null,
......
...@@ -43,35 +43,35 @@ import javax.imageio.stream.ImageInputStream; ...@@ -43,35 +43,35 @@ import javax.imageio.stream.ImageInputStream;
*/ */
public class StreamCloser { public class StreamCloser {
private static WeakHashMap<ImageInputStream, Object> toCloseQueue; private static WeakHashMap<CloseAction, Object> toCloseQueue;
private static Thread streamCloser; private static Thread streamCloser;
public static void addToQueue(ImageInputStream iis) { public static void addToQueue(CloseAction ca) {
synchronized (StreamCloser.class) { synchronized (StreamCloser.class) {
if (toCloseQueue == null) { if (toCloseQueue == null) {
toCloseQueue = toCloseQueue =
new WeakHashMap<ImageInputStream, Object>(); new WeakHashMap<CloseAction, Object>();
} }
toCloseQueue.put(iis, null); toCloseQueue.put(ca, null);
if (streamCloser == null) { if (streamCloser == null) {
final Runnable streamCloserRunnable = new Runnable() { final Runnable streamCloserRunnable = new Runnable() {
public void run() { public void run() {
if (toCloseQueue != null) { if (toCloseQueue != null) {
synchronized (StreamCloser.class) { synchronized (StreamCloser.class) {
Set<ImageInputStream> set = Set<CloseAction> set =
toCloseQueue.keySet(); toCloseQueue.keySet();
// Make a copy of the set in order to avoid // Make a copy of the set in order to avoid
// concurrent modification (the is.close() // concurrent modification (the is.close()
// will in turn call removeFromQueue()) // will in turn call removeFromQueue())
ImageInputStream[] streams = CloseAction[] actions =
new ImageInputStream[set.size()]; new CloseAction[set.size()];
streams = set.toArray(streams); actions = set.toArray(actions);
for (ImageInputStream is : streams) { for (CloseAction ca : actions) {
if (is != null) { if (ca != null) {
try { try {
is.close(); ca.performAction();
} catch (IOException e) { } catch (IOException e) {
} }
} }
...@@ -106,10 +106,28 @@ public class StreamCloser { ...@@ -106,10 +106,28 @@ public class StreamCloser {
} }
} }
public static void removeFromQueue(ImageInputStream iis) { public static void removeFromQueue(CloseAction ca) {
synchronized (StreamCloser.class) { synchronized (StreamCloser.class) {
if (toCloseQueue != null) { if (toCloseQueue != null) {
toCloseQueue.remove(iis); toCloseQueue.remove(ca);
}
}
}
public static CloseAction createCloseAction(ImageInputStream iis) {
return new CloseAction(iis);
}
public static final class CloseAction {
private ImageInputStream iis;
private CloseAction(ImageInputStream iis) {
this.iis = iis;
}
public void performAction() throws IOException {
if (iis != null) {
iis.close();
} }
} }
} }
......
/* /*
* Copyright 2000-2007 Sun Microsystems, Inc. All Rights Reserved. * Copyright 2000-2009 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -922,7 +922,7 @@ public class DnsContext extends ComponentDirContext { ...@@ -922,7 +922,7 @@ public class DnsContext extends ComponentDirContext {
//---------- Debugging //---------- Debugging
public static boolean debug = false; private static final boolean debug = false;
private static final void dprint(String msg) { private static final void dprint(String msg) {
if (debug) { if (debug) {
...@@ -972,14 +972,11 @@ class NameClassPairEnumeration implements NamingEnumeration { ...@@ -972,14 +972,11 @@ class NameClassPairEnumeration implements NamingEnumeration {
} }
/* /*
* ctx will be closed when no longer needed by the enumeration. * ctx will be set to null when no longer needed by the enumeration.
*/ */
public void close () { public void close() {
nodes = null; nodes = null;
if (ctx != null) { ctx = null;
ctx.close();
ctx = null;
}
} }
public boolean hasMore() { public boolean hasMore() {
......
/* /*
* Copyright 1999-2007 Sun Microsystems, Inc. All Rights Reserved. * Copyright 1999-2009 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -41,6 +41,15 @@ import javax.sound.midi.spi.MidiFileWriter; ...@@ -41,6 +41,15 @@ import javax.sound.midi.spi.MidiFileWriter;
import javax.sound.midi.spi.SoundbankReader; import javax.sound.midi.spi.SoundbankReader;
import javax.sound.midi.spi.MidiDeviceProvider; import javax.sound.midi.spi.MidiDeviceProvider;
import javax.sound.midi.Receiver;
import javax.sound.midi.Sequencer;
import javax.sound.midi.Synthesizer;
import javax.sound.midi.Transmitter;
import javax.sound.sampled.Clip;
import javax.sound.sampled.Port;
import javax.sound.sampled.SourceDataLine;
import javax.sound.sampled.TargetDataLine;
/** /**
* JDK13Services uses the Service class in JDK 1.3 * JDK13Services uses the Service class in JDK 1.3
...@@ -186,6 +195,16 @@ public class JDK13Services { ...@@ -186,6 +195,16 @@ public class JDK13Services {
If the property is not set, null is returned. If the property is not set, null is returned.
*/ */
private static synchronized String getDefaultProvider(Class typeClass) { private static synchronized String getDefaultProvider(Class typeClass) {
if (!SourceDataLine.class.equals(typeClass)
&& !TargetDataLine.class.equals(typeClass)
&& !Clip.class.equals(typeClass)
&& !Port.class.equals(typeClass)
&& !Receiver.class.equals(typeClass)
&& !Transmitter.class.equals(typeClass)
&& !Synthesizer.class.equals(typeClass)
&& !Sequencer.class.equals(typeClass)) {
return null;
}
String value; String value;
String propertyName = typeClass.getName(); String propertyName = typeClass.getName();
value = JSSecurityManager.getProperty(propertyName); value = JSSecurityManager.getProperty(propertyName);
......
/* /*
* Copyright 1999-2007 Sun Microsystems, Inc. All Rights Reserved. * Copyright 1999-2009 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -283,28 +283,37 @@ class JSSecurityManager { ...@@ -283,28 +283,37 @@ class JSSecurityManager {
static List getProviders(final Class providerClass) { static List getProviders(final Class providerClass) {
PrivilegedAction action = new PrivilegedAction() { List p = new ArrayList();
public Object run() { // Service.providers(Class) just creates "lazy" iterator instance,
List p = new ArrayList(); // so it doesn't require do be called from privileged section
Iterator ps = Service.providers(providerClass); final Iterator ps = Service.providers(providerClass);
while (ps.hasNext()) {
try { // the iterator's hasNext() method looks through classpath for
Object provider = ps.next(); // the provider class names, so it requires read permissions
if (providerClass.isInstance(provider)) { PrivilegedAction<Boolean> hasNextAction = new PrivilegedAction<Boolean>() {
// $$mp 2003-08-22 public Boolean run() {
// Always adding at the beginning reverses the return ps.hasNext();
// order of the providers. So we no longer have }
// to do this in AudioSystem and MidiSystem. };
p.add(0, provider);
} while (AccessController.doPrivileged(hasNextAction)) {
} catch (Throwable t) { try {
//$$fb 2002-11-07: do not fail on SPI not found // the iterator's next() method creates instances of the
if (Printer.err) t.printStackTrace(); // providers and it should be called in the current security
} } // context
return p; Object provider = ps.next();
if (providerClass.isInstance(provider)) {
// $$mp 2003-08-22
// Always adding at the beginning reverses the
// order of the providers. So we no longer have
// to do this in AudioSystem and MidiSystem.
p.add(0, provider);
} }
}; } catch (Throwable t) {
List providers = (List) AccessController.doPrivileged(action); //$$fb 2002-11-07: do not fail on SPI not found
return providers; if (Printer.err) t.printStackTrace();
}
}
return p;
} }
} }
/* /*
* Copyright 1999-2007 Sun Microsystems, Inc. All Rights Reserved. * Copyright 1999-2009 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -82,7 +82,7 @@ public class StandardMidiFileWriter extends MidiFileWriter { ...@@ -82,7 +82,7 @@ public class StandardMidiFileWriter extends MidiFileWriter {
/** /**
* MIDI parser types * MIDI parser types
*/ */
public static final int types[] = { private static final int types[] = {
MIDI_TYPE_0, MIDI_TYPE_0,
MIDI_TYPE_1 MIDI_TYPE_1
}; };
......
...@@ -60,8 +60,14 @@ public abstract class IntegrityHmac extends SignatureAlgorithmSpi { ...@@ -60,8 +60,14 @@ public abstract class IntegrityHmac extends SignatureAlgorithmSpi {
*/ */
public abstract String engineGetURI(); public abstract String engineGetURI();
/**
* Returns the output length of the hash/digest.
*/
abstract int getDigestLength();
/** Field _macAlgorithm */ /** Field _macAlgorithm */
private Mac _macAlgorithm = null; private Mac _macAlgorithm = null;
private boolean _HMACOutputLengthSet = false;
/** Field _HMACOutputLength */ /** Field _HMACOutputLength */
int _HMACOutputLength = 0; int _HMACOutputLength = 0;
...@@ -100,7 +106,9 @@ public abstract class IntegrityHmac extends SignatureAlgorithmSpi { ...@@ -100,7 +106,9 @@ public abstract class IntegrityHmac extends SignatureAlgorithmSpi {
} }
public void reset() { public void reset() {
_HMACOutputLength=0; _HMACOutputLength=0;
_HMACOutputLengthSet = false;
_macAlgorithm.reset();
} }
/** /**
...@@ -115,14 +123,16 @@ public abstract class IntegrityHmac extends SignatureAlgorithmSpi { ...@@ -115,14 +123,16 @@ public abstract class IntegrityHmac extends SignatureAlgorithmSpi {
throws XMLSignatureException { throws XMLSignatureException {
try { try {
byte[] completeResult = this._macAlgorithm.doFinal(); if (this._HMACOutputLengthSet && this._HMACOutputLength < getDigestLength()) {
if (log.isLoggable(java.util.logging.Level.FINE)) {
if ((this._HMACOutputLength == 0) || (this._HMACOutputLength >= 160)) { log.log(java.util.logging.Level.FINE,
"HMACOutputLength must not be less than " + getDigestLength());
}
throw new XMLSignatureException("errorMessages.XMLSignatureException");
} else {
byte[] completeResult = this._macAlgorithm.doFinal();
return MessageDigestAlgorithm.isEqual(completeResult, signature); return MessageDigestAlgorithm.isEqual(completeResult, signature);
} }
byte[] stripped = IntegrityHmac.reduceBitLength(completeResult,
this._HMACOutputLength);
return MessageDigestAlgorithm.isEqual(stripped, signature);
} catch (IllegalStateException ex) { } catch (IllegalStateException ex) {
throw new XMLSignatureException("empty", ex); throw new XMLSignatureException("empty", ex);
} }
...@@ -176,14 +186,15 @@ public abstract class IntegrityHmac extends SignatureAlgorithmSpi { ...@@ -176,14 +186,15 @@ public abstract class IntegrityHmac extends SignatureAlgorithmSpi {
protected byte[] engineSign() throws XMLSignatureException { protected byte[] engineSign() throws XMLSignatureException {
try { try {
byte[] completeResult = this._macAlgorithm.doFinal(); if (this._HMACOutputLengthSet && this._HMACOutputLength < getDigestLength()) {
if (log.isLoggable(java.util.logging.Level.FINE)) {
if ((this._HMACOutputLength == 0) || (this._HMACOutputLength >= 160)) { log.log(java.util.logging.Level.FINE,
return completeResult; "HMACOutputLength must not be less than " + getDigestLength());
}
throw new XMLSignatureException("errorMessages.XMLSignatureException");
} else {
return this._macAlgorithm.doFinal();
} }
return IntegrityHmac.reduceBitLength(completeResult,
this._HMACOutputLength);
} catch (IllegalStateException ex) { } catch (IllegalStateException ex) {
throw new XMLSignatureException("empty", ex); throw new XMLSignatureException("empty", ex);
} }
...@@ -361,6 +372,7 @@ public abstract class IntegrityHmac extends SignatureAlgorithmSpi { ...@@ -361,6 +372,7 @@ public abstract class IntegrityHmac extends SignatureAlgorithmSpi {
*/ */
protected void engineSetHMACOutputLength(int HMACOutputLength) { protected void engineSetHMACOutputLength(int HMACOutputLength) {
this._HMACOutputLength = HMACOutputLength; this._HMACOutputLength = HMACOutputLength;
this._HMACOutputLengthSet = true;
} }
/** /**
...@@ -376,12 +388,13 @@ public abstract class IntegrityHmac extends SignatureAlgorithmSpi { ...@@ -376,12 +388,13 @@ public abstract class IntegrityHmac extends SignatureAlgorithmSpi {
throw new IllegalArgumentException("element null"); throw new IllegalArgumentException("element null");
} }
Text hmaclength =XMLUtils.selectDsNodeText(element.getFirstChild(), Text hmaclength =XMLUtils.selectDsNodeText(element.getFirstChild(),
Constants._TAG_HMACOUTPUTLENGTH,0); Constants._TAG_HMACOUTPUTLENGTH,0);
if (hmaclength != null) { if (hmaclength != null) {
this._HMACOutputLength = Integer.parseInt(hmaclength.getData()); this._HMACOutputLength = Integer.parseInt(hmaclength.getData());
} this._HMACOutputLengthSet = true;
}
} }
...@@ -390,14 +403,13 @@ public abstract class IntegrityHmac extends SignatureAlgorithmSpi { ...@@ -390,14 +403,13 @@ public abstract class IntegrityHmac extends SignatureAlgorithmSpi {
* *
* @param element * @param element
*/ */
public void engineAddContextToElement(Element element) public void engineAddContextToElement(Element element) {
{
if (element == null) { if (element == null) {
throw new IllegalArgumentException("null element"); throw new IllegalArgumentException("null element");
} }
if (this._HMACOutputLength != 0) { if (this._HMACOutputLengthSet) {
Document doc = element.getOwnerDocument(); Document doc = element.getOwnerDocument();
Element HMElem = XMLUtils.createElementInSignatureSpace(doc, Element HMElem = XMLUtils.createElementInSignatureSpace(doc,
Constants._TAG_HMACOUTPUTLENGTH); Constants._TAG_HMACOUTPUTLENGTH);
...@@ -436,6 +448,10 @@ public abstract class IntegrityHmac extends SignatureAlgorithmSpi { ...@@ -436,6 +448,10 @@ public abstract class IntegrityHmac extends SignatureAlgorithmSpi {
public String engineGetURI() { public String engineGetURI() {
return XMLSignature.ALGO_ID_MAC_HMAC_SHA1; return XMLSignature.ALGO_ID_MAC_HMAC_SHA1;
} }
int getDigestLength() {
return 160;
}
} }
/** /**
...@@ -463,6 +479,10 @@ public abstract class IntegrityHmac extends SignatureAlgorithmSpi { ...@@ -463,6 +479,10 @@ public abstract class IntegrityHmac extends SignatureAlgorithmSpi {
public String engineGetURI() { public String engineGetURI() {
return XMLSignature.ALGO_ID_MAC_HMAC_SHA256; return XMLSignature.ALGO_ID_MAC_HMAC_SHA256;
} }
int getDigestLength() {
return 256;
}
} }
/** /**
...@@ -490,6 +510,10 @@ public abstract class IntegrityHmac extends SignatureAlgorithmSpi { ...@@ -490,6 +510,10 @@ public abstract class IntegrityHmac extends SignatureAlgorithmSpi {
public String engineGetURI() { public String engineGetURI() {
return XMLSignature.ALGO_ID_MAC_HMAC_SHA384; return XMLSignature.ALGO_ID_MAC_HMAC_SHA384;
} }
int getDigestLength() {
return 384;
}
} }
/** /**
...@@ -517,6 +541,10 @@ public abstract class IntegrityHmac extends SignatureAlgorithmSpi { ...@@ -517,6 +541,10 @@ public abstract class IntegrityHmac extends SignatureAlgorithmSpi {
public String engineGetURI() { public String engineGetURI() {
return XMLSignature.ALGO_ID_MAC_HMAC_SHA512; return XMLSignature.ALGO_ID_MAC_HMAC_SHA512;
} }
int getDigestLength() {
return 512;
}
} }
/** /**
...@@ -544,6 +572,10 @@ public abstract class IntegrityHmac extends SignatureAlgorithmSpi { ...@@ -544,6 +572,10 @@ public abstract class IntegrityHmac extends SignatureAlgorithmSpi {
public String engineGetURI() { public String engineGetURI() {
return XMLSignature.ALGO_ID_MAC_HMAC_RIPEMD160; return XMLSignature.ALGO_ID_MAC_HMAC_RIPEMD160;
} }
int getDigestLength() {
return 160;
}
} }
/** /**
...@@ -571,5 +603,9 @@ public abstract class IntegrityHmac extends SignatureAlgorithmSpi { ...@@ -571,5 +603,9 @@ public abstract class IntegrityHmac extends SignatureAlgorithmSpi {
public String engineGetURI() { public String engineGetURI() {
return XMLSignature.ALGO_ID_MAC_HMAC_NOT_RECOMMENDED_MD5; return XMLSignature.ALGO_ID_MAC_HMAC_NOT_RECOMMENDED_MD5;
} }
int getDigestLength() {
return 128;
}
} }
} }
/*
* Copyright 2009 Sun Microsystems, Inc. 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.security.jgss;
/**
* Kerberos 5 AuthorizationData entry.
*/
final public class AuthorizationDataEntry {
private final int type;
private final byte[] data;
/**
* Create an AuthorizationDataEntry object.
* @param type the ad-type
* @param data the ad-data, a copy of the data will be saved
* inside the object.
*/
public AuthorizationDataEntry(int type, byte[] data) {
this.type = type;
this.data = data.clone();
}
/**
* Get the ad-type field.
* @return ad-type
*/
public int getType() {
return type;
}
/**
* Get a copy of the ad-data field.
* @return ad-data
*/
public byte[] getData() {
return data.clone();
}
public String toString() {
return "AuthorizationDataEntry: type="+type+", data=" +
data.length + " bytes:\n" +
new sun.misc.HexDumpEncoder().encode(data);
}
}
/*
* Copyright 2009 Sun Microsystems, Inc. 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.security.jgss;
import org.ietf.jgss.*;
/**
* The extended GSSContext interface for supporting additional
* functionalities not defined by {@code org.ietf.jgss.GSSContext},
* such as querying context-specific attributes.
*/
public interface ExtendedGSSContext extends GSSContext {
/**
* Return the mechanism-specific attribute associated with {@code type}.
* <br><br>
* For each supported attribute type, the type for the output are
* defined below.
* <ol>
* <li>{@code KRB5_GET_TKT_FLAGS}:
* the returned object is a boolean array for the service ticket flags,
* which is long enough to contain all true bits. This means if
* the user wants to get the <em>n</em>'th bit but the length of the
* returned array is less than <em>n</em>, it is regarded as false.
* <li>{@code KRB5_GET_SESSION_KEY}:
* the returned object is an instance of {@link java.security.Key},
* which has the following properties:
* <ul>
* <li>Algorithm: enctype as a string, where
* enctype is defined in RFC 3961, section 8.
* <li>Format: "RAW"
* <li>Encoded form: the raw key bytes, not in any ASN.1 encoding
* </ul>
* <li>{@code KRB5_GET_AUTHZ_DATA}:
* the returned object is an array of
* {@link com.sun.security.jgss.AuthorizationDataEntry}, or null if the
* optional field is missing in the service ticket.
* <li>{@code KRB5_GET_AUTHTIME}:
* the returned object is a String object in the standard KerberosTime
* format defined in RFC 4120 5.2.3
* </ol>
*
* If there is a security manager, an {@link InquireSecContextPermission}
* with the name {@code type.mech} must be granted. Otherwise, this could
* result in a {@link SecurityException}.<p>
*
* Example:
* <pre>
* GSSContext ctxt = m.createContext(...)
* // Establishing the context
* if (ctxt instanceof ExtendedGSSContext) {
* ExtendedGSSContext ex = (ExtendedGSSContext)ctxt;
* try {
* Key key = (key)ex.inquireSecContext(
* InquireType.KRB5_GET_SESSION_KEY);
* // read key info
* } catch (GSSException gsse) {
* // deal with exception
* }
* }
* </pre>
* @param type the type of the attribute requested
* @return the attribute, see the method documentation for details.
* @throws GSSException containing the following
* major error codes:
* {@link GSSException#BAD_MECH GSSException.BAD_MECH} if the mechanism
* does not support this method,
* {@link GSSException#UNAVAILABLE GSSException.UNAVAILABLE} if the
* type specified is not supported,
* {@link GSSException#NO_CONTEXT GSSException.NO_CONTEXT} if the
* security context is invalid,
* {@link GSSException#FAILURE GSSException.FAILURE} for other
* unspecified failures.
* @throws SecurityException if a security manager exists and a proper
* {@link InquireSecContextPermission} is not granted.
* @see InquireSecContextPermission
*/
public Object inquireSecContext(InquireType type)
throws GSSException;
}
/*
* Copyright 2009 Sun Microsystems, Inc. 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.security.jgss;
import java.security.BasicPermission;
/**
* This class is used to protect various attributes of an established
* GSS security context that can be accessed using the
* {@link com.sun.security.jgss.ExtendedGSSContext#inquireSecContext}
* method.
*
* <p>The target name is the {@link InquireType} allowed.
*/
public final class InquireSecContextPermission extends BasicPermission {
/**
* Constructs a new {@code InquireSecContextPermission} object with
* the specified name. The name is the symbolic name of the
* {@link InquireType} allowed.
*
* @param name the {@link InquireType} allowed by this
* permission. "*" means all {@link InquireType}s are allowed.
*
* @throws NullPointerException if <code>name</code> is <code>null</code>.
* @throws IllegalArgumentException if <code>name</code> is empty.
*/
public InquireSecContextPermission(String name) {
super(name);
}
}
/*
* Copyright 2009 Sun Microsystems, Inc. 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.security.jgss;
/**
* Attribute types that can be specified as an argument of
* {@link com.sun.security.jgss.ExtendedGSSContext#inquireSecContext}
*/
public enum InquireType {
/**
* Attribute type for retrieving the session key of an
* established Kerberos 5 security context.
*/
KRB5_GET_SESSION_KEY,
/**
* Attribute type for retrieving the service ticket flags of an
* established Kerberos 5 security context.
*/
KRB5_GET_TKT_FLAGS,
/**
* Attribute type for retrieving the authorization data in the
* service ticket of an established Kerberos 5 security context.
* Only supported on the acceptor side.
*/
KRB5_GET_AUTHZ_DATA,
/**
* Attribute type for retrieving the authtime in the service ticket
* of an established Kerberos 5 security context.
*/
KRB5_GET_AUTHTIME
}
/* /*
* Copyright 2000-2003 Sun Microsystems, Inc. All Rights Reserved. * Copyright 2000-2009 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -48,10 +48,6 @@ import sun.misc.HexDumpEncoder; ...@@ -48,10 +48,6 @@ import sun.misc.HexDumpEncoder;
* @author Rosanna Lee * @author Rosanna Lee
*/ */
public abstract class AbstractSaslImpl { public abstract class AbstractSaslImpl {
/**
* Logger for debug messages
*/
protected static Logger logger; // set in initLogger(); lazily loads logger
protected boolean completed = false; protected boolean completed = false;
protected boolean privacy = false; protected boolean privacy = false;
...@@ -68,7 +64,6 @@ public abstract class AbstractSaslImpl { ...@@ -68,7 +64,6 @@ public abstract class AbstractSaslImpl {
protected String myClassName; protected String myClassName;
protected AbstractSaslImpl(Map props, String className) throws SaslException { protected AbstractSaslImpl(Map props, String className) throws SaslException {
initLogger();
myClassName = className; myClassName = className;
// Parse properties to set desired context options // Parse properties to set desired context options
...@@ -325,19 +320,15 @@ public abstract class AbstractSaslImpl { ...@@ -325,19 +320,15 @@ public abstract class AbstractSaslImpl {
} }
} }
/**
* Sets logger field.
*/
private static synchronized void initLogger() {
if (logger == null) {
logger = Logger.getLogger(SASL_LOGGER_NAME);
}
}
// ---------------- Constants ----------------- // ---------------- Constants -----------------
private static final String SASL_LOGGER_NAME = "javax.security.sasl"; private static final String SASL_LOGGER_NAME = "javax.security.sasl";
protected static final String MAX_SEND_BUF = "javax.security.sasl.sendmaxbuffer"; protected static final String MAX_SEND_BUF = "javax.security.sasl.sendmaxbuffer";
/**
* Logger for debug messages
*/
protected static final Logger logger = Logger.getLogger(SASL_LOGGER_NAME);
// default 0 (no protection); 1 (integrity only) // default 0 (no protection); 1 (integrity only)
protected static final byte NO_PROTECTION = (byte)1; protected static final byte NO_PROTECTION = (byte)1;
protected static final byte INTEGRITY_ONLY_PROTECTION = (byte)2; protected static final byte INTEGRITY_ONLY_PROTECTION = (byte)2;
......
...@@ -118,8 +118,18 @@ public class Cursor implements java.io.Serializable { ...@@ -118,8 +118,18 @@ public class Cursor implements java.io.Serializable {
*/ */
public static final int MOVE_CURSOR = 13; public static final int MOVE_CURSOR = 13;
/**
* @deprecated As of JDK version 1.7, the {@link #getPredefinedCursor()}
* method should be used instead.
*/
@Deprecated
protected static Cursor predefined[] = new Cursor[14]; protected static Cursor predefined[] = new Cursor[14];
/**
* This field is a private replacement for 'predefined' array.
*/
private final static Cursor[] predefinedPrivate = new Cursor[14];
/* Localization names and default values */ /* Localization names and default values */
static final String[][] cursorProperties = { static final String[][] cursorProperties = {
{ "AWT.DefaultCursor", "Default Cursor" }, { "AWT.DefaultCursor", "Default Cursor" },
...@@ -253,10 +263,15 @@ public class Cursor implements java.io.Serializable { ...@@ -253,10 +263,15 @@ public class Cursor implements java.io.Serializable {
if (type < Cursor.DEFAULT_CURSOR || type > Cursor.MOVE_CURSOR) { if (type < Cursor.DEFAULT_CURSOR || type > Cursor.MOVE_CURSOR) {
throw new IllegalArgumentException("illegal cursor type"); throw new IllegalArgumentException("illegal cursor type");
} }
Cursor c = predefinedPrivate[type];
if (c == null) {
predefinedPrivate[type] = c = new Cursor(type);
}
// fill 'predefined' array for backwards compatibility.
if (predefined[type] == null) { if (predefined[type] == null) {
predefined[type] = new Cursor(type); predefined[type] = c;
} }
return predefined[type]; return c;
} }
/** /**
......
...@@ -3743,16 +3743,58 @@ public class Window extends Container implements Accessible { ...@@ -3743,16 +3743,58 @@ public class Window extends Container implements Accessible {
// ****************** END OF MIXING CODE ******************************** // ****************** END OF MIXING CODE ********************************
// This method gets the window location/size as reported by the native /**
// system since the locally cached values may represent outdated data. * Limit the given double value with the given range.
// NOTE: this method is invoked on the toolkit thread, and therefore */
// is not supposed to become public/user-overridable. private static double limit(double value, double min, double max) {
value = Math.max(value, min);
value = Math.min(value, max);
return value;
}
/**
* Calculate the position of the security warning.
*
* This method gets the window location/size as reported by the native
* system since the locally cached values may represent outdated data.
*
* The method is used from the native code, or via AWTAccessor.
*
* NOTE: this method is invoked on the toolkit thread, and therefore is not
* supposed to become public/user-overridable.
*/
private Point2D calculateSecurityWarningPosition(double x, double y, private Point2D calculateSecurityWarningPosition(double x, double y,
double w, double h) double w, double h)
{ {
return new Point2D.Double( // The position according to the spec of SecurityWarning.setPosition()
x + w * securityWarningAlignmentX + securityWarningPointX, double wx = x + w * securityWarningAlignmentX + securityWarningPointX;
y + h * securityWarningAlignmentY + securityWarningPointY); double wy = y + h * securityWarningAlignmentY + securityWarningPointY;
// First, make sure the warning is not too far from the window bounds
wx = Window.limit(wx,
x - securityWarningWidth - 2,
x + w + 2);
wy = Window.limit(wy,
y - securityWarningHeight - 2,
y + h + 2);
// Now make sure the warning window is visible on the screen
GraphicsConfiguration graphicsConfig =
getGraphicsConfiguration_NoClientCode();
Rectangle screenBounds = graphicsConfig.getBounds();
Insets screenInsets =
Toolkit.getDefaultToolkit().getScreenInsets(graphicsConfig);
wx = Window.limit(wx,
screenBounds.x + screenInsets.left,
screenBounds.x + screenBounds.width - screenInsets.right
- securityWarningWidth);
wy = Window.limit(wy,
screenBounds.y + screenInsets.top,
screenBounds.y + screenBounds.height - screenInsets.bottom
- securityWarningHeight);
return new Point2D.Double(wx, wy);
} }
static { static {
......
...@@ -114,8 +114,8 @@ public class Introspector { ...@@ -114,8 +114,8 @@ public class Introspector {
// Static Caches to speed up introspection. // Static Caches to speed up introspection.
private static Map declaredMethodCache = private static Map declaredMethodCache =
Collections.synchronizedMap(new WeakHashMap()); Collections.synchronizedMap(new WeakHashMap());
private static Map beanInfoCache =
Collections.synchronizedMap(new WeakHashMap()); private static final Object BEANINFO_CACHE = new Object();
private Class beanClass; private Class beanClass;
private BeanInfo explicitBeanInfo; private BeanInfo explicitBeanInfo;
...@@ -174,10 +174,18 @@ public class Introspector { ...@@ -174,10 +174,18 @@ public class Introspector {
if (!ReflectUtil.isPackageAccessible(beanClass)) { if (!ReflectUtil.isPackageAccessible(beanClass)) {
return (new Introspector(beanClass, null, USE_ALL_BEANINFO)).getBeanInfo(); return (new Introspector(beanClass, null, USE_ALL_BEANINFO)).getBeanInfo();
} }
BeanInfo bi = (BeanInfo)beanInfoCache.get(beanClass); Map<Class<?>, BeanInfo> map;
synchronized (BEANINFO_CACHE) {
map = (Map<Class<?>, BeanInfo>) AppContext.getAppContext().get(BEANINFO_CACHE);
if (map == null) {
map = Collections.synchronizedMap(new WeakHashMap<Class<?>, BeanInfo>());
AppContext.getAppContext().put(BEANINFO_CACHE, map);
}
}
BeanInfo bi = map.get(beanClass);
if (bi == null) { if (bi == null) {
bi = (new Introspector(beanClass, null, USE_ALL_BEANINFO)).getBeanInfo(); bi = (new Introspector(beanClass, null, USE_ALL_BEANINFO)).getBeanInfo();
beanInfoCache.put(beanClass, bi); map.put(beanClass, bi);
} }
return bi; return bi;
} }
...@@ -351,7 +359,10 @@ public class Introspector { ...@@ -351,7 +359,10 @@ public class Introspector {
*/ */
public static void flushCaches() { public static void flushCaches() {
beanInfoCache.clear(); Map map = (Map) AppContext.getAppContext().get(BEANINFO_CACHE);
if (map != null) {
map.clear();
}
declaredMethodCache.clear(); declaredMethodCache.clear();
} }
...@@ -374,7 +385,10 @@ public class Introspector { ...@@ -374,7 +385,10 @@ public class Introspector {
if (clz == null) { if (clz == null) {
throw new NullPointerException(); throw new NullPointerException();
} }
beanInfoCache.remove(clz); Map map = (Map) AppContext.getAppContext().get(BEANINFO_CACHE);
if (map != null) {
map.remove(clz);
}
declaredMethodCache.remove(clz); declaredMethodCache.remove(clz);
} }
......
...@@ -335,31 +335,6 @@ abstract class java_util_Collections extends PersistenceDelegate { ...@@ -335,31 +335,6 @@ abstract class java_util_Collections extends PersistenceDelegate {
return (oldC.size() == newC.size()) && oldC.containsAll(newC); return (oldC.size() == newC.size()) && oldC.containsAll(newC);
} }
static Object getPrivateField(final Object instance, final String name) {
return AccessController.doPrivileged(
new PrivilegedAction() {
public Object run() {
Class type = instance.getClass();
while ( true ) {
try {
Field field = type.getDeclaredField(name);
field.setAccessible(true);
return field.get( instance );
}
catch (NoSuchFieldException exception) {
type = type.getSuperclass();
if (type == null) {
throw new IllegalStateException("Could not find field " + name, exception);
}
}
catch (Exception exception) {
throw new IllegalStateException("Could not get value " + type.getName() + '.' + name, exception);
}
}
}
} );
}
static final class EmptyList_PersistenceDelegate extends java_util_Collections { static final class EmptyList_PersistenceDelegate extends java_util_Collections {
protected Expression instantiate(Object oldInstance, Encoder out) { protected Expression instantiate(Object oldInstance, Encoder out) {
return new Expression(oldInstance, Collections.class, "emptyList", null); return new Expression(oldInstance, Collections.class, "emptyList", null);
...@@ -500,7 +475,7 @@ abstract class java_util_Collections extends PersistenceDelegate { ...@@ -500,7 +475,7 @@ abstract class java_util_Collections extends PersistenceDelegate {
static final class CheckedCollection_PersistenceDelegate extends java_util_Collections { static final class CheckedCollection_PersistenceDelegate extends java_util_Collections {
protected Expression instantiate(Object oldInstance, Encoder out) { protected Expression instantiate(Object oldInstance, Encoder out) {
Object type = getPrivateField(oldInstance, "type"); Object type = MetaData.getPrivateFieldValue(oldInstance, "java.util.Collections$CheckedCollection.type");
List list = new ArrayList((Collection) oldInstance); List list = new ArrayList((Collection) oldInstance);
return new Expression(oldInstance, Collections.class, "checkedCollection", new Object[]{list, type}); return new Expression(oldInstance, Collections.class, "checkedCollection", new Object[]{list, type});
} }
...@@ -508,7 +483,7 @@ abstract class java_util_Collections extends PersistenceDelegate { ...@@ -508,7 +483,7 @@ abstract class java_util_Collections extends PersistenceDelegate {
static final class CheckedList_PersistenceDelegate extends java_util_Collections { static final class CheckedList_PersistenceDelegate extends java_util_Collections {
protected Expression instantiate(Object oldInstance, Encoder out) { protected Expression instantiate(Object oldInstance, Encoder out) {
Object type = getPrivateField(oldInstance, "type"); Object type = MetaData.getPrivateFieldValue(oldInstance, "java.util.Collections$CheckedCollection.type");
List list = new LinkedList((Collection) oldInstance); List list = new LinkedList((Collection) oldInstance);
return new Expression(oldInstance, Collections.class, "checkedList", new Object[]{list, type}); return new Expression(oldInstance, Collections.class, "checkedList", new Object[]{list, type});
} }
...@@ -516,7 +491,7 @@ abstract class java_util_Collections extends PersistenceDelegate { ...@@ -516,7 +491,7 @@ abstract class java_util_Collections extends PersistenceDelegate {
static final class CheckedRandomAccessList_PersistenceDelegate extends java_util_Collections { static final class CheckedRandomAccessList_PersistenceDelegate extends java_util_Collections {
protected Expression instantiate(Object oldInstance, Encoder out) { protected Expression instantiate(Object oldInstance, Encoder out) {
Object type = getPrivateField(oldInstance, "type"); Object type = MetaData.getPrivateFieldValue(oldInstance, "java.util.Collections$CheckedCollection.type");
List list = new ArrayList((Collection) oldInstance); List list = new ArrayList((Collection) oldInstance);
return new Expression(oldInstance, Collections.class, "checkedList", new Object[]{list, type}); return new Expression(oldInstance, Collections.class, "checkedList", new Object[]{list, type});
} }
...@@ -524,7 +499,7 @@ abstract class java_util_Collections extends PersistenceDelegate { ...@@ -524,7 +499,7 @@ abstract class java_util_Collections extends PersistenceDelegate {
static final class CheckedSet_PersistenceDelegate extends java_util_Collections { static final class CheckedSet_PersistenceDelegate extends java_util_Collections {
protected Expression instantiate(Object oldInstance, Encoder out) { protected Expression instantiate(Object oldInstance, Encoder out) {
Object type = getPrivateField(oldInstance, "type"); Object type = MetaData.getPrivateFieldValue(oldInstance, "java.util.Collections$CheckedCollection.type");
Set set = new HashSet((Set) oldInstance); Set set = new HashSet((Set) oldInstance);
return new Expression(oldInstance, Collections.class, "checkedSet", new Object[]{set, type}); return new Expression(oldInstance, Collections.class, "checkedSet", new Object[]{set, type});
} }
...@@ -532,7 +507,7 @@ abstract class java_util_Collections extends PersistenceDelegate { ...@@ -532,7 +507,7 @@ abstract class java_util_Collections extends PersistenceDelegate {
static final class CheckedSortedSet_PersistenceDelegate extends java_util_Collections { static final class CheckedSortedSet_PersistenceDelegate extends java_util_Collections {
protected Expression instantiate(Object oldInstance, Encoder out) { protected Expression instantiate(Object oldInstance, Encoder out) {
Object type = getPrivateField(oldInstance, "type"); Object type = MetaData.getPrivateFieldValue(oldInstance, "java.util.Collections$CheckedCollection.type");
SortedSet set = new TreeSet((SortedSet) oldInstance); SortedSet set = new TreeSet((SortedSet) oldInstance);
return new Expression(oldInstance, Collections.class, "checkedSortedSet", new Object[]{set, type}); return new Expression(oldInstance, Collections.class, "checkedSortedSet", new Object[]{set, type});
} }
...@@ -540,8 +515,8 @@ abstract class java_util_Collections extends PersistenceDelegate { ...@@ -540,8 +515,8 @@ abstract class java_util_Collections extends PersistenceDelegate {
static final class CheckedMap_PersistenceDelegate extends java_util_Collections { static final class CheckedMap_PersistenceDelegate extends java_util_Collections {
protected Expression instantiate(Object oldInstance, Encoder out) { protected Expression instantiate(Object oldInstance, Encoder out) {
Object keyType = getPrivateField(oldInstance, "keyType"); Object keyType = MetaData.getPrivateFieldValue(oldInstance, "java.util.Collections$CheckedMap.keyType");
Object valueType = getPrivateField(oldInstance, "valueType"); Object valueType = MetaData.getPrivateFieldValue(oldInstance, "java.util.Collections$CheckedMap.valueType");
Map map = new HashMap((Map) oldInstance); Map map = new HashMap((Map) oldInstance);
return new Expression(oldInstance, Collections.class, "checkedMap", new Object[]{map, keyType, valueType}); return new Expression(oldInstance, Collections.class, "checkedMap", new Object[]{map, keyType, valueType});
} }
...@@ -549,8 +524,8 @@ abstract class java_util_Collections extends PersistenceDelegate { ...@@ -549,8 +524,8 @@ abstract class java_util_Collections extends PersistenceDelegate {
static final class CheckedSortedMap_PersistenceDelegate extends java_util_Collections { static final class CheckedSortedMap_PersistenceDelegate extends java_util_Collections {
protected Expression instantiate(Object oldInstance, Encoder out) { protected Expression instantiate(Object oldInstance, Encoder out) {
Object keyType = getPrivateField(oldInstance, "keyType"); Object keyType = MetaData.getPrivateFieldValue(oldInstance, "java.util.Collections$CheckedMap.keyType");
Object valueType = getPrivateField(oldInstance, "valueType"); Object valueType = MetaData.getPrivateFieldValue(oldInstance, "java.util.Collections$CheckedMap.valueType");
SortedMap map = new TreeMap((SortedMap) oldInstance); SortedMap map = new TreeMap((SortedMap) oldInstance);
return new Expression(oldInstance, Collections.class, "checkedSortedMap", new Object[]{map, keyType, valueType}); return new Expression(oldInstance, Collections.class, "checkedSortedMap", new Object[]{map, keyType, valueType});
} }
...@@ -572,7 +547,7 @@ class java_util_EnumMap_PersistenceDelegate extends PersistenceDelegate { ...@@ -572,7 +547,7 @@ class java_util_EnumMap_PersistenceDelegate extends PersistenceDelegate {
} }
private static Object getType(Object instance) { private static Object getType(Object instance) {
return java_util_Collections.getPrivateField(instance, "keyType"); return MetaData.getPrivateFieldValue(instance, "java.util.EnumMap.keyType");
} }
} }
...@@ -591,7 +566,7 @@ class java_util_EnumSet_PersistenceDelegate extends PersistenceDelegate { ...@@ -591,7 +566,7 @@ class java_util_EnumSet_PersistenceDelegate extends PersistenceDelegate {
} }
private static Object getType(Object instance) { private static Object getType(Object instance) {
return java_util_Collections.getPrivateField(instance, "elementType"); return MetaData.getPrivateFieldValue(instance, "java.util.EnumSet.elementType");
} }
} }
...@@ -1282,7 +1257,7 @@ class javax_swing_Box_PersistenceDelegate extends DefaultPersistenceDelegate { ...@@ -1282,7 +1257,7 @@ class javax_swing_Box_PersistenceDelegate extends DefaultPersistenceDelegate {
private Integer getAxis(Object object) { private Integer getAxis(Object object) {
Box box = (Box) object; Box box = (Box) object;
return (Integer) java_util_Collections.getPrivateField(box.getLayout(), "axis"); return (Integer) MetaData.getPrivateFieldValue(box.getLayout(), "javax.swing.BoxLayout.axis");
} }
} }
...@@ -1365,6 +1340,7 @@ final class sun_swing_PrintColorUIResource_PersistenceDelegate extends Persisten ...@@ -1365,6 +1340,7 @@ final class sun_swing_PrintColorUIResource_PersistenceDelegate extends Persisten
} }
class MetaData { class MetaData {
private static final Map<String,Field> fields = Collections.synchronizedMap(new WeakHashMap<String, Field>());
private static Hashtable internalPersistenceDelegates = new Hashtable(); private static Hashtable internalPersistenceDelegates = new Hashtable();
private static PersistenceDelegate nullPersistenceDelegate = new NullPersistenceDelegate(); private static PersistenceDelegate nullPersistenceDelegate = new NullPersistenceDelegate();
...@@ -1503,4 +1479,35 @@ class MetaData { ...@@ -1503,4 +1479,35 @@ class MetaData {
return null; return null;
} }
} }
static Object getPrivateFieldValue(Object instance, String name) {
Field field = fields.get(name);
if (field == null) {
int index = name.lastIndexOf('.');
final String className = name.substring(0, index);
final String fieldName = name.substring(1 + index);
field = AccessController.doPrivileged(new PrivilegedAction<Field>() {
public Field run() {
try {
Field field = Class.forName(className).getDeclaredField(fieldName);
field.setAccessible(true);
return field;
}
catch (ClassNotFoundException exception) {
throw new IllegalStateException("Could not find class", exception);
}
catch (NoSuchFieldException exception) {
throw new IllegalStateException("Could not find field", exception);
}
}
});
fields.put(name, field);
}
try {
return field.get(instance);
}
catch (IllegalAccessException exception) {
throw new IllegalStateException("Could not get value of the field", exception);
}
}
} }
...@@ -81,7 +81,7 @@ public interface Instrumentation { ...@@ -81,7 +81,7 @@ public interface Instrumentation {
* an exception during execution, the JVM will still call the other registered * an exception during execution, the JVM will still call the other registered
* transformers in order. The same transformer may be added more than once, * transformers in order. The same transformer may be added more than once,
* but it is strongly discouraged -- avoid this by creating a new instance of * but it is strongly discouraged -- avoid this by creating a new instance of
* tranformer class. * transformer class.
* <P> * <P>
* This method is intended for use in instrumentation, as described in the * This method is intended for use in instrumentation, as described in the
* {@linkplain Instrumentation class specification}. * {@linkplain Instrumentation class specification}.
...@@ -183,7 +183,7 @@ public interface Instrumentation { ...@@ -183,7 +183,7 @@ public interface Instrumentation {
* <P> * <P>
* *
* The order of transformation is described in the * The order of transformation is described in the
* ({@link java.lang.instrument.ClassFileTransformer#transform transform} method. * {@link java.lang.instrument.ClassFileTransformer#transform transform} method.
* This same order is used in the automatic reapplication of retransformation * This same order is used in the automatic reapplication of retransformation
* incapable transforms. * incapable transforms.
* <P> * <P>
...@@ -424,7 +424,7 @@ public interface Instrumentation { ...@@ -424,7 +424,7 @@ public interface Instrumentation {
* classes or resources other than those to be defined by the bootstrap * classes or resources other than those to be defined by the bootstrap
* class loader for the purpose of instrumentation. * class loader for the purpose of instrumentation.
* Failure to observe this warning could result in unexpected * Failure to observe this warning could result in unexpected
* behaviour that is difficult to diagnose. For example, suppose there is a * behavior that is difficult to diagnose. For example, suppose there is a
* loader L, and L's parent for delegation is the bootstrap class loader. * loader L, and L's parent for delegation is the bootstrap class loader.
* Furthermore, a method in class C, a class defined by L, makes reference to * Furthermore, a method in class C, a class defined by L, makes reference to
* a non-public accessor class C$1. If the JAR file contains a class C$1 then * a non-public accessor class C$1. If the JAR file contains a class C$1 then
...@@ -475,9 +475,9 @@ public interface Instrumentation { ...@@ -475,9 +475,9 @@ public interface Instrumentation {
* classes or resources other than those to be defined by the system class * classes or resources other than those to be defined by the system class
* loader for the purpose of instrumentation. * loader for the purpose of instrumentation.
* Failure to observe this warning could result in unexpected * Failure to observe this warning could result in unexpected
* behaviour that is difficult to diagnose (see * behavior that is difficult to diagnose (see
* {@link #appendToBootstrapClassLoaderSearch * {@link #appendToBootstrapClassLoaderSearch
* appendToBootstrapClassLoaderSearch}. * appendToBootstrapClassLoaderSearch}).
* *
* <p> The system class loader supports adding a JAR file to be searched if * <p> The system class loader supports adding a JAR file to be searched if
* it implements a method named <code>appendToClassPathForInstrumentation</code> * it implements a method named <code>appendToClassPathForInstrumentation</code>
...@@ -485,7 +485,7 @@ public interface Instrumentation { ...@@ -485,7 +485,7 @@ public interface Instrumentation {
* method is not required to have <code>public</code> access. The name of * method is not required to have <code>public</code> access. The name of
* the JAR file is obtained by invoking the {@link java.util.zip.ZipFile#getName * the JAR file is obtained by invoking the {@link java.util.zip.ZipFile#getName
* getName()} method on the <code>jarfile</code> and this is provided as the * getName()} method on the <code>jarfile</code> and this is provided as the
* parameter to the <code>appendtoClassPathForInstrumentation</code> method. * parameter to the <code>appendToClassPathForInstrumentation</code> method.
* *
* <p> The <a href="http://java.sun.com/docs/books/vmspec/">Java Virtual Machine * <p> The <a href="http://java.sun.com/docs/books/vmspec/">Java Virtual Machine
* Specification</a> specifies that a subsequent attempt to resolve a symbolic * Specification</a> specifies that a subsequent attempt to resolve a symbolic
......
...@@ -114,9 +114,14 @@ class Socket implements java.io.Closeable { ...@@ -114,9 +114,14 @@ class Socket implements java.io.Closeable {
* @since 1.5 * @since 1.5
*/ */
public Socket(Proxy proxy) { public Socket(Proxy proxy) {
if (proxy != null && proxy.type() == Proxy.Type.SOCKS) { // Create a copy of Proxy as a security measure
if (proxy == null) {
throw new IllegalArgumentException("Invalid Proxy");
}
Proxy p = proxy == Proxy.NO_PROXY ? Proxy.NO_PROXY : sun.net.ApplicationProxy.create(proxy);
if (p.type() == Proxy.Type.SOCKS) {
SecurityManager security = System.getSecurityManager(); SecurityManager security = System.getSecurityManager();
InetSocketAddress epoint = (InetSocketAddress) proxy.address(); InetSocketAddress epoint = (InetSocketAddress) p.address();
if (security != null) { if (security != null) {
if (epoint.isUnresolved()) if (epoint.isUnresolved())
security.checkConnect(epoint.getHostName(), security.checkConnect(epoint.getHostName(),
...@@ -125,10 +130,10 @@ class Socket implements java.io.Closeable { ...@@ -125,10 +130,10 @@ class Socket implements java.io.Closeable {
security.checkConnect(epoint.getAddress().getHostAddress(), security.checkConnect(epoint.getAddress().getHostAddress(),
epoint.getPort()); epoint.getPort());
} }
impl = new SocksSocketImpl(proxy); impl = new SocksSocketImpl(p);
impl.setSocket(this); impl.setSocket(this);
} else { } else {
if (proxy == Proxy.NO_PROXY) { if (p == Proxy.NO_PROXY) {
if (factory == null) { if (factory == null) {
impl = new PlainSocketImpl(); impl = new PlainSocketImpl();
impl.setSocket(this); impl.setSocket(this);
......
...@@ -46,6 +46,9 @@ class SocksSocketImpl extends PlainSocketImpl implements SocksConsts { ...@@ -46,6 +46,9 @@ class SocksSocketImpl extends PlainSocketImpl implements SocksConsts {
private Socket cmdsock = null; private Socket cmdsock = null;
private InputStream cmdIn = null; private InputStream cmdIn = null;
private OutputStream cmdOut = null; private OutputStream cmdOut = null;
/* true if the Proxy has been set programatically */
private boolean applicationSetProxy; /* false */
SocksSocketImpl() { SocksSocketImpl() {
// Nothing needed // Nothing needed
...@@ -237,8 +240,7 @@ class SocksSocketImpl extends PlainSocketImpl implements SocksConsts { ...@@ -237,8 +240,7 @@ class SocksSocketImpl extends PlainSocketImpl implements SocksConsts {
out.write((endpoint.getPort() >> 8) & 0xff); out.write((endpoint.getPort() >> 8) & 0xff);
out.write((endpoint.getPort() >> 0) & 0xff); out.write((endpoint.getPort() >> 0) & 0xff);
out.write(endpoint.getAddress().getAddress()); out.write(endpoint.getAddress().getAddress());
String userName = java.security.AccessController.doPrivileged( String userName = getUserName();
new sun.security.action.GetPropertyAction("user.name"));
try { try {
out.write(userName.getBytes("ISO-8859-1")); out.write(userName.getBytes("ISO-8859-1"));
} catch (java.io.UnsupportedEncodingException uee) { } catch (java.io.UnsupportedEncodingException uee) {
...@@ -554,8 +556,7 @@ class SocksSocketImpl extends PlainSocketImpl implements SocksConsts { ...@@ -554,8 +556,7 @@ class SocksSocketImpl extends PlainSocketImpl implements SocksConsts {
out.write((super.getLocalPort() >> 8) & 0xff); out.write((super.getLocalPort() >> 8) & 0xff);
out.write((super.getLocalPort() >> 0) & 0xff); out.write((super.getLocalPort() >> 0) & 0xff);
out.write(addr1); out.write(addr1);
String userName = java.security.AccessController.doPrivileged( String userName = getUserName();
new sun.security.action.GetPropertyAction("user.name"));
try { try {
out.write(userName.getBytes("ISO-8859-1")); out.write(userName.getBytes("ISO-8859-1"));
} catch (java.io.UnsupportedEncodingException uee) { } catch (java.io.UnsupportedEncodingException uee) {
...@@ -1022,4 +1023,16 @@ class SocksSocketImpl extends PlainSocketImpl implements SocksConsts { ...@@ -1022,4 +1023,16 @@ class SocksSocketImpl extends PlainSocketImpl implements SocksConsts {
super.close(); super.close();
} }
private String getUserName() {
String userName = "";
if (applicationSetProxy) {
try {
userName = System.getProperty("user.name");
} catch (SecurityException se) { /* swallow Exception */ }
} else {
userName = java.security.AccessController.doPrivileged(
new sun.security.action.GetPropertyAction("user.name"));
}
return userName;
}
} }
...@@ -1004,16 +1004,18 @@ public final class URL implements java.io.Serializable { ...@@ -1004,16 +1004,18 @@ public final class URL implements java.io.Serializable {
throw new IllegalArgumentException("proxy can not be null"); throw new IllegalArgumentException("proxy can not be null");
} }
// Create a copy of Proxy as a security measure
Proxy p = proxy == Proxy.NO_PROXY ? Proxy.NO_PROXY : sun.net.ApplicationProxy.create(proxy);
SecurityManager sm = System.getSecurityManager(); SecurityManager sm = System.getSecurityManager();
if (proxy.type() != Proxy.Type.DIRECT && sm != null) { if (p.type() != Proxy.Type.DIRECT && sm != null) {
InetSocketAddress epoint = (InetSocketAddress) proxy.address(); InetSocketAddress epoint = (InetSocketAddress) p.address();
if (epoint.isUnresolved()) if (epoint.isUnresolved())
sm.checkConnect(epoint.getHostName(), epoint.getPort()); sm.checkConnect(epoint.getHostName(), epoint.getPort());
else else
sm.checkConnect(epoint.getAddress().getHostAddress(), sm.checkConnect(epoint.getAddress().getHostAddress(),
epoint.getPort()); epoint.getPort());
} }
return handler.openConnection(this, proxy); return handler.openConnection(this, p);
} }
/** /**
......
...@@ -421,7 +421,7 @@ public abstract class DatagramChannel ...@@ -421,7 +421,7 @@ public abstract class DatagramChannel
* invocation of this method will block until the first operation is * invocation of this method will block until the first operation is
* complete. If this channel's socket is not bound then this method will * complete. If this channel's socket is not bound then this method will
* first cause the socket to be bound to an address that is assigned * first cause the socket to be bound to an address that is assigned
* automatically, as if by invoking the {@link #bind bind) method with a * automatically, as if by invoking the {@link #bind bind} method with a
* parameter of {@code null}. </p> * parameter of {@code null}. </p>
* *
* @param src * @param src
......
...@@ -115,8 +115,8 @@ ...@@ -115,8 +115,8 @@
* <td>Reads, writes, maps, and manipulates files</td></tr> * <td>Reads, writes, maps, and manipulates files</td></tr>
* <tr><td valign=top><tt>{@link java.nio.channels.FileLock}</tt></td> * <tr><td valign=top><tt>{@link java.nio.channels.FileLock}</tt></td>
* <td>A lock on a (region of a) file</td></tr> * <td>A lock on a (region of a) file</td></tr>
* <tr><td valign=top><tt>{@link java.nio.MappedByteBuffer}/{@link java.nio.MappedBigByteBuffer}&nbsp;&nbsp;</tt></td> * <tr><td valign=top><tt>{@link java.nio.MappedByteBuffer}&nbsp;&nbsp;</tt></td>
* <td>A direct byte buffer or big byte buffer mapped to a region of a&nbsp;file</td></tr> * <td>A direct byte buffer mapped to a region of a&nbsp;file</td></tr>
* </table></blockquote> * </table></blockquote>
* *
* <p> The {@link java.nio.channels.FileChannel} class supports the usual * <p> The {@link java.nio.channels.FileChannel} class supports the usual
......
...@@ -53,7 +53,7 @@ import java.io.IOException; ...@@ -53,7 +53,7 @@ import java.io.IOException;
* invoking the {@link #close close} method. Closing the directory stream * invoking the {@link #close close} method. Closing the directory stream
* releases any resources associated with the stream. Once a directory stream * releases any resources associated with the stream. Once a directory stream
* is closed, all further method invocations on the iterator throw {@link * is closed, all further method invocations on the iterator throw {@link
* java.util.concurrent.ConcurrentModificationException} with cause {@link * java.util.ConcurrentModificationException} with cause {@link
* ClosedDirectoryStreamException}. * ClosedDirectoryStreamException}.
* *
* <p> A directory stream is not required to be <i>asynchronously closeable</i>. * <p> A directory stream is not required to be <i>asynchronously closeable</i>.
......
...@@ -987,7 +987,7 @@ public abstract class Path ...@@ -987,7 +987,7 @@ public abstract class Path
* exception then it is propogated to the iterator's {@link Iterator#hasNext() * exception then it is propogated to the iterator's {@link Iterator#hasNext()
* hasNext} or {@link Iterator#next() next} method. Where an {@code * hasNext} or {@link Iterator#next() next} method. Where an {@code
* IOException} is thrown, it is propogated as a {@link * IOException} is thrown, it is propogated as a {@link
* java.util.concurrent.ConcurrentModificationException} with the {@code * java.util.ConcurrentModificationException} with the {@code
* IOException} as the cause. * IOException} as the cause.
* *
* <p> When an implementation supports operations on entries in the * <p> When an implementation supports operations on entries in the
......
...@@ -47,6 +47,14 @@ public class SimpleFileVisitor<T> implements FileVisitor<T> { ...@@ -47,6 +47,14 @@ public class SimpleFileVisitor<T> implements FileVisitor<T> {
protected SimpleFileVisitor() { protected SimpleFileVisitor() {
} }
/**
* Throws NullPointerException if obj is null.
*/
private static void checkNotNull(Object obj) {
if (obj == null)
throw new NullPointerException();
}
/** /**
* Invoked for a directory before entries in the directory are visited. * Invoked for a directory before entries in the directory are visited.
* *
...@@ -55,6 +63,7 @@ public class SimpleFileVisitor<T> implements FileVisitor<T> { ...@@ -55,6 +63,7 @@ public class SimpleFileVisitor<T> implements FileVisitor<T> {
*/ */
@Override @Override
public FileVisitResult preVisitDirectory(T dir) { public FileVisitResult preVisitDirectory(T dir) {
checkNotNull(dir);
return FileVisitResult.CONTINUE; return FileVisitResult.CONTINUE;
} }
...@@ -70,6 +79,8 @@ public class SimpleFileVisitor<T> implements FileVisitor<T> { ...@@ -70,6 +79,8 @@ public class SimpleFileVisitor<T> implements FileVisitor<T> {
*/ */
@Override @Override
public FileVisitResult preVisitDirectoryFailed(T dir, IOException exc) { public FileVisitResult preVisitDirectoryFailed(T dir, IOException exc) {
checkNotNull(dir);
checkNotNull(exc);
throw new IOError(exc); throw new IOError(exc);
} }
...@@ -81,6 +92,8 @@ public class SimpleFileVisitor<T> implements FileVisitor<T> { ...@@ -81,6 +92,8 @@ public class SimpleFileVisitor<T> implements FileVisitor<T> {
*/ */
@Override @Override
public FileVisitResult visitFile(T file, BasicFileAttributes attrs) { public FileVisitResult visitFile(T file, BasicFileAttributes attrs) {
checkNotNull(file);
checkNotNull(attrs);
return FileVisitResult.CONTINUE; return FileVisitResult.CONTINUE;
} }
...@@ -96,6 +109,8 @@ public class SimpleFileVisitor<T> implements FileVisitor<T> { ...@@ -96,6 +109,8 @@ public class SimpleFileVisitor<T> implements FileVisitor<T> {
*/ */
@Override @Override
public FileVisitResult visitFileFailed(T file, IOException exc) { public FileVisitResult visitFileFailed(T file, IOException exc) {
checkNotNull(file);
checkNotNull(exc);
throw new IOError(exc); throw new IOError(exc);
} }
...@@ -114,6 +129,7 @@ public class SimpleFileVisitor<T> implements FileVisitor<T> { ...@@ -114,6 +129,7 @@ public class SimpleFileVisitor<T> implements FileVisitor<T> {
*/ */
@Override @Override
public FileVisitResult postVisitDirectory(T dir, IOException exc) { public FileVisitResult postVisitDirectory(T dir, IOException exc) {
checkNotNull(dir);
if (exc != null) if (exc != null)
throw new IOError(exc); throw new IOError(exc);
return FileVisitResult.CONTINUE; return FileVisitResult.CONTINUE;
......
...@@ -75,7 +75,7 @@ import java.io.IOException; ...@@ -75,7 +75,7 @@ import java.io.IOException;
* .lookupPrincipalByName("joe"); * .lookupPrincipalByName("joe");
* *
* // get view * // get view
* AclFileAttributeView view = file.newFileAttributeView(AclFileAttributeView.class); * AclFileAttributeView view = file.getFileAttributeView(AclFileAttributeView.class);
* *
* // create ACE to give "joe" read access * // create ACE to give "joe" read access
* AclEntry entry = AclEntry.newBuilder() * AclEntry entry = AclEntry.newBuilder()
......
...@@ -61,7 +61,7 @@ import java.io.IOException; ...@@ -61,7 +61,7 @@ import java.io.IOException;
* Suppose we need to print out the owner and access permissions of a file: * Suppose we need to print out the owner and access permissions of a file:
* <pre> * <pre>
* FileRef file = ... * FileRef file = ...
* PosixFileAttributes attrs = file.newFileAttributeView(PosixFileAttributeView.class) * PosixFileAttributes attrs = file.getFileAttributeView(PosixFileAttributeView.class)
* .readAttributes(); * .readAttributes();
* System.out.format("%s %s%n", * System.out.format("%s %s%n",
* attrs.owner().getName(), * attrs.owner().getName(),
......
...@@ -102,9 +102,9 @@ ...@@ -102,9 +102,9 @@
* <p><li> The {@link java.nio.file.attribute.UserPrincipalLookupService} * <p><li> The {@link java.nio.file.attribute.UserPrincipalLookupService}
* interface defines methods to lookup user or group principals. </li> * interface defines methods to lookup user or group principals. </li>
* *
* <p><li> The {@link java.nio.file.attribute.Attribute} interface * <p><li> The {@link java.nio.file.attribute.FileAttribute} interface
* represents the value of an attribute for cases where the attribute value is * represents the value of an attribute for cases where the attribute value is
* require to be set atomically when creating an object in the file system. </li> * required to be set atomically when creating an object in the file system. </li>
* *
* </ul> * </ul>
* *
......
...@@ -1065,29 +1065,103 @@ public class Arrays { ...@@ -1065,29 +1065,103 @@ public class Arrays {
(x[b] > x[c] ? b : x[a] > x[c] ? c : a)); (x[b] > x[c] ? b : x[a] > x[c] ? c : a));
} }
/** /**
* Sorts the specified array of objects into ascending order, according to * Old merge sort implementation can be selected (for
* the {@linkplain Comparable natural ordering} * compatibility with broken comparators) using a system property.
* of its elements. All elements in the array * Cannot be a static boolean in the enclosing class due to
* must implement the {@link Comparable} interface. Furthermore, all * circular dependencies. To be removed in a future release.
* elements in the array must be <i>mutually comparable</i> (that is, */
* <tt>e1.compareTo(e2)</tt> must not throw a <tt>ClassCastException</tt> static final class LegacyMergeSort {
* for any elements <tt>e1</tt> and <tt>e2</tt> in the array).<p> private static final boolean userRequested =
java.security.AccessController.doPrivileged(
new sun.security.action.GetBooleanAction(
"java.util.Arrays.useLegacyMergeSort")).booleanValue();
}
/*
* If this platform has an optimizing VM, check whether ComparableTimSort
* offers any performance benefit over TimSort in conjunction with a
* comparator that returns:
* {@code ((Comparable)first).compareTo(Second)}.
* If not, you are better off deleting ComparableTimSort to
* eliminate the code duplication. In other words, the commented
* out code below is the preferable implementation for sorting
* arrays of Comparables if it offers sufficient performance.
*/
// /**
// * A comparator that implements the natural ordering of a group of
// * mutually comparable elements. Using this comparator saves us
// * from duplicating most of the code in this file (one version for
// * Comparables, one for explicit Comparators).
// */
// private static final Comparator<Object> NATURAL_ORDER =
// new Comparator<Object>() {
// @SuppressWarnings("unchecked")
// public int compare(Object first, Object second) {
// return ((Comparable<Object>)first).compareTo(second);
// }
// };
//
// public static void sort(Object[] a) {
// sort(a, 0, a.length, NATURAL_ORDER);
// }
//
// public static void sort(Object[] a, int fromIndex, int toIndex) {
// sort(a, fromIndex, toIndex, NATURAL_ORDER);
// }
/**
* Sorts the specified array of objects into ascending order, according
* to the {@linkplain Comparable natural ordering} of its elements.
* All elements in the array must implement the {@link Comparable}
* interface. Furthermore, all elements in the array must be
* <i>mutually comparable</i> (that is, {@code e1.compareTo(e2)} must
* not throw a {@code ClassCastException} for any elements {@code e1}
* and {@code e2} in the array).
*
* <p>This sort is guaranteed to be <i>stable</i>: equal elements will
* not be reordered as a result of the sort.
*
* <p>Implementation note: This implementation is a stable, adaptive,
* iterative mergesort that requires far fewer than n lg(n) comparisons
* when the input array is partially sorted, while offering the
* performance of a traditional mergesort when the input array is
* randomly ordered. If the input array is nearly sorted, the
* implementation requires approximately n comparisons. Temporary
* storage requirements vary from a small constant for nearly sorted
* input arrays to n/2 object references for randomly ordered input
* arrays.
* *
* This sort is guaranteed to be <i>stable</i>: equal elements will * <p>The implementation takes equal advantage of ascending and
* not be reordered as a result of the sort.<p> * descending order in its input array, and can take advantage of
* ascending and descending order in different parts of the the same
* input array. It is well-suited to merging two or more sorted arrays:
* simply concatenate the arrays and sort the resulting array.
* *
* The sorting algorithm is a modified mergesort (in which the merge is * <p>The implementation was adapted from Tim Peters's list sort for Python
* omitted if the highest element in the low sublist is less than the * (<a href="http://svn.python.org/projects/python/trunk/Objects/listsort.txt">
* lowest element in the high sublist). This algorithm offers guaranteed * TimSort</a>). It uses techiques from Peter McIlroy's "Optimistic
* n*log(n) performance. * Sorting and Information Theoretic Complexity", in Proceedings of the
* Fourth Annual ACM-SIAM Symposium on Discrete Algorithms, pp 467-474,
* January 1993.
* *
* @param a the array to be sorted * @param a the array to be sorted
* @throws ClassCastException if the array contains elements that are not * @throws ClassCastException if the array contains elements that are not
* <i>mutually comparable</i> (for example, strings and integers). * <i>mutually comparable</i> (for example, strings and integers)
* @throws IllegalArgumentException (optional) if the natural
* ordering of the array elements is found to violate the
* {@link Comparable} contract
*/ */
public static void sort(Object[] a) { public static void sort(Object[] a) {
if (LegacyMergeSort.userRequested)
legacyMergeSort(a);
else
ComparableTimSort.sort(a);
}
/** To be removed in a future release. */
private static void legacyMergeSort(Object[] a) {
Object[] aux = a.clone(); Object[] aux = a.clone();
mergeSort(aux, a, 0, a.length, 0); mergeSort(aux, a, 0, a.length, 0);
} }
...@@ -1097,34 +1171,63 @@ public class Arrays { ...@@ -1097,34 +1171,63 @@ public class Arrays {
* ascending order, according to the * ascending order, according to the
* {@linkplain Comparable natural ordering} of its * {@linkplain Comparable natural ordering} of its
* elements. The range to be sorted extends from index * elements. The range to be sorted extends from index
* <tt>fromIndex</tt>, inclusive, to index <tt>toIndex</tt>, exclusive. * {@code fromIndex}, inclusive, to index {@code toIndex}, exclusive.
* (If <tt>fromIndex==toIndex</tt>, the range to be sorted is empty.) All * (If {@code fromIndex==toIndex}, the range to be sorted is empty.) All
* elements in this range must implement the {@link Comparable} * elements in this range must implement the {@link Comparable}
* interface. Furthermore, all elements in this range must be <i>mutually * interface. Furthermore, all elements in this range must be <i>mutually
* comparable</i> (that is, <tt>e1.compareTo(e2)</tt> must not throw a * comparable</i> (that is, {@code e1.compareTo(e2)} must not throw a
* <tt>ClassCastException</tt> for any elements <tt>e1</tt> and * {@code ClassCastException} for any elements {@code e1} and
* <tt>e2</tt> in the array).<p> * {@code e2} in the array).
*
* <p>This sort is guaranteed to be <i>stable</i>: equal elements will
* not be reordered as a result of the sort.
*
* <p>Implementation note: This implementation is a stable, adaptive,
* iterative mergesort that requires far fewer than n lg(n) comparisons
* when the input array is partially sorted, while offering the
* performance of a traditional mergesort when the input array is
* randomly ordered. If the input array is nearly sorted, the
* implementation requires approximately n comparisons. Temporary
* storage requirements vary from a small constant for nearly sorted
* input arrays to n/2 object references for randomly ordered input
* arrays.
* *
* This sort is guaranteed to be <i>stable</i>: equal elements will * <p>The implementation takes equal advantage of ascending and
* not be reordered as a result of the sort.<p> * descending order in its input array, and can take advantage of
* ascending and descending order in different parts of the the same
* input array. It is well-suited to merging two or more sorted arrays:
* simply concatenate the arrays and sort the resulting array.
* *
* The sorting algorithm is a modified mergesort (in which the merge is * <p>The implementation was adapted from Tim Peters's list sort for Python
* omitted if the highest element in the low sublist is less than the * (<a href="http://svn.python.org/projects/python/trunk/Objects/listsort.txt">
* lowest element in the high sublist). This algorithm offers guaranteed * TimSort</a>). It uses techiques from Peter McIlroy's "Optimistic
* n*log(n) performance. * Sorting and Information Theoretic Complexity", in Proceedings of the
* Fourth Annual ACM-SIAM Symposium on Discrete Algorithms, pp 467-474,
* January 1993.
* *
* @param a the array to be sorted * @param a the array to be sorted
* @param fromIndex the index of the first element (inclusive) to be * @param fromIndex the index of the first element (inclusive) to be
* sorted * sorted
* @param toIndex the index of the last element (exclusive) to be sorted * @param toIndex the index of the last element (exclusive) to be sorted
* @throws IllegalArgumentException if <tt>fromIndex &gt; toIndex</tt> * @throws IllegalArgumentException if {@code fromIndex > toIndex} or
* @throws ArrayIndexOutOfBoundsException if <tt>fromIndex &lt; 0</tt> or * (optional) if the natural ordering of the array elements is
* <tt>toIndex &gt; a.length</tt> * found to violate the {@link Comparable} contract
* @throws ClassCastException if the array contains elements that are * @throws ArrayIndexOutOfBoundsException if {@code fromIndex < 0} or
* not <i>mutually comparable</i> (for example, strings and * {@code toIndex > a.length}
* integers). * @throws ClassCastException if the array contains elements that are
* not <i>mutually comparable</i> (for example, strings and
* integers).
*/ */
public static void sort(Object[] a, int fromIndex, int toIndex) { public static void sort(Object[] a, int fromIndex, int toIndex) {
if (LegacyMergeSort.userRequested)
legacyMergeSort(a, fromIndex, toIndex);
else
ComparableTimSort.sort(a, fromIndex, toIndex);
}
/** To be removed in a future release. */
private static void legacyMergeSort(Object[] a,
int fromIndex, int toIndex) {
rangeCheck(a.length, fromIndex, toIndex); rangeCheck(a.length, fromIndex, toIndex);
Object[] aux = copyOfRange(a, fromIndex, toIndex); Object[] aux = copyOfRange(a, fromIndex, toIndex);
mergeSort(aux, a, fromIndex, toIndex, -fromIndex); mergeSort(aux, a, fromIndex, toIndex, -fromIndex);
...@@ -1133,6 +1236,7 @@ public class Arrays { ...@@ -1133,6 +1236,7 @@ public class Arrays {
/** /**
* Tuning parameter: list size at or below which insertion sort will be * Tuning parameter: list size at or below which insertion sort will be
* used in preference to mergesort or quicksort. * used in preference to mergesort or quicksort.
* To be removed in a future release.
*/ */
private static final int INSERTIONSORT_THRESHOLD = 7; private static final int INSERTIONSORT_THRESHOLD = 7;
...@@ -1142,6 +1246,7 @@ public class Arrays { ...@@ -1142,6 +1246,7 @@ public class Arrays {
* low is the index in dest to start sorting * low is the index in dest to start sorting
* high is the end index in dest to end sorting * high is the end index in dest to end sorting
* off is the offset to generate corresponding low, high in src * off is the offset to generate corresponding low, high in src
* To be removed in a future release.
*/ */
private static void mergeSort(Object[] src, private static void mergeSort(Object[] src,
Object[] dest, Object[] dest,
...@@ -1197,25 +1302,53 @@ public class Arrays { ...@@ -1197,25 +1302,53 @@ public class Arrays {
* Sorts the specified array of objects according to the order induced by * Sorts the specified array of objects according to the order induced by
* the specified comparator. All elements in the array must be * the specified comparator. All elements in the array must be
* <i>mutually comparable</i> by the specified comparator (that is, * <i>mutually comparable</i> by the specified comparator (that is,
* <tt>c.compare(e1, e2)</tt> must not throw a <tt>ClassCastException</tt> * {@code c.compare(e1, e2)} must not throw a {@code ClassCastException}
* for any elements <tt>e1</tt> and <tt>e2</tt> in the array).<p> * for any elements {@code e1} and {@code e2} in the array).
*
* <p>This sort is guaranteed to be <i>stable</i>: equal elements will
* not be reordered as a result of the sort.
*
* <p>Implementation note: This implementation is a stable, adaptive,
* iterative mergesort that requires far fewer than n lg(n) comparisons
* when the input array is partially sorted, while offering the
* performance of a traditional mergesort when the input array is
* randomly ordered. If the input array is nearly sorted, the
* implementation requires approximately n comparisons. Temporary
* storage requirements vary from a small constant for nearly sorted
* input arrays to n/2 object references for randomly ordered input
* arrays.
* *
* This sort is guaranteed to be <i>stable</i>: equal elements will * <p>The implementation takes equal advantage of ascending and
* not be reordered as a result of the sort.<p> * descending order in its input array, and can take advantage of
* ascending and descending order in different parts of the the same
* input array. It is well-suited to merging two or more sorted arrays:
* simply concatenate the arrays and sort the resulting array.
* *
* The sorting algorithm is a modified mergesort (in which the merge is * <p>The implementation was adapted from Tim Peters's list sort for Python
* omitted if the highest element in the low sublist is less than the * (<a href="http://svn.python.org/projects/python/trunk/Objects/listsort.txt">
* lowest element in the high sublist). This algorithm offers guaranteed * TimSort</a>). It uses techiques from Peter McIlroy's "Optimistic
* n*log(n) performance. * Sorting and Information Theoretic Complexity", in Proceedings of the
* Fourth Annual ACM-SIAM Symposium on Discrete Algorithms, pp 467-474,
* January 1993.
* *
* @param a the array to be sorted * @param a the array to be sorted
* @param c the comparator to determine the order of the array. A * @param c the comparator to determine the order of the array. A
* <tt>null</tt> value indicates that the elements' * {@code null} value indicates that the elements'
* {@linkplain Comparable natural ordering} should be used. * {@linkplain Comparable natural ordering} should be used.
* @throws ClassCastException if the array contains elements that are * @throws ClassCastException if the array contains elements that are
* not <i>mutually comparable</i> using the specified comparator. * not <i>mutually comparable</i> using the specified comparator
* @throws IllegalArgumentException (optional) if the comparator is
* found to violate the {@link Comparator} contract
*/ */
public static <T> void sort(T[] a, Comparator<? super T> c) { public static <T> void sort(T[] a, Comparator<? super T> c) {
if (LegacyMergeSort.userRequested)
legacyMergeSort(a, c);
else
TimSort.sort(a, c);
}
/** To be removed in a future release. */
private static <T> void legacyMergeSort(T[] a, Comparator<? super T> c) {
T[] aux = a.clone(); T[] aux = a.clone();
if (c==null) if (c==null)
mergeSort(aux, a, 0, a.length, 0); mergeSort(aux, a, 0, a.length, 0);
...@@ -1226,36 +1359,65 @@ public class Arrays { ...@@ -1226,36 +1359,65 @@ public class Arrays {
/** /**
* Sorts the specified range of the specified array of objects according * Sorts the specified range of the specified array of objects according
* to the order induced by the specified comparator. The range to be * to the order induced by the specified comparator. The range to be
* sorted extends from index <tt>fromIndex</tt>, inclusive, to index * sorted extends from index {@code fromIndex}, inclusive, to index
* <tt>toIndex</tt>, exclusive. (If <tt>fromIndex==toIndex</tt>, the * {@code toIndex}, exclusive. (If {@code fromIndex==toIndex}, the
* range to be sorted is empty.) All elements in the range must be * range to be sorted is empty.) All elements in the range must be
* <i>mutually comparable</i> by the specified comparator (that is, * <i>mutually comparable</i> by the specified comparator (that is,
* <tt>c.compare(e1, e2)</tt> must not throw a <tt>ClassCastException</tt> * {@code c.compare(e1, e2)} must not throw a {@code ClassCastException}
* for any elements <tt>e1</tt> and <tt>e2</tt> in the range).<p> * for any elements {@code e1} and {@code e2} in the range).
*
* <p>This sort is guaranteed to be <i>stable</i>: equal elements will
* not be reordered as a result of the sort.
*
* <p>Implementation note: This implementation is a stable, adaptive,
* iterative mergesort that requires far fewer than n lg(n) comparisons
* when the input array is partially sorted, while offering the
* performance of a traditional mergesort when the input array is
* randomly ordered. If the input array is nearly sorted, the
* implementation requires approximately n comparisons. Temporary
* storage requirements vary from a small constant for nearly sorted
* input arrays to n/2 object references for randomly ordered input
* arrays.
* *
* This sort is guaranteed to be <i>stable</i>: equal elements will * <p>The implementation takes equal advantage of ascending and
* not be reordered as a result of the sort.<p> * descending order in its input array, and can take advantage of
* ascending and descending order in different parts of the the same
* input array. It is well-suited to merging two or more sorted arrays:
* simply concatenate the arrays and sort the resulting array.
* *
* The sorting algorithm is a modified mergesort (in which the merge is * <p>The implementation was adapted from Tim Peters's list sort for Python
* omitted if the highest element in the low sublist is less than the * (<a href="http://svn.python.org/projects/python/trunk/Objects/listsort.txt">
* lowest element in the high sublist). This algorithm offers guaranteed * TimSort</a>). It uses techiques from Peter McIlroy's "Optimistic
* n*log(n) performance. * Sorting and Information Theoretic Complexity", in Proceedings of the
* Fourth Annual ACM-SIAM Symposium on Discrete Algorithms, pp 467-474,
* January 1993.
* *
* @param a the array to be sorted * @param a the array to be sorted
* @param fromIndex the index of the first element (inclusive) to be * @param fromIndex the index of the first element (inclusive) to be
* sorted * sorted
* @param toIndex the index of the last element (exclusive) to be sorted * @param toIndex the index of the last element (exclusive) to be sorted
* @param c the comparator to determine the order of the array. A * @param c the comparator to determine the order of the array. A
* <tt>null</tt> value indicates that the elements' * {@code null} value indicates that the elements'
* {@linkplain Comparable natural ordering} should be used. * {@linkplain Comparable natural ordering} should be used.
* @throws ClassCastException if the array contains elements that are not * @throws ClassCastException if the array contains elements that are not
* <i>mutually comparable</i> using the specified comparator. * <i>mutually comparable</i> using the specified comparator.
* @throws IllegalArgumentException if <tt>fromIndex &gt; toIndex</tt> * @throws IllegalArgumentException if {@code fromIndex > toIndex} or
* @throws ArrayIndexOutOfBoundsException if <tt>fromIndex &lt; 0</tt> or * (optional) if the comparator is found to violate the
* <tt>toIndex &gt; a.length</tt> * {@link Comparator} contract
* @throws ArrayIndexOutOfBoundsException if {@code fromIndex < 0} or
* {@code toIndex > a.length}
*/ */
public static <T> void sort(T[] a, int fromIndex, int toIndex, public static <T> void sort(T[] a, int fromIndex, int toIndex,
Comparator<? super T> c) { Comparator<? super T> c) {
if (LegacyMergeSort.userRequested)
legacyMergeSort(a, fromIndex, toIndex, c);
else
TimSort.sort(a, fromIndex, toIndex, c);
}
/** To be removed in a future release. */
private static <T> void legacyMergeSort(T[] a, int fromIndex, int toIndex,
Comparator<? super T> c) {
rangeCheck(a.length, fromIndex, toIndex); rangeCheck(a.length, fromIndex, toIndex);
T[] aux = copyOfRange(a, fromIndex, toIndex); T[] aux = copyOfRange(a, fromIndex, toIndex);
if (c==null) if (c==null)
...@@ -1270,6 +1432,7 @@ public class Arrays { ...@@ -1270,6 +1432,7 @@ public class Arrays {
* low is the index in dest to start sorting * low is the index in dest to start sorting
* high is the end index in dest to end sorting * high is the end index in dest to end sorting
* off is the offset into src corresponding to low in dest * off is the offset into src corresponding to low in dest
* To be removed in a future release.
*/ */
private static void mergeSort(Object[] src, private static void mergeSort(Object[] src,
Object[] dest, Object[] dest,
......
...@@ -100,23 +100,42 @@ public class Collections { ...@@ -100,23 +100,42 @@ public class Collections {
/** /**
* Sorts the specified list into ascending order, according to the * Sorts the specified list into ascending order, according to the
* <i>natural ordering</i> of its elements. All elements in the list must * {@linkplain Comparable natural ordering} of its elements.
* implement the <tt>Comparable</tt> interface. Furthermore, all elements * All elements in the list must implement the {@link Comparable}
* in the list must be <i>mutually comparable</i> (that is, * interface. Furthermore, all elements in the list must be
* <tt>e1.compareTo(e2)</tt> must not throw a <tt>ClassCastException</tt> * <i>mutually comparable</i> (that is, {@code e1.compareTo(e2)}
* for any elements <tt>e1</tt> and <tt>e2</tt> in the list).<p> * must not throw a {@code ClassCastException} for any elements
* * {@code e1} and {@code e2} in the list).
* This sort is guaranteed to be <i>stable</i>: equal elements will *
* not be reordered as a result of the sort.<p> * <p>This sort is guaranteed to be <i>stable</i>: equal elements will
* * not be reordered as a result of the sort.
* The specified list must be modifiable, but need not be resizable.<p> *
* * <p>The specified list must be modifiable, but need not be resizable.
* The sorting algorithm is a modified mergesort (in which the merge is *
* omitted if the highest element in the low sublist is less than the * <p>Implementation note: This implementation is a stable, adaptive,
* lowest element in the high sublist). This algorithm offers guaranteed * iterative mergesort that requires far fewer than n lg(n) comparisons
* n log(n) performance. * when the input array is partially sorted, while offering the
* * performance of a traditional mergesort when the input array is
* This implementation dumps the specified list into an array, sorts * randomly ordered. If the input array is nearly sorted, the
* implementation requires approximately n comparisons. Temporary
* storage requirements vary from a small constant for nearly sorted
* input arrays to n/2 object references for randomly ordered input
* arrays.
*
* <p>The implementation takes equal advantage of ascending and
* descending order in its input array, and can take advantage of
* ascending and descending order in different parts of the the same
* input array. It is well-suited to merging two or more sorted arrays:
* simply concatenate the arrays and sort the resulting array.
*
* <p>The implementation was adapted from Tim Peters's list sort for Python
* (<a href="http://svn.python.org/projects/python/trunk/Objects/listsort.txt">
* TimSort</a>). It uses techiques from Peter McIlroy's "Optimistic
* Sorting and Information Theoretic Complexity", in Proceedings of the
* Fourth Annual ACM-SIAM Symposium on Discrete Algorithms, pp 467-474,
* January 1993.
*
* <p>This implementation dumps the specified list into an array, sorts
* the array, and iterates over the list resetting each element * the array, and iterates over the list resetting each element
* from the corresponding position in the array. This avoids the * from the corresponding position in the array. This avoids the
* n<sup>2</sup> log(n) performance that would result from attempting * n<sup>2</sup> log(n) performance that would result from attempting
...@@ -126,8 +145,10 @@ public class Collections { ...@@ -126,8 +145,10 @@ public class Collections {
* @throws ClassCastException if the list contains elements that are not * @throws ClassCastException if the list contains elements that are not
* <i>mutually comparable</i> (for example, strings and integers). * <i>mutually comparable</i> (for example, strings and integers).
* @throws UnsupportedOperationException if the specified list's * @throws UnsupportedOperationException if the specified list's
* list-iterator does not support the <tt>set</tt> operation. * list-iterator does not support the {@code set} operation.
* @see Comparable * @throws IllegalArgumentException (optional) if the implementation
* detects that the natural ordering of the list elements is
* found to violate the {@link Comparable} contract
*/ */
public static <T extends Comparable<? super T>> void sort(List<T> list) { public static <T extends Comparable<? super T>> void sort(List<T> list) {
Object[] a = list.toArray(); Object[] a = list.toArray();
...@@ -143,19 +164,38 @@ public class Collections { ...@@ -143,19 +164,38 @@ public class Collections {
* Sorts the specified list according to the order induced by the * Sorts the specified list according to the order induced by the
* specified comparator. All elements in the list must be <i>mutually * specified comparator. All elements in the list must be <i>mutually
* comparable</i> using the specified comparator (that is, * comparable</i> using the specified comparator (that is,
* <tt>c.compare(e1, e2)</tt> must not throw a <tt>ClassCastException</tt> * {@code c.compare(e1, e2)} must not throw a {@code ClassCastException}
* for any elements <tt>e1</tt> and <tt>e2</tt> in the list).<p> * for any elements {@code e1} and {@code e2} in the list).
* *
* This sort is guaranteed to be <i>stable</i>: equal elements will * <p>This sort is guaranteed to be <i>stable</i>: equal elements will
* not be reordered as a result of the sort.<p> * not be reordered as a result of the sort.
* *
* The sorting algorithm is a modified mergesort (in which the merge is * <p>The specified list must be modifiable, but need not be resizable.
* omitted if the highest element in the low sublist is less than the *
* lowest element in the high sublist). This algorithm offers guaranteed * <p>Implementation note: This implementation is a stable, adaptive,
* n log(n) performance. * iterative mergesort that requires far fewer than n lg(n) comparisons
* * when the input array is partially sorted, while offering the
* The specified list must be modifiable, but need not be resizable. * performance of a traditional mergesort when the input array is
* This implementation dumps the specified list into an array, sorts * randomly ordered. If the input array is nearly sorted, the
* implementation requires approximately n comparisons. Temporary
* storage requirements vary from a small constant for nearly sorted
* input arrays to n/2 object references for randomly ordered input
* arrays.
*
* <p>The implementation takes equal advantage of ascending and
* descending order in its input array, and can take advantage of
* ascending and descending order in different parts of the the same
* input array. It is well-suited to merging two or more sorted arrays:
* simply concatenate the arrays and sort the resulting array.
*
* <p>The implementation was adapted from Tim Peters's list sort for Python
* (<a href="http://svn.python.org/projects/python/trunk/Objects/listsort.txt">
* TimSort</a>). It uses techiques from Peter McIlroy's "Optimistic
* Sorting and Information Theoretic Complexity", in Proceedings of the
* Fourth Annual ACM-SIAM Symposium on Discrete Algorithms, pp 467-474,
* January 1993.
*
* <p>This implementation dumps the specified list into an array, sorts
* the array, and iterates over the list resetting each element * the array, and iterates over the list resetting each element
* from the corresponding position in the array. This avoids the * from the corresponding position in the array. This avoids the
* n<sup>2</sup> log(n) performance that would result from attempting * n<sup>2</sup> log(n) performance that would result from attempting
...@@ -163,13 +203,14 @@ public class Collections { ...@@ -163,13 +203,14 @@ public class Collections {
* *
* @param list the list to be sorted. * @param list the list to be sorted.
* @param c the comparator to determine the order of the list. A * @param c the comparator to determine the order of the list. A
* <tt>null</tt> value indicates that the elements' <i>natural * {@code null} value indicates that the elements' <i>natural
* ordering</i> should be used. * ordering</i> should be used.
* @throws ClassCastException if the list contains elements that are not * @throws ClassCastException if the list contains elements that are not
* <i>mutually comparable</i> using the specified comparator. * <i>mutually comparable</i> using the specified comparator.
* @throws UnsupportedOperationException if the specified list's * @throws UnsupportedOperationException if the specified list's
* list-iterator does not support the <tt>set</tt> operation. * list-iterator does not support the {@code set} operation.
* @see Comparator * @throws IllegalArgumentException (optional) if the comparator is
* found to violate the {@link Comparator} contract
*/ */
public static <T> void sort(List<T> list, Comparator<? super T> c) { public static <T> void sort(List<T> list, Comparator<? super T> c) {
Object[] a = list.toArray(); Object[] a = list.toArray();
......
此差异已折叠。
...@@ -2818,15 +2818,18 @@ public final class Formatter implements Closeable, Flushable { ...@@ -2818,15 +2818,18 @@ public final class Formatter implements Closeable, Flushable {
} }
private void printString(Object arg, Locale l) throws IOException { private void printString(Object arg, Locale l) throws IOException {
if (arg == null) { if (arg instanceof Formattable) {
print("null");
} else if (arg instanceof Formattable) {
Formatter fmt = formatter; Formatter fmt = formatter;
if (formatter.locale() != l) if (formatter.locale() != l)
fmt = new Formatter(formatter.out(), l); fmt = new Formatter(formatter.out(), l);
((Formattable)arg).formatTo(fmt, f.valueOf(), width, precision); ((Formattable)arg).formatTo(fmt, f.valueOf(), width, precision);
} else { } else {
print(arg.toString()); if (f.contains(Flags.ALTERNATE))
failMismatch(Flags.ALTERNATE, 's');
if (arg == null)
print("null");
else
print(arg.toString());
} }
} }
......
此差异已折叠。
...@@ -44,15 +44,11 @@ public class AccessibleResourceBundle extends ListResourceBundle { ...@@ -44,15 +44,11 @@ public class AccessibleResourceBundle extends ListResourceBundle {
* localized display strings. * localized display strings.
*/ */
public Object[][] getContents() { public Object[][] getContents() {
return contents; // The table holding the mapping between the programmatic keys
} // and the display strings for the en_US locale.
return new Object[][] {
/** // LOCALIZE THIS
* The table holding the mapping between the programmatic keys
* and the display strings for the en_US locale.
*/
static final Object[][] contents = {
// LOCALIZE THIS
// Role names // Role names
// { "application","application" }, // { "application","application" },
// { "border","border" }, // { "border","border" },
...@@ -151,5 +147,6 @@ public class AccessibleResourceBundle extends ListResourceBundle { ...@@ -151,5 +147,6 @@ public class AccessibleResourceBundle extends ListResourceBundle {
{ "vertical","vertical" }, { "vertical","vertical" },
{ "horizontal","horizontal" } { "horizontal","horizontal" }
// END OF MATERIAL TO LOCALIZE // END OF MATERIAL TO LOCALIZE
}; };
}
} }
...@@ -78,7 +78,7 @@ public class BMPImageWriteParam extends ImageWriteParam { ...@@ -78,7 +78,7 @@ public class BMPImageWriteParam extends ImageWriteParam {
super(locale); super(locale);
// Set compression types ("BI_RGB" denotes uncompressed). // Set compression types ("BI_RGB" denotes uncompressed).
compressionTypes = BMPConstants.compressionTypeNames; compressionTypes = BMPConstants.compressionTypeNames.clone();
// Set compression flag. // Set compression flag.
canWriteCompressed = true; canWriteCompressed = true;
......
...@@ -77,7 +77,10 @@ public abstract class ImageReaderSpi extends ImageReaderWriterSpi { ...@@ -77,7 +77,10 @@ public abstract class ImageReaderSpi extends ImageReaderWriterSpi {
* A single-element array, initially containing * A single-element array, initially containing
* <code>ImageInputStream.class</code>, to be returned from * <code>ImageInputStream.class</code>, to be returned from
* <code>getInputTypes</code>. * <code>getInputTypes</code>.
* @deprecated Instead of using this field, directly create
* the equivalent array <code>{ ImageInputStream.class }<code>.
*/ */
@Deprecated
public static final Class[] STANDARD_INPUT_TYPE = public static final Class[] STANDARD_INPUT_TYPE =
{ ImageInputStream.class }; { ImageInputStream.class };
...@@ -227,7 +230,11 @@ public abstract class ImageReaderSpi extends ImageReaderWriterSpi { ...@@ -227,7 +230,11 @@ public abstract class ImageReaderSpi extends ImageReaderWriterSpi {
throw new IllegalArgumentException throw new IllegalArgumentException
("inputTypes.length == 0!"); ("inputTypes.length == 0!");
} }
this.inputTypes = (Class[])inputTypes.clone();
this.inputTypes = (inputTypes == STANDARD_INPUT_TYPE) ?
new Class<?>[] { ImageInputStream.class } :
inputTypes.clone();
// If length == 0, leave it null // If length == 0, leave it null
if (writerSpiNames != null && writerSpiNames.length > 0) { if (writerSpiNames != null && writerSpiNames.length > 0) {
this.writerSpiNames = (String[])writerSpiNames.clone(); this.writerSpiNames = (String[])writerSpiNames.clone();
......
...@@ -304,7 +304,12 @@ public abstract class OpenType<T> implements Serializable { ...@@ -304,7 +304,12 @@ public abstract class OpenType<T> implements Serializable {
* @return the class name. * @return the class name.
*/ */
public String getClassName() { public String getClassName() {
return className;
}
// A version of getClassName() that can only be called from within this
// package and that cannot be overridden.
String safeGetClassName() {
return className; return className;
} }
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册