diff --git a/.hgtags b/.hgtags index 95051d6a0d4f8d3e94c0651126bb6f226e9e67ab..f3ad419b9a7cd9ccabf41383826cae073808e31a 100644 --- a/.hgtags +++ b/.hgtags @@ -23,3 +23,10 @@ d8eb2738db6b148911177d9bcfe888109b7f2f71 jdk7-b44 4b03e27a44090d1f646af28dc58f9ead827e24c7 jdk7-b46 b4ac413b1f129eeef0acab3f31081c1b7dfe3b27 jdk7-b47 5fbd9ea7def17186693b6f7099b5d0dc73903eee jdk7-b48 +8311105ea7a3db7bcbcb2b696459127c7f2297a4 jdk7-b49 +58ba2cd5a25053684ec53205d95edeeaa0006f13 jdk7-b50 +fea0898259ae41c73620b1815aa48f036216155c jdk7-b51 +bcbeadb4a5d759b29e876ee2c83401e91ff22f60 jdk7-b52 +a2033addca678f9e4c0d92ffa1e389171cc9321d jdk7-b53 +d1c43d1f5676a24ba86221ac7cad5694f3a9afda jdk7-b54 +522bb5aa17e0c0cff00b1ed7d1b51bc4db2cfef9 jdk7-b55 diff --git a/THIRD_PARTY_README b/THIRD_PARTY_README index 9f4d7e5087a200b17e0ea8778c9de8dfe892d5a2..690890548f228e7601de0505df22f715e43d8a74 100644 --- a/THIRD_PARTY_README +++ b/THIRD_PARTY_README @@ -61,6 +61,28 @@ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +%% This notice is provided with respect to littlecms, which may be included with this software: + +Little cms +Copyright (C) 1998-2004 Marti Maria + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. %% This notice is provided with respect to zlib 1.1.3, which may be included with this software: Acknowledgments: @@ -115,16 +137,6 @@ COPYRIGHT HOLDERS WILL NOT BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL OR CONSEQ The name and trademarks of copyright holders may NOT be used in advertising or publicity pertaining to the software without specific, written prior permission. Title to copyright in this software and any associated documentation will at all times remain with copyright holders. ____________________________________ This formulation of W3C's notice and license became active on August 14 1998 so as to improve compatibility with GPL. This version ensures that W3C software licensing terms are no more restrictive than GPL and consequently W3C software may be distributed in GPL packages. See the older formulation for the policy prior to this date. Please see our Copyright FAQ for common questions about using materials from our site, including specific terms and conditions for packages like libwww, Amaya, and Jigsaw. Other questions about this notice can be directed to site-policy@w3.org. -  -%% This notice is provided with respect to jscheme.jar, which may be included with this software: -Software License Agreement -Copyright © 1998-2002 by Peter Norvig. -Permission is granted to anyone to use this software, in source or object code form, on any computer system, and to modify, compile, decompile, run, and redistribute it to anyone else, subject to the following restrictions: -1.The author makes no warranty of any kind, either expressed or implied, about the suitability of this software for any purpose. -2.The author accepts no liability of any kind for damages or other consequences of the use of this software, even if they arise from defects in the software. -3.The origin of this software must not be misrepresented, either by explicit claim or by omission. -4.Altered versions must be plainly marked as such, and must not be misrepresented as being the original software. Altered versions may be distributed in packages under other licenses (such as the GNU license). -If you find this software useful, it would be nice if you let me (peter@norvig.com) know about it, and nicer still if you send me modifications that you are willing to share. However, you are not required to do so. %% This notice is provided with respect to PC/SC Lite for Suse Linux v. 1.1.1, which may be included with this software: diff --git a/make/com/sun/jmx/Makefile b/make/com/sun/jmx/Makefile index c529dd4be31eed20d73efaf3e8af0bd8b7e033e2..81470f0befed24d8156d9b3721727665bb62aa9d 100644 --- a/make/com/sun/jmx/Makefile +++ b/make/com/sun/jmx/Makefile @@ -41,7 +41,15 @@ include $(BUILDDIR)/common/Defs.gmk # Note : some targets are double colon rules and some single colon rules # within common included gmk files : that is why the following for loop # has been duplicated. -SUBDIRS = snmp + +# When building the openjdk, build snmp only if importing binary plugs, +ifdef OPENJDK + ifeq ($(IMPORT_BINARY_PLUGS),true) + SUBDIRS = snmp + endif +else + SUBDIRS = snmp +endif all build: $(SUBDIRS-loop) diff --git a/make/common/Defs-linux.gmk b/make/common/Defs-linux.gmk index 28d58376fe279f7fb831a455e6520601181846c4..591b6ccae31ffb39559f9aea7f33621cfb701975 100644 --- a/make/common/Defs-linux.gmk +++ b/make/common/Defs-linux.gmk @@ -94,6 +94,9 @@ ifndef OPTIMIZATION_LEVEL OPTIMIZATION_LEVEL = LOWER endif endif +ifndef FASTDEBUG_OPTIMIZATION_LEVEL + FASTDEBUG_OPTIMIZATION_LEVEL = LOWER +endif CC_OPT/NONE = CC_OPT/LOWER = -O2 @@ -116,6 +119,14 @@ LDFLAGS_COMMON_sparc += -m32 -mcpu=v9 CFLAGS_REQUIRED = $(CFLAGS_REQUIRED_$(ARCH)) LDFLAGS_COMMON += $(LDFLAGS_COMMON_$(ARCH)) +# If this is a --hash-style=gnu system, use --hash-style=both +# The gnu .hash section won't work on some Linux systems like SuSE 10. +_HAS_HASH_STYLE_GNU:=$(shell $(CC) -dumpspecs | $(GREP) -- '--hash-style=gnu') +ifneq ($(_HAS_HASH_STYLE_GNU),) + LDFLAGS_HASH_STYLE = -Wl,--hash-style=both +endif +LDFLAGS_COMMON += $(LDFLAGS_HASH_STYLE) + # # Selection of warning messages # @@ -165,8 +176,8 @@ CXXFLAGS_COMMON += $(CFLAGS_REQUIRED) # FASTDEBUG: Optimize the code in the -g versions, gives us a faster debug java ifeq ($(FASTDEBUG), true) - CFLAGS_DBG += $(CC_OPT/LOWER) - CXXFLAGS_DBG += $(CC_OPT/LOWER) + CFLAGS_DBG += $(CC_OPT/$(FASTDEBUG_OPTIMIZATION_LEVEL)) + CXXFLAGS_DBG += $(CC_OPT/$(FASTDEBUG_OPTIMIZATION_LEVEL)) endif CPPFLAGS_COMMON = -D$(ARCH) -DARCH='"$(ARCH)"' -DLINUX $(VERSION_DEFINES) \ diff --git a/make/common/Defs-solaris.gmk b/make/common/Defs-solaris.gmk index 9b5cc8b721bf830bf932f134d23e1c960d4ba509..5b1d237caae2848c58f3f36e7fd82c07d3e6da00 100644 --- a/make/common/Defs-solaris.gmk +++ b/make/common/Defs-solaris.gmk @@ -93,6 +93,9 @@ ifndef OPTIMIZATION_LEVEL OPTIMIZATION_LEVEL = LOWER endif endif +ifndef FASTDEBUG_OPTIMIZATION_LEVEL + FASTDEBUG_OPTIMIZATION_LEVEL = LOWER +endif # # If -Xa is in CFLAGS_COMMON it will end up ahead of $(CC_OPT) for the @@ -143,8 +146,8 @@ endif # Performance/size of files should be about the same, maybe smaller. # ifeq ($(FASTDEBUG), true) - CFLAGS_DEBUG_OPTION = -g $(CC_OPT/LOWER) - CXXFLAGS_DEBUG_OPTION = -g0 $(CXX_OPT/LOWER) + CFLAGS_DEBUG_OPTION = -g $(CC_OPT/$(FASTDEBUG_OPTIMIZATION_LEVEL)) + CXXFLAGS_DEBUG_OPTION = -g0 $(CXX_OPT/$(FASTDEBUG_OPTIMIZATION_LEVEL)) endif CFLAGS_COMMON = -L$(OBJDIR) diff --git a/make/common/Defs-windows.gmk b/make/common/Defs-windows.gmk index 7b178497e128fbe448ca7fc14163bfc639c318ce..00b8ea71e2a668a0e9241c993af185d66114aadf 100644 --- a/make/common/Defs-windows.gmk +++ b/make/common/Defs-windows.gmk @@ -70,7 +70,6 @@ PLATFORM_INCLUDE = $(INCLUDEDIR)/$(PLATFORM_INCLUDE_NAME) # not to be REBASEd, see deploy/make/common/Release.gmk. # msvcrt.dll, msvcrnn.dll [msvcr71 or msvcr80 or msvcr90] : Microsoft runtimes MS_RUNTIME_LIBRARIES = msvcrt.dll -MSVCRNN_DLL = ifeq ($(ARCH_DATA_MODEL), 32) ifeq ($(COMPILER_VERSION), VS2003) MSVCRNN_DLL = msvcr71.dll @@ -89,6 +88,13 @@ ifeq ($(ARCH_DATA_MODEL), 32) endif endif +ifeq ($(ARCH_DATA_MODEL), 64) + ifeq ($(COMPILER_VERSION), VS2008) + MSVCRNN_DLL = msvcr90.dll + MSVCPNN_DLL = msvcp90.dll + MS_RUNTIME_LIBRARIES += $(MSVCRNN_DLL) + endif +endif EXTRA_LFLAGS += /LIBPATH:$(DXSDK_LIB_PATH) @@ -105,6 +111,9 @@ ifndef OPTIMIZATION_LEVEL OPTIMIZATION_LEVEL = LOWER endif endif +ifndef FASTDEBUG_OPTIMIZATION_LEVEL + FASTDEBUG_OPTIMIZATION_LEVEL = LOWER +endif ifeq ($(CC_VERSION),msvc) # Visual Studio .NET 2003 or VS2003 compiler option definitions: @@ -344,17 +353,12 @@ CFLAGS_COMMON += -Fd$(OBJDIR)/$(basename $(@F)).pdb -Fm$(OBJDIR)/$(basename $(@F COMPILER_WARNINGS_TO_IGNORE = 4800 CFLAGS_COMMON += $(COMPILER_WARNINGS_TO_IGNORE:%=-wd%) -# -# Add warnings and extra on 64bit issues -# -ifeq ($(ARCH_DATA_MODEL), 64) - CFLAGS_COMMON += -Wp64 -endif - # # Treat compiler warnings as errors, if requested # CFLAGS_COMMON += -W$(COMPILER_WARNING_LEVEL) +# Turn off security warnings about using the standard C library function strcpy +CFLAGS_COMMON += -D _CRT_SECURE_NO_DEPRECATE ifeq ($(COMPILER_WARNINGS_FATAL),true) CFLAGS_COMMON += -WX endif @@ -398,16 +402,7 @@ ifeq ($(ARCH), ia64) # SA will never be supported here. INCLUDE_SA = false else - # Hopefully, SA will be supported here one of these days, - # and these will be changed to true. Until then, - # to build SA on windows, do a control build with - # BUILD_WIN_SA=1 - # on the make command. - ifdef BUILD_WIN_SA - INCLUDE_SA = true - else - INCLUDE_SA = false - endif + INCLUDE_SA = true endif # Settings for the VERSIONINFO tap on windows. diff --git a/make/common/Defs.gmk b/make/common/Defs.gmk index 33eedad16a4150050be56f7519ebe9dbcd68281e..d959123fdae054a072f9f0d0c26f9bdd83b5b8f1 100644 --- a/make/common/Defs.gmk +++ b/make/common/Defs.gmk @@ -145,6 +145,11 @@ endif # 2. ALT_BINARY_PLUGS_PATH overrides all locations of classes and libraries # 3. ALT_BUILD_BINARY_PLUGS_PATH is used to find a ALT_BINARY_PLUGS_PATH # 4. ALT_CLOSED_JDK_IMPORT_PATH is used to locate classes and libraries +# Note: If any of the ALT_ variables are modified here, it is assumed +# that the build should be done with IMPORT_BINARY_PLUGS=true as +# well. Otherwise the default will be IMPORT_BINARY_PLUGS=false. +# Lastly, setting IMPORT_BINARY_PLUGS=false on the command line +# will override this logic, and plugs will not be imported. # # Always needed, defines the name of the imported/exported jarfile @@ -155,9 +160,11 @@ ifdef OPENJDK CLOSED_JDK_IMPORT_PATH = $(ALT_CLOSED_JDK_IMPORT_PATH) BINARY_PLUGS_PATH = $(CLOSED_JDK_IMPORT_PATH) BINARY_PLUGS_JARFILE = $(CLOSED_JDK_IMPORT_PATH)/jre/lib/rt.jar + IMPORT_BINARY_PLUGS=true endif ifdef ALT_BUILD_BINARY_PLUGS_PATH BUILD_BINARY_PLUGS_PATH = $(ALT_BUILD_BINARY_PLUGS_PATH) + IMPORT_BINARY_PLUGS=true else BUILD_BINARY_PLUGS_PATH = $(SLASH_JAVA)/re/jdk/$(JDK_VERSION)/promoted/latest/openjdk/binaryplugs endif @@ -166,9 +173,11 @@ ifdef OPENJDK ifdef ALT_BINARY_PLUGS_PATH BINARY_PLUGS_PATH = $(ALT_BINARY_PLUGS_PATH) BINARY_PLUGS_JARFILE = $(BINARY_PLUGS_PATH)/jre/lib/$(BINARY_PLUGS_JARNAME) + IMPORT_BINARY_PLUGS=true endif ifdef ALT_BINARY_PLUGS_JARFILE BINARY_PLUGS_JARFILE = $(ALT_BINARY_PLUGS_JARFILE) + IMPORT_BINARY_PLUGS=true endif endif # OPENJDK diff --git a/make/common/shared/Compiler-gcc.gmk b/make/common/shared/Compiler-gcc.gmk index 2750195636893c87110e19e1eb45ac799633e25b..29b8c0a80a420954d1ec1fffa6f58a3e38733246 100644 --- a/make/common/shared/Compiler-gcc.gmk +++ b/make/common/shared/Compiler-gcc.gmk @@ -27,8 +27,6 @@ # GCC Compiler settings # -COMPILER_NAME=GCC - ifeq ($(PLATFORM), windows) # Settings specific to Windows, pretty stale, hasn't been used @@ -68,24 +66,6 @@ ifeq ($(PLATFORM), linux) else CXX = $(COMPILER_PATH)g++ endif - ifneq ("$(findstring sparc,$(ARCH))", "") - # sparc or sparcv9 - REQUIRED_CC_VER = 4.0 - REQUIRED_GCC_VER = 4.0.* - else - REQUIRED_CC_VER = 3.2 - ifeq ($(ARCH_DATA_MODEL), 32) - REQUIRED_GCC_VER = 3.2.1* - REQUIRED_GCC_VER_INT = 3.2.1-7a - else - ifeq ($(ARCH), amd64) - REQUIRED_GCC_VER = 3.2.* - endif - ifeq ($(ARCH), ia64) - REQUIRED_GCC_VER = 2.9[56789].* - endif - endif - endif # Option used to create a shared library SHARED_LIBRARY_FLAG = -shared -mimpure-text SUN_COMP_VER := $(shell $(CC) --verbose 2>&1 ) @@ -98,21 +78,17 @@ ifeq ($(PLATFORM), solaris) CC = $(COMPILER_PATH)gcc CPP = $(COMPILER_PATH)gcc -E CXX = $(COMPILER_PATH)g++ - REQUIRED_CC_VER = 3.2 # Option used to create a shared library SHARED_LIBRARY_FLAG = -G - # But gcc is still needed no matter what on 32bit - ifeq ($(ARCH_DATA_MODEL), 32) - REQUIRED_GCC_VER = 2.95 - GCC =$(GCC_COMPILER_PATH)gcc - _GCC_VER :=$(shell $(GCC) -dumpversion 2>&1 ) - GCC_VER :=$(call GetVersion,"$(_GCC_VER)") - endif - + endif # Get gcc version _CC_VER :=$(shell $(CC) -dumpversion 2>&1 ) CC_VER :=$(call GetVersion,"$(_CC_VER)") +# Name of compiler +COMPILER_NAME = GCC$(call MajorVersion,$(CC_VER)) +COMPILER_VERSION = $(COMPILER_NAME) + diff --git a/make/common/shared/Compiler-msvc.gmk b/make/common/shared/Compiler-msvc.gmk index d23529f39357bf2c03539935cfb4a6eaf80e9d2c..ade430ad9ea06f70ac46185985b9dccddf7abf6e 100644 --- a/make/common/shared/Compiler-msvc.gmk +++ b/make/common/shared/Compiler-msvc.gmk @@ -41,8 +41,6 @@ ifeq ($(PLATFORM), windows) # Fill in unknown values COMPILER_NAME=Unknown MSVC Compiler COMPILER_VERSION= - REQUIRED_CC_VER= - REQUIRED_LINK_VER= # unset any GNU Make settings of MFLAGS and MAKEFLAGS which may mess up nmake NMAKE = MFLAGS= MAKEFLAGS= $(COMPILER_PATH)nmake -nologo @@ -56,8 +54,6 @@ ifeq ($(PLATFORM), windows) CC_MAJORVER :=$(call MajorVersion,$(CC_VER)) ifeq ($(CC_MAJORVER), 13) # This should be: CC_VER=13.10.3077 LINK_VER=7.10.3077 - REQUIRED_CC_VER = 13.10.3077 - REQUIRED_LINK_VER = 7.10.3077 COMPILER_NAME=Visual Studio .NET 2003 Professional C++ COMPILER_VERSION=VS2003 REBASE = $(COMPILER_PATH)../../Common7/Tools/Bin/rebase @@ -67,9 +63,6 @@ ifeq ($(PLATFORM), windows) endif endif ifeq ($(CC_MAJORVER), 14) - # This should be: CC_VER=14.00.50727.42 LINK_VER=8.00.50727.42 - REQUIRED_CC_VER = 14.00.50727.42 - REQUIRED_LINK_VER = 8.00.50727.42 COMPILER_NAME=Visual Studio 8 COMPILER_VERSION=VS2005 REBASE = $(COMPILER_PATH)../../Common8/Tools/Bin/rebase @@ -80,9 +73,6 @@ ifeq ($(PLATFORM), windows) endif endif ifeq ($(CC_MAJORVER), 15) - # This should be: CC_VER=15.00.21022.08 LINK_VER=9.00.21022.08 - REQUIRED_CC_VER = 15.00.21022.08 - REQUIRED_LINK_VER = 9.00.21022.08 COMPILER_NAME=Visual Studio 9 COMPILER_VERSION=VS2008 #rebase and midl moved out of Visual Studio into the SDK: @@ -99,14 +89,6 @@ ifeq ($(PLATFORM), windows) CC_MAJORVER :=$(call MajorVersion,$(CC_VER)) CC_MINORVER :=$(call MinorVersion,$(CC_VER)) CC_MICROVER :=$(call MicroVersion,$(CC_VER)) - ifeq ($(ARCH), ia64) - REQUIRED_CC_VER = 13.00.9337.7 - REQUIRED_LINK_VER = 7.00.9337.7 - endif - ifeq ($(ARCH), amd64) - REQUIRED_CC_VER = 14.00.40310.41 - REQUIRED_LINK_VER = 8.00.40310.39 - endif ifeq ($(CC_MAJORVER), 13) ifeq ($(ARCH), ia64) # This should be: CC_VER=13.00.9337.7 LINK_VER=7.00.9337.7 @@ -130,6 +112,12 @@ ifeq ($(PLATFORM), windows) endif endif endif + ifeq ($(CC_MAJORVER), 15) + COMPILER_NAME=Microsoft Windows SDK with Visual Studio 9 (6001.18000.367) + COMPILER_VERSION=VS2008 + RC = $(MSSDK61)/Bin/X64/rc.exe + MT = $(MSSDK61)/Bin/X64/mt.exe + endif # This will cause problems if ALT_COMPILER_PATH is defined to "" # which is a directive to use the PATH. REBASE = $(COMPILER_PATH)../REBASE diff --git a/make/common/shared/Compiler-sun.gmk b/make/common/shared/Compiler-sun.gmk index b3c4e2a90b1611ba2283985b1ae8f441aa966b4e..8bbd16f21f811fe60b1c43d114c92af784ff4d5d 100644 --- a/make/common/shared/Compiler-sun.gmk +++ b/make/common/shared/Compiler-sun.gmk @@ -27,32 +27,20 @@ # Sun Studio Compiler settings # -COMPILER_NAME=Sun Studio - # Sun Studio Compiler settings specific to Solaris ifeq ($(PLATFORM), solaris) - COMPILER_VERSION=SS12 - REQUIRED_CC_VER=5.9 CC = $(COMPILER_PATH)cc CPP = $(COMPILER_PATH)cc -E CXX = $(COMPILER_PATH)CC LINT = $(COMPILER_PATH)lint # Option used to create a shared library SHARED_LIBRARY_FLAG = -G - # But gcc is still needed no matter what on 32bit - ifeq ($(ARCH_DATA_MODEL), 32) - REQUIRED_GCC_VER = 2.95 - GCC =$(GCC_COMPILER_PATH)gcc - _GCC_VER :=$(shell $(GCC) -dumpversion 2>&1 ) - GCC_VER :=$(call GetVersion,"$(_GCC_VER)") - endif + GCC =$(GCC_COMPILER_PATH)gcc endif # Sun Studio Compiler settings specific to Linux ifeq ($(PLATFORM), linux) # This has not been tested - COMPILER_VERSION=SS12 - REQUIRED_CC_VER=5.9 CC = $(COMPILER_PATH)cc CPP = $(COMPILER_PATH)cc -E CXX = $(COMPILER_PATH)CC @@ -74,6 +62,18 @@ endif _CC_VER :=$(shell $(CC) -V 2>&1 | $(HEAD) -n 1) CC_VER :=$(call GetVersion,"$(_CC_VER)") +# Name of compilers being used +COMPILER_VERSION-5.7 = SS10 +COMPILER_NAME-5.7 = Sun Studio 10 +COMPILER_VERSION-5.8 = SS11 +COMPILER_NAME-5.8 = Sun Studio 11 +COMPILER_VERSION-5.9 = SS12 +COMPILER_NAME-5.9 = Sun Studio 12 +COMPILER_VERSION-5.10 = SS13 +COMPILER_NAME-5.10 = Sun Studio 13 +COMPILER_VERSION = $(COMPILER_VERSION-$(CC_VER)) +COMPILER_NAME = $(COMPILER_NAME-$(CC_VER)) + # Arch specific settings (determines type of .o files and instruction set) # Starting in SS12 (5.9), the arch options changed. # The assembler /usr/ccs/bin/as wants older SS11 (5.8) style options. diff --git a/make/common/shared/Defs-java.gmk b/make/common/shared/Defs-java.gmk index 9bfb96da4537ebe9b8d22c92cde64ca6c689d2ee..78f87294fbed936254ae63da45e61048554a01fc 100644 --- a/make/common/shared/Defs-java.gmk +++ b/make/common/shared/Defs-java.gmk @@ -59,7 +59,15 @@ else ADD_CLIENT_VM_OPTION = true endif endif -JAVA_JVM_FLAGS = + +# Options for hotspot to turn off printing of options with fastdebug version +# and creating the hotspot.log file. +JAVA_HOTSPOT_DISABLE_PRINT_VMOPTIONS = \ + -XX:-PrintVMOptions -XX:+UnlockDiagnosticVMOptions -XX:-LogVMOutput + +# JVM options +JAVA_JVM_FLAGS = $(JAVA_HOTSPOT_DISABLE_PRINT_VMOPTIONS) + ifeq ($(ADD_CLIENT_VM_OPTION), true) JAVA_JVM_FLAGS += -client endif @@ -129,6 +137,9 @@ JAVACFLAGS += $(OTHER_JAVACFLAGS) # Needed for javah JAVAHFLAGS += -bootclasspath $(CLASSBINDIR) +# Needed for JAVADOC and BOOT_JAVACFLAGS +NO_PROPRIETARY_API_WARNINGS = -XDignore.symbol.file=true + # Langtools ifdef LANGTOOLS_DIST JAVAC_JAR = $(LANGTOOLS_DIST)/bootstrap/lib/javac.jar @@ -192,6 +203,8 @@ endif BOOT_JAVACFLAGS += -encoding ascii BOOT_JAR_JFLAGS += $(JAR_JFLAGS) +BOOT_JAVACFLAGS += $(NO_PROPRIETARY_API_WARNINGS) + BOOT_JAVA_CMD = $(BOOTDIR)/bin/java $(JAVA_TOOLS_FLAGS) BOOT_JAVAC_CMD = $(BOOTDIR)/bin/javac $(JAVAC_JVM_FLAGS) $(BOOT_JAVACFLAGS) BOOT_JAR_CMD = $(BOOTDIR)/bin/jar diff --git a/make/common/shared/Defs-solaris.gmk b/make/common/shared/Defs-solaris.gmk index b3630bac34bb074f319b66b062f833d2c685013c..8da2d61dc2ca595b5e051fe1f9b544e36b5c2edc 100644 --- a/make/common/shared/Defs-solaris.gmk +++ b/make/common/shared/Defs-solaris.gmk @@ -91,14 +91,14 @@ endif ifneq "$(origin ALT_COMPILER_PATH)" "undefined" COMPILER_PATH :=$(call PrefixPath,$(ALT_COMPILER_PATH)) else - # Careful here, COMPILER_VERSION may not be defined yet (see Compiler.gmk) + # Careful here, REQUIRED_COMPILER_VERSION may not be defined yet (see Defs-versions.gmk) # If the place where we keep a set of Sun Studio compilers doesn't exist, # try and use /opt/SUNWspro, the default location for the SS compilers. # (DirExists checks for this path twice, an automount double check) _SUNSTUDIO_SET_ROOT=$(JDK_DEVTOOLS_DIR)/$(ARCH_FAMILY)/SUNWspro SUNSTUDIO_SET_ROOT:=$(call DirExists,$(_SUNSTUDIO_SET_ROOT),$(_SUNSTUDIO_SET_ROOT),) ifneq ($(SUNSTUDIO_SET_ROOT),) - COMPILER_PATH =$(SUNSTUDIO_SET_ROOT)/$(COMPILER_VERSION)/bin/ + COMPILER_PATH =$(SUNSTUDIO_SET_ROOT)/$(REQUIRED_COMPILER_VERSION)/bin/ else COMPILER_PATH =/opt/SUNWspro/bin/ endif diff --git a/make/common/shared/Defs-versions.gmk b/make/common/shared/Defs-versions.gmk new file mode 100644 index 0000000000000000000000000000000000000000..0fc1bab461742ee98889d3440487582f5982b510 --- /dev/null +++ b/make/common/shared/Defs-versions.gmk @@ -0,0 +1,199 @@ +# +# 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. +# + +# +# WARNING: This file is shared with other workspaces. +# + +# This file needs these set: CC_VERSION, PLATFORM, ARCH_FAMILY, and ARCH_DATA_MODEL. + +########################################################################## +# +# List of JDK official minimum, expected, or required versions: +# +# REQUIRED_ALSA_VERSION +# Linux only: The ALSA sound library version expected. +# +# REQUIRED_ANT_VER +# The minimum 'ant' version. +# +# REQUIRED_BOOT_VER +# The minimum boot jdk version. +# +# REQUIRED_CC_VER +# The primary C compiler version expected. +# +# REQUIRED_COMPILER_NAME +# The long descriptive name of the compiler we should use +# +# REQUIRED_COMPILER_VERSION +# The one word name that identifies the compilers being used. +# +# REQUIRED_CYGWIN_VER +# Windows only: If CYGWIN is used, the minimum CYGWIN version. +# +# REQUIRED_DXSDK_VER +# Windows only: The version of DirectX SDK expected. +# +# REQUIRED_FREE_SPACE +# The minimum disk space needed as determined by running 'du -sk' on a fully +# built workspace. +# +# REQUIRED_FREETYPE_VERSION +# If we are using freetype, the freetype version expected. +# +# REQUIRED_GCC_VER +# Solaris and Linux only. The required version of gcc/g++ for the plugin. +# +# REQUIRED_LINK_VER +# Windows only: The version of link.exe expected. +# +# REQUIRED_MAKE_VER +# The minimum version of GNU make. +# +# REQUIRED_MKS_VER +# Windows only: If MKS used instead of CYGWIN, the minimum version of MKS. +# +# REQUIRED_OS_VARIANT_NAME +# The OS variation name required. +# Solaris: Solaris or OpenSolaris +# Windows: Windows2000, WindowsXP, Windows2003, etc. +# Linux: Fedora, RedHat, SuSE, Ubuntu, etc. +# +# REQUIRED_OS_VARIANT_VERSION +# The version number associated with the above OS variant name. +# Solaris: output of uname -r +# Windows: 5.0 for Windows2000, 5.1 for WindowsXP, 5.2 for Windows2003, etc. +# Linux: number for the variant, e.g. 9 for Fedora 9 +# +# REQUIRED_OS_VERSION +# The formal OS version number. +# Solaris & Windows: same as REQUIRED_OS_VARIANT_VERSION +# Linux: the kernel version, or output of uname -r +# +# REQUIRED_UNZIP_VER +# The minimum version of unzip. +# +# REQUIRED_ZIP_VER +# The minimum version of unzip. +# +########### +# +# Differences in the build platform from these versions may trigger warnings +# messages during the sanity checking when building the JDK. +# +# When building the OpenJDK most of these required or expected versions are +# ignored or allowed to vary widely to accomodate the many build situations +# of the OpenJDK. +# +########################################################################## + +# Solaris specific +ifeq ($(PLATFORM), solaris) + REQUIRED_OS_VERSION = 5.10 + REQUIRED_OS_VARIANT_NAME = Solaris + REQUIRED_OS_VARIANT_VERSION = $(REQUIRED_OS_VERSION) + ifeq ($(ARCH_FAMILY), sparc) + REQUIRED_FREE_SPACE = 1300000 + else + REQUIRED_FREE_SPACE = 1040000 + endif + REQUIRED_COMPILER_NAME = Sun Studio 12 + REQUIRED_COMPILER_VERSION = SS12 + ifeq ($(CC_VERSION),sun) + REQUIRED_CC_VER = 5.9 + endif + ifeq ($(CC_VERSION),gcc) + REQUIRED_CC_VER = 3.4.3 + endif + REQUIRED_GCC_VER = 2.95.2 +endif + +# Linux specific +ifeq ($(PLATFORM), linux) + REQUIRED_OS_VERSION = 2.6 + REQUIRED_OS_VARIANT_NAME = Fedora + REQUIRED_OS_VARIANT_VERSION = 9 + REQUIRED_FREE_SPACE = 1460000 + REQUIRED_ALSA_VERSION = 0.9.1 + REQUIRED_COMPILER_NAME = GCC4 + REQUIRED_COMPILER_VERSION = GCC4 + REQUIRED_GCC_VER = 2.95 + ifeq ($(CC_VERSION),gcc) + REQUIRED_CC_VER = 4.3.0 + endif + ifeq ($(CC_VERSION),sun) + REQUIRED_CC_VER = 5.9 + endif +endif + +# Windows specific +ifeq ($(PLATFORM), windows) + ifeq ($(ARCH_DATA_MODEL),64) + REQUIRED_OS_VERSION = 5.2 + REQUIRED_OS_VARIANT_NAME = Windows2003 + else + REQUIRED_OS_VERSION = 5.1 + REQUIRED_OS_VARIANT_NAME = WindowsXP + endif + REQUIRED_OS_VARIANT_VERSION = $(REQUIRED_OS_VERSION) + REQUIRED_CYGWIN_VER = 4.0 + REQUIRED_MKS_VER = 6.1 + REQUIRED_FREE_SPACE = 500000 + REQUIRED_DXSDK_VER = 0x0900 + ifeq ($(CC_VERSION),msvc) + ifeq ($(ARCH_DATA_MODEL), 32) + REQUIRED_COMPILER_NAME = Visual Studio 9 + REQUIRED_COMPILER_VERSION = VS2008 + REQUIRED_CC_VER = 15.00.21022.08 + REQUIRED_LINK_VER = 9.00.21022.08 + else + ifeq ($(ARCH), ia64) + REQUIRED_COMPILER_NAME = Microsoft Platform SDK - November 2001 Edition + REQUIRED_COMPILER_VERSION = VS2003 + REQUIRED_CC_VER = 13.00.9337.7 + REQUIRED_LINK_VER = 7.00.9337.7 + endif + ifeq ($(ARCH), amd64) + REQUIRED_COMPILER_NAME = Microsoft Windows SDK with Visual Studio 9 (6001.18000.367) + REQUIRED_COMPILER_VERSION = VS2008 + REQUIRED_CC_VER = 15.00.21022.08 + REQUIRED_LINK_VER = 9.00.21022.08 + endif + endif + endif + ifeq ($(CC_VERSION),gcc) + REQUIRED_CC_VER = 3.4.3 + endif +endif + +# Generic +REQUIRED_ANT_VER = 1.6.3 +REQUIRED_BOOT_VER = 1.5 +REQUIRED_FREETYPE_VERSION = 2.3.0 +REQUIRED_MAKE_VER = 3.78 +REQUIRED_UNZIP_VER = 5.12 +REQUIRED_ZIP_VER = 2.2 + diff --git a/make/common/shared/Defs-windows.gmk b/make/common/shared/Defs-windows.gmk index 1ceb017b2f958fec9c294c44ff3e363184c34346..abaa6a1807e6d5d2cd076e1e61346d3d1f6d45d1 100644 --- a/make/common/shared/Defs-windows.gmk +++ b/make/common/shared/Defs-windows.gmk @@ -136,10 +136,7 @@ endif UNIXCOMMAND_PATH:=$(call AltCheckSpaces,UNIXCOMMAND_PATH) # Get version of MKS or CYGWIN -ifdef USING_CYGWIN -_CYGWIN_VER :=$(shell $(UNAME)) -CYGWIN_VER :=$(call GetVersion,$(_CYGWIN_VER)) -else # MKS +ifndef USING_CYGWIN _MKS_VER :=$(shell $(MKSINFO) 2>&1 | $(GREP) Release | $(TAIL) -1 | $(SED) -e 's@.*\(Release.*\)@\1@') MKS_VER :=$(call GetVersion,$(_MKS_VER)) # At this point, we can re-define FullPath to use DOSNAME_CMD @@ -202,6 +199,7 @@ else endif ifeq ($(ARCH_DATA_MODEL), 32) _program_files :=$(call FullPath,$(xPROGRAMFILES)) + _program_files32 :=$(_program_files) else ifdef PROGRAMW6432 xPROGRAMW6432 :="$(subst \,/,$(PROGRAMW6432))" @@ -255,39 +253,51 @@ ifeq ($(ARCH_DATA_MODEL), 32) _vs90tools :=$(call FullPath,$(xVS90COMNTOOLS)) endif ifneq ($(_vs90tools),) - _msvc_dir :=$(_vs90tools)/../../Vc - _redist_sdk :=$(_msvc_dir)/../SDK/v3.5/Bin - endif - ifdef VS80COMNTOOLS # /Common/Tools directory, use ../../Vc - xVS80COMNTOOLS :="$(subst \,/,$(VS80COMNTOOLS))" - _vs80tools :=$(call FullPath,$(xVS80COMNTOOLS)) - endif - ifneq ($(_vs80tools),) - _msvc_dir :=$(_vs80tools)/../../Vc - _redist_sdk :=$(_msvc_dir)/../SDK/v2.0/Bin - endif - ifdef VS71COMNTOOLS # /Common/Tools directory, use ../../Vc7 - xVS71COMNTOOLS :="$(subst \,/,$(VS71COMNTOOLS))" - _vs71tools :=$(call FullPath,$(xVS71COMNTOOLS)) - endif - ifneq ($(_vs71tools),) - _msvc_dir :=$(_vs71tools)/../../Vc7 - _redist_sdk :=$(_vs71tools)/../.. + _msvc_dir :=$(_vs90tools)/../../Vc + else + ifdef VS80COMNTOOLS # /Common/Tools directory, use ../../Vc + xVS80COMNTOOLS :="$(subst \,/,$(VS80COMNTOOLS))" + _vs80tools :=$(call FullPath,$(xVS80COMNTOOLS)) + endif + ifneq ($(_vs80tools),) + _msvc_dir :=$(_vs80tools)/../../Vc + else + ifdef VS71COMNTOOLS # /Common/Tools directory, use ../../Vc7 + xVS71COMNTOOLS :="$(subst \,/,$(VS71COMNTOOLS))" + _vs71tools :=$(call FullPath,$(xVS71COMNTOOLS)) + endif + ifneq ($(_vs71tools),) + _msvc_dir :=$(_vs71tools)/../../Vc7 + endif + endif endif endif ifneq ($(_msvc_dir),) _compiler_bin :=$(_msvc_dir)/Bin - _ms_sdk :=$(_msvc_dir)/PlatformSDK + # Assume PlatformSDK is in VS71 (will be empty if VS90) + _ms_sdk :=$(call FullPath,$(_msvc_dir)/PlatformSDK) + # Assume VS90, then VS80, then VS71 + _redist_sdk :=$(call FullPath,$(_msvc_dir)/../SDK/v3.5/Bin) + ifeq ($(_redist_sdk),) + _redist_sdk :=$(call FullPath,$(_msvc_dir)/../SDK/v2.0/Bin) + ifeq ($(_redist_sdk),) + _redist_sdk :=$(call FullPath,$(_msvc_dir)/../SDK/v1.1/Bin) + endif + endif endif endif # The Microsoft Platform SDK installed by itself ifneq ($(_program_files),) - xPSDK :="$(_program_files)/Microsoft Platform SDK" - _psdk :=$(call FullPath,$(xPSDK)) + _PSDK :="$(_program_files)/Microsoft SDKs/Windows/v6.1/" + _psdk :=$(call FullPath,$(xMSSDK61)) ifeq ($(_psdk),) - xPSDK :="$(_program_files)/Microsoft SDK" - _psdk :=$(call FullPath,$(xMSSDK)) + xPSDK :="$(_program_files)/Microsoft Platform SDK" + _psdk :=$(call FullPath,$(xPSDK)) + ifeq ($(_psdk),) + xPSDK :="$(_program_files)/Microsoft SDK" + _psdk :=$(call FullPath,$(xMSSDK)) + endif endif endif @@ -308,13 +318,22 @@ endif # Compilers for 64bit are from SDK ifeq ($(ARCH_DATA_MODEL), 64) - ifneq ($(_ms_sdk),) - ifeq ($(ARCH), ia64) - _compiler_bin :=$(_ms_sdk)/Bin/Win64 - endif - ifeq ($(ARCH), amd64) - _compiler_bin :=$(_ms_sdk)/Bin/Win64/x86/$(ARCH) - _redist_sdk :=$(_ms_sdk)/redist/win64/AMD64 + xVS2008 :="$(_program_files32)/Microsoft Visual Studio 9.0/" + VS2008 :=$(call FullPath,$(xVS2008)) + ifneq ($(VS2008),) + _compiler_bin :=$(VS2008)/VC/Bin/$(ARCH) + xMSSDK61 :="$(_program_files)/Microsoft SDKs/Windows/v6.1/" + MSSDK61 :=$(call FullPath,$(xMSSDK61)) + _redist_sdk :=$(VS2008)/VC/redist/x86/Microsoft.VC90.CRT + else + ifneq ($(_ms_sdk),) + ifeq ($(ARCH), ia64) + _compiler_bin :=$(_ms_sdk)/Bin/Win64 + endif + ifeq ($(ARCH), amd64) + _compiler_bin :=$(_ms_sdk)/Bin/Win64/x86/$(ARCH) + _redist_sdk :=$(_ms_sdk)/redist/win64/AMD64 + endif endif endif endif @@ -417,70 +436,39 @@ ifndef ALT_BOOTDIR _BOOTDIR2 =$(USRJDKINSTANCES_PATH)/jdk$(PREVIOUS_JDK_VERSION) endif -# See if SDK area has a msvcrt.dll file, directory may exist w/o msvcr* files -_REDIST_SDK_EXISTS := $(shell \ - if [ -f "$(_redist_sdk)/msvcrt.dll" ]; then \ - echo "true"; \ - else \ - echo "false"; \ - fi) -_REDISTNN_SDK_EXISTS := $(shell \ - if [ -f "$(_redist_sdk)/$(MSVCRNN_DLL)" ]; then \ - echo "true"; \ - else \ - echo "false"; \ - fi) - -# 32 bit needs 2 runtimes -ifeq ($(ARCH_DATA_MODEL), 32) +# 32 bit always needs 2 runtimes, 64 bit usually does too - # MSVCRT_DLL_PATH: location of msvcrt.dll that will be re-distributed - ifdef ALT_MSVCRT_DLL_PATH - xALT_MSVCRT_DLL_PATH :="$(subst \,/,$(ALT_MSVCRT_DLL_PATH))" - MSVCRT_DLL_PATH :=$(call FullPath,$(xALT_MSVCRT_DLL_PATH)) +# MSVCRT_DLL_PATH: location of msvcrt.dll that will be re-distributed +ifdef ALT_MSVCRT_DLL_PATH + xALT_MSVCRT_DLL_PATH :="$(subst \,/,$(ALT_MSVCRT_DLL_PATH))" + MSVCRT_DLL_PATH :=$(call FullPath,$(xALT_MSVCRT_DLL_PATH)) +else + MSVCRT_DLL_PATH :=$(call FullPath,$(_system_root)/system32/) +endif +MSVCRT_DLL_PATH:=$(call AltCheckSpaces,MSVCRT_DLL_PATH) +MSVCRT_DLL_PATH:=$(call AltCheckValue,MSVCRT_DLL_PATH) + +# 32bit always needs the MSVCRNN runtime, 64bit does when using VS2008 +ifeq ($(ARCH_DATA_MODEL), 32) + _NEEDS_MSVCRNN = true +else + ifeq ($(VS2008),) + _NEEDS_MSVCRNN = false else - ifeq ($(_REDIST_SDK_EXISTS), true) - xREDIST_DIR :=$(_redist_sdk) - else - xREDIST_DIR :=$(_system_root)/system32 - endif - MSVCRT_DLL_PATH :=$(call FullPath,$(xREDIST_DIR)) + _NEEDS_MSVCRNN = true endif - MSVCRT_DLL_PATH:=$(call AltCheckSpaces,MSVCRT_DLL_PATH) - MSVCRT_DLL_PATH:=$(call AltCheckValue,MSVCRT_DLL_PATH) - +endif + +ifeq ($(_NEEDS_MSVCRNN), true) # MSVCRNN_DLL_PATH: location of msvcrnn.dll that will be re-distributed ifdef ALT_MSVCRNN_DLL_PATH xALT_MSVCRNN_DLL_PATH :="$(subst \,/,$(ALT_MSVCRNN_DLL_PATH))" MSVCRNN_DLL_PATH :=$(call FullPath,$(xALT_MSVCRNN_DLL_PATH)) else - ifeq ($(_REDISTNN_SDK_EXISTS), true) - xREDISTNN_DIR :=$(_redist_sdk) - else - xREDISTNN_DIR :=$(_system_root)/system32 - endif - MSVCRNN_DLL_PATH :=$(call FullPath,$(xREDISTNN_DIR)) + MSVCRNN_DLL_PATH :=$(_redist_sdk) endif MSVCRNN_DLL_PATH :=$(call AltCheckSpaces,MSVCRNN_DLL_PATH) MSVCRNN_DLL_PATH:=$(call AltCheckValue,MSVCRNN_DLL_PATH) - -else - - # MSVCRT_DLL_PATH: location of msvcrt.dll that will be re-distributed - ifdef ALT_MSVCRT_DLL_PATH - xALT_MSVCRT_DLL_PATH :="$(subst \,/,$(ALT_MSVCRT_DLL_PATH))" - MSVCRT_DLL_PATH :=$(call FullPath,$(xALT_MSVCRT_DLL_PATH)) - else - ifeq ($(_REDIST_SDK_EXISTS), true) - xREDIST_DIR :=$(_redist_sdk) - else - xREDIST_DIR :=$(_system_root)/SysWOW64 - endif - MSVCRT_DLL_PATH :=$(call FullPath,$(xREDIST_DIR)) - endif - MSVCRT_DLL_PATH:=$(call AltCheckSpaces,MSVCRT_DLL_PATH) - MSVCRT_DLL_PATH:=$(call AltCheckValue,MSVCRT_DLL_PATH) - endif # DXSDK_PATH: path to Microsoft DirectX SDK Include and Lib @@ -539,7 +527,7 @@ ifdef ALT_INSTALL_MSIVAL2 xALT_INSTALL_MSIVAL2 :="$(subst \,/,$(ALT_INSTALL_MSIVAL2))" INSTALL_MSIVAL2 :=$(call FullPath,$(xALT_INSTALL_MSIVAL2)) else - INSTALL_MSIVAL2 :=$(_program_files)/MsiVal2 + INSTALL_MSIVAL2 :=$(_program_files32)/MsiVal2 endif INSTALL_MSIVAL2:=$(call AltCheckSpaces,INSTALL_MSIVAL2) diff --git a/make/common/shared/Defs.gmk b/make/common/shared/Defs.gmk index 638cd36369618b8d5bb96263f57f0c77c022d354..5da4a29047e20de6af1a8777bb30b59efaad98fc 100644 --- a/make/common/shared/Defs.gmk +++ b/make/common/shared/Defs.gmk @@ -116,9 +116,9 @@ $(shell \ fi) endef -# Given a line of text, get the major.minor version number from it +# Given a line of text, get the version number from it define GetVersion -$(shell echo $1 | sed -e 's@[^1-9]*\([1-9][0-9]*\.[0-9][0-9]*\).*@\1@' ) +$(shell echo $1 | sed -e 's@[^0-9]*\([0-9][0-9]*\.[0-9][.0-9]*\).*@\1@' ) endef # Given a major.minor.micro version, return the major, minor, or micro number @@ -133,26 +133,26 @@ $(if $(word 3, $(subst ., ,$1)),$(word 3, $(subst ., ,$1)),0) endef # Macro that returns missing, same, newer, or older $1=version $2=required -# (currently does not check the micro number) define CheckVersions $(shell \ if [ "$1" = "" -o "$2" = "" ]; then \ echo missing; \ + elif [ "$1" = "$2" ]; then \ + echo same; \ + elif [ $(call MajorVersion,$1) -lt $(call MajorVersion,$2) ] ; then \ + echo older; \ + elif [ $(call MajorVersion,$1) -gt $(call MajorVersion,$2) ] ; then \ + echo newer; \ + elif [ $(call MinorVersion,$1) -lt $(call MinorVersion,$2) ]; then \ + echo older; \ + elif [ $(call MinorVersion,$1) -gt $(call MinorVersion,$2) ]; then \ + echo newer; \ + elif [ $(call MicroVersion,$1) -lt $(call MicroVersion,$2) ]; then \ + echo older; \ + elif [ $(call MicroVersion,$1) -gt $(call MicroVersion,$2) ]; then \ + echo newer; \ else \ - if [ "$1" = "$2" ]; then \ - echo same; \ - else \ - if [ $(call MajorVersion,$1) -lt $(call MajorVersion,$2) ] ; then \ - echo older; \ - else \ - if [ $(call MajorVersion,$1) -eq $(call MajorVersion,$2) -a \ - $(call MinorVersion,$1) -lt $(call MinorVersion,$2) ]; then \ - echo older; \ - else \ - echo newer; \ - fi; \ - fi; \ - fi; \ + echo same; \ fi) endef @@ -558,6 +558,24 @@ else COPYRIGHT_YEAR = $(shell $(DATE) '+%Y') endif -# Get shared compiler settings -include $(JDK_MAKE_SHARED_DIR)/Compiler.gmk +# Windows uses Microsoft compilers by default +ifeq ($(PLATFORM), windows) + override CC_VERSION = msvc +endif + +# Solaris uses Sun Studio compilers by default +ifeq ($(PLATFORM), solaris) + override CC_VERSION = sun +endif + +# Linux uses GNU compilers by default +ifeq ($(PLATFORM), linux) + override CC_VERSION = gcc +endif + +# Get the REQUIRED versions (needs CC_VERSION set) +include $(JDK_MAKE_SHARED_DIR)/Defs-versions.gmk + +# Get the compiler specific settings +include $(JDK_MAKE_SHARED_DIR)/Compiler-$(CC_VERSION).gmk diff --git a/make/common/shared/Platform.gmk b/make/common/shared/Platform.gmk index 8da23c83fc45a24db0b17d6b047d658750913012..e07de2499fbbd987b2e25377870542a100efcdc5 100644 --- a/make/common/shared/Platform.gmk +++ b/make/common/shared/Platform.gmk @@ -51,9 +51,6 @@ PLATFORM_SHARED=done # USER login name of user (minus blanks) # PLATFORM windows, solaris, or linux # VARIANT OPT or DBG, OPT is the default -# OS_NAME solaris, linux, or nt -# OS_VERSION specific version of os, 5.10, 2.4.9-e.3, etc. -# OS_VENDOR company name # TEMP_DISK /tmp or C:/temp # ARCH_DATA_MODEL 32 or 64 # ARCH sparc, sparcv9, i586, amd64, or ia64 @@ -72,29 +69,11 @@ PLATFORM_SHARED=done # ISA_DIR solaris only: /sparcv9 or /amd64 # LIBARCH32 solaris only: sparc or i386 # LIBARCH64 solaris only: sparcv9 or amd64 -# REQUIRED_WINDOWS_VERSION windows only: specific version of windows # USING_CYGWIN windows only: true or false -# WINDOWS_NT_VERSION_STRING windows only: long version name -# REQUIRED_OS_VERSION required OS version, e.g. 5.10, 2.4 -# REQUIRED_FREE_SPACE minimum disk space needed for outputdir # ISHIELD_TEMP_MIN windows only: minimum disk space in temp area -# REQUIRED_ZIP_VER required version of zip -# REQUIRED_UNZIP_VER required version of unzip -# REQUIRED_DXSDK_VER windows only: required version of DirectX -# LINUX_VERSION_INFO linux only: location of linux release file -# REQUIRED_LINUX_VER linux only: required version of linux -# REQUIRED_LINUX_FULLVER linux only: required full version of linux -# REQUIRED_ALSA_VERSION linux only: required version of ALSA -# REQUIRED_FREETYPE_VERSION openjdk only: required version of freetype SYSTEM_UNAME := $(shell uname) -# Normal boot jdk is previous release, but a hard requirement is a 1.5 boot -REQUIRED_BOOT_VER = 1.5 - -# If we are using freetype, this is the required version -REQUIRED_FREETYPE_VERSION=2.3.0 - # # Prune out all known SCM (Source Code Management) directories # so they will not be included when copying directory trees @@ -113,8 +92,6 @@ endif # Platform settings specific to Solaris ifeq ($(SYSTEM_UNAME), SunOS) PLATFORM = solaris - OS_NAME = solaris - OS_VERSION := $(shell uname -r) # Solaris sparc build can be either 32-bit or 64-bit. # Default to 32, but allow explicit setting to 32 or 64. ifndef ARCH_DATA_MODEL @@ -166,16 +143,6 @@ ifeq ($(SYSTEM_UNAME), SunOS) endif # Suffix for file bundles used in previous release BUNDLE_FILE_SUFFIX=.tar - OS_VENDOR = Sun Microsystems - # Required Solaris version - REQUIRED_OS_VERSION = 5.10 - # Minimum disk space needed as determined by running 'du -sk' on - # a fully built workspace. - ifeq ($(ARCH_FAMILY), sparc) - REQUIRED_FREE_SPACE=1300000 - else - REQUIRED_FREE_SPACE=1040000 - endif # How much RAM does this machine have: MB_OF_MEMORY=$(shell /etc/prtconf | fgrep 'Memory size:' | expand | cut -d' ' -f3) endif @@ -183,8 +150,6 @@ endif # Platform settings specific to Linux ifeq ($(SYSTEM_UNAME), Linux) PLATFORM = linux - OS_NAME = linux - OS_VERSION := $(shell uname -r) # Arch and OS name/version mach := $(shell uname -m) archExpr = case "$(mach)" in \ @@ -242,32 +207,6 @@ ifeq ($(SYSTEM_UNAME), Linux) # Suffix for file bundles used in previous release BUNDLE_FILE_SUFFIX=.tar.gz - # Minimum disk space needed as determined by running 'du -sk' on - # a fully built workspace. - REQUIRED_FREE_SPACE=1460000 - LINUX_VERSION_INFO = /etc/redhat-release - OS_VENDOR = Red Hat - ifeq ($(ARCH_DATA_MODEL), 32) - REQUIRED_LINUX_VER = Advanced Server - REQUIRED_LINUX_FULLVER = Advanced Server release 2.1AS - REQUIRED_OS_VERSION = 2.4.9-e.3 - else - ifeq ($(ARCH), amd64) - LINUX_VERSION_INFO = /etc/SuSE-release - OS_VENDOR = SuSE Enterprise - REQUIRED_LINUX_VER = 8.1 - REQUIRED_LINUX_FULLVER = $(REQUIRED_LINUX_VER) SLSE AMD64 - REQUIRED_OS_VERSION = 2.4.19-SMP - else - REQUIRED_LINUX_VER = Advanced Server - REQUIRED_LINUX_FULLVER = Advanced Server release 2.1AS 64 bit - REQUIRED_OS_VERSION = 2.4.19-SMP - endif - endif - ifneq ($(ARCH), ia64) - # ALSA 0.9.1 and above - REQUIRED_ALSA_VERSION = ^((0[.]9[.][1-9])|(1[.]0[.][0-9]))[0-9]* - endif # How much RAM does this machine have: MB_OF_MEMORY := $(shell free -m | fgrep Mem: | awk '{print $$2;}' ) endif @@ -275,34 +214,34 @@ endif # Windows with and without CYGWIN will be slightly different ifeq ($(SYSTEM_UNAME), Windows_NT) PLATFORM = windows - OS_VERSION := $(shell uname -r) - WINDOWS_NT_VERSION_STRING=Windows_NT - REQUIRED_MKS_VER=6.1 endif ifneq (,$(findstring CYGWIN,$(SYSTEM_UNAME))) PLATFORM = windows - OS_VERSION := 5 USING_CYGWIN = true export USING_CYGWIN - WINDOWS_NT_VERSION_STRING=CYGWIN_NT - REQUIRED_CYGWIN_VER=4.0 endif # Platform settings specific to Windows ifeq ($(PLATFORM), windows) - OS_NAME = nt - REQUIRED_OS_VERSION=5 # Windows builds default to the appropriate for the underlaying # architecture. # Temporary disk area TEMP_DISK=C:/temp # GNU Make or MKS overrides $(PROCESSOR_ARCHITECTURE) to always # return "x86". Use the first word of $(PROCESSOR_IDENTIFIER) instead. + PROC_ARCH:=$(word 1, $(PROCESSOR_IDENTIFIER)) + PROC_ARCH:=$(subst x86,X86,$(PROC_ARCH)) + PROC_ARCH:=$(subst Intel64,X64,$(PROC_ARCH)) + PROC_ARCH:=$(subst em64t,X64,$(PROC_ARCH)) + PROC_ARCH:=$(subst EM64T,X64,$(PROC_ARCH)) + PROC_ARCH:=$(subst amd64,X64,$(PROC_ARCH)) + PROC_ARCH:=$(subst AMD64,X64,$(PROC_ARCH)) + PROC_ARCH:=$(subst ia64,IA64,$(PROC_ARCH)) ifndef ARCH_DATA_MODEL - ifeq ($(word 1, $(PROCESSOR_IDENTIFIER)),ia64) + ifeq ($(PROC_ARCH),IA64) ARCH_DATA_MODEL=64 else - ifeq ($(word 1, $(PROCESSOR_IDENTIFIER)),AMD64) + ifeq ($(PROC_ARCH),X64) ARCH_DATA_MODEL=64 else ARCH_DATA_MODEL=32 @@ -314,18 +253,17 @@ ifeq ($(PLATFORM), windows) # If the user wants to perform a cross compile build then they must # - set ARCH_DATA_MODEL=64 and either # + set ARCH to ia64 or amd64, or - REQUIRED_WINDOWS_VERSION=Server 2003 Enterprise x64 Edition - ifeq ($(word 1, $(PROCESSOR_IDENTIFIER)), AMD64) + ifeq ($(PROC_ARCH),X64) ARCH=amd64 else - ARCH=ia64 + ifeq ($(PROC_ARCH),IA64) + ARCH=ia64 + endif endif LIBARCH=$(ARCH) # Value of Java os.arch property ARCHPROP=$(LIBARCH) else - REQUIRED_WINDOWS_VERSION=2000 or Unknown - #REQUIRED_WINDOWS_VERSION=XP Professional # LIBARCH is used to preserve the jre/lib/i386 directory name for 32-bit intel ARCH=i586 LIBARCH=i386 @@ -364,14 +302,9 @@ ifeq ($(PLATFORM), windows) ARCH_VM_SUBDIR=jre/bin # Suffix for file bundles used in previous release BUNDLE_FILE_SUFFIX=.tar - # Minimum disk space needed as determined by running 'du -sk' on - # a fully built workspace. - REQUIRED_FREE_SPACE=500000 # ISHIELD_TEMP_MIN is the difference of an empty C:\TEMP vs. one after a # bundles build on windows. ISHIELD_TEMP_MIN=250000 - REQUIRED_DXSDK_VER = 0x0900 - OS_VENDOR = Microsoft # How much RAM does this machine have: ifeq ($(JDK_HAS_MEM_INFO),) ifeq ($(USING_CYGWIN),true) @@ -410,10 +343,6 @@ ifeq ($(PLATFORM), windows) endif endif -REQUIRED_ZIP_VER = 2.2 -REQUIRED_UNZIP_VER = 5.12 -REQUIRED_MAKE_VER = 3.78 - # Unix type settings (same for all unix platforms) ifneq ($(PLATFORM), windows) # Temporary disk area diff --git a/make/common/shared/Sanity-Settings.gmk b/make/common/shared/Sanity-Settings.gmk index f3ea2b35a79f12cc7552ce8e5d87f29178fda838..b64e3b52a136a931d3230425feebadcd5fad802b 100644 --- a/make/common/shared/Sanity-Settings.gmk +++ b/make/common/shared/Sanity-Settings.gmk @@ -97,7 +97,7 @@ ifeq ($(PLATFORM),solaris) endif ifeq ($(PLATFORM),windows) ALL_SETTINGS+=$(call addAltSetting,MSVCRT_DLL_PATH) - ifeq ($(ARCH_DATA_MODEL), 32) + ifneq ($(MSVCRNN_DLL),) ALL_SETTINGS+=$(call addAltSetting,MSVCRNN_DLL_PATH) endif ALL_SETTINGS+=$(call addAltSetting,MSDEVTOOLS_PATH) @@ -167,8 +167,6 @@ ALL_SETTINGS+=$(call addRequiredSetting,ARCHPROP) ifeq ($(PLATFORM),windows) ALL_SETTINGS+=$(call addRequiredSetting,PROCESSOR_ARCHITECTURE) ALL_SETTINGS+=$(call addRequiredSetting,PROCESSOR_IDENTIFIER) - ALL_SETTINGS+=$(call addRequiredSetting,WINDOWS_VERSION) - ALL_SETTINGS+=$(call addRequiredSetting,WINDOWS_NT_VERSION_STRING) ifdef USING_CYGWIN ALL_SETTINGS+=$(call addRequiredSetting,USING_CYGWIN) ALL_SETTINGS+=$(call addRequiredVersionSetting,CYGWIN_VER) @@ -179,13 +177,11 @@ ifeq ($(PLATFORM),windows) endif endif ifeq ($(PLATFORM),linux) - ALL_SETTINGS+=$(call addRequiredSetting,LINUX_VERSION) - ifneq ($(ARCH), ia64) - ALL_SETTINGS+=$(call addRequiredSetting,ALSA_VERSION) - endif + ALL_SETTINGS+=$(call addRequiredSetting,ALSA_VERSION) endif ALL_SETTINGS+=$(call addRequiredVersionSetting,OS_VERSION) -ALL_SETTINGS+=$(call addRequiredSetting,OS_NAME) +ALL_SETTINGS+=$(call addOptionalSetting,OS_VARIANT_NAME) +ALL_SETTINGS+=$(call addOptionalSetting,OS_VARIANT_VERSION) ALL_SETTINGS+=$(call addRequiredSetting,TEMP_FREE_SPACE) ALL_SETTINGS+=$(call addRequiredSetting,FREE_SPACE) ALL_SETTINGS+=$(call addRequiredSetting,MB_OF_MEMORY) @@ -249,6 +245,7 @@ ifdef OPENJDK ALL_SETTINGS+=$(call addAltSetting,FREETYPE_HEADERS_PATH) ALL_SETTINGS+=$(call addAltSetting,FREETYPE_LIB_PATH) ALL_SETTINGS+=$(call addHeading,OPENJDK Import Binary Plug Settings) + ALL_SETTINGS+=$(call addOptionalSetting,IMPORT_BINARY_PLUGS) ALL_SETTINGS+=$(call addAltSetting,BINARY_PLUGS_JARFILE) ALL_SETTINGS+=$(call addAltSetting,BINARY_PLUGS_PATH) ALL_SETTINGS+=$(call addAltSetting,BUILD_BINARY_PLUGS_PATH) diff --git a/make/common/shared/Sanity.gmk b/make/common/shared/Sanity.gmk index 997e848904a3ce97b2fe10f0f58db1671135143b..180e52196a999ee3f366ed96723285ca6d380268 100644 --- a/make/common/shared/Sanity.gmk +++ b/make/common/shared/Sanity.gmk @@ -38,60 +38,106 @@ SANITY_FILES = $(ERROR_FILE) $(WARNING_FILE) $(MESSAGE_FILE) # How to say "The Release Engineering people use this" -THE_OFFICIAL_USES=The official $(PLATFORM) builds use +THE_OFFICIAL_USES=The official builds on $(PLATFORM) use # How to say "You are using:" YOU_ARE_USING=You appear to be using +# Error message +define SanityError +$(ECHO) "ERROR: $1\n" >> $(ERROR_FILE) +endef + +# Warning message +define SanityWarning +$(ECHO) "WARNING: $1\n" >> $(WARNING_FILE) +endef + +# Official version error message: name version required_version +define OfficialErrorMessage +$(call SanityError,\ +$(THE_OFFICIAL_USES) $1 $3. Your $1 $(if $2,undefined,$2) will not work.) +endef + +# Official version warning message: name version required_version +define OfficialWarningMessage +$(call SanityWarning,\ +$(THE_OFFICIAL_USES) $1 $3. $(YOU_ARE_USING) $1 $2.) +endef + + # Settings and rules to validate the JDK build environment. ifeq ($(PLATFORM), solaris) FREE_SPACE := $(shell $(DF) -b $(OUTPUTDIR) | $(TAIL) -1 | $(NAWK) '{print $$2;}') TEMP_FREE_SPACE := $(shell $(DF) -b $(TEMP_DISK) | $(TAIL) -1 | $(NAWK) '{print $$2;}') + # What kind of system we are using (Variations are Solaris and OpenSolaris) + OS_VERSION := $(shell uname -r) + OS_VARIANT_NAME := $(strip $(shell head -1 /etc/release | awk '{print $$1;}') ) + OS_VARIANT_VERSION := $(OS_VERSION) REQ_PATCH_LIST = $(JDK_TOPDIR)/make/PatchList.solaris ifeq ($(ARCH_FAMILY), sparc) PATCH_POSITION = $$4 else PATCH_POSITION = $$6 endif + ifndef OPENJDK + _GCC_VER :=$(shell $(GCC) -dumpversion 2>&1 ) + GCC_VER :=$(call GetVersion,"$(_GCC_VER)") + endif endif ifeq ($(PLATFORM), linux) FREE_SPACE := $(shell $(DF) --sync -kP $(OUTPUTDIR) | $(TAIL) -1 | $(NAWK) '{print $$4;}') TEMP_FREE_SPACE := $(shell $(DF) --sync -kP $(TEMP_DISK) | $(TAIL) -1 | $(NAWK) '{print $$4;}') - ifeq ($(ARCH), amd64) - LINUX_VERSION := $(shell \ - if [ -r "$(LINUX_VERSION_INFO)" ] ; then \ - $(CAT) $(LINUX_VERSION_INFO) | $(TAIL) -1 | $(NAWK) '{ print $$3; }';\ - else \ - $(ECHO) "Unknown linux"; \ - fi ) - else - LINUX_VERSION := $(shell \ - if [ -r "$(LINUX_VERSION_INFO)" ] ; then \ - $(NAWK) '{ print $$4" "$$5; }' $(LINUX_VERSION_INFO) ; \ - else \ - $(ECHO) "Unknown linux"; \ - fi ) - endif - ifneq ($(ARCH), ia64) - # dummy program that outputs ALSA's version (created in target sane-alsa-versioncheck) - ALSA_VERSION_CHECK = $(TEMPDIR)/alsaversioncheck - ALSA_VERSION = `if [ -f "$(ALSA_VERSION_CHECK)" ] ; then $(ALSA_VERSION_CHECK) ; fi` - endif + # What kind of system we are using (Variation is the Linux vendor) + OS_VERSION := $(shell uname -r) + OS_VARIANT_NAME := $(shell \ + if [ -f /etc/fedora-release ] ; then \ + echo "Fedora"; \ + elif [ -f /etc/redhat-release ] ; then \ + echo "RedHat"; \ + elif [ -f /etc/SuSE-release ] ; then \ + echo "SuSE"; \ + else \ + echo "Unknown"; \ + fi) + OS_VARIANT_VERSION := $(shell \ + if [ "$(OS_VARIANT_NAME)" = "Fedora" ] ; then \ + $(CAT) /etc/fedora-release | $(HEAD) -1 | $(NAWK) '{ print $$3; }' ; \ + fi) + ALSA_INCLUDE=/usr/include/alsa/version.h + ALSA_LIBRARY=/usr/lib/libasound.so + _ALSA_VERSION := $(shell $(EGREP) SND_LIB_VERSION_STR $(ALSA_INCLUDE) | \ + $(SED) -e 's@.*\"\(.*\)\".*@\1@' ) + ALSA_VERSION := $(call GetVersion,$(_ALSA_VERSION)) endif ifeq ($(PLATFORM), windows) FREE_SPACE := $(shell $(DF) -kP $(OUTPUTDIR) | $(TAIL) -1 | $(NAWK) '{print $$4;}') TEMP_FREE_SPACE := $(shell $(DF) -kP $(TEMP_DISK) | $(TAIL) -1 | $(NAWK) '{print $$4;}') - # Localized systeminfo has localized labels, but not localized values. - _WINDOWS_VERSION := \ - $(shell systeminfo 2> $(DEV_NULL) | grep 'Microsoft' | grep 'Windows' | \ - cut -d':' -f2) - ifeq ($(_WINDOWS_VERSION),) - _WINDOWS_VERSION := Windows 2000 or Unknown (no systeminfo utility) + # Windows 2000 is 5.0, Windows XP is 5.1, Windows 2003 is 5.2 + # Assume 5.0 (Windows 2000) if systeminfo does not help + WINDOWS_MAPPING-5.0 := Windows2000 + WINDOWS_MAPPING-5.1 := WindowsXP + WINDOWS_MAPPING-5.2 := Windows2003 + # What kind of system we are using (Variation is the common name) + _OS_VERSION := \ + $(shell systeminfo 2> $(DEV_NULL) | \ + egrep '^OS Version:' | \ + awk '{print $$3;}' ) + ifeq ($(_OS_VERSION),) + OS_VERSION = 5.0 + else + OS_VERSION = $(call MajorVersion,$(_OS_VERSION)).$(call MinorVersion,$(_OS_VERSION)) + endif + OS_VARIANT_NAME := $(WINDOWS_MAPPING-$(OS_VERSION)) + OS_VARIANT_VERSION := $(OS_VERSION) + ifdef USING_CYGWIN + # CYGWIN version + _CYGWIN_VER := $(SYSTEM_UNAME) + CYGWIN_VER :=$(call GetVersion,$(_CYGWIN_VER)) endif - WINDOWS_VERSION := $(strip $(_WINDOWS_VERSION)) DXSDK_VER := $(shell $(EGREP) DIRECT3D_VERSION $(DXSDK_INCLUDE_PATH)/d3d9.h 2>&1 | \ $(EGREP) "\#define" | $(NAWK) '{print $$3}') endif @@ -106,7 +152,6 @@ ZIP_VER :=$(call GetVersion,"$(_ZIP_VER)") UNZIP_VER :=$(call GetVersion,"$(_UNZIP_VER)") BOOT_VER :=$(call GetVersion,"$(_BOOT_VER)") -REQUIRED_ANT_VER := 1.6.3 _ANT_VER:=$(shell $(ANT) -version 2>&1 ) ANT_VER:=$(call GetVersion,"$(_ANT_VER)") @@ -167,7 +212,6 @@ include $(JDK_MAKE_SHARED_DIR)/Sanity-Settings.gmk sane-compiler \ sane-link \ sane-cacerts \ - sane-alsa-versioncheck \ sane-alsa-headers \ sane-ant_version \ sane-zip_version \ @@ -239,35 +283,29 @@ sane-arch_data_model: # generate a fatal sanity error, and a warning about the official # build platform just becomes clutter. ###################################################### -OS_CHECK :=$(call CheckVersions,$(OS_VERSION),$(REQUIRED_OS_VERSION)) +ifndef OPENJDK + OS_VERSION_CHECK := \ + $(call CheckVersions,$(OS_VERSION),$(REQUIRED_OS_VERSION)) + ifeq ($(OS_VARIANT_NAME),$(REQUIRED_OS_VARIANT_NAME)) + OS_VARIANT_VERSION_CHECK := \ + $(call CheckVersions,$(OS_VARIANT_VERSION),$(REQUIRED_OS_VARIANT_VERSION)) + endif +endif sane-os_version:: sane-arch_data_model sane-memory_check sane-locale sane-os_patch_level ifndef OPENJDK - @if [ "$(OS_CHECK)" = "missing" ]; then \ - $(ECHO) "ERROR: The $(PLATFORM) OS version is undefined (Try: uname -r). \n" \ - "" >> $(ERROR_FILE) ; \ - fi - @if [ "$(OS_CHECK)" != "same" ]; then \ - $(ECHO) "WARNING: $(THE_OFFICIAL_USES) OS version $(REQUIRED_OS_VERSION). \n" \ - " $(YOU_ARE_USING) OS version $(OS_VERSION). \n" \ - "" >> $(WARNING_FILE) ; \ - fi - ifeq ($(PLATFORM), windows) - @if [ "$(findstring $(REQUIRED_WINDOWS_VERSION),$(WINDOWS_VERSION))" = "" ]; then \ - $(ECHO) "WARNING: $(YOU_ARE_USING) an unknown version of Windows. \n" \ - " The required version is $(REQUIRED_WINDOWS_VERSION). \n" \ - " $(YOU_ARE_USING) $(WINDOWS_VERSION) \n" \ - "" >> $(WARNING_FILE) ; \ - fi - endif # windows - ifeq ($(PLATFORM), linux) - @if [ `$(ECHO) "$(LINUX_VERSION)" | $(EGREP) -c '$(REQUIRED_LINUX_VER)'` -ne 1 ]; then \ - $(ECHO) "WARNING: The build is being done on Linux $(LINUX_VERSION). \n" \ - " $(THE_OFFICIAL_USES) Linux $(REQUIRED_LINUX_VER), \n" \ - " specifically Linux $(REQUIRED_LINUX_FULLVER). \n" \ - " The version found was '$(OS_VERSION)'. \n" \ - "" >> $(WARNING_FILE) ; \ - fi - endif # linux + ifneq ($(OS_VARIANT_NAME),$(REQUIRED_OS_VARIANT_NAME)) + ifeq ($(OS_VERSION_CHECK),missing) + @$(call OfficialErrorMessage,OS version,$(OS_VERSION),$(REQUIRED_OS_VERSION)) + endif + ifneq ($(OS_VERSION_CHECK),same) + @$(call OfficialWarningMessage,OS version,$(OS_VERSION),$(REQUIRED_OS_VERSION)) + endif + @$(call OfficialWarningMessage,OS variant,$(OS_VARIANT_NAME),$(REQUIRED_OS_VARIANT_NAME)) + else + ifneq ($(OS_VARIANT_VERSION_CHECK),same) + @$(call OfficialWarningMessage,$(OS_VARIANT_NAME) version,$(OS_VARIANT_VERSION),$(REQUIRED_OS_VARIANT_VERSION)) + endif + endif endif # OPENJDK ifeq ($(PLATFORM), windows) @@ -308,16 +346,12 @@ ifeq ($(PLATFORM), windows) CYGWIN_CHECK :=$(call CheckVersions,$(CYGWIN_VER),$(REQUIRED_CYGWIN_VER)) sane-cygwin: ifdef USING_CYGWIN - @if [ "$(CYGWIN_CHECK)" = "missing" ]; then \ - $(ECHO) "ERROR: The CYGWIN version is undefined. \n" \ - " $(THE_OFFICIAL_USES) CYGWIN $(REQUIRED_CYGWIN_VER). \n" \ - "" >> $(ERROR_FILE) ; \ - fi - @if [ "$(CYGWIN_CHECK)" = "older" ]; then \ - $(ECHO) "ERROR: The build cannot be done on CYGWIN $(CYGWIN_VER). \n" \ - " Use CYGWIN $(REQUIRED_CYGWIN_VER) or higher. \n" \ - "" >> $(ERROR_FILE) ; \ - fi + ifeq ($(CYGWIN_CHECK),missing) + @$(call OfficialErrorMessage,CYGWIN version,$(CYGWIN_VER),$(REQUIRED_CYGWIN_VER)) + endif + ifeq ($(CYGWIN_CHECK),older) + @$(call OfficialWarningMessage,CYGWIN version,$(CYGWIN_VER),$(REQUIRED_CYGWIN_VER)) + endif endif endif @@ -345,16 +379,12 @@ ifeq ($(PLATFORM), windows) MKS_CHECK :=$(call CheckVersions,$(MKS_VER),$(REQUIRED_MKS_VER)) sane-mks: ifndef USING_CYGWIN - @if [ "$(MKS_CHECK)" = "missing" ]; then \ - $(ECHO) "ERROR: The MKS version is undefined. \n" \ - " $(THE_OFFICIAL_USES) MKS $(REQUIRED_MKS_VER). \n" \ - "" >> $(ERROR_FILE) ; \ - fi - @if [ "$(MKS_CHECK)" = "older" ]; then \ - $(ECHO) "ERROR: The build cannot be done on MKS $(MKS_VER). \n" \ - " Use MKS $(REQUIRED_MKS_VER) or higher. \n" \ - "" >> $(ERROR_FILE) ; \ - fi + ifeq ($(MKS_CHECK),missing) + @$(call OfficialErrorMessage,MKS version,$(MKS_VER),$(REQUIRED_MKS_VER)) + endif + ifeq ($(MKS_CHECK),older) + @$(call OfficialErrorMessage,MKS version,$(MKS_VER),$(REQUIRED_MKS_VER)) + endif endif endif @@ -472,13 +502,15 @@ endif ###################################################### ifdef OPENJDK sane-binary-plugs: + ifeq ($(IMPORT_BINARY_PLUGS),true) @if [ ! -d "$(BINARY_PLUGS_PATH)" ]; then \ - $(ECHO) "ERROR: Can't locate pre-built libraries. \n" \ + $(ECHO) "WARNING: Can't locate pre-built libraries. \n" \ " Please check your access to \n" \ " $(BINARY_PLUGS_PATH) \n" \ " and/or check your value of ALT_BINARY_PLUGS_PATH. \n" \ - "" >> $(ERROR_FILE); \ + "" >> $(WARNING_FILE); \ fi + endif endif ###################################################### @@ -834,7 +866,7 @@ ifeq ($(PLATFORM), windows) " and/or check your value of ALT_MSVCRT_DLL_PATH. \n" \ "" >> $(ERROR_FILE) ; \ fi - ifeq ($(ARCH_DATA_MODEL), 32) + ifneq ($(MSVCRNN_DLL),) @if [ ! -r "$(MSVCRNN_DLL_PATH)/$(MSVCRNN_DLL)" ]; then \ $(ECHO) "ERROR: You do not have access to $(MSVCRNN_DLL). \n" \ " Please check your access to \n" \ @@ -1284,8 +1316,8 @@ ifdef LINK_VER fi @if [ "$(LINK_CHECK)" != "same" ]; then \ $(ECHO) "WARNING: To build Java 2 SDK $(JDK_VERSION) you need : \n" \ - " $(COMPILER_VERSION) - link.exe version \"$(REQUIRED_LINK_VER)\" \n" \ - " Specifically the $(COMPILER_NAME) link.exe. \n " \ + " $(REQUIRED_COMPILER_VERSION) - link.exe version \"$(REQUIRED_LINK_VER)\" \n" \ + " Specifically the $(REQUIRED_COMPILER_NAME) link.exe. \n " \ " $(YOU_ARE_USING) Linker version \"$(LINK_VER)\" \n" \ "" >> $(WARNING_FILE) ; \ fi @@ -1295,11 +1327,6 @@ endif # Check the compiler version(s) ###################################################### CC_CHECK :=$(call CheckVersions,$(CC_VER),$(REQUIRED_CC_VER)) -ifeq ($(PLATFORM), solaris) - ifeq ($(ARCH_DATA_MODEL), 32) - GCC_CHECK :=$(call CheckVersions,$(GCC_VER),$(REQUIRED_GCC_VER)) - endif -endif sane-compiler: sane-link @if [ "$(CC_CHECK)" = "missing" ]; then \ $(ECHO) "ERROR: The Compiler version is undefined. \n" \ @@ -1307,69 +1334,36 @@ sane-compiler: sane-link fi ifndef OPENJDK @if [ "$(CC_CHECK)" != "same" ]; then \ - $(ECHO) "WARNING: The $(PLATFORM) compiler is not version $(COMPILER_VERSION) $(REQUIRED_CC_VER) \n" \ - " Specifically the $(COMPILER_NAME) compiler. \n " \ - " $(YOU_ARE_USING) compiler version: $(CC_VER) \n" \ + $(ECHO) "WARNING: The $(PLATFORM) compiler is not version $(REQUIRED_COMPILER_VERSION) $(REQUIRED_CC_VER) \n" \ + " Specifically the $(REQUIRED_COMPILER_NAME) compiler. \n " \ + " $(YOU_ARE_USING) $(COMPILER_VERSION): $(CC_VER) \n" \ " The compiler was obtained from the following location: \n" \ " $(COMPILER_PATH) \n" \ "" >> $(WARNING_FILE) ; \ fi - ifdef GCC_CHECK - @if [ "$(GCC_CHECK)" != "same" ]; then \ - $(ECHO) "WARNING: The $(PLATFORM) GCC compiler must be version $(REQUIRED_GCC_VER) \n" \ - " $(YOU_ARE_USING) compiler version: $(GCC_VER) \n" \ - " The compiler was obtained from the following location: \n" \ - " $(GCC_COMPILER_PATH) \n" \ - " Please change your compiler. \n" \ - "" >> $(WARNING_FILE) ; \ - fi - endif - ifeq ($(PLATFORM), windows) - ifeq ($(ARCH_DATA_MODEL), 64) - ifneq ($(COMPILER_VERSION), VS2005) - @$(ECHO) "WARNING: Should be using VS2005 compiler on 64bit platform. \n" \ - "" >> $(WARNING_FILE) - endif - endif - endif endif ###################################################### # Check that ALSA headers and libs are installed and # that the header has the right version. We only -# need /usr/include/alsa/*.h and /usr/lib/libasound.so +# need /usr/include/alsa/version.h and /usr/lib/libasound.so ###################################################### -ifdef ALSA_VERSION_CHECK -$(ALSA_VERSION_CHECK): $(ALSA_VERSION_CHECK).c - @$(prep-target) - @$(CC) -lasound -o $@ $< - -$(ALSA_VERSION_CHECK).c: - @$(prep-target) - @$(ECHO) "#include \n" \ - "#include \n" \ - "int main(int argc, char** argv) {\n" \ - " printf(\"%s\", SND_LIB_VERSION_STR);\n" \ - " return 0;\n" \ - "}\n" \ - > $@ +ifdef REQUIRED_ALSA_VERSION + ALSA_CHECK := $(call CheckVersions,$(ALSA_VERSION),$(REQUIRED_ALSA_VERSION)) endif - -sane-alsa-versioncheck: $(ALSA_VERSION_CHECK) -sane-alsa-headers: sane-alsa-versioncheck -ifdef ALSA_VERSION_CHECK - @if [ -f "$(ALSA_VERSION_CHECK)" ]; then \ - if [ `$(ALSA_VERSION_CHECK) | $(EGREP) -c '$(REQUIRED_ALSA_VERSION)'` -ne 1 ] ; then \ - $(ECHO) "ERROR: The ALSA version must be 0.9.1 or higher. \n" \ - " You have the following ALSA version installed: $(ALSA_VERSION) \n" \ +sane-alsa-headers: +ifdef REQUIRED_ALSA_VERSION + if [ "$(ALSA_CHECK)" != "same" -a "$(ALSA_CHECK)" != "newer" ] ; then \ + $(ECHO) "ERROR: The ALSA version must be $(REQUIRED_ALSA_VERSION) or higher. \n" \ + " You have the following ALSA version installed: $${alsa_version) \n" \ " Please reinstall ALSA (drivers and lib). You can download \n" \ " the source distribution from http://www.alsa-project.org \n" \ " or go to http://www.freshrpms.net/docs/alsa/ for precompiled RPM packages. \n" \ "" >> $(ERROR_FILE) ; \ fi \ else \ - $(ECHO) "ERROR: You seem to not have installed ALSA 0.9.1 or higher. \n" \ + $(ECHO) "ERROR: You seem to not have installed ALSA $(REQUIRED_ALSA_VERSION) or higher. \n" \ " Please install ALSA (drivers and lib). You can download the \n" \ " source distribution from http://www.alsa-project.org or go to \n" \ " http://www.freshrpms.net/docs/alsa/ for precompiled RPM packages. \n" \ @@ -1384,7 +1378,7 @@ $(SANITY_FILES): ###################################################### # dump out the variable settings... ###################################################### -sane-settings:: sane-alsa-versioncheck +sane-settings:: @$(ECHO) >> $(MESSAGE_FILE) @$(ECHO) $(ALL_SETTINGS) >> $(MESSAGE_FILE) @$(ECHO) >> $(MESSAGE_FILE) @@ -1453,8 +1447,8 @@ sane-gcc-compiler: ifeq ($(PLATFORM), solaris) ifndef OPENJDK @if [ -r $(GCC_COMPILER_PATH) ]; then \ - if [ ! "$(GCC_VER)" = 2.95.2 ]; then \ - $(ECHO) "ERROR: The Solaris GCC compiler version must be 2.95.2. \n" \ + if [ ! "$(GCC_VER)" = $(REQUIRED_GCC_VERSION) ]; then \ + $(ECHO) "ERROR: The Solaris GCC compiler version must be $(REQUIRED_GCC_VERSION). \n" \ " You are using the following compiler version: $(GCC_VER) \n" \ " The compiler was obtained from the following location: \n" \ " $(GCC_COMPILER_PATH) \n" \ diff --git a/make/docs/CORE_PKGS.gmk b/make/docs/CORE_PKGS.gmk index 4a41a2005bf6b361f6c223ae355cb07e085a36c2..f9b9ee59cc1c6738106fb9979489727acff849bf 100644 --- a/make/docs/CORE_PKGS.gmk +++ b/make/docs/CORE_PKGS.gmk @@ -1,5 +1,5 @@ # -# Copyright 2001-2008 Sun Microsystems, Inc. All Rights Reserved. +# Copyright 2001-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 @@ -110,6 +110,9 @@ CORE_PKGS = \ java.nio.channels.spi \ java.nio.charset \ java.nio.charset.spi \ + java.nio.file \ + java.nio.file.attribute \ + java.nio.file.spi \ java.rmi \ java.rmi.activation \ java.rmi.dgc \ diff --git a/make/docs/Makefile b/make/docs/Makefile index 07fe50e64167bb6ddb5c5ff2856d30e9cf41bde2..301acde0826ad5fe0192489b686fa56b94ff89c2 100644 --- a/make/docs/Makefile +++ b/make/docs/Makefile @@ -1,5 +1,5 @@ # -# Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved. +# Copyright 1997-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 @@ -45,6 +45,7 @@ endif DOCSTMPDIR = $(TEMPDIR)/doctmp COMMON_JAVADOCFLAGS = \ + $(NO_PROPRIETARY_API_WARNINGS) \ -source 1.5 \ -quiet \ -use \ @@ -203,6 +204,9 @@ JDI_DOCTITLE = "Java$(TRADEMARK) Debug Interface" JDI_HEADER = "Java Debug Interface" # JDI_PKGS is located in NON_CORE_PKGS.gmk +# Variables used by security components +SECURITYAPI_JAVADOCBOTTOM = 'Report a bug or request a feature.
Copyright $(THIS_YEAR) Sun Microsystems, Inc. All Rights Reserved. Use is subject to license terms.
' + # # Variables used by JAAS target # @@ -220,6 +224,7 @@ JAAS_JAVADOCFLAGS = $(COMMON_JAVADOCFLAGS) \ -windowtitle $(JAAS_WINDOWTITLE) \ -doctitle $(JAAS_DOCTITLE) \ -header $(JAAS_JAVADOCHEADER) \ + -bottom $(SECURITYAPI_JAVADOCBOTTOM) \ -linkoffline ../../../../../api $(DOCSDIR)/api/ \ -overview $(TOPDIR)/src/share/classes/com/sun/security/auth/jaas-overview.html JAAS_WINDOWTITLE = "Java Authentication and Authorization Service " @@ -242,6 +247,7 @@ JGSS_JAVADOCFLAGS = $(COMMON_JAVADOCFLAGS) \ -windowtitle $(JGSS_WINDOWTITLE) \ -doctitle $(JGSS_DOCTITLE) \ -header $(JGSS_JAVADOCHEADER) \ + -bottom $(SECURITYAPI_JAVADOCBOTTOM) \ -linkoffline ../../../../../api $(DOCSDIR)/api/ \ -overview $(JGSS_SOURCEPATH)/com/sun/security/jgss/jgss-overview.html @@ -265,6 +271,7 @@ SMARTCARDIO_JAVADOCFLAGS = $(COMMON_JAVADOCFLAGS) \ -windowtitle $(SMARTCARDIO_WINDOWTITLE) \ -doctitle $(SMARTCARDIO_DOCTITLE) \ -header $(SMARTCARDIO_JAVADOCHEADER) \ + -bottom $(SECURITYAPI_JAVADOCBOTTOM) \ -linkoffline ../../../../../api $(DOCSDIR)/api/ SMARTCARDIO_WINDOWTITLE = "Java Smart Card I/O" diff --git a/make/docs/NON_CORE_PKGS.gmk b/make/docs/NON_CORE_PKGS.gmk index ccf7a0f79a874d8ba69edb8954b96537200d74a2..6028a85da34e47121702f290a147570ca2075e5f 100644 --- a/make/docs/NON_CORE_PKGS.gmk +++ b/make/docs/NON_CORE_PKGS.gmk @@ -1,5 +1,5 @@ # -# Copyright 2002-2008 Sun Microsystems, Inc. All Rights Reserved. +# Copyright 2002-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 @@ -65,6 +65,8 @@ OLD_JSSE_PKGS = com.sun.net.ssl HTTPSERVER_PKGS = com.sun.net.httpserver \ com.sun.net.httpserver.spi +NIO_PKGS = com.sun.nio.file + DOCLETAPI_PKGS = com.sun.javadoc TAGLETAPI_FILE = com/sun/tools/doclets/Taglet.java @@ -92,6 +94,7 @@ NON_CORE_PKGS = $(DOMAPI_PKGS) \ $(MGMT_PKGS) \ $(JAAS_PKGS) \ $(JGSS_PKGS) \ + $(NIO_PKGS) \ $(OLD_JSSE_PKGS) \ $(HTTPSERVER_PKGS) \ $(SMARTCARDIO_PKGS) \ diff --git a/make/java/fdlibm/Makefile b/make/java/fdlibm/Makefile index eeb5e744f4146b6d370963b3791060a948460d09..739eaf4403fd701cd74f8d351ee1f129c9edfb63 100644 --- a/make/java/fdlibm/Makefile +++ b/make/java/fdlibm/Makefile @@ -45,6 +45,7 @@ FDLIBM_SRC = $(SHARE_SRC)/native/java/lang/fdlibm ifeq ($(PLATFORM),windows) # Turn all optimizations off OPTIMIZATION_LEVEL = NONE + FASTDEBUG_OPTIMIZATION_LEVEL = NONE OTHER_CFLAGS = CPPFLAGS_DBG += -DLOGGING endif @@ -56,6 +57,7 @@ endif ifeq ($(PLATFORM),linux) # Turn all optimizations off OPTIMIZATION_LEVEL = NONE + FASTDEBUG_OPTIMIZATION_LEVEL = NONE endif # diff --git a/make/java/java/FILES_java.gmk b/make/java/java/FILES_java.gmk index 3117af8461f4a9560e1c28c251d6c4225924a8fa..83f3af7d96815c898f58a97b0386e74ee6916853 100644 --- a/make/java/java/FILES_java.gmk +++ b/make/java/java/FILES_java.gmk @@ -449,7 +449,6 @@ JAVA_JAVA_java = \ sun/misc/Service.java \ sun/misc/JavaLangAccess.java \ sun/misc/JavaIOAccess.java \ - sun/misc/JavaIODeleteOnExitAccess.java \ sun/misc/JavaIOFileDescriptorAccess.java \ sun/misc/JavaNioAccess.java diff --git a/make/java/java/mapfile-vers b/make/java/java/mapfile-vers index 77a78301af721f9aca72358a1b4ae554bbf2bc49..a9231b4d648a4e63a92b0fae070a2d26d4467c10 100644 --- a/make/java/java/mapfile-vers +++ b/make/java/java/mapfile-vers @@ -1,5 +1,5 @@ # -# Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved. +# Copyright 1997-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 @@ -135,7 +135,8 @@ SUNWprivate_1.1 { Java_java_lang_ClassLoader_00024NativeLibrary_find; Java_java_lang_ClassLoader_00024NativeLibrary_load; Java_java_lang_ClassLoader_00024NativeLibrary_unload; - Java_java_lang_ClassLoader_registerNatives; + Java_java_lang_ClassLoader_getCaller; + Java_java_lang_ClassLoader_registerNatives; Java_java_lang_Compiler_registerNatives; Java_java_lang_Double_longBitsToDouble; Java_java_lang_Double_doubleToRawLongBits; diff --git a/make/java/management/Makefile b/make/java/management/Makefile index 466d2212afe0433258405ab6bde534a2f80ccabe..f579e10c105afe770511d684f0785ba54ccdf920 100644 --- a/make/java/management/Makefile +++ b/make/java/management/Makefile @@ -46,6 +46,8 @@ include $(BUILDDIR)/common/Mapfile-vers.gmk # include FILES_c.gmk +# We don't need snmp here. +AUTO_JAVA_PRUNE = snmp AUTO_FILES_JAVA_DIRS = java/lang/management com/sun/management sun/management include Exportedfiles.gmk diff --git a/make/java/net/FILES_c.gmk b/make/java/net/FILES_c.gmk index 2eb4daa2cbb689344b059c77dba87dbba965266c..0e638816d1046fe39d3b06af5e9a60d70f7a9a71 100644 --- a/make/java/net/FILES_c.gmk +++ b/make/java/net/FILES_c.gmk @@ -39,6 +39,10 @@ FILES_c = \ ResolverConfigurationImpl.c \ DefaultProxySelector.c +ifeq ($(PLATFORM), solaris) + FILES_c += SdpProvider.c +endif + ifeq ($(PLATFORM), linux) FILES_c += linux_close.c endif diff --git a/make/java/net/Makefile b/make/java/net/Makefile index b9a3defdb8ccae2429ade7227b77a2816bf6ac2f..203b059a3888e9514395af9d135f6a34fe401e63 100644 --- a/make/java/net/Makefile +++ b/make/java/net/Makefile @@ -108,11 +108,24 @@ CLASSES.export += java.lang.Integer java.io.FileDescriptor java.net.InetAddressI # LOCALE_SET_DEFINITION = jre -properties: $(LIBDIR) $(LIBDIR)/net.properties +MISC_FILES = $(LIBDIR) $(LIBDIR)/net.properties $(LIBDIR)/net.properties: $(SHARE_SRC)/lib/net.properties @$(RM) $@ $(CP) $< $@ -build: properties +# +# SDP configuration template +# +ifeq ($(PLATFORM), solaris) +SDP_PATH = sdp/sdp.conf.template +SDP_CONF = $(LIBDIR)/$(SDP_PATH) +$(SDP_CONF): $(PLATFORM_SRC)/lib/$(SDP_PATH) + @$(RM) $* + $(install-file) + +MISC_FILES += $(SDP_CONF) +endif + +build: $(MISC_FILES) diff --git a/make/java/net/mapfile-vers b/make/java/net/mapfile-vers index d9803f8f9446c5d5d891aeffaafb43e0c3b1f558..c30803cbfefb9806840a7d5a79ba6039e5588d80 100644 --- a/make/java/net/mapfile-vers +++ b/make/java/net/mapfile-vers @@ -90,6 +90,7 @@ SUNWprivate_1.1 { Java_sun_net_dns_ResolverConfigurationImpl_fallbackDomain0; Java_sun_net_spi_DefaultProxySelector_init; Java_sun_net_spi_DefaultProxySelector_getSystemProxy; + Java_sun_net_spi_SdpProvider_convert; NET_AllocSockaddr; NET_SockaddrToInetAddress; NET_SockaddrEqualsInetAddress; diff --git a/make/java/nio/Exportedfiles.gmk b/make/java/nio/Exportedfiles.gmk index 49c4e24ac3f002250b962a562bed64cb0d0854a4..fd8b73f64b91d32a0a3d79bbd246c10e8727b122 100644 --- a/make/java/nio/Exportedfiles.gmk +++ b/make/java/nio/Exportedfiles.gmk @@ -1,5 +1,5 @@ # -# Copyright 2000-2005 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. # # This code is free software; you can redistribute it and/or modify it @@ -33,7 +33,7 @@ FILES_export = \ sun/nio/ch/DatagramChannelImpl.java \ sun/nio/ch/DatagramDispatcher.java \ sun/nio/ch/FileChannelImpl.java \ - sun/nio/ch/FileDispatcher.java \ + sun/nio/ch/FileDispatcherImpl.java \ sun/nio/ch/FileKey.java \ sun/nio/ch/FileLockImpl.java \ sun/nio/ch/IOStatus.java \ diff --git a/make/java/nio/FILES_c.gmk b/make/java/nio/FILES_c.gmk index 6f7c3ff3f747a0b1ed5464ffef9c94febd808e58..b1670c20dfe42b2144239759c466305149d3c6fb 100644 --- a/make/java/nio/FILES_c.gmk +++ b/make/java/nio/FILES_c.gmk @@ -1,5 +1,5 @@ # -# Copyright 2000-2005 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. # # This code is free software; you can redistribute it and/or modify it @@ -27,7 +27,7 @@ FILES_c = \ DatagramChannelImpl.c \ DatagramDispatcher.c \ FileChannelImpl.c \ - FileDispatcher.c \ + FileDispatcherImpl.c \ FileKey.c \ IOUtil.c \ MappedByteBuffer.c \ diff --git a/make/java/nio/FILES_java.gmk b/make/java/nio/FILES_java.gmk index 29f1f8f42c45ddfd8505522281577b1063fe999b..637b8dc4f96c39f5d84334f3c1d288f1b7b3f11d 100644 --- a/make/java/nio/FILES_java.gmk +++ b/make/java/nio/FILES_java.gmk @@ -1,5 +1,5 @@ # -# Copyright 2000-2008 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. # # This code is free software; you can redistribute it and/or modify it @@ -31,19 +31,29 @@ FILES_src = \ java/nio/MappedByteBuffer.java \ java/nio/StringCharBuffer.java \ \ + java/nio/channels/AsynchronousByteChannel.java \ + java/nio/channels/AsynchronousChannel.java \ + java/nio/channels/AsynchronousChannelGroup.java \ + java/nio/channels/AsynchronousDatagramChannel.java \ + java/nio/channels/AsynchronousFileChannel.java \ + java/nio/channels/AsynchronousServerSocketChannel.java \ + java/nio/channels/AsynchronousSocketChannel.java \ java/nio/channels/ByteChannel.java \ java/nio/channels/Channel.java \ java/nio/channels/Channels.java \ + java/nio/channels/CompletionHandler.java \ java/nio/channels/DatagramChannel.java \ java/nio/channels/FileChannel.java \ java/nio/channels/FileLock.java \ java/nio/channels/GatheringByteChannel.java \ java/nio/channels/InterruptibleChannel.java \ + java/nio/channels/Pipe.java \ java/nio/channels/MembershipKey.java \ java/nio/channels/MulticastChannel.java \ java/nio/channels/NetworkChannel.java \ java/nio/channels/ReadableByteChannel.java \ java/nio/channels/ScatteringByteChannel.java \ + java/nio/channels/SeekableByteChannel.java \ java/nio/channels/SelectableChannel.java \ java/nio/channels/Selector.java \ java/nio/channels/SelectionKey.java \ @@ -55,6 +65,7 @@ FILES_src = \ java/nio/channels/spi/AbstractSelectableChannel.java \ java/nio/channels/spi/AbstractSelectionKey.java \ java/nio/channels/spi/AbstractSelector.java \ + java/nio/channels/spi/AsynchronousChannelProvider.java \ java/nio/channels/spi/SelectorProvider.java \ \ java/nio/charset/Charset.java \ @@ -66,21 +77,117 @@ FILES_src = \ \ java/nio/charset/spi/CharsetProvider.java \ \ + java/nio/file/AccessDeniedException.java \ + java/nio/file/AccessMode.java \ + java/nio/file/AtomicMoveNotSupportedException.java \ + java/nio/file/ClosedDirectoryStreamException.java \ + java/nio/file/ClosedFileSystemException.java \ + java/nio/file/ClosedWatchServiceException.java \ + java/nio/file/CopyOption.java \ + java/nio/file/DirectoryNotEmptyException.java \ + java/nio/file/DirectoryStream.java \ + java/nio/file/DirectoryStreamFilters.java \ + java/nio/file/FileAction.java \ + java/nio/file/FileAlreadyExistsException.java \ + java/nio/file/FileRef.java \ + java/nio/file/FileStore.java \ + java/nio/file/FileSystem.java \ + java/nio/file/FileSystemAlreadyExistsException.java \ + java/nio/file/FileSystemException.java \ + java/nio/file/FileSystemNotFoundException.java \ + java/nio/file/FileSystems.java \ + java/nio/file/FileTreeWalker.java \ + java/nio/file/FileVisitOption.java \ + java/nio/file/FileVisitResult.java \ + java/nio/file/FileVisitor.java \ + java/nio/file/Files.java \ + java/nio/file/InvalidPathException.java \ + java/nio/file/LinkOption.java \ + java/nio/file/LinkPermission.java \ + java/nio/file/NoSuchFileException.java \ + java/nio/file/NotDirectoryException.java \ + java/nio/file/NotLinkException.java \ + java/nio/file/OpenOption.java \ + java/nio/file/Path.java \ + java/nio/file/PathMatcher.java \ + java/nio/file/Paths.java \ + java/nio/file/ProviderMismatchException.java \ + java/nio/file/ProviderNotFoundException.java \ + java/nio/file/ReadOnlyFileSystemException.java \ + java/nio/file/SecureDirectoryStream.java \ + java/nio/file/SimpleFileVisitor.java \ + java/nio/file/StandardCopyOption.java \ + java/nio/file/StandardOpenOption.java \ + java/nio/file/StandardWatchEventKind.java \ + java/nio/file/WatchEvent.java \ + java/nio/file/WatchKey.java \ + java/nio/file/WatchService.java \ + java/nio/file/Watchable.java \ + \ + java/nio/file/attribute/AclEntry.java \ + java/nio/file/attribute/AclEntryFlag.java \ + java/nio/file/attribute/AclEntryPermission.java \ + java/nio/file/attribute/AclEntryType.java \ + java/nio/file/attribute/AclFileAttributeView.java \ + java/nio/file/attribute/AttributeView.java \ + java/nio/file/attribute/Attributes.java \ + java/nio/file/attribute/BasicFileAttributeView.java \ + java/nio/file/attribute/BasicFileAttributes.java \ + java/nio/file/attribute/DosFileAttributeView.java \ + java/nio/file/attribute/DosFileAttributes.java \ + java/nio/file/attribute/FileAttribute.java \ + java/nio/file/attribute/FileAttributeView.java \ + java/nio/file/attribute/FileOwnerAttributeView.java \ + java/nio/file/attribute/FileStoreAttributeView.java \ + java/nio/file/attribute/FileStoreSpaceAttributeView.java \ + java/nio/file/attribute/FileStoreSpaceAttributes.java \ + java/nio/file/attribute/GroupPrincipal.java \ + java/nio/file/attribute/UserDefinedFileAttributeView.java \ + java/nio/file/attribute/PosixFileAttributeView.java \ + java/nio/file/attribute/PosixFileAttributes.java \ + java/nio/file/attribute/PosixFilePermission.java \ + java/nio/file/attribute/PosixFilePermissions.java \ + java/nio/file/attribute/UserPrincipal.java \ + java/nio/file/attribute/UserPrincipalLookupService.java \ + java/nio/file/attribute/UserPrincipalNotFoundException.java \ + \ + java/nio/file/spi/AbstractPath.java \ + java/nio/file/spi/FileSystemProvider.java \ + java/nio/file/spi/FileTypeDetector.java \ + \ + com/sun/nio/file/ExtendedCopyOption.java \ + com/sun/nio/file/ExtendedOpenOption.java \ + com/sun/nio/file/ExtendedWatchEventModifier.java \ + com/sun/nio/file/SensitivityWatchEventModifier.java \ + \ sun/nio/ByteBuffered.java \ \ + sun/nio/ch/AbstractFuture.java \ sun/nio/ch/AbstractPollArrayWrapper.java \ sun/nio/ch/AllocatedNativeObject.java \ + sun/nio/ch/AsynchronousChannelGroupImpl.java \ + sun/nio/ch/AsynchronousFileChannelImpl.java \ + sun/nio/ch/AsynchronousServerSocketChannelImpl.java \ + sun/nio/ch/AsynchronousSocketChannelImpl.java \ + sun/nio/ch/Cancellable.java \ sun/nio/ch/ChannelInputStream.java \ + sun/nio/ch/CompletedFuture.java \ sun/nio/ch/DatagramChannelImpl.java \ sun/nio/ch/DatagramDispatcher.java \ sun/nio/ch/DatagramSocketAdaptor.java \ + sun/nio/ch/DefaultAsynchronousChannelProvider.java \ sun/nio/ch/DefaultSelectorProvider.java \ sun/nio/ch/DirectBuffer.java \ sun/nio/ch/ExtendedSocketOption.java \ sun/nio/ch/FileChannelImpl.java \ sun/nio/ch/FileDispatcher.java \ + sun/nio/ch/FileDispatcherImpl.java \ sun/nio/ch/FileKey.java \ + sun/nio/ch/FileLockImpl.java \ + sun/nio/ch/FileLockTable.java \ + sun/nio/ch/Groupable.java \ sun/nio/ch/Interruptible.java \ + sun/nio/ch/Invoker.java \ sun/nio/ch/IOUtil.java \ sun/nio/ch/IOStatus.java \ sun/nio/ch/IOVecWrapper.java \ @@ -92,6 +199,7 @@ FILES_src = \ sun/nio/ch/NativeThreadSet.java \ sun/nio/ch/Net.java \ sun/nio/ch/OptionKey.java \ + sun/nio/ch/PendingFuture.java \ sun/nio/ch/PipeImpl.java \ sun/nio/ch/PollArrayWrapper.java \ sun/nio/ch/Reflect.java \ @@ -101,15 +209,19 @@ FILES_src = \ sun/nio/ch/SelChImpl.java \ sun/nio/ch/ServerSocketAdaptor.java \ sun/nio/ch/ServerSocketChannelImpl.java \ + sun/nio/ch/SimpleAsynchronousDatagramChannelImpl.java \ sun/nio/ch/SinkChannelImpl.java \ sun/nio/ch/SocketAdaptor.java \ sun/nio/ch/SocketChannelImpl.java \ sun/nio/ch/SocketDispatcher.java \ sun/nio/ch/SocketOptionRegistry.java \ sun/nio/ch/SourceChannelImpl.java \ + sun/nio/ch/ThreadPool.java \ sun/nio/ch/Util.java \ \ sun/nio/cs/AbstractCharsetProvider.java \ + sun/nio/cs/ArrayDecoder.java \ + sun/nio/cs/ArrayEncoder.java \ sun/nio/cs/FastCharsetProvider.java \ sun/nio/cs/HistoricallyNamedCharset.java \ sun/nio/cs/ISO_8859_1.java \ @@ -134,6 +246,25 @@ FILES_src = \ sun/nio/cs/UTF_32LE_BOM.java \ sun/nio/cs/UTF_32Coder.java \ \ + sun/nio/fs/AbstractAclFileAttributeView.java \ + sun/nio/fs/AbstractBasicFileAttributeView.java \ + sun/nio/fs/AbstractFileStoreSpaceAttributeView.java \ + sun/nio/fs/AbstractFileTypeDetector.java \ + sun/nio/fs/AbstractPoller.java \ + sun/nio/fs/AbstractUserDefinedFileAttributeView.java \ + sun/nio/fs/AbstractWatchKey.java \ + sun/nio/fs/AbstractWatchService.java \ + sun/nio/fs/BasicFileAttributesHolder.java \ + sun/nio/fs/Cancellable.java \ + sun/nio/fs/DefaultFileSystemProvider.java \ + sun/nio/fs/DefaultFileTypeDetector.java \ + sun/nio/fs/FileOwnerAttributeViewImpl.java \ + sun/nio/fs/Globs.java \ + sun/nio/fs/MimeType.java \ + sun/nio/fs/NativeBuffer.java \ + sun/nio/fs/NativeBuffers.java \ + sun/nio/fs/Reflect.java \ + \ java/net/DatagramSocket.java \ java/net/DatagramSocketImpl.java \ java/net/PlainSocketImpl.java \ @@ -244,24 +375,31 @@ FILES_gen_ex = \ java/nio/InvalidMarkException.java \ java/nio/ReadOnlyBufferException.java \ \ + java/nio/channels/AcceptPendingException.java \ java/nio/channels/AlreadyBoundException.java \ java/nio/channels/AlreadyConnectedException.java \ java/nio/channels/AsynchronousCloseException.java \ + java/nio/channels/CancelledKeyException.java \ java/nio/channels/ClosedByInterruptException.java \ java/nio/channels/ClosedChannelException.java \ java/nio/channels/ClosedSelectorException.java \ java/nio/channels/ConnectionPendingException.java \ java/nio/channels/FileLockInterruptionException.java \ java/nio/channels/IllegalBlockingModeException.java \ + java/nio/channels/IllegalChannelGroupException.java \ java/nio/channels/IllegalSelectorException.java \ + java/nio/channels/InterruptedByTimeoutException.java \ java/nio/channels/NoConnectionPendingException.java \ java/nio/channels/NonReadableChannelException.java \ java/nio/channels/NonWritableChannelException.java \ java/nio/channels/NotYetBoundException.java \ java/nio/channels/NotYetConnectedException.java \ java/nio/channels/OverlappingFileLockException.java \ + java/nio/channels/ReadPendingException.java \ + java/nio/channels/ShutdownChannelGroupException.java \ java/nio/channels/UnresolvedAddressException.java \ java/nio/channels/UnsupportedAddressTypeException.java \ + java/nio/channels/WritePendingException.java \ \ java/nio/charset/CharacterCodingException.java \ java/nio/charset/IllegalCharsetNameException.java \ diff --git a/make/java/nio/Makefile b/make/java/nio/Makefile index bf7bc2e02365cca74ee5228eebdfc05abff6ddb1..f85cc69e525057dce355c15fcdf4c9c8012f2056 100644 --- a/make/java/nio/Makefile +++ b/make/java/nio/Makefile @@ -1,5 +1,5 @@ # -# Copyright 2000-2008 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. # # This code is free software; you can redistribute it and/or modify it @@ -56,56 +56,214 @@ FILES_java += \ sun/nio/ch/DevPollSelectorProvider.java \ sun/nio/ch/InheritedChannel.java \ sun/nio/ch/PollSelectorProvider.java \ - sun/nio/ch/PollSelectorImpl.java + sun/nio/ch/PollSelectorImpl.java \ + sun/nio/ch/Port.java \ + sun/nio/ch/SimpleAsynchronousFileChannelImpl.java \ + sun/nio/ch/SolarisAsynchronousChannelProvider.java \ + sun/nio/ch/SolarisEventPort.java \ + sun/nio/ch/UnixAsynchronousServerSocketChannelImpl.java \ + sun/nio/ch/UnixAsynchronousSocketChannelImpl.java \ + \ + sun/nio/fs/GnomeFileTypeDetector.java \ + sun/nio/fs/PollingWatchService.java \ + sun/nio/fs/SolarisAclFileAttributeView.java \ + sun/nio/fs/SolarisFileStore.java \ + sun/nio/fs/SolarisFileSystem.java \ + sun/nio/fs/SolarisFileSystemProvider.java \ + sun/nio/fs/SolarisUserDefinedFileAttributeView.java \ + sun/nio/fs/SolarisNativeDispatcher.java \ + sun/nio/fs/SolarisWatchService.java \ + sun/nio/fs/UnixChannelFactory.java \ + sun/nio/fs/UnixCopyFile.java \ + sun/nio/fs/UnixDirectoryStream.java \ + sun/nio/fs/UnixException.java \ + sun/nio/fs/UnixFileAttributeViews.java \ + sun/nio/fs/UnixFileAttributes.java \ + sun/nio/fs/UnixFileKey.java \ + sun/nio/fs/UnixFileModeAttribute.java \ + sun/nio/fs/UnixFileStore.java \ + sun/nio/fs/UnixFileStoreAttributes.java \ + sun/nio/fs/UnixFileSystem.java \ + sun/nio/fs/UnixFileSystemProvider.java \ + sun/nio/fs/UnixMountEntry.java \ + sun/nio/fs/UnixNativeDispatcher.java \ + sun/nio/fs/UnixPath.java \ + sun/nio/fs/UnixSecureDirectoryStream.java \ + sun/nio/fs/UnixUriUtils.java \ + sun/nio/fs/UnixUserPrincipals.java FILES_c += \ DevPollArrayWrapper.c \ InheritedChannel.c \ NativeThread.c \ - PollArrayWrapper.c + PollArrayWrapper.c \ + SolarisEventPort.c \ + UnixAsynchronousServerSocketChannelImpl.c \ + UnixAsynchronousSocketChannelImpl.c \ + \ + GnomeFileTypeDetector.c \ + SolarisNativeDispatcher.c \ + SolarisWatchService.c \ + UnixCopyFile.c \ + UnixNativeDispatcher.c FILES_export += \ sun/nio/ch/DevPollArrayWrapper.java \ sun/nio/ch/InheritedChannel.java \ - sun/nio/ch/NativeThread.java + sun/nio/ch/NativeThread.java \ + sun/nio/ch/SolarisEventPort.java \ + sun/nio/ch/UnixAsynchronousServerSocketChannelImpl.java \ + sun/nio/ch/UnixAsynchronousSocketChannelImpl.java \ + \ + sun/nio/fs/GnomeFileTypeDetector.java \ + sun/nio/fs/SolarisNativeDispatcher.java \ + sun/nio/fs/SolarisWatchService.java \ + sun/nio/fs/UnixCopyFile.java \ + sun/nio/fs/UnixNativeDispatcher.java + +FILES_gen += \ + sun/nio/fs/SolarisConstants.java \ + sun/nio/fs/UnixConstants.java endif # PLATFORM = solaris ifeq ($(PLATFORM), windows) FILES_java += \ + sun/nio/ch/Iocp.java \ + sun/nio/ch/PendingIoCache.java \ + sun/nio/ch/WindowsAsynchronousChannelProvider.java \ + sun/nio/ch/WindowsAsynchronousFileChannelImpl.java \ + sun/nio/ch/WindowsAsynchronousServerSocketChannelImpl.java \ + sun/nio/ch/WindowsAsynchronousSocketChannelImpl.java \ sun/nio/ch/WindowsSelectorImpl.java \ - sun/nio/ch/WindowsSelectorProvider.java + sun/nio/ch/WindowsSelectorProvider.java \ + \ + sun/nio/fs/RegistryFileTypeDetector.java \ + sun/nio/fs/WindowsAclFileAttributeView.java \ + sun/nio/fs/WindowsChannelFactory.java \ + sun/nio/fs/WindowsConstants.java \ + sun/nio/fs/WindowsDirectoryStream.java \ + sun/nio/fs/WindowsException.java \ + sun/nio/fs/WindowsFileAttributeViews.java \ + sun/nio/fs/WindowsFileAttributes.java \ + sun/nio/fs/WindowsFileCopy.java \ + sun/nio/fs/WindowsFileStore.java \ + sun/nio/fs/WindowsFileSystem.java \ + sun/nio/fs/WindowsFileSystemProvider.java \ + sun/nio/fs/WindowsLinkSupport.java \ + sun/nio/fs/WindowsUserDefinedFileAttributeView.java \ + sun/nio/fs/WindowsNativeDispatcher.java \ + sun/nio/fs/WindowsPath.java \ + sun/nio/fs/WindowsPathParser.java \ + sun/nio/fs/WindowsPathType.java \ + sun/nio/fs/WindowsSecurity.java \ + sun/nio/fs/WindowsSecurityDescriptor.java \ + sun/nio/fs/WindowsUriSupport.java \ + sun/nio/fs/WindowsUserPrincipals.java \ + sun/nio/fs/WindowsWatchService.java FILES_c += \ + Iocp.c \ + RegistryFileTypeDetector.c \ + WindowsAsynchronousFileChannelImpl.c \ + WindowsAsynchronousServerSocketChannelImpl.c \ + WindowsAsynchronousSocketChannelImpl.c \ + WindowsNativeDispatcher.c \ WindowsSelectorImpl.c FILES_export += \ - sun/nio/ch/WindowsSelectorImpl.java + sun/nio/ch/Iocp.java \ + sun/nio/ch/WindowsAsynchronousFileChannelImpl.java \ + sun/nio/ch/WindowsAsynchronousServerSocketChannelImpl.java \ + sun/nio/ch/WindowsAsynchronousSocketChannelImpl.java \ + sun/nio/ch/WindowsSelectorImpl.java \ + sun/nio/fs/WindowsNativeDispatcher.java \ + sun/nio/fs/RegistryFileTypeDetector.java endif # PLATFORM = windows ifeq ($(PLATFORM), linux) FILES_java += \ sun/nio/ch/AbstractPollSelectorImpl.java \ + sun/nio/ch/EPoll.java \ sun/nio/ch/EPollArrayWrapper.java \ + sun/nio/ch/EPollPort.java \ sun/nio/ch/EPollSelectorProvider.java \ sun/nio/ch/EPollSelectorImpl.java \ sun/nio/ch/InheritedChannel.java \ + sun/nio/ch/LinuxAsynchronousChannelProvider.java \ sun/nio/ch/PollSelectorProvider.java \ - sun/nio/ch/PollSelectorImpl.java + sun/nio/ch/PollSelectorImpl.java \ + sun/nio/ch/Port.java \ + sun/nio/ch/SimpleAsynchronousFileChannelImpl.java \ + sun/nio/ch/UnixAsynchronousServerSocketChannelImpl.java \ + sun/nio/ch/UnixAsynchronousSocketChannelImpl.java \ + \ + sun/nio/fs/GnomeFileTypeDetector.java \ + sun/nio/fs/LinuxDosFileAttributeView.java \ + sun/nio/fs/LinuxFileStore.java \ + sun/nio/fs/LinuxFileSystem.java \ + sun/nio/fs/LinuxFileSystemProvider.java \ + sun/nio/fs/LinuxUserDefinedFileAttributeView.java \ + sun/nio/fs/LinuxNativeDispatcher.java \ + sun/nio/fs/LinuxWatchService.java \ + sun/nio/fs/PollingWatchService.java \ + sun/nio/fs/UnixChannelFactory.java \ + sun/nio/fs/UnixCopyFile.java \ + sun/nio/fs/UnixDirectoryStream.java \ + sun/nio/fs/UnixException.java \ + sun/nio/fs/UnixFileAttributeViews.java \ + sun/nio/fs/UnixFileAttributes.java \ + sun/nio/fs/UnixFileKey.java \ + sun/nio/fs/UnixFileModeAttribute.java \ + sun/nio/fs/UnixFileStore.java \ + sun/nio/fs/UnixFileStoreAttributes.java \ + sun/nio/fs/UnixFileSystem.java \ + sun/nio/fs/UnixFileSystemProvider.java \ + sun/nio/fs/UnixMountEntry.java \ + sun/nio/fs/UnixNativeDispatcher.java \ + sun/nio/fs/UnixPath.java \ + sun/nio/fs/UnixSecureDirectoryStream.java \ + sun/nio/fs/UnixUriUtils.java \ + sun/nio/fs/UnixUserPrincipals.java FILES_c += \ + EPoll.c \ EPollArrayWrapper.c \ + EPollPort.c \ InheritedChannel.c \ NativeThread.c \ - PollArrayWrapper.c + PollArrayWrapper.c \ + UnixAsynchronousServerSocketChannelImpl.c \ + UnixAsynchronousSocketChannelImpl.c \ + \ + GnomeFileTypeDetector.c \ + LinuxNativeDispatcher.c \ + LinuxWatchService.c \ + UnixCopyFile.c \ + UnixNativeDispatcher.c FILES_export += \ + sun/nio/ch/EPoll.java \ sun/nio/ch/EPollArrayWrapper.java \ + sun/nio/ch/EPollPort.java \ sun/nio/ch/InheritedChannel.java \ - sun/nio/ch/NativeThread.java + sun/nio/ch/NativeThread.java \ + sun/nio/ch/UnixAsynchronousServerSocketChannelImpl.java \ + sun/nio/ch/UnixAsynchronousSocketChannelImpl.java \ + \ + sun/nio/fs/GnomeFileTypeDetector.java \ + sun/nio/fs/LinuxNativeDispatcher.java \ + sun/nio/fs/LinuxWatchService.java \ + sun/nio/fs/UnixCopyFile.java \ + sun/nio/fs/UnixNativeDispatcher.java + +FILES_gen += \ + sun/nio/fs/UnixConstants.java endif # PLATFORM = linux +# # Find platform-specific C source files # +vpath %.c $(PLATFORM_SRC)/native/sun/nio/fs vpath %.c $(PLATFORM_SRC)/native/sun/nio/ch vpath %.c $(SHARE_SRC)/native/sun/nio/ch @@ -175,12 +333,14 @@ CH_SRC=$(NIO_SRC)/channels CS_SRC=$(NIO_SRC)/charset SCH_SRC=$(SNIO_SRC)/ch SCS_SRC=$(SNIO_SRC)/cs +SFS_SRC=$(SNIO_SRC)/fs BUF_GEN=$(NIO_GEN) CH_GEN=$(NIO_GEN)/channels CS_GEN=$(NIO_GEN)/charset SCH_GEN=$(SNIO_GEN)/ch SCS_GEN=$(SNIO_GEN)/cs +SFS_GEN=$(SNIO_GEN)/fs FILES_gensbcs_out = $(FILES_gen_sbcs:%.java=$(GENSRCDIR)/%.java) @@ -670,4 +830,40 @@ $(FILES_gensbcs_out): $(GENCSSRC)/SingleByte-X.java $(GENCSSRC)/sbcs $(BOOT_JAVA_CMD) -cp $(CHARSETMAPPING_JARFILE) build.tools.charsetmapping.GenerateSBCS \ $(GENCSSRC) $(SCS_GEN) sbcs +# +# Generated file system implementation classes (Unix only) +# + +GENUC_SRC = $(PLATFORM_SRC)/native/sun/nio/fs/genUnixConstants.c + +GENUC_EXE = $(TEMPDIR)/genUnixConstants + +GENUC_COPYRIGHT_YEARS = $(shell $(CAT) $(GENUC_SRC) | \ + $(NAWK) '/^.*Copyright.*Sun/ { print $$3 }') + +$(GENUC_EXE) : $(GENUC_SRC) + $(prep-target) + $(CC) $(CPPFLAGS) -o $@ $(GENUC_SRC) + +$(SFS_GEN)/UnixConstants.java: $(GENUC_EXE) + $(prep-target) + NAWK="$(NAWK)" SH="$(SH)" $(SH) -e addNotices.sh $(GENUC_COPYRIGHT_YEARS) > $@ + $(GENUC_EXE) >> $@ + +GENSC_SRC = $(PLATFORM_SRC)/native/sun/nio/fs/genSolarisConstants.c + +GENSC_EXE = $(TEMPDIR)/genSolarisConstants + +GENSC_COPYRIGHT_YEARS = $(shell $(CAT) $(GENSC_SRC) | \ + $(NAWK) '/^.*Copyright.*Sun/ { print $$3 }') + +$(GENSC_EXE) : $(GENSC_SRC) + $(prep-target) + $(CC) $(CPPFLAGS) -o $@ $(GENSC_SRC) + +$(SFS_GEN)/SolarisConstants.java: $(GENSC_EXE) + $(prep-target) + NAWK="$(NAWK)" SH="$(SH)" $(SH) -e addNotices.sh $(GENSC_COPYRIGHT_YEARS) > $@ + $(GENSC_EXE) >> $@ + .PHONY: sources diff --git a/make/java/nio/mapfile-linux b/make/java/nio/mapfile-linux index 3fb47b0eb7c0e42107f01113f529ee39b96726f9..0bd240811c58875c1d8ca6082f6403d2b6190483 100644 --- a/make/java/nio/mapfile-linux +++ b/make/java/nio/mapfile-linux @@ -1,5 +1,5 @@ # -# Copyright 2001-2008 Sun Microsystems, Inc. All Rights Reserved. +# Copyright 2001-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 @@ -44,27 +44,38 @@ SUNWprivate_1.1 { Java_sun_nio_ch_EPollArrayWrapper_interrupt; Java_sun_nio_ch_EPollArrayWrapper_offsetofData; Java_sun_nio_ch_EPollArrayWrapper_sizeofEPollEvent; + Java_sun_nio_ch_EPoll_init; + Java_sun_nio_ch_EPoll_eventSize; + Java_sun_nio_ch_EPoll_eventsOffset; + Java_sun_nio_ch_EPoll_dataOffset; + Java_sun_nio_ch_EPoll_epollCreate; + Java_sun_nio_ch_EPoll_epollCtl; + Java_sun_nio_ch_EPoll_epollWait; + Java_sun_nio_ch_EPollPort_close0; + Java_sun_nio_ch_EPollPort_drain1; + Java_sun_nio_ch_EPollPort_interrupt; + Java_sun_nio_ch_EPollPort_socketpair; Java_sun_nio_ch_FileChannelImpl_close0; - Java_sun_nio_ch_FileChannelImpl_force0; Java_sun_nio_ch_FileChannelImpl_initIDs; - Java_sun_nio_ch_FileChannelImpl_lock0; Java_sun_nio_ch_FileChannelImpl_map0; Java_sun_nio_ch_FileChannelImpl_position0; - Java_sun_nio_ch_FileChannelImpl_release0; - Java_sun_nio_ch_FileChannelImpl_size0; Java_sun_nio_ch_FileChannelImpl_transferTo0; - Java_sun_nio_ch_FileChannelImpl_truncate0; Java_sun_nio_ch_FileChannelImpl_unmap0; - Java_sun_nio_ch_FileDispatcher_close0; - Java_sun_nio_ch_FileDispatcher_closeIntFD; - Java_sun_nio_ch_FileDispatcher_init; - Java_sun_nio_ch_FileDispatcher_preClose0; - Java_sun_nio_ch_FileDispatcher_pread0; - Java_sun_nio_ch_FileDispatcher_pwrite0; - Java_sun_nio_ch_FileDispatcher_read0; - Java_sun_nio_ch_FileDispatcher_readv0; - Java_sun_nio_ch_FileDispatcher_write0; - Java_sun_nio_ch_FileDispatcher_writev0; + Java_sun_nio_ch_FileDispatcherImpl_close0; + Java_sun_nio_ch_FileDispatcherImpl_closeIntFD; + Java_sun_nio_ch_FileDispatcherImpl_force0; + Java_sun_nio_ch_FileDispatcherImpl_init; + Java_sun_nio_ch_FileDispatcherImpl_lock0; + Java_sun_nio_ch_FileDispatcherImpl_preClose0; + Java_sun_nio_ch_FileDispatcherImpl_pread0; + Java_sun_nio_ch_FileDispatcherImpl_pwrite0; + Java_sun_nio_ch_FileDispatcherImpl_read0; + Java_sun_nio_ch_FileDispatcherImpl_readv0; + Java_sun_nio_ch_FileDispatcherImpl_release0; + Java_sun_nio_ch_FileDispatcherImpl_size0; + Java_sun_nio_ch_FileDispatcherImpl_truncate0; + Java_sun_nio_ch_FileDispatcherImpl_write0; + Java_sun_nio_ch_FileDispatcherImpl_writev0; Java_sun_nio_ch_FileKey_init; Java_sun_nio_ch_FileKey_initIDs; Java_sun_nio_ch_InheritedChannel_close0; @@ -108,6 +119,76 @@ SUNWprivate_1.1 { Java_sun_nio_ch_ServerSocketChannelImpl_accept0; Java_sun_nio_ch_ServerSocketChannelImpl_initIDs; Java_sun_nio_ch_SocketChannelImpl_checkConnect; + Java_sun_nio_ch_UnixAsynchronousServerSocketChannelImpl_accept0; + Java_sun_nio_ch_UnixAsynchronousServerSocketChannelImpl_initIDs; + Java_sun_nio_ch_UnixAsynchronousSocketChannelImpl_checkConnect; + Java_sun_nio_fs_GnomeFileTypeDetector_initializeGio; + Java_sun_nio_fs_GnomeFileTypeDetector_probeUsingGio; + Java_sun_nio_fs_GnomeFileTypeDetector_initializeGnomeVfs; + Java_sun_nio_fs_GnomeFileTypeDetector_probeUsingGnomeVfs; + Java_sun_nio_fs_LinuxWatchService_init; + Java_sun_nio_fs_LinuxWatchService_eventSize; + Java_sun_nio_fs_LinuxWatchService_eventOffsets; + Java_sun_nio_fs_LinuxWatchService_inotifyInit; + Java_sun_nio_fs_LinuxWatchService_inotifyAddWatch; + Java_sun_nio_fs_LinuxWatchService_inotifyRmWatch; + Java_sun_nio_fs_LinuxWatchService_configureBlocking; + Java_sun_nio_fs_LinuxWatchService_socketpair; + Java_sun_nio_fs_LinuxWatchService_poll; + Java_sun_nio_fs_LinuxNativeDispatcher_init; + Java_sun_nio_fs_LinuxNativeDispatcher_fgetxattr0; + Java_sun_nio_fs_LinuxNativeDispatcher_flistxattr; + Java_sun_nio_fs_LinuxNativeDispatcher_fsetxattr0; + Java_sun_nio_fs_LinuxNativeDispatcher_fremovexattr0; + Java_sun_nio_fs_LinuxNativeDispatcher_setmntent0; + Java_sun_nio_fs_LinuxNativeDispatcher_endmntent; + Java_sun_nio_fs_UnixNativeDispatcher_initIDs; + Java_sun_nio_fs_UnixNativeDispatcher_getcwd; + Java_sun_nio_fs_UnixNativeDispatcher_strerror; + Java_sun_nio_fs_UnixNativeDispatcher_dup; + Java_sun_nio_fs_UnixNativeDispatcher_access0; + Java_sun_nio_fs_UnixNativeDispatcher_stat0; + Java_sun_nio_fs_UnixNativeDispatcher_lstat0; + Java_sun_nio_fs_UnixNativeDispatcher_fstat; + Java_sun_nio_fs_UnixNativeDispatcher_fstatat0; + Java_sun_nio_fs_UnixNativeDispatcher_chmod0; + Java_sun_nio_fs_UnixNativeDispatcher_fchmod; + Java_sun_nio_fs_UnixNativeDispatcher_chown0; + Java_sun_nio_fs_UnixNativeDispatcher_lchown0; + Java_sun_nio_fs_UnixNativeDispatcher_fchown; + Java_sun_nio_fs_UnixNativeDispatcher_utimes0; + Java_sun_nio_fs_UnixNativeDispatcher_futimes; + Java_sun_nio_fs_UnixNativeDispatcher_open0; + Java_sun_nio_fs_UnixNativeDispatcher_openat0; + Java_sun_nio_fs_UnixNativeDispatcher_close; + Java_sun_nio_fs_UnixNativeDispatcher_read; + Java_sun_nio_fs_UnixNativeDispatcher_write; + Java_sun_nio_fs_UnixNativeDispatcher_fopen0; + Java_sun_nio_fs_UnixNativeDispatcher_fclose; + Java_sun_nio_fs_UnixNativeDispatcher_opendir0; + Java_sun_nio_fs_UnixNativeDispatcher_fdopendir; + Java_sun_nio_fs_UnixNativeDispatcher_readdir; + Java_sun_nio_fs_UnixNativeDispatcher_closedir; + Java_sun_nio_fs_UnixNativeDispatcher_link0; + Java_sun_nio_fs_UnixNativeDispatcher_unlink0; + Java_sun_nio_fs_UnixNativeDispatcher_unlinkat0; + Java_sun_nio_fs_UnixNativeDispatcher_rename0; + Java_sun_nio_fs_UnixNativeDispatcher_renameat0; + Java_sun_nio_fs_UnixNativeDispatcher_mkdir0; + Java_sun_nio_fs_UnixNativeDispatcher_rmdir0; + Java_sun_nio_fs_UnixNativeDispatcher_symlink0; + Java_sun_nio_fs_UnixNativeDispatcher_readlink0; + Java_sun_nio_fs_UnixNativeDispatcher_realpath0; + Java_sun_nio_fs_UnixNativeDispatcher_statvfs0; + Java_sun_nio_fs_UnixNativeDispatcher_pathconf0; + Java_sun_nio_fs_UnixNativeDispatcher_fpathconf; + Java_sun_nio_fs_UnixNativeDispatcher_mknod0; + Java_sun_nio_fs_UnixNativeDispatcher_getpwuid; + Java_sun_nio_fs_UnixNativeDispatcher_getgrgid; + Java_sun_nio_fs_UnixNativeDispatcher_getpwnam0; + Java_sun_nio_fs_UnixNativeDispatcher_getgrnam0; + Java_sun_nio_fs_UnixNativeDispatcher_getextmntent; + Java_sun_nio_fs_UnixCopyFile_transfer; local: *; diff --git a/make/java/nio/mapfile-solaris b/make/java/nio/mapfile-solaris index 6e109e2fabaf9be9aed350acf55ece2eb833265f..2192a5a7751deebe108399b34983a4d4fa065377 100644 --- a/make/java/nio/mapfile-solaris +++ b/make/java/nio/mapfile-solaris @@ -1,5 +1,5 @@ # -# Copyright 2001-2008 Sun Microsystems, Inc. All Rights Reserved. +# Copyright 2001-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 @@ -43,26 +43,26 @@ SUNWprivate_1.1 { Java_sun_nio_ch_DevPollArrayWrapper_register; Java_sun_nio_ch_DevPollArrayWrapper_registerMultiple; Java_sun_nio_ch_FileChannelImpl_close0; - Java_sun_nio_ch_FileChannelImpl_force0; Java_sun_nio_ch_FileChannelImpl_initIDs; - Java_sun_nio_ch_FileChannelImpl_lock0; Java_sun_nio_ch_FileChannelImpl_map0; Java_sun_nio_ch_FileChannelImpl_position0; - Java_sun_nio_ch_FileChannelImpl_release0; - Java_sun_nio_ch_FileChannelImpl_size0; Java_sun_nio_ch_FileChannelImpl_transferTo0; - Java_sun_nio_ch_FileChannelImpl_truncate0; Java_sun_nio_ch_FileChannelImpl_unmap0; - Java_sun_nio_ch_FileDispatcher_close0; - Java_sun_nio_ch_FileDispatcher_closeIntFD; - Java_sun_nio_ch_FileDispatcher_init; - Java_sun_nio_ch_FileDispatcher_preClose0; - Java_sun_nio_ch_FileDispatcher_pread0; - Java_sun_nio_ch_FileDispatcher_pwrite0; - Java_sun_nio_ch_FileDispatcher_read0; - Java_sun_nio_ch_FileDispatcher_readv0; - Java_sun_nio_ch_FileDispatcher_write0; - Java_sun_nio_ch_FileDispatcher_writev0; + Java_sun_nio_ch_FileDispatcherImpl_close0; + Java_sun_nio_ch_FileDispatcherImpl_closeIntFD; + Java_sun_nio_ch_FileDispatcherImpl_force0; + Java_sun_nio_ch_FileDispatcherImpl_init; + Java_sun_nio_ch_FileDispatcherImpl_lock0; + Java_sun_nio_ch_FileDispatcherImpl_preClose0; + Java_sun_nio_ch_FileDispatcherImpl_pread0; + Java_sun_nio_ch_FileDispatcherImpl_pwrite0; + Java_sun_nio_ch_FileDispatcherImpl_read0; + Java_sun_nio_ch_FileDispatcherImpl_readv0; + Java_sun_nio_ch_FileDispatcherImpl_release0; + Java_sun_nio_ch_FileDispatcherImpl_size0; + Java_sun_nio_ch_FileDispatcherImpl_truncate0; + Java_sun_nio_ch_FileDispatcherImpl_write0; + Java_sun_nio_ch_FileDispatcherImpl_writev0; Java_sun_nio_ch_FileKey_init; Java_sun_nio_ch_FileKey_initIDs; Java_sun_nio_ch_InheritedChannel_close0; @@ -106,6 +106,75 @@ SUNWprivate_1.1 { Java_sun_nio_ch_ServerSocketChannelImpl_accept0; Java_sun_nio_ch_ServerSocketChannelImpl_initIDs; Java_sun_nio_ch_SocketChannelImpl_checkConnect; + Java_sun_nio_ch_UnixAsynchronousServerSocketChannelImpl_accept0; + Java_sun_nio_ch_UnixAsynchronousServerSocketChannelImpl_initIDs; + Java_sun_nio_ch_UnixAsynchronousSocketChannelImpl_checkConnect; + Java_sun_nio_ch_SolarisEventPort_init; + Java_sun_nio_ch_SolarisEventPort_portCreate; + Java_sun_nio_ch_SolarisEventPort_portClose; + Java_sun_nio_ch_SolarisEventPort_portAssociate; + Java_sun_nio_ch_SolarisEventPort_portGet; + Java_sun_nio_ch_SolarisEventPort_portGetn; + Java_sun_nio_ch_SolarisEventPort_portSend; + Java_sun_nio_fs_GnomeFileTypeDetector_initializeGio; + Java_sun_nio_fs_GnomeFileTypeDetector_probeUsingGio; + Java_sun_nio_fs_GnomeFileTypeDetector_initializeGnomeVfs; + Java_sun_nio_fs_GnomeFileTypeDetector_probeUsingGnomeVfs; + Java_sun_nio_fs_UnixNativeDispatcher_initIDs; + Java_sun_nio_fs_UnixNativeDispatcher_getcwd; + Java_sun_nio_fs_UnixNativeDispatcher_strerror; + Java_sun_nio_fs_UnixNativeDispatcher_dup; + Java_sun_nio_fs_UnixNativeDispatcher_access0; + Java_sun_nio_fs_UnixNativeDispatcher_stat0; + Java_sun_nio_fs_UnixNativeDispatcher_lstat0; + Java_sun_nio_fs_UnixNativeDispatcher_fstat; + Java_sun_nio_fs_UnixNativeDispatcher_fstatat0; + Java_sun_nio_fs_UnixNativeDispatcher_chmod0; + Java_sun_nio_fs_UnixNativeDispatcher_fchmod; + Java_sun_nio_fs_UnixNativeDispatcher_chown0; + Java_sun_nio_fs_UnixNativeDispatcher_lchown0; + Java_sun_nio_fs_UnixNativeDispatcher_fchown; + Java_sun_nio_fs_UnixNativeDispatcher_utimes0; + Java_sun_nio_fs_UnixNativeDispatcher_futimes; + Java_sun_nio_fs_UnixNativeDispatcher_open0; + Java_sun_nio_fs_UnixNativeDispatcher_openat0; + Java_sun_nio_fs_UnixNativeDispatcher_close; + Java_sun_nio_fs_UnixNativeDispatcher_read; + Java_sun_nio_fs_UnixNativeDispatcher_write; + Java_sun_nio_fs_UnixNativeDispatcher_fopen0; + Java_sun_nio_fs_UnixNativeDispatcher_fclose; + Java_sun_nio_fs_UnixNativeDispatcher_opendir0; + Java_sun_nio_fs_UnixNativeDispatcher_fdopendir; + Java_sun_nio_fs_UnixNativeDispatcher_readdir; + Java_sun_nio_fs_UnixNativeDispatcher_closedir; + Java_sun_nio_fs_UnixNativeDispatcher_link0; + Java_sun_nio_fs_UnixNativeDispatcher_unlink0; + Java_sun_nio_fs_UnixNativeDispatcher_unlinkat0; + Java_sun_nio_fs_UnixNativeDispatcher_rename0; + Java_sun_nio_fs_UnixNativeDispatcher_renameat0; + Java_sun_nio_fs_UnixNativeDispatcher_mkdir0; + Java_sun_nio_fs_UnixNativeDispatcher_rmdir0; + Java_sun_nio_fs_UnixNativeDispatcher_symlink0; + Java_sun_nio_fs_UnixNativeDispatcher_readlink0; + Java_sun_nio_fs_UnixNativeDispatcher_realpath0; + Java_sun_nio_fs_UnixNativeDispatcher_statvfs0; + Java_sun_nio_fs_UnixNativeDispatcher_pathconf0; + Java_sun_nio_fs_UnixNativeDispatcher_fpathconf; + Java_sun_nio_fs_UnixNativeDispatcher_mknod0; + Java_sun_nio_fs_UnixNativeDispatcher_getpwuid; + Java_sun_nio_fs_UnixNativeDispatcher_getgrgid; + Java_sun_nio_fs_UnixNativeDispatcher_getpwnam0; + Java_sun_nio_fs_UnixNativeDispatcher_getgrnam0; + Java_sun_nio_fs_UnixNativeDispatcher_getextmntent; + Java_sun_nio_fs_UnixCopyFile_transfer; + Java_sun_nio_fs_SolarisNativeDispatcher_init; + Java_sun_nio_fs_SolarisNativeDispatcher_facl; + Java_sun_nio_fs_SolarisWatchService_init; + Java_sun_nio_fs_SolarisWatchService_portCreate; + Java_sun_nio_fs_SolarisWatchService_portAssociate; + Java_sun_nio_fs_SolarisWatchService_portDissociate; + Java_sun_nio_fs_SolarisWatchService_portSend; + Java_sun_nio_fs_SolarisWatchService_portGetn; local: *; diff --git a/make/java/redist/Makefile b/make/java/redist/Makefile index 159c247b3f367240b15c5a654ad6dc69ba30baa6..9ab884dd247f6bd11cce5bc1e9a8148a0231571f 100644 --- a/make/java/redist/Makefile +++ b/make/java/redist/Makefile @@ -251,9 +251,11 @@ endif # INCLUDE_SA # ifdef OPENJDK -include $(BUILDDIR)/common/internal/BinaryPlugs.gmk + ifeq ($(IMPORT_BINARY_PLUGS),true) + include $(BUILDDIR)/common/internal/BinaryPlugs.gmk -build: import-binary-plugs + build: import-binary-plugs + endif else # !OPENJDK diff --git a/make/java/text/FILES_java.gmk b/make/java/text/FILES_java.gmk index 67b4c19c66efece0ae1b285fea650514bc2a8743..88dc12903cc9e28eb6a386037e8083767119f5c3 100644 --- a/make/java/text/FILES_java.gmk +++ b/make/java/text/FILES_java.gmk @@ -92,11 +92,11 @@ FILES_java = \ sun/text/normalizer/SymbolTable.java \ sun/text/normalizer/Trie.java \ sun/text/normalizer/TrieIterator.java \ + sun/text/normalizer/UBiDiProps.java \ sun/text/normalizer/UCharacter.java \ sun/text/normalizer/UCharacterIterator.java \ sun/text/normalizer/UCharacterProperty.java \ sun/text/normalizer/UCharacterPropertyReader.java \ - sun/text/normalizer/UProperty.java \ sun/text/normalizer/UTF16.java \ sun/text/normalizer/UnicodeMatcher.java \ sun/text/normalizer/UnicodeSet.java \ diff --git a/make/java/text/Makefile b/make/java/text/Makefile index 76955e22d81ae0e67a5e702a658238685e4a82ee..4db338926f38cf87bc6b3be0d41760ff2b804aef 100644 --- a/make/java/text/Makefile +++ b/make/java/text/Makefile @@ -64,7 +64,8 @@ BIFILES = $(TEXT_CLASSDIR)/CharacterBreakIteratorData \ $(TEXT_CLASSDIR)/SentenceBreakIteratorData ICU_FILES = $(TEXT_CLASSDIR)/unorm.icu \ - $(TEXT_CLASSDIR)/uprops.icu + $(TEXT_CLASSDIR)/uprops.icu \ + $(TEXT_CLASSDIR)/ubidi.icu # builder GENERATEBREAKITERATORDATA_JARFILE = \ @@ -89,7 +90,7 @@ $(BIFILES): $(GENERATEBREAKITERATORDATA_JARFILE) \ build: $(BIFILES) $(ICU_FILES) # -# Extra rules to copy unorm.icu and uprops.icu +# Extra rules to copy unorm.icu, uprops.icu, and ubidi.icu # $(TEXT_CLASSDIR)/unorm.icu: $(TEXT_SRCDIR)/unorm.icu $(install-file) @@ -97,6 +98,9 @@ $(TEXT_CLASSDIR)/unorm.icu: $(TEXT_SRCDIR)/unorm.icu $(TEXT_CLASSDIR)/uprops.icu: $(TEXT_SRCDIR)/uprops.icu $(install-file) +$(TEXT_CLASSDIR)/ubidi.icu: $(TEXT_SRCDIR)/ubidi.icu + $(install-file) + clean clobber:: $(RM) -r $(TEXT_CLASSES) $(RM) -r $(BIFILES) diff --git a/make/javax/management/Makefile b/make/javax/management/Makefile index 2085e38a88bbd4c0d187a4954cf2628873c1ca29..02527ec2d21fdc1d98a410834ffa250aaebf28a7 100644 --- a/make/javax/management/Makefile +++ b/make/javax/management/Makefile @@ -35,6 +35,7 @@ include $(BUILDDIR)/common/Defs.gmk # # Files to compile # +AUTO_JAVA_PRUNE = snmp AUTO_FILES_JAVA_DIRS = javax/management com/sun/jmx com/sun/management/jmx # diff --git a/make/javax/swing/beaninfo/SwingBeans.gmk b/make/javax/swing/beaninfo/SwingBeans.gmk index 66f16aae1a196ee584e06bd1958ecd1b647af69a..cae9873e0c39d0cdd6b71259979e4dbe87b0ba9c 100644 --- a/make/javax/swing/beaninfo/SwingBeans.gmk +++ b/make/javax/swing/beaninfo/SwingBeans.gmk @@ -47,7 +47,7 @@ swing-1.2-beans-debug: LOCAL_JAVADOC = $(JAVADOC_CMD) $(JAVADOCFLAGS) # get the absolute path to the jar command. PREFIX = 1.2 -JAVADOCFLAGS = $(LANGUAGE_VERSION) +JAVADOCFLAGS = $(NO_PROPRIETARY_API_WARNINGS) $(LANGUAGE_VERSION) SWINGPKG = javax/swing LOCAL_JAVAC_FLAGS = $(OTHER_JAVACFLAGS) diff --git a/make/jdk_generic_profile.sh b/make/jdk_generic_profile.sh index 32dd86197ef224ef6c9c5b6dfc62f4527aa3d913..125198301ca74d46b5465a31b0f04a0f0968d0e7 100644 --- a/make/jdk_generic_profile.sh +++ b/make/jdk_generic_profile.sh @@ -174,7 +174,8 @@ else # Check CYGWIN (should have already been done) # Assumption here is that you are in a shell window via cygwin. - if [ "$(echo ${PROCESSOR_IDENTIFIER} | fgrep AMD64)" != "" ] ; then + proc_arch=`echo "$(PROCESSOR_IDENTIFIER)" | expand | cut -d' ' -f1 | sed -e 's@x86@X86@g' -e 's@Intel64@X64@g' -e 's@em64t@X64@g' -e 's@EM64T@X64@g' -e 's@amd64@X64@g' -e 's@AMD64@X64@g' -e 's@ia64@IA64@g'` + if [ "${proc_arch}" = "X64" ] ; then windows_arch=amd64 else windows_arch=i586 diff --git a/make/jprt.config b/make/jprt.config deleted file mode 100644 index d720475cecd77b44ed890ee2eb7f9bebce0c10ab..0000000000000000000000000000000000000000 --- a/make/jprt.config +++ /dev/null @@ -1,363 +0,0 @@ -#!echo "This is not a shell script" -############################################################################# -# -# Copyright 2006-2008 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. -# -############################################################################# -# -# JPRT shell configuration for building. -# -# Input environment variables: -# ALT_BOOTDIR -# ALT_SLASH_JAVA -# ALT_JDK_IMPORT_PATH -# OPENJDK -# Windows Only: -# PATH -# VS71COMNTOOLS -# PROCESSOR_IDENTIFIER -# ROOTDIR -# -# Output variable settings: -# make Full path to GNU make -# compiler_path Path to compiler bin directory -# compiler_name Unique name of this compiler -# -# Output environment variables: -# PATH -# ALT_COMPILER_PATH -# OPENJDK only: -# ALT_CLOSED_JDK_IMPORT_PATH -# ALT_JDK_DEVTOOLS_DIR -# Windows Only: -# ALT_MSDEVTOOLS_PATH -# ALT_DEVTOOLS_PATH (To avoid the C:/UTILS default) -# LIB -# INCLUDE -# -# After JDK6, most settings will be found via ALT_SLASH_JAVA or -# by way of other system environment variables. If this was JDK5 -# or an older JDK, you might need to export more ALT_* variables. -# -# On Windows AMD64, if MSSDK is not set, assumes Platform SDK is installed at: -# C:/Program Files/Microsoft Platform SDK -# -############################################################################# - -############################################################################# -# Error -error() # message -{ - echo "ERROR: $1" - exit 6 -} -# Directory must exist -dirMustExist() # dir name -{ - if [ ! -d "$1" ] ; then - error "Directory for $2 does not exist: $1" - fi -} -# File must exist -fileMustExist() # dir name -{ - if [ ! -f "$1" ] ; then - error "File for $2 does not exist: $1" - fi -} -############################################################################# - -# Should be set by JPRT as the 3 basic inputs -bootdir="${ALT_BOOTDIR}" -slashjava="${ALT_SLASH_JAVA}" -jdk_import="${ALT_JDK_IMPORT_PATH}" - -# The /java/devtools items -jdk_devtools="${slashjava}/devtools" -share="${jdk_devtools}/share" - -# Needed for langtools, maybe other parts of the build -ANT_HOME="${share}/ant/latest" -export ANT_HOME - -# The 3 bin directories in common to all platforms -sharebin="${share}/bin" -antbin="${ANT_HOME}/bin" - -# Check input -dirMustExist "${bootdir}" ALT_BOOTDIR -dirMustExist "${slashjava}" ALT_SLASH_JAVA -dirMustExist "${jdk_import}" ALT_JDK_IMPORT_PATH -dirMustExist "${ANT_HOME}" ANT_HOME - -# Use the JDK import for now (FIXME: use the binary plugs?) -if [ "${OPENJDK}" = true ] ; then - ALT_CLOSED_JDK_IMPORT_PATH="${jdk_import}" - export ALT_CLOSED_JDK_IMPORT_PATH -fi - -# Uses 'uname -s', but only expect SunOS or Linux, assume Windows otherwise. -osname=`uname -s` -if [ "${osname}" = SunOS ] ; then - - # SOLARIS: Sparc or X86 - osarch=`uname -p` - if [ "${osarch}" = sparc ] ; then - solaris_arch=sparc - else - solaris_arch=i386 - fi - - # Get the compilers into path (make sure it matches ALT setting) - if [ "${JPRT_SOLARIS_COMPILER_NAME}" != "" ] ; then - compiler_name=${JPRT_SOLARIS_COMPILER_NAME} - else - compiler_name=SS12 - fi - compiler_path=${jdk_devtools}/${solaris_arch}/SUNWspro/${compiler_name}/bin - ALT_COMPILER_PATH="${compiler_path}" - export ALT_COMPILER_PATH - dirMustExist "${compiler_path}" ALT_COMPILER_PATH - path4sdk=${compiler_path}:${sharebin}:${antbin} - - # Add basic solaris system paths - path4sdk=${path4sdk}:/usr/ccs/bin:/usr/ccs/lib:/usr/bin:/bin:/usr/sfw/bin - - # Get the previous JDK to be used to bootstrap the build - path4sdk=${bootdir}/bin:${path4sdk} - - # Find GNU make - make=/usr/sfw/bin/gmake - if [ ! -f ${make} ] ; then - make=/opt/sfw/bin/gmake - if [ ! -f ${make} ] ; then - make=${jdk_devtools}/${solaris_arch}/bin/gnumake - fi - fi - fileMustExist "${make}" make - - # File creation mask - umask 002 - -elif [ "${osname}" = Linux ] ; then - - # LINUX: X86, AMD64 - osarch=`uname -m` - if [ "${osarch}" = i686 ] ; then - linux_arch=i586 - elif [ "${osarch}" = x86_64 ] ; then - linux_arch=amd64 - fi - - # Get the compilers into path (make sure it matches ALT setting) - compiler_path=/usr/bin - compiler_name=usr_bin - ALT_COMPILER_PATH="${compiler_path}" - export ALT_COMPILER_PATH - dirMustExist "${compiler_path}" ALT_COMPILER_PATH - path4sdk=${compiler_path}:${sharebin}:${antbin} - - # Add basic paths - path4sdk=${path4sdk}:/usr/bin:/bin:/usr/sbin:/sbin - - # Get the previous JDK to be used to bootstrap the build - path4sdk=${bootdir}/bin:${path4sdk} - - # Find GNU make - make=/usr/bin/make - fileMustExist "${make}" make - - umask 002 - - # Linux platform may be old, use motif files from the devtools area - if [ "${OPENJDK}" = true ] ; then - ALT_JDK_DEVTOOLS_DIR="${jdk_devtools}" - export ALT_JDK_DEVTOOLS_DIR - fi - - -else - - # Windows: Differs on CYGWIN vs. MKS, and the compiler available. - # Also, blanks in pathnames gives GNU make headaches, so anything placed - # in any ALT_* variable should be the short windows dosname. - - # WINDOWS: Install and use MKS or CYGWIN (should have already been done) - # Assumption here is that you are in a shell window via MKS or cygwin. - # MKS install should have defined the environment variable ROOTDIR. - # We also need to figure out which one we have: X86, AMD64 - if [ "`echo ${PROCESSOR_IDENTIFIER} | fgrep AMD64`" != "" ] ; then - windows_arch=amd64 - else - windows_arch=i586 - fi - - # We need to determine if we are running a CYGWIN shell or an MKS shell - # (if uname isn't available, then it will be unix_toolset=unknown) - unix_toolset=unknown - if [ "`uname -a | fgrep Cygwin`" = "" -a -d "${ROOTDIR}" ] ; then - # We kind of assume ROOTDIR is where MKS is and it's ok - unix_toolset=MKS - mkshome=`dosname -s "${ROOTDIR}"` - # Utility to convert to short pathnames without spaces - dosname="${mkshome}/mksnt/dosname -s" - # Most unix utilities are in the mksnt directory of ROOTDIR - unixcommand_path="${mkshome}/mksnt" - path4sdk="${sharebin};${antbin};${unixcommand_path}" - dirMustExist "${unixcommand_path}" ALT_UNIXCOMMAND_PATH - devtools_path="${jdk_devtools}/win32/bin" - path4sdk="${devtools_path};${path4sdk}" - # Normally this need not be set, but on Windows it's default is C:/UTILS - ALT_DEVTOOLS_PATH="${devtools_path}" - export ALT_DEVTOOLS_PATH - dirMustExist "${devtools_path}" ALT_DEVTOOLS_PATH - # Find GNU make - make="${devtools_path}/gnumake.exe" - fileMustExist "${make}" make - elif [ "`uname -a | fgrep Cygwin`" != "" -a -f /bin/cygpath ] ; then - # For CYGWIN, uname will have "Cygwin" in it, and /bin/cygpath should exist - unix_toolset=CYGWIN - # Utility to convert to short pathnames without spaces - dosname="/usr/bin/cygpath -a -m -s" - # Most unix utilities are in the /usr/bin - unixcommand_path="/usr/bin" - path4sdk="${sharebin};${antbin};${unixcommand_path}" - dirMustExist "${unixcommand_path}" ALT_UNIXCOMMAND_PATH - # Find GNU make - make="${unixcommand_path}/make.exe" - fileMustExist "${make}" make - else - echo "WARNING: Cannot figure out if this is MKS or CYGWIN" - fi - - # WINDOWS: Compiler setup (nasty part) - # NOTE: You can use vcvars32.bat to set PATH, LIB, and INCLUDE. - # NOTE: CYGWIN has a link.exe too, make sure the compilers are first - if [ "${windows_arch}" = i586 ] ; then - # 32bit Windows compiler settings - # VisualStudio .NET 2003 VC++ 7.1 (VS71COMNTOOLS should be defined) - vs_root=`${dosname} "${VS71COMNTOOLS}/../.."` - # Fill in PATH, LIB, and INCLUDE (unset all others to make sure) - msdev_root="${vs_root}/Common7/Tools" - msdevtools_path="${msdev_root}/bin" - vc7_root="${vs_root}/Vc7" - compiler_path="${vc7_root}/bin" - compiler_name=VS2003 - platform_sdk="${vc7_root}/PlatformSDK" - # LIB and INCLUDE must use ; as a separator - include4sdk="${vc7_root}/atlmfc/include" - include4sdk="${include4sdk};${vc7_root}/include" - include4sdk="${include4sdk};${platform_sdk}/include/prerelease" - include4sdk="${include4sdk};${platform_sdk}/include" - include4sdk="${include4sdk};${vs_root}/SDK/v1.1/include" - lib4sdk="${vc7_root}/atlmfc/lib" - lib4sdk="${lib4sdk};${vc7_root}/lib" - lib4sdk="${lib4sdk};${platform_sdk}/lib/prerelease" - lib4sdk="${lib4sdk};${platform_sdk}/lib" - lib4sdk="${lib4sdk};${vs_root}/SDK/v1.1/lib" - # Search path and DLL locating path - # WARNING: CYGWIN has a link.exe too, make sure compilers are first - path4sdk="${vs_root}/Common7/Tools/bin;${path4sdk}" - path4sdk="${vs_root}/SDK/v1.1/bin;${path4sdk}" - path4sdk="${vs_root}/Common7/Tools;${path4sdk}" - path4sdk="${vs_root}/Common7/Tools/bin/prerelease;${path4sdk}" - path4sdk="${vs_root}/Common7/IDE;${path4sdk}" - path4sdk="${compiler_path};${path4sdk}" - elif [ "${windows_arch}" = amd64 ] ; then - # AMD64 64bit Windows compiler settings - if [ "${MSSDK}" != "" ] ; then - platform_sdk="${MSSDK}" - else - platform_sdk=`${dosname} "C:/Program Files/Microsoft Platform SDK/"` - fi - compiler_path="${platform_sdk}/Bin/win64/x86/AMD64" - compiler_name=VS2005_PSDK - msdevtools_path="${platform_sdk}/Bin" - # LIB and INCLUDE must use ; as a separator - include4sdk="${platform_sdk}/Include" - include4sdk="${include4sdk};${platform_sdk}/Include/crt/sys" - include4sdk="${include4sdk};${platform_sdk}/Include/mfc" - include4sdk="${include4sdk};${platform_sdk}/Include/atl" - include4sdk="${include4sdk};${platform_sdk}/Include/crt" - lib4sdk="${platform_sdk}/Lib/AMD64" - lib4sdk="${lib4sdk};${platform_sdk}/Lib/AMD64/atlmfc" - # Search path and DLL locating path - # WARNING: CYGWIN has a link.exe too, make sure compilers are first - path4sdk="${platform_sdk}/bin;${path4sdk}" - path4sdk="${compiler_path};${path4sdk}" - fi - # Export LIB and INCLUDE - unset lib - unset Lib - LIB="${lib4sdk}" - export LIB - unset include - unset Include - INCLUDE="${include4sdk}" - export INCLUDE - # Set the ALT variable - ALT_COMPILER_PATH=`${dosname} "${compiler_path}"` - export ALT_COMPILER_PATH - dirMustExist "${compiler_path}" ALT_COMPILER_PATH - ALT_MSDEVTOOLS_PATH=`${dosname} "${msdevtools_path}"` - export ALT_MSDEVTOOLS_PATH - dirMustExist "${msdevtools_path}" ALT_MSDEVTOOLS_PATH - - # WINDOWS: Get the previous JDK to be used to bootstrap the build - path4sdk="${bootdir}/bin;${path4sdk}" - - # Turn all \\ into /, remove duplicates and trailing / - slash_path="`echo ${path4sdk} | sed -e 's@\\\\@/@g' -e 's@//@/@g' -e 's@/$@@' -e 's@/;@;@g'`" - - # For windows, it's hard to know where the system is, so we just add this - # to PATH. - path4sdk="${slash_path};${PATH}" - - # Convert path4sdk to cygwin style - if [ "${unix_toolset}" = CYGWIN ] ; then - path4sdk="`/usr/bin/cygpath -p ${path4sdk}`" - fi - - # Set special windows ALT variables - ALT_ISHIELDDIR="C:/ishield802" - export ALT_ISHIELDDIR - - # Sponsors binaries - ALT_SPONSOR1DIR=C:/sponsor_binaries - export ALT_SPONSOR1DIR - ALT_SPONSOR2DIR=C:/sponsor_binaries - export ALT_SPONSOR2DIR - -fi - -# Export PATH setting -PATH="${path4sdk}" -export PATH - -# Things we need to unset -unset LD_LIBRARY_PATH -unset LD_LIBRARY_PATH_32 -unset LD_LIBRARY_PATH_64 -unset JAVA_HOME - diff --git a/make/jprt.properties b/make/jprt.properties index c909f36aa3c4c18411608528ffd952bc5e248b76..a1e7e5100ba2b7db3145e0aa6ed626a2eefaaaea 100644 --- a/make/jprt.properties +++ b/make/jprt.properties @@ -53,6 +53,19 @@ jprt.solaris_x64.build.platform.match32=solaris_i586_5.10 # Standard list of jprt test targets for this workspace jprt.test.targets=*-*-*-jvm98 +jprt.regression.test.targets= \ + *-*-*-java/lang, \ + *-*-*-java/security, \ + *-*-*-java/text, \ + *-*-*-java/util + +#jprt.regression.test.targets= \ +# *-*-*-java/awt, \ +# *-*-*-java/beans, \ +# *-*-*-java/io, \ +# *-*-*-java/net, \ +# *-*-*-java/nio, \ +# *-*-*-java/rmi, \ # Directories needed to build jprt.bundle.exclude.src.dirs=build diff --git a/make/mksample/nio/Makefile b/make/mksample/nio/Makefile index e05106293bbc0764c6f564b00fc4be19f92959bd..5fcfd03a78306c2ad9dad77f6595f6959dfd943d 100644 --- a/make/mksample/nio/Makefile +++ b/make/mksample/nio/Makefile @@ -1,5 +1,5 @@ # -# Copyright 2004-2008 Sun Microsystems, Inc. All Rights Reserved. +# Copyright 2004-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 @@ -31,7 +31,7 @@ BUILDDIR = ../.. PRODUCT = java include $(BUILDDIR)/common/Defs.gmk -SUBDIRS = multicast server +SUBDIRS = file multicast server all build clean clobber:: $(SUBDIRS-loop) diff --git a/make/common/shared/Compiler.gmk b/make/mksample/nio/file/Makefile similarity index 61% rename from make/common/shared/Compiler.gmk rename to make/mksample/nio/file/Makefile index e5847a2e28cf88d94d681164e2d3d236f9237401..f7159de83a32e609d3e2847343faaead881fa77d 100644 --- a/make/common/shared/Compiler.gmk +++ b/make/mksample/nio/file/Makefile @@ -1,5 +1,5 @@ # -# Copyright 2005 Sun Microsystems, Inc. All Rights Reserved. +# Copyright 2008-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 @@ -24,24 +24,33 @@ # # -# Compiler settings for all platforms and the default compiler for each. +# Makefile for the nio/file sample code # -# Windows uses Microsoft compilers by default -ifeq ($(PLATFORM), windows) - override CC_VERSION = msvc -endif +BUILDDIR = ../../.. -# Solaris uses Sun Studio compilers by default -ifeq ($(PLATFORM), solaris) - override CC_VERSION = sun -endif +PRODUCT = java -# Linux uses GNU compilers by default -ifeq ($(PLATFORM), linux) - override CC_VERSION = gcc -endif +include $(BUILDDIR)/common/Defs.gmk -# Get the compiler specific settings -include $(JDK_MAKE_SHARED_DIR)/Compiler-$(CC_VERSION).gmk +SAMPLE_SRC_DIR = $(SHARE_SRC)/sample/nio/file +SAMPLE_DST_DIR = $(SAMPLEDIR)/nio/file +SAMPLE_FILES = \ + $(SAMPLE_DST_DIR)/AclEdit.java \ + $(SAMPLE_DST_DIR)/Chmod.java \ + $(SAMPLE_DST_DIR)/Copy.java \ + $(SAMPLE_DST_DIR)/DiskUsage.java \ + $(SAMPLE_DST_DIR)/FileType.java \ + $(SAMPLE_DST_DIR)/WatchDir.java \ + $(SAMPLE_DST_DIR)/Xdd.java + +all build: $(SAMPLE_FILES) + +$(SAMPLE_DST_DIR)/%: $(SAMPLE_SRC_DIR)/% + $(install-file) + +clean clobber: + $(RM) -r $(SAMPLE_DST_DIR) + +.PHONY: all build clean clobber diff --git a/make/sun/awt/Makefile b/make/sun/awt/Makefile index cd89650a5975d22a0e02e44745a018a6d9d5bbf2..c3c1745ff54993decc7759eced0d5bb81ce782b3 100644 --- a/make/sun/awt/Makefile +++ b/make/sun/awt/Makefile @@ -340,8 +340,7 @@ ifeq ($(PLATFORM), windows) FONTCONFIGS_SRC = $(PLATFORM_SRC)/classes/sun/awt/windows _FONTCONFIGS = \ - fontconfig.properties \ - fontconfig.98.properties + fontconfig.properties FONTCONFIGS_SRC_PREFIX = diff --git a/make/sun/management/Makefile b/make/sun/management/Makefile index 6ae5d85d81751a29f7a612908afba149b4dc3d37..bb7ad8935c94fd655cf31e37293a7cfa485d2189 100644 --- a/make/sun/management/Makefile +++ b/make/sun/management/Makefile @@ -35,7 +35,16 @@ MGMT_LIB_SRC = $(SHARE_SRC)/lib/management all build:: properties aclfile jmxremotefiles -SUBDIRS = snmp jmxremote +# When building the openjdk, build snmp only if importing binary plugs, +ifdef OPENJDK + ifeq ($(IMPORT_BINARY_PLUGS),true) + SUBDIRS = snmp + endif +else + SUBDIRS = snmp +endif +SUBDIRS += jmxremote + all build clean clobber:: $(SUBDIRS-loop) diff --git a/make/sun/net/FILES_java.gmk b/make/sun/net/FILES_java.gmk index 55b6477fc26711e460bb82b9d3b7bd5cde767981..1ab771a37f10cbb53414f4d8ea8356e135fc776f 100644 --- a/make/sun/net/FILES_java.gmk +++ b/make/sun/net/FILES_java.gmk @@ -39,6 +39,7 @@ FILES_java = \ sun/net/TransferProtocolClient.java \ sun/net/ConnectionResetException.java \ sun/net/NetProperties.java \ + sun/net/NetHooks.java \ sun/net/util/IPAddressUtil.java \ sun/net/dns/ResolverConfiguration.java \ sun/net/dns/ResolverConfigurationImpl.java \ @@ -123,3 +124,7 @@ FILES_java = \ ifeq ($(PLATFORM), windows) FILES_java += sun/net/www/protocol/http/NTLMAuthSequence.java endif + +ifeq ($(PLATFORM), solaris) + FILES_java += sun/net/spi/SdpProvider.java +endif diff --git a/make/sun/xawt/mapfile-vers b/make/sun/xawt/mapfile-vers index 8aaaef7f260d60bf29113689b81fd5b0d37988bc..c117a0972687f07ac506c2c9a1a4cd608d25f210 100644 --- a/make/sun/xawt/mapfile-vers +++ b/make/sun/xawt/mapfile-vers @@ -318,12 +318,14 @@ SUNWprivate_1.1 { Java_java_awt_FileDialog_initIDs; Java_sun_awt_X11_XWindow_initIDs; + Java_sun_java2d_opengl_OGLContext_getOGLIdString; Java_sun_java2d_opengl_OGLMaskFill_maskFill; Java_sun_java2d_opengl_OGLRenderer_drawPoly; Java_sun_java2d_opengl_OGLRenderQueue_flushBuffer; Java_sun_java2d_opengl_OGLSurfaceData_initTexture; Java_sun_java2d_opengl_OGLSurfaceData_initFBObject; Java_sun_java2d_opengl_OGLSurfaceData_initFlipBackbuffer; + Java_sun_java2d_opengl_OGLSurfaceData_getTextureID; Java_sun_java2d_opengl_OGLSurfaceData_getTextureTarget; Java_sun_java2d_opengl_OGLTextRenderer_drawGlyphList; Java_sun_java2d_opengl_GLXGraphicsConfig_getGLXConfigInfo; diff --git a/make/tools/GenerateCharacter/CharacterData00.java.template b/make/tools/GenerateCharacter/CharacterData00.java.template index c790f374ef6710084913c2d1898614e548ac46c2..554c7cf57cb832595a6e6e992f37b52292282483 100644 --- a/make/tools/GenerateCharacter/CharacterData00.java.template +++ b/make/tools/GenerateCharacter/CharacterData00.java.template @@ -144,6 +144,55 @@ class CharacterData00 extends CharacterData { case 0x1FBC : mapChar = 0x1FB3; break; case 0x1FCC : mapChar = 0x1FC3; break; case 0x1FFC : mapChar = 0x1FF3; break; + + case 0x023A : mapChar = 0x2C65; break; + case 0x023E : mapChar = 0x2C66; break; + case 0x10A0 : mapChar = 0x2D00; break; + case 0x10A1 : mapChar = 0x2D01; break; + case 0x10A2 : mapChar = 0x2D02; break; + case 0x10A3 : mapChar = 0x2D03; break; + case 0x10A4 : mapChar = 0x2D04; break; + case 0x10A5 : mapChar = 0x2D05; break; + case 0x10A6 : mapChar = 0x2D06; break; + case 0x10A7 : mapChar = 0x2D07; break; + case 0x10A8 : mapChar = 0x2D08; break; + case 0x10A9 : mapChar = 0x2D09; break; + case 0x10AA : mapChar = 0x2D0A; break; + case 0x10AB : mapChar = 0x2D0B; break; + case 0x10AC : mapChar = 0x2D0C; break; + case 0x10AD : mapChar = 0x2D0D; break; + case 0x10AE : mapChar = 0x2D0E; break; + case 0x10AF : mapChar = 0x2D0F; break; + case 0x10B0 : mapChar = 0x2D10; break; + case 0x10B1 : mapChar = 0x2D11; break; + case 0x10B2 : mapChar = 0x2D12; break; + case 0x10B3 : mapChar = 0x2D13; break; + case 0x10B4 : mapChar = 0x2D14; break; + case 0x10B5 : mapChar = 0x2D15; break; + case 0x10B6 : mapChar = 0x2D16; break; + case 0x10B7 : mapChar = 0x2D17; break; + case 0x10B8 : mapChar = 0x2D18; break; + case 0x10B9 : mapChar = 0x2D19; break; + case 0x10BA : mapChar = 0x2D1A; break; + case 0x10BB : mapChar = 0x2D1B; break; + case 0x10BC : mapChar = 0x2D1C; break; + case 0x10BD : mapChar = 0x2D1D; break; + case 0x10BE : mapChar = 0x2D1E; break; + case 0x10BF : mapChar = 0x2D1F; break; + case 0x10C0 : mapChar = 0x2D20; break; + case 0x10C1 : mapChar = 0x2D21; break; + case 0x10C2 : mapChar = 0x2D22; break; + case 0x10C3 : mapChar = 0x2D23; break; + case 0x10C4 : mapChar = 0x2D24; break; + case 0x10C5 : mapChar = 0x2D25; break; + case 0x1E9E : mapChar = 0x00DF; break; + case 0x2C62 : mapChar = 0x026B; break; + case 0x2C63 : mapChar = 0x1D7D; break; + case 0x2C64 : mapChar = 0x027D; break; + case 0x2C6D : mapChar = 0x0251; break; + case 0x2C6E : mapChar = 0x0271; break; + case 0x2C6F : mapChar = 0x0250; break; + case 0xA77D : mapChar = 0x1D79; break; // default mapChar is already set, so no // need to redo it here. // default : mapChar = ch; @@ -196,6 +245,54 @@ class CharacterData00 extends CharacterData { case 0x1FB3 : mapChar = 0x1FBC; break; case 0x1FC3 : mapChar = 0x1FCC; break; case 0x1FF3 : mapChar = 0x1FFC; break; + + case 0x0250 : mapChar = 0x2C6F; break; + case 0x0251 : mapChar = 0x2C6D; break; + case 0x026B : mapChar = 0x2C62; break; + case 0x0271 : mapChar = 0x2C6E; break; + case 0x027D : mapChar = 0x2C64; break; + case 0x1D79 : mapChar = 0xA77D; break; + case 0x1D7D : mapChar = 0x2C63; break; + case 0x2C65 : mapChar = 0x023A; break; + case 0x2C66 : mapChar = 0x023E; break; + case 0x2D00 : mapChar = 0x10A0; break; + case 0x2D01 : mapChar = 0x10A1; break; + case 0x2D02 : mapChar = 0x10A2; break; + case 0x2D03 : mapChar = 0x10A3; break; + case 0x2D04 : mapChar = 0x10A4; break; + case 0x2D05 : mapChar = 0x10A5; break; + case 0x2D06 : mapChar = 0x10A6; break; + case 0x2D07 : mapChar = 0x10A7; break; + case 0x2D08 : mapChar = 0x10A8; break; + case 0x2D09 : mapChar = 0x10A9; break; + case 0x2D0A : mapChar = 0x10AA; break; + case 0x2D0B : mapChar = 0x10AB; break; + case 0x2D0C : mapChar = 0x10AC; break; + case 0x2D0D : mapChar = 0x10AD; break; + case 0x2D0E : mapChar = 0x10AE; break; + case 0x2D0F : mapChar = 0x10AF; break; + case 0x2D10 : mapChar = 0x10B0; break; + case 0x2D11 : mapChar = 0x10B1; break; + case 0x2D12 : mapChar = 0x10B2; break; + case 0x2D13 : mapChar = 0x10B3; break; + case 0x2D14 : mapChar = 0x10B4; break; + case 0x2D15 : mapChar = 0x10B5; break; + case 0x2D16 : mapChar = 0x10B6; break; + case 0x2D17 : mapChar = 0x10B7; break; + case 0x2D18 : mapChar = 0x10B8; break; + case 0x2D19 : mapChar = 0x10B9; break; + case 0x2D1A : mapChar = 0x10BA; break; + case 0x2D1B : mapChar = 0x10BB; break; + case 0x2D1C : mapChar = 0x10BC; break; + case 0x2D1D : mapChar = 0x10BD; break; + case 0x2D1E : mapChar = 0x10BE; break; + case 0x2D1F : mapChar = 0x10BF; break; + case 0x2D20 : mapChar = 0x10C0; break; + case 0x2D21 : mapChar = 0x10C1; break; + case 0x2D22 : mapChar = 0x10C2; break; + case 0x2D23 : mapChar = 0x10C3; break; + case 0x2D24 : mapChar = 0x10C4; break; + case 0x2D25 : mapChar = 0x10C5; break; // ch must have a 1:M case mapping, but we // can't handle it here. Return ch. // since mapChar is already set, no need @@ -315,6 +412,12 @@ class CharacterData00 extends CharacterData { case 0x32BE: retval = 49; break; // CIRCLED NUMBER FORTY NINE case 0x32BF: retval = 50; break; // CIRCLED NUMBER FIFTY + case 0x0D71: retval = 100; break; // MALAYALAM NUMBER ONE HUNDRED + case 0x0D72: retval = 1000; break; // MALAYALAM NUMBER ONE THOUSAND + case 0x2186: retval = 50; break; // ROMAN NUMERAL FIFTY EARLY FORM + case 0x2187: retval = 50000; break; // ROMAN NUMERAL FIFTY THOUSAND + case 0x2188: retval = 100000; break; // ROMAN NUMERAL ONE HUNDRED THOUSAND + default: retval = -2; break; } break; @@ -383,6 +486,54 @@ class CharacterData00 extends CharacterData { case 0x00B5 : mapChar = 0x039C; break; case 0x017F : mapChar = 0x0053; break; case 0x1FBE : mapChar = 0x0399; break; + + case 0x0250 : mapChar = 0x2C6F; break; + case 0x0251 : mapChar = 0x2C6D; break; + case 0x026B : mapChar = 0x2C62; break; + case 0x0271 : mapChar = 0x2C6E; break; + case 0x027D : mapChar = 0x2C64; break; + case 0x1D79 : mapChar = 0xA77D; break; + case 0x1D7D : mapChar = 0x2C63; break; + case 0x2C65 : mapChar = 0x023A; break; + case 0x2C66 : mapChar = 0x023E; break; + case 0x2D00 : mapChar = 0x10A0; break; + case 0x2D01 : mapChar = 0x10A1; break; + case 0x2D02 : mapChar = 0x10A2; break; + case 0x2D03 : mapChar = 0x10A3; break; + case 0x2D04 : mapChar = 0x10A4; break; + case 0x2D05 : mapChar = 0x10A5; break; + case 0x2D06 : mapChar = 0x10A6; break; + case 0x2D07 : mapChar = 0x10A7; break; + case 0x2D08 : mapChar = 0x10A8; break; + case 0x2D09 : mapChar = 0x10A9; break; + case 0x2D0A : mapChar = 0x10AA; break; + case 0x2D0B : mapChar = 0x10AB; break; + case 0x2D0C : mapChar = 0x10AC; break; + case 0x2D0D : mapChar = 0x10AD; break; + case 0x2D0E : mapChar = 0x10AE; break; + case 0x2D0F : mapChar = 0x10AF; break; + case 0x2D10 : mapChar = 0x10B0; break; + case 0x2D11 : mapChar = 0x10B1; break; + case 0x2D12 : mapChar = 0x10B2; break; + case 0x2D13 : mapChar = 0x10B3; break; + case 0x2D14 : mapChar = 0x10B4; break; + case 0x2D15 : mapChar = 0x10B5; break; + case 0x2D16 : mapChar = 0x10B6; break; + case 0x2D17 : mapChar = 0x10B7; break; + case 0x2D18 : mapChar = 0x10B8; break; + case 0x2D19 : mapChar = 0x10B9; break; + case 0x2D1A : mapChar = 0x10BA; break; + case 0x2D1B : mapChar = 0x10BB; break; + case 0x2D1C : mapChar = 0x10BC; break; + case 0x2D1D : mapChar = 0x10BD; break; + case 0x2D1E : mapChar = 0x10BE; break; + case 0x2D1F : mapChar = 0x10BF; break; + case 0x2D20 : mapChar = 0x10C0; break; + case 0x2D21 : mapChar = 0x10C1; break; + case 0x2D22 : mapChar = 0x10C2; break; + case 0x2D23 : mapChar = 0x10C3; break; + case 0x2D24 : mapChar = 0x10C4; break; + case 0x2D25 : mapChar = 0x10C5; break; default : mapChar = Character.ERROR; break; } } diff --git a/make/tools/GenerateCharacter/CharacterData01.java.template b/make/tools/GenerateCharacter/CharacterData01.java.template index 9a228b769c1a2744c013b23771dcbc4752cb6e90..c42f9807a18824eb1db1b06b4813fc537ed6c96f 100644 --- a/make/tools/GenerateCharacter/CharacterData01.java.template +++ b/make/tools/GenerateCharacter/CharacterData01.java.template @@ -218,6 +218,48 @@ class CharacterData01 extends CharacterData { case 0x10132: retval = 80000; break; // AEGEAN NUMBER EIGHTY THOUSAND case 0x10133: retval = 90000; break; // AEGEAN NUMBER NINETY THOUSAND case 0x10323: retval = 50; break; // OLD ITALIC NUMERAL FIFTY + + case 0x010144: retval = 50; break; // ACROPHONIC ATTIC FIFTY + case 0x010145: retval = 500; break; // ACROPHONIC ATTIC FIVE HUNDRED + case 0x010146: retval = 5000; break; // ACROPHONIC ATTIC FIVE THOUSAND + case 0x010147: retval = 50000; break; // ACROPHONIC ATTIC FIFTY THOUSAND + case 0x01014A: retval = 50; break; // ACROPHONIC ATTIC FIFTY TALENTS + case 0x01014B: retval = 100; break; // ACROPHONIC ATTIC ONE HUNDRED TALENTS + case 0x01014C: retval = 500; break; // ACROPHONIC ATTIC FIVE HUNDRED TALENTS + case 0x01014D: retval = 1000; break; // ACROPHONIC ATTIC ONE THOUSAND TALENTS + case 0x01014E: retval = 5000; break; // ACROPHONIC ATTIC FIVE THOUSAND TALENTS + case 0x010151: retval = 50; break; // ACROPHONIC ATTIC FIFTY STATERS + case 0x010152: retval = 100; break; // ACROPHONIC ATTIC ONE HUNDRED STATERS + case 0x010153: retval = 500; break; // ACROPHONIC ATTIC FIVE HUNDRED STATERS + case 0x010154: retval = 1000; break; // ACROPHONIC ATTIC ONE THOUSAND STATERS + case 0x010155: retval = 10000; break; // ACROPHONIC ATTIC TEN THOUSAND STATERS + case 0x010156: retval = 50000; break; // ACROPHONIC ATTIC FIFTY THOUSAND STATERS + case 0x010166: retval = 50; break; // ACROPHONIC TROEZENIAN FIFTY + case 0x010167: retval = 50; break; // ACROPHONIC TROEZENIAN FIFTY ALTERNATE FORM + case 0x010168: retval = 50; break; // ACROPHONIC HERMIONIAN FIFTY + case 0x010169: retval = 50; break; // ACROPHONIC THESPIAN FIFTY + case 0x01016A: retval = 100; break; // ACROPHONIC THESPIAN ONE HUNDRED + case 0x01016B: retval = 300; break; // ACROPHONIC THESPIAN THREE HUNDRED + case 0x01016C: retval = 500; break; // ACROPHONIC EPIDAUREAN FIVE HUNDRED + case 0x01016D: retval = 500; break; // ACROPHONIC TROEZENIAN FIVE HUNDRED + case 0x01016E: retval = 500; break; // ACROPHONIC THESPIAN FIVE HUNDRED + case 0x01016F: retval = 500; break; // ACROPHONIC CARYSTIAN FIVE HUNDRED + case 0x010170: retval = 500; break; // ACROPHONIC NAXIAN FIVE HUNDRED + case 0x010171: retval = 1000; break; // ACROPHONIC THESPIAN ONE THOUSAND + case 0x010172: retval = 5000; break; // ACROPHONIC THESPIAN FIVE THOUSAND + case 0x010174: retval = 50; break; // ACROPHONIC STRATIAN FIFTY MNAS + case 0x010341: retval = 90; break; // GOTHIC LETTER NINETY + case 0x01034A: retval = 900; break; // GOTHIC LETTER NINE HUNDRED + case 0x0103D5: retval = 100; break; // OLD PERSIAN NUMBER HUNDRED + case 0x010919: retval = 100; break; // PHOENICIAN NUMBER ONE HUNDRED + case 0x010A46: retval = 100; break; // KHAROSHTHI NUMBER ONE HUNDRED + case 0x010A47: retval = 1000; break; // KHAROSHTHI NUMBER ONE THOUSAND + case 0x01D36C: retval = 40; break; // COUNTING ROD TENS DIGIT FOUR + case 0x01D36D: retval = 50; break; // COUNTING ROD TENS DIGIT FIVE + case 0x01D36E: retval = 60; break; // COUNTING ROD TENS DIGIT SIX + case 0x01D36F: retval = 70; break; // COUNTING ROD TENS DIGIT SEVEN + case 0x01D370: retval = 80; break; // COUNTING ROD TENS DIGIT EIGHT + case 0x01D371: retval = 90; break; // COUNTING ROD TENS DIGIT NINE default: retval = -2; break; } diff --git a/make/tools/UnicodeData/SpecialCasing.txt b/make/tools/UnicodeData/SpecialCasing.txt index 34d1c61de37ea47eb7a43bd6b8aae8c93b4bc87b..92e70a4a3d23c1d6533d33e1920c29f40ba84d20 100644 --- a/make/tools/UnicodeData/SpecialCasing.txt +++ b/make/tools/UnicodeData/SpecialCasing.txt @@ -1,12 +1,17 @@ -# SpecialCasing-4.0.0.txt -# Date: 2003-03-14, 20:22:04 GMT [MD] +# SpecialCasing-5.1.0.txt +# Date: 2008-03-03, 21:58:10 GMT [MD] +# +# Unicode Character Database +# Copyright (c) 1991-2008 Unicode, Inc. +# For terms of use, see http://www.unicode.org/terms_of_use.html +# For documentation, see UCD.html # # Special Casing Properties # # This file is a supplement to the UnicodeData file. # It contains additional information about the casing of Unicode characters. # (For compatibility, the UnicodeData.txt file only contains case mappings for -# characters where they are 1-1, and does not have locale-specific mappings.) +# characters where they are 1-1, and independent of context and language. # For more information, see the discussion of Case Mappings in the Unicode Standard. # # All code points not listed in this file that do not have a simple case mappings @@ -18,31 +23,31 @@ # # ; ; ; <upper> ; (<condition_list> ;)? # <comment> # -# <code>, <lower>, <title>, and <upper> provide character values in hex. If there is more than -# one character, they are separated by spaces. Other than as used to separate elements, -# spaces are to be ignored. +# <code>, <lower>, <title>, and <upper> provide character values in hex. If there is more +# than one character, they are separated by spaces. Other than as used to separate +# elements, spaces are to be ignored. # -# The <condition_list> is optional. Where present, it consists of one or more locales or contexts, -# separated by spaces. In these conditions: +# The <condition_list> is optional. Where present, it consists of one or more language IDs +# or contexts, separated by spaces. In these conditions: # - A condition list overrides the normal behavior if all of the listed conditions are true. # - The context is always the context of the characters in the original string, # NOT in the resulting string. # - Case distinctions in the condition list are not significant. # - Conditions preceded by "Not_" represent the negation of the condition. +# The condition list is not represented in the UCD as a formal property. # -# A locale is defined as: -# <locale> := <ISO_639_code> ( "_" <ISO_3166_code> ( "_" <variant> )? )? -# <ISO_3166_code> := 2-letter ISO country code, -# <ISO_639_code> := 2-letter ISO language code +# A language ID is defined by BCP 47, with '-' and '_' treated equivalently. # -# A context is one of the following, as defined in the Unicode Standard: -# Final_Sigma, After_Soft_Dotted, More_Above, Before_Dot, Not_Before_Dot, After_I +# A context for a character C is defined by Section 3.13 Default Case +# Operations, of The Unicode Standard, Version 5.0. +# (This is identical to the context defined by Unicode 4.1.0, +# as specified in http://www.unicode.org/versions/Unicode4.1.0/) # # Parsers of this file must be prepared to deal with future additions to this format: # * Additional contexts # * Additional fields # ================================================================================ - +# @missing 0000..10FFFF; <slc>; <stc>; <suc> # ================================================================================ # Unconditional mappings # ================================================================================ @@ -170,7 +175,7 @@ FB17; FB17; 0544 056D; 0544 053D; # ARMENIAN SMALL LIGATURE MEN XEH 1FF3; 1FF3; 1FFC; 03A9 0399; # GREEK SMALL LETTER OMEGA WITH YPOGEGRAMMENI 1FFC; 1FF3; 1FFC; 03A9 0399; # GREEK CAPITAL LETTER OMEGA WITH PROSGEGRAMMENI -# Some characters with YPOGEGRAMMENI are also have no corresponding titlecases +# Some characters with YPOGEGRAMMENI also have no corresponding titlecases 1FB2; 1FB2; 1FBA 0345; 1FBA 0399; # GREEK SMALL LETTER ALPHA WITH VARIA AND YPOGEGRAMMENI 1FB4; 1FB4; 0386 0345; 0386 0399; # GREEK SMALL LETTER ALPHA WITH OXIA AND YPOGEGRAMMENI @@ -184,7 +189,14 @@ FB17; FB17; 0544 056D; 0544 053D; # ARMENIAN SMALL LIGATURE MEN XEH 1FF7; 1FF7; 03A9 0342 0345; 03A9 0342 0399; # GREEK SMALL LETTER OMEGA WITH PERISPOMENI AND YPOGEGRAMMENI # ================================================================================ -# Conditional mappings +# Conditional Mappings +# The remainder of this file provides conditional casing data used to produce +# full case mappings. +# ================================================================================ +# Language-Insensitive Mappings +# These are characters whose full case mappings do not depend on language, but do +# depend on context (which characters come before or after). For more information +# see the header of this file and the Unicode Standard. # ================================================================================ # Special case for final form of sigma @@ -203,7 +215,10 @@ FB17; FB17; 0544 056D; 0544 053D; # ARMENIAN SMALL LIGATURE MEN XEH # 03C2; 03C3; 03A3; 03A3; Not_Final_Sigma; # GREEK SMALL LETTER FINAL SIGMA # ================================================================================ -# Locale-sensitive mappings +# Language-Sensitive Mappings +# These are characters whose full case mappings depend on language and perhaps also +# context (which characters come before or after). For more information +# see the header of this file and the Unicode Standard. # ================================================================================ # Lithuanian @@ -254,3 +269,6 @@ FB17; FB17; 0544 056D; 0544 053D; # ARMENIAN SMALL LIGATURE MEN XEH # Note: the following case is already in the UnicodeData file. # 0131; 0131; 0049; 0049; tr; # LATIN SMALL LETTER DOTLESS I + +# EOF + diff --git a/make/tools/UnicodeData/UnicodeData.txt b/make/tools/UnicodeData/UnicodeData.txt index 86ea1cf9f684cca1f8d2690f1462a9aba177ba37..77db788cf29cb4a124bde6606f479f70d97b91af 100644 --- a/make/tools/UnicodeData/UnicodeData.txt +++ b/make/tools/UnicodeData/UnicodeData.txt @@ -41,11 +41,11 @@ 0028;LEFT PARENTHESIS;Ps;0;ON;;;;;Y;OPENING PARENTHESIS;;;; 0029;RIGHT PARENTHESIS;Pe;0;ON;;;;;Y;CLOSING PARENTHESIS;;;; 002A;ASTERISK;Po;0;ON;;;;;N;;;;; -002B;PLUS SIGN;Sm;0;ET;;;;;N;;;;; +002B;PLUS SIGN;Sm;0;ES;;;;;N;;;;; 002C;COMMA;Po;0;CS;;;;;N;;;;; -002D;HYPHEN-MINUS;Pd;0;ET;;;;;N;;;;; +002D;HYPHEN-MINUS;Pd;0;ES;;;;;N;;;;; 002E;FULL STOP;Po;0;CS;;;;;N;PERIOD;;;; -002F;SOLIDUS;Po;0;ES;;;;;N;SLASH;;;; +002F;SOLIDUS;Po;0;CS;;;;;N;SLASH;;;; 0030;DIGIT ZERO;Nd;0;EN;;0;0;0;N;;;;; 0031;DIGIT ONE;Nd;0;EN;;1;1;1;N;;;;; 0032;DIGIT TWO;Nd;0;EN;;2;2;2;N;;;;; @@ -171,7 +171,7 @@ 00AA;FEMININE ORDINAL INDICATOR;Ll;0;L;<super> 0061;;;;N;;;;; 00AB;LEFT-POINTING DOUBLE ANGLE QUOTATION MARK;Pi;0;ON;;;;;Y;LEFT POINTING GUILLEMET;*;;; 00AC;NOT SIGN;Sm;0;ON;;;;;N;;;;; -00AD;SOFT HYPHEN;Cf;0;ON;;;;;N;;;;; +00AD;SOFT HYPHEN;Cf;0;BN;;;;;N;;;;; 00AE;REGISTERED SIGN;So;0;ON;;;;;N;REGISTERED TRADE MARK SIGN;;;; 00AF;MACRON;Sk;0;ON;<compat> 0020 0304;;;;N;SPACING MACRON;;;; 00B0;DEGREE SIGN;So;0;ET;;;;;N;;;;; @@ -382,7 +382,7 @@ 017D;LATIN CAPITAL LETTER Z WITH CARON;Lu;0;L;005A 030C;;;;N;LATIN CAPITAL LETTER Z HACEK;;;017E; 017E;LATIN SMALL LETTER Z WITH CARON;Ll;0;L;007A 030C;;;;N;LATIN SMALL LETTER Z HACEK;;017D;;017D 017F;LATIN SMALL LETTER LONG S;Ll;0;L;<compat> 0073;;;;N;;;0053;;0053 -0180;LATIN SMALL LETTER B WITH STROKE;Ll;0;L;;;;;N;LATIN SMALL LETTER B BAR;;;; +0180;LATIN SMALL LETTER B WITH STROKE;Ll;0;L;;;;;N;LATIN SMALL LETTER B BAR;;0243;;0243 0181;LATIN CAPITAL LETTER B WITH HOOK;Lu;0;L;;;;;N;LATIN CAPITAL LETTER B HOOK;;;0253; 0182;LATIN CAPITAL LETTER B WITH TOPBAR;Lu;0;L;;;;;N;LATIN CAPITAL LETTER B TOPBAR;;;0183; 0183;LATIN SMALL LETTER B WITH TOPBAR;Ll;0;L;;;;;N;LATIN SMALL LETTER B TOPBAR;;0182;;0182 @@ -408,7 +408,7 @@ 0197;LATIN CAPITAL LETTER I WITH STROKE;Lu;0;L;;;;;N;LATIN CAPITAL LETTER BARRED I;;;0268; 0198;LATIN CAPITAL LETTER K WITH HOOK;Lu;0;L;;;;;N;LATIN CAPITAL LETTER K HOOK;;;0199; 0199;LATIN SMALL LETTER K WITH HOOK;Ll;0;L;;;;;N;LATIN SMALL LETTER K HOOK;;0198;;0198 -019A;LATIN SMALL LETTER L WITH BAR;Ll;0;L;;;;;N;LATIN SMALL LETTER BARRED L;;;; +019A;LATIN SMALL LETTER L WITH BAR;Ll;0;L;;;;;N;LATIN SMALL LETTER BARRED L;;023D;;023D 019B;LATIN SMALL LETTER LAMBDA WITH STROKE;Ll;0;L;;;;;N;LATIN SMALL LETTER BARRED LAMBDA;;;; 019C;LATIN CAPITAL LETTER TURNED M;Lu;0;L;;;;;N;;;;026F; 019D;LATIN CAPITAL LETTER N WITH LEFT HOOK;Lu;0;L;;;;;N;LATIN CAPITAL LETTER N HOOK;;;0272; @@ -565,8 +565,33 @@ 0234;LATIN SMALL LETTER L WITH CURL;Ll;0;L;;;;;N;;;;; 0235;LATIN SMALL LETTER N WITH CURL;Ll;0;L;;;;;N;;;;; 0236;LATIN SMALL LETTER T WITH CURL;Ll;0;L;;;;;N;;;;; -0250;LATIN SMALL LETTER TURNED A;Ll;0;L;;;;;N;;;;; -0251;LATIN SMALL LETTER ALPHA;Ll;0;L;;;;;N;LATIN SMALL LETTER SCRIPT A;;;; +0237;LATIN SMALL LETTER DOTLESS J;Ll;0;L;;;;;N;;;;; +0238;LATIN SMALL LETTER DB DIGRAPH;Ll;0;L;;;;;N;;;;; +0239;LATIN SMALL LETTER QP DIGRAPH;Ll;0;L;;;;;N;;;;; +023A;LATIN CAPITAL LETTER A WITH STROKE;Lu;0;L;;;;;N;;;;2C65; +023B;LATIN CAPITAL LETTER C WITH STROKE;Lu;0;L;;;;;N;;;;023C; +023C;LATIN SMALL LETTER C WITH STROKE;Ll;0;L;;;;;N;;;023B;;023B +023D;LATIN CAPITAL LETTER L WITH BAR;Lu;0;L;;;;;N;;;;019A; +023E;LATIN CAPITAL LETTER T WITH DIAGONAL STROKE;Lu;0;L;;;;;N;;;;2C66; +023F;LATIN SMALL LETTER S WITH SWASH TAIL;Ll;0;L;;;;;N;;;;; +0240;LATIN SMALL LETTER Z WITH SWASH TAIL;Ll;0;L;;;;;N;;;;; +0241;LATIN CAPITAL LETTER GLOTTAL STOP;Lu;0;L;;;;;N;;;;0242; +0242;LATIN SMALL LETTER GLOTTAL STOP;Ll;0;L;;;;;N;;;0241;;0241 +0243;LATIN CAPITAL LETTER B WITH STROKE;Lu;0;L;;;;;N;;;;0180; +0244;LATIN CAPITAL LETTER U BAR;Lu;0;L;;;;;N;;;;0289; +0245;LATIN CAPITAL LETTER TURNED V;Lu;0;L;;;;;N;;;;028C; +0246;LATIN CAPITAL LETTER E WITH STROKE;Lu;0;L;;;;;N;;;;0247; +0247;LATIN SMALL LETTER E WITH STROKE;Ll;0;L;;;;;N;;;0246;;0246 +0248;LATIN CAPITAL LETTER J WITH STROKE;Lu;0;L;;;;;N;;;;0249; +0249;LATIN SMALL LETTER J WITH STROKE;Ll;0;L;;;;;N;;;0248;;0248 +024A;LATIN CAPITAL LETTER SMALL Q WITH HOOK TAIL;Lu;0;L;;;;;N;;;;024B; +024B;LATIN SMALL LETTER Q WITH HOOK TAIL;Ll;0;L;;;;;N;;;024A;;024A +024C;LATIN CAPITAL LETTER R WITH STROKE;Lu;0;L;;;;;N;;;;024D; +024D;LATIN SMALL LETTER R WITH STROKE;Ll;0;L;;;;;N;;;024C;;024C +024E;LATIN CAPITAL LETTER Y WITH STROKE;Lu;0;L;;;;;N;;;;024F; +024F;LATIN SMALL LETTER Y WITH STROKE;Ll;0;L;;;;;N;;;024E;;024E +0250;LATIN SMALL LETTER TURNED A;Ll;0;L;;;;;N;;;2C6F;;2C6F +0251;LATIN SMALL LETTER ALPHA;Ll;0;L;;;;;N;LATIN SMALL LETTER SCRIPT A;;2C6D;;2C6D 0252;LATIN SMALL LETTER TURNED ALPHA;Ll;0;L;;;;;N;LATIN SMALL LETTER TURNED SCRIPT A;;;; 0253;LATIN SMALL LETTER B WITH HOOK;Ll;0;L;;;;;N;LATIN SMALL LETTER B HOOK;;0181;;0181 0254;LATIN SMALL LETTER OPEN O;Ll;0;L;;;;;N;;;0186;;0186 @@ -592,13 +617,13 @@ 0268;LATIN SMALL LETTER I WITH STROKE;Ll;0;L;;;;;N;LATIN SMALL LETTER BARRED I;;0197;;0197 0269;LATIN SMALL LETTER IOTA;Ll;0;L;;;;;N;;;0196;;0196 026A;LATIN LETTER SMALL CAPITAL I;Ll;0;L;;;;;N;;;;; -026B;LATIN SMALL LETTER L WITH MIDDLE TILDE;Ll;0;L;;;;;N;;;;; +026B;LATIN SMALL LETTER L WITH MIDDLE TILDE;Ll;0;L;;;;;N;;;2C62;;2C62 026C;LATIN SMALL LETTER L WITH BELT;Ll;0;L;;;;;N;LATIN SMALL LETTER L BELT;;;; 026D;LATIN SMALL LETTER L WITH RETROFLEX HOOK;Ll;0;L;;;;;N;LATIN SMALL LETTER L RETROFLEX HOOK;;;; 026E;LATIN SMALL LETTER LEZH;Ll;0;L;;;;;N;LATIN SMALL LETTER L YOGH;;;; 026F;LATIN SMALL LETTER TURNED M;Ll;0;L;;;;;N;;;019C;;019C 0270;LATIN SMALL LETTER TURNED M WITH LONG LEG;Ll;0;L;;;;;N;;;;; -0271;LATIN SMALL LETTER M WITH HOOK;Ll;0;L;;;;;N;LATIN SMALL LETTER M HOOK;;;; +0271;LATIN SMALL LETTER M WITH HOOK;Ll;0;L;;;;;N;LATIN SMALL LETTER M HOOK;;2C6E;;2C6E 0272;LATIN SMALL LETTER N WITH LEFT HOOK;Ll;0;L;;;;;N;LATIN SMALL LETTER N HOOK;;019D;;019D 0273;LATIN SMALL LETTER N WITH RETROFLEX HOOK;Ll;0;L;;;;;N;LATIN SMALL LETTER N RETROFLEX HOOK;;;; 0274;LATIN LETTER SMALL CAPITAL N;Ll;0;L;;;;;N;;;;; @@ -610,7 +635,7 @@ 027A;LATIN SMALL LETTER TURNED R WITH LONG LEG;Ll;0;L;;;;;N;;;;; 027B;LATIN SMALL LETTER TURNED R WITH HOOK;Ll;0;L;;;;;N;LATIN SMALL LETTER TURNED R HOOK;;;; 027C;LATIN SMALL LETTER R WITH LONG LEG;Ll;0;L;;;;;N;;;;; -027D;LATIN SMALL LETTER R WITH TAIL;Ll;0;L;;;;;N;LATIN SMALL LETTER R HOOK;;;; +027D;LATIN SMALL LETTER R WITH TAIL;Ll;0;L;;;;;N;LATIN SMALL LETTER R HOOK;;2C64;;2C64 027E;LATIN SMALL LETTER R WITH FISHHOOK;Ll;0;L;;;;;N;LATIN SMALL LETTER FISHHOOK R;;;; 027F;LATIN SMALL LETTER REVERSED R WITH FISHHOOK;Ll;0;L;;;;;N;LATIN SMALL LETTER REVERSED FISHHOOK R;;;; 0280;LATIN LETTER SMALL CAPITAL R;Ll;0;L;;;;;N;;*;01A6;;01A6 @@ -622,10 +647,10 @@ 0286;LATIN SMALL LETTER ESH WITH CURL;Ll;0;L;;;;;N;LATIN SMALL LETTER ESH CURL;;;; 0287;LATIN SMALL LETTER TURNED T;Ll;0;L;;;;;N;;;;; 0288;LATIN SMALL LETTER T WITH RETROFLEX HOOK;Ll;0;L;;;;;N;LATIN SMALL LETTER T RETROFLEX HOOK;;01AE;;01AE -0289;LATIN SMALL LETTER U BAR;Ll;0;L;;;;;N;;;;; +0289;LATIN SMALL LETTER U BAR;Ll;0;L;;;;;N;;;0244;;0244 028A;LATIN SMALL LETTER UPSILON;Ll;0;L;;;;;N;;;01B1;;01B1 028B;LATIN SMALL LETTER V WITH HOOK;Ll;0;L;;;;;N;LATIN SMALL LETTER SCRIPT V;;01B2;;01B2 -028C;LATIN SMALL LETTER TURNED V;Ll;0;L;;;;;N;;;;; +028C;LATIN SMALL LETTER TURNED V;Ll;0;L;;;;;N;;;0245;;0245 028D;LATIN SMALL LETTER TURNED W;Ll;0;L;;;;;N;;;;; 028E;LATIN SMALL LETTER TURNED Y;Ll;0;L;;;;;N;;;;; 028F;LATIN LETTER SMALL CAPITAL Y;Ll;0;L;;;;;N;;;;; @@ -633,7 +658,7 @@ 0291;LATIN SMALL LETTER Z WITH CURL;Ll;0;L;;;;;N;LATIN SMALL LETTER Z CURL;;;; 0292;LATIN SMALL LETTER EZH;Ll;0;L;;;;;N;LATIN SMALL LETTER YOGH;;01B7;;01B7 0293;LATIN SMALL LETTER EZH WITH CURL;Ll;0;L;;;;;N;LATIN SMALL LETTER YOGH CURL;;;; -0294;LATIN LETTER GLOTTAL STOP;Ll;0;L;;;;;N;;;;; +0294;LATIN LETTER GLOTTAL STOP;Lo;0;L;;;;;N;;;;; 0295;LATIN LETTER PHARYNGEAL VOICED FRICATIVE;Ll;0;L;;;;;N;LATIN LETTER REVERSED GLOTTAL STOP;;;; 0296;LATIN LETTER INVERTED GLOTTAL STOP;Ll;0;L;;;;;N;;;;; 0297;LATIN LETTER STRETCHED C;Ll;0;L;;;;;N;;;;; @@ -659,7 +684,7 @@ 02AB;LATIN SMALL LETTER LZ DIGRAPH;Ll;0;L;;;;;N;;;;; 02AC;LATIN LETTER BILABIAL PERCUSSIVE;Ll;0;L;;;;;N;;;;; 02AD;LATIN LETTER BIDENTAL PERCUSSIVE;Ll;0;L;;;;;N;;;;; -02AE;LATIN SMALL LETTER TURNED H WITH FISHHOOK ;Ll;0;L;;;;;N;;;;; +02AE;LATIN SMALL LETTER TURNED H WITH FISHHOOK;Ll;0;L;;;;;N;;;;; 02AF;LATIN SMALL LETTER TURNED H WITH FISHHOOK AND TAIL;Ll;0;L;;;;;N;;;;; 02B0;MODIFIER LETTER SMALL H;Lm;0;L;<super> 0068;;;;N;;;;; 02B1;MODIFIER LETTER SMALL H WITH HOOK;Lm;0;L;<super> 0266;;;;N;MODIFIER LETTER SMALL H HOOK;;;; @@ -721,7 +746,7 @@ 02E9;MODIFIER LETTER EXTRA-LOW TONE BAR;Sk;0;ON;;;;;N;;;;; 02EA;MODIFIER LETTER YIN DEPARTING TONE MARK;Sk;0;ON;;;;;N;;;;; 02EB;MODIFIER LETTER YANG DEPARTING TONE MARK;Sk;0;ON;;;;;N;;;;; -02EC;MODIFIER LETTER VOICING;Sk;0;ON;;;;;N;;;;; +02EC;MODIFIER LETTER VOICING;Lm;0;ON;;;;;N;;;;; 02ED;MODIFIER LETTER UNASPIRATED;Sk;0;ON;;;;;N;;;;; 02EE;MODIFIER LETTER DOUBLE APOSTROPHE;Lm;0;L;;;;;N;;;;; 02EF;MODIFIER LETTER LOW DOWN ARROWHEAD;Sk;0;ON;;;;;N;;;;; @@ -829,6 +854,11 @@ 0355;COMBINING RIGHT ARROWHEAD BELOW;Mn;220;NSM;;;;;N;;;;; 0356;COMBINING RIGHT ARROWHEAD AND UP ARROWHEAD BELOW;Mn;220;NSM;;;;;N;;;;; 0357;COMBINING RIGHT HALF RING ABOVE;Mn;230;NSM;;;;;N;;;;; +0358;COMBINING DOT ABOVE RIGHT;Mn;232;NSM;;;;;N;;;;; +0359;COMBINING ASTERISK BELOW;Mn;220;NSM;;;;;N;;;;; +035A;COMBINING DOUBLE RING BELOW;Mn;220;NSM;;;;;N;;;;; +035B;COMBINING ZIGZAG ABOVE;Mn;230;NSM;;;;;N;;;;; +035C;COMBINING DOUBLE BREVE BELOW;Mn;233;NSM;;;;;N;;;;; 035D;COMBINING DOUBLE BREVE;Mn;234;NSM;;;;;N;;;;; 035E;COMBINING DOUBLE MACRON;Mn;234;NSM;;;;;N;;;;; 035F;COMBINING DOUBLE MACRON BELOW;Mn;233;NSM;;;;;N;;;;; @@ -848,9 +878,18 @@ 036D;COMBINING LATIN SMALL LETTER T;Mn;230;NSM;;;;;N;;;;; 036E;COMBINING LATIN SMALL LETTER V;Mn;230;NSM;;;;;N;;;;; 036F;COMBINING LATIN SMALL LETTER X;Mn;230;NSM;;;;;N;;;;; -0374;GREEK NUMERAL SIGN;Sk;0;ON;02B9;;;;N;GREEK UPPER NUMERAL SIGN;Dexia keraia;;; +0370;GREEK CAPITAL LETTER HETA;Lu;0;L;;;;;N;;;;0371; +0371;GREEK SMALL LETTER HETA;Ll;0;L;;;;;N;;;0370;;0370 +0372;GREEK CAPITAL LETTER ARCHAIC SAMPI;Lu;0;L;;;;;N;;;;0373; +0373;GREEK SMALL LETTER ARCHAIC SAMPI;Ll;0;L;;;;;N;;;0372;;0372 +0374;GREEK NUMERAL SIGN;Lm;0;ON;02B9;;;;N;GREEK UPPER NUMERAL SIGN;Dexia keraia;;; 0375;GREEK LOWER NUMERAL SIGN;Sk;0;ON;;;;;N;;Aristeri keraia;;; +0376;GREEK CAPITAL LETTER PAMPHYLIAN DIGAMMA;Lu;0;L;;;;;N;;;;0377; +0377;GREEK SMALL LETTER PAMPHYLIAN DIGAMMA;Ll;0;L;;;;;N;;;0376;;0376 037A;GREEK YPOGEGRAMMENI;Lm;0;L;<compat> 0020 0345;;;;N;GREEK SPACING IOTA BELOW;;;; +037B;GREEK SMALL REVERSED LUNATE SIGMA SYMBOL;Ll;0;L;;;;;N;;;03FD;;03FD +037C;GREEK SMALL DOTTED LUNATE SIGMA SYMBOL;Ll;0;L;;;;;N;;;03FE;;03FE +037D;GREEK SMALL REVERSED DOTTED LUNATE SIGMA SYMBOL;Ll;0;L;;;;;N;;;03FF;;03FF 037E;GREEK QUESTION MARK;Po;0;ON;003B;;;;N;;Erotimatiko;;; 0384;GREEK TONOS;Sk;0;ON;<compat> 0020 0301;;;;N;GREEK SPACING TONOS;;;; 0385;GREEK DIALYTIKA TONOS;Sk;0;ON;00A8 0301;;;;N;GREEK SPACING DIAERESIS TONOS;;;; @@ -924,6 +963,7 @@ 03CC;GREEK SMALL LETTER OMICRON WITH TONOS;Ll;0;L;03BF 0301;;;;N;GREEK SMALL LETTER OMICRON TONOS;;038C;;038C 03CD;GREEK SMALL LETTER UPSILON WITH TONOS;Ll;0;L;03C5 0301;;;;N;GREEK SMALL LETTER UPSILON TONOS;;038E;;038E 03CE;GREEK SMALL LETTER OMEGA WITH TONOS;Ll;0;L;03C9 0301;;;;N;GREEK SMALL LETTER OMEGA TONOS;;038F;;038F +03CF;GREEK CAPITAL KAI SYMBOL;Lu;0;L;;;;;N;;;;03D7; 03D0;GREEK BETA SYMBOL;Ll;0;L;<compat> 03B2;;;;N;GREEK SMALL LETTER CURLED BETA;;0392;;0392 03D1;GREEK THETA SYMBOL;Ll;0;L;<compat> 03B8;;;;N;GREEK SMALL LETTER SCRIPT THETA;;0398;;0398 03D2;GREEK UPSILON WITH HOOK SYMBOL;Lu;0;L;<compat> 03A5;;;;N;GREEK CAPITAL LETTER UPSILON HOOK;;;; @@ -931,7 +971,7 @@ 03D4;GREEK UPSILON WITH DIAERESIS AND HOOK SYMBOL;Lu;0;L;03D2 0308;;;;N;GREEK CAPITAL LETTER UPSILON HOOK DIAERESIS;;;; 03D5;GREEK PHI SYMBOL;Ll;0;L;<compat> 03C6;;;;N;GREEK SMALL LETTER SCRIPT PHI;;03A6;;03A6 03D6;GREEK PI SYMBOL;Ll;0;L;<compat> 03C0;;;;N;GREEK SMALL LETTER OMEGA PI;;03A0;;03A0 -03D7;GREEK KAI SYMBOL;Ll;0;L;;;;;N;;;;; +03D7;GREEK KAI SYMBOL;Ll;0;L;;;;;N;;;03CF;;03CF 03D8;GREEK LETTER ARCHAIC KOPPA;Lu;0;L;;;;;N;;*;;03D9; 03D9;GREEK SMALL LETTER ARCHAIC KOPPA;Ll;0;L;;;;;N;;*;03D8;;03D8 03DA;GREEK LETTER STIGMA;Lu;0;L;;;;;N;GREEK CAPITAL LETTER STIGMA;;;03DB; @@ -968,6 +1008,10 @@ 03F9;GREEK CAPITAL LUNATE SIGMA SYMBOL;Lu;0;L;<compat> 03A3;;;;N;;;;03F2; 03FA;GREEK CAPITAL LETTER SAN;Lu;0;L;;;;;N;;;;03FB; 03FB;GREEK SMALL LETTER SAN;Ll;0;L;;;;;N;;;03FA;;03FA +03FC;GREEK RHO WITH STROKE SYMBOL;Ll;0;L;;;;;N;;;;; +03FD;GREEK CAPITAL REVERSED LUNATE SIGMA SYMBOL;Lu;0;L;;;;;N;;;;037B; +03FE;GREEK CAPITAL DOTTED LUNATE SIGMA SYMBOL;Lu;0;L;;;;;N;;;;037C; +03FF;GREEK CAPITAL REVERSED DOTTED LUNATE SIGMA SYMBOL;Lu;0;L;;;;;N;;;;037D; 0400;CYRILLIC CAPITAL LETTER IE WITH GRAVE;Lu;0;L;0415 0300;;;;N;;;;0450; 0401;CYRILLIC CAPITAL LETTER IO;Lu;0;L;0415 0308;;;;N;;;;0451; 0402;CYRILLIC CAPITAL LETTER DJE;Lu;0;L;;;;;N;;Serbocroatian;;0452; @@ -1103,6 +1147,7 @@ 0484;COMBINING CYRILLIC PALATALIZATION;Mn;230;NSM;;;;;N;CYRILLIC NON-SPACING PALATALIZATION;;;; 0485;COMBINING CYRILLIC DASIA PNEUMATA;Mn;230;NSM;;;;;N;CYRILLIC NON-SPACING DASIA PNEUMATA;;;; 0486;COMBINING CYRILLIC PSILI PNEUMATA;Mn;230;NSM;;;;;N;CYRILLIC NON-SPACING PSILI PNEUMATA;;;; +0487;COMBINING CYRILLIC POKRYTIE;Mn;230;NSM;;;;;N;;;;; 0488;COMBINING CYRILLIC HUNDRED THOUSANDS SIGN;Me;0;NSM;;;;;N;;;;; 0489;COMBINING CYRILLIC MILLIONS SIGN;Me;0;NSM;;;;;N;;;;; 048A;CYRILLIC CAPITAL LETTER SHORT I WITH TAIL;Lu;0;L;;;;;N;;;;048B; @@ -1159,7 +1204,7 @@ 04BD;CYRILLIC SMALL LETTER ABKHASIAN CHE;Ll;0;L;;;;;N;CYRILLIC SMALL LETTER IE HOOK;;04BC;;04BC 04BE;CYRILLIC CAPITAL LETTER ABKHASIAN CHE WITH DESCENDER;Lu;0;L;;;;;N;CYRILLIC CAPITAL LETTER IE HOOK OGONEK;;;04BF; 04BF;CYRILLIC SMALL LETTER ABKHASIAN CHE WITH DESCENDER;Ll;0;L;;;;;N;CYRILLIC SMALL LETTER IE HOOK OGONEK;;04BE;;04BE -04C0;CYRILLIC LETTER PALOCHKA;Lu;0;L;;;;;N;CYRILLIC LETTER I;;;; +04C0;CYRILLIC LETTER PALOCHKA;Lu;0;L;;;;;N;CYRILLIC LETTER I;;;04CF; 04C1;CYRILLIC CAPITAL LETTER ZHE WITH BREVE;Lu;0;L;0416 0306;;;;N;CYRILLIC CAPITAL LETTER SHORT ZHE;;;04C2; 04C2;CYRILLIC SMALL LETTER ZHE WITH BREVE;Ll;0;L;0436 0306;;;;N;CYRILLIC SMALL LETTER SHORT ZHE;;04C1;;04C1 04C3;CYRILLIC CAPITAL LETTER KA WITH HOOK;Lu;0;L;;;;;N;CYRILLIC CAPITAL LETTER KA HOOK;;;04C4; @@ -1174,6 +1219,7 @@ 04CC;CYRILLIC SMALL LETTER KHAKASSIAN CHE;Ll;0;L;;;;;N;CYRILLIC SMALL LETTER CHE WITH LEFT DESCENDER;;04CB;;04CB 04CD;CYRILLIC CAPITAL LETTER EM WITH TAIL;Lu;0;L;;;;;N;;;;04CE; 04CE;CYRILLIC SMALL LETTER EM WITH TAIL;Ll;0;L;;;;;N;;;04CD;;04CD +04CF;CYRILLIC SMALL LETTER PALOCHKA;Ll;0;L;;;;;N;;;04C0;;04C0 04D0;CYRILLIC CAPITAL LETTER A WITH BREVE;Lu;0;L;0410 0306;;;;N;;;;04D1; 04D1;CYRILLIC SMALL LETTER A WITH BREVE;Ll;0;L;0430 0306;;;;N;;;04D0;;04D0 04D2;CYRILLIC CAPITAL LETTER A WITH DIAERESIS;Lu;0;L;0410 0308;;;;N;;;;04D3; @@ -1212,8 +1258,16 @@ 04F3;CYRILLIC SMALL LETTER U WITH DOUBLE ACUTE;Ll;0;L;0443 030B;;;;N;;;04F2;;04F2 04F4;CYRILLIC CAPITAL LETTER CHE WITH DIAERESIS;Lu;0;L;0427 0308;;;;N;;;;04F5; 04F5;CYRILLIC SMALL LETTER CHE WITH DIAERESIS;Ll;0;L;0447 0308;;;;N;;;04F4;;04F4 +04F6;CYRILLIC CAPITAL LETTER GHE WITH DESCENDER;Lu;0;L;;;;;N;;;;04F7; +04F7;CYRILLIC SMALL LETTER GHE WITH DESCENDER;Ll;0;L;;;;;N;;;04F6;;04F6 04F8;CYRILLIC CAPITAL LETTER YERU WITH DIAERESIS;Lu;0;L;042B 0308;;;;N;;;;04F9; 04F9;CYRILLIC SMALL LETTER YERU WITH DIAERESIS;Ll;0;L;044B 0308;;;;N;;;04F8;;04F8 +04FA;CYRILLIC CAPITAL LETTER GHE WITH STROKE AND HOOK;Lu;0;L;;;;;N;;;;04FB; +04FB;CYRILLIC SMALL LETTER GHE WITH STROKE AND HOOK;Ll;0;L;;;;;N;;;04FA;;04FA +04FC;CYRILLIC CAPITAL LETTER HA WITH HOOK;Lu;0;L;;;;;N;;;;04FD; +04FD;CYRILLIC SMALL LETTER HA WITH HOOK;Ll;0;L;;;;;N;;;04FC;;04FC +04FE;CYRILLIC CAPITAL LETTER HA WITH STROKE;Lu;0;L;;;;;N;;;;04FF; +04FF;CYRILLIC SMALL LETTER HA WITH STROKE;Ll;0;L;;;;;N;;;04FE;;04FE 0500;CYRILLIC CAPITAL LETTER KOMI DE;Lu;0;L;;;;;N;;;;0501; 0501;CYRILLIC SMALL LETTER KOMI DE;Ll;0;L;;;;;N;;;0500;;0500 0502;CYRILLIC CAPITAL LETTER KOMI DJE;Lu;0;L;;;;;N;;;;0503; @@ -1230,6 +1284,26 @@ 050D;CYRILLIC SMALL LETTER KOMI SJE;Ll;0;L;;;;;N;;;050C;;050C 050E;CYRILLIC CAPITAL LETTER KOMI TJE;Lu;0;L;;;;;N;;;;050F; 050F;CYRILLIC SMALL LETTER KOMI TJE;Ll;0;L;;;;;N;;;050E;;050E +0510;CYRILLIC CAPITAL LETTER REVERSED ZE;Lu;0;L;;;;;N;;;;0511; +0511;CYRILLIC SMALL LETTER REVERSED ZE;Ll;0;L;;;;;N;;;0510;;0510 +0512;CYRILLIC CAPITAL LETTER EL WITH HOOK;Lu;0;L;;;;;N;;;;0513; +0513;CYRILLIC SMALL LETTER EL WITH HOOK;Ll;0;L;;;;;N;;;0512;;0512 +0514;CYRILLIC CAPITAL LETTER LHA;Lu;0;L;;;;;N;;;;0515; +0515;CYRILLIC SMALL LETTER LHA;Ll;0;L;;;;;N;;;0514;;0514 +0516;CYRILLIC CAPITAL LETTER RHA;Lu;0;L;;;;;N;;;;0517; +0517;CYRILLIC SMALL LETTER RHA;Ll;0;L;;;;;N;;;0516;;0516 +0518;CYRILLIC CAPITAL LETTER YAE;Lu;0;L;;;;;N;;;;0519; +0519;CYRILLIC SMALL LETTER YAE;Ll;0;L;;;;;N;;;0518;;0518 +051A;CYRILLIC CAPITAL LETTER QA;Lu;0;L;;;;;N;;;;051B; +051B;CYRILLIC SMALL LETTER QA;Ll;0;L;;;;;N;;;051A;;051A +051C;CYRILLIC CAPITAL LETTER WE;Lu;0;L;;;;;N;;;;051D; +051D;CYRILLIC SMALL LETTER WE;Ll;0;L;;;;;N;;;051C;;051C +051E;CYRILLIC CAPITAL LETTER ALEUT KA;Lu;0;L;;;;;N;;;;051F; +051F;CYRILLIC SMALL LETTER ALEUT KA;Ll;0;L;;;;;N;;;051E;;051E +0520;CYRILLIC CAPITAL LETTER EL WITH MIDDLE HOOK;Lu;0;L;;;;;N;;;;0521; +0521;CYRILLIC SMALL LETTER EL WITH MIDDLE HOOK;Ll;0;L;;;;;N;;;0520;;0520 +0522;CYRILLIC CAPITAL LETTER EN WITH MIDDLE HOOK;Lu;0;L;;;;;N;;;;0523; +0523;CYRILLIC SMALL LETTER EN WITH MIDDLE HOOK;Ll;0;L;;;;;N;;;0522;;0522 0531;ARMENIAN CAPITAL LETTER AYB;Lu;0;L;;;;;N;;;;0561; 0532;ARMENIAN CAPITAL LETTER BEN;Lu;0;L;;;;;N;;;;0562; 0533;ARMENIAN CAPITAL LETTER GIM;Lu;0;L;;;;;N;;;;0563; @@ -1333,6 +1407,7 @@ 059F;HEBREW ACCENT QARNEY PARA;Mn;230;NSM;;;;;N;;;;; 05A0;HEBREW ACCENT TELISHA GEDOLA;Mn;230;NSM;;;;;N;;;;; 05A1;HEBREW ACCENT PAZER;Mn;230;NSM;;;;;N;;;;; +05A2;HEBREW ACCENT ATNAH HAFUKH;Mn;220;NSM;;;;;N;;;;; 05A3;HEBREW ACCENT MUNAH;Mn;220;NSM;;;;;N;;;;; 05A4;HEBREW ACCENT MAHAPAKH;Mn;220;NSM;;;;;N;;;;; 05A5;HEBREW ACCENT MERKHA;Mn;220;NSM;;;;;N;;*;;; @@ -1356,16 +1431,20 @@ 05B7;HEBREW POINT PATAH;Mn;17;NSM;;;;;N;;;;; 05B8;HEBREW POINT QAMATS;Mn;18;NSM;;;;;N;;;;; 05B9;HEBREW POINT HOLAM;Mn;19;NSM;;;;;N;;;;; +05BA;HEBREW POINT HOLAM HASER FOR VAV;Mn;19;NSM;;;;;N;;;;; 05BB;HEBREW POINT QUBUTS;Mn;20;NSM;;;;;N;;;;; 05BC;HEBREW POINT DAGESH OR MAPIQ;Mn;21;NSM;;;;;N;HEBREW POINT DAGESH;or shuruq;;; 05BD;HEBREW POINT METEG;Mn;22;NSM;;;;;N;;*;;; -05BE;HEBREW PUNCTUATION MAQAF;Po;0;R;;;;;N;;;;; +05BE;HEBREW PUNCTUATION MAQAF;Pd;0;R;;;;;N;;;;; 05BF;HEBREW POINT RAFE;Mn;23;NSM;;;;;N;;;;; 05C0;HEBREW PUNCTUATION PASEQ;Po;0;R;;;;;N;HEBREW POINT PASEQ;*;;; 05C1;HEBREW POINT SHIN DOT;Mn;24;NSM;;;;;N;;;;; 05C2;HEBREW POINT SIN DOT;Mn;25;NSM;;;;;N;;;;; 05C3;HEBREW PUNCTUATION SOF PASUQ;Po;0;R;;;;;N;;*;;; 05C4;HEBREW MARK UPPER DOT;Mn;230;NSM;;;;;N;;;;; +05C5;HEBREW MARK LOWER DOT;Mn;220;NSM;;;;;N;;;;; +05C6;HEBREW PUNCTUATION NUN HAFUKHA;Po;0;R;;;;;N;;;;; +05C7;HEBREW POINT QAMATS QATAN;Mn;18;NSM;;;;;N;;;;; 05D0;HEBREW LETTER ALEF;Lo;0;R;;;;;N;;;;; 05D1;HEBREW LETTER BET;Lo;0;R;;;;;N;;;;; 05D2;HEBREW LETTER GIMEL;Lo;0;R;;;;;N;;;;; @@ -1398,10 +1477,16 @@ 05F2;HEBREW LIGATURE YIDDISH DOUBLE YOD;Lo;0;R;;;;;N;HEBREW LETTER DOUBLE YOD;;;; 05F3;HEBREW PUNCTUATION GERESH;Po;0;R;;;;;N;;;;; 05F4;HEBREW PUNCTUATION GERSHAYIM;Po;0;R;;;;;N;;;;; -0600;ARABIC NUMBER SIGN;Cf;0;AL;;;;;N;;;;; -0601;ARABIC SIGN SANAH;Cf;0;AL;;;;;N;;;;; -0602;ARABIC FOOTNOTE MARKER;Cf;0;AL;;;;;N;;;;; -0603;ARABIC SIGN SAFHA;Cf;0;AL;;;;;N;;;;; +0600;ARABIC NUMBER SIGN;Cf;0;AN;;;;;N;;;;; +0601;ARABIC SIGN SANAH;Cf;0;AN;;;;;N;;;;; +0602;ARABIC FOOTNOTE MARKER;Cf;0;AN;;;;;N;;;;; +0603;ARABIC SIGN SAFHA;Cf;0;AN;;;;;N;;;;; +0606;ARABIC-INDIC CUBE ROOT;Sm;0;ON;;;;;N;;;;; +0607;ARABIC-INDIC FOURTH ROOT;Sm;0;ON;;;;;N;;;;; +0608;ARABIC RAY;Sm;0;AL;;;;;N;;;;; +0609;ARABIC-INDIC PER MILLE SIGN;Po;0;ET;;;;;N;;;;; +060A;ARABIC-INDIC PER TEN THOUSAND SIGN;Po;0;ET;;;;;N;;;;; +060B;AFGHANI SIGN;Sc;0;AL;;;;;N;;;;; 060C;ARABIC COMMA;Po;0;CS;;;;;N;;;;; 060D;ARABIC DATE SEPARATOR;Po;0;AL;;;;;N;;;;; 060E;ARABIC POETIC VERSE SIGN;So;0;ON;;;;;N;;;;; @@ -1411,8 +1496,14 @@ 0612;ARABIC SIGN RAHMATULLAH ALAYHE;Mn;230;NSM;;;;;N;;;;; 0613;ARABIC SIGN RADI ALLAHOU ANHU;Mn;230;NSM;;;;;N;;;;; 0614;ARABIC SIGN TAKHALLUS;Mn;230;NSM;;;;;N;;;;; -0615;ARABIC SMALL HIGH TAH ;Mn;230;NSM;;;;;N;;;;; +0615;ARABIC SMALL HIGH TAH;Mn;230;NSM;;;;;N;;;;; +0616;ARABIC SMALL HIGH LIGATURE ALEF WITH LAM WITH YEH;Mn;230;NSM;;;;;N;;;;; +0617;ARABIC SMALL HIGH ZAIN;Mn;230;NSM;;;;;N;;;;; +0618;ARABIC SMALL FATHA;Mn;30;NSM;;;;;N;;;;; +0619;ARABIC SMALL DAMMA;Mn;31;NSM;;;;;N;;;;; +061A;ARABIC SMALL KASRA;Mn;32;NSM;;;;;N;;;;; 061B;ARABIC SEMICOLON;Po;0;AL;;;;;N;;;;; +061E;ARABIC TRIPLE DOT PUNCTUATION MARK;Po;0;AL;;;;;N;;;;; 061F;ARABIC QUESTION MARK;Po;0;AL;;;;;N;;;;; 0621;ARABIC LETTER HAMZA;Lo;0;AL;;;;;N;ARABIC LETTER HAMZAH;;;; 0622;ARABIC LETTER ALEF WITH MADDA ABOVE;Lo;0;AL;0627 0653;;;;N;ARABIC LETTER MADDAH ON ALEF;;;; @@ -1440,6 +1531,11 @@ 0638;ARABIC LETTER ZAH;Lo;0;AL;;;;;N;ARABIC LETTER DHAH;;;; 0639;ARABIC LETTER AIN;Lo;0;AL;;;;;N;;;;; 063A;ARABIC LETTER GHAIN;Lo;0;AL;;;;;N;;;;; +063B;ARABIC LETTER KEHEH WITH TWO DOTS ABOVE;Lo;0;AL;;;;;N;;;;; +063C;ARABIC LETTER KEHEH WITH THREE DOTS BELOW;Lo;0;AL;;;;;N;;;;; +063D;ARABIC LETTER FARSI YEH WITH INVERTED V;Lo;0;AL;;;;;N;;;;; +063E;ARABIC LETTER FARSI YEH WITH TWO DOTS ABOVE;Lo;0;AL;;;;;N;;;;; +063F;ARABIC LETTER FARSI YEH WITH THREE DOTS ABOVE;Lo;0;AL;;;;;N;;;;; 0640;ARABIC TATWEEL;Lm;0;AL;;;;;N;;;;; 0641;ARABIC LETTER FEH;Lo;0;AL;;;;;N;ARABIC LETTER FA;;;; 0642;ARABIC LETTER QAF;Lo;0;AL;;;;;N;;;;; @@ -1465,6 +1561,12 @@ 0656;ARABIC SUBSCRIPT ALEF;Mn;220;NSM;;;;;N;;;;; 0657;ARABIC INVERTED DAMMA;Mn;230;NSM;;;;;N;;;;; 0658;ARABIC MARK NOON GHUNNA;Mn;230;NSM;;;;;N;;;;; +0659;ARABIC ZWARAKAY;Mn;230;NSM;;;;;N;;;;; +065A;ARABIC VOWEL SIGN SMALL V ABOVE;Mn;230;NSM;;;;;N;;;;; +065B;ARABIC VOWEL SIGN INVERTED SMALL V ABOVE;Mn;230;NSM;;;;;N;;;;; +065C;ARABIC VOWEL SIGN DOT BELOW;Mn;220;NSM;;;;;N;;;;; +065D;ARABIC REVERSED DAMMA;Mn;230;NSM;;;;;N;;;;; +065E;ARABIC FATHA WITH TWO DOTS;Mn;230;NSM;;;;;N;;;;; 0660;ARABIC-INDIC DIGIT ZERO;Nd;0;AN;;0;0;0;N;;;;; 0661;ARABIC-INDIC DIGIT ONE;Nd;0;AN;;1;1;1;N;;;;; 0662;ARABIC-INDIC DIGIT TWO;Nd;0;AN;;2;2;2;N;;;;; @@ -1590,7 +1692,7 @@ 06DA;ARABIC SMALL HIGH JEEM;Mn;230;NSM;;;;;N;;;;; 06DB;ARABIC SMALL HIGH THREE DOTS;Mn;230;NSM;;;;;N;;;;; 06DC;ARABIC SMALL HIGH SEEN;Mn;230;NSM;;;;;N;;;;; -06DD;ARABIC END OF AYAH;Cf;0;AL;;;;;N;;;;; +06DD;ARABIC END OF AYAH;Cf;0;AN;;;;;N;;;;; 06DE;ARABIC START OF RUB EL HIZB;Me;0;NSM;;;;;N;;;;; 06DF;ARABIC SMALL HIGH ROUNDED ZERO;Mn;230;NSM;;;;;N;;;;; 06E0;ARABIC SMALL HIGH UPRIGHT RECTANGULAR ZERO;Mn;230;NSM;;;;;N;;;;; @@ -1702,6 +1804,54 @@ 074D;SYRIAC LETTER SOGDIAN ZHAIN;Lo;0;AL;;;;;N;;;;; 074E;SYRIAC LETTER SOGDIAN KHAPH;Lo;0;AL;;;;;N;;;;; 074F;SYRIAC LETTER SOGDIAN FE;Lo;0;AL;;;;;N;;;;; +0750;ARABIC LETTER BEH WITH THREE DOTS HORIZONTALLY BELOW;Lo;0;AL;;;;;N;;;;; +0751;ARABIC LETTER BEH WITH DOT BELOW AND THREE DOTS ABOVE;Lo;0;AL;;;;;N;;;;; +0752;ARABIC LETTER BEH WITH THREE DOTS POINTING UPWARDS BELOW;Lo;0;AL;;;;;N;;;;; +0753;ARABIC LETTER BEH WITH THREE DOTS POINTING UPWARDS BELOW AND TWO DOTS ABOVE;Lo;0;AL;;;;;N;;;;; +0754;ARABIC LETTER BEH WITH TWO DOTS BELOW AND DOT ABOVE;Lo;0;AL;;;;;N;;;;; +0755;ARABIC LETTER BEH WITH INVERTED SMALL V BELOW;Lo;0;AL;;;;;N;;;;; +0756;ARABIC LETTER BEH WITH SMALL V;Lo;0;AL;;;;;N;;;;; +0757;ARABIC LETTER HAH WITH TWO DOTS ABOVE;Lo;0;AL;;;;;N;;;;; +0758;ARABIC LETTER HAH WITH THREE DOTS POINTING UPWARDS BELOW;Lo;0;AL;;;;;N;;;;; +0759;ARABIC LETTER DAL WITH TWO DOTS VERTICALLY BELOW AND SMALL TAH;Lo;0;AL;;;;;N;;;;; +075A;ARABIC LETTER DAL WITH INVERTED SMALL V BELOW;Lo;0;AL;;;;;N;;;;; +075B;ARABIC LETTER REH WITH STROKE;Lo;0;AL;;;;;N;;;;; +075C;ARABIC LETTER SEEN WITH FOUR DOTS ABOVE;Lo;0;AL;;;;;N;;;;; +075D;ARABIC LETTER AIN WITH TWO DOTS ABOVE;Lo;0;AL;;;;;N;;;;; +075E;ARABIC LETTER AIN WITH THREE DOTS POINTING DOWNWARDS ABOVE;Lo;0;AL;;;;;N;;;;; +075F;ARABIC LETTER AIN WITH TWO DOTS VERTICALLY ABOVE;Lo;0;AL;;;;;N;;;;; +0760;ARABIC LETTER FEH WITH TWO DOTS BELOW;Lo;0;AL;;;;;N;;;;; +0761;ARABIC LETTER FEH WITH THREE DOTS POINTING UPWARDS BELOW;Lo;0;AL;;;;;N;;;;; +0762;ARABIC LETTER KEHEH WITH DOT ABOVE;Lo;0;AL;;;;;N;;;;; +0763;ARABIC LETTER KEHEH WITH THREE DOTS ABOVE;Lo;0;AL;;;;;N;;;;; +0764;ARABIC LETTER KEHEH WITH THREE DOTS POINTING UPWARDS BELOW;Lo;0;AL;;;;;N;;;;; +0765;ARABIC LETTER MEEM WITH DOT ABOVE;Lo;0;AL;;;;;N;;;;; +0766;ARABIC LETTER MEEM WITH DOT BELOW;Lo;0;AL;;;;;N;;;;; +0767;ARABIC LETTER NOON WITH TWO DOTS BELOW;Lo;0;AL;;;;;N;;;;; +0768;ARABIC LETTER NOON WITH SMALL TAH;Lo;0;AL;;;;;N;;;;; +0769;ARABIC LETTER NOON WITH SMALL V;Lo;0;AL;;;;;N;;;;; +076A;ARABIC LETTER LAM WITH BAR;Lo;0;AL;;;;;N;;;;; +076B;ARABIC LETTER REH WITH TWO DOTS VERTICALLY ABOVE;Lo;0;AL;;;;;N;;;;; +076C;ARABIC LETTER REH WITH HAMZA ABOVE;Lo;0;AL;;;;;N;;;;; +076D;ARABIC LETTER SEEN WITH TWO DOTS VERTICALLY ABOVE;Lo;0;AL;;;;;N;;;;; +076E;ARABIC LETTER HAH WITH SMALL ARABIC LETTER TAH BELOW;Lo;0;AL;;;;;N;;;;; +076F;ARABIC LETTER HAH WITH SMALL ARABIC LETTER TAH AND TWO DOTS;Lo;0;AL;;;;;N;;;;; +0770;ARABIC LETTER SEEN WITH SMALL ARABIC LETTER TAH AND TWO DOTS;Lo;0;AL;;;;;N;;;;; +0771;ARABIC LETTER REH WITH SMALL ARABIC LETTER TAH AND TWO DOTS;Lo;0;AL;;;;;N;;;;; +0772;ARABIC LETTER HAH WITH SMALL ARABIC LETTER TAH ABOVE;Lo;0;AL;;;;;N;;;;; +0773;ARABIC LETTER ALEF WITH EXTENDED ARABIC-INDIC DIGIT TWO ABOVE;Lo;0;AL;;;;;N;;;;; +0774;ARABIC LETTER ALEF WITH EXTENDED ARABIC-INDIC DIGIT THREE ABOVE;Lo;0;AL;;;;;N;;;;; +0775;ARABIC LETTER FARSI YEH WITH EXTENDED ARABIC-INDIC DIGIT TWO ABOVE;Lo;0;AL;;;;;N;;;;; +0776;ARABIC LETTER FARSI YEH WITH EXTENDED ARABIC-INDIC DIGIT THREE ABOVE;Lo;0;AL;;;;;N;;;;; +0777;ARABIC LETTER FARSI YEH WITH EXTENDED ARABIC-INDIC DIGIT FOUR BELOW;Lo;0;AL;;;;;N;;;;; +0778;ARABIC LETTER WAW WITH EXTENDED ARABIC-INDIC DIGIT TWO ABOVE;Lo;0;AL;;;;;N;;;;; +0779;ARABIC LETTER WAW WITH EXTENDED ARABIC-INDIC DIGIT THREE ABOVE;Lo;0;AL;;;;;N;;;;; +077A;ARABIC LETTER YEH BARREE WITH EXTENDED ARABIC-INDIC DIGIT TWO ABOVE;Lo;0;AL;;;;;N;;;;; +077B;ARABIC LETTER YEH BARREE WITH EXTENDED ARABIC-INDIC DIGIT THREE ABOVE;Lo;0;AL;;;;;N;;;;; +077C;ARABIC LETTER HAH WITH EXTENDED ARABIC-INDIC DIGIT FOUR BELOW;Lo;0;AL;;;;;N;;;;; +077D;ARABIC LETTER SEEN WITH EXTENDED ARABIC-INDIC DIGIT FOUR ABOVE;Lo;0;AL;;;;;N;;;;; +077E;ARABIC LETTER SEEN WITH INVERTED V;Lo;0;AL;;;;;N;;;;; +077F;ARABIC LETTER KAF WITH TWO DOTS ABOVE;Lo;0;AL;;;;;N;;;;; 0780;THAANA LETTER HAA;Lo;0;AL;;;;;N;;;;; 0781;THAANA LETTER SHAVIYANI;Lo;0;AL;;;;;N;;;;; 0782;THAANA LETTER NOONU;Lo;0;AL;;;;;N;;;;; @@ -1752,6 +1902,65 @@ 07AF;THAANA OABOAFILI;Mn;0;NSM;;;;;N;;;;; 07B0;THAANA SUKUN;Mn;0;NSM;;;;;N;;;;; 07B1;THAANA LETTER NAA;Lo;0;AL;;;;;N;;;;; +07C0;NKO DIGIT ZERO;Nd;0;R;;0;0;0;N;;;;; +07C1;NKO DIGIT ONE;Nd;0;R;;1;1;1;N;;;;; +07C2;NKO DIGIT TWO;Nd;0;R;;2;2;2;N;;;;; +07C3;NKO DIGIT THREE;Nd;0;R;;3;3;3;N;;;;; +07C4;NKO DIGIT FOUR;Nd;0;R;;4;4;4;N;;;;; +07C5;NKO DIGIT FIVE;Nd;0;R;;5;5;5;N;;;;; +07C6;NKO DIGIT SIX;Nd;0;R;;6;6;6;N;;;;; +07C7;NKO DIGIT SEVEN;Nd;0;R;;7;7;7;N;;;;; +07C8;NKO DIGIT EIGHT;Nd;0;R;;8;8;8;N;;;;; +07C9;NKO DIGIT NINE;Nd;0;R;;9;9;9;N;;;;; +07CA;NKO LETTER A;Lo;0;R;;;;;N;;;;; +07CB;NKO LETTER EE;Lo;0;R;;;;;N;;;;; +07CC;NKO LETTER I;Lo;0;R;;;;;N;;;;; +07CD;NKO LETTER E;Lo;0;R;;;;;N;;;;; +07CE;NKO LETTER U;Lo;0;R;;;;;N;;;;; +07CF;NKO LETTER OO;Lo;0;R;;;;;N;;;;; +07D0;NKO LETTER O;Lo;0;R;;;;;N;;;;; +07D1;NKO LETTER DAGBASINNA;Lo;0;R;;;;;N;;;;; +07D2;NKO LETTER N;Lo;0;R;;;;;N;;;;; +07D3;NKO LETTER BA;Lo;0;R;;;;;N;;;;; +07D4;NKO LETTER PA;Lo;0;R;;;;;N;;;;; +07D5;NKO LETTER TA;Lo;0;R;;;;;N;;;;; +07D6;NKO LETTER JA;Lo;0;R;;;;;N;;;;; +07D7;NKO LETTER CHA;Lo;0;R;;;;;N;;;;; +07D8;NKO LETTER DA;Lo;0;R;;;;;N;;;;; +07D9;NKO LETTER RA;Lo;0;R;;;;;N;;;;; +07DA;NKO LETTER RRA;Lo;0;R;;;;;N;;;;; +07DB;NKO LETTER SA;Lo;0;R;;;;;N;;;;; +07DC;NKO LETTER GBA;Lo;0;R;;;;;N;;;;; +07DD;NKO LETTER FA;Lo;0;R;;;;;N;;;;; +07DE;NKO LETTER KA;Lo;0;R;;;;;N;;;;; +07DF;NKO LETTER LA;Lo;0;R;;;;;N;;;;; +07E0;NKO LETTER NA WOLOSO;Lo;0;R;;;;;N;;;;; +07E1;NKO LETTER MA;Lo;0;R;;;;;N;;;;; +07E2;NKO LETTER NYA;Lo;0;R;;;;;N;;;;; +07E3;NKO LETTER NA;Lo;0;R;;;;;N;;;;; +07E4;NKO LETTER HA;Lo;0;R;;;;;N;;;;; +07E5;NKO LETTER WA;Lo;0;R;;;;;N;;;;; +07E6;NKO LETTER YA;Lo;0;R;;;;;N;;;;; +07E7;NKO LETTER NYA WOLOSO;Lo;0;R;;;;;N;;;;; +07E8;NKO LETTER JONA JA;Lo;0;R;;;;;N;;;;; +07E9;NKO LETTER JONA CHA;Lo;0;R;;;;;N;;;;; +07EA;NKO LETTER JONA RA;Lo;0;R;;;;;N;;;;; +07EB;NKO COMBINING SHORT HIGH TONE;Mn;230;NSM;;;;;N;;;;; +07EC;NKO COMBINING SHORT LOW TONE;Mn;230;NSM;;;;;N;;;;; +07ED;NKO COMBINING SHORT RISING TONE;Mn;230;NSM;;;;;N;;;;; +07EE;NKO COMBINING LONG DESCENDING TONE;Mn;230;NSM;;;;;N;;;;; +07EF;NKO COMBINING LONG HIGH TONE;Mn;230;NSM;;;;;N;;;;; +07F0;NKO COMBINING LONG LOW TONE;Mn;230;NSM;;;;;N;;;;; +07F1;NKO COMBINING LONG RISING TONE;Mn;230;NSM;;;;;N;;;;; +07F2;NKO COMBINING NASALIZATION MARK;Mn;220;NSM;;;;;N;;;;; +07F3;NKO COMBINING DOUBLE DOT ABOVE;Mn;230;NSM;;;;;N;;;;; +07F4;NKO HIGH TONE APOSTROPHE;Lm;0;R;;;;;N;;;;; +07F5;NKO LOW TONE APOSTROPHE;Lm;0;R;;;;;N;;;;; +07F6;NKO SYMBOL OO DENNEN;So;0;ON;;;;;N;;;;; +07F7;NKO SYMBOL GBAKURUNEN;Po;0;ON;;;;;N;;;;; +07F8;NKO COMMA;Po;0;ON;;;;;N;;;;; +07F9;NKO EXCLAMATION MARK;Po;0;ON;;;;;N;;;;; +07FA;NKO LAJANYALAN;Lm;0;R;;;;;N;;;;; 0901;DEVANAGARI SIGN CANDRABINDU;Mn;0;NSM;;;;;N;;;;; 0902;DEVANAGARI SIGN ANUSVARA;Mn;0;NSM;;;;;N;;;;; 0903;DEVANAGARI SIGN VISARGA;Mc;0;L;;;;;N;;;;; @@ -1857,6 +2066,13 @@ 096E;DEVANAGARI DIGIT EIGHT;Nd;0;L;;8;8;8;N;;;;; 096F;DEVANAGARI DIGIT NINE;Nd;0;L;;9;9;9;N;;;;; 0970;DEVANAGARI ABBREVIATION SIGN;Po;0;L;;;;;N;;;;; +0971;DEVANAGARI SIGN HIGH SPACING DOT;Lm;0;L;;;;;N;;;;; +0972;DEVANAGARI LETTER CANDRA A;Lo;0;L;;;;;N;;;;; +097B;DEVANAGARI LETTER GGA;Lo;0;L;;;;;N;;;;; +097C;DEVANAGARI LETTER JJA;Lo;0;L;;;;;N;;;;; +097D;DEVANAGARI LETTER GLOTTAL STOP;Lo;0;L;;;;;N;;;;; +097E;DEVANAGARI LETTER DDDA;Lo;0;L;;;;;N;;;;; +097F;DEVANAGARI LETTER BBA;Lo;0;L;;;;;N;;;;; 0981;BENGALI SIGN CANDRABINDU;Mn;0;NSM;;;;;N;;;;; 0982;BENGALI SIGN ANUSVARA;Mc;0;L;;;;;N;;;;; 0983;BENGALI SIGN VISARGA;Mc;0;L;;;;;N;;;;; @@ -1918,6 +2134,7 @@ 09CB;BENGALI VOWEL SIGN O;Mc;0;L;09C7 09BE;;;;N;;;;; 09CC;BENGALI VOWEL SIGN AU;Mc;0;L;09C7 09D7;;;;N;;;;; 09CD;BENGALI SIGN VIRAMA;Mn;9;NSM;;;;;N;;;;; +09CE;BENGALI LETTER KHANDA TA;Lo;0;L;;;;;N;;;;; 09D7;BENGALI AU LENGTH MARK;Mc;0;L;;;;;N;;;;; 09DC;BENGALI LETTER RRA;Lo;0;L;09A1 09BC;;;;N;;;;; 09DD;BENGALI LETTER RHA;Lo;0;L;09A2 09BC;;;;N;;;;; @@ -2004,6 +2221,7 @@ 0A4B;GURMUKHI VOWEL SIGN OO;Mn;0;NSM;;;;;N;;;;; 0A4C;GURMUKHI VOWEL SIGN AU;Mn;0;NSM;;;;;N;;;;; 0A4D;GURMUKHI SIGN VIRAMA;Mn;9;NSM;;;;;N;;;;; +0A51;GURMUKHI SIGN UDAAT;Mn;0;NSM;;;;;N;;;;; 0A59;GURMUKHI LETTER KHHA;Lo;0;L;0A16 0A3C;;;;N;;;;; 0A5A;GURMUKHI LETTER GHHA;Lo;0;L;0A17 0A3C;;;;N;;;;; 0A5B;GURMUKHI LETTER ZA;Lo;0;L;0A1C 0A3C;;;;N;;;;; @@ -2024,6 +2242,7 @@ 0A72;GURMUKHI IRI;Lo;0;L;;;;;N;;;;; 0A73;GURMUKHI URA;Lo;0;L;;;;;N;;;;; 0A74;GURMUKHI EK ONKAR;Lo;0;L;;;;;N;;;;; +0A75;GURMUKHI SIGN YAKASH;Mn;0;NSM;;;;;N;;;;; 0A81;GUJARATI SIGN CANDRABINDU;Mn;0;NSM;;;;;N;;;;; 0A82;GUJARATI SIGN ANUSVARA;Mn;0;NSM;;;;;N;;;;; 0A83;GUJARATI SIGN VISARGA;Mc;0;L;;;;;N;;;;; @@ -2164,6 +2383,7 @@ 0B41;ORIYA VOWEL SIGN U;Mn;0;NSM;;;;;N;;;;; 0B42;ORIYA VOWEL SIGN UU;Mn;0;NSM;;;;;N;;;;; 0B43;ORIYA VOWEL SIGN VOCALIC R;Mn;0;NSM;;;;;N;;;;; +0B44;ORIYA VOWEL SIGN VOCALIC RR;Mn;0;NSM;;;;;N;;;;; 0B47;ORIYA VOWEL SIGN E;Mc;0;L;;;;;N;;;;; 0B48;ORIYA VOWEL SIGN AI;Mc;0;L;0B47 0B56;;;;N;;;;; 0B4B;ORIYA VOWEL SIGN O;Mc;0;L;0B47 0B3E;;;;N;;;;; @@ -2176,6 +2396,8 @@ 0B5F;ORIYA LETTER YYA;Lo;0;L;;;;;N;;;;; 0B60;ORIYA LETTER VOCALIC RR;Lo;0;L;;;;;N;;;;; 0B61;ORIYA LETTER VOCALIC LL;Lo;0;L;;;;;N;;;;; +0B62;ORIYA VOWEL SIGN VOCALIC L;Mn;0;NSM;;;;;N;;;;; +0B63;ORIYA VOWEL SIGN VOCALIC LL;Mn;0;NSM;;;;;N;;;;; 0B66;ORIYA DIGIT ZERO;Nd;0;L;;0;0;0;N;;;;; 0B67;ORIYA DIGIT ONE;Nd;0;L;;1;1;1;N;;;;; 0B68;ORIYA DIGIT TWO;Nd;0;L;;2;2;2;N;;;;; @@ -2221,6 +2443,7 @@ 0BB3;TAMIL LETTER LLA;Lo;0;L;;;;;N;;;;; 0BB4;TAMIL LETTER LLLA;Lo;0;L;;;;;N;;;;; 0BB5;TAMIL LETTER VA;Lo;0;L;;;;;N;;;;; +0BB6;TAMIL LETTER SHA;Lo;0;L;;;;;N;;;;; 0BB7;TAMIL LETTER SSA;Lo;0;L;;;;;N;;;;; 0BB8;TAMIL LETTER SA;Lo;0;L;;;;;N;;;;; 0BB9;TAMIL LETTER HA;Lo;0;L;;;;;N;;;;; @@ -2236,7 +2459,9 @@ 0BCB;TAMIL VOWEL SIGN OO;Mc;0;L;0BC7 0BBE;;;;N;;;;; 0BCC;TAMIL VOWEL SIGN AU;Mc;0;L;0BC6 0BD7;;;;N;;;;; 0BCD;TAMIL SIGN VIRAMA;Mn;9;NSM;;;;;N;;;;; +0BD0;TAMIL OM;Lo;0;L;;;;;N;;;;; 0BD7;TAMIL AU LENGTH MARK;Mc;0;L;;;;;N;;;;; +0BE6;TAMIL DIGIT ZERO;Nd;0;L;;0;0;0;N;;;;; 0BE7;TAMIL DIGIT ONE;Nd;0;L;;1;1;1;N;;;;; 0BE8;TAMIL DIGIT TWO;Nd;0;L;;2;2;2;N;;;;; 0BE9;TAMIL DIGIT THREE;Nd;0;L;;3;3;3;N;;;;; @@ -2309,6 +2534,7 @@ 0C37;TELUGU LETTER SSA;Lo;0;L;;;;;N;;;;; 0C38;TELUGU LETTER SA;Lo;0;L;;;;;N;;;;; 0C39;TELUGU LETTER HA;Lo;0;L;;;;;N;;;;; +0C3D;TELUGU SIGN AVAGRAHA;Lo;0;L;;;;;N;;;;; 0C3E;TELUGU VOWEL SIGN AA;Mn;0;NSM;;;;;N;;;;; 0C3F;TELUGU VOWEL SIGN I;Mn;0;NSM;;;;;N;;;;; 0C40;TELUGU VOWEL SIGN II;Mn;0;NSM;;;;;N;;;;; @@ -2325,8 +2551,12 @@ 0C4D;TELUGU SIGN VIRAMA;Mn;9;NSM;;;;;N;;;;; 0C55;TELUGU LENGTH MARK;Mn;84;NSM;;;;;N;;;;; 0C56;TELUGU AI LENGTH MARK;Mn;91;NSM;;;;;N;;;;; +0C58;TELUGU LETTER TSA;Lo;0;L;;;;;N;;;;; +0C59;TELUGU LETTER DZA;Lo;0;L;;;;;N;;;;; 0C60;TELUGU LETTER VOCALIC RR;Lo;0;L;;;;;N;;;;; 0C61;TELUGU LETTER VOCALIC LL;Lo;0;L;;;;;N;;;;; +0C62;TELUGU VOWEL SIGN VOCALIC L;Mn;0;NSM;;;;;N;;;;; +0C63;TELUGU VOWEL SIGN VOCALIC LL;Mn;0;NSM;;;;;N;;;;; 0C66;TELUGU DIGIT ZERO;Nd;0;L;;0;0;0;N;;;;; 0C67;TELUGU DIGIT ONE;Nd;0;L;;1;1;1;N;;;;; 0C68;TELUGU DIGIT TWO;Nd;0;L;;2;2;2;N;;;;; @@ -2337,6 +2567,14 @@ 0C6D;TELUGU DIGIT SEVEN;Nd;0;L;;7;7;7;N;;;;; 0C6E;TELUGU DIGIT EIGHT;Nd;0;L;;8;8;8;N;;;;; 0C6F;TELUGU DIGIT NINE;Nd;0;L;;9;9;9;N;;;;; +0C78;TELUGU FRACTION DIGIT ZERO FOR ODD POWERS OF FOUR;No;0;ON;;;;0;N;;;;; +0C79;TELUGU FRACTION DIGIT ONE FOR ODD POWERS OF FOUR;No;0;ON;;;;1;N;;;;; +0C7A;TELUGU FRACTION DIGIT TWO FOR ODD POWERS OF FOUR;No;0;ON;;;;2;N;;;;; +0C7B;TELUGU FRACTION DIGIT THREE FOR ODD POWERS OF FOUR;No;0;ON;;;;3;N;;;;; +0C7C;TELUGU FRACTION DIGIT ONE FOR EVEN POWERS OF FOUR;No;0;ON;;;;1;N;;;;; +0C7D;TELUGU FRACTION DIGIT TWO FOR EVEN POWERS OF FOUR;No;0;ON;;;;2;N;;;;; +0C7E;TELUGU FRACTION DIGIT THREE FOR EVEN POWERS OF FOUR;No;0;ON;;;;3;N;;;;; +0C7F;TELUGU SIGN TUUMU;So;0;L;;;;;N;;;;; 0C82;KANNADA SIGN ANUSVARA;Mc;0;L;;;;;N;;;;; 0C83;KANNADA SIGN VISARGA;Mc;0;L;;;;;N;;;;; 0C85;KANNADA LETTER A;Lo;0;L;;;;;N;;;;; @@ -2409,6 +2647,8 @@ 0CDE;KANNADA LETTER FA;Lo;0;L;;;;;N;;;;; 0CE0;KANNADA LETTER VOCALIC RR;Lo;0;L;;;;;N;;;;; 0CE1;KANNADA LETTER VOCALIC LL;Lo;0;L;;;;;N;;;;; +0CE2;KANNADA VOWEL SIGN VOCALIC L;Mn;0;NSM;;;;;N;;;;; +0CE3;KANNADA VOWEL SIGN VOCALIC LL;Mn;0;NSM;;;;;N;;;;; 0CE6;KANNADA DIGIT ZERO;Nd;0;L;;0;0;0;N;;;;; 0CE7;KANNADA DIGIT ONE;Nd;0;L;;1;1;1;N;;;;; 0CE8;KANNADA DIGIT TWO;Nd;0;L;;2;2;2;N;;;;; @@ -2419,6 +2659,8 @@ 0CED;KANNADA DIGIT SEVEN;Nd;0;L;;7;7;7;N;;;;; 0CEE;KANNADA DIGIT EIGHT;Nd;0;L;;8;8;8;N;;;;; 0CEF;KANNADA DIGIT NINE;Nd;0;L;;9;9;9;N;;;;; +0CF1;KANNADA SIGN JIHVAMULIYA;So;0;ON;;;;;N;;;;; +0CF2;KANNADA SIGN UPADHMANIYA;So;0;ON;;;;;N;;;;; 0D02;MALAYALAM SIGN ANUSVARA;Mc;0;L;;;;;N;;;;; 0D03;MALAYALAM SIGN VISARGA;Mc;0;L;;;;;N;;;;; 0D05;MALAYALAM LETTER A;Lo;0;L;;;;;N;;;;; @@ -2471,12 +2713,14 @@ 0D37;MALAYALAM LETTER SSA;Lo;0;L;;;;;N;;;;; 0D38;MALAYALAM LETTER SA;Lo;0;L;;;;;N;;;;; 0D39;MALAYALAM LETTER HA;Lo;0;L;;;;;N;;;;; +0D3D;MALAYALAM SIGN AVAGRAHA;Lo;0;L;;;;;N;;;;; 0D3E;MALAYALAM VOWEL SIGN AA;Mc;0;L;;;;;N;;;;; 0D3F;MALAYALAM VOWEL SIGN I;Mc;0;L;;;;;N;;;;; 0D40;MALAYALAM VOWEL SIGN II;Mc;0;L;;;;;N;;;;; 0D41;MALAYALAM VOWEL SIGN U;Mn;0;NSM;;;;;N;;;;; 0D42;MALAYALAM VOWEL SIGN UU;Mn;0;NSM;;;;;N;;;;; 0D43;MALAYALAM VOWEL SIGN VOCALIC R;Mn;0;NSM;;;;;N;;;;; +0D44;MALAYALAM VOWEL SIGN VOCALIC RR;Mn;0;NSM;;;;;N;;;;; 0D46;MALAYALAM VOWEL SIGN E;Mc;0;L;;;;;N;;;;; 0D47;MALAYALAM VOWEL SIGN EE;Mc;0;L;;;;;N;;;;; 0D48;MALAYALAM VOWEL SIGN AI;Mc;0;L;;;;;N;;;;; @@ -2487,6 +2731,8 @@ 0D57;MALAYALAM AU LENGTH MARK;Mc;0;L;;;;;N;;;;; 0D60;MALAYALAM LETTER VOCALIC RR;Lo;0;L;;;;;N;;;;; 0D61;MALAYALAM LETTER VOCALIC LL;Lo;0;L;;;;;N;;;;; +0D62;MALAYALAM VOWEL SIGN VOCALIC L;Mn;0;NSM;;;;;N;;;;; +0D63;MALAYALAM VOWEL SIGN VOCALIC LL;Mn;0;NSM;;;;;N;;;;; 0D66;MALAYALAM DIGIT ZERO;Nd;0;L;;0;0;0;N;;;;; 0D67;MALAYALAM DIGIT ONE;Nd;0;L;;1;1;1;N;;;;; 0D68;MALAYALAM DIGIT TWO;Nd;0;L;;2;2;2;N;;;;; @@ -2497,6 +2743,19 @@ 0D6D;MALAYALAM DIGIT SEVEN;Nd;0;L;;7;7;7;N;;;;; 0D6E;MALAYALAM DIGIT EIGHT;Nd;0;L;;8;8;8;N;;;;; 0D6F;MALAYALAM DIGIT NINE;Nd;0;L;;9;9;9;N;;;;; +0D70;MALAYALAM NUMBER TEN;No;0;L;;;;10;N;;;;; +0D71;MALAYALAM NUMBER ONE HUNDRED;No;0;L;;;;100;N;;;;; +0D72;MALAYALAM NUMBER ONE THOUSAND;No;0;L;;;;1000;N;;;;; +0D73;MALAYALAM FRACTION ONE QUARTER;No;0;L;;;;1/4;N;;;;; +0D74;MALAYALAM FRACTION ONE HALF;No;0;L;;;;1/2;N;;;;; +0D75;MALAYALAM FRACTION THREE QUARTERS;No;0;L;;;;3/4;N;;;;; +0D79;MALAYALAM DATE MARK;So;0;L;;;;;N;;;;; +0D7A;MALAYALAM LETTER CHILLU NN;Lo;0;L;;;;;N;;;;; +0D7B;MALAYALAM LETTER CHILLU N;Lo;0;L;;;;;N;;;;; +0D7C;MALAYALAM LETTER CHILLU RR;Lo;0;L;;;;;N;;;;; +0D7D;MALAYALAM LETTER CHILLU L;Lo;0;L;;;;;N;;;;; +0D7E;MALAYALAM LETTER CHILLU LL;Lo;0;L;;;;;N;;;;; +0D7F;MALAYALAM LETTER CHILLU K;Lo;0;L;;;;;N;;;;; 0D82;SINHALA SIGN ANUSVARAYA;Mc;0;L;;;;;N;;;;; 0D83;SINHALA SIGN VISARGAYA;Mc;0;L;;;;;N;;;;; 0D85;SINHALA LETTER AYANNA;Lo;0;L;;;;;N;;;;; @@ -2787,10 +3046,10 @@ 0F37;TIBETAN MARK NGAS BZUNG SGOR RTAGS;Mn;220;NSM;;;;;N;TIBETAN UNDER RING;nge zung gor ta;;; 0F38;TIBETAN MARK CHE MGO;So;0;L;;;;;N;;che go;;; 0F39;TIBETAN MARK TSA -PHRU;Mn;216;NSM;;;;;N;TIBETAN LENITION MARK;tsa tru;;; -0F3A;TIBETAN MARK GUG RTAGS GYON;Ps;0;ON;;;;;N;;gug ta yun;;; -0F3B;TIBETAN MARK GUG RTAGS GYAS;Pe;0;ON;;;;;N;;gug ta ye;;; -0F3C;TIBETAN MARK ANG KHANG GYON;Ps;0;ON;;;;;N;TIBETAN LEFT BRACE;ang kang yun;;; -0F3D;TIBETAN MARK ANG KHANG GYAS;Pe;0;ON;;;;;N;TIBETAN RIGHT BRACE;ang kang ye;;; +0F3A;TIBETAN MARK GUG RTAGS GYON;Ps;0;ON;;;;;Y;;gug ta yun;;; +0F3B;TIBETAN MARK GUG RTAGS GYAS;Pe;0;ON;;;;;Y;;gug ta ye;;; +0F3C;TIBETAN MARK ANG KHANG GYON;Ps;0;ON;;;;;Y;TIBETAN LEFT BRACE;ang kang yun;;; +0F3D;TIBETAN MARK ANG KHANG GYAS;Pe;0;ON;;;;;Y;TIBETAN RIGHT BRACE;ang kang ye;;; 0F3E;TIBETAN SIGN YAR TSHES;Mc;0;L;;;;;N;;yar tse;;; 0F3F;TIBETAN SIGN MAR TSHES;Mc;0;L;;;;;N;;mar tse;;; 0F40;TIBETAN LETTER KA;Lo;0;L;;;;;N;;;;; @@ -2835,6 +3094,8 @@ 0F68;TIBETAN LETTER A;Lo;0;L;;;;;N;;;;; 0F69;TIBETAN LETTER KSSA;Lo;0;L;0F40 0FB5;;;;N;;;;; 0F6A;TIBETAN LETTER FIXED-FORM RA;Lo;0;L;;;;;N;;*;;; +0F6B;TIBETAN LETTER KKA;Lo;0;L;;;;;N;;;;; +0F6C;TIBETAN LETTER RRA;Lo;0;L;;;;;N;;;;; 0F71;TIBETAN VOWEL SIGN AA;Mn;129;NSM;;;;;N;;;;; 0F72;TIBETAN VOWEL SIGN I;Mn;130;NSM;;;;;N;;;;; 0F73;TIBETAN VOWEL SIGN II;Mn;0;NSM;0F71 0F72;;;;N;;;;; @@ -2921,7 +3182,13 @@ 0FCA;TIBETAN SYMBOL NOR BU NYIS -KHYIL;So;0;L;;;;;N;;norbu nyi khyi;;; 0FCB;TIBETAN SYMBOL NOR BU GSUM -KHYIL;So;0;L;;;;;N;;norbu sum khyi;;; 0FCC;TIBETAN SYMBOL NOR BU BZHI -KHYIL;So;0;L;;;;;N;;norbu shi khyi;;; +0FCE;TIBETAN SIGN RDEL NAG RDEL DKAR;So;0;L;;;;;N;;dena deka;;; 0FCF;TIBETAN SIGN RDEL NAG GSUM;So;0;L;;;;;N;;dena sum;;; +0FD0;TIBETAN MARK BSKA- SHOG GI MGO RGYAN;Po;0;L;;;;;N;;ka shog gi go gyen;;; +0FD1;TIBETAN MARK MNYAM YIG GI MGO RGYAN;Po;0;L;;;;;N;;nyam yig gi go gyen;;; +0FD2;TIBETAN MARK NYIS TSHEG;Po;0;L;;;;;N;;nyi tsek;;; +0FD3;TIBETAN MARK INITIAL BRDA RNYING YIG MGO MDUN MA;Po;0;L;;;;;N;;da nying yik go dun ma;;; +0FD4;TIBETAN MARK CLOSING BRDA RNYING YIG MGO SGAB MA;Po;0;L;;;;;N;;da nying yik go kab ma;;; 1000;MYANMAR LETTER KA;Lo;0;L;;;;;N;;;;; 1001;MYANMAR LETTER KHA;Lo;0;L;;;;;N;;;;; 1002;MYANMAR LETTER GA;Lo;0;L;;;;;N;;;;; @@ -2956,13 +3223,16 @@ 101F;MYANMAR LETTER HA;Lo;0;L;;;;;N;;;;; 1020;MYANMAR LETTER LLA;Lo;0;L;;;;;N;;;;; 1021;MYANMAR LETTER A;Lo;0;L;;;;;N;;;;; +1022;MYANMAR LETTER SHAN A;Lo;0;L;;;;;N;;;;; 1023;MYANMAR LETTER I;Lo;0;L;;;;;N;;;;; 1024;MYANMAR LETTER II;Lo;0;L;;;;;N;;;;; 1025;MYANMAR LETTER U;Lo;0;L;;;;;N;;;;; 1026;MYANMAR LETTER UU;Lo;0;L;1025 102E;;;;N;;;;; 1027;MYANMAR LETTER E;Lo;0;L;;;;;N;;;;; +1028;MYANMAR LETTER MON E;Lo;0;L;;;;;N;;;;; 1029;MYANMAR LETTER O;Lo;0;L;;;;;N;;;;; 102A;MYANMAR LETTER AU;Lo;0;L;;;;;N;;;;; +102B;MYANMAR VOWEL SIGN TALL AA;Mc;0;L;;;;;N;;;;; 102C;MYANMAR VOWEL SIGN AA;Mc;0;L;;;;;N;;;;; 102D;MYANMAR VOWEL SIGN I;Mn;0;NSM;;;;;N;;;;; 102E;MYANMAR VOWEL SIGN II;Mn;0;NSM;;;;;N;;;;; @@ -2970,10 +3240,19 @@ 1030;MYANMAR VOWEL SIGN UU;Mn;0;NSM;;;;;N;;;;; 1031;MYANMAR VOWEL SIGN E;Mc;0;L;;;;;N;;;;; 1032;MYANMAR VOWEL SIGN AI;Mn;0;NSM;;;;;N;;;;; +1033;MYANMAR VOWEL SIGN MON II;Mn;0;NSM;;;;;N;;;;; +1034;MYANMAR VOWEL SIGN MON O;Mn;0;NSM;;;;;N;;;;; +1035;MYANMAR VOWEL SIGN E ABOVE;Mn;0;NSM;;;;;N;;;;; 1036;MYANMAR SIGN ANUSVARA;Mn;0;NSM;;;;;N;;;;; 1037;MYANMAR SIGN DOT BELOW;Mn;7;NSM;;;;;N;;;;; 1038;MYANMAR SIGN VISARGA;Mc;0;L;;;;;N;;;;; 1039;MYANMAR SIGN VIRAMA;Mn;9;NSM;;;;;N;;;;; +103A;MYANMAR SIGN ASAT;Mn;9;NSM;;;;;N;;;;; +103B;MYANMAR CONSONANT SIGN MEDIAL YA;Mc;0;L;;;;;N;;;;; +103C;MYANMAR CONSONANT SIGN MEDIAL RA;Mc;0;L;;;;;N;;;;; +103D;MYANMAR CONSONANT SIGN MEDIAL WA;Mn;0;NSM;;;;;N;;;;; +103E;MYANMAR CONSONANT SIGN MEDIAL HA;Mn;0;NSM;;;;;N;;;;; +103F;MYANMAR LETTER GREAT SA;Lo;0;L;;;;;N;;;;; 1040;MYANMAR DIGIT ZERO;Nd;0;L;;0;0;0;N;;;;; 1041;MYANMAR DIGIT ONE;Nd;0;L;;1;1;1;N;;;;; 1042;MYANMAR DIGIT TWO;Nd;0;L;;2;2;2;N;;;;; @@ -3000,44 +3279,110 @@ 1057;MYANMAR VOWEL SIGN VOCALIC RR;Mc;0;L;;;;;N;;;;; 1058;MYANMAR VOWEL SIGN VOCALIC L;Mn;0;NSM;;;;;N;;;;; 1059;MYANMAR VOWEL SIGN VOCALIC LL;Mn;0;NSM;;;;;N;;;;; -10A0;GEORGIAN CAPITAL LETTER AN;Lu;0;L;;;;;N;;Khutsuri;;; -10A1;GEORGIAN CAPITAL LETTER BAN;Lu;0;L;;;;;N;;Khutsuri;;; -10A2;GEORGIAN CAPITAL LETTER GAN;Lu;0;L;;;;;N;;Khutsuri;;; -10A3;GEORGIAN CAPITAL LETTER DON;Lu;0;L;;;;;N;;Khutsuri;;; -10A4;GEORGIAN CAPITAL LETTER EN;Lu;0;L;;;;;N;;Khutsuri;;; -10A5;GEORGIAN CAPITAL LETTER VIN;Lu;0;L;;;;;N;;Khutsuri;;; -10A6;GEORGIAN CAPITAL LETTER ZEN;Lu;0;L;;;;;N;;Khutsuri;;; -10A7;GEORGIAN CAPITAL LETTER TAN;Lu;0;L;;;;;N;;Khutsuri;;; -10A8;GEORGIAN CAPITAL LETTER IN;Lu;0;L;;;;;N;;Khutsuri;;; -10A9;GEORGIAN CAPITAL LETTER KAN;Lu;0;L;;;;;N;;Khutsuri;;; -10AA;GEORGIAN CAPITAL LETTER LAS;Lu;0;L;;;;;N;;Khutsuri;;; -10AB;GEORGIAN CAPITAL LETTER MAN;Lu;0;L;;;;;N;;Khutsuri;;; -10AC;GEORGIAN CAPITAL LETTER NAR;Lu;0;L;;;;;N;;Khutsuri;;; -10AD;GEORGIAN CAPITAL LETTER ON;Lu;0;L;;;;;N;;Khutsuri;;; -10AE;GEORGIAN CAPITAL LETTER PAR;Lu;0;L;;;;;N;;Khutsuri;;; -10AF;GEORGIAN CAPITAL LETTER ZHAR;Lu;0;L;;;;;N;;Khutsuri;;; -10B0;GEORGIAN CAPITAL LETTER RAE;Lu;0;L;;;;;N;;Khutsuri;;; -10B1;GEORGIAN CAPITAL LETTER SAN;Lu;0;L;;;;;N;;Khutsuri;;; -10B2;GEORGIAN CAPITAL LETTER TAR;Lu;0;L;;;;;N;;Khutsuri;;; -10B3;GEORGIAN CAPITAL LETTER UN;Lu;0;L;;;;;N;;Khutsuri;;; -10B4;GEORGIAN CAPITAL LETTER PHAR;Lu;0;L;;;;;N;;Khutsuri;;; -10B5;GEORGIAN CAPITAL LETTER KHAR;Lu;0;L;;;;;N;;Khutsuri;;; -10B6;GEORGIAN CAPITAL LETTER GHAN;Lu;0;L;;;;;N;;Khutsuri;;; -10B7;GEORGIAN CAPITAL LETTER QAR;Lu;0;L;;;;;N;;Khutsuri;;; -10B8;GEORGIAN CAPITAL LETTER SHIN;Lu;0;L;;;;;N;;Khutsuri;;; -10B9;GEORGIAN CAPITAL LETTER CHIN;Lu;0;L;;;;;N;;Khutsuri;;; -10BA;GEORGIAN CAPITAL LETTER CAN;Lu;0;L;;;;;N;;Khutsuri;;; -10BB;GEORGIAN CAPITAL LETTER JIL;Lu;0;L;;;;;N;;Khutsuri;;; -10BC;GEORGIAN CAPITAL LETTER CIL;Lu;0;L;;;;;N;;Khutsuri;;; -10BD;GEORGIAN CAPITAL LETTER CHAR;Lu;0;L;;;;;N;;Khutsuri;;; -10BE;GEORGIAN CAPITAL LETTER XAN;Lu;0;L;;;;;N;;Khutsuri;;; -10BF;GEORGIAN CAPITAL LETTER JHAN;Lu;0;L;;;;;N;;Khutsuri;;; -10C0;GEORGIAN CAPITAL LETTER HAE;Lu;0;L;;;;;N;;Khutsuri;;; -10C1;GEORGIAN CAPITAL LETTER HE;Lu;0;L;;;;;N;;Khutsuri;;; -10C2;GEORGIAN CAPITAL LETTER HIE;Lu;0;L;;;;;N;;Khutsuri;;; -10C3;GEORGIAN CAPITAL LETTER WE;Lu;0;L;;;;;N;;Khutsuri;;; -10C4;GEORGIAN CAPITAL LETTER HAR;Lu;0;L;;;;;N;;Khutsuri;;; -10C5;GEORGIAN CAPITAL LETTER HOE;Lu;0;L;;;;;N;;Khutsuri;;; +105A;MYANMAR LETTER MON NGA;Lo;0;L;;;;;N;;;;; +105B;MYANMAR LETTER MON JHA;Lo;0;L;;;;;N;;;;; +105C;MYANMAR LETTER MON BBA;Lo;0;L;;;;;N;;;;; +105D;MYANMAR LETTER MON BBE;Lo;0;L;;;;;N;;;;; +105E;MYANMAR CONSONANT SIGN MON MEDIAL NA;Mn;0;NSM;;;;;N;;;;; +105F;MYANMAR CONSONANT SIGN MON MEDIAL MA;Mn;0;NSM;;;;;N;;;;; +1060;MYANMAR CONSONANT SIGN MON MEDIAL LA;Mn;0;NSM;;;;;N;;;;; +1061;MYANMAR LETTER SGAW KAREN SHA;Lo;0;L;;;;;N;;;;; +1062;MYANMAR VOWEL SIGN SGAW KAREN EU;Mc;0;L;;;;;N;;;;; +1063;MYANMAR TONE MARK SGAW KAREN HATHI;Mc;0;L;;;;;N;;;;; +1064;MYANMAR TONE MARK SGAW KAREN KE PHO;Mc;0;L;;;;;N;;;;; +1065;MYANMAR LETTER WESTERN PWO KAREN THA;Lo;0;L;;;;;N;;;;; +1066;MYANMAR LETTER WESTERN PWO KAREN PWA;Lo;0;L;;;;;N;;;;; +1067;MYANMAR VOWEL SIGN WESTERN PWO KAREN EU;Mc;0;L;;;;;N;;;;; +1068;MYANMAR VOWEL SIGN WESTERN PWO KAREN UE;Mc;0;L;;;;;N;;;;; +1069;MYANMAR SIGN WESTERN PWO KAREN TONE-1;Mc;0;L;;;;;N;;;;; +106A;MYANMAR SIGN WESTERN PWO KAREN TONE-2;Mc;0;L;;;;;N;;;;; +106B;MYANMAR SIGN WESTERN PWO KAREN TONE-3;Mc;0;L;;;;;N;;;;; +106C;MYANMAR SIGN WESTERN PWO KAREN TONE-4;Mc;0;L;;;;;N;;;;; +106D;MYANMAR SIGN WESTERN PWO KAREN TONE-5;Mc;0;L;;;;;N;;;;; +106E;MYANMAR LETTER EASTERN PWO KAREN NNA;Lo;0;L;;;;;N;;;;; +106F;MYANMAR LETTER EASTERN PWO KAREN YWA;Lo;0;L;;;;;N;;;;; +1070;MYANMAR LETTER EASTERN PWO KAREN GHWA;Lo;0;L;;;;;N;;;;; +1071;MYANMAR VOWEL SIGN GEBA KAREN I;Mn;0;NSM;;;;;N;;;;; +1072;MYANMAR VOWEL SIGN KAYAH OE;Mn;0;NSM;;;;;N;;;;; +1073;MYANMAR VOWEL SIGN KAYAH U;Mn;0;NSM;;;;;N;;;;; +1074;MYANMAR VOWEL SIGN KAYAH EE;Mn;0;NSM;;;;;N;;;;; +1075;MYANMAR LETTER SHAN KA;Lo;0;L;;;;;N;;;;; +1076;MYANMAR LETTER SHAN KHA;Lo;0;L;;;;;N;;;;; +1077;MYANMAR LETTER SHAN GA;Lo;0;L;;;;;N;;;;; +1078;MYANMAR LETTER SHAN CA;Lo;0;L;;;;;N;;;;; +1079;MYANMAR LETTER SHAN ZA;Lo;0;L;;;;;N;;;;; +107A;MYANMAR LETTER SHAN NYA;Lo;0;L;;;;;N;;;;; +107B;MYANMAR LETTER SHAN DA;Lo;0;L;;;;;N;;;;; +107C;MYANMAR LETTER SHAN NA;Lo;0;L;;;;;N;;;;; +107D;MYANMAR LETTER SHAN PHA;Lo;0;L;;;;;N;;;;; +107E;MYANMAR LETTER SHAN FA;Lo;0;L;;;;;N;;;;; +107F;MYANMAR LETTER SHAN BA;Lo;0;L;;;;;N;;;;; +1080;MYANMAR LETTER SHAN THA;Lo;0;L;;;;;N;;;;; +1081;MYANMAR LETTER SHAN HA;Lo;0;L;;;;;N;;;;; +1082;MYANMAR CONSONANT SIGN SHAN MEDIAL WA;Mn;0;NSM;;;;;N;;;;; +1083;MYANMAR VOWEL SIGN SHAN AA;Mc;0;L;;;;;N;;;;; +1084;MYANMAR VOWEL SIGN SHAN E;Mc;0;L;;;;;N;;;;; +1085;MYANMAR VOWEL SIGN SHAN E ABOVE;Mn;0;NSM;;;;;N;;;;; +1086;MYANMAR VOWEL SIGN SHAN FINAL Y;Mn;0;NSM;;;;;N;;;;; +1087;MYANMAR SIGN SHAN TONE-2;Mc;0;L;;;;;N;;;;; +1088;MYANMAR SIGN SHAN TONE-3;Mc;0;L;;;;;N;;;;; +1089;MYANMAR SIGN SHAN TONE-5;Mc;0;L;;;;;N;;;;; +108A;MYANMAR SIGN SHAN TONE-6;Mc;0;L;;;;;N;;;;; +108B;MYANMAR SIGN SHAN COUNCIL TONE-2;Mc;0;L;;;;;N;;;;; +108C;MYANMAR SIGN SHAN COUNCIL TONE-3;Mc;0;L;;;;;N;;;;; +108D;MYANMAR SIGN SHAN COUNCIL EMPHATIC TONE;Mn;220;NSM;;;;;N;;;;; +108E;MYANMAR LETTER RUMAI PALAUNG FA;Lo;0;L;;;;;N;;;;; +108F;MYANMAR SIGN RUMAI PALAUNG TONE-5;Mc;0;L;;;;;N;;;;; +1090;MYANMAR SHAN DIGIT ZERO;Nd;0;L;;0;0;0;N;;;;; +1091;MYANMAR SHAN DIGIT ONE;Nd;0;L;;1;1;1;N;;;;; +1092;MYANMAR SHAN DIGIT TWO;Nd;0;L;;2;2;2;N;;;;; +1093;MYANMAR SHAN DIGIT THREE;Nd;0;L;;3;3;3;N;;;;; +1094;MYANMAR SHAN DIGIT FOUR;Nd;0;L;;4;4;4;N;;;;; +1095;MYANMAR SHAN DIGIT FIVE;Nd;0;L;;5;5;5;N;;;;; +1096;MYANMAR SHAN DIGIT SIX;Nd;0;L;;6;6;6;N;;;;; +1097;MYANMAR SHAN DIGIT SEVEN;Nd;0;L;;7;7;7;N;;;;; +1098;MYANMAR SHAN DIGIT EIGHT;Nd;0;L;;8;8;8;N;;;;; +1099;MYANMAR SHAN DIGIT NINE;Nd;0;L;;9;9;9;N;;;;; +109E;MYANMAR SYMBOL SHAN ONE;So;0;L;;;;;N;;;;; +109F;MYANMAR SYMBOL SHAN EXCLAMATION;So;0;L;;;;;N;;;;; +10A0;GEORGIAN CAPITAL LETTER AN;Lu;0;L;;;;;N;;Khutsuri;;2D00; +10A1;GEORGIAN CAPITAL LETTER BAN;Lu;0;L;;;;;N;;Khutsuri;;2D01; +10A2;GEORGIAN CAPITAL LETTER GAN;Lu;0;L;;;;;N;;Khutsuri;;2D02; +10A3;GEORGIAN CAPITAL LETTER DON;Lu;0;L;;;;;N;;Khutsuri;;2D03; +10A4;GEORGIAN CAPITAL LETTER EN;Lu;0;L;;;;;N;;Khutsuri;;2D04; +10A5;GEORGIAN CAPITAL LETTER VIN;Lu;0;L;;;;;N;;Khutsuri;;2D05; +10A6;GEORGIAN CAPITAL LETTER ZEN;Lu;0;L;;;;;N;;Khutsuri;;2D06; +10A7;GEORGIAN CAPITAL LETTER TAN;Lu;0;L;;;;;N;;Khutsuri;;2D07; +10A8;GEORGIAN CAPITAL LETTER IN;Lu;0;L;;;;;N;;Khutsuri;;2D08; +10A9;GEORGIAN CAPITAL LETTER KAN;Lu;0;L;;;;;N;;Khutsuri;;2D09; +10AA;GEORGIAN CAPITAL LETTER LAS;Lu;0;L;;;;;N;;Khutsuri;;2D0A; +10AB;GEORGIAN CAPITAL LETTER MAN;Lu;0;L;;;;;N;;Khutsuri;;2D0B; +10AC;GEORGIAN CAPITAL LETTER NAR;Lu;0;L;;;;;N;;Khutsuri;;2D0C; +10AD;GEORGIAN CAPITAL LETTER ON;Lu;0;L;;;;;N;;Khutsuri;;2D0D; +10AE;GEORGIAN CAPITAL LETTER PAR;Lu;0;L;;;;;N;;Khutsuri;;2D0E; +10AF;GEORGIAN CAPITAL LETTER ZHAR;Lu;0;L;;;;;N;;Khutsuri;;2D0F; +10B0;GEORGIAN CAPITAL LETTER RAE;Lu;0;L;;;;;N;;Khutsuri;;2D10; +10B1;GEORGIAN CAPITAL LETTER SAN;Lu;0;L;;;;;N;;Khutsuri;;2D11; +10B2;GEORGIAN CAPITAL LETTER TAR;Lu;0;L;;;;;N;;Khutsuri;;2D12; +10B3;GEORGIAN CAPITAL LETTER UN;Lu;0;L;;;;;N;;Khutsuri;;2D13; +10B4;GEORGIAN CAPITAL LETTER PHAR;Lu;0;L;;;;;N;;Khutsuri;;2D14; +10B5;GEORGIAN CAPITAL LETTER KHAR;Lu;0;L;;;;;N;;Khutsuri;;2D15; +10B6;GEORGIAN CAPITAL LETTER GHAN;Lu;0;L;;;;;N;;Khutsuri;;2D16; +10B7;GEORGIAN CAPITAL LETTER QAR;Lu;0;L;;;;;N;;Khutsuri;;2D17; +10B8;GEORGIAN CAPITAL LETTER SHIN;Lu;0;L;;;;;N;;Khutsuri;;2D18; +10B9;GEORGIAN CAPITAL LETTER CHIN;Lu;0;L;;;;;N;;Khutsuri;;2D19; +10BA;GEORGIAN CAPITAL LETTER CAN;Lu;0;L;;;;;N;;Khutsuri;;2D1A; +10BB;GEORGIAN CAPITAL LETTER JIL;Lu;0;L;;;;;N;;Khutsuri;;2D1B; +10BC;GEORGIAN CAPITAL LETTER CIL;Lu;0;L;;;;;N;;Khutsuri;;2D1C; +10BD;GEORGIAN CAPITAL LETTER CHAR;Lu;0;L;;;;;N;;Khutsuri;;2D1D; +10BE;GEORGIAN CAPITAL LETTER XAN;Lu;0;L;;;;;N;;Khutsuri;;2D1E; +10BF;GEORGIAN CAPITAL LETTER JHAN;Lu;0;L;;;;;N;;Khutsuri;;2D1F; +10C0;GEORGIAN CAPITAL LETTER HAE;Lu;0;L;;;;;N;;Khutsuri;;2D20; +10C1;GEORGIAN CAPITAL LETTER HE;Lu;0;L;;;;;N;;Khutsuri;;2D21; +10C2;GEORGIAN CAPITAL LETTER HIE;Lu;0;L;;;;;N;;Khutsuri;;2D22; +10C3;GEORGIAN CAPITAL LETTER WE;Lu;0;L;;;;;N;;Khutsuri;;2D23; +10C4;GEORGIAN CAPITAL LETTER HAR;Lu;0;L;;;;;N;;Khutsuri;;2D24; +10C5;GEORGIAN CAPITAL LETTER HOE;Lu;0;L;;;;;N;;Khutsuri;;2D25; 10D0;GEORGIAN LETTER AN;Lo;0;L;;;;;N;GEORGIAN SMALL LETTER AN;;;; 10D1;GEORGIAN LETTER BAN;Lo;0;L;;;;;N;GEORGIAN SMALL LETTER BAN;;;; 10D2;GEORGIAN LETTER GAN;Lo;0;L;;;;;N;GEORGIAN SMALL LETTER GAN;;;; @@ -3079,7 +3424,10 @@ 10F6;GEORGIAN LETTER FI;Lo;0;L;;;;;N;GEORGIAN SMALL LETTER FI;;;; 10F7;GEORGIAN LETTER YN;Lo;0;L;;;;;N;;;;; 10F8;GEORGIAN LETTER ELIFI;Lo;0;L;;;;;N;;;;; +10F9;GEORGIAN LETTER TURNED GAN;Lo;0;L;;;;;N;;;;; +10FA;GEORGIAN LETTER AIN;Lo;0;L;;;;;N;;;;; 10FB;GEORGIAN PARAGRAPH SEPARATOR;Po;0;L;;;;;N;;;;; +10FC;MODIFIER LETTER GEORGIAN NAR;Lm;0;L;<super> 10DC;;;;N;;;;; 1100;HANGUL CHOSEONG KIYEOK;Lo;0;L;;;;;N;;g *;;; 1101;HANGUL CHOSEONG SSANGKIYEOK;Lo;0;L;;;;;N;;gg *;;; 1102;HANGUL CHOSEONG NIEUN;Lo;0;L;;;;;N;;n *;;; @@ -3327,6 +3675,7 @@ 1204;ETHIOPIC SYLLABLE HEE;Lo;0;L;;;;;N;;;;; 1205;ETHIOPIC SYLLABLE HE;Lo;0;L;;;;;N;;;;; 1206;ETHIOPIC SYLLABLE HO;Lo;0;L;;;;;N;;;;; +1207;ETHIOPIC SYLLABLE HOA;Lo;0;L;;;;;N;;;;; 1208;ETHIOPIC SYLLABLE LA;Lo;0;L;;;;;N;;;;; 1209;ETHIOPIC SYLLABLE LU;Lo;0;L;;;;;N;;;;; 120A;ETHIOPIC SYLLABLE LI;Lo;0;L;;;;;N;;;;; @@ -3390,6 +3739,7 @@ 1244;ETHIOPIC SYLLABLE QEE;Lo;0;L;;;;;N;;;;; 1245;ETHIOPIC SYLLABLE QE;Lo;0;L;;;;;N;;;;; 1246;ETHIOPIC SYLLABLE QO;Lo;0;L;;;;;N;;;;; +1247;ETHIOPIC SYLLABLE QOA;Lo;0;L;;;;;N;;;;; 1248;ETHIOPIC SYLLABLE QWA;Lo;0;L;;;;;N;;;;; 124A;ETHIOPIC SYLLABLE QWI;Lo;0;L;;;;;N;;;;; 124B;ETHIOPIC SYLLABLE QWAA;Lo;0;L;;;;;N;;;;; @@ -3446,6 +3796,7 @@ 1284;ETHIOPIC SYLLABLE XEE;Lo;0;L;;;;;N;;;;; 1285;ETHIOPIC SYLLABLE XE;Lo;0;L;;;;;N;;;;; 1286;ETHIOPIC SYLLABLE XO;Lo;0;L;;;;;N;;;;; +1287;ETHIOPIC SYLLABLE XOA;Lo;0;L;;;;;N;;;;; 1288;ETHIOPIC SYLLABLE XWA;Lo;0;L;;;;;N;;;;; 128A;ETHIOPIC SYLLABLE XWI;Lo;0;L;;;;;N;;;;; 128B;ETHIOPIC SYLLABLE XWAA;Lo;0;L;;;;;N;;;;; @@ -3482,6 +3833,7 @@ 12AC;ETHIOPIC SYLLABLE KEE;Lo;0;L;;;;;N;;;;; 12AD;ETHIOPIC SYLLABLE KE;Lo;0;L;;;;;N;;;;; 12AE;ETHIOPIC SYLLABLE KO;Lo;0;L;;;;;N;;;;; +12AF;ETHIOPIC SYLLABLE KOA;Lo;0;L;;;;;N;;;;; 12B0;ETHIOPIC SYLLABLE KWA;Lo;0;L;;;;;N;;;;; 12B2;ETHIOPIC SYLLABLE KWI;Lo;0;L;;;;;N;;;;; 12B3;ETHIOPIC SYLLABLE KWAA;Lo;0;L;;;;;N;;;;; @@ -3506,6 +3858,7 @@ 12CC;ETHIOPIC SYLLABLE WEE;Lo;0;L;;;;;N;;;;; 12CD;ETHIOPIC SYLLABLE WE;Lo;0;L;;;;;N;;;;; 12CE;ETHIOPIC SYLLABLE WO;Lo;0;L;;;;;N;;;;; +12CF;ETHIOPIC SYLLABLE WOA;Lo;0;L;;;;;N;;;;; 12D0;ETHIOPIC SYLLABLE PHARYNGEAL A;Lo;0;L;;;;;N;;;;; 12D1;ETHIOPIC SYLLABLE PHARYNGEAL U;Lo;0;L;;;;;N;;;;; 12D2;ETHIOPIC SYLLABLE PHARYNGEAL I;Lo;0;L;;;;;N;;;;; @@ -3536,6 +3889,7 @@ 12EC;ETHIOPIC SYLLABLE YEE;Lo;0;L;;;;;N;;;;; 12ED;ETHIOPIC SYLLABLE YE;Lo;0;L;;;;;N;;;;; 12EE;ETHIOPIC SYLLABLE YO;Lo;0;L;;;;;N;;;;; +12EF;ETHIOPIC SYLLABLE YOA;Lo;0;L;;;;;N;;;;; 12F0;ETHIOPIC SYLLABLE DA;Lo;0;L;;;;;N;;;;; 12F1;ETHIOPIC SYLLABLE DU;Lo;0;L;;;;;N;;;;; 12F2;ETHIOPIC SYLLABLE DI;Lo;0;L;;;;;N;;;;; @@ -3567,6 +3921,7 @@ 130C;ETHIOPIC SYLLABLE GEE;Lo;0;L;;;;;N;;;;; 130D;ETHIOPIC SYLLABLE GE;Lo;0;L;;;;;N;;;;; 130E;ETHIOPIC SYLLABLE GO;Lo;0;L;;;;;N;;;;; +130F;ETHIOPIC SYLLABLE GOA;Lo;0;L;;;;;N;;;;; 1310;ETHIOPIC SYLLABLE GWA;Lo;0;L;;;;;N;;;;; 1312;ETHIOPIC SYLLABLE GWI;Lo;0;L;;;;;N;;;;; 1313;ETHIOPIC SYLLABLE GWAA;Lo;0;L;;;;;N;;;;; @@ -3579,6 +3934,7 @@ 131C;ETHIOPIC SYLLABLE GGEE;Lo;0;L;;;;;N;;;;; 131D;ETHIOPIC SYLLABLE GGE;Lo;0;L;;;;;N;;;;; 131E;ETHIOPIC SYLLABLE GGO;Lo;0;L;;;;;N;;;;; +131F;ETHIOPIC SYLLABLE GGWAA;Lo;0;L;;;;;N;;;;; 1320;ETHIOPIC SYLLABLE THA;Lo;0;L;;;;;N;;;;; 1321;ETHIOPIC SYLLABLE THU;Lo;0;L;;;;;N;;;;; 1322;ETHIOPIC SYLLABLE THI;Lo;0;L;;;;;N;;;;; @@ -3618,6 +3974,7 @@ 1344;ETHIOPIC SYLLABLE TZEE;Lo;0;L;;;;;N;;;;; 1345;ETHIOPIC SYLLABLE TZE;Lo;0;L;;;;;N;;;;; 1346;ETHIOPIC SYLLABLE TZO;Lo;0;L;;;;;N;;;;; +1347;ETHIOPIC SYLLABLE TZOA;Lo;0;L;;;;;N;;;;; 1348;ETHIOPIC SYLLABLE FA;Lo;0;L;;;;;N;;;;; 1349;ETHIOPIC SYLLABLE FU;Lo;0;L;;;;;N;;;;; 134A;ETHIOPIC SYLLABLE FI;Lo;0;L;;;;;N;;;;; @@ -3637,6 +3994,8 @@ 1358;ETHIOPIC SYLLABLE RYA;Lo;0;L;;;;;N;;;;; 1359;ETHIOPIC SYLLABLE MYA;Lo;0;L;;;;;N;;;;; 135A;ETHIOPIC SYLLABLE FYA;Lo;0;L;;;;;N;;;;; +135F;ETHIOPIC COMBINING GEMINATION MARK;Mn;230;NSM;;;;;N;;;;; +1360;ETHIOPIC SECTION MARK;So;0;L;;;;;N;;;;; 1361;ETHIOPIC WORDSPACE;Po;0;L;;;;;N;;;;; 1362;ETHIOPIC FULL STOP;Po;0;L;;;;;N;;;;; 1363;ETHIOPIC COMMA;Po;0;L;;;;;N;;;;; @@ -3645,15 +4004,15 @@ 1366;ETHIOPIC PREFACE COLON;Po;0;L;;;;;N;;;;; 1367;ETHIOPIC QUESTION MARK;Po;0;L;;;;;N;;;;; 1368;ETHIOPIC PARAGRAPH SEPARATOR;Po;0;L;;;;;N;;;;; -1369;ETHIOPIC DIGIT ONE;Nd;0;L;;1;1;1;N;;;;; -136A;ETHIOPIC DIGIT TWO;Nd;0;L;;2;2;2;N;;;;; -136B;ETHIOPIC DIGIT THREE;Nd;0;L;;3;3;3;N;;;;; -136C;ETHIOPIC DIGIT FOUR;Nd;0;L;;4;4;4;N;;;;; -136D;ETHIOPIC DIGIT FIVE;Nd;0;L;;5;5;5;N;;;;; -136E;ETHIOPIC DIGIT SIX;Nd;0;L;;6;6;6;N;;;;; -136F;ETHIOPIC DIGIT SEVEN;Nd;0;L;;7;7;7;N;;;;; -1370;ETHIOPIC DIGIT EIGHT;Nd;0;L;;8;8;8;N;;;;; -1371;ETHIOPIC DIGIT NINE;Nd;0;L;;9;9;9;N;;;;; +1369;ETHIOPIC DIGIT ONE;No;0;L;;;1;1;N;;;;; +136A;ETHIOPIC DIGIT TWO;No;0;L;;;2;2;N;;;;; +136B;ETHIOPIC DIGIT THREE;No;0;L;;;3;3;N;;;;; +136C;ETHIOPIC DIGIT FOUR;No;0;L;;;4;4;N;;;;; +136D;ETHIOPIC DIGIT FIVE;No;0;L;;;5;5;N;;;;; +136E;ETHIOPIC DIGIT SIX;No;0;L;;;6;6;N;;;;; +136F;ETHIOPIC DIGIT SEVEN;No;0;L;;;7;7;N;;;;; +1370;ETHIOPIC DIGIT EIGHT;No;0;L;;;8;8;N;;;;; +1371;ETHIOPIC DIGIT NINE;No;0;L;;;9;9;N;;;;; 1372;ETHIOPIC NUMBER TEN;No;0;L;;;;10;N;;;;; 1373;ETHIOPIC NUMBER TWENTY;No;0;L;;;;20;N;;;;; 1374;ETHIOPIC NUMBER THIRTY;No;0;L;;;;30;N;;;;; @@ -3665,6 +4024,32 @@ 137A;ETHIOPIC NUMBER NINETY;No;0;L;;;;90;N;;;;; 137B;ETHIOPIC NUMBER HUNDRED;No;0;L;;;;100;N;;;;; 137C;ETHIOPIC NUMBER TEN THOUSAND;No;0;L;;;;10000;N;;;;; +1380;ETHIOPIC SYLLABLE SEBATBEIT MWA;Lo;0;L;;;;;N;;;;; +1381;ETHIOPIC SYLLABLE MWI;Lo;0;L;;;;;N;;;;; +1382;ETHIOPIC SYLLABLE MWEE;Lo;0;L;;;;;N;;;;; +1383;ETHIOPIC SYLLABLE MWE;Lo;0;L;;;;;N;;;;; +1384;ETHIOPIC SYLLABLE SEBATBEIT BWA;Lo;0;L;;;;;N;;;;; +1385;ETHIOPIC SYLLABLE BWI;Lo;0;L;;;;;N;;;;; +1386;ETHIOPIC SYLLABLE BWEE;Lo;0;L;;;;;N;;;;; +1387;ETHIOPIC SYLLABLE BWE;Lo;0;L;;;;;N;;;;; +1388;ETHIOPIC SYLLABLE SEBATBEIT FWA;Lo;0;L;;;;;N;;;;; +1389;ETHIOPIC SYLLABLE FWI;Lo;0;L;;;;;N;;;;; +138A;ETHIOPIC SYLLABLE FWEE;Lo;0;L;;;;;N;;;;; +138B;ETHIOPIC SYLLABLE FWE;Lo;0;L;;;;;N;;;;; +138C;ETHIOPIC SYLLABLE SEBATBEIT PWA;Lo;0;L;;;;;N;;;;; +138D;ETHIOPIC SYLLABLE PWI;Lo;0;L;;;;;N;;;;; +138E;ETHIOPIC SYLLABLE PWEE;Lo;0;L;;;;;N;;;;; +138F;ETHIOPIC SYLLABLE PWE;Lo;0;L;;;;;N;;;;; +1390;ETHIOPIC TONAL MARK YIZET;So;0;ON;;;;;N;;;;; +1391;ETHIOPIC TONAL MARK DERET;So;0;ON;;;;;N;;;;; +1392;ETHIOPIC TONAL MARK RIKRIK;So;0;ON;;;;;N;;;;; +1393;ETHIOPIC TONAL MARK SHORT RIKRIK;So;0;ON;;;;;N;;;;; +1394;ETHIOPIC TONAL MARK DIFAT;So;0;ON;;;;;N;;;;; +1395;ETHIOPIC TONAL MARK KENAT;So;0;ON;;;;;N;;;;; +1396;ETHIOPIC TONAL MARK CHIRET;So;0;ON;;;;;N;;;;; +1397;ETHIOPIC TONAL MARK HIDET;So;0;ON;;;;;N;;;;; +1398;ETHIOPIC TONAL MARK DERET-HIDET;So;0;ON;;;;;N;;;;; +1399;ETHIOPIC TONAL MARK KURT;So;0;ON;;;;;N;;;;; 13A0;CHEROKEE LETTER A;Lo;0;L;;;;;N;;;;; 13A1;CHEROKEE LETTER E;Lo;0;L;;;;;N;;;;; 13A2;CHEROKEE LETTER I;Lo;0;L;;;;;N;;;;; @@ -4407,8 +4792,8 @@ 1698;OGHAM LETTER IFIN;Lo;0;L;;;;;N;;;;; 1699;OGHAM LETTER EAMHANCHOLL;Lo;0;L;;;;;N;;;;; 169A;OGHAM LETTER PEITH;Lo;0;L;;;;;N;;;;; -169B;OGHAM FEATHER MARK;Ps;0;ON;;;;;N;;;;; -169C;OGHAM REVERSED FEATHER MARK;Pe;0;ON;;;;;N;;;;; +169B;OGHAM FEATHER MARK;Ps;0;ON;;;;;Y;;;;; +169C;OGHAM REVERSED FEATHER MARK;Pe;0;ON;;;;;Y;;;;; 16A0;RUNIC LETTER FEHU FEOH FE F;Lo;0;L;;;;;N;;;;; 16A1;RUNIC LETTER V;Lo;0;L;;;;;N;;;;; 16A2;RUNIC LETTER URUZ UR U;Lo;0;L;;;;;N;;;;; @@ -4840,6 +5225,7 @@ 18A7;MONGOLIAN LETTER ALI GALI HALF YA;Lo;0;L;;;;;N;;;;; 18A8;MONGOLIAN LETTER MANCHU ALI GALI BHA;Lo;0;L;;;;;N;;;;; 18A9;MONGOLIAN LETTER ALI GALI DAGALGA;Mn;228;NSM;;;;;N;;;;; +18AA;MONGOLIAN LETTER MANCHU ALI GALI LHA;Lo;0;L;;;;;N;;;;; 1900;LIMBU VOWEL-CARRIER LETTER;Lo;0;L;;;;;N;;;;; 1901;LIMBU LETTER KA;Lo;0;L;;;;;N;;;;; 1902;LIMBU LETTER KHA;Lo;0;L;;;;;N;;;;; @@ -4878,9 +5264,9 @@ 1926;LIMBU VOWEL SIGN AU;Mc;0;L;;;;;N;;;;; 1927;LIMBU VOWEL SIGN E;Mn;0;NSM;;;;;N;;;;; 1928;LIMBU VOWEL SIGN O;Mn;0;NSM;;;;;N;;;;; -1929;LIMBU SUBJOINED LETTER YA;Mc;0;NSM;;;;;N;;;;; -192A;LIMBU SUBJOINED LETTER RA;Mc;0;NSM;;;;;N;;;;; -192B;LIMBU SUBJOINED LETTER WA;Mc;0;NSM;;;;;N;;;;; +1929;LIMBU SUBJOINED LETTER YA;Mc;0;L;;;;;N;;;;; +192A;LIMBU SUBJOINED LETTER RA;Mc;0;L;;;;;N;;;;; +192B;LIMBU SUBJOINED LETTER WA;Mc;0;L;;;;;N;;;;; 1930;LIMBU SMALL LETTER KA;Mc;0;L;;;;;N;;;;; 1931;LIMBU SMALL LETTER NGA;Mc;0;L;;;;;N;;;;; 1932;LIMBU SMALL LETTER ANUSVARA;Mn;0;NSM;;;;;N;;;;; @@ -4941,6 +5327,86 @@ 1972;TAI LE LETTER TONE-4;Lo;0;L;;;;;N;;;;; 1973;TAI LE LETTER TONE-5;Lo;0;L;;;;;N;;;;; 1974;TAI LE LETTER TONE-6;Lo;0;L;;;;;N;;;;; +1980;NEW TAI LUE LETTER HIGH QA;Lo;0;L;;;;;N;;;;; +1981;NEW TAI LUE LETTER LOW QA;Lo;0;L;;;;;N;;;;; +1982;NEW TAI LUE LETTER HIGH KA;Lo;0;L;;;;;N;;;;; +1983;NEW TAI LUE LETTER HIGH XA;Lo;0;L;;;;;N;;;;; +1984;NEW TAI LUE LETTER HIGH NGA;Lo;0;L;;;;;N;;;;; +1985;NEW TAI LUE LETTER LOW KA;Lo;0;L;;;;;N;;;;; +1986;NEW TAI LUE LETTER LOW XA;Lo;0;L;;;;;N;;;;; +1987;NEW TAI LUE LETTER LOW NGA;Lo;0;L;;;;;N;;;;; +1988;NEW TAI LUE LETTER HIGH TSA;Lo;0;L;;;;;N;;;;; +1989;NEW TAI LUE LETTER HIGH SA;Lo;0;L;;;;;N;;;;; +198A;NEW TAI LUE LETTER HIGH YA;Lo;0;L;;;;;N;;;;; +198B;NEW TAI LUE LETTER LOW TSA;Lo;0;L;;;;;N;;;;; +198C;NEW TAI LUE LETTER LOW SA;Lo;0;L;;;;;N;;;;; +198D;NEW TAI LUE LETTER LOW YA;Lo;0;L;;;;;N;;;;; +198E;NEW TAI LUE LETTER HIGH TA;Lo;0;L;;;;;N;;;;; +198F;NEW TAI LUE LETTER HIGH THA;Lo;0;L;;;;;N;;;;; +1990;NEW TAI LUE LETTER HIGH NA;Lo;0;L;;;;;N;;;;; +1991;NEW TAI LUE LETTER LOW TA;Lo;0;L;;;;;N;;;;; +1992;NEW TAI LUE LETTER LOW THA;Lo;0;L;;;;;N;;;;; +1993;NEW TAI LUE LETTER LOW NA;Lo;0;L;;;;;N;;;;; +1994;NEW TAI LUE LETTER HIGH PA;Lo;0;L;;;;;N;;;;; +1995;NEW TAI LUE LETTER HIGH PHA;Lo;0;L;;;;;N;;;;; +1996;NEW TAI LUE LETTER HIGH MA;Lo;0;L;;;;;N;;;;; +1997;NEW TAI LUE LETTER LOW PA;Lo;0;L;;;;;N;;;;; +1998;NEW TAI LUE LETTER LOW PHA;Lo;0;L;;;;;N;;;;; +1999;NEW TAI LUE LETTER LOW MA;Lo;0;L;;;;;N;;;;; +199A;NEW TAI LUE LETTER HIGH FA;Lo;0;L;;;;;N;;;;; +199B;NEW TAI LUE LETTER HIGH VA;Lo;0;L;;;;;N;;;;; +199C;NEW TAI LUE LETTER HIGH LA;Lo;0;L;;;;;N;;;;; +199D;NEW TAI LUE LETTER LOW FA;Lo;0;L;;;;;N;;;;; +199E;NEW TAI LUE LETTER LOW VA;Lo;0;L;;;;;N;;;;; +199F;NEW TAI LUE LETTER LOW LA;Lo;0;L;;;;;N;;;;; +19A0;NEW TAI LUE LETTER HIGH HA;Lo;0;L;;;;;N;;;;; +19A1;NEW TAI LUE LETTER HIGH DA;Lo;0;L;;;;;N;;;;; +19A2;NEW TAI LUE LETTER HIGH BA;Lo;0;L;;;;;N;;;;; +19A3;NEW TAI LUE LETTER LOW HA;Lo;0;L;;;;;N;;;;; +19A4;NEW TAI LUE LETTER LOW DA;Lo;0;L;;;;;N;;;;; +19A5;NEW TAI LUE LETTER LOW BA;Lo;0;L;;;;;N;;;;; +19A6;NEW TAI LUE LETTER HIGH KVA;Lo;0;L;;;;;N;;;;; +19A7;NEW TAI LUE LETTER HIGH XVA;Lo;0;L;;;;;N;;;;; +19A8;NEW TAI LUE LETTER LOW KVA;Lo;0;L;;;;;N;;;;; +19A9;NEW TAI LUE LETTER LOW XVA;Lo;0;L;;;;;N;;;;; +19B0;NEW TAI LUE VOWEL SIGN VOWEL SHORTENER;Mc;0;L;;;;;N;;;;; +19B1;NEW TAI LUE VOWEL SIGN AA;Mc;0;L;;;;;N;;;;; +19B2;NEW TAI LUE VOWEL SIGN II;Mc;0;L;;;;;N;;;;; +19B3;NEW TAI LUE VOWEL SIGN U;Mc;0;L;;;;;N;;;;; +19B4;NEW TAI LUE VOWEL SIGN UU;Mc;0;L;;;;;N;;;;; +19B5;NEW TAI LUE VOWEL SIGN E;Mc;0;L;;;;;N;;;;; +19B6;NEW TAI LUE VOWEL SIGN AE;Mc;0;L;;;;;N;;;;; +19B7;NEW TAI LUE VOWEL SIGN O;Mc;0;L;;;;;N;;;;; +19B8;NEW TAI LUE VOWEL SIGN OA;Mc;0;L;;;;;N;;;;; +19B9;NEW TAI LUE VOWEL SIGN UE;Mc;0;L;;;;;N;;;;; +19BA;NEW TAI LUE VOWEL SIGN AY;Mc;0;L;;;;;N;;;;; +19BB;NEW TAI LUE VOWEL SIGN AAY;Mc;0;L;;;;;N;;;;; +19BC;NEW TAI LUE VOWEL SIGN UY;Mc;0;L;;;;;N;;;;; +19BD;NEW TAI LUE VOWEL SIGN OY;Mc;0;L;;;;;N;;;;; +19BE;NEW TAI LUE VOWEL SIGN OAY;Mc;0;L;;;;;N;;;;; +19BF;NEW TAI LUE VOWEL SIGN UEY;Mc;0;L;;;;;N;;;;; +19C0;NEW TAI LUE VOWEL SIGN IY;Mc;0;L;;;;;N;;;;; +19C1;NEW TAI LUE LETTER FINAL V;Lo;0;L;;;;;N;;;;; +19C2;NEW TAI LUE LETTER FINAL NG;Lo;0;L;;;;;N;;;;; +19C3;NEW TAI LUE LETTER FINAL N;Lo;0;L;;;;;N;;;;; +19C4;NEW TAI LUE LETTER FINAL M;Lo;0;L;;;;;N;;;;; +19C5;NEW TAI LUE LETTER FINAL K;Lo;0;L;;;;;N;;;;; +19C6;NEW TAI LUE LETTER FINAL D;Lo;0;L;;;;;N;;;;; +19C7;NEW TAI LUE LETTER FINAL B;Lo;0;L;;;;;N;;;;; +19C8;NEW TAI LUE TONE MARK-1;Mc;0;L;;;;;N;;;;; +19C9;NEW TAI LUE TONE MARK-2;Mc;0;L;;;;;N;;;;; +19D0;NEW TAI LUE DIGIT ZERO;Nd;0;L;;0;0;0;N;;;;; +19D1;NEW TAI LUE DIGIT ONE;Nd;0;L;;1;1;1;N;;;;; +19D2;NEW TAI LUE DIGIT TWO;Nd;0;L;;2;2;2;N;;;;; +19D3;NEW TAI LUE DIGIT THREE;Nd;0;L;;3;3;3;N;;;;; +19D4;NEW TAI LUE DIGIT FOUR;Nd;0;L;;4;4;4;N;;;;; +19D5;NEW TAI LUE DIGIT FIVE;Nd;0;L;;5;5;5;N;;;;; +19D6;NEW TAI LUE DIGIT SIX;Nd;0;L;;6;6;6;N;;;;; +19D7;NEW TAI LUE DIGIT SEVEN;Nd;0;L;;7;7;7;N;;;;; +19D8;NEW TAI LUE DIGIT EIGHT;Nd;0;L;;8;8;8;N;;;;; +19D9;NEW TAI LUE DIGIT NINE;Nd;0;L;;9;9;9;N;;;;; +19DE;NEW TAI LUE SIGN LAE;Po;0;ON;;;;;N;;;;; +19DF;NEW TAI LUE SIGN LAEV;Po;0;ON;;;;;N;;;;; 19E0;KHMER SYMBOL PATHAMASAT;So;0;ON;;;;;N;;;;; 19E1;KHMER SYMBOL MUOY KOET;So;0;ON;;;;;N;;;;; 19E2;KHMER SYMBOL PII KOET;So;0;ON;;;;;N;;;;; @@ -4973,6 +5439,334 @@ 19FD;KHMER SYMBOL DAP-BEI ROC;So;0;ON;;;;;N;;;;; 19FE;KHMER SYMBOL DAP-BUON ROC;So;0;ON;;;;;N;;;;; 19FF;KHMER SYMBOL DAP-PRAM ROC;So;0;ON;;;;;N;;;;; +1A00;BUGINESE LETTER KA;Lo;0;L;;;;;N;;;;; +1A01;BUGINESE LETTER GA;Lo;0;L;;;;;N;;;;; +1A02;BUGINESE LETTER NGA;Lo;0;L;;;;;N;;;;; +1A03;BUGINESE LETTER NGKA;Lo;0;L;;;;;N;;;;; +1A04;BUGINESE LETTER PA;Lo;0;L;;;;;N;;;;; +1A05;BUGINESE LETTER BA;Lo;0;L;;;;;N;;;;; +1A06;BUGINESE LETTER MA;Lo;0;L;;;;;N;;;;; +1A07;BUGINESE LETTER MPA;Lo;0;L;;;;;N;;;;; +1A08;BUGINESE LETTER TA;Lo;0;L;;;;;N;;;;; +1A09;BUGINESE LETTER DA;Lo;0;L;;;;;N;;;;; +1A0A;BUGINESE LETTER NA;Lo;0;L;;;;;N;;;;; +1A0B;BUGINESE LETTER NRA;Lo;0;L;;;;;N;;;;; +1A0C;BUGINESE LETTER CA;Lo;0;L;;;;;N;;;;; +1A0D;BUGINESE LETTER JA;Lo;0;L;;;;;N;;;;; +1A0E;BUGINESE LETTER NYA;Lo;0;L;;;;;N;;;;; +1A0F;BUGINESE LETTER NYCA;Lo;0;L;;;;;N;;;;; +1A10;BUGINESE LETTER YA;Lo;0;L;;;;;N;;;;; +1A11;BUGINESE LETTER RA;Lo;0;L;;;;;N;;;;; +1A12;BUGINESE LETTER LA;Lo;0;L;;;;;N;;;;; +1A13;BUGINESE LETTER VA;Lo;0;L;;;;;N;;;;; +1A14;BUGINESE LETTER SA;Lo;0;L;;;;;N;;;;; +1A15;BUGINESE LETTER A;Lo;0;L;;;;;N;;;;; +1A16;BUGINESE LETTER HA;Lo;0;L;;;;;N;;;;; +1A17;BUGINESE VOWEL SIGN I;Mn;230;NSM;;;;;N;;;;; +1A18;BUGINESE VOWEL SIGN U;Mn;220;NSM;;;;;N;;;;; +1A19;BUGINESE VOWEL SIGN E;Mc;0;L;;;;;N;;;;; +1A1A;BUGINESE VOWEL SIGN O;Mc;0;L;;;;;N;;;;; +1A1B;BUGINESE VOWEL SIGN AE;Mc;0;L;;;;;N;;;;; +1A1E;BUGINESE PALLAWA;Po;0;L;;;;;N;;;;; +1A1F;BUGINESE END OF SECTION;Po;0;L;;;;;N;;;;; +1B00;BALINESE SIGN ULU RICEM;Mn;0;NSM;;;;;N;;ardhacandra;;; +1B01;BALINESE SIGN ULU CANDRA;Mn;0;NSM;;;;;N;;candrabindu;;; +1B02;BALINESE SIGN CECEK;Mn;0;NSM;;;;;N;;anusvara;;; +1B03;BALINESE SIGN SURANG;Mn;0;NSM;;;;;N;;repha;;; +1B04;BALINESE SIGN BISAH;Mc;0;L;;;;;N;;visarga;;; +1B05;BALINESE LETTER AKARA;Lo;0;L;;;;;N;;a;;; +1B06;BALINESE LETTER AKARA TEDUNG;Lo;0;L;1B05 1B35;;;;N;;aa;;; +1B07;BALINESE LETTER IKARA;Lo;0;L;;;;;N;;i;;; +1B08;BALINESE LETTER IKARA TEDUNG;Lo;0;L;1B07 1B35;;;;N;;ii;;; +1B09;BALINESE LETTER UKARA;Lo;0;L;;;;;N;;u;;; +1B0A;BALINESE LETTER UKARA TEDUNG;Lo;0;L;1B09 1B35;;;;N;;uu;;; +1B0B;BALINESE LETTER RA REPA;Lo;0;L;;;;;N;;vocalic r;;; +1B0C;BALINESE LETTER RA REPA TEDUNG;Lo;0;L;1B0B 1B35;;;;N;;vocalic rr;;; +1B0D;BALINESE LETTER LA LENGA;Lo;0;L;;;;;N;;vocalic l;;; +1B0E;BALINESE LETTER LA LENGA TEDUNG;Lo;0;L;1B0D 1B35;;;;N;;vocalic ll;;; +1B0F;BALINESE LETTER EKARA;Lo;0;L;;;;;N;;e;;; +1B10;BALINESE LETTER AIKARA;Lo;0;L;;;;;N;;ai;;; +1B11;BALINESE LETTER OKARA;Lo;0;L;;;;;N;;o;;; +1B12;BALINESE LETTER OKARA TEDUNG;Lo;0;L;1B11 1B35;;;;N;;au;;; +1B13;BALINESE LETTER KA;Lo;0;L;;;;;N;;;;; +1B14;BALINESE LETTER KA MAHAPRANA;Lo;0;L;;;;;N;;kha;;; +1B15;BALINESE LETTER GA;Lo;0;L;;;;;N;;;;; +1B16;BALINESE LETTER GA GORA;Lo;0;L;;;;;N;;gha;;; +1B17;BALINESE LETTER NGA;Lo;0;L;;;;;N;;;;; +1B18;BALINESE LETTER CA;Lo;0;L;;;;;N;;;;; +1B19;BALINESE LETTER CA LACA;Lo;0;L;;;;;N;;cha;;; +1B1A;BALINESE LETTER JA;Lo;0;L;;;;;N;;;;; +1B1B;BALINESE LETTER JA JERA;Lo;0;L;;;;;N;;jha;;; +1B1C;BALINESE LETTER NYA;Lo;0;L;;;;;N;;;;; +1B1D;BALINESE LETTER TA LATIK;Lo;0;L;;;;;N;;tta;;; +1B1E;BALINESE LETTER TA MURDA MAHAPRANA;Lo;0;L;;;;;N;;ttha;;; +1B1F;BALINESE LETTER DA MURDA ALPAPRANA;Lo;0;L;;;;;N;;dda;;; +1B20;BALINESE LETTER DA MURDA MAHAPRANA;Lo;0;L;;;;;N;;ddha;;; +1B21;BALINESE LETTER NA RAMBAT;Lo;0;L;;;;;N;;nna;;; +1B22;BALINESE LETTER TA;Lo;0;L;;;;;N;;;;; +1B23;BALINESE LETTER TA TAWA;Lo;0;L;;;;;N;;tha;;; +1B24;BALINESE LETTER DA;Lo;0;L;;;;;N;;;;; +1B25;BALINESE LETTER DA MADU;Lo;0;L;;;;;N;;dha;;; +1B26;BALINESE LETTER NA;Lo;0;L;;;;;N;;;;; +1B27;BALINESE LETTER PA;Lo;0;L;;;;;N;;;;; +1B28;BALINESE LETTER PA KAPAL;Lo;0;L;;;;;N;;pha;;; +1B29;BALINESE LETTER BA;Lo;0;L;;;;;N;;;;; +1B2A;BALINESE LETTER BA KEMBANG;Lo;0;L;;;;;N;;bha;;; +1B2B;BALINESE LETTER MA;Lo;0;L;;;;;N;;;;; +1B2C;BALINESE LETTER YA;Lo;0;L;;;;;N;;;;; +1B2D;BALINESE LETTER RA;Lo;0;L;;;;;N;;;;; +1B2E;BALINESE LETTER LA;Lo;0;L;;;;;N;;;;; +1B2F;BALINESE LETTER WA;Lo;0;L;;;;;N;;;;; +1B30;BALINESE LETTER SA SAGA;Lo;0;L;;;;;N;;sha;;; +1B31;BALINESE LETTER SA SAPA;Lo;0;L;;;;;N;;ssa;;; +1B32;BALINESE LETTER SA;Lo;0;L;;;;;N;;;;; +1B33;BALINESE LETTER HA;Lo;0;L;;;;;N;;;;; +1B34;BALINESE SIGN REREKAN;Mn;7;NSM;;;;;N;;nukta;;; +1B35;BALINESE VOWEL SIGN TEDUNG;Mc;0;L;;;;;N;;aa;;; +1B36;BALINESE VOWEL SIGN ULU;Mn;0;NSM;;;;;N;;i;;; +1B37;BALINESE VOWEL SIGN ULU SARI;Mn;0;NSM;;;;;N;;ii;;; +1B38;BALINESE VOWEL SIGN SUKU;Mn;0;NSM;;;;;N;;u;;; +1B39;BALINESE VOWEL SIGN SUKU ILUT;Mn;0;NSM;;;;;N;;uu;;; +1B3A;BALINESE VOWEL SIGN RA REPA;Mn;0;NSM;;;;;N;;vocalic r;;; +1B3B;BALINESE VOWEL SIGN RA REPA TEDUNG;Mc;0;L;1B3A 1B35;;;;N;;vocalic rr;;; +1B3C;BALINESE VOWEL SIGN LA LENGA;Mn;0;NSM;;;;;N;;vocalic l;;; +1B3D;BALINESE VOWEL SIGN LA LENGA TEDUNG;Mc;0;L;1B3C 1B35;;;;N;;vocalic ll;;; +1B3E;BALINESE VOWEL SIGN TALING;Mc;0;L;;;;;N;;e;;; +1B3F;BALINESE VOWEL SIGN TALING REPA;Mc;0;L;;;;;N;;ai;;; +1B40;BALINESE VOWEL SIGN TALING TEDUNG;Mc;0;L;1B3E 1B35;;;;N;;o;;; +1B41;BALINESE VOWEL SIGN TALING REPA TEDUNG;Mc;0;L;1B3F 1B35;;;;N;;au;;; +1B42;BALINESE VOWEL SIGN PEPET;Mn;0;NSM;;;;;N;;ae;;; +1B43;BALINESE VOWEL SIGN PEPET TEDUNG;Mc;0;L;1B42 1B35;;;;N;;oe;;; +1B44;BALINESE ADEG ADEG;Mc;9;L;;;;;N;;virama;;; +1B45;BALINESE LETTER KAF SASAK;Lo;0;L;;;;;N;;;;; +1B46;BALINESE LETTER KHOT SASAK;Lo;0;L;;;;;N;;;;; +1B47;BALINESE LETTER TZIR SASAK;Lo;0;L;;;;;N;;;;; +1B48;BALINESE LETTER EF SASAK;Lo;0;L;;;;;N;;;;; +1B49;BALINESE LETTER VE SASAK;Lo;0;L;;;;;N;;;;; +1B4A;BALINESE LETTER ZAL SASAK;Lo;0;L;;;;;N;;;;; +1B4B;BALINESE LETTER ASYURA SASAK;Lo;0;L;;;;;N;;;;; +1B50;BALINESE DIGIT ZERO;Nd;0;L;;0;0;0;N;;;;; +1B51;BALINESE DIGIT ONE;Nd;0;L;;1;1;1;N;;;;; +1B52;BALINESE DIGIT TWO;Nd;0;L;;2;2;2;N;;;;; +1B53;BALINESE DIGIT THREE;Nd;0;L;;3;3;3;N;;;;; +1B54;BALINESE DIGIT FOUR;Nd;0;L;;4;4;4;N;;;;; +1B55;BALINESE DIGIT FIVE;Nd;0;L;;5;5;5;N;;;;; +1B56;BALINESE DIGIT SIX;Nd;0;L;;6;6;6;N;;;;; +1B57;BALINESE DIGIT SEVEN;Nd;0;L;;7;7;7;N;;;;; +1B58;BALINESE DIGIT EIGHT;Nd;0;L;;8;8;8;N;;;;; +1B59;BALINESE DIGIT NINE;Nd;0;L;;9;9;9;N;;;;; +1B5A;BALINESE PANTI;Po;0;L;;;;;N;;section;;; +1B5B;BALINESE PAMADA;Po;0;L;;;;;N;;honorific section;;; +1B5C;BALINESE WINDU;Po;0;L;;;;;N;;punctuation ring;;; +1B5D;BALINESE CARIK PAMUNGKAH;Po;0;L;;;;;N;;colon;;; +1B5E;BALINESE CARIK SIKI;Po;0;L;;;;;N;;danda;;; +1B5F;BALINESE CARIK PAREREN;Po;0;L;;;;;N;;double danda;;; +1B60;BALINESE PAMENENG;Po;0;L;;;;;N;;line-breaking hyphen;;; +1B61;BALINESE MUSICAL SYMBOL DONG;So;0;L;;;;;N;;;;; +1B62;BALINESE MUSICAL SYMBOL DENG;So;0;L;;;;;N;;;;; +1B63;BALINESE MUSICAL SYMBOL DUNG;So;0;L;;;;;N;;;;; +1B64;BALINESE MUSICAL SYMBOL DANG;So;0;L;;;;;N;;;;; +1B65;BALINESE MUSICAL SYMBOL DANG SURANG;So;0;L;;;;;N;;;;; +1B66;BALINESE MUSICAL SYMBOL DING;So;0;L;;;;;N;;;;; +1B67;BALINESE MUSICAL SYMBOL DAENG;So;0;L;;;;;N;;;;; +1B68;BALINESE MUSICAL SYMBOL DEUNG;So;0;L;;;;;N;;;;; +1B69;BALINESE MUSICAL SYMBOL DAING;So;0;L;;;;;N;;;;; +1B6A;BALINESE MUSICAL SYMBOL DANG GEDE;So;0;L;;;;;N;;;;; +1B6B;BALINESE MUSICAL SYMBOL COMBINING TEGEH;Mn;230;NSM;;;;;N;;;;; +1B6C;BALINESE MUSICAL SYMBOL COMBINING ENDEP;Mn;220;NSM;;;;;N;;;;; +1B6D;BALINESE MUSICAL SYMBOL COMBINING KEMPUL;Mn;230;NSM;;;;;N;;;;; +1B6E;BALINESE MUSICAL SYMBOL COMBINING KEMPLI;Mn;230;NSM;;;;;N;;;;; +1B6F;BALINESE MUSICAL SYMBOL COMBINING JEGOGAN;Mn;230;NSM;;;;;N;;;;; +1B70;BALINESE MUSICAL SYMBOL COMBINING KEMPUL WITH JEGOGAN;Mn;230;NSM;;;;;N;;;;; +1B71;BALINESE MUSICAL SYMBOL COMBINING KEMPLI WITH JEGOGAN;Mn;230;NSM;;;;;N;;;;; +1B72;BALINESE MUSICAL SYMBOL COMBINING BENDE;Mn;230;NSM;;;;;N;;;;; +1B73;BALINESE MUSICAL SYMBOL COMBINING GONG;Mn;230;NSM;;;;;N;;;;; +1B74;BALINESE MUSICAL SYMBOL RIGHT-HAND OPEN DUG;So;0;L;;;;;N;;;;; +1B75;BALINESE MUSICAL SYMBOL RIGHT-HAND OPEN DAG;So;0;L;;;;;N;;;;; +1B76;BALINESE MUSICAL SYMBOL RIGHT-HAND CLOSED TUK;So;0;L;;;;;N;;;;; +1B77;BALINESE MUSICAL SYMBOL RIGHT-HAND CLOSED TAK;So;0;L;;;;;N;;;;; +1B78;BALINESE MUSICAL SYMBOL LEFT-HAND OPEN PANG;So;0;L;;;;;N;;;;; +1B79;BALINESE MUSICAL SYMBOL LEFT-HAND OPEN PUNG;So;0;L;;;;;N;;;;; +1B7A;BALINESE MUSICAL SYMBOL LEFT-HAND CLOSED PLAK;So;0;L;;;;;N;;;;; +1B7B;BALINESE MUSICAL SYMBOL LEFT-HAND CLOSED PLUK;So;0;L;;;;;N;;;;; +1B7C;BALINESE MUSICAL SYMBOL LEFT-HAND OPEN PING;So;0;L;;;;;N;;;;; +1B80;SUNDANESE SIGN PANYECEK;Mn;0;NSM;;;;;N;;;;; +1B81;SUNDANESE SIGN PANGLAYAR;Mn;0;NSM;;;;;N;;;;; +1B82;SUNDANESE SIGN PANGWISAD;Mc;0;L;;;;;N;;;;; +1B83;SUNDANESE LETTER A;Lo;0;L;;;;;N;;;;; +1B84;SUNDANESE LETTER I;Lo;0;L;;;;;N;;;;; +1B85;SUNDANESE LETTER U;Lo;0;L;;;;;N;;;;; +1B86;SUNDANESE LETTER AE;Lo;0;L;;;;;N;;;;; +1B87;SUNDANESE LETTER O;Lo;0;L;;;;;N;;;;; +1B88;SUNDANESE LETTER E;Lo;0;L;;;;;N;;;;; +1B89;SUNDANESE LETTER EU;Lo;0;L;;;;;N;;;;; +1B8A;SUNDANESE LETTER KA;Lo;0;L;;;;;N;;;;; +1B8B;SUNDANESE LETTER QA;Lo;0;L;;;;;N;;;;; +1B8C;SUNDANESE LETTER GA;Lo;0;L;;;;;N;;;;; +1B8D;SUNDANESE LETTER NGA;Lo;0;L;;;;;N;;;;; +1B8E;SUNDANESE LETTER CA;Lo;0;L;;;;;N;;;;; +1B8F;SUNDANESE LETTER JA;Lo;0;L;;;;;N;;;;; +1B90;SUNDANESE LETTER ZA;Lo;0;L;;;;;N;;;;; +1B91;SUNDANESE LETTER NYA;Lo;0;L;;;;;N;;;;; +1B92;SUNDANESE LETTER TA;Lo;0;L;;;;;N;;;;; +1B93;SUNDANESE LETTER DA;Lo;0;L;;;;;N;;;;; +1B94;SUNDANESE LETTER NA;Lo;0;L;;;;;N;;;;; +1B95;SUNDANESE LETTER PA;Lo;0;L;;;;;N;;;;; +1B96;SUNDANESE LETTER FA;Lo;0;L;;;;;N;;;;; +1B97;SUNDANESE LETTER VA;Lo;0;L;;;;;N;;;;; +1B98;SUNDANESE LETTER BA;Lo;0;L;;;;;N;;;;; +1B99;SUNDANESE LETTER MA;Lo;0;L;;;;;N;;;;; +1B9A;SUNDANESE LETTER YA;Lo;0;L;;;;;N;;;;; +1B9B;SUNDANESE LETTER RA;Lo;0;L;;;;;N;;;;; +1B9C;SUNDANESE LETTER LA;Lo;0;L;;;;;N;;;;; +1B9D;SUNDANESE LETTER WA;Lo;0;L;;;;;N;;;;; +1B9E;SUNDANESE LETTER SA;Lo;0;L;;;;;N;;;;; +1B9F;SUNDANESE LETTER XA;Lo;0;L;;;;;N;;;;; +1BA0;SUNDANESE LETTER HA;Lo;0;L;;;;;N;;;;; +1BA1;SUNDANESE CONSONANT SIGN PAMINGKAL;Mc;0;L;;;;;N;;;;; +1BA2;SUNDANESE CONSONANT SIGN PANYAKRA;Mn;0;NSM;;;;;N;;;;; +1BA3;SUNDANESE CONSONANT SIGN PANYIKU;Mn;0;NSM;;;;;N;;;;; +1BA4;SUNDANESE VOWEL SIGN PANGHULU;Mn;0;NSM;;;;;N;;;;; +1BA5;SUNDANESE VOWEL SIGN PANYUKU;Mn;0;NSM;;;;;N;;;;; +1BA6;SUNDANESE VOWEL SIGN PANAELAENG;Mc;0;L;;;;;N;;;;; +1BA7;SUNDANESE VOWEL SIGN PANOLONG;Mc;0;L;;;;;N;;;;; +1BA8;SUNDANESE VOWEL SIGN PAMEPET;Mn;0;NSM;;;;;N;;;;; +1BA9;SUNDANESE VOWEL SIGN PANEULEUNG;Mn;0;NSM;;;;;N;;;;; +1BAA;SUNDANESE SIGN PAMAAEH;Mc;9;L;;;;;N;;;;; +1BAE;SUNDANESE LETTER KHA;Lo;0;L;;;;;N;;;;; +1BAF;SUNDANESE LETTER SYA;Lo;0;L;;;;;N;;;;; +1BB0;SUNDANESE DIGIT ZERO;Nd;0;L;;0;0;0;N;;;;; +1BB1;SUNDANESE DIGIT ONE;Nd;0;L;;1;1;1;N;;;;; +1BB2;SUNDANESE DIGIT TWO;Nd;0;L;;2;2;2;N;;;;; +1BB3;SUNDANESE DIGIT THREE;Nd;0;L;;3;3;3;N;;;;; +1BB4;SUNDANESE DIGIT FOUR;Nd;0;L;;4;4;4;N;;;;; +1BB5;SUNDANESE DIGIT FIVE;Nd;0;L;;5;5;5;N;;;;; +1BB6;SUNDANESE DIGIT SIX;Nd;0;L;;6;6;6;N;;;;; +1BB7;SUNDANESE DIGIT SEVEN;Nd;0;L;;7;7;7;N;;;;; +1BB8;SUNDANESE DIGIT EIGHT;Nd;0;L;;8;8;8;N;;;;; +1BB9;SUNDANESE DIGIT NINE;Nd;0;L;;9;9;9;N;;;;; +1C00;LEPCHA LETTER KA;Lo;0;L;;;;;N;;;;; +1C01;LEPCHA LETTER KLA;Lo;0;L;;;;;N;;;;; +1C02;LEPCHA LETTER KHA;Lo;0;L;;;;;N;;;;; +1C03;LEPCHA LETTER GA;Lo;0;L;;;;;N;;;;; +1C04;LEPCHA LETTER GLA;Lo;0;L;;;;;N;;;;; +1C05;LEPCHA LETTER NGA;Lo;0;L;;;;;N;;;;; +1C06;LEPCHA LETTER CA;Lo;0;L;;;;;N;;;;; +1C07;LEPCHA LETTER CHA;Lo;0;L;;;;;N;;;;; +1C08;LEPCHA LETTER JA;Lo;0;L;;;;;N;;;;; +1C09;LEPCHA LETTER NYA;Lo;0;L;;;;;N;;;;; +1C0A;LEPCHA LETTER TA;Lo;0;L;;;;;N;;;;; +1C0B;LEPCHA LETTER THA;Lo;0;L;;;;;N;;;;; +1C0C;LEPCHA LETTER DA;Lo;0;L;;;;;N;;;;; +1C0D;LEPCHA LETTER NA;Lo;0;L;;;;;N;;;;; +1C0E;LEPCHA LETTER PA;Lo;0;L;;;;;N;;;;; +1C0F;LEPCHA LETTER PLA;Lo;0;L;;;;;N;;;;; +1C10;LEPCHA LETTER PHA;Lo;0;L;;;;;N;;;;; +1C11;LEPCHA LETTER FA;Lo;0;L;;;;;N;;;;; +1C12;LEPCHA LETTER FLA;Lo;0;L;;;;;N;;;;; +1C13;LEPCHA LETTER BA;Lo;0;L;;;;;N;;;;; +1C14;LEPCHA LETTER BLA;Lo;0;L;;;;;N;;;;; +1C15;LEPCHA LETTER MA;Lo;0;L;;;;;N;;;;; +1C16;LEPCHA LETTER MLA;Lo;0;L;;;;;N;;;;; +1C17;LEPCHA LETTER TSA;Lo;0;L;;;;;N;;;;; +1C18;LEPCHA LETTER TSHA;Lo;0;L;;;;;N;;;;; +1C19;LEPCHA LETTER DZA;Lo;0;L;;;;;N;;;;; +1C1A;LEPCHA LETTER YA;Lo;0;L;;;;;N;;;;; +1C1B;LEPCHA LETTER RA;Lo;0;L;;;;;N;;;;; +1C1C;LEPCHA LETTER LA;Lo;0;L;;;;;N;;;;; +1C1D;LEPCHA LETTER HA;Lo;0;L;;;;;N;;;;; +1C1E;LEPCHA LETTER HLA;Lo;0;L;;;;;N;;;;; +1C1F;LEPCHA LETTER VA;Lo;0;L;;;;;N;;;;; +1C20;LEPCHA LETTER SA;Lo;0;L;;;;;N;;;;; +1C21;LEPCHA LETTER SHA;Lo;0;L;;;;;N;;;;; +1C22;LEPCHA LETTER WA;Lo;0;L;;;;;N;;;;; +1C23;LEPCHA LETTER A;Lo;0;L;;;;;N;;;;; +1C24;LEPCHA SUBJOINED LETTER YA;Mc;0;L;;;;;N;;;;; +1C25;LEPCHA SUBJOINED LETTER RA;Mc;0;L;;;;;N;;;;; +1C26;LEPCHA VOWEL SIGN AA;Mc;0;L;;;;;N;;;;; +1C27;LEPCHA VOWEL SIGN I;Mc;0;L;;;;;N;;;;; +1C28;LEPCHA VOWEL SIGN O;Mc;0;L;;;;;N;;;;; +1C29;LEPCHA VOWEL SIGN OO;Mc;0;L;;;;;N;;;;; +1C2A;LEPCHA VOWEL SIGN U;Mc;0;L;;;;;N;;;;; +1C2B;LEPCHA VOWEL SIGN UU;Mc;0;L;;;;;N;;;;; +1C2C;LEPCHA VOWEL SIGN E;Mn;0;NSM;;;;;N;;;;; +1C2D;LEPCHA CONSONANT SIGN K;Mn;0;NSM;;;;;N;;;;; +1C2E;LEPCHA CONSONANT SIGN M;Mn;0;NSM;;;;;N;;;;; +1C2F;LEPCHA CONSONANT SIGN L;Mn;0;NSM;;;;;N;;;;; +1C30;LEPCHA CONSONANT SIGN N;Mn;0;NSM;;;;;N;;;;; +1C31;LEPCHA CONSONANT SIGN P;Mn;0;NSM;;;;;N;;;;; +1C32;LEPCHA CONSONANT SIGN R;Mn;0;NSM;;;;;N;;;;; +1C33;LEPCHA CONSONANT SIGN T;Mn;0;NSM;;;;;N;;;;; +1C34;LEPCHA CONSONANT SIGN NYIN-DO;Mc;0;L;;;;;N;;;;; +1C35;LEPCHA CONSONANT SIGN KANG;Mc;0;L;;;;;N;;;;; +1C36;LEPCHA SIGN RAN;Mn;0;NSM;;;;;N;;;;; +1C37;LEPCHA SIGN NUKTA;Mn;7;NSM;;;;;N;;;;; +1C3B;LEPCHA PUNCTUATION TA-ROL;Po;0;L;;;;;N;;;;; +1C3C;LEPCHA PUNCTUATION NYET THYOOM TA-ROL;Po;0;L;;;;;N;;;;; +1C3D;LEPCHA PUNCTUATION CER-WA;Po;0;L;;;;;N;;;;; +1C3E;LEPCHA PUNCTUATION TSHOOK CER-WA;Po;0;L;;;;;N;;;;; +1C3F;LEPCHA PUNCTUATION TSHOOK;Po;0;L;;;;;N;;;;; +1C40;LEPCHA DIGIT ZERO;Nd;0;L;;0;0;0;N;;;;; +1C41;LEPCHA DIGIT ONE;Nd;0;L;;1;1;1;N;;;;; +1C42;LEPCHA DIGIT TWO;Nd;0;L;;2;2;2;N;;;;; +1C43;LEPCHA DIGIT THREE;Nd;0;L;;3;3;3;N;;;;; +1C44;LEPCHA DIGIT FOUR;Nd;0;L;;4;4;4;N;;;;; +1C45;LEPCHA DIGIT FIVE;Nd;0;L;;5;5;5;N;;;;; +1C46;LEPCHA DIGIT SIX;Nd;0;L;;6;6;6;N;;;;; +1C47;LEPCHA DIGIT SEVEN;Nd;0;L;;7;7;7;N;;;;; +1C48;LEPCHA DIGIT EIGHT;Nd;0;L;;8;8;8;N;;;;; +1C49;LEPCHA DIGIT NINE;Nd;0;L;;9;9;9;N;;;;; +1C4D;LEPCHA LETTER TTA;Lo;0;L;;;;;N;;;;; +1C4E;LEPCHA LETTER TTHA;Lo;0;L;;;;;N;;;;; +1C4F;LEPCHA LETTER DDA;Lo;0;L;;;;;N;;;;; +1C50;OL CHIKI DIGIT ZERO;Nd;0;L;;0;0;0;N;;;;; +1C51;OL CHIKI DIGIT ONE;Nd;0;L;;1;1;1;N;;;;; +1C52;OL CHIKI DIGIT TWO;Nd;0;L;;2;2;2;N;;;;; +1C53;OL CHIKI DIGIT THREE;Nd;0;L;;3;3;3;N;;;;; +1C54;OL CHIKI DIGIT FOUR;Nd;0;L;;4;4;4;N;;;;; +1C55;OL CHIKI DIGIT FIVE;Nd;0;L;;5;5;5;N;;;;; +1C56;OL CHIKI DIGIT SIX;Nd;0;L;;6;6;6;N;;;;; +1C57;OL CHIKI DIGIT SEVEN;Nd;0;L;;7;7;7;N;;;;; +1C58;OL CHIKI DIGIT EIGHT;Nd;0;L;;8;8;8;N;;;;; +1C59;OL CHIKI DIGIT NINE;Nd;0;L;;9;9;9;N;;;;; +1C5A;OL CHIKI LETTER LA;Lo;0;L;;;;;N;;;;; +1C5B;OL CHIKI LETTER AT;Lo;0;L;;;;;N;;;;; +1C5C;OL CHIKI LETTER AG;Lo;0;L;;;;;N;;;;; +1C5D;OL CHIKI LETTER ANG;Lo;0;L;;;;;N;;;;; +1C5E;OL CHIKI LETTER AL;Lo;0;L;;;;;N;;;;; +1C5F;OL CHIKI LETTER LAA;Lo;0;L;;;;;N;;;;; +1C60;OL CHIKI LETTER AAK;Lo;0;L;;;;;N;;;;; +1C61;OL CHIKI LETTER AAJ;Lo;0;L;;;;;N;;;;; +1C62;OL CHIKI LETTER AAM;Lo;0;L;;;;;N;;;;; +1C63;OL CHIKI LETTER AAW;Lo;0;L;;;;;N;;;;; +1C64;OL CHIKI LETTER LI;Lo;0;L;;;;;N;;;;; +1C65;OL CHIKI LETTER IS;Lo;0;L;;;;;N;;;;; +1C66;OL CHIKI LETTER IH;Lo;0;L;;;;;N;;;;; +1C67;OL CHIKI LETTER INY;Lo;0;L;;;;;N;;;;; +1C68;OL CHIKI LETTER IR;Lo;0;L;;;;;N;;;;; +1C69;OL CHIKI LETTER LU;Lo;0;L;;;;;N;;;;; +1C6A;OL CHIKI LETTER UC;Lo;0;L;;;;;N;;;;; +1C6B;OL CHIKI LETTER UD;Lo;0;L;;;;;N;;;;; +1C6C;OL CHIKI LETTER UNN;Lo;0;L;;;;;N;;;;; +1C6D;OL CHIKI LETTER UY;Lo;0;L;;;;;N;;;;; +1C6E;OL CHIKI LETTER LE;Lo;0;L;;;;;N;;;;; +1C6F;OL CHIKI LETTER EP;Lo;0;L;;;;;N;;;;; +1C70;OL CHIKI LETTER EDD;Lo;0;L;;;;;N;;;;; +1C71;OL CHIKI LETTER EN;Lo;0;L;;;;;N;;;;; +1C72;OL CHIKI LETTER ERR;Lo;0;L;;;;;N;;;;; +1C73;OL CHIKI LETTER LO;Lo;0;L;;;;;N;;;;; +1C74;OL CHIKI LETTER OTT;Lo;0;L;;;;;N;;;;; +1C75;OL CHIKI LETTER OB;Lo;0;L;;;;;N;;;;; +1C76;OL CHIKI LETTER OV;Lo;0;L;;;;;N;;;;; +1C77;OL CHIKI LETTER OH;Lo;0;L;;;;;N;;;;; +1C78;OL CHIKI MU TTUDDAG;Lm;0;L;;;;;N;;;;; +1C79;OL CHIKI GAAHLAA TTUDDAAG;Lm;0;L;;;;;N;;;;; +1C7A;OL CHIKI MU-GAAHLAA TTUDDAAG;Lm;0;L;;;;;N;;;;; +1C7B;OL CHIKI RELAA;Lm;0;L;;;;;N;;;;; +1C7C;OL CHIKI PHAARKAA;Lm;0;L;;;;;N;;;;; +1C7D;OL CHIKI AHAD;Lm;0;L;;;;;N;;;;; +1C7E;OL CHIKI PUNCTUATION MUCAAD;Po;0;L;;;;;N;;;;; +1C7F;OL CHIKI PUNCTUATION DOUBLE MUCAAD;Po;0;L;;;;;N;;;;; 1D00;LATIN LETTER SMALL CAPITAL A;Ll;0;L;;;;;N;;;;; 1D01;LATIN LETTER SMALL CAPITAL AE;Ll;0;L;;;;;N;;;;; 1D02;LATIN SMALL LETTER TURNED AE;Ll;0;L;;;;;N;;;;; @@ -5081,6 +5875,131 @@ 1D69;GREEK SUBSCRIPT SMALL LETTER PHI;Ll;0;L;<sub> 03C6;;;;N;;;;; 1D6A;GREEK SUBSCRIPT SMALL LETTER CHI;Ll;0;L;<sub> 03C7;;;;N;;;;; 1D6B;LATIN SMALL LETTER UE;Ll;0;L;;;;;N;;;;; +1D6C;LATIN SMALL LETTER B WITH MIDDLE TILDE;Ll;0;L;;;;;N;;;;; +1D6D;LATIN SMALL LETTER D WITH MIDDLE TILDE;Ll;0;L;;;;;N;;;;; +1D6E;LATIN SMALL LETTER F WITH MIDDLE TILDE;Ll;0;L;;;;;N;;;;; +1D6F;LATIN SMALL LETTER M WITH MIDDLE TILDE;Ll;0;L;;;;;N;;;;; +1D70;LATIN SMALL LETTER N WITH MIDDLE TILDE;Ll;0;L;;;;;N;;;;; +1D71;LATIN SMALL LETTER P WITH MIDDLE TILDE;Ll;0;L;;;;;N;;;;; +1D72;LATIN SMALL LETTER R WITH MIDDLE TILDE;Ll;0;L;;;;;N;;;;; +1D73;LATIN SMALL LETTER R WITH FISHHOOK AND MIDDLE TILDE;Ll;0;L;;;;;N;;;;; +1D74;LATIN SMALL LETTER S WITH MIDDLE TILDE;Ll;0;L;;;;;N;;;;; +1D75;LATIN SMALL LETTER T WITH MIDDLE TILDE;Ll;0;L;;;;;N;;;;; +1D76;LATIN SMALL LETTER Z WITH MIDDLE TILDE;Ll;0;L;;;;;N;;;;; +1D77;LATIN SMALL LETTER TURNED G;Ll;0;L;;;;;N;;;;; +1D78;MODIFIER LETTER CYRILLIC EN;Lm;0;L;<super> 043D;;;;N;;;;; +1D79;LATIN SMALL LETTER INSULAR G;Ll;0;L;;;;;N;;;A77D;;A77D +1D7A;LATIN SMALL LETTER TH WITH STRIKETHROUGH;Ll;0;L;;;;;N;;;;; +1D7B;LATIN SMALL CAPITAL LETTER I WITH STROKE;Ll;0;L;;;;;N;;;;; +1D7C;LATIN SMALL LETTER IOTA WITH STROKE;Ll;0;L;;;;;N;;;;; +1D7D;LATIN SMALL LETTER P WITH STROKE;Ll;0;L;;;;;N;;;2C63;;2C63 +1D7E;LATIN SMALL CAPITAL LETTER U WITH STROKE;Ll;0;L;;;;;N;;;;; +1D7F;LATIN SMALL LETTER UPSILON WITH STROKE;Ll;0;L;;;;;N;;;;; +1D80;LATIN SMALL LETTER B WITH PALATAL HOOK;Ll;0;L;;;;;N;;;;; +1D81;LATIN SMALL LETTER D WITH PALATAL HOOK;Ll;0;L;;;;;N;;;;; +1D82;LATIN SMALL LETTER F WITH PALATAL HOOK;Ll;0;L;;;;;N;;;;; +1D83;LATIN SMALL LETTER G WITH PALATAL HOOK;Ll;0;L;;;;;N;;;;; +1D84;LATIN SMALL LETTER K WITH PALATAL HOOK;Ll;0;L;;;;;N;;;;; +1D85;LATIN SMALL LETTER L WITH PALATAL HOOK;Ll;0;L;;;;;N;;;;; +1D86;LATIN SMALL LETTER M WITH PALATAL HOOK;Ll;0;L;;;;;N;;;;; +1D87;LATIN SMALL LETTER N WITH PALATAL HOOK;Ll;0;L;;;;;N;;;;; +1D88;LATIN SMALL LETTER P WITH PALATAL HOOK;Ll;0;L;;;;;N;;;;; +1D89;LATIN SMALL LETTER R WITH PALATAL HOOK;Ll;0;L;;;;;N;;;;; +1D8A;LATIN SMALL LETTER S WITH PALATAL HOOK;Ll;0;L;;;;;N;;;;; +1D8B;LATIN SMALL LETTER ESH WITH PALATAL HOOK;Ll;0;L;;;;;N;;;;; +1D8C;LATIN SMALL LETTER V WITH PALATAL HOOK;Ll;0;L;;;;;N;;;;; +1D8D;LATIN SMALL LETTER X WITH PALATAL HOOK;Ll;0;L;;;;;N;;;;; +1D8E;LATIN SMALL LETTER Z WITH PALATAL HOOK;Ll;0;L;;;;;N;;;;; +1D8F;LATIN SMALL LETTER A WITH RETROFLEX HOOK;Ll;0;L;;;;;N;;;;; +1D90;LATIN SMALL LETTER ALPHA WITH RETROFLEX HOOK;Ll;0;L;;;;;N;;;;; +1D91;LATIN SMALL LETTER D WITH HOOK AND TAIL;Ll;0;L;;;;;N;;;;; +1D92;LATIN SMALL LETTER E WITH RETROFLEX HOOK;Ll;0;L;;;;;N;;;;; +1D93;LATIN SMALL LETTER OPEN E WITH RETROFLEX HOOK;Ll;0;L;;;;;N;;;;; +1D94;LATIN SMALL LETTER REVERSED OPEN E WITH RETROFLEX HOOK;Ll;0;L;;;;;N;;;;; +1D95;LATIN SMALL LETTER SCHWA WITH RETROFLEX HOOK;Ll;0;L;;;;;N;;;;; +1D96;LATIN SMALL LETTER I WITH RETROFLEX HOOK;Ll;0;L;;;;;N;;;;; +1D97;LATIN SMALL LETTER OPEN O WITH RETROFLEX HOOK;Ll;0;L;;;;;N;;;;; +1D98;LATIN SMALL LETTER ESH WITH RETROFLEX HOOK;Ll;0;L;;;;;N;;;;; +1D99;LATIN SMALL LETTER U WITH RETROFLEX HOOK;Ll;0;L;;;;;N;;;;; +1D9A;LATIN SMALL LETTER EZH WITH RETROFLEX HOOK;Ll;0;L;;;;;N;;;;; +1D9B;MODIFIER LETTER SMALL TURNED ALPHA;Lm;0;L;<super> 0252;;;;N;;;;; +1D9C;MODIFIER LETTER SMALL C;Lm;0;L;<super> 0063;;;;N;;;;; +1D9D;MODIFIER LETTER SMALL C WITH CURL;Lm;0;L;<super> 0255;;;;N;;;;; +1D9E;MODIFIER LETTER SMALL ETH;Lm;0;L;<super> 00F0;;;;N;;;;; +1D9F;MODIFIER LETTER SMALL REVERSED OPEN E;Lm;0;L;<super> 025C;;;;N;;;;; +1DA0;MODIFIER LETTER SMALL F;Lm;0;L;<super> 0066;;;;N;;;;; +1DA1;MODIFIER LETTER SMALL DOTLESS J WITH STROKE;Lm;0;L;<super> 025F;;;;N;;;;; +1DA2;MODIFIER LETTER SMALL SCRIPT G;Lm;0;L;<super> 0261;;;;N;;;;; +1DA3;MODIFIER LETTER SMALL TURNED H;Lm;0;L;<super> 0265;;;;N;;;;; +1DA4;MODIFIER LETTER SMALL I WITH STROKE;Lm;0;L;<super> 0268;;;;N;;;;; +1DA5;MODIFIER LETTER SMALL IOTA;Lm;0;L;<super> 0269;;;;N;;;;; +1DA6;MODIFIER LETTER SMALL CAPITAL I;Lm;0;L;<super> 026A;;;;N;;;;; +1DA7;MODIFIER LETTER SMALL CAPITAL I WITH STROKE;Lm;0;L;<super> 1D7B;;;;N;;;;; +1DA8;MODIFIER LETTER SMALL J WITH CROSSED-TAIL;Lm;0;L;<super> 029D;;;;N;;;;; +1DA9;MODIFIER LETTER SMALL L WITH RETROFLEX HOOK;Lm;0;L;<super> 026D;;;;N;;;;; +1DAA;MODIFIER LETTER SMALL L WITH PALATAL HOOK;Lm;0;L;<super> 1D85;;;;N;;;;; +1DAB;MODIFIER LETTER SMALL CAPITAL L;Lm;0;L;<super> 029F;;;;N;;;;; +1DAC;MODIFIER LETTER SMALL M WITH HOOK;Lm;0;L;<super> 0271;;;;N;;;;; +1DAD;MODIFIER LETTER SMALL TURNED M WITH LONG LEG;Lm;0;L;<super> 0270;;;;N;;;;; +1DAE;MODIFIER LETTER SMALL N WITH LEFT HOOK;Lm;0;L;<super> 0272;;;;N;;;;; +1DAF;MODIFIER LETTER SMALL N WITH RETROFLEX HOOK;Lm;0;L;<super> 0273;;;;N;;;;; +1DB0;MODIFIER LETTER SMALL CAPITAL N;Lm;0;L;<super> 0274;;;;N;;;;; +1DB1;MODIFIER LETTER SMALL BARRED O;Lm;0;L;<super> 0275;;;;N;;;;; +1DB2;MODIFIER LETTER SMALL PHI;Lm;0;L;<super> 0278;;;;N;;;;; +1DB3;MODIFIER LETTER SMALL S WITH HOOK;Lm;0;L;<super> 0282;;;;N;;;;; +1DB4;MODIFIER LETTER SMALL ESH;Lm;0;L;<super> 0283;;;;N;;;;; +1DB5;MODIFIER LETTER SMALL T WITH PALATAL HOOK;Lm;0;L;<super> 01AB;;;;N;;;;; +1DB6;MODIFIER LETTER SMALL U BAR;Lm;0;L;<super> 0289;;;;N;;;;; +1DB7;MODIFIER LETTER SMALL UPSILON;Lm;0;L;<super> 028A;;;;N;;;;; +1DB8;MODIFIER LETTER SMALL CAPITAL U;Lm;0;L;<super> 1D1C;;;;N;;;;; +1DB9;MODIFIER LETTER SMALL V WITH HOOK;Lm;0;L;<super> 028B;;;;N;;;;; +1DBA;MODIFIER LETTER SMALL TURNED V;Lm;0;L;<super> 028C;;;;N;;;;; +1DBB;MODIFIER LETTER SMALL Z;Lm;0;L;<super> 007A;;;;N;;;;; +1DBC;MODIFIER LETTER SMALL Z WITH RETROFLEX HOOK;Lm;0;L;<super> 0290;;;;N;;;;; +1DBD;MODIFIER LETTER SMALL Z WITH CURL;Lm;0;L;<super> 0291;;;;N;;;;; +1DBE;MODIFIER LETTER SMALL EZH;Lm;0;L;<super> 0292;;;;N;;;;; +1DBF;MODIFIER LETTER SMALL THETA;Lm;0;L;<super> 03B8;;;;N;;;;; +1DC0;COMBINING DOTTED GRAVE ACCENT;Mn;230;NSM;;;;;N;;;;; +1DC1;COMBINING DOTTED ACUTE ACCENT;Mn;230;NSM;;;;;N;;;;; +1DC2;COMBINING SNAKE BELOW;Mn;220;NSM;;;;;N;;;;; +1DC3;COMBINING SUSPENSION MARK;Mn;230;NSM;;;;;N;;;;; +1DC4;COMBINING MACRON-ACUTE;Mn;230;NSM;;;;;N;;;;; +1DC5;COMBINING GRAVE-MACRON;Mn;230;NSM;;;;;N;;;;; +1DC6;COMBINING MACRON-GRAVE;Mn;230;NSM;;;;;N;;;;; +1DC7;COMBINING ACUTE-MACRON;Mn;230;NSM;;;;;N;;;;; +1DC8;COMBINING GRAVE-ACUTE-GRAVE;Mn;230;NSM;;;;;N;;;;; +1DC9;COMBINING ACUTE-GRAVE-ACUTE;Mn;230;NSM;;;;;N;;;;; +1DCA;COMBINING LATIN SMALL LETTER R BELOW;Mn;220;NSM;;;;;N;;;;; +1DCB;COMBINING BREVE-MACRON;Mn;230;NSM;;;;;N;;;;; +1DCC;COMBINING MACRON-BREVE;Mn;230;NSM;;;;;N;;;;; +1DCD;COMBINING DOUBLE CIRCUMFLEX ABOVE;Mn;234;NSM;;;;;N;;;;; +1DCE;COMBINING OGONEK ABOVE;Mn;214;NSM;;;;;N;;;;; +1DCF;COMBINING ZIGZAG BELOW;Mn;220;NSM;;;;;N;;;;; +1DD0;COMBINING IS BELOW;Mn;202;NSM;;;;;N;;;;; +1DD1;COMBINING UR ABOVE;Mn;230;NSM;;;;;N;;;;; +1DD2;COMBINING US ABOVE;Mn;230;NSM;;;;;N;;;;; +1DD3;COMBINING LATIN SMALL LETTER FLATTENED OPEN A ABOVE;Mn;230;NSM;;;;;N;;;;; +1DD4;COMBINING LATIN SMALL LETTER AE;Mn;230;NSM;;;;;N;;;;; +1DD5;COMBINING LATIN SMALL LETTER AO;Mn;230;NSM;;;;;N;;;;; +1DD6;COMBINING LATIN SMALL LETTER AV;Mn;230;NSM;;;;;N;;;;; +1DD7;COMBINING LATIN SMALL LETTER C CEDILLA;Mn;230;NSM;;;;;N;;;;; +1DD8;COMBINING LATIN SMALL LETTER INSULAR D;Mn;230;NSM;;;;;N;;;;; +1DD9;COMBINING LATIN SMALL LETTER ETH;Mn;230;NSM;;;;;N;;;;; +1DDA;COMBINING LATIN SMALL LETTER G;Mn;230;NSM;;;;;N;;;;; +1DDB;COMBINING LATIN LETTER SMALL CAPITAL G;Mn;230;NSM;;;;;N;;;;; +1DDC;COMBINING LATIN SMALL LETTER K;Mn;230;NSM;;;;;N;;;;; +1DDD;COMBINING LATIN SMALL LETTER L;Mn;230;NSM;;;;;N;;;;; +1DDE;COMBINING LATIN LETTER SMALL CAPITAL L;Mn;230;NSM;;;;;N;;;;; +1DDF;COMBINING LATIN LETTER SMALL CAPITAL M;Mn;230;NSM;;;;;N;;;;; +1DE0;COMBINING LATIN SMALL LETTER N;Mn;230;NSM;;;;;N;;;;; +1DE1;COMBINING LATIN LETTER SMALL CAPITAL N;Mn;230;NSM;;;;;N;;;;; +1DE2;COMBINING LATIN LETTER SMALL CAPITAL R;Mn;230;NSM;;;;;N;;;;; +1DE3;COMBINING LATIN SMALL LETTER R ROTUNDA;Mn;230;NSM;;;;;N;;;;; +1DE4;COMBINING LATIN SMALL LETTER S;Mn;230;NSM;;;;;N;;;;; +1DE5;COMBINING LATIN SMALL LETTER LONG S;Mn;230;NSM;;;;;N;;;;; +1DE6;COMBINING LATIN SMALL LETTER Z;Mn;230;NSM;;;;;N;;;;; +1DFE;COMBINING LEFT ARROWHEAD ABOVE;Mn;230;NSM;;;;;N;;;;; +1DFF;COMBINING RIGHT ARROWHEAD AND DOWN ARROWHEAD BELOW;Mn;220;NSM;;;;;N;;;;; 1E00;LATIN CAPITAL LETTER A WITH RING BELOW;Lu;0;L;0041 0325;;;;N;;;;1E01; 1E01;LATIN SMALL LETTER A WITH RING BELOW;Ll;0;L;0061 0325;;;;N;;;1E00;;1E00 1E02;LATIN CAPITAL LETTER B WITH DOT ABOVE;Lu;0;L;0042 0307;;;;N;;;;1E03; @@ -5237,6 +6156,10 @@ 1E99;LATIN SMALL LETTER Y WITH RING ABOVE;Ll;0;L;0079 030A;;;;N;;;;; 1E9A;LATIN SMALL LETTER A WITH RIGHT HALF RING;Ll;0;L;<compat> 0061 02BE;;;;N;;;;; 1E9B;LATIN SMALL LETTER LONG S WITH DOT ABOVE;Ll;0;L;017F 0307;;;;N;;;1E60;;1E60 +1E9C;LATIN SMALL LETTER LONG S WITH DIAGONAL STROKE;Ll;0;L;;;;;N;;;;; +1E9D;LATIN SMALL LETTER LONG S WITH HIGH STROKE;Ll;0;L;;;;;N;;;;; +1E9E;LATIN CAPITAL LETTER SHARP S;Lu;0;L;;;;;N;;;;00DF; +1E9F;LATIN SMALL LETTER DELTA;Ll;0;L;;;;;N;;;;; 1EA0;LATIN CAPITAL LETTER A WITH DOT BELOW;Lu;0;L;0041 0323;;;;N;;;;1EA1; 1EA1;LATIN SMALL LETTER A WITH DOT BELOW;Ll;0;L;0061 0323;;;;N;;;1EA0;;1EA0 1EA2;LATIN CAPITAL LETTER A WITH HOOK ABOVE;Lu;0;L;0041 0309;;;;N;;;;1EA3; @@ -5327,6 +6250,12 @@ 1EF7;LATIN SMALL LETTER Y WITH HOOK ABOVE;Ll;0;L;0079 0309;;;;N;;;1EF6;;1EF6 1EF8;LATIN CAPITAL LETTER Y WITH TILDE;Lu;0;L;0059 0303;;;;N;;;;1EF9; 1EF9;LATIN SMALL LETTER Y WITH TILDE;Ll;0;L;0079 0303;;;;N;;;1EF8;;1EF8 +1EFA;LATIN CAPITAL LETTER MIDDLE-WELSH LL;Lu;0;L;;;;;N;;;;1EFB; +1EFB;LATIN SMALL LETTER MIDDLE-WELSH LL;Ll;0;L;;;;;N;;;1EFA;;1EFA +1EFC;LATIN CAPITAL LETTER MIDDLE-WELSH V;Lu;0;L;;;;;N;;;;1EFD; +1EFD;LATIN SMALL LETTER MIDDLE-WELSH V;Ll;0;L;;;;;N;;;1EFC;;1EFC +1EFE;LATIN CAPITAL LETTER Y WITH LOOP;Lu;0;L;;;;;N;;;;1EFF; +1EFF;LATIN SMALL LETTER Y WITH LOOP;Ll;0;L;;;;;N;;;1EFE;;1EFE 1F00;GREEK SMALL LETTER ALPHA WITH PSILI;Ll;0;L;03B1 0313;;;;N;;;1F08;;1F08 1F01;GREEK SMALL LETTER ALPHA WITH DASIA;Ll;0;L;03B1 0314;;;;N;;;1F09;;1F09 1F02;GREEK SMALL LETTER ALPHA WITH PSILI AND VARIA;Ll;0;L;1F00 0300;;;;N;;;1F0A;;1F0A @@ -5571,7 +6500,7 @@ 2008;PUNCTUATION SPACE;Zs;0;WS;<compat> 0020;;;;N;;;;; 2009;THIN SPACE;Zs;0;WS;<compat> 0020;;;;N;;;;; 200A;HAIR SPACE;Zs;0;WS;<compat> 0020;;;;N;;;;; -200B;ZERO WIDTH SPACE;Zs;0;BN;;;;;N;;;;; +200B;ZERO WIDTH SPACE;Cf;0;BN;;;;;N;;;;; 200C;ZERO WIDTH NON-JOINER;Cf;0;BN;;;;;N;;;;; 200D;ZERO WIDTH JOINER;Cf;0;BN;;;;;N;;;;; 200E;LEFT-TO-RIGHT MARK;Cf;0;L;;;;;N;;;;; @@ -5607,7 +6536,7 @@ 202C;POP DIRECTIONAL FORMATTING;Cf;0;PDF;;;;;N;;;;; 202D;LEFT-TO-RIGHT OVERRIDE;Cf;0;LRO;;;;;N;;;;; 202E;RIGHT-TO-LEFT OVERRIDE;Cf;0;RLO;;;;;N;;;;; -202F;NARROW NO-BREAK SPACE;Zs;0;WS;<noBreak> 0020;;;;N;;;;; +202F;NARROW NO-BREAK SPACE;Zs;0;CS;<noBreak> 0020;;;;N;;;;; 2030;PER MILLE SIGN;Po;0;ET;;;;;N;;;;; 2031;PER TEN THOUSAND SIGN;Po;0;ET;;;;;N;;;;; 2032;PRIME;Po;0;ET;;;;;N;;;;; @@ -5628,7 +6557,7 @@ 2041;CARET INSERTION POINT;Po;0;ON;;;;;N;;;;; 2042;ASTERISM;Po;0;ON;;;;;N;;;;; 2043;HYPHEN BULLET;Po;0;ON;;;;;N;;;;; -2044;FRACTION SLASH;Sm;0;ON;;;;;N;;;;; +2044;FRACTION SLASH;Sm;0;CS;;;;;N;;;;; 2045;LEFT SQUARE BRACKET WITH QUILL;Ps;0;ON;;;;;Y;;;;; 2046;RIGHT SQUARE BRACKET WITH QUILL;Pe;0;ON;;;;;Y;;;;; 2047;DOUBLE QUESTION MARK;Po;0;ON;<compat> 003F 003F;;;;N;;;;; @@ -5645,12 +6574,22 @@ 2052;COMMERCIAL MINUS SIGN;Sm;0;ON;;;;;N;;;;; 2053;SWUNG DASH;Po;0;ON;;;;;N;;;;; 2054;INVERTED UNDERTIE;Pc;0;ON;;;;;N;;;;; +2055;FLOWER PUNCTUATION MARK;Po;0;ON;;;;;N;;;;; +2056;THREE DOT PUNCTUATION;Po;0;ON;;;;;N;;;;; 2057;QUADRUPLE PRIME;Po;0;ON;<compat> 2032 2032 2032 2032;;;;N;;;;; +2058;FOUR DOT PUNCTUATION;Po;0;ON;;;;;N;;;;; +2059;FIVE DOT PUNCTUATION;Po;0;ON;;;;;N;;;;; +205A;TWO DOT PUNCTUATION;Po;0;ON;;;;;N;;;;; +205B;FOUR DOT MARK;Po;0;ON;;;;;N;;;;; +205C;DOTTED CROSS;Po;0;ON;;;;;N;;;;; +205D;TRICOLON;Po;0;ON;;;;;N;;;;; +205E;VERTICAL FOUR DOTS;Po;0;ON;;;;;N;;;;; 205F;MEDIUM MATHEMATICAL SPACE;Zs;0;WS;<compat> 0020;;;;N;;;;; 2060;WORD JOINER;Cf;0;BN;;;;;N;;;;; 2061;FUNCTION APPLICATION;Cf;0;BN;;;;;N;;;;; 2062;INVISIBLE TIMES;Cf;0;BN;;;;;N;;;;; 2063;INVISIBLE SEPARATOR;Cf;0;BN;;;;;N;;;;; +2064;INVISIBLE PLUS;Cf;0;BN;;;;;N;;;;; 206A;INHIBIT SYMMETRIC SWAPPING;Cf;0;BN;;;;;N;;;;; 206B;ACTIVATE SYMMETRIC SWAPPING;Cf;0;BN;;;;;N;;;;; 206C;INHIBIT ARABIC FORM SHAPING;Cf;0;BN;;;;;N;;;;; @@ -5665,8 +6604,8 @@ 2077;SUPERSCRIPT SEVEN;No;0;EN;<super> 0037;;7;7;N;SUPERSCRIPT DIGIT SEVEN;;;; 2078;SUPERSCRIPT EIGHT;No;0;EN;<super> 0038;;8;8;N;SUPERSCRIPT DIGIT EIGHT;;;; 2079;SUPERSCRIPT NINE;No;0;EN;<super> 0039;;9;9;N;SUPERSCRIPT DIGIT NINE;;;; -207A;SUPERSCRIPT PLUS SIGN;Sm;0;ET;<super> 002B;;;;N;;;;; -207B;SUPERSCRIPT MINUS;Sm;0;ET;<super> 2212;;;;N;SUPERSCRIPT HYPHEN-MINUS;;;; +207A;SUPERSCRIPT PLUS SIGN;Sm;0;ES;<super> 002B;;;;N;;;;; +207B;SUPERSCRIPT MINUS;Sm;0;ES;<super> 2212;;;;N;SUPERSCRIPT HYPHEN-MINUS;;;; 207C;SUPERSCRIPT EQUALS SIGN;Sm;0;ON;<super> 003D;;;;N;;;;; 207D;SUPERSCRIPT LEFT PARENTHESIS;Ps;0;ON;<super> 0028;;;;Y;SUPERSCRIPT OPENING PARENTHESIS;;;; 207E;SUPERSCRIPT RIGHT PARENTHESIS;Pe;0;ON;<super> 0029;;;;Y;SUPERSCRIPT CLOSING PARENTHESIS;;;; @@ -5681,11 +6620,16 @@ 2087;SUBSCRIPT SEVEN;No;0;EN;<sub> 0037;;7;7;N;SUBSCRIPT DIGIT SEVEN;;;; 2088;SUBSCRIPT EIGHT;No;0;EN;<sub> 0038;;8;8;N;SUBSCRIPT DIGIT EIGHT;;;; 2089;SUBSCRIPT NINE;No;0;EN;<sub> 0039;;9;9;N;SUBSCRIPT DIGIT NINE;;;; -208A;SUBSCRIPT PLUS SIGN;Sm;0;ET;<sub> 002B;;;;N;;;;; -208B;SUBSCRIPT MINUS;Sm;0;ET;<sub> 2212;;;;N;SUBSCRIPT HYPHEN-MINUS;;;; +208A;SUBSCRIPT PLUS SIGN;Sm;0;ES;<sub> 002B;;;;N;;;;; +208B;SUBSCRIPT MINUS;Sm;0;ES;<sub> 2212;;;;N;SUBSCRIPT HYPHEN-MINUS;;;; 208C;SUBSCRIPT EQUALS SIGN;Sm;0;ON;<sub> 003D;;;;N;;;;; 208D;SUBSCRIPT LEFT PARENTHESIS;Ps;0;ON;<sub> 0028;;;;Y;SUBSCRIPT OPENING PARENTHESIS;;;; 208E;SUBSCRIPT RIGHT PARENTHESIS;Pe;0;ON;<sub> 0029;;;;Y;SUBSCRIPT CLOSING PARENTHESIS;;;; +2090;LATIN SUBSCRIPT SMALL LETTER A;Lm;0;L;<sub> 0061;;;;N;;;;; +2091;LATIN SUBSCRIPT SMALL LETTER E;Lm;0;L;<sub> 0065;;;;N;;;;; +2092;LATIN SUBSCRIPT SMALL LETTER O;Lm;0;L;<sub> 006F;;;;N;;;;; +2093;LATIN SUBSCRIPT SMALL LETTER X;Lm;0;L;<sub> 0078;;;;N;;;;; +2094;LATIN SUBSCRIPT SMALL LETTER SCHWA;Lm;0;L;<sub> 0259;;;;N;;;;; 20A0;EURO-CURRENCY SIGN;Sc;0;ET;;;;;N;;;;; 20A1;COLON SIGN;Sc;0;ET;;;;;N;;;;; 20A2;CRUZEIRO SIGN;Sc;0;ET;;;;;N;;;;; @@ -5704,6 +6648,10 @@ 20AF;DRACHMA SIGN;Sc;0;ET;;;;;N;;;;; 20B0;GERMAN PENNY SIGN;Sc;0;ET;;;;;N;;;;; 20B1;PESO SIGN;Sc;0;ET;;;;;N;;;;; +20B2;GUARANI SIGN;Sc;0;ET;;;;;N;;;;; +20B3;AUSTRAL SIGN;Sc;0;ET;;;;;N;;;;; +20B4;HRYVNIA SIGN;Sc;0;ET;;;;;N;;;;; +20B5;CEDI SIGN;Sc;0;ET;;;;;N;;;;; 20D0;COMBINING LEFT HARPOON ABOVE;Mn;230;NSM;;;;;N;NON-SPACING LEFT HARPOON ABOVE;;;; 20D1;COMBINING RIGHT HARPOON ABOVE;Mn;230;NSM;;;;;N;NON-SPACING RIGHT HARPOON ABOVE;;;; 20D2;COMBINING LONG VERTICAL LINE OVERLAY;Mn;1;NSM;;;;;N;NON-SPACING LONG VERTICAL BAR OVERLAY;;;; @@ -5731,6 +6679,12 @@ 20E8;COMBINING TRIPLE UNDERDOT;Mn;220;NSM;;;;;N;;;;; 20E9;COMBINING WIDE BRIDGE ABOVE;Mn;230;NSM;;;;;N;;;;; 20EA;COMBINING LEFTWARDS ARROW OVERLAY;Mn;1;NSM;;;;;N;;;;; +20EB;COMBINING LONG DOUBLE SOLIDUS OVERLAY;Mn;1;NSM;;;;;N;;;;; +20EC;COMBINING RIGHTWARDS HARPOON WITH BARB DOWNWARDS;Mn;220;NSM;;;;;N;;;;; +20ED;COMBINING LEFTWARDS HARPOON WITH BARB DOWNWARDS;Mn;220;NSM;;;;;N;;;;; +20EE;COMBINING LEFT ARROW BELOW;Mn;220;NSM;;;;;N;;;;; +20EF;COMBINING RIGHT ARROW BELOW;Mn;220;NSM;;;;;N;;;;; +20F0;COMBINING ASTERISK ABOVE;Mn;230;NSM;;;;;N;;;;; 2100;ACCOUNT OF;So;0;ON;<compat> 0061 002F 0063;;;;N;;;;; 2101;ADDRESSED TO THE SUBJECT;So;0;ON;<compat> 0061 002F 0073;;;;N;;;;; 2102;DOUBLE-STRUCK CAPITAL C;Lu;0;L;<font> 0043;;;;N;DOUBLE-STRUCK C;;;; @@ -5781,7 +6735,7 @@ 212F;SCRIPT SMALL E;Ll;0;L;<font> 0065;;;;N;;;;; 2130;SCRIPT CAPITAL E;Lu;0;L;<font> 0045;;;;N;SCRIPT E;;;; 2131;SCRIPT CAPITAL F;Lu;0;L;<font> 0046;;;;N;SCRIPT F;;;; -2132;TURNED CAPITAL F;So;0;ON;;;;;N;TURNED F;;;; +2132;TURNED CAPITAL F;Lu;0;L;;;;;N;TURNED F;;;214E; 2133;SCRIPT CAPITAL M;Lu;0;L;<font> 004D;;;;N;SCRIPT M;;;; 2134;SCRIPT SMALL O;Ll;0;L;<font> 006F;;;;N;;;;; 2135;ALEF SYMBOL;Lo;0;L;<compat> 05D0;;;;N;FIRST TRANSFINITE CARDINAL;;;; @@ -5791,6 +6745,7 @@ 2139;INFORMATION SOURCE;Ll;0;L;<font> 0069;;;;N;;;;; 213A;ROTATED CAPITAL Q;So;0;ON;;;;;N;;;;; 213B;FACSIMILE SIGN;So;0;ON;<compat> 0046 0041 0058;;;;N;;;;; +213C;DOUBLE-STRUCK SMALL PI;Ll;0;L;<font> 03C0;;;;N;;;;; 213D;DOUBLE-STRUCK SMALL GAMMA;Ll;0;L;<font> 03B3;;;;N;;;;; 213E;DOUBLE-STRUCK CAPITAL GAMMA;Lu;0;L;<font> 0393;;;;N;;;;; 213F;DOUBLE-STRUCK CAPITAL PI;Lu;0;L;<font> 03A0;;;;N;;;;; @@ -5806,6 +6761,10 @@ 2149;DOUBLE-STRUCK ITALIC SMALL J;Ll;0;L;<font> 006A;;;;N;;;;; 214A;PROPERTY LINE;So;0;ON;;;;;N;;;;; 214B;TURNED AMPERSAND;Sm;0;ON;;;;;N;;;;; +214C;PER SIGN;So;0;ON;;;;;N;;;;; +214D;AKTIESELSKAB;So;0;ON;;;;;N;;;;; +214E;TURNED SMALL F;Ll;0;L;;;;;N;;;2132;;2132 +214F;SYMBOL FOR SAMARITAN SOURCE;So;0;L;;;;;N;;;;; 2153;VULGAR FRACTION ONE THIRD;No;0;ON;<fraction> 0031 2044 0033;;;1/3;N;FRACTION ONE THIRD;;;; 2154;VULGAR FRACTION TWO THIRDS;No;0;ON;<fraction> 0032 2044 0033;;;2/3;N;FRACTION TWO THIRDS;;;; 2155;VULGAR FRACTION ONE FIFTH;No;0;ON;<fraction> 0031 2044 0035;;;1/5;N;FRACTION ONE FIFTH;;;; @@ -5854,7 +6813,12 @@ 2180;ROMAN NUMERAL ONE THOUSAND C D;Nl;0;L;;;;1000;N;;;;; 2181;ROMAN NUMERAL FIVE THOUSAND;Nl;0;L;;;;5000;N;;;;; 2182;ROMAN NUMERAL TEN THOUSAND;Nl;0;L;;;;10000;N;;;;; -2183;ROMAN NUMERAL REVERSED ONE HUNDRED;Nl;0;L;;;;;N;;;;; +2183;ROMAN NUMERAL REVERSED ONE HUNDRED;Lu;0;L;;;;;N;;;;2184; +2184;LATIN SMALL LETTER REVERSED C;Ll;0;L;;;;;N;;;2183;;2183 +2185;ROMAN NUMERAL SIX LATE FORM;Nl;0;L;;;;6;N;;;;; +2186;ROMAN NUMERAL FIFTY EARLY FORM;Nl;0;L;;;;50;N;;;;; +2187;ROMAN NUMERAL FIFTY THOUSAND;Nl;0;L;;;;50000;N;;;;; +2188;ROMAN NUMERAL ONE HUNDRED THOUSAND;Nl;0;L;;;;100000;N;;;;; 2190;LEFTWARDS ARROW;Sm;0;ON;;;;;N;LEFT ARROW;;;; 2191;UPWARDS ARROW;Sm;0;ON;;;;;N;UP ARROW;;;; 2192;RIGHTWARDS ARROW;Sm;0;ON;;;;;N;RIGHT ARROW;;;; @@ -5985,7 +6949,7 @@ 220F;N-ARY PRODUCT;Sm;0;ON;;;;;N;;;;; 2210;N-ARY COPRODUCT;Sm;0;ON;;;;;N;;;;; 2211;N-ARY SUMMATION;Sm;0;ON;;;;;Y;;;;; -2212;MINUS SIGN;Sm;0;ET;;;;;N;;;;; +2212;MINUS SIGN;Sm;0;ES;;;;;N;;;;; 2213;MINUS-OR-PLUS SIGN;Sm;0;ET;;;;;N;;;;; 2214;DOT PLUS;Sm;0;ON;;;;;N;;;;; 2215;DIVISION SLASH;Sm;0;ON;;;;;Y;;;;; @@ -6403,9 +7367,9 @@ 23B1;UPPER RIGHT OR LOWER LEFT CURLY BRACKET SECTION;Sm;0;ON;;;;;N;;;;; 23B2;SUMMATION TOP;Sm;0;ON;;;;;N;;;;; 23B3;SUMMATION BOTTOM;Sm;0;ON;;;;;N;;;;; -23B4;TOP SQUARE BRACKET;Ps;0;ON;;;;;N;;;;; -23B5;BOTTOM SQUARE BRACKET;Pe;0;ON;;;;;N;;;;; -23B6;BOTTOM SQUARE BRACKET OVER TOP SQUARE BRACKET;Po;0;ON;;;;;N;;;;; +23B4;TOP SQUARE BRACKET;So;0;ON;;;;;N;;;;; +23B5;BOTTOM SQUARE BRACKET;So;0;ON;;;;;N;;;;; +23B6;BOTTOM SQUARE BRACKET OVER TOP SQUARE BRACKET;So;0;ON;;;;;N;;;;; 23B7;RADICAL SYMBOL BOTTOM;So;0;ON;;;;;N;;;;; 23B8;LEFT VERTICAL BOX LINE;So;0;ON;;;;;N;;;;; 23B9;RIGHT VERTICAL BOX LINE;So;0;ON;;;;;N;;;;; @@ -6432,6 +7396,29 @@ 23CE;RETURN SYMBOL;So;0;ON;;;;;N;;;;; 23CF;EJECT SYMBOL;So;0;ON;;;;;N;;;;; 23D0;VERTICAL LINE EXTENSION;So;0;ON;;;;;N;;;;; +23D1;METRICAL BREVE;So;0;ON;;;;;N;;;;; +23D2;METRICAL LONG OVER SHORT;So;0;ON;;;;;N;;;;; +23D3;METRICAL SHORT OVER LONG;So;0;ON;;;;;N;;;;; +23D4;METRICAL LONG OVER TWO SHORTS;So;0;ON;;;;;N;;;;; +23D5;METRICAL TWO SHORTS OVER LONG;So;0;ON;;;;;N;;;;; +23D6;METRICAL TWO SHORTS JOINED;So;0;ON;;;;;N;;;;; +23D7;METRICAL TRISEME;So;0;ON;;;;;N;;;;; +23D8;METRICAL TETRASEME;So;0;ON;;;;;N;;;;; +23D9;METRICAL PENTASEME;So;0;ON;;;;;N;;;;; +23DA;EARTH GROUND;So;0;ON;;;;;N;;;;; +23DB;FUSE;So;0;ON;;;;;N;;;;; +23DC;TOP PARENTHESIS;Sm;0;ON;;;;;N;;mathematical use;;; +23DD;BOTTOM PARENTHESIS;Sm;0;ON;;;;;N;;mathematical use;;; +23DE;TOP CURLY BRACKET;Sm;0;ON;;;;;N;;mathematical use;;; +23DF;BOTTOM CURLY BRACKET;Sm;0;ON;;;;;N;;mathematical use;;; +23E0;TOP TORTOISE SHELL BRACKET;Sm;0;ON;;;;;N;;mathematical use;;; +23E1;BOTTOM TORTOISE SHELL BRACKET;Sm;0;ON;;;;;N;;mathematical use;;; +23E2;WHITE TRAPEZIUM;So;0;ON;;;;;N;;;;; +23E3;BENZENE RING WITH CIRCLE;So;0;ON;;;;;N;;;;; +23E4;STRAIGHTNESS;So;0;ON;;;;;N;;;;; +23E5;FLATNESS;So;0;ON;;;;;N;;;;; +23E6;AC CURRENT;So;0;ON;;;;;N;;;;; +23E7;ELECTRICAL INTERSECTION;So;0;ON;;;;;N;;;;; 2400;SYMBOL FOR NULL;So;0;ON;;;;;N;GRAPHIC FOR NULL;;;; 2401;SYMBOL FOR START OF HEADING;So;0;ON;;;;;N;GRAPHIC FOR START OF HEADING;;;; 2402;SYMBOL FOR START OF TEXT;So;0;ON;;;;;N;GRAPHIC FOR START OF TEXT;;;; @@ -6482,46 +7469,46 @@ 2448;OCR DASH;So;0;ON;;;;;N;;;;; 2449;OCR CUSTOMER ACCOUNT NUMBER;So;0;ON;;;;;N;;;;; 244A;OCR DOUBLE BACKSLASH;So;0;ON;;;;;N;;;;; -2460;CIRCLED DIGIT ONE;No;0;EN;<circle> 0031;;1;1;N;;;;; -2461;CIRCLED DIGIT TWO;No;0;EN;<circle> 0032;;2;2;N;;;;; -2462;CIRCLED DIGIT THREE;No;0;EN;<circle> 0033;;3;3;N;;;;; -2463;CIRCLED DIGIT FOUR;No;0;EN;<circle> 0034;;4;4;N;;;;; -2464;CIRCLED DIGIT FIVE;No;0;EN;<circle> 0035;;5;5;N;;;;; -2465;CIRCLED DIGIT SIX;No;0;EN;<circle> 0036;;6;6;N;;;;; -2466;CIRCLED DIGIT SEVEN;No;0;EN;<circle> 0037;;7;7;N;;;;; -2467;CIRCLED DIGIT EIGHT;No;0;EN;<circle> 0038;;8;8;N;;;;; -2468;CIRCLED DIGIT NINE;No;0;EN;<circle> 0039;;9;9;N;;;;; -2469;CIRCLED NUMBER TEN;No;0;EN;<circle> 0031 0030;;;10;N;;;;; -246A;CIRCLED NUMBER ELEVEN;No;0;EN;<circle> 0031 0031;;;11;N;;;;; -246B;CIRCLED NUMBER TWELVE;No;0;EN;<circle> 0031 0032;;;12;N;;;;; -246C;CIRCLED NUMBER THIRTEEN;No;0;EN;<circle> 0031 0033;;;13;N;;;;; -246D;CIRCLED NUMBER FOURTEEN;No;0;EN;<circle> 0031 0034;;;14;N;;;;; -246E;CIRCLED NUMBER FIFTEEN;No;0;EN;<circle> 0031 0035;;;15;N;;;;; -246F;CIRCLED NUMBER SIXTEEN;No;0;EN;<circle> 0031 0036;;;16;N;;;;; -2470;CIRCLED NUMBER SEVENTEEN;No;0;EN;<circle> 0031 0037;;;17;N;;;;; -2471;CIRCLED NUMBER EIGHTEEN;No;0;EN;<circle> 0031 0038;;;18;N;;;;; -2472;CIRCLED NUMBER NINETEEN;No;0;EN;<circle> 0031 0039;;;19;N;;;;; -2473;CIRCLED NUMBER TWENTY;No;0;EN;<circle> 0032 0030;;;20;N;;;;; -2474;PARENTHESIZED DIGIT ONE;No;0;EN;<compat> 0028 0031 0029;;1;1;N;;;;; -2475;PARENTHESIZED DIGIT TWO;No;0;EN;<compat> 0028 0032 0029;;2;2;N;;;;; -2476;PARENTHESIZED DIGIT THREE;No;0;EN;<compat> 0028 0033 0029;;3;3;N;;;;; -2477;PARENTHESIZED DIGIT FOUR;No;0;EN;<compat> 0028 0034 0029;;4;4;N;;;;; -2478;PARENTHESIZED DIGIT FIVE;No;0;EN;<compat> 0028 0035 0029;;5;5;N;;;;; -2479;PARENTHESIZED DIGIT SIX;No;0;EN;<compat> 0028 0036 0029;;6;6;N;;;;; -247A;PARENTHESIZED DIGIT SEVEN;No;0;EN;<compat> 0028 0037 0029;;7;7;N;;;;; -247B;PARENTHESIZED DIGIT EIGHT;No;0;EN;<compat> 0028 0038 0029;;8;8;N;;;;; -247C;PARENTHESIZED DIGIT NINE;No;0;EN;<compat> 0028 0039 0029;;9;9;N;;;;; -247D;PARENTHESIZED NUMBER TEN;No;0;EN;<compat> 0028 0031 0030 0029;;;10;N;;;;; -247E;PARENTHESIZED NUMBER ELEVEN;No;0;EN;<compat> 0028 0031 0031 0029;;;11;N;;;;; -247F;PARENTHESIZED NUMBER TWELVE;No;0;EN;<compat> 0028 0031 0032 0029;;;12;N;;;;; -2480;PARENTHESIZED NUMBER THIRTEEN;No;0;EN;<compat> 0028 0031 0033 0029;;;13;N;;;;; -2481;PARENTHESIZED NUMBER FOURTEEN;No;0;EN;<compat> 0028 0031 0034 0029;;;14;N;;;;; -2482;PARENTHESIZED NUMBER FIFTEEN;No;0;EN;<compat> 0028 0031 0035 0029;;;15;N;;;;; -2483;PARENTHESIZED NUMBER SIXTEEN;No;0;EN;<compat> 0028 0031 0036 0029;;;16;N;;;;; -2484;PARENTHESIZED NUMBER SEVENTEEN;No;0;EN;<compat> 0028 0031 0037 0029;;;17;N;;;;; -2485;PARENTHESIZED NUMBER EIGHTEEN;No;0;EN;<compat> 0028 0031 0038 0029;;;18;N;;;;; -2486;PARENTHESIZED NUMBER NINETEEN;No;0;EN;<compat> 0028 0031 0039 0029;;;19;N;;;;; -2487;PARENTHESIZED NUMBER TWENTY;No;0;EN;<compat> 0028 0032 0030 0029;;;20;N;;;;; +2460;CIRCLED DIGIT ONE;No;0;ON;<circle> 0031;;1;1;N;;;;; +2461;CIRCLED DIGIT TWO;No;0;ON;<circle> 0032;;2;2;N;;;;; +2462;CIRCLED DIGIT THREE;No;0;ON;<circle> 0033;;3;3;N;;;;; +2463;CIRCLED DIGIT FOUR;No;0;ON;<circle> 0034;;4;4;N;;;;; +2464;CIRCLED DIGIT FIVE;No;0;ON;<circle> 0035;;5;5;N;;;;; +2465;CIRCLED DIGIT SIX;No;0;ON;<circle> 0036;;6;6;N;;;;; +2466;CIRCLED DIGIT SEVEN;No;0;ON;<circle> 0037;;7;7;N;;;;; +2467;CIRCLED DIGIT EIGHT;No;0;ON;<circle> 0038;;8;8;N;;;;; +2468;CIRCLED DIGIT NINE;No;0;ON;<circle> 0039;;9;9;N;;;;; +2469;CIRCLED NUMBER TEN;No;0;ON;<circle> 0031 0030;;;10;N;;;;; +246A;CIRCLED NUMBER ELEVEN;No;0;ON;<circle> 0031 0031;;;11;N;;;;; +246B;CIRCLED NUMBER TWELVE;No;0;ON;<circle> 0031 0032;;;12;N;;;;; +246C;CIRCLED NUMBER THIRTEEN;No;0;ON;<circle> 0031 0033;;;13;N;;;;; +246D;CIRCLED NUMBER FOURTEEN;No;0;ON;<circle> 0031 0034;;;14;N;;;;; +246E;CIRCLED NUMBER FIFTEEN;No;0;ON;<circle> 0031 0035;;;15;N;;;;; +246F;CIRCLED NUMBER SIXTEEN;No;0;ON;<circle> 0031 0036;;;16;N;;;;; +2470;CIRCLED NUMBER SEVENTEEN;No;0;ON;<circle> 0031 0037;;;17;N;;;;; +2471;CIRCLED NUMBER EIGHTEEN;No;0;ON;<circle> 0031 0038;;;18;N;;;;; +2472;CIRCLED NUMBER NINETEEN;No;0;ON;<circle> 0031 0039;;;19;N;;;;; +2473;CIRCLED NUMBER TWENTY;No;0;ON;<circle> 0032 0030;;;20;N;;;;; +2474;PARENTHESIZED DIGIT ONE;No;0;ON;<compat> 0028 0031 0029;;1;1;N;;;;; +2475;PARENTHESIZED DIGIT TWO;No;0;ON;<compat> 0028 0032 0029;;2;2;N;;;;; +2476;PARENTHESIZED DIGIT THREE;No;0;ON;<compat> 0028 0033 0029;;3;3;N;;;;; +2477;PARENTHESIZED DIGIT FOUR;No;0;ON;<compat> 0028 0034 0029;;4;4;N;;;;; +2478;PARENTHESIZED DIGIT FIVE;No;0;ON;<compat> 0028 0035 0029;;5;5;N;;;;; +2479;PARENTHESIZED DIGIT SIX;No;0;ON;<compat> 0028 0036 0029;;6;6;N;;;;; +247A;PARENTHESIZED DIGIT SEVEN;No;0;ON;<compat> 0028 0037 0029;;7;7;N;;;;; +247B;PARENTHESIZED DIGIT EIGHT;No;0;ON;<compat> 0028 0038 0029;;8;8;N;;;;; +247C;PARENTHESIZED DIGIT NINE;No;0;ON;<compat> 0028 0039 0029;;9;9;N;;;;; +247D;PARENTHESIZED NUMBER TEN;No;0;ON;<compat> 0028 0031 0030 0029;;;10;N;;;;; +247E;PARENTHESIZED NUMBER ELEVEN;No;0;ON;<compat> 0028 0031 0031 0029;;;11;N;;;;; +247F;PARENTHESIZED NUMBER TWELVE;No;0;ON;<compat> 0028 0031 0032 0029;;;12;N;;;;; +2480;PARENTHESIZED NUMBER THIRTEEN;No;0;ON;<compat> 0028 0031 0033 0029;;;13;N;;;;; +2481;PARENTHESIZED NUMBER FOURTEEN;No;0;ON;<compat> 0028 0031 0034 0029;;;14;N;;;;; +2482;PARENTHESIZED NUMBER FIFTEEN;No;0;ON;<compat> 0028 0031 0035 0029;;;15;N;;;;; +2483;PARENTHESIZED NUMBER SIXTEEN;No;0;ON;<compat> 0028 0031 0036 0029;;;16;N;;;;; +2484;PARENTHESIZED NUMBER SEVENTEEN;No;0;ON;<compat> 0028 0031 0037 0029;;;17;N;;;;; +2485;PARENTHESIZED NUMBER EIGHTEEN;No;0;ON;<compat> 0028 0031 0038 0029;;;18;N;;;;; +2486;PARENTHESIZED NUMBER NINETEEN;No;0;ON;<compat> 0028 0031 0039 0029;;;19;N;;;;; +2487;PARENTHESIZED NUMBER TWENTY;No;0;ON;<compat> 0028 0032 0030 0029;;;20;N;;;;; 2488;DIGIT ONE FULL STOP;No;0;EN;<compat> 0031 002E;;1;1;N;DIGIT ONE PERIOD;;;; 2489;DIGIT TWO FULL STOP;No;0;EN;<compat> 0032 002E;;2;2;N;DIGIT TWO PERIOD;;;; 248A;DIGIT THREE FULL STOP;No;0;EN;<compat> 0033 002E;;3;3;N;DIGIT THREE PERIOD;;;; @@ -6620,7 +7607,7 @@ 24E7;CIRCLED LATIN SMALL LETTER X;So;0;L;<circle> 0078;;;;N;;;24CD;;24CD 24E8;CIRCLED LATIN SMALL LETTER Y;So;0;L;<circle> 0079;;;;N;;;24CE;;24CE 24E9;CIRCLED LATIN SMALL LETTER Z;So;0;L;<circle> 007A;;;;N;;;24CF;;24CF -24EA;CIRCLED DIGIT ZERO;No;0;EN;<circle> 0030;;0;0;N;;;;; +24EA;CIRCLED DIGIT ZERO;No;0;ON;<circle> 0030;;0;0;N;;;;; 24EB;NEGATIVE CIRCLED NUMBER ELEVEN;No;0;ON;;;;11;N;;;;; 24EC;NEGATIVE CIRCLED NUMBER TWELVE;No;0;ON;;;;12;N;;;;; 24ED;NEGATIVE CIRCLED NUMBER THIRTEEN;No;0;ON;;;;13;N;;;;; @@ -6922,6 +7909,7 @@ 2615;HOT BEVERAGE;So;0;ON;;;;;N;;;;; 2616;WHITE SHOGI PIECE;So;0;ON;;;;;N;;;;; 2617;BLACK SHOGI PIECE;So;0;ON;;;;;N;;;;; +2618;SHAMROCK;So;0;ON;;;;;N;;;;; 2619;REVERSED ROTATED FLORAL HEART BULLET;So;0;ON;;;;;N;;;;; 261A;BLACK LEFT POINTING INDEX;So;0;ON;;;;;N;;;;; 261B;BLACK RIGHT POINTING INDEX;So;0;ON;;;;;N;;;;; @@ -7023,6 +8011,8 @@ 267B;BLACK UNIVERSAL RECYCLING SYMBOL;So;0;ON;;;;;N;;;;; 267C;RECYCLED PAPER SYMBOL;So;0;ON;;;;;N;;;;; 267D;PARTIALLY-RECYCLED PAPER SYMBOL;So;0;ON;;;;;N;;;;; +267E;PERMANENT PAPER SIGN;So;0;ON;;;;;N;;;;; +267F;WHEELCHAIR SYMBOL;So;0;ON;;;;;N;;;;; 2680;DIE FACE-1;So;0;ON;;;;;N;;;;; 2681;DIE FACE-2;So;0;ON;;;;;N;;;;; 2682;DIE FACE-3;So;0;ON;;;;;N;;;;; @@ -7041,8 +8031,51 @@ 268F;DIGRAM FOR GREATER YIN;So;0;ON;;;;;N;;;;; 2690;WHITE FLAG;So;0;ON;;;;;N;;;;; 2691;BLACK FLAG;So;0;ON;;;;;N;;;;; +2692;HAMMER AND PICK;So;0;ON;;;;;N;;;;; +2693;ANCHOR;So;0;ON;;;;;N;;;;; +2694;CROSSED SWORDS;So;0;ON;;;;;N;;;;; +2695;STAFF OF AESCULAPIUS;So;0;ON;;;;;N;;;;; +2696;SCALES;So;0;ON;;;;;N;;;;; +2697;ALEMBIC;So;0;ON;;;;;N;;;;; +2698;FLOWER;So;0;ON;;;;;N;;;;; +2699;GEAR;So;0;ON;;;;;N;;;;; +269A;STAFF OF HERMES;So;0;ON;;;;;N;;;;; +269B;ATOM SYMBOL;So;0;ON;;;;;N;;;;; +269C;FLEUR-DE-LIS;So;0;ON;;;;;N;;;;; +269D;OUTLINED WHITE STAR;So;0;ON;;;;;N;;;;; 26A0;WARNING SIGN;So;0;ON;;;;;N;;;;; 26A1;HIGH VOLTAGE SIGN;So;0;ON;;;;;N;;;;; +26A2;DOUBLED FEMALE SIGN;So;0;ON;;;;;N;;;;; +26A3;DOUBLED MALE SIGN;So;0;ON;;;;;N;;;;; +26A4;INTERLOCKED FEMALE AND MALE SIGN;So;0;ON;;;;;N;;;;; +26A5;MALE AND FEMALE SIGN;So;0;ON;;;;;N;;;;; +26A6;MALE WITH STROKE SIGN;So;0;ON;;;;;N;;;;; +26A7;MALE WITH STROKE AND MALE AND FEMALE SIGN;So;0;ON;;;;;N;;;;; +26A8;VERTICAL MALE WITH STROKE SIGN;So;0;ON;;;;;N;;;;; +26A9;HORIZONTAL MALE WITH STROKE SIGN;So;0;ON;;;;;N;;;;; +26AA;MEDIUM WHITE CIRCLE;So;0;ON;;;;;N;;;;; +26AB;MEDIUM BLACK CIRCLE;So;0;ON;;;;;N;;;;; +26AC;MEDIUM SMALL WHITE CIRCLE;So;0;L;;;;;N;;;;; +26AD;MARRIAGE SYMBOL;So;0;ON;;;;;N;;;;; +26AE;DIVORCE SYMBOL;So;0;ON;;;;;N;;;;; +26AF;UNMARRIED PARTNERSHIP SYMBOL;So;0;ON;;;;;N;;;;; +26B0;COFFIN;So;0;ON;;;;;N;;;;; +26B1;FUNERAL URN;So;0;ON;;;;;N;;;;; +26B2;NEUTER;So;0;ON;;;;;N;;;;; +26B3;CERES;So;0;ON;;;;;N;;;;; +26B4;PALLAS;So;0;ON;;;;;N;;;;; +26B5;JUNO;So;0;ON;;;;;N;;;;; +26B6;VESTA;So;0;ON;;;;;N;;;;; +26B7;CHIRON;So;0;ON;;;;;N;;;;; +26B8;BLACK MOON LILITH;So;0;ON;;;;;N;;;;; +26B9;SEXTILE;So;0;ON;;;;;N;;;;; +26BA;SEMISEXTILE;So;0;ON;;;;;N;;;;; +26BB;QUINCUNX;So;0;ON;;;;;N;;;;; +26BC;SESQUIQUADRATE;So;0;ON;;;;;N;;;;; +26C0;WHITE DRAUGHTS MAN;So;0;ON;;;;;N;;;;; +26C1;WHITE DRAUGHTS KING;So;0;ON;;;;;N;;;;; +26C2;BLACK DRAUGHTS MAN;So;0;ON;;;;;N;;;;; +26C3;BLACK DRAUGHTS KING;So;0;ON;;;;;N;;;;; 2701;UPPER BLADE SCISSORS;So;0;ON;;;;;N;;;;; 2702;BLACK SCISSORS;So;0;ON;;;;;N;;;;; 2703;LOWER BLADE SCISSORS;So;0;ON;;;;;N;;;;; @@ -7217,6 +8250,18 @@ 27BC;WEDGE-TAILED RIGHTWARDS ARROW;So;0;ON;;;;;N;WEDGE-TAILED RIGHT ARROW;;;; 27BD;HEAVY WEDGE-TAILED RIGHTWARDS ARROW;So;0;ON;;;;;N;HEAVY WEDGE-TAILED RIGHT ARROW;;;; 27BE;OPEN-OUTLINED RIGHTWARDS ARROW;So;0;ON;;;;;N;OPEN-OUTLINED RIGHT ARROW;;;; +27C0;THREE DIMENSIONAL ANGLE;Sm;0;ON;;;;;Y;;;;; +27C1;WHITE TRIANGLE CONTAINING SMALL WHITE TRIANGLE;Sm;0;ON;;;;;N;;;;; +27C2;PERPENDICULAR;Sm;0;ON;;;;;N;;;;; +27C3;OPEN SUBSET;Sm;0;ON;;;;;Y;;;;; +27C4;OPEN SUPERSET;Sm;0;ON;;;;;Y;;;;; +27C5;LEFT S-SHAPED BAG DELIMITER;Ps;0;ON;;;;;Y;;;;; +27C6;RIGHT S-SHAPED BAG DELIMITER;Pe;0;ON;;;;;Y;;;;; +27C7;OR WITH DOT INSIDE;Sm;0;ON;;;;;N;;;;; +27C8;REVERSE SOLIDUS PRECEDING SUBSET;Sm;0;ON;;;;;Y;;;;; +27C9;SUPERSET PRECEDING SOLIDUS;Sm;0;ON;;;;;Y;;;;; +27CA;VERTICAL BAR WITH HORIZONTAL STROKE;Sm;0;ON;;;;;N;;;;; +27CC;LONG DIVISION;Sm;0;ON;;;;;Y;;;;; 27D0;WHITE DIAMOND WITH CENTRED DOT;Sm;0;ON;;;;;N;;;;; 27D1;AND WITH DOT;Sm;0;ON;;;;;N;;;;; 27D2;ELEMENT OF OPENING UPWARDS;Sm;0;ON;;;;;N;;;;; @@ -7245,6 +8290,10 @@ 27E9;MATHEMATICAL RIGHT ANGLE BRACKET;Pe;0;ON;;;;;Y;;;;; 27EA;MATHEMATICAL LEFT DOUBLE ANGLE BRACKET;Ps;0;ON;;;;;Y;;;;; 27EB;MATHEMATICAL RIGHT DOUBLE ANGLE BRACKET;Pe;0;ON;;;;;Y;;;;; +27EC;MATHEMATICAL LEFT WHITE TORTOISE SHELL BRACKET;Ps;0;ON;;;;;Y;;;;; +27ED;MATHEMATICAL RIGHT WHITE TORTOISE SHELL BRACKET;Pe;0;ON;;;;;Y;;;;; +27EE;MATHEMATICAL LEFT FLATTENED PARENTHESIS;Ps;0;ON;;;;;Y;;;;; +27EF;MATHEMATICAL RIGHT FLATTENED PARENTHESIS;Pe;0;ON;;;;;Y;;;;; 27F0;UPWARDS QUADRUPLE ARROW;Sm;0;ON;;;;;N;;;;; 27F1;DOWNWARDS QUADRUPLE ARROW;Sm;0;ON;;;;;N;;;;; 27F2;ANTICLOCKWISE GAPPED CIRCLE ARROW;Sm;0;ON;;;;;N;;;;; @@ -7261,262 +8310,262 @@ 27FD;LONG LEFTWARDS DOUBLE ARROW FROM BAR;Sm;0;ON;;;;;N;;;;; 27FE;LONG RIGHTWARDS DOUBLE ARROW FROM BAR;Sm;0;ON;;;;;N;;;;; 27FF;LONG RIGHTWARDS SQUIGGLE ARROW;Sm;0;ON;;;;;N;;;;; -2800;BRAILLE PATTERN BLANK;So;0;ON;;;;;N;;;;; -2801;BRAILLE PATTERN DOTS-1;So;0;ON;;;;;N;;;;; -2802;BRAILLE PATTERN DOTS-2;So;0;ON;;;;;N;;;;; -2803;BRAILLE PATTERN DOTS-12;So;0;ON;;;;;N;;;;; -2804;BRAILLE PATTERN DOTS-3;So;0;ON;;;;;N;;;;; -2805;BRAILLE PATTERN DOTS-13;So;0;ON;;;;;N;;;;; -2806;BRAILLE PATTERN DOTS-23;So;0;ON;;;;;N;;;;; -2807;BRAILLE PATTERN DOTS-123;So;0;ON;;;;;N;;;;; -2808;BRAILLE PATTERN DOTS-4;So;0;ON;;;;;N;;;;; -2809;BRAILLE PATTERN DOTS-14;So;0;ON;;;;;N;;;;; -280A;BRAILLE PATTERN DOTS-24;So;0;ON;;;;;N;;;;; -280B;BRAILLE PATTERN DOTS-124;So;0;ON;;;;;N;;;;; -280C;BRAILLE PATTERN DOTS-34;So;0;ON;;;;;N;;;;; -280D;BRAILLE PATTERN DOTS-134;So;0;ON;;;;;N;;;;; -280E;BRAILLE PATTERN DOTS-234;So;0;ON;;;;;N;;;;; -280F;BRAILLE PATTERN DOTS-1234;So;0;ON;;;;;N;;;;; -2810;BRAILLE PATTERN DOTS-5;So;0;ON;;;;;N;;;;; -2811;BRAILLE PATTERN DOTS-15;So;0;ON;;;;;N;;;;; -2812;BRAILLE PATTERN DOTS-25;So;0;ON;;;;;N;;;;; -2813;BRAILLE PATTERN DOTS-125;So;0;ON;;;;;N;;;;; -2814;BRAILLE PATTERN DOTS-35;So;0;ON;;;;;N;;;;; -2815;BRAILLE PATTERN DOTS-135;So;0;ON;;;;;N;;;;; -2816;BRAILLE PATTERN DOTS-235;So;0;ON;;;;;N;;;;; -2817;BRAILLE PATTERN DOTS-1235;So;0;ON;;;;;N;;;;; -2818;BRAILLE PATTERN DOTS-45;So;0;ON;;;;;N;;;;; -2819;BRAILLE PATTERN DOTS-145;So;0;ON;;;;;N;;;;; -281A;BRAILLE PATTERN DOTS-245;So;0;ON;;;;;N;;;;; -281B;BRAILLE PATTERN DOTS-1245;So;0;ON;;;;;N;;;;; -281C;BRAILLE PATTERN DOTS-345;So;0;ON;;;;;N;;;;; -281D;BRAILLE PATTERN DOTS-1345;So;0;ON;;;;;N;;;;; -281E;BRAILLE PATTERN DOTS-2345;So;0;ON;;;;;N;;;;; -281F;BRAILLE PATTERN DOTS-12345;So;0;ON;;;;;N;;;;; -2820;BRAILLE PATTERN DOTS-6;So;0;ON;;;;;N;;;;; -2821;BRAILLE PATTERN DOTS-16;So;0;ON;;;;;N;;;;; -2822;BRAILLE PATTERN DOTS-26;So;0;ON;;;;;N;;;;; -2823;BRAILLE PATTERN DOTS-126;So;0;ON;;;;;N;;;;; -2824;BRAILLE PATTERN DOTS-36;So;0;ON;;;;;N;;;;; -2825;BRAILLE PATTERN DOTS-136;So;0;ON;;;;;N;;;;; -2826;BRAILLE PATTERN DOTS-236;So;0;ON;;;;;N;;;;; -2827;BRAILLE PATTERN DOTS-1236;So;0;ON;;;;;N;;;;; -2828;BRAILLE PATTERN DOTS-46;So;0;ON;;;;;N;;;;; -2829;BRAILLE PATTERN DOTS-146;So;0;ON;;;;;N;;;;; -282A;BRAILLE PATTERN DOTS-246;So;0;ON;;;;;N;;;;; -282B;BRAILLE PATTERN DOTS-1246;So;0;ON;;;;;N;;;;; -282C;BRAILLE PATTERN DOTS-346;So;0;ON;;;;;N;;;;; -282D;BRAILLE PATTERN DOTS-1346;So;0;ON;;;;;N;;;;; -282E;BRAILLE PATTERN DOTS-2346;So;0;ON;;;;;N;;;;; -282F;BRAILLE PATTERN DOTS-12346;So;0;ON;;;;;N;;;;; -2830;BRAILLE PATTERN DOTS-56;So;0;ON;;;;;N;;;;; -2831;BRAILLE PATTERN DOTS-156;So;0;ON;;;;;N;;;;; -2832;BRAILLE PATTERN DOTS-256;So;0;ON;;;;;N;;;;; -2833;BRAILLE PATTERN DOTS-1256;So;0;ON;;;;;N;;;;; -2834;BRAILLE PATTERN DOTS-356;So;0;ON;;;;;N;;;;; -2835;BRAILLE PATTERN DOTS-1356;So;0;ON;;;;;N;;;;; -2836;BRAILLE PATTERN DOTS-2356;So;0;ON;;;;;N;;;;; -2837;BRAILLE PATTERN DOTS-12356;So;0;ON;;;;;N;;;;; -2838;BRAILLE PATTERN DOTS-456;So;0;ON;;;;;N;;;;; -2839;BRAILLE PATTERN DOTS-1456;So;0;ON;;;;;N;;;;; -283A;BRAILLE PATTERN DOTS-2456;So;0;ON;;;;;N;;;;; -283B;BRAILLE PATTERN DOTS-12456;So;0;ON;;;;;N;;;;; -283C;BRAILLE PATTERN DOTS-3456;So;0;ON;;;;;N;;;;; -283D;BRAILLE PATTERN DOTS-13456;So;0;ON;;;;;N;;;;; -283E;BRAILLE PATTERN DOTS-23456;So;0;ON;;;;;N;;;;; -283F;BRAILLE PATTERN DOTS-123456;So;0;ON;;;;;N;;;;; -2840;BRAILLE PATTERN DOTS-7;So;0;ON;;;;;N;;;;; -2841;BRAILLE PATTERN DOTS-17;So;0;ON;;;;;N;;;;; -2842;BRAILLE PATTERN DOTS-27;So;0;ON;;;;;N;;;;; -2843;BRAILLE PATTERN DOTS-127;So;0;ON;;;;;N;;;;; -2844;BRAILLE PATTERN DOTS-37;So;0;ON;;;;;N;;;;; -2845;BRAILLE PATTERN DOTS-137;So;0;ON;;;;;N;;;;; -2846;BRAILLE PATTERN DOTS-237;So;0;ON;;;;;N;;;;; -2847;BRAILLE PATTERN DOTS-1237;So;0;ON;;;;;N;;;;; -2848;BRAILLE PATTERN DOTS-47;So;0;ON;;;;;N;;;;; -2849;BRAILLE PATTERN DOTS-147;So;0;ON;;;;;N;;;;; -284A;BRAILLE PATTERN DOTS-247;So;0;ON;;;;;N;;;;; -284B;BRAILLE PATTERN DOTS-1247;So;0;ON;;;;;N;;;;; -284C;BRAILLE PATTERN DOTS-347;So;0;ON;;;;;N;;;;; -284D;BRAILLE PATTERN DOTS-1347;So;0;ON;;;;;N;;;;; -284E;BRAILLE PATTERN DOTS-2347;So;0;ON;;;;;N;;;;; -284F;BRAILLE PATTERN DOTS-12347;So;0;ON;;;;;N;;;;; -2850;BRAILLE PATTERN DOTS-57;So;0;ON;;;;;N;;;;; -2851;BRAILLE PATTERN DOTS-157;So;0;ON;;;;;N;;;;; -2852;BRAILLE PATTERN DOTS-257;So;0;ON;;;;;N;;;;; -2853;BRAILLE PATTERN DOTS-1257;So;0;ON;;;;;N;;;;; -2854;BRAILLE PATTERN DOTS-357;So;0;ON;;;;;N;;;;; -2855;BRAILLE PATTERN DOTS-1357;So;0;ON;;;;;N;;;;; -2856;BRAILLE PATTERN DOTS-2357;So;0;ON;;;;;N;;;;; -2857;BRAILLE PATTERN DOTS-12357;So;0;ON;;;;;N;;;;; -2858;BRAILLE PATTERN DOTS-457;So;0;ON;;;;;N;;;;; -2859;BRAILLE PATTERN DOTS-1457;So;0;ON;;;;;N;;;;; -285A;BRAILLE PATTERN DOTS-2457;So;0;ON;;;;;N;;;;; -285B;BRAILLE PATTERN DOTS-12457;So;0;ON;;;;;N;;;;; -285C;BRAILLE PATTERN DOTS-3457;So;0;ON;;;;;N;;;;; -285D;BRAILLE PATTERN DOTS-13457;So;0;ON;;;;;N;;;;; -285E;BRAILLE PATTERN DOTS-23457;So;0;ON;;;;;N;;;;; -285F;BRAILLE PATTERN DOTS-123457;So;0;ON;;;;;N;;;;; -2860;BRAILLE PATTERN DOTS-67;So;0;ON;;;;;N;;;;; -2861;BRAILLE PATTERN DOTS-167;So;0;ON;;;;;N;;;;; -2862;BRAILLE PATTERN DOTS-267;So;0;ON;;;;;N;;;;; -2863;BRAILLE PATTERN DOTS-1267;So;0;ON;;;;;N;;;;; -2864;BRAILLE PATTERN DOTS-367;So;0;ON;;;;;N;;;;; -2865;BRAILLE PATTERN DOTS-1367;So;0;ON;;;;;N;;;;; -2866;BRAILLE PATTERN DOTS-2367;So;0;ON;;;;;N;;;;; -2867;BRAILLE PATTERN DOTS-12367;So;0;ON;;;;;N;;;;; -2868;BRAILLE PATTERN DOTS-467;So;0;ON;;;;;N;;;;; -2869;BRAILLE PATTERN DOTS-1467;So;0;ON;;;;;N;;;;; -286A;BRAILLE PATTERN DOTS-2467;So;0;ON;;;;;N;;;;; -286B;BRAILLE PATTERN DOTS-12467;So;0;ON;;;;;N;;;;; -286C;BRAILLE PATTERN DOTS-3467;So;0;ON;;;;;N;;;;; -286D;BRAILLE PATTERN DOTS-13467;So;0;ON;;;;;N;;;;; -286E;BRAILLE PATTERN DOTS-23467;So;0;ON;;;;;N;;;;; -286F;BRAILLE PATTERN DOTS-123467;So;0;ON;;;;;N;;;;; -2870;BRAILLE PATTERN DOTS-567;So;0;ON;;;;;N;;;;; -2871;BRAILLE PATTERN DOTS-1567;So;0;ON;;;;;N;;;;; -2872;BRAILLE PATTERN DOTS-2567;So;0;ON;;;;;N;;;;; -2873;BRAILLE PATTERN DOTS-12567;So;0;ON;;;;;N;;;;; -2874;BRAILLE PATTERN DOTS-3567;So;0;ON;;;;;N;;;;; -2875;BRAILLE PATTERN DOTS-13567;So;0;ON;;;;;N;;;;; -2876;BRAILLE PATTERN DOTS-23567;So;0;ON;;;;;N;;;;; -2877;BRAILLE PATTERN DOTS-123567;So;0;ON;;;;;N;;;;; -2878;BRAILLE PATTERN DOTS-4567;So;0;ON;;;;;N;;;;; -2879;BRAILLE PATTERN DOTS-14567;So;0;ON;;;;;N;;;;; -287A;BRAILLE PATTERN DOTS-24567;So;0;ON;;;;;N;;;;; -287B;BRAILLE PATTERN DOTS-124567;So;0;ON;;;;;N;;;;; -287C;BRAILLE PATTERN DOTS-34567;So;0;ON;;;;;N;;;;; -287D;BRAILLE PATTERN DOTS-134567;So;0;ON;;;;;N;;;;; -287E;BRAILLE PATTERN DOTS-234567;So;0;ON;;;;;N;;;;; -287F;BRAILLE PATTERN DOTS-1234567;So;0;ON;;;;;N;;;;; -2880;BRAILLE PATTERN DOTS-8;So;0;ON;;;;;N;;;;; -2881;BRAILLE PATTERN DOTS-18;So;0;ON;;;;;N;;;;; -2882;BRAILLE PATTERN DOTS-28;So;0;ON;;;;;N;;;;; -2883;BRAILLE PATTERN DOTS-128;So;0;ON;;;;;N;;;;; -2884;BRAILLE PATTERN DOTS-38;So;0;ON;;;;;N;;;;; -2885;BRAILLE PATTERN DOTS-138;So;0;ON;;;;;N;;;;; -2886;BRAILLE PATTERN DOTS-238;So;0;ON;;;;;N;;;;; -2887;BRAILLE PATTERN DOTS-1238;So;0;ON;;;;;N;;;;; -2888;BRAILLE PATTERN DOTS-48;So;0;ON;;;;;N;;;;; -2889;BRAILLE PATTERN DOTS-148;So;0;ON;;;;;N;;;;; -288A;BRAILLE PATTERN DOTS-248;So;0;ON;;;;;N;;;;; -288B;BRAILLE PATTERN DOTS-1248;So;0;ON;;;;;N;;;;; -288C;BRAILLE PATTERN DOTS-348;So;0;ON;;;;;N;;;;; -288D;BRAILLE PATTERN DOTS-1348;So;0;ON;;;;;N;;;;; -288E;BRAILLE PATTERN DOTS-2348;So;0;ON;;;;;N;;;;; -288F;BRAILLE PATTERN DOTS-12348;So;0;ON;;;;;N;;;;; -2890;BRAILLE PATTERN DOTS-58;So;0;ON;;;;;N;;;;; -2891;BRAILLE PATTERN DOTS-158;So;0;ON;;;;;N;;;;; -2892;BRAILLE PATTERN DOTS-258;So;0;ON;;;;;N;;;;; -2893;BRAILLE PATTERN DOTS-1258;So;0;ON;;;;;N;;;;; -2894;BRAILLE PATTERN DOTS-358;So;0;ON;;;;;N;;;;; -2895;BRAILLE PATTERN DOTS-1358;So;0;ON;;;;;N;;;;; -2896;BRAILLE PATTERN DOTS-2358;So;0;ON;;;;;N;;;;; -2897;BRAILLE PATTERN DOTS-12358;So;0;ON;;;;;N;;;;; -2898;BRAILLE PATTERN DOTS-458;So;0;ON;;;;;N;;;;; -2899;BRAILLE PATTERN DOTS-1458;So;0;ON;;;;;N;;;;; -289A;BRAILLE PATTERN DOTS-2458;So;0;ON;;;;;N;;;;; -289B;BRAILLE PATTERN DOTS-12458;So;0;ON;;;;;N;;;;; -289C;BRAILLE PATTERN DOTS-3458;So;0;ON;;;;;N;;;;; -289D;BRAILLE PATTERN DOTS-13458;So;0;ON;;;;;N;;;;; -289E;BRAILLE PATTERN DOTS-23458;So;0;ON;;;;;N;;;;; -289F;BRAILLE PATTERN DOTS-123458;So;0;ON;;;;;N;;;;; -28A0;BRAILLE PATTERN DOTS-68;So;0;ON;;;;;N;;;;; -28A1;BRAILLE PATTERN DOTS-168;So;0;ON;;;;;N;;;;; -28A2;BRAILLE PATTERN DOTS-268;So;0;ON;;;;;N;;;;; -28A3;BRAILLE PATTERN DOTS-1268;So;0;ON;;;;;N;;;;; -28A4;BRAILLE PATTERN DOTS-368;So;0;ON;;;;;N;;;;; -28A5;BRAILLE PATTERN DOTS-1368;So;0;ON;;;;;N;;;;; -28A6;BRAILLE PATTERN DOTS-2368;So;0;ON;;;;;N;;;;; -28A7;BRAILLE PATTERN DOTS-12368;So;0;ON;;;;;N;;;;; -28A8;BRAILLE PATTERN DOTS-468;So;0;ON;;;;;N;;;;; -28A9;BRAILLE PATTERN DOTS-1468;So;0;ON;;;;;N;;;;; -28AA;BRAILLE PATTERN DOTS-2468;So;0;ON;;;;;N;;;;; -28AB;BRAILLE PATTERN DOTS-12468;So;0;ON;;;;;N;;;;; -28AC;BRAILLE PATTERN DOTS-3468;So;0;ON;;;;;N;;;;; -28AD;BRAILLE PATTERN DOTS-13468;So;0;ON;;;;;N;;;;; -28AE;BRAILLE PATTERN DOTS-23468;So;0;ON;;;;;N;;;;; -28AF;BRAILLE PATTERN DOTS-123468;So;0;ON;;;;;N;;;;; -28B0;BRAILLE PATTERN DOTS-568;So;0;ON;;;;;N;;;;; -28B1;BRAILLE PATTERN DOTS-1568;So;0;ON;;;;;N;;;;; -28B2;BRAILLE PATTERN DOTS-2568;So;0;ON;;;;;N;;;;; -28B3;BRAILLE PATTERN DOTS-12568;So;0;ON;;;;;N;;;;; -28B4;BRAILLE PATTERN DOTS-3568;So;0;ON;;;;;N;;;;; -28B5;BRAILLE PATTERN DOTS-13568;So;0;ON;;;;;N;;;;; -28B6;BRAILLE PATTERN DOTS-23568;So;0;ON;;;;;N;;;;; -28B7;BRAILLE PATTERN DOTS-123568;So;0;ON;;;;;N;;;;; -28B8;BRAILLE PATTERN DOTS-4568;So;0;ON;;;;;N;;;;; -28B9;BRAILLE PATTERN DOTS-14568;So;0;ON;;;;;N;;;;; -28BA;BRAILLE PATTERN DOTS-24568;So;0;ON;;;;;N;;;;; -28BB;BRAILLE PATTERN DOTS-124568;So;0;ON;;;;;N;;;;; -28BC;BRAILLE PATTERN DOTS-34568;So;0;ON;;;;;N;;;;; -28BD;BRAILLE PATTERN DOTS-134568;So;0;ON;;;;;N;;;;; -28BE;BRAILLE PATTERN DOTS-234568;So;0;ON;;;;;N;;;;; -28BF;BRAILLE PATTERN DOTS-1234568;So;0;ON;;;;;N;;;;; -28C0;BRAILLE PATTERN DOTS-78;So;0;ON;;;;;N;;;;; -28C1;BRAILLE PATTERN DOTS-178;So;0;ON;;;;;N;;;;; -28C2;BRAILLE PATTERN DOTS-278;So;0;ON;;;;;N;;;;; -28C3;BRAILLE PATTERN DOTS-1278;So;0;ON;;;;;N;;;;; -28C4;BRAILLE PATTERN DOTS-378;So;0;ON;;;;;N;;;;; -28C5;BRAILLE PATTERN DOTS-1378;So;0;ON;;;;;N;;;;; -28C6;BRAILLE PATTERN DOTS-2378;So;0;ON;;;;;N;;;;; -28C7;BRAILLE PATTERN DOTS-12378;So;0;ON;;;;;N;;;;; -28C8;BRAILLE PATTERN DOTS-478;So;0;ON;;;;;N;;;;; -28C9;BRAILLE PATTERN DOTS-1478;So;0;ON;;;;;N;;;;; -28CA;BRAILLE PATTERN DOTS-2478;So;0;ON;;;;;N;;;;; -28CB;BRAILLE PATTERN DOTS-12478;So;0;ON;;;;;N;;;;; -28CC;BRAILLE PATTERN DOTS-3478;So;0;ON;;;;;N;;;;; -28CD;BRAILLE PATTERN DOTS-13478;So;0;ON;;;;;N;;;;; -28CE;BRAILLE PATTERN DOTS-23478;So;0;ON;;;;;N;;;;; -28CF;BRAILLE PATTERN DOTS-123478;So;0;ON;;;;;N;;;;; -28D0;BRAILLE PATTERN DOTS-578;So;0;ON;;;;;N;;;;; -28D1;BRAILLE PATTERN DOTS-1578;So;0;ON;;;;;N;;;;; -28D2;BRAILLE PATTERN DOTS-2578;So;0;ON;;;;;N;;;;; -28D3;BRAILLE PATTERN DOTS-12578;So;0;ON;;;;;N;;;;; -28D4;BRAILLE PATTERN DOTS-3578;So;0;ON;;;;;N;;;;; -28D5;BRAILLE PATTERN DOTS-13578;So;0;ON;;;;;N;;;;; -28D6;BRAILLE PATTERN DOTS-23578;So;0;ON;;;;;N;;;;; -28D7;BRAILLE PATTERN DOTS-123578;So;0;ON;;;;;N;;;;; -28D8;BRAILLE PATTERN DOTS-4578;So;0;ON;;;;;N;;;;; -28D9;BRAILLE PATTERN DOTS-14578;So;0;ON;;;;;N;;;;; -28DA;BRAILLE PATTERN DOTS-24578;So;0;ON;;;;;N;;;;; -28DB;BRAILLE PATTERN DOTS-124578;So;0;ON;;;;;N;;;;; -28DC;BRAILLE PATTERN DOTS-34578;So;0;ON;;;;;N;;;;; -28DD;BRAILLE PATTERN DOTS-134578;So;0;ON;;;;;N;;;;; -28DE;BRAILLE PATTERN DOTS-234578;So;0;ON;;;;;N;;;;; -28DF;BRAILLE PATTERN DOTS-1234578;So;0;ON;;;;;N;;;;; -28E0;BRAILLE PATTERN DOTS-678;So;0;ON;;;;;N;;;;; -28E1;BRAILLE PATTERN DOTS-1678;So;0;ON;;;;;N;;;;; -28E2;BRAILLE PATTERN DOTS-2678;So;0;ON;;;;;N;;;;; -28E3;BRAILLE PATTERN DOTS-12678;So;0;ON;;;;;N;;;;; -28E4;BRAILLE PATTERN DOTS-3678;So;0;ON;;;;;N;;;;; -28E5;BRAILLE PATTERN DOTS-13678;So;0;ON;;;;;N;;;;; -28E6;BRAILLE PATTERN DOTS-23678;So;0;ON;;;;;N;;;;; -28E7;BRAILLE PATTERN DOTS-123678;So;0;ON;;;;;N;;;;; -28E8;BRAILLE PATTERN DOTS-4678;So;0;ON;;;;;N;;;;; -28E9;BRAILLE PATTERN DOTS-14678;So;0;ON;;;;;N;;;;; -28EA;BRAILLE PATTERN DOTS-24678;So;0;ON;;;;;N;;;;; -28EB;BRAILLE PATTERN DOTS-124678;So;0;ON;;;;;N;;;;; -28EC;BRAILLE PATTERN DOTS-34678;So;0;ON;;;;;N;;;;; -28ED;BRAILLE PATTERN DOTS-134678;So;0;ON;;;;;N;;;;; -28EE;BRAILLE PATTERN DOTS-234678;So;0;ON;;;;;N;;;;; -28EF;BRAILLE PATTERN DOTS-1234678;So;0;ON;;;;;N;;;;; -28F0;BRAILLE PATTERN DOTS-5678;So;0;ON;;;;;N;;;;; -28F1;BRAILLE PATTERN DOTS-15678;So;0;ON;;;;;N;;;;; -28F2;BRAILLE PATTERN DOTS-25678;So;0;ON;;;;;N;;;;; -28F3;BRAILLE PATTERN DOTS-125678;So;0;ON;;;;;N;;;;; -28F4;BRAILLE PATTERN DOTS-35678;So;0;ON;;;;;N;;;;; -28F5;BRAILLE PATTERN DOTS-135678;So;0;ON;;;;;N;;;;; -28F6;BRAILLE PATTERN DOTS-235678;So;0;ON;;;;;N;;;;; -28F7;BRAILLE PATTERN DOTS-1235678;So;0;ON;;;;;N;;;;; -28F8;BRAILLE PATTERN DOTS-45678;So;0;ON;;;;;N;;;;; -28F9;BRAILLE PATTERN DOTS-145678;So;0;ON;;;;;N;;;;; -28FA;BRAILLE PATTERN DOTS-245678;So;0;ON;;;;;N;;;;; -28FB;BRAILLE PATTERN DOTS-1245678;So;0;ON;;;;;N;;;;; -28FC;BRAILLE PATTERN DOTS-345678;So;0;ON;;;;;N;;;;; -28FD;BRAILLE PATTERN DOTS-1345678;So;0;ON;;;;;N;;;;; -28FE;BRAILLE PATTERN DOTS-2345678;So;0;ON;;;;;N;;;;; -28FF;BRAILLE PATTERN DOTS-12345678;So;0;ON;;;;;N;;;;; +2800;BRAILLE PATTERN BLANK;So;0;L;;;;;N;;;;; +2801;BRAILLE PATTERN DOTS-1;So;0;L;;;;;N;;;;; +2802;BRAILLE PATTERN DOTS-2;So;0;L;;;;;N;;;;; +2803;BRAILLE PATTERN DOTS-12;So;0;L;;;;;N;;;;; +2804;BRAILLE PATTERN DOTS-3;So;0;L;;;;;N;;;;; +2805;BRAILLE PATTERN DOTS-13;So;0;L;;;;;N;;;;; +2806;BRAILLE PATTERN DOTS-23;So;0;L;;;;;N;;;;; +2807;BRAILLE PATTERN DOTS-123;So;0;L;;;;;N;;;;; +2808;BRAILLE PATTERN DOTS-4;So;0;L;;;;;N;;;;; +2809;BRAILLE PATTERN DOTS-14;So;0;L;;;;;N;;;;; +280A;BRAILLE PATTERN DOTS-24;So;0;L;;;;;N;;;;; +280B;BRAILLE PATTERN DOTS-124;So;0;L;;;;;N;;;;; +280C;BRAILLE PATTERN DOTS-34;So;0;L;;;;;N;;;;; +280D;BRAILLE PATTERN DOTS-134;So;0;L;;;;;N;;;;; +280E;BRAILLE PATTERN DOTS-234;So;0;L;;;;;N;;;;; +280F;BRAILLE PATTERN DOTS-1234;So;0;L;;;;;N;;;;; +2810;BRAILLE PATTERN DOTS-5;So;0;L;;;;;N;;;;; +2811;BRAILLE PATTERN DOTS-15;So;0;L;;;;;N;;;;; +2812;BRAILLE PATTERN DOTS-25;So;0;L;;;;;N;;;;; +2813;BRAILLE PATTERN DOTS-125;So;0;L;;;;;N;;;;; +2814;BRAILLE PATTERN DOTS-35;So;0;L;;;;;N;;;;; +2815;BRAILLE PATTERN DOTS-135;So;0;L;;;;;N;;;;; +2816;BRAILLE PATTERN DOTS-235;So;0;L;;;;;N;;;;; +2817;BRAILLE PATTERN DOTS-1235;So;0;L;;;;;N;;;;; +2818;BRAILLE PATTERN DOTS-45;So;0;L;;;;;N;;;;; +2819;BRAILLE PATTERN DOTS-145;So;0;L;;;;;N;;;;; +281A;BRAILLE PATTERN DOTS-245;So;0;L;;;;;N;;;;; +281B;BRAILLE PATTERN DOTS-1245;So;0;L;;;;;N;;;;; +281C;BRAILLE PATTERN DOTS-345;So;0;L;;;;;N;;;;; +281D;BRAILLE PATTERN DOTS-1345;So;0;L;;;;;N;;;;; +281E;BRAILLE PATTERN DOTS-2345;So;0;L;;;;;N;;;;; +281F;BRAILLE PATTERN DOTS-12345;So;0;L;;;;;N;;;;; +2820;BRAILLE PATTERN DOTS-6;So;0;L;;;;;N;;;;; +2821;BRAILLE PATTERN DOTS-16;So;0;L;;;;;N;;;;; +2822;BRAILLE PATTERN DOTS-26;So;0;L;;;;;N;;;;; +2823;BRAILLE PATTERN DOTS-126;So;0;L;;;;;N;;;;; +2824;BRAILLE PATTERN DOTS-36;So;0;L;;;;;N;;;;; +2825;BRAILLE PATTERN DOTS-136;So;0;L;;;;;N;;;;; +2826;BRAILLE PATTERN DOTS-236;So;0;L;;;;;N;;;;; +2827;BRAILLE PATTERN DOTS-1236;So;0;L;;;;;N;;;;; +2828;BRAILLE PATTERN DOTS-46;So;0;L;;;;;N;;;;; +2829;BRAILLE PATTERN DOTS-146;So;0;L;;;;;N;;;;; +282A;BRAILLE PATTERN DOTS-246;So;0;L;;;;;N;;;;; +282B;BRAILLE PATTERN DOTS-1246;So;0;L;;;;;N;;;;; +282C;BRAILLE PATTERN DOTS-346;So;0;L;;;;;N;;;;; +282D;BRAILLE PATTERN DOTS-1346;So;0;L;;;;;N;;;;; +282E;BRAILLE PATTERN DOTS-2346;So;0;L;;;;;N;;;;; +282F;BRAILLE PATTERN DOTS-12346;So;0;L;;;;;N;;;;; +2830;BRAILLE PATTERN DOTS-56;So;0;L;;;;;N;;;;; +2831;BRAILLE PATTERN DOTS-156;So;0;L;;;;;N;;;;; +2832;BRAILLE PATTERN DOTS-256;So;0;L;;;;;N;;;;; +2833;BRAILLE PATTERN DOTS-1256;So;0;L;;;;;N;;;;; +2834;BRAILLE PATTERN DOTS-356;So;0;L;;;;;N;;;;; +2835;BRAILLE PATTERN DOTS-1356;So;0;L;;;;;N;;;;; +2836;BRAILLE PATTERN DOTS-2356;So;0;L;;;;;N;;;;; +2837;BRAILLE PATTERN DOTS-12356;So;0;L;;;;;N;;;;; +2838;BRAILLE PATTERN DOTS-456;So;0;L;;;;;N;;;;; +2839;BRAILLE PATTERN DOTS-1456;So;0;L;;;;;N;;;;; +283A;BRAILLE PATTERN DOTS-2456;So;0;L;;;;;N;;;;; +283B;BRAILLE PATTERN DOTS-12456;So;0;L;;;;;N;;;;; +283C;BRAILLE PATTERN DOTS-3456;So;0;L;;;;;N;;;;; +283D;BRAILLE PATTERN DOTS-13456;So;0;L;;;;;N;;;;; +283E;BRAILLE PATTERN DOTS-23456;So;0;L;;;;;N;;;;; +283F;BRAILLE PATTERN DOTS-123456;So;0;L;;;;;N;;;;; +2840;BRAILLE PATTERN DOTS-7;So;0;L;;;;;N;;;;; +2841;BRAILLE PATTERN DOTS-17;So;0;L;;;;;N;;;;; +2842;BRAILLE PATTERN DOTS-27;So;0;L;;;;;N;;;;; +2843;BRAILLE PATTERN DOTS-127;So;0;L;;;;;N;;;;; +2844;BRAILLE PATTERN DOTS-37;So;0;L;;;;;N;;;;; +2845;BRAILLE PATTERN DOTS-137;So;0;L;;;;;N;;;;; +2846;BRAILLE PATTERN DOTS-237;So;0;L;;;;;N;;;;; +2847;BRAILLE PATTERN DOTS-1237;So;0;L;;;;;N;;;;; +2848;BRAILLE PATTERN DOTS-47;So;0;L;;;;;N;;;;; +2849;BRAILLE PATTERN DOTS-147;So;0;L;;;;;N;;;;; +284A;BRAILLE PATTERN DOTS-247;So;0;L;;;;;N;;;;; +284B;BRAILLE PATTERN DOTS-1247;So;0;L;;;;;N;;;;; +284C;BRAILLE PATTERN DOTS-347;So;0;L;;;;;N;;;;; +284D;BRAILLE PATTERN DOTS-1347;So;0;L;;;;;N;;;;; +284E;BRAILLE PATTERN DOTS-2347;So;0;L;;;;;N;;;;; +284F;BRAILLE PATTERN DOTS-12347;So;0;L;;;;;N;;;;; +2850;BRAILLE PATTERN DOTS-57;So;0;L;;;;;N;;;;; +2851;BRAILLE PATTERN DOTS-157;So;0;L;;;;;N;;;;; +2852;BRAILLE PATTERN DOTS-257;So;0;L;;;;;N;;;;; +2853;BRAILLE PATTERN DOTS-1257;So;0;L;;;;;N;;;;; +2854;BRAILLE PATTERN DOTS-357;So;0;L;;;;;N;;;;; +2855;BRAILLE PATTERN DOTS-1357;So;0;L;;;;;N;;;;; +2856;BRAILLE PATTERN DOTS-2357;So;0;L;;;;;N;;;;; +2857;BRAILLE PATTERN DOTS-12357;So;0;L;;;;;N;;;;; +2858;BRAILLE PATTERN DOTS-457;So;0;L;;;;;N;;;;; +2859;BRAILLE PATTERN DOTS-1457;So;0;L;;;;;N;;;;; +285A;BRAILLE PATTERN DOTS-2457;So;0;L;;;;;N;;;;; +285B;BRAILLE PATTERN DOTS-12457;So;0;L;;;;;N;;;;; +285C;BRAILLE PATTERN DOTS-3457;So;0;L;;;;;N;;;;; +285D;BRAILLE PATTERN DOTS-13457;So;0;L;;;;;N;;;;; +285E;BRAILLE PATTERN DOTS-23457;So;0;L;;;;;N;;;;; +285F;BRAILLE PATTERN DOTS-123457;So;0;L;;;;;N;;;;; +2860;BRAILLE PATTERN DOTS-67;So;0;L;;;;;N;;;;; +2861;BRAILLE PATTERN DOTS-167;So;0;L;;;;;N;;;;; +2862;BRAILLE PATTERN DOTS-267;So;0;L;;;;;N;;;;; +2863;BRAILLE PATTERN DOTS-1267;So;0;L;;;;;N;;;;; +2864;BRAILLE PATTERN DOTS-367;So;0;L;;;;;N;;;;; +2865;BRAILLE PATTERN DOTS-1367;So;0;L;;;;;N;;;;; +2866;BRAILLE PATTERN DOTS-2367;So;0;L;;;;;N;;;;; +2867;BRAILLE PATTERN DOTS-12367;So;0;L;;;;;N;;;;; +2868;BRAILLE PATTERN DOTS-467;So;0;L;;;;;N;;;;; +2869;BRAILLE PATTERN DOTS-1467;So;0;L;;;;;N;;;;; +286A;BRAILLE PATTERN DOTS-2467;So;0;L;;;;;N;;;;; +286B;BRAILLE PATTERN DOTS-12467;So;0;L;;;;;N;;;;; +286C;BRAILLE PATTERN DOTS-3467;So;0;L;;;;;N;;;;; +286D;BRAILLE PATTERN DOTS-13467;So;0;L;;;;;N;;;;; +286E;BRAILLE PATTERN DOTS-23467;So;0;L;;;;;N;;;;; +286F;BRAILLE PATTERN DOTS-123467;So;0;L;;;;;N;;;;; +2870;BRAILLE PATTERN DOTS-567;So;0;L;;;;;N;;;;; +2871;BRAILLE PATTERN DOTS-1567;So;0;L;;;;;N;;;;; +2872;BRAILLE PATTERN DOTS-2567;So;0;L;;;;;N;;;;; +2873;BRAILLE PATTERN DOTS-12567;So;0;L;;;;;N;;;;; +2874;BRAILLE PATTERN DOTS-3567;So;0;L;;;;;N;;;;; +2875;BRAILLE PATTERN DOTS-13567;So;0;L;;;;;N;;;;; +2876;BRAILLE PATTERN DOTS-23567;So;0;L;;;;;N;;;;; +2877;BRAILLE PATTERN DOTS-123567;So;0;L;;;;;N;;;;; +2878;BRAILLE PATTERN DOTS-4567;So;0;L;;;;;N;;;;; +2879;BRAILLE PATTERN DOTS-14567;So;0;L;;;;;N;;;;; +287A;BRAILLE PATTERN DOTS-24567;So;0;L;;;;;N;;;;; +287B;BRAILLE PATTERN DOTS-124567;So;0;L;;;;;N;;;;; +287C;BRAILLE PATTERN DOTS-34567;So;0;L;;;;;N;;;;; +287D;BRAILLE PATTERN DOTS-134567;So;0;L;;;;;N;;;;; +287E;BRAILLE PATTERN DOTS-234567;So;0;L;;;;;N;;;;; +287F;BRAILLE PATTERN DOTS-1234567;So;0;L;;;;;N;;;;; +2880;BRAILLE PATTERN DOTS-8;So;0;L;;;;;N;;;;; +2881;BRAILLE PATTERN DOTS-18;So;0;L;;;;;N;;;;; +2882;BRAILLE PATTERN DOTS-28;So;0;L;;;;;N;;;;; +2883;BRAILLE PATTERN DOTS-128;So;0;L;;;;;N;;;;; +2884;BRAILLE PATTERN DOTS-38;So;0;L;;;;;N;;;;; +2885;BRAILLE PATTERN DOTS-138;So;0;L;;;;;N;;;;; +2886;BRAILLE PATTERN DOTS-238;So;0;L;;;;;N;;;;; +2887;BRAILLE PATTERN DOTS-1238;So;0;L;;;;;N;;;;; +2888;BRAILLE PATTERN DOTS-48;So;0;L;;;;;N;;;;; +2889;BRAILLE PATTERN DOTS-148;So;0;L;;;;;N;;;;; +288A;BRAILLE PATTERN DOTS-248;So;0;L;;;;;N;;;;; +288B;BRAILLE PATTERN DOTS-1248;So;0;L;;;;;N;;;;; +288C;BRAILLE PATTERN DOTS-348;So;0;L;;;;;N;;;;; +288D;BRAILLE PATTERN DOTS-1348;So;0;L;;;;;N;;;;; +288E;BRAILLE PATTERN DOTS-2348;So;0;L;;;;;N;;;;; +288F;BRAILLE PATTERN DOTS-12348;So;0;L;;;;;N;;;;; +2890;BRAILLE PATTERN DOTS-58;So;0;L;;;;;N;;;;; +2891;BRAILLE PATTERN DOTS-158;So;0;L;;;;;N;;;;; +2892;BRAILLE PATTERN DOTS-258;So;0;L;;;;;N;;;;; +2893;BRAILLE PATTERN DOTS-1258;So;0;L;;;;;N;;;;; +2894;BRAILLE PATTERN DOTS-358;So;0;L;;;;;N;;;;; +2895;BRAILLE PATTERN DOTS-1358;So;0;L;;;;;N;;;;; +2896;BRAILLE PATTERN DOTS-2358;So;0;L;;;;;N;;;;; +2897;BRAILLE PATTERN DOTS-12358;So;0;L;;;;;N;;;;; +2898;BRAILLE PATTERN DOTS-458;So;0;L;;;;;N;;;;; +2899;BRAILLE PATTERN DOTS-1458;So;0;L;;;;;N;;;;; +289A;BRAILLE PATTERN DOTS-2458;So;0;L;;;;;N;;;;; +289B;BRAILLE PATTERN DOTS-12458;So;0;L;;;;;N;;;;; +289C;BRAILLE PATTERN DOTS-3458;So;0;L;;;;;N;;;;; +289D;BRAILLE PATTERN DOTS-13458;So;0;L;;;;;N;;;;; +289E;BRAILLE PATTERN DOTS-23458;So;0;L;;;;;N;;;;; +289F;BRAILLE PATTERN DOTS-123458;So;0;L;;;;;N;;;;; +28A0;BRAILLE PATTERN DOTS-68;So;0;L;;;;;N;;;;; +28A1;BRAILLE PATTERN DOTS-168;So;0;L;;;;;N;;;;; +28A2;BRAILLE PATTERN DOTS-268;So;0;L;;;;;N;;;;; +28A3;BRAILLE PATTERN DOTS-1268;So;0;L;;;;;N;;;;; +28A4;BRAILLE PATTERN DOTS-368;So;0;L;;;;;N;;;;; +28A5;BRAILLE PATTERN DOTS-1368;So;0;L;;;;;N;;;;; +28A6;BRAILLE PATTERN DOTS-2368;So;0;L;;;;;N;;;;; +28A7;BRAILLE PATTERN DOTS-12368;So;0;L;;;;;N;;;;; +28A8;BRAILLE PATTERN DOTS-468;So;0;L;;;;;N;;;;; +28A9;BRAILLE PATTERN DOTS-1468;So;0;L;;;;;N;;;;; +28AA;BRAILLE PATTERN DOTS-2468;So;0;L;;;;;N;;;;; +28AB;BRAILLE PATTERN DOTS-12468;So;0;L;;;;;N;;;;; +28AC;BRAILLE PATTERN DOTS-3468;So;0;L;;;;;N;;;;; +28AD;BRAILLE PATTERN DOTS-13468;So;0;L;;;;;N;;;;; +28AE;BRAILLE PATTERN DOTS-23468;So;0;L;;;;;N;;;;; +28AF;BRAILLE PATTERN DOTS-123468;So;0;L;;;;;N;;;;; +28B0;BRAILLE PATTERN DOTS-568;So;0;L;;;;;N;;;;; +28B1;BRAILLE PATTERN DOTS-1568;So;0;L;;;;;N;;;;; +28B2;BRAILLE PATTERN DOTS-2568;So;0;L;;;;;N;;;;; +28B3;BRAILLE PATTERN DOTS-12568;So;0;L;;;;;N;;;;; +28B4;BRAILLE PATTERN DOTS-3568;So;0;L;;;;;N;;;;; +28B5;BRAILLE PATTERN DOTS-13568;So;0;L;;;;;N;;;;; +28B6;BRAILLE PATTERN DOTS-23568;So;0;L;;;;;N;;;;; +28B7;BRAILLE PATTERN DOTS-123568;So;0;L;;;;;N;;;;; +28B8;BRAILLE PATTERN DOTS-4568;So;0;L;;;;;N;;;;; +28B9;BRAILLE PATTERN DOTS-14568;So;0;L;;;;;N;;;;; +28BA;BRAILLE PATTERN DOTS-24568;So;0;L;;;;;N;;;;; +28BB;BRAILLE PATTERN DOTS-124568;So;0;L;;;;;N;;;;; +28BC;BRAILLE PATTERN DOTS-34568;So;0;L;;;;;N;;;;; +28BD;BRAILLE PATTERN DOTS-134568;So;0;L;;;;;N;;;;; +28BE;BRAILLE PATTERN DOTS-234568;So;0;L;;;;;N;;;;; +28BF;BRAILLE PATTERN DOTS-1234568;So;0;L;;;;;N;;;;; +28C0;BRAILLE PATTERN DOTS-78;So;0;L;;;;;N;;;;; +28C1;BRAILLE PATTERN DOTS-178;So;0;L;;;;;N;;;;; +28C2;BRAILLE PATTERN DOTS-278;So;0;L;;;;;N;;;;; +28C3;BRAILLE PATTERN DOTS-1278;So;0;L;;;;;N;;;;; +28C4;BRAILLE PATTERN DOTS-378;So;0;L;;;;;N;;;;; +28C5;BRAILLE PATTERN DOTS-1378;So;0;L;;;;;N;;;;; +28C6;BRAILLE PATTERN DOTS-2378;So;0;L;;;;;N;;;;; +28C7;BRAILLE PATTERN DOTS-12378;So;0;L;;;;;N;;;;; +28C8;BRAILLE PATTERN DOTS-478;So;0;L;;;;;N;;;;; +28C9;BRAILLE PATTERN DOTS-1478;So;0;L;;;;;N;;;;; +28CA;BRAILLE PATTERN DOTS-2478;So;0;L;;;;;N;;;;; +28CB;BRAILLE PATTERN DOTS-12478;So;0;L;;;;;N;;;;; +28CC;BRAILLE PATTERN DOTS-3478;So;0;L;;;;;N;;;;; +28CD;BRAILLE PATTERN DOTS-13478;So;0;L;;;;;N;;;;; +28CE;BRAILLE PATTERN DOTS-23478;So;0;L;;;;;N;;;;; +28CF;BRAILLE PATTERN DOTS-123478;So;0;L;;;;;N;;;;; +28D0;BRAILLE PATTERN DOTS-578;So;0;L;;;;;N;;;;; +28D1;BRAILLE PATTERN DOTS-1578;So;0;L;;;;;N;;;;; +28D2;BRAILLE PATTERN DOTS-2578;So;0;L;;;;;N;;;;; +28D3;BRAILLE PATTERN DOTS-12578;So;0;L;;;;;N;;;;; +28D4;BRAILLE PATTERN DOTS-3578;So;0;L;;;;;N;;;;; +28D5;BRAILLE PATTERN DOTS-13578;So;0;L;;;;;N;;;;; +28D6;BRAILLE PATTERN DOTS-23578;So;0;L;;;;;N;;;;; +28D7;BRAILLE PATTERN DOTS-123578;So;0;L;;;;;N;;;;; +28D8;BRAILLE PATTERN DOTS-4578;So;0;L;;;;;N;;;;; +28D9;BRAILLE PATTERN DOTS-14578;So;0;L;;;;;N;;;;; +28DA;BRAILLE PATTERN DOTS-24578;So;0;L;;;;;N;;;;; +28DB;BRAILLE PATTERN DOTS-124578;So;0;L;;;;;N;;;;; +28DC;BRAILLE PATTERN DOTS-34578;So;0;L;;;;;N;;;;; +28DD;BRAILLE PATTERN DOTS-134578;So;0;L;;;;;N;;;;; +28DE;BRAILLE PATTERN DOTS-234578;So;0;L;;;;;N;;;;; +28DF;BRAILLE PATTERN DOTS-1234578;So;0;L;;;;;N;;;;; +28E0;BRAILLE PATTERN DOTS-678;So;0;L;;;;;N;;;;; +28E1;BRAILLE PATTERN DOTS-1678;So;0;L;;;;;N;;;;; +28E2;BRAILLE PATTERN DOTS-2678;So;0;L;;;;;N;;;;; +28E3;BRAILLE PATTERN DOTS-12678;So;0;L;;;;;N;;;;; +28E4;BRAILLE PATTERN DOTS-3678;So;0;L;;;;;N;;;;; +28E5;BRAILLE PATTERN DOTS-13678;So;0;L;;;;;N;;;;; +28E6;BRAILLE PATTERN DOTS-23678;So;0;L;;;;;N;;;;; +28E7;BRAILLE PATTERN DOTS-123678;So;0;L;;;;;N;;;;; +28E8;BRAILLE PATTERN DOTS-4678;So;0;L;;;;;N;;;;; +28E9;BRAILLE PATTERN DOTS-14678;So;0;L;;;;;N;;;;; +28EA;BRAILLE PATTERN DOTS-24678;So;0;L;;;;;N;;;;; +28EB;BRAILLE PATTERN DOTS-124678;So;0;L;;;;;N;;;;; +28EC;BRAILLE PATTERN DOTS-34678;So;0;L;;;;;N;;;;; +28ED;BRAILLE PATTERN DOTS-134678;So;0;L;;;;;N;;;;; +28EE;BRAILLE PATTERN DOTS-234678;So;0;L;;;;;N;;;;; +28EF;BRAILLE PATTERN DOTS-1234678;So;0;L;;;;;N;;;;; +28F0;BRAILLE PATTERN DOTS-5678;So;0;L;;;;;N;;;;; +28F1;BRAILLE PATTERN DOTS-15678;So;0;L;;;;;N;;;;; +28F2;BRAILLE PATTERN DOTS-25678;So;0;L;;;;;N;;;;; +28F3;BRAILLE PATTERN DOTS-125678;So;0;L;;;;;N;;;;; +28F4;BRAILLE PATTERN DOTS-35678;So;0;L;;;;;N;;;;; +28F5;BRAILLE PATTERN DOTS-135678;So;0;L;;;;;N;;;;; +28F6;BRAILLE PATTERN DOTS-235678;So;0;L;;;;;N;;;;; +28F7;BRAILLE PATTERN DOTS-1235678;So;0;L;;;;;N;;;;; +28F8;BRAILLE PATTERN DOTS-45678;So;0;L;;;;;N;;;;; +28F9;BRAILLE PATTERN DOTS-145678;So;0;L;;;;;N;;;;; +28FA;BRAILLE PATTERN DOTS-245678;So;0;L;;;;;N;;;;; +28FB;BRAILLE PATTERN DOTS-1245678;So;0;L;;;;;N;;;;; +28FC;BRAILLE PATTERN DOTS-345678;So;0;L;;;;;N;;;;; +28FD;BRAILLE PATTERN DOTS-1345678;So;0;L;;;;;N;;;;; +28FE;BRAILLE PATTERN DOTS-2345678;So;0;L;;;;;N;;;;; +28FF;BRAILLE PATTERN DOTS-12345678;So;0;L;;;;;N;;;;; 2900;RIGHTWARDS TWO-HEADED ARROW WITH VERTICAL STROKE;Sm;0;ON;;;;;N;;;;; 2901;RIGHTWARDS TWO-HEADED ARROW WITH DOUBLE VERTICAL STROKE;Sm;0;ON;;;;;N;;;;; 2902;LEFTWARDS DOUBLE ARROW WITH VERTICAL STROKE;Sm;0;ON;;;;;N;;;;; @@ -8043,6 +9092,564 @@ 2B0B;SOUTH WEST BLACK ARROW;So;0;ON;;;;;N;;;;; 2B0C;LEFT RIGHT BLACK ARROW;So;0;ON;;;;;N;;;;; 2B0D;UP DOWN BLACK ARROW;So;0;ON;;;;;N;;;;; +2B0E;RIGHTWARDS ARROW WITH TIP DOWNWARDS;So;0;ON;;;;;N;;;;; +2B0F;RIGHTWARDS ARROW WITH TIP UPWARDS;So;0;ON;;;;;N;;;;; +2B10;LEFTWARDS ARROW WITH TIP DOWNWARDS;So;0;ON;;;;;N;;;;; +2B11;LEFTWARDS ARROW WITH TIP UPWARDS;So;0;ON;;;;;N;;;;; +2B12;SQUARE WITH TOP HALF BLACK;So;0;ON;;;;;N;;;;; +2B13;SQUARE WITH BOTTOM HALF BLACK;So;0;ON;;;;;N;;;;; +2B14;SQUARE WITH UPPER RIGHT DIAGONAL HALF BLACK;So;0;ON;;;;;N;;;;; +2B15;SQUARE WITH LOWER LEFT DIAGONAL HALF BLACK;So;0;ON;;;;;N;;;;; +2B16;DIAMOND WITH LEFT HALF BLACK;So;0;ON;;;;;N;;;;; +2B17;DIAMOND WITH RIGHT HALF BLACK;So;0;ON;;;;;N;;;;; +2B18;DIAMOND WITH TOP HALF BLACK;So;0;ON;;;;;N;;;;; +2B19;DIAMOND WITH BOTTOM HALF BLACK;So;0;ON;;;;;N;;;;; +2B1A;DOTTED SQUARE;So;0;ON;;;;;N;;;;; +2B1B;BLACK LARGE SQUARE;So;0;ON;;;;;N;;;;; +2B1C;WHITE LARGE SQUARE;So;0;ON;;;;;N;;;;; +2B1D;BLACK VERY SMALL SQUARE;So;0;ON;;;;;N;;;;; +2B1E;WHITE VERY SMALL SQUARE;So;0;ON;;;;;N;;;;; +2B1F;BLACK PENTAGON;So;0;ON;;;;;N;;;;; +2B20;WHITE PENTAGON;So;0;ON;;;;;N;;;;; +2B21;WHITE HEXAGON;So;0;ON;;;;;N;;;;; +2B22;BLACK HEXAGON;So;0;ON;;;;;N;;;;; +2B23;HORIZONTAL BLACK HEXAGON;So;0;ON;;;;;N;;;;; +2B24;BLACK LARGE CIRCLE;So;0;ON;;;;;N;;;;; +2B25;BLACK MEDIUM DIAMOND;So;0;ON;;;;;N;;;;; +2B26;WHITE MEDIUM DIAMOND;So;0;ON;;;;;N;;;;; +2B27;BLACK MEDIUM LOZENGE;So;0;ON;;;;;N;;;;; +2B28;WHITE MEDIUM LOZENGE;So;0;ON;;;;;N;;;;; +2B29;BLACK SMALL DIAMOND;So;0;ON;;;;;N;;;;; +2B2A;BLACK SMALL LOZENGE;So;0;ON;;;;;N;;;;; +2B2B;WHITE SMALL LOZENGE;So;0;ON;;;;;N;;;;; +2B2C;BLACK HORIZONTAL ELLIPSE;So;0;ON;;;;;N;;;;; +2B2D;WHITE HORIZONTAL ELLIPSE;So;0;ON;;;;;N;;;;; +2B2E;BLACK VERTICAL ELLIPSE;So;0;ON;;;;;N;;;;; +2B2F;WHITE VERTICAL ELLIPSE;So;0;ON;;;;;N;;;;; +2B30;LEFT ARROW WITH SMALL CIRCLE;Sm;0;ON;;;;;N;;;;; +2B31;THREE LEFTWARDS ARROWS;Sm;0;ON;;;;;N;;;;; +2B32;LEFT ARROW WITH CIRCLED PLUS;Sm;0;ON;;;;;N;;;;; +2B33;LONG LEFTWARDS SQUIGGLE ARROW;Sm;0;ON;;;;;N;;;;; +2B34;LEFTWARDS TWO-HEADED ARROW WITH VERTICAL STROKE;Sm;0;ON;;;;;N;;;;; +2B35;LEFTWARDS TWO-HEADED ARROW WITH DOUBLE VERTICAL STROKE;Sm;0;ON;;;;;N;;;;; +2B36;LEFTWARDS TWO-HEADED ARROW FROM BAR;Sm;0;ON;;;;;N;;;;; +2B37;LEFTWARDS TWO-HEADED TRIPLE DASH ARROW;Sm;0;ON;;;;;N;;;;; +2B38;LEFTWARDS ARROW WITH DOTTED STEM;Sm;0;ON;;;;;N;;;;; +2B39;LEFTWARDS ARROW WITH TAIL WITH VERTICAL STROKE;Sm;0;ON;;;;;N;;;;; +2B3A;LEFTWARDS ARROW WITH TAIL WITH DOUBLE VERTICAL STROKE;Sm;0;ON;;;;;N;;;;; +2B3B;LEFTWARDS TWO-HEADED ARROW WITH TAIL;Sm;0;ON;;;;;N;;;;; +2B3C;LEFTWARDS TWO-HEADED ARROW WITH TAIL WITH VERTICAL STROKE;Sm;0;ON;;;;;N;;;;; +2B3D;LEFTWARDS TWO-HEADED ARROW WITH TAIL WITH DOUBLE VERTICAL STROKE;Sm;0;ON;;;;;N;;;;; +2B3E;LEFTWARDS ARROW THROUGH X;Sm;0;ON;;;;;N;;;;; +2B3F;WAVE ARROW POINTING DIRECTLY LEFT;Sm;0;ON;;;;;N;;;;; +2B40;EQUALS SIGN ABOVE LEFTWARDS ARROW;Sm;0;ON;;;;;N;;;;; +2B41;REVERSE TILDE OPERATOR ABOVE LEFTWARDS ARROW;Sm;0;ON;;;;;N;;;;; +2B42;LEFTWARDS ARROW ABOVE REVERSE ALMOST EQUAL TO;Sm;0;ON;;;;;N;;;;; +2B43;RIGHTWARDS ARROW THROUGH GREATER-THAN;Sm;0;ON;;;;;N;;;;; +2B44;RIGHTWARDS ARROW THROUGH SUPERSET;Sm;0;ON;;;;;N;;;;; +2B45;LEFTWARDS QUADRUPLE ARROW;So;0;ON;;;;;N;;;;; +2B46;RIGHTWARDS QUADRUPLE ARROW;So;0;ON;;;;;N;;;;; +2B47;REVERSE TILDE OPERATOR ABOVE RIGHTWARDS ARROW;Sm;0;ON;;;;;N;;;;; +2B48;RIGHTWARDS ARROW ABOVE REVERSE ALMOST EQUAL TO;Sm;0;ON;;;;;N;;;;; +2B49;TILDE OPERATOR ABOVE LEFTWARDS ARROW;Sm;0;ON;;;;;N;;;;; +2B4A;LEFTWARDS ARROW ABOVE ALMOST EQUAL TO;Sm;0;ON;;;;;N;;;;; +2B4B;LEFTWARDS ARROW ABOVE REVERSE TILDE OPERATOR;Sm;0;ON;;;;;N;;;;; +2B4C;RIGHTWARDS ARROW ABOVE REVERSE TILDE OPERATOR;Sm;0;ON;;;;;N;;;;; +2B50;WHITE MEDIUM STAR;So;0;ON;;;;;N;;;;; +2B51;BLACK SMALL STAR;So;0;ON;;;;;N;;;;; +2B52;WHITE SMALL STAR;So;0;ON;;;;;N;;;;; +2B53;BLACK RIGHT-POINTING PENTAGON;So;0;ON;;;;;N;;;;; +2B54;WHITE RIGHT-POINTING PENTAGON;So;0;ON;;;;;N;;;;; +2C00;GLAGOLITIC CAPITAL LETTER AZU;Lu;0;L;;;;;N;;;;2C30; +2C01;GLAGOLITIC CAPITAL LETTER BUKY;Lu;0;L;;;;;N;;;;2C31; +2C02;GLAGOLITIC CAPITAL LETTER VEDE;Lu;0;L;;;;;N;;;;2C32; +2C03;GLAGOLITIC CAPITAL LETTER GLAGOLI;Lu;0;L;;;;;N;;;;2C33; +2C04;GLAGOLITIC CAPITAL LETTER DOBRO;Lu;0;L;;;;;N;;;;2C34; +2C05;GLAGOLITIC CAPITAL LETTER YESTU;Lu;0;L;;;;;N;;;;2C35; +2C06;GLAGOLITIC CAPITAL LETTER ZHIVETE;Lu;0;L;;;;;N;;;;2C36; +2C07;GLAGOLITIC CAPITAL LETTER DZELO;Lu;0;L;;;;;N;;;;2C37; +2C08;GLAGOLITIC CAPITAL LETTER ZEMLJA;Lu;0;L;;;;;N;;;;2C38; +2C09;GLAGOLITIC CAPITAL LETTER IZHE;Lu;0;L;;;;;N;;;;2C39; +2C0A;GLAGOLITIC CAPITAL LETTER INITIAL IZHE;Lu;0;L;;;;;N;;;;2C3A; +2C0B;GLAGOLITIC CAPITAL LETTER I;Lu;0;L;;;;;N;;;;2C3B; +2C0C;GLAGOLITIC CAPITAL LETTER DJERVI;Lu;0;L;;;;;N;;;;2C3C; +2C0D;GLAGOLITIC CAPITAL LETTER KAKO;Lu;0;L;;;;;N;;;;2C3D; +2C0E;GLAGOLITIC CAPITAL LETTER LJUDIJE;Lu;0;L;;;;;N;;;;2C3E; +2C0F;GLAGOLITIC CAPITAL LETTER MYSLITE;Lu;0;L;;;;;N;;;;2C3F; +2C10;GLAGOLITIC CAPITAL LETTER NASHI;Lu;0;L;;;;;N;;;;2C40; +2C11;GLAGOLITIC CAPITAL LETTER ONU;Lu;0;L;;;;;N;;;;2C41; +2C12;GLAGOLITIC CAPITAL LETTER POKOJI;Lu;0;L;;;;;N;;;;2C42; +2C13;GLAGOLITIC CAPITAL LETTER RITSI;Lu;0;L;;;;;N;;;;2C43; +2C14;GLAGOLITIC CAPITAL LETTER SLOVO;Lu;0;L;;;;;N;;;;2C44; +2C15;GLAGOLITIC CAPITAL LETTER TVRIDO;Lu;0;L;;;;;N;;;;2C45; +2C16;GLAGOLITIC CAPITAL LETTER UKU;Lu;0;L;;;;;N;;;;2C46; +2C17;GLAGOLITIC CAPITAL LETTER FRITU;Lu;0;L;;;;;N;;;;2C47; +2C18;GLAGOLITIC CAPITAL LETTER HERU;Lu;0;L;;;;;N;;;;2C48; +2C19;GLAGOLITIC CAPITAL LETTER OTU;Lu;0;L;;;;;N;;;;2C49; +2C1A;GLAGOLITIC CAPITAL LETTER PE;Lu;0;L;;;;;N;;;;2C4A; +2C1B;GLAGOLITIC CAPITAL LETTER SHTA;Lu;0;L;;;;;N;;;;2C4B; +2C1C;GLAGOLITIC CAPITAL LETTER TSI;Lu;0;L;;;;;N;;;;2C4C; +2C1D;GLAGOLITIC CAPITAL LETTER CHRIVI;Lu;0;L;;;;;N;;;;2C4D; +2C1E;GLAGOLITIC CAPITAL LETTER SHA;Lu;0;L;;;;;N;;;;2C4E; +2C1F;GLAGOLITIC CAPITAL LETTER YERU;Lu;0;L;;;;;N;;;;2C4F; +2C20;GLAGOLITIC CAPITAL LETTER YERI;Lu;0;L;;;;;N;;;;2C50; +2C21;GLAGOLITIC CAPITAL LETTER YATI;Lu;0;L;;;;;N;;;;2C51; +2C22;GLAGOLITIC CAPITAL LETTER SPIDERY HA;Lu;0;L;;;;;N;;;;2C52; +2C23;GLAGOLITIC CAPITAL LETTER YU;Lu;0;L;;;;;N;;;;2C53; +2C24;GLAGOLITIC CAPITAL LETTER SMALL YUS;Lu;0;L;;;;;N;;;;2C54; +2C25;GLAGOLITIC CAPITAL LETTER SMALL YUS WITH TAIL;Lu;0;L;;;;;N;;;;2C55; +2C26;GLAGOLITIC CAPITAL LETTER YO;Lu;0;L;;;;;N;;;;2C56; +2C27;GLAGOLITIC CAPITAL LETTER IOTATED SMALL YUS;Lu;0;L;;;;;N;;;;2C57; +2C28;GLAGOLITIC CAPITAL LETTER BIG YUS;Lu;0;L;;;;;N;;;;2C58; +2C29;GLAGOLITIC CAPITAL LETTER IOTATED BIG YUS;Lu;0;L;;;;;N;;;;2C59; +2C2A;GLAGOLITIC CAPITAL LETTER FITA;Lu;0;L;;;;;N;;;;2C5A; +2C2B;GLAGOLITIC CAPITAL LETTER IZHITSA;Lu;0;L;;;;;N;;;;2C5B; +2C2C;GLAGOLITIC CAPITAL LETTER SHTAPIC;Lu;0;L;;;;;N;;;;2C5C; +2C2D;GLAGOLITIC CAPITAL LETTER TROKUTASTI A;Lu;0;L;;;;;N;;;;2C5D; +2C2E;GLAGOLITIC CAPITAL LETTER LATINATE MYSLITE;Lu;0;L;;;;;N;;;;2C5E; +2C30;GLAGOLITIC SMALL LETTER AZU;Ll;0;L;;;;;N;;;2C00;;2C00 +2C31;GLAGOLITIC SMALL LETTER BUKY;Ll;0;L;;;;;N;;;2C01;;2C01 +2C32;GLAGOLITIC SMALL LETTER VEDE;Ll;0;L;;;;;N;;;2C02;;2C02 +2C33;GLAGOLITIC SMALL LETTER GLAGOLI;Ll;0;L;;;;;N;;;2C03;;2C03 +2C34;GLAGOLITIC SMALL LETTER DOBRO;Ll;0;L;;;;;N;;;2C04;;2C04 +2C35;GLAGOLITIC SMALL LETTER YESTU;Ll;0;L;;;;;N;;;2C05;;2C05 +2C36;GLAGOLITIC SMALL LETTER ZHIVETE;Ll;0;L;;;;;N;;;2C06;;2C06 +2C37;GLAGOLITIC SMALL LETTER DZELO;Ll;0;L;;;;;N;;;2C07;;2C07 +2C38;GLAGOLITIC SMALL LETTER ZEMLJA;Ll;0;L;;;;;N;;;2C08;;2C08 +2C39;GLAGOLITIC SMALL LETTER IZHE;Ll;0;L;;;;;N;;;2C09;;2C09 +2C3A;GLAGOLITIC SMALL LETTER INITIAL IZHE;Ll;0;L;;;;;N;;;2C0A;;2C0A +2C3B;GLAGOLITIC SMALL LETTER I;Ll;0;L;;;;;N;;;2C0B;;2C0B +2C3C;GLAGOLITIC SMALL LETTER DJERVI;Ll;0;L;;;;;N;;;2C0C;;2C0C +2C3D;GLAGOLITIC SMALL LETTER KAKO;Ll;0;L;;;;;N;;;2C0D;;2C0D +2C3E;GLAGOLITIC SMALL LETTER LJUDIJE;Ll;0;L;;;;;N;;;2C0E;;2C0E +2C3F;GLAGOLITIC SMALL LETTER MYSLITE;Ll;0;L;;;;;N;;;2C0F;;2C0F +2C40;GLAGOLITIC SMALL LETTER NASHI;Ll;0;L;;;;;N;;;2C10;;2C10 +2C41;GLAGOLITIC SMALL LETTER ONU;Ll;0;L;;;;;N;;;2C11;;2C11 +2C42;GLAGOLITIC SMALL LETTER POKOJI;Ll;0;L;;;;;N;;;2C12;;2C12 +2C43;GLAGOLITIC SMALL LETTER RITSI;Ll;0;L;;;;;N;;;2C13;;2C13 +2C44;GLAGOLITIC SMALL LETTER SLOVO;Ll;0;L;;;;;N;;;2C14;;2C14 +2C45;GLAGOLITIC SMALL LETTER TVRIDO;Ll;0;L;;;;;N;;;2C15;;2C15 +2C46;GLAGOLITIC SMALL LETTER UKU;Ll;0;L;;;;;N;;;2C16;;2C16 +2C47;GLAGOLITIC SMALL LETTER FRITU;Ll;0;L;;;;;N;;;2C17;;2C17 +2C48;GLAGOLITIC SMALL LETTER HERU;Ll;0;L;;;;;N;;;2C18;;2C18 +2C49;GLAGOLITIC SMALL LETTER OTU;Ll;0;L;;;;;N;;;2C19;;2C19 +2C4A;GLAGOLITIC SMALL LETTER PE;Ll;0;L;;;;;N;;;2C1A;;2C1A +2C4B;GLAGOLITIC SMALL LETTER SHTA;Ll;0;L;;;;;N;;;2C1B;;2C1B +2C4C;GLAGOLITIC SMALL LETTER TSI;Ll;0;L;;;;;N;;;2C1C;;2C1C +2C4D;GLAGOLITIC SMALL LETTER CHRIVI;Ll;0;L;;;;;N;;;2C1D;;2C1D +2C4E;GLAGOLITIC SMALL LETTER SHA;Ll;0;L;;;;;N;;;2C1E;;2C1E +2C4F;GLAGOLITIC SMALL LETTER YERU;Ll;0;L;;;;;N;;;2C1F;;2C1F +2C50;GLAGOLITIC SMALL LETTER YERI;Ll;0;L;;;;;N;;;2C20;;2C20 +2C51;GLAGOLITIC SMALL LETTER YATI;Ll;0;L;;;;;N;;;2C21;;2C21 +2C52;GLAGOLITIC SMALL LETTER SPIDERY HA;Ll;0;L;;;;;N;;;2C22;;2C22 +2C53;GLAGOLITIC SMALL LETTER YU;Ll;0;L;;;;;N;;;2C23;;2C23 +2C54;GLAGOLITIC SMALL LETTER SMALL YUS;Ll;0;L;;;;;N;;;2C24;;2C24 +2C55;GLAGOLITIC SMALL LETTER SMALL YUS WITH TAIL;Ll;0;L;;;;;N;;;2C25;;2C25 +2C56;GLAGOLITIC SMALL LETTER YO;Ll;0;L;;;;;N;;;2C26;;2C26 +2C57;GLAGOLITIC SMALL LETTER IOTATED SMALL YUS;Ll;0;L;;;;;N;;;2C27;;2C27 +2C58;GLAGOLITIC SMALL LETTER BIG YUS;Ll;0;L;;;;;N;;;2C28;;2C28 +2C59;GLAGOLITIC SMALL LETTER IOTATED BIG YUS;Ll;0;L;;;;;N;;;2C29;;2C29 +2C5A;GLAGOLITIC SMALL LETTER FITA;Ll;0;L;;;;;N;;;2C2A;;2C2A +2C5B;GLAGOLITIC SMALL LETTER IZHITSA;Ll;0;L;;;;;N;;;2C2B;;2C2B +2C5C;GLAGOLITIC SMALL LETTER SHTAPIC;Ll;0;L;;;;;N;;;2C2C;;2C2C +2C5D;GLAGOLITIC SMALL LETTER TROKUTASTI A;Ll;0;L;;;;;N;;;2C2D;;2C2D +2C5E;GLAGOLITIC SMALL LETTER LATINATE MYSLITE;Ll;0;L;;;;;N;;;2C2E;;2C2E +2C60;LATIN CAPITAL LETTER L WITH DOUBLE BAR;Lu;0;L;;;;;N;;;;2C61; +2C61;LATIN SMALL LETTER L WITH DOUBLE BAR;Ll;0;L;;;;;N;;;2C60;;2C60 +2C62;LATIN CAPITAL LETTER L WITH MIDDLE TILDE;Lu;0;L;;;;;N;;;;026B; +2C63;LATIN CAPITAL LETTER P WITH STROKE;Lu;0;L;;;;;N;;;;1D7D; +2C64;LATIN CAPITAL LETTER R WITH TAIL;Lu;0;L;;;;;N;;;;027D; +2C65;LATIN SMALL LETTER A WITH STROKE;Ll;0;L;;;;;N;;;023A;;023A +2C66;LATIN SMALL LETTER T WITH DIAGONAL STROKE;Ll;0;L;;;;;N;;;023E;;023E +2C67;LATIN CAPITAL LETTER H WITH DESCENDER;Lu;0;L;;;;;N;;;;2C68; +2C68;LATIN SMALL LETTER H WITH DESCENDER;Ll;0;L;;;;;N;;;2C67;;2C67 +2C69;LATIN CAPITAL LETTER K WITH DESCENDER;Lu;0;L;;;;;N;;;;2C6A; +2C6A;LATIN SMALL LETTER K WITH DESCENDER;Ll;0;L;;;;;N;;;2C69;;2C69 +2C6B;LATIN CAPITAL LETTER Z WITH DESCENDER;Lu;0;L;;;;;N;;;;2C6C; +2C6C;LATIN SMALL LETTER Z WITH DESCENDER;Ll;0;L;;;;;N;;;2C6B;;2C6B +2C6D;LATIN CAPITAL LETTER ALPHA;Lu;0;L;;;;;N;;;;0251; +2C6E;LATIN CAPITAL LETTER M WITH HOOK;Lu;0;L;;;;;N;;;;0271; +2C6F;LATIN CAPITAL LETTER TURNED A;Lu;0;L;;;;;N;;;;0250; +2C71;LATIN SMALL LETTER V WITH RIGHT HOOK;Ll;0;L;;;;;N;;;;; +2C72;LATIN CAPITAL LETTER W WITH HOOK;Lu;0;L;;;;;N;;;;2C73; +2C73;LATIN SMALL LETTER W WITH HOOK;Ll;0;L;;;;;N;;;2C72;;2C72 +2C74;LATIN SMALL LETTER V WITH CURL;Ll;0;L;;;;;N;;;;; +2C75;LATIN CAPITAL LETTER HALF H;Lu;0;L;;;;;N;;;;2C76; +2C76;LATIN SMALL LETTER HALF H;Ll;0;L;;;;;N;;;2C75;;2C75 +2C77;LATIN SMALL LETTER TAILLESS PHI;Ll;0;L;;;;;N;;;;; +2C78;LATIN SMALL LETTER E WITH NOTCH;Ll;0;L;;;;;N;;;;; +2C79;LATIN SMALL LETTER TURNED R WITH TAIL;Ll;0;L;;;;;N;;;;; +2C7A;LATIN SMALL LETTER O WITH LOW RING INSIDE;Ll;0;L;;;;;N;;;;; +2C7B;LATIN LETTER SMALL CAPITAL TURNED E;Ll;0;L;;;;;N;;;;; +2C7C;LATIN SUBSCRIPT SMALL LETTER J;Ll;0;L;<sub> 006A;;;;N;;;;; +2C7D;MODIFIER LETTER CAPITAL V;Lm;0;L;<super> 0056;;;;N;;;;; +2C80;COPTIC CAPITAL LETTER ALFA;Lu;0;L;;;;;N;;;;2C81; +2C81;COPTIC SMALL LETTER ALFA;Ll;0;L;;;;;N;;;2C80;;2C80 +2C82;COPTIC CAPITAL LETTER VIDA;Lu;0;L;;;;;N;;;;2C83; +2C83;COPTIC SMALL LETTER VIDA;Ll;0;L;;;;;N;;;2C82;;2C82 +2C84;COPTIC CAPITAL LETTER GAMMA;Lu;0;L;;;;;N;;;;2C85; +2C85;COPTIC SMALL LETTER GAMMA;Ll;0;L;;;;;N;;;2C84;;2C84 +2C86;COPTIC CAPITAL LETTER DALDA;Lu;0;L;;;;;N;;;;2C87; +2C87;COPTIC SMALL LETTER DALDA;Ll;0;L;;;;;N;;;2C86;;2C86 +2C88;COPTIC CAPITAL LETTER EIE;Lu;0;L;;;;;N;;;;2C89; +2C89;COPTIC SMALL LETTER EIE;Ll;0;L;;;;;N;;;2C88;;2C88 +2C8A;COPTIC CAPITAL LETTER SOU;Lu;0;L;;;;;N;;;;2C8B; +2C8B;COPTIC SMALL LETTER SOU;Ll;0;L;;;;;N;;;2C8A;;2C8A +2C8C;COPTIC CAPITAL LETTER ZATA;Lu;0;L;;;;;N;;;;2C8D; +2C8D;COPTIC SMALL LETTER ZATA;Ll;0;L;;;;;N;;;2C8C;;2C8C +2C8E;COPTIC CAPITAL LETTER HATE;Lu;0;L;;;;;N;;;;2C8F; +2C8F;COPTIC SMALL LETTER HATE;Ll;0;L;;;;;N;;;2C8E;;2C8E +2C90;COPTIC CAPITAL LETTER THETHE;Lu;0;L;;;;;N;;;;2C91; +2C91;COPTIC SMALL LETTER THETHE;Ll;0;L;;;;;N;;;2C90;;2C90 +2C92;COPTIC CAPITAL LETTER IAUDA;Lu;0;L;;;;;N;;;;2C93; +2C93;COPTIC SMALL LETTER IAUDA;Ll;0;L;;;;;N;;;2C92;;2C92 +2C94;COPTIC CAPITAL LETTER KAPA;Lu;0;L;;;;;N;;;;2C95; +2C95;COPTIC SMALL LETTER KAPA;Ll;0;L;;;;;N;;;2C94;;2C94 +2C96;COPTIC CAPITAL LETTER LAULA;Lu;0;L;;;;;N;;;;2C97; +2C97;COPTIC SMALL LETTER LAULA;Ll;0;L;;;;;N;;;2C96;;2C96 +2C98;COPTIC CAPITAL LETTER MI;Lu;0;L;;;;;N;;;;2C99; +2C99;COPTIC SMALL LETTER MI;Ll;0;L;;;;;N;;;2C98;;2C98 +2C9A;COPTIC CAPITAL LETTER NI;Lu;0;L;;;;;N;;;;2C9B; +2C9B;COPTIC SMALL LETTER NI;Ll;0;L;;;;;N;;;2C9A;;2C9A +2C9C;COPTIC CAPITAL LETTER KSI;Lu;0;L;;;;;N;;;;2C9D; +2C9D;COPTIC SMALL LETTER KSI;Ll;0;L;;;;;N;;;2C9C;;2C9C +2C9E;COPTIC CAPITAL LETTER O;Lu;0;L;;;;;N;;;;2C9F; +2C9F;COPTIC SMALL LETTER O;Ll;0;L;;;;;N;;;2C9E;;2C9E +2CA0;COPTIC CAPITAL LETTER PI;Lu;0;L;;;;;N;;;;2CA1; +2CA1;COPTIC SMALL LETTER PI;Ll;0;L;;;;;N;;;2CA0;;2CA0 +2CA2;COPTIC CAPITAL LETTER RO;Lu;0;L;;;;;N;;;;2CA3; +2CA3;COPTIC SMALL LETTER RO;Ll;0;L;;;;;N;;;2CA2;;2CA2 +2CA4;COPTIC CAPITAL LETTER SIMA;Lu;0;L;;;;;N;;;;2CA5; +2CA5;COPTIC SMALL LETTER SIMA;Ll;0;L;;;;;N;;;2CA4;;2CA4 +2CA6;COPTIC CAPITAL LETTER TAU;Lu;0;L;;;;;N;;;;2CA7; +2CA7;COPTIC SMALL LETTER TAU;Ll;0;L;;;;;N;;;2CA6;;2CA6 +2CA8;COPTIC CAPITAL LETTER UA;Lu;0;L;;;;;N;;;;2CA9; +2CA9;COPTIC SMALL LETTER UA;Ll;0;L;;;;;N;;;2CA8;;2CA8 +2CAA;COPTIC CAPITAL LETTER FI;Lu;0;L;;;;;N;;;;2CAB; +2CAB;COPTIC SMALL LETTER FI;Ll;0;L;;;;;N;;;2CAA;;2CAA +2CAC;COPTIC CAPITAL LETTER KHI;Lu;0;L;;;;;N;;;;2CAD; +2CAD;COPTIC SMALL LETTER KHI;Ll;0;L;;;;;N;;;2CAC;;2CAC +2CAE;COPTIC CAPITAL LETTER PSI;Lu;0;L;;;;;N;;;;2CAF; +2CAF;COPTIC SMALL LETTER PSI;Ll;0;L;;;;;N;;;2CAE;;2CAE +2CB0;COPTIC CAPITAL LETTER OOU;Lu;0;L;;;;;N;;;;2CB1; +2CB1;COPTIC SMALL LETTER OOU;Ll;0;L;;;;;N;;;2CB0;;2CB0 +2CB2;COPTIC CAPITAL LETTER DIALECT-P ALEF;Lu;0;L;;;;;N;;;;2CB3; +2CB3;COPTIC SMALL LETTER DIALECT-P ALEF;Ll;0;L;;;;;N;;;2CB2;;2CB2 +2CB4;COPTIC CAPITAL LETTER OLD COPTIC AIN;Lu;0;L;;;;;N;;;;2CB5; +2CB5;COPTIC SMALL LETTER OLD COPTIC AIN;Ll;0;L;;;;;N;;;2CB4;;2CB4 +2CB6;COPTIC CAPITAL LETTER CRYPTOGRAMMIC EIE;Lu;0;L;;;;;N;;;;2CB7; +2CB7;COPTIC SMALL LETTER CRYPTOGRAMMIC EIE;Ll;0;L;;;;;N;;;2CB6;;2CB6 +2CB8;COPTIC CAPITAL LETTER DIALECT-P KAPA;Lu;0;L;;;;;N;;;;2CB9; +2CB9;COPTIC SMALL LETTER DIALECT-P KAPA;Ll;0;L;;;;;N;;;2CB8;;2CB8 +2CBA;COPTIC CAPITAL LETTER DIALECT-P NI;Lu;0;L;;;;;N;;;;2CBB; +2CBB;COPTIC SMALL LETTER DIALECT-P NI;Ll;0;L;;;;;N;;;2CBA;;2CBA +2CBC;COPTIC CAPITAL LETTER CRYPTOGRAMMIC NI;Lu;0;L;;;;;N;;;;2CBD; +2CBD;COPTIC SMALL LETTER CRYPTOGRAMMIC NI;Ll;0;L;;;;;N;;;2CBC;;2CBC +2CBE;COPTIC CAPITAL LETTER OLD COPTIC OOU;Lu;0;L;;;;;N;;;;2CBF; +2CBF;COPTIC SMALL LETTER OLD COPTIC OOU;Ll;0;L;;;;;N;;;2CBE;;2CBE +2CC0;COPTIC CAPITAL LETTER SAMPI;Lu;0;L;;;;;N;;;;2CC1; +2CC1;COPTIC SMALL LETTER SAMPI;Ll;0;L;;;;;N;;;2CC0;;2CC0 +2CC2;COPTIC CAPITAL LETTER CROSSED SHEI;Lu;0;L;;;;;N;;;;2CC3; +2CC3;COPTIC SMALL LETTER CROSSED SHEI;Ll;0;L;;;;;N;;;2CC2;;2CC2 +2CC4;COPTIC CAPITAL LETTER OLD COPTIC SHEI;Lu;0;L;;;;;N;;;;2CC5; +2CC5;COPTIC SMALL LETTER OLD COPTIC SHEI;Ll;0;L;;;;;N;;;2CC4;;2CC4 +2CC6;COPTIC CAPITAL LETTER OLD COPTIC ESH;Lu;0;L;;;;;N;;;;2CC7; +2CC7;COPTIC SMALL LETTER OLD COPTIC ESH;Ll;0;L;;;;;N;;;2CC6;;2CC6 +2CC8;COPTIC CAPITAL LETTER AKHMIMIC KHEI;Lu;0;L;;;;;N;;;;2CC9; +2CC9;COPTIC SMALL LETTER AKHMIMIC KHEI;Ll;0;L;;;;;N;;;2CC8;;2CC8 +2CCA;COPTIC CAPITAL LETTER DIALECT-P HORI;Lu;0;L;;;;;N;;;;2CCB; +2CCB;COPTIC SMALL LETTER DIALECT-P HORI;Ll;0;L;;;;;N;;;2CCA;;2CCA +2CCC;COPTIC CAPITAL LETTER OLD COPTIC HORI;Lu;0;L;;;;;N;;;;2CCD; +2CCD;COPTIC SMALL LETTER OLD COPTIC HORI;Ll;0;L;;;;;N;;;2CCC;;2CCC +2CCE;COPTIC CAPITAL LETTER OLD COPTIC HA;Lu;0;L;;;;;N;;;;2CCF; +2CCF;COPTIC SMALL LETTER OLD COPTIC HA;Ll;0;L;;;;;N;;;2CCE;;2CCE +2CD0;COPTIC CAPITAL LETTER L-SHAPED HA;Lu;0;L;;;;;N;;;;2CD1; +2CD1;COPTIC SMALL LETTER L-SHAPED HA;Ll;0;L;;;;;N;;;2CD0;;2CD0 +2CD2;COPTIC CAPITAL LETTER OLD COPTIC HEI;Lu;0;L;;;;;N;;;;2CD3; +2CD3;COPTIC SMALL LETTER OLD COPTIC HEI;Ll;0;L;;;;;N;;;2CD2;;2CD2 +2CD4;COPTIC CAPITAL LETTER OLD COPTIC HAT;Lu;0;L;;;;;N;;;;2CD5; +2CD5;COPTIC SMALL LETTER OLD COPTIC HAT;Ll;0;L;;;;;N;;;2CD4;;2CD4 +2CD6;COPTIC CAPITAL LETTER OLD COPTIC GANGIA;Lu;0;L;;;;;N;;;;2CD7; +2CD7;COPTIC SMALL LETTER OLD COPTIC GANGIA;Ll;0;L;;;;;N;;;2CD6;;2CD6 +2CD8;COPTIC CAPITAL LETTER OLD COPTIC DJA;Lu;0;L;;;;;N;;;;2CD9; +2CD9;COPTIC SMALL LETTER OLD COPTIC DJA;Ll;0;L;;;;;N;;;2CD8;;2CD8 +2CDA;COPTIC CAPITAL LETTER OLD COPTIC SHIMA;Lu;0;L;;;;;N;;;;2CDB; +2CDB;COPTIC SMALL LETTER OLD COPTIC SHIMA;Ll;0;L;;;;;N;;;2CDA;;2CDA +2CDC;COPTIC CAPITAL LETTER OLD NUBIAN SHIMA;Lu;0;L;;;;;N;;;;2CDD; +2CDD;COPTIC SMALL LETTER OLD NUBIAN SHIMA;Ll;0;L;;;;;N;;;2CDC;;2CDC +2CDE;COPTIC CAPITAL LETTER OLD NUBIAN NGI;Lu;0;L;;;;;N;;;;2CDF; +2CDF;COPTIC SMALL LETTER OLD NUBIAN NGI;Ll;0;L;;;;;N;;;2CDE;;2CDE +2CE0;COPTIC CAPITAL LETTER OLD NUBIAN NYI;Lu;0;L;;;;;N;;;;2CE1; +2CE1;COPTIC SMALL LETTER OLD NUBIAN NYI;Ll;0;L;;;;;N;;;2CE0;;2CE0 +2CE2;COPTIC CAPITAL LETTER OLD NUBIAN WAU;Lu;0;L;;;;;N;;;;2CE3; +2CE3;COPTIC SMALL LETTER OLD NUBIAN WAU;Ll;0;L;;;;;N;;;2CE2;;2CE2 +2CE4;COPTIC SYMBOL KAI;Ll;0;L;;;;;N;;;;; +2CE5;COPTIC SYMBOL MI RO;So;0;ON;;;;;N;;;;; +2CE6;COPTIC SYMBOL PI RO;So;0;ON;;;;;N;;;;; +2CE7;COPTIC SYMBOL STAUROS;So;0;ON;;;;;N;;;;; +2CE8;COPTIC SYMBOL TAU RO;So;0;ON;;;;;N;;;;; +2CE9;COPTIC SYMBOL KHI RO;So;0;ON;;;;;N;;;;; +2CEA;COPTIC SYMBOL SHIMA SIMA;So;0;ON;;;;;N;;;;; +2CF9;COPTIC OLD NUBIAN FULL STOP;Po;0;ON;;;;;N;;;;; +2CFA;COPTIC OLD NUBIAN DIRECT QUESTION MARK;Po;0;ON;;;;;N;;;;; +2CFB;COPTIC OLD NUBIAN INDIRECT QUESTION MARK;Po;0;ON;;;;;N;;;;; +2CFC;COPTIC OLD NUBIAN VERSE DIVIDER;Po;0;ON;;;;;N;;;;; +2CFD;COPTIC FRACTION ONE HALF;No;0;ON;;;;1/2;N;;;;; +2CFE;COPTIC FULL STOP;Po;0;ON;;;;;N;;;;; +2CFF;COPTIC MORPHOLOGICAL DIVIDER;Po;0;ON;;;;;N;;;;; +2D00;GEORGIAN SMALL LETTER AN;Ll;0;L;;;;;N;;Khutsuri;10A0;;10A0 +2D01;GEORGIAN SMALL LETTER BAN;Ll;0;L;;;;;N;;Khutsuri;10A1;;10A1 +2D02;GEORGIAN SMALL LETTER GAN;Ll;0;L;;;;;N;;Khutsuri;10A2;;10A2 +2D03;GEORGIAN SMALL LETTER DON;Ll;0;L;;;;;N;;Khutsuri;10A3;;10A3 +2D04;GEORGIAN SMALL LETTER EN;Ll;0;L;;;;;N;;Khutsuri;10A4;;10A4 +2D05;GEORGIAN SMALL LETTER VIN;Ll;0;L;;;;;N;;Khutsuri;10A5;;10A5 +2D06;GEORGIAN SMALL LETTER ZEN;Ll;0;L;;;;;N;;Khutsuri;10A6;;10A6 +2D07;GEORGIAN SMALL LETTER TAN;Ll;0;L;;;;;N;;Khutsuri;10A7;;10A7 +2D08;GEORGIAN SMALL LETTER IN;Ll;0;L;;;;;N;;Khutsuri;10A8;;10A8 +2D09;GEORGIAN SMALL LETTER KAN;Ll;0;L;;;;;N;;Khutsuri;10A9;;10A9 +2D0A;GEORGIAN SMALL LETTER LAS;Ll;0;L;;;;;N;;Khutsuri;10AA;;10AA +2D0B;GEORGIAN SMALL LETTER MAN;Ll;0;L;;;;;N;;Khutsuri;10AB;;10AB +2D0C;GEORGIAN SMALL LETTER NAR;Ll;0;L;;;;;N;;Khutsuri;10AC;;10AC +2D0D;GEORGIAN SMALL LETTER ON;Ll;0;L;;;;;N;;Khutsuri;10AD;;10AD +2D0E;GEORGIAN SMALL LETTER PAR;Ll;0;L;;;;;N;;Khutsuri;10AE;;10AE +2D0F;GEORGIAN SMALL LETTER ZHAR;Ll;0;L;;;;;N;;Khutsuri;10AF;;10AF +2D10;GEORGIAN SMALL LETTER RAE;Ll;0;L;;;;;N;;Khutsuri;10B0;;10B0 +2D11;GEORGIAN SMALL LETTER SAN;Ll;0;L;;;;;N;;Khutsuri;10B1;;10B1 +2D12;GEORGIAN SMALL LETTER TAR;Ll;0;L;;;;;N;;Khutsuri;10B2;;10B2 +2D13;GEORGIAN SMALL LETTER UN;Ll;0;L;;;;;N;;Khutsuri;10B3;;10B3 +2D14;GEORGIAN SMALL LETTER PHAR;Ll;0;L;;;;;N;;Khutsuri;10B4;;10B4 +2D15;GEORGIAN SMALL LETTER KHAR;Ll;0;L;;;;;N;;Khutsuri;10B5;;10B5 +2D16;GEORGIAN SMALL LETTER GHAN;Ll;0;L;;;;;N;;Khutsuri;10B6;;10B6 +2D17;GEORGIAN SMALL LETTER QAR;Ll;0;L;;;;;N;;Khutsuri;10B7;;10B7 +2D18;GEORGIAN SMALL LETTER SHIN;Ll;0;L;;;;;N;;Khutsuri;10B8;;10B8 +2D19;GEORGIAN SMALL LETTER CHIN;Ll;0;L;;;;;N;;Khutsuri;10B9;;10B9 +2D1A;GEORGIAN SMALL LETTER CAN;Ll;0;L;;;;;N;;Khutsuri;10BA;;10BA +2D1B;GEORGIAN SMALL LETTER JIL;Ll;0;L;;;;;N;;Khutsuri;10BB;;10BB +2D1C;GEORGIAN SMALL LETTER CIL;Ll;0;L;;;;;N;;Khutsuri;10BC;;10BC +2D1D;GEORGIAN SMALL LETTER CHAR;Ll;0;L;;;;;N;;Khutsuri;10BD;;10BD +2D1E;GEORGIAN SMALL LETTER XAN;Ll;0;L;;;;;N;;Khutsuri;10BE;;10BE +2D1F;GEORGIAN SMALL LETTER JHAN;Ll;0;L;;;;;N;;Khutsuri;10BF;;10BF +2D20;GEORGIAN SMALL LETTER HAE;Ll;0;L;;;;;N;;Khutsuri;10C0;;10C0 +2D21;GEORGIAN SMALL LETTER HE;Ll;0;L;;;;;N;;Khutsuri;10C1;;10C1 +2D22;GEORGIAN SMALL LETTER HIE;Ll;0;L;;;;;N;;Khutsuri;10C2;;10C2 +2D23;GEORGIAN SMALL LETTER WE;Ll;0;L;;;;;N;;Khutsuri;10C3;;10C3 +2D24;GEORGIAN SMALL LETTER HAR;Ll;0;L;;;;;N;;Khutsuri;10C4;;10C4 +2D25;GEORGIAN SMALL LETTER HOE;Ll;0;L;;;;;N;;Khutsuri;10C5;;10C5 +2D30;TIFINAGH LETTER YA;Lo;0;L;;;;;N;;;;; +2D31;TIFINAGH LETTER YAB;Lo;0;L;;;;;N;;;;; +2D32;TIFINAGH LETTER YABH;Lo;0;L;;;;;N;;;;; +2D33;TIFINAGH LETTER YAG;Lo;0;L;;;;;N;;;;; +2D34;TIFINAGH LETTER YAGHH;Lo;0;L;;;;;N;;;;; +2D35;TIFINAGH LETTER BERBER ACADEMY YAJ;Lo;0;L;;;;;N;;;;; +2D36;TIFINAGH LETTER YAJ;Lo;0;L;;;;;N;;;;; +2D37;TIFINAGH LETTER YAD;Lo;0;L;;;;;N;;;;; +2D38;TIFINAGH LETTER YADH;Lo;0;L;;;;;N;;;;; +2D39;TIFINAGH LETTER YADD;Lo;0;L;;;;;N;;;;; +2D3A;TIFINAGH LETTER YADDH;Lo;0;L;;;;;N;;;;; +2D3B;TIFINAGH LETTER YEY;Lo;0;L;;;;;N;;;;; +2D3C;TIFINAGH LETTER YAF;Lo;0;L;;;;;N;;;;; +2D3D;TIFINAGH LETTER YAK;Lo;0;L;;;;;N;;;;; +2D3E;TIFINAGH LETTER TUAREG YAK;Lo;0;L;;;;;N;;;;; +2D3F;TIFINAGH LETTER YAKHH;Lo;0;L;;;;;N;;;;; +2D40;TIFINAGH LETTER YAH;Lo;0;L;;;;;N;;Tuareg yab;;; +2D41;TIFINAGH LETTER BERBER ACADEMY YAH;Lo;0;L;;;;;N;;;;; +2D42;TIFINAGH LETTER TUAREG YAH;Lo;0;L;;;;;N;;;;; +2D43;TIFINAGH LETTER YAHH;Lo;0;L;;;;;N;;;;; +2D44;TIFINAGH LETTER YAA;Lo;0;L;;;;;N;;;;; +2D45;TIFINAGH LETTER YAKH;Lo;0;L;;;;;N;;;;; +2D46;TIFINAGH LETTER TUAREG YAKH;Lo;0;L;;;;;N;;;;; +2D47;TIFINAGH LETTER YAQ;Lo;0;L;;;;;N;;;;; +2D48;TIFINAGH LETTER TUAREG YAQ;Lo;0;L;;;;;N;;;;; +2D49;TIFINAGH LETTER YI;Lo;0;L;;;;;N;;;;; +2D4A;TIFINAGH LETTER YAZH;Lo;0;L;;;;;N;;;;; +2D4B;TIFINAGH LETTER AHAGGAR YAZH;Lo;0;L;;;;;N;;;;; +2D4C;TIFINAGH LETTER TUAREG YAZH;Lo;0;L;;;;;N;;;;; +2D4D;TIFINAGH LETTER YAL;Lo;0;L;;;;;N;;;;; +2D4E;TIFINAGH LETTER YAM;Lo;0;L;;;;;N;;;;; +2D4F;TIFINAGH LETTER YAN;Lo;0;L;;;;;N;;;;; +2D50;TIFINAGH LETTER TUAREG YAGN;Lo;0;L;;;;;N;;;;; +2D51;TIFINAGH LETTER TUAREG YANG;Lo;0;L;;;;;N;;;;; +2D52;TIFINAGH LETTER YAP;Lo;0;L;;;;;N;;;;; +2D53;TIFINAGH LETTER YU;Lo;0;L;;;;;N;;Tuareg yaw;;; +2D54;TIFINAGH LETTER YAR;Lo;0;L;;;;;N;;;;; +2D55;TIFINAGH LETTER YARR;Lo;0;L;;;;;N;;;;; +2D56;TIFINAGH LETTER YAGH;Lo;0;L;;;;;N;;;;; +2D57;TIFINAGH LETTER TUAREG YAGH;Lo;0;L;;;;;N;;;;; +2D58;TIFINAGH LETTER AYER YAGH;Lo;0;L;;;;;N;;Adrar yaj;;; +2D59;TIFINAGH LETTER YAS;Lo;0;L;;;;;N;;;;; +2D5A;TIFINAGH LETTER YASS;Lo;0;L;;;;;N;;;;; +2D5B;TIFINAGH LETTER YASH;Lo;0;L;;;;;N;;;;; +2D5C;TIFINAGH LETTER YAT;Lo;0;L;;;;;N;;;;; +2D5D;TIFINAGH LETTER YATH;Lo;0;L;;;;;N;;;;; +2D5E;TIFINAGH LETTER YACH;Lo;0;L;;;;;N;;;;; +2D5F;TIFINAGH LETTER YATT;Lo;0;L;;;;;N;;;;; +2D60;TIFINAGH LETTER YAV;Lo;0;L;;;;;N;;;;; +2D61;TIFINAGH LETTER YAW;Lo;0;L;;;;;N;;;;; +2D62;TIFINAGH LETTER YAY;Lo;0;L;;;;;N;;;;; +2D63;TIFINAGH LETTER YAZ;Lo;0;L;;;;;N;;;;; +2D64;TIFINAGH LETTER TAWELLEMET YAZ;Lo;0;L;;;;;N;;harpoon yaz;;; +2D65;TIFINAGH LETTER YAZZ;Lo;0;L;;;;;N;;;;; +2D6F;TIFINAGH MODIFIER LETTER LABIALIZATION MARK;Lm;0;L;<super> 2D61;;;;N;;tamatart;;; +2D80;ETHIOPIC SYLLABLE LOA;Lo;0;L;;;;;N;;;;; +2D81;ETHIOPIC SYLLABLE MOA;Lo;0;L;;;;;N;;;;; +2D82;ETHIOPIC SYLLABLE ROA;Lo;0;L;;;;;N;;;;; +2D83;ETHIOPIC SYLLABLE SOA;Lo;0;L;;;;;N;;;;; +2D84;ETHIOPIC SYLLABLE SHOA;Lo;0;L;;;;;N;;;;; +2D85;ETHIOPIC SYLLABLE BOA;Lo;0;L;;;;;N;;;;; +2D86;ETHIOPIC SYLLABLE TOA;Lo;0;L;;;;;N;;;;; +2D87;ETHIOPIC SYLLABLE COA;Lo;0;L;;;;;N;;;;; +2D88;ETHIOPIC SYLLABLE NOA;Lo;0;L;;;;;N;;;;; +2D89;ETHIOPIC SYLLABLE NYOA;Lo;0;L;;;;;N;;;;; +2D8A;ETHIOPIC SYLLABLE GLOTTAL OA;Lo;0;L;;;;;N;;;;; +2D8B;ETHIOPIC SYLLABLE ZOA;Lo;0;L;;;;;N;;;;; +2D8C;ETHIOPIC SYLLABLE DOA;Lo;0;L;;;;;N;;;;; +2D8D;ETHIOPIC SYLLABLE DDOA;Lo;0;L;;;;;N;;;;; +2D8E;ETHIOPIC SYLLABLE JOA;Lo;0;L;;;;;N;;;;; +2D8F;ETHIOPIC SYLLABLE THOA;Lo;0;L;;;;;N;;;;; +2D90;ETHIOPIC SYLLABLE CHOA;Lo;0;L;;;;;N;;;;; +2D91;ETHIOPIC SYLLABLE PHOA;Lo;0;L;;;;;N;;;;; +2D92;ETHIOPIC SYLLABLE POA;Lo;0;L;;;;;N;;;;; +2D93;ETHIOPIC SYLLABLE GGWA;Lo;0;L;;;;;N;;;;; +2D94;ETHIOPIC SYLLABLE GGWI;Lo;0;L;;;;;N;;;;; +2D95;ETHIOPIC SYLLABLE GGWEE;Lo;0;L;;;;;N;;;;; +2D96;ETHIOPIC SYLLABLE GGWE;Lo;0;L;;;;;N;;;;; +2DA0;ETHIOPIC SYLLABLE SSA;Lo;0;L;;;;;N;;;;; +2DA1;ETHIOPIC SYLLABLE SSU;Lo;0;L;;;;;N;;;;; +2DA2;ETHIOPIC SYLLABLE SSI;Lo;0;L;;;;;N;;;;; +2DA3;ETHIOPIC SYLLABLE SSAA;Lo;0;L;;;;;N;;;;; +2DA4;ETHIOPIC SYLLABLE SSEE;Lo;0;L;;;;;N;;;;; +2DA5;ETHIOPIC SYLLABLE SSE;Lo;0;L;;;;;N;;;;; +2DA6;ETHIOPIC SYLLABLE SSO;Lo;0;L;;;;;N;;;;; +2DA8;ETHIOPIC SYLLABLE CCA;Lo;0;L;;;;;N;;;;; +2DA9;ETHIOPIC SYLLABLE CCU;Lo;0;L;;;;;N;;;;; +2DAA;ETHIOPIC SYLLABLE CCI;Lo;0;L;;;;;N;;;;; +2DAB;ETHIOPIC SYLLABLE CCAA;Lo;0;L;;;;;N;;;;; +2DAC;ETHIOPIC SYLLABLE CCEE;Lo;0;L;;;;;N;;;;; +2DAD;ETHIOPIC SYLLABLE CCE;Lo;0;L;;;;;N;;;;; +2DAE;ETHIOPIC SYLLABLE CCO;Lo;0;L;;;;;N;;;;; +2DB0;ETHIOPIC SYLLABLE ZZA;Lo;0;L;;;;;N;;;;; +2DB1;ETHIOPIC SYLLABLE ZZU;Lo;0;L;;;;;N;;;;; +2DB2;ETHIOPIC SYLLABLE ZZI;Lo;0;L;;;;;N;;;;; +2DB3;ETHIOPIC SYLLABLE ZZAA;Lo;0;L;;;;;N;;;;; +2DB4;ETHIOPIC SYLLABLE ZZEE;Lo;0;L;;;;;N;;;;; +2DB5;ETHIOPIC SYLLABLE ZZE;Lo;0;L;;;;;N;;;;; +2DB6;ETHIOPIC SYLLABLE ZZO;Lo;0;L;;;;;N;;;;; +2DB8;ETHIOPIC SYLLABLE CCHA;Lo;0;L;;;;;N;;;;; +2DB9;ETHIOPIC SYLLABLE CCHU;Lo;0;L;;;;;N;;;;; +2DBA;ETHIOPIC SYLLABLE CCHI;Lo;0;L;;;;;N;;;;; +2DBB;ETHIOPIC SYLLABLE CCHAA;Lo;0;L;;;;;N;;;;; +2DBC;ETHIOPIC SYLLABLE CCHEE;Lo;0;L;;;;;N;;;;; +2DBD;ETHIOPIC SYLLABLE CCHE;Lo;0;L;;;;;N;;;;; +2DBE;ETHIOPIC SYLLABLE CCHO;Lo;0;L;;;;;N;;;;; +2DC0;ETHIOPIC SYLLABLE QYA;Lo;0;L;;;;;N;;;;; +2DC1;ETHIOPIC SYLLABLE QYU;Lo;0;L;;;;;N;;;;; +2DC2;ETHIOPIC SYLLABLE QYI;Lo;0;L;;;;;N;;;;; +2DC3;ETHIOPIC SYLLABLE QYAA;Lo;0;L;;;;;N;;;;; +2DC4;ETHIOPIC SYLLABLE QYEE;Lo;0;L;;;;;N;;;;; +2DC5;ETHIOPIC SYLLABLE QYE;Lo;0;L;;;;;N;;;;; +2DC6;ETHIOPIC SYLLABLE QYO;Lo;0;L;;;;;N;;;;; +2DC8;ETHIOPIC SYLLABLE KYA;Lo;0;L;;;;;N;;;;; +2DC9;ETHIOPIC SYLLABLE KYU;Lo;0;L;;;;;N;;;;; +2DCA;ETHIOPIC SYLLABLE KYI;Lo;0;L;;;;;N;;;;; +2DCB;ETHIOPIC SYLLABLE KYAA;Lo;0;L;;;;;N;;;;; +2DCC;ETHIOPIC SYLLABLE KYEE;Lo;0;L;;;;;N;;;;; +2DCD;ETHIOPIC SYLLABLE KYE;Lo;0;L;;;;;N;;;;; +2DCE;ETHIOPIC SYLLABLE KYO;Lo;0;L;;;;;N;;;;; +2DD0;ETHIOPIC SYLLABLE XYA;Lo;0;L;;;;;N;;;;; +2DD1;ETHIOPIC SYLLABLE XYU;Lo;0;L;;;;;N;;;;; +2DD2;ETHIOPIC SYLLABLE XYI;Lo;0;L;;;;;N;;;;; +2DD3;ETHIOPIC SYLLABLE XYAA;Lo;0;L;;;;;N;;;;; +2DD4;ETHIOPIC SYLLABLE XYEE;Lo;0;L;;;;;N;;;;; +2DD5;ETHIOPIC SYLLABLE XYE;Lo;0;L;;;;;N;;;;; +2DD6;ETHIOPIC SYLLABLE XYO;Lo;0;L;;;;;N;;;;; +2DD8;ETHIOPIC SYLLABLE GYA;Lo;0;L;;;;;N;;;;; +2DD9;ETHIOPIC SYLLABLE GYU;Lo;0;L;;;;;N;;;;; +2DDA;ETHIOPIC SYLLABLE GYI;Lo;0;L;;;;;N;;;;; +2DDB;ETHIOPIC SYLLABLE GYAA;Lo;0;L;;;;;N;;;;; +2DDC;ETHIOPIC SYLLABLE GYEE;Lo;0;L;;;;;N;;;;; +2DDD;ETHIOPIC SYLLABLE GYE;Lo;0;L;;;;;N;;;;; +2DDE;ETHIOPIC SYLLABLE GYO;Lo;0;L;;;;;N;;;;; +2DE0;COMBINING CYRILLIC LETTER BE;Mn;230;NSM;;;;;N;;;;; +2DE1;COMBINING CYRILLIC LETTER VE;Mn;230;NSM;;;;;N;;;;; +2DE2;COMBINING CYRILLIC LETTER GHE;Mn;230;NSM;;;;;N;;;;; +2DE3;COMBINING CYRILLIC LETTER DE;Mn;230;NSM;;;;;N;;;;; +2DE4;COMBINING CYRILLIC LETTER ZHE;Mn;230;NSM;;;;;N;;;;; +2DE5;COMBINING CYRILLIC LETTER ZE;Mn;230;NSM;;;;;N;;;;; +2DE6;COMBINING CYRILLIC LETTER KA;Mn;230;NSM;;;;;N;;;;; +2DE7;COMBINING CYRILLIC LETTER EL;Mn;230;NSM;;;;;N;;;;; +2DE8;COMBINING CYRILLIC LETTER EM;Mn;230;NSM;;;;;N;;;;; +2DE9;COMBINING CYRILLIC LETTER EN;Mn;230;NSM;;;;;N;;;;; +2DEA;COMBINING CYRILLIC LETTER O;Mn;230;NSM;;;;;N;;;;; +2DEB;COMBINING CYRILLIC LETTER PE;Mn;230;NSM;;;;;N;;;;; +2DEC;COMBINING CYRILLIC LETTER ER;Mn;230;NSM;;;;;N;;;;; +2DED;COMBINING CYRILLIC LETTER ES;Mn;230;NSM;;;;;N;;;;; +2DEE;COMBINING CYRILLIC LETTER TE;Mn;230;NSM;;;;;N;;;;; +2DEF;COMBINING CYRILLIC LETTER HA;Mn;230;NSM;;;;;N;;;;; +2DF0;COMBINING CYRILLIC LETTER TSE;Mn;230;NSM;;;;;N;;;;; +2DF1;COMBINING CYRILLIC LETTER CHE;Mn;230;NSM;;;;;N;;;;; +2DF2;COMBINING CYRILLIC LETTER SHA;Mn;230;NSM;;;;;N;;;;; +2DF3;COMBINING CYRILLIC LETTER SHCHA;Mn;230;NSM;;;;;N;;;;; +2DF4;COMBINING CYRILLIC LETTER FITA;Mn;230;NSM;;;;;N;;;;; +2DF5;COMBINING CYRILLIC LETTER ES-TE;Mn;230;NSM;;;;;N;;;;; +2DF6;COMBINING CYRILLIC LETTER A;Mn;230;NSM;;;;;N;;;;; +2DF7;COMBINING CYRILLIC LETTER IE;Mn;230;NSM;;;;;N;;;;; +2DF8;COMBINING CYRILLIC LETTER DJERV;Mn;230;NSM;;;;;N;;;;; +2DF9;COMBINING CYRILLIC LETTER MONOGRAPH UK;Mn;230;NSM;;;;;N;;;;; +2DFA;COMBINING CYRILLIC LETTER YAT;Mn;230;NSM;;;;;N;;;;; +2DFB;COMBINING CYRILLIC LETTER YU;Mn;230;NSM;;;;;N;;;;; +2DFC;COMBINING CYRILLIC LETTER IOTIFIED A;Mn;230;NSM;;;;;N;;;;; +2DFD;COMBINING CYRILLIC LETTER LITTLE YUS;Mn;230;NSM;;;;;N;;;;; +2DFE;COMBINING CYRILLIC LETTER BIG YUS;Mn;230;NSM;;;;;N;;;;; +2DFF;COMBINING CYRILLIC LETTER IOTIFIED BIG YUS;Mn;230;NSM;;;;;N;;;;; +2E00;RIGHT ANGLE SUBSTITUTION MARKER;Po;0;ON;;;;;N;;;;; +2E01;RIGHT ANGLE DOTTED SUBSTITUTION MARKER;Po;0;ON;;;;;N;;;;; +2E02;LEFT SUBSTITUTION BRACKET;Pi;0;ON;;;;;Y;;;;; +2E03;RIGHT SUBSTITUTION BRACKET;Pf;0;ON;;;;;Y;;;;; +2E04;LEFT DOTTED SUBSTITUTION BRACKET;Pi;0;ON;;;;;Y;;;;; +2E05;RIGHT DOTTED SUBSTITUTION BRACKET;Pf;0;ON;;;;;Y;;;;; +2E06;RAISED INTERPOLATION MARKER;Po;0;ON;;;;;N;;;;; +2E07;RAISED DOTTED INTERPOLATION MARKER;Po;0;ON;;;;;N;;;;; +2E08;DOTTED TRANSPOSITION MARKER;Po;0;ON;;;;;N;;;;; +2E09;LEFT TRANSPOSITION BRACKET;Pi;0;ON;;;;;Y;;;;; +2E0A;RIGHT TRANSPOSITION BRACKET;Pf;0;ON;;;;;Y;;;;; +2E0B;RAISED SQUARE;Po;0;ON;;;;;N;;;;; +2E0C;LEFT RAISED OMISSION BRACKET;Pi;0;ON;;;;;Y;;;;; +2E0D;RIGHT RAISED OMISSION BRACKET;Pf;0;ON;;;;;Y;;;;; +2E0E;EDITORIAL CORONIS;Po;0;ON;;;;;N;;;;; +2E0F;PARAGRAPHOS;Po;0;ON;;;;;N;;;;; +2E10;FORKED PARAGRAPHOS;Po;0;ON;;;;;N;;;;; +2E11;REVERSED FORKED PARAGRAPHOS;Po;0;ON;;;;;N;;;;; +2E12;HYPODIASTOLE;Po;0;ON;;;;;N;;;;; +2E13;DOTTED OBELOS;Po;0;ON;;;;;N;;;;; +2E14;DOWNWARDS ANCORA;Po;0;ON;;;;;N;;;;; +2E15;UPWARDS ANCORA;Po;0;ON;;;;;N;;;;; +2E16;DOTTED RIGHT-POINTING ANGLE;Po;0;ON;;;;;N;;;;; +2E17;DOUBLE OBLIQUE HYPHEN;Pd;0;ON;;;;;N;;;;; +2E18;INVERTED INTERROBANG;Po;0;ON;;;;;N;;;;; +2E19;PALM BRANCH;Po;0;ON;;;;;N;;;;; +2E1A;HYPHEN WITH DIAERESIS;Pd;0;ON;;;;;N;;;;; +2E1B;TILDE WITH RING ABOVE;Po;0;ON;;;;;N;;;;; +2E1C;LEFT LOW PARAPHRASE BRACKET;Pi;0;ON;;;;;Y;;;;; +2E1D;RIGHT LOW PARAPHRASE BRACKET;Pf;0;ON;;;;;Y;;;;; +2E1E;TILDE WITH DOT ABOVE;Po;0;ON;;;;;N;;;;; +2E1F;TILDE WITH DOT BELOW;Po;0;ON;;;;;N;;;;; +2E20;LEFT VERTICAL BAR WITH QUILL;Pi;0;ON;;;;;Y;;;;; +2E21;RIGHT VERTICAL BAR WITH QUILL;Pf;0;ON;;;;;Y;;;;; +2E22;TOP LEFT HALF BRACKET;Ps;0;ON;;;;;Y;;;;; +2E23;TOP RIGHT HALF BRACKET;Pe;0;ON;;;;;Y;;;;; +2E24;BOTTOM LEFT HALF BRACKET;Ps;0;ON;;;;;Y;;;;; +2E25;BOTTOM RIGHT HALF BRACKET;Pe;0;ON;;;;;Y;;;;; +2E26;LEFT SIDEWAYS U BRACKET;Ps;0;ON;;;;;Y;;;;; +2E27;RIGHT SIDEWAYS U BRACKET;Pe;0;ON;;;;;Y;;;;; +2E28;LEFT DOUBLE PARENTHESIS;Ps;0;ON;;;;;Y;;;;; +2E29;RIGHT DOUBLE PARENTHESIS;Pe;0;ON;;;;;Y;;;;; +2E2A;TWO DOTS OVER ONE DOT PUNCTUATION;Po;0;ON;;;;;N;;;;; +2E2B;ONE DOT OVER TWO DOTS PUNCTUATION;Po;0;ON;;;;;N;;;;; +2E2C;SQUARED FOUR DOT PUNCTUATION;Po;0;ON;;;;;N;;;;; +2E2D;FIVE DOT MARK;Po;0;ON;;;;;N;;;;; +2E2E;REVERSED QUESTION MARK;Po;0;ON;;;;;N;;;;; +2E2F;VERTICAL TILDE;Lm;0;ON;;;;;N;;;;; +2E30;RING POINT;Po;0;ON;;;;;N;;;;; 2E80;CJK RADICAL REPEAT;So;0;ON;;;;;N;;;;; 2E81;CJK RADICAL CLIFF;So;0;ON;;;;;N;;;;; 2E82;CJK RADICAL SECOND ONE;So;0;ON;;;;;N;;;;; @@ -8632,7 +10239,7 @@ 30F8;KATAKANA LETTER VI;Lo;0;L;30F0 3099;;;;N;;;;; 30F9;KATAKANA LETTER VE;Lo;0;L;30F1 3099;;;;N;;;;; 30FA;KATAKANA LETTER VO;Lo;0;L;30F2 3099;;;;N;;;;; -30FB;KATAKANA MIDDLE DOT;Pc;0;ON;;;;;N;;;;; +30FB;KATAKANA MIDDLE DOT;Po;0;ON;;;;;N;;;;; 30FC;KATAKANA-HIRAGANA PROLONGED SOUND MARK;Lm;0;L;;;;;N;;;;; 30FD;KATAKANA ITERATION MARK;Lm;0;L;;;;;N;;;;; 30FE;KATAKANA VOICED ITERATION MARK;Lm;0;L;30FD 3099;;;;N;;;;; @@ -8677,6 +10284,7 @@ 312A;BOPOMOFO LETTER V;Lo;0;L;;;;;N;;;;; 312B;BOPOMOFO LETTER NG;Lo;0;L;;;;;N;;;;; 312C;BOPOMOFO LETTER GN;Lo;0;L;;;;;N;;;;; +312D;BOPOMOFO LETTER IH;Lo;0;L;;;;;N;;;;; 3131;HANGUL LETTER KIYEOK;Lo;0;L;<compat> 1100;;;;N;HANGUL LETTER GIYEOG;;;; 3132;HANGUL LETTER SSANGKIYEOK;Lo;0;L;<compat> 1101;;;;N;HANGUL LETTER SSANG GIYEOG;;;; 3133;HANGUL LETTER KIYEOK-SIOS;Lo;0;L;<compat> 11AA;;;;N;HANGUL LETTER GIYEOG SIOS;;;; @@ -8811,6 +10419,42 @@ 31B5;BOPOMOFO FINAL LETTER T;Lo;0;L;;;;;N;;;;; 31B6;BOPOMOFO FINAL LETTER K;Lo;0;L;;;;;N;;;;; 31B7;BOPOMOFO FINAL LETTER H;Lo;0;L;;;;;N;;;;; +31C0;CJK STROKE T;So;0;ON;;;;;N;;;;; +31C1;CJK STROKE WG;So;0;ON;;;;;N;;;;; +31C2;CJK STROKE XG;So;0;ON;;;;;N;;;;; +31C3;CJK STROKE BXG;So;0;ON;;;;;N;;;;; +31C4;CJK STROKE SW;So;0;ON;;;;;N;;;;; +31C5;CJK STROKE HZZ;So;0;ON;;;;;N;;;;; +31C6;CJK STROKE HZG;So;0;ON;;;;;N;;;;; +31C7;CJK STROKE HP;So;0;ON;;;;;N;;;;; +31C8;CJK STROKE HZWG;So;0;ON;;;;;N;;;;; +31C9;CJK STROKE SZWG;So;0;ON;;;;;N;;;;; +31CA;CJK STROKE HZT;So;0;ON;;;;;N;;;;; +31CB;CJK STROKE HZZP;So;0;ON;;;;;N;;;;; +31CC;CJK STROKE HPWG;So;0;ON;;;;;N;;;;; +31CD;CJK STROKE HZW;So;0;ON;;;;;N;;;;; +31CE;CJK STROKE HZZZ;So;0;ON;;;;;N;;;;; +31CF;CJK STROKE N;So;0;ON;;;;;N;;;;; +31D0;CJK STROKE H;So;0;ON;;;;;N;;;;; +31D1;CJK STROKE S;So;0;ON;;;;;N;;;;; +31D2;CJK STROKE P;So;0;ON;;;;;N;;;;; +31D3;CJK STROKE SP;So;0;ON;;;;;N;;;;; +31D4;CJK STROKE D;So;0;ON;;;;;N;;;;; +31D5;CJK STROKE HZ;So;0;ON;;;;;N;;;;; +31D6;CJK STROKE HG;So;0;ON;;;;;N;;;;; +31D7;CJK STROKE SZ;So;0;ON;;;;;N;;;;; +31D8;CJK STROKE SWZ;So;0;ON;;;;;N;;;;; +31D9;CJK STROKE ST;So;0;ON;;;;;N;;;;; +31DA;CJK STROKE SG;So;0;ON;;;;;N;;;;; +31DB;CJK STROKE PD;So;0;ON;;;;;N;;;;; +31DC;CJK STROKE PZ;So;0;ON;;;;;N;;;;; +31DD;CJK STROKE TN;So;0;ON;;;;;N;;;;; +31DE;CJK STROKE SZZ;So;0;ON;;;;;N;;;;; +31DF;CJK STROKE SWG;So;0;ON;;;;;N;;;;; +31E0;CJK STROKE HXWG;So;0;ON;;;;;N;;;;; +31E1;CJK STROKE HZZZG;So;0;ON;;;;;N;;;;; +31E2;CJK STROKE PG;So;0;ON;;;;;N;;;;; +31E3;CJK STROKE Q;So;0;ON;;;;;N;;;;; 31F0;KATAKANA LETTER SMALL KU;Lo;0;L;;;;;N;;;;; 31F1;KATAKANA LETTER SMALL SI;Lo;0;L;;;;;N;;;;; 31F2;KATAKANA LETTER SMALL SU;Lo;0;L;;;;;N;;;;; @@ -8940,6 +10584,7 @@ 327B;CIRCLED HANGUL HIEUH A;So;0;L;<circle> 1112 1161;;;;N;CIRCLED HANGUL HA;;;; 327C;CIRCLED KOREAN CHARACTER CHAMKO;So;0;ON;<circle> 110E 1161 11B7 1100 1169;;;;N;;;;; 327D;CIRCLED KOREAN CHARACTER JUEUI;So;0;ON;<circle> 110C 116E 110B 1174;;;;N;;;;; +327E;CIRCLED HANGUL IEUNG U;So;0;ON;<circle> 110B 116E;;;;N;;;;; 327F;KOREAN STANDARD SYMBOL;So;0;L;;;;;N;;;;; 3280;CIRCLED IDEOGRAPH ONE;No;0;L;<circle> 4E00;;;1;N;;;;; 3281;CIRCLED IDEOGRAPH TWO;No;0;L;<circle> 4E8C;;;2;N;;;;; @@ -9391,7 +11036,7 @@ 4DFE;HEXAGRAM FOR AFTER COMPLETION;So;0;ON;;;;;N;;;;; 4DFF;HEXAGRAM FOR BEFORE COMPLETION;So;0;ON;;;;;N;;;;; 4E00;<CJK Ideograph, First>;Lo;0;L;;;;;N;;;;; -9FA5;<CJK Ideograph, Last>;Lo;0;L;;;;;N;;;;; +9FC3;<CJK Ideograph, Last>;Lo;0;L;;;;;N;;;;; A000;YI SYLLABLE IT;Lo;0;L;;;;;N;;;;; A001;YI SYLLABLE IX;Lo;0;L;;;;;N;;;;; A002;YI SYLLABLE I;Lo;0;L;;;;;N;;;;; @@ -9413,7 +11058,7 @@ A011;YI SYLLABLE O;Lo;0;L;;;;;N;;;;; A012;YI SYLLABLE OP;Lo;0;L;;;;;N;;;;; A013;YI SYLLABLE EX;Lo;0;L;;;;;N;;;;; A014;YI SYLLABLE E;Lo;0;L;;;;;N;;;;; -A015;YI SYLLABLE WU;Lo;0;L;;;;;N;;;;; +A015;YI SYLLABLE WU;Lm;0;L;;;;;N;;;;; A016;YI SYLLABLE BIT;Lo;0;L;;;;;N;;;;; A017;YI SYLLABLE BIX;Lo;0;L;;;;;N;;;;; A018;YI SYLLABLE BI;Lo;0;L;;;;;N;;;;; @@ -10612,6 +12257,879 @@ A4C3;YI RADICAL CHE;So;0;ON;;;;;N;;;;; A4C4;YI RADICAL ZZIET;So;0;ON;;;;;N;;;;; A4C5;YI RADICAL NBIE;So;0;ON;;;;;N;;;;; A4C6;YI RADICAL KE;So;0;ON;;;;;N;;;;; +A500;VAI SYLLABLE EE;Lo;0;L;;;;;N;;;;; +A501;VAI SYLLABLE EEN;Lo;0;L;;;;;N;;;;; +A502;VAI SYLLABLE HEE;Lo;0;L;;;;;N;;;;; +A503;VAI SYLLABLE WEE;Lo;0;L;;;;;N;;;;; +A504;VAI SYLLABLE WEEN;Lo;0;L;;;;;N;;;;; +A505;VAI SYLLABLE PEE;Lo;0;L;;;;;N;;;;; +A506;VAI SYLLABLE BHEE;Lo;0;L;;;;;N;;;;; +A507;VAI SYLLABLE BEE;Lo;0;L;;;;;N;;;;; +A508;VAI SYLLABLE MBEE;Lo;0;L;;;;;N;;;;; +A509;VAI SYLLABLE KPEE;Lo;0;L;;;;;N;;;;; +A50A;VAI SYLLABLE MGBEE;Lo;0;L;;;;;N;;;;; +A50B;VAI SYLLABLE GBEE;Lo;0;L;;;;;N;;;;; +A50C;VAI SYLLABLE FEE;Lo;0;L;;;;;N;;;;; +A50D;VAI SYLLABLE VEE;Lo;0;L;;;;;N;;;;; +A50E;VAI SYLLABLE TEE;Lo;0;L;;;;;N;;;;; +A50F;VAI SYLLABLE THEE;Lo;0;L;;;;;N;;;;; +A510;VAI SYLLABLE DHEE;Lo;0;L;;;;;N;;;;; +A511;VAI SYLLABLE DHHEE;Lo;0;L;;;;;N;;;;; +A512;VAI SYLLABLE LEE;Lo;0;L;;;;;N;;;;; +A513;VAI SYLLABLE REE;Lo;0;L;;;;;N;;;;; +A514;VAI SYLLABLE DEE;Lo;0;L;;;;;N;;;;; +A515;VAI SYLLABLE NDEE;Lo;0;L;;;;;N;;;;; +A516;VAI SYLLABLE SEE;Lo;0;L;;;;;N;;;;; +A517;VAI SYLLABLE SHEE;Lo;0;L;;;;;N;;;;; +A518;VAI SYLLABLE ZEE;Lo;0;L;;;;;N;;;;; +A519;VAI SYLLABLE ZHEE;Lo;0;L;;;;;N;;;;; +A51A;VAI SYLLABLE CEE;Lo;0;L;;;;;N;;;;; +A51B;VAI SYLLABLE JEE;Lo;0;L;;;;;N;;;;; +A51C;VAI SYLLABLE NJEE;Lo;0;L;;;;;N;;;;; +A51D;VAI SYLLABLE YEE;Lo;0;L;;;;;N;;;;; +A51E;VAI SYLLABLE KEE;Lo;0;L;;;;;N;;;;; +A51F;VAI SYLLABLE NGGEE;Lo;0;L;;;;;N;;;;; +A520;VAI SYLLABLE GEE;Lo;0;L;;;;;N;;;;; +A521;VAI SYLLABLE MEE;Lo;0;L;;;;;N;;;;; +A522;VAI SYLLABLE NEE;Lo;0;L;;;;;N;;;;; +A523;VAI SYLLABLE NYEE;Lo;0;L;;;;;N;;;;; +A524;VAI SYLLABLE I;Lo;0;L;;;;;N;;;;; +A525;VAI SYLLABLE IN;Lo;0;L;;;;;N;;;;; +A526;VAI SYLLABLE HI;Lo;0;L;;;;;N;;;;; +A527;VAI SYLLABLE HIN;Lo;0;L;;;;;N;;;;; +A528;VAI SYLLABLE WI;Lo;0;L;;;;;N;;;;; +A529;VAI SYLLABLE WIN;Lo;0;L;;;;;N;;;;; +A52A;VAI SYLLABLE PI;Lo;0;L;;;;;N;;;;; +A52B;VAI SYLLABLE BHI;Lo;0;L;;;;;N;;;;; +A52C;VAI SYLLABLE BI;Lo;0;L;;;;;N;;;;; +A52D;VAI SYLLABLE MBI;Lo;0;L;;;;;N;;;;; +A52E;VAI SYLLABLE KPI;Lo;0;L;;;;;N;;;;; +A52F;VAI SYLLABLE MGBI;Lo;0;L;;;;;N;;;;; +A530;VAI SYLLABLE GBI;Lo;0;L;;;;;N;;;;; +A531;VAI SYLLABLE FI;Lo;0;L;;;;;N;;;;; +A532;VAI SYLLABLE VI;Lo;0;L;;;;;N;;;;; +A533;VAI SYLLABLE TI;Lo;0;L;;;;;N;;;;; +A534;VAI SYLLABLE THI;Lo;0;L;;;;;N;;;;; +A535;VAI SYLLABLE DHI;Lo;0;L;;;;;N;;;;; +A536;VAI SYLLABLE DHHI;Lo;0;L;;;;;N;;;;; +A537;VAI SYLLABLE LI;Lo;0;L;;;;;N;;;;; +A538;VAI SYLLABLE RI;Lo;0;L;;;;;N;;;;; +A539;VAI SYLLABLE DI;Lo;0;L;;;;;N;;;;; +A53A;VAI SYLLABLE NDI;Lo;0;L;;;;;N;;;;; +A53B;VAI SYLLABLE SI;Lo;0;L;;;;;N;;;;; +A53C;VAI SYLLABLE SHI;Lo;0;L;;;;;N;;;;; +A53D;VAI SYLLABLE ZI;Lo;0;L;;;;;N;;;;; +A53E;VAI SYLLABLE ZHI;Lo;0;L;;;;;N;;;;; +A53F;VAI SYLLABLE CI;Lo;0;L;;;;;N;;;;; +A540;VAI SYLLABLE JI;Lo;0;L;;;;;N;;;;; +A541;VAI SYLLABLE NJI;Lo;0;L;;;;;N;;;;; +A542;VAI SYLLABLE YI;Lo;0;L;;;;;N;;;;; +A543;VAI SYLLABLE KI;Lo;0;L;;;;;N;;;;; +A544;VAI SYLLABLE NGGI;Lo;0;L;;;;;N;;;;; +A545;VAI SYLLABLE GI;Lo;0;L;;;;;N;;;;; +A546;VAI SYLLABLE MI;Lo;0;L;;;;;N;;;;; +A547;VAI SYLLABLE NI;Lo;0;L;;;;;N;;;;; +A548;VAI SYLLABLE NYI;Lo;0;L;;;;;N;;;;; +A549;VAI SYLLABLE A;Lo;0;L;;;;;N;;;;; +A54A;VAI SYLLABLE AN;Lo;0;L;;;;;N;;;;; +A54B;VAI SYLLABLE NGAN;Lo;0;L;;;;;N;;;;; +A54C;VAI SYLLABLE HA;Lo;0;L;;;;;N;;;;; +A54D;VAI SYLLABLE HAN;Lo;0;L;;;;;N;;;;; +A54E;VAI SYLLABLE WA;Lo;0;L;;;;;N;;;;; +A54F;VAI SYLLABLE WAN;Lo;0;L;;;;;N;;;;; +A550;VAI SYLLABLE PA;Lo;0;L;;;;;N;;;;; +A551;VAI SYLLABLE BHA;Lo;0;L;;;;;N;;;;; +A552;VAI SYLLABLE BA;Lo;0;L;;;;;N;;;;; +A553;VAI SYLLABLE MBA;Lo;0;L;;;;;N;;;;; +A554;VAI SYLLABLE KPA;Lo;0;L;;;;;N;;;;; +A555;VAI SYLLABLE KPAN;Lo;0;L;;;;;N;;;;; +A556;VAI SYLLABLE MGBA;Lo;0;L;;;;;N;;;;; +A557;VAI SYLLABLE GBA;Lo;0;L;;;;;N;;;;; +A558;VAI SYLLABLE FA;Lo;0;L;;;;;N;;;;; +A559;VAI SYLLABLE VA;Lo;0;L;;;;;N;;;;; +A55A;VAI SYLLABLE TA;Lo;0;L;;;;;N;;;;; +A55B;VAI SYLLABLE THA;Lo;0;L;;;;;N;;;;; +A55C;VAI SYLLABLE DHA;Lo;0;L;;;;;N;;;;; +A55D;VAI SYLLABLE DHHA;Lo;0;L;;;;;N;;;;; +A55E;VAI SYLLABLE LA;Lo;0;L;;;;;N;;;;; +A55F;VAI SYLLABLE RA;Lo;0;L;;;;;N;;;;; +A560;VAI SYLLABLE DA;Lo;0;L;;;;;N;;;;; +A561;VAI SYLLABLE NDA;Lo;0;L;;;;;N;;;;; +A562;VAI SYLLABLE SA;Lo;0;L;;;;;N;;;;; +A563;VAI SYLLABLE SHA;Lo;0;L;;;;;N;;;;; +A564;VAI SYLLABLE ZA;Lo;0;L;;;;;N;;;;; +A565;VAI SYLLABLE ZHA;Lo;0;L;;;;;N;;;;; +A566;VAI SYLLABLE CA;Lo;0;L;;;;;N;;;;; +A567;VAI SYLLABLE JA;Lo;0;L;;;;;N;;;;; +A568;VAI SYLLABLE NJA;Lo;0;L;;;;;N;;;;; +A569;VAI SYLLABLE YA;Lo;0;L;;;;;N;;;;; +A56A;VAI SYLLABLE KA;Lo;0;L;;;;;N;;;;; +A56B;VAI SYLLABLE KAN;Lo;0;L;;;;;N;;;;; +A56C;VAI SYLLABLE NGGA;Lo;0;L;;;;;N;;;;; +A56D;VAI SYLLABLE GA;Lo;0;L;;;;;N;;;;; +A56E;VAI SYLLABLE MA;Lo;0;L;;;;;N;;;;; +A56F;VAI SYLLABLE NA;Lo;0;L;;;;;N;;;;; +A570;VAI SYLLABLE NYA;Lo;0;L;;;;;N;;;;; +A571;VAI SYLLABLE OO;Lo;0;L;;;;;N;;;;; +A572;VAI SYLLABLE OON;Lo;0;L;;;;;N;;;;; +A573;VAI SYLLABLE HOO;Lo;0;L;;;;;N;;;;; +A574;VAI SYLLABLE WOO;Lo;0;L;;;;;N;;;;; +A575;VAI SYLLABLE WOON;Lo;0;L;;;;;N;;;;; +A576;VAI SYLLABLE POO;Lo;0;L;;;;;N;;;;; +A577;VAI SYLLABLE BHOO;Lo;0;L;;;;;N;;;;; +A578;VAI SYLLABLE BOO;Lo;0;L;;;;;N;;;;; +A579;VAI SYLLABLE MBOO;Lo;0;L;;;;;N;;;;; +A57A;VAI SYLLABLE KPOO;Lo;0;L;;;;;N;;;;; +A57B;VAI SYLLABLE MGBOO;Lo;0;L;;;;;N;;;;; +A57C;VAI SYLLABLE GBOO;Lo;0;L;;;;;N;;;;; +A57D;VAI SYLLABLE FOO;Lo;0;L;;;;;N;;;;; +A57E;VAI SYLLABLE VOO;Lo;0;L;;;;;N;;;;; +A57F;VAI SYLLABLE TOO;Lo;0;L;;;;;N;;;;; +A580;VAI SYLLABLE THOO;Lo;0;L;;;;;N;;;;; +A581;VAI SYLLABLE DHOO;Lo;0;L;;;;;N;;;;; +A582;VAI SYLLABLE DHHOO;Lo;0;L;;;;;N;;;;; +A583;VAI SYLLABLE LOO;Lo;0;L;;;;;N;;;;; +A584;VAI SYLLABLE ROO;Lo;0;L;;;;;N;;;;; +A585;VAI SYLLABLE DOO;Lo;0;L;;;;;N;;;;; +A586;VAI SYLLABLE NDOO;Lo;0;L;;;;;N;;;;; +A587;VAI SYLLABLE SOO;Lo;0;L;;;;;N;;;;; +A588;VAI SYLLABLE SHOO;Lo;0;L;;;;;N;;;;; +A589;VAI SYLLABLE ZOO;Lo;0;L;;;;;N;;;;; +A58A;VAI SYLLABLE ZHOO;Lo;0;L;;;;;N;;;;; +A58B;VAI SYLLABLE COO;Lo;0;L;;;;;N;;;;; +A58C;VAI SYLLABLE JOO;Lo;0;L;;;;;N;;;;; +A58D;VAI SYLLABLE NJOO;Lo;0;L;;;;;N;;;;; +A58E;VAI SYLLABLE YOO;Lo;0;L;;;;;N;;;;; +A58F;VAI SYLLABLE KOO;Lo;0;L;;;;;N;;;;; +A590;VAI SYLLABLE NGGOO;Lo;0;L;;;;;N;;;;; +A591;VAI SYLLABLE GOO;Lo;0;L;;;;;N;;;;; +A592;VAI SYLLABLE MOO;Lo;0;L;;;;;N;;;;; +A593;VAI SYLLABLE NOO;Lo;0;L;;;;;N;;;;; +A594;VAI SYLLABLE NYOO;Lo;0;L;;;;;N;;;;; +A595;VAI SYLLABLE U;Lo;0;L;;;;;N;;;;; +A596;VAI SYLLABLE UN;Lo;0;L;;;;;N;;;;; +A597;VAI SYLLABLE HU;Lo;0;L;;;;;N;;;;; +A598;VAI SYLLABLE HUN;Lo;0;L;;;;;N;;;;; +A599;VAI SYLLABLE WU;Lo;0;L;;;;;N;;;;; +A59A;VAI SYLLABLE WUN;Lo;0;L;;;;;N;;;;; +A59B;VAI SYLLABLE PU;Lo;0;L;;;;;N;;;;; +A59C;VAI SYLLABLE BHU;Lo;0;L;;;;;N;;;;; +A59D;VAI SYLLABLE BU;Lo;0;L;;;;;N;;;;; +A59E;VAI SYLLABLE MBU;Lo;0;L;;;;;N;;;;; +A59F;VAI SYLLABLE KPU;Lo;0;L;;;;;N;;;;; +A5A0;VAI SYLLABLE MGBU;Lo;0;L;;;;;N;;;;; +A5A1;VAI SYLLABLE GBU;Lo;0;L;;;;;N;;;;; +A5A2;VAI SYLLABLE FU;Lo;0;L;;;;;N;;;;; +A5A3;VAI SYLLABLE VU;Lo;0;L;;;;;N;;;;; +A5A4;VAI SYLLABLE TU;Lo;0;L;;;;;N;;;;; +A5A5;VAI SYLLABLE THU;Lo;0;L;;;;;N;;;;; +A5A6;VAI SYLLABLE DHU;Lo;0;L;;;;;N;;;;; +A5A7;VAI SYLLABLE DHHU;Lo;0;L;;;;;N;;;;; +A5A8;VAI SYLLABLE LU;Lo;0;L;;;;;N;;;;; +A5A9;VAI SYLLABLE RU;Lo;0;L;;;;;N;;;;; +A5AA;VAI SYLLABLE DU;Lo;0;L;;;;;N;;;;; +A5AB;VAI SYLLABLE NDU;Lo;0;L;;;;;N;;;;; +A5AC;VAI SYLLABLE SU;Lo;0;L;;;;;N;;;;; +A5AD;VAI SYLLABLE SHU;Lo;0;L;;;;;N;;;;; +A5AE;VAI SYLLABLE ZU;Lo;0;L;;;;;N;;;;; +A5AF;VAI SYLLABLE ZHU;Lo;0;L;;;;;N;;;;; +A5B0;VAI SYLLABLE CU;Lo;0;L;;;;;N;;;;; +A5B1;VAI SYLLABLE JU;Lo;0;L;;;;;N;;;;; +A5B2;VAI SYLLABLE NJU;Lo;0;L;;;;;N;;;;; +A5B3;VAI SYLLABLE YU;Lo;0;L;;;;;N;;;;; +A5B4;VAI SYLLABLE KU;Lo;0;L;;;;;N;;;;; +A5B5;VAI SYLLABLE NGGU;Lo;0;L;;;;;N;;;;; +A5B6;VAI SYLLABLE GU;Lo;0;L;;;;;N;;;;; +A5B7;VAI SYLLABLE MU;Lo;0;L;;;;;N;;;;; +A5B8;VAI SYLLABLE NU;Lo;0;L;;;;;N;;;;; +A5B9;VAI SYLLABLE NYU;Lo;0;L;;;;;N;;;;; +A5BA;VAI SYLLABLE O;Lo;0;L;;;;;N;;;;; +A5BB;VAI SYLLABLE ON;Lo;0;L;;;;;N;;;;; +A5BC;VAI SYLLABLE NGON;Lo;0;L;;;;;N;;;;; +A5BD;VAI SYLLABLE HO;Lo;0;L;;;;;N;;;;; +A5BE;VAI SYLLABLE HON;Lo;0;L;;;;;N;;;;; +A5BF;VAI SYLLABLE WO;Lo;0;L;;;;;N;;;;; +A5C0;VAI SYLLABLE WON;Lo;0;L;;;;;N;;;;; +A5C1;VAI SYLLABLE PO;Lo;0;L;;;;;N;;;;; +A5C2;VAI SYLLABLE BHO;Lo;0;L;;;;;N;;;;; +A5C3;VAI SYLLABLE BO;Lo;0;L;;;;;N;;;;; +A5C4;VAI SYLLABLE MBO;Lo;0;L;;;;;N;;;;; +A5C5;VAI SYLLABLE KPO;Lo;0;L;;;;;N;;;;; +A5C6;VAI SYLLABLE MGBO;Lo;0;L;;;;;N;;;;; +A5C7;VAI SYLLABLE GBO;Lo;0;L;;;;;N;;;;; +A5C8;VAI SYLLABLE GBON;Lo;0;L;;;;;N;;;;; +A5C9;VAI SYLLABLE FO;Lo;0;L;;;;;N;;;;; +A5CA;VAI SYLLABLE VO;Lo;0;L;;;;;N;;;;; +A5CB;VAI SYLLABLE TO;Lo;0;L;;;;;N;;;;; +A5CC;VAI SYLLABLE THO;Lo;0;L;;;;;N;;;;; +A5CD;VAI SYLLABLE DHO;Lo;0;L;;;;;N;;;;; +A5CE;VAI SYLLABLE DHHO;Lo;0;L;;;;;N;;;;; +A5CF;VAI SYLLABLE LO;Lo;0;L;;;;;N;;;;; +A5D0;VAI SYLLABLE RO;Lo;0;L;;;;;N;;;;; +A5D1;VAI SYLLABLE DO;Lo;0;L;;;;;N;;;;; +A5D2;VAI SYLLABLE NDO;Lo;0;L;;;;;N;;;;; +A5D3;VAI SYLLABLE SO;Lo;0;L;;;;;N;;;;; +A5D4;VAI SYLLABLE SHO;Lo;0;L;;;;;N;;;;; +A5D5;VAI SYLLABLE ZO;Lo;0;L;;;;;N;;;;; +A5D6;VAI SYLLABLE ZHO;Lo;0;L;;;;;N;;;;; +A5D7;VAI SYLLABLE CO;Lo;0;L;;;;;N;;;;; +A5D8;VAI SYLLABLE JO;Lo;0;L;;;;;N;;;;; +A5D9;VAI SYLLABLE NJO;Lo;0;L;;;;;N;;;;; +A5DA;VAI SYLLABLE YO;Lo;0;L;;;;;N;;;;; +A5DB;VAI SYLLABLE KO;Lo;0;L;;;;;N;;;;; +A5DC;VAI SYLLABLE NGGO;Lo;0;L;;;;;N;;;;; +A5DD;VAI SYLLABLE GO;Lo;0;L;;;;;N;;;;; +A5DE;VAI SYLLABLE MO;Lo;0;L;;;;;N;;;;; +A5DF;VAI SYLLABLE NO;Lo;0;L;;;;;N;;;;; +A5E0;VAI SYLLABLE NYO;Lo;0;L;;;;;N;;;;; +A5E1;VAI SYLLABLE E;Lo;0;L;;;;;N;;;;; +A5E2;VAI SYLLABLE EN;Lo;0;L;;;;;N;;;;; +A5E3;VAI SYLLABLE NGEN;Lo;0;L;;;;;N;;;;; +A5E4;VAI SYLLABLE HE;Lo;0;L;;;;;N;;;;; +A5E5;VAI SYLLABLE HEN;Lo;0;L;;;;;N;;;;; +A5E6;VAI SYLLABLE WE;Lo;0;L;;;;;N;;;;; +A5E7;VAI SYLLABLE WEN;Lo;0;L;;;;;N;;;;; +A5E8;VAI SYLLABLE PE;Lo;0;L;;;;;N;;;;; +A5E9;VAI SYLLABLE BHE;Lo;0;L;;;;;N;;;;; +A5EA;VAI SYLLABLE BE;Lo;0;L;;;;;N;;;;; +A5EB;VAI SYLLABLE MBE;Lo;0;L;;;;;N;;;;; +A5EC;VAI SYLLABLE KPE;Lo;0;L;;;;;N;;;;; +A5ED;VAI SYLLABLE KPEN;Lo;0;L;;;;;N;;;;; +A5EE;VAI SYLLABLE MGBE;Lo;0;L;;;;;N;;;;; +A5EF;VAI SYLLABLE GBE;Lo;0;L;;;;;N;;;;; +A5F0;VAI SYLLABLE GBEN;Lo;0;L;;;;;N;;;;; +A5F1;VAI SYLLABLE FE;Lo;0;L;;;;;N;;;;; +A5F2;VAI SYLLABLE VE;Lo;0;L;;;;;N;;;;; +A5F3;VAI SYLLABLE TE;Lo;0;L;;;;;N;;;;; +A5F4;VAI SYLLABLE THE;Lo;0;L;;;;;N;;;;; +A5F5;VAI SYLLABLE DHE;Lo;0;L;;;;;N;;;;; +A5F6;VAI SYLLABLE DHHE;Lo;0;L;;;;;N;;;;; +A5F7;VAI SYLLABLE LE;Lo;0;L;;;;;N;;;;; +A5F8;VAI SYLLABLE RE;Lo;0;L;;;;;N;;;;; +A5F9;VAI SYLLABLE DE;Lo;0;L;;;;;N;;;;; +A5FA;VAI SYLLABLE NDE;Lo;0;L;;;;;N;;;;; +A5FB;VAI SYLLABLE SE;Lo;0;L;;;;;N;;;;; +A5FC;VAI SYLLABLE SHE;Lo;0;L;;;;;N;;;;; +A5FD;VAI SYLLABLE ZE;Lo;0;L;;;;;N;;;;; +A5FE;VAI SYLLABLE ZHE;Lo;0;L;;;;;N;;;;; +A5FF;VAI SYLLABLE CE;Lo;0;L;;;;;N;;;;; +A600;VAI SYLLABLE JE;Lo;0;L;;;;;N;;;;; +A601;VAI SYLLABLE NJE;Lo;0;L;;;;;N;;;;; +A602;VAI SYLLABLE YE;Lo;0;L;;;;;N;;;;; +A603;VAI SYLLABLE KE;Lo;0;L;;;;;N;;;;; +A604;VAI SYLLABLE NGGE;Lo;0;L;;;;;N;;;;; +A605;VAI SYLLABLE NGGEN;Lo;0;L;;;;;N;;;;; +A606;VAI SYLLABLE GE;Lo;0;L;;;;;N;;;;; +A607;VAI SYLLABLE GEN;Lo;0;L;;;;;N;;;;; +A608;VAI SYLLABLE ME;Lo;0;L;;;;;N;;;;; +A609;VAI SYLLABLE NE;Lo;0;L;;;;;N;;;;; +A60A;VAI SYLLABLE NYE;Lo;0;L;;;;;N;;;;; +A60B;VAI SYLLABLE NG;Lo;0;L;;;;;N;;;;; +A60C;VAI SYLLABLE LENGTHENER;Lm;0;L;;;;;N;;;;; +A60D;VAI COMMA;Po;0;ON;;;;;N;;;;; +A60E;VAI FULL STOP;Po;0;ON;;;;;N;;;;; +A60F;VAI QUESTION MARK;Po;0;ON;;;;;N;;;;; +A610;VAI SYLLABLE NDOLE FA;Lo;0;L;;;;;N;;;;; +A611;VAI SYLLABLE NDOLE KA;Lo;0;L;;;;;N;;;;; +A612;VAI SYLLABLE NDOLE SOO;Lo;0;L;;;;;N;;;;; +A613;VAI SYMBOL FEENG;Lo;0;L;;;;;N;;;;; +A614;VAI SYMBOL KEENG;Lo;0;L;;;;;N;;;;; +A615;VAI SYMBOL TING;Lo;0;L;;;;;N;;;;; +A616;VAI SYMBOL NII;Lo;0;L;;;;;N;;;;; +A617;VAI SYMBOL BANG;Lo;0;L;;;;;N;;;;; +A618;VAI SYMBOL FAA;Lo;0;L;;;;;N;;;;; +A619;VAI SYMBOL TAA;Lo;0;L;;;;;N;;;;; +A61A;VAI SYMBOL DANG;Lo;0;L;;;;;N;;;;; +A61B;VAI SYMBOL DOONG;Lo;0;L;;;;;N;;;;; +A61C;VAI SYMBOL KUNG;Lo;0;L;;;;;N;;;;; +A61D;VAI SYMBOL TONG;Lo;0;L;;;;;N;;;;; +A61E;VAI SYMBOL DO-O;Lo;0;L;;;;;N;;;;; +A61F;VAI SYMBOL JONG;Lo;0;L;;;;;N;;;;; +A620;VAI DIGIT ZERO;Nd;0;L;;0;0;0;N;;;;; +A621;VAI DIGIT ONE;Nd;0;L;;1;1;1;N;;;;; +A622;VAI DIGIT TWO;Nd;0;L;;2;2;2;N;;;;; +A623;VAI DIGIT THREE;Nd;0;L;;3;3;3;N;;;;; +A624;VAI DIGIT FOUR;Nd;0;L;;4;4;4;N;;;;; +A625;VAI DIGIT FIVE;Nd;0;L;;5;5;5;N;;;;; +A626;VAI DIGIT SIX;Nd;0;L;;6;6;6;N;;;;; +A627;VAI DIGIT SEVEN;Nd;0;L;;7;7;7;N;;;;; +A628;VAI DIGIT EIGHT;Nd;0;L;;8;8;8;N;;;;; +A629;VAI DIGIT NINE;Nd;0;L;;9;9;9;N;;;;; +A62A;VAI SYLLABLE NDOLE MA;Lo;0;L;;;;;N;;;;; +A62B;VAI SYLLABLE NDOLE DO;Lo;0;L;;;;;N;;;;; +A640;CYRILLIC CAPITAL LETTER ZEMLYA;Lu;0;L;;;;;N;;;;A641; +A641;CYRILLIC SMALL LETTER ZEMLYA;Ll;0;L;;;;;N;;;A640;;A640 +A642;CYRILLIC CAPITAL LETTER DZELO;Lu;0;L;;;;;N;;;;A643; +A643;CYRILLIC SMALL LETTER DZELO;Ll;0;L;;;;;N;;;A642;;A642 +A644;CYRILLIC CAPITAL LETTER REVERSED DZE;Lu;0;L;;;;;N;;;;A645; +A645;CYRILLIC SMALL LETTER REVERSED DZE;Ll;0;L;;;;;N;;;A644;;A644 +A646;CYRILLIC CAPITAL LETTER IOTA;Lu;0;L;;;;;N;;;;A647; +A647;CYRILLIC SMALL LETTER IOTA;Ll;0;L;;;;;N;;;A646;;A646 +A648;CYRILLIC CAPITAL LETTER DJERV;Lu;0;L;;;;;N;;;;A649; +A649;CYRILLIC SMALL LETTER DJERV;Ll;0;L;;;;;N;;;A648;;A648 +A64A;CYRILLIC CAPITAL LETTER MONOGRAPH UK;Lu;0;L;;;;;N;;;;A64B; +A64B;CYRILLIC SMALL LETTER MONOGRAPH UK;Ll;0;L;;;;;N;;;A64A;;A64A +A64C;CYRILLIC CAPITAL LETTER BROAD OMEGA;Lu;0;L;;;;;N;;;;A64D; +A64D;CYRILLIC SMALL LETTER BROAD OMEGA;Ll;0;L;;;;;N;;;A64C;;A64C +A64E;CYRILLIC CAPITAL LETTER NEUTRAL YER;Lu;0;L;;;;;N;;;;A64F; +A64F;CYRILLIC SMALL LETTER NEUTRAL YER;Ll;0;L;;;;;N;;;A64E;;A64E +A650;CYRILLIC CAPITAL LETTER YERU WITH BACK YER;Lu;0;L;;;;;N;;;;A651; +A651;CYRILLIC SMALL LETTER YERU WITH BACK YER;Ll;0;L;;;;;N;;;A650;;A650 +A652;CYRILLIC CAPITAL LETTER IOTIFIED YAT;Lu;0;L;;;;;N;;;;A653; +A653;CYRILLIC SMALL LETTER IOTIFIED YAT;Ll;0;L;;;;;N;;;A652;;A652 +A654;CYRILLIC CAPITAL LETTER REVERSED YU;Lu;0;L;;;;;N;;;;A655; +A655;CYRILLIC SMALL LETTER REVERSED YU;Ll;0;L;;;;;N;;;A654;;A654 +A656;CYRILLIC CAPITAL LETTER IOTIFIED A;Lu;0;L;;;;;N;;;;A657; +A657;CYRILLIC SMALL LETTER IOTIFIED A;Ll;0;L;;;;;N;;;A656;;A656 +A658;CYRILLIC CAPITAL LETTER CLOSED LITTLE YUS;Lu;0;L;;;;;N;;;;A659; +A659;CYRILLIC SMALL LETTER CLOSED LITTLE YUS;Ll;0;L;;;;;N;;;A658;;A658 +A65A;CYRILLIC CAPITAL LETTER BLENDED YUS;Lu;0;L;;;;;N;;;;A65B; +A65B;CYRILLIC SMALL LETTER BLENDED YUS;Ll;0;L;;;;;N;;;A65A;;A65A +A65C;CYRILLIC CAPITAL LETTER IOTIFIED CLOSED LITTLE YUS;Lu;0;L;;;;;N;;;;A65D; +A65D;CYRILLIC SMALL LETTER IOTIFIED CLOSED LITTLE YUS;Ll;0;L;;;;;N;;;A65C;;A65C +A65E;CYRILLIC CAPITAL LETTER YN;Lu;0;L;;;;;N;;;;A65F; +A65F;CYRILLIC SMALL LETTER YN;Ll;0;L;;;;;N;;;A65E;;A65E +A662;CYRILLIC CAPITAL LETTER SOFT DE;Lu;0;L;;;;;N;;;;A663; +A663;CYRILLIC SMALL LETTER SOFT DE;Ll;0;L;;;;;N;;;A662;;A662 +A664;CYRILLIC CAPITAL LETTER SOFT EL;Lu;0;L;;;;;N;;;;A665; +A665;CYRILLIC SMALL LETTER SOFT EL;Ll;0;L;;;;;N;;;A664;;A664 +A666;CYRILLIC CAPITAL LETTER SOFT EM;Lu;0;L;;;;;N;;;;A667; +A667;CYRILLIC SMALL LETTER SOFT EM;Ll;0;L;;;;;N;;;A666;;A666 +A668;CYRILLIC CAPITAL LETTER MONOCULAR O;Lu;0;L;;;;;N;;;;A669; +A669;CYRILLIC SMALL LETTER MONOCULAR O;Ll;0;L;;;;;N;;;A668;;A668 +A66A;CYRILLIC CAPITAL LETTER BINOCULAR O;Lu;0;L;;;;;N;;;;A66B; +A66B;CYRILLIC SMALL LETTER BINOCULAR O;Ll;0;L;;;;;N;;;A66A;;A66A +A66C;CYRILLIC CAPITAL LETTER DOUBLE MONOCULAR O;Lu;0;L;;;;;N;;;;A66D; +A66D;CYRILLIC SMALL LETTER DOUBLE MONOCULAR O;Ll;0;L;;;;;N;;;A66C;;A66C +A66E;CYRILLIC LETTER MULTIOCULAR O;Lo;0;L;;;;;N;;;;; +A66F;COMBINING CYRILLIC VZMET;Mn;230;NSM;;;;;N;;;;; +A670;COMBINING CYRILLIC TEN MILLIONS SIGN;Me;0;NSM;;;;;N;;;;; +A671;COMBINING CYRILLIC HUNDRED MILLIONS SIGN;Me;0;NSM;;;;;N;;;;; +A672;COMBINING CYRILLIC THOUSAND MILLIONS SIGN;Me;0;NSM;;;;;N;;;;; +A673;SLAVONIC ASTERISK;Po;0;ON;;;;;N;;;;; +A67C;COMBINING CYRILLIC KAVYKA;Mn;230;NSM;;;;;N;;;;; +A67D;COMBINING CYRILLIC PAYEROK;Mn;230;NSM;;;;;N;;;;; +A67E;CYRILLIC KAVYKA;Po;0;ON;;;;;N;;;;; +A67F;CYRILLIC PAYEROK;Lm;0;ON;;;;;N;;;;; +A680;CYRILLIC CAPITAL LETTER DWE;Lu;0;L;;;;;N;;;;A681; +A681;CYRILLIC SMALL LETTER DWE;Ll;0;L;;;;;N;;;A680;;A680 +A682;CYRILLIC CAPITAL LETTER DZWE;Lu;0;L;;;;;N;;;;A683; +A683;CYRILLIC SMALL LETTER DZWE;Ll;0;L;;;;;N;;;A682;;A682 +A684;CYRILLIC CAPITAL LETTER ZHWE;Lu;0;L;;;;;N;;;;A685; +A685;CYRILLIC SMALL LETTER ZHWE;Ll;0;L;;;;;N;;;A684;;A684 +A686;CYRILLIC CAPITAL LETTER CCHE;Lu;0;L;;;;;N;;;;A687; +A687;CYRILLIC SMALL LETTER CCHE;Ll;0;L;;;;;N;;;A686;;A686 +A688;CYRILLIC CAPITAL LETTER DZZE;Lu;0;L;;;;;N;;;;A689; +A689;CYRILLIC SMALL LETTER DZZE;Ll;0;L;;;;;N;;;A688;;A688 +A68A;CYRILLIC CAPITAL LETTER TE WITH MIDDLE HOOK;Lu;0;L;;;;;N;;;;A68B; +A68B;CYRILLIC SMALL LETTER TE WITH MIDDLE HOOK;Ll;0;L;;;;;N;;;A68A;;A68A +A68C;CYRILLIC CAPITAL LETTER TWE;Lu;0;L;;;;;N;;;;A68D; +A68D;CYRILLIC SMALL LETTER TWE;Ll;0;L;;;;;N;;;A68C;;A68C +A68E;CYRILLIC CAPITAL LETTER TSWE;Lu;0;L;;;;;N;;;;A68F; +A68F;CYRILLIC SMALL LETTER TSWE;Ll;0;L;;;;;N;;;A68E;;A68E +A690;CYRILLIC CAPITAL LETTER TSSE;Lu;0;L;;;;;N;;;;A691; +A691;CYRILLIC SMALL LETTER TSSE;Ll;0;L;;;;;N;;;A690;;A690 +A692;CYRILLIC CAPITAL LETTER TCHE;Lu;0;L;;;;;N;;;;A693; +A693;CYRILLIC SMALL LETTER TCHE;Ll;0;L;;;;;N;;;A692;;A692 +A694;CYRILLIC CAPITAL LETTER HWE;Lu;0;L;;;;;N;;;;A695; +A695;CYRILLIC SMALL LETTER HWE;Ll;0;L;;;;;N;;;A694;;A694 +A696;CYRILLIC CAPITAL LETTER SHWE;Lu;0;L;;;;;N;;;;A697; +A697;CYRILLIC SMALL LETTER SHWE;Ll;0;L;;;;;N;;;A696;;A696 +A700;MODIFIER LETTER CHINESE TONE YIN PING;Sk;0;ON;;;;;N;;;;; +A701;MODIFIER LETTER CHINESE TONE YANG PING;Sk;0;ON;;;;;N;;;;; +A702;MODIFIER LETTER CHINESE TONE YIN SHANG;Sk;0;ON;;;;;N;;;;; +A703;MODIFIER LETTER CHINESE TONE YANG SHANG;Sk;0;ON;;;;;N;;;;; +A704;MODIFIER LETTER CHINESE TONE YIN QU;Sk;0;ON;;;;;N;;;;; +A705;MODIFIER LETTER CHINESE TONE YANG QU;Sk;0;ON;;;;;N;;;;; +A706;MODIFIER LETTER CHINESE TONE YIN RU;Sk;0;ON;;;;;N;;;;; +A707;MODIFIER LETTER CHINESE TONE YANG RU;Sk;0;ON;;;;;N;;;;; +A708;MODIFIER LETTER EXTRA-HIGH DOTTED TONE BAR;Sk;0;ON;;;;;N;;;;; +A709;MODIFIER LETTER HIGH DOTTED TONE BAR;Sk;0;ON;;;;;N;;;;; +A70A;MODIFIER LETTER MID DOTTED TONE BAR;Sk;0;ON;;;;;N;;;;; +A70B;MODIFIER LETTER LOW DOTTED TONE BAR;Sk;0;ON;;;;;N;;;;; +A70C;MODIFIER LETTER EXTRA-LOW DOTTED TONE BAR;Sk;0;ON;;;;;N;;;;; +A70D;MODIFIER LETTER EXTRA-HIGH DOTTED LEFT-STEM TONE BAR;Sk;0;ON;;;;;N;;;;; +A70E;MODIFIER LETTER HIGH DOTTED LEFT-STEM TONE BAR;Sk;0;ON;;;;;N;;;;; +A70F;MODIFIER LETTER MID DOTTED LEFT-STEM TONE BAR;Sk;0;ON;;;;;N;;;;; +A710;MODIFIER LETTER LOW DOTTED LEFT-STEM TONE BAR;Sk;0;ON;;;;;N;;;;; +A711;MODIFIER LETTER EXTRA-LOW DOTTED LEFT-STEM TONE BAR;Sk;0;ON;;;;;N;;;;; +A712;MODIFIER LETTER EXTRA-HIGH LEFT-STEM TONE BAR;Sk;0;ON;;;;;N;;;;; +A713;MODIFIER LETTER HIGH LEFT-STEM TONE BAR;Sk;0;ON;;;;;N;;;;; +A714;MODIFIER LETTER MID LEFT-STEM TONE BAR;Sk;0;ON;;;;;N;;;;; +A715;MODIFIER LETTER LOW LEFT-STEM TONE BAR;Sk;0;ON;;;;;N;;;;; +A716;MODIFIER LETTER EXTRA-LOW LEFT-STEM TONE BAR;Sk;0;ON;;;;;N;;;;; +A717;MODIFIER LETTER DOT VERTICAL BAR;Lm;0;ON;;;;;N;;;;; +A718;MODIFIER LETTER DOT SLASH;Lm;0;ON;;;;;N;;;;; +A719;MODIFIER LETTER DOT HORIZONTAL BAR;Lm;0;ON;;;;;N;;;;; +A71A;MODIFIER LETTER LOWER RIGHT CORNER ANGLE;Lm;0;ON;;;;;N;;;;; +A71B;MODIFIER LETTER RAISED UP ARROW;Lm;0;ON;;;;;N;;;;; +A71C;MODIFIER LETTER RAISED DOWN ARROW;Lm;0;ON;;;;;N;;;;; +A71D;MODIFIER LETTER RAISED EXCLAMATION MARK;Lm;0;ON;;;;;N;;;;; +A71E;MODIFIER LETTER RAISED INVERTED EXCLAMATION MARK;Lm;0;ON;;;;;N;;;;; +A71F;MODIFIER LETTER LOW INVERTED EXCLAMATION MARK;Lm;0;ON;;;;;N;;;;; +A720;MODIFIER LETTER STRESS AND HIGH TONE;Sk;0;ON;;;;;N;;;;; +A721;MODIFIER LETTER STRESS AND LOW TONE;Sk;0;ON;;;;;N;;;;; +A722;LATIN CAPITAL LETTER EGYPTOLOGICAL ALEF;Lu;0;L;;;;;N;;;;A723; +A723;LATIN SMALL LETTER EGYPTOLOGICAL ALEF;Ll;0;L;;;;;N;;;A722;;A722 +A724;LATIN CAPITAL LETTER EGYPTOLOGICAL AIN;Lu;0;L;;;;;N;;;;A725; +A725;LATIN SMALL LETTER EGYPTOLOGICAL AIN;Ll;0;L;;;;;N;;;A724;;A724 +A726;LATIN CAPITAL LETTER HENG;Lu;0;L;;;;;N;;;;A727; +A727;LATIN SMALL LETTER HENG;Ll;0;L;;;;;N;;;A726;;A726 +A728;LATIN CAPITAL LETTER TZ;Lu;0;L;;;;;N;;;;A729; +A729;LATIN SMALL LETTER TZ;Ll;0;L;;;;;N;;;A728;;A728 +A72A;LATIN CAPITAL LETTER TRESILLO;Lu;0;L;;;;;N;;;;A72B; +A72B;LATIN SMALL LETTER TRESILLO;Ll;0;L;;;;;N;;;A72A;;A72A +A72C;LATIN CAPITAL LETTER CUATRILLO;Lu;0;L;;;;;N;;;;A72D; +A72D;LATIN SMALL LETTER CUATRILLO;Ll;0;L;;;;;N;;;A72C;;A72C +A72E;LATIN CAPITAL LETTER CUATRILLO WITH COMMA;Lu;0;L;;;;;N;;;;A72F; +A72F;LATIN SMALL LETTER CUATRILLO WITH COMMA;Ll;0;L;;;;;N;;;A72E;;A72E +A730;LATIN LETTER SMALL CAPITAL F;Ll;0;L;;;;;N;;;;; +A731;LATIN LETTER SMALL CAPITAL S;Ll;0;L;;;;;N;;;;; +A732;LATIN CAPITAL LETTER AA;Lu;0;L;;;;;N;;;;A733; +A733;LATIN SMALL LETTER AA;Ll;0;L;;;;;N;;;A732;;A732 +A734;LATIN CAPITAL LETTER AO;Lu;0;L;;;;;N;;;;A735; +A735;LATIN SMALL LETTER AO;Ll;0;L;;;;;N;;;A734;;A734 +A736;LATIN CAPITAL LETTER AU;Lu;0;L;;;;;N;;;;A737; +A737;LATIN SMALL LETTER AU;Ll;0;L;;;;;N;;;A736;;A736 +A738;LATIN CAPITAL LETTER AV;Lu;0;L;;;;;N;;;;A739; +A739;LATIN SMALL LETTER AV;Ll;0;L;;;;;N;;;A738;;A738 +A73A;LATIN CAPITAL LETTER AV WITH HORIZONTAL BAR;Lu;0;L;;;;;N;;;;A73B; +A73B;LATIN SMALL LETTER AV WITH HORIZONTAL BAR;Ll;0;L;;;;;N;;;A73A;;A73A +A73C;LATIN CAPITAL LETTER AY;Lu;0;L;;;;;N;;;;A73D; +A73D;LATIN SMALL LETTER AY;Ll;0;L;;;;;N;;;A73C;;A73C +A73E;LATIN CAPITAL LETTER REVERSED C WITH DOT;Lu;0;L;;;;;N;;;;A73F; +A73F;LATIN SMALL LETTER REVERSED C WITH DOT;Ll;0;L;;;;;N;;;A73E;;A73E +A740;LATIN CAPITAL LETTER K WITH STROKE;Lu;0;L;;;;;N;;;;A741; +A741;LATIN SMALL LETTER K WITH STROKE;Ll;0;L;;;;;N;;;A740;;A740 +A742;LATIN CAPITAL LETTER K WITH DIAGONAL STROKE;Lu;0;L;;;;;N;;;;A743; +A743;LATIN SMALL LETTER K WITH DIAGONAL STROKE;Ll;0;L;;;;;N;;;A742;;A742 +A744;LATIN CAPITAL LETTER K WITH STROKE AND DIAGONAL STROKE;Lu;0;L;;;;;N;;;;A745; +A745;LATIN SMALL LETTER K WITH STROKE AND DIAGONAL STROKE;Ll;0;L;;;;;N;;;A744;;A744 +A746;LATIN CAPITAL LETTER BROKEN L;Lu;0;L;;;;;N;;;;A747; +A747;LATIN SMALL LETTER BROKEN L;Ll;0;L;;;;;N;;;A746;;A746 +A748;LATIN CAPITAL LETTER L WITH HIGH STROKE;Lu;0;L;;;;;N;;;;A749; +A749;LATIN SMALL LETTER L WITH HIGH STROKE;Ll;0;L;;;;;N;;;A748;;A748 +A74A;LATIN CAPITAL LETTER O WITH LONG STROKE OVERLAY;Lu;0;L;;;;;N;;;;A74B; +A74B;LATIN SMALL LETTER O WITH LONG STROKE OVERLAY;Ll;0;L;;;;;N;;;A74A;;A74A +A74C;LATIN CAPITAL LETTER O WITH LOOP;Lu;0;L;;;;;N;;;;A74D; +A74D;LATIN SMALL LETTER O WITH LOOP;Ll;0;L;;;;;N;;;A74C;;A74C +A74E;LATIN CAPITAL LETTER OO;Lu;0;L;;;;;N;;;;A74F; +A74F;LATIN SMALL LETTER OO;Ll;0;L;;;;;N;;;A74E;;A74E +A750;LATIN CAPITAL LETTER P WITH STROKE THROUGH DESCENDER;Lu;0;L;;;;;N;;;;A751; +A751;LATIN SMALL LETTER P WITH STROKE THROUGH DESCENDER;Ll;0;L;;;;;N;;;A750;;A750 +A752;LATIN CAPITAL LETTER P WITH FLOURISH;Lu;0;L;;;;;N;;;;A753; +A753;LATIN SMALL LETTER P WITH FLOURISH;Ll;0;L;;;;;N;;;A752;;A752 +A754;LATIN CAPITAL LETTER P WITH SQUIRREL TAIL;Lu;0;L;;;;;N;;;;A755; +A755;LATIN SMALL LETTER P WITH SQUIRREL TAIL;Ll;0;L;;;;;N;;;A754;;A754 +A756;LATIN CAPITAL LETTER Q WITH STROKE THROUGH DESCENDER;Lu;0;L;;;;;N;;;;A757; +A757;LATIN SMALL LETTER Q WITH STROKE THROUGH DESCENDER;Ll;0;L;;;;;N;;;A756;;A756 +A758;LATIN CAPITAL LETTER Q WITH DIAGONAL STROKE;Lu;0;L;;;;;N;;;;A759; +A759;LATIN SMALL LETTER Q WITH DIAGONAL STROKE;Ll;0;L;;;;;N;;;A758;;A758 +A75A;LATIN CAPITAL LETTER R ROTUNDA;Lu;0;L;;;;;N;;;;A75B; +A75B;LATIN SMALL LETTER R ROTUNDA;Ll;0;L;;;;;N;;;A75A;;A75A +A75C;LATIN CAPITAL LETTER RUM ROTUNDA;Lu;0;L;;;;;N;;;;A75D; +A75D;LATIN SMALL LETTER RUM ROTUNDA;Ll;0;L;;;;;N;;;A75C;;A75C +A75E;LATIN CAPITAL LETTER V WITH DIAGONAL STROKE;Lu;0;L;;;;;N;;;;A75F; +A75F;LATIN SMALL LETTER V WITH DIAGONAL STROKE;Ll;0;L;;;;;N;;;A75E;;A75E +A760;LATIN CAPITAL LETTER VY;Lu;0;L;;;;;N;;;;A761; +A761;LATIN SMALL LETTER VY;Ll;0;L;;;;;N;;;A760;;A760 +A762;LATIN CAPITAL LETTER VISIGOTHIC Z;Lu;0;L;;;;;N;;;;A763; +A763;LATIN SMALL LETTER VISIGOTHIC Z;Ll;0;L;;;;;N;;;A762;;A762 +A764;LATIN CAPITAL LETTER THORN WITH STROKE;Lu;0;L;;;;;N;;;;A765; +A765;LATIN SMALL LETTER THORN WITH STROKE;Ll;0;L;;;;;N;;;A764;;A764 +A766;LATIN CAPITAL LETTER THORN WITH STROKE THROUGH DESCENDER;Lu;0;L;;;;;N;;;;A767; +A767;LATIN SMALL LETTER THORN WITH STROKE THROUGH DESCENDER;Ll;0;L;;;;;N;;;A766;;A766 +A768;LATIN CAPITAL LETTER VEND;Lu;0;L;;;;;N;;;;A769; +A769;LATIN SMALL LETTER VEND;Ll;0;L;;;;;N;;;A768;;A768 +A76A;LATIN CAPITAL LETTER ET;Lu;0;L;;;;;N;;;;A76B; +A76B;LATIN SMALL LETTER ET;Ll;0;L;;;;;N;;;A76A;;A76A +A76C;LATIN CAPITAL LETTER IS;Lu;0;L;;;;;N;;;;A76D; +A76D;LATIN SMALL LETTER IS;Ll;0;L;;;;;N;;;A76C;;A76C +A76E;LATIN CAPITAL LETTER CON;Lu;0;L;;;;;N;;;;A76F; +A76F;LATIN SMALL LETTER CON;Ll;0;L;;;;;N;;;A76E;;A76E +A770;MODIFIER LETTER US;Lm;0;L;<super> A76F;;;;N;;;;; +A771;LATIN SMALL LETTER DUM;Ll;0;L;;;;;N;;;;; +A772;LATIN SMALL LETTER LUM;Ll;0;L;;;;;N;;;;; +A773;LATIN SMALL LETTER MUM;Ll;0;L;;;;;N;;;;; +A774;LATIN SMALL LETTER NUM;Ll;0;L;;;;;N;;;;; +A775;LATIN SMALL LETTER RUM;Ll;0;L;;;;;N;;;;; +A776;LATIN LETTER SMALL CAPITAL RUM;Ll;0;L;;;;;N;;;;; +A777;LATIN SMALL LETTER TUM;Ll;0;L;;;;;N;;;;; +A778;LATIN SMALL LETTER UM;Ll;0;L;;;;;N;;;;; +A779;LATIN CAPITAL LETTER INSULAR D;Lu;0;L;;;;;N;;;;A77A; +A77A;LATIN SMALL LETTER INSULAR D;Ll;0;L;;;;;N;;;A779;;A779 +A77B;LATIN CAPITAL LETTER INSULAR F;Lu;0;L;;;;;N;;;;A77C; +A77C;LATIN SMALL LETTER INSULAR F;Ll;0;L;;;;;N;;;A77B;;A77B +A77D;LATIN CAPITAL LETTER INSULAR G;Lu;0;L;;;;;N;;;;1D79; +A77E;LATIN CAPITAL LETTER TURNED INSULAR G;Lu;0;L;;;;;N;;;;A77F; +A77F;LATIN SMALL LETTER TURNED INSULAR G;Ll;0;L;;;;;N;;;A77E;;A77E +A780;LATIN CAPITAL LETTER TURNED L;Lu;0;L;;;;;N;;;;A781; +A781;LATIN SMALL LETTER TURNED L;Ll;0;L;;;;;N;;;A780;;A780 +A782;LATIN CAPITAL LETTER INSULAR R;Lu;0;L;;;;;N;;;;A783; +A783;LATIN SMALL LETTER INSULAR R;Ll;0;L;;;;;N;;;A782;;A782 +A784;LATIN CAPITAL LETTER INSULAR S;Lu;0;L;;;;;N;;;;A785; +A785;LATIN SMALL LETTER INSULAR S;Ll;0;L;;;;;N;;;A784;;A784 +A786;LATIN CAPITAL LETTER INSULAR T;Lu;0;L;;;;;N;;;;A787; +A787;LATIN SMALL LETTER INSULAR T;Ll;0;L;;;;;N;;;A786;;A786 +A788;MODIFIER LETTER LOW CIRCUMFLEX ACCENT;Lm;0;ON;;;;;N;;;;; +A789;MODIFIER LETTER COLON;Sk;0;L;;;;;N;;;;; +A78A;MODIFIER LETTER SHORT EQUALS SIGN;Sk;0;L;;;;;N;;;;; +A78B;LATIN CAPITAL LETTER SALTILLO;Lu;0;L;;;;;N;;;;A78C; +A78C;LATIN SMALL LETTER SALTILLO;Ll;0;L;;;;;N;;;A78B;;A78B +A7FB;LATIN EPIGRAPHIC LETTER REVERSED F;Lo;0;L;;;;;N;;;;; +A7FC;LATIN EPIGRAPHIC LETTER REVERSED P;Lo;0;L;;;;;N;;;;; +A7FD;LATIN EPIGRAPHIC LETTER INVERTED M;Lo;0;L;;;;;N;;;;; +A7FE;LATIN EPIGRAPHIC LETTER I LONGA;Lo;0;L;;;;;N;;;;; +A7FF;LATIN EPIGRAPHIC LETTER ARCHAIC M;Lo;0;L;;;;;N;;;;; +A800;SYLOTI NAGRI LETTER A;Lo;0;L;;;;;N;;;;; +A801;SYLOTI NAGRI LETTER I;Lo;0;L;;;;;N;;;;; +A802;SYLOTI NAGRI SIGN DVISVARA;Mn;0;NSM;;;;;N;;;;; +A803;SYLOTI NAGRI LETTER U;Lo;0;L;;;;;N;;;;; +A804;SYLOTI NAGRI LETTER E;Lo;0;L;;;;;N;;;;; +A805;SYLOTI NAGRI LETTER O;Lo;0;L;;;;;N;;;;; +A806;SYLOTI NAGRI SIGN HASANTA;Mn;9;NSM;;;;;N;;;;; +A807;SYLOTI NAGRI LETTER KO;Lo;0;L;;;;;N;;;;; +A808;SYLOTI NAGRI LETTER KHO;Lo;0;L;;;;;N;;;;; +A809;SYLOTI NAGRI LETTER GO;Lo;0;L;;;;;N;;;;; +A80A;SYLOTI NAGRI LETTER GHO;Lo;0;L;;;;;N;;;;; +A80B;SYLOTI NAGRI SIGN ANUSVARA;Mn;0;NSM;;;;;N;;;;; +A80C;SYLOTI NAGRI LETTER CO;Lo;0;L;;;;;N;;;;; +A80D;SYLOTI NAGRI LETTER CHO;Lo;0;L;;;;;N;;;;; +A80E;SYLOTI NAGRI LETTER JO;Lo;0;L;;;;;N;;;;; +A80F;SYLOTI NAGRI LETTER JHO;Lo;0;L;;;;;N;;;;; +A810;SYLOTI NAGRI LETTER TTO;Lo;0;L;;;;;N;;;;; +A811;SYLOTI NAGRI LETTER TTHO;Lo;0;L;;;;;N;;;;; +A812;SYLOTI NAGRI LETTER DDO;Lo;0;L;;;;;N;;;;; +A813;SYLOTI NAGRI LETTER DDHO;Lo;0;L;;;;;N;;;;; +A814;SYLOTI NAGRI LETTER TO;Lo;0;L;;;;;N;;;;; +A815;SYLOTI NAGRI LETTER THO;Lo;0;L;;;;;N;;;;; +A816;SYLOTI NAGRI LETTER DO;Lo;0;L;;;;;N;;;;; +A817;SYLOTI NAGRI LETTER DHO;Lo;0;L;;;;;N;;;;; +A818;SYLOTI NAGRI LETTER NO;Lo;0;L;;;;;N;;;;; +A819;SYLOTI NAGRI LETTER PO;Lo;0;L;;;;;N;;;;; +A81A;SYLOTI NAGRI LETTER PHO;Lo;0;L;;;;;N;;;;; +A81B;SYLOTI NAGRI LETTER BO;Lo;0;L;;;;;N;;;;; +A81C;SYLOTI NAGRI LETTER BHO;Lo;0;L;;;;;N;;;;; +A81D;SYLOTI NAGRI LETTER MO;Lo;0;L;;;;;N;;;;; +A81E;SYLOTI NAGRI LETTER RO;Lo;0;L;;;;;N;;;;; +A81F;SYLOTI NAGRI LETTER LO;Lo;0;L;;;;;N;;;;; +A820;SYLOTI NAGRI LETTER RRO;Lo;0;L;;;;;N;;;;; +A821;SYLOTI NAGRI LETTER SO;Lo;0;L;;;;;N;;;;; +A822;SYLOTI NAGRI LETTER HO;Lo;0;L;;;;;N;;;;; +A823;SYLOTI NAGRI VOWEL SIGN A;Mc;0;L;;;;;N;;;;; +A824;SYLOTI NAGRI VOWEL SIGN I;Mc;0;L;;;;;N;;;;; +A825;SYLOTI NAGRI VOWEL SIGN U;Mn;0;NSM;;;;;N;;;;; +A826;SYLOTI NAGRI VOWEL SIGN E;Mn;0;NSM;;;;;N;;;;; +A827;SYLOTI NAGRI VOWEL SIGN OO;Mc;0;L;;;;;N;;;;; +A828;SYLOTI NAGRI POETRY MARK-1;So;0;ON;;;;;N;;;;; +A829;SYLOTI NAGRI POETRY MARK-2;So;0;ON;;;;;N;;;;; +A82A;SYLOTI NAGRI POETRY MARK-3;So;0;ON;;;;;N;;;;; +A82B;SYLOTI NAGRI POETRY MARK-4;So;0;ON;;;;;N;;;;; +A840;PHAGS-PA LETTER KA;Lo;0;L;;;;;N;;;;; +A841;PHAGS-PA LETTER KHA;Lo;0;L;;;;;N;;;;; +A842;PHAGS-PA LETTER GA;Lo;0;L;;;;;N;;;;; +A843;PHAGS-PA LETTER NGA;Lo;0;L;;;;;N;;;;; +A844;PHAGS-PA LETTER CA;Lo;0;L;;;;;N;;;;; +A845;PHAGS-PA LETTER CHA;Lo;0;L;;;;;N;;;;; +A846;PHAGS-PA LETTER JA;Lo;0;L;;;;;N;;;;; +A847;PHAGS-PA LETTER NYA;Lo;0;L;;;;;N;;;;; +A848;PHAGS-PA LETTER TA;Lo;0;L;;;;;N;;;;; +A849;PHAGS-PA LETTER THA;Lo;0;L;;;;;N;;;;; +A84A;PHAGS-PA LETTER DA;Lo;0;L;;;;;N;;;;; +A84B;PHAGS-PA LETTER NA;Lo;0;L;;;;;N;;;;; +A84C;PHAGS-PA LETTER PA;Lo;0;L;;;;;N;;;;; +A84D;PHAGS-PA LETTER PHA;Lo;0;L;;;;;N;;;;; +A84E;PHAGS-PA LETTER BA;Lo;0;L;;;;;N;;;;; +A84F;PHAGS-PA LETTER MA;Lo;0;L;;;;;N;;;;; +A850;PHAGS-PA LETTER TSA;Lo;0;L;;;;;N;;;;; +A851;PHAGS-PA LETTER TSHA;Lo;0;L;;;;;N;;;;; +A852;PHAGS-PA LETTER DZA;Lo;0;L;;;;;N;;;;; +A853;PHAGS-PA LETTER WA;Lo;0;L;;;;;N;;;;; +A854;PHAGS-PA LETTER ZHA;Lo;0;L;;;;;N;;;;; +A855;PHAGS-PA LETTER ZA;Lo;0;L;;;;;N;;;;; +A856;PHAGS-PA LETTER SMALL A;Lo;0;L;;;;;N;;;;; +A857;PHAGS-PA LETTER YA;Lo;0;L;;;;;N;;;;; +A858;PHAGS-PA LETTER RA;Lo;0;L;;;;;N;;;;; +A859;PHAGS-PA LETTER LA;Lo;0;L;;;;;N;;;;; +A85A;PHAGS-PA LETTER SHA;Lo;0;L;;;;;N;;;;; +A85B;PHAGS-PA LETTER SA;Lo;0;L;;;;;N;;;;; +A85C;PHAGS-PA LETTER HA;Lo;0;L;;;;;N;;;;; +A85D;PHAGS-PA LETTER A;Lo;0;L;;;;;N;;;;; +A85E;PHAGS-PA LETTER I;Lo;0;L;;;;;N;;;;; +A85F;PHAGS-PA LETTER U;Lo;0;L;;;;;N;;;;; +A860;PHAGS-PA LETTER E;Lo;0;L;;;;;N;;;;; +A861;PHAGS-PA LETTER O;Lo;0;L;;;;;N;;;;; +A862;PHAGS-PA LETTER QA;Lo;0;L;;;;;N;;;;; +A863;PHAGS-PA LETTER XA;Lo;0;L;;;;;N;;;;; +A864;PHAGS-PA LETTER FA;Lo;0;L;;;;;N;;;;; +A865;PHAGS-PA LETTER GGA;Lo;0;L;;;;;N;;;;; +A866;PHAGS-PA LETTER EE;Lo;0;L;;;;;N;;;;; +A867;PHAGS-PA SUBJOINED LETTER WA;Lo;0;L;;;;;N;;;;; +A868;PHAGS-PA SUBJOINED LETTER YA;Lo;0;L;;;;;N;;;;; +A869;PHAGS-PA LETTER TTA;Lo;0;L;;;;;N;;;;; +A86A;PHAGS-PA LETTER TTHA;Lo;0;L;;;;;N;;;;; +A86B;PHAGS-PA LETTER DDA;Lo;0;L;;;;;N;;;;; +A86C;PHAGS-PA LETTER NNA;Lo;0;L;;;;;N;;;;; +A86D;PHAGS-PA LETTER ALTERNATE YA;Lo;0;L;;;;;N;;;;; +A86E;PHAGS-PA LETTER VOICELESS SHA;Lo;0;L;;;;;N;;;;; +A86F;PHAGS-PA LETTER VOICED HA;Lo;0;L;;;;;N;;;;; +A870;PHAGS-PA LETTER ASPIRATED FA;Lo;0;L;;;;;N;;;;; +A871;PHAGS-PA SUBJOINED LETTER RA;Lo;0;L;;;;;N;;;;; +A872;PHAGS-PA SUPERFIXED LETTER RA;Lo;0;L;;;;;N;;;;; +A873;PHAGS-PA LETTER CANDRABINDU;Lo;0;L;;;;;N;;;;; +A874;PHAGS-PA SINGLE HEAD MARK;Po;0;ON;;;;;N;;;;; +A875;PHAGS-PA DOUBLE HEAD MARK;Po;0;ON;;;;;N;;;;; +A876;PHAGS-PA MARK SHAD;Po;0;ON;;;;;N;;;;; +A877;PHAGS-PA MARK DOUBLE SHAD;Po;0;ON;;;;;N;;;;; +A880;SAURASHTRA SIGN ANUSVARA;Mc;0;L;;;;;N;;;;; +A881;SAURASHTRA SIGN VISARGA;Mc;0;L;;;;;N;;;;; +A882;SAURASHTRA LETTER A;Lo;0;L;;;;;N;;;;; +A883;SAURASHTRA LETTER AA;Lo;0;L;;;;;N;;;;; +A884;SAURASHTRA LETTER I;Lo;0;L;;;;;N;;;;; +A885;SAURASHTRA LETTER II;Lo;0;L;;;;;N;;;;; +A886;SAURASHTRA LETTER U;Lo;0;L;;;;;N;;;;; +A887;SAURASHTRA LETTER UU;Lo;0;L;;;;;N;;;;; +A888;SAURASHTRA LETTER VOCALIC R;Lo;0;L;;;;;N;;;;; +A889;SAURASHTRA LETTER VOCALIC RR;Lo;0;L;;;;;N;;;;; +A88A;SAURASHTRA LETTER VOCALIC L;Lo;0;L;;;;;N;;;;; +A88B;SAURASHTRA LETTER VOCALIC LL;Lo;0;L;;;;;N;;;;; +A88C;SAURASHTRA LETTER E;Lo;0;L;;;;;N;;;;; +A88D;SAURASHTRA LETTER EE;Lo;0;L;;;;;N;;;;; +A88E;SAURASHTRA LETTER AI;Lo;0;L;;;;;N;;;;; +A88F;SAURASHTRA LETTER O;Lo;0;L;;;;;N;;;;; +A890;SAURASHTRA LETTER OO;Lo;0;L;;;;;N;;;;; +A891;SAURASHTRA LETTER AU;Lo;0;L;;;;;N;;;;; +A892;SAURASHTRA LETTER KA;Lo;0;L;;;;;N;;;;; +A893;SAURASHTRA LETTER KHA;Lo;0;L;;;;;N;;;;; +A894;SAURASHTRA LETTER GA;Lo;0;L;;;;;N;;;;; +A895;SAURASHTRA LETTER GHA;Lo;0;L;;;;;N;;;;; +A896;SAURASHTRA LETTER NGA;Lo;0;L;;;;;N;;;;; +A897;SAURASHTRA LETTER CA;Lo;0;L;;;;;N;;;;; +A898;SAURASHTRA LETTER CHA;Lo;0;L;;;;;N;;;;; +A899;SAURASHTRA LETTER JA;Lo;0;L;;;;;N;;;;; +A89A;SAURASHTRA LETTER JHA;Lo;0;L;;;;;N;;;;; +A89B;SAURASHTRA LETTER NYA;Lo;0;L;;;;;N;;;;; +A89C;SAURASHTRA LETTER TTA;Lo;0;L;;;;;N;;;;; +A89D;SAURASHTRA LETTER TTHA;Lo;0;L;;;;;N;;;;; +A89E;SAURASHTRA LETTER DDA;Lo;0;L;;;;;N;;;;; +A89F;SAURASHTRA LETTER DDHA;Lo;0;L;;;;;N;;;;; +A8A0;SAURASHTRA LETTER NNA;Lo;0;L;;;;;N;;;;; +A8A1;SAURASHTRA LETTER TA;Lo;0;L;;;;;N;;;;; +A8A2;SAURASHTRA LETTER THA;Lo;0;L;;;;;N;;;;; +A8A3;SAURASHTRA LETTER DA;Lo;0;L;;;;;N;;;;; +A8A4;SAURASHTRA LETTER DHA;Lo;0;L;;;;;N;;;;; +A8A5;SAURASHTRA LETTER NA;Lo;0;L;;;;;N;;;;; +A8A6;SAURASHTRA LETTER PA;Lo;0;L;;;;;N;;;;; +A8A7;SAURASHTRA LETTER PHA;Lo;0;L;;;;;N;;;;; +A8A8;SAURASHTRA LETTER BA;Lo;0;L;;;;;N;;;;; +A8A9;SAURASHTRA LETTER BHA;Lo;0;L;;;;;N;;;;; +A8AA;SAURASHTRA LETTER MA;Lo;0;L;;;;;N;;;;; +A8AB;SAURASHTRA LETTER YA;Lo;0;L;;;;;N;;;;; +A8AC;SAURASHTRA LETTER RA;Lo;0;L;;;;;N;;;;; +A8AD;SAURASHTRA LETTER LA;Lo;0;L;;;;;N;;;;; +A8AE;SAURASHTRA LETTER VA;Lo;0;L;;;;;N;;;;; +A8AF;SAURASHTRA LETTER SHA;Lo;0;L;;;;;N;;;;; +A8B0;SAURASHTRA LETTER SSA;Lo;0;L;;;;;N;;;;; +A8B1;SAURASHTRA LETTER SA;Lo;0;L;;;;;N;;;;; +A8B2;SAURASHTRA LETTER HA;Lo;0;L;;;;;N;;;;; +A8B3;SAURASHTRA LETTER LLA;Lo;0;L;;;;;N;;;;; +A8B4;SAURASHTRA CONSONANT SIGN HAARU;Mc;0;L;;;;;N;;;;; +A8B5;SAURASHTRA VOWEL SIGN AA;Mc;0;L;;;;;N;;;;; +A8B6;SAURASHTRA VOWEL SIGN I;Mc;0;L;;;;;N;;;;; +A8B7;SAURASHTRA VOWEL SIGN II;Mc;0;L;;;;;N;;;;; +A8B8;SAURASHTRA VOWEL SIGN U;Mc;0;L;;;;;N;;;;; +A8B9;SAURASHTRA VOWEL SIGN UU;Mc;0;L;;;;;N;;;;; +A8BA;SAURASHTRA VOWEL SIGN VOCALIC R;Mc;0;L;;;;;N;;;;; +A8BB;SAURASHTRA VOWEL SIGN VOCALIC RR;Mc;0;L;;;;;N;;;;; +A8BC;SAURASHTRA VOWEL SIGN VOCALIC L;Mc;0;L;;;;;N;;;;; +A8BD;SAURASHTRA VOWEL SIGN VOCALIC LL;Mc;0;L;;;;;N;;;;; +A8BE;SAURASHTRA VOWEL SIGN E;Mc;0;L;;;;;N;;;;; +A8BF;SAURASHTRA VOWEL SIGN EE;Mc;0;L;;;;;N;;;;; +A8C0;SAURASHTRA VOWEL SIGN AI;Mc;0;L;;;;;N;;;;; +A8C1;SAURASHTRA VOWEL SIGN O;Mc;0;L;;;;;N;;;;; +A8C2;SAURASHTRA VOWEL SIGN OO;Mc;0;L;;;;;N;;;;; +A8C3;SAURASHTRA VOWEL SIGN AU;Mc;0;L;;;;;N;;;;; +A8C4;SAURASHTRA SIGN VIRAMA;Mn;9;NSM;;;;;N;;;;; +A8CE;SAURASHTRA DANDA;Po;0;L;;;;;N;;;;; +A8CF;SAURASHTRA DOUBLE DANDA;Po;0;L;;;;;N;;;;; +A8D0;SAURASHTRA DIGIT ZERO;Nd;0;L;;0;0;0;N;;;;; +A8D1;SAURASHTRA DIGIT ONE;Nd;0;L;;1;1;1;N;;;;; +A8D2;SAURASHTRA DIGIT TWO;Nd;0;L;;2;2;2;N;;;;; +A8D3;SAURASHTRA DIGIT THREE;Nd;0;L;;3;3;3;N;;;;; +A8D4;SAURASHTRA DIGIT FOUR;Nd;0;L;;4;4;4;N;;;;; +A8D5;SAURASHTRA DIGIT FIVE;Nd;0;L;;5;5;5;N;;;;; +A8D6;SAURASHTRA DIGIT SIX;Nd;0;L;;6;6;6;N;;;;; +A8D7;SAURASHTRA DIGIT SEVEN;Nd;0;L;;7;7;7;N;;;;; +A8D8;SAURASHTRA DIGIT EIGHT;Nd;0;L;;8;8;8;N;;;;; +A8D9;SAURASHTRA DIGIT NINE;Nd;0;L;;9;9;9;N;;;;; +A900;KAYAH LI DIGIT ZERO;Nd;0;L;;0;0;0;N;;;;; +A901;KAYAH LI DIGIT ONE;Nd;0;L;;1;1;1;N;;;;; +A902;KAYAH LI DIGIT TWO;Nd;0;L;;2;2;2;N;;;;; +A903;KAYAH LI DIGIT THREE;Nd;0;L;;3;3;3;N;;;;; +A904;KAYAH LI DIGIT FOUR;Nd;0;L;;4;4;4;N;;;;; +A905;KAYAH LI DIGIT FIVE;Nd;0;L;;5;5;5;N;;;;; +A906;KAYAH LI DIGIT SIX;Nd;0;L;;6;6;6;N;;;;; +A907;KAYAH LI DIGIT SEVEN;Nd;0;L;;7;7;7;N;;;;; +A908;KAYAH LI DIGIT EIGHT;Nd;0;L;;8;8;8;N;;;;; +A909;KAYAH LI DIGIT NINE;Nd;0;L;;9;9;9;N;;;;; +A90A;KAYAH LI LETTER KA;Lo;0;L;;;;;N;;;;; +A90B;KAYAH LI LETTER KHA;Lo;0;L;;;;;N;;;;; +A90C;KAYAH LI LETTER GA;Lo;0;L;;;;;N;;;;; +A90D;KAYAH LI LETTER NGA;Lo;0;L;;;;;N;;;;; +A90E;KAYAH LI LETTER SA;Lo;0;L;;;;;N;;;;; +A90F;KAYAH LI LETTER SHA;Lo;0;L;;;;;N;;;;; +A910;KAYAH LI LETTER ZA;Lo;0;L;;;;;N;;;;; +A911;KAYAH LI LETTER NYA;Lo;0;L;;;;;N;;;;; +A912;KAYAH LI LETTER TA;Lo;0;L;;;;;N;;;;; +A913;KAYAH LI LETTER HTA;Lo;0;L;;;;;N;;;;; +A914;KAYAH LI LETTER NA;Lo;0;L;;;;;N;;;;; +A915;KAYAH LI LETTER PA;Lo;0;L;;;;;N;;;;; +A916;KAYAH LI LETTER PHA;Lo;0;L;;;;;N;;;;; +A917;KAYAH LI LETTER MA;Lo;0;L;;;;;N;;;;; +A918;KAYAH LI LETTER DA;Lo;0;L;;;;;N;;;;; +A919;KAYAH LI LETTER BA;Lo;0;L;;;;;N;;;;; +A91A;KAYAH LI LETTER RA;Lo;0;L;;;;;N;;;;; +A91B;KAYAH LI LETTER YA;Lo;0;L;;;;;N;;;;; +A91C;KAYAH LI LETTER LA;Lo;0;L;;;;;N;;;;; +A91D;KAYAH LI LETTER WA;Lo;0;L;;;;;N;;;;; +A91E;KAYAH LI LETTER THA;Lo;0;L;;;;;N;;;;; +A91F;KAYAH LI LETTER HA;Lo;0;L;;;;;N;;;;; +A920;KAYAH LI LETTER VA;Lo;0;L;;;;;N;;;;; +A921;KAYAH LI LETTER CA;Lo;0;L;;;;;N;;;;; +A922;KAYAH LI LETTER A;Lo;0;L;;;;;N;;;;; +A923;KAYAH LI LETTER OE;Lo;0;L;;;;;N;;;;; +A924;KAYAH LI LETTER I;Lo;0;L;;;;;N;;;;; +A925;KAYAH LI LETTER OO;Lo;0;L;;;;;N;;;;; +A926;KAYAH LI VOWEL UE;Mn;0;NSM;;;;;N;;;;; +A927;KAYAH LI VOWEL E;Mn;0;NSM;;;;;N;;;;; +A928;KAYAH LI VOWEL U;Mn;0;NSM;;;;;N;;;;; +A929;KAYAH LI VOWEL EE;Mn;0;NSM;;;;;N;;;;; +A92A;KAYAH LI VOWEL O;Mn;0;NSM;;;;;N;;;;; +A92B;KAYAH LI TONE PLOPHU;Mn;220;NSM;;;;;N;;;;; +A92C;KAYAH LI TONE CALYA;Mn;220;NSM;;;;;N;;;;; +A92D;KAYAH LI TONE CALYA PLOPHU;Mn;220;NSM;;;;;N;;;;; +A92E;KAYAH LI SIGN CWI;Po;0;L;;;;;N;;;;; +A92F;KAYAH LI SIGN SHYA;Po;0;L;;;;;N;;;;; +A930;REJANG LETTER KA;Lo;0;L;;;;;N;;;;; +A931;REJANG LETTER GA;Lo;0;L;;;;;N;;;;; +A932;REJANG LETTER NGA;Lo;0;L;;;;;N;;;;; +A933;REJANG LETTER TA;Lo;0;L;;;;;N;;;;; +A934;REJANG LETTER DA;Lo;0;L;;;;;N;;;;; +A935;REJANG LETTER NA;Lo;0;L;;;;;N;;;;; +A936;REJANG LETTER PA;Lo;0;L;;;;;N;;;;; +A937;REJANG LETTER BA;Lo;0;L;;;;;N;;;;; +A938;REJANG LETTER MA;Lo;0;L;;;;;N;;;;; +A939;REJANG LETTER CA;Lo;0;L;;;;;N;;;;; +A93A;REJANG LETTER JA;Lo;0;L;;;;;N;;;;; +A93B;REJANG LETTER NYA;Lo;0;L;;;;;N;;;;; +A93C;REJANG LETTER SA;Lo;0;L;;;;;N;;;;; +A93D;REJANG LETTER RA;Lo;0;L;;;;;N;;;;; +A93E;REJANG LETTER LA;Lo;0;L;;;;;N;;;;; +A93F;REJANG LETTER YA;Lo;0;L;;;;;N;;;;; +A940;REJANG LETTER WA;Lo;0;L;;;;;N;;;;; +A941;REJANG LETTER HA;Lo;0;L;;;;;N;;;;; +A942;REJANG LETTER MBA;Lo;0;L;;;;;N;;;;; +A943;REJANG LETTER NGGA;Lo;0;L;;;;;N;;;;; +A944;REJANG LETTER NDA;Lo;0;L;;;;;N;;;;; +A945;REJANG LETTER NYJA;Lo;0;L;;;;;N;;;;; +A946;REJANG LETTER A;Lo;0;L;;;;;N;;;;; +A947;REJANG VOWEL SIGN I;Mn;0;NSM;;;;;N;;;;; +A948;REJANG VOWEL SIGN U;Mn;0;NSM;;;;;N;;;;; +A949;REJANG VOWEL SIGN E;Mn;0;NSM;;;;;N;;;;; +A94A;REJANG VOWEL SIGN AI;Mn;0;NSM;;;;;N;;;;; +A94B;REJANG VOWEL SIGN O;Mn;0;NSM;;;;;N;;;;; +A94C;REJANG VOWEL SIGN AU;Mn;0;NSM;;;;;N;;;;; +A94D;REJANG VOWEL SIGN EU;Mn;0;NSM;;;;;N;;;;; +A94E;REJANG VOWEL SIGN EA;Mn;0;NSM;;;;;N;;;;; +A94F;REJANG CONSONANT SIGN NG;Mn;0;NSM;;;;;N;;;;; +A950;REJANG CONSONANT SIGN N;Mn;0;NSM;;;;;N;;;;; +A951;REJANG CONSONANT SIGN R;Mn;0;NSM;;;;;N;;;;; +A952;REJANG CONSONANT SIGN H;Mc;0;L;;;;;N;;;;; +A953;REJANG VIRAMA;Mc;9;L;;;;;N;;;;; +A95F;REJANG SECTION MARK;Po;0;L;;;;;N;;;;; +AA00;CHAM LETTER A;Lo;0;L;;;;;N;;;;; +AA01;CHAM LETTER I;Lo;0;L;;;;;N;;;;; +AA02;CHAM LETTER U;Lo;0;L;;;;;N;;;;; +AA03;CHAM LETTER E;Lo;0;L;;;;;N;;;;; +AA04;CHAM LETTER AI;Lo;0;L;;;;;N;;;;; +AA05;CHAM LETTER O;Lo;0;L;;;;;N;;;;; +AA06;CHAM LETTER KA;Lo;0;L;;;;;N;;;;; +AA07;CHAM LETTER KHA;Lo;0;L;;;;;N;;;;; +AA08;CHAM LETTER GA;Lo;0;L;;;;;N;;;;; +AA09;CHAM LETTER GHA;Lo;0;L;;;;;N;;;;; +AA0A;CHAM LETTER NGUE;Lo;0;L;;;;;N;;;;; +AA0B;CHAM LETTER NGA;Lo;0;L;;;;;N;;;;; +AA0C;CHAM LETTER CHA;Lo;0;L;;;;;N;;;;; +AA0D;CHAM LETTER CHHA;Lo;0;L;;;;;N;;;;; +AA0E;CHAM LETTER JA;Lo;0;L;;;;;N;;;;; +AA0F;CHAM LETTER JHA;Lo;0;L;;;;;N;;;;; +AA10;CHAM LETTER NHUE;Lo;0;L;;;;;N;;;;; +AA11;CHAM LETTER NHA;Lo;0;L;;;;;N;;;;; +AA12;CHAM LETTER NHJA;Lo;0;L;;;;;N;;;;; +AA13;CHAM LETTER TA;Lo;0;L;;;;;N;;;;; +AA14;CHAM LETTER THA;Lo;0;L;;;;;N;;;;; +AA15;CHAM LETTER DA;Lo;0;L;;;;;N;;;;; +AA16;CHAM LETTER DHA;Lo;0;L;;;;;N;;;;; +AA17;CHAM LETTER NUE;Lo;0;L;;;;;N;;;;; +AA18;CHAM LETTER NA;Lo;0;L;;;;;N;;;;; +AA19;CHAM LETTER DDA;Lo;0;L;;;;;N;;;;; +AA1A;CHAM LETTER PA;Lo;0;L;;;;;N;;;;; +AA1B;CHAM LETTER PPA;Lo;0;L;;;;;N;;;;; +AA1C;CHAM LETTER PHA;Lo;0;L;;;;;N;;;;; +AA1D;CHAM LETTER BA;Lo;0;L;;;;;N;;;;; +AA1E;CHAM LETTER BHA;Lo;0;L;;;;;N;;;;; +AA1F;CHAM LETTER MUE;Lo;0;L;;;;;N;;;;; +AA20;CHAM LETTER MA;Lo;0;L;;;;;N;;;;; +AA21;CHAM LETTER BBA;Lo;0;L;;;;;N;;;;; +AA22;CHAM LETTER YA;Lo;0;L;;;;;N;;;;; +AA23;CHAM LETTER RA;Lo;0;L;;;;;N;;;;; +AA24;CHAM LETTER LA;Lo;0;L;;;;;N;;;;; +AA25;CHAM LETTER VA;Lo;0;L;;;;;N;;;;; +AA26;CHAM LETTER SSA;Lo;0;L;;;;;N;;;;; +AA27;CHAM LETTER SA;Lo;0;L;;;;;N;;;;; +AA28;CHAM LETTER HA;Lo;0;L;;;;;N;;;;; +AA29;CHAM VOWEL SIGN AA;Mn;0;NSM;;;;;N;;;;; +AA2A;CHAM VOWEL SIGN I;Mn;0;NSM;;;;;N;;;;; +AA2B;CHAM VOWEL SIGN II;Mn;0;NSM;;;;;N;;;;; +AA2C;CHAM VOWEL SIGN EI;Mn;0;NSM;;;;;N;;;;; +AA2D;CHAM VOWEL SIGN U;Mn;0;NSM;;;;;N;;;;; +AA2E;CHAM VOWEL SIGN OE;Mn;0;NSM;;;;;N;;;;; +AA2F;CHAM VOWEL SIGN O;Mc;0;L;;;;;N;;;;; +AA30;CHAM VOWEL SIGN AI;Mc;0;L;;;;;N;;;;; +AA31;CHAM VOWEL SIGN AU;Mn;0;NSM;;;;;N;;;;; +AA32;CHAM VOWEL SIGN UE;Mn;0;NSM;;;;;N;;;;; +AA33;CHAM CONSONANT SIGN YA;Mc;0;L;;;;;N;;;;; +AA34;CHAM CONSONANT SIGN RA;Mc;0;L;;;;;N;;;;; +AA35;CHAM CONSONANT SIGN LA;Mn;0;NSM;;;;;N;;;;; +AA36;CHAM CONSONANT SIGN WA;Mn;0;NSM;;;;;N;;;;; +AA40;CHAM LETTER FINAL K;Lo;0;L;;;;;N;;;;; +AA41;CHAM LETTER FINAL G;Lo;0;L;;;;;N;;;;; +AA42;CHAM LETTER FINAL NG;Lo;0;L;;;;;N;;;;; +AA43;CHAM CONSONANT SIGN FINAL NG;Mn;0;NSM;;;;;N;;;;; +AA44;CHAM LETTER FINAL CH;Lo;0;L;;;;;N;;;;; +AA45;CHAM LETTER FINAL T;Lo;0;L;;;;;N;;;;; +AA46;CHAM LETTER FINAL N;Lo;0;L;;;;;N;;;;; +AA47;CHAM LETTER FINAL P;Lo;0;L;;;;;N;;;;; +AA48;CHAM LETTER FINAL Y;Lo;0;L;;;;;N;;;;; +AA49;CHAM LETTER FINAL R;Lo;0;L;;;;;N;;;;; +AA4A;CHAM LETTER FINAL L;Lo;0;L;;;;;N;;;;; +AA4B;CHAM LETTER FINAL SS;Lo;0;L;;;;;N;;;;; +AA4C;CHAM CONSONANT SIGN FINAL M;Mn;0;NSM;;;;;N;;;;; +AA4D;CHAM CONSONANT SIGN FINAL H;Mc;0;L;;;;;N;;;;; +AA50;CHAM DIGIT ZERO;Nd;0;L;;0;0;0;N;;;;; +AA51;CHAM DIGIT ONE;Nd;0;L;;1;1;1;N;;;;; +AA52;CHAM DIGIT TWO;Nd;0;L;;2;2;2;N;;;;; +AA53;CHAM DIGIT THREE;Nd;0;L;;3;3;3;N;;;;; +AA54;CHAM DIGIT FOUR;Nd;0;L;;4;4;4;N;;;;; +AA55;CHAM DIGIT FIVE;Nd;0;L;;5;5;5;N;;;;; +AA56;CHAM DIGIT SIX;Nd;0;L;;6;6;6;N;;;;; +AA57;CHAM DIGIT SEVEN;Nd;0;L;;7;7;7;N;;;;; +AA58;CHAM DIGIT EIGHT;Nd;0;L;;8;8;8;N;;;;; +AA59;CHAM DIGIT NINE;Nd;0;L;;9;9;9;N;;;;; +AA5C;CHAM PUNCTUATION SPIRAL;Po;0;L;;;;;N;;;;; +AA5D;CHAM PUNCTUATION DANDA;Po;0;L;;;;;N;;;;; +AA5E;CHAM PUNCTUATION DOUBLE DANDA;Po;0;L;;;;;N;;;;; +AA5F;CHAM PUNCTUATION TRIPLE DANDA;Po;0;L;;;;;N;;;;; AC00;<Hangul Syllable, First>;Lo;0;L;;;;;N;;;;; D7A3;<Hangul Syllable, Last>;Lo;0;L;;;;;N;;;;; D800;<Non Private Use High Surrogate, First>;Cs;0;L;;;;;N;;;;; @@ -10729,7 +13247,7 @@ F967;CJK COMPATIBILITY IDEOGRAPH-F967;Lo;0;L;4E0D;;;;N;;;;; F968;CJK COMPATIBILITY IDEOGRAPH-F968;Lo;0;L;6CCC;;;;N;;;;; F969;CJK COMPATIBILITY IDEOGRAPH-F969;Lo;0;L;6578;;;;N;;;;; F96A;CJK COMPATIBILITY IDEOGRAPH-F96A;Lo;0;L;7D22;;;;N;;;;; -F96B;CJK COMPATIBILITY IDEOGRAPH-F96B;Lo;0;L;53C3;;;;N;;;;; +F96B;CJK COMPATIBILITY IDEOGRAPH-F96B;Lo;0;L;53C3;;;3;N;;;;; F96C;CJK COMPATIBILITY IDEOGRAPH-F96C;Lo;0;L;585E;;;;N;;;;; F96D;CJK COMPATIBILITY IDEOGRAPH-F96D;Lo;0;L;7701;;;;N;;;;; F96E;CJK COMPATIBILITY IDEOGRAPH-F96E;Lo;0;L;8449;;;;N;;;;; @@ -10737,12 +13255,12 @@ F96F;CJK COMPATIBILITY IDEOGRAPH-F96F;Lo;0;L;8AAA;;;;N;;;;; F970;CJK COMPATIBILITY IDEOGRAPH-F970;Lo;0;L;6BBA;;;;N;;;;; F971;CJK COMPATIBILITY IDEOGRAPH-F971;Lo;0;L;8FB0;;;;N;;;;; F972;CJK COMPATIBILITY IDEOGRAPH-F972;Lo;0;L;6C88;;;;N;;;;; -F973;CJK COMPATIBILITY IDEOGRAPH-F973;Lo;0;L;62FE;;;;N;;;;; +F973;CJK COMPATIBILITY IDEOGRAPH-F973;Lo;0;L;62FE;;;10;N;;;;; F974;CJK COMPATIBILITY IDEOGRAPH-F974;Lo;0;L;82E5;;;;N;;;;; F975;CJK COMPATIBILITY IDEOGRAPH-F975;Lo;0;L;63A0;;;;N;;;;; F976;CJK COMPATIBILITY IDEOGRAPH-F976;Lo;0;L;7565;;;;N;;;;; F977;CJK COMPATIBILITY IDEOGRAPH-F977;Lo;0;L;4EAE;;;;N;;;;; -F978;CJK COMPATIBILITY IDEOGRAPH-F978;Lo;0;L;5169;;;;N;;;;; +F978;CJK COMPATIBILITY IDEOGRAPH-F978;Lo;0;L;5169;;;2;N;;;;; F979;CJK COMPATIBILITY IDEOGRAPH-F979;Lo;0;L;51C9;;;;N;;;;; F97A;CJK COMPATIBILITY IDEOGRAPH-F97A;Lo;0;L;6881;;;;N;;;;; F97B;CJK COMPATIBILITY IDEOGRAPH-F97B;Lo;0;L;7CE7;;;;N;;;;; @@ -10800,7 +13318,7 @@ F9AE;CJK COMPATIBILITY IDEOGRAPH-F9AE;Lo;0;L;7469;;;;N;;;;; F9AF;CJK COMPATIBILITY IDEOGRAPH-F9AF;Lo;0;L;7F9A;;;;N;;;;; F9B0;CJK COMPATIBILITY IDEOGRAPH-F9B0;Lo;0;L;8046;;;;N;;;;; F9B1;CJK COMPATIBILITY IDEOGRAPH-F9B1;Lo;0;L;9234;;;;N;;;;; -F9B2;CJK COMPATIBILITY IDEOGRAPH-F9B2;Lo;0;L;96F6;;;;N;;;;; +F9B2;CJK COMPATIBILITY IDEOGRAPH-F9B2;Lo;0;L;96F6;;;0;N;;;;; F9B3;CJK COMPATIBILITY IDEOGRAPH-F9B3;Lo;0;L;9748;;;;N;;;;; F9B4;CJK COMPATIBILITY IDEOGRAPH-F9B4;Lo;0;L;9818;;;;N;;;;; F9B5;CJK COMPATIBILITY IDEOGRAPH-F9B5;Lo;0;L;4F8B;;;;N;;;;; @@ -10831,9 +13349,9 @@ F9CD;CJK COMPATIBILITY IDEOGRAPH-F9CD;Lo;0;L;7559;;;;N;;;;; F9CE;CJK COMPATIBILITY IDEOGRAPH-F9CE;Lo;0;L;786B;;;;N;;;;; F9CF;CJK COMPATIBILITY IDEOGRAPH-F9CF;Lo;0;L;7D10;;;;N;;;;; F9D0;CJK COMPATIBILITY IDEOGRAPH-F9D0;Lo;0;L;985E;;;;N;;;;; -F9D1;CJK COMPATIBILITY IDEOGRAPH-F9D1;Lo;0;L;516D;;;;N;;;;; +F9D1;CJK COMPATIBILITY IDEOGRAPH-F9D1;Lo;0;L;516D;;;6;N;;;;; F9D2;CJK COMPATIBILITY IDEOGRAPH-F9D2;Lo;0;L;622E;;;;N;;;;; -F9D3;CJK COMPATIBILITY IDEOGRAPH-F9D3;Lo;0;L;9678;;;;N;;;;; +F9D3;CJK COMPATIBILITY IDEOGRAPH-F9D3;Lo;0;L;9678;;;6;N;;;;; F9D4;CJK COMPATIBILITY IDEOGRAPH-F9D4;Lo;0;L;502B;;;;N;;;;; F9D5;CJK COMPATIBILITY IDEOGRAPH-F9D5;Lo;0;L;5D19;;;;N;;;;; F9D6;CJK COMPATIBILITY IDEOGRAPH-F9D6;Lo;0;L;6DEA;;;;N;;;;; @@ -10875,7 +13393,7 @@ F9F9;CJK COMPATIBILITY IDEOGRAPH-F9F9;Lo;0;L;7C92;;;;N;;;;; F9FA;CJK COMPATIBILITY IDEOGRAPH-F9FA;Lo;0;L;72C0;;;;N;;;;; F9FB;CJK COMPATIBILITY IDEOGRAPH-F9FB;Lo;0;L;7099;;;;N;;;;; F9FC;CJK COMPATIBILITY IDEOGRAPH-F9FC;Lo;0;L;8B58;;;;N;;;;; -F9FD;CJK COMPATIBILITY IDEOGRAPH-F9FD;Lo;0;L;4EC0;;;;N;;;;; +F9FD;CJK COMPATIBILITY IDEOGRAPH-F9FD;Lo;0;L;4EC0;;;10;N;;;;; F9FE;CJK COMPATIBILITY IDEOGRAPH-F9FE;Lo;0;L;8336;;;;N;;;;; F9FF;CJK COMPATIBILITY IDEOGRAPH-F9FF;Lo;0;L;523A;;;;N;;;;; FA00;CJK COMPATIBILITY IDEOGRAPH-FA00;Lo;0;L;5207;;;;N;;;;; @@ -10983,6 +13501,112 @@ FA67;CJK COMPATIBILITY IDEOGRAPH-FA67;Lo;0;L;9038;;;;N;;;;; FA68;CJK COMPATIBILITY IDEOGRAPH-FA68;Lo;0;L;96E3;;;;N;;;;; FA69;CJK COMPATIBILITY IDEOGRAPH-FA69;Lo;0;L;97FF;;;;N;;;;; FA6A;CJK COMPATIBILITY IDEOGRAPH-FA6A;Lo;0;L;983B;;;;N;;;;; +FA70;CJK COMPATIBILITY IDEOGRAPH-FA70;Lo;0;L;4E26;;;;N;;;;; +FA71;CJK COMPATIBILITY IDEOGRAPH-FA71;Lo;0;L;51B5;;;;N;;;;; +FA72;CJK COMPATIBILITY IDEOGRAPH-FA72;Lo;0;L;5168;;;;N;;;;; +FA73;CJK COMPATIBILITY IDEOGRAPH-FA73;Lo;0;L;4F80;;;;N;;;;; +FA74;CJK COMPATIBILITY IDEOGRAPH-FA74;Lo;0;L;5145;;;;N;;;;; +FA75;CJK COMPATIBILITY IDEOGRAPH-FA75;Lo;0;L;5180;;;;N;;;;; +FA76;CJK COMPATIBILITY IDEOGRAPH-FA76;Lo;0;L;52C7;;;;N;;;;; +FA77;CJK COMPATIBILITY IDEOGRAPH-FA77;Lo;0;L;52FA;;;;N;;;;; +FA78;CJK COMPATIBILITY IDEOGRAPH-FA78;Lo;0;L;559D;;;;N;;;;; +FA79;CJK COMPATIBILITY IDEOGRAPH-FA79;Lo;0;L;5555;;;;N;;;;; +FA7A;CJK COMPATIBILITY IDEOGRAPH-FA7A;Lo;0;L;5599;;;;N;;;;; +FA7B;CJK COMPATIBILITY IDEOGRAPH-FA7B;Lo;0;L;55E2;;;;N;;;;; +FA7C;CJK COMPATIBILITY IDEOGRAPH-FA7C;Lo;0;L;585A;;;;N;;;;; +FA7D;CJK COMPATIBILITY IDEOGRAPH-FA7D;Lo;0;L;58B3;;;;N;;;;; +FA7E;CJK COMPATIBILITY IDEOGRAPH-FA7E;Lo;0;L;5944;;;;N;;;;; +FA7F;CJK COMPATIBILITY IDEOGRAPH-FA7F;Lo;0;L;5954;;;;N;;;;; +FA80;CJK COMPATIBILITY IDEOGRAPH-FA80;Lo;0;L;5A62;;;;N;;;;; +FA81;CJK COMPATIBILITY IDEOGRAPH-FA81;Lo;0;L;5B28;;;;N;;;;; +FA82;CJK COMPATIBILITY IDEOGRAPH-FA82;Lo;0;L;5ED2;;;;N;;;;; +FA83;CJK COMPATIBILITY IDEOGRAPH-FA83;Lo;0;L;5ED9;;;;N;;;;; +FA84;CJK COMPATIBILITY IDEOGRAPH-FA84;Lo;0;L;5F69;;;;N;;;;; +FA85;CJK COMPATIBILITY IDEOGRAPH-FA85;Lo;0;L;5FAD;;;;N;;;;; +FA86;CJK COMPATIBILITY IDEOGRAPH-FA86;Lo;0;L;60D8;;;;N;;;;; +FA87;CJK COMPATIBILITY IDEOGRAPH-FA87;Lo;0;L;614E;;;;N;;;;; +FA88;CJK COMPATIBILITY IDEOGRAPH-FA88;Lo;0;L;6108;;;;N;;;;; +FA89;CJK COMPATIBILITY IDEOGRAPH-FA89;Lo;0;L;618E;;;;N;;;;; +FA8A;CJK COMPATIBILITY IDEOGRAPH-FA8A;Lo;0;L;6160;;;;N;;;;; +FA8B;CJK COMPATIBILITY IDEOGRAPH-FA8B;Lo;0;L;61F2;;;;N;;;;; +FA8C;CJK COMPATIBILITY IDEOGRAPH-FA8C;Lo;0;L;6234;;;;N;;;;; +FA8D;CJK COMPATIBILITY IDEOGRAPH-FA8D;Lo;0;L;63C4;;;;N;;;;; +FA8E;CJK COMPATIBILITY IDEOGRAPH-FA8E;Lo;0;L;641C;;;;N;;;;; +FA8F;CJK COMPATIBILITY IDEOGRAPH-FA8F;Lo;0;L;6452;;;;N;;;;; +FA90;CJK COMPATIBILITY IDEOGRAPH-FA90;Lo;0;L;6556;;;;N;;;;; +FA91;CJK COMPATIBILITY IDEOGRAPH-FA91;Lo;0;L;6674;;;;N;;;;; +FA92;CJK COMPATIBILITY IDEOGRAPH-FA92;Lo;0;L;6717;;;;N;;;;; +FA93;CJK COMPATIBILITY IDEOGRAPH-FA93;Lo;0;L;671B;;;;N;;;;; +FA94;CJK COMPATIBILITY IDEOGRAPH-FA94;Lo;0;L;6756;;;;N;;;;; +FA95;CJK COMPATIBILITY IDEOGRAPH-FA95;Lo;0;L;6B79;;;;N;;;;; +FA96;CJK COMPATIBILITY IDEOGRAPH-FA96;Lo;0;L;6BBA;;;;N;;;;; +FA97;CJK COMPATIBILITY IDEOGRAPH-FA97;Lo;0;L;6D41;;;;N;;;;; +FA98;CJK COMPATIBILITY IDEOGRAPH-FA98;Lo;0;L;6EDB;;;;N;;;;; +FA99;CJK COMPATIBILITY IDEOGRAPH-FA99;Lo;0;L;6ECB;;;;N;;;;; +FA9A;CJK COMPATIBILITY IDEOGRAPH-FA9A;Lo;0;L;6F22;;;;N;;;;; +FA9B;CJK COMPATIBILITY IDEOGRAPH-FA9B;Lo;0;L;701E;;;;N;;;;; +FA9C;CJK COMPATIBILITY IDEOGRAPH-FA9C;Lo;0;L;716E;;;;N;;;;; +FA9D;CJK COMPATIBILITY IDEOGRAPH-FA9D;Lo;0;L;77A7;;;;N;;;;; +FA9E;CJK COMPATIBILITY IDEOGRAPH-FA9E;Lo;0;L;7235;;;;N;;;;; +FA9F;CJK COMPATIBILITY IDEOGRAPH-FA9F;Lo;0;L;72AF;;;;N;;;;; +FAA0;CJK COMPATIBILITY IDEOGRAPH-FAA0;Lo;0;L;732A;;;;N;;;;; +FAA1;CJK COMPATIBILITY IDEOGRAPH-FAA1;Lo;0;L;7471;;;;N;;;;; +FAA2;CJK COMPATIBILITY IDEOGRAPH-FAA2;Lo;0;L;7506;;;;N;;;;; +FAA3;CJK COMPATIBILITY IDEOGRAPH-FAA3;Lo;0;L;753B;;;;N;;;;; +FAA4;CJK COMPATIBILITY IDEOGRAPH-FAA4;Lo;0;L;761D;;;;N;;;;; +FAA5;CJK COMPATIBILITY IDEOGRAPH-FAA5;Lo;0;L;761F;;;;N;;;;; +FAA6;CJK COMPATIBILITY IDEOGRAPH-FAA6;Lo;0;L;76CA;;;;N;;;;; +FAA7;CJK COMPATIBILITY IDEOGRAPH-FAA7;Lo;0;L;76DB;;;;N;;;;; +FAA8;CJK COMPATIBILITY IDEOGRAPH-FAA8;Lo;0;L;76F4;;;;N;;;;; +FAA9;CJK COMPATIBILITY IDEOGRAPH-FAA9;Lo;0;L;774A;;;;N;;;;; +FAAA;CJK COMPATIBILITY IDEOGRAPH-FAAA;Lo;0;L;7740;;;;N;;;;; +FAAB;CJK COMPATIBILITY IDEOGRAPH-FAAB;Lo;0;L;78CC;;;;N;;;;; +FAAC;CJK COMPATIBILITY IDEOGRAPH-FAAC;Lo;0;L;7AB1;;;;N;;;;; +FAAD;CJK COMPATIBILITY IDEOGRAPH-FAAD;Lo;0;L;7BC0;;;;N;;;;; +FAAE;CJK COMPATIBILITY IDEOGRAPH-FAAE;Lo;0;L;7C7B;;;;N;;;;; +FAAF;CJK COMPATIBILITY IDEOGRAPH-FAAF;Lo;0;L;7D5B;;;;N;;;;; +FAB0;CJK COMPATIBILITY IDEOGRAPH-FAB0;Lo;0;L;7DF4;;;;N;;;;; +FAB1;CJK COMPATIBILITY IDEOGRAPH-FAB1;Lo;0;L;7F3E;;;;N;;;;; +FAB2;CJK COMPATIBILITY IDEOGRAPH-FAB2;Lo;0;L;8005;;;;N;;;;; +FAB3;CJK COMPATIBILITY IDEOGRAPH-FAB3;Lo;0;L;8352;;;;N;;;;; +FAB4;CJK COMPATIBILITY IDEOGRAPH-FAB4;Lo;0;L;83EF;;;;N;;;;; +FAB5;CJK COMPATIBILITY IDEOGRAPH-FAB5;Lo;0;L;8779;;;;N;;;;; +FAB6;CJK COMPATIBILITY IDEOGRAPH-FAB6;Lo;0;L;8941;;;;N;;;;; +FAB7;CJK COMPATIBILITY IDEOGRAPH-FAB7;Lo;0;L;8986;;;;N;;;;; +FAB8;CJK COMPATIBILITY IDEOGRAPH-FAB8;Lo;0;L;8996;;;;N;;;;; +FAB9;CJK COMPATIBILITY IDEOGRAPH-FAB9;Lo;0;L;8ABF;;;;N;;;;; +FABA;CJK COMPATIBILITY IDEOGRAPH-FABA;Lo;0;L;8AF8;;;;N;;;;; +FABB;CJK COMPATIBILITY IDEOGRAPH-FABB;Lo;0;L;8ACB;;;;N;;;;; +FABC;CJK COMPATIBILITY IDEOGRAPH-FABC;Lo;0;L;8B01;;;;N;;;;; +FABD;CJK COMPATIBILITY IDEOGRAPH-FABD;Lo;0;L;8AFE;;;;N;;;;; +FABE;CJK COMPATIBILITY IDEOGRAPH-FABE;Lo;0;L;8AED;;;;N;;;;; +FABF;CJK COMPATIBILITY IDEOGRAPH-FABF;Lo;0;L;8B39;;;;N;;;;; +FAC0;CJK COMPATIBILITY IDEOGRAPH-FAC0;Lo;0;L;8B8A;;;;N;;;;; +FAC1;CJK COMPATIBILITY IDEOGRAPH-FAC1;Lo;0;L;8D08;;;;N;;;;; +FAC2;CJK COMPATIBILITY IDEOGRAPH-FAC2;Lo;0;L;8F38;;;;N;;;;; +FAC3;CJK COMPATIBILITY IDEOGRAPH-FAC3;Lo;0;L;9072;;;;N;;;;; +FAC4;CJK COMPATIBILITY IDEOGRAPH-FAC4;Lo;0;L;9199;;;;N;;;;; +FAC5;CJK COMPATIBILITY IDEOGRAPH-FAC5;Lo;0;L;9276;;;;N;;;;; +FAC6;CJK COMPATIBILITY IDEOGRAPH-FAC6;Lo;0;L;967C;;;;N;;;;; +FAC7;CJK COMPATIBILITY IDEOGRAPH-FAC7;Lo;0;L;96E3;;;;N;;;;; +FAC8;CJK COMPATIBILITY IDEOGRAPH-FAC8;Lo;0;L;9756;;;;N;;;;; +FAC9;CJK COMPATIBILITY IDEOGRAPH-FAC9;Lo;0;L;97DB;;;;N;;;;; +FACA;CJK COMPATIBILITY IDEOGRAPH-FACA;Lo;0;L;97FF;;;;N;;;;; +FACB;CJK COMPATIBILITY IDEOGRAPH-FACB;Lo;0;L;980B;;;;N;;;;; +FACC;CJK COMPATIBILITY IDEOGRAPH-FACC;Lo;0;L;983B;;;;N;;;;; +FACD;CJK COMPATIBILITY IDEOGRAPH-FACD;Lo;0;L;9B12;;;;N;;;;; +FACE;CJK COMPATIBILITY IDEOGRAPH-FACE;Lo;0;L;9F9C;;;;N;;;;; +FACF;CJK COMPATIBILITY IDEOGRAPH-FACF;Lo;0;L;2284A;;;;N;;;;; +FAD0;CJK COMPATIBILITY IDEOGRAPH-FAD0;Lo;0;L;22844;;;;N;;;;; +FAD1;CJK COMPATIBILITY IDEOGRAPH-FAD1;Lo;0;L;233D5;;;;N;;;;; +FAD2;CJK COMPATIBILITY IDEOGRAPH-FAD2;Lo;0;L;3B9D;;;;N;;;;; +FAD3;CJK COMPATIBILITY IDEOGRAPH-FAD3;Lo;0;L;4018;;;;N;;;;; +FAD4;CJK COMPATIBILITY IDEOGRAPH-FAD4;Lo;0;L;4039;;;;N;;;;; +FAD5;CJK COMPATIBILITY IDEOGRAPH-FAD5;Lo;0;L;25249;;;;N;;;;; +FAD6;CJK COMPATIBILITY IDEOGRAPH-FAD6;Lo;0;L;25CD0;;;;N;;;;; +FAD7;CJK COMPATIBILITY IDEOGRAPH-FAD7;Lo;0;L;27ED3;;;;N;;;;; +FAD8;CJK COMPATIBILITY IDEOGRAPH-FAD8;Lo;0;L;9F43;;;;N;;;;; +FAD9;CJK COMPATIBILITY IDEOGRAPH-FAD9;Lo;0;L;9F8E;;;;N;;;;; FB00;LATIN SMALL LIGATURE FF;Ll;0;L;<compat> 0066 0066;;;;N;;;;; FB01;LATIN SMALL LIGATURE FI;Ll;0;L;<compat> 0066 0069;;;;N;;;;; FB02;LATIN SMALL LIGATURE FL;Ll;0;L;<compat> 0066 006C;;;;N;;;;; @@ -11007,7 +13631,7 @@ FB25;HEBREW LETTER WIDE LAMED;Lo;0;R;<font> 05DC;;;;N;;;;; FB26;HEBREW LETTER WIDE FINAL MEM;Lo;0;R;<font> 05DD;;;;N;;;;; FB27;HEBREW LETTER WIDE RESH;Lo;0;R;<font> 05E8;;;;N;;;;; FB28;HEBREW LETTER WIDE TAV;Lo;0;R;<font> 05EA;;;;N;;;;; -FB29;HEBREW LETTER ALTERNATIVE PLUS SIGN;Sm;0;ET;<font> 002B;;;;N;;;;; +FB29;HEBREW LETTER ALTERNATIVE PLUS SIGN;Sm;0;ES;<font> 002B;;;;N;;;;; FB2A;HEBREW LETTER SHIN WITH SHIN DOT;Lo;0;R;05E9 05C1;;;;N;;;;; FB2B;HEBREW LETTER SHIN WITH SIN DOT;Lo;0;R;05E9 05C2;;;;N;;;;; FB2C;HEBREW LETTER SHIN WITH DAGESH AND SHIN DOT;Lo;0;R;FB49 05C1;;;;N;;;;; @@ -11652,10 +14276,23 @@ FE0C;VARIATION SELECTOR-13;Mn;0;NSM;;;;;N;;;;; FE0D;VARIATION SELECTOR-14;Mn;0;NSM;;;;;N;;;;; FE0E;VARIATION SELECTOR-15;Mn;0;NSM;;;;;N;;;;; FE0F;VARIATION SELECTOR-16;Mn;0;NSM;;;;;N;;;;; +FE10;PRESENTATION FORM FOR VERTICAL COMMA;Po;0;ON;<vertical> 002C;;;;N;;;;; +FE11;PRESENTATION FORM FOR VERTICAL IDEOGRAPHIC COMMA;Po;0;ON;<vertical> 3001;;;;N;;;;; +FE12;PRESENTATION FORM FOR VERTICAL IDEOGRAPHIC FULL STOP;Po;0;ON;<vertical> 3002;;;;N;;;;; +FE13;PRESENTATION FORM FOR VERTICAL COLON;Po;0;ON;<vertical> 003A;;;;N;;;;; +FE14;PRESENTATION FORM FOR VERTICAL SEMICOLON;Po;0;ON;<vertical> 003B;;;;N;;;;; +FE15;PRESENTATION FORM FOR VERTICAL EXCLAMATION MARK;Po;0;ON;<vertical> 0021;;;;N;;;;; +FE16;PRESENTATION FORM FOR VERTICAL QUESTION MARK;Po;0;ON;<vertical> 003F;;;;N;;;;; +FE17;PRESENTATION FORM FOR VERTICAL LEFT WHITE LENTICULAR BRACKET;Ps;0;ON;<vertical> 3016;;;;N;;;;; +FE18;PRESENTATION FORM FOR VERTICAL RIGHT WHITE LENTICULAR BRAKCET;Pe;0;ON;<vertical> 3017;;;;N;;;;; +FE19;PRESENTATION FORM FOR VERTICAL HORIZONTAL ELLIPSIS;Po;0;ON;<vertical> 2026;;;;N;;;;; FE20;COMBINING LIGATURE LEFT HALF;Mn;230;NSM;;;;;N;;;;; FE21;COMBINING LIGATURE RIGHT HALF;Mn;230;NSM;;;;;N;;;;; FE22;COMBINING DOUBLE TILDE LEFT HALF;Mn;230;NSM;;;;;N;;;;; FE23;COMBINING DOUBLE TILDE RIGHT HALF;Mn;230;NSM;;;;;N;;;;; +FE24;COMBINING MACRON LEFT HALF;Mn;230;NSM;;;;;N;;;;; +FE25;COMBINING MACRON RIGHT HALF;Mn;230;NSM;;;;;N;;;;; +FE26;COMBINING CONJOINING MACRON;Mn;230;NSM;;;;;N;;;;; FE30;PRESENTATION FORM FOR VERTICAL TWO DOT LEADER;Po;0;ON;<vertical> 2025;;;;N;GLYPH FOR VERTICAL TWO DOT LEADER;;;; FE31;PRESENTATION FORM FOR VERTICAL EM DASH;Pd;0;ON;<vertical> 2014;;;;N;GLYPH FOR VERTICAL EM DASH;;;; FE32;PRESENTATION FORM FOR VERTICAL EN DASH;Pd;0;ON;<vertical> 2013;;;;N;GLYPH FOR VERTICAL EN DASH;;;; @@ -11696,19 +14333,19 @@ FE55;SMALL COLON;Po;0;CS;<small> 003A;;;;N;;;;; FE56;SMALL QUESTION MARK;Po;0;ON;<small> 003F;;;;N;;;;; FE57;SMALL EXCLAMATION MARK;Po;0;ON;<small> 0021;;;;N;;;;; FE58;SMALL EM DASH;Pd;0;ON;<small> 2014;;;;N;;;;; -FE59;SMALL LEFT PARENTHESIS;Ps;0;ON;<small> 0028;;;;N;SMALL OPENING PARENTHESIS;;;; -FE5A;SMALL RIGHT PARENTHESIS;Pe;0;ON;<small> 0029;;;;N;SMALL CLOSING PARENTHESIS;;;; -FE5B;SMALL LEFT CURLY BRACKET;Ps;0;ON;<small> 007B;;;;N;SMALL OPENING CURLY BRACKET;;;; -FE5C;SMALL RIGHT CURLY BRACKET;Pe;0;ON;<small> 007D;;;;N;SMALL CLOSING CURLY BRACKET;;;; -FE5D;SMALL LEFT TORTOISE SHELL BRACKET;Ps;0;ON;<small> 3014;;;;N;SMALL OPENING TORTOISE SHELL BRACKET;;;; -FE5E;SMALL RIGHT TORTOISE SHELL BRACKET;Pe;0;ON;<small> 3015;;;;N;SMALL CLOSING TORTOISE SHELL BRACKET;;;; +FE59;SMALL LEFT PARENTHESIS;Ps;0;ON;<small> 0028;;;;Y;SMALL OPENING PARENTHESIS;;;; +FE5A;SMALL RIGHT PARENTHESIS;Pe;0;ON;<small> 0029;;;;Y;SMALL CLOSING PARENTHESIS;;;; +FE5B;SMALL LEFT CURLY BRACKET;Ps;0;ON;<small> 007B;;;;Y;SMALL OPENING CURLY BRACKET;;;; +FE5C;SMALL RIGHT CURLY BRACKET;Pe;0;ON;<small> 007D;;;;Y;SMALL CLOSING CURLY BRACKET;;;; +FE5D;SMALL LEFT TORTOISE SHELL BRACKET;Ps;0;ON;<small> 3014;;;;Y;SMALL OPENING TORTOISE SHELL BRACKET;;;; +FE5E;SMALL RIGHT TORTOISE SHELL BRACKET;Pe;0;ON;<small> 3015;;;;Y;SMALL CLOSING TORTOISE SHELL BRACKET;;;; FE5F;SMALL NUMBER SIGN;Po;0;ET;<small> 0023;;;;N;;;;; FE60;SMALL AMPERSAND;Po;0;ON;<small> 0026;;;;N;;;;; FE61;SMALL ASTERISK;Po;0;ON;<small> 002A;;;;N;;;;; -FE62;SMALL PLUS SIGN;Sm;0;ET;<small> 002B;;;;N;;;;; -FE63;SMALL HYPHEN-MINUS;Pd;0;ET;<small> 002D;;;;N;;;;; -FE64;SMALL LESS-THAN SIGN;Sm;0;ON;<small> 003C;;;;N;;;;; -FE65;SMALL GREATER-THAN SIGN;Sm;0;ON;<small> 003E;;;;N;;;;; +FE62;SMALL PLUS SIGN;Sm;0;ES;<small> 002B;;;;N;;;;; +FE63;SMALL HYPHEN-MINUS;Pd;0;ES;<small> 002D;;;;N;;;;; +FE64;SMALL LESS-THAN SIGN;Sm;0;ON;<small> 003C;;;;Y;;;;; +FE65;SMALL GREATER-THAN SIGN;Sm;0;ON;<small> 003E;;;;Y;;;;; FE66;SMALL EQUALS SIGN;Sm;0;ON;<small> 003D;;;;N;;;;; FE68;SMALL REVERSE SOLIDUS;Po;0;ON;<small> 005C;;;;N;SMALL BACKSLASH;;;; FE69;SMALL DOLLAR SIGN;Sc;0;ET;<small> 0024;;;;N;;;;; @@ -11865,11 +14502,11 @@ FF07;FULLWIDTH APOSTROPHE;Po;0;ON;<wide> 0027;;;;N;;;;; FF08;FULLWIDTH LEFT PARENTHESIS;Ps;0;ON;<wide> 0028;;;;Y;FULLWIDTH OPENING PARENTHESIS;;;; FF09;FULLWIDTH RIGHT PARENTHESIS;Pe;0;ON;<wide> 0029;;;;Y;FULLWIDTH CLOSING PARENTHESIS;;;; FF0A;FULLWIDTH ASTERISK;Po;0;ON;<wide> 002A;;;;N;;;;; -FF0B;FULLWIDTH PLUS SIGN;Sm;0;ET;<wide> 002B;;;;N;;;;; +FF0B;FULLWIDTH PLUS SIGN;Sm;0;ES;<wide> 002B;;;;N;;;;; FF0C;FULLWIDTH COMMA;Po;0;CS;<wide> 002C;;;;N;;;;; -FF0D;FULLWIDTH HYPHEN-MINUS;Pd;0;ET;<wide> 002D;;;;N;;;;; +FF0D;FULLWIDTH HYPHEN-MINUS;Pd;0;ES;<wide> 002D;;;;N;;;;; FF0E;FULLWIDTH FULL STOP;Po;0;CS;<wide> 002E;;;;N;FULLWIDTH PERIOD;;;; -FF0F;FULLWIDTH SOLIDUS;Po;0;ES;<wide> 002F;;;;N;FULLWIDTH SLASH;;;; +FF0F;FULLWIDTH SOLIDUS;Po;0;CS;<wide> 002F;;;;N;FULLWIDTH SLASH;;;; FF10;FULLWIDTH DIGIT ZERO;Nd;0;EN;<wide> 0030;0;0;0;N;;;;; FF11;FULLWIDTH DIGIT ONE;Nd;0;EN;<wide> 0031;1;1;1;N;;;;; FF12;FULLWIDTH DIGIT TWO;Nd;0;EN;<wide> 0032;2;2;2;N;;;;; @@ -11955,7 +14592,7 @@ FF61;HALFWIDTH IDEOGRAPHIC FULL STOP;Po;0;ON;<narrow> 3002;;;;N;HALFWIDTH IDEOGR FF62;HALFWIDTH LEFT CORNER BRACKET;Ps;0;ON;<narrow> 300C;;;;Y;HALFWIDTH OPENING CORNER BRACKET;;;; FF63;HALFWIDTH RIGHT CORNER BRACKET;Pe;0;ON;<narrow> 300D;;;;Y;HALFWIDTH CLOSING CORNER BRACKET;;;; FF64;HALFWIDTH IDEOGRAPHIC COMMA;Po;0;ON;<narrow> 3001;;;;N;;;;; -FF65;HALFWIDTH KATAKANA MIDDLE DOT;Pc;0;ON;<narrow> 30FB;;;;N;;;;; +FF65;HALFWIDTH KATAKANA MIDDLE DOT;Po;0;ON;<narrow> 30FB;;;;N;;;;; FF66;HALFWIDTH KATAKANA LETTER WO;Lo;0;L;<narrow> 30F2;;;;N;;;;; FF67;HALFWIDTH KATAKANA LETTER SMALL A;Lo;0;L;<narrow> 30A1;;;;N;;;;; FF68;HALFWIDTH KATAKANA LETTER SMALL I;Lo;0;L;<narrow> 30A3;;;;N;;;;; @@ -12080,9 +14717,9 @@ FFEB;HALFWIDTH RIGHTWARDS ARROW;Sm;0;ON;<narrow> 2192;;;;N;;;;; FFEC;HALFWIDTH DOWNWARDS ARROW;Sm;0;ON;<narrow> 2193;;;;N;;;;; FFED;HALFWIDTH BLACK SQUARE;So;0;ON;<narrow> 25A0;;;;N;;;;; FFEE;HALFWIDTH WHITE CIRCLE;So;0;ON;<narrow> 25CB;;;;N;;;;; -FFF9;INTERLINEAR ANNOTATION ANCHOR;Cf;0;BN;;;;;N;;;;; -FFFA;INTERLINEAR ANNOTATION SEPARATOR;Cf;0;BN;;;;;N;;;;; -FFFB;INTERLINEAR ANNOTATION TERMINATOR;Cf;0;BN;;;;;N;;;;; +FFF9;INTERLINEAR ANNOTATION ANCHOR;Cf;0;ON;;;;;N;;;;; +FFFA;INTERLINEAR ANNOTATION SEPARATOR;Cf;0;ON;;;;;N;;;;; +FFFB;INTERLINEAR ANNOTATION TERMINATOR;Cf;0;ON;;;;;N;;;;; FFFC;OBJECT REPLACEMENT CHARACTER;So;0;ON;;;;;N;;;;; FFFD;REPLACEMENT CHARACTER;So;0;ON;;;;;N;;;;; 10000;LINEAR B SYLLABLE B008 A;Lo;0;L;;;;;N;;;;; @@ -12353,6 +14990,217 @@ FFFD;REPLACEMENT CHARACTER;So;0;ON;;;;;N;;;;; 1013D;AEGEAN LIQUID MEASURE FIRST SUBUNIT;So;0;L;;;;;N;;;;; 1013E;AEGEAN MEASURE SECOND SUBUNIT;So;0;L;;;;;N;;;;; 1013F;AEGEAN MEASURE THIRD SUBUNIT;So;0;L;;;;;N;;;;; +10140;GREEK ACROPHONIC ATTIC ONE QUARTER;Nl;0;ON;;;;1/4;N;;;;; +10141;GREEK ACROPHONIC ATTIC ONE HALF;Nl;0;ON;;;;1/2;N;;;;; +10142;GREEK ACROPHONIC ATTIC ONE DRACHMA;Nl;0;ON;;;;1;N;;;;; +10143;GREEK ACROPHONIC ATTIC FIVE;Nl;0;ON;;;;5;N;;;;; +10144;GREEK ACROPHONIC ATTIC FIFTY;Nl;0;ON;;;;50;N;;;;; +10145;GREEK ACROPHONIC ATTIC FIVE HUNDRED;Nl;0;ON;;;;500;N;;;;; +10146;GREEK ACROPHONIC ATTIC FIVE THOUSAND;Nl;0;ON;;;;5000;N;;;;; +10147;GREEK ACROPHONIC ATTIC FIFTY THOUSAND;Nl;0;ON;;;;50000;N;;;;; +10148;GREEK ACROPHONIC ATTIC FIVE TALENTS;Nl;0;ON;;;;5;N;;;;; +10149;GREEK ACROPHONIC ATTIC TEN TALENTS;Nl;0;ON;;;;10;N;;;;; +1014A;GREEK ACROPHONIC ATTIC FIFTY TALENTS;Nl;0;ON;;;;50;N;;;;; +1014B;GREEK ACROPHONIC ATTIC ONE HUNDRED TALENTS;Nl;0;ON;;;;100;N;;;;; +1014C;GREEK ACROPHONIC ATTIC FIVE HUNDRED TALENTS;Nl;0;ON;;;;500;N;;;;; +1014D;GREEK ACROPHONIC ATTIC ONE THOUSAND TALENTS;Nl;0;ON;;;;1000;N;;;;; +1014E;GREEK ACROPHONIC ATTIC FIVE THOUSAND TALENTS;Nl;0;ON;;;;5000;N;;;;; +1014F;GREEK ACROPHONIC ATTIC FIVE STATERS;Nl;0;ON;;;;5;N;;;;; +10150;GREEK ACROPHONIC ATTIC TEN STATERS;Nl;0;ON;;;;10;N;;;;; +10151;GREEK ACROPHONIC ATTIC FIFTY STATERS;Nl;0;ON;;;;50;N;;;;; +10152;GREEK ACROPHONIC ATTIC ONE HUNDRED STATERS;Nl;0;ON;;;;100;N;;;;; +10153;GREEK ACROPHONIC ATTIC FIVE HUNDRED STATERS;Nl;0;ON;;;;500;N;;;;; +10154;GREEK ACROPHONIC ATTIC ONE THOUSAND STATERS;Nl;0;ON;;;;1000;N;;;;; +10155;GREEK ACROPHONIC ATTIC TEN THOUSAND STATERS;Nl;0;ON;;;;10000;N;;;;; +10156;GREEK ACROPHONIC ATTIC FIFTY THOUSAND STATERS;Nl;0;ON;;;;50000;N;;;;; +10157;GREEK ACROPHONIC ATTIC TEN MNAS;Nl;0;ON;;;;10;N;;;;; +10158;GREEK ACROPHONIC HERAEUM ONE PLETHRON;Nl;0;ON;;;;1;N;;;;; +10159;GREEK ACROPHONIC THESPIAN ONE;Nl;0;ON;;;;1;N;;;;; +1015A;GREEK ACROPHONIC HERMIONIAN ONE;Nl;0;ON;;;;1;N;;;;; +1015B;GREEK ACROPHONIC EPIDAUREAN TWO;Nl;0;ON;;;;2;N;;;;; +1015C;GREEK ACROPHONIC THESPIAN TWO;Nl;0;ON;;;;2;N;;;;; +1015D;GREEK ACROPHONIC CYRENAIC TWO DRACHMAS;Nl;0;ON;;;;2;N;;;;; +1015E;GREEK ACROPHONIC EPIDAUREAN TWO DRACHMAS;Nl;0;ON;;;;2;N;;;;; +1015F;GREEK ACROPHONIC TROEZENIAN FIVE;Nl;0;ON;;;;5;N;;;;; +10160;GREEK ACROPHONIC TROEZENIAN TEN;Nl;0;ON;;;;10;N;;;;; +10161;GREEK ACROPHONIC TROEZENIAN TEN ALTERNATE FORM;Nl;0;ON;;;;10;N;;;;; +10162;GREEK ACROPHONIC HERMIONIAN TEN;Nl;0;ON;;;;10;N;;;;; +10163;GREEK ACROPHONIC MESSENIAN TEN;Nl;0;ON;;;;10;N;;;;; +10164;GREEK ACROPHONIC THESPIAN TEN;Nl;0;ON;;;;10;N;;;;; +10165;GREEK ACROPHONIC THESPIAN THIRTY;Nl;0;ON;;;;30;N;;;;; +10166;GREEK ACROPHONIC TROEZENIAN FIFTY;Nl;0;ON;;;;50;N;;;;; +10167;GREEK ACROPHONIC TROEZENIAN FIFTY ALTERNATE FORM;Nl;0;ON;;;;50;N;;;;; +10168;GREEK ACROPHONIC HERMIONIAN FIFTY;Nl;0;ON;;;;50;N;;;;; +10169;GREEK ACROPHONIC THESPIAN FIFTY;Nl;0;ON;;;;50;N;;;;; +1016A;GREEK ACROPHONIC THESPIAN ONE HUNDRED;Nl;0;ON;;;;100;N;;;;; +1016B;GREEK ACROPHONIC THESPIAN THREE HUNDRED;Nl;0;ON;;;;300;N;;;;; +1016C;GREEK ACROPHONIC EPIDAUREAN FIVE HUNDRED;Nl;0;ON;;;;500;N;;;;; +1016D;GREEK ACROPHONIC TROEZENIAN FIVE HUNDRED;Nl;0;ON;;;;500;N;;;;; +1016E;GREEK ACROPHONIC THESPIAN FIVE HUNDRED;Nl;0;ON;;;;500;N;;;;; +1016F;GREEK ACROPHONIC CARYSTIAN FIVE HUNDRED;Nl;0;ON;;;;500;N;;;;; +10170;GREEK ACROPHONIC NAXIAN FIVE HUNDRED;Nl;0;ON;;;;500;N;;;;; +10171;GREEK ACROPHONIC THESPIAN ONE THOUSAND;Nl;0;ON;;;;1000;N;;;;; +10172;GREEK ACROPHONIC THESPIAN FIVE THOUSAND;Nl;0;ON;;;;5000;N;;;;; +10173;GREEK ACROPHONIC DELPHIC FIVE MNAS;Nl;0;ON;;;;5;N;;;;; +10174;GREEK ACROPHONIC STRATIAN FIFTY MNAS;Nl;0;ON;;;;50;N;;;;; +10175;GREEK ONE HALF SIGN;No;0;ON;;;;1/2;N;;;;; +10176;GREEK ONE HALF SIGN ALTERNATE FORM;No;0;ON;;;;1/2;N;;;;; +10177;GREEK TWO THIRDS SIGN;No;0;ON;;;;2/3;N;;;;; +10178;GREEK THREE QUARTERS SIGN;No;0;ON;;;;3/4;N;;;;; +10179;GREEK YEAR SIGN;So;0;ON;;;;;N;;;;; +1017A;GREEK TALENT SIGN;So;0;ON;;;;;N;;;;; +1017B;GREEK DRACHMA SIGN;So;0;ON;;;;;N;;;;; +1017C;GREEK OBOL SIGN;So;0;ON;;;;;N;;;;; +1017D;GREEK TWO OBOLS SIGN;So;0;ON;;;;;N;;;;; +1017E;GREEK THREE OBOLS SIGN;So;0;ON;;;;;N;;;;; +1017F;GREEK FOUR OBOLS SIGN;So;0;ON;;;;;N;;;;; +10180;GREEK FIVE OBOLS SIGN;So;0;ON;;;;;N;;;;; +10181;GREEK METRETES SIGN;So;0;ON;;;;;N;;;;; +10182;GREEK KYATHOS BASE SIGN;So;0;ON;;;;;N;;;;; +10183;GREEK LITRA SIGN;So;0;ON;;;;;N;;;;; +10184;GREEK OUNKIA SIGN;So;0;ON;;;;;N;;;;; +10185;GREEK XESTES SIGN;So;0;ON;;;;;N;;;;; +10186;GREEK ARTABE SIGN;So;0;ON;;;;;N;;;;; +10187;GREEK AROURA SIGN;So;0;ON;;;;;N;;;;; +10188;GREEK GRAMMA SIGN;So;0;ON;;;;;N;;;;; +10189;GREEK TRYBLION BASE SIGN;So;0;ON;;;;;N;;;;; +1018A;GREEK ZERO SIGN;No;0;ON;;;;0;N;;;;; +10190;ROMAN SEXTANS SIGN;So;0;ON;;;;;N;;;;; +10191;ROMAN UNCIA SIGN;So;0;ON;;;;;N;;;;; +10192;ROMAN SEMUNCIA SIGN;So;0;ON;;;;;N;;;;; +10193;ROMAN SEXTULA SIGN;So;0;ON;;;;;N;;;;; +10194;ROMAN DIMIDIA SEXTULA SIGN;So;0;ON;;;;;N;;;;; +10195;ROMAN SILIQUA SIGN;So;0;ON;;;;;N;;;;; +10196;ROMAN DENARIUS SIGN;So;0;ON;;;;;N;;;;; +10197;ROMAN QUINARIUS SIGN;So;0;ON;;;;;N;;;;; +10198;ROMAN SESTERTIUS SIGN;So;0;ON;;;;;N;;;;; +10199;ROMAN DUPONDIUS SIGN;So;0;ON;;;;;N;;;;; +1019A;ROMAN AS SIGN;So;0;ON;;;;;N;;;;; +1019B;ROMAN CENTURIAL SIGN;So;0;ON;;;;;N;;;;; +101D0;PHAISTOS DISC SIGN PEDESTRIAN;So;0;L;;;;;N;;;;; +101D1;PHAISTOS DISC SIGN PLUMED HEAD;So;0;L;;;;;N;;;;; +101D2;PHAISTOS DISC SIGN TATTOOED HEAD;So;0;L;;;;;N;;;;; +101D3;PHAISTOS DISC SIGN CAPTIVE;So;0;L;;;;;N;;;;; +101D4;PHAISTOS DISC SIGN CHILD;So;0;L;;;;;N;;;;; +101D5;PHAISTOS DISC SIGN WOMAN;So;0;L;;;;;N;;;;; +101D6;PHAISTOS DISC SIGN HELMET;So;0;L;;;;;N;;;;; +101D7;PHAISTOS DISC SIGN GAUNTLET;So;0;L;;;;;N;;;;; +101D8;PHAISTOS DISC SIGN TIARA;So;0;L;;;;;N;;;;; +101D9;PHAISTOS DISC SIGN ARROW;So;0;L;;;;;N;;;;; +101DA;PHAISTOS DISC SIGN BOW;So;0;L;;;;;N;;;;; +101DB;PHAISTOS DISC SIGN SHIELD;So;0;L;;;;;N;;;;; +101DC;PHAISTOS DISC SIGN CLUB;So;0;L;;;;;N;;;;; +101DD;PHAISTOS DISC SIGN MANACLES;So;0;L;;;;;N;;;;; +101DE;PHAISTOS DISC SIGN MATTOCK;So;0;L;;;;;N;;;;; +101DF;PHAISTOS DISC SIGN SAW;So;0;L;;;;;N;;;;; +101E0;PHAISTOS DISC SIGN LID;So;0;L;;;;;N;;;;; +101E1;PHAISTOS DISC SIGN BOOMERANG;So;0;L;;;;;N;;;;; +101E2;PHAISTOS DISC SIGN CARPENTRY PLANE;So;0;L;;;;;N;;;;; +101E3;PHAISTOS DISC SIGN DOLIUM;So;0;L;;;;;N;;;;; +101E4;PHAISTOS DISC SIGN COMB;So;0;L;;;;;N;;;;; +101E5;PHAISTOS DISC SIGN SLING;So;0;L;;;;;N;;;;; +101E6;PHAISTOS DISC SIGN COLUMN;So;0;L;;;;;N;;;;; +101E7;PHAISTOS DISC SIGN BEEHIVE;So;0;L;;;;;N;;;;; +101E8;PHAISTOS DISC SIGN SHIP;So;0;L;;;;;N;;;;; +101E9;PHAISTOS DISC SIGN HORN;So;0;L;;;;;N;;;;; +101EA;PHAISTOS DISC SIGN HIDE;So;0;L;;;;;N;;;;; +101EB;PHAISTOS DISC SIGN BULLS LEG;So;0;L;;;;;N;;;;; +101EC;PHAISTOS DISC SIGN CAT;So;0;L;;;;;N;;;;; +101ED;PHAISTOS DISC SIGN RAM;So;0;L;;;;;N;;;;; +101EE;PHAISTOS DISC SIGN EAGLE;So;0;L;;;;;N;;;;; +101EF;PHAISTOS DISC SIGN DOVE;So;0;L;;;;;N;;;;; +101F0;PHAISTOS DISC SIGN TUNNY;So;0;L;;;;;N;;;;; +101F1;PHAISTOS DISC SIGN BEE;So;0;L;;;;;N;;;;; +101F2;PHAISTOS DISC SIGN PLANE TREE;So;0;L;;;;;N;;;;; +101F3;PHAISTOS DISC SIGN VINE;So;0;L;;;;;N;;;;; +101F4;PHAISTOS DISC SIGN PAPYRUS;So;0;L;;;;;N;;;;; +101F5;PHAISTOS DISC SIGN ROSETTE;So;0;L;;;;;N;;;;; +101F6;PHAISTOS DISC SIGN LILY;So;0;L;;;;;N;;;;; +101F7;PHAISTOS DISC SIGN OX BACK;So;0;L;;;;;N;;;;; +101F8;PHAISTOS DISC SIGN FLUTE;So;0;L;;;;;N;;;;; +101F9;PHAISTOS DISC SIGN GRATER;So;0;L;;;;;N;;;;; +101FA;PHAISTOS DISC SIGN STRAINER;So;0;L;;;;;N;;;;; +101FB;PHAISTOS DISC SIGN SMALL AXE;So;0;L;;;;;N;;;;; +101FC;PHAISTOS DISC SIGN WAVY BAND;So;0;L;;;;;N;;;;; +101FD;PHAISTOS DISC SIGN COMBINING OBLIQUE STROKE;Mn;220;NSM;;;;;N;;;;; +10280;LYCIAN LETTER A;Lo;0;L;;;;;N;;;;; +10281;LYCIAN LETTER E;Lo;0;L;;;;;N;;;;; +10282;LYCIAN LETTER B;Lo;0;L;;;;;N;;;;; +10283;LYCIAN LETTER BH;Lo;0;L;;;;;N;;;;; +10284;LYCIAN LETTER G;Lo;0;L;;;;;N;;;;; +10285;LYCIAN LETTER D;Lo;0;L;;;;;N;;;;; +10286;LYCIAN LETTER I;Lo;0;L;;;;;N;;;;; +10287;LYCIAN LETTER W;Lo;0;L;;;;;N;;;;; +10288;LYCIAN LETTER Z;Lo;0;L;;;;;N;;;;; +10289;LYCIAN LETTER TH;Lo;0;L;;;;;N;;;;; +1028A;LYCIAN LETTER J;Lo;0;L;;;;;N;;;;; +1028B;LYCIAN LETTER K;Lo;0;L;;;;;N;;;;; +1028C;LYCIAN LETTER Q;Lo;0;L;;;;;N;;;;; +1028D;LYCIAN LETTER L;Lo;0;L;;;;;N;;;;; +1028E;LYCIAN LETTER M;Lo;0;L;;;;;N;;;;; +1028F;LYCIAN LETTER N;Lo;0;L;;;;;N;;;;; +10290;LYCIAN LETTER MM;Lo;0;L;;;;;N;;;;; +10291;LYCIAN LETTER NN;Lo;0;L;;;;;N;;;;; +10292;LYCIAN LETTER U;Lo;0;L;;;;;N;;;;; +10293;LYCIAN LETTER P;Lo;0;L;;;;;N;;;;; +10294;LYCIAN LETTER KK;Lo;0;L;;;;;N;;;;; +10295;LYCIAN LETTER R;Lo;0;L;;;;;N;;;;; +10296;LYCIAN LETTER S;Lo;0;L;;;;;N;;;;; +10297;LYCIAN LETTER T;Lo;0;L;;;;;N;;;;; +10298;LYCIAN LETTER TT;Lo;0;L;;;;;N;;;;; +10299;LYCIAN LETTER AN;Lo;0;L;;;;;N;;;;; +1029A;LYCIAN LETTER EN;Lo;0;L;;;;;N;;;;; +1029B;LYCIAN LETTER H;Lo;0;L;;;;;N;;;;; +1029C;LYCIAN LETTER X;Lo;0;L;;;;;N;;;;; +102A0;CARIAN LETTER A;Lo;0;L;;;;;N;;;;; +102A1;CARIAN LETTER P2;Lo;0;L;;;;;N;;;;; +102A2;CARIAN LETTER D;Lo;0;L;;;;;N;;;;; +102A3;CARIAN LETTER L;Lo;0;L;;;;;N;;;;; +102A4;CARIAN LETTER UUU;Lo;0;L;;;;;N;;;;; +102A5;CARIAN LETTER R;Lo;0;L;;;;;N;;;;; +102A6;CARIAN LETTER LD;Lo;0;L;;;;;N;;;;; +102A7;CARIAN LETTER A2;Lo;0;L;;;;;N;;;;; +102A8;CARIAN LETTER Q;Lo;0;L;;;;;N;;;;; +102A9;CARIAN LETTER B;Lo;0;L;;;;;N;;;;; +102AA;CARIAN LETTER M;Lo;0;L;;;;;N;;;;; +102AB;CARIAN LETTER O;Lo;0;L;;;;;N;;;;; +102AC;CARIAN LETTER D2;Lo;0;L;;;;;N;;;;; +102AD;CARIAN LETTER T;Lo;0;L;;;;;N;;;;; +102AE;CARIAN LETTER SH;Lo;0;L;;;;;N;;;;; +102AF;CARIAN LETTER SH2;Lo;0;L;;;;;N;;;;; +102B0;CARIAN LETTER S;Lo;0;L;;;;;N;;;;; +102B1;CARIAN LETTER C-18;Lo;0;L;;;;;N;;;;; +102B2;CARIAN LETTER U;Lo;0;L;;;;;N;;;;; +102B3;CARIAN LETTER NN;Lo;0;L;;;;;N;;;;; +102B4;CARIAN LETTER X;Lo;0;L;;;;;N;;;;; +102B5;CARIAN LETTER N;Lo;0;L;;;;;N;;;;; +102B6;CARIAN LETTER TT2;Lo;0;L;;;;;N;;;;; +102B7;CARIAN LETTER P;Lo;0;L;;;;;N;;;;; +102B8;CARIAN LETTER SS;Lo;0;L;;;;;N;;;;; +102B9;CARIAN LETTER I;Lo;0;L;;;;;N;;;;; +102BA;CARIAN LETTER E;Lo;0;L;;;;;N;;;;; +102BB;CARIAN LETTER UUUU;Lo;0;L;;;;;N;;;;; +102BC;CARIAN LETTER K;Lo;0;L;;;;;N;;;;; +102BD;CARIAN LETTER K2;Lo;0;L;;;;;N;;;;; +102BE;CARIAN LETTER ND;Lo;0;L;;;;;N;;;;; +102BF;CARIAN LETTER UU;Lo;0;L;;;;;N;;;;; +102C0;CARIAN LETTER G;Lo;0;L;;;;;N;;;;; +102C1;CARIAN LETTER G2;Lo;0;L;;;;;N;;;;; +102C2;CARIAN LETTER ST;Lo;0;L;;;;;N;;;;; +102C3;CARIAN LETTER ST2;Lo;0;L;;;;;N;;;;; +102C4;CARIAN LETTER NG;Lo;0;L;;;;;N;;;;; +102C5;CARIAN LETTER II;Lo;0;L;;;;;N;;;;; +102C6;CARIAN LETTER C-39;Lo;0;L;;;;;N;;;;; +102C7;CARIAN LETTER TT;Lo;0;L;;;;;N;;;;; +102C8;CARIAN LETTER UUU2;Lo;0;L;;;;;N;;;;; +102C9;CARIAN LETTER RR;Lo;0;L;;;;;N;;;;; +102CA;CARIAN LETTER MB;Lo;0;L;;;;;N;;;;; +102CB;CARIAN LETTER MB2;Lo;0;L;;;;;N;;;;; +102CC;CARIAN LETTER MB3;Lo;0;L;;;;;N;;;;; +102CD;CARIAN LETTER MB4;Lo;0;L;;;;;N;;;;; +102CE;CARIAN LETTER LD2;Lo;0;L;;;;;N;;;;; +102CF;CARIAN LETTER E2;Lo;0;L;;;;;N;;;;; +102D0;CARIAN LETTER UUU3;Lo;0;L;;;;;N;;;;; 10300;OLD ITALIC LETTER A;Lo;0;L;;;;;N;;;;; 10301;OLD ITALIC LETTER BE;Lo;0;L;;;;;N;;;;; 10302;OLD ITALIC LETTER KE;Lo;0;L;;;;;N;;;;; @@ -12405,7 +15253,7 @@ FFFD;REPLACEMENT CHARACTER;So;0;ON;;;;;N;;;;; 1033E;GOTHIC LETTER JER;Lo;0;L;;;;;N;;;;; 1033F;GOTHIC LETTER URUS;Lo;0;L;;;;;N;;;;; 10340;GOTHIC LETTER PAIRTHRA;Lo;0;L;;;;;N;;;;; -10341;GOTHIC LETTER NINETY;Lo;0;L;;;;;N;;;;; +10341;GOTHIC LETTER NINETY;Nl;0;L;;;;90;N;;;;; 10342;GOTHIC LETTER RAIDA;Lo;0;L;;;;;N;;;;; 10343;GOTHIC LETTER SAUIL;Lo;0;L;;;;;N;;;;; 10344;GOTHIC LETTER TEIWS;Lo;0;L;;;;;N;;;;; @@ -12414,7 +15262,7 @@ FFFD;REPLACEMENT CHARACTER;So;0;ON;;;;;N;;;;; 10347;GOTHIC LETTER IGGWS;Lo;0;L;;;;;N;;;;; 10348;GOTHIC LETTER HWAIR;Lo;0;L;;;;;N;;;;; 10349;GOTHIC LETTER OTHAL;Lo;0;L;;;;;N;;;;; -1034A;GOTHIC LETTER NINE HUNDRED;Nl;0;L;;;;;N;;;;; +1034A;GOTHIC LETTER NINE HUNDRED;Nl;0;L;;;;900;N;;;;; 10380;UGARITIC LETTER ALPA;Lo;0;L;;;;;N;;;;; 10381;UGARITIC LETTER BETA;Lo;0;L;;;;;N;;;;; 10382;UGARITIC LETTER GAMLA;Lo;0;L;;;;;N;;;;; @@ -12446,6 +15294,56 @@ FFFD;REPLACEMENT CHARACTER;So;0;ON;;;;;N;;;;; 1039C;UGARITIC LETTER U;Lo;0;L;;;;;N;;;;; 1039D;UGARITIC LETTER SSU;Lo;0;L;;;;;N;;;;; 1039F;UGARITIC WORD DIVIDER;Po;0;L;;;;;N;;;;; +103A0;OLD PERSIAN SIGN A;Lo;0;L;;;;;N;;;;; +103A1;OLD PERSIAN SIGN I;Lo;0;L;;;;;N;;;;; +103A2;OLD PERSIAN SIGN U;Lo;0;L;;;;;N;;;;; +103A3;OLD PERSIAN SIGN KA;Lo;0;L;;;;;N;;;;; +103A4;OLD PERSIAN SIGN KU;Lo;0;L;;;;;N;;;;; +103A5;OLD PERSIAN SIGN GA;Lo;0;L;;;;;N;;;;; +103A6;OLD PERSIAN SIGN GU;Lo;0;L;;;;;N;;;;; +103A7;OLD PERSIAN SIGN XA;Lo;0;L;;;;;N;;;;; +103A8;OLD PERSIAN SIGN CA;Lo;0;L;;;;;N;;;;; +103A9;OLD PERSIAN SIGN JA;Lo;0;L;;;;;N;;;;; +103AA;OLD PERSIAN SIGN JI;Lo;0;L;;;;;N;;;;; +103AB;OLD PERSIAN SIGN TA;Lo;0;L;;;;;N;;;;; +103AC;OLD PERSIAN SIGN TU;Lo;0;L;;;;;N;;;;; +103AD;OLD PERSIAN SIGN DA;Lo;0;L;;;;;N;;;;; +103AE;OLD PERSIAN SIGN DI;Lo;0;L;;;;;N;;;;; +103AF;OLD PERSIAN SIGN DU;Lo;0;L;;;;;N;;;;; +103B0;OLD PERSIAN SIGN THA;Lo;0;L;;;;;N;;;;; +103B1;OLD PERSIAN SIGN PA;Lo;0;L;;;;;N;;;;; +103B2;OLD PERSIAN SIGN BA;Lo;0;L;;;;;N;;;;; +103B3;OLD PERSIAN SIGN FA;Lo;0;L;;;;;N;;;;; +103B4;OLD PERSIAN SIGN NA;Lo;0;L;;;;;N;;;;; +103B5;OLD PERSIAN SIGN NU;Lo;0;L;;;;;N;;;;; +103B6;OLD PERSIAN SIGN MA;Lo;0;L;;;;;N;;;;; +103B7;OLD PERSIAN SIGN MI;Lo;0;L;;;;;N;;;;; +103B8;OLD PERSIAN SIGN MU;Lo;0;L;;;;;N;;;;; +103B9;OLD PERSIAN SIGN YA;Lo;0;L;;;;;N;;;;; +103BA;OLD PERSIAN SIGN VA;Lo;0;L;;;;;N;;;;; +103BB;OLD PERSIAN SIGN VI;Lo;0;L;;;;;N;;;;; +103BC;OLD PERSIAN SIGN RA;Lo;0;L;;;;;N;;;;; +103BD;OLD PERSIAN SIGN RU;Lo;0;L;;;;;N;;;;; +103BE;OLD PERSIAN SIGN LA;Lo;0;L;;;;;N;;;;; +103BF;OLD PERSIAN SIGN SA;Lo;0;L;;;;;N;;;;; +103C0;OLD PERSIAN SIGN ZA;Lo;0;L;;;;;N;;;;; +103C1;OLD PERSIAN SIGN SHA;Lo;0;L;;;;;N;;;;; +103C2;OLD PERSIAN SIGN SSA;Lo;0;L;;;;;N;;;;; +103C3;OLD PERSIAN SIGN HA;Lo;0;L;;;;;N;;;;; +103C8;OLD PERSIAN SIGN AURAMAZDAA;Lo;0;L;;;;;N;;;;; +103C9;OLD PERSIAN SIGN AURAMAZDAA-2;Lo;0;L;;;;;N;;;;; +103CA;OLD PERSIAN SIGN AURAMAZDAAHA;Lo;0;L;;;;;N;;;;; +103CB;OLD PERSIAN SIGN XSHAAYATHIYA;Lo;0;L;;;;;N;;;;; +103CC;OLD PERSIAN SIGN DAHYAAUSH;Lo;0;L;;;;;N;;;;; +103CD;OLD PERSIAN SIGN DAHYAAUSH-2;Lo;0;L;;;;;N;;;;; +103CE;OLD PERSIAN SIGN BAGA;Lo;0;L;;;;;N;;;;; +103CF;OLD PERSIAN SIGN BUUMISH;Lo;0;L;;;;;N;;;;; +103D0;OLD PERSIAN WORD DIVIDER;Po;0;L;;;;;N;;;;; +103D1;OLD PERSIAN NUMBER ONE;Nl;0;L;;;;1;N;;;;; +103D2;OLD PERSIAN NUMBER TWO;Nl;0;L;;;;2;N;;;;; +103D3;OLD PERSIAN NUMBER TEN;Nl;0;L;;;;10;N;;;;; +103D4;OLD PERSIAN NUMBER TWENTY;Nl;0;L;;;;20;N;;;;; +103D5;OLD PERSIAN NUMBER HUNDRED;Nl;0;L;;;;100;N;;;;; 10400;DESERET CAPITAL LETTER LONG I;Lu;0;L;;;;;N;;;;10428; 10401;DESERET CAPITAL LETTER LONG E;Lu;0;L;;;;;N;;;;10429; 10402;DESERET CAPITAL LETTER LONG A;Lu;0;L;;;;;N;;;;1042A; @@ -12669,6 +15567,1107 @@ FFFD;REPLACEMENT CHARACTER;So;0;ON;;;;;N;;;;; 10838;CYPRIOT SYLLABLE XE;Lo;0;R;;;;;N;;;;; 1083C;CYPRIOT SYLLABLE ZA;Lo;0;R;;;;;N;;;;; 1083F;CYPRIOT SYLLABLE ZO;Lo;0;R;;;;;N;;;;; +10900;PHOENICIAN LETTER ALF;Lo;0;R;;;;;N;;;;; +10901;PHOENICIAN LETTER BET;Lo;0;R;;;;;N;;;;; +10902;PHOENICIAN LETTER GAML;Lo;0;R;;;;;N;;;;; +10903;PHOENICIAN LETTER DELT;Lo;0;R;;;;;N;;;;; +10904;PHOENICIAN LETTER HE;Lo;0;R;;;;;N;;;;; +10905;PHOENICIAN LETTER WAU;Lo;0;R;;;;;N;;;;; +10906;PHOENICIAN LETTER ZAI;Lo;0;R;;;;;N;;;;; +10907;PHOENICIAN LETTER HET;Lo;0;R;;;;;N;;;;; +10908;PHOENICIAN LETTER TET;Lo;0;R;;;;;N;;;;; +10909;PHOENICIAN LETTER YOD;Lo;0;R;;;;;N;;;;; +1090A;PHOENICIAN LETTER KAF;Lo;0;R;;;;;N;;;;; +1090B;PHOENICIAN LETTER LAMD;Lo;0;R;;;;;N;;;;; +1090C;PHOENICIAN LETTER MEM;Lo;0;R;;;;;N;;;;; +1090D;PHOENICIAN LETTER NUN;Lo;0;R;;;;;N;;;;; +1090E;PHOENICIAN LETTER SEMK;Lo;0;R;;;;;N;;;;; +1090F;PHOENICIAN LETTER AIN;Lo;0;R;;;;;N;;;;; +10910;PHOENICIAN LETTER PE;Lo;0;R;;;;;N;;;;; +10911;PHOENICIAN LETTER SADE;Lo;0;R;;;;;N;;;;; +10912;PHOENICIAN LETTER QOF;Lo;0;R;;;;;N;;;;; +10913;PHOENICIAN LETTER ROSH;Lo;0;R;;;;;N;;;;; +10914;PHOENICIAN LETTER SHIN;Lo;0;R;;;;;N;;;;; +10915;PHOENICIAN LETTER TAU;Lo;0;R;;;;;N;;;;; +10916;PHOENICIAN NUMBER ONE;No;0;R;;;;1;N;;;;; +10917;PHOENICIAN NUMBER TEN;No;0;R;;;;10;N;;;;; +10918;PHOENICIAN NUMBER TWENTY;No;0;R;;;;20;N;;;;; +10919;PHOENICIAN NUMBER ONE HUNDRED;No;0;R;;;;100;N;;;;; +1091F;PHOENICIAN WORD SEPARATOR;Po;0;ON;;;;;N;;;;; +10920;LYDIAN LETTER A;Lo;0;R;;;;;N;;;;; +10921;LYDIAN LETTER B;Lo;0;R;;;;;N;;;;; +10922;LYDIAN LETTER G;Lo;0;R;;;;;N;;;;; +10923;LYDIAN LETTER D;Lo;0;R;;;;;N;;;;; +10924;LYDIAN LETTER E;Lo;0;R;;;;;N;;;;; +10925;LYDIAN LETTER V;Lo;0;R;;;;;N;;;;; +10926;LYDIAN LETTER I;Lo;0;R;;;;;N;;;;; +10927;LYDIAN LETTER Y;Lo;0;R;;;;;N;;;;; +10928;LYDIAN LETTER K;Lo;0;R;;;;;N;;;;; +10929;LYDIAN LETTER L;Lo;0;R;;;;;N;;;;; +1092A;LYDIAN LETTER M;Lo;0;R;;;;;N;;;;; +1092B;LYDIAN LETTER N;Lo;0;R;;;;;N;;;;; +1092C;LYDIAN LETTER O;Lo;0;R;;;;;N;;;;; +1092D;LYDIAN LETTER R;Lo;0;R;;;;;N;;;;; +1092E;LYDIAN LETTER SS;Lo;0;R;;;;;N;;;;; +1092F;LYDIAN LETTER T;Lo;0;R;;;;;N;;;;; +10930;LYDIAN LETTER U;Lo;0;R;;;;;N;;;;; +10931;LYDIAN LETTER F;Lo;0;R;;;;;N;;;;; +10932;LYDIAN LETTER Q;Lo;0;R;;;;;N;;;;; +10933;LYDIAN LETTER S;Lo;0;R;;;;;N;;;;; +10934;LYDIAN LETTER TT;Lo;0;R;;;;;N;;;;; +10935;LYDIAN LETTER AN;Lo;0;R;;;;;N;;;;; +10936;LYDIAN LETTER EN;Lo;0;R;;;;;N;;;;; +10937;LYDIAN LETTER LY;Lo;0;R;;;;;N;;;;; +10938;LYDIAN LETTER NN;Lo;0;R;;;;;N;;;;; +10939;LYDIAN LETTER C;Lo;0;R;;;;;N;;;;; +1093F;LYDIAN TRIANGULAR MARK;Po;0;R;;;;;N;;;;; +10A00;KHAROSHTHI LETTER A;Lo;0;R;;;;;N;;;;; +10A01;KHAROSHTHI VOWEL SIGN I;Mn;0;NSM;;;;;N;;;;; +10A02;KHAROSHTHI VOWEL SIGN U;Mn;0;NSM;;;;;N;;;;; +10A03;KHAROSHTHI VOWEL SIGN VOCALIC R;Mn;0;NSM;;;;;N;;;;; +10A05;KHAROSHTHI VOWEL SIGN E;Mn;0;NSM;;;;;N;;;;; +10A06;KHAROSHTHI VOWEL SIGN O;Mn;0;NSM;;;;;N;;;;; +10A0C;KHAROSHTHI VOWEL LENGTH MARK;Mn;0;NSM;;;;;N;;;;; +10A0D;KHAROSHTHI SIGN DOUBLE RING BELOW;Mn;220;NSM;;;;;N;;;;; +10A0E;KHAROSHTHI SIGN ANUSVARA;Mn;0;NSM;;;;;N;;;;; +10A0F;KHAROSHTHI SIGN VISARGA;Mn;230;NSM;;;;;N;;;;; +10A10;KHAROSHTHI LETTER KA;Lo;0;R;;;;;N;;;;; +10A11;KHAROSHTHI LETTER KHA;Lo;0;R;;;;;N;;;;; +10A12;KHAROSHTHI LETTER GA;Lo;0;R;;;;;N;;;;; +10A13;KHAROSHTHI LETTER GHA;Lo;0;R;;;;;N;;;;; +10A15;KHAROSHTHI LETTER CA;Lo;0;R;;;;;N;;;;; +10A16;KHAROSHTHI LETTER CHA;Lo;0;R;;;;;N;;;;; +10A17;KHAROSHTHI LETTER JA;Lo;0;R;;;;;N;;;;; +10A19;KHAROSHTHI LETTER NYA;Lo;0;R;;;;;N;;;;; +10A1A;KHAROSHTHI LETTER TTA;Lo;0;R;;;;;N;;;;; +10A1B;KHAROSHTHI LETTER TTHA;Lo;0;R;;;;;N;;;;; +10A1C;KHAROSHTHI LETTER DDA;Lo;0;R;;;;;N;;;;; +10A1D;KHAROSHTHI LETTER DDHA;Lo;0;R;;;;;N;;;;; +10A1E;KHAROSHTHI LETTER NNA;Lo;0;R;;;;;N;;;;; +10A1F;KHAROSHTHI LETTER TA;Lo;0;R;;;;;N;;;;; +10A20;KHAROSHTHI LETTER THA;Lo;0;R;;;;;N;;;;; +10A21;KHAROSHTHI LETTER DA;Lo;0;R;;;;;N;;;;; +10A22;KHAROSHTHI LETTER DHA;Lo;0;R;;;;;N;;;;; +10A23;KHAROSHTHI LETTER NA;Lo;0;R;;;;;N;;;;; +10A24;KHAROSHTHI LETTER PA;Lo;0;R;;;;;N;;;;; +10A25;KHAROSHTHI LETTER PHA;Lo;0;R;;;;;N;;;;; +10A26;KHAROSHTHI LETTER BA;Lo;0;R;;;;;N;;;;; +10A27;KHAROSHTHI LETTER BHA;Lo;0;R;;;;;N;;;;; +10A28;KHAROSHTHI LETTER MA;Lo;0;R;;;;;N;;;;; +10A29;KHAROSHTHI LETTER YA;Lo;0;R;;;;;N;;;;; +10A2A;KHAROSHTHI LETTER RA;Lo;0;R;;;;;N;;;;; +10A2B;KHAROSHTHI LETTER LA;Lo;0;R;;;;;N;;;;; +10A2C;KHAROSHTHI LETTER VA;Lo;0;R;;;;;N;;;;; +10A2D;KHAROSHTHI LETTER SHA;Lo;0;R;;;;;N;;;;; +10A2E;KHAROSHTHI LETTER SSA;Lo;0;R;;;;;N;;;;; +10A2F;KHAROSHTHI LETTER SA;Lo;0;R;;;;;N;;;;; +10A30;KHAROSHTHI LETTER ZA;Lo;0;R;;;;;N;;;;; +10A31;KHAROSHTHI LETTER HA;Lo;0;R;;;;;N;;;;; +10A32;KHAROSHTHI LETTER KKA;Lo;0;R;;;;;N;;;;; +10A33;KHAROSHTHI LETTER TTTHA;Lo;0;R;;;;;N;;;;; +10A38;KHAROSHTHI SIGN BAR ABOVE;Mn;230;NSM;;;;;N;;;;; +10A39;KHAROSHTHI SIGN CAUDA;Mn;1;NSM;;;;;N;;;;; +10A3A;KHAROSHTHI SIGN DOT BELOW;Mn;220;NSM;;;;;N;;;;; +10A3F;KHAROSHTHI VIRAMA;Mn;9;NSM;;;;;N;;;;; +10A40;KHAROSHTHI DIGIT ONE;No;0;R;;;1;1;N;;;;; +10A41;KHAROSHTHI DIGIT TWO;No;0;R;;;2;2;N;;;;; +10A42;KHAROSHTHI DIGIT THREE;No;0;R;;;3;3;N;;;;; +10A43;KHAROSHTHI DIGIT FOUR;No;0;R;;;4;4;N;;;;; +10A44;KHAROSHTHI NUMBER TEN;No;0;R;;;;10;N;;;;; +10A45;KHAROSHTHI NUMBER TWENTY;No;0;R;;;;20;N;;;;; +10A46;KHAROSHTHI NUMBER ONE HUNDRED;No;0;R;;;;100;N;;;;; +10A47;KHAROSHTHI NUMBER ONE THOUSAND;No;0;R;;;;1000;N;;;;; +10A50;KHAROSHTHI PUNCTUATION DOT;Po;0;R;;;;;N;;;;; +10A51;KHAROSHTHI PUNCTUATION SMALL CIRCLE;Po;0;R;;;;;N;;;;; +10A52;KHAROSHTHI PUNCTUATION CIRCLE;Po;0;R;;;;;N;;;;; +10A53;KHAROSHTHI PUNCTUATION CRESCENT BAR;Po;0;R;;;;;N;;;;; +10A54;KHAROSHTHI PUNCTUATION MANGALAM;Po;0;R;;;;;N;;;;; +10A55;KHAROSHTHI PUNCTUATION LOTUS;Po;0;R;;;;;N;;;;; +10A56;KHAROSHTHI PUNCTUATION DANDA;Po;0;R;;;;;N;;;;; +10A57;KHAROSHTHI PUNCTUATION DOUBLE DANDA;Po;0;R;;;;;N;;;;; +10A58;KHAROSHTHI PUNCTUATION LINES;Po;0;R;;;;;N;;;;; +12000;CUNEIFORM SIGN A;Lo;0;L;;;;;N;;;;; +12001;CUNEIFORM SIGN A TIMES A;Lo;0;L;;;;;N;;;;; +12002;CUNEIFORM SIGN A TIMES BAD;Lo;0;L;;;;;N;;;;; +12003;CUNEIFORM SIGN A TIMES GAN2 TENU;Lo;0;L;;;;;N;;;;; +12004;CUNEIFORM SIGN A TIMES HA;Lo;0;L;;;;;N;;;;; +12005;CUNEIFORM SIGN A TIMES IGI;Lo;0;L;;;;;N;;;;; +12006;CUNEIFORM SIGN A TIMES LAGAR GUNU;Lo;0;L;;;;;N;;;;; +12007;CUNEIFORM SIGN A TIMES MUSH;Lo;0;L;;;;;N;;;;; +12008;CUNEIFORM SIGN A TIMES SAG;Lo;0;L;;;;;N;;;;; +12009;CUNEIFORM SIGN A2;Lo;0;L;;;;;N;;;;; +1200A;CUNEIFORM SIGN AB;Lo;0;L;;;;;N;;;;; +1200B;CUNEIFORM SIGN AB TIMES ASH2;Lo;0;L;;;;;N;;;;; +1200C;CUNEIFORM SIGN AB TIMES DUN3 GUNU;Lo;0;L;;;;;N;;;;; +1200D;CUNEIFORM SIGN AB TIMES GAL;Lo;0;L;;;;;N;;;;; +1200E;CUNEIFORM SIGN AB TIMES GAN2 TENU;Lo;0;L;;;;;N;;;;; +1200F;CUNEIFORM SIGN AB TIMES HA;Lo;0;L;;;;;N;;;;; +12010;CUNEIFORM SIGN AB TIMES IGI GUNU;Lo;0;L;;;;;N;;;;; +12011;CUNEIFORM SIGN AB TIMES IMIN;Lo;0;L;;;;;N;;;;; +12012;CUNEIFORM SIGN AB TIMES LAGAB;Lo;0;L;;;;;N;;;;; +12013;CUNEIFORM SIGN AB TIMES SHESH;Lo;0;L;;;;;N;;;;; +12014;CUNEIFORM SIGN AB TIMES U PLUS U PLUS U;Lo;0;L;;;;;N;;;;; +12015;CUNEIFORM SIGN AB GUNU;Lo;0;L;;;;;N;;;;; +12016;CUNEIFORM SIGN AB2;Lo;0;L;;;;;N;;;;; +12017;CUNEIFORM SIGN AB2 TIMES BALAG;Lo;0;L;;;;;N;;;;; +12018;CUNEIFORM SIGN AB2 TIMES GAN2 TENU;Lo;0;L;;;;;N;;;;; +12019;CUNEIFORM SIGN AB2 TIMES ME PLUS EN;Lo;0;L;;;;;N;;;;; +1201A;CUNEIFORM SIGN AB2 TIMES SHA3;Lo;0;L;;;;;N;;;;; +1201B;CUNEIFORM SIGN AB2 TIMES TAK4;Lo;0;L;;;;;N;;;;; +1201C;CUNEIFORM SIGN AD;Lo;0;L;;;;;N;;;;; +1201D;CUNEIFORM SIGN AK;Lo;0;L;;;;;N;;;;; +1201E;CUNEIFORM SIGN AK TIMES ERIN2;Lo;0;L;;;;;N;;;;; +1201F;CUNEIFORM SIGN AK TIMES SHITA PLUS GISH;Lo;0;L;;;;;N;;;;; +12020;CUNEIFORM SIGN AL;Lo;0;L;;;;;N;;;;; +12021;CUNEIFORM SIGN AL TIMES AL;Lo;0;L;;;;;N;;;;; +12022;CUNEIFORM SIGN AL TIMES DIM2;Lo;0;L;;;;;N;;;;; +12023;CUNEIFORM SIGN AL TIMES GISH;Lo;0;L;;;;;N;;;;; +12024;CUNEIFORM SIGN AL TIMES HA;Lo;0;L;;;;;N;;;;; +12025;CUNEIFORM SIGN AL TIMES KAD3;Lo;0;L;;;;;N;;;;; +12026;CUNEIFORM SIGN AL TIMES KI;Lo;0;L;;;;;N;;;;; +12027;CUNEIFORM SIGN AL TIMES SHE;Lo;0;L;;;;;N;;;;; +12028;CUNEIFORM SIGN AL TIMES USH;Lo;0;L;;;;;N;;;;; +12029;CUNEIFORM SIGN ALAN;Lo;0;L;;;;;N;;;;; +1202A;CUNEIFORM SIGN ALEPH;Lo;0;L;;;;;N;;;;; +1202B;CUNEIFORM SIGN AMAR;Lo;0;L;;;;;N;;;;; +1202C;CUNEIFORM SIGN AMAR TIMES SHE;Lo;0;L;;;;;N;;;;; +1202D;CUNEIFORM SIGN AN;Lo;0;L;;;;;N;;;;; +1202E;CUNEIFORM SIGN AN OVER AN;Lo;0;L;;;;;N;;;;; +1202F;CUNEIFORM SIGN AN THREE TIMES;Lo;0;L;;;;;N;;;;; +12030;CUNEIFORM SIGN AN PLUS NAGA OPPOSING AN PLUS NAGA;Lo;0;L;;;;;N;;;;; +12031;CUNEIFORM SIGN AN PLUS NAGA SQUARED;Lo;0;L;;;;;N;;;;; +12032;CUNEIFORM SIGN ANSHE;Lo;0;L;;;;;N;;;;; +12033;CUNEIFORM SIGN APIN;Lo;0;L;;;;;N;;;;; +12034;CUNEIFORM SIGN ARAD;Lo;0;L;;;;;N;;;;; +12035;CUNEIFORM SIGN ARAD TIMES KUR;Lo;0;L;;;;;N;;;;; +12036;CUNEIFORM SIGN ARKAB;Lo;0;L;;;;;N;;;;; +12037;CUNEIFORM SIGN ASAL2;Lo;0;L;;;;;N;;;;; +12038;CUNEIFORM SIGN ASH;Lo;0;L;;;;;N;;;;; +12039;CUNEIFORM SIGN ASH ZIDA TENU;Lo;0;L;;;;;N;;;;; +1203A;CUNEIFORM SIGN ASH KABA TENU;Lo;0;L;;;;;N;;;;; +1203B;CUNEIFORM SIGN ASH OVER ASH TUG2 OVER TUG2 TUG2 OVER TUG2 PAP;Lo;0;L;;;;;N;;;;; +1203C;CUNEIFORM SIGN ASH OVER ASH OVER ASH;Lo;0;L;;;;;N;;;;; +1203D;CUNEIFORM SIGN ASH OVER ASH OVER ASH CROSSING ASH OVER ASH OVER ASH;Lo;0;L;;;;;N;;;;; +1203E;CUNEIFORM SIGN ASH2;Lo;0;L;;;;;N;;;;; +1203F;CUNEIFORM SIGN ASHGAB;Lo;0;L;;;;;N;;;;; +12040;CUNEIFORM SIGN BA;Lo;0;L;;;;;N;;;;; +12041;CUNEIFORM SIGN BAD;Lo;0;L;;;;;N;;;;; +12042;CUNEIFORM SIGN BAG3;Lo;0;L;;;;;N;;;;; +12043;CUNEIFORM SIGN BAHAR2;Lo;0;L;;;;;N;;;;; +12044;CUNEIFORM SIGN BAL;Lo;0;L;;;;;N;;;;; +12045;CUNEIFORM SIGN BAL OVER BAL;Lo;0;L;;;;;N;;;;; +12046;CUNEIFORM SIGN BALAG;Lo;0;L;;;;;N;;;;; +12047;CUNEIFORM SIGN BAR;Lo;0;L;;;;;N;;;;; +12048;CUNEIFORM SIGN BARA2;Lo;0;L;;;;;N;;;;; +12049;CUNEIFORM SIGN BI;Lo;0;L;;;;;N;;;;; +1204A;CUNEIFORM SIGN BI TIMES A;Lo;0;L;;;;;N;;;;; +1204B;CUNEIFORM SIGN BI TIMES GAR;Lo;0;L;;;;;N;;;;; +1204C;CUNEIFORM SIGN BI TIMES IGI GUNU;Lo;0;L;;;;;N;;;;; +1204D;CUNEIFORM SIGN BU;Lo;0;L;;;;;N;;;;; +1204E;CUNEIFORM SIGN BU OVER BU AB;Lo;0;L;;;;;N;;;;; +1204F;CUNEIFORM SIGN BU OVER BU UN;Lo;0;L;;;;;N;;;;; +12050;CUNEIFORM SIGN BU CROSSING BU;Lo;0;L;;;;;N;;;;; +12051;CUNEIFORM SIGN BULUG;Lo;0;L;;;;;N;;;;; +12052;CUNEIFORM SIGN BULUG OVER BULUG;Lo;0;L;;;;;N;;;;; +12053;CUNEIFORM SIGN BUR;Lo;0;L;;;;;N;;;;; +12054;CUNEIFORM SIGN BUR2;Lo;0;L;;;;;N;;;;; +12055;CUNEIFORM SIGN DA;Lo;0;L;;;;;N;;;;; +12056;CUNEIFORM SIGN DAG;Lo;0;L;;;;;N;;;;; +12057;CUNEIFORM SIGN DAG KISIM5 TIMES A PLUS MASH;Lo;0;L;;;;;N;;;;; +12058;CUNEIFORM SIGN DAG KISIM5 TIMES AMAR;Lo;0;L;;;;;N;;;;; +12059;CUNEIFORM SIGN DAG KISIM5 TIMES BALAG;Lo;0;L;;;;;N;;;;; +1205A;CUNEIFORM SIGN DAG KISIM5 TIMES BI;Lo;0;L;;;;;N;;;;; +1205B;CUNEIFORM SIGN DAG KISIM5 TIMES GA;Lo;0;L;;;;;N;;;;; +1205C;CUNEIFORM SIGN DAG KISIM5 TIMES GA PLUS MASH;Lo;0;L;;;;;N;;;;; +1205D;CUNEIFORM SIGN DAG KISIM5 TIMES GI;Lo;0;L;;;;;N;;;;; +1205E;CUNEIFORM SIGN DAG KISIM5 TIMES GIR2;Lo;0;L;;;;;N;;;;; +1205F;CUNEIFORM SIGN DAG KISIM5 TIMES GUD;Lo;0;L;;;;;N;;;;; +12060;CUNEIFORM SIGN DAG KISIM5 TIMES HA;Lo;0;L;;;;;N;;;;; +12061;CUNEIFORM SIGN DAG KISIM5 TIMES IR;Lo;0;L;;;;;N;;;;; +12062;CUNEIFORM SIGN DAG KISIM5 TIMES IR PLUS LU;Lo;0;L;;;;;N;;;;; +12063;CUNEIFORM SIGN DAG KISIM5 TIMES KAK;Lo;0;L;;;;;N;;;;; +12064;CUNEIFORM SIGN DAG KISIM5 TIMES LA;Lo;0;L;;;;;N;;;;; +12065;CUNEIFORM SIGN DAG KISIM5 TIMES LU;Lo;0;L;;;;;N;;;;; +12066;CUNEIFORM SIGN DAG KISIM5 TIMES LU PLUS MASH2;Lo;0;L;;;;;N;;;;; +12067;CUNEIFORM SIGN DAG KISIM5 TIMES LUM;Lo;0;L;;;;;N;;;;; +12068;CUNEIFORM SIGN DAG KISIM5 TIMES NE;Lo;0;L;;;;;N;;;;; +12069;CUNEIFORM SIGN DAG KISIM5 TIMES PAP PLUS PAP;Lo;0;L;;;;;N;;;;; +1206A;CUNEIFORM SIGN DAG KISIM5 TIMES SI;Lo;0;L;;;;;N;;;;; +1206B;CUNEIFORM SIGN DAG KISIM5 TIMES TAK4;Lo;0;L;;;;;N;;;;; +1206C;CUNEIFORM SIGN DAG KISIM5 TIMES U2 PLUS GIR2;Lo;0;L;;;;;N;;;;; +1206D;CUNEIFORM SIGN DAG KISIM5 TIMES USH;Lo;0;L;;;;;N;;;;; +1206E;CUNEIFORM SIGN DAM;Lo;0;L;;;;;N;;;;; +1206F;CUNEIFORM SIGN DAR;Lo;0;L;;;;;N;;;;; +12070;CUNEIFORM SIGN DARA3;Lo;0;L;;;;;N;;;;; +12071;CUNEIFORM SIGN DARA4;Lo;0;L;;;;;N;;;;; +12072;CUNEIFORM SIGN DI;Lo;0;L;;;;;N;;;;; +12073;CUNEIFORM SIGN DIB;Lo;0;L;;;;;N;;;;; +12074;CUNEIFORM SIGN DIM;Lo;0;L;;;;;N;;;;; +12075;CUNEIFORM SIGN DIM TIMES SHE;Lo;0;L;;;;;N;;;;; +12076;CUNEIFORM SIGN DIM2;Lo;0;L;;;;;N;;;;; +12077;CUNEIFORM SIGN DIN;Lo;0;L;;;;;N;;;;; +12078;CUNEIFORM SIGN DIN KASKAL U GUNU DISH;Lo;0;L;;;;;N;;;;; +12079;CUNEIFORM SIGN DISH;Lo;0;L;;;;;N;;;;; +1207A;CUNEIFORM SIGN DU;Lo;0;L;;;;;N;;;;; +1207B;CUNEIFORM SIGN DU OVER DU;Lo;0;L;;;;;N;;;;; +1207C;CUNEIFORM SIGN DU GUNU;Lo;0;L;;;;;N;;;;; +1207D;CUNEIFORM SIGN DU SHESHIG;Lo;0;L;;;;;N;;;;; +1207E;CUNEIFORM SIGN DUB;Lo;0;L;;;;;N;;;;; +1207F;CUNEIFORM SIGN DUB TIMES ESH2;Lo;0;L;;;;;N;;;;; +12080;CUNEIFORM SIGN DUB2;Lo;0;L;;;;;N;;;;; +12081;CUNEIFORM SIGN DUG;Lo;0;L;;;;;N;;;;; +12082;CUNEIFORM SIGN DUGUD;Lo;0;L;;;;;N;;;;; +12083;CUNEIFORM SIGN DUH;Lo;0;L;;;;;N;;;;; +12084;CUNEIFORM SIGN DUN;Lo;0;L;;;;;N;;;;; +12085;CUNEIFORM SIGN DUN3;Lo;0;L;;;;;N;;;;; +12086;CUNEIFORM SIGN DUN3 GUNU;Lo;0;L;;;;;N;;;;; +12087;CUNEIFORM SIGN DUN3 GUNU GUNU;Lo;0;L;;;;;N;;;;; +12088;CUNEIFORM SIGN DUN4;Lo;0;L;;;;;N;;;;; +12089;CUNEIFORM SIGN DUR2;Lo;0;L;;;;;N;;;;; +1208A;CUNEIFORM SIGN E;Lo;0;L;;;;;N;;;;; +1208B;CUNEIFORM SIGN E TIMES PAP;Lo;0;L;;;;;N;;;;; +1208C;CUNEIFORM SIGN E OVER E NUN OVER NUN;Lo;0;L;;;;;N;;;;; +1208D;CUNEIFORM SIGN E2;Lo;0;L;;;;;N;;;;; +1208E;CUNEIFORM SIGN E2 TIMES A PLUS HA PLUS DA;Lo;0;L;;;;;N;;;;; +1208F;CUNEIFORM SIGN E2 TIMES GAR;Lo;0;L;;;;;N;;;;; +12090;CUNEIFORM SIGN E2 TIMES MI;Lo;0;L;;;;;N;;;;; +12091;CUNEIFORM SIGN E2 TIMES SAL;Lo;0;L;;;;;N;;;;; +12092;CUNEIFORM SIGN E2 TIMES SHE;Lo;0;L;;;;;N;;;;; +12093;CUNEIFORM SIGN E2 TIMES U;Lo;0;L;;;;;N;;;;; +12094;CUNEIFORM SIGN EDIN;Lo;0;L;;;;;N;;;;; +12095;CUNEIFORM SIGN EGIR;Lo;0;L;;;;;N;;;;; +12096;CUNEIFORM SIGN EL;Lo;0;L;;;;;N;;;;; +12097;CUNEIFORM SIGN EN;Lo;0;L;;;;;N;;;;; +12098;CUNEIFORM SIGN EN TIMES GAN2;Lo;0;L;;;;;N;;;;; +12099;CUNEIFORM SIGN EN TIMES GAN2 TENU;Lo;0;L;;;;;N;;;;; +1209A;CUNEIFORM SIGN EN TIMES ME;Lo;0;L;;;;;N;;;;; +1209B;CUNEIFORM SIGN EN CROSSING EN;Lo;0;L;;;;;N;;;;; +1209C;CUNEIFORM SIGN EN OPPOSING EN;Lo;0;L;;;;;N;;;;; +1209D;CUNEIFORM SIGN EN SQUARED;Lo;0;L;;;;;N;;;;; +1209E;CUNEIFORM SIGN EREN;Lo;0;L;;;;;N;;;;; +1209F;CUNEIFORM SIGN ERIN2;Lo;0;L;;;;;N;;;;; +120A0;CUNEIFORM SIGN ESH2;Lo;0;L;;;;;N;;;;; +120A1;CUNEIFORM SIGN EZEN;Lo;0;L;;;;;N;;;;; +120A2;CUNEIFORM SIGN EZEN TIMES A;Lo;0;L;;;;;N;;;;; +120A3;CUNEIFORM SIGN EZEN TIMES A PLUS LAL;Lo;0;L;;;;;N;;;;; +120A4;CUNEIFORM SIGN EZEN TIMES A PLUS LAL TIMES LAL;Lo;0;L;;;;;N;;;;; +120A5;CUNEIFORM SIGN EZEN TIMES AN;Lo;0;L;;;;;N;;;;; +120A6;CUNEIFORM SIGN EZEN TIMES BAD;Lo;0;L;;;;;N;;;;; +120A7;CUNEIFORM SIGN EZEN TIMES DUN3 GUNU;Lo;0;L;;;;;N;;;;; +120A8;CUNEIFORM SIGN EZEN TIMES DUN3 GUNU GUNU;Lo;0;L;;;;;N;;;;; +120A9;CUNEIFORM SIGN EZEN TIMES HA;Lo;0;L;;;;;N;;;;; +120AA;CUNEIFORM SIGN EZEN TIMES HA GUNU;Lo;0;L;;;;;N;;;;; +120AB;CUNEIFORM SIGN EZEN TIMES IGI GUNU;Lo;0;L;;;;;N;;;;; +120AC;CUNEIFORM SIGN EZEN TIMES KASKAL;Lo;0;L;;;;;N;;;;; +120AD;CUNEIFORM SIGN EZEN TIMES KASKAL SQUARED;Lo;0;L;;;;;N;;;;; +120AE;CUNEIFORM SIGN EZEN TIMES KU3;Lo;0;L;;;;;N;;;;; +120AF;CUNEIFORM SIGN EZEN TIMES LA;Lo;0;L;;;;;N;;;;; +120B0;CUNEIFORM SIGN EZEN TIMES LAL TIMES LAL;Lo;0;L;;;;;N;;;;; +120B1;CUNEIFORM SIGN EZEN TIMES LI;Lo;0;L;;;;;N;;;;; +120B2;CUNEIFORM SIGN EZEN TIMES LU;Lo;0;L;;;;;N;;;;; +120B3;CUNEIFORM SIGN EZEN TIMES U2;Lo;0;L;;;;;N;;;;; +120B4;CUNEIFORM SIGN EZEN TIMES UD;Lo;0;L;;;;;N;;;;; +120B5;CUNEIFORM SIGN GA;Lo;0;L;;;;;N;;;;; +120B6;CUNEIFORM SIGN GA GUNU;Lo;0;L;;;;;N;;;;; +120B7;CUNEIFORM SIGN GA2;Lo;0;L;;;;;N;;;;; +120B8;CUNEIFORM SIGN GA2 TIMES A PLUS DA PLUS HA;Lo;0;L;;;;;N;;;;; +120B9;CUNEIFORM SIGN GA2 TIMES A PLUS HA;Lo;0;L;;;;;N;;;;; +120BA;CUNEIFORM SIGN GA2 TIMES A PLUS IGI;Lo;0;L;;;;;N;;;;; +120BB;CUNEIFORM SIGN GA2 TIMES AB2 TENU PLUS TAB;Lo;0;L;;;;;N;;;;; +120BC;CUNEIFORM SIGN GA2 TIMES AN;Lo;0;L;;;;;N;;;;; +120BD;CUNEIFORM SIGN GA2 TIMES ASH;Lo;0;L;;;;;N;;;;; +120BE;CUNEIFORM SIGN GA2 TIMES ASH2 PLUS GAL;Lo;0;L;;;;;N;;;;; +120BF;CUNEIFORM SIGN GA2 TIMES BAD;Lo;0;L;;;;;N;;;;; +120C0;CUNEIFORM SIGN GA2 TIMES BAR PLUS RA;Lo;0;L;;;;;N;;;;; +120C1;CUNEIFORM SIGN GA2 TIMES BUR;Lo;0;L;;;;;N;;;;; +120C2;CUNEIFORM SIGN GA2 TIMES BUR PLUS RA;Lo;0;L;;;;;N;;;;; +120C3;CUNEIFORM SIGN GA2 TIMES DA;Lo;0;L;;;;;N;;;;; +120C4;CUNEIFORM SIGN GA2 TIMES DI;Lo;0;L;;;;;N;;;;; +120C5;CUNEIFORM SIGN GA2 TIMES DIM TIMES SHE;Lo;0;L;;;;;N;;;;; +120C6;CUNEIFORM SIGN GA2 TIMES DUB;Lo;0;L;;;;;N;;;;; +120C7;CUNEIFORM SIGN GA2 TIMES EL;Lo;0;L;;;;;N;;;;; +120C8;CUNEIFORM SIGN GA2 TIMES EL PLUS LA;Lo;0;L;;;;;N;;;;; +120C9;CUNEIFORM SIGN GA2 TIMES EN;Lo;0;L;;;;;N;;;;; +120CA;CUNEIFORM SIGN GA2 TIMES EN TIMES GAN2 TENU;Lo;0;L;;;;;N;;;;; +120CB;CUNEIFORM SIGN GA2 TIMES GAN2 TENU;Lo;0;L;;;;;N;;;;; +120CC;CUNEIFORM SIGN GA2 TIMES GAR;Lo;0;L;;;;;N;;;;; +120CD;CUNEIFORM SIGN GA2 TIMES GI;Lo;0;L;;;;;N;;;;; +120CE;CUNEIFORM SIGN GA2 TIMES GI4;Lo;0;L;;;;;N;;;;; +120CF;CUNEIFORM SIGN GA2 TIMES GI4 PLUS A;Lo;0;L;;;;;N;;;;; +120D0;CUNEIFORM SIGN GA2 TIMES GIR2 PLUS SU;Lo;0;L;;;;;N;;;;; +120D1;CUNEIFORM SIGN GA2 TIMES HA PLUS LU PLUS ESH2;Lo;0;L;;;;;N;;;;; +120D2;CUNEIFORM SIGN GA2 TIMES HAL;Lo;0;L;;;;;N;;;;; +120D3;CUNEIFORM SIGN GA2 TIMES HAL PLUS LA;Lo;0;L;;;;;N;;;;; +120D4;CUNEIFORM SIGN GA2 TIMES HI PLUS LI;Lo;0;L;;;;;N;;;;; +120D5;CUNEIFORM SIGN GA2 TIMES HUB2;Lo;0;L;;;;;N;;;;; +120D6;CUNEIFORM SIGN GA2 TIMES IGI GUNU;Lo;0;L;;;;;N;;;;; +120D7;CUNEIFORM SIGN GA2 TIMES ISH PLUS HU PLUS ASH;Lo;0;L;;;;;N;;;;; +120D8;CUNEIFORM SIGN GA2 TIMES KAK;Lo;0;L;;;;;N;;;;; +120D9;CUNEIFORM SIGN GA2 TIMES KASKAL;Lo;0;L;;;;;N;;;;; +120DA;CUNEIFORM SIGN GA2 TIMES KID;Lo;0;L;;;;;N;;;;; +120DB;CUNEIFORM SIGN GA2 TIMES KID PLUS LAL;Lo;0;L;;;;;N;;;;; +120DC;CUNEIFORM SIGN GA2 TIMES KU3 PLUS AN;Lo;0;L;;;;;N;;;;; +120DD;CUNEIFORM SIGN GA2 TIMES LA;Lo;0;L;;;;;N;;;;; +120DE;CUNEIFORM SIGN GA2 TIMES ME PLUS EN;Lo;0;L;;;;;N;;;;; +120DF;CUNEIFORM SIGN GA2 TIMES MI;Lo;0;L;;;;;N;;;;; +120E0;CUNEIFORM SIGN GA2 TIMES NUN;Lo;0;L;;;;;N;;;;; +120E1;CUNEIFORM SIGN GA2 TIMES NUN OVER NUN;Lo;0;L;;;;;N;;;;; +120E2;CUNEIFORM SIGN GA2 TIMES PA;Lo;0;L;;;;;N;;;;; +120E3;CUNEIFORM SIGN GA2 TIMES SAL;Lo;0;L;;;;;N;;;;; +120E4;CUNEIFORM SIGN GA2 TIMES SAR;Lo;0;L;;;;;N;;;;; +120E5;CUNEIFORM SIGN GA2 TIMES SHE;Lo;0;L;;;;;N;;;;; +120E6;CUNEIFORM SIGN GA2 TIMES SHE PLUS TUR;Lo;0;L;;;;;N;;;;; +120E7;CUNEIFORM SIGN GA2 TIMES SHID;Lo;0;L;;;;;N;;;;; +120E8;CUNEIFORM SIGN GA2 TIMES SUM;Lo;0;L;;;;;N;;;;; +120E9;CUNEIFORM SIGN GA2 TIMES TAK4;Lo;0;L;;;;;N;;;;; +120EA;CUNEIFORM SIGN GA2 TIMES U;Lo;0;L;;;;;N;;;;; +120EB;CUNEIFORM SIGN GA2 TIMES UD;Lo;0;L;;;;;N;;;;; +120EC;CUNEIFORM SIGN GA2 TIMES UD PLUS DU;Lo;0;L;;;;;N;;;;; +120ED;CUNEIFORM SIGN GA2 OVER GA2;Lo;0;L;;;;;N;;;;; +120EE;CUNEIFORM SIGN GABA;Lo;0;L;;;;;N;;;;; +120EF;CUNEIFORM SIGN GABA CROSSING GABA;Lo;0;L;;;;;N;;;;; +120F0;CUNEIFORM SIGN GAD;Lo;0;L;;;;;N;;;;; +120F1;CUNEIFORM SIGN GAD OVER GAD GAR OVER GAR;Lo;0;L;;;;;N;;;;; +120F2;CUNEIFORM SIGN GAL;Lo;0;L;;;;;N;;;;; +120F3;CUNEIFORM SIGN GAL GAD OVER GAD GAR OVER GAR;Lo;0;L;;;;;N;;;;; +120F4;CUNEIFORM SIGN GALAM;Lo;0;L;;;;;N;;;;; +120F5;CUNEIFORM SIGN GAM;Lo;0;L;;;;;N;;;;; +120F6;CUNEIFORM SIGN GAN;Lo;0;L;;;;;N;;;;; +120F7;CUNEIFORM SIGN GAN2;Lo;0;L;;;;;N;;;;; +120F8;CUNEIFORM SIGN GAN2 TENU;Lo;0;L;;;;;N;;;;; +120F9;CUNEIFORM SIGN GAN2 OVER GAN2;Lo;0;L;;;;;N;;;;; +120FA;CUNEIFORM SIGN GAN2 CROSSING GAN2;Lo;0;L;;;;;N;;;;; +120FB;CUNEIFORM SIGN GAR;Lo;0;L;;;;;N;;;;; +120FC;CUNEIFORM SIGN GAR3;Lo;0;L;;;;;N;;;;; +120FD;CUNEIFORM SIGN GASHAN;Lo;0;L;;;;;N;;;;; +120FE;CUNEIFORM SIGN GESHTIN;Lo;0;L;;;;;N;;;;; +120FF;CUNEIFORM SIGN GESHTIN TIMES KUR;Lo;0;L;;;;;N;;;;; +12100;CUNEIFORM SIGN GI;Lo;0;L;;;;;N;;;;; +12101;CUNEIFORM SIGN GI TIMES E;Lo;0;L;;;;;N;;;;; +12102;CUNEIFORM SIGN GI TIMES U;Lo;0;L;;;;;N;;;;; +12103;CUNEIFORM SIGN GI CROSSING GI;Lo;0;L;;;;;N;;;;; +12104;CUNEIFORM SIGN GI4;Lo;0;L;;;;;N;;;;; +12105;CUNEIFORM SIGN GI4 OVER GI4;Lo;0;L;;;;;N;;;;; +12106;CUNEIFORM SIGN GI4 CROSSING GI4;Lo;0;L;;;;;N;;;;; +12107;CUNEIFORM SIGN GIDIM;Lo;0;L;;;;;N;;;;; +12108;CUNEIFORM SIGN GIR2;Lo;0;L;;;;;N;;;;; +12109;CUNEIFORM SIGN GIR2 GUNU;Lo;0;L;;;;;N;;;;; +1210A;CUNEIFORM SIGN GIR3;Lo;0;L;;;;;N;;;;; +1210B;CUNEIFORM SIGN GIR3 TIMES A PLUS IGI;Lo;0;L;;;;;N;;;;; +1210C;CUNEIFORM SIGN GIR3 TIMES GAN2 TENU;Lo;0;L;;;;;N;;;;; +1210D;CUNEIFORM SIGN GIR3 TIMES IGI;Lo;0;L;;;;;N;;;;; +1210E;CUNEIFORM SIGN GIR3 TIMES LU PLUS IGI;Lo;0;L;;;;;N;;;;; +1210F;CUNEIFORM SIGN GIR3 TIMES PA;Lo;0;L;;;;;N;;;;; +12110;CUNEIFORM SIGN GISAL;Lo;0;L;;;;;N;;;;; +12111;CUNEIFORM SIGN GISH;Lo;0;L;;;;;N;;;;; +12112;CUNEIFORM SIGN GISH CROSSING GISH;Lo;0;L;;;;;N;;;;; +12113;CUNEIFORM SIGN GISH TIMES BAD;Lo;0;L;;;;;N;;;;; +12114;CUNEIFORM SIGN GISH TIMES TAK4;Lo;0;L;;;;;N;;;;; +12115;CUNEIFORM SIGN GISH TENU;Lo;0;L;;;;;N;;;;; +12116;CUNEIFORM SIGN GU;Lo;0;L;;;;;N;;;;; +12117;CUNEIFORM SIGN GU CROSSING GU;Lo;0;L;;;;;N;;;;; +12118;CUNEIFORM SIGN GU2;Lo;0;L;;;;;N;;;;; +12119;CUNEIFORM SIGN GU2 TIMES KAK;Lo;0;L;;;;;N;;;;; +1211A;CUNEIFORM SIGN GU2 TIMES KAK TIMES IGI GUNU;Lo;0;L;;;;;N;;;;; +1211B;CUNEIFORM SIGN GU2 TIMES NUN;Lo;0;L;;;;;N;;;;; +1211C;CUNEIFORM SIGN GU2 TIMES SAL PLUS TUG2;Lo;0;L;;;;;N;;;;; +1211D;CUNEIFORM SIGN GU2 GUNU;Lo;0;L;;;;;N;;;;; +1211E;CUNEIFORM SIGN GUD;Lo;0;L;;;;;N;;;;; +1211F;CUNEIFORM SIGN GUD TIMES A PLUS KUR;Lo;0;L;;;;;N;;;;; +12120;CUNEIFORM SIGN GUD TIMES KUR;Lo;0;L;;;;;N;;;;; +12121;CUNEIFORM SIGN GUD OVER GUD LUGAL;Lo;0;L;;;;;N;;;;; +12122;CUNEIFORM SIGN GUL;Lo;0;L;;;;;N;;;;; +12123;CUNEIFORM SIGN GUM;Lo;0;L;;;;;N;;;;; +12124;CUNEIFORM SIGN GUM TIMES SHE;Lo;0;L;;;;;N;;;;; +12125;CUNEIFORM SIGN GUR;Lo;0;L;;;;;N;;;;; +12126;CUNEIFORM SIGN GUR7;Lo;0;L;;;;;N;;;;; +12127;CUNEIFORM SIGN GURUN;Lo;0;L;;;;;N;;;;; +12128;CUNEIFORM SIGN GURUSH;Lo;0;L;;;;;N;;;;; +12129;CUNEIFORM SIGN HA;Lo;0;L;;;;;N;;;;; +1212A;CUNEIFORM SIGN HA TENU;Lo;0;L;;;;;N;;;;; +1212B;CUNEIFORM SIGN HA GUNU;Lo;0;L;;;;;N;;;;; +1212C;CUNEIFORM SIGN HAL;Lo;0;L;;;;;N;;;;; +1212D;CUNEIFORM SIGN HI;Lo;0;L;;;;;N;;;;; +1212E;CUNEIFORM SIGN HI TIMES ASH;Lo;0;L;;;;;N;;;;; +1212F;CUNEIFORM SIGN HI TIMES ASH2;Lo;0;L;;;;;N;;;;; +12130;CUNEIFORM SIGN HI TIMES BAD;Lo;0;L;;;;;N;;;;; +12131;CUNEIFORM SIGN HI TIMES DISH;Lo;0;L;;;;;N;;;;; +12132;CUNEIFORM SIGN HI TIMES GAD;Lo;0;L;;;;;N;;;;; +12133;CUNEIFORM SIGN HI TIMES KIN;Lo;0;L;;;;;N;;;;; +12134;CUNEIFORM SIGN HI TIMES NUN;Lo;0;L;;;;;N;;;;; +12135;CUNEIFORM SIGN HI TIMES SHE;Lo;0;L;;;;;N;;;;; +12136;CUNEIFORM SIGN HI TIMES U;Lo;0;L;;;;;N;;;;; +12137;CUNEIFORM SIGN HU;Lo;0;L;;;;;N;;;;; +12138;CUNEIFORM SIGN HUB2;Lo;0;L;;;;;N;;;;; +12139;CUNEIFORM SIGN HUB2 TIMES AN;Lo;0;L;;;;;N;;;;; +1213A;CUNEIFORM SIGN HUB2 TIMES HAL;Lo;0;L;;;;;N;;;;; +1213B;CUNEIFORM SIGN HUB2 TIMES KASKAL;Lo;0;L;;;;;N;;;;; +1213C;CUNEIFORM SIGN HUB2 TIMES LISH;Lo;0;L;;;;;N;;;;; +1213D;CUNEIFORM SIGN HUB2 TIMES UD;Lo;0;L;;;;;N;;;;; +1213E;CUNEIFORM SIGN HUL2;Lo;0;L;;;;;N;;;;; +1213F;CUNEIFORM SIGN I;Lo;0;L;;;;;N;;;;; +12140;CUNEIFORM SIGN I A;Lo;0;L;;;;;N;;;;; +12141;CUNEIFORM SIGN IB;Lo;0;L;;;;;N;;;;; +12142;CUNEIFORM SIGN IDIM;Lo;0;L;;;;;N;;;;; +12143;CUNEIFORM SIGN IDIM OVER IDIM BUR;Lo;0;L;;;;;N;;;;; +12144;CUNEIFORM SIGN IDIM OVER IDIM SQUARED;Lo;0;L;;;;;N;;;;; +12145;CUNEIFORM SIGN IG;Lo;0;L;;;;;N;;;;; +12146;CUNEIFORM SIGN IGI;Lo;0;L;;;;;N;;;;; +12147;CUNEIFORM SIGN IGI DIB;Lo;0;L;;;;;N;;;;; +12148;CUNEIFORM SIGN IGI RI;Lo;0;L;;;;;N;;;;; +12149;CUNEIFORM SIGN IGI OVER IGI SHIR OVER SHIR UD OVER UD;Lo;0;L;;;;;N;;;;; +1214A;CUNEIFORM SIGN IGI GUNU;Lo;0;L;;;;;N;;;;; +1214B;CUNEIFORM SIGN IL;Lo;0;L;;;;;N;;;;; +1214C;CUNEIFORM SIGN IL TIMES GAN2 TENU;Lo;0;L;;;;;N;;;;; +1214D;CUNEIFORM SIGN IL2;Lo;0;L;;;;;N;;;;; +1214E;CUNEIFORM SIGN IM;Lo;0;L;;;;;N;;;;; +1214F;CUNEIFORM SIGN IM TIMES TAK4;Lo;0;L;;;;;N;;;;; +12150;CUNEIFORM SIGN IM CROSSING IM;Lo;0;L;;;;;N;;;;; +12151;CUNEIFORM SIGN IM OPPOSING IM;Lo;0;L;;;;;N;;;;; +12152;CUNEIFORM SIGN IM SQUARED;Lo;0;L;;;;;N;;;;; +12153;CUNEIFORM SIGN IMIN;Lo;0;L;;;;;N;;;;; +12154;CUNEIFORM SIGN IN;Lo;0;L;;;;;N;;;;; +12155;CUNEIFORM SIGN IR;Lo;0;L;;;;;N;;;;; +12156;CUNEIFORM SIGN ISH;Lo;0;L;;;;;N;;;;; +12157;CUNEIFORM SIGN KA;Lo;0;L;;;;;N;;;;; +12158;CUNEIFORM SIGN KA TIMES A;Lo;0;L;;;;;N;;;;; +12159;CUNEIFORM SIGN KA TIMES AD;Lo;0;L;;;;;N;;;;; +1215A;CUNEIFORM SIGN KA TIMES AD PLUS KU3;Lo;0;L;;;;;N;;;;; +1215B;CUNEIFORM SIGN KA TIMES ASH2;Lo;0;L;;;;;N;;;;; +1215C;CUNEIFORM SIGN KA TIMES BAD;Lo;0;L;;;;;N;;;;; +1215D;CUNEIFORM SIGN KA TIMES BALAG;Lo;0;L;;;;;N;;;;; +1215E;CUNEIFORM SIGN KA TIMES BAR;Lo;0;L;;;;;N;;;;; +1215F;CUNEIFORM SIGN KA TIMES BI;Lo;0;L;;;;;N;;;;; +12160;CUNEIFORM SIGN KA TIMES ERIN2;Lo;0;L;;;;;N;;;;; +12161;CUNEIFORM SIGN KA TIMES ESH2;Lo;0;L;;;;;N;;;;; +12162;CUNEIFORM SIGN KA TIMES GA;Lo;0;L;;;;;N;;;;; +12163;CUNEIFORM SIGN KA TIMES GAL;Lo;0;L;;;;;N;;;;; +12164;CUNEIFORM SIGN KA TIMES GAN2 TENU;Lo;0;L;;;;;N;;;;; +12165;CUNEIFORM SIGN KA TIMES GAR;Lo;0;L;;;;;N;;;;; +12166;CUNEIFORM SIGN KA TIMES GAR PLUS SHA3 PLUS A;Lo;0;L;;;;;N;;;;; +12167;CUNEIFORM SIGN KA TIMES GI;Lo;0;L;;;;;N;;;;; +12168;CUNEIFORM SIGN KA TIMES GIR2;Lo;0;L;;;;;N;;;;; +12169;CUNEIFORM SIGN KA TIMES GISH PLUS SAR;Lo;0;L;;;;;N;;;;; +1216A;CUNEIFORM SIGN KA TIMES GISH CROSSING GISH;Lo;0;L;;;;;N;;;;; +1216B;CUNEIFORM SIGN KA TIMES GU;Lo;0;L;;;;;N;;;;; +1216C;CUNEIFORM SIGN KA TIMES GUR7;Lo;0;L;;;;;N;;;;; +1216D;CUNEIFORM SIGN KA TIMES IGI;Lo;0;L;;;;;N;;;;; +1216E;CUNEIFORM SIGN KA TIMES IM;Lo;0;L;;;;;N;;;;; +1216F;CUNEIFORM SIGN KA TIMES KAK;Lo;0;L;;;;;N;;;;; +12170;CUNEIFORM SIGN KA TIMES KI;Lo;0;L;;;;;N;;;;; +12171;CUNEIFORM SIGN KA TIMES KID;Lo;0;L;;;;;N;;;;; +12172;CUNEIFORM SIGN KA TIMES LI;Lo;0;L;;;;;N;;;;; +12173;CUNEIFORM SIGN KA TIMES LU;Lo;0;L;;;;;N;;;;; +12174;CUNEIFORM SIGN KA TIMES ME;Lo;0;L;;;;;N;;;;; +12175;CUNEIFORM SIGN KA TIMES ME PLUS DU;Lo;0;L;;;;;N;;;;; +12176;CUNEIFORM SIGN KA TIMES ME PLUS GI;Lo;0;L;;;;;N;;;;; +12177;CUNEIFORM SIGN KA TIMES ME PLUS TE;Lo;0;L;;;;;N;;;;; +12178;CUNEIFORM SIGN KA TIMES MI;Lo;0;L;;;;;N;;;;; +12179;CUNEIFORM SIGN KA TIMES MI PLUS NUNUZ;Lo;0;L;;;;;N;;;;; +1217A;CUNEIFORM SIGN KA TIMES NE;Lo;0;L;;;;;N;;;;; +1217B;CUNEIFORM SIGN KA TIMES NUN;Lo;0;L;;;;;N;;;;; +1217C;CUNEIFORM SIGN KA TIMES PI;Lo;0;L;;;;;N;;;;; +1217D;CUNEIFORM SIGN KA TIMES RU;Lo;0;L;;;;;N;;;;; +1217E;CUNEIFORM SIGN KA TIMES SA;Lo;0;L;;;;;N;;;;; +1217F;CUNEIFORM SIGN KA TIMES SAR;Lo;0;L;;;;;N;;;;; +12180;CUNEIFORM SIGN KA TIMES SHA;Lo;0;L;;;;;N;;;;; +12181;CUNEIFORM SIGN KA TIMES SHE;Lo;0;L;;;;;N;;;;; +12182;CUNEIFORM SIGN KA TIMES SHID;Lo;0;L;;;;;N;;;;; +12183;CUNEIFORM SIGN KA TIMES SHU;Lo;0;L;;;;;N;;;;; +12184;CUNEIFORM SIGN KA TIMES SIG;Lo;0;L;;;;;N;;;;; +12185;CUNEIFORM SIGN KA TIMES SUHUR;Lo;0;L;;;;;N;;;;; +12186;CUNEIFORM SIGN KA TIMES TAR;Lo;0;L;;;;;N;;;;; +12187;CUNEIFORM SIGN KA TIMES U;Lo;0;L;;;;;N;;;;; +12188;CUNEIFORM SIGN KA TIMES U2;Lo;0;L;;;;;N;;;;; +12189;CUNEIFORM SIGN KA TIMES UD;Lo;0;L;;;;;N;;;;; +1218A;CUNEIFORM SIGN KA TIMES UMUM TIMES PA;Lo;0;L;;;;;N;;;;; +1218B;CUNEIFORM SIGN KA TIMES USH;Lo;0;L;;;;;N;;;;; +1218C;CUNEIFORM SIGN KA TIMES ZI;Lo;0;L;;;;;N;;;;; +1218D;CUNEIFORM SIGN KA2;Lo;0;L;;;;;N;;;;; +1218E;CUNEIFORM SIGN KA2 CROSSING KA2;Lo;0;L;;;;;N;;;;; +1218F;CUNEIFORM SIGN KAB;Lo;0;L;;;;;N;;;;; +12190;CUNEIFORM SIGN KAD2;Lo;0;L;;;;;N;;;;; +12191;CUNEIFORM SIGN KAD3;Lo;0;L;;;;;N;;;;; +12192;CUNEIFORM SIGN KAD4;Lo;0;L;;;;;N;;;;; +12193;CUNEIFORM SIGN KAD5;Lo;0;L;;;;;N;;;;; +12194;CUNEIFORM SIGN KAD5 OVER KAD5;Lo;0;L;;;;;N;;;;; +12195;CUNEIFORM SIGN KAK;Lo;0;L;;;;;N;;;;; +12196;CUNEIFORM SIGN KAK TIMES IGI GUNU;Lo;0;L;;;;;N;;;;; +12197;CUNEIFORM SIGN KAL;Lo;0;L;;;;;N;;;;; +12198;CUNEIFORM SIGN KAL TIMES BAD;Lo;0;L;;;;;N;;;;; +12199;CUNEIFORM SIGN KAL CROSSING KAL;Lo;0;L;;;;;N;;;;; +1219A;CUNEIFORM SIGN KAM2;Lo;0;L;;;;;N;;;;; +1219B;CUNEIFORM SIGN KAM4;Lo;0;L;;;;;N;;;;; +1219C;CUNEIFORM SIGN KASKAL;Lo;0;L;;;;;N;;;;; +1219D;CUNEIFORM SIGN KASKAL LAGAB TIMES U OVER LAGAB TIMES U;Lo;0;L;;;;;N;;;;; +1219E;CUNEIFORM SIGN KASKAL OVER KASKAL LAGAB TIMES U OVER LAGAB TIMES U;Lo;0;L;;;;;N;;;;; +1219F;CUNEIFORM SIGN KESH2;Lo;0;L;;;;;N;;;;; +121A0;CUNEIFORM SIGN KI;Lo;0;L;;;;;N;;;;; +121A1;CUNEIFORM SIGN KI TIMES BAD;Lo;0;L;;;;;N;;;;; +121A2;CUNEIFORM SIGN KI TIMES U;Lo;0;L;;;;;N;;;;; +121A3;CUNEIFORM SIGN KI TIMES UD;Lo;0;L;;;;;N;;;;; +121A4;CUNEIFORM SIGN KID;Lo;0;L;;;;;N;;;;; +121A5;CUNEIFORM SIGN KIN;Lo;0;L;;;;;N;;;;; +121A6;CUNEIFORM SIGN KISAL;Lo;0;L;;;;;N;;;;; +121A7;CUNEIFORM SIGN KISH;Lo;0;L;;;;;N;;;;; +121A8;CUNEIFORM SIGN KISIM5;Lo;0;L;;;;;N;;;;; +121A9;CUNEIFORM SIGN KISIM5 OVER KISIM5;Lo;0;L;;;;;N;;;;; +121AA;CUNEIFORM SIGN KU;Lo;0;L;;;;;N;;;;; +121AB;CUNEIFORM SIGN KU OVER HI TIMES ASH2 KU OVER HI TIMES ASH2;Lo;0;L;;;;;N;;;;; +121AC;CUNEIFORM SIGN KU3;Lo;0;L;;;;;N;;;;; +121AD;CUNEIFORM SIGN KU4;Lo;0;L;;;;;N;;;;; +121AE;CUNEIFORM SIGN KU4 VARIANT FORM;Lo;0;L;;;;;N;;;;; +121AF;CUNEIFORM SIGN KU7;Lo;0;L;;;;;N;;;;; +121B0;CUNEIFORM SIGN KUL;Lo;0;L;;;;;N;;;;; +121B1;CUNEIFORM SIGN KUL GUNU;Lo;0;L;;;;;N;;;;; +121B2;CUNEIFORM SIGN KUN;Lo;0;L;;;;;N;;;;; +121B3;CUNEIFORM SIGN KUR;Lo;0;L;;;;;N;;;;; +121B4;CUNEIFORM SIGN KUR OPPOSING KUR;Lo;0;L;;;;;N;;;;; +121B5;CUNEIFORM SIGN KUSHU2;Lo;0;L;;;;;N;;;;; +121B6;CUNEIFORM SIGN KWU318;Lo;0;L;;;;;N;;;;; +121B7;CUNEIFORM SIGN LA;Lo;0;L;;;;;N;;;;; +121B8;CUNEIFORM SIGN LAGAB;Lo;0;L;;;;;N;;;;; +121B9;CUNEIFORM SIGN LAGAB TIMES A;Lo;0;L;;;;;N;;;;; +121BA;CUNEIFORM SIGN LAGAB TIMES A PLUS DA PLUS HA;Lo;0;L;;;;;N;;;;; +121BB;CUNEIFORM SIGN LAGAB TIMES A PLUS GAR;Lo;0;L;;;;;N;;;;; +121BC;CUNEIFORM SIGN LAGAB TIMES A PLUS LAL;Lo;0;L;;;;;N;;;;; +121BD;CUNEIFORM SIGN LAGAB TIMES AL;Lo;0;L;;;;;N;;;;; +121BE;CUNEIFORM SIGN LAGAB TIMES AN;Lo;0;L;;;;;N;;;;; +121BF;CUNEIFORM SIGN LAGAB TIMES ASH ZIDA TENU;Lo;0;L;;;;;N;;;;; +121C0;CUNEIFORM SIGN LAGAB TIMES BAD;Lo;0;L;;;;;N;;;;; +121C1;CUNEIFORM SIGN LAGAB TIMES BI;Lo;0;L;;;;;N;;;;; +121C2;CUNEIFORM SIGN LAGAB TIMES DAR;Lo;0;L;;;;;N;;;;; +121C3;CUNEIFORM SIGN LAGAB TIMES EN;Lo;0;L;;;;;N;;;;; +121C4;CUNEIFORM SIGN LAGAB TIMES GA;Lo;0;L;;;;;N;;;;; +121C5;CUNEIFORM SIGN LAGAB TIMES GAR;Lo;0;L;;;;;N;;;;; +121C6;CUNEIFORM SIGN LAGAB TIMES GUD;Lo;0;L;;;;;N;;;;; +121C7;CUNEIFORM SIGN LAGAB TIMES GUD PLUS GUD;Lo;0;L;;;;;N;;;;; +121C8;CUNEIFORM SIGN LAGAB TIMES HA;Lo;0;L;;;;;N;;;;; +121C9;CUNEIFORM SIGN LAGAB TIMES HAL;Lo;0;L;;;;;N;;;;; +121CA;CUNEIFORM SIGN LAGAB TIMES HI TIMES NUN;Lo;0;L;;;;;N;;;;; +121CB;CUNEIFORM SIGN LAGAB TIMES IGI GUNU;Lo;0;L;;;;;N;;;;; +121CC;CUNEIFORM SIGN LAGAB TIMES IM;Lo;0;L;;;;;N;;;;; +121CD;CUNEIFORM SIGN LAGAB TIMES IM PLUS HA;Lo;0;L;;;;;N;;;;; +121CE;CUNEIFORM SIGN LAGAB TIMES IM PLUS LU;Lo;0;L;;;;;N;;;;; +121CF;CUNEIFORM SIGN LAGAB TIMES KI;Lo;0;L;;;;;N;;;;; +121D0;CUNEIFORM SIGN LAGAB TIMES KIN;Lo;0;L;;;;;N;;;;; +121D1;CUNEIFORM SIGN LAGAB TIMES KU3;Lo;0;L;;;;;N;;;;; +121D2;CUNEIFORM SIGN LAGAB TIMES KUL;Lo;0;L;;;;;N;;;;; +121D3;CUNEIFORM SIGN LAGAB TIMES KUL PLUS HI PLUS A;Lo;0;L;;;;;N;;;;; +121D4;CUNEIFORM SIGN LAGAB TIMES LAGAB;Lo;0;L;;;;;N;;;;; +121D5;CUNEIFORM SIGN LAGAB TIMES LISH;Lo;0;L;;;;;N;;;;; +121D6;CUNEIFORM SIGN LAGAB TIMES LU;Lo;0;L;;;;;N;;;;; +121D7;CUNEIFORM SIGN LAGAB TIMES LUL;Lo;0;L;;;;;N;;;;; +121D8;CUNEIFORM SIGN LAGAB TIMES ME;Lo;0;L;;;;;N;;;;; +121D9;CUNEIFORM SIGN LAGAB TIMES ME PLUS EN;Lo;0;L;;;;;N;;;;; +121DA;CUNEIFORM SIGN LAGAB TIMES MUSH;Lo;0;L;;;;;N;;;;; +121DB;CUNEIFORM SIGN LAGAB TIMES NE;Lo;0;L;;;;;N;;;;; +121DC;CUNEIFORM SIGN LAGAB TIMES SHE PLUS SUM;Lo;0;L;;;;;N;;;;; +121DD;CUNEIFORM SIGN LAGAB TIMES SHITA PLUS GISH PLUS ERIN2;Lo;0;L;;;;;N;;;;; +121DE;CUNEIFORM SIGN LAGAB TIMES SHITA PLUS GISH TENU;Lo;0;L;;;;;N;;;;; +121DF;CUNEIFORM SIGN LAGAB TIMES SHU2;Lo;0;L;;;;;N;;;;; +121E0;CUNEIFORM SIGN LAGAB TIMES SHU2 PLUS SHU2;Lo;0;L;;;;;N;;;;; +121E1;CUNEIFORM SIGN LAGAB TIMES SUM;Lo;0;L;;;;;N;;;;; +121E2;CUNEIFORM SIGN LAGAB TIMES TAG;Lo;0;L;;;;;N;;;;; +121E3;CUNEIFORM SIGN LAGAB TIMES TAK4;Lo;0;L;;;;;N;;;;; +121E4;CUNEIFORM SIGN LAGAB TIMES TE PLUS A PLUS SU PLUS NA;Lo;0;L;;;;;N;;;;; +121E5;CUNEIFORM SIGN LAGAB TIMES U;Lo;0;L;;;;;N;;;;; +121E6;CUNEIFORM SIGN LAGAB TIMES U PLUS A;Lo;0;L;;;;;N;;;;; +121E7;CUNEIFORM SIGN LAGAB TIMES U PLUS U PLUS U;Lo;0;L;;;;;N;;;;; +121E8;CUNEIFORM SIGN LAGAB TIMES U2 PLUS ASH;Lo;0;L;;;;;N;;;;; +121E9;CUNEIFORM SIGN LAGAB TIMES UD;Lo;0;L;;;;;N;;;;; +121EA;CUNEIFORM SIGN LAGAB TIMES USH;Lo;0;L;;;;;N;;;;; +121EB;CUNEIFORM SIGN LAGAB SQUARED;Lo;0;L;;;;;N;;;;; +121EC;CUNEIFORM SIGN LAGAR;Lo;0;L;;;;;N;;;;; +121ED;CUNEIFORM SIGN LAGAR TIMES SHE;Lo;0;L;;;;;N;;;;; +121EE;CUNEIFORM SIGN LAGAR TIMES SHE PLUS SUM;Lo;0;L;;;;;N;;;;; +121EF;CUNEIFORM SIGN LAGAR GUNU;Lo;0;L;;;;;N;;;;; +121F0;CUNEIFORM SIGN LAGAR GUNU OVER LAGAR GUNU SHE;Lo;0;L;;;;;N;;;;; +121F1;CUNEIFORM SIGN LAHSHU;Lo;0;L;;;;;N;;;;; +121F2;CUNEIFORM SIGN LAL;Lo;0;L;;;;;N;;;;; +121F3;CUNEIFORM SIGN LAL TIMES LAL;Lo;0;L;;;;;N;;;;; +121F4;CUNEIFORM SIGN LAM;Lo;0;L;;;;;N;;;;; +121F5;CUNEIFORM SIGN LAM TIMES KUR;Lo;0;L;;;;;N;;;;; +121F6;CUNEIFORM SIGN LAM TIMES KUR PLUS RU;Lo;0;L;;;;;N;;;;; +121F7;CUNEIFORM SIGN LI;Lo;0;L;;;;;N;;;;; +121F8;CUNEIFORM SIGN LIL;Lo;0;L;;;;;N;;;;; +121F9;CUNEIFORM SIGN LIMMU2;Lo;0;L;;;;;N;;;;; +121FA;CUNEIFORM SIGN LISH;Lo;0;L;;;;;N;;;;; +121FB;CUNEIFORM SIGN LU;Lo;0;L;;;;;N;;;;; +121FC;CUNEIFORM SIGN LU TIMES BAD;Lo;0;L;;;;;N;;;;; +121FD;CUNEIFORM SIGN LU2;Lo;0;L;;;;;N;;;;; +121FE;CUNEIFORM SIGN LU2 TIMES AL;Lo;0;L;;;;;N;;;;; +121FF;CUNEIFORM SIGN LU2 TIMES BAD;Lo;0;L;;;;;N;;;;; +12200;CUNEIFORM SIGN LU2 TIMES ESH2;Lo;0;L;;;;;N;;;;; +12201;CUNEIFORM SIGN LU2 TIMES ESH2 TENU;Lo;0;L;;;;;N;;;;; +12202;CUNEIFORM SIGN LU2 TIMES GAN2 TENU;Lo;0;L;;;;;N;;;;; +12203;CUNEIFORM SIGN LU2 TIMES HI TIMES BAD;Lo;0;L;;;;;N;;;;; +12204;CUNEIFORM SIGN LU2 TIMES IM;Lo;0;L;;;;;N;;;;; +12205;CUNEIFORM SIGN LU2 TIMES KAD2;Lo;0;L;;;;;N;;;;; +12206;CUNEIFORM SIGN LU2 TIMES KAD3;Lo;0;L;;;;;N;;;;; +12207;CUNEIFORM SIGN LU2 TIMES KAD3 PLUS ASH;Lo;0;L;;;;;N;;;;; +12208;CUNEIFORM SIGN LU2 TIMES KI;Lo;0;L;;;;;N;;;;; +12209;CUNEIFORM SIGN LU2 TIMES LA PLUS ASH;Lo;0;L;;;;;N;;;;; +1220A;CUNEIFORM SIGN LU2 TIMES LAGAB;Lo;0;L;;;;;N;;;;; +1220B;CUNEIFORM SIGN LU2 TIMES ME PLUS EN;Lo;0;L;;;;;N;;;;; +1220C;CUNEIFORM SIGN LU2 TIMES NE;Lo;0;L;;;;;N;;;;; +1220D;CUNEIFORM SIGN LU2 TIMES NU;Lo;0;L;;;;;N;;;;; +1220E;CUNEIFORM SIGN LU2 TIMES SI PLUS ASH;Lo;0;L;;;;;N;;;;; +1220F;CUNEIFORM SIGN LU2 TIMES SIK2 PLUS BU;Lo;0;L;;;;;N;;;;; +12210;CUNEIFORM SIGN LU2 TIMES TUG2;Lo;0;L;;;;;N;;;;; +12211;CUNEIFORM SIGN LU2 TENU;Lo;0;L;;;;;N;;;;; +12212;CUNEIFORM SIGN LU2 CROSSING LU2;Lo;0;L;;;;;N;;;;; +12213;CUNEIFORM SIGN LU2 OPPOSING LU2;Lo;0;L;;;;;N;;;;; +12214;CUNEIFORM SIGN LU2 SQUARED;Lo;0;L;;;;;N;;;;; +12215;CUNEIFORM SIGN LU2 SHESHIG;Lo;0;L;;;;;N;;;;; +12216;CUNEIFORM SIGN LU3;Lo;0;L;;;;;N;;;;; +12217;CUNEIFORM SIGN LUGAL;Lo;0;L;;;;;N;;;;; +12218;CUNEIFORM SIGN LUGAL OVER LUGAL;Lo;0;L;;;;;N;;;;; +12219;CUNEIFORM SIGN LUGAL OPPOSING LUGAL;Lo;0;L;;;;;N;;;;; +1221A;CUNEIFORM SIGN LUGAL SHESHIG;Lo;0;L;;;;;N;;;;; +1221B;CUNEIFORM SIGN LUH;Lo;0;L;;;;;N;;;;; +1221C;CUNEIFORM SIGN LUL;Lo;0;L;;;;;N;;;;; +1221D;CUNEIFORM SIGN LUM;Lo;0;L;;;;;N;;;;; +1221E;CUNEIFORM SIGN LUM OVER LUM;Lo;0;L;;;;;N;;;;; +1221F;CUNEIFORM SIGN LUM OVER LUM GAR OVER GAR;Lo;0;L;;;;;N;;;;; +12220;CUNEIFORM SIGN MA;Lo;0;L;;;;;N;;;;; +12221;CUNEIFORM SIGN MA TIMES TAK4;Lo;0;L;;;;;N;;;;; +12222;CUNEIFORM SIGN MA GUNU;Lo;0;L;;;;;N;;;;; +12223;CUNEIFORM SIGN MA2;Lo;0;L;;;;;N;;;;; +12224;CUNEIFORM SIGN MAH;Lo;0;L;;;;;N;;;;; +12225;CUNEIFORM SIGN MAR;Lo;0;L;;;;;N;;;;; +12226;CUNEIFORM SIGN MASH;Lo;0;L;;;;;N;;;;; +12227;CUNEIFORM SIGN MASH2;Lo;0;L;;;;;N;;;;; +12228;CUNEIFORM SIGN ME;Lo;0;L;;;;;N;;;;; +12229;CUNEIFORM SIGN MES;Lo;0;L;;;;;N;;;;; +1222A;CUNEIFORM SIGN MI;Lo;0;L;;;;;N;;;;; +1222B;CUNEIFORM SIGN MIN;Lo;0;L;;;;;N;;;;; +1222C;CUNEIFORM SIGN MU;Lo;0;L;;;;;N;;;;; +1222D;CUNEIFORM SIGN MU OVER MU;Lo;0;L;;;;;N;;;;; +1222E;CUNEIFORM SIGN MUG;Lo;0;L;;;;;N;;;;; +1222F;CUNEIFORM SIGN MUG GUNU;Lo;0;L;;;;;N;;;;; +12230;CUNEIFORM SIGN MUNSUB;Lo;0;L;;;;;N;;;;; +12231;CUNEIFORM SIGN MURGU2;Lo;0;L;;;;;N;;;;; +12232;CUNEIFORM SIGN MUSH;Lo;0;L;;;;;N;;;;; +12233;CUNEIFORM SIGN MUSH TIMES A;Lo;0;L;;;;;N;;;;; +12234;CUNEIFORM SIGN MUSH TIMES KUR;Lo;0;L;;;;;N;;;;; +12235;CUNEIFORM SIGN MUSH TIMES ZA;Lo;0;L;;;;;N;;;;; +12236;CUNEIFORM SIGN MUSH OVER MUSH;Lo;0;L;;;;;N;;;;; +12237;CUNEIFORM SIGN MUSH OVER MUSH TIMES A PLUS NA;Lo;0;L;;;;;N;;;;; +12238;CUNEIFORM SIGN MUSH CROSSING MUSH;Lo;0;L;;;;;N;;;;; +12239;CUNEIFORM SIGN MUSH3;Lo;0;L;;;;;N;;;;; +1223A;CUNEIFORM SIGN MUSH3 TIMES A;Lo;0;L;;;;;N;;;;; +1223B;CUNEIFORM SIGN MUSH3 TIMES A PLUS DI;Lo;0;L;;;;;N;;;;; +1223C;CUNEIFORM SIGN MUSH3 TIMES DI;Lo;0;L;;;;;N;;;;; +1223D;CUNEIFORM SIGN MUSH3 GUNU;Lo;0;L;;;;;N;;;;; +1223E;CUNEIFORM SIGN NA;Lo;0;L;;;;;N;;;;; +1223F;CUNEIFORM SIGN NA2;Lo;0;L;;;;;N;;;;; +12240;CUNEIFORM SIGN NAGA;Lo;0;L;;;;;N;;;;; +12241;CUNEIFORM SIGN NAGA INVERTED;Lo;0;L;;;;;N;;;;; +12242;CUNEIFORM SIGN NAGA TIMES SHU TENU;Lo;0;L;;;;;N;;;;; +12243;CUNEIFORM SIGN NAGA OPPOSING NAGA;Lo;0;L;;;;;N;;;;; +12244;CUNEIFORM SIGN NAGAR;Lo;0;L;;;;;N;;;;; +12245;CUNEIFORM SIGN NAM NUTILLU;Lo;0;L;;;;;N;;;;; +12246;CUNEIFORM SIGN NAM;Lo;0;L;;;;;N;;;;; +12247;CUNEIFORM SIGN NAM2;Lo;0;L;;;;;N;;;;; +12248;CUNEIFORM SIGN NE;Lo;0;L;;;;;N;;;;; +12249;CUNEIFORM SIGN NE TIMES A;Lo;0;L;;;;;N;;;;; +1224A;CUNEIFORM SIGN NE TIMES UD;Lo;0;L;;;;;N;;;;; +1224B;CUNEIFORM SIGN NE SHESHIG;Lo;0;L;;;;;N;;;;; +1224C;CUNEIFORM SIGN NI;Lo;0;L;;;;;N;;;;; +1224D;CUNEIFORM SIGN NI TIMES E;Lo;0;L;;;;;N;;;;; +1224E;CUNEIFORM SIGN NI2;Lo;0;L;;;;;N;;;;; +1224F;CUNEIFORM SIGN NIM;Lo;0;L;;;;;N;;;;; +12250;CUNEIFORM SIGN NIM TIMES GAN2 TENU;Lo;0;L;;;;;N;;;;; +12251;CUNEIFORM SIGN NIM TIMES GAR PLUS GAN2 TENU;Lo;0;L;;;;;N;;;;; +12252;CUNEIFORM SIGN NINDA2;Lo;0;L;;;;;N;;;;; +12253;CUNEIFORM SIGN NINDA2 TIMES AN;Lo;0;L;;;;;N;;;;; +12254;CUNEIFORM SIGN NINDA2 TIMES ASH;Lo;0;L;;;;;N;;;;; +12255;CUNEIFORM SIGN NINDA2 TIMES ASH PLUS ASH;Lo;0;L;;;;;N;;;;; +12256;CUNEIFORM SIGN NINDA2 TIMES GUD;Lo;0;L;;;;;N;;;;; +12257;CUNEIFORM SIGN NINDA2 TIMES ME PLUS GAN2 TENU;Lo;0;L;;;;;N;;;;; +12258;CUNEIFORM SIGN NINDA2 TIMES NE;Lo;0;L;;;;;N;;;;; +12259;CUNEIFORM SIGN NINDA2 TIMES NUN;Lo;0;L;;;;;N;;;;; +1225A;CUNEIFORM SIGN NINDA2 TIMES SHE;Lo;0;L;;;;;N;;;;; +1225B;CUNEIFORM SIGN NINDA2 TIMES SHE PLUS A AN;Lo;0;L;;;;;N;;;;; +1225C;CUNEIFORM SIGN NINDA2 TIMES SHE PLUS ASH;Lo;0;L;;;;;N;;;;; +1225D;CUNEIFORM SIGN NINDA2 TIMES SHE PLUS ASH PLUS ASH;Lo;0;L;;;;;N;;;;; +1225E;CUNEIFORM SIGN NINDA2 TIMES U2 PLUS ASH;Lo;0;L;;;;;N;;;;; +1225F;CUNEIFORM SIGN NINDA2 TIMES USH;Lo;0;L;;;;;N;;;;; +12260;CUNEIFORM SIGN NISAG;Lo;0;L;;;;;N;;;;; +12261;CUNEIFORM SIGN NU;Lo;0;L;;;;;N;;;;; +12262;CUNEIFORM SIGN NU11;Lo;0;L;;;;;N;;;;; +12263;CUNEIFORM SIGN NUN;Lo;0;L;;;;;N;;;;; +12264;CUNEIFORM SIGN NUN LAGAR TIMES GAR;Lo;0;L;;;;;N;;;;; +12265;CUNEIFORM SIGN NUN LAGAR TIMES MASH;Lo;0;L;;;;;N;;;;; +12266;CUNEIFORM SIGN NUN LAGAR TIMES SAL;Lo;0;L;;;;;N;;;;; +12267;CUNEIFORM SIGN NUN LAGAR TIMES SAL OVER NUN LAGAR TIMES SAL;Lo;0;L;;;;;N;;;;; +12268;CUNEIFORM SIGN NUN LAGAR TIMES USH;Lo;0;L;;;;;N;;;;; +12269;CUNEIFORM SIGN NUN TENU;Lo;0;L;;;;;N;;;;; +1226A;CUNEIFORM SIGN NUN OVER NUN;Lo;0;L;;;;;N;;;;; +1226B;CUNEIFORM SIGN NUN CROSSING NUN;Lo;0;L;;;;;N;;;;; +1226C;CUNEIFORM SIGN NUN CROSSING NUN LAGAR OVER LAGAR;Lo;0;L;;;;;N;;;;; +1226D;CUNEIFORM SIGN NUNUZ;Lo;0;L;;;;;N;;;;; +1226E;CUNEIFORM SIGN NUNUZ AB2 TIMES ASHGAB;Lo;0;L;;;;;N;;;;; +1226F;CUNEIFORM SIGN NUNUZ AB2 TIMES BI;Lo;0;L;;;;;N;;;;; +12270;CUNEIFORM SIGN NUNUZ AB2 TIMES DUG;Lo;0;L;;;;;N;;;;; +12271;CUNEIFORM SIGN NUNUZ AB2 TIMES GUD;Lo;0;L;;;;;N;;;;; +12272;CUNEIFORM SIGN NUNUZ AB2 TIMES IGI GUNU;Lo;0;L;;;;;N;;;;; +12273;CUNEIFORM SIGN NUNUZ AB2 TIMES KAD3;Lo;0;L;;;;;N;;;;; +12274;CUNEIFORM SIGN NUNUZ AB2 TIMES LA;Lo;0;L;;;;;N;;;;; +12275;CUNEIFORM SIGN NUNUZ AB2 TIMES NE;Lo;0;L;;;;;N;;;;; +12276;CUNEIFORM SIGN NUNUZ AB2 TIMES SILA3;Lo;0;L;;;;;N;;;;; +12277;CUNEIFORM SIGN NUNUZ AB2 TIMES U2;Lo;0;L;;;;;N;;;;; +12278;CUNEIFORM SIGN NUNUZ KISIM5 TIMES BI;Lo;0;L;;;;;N;;;;; +12279;CUNEIFORM SIGN NUNUZ KISIM5 TIMES BI U;Lo;0;L;;;;;N;;;;; +1227A;CUNEIFORM SIGN PA;Lo;0;L;;;;;N;;;;; +1227B;CUNEIFORM SIGN PAD;Lo;0;L;;;;;N;;;;; +1227C;CUNEIFORM SIGN PAN;Lo;0;L;;;;;N;;;;; +1227D;CUNEIFORM SIGN PAP;Lo;0;L;;;;;N;;;;; +1227E;CUNEIFORM SIGN PESH2;Lo;0;L;;;;;N;;;;; +1227F;CUNEIFORM SIGN PI;Lo;0;L;;;;;N;;;;; +12280;CUNEIFORM SIGN PI TIMES A;Lo;0;L;;;;;N;;;;; +12281;CUNEIFORM SIGN PI TIMES AB;Lo;0;L;;;;;N;;;;; +12282;CUNEIFORM SIGN PI TIMES BI;Lo;0;L;;;;;N;;;;; +12283;CUNEIFORM SIGN PI TIMES BU;Lo;0;L;;;;;N;;;;; +12284;CUNEIFORM SIGN PI TIMES E;Lo;0;L;;;;;N;;;;; +12285;CUNEIFORM SIGN PI TIMES I;Lo;0;L;;;;;N;;;;; +12286;CUNEIFORM SIGN PI TIMES IB;Lo;0;L;;;;;N;;;;; +12287;CUNEIFORM SIGN PI TIMES U;Lo;0;L;;;;;N;;;;; +12288;CUNEIFORM SIGN PI TIMES U2;Lo;0;L;;;;;N;;;;; +12289;CUNEIFORM SIGN PI CROSSING PI;Lo;0;L;;;;;N;;;;; +1228A;CUNEIFORM SIGN PIRIG;Lo;0;L;;;;;N;;;;; +1228B;CUNEIFORM SIGN PIRIG TIMES KAL;Lo;0;L;;;;;N;;;;; +1228C;CUNEIFORM SIGN PIRIG TIMES UD;Lo;0;L;;;;;N;;;;; +1228D;CUNEIFORM SIGN PIRIG TIMES ZA;Lo;0;L;;;;;N;;;;; +1228E;CUNEIFORM SIGN PIRIG OPPOSING PIRIG;Lo;0;L;;;;;N;;;;; +1228F;CUNEIFORM SIGN RA;Lo;0;L;;;;;N;;;;; +12290;CUNEIFORM SIGN RAB;Lo;0;L;;;;;N;;;;; +12291;CUNEIFORM SIGN RI;Lo;0;L;;;;;N;;;;; +12292;CUNEIFORM SIGN RU;Lo;0;L;;;;;N;;;;; +12293;CUNEIFORM SIGN SA;Lo;0;L;;;;;N;;;;; +12294;CUNEIFORM SIGN SAG NUTILLU;Lo;0;L;;;;;N;;;;; +12295;CUNEIFORM SIGN SAG;Lo;0;L;;;;;N;;;;; +12296;CUNEIFORM SIGN SAG TIMES A;Lo;0;L;;;;;N;;;;; +12297;CUNEIFORM SIGN SAG TIMES DU;Lo;0;L;;;;;N;;;;; +12298;CUNEIFORM SIGN SAG TIMES DUB;Lo;0;L;;;;;N;;;;; +12299;CUNEIFORM SIGN SAG TIMES HA;Lo;0;L;;;;;N;;;;; +1229A;CUNEIFORM SIGN SAG TIMES KAK;Lo;0;L;;;;;N;;;;; +1229B;CUNEIFORM SIGN SAG TIMES KUR;Lo;0;L;;;;;N;;;;; +1229C;CUNEIFORM SIGN SAG TIMES LUM;Lo;0;L;;;;;N;;;;; +1229D;CUNEIFORM SIGN SAG TIMES MI;Lo;0;L;;;;;N;;;;; +1229E;CUNEIFORM SIGN SAG TIMES NUN;Lo;0;L;;;;;N;;;;; +1229F;CUNEIFORM SIGN SAG TIMES SAL;Lo;0;L;;;;;N;;;;; +122A0;CUNEIFORM SIGN SAG TIMES SHID;Lo;0;L;;;;;N;;;;; +122A1;CUNEIFORM SIGN SAG TIMES TAB;Lo;0;L;;;;;N;;;;; +122A2;CUNEIFORM SIGN SAG TIMES U2;Lo;0;L;;;;;N;;;;; +122A3;CUNEIFORM SIGN SAG TIMES UB;Lo;0;L;;;;;N;;;;; +122A4;CUNEIFORM SIGN SAG TIMES UM;Lo;0;L;;;;;N;;;;; +122A5;CUNEIFORM SIGN SAG TIMES UR;Lo;0;L;;;;;N;;;;; +122A6;CUNEIFORM SIGN SAG TIMES USH;Lo;0;L;;;;;N;;;;; +122A7;CUNEIFORM SIGN SAG OVER SAG;Lo;0;L;;;;;N;;;;; +122A8;CUNEIFORM SIGN SAG GUNU;Lo;0;L;;;;;N;;;;; +122A9;CUNEIFORM SIGN SAL;Lo;0;L;;;;;N;;;;; +122AA;CUNEIFORM SIGN SAL LAGAB TIMES ASH2;Lo;0;L;;;;;N;;;;; +122AB;CUNEIFORM SIGN SANGA2;Lo;0;L;;;;;N;;;;; +122AC;CUNEIFORM SIGN SAR;Lo;0;L;;;;;N;;;;; +122AD;CUNEIFORM SIGN SHA;Lo;0;L;;;;;N;;;;; +122AE;CUNEIFORM SIGN SHA3;Lo;0;L;;;;;N;;;;; +122AF;CUNEIFORM SIGN SHA3 TIMES A;Lo;0;L;;;;;N;;;;; +122B0;CUNEIFORM SIGN SHA3 TIMES BAD;Lo;0;L;;;;;N;;;;; +122B1;CUNEIFORM SIGN SHA3 TIMES GISH;Lo;0;L;;;;;N;;;;; +122B2;CUNEIFORM SIGN SHA3 TIMES NE;Lo;0;L;;;;;N;;;;; +122B3;CUNEIFORM SIGN SHA3 TIMES SHU2;Lo;0;L;;;;;N;;;;; +122B4;CUNEIFORM SIGN SHA3 TIMES TUR;Lo;0;L;;;;;N;;;;; +122B5;CUNEIFORM SIGN SHA3 TIMES U;Lo;0;L;;;;;N;;;;; +122B6;CUNEIFORM SIGN SHA3 TIMES U PLUS A;Lo;0;L;;;;;N;;;;; +122B7;CUNEIFORM SIGN SHA6;Lo;0;L;;;;;N;;;;; +122B8;CUNEIFORM SIGN SHAB6;Lo;0;L;;;;;N;;;;; +122B9;CUNEIFORM SIGN SHAR2;Lo;0;L;;;;;N;;;;; +122BA;CUNEIFORM SIGN SHE;Lo;0;L;;;;;N;;;;; +122BB;CUNEIFORM SIGN SHE HU;Lo;0;L;;;;;N;;;;; +122BC;CUNEIFORM SIGN SHE OVER SHE GAD OVER GAD GAR OVER GAR;Lo;0;L;;;;;N;;;;; +122BD;CUNEIFORM SIGN SHE OVER SHE TAB OVER TAB GAR OVER GAR;Lo;0;L;;;;;N;;;;; +122BE;CUNEIFORM SIGN SHEG9;Lo;0;L;;;;;N;;;;; +122BF;CUNEIFORM SIGN SHEN;Lo;0;L;;;;;N;;;;; +122C0;CUNEIFORM SIGN SHESH;Lo;0;L;;;;;N;;;;; +122C1;CUNEIFORM SIGN SHESH2;Lo;0;L;;;;;N;;;;; +122C2;CUNEIFORM SIGN SHESHLAM;Lo;0;L;;;;;N;;;;; +122C3;CUNEIFORM SIGN SHID;Lo;0;L;;;;;N;;;;; +122C4;CUNEIFORM SIGN SHID TIMES A;Lo;0;L;;;;;N;;;;; +122C5;CUNEIFORM SIGN SHID TIMES IM;Lo;0;L;;;;;N;;;;; +122C6;CUNEIFORM SIGN SHIM;Lo;0;L;;;;;N;;;;; +122C7;CUNEIFORM SIGN SHIM TIMES A;Lo;0;L;;;;;N;;;;; +122C8;CUNEIFORM SIGN SHIM TIMES BAL;Lo;0;L;;;;;N;;;;; +122C9;CUNEIFORM SIGN SHIM TIMES BULUG;Lo;0;L;;;;;N;;;;; +122CA;CUNEIFORM SIGN SHIM TIMES DIN;Lo;0;L;;;;;N;;;;; +122CB;CUNEIFORM SIGN SHIM TIMES GAR;Lo;0;L;;;;;N;;;;; +122CC;CUNEIFORM SIGN SHIM TIMES IGI;Lo;0;L;;;;;N;;;;; +122CD;CUNEIFORM SIGN SHIM TIMES IGI GUNU;Lo;0;L;;;;;N;;;;; +122CE;CUNEIFORM SIGN SHIM TIMES KUSHU2;Lo;0;L;;;;;N;;;;; +122CF;CUNEIFORM SIGN SHIM TIMES LUL;Lo;0;L;;;;;N;;;;; +122D0;CUNEIFORM SIGN SHIM TIMES MUG;Lo;0;L;;;;;N;;;;; +122D1;CUNEIFORM SIGN SHIM TIMES SAL;Lo;0;L;;;;;N;;;;; +122D2;CUNEIFORM SIGN SHINIG;Lo;0;L;;;;;N;;;;; +122D3;CUNEIFORM SIGN SHIR;Lo;0;L;;;;;N;;;;; +122D4;CUNEIFORM SIGN SHIR TENU;Lo;0;L;;;;;N;;;;; +122D5;CUNEIFORM SIGN SHIR OVER SHIR BUR OVER BUR;Lo;0;L;;;;;N;;;;; +122D6;CUNEIFORM SIGN SHITA;Lo;0;L;;;;;N;;;;; +122D7;CUNEIFORM SIGN SHU;Lo;0;L;;;;;N;;;;; +122D8;CUNEIFORM SIGN SHU OVER INVERTED SHU;Lo;0;L;;;;;N;;;;; +122D9;CUNEIFORM SIGN SHU2;Lo;0;L;;;;;N;;;;; +122DA;CUNEIFORM SIGN SHUBUR;Lo;0;L;;;;;N;;;;; +122DB;CUNEIFORM SIGN SI;Lo;0;L;;;;;N;;;;; +122DC;CUNEIFORM SIGN SI GUNU;Lo;0;L;;;;;N;;;;; +122DD;CUNEIFORM SIGN SIG;Lo;0;L;;;;;N;;;;; +122DE;CUNEIFORM SIGN SIG4;Lo;0;L;;;;;N;;;;; +122DF;CUNEIFORM SIGN SIG4 OVER SIG4 SHU2;Lo;0;L;;;;;N;;;;; +122E0;CUNEIFORM SIGN SIK2;Lo;0;L;;;;;N;;;;; +122E1;CUNEIFORM SIGN SILA3;Lo;0;L;;;;;N;;;;; +122E2;CUNEIFORM SIGN SU;Lo;0;L;;;;;N;;;;; +122E3;CUNEIFORM SIGN SU OVER SU;Lo;0;L;;;;;N;;;;; +122E4;CUNEIFORM SIGN SUD;Lo;0;L;;;;;N;;;;; +122E5;CUNEIFORM SIGN SUD2;Lo;0;L;;;;;N;;;;; +122E6;CUNEIFORM SIGN SUHUR;Lo;0;L;;;;;N;;;;; +122E7;CUNEIFORM SIGN SUM;Lo;0;L;;;;;N;;;;; +122E8;CUNEIFORM SIGN SUMASH;Lo;0;L;;;;;N;;;;; +122E9;CUNEIFORM SIGN SUR;Lo;0;L;;;;;N;;;;; +122EA;CUNEIFORM SIGN SUR9;Lo;0;L;;;;;N;;;;; +122EB;CUNEIFORM SIGN TA;Lo;0;L;;;;;N;;;;; +122EC;CUNEIFORM SIGN TA ASTERISK;Lo;0;L;;;;;N;;;;; +122ED;CUNEIFORM SIGN TA TIMES HI;Lo;0;L;;;;;N;;;;; +122EE;CUNEIFORM SIGN TA TIMES MI;Lo;0;L;;;;;N;;;;; +122EF;CUNEIFORM SIGN TA GUNU;Lo;0;L;;;;;N;;;;; +122F0;CUNEIFORM SIGN TAB;Lo;0;L;;;;;N;;;;; +122F1;CUNEIFORM SIGN TAB OVER TAB NI OVER NI DISH OVER DISH;Lo;0;L;;;;;N;;;;; +122F2;CUNEIFORM SIGN TAB SQUARED;Lo;0;L;;;;;N;;;;; +122F3;CUNEIFORM SIGN TAG;Lo;0;L;;;;;N;;;;; +122F4;CUNEIFORM SIGN TAG TIMES BI;Lo;0;L;;;;;N;;;;; +122F5;CUNEIFORM SIGN TAG TIMES GUD;Lo;0;L;;;;;N;;;;; +122F6;CUNEIFORM SIGN TAG TIMES SHE;Lo;0;L;;;;;N;;;;; +122F7;CUNEIFORM SIGN TAG TIMES SHU;Lo;0;L;;;;;N;;;;; +122F8;CUNEIFORM SIGN TAG TIMES TUG2;Lo;0;L;;;;;N;;;;; +122F9;CUNEIFORM SIGN TAG TIMES UD;Lo;0;L;;;;;N;;;;; +122FA;CUNEIFORM SIGN TAK4;Lo;0;L;;;;;N;;;;; +122FB;CUNEIFORM SIGN TAR;Lo;0;L;;;;;N;;;;; +122FC;CUNEIFORM SIGN TE;Lo;0;L;;;;;N;;;;; +122FD;CUNEIFORM SIGN TE GUNU;Lo;0;L;;;;;N;;;;; +122FE;CUNEIFORM SIGN TI;Lo;0;L;;;;;N;;;;; +122FF;CUNEIFORM SIGN TI TENU;Lo;0;L;;;;;N;;;;; +12300;CUNEIFORM SIGN TIL;Lo;0;L;;;;;N;;;;; +12301;CUNEIFORM SIGN TIR;Lo;0;L;;;;;N;;;;; +12302;CUNEIFORM SIGN TIR TIMES TAK4;Lo;0;L;;;;;N;;;;; +12303;CUNEIFORM SIGN TIR OVER TIR;Lo;0;L;;;;;N;;;;; +12304;CUNEIFORM SIGN TIR OVER TIR GAD OVER GAD GAR OVER GAR;Lo;0;L;;;;;N;;;;; +12305;CUNEIFORM SIGN TU;Lo;0;L;;;;;N;;;;; +12306;CUNEIFORM SIGN TUG2;Lo;0;L;;;;;N;;;;; +12307;CUNEIFORM SIGN TUK;Lo;0;L;;;;;N;;;;; +12308;CUNEIFORM SIGN TUM;Lo;0;L;;;;;N;;;;; +12309;CUNEIFORM SIGN TUR;Lo;0;L;;;;;N;;;;; +1230A;CUNEIFORM SIGN TUR OVER TUR ZA OVER ZA;Lo;0;L;;;;;N;;;;; +1230B;CUNEIFORM SIGN U;Lo;0;L;;;;;N;;;;; +1230C;CUNEIFORM SIGN U GUD;Lo;0;L;;;;;N;;;;; +1230D;CUNEIFORM SIGN U U U;Lo;0;L;;;;;N;;;;; +1230E;CUNEIFORM SIGN U OVER U PA OVER PA GAR OVER GAR;Lo;0;L;;;;;N;;;;; +1230F;CUNEIFORM SIGN U OVER U SUR OVER SUR;Lo;0;L;;;;;N;;;;; +12310;CUNEIFORM SIGN U OVER U U REVERSED OVER U REVERSED;Lo;0;L;;;;;N;;;;; +12311;CUNEIFORM SIGN U2;Lo;0;L;;;;;N;;;;; +12312;CUNEIFORM SIGN UB;Lo;0;L;;;;;N;;;;; +12313;CUNEIFORM SIGN UD;Lo;0;L;;;;;N;;;;; +12314;CUNEIFORM SIGN UD KUSHU2;Lo;0;L;;;;;N;;;;; +12315;CUNEIFORM SIGN UD TIMES BAD;Lo;0;L;;;;;N;;;;; +12316;CUNEIFORM SIGN UD TIMES MI;Lo;0;L;;;;;N;;;;; +12317;CUNEIFORM SIGN UD TIMES U PLUS U PLUS U;Lo;0;L;;;;;N;;;;; +12318;CUNEIFORM SIGN UD TIMES U PLUS U PLUS U GUNU;Lo;0;L;;;;;N;;;;; +12319;CUNEIFORM SIGN UD GUNU;Lo;0;L;;;;;N;;;;; +1231A;CUNEIFORM SIGN UD SHESHIG;Lo;0;L;;;;;N;;;;; +1231B;CUNEIFORM SIGN UD SHESHIG TIMES BAD;Lo;0;L;;;;;N;;;;; +1231C;CUNEIFORM SIGN UDUG;Lo;0;L;;;;;N;;;;; +1231D;CUNEIFORM SIGN UM;Lo;0;L;;;;;N;;;;; +1231E;CUNEIFORM SIGN UM TIMES LAGAB;Lo;0;L;;;;;N;;;;; +1231F;CUNEIFORM SIGN UM TIMES ME PLUS DA;Lo;0;L;;;;;N;;;;; +12320;CUNEIFORM SIGN UM TIMES SHA3;Lo;0;L;;;;;N;;;;; +12321;CUNEIFORM SIGN UM TIMES U;Lo;0;L;;;;;N;;;;; +12322;CUNEIFORM SIGN UMBIN;Lo;0;L;;;;;N;;;;; +12323;CUNEIFORM SIGN UMUM;Lo;0;L;;;;;N;;;;; +12324;CUNEIFORM SIGN UMUM TIMES KASKAL;Lo;0;L;;;;;N;;;;; +12325;CUNEIFORM SIGN UMUM TIMES PA;Lo;0;L;;;;;N;;;;; +12326;CUNEIFORM SIGN UN;Lo;0;L;;;;;N;;;;; +12327;CUNEIFORM SIGN UN GUNU;Lo;0;L;;;;;N;;;;; +12328;CUNEIFORM SIGN UR;Lo;0;L;;;;;N;;;;; +12329;CUNEIFORM SIGN UR CROSSING UR;Lo;0;L;;;;;N;;;;; +1232A;CUNEIFORM SIGN UR SHESHIG;Lo;0;L;;;;;N;;;;; +1232B;CUNEIFORM SIGN UR2;Lo;0;L;;;;;N;;;;; +1232C;CUNEIFORM SIGN UR2 TIMES A PLUS HA;Lo;0;L;;;;;N;;;;; +1232D;CUNEIFORM SIGN UR2 TIMES A PLUS NA;Lo;0;L;;;;;N;;;;; +1232E;CUNEIFORM SIGN UR2 TIMES AL;Lo;0;L;;;;;N;;;;; +1232F;CUNEIFORM SIGN UR2 TIMES HA;Lo;0;L;;;;;N;;;;; +12330;CUNEIFORM SIGN UR2 TIMES NUN;Lo;0;L;;;;;N;;;;; +12331;CUNEIFORM SIGN UR2 TIMES U2;Lo;0;L;;;;;N;;;;; +12332;CUNEIFORM SIGN UR2 TIMES U2 PLUS ASH;Lo;0;L;;;;;N;;;;; +12333;CUNEIFORM SIGN UR2 TIMES U2 PLUS BI;Lo;0;L;;;;;N;;;;; +12334;CUNEIFORM SIGN UR4;Lo;0;L;;;;;N;;;;; +12335;CUNEIFORM SIGN URI;Lo;0;L;;;;;N;;;;; +12336;CUNEIFORM SIGN URI3;Lo;0;L;;;;;N;;;;; +12337;CUNEIFORM SIGN URU;Lo;0;L;;;;;N;;;;; +12338;CUNEIFORM SIGN URU TIMES A;Lo;0;L;;;;;N;;;;; +12339;CUNEIFORM SIGN URU TIMES ASHGAB;Lo;0;L;;;;;N;;;;; +1233A;CUNEIFORM SIGN URU TIMES BAR;Lo;0;L;;;;;N;;;;; +1233B;CUNEIFORM SIGN URU TIMES DUN;Lo;0;L;;;;;N;;;;; +1233C;CUNEIFORM SIGN URU TIMES GA;Lo;0;L;;;;;N;;;;; +1233D;CUNEIFORM SIGN URU TIMES GAL;Lo;0;L;;;;;N;;;;; +1233E;CUNEIFORM SIGN URU TIMES GAN2 TENU;Lo;0;L;;;;;N;;;;; +1233F;CUNEIFORM SIGN URU TIMES GAR;Lo;0;L;;;;;N;;;;; +12340;CUNEIFORM SIGN URU TIMES GU;Lo;0;L;;;;;N;;;;; +12341;CUNEIFORM SIGN URU TIMES HA;Lo;0;L;;;;;N;;;;; +12342;CUNEIFORM SIGN URU TIMES IGI;Lo;0;L;;;;;N;;;;; +12343;CUNEIFORM SIGN URU TIMES IM;Lo;0;L;;;;;N;;;;; +12344;CUNEIFORM SIGN URU TIMES ISH;Lo;0;L;;;;;N;;;;; +12345;CUNEIFORM SIGN URU TIMES KI;Lo;0;L;;;;;N;;;;; +12346;CUNEIFORM SIGN URU TIMES LUM;Lo;0;L;;;;;N;;;;; +12347;CUNEIFORM SIGN URU TIMES MIN;Lo;0;L;;;;;N;;;;; +12348;CUNEIFORM SIGN URU TIMES PA;Lo;0;L;;;;;N;;;;; +12349;CUNEIFORM SIGN URU TIMES SHE;Lo;0;L;;;;;N;;;;; +1234A;CUNEIFORM SIGN URU TIMES SIG4;Lo;0;L;;;;;N;;;;; +1234B;CUNEIFORM SIGN URU TIMES TU;Lo;0;L;;;;;N;;;;; +1234C;CUNEIFORM SIGN URU TIMES U PLUS GUD;Lo;0;L;;;;;N;;;;; +1234D;CUNEIFORM SIGN URU TIMES UD;Lo;0;L;;;;;N;;;;; +1234E;CUNEIFORM SIGN URU TIMES URUDA;Lo;0;L;;;;;N;;;;; +1234F;CUNEIFORM SIGN URUDA;Lo;0;L;;;;;N;;;;; +12350;CUNEIFORM SIGN URUDA TIMES U;Lo;0;L;;;;;N;;;;; +12351;CUNEIFORM SIGN USH;Lo;0;L;;;;;N;;;;; +12352;CUNEIFORM SIGN USH TIMES A;Lo;0;L;;;;;N;;;;; +12353;CUNEIFORM SIGN USH TIMES KU;Lo;0;L;;;;;N;;;;; +12354;CUNEIFORM SIGN USH TIMES KUR;Lo;0;L;;;;;N;;;;; +12355;CUNEIFORM SIGN USH TIMES TAK4;Lo;0;L;;;;;N;;;;; +12356;CUNEIFORM SIGN USHX;Lo;0;L;;;;;N;;;;; +12357;CUNEIFORM SIGN USH2;Lo;0;L;;;;;N;;;;; +12358;CUNEIFORM SIGN USHUMX;Lo;0;L;;;;;N;;;;; +12359;CUNEIFORM SIGN UTUKI;Lo;0;L;;;;;N;;;;; +1235A;CUNEIFORM SIGN UZ3;Lo;0;L;;;;;N;;;;; +1235B;CUNEIFORM SIGN UZ3 TIMES KASKAL;Lo;0;L;;;;;N;;;;; +1235C;CUNEIFORM SIGN UZU;Lo;0;L;;;;;N;;;;; +1235D;CUNEIFORM SIGN ZA;Lo;0;L;;;;;N;;;;; +1235E;CUNEIFORM SIGN ZA TENU;Lo;0;L;;;;;N;;;;; +1235F;CUNEIFORM SIGN ZA SQUARED TIMES KUR;Lo;0;L;;;;;N;;;;; +12360;CUNEIFORM SIGN ZAG;Lo;0;L;;;;;N;;;;; +12361;CUNEIFORM SIGN ZAMX;Lo;0;L;;;;;N;;;;; +12362;CUNEIFORM SIGN ZE2;Lo;0;L;;;;;N;;;;; +12363;CUNEIFORM SIGN ZI;Lo;0;L;;;;;N;;;;; +12364;CUNEIFORM SIGN ZI OVER ZI;Lo;0;L;;;;;N;;;;; +12365;CUNEIFORM SIGN ZI3;Lo;0;L;;;;;N;;;;; +12366;CUNEIFORM SIGN ZIB;Lo;0;L;;;;;N;;;;; +12367;CUNEIFORM SIGN ZIB KABA TENU;Lo;0;L;;;;;N;;;;; +12368;CUNEIFORM SIGN ZIG;Lo;0;L;;;;;N;;;;; +12369;CUNEIFORM SIGN ZIZ2;Lo;0;L;;;;;N;;;;; +1236A;CUNEIFORM SIGN ZU;Lo;0;L;;;;;N;;;;; +1236B;CUNEIFORM SIGN ZU5;Lo;0;L;;;;;N;;;;; +1236C;CUNEIFORM SIGN ZU5 TIMES A;Lo;0;L;;;;;N;;;;; +1236D;CUNEIFORM SIGN ZUBUR;Lo;0;L;;;;;N;;;;; +1236E;CUNEIFORM SIGN ZUM;Lo;0;L;;;;;N;;;;; +12400;CUNEIFORM NUMERIC SIGN TWO ASH;Nl;0;L;;;;2;N;;;;; +12401;CUNEIFORM NUMERIC SIGN THREE ASH;Nl;0;L;;;;3;N;;;;; +12402;CUNEIFORM NUMERIC SIGN FOUR ASH;Nl;0;L;;;;4;N;;;;; +12403;CUNEIFORM NUMERIC SIGN FIVE ASH;Nl;0;L;;;;5;N;;;;; +12404;CUNEIFORM NUMERIC SIGN SIX ASH;Nl;0;L;;;;6;N;;;;; +12405;CUNEIFORM NUMERIC SIGN SEVEN ASH;Nl;0;L;;;;7;N;;;;; +12406;CUNEIFORM NUMERIC SIGN EIGHT ASH;Nl;0;L;;;;8;N;;;;; +12407;CUNEIFORM NUMERIC SIGN NINE ASH;Nl;0;L;;;;9;N;;;;; +12408;CUNEIFORM NUMERIC SIGN THREE DISH;Nl;0;L;;;;3;N;;;;; +12409;CUNEIFORM NUMERIC SIGN FOUR DISH;Nl;0;L;;;;4;N;;;;; +1240A;CUNEIFORM NUMERIC SIGN FIVE DISH;Nl;0;L;;;;5;N;;;;; +1240B;CUNEIFORM NUMERIC SIGN SIX DISH;Nl;0;L;;;;6;N;;;;; +1240C;CUNEIFORM NUMERIC SIGN SEVEN DISH;Nl;0;L;;;;7;N;;;;; +1240D;CUNEIFORM NUMERIC SIGN EIGHT DISH;Nl;0;L;;;;8;N;;;;; +1240E;CUNEIFORM NUMERIC SIGN NINE DISH;Nl;0;L;;;;9;N;;;;; +1240F;CUNEIFORM NUMERIC SIGN FOUR U;Nl;0;L;;;;4;N;;;;; +12410;CUNEIFORM NUMERIC SIGN FIVE U;Nl;0;L;;;;5;N;;;;; +12411;CUNEIFORM NUMERIC SIGN SIX U;Nl;0;L;;;;6;N;;;;; +12412;CUNEIFORM NUMERIC SIGN SEVEN U;Nl;0;L;;;;7;N;;;;; +12413;CUNEIFORM NUMERIC SIGN EIGHT U;Nl;0;L;;;;8;N;;;;; +12414;CUNEIFORM NUMERIC SIGN NINE U;Nl;0;L;;;;9;N;;;;; +12415;CUNEIFORM NUMERIC SIGN ONE GESH2;Nl;0;L;;;;1;N;;;;; +12416;CUNEIFORM NUMERIC SIGN TWO GESH2;Nl;0;L;;;;2;N;;;;; +12417;CUNEIFORM NUMERIC SIGN THREE GESH2;Nl;0;L;;;;3;N;;;;; +12418;CUNEIFORM NUMERIC SIGN FOUR GESH2;Nl;0;L;;;;4;N;;;;; +12419;CUNEIFORM NUMERIC SIGN FIVE GESH2;Nl;0;L;;;;5;N;;;;; +1241A;CUNEIFORM NUMERIC SIGN SIX GESH2;Nl;0;L;;;;6;N;;;;; +1241B;CUNEIFORM NUMERIC SIGN SEVEN GESH2;Nl;0;L;;;;7;N;;;;; +1241C;CUNEIFORM NUMERIC SIGN EIGHT GESH2;Nl;0;L;;;;8;N;;;;; +1241D;CUNEIFORM NUMERIC SIGN NINE GESH2;Nl;0;L;;;;9;N;;;;; +1241E;CUNEIFORM NUMERIC SIGN ONE GESHU;Nl;0;L;;;;1;N;;;;; +1241F;CUNEIFORM NUMERIC SIGN TWO GESHU;Nl;0;L;;;;2;N;;;;; +12420;CUNEIFORM NUMERIC SIGN THREE GESHU;Nl;0;L;;;;3;N;;;;; +12421;CUNEIFORM NUMERIC SIGN FOUR GESHU;Nl;0;L;;;;4;N;;;;; +12422;CUNEIFORM NUMERIC SIGN FIVE GESHU;Nl;0;L;;;;5;N;;;;; +12423;CUNEIFORM NUMERIC SIGN TWO SHAR2;Nl;0;L;;;;2;N;;;;; +12424;CUNEIFORM NUMERIC SIGN THREE SHAR2;Nl;0;L;;;;3;N;;;;; +12425;CUNEIFORM NUMERIC SIGN THREE SHAR2 VARIANT FORM;Nl;0;L;;;;3;N;;;;; +12426;CUNEIFORM NUMERIC SIGN FOUR SHAR2;Nl;0;L;;;;4;N;;;;; +12427;CUNEIFORM NUMERIC SIGN FIVE SHAR2;Nl;0;L;;;;5;N;;;;; +12428;CUNEIFORM NUMERIC SIGN SIX SHAR2;Nl;0;L;;;;6;N;;;;; +12429;CUNEIFORM NUMERIC SIGN SEVEN SHAR2;Nl;0;L;;;;7;N;;;;; +1242A;CUNEIFORM NUMERIC SIGN EIGHT SHAR2;Nl;0;L;;;;8;N;;;;; +1242B;CUNEIFORM NUMERIC SIGN NINE SHAR2;Nl;0;L;;;;9;N;;;;; +1242C;CUNEIFORM NUMERIC SIGN ONE SHARU;Nl;0;L;;;;1;N;;;;; +1242D;CUNEIFORM NUMERIC SIGN TWO SHARU;Nl;0;L;;;;2;N;;;;; +1242E;CUNEIFORM NUMERIC SIGN THREE SHARU;Nl;0;L;;;;3;N;;;;; +1242F;CUNEIFORM NUMERIC SIGN THREE SHARU VARIANT FORM;Nl;0;L;;;;3;N;;;;; +12430;CUNEIFORM NUMERIC SIGN FOUR SHARU;Nl;0;L;;;;4;N;;;;; +12431;CUNEIFORM NUMERIC SIGN FIVE SHARU;Nl;0;L;;;;5;N;;;;; +12432;CUNEIFORM NUMERIC SIGN SHAR2 TIMES GAL PLUS DISH;Nl;0;L;;;;;N;;;;; +12433;CUNEIFORM NUMERIC SIGN SHAR2 TIMES GAL PLUS MIN;Nl;0;L;;;;;N;;;;; +12434;CUNEIFORM NUMERIC SIGN ONE BURU;Nl;0;L;;;;1;N;;;;; +12435;CUNEIFORM NUMERIC SIGN TWO BURU;Nl;0;L;;;;2;N;;;;; +12436;CUNEIFORM NUMERIC SIGN THREE BURU;Nl;0;L;;;;3;N;;;;; +12437;CUNEIFORM NUMERIC SIGN THREE BURU VARIANT FORM;Nl;0;L;;;;3;N;;;;; +12438;CUNEIFORM NUMERIC SIGN FOUR BURU;Nl;0;L;;;;4;N;;;;; +12439;CUNEIFORM NUMERIC SIGN FIVE BURU;Nl;0;L;;;;5;N;;;;; +1243A;CUNEIFORM NUMERIC SIGN THREE VARIANT FORM ESH16;Nl;0;L;;;;3;N;;;;; +1243B;CUNEIFORM NUMERIC SIGN THREE VARIANT FORM ESH21;Nl;0;L;;;;3;N;;;;; +1243C;CUNEIFORM NUMERIC SIGN FOUR VARIANT FORM LIMMU;Nl;0;L;;;;4;N;;;;; +1243D;CUNEIFORM NUMERIC SIGN FOUR VARIANT FORM LIMMU4;Nl;0;L;;;;4;N;;;;; +1243E;CUNEIFORM NUMERIC SIGN FOUR VARIANT FORM LIMMU A;Nl;0;L;;;;4;N;;;;; +1243F;CUNEIFORM NUMERIC SIGN FOUR VARIANT FORM LIMMU B;Nl;0;L;;;;4;N;;;;; +12440;CUNEIFORM NUMERIC SIGN SIX VARIANT FORM ASH9;Nl;0;L;;;;6;N;;;;; +12441;CUNEIFORM NUMERIC SIGN SEVEN VARIANT FORM IMIN3;Nl;0;L;;;;7;N;;;;; +12442;CUNEIFORM NUMERIC SIGN SEVEN VARIANT FORM IMIN A;Nl;0;L;;;;7;N;;;;; +12443;CUNEIFORM NUMERIC SIGN SEVEN VARIANT FORM IMIN B;Nl;0;L;;;;7;N;;;;; +12444;CUNEIFORM NUMERIC SIGN EIGHT VARIANT FORM USSU;Nl;0;L;;;;8;N;;;;; +12445;CUNEIFORM NUMERIC SIGN EIGHT VARIANT FORM USSU3;Nl;0;L;;;;8;N;;;;; +12446;CUNEIFORM NUMERIC SIGN NINE VARIANT FORM ILIMMU;Nl;0;L;;;;9;N;;;;; +12447;CUNEIFORM NUMERIC SIGN NINE VARIANT FORM ILIMMU3;Nl;0;L;;;;9;N;;;;; +12448;CUNEIFORM NUMERIC SIGN NINE VARIANT FORM ILIMMU4;Nl;0;L;;;;9;N;;;;; +12449;CUNEIFORM NUMERIC SIGN NINE VARIANT FORM ILIMMU A;Nl;0;L;;;;9;N;;;;; +1244A;CUNEIFORM NUMERIC SIGN TWO ASH TENU;Nl;0;L;;;;2;N;;;;; +1244B;CUNEIFORM NUMERIC SIGN THREE ASH TENU;Nl;0;L;;;;3;N;;;;; +1244C;CUNEIFORM NUMERIC SIGN FOUR ASH TENU;Nl;0;L;;;;4;N;;;;; +1244D;CUNEIFORM NUMERIC SIGN FIVE ASH TENU;Nl;0;L;;;;5;N;;;;; +1244E;CUNEIFORM NUMERIC SIGN SIX ASH TENU;Nl;0;L;;;;6;N;;;;; +1244F;CUNEIFORM NUMERIC SIGN ONE BAN2;Nl;0;L;;;;1;N;;;;; +12450;CUNEIFORM NUMERIC SIGN TWO BAN2;Nl;0;L;;;;2;N;;;;; +12451;CUNEIFORM NUMERIC SIGN THREE BAN2;Nl;0;L;;;;3;N;;;;; +12452;CUNEIFORM NUMERIC SIGN FOUR BAN2;Nl;0;L;;;;4;N;;;;; +12453;CUNEIFORM NUMERIC SIGN FOUR BAN2 VARIANT FORM;Nl;0;L;;;;4;N;;;;; +12454;CUNEIFORM NUMERIC SIGN FIVE BAN2;Nl;0;L;;;;5;N;;;;; +12455;CUNEIFORM NUMERIC SIGN FIVE BAN2 VARIANT FORM;Nl;0;L;;;;5;N;;;;; +12456;CUNEIFORM NUMERIC SIGN NIGIDAMIN;Nl;0;L;;;;;N;;;;; +12457;CUNEIFORM NUMERIC SIGN NIGIDAESH;Nl;0;L;;;;;N;;;;; +12458;CUNEIFORM NUMERIC SIGN ONE ESHE3;Nl;0;L;;;;1;N;;;;; +12459;CUNEIFORM NUMERIC SIGN TWO ESHE3;Nl;0;L;;;;2;N;;;;; +1245A;CUNEIFORM NUMERIC SIGN ONE THIRD DISH;Nl;0;L;;;;1/3;N;;;;; +1245B;CUNEIFORM NUMERIC SIGN TWO THIRDS DISH;Nl;0;L;;;;2/3;N;;;;; +1245C;CUNEIFORM NUMERIC SIGN FIVE SIXTHS DISH;Nl;0;L;;;;5/6;N;;;;; +1245D;CUNEIFORM NUMERIC SIGN ONE THIRD VARIANT FORM A;Nl;0;L;;;;1/3;N;;;;; +1245E;CUNEIFORM NUMERIC SIGN TWO THIRDS VARIANT FORM A;Nl;0;L;;;;2/3;N;;;;; +1245F;CUNEIFORM NUMERIC SIGN ONE EIGHTH ASH;Nl;0;L;;;;1/8;N;;;;; +12460;CUNEIFORM NUMERIC SIGN ONE QUARTER ASH;Nl;0;L;;;;1/4;N;;;;; +12461;CUNEIFORM NUMERIC SIGN OLD ASSYRIAN ONE SIXTH;Nl;0;L;;;;1/6;N;;;;; +12462;CUNEIFORM NUMERIC SIGN OLD ASSYRIAN ONE QUARTER;Nl;0;L;;;;1/4;N;;;;; +12470;CUNEIFORM PUNCTUATION SIGN OLD ASSYRIAN WORD DIVIDER;Po;0;L;;;;;N;;;;; +12471;CUNEIFORM PUNCTUATION SIGN VERTICAL COLON;Po;0;L;;;;;N;;;;; +12472;CUNEIFORM PUNCTUATION SIGN DIAGONAL COLON;Po;0;L;;;;;N;;;;; +12473;CUNEIFORM PUNCTUATION SIGN DIAGONAL TRICOLON;Po;0;L;;;;;N;;;;; 1D000;BYZANTINE MUSICAL SYMBOL PSILI;So;0;L;;;;;N;;;;; 1D001;BYZANTINE MUSICAL SYMBOL DASEIA;So;0;L;;;;;N;;;;; 1D002;BYZANTINE MUSICAL SYMBOL PERISPOMENI;So;0;L;;;;;N;;;;; @@ -12954,6 +16953,7 @@ FFFD;REPLACEMENT CHARACTER;So;0;ON;;;;;N;;;;; 1D124;MUSICAL SYMBOL F CLEF OTTAVA BASSA;So;0;L;;;;;N;;;;; 1D125;MUSICAL SYMBOL DRUM CLEF-1;So;0;L;;;;;N;;;;; 1D126;MUSICAL SYMBOL DRUM CLEF-2;So;0;L;;;;;N;;;;; +1D129;MUSICAL SYMBOL MULTIPLE MEASURE REST;So;0;L;;;;;N;;;;; 1D12A;MUSICAL SYMBOL DOUBLE SHARP;So;0;L;;;;;N;;;;; 1D12B;MUSICAL SYMBOL DOUBLE FLAT;So;0;L;;;;;N;;;;; 1D12C;MUSICAL SYMBOL FLAT UP;So;0;L;;;;;N;;;;; @@ -13134,12 +17134,82 @@ FFFD;REPLACEMENT CHARACTER;So;0;ON;;;;;N;;;;; 1D1DB;MUSICAL SYMBOL SCANDICUS FLEXUS;So;0;L;;;;;N;;;;; 1D1DC;MUSICAL SYMBOL TORCULUS RESUPINUS;So;0;L;;;;;N;;;;; 1D1DD;MUSICAL SYMBOL PES SUBPUNCTIS;So;0;L;;;;;N;;;;; -1D300;MONOGRAM FOR EARTH;So;0;ON;;;;;N;;;;; -1D301;DIGRAM FOR HEAVENLY EARTH;So;0;ON;;;;;N;;;;; -1D302;DIGRAM FOR HUMAN EARTH;So;0;ON;;;;;N;;;;; -1D303;DIGRAM FOR EARTHLY HEAVEN;So;0;ON;;;;;N;;;;; -1D304;DIGRAM FOR EARTHLY HUMAN;So;0;ON;;;;;N;;;;; -1D305;DIGRAM FOR EARTH;So;0;ON;;;;;N;;;;; +1D200;GREEK VOCAL NOTATION SYMBOL-1;So;0;ON;;;;;N;;;;; +1D201;GREEK VOCAL NOTATION SYMBOL-2;So;0;ON;;;;;N;;;;; +1D202;GREEK VOCAL NOTATION SYMBOL-3;So;0;ON;;;;;N;;;;; +1D203;GREEK VOCAL NOTATION SYMBOL-4;So;0;ON;;;;;N;;;;; +1D204;GREEK VOCAL NOTATION SYMBOL-5;So;0;ON;;;;;N;;;;; +1D205;GREEK VOCAL NOTATION SYMBOL-6;So;0;ON;;;;;N;;;;; +1D206;GREEK VOCAL NOTATION SYMBOL-7;So;0;ON;;;;;N;;;;; +1D207;GREEK VOCAL NOTATION SYMBOL-8;So;0;ON;;;;;N;;;;; +1D208;GREEK VOCAL NOTATION SYMBOL-9;So;0;ON;;;;;N;;;;; +1D209;GREEK VOCAL NOTATION SYMBOL-10;So;0;ON;;;;;N;;;;; +1D20A;GREEK VOCAL NOTATION SYMBOL-11;So;0;ON;;;;;N;;;;; +1D20B;GREEK VOCAL NOTATION SYMBOL-12;So;0;ON;;;;;N;;;;; +1D20C;GREEK VOCAL NOTATION SYMBOL-13;So;0;ON;;;;;N;;;;; +1D20D;GREEK VOCAL NOTATION SYMBOL-14;So;0;ON;;;;;N;;;;; +1D20E;GREEK VOCAL NOTATION SYMBOL-15;So;0;ON;;;;;N;;;;; +1D20F;GREEK VOCAL NOTATION SYMBOL-16;So;0;ON;;;;;N;;;;; +1D210;GREEK VOCAL NOTATION SYMBOL-17;So;0;ON;;;;;N;;;;; +1D211;GREEK VOCAL NOTATION SYMBOL-18;So;0;ON;;;;;N;;;;; +1D212;GREEK VOCAL NOTATION SYMBOL-19;So;0;ON;;;;;N;;;;; +1D213;GREEK VOCAL NOTATION SYMBOL-20;So;0;ON;;;;;N;;;;; +1D214;GREEK VOCAL NOTATION SYMBOL-21;So;0;ON;;;;;N;;;;; +1D215;GREEK VOCAL NOTATION SYMBOL-22;So;0;ON;;;;;N;;;;; +1D216;GREEK VOCAL NOTATION SYMBOL-23;So;0;ON;;;;;N;;;;; +1D217;GREEK VOCAL NOTATION SYMBOL-24;So;0;ON;;;;;N;;;;; +1D218;GREEK VOCAL NOTATION SYMBOL-50;So;0;ON;;;;;N;;;;; +1D219;GREEK VOCAL NOTATION SYMBOL-51;So;0;ON;;;;;N;;;;; +1D21A;GREEK VOCAL NOTATION SYMBOL-52;So;0;ON;;;;;N;;;;; +1D21B;GREEK VOCAL NOTATION SYMBOL-53;So;0;ON;;;;;N;;;;; +1D21C;GREEK VOCAL NOTATION SYMBOL-54;So;0;ON;;;;;N;;;;; +1D21D;GREEK INSTRUMENTAL NOTATION SYMBOL-1;So;0;ON;;;;;N;;;;; +1D21E;GREEK INSTRUMENTAL NOTATION SYMBOL-2;So;0;ON;;;;;N;;;;; +1D21F;GREEK INSTRUMENTAL NOTATION SYMBOL-4;So;0;ON;;;;;N;;;;; +1D220;GREEK INSTRUMENTAL NOTATION SYMBOL-5;So;0;ON;;;;;N;;;;; +1D221;GREEK INSTRUMENTAL NOTATION SYMBOL-7;So;0;ON;;;;;N;;;;; +1D222;GREEK INSTRUMENTAL NOTATION SYMBOL-8;So;0;ON;;;;;N;;;;; +1D223;GREEK INSTRUMENTAL NOTATION SYMBOL-11;So;0;ON;;;;;N;;;;; +1D224;GREEK INSTRUMENTAL NOTATION SYMBOL-12;So;0;ON;;;;;N;;;;; +1D225;GREEK INSTRUMENTAL NOTATION SYMBOL-13;So;0;ON;;;;;N;;;;; +1D226;GREEK INSTRUMENTAL NOTATION SYMBOL-14;So;0;ON;;;;;N;;;;; +1D227;GREEK INSTRUMENTAL NOTATION SYMBOL-17;So;0;ON;;;;;N;;;;; +1D228;GREEK INSTRUMENTAL NOTATION SYMBOL-18;So;0;ON;;;;;N;;;;; +1D229;GREEK INSTRUMENTAL NOTATION SYMBOL-19;So;0;ON;;;;;N;;;;; +1D22A;GREEK INSTRUMENTAL NOTATION SYMBOL-23;So;0;ON;;;;;N;;;;; +1D22B;GREEK INSTRUMENTAL NOTATION SYMBOL-24;So;0;ON;;;;;N;;;;; +1D22C;GREEK INSTRUMENTAL NOTATION SYMBOL-25;So;0;ON;;;;;N;;;;; +1D22D;GREEK INSTRUMENTAL NOTATION SYMBOL-26;So;0;ON;;;;;N;;;;; +1D22E;GREEK INSTRUMENTAL NOTATION SYMBOL-27;So;0;ON;;;;;N;;;;; +1D22F;GREEK INSTRUMENTAL NOTATION SYMBOL-29;So;0;ON;;;;;N;;;;; +1D230;GREEK INSTRUMENTAL NOTATION SYMBOL-30;So;0;ON;;;;;N;;;;; +1D231;GREEK INSTRUMENTAL NOTATION SYMBOL-32;So;0;ON;;;;;N;;;;; +1D232;GREEK INSTRUMENTAL NOTATION SYMBOL-36;So;0;ON;;;;;N;;;;; +1D233;GREEK INSTRUMENTAL NOTATION SYMBOL-37;So;0;ON;;;;;N;;;;; +1D234;GREEK INSTRUMENTAL NOTATION SYMBOL-38;So;0;ON;;;;;N;;;;; +1D235;GREEK INSTRUMENTAL NOTATION SYMBOL-39;So;0;ON;;;;;N;;;;; +1D236;GREEK INSTRUMENTAL NOTATION SYMBOL-40;So;0;ON;;;;;N;;;;; +1D237;GREEK INSTRUMENTAL NOTATION SYMBOL-42;So;0;ON;;;;;N;;;;; +1D238;GREEK INSTRUMENTAL NOTATION SYMBOL-43;So;0;ON;;;;;N;;;;; +1D239;GREEK INSTRUMENTAL NOTATION SYMBOL-45;So;0;ON;;;;;N;;;;; +1D23A;GREEK INSTRUMENTAL NOTATION SYMBOL-47;So;0;ON;;;;;N;;;;; +1D23B;GREEK INSTRUMENTAL NOTATION SYMBOL-48;So;0;ON;;;;;N;;;;; +1D23C;GREEK INSTRUMENTAL NOTATION SYMBOL-49;So;0;ON;;;;;N;;;;; +1D23D;GREEK INSTRUMENTAL NOTATION SYMBOL-50;So;0;ON;;;;;N;;;;; +1D23E;GREEK INSTRUMENTAL NOTATION SYMBOL-51;So;0;ON;;;;;N;;;;; +1D23F;GREEK INSTRUMENTAL NOTATION SYMBOL-52;So;0;ON;;;;;N;;;;; +1D240;GREEK INSTRUMENTAL NOTATION SYMBOL-53;So;0;ON;;;;;N;;;;; +1D241;GREEK INSTRUMENTAL NOTATION SYMBOL-54;So;0;ON;;;;;N;;;;; +1D242;COMBINING GREEK MUSICAL TRISEME;Mn;230;NSM;;;;;N;;;;; +1D243;COMBINING GREEK MUSICAL TETRASEME;Mn;230;NSM;;;;;N;;;;; +1D244;COMBINING GREEK MUSICAL PENTASEME;Mn;230;NSM;;;;;N;;;;; +1D245;GREEK MUSICAL LEIMMA;So;0;ON;;;;;N;;;;; +1D300;MONOGRAM FOR EARTH;So;0;ON;;;;;N;;ren *;;; +1D301;DIGRAM FOR HEAVENLY EARTH;So;0;ON;;;;;N;;tian ren *;;; +1D302;DIGRAM FOR HUMAN EARTH;So;0;ON;;;;;N;;di ren *;;; +1D303;DIGRAM FOR EARTHLY HEAVEN;So;0;ON;;;;;N;;ren tian *;;; +1D304;DIGRAM FOR EARTHLY HUMAN;So;0;ON;;;;;N;;ren di *;;; +1D305;DIGRAM FOR EARTH;So;0;ON;;;;;N;;ren ren *;;; 1D306;TETRAGRAM FOR CENTRE;So;0;ON;;;;;N;;;;; 1D307;TETRAGRAM FOR FULL CIRCLE;So;0;ON;;;;;N;;;;; 1D308;TETRAGRAM FOR MIRED;So;0;ON;;;;;N;;;;; @@ -13221,6 +17291,24 @@ FFFD;REPLACEMENT CHARACTER;So;0;ON;;;;;N;;;;; 1D354;TETRAGRAM FOR DIFFICULTIES;So;0;ON;;;;;N;;;;; 1D355;TETRAGRAM FOR LABOURING;So;0;ON;;;;;N;;;;; 1D356;TETRAGRAM FOR FOSTERING;So;0;ON;;;;;N;;;;; +1D360;COUNTING ROD UNIT DIGIT ONE;No;0;L;;;;1;N;;;;; +1D361;COUNTING ROD UNIT DIGIT TWO;No;0;L;;;;2;N;;;;; +1D362;COUNTING ROD UNIT DIGIT THREE;No;0;L;;;;3;N;;;;; +1D363;COUNTING ROD UNIT DIGIT FOUR;No;0;L;;;;4;N;;;;; +1D364;COUNTING ROD UNIT DIGIT FIVE;No;0;L;;;;5;N;;;;; +1D365;COUNTING ROD UNIT DIGIT SIX;No;0;L;;;;6;N;;;;; +1D366;COUNTING ROD UNIT DIGIT SEVEN;No;0;L;;;;7;N;;;;; +1D367;COUNTING ROD UNIT DIGIT EIGHT;No;0;L;;;;8;N;;;;; +1D368;COUNTING ROD UNIT DIGIT NINE;No;0;L;;;;9;N;;;;; +1D369;COUNTING ROD TENS DIGIT ONE;No;0;L;;;;10;N;;;;; +1D36A;COUNTING ROD TENS DIGIT TWO;No;0;L;;;;20;N;;;;; +1D36B;COUNTING ROD TENS DIGIT THREE;No;0;L;;;;30;N;;;;; +1D36C;COUNTING ROD TENS DIGIT FOUR;No;0;L;;;;40;N;;;;; +1D36D;COUNTING ROD TENS DIGIT FIVE;No;0;L;;;;50;N;;;;; +1D36E;COUNTING ROD TENS DIGIT SIX;No;0;L;;;;60;N;;;;; +1D36F;COUNTING ROD TENS DIGIT SEVEN;No;0;L;;;;70;N;;;;; +1D370;COUNTING ROD TENS DIGIT EIGHT;No;0;L;;;;80;N;;;;; +1D371;COUNTING ROD TENS DIGIT NINE;No;0;L;;;;90;N;;;;; 1D400;MATHEMATICAL BOLD CAPITAL A;Lu;0;L;<font> 0041;;;;N;;;;; 1D401;MATHEMATICAL BOLD CAPITAL B;Lu;0;L;<font> 0042;;;;N;;;;; 1D402;MATHEMATICAL BOLD CAPITAL C;Lu;0;L;<font> 0043;;;;N;;;;; @@ -13873,6 +17961,8 @@ FFFD;REPLACEMENT CHARACTER;So;0;ON;;;;;N;;;;; 1D6A1;MATHEMATICAL MONOSPACE SMALL X;Ll;0;L;<font> 0078;;;;N;;;;; 1D6A2;MATHEMATICAL MONOSPACE SMALL Y;Ll;0;L;<font> 0079;;;;N;;;;; 1D6A3;MATHEMATICAL MONOSPACE SMALL Z;Ll;0;L;<font> 007A;;;;N;;;;; +1D6A4;MATHEMATICAL ITALIC SMALL DOTLESS I;Ll;0;L;<font> 0131;;;;N;;;;; +1D6A5;MATHEMATICAL ITALIC SMALL DOTLESS J;Ll;0;L;<font> 0237;;;;N;;;;; 1D6A8;MATHEMATICAL BOLD CAPITAL ALPHA;Lu;0;L;<font> 0391;;;;N;;;;; 1D6A9;MATHEMATICAL BOLD CAPITAL BETA;Lu;0;L;<font> 0392;;;;N;;;;; 1D6AA;MATHEMATICAL BOLD CAPITAL GAMMA;Lu;0;L;<font> 0393;;;;N;;;;; @@ -13924,7 +18014,7 @@ FFFD;REPLACEMENT CHARACTER;So;0;ON;;;;;N;;;;; 1D6D8;MATHEMATICAL BOLD SMALL CHI;Ll;0;L;<font> 03C7;;;;N;;;;; 1D6D9;MATHEMATICAL BOLD SMALL PSI;Ll;0;L;<font> 03C8;;;;N;;;;; 1D6DA;MATHEMATICAL BOLD SMALL OMEGA;Ll;0;L;<font> 03C9;;;;N;;;;; -1D6DB;MATHEMATICAL BOLD PARTIAL DIFFERENTIAL;Sm;0;L;<font> 2202;;;;N;;;;; +1D6DB;MATHEMATICAL BOLD PARTIAL DIFFERENTIAL;Sm;0;L;<font> 2202;;;;Y;;;;; 1D6DC;MATHEMATICAL BOLD EPSILON SYMBOL;Ll;0;L;<font> 03F5;;;;N;;;;; 1D6DD;MATHEMATICAL BOLD THETA SYMBOL;Ll;0;L;<font> 03D1;;;;N;;;;; 1D6DE;MATHEMATICAL BOLD KAPPA SYMBOL;Ll;0;L;<font> 03F0;;;;N;;;;; @@ -13982,7 +18072,7 @@ FFFD;REPLACEMENT CHARACTER;So;0;ON;;;;;N;;;;; 1D712;MATHEMATICAL ITALIC SMALL CHI;Ll;0;L;<font> 03C7;;;;N;;;;; 1D713;MATHEMATICAL ITALIC SMALL PSI;Ll;0;L;<font> 03C8;;;;N;;;;; 1D714;MATHEMATICAL ITALIC SMALL OMEGA;Ll;0;L;<font> 03C9;;;;N;;;;; -1D715;MATHEMATICAL ITALIC PARTIAL DIFFERENTIAL;Sm;0;L;<font> 2202;;;;N;;;;; +1D715;MATHEMATICAL ITALIC PARTIAL DIFFERENTIAL;Sm;0;L;<font> 2202;;;;Y;;;;; 1D716;MATHEMATICAL ITALIC EPSILON SYMBOL;Ll;0;L;<font> 03F5;;;;N;;;;; 1D717;MATHEMATICAL ITALIC THETA SYMBOL;Ll;0;L;<font> 03D1;;;;N;;;;; 1D718;MATHEMATICAL ITALIC KAPPA SYMBOL;Ll;0;L;<font> 03F0;;;;N;;;;; @@ -14040,7 +18130,7 @@ FFFD;REPLACEMENT CHARACTER;So;0;ON;;;;;N;;;;; 1D74C;MATHEMATICAL BOLD ITALIC SMALL CHI;Ll;0;L;<font> 03C7;;;;N;;;;; 1D74D;MATHEMATICAL BOLD ITALIC SMALL PSI;Ll;0;L;<font> 03C8;;;;N;;;;; 1D74E;MATHEMATICAL BOLD ITALIC SMALL OMEGA;Ll;0;L;<font> 03C9;;;;N;;;;; -1D74F;MATHEMATICAL BOLD ITALIC PARTIAL DIFFERENTIAL;Sm;0;L;<font> 2202;;;;N;;;;; +1D74F;MATHEMATICAL BOLD ITALIC PARTIAL DIFFERENTIAL;Sm;0;L;<font> 2202;;;;Y;;;;; 1D750;MATHEMATICAL BOLD ITALIC EPSILON SYMBOL;Ll;0;L;<font> 03F5;;;;N;;;;; 1D751;MATHEMATICAL BOLD ITALIC THETA SYMBOL;Ll;0;L;<font> 03D1;;;;N;;;;; 1D752;MATHEMATICAL BOLD ITALIC KAPPA SYMBOL;Ll;0;L;<font> 03F0;;;;N;;;;; @@ -14098,7 +18188,7 @@ FFFD;REPLACEMENT CHARACTER;So;0;ON;;;;;N;;;;; 1D786;MATHEMATICAL SANS-SERIF BOLD SMALL CHI;Ll;0;L;<font> 03C7;;;;N;;;;; 1D787;MATHEMATICAL SANS-SERIF BOLD SMALL PSI;Ll;0;L;<font> 03C8;;;;N;;;;; 1D788;MATHEMATICAL SANS-SERIF BOLD SMALL OMEGA;Ll;0;L;<font> 03C9;;;;N;;;;; -1D789;MATHEMATICAL SANS-SERIF BOLD PARTIAL DIFFERENTIAL;Sm;0;L;<font> 2202;;;;N;;;;; +1D789;MATHEMATICAL SANS-SERIF BOLD PARTIAL DIFFERENTIAL;Sm;0;L;<font> 2202;;;;Y;;;;; 1D78A;MATHEMATICAL SANS-SERIF BOLD EPSILON SYMBOL;Ll;0;L;<font> 03F5;;;;N;;;;; 1D78B;MATHEMATICAL SANS-SERIF BOLD THETA SYMBOL;Ll;0;L;<font> 03D1;;;;N;;;;; 1D78C;MATHEMATICAL SANS-SERIF BOLD KAPPA SYMBOL;Ll;0;L;<font> 03F0;;;;N;;;;; @@ -14156,13 +18246,15 @@ FFFD;REPLACEMENT CHARACTER;So;0;ON;;;;;N;;;;; 1D7C0;MATHEMATICAL SANS-SERIF BOLD ITALIC SMALL CHI;Ll;0;L;<font> 03C7;;;;N;;;;; 1D7C1;MATHEMATICAL SANS-SERIF BOLD ITALIC SMALL PSI;Ll;0;L;<font> 03C8;;;;N;;;;; 1D7C2;MATHEMATICAL SANS-SERIF BOLD ITALIC SMALL OMEGA;Ll;0;L;<font> 03C9;;;;N;;;;; -1D7C3;MATHEMATICAL SANS-SERIF BOLD ITALIC PARTIAL DIFFERENTIAL;Sm;0;L;<font> 2202;;;;N;;;;; +1D7C3;MATHEMATICAL SANS-SERIF BOLD ITALIC PARTIAL DIFFERENTIAL;Sm;0;L;<font> 2202;;;;Y;;;;; 1D7C4;MATHEMATICAL SANS-SERIF BOLD ITALIC EPSILON SYMBOL;Ll;0;L;<font> 03F5;;;;N;;;;; 1D7C5;MATHEMATICAL SANS-SERIF BOLD ITALIC THETA SYMBOL;Ll;0;L;<font> 03D1;;;;N;;;;; 1D7C6;MATHEMATICAL SANS-SERIF BOLD ITALIC KAPPA SYMBOL;Ll;0;L;<font> 03F0;;;;N;;;;; 1D7C7;MATHEMATICAL SANS-SERIF BOLD ITALIC PHI SYMBOL;Ll;0;L;<font> 03D5;;;;N;;;;; 1D7C8;MATHEMATICAL SANS-SERIF BOLD ITALIC RHO SYMBOL;Ll;0;L;<font> 03F1;;;;N;;;;; 1D7C9;MATHEMATICAL SANS-SERIF BOLD ITALIC PI SYMBOL;Ll;0;L;<font> 03D6;;;;N;;;;; +1D7CA;MATHEMATICAL BOLD CAPITAL DIGAMMA;Lu;0;L;<font> 03DC;;;;N;;;;; +1D7CB;MATHEMATICAL BOLD SMALL DIGAMMA;Ll;0;L;<font> 03DD;;;;N;;;;; 1D7CE;MATHEMATICAL BOLD DIGIT ZERO;Nd;0;EN;<font> 0030;0;0;0;N;;;;; 1D7CF;MATHEMATICAL BOLD DIGIT ONE;Nd;0;EN;<font> 0031;1;1;1;N;;;;; 1D7D0;MATHEMATICAL BOLD DIGIT TWO;Nd;0;EN;<font> 0032;2;2;2;N;;;;; @@ -14213,6 +18305,150 @@ FFFD;REPLACEMENT CHARACTER;So;0;ON;;;;;N;;;;; 1D7FD;MATHEMATICAL MONOSPACE DIGIT SEVEN;Nd;0;EN;<font> 0037;7;7;7;N;;;;; 1D7FE;MATHEMATICAL MONOSPACE DIGIT EIGHT;Nd;0;EN;<font> 0038;8;8;8;N;;;;; 1D7FF;MATHEMATICAL MONOSPACE DIGIT NINE;Nd;0;EN;<font> 0039;9;9;9;N;;;;; +1F000;MAHJONG TILE EAST WIND;So;0;ON;;;;;N;;;;; +1F001;MAHJONG TILE SOUTH WIND;So;0;ON;;;;;N;;;;; +1F002;MAHJONG TILE WEST WIND;So;0;ON;;;;;N;;;;; +1F003;MAHJONG TILE NORTH WIND;So;0;ON;;;;;N;;;;; +1F004;MAHJONG TILE RED DRAGON;So;0;ON;;;;;N;;;;; +1F005;MAHJONG TILE GREEN DRAGON;So;0;ON;;;;;N;;;;; +1F006;MAHJONG TILE WHITE DRAGON;So;0;ON;;;;;N;;;;; +1F007;MAHJONG TILE ONE OF CHARACTERS;So;0;ON;;;;;N;;;;; +1F008;MAHJONG TILE TWO OF CHARACTERS;So;0;ON;;;;;N;;;;; +1F009;MAHJONG TILE THREE OF CHARACTERS;So;0;ON;;;;;N;;;;; +1F00A;MAHJONG TILE FOUR OF CHARACTERS;So;0;ON;;;;;N;;;;; +1F00B;MAHJONG TILE FIVE OF CHARACTERS;So;0;ON;;;;;N;;;;; +1F00C;MAHJONG TILE SIX OF CHARACTERS;So;0;ON;;;;;N;;;;; +1F00D;MAHJONG TILE SEVEN OF CHARACTERS;So;0;ON;;;;;N;;;;; +1F00E;MAHJONG TILE EIGHT OF CHARACTERS;So;0;ON;;;;;N;;;;; +1F00F;MAHJONG TILE NINE OF CHARACTERS;So;0;ON;;;;;N;;;;; +1F010;MAHJONG TILE ONE OF BAMBOOS;So;0;ON;;;;;N;;;;; +1F011;MAHJONG TILE TWO OF BAMBOOS;So;0;ON;;;;;N;;;;; +1F012;MAHJONG TILE THREE OF BAMBOOS;So;0;ON;;;;;N;;;;; +1F013;MAHJONG TILE FOUR OF BAMBOOS;So;0;ON;;;;;N;;;;; +1F014;MAHJONG TILE FIVE OF BAMBOOS;So;0;ON;;;;;N;;;;; +1F015;MAHJONG TILE SIX OF BAMBOOS;So;0;ON;;;;;N;;;;; +1F016;MAHJONG TILE SEVEN OF BAMBOOS;So;0;ON;;;;;N;;;;; +1F017;MAHJONG TILE EIGHT OF BAMBOOS;So;0;ON;;;;;N;;;;; +1F018;MAHJONG TILE NINE OF BAMBOOS;So;0;ON;;;;;N;;;;; +1F019;MAHJONG TILE ONE OF CIRCLES;So;0;ON;;;;;N;;;;; +1F01A;MAHJONG TILE TWO OF CIRCLES;So;0;ON;;;;;N;;;;; +1F01B;MAHJONG TILE THREE OF CIRCLES;So;0;ON;;;;;N;;;;; +1F01C;MAHJONG TILE FOUR OF CIRCLES;So;0;ON;;;;;N;;;;; +1F01D;MAHJONG TILE FIVE OF CIRCLES;So;0;ON;;;;;N;;;;; +1F01E;MAHJONG TILE SIX OF CIRCLES;So;0;ON;;;;;N;;;;; +1F01F;MAHJONG TILE SEVEN OF CIRCLES;So;0;ON;;;;;N;;;;; +1F020;MAHJONG TILE EIGHT OF CIRCLES;So;0;ON;;;;;N;;;;; +1F021;MAHJONG TILE NINE OF CIRCLES;So;0;ON;;;;;N;;;;; +1F022;MAHJONG TILE PLUM;So;0;ON;;;;;N;;;;; +1F023;MAHJONG TILE ORCHID;So;0;ON;;;;;N;;;;; +1F024;MAHJONG TILE BAMBOO;So;0;ON;;;;;N;;;;; +1F025;MAHJONG TILE CHRYSANTHEMUM;So;0;ON;;;;;N;;;;; +1F026;MAHJONG TILE SPRING;So;0;ON;;;;;N;;;;; +1F027;MAHJONG TILE SUMMER;So;0;ON;;;;;N;;;;; +1F028;MAHJONG TILE AUTUMN;So;0;ON;;;;;N;;;;; +1F029;MAHJONG TILE WINTER;So;0;ON;;;;;N;;;;; +1F02A;MAHJONG TILE JOKER;So;0;ON;;;;;N;;;;; +1F02B;MAHJONG TILE BACK;So;0;ON;;;;;N;;;;; +1F030;DOMINO TILE HORIZONTAL BACK;So;0;ON;;;;;N;;;;; +1F031;DOMINO TILE HORIZONTAL-00-00;So;0;ON;;;;;N;;;;; +1F032;DOMINO TILE HORIZONTAL-00-01;So;0;ON;;;;;N;;;;; +1F033;DOMINO TILE HORIZONTAL-00-02;So;0;ON;;;;;N;;;;; +1F034;DOMINO TILE HORIZONTAL-00-03;So;0;ON;;;;;N;;;;; +1F035;DOMINO TILE HORIZONTAL-00-04;So;0;ON;;;;;N;;;;; +1F036;DOMINO TILE HORIZONTAL-00-05;So;0;ON;;;;;N;;;;; +1F037;DOMINO TILE HORIZONTAL-00-06;So;0;ON;;;;;N;;;;; +1F038;DOMINO TILE HORIZONTAL-01-00;So;0;ON;;;;;N;;;;; +1F039;DOMINO TILE HORIZONTAL-01-01;So;0;ON;;;;;N;;;;; +1F03A;DOMINO TILE HORIZONTAL-01-02;So;0;ON;;;;;N;;;;; +1F03B;DOMINO TILE HORIZONTAL-01-03;So;0;ON;;;;;N;;;;; +1F03C;DOMINO TILE HORIZONTAL-01-04;So;0;ON;;;;;N;;;;; +1F03D;DOMINO TILE HORIZONTAL-01-05;So;0;ON;;;;;N;;;;; +1F03E;DOMINO TILE HORIZONTAL-01-06;So;0;ON;;;;;N;;;;; +1F03F;DOMINO TILE HORIZONTAL-02-00;So;0;ON;;;;;N;;;;; +1F040;DOMINO TILE HORIZONTAL-02-01;So;0;ON;;;;;N;;;;; +1F041;DOMINO TILE HORIZONTAL-02-02;So;0;ON;;;;;N;;;;; +1F042;DOMINO TILE HORIZONTAL-02-03;So;0;ON;;;;;N;;;;; +1F043;DOMINO TILE HORIZONTAL-02-04;So;0;ON;;;;;N;;;;; +1F044;DOMINO TILE HORIZONTAL-02-05;So;0;ON;;;;;N;;;;; +1F045;DOMINO TILE HORIZONTAL-02-06;So;0;ON;;;;;N;;;;; +1F046;DOMINO TILE HORIZONTAL-03-00;So;0;ON;;;;;N;;;;; +1F047;DOMINO TILE HORIZONTAL-03-01;So;0;ON;;;;;N;;;;; +1F048;DOMINO TILE HORIZONTAL-03-02;So;0;ON;;;;;N;;;;; +1F049;DOMINO TILE HORIZONTAL-03-03;So;0;ON;;;;;N;;;;; +1F04A;DOMINO TILE HORIZONTAL-03-04;So;0;ON;;;;;N;;;;; +1F04B;DOMINO TILE HORIZONTAL-03-05;So;0;ON;;;;;N;;;;; +1F04C;DOMINO TILE HORIZONTAL-03-06;So;0;ON;;;;;N;;;;; +1F04D;DOMINO TILE HORIZONTAL-04-00;So;0;ON;;;;;N;;;;; +1F04E;DOMINO TILE HORIZONTAL-04-01;So;0;ON;;;;;N;;;;; +1F04F;DOMINO TILE HORIZONTAL-04-02;So;0;ON;;;;;N;;;;; +1F050;DOMINO TILE HORIZONTAL-04-03;So;0;ON;;;;;N;;;;; +1F051;DOMINO TILE HORIZONTAL-04-04;So;0;ON;;;;;N;;;;; +1F052;DOMINO TILE HORIZONTAL-04-05;So;0;ON;;;;;N;;;;; +1F053;DOMINO TILE HORIZONTAL-04-06;So;0;ON;;;;;N;;;;; +1F054;DOMINO TILE HORIZONTAL-05-00;So;0;ON;;;;;N;;;;; +1F055;DOMINO TILE HORIZONTAL-05-01;So;0;ON;;;;;N;;;;; +1F056;DOMINO TILE HORIZONTAL-05-02;So;0;ON;;;;;N;;;;; +1F057;DOMINO TILE HORIZONTAL-05-03;So;0;ON;;;;;N;;;;; +1F058;DOMINO TILE HORIZONTAL-05-04;So;0;ON;;;;;N;;;;; +1F059;DOMINO TILE HORIZONTAL-05-05;So;0;ON;;;;;N;;;;; +1F05A;DOMINO TILE HORIZONTAL-05-06;So;0;ON;;;;;N;;;;; +1F05B;DOMINO TILE HORIZONTAL-06-00;So;0;ON;;;;;N;;;;; +1F05C;DOMINO TILE HORIZONTAL-06-01;So;0;ON;;;;;N;;;;; +1F05D;DOMINO TILE HORIZONTAL-06-02;So;0;ON;;;;;N;;;;; +1F05E;DOMINO TILE HORIZONTAL-06-03;So;0;ON;;;;;N;;;;; +1F05F;DOMINO TILE HORIZONTAL-06-04;So;0;ON;;;;;N;;;;; +1F060;DOMINO TILE HORIZONTAL-06-05;So;0;ON;;;;;N;;;;; +1F061;DOMINO TILE HORIZONTAL-06-06;So;0;ON;;;;;N;;;;; +1F062;DOMINO TILE VERTICAL BACK;So;0;ON;;;;;N;;;;; +1F063;DOMINO TILE VERTICAL-00-00;So;0;ON;;;;;N;;;;; +1F064;DOMINO TILE VERTICAL-00-01;So;0;ON;;;;;N;;;;; +1F065;DOMINO TILE VERTICAL-00-02;So;0;ON;;;;;N;;;;; +1F066;DOMINO TILE VERTICAL-00-03;So;0;ON;;;;;N;;;;; +1F067;DOMINO TILE VERTICAL-00-04;So;0;ON;;;;;N;;;;; +1F068;DOMINO TILE VERTICAL-00-05;So;0;ON;;;;;N;;;;; +1F069;DOMINO TILE VERTICAL-00-06;So;0;ON;;;;;N;;;;; +1F06A;DOMINO TILE VERTICAL-01-00;So;0;ON;;;;;N;;;;; +1F06B;DOMINO TILE VERTICAL-01-01;So;0;ON;;;;;N;;;;; +1F06C;DOMINO TILE VERTICAL-01-02;So;0;ON;;;;;N;;;;; +1F06D;DOMINO TILE VERTICAL-01-03;So;0;ON;;;;;N;;;;; +1F06E;DOMINO TILE VERTICAL-01-04;So;0;ON;;;;;N;;;;; +1F06F;DOMINO TILE VERTICAL-01-05;So;0;ON;;;;;N;;;;; +1F070;DOMINO TILE VERTICAL-01-06;So;0;ON;;;;;N;;;;; +1F071;DOMINO TILE VERTICAL-02-00;So;0;ON;;;;;N;;;;; +1F072;DOMINO TILE VERTICAL-02-01;So;0;ON;;;;;N;;;;; +1F073;DOMINO TILE VERTICAL-02-02;So;0;ON;;;;;N;;;;; +1F074;DOMINO TILE VERTICAL-02-03;So;0;ON;;;;;N;;;;; +1F075;DOMINO TILE VERTICAL-02-04;So;0;ON;;;;;N;;;;; +1F076;DOMINO TILE VERTICAL-02-05;So;0;ON;;;;;N;;;;; +1F077;DOMINO TILE VERTICAL-02-06;So;0;ON;;;;;N;;;;; +1F078;DOMINO TILE VERTICAL-03-00;So;0;ON;;;;;N;;;;; +1F079;DOMINO TILE VERTICAL-03-01;So;0;ON;;;;;N;;;;; +1F07A;DOMINO TILE VERTICAL-03-02;So;0;ON;;;;;N;;;;; +1F07B;DOMINO TILE VERTICAL-03-03;So;0;ON;;;;;N;;;;; +1F07C;DOMINO TILE VERTICAL-03-04;So;0;ON;;;;;N;;;;; +1F07D;DOMINO TILE VERTICAL-03-05;So;0;ON;;;;;N;;;;; +1F07E;DOMINO TILE VERTICAL-03-06;So;0;ON;;;;;N;;;;; +1F07F;DOMINO TILE VERTICAL-04-00;So;0;ON;;;;;N;;;;; +1F080;DOMINO TILE VERTICAL-04-01;So;0;ON;;;;;N;;;;; +1F081;DOMINO TILE VERTICAL-04-02;So;0;ON;;;;;N;;;;; +1F082;DOMINO TILE VERTICAL-04-03;So;0;ON;;;;;N;;;;; +1F083;DOMINO TILE VERTICAL-04-04;So;0;ON;;;;;N;;;;; +1F084;DOMINO TILE VERTICAL-04-05;So;0;ON;;;;;N;;;;; +1F085;DOMINO TILE VERTICAL-04-06;So;0;ON;;;;;N;;;;; +1F086;DOMINO TILE VERTICAL-05-00;So;0;ON;;;;;N;;;;; +1F087;DOMINO TILE VERTICAL-05-01;So;0;ON;;;;;N;;;;; +1F088;DOMINO TILE VERTICAL-05-02;So;0;ON;;;;;N;;;;; +1F089;DOMINO TILE VERTICAL-05-03;So;0;ON;;;;;N;;;;; +1F08A;DOMINO TILE VERTICAL-05-04;So;0;ON;;;;;N;;;;; +1F08B;DOMINO TILE VERTICAL-05-05;So;0;ON;;;;;N;;;;; +1F08C;DOMINO TILE VERTICAL-05-06;So;0;ON;;;;;N;;;;; +1F08D;DOMINO TILE VERTICAL-06-00;So;0;ON;;;;;N;;;;; +1F08E;DOMINO TILE VERTICAL-06-01;So;0;ON;;;;;N;;;;; +1F08F;DOMINO TILE VERTICAL-06-02;So;0;ON;;;;;N;;;;; +1F090;DOMINO TILE VERTICAL-06-03;So;0;ON;;;;;N;;;;; +1F091;DOMINO TILE VERTICAL-06-04;So;0;ON;;;;;N;;;;; +1F092;DOMINO TILE VERTICAL-06-05;So;0;ON;;;;;N;;;;; +1F093;DOMINO TILE VERTICAL-06-06;So;0;ON;;;;;N;;;;; 20000;<CJK Ideograph Extension B, First>;Lo;0;L;;;;;N;;;;; 2A6D6;<CJK Ideograph Extension B, Last>;Lo;0;L;;;;;N;;;;; 2F800;CJK COMPATIBILITY IDEOGRAPH-2F800;Lo;0;L;4E3D;;;;N;;;;; @@ -14359,7 +18595,7 @@ FFFD;REPLACEMENT CHARACTER;So;0;ON;;;;;N;;;;; 2F88D;CJK COMPATIBILITY IDEOGRAPH-2F88D;Lo;0;L;5EB6;;;;N;;;;; 2F88E;CJK COMPATIBILITY IDEOGRAPH-2F88E;Lo;0;L;5ECA;;;;N;;;;; 2F88F;CJK COMPATIBILITY IDEOGRAPH-2F88F;Lo;0;L;2A392;;;;N;;;;; -2F890;CJK COMPATIBILITY IDEOGRAPH-2F890;Lo;0;L;5EFE;;;;N;;;;; +2F890;CJK COMPATIBILITY IDEOGRAPH-2F890;Lo;0;L;5EFE;;;9;N;;;;; 2F891;CJK COMPATIBILITY IDEOGRAPH-2F891;Lo;0;L;22331;;;;N;;;;; 2F892;CJK COMPATIBILITY IDEOGRAPH-2F892;Lo;0;L;22331;;;;N;;;;; 2F893;CJK COMPATIBILITY IDEOGRAPH-2F893;Lo;0;L;8201;;;;N;;;;; diff --git a/make/tools/UnicodeData/VERSION b/make/tools/UnicodeData/VERSION new file mode 100644 index 0000000000000000000000000000000000000000..831446cbd27a6de403344b21c9fa93a25357f43d --- /dev/null +++ b/make/tools/UnicodeData/VERSION @@ -0,0 +1 @@ +5.1.0 diff --git a/src/share/classes/com/sun/imageio/plugins/gif/GIFImageMetadata.java b/src/share/classes/com/sun/imageio/plugins/gif/GIFImageMetadata.java index 08da84856b71fb4de5004ec0d45fdb5b04bcb79d..9660d82603a9cacc99cdc58c79a1926e91d5f507 100644 --- a/src/share/classes/com/sun/imageio/plugins/gif/GIFImageMetadata.java +++ b/src/share/classes/com/sun/imageio/plugins/gif/GIFImageMetadata.java @@ -153,7 +153,7 @@ public class GIFImageMetadata extends GIFMetadata { node.setAttribute("imageWidth", Integer.toString(imageWidth)); node.setAttribute("imageHeight", Integer.toString(imageHeight)); node.setAttribute("interlaceFlag", - interlaceFlag ? "true" : "false"); + interlaceFlag ? "TRUE" : "FALSE"); root.appendChild(node); // Local color table @@ -185,9 +185,9 @@ public class GIFImageMetadata extends GIFMetadata { node.setAttribute("disposalMethod", disposalMethodNames[disposalMethod]); node.setAttribute("userInputFlag", - userInputFlag ? "true" : "false"); + userInputFlag ? "TRUE" : "FALSE"); node.setAttribute("transparentColorFlag", - transparentColorFlag ? "true" : "false"); + transparentColorFlag ? "TRUE" : "FALSE"); node.setAttribute("delayTime", Integer.toString(delayTime)); node.setAttribute("transparentColorIndex", diff --git a/src/share/classes/com/sun/imageio/plugins/gif/GIFImageWriter.java b/src/share/classes/com/sun/imageio/plugins/gif/GIFImageWriter.java index 4c7903bfe840e36a2377d5d543468ead28819f03..89f735d8793f3719809f06306a33a95415444757 100644 --- a/src/share/classes/com/sun/imageio/plugins/gif/GIFImageWriter.java +++ b/src/share/classes/com/sun/imageio/plugins/gif/GIFImageWriter.java @@ -55,6 +55,7 @@ import org.w3c.dom.Node; import org.w3c.dom.NodeList; import com.sun.imageio.plugins.common.LZWCompressor; import com.sun.imageio.plugins.common.PaletteBuilder; +import sun.awt.image.ByteComponentRaster; public class GIFImageWriter extends ImageWriter { private static final boolean DEBUG = false; // XXX false for release! @@ -905,10 +906,18 @@ public class GIFImageWriter extends ImageWriter { LZWCompressor compressor = new LZWCompressor(stream, initCodeSize, false); + /* At this moment we know that input image is indexed image. + * We can directly copy data iff: + * - no subsampling required (periodX = 1, periodY = 0) + * - we can access data directly (image is non-tiled, + * i.e. image data are in single block) + * - we can calculate offset in data buffer (next 3 lines) + */ boolean isOptimizedCase = periodX == 1 && periodY == 1 && - sampleModel instanceof ComponentSampleModel && image.getNumXTiles() == 1 && image.getNumYTiles() == 1 && + sampleModel instanceof ComponentSampleModel && + image.getTile(0, 0) instanceof ByteComponentRaster && image.getTile(0, 0).getDataBuffer() instanceof DataBufferByte; int numRowsWritten = 0; @@ -921,11 +930,14 @@ public class GIFImageWriter extends ImageWriter { if (DEBUG) System.out.println("Writing interlaced"); if (isOptimizedCase) { - Raster tile = image.getTile(0, 0); + ByteComponentRaster tile = + (ByteComponentRaster)image.getTile(0, 0); byte[] data = ((DataBufferByte)tile.getDataBuffer()).getData(); ComponentSampleModel csm = (ComponentSampleModel)tile.getSampleModel(); int offset = csm.getOffset(sourceXOffset, sourceYOffset, 0); + // take into account the raster data offset + offset += tile.getDataOffset(0); int lineStride = csm.getScanlineStride(); writeRowsOpt(data, offset, lineStride, compressor, diff --git a/src/share/classes/com/sun/imageio/plugins/gif/GIFMetadata.java b/src/share/classes/com/sun/imageio/plugins/gif/GIFMetadata.java index 42dfbd0bed9317871923b86b51907201629f921d..8acdaa2db49acc0c69186fd4c989e48382d155c2 100644 --- a/src/share/classes/com/sun/imageio/plugins/gif/GIFMetadata.java +++ b/src/share/classes/com/sun/imageio/plugins/gif/GIFMetadata.java @@ -158,13 +158,10 @@ abstract class GIFMetadata extends IIOMetadata { } } String value = attr.getNodeValue(); - // XXX Should be able to use equals() here instead of - // equalsIgnoreCase() but some boolean attributes are incorrectly - // set to "true" or "false" by the J2SE core metadata classes - // getAsTree() method (which are duplicated above). See bug 5082756. - if (value.equalsIgnoreCase("TRUE")) { + // Allow lower case booleans for backward compatibility, #5082756 + if (value.equals("TRUE") || value.equals("true")) { return true; - } else if (value.equalsIgnoreCase("FALSE")) { + } else if (value.equals("FALSE") || value.equals("false")) { return false; } else { fatal(node, "Attribute " + name + " must be 'TRUE' or 'FALSE'!"); diff --git a/src/share/classes/com/sun/imageio/plugins/gif/GIFStreamMetadata.java b/src/share/classes/com/sun/imageio/plugins/gif/GIFStreamMetadata.java index 0979bf3d849f610011eaf7c07242e5574ea3a540..bc0a784b272fb917791476969daca646898665ab 100644 --- a/src/share/classes/com/sun/imageio/plugins/gif/GIFStreamMetadata.java +++ b/src/share/classes/com/sun/imageio/plugins/gif/GIFStreamMetadata.java @@ -202,7 +202,7 @@ public class GIFStreamMetadata extends GIFMetadata { compression_node.appendChild(node); node = new IIOMetadataNode("Lossless"); - node.setAttribute("value", "true"); + node.setAttribute("value", "TRUE"); compression_node.appendChild(node); // NumProgressiveScans not in stream diff --git a/src/share/classes/com/sun/imageio/plugins/jpeg/JFIFMarkerSegment.java b/src/share/classes/com/sun/imageio/plugins/jpeg/JFIFMarkerSegment.java index 883bd1a744751621a8925a5c410975c2ac6e907d..d59a8885c9b159ac89dc5431b710827129845e5a 100644 --- a/src/share/classes/com/sun/imageio/plugins/jpeg/JFIFMarkerSegment.java +++ b/src/share/classes/com/sun/imageio/plugins/jpeg/JFIFMarkerSegment.java @@ -1003,7 +1003,7 @@ class JFIFMarkerSegment extends MarkerSegment { 3, new int [] {0, 1, 2}, null); - ColorModel cm = new ComponentColorModel(JPEG.sRGB, + ColorModel cm = new ComponentColorModel(JPEG.JCS.sRGB, false, false, ColorModel.OPAQUE, diff --git a/src/share/classes/com/sun/imageio/plugins/jpeg/JPEG.java b/src/share/classes/com/sun/imageio/plugins/jpeg/JPEG.java index b16669bc08905f8980d6bf287f273277faa09067..3ed5c5083c3e086babc8a585e27cd362a23caec4 100644 --- a/src/share/classes/com/sun/imageio/plugins/jpeg/JPEG.java +++ b/src/share/classes/com/sun/imageio/plugins/jpeg/JPEG.java @@ -208,15 +208,24 @@ public class JPEG { public static final int [] bOffsRGB = { 2, 1, 0 }; - protected static final ColorSpace sRGB = - ColorSpace.getInstance(ColorSpace.CS_sRGB); - protected static ColorSpace YCC = null; // Can't be final - - static { - try { - YCC = ColorSpace.getInstance(ColorSpace.CS_PYCC); - } catch (IllegalArgumentException e) { - // PYCC.pf may not always be installed + /* These are kept in the inner class to avoid static initialization + * of the CMM class until someone actually needs it. + * (e.g. do not init CMM on the request for jpeg mime types) + */ + public static class JCS { + public static final ColorSpace sRGB = + ColorSpace.getInstance(ColorSpace.CS_sRGB); + public static final ColorSpace YCC; + + static { + ColorSpace cs = null; + try { + cs = ColorSpace.getInstance(ColorSpace.CS_PYCC); + } catch (IllegalArgumentException e) { + // PYCC.pf may not always be installed + } finally { + YCC = cs; + } } } diff --git a/src/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageReader.java b/src/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageReader.java index 48afd2f354c1e1c4fd4e9e3b00a78982f44633f6..faf8261544c2614d5e8fa1f715154b866bce8091 100644 --- a/src/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageReader.java +++ b/src/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageReader.java @@ -228,31 +228,31 @@ public class JPEGImageReader extends ImageReader { (BufferedImage.TYPE_BYTE_GRAY); defaultTypes[JPEG.JCS_RGB] = ImageTypeSpecifier.createInterleaved - (JPEG.sRGB, + (JPEG.JCS.sRGB, JPEG.bOffsRGB, DataBuffer.TYPE_BYTE, false, false); defaultTypes[JPEG.JCS_RGBA] = ImageTypeSpecifier.createPacked - (JPEG.sRGB, + (JPEG.JCS.sRGB, 0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff, DataBuffer.TYPE_INT, false); - if (JPEG.YCC != null) { + if (JPEG.JCS.YCC != null) { defaultTypes[JPEG.JCS_YCC] = ImageTypeSpecifier.createInterleaved - (JPEG.YCC, + (JPEG.JCS.YCC, JPEG.bandOffsets[2], DataBuffer.TYPE_BYTE, false, false); defaultTypes[JPEG.JCS_YCCA] = ImageTypeSpecifier.createInterleaved - (JPEG.YCC, + (JPEG.JCS.YCC, JPEG.bandOffsets[3], DataBuffer.TYPE_BYTE, true, @@ -774,7 +774,7 @@ public class JPEGImageReader extends ImageReader { case JPEG.JCS_RGB: list.add(raw); list.add(getImageType(JPEG.JCS_GRAYSCALE)); - if (JPEG.YCC != null) { + if (JPEG.JCS.YCC != null) { list.add(getImageType(JPEG.JCS_YCC)); } break; @@ -811,7 +811,7 @@ public class JPEGImageReader extends ImageReader { } list.add(getImageType(JPEG.JCS_GRAYSCALE)); - if (JPEG.YCC != null) { // Might be null if PYCC.pf not installed + if (JPEG.JCS.YCC != null) { // Might be null if PYCC.pf not installed list.add(getImageType(JPEG.JCS_YCC)); } break; @@ -893,7 +893,7 @@ public class JPEGImageReader extends ImageReader { (!cs.isCS_sRGB()) && (cm.getNumComponents() == numComponents)) { // Target isn't sRGB, so convert from sRGB to the target - convert = new ColorConvertOp(JPEG.sRGB, cs, null); + convert = new ColorConvertOp(JPEG.JCS.sRGB, cs, null); } else if (csType != ColorSpace.TYPE_RGB) { throw new IIOException("Incompatible color conversion"); } @@ -906,18 +906,18 @@ public class JPEGImageReader extends ImageReader { } break; case JPEG.JCS_YCC: - if (JPEG.YCC == null) { // We can't do YCC at all + if (JPEG.JCS.YCC == null) { // We can't do YCC at all throw new IIOException("Incompatible color conversion"); } - if ((cs != JPEG.YCC) && + if ((cs != JPEG.JCS.YCC) && (cm.getNumComponents() == numComponents)) { - convert = new ColorConvertOp(JPEG.YCC, cs, null); + convert = new ColorConvertOp(JPEG.JCS.YCC, cs, null); } break; case JPEG.JCS_YCCA: // No conversions available; image must be YCCA - if ((JPEG.YCC == null) || // We can't do YCC at all - (cs != JPEG.YCC) || + if ((JPEG.JCS.YCC == null) || // We can't do YCC at all + (cs != JPEG.JCS.YCC) || (cm.getNumComponents() != numComponents)) { throw new IIOException("Incompatible color conversion"); } diff --git a/src/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageReaderSpi.java b/src/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageReaderSpi.java index 5bed06158af8e6ee2c7329b06bf18e90e31846dd..13327e3ea9c08a58026ee9797e1f328db93f48ab 100644 --- a/src/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageReaderSpi.java +++ b/src/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageReaderSpi.java @@ -39,8 +39,6 @@ public class JPEGImageReaderSpi extends ImageReaderSpi { private static String [] writerSpiNames = {"com.sun.imageio.plugins.jpeg.JPEGImageWriterSpi"}; - private boolean registered = false; - public JPEGImageReaderSpi() { super(JPEG.vendor, JPEG.version, @@ -61,26 +59,6 @@ public class JPEGImageReaderSpi extends ImageReaderSpi { ); } - public void onRegistration(ServiceRegistry registry, - Class<?> category) { - if (registered) { - return; - } - try { - java.security.AccessController.doPrivileged( - new sun.security.action.LoadLibraryAction("jpeg")); - // Stuff it all into one lib for first pass - //java.security.AccessController.doPrivileged( - //new sun.security.action.LoadLibraryAction("imageioIJG")); - } catch (Throwable e) { // Fail on any Throwable - // if it can't be loaded, deregister and return - registry.deregisterServiceProvider(this); - return; - } - - registered = true; - } - public String getDescription(Locale locale) { return "Standard JPEG Image Reader"; } diff --git a/src/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageWriter.java b/src/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageWriter.java index 0fbe8f3394527ff10481732fcc0e6f3f48902404..9c585047faa2bef2d44252b7563b25e137cd5e56 100644 --- a/src/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageWriter.java +++ b/src/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageWriter.java @@ -812,13 +812,13 @@ public class JPEGImageWriter extends ImageWriter { } break; case ColorSpace.TYPE_3CLR: - if (cs == JPEG.YCC) { + if (cs == JPEG.JCS.YCC) { if (!alpha) { if (jfif != null) { convertTosRGB = true; convertOp = new ColorConvertOp(cs, - JPEG.sRGB, + JPEG.JCS.sRGB, null); outCsType = JPEG.JCS_YCbCr; } else if (adobe != null) { @@ -1494,7 +1494,7 @@ public class JPEGImageWriter extends ImageWriter { } break; case ColorSpace.TYPE_3CLR: - if (cs == JPEG.YCC) { + if (cs == JPEG.JCS.YCC) { if (alpha) { retval = JPEG.JCS_YCCA; } else { @@ -1533,7 +1533,7 @@ public class JPEGImageWriter extends ImageWriter { } break; case ColorSpace.TYPE_3CLR: - if (cs == JPEG.YCC) { + if (cs == JPEG.JCS.YCC) { if (alpha) { retval = JPEG.JCS_YCCA; } else { @@ -1579,7 +1579,7 @@ public class JPEGImageWriter extends ImageWriter { } break; case ColorSpace.TYPE_3CLR: - if (cs == JPEG.YCC) { + if (cs == JPEG.JCS.YCC) { if (alpha) { retval = JPEG.JCS_YCCA; } else { diff --git a/src/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageWriterSpi.java b/src/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageWriterSpi.java index 936c65c544ff648ca86d48de4a3403198d4bf79e..717b4360794d47798ac0849078beca8bfeb2996c 100644 --- a/src/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageWriterSpi.java +++ b/src/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageWriterSpi.java @@ -42,8 +42,6 @@ public class JPEGImageWriterSpi extends ImageWriterSpi { private static String [] readerSpiNames = {"com.sun.imageio.plugins.jpeg.JPEGImageReaderSpi"}; - private boolean registered = false; - public JPEGImageWriterSpi() { super(JPEG.vendor, JPEG.version, @@ -68,23 +66,6 @@ public class JPEGImageWriterSpi extends ImageWriterSpi { return "Standard JPEG Image Writer"; } - public void onRegistration(ServiceRegistry registry, - Class<?> category) { - if (registered) { - return; - } - try { - java.security.AccessController.doPrivileged( - new sun.security.action.LoadLibraryAction("jpeg")); - } catch (Throwable e) { // Fail on any Throwable - // if it can't be loaded, deregister and return - registry.deregisterServiceProvider(this); - return; - } - - registered = true; - } - public boolean isFormatLossless() { return false; } diff --git a/src/share/classes/com/sun/imageio/plugins/jpeg/JPEGMetadata.java b/src/share/classes/com/sun/imageio/plugins/jpeg/JPEGMetadata.java index 7f753341c931bb46abc84151f3623287b16ed4ef..044f7d632f65a27863caa021ef03c4db3d354b1e 100644 --- a/src/share/classes/com/sun/imageio/plugins/jpeg/JPEGMetadata.java +++ b/src/share/classes/com/sun/imageio/plugins/jpeg/JPEGMetadata.java @@ -490,7 +490,7 @@ public class JPEGMetadata extends IIOMetadata implements Cloneable { } break; case ColorSpace.TYPE_3CLR: - if (cs == JPEG.YCC) { + if (cs == JPEG.JCS.YCC) { wantJFIF = false; componentIDs[0] = (byte) 'Y'; componentIDs[1] = (byte) 'C'; @@ -955,7 +955,7 @@ public class JPEGMetadata extends IIOMetadata implements Cloneable { // Lossless - false IIOMetadataNode lossless = new IIOMetadataNode("Lossless"); - lossless.setAttribute("value", "false"); + lossless.setAttribute("value", "FALSE"); compression.appendChild(lossless); // NumProgressiveScans - count sos segments diff --git a/src/share/classes/com/sun/imageio/plugins/png/PNGImageReader.java b/src/share/classes/com/sun/imageio/plugins/png/PNGImageReader.java index 84a593264bee03d80896f5cce171ee9ee59f079b..f35165420e95d49f044be5979eda962eac6c0508 100644 --- a/src/share/classes/com/sun/imageio/plugins/png/PNGImageReader.java +++ b/src/share/classes/com/sun/imageio/plugins/png/PNGImageReader.java @@ -37,6 +37,7 @@ import java.awt.image.WritableRaster; import java.io.BufferedInputStream; import java.io.ByteArrayInputStream; import java.io.DataInputStream; +import java.io.EOFException; import java.io.InputStream; import java.io.IOException; import java.io.SequenceInputStream; @@ -59,7 +60,7 @@ import com.sun.imageio.plugins.common.SubImageInputStream; import java.io.ByteArrayOutputStream; import sun.awt.image.ByteInterleavedRaster; -class PNGImageDataEnumeration implements Enumeration { +class PNGImageDataEnumeration implements Enumeration<InputStream> { boolean firstTime = true; ImageInputStream stream; @@ -72,7 +73,7 @@ class PNGImageDataEnumeration implements Enumeration { int type = stream.readInt(); // skip chunk type } - public Object nextElement() { + public InputStream nextElement() { try { firstTime = false; ImageInputStream iis = new SubImageInputStream(stream, length); @@ -207,25 +208,17 @@ public class PNGImageReader extends ImageReader { resetStreamSettings(); } - private String readNullTerminatedString(String charset) throws IOException { + private String readNullTerminatedString(String charset, int maxLen) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); int b; - while ((b = stream.read()) != 0) { + int count = 0; + while ((maxLen > count++) && ((b = stream.read()) != 0)) { + if (b == -1) throw new EOFException(); baos.write(b); } return new String(baos.toByteArray(), charset); } - private String readNullTerminatedString() throws IOException { - StringBuilder b = new StringBuilder(); - int c; - - while ((c = stream.read()) != 0) { - b.append((char)c); - } - return b.toString(); - } - private void readHeader() throws IIOException { if (gotHeader) { return; @@ -434,7 +427,7 @@ public class PNGImageReader extends ImageReader { } private void parse_iCCP_chunk(int chunkLength) throws IOException { - String keyword = readNullTerminatedString(); + String keyword = readNullTerminatedString("ISO-8859-1", 80); metadata.iCCP_profileName = keyword; metadata.iCCP_compressionMethod = stream.readUnsignedByte(); @@ -450,7 +443,7 @@ public class PNGImageReader extends ImageReader { private void parse_iTXt_chunk(int chunkLength) throws IOException { long chunkStart = stream.getStreamPosition(); - String keyword = readNullTerminatedString(); + String keyword = readNullTerminatedString("ISO-8859-1", 80); metadata.iTXt_keyword.add(keyword); int compressionFlag = stream.readUnsignedByte(); @@ -459,15 +452,17 @@ public class PNGImageReader extends ImageReader { int compressionMethod = stream.readUnsignedByte(); metadata.iTXt_compressionMethod.add(Integer.valueOf(compressionMethod)); - String languageTag = readNullTerminatedString("UTF8"); + String languageTag = readNullTerminatedString("UTF8", 80); metadata.iTXt_languageTag.add(languageTag); + long pos = stream.getStreamPosition(); + int maxLen = (int)(chunkStart + chunkLength - pos); String translatedKeyword = - readNullTerminatedString("UTF8"); + readNullTerminatedString("UTF8", maxLen); metadata.iTXt_translatedKeyword.add(translatedKeyword); String text; - long pos = stream.getStreamPosition(); + pos = stream.getStreamPosition(); byte[] b = new byte[(int)(chunkStart + chunkLength - pos)]; stream.readFully(b); @@ -511,7 +506,7 @@ public class PNGImageReader extends ImageReader { private void parse_sPLT_chunk(int chunkLength) throws IOException, IIOException { - metadata.sPLT_paletteName = readNullTerminatedString(); + metadata.sPLT_paletteName = readNullTerminatedString("ISO-8859-1", 80); chunkLength -= metadata.sPLT_paletteName.length() + 1; int sampleDepth = stream.readUnsignedByte(); @@ -554,12 +549,12 @@ public class PNGImageReader extends ImageReader { } private void parse_tEXt_chunk(int chunkLength) throws IOException { - String keyword = readNullTerminatedString(); + String keyword = readNullTerminatedString("ISO-8859-1", 80); metadata.tEXt_keyword.add(keyword); byte[] b = new byte[chunkLength - keyword.length() - 1]; stream.readFully(b); - metadata.tEXt_text.add(new String(b)); + metadata.tEXt_text.add(new String(b, "ISO-8859-1")); } private void parse_tIME_chunk() throws IOException { @@ -640,7 +635,7 @@ public class PNGImageReader extends ImageReader { } private void parse_zTXt_chunk(int chunkLength) throws IOException { - String keyword = readNullTerminatedString(); + String keyword = readNullTerminatedString("ISO-8859-1", 80); metadata.zTXt_keyword.add(keyword); int method = stream.readUnsignedByte(); @@ -648,7 +643,7 @@ public class PNGImageReader extends ImageReader { byte[] b = new byte[chunkLength - keyword.length() - 2]; stream.readFully(b); - metadata.zTXt_text.add(new String(inflate(b))); + metadata.zTXt_text.add(new String(inflate(b), "ISO-8859-1")); } private void readMetadata() throws IIOException { @@ -1263,7 +1258,7 @@ public class PNGImageReader extends ImageReader { try { stream.seek(imageStartPosition); - Enumeration e = new PNGImageDataEnumeration(stream); + Enumeration<InputStream> e = new PNGImageDataEnumeration(stream); InputStream is = new SequenceInputStream(e); /* InflaterInputStream uses an Inflater instance which consumes diff --git a/src/share/classes/com/sun/imageio/plugins/png/PNGImageWriter.java b/src/share/classes/com/sun/imageio/plugins/png/PNGImageWriter.java index ea4233a68ea013fa7dcb555af1aa6a46dbc000e4..0f9cc785f92f5aef55436eb16b76dafb75fdd94d 100644 --- a/src/share/classes/com/sun/imageio/plugins/png/PNGImageWriter.java +++ b/src/share/classes/com/sun/imageio/plugins/png/PNGImageWriter.java @@ -674,13 +674,8 @@ public class PNGImageWriter extends ImageWriter { private byte[] deflate(byte[] b) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); DeflaterOutputStream dos = new DeflaterOutputStream(baos); - - int len = b.length; - for (int i = 0; i < len; i++) { - dos.write((int)(0xff & b[i])); - } + dos.write(b); dos.close(); - return baos.toByteArray(); } @@ -736,7 +731,7 @@ public class PNGImageWriter extends ImageWriter { cs.writeByte(compressionMethod); String text = (String)textIter.next(); - cs.write(deflate(text.getBytes())); + cs.write(deflate(text.getBytes("ISO-8859-1"))); cs.finish(); } } diff --git a/src/share/classes/com/sun/imageio/plugins/png/PNGMetadata.java b/src/share/classes/com/sun/imageio/plugins/png/PNGMetadata.java index 5475fc796512d5fac1a0ad80cf34aa2848c0c503..9da722988849d935c40997ab37b55e4831f5de85 100644 --- a/src/share/classes/com/sun/imageio/plugins/png/PNGMetadata.java +++ b/src/share/classes/com/sun/imageio/plugins/png/PNGMetadata.java @@ -211,8 +211,8 @@ public class PNGMetadata extends IIOMetadata implements Cloneable { public int sRGB_renderingIntent; // tEXt chunk - public ArrayList tEXt_keyword = new ArrayList(); // 1-79 char Strings - public ArrayList tEXt_text = new ArrayList(); // Strings + public ArrayList<String> tEXt_keyword = new ArrayList<String>(); // 1-79 characters + public ArrayList<String> tEXt_text = new ArrayList<String>(); // tIME chunk public boolean tIME_present; @@ -235,13 +235,13 @@ public class PNGMetadata extends IIOMetadata implements Cloneable { public int tRNS_blue; // zTXt chunk - public ArrayList zTXt_keyword = new ArrayList(); // Strings - public ArrayList zTXt_compressionMethod = new ArrayList(); // Integers - public ArrayList zTXt_text = new ArrayList(); // Strings + public ArrayList<String> zTXt_keyword = new ArrayList<String>(); + public ArrayList<Integer> zTXt_compressionMethod = new ArrayList<Integer>(); + public ArrayList<String> zTXt_text = new ArrayList<String>(); // Unknown chunks - public ArrayList unknownChunkType = new ArrayList(); // Strings - public ArrayList unknownChunkData = new ArrayList(); // byte arrays + public ArrayList<String> unknownChunkType = new ArrayList<String>(); + public ArrayList<byte[]> unknownChunkData = new ArrayList<byte[]>(); public PNGMetadata() { super(true, @@ -426,21 +426,14 @@ public class PNGMetadata extends IIOMetadata implements Cloneable { return false; } - private ArrayList cloneBytesArrayList(ArrayList in) { + private ArrayList<byte[]> cloneBytesArrayList(ArrayList<byte[]> in) { if (in == null) { return null; } else { - ArrayList list = new ArrayList(in.size()); - Iterator iter = in.iterator(); - while (iter.hasNext()) { - Object o = iter.next(); - if (o == null) { - list.add(null); - } else { - list.add(((byte[])o).clone()); - } + ArrayList<byte[]> list = new ArrayList<byte[]>(in.size()); + for (byte[] b: in) { + list.add((b == null) ? null : (byte[])b.clone()); } - return list; } } @@ -600,7 +593,7 @@ public class PNGMetadata extends IIOMetadata implements Cloneable { IIOMetadataNode iTXt_node = new IIOMetadataNode("iTXtEntry"); iTXt_node.setAttribute("keyword", iTXt_keyword.get(i)); iTXt_node.setAttribute("compressionFlag", - iTXt_compressionFlag.get(i) ? "1" : "0"); + iTXt_compressionFlag.get(i) ? "TRUE" : "FALSE"); iTXt_node.setAttribute("compressionMethod", iTXt_compressionMethod.get(i).toString()); iTXt_node.setAttribute("languageTag", @@ -832,7 +825,7 @@ public class PNGMetadata extends IIOMetadata implements Cloneable { } node = new IIOMetadataNode("BlackIsZero"); - node.setAttribute("value", "true"); + node.setAttribute("value", "TRUE"); chroma_node.appendChild(node); if (PLTE_present) { @@ -894,7 +887,7 @@ public class PNGMetadata extends IIOMetadata implements Cloneable { compression_node.appendChild(node); node = new IIOMetadataNode("Lossless"); - node.setAttribute("value", "true"); + node.setAttribute("value", "TRUE"); compression_node.appendChild(node); node = new IIOMetadataNode("NumProgressiveScans"); @@ -1040,7 +1033,7 @@ public class PNGMetadata extends IIOMetadata implements Cloneable { node.setAttribute("language", iTXt_languageTag.get(i)); if (iTXt_compressionFlag.get(i)) { - node.setAttribute("compression", "deflate"); + node.setAttribute("compression", "zip"); } else { node.setAttribute("compression", "none"); } @@ -1052,7 +1045,7 @@ public class PNGMetadata extends IIOMetadata implements Cloneable { node = new IIOMetadataNode("TextEntry"); node.setAttribute("keyword", (String)zTXt_keyword.get(i)); node.setAttribute("value", (String)zTXt_text.get(i)); - node.setAttribute("compression", "deflate"); + node.setAttribute("compression", "zip"); text_node.appendChild(node); } @@ -1162,12 +1155,13 @@ public class PNGMetadata extends IIOMetadata implements Cloneable { } } String value = attr.getNodeValue(); - if (value.equals("true")) { + // Allow lower case booleans for backward compatibility, #5082756 + if (value.equals("TRUE") || value.equals("true")) { return true; - } else if (value.equals("false")) { + } else if (value.equals("FALSE") || value.equals("false")) { return false; } else { - fatal(node, "Attribute " + name + " must be 'true' or 'false'!"); + fatal(node, "Attribute " + name + " must be 'TRUE' or 'FALSE'!"); return false; } } @@ -1421,26 +1415,30 @@ public class PNGMetadata extends IIOMetadata implements Cloneable { } String keyword = getAttribute(iTXt_node, "keyword"); - iTXt_keyword.add(keyword); + if (isValidKeyword(keyword)) { + iTXt_keyword.add(keyword); + + boolean compressionFlag = + getBooleanAttribute(iTXt_node, "compressionFlag"); + iTXt_compressionFlag.add(Boolean.valueOf(compressionFlag)); - boolean compressionFlag = - getBooleanAttribute(iTXt_node, "compressionFlag"); - iTXt_compressionFlag.add(Boolean.valueOf(compressionFlag)); + String compressionMethod = + getAttribute(iTXt_node, "compressionMethod"); + iTXt_compressionMethod.add(Integer.valueOf(compressionMethod)); - String compressionMethod = - getAttribute(iTXt_node, "compressionMethod"); - iTXt_compressionMethod.add(Integer.valueOf(compressionMethod)); + String languageTag = + getAttribute(iTXt_node, "languageTag"); + iTXt_languageTag.add(languageTag); - String languageTag = - getAttribute(iTXt_node, "languageTag"); - iTXt_languageTag.add(languageTag); + String translatedKeyword = + getAttribute(iTXt_node, "translatedKeyword"); + iTXt_translatedKeyword.add(translatedKeyword); - String translatedKeyword = - getAttribute(iTXt_node, "translatedKeyword"); - iTXt_translatedKeyword.add(translatedKeyword); + String text = getAttribute(iTXt_node, "text"); + iTXt_text.add(text); - String text = getAttribute(iTXt_node, "text"); - iTXt_text.add(text); + } + // silently skip invalid text entry iTXt_node = iTXt_node.getNextSibling(); } @@ -1692,11 +1690,45 @@ public class PNGMetadata extends IIOMetadata implements Cloneable { } } - private boolean isISOLatin(String s) { + /* + * Accrding to PNG spec, keywords are restricted to 1 to 79 bytes + * in length. Keywords shall contain only printable Latin-1 characters + * and spaces; To reduce the chances for human misreading of a keyword, + * leading spaces, trailing spaces, and consecutive spaces are not + * permitted in keywords. + * + * See: http://www.w3.org/TR/PNG/#11keywords + */ + private boolean isValidKeyword(String s) { + int len = s.length(); + if (len < 1 || len >= 80) { + return false; + } + if (s.startsWith(" ") || s.endsWith(" ") || s.contains(" ")) { + return false; + } + return isISOLatin(s, false); + } + + /* + * According to PNG spec, keyword shall contain only printable + * Latin-1 [ISO-8859-1] characters and spaces; that is, only + * character codes 32-126 and 161-255 decimal are allowed. + * For Latin-1 value fields the 0x10 (linefeed) control + * character is aloowed too. + * + * See: http://www.w3.org/TR/PNG/#11keywords + */ + private boolean isISOLatin(String s, boolean isLineFeedAllowed) { int len = s.length(); for (int i = 0; i < len; i++) { - if (s.charAt(i) > 255) { - return false; + char c = s.charAt(i); + if (c < 32 || c > 255 || (c > 126 && c < 161)) { + // not printable. Check whether this is an allowed + // control char + if (!isLineFeedAllowed || c != 0x10) { + return false; + } } } return true; @@ -1929,19 +1961,22 @@ public class PNGMetadata extends IIOMetadata implements Cloneable { while (child != null) { String childName = child.getNodeName(); if (childName.equals("TextEntry")) { - String keyword = getAttribute(child, "keyword"); + String keyword = + getAttribute(child, "keyword", "", false); String value = getAttribute(child, "value"); - String encoding = getAttribute(child, "encoding"); - String language = getAttribute(child, "language"); + String language = + getAttribute(child, "language", "", false); String compression = - getAttribute(child, "compression"); + getAttribute(child, "compression", "none", false); - if (isISOLatin(value)) { + if (!isValidKeyword(keyword)) { + // Just ignore this node, PNG requires keywords + } else if (isISOLatin(value, true)) { if (compression.equals("zip")) { // Use a zTXt node zTXt_keyword.add(keyword); zTXt_text.add(value); - zTXt_compressionMethod.add(new Integer(0)); + zTXt_compressionMethod.add(Integer.valueOf(0)); } else { // Use a tEXt node tEXt_keyword.add(keyword); @@ -1998,14 +2033,14 @@ public class PNGMetadata extends IIOMetadata implements Cloneable { sBIT_present = false; sPLT_present = false; sRGB_present = false; - tEXt_keyword = new ArrayList(); - tEXt_text = new ArrayList(); + tEXt_keyword = new ArrayList<String>(); + tEXt_text = new ArrayList<String>(); tIME_present = false; tRNS_present = false; - zTXt_keyword = new ArrayList(); - zTXt_compressionMethod = new ArrayList(); - zTXt_text = new ArrayList(); - unknownChunkType = new ArrayList(); - unknownChunkData = new ArrayList(); + zTXt_keyword = new ArrayList<String>(); + zTXt_compressionMethod = new ArrayList<Integer>(); + zTXt_text = new ArrayList<String>(); + unknownChunkType = new ArrayList<String>(); + unknownChunkData = new ArrayList<byte[]>(); } } diff --git a/src/share/classes/com/sun/imageio/stream/StreamCloser.java b/src/share/classes/com/sun/imageio/stream/StreamCloser.java index f39b98eb05d41f14ecb47f3410c99386cd64401d..03c6ce3236440db4297775d00cdf47da4abd9efc 100644 --- a/src/share/classes/com/sun/imageio/stream/StreamCloser.java +++ b/src/share/classes/com/sun/imageio/stream/StreamCloser.java @@ -94,6 +94,10 @@ public class StreamCloser { tgn != null; tg = tgn, tgn = tg.getParent()); streamCloser = new Thread(tg, streamCloserRunnable); + /* Set context class loader to null in order to avoid + * keeping a strong reference to an application classloader. + */ + streamCloser.setContextClassLoader(null); Runtime.getRuntime().addShutdownHook(streamCloser); return null; } diff --git a/src/share/classes/com/sun/java/swing/plaf/gtk/GTKIconFactory.java b/src/share/classes/com/sun/java/swing/plaf/gtk/GTKIconFactory.java index 850aa154b83d58876eb1e099dd9d910272fa2ccb..23df1928fd4942f6b2944eaadb1c9a2afc8c2f70 100644 --- a/src/share/classes/com/sun/java/swing/plaf/gtk/GTKIconFactory.java +++ b/src/share/classes/com/sun/java/swing/plaf/gtk/GTKIconFactory.java @@ -279,20 +279,22 @@ class GTKIconFactory { public void paintIcon(SynthContext context, Graphics g, int x, int y, int w, int h) { - JToolBar toolbar = (JToolBar)context.getComponent(); - Orientation orientation = - (toolbar.getOrientation() == JToolBar.HORIZONTAL ? - Orientation.HORIZONTAL : Orientation.VERTICAL); - - if (style == null) { - style = SynthLookAndFeel.getStyleFactory().getStyle( - context.getComponent(), GTKRegion.HANDLE_BOX); - } - context = new SynthContext(toolbar, GTKRegion.HANDLE_BOX, - style, SynthConstants.ENABLED); + if (context != null) { + JToolBar toolbar = (JToolBar)context.getComponent(); + Orientation orientation = + (toolbar.getOrientation() == JToolBar.HORIZONTAL ? + Orientation.HORIZONTAL : Orientation.VERTICAL); + + if (style == null) { + style = SynthLookAndFeel.getStyleFactory().getStyle( + context.getComponent(), GTKRegion.HANDLE_BOX); + } + context = new SynthContext(toolbar, GTKRegion.HANDLE_BOX, + style, SynthConstants.ENABLED); - GTKPainter.INSTANCE.paintIcon(context, g, - getMethod(), x, y, w, h, orientation); + GTKPainter.INSTANCE.paintIcon(context, g, + getMethod(), x, y, w, h, orientation); + } } public int getIconWidth(SynthContext context) { @@ -336,12 +338,14 @@ class GTKIconFactory { public void paintIcon(SynthContext context, Graphics g, int x, int y, int w, int h) { - ArrowType arrowDir = ArrowType.RIGHT; - if (!context.getComponent().getComponentOrientation().isLeftToRight()) { - arrowDir = ArrowType.LEFT; + if (context != null) { + ArrowType arrowDir = ArrowType.RIGHT; + if (!context.getComponent().getComponentOrientation().isLeftToRight()) { + arrowDir = ArrowType.LEFT; + } + GTKPainter.INSTANCE.paintIcon(context, g, + getMethod(), x, y, w, h, arrowDir); } - GTKPainter.INSTANCE.paintIcon(context, g, - getMethod(), x, y, w, h, arrowDir); } } } diff --git a/src/share/classes/com/sun/java/swing/plaf/windows/WindowsFileChooserUI.java b/src/share/classes/com/sun/java/swing/plaf/windows/WindowsFileChooserUI.java index 57af97958dd0646a431aeed8b22135bf66ddfc2e..79d06782e8b4b3cdabae0464904dedb89915b982 100644 --- a/src/share/classes/com/sun/java/swing/plaf/windows/WindowsFileChooserUI.java +++ b/src/share/classes/com/sun/java/swing/plaf/windows/WindowsFileChooserUI.java @@ -39,6 +39,8 @@ import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.util.*; +import java.security.AccessController; +import java.security.PrivilegedAction; import sun.awt.shell.ShellFolder; import sun.awt.OSInfo; @@ -1143,7 +1145,11 @@ public class WindowsFileChooserUI extends BasicFileChooserUI { File[] baseFolders; if (useShellFolder) { - baseFolders = (File[])ShellFolder.get("fileChooserComboBoxFolders"); + baseFolders = AccessController.doPrivileged(new PrivilegedAction<File[]>() { + public File[] run() { + return (File[]) ShellFolder.get("fileChooserComboBoxFolders"); + } + }); } else { baseFolders = fsv.getRoots(); } diff --git a/src/share/classes/com/sun/nio/file/ExtendedCopyOption.java b/src/share/classes/com/sun/nio/file/ExtendedCopyOption.java new file mode 100644 index 0000000000000000000000000000000000000000..b612c0e8d59fb50b986dffd90b20a509fa23d30e --- /dev/null +++ b/src/share/classes/com/sun/nio/file/ExtendedCopyOption.java @@ -0,0 +1,43 @@ +/* + * Copyright 2007-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.nio.file; + +import java.nio.file.CopyOption; + +/** + * Defines <em>extended</em> copy options supported on some platforms + * by Sun's provider implementation. + * + * @since 1.7 + */ + +public enum ExtendedCopyOption implements CopyOption { + /** + * The copy may be interrupted by the {@link Thread#interrupt interrupt} + * method. + */ + INTERRUPTIBLE, +} diff --git a/src/share/classes/com/sun/nio/file/ExtendedOpenOption.java b/src/share/classes/com/sun/nio/file/ExtendedOpenOption.java new file mode 100644 index 0000000000000000000000000000000000000000..25208d81257ef3efcf894fd1ee7d7062d79e7a2d --- /dev/null +++ b/src/share/classes/com/sun/nio/file/ExtendedOpenOption.java @@ -0,0 +1,50 @@ +/* + * Copyright 2007-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.nio.file; + +import java.nio.file.OpenOption; + +/** + * Defines <em>extended</em> open options supported on some platforms + * by Sun's provider implementation. + * + * @since 1.7 + */ + +public enum ExtendedOpenOption implements OpenOption { + /** + * Prevent operations on the file that request read access. + */ + NOSHARE_READ, + /** + * Prevent operations on the file that request write access. + */ + NOSHARE_WRITE, + /** + * Prevent operations on the file that request delete access. + */ + NOSHARE_DELETE; +} diff --git a/src/share/classes/com/sun/nio/file/ExtendedWatchEventModifier.java b/src/share/classes/com/sun/nio/file/ExtendedWatchEventModifier.java new file mode 100644 index 0000000000000000000000000000000000000000..0f6ddc3276af876996e2ab0500a18770c0ea785f --- /dev/null +++ b/src/share/classes/com/sun/nio/file/ExtendedWatchEventModifier.java @@ -0,0 +1,43 @@ +/* + * Copyright 2007-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.nio.file; + +import java.nio.file.WatchEvent.Modifier; + +/** + * Defines <em>extended</em> watch event modifiers supported on some platforms + * by Sun's provider implementation. + * + * @since 1.7 + */ + +public enum ExtendedWatchEventModifier implements Modifier { + + /** + * Register a file tree instead of a single directory. + */ + FILE_TREE, +} diff --git a/src/share/classes/com/sun/nio/file/SensitivityWatchEventModifier.java b/src/share/classes/com/sun/nio/file/SensitivityWatchEventModifier.java new file mode 100644 index 0000000000000000000000000000000000000000..57ab111b00b9b1c7c87d05513e37b667525a5f54 --- /dev/null +++ b/src/share/classes/com/sun/nio/file/SensitivityWatchEventModifier.java @@ -0,0 +1,62 @@ +/* + * Copyright 2007-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.nio.file; + +import java.nio.file.WatchEvent.Modifier; + +/** + * Defines the <em>sensitivity levels</em> when registering objects with a + * watch service implementation that polls the file system. + * + * @since 1.7 + */ + +public enum SensitivityWatchEventModifier implements Modifier { + /** + * High sensitivity. + */ + HIGH(2), + /** + * Medium sensitivity. + */ + MEDIUM(10), + /** + * Low sensitivity. + */ + LOW(30); + + /** + * Returns the sensitivity in seconds. + */ + public int sensitivityValueInSeconds() { + return sensitivity; + } + + private final int sensitivity; + private SensitivityWatchEventModifier(int sensitivity) { + this.sensitivity = sensitivity; + } +} diff --git a/src/share/classes/com/sun/servicetag/resources/register.html b/src/share/classes/com/sun/servicetag/resources/register.html index 23e9d717ab7ec713ea51f24141057792c0656f29..29a275b35be30833304f98ebf9abea88f94a9422 100644 --- a/src/share/classes/com/sun/servicetag/resources/register.html +++ b/src/share/classes/com/sun/servicetag/resources/register.html @@ -68,7 +68,7 @@ a:visited,a:visited code{color:#917E9C} <table width="708" border="0" cellspacing="0" cellpadding="3"> <tr valign="top"> <td width="126" height="35"> - <form name="form1" method="post" action="@@REGISTRATION_URL@@" enctype="text/xml"> + <form name="form1" method="post" action="@@REGISTRATION_URL@@"> <input type="hidden" name="servicetag_payload" value="@@REGISTRATION_PAYLOAD@@"> <input type="submit" name="Submit"border="0" class="buttonblue" onmouseover="this.style.color='#fbe249';" onmouseout="this.style.color='#FFF';" value="Register My JDK"> </form></td> diff --git a/src/share/classes/com/sun/servicetag/resources/register_ja.html b/src/share/classes/com/sun/servicetag/resources/register_ja.html index 56ee84f54267a45cc9d4231c65f9c526b7e1a3ea..fc7cf0517c2b8d0b6b4d428fcdabf3788c35dea7 100644 --- a/src/share/classes/com/sun/servicetag/resources/register_ja.html +++ b/src/share/classes/com/sun/servicetag/resources/register_ja.html @@ -62,7 +62,7 @@ a:visited,a:visited code{color:#917E9C} <p class="style1">å¿…è¦ã«ãªã‚‹ã®ã¯ã€Sun 開発者å‘ã‘ãƒãƒƒãƒˆãƒ¯ãƒ¼ã‚¯ã‚¢ã‚«ã‚¦ãƒ³ãƒˆã¾ãŸã¯ãã®ä»–ã® Sun オンラインアカウントã ã‘ã§ã™ã€‚ ã¾ã ã‚¢ã‚«ã‚¦ãƒ³ãƒˆãŒãªã„å ´åˆã¯ã€ã‚¢ã‚«ã‚¦ãƒ³ãƒˆã®ä½œæˆãŒæ±‚ã‚られã¾ã™ã€‚ </p> <table width="708" border="0" cellspacing="0" cellpadding="3"> <tr valign="top"> - <td width="126" height="35"><form name="form1" method="post" action="@@REGISTRATION_URL@@" enctype="text/xml"> + <td width="126" height="35"><form name="form1" method="post" action="@@REGISTRATION_URL@@"> <input type="hidden" name="servicetag_payload" value="@@REGISTRATION_PAYLOAD@@"> <input type="submit" name="Submit"border="0" class="buttonblue" onmouseover="this.style.color='#fbe249';" onmouseout="this.style.color='#FFF';" value="JDK 製å“登録"> </form></td> diff --git a/src/share/classes/com/sun/servicetag/resources/register_zh_CN.html b/src/share/classes/com/sun/servicetag/resources/register_zh_CN.html index c47929fb7445d2aceae6f9ac4ef9b4fe658a1e8d..92cf04b7f10b3af8d4722731f794958da96d0cd9 100644 --- a/src/share/classes/com/sun/servicetag/resources/register_zh_CN.html +++ b/src/share/classes/com/sun/servicetag/resources/register_zh_CN.html @@ -63,7 +63,7 @@ a:visited,a:visited code{color:#917E9C} <p class="style1">您需è¦å…·æœ‰ Sun å¼€å‘者网络或其他 Sun è”æœºå¸æˆ·ã€‚如果您没有,系统将æç¤ºæ‚¨åˆ›å»ºä¸€ä¸ªã€‚ </p> <table width="708" border="0" cellspacing="0" cellpadding="3"> <tr valign="top"> - <td width="126" height="35"><form name="form1" method="post" action="@@REGISTRATION_URL@@" enctype="text/xml"> + <td width="126" height="35"><form name="form1" method="post" action="@@REGISTRATION_URL@@"> <input type="hidden" name="servicetag_payload" value="@@REGISTRATION_PAYLOAD@@"> <input type="submit" name="Submit"border="0" class="buttonblue" onmouseover="this.style.color='#fbe249';" onmouseout="this.style.color='#FFF';" value="注册我的 JDK"> </form></td> diff --git a/src/share/classes/java/awt/GraphicsEnvironment.java b/src/share/classes/java/awt/GraphicsEnvironment.java index 167db051910e3f311b77178db170ce42252cdbed..cf1852e2fc0c9a3c8a935332e3dbc82c35ca6f60 100644 --- a/src/share/classes/java/awt/GraphicsEnvironment.java +++ b/src/share/classes/java/awt/GraphicsEnvironment.java @@ -356,6 +356,9 @@ public abstract class GraphicsEnvironment { * @since 1.5 */ public void preferLocaleFonts() { + if (!(this instanceof SunGraphicsEnvironment)) { + return; + } sun.font.FontManager.preferLocaleFonts(); } @@ -376,6 +379,9 @@ public abstract class GraphicsEnvironment { * @since 1.5 */ public void preferProportionalFonts() { + if (!(this instanceof SunGraphicsEnvironment)) { + return; + } sun.font.FontManager.preferProportionalFonts(); } diff --git a/src/share/classes/java/awt/color/ICC_Profile.java b/src/share/classes/java/awt/color/ICC_Profile.java index 3ef8d437bb4656bb852d6207e1b1e2820a6483fe..705d2560e1fe983d29097290e8dd21caedf171ea 100644 --- a/src/share/classes/java/awt/color/ICC_Profile.java +++ b/src/share/classes/java/awt/color/ICC_Profile.java @@ -737,7 +737,7 @@ public class ICC_Profile implements Serializable { ICC_Profile(ProfileDeferralInfo pdi) { this.deferralInfo = pdi; this.profileActivator = new ProfileActivator() { - public void activate() { + public void activate() throws ProfileDataException { activateDeferredProfile(); } }; @@ -830,20 +830,16 @@ public class ICC_Profile implements Serializable { case ColorSpace.CS_sRGB: synchronized(ICC_Profile.class) { if (sRGBprofile == null) { - try { - /* - * Deferral is only used for standard profiles. - * Enabling the appropriate access privileges is handled - * at a lower level. - */ - sRGBprofile = getDeferredInstance( - new ProfileDeferralInfo("sRGB.pf", - ColorSpace.TYPE_RGB, - 3, CLASS_DISPLAY)); - } catch (IOException e) { - throw new IllegalArgumentException( - "Can't load standard profile: sRGB.pf"); - } + /* + * Deferral is only used for standard profiles. + * Enabling the appropriate access privileges is handled + * at a lower level. + */ + ProfileDeferralInfo pInfo = + new ProfileDeferralInfo("sRGB.pf", + ColorSpace.TYPE_RGB, 3, + CLASS_DISPLAY); + sRGBprofile = getDeferredInstance(pInfo); } thisProfile = sRGBprofile; } @@ -853,7 +849,11 @@ public class ICC_Profile implements Serializable { case ColorSpace.CS_CIEXYZ: synchronized(ICC_Profile.class) { if (XYZprofile == null) { - XYZprofile = getStandardProfile("CIEXYZ.pf"); + ProfileDeferralInfo pInfo = + new ProfileDeferralInfo("CIEXYZ.pf", + ColorSpace.TYPE_XYZ, 3, + CLASS_DISPLAY); + XYZprofile = getDeferredInstance(pInfo); } thisProfile = XYZprofile; } @@ -863,7 +863,11 @@ public class ICC_Profile implements Serializable { case ColorSpace.CS_PYCC: synchronized(ICC_Profile.class) { if (PYCCprofile == null) { - PYCCprofile = getStandardProfile("PYCC.pf"); + ProfileDeferralInfo pInfo = + new ProfileDeferralInfo("PYCC.pf", + ColorSpace.TYPE_3CLR, 3, + CLASS_DISPLAY); + PYCCprofile = getDeferredInstance(pInfo); } thisProfile = PYCCprofile; } @@ -873,7 +877,11 @@ public class ICC_Profile implements Serializable { case ColorSpace.CS_GRAY: synchronized(ICC_Profile.class) { if (GRAYprofile == null) { - GRAYprofile = getStandardProfile("GRAY.pf"); + ProfileDeferralInfo pInfo = + new ProfileDeferralInfo("GRAY.pf", + ColorSpace.TYPE_GRAY, 1, + CLASS_DISPLAY); + GRAYprofile = getDeferredInstance(pInfo); } thisProfile = GRAYprofile; } @@ -883,7 +891,11 @@ public class ICC_Profile implements Serializable { case ColorSpace.CS_LINEAR_RGB: synchronized(ICC_Profile.class) { if (LINEAR_RGBprofile == null) { - LINEAR_RGBprofile = getStandardProfile("LINEAR_RGB.pf"); + ProfileDeferralInfo pInfo = + new ProfileDeferralInfo("LINEAR_RGB.pf", + ColorSpace.TYPE_RGB, 3, + CLASS_DISPLAY); + LINEAR_RGBprofile = getDeferredInstance(pInfo); } thisProfile = LINEAR_RGBprofile; } @@ -1047,9 +1059,7 @@ public class ICC_Profile implements Serializable { * code will take care of access privileges. * @see activateDeferredProfile() */ - static ICC_Profile getDeferredInstance(ProfileDeferralInfo pdi) - throws IOException { - + static ICC_Profile getDeferredInstance(ProfileDeferralInfo pdi) { if (!ProfileDeferralMgr.deferring) { return getStandardProfile(pdi.filename); } @@ -1063,33 +1073,37 @@ public class ICC_Profile implements Serializable { } - void activateDeferredProfile() { - byte profileData[]; - FileInputStream fis; - String fileName = deferralInfo.filename; + void activateDeferredProfile() throws ProfileDataException { + byte profileData[]; + FileInputStream fis; + String fileName = deferralInfo.filename; profileActivator = null; deferralInfo = null; if ((fis = openProfile(fileName)) == null) { - throw new IllegalArgumentException("Cannot open file " + fileName); + throw new ProfileDataException("Cannot open file " + fileName); } try { profileData = getProfileDataFromStream(fis); fis.close(); /* close the file */ } catch (IOException e) { - throw new IllegalArgumentException("Invalid ICC Profile Data" + - fileName); + ProfileDataException pde = new + ProfileDataException("Invalid ICC Profile Data" + fileName); + pde.initCause(e); + throw pde; } if (profileData == null) { - throw new IllegalArgumentException("Invalid ICC Profile Data" + + throw new ProfileDataException("Invalid ICC Profile Data" + fileName); } try { ID = CMSManager.getModule().loadProfile(profileData); } catch (CMMException c) { - throw new IllegalArgumentException("Invalid ICC Profile Data" + - fileName); + ProfileDataException pde = new + ProfileDataException("Invalid ICC Profile Data" + fileName); + pde.initCause(c); + throw pde; } } diff --git a/src/share/classes/java/beans/Beans.java b/src/share/classes/java/beans/Beans.java index f19b21aead21254efb06530874580db97d4a613e..8a750a8b15ca17fd02e4f5ee8c63cdd5693bc49b 100644 --- a/src/share/classes/java/beans/Beans.java +++ b/src/share/classes/java/beans/Beans.java @@ -1,5 +1,5 @@ /* - * Copyright 1996-2006 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. * * This code is free software; you can redistribute it and/or modify it @@ -27,26 +27,41 @@ package java.beans; import com.sun.beans.finder.ClassFinder; -import java.applet.*; +import java.applet.Applet; +import java.applet.AppletContext; +import java.applet.AppletStub; +import java.applet.AudioClip; -import java.awt.*; - -import java.beans.AppletInitializer; +import java.awt.GraphicsEnvironment; +import java.awt.Image; import java.beans.beancontext.BeanContext; -import java.io.*; - -import java.lang.reflect.Constructor; +import java.io.IOException; +import java.io.InputStream; +import java.io.ObjectInputStream; +import java.io.ObjectStreamClass; +import java.io.StreamCorruptedException; import java.net.URL; -import java.lang.reflect.Array; + +import java.security.AccessController; +import java.security.PrivilegedAction; + +import java.util.Enumeration; +import java.util.Hashtable; +import java.util.Iterator; +import java.util.Vector; + +import sun.awt.AppContext; /** * This class provides some general purpose beans control methods. */ public class Beans { + private static final Object DESIGN_TIME = new Object(); + private static final Object GUI_AVAILABLE = new Object(); /** * <p> @@ -59,12 +74,12 @@ public class Beans { * @param beanName the name of the bean within the class-loader. * For example "sun.beanbox.foobah" * - * @exception java.lang.ClassNotFoundException if the class of a serialized + * @exception ClassNotFoundException if the class of a serialized * object could not be found. - * @exception java.io.IOException if an I/O error occurs. + * @exception IOException if an I/O error occurs. */ - public static Object instantiate(ClassLoader cls, String beanName) throws java.io.IOException, ClassNotFoundException { + public static Object instantiate(ClassLoader cls, String beanName) throws IOException, ClassNotFoundException { return Beans.instantiate(cls, beanName, null, null); } @@ -80,12 +95,12 @@ public class Beans { * For example "sun.beanbox.foobah" * @param beanContext The BeanContext in which to nest the new bean * - * @exception java.lang.ClassNotFoundException if the class of a serialized + * @exception ClassNotFoundException if the class of a serialized * object could not be found. - * @exception java.io.IOException if an I/O error occurs. + * @exception IOException if an I/O error occurs. */ - public static Object instantiate(ClassLoader cls, String beanName, BeanContext beanContext) throws java.io.IOException, ClassNotFoundException { + public static Object instantiate(ClassLoader cls, String beanName, BeanContext beanContext) throws IOException, ClassNotFoundException { return Beans.instantiate(cls, beanName, beanContext, null); } @@ -135,19 +150,19 @@ public class Beans { * @param beanContext The BeanContext in which to nest the new bean * @param initializer The AppletInitializer for the new bean * - * @exception java.lang.ClassNotFoundException if the class of a serialized + * @exception ClassNotFoundException if the class of a serialized * object could not be found. - * @exception java.io.IOException if an I/O error occurs. + * @exception IOException if an I/O error occurs. */ public static Object instantiate(ClassLoader cls, String beanName, BeanContext beanContext, AppletInitializer initializer) - throws java.io.IOException, ClassNotFoundException { + throws IOException, ClassNotFoundException { - java.io.InputStream ins; - java.io.ObjectInputStream oins = null; + InputStream ins; + ObjectInputStream oins = null; Object result = null; boolean serialized = false; - java.io.IOException serex = null; + IOException serex = null; // If the given classloader is null, we check if an // system classloader is available and (if so) @@ -166,8 +181,8 @@ public class Beans { // Try to find a serialized object with this name final String serName = beanName.replace('.','/').concat(".ser"); final ClassLoader loader = cls; - ins = (InputStream)java.security.AccessController.doPrivileged - (new java.security.PrivilegedAction() { + ins = (InputStream)AccessController.doPrivileged + (new PrivilegedAction() { public Object run() { if (loader == null) return ClassLoader.getSystemResourceAsStream(serName); @@ -185,7 +200,7 @@ public class Beans { result = oins.readObject(); serialized = true; oins.close(); - } catch (java.io.IOException ex) { + } catch (IOException ex) { ins.close(); // Drop through and try opening the class. But remember // the exception in case we can't find the class either. @@ -264,8 +279,8 @@ public class Beans { final ClassLoader cloader = cls; objectUrl = (URL) - java.security.AccessController.doPrivileged - (new java.security.PrivilegedAction() { + AccessController.doPrivileged + (new PrivilegedAction() { public Object run() { if (cloader == null) return ClassLoader.getSystemResource @@ -377,10 +392,11 @@ public class Beans { * @return True if we are running in an application construction * environment. * - * @see java.beans.DesignMode + * @see DesignMode */ public static boolean isDesignTime() { - return designTime; + Object value = AppContext.getAppContext().get(DESIGN_TIME); + return (value instanceof Boolean) && (Boolean) value; } /** @@ -393,11 +409,12 @@ public class Beans { * false in a server environment or if an application is * running as part of a batch job. * - * @see java.beans.Visibility + * @see Visibility * */ public static boolean isGuiAvailable() { - return guiAvailable; + Object value = AppContext.getAppContext().get(GUI_AVAILABLE); + return (value instanceof Boolean) ? (Boolean) value : !GraphicsEnvironment.isHeadless(); } /** @@ -423,7 +440,7 @@ public class Beans { if (sm != null) { sm.checkPropertiesAccess(); } - designTime = isDesignTime; + AppContext.getAppContext().put(DESIGN_TIME, Boolean.valueOf(isDesignTime)); } /** @@ -449,14 +466,7 @@ public class Beans { if (sm != null) { sm.checkPropertiesAccess(); } - guiAvailable = isGuiAvailable; - } - - - private static boolean designTime; - private static boolean guiAvailable; - static { - guiAvailable = !GraphicsEnvironment.isHeadless(); + AppContext.getAppContext().put(GUI_AVAILABLE, Boolean.valueOf(isGuiAvailable)); } } @@ -501,7 +511,7 @@ class ObjectInputStreamWithLoader extends ObjectInputStream class BeansAppletContext implements AppletContext { Applet target; - java.util.Hashtable imageCache = new java.util.Hashtable(); + Hashtable imageCache = new Hashtable(); BeansAppletContext(Applet target) { this.target = target; @@ -546,8 +556,8 @@ class BeansAppletContext implements AppletContext { return null; } - public java.util.Enumeration getApplets() { - java.util.Vector applets = new java.util.Vector(); + public Enumeration getApplets() { + Vector applets = new Vector(); applets.addElement(target); return applets.elements(); } @@ -573,7 +583,7 @@ class BeansAppletContext implements AppletContext { return null; } - public java.util.Iterator getStreamKeys(){ + public Iterator getStreamKeys(){ // We do nothing. return null; } diff --git a/src/share/classes/java/beans/IndexedPropertyChangeEvent.java b/src/share/classes/java/beans/IndexedPropertyChangeEvent.java index ea78643e435070b739167b9b691eff94d4bee491..951cd871fe515c7c6ada00651b423856a995d21c 100644 --- a/src/share/classes/java/beans/IndexedPropertyChangeEvent.java +++ b/src/share/classes/java/beans/IndexedPropertyChangeEvent.java @@ -1,5 +1,5 @@ /* - * Copyright 2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2003-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 @@ -41,6 +41,7 @@ package java.beans; * @author Mark Davidson */ public class IndexedPropertyChangeEvent extends PropertyChangeEvent { + private static final long serialVersionUID = -320227448495806870L; private int index; diff --git a/src/share/classes/java/beans/IntrospectionException.java b/src/share/classes/java/beans/IntrospectionException.java index cac0b20fc0104b989b192db73c2b75fd39059978..2f5a65eda73656f7a744557b5ff410c64383999d 100644 --- a/src/share/classes/java/beans/IntrospectionException.java +++ b/src/share/classes/java/beans/IntrospectionException.java @@ -1,5 +1,5 @@ /* - * Copyright 1996-1998 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. * * This code is free software; you can redistribute it and/or modify it @@ -36,6 +36,7 @@ package java.beans; public class IntrospectionException extends Exception { + private static final long serialVersionUID = -3728150539969542619L; /** * Constructs an <code>IntrospectionException</code> with a diff --git a/src/share/classes/java/beans/PropertyChangeEvent.java b/src/share/classes/java/beans/PropertyChangeEvent.java index 69f523d92e317640fdf1ffe1f7869daeb30d71f7..3e0c9cef6f979c0ce75f4b11d249573f669bdf47 100644 --- a/src/share/classes/java/beans/PropertyChangeEvent.java +++ b/src/share/classes/java/beans/PropertyChangeEvent.java @@ -1,5 +1,5 @@ /* - * Copyright 1996-2006 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. * * This code is free software; you can redistribute it and/or modify it @@ -44,6 +44,7 @@ package java.beans; */ public class PropertyChangeEvent extends java.util.EventObject { + private static final long serialVersionUID = 7042693688939648123L; /** * Constructs a new <code>PropertyChangeEvent</code>. diff --git a/src/share/classes/java/beans/PropertyVetoException.java b/src/share/classes/java/beans/PropertyVetoException.java index f736b3bade56bd04570c0512bcb44fef73a5e191..73376496b53c32c490f69bc16923952b9b32807c 100644 --- a/src/share/classes/java/beans/PropertyVetoException.java +++ b/src/share/classes/java/beans/PropertyVetoException.java @@ -1,5 +1,5 @@ /* - * Copyright 1996-1998 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. * * This code is free software; you can redistribute it and/or modify it @@ -33,7 +33,7 @@ package java.beans; public class PropertyVetoException extends Exception { - + private static final long serialVersionUID = 129596057694162164L; /** * Constructs a <code>PropertyVetoException</code> with a diff --git a/src/share/classes/java/beans/beancontext/BeanContextEvent.java b/src/share/classes/java/beans/beancontext/BeanContextEvent.java index 4574605a15478047f740f3de3ad2385fa5d5edb9..2530869534becdcc9551ca28320cc769146876f5 100644 --- a/src/share/classes/java/beans/beancontext/BeanContextEvent.java +++ b/src/share/classes/java/beans/beancontext/BeanContextEvent.java @@ -1,5 +1,5 @@ /* - * Copyright 1997-2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 1997-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 @@ -48,6 +48,7 @@ import java.beans.beancontext.BeanContext; */ public abstract class BeanContextEvent extends EventObject { + private static final long serialVersionUID = 7267998073569045052L; /** * Contruct a BeanContextEvent diff --git a/src/share/classes/java/beans/beancontext/BeanContextMembershipEvent.java b/src/share/classes/java/beans/beancontext/BeanContextMembershipEvent.java index 7e6c1ae0a69323fed8b9e22db6398200b6119257..3752e390341cf606f0b463298f56a7208b1b1d81 100644 --- a/src/share/classes/java/beans/beancontext/BeanContextMembershipEvent.java +++ b/src/share/classes/java/beans/beancontext/BeanContextMembershipEvent.java @@ -1,5 +1,5 @@ /* - * Copyright 1997-2004 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 1997-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 @@ -55,6 +55,7 @@ import java.util.Iterator; * @see java.beans.beancontext.BeanContextMembershipListener */ public class BeanContextMembershipEvent extends BeanContextEvent { + private static final long serialVersionUID = 3499346510334590959L; /** * Contruct a BeanContextMembershipEvent diff --git a/src/share/classes/java/beans/beancontext/BeanContextServiceAvailableEvent.java b/src/share/classes/java/beans/beancontext/BeanContextServiceAvailableEvent.java index 558c7f9f3637a0301d6348f7f96350fa28fc2e42..7bb47a660330a03041d9747f406a571e0c605ff0 100644 --- a/src/share/classes/java/beans/beancontext/BeanContextServiceAvailableEvent.java +++ b/src/share/classes/java/beans/beancontext/BeanContextServiceAvailableEvent.java @@ -1,5 +1,5 @@ /* - * Copyright 1998-2004 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 1998-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 @@ -40,6 +40,7 @@ import java.util.Iterator; */ public class BeanContextServiceAvailableEvent extends BeanContextEvent { + private static final long serialVersionUID = -5333985775656400778L; /** * Construct a <code>BeanContextAvailableServiceEvent</code>. diff --git a/src/share/classes/java/beans/beancontext/BeanContextServiceRevokedEvent.java b/src/share/classes/java/beans/beancontext/BeanContextServiceRevokedEvent.java index a508f4ca1578c88ee76ac24016665e34c2713c9b..50d888cdf7ea7534d22e419d47947dab4f52b796 100644 --- a/src/share/classes/java/beans/beancontext/BeanContextServiceRevokedEvent.java +++ b/src/share/classes/java/beans/beancontext/BeanContextServiceRevokedEvent.java @@ -1,5 +1,5 @@ /* - * Copyright 1998-2004 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 1998-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 @@ -37,6 +37,7 @@ import java.beans.beancontext.BeanContextServices; * </p> */ public class BeanContextServiceRevokedEvent extends BeanContextEvent { + private static final long serialVersionUID = -1295543154724961754L; /** * Construct a <code>BeanContextServiceEvent</code>. diff --git a/src/share/classes/java/beans/beancontext/BeanContextServicesSupport.java b/src/share/classes/java/beans/beancontext/BeanContextServicesSupport.java index d9552c8a34e45f6d41626e7fcfa8a78dbef2113a..54dfdd7d227e0c93fdb616e538ae1e8415c14b95 100644 --- a/src/share/classes/java/beans/beancontext/BeanContextServicesSupport.java +++ b/src/share/classes/java/beans/beancontext/BeanContextServicesSupport.java @@ -1,5 +1,5 @@ /* - * Copyright 1998-2006 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 1998-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 @@ -60,6 +60,7 @@ import java.util.Locale; public class BeanContextServicesSupport extends BeanContextSupport implements BeanContextServices { + private static final long serialVersionUID = -8494482757288719206L; /** * <p> @@ -594,6 +595,7 @@ public class BeanContextServicesSupport extends BeanContextSupport */ protected static class BCSSServiceProvider implements Serializable { + private static final long serialVersionUID = 861278251667444782L; BCSSServiceProvider(Class sc, BeanContextServiceProvider bcsp) { super(); diff --git a/src/share/classes/java/io/Console.java b/src/share/classes/java/io/Console.java index 9e009943a9507ff512a80d5119e6bae7204d8bc5..201b66f71b5bb7426110c290a3aca12b9d606af2 100644 --- a/src/share/classes/java/io/Console.java +++ b/src/share/classes/java/io/Console.java @@ -503,6 +503,21 @@ public final class Console implements Flushable // Set up JavaIOAccess in SharedSecrets static { + + // Add a shutdown hook to restore console's echo state should + // it be necessary. + sun.misc.SharedSecrets.getJavaLangAccess() + .registerShutdownHook(0 /* shutdown hook invocation order */, + new Runnable() { + public void run() { + try { + if (echoOff) { + echo(true); + } + } catch (IOException x) { } + } + }); + sun.misc.SharedSecrets.setJavaIOAccess(new sun.misc.JavaIOAccess() { public Console console() { if (istty()) { @@ -513,20 +528,6 @@ public final class Console implements Flushable return null; } - // Add a shutdown hook to restore console's echo state should - // it be necessary. - public Runnable consoleRestoreHook() { - return new Runnable() { - public void run() { - try { - if (echoOff) { - echo(true); - } - } catch (IOException x) {} - } - }; - } - public Charset charset() { // This method is called in sun.security.util.Password, // cons already exists when this method is called diff --git a/src/share/classes/java/io/DeleteOnExitHook.java b/src/share/classes/java/io/DeleteOnExitHook.java index bf4d9e7f20f13febd55a1027eff4df4f2e7905b6..1dc5c9d85bce11f62c93dd3c606a443529f117aa 100644 --- a/src/share/classes/java/io/DeleteOnExitHook.java +++ b/src/share/classes/java/io/DeleteOnExitHook.java @@ -34,17 +34,18 @@ import java.io.File; */ class DeleteOnExitHook { - private static DeleteOnExitHook instance = null; + static { + sun.misc.SharedSecrets.getJavaLangAccess() + .registerShutdownHook(2 /* Shutdown hook invocation order */, + new Runnable() { + public void run() { + runHooks(); + } + }); + } private static LinkedHashSet<String> files = new LinkedHashSet<String>(); - static DeleteOnExitHook hook() { - if (instance == null) - instance = new DeleteOnExitHook(); - - return instance; - } - private DeleteOnExitHook() {} static synchronized void add(String file) { @@ -54,7 +55,7 @@ class DeleteOnExitHook { files.add(file); } - void run() { + static void runHooks() { LinkedHashSet<String> theFiles; synchronized (DeleteOnExitHook.class) { diff --git a/src/share/classes/java/io/File.java b/src/share/classes/java/io/File.java index d573b89f48317f8386625f01d23b05c8c056ff95..6e58efbbd6b5349c84d3f93aa98e41e77bcf33d8 100644 --- a/src/share/classes/java/io/File.java +++ b/src/share/classes/java/io/File.java @@ -1,5 +1,5 @@ /* - * Copyright 1994-2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 1994-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 @@ -30,12 +30,12 @@ import java.net.URI; import java.net.URL; import java.net.MalformedURLException; import java.net.URISyntaxException; -import java.util.ArrayList; -import java.util.Map; -import java.util.Hashtable; -import java.util.Random; +import java.util.*; +import java.nio.file.*; +import java.nio.file.attribute.*; import java.security.AccessController; -import java.security.AccessControlException; +import java.security.PrivilegedAction; +import java.security.SecureRandom; import sun.security.action.GetPropertyAction; @@ -131,6 +131,18 @@ import sun.security.action.GetPropertyAction; * created, the abstract pathname represented by a <code>File</code> object * will never change. * + * <h4>Interoperability with {@code java.nio.file} package</h4> + * + * <p> The <a href="../../java/nio/file/package-summary.html">{@code java.nio.file}</a> + * package defines interfaces and classes for the Java virtual machine to access + * files, file attributes, and file systems. This API may be used to overcome + * many of the limitations of the {@code java.io.File} class. + * The {@link #toPath toPath} method may be used to obtain a {@link + * Path} that uses the abstract path represented by a {@code File} object to + * locate a file. The resulting {@code Path} provides more efficient and + * extensive access to file attributes, additional file operations, and I/O + * exceptions to help diagnose errors when an operation on a file fails. + * * @author unascribed * @since JDK1.0 */ @@ -573,6 +585,7 @@ public class File * read access to the file * * @since JDK1.1 + * @see Path#toRealPath */ public String getCanonicalPath() throws IOException { return fs.canonicalize(fs.resolve(this)); @@ -597,6 +610,7 @@ public class File * read access to the file * * @since 1.2 + * @see Path#toRealPath */ public File getCanonicalFile() throws IOException { String canonPath = getCanonicalPath(); @@ -663,6 +677,14 @@ public class File * system is converted into an abstract pathname in a virtual machine on a * different operating system. * + * <p> Note that when this abstract pathname represents a UNC pathname then + * all components of the UNC (including the server name component) are encoded + * in the {@code URI} path. The authority component is undefined, meaning + * that it is represented as {@code null}. The {@link Path} class defines the + * {@link Path#toUri toUri} method to encode the server name in the authority + * component of the resulting {@code URI}. The {@link #toPath toPath} method + * may be used to obtain a {@code Path} representing this abstract pathname. + * * @return An absolute, hierarchical URI with a scheme equal to * <tt>"file"</tt>, a path representing this abstract pathname, * and undefined authority, query, and fragment components @@ -764,6 +786,8 @@ public class File * If a security manager exists and its <code>{@link * java.lang.SecurityManager#checkRead(java.lang.String)}</code> * method denies read access to the file + * + * @see Attributes#readBasicFileAttributes */ public boolean isDirectory() { SecurityManager security = System.getSecurityManager(); @@ -788,6 +812,8 @@ public class File * If a security manager exists and its <code>{@link * java.lang.SecurityManager#checkRead(java.lang.String)}</code> * method denies read access to the file + * + * @see Attributes#readBasicFileAttributes */ public boolean isFile() { SecurityManager security = System.getSecurityManager(); @@ -836,6 +862,8 @@ public class File * If a security manager exists and its <code>{@link * java.lang.SecurityManager#checkRead(java.lang.String)}</code> * method denies read access to the file + * + * @see Attributes#readBasicFileAttributes */ public long lastModified() { SecurityManager security = System.getSecurityManager(); @@ -858,6 +886,8 @@ public class File * If a security manager exists and its <code>{@link * java.lang.SecurityManager#checkRead(java.lang.String)}</code> * method denies read access to the file + * + * @see Attributes#readBasicFileAttributes */ public long length() { SecurityManager security = System.getSecurityManager(); @@ -907,6 +937,12 @@ public class File * this pathname denotes a directory, then the directory must be empty in * order to be deleted. * + * <p> Note that the {@link Path} class defines the {@link Path#delete + * delete} method to throw an {@link IOException} when a file cannot be + * deleted. This is useful for error reporting and to diagnose why a file + * cannot be deleted. The {@link #toPath toPath} method may be used to + * obtain a {@code Path} representing this abstract pathname. + * * @return <code>true</code> if and only if the file or directory is * successfully deleted; <code>false</code> otherwise * @@ -973,6 +1009,13 @@ public class File * will appear in any specific order; they are not, in particular, * guaranteed to appear in alphabetical order. * + * <p> Note that the {@link Path} class defines the {@link + * Path#newDirectoryStream newDirectoryStream} method to open a directory + * and iterate over the names of the files in the directory. This may use + * less resources when working with very large directories. The {@link + * #toPath toPath} method may be used to obtain a {@code Path} representing + * this abstract pathname. + * * @return An array of strings naming the files and directories in the * directory denoted by this abstract pathname. The array will be * empty if the directory is empty. Returns {@code null} if @@ -1024,13 +1067,13 @@ public class File if ((names == null) || (filter == null)) { return names; } - ArrayList v = new ArrayList(); + List<String> v = new ArrayList<String>(); for (int i = 0 ; i < names.length ; i++) { if (filter.accept(this, names[i])) { v.add(names[i]); } } - return (String[])(v.toArray(new String[v.size()])); + return v.toArray(new String[v.size()]); } /** @@ -1052,6 +1095,13 @@ public class File * will appear in any specific order; they are not, in particular, * guaranteed to appear in alphabetical order. * + * <p> Note that the {@link Path} class defines the {@link + * Path#newDirectoryStream newDirectoryStream} method to open a directory + * and iterate over the names of the files in the directory. This may use + * less resources when working with very large directories. The {@link + * #toPath toPath} method may be used to obtain a {@code Path} representing + * this abstract pathname. + * * @return An array of abstract pathnames denoting the files and * directories in the directory denoted by this abstract pathname. * The array will be empty if the directory is empty. Returns @@ -1157,6 +1207,12 @@ public class File /** * Creates the directory named by this abstract pathname. * + * <p> Note that the {@link Path} class defines the {@link Path#createDirectory + * createDirectory} method to throw an {@link IOException} when a directory + * cannot be created. This is useful for error reporting and to diagnose why + * a directory cannot be created. The {@link #toPath toPath} method may be + * used to obtain a {@code Path} representing this abstract pathname. + * * @return <code>true</code> if and only if the directory was * created; <code>false</code> otherwise * @@ -1222,6 +1278,11 @@ public class File * already exists. The return value should always be checked to make sure * that the rename operation was successful. * + * <p> Note that the {@link Path} class defines the {@link Path#moveTo + * moveTo} method to move or rename a file in a platform independent manner. + * The {@link #toPath toPath} method may be used to obtain a {@code Path} + * representing this abstract pathname. + * * @param dest The new abstract pathname for the named file * * @return <code>true</code> if and only if the renaming succeeded; @@ -1304,10 +1365,14 @@ public class File return fs.setReadOnly(this); } - /** + /** * Sets the owner's or everybody's write permission for this abstract * pathname. * + * <p> The {@link Attributes Attributes} class defines methods that operate + * on file attributes including file permissions. This may be used when + * finer manipulation of file permissions is required. + * * @param writable * If <code>true</code>, sets the access permission to allow write * operations; if <code>false</code> to disallow write operations @@ -1371,6 +1436,10 @@ public class File * Sets the owner's or everybody's read permission for this abstract * pathname. * + * <p> The {@link Attributes Attributes} class defines methods that operate + * on file attributes including file permissions. This may be used when + * finer manipulation of file permissions is required. + * * @param readable * If <code>true</code>, sets the access permission to allow read * operations; if <code>false</code> to disallow read operations @@ -1440,6 +1509,10 @@ public class File * Sets the owner's or everybody's execute permission for this abstract * pathname. * + * <p> The {@link Attributes Attributes} class defines methods that operate + * on file attributes including file permissions. This may be used when + * finer manipulation of file permissions is required. + * * @param executable * If <code>true</code>, sets the access permission to allow execute * operations; if <code>false</code> to disallow execute operations @@ -1678,44 +1751,44 @@ public class File /* -- Temporary files -- */ - private static final Object tmpFileLock = new Object(); + private static class TemporaryDirectory { + private TemporaryDirectory() { } - private static int counter = -1; /* Protected by tmpFileLock */ + static final String valueAsString = fs.normalize( + AccessController.doPrivileged(new GetPropertyAction("java.io.tmpdir"))); + static final File valueAsFile = + new File(valueAsString, fs.prefixLength(valueAsString)); - private static File generateFile(String prefix, String suffix, File dir) - throws IOException - { - if (counter == -1) { - counter = new Random().nextInt() & 0xffff; + // file name generation + private static final SecureRandom random = new SecureRandom(); + static File generateFile(String prefix, String suffix, File dir) { + long n = random.nextLong(); + if (n == Long.MIN_VALUE) { + n = 0; // corner case + } else { + n = Math.abs(n); + } + return new File(dir, prefix + Long.toString(n) + suffix); } - counter++; - return new File(dir, prefix + Integer.toString(counter) + suffix); - } - private static String tmpdir; /* Protected by tmpFileLock */ - - private static String getTempDir() { - if (tmpdir == null) - tmpdir = fs.normalize( - AccessController.doPrivileged( - new GetPropertyAction("java.io.tmpdir"))); - return tmpdir; - } - - private static boolean checkAndCreate(String filename, SecurityManager sm) - throws IOException - { - if (sm != null) { - try { - sm.checkWrite(filename); - } catch (AccessControlException x) { - /* Throwing the original AccessControlException could disclose - the location of the default temporary directory, so we - re-throw a more innocuous SecurityException */ - throw new SecurityException("Unable to create temporary file"); - } + // default file permissions + static final FileAttribute<Set<PosixFilePermission>> defaultPosixFilePermissions = + PosixFilePermissions.asFileAttribute(EnumSet + .of(PosixFilePermission.OWNER_READ, PosixFilePermission.OWNER_WRITE)); + static final boolean isPosix = isPosix(); + static boolean isPosix() { + return AccessController.doPrivileged( + new PrivilegedAction<Boolean>() { + public Boolean run() { + try { + return FileSystems.getDefault().getPath(valueAsString) + .getFileStore().supportsFileAttributeView("posix"); + } catch (IOException e) { + throw new IOError(e); + } + } + }); } - return fs.createFileExclusively(filename); } /** @@ -1791,22 +1864,29 @@ public class File File directory) throws IOException { - if (prefix == null) throw new NullPointerException(); if (prefix.length() < 3) throw new IllegalArgumentException("Prefix string too short"); - String s = (suffix == null) ? ".tmp" : suffix; - synchronized (tmpFileLock) { - if (directory == null) { - String tmpDir = getTempDir(); - directory = new File(tmpDir, fs.prefixLength(tmpDir)); + if (suffix == null) + suffix = ".tmp"; + + File tmpdir = (directory != null) ? + directory : TemporaryDirectory.valueAsFile; + SecurityManager sm = System.getSecurityManager(); + File f; + do { + f = TemporaryDirectory.generateFile(prefix, suffix, tmpdir); + if (sm != null) { + try { + sm.checkWrite(f.getPath()); + } catch (SecurityException se) { + // don't reveal temporary directory location + if (directory == null) + throw new SecurityException("Unable to create temporary file"); + throw se; + } } - SecurityManager sm = System.getSecurityManager(); - File f; - do { - f = generateFile(prefix, s, directory); - } while (!checkAndCreate(f.getPath(), sm)); - return f; - } + } while (!fs.createFileExclusively(f.getPath())); + return f; } /** @@ -1844,6 +1924,122 @@ public class File return createTempFile(prefix, suffix, null); } + /** + * Creates an empty file in the default temporary-file directory, using + * the given prefix and suffix to generate its name. This method is + * equivalent to invoking the {@link #createTempFile(String,String) + * createTempFile(prefix, suffix)} method with the addition that the + * resulting pathname may be requested to be deleted when the Java virtual + * machine terminates, and the initial file attributes to set atomically + * when creating the file may be specified. + * + * <p> When the value of the {@code deleteOnExit} method is {@code true} + * then the resulting file is requested to be deleted when the Java virtual + * machine terminates as if by invoking the {@link #deleteOnExit deleteOnExit} + * method. + * + * <p> The {@code attrs} parameter is an optional array of {@link FileAttribute + * attributes} to set atomically when creating the file. Each attribute is + * identified by its {@link FileAttribute#name name}. If more than one attribute + * of the same name is included in the array then all but the last occurrence + * is ignored. + * + * @param prefix + * The prefix string to be used in generating the file's + * name; must be at least three characters long + * @param suffix + * The suffix string to be used in generating the file's + * name; may be {@code null}, in which case the suffix + * {@code ".tmp"} will be used + * @param deleteOnExit + * {@code true} if the file denoted by resulting pathname be + * deleted when the Java virtual machine terminates + * @param attrs + * An optional list of file attributes to set atomically when creating + * the file + * + * @return An abstract pathname denoting a newly-created empty file + * + * @throws IllegalArgumentException + * If the <code>prefix</code> argument contains fewer than three + * characters + * @throws UnsupportedOperationException + * If the array contains an attribute that cannot be set atomically + * when creating the file + * @throws IOException + * If a file could not be created + * @throws SecurityException + * If a security manager exists and its <code>{@link + * java.lang.SecurityManager#checkWrite(java.lang.String)}</code> + * method does not allow a file to be created. When the {@code + * deleteOnExit} parameter has the value {@code true} then the + * security manager's {@link + * java.lang.SecurityManager#checkDelete(java.lang.String)} is + * invoked to check delete access to the file. + * @since 1.7 + */ + public static File createTempFile(String prefix, + String suffix, + boolean deleteOnExit, + FileAttribute<?>... attrs) + throws IOException + { + if (prefix.length() < 3) + throw new IllegalArgumentException("Prefix string too short"); + suffix = (suffix == null) ? ".tmp" : suffix; + + // special case POSIX environments so that 0600 is used as the file mode + if (TemporaryDirectory.isPosix) { + if (attrs.length == 0) { + // no attributes so use default permissions + attrs = new FileAttribute<?>[1]; + attrs[0] = TemporaryDirectory.defaultPosixFilePermissions; + } else { + // check if posix permissions given; if not use default + boolean hasPermissions = false; + for (int i=0; i<attrs.length; i++) { + if (attrs[i].name().equals("posix:permissions")) { + hasPermissions = true; + break; + } + } + if (!hasPermissions) { + FileAttribute<?>[] copy = new FileAttribute<?>[attrs.length+1]; + System.arraycopy(attrs, 0, copy, 0, attrs.length); + attrs = copy; + attrs[attrs.length-1] = + TemporaryDirectory.defaultPosixFilePermissions; + } + } + } + + // use Path#createFile to create file + SecurityManager sm = System.getSecurityManager(); + for (;;) { + File f = TemporaryDirectory + .generateFile(prefix, suffix, TemporaryDirectory.valueAsFile); + if (sm != null && deleteOnExit) + sm.checkDelete(f.getPath()); + try { + f.toPath().createFile(attrs); + if (deleteOnExit) + DeleteOnExitHook.add(f.getPath()); + return f; + } catch (InvalidPathException e) { + // don't reveal temporary directory location + if (sm != null) + throw new IllegalArgumentException("Invalid prefix or suffix"); + throw e; + } catch (SecurityException e) { + // don't reveal temporary directory location + if (sm != null) + throw new SecurityException("Unable to create temporary file"); + throw e; + } catch (FileAlreadyExistsException e) { + // ignore + } + } + } /* -- Basic infrastructure -- */ @@ -1951,17 +2147,46 @@ public class File /** use serialVersionUID from JDK 1.0.2 for interoperability */ private static final long serialVersionUID = 301077366599181567L; - // Set up JavaIODeleteOnExitAccess in SharedSecrets - // Added here as DeleteOnExitHook is package-private and SharedSecrets cannot easily access it. - static { - sun.misc.SharedSecrets.setJavaIODeleteOnExitAccess( - new sun.misc.JavaIODeleteOnExitAccess() { - public void run() { - DeleteOnExitHook.hook().run(); + // -- Integration with java.nio.file -- + + private volatile transient Path filePath; + + /** + * Returns a {@link Path java.nio.file.Path} object constructed from the + * this abstract path. The first invocation of this method works as if + * invoking it were equivalent to evaluating the expression: + * <blockquote><pre> + * {@link FileSystems#getDefault FileSystems.getDefault}().{@link FileSystem#getPath getPath}(this.{@link #getPath getPath}()); + * </pre></blockquote> + * Subsequent invocations of this method return the same {@code Path}. + * + * <p> If this abstract pathname is the empty abstract pathname then this + * method returns a {@code Path} that may be used to access to the current + * user directory. + * + * @return A {@code Path} constructed from this abstract path. The resulting + * {@code Path} is associated with the {@link FileSystems#getDefault + * default-filesystem}. + * + * @throws InvalidPathException + * If a {@code Path} object cannot be constructed from the abstract + * path (see {@link java.nio.file.FileSystem#getPath FileSystem.getPath}) + * + * @since 1.7 + */ + public Path toPath() { + if (filePath == null) { + synchronized (this) { + if (filePath == null) { + if (path.length() == 0) { + // assume default file system treats "." as current directory + filePath = Paths.get("."); + } else { + filePath = Paths.get(path); + } } } - ); + } + return filePath; } - - } diff --git a/src/share/classes/java/io/FilePermission.java b/src/share/classes/java/io/FilePermission.java index 9758e35de6027ac6eaba45b073dd16fdea68aee2..88c98fbddf3948868f03aebfcefd0b59c96cc4cb 100644 --- a/src/share/classes/java/io/FilePermission.java +++ b/src/share/classes/java/io/FilePermission.java @@ -1,5 +1,5 @@ /* - * Copyright 1997-2005 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 1997-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 @@ -29,7 +29,6 @@ import java.security.*; import java.util.Enumeration; import java.util.List; import java.util.ArrayList; -import java.util.StringTokenizer; import java.util.Vector; import java.util.Collections; import java.io.ObjectStreamField; @@ -58,7 +57,8 @@ import sun.security.util.SecurityConstants; * <P> * The actions to be granted are passed to the constructor in a string containing * a list of one or more comma-separated keywords. The possible keywords are - * "read", "write", "execute", and "delete". Their meaning is defined as follows: + * "read", "write", "execute", "delete", and "readlink". Their meaning is + * defined as follows: * <P> * <DL> * <DT> read <DD> read permission @@ -69,6 +69,11 @@ import sun.security.util.SecurityConstants; * <DT> delete * <DD> delete permission. Allows <code>File.delete</code> to * be called. Corresponds to <code>SecurityManager.checkDelete</code>. + * <DT> readlink + * <DD> read link permission. Allows the target of a + * <a href="../nio/file/package-summary.html#links">symbolic link</a> + * to be read by invoking the {@link java.nio.file.Path#readSymbolicLink + * readSymbolicLink } method. * </DL> * <P> * The actions string is converted to lowercase before processing. @@ -114,11 +119,15 @@ public final class FilePermission extends Permission implements Serializable { * Delete action. */ private final static int DELETE = 0x8; + /** + * Read link action. + */ + private final static int READLINK = 0x10; /** - * All actions (read,write,execute,delete) + * All actions (read,write,execute,delete,readlink) */ - private final static int ALL = READ|WRITE|EXECUTE|DELETE; + private final static int ALL = READ|WRITE|EXECUTE|DELETE|READLINK; /** * No actions. */ @@ -235,7 +244,7 @@ public final class FilePermission extends Permission implements Serializable { * <i>path</i> is the pathname of a file or directory, and <i>actions</i> * contains a comma-separated list of the desired actions granted on the * file or directory. Possible actions are - * "read", "write", "execute", and "delete". + * "read", "write", "execute", "delete", and "readlink". * * <p>A pathname that ends in "/*" (where "/" is * the file separator character, <code>File.separatorChar</code>) @@ -425,6 +434,8 @@ public final class FilePermission extends Permission implements Serializable { return EXECUTE; } else if (actions == SecurityConstants.FILE_DELETE_ACTION) { return DELETE; + } else if (actions == SecurityConstants.FILE_READLINK_ACTION) { + return READLINK; } char[] a = actions.toCharArray(); @@ -485,6 +496,18 @@ public final class FilePermission extends Permission implements Serializable { matchlen = 6; mask |= DELETE; + } else if (i >= 7 && (a[i-7] == 'r' || a[i-7] == 'R') && + (a[i-6] == 'e' || a[i-6] == 'E') && + (a[i-5] == 'a' || a[i-5] == 'A') && + (a[i-4] == 'd' || a[i-4] == 'D') && + (a[i-3] == 'l' || a[i-3] == 'L') && + (a[i-2] == 'i' || a[i-2] == 'I') && + (a[i-1] == 'n' || a[i-1] == 'N') && + (a[i] == 'k' || a[i] == 'K')) + { + matchlen = 8; + mask |= READLINK; + } else { // parse error throw new IllegalArgumentException( @@ -529,7 +552,7 @@ public final class FilePermission extends Permission implements Serializable { /** * Return the canonical string representation of the actions. * Always returns present actions in the following order: - * read, write, execute, delete. + * read, write, execute, delete, readlink. * * @return the canonical string representation of the actions. */ @@ -561,14 +584,20 @@ public final class FilePermission extends Permission implements Serializable { sb.append("delete"); } + if ((mask & READLINK) == READLINK) { + if (comma) sb.append(','); + else comma = true; + sb.append("readlink"); + } + return sb.toString(); } /** * Returns the "canonical string representation" of the actions. * That is, this method always returns present actions in the following order: - * read, write, execute, delete. For example, if this FilePermission object - * allows both write and read actions, a call to <code>getActions</code> + * read, write, execute, delete, readlink. For example, if this FilePermission + * object allows both write and read actions, a call to <code>getActions</code> * will return the string "read,write". * * @return the canonical string representation of the actions. @@ -678,7 +707,7 @@ final class FilePermissionCollection extends PermissionCollection implements Serializable { // Not serialized; see serialization section at end of class - private transient List perms; + private transient List<Permission> perms; /** * Create an empty FilePermissions object. @@ -686,7 +715,7 @@ implements Serializable { */ public FilePermissionCollection() { - perms = new ArrayList(); + perms = new ArrayList<Permission>(); } /** @@ -791,7 +820,7 @@ implements Serializable { // Don't call out.defaultWriteObject() // Write out Vector - Vector permissions = new Vector(perms.size()); + Vector<Permission> permissions = new Vector<Permission>(perms.size()); synchronized (this) { permissions.addAll(perms); } @@ -804,6 +833,7 @@ implements Serializable { /* * Reads in a Vector of FilePermissions and saves them in the perms field. */ + @SuppressWarnings("unchecked") private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { // Don't call defaultReadObject() @@ -812,8 +842,8 @@ implements Serializable { ObjectInputStream.GetField gfields = in.readFields(); // Get the one we want - Vector permissions = (Vector)gfields.get("permissions", null); - perms = new ArrayList(permissions.size()); + Vector<Permission> permissions = (Vector<Permission>)gfields.get("permissions", null); + perms = new ArrayList<Permission>(permissions.size()); perms.addAll(permissions); } } diff --git a/src/share/classes/java/lang/ApplicationShutdownHooks.java b/src/share/classes/java/lang/ApplicationShutdownHooks.java index 8eeb0fef8d0de4a066c56c56faa8a211426510e5..b3341de15a45ab374ff457cc98733ce2e160db17 100644 --- a/src/share/classes/java/lang/ApplicationShutdownHooks.java +++ b/src/share/classes/java/lang/ApplicationShutdownHooks.java @@ -34,19 +34,19 @@ import java.util.*; * @see java.lang.Runtime#removeShutdownHook */ -class ApplicationShutdownHooks implements Runnable { - private static ApplicationShutdownHooks instance = null; +class ApplicationShutdownHooks { + static { + Shutdown.add(1 /* shutdown hook invocation order */, + new Runnable() { + public void run() { + runHooks(); + } + }); + } /* The set of registered hooks */ private static IdentityHashMap<Thread, Thread> hooks = new IdentityHashMap<Thread, Thread>(); - static synchronized ApplicationShutdownHooks hook() { - if (instance == null) - instance = new ApplicationShutdownHooks(); - - return instance; - } - private ApplicationShutdownHooks() {} /* Add a new shutdown hook. Checks the shutdown state and the hook itself, @@ -82,7 +82,7 @@ class ApplicationShutdownHooks implements Runnable { * to run in. Hooks are run concurrently and this method waits for * them to finish. */ - public void run() { + static void runHooks() { Collection<Thread> threads; synchronized(ApplicationShutdownHooks.class) { threads = hooks.keySet(); diff --git a/src/share/classes/java/lang/Character.java b/src/share/classes/java/lang/Character.java index 33b936f9c01d47f02528b24ba7623ddc36b9d753..e33052ee170c6f951b49e9866a50618ac7089b2a 100644 --- a/src/share/classes/java/lang/Character.java +++ b/src/share/classes/java/lang/Character.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2006 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2002-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 @@ -920,9 +920,9 @@ class Character extends Object implements java.io.Serializable, Comparable<Chara */ public static final UnicodeBlock COMBINING_MARKS_FOR_SYMBOLS = new UnicodeBlock("COMBINING_MARKS_FOR_SYMBOLS", new String[] {"Combining Diacritical Marks for Symbols", - "CombiningDiacriticalMarksforSymbols", - "Combining Marks for Symbols", - "CombiningMarksforSymbols" }); + "CombiningDiacriticalMarksforSymbols", + "Combining Marks for Symbols", + "CombiningMarksforSymbols" }); /** * Constant for the "Letterlike Symbols" Unicode character block. @@ -1332,8 +1332,11 @@ class Character extends Object implements java.io.Serializable, Comparable<Chara * @since 1.5 */ public static final UnicodeBlock CYRILLIC_SUPPLEMENTARY = - new UnicodeBlock("CYRILLIC_SUPPLEMENTARY", new String[] {"Cyrillic Supplementary", - "CyrillicSupplementary"}); + new UnicodeBlock("CYRILLIC_SUPPLEMENTARY", + new String[] {"Cyrillic Supplementary", + "CyrillicSupplementary", + "Cyrillic Supplement", + "CyrillicSupplement"}); /** * Constant for the "Tagalog" Unicode character block. @@ -1641,157 +1644,579 @@ class Character extends Object implements java.io.Serializable, Comparable<Chara public static final UnicodeBlock LOW_SURROGATES = new UnicodeBlock("LOW_SURROGATES", new String[] {"Low Surrogates", "LowSurrogates"}); + /** + * Constant for the "Arabic Supplement" Unicode character block. + * @since 1.7 + */ + public static final UnicodeBlock ARABIC_SUPPLEMENT = + new UnicodeBlock("ARABIC_SUPPLEMENT", + new String[] { "Arabic Supplement", + "ArabicSupplement"}); + + /** + * Constant for the "NKo" Unicode character block. + * @since 1.7 + */ + public static final UnicodeBlock NKO = new UnicodeBlock("NKO"); + + /** + * Constant for the "Ethiopic Supplement" Unicode character block. + * @since 1.7 + */ + public static final UnicodeBlock ETHIOPIC_SUPPLEMENT = + new UnicodeBlock("ETHIOPIC_SUPPLEMENT", + new String[] { "Ethiopic Supplement", + "EthiopicSupplement"}); + + /** + * Constant for the "New Tai Lue" Unicode character block. + * @since 1.7 + */ + public static final UnicodeBlock NEW_TAI_LUE = + new UnicodeBlock("NEW_TAI_LUE", + new String[] { "New Tai Lue", + "NewTaiLue"}); + + /** + * Constant for the "Buginese" Unicode character block. + * @since 1.7 + */ + public static final UnicodeBlock BUGINESE = + new UnicodeBlock("BUGINESE"); + + /** + * Constant for the "Balinese" Unicode character block. + * @since 1.7 + */ + public static final UnicodeBlock BALINESE = + new UnicodeBlock("BALINESE"); + + /** + * Constant for the "Sundanese" Unicode character block. + * @since 1.7 + */ + public static final UnicodeBlock SUNDANESE = + new UnicodeBlock("SUNDANESE"); + + /** + * Constant for the "Lepcha" Unicode character block. + * @since 1.7 + */ + public static final UnicodeBlock LEPCHA = new UnicodeBlock("LEPCHA"); + + /** + * Constant for the "Ol Chiki" Unicode character block. + * @since 1.7 + */ + public static final UnicodeBlock OL_CHIKI = + new UnicodeBlock("OL_CHIKI", + new String[] { "Ol Chiki", + "OlChiki"}); + + /** + * Constant for the "Phonetic Extensions Supplement" Unicode character + * block. + * @since 1.7 + */ + public static final UnicodeBlock PHONETIC_EXTENSIONS_SUPPLEMENT = + new UnicodeBlock("PHONETIC_EXTENSIONS_SUPPLEMENT", + new String[] { "Phonetic Extensions Supplement", + "PhoneticExtensionsSupplement"}); + + /** + * Constant for the "Combining Diacritical Marks Supplement" Unicode + * character block. + * @since 1.7 + */ + public static final UnicodeBlock COMBINING_DIACRITICAL_MARKS_SUPPLEMENT = + new UnicodeBlock("COMBINING_DIACRITICAL_MARKS_SUPPLEMENT", + new String[] { "Combining Diacritical Marks Supplement", + "CombiningDiacriticalMarksSupplement"}); + + /** + * Constant for the "Glagolitic" Unicode character block. + * @since 1.7 + */ + public static final UnicodeBlock GLAGOLITIC = + new UnicodeBlock("GLAGOLITIC"); + + /** + * Constant for the "Latin Extended-C" Unicode character block. + * @since 1.7 + */ + public static final UnicodeBlock LATIN_EXTENDED_C = + new UnicodeBlock("LATIN_EXTENDED_C", + new String[] { "Latin Extended-C", + "LatinExtended-C"}); + + /** + * Constant for the "Coptic" Unicode character block. + * @since 1.7 + */ + public static final UnicodeBlock COPTIC = new UnicodeBlock("COPTIC"); + + /** + * Constant for the "Georgian Supplement" Unicode character block. + * @since 1.7 + */ + public static final UnicodeBlock GEORGIAN_SUPPLEMENT = + new UnicodeBlock("GEORGIAN_SUPPLEMENT", + new String[] { "Georgian Supplement", + "GeorgianSupplement"}); + + /** + * Constant for the "Tifinagh" Unicode character block. + * @since 1.7 + */ + public static final UnicodeBlock TIFINAGH = + new UnicodeBlock("TIFINAGH"); + + /** + * Constant for the "Ethiopic Extended" Unicode character block. + * @since 1.7 + */ + public static final UnicodeBlock ETHIOPIC_EXTENDED = + new UnicodeBlock("ETHIOPIC_EXTENDED", + new String[] { "Ethiopic Extended", + "EthiopicExtended"}); + + /** + * Constant for the "Cyrillic Extended-A" Unicode character block. + * @since 1.7 + */ + public static final UnicodeBlock CYRILLIC_EXTENDED_A = + new UnicodeBlock("CYRILLIC_EXTENDED_A", + new String[] { "Cyrillic Extended-A", + "CyrillicExtended-A"}); + + /** + * Constant for the "Supplemental Punctuation" Unicode character block. + * @since 1.7 + */ + public static final UnicodeBlock SUPPLEMENTAL_PUNCTUATION = + new UnicodeBlock("SUPPLEMENTAL_PUNCTUATION", + new String[] { "Supplemental Punctuation", + "SupplementalPunctuation"}); + + /** + * Constant for the "CJK Strokes" Unicode character block. + * @since 1.7 + */ + public static final UnicodeBlock CJK_STROKES = + new UnicodeBlock("CJK_STROKES", + new String[] { "CJK Strokes", + "CJKStrokes"}); + + /** + * Constant for the "Vai" Unicode character block. + * @since 1.7 + */ + public static final UnicodeBlock VAI = new UnicodeBlock("VAI"); + + /** + * Constant for the "Cyrillic Extended-B" Unicode character block. + * @since 1.7 + */ + public static final UnicodeBlock CYRILLIC_EXTENDED_B = + new UnicodeBlock("CYRILLIC_EXTENDED_B", + new String[] { "Cyrillic Extended-B", + "CyrillicExtended-B"}); + + /** + * Constant for the "Modifier Tone Letters" Unicode character block. + * @since 1.7 + */ + public static final UnicodeBlock MODIFIER_TONE_LETTERS = + new UnicodeBlock("MODIFIER_TONE_LETTERS", + new String[] { "Modifier Tone Letters", + "ModifierToneLetters"}); + + /** + * Constant for the "Latin Extended-D" Unicode character block. + * @since 1.7 + */ + public static final UnicodeBlock LATIN_EXTENDED_D = + new UnicodeBlock("LATIN_EXTENDED_D", + new String[] { "Latin Extended-D", + "LatinExtended-D"}); + + /** + * Constant for the "Syloti Nagri" Unicode character block. + * @since 1.7 + */ + public static final UnicodeBlock SYLOTI_NAGRI = + new UnicodeBlock("SYLOTI_NAGRI", + new String[] { "Syloti Nagri", + "SylotiNagri"}); + + /** + * Constant for the "Phags-pa" Unicode character block. + * @since 1.7 + */ + public static final UnicodeBlock PHAGS_PA = + new UnicodeBlock("PHAGS_PA", new String[] { "Phags-pa"}); + + /** + * Constant for the "Saurashtra" Unicode character block. + * @since 1.7 + */ + public static final UnicodeBlock SAURASHTRA = + new UnicodeBlock("SAURASHTRA"); + + /** + * Constant for the "Kayah Li" Unicode character block. + * @since 1.7 + */ + public static final UnicodeBlock KAYAH_LI = + new UnicodeBlock("KAYAH_LI", + new String[] { "Kayah Li", + "KayahLi"}); + + /** + * Constant for the "Rejang" Unicode character block. + * @since 1.7 + */ + public static final UnicodeBlock REJANG = new UnicodeBlock("REJANG"); + + /** + * Constant for the "Cham" Unicode character block. + * @since 1.7 + */ + public static final UnicodeBlock CHAM = new UnicodeBlock("CHAM"); + + /** + * Constant for the "Vertical Forms" Unicode character block. + * @since 1.7 + */ + public static final UnicodeBlock VERTICAL_FORMS = + new UnicodeBlock("VERTICAL_FORMS", + new String[] { "Vertical Forms", + "VerticalForms"}); + + /** + * Constant for the "Ancient Greek Numbers" Unicode character block. + * @since 1.7 + */ + public static final UnicodeBlock ANCIENT_GREEK_NUMBERS = + new UnicodeBlock("ANCIENT_GREEK_NUMBERS", + new String[] { "Ancient Greek Numbers", + "AncientGreekNumbers"}); + + /** + * Constant for the "Ancient Symbols" Unicode character block. + * @since 1.7 + */ + public static final UnicodeBlock ANCIENT_SYMBOLS = + new UnicodeBlock("ANCIENT_SYMBOLS", + new String[] { "Ancient Symbols", + "AncientSymbols"}); + + /** + * Constant for the "Phaistos Disc" Unicode character block. + * @since 1.7 + */ + public static final UnicodeBlock PHAISTOS_DISC = + new UnicodeBlock("PHAISTOS_DISC", + new String[] { "Phaistos Disc", + "PhaistosDisc"}); + + /** + * Constant for the "Lycian" Unicode character block. + * @since 1.7 + */ + public static final UnicodeBlock LYCIAN = new UnicodeBlock("LYCIAN"); + + /** + * Constant for the "Carian" Unicode character block. + * @since 1.7 + */ + public static final UnicodeBlock CARIAN = new UnicodeBlock("CARIAN"); + + /** + * Constant for the "Old Persian" Unicode character block. + * @since 1.7 + */ + public static final UnicodeBlock OLD_PERSIAN = + new UnicodeBlock("OLD_PERSIAN", + new String[] { "Old Persian", + "OldPersian"}); + + /** + * Constant for the "Phoenician" Unicode character block. + * @since 1.7 + */ + public static final UnicodeBlock PHOENICIAN = + new UnicodeBlock("PHOENICIAN"); + + /** + * Constant for the "Lydian" Unicode character block. + * @since 1.7 + */ + public static final UnicodeBlock LYDIAN = new UnicodeBlock("LYDIAN"); + + /** + * Constant for the "Kharoshthi" Unicode character block. + * @since 1.7 + */ + public static final UnicodeBlock KHAROSHTHI = + new UnicodeBlock("KHAROSHTHI"); + + /** + * Constant for the "Cuneiform" Unicode character block. + * @since 1.7 + */ + public static final UnicodeBlock CUNEIFORM = + new UnicodeBlock("CUNEIFORM"); + + /** + * Constant for the "Cuneiform Numbers and Punctuation" Unicode + * character block. + * @since 1.7 + */ + public static final UnicodeBlock CUNEIFORM_NUMBERS_AND_PUNCTUATION = + new UnicodeBlock("CUNEIFORM_NUMBERS_AND_PUNCTUATION", + new String[] { "Cuneiform Numbers and Punctuation", + "CuneiformNumbersandPunctuation"}); + + /** + * Constant for the "Ancient Greek Musical Notation" Unicode character + * block. + * @since 1.7 + */ + public static final UnicodeBlock ANCIENT_GREEK_MUSICAL_NOTATION = + new UnicodeBlock("ANCIENT_GREEK_MUSICAL_NOTATION", + new String[] { "Ancient Greek Musical Notation", + "AncientGreekMusicalNotation"}); + + /** + * Constant for the "Counting Rod Numerals" Unicode character block. + * @since 1.7 + */ + public static final UnicodeBlock COUNTING_ROD_NUMERALS = + new UnicodeBlock("COUNTING_ROD_NUMERALS", + new String[] { "Counting Rod Numerals", + "CountingRodNumerals"}); + + /** + * Constant for the "Mahjong Tiles" Unicode character block. + * @since 1.7 + */ + public static final UnicodeBlock MAHJONG_TILES = + new UnicodeBlock("MAHJONG_TILES", + new String[] { "Mahjong Tiles", + "MahjongTiles"}); + + /** + * Constant for the "Domino Tiles" Unicode character block. + * @since 1.7 + */ + public static final UnicodeBlock DOMINO_TILES = + new UnicodeBlock("DOMINO_TILES", + new String[] { "Domino Tiles", + "DominoTiles"}); + private static final int blockStarts[] = { - 0x0000, // Basic Latin - 0x0080, // Latin-1 Supplement - 0x0100, // Latin Extended-A - 0x0180, // Latin Extended-B - 0x0250, // IPA Extensions - 0x02B0, // Spacing Modifier Letters - 0x0300, // Combining Diacritical Marks - 0x0370, // Greek and Coptic - 0x0400, // Cyrillic - 0x0500, // Cyrillic Supplementary - 0x0530, // Armenian - 0x0590, // Hebrew - 0x0600, // Arabic - 0x0700, // Syriac - 0x0750, // unassigned - 0x0780, // Thaana - 0x07C0, // unassigned - 0x0900, // Devanagari - 0x0980, // Bengali - 0x0A00, // Gurmukhi - 0x0A80, // Gujarati - 0x0B00, // Oriya - 0x0B80, // Tamil - 0x0C00, // Telugu - 0x0C80, // Kannada - 0x0D00, // Malayalam - 0x0D80, // Sinhala - 0x0E00, // Thai - 0x0E80, // Lao - 0x0F00, // Tibetan - 0x1000, // Myanmar - 0x10A0, // Georgian - 0x1100, // Hangul Jamo - 0x1200, // Ethiopic - 0x1380, // unassigned - 0x13A0, // Cherokee - 0x1400, // Unified Canadian Aboriginal Syllabics - 0x1680, // Ogham - 0x16A0, // Runic - 0x1700, // Tagalog - 0x1720, // Hanunoo - 0x1740, // Buhid - 0x1760, // Tagbanwa - 0x1780, // Khmer - 0x1800, // Mongolian - 0x18B0, // unassigned - 0x1900, // Limbu - 0x1950, // Tai Le - 0x1980, // unassigned - 0x19E0, // Khmer Symbols - 0x1A00, // unassigned - 0x1D00, // Phonetic Extensions - 0x1D80, // unassigned - 0x1E00, // Latin Extended Additional - 0x1F00, // Greek Extended - 0x2000, // General Punctuation - 0x2070, // Superscripts and Subscripts - 0x20A0, // Currency Symbols - 0x20D0, // Combining Diacritical Marks for Symbols - 0x2100, // Letterlike Symbols - 0x2150, // Number Forms - 0x2190, // Arrows - 0x2200, // Mathematical Operators - 0x2300, // Miscellaneous Technical - 0x2400, // Control Pictures - 0x2440, // Optical Character Recognition - 0x2460, // Enclosed Alphanumerics - 0x2500, // Box Drawing - 0x2580, // Block Elements - 0x25A0, // Geometric Shapes - 0x2600, // Miscellaneous Symbols - 0x2700, // Dingbats - 0x27C0, // Miscellaneous Mathematical Symbols-A - 0x27F0, // Supplemental Arrows-A - 0x2800, // Braille Patterns - 0x2900, // Supplemental Arrows-B - 0x2980, // Miscellaneous Mathematical Symbols-B - 0x2A00, // Supplemental Mathematical Operators - 0x2B00, // Miscellaneous Symbols and Arrows - 0x2C00, // unassigned - 0x2E80, // CJK Radicals Supplement - 0x2F00, // Kangxi Radicals - 0x2FE0, // unassigned - 0x2FF0, // Ideographic Description Characters - 0x3000, // CJK Symbols and Punctuation - 0x3040, // Hiragana - 0x30A0, // Katakana - 0x3100, // Bopomofo - 0x3130, // Hangul Compatibility Jamo - 0x3190, // Kanbun - 0x31A0, // Bopomofo Extended - 0x31C0, // unassigned - 0x31F0, // Katakana Phonetic Extensions - 0x3200, // Enclosed CJK Letters and Months - 0x3300, // CJK Compatibility - 0x3400, // CJK Unified Ideographs Extension A - 0x4DC0, // Yijing Hexagram Symbols - 0x4E00, // CJK Unified Ideographs - 0xA000, // Yi Syllables - 0xA490, // Yi Radicals - 0xA4D0, // unassigned - 0xAC00, // Hangul Syllables - 0xD7B0, // unassigned - 0xD800, // High Surrogates - 0xDB80, // High Private Use Surrogates - 0xDC00, // Low Surrogates - 0xE000, // Private Use - 0xF900, // CJK Compatibility Ideographs - 0xFB00, // Alphabetic Presentation Forms - 0xFB50, // Arabic Presentation Forms-A - 0xFE00, // Variation Selectors - 0xFE10, // unassigned - 0xFE20, // Combining Half Marks - 0xFE30, // CJK Compatibility Forms - 0xFE50, // Small Form Variants - 0xFE70, // Arabic Presentation Forms-B - 0xFF00, // Halfwidth and Fullwidth Forms - 0xFFF0, // Specials - 0x10000, // Linear B Syllabary - 0x10080, // Linear B Ideograms - 0x10100, // Aegean Numbers - 0x10140, // unassigned - 0x10300, // Old Italic - 0x10330, // Gothic - 0x10350, // unassigned - 0x10380, // Ugaritic - 0x103A0, // unassigned - 0x10400, // Deseret - 0x10450, // Shavian - 0x10480, // Osmanya - 0x104B0, // unassigned - 0x10800, // Cypriot Syllabary - 0x10840, // unassigned - 0x1D000, // Byzantine Musical Symbols - 0x1D100, // Musical Symbols - 0x1D200, // unassigned - 0x1D300, // Tai Xuan Jing Symbols - 0x1D360, // unassigned - 0x1D400, // Mathematical Alphanumeric Symbols - 0x1D800, // unassigned - 0x20000, // CJK Unified Ideographs Extension B - 0x2A6E0, // unassigned - 0x2F800, // CJK Compatibility Ideographs Supplement - 0x2FA20, // unassigned - 0xE0000, // Tags - 0xE0080, // unassigned - 0xE0100, // Variation Selectors Supplement - 0xE01F0, // unassigned - 0xF0000, // Supplementary Private Use Area-A - 0x100000, // Supplementary Private Use Area-B + 0x0000, // 0000..007F; Basic Latin + 0x0080, // 0080..00FF; Latin-1 Supplement + 0x0100, // 0100..017F; Latin Extended-A + 0x0180, // 0180..024F; Latin Extended-B + 0x0250, // 0250..02AF; IPA Extensions + 0x02B0, // 02B0..02FF; Spacing Modifier Letters + 0x0300, // 0300..036F; Combining Diacritical Marks + 0x0370, // 0370..03FF; Greek and Coptic + 0x0400, // 0400..04FF; Cyrillic + 0x0500, // 0500..052F; Cyrillic Supplement + 0x0530, // 0530..058F; Armenian + 0x0590, // 0590..05FF; Hebrew + 0x0600, // 0600..06FF; Arabic + 0x0700, // 0700..074F; Syria + 0x0750, // 0750..077F; Arabic Supplement + 0x0780, // 0780..07BF; Thaana + 0x07C0, // 07C0..07FF; NKo + 0x0800, // unassigned + 0x0900, // 0900..097F; Devanagari + 0x0980, // 0980..09FF; Bengali + 0x0A00, // 0A00..0A7F; Gurmukhi + 0x0A80, // 0A80..0AFF; Gujarati + 0x0B00, // 0B00..0B7F; Oriya + 0x0B80, // 0B80..0BFF; Tamil + 0x0C00, // 0C00..0C7F; Telugu + 0x0C80, // 0C80..0CFF; Kannada + 0x0D00, // 0D00..0D7F; Malayalam + 0x0D80, // 0D80..0DFF; Sinhala + 0x0E00, // 0E00..0E7F; Thai + 0x0E80, // 0E80..0EFF; Lao + 0x0F00, // 0F00..0FFF; Tibetan + 0x1000, // 1000..109F; Myanmar + 0x10A0, // 10A0..10FF; Georgian + 0x1100, // 1100..11FF; Hangul Jamo + 0x1200, // 1200..137F; Ethiopic + 0x1380, // 1380..139F; Ethiopic Supplement + 0x13A0, // 13A0..13FF; Cherokee + 0x1400, // 1400..167F; Unified Canadian Aboriginal Syllabics + 0x1680, // 1680..169F; Ogham + 0x16A0, // 16A0..16FF; Runic + 0x1700, // 1700..171F; Tagalog + 0x1720, // 1720..173F; Hanunoo + 0x1740, // 1740..175F; Buhid + 0x1760, // 1760..177F; Tagbanwa + 0x1780, // 1780..17FF; Khmer + 0x1800, // 1800..18AF; Mongolian + 0x18B0, // unassigned + 0x1900, // 1900..194F; Limbu + 0x1950, // 1950..197F; Tai Le + 0x1980, // 1980..19DF; New Tai Lue + 0x19E0, // 19E0..19FF; Khmer Symbols + 0x1A00, // 1A00..1A1F; Buginese + 0x1A20, // unassigned + 0x1B00, // 1B00..1B7F; Balinese + 0x1B80, // 1B80..1BBF; Sundanese + 0x1BC0, // unassigned + 0x1C00, // 1C00..1C4F; Lepcha + 0x1C50, // 1C50..1C7F; Ol Chiki + 0x1C80, // unassigned + 0x1D00, // 1D00..1D7F; Phonetic Extensions + 0x1D80, // 1D80..1DBF; Phonetic Extensions Supplement + 0x1DC0, // 1DC0..1DFF; Combining Diacritical Marks Supplement + 0x1E00, // 1E00..1EFF; Latin Extended Additional + 0x1F00, // 1F00..1FFF; Greek Extended + 0x2000, // 2000..206F; General Punctuation + 0x2070, // 2070..209F; Superscripts and Subscripts + 0x20A0, // 20A0..20CF; Currency Symbols + 0x20D0, // 20D0..20FF; Combining Diacritical Marks for Symbols + 0x2100, // 2100..214F; Letterlike Symbols + 0x2150, // 2150..218F; Number Forms + 0x2190, // 2190..21FF; Arrows + 0x2200, // 2200..22FF; Mathematical Operators + 0x2300, // 2300..23FF; Miscellaneous Technical + 0x2400, // 2400..243F; Control Pictures + 0x2440, // 2440..245F; Optical Character Recognition + 0x2460, // 2460..24FF; Enclosed Alphanumerics + 0x2500, // 2500..257F; Box Drawing + 0x2580, // 2580..259F; Block Elements + 0x25A0, // 25A0..25FF; Geometric Shapes + 0x2600, // 2600..26FF; Miscellaneous Symbols + 0x2700, // 2700..27BF; Dingbats + 0x27C0, // 27C0..27EF; Miscellaneous Mathematical Symbols-A + 0x27F0, // 27F0..27FF; Supplemental Arrows-A + 0x2800, // 2800..28FF; Braille Patterns + 0x2900, // 2900..297F; Supplemental Arrows-B + 0x2980, // 2980..29FF; Miscellaneous Mathematical Symbols-B + 0x2A00, // 2A00..2AFF; Supplemental Mathematical Operators + 0x2B00, // 2B00..2BFF; Miscellaneous Symbols and Arrows + 0x2C00, // 2C00..2C5F; Glagolitic + 0x2C60, // 2C60..2C7F; Latin Extended-C + 0x2C80, // 2C80..2CFF; Coptic + 0x2D00, // 2D00..2D2F; Georgian Supplement + 0x2D30, // 2D30..2D7F; Tifinagh + 0x2D80, // 2D80..2DDF; Ethiopic Extended + 0x2DE0, // 2DE0..2DFF; Cyrillic Extended-A + 0x2E00, // 2E00..2E7F; Supplemental Punctuation + 0x2E80, // 2E80..2EFF; CJK Radicals Supplement + 0x2F00, // 2F00..2FDF; Kangxi Radicals + 0x2FE0, // unassigned + 0x2FF0, // 2FF0..2FFF; Ideographic Description Characters + 0x3000, // 3000..303F; CJK Symbols and Punctuation + 0x3040, // 3040..309F; Hiragana + 0x30A0, // 30A0..30FF; Katakana + 0x3100, // 3100..312F; Bopomofo + 0x3130, // 3130..318F; Hangul Compatibility Jamo + 0x3190, // 3190..319F; Kanbun + 0x31A0, // 31A0..31BF; Bopomofo Extended + 0x31C0, // 31C0..31EF; CJK Strokes + 0x31F0, // 31F0..31FF; Katakana Phonetic Extensions + 0x3200, // 3200..32FF; Enclosed CJK Letters and Months + 0x3300, // 3300..33FF; CJK Compatibility + 0x3400, // 3400..4DBF; CJK Unified Ideographs Extension A + 0x4DC0, // 4DC0..4DFF; Yijing Hexagram Symbols + 0x4E00, // 4E00..9FFF; CJK Unified Ideograph + 0xA000, // A000..A48F; Yi Syllables + 0xA490, // A490..A4CF; Yi Radicals + 0xA4D0, // unassigned + 0xA500, // A500..A63F; Vai + 0xA640, // A640..A69F; Cyrillic Extended-B + 0xA6A0, // unassigned + 0xA700, // A700..A71F; Modifier Tone Letters + 0xA720, // A720..A7FF; Latin Extended-D + 0xA800, // A800..A82F; Syloti Nagri + 0xA830, // unassigned + 0xA840, // A840..A87F; Phags-pa + 0xA880, // A880..A8DF; Saurashtra + 0xA8E0, // unassigned + 0xA900, // A900..A92F; Kayah Li + 0xA930, // A930..A95F; Rejang + 0xA960, // unassigned + 0xAA00, // AA00..AA5F; Cham + 0xAA60, // unassigned + 0xAC00, // AC00..D7AF; Hangul Syllables + 0xD7B0, // unassigned + 0xD800, // D800..DB7F; High Surrogates + 0xDB80, // DB80..DBFF; High Private Use Surrogates + 0xDC00, // DC00..DFFF; Low Surrogates + 0xE000, // E000..F8FF; Private Use Area + 0xF900, // F900..FAFF; CJK Compatibility Ideographs + 0xFB00, // FB00..FB4F; Alphabetic Presentation Forms + 0xFB50, // FB50..FDFF; Arabic Presentation Forms-A + 0xFE00, // FE00..FE0F; Variation Selectors + 0xFE10, // FE10..FE1F; Vertical Forms + 0xFE20, // FE20..FE2F; Combining Half Marks + 0xFE30, // FE30..FE4F; CJK Compatibility Forms + 0xFE50, // FE50..FE6F; Small Form Variants + 0xFE70, // FE70..FEFF; Arabic Presentation Forms-B + 0xFF00, // FF00..FFEF; Halfwidth and Fullwidth Forms + 0xFFF0, // FFF0..FFFF; Specials + 0x10000, // 10000..1007F; Linear B Syllabary + 0x10080, // 10080..100FF; Linear B Ideograms + 0x10100, // 10100..1013F; Aegean Numbers + 0x10140, // 10140..1018F; Ancient Greek Numbers + 0x10190, // 10190..101CF; Ancient Symbols + 0x101D0, // 101D0..101FF; Phaistos Disc + 0x10200, // unassigned + 0x10280, // 10280..1029F; Lycian + 0x102A0, // 102A0..102DF; Carian + 0x102E0, // unassigned + 0x10300, // 10300..1032F; Old Italic + 0x10330, // 10330..1034F; Gothic + 0x10350, // unassigned + 0x10380, // 10380..1039F; Ugaritic + 0x103A0, // 103A0..103DF; Old Persian + 0x103E0, // unassigned + 0x10400, // 10400..1044F; Desere + 0x10450, // 10450..1047F; Shavian + 0x10480, // 10480..104AF; Osmanya + 0x104B0, // unassigned + 0x10800, // 10800..1083F; Cypriot Syllabary + 0x10840, // unassigned + 0x10900, // 10900..1091F; Phoenician + 0x10920, // 10920..1093F; Lydian + 0x10940, // unassigned + 0x10A00, // 10A00..10A5F; Kharoshthi + 0x10A60, // unassigned + 0x12000, // 12000..123FF; Cuneiform + 0x12400, // 12400..1247F; Cuneiform Numbers and Punctuation + 0x12480, // unassigned + 0x1D000, // 1D000..1D0FF; Byzantine Musical Symbols + 0x1D100, // 1D100..1D1FF; Musical Symbols + 0x1D200, // 1D200..1D24F; Ancient Greek Musical Notation + 0x1D250, // unassigned + 0x1D300, // 1D300..1D35F; Tai Xuan Jing Symbols + 0x1D360, // 1D360..1D37F; Counting Rod Numerals + 0x1D380, // unassigned + 0x1D400, // 1D400..1D7FF; Mathematical Alphanumeric Symbols + 0x1D800, // unassigned + 0x1F000, // 1F000..1F02F; Mahjong Tiles + 0x1F030, // 1F030..1F09F; Domino Tiles + 0x1F0A0, // unassigned + 0x20000, // 20000..2A6DF; CJK Unified Ideographs Extension B + 0x2A6E0, // unassigned + 0x2F800, // 2F800..2FA1F; CJK Compatibility Ideographs Supplement + 0x2FA20, // unassigned + 0xE0000, // E0000..E007F; Tags + 0xE0080, // unassigned + 0xE0100, // E0100..E01EF; Variation Selectors Supplement + 0xE01F0, // unassigned + 0xF0000, // F0000..FFFFF; Supplementary Private Use Area-A + 0x100000, // 100000..10FFFF; Supplementary Private Use Area-B }; private static final UnicodeBlock[] blocks = { @@ -1809,8 +2234,9 @@ class Character extends Object implements java.io.Serializable, Comparable<Chara HEBREW, ARABIC, SYRIAC, - null, + ARABIC_SUPPLEMENT, THAANA, + NKO, null, DEVANAGARI, BENGALI, @@ -1829,7 +2255,7 @@ class Character extends Object implements java.io.Serializable, Comparable<Chara GEORGIAN, HANGUL_JAMO, ETHIOPIC, - null, + ETHIOPIC_SUPPLEMENT, CHEROKEE, UNIFIED_CANADIAN_ABORIGINAL_SYLLABICS, OGHAM, @@ -1843,11 +2269,19 @@ class Character extends Object implements java.io.Serializable, Comparable<Chara null, LIMBU, TAI_LE, - null, + NEW_TAI_LUE, KHMER_SYMBOLS, + BUGINESE, null, - PHONETIC_EXTENSIONS, + BALINESE, + SUNDANESE, + null, + LEPCHA, + OL_CHIKI, null, + PHONETIC_EXTENSIONS, + PHONETIC_EXTENSIONS_SUPPLEMENT, + COMBINING_DIACRITICAL_MARKS_SUPPLEMENT, LATIN_EXTENDED_ADDITIONAL, GREEK_EXTENDED, GENERAL_PUNCTUATION, @@ -1874,7 +2308,14 @@ class Character extends Object implements java.io.Serializable, Comparable<Chara MISCELLANEOUS_MATHEMATICAL_SYMBOLS_B, SUPPLEMENTAL_MATHEMATICAL_OPERATORS, MISCELLANEOUS_SYMBOLS_AND_ARROWS, - null, + GLAGOLITIC, + LATIN_EXTENDED_C, + COPTIC, + GEORGIAN_SUPPLEMENT, + TIFINAGH, + ETHIOPIC_EXTENDED, + CYRILLIC_EXTENDED_A, + SUPPLEMENTAL_PUNCTUATION, CJK_RADICALS_SUPPLEMENT, KANGXI_RADICALS, null, @@ -1886,7 +2327,7 @@ class Character extends Object implements java.io.Serializable, Comparable<Chara HANGUL_COMPATIBILITY_JAMO, KANBUN, BOPOMOFO_EXTENDED, - null, + CJK_STROKES, KATAKANA_PHONETIC_EXTENSIONS, ENCLOSED_CJK_LETTERS_AND_MONTHS, CJK_COMPATIBILITY, @@ -1896,6 +2337,21 @@ class Character extends Object implements java.io.Serializable, Comparable<Chara YI_SYLLABLES, YI_RADICALS, null, + VAI, + CYRILLIC_EXTENDED_B, + null, + MODIFIER_TONE_LETTERS, + LATIN_EXTENDED_D, + SYLOTI_NAGRI, + null, + PHAGS_PA, + SAURASHTRA, + null, + KAYAH_LI, + REJANG, + null, + CHAM, + null, HANGUL_SYLLABLES, null, HIGH_SURROGATES, @@ -1906,7 +2362,7 @@ class Character extends Object implements java.io.Serializable, Comparable<Chara ALPHABETIC_PRESENTATION_FORMS, ARABIC_PRESENTATION_FORMS_A, VARIATION_SELECTORS, - null, + VERTICAL_FORMS, COMBINING_HALF_MARKS, CJK_COMPATIBILITY_FORMS, SMALL_FORM_VARIANTS, @@ -1916,11 +2372,18 @@ class Character extends Object implements java.io.Serializable, Comparable<Chara LINEAR_B_SYLLABARY, LINEAR_B_IDEOGRAMS, AEGEAN_NUMBERS, + ANCIENT_GREEK_NUMBERS, + ANCIENT_SYMBOLS, + PHAISTOS_DISC, + null, + LYCIAN, + CARIAN, null, OLD_ITALIC, GOTHIC, null, UGARITIC, + OLD_PERSIAN, null, DESERET, SHAVIAN, @@ -1928,13 +2391,26 @@ class Character extends Object implements java.io.Serializable, Comparable<Chara null, CYPRIOT_SYLLABARY, null, + PHOENICIAN, + LYDIAN, + null, + KHAROSHTHI, + null, + CUNEIFORM, + CUNEIFORM_NUMBERS_AND_PUNCTUATION, + null, BYZANTINE_MUSICAL_SYMBOLS, MUSICAL_SYMBOLS, + ANCIENT_GREEK_MUSICAL_NOTATION, null, TAI_XUAN_JING_SYMBOLS, + COUNTING_ROD_NUMERALS, null, MATHEMATICAL_ALPHANUMERIC_SYMBOLS, null, + MAHJONG_TILES, + DOMINO_TILES, + null, CJK_UNIFIED_IDEOGRAPHS_EXTENSION_B, null, CJK_COMPATIBILITY_IDEOGRAPHS_SUPPLEMENT, diff --git a/src/share/classes/java/lang/Class.java b/src/share/classes/java/lang/Class.java index 77df0d146fdc097fddec5916b571a3400dabcdc7..4ba497c64cf280c41d6148b59110e22e0263f00e 100644 --- a/src/share/classes/java/lang/Class.java +++ b/src/share/classes/java/lang/Class.java @@ -1,5 +1,5 @@ /* - * Copyright 1994-2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 1994-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 @@ -2846,14 +2846,14 @@ public final if (loader == null) return desiredAssertionStatus0(this); - synchronized(loader) { - // If the classloader has been initialized with - // the assertion directives, ask it. Otherwise, - // ask the VM. - return (loader.classAssertionStatus == null ? - desiredAssertionStatus0(this) : - loader.desiredAssertionStatus(getName())); + // If the classloader has been initialized with the assertion + // directives, ask it. Otherwise, ask the VM. + synchronized(loader.assertionLock) { + if (loader.classAssertionStatus != null) { + return loader.desiredAssertionStatus(getName()); + } } + return desiredAssertionStatus0(this); } // Retrieves the desired assertion status of this class from the VM @@ -3059,14 +3059,12 @@ public final } - private static Annotation[] EMPTY_ANNOTATIONS_ARRAY = new Annotation[0]; - /** * @since 1.5 */ public Annotation[] getAnnotations() { initAnnotationsIfNecessary(); - return annotations.values().toArray(EMPTY_ANNOTATIONS_ARRAY); + return AnnotationParser.toArray(annotations); } /** @@ -3074,7 +3072,7 @@ public final */ public Annotation[] getDeclaredAnnotations() { initAnnotationsIfNecessary(); - return declaredAnnotations.values().toArray(EMPTY_ANNOTATIONS_ARRAY); + return AnnotationParser.toArray(declaredAnnotations); } // Annotations cache diff --git a/src/share/classes/java/lang/ClassLoader.java b/src/share/classes/java/lang/ClassLoader.java index c0caa01dcf3229bad0ae3fb135e08f7021340fcb..cc0987a5864cafb73414ed368ceb8b0f8d8430c2 100644 --- a/src/share/classes/java/lang/ClassLoader.java +++ b/src/share/classes/java/lang/ClassLoader.java @@ -1,5 +1,5 @@ /* - * Copyright 1994-2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 1994-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 @@ -40,14 +40,17 @@ import java.security.PrivilegedActionException; import java.security.PrivilegedExceptionAction; import java.security.ProtectionDomain; import java.security.cert.Certificate; +import java.util.Collections; import java.util.Enumeration; -import java.util.Hashtable; import java.util.HashMap; import java.util.HashSet; import java.util.Set; import java.util.Stack; import java.util.Map; import java.util.Vector; +import java.util.Hashtable; +import java.util.WeakHashMap; +import java.util.concurrent.ConcurrentHashMap; import sun.misc.ClassFileTransformer; import sun.misc.CompoundEnumeration; import sun.misc.Resource; @@ -91,6 +94,17 @@ import sun.security.util.SecurityConstants; * called the "bootstrap class loader", does not itself have a parent but may * serve as the parent of a <tt>ClassLoader</tt> instance. * + * <p> Class loaders that support concurrent loading of classes are known as + * <em>parallel capable</em> class loaders and are required to register + * themselves at their class initialization time by invoking the + * {@link + * #registerAsParallelCapable <tt>ClassLoader.registerAsParallelCapable</tt>} + * method. In environments in which the delegation model is not strictly + * hierarchical, class loaders need to be parallel capable, otherise class + * loading can lead to deadlocks because the loader lock is held for the + * duration of the class loading process (see {@link #loadClass + * <tt>loadClass</tt>} methods). + * * <p> Normally, the Java virtual machine loads classes from the local file * system in a platform-dependent manner. For example, on UNIX systems, the * virtual machine loads classes from the directory defined by the @@ -160,31 +174,51 @@ import sun.security.util.SecurityConstants; public abstract class ClassLoader { private static native void registerNatives(); + + // Set of classes which are registered as parallel capable class loaders + private static final Set<Class<? extends ClassLoader>> parallelLoaders + = Collections.newSetFromMap(Collections.synchronizedMap + (new WeakHashMap<Class<? extends ClassLoader>, Boolean>())); + static { registerNatives(); + parallelLoaders.add(ClassLoader.class); } // If initialization succeed this is set to true and security checks will // succeed. Otherwise the object is not initialized and the object is // useless. - private boolean initialized = false; + private final boolean initialized; // The parent class loader for delegation - private ClassLoader parent; + // Note: VM hardcoded the offset of this field, thus all new fields + // must be added *after* it. + private final ClassLoader parent; + + // Maps class name to the corresponding lock object when the current + // class loader is parallel capable. + // Note: VM also uses this field to decide if the current class loader + // is parallel capable and the appropriate lock object for class loading. + private final ConcurrentHashMap<String, Object> parallelLockMap; // Hashtable that maps packages to certs - private Hashtable<String, Certificate[]> package2certs - = new Hashtable<String, Certificate[]>(11); + private final Map <String, Certificate[]> package2certs; // Shared among all packages with unsigned classes - Certificate[] nocerts; + private static final Certificate[] nocerts = new Certificate[0]; - // The classes loaded by this class loader. The only purpose of this table + // The classes loaded by this class loader. The only purpose of this table // is to keep the classes from being GC'ed until the loader is GC'ed. - private Vector<Class<?>> classes = new Vector<Class<?>>(); + private final Vector<Class<?>> classes = new Vector<Class<?>>(); + + // The "default" domain. Set as the default ProtectionDomain on newly + // created classes. + private final ProtectionDomain defaultDomain = + new ProtectionDomain(new CodeSource(null, (Certificate[]) null), + null, this, null); // The initiating protection domains for all classes loaded by this loader - private Set<ProtectionDomain> domains = new HashSet<ProtectionDomain>(); + private final Set<ProtectionDomain> domains; // Invoked by the VM to record every loaded class with this loader. void addClass(Class c) { @@ -193,7 +227,9 @@ public abstract class ClassLoader { // The packages defined in this class loader. Each package name is mapped // to its corresponding Package object. - private HashMap<String, Package> packages = new HashMap<String, Package>(); + // @GuardedBy("itself") + private final HashMap<String, Package> packages = + new HashMap<String, Package>(); /** * Creates a new class loader using the specified parent class loader for @@ -220,6 +256,19 @@ public abstract class ClassLoader { security.checkCreateClassLoader(); } this.parent = parent; + if (parallelLoaders.contains(this.getClass())) { + parallelLockMap = new ConcurrentHashMap<String, Object>(); + package2certs = new ConcurrentHashMap<String, Certificate[]>(); + domains = + Collections.synchronizedSet(new HashSet<ProtectionDomain>()); + assertionLock = new Object(); + } else { + // no finer-grained lock; lock on the classloader instance + parallelLockMap = null; + package2certs = new Hashtable<String, Certificate[]>(); + domains = new HashSet<ProtectionDomain>(); + assertionLock = this; + } initialized = true; } @@ -244,10 +293,22 @@ public abstract class ClassLoader { security.checkCreateClassLoader(); } this.parent = getSystemClassLoader(); + if (parallelLoaders.contains(this.getClass())) { + parallelLockMap = new ConcurrentHashMap<String, Object>(); + package2certs = new ConcurrentHashMap<String, Certificate[]>(); + domains = + Collections.synchronizedSet(new HashSet<ProtectionDomain>()); + assertionLock = new Object(); + } else { + // no finer-grained lock; lock on the classloader instance + parallelLockMap = null; + package2certs = new Hashtable<String, Certificate[]>(); + domains = new HashSet<ProtectionDomain>(); + assertionLock = this; + } initialized = true; } - // -- Class -- /** @@ -296,6 +357,10 @@ public abstract class ClassLoader { * <p> Subclasses of <tt>ClassLoader</tt> are encouraged to override {@link * #findClass(String)}, rather than this method. </p> * + * <p> Unless overridden, this method synchronizes on the result of + * {@link #getClassLoadingLock <tt>getClassLoadingLock</tt>} method + * during the entire class loading process. + * * @param name * The <a href="#name">binary name</a> of the class * @@ -307,37 +372,80 @@ public abstract class ClassLoader { * @throws ClassNotFoundException * If the class could not be found */ - protected synchronized Class<?> loadClass(String name, boolean resolve) + protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException { - // First, check if the class has already been loaded - Class c = findLoadedClass(name); - if (c == null) { - try { - if (parent != null) { - c = parent.loadClass(name, false); - } else { - c = findBootstrapClass0(name); + synchronized (getClassLoadingLock(name)) { + // First, check if the class has already been loaded + Class c = findLoadedClass(name); + if (c == null) { + try { + if (parent != null) { + c = parent.loadClass(name, false); + } else { + c = findBootstrapClass0(name); + } + } catch (ClassNotFoundException e) { + // If still not found, then invoke findClass in order + // to find the class. + c = findClass(name); } - } catch (ClassNotFoundException e) { - // If still not found, then invoke findClass in order - // to find the class. - c = findClass(name); } + if (resolve) { + resolveClass(c); + } + return c; } - if (resolve) { - resolveClass(c); + } + + /** + * Returns the lock object for class loading operations. + * For backward compatibility, the default implementation of this method + * behaves as follows. If this ClassLoader object is registered as + * parallel capable, the method returns a dedicated object associated + * with the specified class name. Otherwise, the method returns this + * ClassLoader object. </p> + * + * @param className + * The name of the to-be-loaded class + * + * @return the lock for class loading operations + * + * @throws NullPointerException + * If registered as parallel capable and <tt>className</tt> is null + * + * @see #loadClass(String, boolean) + * + * @since 1.7 + */ + protected Object getClassLoadingLock(String className) { + Object lock = this; + if (parallelLockMap != null) { + Object newLock = new Object(); + lock = parallelLockMap.putIfAbsent(className, newLock); + if (lock == null) { + lock = newLock; + } } - return c; + return lock; } // This method is invoked by the virtual machine to load a class. - private synchronized Class loadClassInternal(String name) + private Class loadClassInternal(String name) throws ClassNotFoundException { - return loadClass(name); + // For backward compatibility, explicitly lock on 'this' when + // the current class loader is not parallel capable. + if (parallelLockMap == null) { + synchronized (this) { + return loadClass(name); + } + } else { + return loadClass(name); + } } + // Invoked by the VM after loading class with this loader. private void checkPackageAccess(Class cls, ProtectionDomain pd) { final SecurityManager sm = System.getSecurityManager(); if (sm != null) { @@ -486,31 +594,32 @@ public abstract class ClassLoader { /* Determine protection domain, and check that: - not define java.* class, - - signer of this class matches signers for the rest of the classes in package. + - signer of this class matches signers for the rest of the classes in + package. */ private ProtectionDomain preDefineClass(String name, - ProtectionDomain protectionDomain) + ProtectionDomain pd) { if (!checkName(name)) throw new NoClassDefFoundError("IllegalName: " + name); if ((name != null) && name.startsWith("java.")) { - throw new SecurityException("Prohibited package name: " + - name.substring(0, name.lastIndexOf('.'))); + throw new SecurityException + ("Prohibited package name: " + + name.substring(0, name.lastIndexOf('.'))); } - if (protectionDomain == null) { - protectionDomain = getDefaultDomain(); + if (pd == null) { + pd = defaultDomain; } - if (name != null) - checkCerts(name, protectionDomain.getCodeSource()); + if (name != null) checkCerts(name, pd.getCodeSource()); - return protectionDomain; + return pd; } - private String defineClassSourceLocation(ProtectionDomain protectionDomain) + private String defineClassSourceLocation(ProtectionDomain pd) { - CodeSource cs = protectionDomain.getCodeSource(); + CodeSource cs = pd.getCodeSource(); String source = null; if (cs != null && cs.getLocation() != null) { source = cs.getLocation().toString(); @@ -519,14 +628,15 @@ public abstract class ClassLoader { } private Class defineTransformedClass(String name, byte[] b, int off, int len, - ProtectionDomain protectionDomain, + ProtectionDomain pd, ClassFormatError cfe, String source) throws ClassFormatError { // Class format error - try to transform the bytecode and // define the class again // - ClassFileTransformer[] transformers = ClassFileTransformer.getTransformers(); + ClassFileTransformer[] transformers = + ClassFileTransformer.getTransformers(); Class c = null; if (transformers != null) { @@ -535,7 +645,7 @@ public abstract class ClassLoader { // Transform byte code using transformer byte[] tb = transformer.transform(b, off, len); c = defineClass1(name, tb, 0, tb.length, - protectionDomain, source); + pd, source); break; } catch (ClassFormatError cfe2) { // If ClassFormatError occurs, try next transformer @@ -552,11 +662,10 @@ public abstract class ClassLoader { return c; } - private void postDefineClass(Class c, ProtectionDomain protectionDomain) + private void postDefineClass(Class c, ProtectionDomain pd) { - if (protectionDomain.getCodeSource() != null) { - Certificate certs[] = - protectionDomain.getCodeSource().getCertificates(); + if (pd.getCodeSource() != null) { + Certificate certs[] = pd.getCodeSource().getCertificates(); if (certs != null) setSigners(c, certs); } @@ -641,7 +750,8 @@ public abstract class ClassLoader { try { c = defineClass1(name, b, off, len, protectionDomain, source); } catch (ClassFormatError cfe) { - c = defineTransformedClass(name, b, off, len, protectionDomain, cfe, source); + c = defineTransformedClass(name, b, off, len, protectionDomain, cfe, + source); } postDefineClass(c, protectionDomain); @@ -656,10 +766,10 @@ public abstract class ClassLoader { * specified in the documentation for {@link #defineClass(String, byte[], * int, int)}. Before the class can be used it must be resolved. * - * <p>The rules about the first class defined in a package determining the set of - * certificates for the package, and the restrictions on class names are identical - * to those specified in the documentation for {@link #defineClass(String, byte[], - * int, int, ProtectionDomain)}. + * <p>The rules about the first class defined in a package determining the + * set of certificates for the package, and the restrictions on class names + * are identical to those specified in the documentation for {@link + * #defineClass(String, byte[], int, int, ProtectionDomain)}. * * <p> An invocation of this method of the form * <i>cl</i><tt>.defineClass(</tt><i>name</i><tt>,</tt> @@ -668,12 +778,13 @@ public abstract class ClassLoader { * * <blockquote><tt> * ...<br> - * byte[] temp = new byte[</tt><i>bBuffer</i><tt>.{@link java.nio.ByteBuffer#remaining - * remaining}()];<br> + * byte[] temp = new byte[</tt><i>bBuffer</i><tt>.{@link + * java.nio.ByteBuffer#remaining remaining}()];<br> * </tt><i>bBuffer</i><tt>.{@link java.nio.ByteBuffer#get(byte[]) * get}(temp);<br> * return {@link #defineClass(String, byte[], int, int, ProtectionDomain) - * </tt><i>cl</i><tt>.defineClass}(</tt><i>name</i><tt>, temp, 0, temp.length, </tt><i>pd</i><tt>);<br> + * </tt><i>cl</i><tt>.defineClass}(</tt><i>name</i><tt>, temp, 0, + * temp.length, </tt><i>pd</i><tt>);<br> * </tt></blockquote> * * @param name @@ -682,9 +793,9 @@ public abstract class ClassLoader { * * @param b * The bytes that make up the class data. The bytes from positions - * <tt>b.position()</tt> through <tt>b.position() + b.limit() -1 </tt> - * should have the format of a valid class file as defined by the <a - * href="http://java.sun.com/docs/books/vmspec/">Java Virtual + * <tt>b.position()</tt> through <tt>b.position() + b.limit() -1 + * </tt> should have the format of a valid class file as defined by + * the <a href="http://java.sun.com/docs/books/vmspec/">Java Virtual * Machine Specification</a>. * * @param protectionDomain @@ -738,11 +849,13 @@ public abstract class ClassLoader { String source = defineClassSourceLocation(protectionDomain); try { - c = defineClass2(name, b, b.position(), len, protectionDomain, source); + c = defineClass2(name, b, b.position(), len, protectionDomain, + source); } catch (ClassFormatError cfe) { byte[] tb = new byte[len]; b.get(tb); // get bytes out of byte buffer. - c = defineTransformedClass(name, tb, 0, len, protectionDomain, cfe, source); + c = defineTransformedClass(name, tb, 0, len, protectionDomain, cfe, + source); } postDefineClass(c, protectionDomain); @@ -769,33 +882,29 @@ public abstract class ClassLoader { return true; } - private synchronized void checkCerts(String name, CodeSource cs) { + private void checkCerts(String name, CodeSource cs) { int i = name.lastIndexOf('.'); String pname = (i == -1) ? "" : name.substring(0, i); - Certificate[] pcerts = package2certs.get(pname); - if (pcerts == null) { - // first class in this package gets to define which - // certificates must be the same for all other classes - // in this package - if (cs != null) { - pcerts = cs.getCertificates(); - } - if (pcerts == null) { - if (nocerts == null) - nocerts = new Certificate[0]; - pcerts = nocerts; - } - package2certs.put(pname, pcerts); - } else { - Certificate[] certs = null; - if (cs != null) { - certs = cs.getCertificates(); - } - if (!compareCerts(pcerts, certs)) { - throw new SecurityException("class \""+ name + - "\"'s signer information does not match signer information of other classes in the same package"); + Certificate[] certs = null; + if (cs != null) { + certs = cs.getCertificates(); + } + Certificate[] pcerts = null; + if (parallelLockMap == null) { + synchronized (this) { + pcerts = package2certs.get(pname); + if (pcerts == null) { + package2certs.put(pname, (certs == null? nocerts:certs)); + } } + } else { + pcerts = ((ConcurrentHashMap<String, Certificate[]>)package2certs). + putIfAbsent(pname, (certs == null? nocerts:certs)); + } + if (pcerts != null && !compareCerts(pcerts, certs)) { + throw new SecurityException("class \""+ name + + "\"'s signer information does not match signer information of other classes in the same package"); } } @@ -1075,6 +1184,47 @@ public abstract class ClassLoader { return java.util.Collections.emptyEnumeration(); } + // index 0: java.lang.ClassLoader.class + // index 1: the immediate caller of index 0. + // index 2: the immediate caller of index 1. + private static native Class<? extends ClassLoader> getCaller(int index); + + /** + * Registers the caller class loader as parallel capable. + * In order for the registration to succeed, all super classes + * of the caller class loader must also be registered as + * parallel capable when this method is called. </p> + * Note that once a class loader is registered as + * parallel capable, there is no way to change it back. + * In addition, registration should be done statically before + * any instance of the caller classloader being constructed. </p> + * + * @return true if the caller is successfully registered as + * parallel capable and false if otherwise. + * + * @since 1.7 + */ + protected static boolean registerAsParallelCapable() { + Class<? extends ClassLoader> caller = getCaller(1); + Class superCls = caller.getSuperclass(); + boolean result = false; + // Explicit synchronization needed for composite action + synchronized (parallelLoaders) { + if (!parallelLoaders.contains(caller)) { + if (parallelLoaders.contains(superCls)) { + // register the immediate caller as parallel capable + // if and only if all of its super classes are. + // Note: given current classloading sequence, if + // the immediate super class is parallel capable, + // all the super classes higher up must be too. + result = true; + parallelLoaders.add(caller); + } + } else result = true; + } + return result; + } + /** * Find a resource of the specified name from the search path used to load * classes. This method locates the resource through the system class @@ -1141,7 +1291,8 @@ public abstract class ClassLoader { private static Enumeration<URL> getBootstrapResources(String name) throws IOException { - final Enumeration<Resource> e = getBootstrapClassPath().getResources(name); + final Enumeration<Resource> e = + getBootstrapClassPath().getResources(name); return new Enumeration<URL> () { public URL nextElement() { return e.nextElement().getURL(); @@ -1377,9 +1528,11 @@ public abstract class ClassLoader { } // The class loader for the system + // @GuardedBy("ClassLoader.class") private static ClassLoader scl; // Set to true once the system class loader has been set + // @GuardedBy("ClassLoader.class") private static boolean sclSet; @@ -1592,19 +1745,6 @@ public abstract class ClassLoader { } } - // The "default" domain. Set as the default ProtectionDomain on newly - // created classes. - private ProtectionDomain defaultDomain = null; - - // Returns (and initializes) the default domain. - private synchronized ProtectionDomain getDefaultDomain() { - if (defaultDomain == null) { - CodeSource cs = new CodeSource(null, (Certificate[]) null); - defaultDomain = new ProtectionDomain(cs, null, this, null); - } - return defaultDomain; - } - // All native library names we've loaded. private static Vector<String> loadedLibraryNames = new Vector<String>(); @@ -1622,8 +1762,8 @@ public abstract class ClassLoader { = new Stack<NativeLibrary>(); // The paths searched for libraries - static private String usr_paths[]; - static private String sys_paths[]; + private static String usr_paths[]; + private static String sys_paths[]; private static String[] initializePath(String propname) { String ldpath = System.getProperty(propname, ""); @@ -1803,7 +1943,10 @@ public abstract class ClassLoader { // -- Assertion management -- + final Object assertionLock; + // The default toggle for assertion checking. + // @GuardedBy("assertionLock") private boolean defaultAssertionStatus = false; // Maps String packageName to Boolean package default assertion status Note @@ -1811,12 +1954,14 @@ public abstract class ClassLoader { // is null then we are delegating assertion status queries to the VM, i.e., // none of this ClassLoader's assertion status modification methods have // been invoked. + // @GuardedBy("assertionLock") private Map<String, Boolean> packageAssertionStatus = null; // Maps String fullyQualifiedClassName to Boolean assertionStatus If this // field is null then we are delegating assertion status queries to the VM, // i.e., none of this ClassLoader's assertion status modification methods // have been invoked. + // @GuardedBy("assertionLock") Map<String, Boolean> classAssertionStatus = null; /** @@ -1834,11 +1979,13 @@ public abstract class ClassLoader { * * @since 1.4 */ - public synchronized void setDefaultAssertionStatus(boolean enabled) { - if (classAssertionStatus == null) - initializeJavaAssertionMaps(); + public void setDefaultAssertionStatus(boolean enabled) { + synchronized (assertionLock) { + if (classAssertionStatus == null) + initializeJavaAssertionMaps(); - defaultAssertionStatus = enabled; + defaultAssertionStatus = enabled; + } } /** @@ -1878,13 +2025,14 @@ public abstract class ClassLoader { * * @since 1.4 */ - public synchronized void setPackageAssertionStatus(String packageName, - boolean enabled) - { - if (packageAssertionStatus == null) - initializeJavaAssertionMaps(); + public void setPackageAssertionStatus(String packageName, + boolean enabled) { + synchronized (assertionLock) { + if (packageAssertionStatus == null) + initializeJavaAssertionMaps(); - packageAssertionStatus.put(packageName, enabled); + packageAssertionStatus.put(packageName, enabled); + } } /** @@ -1909,13 +2057,13 @@ public abstract class ClassLoader { * * @since 1.4 */ - public synchronized void setClassAssertionStatus(String className, - boolean enabled) - { - if (classAssertionStatus == null) - initializeJavaAssertionMaps(); + public void setClassAssertionStatus(String className, boolean enabled) { + synchronized (assertionLock) { + if (classAssertionStatus == null) + initializeJavaAssertionMaps(); - classAssertionStatus.put(className, enabled); + classAssertionStatus.put(className, enabled); + } } /** @@ -1928,15 +2076,16 @@ public abstract class ClassLoader { * * @since 1.4 */ - public synchronized void clearAssertionStatus() { + public void clearAssertionStatus() { /* * Whether or not "Java assertion maps" are initialized, set * them to empty maps, effectively ignoring any present settings. */ - classAssertionStatus = new HashMap<String, Boolean>(); - packageAssertionStatus = new HashMap<String, Boolean>(); - - defaultAssertionStatus = false; + synchronized (assertionLock) { + classAssertionStatus = new HashMap<String, Boolean>(); + packageAssertionStatus = new HashMap<String, Boolean>(); + defaultAssertionStatus = false; + } } /** @@ -1961,39 +2110,40 @@ public abstract class ClassLoader { * * @since 1.4 */ - synchronized boolean desiredAssertionStatus(String className) { - Boolean result; - - // assert classAssertionStatus != null; - // assert packageAssertionStatus != null; + boolean desiredAssertionStatus(String className) { + synchronized (assertionLock) { + // assert classAssertionStatus != null; + // assert packageAssertionStatus != null; - // Check for a class entry - result = classAssertionStatus.get(className); - if (result != null) - return result.booleanValue(); - - // Check for most specific package entry - int dotIndex = className.lastIndexOf("."); - if (dotIndex < 0) { // default package - result = packageAssertionStatus.get(null); + // Check for a class entry + Boolean result = classAssertionStatus.get(className); if (result != null) return result.booleanValue(); - } - while(dotIndex > 0) { - className = className.substring(0, dotIndex); - result = packageAssertionStatus.get(className); - if (result != null) - return result.booleanValue(); - dotIndex = className.lastIndexOf(".", dotIndex-1); - } - // Return the classloader default - return defaultAssertionStatus; + // Check for most specific package entry + int dotIndex = className.lastIndexOf("."); + if (dotIndex < 0) { // default package + result = packageAssertionStatus.get(null); + if (result != null) + return result.booleanValue(); + } + while(dotIndex > 0) { + className = className.substring(0, dotIndex); + result = packageAssertionStatus.get(className); + if (result != null) + return result.booleanValue(); + dotIndex = className.lastIndexOf(".", dotIndex-1); + } + + // Return the classloader default + return defaultAssertionStatus; + } } // Set up the assertions with information provided by the VM. + // Note: Should only be called inside a synchronized block private void initializeJavaAssertionMaps() { - // assert Thread.holdsLock(this); + // assert Thread.holdsLock(assertionLock); classAssertionStatus = new HashMap<String, Boolean>(); packageAssertionStatus = new HashMap<String, Boolean>(); diff --git a/src/share/classes/java/lang/ConditionalSpecialCasing.java b/src/share/classes/java/lang/ConditionalSpecialCasing.java index d81e550eef5ffcb00a5b0ad30fc6c97cf86e0f92..0e66326069c770be473111d450d95b081c607153 100644 --- a/src/share/classes/java/lang/ConditionalSpecialCasing.java +++ b/src/share/classes/java/lang/ConditionalSpecialCasing.java @@ -74,6 +74,7 @@ final class ConditionalSpecialCasing { new Entry(0x00CC, new char[]{0x0069, 0x0307, 0x0300}, new char[]{0x00CC}, "lt", 0), // # LATIN CAPITAL LETTER I WITH GRAVE new Entry(0x00CD, new char[]{0x0069, 0x0307, 0x0301}, new char[]{0x00CD}, "lt", 0), // # LATIN CAPITAL LETTER I WITH ACUTE new Entry(0x0128, new char[]{0x0069, 0x0307, 0x0303}, new char[]{0x0128}, "lt", 0), // # LATIN CAPITAL LETTER I WITH TILDE + new Entry(0x0130, new char[]{0x0069, 0x0307}, new char[]{0x0130}, "lt", 0), // # LATIN CAPITAL LETTER I WITH DOT ABOVE //# ================================================================================ //# Turkish and Azeri @@ -84,7 +85,10 @@ final class ConditionalSpecialCasing { new Entry(0x0049, new char[]{0x0131}, new char[]{0x0049}, "tr", NOT_BEFORE_DOT), // # LATIN CAPITAL LETTER I new Entry(0x0049, new char[]{0x0131}, new char[]{0x0049}, "az", NOT_BEFORE_DOT), // # LATIN CAPITAL LETTER I new Entry(0x0069, new char[]{0x0069}, new char[]{0x0130}, "tr", 0), // # LATIN SMALL LETTER I - new Entry(0x0069, new char[]{0x0069}, new char[]{0x0130}, "az", 0) // # LATIN SMALL LETTER I + new Entry(0x0069, new char[]{0x0069}, new char[]{0x0130}, "az", 0), // # LATIN SMALL LETTER I + //# ================================================================================ + //# Other + new Entry(0x0130, new char[]{0x0069, 0x0307}, new char[]{0x0130}, "en", 0), // # LATIN CAPITALLETTER I WITH DOT ABOVE }; // A hash table that contains the above entries diff --git a/src/share/classes/java/lang/Integer.java b/src/share/classes/java/lang/Integer.java index f984f177275ae305e6c0d40a8964deef397e34d7..50863dd7e9fa646f6312ddb856b3aa1c56abee76 100644 --- a/src/share/classes/java/lang/Integer.java +++ b/src/share/classes/java/lang/Integer.java @@ -25,6 +25,8 @@ package java.lang; +import java.util.Properties; + /** * The {@code Integer} class wraps a value of the primitive type * {@code int} in an object. An object of type {@code Integer} @@ -442,6 +444,12 @@ public final class Integer extends Number implements Comparable<Integer> { public static int parseInt(String s, int radix) throws NumberFormatException { + /* + * WARNING: This method may be invoked early during VM initialization + * before IntegerCache is initialized. Care must be taken to not use + * the valueOf method. + */ + if (s == null) { throw new NumberFormatException("null"); } @@ -545,7 +553,7 @@ public final class Integer extends Number implements Comparable<Integer> { * does not contain a parsable {@code int}. */ public static Integer valueOf(String s, int radix) throws NumberFormatException { - return new Integer(parseInt(s,radix)); + return Integer.valueOf(parseInt(s,radix)); } /** @@ -570,20 +578,56 @@ public final class Integer extends Number implements Comparable<Integer> { * @exception NumberFormatException if the string cannot be parsed * as an integer. */ - public static Integer valueOf(String s) throws NumberFormatException - { - return new Integer(parseInt(s, 10)); + public static Integer valueOf(String s) throws NumberFormatException { + return Integer.valueOf(parseInt(s, 10)); } - private static class IntegerCache { - private IntegerCache(){} + /** + * Cache to support the object identity semantics of autoboxing for values between + * -128 and 127 (inclusive) as required by JLS. + * + * The cache is initialized on first usage. During VM initialization the + * getAndRemoveCacheProperties method may be used to get and remove any system + * properites that configure the cache size. At this time, the size of the + * cache may be controlled by the -XX:AutoBoxCacheMax=<size> option. + */ + + // value of java.lang.Integer.IntegerCache.high property (obtained during VM init) + private static String integerCacheHighPropValue; - static final Integer cache[] = new Integer[-(-128) + 127 + 1]; + static void getAndRemoveCacheProperties() { + if (!sun.misc.VM.isBooted()) { + Properties props = System.getProperties(); + integerCacheHighPropValue = + (String)props.remove("java.lang.Integer.IntegerCache.high"); + if (integerCacheHighPropValue != null) + System.setProperties(props); // remove from system props + } + } + + private static class IntegerCache { + static final int low = -128; + static final int high; + static final Integer cache[]; static { - for(int i = 0; i < cache.length; i++) - cache[i] = new Integer(i - 128); + // high value may be configured by property + int h = 127; + if (integerCacheHighPropValue != null) { + int i = parseInt(integerCacheHighPropValue); + i = Math.max(i, 127); + // Maximum array size is Integer.MAX_VALUE + h = Math.min(i, Integer.MAX_VALUE - (-low)); + } + high = h; + + cache = new Integer[(high - low) + 1]; + int j = low; + for(int k = 0; k < cache.length; k++) + cache[k] = new Integer(j++); } + + private IntegerCache() {} } /** @@ -599,10 +643,9 @@ public final class Integer extends Number implements Comparable<Integer> { * @since 1.5 */ public static Integer valueOf(int i) { - final int offset = 128; - if (i >= -128 && i <= 127) { // must cache - return IntegerCache.cache[i + offset]; - } + assert IntegerCache.high >= 127; + if (i >= IntegerCache.low && i <= IntegerCache.high) + return IntegerCache.cache[i + (-IntegerCache.low)]; return new Integer(i); } @@ -806,7 +849,7 @@ public final class Integer extends Number implements Comparable<Integer> { */ public static Integer getInteger(String nm, int val) { Integer result = getInteger(nm, null); - return (result == null) ? new Integer(val) : result; + return (result == null) ? Integer.valueOf(val) : result; } /** @@ -938,7 +981,7 @@ public final class Integer extends Number implements Comparable<Integer> { try { result = Integer.valueOf(nm.substring(index), radix); - result = negative ? new Integer(-result.intValue()) : result; + result = negative ? Integer.valueOf(-result.intValue()) : result; } catch (NumberFormatException e) { // If number is Integer.MIN_VALUE, we'll end up here. The next line // handles this case, and causes any genuine format error to be diff --git a/src/share/classes/java/lang/Long.java b/src/share/classes/java/lang/Long.java index 62400a9b967fe8ac6ead9ab8ecd1967c3e0845ac..c632d5df2d9b15af976ac8632744362478762d24 100644 --- a/src/share/classes/java/lang/Long.java +++ b/src/share/classes/java/lang/Long.java @@ -510,7 +510,7 @@ public final class Long extends Number implements Comparable<Long> { * contain a parsable {@code long}. */ public static Long valueOf(String s, int radix) throws NumberFormatException { - return new Long(parseLong(s, radix)); + return Long.valueOf(parseLong(s, radix)); } /** @@ -537,7 +537,7 @@ public final class Long extends Number implements Comparable<Long> { */ public static Long valueOf(String s) throws NumberFormatException { - return new Long(parseLong(s, 10)); + return Long.valueOf(parseLong(s, 10)); } private static class LongCache { @@ -650,7 +650,7 @@ public final class Long extends Number implements Comparable<Long> { try { result = Long.valueOf(nm.substring(index), radix); - result = negative ? new Long(-result.longValue()) : result; + result = negative ? Long.valueOf(-result.longValue()) : result; } catch (NumberFormatException e) { // If number is Long.MIN_VALUE, we'll end up here. The next line // handles this case, and causes any genuine format error to be @@ -869,7 +869,7 @@ public final class Long extends Number implements Comparable<Long> { */ public static Long getLong(String nm, long val) { Long result = Long.getLong(nm, null); - return (result == null) ? new Long(val) : result; + return (result == null) ? Long.valueOf(val) : result; } /** diff --git a/src/share/classes/java/lang/Shutdown.java b/src/share/classes/java/lang/Shutdown.java index 18e32d96f8e3a0db64eda0312976ff087ec9b105..b77b45056a73da3ddf4ccf2ae840101b56ae4019 100644 --- a/src/share/classes/java/lang/Shutdown.java +++ b/src/share/classes/java/lang/Shutdown.java @@ -25,8 +25,6 @@ package java.lang; -import java.util.ArrayList; - /** * Package-private utility class containing data structures and logic @@ -47,8 +45,13 @@ class Shutdown { /* Should we run all finalizers upon exit? */ private static boolean runFinalizersOnExit = false; - /* The set of registered, wrapped hooks, or null if there aren't any */ - private static ArrayList<Runnable> hooks = new ArrayList<Runnable>(); + // The system shutdown hooks are registered with a predefined slot. + // The list of shutdown hooks is as follows: + // (0) Console restore hook + // (1) Application hooks + // (2) DeleteOnExit hook + private static final int MAX_SYSTEM_HOOKS = 10; + private static final Runnable[] hooks = new Runnable[MAX_SYSTEM_HOOKS]; /* The preceding static fields are protected by this lock */ private static class Lock { }; @@ -68,33 +71,18 @@ class Shutdown { /* Add a new shutdown hook. Checks the shutdown state and the hook itself, * but does not do any security checks. */ - static void add(Runnable hook) { + static void add(int slot, Runnable hook) { synchronized (lock) { if (state > RUNNING) throw new IllegalStateException("Shutdown in progress"); - hooks.add(hook); - } - } + if (hooks[slot] != null) + throw new InternalError("Shutdown hook at slot " + slot + " already registered"); - - /* Remove a previously-registered hook. Like the add method, this method - * does not do any security checks. - */ - static boolean remove(Runnable hook) { - synchronized (lock) { - if (state > RUNNING) - throw new IllegalStateException("Shutdown in progress"); - if (hook == null) throw new NullPointerException(); - if (hooks == null) { - return false; - } else { - return hooks.remove(hook); - } + hooks[slot] = hook; } } - /* Run all registered shutdown hooks */ private static void runHooks() { @@ -103,7 +91,7 @@ class Shutdown { */ for (Runnable hook : hooks) { try { - hook.run(); + if (hook != null) hook.run(); } catch(Throwable t) { if (t instanceof ThreadDeath) { ThreadDeath td = (ThreadDeath)t; diff --git a/src/share/classes/java/lang/String.java b/src/share/classes/java/lang/String.java index 28d96de741b0ce008c84b7ed3f88fbc474002e58..316da645f3c8dfb16eab5681c957b2aa92a26bd2 100644 --- a/src/share/classes/java/lang/String.java +++ b/src/share/classes/java/lang/String.java @@ -2451,14 +2451,21 @@ public final class String } if (localeDependent || srcChar == '\u03A3') { // GREEK CAPITAL LETTER SIGMA lowerChar = ConditionalSpecialCasing.toLowerCaseEx(this, i, locale); + } else if (srcChar == '\u0130') { // LATIN CAPITAL LETTER I DOT + lowerChar = Character.ERROR; } else { lowerChar = Character.toLowerCase(srcChar); } if ((lowerChar == Character.ERROR) || (lowerChar >= Character.MIN_SUPPLEMENTARY_CODE_POINT)) { if (lowerChar == Character.ERROR) { - lowerCharArray = - ConditionalSpecialCasing.toLowerCaseCharArray(this, i, locale); + if (!localeDependent && srcChar == '\u0130') { + lowerCharArray = + ConditionalSpecialCasing.toLowerCaseCharArray(this, i, Locale.ENGLISH); + } else { + lowerCharArray = + ConditionalSpecialCasing.toLowerCaseCharArray(this, i, locale); + } } else if (srcCount == 2) { resultOffset += Character.toChars(lowerChar, result, i + resultOffset) - srcCount; continue; diff --git a/src/share/classes/java/lang/StringCoding.java b/src/share/classes/java/lang/StringCoding.java index 833fdf5f603ba8801108f84f6cf16f82d09930b6..885db317af5fede1f50758de3f68e9c51d2080c6 100644 --- a/src/share/classes/java/lang/StringCoding.java +++ b/src/share/classes/java/lang/StringCoding.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2008 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. * * This code is free software; you can redistribute it and/or modify it @@ -25,13 +25,10 @@ package java.lang; -import java.io.CharConversionException; import java.io.UnsupportedEncodingException; import java.lang.ref.SoftReference; import java.nio.ByteBuffer; import java.nio.CharBuffer; -import java.nio.BufferOverflowException; -import java.nio.BufferUnderflowException; import java.nio.charset.Charset; import java.nio.charset.CharsetDecoder; import java.nio.charset.CharsetEncoder; @@ -39,11 +36,12 @@ import java.nio.charset.CharacterCodingException; import java.nio.charset.CoderResult; import java.nio.charset.CodingErrorAction; import java.nio.charset.IllegalCharsetNameException; -import java.nio.charset.MalformedInputException; import java.nio.charset.UnsupportedCharsetException; import java.util.Arrays; import sun.misc.MessageUtils; import sun.nio.cs.HistoricallyNamedCharset; +import sun.nio.cs.ArrayDecoder; +import sun.nio.cs.ArrayEncoder; /** * Utility class for string encoding and decoding. @@ -74,10 +72,8 @@ class StringCoding { // Trim the given byte array to the given length // - private static byte[] safeTrim(byte[] ba, int len, Charset cs) { - if (len == ba.length - && (System.getSecurityManager() == null - || cs.getClass().getClassLoader0() == null)) + private static byte[] safeTrim(byte[] ba, int len, Charset cs, boolean isTrusted) { + if (len == ba.length && (isTrusted || System.getSecurityManager() == null)) return ba; else return Arrays.copyOf(ba, len); @@ -85,10 +81,9 @@ class StringCoding { // Trim the given char array to the given length // - private static char[] safeTrim(char[] ca, int len, Charset cs) { - if (len == ca.length - && (System.getSecurityManager() == null - || cs.getClass().getClassLoader0() == null)) + private static char[] safeTrim(char[] ca, int len, + Charset cs, boolean isTrusted) { + if (len == ca.length && (isTrusted || System.getSecurityManager() == null)) return ca; else return Arrays.copyOf(ca, len); @@ -128,6 +123,7 @@ class StringCoding { private final String requestedCharsetName; private final Charset cs; private final CharsetDecoder cd; + private final boolean isTrusted; private StringDecoder(Charset cs, String rcn) { this.requestedCharsetName = rcn; @@ -135,6 +131,7 @@ class StringCoding { this.cd = cs.newDecoder() .onMalformedInput(CodingErrorAction.REPLACE) .onUnmappableCharacter(CodingErrorAction.REPLACE); + this.isTrusted = (cs.getClass().getClassLoader0() == null); } String charsetName() { @@ -152,24 +149,28 @@ class StringCoding { char[] ca = new char[en]; if (len == 0) return ca; - cd.reset(); - ByteBuffer bb = ByteBuffer.wrap(ba, off, len); - CharBuffer cb = CharBuffer.wrap(ca); - try { - CoderResult cr = cd.decode(bb, cb, true); - if (!cr.isUnderflow()) - cr.throwException(); - cr = cd.flush(cb); - if (!cr.isUnderflow()) - cr.throwException(); - } catch (CharacterCodingException x) { - // Substitution is always enabled, - // so this shouldn't happen - throw new Error(x); + if (cd instanceof ArrayDecoder) { + int clen = ((ArrayDecoder)cd).decode(ba, off, len, ca); + return safeTrim(ca, clen, cs, isTrusted); + } else { + cd.reset(); + ByteBuffer bb = ByteBuffer.wrap(ba, off, len); + CharBuffer cb = CharBuffer.wrap(ca); + try { + CoderResult cr = cd.decode(bb, cb, true); + if (!cr.isUnderflow()) + cr.throwException(); + cr = cd.flush(cb); + if (!cr.isUnderflow()) + cr.throwException(); + } catch (CharacterCodingException x) { + // Substitution is always enabled, + // so this shouldn't happen + throw new Error(x); + } + return safeTrim(ca, cb.position(), cs, isTrusted); } - return safeTrim(ca, cb.position(), cs); } - } static char[] decode(String charsetName, byte[] ba, int off, int len) @@ -193,8 +194,57 @@ class StringCoding { } static char[] decode(Charset cs, byte[] ba, int off, int len) { - StringDecoder sd = new StringDecoder(cs, cs.name()); - return sd.decode(Arrays.copyOfRange(ba, off, off + len), 0, len); + // (1)We never cache the "external" cs, the only benefit of creating + // an additional StringDe/Encoder object to wrap it is to share the + // de/encode() method. These SD/E objects are short-lifed, the young-gen + // gc should be able to take care of them well. But the best approash + // is still not to generate them if not really necessary. + // (2)The defensive copy of the input byte/char[] has a big performance + // impact, as well as the outgoing result byte/char[]. Need to do the + // optimization check of (sm==null && classLoader0==null) for both. + // (3)getClass().getClassLoader0() is expensive + // (4)There might be a timing gap in isTrusted setting. getClassLoader0() + // is only chcked (and then isTrusted gets set) when (SM==null). It is + // possible that the SM==null for now but then SM is NOT null later + // when safeTrim() is invoked...the "safe" way to do is to redundant + // check (... && (isTrusted || SM == null || getClassLoader0())) in trim + // but it then can be argued that the SM is null when the opertaion + // is started... + CharsetDecoder cd = cs.newDecoder(); + int en = scale(len, cd.maxCharsPerByte()); + char[] ca = new char[en]; + if (len == 0) + return ca; + boolean isTrusted = false; + if (System.getSecurityManager() != null) { + if (!(isTrusted = (cs.getClass().getClassLoader0() == null))) { + ba = Arrays.copyOfRange(ba, off, off + len); + off = 0; + } + } + if (cd instanceof ArrayDecoder) { + int clen = ((ArrayDecoder)cd).decode(ba, off, len, ca); + return safeTrim(ca, clen, cs, isTrusted); + } else { + cd.onMalformedInput(CodingErrorAction.REPLACE) + .onUnmappableCharacter(CodingErrorAction.REPLACE) + .reset(); + ByteBuffer bb = ByteBuffer.wrap(ba, off, len); + CharBuffer cb = CharBuffer.wrap(ca); + try { + CoderResult cr = cd.decode(bb, cb, true); + if (!cr.isUnderflow()) + cr.throwException(); + cr = cd.flush(cb); + if (!cr.isUnderflow()) + cr.throwException(); + } catch (CharacterCodingException x) { + // Substitution is always enabled, + // so this shouldn't happen + throw new Error(x); + } + return safeTrim(ca, cb.position(), cs, isTrusted); + } } static char[] decode(byte[] ba, int off, int len) { @@ -218,14 +268,12 @@ class StringCoding { } } - - - // -- Encoding -- private static class StringEncoder { private Charset cs; private CharsetEncoder ce; private final String requestedCharsetName; + private final boolean isTrusted; private StringEncoder(Charset cs, String rcn) { this.requestedCharsetName = rcn; @@ -233,6 +281,7 @@ class StringCoding { this.ce = cs.newEncoder() .onMalformedInput(CodingErrorAction.REPLACE) .onUnmappableCharacter(CodingErrorAction.REPLACE); + this.isTrusted = (cs.getClass().getClassLoader0() == null); } String charsetName() { @@ -250,23 +299,27 @@ class StringCoding { byte[] ba = new byte[en]; if (len == 0) return ba; - - ce.reset(); - ByteBuffer bb = ByteBuffer.wrap(ba); - CharBuffer cb = CharBuffer.wrap(ca, off, len); - try { - CoderResult cr = ce.encode(cb, bb, true); - if (!cr.isUnderflow()) - cr.throwException(); - cr = ce.flush(bb); - if (!cr.isUnderflow()) - cr.throwException(); - } catch (CharacterCodingException x) { - // Substitution is always enabled, - // so this shouldn't happen - throw new Error(x); + if (ce instanceof ArrayEncoder) { + int blen = ((ArrayEncoder)ce).encode(ca, off, len, ba); + return safeTrim(ba, blen, cs, isTrusted); + } else { + ce.reset(); + ByteBuffer bb = ByteBuffer.wrap(ba); + CharBuffer cb = CharBuffer.wrap(ca, off, len); + try { + CoderResult cr = ce.encode(cb, bb, true); + if (!cr.isUnderflow()) + cr.throwException(); + cr = ce.flush(bb); + if (!cr.isUnderflow()) + cr.throwException(); + } catch (CharacterCodingException x) { + // Substitution is always enabled, + // so this shouldn't happen + throw new Error(x); + } + return safeTrim(ba, bb.position(), cs, isTrusted); } - return safeTrim(ba, bb.position(), cs); } } @@ -291,8 +344,39 @@ class StringCoding { } static byte[] encode(Charset cs, char[] ca, int off, int len) { - StringEncoder se = new StringEncoder(cs, cs.name()); - return se.encode(Arrays.copyOfRange(ca, off, off + len), 0, len); + CharsetEncoder ce = cs.newEncoder(); + int en = scale(len, ce.maxBytesPerChar()); + byte[] ba = new byte[en]; + if (len == 0) + return ba; + boolean isTrusted = false; + if (System.getSecurityManager() != null) { + if (!(isTrusted = (cs.getClass().getClassLoader0() == null))) { + ca = Arrays.copyOfRange(ca, off, off + len); + off = 0; + } + } + if (ce instanceof ArrayEncoder) { + int blen = ((ArrayEncoder)ce).encode(ca, off, len, ba); + return safeTrim(ba, blen, cs, isTrusted); + } else { + ce.onMalformedInput(CodingErrorAction.REPLACE) + .onUnmappableCharacter(CodingErrorAction.REPLACE) + .reset(); + ByteBuffer bb = ByteBuffer.wrap(ba); + CharBuffer cb = CharBuffer.wrap(ca, off, len); + try { + CoderResult cr = ce.encode(cb, bb, true); + if (!cr.isUnderflow()) + cr.throwException(); + cr = ce.flush(bb); + if (!cr.isUnderflow()) + cr.throwException(); + } catch (CharacterCodingException x) { + throw new Error(x); + } + return safeTrim(ba, bb.position(), cs, isTrusted); + } } static byte[] encode(char[] ca, int off, int len) { diff --git a/src/share/classes/java/lang/System.java b/src/share/classes/java/lang/System.java index a81bfa7015286ff1f4e868a1380a4a77bafe79a8..6c539b28e1c8ade97eb264fe87938854633df703 100644 --- a/src/share/classes/java/lang/System.java +++ b/src/share/classes/java/lang/System.java @@ -34,7 +34,6 @@ import java.security.AllPermission; import java.nio.channels.Channel; import java.nio.channels.spi.SelectorProvider; import sun.nio.ch.Interruptible; -import sun.net.InetAddressCachePolicy; import sun.reflect.Reflection; import sun.security.util.SecurityConstants; import sun.reflect.annotation.AnnotationType; @@ -310,7 +309,6 @@ public final class System { } security = s; - InetAddressCachePolicy.setIfNotSet(InetAddressCachePolicy.FOREVER); } /** @@ -1107,6 +1105,13 @@ public final class System { props = new Properties(); initProperties(props); sun.misc.Version.init(); + + // Gets and removes system properties that configure the Integer + // cache used to support the object identity semantics of autoboxing. + // At this time, the size of the cache may be controlled by the + // -XX:AutoBoxCacheMax=<size> option. + Integer.getAndRemoveCacheProperties(); + FileInputStream fdIn = new FileInputStream(FileDescriptor.in); FileOutputStream fdOut = new FileOutputStream(FileDescriptor.out); FileOutputStream fdErr = new FileOutputStream(FileDescriptor.err); @@ -1121,14 +1126,6 @@ public final class System { // Setup Java signal handlers for HUP, TERM, and INT (where available). Terminator.setup(); - // The order in with the hooks are added here is important as it - // determines the order in which they are run. - // (1)Console restore hook needs to be called first. - // (2)Application hooks must be run before calling deleteOnExitHook. - Shutdown.add(sun.misc.SharedSecrets.getJavaIOAccess().consoleRestoreHook()); - Shutdown.add(ApplicationShutdownHooks.hook()); - Shutdown.add(sun.misc.SharedSecrets.getJavaIODeleteOnExitAccess()); - // Initialize any miscellenous operating system settings that need to be // set for the class libraries. Currently this is no-op everywhere except // for Windows where the process-wide error mode is set before the java.io @@ -1174,6 +1171,9 @@ public final class System { public void blockedOn(Thread t, Interruptible b) { t.blockedOn(b); } + public void registerShutdownHook(int slot, Runnable r) { + Shutdown.add(slot, r); + } }); } diff --git a/src/share/classes/java/lang/Thread.java b/src/share/classes/java/lang/Thread.java index 60300ebc911b8eceaa96911ff8d180c8cbf9e3d1..d5d163bd6e3ba06b4a23a1251b5e670fac9ff711 100644 --- a/src/share/classes/java/lang/Thread.java +++ b/src/share/classes/java/lang/Thread.java @@ -1,5 +1,5 @@ /* - * Copyright 1994-2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 1994-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 @@ -25,13 +25,17 @@ package java.lang; +import java.lang.ref.Reference; +import java.lang.ref.ReferenceQueue; +import java.lang.ref.WeakReference; import java.security.AccessController; import java.security.AccessControlContext; import java.security.PrivilegedAction; import java.util.Map; import java.util.HashMap; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; import java.util.concurrent.locks.LockSupport; -import sun.misc.SoftCache; import sun.nio.ch.Interruptible; import sun.security.util.SecurityConstants; @@ -1640,8 +1644,17 @@ class Thread implements Runnable { new RuntimePermission("enableContextClassLoaderOverride"); /** cache of subclass security audit results */ - private static final SoftCache subclassAudits = new SoftCache(10); - + /* Replace with ConcurrentReferenceHashMap when/if it appears in a future + * release */ + private static class Caches { + /** cache of subclass security audit results */ + static final ConcurrentMap<WeakClassKey,Boolean> subclassAudits = + new ConcurrentHashMap<WeakClassKey,Boolean>(); + + /** queue for WeakReferences to audited subclasses */ + static final ReferenceQueue<Class<?>> subclassAuditsQueue = + new ReferenceQueue<Class<?>>(); + } /** * Verifies that this (possibly subclass) instance can be constructed @@ -1652,19 +1665,15 @@ class Thread implements Runnable { private static boolean isCCLOverridden(Class cl) { if (cl == Thread.class) return false; - Boolean result = null; - synchronized (subclassAudits) { - result = (Boolean) subclassAudits.get(cl); - if (result == null) { - /* - * Note: only new Boolean instances (i.e., not Boolean.TRUE or - * Boolean.FALSE) must be used as cache values, otherwise cache - * entry will pin associated class. - */ - result = new Boolean(auditSubclass(cl)); - subclassAudits.put(cl, result); - } + + processQueue(Caches.subclassAuditsQueue, Caches.subclassAudits); + WeakClassKey key = new WeakClassKey(cl, Caches.subclassAuditsQueue); + Boolean result = Caches.subclassAudits.get(key); + if (result == null) { + result = Boolean.valueOf(auditSubclass(cl)); + Caches.subclassAudits.putIfAbsent(key, result); } + return result.booleanValue(); } @@ -1967,6 +1976,68 @@ class Thread implements Runnable { getUncaughtExceptionHandler().uncaughtException(this, e); } + /** + * Removes from the specified map any keys that have been enqueued + * on the specified reference queue. + */ + static void processQueue(ReferenceQueue<Class<?>> queue, + ConcurrentMap<? extends + WeakReference<Class<?>>, ?> map) + { + Reference<? extends Class<?>> ref; + while((ref = queue.poll()) != null) { + map.remove(ref); + } + } + + /** + * Weak key for Class objects. + **/ + static class WeakClassKey extends WeakReference<Class<?>> { + /** + * saved value of the referent's identity hash code, to maintain + * a consistent hash code after the referent has been cleared + */ + private final int hash; + + /** + * Create a new WeakClassKey to the given object, registered + * with a queue. + */ + WeakClassKey(Class<?> cl, ReferenceQueue<Class<?>> refQueue) { + super(cl, refQueue); + hash = System.identityHashCode(cl); + } + + /** + * Returns the identity hash code of the original referent. + */ + @Override + public int hashCode() { + return hash; + } + + /** + * Returns true if the given object is this identical + * WeakClassKey instance, or, if this object's referent has not + * been cleared, if the given object is another WeakClassKey + * instance with the identical non-null referent as this one. + */ + @Override + public boolean equals(Object obj) { + if (obj == this) + return true; + + if (obj instanceof WeakClassKey) { + Object referent = get(); + return (referent != null) && + (referent == ((WeakClassKey) obj).get()); + } else { + return false; + } + } + } + /* Some private helper methods */ private native void setPriority0(int newPriority); private native void stop0(Object o); diff --git a/src/share/classes/java/lang/ref/ReferenceQueue.java b/src/share/classes/java/lang/ref/ReferenceQueue.java index 872ee14f8e27fc7a15f1c869b608af4a03cb2b15..9882844e5a8323d2bb14641192e1dd461ee53720 100644 --- a/src/share/classes/java/lang/ref/ReferenceQueue.java +++ b/src/share/classes/java/lang/ref/ReferenceQueue.java @@ -51,7 +51,7 @@ public class ReferenceQueue<T> { static private class Lock { }; private Lock lock = new Lock(); - private Reference<? extends T> head = null; + private volatile Reference<? extends T> head = null; private long queueLength = 0; boolean enqueue(Reference<? extends T> r) { /* Called only by Reference class */ @@ -95,6 +95,8 @@ public class ReferenceQueue<T> { * otherwise <code>null</code> */ public Reference<? extends T> poll() { + if (head == null) + return null; synchronized (lock) { return reallyPoll(); } diff --git a/src/share/classes/java/lang/ref/SoftReference.java b/src/share/classes/java/lang/ref/SoftReference.java index 35c6710d18e457ab4cabe0245acb7464707bf956..4a6428efaf487885074825d436828daf85a1876b 100644 --- a/src/share/classes/java/lang/ref/SoftReference.java +++ b/src/share/classes/java/lang/ref/SoftReference.java @@ -63,11 +63,13 @@ package java.lang.ref; public class SoftReference<T> extends Reference<T> { - /* Timestamp clock, updated by the garbage collector + /** + * Timestamp clock, updated by the garbage collector */ static private long clock; - /* Timestamp updated by each invocation of the get method. The VM may use + /** + * Timestamp updated by each invocation of the get method. The VM may use * this field when selecting soft references to be cleared, but it is not * required to do so. */ @@ -108,7 +110,8 @@ public class SoftReference<T> extends Reference<T> { */ public T get() { T o = super.get(); - if (o != null) this.timestamp = clock; + if (o != null && this.timestamp != clock) + this.timestamp = clock; return o; } diff --git a/src/share/classes/java/lang/reflect/Constructor.java b/src/share/classes/java/lang/reflect/Constructor.java index 49d2478bd90b16a89faf83a12eab5d17cac59ede..0c101ccacb8596bad591d09fd5fda9a4beaa540f 100644 --- a/src/share/classes/java/lang/reflect/Constructor.java +++ b/src/share/classes/java/lang/reflect/Constructor.java @@ -626,13 +626,11 @@ public final return (T) declaredAnnotations().get(annotationClass); } - private static final Annotation[] EMPTY_ANNOTATION_ARRAY=new Annotation[0]; - /** * @since 1.5 */ public Annotation[] getDeclaredAnnotations() { - return declaredAnnotations().values().toArray(EMPTY_ANNOTATION_ARRAY); + return AnnotationParser.toArray(declaredAnnotations()); } private transient Map<Class, Annotation> declaredAnnotations; diff --git a/src/share/classes/java/lang/reflect/Field.java b/src/share/classes/java/lang/reflect/Field.java index 33b6fc61ad86db712d51f2df9c2ea5991a5aa1ce..5a3e9e9ab7dccd6b58483641af5b3f63375857ce 100644 --- a/src/share/classes/java/lang/reflect/Field.java +++ b/src/share/classes/java/lang/reflect/Field.java @@ -1018,13 +1018,11 @@ class Field extends AccessibleObject implements Member { return (T) declaredAnnotations().get(annotationClass); } - private static final Annotation[] EMPTY_ANNOTATION_ARRAY=new Annotation[0]; - /** * @since 1.5 */ public Annotation[] getDeclaredAnnotations() { - return declaredAnnotations().values().toArray(EMPTY_ANNOTATION_ARRAY); + return AnnotationParser.toArray(declaredAnnotations()); } private transient Map<Class, Annotation> declaredAnnotations; diff --git a/src/share/classes/java/lang/reflect/Method.java b/src/share/classes/java/lang/reflect/Method.java index 97947468f086f3f57e0161c5728f5170d9570595..c638869cd38e81b8eeafde35d60d1cfa955e9349 100644 --- a/src/share/classes/java/lang/reflect/Method.java +++ b/src/share/classes/java/lang/reflect/Method.java @@ -705,13 +705,11 @@ public final return (T) declaredAnnotations().get(annotationClass); } - private static final Annotation[] EMPTY_ANNOTATION_ARRAY=new Annotation[0]; - /** * @since 1.5 */ public Annotation[] getDeclaredAnnotations() { - return declaredAnnotations().values().toArray(EMPTY_ANNOTATION_ARRAY); + return AnnotationParser.toArray(declaredAnnotations()); } private transient Map<Class, Annotation> declaredAnnotations; diff --git a/src/share/classes/java/net/AbstractPlainSocketImpl.java b/src/share/classes/java/net/AbstractPlainSocketImpl.java index 597783bf730628fcf39cac13680ade28120e4e82..18af8d6db64b67b3cc05e409c2383f8bc1976d12 100644 --- a/src/share/classes/java/net/AbstractPlainSocketImpl.java +++ b/src/share/classes/java/net/AbstractPlainSocketImpl.java @@ -33,6 +33,7 @@ import java.io.FileDescriptor; import java.io.ByteArrayOutputStream; import sun.net.ConnectionResetException; +import sun.net.NetHooks; /** * Default Socket Implementation. This implementation does @@ -304,6 +305,11 @@ abstract class AbstractPlainSocketImpl extends SocketImpl */ synchronized void doConnect(InetAddress address, int port, int timeout) throws IOException { + synchronized (fdLock) { + if (!closePending && (socket == null || !socket.isBound())) { + NetHooks.beforeTcpConnect(fd, address, port); + } + } try { FileDescriptor fd = acquireFD(); try { @@ -339,6 +345,11 @@ abstract class AbstractPlainSocketImpl extends SocketImpl protected synchronized void bind(InetAddress address, int lport) throws IOException { + synchronized (fdLock) { + if (!closePending && (socket == null || !socket.isBound())) { + NetHooks.beforeTcpBind(fd, address, lport); + } + } socketBind(address, lport); if (socket != null) socket.setBound(); diff --git a/src/share/classes/java/net/SocketPermission.java b/src/share/classes/java/net/SocketPermission.java index 9f948bed6a2ead8c4642d03dcbc16c26ea67d6a1..4c63ab9afbabb49b4d27dbe1f837bffea2f601de 100644 --- a/src/share/classes/java/net/SocketPermission.java +++ b/src/share/classes/java/net/SocketPermission.java @@ -113,7 +113,6 @@ import sun.security.util.SecurityConstants; * <p>Similarly, if the following permission: * * <pre> - * p1 = new SocketPermission("puffin.eng.sun.com:7777", "connect,accept"); * p2 = new SocketPermission("localhost:1024-", "accept,connect,listen"); * </pre> * diff --git a/src/share/classes/java/net/StandardProtocolFamily.java b/src/share/classes/java/net/StandardProtocolFamily.java index 7c11b32f59fc61f741978eca32191a6cd1fa952b..d4b03ed887fb30f119d8441d62d69b4d1f0befa2 100644 --- a/src/share/classes/java/net/StandardProtocolFamily.java +++ b/src/share/classes/java/net/StandardProtocolFamily.java @@ -1,5 +1,5 @@ /* - * Copyright 2007-2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2007-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 @@ -26,7 +26,7 @@ package java.net; /** - * Defines the standard family of communication protocols. + * Defines the standard families of communication protocols. * * @since 1.7 */ diff --git a/src/share/classes/java/net/StandardSocketOption.java b/src/share/classes/java/net/StandardSocketOption.java index 405038cc1c21cd213e1565949d15fd2eecf73659..dba8ff22d90a3263a4136383b0f237a65140909d 100644 --- a/src/share/classes/java/net/StandardSocketOption.java +++ b/src/share/classes/java/net/StandardSocketOption.java @@ -1,5 +1,5 @@ /* - * Copyright 2007-2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2007-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 @@ -59,6 +59,7 @@ public final class StandardSocketOption { * * @see <a href="http://www.ietf.org/rfc/rfc919.txt">RFC 929: * Broadcasting Internet Datagrams</a> + * @see DatagramSocket#setBroadcast */ public static final SocketOption<Boolean> SO_BROADCAST = new StdSocketOption<Boolean>("SO_BROADCAST", Boolean.class); @@ -78,6 +79,7 @@ public final class StandardSocketOption { * * @see <a href="http://www.ietf.org/rfc/rfc1122.txt">RFC 1122 * Requirements for Internet Hosts -- Communication Layers</a> + * @see Socket#setKeepAlive */ public static final SocketOption<Boolean> SO_KEEPALIVE = new StdSocketOption<Boolean>("SO_KEEPALIVE", Boolean.class); @@ -107,6 +109,8 @@ public final class StandardSocketOption { * socket is bound or connected. Whether an implementation allows the * socket send buffer to be changed after the socket is bound is system * dependent. + * + * @see Socket#setSendBufferSize */ public static final SocketOption<Integer> SO_SNDBUF = new StdSocketOption<Integer>("SO_SNDBUF", Integer.class); @@ -145,6 +149,8 @@ public final class StandardSocketOption { * * @see <a href="http://www.ietf.org/rfc/rfc1323.txt">RFC 1323: TCP * Extensions for High Performance</a> + * @see Socket#setReceiveBufferSize + * @see ServerSocket#setReceiveBufferSize */ public static final SocketOption<Integer> SO_RCVBUF = new StdSocketOption<Integer>("SO_RCVBUF", Integer.class); @@ -175,6 +181,7 @@ public final class StandardSocketOption { * * @see <a href="http://www.ietf.org/rfc/rfc793.txt">RFC 793: Transmission * Control Protocol</a> + * @see ServerSocket#setReuseAddress */ public static final SocketOption<Boolean> SO_REUSEADDR = new StdSocketOption<Boolean>("SO_REUSEADDR", Boolean.class); @@ -205,6 +212,8 @@ public final class StandardSocketOption { * is system dependent. Setting the linger interval to a value that is * greater than its maximum value causes the linger interval to be set to * its maximum value. + * + * @see Socket#setSoLinger */ public static final SocketOption<Integer> SO_LINGER = new StdSocketOption<Integer>("SO_LINGER", Integer.class); @@ -215,15 +224,15 @@ public final class StandardSocketOption { /** * The Type of Service (ToS) octet in the Internet Protocol (IP) header. * - * <p> The value of this socket option is an {@code Integer}, the least - * significant 8 bits of which represents the value of the ToS octet in IP - * packets sent by sockets to an {@link StandardProtocolFamily#INET IPv4} - * socket. The interpretation of the ToS octet is network specific and - * is not defined by this class. Further information on the ToS octet can be - * found in <a href="http://www.ietf.org/rfc/rfc1349.txt">RFC 1349</a> - * and <a href="http://www.ietf.org/rfc/rfc2474.txt">RFC 2474</a>. The - * value of the socket option is a <em>hint</em>. An implementation may - * ignore the value, or ignore specific values. + * <p> The value of this socket option is an {@code Integer} representing + * the value of the ToS octet in IP packets sent by sockets to an {@link + * StandardProtocolFamily#INET IPv4} socket. The interpretation of the ToS + * octet is network specific and is not defined by this class. Further + * information on the ToS octet can be found in <a + * href="http://www.ietf.org/rfc/rfc1349.txt">RFC 1349</a> and <a + * href="http://www.ietf.org/rfc/rfc2474.txt">RFC 2474</a>. The value + * of the socket option is a <em>hint</em>. An implementation may ignore the + * value, or ignore specific values. * * <p> The initial/default value of the TOS field in the ToS octet is * implementation specific but will typically be {@code 0}. For @@ -235,6 +244,8 @@ public final class StandardSocketOption { * <p> The behavior of this socket option on a stream-oriented socket, or an * {@link StandardProtocolFamily#INET6 IPv6} socket, is not defined in this * release. + * + * @see DatagramSocket#setTrafficClass */ public static final SocketOption<Integer> IP_TOS = new StdSocketOption<Integer>("IP_TOS", Integer.class); @@ -257,6 +268,7 @@ public final class StandardSocketOption { * is system dependent. * * @see java.nio.channels.MulticastChannel + * @see MulticastSocket#setInterface */ public static final SocketOption<NetworkInterface> IP_MULTICAST_IF = new StdSocketOption<NetworkInterface>("IP_MULTICAST_IF", NetworkInterface.class); @@ -283,6 +295,7 @@ public final class StandardSocketOption { * prior to binding the socket is system dependent. * * @see java.nio.channels.MulticastChannel + * @see MulticastSocket#setTimeToLive */ public static final SocketOption<Integer> IP_MULTICAST_TTL = new StdSocketOption<Integer>("IP_MULTICAST_TTL", Integer.class); @@ -307,6 +320,7 @@ public final class StandardSocketOption { * binding the socket is system dependent. * * @see java.nio.channels.MulticastChannel + * @see MulticastSocket#setLoopbackMode */ public static final SocketOption<Boolean> IP_MULTICAST_LOOP = new StdSocketOption<Boolean>("IP_MULTICAST_LOOP", Boolean.class); @@ -328,11 +342,12 @@ public final class StandardSocketOption { * coalescing impacts performance. The socket option may be enabled at any * time. In other words, the Nagle Algorithm can be disabled. Once the option * is enabled, it is system dependent whether it can be subsequently - * disabled. In that case, invoking the {@code setOption} method to disable - * the option has no effect. + * disabled. If it cannot, then invoking the {@code setOption} method to + * disable the option has no effect. * * @see <a href="http://www.ietf.org/rfc/rfc1122.txt">RFC 1122: * Requirements for Internet Hosts -- Communication Layers</a> + * @see Socket#setTcpNoDelay */ public static final SocketOption<Boolean> TCP_NODELAY = new StdSocketOption<Boolean>("TCP_NODELAY", Boolean.class); diff --git a/src/share/classes/java/net/URLClassLoader.java b/src/share/classes/java/net/URLClassLoader.java index afb92b8c9389e7c319ea44db7ec0274beefdd30f..601601a56529604e84a03700619d00df63541db7 100644 --- a/src/share/classes/java/net/URLClassLoader.java +++ b/src/share/classes/java/net/URLClassLoader.java @@ -1,5 +1,5 @@ /* - * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 1997-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 @@ -74,10 +74,10 @@ import sun.security.util.SecurityConstants; */ public class URLClassLoader extends SecureClassLoader implements Closeable { /* The search path for classes and resources */ - URLClassPath ucp; + private final URLClassPath ucp; /* The context to be used when loading classes and resources */ - private AccessControlContext acc; + private final AccessControlContext acc; /** * Constructs a new URLClassLoader for the given URLs. The URLs will be @@ -105,7 +105,19 @@ public class URLClassLoader extends SecureClassLoader implements Closeable { security.checkCreateClassLoader(); } ucp = new URLClassPath(urls); - acc = AccessController.getContext(); + this.acc = AccessController.getContext(); + } + + URLClassLoader(URL[] urls, ClassLoader parent, + AccessControlContext acc) { + super(parent); + // this is to make the stack depth consistent with 1.1 + SecurityManager security = System.getSecurityManager(); + if (security != null) { + security.checkCreateClassLoader(); + } + ucp = new URLClassPath(urls); + this.acc = acc; } /** @@ -136,7 +148,18 @@ public class URLClassLoader extends SecureClassLoader implements Closeable { security.checkCreateClassLoader(); } ucp = new URLClassPath(urls); - acc = AccessController.getContext(); + this.acc = AccessController.getContext(); + } + + URLClassLoader(URL[] urls, AccessControlContext acc) { + super(); + // this is to make the stack depth consistent with 1.1 + SecurityManager security = System.getSecurityManager(); + if (security != null) { + security.checkCreateClassLoader(); + } + ucp = new URLClassPath(urls); + this.acc = acc; } /** @@ -599,17 +622,14 @@ public class URLClassLoader extends SecureClassLoader implements Closeable { public static URLClassLoader newInstance(final URL[] urls, final ClassLoader parent) { // Save the caller's context - AccessControlContext acc = AccessController.getContext(); + final AccessControlContext acc = AccessController.getContext(); // Need a privileged block to create the class loader URLClassLoader ucl = AccessController.doPrivileged( new PrivilegedAction<URLClassLoader>() { public URLClassLoader run() { - return new FactoryURLClassLoader(urls, parent); + return new FactoryURLClassLoader(urls, parent, acc); } }); - // Now set the context on the loader using the one we saved, - // not the one inside the privileged block... - ucl.acc = acc; return ucl; } @@ -626,18 +646,14 @@ public class URLClassLoader extends SecureClassLoader implements Closeable { */ public static URLClassLoader newInstance(final URL[] urls) { // Save the caller's context - AccessControlContext acc = AccessController.getContext(); + final AccessControlContext acc = AccessController.getContext(); // Need a privileged block to create the class loader URLClassLoader ucl = AccessController.doPrivileged( new PrivilegedAction<URLClassLoader>() { public URLClassLoader run() { - return new FactoryURLClassLoader(urls); + return new FactoryURLClassLoader(urls, acc); } }); - - // Now set the context on the loader using the one we saved, - // not the one inside the privileged block... - ucl.acc = acc; return ucl; } @@ -649,20 +665,26 @@ public class URLClassLoader extends SecureClassLoader implements Closeable { } } ); + ClassLoader.registerAsParallelCapable(); } } final class FactoryURLClassLoader extends URLClassLoader { - FactoryURLClassLoader(URL[] urls, ClassLoader parent) { - super(urls, parent); + static { + ClassLoader.registerAsParallelCapable(); + } + + FactoryURLClassLoader(URL[] urls, ClassLoader parent, + AccessControlContext acc) { + super(urls, parent, acc); } - FactoryURLClassLoader(URL[] urls) { - super(urls); + FactoryURLClassLoader(URL[] urls, AccessControlContext acc) { + super(urls, acc); } - public final synchronized Class loadClass(String name, boolean resolve) + public final Class loadClass(String name, boolean resolve) throws ClassNotFoundException { // First check if we have permission to access the package. This diff --git a/src/share/classes/java/nio/channels/AsynchronousByteChannel.java b/src/share/classes/java/nio/channels/AsynchronousByteChannel.java new file mode 100644 index 0000000000000000000000000000000000000000..7bc433574792ff82b734dbaf44f68e61f8b9bedd --- /dev/null +++ b/src/share/classes/java/nio/channels/AsynchronousByteChannel.java @@ -0,0 +1,205 @@ +/* + * Copyright 2007-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 java.nio.channels; + +import java.nio.ByteBuffer; +import java.util.concurrent.Future; + +/** + * An asynchronous channel that can read and write bytes. + * + * <p> Some channels may not allow more than one read or write to be outstanding + * at any given time. If a thread invokes a read method before a previous read + * operation has completed then a {@link ReadPendingException} will be thrown. + * Similarly, if a write method is invoked before a previous write has completed + * then {@link WritePendingException} is thrown. Whether or not other kinds of + * I/O operations may proceed concurrently with a read operation depends upon + * the type of the channel. + * + * <p> Note that {@link java.nio.ByteBuffer ByteBuffers} are not safe for use by + * multiple concurrent threads. When a read or write operation is initiated then + * care must be taken to ensure that the buffer is not accessed until the + * operation completes. + * + * @see Channels#newInputStream(AsynchronousByteChannel) + * @see Channels#newOutputStream(AsynchronousByteChannel) + * + * @since 1.7 + */ + +public interface AsynchronousByteChannel + extends AsynchronousChannel +{ + /** + * Reads a sequence of bytes from this channel into the given buffer. + * + * <p> This method initiates an operation to read a sequence of bytes from + * this channel into the given buffer. The method returns a {@link Future} + * representing the pending result of the operation. The result of the + * operation, obtained by invoking the {@code Future} 's {@link + * Future#get() get} method, is the number of bytes read or {@code -1} if + * all bytes have been read and the channel has reached end-of-stream. + * + * <p> This method initiates a read operation to read up to <i>r</i> bytes + * from the channel, where <i>r</i> is the number of bytes remaining in the + * buffer, that is, {@code dst.remaining()} at the time that the read is + * attempted. Where <i>r</i> is 0, the read operation completes immediately + * with a result of {@code 0} without initiating an I/O operation. + * + * <p> Suppose that a byte sequence of length <i>n</i> is read, where + * <tt>0</tt> <tt><</tt> <i>n</i> <tt><=</tt> <i>r</i>. + * This byte sequence will be transferred into the buffer so that the first + * byte in the sequence is at index <i>p</i> and the last byte is at index + * <i>p</i> <tt>+</tt> <i>n</i> <tt>-</tt> <tt>1</tt>, + * where <i>p</i> is the buffer's position at the moment the read is + * performed. Upon completion the buffer's position will be equal to + * <i>p</i> <tt>+</tt> <i>n</i>; its limit will not have changed. + * + * <p> Buffers are not safe for use by multiple concurrent threads so care + * should be taken to not to access the buffer until the operaton has completed. + * + * <p> This method may be invoked at any time. Some channel types may not + * allow more than one read to be outstanding at any given time. If a thread + * initiates a read operation before a previous read operation has + * completed then a {@link ReadPendingException} will be thrown. + * + * <p> The <tt>handler</tt> parameter is used to specify a {@link + * CompletionHandler}. When the read operation completes the handler's + * {@link CompletionHandler#completed completed} method is executed. + * + * + * @param dst + * The buffer into which bytes are to be transferred + * @param attachment + * The object to attach to the I/O operation; can be {@code null} + * @param handler + * The completion handler object; can be {@code null} + * + * @return A Future representing the result of the operation + * + * @throws IllegalArgumentException + * If the buffer is read-only + * @throws ReadPendingException + * If the channel does not allow more than one read to be outstanding + * and a previous read has not completed + */ + <A> Future<Integer> read(ByteBuffer dst, + A attachment, + CompletionHandler<Integer,? super A> handler); + + /** + * Reads a sequence of bytes from this channel into the given buffer. + * + * <p> An invocation of this method of the form <tt>c.read(dst)</tt> + * behaves in exactly the same manner as the invocation + * <blockquote><pre> + * c.read(dst, null, null);</pre></blockquote> + * + * @param dst + * The buffer into which bytes are to be transferred + * + * @return A Future representing the result of the operation + * + * @throws IllegalArgumentException + * If the buffer is read-only + * @throws ReadPendingException + * If the channel does not allow more than one read to be outstanding + * and a previous read has not completed + */ + Future<Integer> read(ByteBuffer dst); + + /** + * Writes a sequence of bytes to this channel from the given buffer. + * + * <p> This method initiates an operation to write a sequence of bytes to + * this channel from the given buffer. This method returns a {@link + * Future} representing the pending result of the operation. The result + * of the operation, obtained by invoking the <tt>Future</tt>'s {@link + * Future#get() get} method, is the number of bytes written, possibly zero. + * + * <p> This method initiates a write operation to write up to <i>r</i> bytes + * to the channel, where <i>r</i> is the number of bytes remaining in the + * buffer, that is, {@code src.remaining()} at the moment the write is + * attempted. Where <i>r</i> is 0, the write operation completes immediately + * with a result of {@code 0} without initiating an I/O operation. + * + * <p> Suppose that a byte sequence of length <i>n</i> is written, where + * <tt>0</tt> <tt><</tt> <i>n</i> <tt><=</tt> <i>r</i>. + * This byte sequence will be transferred from the buffer starting at index + * <i>p</i>, where <i>p</i> is the buffer's position at the moment the + * write is performed; the index of the last byte written will be + * <i>p</i> <tt>+</tt> <i>n</i> <tt>-</tt> <tt>1</tt>. + * Upon completion the buffer's position will be equal to + * <i>p</i> <tt>+</tt> <i>n</i>; its limit will not have changed. + * + * <p> Buffers are not safe for use by multiple concurrent threads so care + * should be taken to not to access the buffer until the operaton has completed. + * + * <p> This method may be invoked at any time. Some channel types may not + * allow more than one write to be outstanding at any given time. If a thread + * initiates a write operation before a previous write operation has + * completed then a {@link WritePendingException} will be thrown. + * + * <p> The <tt>handler</tt> parameter is used to specify a {@link + * CompletionHandler}. When the write operation completes the handler's + * {@link CompletionHandler#completed completed} method is executed. + * + * @param src + * The buffer from which bytes are to be retrieved + * @param attachment + * The object to attach to the I/O operation; can be {@code null} + * @param handler + * The completion handler object; can be {@code null} + * + * @return A Future representing the result of the operation + * + * @throws WritePendingException + * If the channel does not allow more than one write to be outstanding + * and a previous write has not completed + */ + <A> Future<Integer> write(ByteBuffer src, + A attachment, + CompletionHandler<Integer,? super A> handler); + + /** + * Writes a sequence of bytes to this channel from the given buffer. + * + * <p> An invocation of this method of the form <tt>c.write(src)</tt> + * behaves in exactly the same manner as the invocation + * <blockquote><pre> + * c.write(src, null, null);</pre></blockquote> + * + * @param src + * The buffer from which bytes are to be retrieved + * + * @return A Future representing the result of the operation + * + * @throws WritePendingException + * If the channel does not allow more than one write to be outstanding + * and a previous write has not completed + */ + Future<Integer> write(ByteBuffer src); +} diff --git a/src/share/classes/java/nio/channels/AsynchronousChannel.java b/src/share/classes/java/nio/channels/AsynchronousChannel.java new file mode 100644 index 0000000000000000000000000000000000000000..f3e4ffe4ea5ac488b3ed76c0417c64523f058133 --- /dev/null +++ b/src/share/classes/java/nio/channels/AsynchronousChannel.java @@ -0,0 +1,116 @@ +/* + * Copyright 2007-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 java.nio.channels; + +import java.io.IOException; +import java.util.concurrent.Future; // javadoc + +/** + * A channel that supports asynchronous I/O operations. Asynchronous I/O + * operations will usually take one of two forms: + * + * <ol> + * <li><pre>{@link Future}<V> <em>operation</em>(<em>...</em>)</pre></li> + * <li><pre>Future<V> <em>operation</em>(<em>...</em> A attachment, {@link CompletionHandler}<V,? super A> handler)</pre></li> + * </ol> + * + * where <i>operation</i> is the name of the I/O operation (read or write for + * example), <i>V</i> is the result type of the I/O operation, and <i>A</i> is + * the type of an object attached to the I/O operation to provide context when + * consuming the result. The attachment is important for cases where a + * <em>state-less</em> {@code CompletionHandler} is used to consume the result + * of many I/O operations. + * + * <p> In the first form, the methods defined by the {@link Future Future} + * interface may be used to check if the operation has completed, wait for its + * completion, and to retrieve the result. In the second form, a {@link + * CompletionHandler} is invoked to consume the result of the I/O operation when + * it completes, fails, or is cancelled. + * + * <p> A channel that implements this interface is <em>asynchronously + * closeable</em>: If an I/O operation is outstanding on the channel and the + * channel's {@link #close close} method is invoked, then the I/O operation + * fails with the exception {@link AsynchronousCloseException}. + * + * <p> Asynchronous channels are safe for use by multiple concurrent threads. + * Some channel implementations may support concurrent reading and writing, but + * may not allow more than one read and one write operation to be outstanding at + * any given time. + * + * <h4>Cancellation</h4> + * + * <p> The {@code Future} interface defines the {@link Future#cancel cancel} + * method to cancel execution of a task. + * + * <p> Where the {@code cancel} method is invoked with the {@code + * mayInterruptIfRunning} parameter set to {@code true} then the I/O operation + * may be interrupted by closing the channel. This will cause any other I/O + * operations outstanding on the channel to complete with the exception {@link + * AsynchronousCloseException}. + * + * <p> If a {@code CompletionHandler} is specified when initiating an I/O + * operation, and the {@code cancel} method is invoked to cancel the I/O + * operation before it completes, then the {@code CompletionHandler}'s {@link + * CompletionHandler#cancelled cancelled} method is invoked. + * + * <p> If an implementation of this interface supports a means to cancel I/O + * operations, and where cancellation may leave the channel, or the entity to + * which it is connected, in an inconsistent state, then the channel is put into + * an implementation specific <em>error state</em> that prevents further + * attempts to initiate I/O operations on the channel. For example, if a read + * operation is cancelled but the implementation cannot guarantee that bytes + * have not been read from the channel then it puts the channel into error state + * state; further attempts to initiate a {@code read} operation causes an + * unspecified runtime exception to be thrown. + * + * <p> Where the {@code cancel} method is invoked to cancel read or write + * operations then it recommended that all buffers used in the I/O operations be + * discarded or care taken to ensure that the buffers are not accessed while the + * channel remains open. + * + * @since 1.7 + */ + +public interface AsynchronousChannel + extends Channel +{ + /** + * Closes this channel. + * + * <p> Any outstanding asynchronous operations upon this channel will + * complete with the exception {@link AsynchronousCloseException}. After a + * channel is closed then further attempts to initiate asynchronous I/O + * operations complete immediately with cause {@link ClosedChannelException}. + * + * <p> This method otherwise behaves exactly as specified by the {@link + * Channel} interface. + * + * @throws IOException + * If an I/O error occurs + */ + @Override + void close() throws IOException; +} diff --git a/src/share/classes/java/nio/channels/AsynchronousChannelGroup.java b/src/share/classes/java/nio/channels/AsynchronousChannelGroup.java new file mode 100644 index 0000000000000000000000000000000000000000..1199e16b51f8641e1d8591f6154c98c225284586 --- /dev/null +++ b/src/share/classes/java/nio/channels/AsynchronousChannelGroup.java @@ -0,0 +1,344 @@ +/* + * Copyright 2007-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 java.nio.channels; + +import java.nio.channels.spi.AsynchronousChannelProvider; +import java.io.IOException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.ThreadFactory; +import java.util.concurrent.TimeUnit; + +/** + * A grouping of asynchronous channels for the purpose of resource sharing. + * + * <p> An asynchronous channel group encapsulates the mechanics required to + * handle the completion of I/O operations initiated by {@link AsynchronousChannel + * asynchronous channels} that are bound to the group. A group has an associated + * thread pool to which tasks are submitted to handle I/O events and dispatch to + * {@link CompletionHandler completion-handlers} that consume the result of + * asynchronous operations performed on channels in the group. In addition to + * handling I/O events, the pooled threads may also execute other tasks required + * to support the execution of asynchronous I/O operations. + * + * <p> An asynchronous channel group is created by invoking the {@link + * #withFixedThreadPool withFixedThreadPool} or {@link #withCachedThreadPool + * withCachedThreadPool} methods defined here. Channels are bound to a group by + * specifying the group when constructing the channel. The associated thread + * pool is <em>owned</em> by the group; termination of the group results in the + * shutdown of the associated thread pool. + * + * <p> In addition to groups created explicitly, the Java virtual machine + * maintains a system-wide <em>default group</em> that is constructed + * automatically. Asynchronous channels that do not specify a group at + * construction time are bound to the default group. The default group has an + * associated thread pool that creates new threads as needed. The default group + * may be configured by means of system properties defined in the table below. + * Where the {@link java.util.concurrent.ThreadFactory ThreadFactory} for the + * default group is not configured then the pooled threads of the default group + * are {@link Thread#isDaemon daemon} threads. + * + * <table border> + * <tr> + * <th>System property</th> + * <th>Description</th> + * </tr> + * <tr> + * <tr> + * <td> {@code java.nio.channels.DefaultThreadPool.threadFactory} </td> + * <td> The value of this property is taken to be the fully-qualified name + * of a concrete {@link java.util.concurrent.ThreadFactory ThreadFactory} + * class. The class is loaded using the system class loader and instantiated. + * The factory's {@link java.util.concurrent.ThreadFactory#newThread + * newThread} method is invoked to create each thread for the default + * group's thread pool. If the process to load and instantiate the value + * of the property fails then an unspecified error is thrown during the + * construction of the default group. </td> + * </tr> + * <tr> + * <td> {@code java.nio.channels.DefaultThreadPool.initialSize} </td> + * <td> The value of the {@code initialSize} parameter for the default + * group (see {@link #withCachedThreadPool withCachedThreadPool}). + * The value of the property is taken to be the {@code String} + * representation of an {@code Integer} that is the initial size parameter. + * If the value cannot be parsed as an {@code Integer} it causes an + * unspecified error to be thrown during the construction of the default + * group. </td> + * </tr> + * </table> + * + * <a name="threading"><h4>Threading</h4></a> + * + * <p> The completion handler for an I/O operation initiated on a channel bound + * to a group is guaranteed to be invoked by one of the pooled threads in the + * group. This ensures that the completion handler is run by a thread with the + * expected <em>identity</em>. + * + * <p> Where an I/O operation completes immediately, and the initiating thread + * is one of the pooled threads in the group then the completion handler may + * be invoked directly by the initiating thread. To avoid stack overflow, an + * implementation may impose a limit as to the number of activations on the + * thread stack. Some I/O operations may prohibit invoking the completion + * handler directly by the initiating thread (see {@link + * AsynchronousServerSocketChannel#accept(Object,CompletionHandler) accept}). + * + * <a name="shutdown"><h4>Shutdown and Termination</h4></a> + * + * <p> The {@link #shutdown() shutdown} method is used to initiate an <em>orderly + * shutdown</em> of a group. An orderly shutdown marks the group as shutdown; + * further attempts to construct a channel that binds to the group will throw + * {@link ShutdownChannelGroupException}. Whether or not a group is shutdown can + * be tested using the {@link #isShutdown() isShutdown} method. Once shutdown, + * the group <em>terminates</em> when all asynchronous channels that are bound to + * the group are closed, all actively executing completion handlers have run to + * completion, and resources used by the group are released. No attempt is made + * to stop or interrupt threads that are executing completion handlers. The + * {@link #isTerminated() isTerminated} method is used to test if the group has + * terminated, and the {@link #awaitTermination awaitTermination} method can be + * used to block until the group has terminated. + * + * <p> The {@link #shutdownNow() shutdownNow} method can be used to initiate a + * <em>forceful shutdown</em> of the group. In addition to the actions performed + * by an orderly shutdown, the {@code shutdownNow} method closes all open channels + * in the group as if by invoking the {@link AsynchronousChannel#close close} + * method. + * + * @since 1.7 + * + * @see AsynchronousSocketChannel#open(AsynchronousChannelGroup) + * @see AsynchronousServerSocketChannel#open(AsynchronousChannelGroup) + */ + +public abstract class AsynchronousChannelGroup { + private final AsynchronousChannelProvider provider; + + /** + * Initialize a new instance of this class. + * + * @param provider + * The asynchronous channel provider for this group + */ + protected AsynchronousChannelGroup(AsynchronousChannelProvider provider) { + this.provider = provider; + } + + /** + * Returns the provider that created this channel group. + * + * @return The provider that created this channel group + */ + public final AsynchronousChannelProvider provider() { + return provider; + } + + /** + * Creates an asynchronous channel group with a fixed thread pool. + * + * <p> The resulting asynchronous channel group reuses a fixed number of + * threads. At any point, at most {@code nThreads} threads will be active + * processing tasks that are submitted to handle I/O events and dispatch + * completion results for operations initiated on asynchronous channels in + * the group. + * + * <p> The group is created by invoking the {@link + * AsynchronousChannelProvider#openAsynchronousChannelGroup(int,ThreadFactory) + * openAsynchronousChannelGroup(int,ThreadFactory)} method of the system-wide + * default {@link AsynchronousChannelProvider} object. + * + * @param nThreads + * The number of threads in the pool + * @param threadFactory + * The factory to use when creating new threads + * + * @return A new asynchronous channel group + * + * @throws IllegalArgumentException + * If {@code nThreads <= 0} + * @throws IOException + * If an I/O error occurs + */ + public static AsynchronousChannelGroup withFixedThreadPool(int nThreads, + ThreadFactory threadFactory) + throws IOException + { + return AsynchronousChannelProvider.provider() + .openAsynchronousChannelGroup(nThreads, threadFactory); + } + + /** + * Creates an asynchronous channel group with a given thread pool that + * creates new threads as needed. + * + * <p> The {@code executor} parameter is an {@code ExecutorService} that + * creates new threads as needed to execute tasks that are submitted to + * handle I/O events and dispatch completion results for operations initiated + * on asynchronous channels in the group. It may reuse previously constructed + * threads when they are available. + * + * <p> The {@code initialSize} parameter may be used by the implementation + * as a <em>hint</em> as to the initial number of tasks it may submit. For + * example, it may be used to indictae the initial number of threads that + * wait on I/O events. + * + * <p> The executor is intended to be used exclusively by the resulting + * asynchronous channel group. Termination of the group results in the + * orderly {@link ExecutorService#shutdown shutdown} of the executor + * service. Shutting down the executor service by other means results in + * unspecified behavior. + * + * <p> The group is created by invoking the {@link + * AsynchronousChannelProvider#openAsynchronousChannelGroup(ExecutorService,int) + * openAsynchronousChannelGroup(ExecutorService,int)} method of the system-wide + * default {@link AsynchronousChannelProvider} object. + * + * @param executor + * The thread pool for the resulting group + * @param initialSize + * A value {@code >=0} or a negative value for implementation + * specific default + * + * @return A new asynchronous channel group + * + * @throws IOException + * If an I/O error occurs + * + * @see java.util.concurrent.Executors#newCachedThreadPool + */ + public static AsynchronousChannelGroup withCachedThreadPool(ExecutorService executor, + int initialSize) + throws IOException + { + return AsynchronousChannelProvider.provider() + .openAsynchronousChannelGroup(executor, initialSize); + } + + /** + * Creates an asynchronous channel group with a given thread pool. + * + * <p> The {@code executor} parameter is an {@code ExecutorService} that + * executes tasks submitted to dispatch completion results for operations + * initiated on asynchronous channels in the group. + * + * <p> Care should be taken when configuring the executor service. It + * should support <em>direct handoff</em> or <em>unbounded queuing</em> of + * submitted tasks, and the thread that invokes the {@link + * ExecutorService#execute execute} method should never invoke the task + * directly. An implementation may mandate additional constraints. + * + * <p> The executor is intended to be used exclusively by the resulting + * asynchronous channel group. Termination of the group results in the + * orderly {@link ExecutorService#shutdown shutdown} of the executor + * service. Shutting down the executor service by other means results in + * unspecified behavior. + * + * <p> The group is created by invoking the {@link + * AsynchronousChannelProvider#openAsynchronousChannelGroup(ExecutorService,int) + * openAsynchronousChannelGroup(ExecutorService,int)} method of the system-wide + * default {@link AsynchronousChannelProvider} object with an {@code + * initialSize} of {@code 0}. + * + * @param executor + * The thread pool for the resulting group + * + * @return A new asynchronous channel group + * + * @throws IOException + * If an I/O error occurs + */ + public static AsynchronousChannelGroup withThreadPool(ExecutorService executor) + throws IOException + { + return AsynchronousChannelProvider.provider() + .openAsynchronousChannelGroup(executor, 0); + } + + /** + * Tells whether or not this asynchronous channel group is shutdown. + * + * @return {@code true} if this asynchronous channel group is shutdown or + * has been marked for shutdown. + */ + public abstract boolean isShutdown(); + + /** + * Tells whether or not this group has terminated. + * + * <p> Where this method returns {@code true}, then the associated thread + * pool has also {@link ExecutorService#isTerminated terminated}. + * + * @return {@code true} if this group has terminated + */ + public abstract boolean isTerminated(); + + /** + * Initiates an orderly shutdown of the group. + * + * <p> This method marks the group as shutdown. Further attempts to construct + * channel that binds to this group will throw {@link ShutdownChannelGroupException}. + * The group terminates when all asynchronous channels in the group are + * closed, all actively executing completion handlers have run to completion, + * and all resources have been released. This method has no effect if the + * group is already shutdown. + */ + public abstract void shutdown(); + + /** + * Shuts down the group and closes all open channels in the group. + * + * <p> In addition to the actions performed by the {@link #shutdown() shutdown} + * method, this method invokes the {@link AsynchronousChannel#close close} + * method on all open channels in the group. This method does not attempt to + * stop or interrupt threads that are executing completion handlers. The + * group terminates when all actively executing completion handlers have run + * to completion and all resources have been released. This method may be + * invoked at any time. If some other thread has already invoked it, then + * another invocation will block until the first invocation is complete, + * after which it will return without effect. + * + * @throws IOException + * If an I/O error occurs + */ + public abstract void shutdownNow() throws IOException; + + /** + * Awaits termination of the group. + + * <p> This method blocks until the group has terminated, or the timeout + * occurs, or the current thread is interrupted, whichever happens first. + * + * @param timeout + * The maximum time to wait, or zero or less to not wait + * @param unit + * The time unit of the timeout argument + * + * @return {@code true} if the group has terminated; {@code false} if the + * timeout elapsed before termination + * + * @throws InterruptedException + * If interrupted while waiting + */ + public abstract boolean awaitTermination(long timeout, TimeUnit unit) + throws InterruptedException; +} diff --git a/src/share/classes/java/nio/channels/AsynchronousDatagramChannel.java b/src/share/classes/java/nio/channels/AsynchronousDatagramChannel.java new file mode 100644 index 0000000000000000000000000000000000000000..6a9d9f09715862a1b1fb4b757fd113b7be4a24eb --- /dev/null +++ b/src/share/classes/java/nio/channels/AsynchronousDatagramChannel.java @@ -0,0 +1,718 @@ +/* + * Copyright 2007-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 java.nio.channels; + +import java.nio.channels.spi.*; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.Future; +import java.io.IOException; +import java.net.SocketOption; +import java.net.SocketAddress; +import java.net.ProtocolFamily; +import java.nio.ByteBuffer; + +/** + * An asynchronous channel for datagram-oriented sockets. + * + * <p> An asynchronous datagram channel is created by invoking one of the {@link + * #open open} methods defined by this class. It is not possible to create a channel + * for an arbitrary, pre-existing datagram socket. A newly-created asynchronous + * datagram channel is open but not connected. It need not be connected in order + * for the {@link #send send} and {@link #receive receive} methods to be used. + * A datagram channel may be connected, by invoking its {@link #connect connect} + * method, in order to avoid the overhead of the security checks that are otherwise + * performed as part of every send and receive operation when a security manager + * is set. The channel must be connected in order to use the {@link #read read} + * and {@link #write write} methods, since those methods do not accept or return + * socket addresses. Once connected, an asynchronous datagram channel remains + * connected until it is disconnected or closed. + * + * <p> Socket options are configured using the {@link #setOption(SocketOption,Object) + * setOption} method. An asynchronous datagram channel to an Internet Protocol + * (IP) socket supports the following options: + * <blockquote> + * <table border> + * <tr> + * <th>Option Name</th> + * <th>Description</th> + * </tr> + * <tr> + * <td> {@link java.net.StandardSocketOption#SO_SNDBUF SO_SNDBUF} </td> + * <td> The size of the socket send buffer </td> + * </tr> + * <tr> + * <td> {@link java.net.StandardSocketOption#SO_RCVBUF SO_RCVBUF} </td> + * <td> The size of the socket receive buffer </td> + * </tr> + * <tr> + * <td> {@link java.net.StandardSocketOption#SO_REUSEADDR SO_REUSEADDR} </td> + * <td> Re-use address </td> + * </tr> + * <tr> + * <td> {@link java.net.StandardSocketOption#SO_BROADCAST SO_BROADCAST} </td> + * <td> Allow transmission of broadcast datagrams </td> + * </tr> + * <tr> + * <td> {@link java.net.StandardSocketOption#IP_TOS IP_TOS} </td> + * <td> The Type of Service (ToS) octet in the Internet Protocol (IP) header </td> + * </tr> + * <tr> + * <td> {@link java.net.StandardSocketOption#IP_MULTICAST_IF IP_MULTICAST_IF} </td> + * <td> The network interface for Internet Protocol (IP) multicast datagrams </td> + * </tr> + * <tr> + * <td> {@link java.net.StandardSocketOption#IP_MULTICAST_TTL + * IP_MULTICAST_TTL} </td> + * <td> The <em>time-to-live</em> for Internet Protocol (IP) multicast + * datagrams </td> + * </tr> + * <tr> + * <td> {@link java.net.StandardSocketOption#IP_MULTICAST_LOOP + * IP_MULTICAST_LOOP} </td> + * <td> Loopback for Internet Protocol (IP) multicast datagrams </td> + * </tr> + * </table> + * </blockquote> + * Additional (implementation specific) options may also be supported. + * + * <p> Asynchronous datagram channels allow more than one read/receive and + * write/send to be oustanding at any given time. + * + * <p> <b>Usage Example:</b> + * <pre> + * final AsynchronousDatagramChannel dc = AsynchronousDatagramChannel.open() + * .bind(new InetSocketAddress(4000)); + * + * // print the source address of all packets that we receive + * dc.receive(buffer, buffer, new CompletionHandler<SocketAddress,ByteBuffer>() { + * public void completed(SocketAddress sa, ByteBuffer buffer) { + * try { + * System.out.println(sa); + * + * buffer.clear(); + * dc.receive(buffer, buffer, this); + * } catch (...) { ... } + * } + * public void failed(Throwable exc, ByteBuffer buffer) { + * ... + * } + * public void cancelled(ByteBuffer buffer) { + * ... + * } + * }); + * </pre> + * + * @since 1.7 + */ + +public abstract class AsynchronousDatagramChannel + implements AsynchronousByteChannel, MulticastChannel +{ + private final AsynchronousChannelProvider provider; + + /** + * Initializes a new instance of this class. + */ + protected AsynchronousDatagramChannel(AsynchronousChannelProvider provider) { + this.provider = provider; + } + + /** + * Returns the provider that created this channel. + */ + public final AsynchronousChannelProvider provider() { + return provider; + } + + /** + * Opens an asynchronous datagram channel. + * + * <p> The new channel is created by invoking the {@link + * java.nio.channels.spi.AsynchronousChannelProvider#openAsynchronousDatagramChannel + * openAsynchronousDatagramChannel} method on the {@link + * java.nio.channels.spi.AsynchronousChannelProvider} object that created + * the given group (or the default provider where {@code group} is {@code + * null}). + * + * <p> The {@code family} parameter is used to specify the {@link ProtocolFamily}. + * If the datagram channel is to be used for Internet Protocol {@link + * MulticastChannel multicasting} then this parameter should correspond to + * the address type of the multicast groups that this channel will join. + * + * @param family + * The protocol family, or {@code null} to use the default protocol + * family + * @param group + * The group to which the newly constructed channel should be bound, + * or {@code null} for the default group + * + * @return A new asynchronous datagram channel + * + * @throws UnsupportedOperationException + * If the specified protocol family is not supported. For example, + * suppose the parameter is specified as {@link + * java.net.StandardProtocolFamily#INET6 INET6} but IPv6 is not + * enabled on the platform. + * @throws ShutdownChannelGroupException + * The specified group is shutdown + * @throws IOException + * If an I/O error occurs + */ + public static AsynchronousDatagramChannel open(ProtocolFamily family, + AsynchronousChannelGroup group) + throws IOException + { + AsynchronousChannelProvider provider = (group == null) ? + AsynchronousChannelProvider.provider() : group.provider(); + return provider.openAsynchronousDatagramChannel(family, group); + } + + /** + * Opens an asynchronous datagram channel. + * + * <p> This method returns an asynchronous datagram channel that is + * bound to the <em>default group</em>. This method is equivalent to evaluating + * the expression: + * <blockquote><pre> + * open((ProtocolFamily)null, (AsynchronousChannelGroup)null); + * </pre></blockquote> + * + * @return A new asynchronous datagram channel + * + * @throws IOException + * If an I/O error occurs + */ + public static AsynchronousDatagramChannel open() + throws IOException + { + return open(null, null); + } + + // -- Socket-specific operations -- + + /** + * @throws AlreadyBoundException {@inheritDoc} + * @throws UnsupportedAddressTypeException {@inheritDoc} + * @throws ClosedChannelException {@inheritDoc} + * @throws IOException {@inheritDoc} + * @throws SecurityException + * If a security manager has been installed and its {@link + * SecurityManager#checkListen checkListen} method denies the + * operation + */ + @Override + public abstract AsynchronousDatagramChannel bind(SocketAddress local) + throws IOException; + + /** + * @throws IllegalArgumentException {@inheritDoc} + * @throws ClosedChannelException {@inheritDoc} + * @throws IOException {@inheritDoc} + */ + @Override + public abstract <T> AsynchronousDatagramChannel setOption(SocketOption<T> name, T value) + throws IOException; + + /** + * Returns the remote address to which this channel is connected. + * + * <p> Where the channel is connected to an Internet Protocol socket address + * then the return value from this method is of type {@link + * java.net.InetSocketAddress}. + * + * @return The remote address; {@code null} if the channel's socket is not + * connected + * + * @throws ClosedChannelException + * If the channel is closed + * @throws IOException + * If an I/O error occurs + */ + public abstract SocketAddress getRemoteAddress() throws IOException; + + /** + * Connects this channel's socket. + * + * <p> The channel's socket is configured so that it only receives + * datagrams from, and sends datagrams to, the given remote <i>peer</i> + * address. Once connected, datagrams may not be received from or sent to + * any other address. A datagram socket remains connected until it is + * explicitly disconnected or until it is closed. + * + * <p> This method performs exactly the same security checks as the {@link + * java.net.DatagramSocket#connect connect} method of the {@link + * java.net.DatagramSocket} class. That is, if a security manager has been + * installed then this method verifies that its {@link + * java.lang.SecurityManager#checkAccept checkAccept} and {@link + * java.lang.SecurityManager#checkConnect checkConnect} methods permit + * datagrams to be received from and sent to, respectively, the given + * remote address. + * + * <p> This method may be invoked at any time. Whether it has any effect + * on outstanding read or write operations is implementation specific and + * therefore not specified. + * + * @param remote + * The remote address to which this channel is to be connected + * + * @return This datagram channel + * + * @throws ClosedChannelException + * If this channel is closed + * + * @throws SecurityException + * If a security manager has been installed + * and it does not permit access to the given remote address + * + * @throws IOException + * If some other I/O error occurs + */ + public abstract AsynchronousDatagramChannel connect(SocketAddress remote) + throws IOException; + + /** + * Disconnects this channel's socket. + * + * <p> The channel's socket is configured so that it can receive datagrams + * from, and sends datagrams to, any remote address so long as the security + * manager, if installed, permits it. + * + * <p> This method may be invoked at any time. Whether it has any effect + * on outstanding read or write operations is implementation specific and + * therefore not specified. + * + * @return This datagram channel + * + * @throws IOException + * If some other I/O error occurs + */ + public abstract AsynchronousDatagramChannel disconnect() throws IOException; + + /** + * Receives a datagram via this channel. + * + * <p> This method initiates the receiving of a datagram, returning a + * {@code Future} representing the pending result of the operation. + * The {@code Future}'s {@link Future#get() get} method returns + * the source address of the datagram upon successful completion. + * + * <p> The datagram is transferred into the given byte buffer starting at + * its current position, as if by a regular {@link AsynchronousByteChannel#read + * read} operation. If there are fewer bytes remaining in the buffer + * than are required to hold the datagram then the remainder of the datagram + * is silently discarded. + * + * <p> If a timeout is specified and the timeout elapses before the operation + * completes then the operation completes with the exception {@link + * InterruptedByTimeoutException}. When a timeout elapses then the state of + * the {@link ByteBuffer} is not defined. The buffers should be discarded or + * at least care must be taken to ensure that the buffer is not accessed + * while the channel remains open. + * + * <p> When a security manager has been installed and the channel is not + * connected, then it verifies that the source's address and port number are + * permitted by the security manager's {@link SecurityManager#checkAccept + * checkAccept} method. The permission check is performed with privileges that + * are restricted by the calling context of this method. If the permission + * check fails then the operation completes with a {@link SecurityException}. + * The overhead of this security check can be avoided by first connecting the + * socket via the {@link #connect connect} method. + * + * @param dst + * The buffer into which the datagram is to be transferred + * @param timeout + * The timeout, or {@code 0L} for no timeout + * @param unit + * The time unit of the {@code timeout} argument + * @param attachment + * The object to attach to the I/O operation; can be {@code null} + * @param handler + * The handler for consuming the result; can be {@code null} + * + * @return a {@code Future} object representing the pending result + * + * @throws IllegalArgumentException + * If the timeout is negative or the buffer is read-only + * @throws ShutdownChannelGroupException + * If a handler is specified, and the channel group is shutdown + */ + public abstract <A> Future<SocketAddress> receive(ByteBuffer dst, + long timeout, + TimeUnit unit, + A attachment, + CompletionHandler<SocketAddress,? super A> handler); + + /** + * Receives a datagram via this channel. + * + * <p> This method initiates the receiving of a datagram, returning a + * {@code Future} representing the pending result of the operation. + * The {@code Future}'s {@link Future#get() get} method returns + * the source address of the datagram upon successful completion. + * + * <p> This method is equivalent to invoking {@link + * #receive(ByteBuffer,long,TimeUnit,Object,CompletionHandler)} with a + * timeout of {@code 0L}. + * + * @param dst + * The buffer into which the datagram is to be transferred + * @param attachment + * The object to attach to the I/O operation; can be {@code null} + * @param handler + * The handler for consuming the result; can be {@code null} + * + * @return a {@code Future} object representing the pending result + * + * @throws IllegalArgumentException + * If the buffer is read-only + * @throws ShutdownChannelGroupException + * If a handler is specified, and the channel group is shutdown + */ + public final <A> Future<SocketAddress> receive(ByteBuffer dst, + A attachment, + CompletionHandler<SocketAddress,? super A> handler) + { + return receive(dst, 0L, TimeUnit.MILLISECONDS, attachment, handler); + } + + /** + * Receives a datagram via this channel. + * + * <p> This method initiates the receiving of a datagram, returning a + * {@code Future} representing the pending result of the operation. + * The {@code Future}'s {@link Future#get() get} method returns + * the source address of the datagram upon successful completion. + * + * <p> This method is equivalent to invoking {@link + * #receive(ByteBuffer,long,TimeUnit,Object,CompletionHandler)} with a + * timeout of {@code 0L}, and an attachment and completion handler + * of {@code null}. + * + * @param dst + * The buffer into which the datagram is to be transferred + * + * @return a {@code Future} object representing the pending result + * + * @throws IllegalArgumentException + * If the buffer is read-only + */ + public final <A> Future<SocketAddress> receive(ByteBuffer dst) { + return receive(dst, 0L, TimeUnit.MILLISECONDS, null, null); + } + + /** + * Sends a datagram via this channel. + * + * <p> This method initiates sending of a datagram, returning a + * {@code Future} representing the pending result of the operation. + * The operation sends the remaining bytes in the given buffer as a single + * datagram to the given target address. The result of the operation, obtained + * by invoking the {@code Future}'s {@link Future#get() get} + * method, is the number of bytes sent. + * + * <p> The datagram is transferred from the byte buffer as if by a regular + * {@link AsynchronousByteChannel#write write} operation. + * + * <p> If a timeout is specified and the timeout elapses before the operation + * completes then the operation completes with the exception {@link + * InterruptedByTimeoutException}. When a timeout elapses then the state of + * the {@link ByteBuffer} is not defined. The buffers should be discarded or + * at least care must be taken to ensure that the buffer is not accessed + * while the channel remains open. + * + * <p> If there is a security manager installed and the the channel is not + * connected then this method verifies that the target address and port number + * are permitted by the security manager's {@link SecurityManager#checkConnect + * checkConnect} method. The overhead of this security check can be avoided + * by first connecting the socket via the {@link #connect connect} method. + * + * @param src + * The buffer containing the datagram to be sent + * @param target + * The address to which the datagram is to be sent + * @param timeout + * The timeout, or {@code 0L} for no timeout + * @param unit + * The time unit of the {@code timeout} argument + * @param attachment + * The object to attach to the I/O operation; can be {@code null} + * @param handler + * The handler for consuming the result; can be {@code null} + * + * @return a {@code Future} object representing the pending result + * + * @throws UnresolvedAddressException + * If the given remote address is not fully resolved + * @throws UnsupportedAddressTypeException + * If the type of the given remote address is not supported + * @throws IllegalArgumentException + * If the timeout is negative, or if the channel's socket is + * connected to an address that is not equal to {@code target} + * @throws SecurityException + * If a security manager has been installed and it does not permit + * datagrams to be sent to the given address + * @throws ShutdownChannelGroupException + * If a handler is specified, and the channel group is shutdown + */ + public abstract <A> Future<Integer> send(ByteBuffer src, + SocketAddress target, + long timeout, + TimeUnit unit, + A attachment, + CompletionHandler<Integer,? super A> handler); + + /** + * Sends a datagram via this channel. + * + * <p> This method initiates sending of a datagram, returning a + * {@code Future} representing the pending result of the operation. + * The operation sends the remaining bytes in the given buffer as a single + * datagram to the given target address. The result of the operation, obtained + * by invoking the {@code Future}'s {@link Future#get() get} + * method, is the number of bytes sent. + * + * <p> This method is equivalent to invoking {@link + * #send(ByteBuffer,SocketAddress,long,TimeUnit,Object,CompletionHandler)} + * with a timeout of {@code 0L}. + * + * @param src + * The buffer containing the datagram to be sent + * @param target + * The address to which the datagram is to be sent + * @param attachment + * The object to attach to the I/O operation; can be {@code null} + * @param handler + * The handler for consuming the result; can be {@code null} + * + * @return a {@code Future} object representing the pending result + * + * @throws UnresolvedAddressException + * If the given remote address is not fully resolved + * @throws UnsupportedAddressTypeException + * If the type of the given remote address is not supported + * @throws IllegalArgumentException + * If the channel's socket is connected and is connected to an + * address that is not equal to {@code target} + * @throws SecurityException + * If a security manager has been installed and it does not permit + * datagrams to be sent to the given address + * @throws ShutdownChannelGroupException + * If a handler is specified, and the channel group is shutdown + */ + public final <A> Future<Integer> send(ByteBuffer src, + SocketAddress target, + A attachment, + CompletionHandler<Integer,? super A> handler) + { + return send(src, target, 0L, TimeUnit.MILLISECONDS, attachment, handler); + } + + /** + * Sends a datagram via this channel. + * + * <p> This method initiates sending of a datagram, returning a + * {@code Future} representing the pending result of the operation. + * The operation sends the remaining bytes in the given buffer as a single + * datagram to the given target address. The result of the operation, obtained + * by invoking the {@code Future}'s {@link Future#get() get} + * method, is the number of bytes sent. + * + * <p> This method is equivalent to invoking {@link + * #send(ByteBuffer,SocketAddress,long,TimeUnit,Object,CompletionHandler)} + * with a timeout of {@code 0L} and an attachment and completion handler + * of {@code null}. + * + * @param src + * The buffer containing the datagram to be sent + * @param target + * The address to which the datagram is to be sent + * + * @return a {@code Future} object representing the pending result + * + * @throws UnresolvedAddressException + * If the given remote address is not fully resolved + * @throws UnsupportedAddressTypeException + * If the type of the given remote address is not supported + * @throws IllegalArgumentException + * If the channel's socket is connected and is connected to an + * address that is not equal to {@code target} + * @throws SecurityException + * If a security manager has been installed and it does not permit + * datagrams to be sent to the given address + */ + public final Future<Integer> send(ByteBuffer src, SocketAddress target) { + return send(src, target, 0L, TimeUnit.MILLISECONDS, null, null); + } + + /** + * Receives a datagram via this channel. + * + * <p> This method initiates the receiving of a datagram, returning a + * {@code Future} representing the pending result of the operation. + * The {@code Future}'s {@link Future#get() get} method returns + * the number of bytes transferred upon successful completion. + * + * <p> This method may only be invoked if this channel is connected, and it + * only accepts datagrams from the peer that the channel is connected too. + * The datagram is transferred into the given byte buffer starting at + * its current position and exactly as specified in the {@link + * AsynchronousByteChannel} interface. If there are fewer bytes + * remaining in the buffer than are required to hold the datagram then the + * remainder of the datagram is silently discarded. + * + * <p> If a timeout is specified and the timeout elapses before the operation + * completes then the operation completes with the exception {@link + * InterruptedByTimeoutException}. When a timeout elapses then the state of + * the {@link ByteBuffer} is not defined. The buffers should be discarded or + * at least care must be taken to ensure that the buffer is not accessed + * while the channel remains open. + * + * @param dst + * The buffer into which the datagram is to be transferred + * @param timeout + * The timeout, or {@code 0L} for no timeout + * @param unit + * The time unit of the {@code timeout} argument + * @param attachment + * The object to attach to the I/O operation; can be {@code null} + * @param handler + * The handler for consuming the result; can be {@code null} + * + * @return a {@code Future} object representing the pending result + * + * @throws IllegalArgumentException + * If the timeout is negative or buffer is read-only + * @throws NotYetConnectedException + * If this channel is not connected + * @throws ShutdownChannelGroupException + * If a handler is specified, and the channel group is shutdown + */ + public abstract <A> Future<Integer> read(ByteBuffer dst, + long timeout, + TimeUnit unit, + A attachment, + CompletionHandler<Integer,? super A> handler); + + /** + * @throws NotYetConnectedException + * If this channel is not connected + * @throws ShutdownChannelGroupException + * If a handler is specified, and the channel group is shutdown + */ + @Override + public final <A> Future<Integer> read(ByteBuffer dst, + A attachment, + CompletionHandler<Integer,? super A> handler) + { + return read(dst, 0L, TimeUnit.MILLISECONDS, attachment, handler); + } + + /** + * @throws NotYetConnectedException + * If this channel is not connected + * @throws ShutdownChannelGroupException + * If a handler is specified, and the channel group is shutdown + */ + @Override + public final Future<Integer> read(ByteBuffer dst) { + return read(dst, 0L, TimeUnit.MILLISECONDS, null, null); + } + + /** + * Writes a datagram to this channel. + * + * <p> This method initiates sending of a datagram, returning a + * {@code Future} representing the pending result of the operation. + * The operation sends the remaining bytes in the given buffer as a single + * datagram. The result of the operation, obtained by invoking the + * {@code Future}'s {@link Future#get() get} method, is the + * number of bytes sent. + * + * <p> The datagram is transferred from the byte buffer as if by a regular + * {@link AsynchronousByteChannel#write write} operation. + * + * <p> This method may only be invoked if this channel is connected, + * in which case it sends datagrams directly to the socket's peer. Otherwise + * it behaves exactly as specified in the {@link + * AsynchronousByteChannel} interface. + * + * <p> If a timeout is specified and the timeout elapses before the operation + * completes then the operation completes with the exception {@link + * InterruptedByTimeoutException}. When a timeout elapses then the state of + * the {@link ByteBuffer} is not defined. The buffers should be discarded or + * at least care must be taken to ensure that the buffer is not accessed + * while the channel remains open. + * + * @param src + * The buffer containing the datagram to be sent + * @param timeout + * The timeout, or {@code 0L} for no timeout + * @param unit + * The time unit of the {@code timeout} argument + * @param attachment + * The object to attach to the I/O operation; can be {@code null} + * @param handler + * The handler for consuming the result; can be {@code null} + * + * @return a {@code Future} object representing the pending result + * + * @throws IllegalArgumentException + * If the timeout is negative + * @throws NotYetConnectedException + * If this channel is not connected + * @throws ShutdownChannelGroupException + * If a handler is specified, and the channel group is shutdown + */ + public abstract <A> Future<Integer> write(ByteBuffer src, + long timeout, + TimeUnit unit, + A attachment, + CompletionHandler<Integer,? super A> handler); + /** + * @throws NotYetConnectedException + * If this channel is not connected + * @throws ShutdownChannelGroupException + * If a handler is specified, and the channel group is shutdown + */ + @Override + public final <A> Future<Integer> write(ByteBuffer src, + A attachment, + CompletionHandler<Integer,? super A> handler) + { + return write(src, 0L, TimeUnit.MILLISECONDS, attachment, handler); + } + + /** + * @throws NotYetConnectedException + * If this channel is not connected + * @throws ShutdownChannelGroupException + * If a handler is specified, and the channel group is shutdown + */ + @Override + public final Future<Integer> write(ByteBuffer src) { + return write(src, 0L, TimeUnit.MILLISECONDS, null, null); + } +} diff --git a/src/share/classes/java/nio/channels/AsynchronousFileChannel.java b/src/share/classes/java/nio/channels/AsynchronousFileChannel.java new file mode 100644 index 0000000000000000000000000000000000000000..a9bff5f16d4be4b7157d4770a21464e575cbe083 --- /dev/null +++ b/src/share/classes/java/nio/channels/AsynchronousFileChannel.java @@ -0,0 +1,774 @@ +/* + * Copyright 2007-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 java.nio.channels; + +import java.nio.file.*; +import java.nio.file.attribute.FileAttribute; +import java.nio.file.spi.*; +import java.nio.ByteBuffer; +import java.io.IOException; +import java.util.concurrent.Future; +import java.util.concurrent.ExecutorService; +import java.util.Set; +import java.util.HashSet; +import java.util.Collections; + +/** + * An asynchronous channel for reading, writing, and manipulating a file. + * + * <p> An asynchronous file channel is created when a file is opened by invoking + * one of the {@link #open open} methods defined by this class. The file contains + * a variable-length sequence of bytes that can be read and written and whose + * current size can be {@link #size() queried}. The size of the file increases + * when bytes are written beyond its current size; the size of the file decreases + * when it is {@link #truncate truncated}. + * + * <p> An asynchronous file channel does not have a <i>current position</i> + * within the file. Instead, the file position is specified to each read and + * write operation. + * + * <p> In addition to read and write operations, this class defines the + * following operations: </p> + * + * <ul> + * + * <li><p> Updates made to a file may be {@link #force <i>forced + * out</i>} to the underlying storage device, ensuring that data are not + * lost in the event of a system crash. </p></li> + * + * <li><p> A region of a file may be {@link FileLock <i>locked</i>} + * against access by other programs. </p></li> + * + * </ul> + * + * <p> The {@link #read read}, {@link #write write}, and {@link #lock lock} + * methods defined by this class are asynchronous and return a {@link Future} + * to represent the pending result of the operation. This may be used to check + * if the operation has completed, to wait for its completion, and to retrieve + * the result. These method may optionally specify a {@link CompletionHandler} + * that is invoked to consume the result of the I/O operation when it completes. + * + * <p> An {@code AsynchronousFileChannel} is associated with a thread pool to + * which tasks are submitted to handle I/O events and dispatch to completion + * handlers that consume the results of I/O operations on the channel. The + * completion handler for an I/O operation initiated on a channel is guaranteed + * to be invoked by one threads in the thread pool (This ensures that the + * completion handler is run by a thread with the expected <em>identity</em>). + * Where an I/O operation completes immediately, and the initiating thread is + * itself a thread in the thread pool, then the completion handler may be invoked + * directly by the initiating thread. When an {@code AsynchronousFileChannel} is + * created without specifying a thread pool then the channel is associated with + * a system-dependent and default thread pool that may be shared with other + * channels. The default thread pool is configured by the system properties + * defined by the {@link AsynchronousChannelGroup} class. + * + * <p> Channels of this type are safe for use by multiple concurrent threads. The + * {@link Channel#close close} method may be invoked at any time, as specified + * by the {@link Channel} interface. This causes all outstanding asynchronous + * operations on the channel to complete with the exception {@link + * AsynchronousCloseException}. Multiple read and write operations may be + * outstanding at the same time. When multiple read and write operations are + * outstanding then the ordering of the I/O operations, and the order that the + * completion handlers are invoked, is not specified; they are not, in particular, + * guaranteed to execute in the order that the operations were initiated. The + * {@link java.nio.ByteBuffer ByteBuffers} used when reading or writing are not + * safe for use by multiple concurrent I/O operations. Furthermore, after an I/O + * operation is initiated then care should be taken to ensure that the buffer is + * not accessed until after the operation has completed. + * + * <p> As with {@link FileChannel}, the view of a file provided by an instance of + * this class is guaranteed to be consistent with other views of the same file + * provided by other instances in the same program. The view provided by an + * instance of this class may or may not, however, be consistent with the views + * seen by other concurrently-running programs due to caching performed by the + * underlying operating system and delays induced by network-filesystem protocols. + * This is true regardless of the language in which these other programs are + * written, and whether they are running on the same machine or on some other + * machine. The exact nature of any such inconsistencies are system-dependent + * and are therefore unspecified. + * + * @since 1.7 + */ + +public abstract class AsynchronousFileChannel + implements AsynchronousChannel +{ + /** + * Initializes a new instance of this class. + */ + protected AsynchronousFileChannel() { + } + + /** + * Closes this channel. + * + * <p> If this channel is associated with its own thread pool then closing + * the channel causes the thread pool to shutdown after all actively + * executing completion handlers have completed. No attempt is made to stop + * or interrupt actively completion handlers. + * + * <p> This method otherwise behaves exactly as specified by the {@link + * AsynchronousChannel} interface. + * + * @throws IOException {@inheritDoc} + */ + @Override + public abstract void close() throws IOException; + + /** + * Opens or creates a file for reading and/or writing, returning an + * asynchronous file channel to access the file. + * + * <p> The {@code options} parameter determines how the file is opened. + * The {@link StandardOpenOption#READ READ} and {@link StandardOpenOption#WRITE + * WRITE} options determines if the file should be opened for reading and/or + * writing. If neither option is contained in the array then an existing file + * is opened for reading. + * + * <p> In addition to {@code READ} and {@code WRITE}, the following options + * may be present: + * + * <table border=1 cellpadding=5 summary=""> + * <tr> <th>Option</th> <th>Description</th> </tr> + * <tr> + * <td> {@link StandardOpenOption#TRUNCATE_EXISTING TRUNCATE_EXISTING} </td> + * <td> When opening an existing file, the file is first truncated to a + * size of 0 bytes. This option is ignored when the file is opened only + * for reading.</td> + * </tr> + * <tr> + * <td> {@link StandardOpenOption#CREATE_NEW CREATE_NEW} </td> + * <td> If this option is present then a new file is created, failing if + * the file already exists. When creating a file the check for the + * existence of the file and the creation of the file if it does not exist + * is atomic with respect to other file system operations. This option is + * ignored when the file is opened only for reading. </td> + * </tr> + * <tr> + * <td > {@link StandardOpenOption#CREATE CREATE} </td> + * <td> If this option is present then an existing file is opened if it + * exists, otherwise a new file is created. When creating a file the check + * for the existence of the file and the creation of the file if it does + * not exist is atomic with respect to other file system operations. This + * option is ignored if the {@code CREATE_NEW} option is also present or + * the file is opened only for reading. </td> + * </tr> + * <tr> + * <td > {@link StandardOpenOption#DELETE_ON_CLOSE DELETE_ON_CLOSE} </td> + * <td> When this option is present then the implementation makes a + * <em>best effort</em> attempt to delete the file when closed by the + * the {@link #close close} method. If the {@code close} method is not + * invoked then a <em>best effort</em> attempt is made to delete the file + * when the Java virtual machine terminates. </td> + * </tr> + * <tr> + * <td>{@link StandardOpenOption#SPARSE SPARSE} </td> + * <td> When creating a new file this option is a <em>hint</em> that the + * new file will be sparse. This option is ignored when not creating + * a new file. </td> + * </tr> + * <tr> + * <td> {@link StandardOpenOption#SYNC SYNC} </td> + * <td> Requires that every update to the file's content or metadata be + * written synchronously to the underlying storage device. (see <a + * href="../file/package-summary.html#integrity"> Synchronized I/O file + * integrity</a>). </td> + * <tr> + * <tr> + * <td> {@link StandardOpenOption#DSYNC DSYNC} </td> + * <td> Requires that every update to the file's content be written + * synchronously to the underlying storage device. (see <a + * href="../file/package-summary.html#integrity"> Synchronized I/O file + * integrity</a>). </td> + * </tr> + * </table> + * + * <p> An implementation may also support additional options. + * + * <p> The {@code executor} parameter is the {@link ExecutorService} to + * which tasks are submitted to handle I/O events and dispatch completion + * results for operations initiated on resulting channel. + * The nature of these tasks is highly implementation specific and so care + * should be taken when configuring the {@code Executor}. Minimally it + * should support an unbounded work queue and should not run tasks on the + * caller thread of the {@link ExecutorService#execute execute} method. + * {@link #close Closing} the channel results in the orderly {@link + * ExecutorService#shutdown shutdown} of the executor service. Shutting down + * the executor service by other means results in unspecified behavior. + * + * <p> The {@code attrs} parameter is an optional array of file {@link + * FileAttribute file-attributes} to set atomically when creating the file. + * + * <p> The new channel is created by invoking the {@link + * FileSystemProvider#newFileChannel newFileChannel} method on the + * provider that created the {@code Path}. + * + * @param file + * The path of the file to open or create + * @param options + * Options specifying how the file is opened + * @param executor + * The thread pool or {@code null} to associate the channel with + * the default thread pool + * @param attrs + * An optional list of file attributes to set atomically when + * creating the file + * + * @return A new asynchronous file channel + * + * @throws IllegalArgumentException + * If the set contains an invalid combination of options + * @throws UnsupportedOperationException + * If the {@code file} is associated with a provider that does not + * support creating asynchronous file channels, or an unsupported + * open option is specified, or the array contains an attribute that + * cannot be set atomically when creating the file + * @throws IOException + * If an I/O error occurs + * @throws SecurityException + * If a security manager is installed and it denies an + * unspecified permission required by the implementation. + * In the case of the default provider, the {@link + * SecurityManager#checkRead(String)} method is invoked to check + * read access if the file is opened for reading. The {@link + * SecurityManager#checkWrite(String)} method is invoked to check + * write access if the file is opened for writing + */ + public static AsynchronousFileChannel open(Path file, + Set<? extends OpenOption> options, + ExecutorService executor, + FileAttribute<?>... attrs) + throws IOException + { + FileSystemProvider provider = file.getFileSystem().provider(); + return provider.newAsynchronousFileChannel(file, options, executor, attrs); + } + + private static final FileAttribute<?>[] NO_ATTRIBUTES = new FileAttribute[0]; + + /** + * Opens or creates a file for reading and/or writing, returning an + * asynchronous file channel to access the file. + * + * <p> An invocation of this method behaves in exactly the same way as the + * invocation + * <pre> + * ch.{@link #open(Path,Set,ExecutorService,FileAttribute[]) open}(file, opts, null, new FileAttribute<?>[0]); + * </pre> + * where {@code opts} is a {@code Set} containing the options specified to + * this method. + * + * <p> The resulting channel is associated with default thread pool to which + * tasks are submitted to handle I/O events and dispatch to completion + * handlers that consume the result of asynchronous operations performed on + * the resulting channel. + * + * @param file + * The path of the file to open or create + * @param options + * Options specifying how the file is opened + * + * @return A new asynchronous file channel + * + * @throws IllegalArgumentException + * If the set contains an invalid combination of options + * @throws UnsupportedOperationException + * If the {@code file} is associated with a provider that does not + * support creating file channels, or an unsupported open option is + * specified + * @throws IOException + * If an I/O error occurs + * @throws SecurityException + * If a security manager is installed and it denies an + * unspecified permission required by the implementation. + * In the case of the default provider, the {@link + * SecurityManager#checkRead(String)} method is invoked to check + * read access if the file is opened for reading. The {@link + * SecurityManager#checkWrite(String)} method is invoked to check + * write access if the file is opened for writing + */ + public static AsynchronousFileChannel open(Path file, OpenOption... options) + throws IOException + { + Set<OpenOption> set = new HashSet<OpenOption>(options.length); + Collections.addAll(set, options); + return open(file, set, null, NO_ATTRIBUTES); + } + + /** + * Returns the current size of this channel's file. + * + * @return The current size of this channel's file, measured in bytes + * + * @throws ClosedChannelException + * If this channel is closed + * @throws IOException + * If some other I/O error occurs + */ + public abstract long size() throws IOException; + + /** + * Truncates this channel's file to the given size. + * + * <p> If the given size is less than the file's current size then the file + * is truncated, discarding any bytes beyond the new end of the file. If + * the given size is greater than or equal to the file's current size then + * the file is not modified. </p> + * + * @param size + * The new size, a non-negative byte count + * + * @return This file channel + * + * @throws NonWritableChannelException + * If this channel was not opened for writing + * + * @throws ClosedChannelException + * If this channel is closed + * + * @throws IllegalArgumentException + * If the new size is negative + * + * @throws IOException + * If some other I/O error occurs + */ + public abstract AsynchronousFileChannel truncate(long size) throws IOException; + + /** + * Forces any updates to this channel's file to be written to the storage + * device that contains it. + * + * <p> If this channel's file resides on a local storage device then when + * this method returns it is guaranteed that all changes made to the file + * since this channel was created, or since this method was last invoked, + * will have been written to that device. This is useful for ensuring that + * critical information is not lost in the event of a system crash. + * + * <p> If the file does not reside on a local device then no such guarantee + * is made. + * + * <p> The {@code metaData} parameter can be used to limit the number of + * I/O operations that this method is required to perform. Passing + * {@code false} for this parameter indicates that only updates to the + * file's content need be written to storage; passing {@code true} + * indicates that updates to both the file's content and metadata must be + * written, which generally requires at least one more I/O operation. + * Whether this parameter actually has any effect is dependent upon the + * underlying operating system and is therefore unspecified. + * + * <p> Invoking this method may cause an I/O operation to occur even if the + * channel was only opened for reading. Some operating systems, for + * example, maintain a last-access time as part of a file's metadata, and + * this time is updated whenever the file is read. Whether or not this is + * actually done is system-dependent and is therefore unspecified. + * + * <p> This method is only guaranteed to force changes that were made to + * this channel's file via the methods defined in this class. + * + * @param metaData + * If {@code true} then this method is required to force changes + * to both the file's content and metadata to be written to + * storage; otherwise, it need only force content changes to be + * written + * + * @throws ClosedChannelException + * If this channel is closed + * + * @throws IOException + * If some other I/O error occurs + */ + public abstract void force(boolean metaData) throws IOException; + + /** + * Acquires a lock on the given region of this channel's file. + * + * <p> This method initiates an operation to acquire a lock on the given region + * of this channel's file. The method returns a {@code Future} representing + * the pending result of the operation. Its {@link Future#get() get} + * method returns the {@link FileLock} on successful completion. + * + * <p> The region specified by the {@code position} and {@code size} + * parameters need not be contained within, or even overlap, the actual + * underlying file. Lock regions are fixed in size; if a locked region + * initially contains the end of the file and the file grows beyond the + * region then the new portion of the file will not be covered by the lock. + * If a file is expected to grow in size and a lock on the entire file is + * required then a region starting at zero, and no smaller than the + * expected maximum size of the file, should be locked. The two-argument + * {@link #lock(Object,CompletionHandler)} method simply locks a region + * of size {@link Long#MAX_VALUE}. If a lock that overlaps the requested + * region is already held by this Java virtual machine, or this method has + * been invoked to lock an overlapping region and that operation has not + * completed, then this method throws {@link OverlappingFileLockException}. + * + * <p> Some operating systems do not support a mechanism to acquire a file + * lock in an asynchronous manner. Consequently an implementation may + * acquire the file lock in a background thread or from a task executed by + * a thread in the associated thread pool. If there are many lock operations + * outstanding then it may consume threads in the Java virtual machine for + * indefinite periods. + * + * <p> Some operating systems do not support shared locks, in which case a + * request for a shared lock is automatically converted into a request for + * an exclusive lock. Whether the newly-acquired lock is shared or + * exclusive may be tested by invoking the resulting lock object's {@link + * FileLock#isShared() isShared} method. + * + * <p> File locks are held on behalf of the entire Java virtual machine. + * They are not suitable for controlling access to a file by multiple + * threads within the same virtual machine. + * + * @param position + * The position at which the locked region is to start; must be + * non-negative + * @param size + * The size of the locked region; must be non-negative, and the sum + * {@code position} + {@code size} must be non-negative + * @param shared + * {@code true} to request a shared lock, in which case this + * channel must be open for reading (and possibly writing); + * {@code false} to request an exclusive lock, in which case this + * channel must be open for writing (and possibly reading) + * @param attachment + * The object to attach to the I/O operation; can be {@code null} + * @param handler + * The handler for consuming the result; can be {@code null} + * + * @return a {@code Future} object representing the pending result + * + * @throws OverlappingFileLockException + * If a lock that overlaps the requested region is already held by + * this Java virtual machine, or there is already a pending attempt + * to lock an overlapping region + * @throws IllegalArgumentException + * If the preconditions on the parameters do not hold + * @throws NonReadableChannelException + * If {@code shared} is true this channel but was not opened for reading + * @throws NonWritableChannelException + * If {@code shared} is false but this channel was not opened for writing + * @throws ShutdownChannelGroupException + * If a handler is specified, the channel is closed, and the channel + * was originally created with its own thread pool + */ + public abstract <A> Future<FileLock> lock(long position, + long size, + boolean shared, + A attachment, + CompletionHandler<FileLock,? super A> handler); + + /** + * Acquires an exclusive lock on this channel's file. + * + * <p> This method initiates an operation to acquire an exclusive lock on this + * channel's file. The method returns a {@code Future} representing + * the pending result of the operation. Its {@link Future#get() get} + * method returns the {@link FileLock} on successful completion. + * + * <p> An invocation of this method of the form {@code ch.lock(att,handler)} + * behaves in exactly the same way as the invocation + * <pre> + * ch.{@link #lock(long,long,boolean,Object,CompletionHandler) lock}(0L, Long.MAX_VALUE, false, att, handler) + * </pre> + * + * @param attachment + * The object to attach to the I/O operation; can be {@code null} + * @param handler + * The handler for consuming the result; can be {@code null} + * + * @return a {@code Future} object representing the pending result + * + * @throws OverlappingFileLockException + * If a lock is already held by this Java virtual machine, or there + * is already a pending attempt to lock a region + * @throws NonWritableChannelException + * If this channel was not opened for writing + * @throws ShutdownChannelGroupException + * If a handler is specified, the channel is closed, and the channel + * was originally created with its own thread pool + */ + public final <A> Future<FileLock> lock(A attachment, + CompletionHandler<FileLock,? super A> handler) + { + return lock(0L, Long.MAX_VALUE, false, attachment, handler); + } + + /** + * Acquires an exclusive lock on this channel's file. + * + * <p> This method initiates an operation to acquire an exclusive lock on this + * channel's file. The method returns a {@code Future} representing the + * pending result of the operation. Its {@link Future#get() get} method + * returns the {@link FileLock} on successful completion. + * + * <p> An invocation of this method behaves in exactly the same way as the + * invocation + * <pre> + * ch.{@link #lock(long,long,boolean,Object,CompletionHandler) lock}(0L, Long.MAX_VALUE, false, null, null) + * </pre> + * + * @return A {@code Future} object representing the pending result + * + * @throws OverlappingFileLockException + * If a lock is already held by this Java virtual machine, or there + * is already a pending attempt to lock a region + * @throws NonWritableChannelException + * If this channel was not opened for writing + */ + public final Future<FileLock> lock() { + return lock(0L, Long.MAX_VALUE, false, null, null); + } + + /** + * Attempts to acquire a lock on the given region of this channel's file. + * + * <p> This method does not block. An invocation always returns immediately, + * either having acquired a lock on the requested region or having failed to + * do so. If it fails to acquire a lock because an overlapping lock is held + * by another program then it returns {@code null}. If it fails to acquire + * a lock for any other reason then an appropriate exception is thrown. + * + * @param position + * The position at which the locked region is to start; must be + * non-negative + * + * @param size + * The size of the locked region; must be non-negative, and the sum + * {@code position} + {@code size} must be non-negative + * + * @param shared + * {@code true} to request a shared lock, + * {@code false} to request an exclusive lock + * + * @return A lock object representing the newly-acquired lock, + * or {@code null} if the lock could not be acquired + * because another program holds an overlapping lock + * + * @throws IllegalArgumentException + * If the preconditions on the parameters do not hold + * @throws ClosedChannelException + * If this channel is closed + * @throws OverlappingFileLockException + * If a lock that overlaps the requested region is already held by + * this Java virtual machine, or if another thread is already + * blocked in this method and is attempting to lock an overlapping + * region of the same file + * @throws NonReadableChannelException + * If {@code shared} is true this channel but was not opened for reading + * @throws NonWritableChannelException + * If {@code shared} is false but this channel was not opened for writing + * + * @throws IOException + * If some other I/O error occurs + * + * @see #lock(Object,CompletionHandler) + * @see #lock(long,long,boolean,Object,CompletionHandler) + * @see #tryLock() + */ + public abstract FileLock tryLock(long position, long size, boolean shared) + throws IOException; + + /** + * Attempts to acquire an exclusive lock on this channel's file. + * + * <p> An invocation of this method of the form {@code ch.tryLock()} + * behaves in exactly the same way as the invocation + * + * <pre> + * ch.{@link #tryLock(long,long,boolean) tryLock}(0L, Long.MAX_VALUE, false) </pre> + * + * @return A lock object representing the newly-acquired lock, + * or {@code null} if the lock could not be acquired + * because another program holds an overlapping lock + * + * @throws ClosedChannelException + * If this channel is closed + * @throws OverlappingFileLockException + * If a lock that overlaps the requested region is already held by + * this Java virtual machine, or if another thread is already + * blocked in this method and is attempting to lock an overlapping + * region + * @throws NonWritableChannelException + * If {@code shared} is false but this channel was not opened for writing + * + * @throws IOException + * If some other I/O error occurs + * + * @see #lock(Object,CompletionHandler) + * @see #lock(long,long,boolean,Object,CompletionHandler) + * @see #tryLock(long,long,boolean) + */ + public final FileLock tryLock() throws IOException { + return tryLock(0L, Long.MAX_VALUE, false); + } + + /** + * Reads a sequence of bytes from this channel into the given buffer, + * starting at the given file position. + * + * <p> This method initiates the reading of a sequence of bytes from this + * channel into the given buffer, starting at the given file position. This + * method returns a {@code Future} representing the pending result of the + * operation. The Future's {@link Future#get() get} method returns the + * number of bytes read or {@code -1} if the given position is greater than + * or equal to the file's size at the time that the read is attempted. + * + * <p> This method works in the same manner as the {@link + * AsynchronousByteChannel#read(ByteBuffer,Object,CompletionHandler)} + * method, except that bytes are read starting at the given file position. + * If the given file position is greater than the file's size at the time + * that the read is attempted then no bytes are read. + * + * @param dst + * The buffer into which bytes are to be transferred + * @param position + * The file position at which the transfer is to begin; + * must be non-negative + * @param attachment + * The object to attach to the I/O operation; can be {@code null} + * @param handler + * The handler for consuming the result; can be {@code null} + * + * @return A {@code Future} object representing the pending result + * + * @throws IllegalArgumentException + * If the position is negative or the buffer is read-only + * @throws NonReadableChannelException + * If this channel was not opened for reading + * @throws ShutdownChannelGroupException + * If a handler is specified, the channel is closed, and the channel + * was originally created with its own thread pool + */ + public abstract <A> Future<Integer> read(ByteBuffer dst, + long position, + A attachment, + CompletionHandler<Integer,? super A> handler); + + /** + * Reads a sequence of bytes from this channel into the given buffer, + * starting at the given file position. + * + * <p> This method initiates the reading of a sequence of bytes from this + * channel into the given buffer, starting at the given file position. This + * method returns a {@code Future} representing the pending result of the + * operation. The Future's {@link Future#get() get} method returns the + * number of bytes read or {@code -1} if the given position is greater + * than or equal to the file's size at the time that the read is attempted. + * + * <p> This method is equivalent to invoking {@link + * #read(ByteBuffer,long,Object,CompletionHandler)} with the {@code attachment} + * and handler parameters set to {@code null}. + * + * @param dst + * The buffer into which bytes are to be transferred + * @param position + * The file position at which the transfer is to begin; + * must be non-negative + * + * @return A {@code Future} object representing the pending result + * + * @throws IllegalArgumentException + * If the position is negative or the buffer is read-only + * @throws NonReadableChannelException + * If this channel was not opened for reading + */ + public final Future<Integer> read(ByteBuffer dst, long position) { + return read(dst, position, null, null); + } + + /** + * Writes a sequence of bytes to this channel from the given buffer, starting + * at the given file position. + * + * <p> This method initiates the writing of a sequence of bytes to this channel + * from the given buffer, starting at the given file position. The method + * returns a {@code Future} representing the pending result of the write + * operation. The Future's {@link Future#get() get} method returns the + * number of bytes written. + * + * <p> This method works in the same manner as the {@link + * AsynchronousByteChannel#write(ByteBuffer,Object,CompletionHandler)} + * method, except that bytes are written starting at the given file position. + * If the given position is greater than the file's size, at the time that + * the write is attempted, then the file will be grown to accommodate the new + * bytes; the values of any bytes between the previous end-of-file and the + * newly-written bytes are unspecified. + * + * @param src + * The buffer from which bytes are to be transferred + * @param position + * The file position at which the transfer is to begin; + * must be non-negative + * @param attachment + * The object to attach to the I/O operation; can be {@code null} + * @param handler + * The handler for consuming the result; can be {@code null} + * + * @return A {@code Future} object representing the pending result + * + * @throws IllegalArgumentException + * If the position is negative + * @throws NonWritableChannelException + * If this channel was not opened for writing + * @throws ShutdownChannelGroupException + * If a handler is specified, the channel is closed, and the channel + * was originally created with its own thread pool + */ + public abstract <A> Future<Integer> write(ByteBuffer src, + long position, + A attachment, + CompletionHandler<Integer,? super A> handler); + + /** + * Writes a sequence of bytes to this channel from the given buffer, starting + * at the given file position. + * + * <p> This method initiates the writing of a sequence of bytes to this channel + * from the given buffer, starting at the given file position. The method + * returns a {@code Future} representing the pending result of the write + * operation. The Future's {@link Future#get() get} method returns the + * number of bytes written. + * + * <p> This method is equivalent to invoking {@link + * #write(ByteBuffer,long,Object,CompletionHandler)} with the {@code attachment} + * and handler parameters set to {@code null}. + * + * @param src + * The buffer from which bytes are to be transferred + * @param position + * The file position at which the transfer is to begin; + * must be non-negative + * + * @return A {@code Future} object representing the pending result + * + * @throws IllegalArgumentException + * If the position is negative + * @throws NonWritableChannelException + * If this channel was not opened for writing + */ + public final Future<Integer> write(ByteBuffer src, long position) { + return write(src, position, null, null); + } +} diff --git a/src/share/classes/java/nio/channels/AsynchronousServerSocketChannel.java b/src/share/classes/java/nio/channels/AsynchronousServerSocketChannel.java new file mode 100644 index 0000000000000000000000000000000000000000..99c56fa59c0f69fb91c83dad385f5df3908e2a1a --- /dev/null +++ b/src/share/classes/java/nio/channels/AsynchronousServerSocketChannel.java @@ -0,0 +1,303 @@ +/* + * Copyright 2007-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 java.nio.channels; + +import java.nio.channels.spi.*; +import java.net.SocketOption; +import java.net.SocketAddress; +import java.util.concurrent.Future; +import java.io.IOException; + +/** + * An asynchronous channel for stream-oriented listening sockets. + * + * <p> An asynchronous server-socket channel is created by invoking the + * {@link #open open} method of this class. + * A newly-created asynchronous server-socket channel is open but not yet bound. + * It can be bound to a local address and configured to listen for connections + * by invoking the {@link #bind(SocketAddress,int) bind} method. Once bound, + * the {@link #accept(Object,CompletionHandler) accept} method + * is used to initiate the accepting of connections to the channel's socket. + * An attempt to invoke the <tt>accept</tt> method on an unbound channel will + * cause a {@link NotYetBoundException} to be thrown. + * + * <p> Channels of this type are safe for use by multiple concurrent threads + * though at most one accept operation can be outstanding at any time. + * If a thread initiates an accept operation before a previous accept operation + * has completed then an {@link AcceptPendingException} will be thrown. + * + * <p> Socket options are configured using the {@link #setOption(SocketOption,Object) + * setOption} method. Channels of this type support the following options: + * <blockquote> + * <table border> + * <tr> + * <th>Option Name</th> + * <th>Description</th> + * </tr> + * <tr> + * <td> {@link java.net.StandardSocketOption#SO_RCVBUF SO_RCVBUF} </td> + * <td> The size of the socket receive buffer </td> + * </tr> + * <tr> + * <td> {@link java.net.StandardSocketOption#SO_REUSEADDR SO_REUSEADDR} </td> + * <td> Re-use address </td> + * </tr> + * </table> + * </blockquote> + * Additional (implementation specific) options may also be supported. + * + * <p> <b>Usage Example:</b> + * <pre> + * final AsynchronousServerSocketChannel listener = + * AsynchronousServerSocketChannel.open().bind(new InetSocketAddress(5000)); + * + * listener.accept(null, new CompletionHandler<AsynchronousSocketChannel,Void>() { + * public void completed(AsynchronousSocketChannel ch, Void att) { + * // accept the next connection + * listener.accept(null, this); + * + * // handle this connection + * handle(ch); + * } + * public void failed(Throwable exc, Void att) { + * ... + * } + * public void cancelled(Void att) { + * ... + * } + * }); + * </pre> + * + * @since 1.7 + */ + +public abstract class AsynchronousServerSocketChannel + implements AsynchronousChannel, NetworkChannel +{ + private final AsynchronousChannelProvider provider; + + /** + * Initializes a new instance of this class. + */ + protected AsynchronousServerSocketChannel(AsynchronousChannelProvider provider) { + this.provider = provider; + } + + /** + * Returns the provider that created this channel. + */ + public final AsynchronousChannelProvider provider() { + return provider; + } + + /** + * Opens an asynchronous server-socket channel. + * + * <p> The new channel is created by invoking the {@link + * java.nio.channels.spi.AsynchronousChannelProvider#openAsynchronousServerSocketChannel + * openAsynchronousServerSocketChannel} method on the {@link + * java.nio.channels.spi.AsynchronousChannelProvider} object that created + * the given group. If the group parameter is <tt>null</tt> then the + * resulting channel is created by the system-wide default provider, and + * bound to the <em>default group</em>. + * + * @param group + * The group to which the newly constructed channel should be bound, + * or <tt>null</tt> for the default group + * + * @return A new asynchronous server socket channel + * + * @throws ShutdownChannelGroupException + * If the channel group is shutdown + * @throws IOException + * If an I/O error occurs + */ + public static AsynchronousServerSocketChannel open(AsynchronousChannelGroup group) + throws IOException + { + AsynchronousChannelProvider provider = (group == null) ? + AsynchronousChannelProvider.provider() : group.provider(); + return provider.openAsynchronousServerSocketChannel(group); + } + + /** + * Opens an asynchronous server-socket channel. + * + * <p> This method returns an asynchronous server socket channel that is + * bound to the <em>default group</em>. This method is equivalent to evaluating + * the expression: + * <blockquote><pre> + * open((AsynchronousChannelGroup)null); + * </pre></blockquote> + * + * @return A new asynchronous server socket channel + * + * @throws IOException + * If an I/O error occurs + */ + public static AsynchronousServerSocketChannel open() + throws IOException + { + return open(null); + } + + /** + * Binds the channel's socket to a local address and configures the socket to + * listen for connections. + * + * <p> An invocation of this method is equivalent to the following: + * <blockquote><pre> + * bind(local, 0); + * </pre></blockquote> + * + * @param local + * The local address to bind the socket, or <tt>null</tt> to bind + * to an automatically assigned socket address + * + * @return This channel + * + * @throws AlreadyBoundException {@inheritDoc} + * @throws UnsupportedAddressTypeException {@inheritDoc} + * @throws SecurityException {@inheritDoc} + * @throws ClosedChannelException {@inheritDoc} + * @throws IOException {@inheritDoc} + */ + public final AsynchronousServerSocketChannel bind(SocketAddress local) + throws IOException + { + return bind(local, 0); + } + + /** + * Binds the channel's socket to a local address and configures the socket to + * listen for connections. + * + * <p> This method is used to establish an association between the socket and + * a local address. Once an association is established then the socket remains + * bound until the associated channel is closed. + * + * <p> The {@code backlog} parameter is the maximum number of pending + * connections on the socket. Its exact semantics are implementation specific. + * In particular, an implementation may impose a maximum length or may choose + * to ignore the parameter altogther. If the {@code backlog} parameter has + * the value {@code 0}, or a negative value, then an implementation specific + * default is used. + * + * @param local + * The local address to bind the socket, or {@code null} to bind + * to an automatically assigned socket address + * @param backlog + * The maximum number of pending connections + * + * @return This channel + * + * @throws AlreadyBoundException + * If the socket is already bound + * @throws UnsupportedAddressTypeException + * If the type of the given address is not supported + * @throws SecurityException + * If a security manager has been installed and its {@link + * SecurityManager#checkListen checkListen} method denies the operation + * @throws ClosedChannelException + * If the channel is closed + * @throws IOException + * If some other I/O error occurs + */ + public abstract AsynchronousServerSocketChannel bind(SocketAddress local, int backlog) + throws IOException; + + /** + * @throws IllegalArgumentException {@inheritDoc} + * @throws ClosedChannelException {@inheritDoc} + * @throws IOException {@inheritDoc} + */ + public abstract <T> AsynchronousServerSocketChannel setOption(SocketOption<T> name, T value) + throws IOException; + + /** + * Accepts a connection. + * + * <p> This method initiates accepting a connection made to this channel's + * socket, returning a {@link Future} representing the pending result + * of the operation. The {@code Future}'s {@link Future#get() get} + * method will return the {@link AsynchronousSocketChannel} for the new + * connection on successful completion. + * + * <p> When a new connection is accepted then the resulting {@code + * AsynchronousSocketChannel} will be bound to the same {@link + * AsynchronousChannelGroup} as this channel. If the group is {@link + * AsynchronousChannelGroup#isShutdown shutdown} and a connection is accepted, + * then the connection is closed, and the operation completes with an {@code + * IOException} and cause {@link ShutdownChannelGroupException}. + * + * <p> To allow for concurrent handling of new connections, the completion + * handler is not invoked directly by the initiating thread when a new + * connection is accepted immediately (see <a + * href="AsynchronousChannelGroup.html#threading">Threading<a>). + * + * <p> If a security manager has been installed then it verifies that the + * address and port number of the connection's remote endpoint are permitted + * by the security manager's {@link SecurityManager#checkAccept checkAccept} + * method. The permission check is performed with privileges that are restricted + * by the calling context of this method. If the permission check fails then + * the connection is closed and the operation completes with a {@link + * SecurityException}. + * + * @param attachment + * The object to attach to the I/O operation; can be {@code null} + * @param handler + * The handler for consuming the result; can be {@code null} + * + * @return an <tt>Future</tt> object representing the pending result + * + * @throws AcceptPendingException + * If an accept operation is already in progress on this channel + * @throws NotYetBoundException + * If this channel's socket has not yet been bound + * @throws ShutdownChannelGroupException + * If a handler is specified, and the channel group is shutdown + */ + public abstract <A> Future<AsynchronousSocketChannel> + accept(A attachment, CompletionHandler<AsynchronousSocketChannel,? super A> handler); + + /** + * Accepts a connection. + * + * <p> This method is equivalent to invoking {@link + * #accept(Object,CompletionHandler)} with the {@code attachment} + * and {@code handler} parameters set to {@code null}. + * + * @return an <tt>Future</tt> object representing the pending result + * + * @throws AcceptPendingException + * If an accept operation is already in progress on this channel + * @throws NotYetBoundException + * If this channel's socket has not yet been bound + */ + public final Future<AsynchronousSocketChannel> accept() { + return accept(null, null); + } +} diff --git a/src/share/classes/java/nio/channels/AsynchronousSocketChannel.java b/src/share/classes/java/nio/channels/AsynchronousSocketChannel.java new file mode 100644 index 0000000000000000000000000000000000000000..b6a5da8105dc10cbe4169c8a2776d114541486c4 --- /dev/null +++ b/src/share/classes/java/nio/channels/AsynchronousSocketChannel.java @@ -0,0 +1,670 @@ +/* + * Copyright 2007-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 java.nio.channels; + +import java.nio.channels.spi.*; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.Future; +import java.io.IOException; +import java.net.SocketOption; +import java.net.SocketAddress; +import java.nio.ByteBuffer; + +/** + * An asynchronous channel for stream-oriented connecting sockets. + * + * <p> Asynchronous socket channels are created in one of two ways. A newly-created + * {@code AsynchronousSocketChannel} is created by invoking one of the {@link + * #open open} methods defined by this class. A newly-created channel is open but + * not yet connected. A connected {@code AsynchronousSocketChannel} is created + * when a connection is made to the socket of an {@link AsynchronousServerSocketChannel}. + * It is not possible to create an asynchronous socket channel for an arbitrary, + * pre-existing {@link java.net.Socket socket}. + * + * <p> A newly-created channel is connected by invoking its {@link #connect connect} + * method; once connected, a channel remains connected until it is closed. Whether + * or not a socket channel is connected may be determined by invoking its {@link + * #getRemoteAddress getRemoteAddress} method. An attempt to invoke an I/O + * operation upon an unconnected channel will cause a {@link NotYetConnectedException} + * to be thrown. + * + * <p> Channels of this type are safe for use by multiple concurrent threads. + * They support concurrent reading and writing, though at most one read operation + * and one write operation can be outstanding at any time. + * If a thread initiates a read operation before a previous read operation has + * completed then a {@link ReadPendingException} will be thrown. Similarly, an + * attempt to initiate a write operation before a previous write has completed + * will throw a {@link WritePendingException}. + * + * <p> Socket options are configured using the {@link #setOption(SocketOption,Object) + * setOption} method. Asynchronous socket channels support the following options: + * <blockquote> + * <table border> + * <tr> + * <th>Option Name</th> + * <th>Description</th> + * </tr> + * <tr> + * <td> {@link java.net.StandardSocketOption#SO_SNDBUF SO_SNDBUF} </td> + * <td> The size of the socket send buffer </td> + * </tr> + * <tr> + * <td> {@link java.net.StandardSocketOption#SO_RCVBUF SO_RCVBUF} </td> + * <td> The size of the socket receive buffer </td> + * </tr> + * <tr> + * <td> {@link java.net.StandardSocketOption#SO_KEEPALIVE SO_KEEPALIVE} </td> + * <td> Keep connection alive </td> + * </tr> + * <tr> + * <td> {@link java.net.StandardSocketOption#SO_REUSEADDR SO_REUSEADDR} </td> + * <td> Re-use address </td> + * </tr> + * <tr> + * <td> {@link java.net.StandardSocketOption#TCP_NODELAY TCP_NODELAY} </td> + * <td> Disable the Nagle algorithm </td> + * </tr> + * </table> + * </blockquote> + * Additional (implementation specific) options may also be supported. + * + * <h4>Timeouts</h4> + * + * <p> The {@link #read(ByteBuffer,long,TimeUnit,Object,CompletionHandler) read} + * and {@link #write(ByteBuffer,long,TimeUnit,Object,CompletionHandler) write} + * methods defined by this class allow a timeout to be specified when initiating + * a read or write operation. If the timeout elapses before an operation completes + * then the operation completes with the exception {@link + * InterruptedByTimeoutException}. A timeout may leave the channel, or the + * underlying connection, in an inconsistent state. Where the implementation + * cannot guarantee that bytes have not been read from the channel then it puts + * the channel into an implementation specific <em>error state</em>. A subsequent + * attempt to initiate a {@code read} operation causes an unspecified runtime + * exception to be thrown. Similarly if a {@code write} operation times out and + * the implementation cannot guarantee bytes have not been written to the + * channel then further attempts to {@code write} to the channel cause an + * unspecified runtime exception to be thrown. When a timeout elapses then the + * state of the {@link ByteBuffer}, or the sequence of buffers, for the I/O + * operation is not defined. Buffers should be discarded or at least care must + * be taken to ensure that the buffers are not accessed while the channel remains + * open. + * + * @since 1.7 + */ + +public abstract class AsynchronousSocketChannel + implements AsynchronousByteChannel, NetworkChannel +{ + private final AsynchronousChannelProvider provider; + + /** + * Initializes a new instance of this class. + */ + protected AsynchronousSocketChannel(AsynchronousChannelProvider provider) { + this.provider = provider; + } + + /** + * Returns the provider that created this channel. + */ + public final AsynchronousChannelProvider provider() { + return provider; + } + + /** + * Opens an asynchronous socket channel. + * + * <p> The new channel is created by invoking the {@link + * AsynchronousChannelProvider#openAsynchronousSocketChannel + * openAsynchronousSocketChannel} method on the {@link + * AsynchronousChannelProvider} that created the group. If the group parameter + * is {@code null} then the resulting channel is created by the system-wide + * default provider, and bound to the <em>default group</em>. + * + * @param group + * The group to which the newly constructed channel should be bound, + * or {@code null} for the default group + * + * @return A new asynchronous socket channel + * + * @throws ShutdownChannelGroupException + * If the channel group is shutdown + * @throws IOException + * If an I/O error occurs + */ + public static AsynchronousSocketChannel open(AsynchronousChannelGroup group) + throws IOException + { + AsynchronousChannelProvider provider = (group == null) ? + AsynchronousChannelProvider.provider() : group.provider(); + return provider.openAsynchronousSocketChannel(group); + } + + /** + * Opens an asynchronous socket channel. + * + * <p> This method returns an asynchronous socket channel that is bound to + * the <em>default group</em>.This method is equivalent to evaluating the + * expression: + * <blockquote><pre> + * open((AsynchronousChannelGroup)null); + * </pre></blockquote> + * + * @return A new asynchronous socket channel + * + * @throws IOException + * If an I/O error occurs + */ + public static AsynchronousSocketChannel open() + throws IOException + { + return open(null); + } + + + // -- socket options and related -- + + /** + * @throws ConnectionPendingException + * If a connection operation is already in progress on this channel + * @throws AlreadyBoundException {@inheritDoc} + * @throws UnsupportedAddressTypeException {@inheritDoc} + * @throws ClosedChannelException {@inheritDoc} + * @throws IOException {@inheritDoc} + */ + @Override + public abstract AsynchronousSocketChannel bind(SocketAddress local) + throws IOException; + + /** + * @throws IllegalArgumentException {@inheritDoc} + * @throws ClosedChannelException {@inheritDoc} + * @throws IOException {@inheritDoc} + */ + @Override + public abstract <T> AsynchronousSocketChannel setOption(SocketOption<T> name, T value) + throws IOException; + + /** + * Shutdown the connection for reading without closing the channel. + * + * <p> Once shutdown for reading then further reads on the channel will + * return {@code -1}, the end-of-stream indication. If the input side of the + * connection is already shutdown then invoking this method has no effect. + * The effect on an outstanding read operation is system dependent and + * therefore not specified. The effect, if any, when there is data in the + * socket receive buffer that has not been read, or data arrives subsequently, + * is also system dependent. + * + * @return The channel + * + * @throws NotYetConnectedException + * If this channel is not yet connected + * @throws ClosedChannelException + * If this channel is closed + * @throws IOException + * If some other I/O error occurs + */ + public abstract AsynchronousSocketChannel shutdownInput() throws IOException; + + /** + * Shutdown the connection for writing without closing the channel. + * + * <p> Once shutdown for writing then further attempts to write to the + * channel will throw {@link ClosedChannelException}. If the output side of + * the connection is already shutdown then invoking this method has no + * effect. The effect on an outstanding write operation is system dependent + * and therefore not specified. + * + * @return The channel + * + * @throws NotYetConnectedException + * If this channel is not yet connected + * @throws ClosedChannelException + * If this channel is closed + * @throws IOException + * If some other I/O error occurs + */ + public abstract AsynchronousSocketChannel shutdownOutput() throws IOException; + + // -- state -- + + /** + * Returns the remote address to which this channel's socket is connected. + * + * <p> Where the channel is bound and connected to an Internet Protocol + * socket address then the return value from this method is of type {@link + * java.net.InetSocketAddress}. + * + * @return The remote address; {@code null} if the channel's socket is not + * connected + * + * @throws ClosedChannelException + * If the channel is closed + * @throws IOException + * If an I/O error occurs + */ + public abstract SocketAddress getRemoteAddress() throws IOException; + + // -- asynchronous operations -- + + /** + * Connects this channel. + * + * <p> This method initiates an operation to connect this channel, returning + * a {@code Future} representing the pending result of the operation. If + * the connection is successfully established then the {@code Future}'s + * {@link Future#get() get} method will return {@code null}. If the + * connection cannot be established then the channel is closed. In that case, + * invoking the {@code get} method throws {@link + * java.util.concurrent.ExecutionException} with an {@code IOException} as + * the cause. + * + * <p> This method performs exactly the same security checks as the {@link + * java.net.Socket} class. That is, if a security manager has been + * installed then this method verifies that its {@link + * java.lang.SecurityManager#checkConnect checkConnect} method permits + * connecting to the address and port number of the given remote endpoint. + * + * @param remote + * The remote address to which this channel is to be connected + * @param attachment + * The object to attach to the I/O operation; can be {@code null} + * @param handler + * The handler for consuming the result; can be {@code null} + * + * @return A {@code Future} object representing the pending result + * + * @throws UnresolvedAddressException + * If the given remote address is not fully resolved + * @throws UnsupportedAddressTypeException + * If the type of the given remote address is not supported + * @throws AlreadyConnectedException + * If this channel is already connected + * @throws ConnectionPendingException + * If a connection operation is already in progress on this channel + * @throws ShutdownChannelGroupException + * If a handler is specified, and the channel group is shutdown + * @throws SecurityException + * If a security manager has been installed + * and it does not permit access to the given remote endpoint + * + * @see #getRemoteAddress + */ + public abstract <A> Future<Void> connect(SocketAddress remote, + A attachment, + CompletionHandler<Void,? super A> handler); + + /** + * Connects this channel. + * + * <p> This method is equivalent to invoking {@link + * #connect(SocketAddress,Object,CompletionHandler)} with the {@code attachment} + * and handler parameters set to {@code null}. + * + * @param remote + * The remote address to which this channel is to be connected + * + * @return A {@code Future} object representing the pending result + * + * @throws UnresolvedAddressException + * If the given remote address is not fully resolved + * @throws UnsupportedAddressTypeException + * If the type of the given remote address is not supported + * @throws AlreadyConnectedException + * If this channel is already connected + * @throws ConnectionPendingException + * If a connection operation is already in progress on this channel + * @throws SecurityException + * If a security manager has been installed + * and it does not permit access to the given remote endpoint + */ + public final Future<Void> connect(SocketAddress remote) { + return connect(remote, null, null); + } + + /** + * Reads a sequence of bytes from this channel into the given buffer. + * + * <p> This method initiates the reading of a sequence of bytes from this + * channel into the given buffer, returning a {@code Future} representing + * the pending result of the operation. The {@code Future}'s {@link + * Future#get() get} method returns the number of bytes read or {@code -1} + * if all bytes have been read and channel has reached end-of-stream. + * + * <p> If a timeout is specified and the timeout elapses before the operation + * completes then the operation completes with the exception {@link + * InterruptedByTimeoutException}. Where a timeout occurs, and the + * implementation cannot guarantee that bytes have not been read, or will not + * be read from the channel into the given buffer, then further attempts to + * read from the channel will cause an unspecific runtime exception to be + * thrown. + * + * <p> Otherwise this method works in the same manner as the {@link + * AsynchronousByteChannel#read(ByteBuffer,Object,CompletionHandler)} + * method. + * + * @param dst + * The buffer into which bytes are to be transferred + * @param timeout + * The timeout, or {@code 0L} for no timeout + * @param unit + * The time unit of the {@code timeout} argument + * @param attachment + * The object to attach to the I/O operation; can be {@code null} + * @param handler + * The handler for consuming the result; can be {@code null} + * + * @return A {@code Future} object representing the pending result + * + * @throws IllegalArgumentException + * If the {@code timeout} parameter is negative or the buffer is + * read-only + * @throws ReadPendingException + * If a read operation is already in progress on this channel + * @throws NotYetConnectedException + * If this channel is not yet connected + * @throws ShutdownChannelGroupException + * If a handler is specified, and the channel group is shutdown + */ + public abstract <A> Future<Integer> read(ByteBuffer dst, + long timeout, + TimeUnit unit, + A attachment, + CompletionHandler<Integer,? super A> handler); + + /** + * @throws IllegalArgumentException {@inheritDoc} + * @throws ReadPendingException {@inheritDoc} + * @throws NotYetConnectedException + * If this channel is not yet connected + * @throws ShutdownChannelGroupException + * If a handler is specified, and the channel group is shutdown + */ + @Override + public final <A> Future<Integer> read(ByteBuffer dst, + A attachment, + CompletionHandler<Integer,? super A> handler) + { + return read(dst, 0L, TimeUnit.MILLISECONDS, attachment, handler); + } + + /** + * @throws IllegalArgumentException {@inheritDoc} + * @throws ReadPendingException {@inheritDoc} + * @throws NotYetConnectedException + * If this channel is not yet connected + */ + @Override + public final Future<Integer> read(ByteBuffer dst) { + return read(dst, 0L, TimeUnit.MILLISECONDS, null, null); + } + + /** + * Reads a sequence of bytes from this channel into a subsequence of the + * given buffers. This operation, sometimes called a <em>scattering read</em>, + * is often useful when implementing network protocols that group data into + * segments consisting of one or more fixed-length headers followed by a + * variable-length body. + * + * <p> This method initiates a read of up to <i>r</i> bytes from this channel, + * where <i>r</i> is the total number of bytes remaining in the specified + * subsequence of the given buffer array, that is, + * + * <blockquote><pre> + * dsts[offset].remaining() + * + dsts[offset+1].remaining() + * + ... + dsts[offset+length-1].remaining()</pre></blockquote> + * + * at the moment that the read is attempted. + * + * <p> Suppose that a byte sequence of length <i>n</i> is read, where + * <tt>0</tt> <tt><</tt> <i>n</i> <tt><=</tt> <i>r</i>. + * Up to the first <tt>dsts[offset].remaining()</tt> bytes of this sequence + * are transferred into buffer <tt>dsts[offset]</tt>, up to the next + * <tt>dsts[offset+1].remaining()</tt> bytes are transferred into buffer + * <tt>dsts[offset+1]</tt>, and so forth, until the entire byte sequence + * is transferred into the given buffers. As many bytes as possible are + * transferred into each buffer, hence the final position of each updated + * buffer, except the last updated buffer, is guaranteed to be equal to + * that buffer's limit. The underlying operating system may impose a limit + * on the number of buffers that may be used in an I/O operation. Where the + * number of buffers (with bytes remaining), exceeds this limit, then the + * I/O operation is performed with the maximum number of buffers allowed by + * the operating system. + * + * <p> The return value from this method is a {@code Future} representing + * the pending result of the operation. The {@code Future}'s {@link + * Future#get() get} method returns the number of bytes read or {@code -1L} + * if all bytes have been read and the channel has reached end-of-stream. + * + * <p> If a timeout is specified and the timeout elapses before the operation + * completes then it completes with the exception {@link + * InterruptedByTimeoutException}. Where a timeout occurs, and the + * implementation cannot guarantee that bytes have not been read, or will not + * be read from the channel into the given buffers, then further attempts to + * read from the channel will cause an unspecific runtime exception to be + * thrown. + * + * @param dsts + * The buffers into which bytes are to be transferred + * @param offset + * The offset within the buffer array of the first buffer into which + * bytes are to be transferred; must be non-negative and no larger than + * {@code dsts.length} + * @param length + * The maximum number of buffers to be accessed; must be non-negative + * and no larger than {@code dsts.length - offset} + * @param timeout + * The timeout, or {@code 0L} for no timeout + * @param unit + * The time unit of the {@code timeout} argument + * @param attachment + * The object to attach to the I/O operation; can be {@code null} + * @param handler + * The handler for consuming the result; can be {@code null} + * + * @return A {@code Future} object representing the pending result + * + * @throws IndexOutOfBoundsException + * If the pre-conditions for the {@code offset} and {@code length} + * parameter aren't met + * @throws IllegalArgumentException + * If the {@code timeout} parameter is negative, or a buffer is + * read-only + * @throws ReadPendingException + * If a read operation is already in progress on this channel + * @throws NotYetConnectedException + * If this channel is not yet connected + * @throws ShutdownChannelGroupException + * If a handler is specified, and the channel group is shutdown + */ + public abstract <A> Future<Long> read(ByteBuffer[] dsts, + int offset, + int length, + long timeout, + TimeUnit unit, + A attachment, + CompletionHandler<Long,? super A> handler); + + /** + * Writes a sequence of bytes to this channel from the given buffer. + * + * <p> This method initiates the writing of a sequence of bytes to this channel + * from the given buffer, returning a {@code Future} representing the + * pending result of the operation. The {@code Future}'s {@link Future#get() + * get} method will return the number of bytes written. + * + * <p> If a timeout is specified and the timeout elapses before the operation + * completes then it completes with the exception {@link + * InterruptedByTimeoutException}. Where a timeout occurs, and the + * implementation cannot guarantee that bytes have not been written, or will + * not be written to the channel from the given buffer, then further attempts + * to write to the channel will cause an unspecific runtime exception to be + * thrown. + * + * <p> Otherwise this method works in the same manner as the {@link + * AsynchronousByteChannel#write(ByteBuffer,Object,CompletionHandler)} + * method. + * + * @param src + * The buffer from which bytes are to be retrieved + * @param timeout + * The timeout, or {@code 0L} for no timeout + * @param unit + * The time unit of the {@code timeout} argument + * @param attachment + * The object to attach to the I/O operation; can be {@code null} + * @param handler + * The handler for consuming the result; can be {@code null} + * + * @return A {@code Future} object representing the pending result + * + * @throws IllegalArgumentException + * If the {@code timeout} parameter is negative + * @throws WritePendingException + * If a write operation is already in progress on this channel + * @throws NotYetConnectedException + * If this channel is not yet connected + * @throws ShutdownChannelGroupException + * If a handler is specified, and the channel group is shutdown + */ + public abstract <A> Future<Integer> write(ByteBuffer src, + long timeout, + TimeUnit unit, + A attachment, + CompletionHandler<Integer,? super A> handler); + + /** + * @throws WritePendingException {@inheritDoc} + * @throws NotYetConnectedException + * If this channel is not yet connected + * @throws ShutdownChannelGroupException + * If a handler is specified, and the channel group is shutdown + */ + @Override + public final <A> Future<Integer> write(ByteBuffer src, + A attachment, + CompletionHandler<Integer,? super A> handler) + + { + return write(src, 0L, TimeUnit.MILLISECONDS, attachment, handler); + } + + /** + * @throws WritePendingException {@inheritDoc} + * @throws NotYetConnectedException + * If this channel is not yet connected + */ + @Override + public final Future<Integer> write(ByteBuffer src) { + return write(src, 0L, TimeUnit.MILLISECONDS, null, null); + } + + /** + * Writes a sequence of bytes to this channel from a subsequence of the given + * buffers. This operation, sometimes called a <em>gathering write</em>, is + * often useful when implementing network protocols that group data into + * segments consisting of one or more fixed-length headers followed by a + * variable-length body. + * + * <p> This method initiates a write of up to <i>r</i> bytes to this channel, + * where <i>r</i> is the total number of bytes remaining in the specified + * subsequence of the given buffer array, that is, + * + * <blockquote><pre> + * srcs[offset].remaining() + * + srcs[offset+1].remaining() + * + ... + srcs[offset+length-1].remaining()</pre></blockquote> + * + * at the moment that the write is attempted. + * + * <p> Suppose that a byte sequence of length <i>n</i> is written, where + * <tt>0</tt> <tt><</tt> <i>n</i> <tt><=</tt> <i>r</i>. + * Up to the first <tt>srcs[offset].remaining()</tt> bytes of this sequence + * are written from buffer <tt>srcs[offset]</tt>, up to the next + * <tt>srcs[offset+1].remaining()</tt> bytes are written from buffer + * <tt>srcs[offset+1]</tt>, and so forth, until the entire byte sequence is + * written. As many bytes as possible are written from each buffer, hence + * the final position of each updated buffer, except the last updated + * buffer, is guaranteed to be equal to that buffer's limit. The underlying + * operating system may impose a limit on the number of buffers that may be + * used in an I/O operation. Where the number of buffers (with bytes + * remaining), exceeds this limit, then the I/O operation is performed with + * the maximum number of buffers allowed by the operating system. + * + * <p> The return value from this method is a {@code Future} representing + * the pending result of the operation. The {@code Future}'s {@link + * Future#get() get} method will return the number of bytes written. + * + * <p> If a timeout is specified and the timeout elapses before the operation + * completes then it completes with the exception {@link + * InterruptedByTimeoutException}. Where a timeout occurs, and the + * implementation cannot guarantee that bytes have not been written, or will + * not be written to the channel from the given buffers, then further attempts + * to write to the channel will cause an unspecific runtime exception to be + * thrown. + * + * @param srcs + * The buffers from which bytes are to be retrieved + * @param offset + * The offset within the buffer array of the first buffer from which + * bytes are to be retrieved; must be non-negative and no larger + * than {@code srcs.length} + * @param length + * The maximum number of buffers to be accessed; must be non-negative + * and no larger than {@code srcs.length - offset} + * @param timeout + * The timeout, or {@code 0L} for no timeout + * @param unit + * The time unit of the {@code timeout} argument + * @param attachment + * The object to attach to the I/O operation; can be {@code null} + * @param handler + * The handler for consuming the result; can be {@code null} + * + * @return A {@code Future} object representing the pending result + * + * @throws IndexOutOfBoundsException + * If the pre-conditions for the {@code offset} and {@code length} + * parameter aren't met + * @throws IllegalArgumentException + * If the {@code timeout} parameter is negative + * @throws WritePendingException + * If a write operation is already in progress on this channel + * @throws NotYetConnectedException + * If this channel is not yet connected + * @throws ShutdownChannelGroupException + * If a handler is specified, and the channel group is shutdown + */ + public abstract <A> Future<Long> write(ByteBuffer[] srcs, + int offset, + int length, + long timeout, + TimeUnit unit, + A attachment, + CompletionHandler<Long,? super A> handler); +} diff --git a/src/share/classes/java/nio/channels/Channels.java b/src/share/classes/java/nio/channels/Channels.java index cab96048629406759661a83fe594b2699936f21b..4fdcef8abb0fdd8d23f34527761aa7fb6a803c8e 100644 --- a/src/share/classes/java/nio/channels/Channels.java +++ b/src/share/classes/java/nio/channels/Channels.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2008 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. * * This code is free software; you can redistribute it and/or modify it @@ -33,15 +33,12 @@ import java.io.Reader; import java.io.Writer; import java.io.IOException; import java.nio.ByteBuffer; -import java.nio.CharBuffer; -import java.nio.BufferOverflowException; -import java.nio.BufferUnderflowException; import java.nio.charset.Charset; import java.nio.charset.CharsetDecoder; import java.nio.charset.CharsetEncoder; -import java.nio.charset.CoderResult; import java.nio.charset.UnsupportedCharsetException; import java.nio.channels.spi.AbstractInterruptibleChannel; +import java.util.concurrent.ExecutionException; import sun.nio.ch.ChannelInputStream; import sun.nio.cs.StreamDecoder; import sun.nio.cs.StreamEncoder; @@ -184,6 +181,155 @@ public final class Channels { }; } + /** + * {@note new} + * Constructs a stream that reads bytes from the given channel. + * + * <p> The stream will not be buffered, and it will not support the {@link + * InputStream#mark mark} or {@link InputStream#reset reset} methods. The + * stream will be safe for access by multiple concurrent threads. Closing + * the stream will in turn cause the channel to be closed. </p> + * + * @param ch + * The channel from which bytes will be read + * + * @return A new input stream + * + * @since 1.7 + */ + public static InputStream newInputStream(final AsynchronousByteChannel ch) { + checkNotNull(ch, "ch"); + return new InputStream() { + + private ByteBuffer bb = null; + private byte[] bs = null; // Invoker's previous array + private byte[] b1 = null; + + @Override + public synchronized int read() throws IOException { + if (b1 == null) + b1 = new byte[1]; + int n = this.read(b1); + if (n == 1) + return b1[0] & 0xff; + return -1; + } + + @Override + public synchronized int read(byte[] bs, int off, int len) + throws IOException + { + if ((off < 0) || (off > bs.length) || (len < 0) || + ((off + len) > bs.length) || ((off + len) < 0)) { + throw new IndexOutOfBoundsException(); + } else if (len == 0) + return 0; + + ByteBuffer bb = ((this.bs == bs) + ? this.bb + : ByteBuffer.wrap(bs)); + bb.position(off); + bb.limit(Math.min(off + len, bb.capacity())); + this.bb = bb; + this.bs = bs; + + boolean interrupted = false; + try { + for (;;) { + try { + return ch.read(bb).get(); + } catch (ExecutionException ee) { + throw new IOException(ee.getCause()); + } catch (InterruptedException ie) { + interrupted = true; + } + } + } finally { + if (interrupted) + Thread.currentThread().interrupt(); + } + } + + @Override + public void close() throws IOException { + ch.close(); + } + }; + } + + /** + * {@note new} + * Constructs a stream that writes bytes to the given channel. + * + * <p> The stream will not be buffered. The stream will be safe for access + * by multiple concurrent threads. Closing the stream will in turn cause + * the channel to be closed. </p> + * + * @param ch + * The channel to which bytes will be written + * + * @return A new output stream + * + * @since 1.7 + */ + public static OutputStream newOutputStream(final AsynchronousByteChannel ch) { + checkNotNull(ch, "ch"); + return new OutputStream() { + + private ByteBuffer bb = null; + private byte[] bs = null; // Invoker's previous array + private byte[] b1 = null; + + @Override + public synchronized void write(int b) throws IOException { + if (b1 == null) + b1 = new byte[1]; + b1[0] = (byte)b; + this.write(b1); + } + + @Override + public synchronized void write(byte[] bs, int off, int len) + throws IOException + { + if ((off < 0) || (off > bs.length) || (len < 0) || + ((off + len) > bs.length) || ((off + len) < 0)) { + throw new IndexOutOfBoundsException(); + } else if (len == 0) { + return; + } + ByteBuffer bb = ((this.bs == bs) + ? this.bb + : ByteBuffer.wrap(bs)); + bb.limit(Math.min(off + len, bb.capacity())); + bb.position(off); + this.bb = bb; + this.bs = bs; + + boolean interrupted = false; + try { + while (bb.remaining() > 0) { + try { + ch.write(bb).get(); + } catch (ExecutionException ee) { + throw new IOException(ee.getCause()); + } catch (InterruptedException ie) { + interrupted = true; + } + } + } finally { + if (interrupted) + Thread.currentThread().interrupt(); + } + } + + @Override + public void close() throws IOException { + ch.close(); + } + }; + } + // -- Channels from streams -- @@ -468,5 +614,4 @@ public final class Channels { checkNotNull(csName, "csName"); return newWriter(ch, Charset.forName(csName).newEncoder(), -1); } - } diff --git a/src/share/classes/java/nio/channels/CompletionHandler.java b/src/share/classes/java/nio/channels/CompletionHandler.java new file mode 100644 index 0000000000000000000000000000000000000000..c4d4add8ff9424b47d94499f58885f9868d251f8 --- /dev/null +++ b/src/share/classes/java/nio/channels/CompletionHandler.java @@ -0,0 +1,77 @@ +/* + * Copyright 2007-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 java.nio.channels; + +/** + * A handler for consuming the result of an asynchronous I/O operation. + * + * <p> The asynchronous channels defined in this package allow a completion + * handler to be specified to consume the result of an asynchronous operation. + * The {@link #completed completed} method is invoked when the I/O operation + * completes successfully. The {@link #failed failed} method is invoked if the + * I/O operations fails. The {@link #cancelled cancelled} method is invoked when + * the I/O operation is cancelled by invoking the {@link + * java.util.concurrent.Future#cancel cancel} method. The implementations of + * these methods should complete in a timely manner so as to avoid keeping the + * invoking thread from dispatching to other completion handlers. + * + * @param <V> The result type of the I/O operation + * @param <A> The type of the object attached to the I/O operation + * + * @since 1.7 + */ + +public interface CompletionHandler<V,A> { + + /** + * Invoked when an operation has completed. + * + * @param result + * The result of the I/O operation. + * @param attachment + * The object attached to the I/O operation when it was initiated. + */ + void completed(V result, A attachment); + + /** + * Invoked when an operation fails. + * + * @param exc + * The exception to indicate why the I/O operation failed + * @param attachment + * The object attached to the I/O operation when it was initiated. + */ + void failed(Throwable exc, A attachment); + + /** + * Invoked when an operation is cancelled by invoking the {@link + * java.util.concurrent.Future#cancel cancel} method. + * + * @param attachment + * The object attached to the I/O operation when it was initiated. + */ + void cancelled(A attachment); +} diff --git a/src/share/classes/java/nio/channels/DatagramChannel.java b/src/share/classes/java/nio/channels/DatagramChannel.java index b8697fa1dc69f22c32c09f8bc4ded6a0a19f1a12..cbf402f5933c3551cedb67360ed3dc58e47d957a 100644 --- a/src/share/classes/java/nio/channels/DatagramChannel.java +++ b/src/share/classes/java/nio/channels/DatagramChannel.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2008 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. * * This code is free software; you can redistribute it and/or modify it @@ -31,7 +31,8 @@ import java.net.DatagramSocket; import java.net.SocketOption; import java.net.SocketAddress; import java.nio.ByteBuffer; -import java.nio.channels.spi.*; +import java.nio.channels.spi.AbstractSelectableChannel; +import java.nio.channels.spi.SelectorProvider; /** * A selectable channel for datagram-oriented sockets. @@ -53,7 +54,8 @@ import java.nio.channels.spi.*; * be determined by invoking its {@link #isConnected isConnected} method. * * <p> Socket options are configured using the {@link #setOption(SocketOption,Object) - * setOption} method. Datagram channels support the following options: + * setOption} method. A datagram channel to an Internet Protocol socket supports + * the following options: * <blockquote> * <table border> * <tr> @@ -211,6 +213,7 @@ public abstract class DatagramChannel throws IOException; /** + * @throws UnsupportedOperationException {@inheritDoc} * @throws IllegalArgumentException {@inheritDoc} * @throws ClosedChannelException {@inheritDoc} * @throws IOException {@inheritDoc} @@ -220,7 +223,6 @@ public abstract class DatagramChannel public abstract <T> DatagramChannel setOption(SocketOption<T> name, T value) throws IOException; - /** * Retrieves a datagram socket associated with this channel. * @@ -259,7 +261,10 @@ public abstract class DatagramChannel * * <p> This method may be invoked at any time. It will not have any effect * on read or write operations that are already in progress at the moment - * that it is invoked. </p> + * that it is invoked. 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 + * automatically, as if invoking the {@link #bind bind} method with a + * parameter of {@code null}. </p> * * @param remote * The remote address to which this channel is to be connected @@ -313,15 +318,17 @@ public abstract class DatagramChannel /** * Returns the remote address to which this channel's socket is connected. * - * @return The remote address; {@code null} if the channel is not {@link - * #isOpen open} or the channel's socket is not connected + * @return The remote address; {@code null} if the channel's socket is not + * connected * + * @throws ClosedChannelException + * If the channel is closed * @throws IOException * If an I/O error occurs * * @since 1.7 */ - public abstract SocketAddress getConnectedAddress() throws IOException; + public abstract SocketAddress getRemoteAddress() throws IOException; /** * Receives a datagram via this channel. @@ -352,7 +359,10 @@ public abstract class DatagramChannel * <p> This method may be invoked at any time. If another thread has * already initiated a read operation upon this channel, however, then an * invocation of this method will block until the first operation is - * complete. </p> + * 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 + * automatically, as if invoking the {@link #bind bind} method with a + * parameter of {@code null}. </p> * * @param dst * The buffer into which the datagram is to be transferred @@ -409,7 +419,10 @@ public abstract class DatagramChannel * <p> This method may be invoked at any time. If another thread has * already initiated a write operation upon this channel, however, then an * invocation of this method will block until the first operation is - * complete. </p> + * 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 + * automatically, as if by invoking the {@link #bind bind) method with a + * parameter of {@code null}. </p> * * @param src * The buffer containing the datagram to be sent diff --git a/src/share/classes/java/nio/channels/FileChannel.java b/src/share/classes/java/nio/channels/FileChannel.java index e3b5f5bcb79469443cbe088dd7c00d9d52adc9e1..ab780a520a9b3c75317bf7f13dd6d8acfffb6814 100644 --- a/src/share/classes/java/nio/channels/FileChannel.java +++ b/src/share/classes/java/nio/channels/FileChannel.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2005 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. * * This code is free software; you can redistribute it and/or modify it @@ -29,16 +29,23 @@ import java.io.*; import java.nio.ByteBuffer; import java.nio.MappedByteBuffer; import java.nio.channels.spi.AbstractInterruptibleChannel; - +import java.nio.file.*; +import java.nio.file.attribute.FileAttribute; +import java.nio.file.spi.*; +import java.util.Set; +import java.util.HashSet; +import java.util.Collections; /** * A channel for reading, writing, mapping, and manipulating a file. * - * <p> A file channel has a current <i>position</i> within its file which can - * be both {@link #position() </code>queried<code>} and {@link #position(long) - * </code>modified<code>}. The file itself contains a variable-length sequence + * <p> {@note revised} + * A file channel is a {@link SeekableByteChannel} that is connected to + * a file. It has a current <i>position</i> within its file which can + * be both {@link #position() <i>queried</i>} and {@link #position(long) + * <i>modified</i>}. The file itself contains a variable-length sequence * of bytes that can be read and written and whose current {@link #size - * </code><i>size</i><code>} can be queried. The size of the file increases + * <i>size</i>} can be queried. The size of the file increases * when bytes are written beyond its current size; the size of the file * decreases when it is {@link #truncate </code><i>truncated</i><code>}. The * file may also have some associated <i>metadata</i> such as access @@ -50,27 +57,27 @@ import java.nio.channels.spi.AbstractInterruptibleChannel; * * <ul> * - * <li><p> Bytes may be {@link #read(ByteBuffer, long) </code>read<code>} or - * {@link #write(ByteBuffer, long) </code>written<code>} at an absolute + * <li><p> Bytes may be {@link #read(ByteBuffer, long) read} or + * {@link #write(ByteBuffer, long) <i>written</i>} at an absolute * position in a file in a way that does not affect the channel's current * position. </p></li> * - * <li><p> A region of a file may be {@link #map </code>mapped<code>} + * <li><p> A region of a file may be {@link #map <i>mapped</i>} * directly into memory; for large files this is often much more efficient * than invoking the usual <tt>read</tt> or <tt>write</tt> methods. * </p></li> * - * <li><p> Updates made to a file may be {@link #force </code>forced - * out<code>} to the underlying storage device, ensuring that data are not + * <li><p> Updates made to a file may be {@link #force <i>forced + * out</i>} to the underlying storage device, ensuring that data are not * lost in the event of a system crash. </p></li> * - * <li><p> Bytes can be transferred from a file {@link #transferTo </code>to - * some other channel<code>}, and {@link #transferFrom </code>vice - * versa<code>}, in a way that can be optimized by many operating systems + * <li><p> Bytes can be transferred from a file {@link #transferTo <i>to + * some other channel</i>}, and {@link #transferFrom <i>vice + * versa</i>}, in a way that can be optimized by many operating systems * into a very fast transfer directly to or from the filesystem cache. * </p></li> * - * <li><p> A region of a file may be {@link FileLock </code>locked<code>} + * <li><p> A region of a file may be {@link FileLock <i>locked</i>} * against access by other programs. </p></li> * * </ul> @@ -96,25 +103,23 @@ import java.nio.channels.spi.AbstractInterruptibleChannel; * machine. The exact nature of any such inconsistencies are system-dependent * and are therefore unspecified. * - * <p> This class does not define methods for opening existing files or for - * creating new ones; such methods may be added in a future release. In this - * release a file channel can be obtained from an existing {@link - * java.io.FileInputStream#getChannel FileInputStream}, {@link + * <p> A file channel is created by invoking one of the {@link #open open} + * methods defined by this class. A file channel can also be obtained from an + * existing {@link java.io.FileInputStream#getChannel FileInputStream}, {@link * java.io.FileOutputStream#getChannel FileOutputStream}, or {@link * java.io.RandomAccessFile#getChannel RandomAccessFile} object by invoking * that object's <tt>getChannel</tt> method, which returns a file channel that - * is connected to the same underlying file. - * - * <p> The state of a file channel is intimately connected to that of the - * object whose <tt>getChannel</tt> method returned the channel. Changing the - * channel's position, whether explicitly or by reading or writing bytes, will - * change the file position of the originating object, and vice versa. - * Changing the file's length via the file channel will change the length seen - * via the originating object, and vice versa. Changing the file's content by - * writing bytes will change the content seen by the originating object, and - * vice versa. + * is connected to the same underlying file. Where the file channel is obtained + * from an existing stream or random access file then the state of the file + * channel is intimately connected to that of the object whose <tt>getChannel</tt> + * method returned the channel. Changing the channel's position, whether + * explicitly or by reading or writing bytes, will change the file position of + * the originating object, and vice versa. Changing the file's length via the + * file channel will change the length seen via the originating object, and vice + * versa. Changing the file's content by writing bytes will change the content + * seen by the originating object, and vice versa. * - * <a name="open-mode"><p> At various points this class specifies that an + * <a name="open-mode"></a> <p> At various points this class specifies that an * instance that is "open for reading," "open for writing," or "open for * reading and writing" is required. A channel obtained via the {@link * java.io.FileInputStream#getChannel getChannel} method of a {@link @@ -127,7 +132,7 @@ import java.nio.channels.spi.AbstractInterruptibleChannel; * was created with mode <tt>"r"</tt> and will be open for reading and writing * if the instance was created with mode <tt>"rw"</tt>. * - * <a name="append-mode"><p> A file channel that is open for writing may be in + * <a name="append-mode"></a><p> A file channel that is open for writing may be in * <i>append mode</i>, for example if it was obtained from a file-output stream * that was created by invoking the {@link * java.io.FileOutputStream#FileOutputStream(java.io.File,boolean) @@ -138,7 +143,6 @@ import java.nio.channels.spi.AbstractInterruptibleChannel; * of the data are done in a single atomic operation is system-dependent and * therefore unspecified. * - * * @see java.io.FileInputStream#getChannel() * @see java.io.FileOutputStream#getChannel() * @see java.io.RandomAccessFile#getChannel() @@ -147,18 +151,190 @@ import java.nio.channels.spi.AbstractInterruptibleChannel; * @author Mike McCloskey * @author JSR-51 Expert Group * @since 1.4 + * @updated 1.7 */ public abstract class FileChannel extends AbstractInterruptibleChannel - implements ByteChannel, GatheringByteChannel, ScatteringByteChannel + implements SeekableByteChannel, GatheringByteChannel, ScatteringByteChannel { - /** * Initializes a new instance of this class. */ protected FileChannel() { } + /** + * {@note new} + * Opens or creates a file, returning a file channel to access the file. + * + * <p> The {@code options} parameter determines how the file is opened. + * The {@link StandardOpenOption#READ READ} and {@link StandardOpenOption#WRITE + * WRITE} options determine if the file should be opened for reading and/or + * writing. If neither option (or the {@link StandardOpenOption#APPEND APPEND} + * option) is contained in the array then the file is opened for reading. + * By default reading or writing commences at the beginning of the file. + * + * <p> In the addition to {@code READ} and {@code WRITE}, the following + * options may be present: + * + * <table border=1 cellpadding=5 summary=""> + * <tr> <th>Option</th> <th>Description</th> </tr> + * <tr> + * <td> {@link StandardOpenOption#APPEND APPEND} </td> + * <td> If this option is present then the file is opened for writing and + * each invocation of the channel's {@code write} method first advances + * the position to the end of the file and then writes the requested + * data. Whether the advancement of the position and the writing of the + * data are done in a single atomic operation is system-dependent and + * therefore unspecified. This option may not be used in conjunction + * with the {@code READ} or {@code TRUNCATE_EXISTING} options. </td> + * </tr> + * <tr> + * <td> {@link StandardOpenOption#TRUNCATE_EXISTING TRUNCATE_EXISTING} </td> + * <td> If this option is present then the existing file is truncated to + * a size of 0 bytes. This option is ignored when the file is opened only + * for reading. </td> + * </tr> + * <tr> + * <td> {@link StandardOpenOption#CREATE_NEW CREATE_NEW} </td> + * <td> If this option is present then a new file is created, failing if + * the file already exists. When creating a file the check for the + * existence of the file and the creation of the file if it does not exist + * is atomic with respect to other file system operations. This option is + * ignored when the file is opened only for reading. </td> + * </tr> + * <tr> + * <td > {@link StandardOpenOption#CREATE CREATE} </td> + * <td> If this option is present then an existing file is opened if it + * exists, otherwise a new file is created. When creating a file the check + * for the existence of the file and the creation of the file if it does + * not exist is atomic with respect to other file system operations. This + * option is ignored if the {@code CREATE_NEW} option is also present or + * the file is opened only for reading. </td> + * </tr> + * <tr> + * <td > {@link StandardOpenOption#DELETE_ON_CLOSE DELETE_ON_CLOSE} </td> + * <td> When this option is present then the implementation makes a + * <em>best effort</em> attempt to delete the file when closed by the + * the {@link #close close} method. If the {@code close} method is not + * invoked then a <em>best effort</em> attempt is made to delete the file + * when the Java virtual machine terminates. </td> + * </tr> + * <tr> + * <td>{@link StandardOpenOption#SPARSE SPARSE} </td> + * <td> When creating a new file this option is a <em>hint</em> that the + * new file will be sparse. This option is ignored when not creating + * a new file. </td> + * </tr> + * <tr> + * <td> {@link StandardOpenOption#SYNC SYNC} </td> + * <td> Requires that every update to the file's content or metadata be + * written synchronously to the underlying storage device. (see <a + * href="../file/package-summary.html#integrity"> Synchronized I/O file + * integrity</a>). </td> + * <tr> + * <tr> + * <td> {@link StandardOpenOption#DSYNC DSYNC} </td> + * <td> Requires that every update to the file's content be written + * synchronously to the underlying storage device. (see <a + * href="../file/package-summary.html#integrity"> Synchronized I/O file + * integrity</a>). </td> + * </tr> + * </table> + * + * <p> An implementation may also support additional options. + * + * <p> The {@code attrs} parameter is an optional array of file {@link + * FileAttribute file-attributes} to set atomically when creating the file. + * + * <p> The new channel is created by invoking the {@link + * FileSystemProvider#newFileChannel newFileChannel} method on the + * provider that created the {@code Path}. + * + * @param file + * The path of the file to open or create + * @param options + * Options specifying how the file is opened + * @param attrs + * An optional list of file attributes to set atomically when + * creating the file + * + * @return A new file channel + * + * @throws IllegalArgumentException + * If the set contains an invalid combination of options + * @throws UnsupportedOperationException + * If the {@code file} is associated with a provider that does not + * support creating file channels, or an unsupported open option is + * specified, or the array contains an attribute that cannot be set + * atomically when creating the file + * @throws IOException + * If an I/O error occurs + * @throws SecurityException + * If a security manager is installed and it denies an + * unspecified permission required by the implementation. + * In the case of the default provider, the {@link + * SecurityManager#checkRead(String)} method is invoked to check + * read access if the file is opened for reading. The {@link + * SecurityManager#checkWrite(String)} method is invoked to check + * write access if the file is opened for writing + * + * @since 1.7 + */ + public static FileChannel open(Path file, + Set<? extends OpenOption> options, + FileAttribute<?>... attrs) + throws IOException + { + FileSystemProvider provider = file.getFileSystem().provider(); + return provider.newFileChannel(file, options, attrs); + } + + private static final FileAttribute<?>[] NO_ATTRIBUTES = new FileAttribute[0]; + + /** + * {@note new} + * Opens or creates a file, returning a file channel to access the file. + * + * <p> An invocation of this method behaves in exactly the same way as the + * invocation + * <pre> + * fc.{@link #open(Path,Set,FileAttribute[]) open}(file, options, new FileAttribute<?>[0]); + * </pre> + * + * @param file + * The path of the file to open or create + * @param options + * Options specifying how the file is opened + * + * @return A new file channel + * + * @throws IllegalArgumentException + * If the set contains an invalid combination of options + * @throws UnsupportedOperationException + * If the {@code file} is associated with a provider that does not + * support creating file channels, or an unsupported open option is + * specified + * @throws IOException + * If an I/O error occurs + * @throws SecurityException + * If a security manager is installed and it denies an + * unspecified permission required by the implementation. + * In the case of the default provider, the {@link + * SecurityManager#checkRead(String)} method is invoked to check + * read access if the file is opened for reading. The {@link + * SecurityManager#checkWrite(String)} method is invoked to check + * write access if the file is opened for writing + * + * @since 1.7 + */ + public static FileChannel open(Path file, OpenOption... options) + throws IOException + { + Set<OpenOption> set = new HashSet<OpenOption>(options.length); + Collections.addAll(set, options); + return open(file, set, NO_ATTRIBUTES); + } // -- Channel operations -- @@ -286,7 +462,7 @@ public abstract class FileChannel public abstract FileChannel position(long newPosition) throws IOException; /** - * Returns the current size of this channel's file. </p> + * Returns the current size of this channel's file. </p> * * @return The current size of this channel's file, * measured in bytes @@ -359,7 +535,7 @@ public abstract class FileChannel * <p> This method is only guaranteed to force changes that were made to * this channel's file via the methods defined in this class. It may or * may not force changes that were made by modifying the content of a - * {@link MappedByteBuffer </code>mapped byte buffer<code>} obtained by + * {@link MappedByteBuffer <i>mapped byte buffer</i>} obtained by * invoking the {@link #map map} method. Invoking the {@link * MappedByteBuffer#force force} method of the mapped byte buffer will * force changes made to the buffer's content to be written. </p> @@ -678,7 +854,7 @@ public abstract class FileChannel * reading; for a read/write or private mapping, this channel must have * been opened for both reading and writing. * - * <p> The {@link MappedByteBuffer </code>mapped byte buffer<code>} + * <p> The {@link MappedByteBuffer <i>mapped byte buffer</i>} * returned by this method will have a position of zero and a limit and * capacity of <tt>size</tt>; its mark will be undefined. The buffer and * the mapping that it represents will remain valid until the buffer itself @@ -717,6 +893,8 @@ public abstract class FileChannel * The size of the region to be mapped; must be non-negative and * no greater than {@link java.lang.Integer#MAX_VALUE} * + * @return The mapped byte buffer + * * @throws NonReadableChannelException * If the <tt>mode</tt> is {@link MapMode#READ_ONLY READ_ONLY} but * this channel was not opened for reading diff --git a/src/share/classes/java/nio/channels/FileLock.java b/src/share/classes/java/nio/channels/FileLock.java index 921922242d77503b92842be020ba3e4a2ecb6bc5..b0ec37f1ba5a78f2c7a1b425fceb9d5686a6a232 100644 --- a/src/share/classes/java/nio/channels/FileLock.java +++ b/src/share/classes/java/nio/channels/FileLock.java @@ -1,5 +1,5 @@ /* - * Copyright 2001 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2001-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 @@ -27,14 +27,16 @@ package java.nio.channels; import java.io.IOException; - /** * A token representing a lock on a region of a file. * * <p> A file-lock object is created each time a lock is acquired on a file via * one of the {@link FileChannel#lock(long,long,boolean) lock} or {@link - * FileChannel#tryLock(long,long,boolean) tryLock} methods of the {@link - * FileChannel} class. + * FileChannel#tryLock(long,long,boolean) tryLock} methods of the + * {@link FileChannel} class, or the {@link + * AsynchronousFileChannel#lock(long,long,boolean,Object,CompletionHandler) lock} + * or {@link AsynchronousFileChannel#tryLock(long,long,boolean) tryLock} + * methods of the {@link AsynchronousFileChannel} class. * * <p> A file-lock object is initially valid. It remains valid until the lock * is released by invoking the {@link #release release} method, by closing the @@ -70,8 +72,7 @@ import java.io.IOException; * <p> File-lock objects are safe for use by multiple concurrent threads. * * - * <a name="pdep"> - * <h4> Platform dependencies </h4> + * <a name="pdep"><h4> Platform dependencies </h4></a> * * <p> This file-locking API is intended to map directly to the native locking * facility of the underlying operating system. Thus the locks held on a file @@ -93,7 +94,7 @@ import java.io.IOException; * * <p> On some systems, acquiring a mandatory lock on a region of a file * prevents that region from being {@link java.nio.channels.FileChannel#map - * </code>mapped into memory<code>}, and vice versa. Programs that combine + * <i>mapped into memory</i>}, and vice versa. Programs that combine * locking and mapping should be prepared for this combination to fail. * * <p> On some systems, closing a channel releases all locks held by the Java @@ -113,11 +114,12 @@ import java.io.IOException; * @author Mark Reinhold * @author JSR-51 Expert Group * @since 1.4 + * @updated 1.7 */ public abstract class FileLock { - private final FileChannel channel; + private final Channel channel; private final long position; private final long size; private final boolean shared; @@ -159,11 +161,66 @@ public abstract class FileLock { } /** - * Returns the file channel upon whose file this lock is held. </p> + * {@note new} Initializes a new instance of this class. + * + * @param channel + * The channel upon whose file this lock is held + * + * @param position + * The position within the file at which the locked region starts; + * must be non-negative + * + * @param size + * The size of the locked region; must be non-negative, and the sum + * <tt>position</tt> + <tt>size</tt> must be non-negative + * + * @param shared + * <tt>true</tt> if this lock is shared, + * <tt>false</tt> if it is exclusive + * + * @throws IllegalArgumentException + * If the preconditions on the parameters do not hold + * + * @since 1.7 + */ + protected FileLock(AsynchronousFileChannel channel, + long position, long size, boolean shared) + { + if (position < 0) + throw new IllegalArgumentException("Negative position"); + if (size < 0) + throw new IllegalArgumentException("Negative size"); + if (position + size < 0) + throw new IllegalArgumentException("Negative position + size"); + this.channel = channel; + this.position = position; + this.size = size; + this.shared = shared; + } + + /** + * {@note revised} + * Returns the file channel upon whose file this lock was acquired. * - * @return The file channel + * <p> This method has been superseded by the {@link #acquiredBy acquiredBy} + * method. + * + * @return The file channel, or {@code null} if the file lock was not + * acquired by a file channel. */ public final FileChannel channel() { + return (channel instanceof FileChannel) ? (FileChannel)channel : null; + } + + /** + * {@note new} + * Returns the channel upon whose file this lock was acquired. + * + * @return The channel upon whose file this lock was acquired. + * + * @since 1.7 + */ + public Channel acquiredBy() { return channel; } diff --git a/src/share/classes/java/nio/channels/MembershipKey.java b/src/share/classes/java/nio/channels/MembershipKey.java index 0d2fc52bc4de195ca11c30016a1da39b807015df..804e6724ad0c40ed898cf820d406001febbefc59 100644 --- a/src/share/classes/java/nio/channels/MembershipKey.java +++ b/src/share/classes/java/nio/channels/MembershipKey.java @@ -1,5 +1,5 @@ /* - * Copyright 2007-2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2007-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 @@ -28,7 +28,6 @@ package java.nio.channels; import java.net.InetAddress; import java.net.NetworkInterface; import java.io.IOException; -import java.util.List; /** * A token representing the membership of an Internet Protocol (IP) multicast @@ -38,7 +37,7 @@ import java.util.List; * to the group, or it may be <em>source-specific</em>, meaning that it * represents a membership that receives only datagrams from a specific source * address. Whether or not a membership key is source-specific may be determined - * by invoking its {@link #getSourceAddress() getSourceAddress} method. + * by invoking its {@link #sourceAddress() sourceAddress} method. * * <p> A membership key is valid upon creation and remains valid until the * membership is dropped by invoking the {@link #drop() drop} method, or @@ -93,11 +92,8 @@ public abstract class MembershipKey { * If the multicast group membership is already invalid then invoking this * method has no effect. Once a multicast group membership is invalid, * it remains invalid forever. - * - * @throws IOException - * If an I/O error occurs */ - public abstract void drop() throws IOException; + public abstract void drop(); /** * Block multicast datagrams from the given source address. @@ -140,10 +136,8 @@ public abstract class MembershipKey { * @throws IllegalStateException * If the given source address is not currently blocked or the * membership key is no longer valid - * @throws IOException - * If an I/O error occurs */ - public abstract MembershipKey unblock(InetAddress source) throws IOException; + public abstract MembershipKey unblock(InetAddress source); /** * Returns the channel for which this membership key was created. This @@ -152,7 +146,7 @@ public abstract class MembershipKey { * * @return the channel */ - public abstract MulticastChannel getChannel(); + public abstract MulticastChannel channel(); /** * Returns the multicast group for which this membership key was created. @@ -161,7 +155,7 @@ public abstract class MembershipKey { * * @return the multicast group */ - public abstract InetAddress getGroup(); + public abstract InetAddress group(); /** * Returns the network interface for which this membership key was created. @@ -170,7 +164,7 @@ public abstract class MembershipKey { * * @return the network interface */ - public abstract NetworkInterface getNetworkInterface(); + public abstract NetworkInterface networkInterface(); /** * Returns the source address if this membership key is source-specific, @@ -179,5 +173,5 @@ public abstract class MembershipKey { * @return The source address if this membership key is source-specific, * otherwise {@code null} */ - public abstract InetAddress getSourceAddress(); + public abstract InetAddress sourceAddress(); } diff --git a/src/share/classes/java/nio/channels/MulticastChannel.java b/src/share/classes/java/nio/channels/MulticastChannel.java index 440dd2a8b85a6eaa76eb2b4e7b754cdff1d2c01a..1cacf98e69c8393e537f1833a795be4f7c26f6ff 100644 --- a/src/share/classes/java/nio/channels/MulticastChannel.java +++ b/src/share/classes/java/nio/channels/MulticastChannel.java @@ -1,5 +1,5 @@ /* - * Copyright 2007-2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2007-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 @@ -122,6 +122,22 @@ import java.net.StandardSocketOption; // javadoc public interface MulticastChannel extends NetworkChannel { + /** + * Closes this channel. + * + * <p> If the channel is a member of a multicast group then the membership + * is {@link MembershipKey#drop dropped}. Upon return, the {@link + * MembershipKey membership-key} will be {@link MembershipKey#isValid + * invalid}. + * + * <p> This method otherwise behaves exactly as specified by the {@link + * Channel} interface. + * + * @throws IOException + * If an I/O error occurs + */ + @Override void close() throws IOException; + /** * Joins a multicast group to begin receiving all datagrams sent to the group, * returning a membership key. @@ -130,7 +146,7 @@ public interface MulticastChannel * interface to receive all datagrams then the membership key, representing * that membership, is returned. Otherwise this channel joins the group and * the resulting new membership key is returned. The resulting membership key - * is not {@link MembershipKey#getSourceAddress source-specific}. + * is not {@link MembershipKey#sourceAddress source-specific}. * * <p> A multicast channel may join several multicast groups, including * the same group on more than one interface. An implementation may impose a @@ -150,6 +166,8 @@ public interface MulticastChannel * @throws IllegalStateException * If the channel already has source-specific membership of the * group on the interface + * @throws UnsupportedOperationException + * If the channel's socket is not an Internet Protocol socket * @throws ClosedChannelException * If this channel is closed * @throws IOException @@ -170,7 +188,7 @@ public interface MulticastChannel * interface to receive datagrams from the given source address then the * membership key, representing that membership, is returned. Otherwise this * channel joins the group and the resulting new membership key is returned. - * The resulting membership key is {@link MembershipKey#getSourceAddress + * The resulting membership key is {@link MembershipKey#sourceAddress * source-specific}. * * <p> Membership is <em>cumulative</em> and this method may be invoked @@ -196,7 +214,8 @@ public interface MulticastChannel * If the channel is currently a member of the group on the given * interface to receive all datagrams * @throws UnsupportedOperationException - * If the underlying operation system does not support source filtering + * If the channel's socket is not an Internet Protocol socket or + * source filtering is not supported * @throws ClosedChannelException * If this channel is closed * @throws IOException diff --git a/src/share/classes/java/nio/channels/NetworkChannel.java b/src/share/classes/java/nio/channels/NetworkChannel.java index fae642fcbdbe5263af754c847757296e39e0d417..103427759e757ce34cc3cf9ec1f55b02e4388e34 100644 --- a/src/share/classes/java/nio/channels/NetworkChannel.java +++ b/src/share/classes/java/nio/channels/NetworkChannel.java @@ -1,5 +1,5 @@ /* - * Copyright 2007-2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2007-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 @@ -95,9 +95,10 @@ public interface NetworkChannel * java.net.InetSocketAddress}. * * @return The socket address that the socket is bound to, or {@code null} - * if the channel is not {@link #isOpen open} or the channel's socket - * is not bound + * if the channel's socket is not bound * + * @throws ClosedChannelException + * If the channel is closed * @throws IOException * If an I/O error occurs */ @@ -114,9 +115,10 @@ public interface NetworkChannel * * @return This channel * + * @throws UnsupportedOperationException + * If the socket option is not supported by this channel * @throws IllegalArgumentException - * If the socket option is not supported by this channel, or - * the value is not a valid value for this socket option + * If the value is not a valid value for this socket option * @throws ClosedChannelException * If this channel is closed * @throws IOException @@ -135,7 +137,7 @@ public interface NetworkChannel * @return The value of the socket option. A value of {@code null} may be * a valid value for some socket options. * - * @throws IllegalArgumentException + * @throws UnsupportedOperationException * If the socket option is not supported by this channel * @throws ClosedChannelException * If this channel is closed @@ -154,5 +156,5 @@ public interface NetworkChannel * * @return A set of the socket options supported by this channel */ - Set<SocketOption<?>> options(); + Set<SocketOption<?>> supportedOptions(); } diff --git a/src/share/classes/java/nio/channels/SeekableByteChannel.java b/src/share/classes/java/nio/channels/SeekableByteChannel.java new file mode 100644 index 0000000000000000000000000000000000000000..33efc248861e96492fa12539d8cf508fa0163a25 --- /dev/null +++ b/src/share/classes/java/nio/channels/SeekableByteChannel.java @@ -0,0 +1,168 @@ +/* + * Copyright 2007-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 java.nio.channels; + +import java.nio.ByteBuffer; +import java.io.IOException; + +/** + * A byte channel that maintains a current <i>position</i> and allows the + * position to be changed. + * + * <p> A seekable byte channel is connected to an entity, typically a file, + * that contains a variable-length sequence of bytes that can be read and + * written. The current position can be {@link #position() <i>queried</i>} and + * {@link #position(long) <i>modified</i>}. The channel also provides access to + * the current <i>size</i> of the entity to which the channel is connected. The + * size increases when bytes are written beyond its current size; the size + * decreases when it is {@link #truncate <i>truncated</i>}. + * + * <p> The {@link #position(long) position} and {@link #truncate truncate} methods + * which do not otherwise have a value to return are specified to return the + * channel upon which they are invoked. This allows method invocations to be + * chained. Implementations of this interface should specialize the return type + * so that method invocations on the implementation class can be chained. + * + * @since 1.7 + * @see java.nio.file.FileRef#newByteChannel + */ + +public interface SeekableByteChannel + extends ByteChannel +{ + /** + * Reads a sequence of bytes from this channel into the given buffer. + * + * <p> Bytes are read starting at this channel's current position, and + * then the position is updated with the number of bytes actually read. + * Otherwise this method behaves exactly as specified in the {@link + * ReadableByteChannel} interface. + */ + @Override + int read(ByteBuffer dst) throws IOException; + + /** + * Writes a sequence of bytes to this channel from the given buffer. + * + * <p> Bytes are written starting at this channel's current position, unless + * the channel is connected to an entity such as a file that is opened with + * the {@link java.nio.file.StandardOpenOption#APPEND APPEND} option, in + * which case the position is first advanced to the end. The entity to which + * the channel is connected is grown, if necessary, to accommodate the + * written bytes, and then the position is updated with the number of bytes + * actually written. Otherwise this method behaves exactly as specified by + * the {@link WritableByteChannel} interface. + */ + @Override + int write(ByteBuffer src) throws IOException; + + /** + * Returns this channel's position. + * + * @return This channel's position, + * a non-negative integer counting the number of bytes + * from the beginning of the entity to the current position + * + * @throws ClosedChannelException + * If this channel is closed + * @throws IOException + * If some other I/O error occurs + */ + long position() throws IOException; + + /** + * Sets this channel's position. + * + * <p> Setting the position to a value that is greater than the current size + * is legal but does not change the size of the entity. A later attempt to + * read bytes at such a position will immediately return an end-of-file + * indication. A later attempt to write bytes at such a position will cause + * the entity to grow to accommodate the new bytes; the values of any bytes + * between the previous end-of-file and the newly-written bytes are + * unspecified. + * + * <p> Setting the channel's position is not recommended when connected to + * an entity, typically a file, that is opened with the {@link + * java.nio.file.StandardOpenOption#APPEND APPEND} option. When opened for + * append, the position is first advanced to the end before writing. + * + * @param newPosition + * The new position, a non-negative integer counting + * the number of bytes from the beginning of the entity + * + * @return This channel + * + * @throws ClosedChannelException + * If this channel is closed + * @throws IllegalArgumentException + * If the new position is negative + * @throws IOException + * If some other I/O error occurs + */ + SeekableByteChannel position(long newPosition) throws IOException; + + /** + * Returns the current size of entity to which this channel is connected. + * + * @return The current size, measured in bytes + * + * @throws ClosedChannelException + * If this channel is closed + * @throws IOException + * If some other I/O error occurs + */ + long size() throws IOException; + + /** + * Truncates the entity, to which this channel is connected, to the given + * size. + * + * <p> If the given size is less than the current size then the entity is + * truncated, discarding any bytes beyond the new end. If the given size is + * greater than or equal to the current size then the entity is not modified. + * In either case, if the current position is greater than the given size + * then it is set to that size. + * + * <p> An implementation of this interface may prohibit truncation when + * connected to an entity, typically a file, opened with the {@link + * java.nio.file.StandardOpenOption#APPEND APPEND} option. + * + * @param size + * The new size, a non-negative byte count + * + * @return This channel + * + * @throws NonWritableChannelException + * If this channel was not opened for writing + * @throws ClosedChannelException + * If this channel is closed + * @throws IllegalArgumentException + * If the new size is negative + * @throws IOException + * If some other I/O error occurs + */ + SeekableByteChannel truncate(long size) throws IOException; +} diff --git a/src/share/classes/java/nio/channels/ServerSocketChannel.java b/src/share/classes/java/nio/channels/ServerSocketChannel.java index 84ea062c9f08b8cb2d2f2c60882f96ae193fc18d..5be9bc7cb15a82d2e854ac559326f2c896793b0d 100644 --- a/src/share/classes/java/nio/channels/ServerSocketChannel.java +++ b/src/share/classes/java/nio/channels/ServerSocketChannel.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2008 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. * * This code is free software; you can redistribute it and/or modify it @@ -29,7 +29,8 @@ import java.io.IOException; import java.net.ServerSocket; import java.net.SocketOption; import java.net.SocketAddress; -import java.nio.channels.spi.*; +import java.nio.channels.spi.AbstractSelectableChannel; +import java.nio.channels.spi.SelectorProvider; /** * A selectable channel for stream-oriented listening sockets. @@ -195,6 +196,7 @@ public abstract class ServerSocketChannel throws IOException; /** + * @throws UnsupportedOperationException {@inheritDoc} * @throws IllegalArgumentException {@inheritDoc} * @throws ClosedChannelException {@inheritDoc} * @throws IOException {@inheritDoc} diff --git a/src/share/classes/java/nio/channels/SocketChannel.java b/src/share/classes/java/nio/channels/SocketChannel.java index 2e96bd2e4ceafe3f8f72e76163f6b3d1ad2b5fd7..975048df0c022949de9f1ed69fb110e18445a247 100644 --- a/src/share/classes/java/nio/channels/SocketChannel.java +++ b/src/share/classes/java/nio/channels/SocketChannel.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2008 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. * * This code is free software; you can redistribute it and/or modify it @@ -30,7 +30,8 @@ import java.net.Socket; import java.net.SocketOption; import java.net.SocketAddress; import java.nio.ByteBuffer; -import java.nio.channels.spi.*; +import java.nio.channels.spi.AbstractSelectableChannel; +import java.nio.channels.spi.SelectorProvider; /** * A selectable channel for stream-oriented connecting sockets. @@ -212,7 +213,7 @@ public abstract class SocketChannel /** * @throws ConnectionPendingException - * If a non-blocking connection operation is already in progress on + * If a non-blocking connect operation is already in progress on * this channel * @throws AlreadyBoundException {@inheritDoc} * @throws UnsupportedAddressTypeException {@inheritDoc} @@ -226,6 +227,7 @@ public abstract class SocketChannel throws IOException; /** + * @throws UnsupportedOperationException {@inheritDoc} * @throws IllegalArgumentException {@inheritDoc} * @throws ClosedChannelException {@inheritDoc} * @throws IOException {@inheritDoc} @@ -432,15 +434,17 @@ public abstract class SocketChannel * socket address then the return value from this method is of type {@link * java.net.InetSocketAddress}. * - * @return The remote address; {@code null} if the channel is not {@link - * #isOpen open} or the channel's socket is not connected + * @return The remote address; {@code null} if the channel's socket is not + * connected * + * @throws ClosedChannelException + * If the channel is closed * @throws IOException * If an I/O error occurs * * @since 1.7 */ - public abstract SocketAddress getConnectedAddress() throws IOException; + public abstract SocketAddress getRemoteAddress() throws IOException; // -- ByteChannel operations -- diff --git a/src/share/classes/java/nio/channels/exceptions b/src/share/classes/java/nio/channels/exceptions index 04cfbe03e29a89d57b2ff375a57bfce1744e7212..fed9f72ab2e068642926f5467b61dda42434a3eb 100644 --- a/src/share/classes/java/nio/channels/exceptions +++ b/src/share/classes/java/nio/channels/exceptions @@ -1,5 +1,5 @@ # -# Copyright 2000-2008 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. # # This code is free software; you can redistribute it and/or modify it @@ -150,6 +150,21 @@ gen OverlappingFileLockException " SINCE=1.7 +SUPER=java.io.IOException + +gen InterruptedByTimeoutException " + * Checked exception received by a thread when a timeout elapses before an + * asynchronous operation completes." \ + -4268008601014042947L + +SUPER=IllegalArgumentException + +gen IllegalChannelGroupException " + * Unchecked exception thrown when an attempt is made to open a channel + * in a group that was not created by the same provider. " \ + -2495041211157744253L + + SUPER=IllegalStateException gen AlreadyBoundException " @@ -157,3 +172,23 @@ gen AlreadyBoundException " * network oriented channel that is already bound." \ 6796072983322737592L +gen AcceptPendingException " + * Unchecked exception thrown when an attempt is made to initiate an accept + * operation on a channel and a previous accept operation has not completed." \ + 2721339977965416421L + +gen ReadPendingException " + * Unchecked exception thrown when an attempt is made to read from an + * asynchronous socket channel and a previous read has not completed." \ + 1986315242191227217L + +gen WritePendingException " + * Unchecked exception thrown when an attempt is made to write to an + * asynchronous socket channel and a previous write has not completed." \ + 7031871839266032276L + +gen ShutdownChannelGroupException " + * Unchecked exception thrown when an attempt is made to construct a channel in + * a group that is shutdown or the completion handler for an I/O operation + * cannot be invoked because the channel group is shutdown." \ + -3903801676350154157L diff --git a/src/share/classes/java/nio/channels/package-info.java b/src/share/classes/java/nio/channels/package-info.java index e8c2a929d4b9f4273cff66a59cd8d0e2728fa0e7..47a1cb5f97928b316961c33070bc1c6abdd0b453 100644 --- a/src/share/classes/java/nio/channels/package-info.java +++ b/src/share/classes/java/nio/channels/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright 2001-2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2001-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 @@ -46,6 +46,10 @@ * <td>Can read/write to/from a buffer</td></tr> * <tr><td valign=top><tt>    <i>{@link java.nio.channels.SeekableByteChannel}</i></tt></td> * <td>A {@code ByteChannel} connected to an entity that contains a variable-length sequence of bytes</td></tr> + * <tr><td valign=top><tt>  <i>{@link java.nio.channels.AsynchronousChannel}</i></tt></td> + * <td>Supports asynchronous I/O operations.</td></tr> + * <tr><td valign=top><tt>    <i>{@link java.nio.channels.AsynchronousByteChannel}</i></tt></td> + * <td>Can read and write bytes asynchronously</td></tr> * <tr><td valign=top><tt>  <i>{@link java.nio.channels.NetworkChannel}</i></tt></td> * <td>A channel to a network socket</td></tr> * <tr><td valign=top><tt>    <i>{@link java.nio.channels.MulticastChannel}</i></tt></td> @@ -218,12 +222,70 @@ * directly; custom channel classes should extend the appropriate {@link * java.nio.channels.SelectableChannel} subclasses defined in this package. * + * <a name="async"></a> + * + * <blockquote><table cellspacing=1 cellpadding=0 summary="Lists asynchronous channels and their descriptions"> + * <tr><th><p align="left">Asynchronous I/O</p></th><th><p align="left">Description</p></th></tr> + * <tr><td valign=top><tt>{@link java.nio.channels.AsynchronousFileChannel}</tt></td> + * <td>An asynchronous channel for reading, writing, and manipulating a file</td></tr> + * <tr><td valign=top><tt>{@link java.nio.channels.AsynchronousSocketChannel}</tt></td> + * <td>An asynchronous channel to a stream-oriented connecting socket</td></tr> + * <tr><td valign=top><tt>{@link java.nio.channels.AsynchronousServerSocketChannel}  </tt></td> + * <td>An asynchronous channel to a stream-oriented listening socket</td></tr> + * <tr><td valign=top><tt>{@link java.nio.channels.AsynchronousDatagramChannel}</tt></td> + * <td>An asynchronous channel to a datagram-oriented socket</td></tr> + * <tr><td valign=top><tt>{@link java.nio.channels.CompletionHandler}</tt></td> + * <td>A handler for consuming the result of an asynchronous operation</td></tr> + * <tr><td valign=top><tt>{@link java.nio.channels.AsynchronousChannelGroup}</tt></td> + * <td>A grouping of asynchronous channels for the purpose of resource sharing</td></tr> + * </table></blockquote> + * + * <p> {@link java.nio.channels.AsynchronousChannel Asynchronous channels} are a + * special type of channel capable of asynchronous I/O operations. Asynchronous + * channels are non-blocking and define methods to initiate asynchronous + * operations, returning a {@link java.util.concurrent.Future} representing the + * pending result of each operation. The {@code Future} can be used to poll or + * wait for the result of the operation. Asynchronous I/O operations can also + * specify a {@link java.nio.channels.CompletionHandler} to invoke when the + * operation completes. A completion handler is user provided code that is executed + * to consume the result of I/O operation. + * + * <p> This package defines asynchronous-channel classes that are connected to + * a stream-oriented connecting or listening socket, or a datagram-oriented socket. + * It also defines the {@link java.nio.channels.AsynchronousFileChannel} class + * for asynchronous reading, writing, and manipulating a file. As with the {@link + * java.nio.channels.FileChannel} it supports operations to truncate the file + * to a specific size, force updates to the file to be written to the storage + * device, or acquire locks on the whole file or on a specific region of the file. + * Unlike the {@code FileChannel} it does not define methods for mapping a + * region of the file directly into memory. Where memory mapped I/O is required, + * then a {@code FileChannel} can be used. + * + * <p> Asynchronous channels are bound to an asynchronous channel group for the + * purpose of resource sharing. A group has an associated {@link + * java.util.concurrent.ExecutorService} to which tasks are submitted to handle + * I/O events and dispatch to completion handlers that consume the result of + * asynchronous operations performed on channels in the group. The group can + * optionally be specified when creating the channel or the channel can be bound + * to a <em>default group</em>. Sophisticated users may wish to create their + * own asynchronous channel groups or configure the {@code ExecutorService} + * that will be used for the default group. + * + * <p> As with selectors, the implementatin of asynchronous channels can be + * replaced by "plugging in" an alternative definition or instance of the {@link + * java.nio.channels.spi.AsynchronousChannelProvider} class defined in the + * <tt>{@link java.nio.channels.spi}</tt> package. It is not expected that many + * developers will actually make use of this facility; it is provided primarily + * so that sophisticated users can take advantage of operating-system-specific + * asynchronous I/O mechanisms when very high performance is required. + * * <hr width="80%"> * <p> Unless otherwise noted, passing a <tt>null</tt> argument to a constructor * or method in any class or interface in this package will cause a {@link * java.lang.NullPointerException NullPointerException} to be thrown. * * @since 1.4 + * @updated 1.7 * @author Mark Reinhold * @author JSR-51 Expert Group */ diff --git a/src/share/classes/java/nio/channels/spi/AsynchronousChannelProvider.java b/src/share/classes/java/nio/channels/spi/AsynchronousChannelProvider.java new file mode 100644 index 0000000000000000000000000000000000000000..941364876ed060471f6691f3a64f4116e741f692 --- /dev/null +++ b/src/share/classes/java/nio/channels/spi/AsynchronousChannelProvider.java @@ -0,0 +1,264 @@ +/* + * Copyright 2007-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 java.nio.channels.spi; + +import java.nio.channels.*; +import java.net.ProtocolFamily; +import java.io.IOException; +import java.util.Iterator; +import java.util.ServiceLoader; +import java.util.ServiceConfigurationError; +import java.util.concurrent.*; +import java.security.AccessController; +import java.security.PrivilegedAction; + +/** + * Service-provider class for asynchronous channels. + * + * <p> An asynchronous channel provider is a concrete subclass of this class that + * has a zero-argument constructor and implements the abstract methods specified + * below. A given invocation of the Java virtual machine maintains a single + * system-wide default provider instance, which is returned by the {@link + * #provider() provider} method. The first invocation of that method will locate + * the default provider as specified below. + * + * <p> All of the methods in this class are safe for use by multiple concurrent + * threads. </p> + * + * @since 1.7 + */ + +public abstract class AsynchronousChannelProvider { + private static Void checkPermission() { + SecurityManager sm = System.getSecurityManager(); + if (sm != null) + sm.checkPermission(new RuntimePermission("asynchronousChannelProvider")); + return null; + } + private AsynchronousChannelProvider(Void ignore) { } + + /** + * Initializes a new instance of this class. + * + * @throws SecurityException + * If a security manager has been installed and it denies + * {@link RuntimePermission}<tt>("asynchronousChannelProvider")</tt> + */ + protected AsynchronousChannelProvider() { + this(checkPermission()); + } + + // lazy initialization of default provider + private static class ProviderHolder { + static final AsynchronousChannelProvider provider = load(); + + private static AsynchronousChannelProvider load() { + return AccessController + .doPrivileged(new PrivilegedAction<AsynchronousChannelProvider>() { + public AsynchronousChannelProvider run() { + AsynchronousChannelProvider p; + p = loadProviderFromProperty(); + if (p != null) + return p; + p = loadProviderAsService(); + if (p != null) + return p; + return sun.nio.ch.DefaultAsynchronousChannelProvider.create(); + }}); + } + + private static AsynchronousChannelProvider loadProviderFromProperty() { + String cn = System.getProperty("java.nio.channels.spi.AsynchronousChannelProvider"); + if (cn == null) + return null; + try { + Class<?> c = Class.forName(cn, true, + ClassLoader.getSystemClassLoader()); + return (AsynchronousChannelProvider)c.newInstance(); + } catch (ClassNotFoundException x) { + throw new ServiceConfigurationError(null, x); + } catch (IllegalAccessException x) { + throw new ServiceConfigurationError(null, x); + } catch (InstantiationException x) { + throw new ServiceConfigurationError(null, x); + } catch (SecurityException x) { + throw new ServiceConfigurationError(null, x); + } + } + + private static AsynchronousChannelProvider loadProviderAsService() { + ServiceLoader<AsynchronousChannelProvider> sl = + ServiceLoader.load(AsynchronousChannelProvider.class, + ClassLoader.getSystemClassLoader()); + Iterator<AsynchronousChannelProvider> i = sl.iterator(); + for (;;) { + try { + return (i.hasNext()) ? i.next() : null; + } catch (ServiceConfigurationError sce) { + if (sce.getCause() instanceof SecurityException) { + // Ignore the security exception, try the next provider + continue; + } + throw sce; + } + } + } + } + + /** + * Returns the system-wide default asynchronous channel provider for this + * invocation of the Java virtual machine. + * + * <p> The first invocation of this method locates the default provider + * object as follows: </p> + * + * <ol> + * + * <li><p> If the system property + * <tt>java.nio.channels.spi.AsynchronousChannelProvider</tt> is defined + * then it is taken to be the fully-qualified name of a concrete provider class. + * The class is loaded and instantiated; if this process fails then an + * unspecified error is thrown. </p></li> + * + * <li><p> If a provider class has been installed in a jar file that is + * visible to the system class loader, and that jar file contains a + * provider-configuration file named + * <tt>java.nio.channels.spi.AsynchronousChannelProvider</tt> in the resource + * directory <tt>META-INF/services</tt>, then the first class name + * specified in that file is taken. The class is loaded and + * instantiated; if this process fails then an unspecified error is + * thrown. </p></li> + * + * <li><p> Finally, if no provider has been specified by any of the above + * means then the system-default provider class is instantiated and the + * result is returned. </p></li> + * + * </ol> + * + * <p> Subsequent invocations of this method return the provider that was + * returned by the first invocation. </p> + * + * @return The system-wide default AsynchronousChannel provider + */ + public static AsynchronousChannelProvider provider() { + return ProviderHolder.provider; + } + + /** + * Constructs a new asynchronous channel group with a fixed thread pool. + * + * @param nThreads + * The number of threads in the pool + * @param threadFactory + * The factory to use when creating new threads + * + * @throws IllegalArgumentException + * If {@code nThreads <= 0} + * @throws IOException + * If an I/O error occurs + * + * @see AsynchronousChannelGroup#withFixedThreadPool + */ + public abstract AsynchronousChannelGroup + openAsynchronousChannelGroup(int nThreads, ThreadFactory threadFactory) throws IOException; + + /** + * Constructs a new asynchronous channel group with the given thread pool. + * + * @param executor + * The thread pool + * @param initialSize + * A value {@code >=0} or a negative value for implementation + * specific default + * + * @throws IOException + * If an I/O error occurs + * + * @see AsynchronousChannelGroup#withCachedThreadPool + */ + public abstract AsynchronousChannelGroup + openAsynchronousChannelGroup(ExecutorService executor, int initialSize) throws IOException; + + /** + * Opens an asynchronous server-socket channel. + * + * @param group + * The group to which the channel is bound, or {@code null} to + * bind to the default group + * + * @return The new channel + * + * @throws IllegalChannelGroupException + * If the provider that created the group differs from this provider + * @throws ShutdownChannelGroupException + * The group is shutdown + * @throws IOException + * If an I/O error occurs + */ + public abstract AsynchronousServerSocketChannel openAsynchronousServerSocketChannel + (AsynchronousChannelGroup group) throws IOException; + + /** + * Opens an asynchronous socket channel. + * + * @param group + * The group to which the channel is bound, or {@code null} to + * bind to the default group + * + * @return The new channel + * + * @throws IllegalChannelGroupException + * If the provider that created the group differs from this provider + * @throws ShutdownChannelGroupException + * The group is shutdown + * @throws IOException + * If an I/O error occurs + */ + public abstract AsynchronousSocketChannel openAsynchronousSocketChannel + (AsynchronousChannelGroup group) throws IOException; + + /** + * Opens an asynchronous datagram channel. + * + * @param family + * The protocol family, or {@code null} for the default protocol + * family + * @param group + * The group to which the channel is bound, or {@code null} to + * bind to the default group + * + * @return The new channel + * + * @throws IllegalChannelGroupException + * If the provider that created the group differs from this provider + * @throws ShutdownChannelGroupException + * The group is shutdown + * @throws IOException + * If an I/O error occurs + */ + public abstract AsynchronousDatagramChannel openAsynchronousDatagramChannel + (ProtocolFamily family, AsynchronousChannelGroup group) throws IOException; +} diff --git a/src/share/classes/java/nio/channels/spi/SelectorProvider.java b/src/share/classes/java/nio/channels/spi/SelectorProvider.java index dc61c9c270abc391044eb95504b3c80d5db517a6..d03800e22f30d94762e229f802453569d6871aa6 100644 --- a/src/share/classes/java/nio/channels/spi/SelectorProvider.java +++ b/src/share/classes/java/nio/channels/spi/SelectorProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2008 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. * * This code is free software; you can redistribute it and/or modify it @@ -89,8 +89,8 @@ public abstract class SelectorProvider { if (cn == null) return false; try { - Class c = Class.forName(cn, true, - ClassLoader.getSystemClassLoader()); + Class<?> c = Class.forName(cn, true, + ClassLoader.getSystemClassLoader()); provider = (SelectorProvider)c.newInstance(); return true; } catch (ClassNotFoundException x) { diff --git a/src/share/classes/java/nio/channels/spi/package.html b/src/share/classes/java/nio/channels/spi/package.html index 5b3ddd299f936c5a515b0fc7b50c1c1c43c00342..5960da38e82853a8dba4d738586ded4082dbcfeb 100644 --- a/src/share/classes/java/nio/channels/spi/package.html +++ b/src/share/classes/java/nio/channels/spi/package.html @@ -1,5 +1,5 @@ <!-- - Copyright 2000-2005 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. This code is free software; you can redistribute it and/or modify it @@ -29,8 +29,8 @@ Service-provider classes for the <tt>{@link java.nio.channels}</tt> package. -<p> Only developers who are defining new selector providers should need to make -direct use of this package. </p> +<p> Only developers who are defining new selector providers or asynchronous +channel providers should need to make direct use of this package. </p> <p> Unless otherwise noted, passing a <tt>null</tt> argument to a constructor or method in any class or interface in this package will cause a {@link diff --git a/src/share/classes/java/nio/file/AccessDeniedException.java b/src/share/classes/java/nio/file/AccessDeniedException.java new file mode 100644 index 0000000000000000000000000000000000000000..82a4fd2d54e0abb72d95bd05dc2b15e073734f48 --- /dev/null +++ b/src/share/classes/java/nio/file/AccessDeniedException.java @@ -0,0 +1,68 @@ +/* + * Copyright 2007-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 java.nio.file; + +/** + * Checked exception thrown when a file system operation is denied, typically + * due to a file permission or other access check. + * + * <p> This exception is not related to the {@link + * java.security.AccessControlException AccessControlException} or {@link + * SecurityException} thrown by access controllers or security managers when + * access to a file is denied. + * + * @since 1.7 + */ + +public class AccessDeniedException + extends FileSystemException +{ + private static final long serialVersionUID = 4943049599949219617L; + + /** + * Constructs an instance of this class. + * + * @param file + * a string identifying the file or {@code null} if not known + */ + public AccessDeniedException(String file) { + super(file); + } + + /** + * Constructs an instance of this class. + * + * @param file + * a string identifying the file or {@code null} if not known + * @param other + * a string identifying the other file or {@code null} if not known + * @param reason + * a reason message with additional information or {@code null} + */ + public AccessDeniedException(String file, String other, String reason) { + super(file, other, reason); + } +} diff --git a/src/share/classes/java/nio/file/AccessMode.java b/src/share/classes/java/nio/file/AccessMode.java new file mode 100644 index 0000000000000000000000000000000000000000..240837681ee9db84f595d71c3f641cdddb20b28e --- /dev/null +++ b/src/share/classes/java/nio/file/AccessMode.java @@ -0,0 +1,49 @@ +/* + * Copyright 2007-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 java.nio.file; + +/** + * Defines access modes used to test the accessibility of a file. + * + * @since 1.7 + * + * @see FileRef#checkAccess + */ + +public enum AccessMode { + /** + * Test read access. + */ + READ, + /** + * Test write access. + */ + WRITE, + /** + * Test execute access. + */ + EXECUTE; +} diff --git a/src/share/classes/java/nio/file/AtomicMoveNotSupportedException.java b/src/share/classes/java/nio/file/AtomicMoveNotSupportedException.java new file mode 100644 index 0000000000000000000000000000000000000000..503d24c2e91fce3de16d21758ff5ac0cc829c30f --- /dev/null +++ b/src/share/classes/java/nio/file/AtomicMoveNotSupportedException.java @@ -0,0 +1,56 @@ +/* + * Copyright 2007-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 java.nio.file; + +/** + * Checked exception thrown when a file cannot be moved as an atomic file system + * operation. + * + * @since 1.7 + */ + +public class AtomicMoveNotSupportedException + extends FileSystemException +{ + static final long serialVersionUID = 5402760225333135579L; + + /** + * Constructs an instance of this class. + * + * @param source + * a string identifying the source file or {@code null} if not known + * @param target + * a string identifying the target file or {@code null} if not known + * @param reason + * a reason message with additional information + */ + public AtomicMoveNotSupportedException(String source, + String target, + String reason) + { + super(source, target, reason); + } +} diff --git a/src/share/classes/java/nio/file/ClosedDirectoryStreamException.java b/src/share/classes/java/nio/file/ClosedDirectoryStreamException.java new file mode 100644 index 0000000000000000000000000000000000000000..f938776d1d1f9173aed0597bec8fd962cef79372 --- /dev/null +++ b/src/share/classes/java/nio/file/ClosedDirectoryStreamException.java @@ -0,0 +1,45 @@ +/* + * Copyright 2007-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 java.nio.file; + +/** + * Unchecked exception thrown when an attempt is made to invoke an operation on + * a directory stream that is closed. + * + * @since 1.7 + */ + +public class ClosedDirectoryStreamException + extends IllegalStateException +{ + static final long serialVersionUID = 4228386650900895400L; + + /** + * Constructs an instance of this class. + */ + public ClosedDirectoryStreamException() { + } +} diff --git a/src/share/classes/java/nio/file/ClosedFileSystemException.java b/src/share/classes/java/nio/file/ClosedFileSystemException.java new file mode 100644 index 0000000000000000000000000000000000000000..fcd720a860aa9083429ea5c97b1c4c6aa553ab7c --- /dev/null +++ b/src/share/classes/java/nio/file/ClosedFileSystemException.java @@ -0,0 +1,43 @@ +/* + * Copyright 2007-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 java.nio.file; + +/** + * Unchecked exception thrown when an attempt is made to invoke an operation on + * a file and the file system is closed. + */ + +public class ClosedFileSystemException + extends IllegalStateException +{ + static final long serialVersionUID = -8158336077256193488L; + + /** + * Constructs an instance of this class. + */ + public ClosedFileSystemException() { + } +} diff --git a/src/share/classes/java/nio/file/ClosedWatchServiceException.java b/src/share/classes/java/nio/file/ClosedWatchServiceException.java new file mode 100644 index 0000000000000000000000000000000000000000..662d0b6aca701ccf42901fbf0e6c15cc6e11b168 --- /dev/null +++ b/src/share/classes/java/nio/file/ClosedWatchServiceException.java @@ -0,0 +1,43 @@ +/* + * Copyright 2007-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 java.nio.file; + +/** + * Unchecked exception thrown when an attempt is made to invoke an operation on + * a watch service that is closed. + */ + +public class ClosedWatchServiceException + extends IllegalStateException +{ + static final long serialVersionUID = 1853336266231677732L; + + /** + * Constructs an instance of this class. + */ + public ClosedWatchServiceException() { + } +} diff --git a/src/share/classes/java/nio/file/CopyOption.java b/src/share/classes/java/nio/file/CopyOption.java new file mode 100644 index 0000000000000000000000000000000000000000..24534741fe3dc2cd2ad48e2fb696358021e1a282 --- /dev/null +++ b/src/share/classes/java/nio/file/CopyOption.java @@ -0,0 +1,41 @@ +/* + * Copyright 2007-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 java.nio.file; + +/** + * An object that configures how to copy or move a file. + * + * <p> Objects of this type may be used with the {@link Path#copyTo copyTo} and + * {@link Path#moveTo moveTo} methods to configure how a file is copied or moved. + * + * <p> The {@link StandardCopyOption} enumeration type defines the + * <i>standard</i> options. + * + * @since 1.7 + */ + +public interface CopyOption { +} diff --git a/src/share/classes/java/nio/file/DirectoryNotEmptyException.java b/src/share/classes/java/nio/file/DirectoryNotEmptyException.java new file mode 100644 index 0000000000000000000000000000000000000000..482b476410dd8c03ebceacc934817c52efc4a5b1 --- /dev/null +++ b/src/share/classes/java/nio/file/DirectoryNotEmptyException.java @@ -0,0 +1,49 @@ +/* + * Copyright 2007-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 java.nio.file; + +/** + * Checked exception thrown when a file system operation fails because a + * directory is not empty. + * + * @since 1.7 + */ + +public class DirectoryNotEmptyException + extends FileSystemException +{ + static final long serialVersionUID = 3056667871802779003L; + + /** + * Constructs an instance of this class. + * + * @param dir + * a string identifying the directory or {@code null} if not known + */ + public DirectoryNotEmptyException(String dir) { + super(dir); + } +} diff --git a/src/share/classes/java/nio/file/DirectoryStream.java b/src/share/classes/java/nio/file/DirectoryStream.java new file mode 100644 index 0000000000000000000000000000000000000000..589d7b4f5e9907f88aa0a14daaad1629211449fb --- /dev/null +++ b/src/share/classes/java/nio/file/DirectoryStream.java @@ -0,0 +1,138 @@ +/* + * Copyright 2007-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 java.nio.file; + +import java.util.Iterator; +import java.io.Closeable; + +/** + * An object to iterate over the entries in a directory. A directory stream + * allows for convenient use of the for-each construct: + * <pre> + * Path dir = ... + * DirectoryStream<Path> stream = dir.newDirectoryStream(); + * try { + * for (Path entry: stream) { + * .. + * } + * } finally { + * stream.close(); + * } + * </pre> + * + * <p><b> A {@code DirectoryStream} is not a general-purpose {@code Iterable}. + * While this interface extends {@code Iterable}, the {@code iterator} method + * may only be invoked once to obtain the iterator; a second, or subsequent, + * call to the {@code iterator} method throws {@code IllegalStateException}. </b> + * + * <p> A {@code DirectoryStream} is opened upon creation and is closed by + * invoking the {@link #close close} method. Closing the directory stream + * releases any resources associated with the stream. The {@link + * Files#withDirectory Files.withDirectory} utility method is useful for cases + * where a task is performed on entries in a directory. This method automatically + * closes the directory stream when iteration is complete (or an error occurs). + * Once a directory stream is closed, all further method invocations on the + * iterator throw {@link java.util.concurrent.ConcurrentModificationException} + * with cause {@link ClosedDirectoryStreamException}. + * + * <p> A directory stream is not required to be <i>asynchronously closeable</i>. + * If a thread is blocked on the directory stream's iterator reading from the + * directory, and another thread invokes the {@code close} method, then the + * second thread may block until the read operation is complete. + * + * <p> The {@link Iterator#hasNext() hasNext} and {@link Iterator#next() next} + * methods can encounter an I/O error when iterating over the directory in which + * case {@code ConcurrentModificationException} is thrown with cause + * {@link java.io.IOException}. The {@code hasNext} method is guaranteed to + * read-ahead by at least one element. This means that if the {@code hasNext} + * method returns {@code true} and is followed by a call to the {@code next} + * method then it is guaranteed not to fail with a {@code + * ConcurrentModificationException}. + * + * <p> The elements returned by the iterator are in no specific order. Some file + * systems maintain special links to the directory itself and the directory's + * parent directory. Entries representing these links are not returned by the + * iterator. + * + * <p> The iterator's {@link Iterator#remove() remove} method removes the + * directory entry for the last element returned by the iterator, as if by + * invoking the {@link FileRef#delete delete} method. If an I/O error or + * security exception occurs then {@code ConcurrentModificationException} is + * thrown with the cause. + * + * <p> The iterator is <i>weakly consistent</i>. It is thread safe but does not + * freeze the directory while iterating, so it may (or may not) reflect updates + * to the directory that occur after the {@code DirectoryStream} is created. + * + * @param <T> The type of element returned by the iterator + * + * @since 1.7 + * + * @see Path#newDirectoryStream + */ + +public interface DirectoryStream<T> + extends Closeable, Iterable<T> +{ + /** + * An interface that is implemented by objects that decide if a directory + * entry should be accepted or filtered. A {@code Filter} is passed as the + * parameter to the {@link Path#newDirectoryStream(DirectoryStream.Filter) + * newDirectoryStream} method when opening a directory to iterate over the + * entries in the directory. + * + * <p> The {@link DirectoryStreamFilters} class defines factory methods to + * create filters for a number of common usages and also methods to combine + * filters. + * + * @param <T> the type of the directory entry + * + * @since 1.7 + */ + public static interface Filter<T> { + /** + * Decides if the given directory entry should be accepted or filtered. + * + * @param entry + * the directory entry to be tested + * + * @return {@code true} if the directory entry should be accepted + */ + boolean accept(T entry); + } + + /** + * Returns the iterator associated with this {@code DirectoryStream}. + * + * @return the iterator associated with this {@code DirectoryStream} + * + * @throws IllegalStateException + * if this directory stream is closed or the iterator has already + * been returned + */ + @Override + Iterator<T> iterator(); +} diff --git a/src/share/classes/java/nio/file/DirectoryStreamFilters.java b/src/share/classes/java/nio/file/DirectoryStreamFilters.java new file mode 100644 index 0000000000000000000000000000000000000000..b582bbf93bcf3f051b63017bf69712b38499da37 --- /dev/null +++ b/src/share/classes/java/nio/file/DirectoryStreamFilters.java @@ -0,0 +1,210 @@ +/* + * Copyright 2007-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 java.nio.file; + +import java.io.IOException; +import java.io.IOError; +import sun.nio.fs.MimeType; + +/** + * This class consists exclusively of static methods that construct or combine + * filters. + * + * @since 1.7 + */ + +public final class DirectoryStreamFilters { + private DirectoryStreamFilters() { } + + /** + * Constructs a directory stream filter that filters directory entries by + * their <a href="http://www.ietf.org/rfc/rfc2045.txt">MIME</a> content + * type. The directory stream filter's {@link + * java.nio.file.DirectoryStream.Filter#accept accept} method returns {@code + * true} if the content type of the directory entry can be determined by + * invoking the {@link Files#probeContentType probeContentType} method, and + * the content type matches the given content type. + * + * <p> The {@code type} parameter is the value of a Multipurpose Internet + * Mail Extension (MIME) content type as defined by <a + * href="http://www.ietf.org/rfc/rfc2045.txt"><i>RFC 2045: Multipurpose + * Internet Mail Extensions (MIME) Part One: Format of Internet Message + * Bodies</i></a>. It is parsable according to the grammar in the RFC. Any + * space characters (<code>'\u0020'</code>) surrounding its components are + * ignored. The {@code type} parameter is parsed into its primary and subtype + * components which are used to match the primary and subtype components of + * each directory entry's content type. Parameters are not allowed. The + * primary type matches if it has value {@code '*'} or is equal to the + * primary type of the directory entry's content type without regard to + * case. The subtype matches if has the value {@code '*'} or is equal to the + * subtype of the directory entry's content type without regard to case. If + * both the primary and subtype match then the filter's {@code accept} method + * returns {@code true}. If the content type of a directory entry cannot be + * determined then the entry is filtered. + * + * <p> The {@code accept} method of the resulting directory stream filter + * throws {@link IOError} if the probing of the content type fails by + * throwing an {@link IOException}. Security exceptions are also propogated + * to the caller of the {@code accept} method. + * + * <p> <b>Usage Example:</b> + * Suppose we require to list only the HTML files in a directory. + * <pre> + * DirectoryStream.Filter<FileRef> filter = + * DirectoryStreamFilters.newContentTypeFilter("text/html"); + * </pre> + * + * @param type + * the content type + * + * @return a new directory stream filter + * + * @throws IllegalArgumentException + * if the {@code type} parameter cannot be parsed as a MIME type + * or it has parameters + */ + public static <T extends FileRef> DirectoryStream.Filter<T> + newContentTypeFilter(String type) + { + final MimeType matchType = MimeType.parse(type); + if (matchType.hasParameters()) + throw new IllegalArgumentException("Parameters not allowed"); + return new DirectoryStream.Filter<T>() { + @Override + public boolean accept(T entry) { + String fileType; + try { + fileType = Files.probeContentType(entry); + } catch (IOException x) { + throw new IOError(x); + } + if (fileType != null) { + return matchType.match(fileType); + } + return false; + } + }; + } + + /** + * Returns a directory stream filter that {@link DirectoryStream.Filter#accept + * accepts} a directory entry if the entry is accepted by all of the given + * filters. + * + * <p> This method returns a filter that invokes, in iterator order, the + * {@code accept} method of each of the filters. If {@code false} is returned + * by any of the filters then the directory entry is filtered. If the + * directory entry is not filtered then the resulting filter accepts the + * entry. If the iterator returns zero elements then the resulting filter + * accepts all directory entries. + * + * <p> <b>Usage Example:</b> + * <pre> + * List<DirectoryStream.Filter<? super Path>> filters = ... + * DirectoryStream.Filter<Path> filter = DirectoryStreamFilters.allOf(filters); + * </pre> + * + * @param filters + * the sequence of filters + * + * @return the resulting filter + */ + public static <T> DirectoryStream.Filter<T> + allOf(final Iterable<? extends DirectoryStream.Filter<? super T>> filters) + { + if (filters == null) + throw new NullPointerException("'filters' is null"); + return new DirectoryStream.Filter<T>() { + @Override + public boolean accept(T entry) { + for (DirectoryStream.Filter<? super T> filter: filters) { + if (!filter.accept(entry)) + return false; + } + return true; + } + }; + } + + /** + * Returns a directory stream filter that {@link DirectoryStream.Filter#accept + * accepts} a directory entry if the entry is accepted by one or more of + * the given filters. + * + * <p> This method returns a filter that invokes, in iteration order, the + * {@code accept} method of each of filter. If {@code true} is returned by + * any of the filters then the directory entry is accepted. If none of the + * filters accepts the directory entry then it is filtered. If the iterator + * returns zero elements then the resulting filter filters all directory + * entries. + * + * @param filters + * the sequence of filters + * + * @return the resulting filter + */ + public static <T> DirectoryStream.Filter<T> + anyOf(final Iterable<? extends DirectoryStream.Filter<? super T>> filters) + { + if (filters == null) + throw new NullPointerException("'filters' is null"); + return new DirectoryStream.Filter<T>() { + @Override + public boolean accept(T entry) { + for (DirectoryStream.Filter<? super T> filter: filters) { + if (filter.accept(entry)) + return true; + } + return false; + } + }; + } + + /** + * Returns a directory stream filter that is the <em>complement</em> of the + * given filter. The resulting filter {@link + * java.nio.file.DirectoryStream.Filter#accept accepts} a directory entry + * if filtered by the given filter, and filters any entries that are accepted + * by the given filter. + * + * @param filter + * the given filter + * + * @return the resulting filter that is the complement of the given filter + */ + public static <T> DirectoryStream.Filter<T> + complementOf(final DirectoryStream.Filter<T> filter) + { + if (filter == null) + throw new NullPointerException("'filter' is null"); + return new DirectoryStream.Filter<T>() { + @Override + public boolean accept(T entry) { + return !filter.accept(entry); + } + }; + } +} diff --git a/src/share/classes/java/nio/file/FileAction.java b/src/share/classes/java/nio/file/FileAction.java new file mode 100644 index 0000000000000000000000000000000000000000..58088c2f814ca23d1c0880721c5c0268d6c47eed --- /dev/null +++ b/src/share/classes/java/nio/file/FileAction.java @@ -0,0 +1,64 @@ +/* + * Copyright 2007-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 java.nio.file; + +import java.io.IOException; + +/** + * An interface that is implemented by objects that operate on a file. An + * implementation of this interface is provided to the {@link Files#withDirectory + * withDirectory} utility method so that the file action is {@link #invoke + * invoked} for all accepted entries in the directory, after which, the directory + * is automatically closed. + * + * <p> <b>Usage Example:</b> + * Suppose we require to perform a task on all class files in a directory: + * <pre> + * Path dir = ... + * Files.withDirectory(dir, "*.class", new FileAction<Path>() { + * public void invoke(Path entry) { + * : + * } + * }); + * </pre> + * + * @param <T> the type of file reference + * + * @since 1.7 + */ + +public interface FileAction<T extends FileRef> { + /** + * Invoked for a file. + * + * @param file + * the file + * + * @throws IOException + * if the block terminates due an uncaught I/O exception + */ + void invoke(T file) throws IOException; +} diff --git a/src/share/classes/java/nio/file/FileAlreadyExistsException.java b/src/share/classes/java/nio/file/FileAlreadyExistsException.java new file mode 100644 index 0000000000000000000000000000000000000000..ff60e6371d1f7b3ea291a129f05fea4d0ccb7d44 --- /dev/null +++ b/src/share/classes/java/nio/file/FileAlreadyExistsException.java @@ -0,0 +1,63 @@ +/* + * Copyright 2007-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 java.nio.file; + +/** + * Checked exception thrown when an attempt is made to create a file or + * directory and a file of that name already exists. + * + * @since 1.7 + */ + +public class FileAlreadyExistsException + extends FileSystemException +{ + static final long serialVersionUID = 7579540934498831181L; + + /** + * Constructs an instance of this class. + * + * @param file + * a string identifying the file or {@code null} if not known + */ + public FileAlreadyExistsException(String file) { + super(file); + } + + /** + * Constructs an instance of this class. + * + * @param file + * a string identifying the file or {@code null} if not known + * @param other + * a string identifying the other file or {@code null} if not known + * @param reason + * a reason message with additional information or {@code null} + */ + public FileAlreadyExistsException(String file, String other, String reason) { + super(file, other, reason); + } +} diff --git a/src/share/classes/java/nio/file/FileRef.java b/src/share/classes/java/nio/file/FileRef.java new file mode 100644 index 0000000000000000000000000000000000000000..2606a879c7505474b5cf9917aaa4440f1d8c6627 --- /dev/null +++ b/src/share/classes/java/nio/file/FileRef.java @@ -0,0 +1,424 @@ +/* + * Copyright 2007-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 java.nio.file; + +import java.nio.file.attribute.*; +import java.nio.channels.SeekableByteChannel; +import java.io.IOException; + +/** + * A reference to a file. + * + * <p> A {@code FileRef} is an object that locates a file and defines methods to + * access the file. The means by which the file is located depends on the + * implementation. In many cases, a file is located by a {@link Path} but it may + * be located by other means such as a file-system identifier. + * + * <p> This interface defines the following operations: + * <ul> + * <li><p> The {@link #newByteChannel newByteChannel} method + * may be used to open a file and obtain a byte channel for reading or + * writing. </p></li> + * <li><p> The {@link #delete delete} method may be used to delete a file. + * </p></li> + * <li><p> The {@link #checkAccess checkAccess} method may be used to check + * the existence or accessibility of a file. </p></li> + * <li><p> The {@link #isSameFile isSameFile} method may be used to test if + * two file references locate the same file. </p></li> + * <li><p> The {@link #getFileStore getFileStore} method may be used to + * obtain the {@link FileStore} representing the storage where a file is + * located. </p></li> + * </ul> + * + * <p> Access to associated metadata or file attributes requires an appropriate + * {@link FileAttributeView FileAttributeView}. The {@link + * #getFileAttributeView(Class,LinkOption[]) getFileAttributeView(Class,LinkOption[])} + * method may be used to obtain a file attribute view that defines type-safe + * methods to read or update file attributes. The {@link + * #getFileAttributeView(String,LinkOption[]) getFileAttributeView(String,LinkOption[])} + * method may be used to obtain a file attribute view where dynamic access to + * file attributes where required. + * + * <p> A {@code FileRef} is immutable and safe for use by multiple concurrent + * threads. + * + * @since 1.7 + */ + +public interface FileRef { + + /** + * Opens the file referenced by this object, returning a seekable byte + * channel to access the file. + * + * <p> The {@code options} parameter determines how the file is opened. + * The {@link StandardOpenOption#READ READ} and {@link StandardOpenOption#WRITE + * WRITE} options determine if the file should be opened for reading and/or + * writing. If neither option (or the {@link StandardOpenOption#APPEND APPEND} + * option) is contained in the array then the file is opened for reading. + * By default reading or writing commences at the beginning of the file. + * + * <p> In the addition to {@code READ} and {@code WRITE}, the following + * options may be present: + * + * <table border=1 cellpadding=5 summary=""> + * <tr> <th>Option</th> <th>Description</th> </tr> + * <tr> + * <td> {@link StandardOpenOption#APPEND APPEND} </td> + * <td> If this option is present then the file is opened for writing and + * each invocation of the channel's {@code write} method first advances + * the position to the end of the file and then writes the requested + * data. Whether the advancement of the position and the writing of the + * data are done in a single atomic operation is system-dependent and + * therefore unspecified. This option may not be used in conjunction + * with the {@code READ} or {@code TRUNCATE_EXISTING} options. </td> + * </tr> + * <tr> + * <td> {@link StandardOpenOption#TRUNCATE_EXISTING TRUNCATE_EXISTING} </td> + * <td> If this option is present then the existing file is truncated to + * a size of 0 bytes. This option is ignored when the file is opened only + * for reading. </td> + * </tr> + * <tr> + * <td> {@link StandardOpenOption#SYNC SYNC} </td> + * <td> Requires that every update to the file's content or metadata be + * written synchronously to the underlying storage device. (see <a + * href="package-summary.html#integrity"> Synchronized I/O file + * integrity</a>). </td> + * </tr> + * <tr> + * <td> {@link StandardOpenOption#DSYNC DSYNC} </td> + * <td> Requires that every update to the file's content be written + * synchronously to the underlying storage device. (see <a + * href="package-summary.html#integrity"> Synchronized I/O file + * integrity</a>). </td> + * </tr> + * </table> + * + * <p> An implementation of this interface may support additional options + * defined by the {@link StandardOpenOption} enumeration type or other + * implementation specific options. + * + * <p> The {@link java.nio.channels.Channels} utility classes defines methods + * to construct input and output streams where inter-operation with the + * {@link java.io} package is required. + * + * @param options + * Options specifying how the file is opened + * + * @return a new seekable byte channel + * + * @throws IllegalArgumentException + * If an invalid combination of options is specified + * @throws UnsupportedOperationException + * If an unsupported open option is specified + * @throws IOException + * If an I/O error occurs + * @throws SecurityException + * In the case of the default provider, and a security manager is + * installed, the {@link SecurityManager#checkRead(String) checkRead} + * method is invoked to check read access to the path if the file is + * opened for reading. The {@link SecurityManager#checkWrite(String) + * checkWrite} method is invoked to check write access to the path + * if the file is opened for writing. + */ + SeekableByteChannel newByteChannel(OpenOption... options) + throws IOException; + + /** + * Returns the {@link FileStore} representing the file store where the file + * referenced by this object is stored. + * + * <p> Once a reference to the {@code FileStore} is obtained it is + * implementation specific if operations on the returned {@code FileStore}, + * or {@link FileStoreAttributeView} objects obtained from it, continue + * to depend on the existence of the file. In particular the behavior is not + * defined for the case that the file is deleted or moved to a different + * file store. + * + * @return The file store where the file is stored + * + * @throws IOException + * If an I/O error occurs + * @throws SecurityException + * In the case of the default provider, and a security manager is + * installed, the {@link SecurityManager#checkRead(String) checkRead} + * method is invoked to check read access to the file, and in + * addition it checks {@link RuntimePermission}<tt> + * ("getFileStoreAttributes")</tt> + */ + FileStore getFileStore() throws IOException; + + /** + * Checks the existence and optionally the accessibility of the file + * referenced by this object. + * + * <p> This method checks the existence of a file and that this Java virtual + * machine has appropriate privileges that would allow it access the file + * according to all of access modes specified in the {@code modes} parameter + * as follows: + * + * <table border=1 cellpadding=5 summary=""> + * <tr> <th>Value</th> <th>Description</th> </tr> + * <tr> + * <td> {@link AccessMode#READ READ} </td> + * <td> Checks that the file exists and that the Java virtual machine has + * permission to read the file. </td> + * </tr> + * <tr> + * <td> {@link AccessMode#WRITE WRITE} </td> + * <td> Checks that the file exists and that the Java virtual machine has + * permission to write to the file, </td> + * </tr> + * <tr> + * <td> {@link AccessMode#EXECUTE EXECUTE} </td> + * <td> Checks that the file exists and that the Java virtual machine has + * permission to {@link Runtime#exec execute} the file. The semantics + * may differ when checking access to a directory. For example, on UNIX + * systems, checking for {@code EXECUTE} access checks that the Java + * virtual machine has permission to search the directory in order to + * access file or subdirectories. </td> + * </tr> + * </table> + * + * <p> If the {@code modes} parameter is of length zero, then the existence + * of the file is checked. + * + * <p> This method follows symbolic links if the file referenced by this + * object is a symbolic link. Depending on the implementation, this method + * may require to read file permissions, access control lists, or other + * file attributes in order to check the effective access to the file. To + * determine the effective access to a file may require access to several + * attributes and so in some implementations this method may not be atomic + * with respect to other file system operations. Furthermore, as the result + * of this method is immediately outdated, there is no guarantee that a + * subsequence access will succeed (or even that it will access the same + * file). Care should be taken when using this method in security sensitive + * applications. + * + * @param modes + * The access modes to check; may have zero elements + * + * @throws UnsupportedOperationException + * An implementation is required to support checking for + * {@code READ}, {@code WRITE}, and {@code EXECUTE} access. This + * exception is specified to allow for the {@code Access} enum to + * be extended in future releases. + * @throws NoSuchFileException + * If a file does not exist <i>(optional specific exception)</i> + * @throws AccessDeniedException + * The requested access would be denied or the access cannot be + * determined because the Java virtual machine has insufficient + * privileges or other reasons. <i>(optional specific exception)</i> + * @throws IOException + * If an I/O error occurs + * @throws SecurityException + * In the case of the default provider, and a security manager is + * installed, the {@link SecurityManager#checkRead(String) checkRead} + * is invoked when checking read access to the file or only the + * existence of the file, the {@link SecurityManager#checkWrite(String) + * checkWrite} is invoked when checking write access to the file, + * and {@link SecurityManager#checkExec(String) checkExec} is invoked + * when checking execute access. + */ + void checkAccess(AccessMode... modes) throws IOException; + + /** + * Returns a file attribute view of a given type. + * + * <p> A file attribute view provides a read-only or updatable view of a + * set of file attributes. This method is intended to be used where the file + * attribute view defines type-safe methods to read or update the file + * attributes. The {@code type} parameter is the type of the attribute view + * required and the method returns an instance of that type if supported. + * The {@link BasicFileAttributeView} type supports access to the basic + * attributes of a file. Invoking this method to select a file attribute + * view of that type will always return an instance of that class. + * + * <p> The {@code options} array may be used to indicate how symbolic links + * are handled by the resulting file attribute view for the case that the + * file is a symbolic link. By default, symbolic links are followed. If the + * option {@link LinkOption#NOFOLLOW_LINKS NOFOLLOW_LINKS} is present then + * symbolic links are not followed. This option is ignored by implementations + * that do not support symbolic links. + * + * @param type + * The {@code Class} object corresponding to the file attribute view + * @param options + * Options indicating how symbolic links are handled + * + * @return A file attribute view of the specified type, or {@code null} if + * the attribute view type is not available + * + * @throws UnsupportedOperationException + * If options contains an unsupported option. This exception is + * specified to allow the {@code LinkOption} enum be extended + * in future releases. + * + * @see Attributes#readBasicFileAttributes + */ + <V extends FileAttributeView> V getFileAttributeView(Class<V> type, LinkOption... options); + + /** + * Returns a file attribute view of the given name. + * + * <p> A file attribute view provides a read-only or updatable view of a + * set of file attributes. This method is intended to be used where + * <em>dynamic access</em> to the file attributes is required. The {@code + * name} parameter specifies the {@link FileAttributeView#name name} of the + * file attribute view and this method returns an instance of that view if + * supported. The {@link BasicFileAttributeView} type supports access to the + * basic attributes of a file and is name {@code "basic"}. Invoking this + * method to select a file attribute view named {@code "basic"} will always + * return an instance of that class. + * + * <p> The {@code options} array may be used to indicate how symbolic links + * are handled by the resulting file attribute view for the case that the + * file is a symbolic link. By default, symbolic links are followed. If the + * option {@link LinkOption#NOFOLLOW_LINKS NOFOLLOW_LINKS} is present then + * symbolic links are not followed. This option is ignored by implementations + * that do not support symbolic links. + * + * @param name + * The name of the file attribute view + * @param options + * Options indicating how symbolic links are handled + * + * @return A file attribute view of the given name, or {@code null} if + * the attribute view is not available + * + * @throws UnsupportedOperationException + * If options contains an unsupported option. This exception is + * specified to allow the {@code LinkOption} enum be extended + * in future releases. + */ + FileAttributeView getFileAttributeView(String name, LinkOption... options); + + /** + * Tests if the file referenced by this object is the same file referenced + * by another object. + * + * <p> If this {@code FileRef} and the given {@code FileRef} are {@link + * #equals(Object) equal} then this method returns {@code true} without checking + * if the file exists. If the {@code FileRef} and the given {@code FileRef} + * are associated with different providers, or the given {@code FileRef} is + * {@code null} then this method returns {@code false}. Otherwise, this method + * checks if both {@code FileRefs} locate the same file, and depending on the + * implementation, may require to open or access both files. + * + * <p> If the file system and files remain static, then this method implements + * an equivalence relation for non-null {@code FileRefs}. + * <ul> + * <li>It is <i>reflexive</i>: for a non-null {@code FileRef} {@code f}, + * {@code f.isSameFile(f)} should return {@code true}. + * <li>It is <i>symmetric</i>: for two non-null {@code FileRefs} + * {@code f} and {@code g}, {@code f.isSameFile(g)} will equal + * {@code g.isSameFile(f)}. + * <li>It is <i>transitive</i>: for three {@code FileRefs} + * {@code f}, {@code g}, and {@code h}, if {@code f.isSameFile(g)} returns + * {@code true} and {@code g.isSameFile(h)} returns {@code true}, then + * {@code f.isSameFile(h)} will return return {@code true}. + * </ul> + * + * @param other + * The other file reference + * + * @return {@code true} if, and only if, this object and the given object + * locate the same file + * + * @throws IOException + * If an I/O error occurs + * @throws SecurityException + * In the case of the default provider, and a security manager is + * installed, the {@link SecurityManager#checkRead(String) checkRead} + * method is invoked to check read access to both files. + * + * @see java.nio.file.attribute.BasicFileAttributes#fileKey + */ + boolean isSameFile(FileRef other) throws IOException; + + /** + * Deletes the file referenced by this object. + * + * <p> An implementation may require to examine the file to determine if the + * file is a directory. Consequently this method may not be atomic with respect + * to other file system operations. If the file is a symbolic-link then the + * link is deleted and not the final target of the link. + * + * <p> If the file is a directory then the directory must be empty. In some + * implementations a directory has entries for special files or links that + * are created when the directory is created. In such implementations a + * directory is considered empty when only the special entries exist. + * + * <p> On some operating systems it may not be possible to remove a file when + * it is open and in use by this Java virtual machine or other programs. + * + * @throws NoSuchFileException + * If the file does not exist <i>(optional specific exception)</i> + * @throws DirectoryNotEmptyException + * If the file is a directory and could not otherwise be deleted + * because the directory is not empty <i>(optional specific + * exception)</i> + * @throws IOException + * If an I/O error occurs + * @throws SecurityException + * In the case of the default provider, and a security manager is + * installed, the {@link SecurityManager#checkDelete(String)} method + * is invoked to check delete access to the file + */ + void delete() throws IOException; + + /** + * Tests this object for equality with another object. + * + * <p> If the given object is not a {@code FileRef} then this method + * immediately returns {@code false}. + * + * <p> For two file references to be considered equal requires that they + * are both the same type of {@code FileRef} and encapsulate components + * to locate the same file. This method does not access the file system and + * the file may not exist. + * + * <p> This method satisfies the general contract of the {@link + * java.lang.Object#equals(Object) Object.equals} method. </p> + * + * @param ob The object to which this object is to be compared + * + * @return {@code true} if, and only if, the given object is a {@code FileRef} + * that is identical to this {@code FileRef} + * + * @see #isSameFile + */ + boolean equals(Object ob); + + /** + * Returns the hash-code value for this object. + * + * <p> This method satisfies the general contract of the + * {@link java.lang.Object#hashCode() Object.hashCode} method. + */ + int hashCode(); +} diff --git a/src/share/classes/java/nio/file/FileStore.java b/src/share/classes/java/nio/file/FileStore.java new file mode 100644 index 0000000000000000000000000000000000000000..3f8df10312990d50b0c53914e034f63e1e93dd4f --- /dev/null +++ b/src/share/classes/java/nio/file/FileStore.java @@ -0,0 +1,169 @@ +/* + * Copyright 2007-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 java.nio.file; + +import java.nio.file.attribute.*; + +/** + * Storage for files. A {@code FileStore} represents a storage pool, device, + * partition, volume, concrete file system or other implementation specific means + * of file storage. The {@code FileStore} for where a file is stored is obtained + * by invoking the {@link FileRef#getFileStore getFileStore} method, or all file + * stores can be enumerated by invoking the {@link FileSystem#getFileStores + * getFileStores} method. + * + * <p> In addition to the methods defined by this class, a file store may support + * one or more {@link FileStoreAttributeView FileStoreAttributeView} classes + * that provide a read-only or updatable view of a set of file store attributes. + * File stores associated with the default provider support the {@link + * FileStoreSpaceAttributeView} to read the space related attributes of the + * file store. + * + * @since 1.7 + */ + +public abstract class FileStore { + + /** + * Initializes a new instance of this class. + */ + protected FileStore() { + } + + /** + * Returns the name of this file store. The format of the name is highly + * implementation specific. It will typically be the name of the storage + * pool or volume. + * + * <p> The string returned by this method may differ from the string + * returned by the {@link Object#toString() toString} method. + * + * @return the name of this file store + */ + public abstract String name(); + + /** + * Returns the <em>type</em> of this file store. The format of the string + * returned by this method is highly implementation specific. It may + * indicate, for example, the format used or if the file store is local + * or remote. + * + * @return a string representing the type of this file store + */ + public abstract String type(); + + /** + * Tells whether this file store is read-only. A file store is read-only if + * it does not support write operations or other changes to files. Any + * attempt to create a file, open an existing file for writing etc. causes + * an {@code IOException} to be thrown. + * + * @return {@code true} if, and only if, this file store is read-only + */ + public abstract boolean isReadOnly(); + + /** + * Tells whether or not this file store supports the file attributes + * identified by the given file attribute view. + * + * <p> Invoking this method to test if the file store supports {@link + * BasicFileAttributeView} will always return {@code true}. In the case of + * the default provider, this method cannot guarantee to give the correct + * result when the file store is not a local storage device. The reasons for + * this are implementation specific and therefore unspecified. + * + * @param type + * the file attribute view type + * + * @return {@code true} if, and only if, the file attribute view is + * supported + */ + public abstract boolean supportsFileAttributeView(Class<? extends FileAttributeView> type); + + /** + * Tells whether or not this file store supports the file attributes + * identified by the given file attribute view. + * + * <p> Invoking this method to test if the file store supports {@link + * BasicFileAttributeView}, identified by the name "{@code basic}" will + * always return {@code true}. In the case of the default provider, this + * method cannot guarantee to give the correct result when the file store is + * not a local storage device. The reasons for this are implementation + * specific and therefore unspecified. + * + * @param name + * the {@link FileAttributeView#name name} of file attribute view + * + * @return {@code true} if, and only if, the file attribute view is + * supported + */ + public abstract boolean supportsFileAttributeView(String name); + + /** + * Returns a {@code FileStoreAttributeView} of the given type. + * + * <p> This method is intended to be used where the file store attribute + * view defines type-safe methods to read or update the file store attributes. + * The {@code type} parameter is the type of the attribute view required and + * the method returns an instance of that type if supported. + * + * <p> For {@code FileStore} objects created by the default provider, then + * the file stores support the {@link FileStoreSpaceAttributeView} that + * provides access to space attributes. In that case invoking this method + * with a parameter value of {@code FileStoreSpaceAttributeView.class} will + * always return an instance of that class. + * + * @param type + * the {@code Class} object corresponding to the attribute view + * + * @return a file store attribute view of the specified type or + * {@code null} if the attribute view is not available + */ + public abstract <V extends FileStoreAttributeView> V + getFileStoreAttributeView(Class<V> type); + + /** + * Returns a {@code FileStoreAttributeView} of the given name. + * + * <p> This method is intended to be used where <em>dynamic access</em> to + * file store attributes is required. The {@code name} parameter specifies + * the {@link FileAttributeView#name name} of the file store attribute view + * and this method returns an instance of that view if supported. + * + * <p> For {@code FileStore} objects created by the default provider, then + * the file stores support the {@link FileStoreSpaceAttributeView} that + * provides access to space attributes. In that case invoking this method + * with a parameter value of {@code "space"} will always return an instance + * of that class. + * + * @param name + * the name of the attribute view + * + * @return a file store attribute view of the given name, or {@code null} + * if the attribute view is not available + */ + public abstract FileStoreAttributeView getFileStoreAttributeView(String name); +} diff --git a/src/share/classes/java/nio/file/FileSystem.java b/src/share/classes/java/nio/file/FileSystem.java new file mode 100644 index 0000000000000000000000000000000000000000..b7cb063258a10bd9dc457befcc03a4cef63588af --- /dev/null +++ b/src/share/classes/java/nio/file/FileSystem.java @@ -0,0 +1,453 @@ +/* + * Copyright 2007-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 java.nio.file; + +import java.nio.file.attribute.*; +import java.nio.file.spi.FileSystemProvider; +import java.util.Set; +import java.io.Closeable; +import java.io.IOException; + +/** + * Provides an interface to a file system and is the factory for objects to + * access files and other objects in the file system. + * + * <p> The default file system, obtained by invoking the {@link FileSystems#getDefault + * FileSystems.getDefault} method, provides access to the file system that is + * accessible to the Java virtual machine. The {@link FileSystems} class defines + * methods to create file systems that provide access to other types of file + * systems. + * + * <p> A file system is the factory for several types of objects: + * + * <ul> + * <li><p> The {@link #getPath getPath} method converts a system dependent + * <em>path string</em>, returning a {@link Path} object that may be used + * to locate and access a file. </p></li> + * <li><p> The {@link #getPathMatcher getPathMatcher} method is used + * to create a {@link PathMatcher} that performs match operations on + * paths. </p></li> + * <li><p> The {@link #getFileStores getFileStores} method returns an iterator + * over the underlying {@link FileStore file-stores}. </p></li> + * <li><p> The {@link #getUserPrincipalLookupService getUserPrincipalLookupService} + * method returns the {@link UserPrincipalLookupService} to lookup users or + * groups by name. </p></li> + * <li><p> The {@link #newWatchService newWatchService} method creates a + * {@link WatchService} that may be used to watch objects for changes and + * events. </p></li> + * </ul> + * + * <p> File systems vary greatly. In some cases the file system is a single + * hierarchy of files with one top-level root directory. In other cases it may + * have several distinct file hierarchies, each with its own top-level root + * directory. The {@link #getRootDirectories getRootDirectories} method may be + * used to iterate over the root directories in the file system. A file system + * is typically composed of one or more underlying {@link FileStore file-stores} + * that provide the storage for the files. Theses file stores can also vary in + * the features they support, and the file attributes or <em>meta-data</em> that + * they associate with files. + * + * <p> A file system is open upon creation and can be closed by invoking its + * {@link #close() close} method. Once closed, any further attempt to access + * objects in the file system cause {@link ClosedFileSystemException} to be + * thrown. File systems created by the default {@link FileSystemProvider provider} + * cannot be closed. + * + * <p> A {@code FileSystem} can provide read-only or read-write access to the + * file system. Whether or not a file system provides read-only access is + * established when the {@code FileSystem} is created and can be tested by invoking + * its {@link #isReadOnly() isReadOnly} method. Attempts to write to file stores + * by means of an object associated with a read-only file system throws {@link + * ReadOnlyFileSystemException}. + * + * <p> File systems are safe for use by multiple concurrent threads. The {@link + * #close close} method may be invoked at any time to close a file system but + * whether a file system is <i>asynchronously closeable</i> is provider specific + * and therefore unspecified. In other words, if a thread is accessing an + * object in a file system, and another thread invokes the {@code close} method + * then it may require to block until the first operation is complete. Closing + * a file system causes all open channels, watch services, and other {@link + * Closeable closeable} objects associated with the file system to be closed. + * + * @since 1.7 + */ + +public abstract class FileSystem + implements Closeable +{ + /** + * Initializes a new instance of this class. + */ + protected FileSystem() { + } + + /** + * Returns the provider that created this file system. + * + * @return The provider that created this file system. + */ + public abstract FileSystemProvider provider(); + + /** + * Closes this file system. + * + * <p> After a file system is closed then all subsequent access to the file + * system, either by methods defined by this class or on objects associated + * with this file system, throw {@link ClosedFileSystemException}. If the + * file system is already closed then invoking this method has no effect. + * + * <p> Closing a file system will close all open {@link + * java.nio.channels.Channel channels}, {@link DirectoryStream directory-streams}, + * {@link WatchService watch-service}, and other closeable objects associated + * with this file system. The {@link FileSystems#getDefault default} file + * system cannot be closed. + * + * @throws IOException + * If an I/O error occurs + * @throws UnsupportedOperationException + * Thrown in the case of the default file system + */ + @Override + public abstract void close() throws IOException; + + /** + * Tells whether or not this file system is open. + * + * <p> File systems created by the default provider are always open. + * + * @return {@code true} if, and only if, this file system is open + */ + public abstract boolean isOpen(); + + /** + * Tells whether or not this file system allows only read-only access to + * its file stores. + * + * @return {@code true} if, and only if, this file system provides + * read-only access + */ + public abstract boolean isReadOnly(); + + /** + * Returns the name separator, represented as a string. + * + * <p> The name separator is used to separate names in a path string. An + * implementation may support multiple name separators in which case this + * method returns an implementation specific <em>default</em> name separator. + * This separator is used when creating path strings by invoking the {@link + * Path#toString() toString()} method. + * + * <p> In the case of the default provider, this method returns the same + * separator as {@link java.io.File#separator}. + * + * @return The name separator + */ + public abstract String getSeparator(); + + /** + * Returns an object to iterate over the paths of the root directories. + * + * <p> A file system provides access to a file store that may be composed + * of a number of distinct file hierarchies, each with its own top-level + * root directory. Unless denied by the security manager, each element in + * the returned iterator corresponds to the root directory of a distinct + * file hierarchy. The order of the elements is not defined. The file + * hierarchies may change during the lifetime of the Java virtual machine. + * For example, in some implementations, the insertion of removable media + * may result in the creation of a new file hierarchy with its own + * top-level directory. + * + * <p> When a security manager is installed, it is invoked to check access + * to the each root directory. If denied, the root directory is not returned + * by the iterator. In the case of the default provider, the {@link + * SecurityManager#checkRead(String)} method is invoked to check read access + * to each root directory. It is system dependent if the permission checks + * are done when the iterator is obtained or during iteration. + * + * @return An object to iterate over the root directories + */ + public abstract Iterable<Path> getRootDirectories(); + + /** + * Returns an object to iterate over the underlying file stores. + * + * <p> The elements of the returned iterator are the {@link + * FileStore FileStores} for this file system. The order of the elements is + * not defined and the file stores may change during the lifetime of the + * Java virtual machine. When an I/O error occurs, perhaps because a file + * store is not accessible, then it is not returned by the iterator. + * + * <p> In the case of the default provider, and a security manager is + * installed, the security manager is invoked to check {@link + * RuntimePermission}<tt>("getFileStoreAttributes")</tt>. If denied, then + * no file stores are returned by the iterator. In addition, the security + * manager's {@link SecurityManager#checkRead(String)} method is invoked to + * check read access to the file store's <em>top-most</em> directory. If + * denied, the file store is not returned by the iterator. It is system + * dependent if the permission checks are done when the iterator is obtained + * or during iteration. + * + * <p> <b>Usage Example:</b> + * Suppose we want to print the space usage for all file stores: + * <pre> + * for (FileStore store: FileSystems.getDefault().getFileStores()) { + * FileStoreSpaceAttributes attrs = Attributes.readFileStoreSpaceAttributes(store); + * long total = attrs.totalSpace() / 1024; + * long used = (attrs.totalSpace() - attrs.unallocatedSpace()) / 1024; + * long avail = attrs.usableSpace() / 1024; + * System.out.format("%-20s %12d %12d %12d%n", store, total, used, avail); + * } + * </pre> + * + * @return An object to iterate over the backing file stores + */ + public abstract Iterable<FileStore> getFileStores(); + + /** + * Returns the set of the {@link FileAttributeView#name names} of the file + * attribute views supported by this {@code FileSystem}. + * + * <p> The {@link BasicFileAttributeView} is required to be supported and + * therefore the set contains at least one element, "basic". + * + * <p> The {@link FileStore#supportsFileAttributeView(String) + * supportsFileAttributeView(String)} method may be used to test if an + * underlying {@link FileStore} supports the file attributes identified by a + * file attribute view. + * + * @return An unmodifiable set of the names of the supported file attribute + * views + */ + public abstract Set<String> supportedFileAttributeViews(); + + /** + * Converts a path string to a {@code Path}. + * + * <p> The parsing and conversion to a path object is inherently + * implementation dependent. In the simplest case, the path string is rejected, + * and {@link InvalidPathException} thrown, if the path string contains + * characters that cannot be converted to characters that are <em>legal</em> + * to the file store. For example, on UNIX systems, the NUL (\u0000) + * character is not allowed to be present in a path. An implementation may + * choose to reject path strings that contain names that are longer than those + * allowed by any file store, and where an implementation supports a complex + * path syntax, it may choose to reject path strings that are <em>badly + * formed</em>. + * + * <p> In the case of the default provider, path strings are parsed based + * on the definition of paths at the platform or virtual file system level. + * For example, an operating system may not allow specific characters to be + * present in a file name, but a specific underlying file store may impose + * different or additional restrictions on the set of legal + * characters. + * + * <p> This method throws {@link InvalidPathException} when the path string + * cannot be converted to a path. Where possible, and where applicable, + * the exception is created with an {@link InvalidPathException#getIndex + * index} value indicating the first position in the {@code path} parameter + * that caused the path string to be rejected. + * + * <p> Invoking this method with an empty path string throws + * {@code InvalidPathException}. + * + * @param path + * The path string + * + * @return A {@code Path} object + * + * @throws InvalidPathException + * If the path string cannot be converted + */ + public abstract Path getPath(String path); + + /** + * Returns a {@code PathMatcher} that performs match operations on the + * {@code String} representation of {@link Path} objects by interpreting a + * given pattern. + * + * The {@code syntaxAndPattern} parameter identifies the syntax and the + * pattern and takes the form: + * <blockquote> + * <i>syntax</i><b>:</b><i>pattern</i> + * </blockquote> + * where {@code ':'} stands for itself. + * + * <p> A {@code FileSystem} implementation supports the "{@code glob}" and + * "{@code regex}" syntaxes, and may support others. The value of the syntax + * component is compared without regard to case. + * + * <p> When the syntax is "{@code glob}" then the {@code String} + * representation of the path is matched using a limited pattern language + * that resembles regular expressions but with a simpler syntax. For example: + * + * <blockquote> + * <table border="0"> + * <tr> + * <td>{@code *.java}</td> + * <td>Matches a path that represents a file name ending in {@code .java}</td> + * </tr> + * <tr> + * <td>{@code *.*}</td> + * <td>Matches file names containing a dot</td> + * </tr> + * <tr> + * <tr> + * <td>{@code *.{java,class}}</td> + * <td>Matches file names ending with {@code .java} or {@code .class}</td> + * </tr> + * <tr> + * <td>{@code foo.?}</td> + * <td>Matches file names starting with {@code foo.} and a single + * character extension</td> + * </tr> + * <tr> + * <td><tt>/home/*/*</tt> + * <td>Matches <tt>/home/gus/data</tt> on UNIX platforms</td> + * </tr> + * <tr> + * <td><tt>/home/**</tt> + * <td>Matches <tt>/home/gus</tt> and + * <tt>/home/gus/data</tt> on UNIX platforms</td> + * </tr> + * <tr> + * <td><tt>C:\\*</tt> + * <td>Matches <tt>C:\foo</tt> and <tt>C:\bar</tt> on the Windows + * platform (note that the backslash is escaped; as a string literal in the + * Java Language the pattern would be <tt>"C:\\\\*"</tt>) </td> + * </tr> + * + * </table> + * </blockquote> + * + * <p> The following rules are used to interpret glob patterns: + * + * <p> <ul> + * <li><p> The {@code *} character matches zero or more {@link Character + * characters} of a {@link Path#getName(int) name} component without + * crossing directory boundaries. </p></li> + * + * <li><p> The {@code **} characters matches zero or more {@link Character + * characters} crossing directory boundaries. </p></li> + * + * <li><p> The {@code ?} character matches exactly one character of a + * name component.</p></li> + * + * <li><p> The backslash character ({@code \}) is used to escape characters + * that would otherwise be interpreted as special characters. The expression + * {@code \\} matches a single backslash and "\{" matches a left brace + * for example. </p></li> + * + * <li><p> The {@code [ ]} characters are a <i>bracket expression</i> that + * match a single character of a name component out of a set of characters. + * For example, {@code [abc]} matches {@code "a"}, {@code "b"}, or {@code "c"}. + * The hyphen ({@code -}) may be used to specify a range so {@code [a-z]} + * specifies a range that matches from {@code "a"} to {@code "z"} (inclusive). + * These forms can be mixed so [abce-g] matches {@code "a"}, {@code "b"}, + * {@code "c"}, {@code "e"}, {@code "f"} or {@code "g"}. If the character + * after the {@code [} is a {@code !} then it is used for negation so {@code + * [!a-c]} matches any character except {@code "a"}, {@code "b"}, or {@code + * "c"}. + * <p> Within a bracket expression the {@code *}, {@code ?} and {@code \} + * characters match themselves. The ({@code -}) character matches itself if + * it is the first character within the brackets, or the first character + * after the {@code !} if negating.</p></li> + * + * <li><p> The {@code { }} characters are a group of subpatterns, where + * the group matches if any subpattern in the group matches. The {@code ","} + * character is used to separate the subpatterns. Groups cannot be nested. + * </p></li> + * + * <li><p> All other characters match themselves in an implementation + * dependent manner. This includes characters representing any {@link + * FileSystem#getSeparator name-separators}. </p></li> + * + * <li><p> The matching of {@link Path#getRoot root} components is highly + * implementation-dependent and is not specified. </p></li> + * + * </ul> + * + * <p> When the syntax is "{@code regex}" then the pattern component is a + * regular expression as defined by the {@link java.util.regex.Pattern} + * class. + * + * <p> For both the glob and regex syntaxes, the matching details, such as + * whether the matching is case sensitive, are implementation-dependent + * and therefore not specified. + * + * @param syntaxAndPattern + * The syntax and pattern + * + * @return A path matcher that may be used to match paths against the pattern + * + * @throws IllegalArgumentException + * If the parameter does not take the form: {@code syntax:pattern} + * @throws java.util.regex.PatternSyntaxException + * If the pattern is invalid + * @throws UnsupportedOperationException + * If the pattern syntax is not known to the implementation + * + * @see Path#newDirectoryStream(String) + */ + public abstract PathMatcher getPathMatcher(String syntaxAndPattern); + + /** + * Returns the {@code UserPrincipalLookupService} for this file system + * <i>(optional operation)</i>. The resulting lookup service may be used to + * lookup user or group names. + * + * <p> <b>Usage Example:</b> + * Suppose we want to make "joe" the owner of a file: + * <pre> + * Path file = ... + * UserPrincipal joe = file.getFileSystem().getUserPrincipalLookupService() + * .lookupPrincipalByName("joe"); + * Attributes.setOwner(file, joe); + * </pre> + * + * @throws UnsupportedOperationException + * If this {@code FileSystem} does not does have a lookup service + * + * @return The {@code UserPrincipalLookupService} for this file system + */ + public abstract UserPrincipalLookupService getUserPrincipalLookupService(); + + /** + * Constructs a new {@link WatchService} <i>(optional operation)</i>. + * + * <p> This method constructs a new watch service that may be used to watch + * registered objects for changes and events. + * + * @return a new watch service + * + * @throws UnsupportedOperationException + * If this {@code FileSystem} does not support watching file system + * objects for changes and events. This exception is not thrown + * by {@code FileSystems} created by the default provider. + * @throws IOException + * If an I/O error occurs + */ + public abstract WatchService newWatchService() throws IOException; +} diff --git a/src/share/classes/java/nio/file/FileSystemAlreadyExistsException.java b/src/share/classes/java/nio/file/FileSystemAlreadyExistsException.java new file mode 100644 index 0000000000000000000000000000000000000000..68c4e153b328cbaac9a18bb0f52635ccc8bdbce2 --- /dev/null +++ b/src/share/classes/java/nio/file/FileSystemAlreadyExistsException.java @@ -0,0 +1,53 @@ +/* + * Copyright 2007-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 java.nio.file; + +/** + * Runtime exception thrown when an attempt is made to create a file system that + * already exists. + */ + +public class FileSystemAlreadyExistsException + extends RuntimeException +{ + static final long serialVersionUID = -5438419127181131148L; + + /** + * Constructs an instance of this class. + */ + public FileSystemAlreadyExistsException() { + } + + /** + * Constructs an instance of this class. + * + * @param msg + * the detail message + */ + public FileSystemAlreadyExistsException(String msg) { + super(msg); + } +} diff --git a/src/share/classes/java/nio/file/FileSystemException.java b/src/share/classes/java/nio/file/FileSystemException.java new file mode 100644 index 0000000000000000000000000000000000000000..8735dd8795d8334f3fdbf01fee10064a1200bcf2 --- /dev/null +++ b/src/share/classes/java/nio/file/FileSystemException.java @@ -0,0 +1,125 @@ +/* + * Copyright 2007-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 java.nio.file; + +import java.io.IOException; + +/** + * Thrown when a file system operation fails on one or two files. This class is + * the general class for file system exceptions. + * + * @since 1.7 + */ + +public class FileSystemException + extends IOException +{ + static final long serialVersionUID = -3055425747967319812L; + + private final String file; + private final String other; + + /** + * Constructs an instance of this class. This constructor should be used + * when an operation involving one file fails and there isn't any additional + * information to explain the reason. + * + * @param file + * a string identifying the file or {@code null} if not known. + */ + public FileSystemException(String file) { + super((String)null); + this.file = file; + this.other = null; + } + + /** + * Constructs an instance of this class. This constructor should be used + * when an operation involving two files fails, or there is additional + * information to explain the reason. + * + * @param file + * a string identifying the file or {@code null} if not known. + * @param other + * a string identifying the other file or {@code null} if there + * isn't another file or if not known + * @param reason + * a reason message with additional information or {@code null} + */ + public FileSystemException(String file, String other, String reason) { + super(reason); + this.file = file; + this.other = other; + } + + /** + * Returns the file used to create this exception. + * + * @return the file (can be {@code null}) + */ + public String getFile() { + return file; + } + + /** + * Returns the other file used to create this exception. + * + * @return the other file (can be {@code null}) + */ + public String getOtherFile() { + return other; + } + + /** + * Returns the string explaining why the file system operation failed. + * + * @return the string explaining why the file system operation failed + */ + public String getReason() { + return super.getMessage(); + } + + /** + * Returns the detail message string. + */ + @Override + public String getMessage() { + if (file == null && other == null) + return getReason(); + StringBuilder sb = new StringBuilder(); + if (file != null) + sb.append(file); + if (other != null) { + sb.append(" -> "); + sb.append(other); + } + if (getReason() != null) { + sb.append(": "); + sb.append(getReason()); + } + return sb.toString(); + } +} diff --git a/src/share/classes/java/nio/file/FileSystemNotFoundException.java b/src/share/classes/java/nio/file/FileSystemNotFoundException.java new file mode 100644 index 0000000000000000000000000000000000000000..7cb58cada2183efb04d37a5b5fd3228cbaea91f1 --- /dev/null +++ b/src/share/classes/java/nio/file/FileSystemNotFoundException.java @@ -0,0 +1,52 @@ +/* + * Copyright 2007-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 java.nio.file; + +/** + * Runtime exception thrown when a file system cannot be found. + */ + +public class FileSystemNotFoundException + extends RuntimeException +{ + static final long serialVersionUID = 7999581764446402397L; + + /** + * Constructs an instance of this class. + */ + public FileSystemNotFoundException() { + } + + /** + * Constructs an instance of this class. + * + * @param msg + * the detail message + */ + public FileSystemNotFoundException(String msg) { + super(msg); + } +} diff --git a/src/share/classes/java/nio/file/FileSystems.java b/src/share/classes/java/nio/file/FileSystems.java new file mode 100644 index 0000000000000000000000000000000000000000..28885f8afee58b02409996005e35c41a31426189 --- /dev/null +++ b/src/share/classes/java/nio/file/FileSystems.java @@ -0,0 +1,413 @@ +/* + * Copyright 2007-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 java.nio.file; + +import java.nio.file.spi.FileSystemProvider; +import java.net.URI; +import java.io.IOException; +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.util.*; +import java.lang.reflect.Constructor; + +/** + * Factory methods for file systems. This class defines the {@link #getDefault + * getDefault} method to get the default file system and factory methods to + * construct other types of file systems. + * + * <p> The first invocation of any of the methods defined by this class causes + * the default {@link FileSystemProvider provider} to be loaded. The default + * provider, identified by the URI scheme "file", creates the {@link FileSystem} + * that provides access to the file systems accessible to the Java virtual + * machine. If the process of loading or initializing the default provider fails + * then an unspecified error is thrown. + * + * <p> The first invocation of the {@link FileSystemProvider#installedProviders + * installedProviders} method, by way of invoking any of the {@code + * newFileSystem} methods defined by this class, locates and loads all + * installed file system providers. Installed providers are loaded using the + * service-provider loading facility defined by the {@link ServiceLoader} class. + * Installed providers are loaded using the system class loader. If the + * system class loader cannot be found then the extension class loader is used; + * if there is no extension class loader then the bootstrap class loader is used. + * Providers are typically installed by placing them in a JAR file on the + * application class path or in the extension directory, the JAR file contains a + * provider-configuration file named {@code java.nio.file.spi.FileSystemProvider} + * in the resource directory {@code META-INF/services}, and the file lists one or + * more fully-qualified names of concrete subclass of {@link FileSystemProvider} + * that have a zero argument constructor. + * The ordering that installed providers are located is implementation specific. + * If a provider is instantiated and its {@link FileSystemProvider#getScheme() + * getScheme} returns the same URI scheme of a provider that was previously + * instantiated then the most recently instantiated duplicate is discarded. URI + * schemes are compared without regard to case. During construction a provider + * may safely access files associated with the default provider but care needs + * to be taken to avoid circular loading of other installed providers. If + * circular loading of installed providers is detected then an unspecified error + * is thrown. + * + * <p> This class also defines factory methods that allow a {@link ClassLoader} + * to be specified when locating a provider. As with installed providers, the + * provider classes are identified by placing the provider configuration file + * in the resource directory {@code META-INF/services}. + * + * <p> If a thread initiates the loading of the installed file system providers + * and another thread invokes a method that also attempts to load the providers + * then the method will block until the loading completes. + * + * @since 1.7 + */ + +public final class FileSystems { + private FileSystems() { + } + + // lazy initialization of default file system + private static class DefaultFileSystemHolder { + static final FileSystem defaultFileSystem = defaultFileSystem(); + + // returns default file system + private static FileSystem defaultFileSystem() { + // load default provider + FileSystemProvider provider = AccessController + .doPrivileged(new PrivilegedAction<FileSystemProvider>() { + public FileSystemProvider run() { + return getDefaultProvider(); + } + }); + + // return file system + return provider.getFileSystem(URI.create("file:///")); + } + + // returns default provider + private static FileSystemProvider getDefaultProvider() { + FileSystemProvider provider = sun.nio.fs.DefaultFileSystemProvider.create(); + + // if the property java.nio.file.spi.DefaultFileSystemProvider is + // set then its value is the name of the default provider (or a list) + String propValue = System + .getProperty("java.nio.file.spi.DefaultFileSystemProvider"); + if (propValue != null) { + for (String cn: propValue.split(",")) { + try { + Class<?> c = Class + .forName(cn, true, ClassLoader.getSystemClassLoader()); + Constructor<?> ctor = c + .getDeclaredConstructor(FileSystemProvider.class); + provider = (FileSystemProvider)ctor.newInstance(provider); + + // must be "file" + if (!provider.getScheme().equals("file")) + throw new Error("Default provider must use scheme 'file'"); + + } catch (Exception x) { + throw new Error(x); + } + } + } + return provider; + } + } + + /** + * Returns the default {@code FileSystem}. The default file system creates + * objects that provide access to the file systems accessible to the Java + * virtual machine. The <em>working directory</em> of the file system is + * the current user directory, named by the system property {@code user.dir}. + * This allows for interoperability with the {@link java.io.File java.io.File} + * class. + * + * <p> The first invocation of any of the methods defined by this class + * locates the default {@link FileSystemProvider provider} object. Where the + * system property {@code java.nio.file.spi.DefaultFileSystemProvider} is + * not defined then the default provider is a system-default provider that + * is invoked to create the default file system. + * + * <p> If the system property {@code java.nio.file.spi.DefaultFileSystemProvider} + * is defined then it is taken to be a list of one or more fully-qualified + * names of concrete provider classes identified by the URI scheme + * {@code "file"}. Where the property is a list of more than one name then + * the names are separated by a comma. Each class is loaded, using the system + * class loader, and instantiated by invoking a one argument constructor + * whose formal parameter type is {@code FileSystemProvider}. The providers + * are loaded and instantiated in the order they are listed in the property. + * If this process fails or a provider's scheme is not equal to {@code "file"} + * then an unspecified error is thrown. URI schemes are normally compared + * without regard to case but for the default provider, the scheme is + * required to be {@code "file"}. The first provider class is instantiated + * by invoking it with a reference to the system-default provider. + * The second provider class is instantiated by invoking it with a reference + * to the first provider instance. The third provider class is instantiated + * by invoking it with a reference to the second instance, and so on. The + * last provider to be instantiated becomes the default provider; its {@code + * getFileSystem} method is invoked with the URI {@code "file:///"} to create + * the default file system. + * + * <p> Subsequent invocations of this method return the file system that was + * returned by the first invocation. + * + * @return the default file system + */ + public static FileSystem getDefault() { + return DefaultFileSystemHolder.defaultFileSystem; + } + + /** + * Returns a reference to an existing {@code FileSystem}. + * + * <p> This method iterates over the {@link FileSystemProvider#installedProviders() + * installed} providers to locate the provider that is identified by the URI + * {@link URI#getScheme scheme} of the given URI. URI schemes are compared + * without regard to case. The exact form of the URI is highly provider + * dependent. If found, the provider's {@link FileSystemProvider#getFileSystem + * getFileSystem} method is invoked to obtain a reference to the {@code + * FileSystem}. + * + * <p> Once a file system created by this provider is {@link FileSystem#close + * closed} it is provider-dependent if this method returns a reference to + * the closed file system or throws {@link FileSystemNotFoundException}. + * If the provider allows a new file system to be created with the same URI + * as a file system it previously created then this method throws the + * exception if invoked after the file system is closed (and before a new + * instance is created by the {@link #newFileSystem newFileSystem} method). + * + * <p> If a security manager is installed then a provider implementation + * may require to check a permission before returning a reference to an + * existing file system. In the case of the {@link FileSystems#getDefault + * default} file system, no permission check is required. + * + * @throws IllegalArgumentException + * if the pre-conditions for the {@code uri} parameter are not met + * @throws FileSystemNotFoundException + * if the file system, identified by the URI, does not exist + * @throws ProviderNotFoundException + * if a provider supporting the URI scheme is not installed + * @throws SecurityException + * if a security manager is installed and it denies an unspecified + * permission + */ + public static FileSystem getFileSystem(URI uri) { + String scheme = uri.getScheme(); + for (FileSystemProvider provider: FileSystemProvider.installedProviders()) { + if (scheme.equalsIgnoreCase(provider.getScheme())) { + return provider.getFileSystem(uri); + } + } + throw new ProviderNotFoundException("Provider \"" + scheme + "\" not found"); + } + + /** + * Constructs a new file system that is identified by a {@link URI} + * + * <p> This method iterates over the {@link FileSystemProvider#installedProviders() + * installed} providers to locate the provider that is identified by the URI + * {@link URI#getScheme scheme} of the given URI. URI schemes are compared + * without regard to case. The exact form of the URI is highly provider + * dependent. If found, the provider's {@link FileSystemProvider#newFileSystem(URI,Map) + * newFileSystem(URI,Map)} method is invoked to construct the new file system. + * + * <p> Once a file system is {@link FileSystem#close closed} it is + * provider-dependent if the provider allows a new file system to be created + * with the same URI as a file system it previously created. + * + * <p> <b>Usage Example:</b> + * Suppose there is a provider identified by the scheme {@code "memory"} + * installed: + * <pre> + * Map<String,String> env = new HashMap<String,String>(); + * env.put("capacity", "16G"); + * env.put("blockSize", "4k"); + * FileSystem fs = FileSystems.newFileSystem(URI.create("memory:///?name=logfs"), env); + * </pre> + * + * @param uri + * the URI identifying the file system + * @param env + * a map of provider specific properties to configure the file system; + * may be empty + * + * @return a new file system + * + * @throws IllegalArgumentException + * if the pre-conditions for the {@code uri} parameter are not met, + * or the {@code env} parameter does not contain properties required + * by the provider, or a property value is invalid + * @throws FileSystemAlreadyExistsException + * if the file system has already been created + * @throws ProviderNotFoundException + * if a provider supporting the URI scheme is not installed + * @throws IOException + * if an I/O error occurs creating the file system + * @throws SecurityException + * if a security manager is installed and it denies an unspecified + * permission required by the file system provider implementation + */ + public static FileSystem newFileSystem(URI uri, Map<String,?> env) + throws IOException + { + return newFileSystem(uri, env, null); + } + + /** + * Constructs a new file system that is identified by a {@link URI} + * + * <p> This method first attempts to locate an installed provider in exactly + * the same manner as the {@link #newFileSystem(URI,Map) newFileSystem(URI,Map)} + * method. If none of the installed providers support the URI scheme then an + * attempt is made to locate the provider using the given class loader. If a + * provider supporting the URI scheme is located then its {@link + * FileSystemProvider#newFileSystem(URI,Map) newFileSystem(URI,Map)} is + * invoked to construct the new file system. + * + * @param uri + * the URI identifying the file system + * @param env + * a map of provider specific properties to configure the file system; + * may be empty + * @param loader + * the class loader to locate the provider or {@code null} to only + * attempt to locate an installed provider + * + * @return a new file system + * + * @throws IllegalArgumentException + * if the pre-conditions for the {@code uri} parameter are not met, + * or the {@code env} parameter does not contain properties required + * by the provider, or a property value is invalid + * @throws FileSystemAlreadyExistsException + * if the URI scheme identifies an installed provider and the file + * system has already been created + * @throws ProviderNotFoundException + * if a provider supporting the URI scheme is not found + * @throws ServiceConfigurationError + * when an error occurs while loading a service provider + * @throws IOException + * an I/O error occurs creating the file system + * @throws SecurityException + * if a security manager is installed and it denies an unspecified + * permission required by the file system provider implementation + */ + public static FileSystem newFileSystem(URI uri, Map<String,?> env, ClassLoader loader) + throws IOException + { + String scheme = uri.getScheme(); + + // check installed providers + for (FileSystemProvider provider: FileSystemProvider.installedProviders()) { + if (scheme.equalsIgnoreCase(provider.getScheme())) { + return provider.newFileSystem(uri, env); + } + } + + // if not found, use service-provider loading facility + if (loader != null) { + ServiceLoader<FileSystemProvider> sl = ServiceLoader + .load(FileSystemProvider.class, loader); + for (FileSystemProvider provider: sl) { + if (scheme.equalsIgnoreCase(provider.getScheme())) { + return provider.newFileSystem(uri, env); + } + } + } + + throw new ProviderNotFoundException("Provider \"" + scheme + "\" not found"); + } + + /** + * Constructs a new {@code FileSystem} to access the contents of a file as a + * file system. + * + * <p> This method makes use of specialized providers that create pseudo file + * systems where the contents of one or more files is treated as a file + * system. The {@code file} parameter is a reference to an existing file + * and the {@code env} parameter is a map of provider specific properties to + * configure the file system. + * + * <p> This method iterates over the {@link FileSystemProvider#installedProviders() + * installed} providers. It invokes, in turn, each provider's {@link + * FileSystemProvider#newFileSystem(FileRef,Map) newFileSystem(FileRef,Map)} method. + * If a provider returns a file system then the iteration terminates + * and the file system is returned. If none of the installed providers return + * a {@code FileSystem} then an attempt is made to locate the provider using + * the given class loader. If a provider returns a file system then the lookup + * terminates and the file system is returned. + * + * @param file + * a reference to a file + * @param env + * a map of provider specific properties to configure the file system; + * may be empty + * @param loader + * the class loader to locate the provider or {@code null} to only + * attempt to locate an installed provider + * + * @return a new file system + * + * @throws IllegalArgumentException + * if the {@code env} parameter does not contain properties required + * by the provider, or a property value is invalid + * @throws ProviderNotFoundException + * if a provider supporting this file type cannot be located + * @throws ServiceConfigurationError + * when an error occurs while loading a service provider + * @throws IOException + * if an I/O error occurs + * @throws SecurityException + * if a security manager is installed and it denies an unspecified + * permission + */ + public static FileSystem newFileSystem(FileRef file, + Map<String,?> env, + ClassLoader loader) + throws IOException + { + if (file == null) + throw new NullPointerException(); + + // check installed providers + for (FileSystemProvider provider: FileSystemProvider.installedProviders()) { + try { + return provider.newFileSystem(file, env); + } catch (UnsupportedOperationException uoe) { + } + } + + // if not found, use service-provider loading facility + if (loader != null) { + ServiceLoader<FileSystemProvider> sl = ServiceLoader + .load(FileSystemProvider.class, loader); + for (FileSystemProvider provider: sl) { + try { + return provider.newFileSystem(file, env); + } catch (UnsupportedOperationException uoe) { + } + } + } + + throw new ProviderNotFoundException("Provider not found"); + } +} diff --git a/src/share/classes/java/nio/file/FileTreeWalker.java b/src/share/classes/java/nio/file/FileTreeWalker.java new file mode 100644 index 0000000000000000000000000000000000000000..95148a5b50dfef837558f2efe1f3e00bca8df6b8 --- /dev/null +++ b/src/share/classes/java/nio/file/FileTreeWalker.java @@ -0,0 +1,255 @@ +/* + * Copyright 2007-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 java.nio.file; + +import java.nio.file.attribute.*; +import java.io.IOException; +import java.util.*; +import sun.nio.fs.BasicFileAttributesHolder; + +/** + * Simple file tree walker that works in a similar manner to nftw(3C). + * + * @see Files#walkFileTree + */ + +class FileTreeWalker { + private final boolean followLinks; + private final boolean detectCycles; + private final LinkOption[] linkOptions; + private final FileVisitor<? super Path> visitor; + + FileTreeWalker(Set<FileVisitOption> options, FileVisitor<? super Path> visitor) { + boolean fl = false; + boolean dc = false; + for (FileVisitOption option: options) { + switch (option) { + case FOLLOW_LINKS : fl = true; break; + case DETECT_CYCLES : dc = true; break; + default: + if (option == null) + throw new NullPointerException("Visit options contains 'null'"); + throw new AssertionError("Should not get here"); + } + } + this.followLinks = fl; + this.detectCycles = fl | dc; + this.linkOptions = (fl) ? new LinkOption[0] : + new LinkOption[] { LinkOption.NOFOLLOW_LINKS }; + this.visitor = visitor; + } + + /** + * Walk file tree starting at the given file + */ + void walk(Path start, int maxDepth) { + // don't use attributes of starting file as they may be stale + if (start instanceof BasicFileAttributesHolder) { + ((BasicFileAttributesHolder)start).invalidate(); + } + FileVisitResult result = walk(start, + maxDepth, + new ArrayList<AncestorDirectory>()); + if (result == null) { + throw new NullPointerException("Visitor returned 'null'"); + } + } + + /** + * @param file + * the directory to visit + * @param depth + * depth remaining + * @param ancestors + * use when cycle detection is enabled + */ + private FileVisitResult walk(Path file, + int depth, + List<AncestorDirectory> ancestors) + { + // depth check + if (depth-- < 0) + return FileVisitResult.CONTINUE; + + // if attributes are cached then use them if possible + BasicFileAttributes attrs = null; + if (file instanceof BasicFileAttributesHolder) { + BasicFileAttributes cached = ((BasicFileAttributesHolder)file).get(); + if (!followLinks || !cached.isSymbolicLink()) + attrs = cached; + } + IOException exc = null; + + // attempt to get attributes of file. If fails and we are following + // links then a link target might not exist so get attributes of link + if (attrs == null) { + try { + try { + attrs = Attributes.readBasicFileAttributes(file, linkOptions); + } catch (IOException x1) { + if (followLinks) { + try { + attrs = Attributes + .readBasicFileAttributes(file, LinkOption.NOFOLLOW_LINKS); + } catch (IOException x2) { + exc = x2; + } + } else { + exc = x1; + } + } + } catch (SecurityException x) { + return FileVisitResult.CONTINUE; + } + } + + // unable to get attributes of file + if (exc != null) { + return visitor.visitFileFailed(file, exc); + } + + // file is not a directory so invoke visitFile method + if (!attrs.isDirectory()) { + return visitor.visitFile(file, attrs); + } + + // check for cycles + if (detectCycles) { + Object key = attrs.fileKey(); + + // if this directory and ancestor has a file key then we compare + // them; otherwise we use less efficient isSameFile test. + for (AncestorDirectory ancestor: ancestors) { + Object ancestorKey = ancestor.fileKey(); + if (key != null && ancestorKey != null) { + if (key.equals(ancestorKey)) { + // cycle detected + return visitor.visitFile(file, attrs); + } + } else { + try { + if (file.isSameFile(ancestor.file())) { + // cycle detected + return visitor.visitFile(file, attrs); + } + } catch (IOException x) { + // ignore + } catch (SecurityException x) { + // ignore + } + } + } + + ancestors.add(new AncestorDirectory(file, key)); + } + + // visit directory + try { + DirectoryStream<Path> stream = null; + FileVisitResult result; + + // open the directory + try { + stream = file.newDirectoryStream(); + } catch (IOException x) { + return visitor.preVisitDirectoryFailed(file, x); + } catch (SecurityException x) { + // ignore, as per spec + return FileVisitResult.CONTINUE; + } + + // the exception notified to the postVisitDirectory method + IOException ioe = null; + + // invoke preVisitDirectory and then visit each entry + try { + result = visitor.preVisitDirectory(file); + if (result != FileVisitResult.CONTINUE) { + return result; + } + + // if an I/O occurs during iteration then a CME is thrown. We + // need to distinguish this from a CME thrown by the visitor. + boolean inAction = false; + + try { + for (Path entry: stream) { + inAction = true; + result = walk(entry, depth, ancestors); + inAction = false; + + // returning null will cause NPE to be thrown + if (result == null || result == FileVisitResult.TERMINATE) + return result; + + // skip remaining siblings in this directory + if (result == FileVisitResult.SKIP_SIBLINGS) + break; + } + } catch (ConcurrentModificationException x) { + // if CME thrown because the iteration failed then remember + // the IOException so that it is notified to postVisitDirectory + if (!inAction) { + // iteration failed + Throwable t = x.getCause(); + if (t instanceof IOException) + ioe = (IOException)t; + } + if (ioe == null) + throw x; + } + } finally { + try { + stream.close(); + } catch (IOException x) { } + } + + // invoke postVisitDirectory last + return visitor.postVisitDirectory(file, ioe); + + } finally { + // remove key from trail if doing cycle detection + if (detectCycles) { + ancestors.remove(ancestors.size()-1); + } + } + } + + private static class AncestorDirectory { + private final FileRef dir; + private final Object key; + AncestorDirectory(FileRef dir, Object key) { + this.dir = dir; + this.key = key; + } + FileRef file() { + return dir; + } + Object fileKey() { + return key; + } + } +} diff --git a/src/share/classes/java/nio/file/FileVisitOption.java b/src/share/classes/java/nio/file/FileVisitOption.java new file mode 100644 index 0000000000000000000000000000000000000000..c02e3e2d1064636143429fcc15cf98a57e35f235 --- /dev/null +++ b/src/share/classes/java/nio/file/FileVisitOption.java @@ -0,0 +1,45 @@ +/* + * Copyright 2007-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 java.nio.file; + +/** + * Defines the file tree traversal options. + * + * @since 1.7 + * + * @see Files#walkFileTree + */ + +public enum FileVisitOption { + /** + * Follow symbolic links. + */ + FOLLOW_LINKS, + /** + * Detect cycles in the file tree. + */ + DETECT_CYCLES; +} diff --git a/src/share/classes/java/nio/file/FileVisitResult.java b/src/share/classes/java/nio/file/FileVisitResult.java new file mode 100644 index 0000000000000000000000000000000000000000..28e628bc85b810121c326f902ebdd4c075d4353b --- /dev/null +++ b/src/share/classes/java/nio/file/FileVisitResult.java @@ -0,0 +1,62 @@ +/* + * Copyright 2007-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 java.nio.file; + +/** + * The result type of a {@link FileVisitor FileVisitor}. + * + * @since 1.7 + * + * @see Files#walkFileTree + */ + +public enum FileVisitResult { + /** + * Continue. When returned from a {@link FileVisitor#preVisitDirectory + * preVisitDirectory} method then the entries in the directory should also + * be visited. + */ + CONTINUE, + /** + * Terminate. + */ + TERMINATE, + /** + * Continue without visiting the entries in this directory. This result + * is only meaningful when returned from the {@link + * FileVisitor#preVisitDirectory preVisitDirectory} method; otherwise + * this result type is the same as returning {@link #CONTINUE}. + */ + SKIP_SUBTREE, + /** + * Continue without visiting the <em>siblings</em> of this file or directory. + * If returned from the {@link FileVisitor#preVisitDirectory + * preVisitDirectory} method then the entries in the directory are also + * skipped and the {@link FileVisitor#postVisitDirectory postVisitDirectory} + * method is not invoked. + */ + SKIP_SIBLINGS; +} diff --git a/src/share/classes/java/nio/file/FileVisitor.java b/src/share/classes/java/nio/file/FileVisitor.java new file mode 100644 index 0000000000000000000000000000000000000000..6d65eba27a923165c3e3088289174978256a7e9c --- /dev/null +++ b/src/share/classes/java/nio/file/FileVisitor.java @@ -0,0 +1,175 @@ +/* + * Copyright 2007-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 java.nio.file; + +import java.nio.file.attribute.BasicFileAttributes; +import java.io.IOException; + +/** + * A visitor of files. An implementation of this interface is provided to the + * {@link Files#walkFileTree walkFileTree} utility method to visit each file + * in a tree. + * + * <p> <b>Usage Examples:</b> + * Suppose we want to delete a file tree. In that case, each directory should + * be deleted after the entries in the directory are deleted. + * <pre> + * Path start = ... + * Files.walkFileTree(start, new SimpleFileVisitor<Path>() { + * @Override + * public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) { + * try { + * file.delete(false); + * } catch (IOException exc) { + * // failed to delete + * } + * return FileVisitResult.CONTINUE; + * } + * @Override + * public FileVisitResult postVisitDirectory(Path dir, IOException e) { + * if (e == null) { + * try { + * dir.delete(false); + * } catch (IOException exc) { + * // failed to delete + * } + * } else { + * // directory iteration failed + * } + * return FileVisitResult.CONTINUE; + * } + * }); + * </pre> + * <p> Furthermore, suppose we want to copy a file tree rooted at a source + * directory to a target location. In that case, symbolic links should be + * followed and the target directory should be created before the entries in + * the directory are copied. + * <pre> + * final Path source = ... + * final Path target = ... + * + * Files.walkFileTree(source, EnumSet.of(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE, + * new SimpleFileVisitor<Path>() { + * @Override + * public FileVisitResult preVisitDirectory(Path dir) { + * try { + * dir.copyTo(target.resolve(source.relativize(dir))); + * } catch (FileAlreadyExistsException e) { + * // ignore + * } catch (IOException e) { + * // copy failed, skip rest of directory and descendants + * return SKIP_SUBTREE; + * } + * return CONTINUE; + * } + * @Override + * public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) { + * try { + * file.copyTo(target.resolve(source.relativize(file))); + * } catch (IOException e) { + * // copy failed + * } + * return CONTINUE; + * } + * }); + * </pre> + * + * @since 1.7 + */ + +public interface FileVisitor<T extends FileRef> { + + /** + * Invoked for a directory before entries in the directory are visited. + * + * <p> If this method returns {@link FileVisitResult#CONTINUE CONTINUE}, + * then entries in the directory are visited. If this method returns {@link + * FileVisitResult#SKIP_SUBTREE SKIP_SUBTREE} or {@link + * FileVisitResult#SKIP_SIBLINGS SKIP_SIBLINGS} then entries in the + * directory (and any descendants) will not be visited. + * + * @param dir + * a reference to the directory + * + * @return the visit result + */ + FileVisitResult preVisitDirectory(T dir); + + /** + * Invoked for a directory that could not be opened. + * + * @param dir + * a reference to the directory + * @param exc + * the I/O exception thrown from the attempt to open the directory + * + * @return the visit result + */ + FileVisitResult preVisitDirectoryFailed(T dir, IOException exc); + + /** + * Invoked for a file in a directory. + * + * @param file + * a reference to the file + * @param attrs + * the file's basic attributes + * + * @return the visit result + */ + FileVisitResult visitFile(T file, BasicFileAttributes attrs); + + /** + * Invoked for a file when its basic file attributes could not be read. + * + * @param file + * a reference to the file + * @param exc + * the I/O exception thrown from the attempt to read the file + * attributes + * + * @return the visit result + */ + FileVisitResult visitFileFailed(T file, IOException exc); + + /** + * Invoked for a directory after entries in the directory, and all of their + * descendants, have been visited. This method is also invoked when iteration + * of the directory completes prematurely (by a {@link #visitFile visitFile} + * method returning {@link FileVisitResult#SKIP_SIBLINGS SKIP_SIBLINGS}, + * or an I/O error when iterating over the directory). + * + * @param dir + * a reference to the directory + * @param exc + * {@code null} if the iteration of the directory completes without + * an error; otherwise the I/O exception that caused the iteration + * of the directory to complete prematurely + * + * @return the visit result + */ + FileVisitResult postVisitDirectory(T dir, IOException exc); +} diff --git a/src/share/classes/java/nio/file/Files.java b/src/share/classes/java/nio/file/Files.java new file mode 100644 index 0000000000000000000000000000000000000000..42fdad823b3bd43ebb3244c829ee59c3667cb0fc --- /dev/null +++ b/src/share/classes/java/nio/file/Files.java @@ -0,0 +1,406 @@ +/* + * Copyright 2007-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 java.nio.file; + +import java.nio.file.spi.FileTypeDetector; +import java.io.IOException; +import java.util.*; +import java.security.AccessController; +import java.security.PrivilegedAction; + +/** + * Utility methods for files and directories. + * + * @since 1.7 + */ + +public final class Files { + private Files() { } + + // lazy loading of default and installed file type detectors + private static class DefaultFileTypeDetectorHolder { + static final FileTypeDetector defaultFileTypeDetector = + sun.nio.fs.DefaultFileTypeDetector.create(); + static final List<FileTypeDetector> installeDetectors = + loadInstalledDetectors(); + + // loads all installed file type detectors + private static List<FileTypeDetector> loadInstalledDetectors() { + return AccessController + .doPrivileged(new PrivilegedAction<List<FileTypeDetector>>() { + @Override public List<FileTypeDetector> run() { + List<FileTypeDetector> list = new ArrayList<FileTypeDetector>(); + ServiceLoader<FileTypeDetector> loader = ServiceLoader + .load(FileTypeDetector.class, ClassLoader.getSystemClassLoader()); + for (FileTypeDetector detector: loader) { + list.add(detector); + } + return list; + }}); + } + } + + /** + * Probes the content type of a file. + * + * <p> This method uses the installed {@link FileTypeDetector} implementations + * to probe the given file to determine its content type. Each file type + * detector's {@link FileTypeDetector#probeContentType probeContentType} is + * invoked, in turn, to probe the file type. If the file is recognized then + * the content type is returned. If the file is not recognized by any of the + * installed file type detectors then a system-default file type detector is + * invoked to guess the content type. + * + * <p> A given invocation of the Java virtual machine maintains a system-wide + * list of file type detectors. Installed file type detectors are loaded + * using the service-provider loading facility defined by the {@link ServiceLoader} + * class. Installed file type detectors are loaded using the system class + * loader. If the system class loader cannot be found then the extension class + * loader is used; If the extension class loader cannot be found then the + * bootstrap class loader is used. File type detectors are typically installed + * by placing them in a JAR file on the application class path or in the + * extension directory, the JAR file contains a provider-configuration file + * named {@code java.nio.file.spi.FileTypeDetector} in the resource directory + * {@code META-INF/services}, and the file lists one or more fully-qualified + * names of concrete subclass of {@code FileTypeDetector } that have a zero + * argument constructor. If the process of locating or instantiating the + * installed file type detectors fails then an unspecified error is thrown. + * The ordering that installed providers are located is implementation + * specific. + * + * <p> The return value of this method is the string form of the value of a + * Multipurpose Internet Mail Extension (MIME) content type as + * defined by <a href="http://www.ietf.org/rfc/rfc2045.txt"><i>RFC 2045: + * Multipurpose Internet Mail Extensions (MIME) Part One: Format of Internet + * Message Bodies</i></a>. The string is guaranteed to be parsable according + * to the grammar in the RFC. + * + * @param file + * The file reference + * + * @return The content type of the file, or {@code null} if the content + * type cannot be determined + * + * @throws IOException + * If an I/O error occurs + * @throws SecurityException + * If a security manager is installed and it denies an unspecified + * permission required by a file type detector implementation. + * + * @see DirectoryStreamFilters#newContentTypeFilter + */ + public static String probeContentType(FileRef file) + throws IOException + { + // try installed file type detectors + for (FileTypeDetector detector: DefaultFileTypeDetectorHolder.installeDetectors) { + String result = detector.probeContentType(file); + if (result != null) + return result; + } + + // fallback to default + return DefaultFileTypeDetectorHolder.defaultFileTypeDetector + .probeContentType(file); + } + + /** + * Invokes a {@link FileAction} for each entry in a directory accepted + * by a given {@link java.nio.file.DirectoryStream.Filter filter}. + * + * <p> This method opens the given directory and invokes the file action's + * {@link FileAction#invoke invoke} method for each entry accepted by the + * filter. When iteration is completed then the directory is closed. If the + * {@link DirectoryStream#close close} method throws an {@code IOException} + * then it is silently ignored. + * + * <p> If the {@code FileAction}'s {@code invoke} method terminates due + * to an uncaught {@link IOException}, {@code Error} or {@code RuntimeException} + * then the exception is propagated by this method after closing the + * directory. + * + * @param dir + * The directory + * @param filter + * The filter + * @param action + * The {@code FileAction} to invoke for each accepted entry + * + * @throws NotDirectoryException + * If the {@code dir} parameter is not a directory <i>(optional + * specific exception)</i> + * @throws IOException + * If an I/O error occurs or the {@code invoke} method terminates + * due to an uncaught {@code IOException} + * @throws SecurityException + * In the case of the default provider, the {@link + * SecurityManager#checkRead(String) checkRead} method is invoked + * to check read access to the directory. + */ + public static void withDirectory(Path dir, + DirectoryStream.Filter<? super Path> filter, + FileAction<? super Path> action) + throws IOException + { + // explicit null check required in case directory is empty + if (action == null) + throw new NullPointerException(); + + DirectoryStream<Path> stream = dir.newDirectoryStream(filter); + try { + // set to true when invoking the action so as to distinguish a + // CME thrown by the iteration from a CME thrown by the invoke + boolean inAction = false; + try { + for (Path entry: stream) { + inAction = true; + action.invoke(entry); + inAction = false; + } + } catch (ConcurrentModificationException cme) { + if (!inAction) { + Throwable cause = cme.getCause(); + if (cause instanceof IOException) + throw (IOException)cause; + } + throw cme; + } + } finally { + try { + stream.close(); + } catch (IOException x) { } + } + } + + /** + * Invokes a {@link FileAction} for each entry in a directory with a + * file name that matches a given pattern. + * + * <p> This method opens the given directory and invokes the file action's + * {@link FileAction#invoke invoke} method for each entry that matches the + * given pattern. When iteration is completed then the directory is closed. + * If the {@link DirectoryStream#close close} method throws an {@code + * IOException} then it is silently ignored. + * + * <p> If the {@code FileAction}'s {@code invoke} method terminates due + * to an uncaught {@link IOException}, {@code Error} or {@code RuntimeException} + * then the exception is propagated by this method after closing the + * directory. + * + * <p> The globbing pattern language supported by this method is as + * specified by the {@link FileSystem#getPathMatcher getPathMatcher} method. + * + * @param dir + * The directory + * @param glob + * The globbing pattern + * @param action + * The {@code FileAction} to invoke for each entry + * + * @throws NotDirectoryException + * If the {@code dir} parameter is not a directory <i>(optional + * specific exception)</i> + * @throws IOException + * If an I/O error occurs or the {@code invoke} method terminates + * due to an uncaught {@code IOException} + * @throws SecurityException + * In the case of the default provider, the {@link + * SecurityManager#checkRead(String) checkRead} method is invoked + * to check read access to the directory. + */ + public static void withDirectory(Path dir, + String glob, + FileAction<? super Path> action) + throws IOException + { + if (glob == null) + throw new NullPointerException("'glob' is null"); + final PathMatcher matcher = dir.getFileSystem().getPathMatcher("glob:" + glob); + DirectoryStream.Filter<Path> filter = new DirectoryStream.Filter<Path>() { + @Override + public boolean accept(Path entry) { + return matcher.matches(entry.getName()); + } + }; + withDirectory(dir, filter, action); + } + + /** + * Invokes a {@link FileAction} for all entries in a directory. + * + * <p> This method works as if invoking it were equivalent to evaluating the + * expression: + * <blockquote><pre> + * withDirectory(dir, "*", action) + * </pre></blockquote> + * + * @param dir + * The directory + * @param action + * The {@code FileAction} to invoke for each entry + * + * @throws NotDirectoryException + * If the {@code dir} parameter is not a directory <i>(optional + * specific exception)</i> + * @throws IOException + * If an I/O error occurs or the {@code invoke} method terminates + * due to an uncaught {@code IOException} + * @throws SecurityException + * In the case of the default provider, the {@link + * SecurityManager#checkRead(String) checkRead} method is invoked + * to check read access to the directory. + */ + public static void withDirectory(Path dir, FileAction<? super Path> action) + throws IOException + { + withDirectory(dir, "*", action); + } + + /** + * Walks a file tree. + * + * <p> This method walks a file tree rooted at a given starting file. The + * file tree traversal is <em>depth-first</em> with the given {@link + * FileVisitor} invoked for each file encountered. File tree traversal + * completes when all accessible files in the tree have been visited, a + * visitor returns a result of {@link FileVisitResult#TERMINATE TERMINATE}, + * or the visitor terminates due to an uncaught {@code Error} or {@code + * RuntimeException}. + * + * <p> For each file encountered this method attempts to gets its {@link + * java.nio.file.attribute.BasicFileAttributes}. If the file is not a + * directory then the {@link FileVisitor#visitFile visitFile} method is + * invoked with the file attributes. If the file attributes cannot be read, + * due to an I/O exception, then the {@link FileVisitor#visitFileFailed + * visitFileFailed} method is invoked with the I/O exception. + * + * <p> Where the file is a directory, this method attempts to open it by + * invoking its {@link Path#newDirectoryStream newDirectoryStream} method. + * Where the directory could not be opened, due to an {@code IOException}, + * then the {@link FileVisitor#preVisitDirectoryFailed preVisitDirectoryFailed} + * method is invoked with the I/O exception, after which, the file tree walk + * continues, by default, at the next <em>sibling</em> of the directory. + * + * <p> Where the directory is opened successfully, then the entries in the + * directory, and their <em>descendants</em> are visited. When all entries + * have been visited, or an I/O error occurs during iteration of the + * directory, then the directory is closed and the visitor's {@link + * FileVisitor#postVisitDirectory postVisitDirectory} method is invoked. + * The file tree walk then continues, by default, at the next <em>sibling</em> + * of the directory. + * + * <p> By default, symbolic links are not automatically followed by this + * method. If the {@code options} parameter contains the {@link + * FileVisitOption#FOLLOW_LINKS FOLLOW_LINKS} option then symbolic links are + * followed. When following links, and the attributes of the target cannot + * be read, then this method attempts to get the {@code BasicFileAttributes} + * of the link. If they can be read then the {@code visitFile} method is + * invoked with the attributes of the link (otherwise the {@code visitFileFailed} + * method is invoked as specified above). + * + * <p> If the {@code options} parameter contains the {@link + * FileVisitOption#DETECT_CYCLES DETECT_CYCLES} or {@link + * FileVisitOption#FOLLOW_LINKS FOLLOW_LINKS} options then this method keeps + * track of directories visited so that cycles can be detected. A cycle + * arises when there is an entry in a directory that is an ancestor of the + * directory. Cycle detection is done by recording the {@link + * java.nio.file.attribute.BasicFileAttributes#fileKey file-key} of directories, + * or if file keys are not available, by invoking the {@link FileRef#isSameFile + * isSameFile} method to test if a directory is the same file as an + * ancestor. When a cycle is detected the {@link FileVisitor#visitFile + * visitFile} is invoked with the attributes of the directory. The {@link + * java.nio.file.attribute.BasicFileAttributes#isDirectory isDirectory} + * method may be used to test if the file is a directory and that a cycle is + * detected. The {@code preVisitDirectory} and {@code postVisitDirectory} + * methods are not invoked. + * + * <p> The {@code maxDepth} parameter is the maximum number of levels of + * directories to visit. A value of {@code 0} means that only the starting + * file is visited, unless denied by the security manager. A value of + * {@link Integer#MAX_VALUE MAX_VALUE} may be used to indicate that all + * levels should be visited. + * + * <p> If a visitor returns a result of {@code null} then {@code + * NullPointerException} is thrown. + * + * <p> When a security manager is installed and it denies access to a file + * (or directory), then it is ignored and the visitor is not invoked for + * that file (or directory). + * + * @param start + * The starting file + * @param options + * Options to configure the traversal + * @param maxDepth + * The maximum number of directory levels to visit + * @param visitor + * The file visitor to invoke for each file + * + * @throws IllegalArgumentException + * If the {@code maxDepth} parameter is negative + * @throws SecurityException + * If the security manager denies access to the starting file. + * In the case of the default provider, the {@link + * SecurityManager#checkRead(String) checkRead} method is invoked + * to check read access to the directory. + */ + public static void walkFileTree(Path start, + Set<FileVisitOption> options, + int maxDepth, + FileVisitor<? super Path> visitor) + { + if (maxDepth < 0) + throw new IllegalArgumentException("'maxDepth' is negative"); + new FileTreeWalker(options, visitor).walk(start, maxDepth); + } + + /** + * Walks a file tree. + * + * <p> This method works as if invoking it were equivalent to evaluating the + * expression: + * <blockquote><pre> + * walkFileTree(start, EnumSet.noneOf(FileVisitOption.class), Integer.MAX_VALUE, visitor) + * </pre></blockquote> + * + * @param start + * The starting file + * @param visitor + * The file visitor to invoke for each file + * + * @throws SecurityException + * If the security manager denies access to the starting file. + * In the case of the default provider, the {@link + * SecurityManager#checkRead(String) checkRead} method is invoked + * to check read access to the directory. + */ + public static void walkFileTree(Path start, FileVisitor<? super Path> visitor) { + walkFileTree(start, + EnumSet.noneOf(FileVisitOption.class), + Integer.MAX_VALUE, + visitor); + } +} diff --git a/src/share/classes/java/nio/file/InvalidPathException.java b/src/share/classes/java/nio/file/InvalidPathException.java new file mode 100644 index 0000000000000000000000000000000000000000..37f23202c63d9d9bb2c79d05d8c67fd081d1d945 --- /dev/null +++ b/src/share/classes/java/nio/file/InvalidPathException.java @@ -0,0 +1,130 @@ +/* + * Copyright 2007-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 java.nio.file; + +/** + * Unchecked exception thrown when path string cannot be converted into a + * {@link Path} because the path string contains invalid characters, or + * the path string is invalid for other file system specific reasons. + */ + +public class InvalidPathException + extends IllegalArgumentException +{ + static final long serialVersionUID = 4355821422286746137L; + + private String input; + private int index; + + /** + * Constructs an instance from the given input string, reason, and error + * index. + * + * @param input the input string + * @param reason a string explaining why the input was rejected + * @param index the index at which the error occurred, + * or <tt>-1</tt> if the index is not known + * + * @throws NullPointerException + * if either the input or reason strings are <tt>null</tt> + * + * @throws IllegalArgumentException + * if the error index is less than <tt>-1</tt> + */ + public InvalidPathException(String input, String reason, int index) { + super(reason); + if ((input == null) || (reason == null)) + throw new NullPointerException(); + if (index < -1) + throw new IllegalArgumentException(); + this.input = input; + this.index = index; + } + + /** + * Constructs an instance from the given input string and reason. The + * resulting object will have an error index of <tt>-1</tt>. + * + * @param input the input string + * @param reason a string explaining why the input was rejected + * + * @throws NullPointerException + * if either the input or reason strings are <tt>null</tt> + */ + public InvalidPathException(String input, String reason) { + this(input, reason, -1); + } + + /** + * Returns the input string. + * + * @return the input string + */ + public String getInput() { + return input; + } + + /** + * Returns a string explaining why the input string was rejected. + * + * @return the reason string + */ + public String getReason() { + return super.getMessage(); + } + + /** + * Returns an index into the input string of the position at which the + * error occurred, or <tt>-1</tt> if this position is not known. + * + * @return the error index + */ + public int getIndex() { + return index; + } + + /** + * Returns a string describing the error. The resulting string + * consists of the reason string followed by a colon character + * (<tt>':'</tt>), a space, and the input string. If the error index is + * defined then the string <tt>" at index "</tt> followed by the index, in + * decimal, is inserted after the reason string and before the colon + * character. + * + * @return a string describing the error + */ + public String getMessage() { + StringBuffer sb = new StringBuffer(); + sb.append(getReason()); + if (index > -1) { + sb.append(" at index "); + sb.append(index); + } + sb.append(": "); + sb.append(input); + return sb.toString(); + } +} diff --git a/src/share/classes/java/nio/file/LinkOption.java b/src/share/classes/java/nio/file/LinkOption.java new file mode 100644 index 0000000000000000000000000000000000000000..08e5c1e1d72ae4d6cc520bddb3c45e0820657c28 --- /dev/null +++ b/src/share/classes/java/nio/file/LinkOption.java @@ -0,0 +1,43 @@ +/* + * Copyright 2007-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 java.nio.file; + +/** + * Defines the options as to how symbolic links are handled. + * + * @since 1.7 + */ + +public enum LinkOption implements OpenOption, CopyOption { + /** + * Do not follow symbolic links. + * + * @see FileRef#getFileAttributeView(Class,LinkOption[]) + * @see Path#copyTo + * @see SecureDirectoryStream#newByteChannel + */ + NOFOLLOW_LINKS; +} diff --git a/src/share/classes/java/nio/file/LinkPermission.java b/src/share/classes/java/nio/file/LinkPermission.java new file mode 100644 index 0000000000000000000000000000000000000000..d17788fd029315fea2dd104b08ca8f39aa80cad6 --- /dev/null +++ b/src/share/classes/java/nio/file/LinkPermission.java @@ -0,0 +1,107 @@ +/* + * Copyright 2007-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 java.nio.file; + +import java.security.BasicPermission; + +/** + * The {@code Permission} class for link creation operations. + * + * <p> The following table provides a summary description of what the permission + * allows, and discusses the risks of granting code the permission. + * + * <table border=1 cellpadding=5 + * summary="Table shows permission target name, what the permission allows, and associated risks"> + * <tr> + * <th>Permission Target Name</th> + * <th>What the Permission Allows</th> + * <th>Risks of Allowing this Permission</th> + * </tr> + * <tr> + * <td>hard</td> + * <td> Ability to add an existing file to a directory. This is sometimes + * known as creating a link, or hard link. </td> + * <td> Extreme care should be taken when granting this permission. It allows + * linking to any file or directory in the file system thus allowing the + * attacker to access to all files. </td> + * </tr> + * <tr> + * <td>symbolic</td> + * <td> Ability to create symbolic links. </td> + * <td> Extreme care should be taken when granting this permission. It allows + * linking to any file or directory in the file system thus allowing the + * attacker to access to all files. </td> + * </tr> + * </table> + * + * @since 1.7 + * + * @see Path#createLink + * @see Path#createSymbolicLink + */ +public final class LinkPermission extends BasicPermission { + static final long serialVersionUID = -1441492453772213220L; + + private void checkName(String name) { + if (!name.equals("hard") && !name.equals("symbolic")) { + throw new IllegalArgumentException("name: " + name); + } + } + + /** + * Constructs a {@code LinkPermission} with the specified name. + * + * @param name + * the name of the permission. It must be "hard" or "symbolic". + * + * @throws IllegalArgumentException + * if name is empty or invalid + */ + public LinkPermission(String name) { + super(name); + checkName(name); + } + + /** + * Constructs a {@code LinkPermission} with the specified name. + * + * @param name + * the name of the permission; must be "hard" or "symbolic". + * @param actions + * the actions for the permission; must be the empty string or + * {@code null} + * + * @throws IllegalArgumentException + * if name is empty or invalid + */ + public LinkPermission(String name, String actions) { + super(name); + checkName(name); + if (actions != null && actions.length() > 0) { + throw new IllegalArgumentException("actions: " + actions); + } + } +} diff --git a/src/share/classes/java/nio/file/NoSuchFileException.java b/src/share/classes/java/nio/file/NoSuchFileException.java new file mode 100644 index 0000000000000000000000000000000000000000..ccde9ae95e70bd8b12b55dbedaf5ece61727fd3a --- /dev/null +++ b/src/share/classes/java/nio/file/NoSuchFileException.java @@ -0,0 +1,63 @@ +/* + * Copyright 2007-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 java.nio.file; + +/** + * Checked exception thrown when an attempt is made to access a file that does + * not exist. + * + * @since 1.7 + */ + +public class NoSuchFileException + extends FileSystemException +{ + static final long serialVersionUID = -1390291775875351931L; + + /** + * Constructs an instance of this class. + * + * @param file + * a string identifying the file or {@code null} if not known. + */ + public NoSuchFileException(String file) { + super(file); + } + + /** + * Constructs an instance of this class. + * + * @param file + * a string identifying the file or {@code null} if not known. + * @param other + * a string identifying the other file or {@code null} if not known. + * @param reason + * a reason message with additional information or {@code null} + */ + public NoSuchFileException(String file, String other, String reason) { + super(file, other, reason); + } +} diff --git a/src/share/classes/java/nio/file/NotDirectoryException.java b/src/share/classes/java/nio/file/NotDirectoryException.java new file mode 100644 index 0000000000000000000000000000000000000000..684bd2df44e12744493de30397dc165651e4fce0 --- /dev/null +++ b/src/share/classes/java/nio/file/NotDirectoryException.java @@ -0,0 +1,49 @@ +/* + * Copyright 2007-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 java.nio.file; + +/** + * Checked exception thrown when a file system operation, intended for a + * directory, fails because the file is not a directory. + * + * @since 1.7 + */ + +public class NotDirectoryException + extends FileSystemException +{ + private static final long serialVersionUID = -9011457427178200199L; + + /** + * Constructs an instance of this class. + * + * @param file + * a string identifying the file or {@code null} if not known + */ + public NotDirectoryException(String file) { + super(file); + } +} diff --git a/src/share/classes/java/nio/file/NotLinkException.java b/src/share/classes/java/nio/file/NotLinkException.java new file mode 100644 index 0000000000000000000000000000000000000000..bdc1fc354adf2a184aadb86982c1879672afda9f --- /dev/null +++ b/src/share/classes/java/nio/file/NotLinkException.java @@ -0,0 +1,63 @@ +/* + * Copyright 2007-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 java.nio.file; + +/** + * Checked exception thrown when a file system operation fails because a file + * is not a link. + * + * @since 1.7 + */ + +public class NotLinkException + extends FileSystemException +{ + static final long serialVersionUID = -388655596416518021L; + + /** + * Constructs an instance of this class. + * + * @param file + * a string identifying the file or {@code null} if not known + */ + public NotLinkException(String file) { + super(file); + } + + /** + * Constructs an instance of this class. + * + * @param file + * a string identifying the file or {@code null} if not known + * @param other + * a string identifying the other file or {@code null} if not known + * @param reason + * a reason message with additional information or {@code null} + */ + public NotLinkException(String file, String other, String reason) { + super(file, other, reason); + } +} diff --git a/src/share/classes/java/nio/file/OpenOption.java b/src/share/classes/java/nio/file/OpenOption.java new file mode 100644 index 0000000000000000000000000000000000000000..c525307e7dcfb656c10c2c2d34004668f0b0da78 --- /dev/null +++ b/src/share/classes/java/nio/file/OpenOption.java @@ -0,0 +1,45 @@ +/* + * Copyright 2007-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 java.nio.file; + +/** + * An object that configures how to open or create a file. + * + * <p> Objects of this type are used by methods such as {@link + * Path#newOutputStream(OpenOption[]) newOutputStream}, {@link + * FileRef#newByteChannel newByteChannel}, {@link + * java.nio.channels.FileChannel#open FileChannel.open}, and {@link + * java.nio.channels.AsynchronousFileChannel#open AsynchronousFileChannel.open} + * when opening or creating a file. + * + * <p> The {@link StandardOpenOption} enumeration type defines the + * <i>standard</i> options. + * + * @since 1.7 + */ + +public interface OpenOption { +} diff --git a/src/share/classes/java/nio/file/Path.java b/src/share/classes/java/nio/file/Path.java new file mode 100644 index 0000000000000000000000000000000000000000..55bf8fd2675995dddb3dad50da5b867f0369ac3e --- /dev/null +++ b/src/share/classes/java/nio/file/Path.java @@ -0,0 +1,1613 @@ +/* + * Copyright 2007-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 java.nio.file; + +import java.nio.file.attribute.*; +import java.nio.channels.*; +import java.io.*; +import java.net.URI; +import java.util.*; + +/** + * A file reference that locates a file using a system dependent path. The file + * is not required to exist. + * + * <p> On many platforms a <em>path</em> is the means to locate and access files + * in a file system. A path is hierarchical and composed of a sequence of + * directory and file name elements separated by a special separator or + * delimiter. + * + * <h4>Path operations</h4> + * + * <p> A system dependent path represented by this class is conceptually a + * sequence of name elements and optionally a <em>root component</em>. The name + * that is <em>farthest</em> from the root of the directory hierarchy is the + * name of a file or directory. The other elements are directory names. The root + * component typically identifies a file system hierarchy. A {@code Path} can + * represent a root, a root and a sequence of names, or simply one or more name + * elements. It defines the {@link #getName() getName}, {@link #getParent + * getParent}, {@link #getRoot getRoot}, and {@link #subpath subpath} methods + * to access the components or a subsequence of its name elements. + * + * <p> In addition to accessing the components of a path, a {@code Path} also + * defines {@link #resolve(Path) resolve} and {@link #relativize relativize} + * operations. Paths can also be {@link #compareTo compared}, and tested + * against each other using using the {@link #startsWith startsWith} and {@link + * #endsWith endWith} methods. + * + * <h4>File operations</h4> + * + * <p> A {@code Path} is either <em>absolute</em> or <em>relative</em>. An + * absolute path is complete in that does not need to be combined with another + * path in order to locate a file. All operations on relative paths are first + * resolved against a file system's default directory as if by invoking the + * {@link #toAbsolutePath toAbsolutePath} method. + * + * <p> In addition to the operations defined by the {@link FileRef} interface, + * this class defines the following operations: + * + * <ul> + * <li><p> Files may be {@link #createFile(FileAttribute[]) created}, or + * directories may be {@link #createDirectory(FileAttribute[]) created}. + * </p></li> + * <li><p> Directories can be {@link #newDirectoryStream opened} so as to + * iterate over the entries in the directory. </p></li> + * <li><p> Files can be {@link #copyTo(Path,CopyOption[]) copied} or + * {@link #moveTo(Path,CopyOption[]) moved}. </p></li> + * <li><p> Symbolic-links may be {@link #createSymbolicLink created}, or the + * target of a link may be {@link #readSymbolicLink read}. </p></li> + * <li><p> {@link #newInputStream InputStream} or {@link #newOutputStream + * OutputStream} streams can be created to allow for interoperation with the + * <a href="../../../java/io/package-summary.html">{@code java.io}</a> package + * where required. </li></p> + * <li><p> The {@link #toRealPath real} path of an existing file may be + * obtained. </li></p> + * </ul> + * + * <p> This class implements {@link Watchable} interface so that a directory + * located by a path can be {@link #register registered} with a {@link WatchService}. + * and entries in the directory watched. + * + * <h4>File attributes</h4> + * + * The <a href="attribute/package-summary.html">{@code java.nio.file.attribute}</a> + * package provides access to file attributes or <em>meta-data</em> associated + * with files. The {@link Attributes Attributes} class defines methods that + * operate on or return file attributes. For example, the file type, size, + * timestamps, and other <em>basic</em> meta-data are obtained, in bulk, by + * invoking the {@link Attributes#readBasicFileAttributes + * Attributes.readBasicFileAttributes} method: + * <pre> + * Path file = ... + * BasicFileAttributes attrs = Attributes.readBasicFileAttributes(file); + * </pre> + * + * <a name="interop"><h4>Interoperability</h4></a> + * + * <p> Paths created by file systems associated with the default {@link + * java.nio.file.spi.FileSystemProvider provider} are generally interoperable + * with the {@link java.io.File java.io.File} class. Paths created by other + * providers are unlikely to be interoperable with the abstract path names + * represented by {@code java.io.File}. The {@link java.io.File#toPath + * File.toPath} method may be used to obtain a {@code Path} from the abstract + * path name represented by a {@code java.io.File java.io.File} object. The + * resulting {@code Path} can be used to operate on the same file as the {@code + * java.io.File} object. + * + * <p> Path objects created by file systems associated with the default + * provider are interoperable with objects created by other file systems created + * by the same provider. Path objects created by file systems associated with + * other providers may not be interoperable with other file systems created by + * the same provider. The reasons for this are provider specific. + * + * <h4>Concurrency</h4></a> + * + * <p> Instances of this class are immutable and safe for use by multiple concurrent + * threads. + * + * @since 1.7 + */ + +public abstract class Path + implements FileRef, Comparable<Path>, Iterable<Path>, Watchable +{ + /** + * Initializes a new instance of this class. + */ + protected Path() { } + + /** + * Returns the file system that created this object. + * + * @return the file system that created this object + */ + public abstract FileSystem getFileSystem(); + + /** + * Tells whether or not this path is absolute. + * + * <p> An absolute path is complete in that it doesn't need to be + * combined with other path information in order to locate a file. + * + * @return {@code true} if, and only if, this path is absolute + */ + public abstract boolean isAbsolute(); + + /** + * Returns the root component of this path as a {@code Path} object, + * or {@code null} if this path does not have a root component. + * + * @return a path representing the root component of this path, + * or {@code null} + */ + public abstract Path getRoot(); + + /** + * Returns the name of the file or directory denoted by this path. The + * file name is the <em>farthest</em> element from the root in the directory + * hierarchy. + * + * @return a path representing the name of the file or directory, or + * {@code null} if this path has zero elements + */ + public abstract Path getName(); + + /** + * Returns the <em>parent path</em>, or {@code null} if this path does not + * have a parent. + * + * <p> The parent of this path object consists of this path's root + * component, if any, and each element in the path except for the + * <em>farthest</em> from the root in the directory hierarchy. This method + * does not access the file system; the path or its parent may not exist. + * Furthermore, this method does not eliminate special names such as "." + * and ".." that may be used in some implementations. On UNIX for example, + * the parent of "{@code /a/b/c}" is "{@code /a/b}", and the parent of + * {@code "x/y/.}" is "{@code x/y}". This method may be used with the {@link + * #normalize normalize} method, to eliminate redundant names, for cases where + * <em>shell-like</em> navigation is required. + * + * <p> If this path has one or more elements, and no root component, then + * this method is equivalent to evaluating the expression: + * <blockquote><pre> + * subpath(0, getNameCount()-1); + * </pre></blockquote> + * + * @return a path representing the path's parent + */ + public abstract Path getParent(); + + /** + * Returns the number of name elements in the path. + * + * @return the number of elements in the path, or {@code 0} if this path + * only represents a root component + */ + public abstract int getNameCount(); + + /** + * Returns a name element of this path. + * + * <p> The {@code index} parameter is the index of the name element to return. + * The element that is <em>closest</em> to the root in the directory hierarchy + * has index {@code 0}. The element that is <em>farthest</em> from the root + * has index {@link #getNameCount count}{@code -1}. + * + * @param index + * the index of the element + * + * @return the name element + * + * @throws IllegalArgumentException + * if {@code index} is negative, {@code index} is greater than or + * equal to the number of elements, or this path has zero name + * elements + */ + public abstract Path getName(int index); + + /** + * Returns a relative {@code Path} that is a subsequence of the name + * elements of this path. + * + * <p> The {@code beginIndex} and {@code endIndex} parameters specify the + * subsequence of name elements. The name that is <em>closest</em> to the root + * in the directory hierarchy has index {@code 0}. The name that is + * <em>farthest</em> from the root has index {@link #getNameCount + * count}{@code -1}. The returned {@code Path} object has the name elements + * that begin at {@code beginIndex} and extend to the element at index {@code + * endIndex-1}. + * + * @param beginIndex + * the index of the first element, inclusive + * @param endIndex + * the index of the last element, exclusive + * + * @return a new {@code Path} object that is a subsequence of the name + * elements in this {@code Path} + * + * @throws IllegalArgumentException + * if {@code beginIndex} is negative, or greater than or equal to + * the number of elements. If {@code endIndex} is less than or + * equal to {@code beginIndex}, or larger than the number of elements. + */ + public abstract Path subpath(int beginIndex, int endIndex); + + /** + * Tests if this path starts with the given path. + * + * <p> This path <em>starts</em> with the given path if this path's root + * component <em>starts</em> with the root component of the given path, + * and this path starts with the same name elements as the given path. + * If the given path has more name elements than this path then {@code false} + * is returned. + * + * <p> Whether or not the root component of this path starts with the root + * component of the given path is file system specific. If this path does + * not have a root component and the given path has a root component then + * this path does not start with the given path. + * + * @param other + * the given path + * + * @return {@code true} if this path starts with the given path; otherwise + * {@code false} + */ + public abstract boolean startsWith(Path other); + + /** + * Tests if this path ends with the given path. + * + * <p> If the given path has <em>N</em> elements, and no root component, + * and this path has <em>N</em> or more elements, then this path ends with + * the given path if the last <em>N</em> elements of each path, starting at + * the element farthest from the root, are equal. + * + * <p> If the given path has a root component then this path ends with the + * given path if the root component of this path <em>ends with</em> the root + * component of the given path, and the corresponding elements of both paths + * are equal. Whether or not the root component of this path ends with the + * root component of the given path is file system specific. If this path + * does not have a root component and the given path has a root component + * then this path does not end with the given path. + * + * @param other + * the given path + * + * @return {@code true} if this path ends with the given path; otherwise + * {@code false} + */ + public abstract boolean endsWith(Path other); + + /** + * Returns a path that is this path with redundant name elements eliminated. + * + * <p> The precise definition of this method is implementation dependent but + * in general it derives from this path, a path that does not contain + * <em>redundant</em> name elements. In many file systems, the "{@code .}" + * and "{@code ..}" are special names used to indicate the current directory + * and parent directory. In such file systems all occurrences of "{@code .}" + * are considered redundant. If a "{@code ..}" is preceded by a + * non-"{@code ..}" name then both names are considered redundant (the + * process to identify such names is repeated until is it no longer + * applicable). + * + * <p> This method does not access the file system; the path may not locate + * a file that exists. Eliminating "{@code ..}" and a preceding name from a + * path may result in the path that locates a different file than the original + * path. This can arise when the preceding name is a symbolic link. + * + * @return the resulting path, or this path if it does not contain + * redundant name elements, or {@code null} if this path does not + * have a root component and all name elements are redundant + * + * @see #getParent + * @see #toRealPath + */ + public abstract Path normalize(); + + // -- resolution and relativization -- + + /** + * Resolve the given path against this path. + * + * <p> If the {@code other} parameter is an {@link #isAbsolute() absolute} + * path then this method trivially returns {@code other}. If {@code other} + * is {@code null} then this path is returned. Otherwise this method + * considers this path to be a directory and resolves the given path + * against this path. In the simplest case, the given path does not have + * a {@link #getRoot root} component, in which case this method <em>joins</em> + * the given path to this path and returns a resulting path that {@link + * #endsWith ends} with the given path. Where the given path has a root + * component then resolution is highly implementation dependent and therefore + * unspecified. + * + * @param other + * the path to resolve against this path; can be {@code null} + * + * @return the resulting path + * + * @see #relativize + */ + public abstract Path resolve(Path other); + + /** + * Converts a given path string to a {@code Path} and resolves it against + * this {@code Path} in exactly the manner specified by the {@link + * #resolve(Path) resolve} method. + * + * @param other + * the path string to resolve against this path + * + * @return the resulting path + * + * @throws InvalidPathException + * If the path string cannot be converted to a Path. + * + * @see FileSystem#getPath + */ + public abstract Path resolve(String other); + + /** + * Constructs a relative path between this path and a given path. + * + * <p> Relativization is the inverse of {@link #resolve(Path) resolution}. + * This method attempts to construct a {@link #isAbsolute relative} path + * that when {@link #resolve(Path) resolved} against this path, yields a + * path that locates the same file as the given path. For example, on UNIX, + * if this path is {@code "/a/b"} and the given path is {@code "/a/b/c/d"} + * then the resulting relative path would be {@code "c/d"}. Where this + * path and the given path do not have a {@link #getRoot root} component, + * then a relative path can be constructed. A relative path cannot be + * constructed if only one of the paths have a root component. Where both + * paths have a root component then it is implementation dependent if a + * relative path can be constructed. If this path and the given path are + * {@link #equals equal} then {@code null} is returned. + * + * <p> For any two paths <i>p</i> and <i>q</i>, where <i>q</i> does not have + * a root component, + * <blockquote> + * <i>p</i><tt>.relativize(</tt><i>p</i><tt>.resolve(</tt><i>q</i><tt>)).equals(</tt><i>q</i><tt>)</tt> + * </blockquote> + * + * <p> When symbolic-links are supported, then whether the resulting path, + * when resolved against this path, yields a path that can be used to locate + * the {@link #isSameFile same} file as {@code other} is implementation + * dependent. For example, if this path is {@code "/a/b"} and the given + * path is {@code "/a/x"} then the resulting relative path may be {@code + * "../x"}. If {@code "b"} is a symbolic-link then is implementation + * dependent if {@code "a/b/../x"} would locate the same file as {@code "/a/x"}. + * + * @param other + * the resulting path + * + * @return the resulting relative path, or {@code null} if both paths are + * equal + * + * @throws IllegalArgumentException + * if {@code other} is not a {@code Path} that can be relativized + * against this path + */ + public abstract Path relativize(Path other); + + // -- file operations -- + + /** + * Deletes the file located by this path. + * + * <p> The {@code failIfNotExists} parameter determines how the method + * behaves when the file does not exist. When {@code true}, and the file + * does not exist, then the method fails. When {@code false} then the method + * does not fail. + * + * <p> As with the {@link FileRef#delete delete()} method, an implementation + * may require to examine the file to determine if the file is a directory. + * Consequently this method may not be atomic with respect to other file + * system operations. If the file is a symbolic-link then the link is + * deleted and not the final target of the link. + * + * <p> If the file is a directory then the directory must be empty. In some + * implementations a directory has entries for special files or links that + * are created when the directory is created. In such implementations a + * directory is considered empty when only the special entries exist. + * + * <p> On some operating systems it may not be possible to remove a file when + * it is open and in use by this Java virtual machine or other programs. + * + * @param failIfNotExists + * {@code true} if the method should fail when the file does not + * exist + * + * @throws NoSuchFileException + * if the value of the {@code failIfNotExists} is {@code true} and + * the file does not exist <i>(optional specific exception)</i> + * @throws DirectoryNotEmptyException + * if the file is a directory and could not otherwise be deleted + * because the directory is not empty <i>(optional specific + * exception)</i> + * @throws IOException + * if an I/O error occurs + * @throws SecurityException + * In the case of the default provider, and a security manager is + * installed, the {@link SecurityManager#checkDelete(String)} method + * is invoked to check delete access to the file. + */ + public abstract void delete(boolean failIfNotExists) throws IOException; + + /** + * Creates a symbolic link to a target <i>(optional operation)</i>. + * + * <p> The {@code target} parameter is the target of the link. It may be an + * {@link Path#isAbsolute absolute} or relative path and may not exist. When + * the target is a relative path then file system operations on the resulting + * link are relative to the path of the link. + * + * <p> The {@code attrs} parameter is an optional array of {@link FileAttribute + * attributes} to set atomically when creating the link. Each attribute is + * identified by its {@link FileAttribute#name name}. If more than one attribute + * of the same name is included in the array then all but the last occurrence + * is ignored. + * + * <p> Where symbolic links are supported, but the underlying {@link FileStore} + * does not support symbolic links, then this may fail with an {@link + * IOException}. Additionally, some operating systems may require that the + * Java virtual machine be started with implementation specific privileges to + * create symbolic links, in which case this method may throw {@code IOException}. + * + * @param target + * the target of the link + * @param attrs + * the array of attributes to set atomically when creating the + * symbolic link + * + * @return this path + * + * @throws UnsupportedOperationException + * if the implementation does not support symbolic links or the + * array contains an attribute that cannot be set atomically when + * creating the symbolic link + * @throws FileAlreadyExistsException + * if a file with the name already exists <i>(optional specific + * exception)</i> + * @throws IOException + * if an I/O error occurs + * @throws SecurityException + * In the case of the the default provider, and a security manager + * is installed, it denies {@link LinkPermission}<tt>("symbolic")</tt> + * or its {@link SecurityManager#checkWrite(String) checkWrite} + * method denies write access to the path of the symbolic link. + */ + public abstract Path createSymbolicLink(Path target, FileAttribute<?>... attrs) + throws IOException; + + /** + * Creates a new link (directory entry) for an existing file <i>(optional + * operation)</i>. + * + * <p> This path locates the directory entry to create. The {@code existing} + * parameter is the path to an existing file. This method creates a new + * directory entry for the file so that it can be accessed using this path. + * On some file systems this is known as creating a "hard link". Whether the + * file attributes are maintained for the file or for each directory entry + * is file system specific and therefore not specified. Typically, a file + * system requires that all links (directory entries) for a file be on the + * same file system. Furthermore, on some platforms, the Java virtual machine + * may require to be started with implementation specific privileges to + * create hard links or to create links to directories. + * + * @param existing + * a reference to an existing file + * + * @return this path + * + * @throws UnsupportedOperationException + * if the implementation does not support adding an existing file + * to a directory + * @throws FileAlreadyExistsException + * if the entry could not otherwise be created because a file of + * that name already exists <i>(optional specific exception)</i> + * @throws IOException + * if an I/O error occurs + * @throws SecurityException + * In the case of the the default provider, and a security manager + * is installed, it denies {@link LinkPermission}<tt>("hard")</tt> + * or its {@link SecurityManager#checkWrite(String) checkWrite} + * method denies write access to both this path and the path of the + * existing file. + * + * @see BasicFileAttributes#linkCount + */ + public abstract Path createLink(Path existing) throws IOException; + + /** + * Reads the target of a symbolic link <i>(optional operation)</i>. + * + * <p> If the file system supports <a href="package-summary.html#links">symbolic + * links</a> then this method is used read the target of the link, failing + * if the file is not a link. The target of the link need not exist. The + * returned {@code Path} object will be associated with the same file + * system as this {@code Path}. + * + * @return a {@code Path} object representing the target of the link + * + * @throws UnsupportedOperationException + * if the implementation does not support symbolic links + * @throws NotLinkException + * if the target could otherwise not be read because the file + * is not a link <i>(optional specific exception)</i> + * @throws IOException + * if an I/O error occurs + * @throws SecurityException + * In the case of the the default provider, and a security manager + * is installed, it checks that {@code FilePermission} has been + * granted with the "{@code readlink}" action to read the link. + */ + public abstract Path readSymbolicLink() throws IOException; + + /** + * Returns a URI to represent this path. + * + * <p> This method constructs a hierarchical {@link URI} that is absolute + * with a non-empty path component. Its {@link URI#getScheme() scheme} is + * equal to the URI scheme that identifies the provider. The exact form of + * the other URI components is highly provider dependent. In particular, it + * is implementation dependent if its query, fragment, and authority + * components are defined or undefined. + * + * <p> For the default provider the {@link URI#getPath() path} component + * will represent the {@link #toAbsolutePath absolute} path; the query, + * fragment components are undefined. Whether the authority component is + * defined or not is implementation dependent. There is no guarantee that + * the {@code URI} may be used to construct a {@link java.io.File java.io.File}. + * In particular, if this path represents a Universal Naming Convention (UNC) + * path, then the UNC server name may be encoded in the authority component + * of the resulting URI. In the case of the default provider, and the file + * exists, and it can be determined that the file is a directory, then the + * resulting {@code URI} will end with a slash. + * + * <p> The default provider provides a similar <em>round-trip</em> guarantee + * to the {@link java.io.File} class. For a given {@code Path} <i>p</i> it + * is guaranteed that + * <blockquote><tt> + * {@link Paths#get(URI) Paths.get}(</tt><i>p</i><tt>.toUri()).equals(</tt><i>p</i> + * <tt>.{@link #toAbsolutePath() toAbsolutePath}())</tt> + * </blockquote> + * so long as the original {@code Path}, the {@code URI}, and the new {@code + * Path} are all created in (possibly different invocations of) the same + * Java virtual machine. Whether other providers make any guarantees is + * provider specific and therefore unspecified. + * + * <p> When a file system is constructed to access the contents of a file + * as a file system then it is highly implementation specific if the returned + * URI represents the given path in the file system or it represents a + * <em>compound</em> URI that encodes the URI of the enclosing file system. + * A format for compound URIs is not defined in this release; such a scheme + * may be added in a future release. + * + * @return an absolute, hierarchical URI with a non-empty path component + * + * @throws IOError + * if an I/O error occurs obtaining the absolute path, or where a + * file system is constructed to access the contents of a file as + * a file system, and the URI of the enclosing file system cannot be + * obtained + * + * @throws SecurityException + * In the case of the the default provider, and a security manager + * is installed, the {@link #toAbsolutePath toAbsolutePath} method + * throws a security exception. + */ + public abstract URI toUri(); + + /** + * Returns a {@code Path} object representing the absolute path of this + * path. + * + * <p> If this path is already {@link Path#isAbsolute absolute} then this + * method simply returns this path. Otherwise, this method resolves the path + * in an implementation dependent manner, typically by resolving the path + * against a file system default directory. Depending on the implementation, + * this method may throw an I/O error if the file system is not accessible. + * + * @return a {@code Path} object representing the absolute path + * + * @throws IOError + * if an I/O error occurs + * @throws SecurityException + * In the case of the the default provider, and a security manager + * is installed, its {@link SecurityManager#checkPropertyAccess(String) + * checkPropertyAccess} method is invoked to check access to the + * system property {@code user.dir} + */ + public abstract Path toAbsolutePath(); + + /** + * Returns the <em>real</em> path of an existing file. + * + * <p> The precise definition of this method is implementation dependent but + * in general it derives from this path, an {@link #isAbsolute absolute} + * path that locates the {@link #isSameFile same} file as this path, but + * with name elements that represent the actual name of the directories + * and the file. For example, where filename comparisons on a file system + * are case insensitive then the name elements represent the names in their + * actual case. Additionally, the resulting path has redundant name + * elements removed. + * + * <p> If this path is relative then its absolute path is first obtained, + * as if by invoking the {@link #toAbsolutePath toAbsolutePath} method. + * + * <p> The {@code resolveLinks} parameter specifies if symbolic links + * should be resolved. This parameter is ignored when symbolic links are + * not supported. Where supported, and the parameter has the value {@code + * true} then symbolic links are resolved to their final target. Where the + * parameter has the value {@code false} then this method does not resolve + * symbolic links. Some implementations allow special names such as + * "{@code ..}" to refer to the parent directory. When deriving the <em>real + * path</em>, and a "{@code ..}" (or equivalent) is preceded by a + * non-"{@code ..}" name then an implementation will typically causes both + * names to be removed. When not resolving symbolic links and the preceding + * name is a symbolic link then the names are only removed if it guaranteed + * that the resulting path will locate the same file as this path. + * + * @return an absolute path represent the <em>real</em> path of the file + * located by this object + * + * @throws IOException + * if the file does not exist or an I/O error occurs + * @throws SecurityException + * In the case of the the default provider, and a security manager + * is installed, its {@link SecurityManager#checkRead(String) checkRead} + * method is invoked to check read access to the file, and where + * this path is not absolute, its {@link SecurityManager#checkPropertyAccess(String) + * checkPropertyAccess} method is invoked to check access to the + * system property {@code user.dir} + */ + public abstract Path toRealPath(boolean resolveLinks) throws IOException; + + /** + * Copy the file located by this path to a target location. + * + * <p> This method copies the file located by this {@code Path} to the + * target location with the {@code options} parameter specifying how the + * copy is performed. By default, the copy fails if the target file already + * exists, except if the source and target are the {@link #isSameFile same} + * file, in which case this method has no effect. File attributes are not + * required to be copied to the target file. If symbolic links are supported, + * and the file is a link, then the final target of the link is copied. If + * the file is a directory then it creates an empty directory in the target + * location (entries in the directory are not copied). This method can be + * used with the {@link Files#walkFileTree Files.walkFileTree} utility + * method to copy a directory and all entries in the directory, or an entire + * <i>file-tree</i> where required. + * + * <p> The {@code options} parameter is an array of options and may contain + * any of the following: + * + * <table border=1 cellpadding=5 summary=""> + * <tr> <th>Option</th> <th>Description</th> </tr> + * <tr> + * <td> {@link StandardCopyOption#REPLACE_EXISTING REPLACE_EXISTING} </td> + * <td> If the target file exists, then the target file is replaced if it + * is not a non-empty directory. If the target file exists and is a + * symbolic-link then the symbolic-link is replaced (not the target of + * the link. </td> + * </tr> + * <tr> + * <td> {@link StandardCopyOption#COPY_ATTRIBUTES COPY_ATTRIBUTES} </td> + * <td> Attempts to copy the file attributes associated with this file to + * the target file. The exact file attributes that are copied is platform + * and file system dependent and therefore unspecified. Minimally, the + * {@link BasicFileAttributes#lastModifiedTime last-modified-time} is + * copied to the target file. </td> + * </tr> + * <tr> + * <td> {@link LinkOption#NOFOLLOW_LINKS NOFOLLOW_LINKS} </td> + * <td> Symbolic-links are not followed. If the file, located by this path, + * is a symbolic-link then the link is copied rather than the target of + * the link. It is implementation specific if file attributes can be + * copied to the new link. In other words, the {@code COPY_ATTRIBUTES} + * option may be ignored when copying a link. </td> + * </tr> + * </table> + * + * <p> An implementation of this interface may support additional + * implementation specific options. + * + * <p> Copying a file is not an atomic operation. If an {@link IOException} + * is thrown then it possible that the target file is incomplete or some of + * its file attributes have not been copied from the source file. When the + * {@code REPLACE_EXISTING} option is specified and the target file exists, + * then the target file is replaced. The check for the existence of the file + * and the creation of the new file may not be atomic with respect to other + * file system activities. + * + * @param target + * the target location + * @param options + * options specifying how the copy should be done + * + * @return the target + * + * @throws UnsupportedOperationException + * if the array contains a copy option that is not supported + * @throws FileAlreadyExistsException + * if the target file exists and cannot be replaced because the + * {@code REPLACE_EXISTING} option is not specified, or the target + * file is a non-empty directory <i>(optional specific exception)</i> + * @throws IOException + * if an I/O error occurs + * @throws SecurityException + * In the case of the default provider, and a security manager is + * installed, the {@link SecurityManager#checkRead(String) checkRead} + * method is invoked to check read access to the source file, the + * {@link SecurityManager#checkWrite(String) checkWrite} is invoked + * to check write access to the target file. If a symbolic link is + * copied the security manager is invoked to check {@link + * LinkPermission}{@code ("symbolic")}. + */ + public abstract Path copyTo(Path target, CopyOption... options) + throws IOException; + + /** + * Move or rename the file located by this path to a target location. + * + * <p> By default, this method attempts to move the file to the target + * location, failing if the target file exists except if the source and + * target are the {@link #isSameFile same} file, in which case this method + * has no effect. If the file is a symbolic link then the link is moved and + * not the target of the link. This method may be invoked to move an empty + * directory. In some implementations a directory has entries for special + * files or links that are created when the directory is created. In such + * implementations a directory is considered empty when only the special + * entries exist. When invoked to move a directory that is not empty then the + * directory is moved if it does not require moving the entries in the directory. + * For example, renaming a directory on the same {@link FileStore} will usually + * not require moving the entries in the directory. When moving a directory + * requires that its entries be moved then this method fails (by throwing + * an {@code IOException}). To move a <i>file tree</i> may involve copying + * rather than moving directories and this can be done using the {@link + * #copyTo copyTo} method in conjunction with the {@link + * Files#walkFileTree Files.walkFileTree} utility method. + * + * <p> The {@code options} parameter is an array of options and may contain + * any of the following: + * + * <table border=1 cellpadding=5 summary=""> + * <tr> <th>Option</th> <th>Description</th> </tr> + * <tr> + * <td> {@link StandardCopyOption#REPLACE_EXISTING REPLACE_EXISTING} </td> + * <td> If the target file exists, then the target file is replaced if it + * is not a non-empty directory. If the target file exists and is a + * symbolic-link then the symbolic-link is replaced and not the target of + * the link. </td> + * </tr> + * <tr> + * <td> {@link StandardCopyOption#ATOMIC_MOVE ATOMIC_MOVE} </td> + * <td> The move is performed as an atomic file system operation and all + * other options are ignored. If the target file exists then it is + * implementation specific if the existing file is replaced or this method + * fails by throwing an {@link IOException}. If the move cannot be + * performed as an atomic file system operation then {@link + * AtomicMoveNotSupportedException} is thrown. This can arise, for + * example, when the target location is on a different {@code FileStore} + * and would require that the file be copied, or target location is + * associated with a different provider to this object. </td> + * </table> + * + * <p> An implementation of this interface may support additional + * implementation specific options. + * + * <p> Where the move requires that the file be copied then the {@link + * BasicFileAttributes#lastModifiedTime last-modified-time} is copied to the + * new file. An implementation may also attempt to copy other file + * attributes but is not required to fail if the file attributes cannot be + * copied. When the move is performed as a non-atomic operation, and a {@code + * IOException} is thrown, then the state of the files is not defined. The + * original file and the target file may both exist, the target file may be + * incomplete or some of its file attributes may not been copied from the + * original file. + * + * @param target + * the target location + * @param options + * options specifying how the move should be done + * + * @return the target + * + * @throws UnsupportedOperationException + * if the array contains a copy option that is not supported + * @throws FileAlreadyExistsException + * if the target file exists and cannot be replaced because the + * {@code REPLACE_EXISTING} option is not specified, or the target + * file is a non-empty directory + * @throws AtomicMoveNotSupportedException + * if the options array contains the {@code ATOMIC_MOVE} option but + * the file cannot be moved as an atomic file system operation. + * @throws IOException + * if an I/O error occurs + * @throws SecurityException + * In the case of the default provider, and a security manager is + * installed, the {@link SecurityManager#checkWrite(String) checkWrite} + * method is invoked to check write access to both the source and + * target file. + */ + public abstract Path moveTo(Path target, CopyOption... options) + throws IOException; + + /** + * Opens the directory referenced by this object, returning a {@code + * DirectoryStream} to iterate over all entries in the directory. The + * elements returned by the directory stream's {@link DirectoryStream#iterator + * iterator} are of type {@code Path}, each one representing an entry in the + * directory. The {@code Path} objects are obtained as if by {@link + * #resolve(Path) resolving} the name of the directory entry against this + * path. + * + * <p> The directory stream's {@code close} method should be invoked after + * iteration is completed so as to free any resources held for the open + * directory. The {@link Files#withDirectory Files.withDirectory} utility + * method is useful for cases where a task is performed on each accepted + * entry in a directory. This method closes the directory when iteration is + * complete (or an error occurs). + * + * <p> When an implementation supports operations on entries in the + * directory that execute in a race-free manner then the returned directory + * stream is a {@link SecureDirectoryStream}. + * + * @return a new and open {@code DirectoryStream} object + * + * @throws NotDirectoryException + * if the file could not otherwise be opened because it is not + * a directory <i>(optional specific exception)</i> + * @throws IOException + * if an I/O error occurs + * @throws SecurityException + * In the case of the default provider, and a security manager is + * installed, the {@link SecurityManager#checkRead(String) checkRead} + * method is invoked to check read access to the directory. + */ + public abstract DirectoryStream<Path> newDirectoryStream() + throws IOException; + + /** + * Opens the directory referenced by this object, returning a {@code + * DirectoryStream} to iterate over the entries in the directory. The + * elements returned by the directory stream's {@link DirectoryStream#iterator + * iterator} are of type {@code Path}, each one representing an entry in the + * directory. The {@code Path} objects are obtained as if by {@link + * #resolve(Path) resolving} the name of the directory entry against this + * path. The entries returned by the iterator are filtered by matching the + * {@code String} representation of their file names against the given + * <em>globbing</em> pattern. + * + * <p> For example, suppose we want to iterate over the files ending with + * ".java" in a directory: + * <pre> + * Path dir = ... + * DirectoryStream<Path> stream = dir.newDirectoryStream("*.java"); + * </pre> + * + * <p> The globbing pattern is specified by the {@link + * FileSystem#getPathMatcher getPathMatcher} method. + * + * <p> The directory stream's {@code close} method should be invoked after + * iteration is completed so as to free any resources held for the open + * directory. + * + * <p> When an implementation supports operations on entries in the + * directory that execute in a race-free manner then the returned directory + * stream is a {@link SecureDirectoryStream}. + * + * @param glob + * the glob pattern + * + * @return a new and open {@code DirectoryStream} object + * + * @throws java.util.regex.PatternSyntaxException + * if the pattern is invalid + * @throws UnsupportedOperationException + * if the pattern syntax is not known to the implementation + * @throws NotDirectoryException + * if the file could not otherwise be opened because it is not + * a directory <i>(optional specific exception)</i> + * @throws IOException + * if an I/O error occurs + * @throws SecurityException + * In the case of the default provider, and a security manager is + * installed, the {@link SecurityManager#checkRead(String) checkRead} + * method is invoked to check read access to the directory. + */ + public abstract DirectoryStream<Path> newDirectoryStream(String glob) + throws IOException; + + /** + * Opens the directory referenced by this object, returning a {@code + * DirectoryStream} to iterate over the entries in the directory. The + * elements returned by the directory stream's {@link DirectoryStream#iterator + * iterator} are of type {@code Path}, each one representing an entry in the + * directory. The {@code Path} objects are obtained as if by {@link + * #resolve(Path) resolving} the name of the directory entry against this + * path. The entries returned by the iterator are filtered by the given + * {@link DirectoryStream.Filter filter}. The {@link DirectoryStreamFilters} + * class defines factory methods that create useful filters. + * + * <p> The directory stream's {@code close} method should be invoked after + * iteration is completed so as to free any resources held for the open + * directory. The {@link Files#withDirectory Files.withDirectory} utility + * method is useful for cases where a task is performed on each accepted + * entry in a directory. This method closes the directory when iteration is + * complete (or an error occurs). + * + * <p> Where the filter terminates due to an uncaught error or runtime + * exception then it propogated to the caller of the iterator's {@link + * Iterator#hasNext() hasNext} or {@link Iterator#next() next} methods. + * + * <p> When an implementation supports operations on entries in the + * directory that execute in a race-free manner then the returned directory + * stream is a {@link SecureDirectoryStream}. + * + * <p> <b>Usage Example:</b> + * Suppose we want to iterate over the files in a directory that are + * larger than 8K. + * <pre> + * DirectoryStream.Filter<Path> filter = new DirectoryStream.Filter<Path>() { + * public boolean accept(Path file) { + * try { + * long size = Attributes.readBasicFileAttributes(file).size(); + * return (size > 8192L); + * } catch (IOException e) { + * // failed to get size + * return false; + * } + * } + * }; + * Path dir = ... + * DirectoryStream<Path> stream = dir.newDirectoryStream(filter); + * </pre> + * @param filter + * the directory stream filter + * + * @return a new and open {@code DirectoryStream} object + * + * @throws NotDirectoryException + * if the file could not otherwise be opened because it is not + * a directory <i>(optional specific exception)</i> + * @throws IOException + * if an I/O error occurs + * @throws SecurityException + * In the case of the default provider, and a security manager is + * installed, the {@link SecurityManager#checkRead(String) checkRead} + * method is invoked to check read access to the directory. + */ + public abstract DirectoryStream<Path> newDirectoryStream(DirectoryStream.Filter<? super Path> filter) + throws IOException; + + /** + * Creates a new and empty file, failing if the file already exists. + * + * <p> This {@code Path} locates the file to create. The check for the + * existence of the file and the creation of the new file if it does not + * exist are a single operation that is atomic with respect to all other + * filesystem activities that might affect the directory. + * + * <p> The {@code attrs} parameter is an optional array of {@link FileAttribute + * file-attributes} to set atomically when creating the file. Each attribute + * is identified by its {@link FileAttribute#name name}. If more than one + * attribute of the same name is included in the array then all but the last + * occurrence is ignored. + * + * @param attrs + * an optional list of file attributes to set atomically when + * creating the file + * + * @return this path + * + * @throws UnsupportedOperationException + * if the array contains an attribute that cannot be set atomically + * when creating the file + * @throws FileAlreadyExistsException + * if a file of that name already exists + * <i>(optional specific exception)</i> + * @throws IOException + * if an I/O error occurs + * @throws SecurityException + * In the case of the default provider, and a security manager is + * installed, the {@link SecurityManager#checkWrite(String) checkWrite} + * method is invoked to check write access to the new file. + */ + public abstract Path createFile(FileAttribute<?>... attrs) throws IOException; + + /** + * Creates a new directory. + * + * <p> This {@code Path} locates the directory to create. The check for the + * existence of the file and the creation of the directory if it does not + * exist are a single operation that is atomic with respect to all other + * filesystem activities that might affect the directory. + * + * <p> The {@code attrs} parameter is an optional array of {@link FileAttribute + * file-attributes} to set atomically when creating the directory. Each + * file attribute is identified by its {@link FileAttribute#name name}. If + * more than one attribute of the same name is included in the array then all + * but the last occurrence is ignored. + * + * @param attrs + * an optional list of file attributes to set atomically when + * creating the directory + * + * @return this path + * + * @throws UnsupportedOperationException + * if the array contains an attribute that cannot be set atomically + * when creating the directory + * @throws FileAlreadyExistsException + * if a directory could not otherwise be created because a file of + * that name already exists <i>(optional specific exception)</i> + * @throws IOException + * if an I/O error occurs + * @throws SecurityException + * In the case of the default provider, and a security manager is + * installed, the {@link SecurityManager#checkWrite(String) checkWrite} + * method is invoked to check write access to the new directory. + */ + public abstract Path createDirectory(FileAttribute<?>... attrs) + throws IOException; + + /** + * Opens or creates a file, returning a seekable byte channel to access the + * file. + * + * <p> The {@code options} parameter determines how the file is opened. + * The {@link StandardOpenOption#READ READ} and {@link StandardOpenOption#WRITE WRITE} + * options determine if the file should be opened for reading and/or writing. + * If neither option (or the {@link StandardOpenOption#APPEND APPEND} + * option) is contained in the array then the file is opened for reading. + * By default reading or writing commences at the beginning of the file. + * + * <p> In the addition to {@code READ} and {@code WRITE}, the following + * options may be present: + * + * <table border=1 cellpadding=5 summary=""> + * <tr> <th>Option</th> <th>Description</th> </tr> + * <tr> + * <td> {@link StandardOpenOption#APPEND APPEND} </td> + * <td> If this option is present then the file is opened for writing and + * each invocation of the channel's {@code write} method first advances + * the position to the end of the file and then writes the requested + * data. Whether the advancement of the position and the writing of the + * data are done in a single atomic operation is system-dependent and + * therefore unspecified. This option may not be used in conjunction + * with the {@code READ} or {@code TRUNCATE_EXISTING} options. </td> + * </tr> + * <tr> + * <td> {@link StandardOpenOption#TRUNCATE_EXISTING TRUNCATE_EXISTING} </td> + * <td> If this option is present then the existing file is truncated to + * a size of 0 bytes. This option is ignored when the file is opened only + * for reading. </td> + * </tr> + * <tr> + * <td> {@link StandardOpenOption#CREATE_NEW CREATE_NEW} </td> + * <td> If this option is present then a new file is created, failing if + * the file already exists or is a symbolic link. When creating a file the + * check for the existence of the file and the creation of the file if it + * does not exist is atomic with respect to other file system operations. + * This option is ignored when the file is opened only for reading. </td> + * </tr> + * <tr> + * <td > {@link StandardOpenOption#CREATE CREATE} </td> + * <td> If this option is present then an existing file is opened if it + * exists, otherwise a new file is created. This option is ignored if the + * {@code CREATE_NEW} option is also present or the file is opened only + * for reading. </td> + * </tr> + * <tr> + * <td > {@link StandardOpenOption#DELETE_ON_CLOSE DELETE_ON_CLOSE} </td> + * <td> When this option is present then the implementation makes a + * <em>best effort</em> attempt to delete the file when closed by the + * {@link SeekableByteChannel#close close} method. If the {@code close} + * method is not invoked then a <em>best effort</em> attempt is made to + * delete the file when the Java virtual machine terminates. </td> + * </tr> + * <tr> + * <td>{@link StandardOpenOption#SPARSE SPARSE} </td> + * <td> When creating a new file this option is a <em>hint</em> that the + * new file will be sparse. This option is ignored when not creating + * a new file. </td> + * </tr> + * <tr> + * <td> {@link StandardOpenOption#SYNC SYNC} </td> + * <td> Requires that every update to the file's content or metadata be + * written synchronously to the underlying storage device. (see <a + * href="package-summary.html#integrity"> Synchronized I/O file + * integrity</a>). </td> + * <tr> + * <tr> + * <td> {@link StandardOpenOption#DSYNC DSYNC} </td> + * <td> Requires that every update to the file's content be written + * synchronously to the underlying storage device. (see <a + * href="package-summary.html#integrity"> Synchronized I/O file + * integrity</a>). </td> + * </tr> + * </table> + * + * <p> An implementation may also support additional implementation specific + * options. + * + * <p> The {@code attrs} parameter is an optional array of file {@link + * FileAttribute file-attributes} to set atomically when a new file is created. + * + * <p> In the case of the default provider, the returned seekable byte channel + * is a {@link FileChannel}. + * + * <p> <b>Usage Examples:</b> + * <pre> + * Path file = ... + * + * // open file for reading + * ReadableByteChannel rbc = file.newByteChannel(EnumSet.of(READ))); + * + * // open file for writing to the end of an existing file, creating + * // the file if it doesn't already exist + * WritableByteChannel wbc = file.newByteChannel(EnumSet.of(CREATE,APPEND)); + * + * // create file with initial permissions, opening it for both reading and writing + * FileAttribute<Set<PosixFilePermission>> perms = ... + * SeekableByteChannel sbc = file.newByteChannel(EnumSet.of(CREATE_NEW,READ,WRITE), perms); + * </pre> + * + * @param options + * Options specifying how the file is opened + * @param attrs + * An optional list of file attributes to set atomically when + * creating the file + * + * @return a new seekable byte channel + * + * @throws IllegalArgumentException + * if the set contains an invalid combination of options + * @throws UnsupportedOperationException + * if an unsupported open option is specified or the array contains + * attributes that cannot be set atomically when creating the file + * @throws FileAlreadyExistsException + * if a file of that name already exists and the {@link + * StandardOpenOption#CREATE_NEW CREATE_NEW} option is specified + * <i>(optional specific exception)</i> + * @throws IOException + * if an I/O error occurs + * @throws SecurityException + * In the case of the default provider, and a security manager is + * installed, the {@link SecurityManager#checkRead(String) checkRead} + * method is invoked to check read access to the path if the file is + * opened for reading. The {@link SecurityManager#checkWrite(String) + * checkWrite} method is invoked to check write access to the path + * if the file is opened for writing. + */ + public abstract SeekableByteChannel newByteChannel(Set<? extends OpenOption> options, + FileAttribute<?>... attrs) + throws IOException; + + /** + * Opens or creates a file, returning a seekable byte channel to access the + * file. + * + * <p> This method extends the options defined by the {@code FileRef} + * interface and to the options specified by the {@link + * #newByteChannel(Set,FileAttribute[]) newByteChannel} method + * except that the options are specified by an array. In the case of the + * default provider, the returned seekable byte channel is a {@link + * FileChannel}. + * + * @param options + * options specifying how the file is opened + * + * @return a new seekable byte channel + * + * @throws IllegalArgumentException + * if the set contains an invalid combination of options + * @throws UnsupportedOperationException + * if an unsupported open option is specified + * @throws FileAlreadyExistsException + * if a file of that name already exists and the {@link + * StandardOpenOption#CREATE_NEW CREATE_NEW} option is specified + * <i>(optional specific exception)</i> + * @throws IOException {@inheritDoc} + * @throws SecurityException {@inheritDoc} + */ + @Override + public abstract SeekableByteChannel newByteChannel(OpenOption... options) + throws IOException; + + /** + * Opens the file located by this path for reading, returning an input + * stream to read bytes from the file. The stream will not be buffered, and + * is not required to support the {@link InputStream#mark mark} or {@link + * InputStream#reset reset} methods. The stream will be safe for access by + * multiple concurrent threads. Reading commences at the beginning of the file. + * + * @return an input stream to read bytes from the file + * + * @throws IOException + * if an I/O error occurs + * @throws SecurityException + * In the case of the default provider, and a security manager is + * installed, the {@link SecurityManager#checkRead(String) checkRead} + * method is invoked to check read access to the file. + */ + public abstract InputStream newInputStream() throws IOException; + + /** + * Opens or creates the file located by this path for writing, returning an + * output stream to write bytes to the file. + * + * <p> This method opens or creates a file in exactly the manner specified + * by the {@link Path#newByteChannel(Set,FileAttribute[]) newByteChannel} + * method except that the {@link StandardOpenOption#READ READ} option may not + * be present in the array of open options. If no open options are present + * then this method creates a new file for writing or truncates an existing + * file. + * + * <p> The resulting stream will not be buffered. The stream will be safe + * for access by multiple concurrent threads. + * + * <p> <b>Usage Example:</b> + * Suppose we wish to open a log file for writing so that we append to the + * file if it already exists, or create it when it doesn't exist. + * <pre> + * Path logfile = ... + * OutputStream out = new BufferedOutputStream(logfile.newOutputStream(CREATE, APPEND)); + * </pre> + * + * @param options + * options specifying how the file is opened + * + * @return a new seekable byte channel + * + * @throws IllegalArgumentException + * if {@code options} contains an invalid combination of options + * @throws UnsupportedOperationException + * if an unsupported open option is specified + * @throws IOException + * if an I/O error occurs + * @throws SecurityException + * In the case of the default provider, and a security manager is + * installed, the {@link SecurityManager#checkWrite(String) checkWrite} + * method is invoked to check write access to the file. + */ + public abstract OutputStream newOutputStream(OpenOption... options) + throws IOException; + + /** + * Opens or creates the file located by this path for writing, returning an + * output stream to write bytes to the file. + * + * <p> This method opens or creates a file in exactly the manner specified + * by the {@link Path#newByteChannel(Set,FileAttribute[]) newByteChannel} + * method except that {@code options} parameter may not contain the {@link + * StandardOpenOption#READ READ} option. If no open options are present + * then this method creates a new file for writing or truncates an existing + * file. + * + * <p> The resulting stream will not be buffered. The stream will be safe + * for access by multiple concurrent threads. + * + * @param options + * options specifying how the file is opened + * @param attrs + * an optional list of file attributes to set atomically when + * creating the file + * + * @return a new output stream + * + * @throws IllegalArgumentException + * if the set contains an invalid combination of options + * @throws UnsupportedOperationException + * if an unsupported open option is specified or the array contains + * attributes that cannot be set atomically when creating the file + * @throws IOException + * if an I/O error occurs + * @throws SecurityException + * In the case of the default provider, and a security manager is + * installed, the {@link SecurityManager#checkWrite(String) checkWrite} + * method is invoked to check write access to the file. + */ + public abstract OutputStream newOutputStream(Set<? extends OpenOption> options, + FileAttribute<?>... attrs) + throws IOException; + + /** + * Tells whether or not the file located by this object is considered + * <em>hidden</em>. The exact definition of hidden is platform or provider + * dependent. On UNIX for example a file is considered to be hidden if its + * name begins with a period character ('.'). On Windows a file is + * considered hidden if it isn't a directory and the DOS {@link + * DosFileAttributes#isHidden hidden} attribute is set. + * + * <p> Depending on the implementation this method may require to access + * the file system to determine if the file is considered hidden. + * + * @return {@code true} if the file is considered hidden + * + * @throws IOException + * if an I/O error occurs + * @throws SecurityException + * In the case of the default provider, and a security manager is + * installed, the {@link SecurityManager#checkRead(String) checkRead} + * method is invoked to check read access to the file. + */ + public abstract boolean isHidden() throws IOException; + + /** + * Tests whether the file located by this path exists. + * + * <p> This convenience method is intended for cases where it is required to + * take action when it can be confirmed that a file exists. This method simply + * invokes the {@link #checkAccess checkAccess} method to check if the file + * exists. If the {@code checkAccess} method succeeds then this method returns + * {@code true}, otherwise if an {@code IOException} is thrown (because the + * file doesn't exist or cannot be accessed by this Java virtual machine) + * then {@code false} is returned. + * + * <p> Note that the result of this method is immediately outdated. If this + * method indicates the file exists then there is no guarantee that a + * subsequence access will succeed. Care should be taken when using this + * method in security sensitive applications. + * + * @return {@code true} if the file exists; {@code false} if the file does + * not exist or its existence cannot be determined. + * + * @throws SecurityException + * In the case of the default provider, the {@link + * SecurityManager#checkRead(String)} is invoked to check + * read access to the file. + * + * @see #notExists + */ + public abstract boolean exists(); + + /** + * Tests whether the file located by this path does not exist. + * + * <p> This convenience method is intended for cases where it is required to + * take action when it can be confirmed that a file does not exist. This + * method invokes the {@link #checkAccess checkAccess} method to check if the + * file exists. If the file does not exist then {@code true} is returned, + * otherwise the file exists or cannot be accessed by this Java virtual + * machine and {@code false} is returned. + * + * <p> Note that this method is not the complement of the {@link #exists + * exists} method. Where it is not possible to determine if a file exists + * or not then both methods return {@code false}. As with the {@code exists} + * method, the result of this method is immediately outdated. If this + * method indicates the file does exist then there is no guarantee that a + * subsequence attempt to create the file will succeed. Care should be taken + * when using this method in security sensitive applications. + * + * @return {@code true} if the file does not exist; {@code false} if the + * file exists or its existence cannot be determined. + * + * @throws SecurityException + * In the case of the default provider, the {@link + * SecurityManager#checkRead(String)} is invoked to check + * read access to the file. + */ + public abstract boolean notExists(); + + // -- watchable -- + + /** + * Registers the file located by this path with a watch service. + * + * <p> In this release, this path locates a directory that exists. The + * directory is registered with the watch service so that entries in the + * directory can be watched. The {@code events} parameter is an array of + * events to register and may contain the following events: + * <ul> + * <li>{@link StandardWatchEventKind#ENTRY_CREATE ENTRY_CREATE} - + * entry created or moved into the directory</li> + * <li>{@link StandardWatchEventKind#ENTRY_DELETE ENTRY_DELETE} - + * entry deleted or moved out of the directory</li> + * <li>{@link StandardWatchEventKind#ENTRY_MODIFY ENTRY_MODIFY} - + * entry in directory was modified</li> + * </ul> + * + * <p> The {@link WatchEvent#context context} for these events is the + * relative path between the directory located by this path, and the path + * that locates the directory entry that is created, deleted, or modified. + * + * <p> The set of events may include additional implementation specific + * event that are not defined by the enum {@link StandardWatchEventKind} + * + * <p> The {@code modifiers} parameter is an array of <em>modifiers</em> + * that qualify how the directory is registered. This release does not + * define any <em>standard</em> modifiers. The array may contain + * implementation specific modifiers. + * + * <p> Where a file is registered with a watch service by means of a symbolic + * link then it is implementation specific if the watch continues to depend + * on the existence of the link after it is registered. + * + * @param watcher + * the watch service to which this object is to be registered + * @param events + * the events for which this object should be registered + * @param modifiers + * the modifiers, if any, that modify how the object is registered + * + * @return a key representing the registration of this object with the + * given watch service + * + * @throws UnsupportedOperationException + * if unsupported events or modifiers are specified + * @throws IllegalArgumentException + * if an invalid combination of events or modifiers is specified + * @throws ClosedWatchServiceException + * if the watch service is closed + * @throws NotDirectoryException + * if the file is registered to watch the entries in a directory + * and the file is not a directory <i>(optional specific exception)</i> + * @throws IOException + * if an I/O error occurs + * @throws SecurityException + * In the case of the default provider, and a security manager is + * installed, the {@link SecurityManager#checkRead(String) checkRead} + * method is invoked to check read access to the file. + */ + @Override + public abstract WatchKey register(WatchService watcher, + WatchEvent.Kind<?>[] events, + WatchEvent.Modifier... modifiers) + throws IOException; + + /** + * Registers the file located by this path with a watch service. + * + * <p> An invocation of this method behaves in exactly the same way as the + * invocation + * <pre> + * watchable.{@link #register(WatchService,WatchEvent.Kind[],WatchEvent.Modifier[]) register}(watcher, events, new WatchEvent.Modifier[0]); + * </pre> + * + * <p> <b>Usage Example:</b> + * Suppose we wish to register a directory for entry create, delete, and modify + * events: + * <pre> + * Path dir = ... + * WatchService watcher = ... + * + * WatchKey key = dir.register(watcher, ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY); + * </pre> + * @param watcher + * The watch service to which this object is to be registered + * @param events + * The events for which this object should be registered + * + * @return A key representing the registration of this object with the + * given watch service + * + * @throws UnsupportedOperationException + * If unsupported events are specified + * @throws IllegalArgumentException + * If an invalid combination of events is specified + * @throws ClosedWatchServiceException + * If the watch service is closed + * @throws NotDirectoryException + * If the file is registered to watch the entries in a directory + * and the file is not a directory <i>(optional specific exception)</i> + * @throws IOException + * If an I/O error occurs + * @throws SecurityException + * In the case of the default provider, and a security manager is + * installed, the {@link SecurityManager#checkRead(String) checkRead} + * method is invoked to check read access to the file. + */ + @Override + public abstract WatchKey register(WatchService watcher, + WatchEvent.Kind<?>... events) + throws IOException; + + // -- Iterable -- + + /** + * Returns an iterator over the name elements of this path. + * + * <p> The first element returned by the iterator represents the name + * element that is closest to the root in the directory hierarchy, the + * second element is the next closest, and so on. The last element returned + * is the name of the file or directory denoted by this path. The {@link + * #getRoot root} component, if present, is not returned by the iterator. + * + * @return an iterator over the name elements of this path. + */ + @Override + public abstract Iterator<Path> iterator(); + + // -- compareTo/equals/hashCode -- + + /** + * Compares two abstract paths lexicographically. The ordering defined by + * this method is provider specific, and in the case of the default + * provider, platform specific. This method does not access the file system + * and neither file is required to exist. + * + * @param other the path compared to this path. + * + * @return zero if the argument is {@link #equals equal} to this path, a + * value less than zero if this path is lexicographically less than + * the argument, or a value greater than zero if this path is + * lexicographically greater than the argument + */ + @Override + public abstract int compareTo(Path other); + + /** + * Tests this path for equality with the given object. + * + * <p> If the given object is not a Path, or is a Path associated with a + * different provider, then this method immediately returns {@code false}. + * + * <p> Whether or not two path are equal depends on the file system + * implementation. In some cases the paths are compared without regard + * to case, and others are case sensitive. This method does not access the + * file system and the file is not required to exist. + * + * <p> This method satisfies the general contract of the {@link + * java.lang.Object#equals(Object) Object.equals} method. </p> + * + * @param other + * the object to which this object is to be compared + * + * @return {@code true} if, and only if, the given object is a {@code Path} + * that is identical to this {@code Path} + */ + @Override + public abstract boolean equals(Object other); + + /** + * Computes a hash code for this path. + * + * <p> The hash code is based upon the components of the path, and + * satisfies the general contract of the {@link Object#hashCode + * Object.hashCode} method. + * + * @return the hash-code value for this path + */ + @Override + public abstract int hashCode(); + + /** + * Returns the string representation of this path. + * + * <p> If this path was created by converting a path string using the + * {@link FileSystem#getPath getPath} method then the path string returned + * by this method may differ from the original String used to create the path. + * + * <p> The returned path string uses the default name {@link + * FileSystem#getSeparator separator} to separate names in the path. + * + * @return the string representation of this path + */ + @Override + public abstract String toString(); +} diff --git a/src/share/classes/java/nio/file/PathMatcher.java b/src/share/classes/java/nio/file/PathMatcher.java new file mode 100644 index 0000000000000000000000000000000000000000..5a1cfee88e6297f5f56738300290750933e7a1e1 --- /dev/null +++ b/src/share/classes/java/nio/file/PathMatcher.java @@ -0,0 +1,49 @@ +/* + * Copyright 2007-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 java.nio.file; + +/** + * An interface that is implemented by objects that perform match operations on + * paths. + * + * @since 1.7 + * + * @see FileSystem#getPathMatcher + * @see Path#newDirectoryStream(String) + */ + +public interface PathMatcher { + /** + * Tells if given path matches this matcher's pattern. + * + * @param path + * the path to match + * + * @return {@code true} if, and only if, the path matches this + * matcher's pattern + */ + boolean matches(Path path); +} diff --git a/src/share/classes/java/nio/file/Paths.java b/src/share/classes/java/nio/file/Paths.java new file mode 100644 index 0000000000000000000000000000000000000000..2cd7a091213208a3c6f670aa89797f47d5a6bb61 --- /dev/null +++ b/src/share/classes/java/nio/file/Paths.java @@ -0,0 +1,133 @@ +/* + * Copyright 2007-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 java.nio.file; + +import java.nio.file.spi.FileSystemProvider; +import java.net.URI; + +/** + * This class consists exclusively of static methods that return a {@link Path} + * by converting a path string or {@link URI}. + * + * @since 1.7 + */ + +public class Paths { + private Paths() { } + + /** + * Constructs a {@code Path} by converting the given path string. + * + * <p> The {@code Path} is obtained by invoking the {@link FileSystem#getPath + * getPath} method of the {@link FileSystems#getDefault default} {@link + * FileSystem}. + * + * <p> Note that while this method is very convenient, using it will + * imply an assumed reference to the default FileSystem and limit the + * utility of the calling code. Hence it should not be used in library code + * intended for flexible reuse. A more flexible alternative is to use an + * existing {@code Path} instance as an anchor, such as: + * <pre> + * Path dir = ... + * Path path = dir.resolve("file"); + * </pre> + * + * @param path + * the path string to convert + * + * @return the resulting {@code Path} + * + * @throws InvalidPathException + * if the path string cannot be converted to a {@code Path} + * + * @see FileSystem#getPath + */ + public static Path get(String path) { + return FileSystems.getDefault().getPath(path); + } + + /** + * Converts the given URI to a {@link Path} object. + * + * <p> This method iterates over the {@link FileSystemProvider#installedProviders() + * installed} providers to locate the provider that is identified by the + * URI {@link URI#getScheme scheme} of the given URI. URI schemes are + * compared without regard to case. If the provider is found then its {@link + * FileSystemProvider#getPath getPath} method is invoked to convert the + * URI. + * + * <p> In the case of the default provider, identified by the URI scheme + * "file", the given URI has a non-empty path component, and undefined query + * and fragment components. Whether the authority component may be present + * is platform specific. The returned {@code Path} is associated with the + * {@link FileSystems#getDefault default} file system. + * + * <p> The default provider provides a similar <em>round-trip</em> guarantee + * to the {@link java.io.File} class. For a given {@code Path} <i>p</i> it + * is guaranteed that + * <blockquote><tt> + * Paths.get(</tt><i>p</i><tt>.{@link Path#toUri() toUri}()).equals(</tt> + * <i>p</i><tt>.{@link Path#toAbsolutePath() toAbsolutePath}())</tt> + * </blockquote> + * so long as the original {@code Path}, the {@code URI}, and the new {@code + * Path} are all created in (possibly different invocations of) the same + * Java virtual machine. Whether other providers make any guarantees is + * provider specific and therefore unspecified. + * + * @param uri + * the URI to convert + * + * @return the resulting {@code Path} + * + * @throws IllegalArgumentException + * if preconditions on the {@code uri} parameter do not hold. The + * format of the URI is provider specific. + * @throws FileSystemNotFoundException + * if the file system identified by the URI does not exist or the + * provider identified by the URI's scheme component is not installed + * @throws SecurityException + * if a security manager is installed and it denies an unspecified + * permission to access the file system + */ + public static Path get(URI uri) { + String scheme = uri.getScheme(); + if (scheme == null) + throw new IllegalArgumentException("Missing scheme"); + + // check for default provider to avoid loading of installed providers + if (scheme.equalsIgnoreCase("file")) + return FileSystems.getDefault().provider().getPath(uri); + + // try to find provider + for (FileSystemProvider provider: FileSystemProvider.installedProviders()) { + if (provider.getScheme().equalsIgnoreCase(scheme)) { + return provider.getPath(uri); + } + } + + throw new FileSystemNotFoundException("Provider \"" + scheme + "\" not installed"); + } +} diff --git a/src/share/classes/java/nio/file/ProviderMismatchException.java b/src/share/classes/java/nio/file/ProviderMismatchException.java new file mode 100644 index 0000000000000000000000000000000000000000..7c1bbc0976295105d2c927dcd613f43ffc730c00 --- /dev/null +++ b/src/share/classes/java/nio/file/ProviderMismatchException.java @@ -0,0 +1,53 @@ +/* + * Copyright 2007-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 java.nio.file; + +/** + * Unchecked exception thrown when an attempt is made to invoke a method on an + * object created by one file system provider with a parameter created by a + * different file system provider. + */ +public class ProviderMismatchException + extends java.lang.IllegalArgumentException +{ + static final long serialVersionUID = 4990847485741612530L; + + /** + * Constructs an instance of this class. + */ + public ProviderMismatchException() { + } + + /** + * Constructs an instance of this class. + * + * @param msg + * the detail message + */ + public ProviderMismatchException(String msg) { + super(msg); + } +} diff --git a/src/share/classes/java/nio/file/ProviderNotFoundException.java b/src/share/classes/java/nio/file/ProviderNotFoundException.java new file mode 100644 index 0000000000000000000000000000000000000000..dd1fee82dababda80bae7c4cd4b7ab95a58c1847 --- /dev/null +++ b/src/share/classes/java/nio/file/ProviderNotFoundException.java @@ -0,0 +1,52 @@ +/* + * Copyright 2007-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 java.nio.file; + +/** + * Runtime exception thrown when a provider of the required type cannot be found. + */ + +public class ProviderNotFoundException + extends RuntimeException +{ + static final long serialVersionUID = -1880012509822920354L; + + /** + * Constructs an instance of this class. + */ + public ProviderNotFoundException() { + } + + /** + * Constructs an instance of this class. + * + * @param msg + * the detail message + */ + public ProviderNotFoundException(String msg) { + super(msg); + } +} diff --git a/src/share/classes/java/nio/file/ReadOnlyFileSystemException.java b/src/share/classes/java/nio/file/ReadOnlyFileSystemException.java new file mode 100644 index 0000000000000000000000000000000000000000..4e92efba089ca88eb23a0067f56800194b7c255d --- /dev/null +++ b/src/share/classes/java/nio/file/ReadOnlyFileSystemException.java @@ -0,0 +1,43 @@ +/* + * Copyright 2007-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 java.nio.file; + +/** + * Unchecked exception thrown when an attempt is made to update an object + * associated with a {@link FileSystem#isReadOnly() read-only} {@code FileSystem}. + */ + +public class ReadOnlyFileSystemException + extends UnsupportedOperationException +{ + static final long serialVersionUID = -6822409595617487197L; + + /** + * Constructs an instance of this class. + */ + public ReadOnlyFileSystemException() { + } +} diff --git a/src/share/classes/java/nio/file/SecureDirectoryStream.java b/src/share/classes/java/nio/file/SecureDirectoryStream.java new file mode 100644 index 0000000000000000000000000000000000000000..b2555c14185774a154dd292b8ac213e892313fd6 --- /dev/null +++ b/src/share/classes/java/nio/file/SecureDirectoryStream.java @@ -0,0 +1,324 @@ +/* + * Copyright 2007-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 java.nio.file; + +import java.nio.file.attribute.*; +import java.nio.channels.SeekableByteChannel; +import java.util.Set; +import java.io.IOException; + +/** + * A {@code DirectoryStream} that defines operations on files that are located + * relative to an open directory. A {@code SecureDirectoryStream} is intended + * for use by sophisticated or security sensitive applications requiring to + * traverse file trees or otherwise operate on directories in a race-free manner. + * Race conditions can arise when a sequence of file operations cannot be + * carried out in isolation. Each of the file operations defined by this + * interface specify a relative {@link Path}. All access to the file is relative + * to the open directory irrespective of if the directory is moved or replaced + * by an attacker while the directory is open. A {@code SecureDirectoryStream} + * may also be used as a virtual <em>working directory</em>. + * + * <p> A {@code SecureDirectoryStream} requires corresponding support from the + * underlying operating system. Where an implementation supports this features + * then the {@code DirectoryStream} returned by the {@link Path#newDirectoryStream + * newDirectoryStream} method will be a {@code SecureDirectoryStream} and must + * be cast to that type in order to invoke the methods defined by this interface. + * + * <p> As specified by {@code DirectoryStream}, the iterator's {@link + * java.util.Iterator#remove() remove} method removes the directory entry for + * the last element returned by the iterator. In the case of a {@code + * SecureDirectoryStream} the {@code remove} method behaves as if by invoking + * the {@link #deleteFile deleteFile} or {@link #deleteDirectory deleteDirectory} + * methods defined by this interface. The {@code remove} may require to examine + * the file to determine if the file is a directory, and consequently, it may + * not be atomic with respect to other file system operations. + * + * <p> In the case of the default {@link java.nio.file.spi.FileSystemProvider + * provider}, and a security manager is set, then the permission checks are + * performed using the path obtained by resolving the given relative path + * against the <i>original path</i> of the directory (irrespective of if the + * directory is moved since it was opened). + * + * @since 1.7 + */ + +public abstract class SecureDirectoryStream + implements DirectoryStream<Path> +{ + /** + * Initialize a new instance of this class. + */ + protected SecureDirectoryStream() { } + + /** + * Opens the directory identified by the given path, returning a {@code + * SecureDirectoryStream} to iterate over the entries in the directory. + * + * <p> This method works in exactly the manner specified by the {@link + * Path#newDirectoryStream newDirectoryStream} method for the case that + * the {@code path} parameter is an {@link Path#isAbsolute absolute} path. + * When the parameter is a relative path then the directory to open is + * relative to this open directory. The {@code followLinks} parameter + * determines if links should be followed. If this parameter is {@code + * false} and the file is a symbolic link then this method fails (by + * throwing an I/O exception). + * + * <p> The new directory stream, once created, is not dependent upon the + * directory stream used to create it. Closing this directory stream has no + * effect upon newly created directory stream. + * + * @param path + * the path to the directory to open + * @param followLinks + * {@code true} if the links should be followed + * @param filter + * the directory stream filter or {@code null}. + * + * @return a new and open {@code SecureDirectoryStream} object + * + * @throws ClosedDirectoryStreamException + * if the directory stream is closed + * @throws NotDirectoryException + * if the file could not otherwise be opened because it is not + * a directory <i>(optional specific exception)</i> + * @throws IOException + * if an I/O error occurs + * @throws SecurityException + * In the case of the default provider, and a security manager is + * installed, the {@link SecurityManager#checkRead(String) checkRead} + * method is invoked to check read access to the directory. + */ + public abstract SecureDirectoryStream newDirectoryStream(Path path, + boolean followLinks, + DirectoryStream.Filter<? super Path> filter) + throws IOException; + + /** + * Opens or creates a file in this directory, returning a seekable byte + * channel to access the file. + * + * <p> This method works in exactly the manner specified by the {@link + * Path#newByteChannel Path.newByteChannel} method for the + * case that the {@code path} parameter is an {@link Path#isAbsolute absolute} + * path. When the parameter is a relative path then the file to open or + * create is relative to this open directory. In addition to the options + * defined by the {@code Path.newByteChannel} method, the {@link + * LinkOption#NOFOLLOW_LINKS NOFOLLOW_LINKS} option may be used to + * ensure that this method fails if the file is a symbolic link. + * + * <p> The channel, once created, is not dependent upon the directory stream + * used to create it. Closing this directory stream has no effect upon the + * channel. + * + * @param path + * the path of the file to open open or create + * @param options + * options specifying how the file is opened + * @param attrs + * an optional list of attributes to set atomically when creating + * the file + * + * @throws ClosedDirectoryStreamException + * if the directory stream is closed + * @throws IllegalArgumentException + * if the set contains an invalid combination of options + * @throws UnsupportedOperationException + * if an unsupported open option is specified or the array contains + * attributes that cannot be set atomically when creating the file + * @throws FileAlreadyExistsException + * if a file of that name already exists and the {@link + * StandardOpenOption#CREATE_NEW CREATE_NEW} option is specified + * <i>(optional specific exception)</i> + * @throws IOException + * if an I/O error occurs + * @throws SecurityException + * In the case of the default provider, and a security manager is + * installed, the {@link SecurityManager#checkRead(String) checkRead} + * method is invoked to check read access to the path if the file + * is opened for reading. The {@link SecurityManager#checkWrite(String) + * checkWrite} method is invoked to check write access to the path + * if the file is opened for writing. + */ + public abstract SeekableByteChannel newByteChannel(Path path, + Set<? extends OpenOption> options, + FileAttribute<?>... attrs) + throws IOException; + + /** + * Deletes a file. + * + * <p> Unlike the {@link FileRef#delete delete()} method, this method + * does not first examine the file to determine if the file is a directory. + * Whether a directory is deleted by this method is system dependent and + * therefore not specified. If the file is a symbolic-link then the link is + * deleted (not the final target of the link). When the parameter is a + * relative path then the file to delete is relative to this open directory. + * + * @param path + * the path of the file to delete + * + * @throws ClosedDirectoryStreamException + * if the directory stream is closed + * @throws NoSuchFileException + * if the file does not exist <i>(optional specific exception)</i> + * @throws IOException + * if an I/O error occurs + * @throws SecurityException + * In the case of the default provider, and a security manager is + * installed, the {@link SecurityManager#checkDelete(String) checkDelete} + * method is invoked to check delete access to the file + */ + public abstract void deleteFile(Path path) throws IOException; + + /** + * Deletes a directory. + * + * <p> Unlike the {@link FileRef#delete delete()} method, this method + * does not first examine the file to determine if the file is a directory. + * Whether non-directories are deleted by this method is system dependent and + * therefore not specified. When the parameter is a relative path then the + * directory to delete is relative to this open directory. + * + * @param path + * the path of the directory to delete + * + * @throws ClosedDirectoryStreamException + * if the directory stream is closed + * @throws NoSuchFileException + * if the the directory does not exist <i>(optional specific exception)</i> + * @throws DirectoryNotEmptyException + * if the directory could not otherwise be deleted because it is + * not empty <i>(optional specific exception)</i> + * @throws IOException + * if an I/O error occurs + * @throws SecurityException + * In the case of the default provider, and a security manager is + * installed, the {@link SecurityManager#checkDelete(String) checkDelete} + * method is invoked to check delete access to the directory + */ + public abstract void deleteDirectory(Path path) throws IOException; + + /** + * Move a file from this directory to another directory. + * + * <p> This method works in a similar manner to {@link Path#moveTo moveTo} + * method when the {@link StandardCopyOption#ATOMIC_MOVE ATOMIC_MOVE} option + * is specified. That is, this method moves a file as an atomic file system + * operation. If the {@code srcpath} parameter is an {@link Path#isAbsolute + * absolute} path then it locates the source file. If the parameter is a + * relative path then it is located relative to this open directory. If + * the {@code targetpath} parameter is absolute then it locates the target + * file (the {@code targetdir} parameter is ignored). If the parameter is + * a relative path it is located relative to the open directory identified + * by the {@code targetdir} parameter. In all cases, if the target file + * exists then it is implementation specific if it is replaced or this + * method fails. + * + * @param srcpath + * the name of the file to move + * @param targetdir + * the destination directory + * @param targetpath + * the name to give the file in the destination directory + * + * @throws ClosedDirectoryStreamException + * if this or the target directory stream is closed + * @throws FileAlreadyExistsException + * if the file already exists in the target directory and cannot + * be replaced <i>(optional specific exception)</i> + * @throws AtomicMoveNotSupportedException + * if the file cannot be moved as an atomic file system operation + * @throws IOException + * if an I/O error occurs + * @throws SecurityException + * In the case of the default provider, and a security manager is + * installed, the {@link SecurityManager#checkWrite(String) checkWrite} + * method is invoked to check write access to both the source and + * target file. + */ + public abstract void move(Path srcpath, SecureDirectoryStream targetdir, Path targetpath) + throws IOException; + + /** + * Returns a new file attribute view to access the file attributes of this + * directory. + * + * <p> The resulting file attribute view can be used to read or update the + * attributes of this (open) directory. The {@code type} parameter specifies + * the type of the attribute view and the method returns an instance of that + * type if supported. Invoking this method to obtain a {@link + * BasicFileAttributeView} always returns an instance of that class that is + * bound to this open directory. + * + * <p> The state of resulting file attribute view is intimately connected + * to this directory stream. Once the directory stream is {@link #close closed}, + * then all methods to read or update attributes will throw {@link + * ClosedDirectoryStreamException ClosedDirectoryStreamException}. + * + * @param type + * the {@code Class} object corresponding to the file attribute view + * + * @return a new file attribute view of the specified type bound to + * this directory stream, or {@code null} if the attribute view + * type is not available + */ + public abstract <V extends FileAttributeView> V getFileAttributeView(Class<V> type); + + /** + * Returns a new file attribute view to access the file attributes of a file + * in this directory. + * + * <p> The resulting file attribute view can be used to read or update the + * attributes of file in this directory. The {@code type} parameter specifies + * the type of the attribute view and the method returns an instance of that + * type if supported. Invoking this method to obtain a {@link + * BasicFileAttributeView} always returns an instance of that class that is + * bound to the file in the directory. + * + * <p> The state of resulting file attribute view is intimately connected + * to this directory stream. Once the directory stream {@link #close closed}, + * then all methods to read or update attributes will throw {@link + * ClosedDirectoryStreamException ClosedDirectoryStreamException}. The + * file is not required to exist at the time that the file attribute view + * is created but methods to read or update attributes of the file will + * fail when invoked and the file does not exist. + * + * @param path + * the path of the file + * @param type + * the {@code Class} object corresponding to the file attribute view + * @param options + * options indicating how symbolic links are handled + * + * @return a new file attribute view of the specified type bound to a + * this directory stream, or {@code null} if the attribute view + * type is not available + * + */ + public abstract <V extends FileAttributeView> V getFileAttributeView(Path path, + Class<V> type, + LinkOption... options); +} diff --git a/src/share/classes/java/nio/file/SimpleFileVisitor.java b/src/share/classes/java/nio/file/SimpleFileVisitor.java new file mode 100644 index 0000000000000000000000000000000000000000..d9557d024a42f67d5be63a05cf48e628330bdd83 --- /dev/null +++ b/src/share/classes/java/nio/file/SimpleFileVisitor.java @@ -0,0 +1,121 @@ +/* + * Copyright 2007-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 java.nio.file; + +import java.nio.file.attribute.BasicFileAttributes; +import java.io.IOException; +import java.io.IOError; + +/** + * A simple visitor of files with default behavior to visit all files and to + * re-throw I/O errors. + * + * <p> Methods in this class may be overridden subject to their general contract. + * + * @param <T> The type of reference to the files + * + * @since 1.7 + */ + +public class SimpleFileVisitor<T extends FileRef> implements FileVisitor<T> { + /** + * Initializes a new instance of this class. + */ + protected SimpleFileVisitor() { + } + + /** + * Invoked for a directory before entries in the directory are visited. + * + * <p> Unless overridden, this method returns {@link FileVisitResult#CONTINUE + * CONTINUE}. + */ + @Override + public FileVisitResult preVisitDirectory(T dir) { + return FileVisitResult.CONTINUE; + } + + /** + * Invoked for a directory that could not be opened. + * + * <p> Unless overridden, this method throws {@link IOError} with the I/O + * exception as cause. + * + * @throws IOError + * with the I/O exception thrown when the attempt to open the + * directory failed + */ + @Override + public FileVisitResult preVisitDirectoryFailed(T dir, IOException exc) { + throw new IOError(exc); + } + + /** + * Invoked for a file in a directory. + * + * <p> Unless overridden, this method returns {@link FileVisitResult#CONTINUE + * CONTINUE}. + */ + @Override + public FileVisitResult visitFile(T file, BasicFileAttributes attrs) { + return FileVisitResult.CONTINUE; + } + + /** + * Invoked for a file when its basic file attributes could not be read. + * + * <p> Unless overridden, this method throws {@link IOError} with the I/O + * exception as cause. + * + * @throws IOError + * with the I/O exception thrown when the attempt to read the file + * attributes failed + */ + @Override + public FileVisitResult visitFileFailed(T file, IOException exc) { + throw new IOError(exc); + } + + /** + * Invoked for a directory after entries in the directory, and all of their + * descendants, have been visited. + * + * <p> Unless overridden, this method returns {@link FileVisitResult#CONTINUE + * CONTINUE} if the directory iteration completes without an I/O exception; + * otherwise this method throws {@link IOError} with the I/O exception as + * cause. + * + * @throws IOError + * if iteration of the directory completed prematurely due to an + * I/O error + */ + @Override + public FileVisitResult postVisitDirectory(T dir, IOException exc) { + if (exc != null) + throw new IOError(exc); + return FileVisitResult.CONTINUE; + } +} diff --git a/src/share/classes/java/nio/file/StandardCopyOption.java b/src/share/classes/java/nio/file/StandardCopyOption.java new file mode 100644 index 0000000000000000000000000000000000000000..32572c1ef18f90cf3e009f8a9b9f500c918bb27e --- /dev/null +++ b/src/share/classes/java/nio/file/StandardCopyOption.java @@ -0,0 +1,47 @@ +/* + * Copyright 2007-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 java.nio.file; + +/** + * Defines the standard copy options. + * + * @since 1.7 + */ + +public enum StandardCopyOption implements CopyOption { + /** + * Replace an existing file if it exists. + */ + REPLACE_EXISTING, + /** + * Copy attributes to the new file. + */ + COPY_ATTRIBUTES, + /** + * Move the file as an atomic file system operation. + */ + ATOMIC_MOVE; +} diff --git a/src/share/classes/java/nio/file/StandardOpenOption.java b/src/share/classes/java/nio/file/StandardOpenOption.java new file mode 100644 index 0000000000000000000000000000000000000000..d01763c6a637646b723df1736eefc393a2f2bb54 --- /dev/null +++ b/src/share/classes/java/nio/file/StandardOpenOption.java @@ -0,0 +1,125 @@ +/* + * Copyright 2007-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 java.nio.file; + +/** + * Defines the standard open options. + * + * @since 1.7 + */ + +public enum StandardOpenOption implements OpenOption { + /** + * Open for read access. + */ + READ, + + /** + * Open for write access. + */ + WRITE, + + /** + * If the file is opened for {@link #WRITE} access then bytes will be written + * to the end of the file rather than the beginning. + * + * <p> If the file is opened for write access by other programs, then it + * is file system specific if writing to the end of the file is atomic. + */ + APPEND, + + /** + * If the file already exists and it is opened for {@link #WRITE} + * access, then its length is truncated to 0. This option is ignored + * if the file is opened only for {@link #READ} access. + */ + TRUNCATE_EXISTING, + + /** + * Create a new file if it does not exist. + * This option is ignored if the {@link #CREATE_NEW} option is also set. + * The check for the existence of the file and the creation of the file + * if it does not exist is atomic with respect to other file system + * operations. + */ + CREATE, + + /** + * Create a new file, failing if the file already exists. + * The check for the existence of the file and the creation of the file + * if it does not exist is atomic with respect to other file system + * operations. + */ + CREATE_NEW, + + /** + * Delete on close. When this option is present then the implementation + * makes a <em>best effort</em> attempt to delete the file when closed + * by the appropriate {@code close} method. If the {@code close} method is + * not invoked then a <em>best effort</em> attempt is made to delete the + * file when the Java virtual machine terminates (either normally, as + * defined by the Java Language Specification, or where possible, abnormally). + * This option is primarily intended for use with <em>work files</em> that + * are used solely by a single instance of the Java virtual machine. This + * option is not recommended for use when opening files that are open + * concurrently by other entities. Many of the details as to when and how + * the file is deleted are implementation specific and therefore not + * specified. In particular, an implementation may be unable to guarantee + * that it deletes the expected file when replaced by an attacker while the + * file is open. Consequently, security sensitive applications should take + * care when using this option. + * + * <p> For security reasons, this option may imply the {@link + * LinkOption#NOFOLLOW_LINKS} option. In other words, if the option is present + * when opening an existing file that is a symbolic link then it may fail + * (by throwing {@link java.io.IOException}). + */ + DELETE_ON_CLOSE, + + /** + * Sparse file. When used with the {@link #CREATE_NEW} option then this + * option provides a <em>hint</em> that the new file will be sparse. The + * option is ignored when the file system does not support the creation of + * sparse files. + */ + SPARSE, + + /** + * Requires that every update to the file's content or metadata be written + * synchronously to the underlying storage device. + * + * @see <a href="package-summary.html#integrity">Synchronized I/O file integrity</a> + */ + SYNC, + + /** + * Requires that every update to the file's content be written + * synchronously to the underlying storage device. + * + * @see <a href="package-summary.html#integrity">Synchronized I/O file integrity</a> + */ + DSYNC; +} diff --git a/src/share/classes/java/nio/file/StandardWatchEventKind.java b/src/share/classes/java/nio/file/StandardWatchEventKind.java new file mode 100644 index 0000000000000000000000000000000000000000..6cc937e9943e92ec5f4943c01832f8ba66daf1b1 --- /dev/null +++ b/src/share/classes/java/nio/file/StandardWatchEventKind.java @@ -0,0 +1,94 @@ +/* + * Copyright 2007-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 java.nio.file; + +/** + * Defines the <em>standard</em> event kinds. + * + * @since 1.7 + */ + +public class StandardWatchEventKind { + private StandardWatchEventKind() { } + + /** + * A special event to indicate that events may have been lost or + * discarded. + * + * <p> The {@link WatchEvent#context context} for this event is + * implementation specific and may be {@code null}. The event {@link + * WatchEvent#count count} may be greater than {@code 1}. + * + * @see WatchService + */ + public static final WatchEvent.Kind<Void> OVERFLOW = + new StdWatchEventKind<Void>("OVERFLOW", Void.class); + + /** + * Directory entry created. + * + * <p> When a directory is registered for this event then the {@link WatchKey} + * is queued when it is observed that an entry is created in the directory + * or renamed into the directory. The event {@link WatchEvent#count count} + * for this event is always {@code 1}. + */ + public static final WatchEvent.Kind<Path> ENTRY_CREATE = + new StdWatchEventKind<Path>("ENTRY_CREATE", Path.class); + + /** + * Directory entry deleted. + * + * <p> When a directory is registered for this event then the {@link WatchKey} + * is queued when it is observed that an entry is deleted or renamed out of + * the directory. The event {@link WatchEvent#count count} for this event + * is always {@code 1}. + */ + public static final WatchEvent.Kind<Path> ENTRY_DELETE = + new StdWatchEventKind<Path>("ENTRY_DELETE", Path.class); + + /** + * Directory entry modified. + * + * <p> When a directory is registered for this event then the {@link WatchKey} + * is queued when it is observed that an entry in the directory has been + * modified. The event {@link WatchEvent#count count} for this event is + * {@code 1} or greater. + */ + public static final WatchEvent.Kind<Path> ENTRY_MODIFY = + new StdWatchEventKind<Path>("ENTRY_MODIFY", Path.class); + + private static class StdWatchEventKind<T> implements WatchEvent.Kind<T> { + private final String name; + private final Class<T> type; + StdWatchEventKind(String name, Class<T> type) { + this.name = name; + this.type = type; + } + @Override public String name() { return name; } + @Override public Class<T> type() { return type; } + @Override public String toString() { return name; } + } +} diff --git a/src/share/classes/java/nio/file/WatchEvent.java b/src/share/classes/java/nio/file/WatchEvent.java new file mode 100644 index 0000000000000000000000000000000000000000..296efd44377ce659318a0f95f31696796e8def25 --- /dev/null +++ b/src/share/classes/java/nio/file/WatchEvent.java @@ -0,0 +1,116 @@ +/* + * Copyright 2007-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 java.nio.file; + +/** + * An event or a repeated event for an object that is registered with a {@link + * WatchService}. + * + * <p> An event is classified by its {@link #kind() kind} and has a {@link + * #count() count} to indicate the number of times that the event has been + * observed. This allows for efficient representation of repeated events. The + * {@link #context() context} method returns any context associated with + * the event. In the case of a repeated event then the context is the same for + * all events. + * + * <p> Watch events are immutable and safe for use by multiple concurrent + * threads. + * + * @param <T> The type of the context object associated with the event + * + * @since 1.7 + */ + +public abstract class WatchEvent<T> { + + /** + * An event kind, for the purposes of identification. + * + * @since 1.7 + * @see StandardWatchEventKind + */ + public static interface Kind<T> { + /** + * Returns the name of the event kind. + */ + String name(); + + /** + * Returns the type of the {@link WatchEvent#context context} value. + */ + Class<T> type(); + } + + /** + * Initializes a new instance of this class. + */ + protected WatchEvent() { } + + /** + * An event modifier that qualifies how a {@link Watchable} is registered + * with a {@link WatchService}. + * + * <p> This release does not define any <em>standard</em> modifiers. + * + * @since 1.7 + * @see Watchable#register + */ + public static interface Modifier { + /** + * Returns the name of the modifier. + */ + String name(); + } + + /** + * Returns the event kind. + * + * @return the event kind + */ + public abstract Kind<T> kind(); + + /** + * Returns the event count. If the event count is greater than {@code 1} + * then this is a repeated event. + * + * @return the event count + */ + public abstract int count(); + + /** + * Returns the context for the event. + * + * <p> In the case of {@link StandardWatchEventKind#ENTRY_CREATE ENTRY_CREATE}, + * {@link StandardWatchEventKind#ENTRY_DELETE ENTRY_DELETE}, and {@link + * StandardWatchEventKind#ENTRY_MODIFY ENTRY_MODIFY} events the context is + * a {@code Path} that is the {@link Path#relativize relative} path between + * the directory registered with the watch service, and the entry that is + * created, deleted, or modified. + * + * @return the event context; may be {@code null} + */ + public abstract T context(); +} diff --git a/src/share/classes/java/nio/file/WatchKey.java b/src/share/classes/java/nio/file/WatchKey.java new file mode 100644 index 0000000000000000000000000000000000000000..d065585d87df88bc0711fca144a3f283fd706170 --- /dev/null +++ b/src/share/classes/java/nio/file/WatchKey.java @@ -0,0 +1,138 @@ +/* + * Copyright 2007-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 java.nio.file; + +import java.util.List; + +/** + * A token representing the registration of a {@link Watchable watchable} object + * with a {@link WatchService}. + * + * <p> A watch key is created when a watchable object is registered with a watch + * service. The key remains {@link #isValid valid} until: + * <ol> + * <li> It is cancelled, explicitly, by invoking its {@link #cancel cancel} + * method, or</li> + * <li> Cancelled implicitly, because the object is no longer accessible, + * or </li> + * <li> By {@link WatchService#close closing} the watch service. </li> + * </ol> + * + * <p> A watch key has a state. When initially created the key is said to be + * <em>ready</em>. When an event is detected then the key is <em>signalled</em> + * and queued so that it can be retrieved by invoking the watch service's {@link + * WatchService#poll() poll} or {@link WatchService#take() take} methods. Once + * signalled, a key remains in this state until its {@link #reset reset} method + * is invoked to return the key to the ready state. Events detected while the + * key is in the signalled state are queued but do not cause the key to be + * re-queued for retrieval from the watch service. Events are retrieved by + * invoking the key's {@link #pollEvents pollEvents} method. This method + * retrieves and removes all events accumulated for the object. When initially + * created, a watch key has no pending events. Typically events are retrieved + * when the key is in the signalled state leading to the following idiom: + * + * <pre> + * for (;;) { + * // retrieve key + * WatchKey key = watcher.take(); + * + * // process events + * for (WatchEvent<?> event: key.pollEvents()) { + * : + * } + * + * // reset the key + * boolean valid = key.reset(); + * if (!valid) { + * // object no longer registered + * } + * } + * </pre> + * + * <p> Watch keys are safe for use by multiple concurrent threads. Where there + * are several threads retrieving signalled keys from a watch service then care + * should be taken to ensure that the {@code reset} method is only invoked after + * the events for the object have been processed. This ensures that one thread + * is processing the events for an object at any time. + * + * @since 1.7 + */ + +public abstract class WatchKey { + /** + * Initializes a new instance of this class. + */ + protected WatchKey() { } + + /** + * Tells whether or not this watch key is valid. + * + * <p> A watch key is valid upon creation and remains until it is cancelled, + * or its watch service is closed. + * + * @return {@code true} if, and only if, this watch key is valid + */ + public abstract boolean isValid(); + + /** + * Retrieves and removes all pending events for this watch key, returning + * a {@code List} of the events that were retrieved. + * + * <p> Note that this method does not wait if there are no events pending. + * + * @return the list of the events retrieved + */ + public abstract List<WatchEvent<?>> pollEvents(); + + /** + * Resets this watch key. + * + * <p> If this watch key has been cancelled or this watch key is already in + * the ready state then invoking this method has no effect. Otherwise + * if there are pending events for the object then this watch key is + * immediately re-queued to the watch service. If there are no pending + * events then the watch key is put into the ready state and will remain in + * that state until an event is detected or the watch key is cancelled. + * + * @return {@code true} if the watch key is valid and has been reset, and + * {@code false} if the watch key could not be reset because it is + * no longer {@link #isValid valid} + */ + public abstract boolean reset(); + + /** + * Cancels the registration with the watch service. Upon return the watch key + * will be invalid. If the watch key is enqueued, waiting to be retrieved + * from the watch service, then it will remain in the queue until it is + * removed. Pending events, if any, remain pending and may be retrieved by + * invoking the {@link #pollEvents pollEvents} method event after the key is + * cancelled. + * + * <p> If this watch key has already been cancelled then invoking this + * method has no effect. Once cancelled, a watch key remains forever invalid. + */ + public abstract void cancel(); +} diff --git a/src/share/classes/java/nio/file/WatchService.java b/src/share/classes/java/nio/file/WatchService.java new file mode 100644 index 0000000000000000000000000000000000000000..52678df79b6a1ece85de1d2914ef59af4198febb --- /dev/null +++ b/src/share/classes/java/nio/file/WatchService.java @@ -0,0 +1,178 @@ +/* + * Copyright 2007-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 java.nio.file; + +import java.io.Closeable; +import java.io.IOException; +import java.util.concurrent.TimeUnit; + +/** + * A watch service that <em>watches</em> registered objects for changes and + * events. For example a file manager may use a watch service to monitor a + * directory for changes so that it can update its display of the list of files + * when files are created or deleted. + * + * <p> A {@link Watchable} object is registered with a watch service by invoking + * its {@link Watchable#register register} method, returning a {@link WatchKey} + * to represent the registration. When an event for an object is detected the + * key is <em>signalled</em>, and if not currently signalled, it is queued to + * the watch service so that it can be retrieved by consumers that invoke the + * {@link #poll() poll} or {@link #take() take} methods to retrieve keys + * and process events. Once the events have been processed the consumer + * invokes the key's {@link WatchKey#reset reset} method to reset the key which + * allows the key to be signalled and re-queued with further events. + * + * <p> Registration with a watch service is cancelled by invoking the key's + * {@link WatchKey#cancel cancel} method. A key that is queued at the time that + * it is cancelled remains in the queue until it is retrieved. Depending on the + * object, a key may be cancelled automatically. For example, suppose a + * directory is watched and the watch service detects that it has been deleted + * or its file system is no longer accessible. When a key is cancelled in this + * manner it is signalled and queued, if not currently signalled. To ensure + * that the consumer is notified the return value from the {@code reset} + * method indicates if the key is valid. + * + * <p> A watch service is safe for use by multiple concurrent consumers. To + * ensure that only one consumer processes the events for a particular object at + * any time then care should be taken to ensure that the key's {@code reset} + * method is only invoked after its events have been processed. The {@link + * #close close} method may be invoked at any time to close the service causing + * any threads waiting to retrieve keys, to throw {@code + * ClosedWatchServiceException}. + * + * <p> File systems may report events faster than they can be retrieved or + * processed and an implementation may impose an unspecified limit on the number + * of events that it may accumulate. Where an implementation <em>knowingly</em> + * discards events then it arranges for the key's {@link WatchKey#pollEvents + * pollEvents} method to return an element with an event type of {@link + * StandardWatchEventKind#OVERFLOW OVERFLOW}. This event can be used by the + * consumer as a trigger to re-examine the state of the object. + * + * <p> When an event is reported to indicate that a file in a watched directory + * has been modified then there is no guarantee that the program (or programs) + * that have modified the file have completed. Care should be taken to coordinate + * access with other programs that may be updating the file. + * The {@link java.nio.channels.FileChannel FileChannel} class defines methods + * to lock regions of a file against access by other programs. + * + * <h4>Platform dependencies</h4> + * + * <p> The implementation that observes events from the file system is intended + * to map directly on to the native file event notification facility where + * available, or to use a primitive mechanism, such as polling, when a native + * facility is not available. Consequently, many of the details on how events + * are detected, their timeliness, and whether their ordering is preserved are + * highly implementation specific. For example, when a file in a watched + * directory is modified then it may result in a single {@link + * StandardWatchEventKind#ENTRY_MODIFY ENTRY_MODIFY} event in some + * implementations but several events in other implementations. Short-lived + * files (meaning files that are deleted very quickly after they are created) + * may not be detected by primitive implementations that periodically poll the + * file system to detect changes. + * + * <p> If a watched file is not located on a local storage device then it is + * implementation specific if changes to the file can be detected. In particular, + * it is not required that changes to files carried out on remote systems be + * detected. + * + * @since 1.7 + * + * @see FileSystem#newWatchService + */ + +public abstract class WatchService + implements Closeable +{ + /** + * Initializes a new instance of this class. + */ + protected WatchService() { } + + /** + * Closes this watch service. + * + * <p> If a thread is currently blocked in the {@link #take take} or {@link + * #poll(long,TimeUnit) poll} methods waiting for a key to be queued then + * it immediately receives a {@link ClosedWatchServiceException}. Any + * valid keys associated with this watch service are {@link WatchKey#isValid + * invalidated}. + * + * <p> After a watch service is closed, any further attempt to invoke + * operations upon it will throw {@link ClosedWatchServiceException}. + * If this watch service is already closed then invoking this method + * has no effect. + * + * @throws IOException + * if an I/O error occurs + */ + @Override + public abstract void close() throws IOException; + + /** + * Retrieves and removes the next watch key, or {@code null} if none are + * present. + * + * @return the next watch key, or {@code null} + * + * @throws ClosedWatchServiceException + * if this watch service is closed + */ + public abstract WatchKey poll(); + + /** + * Retrieves and removes the next watch key, waiting if necessary up to the + * specified wait time if none are yet present. + * + * @param timeout + * how to wait before giving up, in units of unit + * @param unit + * a {@code TimeUnit} determining how to interpret the timeout + * parameter + * + * @return the next watch key, or {@code null} + * + * @throws ClosedWatchServiceException + * if this watch service is closed, or it is closed while waiting + * for the next key + * @throws InterruptedException + * if interrupted while waiting + */ + public abstract WatchKey poll(long timeout, TimeUnit unit) + throws InterruptedException; + + /** + * Retrieves and removes next watch key, waiting if none are yet present. + * + * @return the next watch key + * + * @throws ClosedWatchServiceException + * if this watch service is closed, or it is closed while waiting + * for the next key + * @throws InterruptedException + * if interrupted while waiting + */ + public abstract WatchKey take() throws InterruptedException; +} diff --git a/src/share/classes/java/nio/file/Watchable.java b/src/share/classes/java/nio/file/Watchable.java new file mode 100644 index 0000000000000000000000000000000000000000..9bfa627f7bc6cf07ff256eeb2936dc913c17fa2e --- /dev/null +++ b/src/share/classes/java/nio/file/Watchable.java @@ -0,0 +1,127 @@ +/* + * Copyright 2007-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 java.nio.file; + +import java.io.IOException; + +/** + * An object that may be registered with a watch service so that it can be + * <em>watched</em> for changes and events. + * + * <p> This interface defines the {@link #register register} method to register + * the object with a {@link WatchService} returning a {@link WatchKey} to + * represent the registration. An object may be registered with more than one + * watch service. Registration with a watch service is cancelled by invoking the + * key's {@link WatchKey#cancel cancel} method. + * + * @since 1.7 + * + * @see Path#register + */ + +public interface Watchable { + + /** + * Registers an object with a watch service. + * + * <p> If the file system object identified by this object is currently + * registered with the watch service then the watch key, representing that + * registration, is returned after changing the event set or modifiers to + * those specified by the {@code events} and {@code modifiers} parameters. + * Changing the event set does not cause pending events for the object to be + * discarded. Objects are automatically registered for the {@link + * StandardWatchEventKind#OVERFLOW OVERFLOW} event. This event is not + * required to be present in the array of events. + * + * <p> Otherwise the file system object has not yet been registered with the + * given watch service, so it is registered and the resulting new key is + * returned. + * + * <p> Implementations of this interface should specify the events they + * support. + * + * @param watcher + * the watch service to which this object is to be registered + * @param events + * the events for which this object should be registered + * @param modifiers + * the modifiers, if any, that modify how the object is registered + * + * @return a key representing the registration of this object with the + * given watch service + * + * @throws UnsupportedOperationException + * if unsupported events or modifiers are specified + * @throws IllegalArgumentException + * if an invalid of combination of events are modifiers are specified + * @throws ClosedWatchServiceException + * if the watch service is closed + * @throws IOException + * if an I/O error occurs + * @throws SecurityException + * if a security manager is installed and it denies an unspecified + * permission required to monitor this object. Implementations of + * this interface should specify the permission checks. + */ + WatchKey register(WatchService watcher, + WatchEvent.Kind<?>[] events, + WatchEvent.Modifier... modifiers) + throws IOException; + + + /** + * Registers an object with a watch service. + * + * <p> An invocation of this method behaves in exactly the same way as the + * invocation + * <pre> + * watchable.{@link #register(WatchService,WatchEvent.Kind[],WatchEvent.Modifier[]) register}(watcher, events, new WatchEvent.Modifier[0]); + * </pre> + * + * @param watcher + * the watch service to which this object is to be registered + * @param events + * the events for which this object should be registered + * + * @return a key representing the registration of this object with the + * given watch service + * + * @throws UnsupportedOperationException + * if unsupported events are specified + * @throws IllegalArgumentException + * if an invalid of combination of events are specified + * @throws ClosedWatchServiceException + * if the watch service is closed + * @throws IOException + * if an I/O error occurs + * @throws SecurityException + * if a security manager is installed and it denies an unspecified + * permission required to monitor this object. Implementations of + * this interface should specify the permission checks. + */ + WatchKey register(WatchService watcher, WatchEvent.Kind<?>... events) + throws IOException; +} diff --git a/src/share/classes/java/nio/file/attribute/AclEntry.java b/src/share/classes/java/nio/file/attribute/AclEntry.java new file mode 100644 index 0000000000000000000000000000000000000000..817e1b0474227788f1bf95eaf2ee9b8cc9b6ba9f --- /dev/null +++ b/src/share/classes/java/nio/file/attribute/AclEntry.java @@ -0,0 +1,394 @@ +/* + * Copyright 2007-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 java.nio.file.attribute; + +import java.util.*; + +/** + * An entry in an access control list (ACL). + * + * <p> The ACL entry represented by this class is based on the ACL model + * specified in <a href="http://www.ietf.org/rfc/rfc3530.txt"><i>RFC 3530: + * Network File System (NFS) version 4 Protocol</i></a>. Each entry has four + * components as follows: + * + * <ol> + * <li><p> The {@link #type() type} component determines if the entry + * grants or denies access. </p></li> + * + * <li><p> The {@link #principal() principal} component, sometimes called the + * "who" component, is a {@link UserPrincipal} corresponding to the identity + * that the entry grants or denies access + * </p></li> + * + * <li><p> The {@link #permissions permissions} component is a set of + * {@link AclEntryPermission permissions} + * </p></li> + * + * <li><p> The {@link #flags flags} component is a set of {@link AclEntryFlag + * flags} to indicate how entries are inherited and propagated </p></li> + * </ol> + * + * <p> ACL entries are created using an associated {@link Builder} object by + * invoking its {@link Builder#build build} method. + * + * <p> ACL entries are immutable and are safe for use by multiple concurrent + * threads. + * + * @since 1.7 + */ + +public final class AclEntry { + + private final AclEntryType type; + private final UserPrincipal who; + private final Set<AclEntryPermission> perms; + private final Set<AclEntryFlag> flags; + + // cached hash code + private volatile int hash; + + // private constructor + private AclEntry(AclEntryType type, + UserPrincipal who, + Set<AclEntryPermission> perms, + Set<AclEntryFlag> flags) + { + this.type = type; + this.who = who; + this.perms = perms; + this.flags = flags; + } + + /** + * A builder of {@link AclEntry} objects. + * + * <p> A {@code Builder} object is obtained by invoking one of the {@link + * AclEntry#newBuilder newBuilder} methods defined by the {@code AclEntry} + * class. + * + * <p> Builder objects are mutable and are not safe for use by multiple + * concurrent threads without appropriate synchronization. + * + * @since 1.7 + */ + public static final class Builder { + private AclEntryType type; + private UserPrincipal who; + private Set<AclEntryPermission> perms; + private Set<AclEntryFlag> flags; + + private Builder(AclEntryType type, + UserPrincipal who, + Set<AclEntryPermission> perms, + Set<AclEntryFlag> flags) + { + assert perms != null && flags != null; + this.type = type; + this.who = who; + this.perms = perms; + this.flags = flags; + } + + /** + * Constructs an {@link AclEntry} from the components of this builder. + * The type and who components are required to have been set in order + * to construct an {@code AclEntry}. + * + * @return a new ACL entry + * + * @throws IllegalStateException + * if the type or who component have not been set + */ + public AclEntry build() { + if (type == null) + throw new IllegalStateException("Missing type component"); + if (who == null) + throw new IllegalStateException("Missing who component"); + return new AclEntry(type, who, perms, flags); + } + + /** + * Sets the type component of this builder. + * + * @return this builder + */ + public Builder setType(AclEntryType type) { + if (type == null) + throw new NullPointerException(); + this.type = type; + return this; + } + + /** + * Sets the principal component of this builder. + * + * @return this builder + */ + public Builder setPrincipal(UserPrincipal who) { + if (who == null) + throw new NullPointerException(); + this.who = who; + return this; + } + + // check set only contains elements of the given type + private static void checkSet(Set<?> set, Class<?> type) { + for (Object e: set) { + if (e == null) + throw new NullPointerException(); + type.cast(e); + } + } + + /** + * Sets the permissions component of this builder. On return, the + * permissions component of this builder is a copy of the given set. + * + * @return this builder + * + * @throws ClassCastException + * if the set contains elements that are not of type {@code + * AclEntryPermission} + */ + public Builder setPermissions(Set<AclEntryPermission> perms) { + // copy and check for erroneous elements + perms = new HashSet<AclEntryPermission>(perms); + checkSet(perms, AclEntryPermission.class); + this.perms = perms; + return this; + } + + /** + * Sets the permissions component of this builder. On return, the + * permissions component of this builder is a copy of the permissions in + * the given array. + * + * @return this builder + */ + public Builder setPermissions(AclEntryPermission... perms) { + Set<AclEntryPermission> set = + new HashSet<AclEntryPermission>(perms.length); + // copy and check for null elements + for (AclEntryPermission p: perms) { + if (p == null) + throw new NullPointerException(); + set.add(p); + } + this.perms = set; + return this; + } + + /** + * Sets the flags component of this builder. On return, the flags + * component of this builder is a copy of the given set. + * + * @return this builder + * + * @throws ClassCastException + * if the set contains elements that are not of type {@code + * AclEntryFlag} + */ + public Builder setFlags(Set<AclEntryFlag> flags) { + // copy and check for erroneous elements + flags = new HashSet<AclEntryFlag>(flags); + checkSet(flags, AclEntryFlag.class); + this.flags = flags; + return this; + } + + /** + * Sets the flags component of this builder. On return, the flags + * component of this builder is a copy of the flags in the given + * array. + * + * @return this builder + */ + public Builder setFlags(AclEntryFlag... flags) { + Set<AclEntryFlag> set = new HashSet<AclEntryFlag>(flags.length); + // copy and check for null elements + for (AclEntryFlag f: flags) { + if (f == null) + throw new NullPointerException(); + set.add(f); + } + this.flags = set; + return this; + } + } + + /** + * Constructs a new builder. The initial value of the type and who + * components is {@code null}. The initial value of the permissions and + * flags components is the empty set. + * + * @return a new builder + */ + public static Builder newBuilder() { + Set<AclEntryPermission> perms = Collections.emptySet(); + Set<AclEntryFlag> flags = Collections.emptySet(); + return new Builder(null, null, perms, flags); + } + + /** + * Constructs a new builder with the components of an existing ACL entry. + * + * @param entry + * an ACL entry + * + * @return a new builder + */ + public static Builder newBuilder(AclEntry entry) { + return new Builder(entry.type, entry.who, entry.perms, entry.flags); + } + + /** + * Returns the ACL entry type. + */ + public AclEntryType type() { + return type; + } + + /** + * Returns the principal component. + */ + public UserPrincipal principal() { + return who; + } + + /** + * Returns a copy of the permissions component. + * + * <p> The returned set is a modifiable copy of the permissions. + */ + public Set<AclEntryPermission> permissions() { + return new HashSet<AclEntryPermission>(perms); + } + + /** + * Returns a copy of the flags component. + * + * <p> The returned set is a modifiable copy of the flags. + */ + public Set<AclEntryFlag> flags() { + return new HashSet<AclEntryFlag>(flags); + } + + /** + * Compares the specified object with this ACL entry for equality. + * + * <p> If the given object is not an {@code AclEntry} then this method + * immediately returns {@code false}. + * + * <p> For two ACL entries to be considered equals requires that they are + * both the same type, their who components are equal, their permissions + * components are equal, and their flags components are equal. + * + * <p> This method satisfies the general contract of the {@link + * java.lang.Object#equals(Object) Object.equals} method. </p> + * + * @param ob the object to which this object is to be compared + * + * @return {@code true} if, and only if, the given object is an AclEntry that + * is identical to this AclEntry + */ + @Override + public boolean equals(Object ob) { + if (ob == this) + return true; + if (ob == null || !(ob instanceof AclEntry)) + return false; + AclEntry other = (AclEntry)ob; + if (this.type != other.type) + return false; + if (!this.who.equals(other.who)) + return false; + if (!this.perms.equals(other.perms)) + return false; + if (!this.flags.equals(other.flags)) + return false; + return true; + } + + private static int hash(int h, Object o) { + return h * 127 + o.hashCode(); + } + + /** + * Returns the hash-code value for this ACL entry. + * + * <p> This method satisfies the general contract of the {@link + * Object#hashCode} method. + */ + @Override + public int hashCode() { + // return cached hash if available + if (hash != 0) + return hash; + int h = type.hashCode(); + h = hash(h, who); + h = hash(h, perms); + h = hash(h, flags); + hash = h; + return hash; + } + + /** + * Returns the string representation of this ACL entry. + * + * @return the string representation of this entry + */ + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + + // who + sb.append(who.getName()); + sb.append(':'); + + // permissions + for (AclEntryPermission perm: perms) { + sb.append(perm.name()); + sb.append('/'); + } + sb.setLength(sb.length()-1); // drop final slash + sb.append(':'); + + // flags + if (!flags.isEmpty()) { + for (AclEntryFlag flag: flags) { + sb.append(flag.name()); + sb.append('/'); + } + sb.setLength(sb.length()-1); // drop final slash + sb.append(':'); + } + + // type + sb.append(type.name()); + return sb.toString(); + } +} diff --git a/src/share/classes/java/nio/file/attribute/AclEntryFlag.java b/src/share/classes/java/nio/file/attribute/AclEntryFlag.java new file mode 100644 index 0000000000000000000000000000000000000000..8cad24d19236a737609ae9be45e83f2593e577c6 --- /dev/null +++ b/src/share/classes/java/nio/file/attribute/AclEntryFlag.java @@ -0,0 +1,65 @@ +/* + * Copyright 2007-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 java.nio.file.attribute; + +/** + * Defines the flags for used by the flags component of an ACL {@link AclEntry + * entry}. + * + * <p> In this release, this class does not define flags related to {@link + * AclEntryType#AUDIT} and {@link AclEntryType#ALARM} entry types. + * + * @since 1.7 + */ + +public enum AclEntryFlag { + + /** + * Can be placed on a directory and indicates that the ACL entry should be + * added to each new non-directory file created. + */ + FILE_INHERIT, + + /** + * Can be placed on a directory and indicates that the ACL entry should be + * added to each new directory created. + */ + DIRECTORY_INHERIT, + + /** + * Can be placed on a directory to indicate that the ACL entry should not + * be placed on the newly created directory which is inheritable by + * subdirectories of the created directory. + */ + NO_PROPAGATE_INHERIT, + + /** + * Can be placed on a directory but does not apply to the directory, + * only to newly created files/directories as specified by the + * {@link #FILE_INHERIT} and {@link #DIRECTORY_INHERIT} flags. + */ + INHERIT_ONLY; +} diff --git a/src/share/classes/java/nio/file/attribute/AclEntryPermission.java b/src/share/classes/java/nio/file/attribute/AclEntryPermission.java new file mode 100644 index 0000000000000000000000000000000000000000..b88431c04c4d6634649f2c307f206095eca3038e --- /dev/null +++ b/src/share/classes/java/nio/file/attribute/AclEntryPermission.java @@ -0,0 +1,130 @@ +/* + * Copyright 2007-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 java.nio.file.attribute; + +/** + * Defines the permissions for use with the permissions component of an ACL + * {@link AclEntry entry}. + * + * @since 1.7 + */ + +public enum AclEntryPermission { + + /** + * Permission to read the data of the file. + */ + READ_DATA, + + /** + * Permission to modify the file's data. + */ + WRITE_DATA, + + /** + * Permission to append data to a file. + */ + APPEND_DATA, + + /** + * Permission to read the named attributes of a file. + * + * <p> <a href="http://www.ietf.org/rfc/rfc3530.txt">RFC 3530: Network + * File System (NFS) version 4 Protocol</a> defines <em>named attributes</em> + * as opaque files associated with a file in the file system. + */ + READ_NAMED_ATTRS, + + /** + * Permission to write the named attributes of a file. + * + * <p> <a href="http://www.ietf.org/rfc/rfc3530.txt">RFC 3530: Network + * File System (NFS) version 4 Protocol</a> defines <em>named attributes</em> + * as opaque files associated with a file in the file system. + */ + WRITE_NAMED_ATTRS, + + /** + * Permission to execute a file. + */ + EXECUTE, + + /** + * Permission to delete a file or directory within a directory. + */ + DELETE_CHILD, + + /** + * The ability to read (non-acl) file attributes. + */ + READ_ATTRIBUTES, + + /** + * The ability to write (non-acl) file attributes. + */ + WRITE_ATTRIBUTES, + + /** + * Permission to delete the file. + */ + DELETE, + + /** + * Permission to read the ACL attribute. + */ + READ_ACL, + + /** + * Permission to write the ACL attribute. + */ + WRITE_ACL, + + /** + * Permission to change the owner. + */ + WRITE_OWNER, + + /** + * Permission to access file locally at the server with synchronous reads + * and writes. + */ + SYNCHRONIZE; + + /** + * Permission to list the entries of a directory (equal to {@link #READ_DATA}) + */ + public static final AclEntryPermission LIST_DIRECTORY = READ_DATA; + + /** + * Permission to add a new file to a directory (equal to {@link #WRITE_DATA}) + */ + public static final AclEntryPermission ADD_FILE = WRITE_DATA; + + /** + * Permission to create a subdirectory to a directory (equal to {@link #APPEND_DATA}) + */ + public static final AclEntryPermission ADD_SUBDIRECTORY = APPEND_DATA; +} diff --git a/src/share/classes/java/nio/file/attribute/AclEntryType.java b/src/share/classes/java/nio/file/attribute/AclEntryType.java new file mode 100644 index 0000000000000000000000000000000000000000..c0051c0e83e63a9ab91b72258de2fcc09da610a9 --- /dev/null +++ b/src/share/classes/java/nio/file/attribute/AclEntryType.java @@ -0,0 +1,56 @@ +/* + * Copyright 2007-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 java.nio.file.attribute; + +/** + * A typesafe enumeration of the access control entry types. + * + * @since 1.7 + */ + +public enum AclEntryType { + /** + * Explicitly grants access to a file or directory. + */ + ALLOW, + + /** + * Explicitly denies access to a file or directory. + */ + DENY, + + /** + * Log, in a system dependent way, the access specified in the + * permissions component of the ACL entry. + */ + AUDIT, + + /** + * Generate an alarm, in a system dependent way, the access specified in the + * permissions component of the ACL entry. + */ + ALARM +} diff --git a/src/share/classes/java/nio/file/attribute/AclFileAttributeView.java b/src/share/classes/java/nio/file/attribute/AclFileAttributeView.java new file mode 100644 index 0000000000000000000000000000000000000000..c3d28c914a79ec7201a24edf1d7a7fdbdef04c0a --- /dev/null +++ b/src/share/classes/java/nio/file/attribute/AclFileAttributeView.java @@ -0,0 +1,211 @@ +/* + * Copyright 2007-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 java.nio.file.attribute; + +import java.nio.file.*; +import java.util.List; +import java.io.IOException; + +/** + * A file attribute view that supports reading or updating a file's Access + * Control Lists (ACL) or file owner attributes. + * + * <p> ACLs are used to specify access rights to file system objects. An ACL is + * an ordered list of {@link AclEntry access-control-entries}, each specifying a + * {@link UserPrincipal} and the level of access for that user principal. This + * file attribute view defines the {@link #getAcl() getAcl}, and {@link + * #setAcl(List) setAcl} methods to read and write ACLs based on the ACL + * model specified in <a href="http://www.ietf.org/rfc/rfc3530.txt"><i>RFC 3530: + * Network File System (NFS) version 4 Protocol</i></a>. This file attribute view + * is intended for file system implementations that support the NFSv4 ACL model + * or have a <em>well-defined</em> mapping between the NFSv4 ACL model and the ACL + * model used by the file system. The details of such mapping are implementation + * dependent and are therefore unspecified. + * + * <p> This class also extends {@code FileOwnerAttributeView} so as to define + * methods to get and set the file owner. + * + * <p> When a file system provides access to a set of {@link FileStore + * file-systems} that are not homogeneous then only some of the file systems may + * support ACLs. The {@link FileStore#supportsFileAttributeView + * supportsFileAttributeView} method can be used to test if a file system + * supports ACLs. + * + * <a name="interop"><h4>Interoperability</h4></a> + * + * RFC 3530 allows for special user identities to be used on platforms that + * support the POSIX defined access permissions. The special user identities + * are "{@code OWNER@}", "{@code GROUP@}", and "{@code EVERYONE@}". When both + * the {@code AclFileAttributeView} and the {@link PosixFileAttributeView} + * are supported then these special user identities may be included in ACL {@link + * AclEntry entries} that are read or written. The file system's {@link + * UserPrincipalLookupService} may be used to obtain a {@link UserPrincipal} + * to represent these special identities by invoking the {@link + * UserPrincipalLookupService#lookupPrincipalByName lookupPrincipalByName} + * method. + * + * <p> <b>Usage Example:</b> + * Suppose we wish to add an entry to an existing ACL to grant "joe" access: + * <pre> + * // lookup "joe" + * UserPrincipal joe = file.getFileSystem().getUserPrincipalLookupService() + * .lookupPrincipalByName("joe"); + * + * // get view + * AclFileAttributeView view = file.newFileAttributeView(AclFileAttributeView.class); + * + * // create ACE to give "joe" read access + * AclEntry entry = AclEntry.newBuilder() + * .setType(AclEntryType.ALLOW) + * .setPrincipal(joe) + * .setPermissions(AclEntryPermission.READ_DATA, AclEntryPermission.READ_ATTRIBUTES) + * .build(); + * + * // read ACL, insert ACE, re-write ACL + * List<AclEntry> acl = view.getAcl(); + * acl.add(0, entry); // insert before any DENY entries + * view.setAcl(acl); + * </pre> + * + * <h4> Dynamic Access </h4> + * <p> Where dynamic access to file attributes is required, the attributes + * supported by this attribute view are as follows: + * <blockquote> + * <table border="1" cellpadding="8"> + * <tr> + * <th> Name </th> + * <th> Type </th> + * </tr> + * <tr> + * <td> "acl" </td> + * <td> {@link List}<{@link AclEntry}> </td> + * </tr> + * <tr> + * <td> "owner" </td> + * <td> {@link UserPrincipal} </td> + * </tr> + * </table> + * </blockquote> + * + * <p> The {@link #getAttribute getAttribute} or {@link #readAttributes + * readAttributes} methods may be used to read the ACL or owner attributes as if + * by invoking the {@link #getAcl getAcl} or {@link #getOwner getOwner} methods. + * + * <p> The {@link #setAttribute setAttribute} method may be used to update the + * ACL or owner attributes as if by invoking the {@link #setAcl setAcl} or {@link + * #setOwner setOwner} methods. + * + * <h4> Setting the ACL when creating a file </h4> + * + * <p> Implementations supporting this attribute view may also support setting + * the initial ACL when creating a file or directory. The initial ACL + * may be provided to methods such as {@link Path#createFile createFile} or {@link + * Path#createDirectory createDirectory} as an {@link FileAttribute} with {@link + * FileAttribute#name name} {@code "acl:acl"} and a {@link FileAttribute#value + * value} that is the list of {@code AclEntry} objects. + * + * <p> Where an implementation supports an ACL model that differs from the NFSv4 + * defined ACL model then setting the initial ACL when creating the file must + * translate the ACL to the model supported by the file system. Methods that + * create a file should reject (by throwing {@link IOException IOException}) + * any attempt to create a file that would be less secure as a result of the + * translation. + * + * @since 1.7 + * @see Attributes#getAcl + * @see Attributes#setAcl + */ + +public interface AclFileAttributeView + extends FileOwnerAttributeView +{ + /** + * Returns the name of the attribute view. Attribute views of this type + * have the name {@code "acl"}. + */ + @Override + String name(); + + /** + * Reads the access control list. + * + * <p> When the file system uses an ACL model that differs from the NFSv4 + * defined ACL model, then this method returns an ACL that is the translation + * of the ACL to the NFSv4 ACL model. + * + * <p> The returned list is modifiable so as to facilitate changes to the + * existing ACL. The {@link #setAcl setAcl} method is used to update + * the file's ACL attribute. + * + * @return an ordered list of {@link AclEntry entries} representing the + * ACL + * + * @throws IOException + * if an I/O error occurs + * @throws SecurityException + * In the case of the default provider, a security manager is + * installed, and it denies {@link RuntimePermission}<tt>("accessUserInformation")</tt> + * or its {@link SecurityManager#checkRead(String) checkRead} method + * denies read access to the file. + */ + List<AclEntry> getAcl() throws IOException; + + /** + * Updates (replace) the access control list. + * + * <p> Where the file system supports Access Control Lists, and it uses an + * ACL model that differs from the NFSv4 defined ACL model, then this method + * must translate the ACL to the model supported by the file system. This + * method should reject (by throwing {@link IOException IOException}) any + * attempt to write an ACL that would appear to make the file more secure + * than would be the case if the ACL were updated. Where an implementation + * does not support a mapping of {@link AclEntryType#AUDIT} or {@link + * AclEntryType#ALARM} entries, then this method ignores these entries when + * writing the ACL. + * + * <p> If an ACL entry contains a {@link AclEntry#principal user-principal} + * that is not associated with the same provider as this attribute view then + * {@link ProviderMismatchException} is thrown. Additional validation, if + * any, is implementation dependent. + * + * <p> If the file system supports other security related file attributes + * (such as a file {@link PosixFileAttributes#permissions + * access-permissions} for example), the updating the access control list + * may also cause these security related attributes to be updated. + * + * @param acl + * the new access control list + * + * @throws IOException + * if an I/O error occurs or the ACL is invalid + * @throws SecurityException + * In the case of the default provider, a security manager is + * installed, it denies {@link RuntimePermission}<tt>("accessUserInformation")</tt> + * or its {@link SecurityManager#checkWrite(String) checkWrite} + * method denies write access to the file. + */ + void setAcl(List<AclEntry> acl) throws IOException; +} diff --git a/src/share/classes/java/nio/file/attribute/AttributeView.java b/src/share/classes/java/nio/file/attribute/AttributeView.java new file mode 100644 index 0000000000000000000000000000000000000000..6b0934e7af03bb29d2d191311a4aa20695953b77 --- /dev/null +++ b/src/share/classes/java/nio/file/attribute/AttributeView.java @@ -0,0 +1,118 @@ +/* + * Copyright 2007-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 java.nio.file.attribute; + +import java.util.*; +import java.io.IOException; + +/** + * An object that provides a read-only or updatable <em>view</em> of non-opaque + * values associated with an object in a filesystem. This interface is extended + * or implemented by specific attribute views that define the attributes + * supported by the view. A specific attribute view will typically define + * type-safe methods to read or update the attributes that it supports. It also + * provides <em>dynamic access</em> where the {@link #readAttributes + * readAttributes}, {@link #getAttribute getAttribute} and {@link #setAttribute + * setAttributs} methods are used to access the attributes by names defined + * by the attribute view. Implementations must ensure that the attribute names + * do not contain the colon (':') or comma (',') characters. + * + * @since 1.7 + */ + +public interface AttributeView { + /** + * Returns the name of the attribute view. + */ + String name(); + + /** + * Reads the value of an attribute. + * + * @param attribute + * the attribute name (case sensitive) + * + * @return the value of the attribute, or {@code null} if the attribute is + * not supported + * + * @throws IOException + * if an I/O error occurs + * @throws SecurityException + * if a security manager is set and it denies access + */ + Object getAttribute(String attribute) throws IOException; + + /** + * Sets/updates the value of an attribute. + * + * @param attribute + * the attribute name (case sensitive) + * @param value + * the attribute value + * + * @throws UnsupportedOperationException + * if the attribute is not supported or this attribute view does + * not support updating the value of the attribute + * @throws IllegalArgumentException + * if the attribute value is of the correct type but has an + * inappropriate value + * @throws ClassCastException + * if the attribute value is not of the expected type or is a + * collection containing elements that are not of the expected + * type + * @throws IOException + * if an I/O error occurs + * @throws SecurityException + * if a security manager is set and it denies access + */ + void setAttribute(String attribute, Object value) throws IOException; + + /** + * Reads all, or a subset, of the attributes supported by this file attribute + * view. + * + * <p> The {@code first} and {@code rest} parameters are the names of the + * attributes to read. If any of the parameters has the value {@code "*"} + * then all attributes are read. Attributes that are not supported are + * ignored and will not be present in the returned map. It is implementation + * specific if all attributes are read as an atomic operation with respect + * to other file system operations. + * + * @param first + * the name of an attribute to read (case sensitive) + * @param rest + * the names of other attributes to read (case sensitive) + * + * @return an unmodifiable map of the attributes; may be empty. Its keys are + * the attribute names, its values are the attribute values + * + * @throws IOException + * if an I/O error occurs + * @throws SecurityException + * if a security manager is set and it denies access + */ + Map<String,?> readAttributes(String first, String... rest) throws IOException; +} diff --git a/src/share/classes/java/nio/file/attribute/Attributes.java b/src/share/classes/java/nio/file/attribute/Attributes.java new file mode 100644 index 0000000000000000000000000000000000000000..b3fe130d5bac90c54917bed4ae6715161aa9e2fc --- /dev/null +++ b/src/share/classes/java/nio/file/attribute/Attributes.java @@ -0,0 +1,703 @@ +/* + * Copyright 2007-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 java.nio.file.attribute; + +import java.nio.file.*; +import java.io.IOException; +import java.util.*; +import java.util.concurrent.TimeUnit; + +/** + * This class consists exclusively of static methods that operate on or return + * the attributes of files or file stores. These methods provide for convenient + * use of the {@link AttributeView attribute-views} defined in this package. + * + * @since 1.7 + */ + +public final class Attributes { + private Attributes() { + } + + /** + * Splits the given attribute name into the name of an attribute view and + * the attribute. If the attribute view is not identified then it assumed + * to be "basic". + */ + private static String[] split(String attribute) { + String[] s = new String[2]; + int pos = attribute.indexOf(':'); + if (pos == -1) { + s[0] = "basic"; + s[1] = attribute; + } else { + s[0] = attribute.substring(0, pos++); + s[1] = (pos == attribute.length()) ? "" : attribute.substring(pos); + } + return s; + } + + /** + * Sets the value of a file attribute. + * + * <p> The {@code attribute} parameter identifies the attribute to be set + * and takes the form: + * <blockquote> + * [<i>view-name</i><b>:</b>]<i>attribute-name</i> + * </blockquote> + * where square brackets [...] delineate an optional component and the + * character {@code ':'} stands for itself. + * + * <p> <i>view-name</i> is the {@link FileAttributeView#name name} of a {@link + * FileAttributeView} that identifies a set of file attributes. If not + * specified then it defaults to {@code "basic"}, the name of the file + * attribute view that identifies the basic set of file attributes common to + * many file systems. <i>attribute-name</i> is the name of the attribute + * within the set. + * + * <p> <b>Usage Example:</b> + * Suppose we want to set the DOS "hidden" attribute: + * <pre> + * Attributes.setAttribute(file, "dos:hidden", true); + * </pre> + * + * @param file + * A file reference that locates the file + * @param attribute + * The attribute to set + * @param value + * The attribute value + * + * @throws UnsupportedOperationException + * If the attribute view is not available or it does not + * support updating the attribute + * @throws IllegalArgumentException + * If the attribute value is of the correct type but has an + * inappropriate value + * @throws ClassCastException + * If the attribute value is not of the expected type or is a + * collection containing elements that are not of the expected + * type + * @throws IOException + * If an I/O error occurs + * @throws SecurityException + * In the case of the default provider, and a security manager is + * installed, its {@link SecurityManager#checkWrite(String) checkWrite} + * method denies write access to the file. If this method is invoked + * to set security sensitive attributes then the security manager + * may be invoked to check for additional permissions. + */ + public static void setAttribute(FileRef file, String attribute, Object value) + throws IOException + { + String[] s = split(attribute); + FileAttributeView view = file.getFileAttributeView(s[0]); + if (view == null) + throw new UnsupportedOperationException("View '" + s[0] + "' not available"); + view.setAttribute(s[1], value); + } + + /** + * Reads the value of a file attribute. + * + * <p> The {@code attribute} parameter identifies the attribute to be read + * and takes the form: + * <blockquote> + * [<i>view-name</i><b>:</b>]<i>attribute-name</i> + * </blockquote> + * where square brackets [...] delineate an optional component and the + * character {@code ':'} stands for itself. + * + * <p> <i>view-name</i> is the {@link FileAttributeView#name name} of a {@link + * FileAttributeView} that identifies a set of file attributes. If not + * specified then it defaults to {@code "basic"}, the name of the file + * attribute view that identifies the basic set of file attributes common to + * many file systems. <i>attribute-name</i> is the name of the attribute. + * + * <p> The {@code options} array may be used to indicate how symbolic links + * are handled for the case that the file is a symbolic link. By default, + * symbolic links are followed and the file attribute of the final target + * of the link is read. If the option {@link LinkOption#NOFOLLOW_LINKS + * NOFOLLOW_LINKS} is present then symbolic links are not followed and so + * the method returns the file attribute of the symbolic link. + * + * <p> <b>Usage Example:</b> + * Suppose we require the user ID of the file owner on a system that + * supports a "{@code unix}" view: + * <pre> + * int uid = (Integer)Attributes.getAttribute(file, "unix:uid"); + * </pre> + * + * @param file + * A file reference that locates the file + * @param attribute + * The attribute to read + * @param options + * Options indicating how symbolic links are handled + * + * @return The attribute value, or {@code null} if the attribute view + * is not available or it does not support reading the attribute + * + * @throws IOException + * If an I/O error occurs + * @throws SecurityException + * In the case of the default provider, and a security manager is + * installed, its {@link SecurityManager#checkRead(String) checkRead} + * method denies read access to the file. If this method is invoked + * to read security sensitive attributes then the security manager + * may be invoked to check for additional permissions. + */ + public static Object getAttribute(FileRef file, + String attribute, + LinkOption... options) + throws IOException + { + String[] s = split(attribute); + FileAttributeView view = file.getFileAttributeView(s[0], options); + if (view != null) + return view.getAttribute(s[1]); + // view not available + return null; + } + + /** + * Reads a set of file attributes as a bulk operation. + * + * <p> The {@code attributes} parameter identifies the attributes to be read + * and takes the form: + * <blockquote> + * [<i>view-name</i><b>:</b>]<i>attribute-list</i> + * </blockquote> + * where square brackets [...] delineate an optional component and the + * character {@code ':'} stands for itself. + * + * <p> <i>view-name</i> is the {@link FileAttributeView#name name} of a {@link + * FileAttributeView} that identifies a set of file attributes. If not + * specified then it defaults to {@code "basic"}, the name of the file + * attribute view that identifies the basic set of file attributes common to + * many file systems. + * + * <p> The <i>attribute-list</i> component is a comma separated list of + * zero or more names of attributes to read. If the list contains the value + * {@code "*"} then all attributes are read. Attributes that are not supported + * are ignored and will not be present in the returned map. It is + * implementation specific if all attributes are read as an atomic operation + * with respect to other file system operations. + * + * <p> The following examples demonstrate possible values for the {@code + * attributes} parameter: + * + * <blockquote> + * <table border="0"> + * <tr> + * <td> {@code "*"} </td> + * <td> Read all {@link BasicFileAttributes basic-file-attributes}. </td> + * </tr> + * <tr> + * <td> {@code "size,lastModifiedTime,lastAccessTime"} </td> + * <td> Reads the file size, last modified time, and last access time + * attributes. </td> + * </tr> + * <tr> + * <td> {@code "posix:*"} </td> + * <td> Read all {@link PosixFileAttributes POSIX-file-attributes}.. </td> + * </tr> + * <tr> + * <td> {@code "posix:permissions,owner,size"} </td> + * <td> Reads the POSX file permissions, owner, and file size. </td> + * </tr> + * </table> + * </blockquote> + * + * <p> The {@code options} array may be used to indicate how symbolic links + * are handled for the case that the file is a symbolic link. By default, + * symbolic links are followed and the file attributes of the final target + * of the link are read. If the option {@link LinkOption#NOFOLLOW_LINKS + * NOFOLLOW_LINKS} is present then symbolic links are not followed and so + * the method returns the file attributes of the symbolic link. + * + * @param file + * A file reference that locates the file + * @param attributes + * The attributes to read + * @param options + * Options indicating how symbolic links are handled + * + * @return A map of the attributes returned; may be empty. The map's keys + * are the attribute names, its values are the attribute values + * + * @throws IOException + * If an I/O error occurs + * @throws SecurityException + * In the case of the default provider, and a security manager is + * installed, its {@link SecurityManager#checkRead(String) checkRead} + * method denies read access to the file. If this method is invoked + * to read security sensitive attributes then the security manager + * may be invoke to check for additional permissions. + */ + public static Map<String,?> readAttributes(FileRef file, + String attributes, + LinkOption... options) + throws IOException + { + String[] s = split(attributes); + FileAttributeView view = file.getFileAttributeView(s[0], options); + if (view != null) { + // further split attributes into the first and rest. + String[] names = s[1].split(","); + int rem = names.length-1; + String first = names[0]; + String[] rest = new String[rem]; + if (rem > 0) System.arraycopy(names, 1, rest, 0, rem); + + return view.readAttributes(first, rest); + } + // view not available + return Collections.emptyMap(); + } + + /** + * Reads the basic file attributes of a file. + * + * <p> The {@code options} array may be used to indicate how symbolic links + * are handled for the case that the file is a symbolic link. By default, + * symbolic links are followed and the file attributes of the final target + * of the link are read. If the option {@link LinkOption#NOFOLLOW_LINKS + * NOFOLLOW_LINKS} is present then symbolic links are not followed and so + * the method returns the file attributes of the symbolic link. This option + * should be used where there is a need to determine if a file is a + * symbolic link: + * <pre> + * boolean isSymbolicLink = Attributes.readBasicFileAttributes(file, NOFOLLOW_LINKS).isSymbolicLink(); + * </pre> + * + * <p> It is implementation specific if all file attributes are read as an + * atomic operation with respect to other file system operations. + * + * @param file + * A file reference that locates the file + * @param options + * Options indicating how symbolic links are handled + * + * @return The basic file attributes + * + * @throws IOException + * If an I/O error occurs + * @throws SecurityException + * In the case of the default provider, the security manager's {@link + * SecurityManager#checkRead(String) checkRead} method is invoked + * to check read access to file + * + * @see BasicFileAttributeView#readAttributes + */ + public static BasicFileAttributes readBasicFileAttributes(FileRef file, + LinkOption... options) + throws IOException + { + return file.getFileAttributeView(BasicFileAttributeView.class, options) + .readAttributes(); + } + + /** + * Reads the POSIX file attributes of a file. + * + * <p> The {@code file} parameter locates a file that supports the {@link + * PosixFileAttributeView}. This file attribute view provides access to a + * subset of the file attributes commonly associated with files on file + * systems used by operating systems that implement the Portable Operating + * System Interface (POSIX) family of standards. It is implementation + * specific if all file attributes are read as an atomic operation with + * respect to other file system operations. + * + * <p> The {@code options} array may be used to indicate how symbolic links + * are handled for the case that the file is a symbolic link. By default, + * symbolic links are followed and the file attributes of the final target + * of the link are read. If the option {@link LinkOption#NOFOLLOW_LINKS + * NOFOLLOW_LINKS} is present then symbolic links are not followed and so + * the method returns the file attributes of the symbolic link. + * + * @param file + * A file reference that locates the file + * @param options + * Options indicating how symbolic links are handled + * + * @return The POSIX file attributes + * + * @throws UnsupportedOperationException + * If the {@code PosixFileAttributeView} is not available + * @throws IOException + * If an I/O error occurs + * @throws SecurityException + * In the case of the default provider, and a security manager is + * installed, it denies {@link RuntimePermission}<tt>("accessUserInformation")</tt> + * or its {@link SecurityManager#checkRead(String) checkRead} method + * denies read access to the file. + * + * @see PosixFileAttributeView#readAttributes + */ + public static PosixFileAttributes readPosixFileAttributes(FileRef file, + LinkOption... options) + throws IOException + { + PosixFileAttributeView view = + file.getFileAttributeView(PosixFileAttributeView.class, options); + if (view == null) + throw new UnsupportedOperationException(); + return view.readAttributes(); + } + + /** + * Reads the DOS file attributes of a file. + * + * <p> The {@code file} parameter locates a file that supports the {@link + * DosFileAttributeView}. This file attribute view provides access to + * legacy "DOS" attributes supported by the file systems such as File + * Allocation Table (FAT), commonly used in <em>consumer devices</em>. It is + * implementation specific if all file attributes are read as an atomic + * operation with respect to other file system operations. + * + * <p> The {@code options} array may be used to indicate how symbolic links + * are handled for the case that the file is a symbolic link. By default, + * symbolic links are followed and the file attributes of the final target + * of the link are read. If the option {@link LinkOption#NOFOLLOW_LINKS + * NOFOLLOW_LINKS} is present then symbolic links are not followed and so + * the method returns the file attributes of the symbolic link. + * + * @param file + * A file reference that locates the file + * @param options + * Options indicating how symbolic links are handled + * + * @return The DOS file attributes + * + * @throws UnsupportedOperationException + * If the {@code DosFileAttributeView} is not available + * @throws IOException + * If an I/O error occurs + * @throws SecurityException + * In the case of the default provider, the security manager's {@link + * SecurityManager#checkRead(String) checkRead} method is invoked + * to check read access to file + * + * @see DosFileAttributeView#readAttributes + */ + public static DosFileAttributes readDosFileAttributes(FileRef file, + LinkOption... options) + throws IOException + { + DosFileAttributeView view = + file.getFileAttributeView(DosFileAttributeView.class, options); + if (view == null) + throw new UnsupportedOperationException(); + return view.readAttributes(); + } + + /** + * Returns the owner of a file. + * + * <p> The {@code file} parameter locates a file that supports the {@link + * FileOwnerAttributeView}. This file attribute view provides access to + * a file attribute that is the owner of the file. + * + * @param file + * A file reference that locates the file + * + * @return A user principal representing the owner of the file + * + * @throws UnsupportedOperationException + * If the {@code FileOwnerAttributeView} is not available + * @throws IOException + * If an I/O error occurs + * @throws SecurityException + * In the case of the default provider, and a security manager is + * installed, it denies {@link RuntimePermission}<tt>("accessUserInformation")</tt> + * or its {@link SecurityManager#checkRead(String) checkRead} method + * denies read access to the file. + * + * @see FileOwnerAttributeView#getOwner + */ + public static UserPrincipal getOwner(FileRef file) throws IOException { + FileOwnerAttributeView view = + file.getFileAttributeView(FileOwnerAttributeView.class); + if (view == null) + throw new UnsupportedOperationException(); + return view.getOwner(); + } + + /** + * Updates the file owner. + * + * <p> The {@code file} parameter locates a file that supports the {@link + * FileOwnerAttributeView}. This file attribute view provides access to + * a file attribute that is the owner of the file. + * + * @param file + * A file reference that locates the file + * @param owner + * The new file owner + * + * @throws UnsupportedOperationException + * If the {@code FileOwnerAttributeView} is not available + * @throws IOException + * If an I/O error occurs + * @throws SecurityException + * In the case of the default provider, and a security manager is + * installed, it denies {@link RuntimePermission}<tt>("accessUserInformation")</tt> + * or its {@link SecurityManager#checkWrite(String) checkWrite} + * method denies write access to the file. + * + * @see FileOwnerAttributeView#setOwner + */ + public static void setOwner(FileRef file, UserPrincipal owner) + throws IOException + { + FileOwnerAttributeView view = + file.getFileAttributeView(FileOwnerAttributeView.class); + if (view == null) + throw new UnsupportedOperationException(); + view.setOwner(owner); + } + + /** + * Reads a file's Access Control List (ACL). + * + * <p> The {@code file} parameter locates a file that supports the {@link + * AclFileAttributeView}. This file attribute view provides access to ACLs + * based on the ACL model specified in + * <a href="http://www.ietf.org/rfc/rfc3530.txt"><i>RFC 3530</i></a>. + * + * @param file + * A file reference that locates the file + * + * @return An ordered list of {@link AclEntry entries} representing the + * ACL. The returned list is modifiable. + * + * @throws UnsupportedOperationException + * If the {@code AclAttributeView} is not available + * @throws IOException + * If an I/O error occurs + * @throws SecurityException + * In the case of the default provider, and a security manager is + * installed, it denies {@link RuntimePermission}<tt>("accessUserInformation")</tt> + * or its {@link SecurityManager#checkRead(String) checkRead} method + * denies read access to the file. + * + * @see AclFileAttributeView#getAcl + */ + public static List<AclEntry> getAcl(FileRef file) throws IOException { + AclFileAttributeView view = + file.getFileAttributeView(AclFileAttributeView.class); + if (view == null) + throw new UnsupportedOperationException(); + return view.getAcl(); + } + + /** + * Updates a file's Access Control List (ACL). + * + * <p> The {@code file} parameter locates a file that supports the {@link + * AclFileAttributeView}. This file attribute view provides access to ACLs + * based on the ACL model specified in + * <a href="http://www.ietf.org/rfc/rfc3530.txt"><i>RFC 3530</i></a>. + * + * @param file + * A file reference that locates the file + * @param acl + * The new file ACL + * + * @throws UnsupportedOperationException + * If the {@code AclFileAttributeView} is not available + * @throws IOException + * If an I/O error occurs + * @throws SecurityException + * In the case of the default provider, and a security manager is + * installed, it denies {@link RuntimePermission}<tt>("accessUserInformation")</tt> + * or its {@link SecurityManager#checkWrite(String) checkWrite} + * method denies write access to the file. + * + * @see AclFileAttributeView#setAcl + */ + public static void setAcl(FileRef file, List<AclEntry> acl) + throws IOException + { + AclFileAttributeView view = + file.getFileAttributeView(AclFileAttributeView.class); + if (view == null) + throw new UnsupportedOperationException(); + view.setAcl(acl); + } + + /** + * Updates the value of a file's last modified time attribute. + * + * <p> The time value is measured since the epoch + * (00:00:00 GMT, January 1, 1970) and is converted to the precision supported + * by the file system. Converting from finer to coarser granularities result + * in precision loss. + * + * <p> If the file system does not support a last modified time attribute then + * this method has no effect. + * + * @param file + * A file reference that locates the file + * + * @param lastModifiedTime + * The new last modified time, or {@code -1L} to update it to + * the current time + * @param unit + * A {@code TimeUnit} determining how to interpret the + * {@code lastModifiedTime} parameter + * + * @throws IllegalArgumentException + * If the {@code lastModifiedime} parameter is a negative value other + * than {@code -1L} + * @throws IOException + * If an I/O error occurs + * @throws SecurityException + * In the case of the default provider, the security manager's {@link + * SecurityManager#checkWrite(String) checkWrite} method is invoked + * to check write access to file + * + * @see BasicFileAttributeView#setTimes + */ + public static void setLastModifiedTime(FileRef file, + long lastModifiedTime, + TimeUnit unit) + throws IOException + { + file.getFileAttributeView(BasicFileAttributeView.class) + .setTimes(lastModifiedTime, null, null, unit); + } + + /** + * Updates the value of a file's last access time attribute. + * + * <p> The time value is measured since the epoch + * (00:00:00 GMT, January 1, 1970) and is converted to the precision supported + * by the file system. Converting from finer to coarser granularities result + * in precision loss. + * + * <p> If the file system does not support a last access time attribute then + * this method has no effect. + * + * @param lastAccessTime + * The new last access time, or {@code -1L} to update it to + * the current time + * @param unit + * A {@code TimeUnit} determining how to interpret the + * {@code lastModifiedTime} parameter + * + * @throws IllegalArgumentException + * If the {@code lastAccessTime} parameter is a negative value other + * than {@code -1L} + * @throws IOException + * If an I/O error occurs + * @throws SecurityException + * In the case of the default provider, the security manager's {@link + * SecurityManager#checkWrite(String) checkWrite} method is invoked + * to check write access to file + * + * @see BasicFileAttributeView#setTimes + */ + public static void setLastAccessTime(FileRef file, + long lastAccessTime, + TimeUnit unit) + throws IOException + { + file.getFileAttributeView(BasicFileAttributeView.class) + .setTimes(null, lastAccessTime, null, unit); + } + + /** + * Sets a file's POSIX permissions. + * + * <p> The {@code file} parameter is a reference to an existing file. It + * supports the {@link PosixFileAttributeView} that provides access to file + * attributes commonly associated with files on file systems used by + * operating systems that implement the Portable Operating System Interface + * (POSIX) family of standards. + * + * @param file + * A file reference that locates the file + * @param perms + * The new set of permissions + * + * @throws UnsupportedOperationException + * If {@code PosixFileAttributeView} is not available + * @throws ClassCastException + * If the sets contains elements that are not of type {@code + * PosixFilePermission} + * @throws IOException + * If an I/O error occurs + * @throws SecurityException + * In the case of the default provider, and a security manager is + * installed, it denies {@link RuntimePermission}<tt>("accessUserInformation")</tt> + * or its {@link SecurityManager#checkWrite(String) checkWrite} + * method denies write access to the file. + * + * @see PosixFileAttributeView#setPermissions + */ + public static void setPosixFilePermissions(FileRef file, + Set<PosixFilePermission> perms) + throws IOException + { + PosixFileAttributeView view = + file.getFileAttributeView(PosixFileAttributeView.class); + if (view == null) + throw new UnsupportedOperationException(); + view.setPermissions(perms); + } + + /** + * Reads the space attributes of a file store. + * + * <p> The {@code store} parameter is a file store that supports the + * {@link FileStoreSpaceAttributeView} providing access to the space related + * attributes of the file store. It is implementation specific if all attributes + * are read as an atomic operation with respect to other file system operations. + * + * @param store + * The file store + * + * @return The file store space attributes + * + * @throws UnsupportedOperationException + * If the file store space attribute view is not supported + * @throws IOException + * If an I/O error occurs + * + * @see FileStoreSpaceAttributeView#readAttributes() + */ + public static FileStoreSpaceAttributes readFileStoreSpaceAttributes(FileStore store) + throws IOException + { + FileStoreSpaceAttributeView view = + store.getFileStoreAttributeView(FileStoreSpaceAttributeView.class); + if (view == null) + throw new UnsupportedOperationException(); + return view.readAttributes(); + } +} diff --git a/src/share/classes/java/nio/file/attribute/BasicFileAttributeView.java b/src/share/classes/java/nio/file/attribute/BasicFileAttributeView.java new file mode 100644 index 0000000000000000000000000000000000000000..70100834d8f4f87d5d5adc2565ff432602bbe602 --- /dev/null +++ b/src/share/classes/java/nio/file/attribute/BasicFileAttributeView.java @@ -0,0 +1,186 @@ +/* + * Copyright 2007-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 java.nio.file.attribute; + +import java.util.concurrent.TimeUnit; +import java.io.IOException; + +/** + * A file attribute view that provides a view of a <em>basic set</em> of file + * attributes common to many file systems. The basic set of file attributes + * consist of <em>mandatory</em> and <em>optional</em> file attributes as + * defined by the {@link BasicFileAttributes} interface. + + * <p> The file attributes are retrieved from the file system as a <em>bulk + * operation</em> by invoking the {@link #readAttributes() readAttributes} method. + * This class also defines the {@link #setTimes setTimes} method to update the + * file's time attributes. + * + * <p> Where dynamic access to file attributes is required, the attributes + * supported by this attribute view have the following names and types: + * <blockquote> + * <table border="1" cellpadding="8"> + * <tr> + * <th> Name </th> + * <th> Type </th> + * </tr> + * <tr> + * <td> "lastModifiedTime" </td> + * <td> {@link Long} </td> + * </tr> + * <tr> + * <td> "lastAccessTime" </td> + * <td> {@link Long} </td> + * </tr> + * <tr> + * <td> "creationTime" </td> + * <td> {@link Long} </td> + * </tr> + * <tr> + * <td> "resolution" </td> + * <td> {@link java.util.concurrent.TimeUnit} </td> + * </tr> + * <tr> + * <td> "size" </td> + * <td> {@link Long} </td> + * </tr> + * <tr> + * <td> "isRegularFile" </td> + * <td> {@link Boolean} </td> + * </tr> + * <tr> + * <td> "isDirectory" </td> + * <td> {@link Boolean} </td> + * </tr> + * <tr> + * <td> "isSymbolicLink" </td> + * <td> {@link Boolean} </td> + * </tr> + * <tr> + * <td> "isOther" </td> + * <td> {@link Boolean} </td> + * </tr> + * <tr> + * <td> "linkCount" </td> + * <td> {@link Integer} </td> + * </tr> + * <tr> + * <td> "fileKey" </td> + * <td> {@link Object} </td> + * </tr> + * </table> + * </blockquote> + * + * <p> The {@link #getAttribute getAttribute} or {@link + * #readAttributes(String,String[]) readAttributes(String,String[])} methods may + * be used to read any of these attributes as if by invoking the {@link + * #readAttributes() readAttributes()} method. + * + * <p> The {@link #setAttribute setAttribute} method may be used to update the + * file's last modified time, last access time or create time attributes as if + * by invoking the {@link #setTimes setTimes} method. In that case, the time + * value is interpreted in {@link TimeUnit#MILLISECONDS milliseconds} and + * converted to the precision supported by the file system. + * + * @since 1.7 + * @see Attributes + */ + +public interface BasicFileAttributeView + extends FileAttributeView +{ + /** + * Returns the name of the attribute view. Attribute views of this type + * have the name {@code "basic"}. + */ + @Override + String name(); + + /** + * Reads the basic file attributes as a bulk operation. + * + * <p> It is implementation specific if all file attributes are read as an + * atomic operation with respect to other file system operations. + * + * @return the file attributes + * + * @throws IOException + * if an I/O error occurs + * @throws SecurityException + * In the case of the default provider, a security manager is + * installed, its {@link SecurityManager#checkRead(String) checkRead} + * method is invoked to check read access to the file + */ + BasicFileAttributes readAttributes() throws IOException; + + /** + * Updates any or all of the file's last modified time, last access time, + * and create time attributes. + * + * <p> This method updates the file's timestamp attributes. The values are + * measured since the epoch (00:00:00 GMT, January 1, 1970) and converted to + * the precision supported by the file system. Converting from finer to + * coarser granularities result in precision loss. If a value is larger + * than the maximum supported by the file system then the corresponding + * timestamp is set to its maximum value. + * + * <p> If any of the {@code lastModifiedTime}, {@code lastAccessTime}, + * or {@code createTime} parameters has the value {@code null} then the + * corresponding timestamp is not changed. An implementation may require to + * read the existing values of the file attributes when only some, but not + * all, of the timestamp attributes are updated. Consequently, this method + * may not be an atomic operation with respect to other file system + * operations. If all of the {@code lastModifiedTime}, {@code + * lastAccessTime} and {@code createTime} parameters are {@code null} then + * this method has no effect. + * + * @param lastModifiedTime + * the new last modified time, or {@code -1L} to update it to + * the current time, or {@code null} to not change the attribute + * @param lastAccessTime + * the last access time, or {@code -1L} to update it to + * the current time, or {@code null} to not change the attribute. + * @param createTime + * the file's create time, or {@code -1L} to update it to + * the current time, or {@code null} to not change the attribute + * @param unit + * a {@code TimeUnit} determining how to interpret the time values + * + * @throws IllegalArgumentException + * if any of the parameters is a negative value other than {@code + * -1L} + * @throws IOException + * if an I/O error occurs + * @throws SecurityException + * In the case of the default provider, a security manager is + * installed, its {@link SecurityManager#checkWrite(String) checkWrite} + * method is invoked to check write access to the file + */ + void setTimes(Long lastModifiedTime, + Long lastAccessTime, + Long createTime, + TimeUnit unit) throws IOException; +} diff --git a/src/share/classes/java/nio/file/attribute/BasicFileAttributes.java b/src/share/classes/java/nio/file/attribute/BasicFileAttributes.java new file mode 100644 index 0000000000000000000000000000000000000000..64c163bc5a19bc6a65a512d40a120ee3d5e358a6 --- /dev/null +++ b/src/share/classes/java/nio/file/attribute/BasicFileAttributes.java @@ -0,0 +1,163 @@ +/* + * Copyright 2007-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 java.nio.file.attribute; + +import java.util.concurrent.TimeUnit; + +/** + * Basic attributes associated with a file in a file system. + * + * <p> Basic file attributes are attributes that are common to many file systems + * and consist of mandatory and optional file attributes as defined by this + * interface. + * + * <p> <b>Usage Example:</b> + * <pre> + * FileRef file = ... + * BasicFileAttributes attrs = Attributes.readBasicFileAttributes(file); + * </pre> + * + * @since 1.7 + * + * @see BasicFileAttributeView + */ + +public interface BasicFileAttributes { + + /** + * Returns the time of last modification. + * + * <p> The {@link #resolution() resolution} method returns the {@link TimeUnit} + * to interpret the return value of this method. + * + * @return a <code>long</code> value representing the time the file was + * last modified since the epoch (00:00:00 GMT, January 1, 1970), + * or {@code -1L} if the attribute is not supported. + */ + long lastModifiedTime(); + + /** + * Returns the time of last access if supported. + * + * <p> The {@link #resolution() resolution} method returns the {@link TimeUnit} + * to interpret the return value of this method. + * + * @return a <code>long</code> value representing the time of last access + * since the epoch (00:00:00 GMT, January 1, 1970), or {@code -1L} + * if the attribute is not supported. + */ + long lastAccessTime(); + + /** + * Returns the creation time if supported. The creation time is the time + * that the file was created. + * + * <p> The {@link #resolution() resolution} method returns the {@link TimeUnit} + * to interpret the return value of this method. + * + * @return a <code>long</code> value representing the time the file was + * created since the epoch (00:00:00 GMT, January 1, 1970), or + * {@code -1L} if the attribute is not supported. + */ + long creationTime(); + + /** + * Returns the {@link TimeUnit} required to interpret the time of last + * modification, time of last access, and creation time. + * + * @return the {@code TimeUnit} required to interpret the file time stamps + */ + TimeUnit resolution(); + + /** + * Tells whether the file is a regular file with opaque content. + */ + boolean isRegularFile(); + + /** + * Tells whether the file is a directory. + */ + boolean isDirectory(); + + /** + * Tells whether the file is a symbolic-link. + */ + boolean isSymbolicLink(); + + /** + * Tells whether the file is something other than a regular file, directory, + * or link. + */ + boolean isOther(); + + /** + * Returns the size of the file (in bytes). The size may differ from the + * actual size on the file system due to compression, support for sparse + * files, or other reasons. The size of files that are not {@link + * #isRegularFile regular} files is implementation specific and + * therefore unspecified. + * + * @return the file size, in bytes + */ + long size(); + + /** + * Returns the number of <em>links</em> to this file. + * + * <p> On file systems where the same file may be in several directories then + * the link count is the number of directory entries for the file. The return + * value is {@code 1} on file systems that only allow a file to have a + * single name in a single directory. + * + * @see java.nio.file.Path#createLink + */ + int linkCount(); + + /** + * Returns an object that uniquely identifies the given file, or {@code + * null} if a file key is not available. On some platforms or file systems + * it is possible to use an identifier, or a combination of identifiers to + * uniquely identify a file. Such identifiers are important for operations + * such as file tree traversal in file systems that support <a + * href="../package-summary.html#links">symbolic links</a> or file systems + * that allow a file to be an entry in more than one directory. On UNIX file + * systems, for example, the <em>device ID</em> and <em>inode</em> are + * commonly used for such purposes. + * + * <p> The file key returned by this method can only be guaranteed to be + * unique if the file system and files remain static. Whether a file system + * re-uses identifiers after a file is deleted is implementation dependent and + * therefore unspecified. + * + * <p> File keys returned by this method can be compared for equality and are + * suitable for use in collections. If the file system and files remain static, + * and two files are the {@link java.nio.file.FileRef#isSameFile same} with + * non-{@code null} file keys, then their file keys are equal. + * + * @see java.nio.file.Files#walkFileTree + */ + Object fileKey(); +} diff --git a/src/share/classes/java/nio/file/attribute/DosFileAttributeView.java b/src/share/classes/java/nio/file/attribute/DosFileAttributeView.java new file mode 100644 index 0000000000000000000000000000000000000000..c57683999b62d4acf4f971afba71d6f888ad669d --- /dev/null +++ b/src/share/classes/java/nio/file/attribute/DosFileAttributeView.java @@ -0,0 +1,179 @@ +/* + * Copyright 2007-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 java.nio.file.attribute; + +import java.io.IOException; + +/** + * A file attribute view that provides a view of the legacy "DOS" file attributes. + * These attributes are supported by file systems such as the File Allocation + * Table (FAT) format commonly used in <em>consumer devices</em>. + * + * <p> A {@code DosFileAttributeView} is a {@link BasicFileAttributeView} that + * additionally supports access to the set of DOS attribute flags that are used + * to indicate if the file is read-only, hidden, a system file, or archived. + * + * <p> Where dynamic access to file attributes is required, the attributes + * supported by this attribute view are as defined by {@code + * BasicFileAttributeView}, and in addition, the following attributes are + * supported: + * <blockquote> + * <table border="1" cellpadding="8"> + * <tr> + * <th> Name </th> + * <th> Type </th> + * </tr> + * <tr> + * <td> readonly </td> + * <td> {@link Boolean} </td> + * </tr> + * <tr> + * <td> hidden </td> + * <td> {@link Boolean} </td> + * </tr> + * <tr> + * <td> system </td> + * <td> {@link Boolean} </td> + * </tr> + * <tr> + * <td> archive </td> + * <td> {@link Boolean} </td> + * </tr> + * </table> + * </blockquote> + * + * <p> The {@link #getAttribute getAttribute} or {@link #readAttributes(String,String[]) + * readAttributes(String,String[])} methods may be used to read any of these + * attributes, or any of the attributes defined by {@link BasicFileAttributeView} + * as if by invoking the {@link #readAttributes readAttributes()} method. + * + * <p> The {@link #setAttribute setAttribute} method may be used to update the + * file's last modified time, last access time or create time attributes as + * defined by {@link BasicFileAttributeView}. It may also be used to update + * the DOS attributes as if by invoking the {@link #setReadOnly setReadOnly}, + * {@link #setHidden setHidden}, {@link #setSystem setSystem}, and {@link + * #setArchive setArchive} methods respectively. + * + * @since 1.7 + */ + +public interface DosFileAttributeView + extends BasicFileAttributeView +{ + /** + * Returns the name of the attribute view. Attribute views of this type + * have the name {@code "dos"}. + */ + @Override + String name(); + + /** + * @throws IOException {@inheritDoc} + * @throws SecurityException {@inheritDoc} + */ + @Override + DosFileAttributes readAttributes() throws IOException; + + /** + * Updates the value of the read-only attribute. + * + * <p> It is implementation specific if the attribute can be updated as an + * atomic operation with respect to other file system operations. An + * implementation may, for example, require to read the existing value of + * the DOS attribute in order to update this attribute. + * + * @param value + * the new value of the attribute + * + * @throws IOException + * if an I/O error occurs + * @throws SecurityException + * In the case of the default, and a security manager is installed, + * its {@link SecurityManager#checkWrite(String) checkWrite} method + * is invoked to check write access to the file + */ + void setReadOnly(boolean value) throws IOException; + + /** + * Updates the value of the hidden attribute. + * + * <p> It is implementation specific if the attribute can be updated as an + * atomic operation with respect to other file system operations. An + * implementation may, for example, require to read the existing value of + * the DOS attribute in order to update this attribute. + * + * @param value + * the new value of the attribute + * + * @throws IOException + * if an I/O error occurs + * @throws SecurityException + * In the case of the default, and a security manager is installed, + * its {@link SecurityManager#checkWrite(String) checkWrite} method + * is invoked to check write access to the file + */ + void setHidden(boolean value) throws IOException; + + /** + * Updates the value of the system attribute. + * + * <p> It is implementation specific if the attribute can be updated as an + * atomic operation with respect to other file system operations. An + * implementation may, for example, require to read the existing value of + * the DOS attribute in order to update this attribute. + * + * @param value + * the new value of the attribute + * + * @throws IOException + * if an I/O error occurs + * @throws SecurityException + * In the case of the default, and a security manager is installed, + * its {@link SecurityManager#checkWrite(String) checkWrite} method + * is invoked to check write access to the file + */ + void setSystem(boolean value) throws IOException; + + /** + * Updates the value of the archive attribute. + * + * <p> It is implementation specific if the attribute can be updated as an + * atomic operation with respect to other file system operations. An + * implementation may, for example, require to read the existing value of + * the DOS attribute in order to update this attribute. + * + * @param value + * the new value of the attribute + * + * @throws IOException + * if an I/O error occurs + * @throws SecurityException + * In the case of the default, and a security manager is installed, + * its {@link SecurityManager#checkWrite(String) checkWrite} method + * is invoked to check write access to the file + */ + void setArchive(boolean value) throws IOException; +} diff --git a/src/share/classes/java/nio/file/attribute/DosFileAttributes.java b/src/share/classes/java/nio/file/attribute/DosFileAttributes.java new file mode 100644 index 0000000000000000000000000000000000000000..53e63d51a98d4247cceb39f2d09af0649962c3ff --- /dev/null +++ b/src/share/classes/java/nio/file/attribute/DosFileAttributes.java @@ -0,0 +1,84 @@ +/* + * Copyright 2007-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 java.nio.file.attribute; + +/** + * File attributes associated with a file in a file system that supports + * legacy "DOS" attributes. + * + * <p> The DOS attributes of a file are retrieved using a {@link + * DosFileAttributeView} by invoking its {@link DosFileAttributeView#readAttributes + * readAttributes} method. + * + * @since 1.7 + * + * @see Attributes#readDosFileAttributes + */ + +public interface DosFileAttributes + extends BasicFileAttributes +{ + /** + * Returns the value of the read-only attribute. + * + * <p> This attribute is often used as a simple access control mechanism + * to prevent files from being deleted or updated. Whether the file system + * or platform does any enforcement to prevent <em>read-only</em> files + * from being updated is implementation specific. + * + * @return the value of the read-only attribute + */ + boolean isReadOnly(); + + /** + * Returns the value of the hidden attribute. + * + * <p> This attribute is often used to indicate if the file is visible to + * users. + * + * @return the value of the hidden attribute + */ + boolean isHidden(); + + /** + * Returns the value of the archive attribute. + * + * <p> This attribute is typically used by backup programs. + * + * @return the value of the archive attribute + */ + boolean isArchive(); + + /** + * Returns the value of the system attribute. + * + * <p> This attribute is often used to indicate that the file is a component + * of the operating system. + * + * @return the value of the system attribute + */ + boolean isSystem(); +} diff --git a/src/share/classes/java/nio/file/attribute/FileAttribute.java b/src/share/classes/java/nio/file/attribute/FileAttribute.java new file mode 100644 index 0000000000000000000000000000000000000000..ed0d7311ff03e0eb899fe9ab5c9a9b17c5edcb71 --- /dev/null +++ b/src/share/classes/java/nio/file/attribute/FileAttribute.java @@ -0,0 +1,50 @@ +/* + * Copyright 2007-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 java.nio.file.attribute; + +/** + * An object that encapsulates the value of a file attribute that can be set + * atomically when creating a new file or directory by invoking the {@link + * java.nio.file.Path#createFile createFile} or {@link + * java.nio.file.Path#createDirectory createDirectory} methods. + * + * @param <T> The type of the file attribute value + * + * @since 1.7 + * @see PosixFilePermissions#asFileAttribute + */ + +public interface FileAttribute<T> { + /** + * Returns the attribute name. + */ + String name(); + + /** + * Returns the attribute value. + */ + T value(); +} diff --git a/src/share/classes/java/nio/file/attribute/FileAttributeView.java b/src/share/classes/java/nio/file/attribute/FileAttributeView.java new file mode 100644 index 0000000000000000000000000000000000000000..78a67b4a4cda46c62b7ec3e6d48d473bed6025b1 --- /dev/null +++ b/src/share/classes/java/nio/file/attribute/FileAttributeView.java @@ -0,0 +1,43 @@ +/* + * Copyright 2007-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 java.nio.file.attribute; + +/** + * An attribute view that is a read-only or updatable view of non-opaque + * values associated with a file in a filesystem. This interface is extended or + * implemented by specific file attribute views that define methods to read + * and/or update the attributes of a file. + * + * @since 1.7 + * + * @see java.nio.file.FileRef#getFileAttributeView(Class,java.nio.file.LinkOption[]) + * @see java.nio.file.FileRef#getFileAttributeView(String,java.nio.file.LinkOption[]) + */ + +public interface FileAttributeView + extends AttributeView +{ +} diff --git a/src/share/classes/java/nio/file/attribute/FileOwnerAttributeView.java b/src/share/classes/java/nio/file/attribute/FileOwnerAttributeView.java new file mode 100644 index 0000000000000000000000000000000000000000..0afc19efbffbdbb830196be45c326ea8af0e1a2f --- /dev/null +++ b/src/share/classes/java/nio/file/attribute/FileOwnerAttributeView.java @@ -0,0 +1,101 @@ +/* + * Copyright 2007-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 java.nio.file.attribute; + +import java.io.IOException; + +/** + * A file attribute view that supports reading or updating the owner of a file. + * This file attribute view is intended for file system implementations that + * support a file attribute that represents an identity that is the owner of + * the file. Often the owner of a file is the identity of the entity that + * created the file. + * + * <p> The {@link #getOwner getOwner} or {@link #setOwner setOwner} methods may + * be used to read or update the owner of the file. + * + * <p> Where dynamic access to file attributes is required, the owner attribute + * is identified by the name {@code "owner"}, and the value of the attribute is + * a {@link UserPrincipal}. The {@link #readAttributes readAttributes}, {@link + * #getAttribute getAttribute} and {@link #setAttribute setAttributes} methods + * may be used to read or update the file owner. + * + * @since 1.7 + */ + +public interface FileOwnerAttributeView + extends FileAttributeView +{ + /** + * Returns the name of the attribute view. Attribute views of this type + * have the name {@code "owner"}. + */ + @Override + String name(); + + /** + * Read the file owner. + * + * <p> It it implementation specific if the file owner can be a {@link + * GroupPrincipal group}. + * + * @return the file owner + * + * @throws IOException + * if an I/O error occurs + * @throws SecurityException + * In the case of the default provider, a security manager is + * installed, and it denies {@link + * RuntimePermission}<tt>("accessUserInformation")</tt> or its + * {@link SecurityManager#checkRead(String) checkRead} method + * denies read access to the file. + */ + UserPrincipal getOwner() throws IOException; + + /** + * Updates the file owner. + * + * <p> It it implementation specific if the file owner can be a {@link + * GroupPrincipal group}. To ensure consistent and correct behavior + * across platforms it is recommended that this method should only be used + * to set the file owner to a user principal that is not a group. + * + * @param owner + * the new file owner + * + * @throws IOException + * if an I/O error occurs, or the {@code owner} parameter is a + * group and this implementation does not support setting the owner + * to a group + * @throws SecurityException + * In the case of the default provider, a security manager is + * installed, and it denies {@link + * RuntimePermission}<tt>("accessUserInformation")</tt> or its + * {@link SecurityManager#checkWrite(String) checkWrite} method + * denies write access to the file. + */ + void setOwner(UserPrincipal owner) throws IOException; +} diff --git a/src/share/classes/java/nio/file/attribute/FileStoreAttributeView.java b/src/share/classes/java/nio/file/attribute/FileStoreAttributeView.java new file mode 100644 index 0000000000000000000000000000000000000000..6dfb3ff022862b1de2531bc414d0e7d415a6028e --- /dev/null +++ b/src/share/classes/java/nio/file/attribute/FileStoreAttributeView.java @@ -0,0 +1,38 @@ +/* + * Copyright 2007-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 java.nio.file.attribute; + +/** + * An attribute view that is a read-only or updatable view of the attributes of + * a {@link java.nio.file.FileStore}. + * + * @since 1.7 + */ + +public interface FileStoreAttributeView + extends AttributeView +{ +} diff --git a/src/share/classes/java/nio/file/attribute/FileStoreSpaceAttributeView.java b/src/share/classes/java/nio/file/attribute/FileStoreSpaceAttributeView.java new file mode 100644 index 0000000000000000000000000000000000000000..22d38617cb02491de1299f890b4769240f7b1cac --- /dev/null +++ b/src/share/classes/java/nio/file/attribute/FileStoreSpaceAttributeView.java @@ -0,0 +1,85 @@ +/* + * Copyright 2007-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 java.nio.file.attribute; + +import java.io.IOException; + +/** + * A file store attribute view that supports reading of space attributes. + * + * <p> Where dynamic access to file attributes is required, the attributes + * supported by this attribute view have the following names and types: + * <blockquote> + * <table border="1" cellpadding="8"> + * <tr> + * <th> Name </th> + * <th> Type </th> + * </tr> + * <tr> + * <td> "totalSpace" </td> + * <td> {@link Long} </td> + * </tr> + * <tr> + * <td> "usableSpace" </td> + * <td> {@link Long} </td> + * </tr> + * <tr> + * <td> "unallocatedSpace" </td> + * <td> {@link Long} </td> + * </tr> + * </table> + * </blockquote> + * <p> The {@link #getAttribute getAttribute} or {@link #readAttributes + * readAttributes(String,String[])} methods may be used to read any of these + * attributes as if by invoking the {@link #readAttributes readAttributes()} + * method. + * + * @since 1.7 + */ + +public interface FileStoreSpaceAttributeView + extends FileStoreAttributeView +{ + /** + * Returns the name of the attribute view. Attribute views of this type + * have the name {@code "space"}. + */ + @Override + String name(); + + /** + * Reads the disk space attributes as a bulk operation. + * + * <p> It is file system specific if all attributes are read as an + * atomic operation with respect to other file system operations. + * + * @return The disk space attributes + * + * @throws IOException + * If an I/O error occurs + */ + FileStoreSpaceAttributes readAttributes() throws IOException; +} diff --git a/src/share/classes/java/nio/file/attribute/FileStoreSpaceAttributes.java b/src/share/classes/java/nio/file/attribute/FileStoreSpaceAttributes.java new file mode 100644 index 0000000000000000000000000000000000000000..6f12d71e5955ac60a697c95275293963accbdeeb --- /dev/null +++ b/src/share/classes/java/nio/file/attribute/FileStoreSpaceAttributes.java @@ -0,0 +1,66 @@ +/* + * Copyright 2007-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 java.nio.file.attribute; + +/** + * Space related attributes of a file store. + * + * @since 1.7 + * + * @see Attributes#readFileStoreSpaceAttributes + */ + +public interface FileStoreSpaceAttributes { + /** + * Returns the size, in bytes, of the file store. + */ + long totalSpace(); + + /** + * Returns the number of bytes available to this Java virtual machine on the + * file store. + * + * <p> The returned number of available bytes is a hint, but not a + * guarantee, that it is possible to use most or any of these bytes. The + * number of usable bytes is most likely to be accurate immediately + * after the space attributes are obtained. It is likely to be made inaccurate + * by any external I/O operations including those made on the system outside + * of this Java virtual machine. + */ + long usableSpace(); + + /** + * Returns the number of unallocated bytes in the file store. + * + * <p> The returned number of unallocated bytes is a hint, but not a + * guarantee, that it is possible to use most or any of these bytes. The + * number of unallocated bytes is most likely to be accurate immediately + * after the space attributes are obtained. It is likely to be + * made inaccurate by any external I/O operations including those made on + * the system outside of this virtual machine. + */ + long unallocatedSpace(); +} diff --git a/src/share/classes/java/nio/file/attribute/GroupPrincipal.java b/src/share/classes/java/nio/file/attribute/GroupPrincipal.java new file mode 100644 index 0000000000000000000000000000000000000000..db09d48ae65795fbb7aa61b565bc1e8b392f3cae --- /dev/null +++ b/src/share/classes/java/nio/file/attribute/GroupPrincipal.java @@ -0,0 +1,42 @@ +/* + * Copyright 2007-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 java.nio.file.attribute; + +/** + * A {@code UserPrincipal} representing a <em>group identity</em>, used to + * determine access rights to objects in a file system. The exact definition of + * a group is implementation specific, but typically, it represents an identity + * created for administrative purposes so as to determine the access rights for + * the members of the group. Whether an entity can be a member of multiple + * groups, and whether groups can be nested, are implementation specified and + * therefore not specified. + * + * @since 1.7 + * + * @see UserPrincipalLookupService#lookupPrincipalByGroupName + */ + +public interface GroupPrincipal extends UserPrincipal { } diff --git a/src/share/classes/java/nio/file/attribute/PosixFileAttributeView.java b/src/share/classes/java/nio/file/attribute/PosixFileAttributeView.java new file mode 100644 index 0000000000000000000000000000000000000000..285b8bb7d1cfb7ff3630d5878a2448b485881784 --- /dev/null +++ b/src/share/classes/java/nio/file/attribute/PosixFileAttributeView.java @@ -0,0 +1,196 @@ +/* + * Copyright 2007-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 java.nio.file.attribute; + +import java.nio.file.*; +import java.util.Set; +import java.io.IOException; + +/** + * A file attribute view that provides a view of the file attributes commonly + * associated with files on file systems used by operating systems that implement + * the Portable Operating System Interface (POSIX) family of standards. + * + * <p> Operating systems that implement the <a href="http://www.opengroup.org"> + * POSIX</a> family of standards commonly use file systems that have a + * file <em>owner</em>, <em>group-owner</em>, and related <em>access + * permissions</em>. This file attribute view provides read and write access + * to these attributes. + * + * <p> The {@link #readAttributes() readAttributes} method is used to read the + * file's attributes. The file {@link PosixFileAttributes#owner() owner} is + * represented by a {@link UserPrincipal} that is the identity of the file owner + * for the purposes of access control. The {@link PosixFileAttributes#group() + * group-owner}, represented by a {@link GroupPrincipal}, is the identity of the + * group owner, where a group is an identity created for administrative purposes + * so as to determine the access rights for the members of the group. + * + * <p> The {@link PosixFileAttributes#permissions() permissions} attribute is a + * set of access permissions. This file attribute view provides access to the nine + * permission defined by the {@link PosixFilePermission} class. + * These nine permission bits determine the <em>read</em>, <em>write</em>, and + * <em>execute</em> access for the file owner, group, and others (others + * meaning identities other than the owner and members of the group). Some + * operating systems and file systems may provide additional permission bits + * but access to these other bits is not defined by this class in this release. + * + * <p> <b>Usage Example:</b> + * Suppose we need to print out the owner and access permissions of a file: + * <pre> + * FileRef file = ... + * PosixFileAttributes attrs = file.newFileAttributeView(PosixFileAttributeView.class) + * .readAttributes(); + * System.out.format("%s %s%n", + * attrs.owner().getName(), + * PosixFilePermissions.toString(attrs.permissions())); + * </pre> + * + * <h4> Dynamic Access </h4> + * <p> Where dynamic access to file attributes is required, the attributes + * supported by this attribute view are as defined by {@link + * BasicFileAttributeView} and {@link FileOwnerAttributeView}, and in addition, + * the following attributes are supported: + * <blockquote> + * <table border="1" cellpadding="8"> + * <tr> + * <th> Name </th> + * <th> Type </th> + * </tr> + * <tr> + * <td> "permissions" </td> + * <td> {@link Set}<{@link PosixFilePermission}> </td> + * </tr> + * <tr> + * <td> "group" </td> + * <td> {@link GroupPrincipal} </td> + * </tr> + * </table> + * </blockquote> + * + * <p> The {@link #getAttribute getAttribute} or {@link + * #readAttributes(String,String[]) readAttributes(String,String[])} methods may + * be used to read any of these attributes, or any of the attributes defined by + * {@link BasicFileAttributeView} as if by invoking the {@link #readAttributes + * readAttributes()} method. + * + * <p> The {@link #setAttribute setAttribute} method may be used to update the + * file's last modified time, last access time or create time attributes as + * defined by {@link BasicFileAttributeView}. It may also be used to update + * the permissions, owner, or group-owner as if by invoking the {@link + * #setPermissions setPermissions}, {@link #setOwner setOwner}, and {@link + * #setGroup setGroup} methods respectively. + * + * <h4> Setting Initial Permissions </h4> + * <p> Implementations supporting this attribute view may also support setting + * the initial permissions when creating a file or directory. The + * initial permissions are provided to the {@link Path#createFile createFile} + * or {@link Path#createDirectory createDirectory} methods as a {@link + * FileAttribute} with {@link FileAttribute#name name} {@code "posix:permissions"} + * and a {@link FileAttribute#value value} that is the set of permissions. The + * following example uses the {@link PosixFilePermissions#asFileAttribute + * asFileAttribute} method to construct a {@code FileAttribute} when creating a + * file: + * + * <pre> + * Path path = ... + * Set<PosixFilePermission> perms = + * EnumSet.of(OWNER_READ, OWNER_WRITE, OWNER_EXECUTE, GROUP_READ); + * path.createFile(PosixFilePermissions.asFileAttribute(perms)); + * </pre> + * + * <p> When the access permissions are set at file creation time then the actual + * value of the permissions may differ that the value of the attribute object. + * The reasons for this are implementation specific. On UNIX systems, for + * example, a process has a <em>umask</em> that impacts the permission bits + * of newly created files. Where an implementation supports the setting of + * the access permissions, and the underlying file system supports access + * permissions, then it is required that the value of the actual access + * permissions will be equal or less than the value of the attribute + * provided to the {@link java.nio.file.Path#createFile createFile} or + * {@link java.nio.file.Path#createDirectory createDirectory} methods. In + * other words, the file may be more secure than requested. + * + * @since 1.7 + * + * @see Attributes#readPosixFileAttributes + */ + +public interface PosixFileAttributeView + extends BasicFileAttributeView, FileOwnerAttributeView +{ + /** + * Returns the name of the attribute view. Attribute views of this type + * have the name {@code "posix"}. + */ + @Override + String name(); + + /** + * @throws IOException {@inheritDoc} + * @throws SecurityException + * In the case of the default provider, a security manager is + * installed, and it denies {@link RuntimePermission}<tt>("accessUserInformation")</tt> + * or its {@link SecurityManager#checkRead(String) checkRead} method + * denies read access to the file. + */ + @Override + PosixFileAttributes readAttributes() throws IOException; + + /** + * Updates the file permissions. + * + * @param perms + * the new set of permissions + * + * @throws ClassCastException + * if the sets contains elements that are not of type {@code + * PosixFilePermission} + * @throws IOException + * if an I/O error occurs + * @throws SecurityException + * In the case of the default provider, a security manager is + * installed, and it denies {@link RuntimePermission}<tt>("accessUserInformation")</tt> + * or its {@link SecurityManager#checkWrite(String) checkWrite} + * method denies write access to the file. + */ + void setPermissions(Set<PosixFilePermission> perms) throws IOException; + + /** + * Updates the file group-owner. + * + * @param group + * the new file group-owner + * + * @throws IOException + * if an I/O error occurs + * @throws SecurityException + * In the case of the default provider, and a security manager is + * installed, it denies {@link RuntimePermission}<tt>("accessUserInformation")</tt> + * or its {@link SecurityManager#checkWrite(String) checkWrite} + * method denies write access to the file. + */ + void setGroup(GroupPrincipal group) throws IOException; +} diff --git a/src/share/classes/java/nio/file/attribute/PosixFileAttributes.java b/src/share/classes/java/nio/file/attribute/PosixFileAttributes.java new file mode 100644 index 0000000000000000000000000000000000000000..c09aa9db37cb75af73949b5e1748bcede65f8821 --- /dev/null +++ b/src/share/classes/java/nio/file/attribute/PosixFileAttributes.java @@ -0,0 +1,77 @@ +/* + * Copyright 2007-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 java.nio.file.attribute; + +import java.util.Set; + +/** + * File attributes associated with files on file systems used by operating systems + * that implement the Portable Operating System Interface (POSIX) family of + * standards. + * + * <p> The POSIX attributes of a file are retrieved using a {@link + * PosixFileAttributeView} by invoking its {@link + * PosixFileAttributeView#readAttributes readAttributes} method. + * + * @since 1.7 + * + * @see Attributes#readPosixFileAttributes + */ + +public interface PosixFileAttributes + extends BasicFileAttributes +{ + /** + * Returns the owner of the file. + * + * @return the file owner + * + * @see PosixFileAttributeView#setOwner + */ + UserPrincipal owner(); + + /** + * Returns the group owner of the file. + * + * @return the file group owner + * + * @see PosixFileAttributeView#setGroup + */ + GroupPrincipal group(); + + /** + * Returns the permissions of the file. The file permissions are returned + * as a set of {@link PosixFilePermission} elements. The returned set is a + * copy of the file permissions and is modifiable. This allows the result + * to be modified and passed to the {@link PosixFileAttributeView#setPermissions + * setPermissions} method to update the file's permissions. + * + * @return the file permissions + * + * @see PosixFileAttributeView#setPermissions + */ + Set<PosixFilePermission> permissions(); +} diff --git a/src/share/classes/java/nio/file/attribute/PosixFilePermission.java b/src/share/classes/java/nio/file/attribute/PosixFilePermission.java new file mode 100644 index 0000000000000000000000000000000000000000..795f509940890bc75b9935ef08753c522dbd92b6 --- /dev/null +++ b/src/share/classes/java/nio/file/attribute/PosixFilePermission.java @@ -0,0 +1,86 @@ +/* + * Copyright 2007-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 java.nio.file.attribute; + +import java.util.*; + +/** + * Defines the bits for use with the {@link PosixFileAttributes#permissions() + * permissions} attribute. + * + * <p> The {@link PosixFileAttributes} class defines method methods for + * manipulating {@link Set sets} of permissions. + * + * @since 1.7 + */ + +public enum PosixFilePermission { + + /** + * Read permission, owner. + */ + OWNER_READ, + + /** + * Write permission, owner. + */ + OWNER_WRITE, + + /** + * Execute/search permission, owner. + */ + OWNER_EXECUTE, + + /** + * Read permission, group. + */ + GROUP_READ, + + /** + * Write permission, group. + */ + GROUP_WRITE, + + /** + * Execute/search permission, group. + */ + GROUP_EXECUTE, + + /** + * Read permission, others. + */ + OTHERS_READ, + + /** + * Write permission, others. + */ + OTHERS_WRITE, + + /** + * Execute/search permission, others. + */ + OTHERS_EXECUTE; +} diff --git a/src/share/classes/java/nio/file/attribute/PosixFilePermissions.java b/src/share/classes/java/nio/file/attribute/PosixFilePermissions.java new file mode 100644 index 0000000000000000000000000000000000000000..97d322c6a59ca4888b9aaf1d77a86e96a13a44e5 --- /dev/null +++ b/src/share/classes/java/nio/file/attribute/PosixFilePermissions.java @@ -0,0 +1,180 @@ +/* + * Copyright 2007-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 java.nio.file.attribute; + +import static java.nio.file.attribute.PosixFilePermission.*; +import java.util.*; + +/** + * This class consists exclusively of static methods that operate on sets of + * {@link PosixFilePermission} objects. + * + * @since 1.7 + */ + +public class PosixFilePermissions { + private PosixFilePermissions() { } + + // Write string representation of permission bits to {@code sb}. + private static void writeBits(StringBuilder sb, boolean r, boolean w, boolean x) { + if (r) { + sb.append('r'); + } else { + sb.append('-'); + } + if (w) { + sb.append('w'); + } else { + sb.append('-'); + } + if (x) { + sb.append('x'); + } else { + sb.append('-'); + } + } + + /** + * Returns the {@code String} representation of a set of permissions. + * + * <p> If the set contains {@code null} or elements that are not of type + * {@code PosixFilePermission} then these elements are ignored. + * + * @param perms + * the set of permissions + * + * @return the string representation of the permission set + * + * @see #fromString + */ + public static String toString(Set<PosixFilePermission> perms) { + StringBuilder sb = new StringBuilder(9); + writeBits(sb, perms.contains(OWNER_READ), perms.contains(OWNER_WRITE), + perms.contains(OWNER_EXECUTE)); + writeBits(sb, perms.contains(GROUP_READ), perms.contains(GROUP_WRITE), + perms.contains(GROUP_EXECUTE)); + writeBits(sb, perms.contains(OTHERS_READ), perms.contains(OTHERS_WRITE), + perms.contains(OTHERS_EXECUTE)); + return sb.toString(); + } + + private static boolean isSet(char c, char setValue) { + if (c == setValue) + return true; + if (c == '-') + return false; + throw new IllegalArgumentException("Invalid mode"); + } + private static boolean isR(char c) { return isSet(c, 'r'); } + private static boolean isW(char c) { return isSet(c, 'w'); } + private static boolean isX(char c) { return isSet(c, 'x'); } + + /** + * Returns the set of permissions corresponding to a given {@code String} + * representation. + * + * <p> The {@code perms} parameter is a {@code String} representing the + * permissions. It has 9 characters that are interpreted as three sets of + * three. The first set refers to the owner's permissions; the next to the + * group permissions and the last to others. Within each set, the first + * character is {@code 'r'} to indicate permission to read, the second + * character is {@code 'w'} to indicate permission to write, and the third + * character is {@code 'x'} for execute permission. Where a permission is + * not set then the corresponding character is set to {@code '-'}. + * + * <p> <b>Usage Example:</b> + * Suppose we require the set of permissions that indicate the owner has read, + * write, and execute permissions, the group has read and execute permissions + * and others have none. + * <pre> + * Set<PosixFilePermission> perms = PosixFilePermissions.fromString("rwxr-x---"); + * </pre> + * + * @param perms + * string representing a set of permissions + * + * @return the resulting set of permissions + * + * @throws IllegalArgumentException + * if the string cannot be converted to a set of permissions + * + * @see #toString(Set) + */ + public static Set<PosixFilePermission> fromString(String perms) { + if (perms.length() != 9) + throw new IllegalArgumentException("Invalid mode"); + Set<PosixFilePermission> result = new HashSet<PosixFilePermission>(); + if (isR(perms.charAt(0))) result.add(OWNER_READ); + if (isW(perms.charAt(1))) result.add(OWNER_WRITE); + if (isX(perms.charAt(2))) result.add(OWNER_EXECUTE); + if (isR(perms.charAt(3))) result.add(GROUP_READ); + if (isW(perms.charAt(4))) result.add(GROUP_WRITE); + if (isX(perms.charAt(5))) result.add(GROUP_EXECUTE); + if (isR(perms.charAt(6))) result.add(OTHERS_READ); + if (isW(perms.charAt(7))) result.add(OTHERS_WRITE); + if (isX(perms.charAt(8))) result.add(OTHERS_EXECUTE); + return result; + } + + /** + * Creates a {@link FileAttribute}, encapsulating a copy of the given file + * permissions, suitable for passing to the {@link java.nio.file.Path#createFile + * createFile} or {@link java.nio.file.Path#createDirectory createDirectory} + * methods. + * + * @param perms + * the set of permissions + * + * @return an attribute encapsulating the given file permissions with + * {@link FileAttribute#name name} {@code "posix:permissions"} + * + * @throws ClassCastException + * if the set contains elements that are not of type {@code + * PosixFilePermission} + */ + public static FileAttribute<Set<PosixFilePermission>> + asFileAttribute(Set<PosixFilePermission> perms) + { + // copy set and check for nulls (CCE will be thrown if an element is not + // a PosixFilePermission) + perms = new HashSet<PosixFilePermission>(perms); + for (PosixFilePermission p: perms) { + if (p == null) + throw new NullPointerException(); + } + final Set<PosixFilePermission> value = perms; + return new FileAttribute<Set<PosixFilePermission>>() { + @Override + public String name() { + return "posix:permissions"; + } + @Override + public Set<PosixFilePermission> value() { + return Collections.unmodifiableSet(value); + } + }; + } +} diff --git a/src/share/classes/java/nio/file/attribute/UserDefinedFileAttributeView.java b/src/share/classes/java/nio/file/attribute/UserDefinedFileAttributeView.java new file mode 100644 index 0000000000000000000000000000000000000000..c0b6896011a6c492764574a121bb36922da266ab --- /dev/null +++ b/src/share/classes/java/nio/file/attribute/UserDefinedFileAttributeView.java @@ -0,0 +1,232 @@ +/* + * Copyright 2007-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 java.nio.file.attribute; + +import java.nio.ByteBuffer; +import java.util.List; +import java.io.IOException; + +/** + * A file attribute view that provides a view of a file's user-defined + * attributes, sometimes known as <em>extended attributes</em>. User-defined + * file attributes are used to store metadata with a file that is not meaningful + * to the file system. It is primarily intended for file system implementations + * that support such a capability directly but may be emulated. The details of + * such emulation are highly implementation specific and therefore not specified. + * + * <p> This {@code FileAttributeView} provides a view of a file's user-defined + * attributes as a set of name/value pairs, where the attribute name is + * represented by a {@code String}. An implementation may require to encode and + * decode from the platform or file system representation when accessing the + * attribute. The value has opaque content. This attribute view defines the + * {@link #read read} and {@link #write write} methods to read the value into + * or write from a {@link ByteBuffer}. This {@code FileAttributeView} is not + * intended for use where the size of an attribute value is larger than {@link + * Integer#MAX_VALUE}. + * + * <p> User-defined attributes may be used in some implementations to store + * security related attributes so consequently, in the case of the default + * provider at least, all methods that access user-defined attributes require the + * {@code RuntimePermission("accessUserDefinedAttributes")} permission when a + * security manager is installed. + * + * <p> The {@link java.nio.file.FileStore#supportsFileAttributeView + * supportsFileAttributeView} method may be used to test if a specific {@link + * java.nio.file.FileStore FileStore} supports the storage of user-defined + * attributes. + * + * <p> Where dynamic access to file attributes is required, the {@link + * #getAttribute getAttribute} or {@link #readAttributes(String,String[]) + * readAttributes(String,String[])} methods may be used to read the attribute + * value. The attribute value is returned as a byte array (byte[]). The {@link + * #setAttribute setAttribute} method may be used to write the value of a + * user-defined attribute from a buffer (as if by invoking the {@link #write + * write} method), or byte array (byte[]). + * + * @since 1.7 + */ + +public interface UserDefinedFileAttributeView + extends FileAttributeView +{ + /** + * Returns the name of this attribute view. Attribute views of this type + * have the name {@code "xattr"}. + */ + @Override + String name(); + + /** + * Returns a list containing the names of the user-defined attributes. + * + * @return An unmodifiable list continaing the names of the file's + * user-defined + * + * @throws IOException + * If an I/O error occurs + * @throws SecurityException + * In the case of the default provider, a security manager is + * installed, and it denies {@link + * RuntimePermission}<tt>("accessUserDefinedAttributes")</tt> + * or its {@link SecurityManager#checkRead(String) checkRead} method + * denies read access to the file. + */ + List<String> list() throws IOException; + + /** + * Returns the size of the value of a user-defined attribute. + * + * @param name + * The attribute name + * + * @return The size of the attribute value, in bytes. + * + * @throws ArithmeticException + * If the size of the attribute is larger than {@link Integer#MAX_VALUE} + * @throws IOException + * If an I/O error occurs + * @throws SecurityException + * In the case of the default provider, a security manager is + * installed, and it denies {@link + * RuntimePermission}<tt>("accessUserDefinedAttributes")</tt> + * or its {@link SecurityManager#checkRead(String) checkRead} method + * denies read access to the file. + */ + int size(String name) throws IOException; + + /** + * Read the value of a user-defined attribute into a buffer. + * + * <p> This method reads the value of the attribute into the given buffer + * as a sequence of bytes, failing if the number of bytes remaining in + * the buffer is insufficient to read the complete attribute value. The + * number of bytes transferred into the buffer is {@code n}, where {@code n} + * is the size of the attribute value. The first byte in the sequence is at + * index {@code p} and the last byte is at index {@code p + n - 1}, where + * {@code p} is the buffer's position. Upon return the buffer's position + * will be equal to {@code p + n}; its limit will not have changed. + * + * <p> <b>Usage Example:</b> + * Suppose we want to read a file's MIME type that is stored as a user-defined + * attribute with the name "{@code user.mimetype}". + * <pre> + * UserDefinedFileAttributeView view = file + * .getFileAttributeView(UserDefinedFileAttributeView.class); + * String name = "user.mimetype"; + * ByteBuffer buf = ByteBuffer.allocate(view.size(name)); + * view.read(name, buf); + * buf.flip(); + * String value = Charset.defaultCharset().decode(buf).toString(); + * </pre> + * + * @param name + * The attribute name + * @param dst + * The destination buffer + * + * @return The number of bytes read, possibly zero + * + * @throws IllegalArgumentException + * If the destination buffer is read-only + * @throws IOException + * If an I/O error occurs or there is insufficient space in the + * destination buffer for the attribute value + * @throws SecurityException + * In the case of the default provider, a security manager is + * installed, and it denies {@link + * RuntimePermission}<tt>("accessUserDefinedAttributes")</tt> + * or its {@link SecurityManager#checkRead(String) checkRead} method + * denies read access to the file. + * + * @see #size + */ + int read(String name, ByteBuffer dst) throws IOException; + + /** + * Writes the value of a user-defined attribute from a buffer. + * + * <p> This method writes the value of the attribute from a given buffer as + * a sequence of bytes. The size of the value to transfer is {@code r}, + * where {@code r} is the number of bytes remaining in the buffer, that is + * {@code src.remaining()}. The sequence of bytes is transferred from the + * buffer starting at index {@code p}, where {@code p} is the buffer's + * position. Upon return, the buffer's position will be equal to {@code + * p + n}, where {@code n} is the number of bytes transferred; its limit + * will not have changed. + * + * <p> If an attribute of the given name already exists then its value is + * replaced. If the attribute does not exist then it is created. If it + * implementation specific if a test to check for the existence of the + * attribute and the creation of attribute are atomic with repect to other + * file system activities. + * + * <p> Where there is insufficient space to store the attribute, or the + * attribute name or value exceed an implementation specific maximum size + * then an {@code IOException} is thrown. + * + * <p> <b>Usage Example:</b> + * Suppose we want to write a file's MIME type as a user-defined attribute: + * <pre> + * UserDefinedFileAttributeView view = file + * .getFileAttributeView(UserDefinedFileAttributeView.class); + * view.write("user.mimetype", Charset.defaultCharset().encode("text/html")); + * </pre> + * + * @param name + * The attribute name + * @param src + * The buffer containing the attribute value + * + * @return The number of bytes written, possibly zero + * + * @throws IOException + * If an I/O error occurs + * @throws SecurityException + * In the case of the default provider, a security manager is + * installed, and it denies {@link + * RuntimePermission}<tt>("accessUserDefinedAttributes")</tt> + * or its {@link SecurityManager#checkWrite(String) checkWrite} + * method denies write access to the file. + */ + int write(String name, ByteBuffer src) throws IOException; + + /** + * Deletes a user-defined attribute. + * + * @param name + * The attribute name + * + * @throws IOException + * If an I/O error occurs or the attribute does not exist + * @throws SecurityException + * In the case of the default provider, a security manager is + * installed, and it denies {@link + * RuntimePermission}<tt>("accessUserDefinedAttributes")</tt> + * or its {@link SecurityManager#checkWrite(String) checkWrite} + * method denies write access to the file. + */ + void delete(String name) throws IOException; +} diff --git a/src/share/classes/java/nio/file/attribute/UserPrincipal.java b/src/share/classes/java/nio/file/attribute/UserPrincipal.java new file mode 100644 index 0000000000000000000000000000000000000000..edb04fc6f3b6f86110330a81fb49512cd7c12d75 --- /dev/null +++ b/src/share/classes/java/nio/file/attribute/UserPrincipal.java @@ -0,0 +1,54 @@ +/* + * Copyright 2007-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 java.nio.file.attribute; + +import java.security.Principal; + +/** + * A {@code Principal} representing an identity used to determine access rights + * to objects in a file system. + * + * <p> On many platforms and file systems an entity requires appropriate access + * rights or permissions in order to access objects in a file system. The + * access rights are generally performed by checking the identity of the entity. + * For example, on implementations that use Access Control Lists (ACLs) to + * enforce privilege separation then a file in the file system may have an + * associated ACL that determines the access rights of identities specified in + * the ACL. + * + * <p> A {@code UserPrincipal} object is an abstract representation of an + * identity. It has a {@link #getName() name} that is typically the username or + * account name that it represents. User principal objects may be obtained using + * a {@link UserPrincipalLookupService}, or returned by {@link + * FileAttributeView} implementations that provide access to identity related + * attributes. For example, the {@link AclFileAttributeView} and {@link + * PosixFileAttributeView} provide access to a file's {@link + * PosixFileAttributes#owner owner}. + * + * @since 1.7 + */ + +public interface UserPrincipal extends Principal { } diff --git a/src/share/classes/java/nio/file/attribute/UserPrincipalLookupService.java b/src/share/classes/java/nio/file/attribute/UserPrincipalLookupService.java new file mode 100644 index 0000000000000000000000000000000000000000..ba74882ce6741b8b21fcae3480a3cc6b2d4edcf3 --- /dev/null +++ b/src/share/classes/java/nio/file/attribute/UserPrincipalLookupService.java @@ -0,0 +1,104 @@ +/* + * Copyright 2007-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 java.nio.file.attribute; + +import java.io.IOException; + +/** + * An object to lookup user and group principals by name. A {@link UserPrincipal} + * represents an identity that may be used to determine access rights to objects + * in a file system. A {@link GroupPrincipal} represents a <em>group identity</em>. + * A {@code UserPrincipalLookupService} defines methods to lookup identities by + * name or group name (which are typically user or account names). Whether names + * and group names are case sensitive or not depends on the implementation. + * The exact definition of a group is implementation specific but typically a + * group represents an identity created for administrative purposes so as to + * determine the access rights for the members of the group. In particular it is + * implementation specific if the <em>namespace</em> for names and groups is the + * same or is distinct. To ensure consistent and correct behavior across + * platforms it is recommended that this API be used as if the namespaces are + * distinct. In other words, the {@link #lookupPrincipalByName + * lookupPrincipalByName} should be used to lookup users, and {@link + * #lookupPrincipalByGroupName lookupPrincipalByGroupName} should be used to + * lookup groups. + * + * @since 1.7 + * + * @see java.nio.file.FileSystem#getUserPrincipalLookupService + */ + +public abstract class UserPrincipalLookupService { + + /** + * Initializes a new instance of this class. + */ + protected UserPrincipalLookupService() { + } + + /** + * Lookup a user principal by name. + * + * @param name + * the string representation of the user principal to lookup + * + * @return a user principal + * + * @throws UserPrincipalNotFoundException + * the principal does not exist + * @throws IOException + * if an I/O error occurs + * @throws SecurityException + * In the case of the default provider, and a security manager is + * installed, it checks {@link RuntimePermission}<tt>("lookupUserInformation")</tt> + */ + public abstract UserPrincipal lookupPrincipalByName(String name) + throws IOException; + + /** + * Lookup a group principal by group name. + * + * <p> Where an implementation does not support any notion of group then + * this method always throws {@link UserPrincipalNotFoundException}. Where + * the namespace for user accounts and groups is the same, then this method + * is identical to invoking {@link #lookupPrincipalByName + * lookupPrincipalByName}. + * + * @param group + * the string representation of the group to lookup + * + * @return a user principal + * + * @throws UserPrincipalNotFoundException + * the principal does not exist or is not a group + * @throws IOException + * if an I/O error occurs + * @throws SecurityException + * In the case of the default provider, and a security manager is + * installed, it checks {@link RuntimePermission}<tt>("lookupUserInformation")</tt> + */ + public abstract GroupPrincipal lookupPrincipalByGroupName(String group) + throws IOException; +} diff --git a/src/share/classes/java/nio/file/attribute/UserPrincipalNotFoundException.java b/src/share/classes/java/nio/file/attribute/UserPrincipalNotFoundException.java new file mode 100644 index 0000000000000000000000000000000000000000..94cc88ba20aabfd3f2db1c9eab37e4865bb53dc3 --- /dev/null +++ b/src/share/classes/java/nio/file/attribute/UserPrincipalNotFoundException.java @@ -0,0 +1,64 @@ +/* + * Copyright 2007-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 java.nio.file.attribute; + +import java.io.IOException; + +/** + * Checked exception thrown when a lookup of {@link UserPrincipal} fails because + * the principal does not exist. + * + * @since 1.7 + */ + +public class UserPrincipalNotFoundException + extends IOException +{ + static final long serialVersionUID = -5369283889045833024L; + + private final String name; + + /** + * Constructs an instance of this class. + * + * @param name + * the principal name; may be {@code null} + */ + public UserPrincipalNotFoundException(String name) { + super(); + this.name = name; + } + + /** + * Returns the user principal name if this exception was created with the + * user principal name that was not found, otherwise <tt>null</tt>. + * + * @return the user principal name or {@code null} + */ + public String getName() { + return name; + } +} diff --git a/src/share/classes/java/nio/file/attribute/package-info.java b/src/share/classes/java/nio/file/attribute/package-info.java new file mode 100644 index 0000000000000000000000000000000000000000..c5301b1f840beb97ef599c1b49b7f3e553e015ca --- /dev/null +++ b/src/share/classes/java/nio/file/attribute/package-info.java @@ -0,0 +1,119 @@ +/* + * Copyright 2007-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. + */ + +/** + * Interfaces and classes providing access to file and file system attributes. + * + * <blockquote><table cellspacing=1 cellpadding=0 summary="Attribute views"> + * <tr><th><p align="left">Attribute views</p></th><th><p align="left">Description</p></th></tr> + * <tr><td valign=top><tt><i>{@link java.nio.file.attribute.AttributeView}</i></tt></td> + * <td>Can read or update non-opaque values associated with objects in a file system</td></tr> + * <tr><td valign=top><tt>  <i>{@link java.nio.file.attribute.FileAttributeView}</i></tt></td> + * <td>Can read or update file attributes</td></tr> + * <tr><td valign=top><tt>    <i>{@link java.nio.file.attribute.BasicFileAttributeView}  </i></tt></td> + * <td>Can read or update a basic set of file attributes</td></tr> + * <tr><td valign=top><tt>      <i>{@link java.nio.file.attribute.PosixFileAttributeView}  </i></tt></td> + * <td>Can read or update POSIX defined file attributes</td></tr> + * <tr><td valign=top><tt>      <i>{@link java.nio.file.attribute.DosFileAttributeView}  </i></tt></td> + * <td>Can read or update FAT file attributes</td></tr> + * <tr><td valign=top><tt>    <i>{@link java.nio.file.attribute.FileOwnerAttributeView}  </i></tt></td> + * <td>Can read or update the owner of a file</td></tr> + * <tr><td valign=top><tt>     <i>{@link java.nio.file.attribute.AclFileAttributeView}  </i></tt></td> + * <td>Can read or update Access Control Lists</td></tr> + * <tr><td valign=top><tt>    <i>{@link java.nio.file.attribute.UserDefinedFileAttributeView}  </i></tt></td> + * <td>Can read or update user-defined file attributes</td></tr> + * <tr><td valign=top><tt>  <i>{@link java.nio.file.attribute.FileStoreAttributeView}</i></tt></td> + * <td>Can read or update file system attributes</td></tr> + * <tr><td valign=top><tt>    <i>{@link java.nio.file.attribute.FileStoreSpaceAttributeView}  </i></tt></td> + * <td>Can read file system <em>space usage</em> related attributes</td></tr> + * </table></blockquote> + * + * <p> An attribute view provides a read-only or updatable view of the non-opaque + * values, or <em>metadata</em>, associated with objects in a file system. + * The {@link java.nio.file.attribute.FileAttributeView} interface is + * extended by several other interfaces that that views to specific sets of file + * attributes. {@code FileAttributeViews} are selected by invoking the {@link + * java.nio.file.FileRef#getFileAttributeView} method with a + * <em>type-token</em> to identify the required view. Views can also be identified + * by name. The {@link java.nio.file.attribute.FileStoreAttributeView} interface + * provides access to file store attributes. A {@code FileStoreAttributeView} of + * a given type is obtained by invoking the {@link + * java.nio.file.FileStore#getFileStoreAttributeView} method. + * + * <p> The {@link java.nio.file.attribute.BasicFileAttributeView} + * class defines methods to read and update a <em>basic</em> set of file + * attributes that are common to many file systems. + * + * <p> The {@link java.nio.file.attribute.PosixFileAttributeView} + * interface extends {@code BasicFileAttributeView} by defining methods + * to access the file attributes commonly used by file systems and operating systems + * that implement the Portable Operating System Interface (POSIX) family of + * standards. + * + * <p> The {@link java.nio.file.attribute.DosFileAttributeView} + * class extends {@code BasicFileAttributeView} by defining methods to + * access the legacy "DOS" file attributes supported on file systems such as File + * Allocation Tabl (FAT), commonly used in consumer devices. + * + * <p> The {@link java.nio.file.attribute.AclFileAttributeView} + * class defines methods to read and write the Access Control List (ACL) + * file attribute. The ACL model used by this file attribute view is based + * on the model defined by <a href="http://www.ietf.org/rfc/rfc3530.txt"> + * <i>RFC 3530: Network File System (NFS) version 4 Protocol</i></a>. + * + * <p> The {@link java.nio.file.attribute.FileStoreSpaceAttributeView} class + * defines methods to read file system space usage related attributes of a file system. + * + * <p> The {@link java.nio.file.attribute.Attributes} utility class defines + * static methods to access file or file system attribute using the above + * attribute views. + * + * <p> In addition to attribute views, this package also defines classes and + * interfaces that are used when accessing attributes: + * + * <ul> + * + * <p><li> The {@link java.nio.file.attribute.UserPrincipal} and + * {@link java.nio.file.attribute.GroupPrincipal} interfaces represent an + * identity or group identity. </li> + * + * <p><li> The {@link java.nio.file.attribute.UserPrincipalLookupService} + * interface defines methods to lookup user or group principals. </li> + * + * <p><li> The {@link java.nio.file.attribute.Attribute} interface + * 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> + * + * </ul> + * + * + * <p> Unless otherwise noted, passing a <tt>null</tt> argument to a constructor + * or method in any class or interface in this package will cause a {@link + * java.lang.NullPointerException NullPointerException} to be thrown. + * + * @since 1.7 + */ + +package java.nio.file.attribute; diff --git a/src/share/classes/java/nio/file/package-info.java b/src/share/classes/java/nio/file/package-info.java new file mode 100644 index 0000000000000000000000000000000000000000..3623ebe12cd526a5bbc563836e616cd1c0d4043f --- /dev/null +++ b/src/share/classes/java/nio/file/package-info.java @@ -0,0 +1,116 @@ +/* + * Copyright 2007-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. + */ + +/** + * Defines interfaces and classes for the Java virtual machine to access files, + * file attributes, and file systems. + * + * <p> The java.nio.file package defines classes to access files and file + * systems. The API to access file and file system attributes is defined in the + * {@link java.nio.file.attribute} package. The {@link java.nio.file.spi} + * package is used by service provider implementors wishing to extend the + * platform default provider, or to construct other provider implementations. + * + * <a name="links"><h3>Symbolic Links</h3></a> + * Many operating systems and file systems support for <em>symbolic links</em>. + * A symbolic link is a special file that serves as a reference to another file. + * For the most part, symbolic links are transparent to applications and + * operations on symbolic links are automatically redirected to the <em>target</em> + * of the link. Exceptions to this are when a symbolic link is deleted or + * renamed/moved in which case the link is deleted or removed rather than the + * target of the link. This package includes support for symbolic links where + * implementations provide these semantics. File systems may support other types + * that are semantically close but support for these other types of links is + * not included in this package. + * + * <a name="interop"><h3>Interoperability</h3></a> + * The {@link java.io.File} class defines the {@link java.io.File#toPath + * toPath} method to construct a {@link java.nio.file.Path} by converting + * the abstract path represented by the {@code java.io.File} object. The resulting + * {@code Path} can be used to operate on the same file as the {@code File} + * object. The {@code Path} specification provides further information + * on the <a href="Path.html#interop">interoperability</a> between {@code Path} + * and {@code java.io.File} objects. + * + * <h3>Visibility</h3> + * The view of the files and file system provided by classes in this package are + * guaranteed to be consistent with other views provided by other instances in the + * same Java virtual machine. The view may or may not, however, be consistent with + * the view of the file system as seen by other concurrently running programs due + * to caching performed by the underlying operating system and delays induced by + * network-filesystem protocols. This is true regardless of the language in which + * these other programs are written, and whether they are running on the same machine + * or on some other machine. The exact nature of any such inconsistencies are + * system-dependent and are therefore unspecified. + * + * <a name="integrity"><h3>Synchronized I/O File Integrity</h3></a> + * The {@link java.nio.file.StandardOpenOption#SYNC SYNC} and {@link + * java.nio.file.StandardOpenOption#DSYNC DSYNC} options are used when opening a file + * to require that updates to the file are written synchronously to the underlying + * storage device. In the case of the default provider, and the file resides on + * a local storage device, and the {@link java.nio.channels.SeekableByteChannel + * seekable} channel is connected to a file that was opened with one of these + * options, then an invocation of the {@link + * java.nio.channels.WritableByteChannel#write(java.nio.ByteBuffer) write} + * method is only guaranteed to return when all changes made to the file + * by that invocation have been written to the device. These options are useful + * for ensuring that critical information is not lost in the event of a system + * crash. If the file does not reside on a local device then no such guarantee + * is made. Whether this guarantee is possible with other {@link + * java.nio.file.spi.FileSystemProvider provider} implementations is provider + * specific. + * + * <h3>General Exceptions</h3> + * Unless otherwise noted, passing a {@code null} argument to a constructor + * or method of any class or interface in this package will cause a {@link + * java.lang.NullPointerException NullPointerException} to be thrown. Additionally, + * invoking a method with a collection containing a {@code null} element will + * cause a {@code NullPointerException}, unless otherwise specified. + * + * <p> Unless otherwise noted, methods that attempt to access the file system + * will throw {@link java.nio.file.ClosedFileSystemException} when invoked on + * objects associated with a {@link java.nio.file.FileSystem} that has been + * {@link java.nio.file.FileSystem#close closed}. Additionally, any methods + * that attempt write access to a file system will throw {@link + * java.nio.file.ReadOnlyFileSystemException} when invoked on an object associated + * with a {@link java.nio.file.FileSystem} that only provides read-only access. + * + * <p> Unless otherwise noted, invoking a method of any class or interface in + * this package created by one {@link java.nio.file.spi.FileSystemProvider + * provider} with a parameter that is an object created by another provider, + * will throw {@link java.nio.file.ProviderMismatchException}. + * + * <h3>Optional Specific Exceptions</h3> + * Most of the methods defined by classes in this package that access the + * file system specify that {@link java.io.IOException} be thrown when an I/O + * error occurs. In some cases, these methods define specific I/O exceptions + * for common cases. These exceptions, noted as <i>optional specific exceptions</i>, + * are thrown by the implementation where it can detect the specific error. + * Where the specific error cannot be detected then the more general {@code + * IOException} is thrown. + * + * @since 1.7 + */ +package java.nio.file; diff --git a/src/share/classes/java/nio/file/spi/AbstractPath.java b/src/share/classes/java/nio/file/spi/AbstractPath.java new file mode 100644 index 0000000000000000000000000000000000000000..133411e3bf818b3ed8310d66277f86973fe3d97b --- /dev/null +++ b/src/share/classes/java/nio/file/spi/AbstractPath.java @@ -0,0 +1,568 @@ +/* + * Copyright 2007-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 java.nio.file.spi; + +import java.nio.file.*; +import static java.nio.file.StandardOpenOption.*; +import java.nio.file.attribute.*; +import java.nio.channels.*; +import java.nio.ByteBuffer; +import java.io.*; +import java.util.*; + +/** + * Base implementation class for a {@code Path}. + * + * <p> This class is intended to be extended by provider implementors. It + * implements, or provides default implementations for several of the methods + * defined by the {@code Path} class. It implements the {@link #copyTo copyTo} + * and {@link #moveTo moveTo} methods for the case that the source and target + * are not associated with the same provider. + * + * @since 1.7 + */ + +public abstract class AbstractPath extends Path { + + /** + * Initializes a new instance of this class. + */ + protected AbstractPath() { } + + /** + * Deletes the file referenced by this object. + * + * <p> This method invokes the {@link #delete(boolean) delete(boolean)} + * method with a parameter of {@code true}. It may be overridden where + * required. + * + * @throws NoSuchFileException {@inheritDoc} + * @throws DirectoryNotEmptyException {@inheritDoc} + * @throws IOException {@inheritDoc} + * @throws SecurityException {@inheritDoc} + */ + @Override + public void delete() throws IOException { + delete(true); + } + + /** + * Creates a new and empty file, failing if the file already exists. + * + * <p> This method invokes the {@link #newByteChannel(Set,FileAttribute[]) + * newByteChannel(Set,FileAttribute...)} method to create the file. It may be + * overridden where required. + * + * @throws IllegalArgumentException {@inheritDoc} + * @throws FileAlreadyExistsException {@inheritDoc} + * @throws IOException {@inheritDoc} + * @throws SecurityException {@inheritDoc} + */ + @Override + public Path createFile(FileAttribute<?>... attrs) + throws IOException + { + EnumSet<StandardOpenOption> options = EnumSet.of(CREATE_NEW, WRITE); + SeekableByteChannel sbc = newByteChannel(options, attrs); + try { + sbc.close(); + } catch (IOException x) { + // ignore + } + return this; + } + + /** + * Opens or creates a file, returning a seekable byte channel to access the + * file. + * + * <p> This method invokes the {@link #newByteChannel(Set,FileAttribute[]) + * newByteChannel(Set,FileAttribute...)} method to open or create the file. + * It may be overridden where required. + * + * @throws IllegalArgumentException {@inheritDoc} + * @throws FileAlreadyExistsException {@inheritDoc} + * @throws IOException {@inheritDoc} + * @throws SecurityException {@inheritDoc} + */ + @Override + public SeekableByteChannel newByteChannel(OpenOption... options) + throws IOException + { + Set<OpenOption> set = new HashSet<OpenOption>(options.length); + Collections.addAll(set, options); + return newByteChannel(set); + } + + /** + * Opens the file located by this path for reading, returning an input + * stream to read bytes from the file. + * + * <p> This method returns an {@code InputStream} that is constructed by + * invoking the {@link java.nio.channels.Channels#newInputStream + * Channels.newInputStream} method. It may be overridden where a more + * efficient implementation is available. + * + * @throws IOException {@inheritDoc} + * @throws SecurityException {@inheritDoc} + */ + @Override + public InputStream newInputStream() throws IOException { + return Channels.newInputStream(newByteChannel()); + } + + // opts must be modifiable + private OutputStream implNewOutputStream(Set<OpenOption> opts, + FileAttribute<?>... attrs) + throws IOException + { + if (opts.isEmpty()) { + opts.add(CREATE); + opts.add(TRUNCATE_EXISTING); + } else { + if (opts.contains(READ)) + throw new IllegalArgumentException("READ not allowed"); + } + opts.add(WRITE); + return Channels.newOutputStream(newByteChannel(opts, attrs)); + } + + /** + * Opens or creates the file located by this path for writing, returning an + * output stream to write bytes to the file. + * + * <p> This method returns an {@code OutputStream} that is constructed by + * invoking the {@link java.nio.channels.Channels#newOutputStream + * Channels.newOutputStream} method. It may be overridden where a more + * efficient implementation is available. + * + * @throws IllegalArgumentException {@inheritDoc} + * @throws IOException {@inheritDoc} + * @throws SecurityException {@inheritDoc} + */ + @Override + public OutputStream newOutputStream(OpenOption... options) throws IOException { + int len = options.length; + Set<OpenOption> opts = new HashSet<OpenOption>(len + 3); + if (len > 0) { + for (OpenOption opt: options) { + opts.add(opt); + } + } + return implNewOutputStream(opts); + } + + /** + * Opens or creates the file located by this path for writing, returning an + * output stream to write bytes to the file. + * + * <p> This method returns an {@code OutputStream} that is constructed by + * invoking the {@link java.nio.channels.Channels#newOutputStream + * Channels.newOutputStream} method. It may be overridden where a more + * efficient implementation is available. + * + * @throws IllegalArgumentException {@inheritDoc} + * @throws IOException {@inheritDoc} + * @throws SecurityException {@inheritDoc} + */ + @Override + public OutputStream newOutputStream(Set<? extends OpenOption> options, + FileAttribute<?>... attrs) + throws IOException + { + Set<OpenOption> opts = new HashSet<OpenOption>(options); + return implNewOutputStream(opts, attrs); + } + + /** + * Opens the directory referenced by this object, returning a {@code + * DirectoryStream} to iterate over all entries in the directory. + * + * <p> This method invokes the {@link + * #newDirectoryStream(java.nio.file.DirectoryStream.Filter) + * newDirectoryStream(Filter)} method with a filter that accept all entries. + * It may be overridden where required. + * + * @throws NotDirectoryException {@inheritDoc} + * @throws IOException {@inheritDoc} + * @throws SecurityException {@inheritDoc} + */ + @Override + public DirectoryStream<Path> newDirectoryStream() throws IOException { + return newDirectoryStream(acceptAllFilter); + } + private static final DirectoryStream.Filter<Path> acceptAllFilter = + new DirectoryStream.Filter<Path>() { + @Override public boolean accept(Path entry) { return true; } + }; + + /** + * Opens the directory referenced by this object, returning a {@code + * DirectoryStream} to iterate over the entries in the directory. The + * entries are filtered by matching the {@code String} representation of + * their file names against a given pattern. + * + * <p> This method constructs a {@link PathMatcher} by invoking the + * file system's {@link java.nio.file.FileSystem#getPathMatcher + * getPathMatcher} method. This method may be overridden where a more + * efficient implementation is available. + * + * @throws java.util.regex.PatternSyntaxException {@inheritDoc} + * @throws UnsupportedOperationException {@inheritDoc} + * @throws NotDirectoryException {@inheritDoc} + * @throws IOException {@inheritDoc} + * @throws SecurityException {@inheritDoc} + */ + @Override + public DirectoryStream<Path> newDirectoryStream(String glob) + throws IOException + { + // avoid creating a matcher if all entries are required. + if (glob.equals("*")) + return newDirectoryStream(); + + // create a matcher and return a filter that uses it. + final PathMatcher matcher = getFileSystem().getPathMatcher("glob:" + glob); + DirectoryStream.Filter<Path> filter = new DirectoryStream.Filter<Path>() { + @Override + public boolean accept(Path entry) { + return matcher.matches(entry.getName()); + } + }; + return newDirectoryStream(filter); + } + + /** + * Tests whether the file located by this path exists. + * + * <p> This method invokes the {@link #checkAccess checkAccess} method to + * check if the file exists. It may be overridden where a more efficient + * implementation is available. + */ + @Override + public boolean exists() { + try { + checkAccess(); + return true; + } catch (IOException x) { + // unable to determine if file exists + } + return false; + } + + /** + * Tests whether the file located by this path does not exist. + * + * <p> This method invokes the {@link #checkAccess checkAccess} method to + * check if the file exists. It may be overridden where a more efficient + * implementation is available. + */ + @Override + public boolean notExists() { + try { + checkAccess(); + return false; + } catch (NoSuchFileException x) { + // file confirmed not to exist + return true; + } catch (IOException x) { + return false; + } + } + + /** + * Registers the file located by this path with a watch service. + * + * <p> This method invokes the {@link #register(WatchService,WatchEvent.Kind[],WatchEvent.Modifier[]) + * register(WatchService,WatchEvent.Kind[],WatchEvent.Modifier...)} + * method to register the file. It may be overridden where required. + */ + @Override + public WatchKey register(WatchService watcher, WatchEvent.Kind<?>... events) + throws IOException + { + return register(watcher, events, NO_MODIFIERS); + } + private static final WatchEvent.Modifier[] NO_MODIFIERS = new WatchEvent.Modifier[0]; + + /** + * Copy the file located by this path to a target location. + * + * <p> This method is invoked by the {@link #copyTo copyTo} method for + * the case that this {@code Path} and the target {@code Path} are + * associated with the same provider. + * + * @param target + * The target location + * @param options + * Options specifying how the copy should be done + * + * @throws IllegalArgumentException + * If an invalid option is specified + * @throws FileAlreadyExistsException + * The target file exists and cannot be replaced because the + * {@code REPLACE_EXISTING} option is not specified, or the target + * file is a non-empty directory <i>(optional specific exception)</i> + * @throws IOException + * If an I/O error occurs + * @throws SecurityException + * In the case of the default provider, and a security manager is + * installed, the {@link SecurityManager#checkRead(String) checkRead} + * method is invoked to check read access to the source file, the + * {@link SecurityManager#checkWrite(String) checkWrite} is invoked + * to check write access to the target file. If a symbolic link is + * copied the security manager is invoked to check {@link + * LinkPermission}{@code ("symbolic")}. + */ + protected abstract void implCopyTo(Path target, CopyOption... options) + throws IOException; + + /** + * Move the file located by this path to a target location. + * + * <p> This method is invoked by the {@link #moveTo moveTo} method for + * the case that this {@code Path} and the target {@code Path} are + * associated with the same provider. + * + * @param target + * The target location + * @param options + * Options specifying how the move should be done + * + * @throws IllegalArgumentException + * If an invalid option is specified + * @throws FileAlreadyExistsException + * The target file exists and cannot be replaced because the + * {@code REPLACE_EXISTING} option is not specified, or the target + * file is a non-empty directory + * @throws AtomicMoveNotSupportedException + * The options array contains the {@code ATOMIC_MOVE} option but + * the file cannot be moved as an atomic file system operation. + * @throws IOException + * If an I/O error occurs + * @throws SecurityException + * In the case of the default provider, and a security manager is + * installed, the {@link SecurityManager#checkWrite(String) checkWrite} + * method is invoked to check write access to both the source and + * target file. + */ + protected abstract void implMoveTo(Path target, CopyOption... options) + throws IOException; + + /** + * Copy the file located by this path to a target location. + * + * <p> If this path is associated with the same {@link FileSystemProvider + * provider} as the {@code target} then the {@link #implCopyTo implCopyTo} + * method is invoked to copy the file. Otherwise, this method attempts to + * copy the file to the target location in a manner that may be less + * efficient than would be the case that target is associated with the same + * provider as this path. + * + * @throws IllegalArgumentException {@inheritDoc} + * @throws FileAlreadyExistsException {@inheritDoc} + * @throws IOException {@inheritDoc} + * @throws SecurityException {@inheritDoc} + */ + @Override + public final Path copyTo(Path target, CopyOption... options) + throws IOException + { + if ((getFileSystem().provider() == target.getFileSystem().provider())) { + implCopyTo(target, options); + } else { + xProviderCopyTo(target, options); + } + return target; + } + + /** + * Move or rename the file located by this path to a target location. + * + * <p> If this path is associated with the same {@link FileSystemProvider + * provider} as the {@code target} then the {@link #implCopyTo implMoveTo} + * method is invoked to move the file. Otherwise, this method attempts to + * copy the file to the target location and delete the source file. This + * implementation may be less efficient than would be the case that + * target is associated with the same provider as this path. + * + * @throws IllegalArgumentException {@inheritDoc} + * @throws FileAlreadyExistsException {@inheritDoc} + * @throws IOException {@inheritDoc} + * @throws SecurityException {@inheritDoc} + */ + @Override + public final Path moveTo(Path target, CopyOption... options) + throws IOException + { + if ((getFileSystem().provider() == target.getFileSystem().provider())) { + implMoveTo(target, options); + } else { + // different providers so copy + delete + xProviderCopyTo(target, convertMoveToCopyOptions(options)); + delete(false); + } + return target; + } + + /** + * Converts the given array of options for moving a file to options suitable + * for copying the file when a move is implemented as copy + delete. + */ + private static CopyOption[] convertMoveToCopyOptions(CopyOption... options) + throws AtomicMoveNotSupportedException + { + int len = options.length; + CopyOption[] newOptions = new CopyOption[len+2]; + for (int i=0; i<len; i++) { + CopyOption option = options[i]; + if (option == StandardCopyOption.ATOMIC_MOVE) { + throw new AtomicMoveNotSupportedException(null, null, + "Atomic move between providers is not supported"); + } + newOptions[i] = option; + } + newOptions[len] = LinkOption.NOFOLLOW_LINKS; + newOptions[len+1] = StandardCopyOption.COPY_ATTRIBUTES; + return newOptions; + } + + /** + * Parses the arguments for a file copy operation. + */ + private static class CopyOptions { + boolean replaceExisting = false; + boolean copyAttributes = false; + boolean followLinks = true; + + private CopyOptions() { } + + static CopyOptions parse(CopyOption... options) { + CopyOptions result = new CopyOptions(); + for (CopyOption option: options) { + if (option == StandardCopyOption.REPLACE_EXISTING) { + result.replaceExisting = true; + continue; + } + if (option == LinkOption.NOFOLLOW_LINKS) { + result.followLinks = false; + continue; + } + if (option == StandardCopyOption.COPY_ATTRIBUTES) { + result.copyAttributes = true; + continue; + } + if (option == null) + throw new NullPointerException(); + throw new IllegalArgumentException("'" + option + + "' is not a valid copy option"); + } + return result; + } + } + + /** + * Simple cross-provider copy where the target is a Path. + */ + private void xProviderCopyTo(Path target, CopyOption... options) + throws IOException + { + CopyOptions opts = CopyOptions.parse(options); + LinkOption[] linkOptions = (opts.followLinks) ? new LinkOption[0] : + new LinkOption[] { LinkOption.NOFOLLOW_LINKS }; + + // attributes of source file + BasicFileAttributes attrs = Attributes + .readBasicFileAttributes(this, linkOptions); + if (attrs.isSymbolicLink()) + throw new IOException("Copying of symbolic links not supported"); + + // delete target file + if (opts.replaceExisting) + target.delete(false); + + // create directory or file + if (attrs.isDirectory()) { + target.createDirectory(); + } else { + xProviderCopyRegularFileTo(target); + } + + // copy basic attributes to target + if (opts.copyAttributes) { + BasicFileAttributeView view = target + .getFileAttributeView(BasicFileAttributeView.class, linkOptions); + try { + view.setTimes(attrs.lastModifiedTime(), + attrs.lastAccessTime(), + attrs.creationTime(), + attrs.resolution()); + } catch (IOException x) { + // rollback + try { + target.delete(false); + } catch (IOException ignore) { } + throw x; + } + } + } + + + /** + * Simple copy of regular file to a target file that exists. + */ + private void xProviderCopyRegularFileTo(FileRef target) + throws IOException + { + ReadableByteChannel rbc = newByteChannel(); + try { + // open target file for writing + SeekableByteChannel sbc = target.newByteChannel(CREATE, WRITE); + + // simple copy loop + try { + ByteBuffer buf = ByteBuffer.wrap(new byte[8192]); + int n = 0; + for (;;) { + n = rbc.read(buf); + if (n < 0) + break; + assert n > 0; + buf.flip(); + while (buf.hasRemaining()) { + sbc.write(buf); + } + buf.rewind(); + } + + } finally { + sbc.close(); + } + } finally { + rbc.close(); + } + } +} diff --git a/src/share/classes/java/nio/file/spi/FileSystemProvider.java b/src/share/classes/java/nio/file/spi/FileSystemProvider.java new file mode 100644 index 0000000000000000000000000000000000000000..6b79381bad46fcf0c6e718c3778809c8a619e3d1 --- /dev/null +++ b/src/share/classes/java/nio/file/spi/FileSystemProvider.java @@ -0,0 +1,434 @@ +/* + * Copyright 2007-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 java.nio.file.spi; + +import java.nio.file.*; +import java.nio.file.attribute.FileAttribute; +import java.nio.channels.*; +import java.net.URI; +import java.util.*; +import java.util.concurrent.ExecutorService; +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.io.IOException; + +/** + * Service-provider class for file systems. + * + * <p> A file system provider is a concrete implementation of this class that + * implements the abstract methods defined by this class. A provider is + * identified by a {@code URI} {@link #getScheme() scheme}. The default provider + * is identified by the URI scheme "file". It creates the {@link FileSystem} that + * provides access to the file systems accessible to the Java virtual machine. + * The {@link FileSystems} class defines how file system providers are located + * and loaded. The default provider is typically a system-default provider but + * may be overridden if the system property {@code + * java.nio.file.spi.DefaultFileSystemProvider} is set. In that case, the + * provider has a one argument constructor whose formal parameter type is {@code + * FileSystemProvider}. All other providers have a zero argument constructor + * that initializes the provider. + * + * <p> A provider is a factory for one or more {@link FileSystem} instances. Each + * file system is identified by a {@code URI} where the URI's scheme matches + * the provider's {@link #getScheme scheme}. The default file system, for example, + * is identified by the URI {@code "file:///"}. A memory-based file system, + * for example, may be identified by a URI such as {@code "memory:///?name=logfs"}. + * The {@link #newFileSystem newFileSystem} method may be used to create a file + * system, and the {@link #getFileSystem getFileSystem} method may be used to + * obtain a reference to an existing file system created by the provider. Where + * a provider is the factory for a single file system then it is provider dependent + * if the file system is created when the provider is initialized, or later when + * the {@code newFileSystem} method is invoked. In the case of the default + * provider, the {@code FileSystem} is created when the provider is initialized. + * + * <p> In addition to file systems, a provider is also a factory for {@link + * FileChannel} and {@link AsynchronousFileChannel} channels. The {@link + * #newFileChannel newFileChannel} and {@link #newAsynchronousFileChannel + * AsynchronousFileChannel} methods are defined to open or create files, returning + * a channel to access the file. These methods are invoked by static factory + * methods defined in the {@link java.nio.channels} package. + * + * <p> All of the methods in this class are safe for use by multiple concurrent + * threads. + * + * @since 1.7 + */ + +public abstract class FileSystemProvider { + // lock using when loading providers + private static final Object lock = new Object(); + + // installed providers + private static volatile List<FileSystemProvider> installedProviders; + + // used to avoid recursive loading of instaled providers + private static boolean loadingProviders = false; + + private static Void checkPermission() { + SecurityManager sm = System.getSecurityManager(); + if (sm != null) + sm.checkPermission(new RuntimePermission("fileSystemProvider")); + return null; + } + private FileSystemProvider(Void ignore) { } + + /** + * Initializes a new instance of this class. + * + * <p> During construction a provider may safely access files associated + * with the default provider but care needs to be taken to avoid circular + * loading of other installed providers. If circular loading of installed + * providers is detected then an unspecified error is thrown. + * + * @throws SecurityException + * If a security manager has been installed and it denies + * {@link RuntimePermission}<tt>("fileSystemProvider")</tt> + */ + protected FileSystemProvider() { + this(checkPermission()); + } + + // loads all installed providers + private static List<FileSystemProvider> loadInstalledProviders() { + List<FileSystemProvider> list = new ArrayList<FileSystemProvider>(); + + ServiceLoader<FileSystemProvider> sl = ServiceLoader + .load(FileSystemProvider.class, ClassLoader.getSystemClassLoader()); + + // ServiceConfigurationError may be throw here + for (FileSystemProvider provider: sl) { + String scheme = provider.getScheme(); + + // add to list if the provider is not "file" and isn't a duplicate + if (!scheme.equalsIgnoreCase("file")) { + boolean found = false; + for (FileSystemProvider p: list) { + if (p.getScheme().equalsIgnoreCase(scheme)) { + found = true; + break; + } + } + if (!found) { + list.add(provider); + } + } + } + return list; + } + + /** + * Returns a list of the installed file system providers. + * + * <p> The first invocation of this method causes the default provider to be + * initialized (if not already initialized) and loads any other installed + * providers as described by the {@link FileSystems} class. + * + * @return An unmodifiable list of the installed file system providers. The + * list contains at least one element, that is the default file + * system provider + * + * @throws ServiceConfigurationError + * When an error occurs while loading a service provider + */ + public static List<FileSystemProvider> installedProviders() { + if (installedProviders == null) { + // ensure default provider is initialized + FileSystemProvider defaultProvider = FileSystems.getDefault().provider(); + + synchronized (lock) { + if (installedProviders == null) { + if (loadingProviders) { + throw new Error("Circular loading of installed providers detected"); + } + loadingProviders = true; + + List<FileSystemProvider> list = AccessController + .doPrivileged(new PrivilegedAction<List<FileSystemProvider>>() { + @Override + public List<FileSystemProvider> run() { + return loadInstalledProviders(); + }}); + + // insert the default provider at the start of the list + list.add(0, defaultProvider); + + installedProviders = Collections.unmodifiableList(list); + } + } + } + return installedProviders; + } + + /** + * Returns the URI scheme that identifies this provider. + * + * @return The URI scheme + */ + public abstract String getScheme(); + + /** + * Constructs a new {@code FileSystem} object identified by a URI. This + * method is invoked by the {@link FileSystems#newFileSystem(URI,Map)} + * method to open a new file system identified by a URI. + * + * <p> The {@code uri} parameter is an absolute, hierarchical URI, with a + * scheme equal (without regard to case) to the scheme supported by this + * provider. The exact form of the URI is highly provider dependent. The + * {@code env} parameter is a map of provider specific properties to configure + * the file system. + * + * <p> This method throws {@link FileSystemAlreadyExistsException} if the + * file system already exists because it was previously created by an + * invocation of this method. Once a file system is {@link FileSystem#close + * closed} it is provider-dependent if the provider allows a new file system + * to be created with the same URI as a file system it previously created. + * + * @param uri + * URI reference + * @param env + * A map of provider specific properties to configure the file system; + * may be empty + * + * @return A new file system + * + * @throws IllegalArgumentException + * If the pre-conditions for the {@code uri} parameter aren't met, + * or the {@code env} parameter does not contain properties required + * by the provider, or a property value is invalid + * @throws IOException + * An I/O error occurs creating the file system + * @throws SecurityException + * If a security manager is installed and it denies an unspecified + * permission required by the file system provider implementation + * @throws FileSystemAlreadyExistsException + * If the file system has already been created + */ + public abstract FileSystem newFileSystem(URI uri, Map<String,?> env) + throws IOException; + + /** + * Returns an existing {@code FileSystem} created by this provider. + * + * <p> This method returns a reference to a {@code FileSystem} that was + * created by invoking the {@link #newFileSystem(URI,Map) newFileSystem(URI,Map)} + * method. File systems created the {@link #newFileSystem(FileRef,Map) + * newFileSystem(FileRef,Map)} method are not returned by this method. + * The file system is identified by its {@code URI}. Its exact form + * is highly provider dependent. In the case of the default provider the URI's + * path component is {@code "/"} and the authority, query and fragment components + * are undefined (Undefined components are represented by {@code null}). + * + * <p> Once a file system created by this provider is {@link FileSystem#close + * closed} it is provider-dependent if this method returns a reference to + * the closed file system or throws {@link FileSystemNotFoundException}. + * If the provider allows a new file system to be created with the same URI + * as a file system it previously created then this method throws the + * exception if invoked after the file system is closed (and before a new + * instance is created by the {@link #newFileSystem newFileSystem} method). + * + * <p> If a security manager is installed then a provider implementation + * may require to check a permission before returning a reference to an + * existing file system. In the case of the {@link FileSystems#getDefault + * default} file system, no permission check is required. + * + * @param uri + * URI reference + * + * @return The file system + * + * @throws IllegalArgumentException + * If the pre-conditions for the {@code uri} parameter aren't met + * @throws FileSystemNotFoundException + * If the file system does not exist + * @throws SecurityException + * If a security manager is installed and it denies an unspecified + * permission. + */ + public abstract FileSystem getFileSystem(URI uri); + + /** + * Return a {@code Path} object by converting the given {@link URI}. + * + * <p> The exact form of the URI is file system provider dependent. In the + * case of the default provider, the URI scheme is {@code "file"} and the + * given URI has a non-empty path component, and undefined query, and + * fragment components. The resulting {@code Path} is associated with the + * default {@link FileSystems#getDefault default} {@code FileSystem}. + * + * <p> If a security manager is installed then a provider implementation + * may require to check a permission. In the case of the {@link + * FileSystems#getDefault default} file system, no permission check is + * required. + * + * @param uri + * The URI to convert + * + * @throws IllegalArgumentException + * If the URI scheme does not identify this provider or other + * preconditions on the uri parameter do not hold + * @throws FileSystemNotFoundException + * The file system, identified by the URI, does not exist + * @throws SecurityException + * If a security manager is installed and it denies an unspecified + * permission. + */ + public abstract Path getPath(URI uri); + + /** + * Constructs a new {@code FileSystem} to access the contents of a file as a + * file system. + * + * <p> This method is intended for specialized providers of pseudo file + * systems where the contents of one or more files is treated as a file + * system. The {@code file} parameter is a reference to an existing file + * and the {@code env} parameter is a map of provider specific properties to + * configure the file system. + * + * <p> If this provider does not support the creation of such file systems + * or if the provider does not recognize the file type of the given file then + * it throws {@code UnsupportedOperationException}. The default implementation + * of this method throws {@code UnsupportedOperationException}. + * + * @param file + * The file + * @param env + * A map of provider specific properties to configure the file system; + * may be empty + * + * @return A new file system + * + * @throws UnsupportedOperationException + * If this provider does not support access to the contents as a + * file system or it does not recognize the file type of the + * given file + * @throws IllegalArgumentException + * If the {@code env} parameter does not contain properties required + * by the provider, or a property value is invalid + * @throws IOException + * If an I/O error occurs + * @throws SecurityException + * If a security manager is installed and it denies an unspecified + * permission. + */ + public FileSystem newFileSystem(FileRef file, Map<String,?> env) + throws IOException + { + throw new UnsupportedOperationException(); + } + + /** + * Opens or creates a file for reading and/or writing, returning a file + * channel to access the file. + * + * <p> This method is invoked by the {@link FileChannel#open(Path,Set,FileAttribute[]) + * FileChannel.open} method to open a file channel. A provider that does not + * support all the features required to construct a file channel throws + * {@code UnsupportedOperationException}. The default provider is required + * to support the creation of file channels. When not overridden, the + * default implementation throws {@code UnsupportedOperationException}. + * + * @param path + * The path of the file to open or create + * @param options + * Options specifying how the file is opened + * @param attrs + * An optional list of file attributes to set atomically when + * creating the file + * + * @return A new file channel + * + * @throws IllegalArgumentException + * If the set contains an invalid combination of options + * @throws UnsupportedOperationException + * If this provider that does not support creating file channels, + * or an unsupported open option or file attribute is specified + * @throws IOException + * If an I/O error occurs + * @throws SecurityException + * In the case of the default file system, the {@link + * SecurityManager#checkRead(String)} method is invoked to check + * read access if the file is opened for reading. The {@link + * SecurityManager#checkWrite(String)} method is invoked to check + * write access if the file is opened for writing + */ + public FileChannel newFileChannel(Path path, + Set<? extends OpenOption> options, + FileAttribute<?>... attrs) + throws IOException + { + throw new UnsupportedOperationException(); + } + + /** + * Opens or creates a file for reading and/or writing, returning an + * asynchronous file channel to access the file. + * + * <p> This method is invoked by the {@link + * AsynchronousFileChannel#open(Path,Set,ExecutorService,FileAttribute[]) + * AsynchronousFileChannel.open} method to open an asynchronous file channel. + * A provider that does not support all the features required to construct + * an asynchronous file channel throws {@code UnsupportedOperationException}. + * The default provider is required to support the creation of asynchronous + * file channels. When not overridden, the default implementation of this + * method throws {@code UnsupportedOperationException}. + * + * @param path + * The path of the file to open or create + * @param options + * Options specifying how the file is opened + * @param executor + * The thread pool or {@code null} to associate the channel with + * the default thread pool + * @param attrs + * An optional list of file attributes to set atomically when + * creating the file + * + * @return A new asynchronous file channel + * + * @throws IllegalArgumentException + * If the set contains an invalid combination of options + * @throws UnsupportedOperationException + * If this provider that does not support creating asynchronous file + * channels, or an unsupported open option or file attribute is + * specified + * @throws IOException + * If an I/O error occurs + * @throws SecurityException + * In the case of the default file system, the {@link + * SecurityManager#checkRead(String)} method is invoked to check + * read access if the file is opened for reading. The {@link + * SecurityManager#checkWrite(String)} method is invoked to check + * write access if the file is opened for writing + */ + public AsynchronousFileChannel newAsynchronousFileChannel(Path path, + Set<? extends OpenOption> options, + ExecutorService executor, + FileAttribute<?>... attrs) + throws IOException + { + throw new UnsupportedOperationException(); + } +} diff --git a/src/share/classes/java/nio/file/spi/FileTypeDetector.java b/src/share/classes/java/nio/file/spi/FileTypeDetector.java new file mode 100644 index 0000000000000000000000000000000000000000..65e3c49c074ab1c2032e187a76123ed1c1f9c64c --- /dev/null +++ b/src/share/classes/java/nio/file/spi/FileTypeDetector.java @@ -0,0 +1,106 @@ +/* + * Copyright 2007-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 java.nio.file.spi; + +import java.nio.file.FileRef; +import java.io.IOException; + +/** + * A file type detector for probing a file to guess its file type. + * + * <p> A file type detector is a concrete implementation of this class, has a + * zero-argument constructor, and implements the abstract methods specified + * below. + * + * <p> The means by which a file type detector determines the file type is + * highly implementation specific. A simple implementation might examine the + * <em>file extension</em> (a convention used in some platforms) and map it to + * a file type. In other cases, the file type may be stored as a file <a + * href="../attribute/package-summary.html"> attribute</a> or the bytes in a + * file may be examined to guess its file type. + * + * @see java.nio.file.Files#probeContentType(FileRef) + * + * @since 1.7 + */ + +public abstract class FileTypeDetector { + + private static Void checkPermission() { + SecurityManager sm = System.getSecurityManager(); + if (sm != null) + sm.checkPermission(new RuntimePermission("fileTypeDetector")); + return null; + } + private FileTypeDetector(Void ignore) { } + + /** + * Initializes a new instance of this class. + * + * @throws SecurityException + * If a security manager has been installed and it denies + * {@link RuntimePermission}<tt>("fileTypeDetector")</tt> + */ + protected FileTypeDetector() { + this(checkPermission()); + } + + /** + * Probes the given file to guess its content type. + * + * <p> The means by which this method determines the file type is highly + * implementation specific. It may simply examine the file name, it may use + * a file <a href="../attribute/package-summary.html">attribute</a>, + * or it may examines bytes in the file. + * + * <p> The probe result is the string form of the value of a + * Multipurpose Internet Mail Extension (MIME) content type as + * defined by <a href="http://www.ietf.org/rfc/rfc2045.txt"><i>RFC 2045: + * Multipurpose Internet Mail Extensions (MIME) Part One: Format of Internet + * Message Bodies</i></a>. The string must be parsable according to the + * grammar in the RFC 2045. + * + * @param file + * The file to probe + * + * @return The content type or {@code null} if the file type is not + * recognized + * + * @throws IOException + * An I/O error occurs + * @throws SecurityException + * If the implementation requires to access the file, and a + * security manager is installed, and it denies an unspecified + * permission required by a file system provider implementation. + * If the file reference is associated with the default file system + * provider then the {@link SecurityManager#checkRead(String)} method + * is invoked to check read access to the file. + * + * @see java.nio.file.Files#probeContentType + */ + public abstract String probeContentType(FileRef file) + throws IOException; +} diff --git a/src/share/classes/java/nio/file/spi/package-info.java b/src/share/classes/java/nio/file/spi/package-info.java new file mode 100644 index 0000000000000000000000000000000000000000..88149b7974adbf79a5c84e8ad889a371656dd2c1 --- /dev/null +++ b/src/share/classes/java/nio/file/spi/package-info.java @@ -0,0 +1,39 @@ +/* + * Copyright 2007-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. + */ + +/** + * Service-provider classes for the <tt>{@link java.nio.file}</tt> package. + * + * <p> Only developers who are defining new file system providers or file type + * detectors should need to make direct use of this package. </p> + * + * <p> Unless otherwise noted, passing a <tt>null</tt> argument to a constructor + * or method in any class or interface in this package will cause a {@link + * java.lang.NullPointerException NullPointerException} to be thrown. + * + * @since 1.7 + */ + +package java.nio.file.spi; diff --git a/src/share/classes/java/security/Permission.java b/src/share/classes/java/security/Permission.java index 243f98317bbf421a119f8d011bb4b35d1e201a2b..a33b6e9f568b6afabd95d50b299266b9a9ebcba7 100644 --- a/src/share/classes/java/security/Permission.java +++ b/src/share/classes/java/security/Permission.java @@ -1,5 +1,5 @@ /* - * Copyright 1997-2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 1997-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 @@ -214,18 +214,18 @@ public abstract class Permission implements Guard, java.io.Serializable { /** * Returns a string describing this Permission. The convention is to * specify the class name, the permission name, and the actions in - * the following format: '("ClassName" "name" "actions")'. + * the following format: '("ClassName" "name" "actions")', or + * '("ClassName" "name")' if actions list is null or empty. * * @return information about this Permission. */ - public String toString() { String actions = getActions(); if ((actions == null) || (actions.length() == 0)) { // OPTIONAL - return "(" + getClass().getName() + " " + name + ")"; + return "(\"" + getClass().getName() + "\" \"" + name + "\")"; } else { - return "(" + getClass().getName() + " " + name + " " + - actions + ")"; + return "(\"" + getClass().getName() + "\" \"" + name + + "\" \"" + actions + "\")"; } } } diff --git a/src/share/classes/java/security/SecureClassLoader.java b/src/share/classes/java/security/SecureClassLoader.java index fac4596359c98bea961a2a30b0ad7d5938724328..ff11f38aaaa22638a30990e05fd4723545c52171 100644 --- a/src/share/classes/java/security/SecureClassLoader.java +++ b/src/share/classes/java/security/SecureClassLoader.java @@ -1,5 +1,5 @@ /* - * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 1997-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 @@ -45,14 +45,19 @@ public class SecureClassLoader extends ClassLoader { * succeed. Otherwise the object is not initialized and the object is * useless. */ - private boolean initialized = false; + private final boolean initialized; // HashMap that maps CodeSource to ProtectionDomain - private HashMap<CodeSource, ProtectionDomain> pdcache = + // @GuardedBy("pdcache") + private final HashMap<CodeSource, ProtectionDomain> pdcache = new HashMap<CodeSource, ProtectionDomain>(11); private static final Debug debug = Debug.getInstance("scl"); + static { + ClassLoader.registerAsParallelCapable(); + } + /** * Creates a new SecureClassLoader using the specified parent * class loader for delegation. @@ -136,10 +141,7 @@ public class SecureClassLoader extends ClassLoader { byte[] b, int off, int len, CodeSource cs) { - if (cs == null) - return defineClass(name, b, off, len); - else - return defineClass(name, b, off, len, getProtectionDomain(cs)); + return defineClass(name, b, off, len, getProtectionDomain(cs)); } /** @@ -172,10 +174,7 @@ public class SecureClassLoader extends ClassLoader { protected final Class<?> defineClass(String name, java.nio.ByteBuffer b, CodeSource cs) { - if (cs == null) - return defineClass(name, b, (ProtectionDomain)null); - else - return defineClass(name, b, getProtectionDomain(cs)); + return defineClass(name, b, getProtectionDomain(cs)); } /** @@ -209,12 +208,10 @@ public class SecureClassLoader extends ClassLoader { if (pd == null) { PermissionCollection perms = getPermissions(cs); pd = new ProtectionDomain(cs, perms, this, null); - if (pd != null) { - pdcache.put(cs, pd); - if (debug != null) { - debug.println(" getPermissions "+ pd); - debug.println(""); - } + pdcache.put(cs, pd); + if (debug != null) { + debug.println(" getPermissions "+ pd); + debug.println(""); } } } diff --git a/src/share/classes/java/util/ArrayList.java b/src/share/classes/java/util/ArrayList.java index 6eeb2a4fc2a5e7957e09e627ac590fb0376576b8..dbd46096bf3bf0b08b399c80bcbc8e6393b0a50b 100644 --- a/src/share/classes/java/util/ArrayList.java +++ b/src/share/classes/java/util/ArrayList.java @@ -179,7 +179,6 @@ public class ArrayList<E> extends AbstractList<E> modCount++; int oldCapacity = elementData.length; if (minCapacity > oldCapacity) { - Object oldData[] = elementData; int newCapacity = (oldCapacity * 3)/2 + 1; if (newCapacity < minCapacity) newCapacity = minCapacity; diff --git a/src/share/classes/java/util/Scanner.java b/src/share/classes/java/util/Scanner.java index 8fd828fffe9e55222becfda780eee2d888c4a774..3e3806d1ff4bc82b2b053e6ae778553da5b15fa0 100644 --- a/src/share/classes/java/util/Scanner.java +++ b/src/share/classes/java/util/Scanner.java @@ -1,5 +1,5 @@ /* - * Copyright 2003-2006 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2003-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 @@ -25,6 +25,7 @@ package java.util; +import java.nio.file.FileRef; import java.util.regex.*; import java.io.*; import java.math.*; @@ -672,6 +673,49 @@ public final class Scanner implements Iterator<String> { charsetName); } + /** + * {@note new} + * Constructs a new <code>Scanner</code> that produces values scanned + * from the specified file. Bytes from the file are converted into + * characters using the underlying platform's + * {@linkplain java.nio.charset.Charset#defaultCharset() default charset}. + * + * @param source + * A file to be scanned + * @throws IOException + * if an I/O error occurs opening source + * + * @since 1.7 + */ + public Scanner(FileRef source) + throws IOException + { + this(source.newByteChannel()); + } + + /** + * {@note new} + * Constructs a new <code>Scanner</code> that produces values scanned + * from the specified file. Bytes from the file are converted into + * characters using the specified charset. + * + * @param source + * A file to be scanned + * @param charsetName + * The encoding type used to convert bytes from the file + * into characters to be scanned + * @throws IOException + * if an I/O error occurs opening source + * @throws IllegalArgumentException + * if the specified encoding is not found + * @since 1.7 + */ + public Scanner(FileRef source, String charsetName) + throws IOException + { + this(source.newByteChannel(), charsetName); + } + /** * Constructs a new <code>Scanner</code> that produces values scanned * from the specified string. diff --git a/src/share/classes/java/util/TreeMap.java b/src/share/classes/java/util/TreeMap.java index 6a1c6b411f53e91a95887eaf25a201a461f3ccc0..cf97bccb7e7dc9101ae945a63b4cca64b299e108 100644 --- a/src/share/classes/java/util/TreeMap.java +++ b/src/share/classes/java/util/TreeMap.java @@ -1068,14 +1068,14 @@ public class TreeMap<K,V> } public NavigableSet<E> subSet(E fromElement, boolean fromInclusive, E toElement, boolean toInclusive) { - return new TreeSet<E>(m.subMap(fromElement, fromInclusive, - toElement, toInclusive)); + return new KeySet<E>(m.subMap(fromElement, fromInclusive, + toElement, toInclusive)); } public NavigableSet<E> headSet(E toElement, boolean inclusive) { - return new TreeSet<E>(m.headMap(toElement, inclusive)); + return new KeySet<E>(m.headMap(toElement, inclusive)); } public NavigableSet<E> tailSet(E fromElement, boolean inclusive) { - return new TreeSet<E>(m.tailMap(fromElement, inclusive)); + return new KeySet<E>(m.tailMap(fromElement, inclusive)); } public SortedSet<E> subSet(E fromElement, E toElement) { return subSet(fromElement, true, toElement, false); @@ -1087,7 +1087,7 @@ public class TreeMap<K,V> return tailSet(fromElement, true); } public NavigableSet<E> descendingSet() { - return new TreeSet(m.descendingMap()); + return new KeySet(m.descendingMap()); } } diff --git a/src/share/classes/java/util/concurrent/ConcurrentSkipListMap.java b/src/share/classes/java/util/concurrent/ConcurrentSkipListMap.java index 143d06713b4b69626677628c6ae2ec928d4d7baf..323482acb4ea0ffbd18622d93c223bf396ad66bb 100644 --- a/src/share/classes/java/util/concurrent/ConcurrentSkipListMap.java +++ b/src/share/classes/java/util/concurrent/ConcurrentSkipListMap.java @@ -2394,15 +2394,14 @@ public class ConcurrentSkipListMap<K,V> extends AbstractMap<K,V> boolean fromInclusive, E toElement, boolean toInclusive) { - return new ConcurrentSkipListSet<E> - (m.subMap(fromElement, fromInclusive, - toElement, toInclusive)); + return new KeySet<E>(m.subMap(fromElement, fromInclusive, + toElement, toInclusive)); } public NavigableSet<E> headSet(E toElement, boolean inclusive) { - return new ConcurrentSkipListSet<E>(m.headMap(toElement, inclusive)); + return new KeySet<E>(m.headMap(toElement, inclusive)); } public NavigableSet<E> tailSet(E fromElement, boolean inclusive) { - return new ConcurrentSkipListSet<E>(m.tailMap(fromElement, inclusive)); + return new KeySet<E>(m.tailMap(fromElement, inclusive)); } public NavigableSet<E> subSet(E fromElement, E toElement) { return subSet(fromElement, true, toElement, false); @@ -2414,7 +2413,7 @@ public class ConcurrentSkipListMap<K,V> extends AbstractMap<K,V> return tailSet(fromElement, true); } public NavigableSet<E> descendingSet() { - return new ConcurrentSkipListSet(m.descendingMap()); + return new KeySet(m.descendingMap()); } } diff --git a/src/share/classes/java/util/concurrent/locks/AbstractQueuedLongSynchronizer.java b/src/share/classes/java/util/concurrent/locks/AbstractQueuedLongSynchronizer.java index 2b0f36c523d1c9b9288ef1af0d684eb45dbb062c..68135015c291d684a522c62b3a955bc1f4243895 100644 --- a/src/share/classes/java/util/concurrent/locks/AbstractQueuedLongSynchronizer.java +++ b/src/share/classes/java/util/concurrent/locks/AbstractQueuedLongSynchronizer.java @@ -166,6 +166,11 @@ public abstract class AbstractQueuedLongSynchronizer static final int SIGNAL = -1; /** waitStatus value to indicate thread is waiting on condition */ static final int CONDITION = -2; + /** + * waitStatus value to indicate the next acquireShared should + * unconditionally propagate + */ + static final int PROPAGATE = -3; /** * Status field, taking on only the values: @@ -180,10 +185,16 @@ public abstract class AbstractQueuedLongSynchronizer * Nodes never leave this state. In particular, * a thread with cancelled node never again blocks. * CONDITION: This node is currently on a condition queue. - * It will not be used as a sync queue node until - * transferred. (Use of this value here - * has nothing to do with the other uses - * of the field, but simplifies mechanics.) + * It will not be used as a sync queue node + * until transferred, at which time the status + * will be set to 0. (Use of this value here has + * nothing to do with the other uses of the + * field, but simplifies mechanics.) + * PROPAGATE: A releaseShared should be propagated to other + * nodes. This is set (for head node only) in + * doReleaseShared to ensure propagation + * continues, even if other operations have + * since intervened. * 0: None of the above * * The values are arranged numerically to simplify use. @@ -403,10 +414,13 @@ public abstract class AbstractQueuedLongSynchronizer */ private void unparkSuccessor(Node node) { /* - * Try to clear status in anticipation of signalling. It is - * OK if this fails or if status is changed by waiting thread. + * If status is negative (i.e., possibly needing signal) try + * to clear in anticipation of signalling. It is OK if this + * fails or if status is changed by waiting thread. */ - compareAndSetWaitStatus(node, Node.SIGNAL, 0); + int ws = node.waitStatus; + if (ws < 0) + compareAndSetWaitStatus(node, ws, 0); /* * Thread to unpark is held in successor, which is normally @@ -425,24 +439,71 @@ public abstract class AbstractQueuedLongSynchronizer LockSupport.unpark(s.thread); } + /** + * Release action for shared mode -- signal successor and ensure + * propagation. (Note: For exclusive mode, release just amounts + * to calling unparkSuccessor of head if it needs signal.) + */ + private void doReleaseShared() { + /* + * Ensure that a release propagates, even if there are other + * in-progress acquires/releases. This proceeds in the usual + * way of trying to unparkSuccessor of head if it needs + * signal. But if it does not, status is set to PROPAGATE to + * ensure that upon release, propagation continues. + * Additionally, we must loop in case a new node is added + * while we are doing this. Also, unlike other uses of + * unparkSuccessor, we need to know if CAS to reset status + * fails, if so rechecking. + */ + for (;;) { + Node h = head; + if (h != null && h != tail) { + int ws = h.waitStatus; + if (ws == Node.SIGNAL) { + if (!compareAndSetWaitStatus(h, Node.SIGNAL, 0)) + continue; // loop to recheck cases + unparkSuccessor(h); + } + else if (ws == 0 && + !compareAndSetWaitStatus(h, 0, Node.PROPAGATE)) + continue; // loop on failed CAS + } + if (h == head) // loop if head changed + break; + } + } + /** * Sets head of queue, and checks if successor may be waiting - * in shared mode, if so propagating if propagate > 0. + * in shared mode, if so propagating if either propagate > 0 or + * PROPAGATE status was set. * - * @param pred the node holding waitStatus for node * @param node the node * @param propagate the return value from a tryAcquireShared */ private void setHeadAndPropagate(Node node, long propagate) { + Node h = head; // Record old head for check below setHead(node); - if (propagate > 0 && node.waitStatus != 0) { - /* - * Don't bother fully figuring out successor. If it - * looks null, call unparkSuccessor anyway to be safe. - */ + /* + * Try to signal next queued node if: + * Propagation was indicated by caller, + * or was recorded (as h.waitStatus) by a previous operation + * (note: this uses sign-check of waitStatus because + * PROPAGATE status may transition to SIGNAL.) + * and + * The next node is waiting in shared mode, + * or we don't know, because it appears null + * + * The conservatism in both of these checks may cause + * unnecessary wake-ups, but only when there are multiple + * racing acquires/releases, so most need signals now or soon + * anyway. + */ + if (propagate > 0 || h == null || h.waitStatus < 0) { Node s = node.next; if (s == null || s.isShared()) - unparkSuccessor(node); + doReleaseShared(); } } @@ -465,23 +526,27 @@ public abstract class AbstractQueuedLongSynchronizer while (pred.waitStatus > 0) node.prev = pred = pred.prev; - // Getting this before setting waitStatus ensures staleness + // predNext is the apparent node to unsplice. CASes below will + // fail if not, in which case, we lost race vs another cancel + // or signal, so no further action is necessary. Node predNext = pred.next; - // Can use unconditional write instead of CAS here + // Can use unconditional write instead of CAS here. + // After this atomic step, other Nodes can skip past us. + // Before, we are free of interference from other threads. node.waitStatus = Node.CANCELLED; - // If we are the tail, remove ourselves + // If we are the tail, remove ourselves. if (node == tail && compareAndSetTail(node, pred)) { compareAndSetNext(pred, predNext, null); } else { - // If "active" predecessor found... - if (pred != head - && (pred.waitStatus == Node.SIGNAL - || compareAndSetWaitStatus(pred, 0, Node.SIGNAL)) - && pred.thread != null) { - - // If successor is active, set predecessor's next link + // If successor needs signal, try to set pred's next-link + // so it will get one. Otherwise wake it up to propagate. + int ws; + if (pred != head && + ((ws = pred.waitStatus) == Node.SIGNAL || + (ws <= 0 && compareAndSetWaitStatus(pred, ws, Node.SIGNAL))) && + pred.thread != null) { Node next = node.next; if (next != null && next.waitStatus <= 0) compareAndSetNext(pred, predNext, next); @@ -503,14 +568,14 @@ public abstract class AbstractQueuedLongSynchronizer * @return {@code true} if thread should block */ private static boolean shouldParkAfterFailedAcquire(Node pred, Node node) { - int s = pred.waitStatus; - if (s < 0) + int ws = pred.waitStatus; + if (ws == Node.SIGNAL) /* * This node has already set status asking a release * to signal it, so it can safely park. */ return true; - if (s > 0) { + if (ws > 0) { /* * Predecessor was cancelled. Skip over predecessors and * indicate retry. @@ -519,14 +584,14 @@ public abstract class AbstractQueuedLongSynchronizer node.prev = pred = pred.prev; } while (pred.waitStatus > 0); pred.next = node; - } - else + } else { /* - * Indicate that we need a signal, but don't park yet. Caller - * will need to retry to make sure it cannot acquire before - * parking. + * waitStatus must be 0 or PROPAGATE. Indicate that we + * need a signal, but don't park yet. Caller will need to + * retry to make sure it cannot acquire before parking. */ - compareAndSetWaitStatus(pred, 0, Node.SIGNAL); + compareAndSetWaitStatus(pred, ws, Node.SIGNAL); + } return false; } @@ -1046,9 +1111,7 @@ public abstract class AbstractQueuedLongSynchronizer */ public final boolean releaseShared(long arg) { if (tryReleaseShared(arg)) { - Node h = head; - if (h != null && h.waitStatus != 0) - unparkSuccessor(h); + doReleaseShared(); return true; } return false; @@ -1222,8 +1285,10 @@ public abstract class AbstractQueuedLongSynchronizer // The correctness of this depends on head being initialized // before tail and on head.next being accurate if the current // thread is first in queue. - Node h, s; - return (h = head) != tail && + Node t = tail; // Read fields in reverse initialization order + Node h = head; + Node s; + return h != t && ((s = h.next) == null || s.thread != Thread.currentThread()); } @@ -1388,8 +1453,8 @@ public abstract class AbstractQueuedLongSynchronizer * case the waitStatus can be transiently and harmlessly wrong). */ Node p = enq(node); - int c = p.waitStatus; - if (c > 0 || !compareAndSetWaitStatus(p, c, Node.SIGNAL)) + int ws = p.waitStatus; + if (ws > 0 || !compareAndSetWaitStatus(p, ws, Node.SIGNAL)) LockSupport.unpark(node.thread); return true; } diff --git a/src/share/classes/java/util/concurrent/locks/AbstractQueuedSynchronizer.java b/src/share/classes/java/util/concurrent/locks/AbstractQueuedSynchronizer.java index 597e15270aeedade66625fceb30ae5ed368c48c9..8de1cad1d503997b052c0ca2b875330d90d67d22 100644 --- a/src/share/classes/java/util/concurrent/locks/AbstractQueuedSynchronizer.java +++ b/src/share/classes/java/util/concurrent/locks/AbstractQueuedSynchronizer.java @@ -389,6 +389,11 @@ public abstract class AbstractQueuedSynchronizer static final int SIGNAL = -1; /** waitStatus value to indicate thread is waiting on condition */ static final int CONDITION = -2; + /** + * waitStatus value to indicate the next acquireShared should + * unconditionally propagate + */ + static final int PROPAGATE = -3; /** * Status field, taking on only the values: @@ -403,10 +408,16 @@ public abstract class AbstractQueuedSynchronizer * Nodes never leave this state. In particular, * a thread with cancelled node never again blocks. * CONDITION: This node is currently on a condition queue. - * It will not be used as a sync queue node until - * transferred. (Use of this value here - * has nothing to do with the other uses - * of the field, but simplifies mechanics.) + * It will not be used as a sync queue node + * until transferred, at which time the status + * will be set to 0. (Use of this value here has + * nothing to do with the other uses of the + * field, but simplifies mechanics.) + * PROPAGATE: A releaseShared should be propagated to other + * nodes. This is set (for head node only) in + * doReleaseShared to ensure propagation + * continues, even if other operations have + * since intervened. * 0: None of the above * * The values are arranged numerically to simplify use. @@ -626,10 +637,13 @@ public abstract class AbstractQueuedSynchronizer */ private void unparkSuccessor(Node node) { /* - * Try to clear status in anticipation of signalling. It is - * OK if this fails or if status is changed by waiting thread. + * If status is negative (i.e., possibly needing signal) try + * to clear in anticipation of signalling. It is OK if this + * fails or if status is changed by waiting thread. */ - compareAndSetWaitStatus(node, Node.SIGNAL, 0); + int ws = node.waitStatus; + if (ws < 0) + compareAndSetWaitStatus(node, ws, 0); /* * Thread to unpark is held in successor, which is normally @@ -648,24 +662,71 @@ public abstract class AbstractQueuedSynchronizer LockSupport.unpark(s.thread); } + /** + * Release action for shared mode -- signal successor and ensure + * propagation. (Note: For exclusive mode, release just amounts + * to calling unparkSuccessor of head if it needs signal.) + */ + private void doReleaseShared() { + /* + * Ensure that a release propagates, even if there are other + * in-progress acquires/releases. This proceeds in the usual + * way of trying to unparkSuccessor of head if it needs + * signal. But if it does not, status is set to PROPAGATE to + * ensure that upon release, propagation continues. + * Additionally, we must loop in case a new node is added + * while we are doing this. Also, unlike other uses of + * unparkSuccessor, we need to know if CAS to reset status + * fails, if so rechecking. + */ + for (;;) { + Node h = head; + if (h != null && h != tail) { + int ws = h.waitStatus; + if (ws == Node.SIGNAL) { + if (!compareAndSetWaitStatus(h, Node.SIGNAL, 0)) + continue; // loop to recheck cases + unparkSuccessor(h); + } + else if (ws == 0 && + !compareAndSetWaitStatus(h, 0, Node.PROPAGATE)) + continue; // loop on failed CAS + } + if (h == head) // loop if head changed + break; + } + } + /** * Sets head of queue, and checks if successor may be waiting - * in shared mode, if so propagating if propagate > 0. + * in shared mode, if so propagating if either propagate > 0 or + * PROPAGATE status was set. * - * @param pred the node holding waitStatus for node * @param node the node * @param propagate the return value from a tryAcquireShared */ private void setHeadAndPropagate(Node node, int propagate) { + Node h = head; // Record old head for check below setHead(node); - if (propagate > 0 && node.waitStatus != 0) { - /* - * Don't bother fully figuring out successor. If it - * looks null, call unparkSuccessor anyway to be safe. - */ + /* + * Try to signal next queued node if: + * Propagation was indicated by caller, + * or was recorded (as h.waitStatus) by a previous operation + * (note: this uses sign-check of waitStatus because + * PROPAGATE status may transition to SIGNAL.) + * and + * The next node is waiting in shared mode, + * or we don't know, because it appears null + * + * The conservatism in both of these checks may cause + * unnecessary wake-ups, but only when there are multiple + * racing acquires/releases, so most need signals now or soon + * anyway. + */ + if (propagate > 0 || h == null || h.waitStatus < 0) { Node s = node.next; if (s == null || s.isShared()) - unparkSuccessor(node); + doReleaseShared(); } } @@ -688,23 +749,27 @@ public abstract class AbstractQueuedSynchronizer while (pred.waitStatus > 0) node.prev = pred = pred.prev; - // Getting this before setting waitStatus ensures staleness + // predNext is the apparent node to unsplice. CASes below will + // fail if not, in which case, we lost race vs another cancel + // or signal, so no further action is necessary. Node predNext = pred.next; - // Can use unconditional write instead of CAS here + // Can use unconditional write instead of CAS here. + // After this atomic step, other Nodes can skip past us. + // Before, we are free of interference from other threads. node.waitStatus = Node.CANCELLED; - // If we are the tail, remove ourselves + // If we are the tail, remove ourselves. if (node == tail && compareAndSetTail(node, pred)) { compareAndSetNext(pred, predNext, null); } else { - // If "active" predecessor found... - if (pred != head - && (pred.waitStatus == Node.SIGNAL - || compareAndSetWaitStatus(pred, 0, Node.SIGNAL)) - && pred.thread != null) { - - // If successor is active, set predecessor's next link + // If successor needs signal, try to set pred's next-link + // so it will get one. Otherwise wake it up to propagate. + int ws; + if (pred != head && + ((ws = pred.waitStatus) == Node.SIGNAL || + (ws <= 0 && compareAndSetWaitStatus(pred, ws, Node.SIGNAL))) && + pred.thread != null) { Node next = node.next; if (next != null && next.waitStatus <= 0) compareAndSetNext(pred, predNext, next); @@ -726,14 +791,14 @@ public abstract class AbstractQueuedSynchronizer * @return {@code true} if thread should block */ private static boolean shouldParkAfterFailedAcquire(Node pred, Node node) { - int s = pred.waitStatus; - if (s < 0) + int ws = pred.waitStatus; + if (ws == Node.SIGNAL) /* * This node has already set status asking a release * to signal it, so it can safely park. */ return true; - if (s > 0) { + if (ws > 0) { /* * Predecessor was cancelled. Skip over predecessors and * indicate retry. @@ -742,14 +807,14 @@ public abstract class AbstractQueuedSynchronizer node.prev = pred = pred.prev; } while (pred.waitStatus > 0); pred.next = node; - } - else + } else { /* - * Indicate that we need a signal, but don't park yet. Caller - * will need to retry to make sure it cannot acquire before - * parking. + * waitStatus must be 0 or PROPAGATE. Indicate that we + * need a signal, but don't park yet. Caller will need to + * retry to make sure it cannot acquire before parking. */ - compareAndSetWaitStatus(pred, 0, Node.SIGNAL); + compareAndSetWaitStatus(pred, ws, Node.SIGNAL); + } return false; } @@ -1269,9 +1334,7 @@ public abstract class AbstractQueuedSynchronizer */ public final boolean releaseShared(int arg) { if (tryReleaseShared(arg)) { - Node h = head; - if (h != null && h.waitStatus != 0) - unparkSuccessor(h); + doReleaseShared(); return true; } return false; @@ -1445,8 +1508,10 @@ public abstract class AbstractQueuedSynchronizer // The correctness of this depends on head being initialized // before tail and on head.next being accurate if the current // thread is first in queue. - Node h, s; - return (h = head) != tail && + Node t = tail; // Read fields in reverse initialization order + Node h = head; + Node s; + return h != t && ((s = h.next) == null || s.thread != Thread.currentThread()); } @@ -1611,8 +1676,8 @@ public abstract class AbstractQueuedSynchronizer * case the waitStatus can be transiently and harmlessly wrong). */ Node p = enq(node); - int c = p.waitStatus; - if (c > 0 || !compareAndSetWaitStatus(p, c, Node.SIGNAL)) + int ws = p.waitStatus; + if (ws > 0 || !compareAndSetWaitStatus(p, ws, Node.SIGNAL)) LockSupport.unpark(node.thread); return true; } diff --git a/src/share/classes/java/util/concurrent/locks/ReentrantReadWriteLock.java b/src/share/classes/java/util/concurrent/locks/ReentrantReadWriteLock.java index 8888efb2477a57994432cdb724ba0969333a567f..e767dfa62b1d2974bcc2d5aa23c4a848e740ba67 100644 --- a/src/share/classes/java/util/concurrent/locks/ReentrantReadWriteLock.java +++ b/src/share/classes/java/util/concurrent/locks/ReentrantReadWriteLock.java @@ -276,7 +276,7 @@ public class ReentrantReadWriteLock implements ReadWriteLock, java.io.Serializab * Maintained as a ThreadLocal; cached in cachedHoldCounter */ static final class HoldCounter { - int count; + int count = 0; // Use id, not reference, to avoid garbage retention final long tid = Thread.currentThread().getId(); } @@ -293,8 +293,9 @@ public class ReentrantReadWriteLock implements ReadWriteLock, java.io.Serializab } /** - * The number of read locks held by current thread. + * The number of reentrant read locks held by current thread. * Initialized only in constructor and readObject. + * Removed whenever a thread's read hold count drops to 0. */ private transient ThreadLocalHoldCounter readHolds; @@ -304,17 +305,35 @@ public class ReentrantReadWriteLock implements ReadWriteLock, java.io.Serializab * where the next thread to release is the last one to * acquire. This is non-volatile since it is just used * as a heuristic, and would be great for threads to cache. + * + * <p>Can outlive the Thread for which it is caching the read + * hold count, but avoids garbage retention by not retaining a + * reference to the Thread. + * + * <p>Accessed via a benign data race; relies on the memory + * model's final field and out-of-thin-air guarantees. */ private transient HoldCounter cachedHoldCounter; /** * firstReader is the first thread to have acquired the read lock. * firstReaderHoldCount is firstReader's hold count. - * This allows tracking of read holds for uncontended read + * + * <p>More precisely, firstReader is the unique thread that last + * changed the shared count from 0 to 1, and has not released the + * read lock since then; null if there is no such thread. + * + * <p>Cannot cause garbage retention unless the thread terminated + * without relinquishing its read locks, since tryReleaseShared + * sets it to null. + * + * <p>Accessed via a benign data race; relies on the memory + * model's out-of-thin-air guarantees for references. + * + * <p>This allows tracking of read holds for uncontended read * locks to be very cheap. */ - private final static long INVALID_THREAD_ID = -1; - private transient long firstReader = INVALID_THREAD_ID; + private transient Thread firstReader = null; private transient int firstReaderHoldCount; Sync() { @@ -393,16 +412,16 @@ public class ReentrantReadWriteLock implements ReadWriteLock, java.io.Serializab } protected final boolean tryReleaseShared(int unused) { - long tid = Thread.currentThread().getId(); - if (firstReader == tid) { + Thread current = Thread.currentThread(); + if (firstReader == current) { // assert firstReaderHoldCount > 0; if (firstReaderHoldCount == 1) - firstReader = INVALID_THREAD_ID; + firstReader = null; else firstReaderHoldCount--; } else { HoldCounter rh = cachedHoldCounter; - if (rh == null || rh.tid != tid) + if (rh == null || rh.tid != current.getId()) rh = readHolds.get(); int count = rh.count; if (count <= 1) { @@ -416,6 +435,9 @@ public class ReentrantReadWriteLock implements ReadWriteLock, java.io.Serializab int c = getState(); int nextc = c - SHARED_UNIT; if (compareAndSetState(c, nextc)) + // Releasing the read lock has no effect on readers, + // but it may allow waiting writers to proceed if + // both read and write locks are now free. return nextc == 0; } } @@ -450,15 +472,14 @@ public class ReentrantReadWriteLock implements ReadWriteLock, java.io.Serializab if (!readerShouldBlock() && r < MAX_COUNT && compareAndSetState(c, c + SHARED_UNIT)) { - long tid = current.getId(); if (r == 0) { - firstReader = tid; + firstReader = current; firstReaderHoldCount = 1; - } else if (firstReader == tid) { + } else if (firstReader == current) { firstReaderHoldCount++; } else { HoldCounter rh = cachedHoldCounter; - if (rh == null || rh.tid != tid) + if (rh == null || rh.tid != current.getId()) cachedHoldCounter = rh = readHolds.get(); else if (rh.count == 0) readHolds.set(rh); @@ -485,19 +506,17 @@ public class ReentrantReadWriteLock implements ReadWriteLock, java.io.Serializab int c = getState(); if (exclusiveCount(c) != 0) { if (getExclusiveOwnerThread() != current) - //if (removeNeeded) readHolds.remove(); return -1; // else we hold the exclusive lock; blocking here // would cause deadlock. } else if (readerShouldBlock()) { // Make sure we're not acquiring read lock reentrantly - long tid = current.getId(); - if (firstReader == tid) { + if (firstReader == current) { // assert firstReaderHoldCount > 0; } else { if (rh == null) { rh = cachedHoldCounter; - if (rh == null || rh.tid != tid) { + if (rh == null || rh.tid != current.getId()) { rh = readHolds.get(); if (rh.count == 0) readHolds.remove(); @@ -510,25 +529,20 @@ public class ReentrantReadWriteLock implements ReadWriteLock, java.io.Serializab if (sharedCount(c) == MAX_COUNT) throw new Error("Maximum lock count exceeded"); if (compareAndSetState(c, c + SHARED_UNIT)) { - long tid = current.getId(); if (sharedCount(c) == 0) { - firstReader = tid; + firstReader = current; firstReaderHoldCount = 1; - } else if (firstReader == tid) { + } else if (firstReader == current) { firstReaderHoldCount++; } else { - if (rh == null) { + if (rh == null) rh = cachedHoldCounter; - if (rh != null && rh.tid == tid) { - if (rh.count == 0) - readHolds.set(rh); - } else { - rh = readHolds.get(); - } - } else if (rh.count == 0) + if (rh == null || rh.tid != current.getId()) + rh = readHolds.get(); + else if (rh.count == 0) readHolds.set(rh); - cachedHoldCounter = rh; // cache for release rh.count++; + cachedHoldCounter = rh; // cache for release } return 1; } @@ -572,15 +586,14 @@ public class ReentrantReadWriteLock implements ReadWriteLock, java.io.Serializab if (r == MAX_COUNT) throw new Error("Maximum lock count exceeded"); if (compareAndSetState(c, c + SHARED_UNIT)) { - long tid = current.getId(); if (r == 0) { - firstReader = tid; + firstReader = current; firstReaderHoldCount = 1; - } else if (firstReader == tid) { + } else if (firstReader == current) { firstReaderHoldCount++; } else { HoldCounter rh = cachedHoldCounter; - if (rh == null || rh.tid != tid) + if (rh == null || rh.tid != current.getId()) cachedHoldCounter = rh = readHolds.get(); else if (rh.count == 0) readHolds.set(rh); @@ -626,12 +639,12 @@ public class ReentrantReadWriteLock implements ReadWriteLock, java.io.Serializab if (getReadLockCount() == 0) return 0; - long tid = Thread.currentThread().getId(); - if (firstReader == tid) + Thread current = Thread.currentThread(); + if (firstReader == current) return firstReaderHoldCount; HoldCounter rh = cachedHoldCounter; - if (rh != null && rh.tid == tid) + if (rh != null && rh.tid == current.getId()) return rh.count; int count = readHolds.get().count; @@ -647,7 +660,6 @@ public class ReentrantReadWriteLock implements ReadWriteLock, java.io.Serializab throws java.io.IOException, ClassNotFoundException { s.defaultReadObject(); readHolds = new ThreadLocalHoldCounter(); - firstReader = INVALID_THREAD_ID; setState(0); // reset to unlocked state } diff --git a/src/share/classes/java/util/logging/LogManager.java b/src/share/classes/java/util/logging/LogManager.java index 412f749404d51d7d013d63be7e63dc01aced6843..fc8f080eb71ad6f15989dbbef3e515a6ac5afb5f 100644 --- a/src/share/classes/java/util/logging/LogManager.java +++ b/src/share/classes/java/util/logging/LogManager.java @@ -215,6 +215,14 @@ public class LogManager { // This private class is used as a shutdown hook. // It does a "reset" to close all open handlers. private class Cleaner extends Thread { + + private Cleaner() { + /* Set context class loader to null in order to avoid + * keeping a strong reference to an application classloader. + */ + this.setContextClassLoader(null); + } + public void run() { // This is to ensure the LogManager.<clinit> is completed // before synchronized block. Otherwise deadlocks are possible. diff --git a/src/share/classes/java/util/regex/Matcher.java b/src/share/classes/java/util/regex/Matcher.java index ee7931688e2ae14cbcd49406293b9db0133e637b..488e47da89a80dd2eb245d727ddfcc20b2266fef 100644 --- a/src/share/classes/java/util/regex/Matcher.java +++ b/src/share/classes/java/util/regex/Matcher.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2008 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. * * This code is free software; you can redistribute it and/or modify it @@ -490,6 +490,45 @@ public final class Matcher implements MatchResult { return getSubSequence(groups[group * 2], groups[group * 2 + 1]).toString(); } + /** + * Returns the input subsequence captured by the given + * <a href="Pattern.html#groupname">named-capturing group</a> during the previous + * match operation. + * + * <p> If the match was successful but the group specified failed to match + * any part of the input sequence, then <tt>null</tt> is returned. Note + * that some groups, for example <tt>(a*)</tt>, match the empty string. + * This method will return the empty string when such a group successfully + * matches the empty string in the input. </p> + * + * @param name + * The name of a named-capturing group in this matcher's pattern + * + * @return The (possibly empty) subsequence captured by the named group + * during the previous match, or <tt>null</tt> if the group + * failed to match part of the input + * + * @throws IllegalStateException + * If no match has yet been attempted, + * or if the previous match operation failed + * + * @throws IllegalArgumentException + * If there is no capturing group in the pattern + * with the given name + */ + public String group(String name) { + if (name == null) + throw new NullPointerException("Null group name"); + if (first < 0) + throw new IllegalStateException("No match found"); + if (!parentPattern.namedGroups().containsKey(name)) + throw new IllegalArgumentException("No group with name <" + name + ">"); + int group = parentPattern.namedGroups().get(name); + if ((groups[group*2] == -1) || (groups[group*2+1] == -1)) + return null; + return getSubSequence(groups[group * 2], groups[group * 2 + 1]).toString(); + } + /** * Returns the number of capturing groups in this matcher's pattern. * @@ -649,9 +688,11 @@ public final class Matcher implements MatchResult { * * <p> The replacement string may contain references to subsequences * captured during the previous match: Each occurrence of - * <tt>$</tt><i>g</i><tt></tt> will be replaced by the result of - * evaluating {@link #group(int) group}<tt>(</tt><i>g</i><tt>)</tt>. - * The first number after the <tt>$</tt> is always treated as part of + * <tt>$</tt><<i>name</i>> or <tt>$</tt><i>g</i> + * will be replaced by the result of evaluating the corresponding + * {@link #group(String) group(name)} or {@link #group(int) group(g)</tt>} + * respectively. For <tt>$</tt><i>g</i><tt></tt>, + * the first number after the <tt>$</tt> is always treated as part of * the group reference. Subsequent numbers are incorporated into g if * they would form a legal group reference. Only the numerals '0' * through '9' are considered as potential components of the group @@ -695,6 +736,10 @@ public final class Matcher implements MatchResult { * If no match has yet been attempted, * or if the previous match operation failed * + * @throws IllegalArgumentException + * If the replacement string refers to a named-capturing + * group that does not exist in the pattern + * * @throws IndexOutOfBoundsException * If the replacement string refers to a capturing group * that does not exist in the pattern @@ -719,29 +764,62 @@ public final class Matcher implements MatchResult { } else if (nextChar == '$') { // Skip past $ cursor++; - // The first number is always a group - int refNum = (int)replacement.charAt(cursor) - '0'; - if ((refNum < 0)||(refNum > 9)) - throw new IllegalArgumentException( - "Illegal group reference"); - cursor++; - - // Capture the largest legal group string - boolean done = false; - while (!done) { - if (cursor >= replacement.length()) { - break; - } - int nextDigit = replacement.charAt(cursor) - '0'; - if ((nextDigit < 0)||(nextDigit > 9)) { // not a number - break; + // A StringIndexOutOfBoundsException is thrown if + // this "$" is the last character in replacement + // string in current implementation, a IAE might be + // more appropriate. + nextChar = replacement.charAt(cursor); + int refNum = -1; + if (nextChar == '<') { + cursor++; + StringBuilder gsb = new StringBuilder(); + while (cursor < replacement.length()) { + nextChar = replacement.charAt(cursor); + if (ASCII.isLower(nextChar) || + ASCII.isUpper(nextChar) || + ASCII.isDigit(nextChar)) { + gsb.append(nextChar); + cursor++; + } else { + break; + } } - int newRefNum = (refNum * 10) + nextDigit; - if (groupCount() < newRefNum) { - done = true; - } else { - refNum = newRefNum; - cursor++; + if (gsb.length() == 0) + throw new IllegalArgumentException( + "named capturing group has 0 length name"); + if (nextChar != '>') + throw new IllegalArgumentException( + "named capturing group is missing trailing '>'"); + String gname = gsb.toString(); + if (!parentPattern.namedGroups().containsKey(gname)) + throw new IllegalArgumentException( + "No group with name <" + gname + ">"); + refNum = parentPattern.namedGroups().get(gname); + cursor++; + } else { + // The first number is always a group + refNum = (int)nextChar - '0'; + if ((refNum < 0)||(refNum > 9)) + throw new IllegalArgumentException( + "Illegal group reference"); + cursor++; + // Capture the largest legal group string + boolean done = false; + while (!done) { + if (cursor >= replacement.length()) { + break; + } + int nextDigit = replacement.charAt(cursor) - '0'; + if ((nextDigit < 0)||(nextDigit > 9)) { // not a number + break; + } + int newRefNum = (refNum * 10) + nextDigit; + if (groupCount() < newRefNum) { + done = true; + } else { + refNum = newRefNum; + cursor++; + } } } // Append group diff --git a/src/share/classes/java/util/regex/Pattern.java b/src/share/classes/java/util/regex/Pattern.java index 2458a855e080c3c3f885d55a786b5293c6c43b2d..bda83849a376d25f2e461c6e0c60c3f8dd233365 100644 --- a/src/share/classes/java/util/regex/Pattern.java +++ b/src/share/classes/java/util/regex/Pattern.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2008 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. * * This code is free software; you can redistribute it and/or modify it @@ -29,6 +29,7 @@ import java.security.AccessController; import java.security.PrivilegedAction; import java.text.CharacterIterator; import java.text.Normalizer; +import java.util.Map; import java.util.ArrayList; import java.util.HashMap; import java.util.Arrays; @@ -298,6 +299,10 @@ import java.util.Arrays; * <td valign="bottom" headers="matches">Whatever the <i>n</i><sup>th</sup> * <a href="#cg">capturing group</a> matched</td></tr> * + * <tr><td valign="bottom" headers="construct backref"><tt>\</tt><i>k</i><<i>name</i>></td> + * <td valign="bottom" headers="matches">Whatever the + * <a href="#groupname">named-capturing group</a> "name" matched</td></tr> + * * <tr><th> </th></tr> * <tr align="left"><th colspan="2" id="quot">Quotation</th></tr> * @@ -310,8 +315,10 @@ import java.util.Arrays; * <!-- Metachars: !$()*+.<>?[\]^{|} --> * * <tr><th> </th></tr> - * <tr align="left"><th colspan="2" id="special">Special constructs (non-capturing)</th></tr> + * <tr align="left"><th colspan="2" id="special">Special constructs (named-capturing and non-capturing)</th></tr> * + * <tr><td valign="top" headers="construct special"><tt>(?<<a href="#groupname">name</a>></tt><i>X</i><tt>)</tt></td> + * <td headers="matches"><i>X</i>, as a named-capturing group</td></tr> * <tr><td valign="top" headers="construct special"><tt>(?:</tt><i>X</i><tt>)</tt></td> * <td headers="matches"><i>X</i>, as a non-capturing group</td></tr> * <tr><td valign="top" headers="construct special"><tt>(?idmsux-idmsux) </tt></td> @@ -449,6 +456,8 @@ import java.util.Arrays; * <a name="cg"> * <h4> Groups and capturing </h4> * + * <a name="gnumber"> + * <h5> Group number </h5> * <p> Capturing groups are numbered by counting their opening parentheses from * left to right. In the expression <tt>((A)(B(C)))</tt>, for example, there * are four such groups: </p> @@ -471,6 +480,24 @@ import java.util.Arrays; * subsequence may be used later in the expression, via a back reference, and * may also be retrieved from the matcher once the match operation is complete. * + * <a name="groupname"> + * <h5> Group name </h5> + * <p>A capturing group can also be assigned a "name", a <tt>named-capturing group</tt>, + * and then be back-referenced later by the "name". Group names are composed of + * the following characters: + * + * <ul> + * <li> The uppercase letters <tt>'A'</tt> through <tt>'Z'</tt> + * (<tt>'\u0041'</tt> through <tt>'\u005a'</tt>), + * <li> The lowercase letters <tt>'a'</tt> through <tt>'z'</tt> + * (<tt>'\u0061'</tt> through <tt>'\u007a'</tt>), + * <li> The digits <tt>'0'</tt> through <tt>'9'</tt> + * (<tt>'\u0030'</tt> through <tt>'\u0039'</tt>), + * </ul> + * + * <p> A <tt>named-capturing group</tt> is still numbered as described in + * <a href="#gnumber">Group number</a>. + * * <p> The captured input associated with a group is always the subsequence * that the group most recently matched. If a group is evaluated a second time * because of quantification then its previously-captured value, if any, will @@ -479,9 +506,9 @@ import java.util.Arrays; * group two set to <tt>"b"</tt>. All captured input is discarded at the * beginning of each match. * - * <p> Groups beginning with <tt>(?</tt> are pure, <i>non-capturing</i> groups - * that do not capture text and do not count towards the group total. - * + * <p> Groups beginning with <tt>(?</tt> are either pure, <i>non-capturing</i> groups + * that do not capture text and do not count towards the group total, or + * <i>named-capturing</i> group. * * <h4> Unicode support </h4> * @@ -794,6 +821,12 @@ public final class Pattern */ transient int[] buffer; + /** + * Map the "name" of the "named capturing group" to its group id + * node. + */ + transient volatile Map<String, Integer> namedGroups; + /** * Temporary storage used while parsing group references. */ @@ -1467,6 +1500,7 @@ loop: for(int x=0, offset=0; x<nCodePoints; x++, offset+=len) { // Allocate all temporary objects here. buffer = new int[32]; groupNodes = new GroupHead[10]; + namedGroups = null; if (has(LITERAL)) { // Literal pattern handling @@ -1505,6 +1539,12 @@ loop: for(int x=0, offset=0; x<nCodePoints; x++, offset+=len) { compiled = true; } + Map<String, Integer> namedGroups() { + if (namedGroups == null) + namedGroups = new HashMap<String, Integer>(2); + return namedGroups; + } + /** * Used to print out a subtree of the Pattern to help with debugging. */ @@ -2156,7 +2196,22 @@ loop: for(int x=0, offset=0; x<nCodePoints; x++, offset+=len) { case 'h': case 'i': case 'j': + break; case 'k': + if (inclass) + break; + if (read() != '<') + throw error("\\k is not followed by '<' for named capturing group"); + String name = groupname(read()); + if (!namedGroups().containsKey(name)) + throw error("(named capturing group <"+ name+"> does not exit"); + if (create) { + if (has(CASE_INSENSITIVE)) + root = new CIBackRef(namedGroups().get(name), has(UNICODE_CASE)); + else + root = new BackRef(namedGroups().get(name)); + } + return -1; case 'l': case 'm': break; @@ -2455,6 +2510,24 @@ loop: for(int x=0, offset=0; x<nCodePoints; x++, offset+=len) { return p; } + /** + * Parses and returns the name of a "named capturing group", the trailing + * ">" is consumed after parsing. + */ + private String groupname(int ch) { + StringBuilder sb = new StringBuilder(); + sb.append(Character.toChars(ch)); + while (ASCII.isLower(ch=read()) || ASCII.isUpper(ch) || + ASCII.isDigit(ch)) { + sb.append(Character.toChars(ch)); + } + if (sb.length() == 0) + throw error("named capturing group has 0 length name"); + if (ch != '>') + throw error("named capturing group is missing trailing '>'"); + return sb.toString(); + } + /** * Parses a group and returns the head node of a set of nodes that process * the group. Sometimes a double return system is used where the tail is @@ -2494,6 +2567,19 @@ loop: for(int x=0, offset=0; x<nCodePoints; x++, offset+=len) { break; case '<': // (?<xxx) look behind ch = read(); + if (ASCII.isLower(ch) || ASCII.isUpper(ch) || ASCII.isDigit(ch)) { + // named captured group + String name = groupname(ch); + if (namedGroups().containsKey(name)) + throw error("Named capturing group <" + name + + "> is already defined"); + capturingGroup = true; + head = createGroup(false); + tail = root; + namedGroups().put(name, capturingGroupCount-1); + head.next = expr(tail); + break; + } int start = cursor; head = createGroup(true); tail = root; diff --git a/src/share/classes/java/util/zip/ZipConstants64.java b/src/share/classes/java/util/zip/ZipConstants64.java new file mode 100644 index 0000000000000000000000000000000000000000..1bf3b1841b4aa8c637c0337db3fd3b4f39552d97 --- /dev/null +++ b/src/share/classes/java/util/zip/ZipConstants64.java @@ -0,0 +1,77 @@ +/* + * Copyright 1995-1996 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 java.util.zip; + +/* + * This class defines the constants that are used by the classes + * which manipulate Zip64 files. + */ + +class ZipConstants64 { + + /* + * ZIP64 constants + */ + static final long ZIP64_ENDSIG = 0x06064b50L; // "PK\006\006" + static final long ZIP64_LOCSIG = 0x07064b50L; // "PK\006\007" + static final int ZIP64_ENDHDR = 56; // ZIP64 end header size + static final int ZIP64_LOCHDR = 20; // ZIP64 end loc header size + static final int ZIP64_EXTHDR = 24; // EXT header size + static final int ZIP64_EXTID = 0x0001; // Extra field Zip64 header ID + + static final int ZIP64_MAGICCOUNT = 0xFFFF; + static final long ZIP64_MAGICVAL = 0xFFFFFFFFL; + + /* + * Zip64 End of central directory (END) header field offsets + */ + static final int ZIP64_ENDLEN = 4; // size of zip64 end of central dir + static final int ZIP64_ENDVEM = 12; // version made by + static final int ZIP64_ENDVER = 14; // version needed to extract + static final int ZIP64_ENDNMD = 16; // number of this disk + static final int ZIP64_ENDDSK = 20; // disk number of start + static final int ZIP64_ENDTOD = 24; // total number of entries on this disk + static final int ZIP64_ENDTOT = 32; // total number of entries + static final int ZIP64_ENDSIZ = 40; // central directory size in bytes + static final int ZIP64_ENDOFF = 48; // offset of first CEN header + static final int ZIP64_ENDEXT = 56; // zip64 extensible data sector + + /* + * Zip64 End of central directory locator field offsets + */ + static final int ZIP64_LOCDSK = 4; // disk number start + static final int ZIP64_LOCOFF = 8; // offset of zip64 end + static final int ZIP64_LOCTOT = 16; // total number of disks + + /* + * Zip64 Extra local (EXT) header field offsets + */ + static final int ZIP64_EXTCRC = 4; // uncompressed file crc-32 value + static final int ZIP64_EXTSIZ = 8; // compressed size, 8-byte + static final int ZIP64_EXTLEN = 16; // uncompressed size, 8-byte + + private ZipConstants64() {} +} diff --git a/src/share/classes/java/util/zip/ZipEntry.java b/src/share/classes/java/util/zip/ZipEntry.java index bcc27e63a0fceaf6c71b69ea06d063d8fda6d35d..6c16a9adb150c9eb5697efff54ce0b33dbf21ccb 100644 --- a/src/share/classes/java/util/zip/ZipEntry.java +++ b/src/share/classes/java/util/zip/ZipEntry.java @@ -1,5 +1,5 @@ /* - * Copyright 1995-2005 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 1995-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 @@ -144,11 +144,13 @@ class ZipEntry implements ZipConstants, Cloneable { * Sets the uncompressed size of the entry data. * @param size the uncompressed size in bytes * @exception IllegalArgumentException if the specified size is less - * than 0 or greater than 0xFFFFFFFF bytes + * than 0, is greater than 0xFFFFFFFF when + * <a href="package-summary.html#zip64">ZIP64 format</a> is not supported, + * or is less than 0 when ZIP64 is supported * @see #getSize() */ public void setSize(long size) { - if (size < 0 || size > 0xFFFFFFFFL) { + if (size < 0) { throw new IllegalArgumentException("invalid entry size"); } this.size = size; diff --git a/src/share/classes/java/util/zip/ZipInputStream.java b/src/share/classes/java/util/zip/ZipInputStream.java index e8f0ebdc5d96f311b8494941d05e5764c67bf052..1b9b93415cb2b3fbed73b8904970a7d69d108a53 100644 --- a/src/share/classes/java/util/zip/ZipInputStream.java +++ b/src/share/classes/java/util/zip/ZipInputStream.java @@ -1,5 +1,5 @@ /* - * Copyright 1996-2006 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. * * This code is free software; you can redistribute it and/or modify it @@ -29,6 +29,7 @@ import java.io.InputStream; import java.io.IOException; import java.io.EOFException; import java.io.PushbackInputStream; +import static java.util.zip.ZipConstants64.*; /** * This class implements an input stream filter for reading files in the @@ -285,6 +286,29 @@ class ZipInputStream extends InflaterInputStream implements ZipConstants { byte[] bb = new byte[len]; readFully(bb, 0, len); e.setExtra(bb); + // extra fields are in "HeaderID(2)DataSize(2)Data... format + if (e.csize == ZIP64_MAGICVAL || e.size == ZIP64_MAGICVAL) { + int off = 0; + while (off + 4 < len) { + int sz = get16(bb, off + 2); + if (get16(bb, off) == ZIP64_EXTID) { + off += 4; + // LOC extra zip64 entry MUST include BOTH original and + // compressed file size fields + if (sz < 16 || (off + sz) > len ) { + // Invalid zip64 extra fields, simply skip. Even it's + // rare, it's possible the entry size happens to be + // the magic value and it "accidnetly" has some bytes + // in extra match the id. + return e; + } + e.size = get64(bb, off); + e.csize = get64(bb, off + 8); + break; + } + off += (sz + 4); + } + } } return e; } @@ -375,18 +399,36 @@ class ZipInputStream extends InflaterInputStream implements ZipConstants { } if ((flag & 8) == 8) { /* "Data Descriptor" present */ - readFully(tmpbuf, 0, EXTHDR); - long sig = get32(tmpbuf, 0); - if (sig != EXTSIG) { // no EXTSIG present - e.crc = sig; - e.csize = get32(tmpbuf, EXTSIZ - EXTCRC); - e.size = get32(tmpbuf, EXTLEN - EXTCRC); - ((PushbackInputStream)in).unread( - tmpbuf, EXTHDR - EXTCRC - 1, EXTCRC); + if (inf.getBytesWritten() > ZIP64_MAGICVAL || + inf.getBytesRead() > ZIP64_MAGICVAL) { + // ZIP64 format + readFully(tmpbuf, 0, ZIP64_EXTHDR); + long sig = get32(tmpbuf, 0); + if (sig != EXTSIG) { // no EXTSIG present + e.crc = sig; + e.csize = get64(tmpbuf, ZIP64_EXTSIZ - ZIP64_EXTCRC); + e.size = get64(tmpbuf, ZIP64_EXTLEN - ZIP64_EXTCRC); + ((PushbackInputStream)in).unread( + tmpbuf, ZIP64_EXTHDR - ZIP64_EXTCRC - 1, ZIP64_EXTCRC); + } else { + e.crc = get32(tmpbuf, ZIP64_EXTCRC); + e.csize = get64(tmpbuf, ZIP64_EXTSIZ); + e.size = get64(tmpbuf, ZIP64_EXTLEN); + } } else { - e.crc = get32(tmpbuf, EXTCRC); - e.csize = get32(tmpbuf, EXTSIZ); - e.size = get32(tmpbuf, EXTLEN); + readFully(tmpbuf, 0, EXTHDR); + long sig = get32(tmpbuf, 0); + if (sig != EXTSIG) { // no EXTSIG present + e.crc = sig; + e.csize = get32(tmpbuf, EXTSIZ - EXTCRC); + e.size = get32(tmpbuf, EXTLEN - EXTCRC); + ((PushbackInputStream)in).unread( + tmpbuf, EXTHDR - EXTCRC - 1, EXTCRC); + } else { + e.crc = get32(tmpbuf, EXTCRC); + e.csize = get32(tmpbuf, EXTSIZ); + e.size = get32(tmpbuf, EXTLEN); + } } } if (e.size != inf.getBytesWritten()) { @@ -433,6 +475,14 @@ class ZipInputStream extends InflaterInputStream implements ZipConstants { * The bytes are assumed to be in Intel (little-endian) byte order. */ private static final long get32(byte b[], int off) { - return get16(b, off) | ((long)get16(b, off+2) << 16); + return (get16(b, off) | ((long)get16(b, off+2) << 16)) & 0xffffffffL; + } + + /* + * Fetches signed 64-bit value from byte array at specified offset. + * The bytes are assumed to be in Intel (little-endian) byte order. + */ + private static final long get64(byte b[], int off) { + return get32(b, off) | (get32(b, off+4) << 32); } } diff --git a/src/share/classes/java/util/zip/ZipOutputStream.java b/src/share/classes/java/util/zip/ZipOutputStream.java index 797a37392fe4e73ac57a3d8ee14a8887ee11b6b7..bd44d3213cfa24dea4a7b7d6162aa615be77fa66 100644 --- a/src/share/classes/java/util/zip/ZipOutputStream.java +++ b/src/share/classes/java/util/zip/ZipOutputStream.java @@ -1,5 +1,5 @@ /* - * Copyright 1996-2008 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. * * This code is free software; you can redistribute it and/or modify it @@ -29,6 +29,7 @@ import java.io.OutputStream; import java.io.IOException; import java.util.Vector; import java.util.HashSet; +import static java.util.zip.ZipConstants64.*; /** * This class implements an output stream filter for writing files in the @@ -343,26 +344,52 @@ class ZipOutputStream extends DeflaterOutputStream implements ZipConstants { private void writeLOC(XEntry xentry) throws IOException { ZipEntry e = xentry.entry; int flag = xentry.flag; + int elen = (e.extra != null) ? e.extra.length : 0; + boolean hasZip64 = false; + writeInt(LOCSIG); // LOC header signature - writeShort(version(e)); // version needed to extract - writeShort(flag); // general purpose bit flag - writeShort(e.method); // compression method - writeInt(e.time); // last modification time + if ((flag & 8) == 8) { + writeShort(version(e)); // version needed to extract + writeShort(flag); // general purpose bit flag + writeShort(e.method); // compression method + writeInt(e.time); // last modification time + // store size, uncompressed size, and crc-32 in data descriptor // immediately following compressed entry data writeInt(0); writeInt(0); writeInt(0); } else { - writeInt(e.crc); // crc-32 - writeInt(e.csize); // compressed size - writeInt(e.size); // uncompressed size + if (e.csize >= ZIP64_MAGICVAL || e.size >= ZIP64_MAGICVAL) { + hasZip64 = true; + writeShort(45); // ver 4.5 for zip64 + } else { + writeShort(version(e)); // version needed to extract + } + writeShort(flag); // general purpose bit flag + writeShort(e.method); // compression method + writeInt(e.time); // last modification time + writeInt(e.crc); // crc-32 + if (hasZip64) { + writeInt(ZIP64_MAGICVAL); + writeInt(ZIP64_MAGICVAL); + elen += 20; //headid(2) + size(2) + size(8) + csize(8) + } else { + writeInt(e.csize); // compressed size + writeInt(e.size); // uncompressed size + } } byte[] nameBytes = getUTF8Bytes(e.name); writeShort(nameBytes.length); - writeShort(e.extra != null ? e.extra.length : 0); + writeShort(elen); writeBytes(nameBytes, 0, nameBytes.length); + if (hasZip64) { + writeShort(ZIP64_EXTID); + writeShort(16); + writeLong(e.size); + writeLong(e.csize); + } if (e.extra != null) { writeBytes(e.extra, 0, e.extra.length); } @@ -375,8 +402,13 @@ class ZipOutputStream extends DeflaterOutputStream implements ZipConstants { private void writeEXT(ZipEntry e) throws IOException { writeInt(EXTSIG); // EXT header signature writeInt(e.crc); // crc-32 - writeInt(e.csize); // compressed size - writeInt(e.size); // uncompressed size + if (e.csize >= ZIP64_MAGICVAL || e.size >= ZIP64_MAGICVAL) { + writeLong(e.csize); + writeLong(e.size); + } else { + writeInt(e.csize); // compressed size + writeInt(e.size); // uncompressed size + } } /* @@ -387,18 +419,49 @@ class ZipOutputStream extends DeflaterOutputStream implements ZipConstants { ZipEntry e = xentry.entry; int flag = xentry.flag; int version = version(e); + + long csize = e.csize; + long size = e.size; + long offset = xentry.offset; + int e64len = 0; + boolean hasZip64 = false; + if (e.csize >= ZIP64_MAGICVAL) { + csize = ZIP64_MAGICVAL; + e64len += 8; // csize(8) + hasZip64 = true; + } + if (e.size >= ZIP64_MAGICVAL) { + size = ZIP64_MAGICVAL; // size(8) + e64len += 8; + hasZip64 = true; + } + if (xentry.offset >= ZIP64_MAGICVAL) { + offset = ZIP64_MAGICVAL; + e64len += 8; // offset(8) + hasZip64 = true; + } writeInt(CENSIG); // CEN header signature - writeShort(version); // version made by - writeShort(version); // version needed to extract + if (hasZip64) { + writeShort(45); // ver 4.5 for zip64 + writeShort(45); + } else { + writeShort(version); // version made by + writeShort(version); // version needed to extract + } writeShort(flag); // general purpose bit flag writeShort(e.method); // compression method writeInt(e.time); // last modification time writeInt(e.crc); // crc-32 - writeInt(e.csize); // compressed size - writeInt(e.size); // uncompressed size + writeInt(csize); // compressed size + writeInt(size); // uncompressed size byte[] nameBytes = getUTF8Bytes(e.name); writeShort(nameBytes.length); - writeShort(e.extra != null ? e.extra.length : 0); + if (hasZip64) { + // + headid(2) + datasize(2) + writeShort(e64len + 4 + (e.extra != null ? e.extra.length : 0)); + } else { + writeShort(e.extra != null ? e.extra.length : 0); + } byte[] commentBytes; if (e.comment != null) { commentBytes = getUTF8Bytes(e.comment); @@ -410,8 +473,18 @@ class ZipOutputStream extends DeflaterOutputStream implements ZipConstants { writeShort(0); // starting disk number writeShort(0); // internal file attributes (unused) writeInt(0); // external file attributes (unused) - writeInt(xentry.offset); // relative offset of local header + writeInt(offset); // relative offset of local header writeBytes(nameBytes, 0, nameBytes.length); + if (hasZip64) { + writeShort(ZIP64_EXTID);// Zip64 extra + writeShort(e64len); + if (size == ZIP64_MAGICVAL) + writeLong(e.size); + if (csize == ZIP64_MAGICVAL) + writeLong(e.csize); + if (offset == ZIP64_MAGICVAL) + writeLong(xentry.offset); + } if (e.extra != null) { writeBytes(e.extra, 0, e.extra.length); } @@ -424,15 +497,50 @@ class ZipOutputStream extends DeflaterOutputStream implements ZipConstants { * Writes end of central directory (END) header. */ private void writeEND(long off, long len) throws IOException { + boolean hasZip64 = false; + long xlen = len; + long xoff = off; + if (xlen >= ZIP64_MAGICVAL) { + xlen = ZIP64_MAGICVAL; + hasZip64 = true; + } + if (xoff >= ZIP64_MAGICVAL) { + xoff = ZIP64_MAGICVAL; + hasZip64 = true; + } int count = xentries.size(); - writeInt(ENDSIG); // END record signature - writeShort(0); // number of this disk - writeShort(0); // central directory start disk - writeShort(count); // number of directory entries on disk - writeShort(count); // total number of directory entries - writeInt(len); // length of central directory - writeInt(off); // offset of central directory - if (comment != null) { // zip file comment + if (count >= ZIP64_MAGICCOUNT) { + count = ZIP64_MAGICCOUNT; + hasZip64 = true; + } + if (hasZip64) { + long off64 = written; + //zip64 end of central directory record + writeInt(ZIP64_ENDSIG); // zip64 END record signature + writeLong(ZIP64_ENDHDR - 12); // size of zip64 end + writeShort(45); // version made by + writeShort(45); // version needed to extract + writeInt(0); // number of this disk + writeInt(0); // central directory start disk + writeLong(xentries.size()); // number of directory entires on disk + writeLong(xentries.size()); // number of directory entires + writeLong(len); // length of central directory + writeLong(off); // offset of central directory + + //zip64 end of central directory locator + writeInt(ZIP64_LOCSIG); // zip64 END locator signature + writeInt(0); // zip64 END start disk + writeLong(off64); // offset of zip64 END + writeInt(1); // total number of disks (?) + } + writeInt(ENDSIG); // END record signature + writeShort(0); // number of this disk + writeShort(0); // central directory start disk + writeShort(count); // number of directory entries on disk + writeShort(count); // total number of directory entries + writeInt(xlen); // length of central directory + writeInt(xoff); // offset of central directory + if (comment != null) { // zip file comment byte[] b = getUTF8Bytes(comment); writeShort(b.length); writeBytes(b, 0, b.length); @@ -463,6 +571,22 @@ class ZipOutputStream extends DeflaterOutputStream implements ZipConstants { written += 4; } + /* + * Writes a 64-bit int to the output stream in little-endian byte order. + */ + private void writeLong(long v) throws IOException { + OutputStream out = this.out; + out.write((int)((v >>> 0) & 0xff)); + out.write((int)((v >>> 8) & 0xff)); + out.write((int)((v >>> 16) & 0xff)); + out.write((int)((v >>> 24) & 0xff)); + out.write((int)((v >>> 32) & 0xff)); + out.write((int)((v >>> 40) & 0xff)); + out.write((int)((v >>> 48) & 0xff)); + out.write((int)((v >>> 56) & 0xff)); + written += 8; + } + /* * Writes an array of bytes to the output stream. */ diff --git a/src/share/classes/java/util/zip/package.html b/src/share/classes/java/util/zip/package.html index d32e0fa0f4a5f44b554ea5dc1eaaf95ce2afd06f..d4b5926367842b40959b34b2d57b281e1a548e3b 100644 --- a/src/share/classes/java/util/zip/package.html +++ b/src/share/classes/java/util/zip/package.html @@ -45,6 +45,13 @@ input streams. Info-ZIP Application Note 970311 </a> - a detailed description of the Info-ZIP format upon which the <code>java.util.zip</code> classes are based. +<p> + <a name="zip64"> + <li>An implementation may optionally support the ZIP64(tm) format extensions + defined by the + <a href="http://www.pkware.com/documents/casestudies/APPNOTE.TXT"> + PKWARE ZIP File Format Specification</a>. The ZIP64(tm) format extensions + are used to overcome the size limitations of the original ZIP format. <p> <li><a href="http://www.isi.edu/in-notes/rfc1950.txt"> ZLIB Compressed Data Format Specification version 3.3</a> @@ -70,7 +77,6 @@ input streams. <li>CRC-32 checksum is described in RFC 1952 (above) <p> <li>Adler-32 checksum is described in RFC 1950 (above) - </ul> diff --git a/src/share/classes/javax/imageio/ImageTypeSpecifier.java b/src/share/classes/javax/imageio/ImageTypeSpecifier.java index 4ba0c1062d41ef864e55fe14d8d3f16778a72d40..184bf8870cc65b3eefcb5b283fff8557dffed9fe 100644 --- a/src/share/classes/javax/imageio/ImageTypeSpecifier.java +++ b/src/share/classes/javax/imageio/ImageTypeSpecifier.java @@ -67,126 +67,13 @@ public class ImageTypeSpecifier { * <code>BufferedImage</code> types. */ private static ImageTypeSpecifier[] BISpecifier; - + private static ColorSpace sRGB; // Initialize the standard specifiers static { - ColorSpace sRGB = ColorSpace.getInstance(ColorSpace.CS_sRGB); + sRGB = ColorSpace.getInstance(ColorSpace.CS_sRGB); BISpecifier = new ImageTypeSpecifier[BufferedImage.TYPE_BYTE_INDEXED + 1]; - - BISpecifier[BufferedImage.TYPE_CUSTOM] = null; - - BISpecifier[BufferedImage.TYPE_INT_RGB] = - createPacked(sRGB, - 0x00ff0000, - 0x0000ff00, - 0x000000ff, - 0x0, - DataBuffer.TYPE_INT, - false); - - BISpecifier[BufferedImage.TYPE_INT_ARGB] = - createPacked(sRGB, - 0x00ff0000, - 0x0000ff00, - 0x000000ff, - 0xff000000, - DataBuffer.TYPE_INT, - false); - - BISpecifier[BufferedImage.TYPE_INT_ARGB_PRE] = - createPacked(sRGB, - 0x00ff0000, - 0x0000ff00, - 0x000000ff, - 0xff000000, - DataBuffer.TYPE_INT, - true); - - BISpecifier[BufferedImage.TYPE_INT_BGR] = - createPacked(sRGB, - 0x000000ff, - 0x0000ff00, - 0x00ff0000, - 0x0, - DataBuffer.TYPE_INT, - false); - - int[] bOffsRGB = { 2, 1, 0 }; - BISpecifier[BufferedImage.TYPE_3BYTE_BGR] = - createInterleaved(sRGB, - bOffsRGB, - DataBuffer.TYPE_BYTE, - false, - false); - - int[] bOffsABGR = { 3, 2, 1, 0 }; - BISpecifier[BufferedImage.TYPE_4BYTE_ABGR] = - createInterleaved(sRGB, - bOffsABGR, - DataBuffer.TYPE_BYTE, - true, - false); - - BISpecifier[BufferedImage.TYPE_4BYTE_ABGR_PRE] = - createInterleaved(sRGB, - bOffsABGR, - DataBuffer.TYPE_BYTE, - true, - true); - - BISpecifier[BufferedImage.TYPE_USHORT_565_RGB] = - createPacked(sRGB, - 0xF800, - 0x07E0, - 0x001F, - 0x0, - DataBuffer.TYPE_USHORT, - false); - - BISpecifier[BufferedImage.TYPE_USHORT_555_RGB] = - createPacked(sRGB, - 0x7C00, - 0x03E0, - 0x001F, - 0x0, - DataBuffer.TYPE_USHORT, - false); - - BISpecifier[BufferedImage.TYPE_BYTE_GRAY] = - createGrayscale(8, - DataBuffer.TYPE_BYTE, - false); - - BISpecifier[BufferedImage.TYPE_USHORT_GRAY] = - createGrayscale(16, - DataBuffer.TYPE_USHORT, - false); - - BISpecifier[BufferedImage.TYPE_BYTE_BINARY] = - createGrayscale(1, - DataBuffer.TYPE_BYTE, - false); - - BufferedImage bi = - new BufferedImage(1, 1, BufferedImage.TYPE_BYTE_INDEXED); - IndexColorModel icm = (IndexColorModel)bi.getColorModel(); - int mapSize = icm.getMapSize(); - byte[] redLUT = new byte[mapSize]; - byte[] greenLUT = new byte[mapSize]; - byte[] blueLUT = new byte[mapSize]; - byte[] alphaLUT = new byte[mapSize]; - - icm.getReds(redLUT); - icm.getGreens(greenLUT); - icm.getBlues(blueLUT); - icm.getAlphas(alphaLUT); - - BISpecifier[BufferedImage.TYPE_BYTE_INDEXED] = - createIndexed(redLUT, greenLUT, blueLUT, alphaLUT, - 8, - DataBuffer.TYPE_BYTE); } /** @@ -1011,7 +898,7 @@ public class ImageTypeSpecifier { ImageTypeSpecifier createFromBufferedImageType(int bufferedImageType) { if (bufferedImageType >= BufferedImage.TYPE_INT_RGB && bufferedImageType <= BufferedImage.TYPE_BYTE_INDEXED) { - return BISpecifier[bufferedImageType]; + return getSpecifier(bufferedImageType); } else if (bufferedImageType == BufferedImage.TYPE_CUSTOM) { throw new IllegalArgumentException("Cannot create from TYPE_CUSTOM!"); } else { @@ -1041,7 +928,7 @@ public class ImageTypeSpecifier { if (image instanceof BufferedImage) { int bufferedImageType = ((BufferedImage)image).getType(); if (bufferedImageType != BufferedImage.TYPE_CUSTOM) { - return BISpecifier[bufferedImageType]; + return getSpecifier(bufferedImageType); } } @@ -1225,4 +1112,130 @@ public class ImageTypeSpecifier { public int hashCode() { return (9 * colorModel.hashCode()) + (14 * sampleModel.hashCode()); } + + private static ImageTypeSpecifier getSpecifier(int type) { + if (BISpecifier[type] == null) { + BISpecifier[type] = createSpecifier(type); + } + return BISpecifier[type]; + } + + private static ImageTypeSpecifier createSpecifier(int type) { + switch(type) { + case BufferedImage.TYPE_INT_RGB: + return createPacked(sRGB, + 0x00ff0000, + 0x0000ff00, + 0x000000ff, + 0x0, + DataBuffer.TYPE_INT, + false); + + case BufferedImage.TYPE_INT_ARGB: + return createPacked(sRGB, + 0x00ff0000, + 0x0000ff00, + 0x000000ff, + 0xff000000, + DataBuffer.TYPE_INT, + false); + + case BufferedImage.TYPE_INT_ARGB_PRE: + return createPacked(sRGB, + 0x00ff0000, + 0x0000ff00, + 0x000000ff, + 0xff000000, + DataBuffer.TYPE_INT, + true); + + case BufferedImage.TYPE_INT_BGR: + return createPacked(sRGB, + 0x000000ff, + 0x0000ff00, + 0x00ff0000, + 0x0, + DataBuffer.TYPE_INT, + false); + + case BufferedImage.TYPE_3BYTE_BGR: + return createInterleaved(sRGB, + new int[] { 2, 1, 0 }, + DataBuffer.TYPE_BYTE, + false, + false); + + case BufferedImage.TYPE_4BYTE_ABGR: + return createInterleaved(sRGB, + new int[] { 3, 2, 1, 0 }, + DataBuffer.TYPE_BYTE, + true, + false); + + case BufferedImage.TYPE_4BYTE_ABGR_PRE: + return createInterleaved(sRGB, + new int[] { 3, 2, 1, 0 }, + DataBuffer.TYPE_BYTE, + true, + true); + + case BufferedImage.TYPE_USHORT_565_RGB: + return createPacked(sRGB, + 0xF800, + 0x07E0, + 0x001F, + 0x0, + DataBuffer.TYPE_USHORT, + false); + + case BufferedImage.TYPE_USHORT_555_RGB: + return createPacked(sRGB, + 0x7C00, + 0x03E0, + 0x001F, + 0x0, + DataBuffer.TYPE_USHORT, + false); + + case BufferedImage.TYPE_BYTE_GRAY: + return createGrayscale(8, + DataBuffer.TYPE_BYTE, + false); + + case BufferedImage.TYPE_USHORT_GRAY: + return createGrayscale(16, + DataBuffer.TYPE_USHORT, + false); + + case BufferedImage.TYPE_BYTE_BINARY: + return createGrayscale(1, + DataBuffer.TYPE_BYTE, + false); + + case BufferedImage.TYPE_BYTE_INDEXED: + { + + BufferedImage bi = + new BufferedImage(1, 1, BufferedImage.TYPE_BYTE_INDEXED); + IndexColorModel icm = (IndexColorModel)bi.getColorModel(); + int mapSize = icm.getMapSize(); + byte[] redLUT = new byte[mapSize]; + byte[] greenLUT = new byte[mapSize]; + byte[] blueLUT = new byte[mapSize]; + byte[] alphaLUT = new byte[mapSize]; + + icm.getReds(redLUT); + icm.getGreens(greenLUT); + icm.getBlues(blueLUT); + icm.getAlphas(alphaLUT); + + return createIndexed(redLUT, greenLUT, blueLUT, alphaLUT, + 8, + DataBuffer.TYPE_BYTE); + } + default: + throw new IllegalArgumentException("Invalid BufferedImage type!"); + } + } + } diff --git a/src/share/classes/javax/imageio/metadata/IIOMetadataFormat.java b/src/share/classes/javax/imageio/metadata/IIOMetadataFormat.java index 88ea8e987561f4dd1ed2fe02c857dac4d1d59260..cff46177d623b1e06236f024e18728157c017934 100644 --- a/src/share/classes/javax/imageio/metadata/IIOMetadataFormat.java +++ b/src/share/classes/javax/imageio/metadata/IIOMetadataFormat.java @@ -242,8 +242,12 @@ public interface IIOMetadataFormat { /** * A constant returned by <code>getAttributeDataType</code> - * indicating that the value of an attribute is one of 'true' or - * 'false'. + * indicating that the value of an attribute is one of the boolean + * values 'true' or 'false'. + * Attribute values of type DATATYPE_BOOLEAN should be marked as + * enumerations, and the permitted values should be the string + * literal values "TRUE" or "FALSE", although a plugin may also + * recognise lower or mixed case equivalents. */ int DATATYPE_BOOLEAN = 1; diff --git a/src/share/classes/javax/swing/PopupFactory.java b/src/share/classes/javax/swing/PopupFactory.java index 753959cea1fa61bed0ad12aaf4eac0fd9ae504ec..1eb6d1b54057e9d8b7cfd67ed9b567d74a495525 100644 --- a/src/share/classes/javax/swing/PopupFactory.java +++ b/src/share/classes/javax/swing/PopupFactory.java @@ -552,14 +552,15 @@ public class PopupFactory { boolean result = false; Component component = getComponent(); if (owner != null && component != null) { - Container parent = (Container) SwingUtilities.getRoot(owner); int popupWidth = component.getWidth(); int popupHeight = component.getHeight(); - Rectangle parentBounds = parent.getBounds(); + + Container parent = (Container) SwingUtilities.getRoot(owner); if (parent instanceof JFrame || parent instanceof JDialog || parent instanceof JWindow) { + Rectangle parentBounds = parent.getBounds(); Insets i = parent.getInsets(); parentBounds.x += i.left; parentBounds.y += i.top; @@ -577,11 +578,11 @@ public class PopupFactory { .contains(x, y, popupWidth, popupHeight); } } else if (parent instanceof JApplet) { + Rectangle parentBounds = parent.getBounds(); Point p = parent.getLocationOnScreen(); parentBounds.x = p.x; parentBounds.y = p.y; - result = parentBounds - .contains(x, y, popupWidth, popupHeight); + result = parentBounds.contains(x, y, popupWidth, popupHeight); } } return result; diff --git a/src/share/classes/javax/swing/SwingWorker.java b/src/share/classes/javax/swing/SwingWorker.java index 9eca7d535f63413cdf4f26f66e9f4b9bd722a98c..263284acc4eb6b0b8da4a552f523388cdb806ce2 100644 --- a/src/share/classes/javax/swing/SwingWorker.java +++ b/src/share/classes/javax/swing/SwingWorker.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2006 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2005-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 @@ -778,35 +778,33 @@ public abstract class SwingWorker<T, V> implements RunnableFuture<T> { threadFactory); appContext.put(SwingWorker.class, executorService); - //register shutdown hook for this executor service + // Don't use ShutdownHook here as it's not enough. We should track + // AppContext disposal instead of JVM shutdown, see 6799345 for details final ExecutorService es = executorService; - final Runnable shutdownHook = - new Runnable() { - final WeakReference<ExecutorService> executorServiceRef = - new WeakReference<ExecutorService>(es); - public void run() { - final ExecutorService executorService = - executorServiceRef.get(); - if (executorService != null) { - AccessController.doPrivileged( - new PrivilegedAction<Void>() { - public Void run() { - executorService.shutdown(); - return null; + appContext.addPropertyChangeListener(AppContext.DISPOSED_PROPERTY_NAME, + new PropertyChangeListener() { + @Override + public void propertyChange(PropertyChangeEvent pce) { + boolean disposed = (Boolean)pce.getNewValue(); + if (disposed) { + final WeakReference<ExecutorService> executorServiceRef = + new WeakReference<ExecutorService>(es); + final ExecutorService executorService = + executorServiceRef.get(); + if (executorService != null) { + AccessController.doPrivileged( + new PrivilegedAction<Void>() { + public Void run() { + executorService.shutdown(); + return null; + } } - }); + ); + } } } - }; - - AccessController.doPrivileged( - new PrivilegedAction<Void>() { - public Void run() { - Runtime.getRuntime().addShutdownHook( - new Thread(shutdownHook)); - return null; - } - }); + } + ); } return executorService; } diff --git a/src/share/classes/javax/swing/TimerQueue.java b/src/share/classes/javax/swing/TimerQueue.java index 8cd7d16d87c526b5c453f59ba86ba9d2ed6954dc..642bc56bac74511017d4d327f761a2746ff660f9 100644 --- a/src/share/classes/javax/swing/TimerQueue.java +++ b/src/share/classes/javax/swing/TimerQueue.java @@ -1,5 +1,5 @@ /* - * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 1997-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 @@ -191,7 +191,12 @@ class TimerQueue implements Runnable } finally { timer.getLock().unlock(); } - } catch (InterruptedException ignore) { + } catch (InterruptedException ie) { + // Shouldn't ignore InterruptedExceptions here, so AppContext + // is disposed gracefully, see 6799345 for details + if (AppContext.getAppContext().isDisposed()) { + break; + } } } } diff --git a/src/share/classes/javax/swing/UIManager.java b/src/share/classes/javax/swing/UIManager.java index 43476f2d6933756877c9b5952e28282718a9c928..bd6f6ac9144f3bf4805dffd0efbbe73880cb8a49 100644 --- a/src/share/classes/javax/swing/UIManager.java +++ b/src/share/classes/javax/swing/UIManager.java @@ -58,6 +58,8 @@ import sun.awt.OSInfo; import sun.security.action.GetPropertyAction; import sun.swing.SwingUtilities2; import java.lang.reflect.Method; +import java.util.HashMap; +import sun.awt.AppContext; /** @@ -1323,19 +1325,29 @@ public class UIManager implements Serializable return; } - String metalLnf = getCrossPlatformLookAndFeelClassName(); - String lnfDefault = metalLnf; + // Try to get default LAF from system property, then from AppContext + // (6653395), then use cross-platform one by default. + String lafName = null; + HashMap lafData = + (HashMap) AppContext.getAppContext().remove("swing.lafdata"); + if (lafData != null) { + lafName = (String) lafData.remove("defaultlaf"); + } + if (lafName == null) { + lafName = getCrossPlatformLookAndFeelClassName(); + } + lafName = swingProps.getProperty(defaultLAFKey, lafName); - String lnfName = "<undefined>" ; try { - lnfName = swingProps.getProperty(defaultLAFKey, lnfDefault); - setLookAndFeel(lnfName); + setLookAndFeel(lafName); } catch (Exception e) { - try { - lnfName = swingProps.getProperty(defaultLAFKey, metalLnf); - setLookAndFeel(lnfName); - } catch (Exception e2) { - throw new Error("can't load " + lnfName); + throw new Error("Cannot load " + lafName); + } + + // Set any properties passed through AppContext (6653395). + if (lafData != null) { + for (Object key: lafData.keySet()) { + UIManager.put(key, lafData.get(key)); } } } diff --git a/src/share/classes/javax/swing/plaf/basic/BasicDirectoryModel.java b/src/share/classes/javax/swing/plaf/basic/BasicDirectoryModel.java index 8cff0a3e7cb4accf6153592881333ef874e23082..b823553b627172769771cb72b7b6b6ee0c777547 100644 --- a/src/share/classes/javax/swing/plaf/basic/BasicDirectoryModel.java +++ b/src/share/classes/javax/swing/plaf/basic/BasicDirectoryModel.java @@ -27,6 +27,7 @@ package javax.swing.plaf.basic; import java.io.File; import java.util.*; +import java.util.concurrent.Callable; import javax.swing.*; import javax.swing.filechooser.*; import javax.swing.event.*; @@ -223,113 +224,115 @@ public class BasicDirectoryModel extends AbstractListModel implements PropertyCh this.fid = fid; } - private void invokeLater(DoChangeContents runnable) { - runnables.addElement(runnable); - SwingUtilities.invokeLater(runnable); - } - public void run() { run0(); setBusy(false, fid); } public void run0() { - FileSystemView fileSystem = filechooser.getFileSystemView(); + DoChangeContents doChangeContents = ShellFolder.getInvoker().invoke(new Callable<DoChangeContents>() { + public DoChangeContents call() throws Exception { + FileSystemView fileSystem = filechooser.getFileSystemView(); - File[] list = fileSystem.getFiles(currentDirectory, filechooser.isFileHidingEnabled()); + File[] list = fileSystem.getFiles(currentDirectory, filechooser.isFileHidingEnabled()); - Vector<File> acceptsList = new Vector<File>(); + Vector<File> acceptsList = new Vector<File>(); - if (isInterrupted()) { - return; - } + if (isInterrupted()) { + return null; + } - // run through the file list, add directories and selectable files to fileCache - for (File file : list) { - if (filechooser.accept(file)) { - acceptsList.addElement(file); - } - } + // run through the file list, add directories and selectable files to fileCache + for (File file : list) { + if (filechooser.accept(file)) { + acceptsList.addElement(file); + } + } - if (isInterrupted()) { - return; - } + if (isInterrupted()) { + return null; + } - // First sort alphabetically by filename - sort(acceptsList); - - Vector<File> newDirectories = new Vector<File>(50); - Vector<File> newFiles = new Vector<File>(); - // run through list grabbing directories in chunks of ten - for(int i = 0; i < acceptsList.size(); i++) { - File f = acceptsList.elementAt(i); - boolean isTraversable = filechooser.isTraversable(f); - if (isTraversable) { - newDirectories.addElement(f); - } else if (!isTraversable && filechooser.isFileSelectionEnabled()) { - newFiles.addElement(f); - } - if(isInterrupted()) { - return; - } - } + // First sort alphabetically by filename + sort(acceptsList); + + Vector<File> newDirectories = new Vector<File>(50); + Vector<File> newFiles = new Vector<File>(); + // run through list grabbing directories in chunks of ten + for (int i = 0; i < acceptsList.size(); i++) { + File f = acceptsList.elementAt(i); + boolean isTraversable = filechooser.isTraversable(f); + if (isTraversable) { + newDirectories.addElement(f); + } else if (!isTraversable && filechooser.isFileSelectionEnabled()) { + newFiles.addElement(f); + } + if (isInterrupted()) { + return null; + } + } - Vector<File> newFileCache = new Vector<File>(newDirectories); - newFileCache.addAll(newFiles); - - int newSize = newFileCache.size(); - int oldSize = fileCache.size(); - - if (newSize > oldSize) { - //see if interval is added - int start = oldSize; - int end = newSize; - for (int i = 0; i < oldSize; i++) { - if (!newFileCache.get(i).equals(fileCache.get(i))) { - start = i; - for (int j = i; j < newSize; j++) { - if (newFileCache.get(j).equals(fileCache.get(i))) { - end = j; + Vector<File> newFileCache = new Vector<File>(newDirectories); + newFileCache.addAll(newFiles); + + int newSize = newFileCache.size(); + int oldSize = fileCache.size(); + + if (newSize > oldSize) { + //see if interval is added + int start = oldSize; + int end = newSize; + for (int i = 0; i < oldSize; i++) { + if (!newFileCache.get(i).equals(fileCache.get(i))) { + start = i; + for (int j = i; j < newSize; j++) { + if (newFileCache.get(j).equals(fileCache.get(i))) { + end = j; + break; + } + } break; } } - break; - } - } - if (start >= 0 && end > start - && newFileCache.subList(end, newSize).equals(fileCache.subList(start, oldSize))) { - if(isInterrupted()) { - return; - } - invokeLater(new DoChangeContents(newFileCache.subList(start, end), start, null, 0, fid)); - newFileCache = null; - } - } else if (newSize < oldSize) { - //see if interval is removed - int start = -1; - int end = -1; - for (int i = 0; i < newSize; i++) { - if (!newFileCache.get(i).equals(fileCache.get(i))) { - start = i; - end = i + oldSize - newSize; - break; + if (start >= 0 && end > start + && newFileCache.subList(end, newSize).equals(fileCache.subList(start, oldSize))) { + if (isInterrupted()) { + return null; + } + return new DoChangeContents(newFileCache.subList(start, end), start, null, 0, fid); + } + } else if (newSize < oldSize) { + //see if interval is removed + int start = -1; + int end = -1; + for (int i = 0; i < newSize; i++) { + if (!newFileCache.get(i).equals(fileCache.get(i))) { + start = i; + end = i + oldSize - newSize; + break; + } + } + if (start >= 0 && end > start + && fileCache.subList(end, oldSize).equals(newFileCache.subList(start, newSize))) { + if (isInterrupted()) { + return null; + } + return new DoChangeContents(null, 0, new Vector(fileCache.subList(start, end)), start, fid); + } } - } - if (start >= 0 && end > start - && fileCache.subList(end, oldSize).equals(newFileCache.subList(start, newSize))) { - if(isInterrupted()) { - return; + if (!fileCache.equals(newFileCache)) { + if (isInterrupted()) { + cancelRunnables(runnables); + } + return new DoChangeContents(newFileCache, 0, fileCache, 0, fid); } - invokeLater(new DoChangeContents(null, 0, new Vector<File>(fileCache.subList(start, end)), - start, fid)); - newFileCache = null; - } - } - if (newFileCache != null && !fileCache.equals(newFileCache)) { - if (isInterrupted()) { - cancelRunnables(runnables); + return null; } - invokeLater(new DoChangeContents(newFileCache, 0, fileCache, 0, fid)); + }); + + if (doChangeContents != null) { + runnables.addElement(doChangeContents); + SwingUtilities.invokeLater(doChangeContents); } } diff --git a/src/share/classes/javax/swing/plaf/basic/BasicSliderUI.java b/src/share/classes/javax/swing/plaf/basic/BasicSliderUI.java index 864ad13264a7dcf231aaca6dac0e4641ff955dd7..0a858d41c18b33f37740fcbebcb14f07b15b0031 100644 --- a/src/share/classes/javax/swing/plaf/basic/BasicSliderUI.java +++ b/src/share/classes/javax/swing/plaf/basic/BasicSliderUI.java @@ -1004,47 +1004,62 @@ public class BasicSliderUI extends SliderUI{ g.setColor(DefaultLookup.getColor(slider, this, "Slider.tickColor", Color.black)); if ( slider.getOrientation() == JSlider.HORIZONTAL ) { - g.translate( 0, tickBounds.y); + g.translate(0, tickBounds.y); - int value = slider.getMinimum(); - int xPos; + if (slider.getMinorTickSpacing() > 0) { + int value = slider.getMinimum(); - if ( slider.getMinorTickSpacing() > 0 ) { while ( value <= slider.getMaximum() ) { - xPos = xPositionForValue( value ); + int xPos = xPositionForValue(value); paintMinorTickForHorizSlider( g, tickBounds, xPos ); + + // Overflow checking + if (Integer.MAX_VALUE - slider.getMinorTickSpacing() < value) { + break; + } + value += slider.getMinorTickSpacing(); } } - if ( slider.getMajorTickSpacing() > 0 ) { - value = slider.getMinimum(); + if (slider.getMajorTickSpacing() > 0) { + int value = slider.getMinimum(); while ( value <= slider.getMaximum() ) { - xPos = xPositionForValue( value ); + int xPos = xPositionForValue(value); paintMajorTickForHorizSlider( g, tickBounds, xPos ); + + // Overflow checking + if (Integer.MAX_VALUE - slider.getMajorTickSpacing() < value) { + break; + } + value += slider.getMajorTickSpacing(); } } g.translate( 0, -tickBounds.y); - } - else { - g.translate(tickBounds.x, 0); - - int value = slider.getMinimum(); - int yPos; + } else { + g.translate(tickBounds.x, 0); - if ( slider.getMinorTickSpacing() > 0 ) { + if (slider.getMinorTickSpacing() > 0) { int offset = 0; if(!BasicGraphicsUtils.isLeftToRight(slider)) { offset = tickBounds.width - tickBounds.width / 2; g.translate(offset, 0); } - while ( value <= slider.getMaximum() ) { - yPos = yPositionForValue( value ); + int value = slider.getMinimum(); + + while (value <= slider.getMaximum()) { + int yPos = yPositionForValue(value); paintMinorTickForVertSlider( g, tickBounds, yPos ); + + // Overflow checking + if (Integer.MAX_VALUE - slider.getMinorTickSpacing() < value) { + break; + } + value += slider.getMinorTickSpacing(); } @@ -1053,15 +1068,22 @@ public class BasicSliderUI extends SliderUI{ } } - if ( slider.getMajorTickSpacing() > 0 ) { - value = slider.getMinimum(); + if (slider.getMajorTickSpacing() > 0) { if(!BasicGraphicsUtils.isLeftToRight(slider)) { g.translate(2, 0); } - while ( value <= slider.getMaximum() ) { - yPos = yPositionForValue( value ); + int value = slider.getMinimum(); + + while (value <= slider.getMaximum()) { + int yPos = yPositionForValue(value); paintMajorTickForVertSlider( g, tickBounds, yPos ); + + // Overflow checking + if (Integer.MAX_VALUE - slider.getMajorTickSpacing() < value) { + break; + } + value += slider.getMajorTickSpacing(); } @@ -1775,8 +1797,6 @@ public class BasicSliderUI extends SliderUI{ thumbMiddle = thumbLeft + halfThumbWidth; slider.setValue(valueForXPosition(thumbMiddle)); break; - default: - return; } } diff --git a/src/share/classes/javax/swing/plaf/metal/MetalFileChooserUI.java b/src/share/classes/javax/swing/plaf/metal/MetalFileChooserUI.java index 4636e07c4fdb543e3f28e4e72b16959953e9d7db..58063f585b241c59efd6a56457ff0dad514ef10c 100644 --- a/src/share/classes/javax/swing/plaf/metal/MetalFileChooserUI.java +++ b/src/share/classes/javax/swing/plaf/metal/MetalFileChooserUI.java @@ -38,6 +38,8 @@ import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.util.*; +import java.security.AccessController; +import java.security.PrivilegedAction; import javax.accessibility.*; import sun.awt.shell.ShellFolder; @@ -937,7 +939,11 @@ public class MetalFileChooserUI extends BasicFileChooserUI { File[] baseFolders; if (useShellFolder) { - baseFolders = (File[])ShellFolder.get("fileChooserComboBoxFolders"); + baseFolders = AccessController.doPrivileged(new PrivilegedAction<File[]>() { + public File[] run() { + return (File[]) ShellFolder.get("fileChooserComboBoxFolders"); + } + }); } else { baseFolders = fsv.getRoots(); } diff --git a/src/share/classes/javax/swing/plaf/synth/SynthTabbedPaneUI.java b/src/share/classes/javax/swing/plaf/synth/SynthTabbedPaneUI.java index 975056a1c69896a001d20dcb1353bcca0d3e3651..ac91419f11504cb06e977726034529146fc44bfd 100644 --- a/src/share/classes/javax/swing/plaf/synth/SynthTabbedPaneUI.java +++ b/src/share/classes/javax/swing/plaf/synth/SynthTabbedPaneUI.java @@ -233,7 +233,7 @@ class SynthTabbedPaneUI extends BasicTabbedPaneUI implements SynthUI, PropertyCh tabContext.getStyle().getGraphicsUtils(tabContext).layoutText( tabContext, metrics, title, icon, SwingUtilities.CENTER, SwingUtilities.CENTER, SwingUtilities.LEADING, - SwingUtilities.TRAILING, calcRect, + SwingUtilities.CENTER, calcRect, iconRect, textRect, textIconGap); return textRect.y + metrics.getAscent() + getBaselineOffset(); } @@ -426,7 +426,7 @@ class SynthTabbedPaneUI extends BasicTabbedPaneUI implements SynthUI, PropertyCh ss.getStyle().getGraphicsUtils(ss).layoutText(ss, metrics, title, icon, SwingUtilities.CENTER, SwingUtilities.CENTER, - SwingUtilities.LEADING, SwingUtilities.TRAILING, + SwingUtilities.LEADING, SwingUtilities.CENTER, tabRect, iconRect, textRect, textIconGap); tabPane.putClientProperty("html", null); diff --git a/src/share/classes/javax/swing/text/GlyphView.java b/src/share/classes/javax/swing/text/GlyphView.java index 3cb4efe59f97a8fc6fedfa3bc96228c897cd1417..364fd69e8eedd2d2a65408fb60a3d5c5faf07f6c 100644 --- a/src/share/classes/javax/swing/text/GlyphView.java +++ b/src/share/classes/javax/swing/text/GlyphView.java @@ -30,6 +30,7 @@ import javax.swing.event.*; import java.util.BitSet; import java.util.Locale; +import javax.swing.UIManager; import sun.swing.SwingUtilities2; /** @@ -382,11 +383,10 @@ public class GlyphView extends View implements TabableView, Cloneable { Color bg = getBackground(); Color fg = getForeground(); - if (c instanceof JTextComponent) { - JTextComponent tc = (JTextComponent) c; - if (!tc.isEnabled()) { - fg = tc.getDisabledTextColor(); - } + if (c != null && ! c.isEnabled()) { + fg = (c instanceof JTextComponent ? + ((JTextComponent)c).getDisabledTextColor() : + UIManager.getColor("textInactiveText")); } if (bg != null) { g.setColor(bg); diff --git a/src/share/classes/javax/swing/text/html/ImageView.java b/src/share/classes/javax/swing/text/html/ImageView.java index 4b645b6a72598cf4ed61a632ba1d3080c16c37ef..0831e2567cd3a4fad406db336d178f6745561c10 100644 --- a/src/share/classes/javax/swing/text/html/ImageView.java +++ b/src/share/classes/javax/swing/text/html/ImageView.java @@ -25,9 +25,7 @@ package javax.swing.text.html; import java.awt.*; -import java.awt.event.*; import java.awt.image.ImageObserver; -import java.io.*; import java.net.*; import java.util.Dictionary; import javax.swing.*; @@ -97,6 +95,7 @@ public class ImageView extends View { private AttributeSet attr; private Image image; + private Image disabledImage; private int width; private int height; /** Bitmask containing some of the above bitmask values. Because the @@ -193,6 +192,17 @@ public class ImageView extends View { return image; } + private Image getImage(boolean enabled) { + Image img = getImage(); + if (! enabled) { + if (disabledImage == null) { + disabledImage = GrayFilter.createDisabledImage(img); + } + img = disabledImage; + } + return img; + } + /** * Sets how the image is loaded. If <code>newValue</code> is true, * the image we be loaded when first asked for, otherwise it will @@ -338,8 +348,6 @@ public class ImageView extends View { Rectangle rect = (a instanceof Rectangle) ? (Rectangle)a : a.getBounds(); - - Image image = getImage(); Rectangle clip = g.getClipBounds(); fBounds.setBounds(rect); @@ -350,29 +358,29 @@ public class ImageView extends View { rect.width - leftInset - rightInset, rect.height - topInset - bottomInset); } - if (image != null) { - if (!hasPixels(image)) { - // No pixels yet, use the default - Icon icon = (image == null) ? getNoImageIcon() : - getLoadingImageIcon(); + Container host = getContainer(); + Image img = getImage(host == null || host.isEnabled()); + if (img != null) { + if (! hasPixels(img)) { + // No pixels yet, use the default + Icon icon = getLoadingImageIcon(); if (icon != null) { - icon.paintIcon(getContainer(), g, rect.x + leftInset, - rect.y + topInset); + icon.paintIcon(host, g, + rect.x + leftInset, rect.y + topInset); } } else { // Draw the image - g.drawImage(image, rect.x + leftInset, rect.y + topInset, + g.drawImage(img, rect.x + leftInset, rect.y + topInset, width, height, imageObserver); } } else { Icon icon = getNoImageIcon(); - if (icon != null) { - icon.paintIcon(getContainer(), g, rect.x + leftInset, - rect.y + topInset); + icon.paintIcon(host, g, + rect.x + leftInset, rect.y + topInset); } View view = getAltView(); // Paint the view representing the alt text, if its non-null @@ -855,7 +863,9 @@ public class ImageView extends View { // it will pick up the new height/width, if necessary. public boolean imageUpdate(Image img, int flags, int x, int y, int newWidth, int newHeight ) { - if (image == null || image != img || getParent() == null) { + if (img != image && img != disabledImage || + image == null || getParent() == null) { + return false; } @@ -873,6 +883,8 @@ public class ImageView extends View { if ((state & HEIGHT_FLAG) != HEIGHT_FLAG) { height = DEFAULT_HEIGHT; } + } else { + disabledImage = null; } if ((state & LOADING_FLAG) == LOADING_FLAG) { // No need to resize or repaint, still in the process @@ -885,38 +897,37 @@ public class ImageView extends View { return false; } - // Resize image if necessary: - short changed = 0; - if ((flags & ImageObserver.HEIGHT) != 0 && !getElement(). - getAttributes().isDefined(HTML.Attribute.HEIGHT)) { - changed |= 1; - } - if ((flags & ImageObserver.WIDTH) != 0 && !getElement(). - getAttributes().isDefined(HTML.Attribute.WIDTH)) { - changed |= 2; - } - - synchronized(ImageView.this) { - if (image != img) { - return false; + if (image == img) { + // Resize image if necessary: + short changed = 0; + if ((flags & ImageObserver.HEIGHT) != 0 && !getElement(). + getAttributes().isDefined(HTML.Attribute.HEIGHT)) { + changed |= 1; } - if ((changed & 1) == 1 && (state & WIDTH_FLAG) == 0) { - width = newWidth; + if ((flags & ImageObserver.WIDTH) != 0 && !getElement(). + getAttributes().isDefined(HTML.Attribute.WIDTH)) { + changed |= 2; } - if ((changed & 2) == 2 && (state & HEIGHT_FLAG) == 0) { - height = newHeight; + + synchronized(ImageView.this) { + if ((changed & 1) == 1 && (state & WIDTH_FLAG) == 0) { + width = newWidth; + } + if ((changed & 2) == 2 && (state & HEIGHT_FLAG) == 0) { + height = newHeight; + } + if ((state & LOADING_FLAG) == LOADING_FLAG) { + // No need to resize or repaint, still in the process of + // loading. + return true; + } } - if ((state & LOADING_FLAG) == LOADING_FLAG) { - // No need to resize or repaint, still in the process of - // loading. + if (changed != 0) { + // May need to resize myself, asynchronously: + safePreferenceChanged(); return true; } } - if (changed != 0) { - // May need to resize myself, asynchronously: - safePreferenceChanged(); - return true; - } // Repaint when done or when new pixels arrive: if ((flags & (FRAMEBITS|ALLBITS)) != 0) { diff --git a/src/share/classes/javax/swing/text/html/StyleSheet.java b/src/share/classes/javax/swing/text/html/StyleSheet.java index 0cf1804787229e2e3dcd0e24374f738e617e6477..c2a07739a049f99a3a293848dc6a8ffdaf738eea 100644 --- a/src/share/classes/javax/swing/text/html/StyleSheet.java +++ b/src/share/classes/javax/swing/text/html/StyleSheet.java @@ -31,6 +31,7 @@ import java.io.*; import java.net.*; import javax.swing.Icon; import javax.swing.ImageIcon; +import javax.swing.UIManager; import javax.swing.border.*; import javax.swing.event.ChangeListener; import javax.swing.text.*; @@ -2161,6 +2162,7 @@ public class StyleSheet extends StyleContext { */ public void paint(Graphics g, float x, float y, float w, float h, View v, int item) { View cv = v.getView(item); + Container host = v.getContainer(); Object name = cv.getElement().getAttributes().getAttribute (StyleConstants.NameAttribute); // Only draw something if the View is a list item. This won't @@ -2171,7 +2173,7 @@ public class StyleSheet extends StyleContext { } // deside on what side draw bullets, etc. isLeftToRight = - cv.getContainer().getComponentOrientation().isLeftToRight(); + host.getComponentOrientation().isLeftToRight(); // How the list indicator is aligned is not specified, it is // left up to the UA. IE and NS differ on this behavior. @@ -2200,15 +2202,15 @@ public class StyleSheet extends StyleContext { } // set the color of a decoration - if (ss != null) { - g.setColor(ss.getForeground(cv.getAttributes())); - } else { - g.setColor(Color.black); - } + Color c = (host.isEnabled() + ? (ss != null + ? ss.getForeground(cv.getAttributes()) + : host.getForeground()) + : UIManager.getColor("textInactiveText")); + g.setColor(c); if (img != null) { - drawIcon(g, (int) x, (int) y, (int) w, (int) h, align, - v.getContainer()); + drawIcon(g, (int) x, (int) y, (int) w, (int) h, align, host); return; } CSS.Value childtype = getChildType(cv); diff --git a/src/share/classes/sun/awt/FontConfiguration.java b/src/share/classes/sun/awt/FontConfiguration.java index 6349aa778eacafad9986f5ae7ff846f3fe56b058..4504af24e9d2d78e2136f86cb0e6ca17ce88cb88 100644 --- a/src/share/classes/sun/awt/FontConfiguration.java +++ b/src/share/classes/sun/awt/FontConfiguration.java @@ -98,7 +98,7 @@ public abstract class FontConfiguration { if (!inited) { this.preferLocaleFonts = false; this.preferPropFonts = false; - fontConfig = this; /* static initialization */ + setFontConfiguration(); readFontConfigFile(fontConfigFile); initFontConfig(); inited = true; @@ -1244,6 +1244,10 @@ public abstract class FontConfiguration { return fontConfig; } + protected void setFontConfiguration() { + fontConfig = this; /* static initialization */ + } + ////////////////////////////////////////////////////////////////////// // FontConfig data tables and the index constants in binary file // ////////////////////////////////////////////////////////////////////// diff --git a/src/share/classes/sun/awt/shell/ShellFolder.java b/src/share/classes/sun/awt/shell/ShellFolder.java index 16c1b12cb80ef6e3ce5a5f1355322d93a24b4009..0e75ac183dcfa8eefea46171691abadc3fe7098c 100644 --- a/src/share/classes/sun/awt/shell/ShellFolder.java +++ b/src/share/classes/sun/awt/shell/ShellFolder.java @@ -31,6 +31,7 @@ import java.awt.Toolkit; import java.io.*; import java.io.FileNotFoundException; import java.util.*; +import java.util.concurrent.Callable; /** * @author Michael Martak @@ -461,6 +462,35 @@ public abstract class ShellFolder extends File { return null; } + private static Invoker invoker; + + /** + * Provides the single access point to the {@link Invoker}. It is guaranteed that the value + * returned by this method will be always the same. + * + * @return the singleton instance of {@link Invoker} + */ + public static Invoker getInvoker() { + if (invoker == null) { + invoker = shellFolderManager.createInvoker(); + } + return invoker; + } + + /** + * Interface allowing to invoke tasks in different environments on different platforms. + */ + public static interface Invoker { + /** + * Invokes a callable task. If the {@code task} throws a checked exception, + * it will be wrapped into a {@link RuntimeException} + * + * @param task a task to invoke + * @return the result of {@code task}'s invokation + */ + <T> T invoke(Callable<T> task); + } + /** * Provides a default comparator for the default column set */ diff --git a/src/share/classes/sun/awt/shell/ShellFolderManager.java b/src/share/classes/sun/awt/shell/ShellFolderManager.java index 8fb15bf0cf8c39b48310d92155cdc5ebe0006811..dc8901f7bc5aebc4fb185d661b0c4bd40a06d118 100644 --- a/src/share/classes/sun/awt/shell/ShellFolderManager.java +++ b/src/share/classes/sun/awt/shell/ShellFolderManager.java @@ -27,6 +27,7 @@ package sun.awt.shell; import java.io.File; import java.io.FileNotFoundException; +import java.util.concurrent.Callable; /** * @author Michael Martak @@ -96,9 +97,23 @@ class ShellFolderManager { } public boolean isFileSystemRoot(File dir) { - if (dir instanceof ShellFolder && !((ShellFolder)dir).isFileSystem()) { + if (dir instanceof ShellFolder && !((ShellFolder) dir).isFileSystem()) { return false; } return (dir.getParentFile() == null); } + + protected ShellFolder.Invoker createInvoker() { + return new DirectInvoker(); + } + + private static class DirectInvoker implements ShellFolder.Invoker { + public <T> T invoke(Callable<T> task) { + try { + return task.call(); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + } } diff --git a/src/share/classes/sun/beans/editors/ColorEditor.java b/src/share/classes/sun/beans/editors/ColorEditor.java index a3610e0ee2ef9d7c64c74c0f627de2bd3c6571f6..55dd9137be1ef1f605f0e972f5be0fca96d31b54 100644 --- a/src/share/classes/sun/beans/editors/ColorEditor.java +++ b/src/share/classes/sun/beans/editors/ColorEditor.java @@ -1,5 +1,5 @@ /* - * 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. * * This code is free software; you can redistribute it and/or modify it @@ -29,6 +29,8 @@ import java.awt.*; import java.beans.*; public class ColorEditor extends Panel implements PropertyEditor { + private static final long serialVersionUID = 1781257185164716054L; + public ColorEditor() { setLayout(null); diff --git a/src/share/classes/sun/beans/editors/FontEditor.java b/src/share/classes/sun/beans/editors/FontEditor.java index 88de9aea48f7bf8ed2939b88340a7245c34b0053..04d4c187e22c6e1d1c37dd6f5198af2dcd34b453 100644 --- a/src/share/classes/sun/beans/editors/FontEditor.java +++ b/src/share/classes/sun/beans/editors/FontEditor.java @@ -1,5 +1,5 @@ /* - * 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. * * This code is free software; you can redistribute it and/or modify it @@ -29,6 +29,7 @@ import java.awt.*; import java.beans.*; public class FontEditor extends Panel implements java.beans.PropertyEditor { + private static final long serialVersionUID = 6732704486002715933L; public FontEditor() { setLayout(null); diff --git a/src/share/classes/sun/font/FileFontStrike.java b/src/share/classes/sun/font/FileFontStrike.java index dab135e96d20b9894f4588a6be4e93309b576204..11dff8a20c1ac4a978265bab712f5a740f26f758 100644 --- a/src/share/classes/sun/font/FileFontStrike.java +++ b/src/share/classes/sun/font/FileFontStrike.java @@ -26,6 +26,7 @@ package sun.font; import java.lang.ref.SoftReference; +import java.lang.ref.WeakReference; import java.awt.Font; import java.awt.GraphicsEnvironment; import java.awt.Rectangle; @@ -842,8 +843,36 @@ public class FileFontStrike extends PhysicalStrike { return fileFont.getGlyphOutlineBounds(pScalerContext, glyphCode); } + private + WeakReference<ConcurrentHashMap<Integer,GeneralPath>> outlineMapRef; + GeneralPath getGlyphOutline(int glyphCode, float x, float y) { - return fileFont.getGlyphOutline(pScalerContext, glyphCode, x, y); + + GeneralPath gp = null; + ConcurrentHashMap<Integer, GeneralPath> outlineMap = null; + + if (outlineMapRef != null) { + outlineMap = outlineMapRef.get(); + if (outlineMap != null) { + gp = (GeneralPath)outlineMap.get(glyphCode); + } + } + + if (gp == null) { + gp = fileFont.getGlyphOutline(pScalerContext, glyphCode, 0, 0); + if (outlineMap == null) { + outlineMap = new ConcurrentHashMap<Integer, GeneralPath>(); + outlineMapRef = + new WeakReference + <ConcurrentHashMap<Integer,GeneralPath>>(outlineMap); + } + outlineMap.put(glyphCode, gp); + } + gp = (GeneralPath)gp.clone(); // mutable! + if (x != 0f || y != 0f) { + gp.transform(AffineTransform.getTranslateInstance(x, y)); + } + return gp; } GeneralPath getGlyphVectorOutline(int[] glyphs, float x, float y) { diff --git a/src/share/classes/sun/font/FontManager.java b/src/share/classes/sun/font/FontManager.java index f709f381ada71af392bff7e4e26568a4a9d5e44e..a8b721daffc014c47d5baaac16b7815eb5c0191d 100644 --- a/src/share/classes/sun/font/FontManager.java +++ b/src/share/classes/sun/font/FontManager.java @@ -1601,18 +1601,27 @@ public final class FontManager { /* Path may be absolute or a base file name relative to one of * the platform font directories */ - private static String getPathName(String s) { + private static String getPathName(final String s) { File f = new File(s); if (f.isAbsolute()) { return s; } else if (pathDirs.length==1) { return pathDirs[0] + File.separator + s; } else { - for (int p=0; p<pathDirs.length; p++) { - f = new File(pathDirs[p] + File.separator + s); - if (f.exists()) { - return f.getAbsolutePath(); - } + String path = java.security.AccessController.doPrivileged( + new java.security.PrivilegedAction<String>() { + public String run() { + for (int p=0; p<pathDirs.length; p++) { + File f = new File(pathDirs[p] +File.separator+ s); + if (f.exists()) { + return f.getAbsolutePath(); + } + } + return null; + } + }); + if (path != null) { + return path; } } return s; // shouldn't happen, but harmless diff --git a/src/share/classes/sun/font/GlyphLayout.java b/src/share/classes/sun/font/GlyphLayout.java index 18ebec85a02205a1e491a109d1377acc648e64b5..91162cb1c577631bddc7d306a283f6503f4a75fa 100644 --- a/src/share/classes/sun/font/GlyphLayout.java +++ b/src/share/classes/sun/font/GlyphLayout.java @@ -338,6 +338,8 @@ public final class GlyphLayout { cache = new ConcurrentHashMap<SDKey, SDCache>(10); cacheRef = new SoftReference<ConcurrentHashMap<SDKey, SDCache>>(cache); + } else if (cache.size() >= 512) { + cache.clear(); } cache.put(key, res); } diff --git a/src/share/classes/sun/font/StrikeCache.java b/src/share/classes/sun/font/StrikeCache.java index 560be3af2cdf96c06704aa331989952de3d76299..56539e7489f853e09b37794e97986fa77e9c2ccf 100644 --- a/src/share/classes/sun/font/StrikeCache.java +++ b/src/share/classes/sun/font/StrikeCache.java @@ -232,6 +232,16 @@ public final class StrikeCache { if (disposer.pScalerContext != 0L) { freeLongMemory(new long[0], disposer.pScalerContext); } + } else if (disposer.pScalerContext != 0L) { + /* Rarely a strike may have been created that never cached + * any glyphs. In this case we still want to free the scaler + * context. + */ + if (FontManager.longAddresses) { + freeLongMemory(new long[0], disposer.pScalerContext); + } else { + freeIntMemory(new int[0], disposer.pScalerContext); + } } } diff --git a/src/share/classes/sun/java2d/cmm/ProfileActivator.java b/src/share/classes/sun/java2d/cmm/ProfileActivator.java index 32c4e477fb9ae013dd592977b4ae1b70be0368d2..f5a28f842328a4f76767e1fb37660e2493ebbe26 100644 --- a/src/share/classes/sun/java2d/cmm/ProfileActivator.java +++ b/src/share/classes/sun/java2d/cmm/ProfileActivator.java @@ -25,6 +25,7 @@ package sun.java2d.cmm; +import java.awt.color.ProfileDataException; /** * An interface to allow the ProfileDeferralMgr to activate a @@ -35,6 +36,6 @@ public interface ProfileActivator { /** * Activate a previously deferred ICC_Profile object. */ - public void activate(); + public void activate() throws ProfileDataException; } diff --git a/src/share/classes/sun/java2d/cmm/ProfileDeferralMgr.java b/src/share/classes/sun/java2d/cmm/ProfileDeferralMgr.java index 41804c3fd9b3d2839bab5487f2d5846cf98d6052..116f339da0a97485bb78ddb6e3ef010d17ee3c61 100644 --- a/src/share/classes/sun/java2d/cmm/ProfileDeferralMgr.java +++ b/src/share/classes/sun/java2d/cmm/ProfileDeferralMgr.java @@ -25,6 +25,7 @@ package sun.java2d.cmm; +import java.awt.color.ProfileDataException; import java.util.Vector; @@ -39,7 +40,7 @@ import java.util.Vector; public class ProfileDeferralMgr { public static boolean deferring = true; - private static Vector aVector; + private static Vector<ProfileActivator> aVector; /** * Records a ProfileActivator object whose activate method will @@ -51,7 +52,7 @@ public class ProfileDeferralMgr { return; } if (aVector == null) { - aVector = new Vector(3, 3); + aVector = new Vector<ProfileActivator>(3, 3); } aVector.addElement(pa); return; @@ -89,8 +90,26 @@ public class ProfileDeferralMgr { return; } n = aVector.size(); - for (i = 0; i < n; i++) { - ((ProfileActivator) aVector.get(i)).activate(); + for (ProfileActivator pa : aVector) { + try { + pa.activate(); + } catch (ProfileDataException e) { + /* + * Ignore profile activation error for now: + * such exception is pssible due to absence + * or corruption of standard color profile. + * As for now we expect all profiles should + * be shiped with jre and presence of this + * exception is indication of some configuration + * problem in jre installation. + * + * NB: we still are greedy loading deferred profiles + * and load them all if any of them is needed. + * Therefore broken profile (if any) might be never used. + * If there will be attempt to use broken profile then + * it will result in CMMException. + */ + } } aVector.removeAllElements(); aVector = null; diff --git a/src/share/classes/sun/java2d/pisces/Dasher.java b/src/share/classes/sun/java2d/pisces/Dasher.java index 81c92f44a6000bff2133cc9641c614743c4866c7..99215e01b8ed1b3b7ca11bec4c13e2551b5d5d82 100644 --- a/src/share/classes/sun/java2d/pisces/Dasher.java +++ b/src/share/classes/sun/java2d/pisces/Dasher.java @@ -120,7 +120,7 @@ public class Dasher extends LineSink { // Normalize so 0 <= phase < dash[0] int idx = 0; - dashOn = false; + dashOn = true; int d; while (phase >= (d = dash[idx])) { phase -= d; diff --git a/src/share/classes/sun/java2d/pisces/PiscesRenderingEngine.java b/src/share/classes/sun/java2d/pisces/PiscesRenderingEngine.java index 7f55e886c694149032a7e9dd13d15927f12d3160..12296daad2cf789503cb9e2d85ac37b4758e12cd 100644 --- a/src/share/classes/sun/java2d/pisces/PiscesRenderingEngine.java +++ b/src/share/classes/sun/java2d/pisces/PiscesRenderingEngine.java @@ -245,6 +245,7 @@ public class PiscesRenderingEngine extends RenderingEngine { FloatToS15_16(coords[1])); break; case PathIterator.SEG_CLOSE: + lsink.lineJoin(); lsink.close(); break; default: diff --git a/src/share/classes/sun/launcher/LauncherHelper.java b/src/share/classes/sun/launcher/LauncherHelper.java index 3951bcfeb12f6f1755fad8876959ca9686c446d8..76db55ebd34e4b841244518db68083eec9298c45 100644 --- a/src/share/classes/sun/launcher/LauncherHelper.java +++ b/src/share/classes/sun/launcher/LauncherHelper.java @@ -1,6 +1,5 @@ - /* - * Copyright 2007-2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2007-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 @@ -55,18 +54,24 @@ public enum LauncherHelper { INSTANCE; private static final String defaultBundleName = "sun.launcher.resources.launcher"; - private static ResourceBundle javarb = - ResourceBundle.getBundle(defaultBundleName); private static final String MAIN_CLASS = "Main-Class"; private static StringBuilder outBuf = new StringBuilder(); + private static ResourceBundle javarb = null; + private static synchronized ResourceBundle getLauncherResourceBundle() { + if (javarb == null) { + javarb = ResourceBundle.getBundle(defaultBundleName); + } + return javarb; + } + /** * A private helper method to get a localized message and also * apply any arguments that we might pass. */ private static String getLocalizedMessage(String key, Object... args) { - String msg = javarb.getString(key); + String msg = getLauncherResourceBundle().getString(key); return (args != null) ? MessageFormat.format(msg, args) : msg; } diff --git a/src/share/classes/sun/management/Agent.java b/src/share/classes/sun/management/Agent.java index e247412ba91c0a258dea940854a9e16934b2b518..edc53f93c6efb234cdbdac4a4217d8b90d4291c1 100644 --- a/src/share/classes/sun/management/Agent.java +++ b/src/share/classes/sun/management/Agent.java @@ -31,9 +31,9 @@ import java.io.FileInputStream; import java.io.BufferedInputStream; import java.io.FileNotFoundException; import java.io.IOException; +import java.lang.reflect.InvocationTargetException; import java.text.MessageFormat; import java.util.Properties; -import java.util.Enumeration; import java.util.ResourceBundle; import java.util.MissingResourceException; import java.lang.management.ManagementFactory; @@ -41,7 +41,6 @@ import java.lang.reflect.Method; import javax.management.remote.JMXConnectorServer; -import sun.management.snmp.AdaptorBootstrap; import sun.management.jmxremote.ConnectorBootstrap; import static sun.management.AgentConfigurationError.*; import sun.misc.VMSupport; @@ -69,6 +68,9 @@ public class Agent { private static final String LOCAL_CONNECTOR_ADDRESS_PROP = "com.sun.management.jmxremote.localConnectorAddress"; + private static final String SNMP_ADAPTOR_BOOTSTRAP_CLASS_NAME = + "sun.management.snmp.AdaptorBootstrap"; + // invoked by -javaagent or -Dcom.sun.management.agent.class public static void premain(String args) throws Exception { agentmain(args); @@ -128,7 +130,7 @@ public class Agent { try { if (snmpPort != null) { - AdaptorBootstrap.initialize(snmpPort, props); + loadSnmpAgent(snmpPort, props); } /* @@ -204,6 +206,36 @@ public class Agent { return mgmtProps; } + private static void loadSnmpAgent(String snmpPort, Properties props) { + try { + // invoke the following through reflection: + // AdaptorBootstrap.initialize(snmpPort, props); + final Class<?> adaptorClass = + Class.forName(SNMP_ADAPTOR_BOOTSTRAP_CLASS_NAME,true,null); + final Method initializeMethod = + adaptorClass.getMethod("initialize", + String.class, Properties.class); + initializeMethod.invoke(null,snmpPort,props); + } catch (ClassNotFoundException x) { + // The SNMP packages are not present: throws an exception. + throw new UnsupportedOperationException("Unsupported management property: " + SNMP_PORT,x); + } catch (NoSuchMethodException x) { + // should not happen... + throw new UnsupportedOperationException("Unsupported management property: " + SNMP_PORT,x); + } catch (InvocationTargetException x) { + final Throwable cause = x.getCause(); + if (cause instanceof RuntimeException) + throw (RuntimeException) cause; + else if (cause instanceof Error) + throw (Error) cause; + // should not happen... + throw new UnsupportedOperationException("Unsupported management property: " + SNMP_PORT,cause); + } catch (IllegalAccessException x) { + // should not happen... + throw new UnsupportedOperationException("Unsupported management property: " + SNMP_PORT,x); + } + } + // read config file and initialize the properties private static void readConfiguration(String fname, Properties p) { if (fname == null) { diff --git a/src/share/classes/sun/misc/ClassLoaderUtil.java b/src/share/classes/sun/misc/ClassLoaderUtil.java index b57dfccbb5c9b9d0c734fb2d58a5e3c878e15b3a..b71a89dfd337d1aa206d09ab6ae7bf7995891308 100644 --- a/src/share/classes/sun/misc/ClassLoaderUtil.java +++ b/src/share/classes/sun/misc/ClassLoaderUtil.java @@ -77,8 +77,6 @@ public class ClassLoaderUtil { jarsClosed.clear(); } - System.out.println ("classLoader = " + classLoader); - System.out.println ("SharedSecrets.getJavaNetAccess()="+SharedSecrets.getJavaNetAccess()); URLClassPath ucp = SharedSecrets.getJavaNetAccess() .getURLClassPath(classLoader); ArrayList loaders = ucp.loaders; diff --git a/src/share/classes/sun/misc/FloatingDecimal.java b/src/share/classes/sun/misc/FloatingDecimal.java index 46e4e55bc186f37e94175a30074af75b4a92f29f..f0316ff56315b4c917817c0bfedd961e9d9754f9 100644 --- a/src/share/classes/sun/misc/FloatingDecimal.java +++ b/src/share/classes/sun/misc/FloatingDecimal.java @@ -1867,10 +1867,16 @@ public class FloatingDecimal{ * Grammar is compatible with hexadecimal floating-point constants * described in section 6.4.4.2 of the C99 specification. */ - private static Pattern hexFloatPattern = Pattern.compile( + private static Pattern hexFloatPattern = null; + private static synchronized Pattern getHexFloatPattern() { + if (hexFloatPattern == null) { + hexFloatPattern = Pattern.compile( //1 234 56 7 8 9 "([-+])?0[xX](((\\p{XDigit}+)\\.?)|((\\p{XDigit}*)\\.(\\p{XDigit}+)))[pP]([-+])?(\\p{Digit}+)[fFdD]?" ); + } + return hexFloatPattern; + } /* * Convert string s to a suitable floating decimal; uses the @@ -1880,7 +1886,7 @@ public class FloatingDecimal{ static FloatingDecimal parseHexString(String s) { // Verify string is a member of the hexadecimal floating-point // string language. - Matcher m = hexFloatPattern.matcher(s); + Matcher m = getHexFloatPattern().matcher(s); boolean validInput = m.matches(); if (!validInput) { diff --git a/src/share/classes/sun/misc/FormattedFloatingDecimal.java b/src/share/classes/sun/misc/FormattedFloatingDecimal.java index a1a658a3e6fca6734faf582ecdacab9a4f9219e0..99ba522495086717583badc2c24a61c2456bc1c2 100644 --- a/src/share/classes/sun/misc/FormattedFloatingDecimal.java +++ b/src/share/classes/sun/misc/FormattedFloatingDecimal.java @@ -978,15 +978,6 @@ public class FormattedFloatingDecimal{ return new String(result); } - // This method should only ever be called if this object is constructed - // without Form.DECIMAL_FLOAT because the perThreadBuffer is not large - // enough to handle floating-point numbers of large precision. - public String toJavaFormatString() { - char result[] = (char[])(perThreadBuffer.get()); - int i = getChars(result); - return new String(result, 0, i); - } - // returns the exponent before rounding public int getExponent() { return decExponent - 1; @@ -1157,265 +1148,6 @@ public class FormattedFloatingDecimal{ } }; - // This method should only ever be called if this object is constructed - // without Form.DECIMAL_FLOAT because the perThreadBuffer is not large - // enough to handle floating-point numbers of large precision. - public void appendTo(Appendable buf) { - char result[] = (char[])(perThreadBuffer.get()); - int i = getChars(result); - if (buf instanceof StringBuilder) - ((StringBuilder) buf).append(result, 0, i); - else if (buf instanceof StringBuffer) - ((StringBuffer) buf).append(result, 0, i); - else - assert false; - } - - public static FormattedFloatingDecimal - readJavaFormatString( String in ) throws NumberFormatException { - boolean isNegative = false; - boolean signSeen = false; - int decExp; - char c; - - parseNumber: - try{ - in = in.trim(); // don't fool around with white space. - // throws NullPointerException if null - int l = in.length(); - if ( l == 0 ) throw new NumberFormatException("empty String"); - int i = 0; - switch ( c = in.charAt( i ) ){ - case '-': - isNegative = true; - //FALLTHROUGH - case '+': - i++; - signSeen = true; - } - - // Check for NaN and Infinity strings - c = in.charAt(i); - if(c == 'N' || c == 'I') { // possible NaN or infinity - boolean potentialNaN = false; - char targetChars[] = null; // char arrary of "NaN" or "Infinity" - - if(c == 'N') { - targetChars = notANumber; - potentialNaN = true; - } else { - targetChars = infinity; - } - - // compare Input string to "NaN" or "Infinity" - int j = 0; - while(i < l && j < targetChars.length) { - if(in.charAt(i) == targetChars[j]) { - i++; j++; - } - else // something is amiss, throw exception - break parseNumber; - } - - // For the candidate string to be a NaN or infinity, - // all characters in input string and target char[] - // must be matched ==> j must equal targetChars.length - // and i must equal l - if( (j == targetChars.length) && (i == l) ) { // return NaN or infinity - return (potentialNaN ? new FormattedFloatingDecimal(Double.NaN) // NaN has no sign - : new FormattedFloatingDecimal(isNegative? - Double.NEGATIVE_INFINITY: - Double.POSITIVE_INFINITY)) ; - } - else { // something went wrong, throw exception - break parseNumber; - } - - } else if (c == '0') { // check for hexadecimal floating-point number - if (l > i+1 ) { - char ch = in.charAt(i+1); - if (ch == 'x' || ch == 'X' ) // possible hex string - return parseHexString(in); - } - } // look for and process decimal floating-point string - - char[] digits = new char[ l ]; - int nDigits= 0; - boolean decSeen = false; - int decPt = 0; - int nLeadZero = 0; - int nTrailZero= 0; - digitLoop: - while ( i < l ){ - switch ( c = in.charAt( i ) ){ - case '0': - if ( nDigits > 0 ){ - nTrailZero += 1; - } else { - nLeadZero += 1; - } - break; // out of switch. - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - while ( nTrailZero > 0 ){ - digits[nDigits++] = '0'; - nTrailZero -= 1; - } - digits[nDigits++] = c; - break; // out of switch. - case '.': - if ( decSeen ){ - // already saw one ., this is the 2nd. - throw new NumberFormatException("multiple points"); - } - decPt = i; - if ( signSeen ){ - decPt -= 1; - } - decSeen = true; - break; // out of switch. - default: - break digitLoop; - } - i++; - } - /* - * At this point, we've scanned all the digits and decimal - * point we're going to see. Trim off leading and trailing - * zeros, which will just confuse us later, and adjust - * our initial decimal exponent accordingly. - * To review: - * we have seen i total characters. - * nLeadZero of them were zeros before any other digits. - * nTrailZero of them were zeros after any other digits. - * if ( decSeen ), then a . was seen after decPt characters - * ( including leading zeros which have been discarded ) - * nDigits characters were neither lead nor trailing - * zeros, nor point - */ - /* - * special hack: if we saw no non-zero digits, then the - * answer is zero! - * Unfortunately, we feel honor-bound to keep parsing! - */ - if ( nDigits == 0 ){ - digits = zero; - nDigits = 1; - if ( nLeadZero == 0 ){ - // we saw NO DIGITS AT ALL, - // not even a crummy 0! - // this is not allowed. - break parseNumber; // go throw exception - } - - } - - /* Our initial exponent is decPt, adjusted by the number of - * discarded zeros. Or, if there was no decPt, - * then its just nDigits adjusted by discarded trailing zeros. - */ - if ( decSeen ){ - decExp = decPt - nLeadZero; - } else { - decExp = nDigits+nTrailZero; - } - - /* - * Look for 'e' or 'E' and an optionally signed integer. - */ - if ( (i < l) && (((c = in.charAt(i) )=='e') || (c == 'E') ) ){ - int expSign = 1; - int expVal = 0; - int reallyBig = Integer.MAX_VALUE / 10; - boolean expOverflow = false; - switch( in.charAt(++i) ){ - case '-': - expSign = -1; - //FALLTHROUGH - case '+': - i++; - } - int expAt = i; - expLoop: - while ( i < l ){ - if ( expVal >= reallyBig ){ - // the next character will cause integer - // overflow. - expOverflow = true; - } - switch ( c = in.charAt(i++) ){ - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - expVal = expVal*10 + ( (int)c - (int)'0' ); - continue; - default: - i--; // back up. - break expLoop; // stop parsing exponent. - } - } - int expLimit = bigDecimalExponent+nDigits+nTrailZero; - if ( expOverflow || ( expVal > expLimit ) ){ - // - // The intent here is to end up with - // infinity or zero, as appropriate. - // The reason for yielding such a small decExponent, - // rather than something intuitive such as - // expSign*Integer.MAX_VALUE, is that this value - // is subject to further manipulation in - // doubleValue() and floatValue(), and I don't want - // it to be able to cause overflow there! - // (The only way we can get into trouble here is for - // really outrageous nDigits+nTrailZero, such as 2 billion. ) - // - decExp = expSign*expLimit; - } else { - // this should not overflow, since we tested - // for expVal > (MAX+N), where N >= abs(decExp) - decExp = decExp + expSign*expVal; - } - - // if we saw something not a digit ( or end of string ) - // after the [Ee][+-], without seeing any digits at all - // this is certainly an error. If we saw some digits, - // but then some trailing garbage, that might be ok. - // so we just fall through in that case. - // HUMBUG - if ( i == expAt ) - break parseNumber; // certainly bad - } - /* - * We parsed everything we could. - * If there are leftovers, then this is not good input! - */ - if ( i < l && - ((i != l - 1) || - (in.charAt(i) != 'f' && - in.charAt(i) != 'F' && - in.charAt(i) != 'd' && - in.charAt(i) != 'D'))) { - break parseNumber; // go throw exception - } - - return new FormattedFloatingDecimal( isNegative, decExp, digits, nDigits, false, Integer.MAX_VALUE, Form.COMPATIBLE ); - } catch ( StringIndexOutOfBoundsException e ){ } - throw new NumberFormatException("For input string: \"" + in + "\""); - } - /* * Take a FormattedFloatingDecimal, which we presumably just scanned in, * and find out what its value is, as a double. @@ -2035,548 +1767,4 @@ public class FormattedFloatingDecimal{ private static final char infinity[] = { 'I', 'n', 'f', 'i', 'n', 'i', 't', 'y' }; private static final char notANumber[] = { 'N', 'a', 'N' }; private static final char zero[] = { '0', '0', '0', '0', '0', '0', '0', '0' }; - - - /* - * Grammar is compatible with hexadecimal floating-point constants - * described in section 6.4.4.2 of the C99 specification. - */ - private static Pattern hexFloatPattern = Pattern.compile( - //1 234 56 7 8 9 - "([-+])?0[xX](((\\p{XDigit}+)\\.?)|((\\p{XDigit}*)\\.(\\p{XDigit}+)))[pP]([-+])?(\\p{Digit}+)[fFdD]?" - ); - - /* - * Convert string s to a suitable floating decimal; uses the - * double constructor and set the roundDir variable appropriately - * in case the value is later converted to a float. - */ - static FormattedFloatingDecimal parseHexString(String s) { - // Verify string is a member of the hexadecimal floating-point - // string language. - Matcher m = hexFloatPattern.matcher(s); - boolean validInput = m.matches(); - - if (!validInput) { - // Input does not match pattern - throw new NumberFormatException("For input string: \"" + s + "\""); - } else { // validInput - /* - * We must isolate the sign, significand, and exponent - * fields. The sign value is straightforward. Since - * floating-point numbers are stored with a normalized - * representation, the significand and exponent are - * interrelated. - * - * After extracting the sign, we normalized the - * significand as a hexadecimal value, calculating an - * exponent adjust for any shifts made during - * normalization. If the significand is zero, the - * exponent doesn't need to be examined since the output - * will be zero. - * - * Next the exponent in the input string is extracted. - * Afterwards, the significand is normalized as a *binary* - * value and the input value's normalized exponent can be - * computed. The significand bits are copied into a - * double significand; if the string has more logical bits - * than can fit in a double, the extra bits affect the - * round and sticky bits which are used to round the final - * value. - */ - - // Extract significand sign - String group1 = m.group(1); - double sign = (( group1 == null ) || group1.equals("+"))? 1.0 : -1.0; - - - // Extract Significand magnitude - /* - * Based on the form of the significand, calculate how the - * binary exponent needs to be adjusted to create a - * normalized *hexadecimal* floating-point number; that - * is, a number where there is one nonzero hex digit to - * the left of the (hexa)decimal point. Since we are - * adjusting a binary, not hexadecimal exponent, the - * exponent is adjusted by a multiple of 4. - * - * There are a number of significand scenarios to consider; - * letters are used in indicate nonzero digits: - * - * 1. 000xxxx => x.xxx normalized - * increase exponent by (number of x's - 1)*4 - * - * 2. 000xxx.yyyy => x.xxyyyy normalized - * increase exponent by (number of x's - 1)*4 - * - * 3. .000yyy => y.yy normalized - * decrease exponent by (number of zeros + 1)*4 - * - * 4. 000.00000yyy => y.yy normalized - * decrease exponent by (number of zeros to right of point + 1)*4 - * - * If the significand is exactly zero, return a properly - * signed zero. - */ - - String significandString =null; - int signifLength = 0; - int exponentAdjust = 0; - { - int leftDigits = 0; // number of meaningful digits to - // left of "decimal" point - // (leading zeros stripped) - int rightDigits = 0; // number of digits to right of - // "decimal" point; leading zeros - // must always be accounted for - /* - * The significand is made up of either - * - * 1. group 4 entirely (integer portion only) - * - * OR - * - * 2. the fractional portion from group 7 plus any - * (optional) integer portions from group 6. - */ - String group4; - if( (group4 = m.group(4)) != null) { // Integer-only significand - // Leading zeros never matter on the integer portion - significandString = stripLeadingZeros(group4); - leftDigits = significandString.length(); - } - else { - // Group 6 is the optional integer; leading zeros - // never matter on the integer portion - String group6 = stripLeadingZeros(m.group(6)); - leftDigits = group6.length(); - - // fraction - String group7 = m.group(7); - rightDigits = group7.length(); - - // Turn "integer.fraction" into "integer"+"fraction" - significandString = - ((group6 == null)?"":group6) + // is the null - // check necessary? - group7; - } - - significandString = stripLeadingZeros(significandString); - signifLength = significandString.length(); - - /* - * Adjust exponent as described above - */ - if (leftDigits >= 1) { // Cases 1 and 2 - exponentAdjust = 4*(leftDigits - 1); - } else { // Cases 3 and 4 - exponentAdjust = -4*( rightDigits - signifLength + 1); - } - - // If the significand is zero, the exponent doesn't - // matter; return a properly signed zero. - - if (signifLength == 0) { // Only zeros in input - return new FormattedFloatingDecimal(sign * 0.0); - } - } - - // Extract Exponent - /* - * Use an int to read in the exponent value; this should - * provide more than sufficient range for non-contrived - * inputs. If reading the exponent in as an int does - * overflow, examine the sign of the exponent and - * significand to determine what to do. - */ - String group8 = m.group(8); - boolean positiveExponent = ( group8 == null ) || group8.equals("+"); - long unsignedRawExponent; - try { - unsignedRawExponent = Integer.parseInt(m.group(9)); - } - catch (NumberFormatException e) { - // At this point, we know the exponent is - // syntactically well-formed as a sequence of - // digits. Therefore, if an NumberFormatException - // is thrown, it must be due to overflowing int's - // range. Also, at this point, we have already - // checked for a zero significand. Thus the signs - // of the exponent and significand determine the - // final result: - // - // significand - // + - - // exponent + +infinity -infinity - // - +0.0 -0.0 - return new FormattedFloatingDecimal(sign * (positiveExponent ? - Double.POSITIVE_INFINITY : 0.0)); - } - - long rawExponent = - (positiveExponent ? 1L : -1L) * // exponent sign - unsignedRawExponent; // exponent magnitude - - // Calculate partially adjusted exponent - long exponent = rawExponent + exponentAdjust ; - - // Starting copying non-zero bits into proper position in - // a long; copy explicit bit too; this will be masked - // later for normal values. - - boolean round = false; - boolean sticky = false; - int bitsCopied=0; - int nextShift=0; - long significand=0L; - // First iteration is different, since we only copy - // from the leading significand bit; one more exponent - // adjust will be needed... - - // IMPORTANT: make leadingDigit a long to avoid - // surprising shift semantics! - long leadingDigit = getHexDigit(significandString, 0); - - /* - * Left shift the leading digit (53 - (bit position of - * leading 1 in digit)); this sets the top bit of the - * significand to 1. The nextShift value is adjusted - * to take into account the number of bit positions of - * the leadingDigit actually used. Finally, the - * exponent is adjusted to normalize the significand - * as a binary value, not just a hex value. - */ - if (leadingDigit == 1) { - significand |= leadingDigit << 52; - nextShift = 52 - 4; - /* exponent += 0 */ } - else if (leadingDigit <= 3) { // [2, 3] - significand |= leadingDigit << 51; - nextShift = 52 - 5; - exponent += 1; - } - else if (leadingDigit <= 7) { // [4, 7] - significand |= leadingDigit << 50; - nextShift = 52 - 6; - exponent += 2; - } - else if (leadingDigit <= 15) { // [8, f] - significand |= leadingDigit << 49; - nextShift = 52 - 7; - exponent += 3; - } else { - throw new AssertionError("Result from digit converstion too large!"); - } - // The preceding if-else could be replaced by a single - // code block based on the high-order bit set in - // leadingDigit. Given leadingOnePosition, - - // significand |= leadingDigit << (SIGNIFICAND_WIDTH - leadingOnePosition); - // nextShift = 52 - (3 + leadingOnePosition); - // exponent += (leadingOnePosition-1); - - - /* - * Now the exponent variable is equal to the normalized - * binary exponent. Code below will make representation - * adjustments if the exponent is incremented after - * rounding (includes overflows to infinity) or if the - * result is subnormal. - */ - - // Copy digit into significand until the significand can't - // hold another full hex digit or there are no more input - // hex digits. - int i = 0; - for(i = 1; - i < signifLength && nextShift >= 0; - i++) { - long currentDigit = getHexDigit(significandString, i); - significand |= (currentDigit << nextShift); - nextShift-=4; - } - - // After the above loop, the bulk of the string is copied. - // Now, we must copy any partial hex digits into the - // significand AND compute the round bit and start computing - // sticky bit. - - if ( i < signifLength ) { // at least one hex input digit exists - long currentDigit = getHexDigit(significandString, i); - - // from nextShift, figure out how many bits need - // to be copied, if any - switch(nextShift) { // must be negative - case -1: - // three bits need to be copied in; can - // set round bit - significand |= ((currentDigit & 0xEL) >> 1); - round = (currentDigit & 0x1L) != 0L; - break; - - case -2: - // two bits need to be copied in; can - // set round and start sticky - significand |= ((currentDigit & 0xCL) >> 2); - round = (currentDigit &0x2L) != 0L; - sticky = (currentDigit & 0x1L) != 0; - break; - - case -3: - // one bit needs to be copied in - significand |= ((currentDigit & 0x8L)>>3); - // Now set round and start sticky, if possible - round = (currentDigit &0x4L) != 0L; - sticky = (currentDigit & 0x3L) != 0; - break; - - case -4: - // all bits copied into significand; set - // round and start sticky - round = ((currentDigit & 0x8L) != 0); // is top bit set? - // nonzeros in three low order bits? - sticky = (currentDigit & 0x7L) != 0; - break; - - default: - throw new AssertionError("Unexpected shift distance remainder."); - // break; - } - - // Round is set; sticky might be set. - - // For the sticky bit, it suffices to check the - // current digit and test for any nonzero digits in - // the remaining unprocessed input. - i++; - while(i < signifLength && !sticky) { - currentDigit = getHexDigit(significandString,i); - sticky = sticky || (currentDigit != 0); - i++; - } - - } - // else all of string was seen, round and sticky are - // correct as false. - - - // Check for overflow and update exponent accordingly. - - if (exponent > DoubleConsts.MAX_EXPONENT) { // Infinite result - // overflow to properly signed infinity - return new FormattedFloatingDecimal(sign * Double.POSITIVE_INFINITY); - } else { // Finite return value - if (exponent <= DoubleConsts.MAX_EXPONENT && // (Usually) normal result - exponent >= DoubleConsts.MIN_EXPONENT) { - - // The result returned in this block cannot be a - // zero or subnormal; however after the - // significand is adjusted from rounding, we could - // still overflow in infinity. - - // AND exponent bits into significand; if the - // significand is incremented and overflows from - // rounding, this combination will update the - // exponent correctly, even in the case of - // Double.MAX_VALUE overflowing to infinity. - - significand = (( ((long)exponent + - (long)DoubleConsts.EXP_BIAS) << - (DoubleConsts.SIGNIFICAND_WIDTH-1)) - & DoubleConsts.EXP_BIT_MASK) | - (DoubleConsts.SIGNIF_BIT_MASK & significand); - - } else { // Subnormal or zero - // (exponent < DoubleConsts.MIN_EXPONENT) - - if (exponent < (DoubleConsts.MIN_SUB_EXPONENT -1 )) { - // No way to round back to nonzero value - // regardless of significand if the exponent is - // less than -1075. - return new FormattedFloatingDecimal(sign * 0.0); - } else { // -1075 <= exponent <= MIN_EXPONENT -1 = -1023 - /* - * Find bit position to round to; recompute - * round and sticky bits, and shift - * significand right appropriately. - */ - - sticky = sticky || round; - round = false; - - // Number of bits of significand to preserve is - // exponent - abs_min_exp +1 - // check: - // -1075 +1074 + 1 = 0 - // -1023 +1074 + 1 = 52 - - int bitsDiscarded = 53 - - ((int)exponent - DoubleConsts.MIN_SUB_EXPONENT + 1); - assert bitsDiscarded >= 1 && bitsDiscarded <= 53; - - // What to do here: - // First, isolate the new round bit - round = (significand & (1L << (bitsDiscarded -1))) != 0L; - if (bitsDiscarded > 1) { - // create mask to update sticky bits; low - // order bitsDiscarded bits should be 1 - long mask = ~((~0L) << (bitsDiscarded -1)); - sticky = sticky || ((significand & mask) != 0L ) ; - } - - // Now, discard the bits - significand = significand >> bitsDiscarded; - - significand = (( ((long)(DoubleConsts.MIN_EXPONENT -1) + // subnorm exp. - (long)DoubleConsts.EXP_BIAS) << - (DoubleConsts.SIGNIFICAND_WIDTH-1)) - & DoubleConsts.EXP_BIT_MASK) | - (DoubleConsts.SIGNIF_BIT_MASK & significand); - } - } - - // The significand variable now contains the currently - // appropriate exponent bits too. - - /* - * Determine if significand should be incremented; - * making this determination depends on the least - * significant bit and the round and sticky bits. - * - * Round to nearest even rounding table, adapted from - * table 4.7 in "Computer Arithmetic" by IsraelKoren. - * The digit to the left of the "decimal" point is the - * least significant bit, the digits to the right of - * the point are the round and sticky bits - * - * Number Round(x) - * x0.00 x0. - * x0.01 x0. - * x0.10 x0. - * x0.11 x1. = x0. +1 - * x1.00 x1. - * x1.01 x1. - * x1.10 x1. + 1 - * x1.11 x1. + 1 - */ - boolean incremented = false; - boolean leastZero = ((significand & 1L) == 0L); - if( ( leastZero && round && sticky ) || - ((!leastZero) && round )) { - incremented = true; - significand++; - } - - FormattedFloatingDecimal fd = new FormattedFloatingDecimal(FpUtils.rawCopySign( - Double.longBitsToDouble(significand), - sign)); - - /* - * Set roundingDir variable field of fd properly so - * that the input string can be properly rounded to a - * float value. There are two cases to consider: - * - * 1. rounding to double discards sticky bit - * information that would change the result of a float - * rounding (near halfway case between two floats) - * - * 2. rounding to double rounds up when rounding up - * would not occur when rounding to float. - * - * For former case only needs to be considered when - * the bits rounded away when casting to float are all - * zero; otherwise, float round bit is properly set - * and sticky will already be true. - * - * The lower exponent bound for the code below is the - * minimum (normalized) subnormal exponent - 1 since a - * value with that exponent can round up to the - * minimum subnormal value and the sticky bit - * information must be preserved (i.e. case 1). - */ - if ((exponent >= FloatConsts.MIN_SUB_EXPONENT-1) && - (exponent <= FloatConsts.MAX_EXPONENT ) ){ - // Outside above exponent range, the float value - // will be zero or infinity. - - /* - * If the low-order 28 bits of a rounded double - * significand are 0, the double could be a - * half-way case for a rounding to float. If the - * double value is a half-way case, the double - * significand may have to be modified to round - * the the right float value (see the stickyRound - * method). If the rounding to double has lost - * what would be float sticky bit information, the - * double significand must be incremented. If the - * double value's significand was itself - * incremented, the float value may end up too - * large so the increment should be undone. - */ - if ((significand & 0xfffffffL) == 0x0L) { - // For negative values, the sign of the - // roundDir is the same as for positive values - // since adding 1 increasing the significand's - // magnitude and subtracting 1 decreases the - // significand's magnitude. If neither round - // nor sticky is true, the double value is - // exact and no adjustment is required for a - // proper float rounding. - if( round || sticky) { - if (leastZero) { // prerounding lsb is 0 - // If round and sticky were both true, - // and the least significant - // significand bit were 0, the rounded - // significand would not have its - // low-order bits be zero. Therefore, - // we only need to adjust the - // significand if round XOR sticky is - // true. - if (round ^ sticky) { - fd.roundDir = 1; - } - } - else { // prerounding lsb is 1 - // If the prerounding lsb is 1 and the - // resulting significand has its - // low-order bits zero, the significand - // was incremented. Here, we undo the - // increment, which will ensure the - // right guard and sticky bits for the - // float rounding. - if (round) - fd.roundDir = -1; - } - } - } - } - - fd.fromHex = true; - return fd; - } - } - } - - /** - * Return <code>s</code> with any leading zeros removed. - */ - static String stripLeadingZeros(String s) { - return s.replaceFirst("^0+", ""); - } - - /** - * Extract a hexadecimal digit from position <code>position</code> - * of string <code>s</code>. - */ - static int getHexDigit(String s, int position) { - int value = Character.digit(s.charAt(position), 16); - if (value <= -1 || value >= 16) { - throw new AssertionError("Unxpected failure of digit converstion of " + - s.charAt(position)); - } - return value; - } - - } diff --git a/src/share/classes/sun/misc/JavaIOAccess.java b/src/share/classes/sun/misc/JavaIOAccess.java index 2a076a9d84de8d71659023dd94af4a53eaa61bac..f0b50a8ac4e3dd8343cb5cadb8fd20dd9c0faf7e 100644 --- a/src/share/classes/sun/misc/JavaIOAccess.java +++ b/src/share/classes/sun/misc/JavaIOAccess.java @@ -29,6 +29,5 @@ import java.nio.charset.Charset; public interface JavaIOAccess { public Console console(); - public Runnable consoleRestoreHook(); public Charset charset(); } diff --git a/src/share/classes/sun/misc/JavaLangAccess.java b/src/share/classes/sun/misc/JavaLangAccess.java index 7c1cc55032f7e9431d7fbe17554fba478c857897..c288bc8402f04f7af27fb967b0d4830c6cdacde3 100644 --- a/src/share/classes/sun/misc/JavaLangAccess.java +++ b/src/share/classes/sun/misc/JavaLangAccess.java @@ -54,4 +54,7 @@ public interface JavaLangAccess { /** Set thread's blocker field. */ void blockedOn(Thread t, Interruptible b); + + /** register shutdown hook */ + void registerShutdownHook(int slot, Runnable r); } diff --git a/src/share/classes/sun/misc/Launcher.java b/src/share/classes/sun/misc/Launcher.java index a64986e6260eb48a9c14766ec7ce376ba7f0c164..030d3e571a1498909b4ccb271c043ba13cde899a 100644 --- a/src/share/classes/sun/misc/Launcher.java +++ b/src/share/classes/sun/misc/Launcher.java @@ -1,5 +1,5 @@ /* - * Copyright 1998-2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 1998-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 @@ -120,7 +120,10 @@ public class Launcher { * The class loader used for loading installed extensions. */ static class ExtClassLoader extends URLClassLoader { - private File[] dirs; + + static { + ClassLoader.registerAsParallelCapable(); + } /** * create an ExtClassLoader. The ExtClassLoader is created @@ -146,12 +149,12 @@ public class Launcher { } }); } catch (java.security.PrivilegedActionException e) { - throw (IOException) e.getException(); + throw (IOException) e.getException(); } } void addExtURL(URL url) { - super.addURL(url); + super.addURL(url); } /* @@ -159,7 +162,6 @@ public class Launcher { */ public ExtClassLoader(File[] dirs) throws IOException { super(getExtURLs(dirs), null, factory); - this.dirs = dirs; } private static File[] getExtDirs() { @@ -206,20 +208,27 @@ public class Launcher { */ public String findLibrary(String name) { name = System.mapLibraryName(name); - for (int i = 0; i < dirs.length; i++) { - // Look in architecture-specific subdirectory first - String arch = System.getProperty("os.arch"); - if (arch != null) { - File file = new File(new File(dirs[i], arch), name); + URL[] urls = super.getURLs(); + File prevDir = null; + for (int i = 0; i < urls.length; i++) { + // Get the ext directory from the URL + File dir = new File(urls[i].getPath()).getParentFile(); + if (dir != null && !dir.equals(prevDir)) { + // Look in architecture-specific subdirectory first + String arch = System.getProperty("os.arch"); + if (arch != null) { + File file = new File(new File(dir, arch), name); + if (file.exists()) { + return file.getAbsolutePath(); + } + } + // Then check the extension directory + File file = new File(dir, name); if (file.exists()) { return file.getAbsolutePath(); } } - // Then check the extension directory - File file = new File(dirs[i], name); - if (file.exists()) { - return file.getAbsolutePath(); - } + prevDir = dir; } return null; } @@ -248,6 +257,10 @@ public class Launcher { */ static class AppClassLoader extends URLClassLoader { + static { + ClassLoader.registerAsParallelCapable(); + } + public static ClassLoader getAppClassLoader(final ClassLoader extcl) throws IOException { @@ -281,7 +294,7 @@ public class Launcher { /** * Override loadClass so we can checkPackageAccess. */ - public synchronized Class loadClass(String name, boolean resolve) + public Class loadClass(String name, boolean resolve) throws ClassNotFoundException { int i = name.lastIndexOf('.'); diff --git a/src/share/classes/sun/misc/SharedSecrets.java b/src/share/classes/sun/misc/SharedSecrets.java index 938e54c6c503a96fc788bc3260610545924332ae..16b5727c60444cf4999deeb3f917cb82639673bd 100644 --- a/src/share/classes/sun/misc/SharedSecrets.java +++ b/src/share/classes/sun/misc/SharedSecrets.java @@ -44,7 +44,6 @@ public class SharedSecrets { private static JavaUtilJarAccess javaUtilJarAccess; private static JavaLangAccess javaLangAccess; private static JavaIOAccess javaIOAccess; - private static JavaIODeleteOnExitAccess javaIODeleteOnExitAccess; private static JavaNetAccess javaNetAccess; private static JavaNioAccess javaNioAccess; private static JavaIOFileDescriptorAccess javaIOFileDescriptorAccess; @@ -103,17 +102,6 @@ public class SharedSecrets { return javaIOAccess; } - public static void setJavaIODeleteOnExitAccess(JavaIODeleteOnExitAccess jida) { - javaIODeleteOnExitAccess = jida; - } - - public static JavaIODeleteOnExitAccess getJavaIODeleteOnExitAccess() { - if (javaIODeleteOnExitAccess == null) { - unsafe.ensureClassInitialized(File.class); - } - return javaIODeleteOnExitAccess; - } - public static void setJavaIOFileDescriptorAccess(JavaIOFileDescriptorAccess jiofda) { javaIOFileDescriptorAccess = jiofda; } diff --git a/src/share/classes/sun/net/spi/DefaultProxySelector.java b/src/share/classes/sun/net/spi/DefaultProxySelector.java index a4fd7df23e15ede56b2a2795bb00681e4dc58566..714dc4ce5c3ba133a47825a1a13ab674ead65e63 100644 --- a/src/share/classes/sun/net/spi/DefaultProxySelector.java +++ b/src/share/classes/sun/net/spi/DefaultProxySelector.java @@ -78,7 +78,6 @@ public class DefaultProxySelector extends ProxySelector { }; private static boolean hasSystemProxies = false; - private static Properties defprops = new Properties(); static { final String key = "java.net.useSystemProxies"; @@ -107,6 +106,9 @@ public class DefaultProxySelector extends ProxySelector { RegexpPool hostsPool; String property; + static NonProxyInfo ftpNonProxyInfo = new NonProxyInfo("ftp.nonProxyHosts", null, null); + static NonProxyInfo httpNonProxyInfo = new NonProxyInfo("http.nonProxyHosts", null, null); + NonProxyInfo(String p, String s, RegexpPool pool) { property = p; hostsSource = s; @@ -114,8 +116,6 @@ public class DefaultProxySelector extends ProxySelector { } } - private static NonProxyInfo ftpNonProxyInfo = new NonProxyInfo("ftp.nonProxyHosts", null, null); - private static NonProxyInfo httpNonProxyInfo = new NonProxyInfo("http.nonProxyHosts", null, null); /** * select() method. Where all the hard work is done. @@ -175,13 +175,13 @@ public class DefaultProxySelector extends ProxySelector { NonProxyInfo pinfo = null; if ("http".equalsIgnoreCase(protocol)) { - pinfo = httpNonProxyInfo; + pinfo = NonProxyInfo.httpNonProxyInfo; } else if ("https".equalsIgnoreCase(protocol)) { // HTTPS uses the same property as HTTP, for backward // compatibility - pinfo = httpNonProxyInfo; + pinfo = NonProxyInfo.httpNonProxyInfo; } else if ("ftp".equalsIgnoreCase(protocol)) { - pinfo = ftpNonProxyInfo; + pinfo = NonProxyInfo.ftpNonProxyInfo; } /** @@ -334,7 +334,6 @@ public class DefaultProxySelector extends ProxySelector { } } - private static final Pattern p6 = Pattern.compile("::1|(0:){7}1|(0:){1,6}:1"); private boolean isLoopback(String host) { if (host == null || host.length() == 0) return false; @@ -364,6 +363,7 @@ public class DefaultProxySelector extends ProxySelector { } if (host.endsWith(":1")) { + final Pattern p6 = Pattern.compile("::1|(0:){7}1|(0:){1,6}:1"); return p6.matcher(host).matches(); } return false; diff --git a/src/share/classes/sun/nio/ch/AbstractFuture.java b/src/share/classes/sun/nio/ch/AbstractFuture.java new file mode 100644 index 0000000000000000000000000000000000000000..f79dc7abbbfa2ea658c298d4bca20ba66e4fecb2 --- /dev/null +++ b/src/share/classes/sun/nio/ch/AbstractFuture.java @@ -0,0 +1,63 @@ +/* + * Copyright 2008-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 sun.nio.ch; + +import java.nio.channels.AsynchronousChannel; +import java.util.concurrent.Future; + +/** + * Base implementation of Future used for asynchronous I/O + */ + +abstract class AbstractFuture<V,A> + implements Future<V> +{ + private final AsynchronousChannel channel; + private final A attachment; + + protected AbstractFuture(AsynchronousChannel channel, A attachment) { + this.channel = channel; + this.attachment = attachment; + } + + final AsynchronousChannel channel() { + return channel; + } + + final A attachment() { + return attachment; + } + + /** + * Returns the result of the operation if it has completed successfully. + */ + abstract V value(); + + /** + * Returns the exception if the operation has failed. + */ + abstract Throwable exception(); +} diff --git a/src/share/classes/sun/nio/ch/AsynchronousChannelGroupImpl.java b/src/share/classes/sun/nio/ch/AsynchronousChannelGroupImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..14e33ffe9d138f14c2217578d2facc0e3bae3762 --- /dev/null +++ b/src/share/classes/sun/nio/ch/AsynchronousChannelGroupImpl.java @@ -0,0 +1,341 @@ +/* + * Copyright 2008-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 sun.nio.ch; + +import java.nio.channels.Channel; +import java.nio.channels.AsynchronousChannelGroup; +import java.nio.channels.spi.AsynchronousChannelProvider; +import java.io.IOException; +import java.io.FileDescriptor; +import java.util.Queue; +import java.util.concurrent.*; +import java.util.concurrent.locks.*; +import java.util.concurrent.atomic.AtomicInteger; +import java.security.PrivilegedAction; +import java.security.AccessController; +import java.security.AccessControlContext; +import sun.security.action.GetIntegerAction; + +/** + * Base implementation of AsynchronousChannelGroup + */ + +abstract class AsynchronousChannelGroupImpl + extends AsynchronousChannelGroup implements Executor +{ + // number of internal threads handling I/O events when using an unbounded + // thread pool. Internal threads do not dispatch to completion handlers. + private static final int internalThreadCount = AccessController.doPrivileged( + new GetIntegerAction("sun.nio.ch.internalThreadPoolSize", 1)); + + // associated thread pool + private final ThreadPool pool; + + // number of tasks running (including internal) + private final AtomicInteger threadCount = new AtomicInteger(); + + // associated Executor for timeouts + private ScheduledThreadPoolExecutor timeoutExecutor; + + // task queue for when using a fixed thread pool. In that case, thread + // waiting on I/O events must be awokon to poll tasks from this queue. + private final Queue<Runnable> taskQueue; + + // group shutdown + // shutdownLock is RW lock so as to allow for concurrent queuing of tasks + // when using a fixed thread pool. + private final ReadWriteLock shutdownLock = new ReentrantReadWriteLock(); + private final Object shutdownNowLock = new Object(); + private volatile boolean shutdown; + private volatile boolean terminateInitiated; + + AsynchronousChannelGroupImpl(AsynchronousChannelProvider provider, + ThreadPool pool) + { + super(provider); + this.pool = pool; + + if (pool.isFixedThreadPool()) { + taskQueue = new ConcurrentLinkedQueue<Runnable>(); + } else { + taskQueue = null; // not used + } + + // use default thread factory as thread should not be visible to + // application (it doesn't execute completion handlers). + this.timeoutExecutor = (ScheduledThreadPoolExecutor) + Executors.newScheduledThreadPool(1, ThreadPool.defaultThreadFactory()); + this.timeoutExecutor.setRemoveOnCancelPolicy(true); + } + + final ExecutorService executor() { + return pool.executor(); + } + + final boolean isFixedThreadPool() { + return pool.isFixedThreadPool(); + } + + final int fixedThreadCount() { + if (isFixedThreadPool()) { + return pool.poolSize(); + } else { + return pool.poolSize() + internalThreadCount; + } + } + + private Runnable bindToGroup(final Runnable task) { + final AsynchronousChannelGroupImpl thisGroup = this; + return new Runnable() { + public void run() { + Invoker.bindToGroup(thisGroup); + task.run(); + } + }; + } + + private void startInternalThread(final Runnable task) { + AccessController.doPrivileged(new PrivilegedAction<Void>() { + @Override + public Void run() { + // internal threads should not be visible to application so + // cannot use user-supplied thread factory + ThreadPool.defaultThreadFactory().newThread(task).start(); + return null; + } + }); + } + + protected final void startThreads(Runnable task) { + if (!isFixedThreadPool()) { + for (int i=0; i<internalThreadCount; i++) { + startInternalThread(task); + threadCount.incrementAndGet(); + } + } + if (pool.poolSize() > 0) { + task = bindToGroup(task); + try { + for (int i=0; i<pool.poolSize(); i++) { + pool.executor().execute(task); + threadCount.incrementAndGet(); + } + } catch (RejectedExecutionException x) { + // nothing we can do + } + } + } + + final int threadCount() { + return threadCount.get(); + } + + /** + * Invoked by tasks as they terminate + */ + final int threadExit(Runnable task, boolean replaceMe) { + if (replaceMe) { + try { + if (Invoker.isBoundToAnyGroup()) { + // submit new task to replace this thread + pool.executor().execute(bindToGroup(task)); + } else { + // replace internal thread + startInternalThread(task); + } + return threadCount.get(); + } catch (RejectedExecutionException x) { + // unable to replace + } + } + return threadCount.decrementAndGet(); + } + + /** + * Wakes up a thread waiting for I/O events to execute the given task. + */ + abstract void executeOnHandlerTask(Runnable task); + + /** + * For a fixed thread pool the task is queued to a thread waiting on I/O + * events. For other thread pools we simply submit the task to the thread + * pool. + */ + final void executeOnPooledThread(Runnable task) { + if (isFixedThreadPool()) { + executeOnHandlerTask(task); + } else { + pool.executor().execute(bindToGroup(task)); + } + } + + final void offerTask(Runnable task) { + taskQueue.offer(task); + } + + final Runnable pollTask() { + return (taskQueue == null) ? null : taskQueue.poll(); + } + + final Future<?> schedule(Runnable task, long timeout, TimeUnit unit) { + try { + return timeoutExecutor.schedule(task, timeout, unit); + } catch (RejectedExecutionException rej) { + if (terminateInitiated) { + // no timeout scheduled as group is terminating + return null; + } + throw new AssertionError(rej); + } + } + + @Override + public final boolean isShutdown() { + return shutdown; + } + + @Override + public final boolean isTerminated() { + return pool.executor().isTerminated(); + } + + /** + * Returns true if there are no channels in the group + */ + abstract boolean isEmpty(); + + /** + * Attaches a foreign channel to this group. + */ + abstract Object attachForeignChannel(Channel channel, FileDescriptor fdo) + throws IOException; + + /** + * Detaches a foreign channel from this group. + */ + abstract void detachForeignChannel(Object key); + + /** + * Closes all channels in the group + */ + abstract void closeAllChannels() throws IOException; + + /** + * Shutdown all tasks waiting for I/O events. + */ + abstract void shutdownHandlerTasks(); + + private void shutdownExecutors() { + AccessController.doPrivileged(new PrivilegedAction<Void>() { + public Void run() { + pool.executor().shutdown(); + timeoutExecutor.shutdown(); + return null; + } + }); + } + + @Override + public final void shutdown() { + shutdownLock.writeLock().lock(); + try { + if (shutdown) { + // already shutdown + return; + } + shutdown = true; + } finally { + shutdownLock.writeLock().unlock(); + } + + // if there are channels in the group then shutdown will continue + // when the last channel is closed + if (!isEmpty()) { + return; + } + // initiate termination (acquire shutdownNowLock to ensure that other + // threads invoking shutdownNow will block). + synchronized (shutdownNowLock) { + if (!terminateInitiated) { + terminateInitiated = true; + shutdownHandlerTasks(); + shutdownExecutors(); + } + } + } + + @Override + public final void shutdownNow() throws IOException { + shutdownLock.writeLock().lock(); + try { + shutdown = true; + } finally { + shutdownLock.writeLock().unlock(); + } + synchronized (shutdownNowLock) { + if (!terminateInitiated) { + terminateInitiated = true; + closeAllChannels(); + shutdownHandlerTasks(); + shutdownExecutors(); + } + } + } + + @Override + public final boolean awaitTermination(long timeout, TimeUnit unit) + throws InterruptedException + { + return pool.executor().awaitTermination(timeout, unit); + } + + /** + * Executes the given command on one of the channel group's pooled threads. + */ + @Override + public final void execute(Runnable task) { + SecurityManager sm = System.getSecurityManager(); + if (sm != null) { + // when a security manager is installed then the user's task + // must be run with the current calling context + final AccessControlContext acc = AccessController.getContext(); + final Runnable delegate = task; + task = new Runnable() { + @Override + public void run() { + AccessController.doPrivileged(new PrivilegedAction<Void>() { + @Override + public Void run() { + delegate.run(); + return null; + } + }, acc); + } + }; + } + executeOnPooledThread(task); + } +} diff --git a/src/share/classes/sun/nio/ch/AsynchronousFileChannelImpl.java b/src/share/classes/sun/nio/ch/AsynchronousFileChannelImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..2735a5a29cdd2a4024848505cd6167e81fa92e20 --- /dev/null +++ b/src/share/classes/sun/nio/ch/AsynchronousFileChannelImpl.java @@ -0,0 +1,164 @@ +/* + * Copyright 2008-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 sun.nio.ch; + +import java.nio.channels.*; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.locks.*; +import java.io.FileDescriptor; +import java.io.IOException; + +/** + * Base implementation of AsynchronousFileChannel. + */ + +abstract class AsynchronousFileChannelImpl + extends AsynchronousFileChannel +{ + // close support + protected final ReadWriteLock closeLock = new ReentrantReadWriteLock(); + protected volatile boolean closed; + + // file descriptor + protected final FileDescriptor fdObj; + + // indicates if open for reading/writing + protected final boolean reading; + protected final boolean writing; + + // associated Executor + protected final ExecutorService executor; + + protected AsynchronousFileChannelImpl(FileDescriptor fdObj, + boolean reading, + boolean writing, + ExecutorService executor) + { + this.fdObj = fdObj; + this.reading = reading; + this.writing = writing; + this.executor = executor; + } + + final ExecutorService executor() { + return executor; + } + + @Override + public final boolean isOpen() { + return !closed; + } + + /** + * Marks the beginning of an I/O operation. + * + * @throws ClosedChannelException If channel is closed + */ + protected final void begin() throws IOException { + closeLock.readLock().lock(); + if (closed) + throw new ClosedChannelException(); + } + + /** + * Marks the end of an I/O operation. + */ + protected final void end() { + closeLock.readLock().unlock(); + } + + /** + * Marks end of I/O operation + */ + protected final void end(boolean completed) throws IOException { + end(); + if (!completed && !isOpen()) + throw new AsynchronousCloseException(); + } + + // -- file locking -- + + private volatile FileLockTable fileLockTable; + + final void ensureFileLockTableInitialized() throws IOException { + if (fileLockTable == null) { + synchronized (this) { + if (fileLockTable == null) { + fileLockTable = FileLockTable.newSharedFileLockTable(this, fdObj); + } + } + } + } + + final void invalidateAllLocks() { + if (fileLockTable != null) { + try { + fileLockTable.removeAll( new FileLockTable.Releaser() { + public void release(FileLock fl) { + ((FileLockImpl)fl).invalidate(); + } + }); + } catch (IOException e) { + throw new AssertionError(e); + } + } + } + + /** + * Adds region to lock table + */ + protected final FileLockImpl addToFileLockTable(long position, long size, boolean shared) { + final FileLockImpl fli; + try { + // like begin() but returns null instead of exception + closeLock.readLock().lock(); + if (closed) + return null; + + try { + ensureFileLockTableInitialized(); + } catch (IOException x) { + // should not happen + throw new AssertionError(x); + } + fli = new FileLockImpl(this, position, size, shared); + // may throw OverlappedFileLockException + fileLockTable.add(fli); + } finally { + end(); + } + return fli; + } + + protected final void removeFromFileLockTable(FileLockImpl fli) { + fileLockTable.remove(fli); + } + + /** + * Invoked by FileLockImpl to release lock acquired by this channel. + */ + abstract void release(FileLockImpl fli) throws IOException; +} diff --git a/src/share/classes/sun/nio/ch/AsynchronousServerSocketChannelImpl.java b/src/share/classes/sun/nio/ch/AsynchronousServerSocketChannelImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..492319301590ea115c0540502ea56d5e4888b97d --- /dev/null +++ b/src/share/classes/sun/nio/ch/AsynchronousServerSocketChannelImpl.java @@ -0,0 +1,221 @@ +/* + * Copyright 2008-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 sun.nio.ch; + +import java.nio.channels.*; +import java.net.SocketAddress; +import java.net.SocketOption; +import java.net.StandardSocketOption; +import java.net.InetSocketAddress; +import java.io.FileDescriptor; +import java.io.IOException; +import java.util.Set; +import java.util.HashSet; +import java.util.Collections; +import java.util.concurrent.locks.ReadWriteLock; +import java.util.concurrent.locks.ReentrantReadWriteLock; +import sun.net.NetHooks; + +/** + * Base implementation of AsynchronousServerSocketChannel. + */ + +abstract class AsynchronousServerSocketChannelImpl + extends AsynchronousServerSocketChannel + implements Cancellable, Groupable +{ + protected final FileDescriptor fd; + + // the local address to which the channel's socket is bound + protected volatile SocketAddress localAddress = null; + + // need this lock to set local address + private final Object stateLock = new Object(); + + // close support + private ReadWriteLock closeLock = new ReentrantReadWriteLock(); + private volatile boolean open = true; + + // set true when accept operation is cancelled + private volatile boolean acceptKilled; + + + AsynchronousServerSocketChannelImpl(AsynchronousChannelGroupImpl group) { + super(group.provider()); + this.fd = Net.serverSocket(true); + } + + @Override + public final boolean isOpen() { + return open; + } + + /** + * Marks beginning of access to file descriptor/handle + */ + final void begin() throws IOException { + closeLock.readLock().lock(); + if (!isOpen()) + throw new ClosedChannelException(); + } + + /** + * Marks end of access to file descriptor/handle + */ + final void end() { + closeLock.readLock().unlock(); + } + + /** + * Invoked to close file descriptor/handle. + */ + abstract void implClose() throws IOException; + + @Override + public final void close() throws IOException { + // synchronize with any threads using file descriptor/handle + closeLock.writeLock().lock(); + try { + if (!open) + return; // already closed + open = false; + } finally { + closeLock.writeLock().unlock(); + } + implClose(); + } + + final boolean isAcceptKilled() { + return acceptKilled; + } + + @Override + public final void onCancel(PendingFuture<?,?> task) { + acceptKilled = true; + } + + @Override + public final AsynchronousServerSocketChannel bind(SocketAddress local, int backlog) + throws IOException + { + InetSocketAddress isa = (local == null) ? new InetSocketAddress(0) : + Net.checkAddress(local); + SecurityManager sm = System.getSecurityManager(); + if (sm != null) + sm.checkListen(isa.getPort()); + + try { + begin(); + synchronized (stateLock) { + if (localAddress != null) + throw new AlreadyBoundException(); + NetHooks.beforeTcpBind(fd, isa.getAddress(), isa.getPort()); + Net.bind(fd, isa.getAddress(), isa.getPort()); + Net.listen(fd, backlog < 1 ? 50 : backlog); + localAddress = Net.localAddress(fd); + } + } finally { + end(); + } + return this; + } + + @Override + public final SocketAddress getLocalAddress() throws IOException { + if (!isOpen()) + throw new ClosedChannelException(); + return localAddress; + } + + @Override + public final <T> AsynchronousServerSocketChannel setOption(SocketOption<T> name, + T value) + throws IOException + { + if (name == null) + throw new NullPointerException(); + if (!supportedOptions().contains(name)) + throw new UnsupportedOperationException("'" + name + "' not supported"); + + try { + begin(); + Net.setSocketOption(fd, Net.UNSPEC, name, value); + return this; + } finally { + end(); + } + } + + @Override + @SuppressWarnings("unchecked") + public final <T> T getOption(SocketOption<T> name) throws IOException { + if (name == null) + throw new NullPointerException(); + if (!supportedOptions().contains(name)) + throw new UnsupportedOperationException("'" + name + "' not supported"); + + try { + begin(); + return (T) Net.getSocketOption(fd, Net.UNSPEC, name); + } finally { + end(); + } + } + + private static class DefaultOptionsHolder { + static final Set<SocketOption<?>> defaultOptions = defaultOptions(); + + private static Set<SocketOption<?>> defaultOptions() { + HashSet<SocketOption<?>> set = new HashSet<SocketOption<?>>(2); + set.add(StandardSocketOption.SO_RCVBUF); + set.add(StandardSocketOption.SO_REUSEADDR); + return Collections.unmodifiableSet(set); + } + } + + @Override + public final Set<SocketOption<?>> supportedOptions() { + return DefaultOptionsHolder.defaultOptions; + } + + @Override + public final String toString() { + StringBuilder sb = new StringBuilder(); + sb.append(this.getClass().getName()); + sb.append('['); + if (!isOpen()) + sb.append("closed"); + else { + if (localAddress == null) { + sb.append("unbound"); + } else { + sb.append(localAddress.toString()); + } + } + sb.append(']'); + return sb.toString(); + } +} diff --git a/src/share/classes/sun/nio/ch/AsynchronousSocketChannelImpl.java b/src/share/classes/sun/nio/ch/AsynchronousSocketChannelImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..84b81a0c8b0bf93f0b0e13826b0259f9e5f3791a --- /dev/null +++ b/src/share/classes/sun/nio/ch/AsynchronousSocketChannelImpl.java @@ -0,0 +1,544 @@ +/* + * Copyright 2008-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 sun.nio.ch; + +import java.nio.ByteBuffer; +import java.nio.channels.*; +import java.net.SocketOption; +import java.net.StandardSocketOption; +import java.net.SocketAddress; +import java.net.InetSocketAddress; +import java.io.IOException; +import java.io.FileDescriptor; +import java.util.Set; +import java.util.HashSet; +import java.util.Collections; +import java.util.concurrent.*; +import java.util.concurrent.locks.*; +import sun.net.NetHooks; + +/** + * Base implementation of AsynchronousSocketChannel + */ + +abstract class AsynchronousSocketChannelImpl + extends AsynchronousSocketChannel + implements Cancellable, Groupable +{ + protected final FileDescriptor fd; + + // protects state, localAddress, and remoteAddress + protected final Object stateLock = new Object(); + + protected volatile SocketAddress localAddress = null; + protected volatile SocketAddress remoteAddress = null; + + // State, increases monotonically + static final int ST_UNINITIALIZED = -1; + static final int ST_UNCONNECTED = 0; + static final int ST_PENDING = 1; + static final int ST_CONNECTED = 2; + protected volatile int state = ST_UNINITIALIZED; + + // reading state + private final Object readLock = new Object(); + private boolean reading; + private boolean readShutdown; + private boolean readKilled; // further reading disallowed due to timeout + + // writing state + private final Object writeLock = new Object(); + private boolean writing; + private boolean writeShutdown; + private boolean writeKilled; // further writing disallowed due to timeout + + // close support + private final ReadWriteLock closeLock = new ReentrantReadWriteLock(); + private volatile boolean open = true; + + AsynchronousSocketChannelImpl(AsynchronousChannelGroupImpl group) + throws IOException + { + super(group.provider()); + this.fd = Net.socket(true); + this.state = ST_UNCONNECTED; + } + + // Constructor for sockets obtained from AsynchronousServerSocketChannelImpl + AsynchronousSocketChannelImpl(AsynchronousChannelGroupImpl group, + FileDescriptor fd, + InetSocketAddress remote) + throws IOException + { + super(group.provider()); + this.fd = fd; + this.state = ST_CONNECTED; + this.localAddress = Net.localAddress(fd); + this.remoteAddress = remote; + } + + @Override + public final boolean isOpen() { + return open; + } + + /** + * Marks beginning of access to file descriptor/handle + */ + final void begin() throws IOException { + closeLock.readLock().lock(); + if (!isOpen()) + throw new ClosedChannelException(); + } + + /** + * Marks end of access to file descriptor/handle + */ + final void end() { + closeLock.readLock().unlock(); + } + + /** + * Invoked to close socket and release other resources. + */ + abstract void implClose() throws IOException; + + @Override + public final void close() throws IOException { + // synchronize with any threads initiating asynchronous operations + closeLock.writeLock().lock(); + try { + if (!open) + return; // already closed + open = false; + } finally { + closeLock.writeLock().unlock(); + } + implClose(); + } + + final void enableReading(boolean killed) { + synchronized (readLock) { + reading = false; + if (killed) + readKilled = true; + } + } + + final void enableReading() { + enableReading(false); + } + + final void enableWriting(boolean killed) { + synchronized (writeLock) { + writing = false; + if (killed) + writeKilled = true; + } + } + + final void enableWriting() { + enableWriting(false); + } + + final void killReading() { + synchronized (readLock) { + readKilled = true; + } + } + + final void killWriting() { + synchronized (writeLock) { + writeKilled = true; + } + } + + final void killConnect() { + // when a connect is cancelled then the connection may have been + // established so prevent reading or writing. + killReading(); + killWriting(); + } + + /** + * Invoked by read to initiate the I/O operation. + */ + abstract <V extends Number,A> Future<V> readImpl(ByteBuffer[] dsts, + boolean isScatteringRead, + long timeout, + TimeUnit unit, + A attachment, + CompletionHandler<V,? super A> handler); + + @SuppressWarnings("unchecked") + private <V extends Number,A> Future<V> read(ByteBuffer[] dsts, + boolean isScatteringRead, + long timeout, + TimeUnit unit, + A attachment, + CompletionHandler<V,? super A> handler) + { + if (!isOpen()) { + CompletedFuture<V,A> result = CompletedFuture + .withFailure(this, new ClosedChannelException(), attachment); + Invoker.invoke(handler, result); + return result; + } + + if (remoteAddress == null) + throw new NotYetConnectedException(); + if (timeout < 0L) + throw new IllegalArgumentException("Negative timeout"); + + boolean hasSpaceToRead = isScatteringRead || dsts[0].hasRemaining(); + boolean shutdown = false; + + // check and update state + synchronized (readLock) { + if (readKilled) + throw new RuntimeException("Reading not allowed due to timeout or cancellation"); + if (reading) + throw new ReadPendingException(); + if (readShutdown) { + shutdown = true; + } else { + if (hasSpaceToRead) { + reading = true; + } + } + } + + // immediately complete with -1 if shutdown for read + // immediately complete with 0 if no space remaining + if (shutdown || !hasSpaceToRead) { + CompletedFuture<V,A> result; + if (isScatteringRead) { + Long value = (shutdown) ? Long.valueOf(-1L) : Long.valueOf(0L); + result = (CompletedFuture<V,A>)CompletedFuture.withResult(this, value, attachment); + } else { + int value = (shutdown) ? -1 : 0; + result = (CompletedFuture<V,A>)CompletedFuture.withResult(this, value, attachment); + } + Invoker.invoke(handler, result); + return result; + } + + return readImpl(dsts, isScatteringRead, timeout, unit, attachment, handler); + } + + @Override + public final <A> Future<Integer> read(ByteBuffer dst, + long timeout, + TimeUnit unit, + A attachment, + CompletionHandler<Integer,? super A> handler) + { + if (dst.isReadOnly()) + throw new IllegalArgumentException("Read-only buffer"); + ByteBuffer[] bufs = new ByteBuffer[1]; + bufs[0] = dst; + return read(bufs, false, timeout, unit, attachment, handler); + } + + @Override + public final <A> Future<Long> read(ByteBuffer[] dsts, + int offset, + int length, + long timeout, + TimeUnit unit, + A attachment, + CompletionHandler<Long,? super A> handler) + { + if ((offset < 0) || (length < 0) || (offset > dsts.length - length)) + throw new IndexOutOfBoundsException(); + ByteBuffer[] bufs = Util.subsequence(dsts, offset, length); + for (int i=0; i<bufs.length; i++) { + if (bufs[i].isReadOnly()) + throw new IllegalArgumentException("Read-only buffer"); + } + return read(bufs, true, timeout, unit, attachment, handler); + } + + /** + * Invoked by write to initiate the I/O operation. + */ + abstract <V extends Number,A> Future<V> writeImpl(ByteBuffer[] srcs, + boolean isGatheringWrite, + long timeout, + TimeUnit unit, + A attachment, + CompletionHandler<V,? super A> handler); + + @SuppressWarnings("unchecked") + private <V extends Number,A> Future<V> write(ByteBuffer[] srcs, + boolean isGatheringWrite, + long timeout, + TimeUnit unit, + A attachment, + CompletionHandler<V,? super A> handler) + { + boolean hasDataToWrite = isGatheringWrite || srcs[0].hasRemaining(); + + boolean closed = false; + if (isOpen()) { + if (remoteAddress == null) + throw new NotYetConnectedException(); + if (timeout < 0L) + throw new IllegalArgumentException("Negative timeout"); + // check and update state + synchronized (writeLock) { + if (writeKilled) + throw new RuntimeException("Writing not allowed due to timeout or cancellation"); + if (writing) + throw new WritePendingException(); + if (writeShutdown) { + closed = true; + } else { + if (hasDataToWrite) + writing = true; + } + } + } else { + closed = true; + } + + // channel is closed or shutdown for write + if (closed) { + CompletedFuture<V,A> result = CompletedFuture + .withFailure(this, new ClosedChannelException(), attachment); + Invoker.invoke(handler, result); + return result; + } + + // nothing to write so complete immediately + if (!hasDataToWrite) { + CompletedFuture<V,A> result; + if (isGatheringWrite) { + result = (CompletedFuture<V,A>)CompletedFuture.withResult(this, 0L, attachment); + } else { + result = (CompletedFuture<V,A>)CompletedFuture.withResult(this, 0, attachment); + } + Invoker.invoke(handler, result); + return result; + } + + return writeImpl(srcs, isGatheringWrite, timeout, unit, attachment, handler); + } + + @Override + public final <A> Future<Integer> write(ByteBuffer src, + long timeout, + TimeUnit unit, + A attachment, + CompletionHandler<Integer,? super A> handler) + { + ByteBuffer[] bufs = new ByteBuffer[1]; + bufs[0] = src; + return write(bufs, false, timeout, unit, attachment, handler); + } + + @Override + public final <A> Future<Long> write(ByteBuffer[] srcs, + int offset, + int length, + long timeout, + TimeUnit unit, + A attachment, + CompletionHandler<Long,? super A> handler) + { + if ((offset < 0) || (length < 0) || (offset > srcs.length - length)) + throw new IndexOutOfBoundsException(); + srcs = Util.subsequence(srcs, offset, length); + return write(srcs, true, timeout, unit, attachment, handler); + } + + @Override + public final AsynchronousSocketChannel bind(SocketAddress local) + throws IOException + { + try { + begin(); + synchronized (stateLock) { + if (state == ST_PENDING) + throw new ConnectionPendingException(); + if (localAddress != null) + throw new AlreadyBoundException(); + InetSocketAddress isa = (local == null) ? + new InetSocketAddress(0) : Net.checkAddress(local); + NetHooks.beforeTcpBind(fd, isa.getAddress(), isa.getPort()); + Net.bind(fd, isa.getAddress(), isa.getPort()); + localAddress = Net.localAddress(fd); + } + } finally { + end(); + } + return this; + } + + @Override + public final SocketAddress getLocalAddress() throws IOException { + if (!isOpen()) + throw new ClosedChannelException(); + return localAddress; + } + + @Override + public final <T> AsynchronousSocketChannel setOption(SocketOption<T> name, T value) + throws IOException + { + if (name == null) + throw new NullPointerException(); + if (!supportedOptions().contains(name)) + throw new UnsupportedOperationException("'" + name + "' not supported"); + + try { + begin(); + if (writeShutdown) + throw new IOException("Connection has been shutdown for writing"); + Net.setSocketOption(fd, Net.UNSPEC, name, value); + return this; + } finally { + end(); + } + } + + @Override + @SuppressWarnings("unchecked") + public final <T> T getOption(SocketOption<T> name) throws IOException { + if (name == null) + throw new NullPointerException(); + if (!supportedOptions().contains(name)) + throw new UnsupportedOperationException("'" + name + "' not supported"); + + try { + begin(); + return (T) Net.getSocketOption(fd, Net.UNSPEC, name); + } finally { + end(); + } + } + + private static class DefaultOptionsHolder { + static final Set<SocketOption<?>> defaultOptions = defaultOptions(); + + private static Set<SocketOption<?>> defaultOptions() { + HashSet<SocketOption<?>> set = new HashSet<SocketOption<?>>(5); + set.add(StandardSocketOption.SO_SNDBUF); + set.add(StandardSocketOption.SO_RCVBUF); + set.add(StandardSocketOption.SO_KEEPALIVE); + set.add(StandardSocketOption.SO_REUSEADDR); + set.add(StandardSocketOption.TCP_NODELAY); + return Collections.unmodifiableSet(set); + } + } + + @Override + public final Set<SocketOption<?>> supportedOptions() { + return DefaultOptionsHolder.defaultOptions; + } + + @Override + @SuppressWarnings("unchecked") + public final SocketAddress getRemoteAddress() throws IOException { + if (!isOpen()) + throw new ClosedChannelException(); + return remoteAddress; + } + + @Override + public final AsynchronousSocketChannel shutdownInput() throws IOException { + try { + begin(); + if (remoteAddress == null) + throw new NotYetConnectedException(); + synchronized (readLock) { + if (!readShutdown) { + Net.shutdown(fd, Net.SHUT_RD); + readShutdown = true; + } + } + } finally { + end(); + } + return this; + } + + @Override + public final AsynchronousSocketChannel shutdownOutput() throws IOException { + try { + begin(); + if (remoteAddress == null) + throw new NotYetConnectedException(); + synchronized (writeLock) { + if (!writeShutdown) { + Net.shutdown(fd, Net.SHUT_WR); + writeShutdown = true; + } + } + } finally { + end(); + } + return this; + } + + @Override + public final String toString() { + StringBuilder sb = new StringBuilder(); + sb.append(this.getClass().getName()); + sb.append('['); + synchronized (stateLock) { + if (!isOpen()) { + sb.append("closed"); + } else { + switch (state) { + case ST_UNCONNECTED: + sb.append("unconnected"); + break; + case ST_PENDING: + sb.append("connection-pending"); + break; + case ST_CONNECTED: + sb.append("connected"); + if (readShutdown) + sb.append(" ishut"); + if (writeShutdown) + sb.append(" oshut"); + break; + } + if (localAddress != null) { + sb.append(" local="); + sb.append(localAddress.toString()); + } + if (remoteAddress != null) { + sb.append(" remote="); + sb.append(remoteAddress.toString()); + } + } + } + sb.append(']'); + return sb.toString(); + } +} diff --git a/src/share/classes/sun/nio/ch/Cancellable.java b/src/share/classes/sun/nio/ch/Cancellable.java new file mode 100644 index 0000000000000000000000000000000000000000..ae08ed9eb89685ea173d34b248216d66ff8aac42 --- /dev/null +++ b/src/share/classes/sun/nio/ch/Cancellable.java @@ -0,0 +1,39 @@ +/* + * Copyright 2008-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 sun.nio.ch; + +/** + * Implemented by asynchronous channels that require notification when an I/O + * operation is cancelled. + */ + +interface Cancellable { + /** + * Invoked to notify channel that cancel has been invoked while holding + * the Future's lock. + */ + void onCancel(PendingFuture<?,?> task); +} diff --git a/src/share/classes/sun/nio/ch/CompletedFuture.java b/src/share/classes/sun/nio/ch/CompletedFuture.java new file mode 100644 index 0000000000000000000000000000000000000000..221b9f8f5f71b8caae539a2f8b645b31050e5ec7 --- /dev/null +++ b/src/share/classes/sun/nio/ch/CompletedFuture.java @@ -0,0 +1,113 @@ +/* + * Copyright 2008-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 sun.nio.ch; + +import java.nio.channels.AsynchronousChannel; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.ExecutionException; +import java.io.IOException; + +/** + * A Future representing the result of an I/O operation that has already + * completed. + */ + +final class CompletedFuture<V,A> + extends AbstractFuture<V,A> +{ + private final V result; + private final Throwable exc; + + private CompletedFuture(AsynchronousChannel channel, + V result, + Throwable exc, + A attachment) + { + super(channel, attachment); + this.result = result; + this.exc = exc; + } + + @SuppressWarnings("unchecked") + static <V,A> CompletedFuture<V,A> withResult(AsynchronousChannel channel, + V result, + A attachment) + { + return new CompletedFuture<V,A>(channel, result, null, attachment); + } + + @SuppressWarnings("unchecked") + static <V,A> CompletedFuture<V,A> withFailure(AsynchronousChannel channel, + Throwable exc, + A attachment) + { + // exception must be IOException or SecurityException + if (!(exc instanceof IOException) && !(exc instanceof SecurityException)) + exc = new IOException(exc); + return new CompletedFuture(channel, null, exc, attachment); + } + + @Override + public V get() throws ExecutionException { + if (exc != null) + throw new ExecutionException(exc); + return result; + } + + @Override + public V get(long timeout, TimeUnit unit) throws ExecutionException { + if (unit == null) + throw new NullPointerException(); + if (exc != null) + throw new ExecutionException(exc); + return result; + } + + @Override + public boolean isCancelled() { + return false; + } + + @Override + public boolean isDone() { + return true; + } + + @Override + public boolean cancel(boolean mayInterruptIfRunning) { + return false; + } + + @Override + Throwable exception() { + return exc; + } + + @Override + V value() { + return result; + } +} diff --git a/src/share/classes/sun/nio/ch/DatagramChannelImpl.java b/src/share/classes/sun/nio/ch/DatagramChannelImpl.java index 54cbfba16c33320e7110104088c61425f4eda21b..57b35c9bc20a120d15f0907a39538f3d4ce16841 100644 --- a/src/share/classes/sun/nio/ch/DatagramChannelImpl.java +++ b/src/share/classes/sun/nio/ch/DatagramChannelImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2001-2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2001-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 @@ -111,8 +111,12 @@ class DatagramChannelImpl public DatagramChannelImpl(SelectorProvider sp, ProtocolFamily family) { super(sp); if ((family != StandardProtocolFamily.INET) && - (family != StandardProtocolFamily.INET6)) { - throw new UnsupportedOperationException("Protocol family not supported"); + (family != StandardProtocolFamily.INET6)) + { + if (family == null) + throw new NullPointerException("'family' is null"); + else + throw new UnsupportedOperationException("Protocol family not supported"); } if (family == StandardProtocolFamily.INET6) { if (!Net.isIPv6Available()) { @@ -149,28 +153,28 @@ class DatagramChannelImpl public SocketAddress getLocalAddress() throws IOException { synchronized (stateLock) { if (!isOpen()) - return null; + throw new ClosedChannelException(); return localAddress; } } @Override - public SocketAddress getConnectedAddress() throws IOException { + public SocketAddress getRemoteAddress() throws IOException { synchronized (stateLock) { if (!isOpen()) - return null; + throw new ClosedChannelException(); return remoteAddress; } } @Override - public DatagramChannel setOption(SocketOption name, Object value) + public <T> DatagramChannel setOption(SocketOption<T> name, T value) throws IOException { if (name == null) throw new NullPointerException(); - if (!options().contains(name)) - throw new IllegalArgumentException("Invalid option name"); + if (!supportedOptions().contains(name)) + throw new UnsupportedOperationException("'" + name + "' not supported"); synchronized (stateLock) { ensureOpen(); @@ -224,8 +228,8 @@ class DatagramChannelImpl { if (name == null) throw new NullPointerException(); - if (!options().contains(name)) - throw new IllegalArgumentException("Invalid option name"); + if (!supportedOptions().contains(name)) + throw new UnsupportedOperationException("'" + name + "' not supported"); synchronized (stateLock) { ensureOpen(); @@ -273,7 +277,7 @@ class DatagramChannelImpl } } - private static class LazyInitialization { + private static class DefaultOptionsHolder { static final Set<SocketOption<?>> defaultOptions = defaultOptions(); private static Set<SocketOption<?>> defaultOptions() { @@ -291,8 +295,8 @@ class DatagramChannelImpl } @Override - public final Set<SocketOption<?>> options() { - return LazyInitialization.defaultOptions; + public final Set<SocketOption<?>> supportedOptions() { + return DefaultOptionsHolder.defaultOptions; } private void ensureOpen() throws ClosedChannelException { @@ -309,11 +313,9 @@ class DatagramChannelImpl throw new NullPointerException(); synchronized (readLock) { ensureOpen(); - // If socket is not bound then behave as if nothing received - // Will be fixed by 6621699 - if (localAddress() == null) { - return null; - } + // Socket was not bound before attempting receive + if (localAddress() == null) + bind(null); int n = 0; ByteBuffer bb = null; try { @@ -864,23 +866,26 @@ class DatagramChannelImpl } // package-private - void drop(MembershipKeyImpl key) - throws IOException - { - assert key.getChannel() == this; + void drop(MembershipKeyImpl key) { + assert key.channel() == this; synchronized (stateLock) { if (!key.isValid()) return; - if (family == StandardProtocolFamily.INET6) { - MembershipKeyImpl.Type6 key6 = - (MembershipKeyImpl.Type6)key; - Net.drop6(fd, key6.group(), key6.index(), key6.source()); - } else { - MembershipKeyImpl.Type4 key4 = - (MembershipKeyImpl.Type4)key; - Net.drop4(fd, key4.group(), key4.interfaceAddress(), key4.source()); + try { + if (family == StandardProtocolFamily.INET6) { + MembershipKeyImpl.Type6 key6 = + (MembershipKeyImpl.Type6)key; + Net.drop6(fd, key6.groupAddress(), key6.index(), key6.source()); + } else { + MembershipKeyImpl.Type4 key4 = (MembershipKeyImpl.Type4)key; + Net.drop4(fd, key4.groupAddress(), key4.interfaceAddress(), + key4.source()); + } + } catch (IOException ioe) { + // should not happen + throw new AssertionError(ioe); } key.invalidate(); @@ -895,8 +900,8 @@ class DatagramChannelImpl void block(MembershipKeyImpl key, InetAddress source) throws IOException { - assert key.getChannel() == this; - assert key.getSourceAddress() == null; + assert key.channel() == this; + assert key.sourceAddress() == null; synchronized (stateLock) { if (!key.isValid()) @@ -905,19 +910,19 @@ class DatagramChannelImpl throw new IllegalArgumentException("Source address is a wildcard address"); if (source.isMulticastAddress()) throw new IllegalArgumentException("Source address is multicast address"); - if (source.getClass() != key.getGroup().getClass()) + if (source.getClass() != key.group().getClass()) throw new IllegalArgumentException("Source address is different type to group"); int n; if (family == StandardProtocolFamily.INET6) { MembershipKeyImpl.Type6 key6 = (MembershipKeyImpl.Type6)key; - n = Net.block6(fd, key6.group(), key6.index(), + n = Net.block6(fd, key6.groupAddress(), key6.index(), Net.inet6AsByteArray(source)); } else { MembershipKeyImpl.Type4 key4 = (MembershipKeyImpl.Type4)key; - n = Net.block4(fd, key4.group(), key4.interfaceAddress(), + n = Net.block4(fd, key4.groupAddress(), key4.interfaceAddress(), Net.inet4AsInt(source)); } if (n == IOStatus.UNAVAILABLE) { @@ -930,26 +935,29 @@ class DatagramChannelImpl /** * Unblock given source. */ - void unblock(MembershipKeyImpl key, InetAddress source) - throws IOException - { - assert key.getChannel() == this; - assert key.getSourceAddress() == null; + void unblock(MembershipKeyImpl key, InetAddress source) { + assert key.channel() == this; + assert key.sourceAddress() == null; synchronized (stateLock) { if (!key.isValid()) throw new IllegalStateException("key is no longer valid"); - if (family == StandardProtocolFamily.INET6) { - MembershipKeyImpl.Type6 key6 = - (MembershipKeyImpl.Type6)key; - Net.unblock6(fd, key6.group(), key6.index(), - Net.inet6AsByteArray(source)); - } else { - MembershipKeyImpl.Type4 key4 = - (MembershipKeyImpl.Type4)key; - Net.unblock4(fd, key4.group(), key4.interfaceAddress(), - Net.inet4AsInt(source)); + try { + if (family == StandardProtocolFamily.INET6) { + MembershipKeyImpl.Type6 key6 = + (MembershipKeyImpl.Type6)key; + Net.unblock6(fd, key6.groupAddress(), key6.index(), + Net.inet6AsByteArray(source)); + } else { + MembershipKeyImpl.Type4 key4 = + (MembershipKeyImpl.Type4)key; + Net.unblock4(fd, key4.groupAddress(), key4.interfaceAddress(), + Net.inet4AsInt(source)); + } + } catch (IOException ioe) { + // should not happen + throw new AssertionError(ioe); } } } diff --git a/src/share/classes/sun/nio/ch/ExtendedSocketOption.java b/src/share/classes/sun/nio/ch/ExtendedSocketOption.java index 86e787ef80558f1a45deaa55f983fdd219f23464..d695fd2a4f5c0cbd3162a65d55ca684415f498d0 100644 --- a/src/share/classes/sun/nio/ch/ExtendedSocketOption.java +++ b/src/share/classes/sun/nio/ch/ExtendedSocketOption.java @@ -1,5 +1,5 @@ /* - * Copyright 2007-2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2008 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 diff --git a/src/share/classes/sun/nio/ch/FileChannelImpl.java b/src/share/classes/sun/nio/ch/FileChannelImpl.java index 4d0543e4b1ca091b4b48d43c2514d9c616a7ff05..1d60e9615ffad00fd4128947f1e11e62950b7f06 100644 --- a/src/share/classes/sun/nio/ch/FileChannelImpl.java +++ b/src/share/classes/sun/nio/ch/FileChannelImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2008 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. * * This code is free software; you can redistribute it and/or modify it @@ -26,27 +26,18 @@ package sun.nio.ch; import java.io.FileDescriptor; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.RandomAccessFile; import java.io.IOException; import java.nio.ByteBuffer; import java.nio.MappedByteBuffer; import java.nio.BufferPoolMXBean; import java.nio.channels.*; -import java.nio.channels.spi.*; import java.util.ArrayList; import java.util.List; import java.util.Iterator; -import java.util.concurrent.ConcurrentHashMap; -import java.lang.ref.WeakReference; -import java.lang.ref.ReferenceQueue; import java.lang.reflect.Field; import java.security.AccessController; -import java.security.PrivilegedAction; import javax.management.ObjectName; import javax.management.MalformedObjectNameException; - import sun.misc.Cleaner; import sun.security.action.GetPropertyAction; @@ -55,7 +46,7 @@ public class FileChannelImpl { // Used to make native read and write calls - private static final NativeDispatcher nd; + private static final FileDispatcher nd; // Memory allocation size for mapping buffers private static final long allocationGranularity; @@ -104,20 +95,19 @@ public class FileChannelImpl // -- Standard channel operations -- protected void implCloseChannel() throws IOException { - - nd.preClose(fd); - threads.signal(); - // Invalidate and release any locks that we still hold if (fileLockTable != null) { fileLockTable.removeAll( new FileLockTable.Releaser() { public void release(FileLock fl) throws IOException { ((FileLockImpl)fl).invalidate(); - release0(fd, fl.position(), fl.size()); + nd.release(fd, fl.position(), fl.size()); } }); } + nd.preClose(fd); + threads.signalAndWait(); + if (parent != null) { // Close the fd via the parent stream's close method. The parent @@ -141,9 +131,9 @@ public class FileChannelImpl int ti = -1; try { begin(); + ti = threads.add(); if (!isOpen()) return 0; - ti = threads.add(); do { n = IOUtil.read(fd, dst, -1, nd, positionLock); } while ((n == IOStatus.INTERRUPTED) && isOpen()); @@ -165,9 +155,9 @@ public class FileChannelImpl int ti = -1; try { begin(); + ti = threads.add(); if (!isOpen()) return 0; - ti = threads.add(); do { n = IOUtil.read(fd, dsts, nd); } while ((n == IOStatus.INTERRUPTED) && isOpen()); @@ -198,9 +188,9 @@ public class FileChannelImpl int ti = -1; try { begin(); + ti = threads.add(); if (!isOpen()) return 0; - ti = threads.add(); do { n = IOUtil.write(fd, src, -1, nd, positionLock); } while ((n == IOStatus.INTERRUPTED) && isOpen()); @@ -222,9 +212,9 @@ public class FileChannelImpl int ti = -1; try { begin(); + ti = threads.add(); if (!isOpen()) return 0; - ti = threads.add(); do { n = IOUtil.write(fd, srcs, nd); } while ((n == IOStatus.INTERRUPTED) && isOpen()); @@ -256,9 +246,9 @@ public class FileChannelImpl int ti = -1; try { begin(); + ti = threads.add(); if (!isOpen()) return 0; - ti = threads.add(); do { p = position0(fd, -1); } while ((p == IOStatus.INTERRUPTED) && isOpen()); @@ -280,9 +270,9 @@ public class FileChannelImpl int ti = -1; try { begin(); + ti = threads.add(); if (!isOpen()) return null; - ti = threads.add(); do { p = position0(fd, newPosition); } while ((p == IOStatus.INTERRUPTED) && isOpen()); @@ -302,11 +292,11 @@ public class FileChannelImpl int ti = -1; try { begin(); + ti = threads.add(); if (!isOpen()) return -1; - ti = threads.add(); do { - s = size0(fd); + s = nd.size(fd); } while ((s == IOStatus.INTERRUPTED) && isOpen()); return IOStatus.normalize(s); } finally { @@ -331,9 +321,9 @@ public class FileChannelImpl int ti = -1; try { begin(); + ti = threads.add(); if (!isOpen()) return null; - ti = threads.add(); // get current position do { @@ -345,7 +335,7 @@ public class FileChannelImpl // truncate file do { - rv = truncate0(fd, size); + rv = nd.truncate(fd, size); } while ((rv == IOStatus.INTERRUPTED) && isOpen()); if (!isOpen()) return null; @@ -371,11 +361,11 @@ public class FileChannelImpl int ti = -1; try { begin(); + ti = threads.add(); if (!isOpen()) return; - ti = threads.add(); do { - rv = force0(fd, metaData); + rv = nd.force(fd, metaData); } while ((rv == IOStatus.INTERRUPTED) && isOpen()); } finally { threads.remove(ti); @@ -428,9 +418,9 @@ public class FileChannelImpl int ti = -1; try { begin(); + ti = threads.add(); if (!isOpen()) return -1; - ti = threads.add(); do { n = transferTo0(thisFDVal, position, icount, targetFDVal); } while ((n == IOStatus.INTERRUPTED) && isOpen()); @@ -635,9 +625,9 @@ public class FileChannelImpl int ti = -1; try { begin(); + ti = threads.add(); if (!isOpen()) return -1; - ti = threads.add(); do { n = IOUtil.read(fd, dst, position, nd, positionLock); } while ((n == IOStatus.INTERRUPTED) && isOpen()); @@ -661,9 +651,9 @@ public class FileChannelImpl int ti = -1; try { begin(); + ti = threads.add(); if (!isOpen()) return -1; - ti = threads.add(); do { n = IOUtil.write(fd, src, position, nd, positionLock); } while ((n == IOStatus.INTERRUPTED) && isOpen()); @@ -756,9 +746,9 @@ public class FileChannelImpl int ti = -1; try { begin(); + ti = threads.add(); if (!isOpen()) return null; - ti = threads.add(); if (size() < position + size) { // Extend file size if (!writable) { throw new IOException("Channel not open for writing " + @@ -766,7 +756,7 @@ public class FileChannelImpl } int rv; do { - rv = truncate0(fd, position + size); + rv = nd.truncate(fd, position + size); } while ((rv == IOStatus.INTERRUPTED) && isOpen()); } if (size == 0) { @@ -860,10 +850,7 @@ public class FileChannelImpl // -- Locks -- - public static final int NO_LOCK = -1; // Failed to lock - public static final int LOCKED = 0; // Obtained requested lock - public static final int RET_EX_LOCK = 1; // Obtained exclusive lock - public static final int INTERRUPTED = 2; // Request interrupted + // keeps track of locks on this file private volatile FileLockTable fileLockTable; @@ -893,12 +880,21 @@ public class FileChannelImpl return isSharedFileLockTable; } - private FileLockTable fileLockTable() { + private FileLockTable fileLockTable() throws IOException { if (fileLockTable == null) { synchronized (this) { if (fileLockTable == null) { - fileLockTable = isSharedFileLockTable() ? - new SharedFileLockTable(this) : new SimpleFileLockTable(); + if (isSharedFileLockTable()) { + int ti = threads.add(); + try { + ensureOpen(); + fileLockTable = FileLockTable.newSharedFileLockTable(this, fd); + } finally { + threads.remove(ti); + } + } else { + fileLockTable = new SimpleFileLockTable(); + } } } } @@ -920,18 +916,18 @@ public class FileChannelImpl int ti = -1; try { begin(); + ti = threads.add(); if (!isOpen()) return null; - ti = threads.add(); - int result = lock0(fd, true, position, size, shared); - if (result == RET_EX_LOCK) { + int result = nd.lock(fd, true, position, size, shared); + if (result == FileDispatcher.RET_EX_LOCK) { assert shared; FileLockImpl fli2 = new FileLockImpl(this, position, size, false); flt.replace(fli, fli2); return fli2; } - if (result == INTERRUPTED || result == NO_LOCK) { + if (result == FileDispatcher.INTERRUPTED || result == FileDispatcher.NO_LOCK) { flt.remove(fli); i = false; } @@ -960,77 +956,54 @@ public class FileChannelImpl FileLockImpl fli = new FileLockImpl(this, position, size, shared); FileLockTable flt = fileLockTable(); flt.add(fli); - int result = lock0(fd, false, position, size, shared); - if (result == NO_LOCK) { - flt.remove(fli); - return null; - } - if (result == RET_EX_LOCK) { - assert shared; - FileLockImpl fli2 = new FileLockImpl(this, position, size, - false); - flt.replace(fli, fli2); - return fli2; + int result; + + int ti = threads.add(); + try { + try { + ensureOpen(); + result = nd.lock(fd, false, position, size, shared); + } catch (IOException e) { + flt.remove(fli); + throw e; + } + if (result == FileDispatcher.NO_LOCK) { + flt.remove(fli); + return null; + } + if (result == FileDispatcher.RET_EX_LOCK) { + assert shared; + FileLockImpl fli2 = new FileLockImpl(this, position, size, + false); + flt.replace(fli, fli2); + return fli2; + } + return fli; + } finally { + threads.remove(ti); } - return fli; } void release(FileLockImpl fli) throws IOException { ensureOpen(); - release0(fd, fli.position(), fli.size()); + int ti = threads.add(); + try { + ensureOpen(); + nd.release(fd, fli.position(), fli.size()); + } finally { + threads.remove(ti); + } assert fileLockTable != null; fileLockTable.remove(fli); } - - // -- File lock support -- - - /** - * A table of FileLocks. - */ - private interface FileLockTable { - /** - * Adds a file lock to the table. - * - * @throws OverlappingFileLockException if the file lock overlaps - * with an existing file lock in the table - */ - void add(FileLock fl) throws OverlappingFileLockException; - - /** - * Remove an existing file lock from the table. - */ - void remove(FileLock fl); - - /** - * An implementation of this interface releases a given file lock. - * Used with removeAll. - */ - interface Releaser { - void release(FileLock fl) throws IOException; - } - - /** - * Removes all file locks from the table. - * <p> - * The Releaser#release method is invoked for each file lock before - * it is removed. - * - * @throws IOException if the release method throws IOException - */ - void removeAll(Releaser r) throws IOException; - - /** - * Replaces an existing file lock in the table. - */ - void replace(FileLock fl1, FileLock fl2); - } + // -- File lock support -- /** * A simple file lock table that maintains a list of FileLocks obtained by a * FileChannel. Use to get 1.4/5.0 behaviour. */ - private static class SimpleFileLockTable implements FileLockTable { + private static class SimpleFileLockTable extends FileLockTable { // synchronize on list for access private List<FileLock> lockList = new ArrayList<FileLock>(2); @@ -1080,207 +1053,8 @@ public class FileChannelImpl } } - /** - * A weak reference to a FileLock. - * <p> - * SharedFileLockTable uses a list of file lock references to avoid keeping the - * FileLock (and FileChannel) alive. - */ - private static class FileLockReference extends WeakReference<FileLock> { - private FileKey fileKey; - - FileLockReference(FileLock referent, - ReferenceQueue<FileLock> queue, - FileKey key) { - super(referent, queue); - this.fileKey = key; - } - - private FileKey fileKey() { - return fileKey; - } - } - - /** - * A file lock table that is over a system-wide map of all file locks. - */ - private static class SharedFileLockTable implements FileLockTable { - // The system-wide map is a ConcurrentHashMap that is keyed on the FileKey. - // The map value is a list of file locks represented by FileLockReferences. - // All access to the list must be synchronized on the list. - private static ConcurrentHashMap<FileKey, ArrayList<FileLockReference>> lockMap = - new ConcurrentHashMap<FileKey, ArrayList<FileLockReference>>(); - - // reference queue for cleared refs - private static ReferenceQueue<FileLock> queue = new ReferenceQueue<FileLock>(); - - // the enclosing file channel - private FileChannelImpl fci; - - // File key for the file that this channel is connected to - private FileKey fileKey; - - public SharedFileLockTable(FileChannelImpl fci) { - this.fci = fci; - this.fileKey = FileKey.create(fci.fd); - } - - public void add(FileLock fl) throws OverlappingFileLockException { - ArrayList<FileLockReference> list = lockMap.get(fileKey); - - for (;;) { - - // The key isn't in the map so we try to create it atomically - if (list == null) { - list = new ArrayList<FileLockReference>(2); - ArrayList<FileLockReference> prev; - synchronized (list) { - prev = lockMap.putIfAbsent(fileKey, list); - if (prev == null) { - // we successfully created the key so we add the file lock - list.add(new FileLockReference(fl, queue, fileKey)); - break; - } - } - // someone else got there first - list = prev; - } - - // There is already a key. It is possible that some other thread - // is removing it so we re-fetch the value from the map. If it - // hasn't changed then we check the list for overlapping locks - // and add the new lock to the list. - synchronized (list) { - ArrayList<FileLockReference> current = lockMap.get(fileKey); - if (list == current) { - checkList(list, fl.position(), fl.size()); - list.add(new FileLockReference(fl, queue, fileKey)); - break; - } - list = current; - } - - } - - // process any stale entries pending in the reference queue - removeStaleEntries(); - } - - private void removeKeyIfEmpty(FileKey fk, ArrayList<FileLockReference> list) { - assert Thread.holdsLock(list); - assert lockMap.get(fk) == list; - if (list.isEmpty()) { - lockMap.remove(fk); - } - } - - public void remove(FileLock fl) { - assert fl != null; - - // the lock must exist so the list of locks must be present - ArrayList<FileLockReference> list = lockMap.get(fileKey); - assert list != null; - - synchronized (list) { - int index = 0; - while (index < list.size()) { - FileLockReference ref = list.get(index); - FileLock lock = ref.get(); - if (lock == fl) { - assert (lock != null) && (lock.channel() == fci); - ref.clear(); - list.remove(index); - break; - } - index++; - } - } - } - - public void removeAll(Releaser releaser) throws IOException { - ArrayList<FileLockReference> list = lockMap.get(fileKey); - if (list != null) { - synchronized (list) { - int index = 0; - while (index < list.size()) { - FileLockReference ref = list.get(index); - FileLock lock = ref.get(); - - // remove locks obtained by this channel - if (lock != null && lock.channel() == fci) { - // invoke the releaser to invalidate/release the lock - releaser.release(lock); - - // remove the lock from the list - ref.clear(); - list.remove(index); - } else { - index++; - } - } - - // once the lock list is empty we remove it from the map - removeKeyIfEmpty(fileKey, list); - } - } - } - - public void replace(FileLock fromLock, FileLock toLock) { - // the lock must exist so there must be a list - ArrayList<FileLockReference> list = lockMap.get(fileKey); - assert list != null; - - synchronized (list) { - for (int index=0; index<list.size(); index++) { - FileLockReference ref = list.get(index); - FileLock lock = ref.get(); - if (lock == fromLock) { - ref.clear(); - list.set(index, new FileLockReference(toLock, queue, fileKey)); - break; - } - } - } - } - - // Check for overlapping file locks - private void checkList(List<FileLockReference> list, long position, long size) - throws OverlappingFileLockException - { - assert Thread.holdsLock(list); - for (FileLockReference ref: list) { - FileLock fl = ref.get(); - if (fl != null && fl.overlaps(position, size)) - throw new OverlappingFileLockException(); - } - } - - // Process the reference queue - private void removeStaleEntries() { - FileLockReference ref; - while ((ref = (FileLockReference)queue.poll()) != null) { - FileKey fk = ref.fileKey(); - ArrayList<FileLockReference> list = lockMap.get(fk); - if (list != null) { - synchronized (list) { - list.remove(ref); - removeKeyIfEmpty(fk, list); - } - } - } - } - } - // -- Native methods -- - // Grabs a file lock - native int lock0(FileDescriptor fd, boolean blocking, long pos, long size, - boolean shared) throws IOException; - - // Releases a file lock - native void release0(FileDescriptor fd, long pos, long size) - throws IOException; - // Creates a new mapping private native long map0(int prot, long position, long length) throws IOException; @@ -1288,12 +1062,6 @@ public class FileChannelImpl // Removes an existing mapping private static native int unmap0(long address, long length); - // Forces output to device - private native int force0(FileDescriptor fd, boolean metaData); - - // Truncates a file - private native int truncate0(FileDescriptor fd, long size); - // Transfers from src to dst, or returns -2 if kernel can't do that private native long transferTo0(int src, long position, long count, int dst); @@ -1302,16 +1070,13 @@ public class FileChannelImpl // otherwise the position is set to offset private native long position0(FileDescriptor fd, long offset); - // Reports this file's size - private native long size0(FileDescriptor fd); - // Caches fieldIDs private static native long initIDs(); static { Util.load(); allocationGranularity = initIDs(); - nd = new FileDispatcher(); + nd = new FileDispatcherImpl(); } } diff --git a/src/share/classes/sun/nio/ch/FileDispatcher.java b/src/share/classes/sun/nio/ch/FileDispatcher.java new file mode 100644 index 0000000000000000000000000000000000000000..9f8a0f79e4fe8cca4f373bbb51145a4e690c20ad --- /dev/null +++ b/src/share/classes/sun/nio/ch/FileDispatcher.java @@ -0,0 +1,48 @@ +/* + * Copyright 2007-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 sun.nio.ch; + +import java.io.*; + +abstract class FileDispatcher extends NativeDispatcher { + + public static final int NO_LOCK = -1; // Failed to lock + public static final int LOCKED = 0; // Obtained requested lock + public static final int RET_EX_LOCK = 1; // Obtained exclusive lock + public static final int INTERRUPTED = 2; // Request interrupted + + abstract int force(FileDescriptor fd, boolean metaData) throws IOException; + + abstract int truncate(FileDescriptor fd, long size) throws IOException; + + abstract long size(FileDescriptor fd) throws IOException; + + abstract int lock(FileDescriptor fd, boolean blocking, long pos, long size, + boolean shared) throws IOException; + + abstract void release(FileDescriptor fd, long pos, long size) + throws IOException; +} diff --git a/src/share/classes/sun/nio/ch/FileLockImpl.java b/src/share/classes/sun/nio/ch/FileLockImpl.java index 721faf1a0fa914472cf07f5532ceafe5929d1fd9..9efd1532b50ab787703266f51a5189ebc5de212e 100644 --- a/src/share/classes/sun/nio/ch/FileLockImpl.java +++ b/src/share/classes/sun/nio/ch/FileLockImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2001-2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2001-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 @@ -26,9 +26,7 @@ package sun.nio.ch; import java.io.IOException; -import java.nio.channels.ClosedChannelException; -import java.nio.channels.FileLock; -import java.nio.channels.FileChannel; +import java.nio.channels.*; public class FileLockImpl extends FileLock @@ -41,6 +39,12 @@ public class FileLockImpl this.valid = true; } + FileLockImpl(AsynchronousFileChannel channel, long position, long size, boolean shared) + { + super(channel, position, size, shared); + this.valid = true; + } + public synchronized boolean isValid() { return valid; } @@ -50,10 +54,15 @@ public class FileLockImpl } public synchronized void release() throws IOException { - if (!channel().isOpen()) + Channel ch = acquiredBy(); + if (!ch.isOpen()) throw new ClosedChannelException(); if (valid) { - ((FileChannelImpl)channel()).release(this); + if (ch instanceof FileChannelImpl) + ((FileChannelImpl)ch).release(this); + else if (ch instanceof AsynchronousFileChannelImpl) + ((AsynchronousFileChannelImpl)ch).release(this); + else throw new AssertionError(); valid = false; } } diff --git a/src/share/classes/sun/nio/ch/FileLockTable.java b/src/share/classes/sun/nio/ch/FileLockTable.java new file mode 100644 index 0000000000000000000000000000000000000000..137ab88872b050bfeec744d66a5ee4570ec8660a --- /dev/null +++ b/src/share/classes/sun/nio/ch/FileLockTable.java @@ -0,0 +1,282 @@ +/* + * Copyright 2005-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 sun.nio.ch; + +import java.nio.channels.*; +import java.util.*; +import java.util.concurrent.ConcurrentHashMap; +import java.lang.ref.*; +import java.io.FileDescriptor; +import java.io.IOException; + +abstract class FileLockTable { + protected FileLockTable() { + } + + /** + * Creates and returns a file lock table for a channel that is connected to + * the a system-wide map of all file locks for the Java virtual machine. + */ + public static FileLockTable newSharedFileLockTable(Channel channel, + FileDescriptor fd) + throws IOException + { + return new SharedFileLockTable(channel, fd); + } + + /** + * Adds a file lock to the table. + * + * @throws OverlappingFileLockException if the file lock overlaps + * with an existing file lock in the table + */ + public abstract void add(FileLock fl) throws OverlappingFileLockException; + + /** + * Remove an existing file lock from the table. + */ + public abstract void remove(FileLock fl); + + /** + * An implementation of this interface releases a given file lock. + * Used with removeAll. + */ + public abstract interface Releaser { + void release(FileLock fl) throws IOException; + } + + /** + * Removes all file locks from the table. + * <p> + * The Releaser#release method is invoked for each file lock before + * it is removed. + * + * @throws IOException if the release method throws IOException + */ + public abstract void removeAll(Releaser r) throws IOException; + + /** + * Replaces an existing file lock in the table. + */ + public abstract void replace(FileLock fl1, FileLock fl2); +} + + +/** + * A file lock table that is over a system-wide map of all file locks. + */ +class SharedFileLockTable extends FileLockTable { + + /** + * A weak reference to a FileLock. + * <p> + * SharedFileLockTable uses a list of file lock references to avoid keeping the + * FileLock (and FileChannel) alive. + */ + private static class FileLockReference extends WeakReference<FileLock> { + private FileKey fileKey; + + FileLockReference(FileLock referent, + ReferenceQueue<FileLock> queue, + FileKey key) { + super(referent, queue); + this.fileKey = key; + } + + FileKey fileKey() { + return fileKey; + } + } + + // The system-wide map is a ConcurrentHashMap that is keyed on the FileKey. + // The map value is a list of file locks represented by FileLockReferences. + // All access to the list must be synchronized on the list. + private static ConcurrentHashMap<FileKey, List<FileLockReference>> lockMap = + new ConcurrentHashMap<FileKey, List<FileLockReference>>(); + + // reference queue for cleared refs + private static ReferenceQueue<FileLock> queue = new ReferenceQueue<FileLock>(); + + // The connection to which this table is connected + private final Channel channel; + + // File key for the file that this channel is connected to + private final FileKey fileKey; + + SharedFileLockTable(Channel channel, FileDescriptor fd) throws IOException { + this.channel = channel; + this.fileKey = FileKey.create(fd); + } + + @Override + public void add(FileLock fl) throws OverlappingFileLockException { + List<FileLockReference> list = lockMap.get(fileKey); + + for (;;) { + + // The key isn't in the map so we try to create it atomically + if (list == null) { + list = new ArrayList<FileLockReference>(2); + List<FileLockReference> prev; + synchronized (list) { + prev = lockMap.putIfAbsent(fileKey, list); + if (prev == null) { + // we successfully created the key so we add the file lock + list.add(new FileLockReference(fl, queue, fileKey)); + break; + } + } + // someone else got there first + list = prev; + } + + // There is already a key. It is possible that some other thread + // is removing it so we re-fetch the value from the map. If it + // hasn't changed then we check the list for overlapping locks + // and add the new lock to the list. + synchronized (list) { + List<FileLockReference> current = lockMap.get(fileKey); + if (list == current) { + checkList(list, fl.position(), fl.size()); + list.add(new FileLockReference(fl, queue, fileKey)); + break; + } + list = current; + } + + } + + // process any stale entries pending in the reference queue + removeStaleEntries(); + } + + private void removeKeyIfEmpty(FileKey fk, List<FileLockReference> list) { + assert Thread.holdsLock(list); + assert lockMap.get(fk) == list; + if (list.isEmpty()) { + lockMap.remove(fk); + } + } + + @Override + public void remove(FileLock fl) { + assert fl != null; + + // the lock must exist so the list of locks must be present + List<FileLockReference> list = lockMap.get(fileKey); + if (list == null) return; + + synchronized (list) { + int index = 0; + while (index < list.size()) { + FileLockReference ref = list.get(index); + FileLock lock = ref.get(); + if (lock == fl) { + assert (lock != null) && (lock.channel() == channel); + ref.clear(); + list.remove(index); + break; + } + index++; + } + } + } + + @Override + public void removeAll(Releaser releaser) throws IOException { + List<FileLockReference> list = lockMap.get(fileKey); + if (list != null) { + synchronized (list) { + int index = 0; + while (index < list.size()) { + FileLockReference ref = list.get(index); + FileLock lock = ref.get(); + + // remove locks obtained by this channel + if (lock != null && lock.channel() == channel) { + // invoke the releaser to invalidate/release the lock + releaser.release(lock); + + // remove the lock from the list + ref.clear(); + list.remove(index); + } else { + index++; + } + } + + // once the lock list is empty we remove it from the map + removeKeyIfEmpty(fileKey, list); + } + } + } + + @Override + public void replace(FileLock fromLock, FileLock toLock) { + // the lock must exist so there must be a list + List<FileLockReference> list = lockMap.get(fileKey); + assert list != null; + + synchronized (list) { + for (int index=0; index<list.size(); index++) { + FileLockReference ref = list.get(index); + FileLock lock = ref.get(); + if (lock == fromLock) { + ref.clear(); + list.set(index, new FileLockReference(toLock, queue, fileKey)); + break; + } + } + } + } + + // Check for overlapping file locks + private void checkList(List<FileLockReference> list, long position, long size) + throws OverlappingFileLockException + { + assert Thread.holdsLock(list); + for (FileLockReference ref: list) { + FileLock fl = ref.get(); + if (fl != null && fl.overlaps(position, size)) + throw new OverlappingFileLockException(); + } + } + + // Process the reference queue + private void removeStaleEntries() { + FileLockReference ref; + while ((ref = (FileLockReference)queue.poll()) != null) { + FileKey fk = ref.fileKey(); + List<FileLockReference> list = lockMap.get(fk); + if (list != null) { + synchronized (list) { + list.remove(ref); + removeKeyIfEmpty(fk, list); + } + } + } + } +} diff --git a/src/share/classes/sun/nio/ch/Groupable.java b/src/share/classes/sun/nio/ch/Groupable.java new file mode 100644 index 0000000000000000000000000000000000000000..b1760152b37806daaf872845d1747133ab35a444 --- /dev/null +++ b/src/share/classes/sun/nio/ch/Groupable.java @@ -0,0 +1,35 @@ +/* + * Copyright 2008-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 sun.nio.ch; + +/** + * Implemented by asynchronous channels that can be associated with an + * asynchronous channel group. + */ + +interface Groupable { + AsynchronousChannelGroupImpl group(); +} diff --git a/src/share/classes/sun/nio/ch/IOUtil.java b/src/share/classes/sun/nio/ch/IOUtil.java index f57b724b562767e86b8f815a79e1e171963bcef5..8d5bb13a2eec5abbc47fbefe2deaa91f4f4425ef 100644 --- a/src/share/classes/sun/nio/ch/IOUtil.java +++ b/src/share/classes/sun/nio/ch/IOUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2002 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. * * This code is free software; you can redistribute it and/or modify it @@ -27,10 +27,7 @@ package sun.nio.ch; import java.io.FileDescriptor; import java.io.IOException; -import java.net.*; import java.nio.ByteBuffer; -import java.nio.channels.*; -import java.nio.channels.spi.*; /** @@ -47,7 +44,6 @@ class IOUtil { */ private static int remaining(ByteBuffer[] bufs) { int numBufs = bufs.length; - boolean remaining = false; for (int i=0; i<numBufs; i++) { if (bufs[i].hasRemaining()) { return i; @@ -138,74 +134,82 @@ class IOUtil { bufs = skipBufs(bufs, nextWithRemaining); int numBufs = bufs.length; - int bytesReadyToWrite = 0; // Create shadow to ensure DirectByteBuffers are used ByteBuffer[] shadow = new ByteBuffer[numBufs]; - for (int i=0; i<numBufs; i++) { - if (!(bufs[i] instanceof DirectBuffer)) { - int pos = bufs[i].position(); - int lim = bufs[i].limit(); - assert (pos <= lim); - int rem = (pos <= lim ? lim - pos : 0); - - ByteBuffer bb = ByteBuffer.allocateDirect(rem); - shadow[i] = bb; - // Leave slow buffer position untouched; it will be updated - // after we see how many bytes were really written out - bb.put(bufs[i]); - bufs[i].position(pos); - bb.flip(); - } else { - shadow[i] = bufs[i]; - } - } - - IOVecWrapper vec = null; - long bytesWritten = 0; try { - // Create a native iovec array - vec= new IOVecWrapper(numBufs); - - // Fill in the iovec array with appropriate data for (int i=0; i<numBufs; i++) { - ByteBuffer nextBuffer = shadow[i]; - // put in the buffer addresses - long pos = nextBuffer.position(); - long len = nextBuffer.limit() - pos; - bytesReadyToWrite += len; - vec.putBase(i, ((DirectBuffer)nextBuffer).address() + pos); - vec.putLen(i, len); + if (!(bufs[i] instanceof DirectBuffer)) { + int pos = bufs[i].position(); + int lim = bufs[i].limit(); + assert (pos <= lim); + int rem = (pos <= lim ? lim - pos : 0); + + ByteBuffer bb = Util.getTemporaryDirectBuffer(rem); + shadow[i] = bb; + // Leave slow buffer position untouched; it will be updated + // after we see how many bytes were really written out + bb.put(bufs[i]); + bufs[i].position(pos); + bb.flip(); + } else { + shadow[i] = bufs[i]; + } } - // Invoke native call to fill the buffers - bytesWritten = nd.writev(fd, vec.address, numBufs); - } finally { - vec.free(); - } - long returnVal = bytesWritten; + IOVecWrapper vec = null; + long bytesWritten = 0; + try { + // Create a native iovec array + vec= new IOVecWrapper(numBufs); + + // Fill in the iovec array with appropriate data + for (int i=0; i<numBufs; i++) { + ByteBuffer nextBuffer = shadow[i]; + // put in the buffer addresses + long pos = nextBuffer.position(); + long len = nextBuffer.limit() - pos; + vec.putBase(i, ((DirectBuffer)nextBuffer).address() + pos); + vec.putLen(i, len); + } - // Notify the buffers how many bytes were taken - for (int i=0; i<numBufs; i++) { - ByteBuffer nextBuffer = bufs[i]; - int pos = nextBuffer.position(); - int lim = nextBuffer.limit(); - assert (pos <= lim); - int len = (pos <= lim ? lim - pos : lim); - if (bytesWritten >= len) { - bytesWritten -= len; - int newPosition = pos + len; - nextBuffer.position(newPosition); - } else { // Buffers not completely filled - if (bytesWritten > 0) { - assert(pos + bytesWritten < (long)Integer.MAX_VALUE); - int newPosition = (int)(pos + bytesWritten); + // Invoke native call to fill the buffers + bytesWritten = nd.writev(fd, vec.address, numBufs); + } finally { + vec.free(); + } + long returnVal = bytesWritten; + + // Notify the buffers how many bytes were taken + for (int i=0; i<numBufs; i++) { + ByteBuffer nextBuffer = bufs[i]; + int pos = nextBuffer.position(); + int lim = nextBuffer.limit(); + assert (pos <= lim); + int len = (pos <= lim ? lim - pos : lim); + if (bytesWritten >= len) { + bytesWritten -= len; + int newPosition = pos + len; nextBuffer.position(newPosition); + } else { // Buffers not completely filled + if (bytesWritten > 0) { + assert(pos + bytesWritten < (long)Integer.MAX_VALUE); + int newPosition = (int)(pos + bytesWritten); + nextBuffer.position(newPosition); + } + break; + } + } + return returnVal; + } finally { + // return any substituted buffers to cache + for (int i=0; i<numBufs; i++) { + ByteBuffer bb = shadow[i]; + if (bb != null && bb != bufs[i]) { + Util.releaseTemporaryDirectBuffer(bb); } - break; } } - return returnVal; } static int read(FileDescriptor fd, ByteBuffer dst, long position, @@ -270,68 +274,83 @@ class IOUtil { // Read into the shadow to ensure DirectByteBuffers are used ByteBuffer[] shadow = new ByteBuffer[numBufs]; - for (int i=0; i<numBufs; i++) { - if (bufs[i].isReadOnly()) - throw new IllegalArgumentException("Read-only buffer"); - if (!(bufs[i] instanceof DirectBuffer)) { - shadow[i] = ByteBuffer.allocateDirect(bufs[i].remaining()); - } else { - shadow[i] = bufs[i]; - } - } - - IOVecWrapper vec = null; - long bytesRead = 0; + boolean usingSlowBuffers = false; try { - // Create a native iovec array - vec = new IOVecWrapper(numBufs); - - // Fill in the iovec array with appropriate data for (int i=0; i<numBufs; i++) { - ByteBuffer nextBuffer = shadow[i]; - // put in the buffer addresses - long pos = nextBuffer.position(); - long len = nextBuffer.remaining(); - vec.putBase(i, ((DirectBuffer)nextBuffer).address() + pos); - vec.putLen(i, len); + if (bufs[i].isReadOnly()) + throw new IllegalArgumentException("Read-only buffer"); + if (!(bufs[i] instanceof DirectBuffer)) { + shadow[i] = Util.getTemporaryDirectBuffer(bufs[i].remaining()); + usingSlowBuffers = true; + } else { + shadow[i] = bufs[i]; + } } - // Invoke native call to fill the buffers - bytesRead = nd.readv(fd, vec.address, numBufs); - } finally { - vec.free(); - } - long returnVal = bytesRead; + IOVecWrapper vec = null; + long bytesRead = 0; + try { + // Create a native iovec array + vec = new IOVecWrapper(numBufs); + + // Fill in the iovec array with appropriate data + for (int i=0; i<numBufs; i++) { + ByteBuffer nextBuffer = shadow[i]; + // put in the buffer addresses + long pos = nextBuffer.position(); + long len = nextBuffer.remaining(); + vec.putBase(i, ((DirectBuffer)nextBuffer).address() + pos); + vec.putLen(i, len); + } - // Notify the buffers how many bytes were read - for (int i=0; i<numBufs; i++) { - ByteBuffer nextBuffer = shadow[i]; - // Note: should this have been cached from above? - int pos = nextBuffer.position(); - int len = nextBuffer.remaining(); - if (bytesRead >= len) { - bytesRead -= len; - int newPosition = pos + len; - nextBuffer.position(newPosition); - } else { // Buffers not completely filled - if (bytesRead > 0) { - assert(pos + bytesRead < (long)Integer.MAX_VALUE); - int newPosition = (int)(pos + bytesRead); + // Invoke native call to fill the buffers + bytesRead = nd.readv(fd, vec.address, numBufs); + } finally { + vec.free(); + } + long returnVal = bytesRead; + + // Notify the buffers how many bytes were read + for (int i=0; i<numBufs; i++) { + ByteBuffer nextBuffer = shadow[i]; + // Note: should this have been cached from above? + int pos = nextBuffer.position(); + int len = nextBuffer.remaining(); + if (bytesRead >= len) { + bytesRead -= len; + int newPosition = pos + len; nextBuffer.position(newPosition); + } else { // Buffers not completely filled + if (bytesRead > 0) { + assert(pos + bytesRead < (long)Integer.MAX_VALUE); + int newPosition = (int)(pos + bytesRead); + nextBuffer.position(newPosition); + } + break; } - break; } - } - // Put results from shadow into the slow buffers - for (int i=0; i<numBufs; i++) { - if (!(bufs[i] instanceof DirectBuffer)) { - shadow[i].flip(); - bufs[i].put(shadow[i]); + // Put results from shadow into the slow buffers + if (usingSlowBuffers) { + for (int i=0; i<numBufs; i++) { + if (!(bufs[i] instanceof DirectBuffer)) { + shadow[i].flip(); + bufs[i].put(shadow[i]); + } + } + } + return returnVal; + } finally { + // return any substituted buffers to cache + if (usingSlowBuffers) { + for (int i=0; i<numBufs; i++) { + ByteBuffer bb = shadow[i]; + if (bb != null && bb != bufs[i]) { + Util.releaseTemporaryDirectBuffer(bb); + } + } } } - - return returnVal; } static FileDescriptor newFD(int i) { diff --git a/src/share/classes/sun/nio/ch/Invoker.java b/src/share/classes/sun/nio/ch/Invoker.java new file mode 100644 index 0000000000000000000000000000000000000000..182f7989a469e14a1981656638cea716128632a2 --- /dev/null +++ b/src/share/classes/sun/nio/ch/Invoker.java @@ -0,0 +1,261 @@ +/* + * Copyright 2008-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 sun.nio.ch; + +import java.nio.channels.*; +import java.util.concurrent.*; +import java.security.AccessController; +import sun.security.action.GetIntegerAction; + +/** + * Defines static methods to invoke a completion handler or arbitrary task. + */ + +class Invoker { + private Invoker() { } + + // maximum number of completion handlers that may be invoked on the current + // thread before it re-directs invocations to the thread pool. This helps + // avoid stack overflow and lessens the risk of starvation. + private static final int maxHandlerInvokeCount = AccessController.doPrivileged( + new GetIntegerAction("sun.nio.ch.maxCompletionHandlersOnStack", 16)); + + // Per-thread object with reference to channel group and a counter for + // the number of completion handlers invoked. This should be reset to 0 + // when all completion handlers have completed. + static class GroupAndInvokeCount { + private final AsynchronousChannelGroupImpl group; + private int handlerInvokeCount; + GroupAndInvokeCount(AsynchronousChannelGroupImpl group) { + this.group = group; + } + AsynchronousChannelGroupImpl group() { + return group; + } + int invokeCount() { + return handlerInvokeCount; + } + void setInvokeCount(int value) { + handlerInvokeCount = value; + } + void resetInvokeCount() { + handlerInvokeCount = 0; + } + void incrementInvokeCount() { + handlerInvokeCount++; + } + } + private static final ThreadLocal<GroupAndInvokeCount> myGroupAndInvokeCount = + new ThreadLocal<GroupAndInvokeCount>() { + @Override protected GroupAndInvokeCount initialValue() { + return null; + } + }; + + /** + * Binds this thread to the given group + */ + static void bindToGroup(AsynchronousChannelGroupImpl group) { + myGroupAndInvokeCount.set(new GroupAndInvokeCount(group)); + } + + /** + * Returns the GroupAndInvokeCount object for this thread. + */ + static GroupAndInvokeCount getGroupAndInvokeCount() { + return myGroupAndInvokeCount.get(); + } + + /** + * Returns true if the current thread is in a channel group's thread pool + */ + static boolean isBoundToAnyGroup() { + return myGroupAndInvokeCount.get() != null; + } + + /** + * Returns true if the current thread is in the given channel's thread + * pool and we haven't exceeded the maximum number of handler frames on + * the stack. + */ + static boolean mayInvokeDirect(GroupAndInvokeCount myGroupAndInvokeCount, + AsynchronousChannelGroupImpl group) + { + if ((myGroupAndInvokeCount != null) && + (myGroupAndInvokeCount.group() == group) && + (myGroupAndInvokeCount.invokeCount() < maxHandlerInvokeCount)) + { + return true; + } + return false; + } + + /** + * Invoke handler without checking the thread identity or number of handlers + * on the thread stack. + */ + @SuppressWarnings("unchecked") + static <V,A> void invokeUnchecked(CompletionHandler<V,? super A> handler, + AbstractFuture<V,A> result) + { + if (handler != null && !result.isCancelled()) { + Throwable exc = result.exception(); + if (exc == null) { + handler.completed(result.value(), result.attachment()); + } else { + handler.failed(exc, result.attachment()); + } + + // clear interrupt + Thread.interrupted(); + } + } + + + /** + * Invoke handler after incrementing the invoke count. + */ + static <V,A> void invokeDirect(GroupAndInvokeCount myGroupAndInvokeCount, + CompletionHandler<V,? super A> handler, + AbstractFuture<V,A> result) + { + myGroupAndInvokeCount.incrementInvokeCount(); + invokeUnchecked(handler, result); + } + + /** + * Invokes the handler. If the current thread is in the channel group's + * thread pool then the handler is invoked directly, otherwise it is + * invoked indirectly. + */ + static <V,A> void invoke(CompletionHandler<V,? super A> handler, + AbstractFuture<V,A> result) + { + if (handler != null) { + boolean invokeDirect = false; + boolean identityOkay = false; + GroupAndInvokeCount thisGroupAndInvokeCount = myGroupAndInvokeCount.get(); + if (thisGroupAndInvokeCount != null) { + AsynchronousChannel channel = result.channel(); + if ((thisGroupAndInvokeCount.group() == ((Groupable)channel).group())) + identityOkay = true; + if (identityOkay && + (thisGroupAndInvokeCount.invokeCount() < maxHandlerInvokeCount)) + { + // group match + invokeDirect = true; + } + } + if (invokeDirect) { + thisGroupAndInvokeCount.incrementInvokeCount(); + invokeUnchecked(handler, result); + } else { + try { + invokeIndirectly(handler, result); + } catch (RejectedExecutionException ree) { + // channel group shutdown; fallback to invoking directly + // if the current thread has the right identity. + if (identityOkay) { + invokeUnchecked(handler, result); + } else { + throw new ShutdownChannelGroupException(); + } + } + } + } + } + + /** + * Invokes the handler "indirectly" in the channel group's thread pool. + */ + static <V,A> void invokeIndirectly(final CompletionHandler<V,? super A> handler, + final AbstractFuture<V,A> result) + { + if (handler != null) { + AsynchronousChannel channel = result.channel(); + try { + ((Groupable)channel).group().executeOnPooledThread(new Runnable() { + public void run() { + GroupAndInvokeCount thisGroupAndInvokeCount = + myGroupAndInvokeCount.get(); + if (thisGroupAndInvokeCount != null) + thisGroupAndInvokeCount.setInvokeCount(1); + invokeUnchecked(handler, result); + } + }); + } catch (RejectedExecutionException ree) { + throw new ShutdownChannelGroupException(); + } + } + } + + /** + * Invokes the handler "indirectly" in the given Executor + */ + static <V,A> void invokeIndirectly(final CompletionHandler<V,? super A> handler, + final AbstractFuture<V,A> result, + Executor executor) + { + if (handler != null) { + try { + executor.execute(new Runnable() { + public void run() { + invokeUnchecked(handler, result); + } + }); + } catch (RejectedExecutionException ree) { + throw new ShutdownChannelGroupException(); + } + } + } + + /** + * Invokes the given task on the thread pool associated with the given + * channel. If the current thread is in the thread pool then the task is + * invoked directly. + */ + static void invokeOnThreadInThreadPool(Groupable channel, + Runnable task) + { + boolean invokeDirect; + GroupAndInvokeCount thisGroupAndInvokeCount = myGroupAndInvokeCount.get(); + AsynchronousChannelGroupImpl targetGroup = channel.group(); + if (thisGroupAndInvokeCount == null) { + invokeDirect = false; + } else { + invokeDirect = (thisGroupAndInvokeCount.group == targetGroup); + } + try { + if (invokeDirect) { + task.run(); + } else { + targetGroup.executeOnPooledThread(task); + } + } catch (RejectedExecutionException ree) { + throw new ShutdownChannelGroupException(); + } + } +} diff --git a/src/share/classes/sun/nio/ch/MembershipKeyImpl.java b/src/share/classes/sun/nio/ch/MembershipKeyImpl.java index 687f79c009509e41acdbce3d53472987ba7ebb74..0089ffd4440dd2a91c48d295d68c1add3549ca29 100644 --- a/src/share/classes/sun/nio/ch/MembershipKeyImpl.java +++ b/src/share/classes/sun/nio/ch/MembershipKeyImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2007-2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2008-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 @@ -85,7 +85,7 @@ class MembershipKeyImpl this.sourceAddress = sourceAddress; } - int group() { + int groupAddress() { return groupAddress; } @@ -120,7 +120,7 @@ class MembershipKeyImpl this.sourceAddress = sourceAddress; } - byte[] group() { + byte[] groupAddress() { return groupAddress; } @@ -142,28 +142,28 @@ class MembershipKeyImpl valid = false; } - public void drop() throws IOException { + public void drop() { // delegate to channel ((DatagramChannelImpl)ch).drop(this); } @Override - public MulticastChannel getChannel() { + public MulticastChannel channel() { return ch; } @Override - public InetAddress getGroup() { + public InetAddress group() { return group; } @Override - public NetworkInterface getNetworkInterface() { + public NetworkInterface networkInterface() { return interf; } @Override - public InetAddress getSourceAddress() { + public InetAddress sourceAddress() { return source; } @@ -191,9 +191,7 @@ class MembershipKeyImpl } @Override - public MembershipKey unblock(InetAddress toUnblock) - throws IOException - { + public MembershipKey unblock(InetAddress toUnblock) { synchronized (stateLock) { if ((blockedSet == null) || !blockedSet.contains(toUnblock)) throw new IllegalStateException("not blocked"); diff --git a/src/share/classes/sun/nio/ch/MembershipRegistry.java b/src/share/classes/sun/nio/ch/MembershipRegistry.java index 5a2a8ef7447e6f970f062037a7aa69b714906432..fc90be39d16b6cf156cd34b9786e87a1c7ea2f65 100644 --- a/src/share/classes/sun/nio/ch/MembershipRegistry.java +++ b/src/share/classes/sun/nio/ch/MembershipRegistry.java @@ -1,5 +1,5 @@ /* - * Copyright 2007-2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2008-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 @@ -55,20 +55,20 @@ class MembershipRegistry { List<MembershipKeyImpl> keys = groups.get(group); if (keys != null) { for (MembershipKeyImpl key: keys) { - if (key.getNetworkInterface().equals(interf)) { + if (key.networkInterface().equals(interf)) { // already a member to receive all packets so return // existing key or detect conflict if (source == null) { - if (key.getSourceAddress() == null) + if (key.sourceAddress() == null) return key; throw new IllegalStateException("Already a member to receive all packets"); } // already have source-specific membership so return key // or detect conflict - if (key.getSourceAddress() == null) + if (key.sourceAddress() == null) throw new IllegalStateException("Already have source-specific membership"); - if (source.equals(key.getSourceAddress())) + if (source.equals(key.sourceAddress())) return key; } } @@ -81,7 +81,7 @@ class MembershipRegistry { * Add membership to the registry, returning a new membership key. */ void add(MembershipKeyImpl key) { - InetAddress group = key.getGroup(); + InetAddress group = key.group(); List<MembershipKeyImpl> keys; if (groups == null) { groups = new HashMap<InetAddress,List<MembershipKeyImpl>>(); @@ -100,7 +100,7 @@ class MembershipRegistry { * Remove a key from the registry */ void remove(MembershipKeyImpl key) { - InetAddress group = key.getGroup(); + InetAddress group = key.group(); List<MembershipKeyImpl> keys = groups.get(group); if (keys != null) { Iterator<MembershipKeyImpl> i = keys.iterator(); @@ -120,9 +120,11 @@ class MembershipRegistry { * Invalidate all keys in the registry */ void invalidateAll() { - for (InetAddress group: groups.keySet()) { - for (MembershipKeyImpl key: groups.get(group)) { - key.invalidate(); + if (groups != null) { + for (InetAddress group: groups.keySet()) { + for (MembershipKeyImpl key: groups.get(group)) { + key.invalidate(); + } } } } diff --git a/src/share/classes/sun/nio/ch/NativeThreadSet.java b/src/share/classes/sun/nio/ch/NativeThreadSet.java index 612befcbbd09641c85e44faeffb339f20a036a12..a009541d97c2f01870c6622f0d191658e0b62957 100644 --- a/src/share/classes/sun/nio/ch/NativeThreadSet.java +++ b/src/share/classes/sun/nio/ch/NativeThreadSet.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2002-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 @@ -33,6 +33,7 @@ class NativeThreadSet { private long[] elts; private int used = 0; + private boolean waitingToEmpty; NativeThreadSet(int n) { elts = new long[n]; @@ -75,12 +76,14 @@ class NativeThreadSet { synchronized (this) { elts[i] = 0; used--; + if (used == 0 && waitingToEmpty) + notifyAll(); } } // Signals all threads in this set. // - void signal() { + void signalAndWait() { synchronized (this) { int u = used; int n = elts.length; @@ -92,7 +95,12 @@ class NativeThreadSet { if (--u == 0) break; } + waitingToEmpty = true; + while (used > 0) { + try { + wait(); + } catch (InterruptedException ignore) { } + } } } - } diff --git a/src/share/classes/sun/nio/ch/Net.java b/src/share/classes/sun/nio/ch/Net.java index ba0ba0bdcdecd83964f2c2fa093e28f5e807e528..f910c5db05e1edee6693dee228dd7206f6a4ad9c 100644 --- a/src/share/classes/sun/nio/ch/Net.java +++ b/src/share/classes/sun/nio/ch/Net.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2008 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. * * This code is free software; you can redistribute it and/or modify it @@ -207,7 +207,7 @@ class Net { // package-private // -- Socket options static void setSocketOption(FileDescriptor fd, ProtocolFamily family, - SocketOption name, Object value) + SocketOption<?> name, Object value) throws IOException { if (value == null) @@ -262,7 +262,7 @@ class Net { // package-private } static Object getSocketOption(FileDescriptor fd, ProtocolFamily family, - SocketOption name) + SocketOption<?> name) throws IOException { Class<?> type = name.type(); diff --git a/src/share/classes/sun/nio/ch/OptionKey.java b/src/share/classes/sun/nio/ch/OptionKey.java index 70ba8a6fa7144e6463348e95104c06dce3589607..88474533587a7f4af30d1fb9b975e15465e2247b 100644 --- a/src/share/classes/sun/nio/ch/OptionKey.java +++ b/src/share/classes/sun/nio/ch/OptionKey.java @@ -1,5 +1,5 @@ /* - * Copyright 2007-2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2008 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 diff --git a/src/share/classes/sun/nio/ch/PendingFuture.java b/src/share/classes/sun/nio/ch/PendingFuture.java new file mode 100644 index 0000000000000000000000000000000000000000..d88cf233a821a03e3174fe3f2b6288b1029a1e84 --- /dev/null +++ b/src/share/classes/sun/nio/ch/PendingFuture.java @@ -0,0 +1,257 @@ +/* + * Copyright 2008-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 sun.nio.ch; + +import java.nio.channels.*; +import java.util.concurrent.*; +import java.io.IOException; + +/** + * A Future for a pending I/O operation. A PendingFuture allows for the + * attachment of an additional arbitrary context object and a timer task. + */ + +final class PendingFuture<V,A> + extends AbstractFuture<V,A> +{ + private static final CancellationException CANCELLED = + new CancellationException(); + + private final CompletionHandler<V,? super A> handler; + + // true if result (or exception) is available + private volatile boolean haveResult; + private volatile V result; + private volatile Throwable exc; + + // latch for waiting (created lazily if needed) + private CountDownLatch latch; + + // optional timer task that is cancelled when result becomes available + private Future<?> timeoutTask; + + // optional context object + private volatile Object context; + + + PendingFuture(AsynchronousChannel channel, + CompletionHandler<V,? super A> handler, + A attachment, + Object context) + { + super(channel, attachment); + this.handler = handler; + this.context = context; + } + + PendingFuture(AsynchronousChannel channel, + CompletionHandler<V,? super A> handler, + A attachment) + { + super(channel, attachment); + this.handler = handler; + } + + CompletionHandler<V,? super A> handler() { + return handler; + } + + void setContext(Object context) { + this.context = context; + } + + Object getContext() { + return context; + } + + void setTimeoutTask(Future<?> task) { + synchronized (this) { + if (haveResult) { + task.cancel(false); + } else { + this.timeoutTask = task; + } + } + } + + // creates latch if required; return true if caller needs to wait + private boolean prepareForWait() { + synchronized (this) { + if (haveResult) { + return false; + } else { + if (latch == null) + latch = new CountDownLatch(1); + return true; + } + } + } + + /** + * Sets the result, or a no-op if the result or exception is already set. + */ + boolean setResult(V res) { + synchronized (this) { + if (haveResult) + return false; + result = res; + haveResult = true; + if (timeoutTask != null) + timeoutTask.cancel(false); + if (latch != null) + latch.countDown(); + return true; + } + } + + /** + * Sets the result, or a no-op if the result or exception is already set. + */ + boolean setFailure(Throwable x) { + if (!(x instanceof IOException) && !(x instanceof SecurityException)) + x = new IOException(x); + synchronized (this) { + if (haveResult) + return false; + exc = x; + haveResult = true; + if (timeoutTask != null) + timeoutTask.cancel(false); + if (latch != null) + latch.countDown(); + return true; + } + } + + @Override + public V get() throws ExecutionException, InterruptedException { + if (!haveResult) { + boolean needToWait = prepareForWait(); + if (needToWait) + latch.await(); + } + if (exc != null) { + if (exc == CANCELLED) + throw new CancellationException(); + throw new ExecutionException(exc); + } + return result; + } + + @Override + public V get(long timeout, TimeUnit unit) + throws ExecutionException, InterruptedException, TimeoutException + { + if (!haveResult) { + boolean needToWait = prepareForWait(); + if (needToWait) + if (!latch.await(timeout, unit)) throw new TimeoutException(); + } + if (exc != null) { + if (exc == CANCELLED) + throw new CancellationException(); + throw new ExecutionException(exc); + } + return result; + } + + @Override + Throwable exception() { + return (exc != CANCELLED) ? exc : null; + } + + @Override + V value() { + return result; + } + + @Override + public boolean isCancelled() { + return (exc == CANCELLED); + } + + @Override + public boolean isDone() { + return haveResult; + } + + @Override + public boolean cancel(boolean mayInterruptIfRunning) { + synchronized (this) { + if (haveResult) + return false; // already completed + + // A shutdown of the channel group will close all channels and + // shutdown the executor. To ensure that the completion handler + // is executed we queue the task while holding the lock. + if (handler != null) { + prepareForWait(); + Runnable cancelTask = new Runnable() { + public void run() { + while (!haveResult) { + try { + latch.await(); + } catch (InterruptedException ignore) { } + } + handler.cancelled(attachment()); + } + }; + AsynchronousChannel ch = channel(); + if (ch instanceof Groupable) { + ((Groupable)ch).group().executeOnPooledThread(cancelTask); + } else { + if (ch instanceof AsynchronousFileChannelImpl) { + ((AsynchronousFileChannelImpl)ch).executor().execute(cancelTask); + } else { + throw new AssertionError("Should not get here"); + } + } + } + + // notify channel + if (channel() instanceof Cancellable) + ((Cancellable)channel()).onCancel(this); + + // set result and cancel timer + exc = CANCELLED; + haveResult = true; + if (timeoutTask != null) + timeoutTask.cancel(false); + } + + // close channel if forceful cancel + if (mayInterruptIfRunning) { + try { + channel().close(); + } catch (IOException ignore) { } + } + + // release waiters (this also releases the invoker) + if (latch != null) + latch.countDown(); + return true; + } +} diff --git a/src/share/classes/sun/nio/ch/Reflect.java b/src/share/classes/sun/nio/ch/Reflect.java index 913357fcd9ecba8003ac5813f7919ba324eb5884..cc4716eb1adb9f73b593e2a8588226a80ac43341 100644 --- a/src/share/classes/sun/nio/ch/Reflect.java +++ b/src/share/classes/sun/nio/ch/Reflect.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2008 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. * * This code is free software; you can redistribute it and/or modify it @@ -55,7 +55,7 @@ class Reflect { // package-private { try { Class<?> cl = Class.forName(className); - Constructor c = cl.getDeclaredConstructor(paramTypes); + Constructor<?> c = cl.getDeclaredConstructor(paramTypes); setAccessible(c); return c; } catch (ClassNotFoundException x) { @@ -79,7 +79,7 @@ class Reflect { // package-private static Method lookupMethod(String className, String methodName, - Class[] paramTypes) + Class... paramTypes) { try { Class<?> cl = Class.forName(className); diff --git a/src/share/classes/sun/nio/ch/SelChImpl.java b/src/share/classes/sun/nio/ch/SelChImpl.java index 0ef4d357f8d1be3f05cb8bad40e0eeb0bf6ac18e..fb1571d84d2039ddf2e82ac428c28c76beb4e882 100644 --- a/src/share/classes/sun/nio/ch/SelChImpl.java +++ b/src/share/classes/sun/nio/ch/SelChImpl.java @@ -25,6 +25,7 @@ package sun.nio.ch; +import java.nio.channels.Channel; import java.io.FileDescriptor; import java.io.IOException; @@ -35,7 +36,7 @@ import java.io.IOException; * @since 1.4 */ -interface SelChImpl { +interface SelChImpl extends Channel { FileDescriptor getFD(); diff --git a/src/share/classes/sun/nio/ch/ServerSocketChannelImpl.java b/src/share/classes/sun/nio/ch/ServerSocketChannelImpl.java index fd532980b0b7d1923da051131908a99a9147323f..0b0e4b6aee24f0d7473d2c49c609ab8e6fbddaff 100644 --- a/src/share/classes/sun/nio/ch/ServerSocketChannelImpl.java +++ b/src/share/classes/sun/nio/ch/ServerSocketChannelImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2008 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. * * This code is free software; you can redistribute it and/or modify it @@ -27,13 +27,11 @@ package sun.nio.ch; import java.io.FileDescriptor; import java.io.IOException; -import java.lang.reflect.*; import java.net.*; import java.nio.channels.*; import java.nio.channels.spi.*; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.util.*; +import sun.net.NetHooks; /** @@ -111,19 +109,19 @@ class ServerSocketChannelImpl public SocketAddress getLocalAddress() throws IOException { synchronized (stateLock) { if (!isOpen()) - return null; + throw new ClosedChannelException(); return localAddress; } } @Override - public ServerSocketChannel setOption(SocketOption name, Object value) + public <T> ServerSocketChannel setOption(SocketOption<T> name, T value) throws IOException { if (name == null) throw new NullPointerException(); - if (!options().contains(name)) - throw new IllegalArgumentException("invalid option name"); + if (!supportedOptions().contains(name)) + throw new UnsupportedOperationException("'" + name + "' not supported"); synchronized (stateLock) { if (!isOpen()) @@ -142,8 +140,8 @@ class ServerSocketChannelImpl { if (name == null) throw new NullPointerException(); - if (!options().contains(name)) - throw new IllegalArgumentException("invalid option name"); + if (!supportedOptions().contains(name)) + throw new UnsupportedOperationException("'" + name + "' not supported"); synchronized (stateLock) { if (!isOpen()) @@ -154,7 +152,7 @@ class ServerSocketChannelImpl } } - private static class LazyInitialization { + private static class DefaultOptionsHolder { static final Set<SocketOption<?>> defaultOptions = defaultOptions(); private static Set<SocketOption<?>> defaultOptions() { @@ -166,8 +164,8 @@ class ServerSocketChannelImpl } @Override - public final Set<SocketOption<?>> options() { - return LazyInitialization.defaultOptions; + public final Set<SocketOption<?>> supportedOptions() { + return DefaultOptionsHolder.defaultOptions; } public boolean isBound() { @@ -194,6 +192,7 @@ class ServerSocketChannelImpl SecurityManager sm = System.getSecurityManager(); if (sm != null) sm.checkListen(isa.getPort()); + NetHooks.beforeTcpBind(fd, isa.getAddress(), isa.getPort()); Net.bind(fd, isa.getAddress(), isa.getPort()); Net.listen(fd, backlog < 1 ? 50 : backlog); synchronized (stateLock) { diff --git a/src/share/classes/sun/nio/ch/SimpleAsynchronousDatagramChannelImpl.java b/src/share/classes/sun/nio/ch/SimpleAsynchronousDatagramChannelImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..47c3b2abd29059e116ea86b5e28774228a35e6e0 --- /dev/null +++ b/src/share/classes/sun/nio/ch/SimpleAsynchronousDatagramChannelImpl.java @@ -0,0 +1,612 @@ +/* + * Copyright 2008-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 sun.nio.ch; + +import java.nio.ByteBuffer; +import java.nio.channels.*; +import java.net.*; +import java.io.IOException; +import java.util.*; +import java.util.concurrent.*; +import java.security.AccessController; +import java.security.AccessControlContext; +import java.security.PrivilegedExceptionAction; +import java.security.PrivilegedActionException; + +/** + * A prototype implementation of AsynchronousDatagramChannel, used to aid + * test and spec development. + */ + +class SimpleAsynchronousDatagramChannelImpl + extends AsynchronousDatagramChannel implements Groupable, Cancellable +{ + private final DatagramChannel dc; + private final AsynchronousChannelGroupImpl group; + private final Object attachKey; + private boolean closed; + + // used to coordinate timed and blocking reads + private final Object readLock = new Object(); + + // channel blocking mode (requires readLock) + private boolean isBlocking = true; + + // number of blocking readers (requires readLock) + private int blockingReaderCount; + + // true if timed read attempted while blocking read in progress (requires readLock) + private boolean transitionToNonBlocking; + + // true if a blocking read is cancelled (requires readLock) + private boolean blockingReadKilledByCancel; + + // temporary Selectors used by timed reads (requires readLock) + private Selector firstReader; + private Set<Selector> otherReaders; + + SimpleAsynchronousDatagramChannelImpl(ProtocolFamily family, + AsynchronousChannelGroupImpl group) + throws IOException + { + super(group.provider()); + this.dc = (family == null) ? + DatagramChannel.open() : DatagramChannel.open(family); + this.group = group; + + // attach this channel to the group as foreign channel + boolean registered = false; + try { + if (!(dc instanceof DatagramChannelImpl)) + throw new UnsupportedOperationException(); + attachKey = group + .attachForeignChannel(this, ((DatagramChannelImpl)dc).getFD()); + registered = true; + } finally { + if (!registered) + dc.close(); + } + } + + // throws RuntimeException if blocking read has been cancelled + private void ensureBlockingReadNotKilled() { + assert Thread.holdsLock(readLock); + if (blockingReadKilledByCancel) + throw new RuntimeException("Reading not allowed due to cancellation"); + } + + // invoke prior to non-timed read/receive + private void beginNoTimeoutRead() { + synchronized (readLock) { + ensureBlockingReadNotKilled(); + if (isBlocking) + blockingReaderCount++; + } + } + + // invoke after non-timed read/receive has completed + private void endNoTimeoutRead() { + synchronized (readLock) { + if (isBlocking) { + if (--blockingReaderCount == 0 && transitionToNonBlocking) { + // notify any threads waiting to make channel non-blocking + readLock.notifyAll(); + } + } + } + } + + // invoke prior to timed read + // returns the timeout remaining + private long prepareForTimedRead(PendingFuture<?,?> result, long timeout) + throws IOException + { + synchronized (readLock) { + ensureBlockingReadNotKilled(); + if (isBlocking) { + transitionToNonBlocking = true; + while (blockingReaderCount > 0 && + timeout > 0L && + !result.isCancelled()) + { + long st = System.currentTimeMillis(); + try { + readLock.wait(timeout); + } catch (InterruptedException e) { } + timeout -= System.currentTimeMillis() - st; + } + if (blockingReaderCount == 0) { + // re-check that blocked read wasn't cancelled + ensureBlockingReadNotKilled(); + // no blocking reads so change channel to non-blocking + dc.configureBlocking(false); + isBlocking = false; + } + } + return timeout; + } + } + + // returns a temporary Selector + private Selector getSelector() throws IOException { + Selector sel = Util.getTemporarySelector(dc); + synchronized (readLock) { + if (firstReader == null) { + firstReader = sel; + } else { + if (otherReaders == null) + otherReaders = new HashSet<Selector>(); + otherReaders.add(sel); + } + } + return sel; + } + + // releases a temporary Selector + private void releaseSelector(Selector sel) throws IOException { + synchronized (readLock) { + if (firstReader == sel) { + firstReader = null; + } else { + otherReaders.remove(sel); + } + } + Util.releaseTemporarySelector(sel); + } + + // wakeup all Selectors currently in use + private void wakeupSelectors() { + synchronized (readLock) { + if (firstReader != null) + firstReader.wakeup(); + if (otherReaders != null) { + for (Selector sel: otherReaders) { + sel.wakeup(); + } + } + } + } + + @Override + public AsynchronousChannelGroupImpl group() { + return group; + } + + @Override + public boolean isOpen() { + return dc.isOpen(); + } + + @Override + public void onCancel(PendingFuture<?,?> task) { + synchronized (readLock) { + if (blockingReaderCount > 0) { + blockingReadKilledByCancel = true; + readLock.notifyAll(); + return; + } + } + wakeupSelectors(); + } + + @Override + public void close() throws IOException { + synchronized (dc) { + if (closed) + return; + closed = true; + } + // detach from group and close underlying channel + group.detachForeignChannel(attachKey); + dc.close(); + + // wakeup any threads blocked in timed read/receives + wakeupSelectors(); + } + + @Override + public AsynchronousDatagramChannel connect(SocketAddress remote) + throws IOException + { + dc.connect(remote); + return this; + } + + @Override + public AsynchronousDatagramChannel disconnect() throws IOException { + dc.disconnect(); + return this; + } + + private static class WrappedMembershipKey extends MembershipKey { + private final MulticastChannel channel; + private final MembershipKey key; + + WrappedMembershipKey(MulticastChannel channel, MembershipKey key) { + this.channel = channel; + this.key = key; + } + + @Override + public boolean isValid() { + return key.isValid(); + } + + @Override + public void drop() { + key.drop(); + } + + @Override + public MulticastChannel channel() { + return channel; + } + + @Override + public InetAddress group() { + return key.group(); + } + + @Override + public NetworkInterface networkInterface() { + return key.networkInterface(); + } + + @Override + public InetAddress sourceAddress() { + return key.sourceAddress(); + } + + @Override + public MembershipKey block(InetAddress toBlock) throws IOException { + key.block(toBlock); + return this; + } + + @Override + public MembershipKey unblock(InetAddress toUnblock) { + key.unblock(toUnblock); + return this; + } + + @Override + public String toString() { + return key.toString(); + } + } + + @Override + public MembershipKey join(InetAddress group, + NetworkInterface interf) + throws IOException + { + MembershipKey key = ((MulticastChannel)dc).join(group, interf); + return new WrappedMembershipKey(this, key); + } + + @Override + public MembershipKey join(InetAddress group, + NetworkInterface interf, + InetAddress source) + throws IOException + { + MembershipKey key = ((MulticastChannel)dc).join(group, interf, source); + return new WrappedMembershipKey(this, key); + } + + @Override + public <A> Future<Integer> send(ByteBuffer src, + SocketAddress target, + long timeout, + TimeUnit unit, + A attachment, + CompletionHandler<Integer,? super A> handler) + { + if (timeout < 0L) + throw new IllegalArgumentException("Negative timeout"); + if (unit == null) + throw new NullPointerException(); + + CompletedFuture<Integer,A> result; + try { + int n = dc.send(src, target); + result = CompletedFuture.withResult(this, n, attachment); + } catch (IOException ioe) { + result = CompletedFuture.withFailure(this, ioe, attachment); + } + Invoker.invoke(handler, result); + return result; + } + + @Override + public <A> Future<Integer> write(ByteBuffer src, + long timeout, + TimeUnit unit, + A attachment, + CompletionHandler<Integer,? super A> handler) + { + if (timeout < 0L) + throw new IllegalArgumentException("Negative timeout"); + if (unit == null) + throw new NullPointerException(); + + CompletedFuture<Integer,A> result; + try { + int n = dc.write(src); + result = CompletedFuture.withResult(this, n, attachment); + } catch (IOException ioe) { + result = CompletedFuture.withFailure(this, ioe, attachment); + } + Invoker.invoke(handler, result); + return result; + } + + /** + * Receive into the given buffer with privileges enabled and restricted by + * the given AccessControlContext (can be null). + */ + private SocketAddress doRestrictedReceive(final ByteBuffer dst, + AccessControlContext acc) + throws IOException + { + if (acc == null) { + return dc.receive(dst); + } else { + try { + return AccessController.doPrivileged( + new PrivilegedExceptionAction<SocketAddress>() { + public SocketAddress run() throws IOException { + return dc.receive(dst); + }}, acc); + } catch (PrivilegedActionException pae) { + Exception cause = pae.getException(); + if (cause instanceof SecurityException) + throw (SecurityException)cause; + throw (IOException)cause; + } + } + } + + @Override + public <A> Future<SocketAddress> receive(final ByteBuffer dst, + final long timeout, + final TimeUnit unit, + A attachment, + final CompletionHandler<SocketAddress,? super A> handler) + { + if (dst.isReadOnly()) + throw new IllegalArgumentException("Read-only buffer"); + if (timeout < 0L) + throw new IllegalArgumentException("Negative timeout"); + if (unit == null) + throw new NullPointerException(); + + // complete immediately if channel closed + if (!isOpen()) { + CompletedFuture<SocketAddress,A> result = CompletedFuture.withFailure(this, + new ClosedChannelException(), attachment); + Invoker.invoke(handler, result); + return result; + } + + final AccessControlContext acc = (System.getSecurityManager() == null) ? + null : AccessController.getContext(); + final PendingFuture<SocketAddress,A> result = + new PendingFuture<SocketAddress,A>(this, handler, attachment); + Runnable task = new Runnable() { + public void run() { + try { + SocketAddress remote = null; + long to; + if (timeout == 0L) { + beginNoTimeoutRead(); + try { + remote = doRestrictedReceive(dst, acc); + } finally { + endNoTimeoutRead(); + } + to = 0L; + } else { + to = prepareForTimedRead(result, unit.toMillis(timeout)); + if (to <= 0L) + throw new InterruptedByTimeoutException(); + remote = doRestrictedReceive(dst, acc); + } + if (remote == null) { + Selector sel = getSelector(); + SelectionKey sk = null; + try { + sk = dc.register(sel, SelectionKey.OP_READ); + for (;;) { + if (!dc.isOpen()) + throw new AsynchronousCloseException(); + if (result.isCancelled()) + break; + long st = System.currentTimeMillis(); + int ns = sel.select(to); + if (ns > 0) { + remote = doRestrictedReceive(dst, acc); + if (remote != null) + break; + } + sel.selectedKeys().remove(sk); + if (timeout != 0L) { + to -= System.currentTimeMillis() - st; + if (to <= 0) + throw new InterruptedByTimeoutException(); + } + } + } finally { + if (sk != null) + sk.cancel(); + releaseSelector(sel); + } + } + result.setResult(remote); + } catch (Throwable x) { + if (x instanceof ClosedChannelException) + x = new AsynchronousCloseException(); + result.setFailure(x); + } + Invoker.invokeUnchecked(handler, result); + } + }; + try { + group.executeOnPooledThread(task); + } catch (RejectedExecutionException ree) { + throw new ShutdownChannelGroupException(); + } + return result; + } + + @Override + public <A> Future<Integer> read(final ByteBuffer dst, + final long timeout, + final TimeUnit unit, + A attachment, + final CompletionHandler<Integer,? super A> handler) + { + if (dst.isReadOnly()) + throw new IllegalArgumentException("Read-only buffer"); + if (timeout < 0L) + throw new IllegalArgumentException("Negative timeout"); + if (unit == null) + throw new NullPointerException(); + // another thread may disconnect before read is initiated + if (!dc.isConnected()) + throw new NotYetConnectedException(); + + // complete immediately if channel closed + if (!isOpen()) { + CompletedFuture<Integer,A> result = CompletedFuture.withFailure(this, + new ClosedChannelException(), attachment); + Invoker.invoke(handler, result); + return result; + } + + final PendingFuture<Integer,A> result = + new PendingFuture<Integer,A>(this, handler, attachment); + Runnable task = new Runnable() { + public void run() { + try { + int n = 0; + long to; + if (timeout == 0L) { + beginNoTimeoutRead(); + try { + n = dc.read(dst); + } finally { + endNoTimeoutRead(); + } + to = 0L; + } else { + to = prepareForTimedRead(result, unit.toMillis(timeout)); + if (to <= 0L) + throw new InterruptedByTimeoutException(); + n = dc.read(dst); + } + if (n == 0) { + Selector sel = getSelector(); + SelectionKey sk = null; + try { + sk = dc.register(sel, SelectionKey.OP_READ); + for (;;) { + if (!dc.isOpen()) + throw new AsynchronousCloseException(); + if (result.isCancelled()) + break; + long st = System.currentTimeMillis(); + int ns = sel.select(to); + if (ns > 0) { + if ((n = dc.read(dst)) != 0) + break; + } + sel.selectedKeys().remove(sk); + if (timeout != 0L) { + to -= System.currentTimeMillis() - st; + if (to <= 0) + throw new InterruptedByTimeoutException(); + } + } + } finally { + if (sk != null) + sk.cancel(); + releaseSelector(sel); + } + } + result.setResult(n); + } catch (Throwable x) { + if (x instanceof ClosedChannelException) + x = new AsynchronousCloseException(); + result.setFailure(x); + } + Invoker.invokeUnchecked(handler, result); + } + }; + try { + group.executeOnPooledThread(task); + } catch (RejectedExecutionException ree) { + throw new ShutdownChannelGroupException(); + } + return result; + } + + @Override + public AsynchronousDatagramChannel bind(SocketAddress local) + throws IOException + { + dc.bind(local); + return this; + } + + @Override + public SocketAddress getLocalAddress() throws IOException { + return dc.getLocalAddress(); + } + + @Override + public <T> AsynchronousDatagramChannel setOption(SocketOption<T> name, T value) + throws IOException + { + dc.setOption(name, value); + return this; + } + + @Override + public <T> T getOption(SocketOption<T> name) throws IOException { + return dc.getOption(name); + } + + @Override + public Set<SocketOption<?>> supportedOptions() { + return dc.supportedOptions(); + } + + @Override + public SocketAddress getRemoteAddress() throws IOException { + return dc.getRemoteAddress(); + } +} diff --git a/src/share/classes/sun/nio/ch/SimpleAsynchronousFileChannelImpl.java b/src/share/classes/sun/nio/ch/SimpleAsynchronousFileChannelImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..52fe5a2802f18aca761735535aa0b1e79a2c1ecf --- /dev/null +++ b/src/share/classes/sun/nio/ch/SimpleAsynchronousFileChannelImpl.java @@ -0,0 +1,426 @@ +/* + * Copyright 2008-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 sun.nio.ch; + +import java.nio.channels.*; +import java.util.concurrent.*; +import java.nio.ByteBuffer; +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.io.FileDescriptor; +import java.io.IOException; + +/** + * "Portable" implementation of AsynchronousFileChannel for use on operating + * systems that don't support asynchronous file I/O. + */ + +public class SimpleAsynchronousFileChannelImpl + extends AsynchronousFileChannelImpl +{ + // lazy initialization of default thread pool for file I/O + private static class DefaultExecutorHolder { + static final ExecutorService defaultExecutor = + ThreadPool.createDefault().executor(); + } + + // Used to make native read and write calls + private static final FileDispatcher nd = new FileDispatcherImpl(); + + // indicates if the associated thread pool is the default thread pool + private final boolean isDefaultExecutor; + + // Thread-safe set of IDs of native threads, for signalling + private final NativeThreadSet threads = new NativeThreadSet(2); + + + SimpleAsynchronousFileChannelImpl(FileDescriptor fdObj, + boolean reading, + boolean writing, + ExecutorService executor, + boolean isDefaultexecutor) + { + super(fdObj, reading, writing, executor); + this.isDefaultExecutor = isDefaultexecutor; + } + + public static AsynchronousFileChannel open(FileDescriptor fdo, + boolean reading, + boolean writing, + ThreadPool pool) + { + // Executor is either default or based on pool parameters + ExecutorService executor; + boolean isDefaultexecutor; + if (pool == null) { + executor = DefaultExecutorHolder.defaultExecutor; + isDefaultexecutor = true; + } else { + executor = pool.executor(); + isDefaultexecutor = false; + } + return new SimpleAsynchronousFileChannelImpl(fdo, + reading, writing, executor, isDefaultexecutor); + } + + @Override + public void close() throws IOException { + // mark channel as closed + synchronized (fdObj) { + if (closed) + return; // already closed + closed = true; + // from this point on, if another thread invokes the begin() method + // then it will throw ClosedChannelException + } + + // signal any threads blocked on this channel + nd.preClose(fdObj); + threads.signalAndWait(); + + // wait until all async I/O operations have completely gracefully + closeLock.writeLock().lock(); + try { + // do nothing + } finally { + closeLock.writeLock().unlock(); + } + + // Invalidate and release any locks that we still hold + invalidateAllLocks(); + + // close file + nd.close(fdObj); + + // shutdown executor if specific to this channel + if (!isDefaultExecutor) { + AccessController.doPrivileged(new PrivilegedAction<Void>() { + public Void run() { + executor.shutdown(); + return null; + } + }); + } + } + + @Override + public long size() throws IOException { + int ti = threads.add(); + try { + long n = 0L; + try { + begin(); + do { + n = nd.size(fdObj); + } while ((n == IOStatus.INTERRUPTED) && isOpen()); + return n; + } finally { + end(n >= 0L); + } + } finally { + threads.remove(ti); + } + } + + @Override + public AsynchronousFileChannel truncate(long size) throws IOException { + if (size < 0L) + throw new IllegalArgumentException("Negative size"); + if (!writing) + throw new NonWritableChannelException(); + int ti = threads.add(); + try { + long n = 0L; + try { + begin(); + do { + n = nd.size(fdObj); + } while ((n == IOStatus.INTERRUPTED) && isOpen()); + + // truncate file if 'size' less than current size + if (size < n && isOpen()) { + do { + n = nd.truncate(fdObj, size); + } while ((n == IOStatus.INTERRUPTED) && isOpen()); + } + return this; + } finally { + end(n > 0); + } + } finally { + threads.remove(ti); + } + } + + @Override + public void force(boolean metaData) throws IOException { + int ti = threads.add(); + try { + int n = 0; + try { + begin(); + do { + n = nd.force(fdObj, metaData); + } while ((n == IOStatus.INTERRUPTED) && isOpen()); + } finally { + end(n >= 0); + } + } finally { + threads.remove(ti); + } + } + + @Override + public <A> Future<FileLock> lock(final long position, + final long size, + final boolean shared, + A attachment, + final CompletionHandler<FileLock,? super A> handler) + { + if (shared && !reading) + throw new NonReadableChannelException(); + if (!shared && !writing) + throw new NonWritableChannelException(); + + // add to lock table + final FileLockImpl fli = addToFileLockTable(position, size, shared); + if (fli == null) { + CompletedFuture<FileLock,A> result = CompletedFuture + .withFailure(this, new ClosedChannelException(), attachment); + Invoker.invokeIndirectly(handler, result, executor); + return result; + } + + final PendingFuture<FileLock,A> result = + new PendingFuture<FileLock,A>(this, handler, attachment); + Runnable task = new Runnable() { + public void run() { + int ti = threads.add(); + try { + int n; + try { + begin(); + do { + n = nd.lock(fdObj, true, position, size, shared); + } while ((n == FileDispatcher.INTERRUPTED) && isOpen()); + if (n == FileDispatcher.LOCKED) { + result.setResult(fli); + } else { + if (n != FileDispatcher.INTERRUPTED) + throw new AssertionError(); + throw new AsynchronousCloseException(); + } + } catch (IOException x) { + removeFromFileLockTable(fli); + if (!isOpen()) + x = new AsynchronousCloseException(); + result.setFailure(x); + } finally { + end(); + } + } finally { + threads.remove(ti); + } + Invoker.invokeUnchecked(handler, result); + } + }; + try { + executor.execute(task); + } catch (RejectedExecutionException ree) { + // rollback + removeFromFileLockTable(fli); + throw new ShutdownChannelGroupException(); + } + return result; + } + + @Override + public FileLock tryLock(long position, long size, boolean shared) + throws IOException + { + if (shared && !reading) + throw new NonReadableChannelException(); + if (!shared && !writing) + throw new NonWritableChannelException(); + + // add to lock table + FileLockImpl fli = addToFileLockTable(position, size, shared); + if (fli == null) + throw new ClosedChannelException(); + + int ti = threads.add(); + boolean gotLock = false; + try { + begin(); + int n; + do { + n = nd.lock(fdObj, false, position, size, shared); + } while ((n == FileDispatcher.INTERRUPTED) && isOpen()); + if (n != FileDispatcher.LOCKED) { + if (n == FileDispatcher.NO_LOCK) + return null; // locked by someone else + if (n == FileDispatcher.INTERRUPTED) + throw new AsynchronousCloseException(); + // should not get here + throw new AssertionError(); + } + gotLock = true; + return fli; + } finally { + if (!gotLock) + removeFromFileLockTable(fli); + end(); + threads.remove(ti); + } + } + + @Override + void release(FileLockImpl fli) throws IOException { + try { + begin(); + nd.release(fdObj, fli.position(), fli.size()); + removeFromFileLockTable(fli); + } finally { + end(); + } + } + + @Override + public <A> Future<Integer> read(final ByteBuffer dst, + final long position, + A attachment, + final CompletionHandler<Integer,? super A> handler) + { + if (position < 0) + throw new IllegalArgumentException("Negative position"); + if (!reading) + throw new NonReadableChannelException(); + if (dst.isReadOnly()) + throw new IllegalArgumentException("Read-only buffer"); + + // complete immediately if channel closed or no space remaining + if (!isOpen() || (dst.remaining() == 0)) { + CompletedFuture<Integer,A> result; + if (isOpen()) { + result = CompletedFuture.withResult(this, 0, attachment); + } else { + result = CompletedFuture.withFailure(this, + new ClosedChannelException(), attachment); + } + Invoker.invokeIndirectly(handler, result, executor); + return result; + } + + final PendingFuture<Integer,A> result = + new PendingFuture<Integer,A>(this, handler, attachment); + Runnable task = new Runnable() { + public void run() { + int ti = threads.add(); + try { + begin(); + int n; + do { + n = IOUtil.read(fdObj, dst, position, nd, null); + } while ((n == IOStatus.INTERRUPTED) && isOpen()); + if (n < 0 && !isOpen()) + throw new AsynchronousCloseException(); + result.setResult(n); + } catch (IOException x) { + if (!isOpen()) + x = new AsynchronousCloseException(); + result.setFailure(x); + } finally { + end(); + threads.remove(ti); + } + Invoker.invokeUnchecked(handler, result); + } + }; + try { + executor.execute(task); + } catch (RejectedExecutionException ree) { + throw new ShutdownChannelGroupException(); + } + return result; + } + + @Override + public <A> Future<Integer> write(final ByteBuffer src, + final long position, + A attachment, + final CompletionHandler<Integer,? super A> handler) + { + if (position < 0) + throw new IllegalArgumentException("Negative position"); + if (!writing) + throw new NonWritableChannelException(); + + // complete immediately if channel is closed or no bytes remaining + if (!isOpen() || (src.remaining() == 0)) { + CompletedFuture<Integer,A> result; + if (isOpen()) { + result = CompletedFuture.withResult(this, 0, attachment); + } else { + result = CompletedFuture.withFailure(this, + new ClosedChannelException(), attachment); + } + Invoker.invokeIndirectly(handler, result, executor); + return result; + } + + final PendingFuture<Integer,A> result = + new PendingFuture<Integer,A>(this, handler, attachment); + Runnable task = new Runnable() { + public void run() { + int ti = threads.add(); + try { + begin(); + int n; + do { + n = IOUtil.write(fdObj, src, position, nd, null); + } while ((n == IOStatus.INTERRUPTED) && isOpen()); + if (n < 0 && !isOpen()) + throw new AsynchronousCloseException(); + result.setResult(n); + } catch (IOException x) { + if (!isOpen()) + x = new AsynchronousCloseException(); + result.setFailure(x); + } finally { + end(); + threads.remove(ti); + } + Invoker.invokeUnchecked(handler, result); + } + }; + try { + executor.execute(task); + } catch (RejectedExecutionException ree) { + throw new ShutdownChannelGroupException(); + } + return result; + } +} diff --git a/src/share/classes/sun/nio/ch/SocketChannelImpl.java b/src/share/classes/sun/nio/ch/SocketChannelImpl.java index 11567ba2ab7e1ec2586dfd9621028c3c0f08eee5..ec4f8f5754b05fdb431c67b936e2e88cbf7785a0 100644 --- a/src/share/classes/sun/nio/ch/SocketChannelImpl.java +++ b/src/share/classes/sun/nio/ch/SocketChannelImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2008 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. * * This code is free software; you can redistribute it and/or modify it @@ -32,6 +32,7 @@ import java.nio.ByteBuffer; import java.nio.channels.*; import java.nio.channels.spi.*; import java.util.*; +import sun.net.NetHooks; /** @@ -128,28 +129,28 @@ class SocketChannelImpl public SocketAddress getLocalAddress() throws IOException { synchronized (stateLock) { if (!isOpen()) - return null; + throw new ClosedChannelException(); return localAddress; } } @Override - public SocketAddress getConnectedAddress() throws IOException { + public SocketAddress getRemoteAddress() throws IOException { synchronized (stateLock) { if (!isOpen()) - return null; + throw new ClosedChannelException(); return remoteAddress; } } @Override - public SocketChannel setOption(SocketOption name, Object value) + public <T> SocketChannel setOption(SocketOption<T> name, T value) throws IOException { if (name == null) throw new NullPointerException(); - if (!options().contains(name)) - throw new IllegalArgumentException("Invalid option name"); + if (!supportedOptions().contains(name)) + throw new UnsupportedOperationException("'" + name + "' not supported"); synchronized (stateLock) { if (!isOpen()) @@ -175,8 +176,8 @@ class SocketChannelImpl { if (name == null) throw new NullPointerException(); - if (!options().contains(name)) - throw new IllegalArgumentException("Invalid option name"); + if (!supportedOptions().contains(name)) + throw new UnsupportedOperationException("'" + name + "' not supported"); synchronized (stateLock) { if (!isOpen()) @@ -193,7 +194,7 @@ class SocketChannelImpl } } - private static class LazyInitialization { + private static class DefaultOptionsHolder { static final Set<SocketOption<?>> defaultOptions = defaultOptions(); private static Set<SocketOption<?>> defaultOptions() { @@ -212,8 +213,8 @@ class SocketChannelImpl } @Override - public final Set<SocketOption<?>> options() { - return LazyInitialization.defaultOptions; + public final Set<SocketOption<?>> supportedOptions() { + return DefaultOptionsHolder.defaultOptions; } private boolean ensureReadOpen() throws ClosedChannelException { @@ -526,6 +527,7 @@ class SocketChannelImpl throw new AlreadyBoundException(); InetSocketAddress isa = (local == null) ? new InetSocketAddress(0) : Net.checkAddress(local); + NetHooks.beforeTcpBind(fd, isa.getAddress(), isa.getPort()); Net.bind(fd, isa.getAddress(), isa.getPort()); localAddress = Net.localAddress(fd); } @@ -577,6 +579,12 @@ class SocketChannelImpl if (!isOpen()) { return false; } + // notify hook only if unbound + if (localAddress == null) { + NetHooks.beforeTcpConnect(fd, + isa.getAddress(), + isa.getPort()); + } readerThread = NativeThread.current(); } for (;;) { diff --git a/src/share/classes/sun/nio/ch/ThreadPool.java b/src/share/classes/sun/nio/ch/ThreadPool.java new file mode 100644 index 0000000000000000000000000000000000000000..37e6a80a0bad0280b0328c8740ef77b1494fc321 --- /dev/null +++ b/src/share/classes/sun/nio/ch/ThreadPool.java @@ -0,0 +1,176 @@ +/* + * Copyright 2008-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 sun.nio.ch; + +import java.util.concurrent.*; +import java.security.AccessController; +import sun.security.action.GetPropertyAction; +import sun.security.action.GetIntegerAction; + +/** + * Encapsulates a thread pool associated with a channel group. + */ + +public class ThreadPool { + private static final String DEFAULT_THREAD_POOL_THREAD_FACTORY = + "java.nio.channels.DefaultThreadPool.threadFactory"; + private static final String DEFAULT_THREAD_POOL_INITIAL_SIZE = + "java.nio.channels.DefaultThreadPool.initialSize"; + private static final ThreadFactory defaultThreadFactory = new ThreadFactory() { + @Override + public Thread newThread(Runnable r) { + Thread t = new Thread(r); + t.setDaemon(true); + return t; + } + }; + + private final ExecutorService executor; + + // indicates if thread pool is fixed size + private final boolean isFixed; + + // indicates the pool size (for a fixed thread pool configuratin this is + // the maximum pool size; for other thread pools it is the initial size) + private final int poolSize; + + private ThreadPool(ExecutorService executor, + boolean isFixed, + int poolSize) + { + this.executor = executor; + this.isFixed = isFixed; + this.poolSize = poolSize; + } + + ExecutorService executor() { + return executor; + } + + boolean isFixedThreadPool() { + return isFixed; + } + + int poolSize() { + return poolSize; + } + + static ThreadFactory defaultThreadFactory() { + return defaultThreadFactory; + } + + private static class DefaultThreadPoolHolder { + final static ThreadPool defaultThreadPool = createDefault(); + } + + // return the default (system-wide) thread pool + static ThreadPool getDefault() { + return DefaultThreadPoolHolder.defaultThreadPool; + } + + // create thread using default settings (configured by system properties) + static ThreadPool createDefault() { + // default the number of fixed threads to the hardware core count + int initialSize = getDefaultThreadPoolInitialSize(); + if (initialSize < 0) + initialSize = Runtime.getRuntime().availableProcessors(); + // default to thread factory that creates daemon threads + ThreadFactory threadFactory = getDefaultThreadPoolThreadFactory(); + if (threadFactory == null) + threadFactory = defaultThreadFactory; + // create thread pool + ExecutorService executor = + new ThreadPoolExecutor(0, Integer.MAX_VALUE, + Long.MAX_VALUE, TimeUnit.MILLISECONDS, + new SynchronousQueue<Runnable>(), + threadFactory); + return new ThreadPool(executor, false, initialSize); + } + + // create using given parameters + static ThreadPool create(int nThreads, ThreadFactory factory) { + if (nThreads <= 0) + throw new IllegalArgumentException("'nThreads' must be > 0"); + ExecutorService executor = Executors.newFixedThreadPool(nThreads, factory); + return new ThreadPool(executor, true, nThreads); + } + + // wrap a user-supplied executor + public static ThreadPool wrap(ExecutorService executor, int initialSize) { + if (executor == null) + throw new NullPointerException("'executor' is null"); + // attempt to check if cached thread pool + if (executor instanceof ThreadPoolExecutor) { + int max = ((ThreadPoolExecutor)executor).getMaximumPoolSize(); + if (max == Integer.MAX_VALUE) { + if (initialSize < 0) { + initialSize = Runtime.getRuntime().availableProcessors(); + } else { + // not a cached thread pool so ignore initial size + initialSize = 0; + } + } + } else { + // some other type of thread pool + if (initialSize < 0) + initialSize = 0; + } + return new ThreadPool(executor, false, initialSize); + } + + private static int getDefaultThreadPoolInitialSize() { + String propValue = AccessController.doPrivileged(new + GetPropertyAction(DEFAULT_THREAD_POOL_INITIAL_SIZE)); + if (propValue != null) { + try { + return Integer.parseInt(propValue); + } catch (NumberFormatException x) { + throw new Error("Value of property '" + DEFAULT_THREAD_POOL_INITIAL_SIZE + + "' is invalid: " + x); + } + } + return -1; + } + + private static ThreadFactory getDefaultThreadPoolThreadFactory() { + String propValue = AccessController.doPrivileged(new + GetPropertyAction(DEFAULT_THREAD_POOL_THREAD_FACTORY)); + if (propValue != null) { + try { + Class<?> c = Class + .forName(propValue, true, ClassLoader.getSystemClassLoader()); + return ((ThreadFactory)c.newInstance()); + } catch (ClassNotFoundException x) { + throw new Error(x); + } catch (InstantiationException x) { + throw new Error(x); + } catch (IllegalAccessException x) { + throw new Error(x); + } + } + return null; + } +} diff --git a/src/share/classes/sun/nio/ch/Util.java b/src/share/classes/sun/nio/ch/Util.java index 534548ff7788663b4abd3b98cd0e4afdfaecf7ac..efdce4a4b9a0b2f6d343488ca178d42b40c417c3 100644 --- a/src/share/classes/sun/nio/ch/Util.java +++ b/src/share/classes/sun/nio/ch/Util.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2008 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. * * This code is free software; you can redistribute it and/or modify it @@ -31,7 +31,6 @@ import java.io.IOException; import java.nio.ByteBuffer; import java.nio.MappedByteBuffer; import java.nio.channels.*; -import java.nio.channels.spi.*; import java.security.AccessController; import java.security.PrivilegedAction; import java.util.*; @@ -100,6 +99,9 @@ class Util { return; } } + + // release memory + ((DirectBuffer)buf).cleaner().clean(); } private static class SelectorWrapper { diff --git a/src/share/classes/sun/misc/JavaIODeleteOnExitAccess.java b/src/share/classes/sun/nio/cs/ArrayDecoder.java similarity index 81% rename from src/share/classes/sun/misc/JavaIODeleteOnExitAccess.java rename to src/share/classes/sun/nio/cs/ArrayDecoder.java index 54aef8b428a76b6f3e0bb212c29a60b4379dbb72..daff5ec39d1744ef722b015c2fe72b4e75e206bb 100644 --- a/src/share/classes/sun/misc/JavaIODeleteOnExitAccess.java +++ b/src/share/classes/sun/nio/cs/ArrayDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2005 Sun Microsystems, Inc. All Rights Reserved. + * 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 @@ -23,8 +23,13 @@ * have any questions. */ -package sun.misc; +package sun.nio.cs; -public interface JavaIODeleteOnExitAccess extends Runnable { - public void run(); +/* + * FastPath byte[]->char[] decoder, REPLACE on malformed or + * unmappable input. + */ + +public interface ArrayDecoder { + int decode(byte[] src, int off, int len, char[] dst); } diff --git a/src/share/classes/sun/nio/cs/ArrayEncoder.java b/src/share/classes/sun/nio/cs/ArrayEncoder.java new file mode 100644 index 0000000000000000000000000000000000000000..1eb4726f70b7ecc03962156d0dddb4ee10ba5ca8 --- /dev/null +++ b/src/share/classes/sun/nio/cs/ArrayEncoder.java @@ -0,0 +1,35 @@ +/* + * 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 sun.nio.cs; + +/* + * FastPath char[]->byte[] encoder, REPLACE on malformed input or + * unmappable input. + */ + +public interface ArrayEncoder { + int encode(char[] src, int off, int len, byte[] dst); +} diff --git a/src/share/classes/sun/nio/cs/ISO_8859_1.java b/src/share/classes/sun/nio/cs/ISO_8859_1.java index ad27a1507ac3722db2533d99f0ad17e45e05a9cd..7eb3b5b8a833b661f2f958e8f6056e58e5f417bd 100644 --- a/src/share/classes/sun/nio/cs/ISO_8859_1.java +++ b/src/share/classes/sun/nio/cs/ISO_8859_1.java @@ -23,9 +23,6 @@ * have any questions. */ -/* - */ - package sun.nio.cs; import java.nio.ByteBuffer; @@ -34,10 +31,7 @@ import java.nio.charset.Charset; import java.nio.charset.CharsetDecoder; import java.nio.charset.CharsetEncoder; import java.nio.charset.CoderResult; -import java.nio.charset.CharacterCodingException; -import java.nio.charset.MalformedInputException; -import java.nio.charset.UnmappableCharacterException; - +import java.util.Arrays; class ISO_8859_1 extends Charset @@ -65,8 +59,8 @@ class ISO_8859_1 return new Encoder(this); } - private static class Decoder extends CharsetDecoder { - + private static class Decoder extends CharsetDecoder + implements ArrayDecoder { private Decoder(Charset cs) { super(cs, 1.0f, 1.0f); } @@ -127,10 +121,18 @@ class ISO_8859_1 return decodeBufferLoop(src, dst); } + public int decode(byte[] src, int sp, int len, char[] dst) { + if (len > dst.length) + len = dst.length; + int dp = 0; + while (dp < len) + dst[dp++] = (char)(src[sp++] & 0xff); + return dp; + } } - private static class Encoder extends CharsetEncoder { - + private static class Encoder extends CharsetEncoder + implements ArrayEncoder { private Encoder(Charset cs) { super(cs, 1.0f, 1.0f); } @@ -139,6 +141,10 @@ class ISO_8859_1 return c <= '\u00FF'; } + public boolean isLegalReplacement(byte[] repl) { + return (repl.length == 1); // we accept any byte value + } + private final Surrogate.Parser sgp = new Surrogate.Parser(); private CoderResult encodeArrayLoop(CharBuffer src, @@ -208,5 +214,31 @@ class ISO_8859_1 return encodeBufferLoop(src, dst); } + private byte repl = (byte)'?'; + protected void implReplaceWith(byte[] newReplacement) { + repl = newReplacement[0]; + } + + public int encode(char[] src, int sp, int len, byte[] dst) { + int dp = 0; + int sl = sp + Math.min(len, dst.length); + while (sp < sl) { + char c = src[sp++]; + if (c <= '\u00FF') { + dst[dp++] = (byte)c; + continue; + } + if (Surrogate.isHigh(c) && sp < sl && + Surrogate.isLow(src[sp])) { + if (len > dst.length) { + sl++; + len--; + } + sp++; + } + dst[dp++] = repl; + } + return dp; + } } } diff --git a/src/share/classes/sun/nio/cs/SingleByte.java b/src/share/classes/sun/nio/cs/SingleByte.java index fdbf4e3c6436234a523de587aaefd062d1fccb55..9b0531eebd93a90ce0978cdff65ca252f08f623e 100644 --- a/src/share/classes/sun/nio/cs/SingleByte.java +++ b/src/share/classes/sun/nio/cs/SingleByte.java @@ -32,6 +32,7 @@ import java.nio.charset.Charset; import java.nio.charset.CharsetDecoder; import java.nio.charset.CharsetEncoder; import java.nio.charset.CoderResult; +import java.util.Arrays; import static sun.nio.cs.CharsetMapping.*; public class SingleByte @@ -45,7 +46,8 @@ public class SingleByte return cr; } - public static class Decoder extends CharsetDecoder { + final public static class Decoder extends CharsetDecoder + implements ArrayDecoder { private final char[] b2c; public Decoder(Charset cs, char[] b2c) { @@ -108,9 +110,29 @@ public class SingleByte private final char decode(int b) { return b2c[b + 128]; } + + private char repl = '\uFFFD'; + protected void implReplaceWith(String newReplacement) { + repl = newReplacement.charAt(0); + } + + public int decode(byte[] src, int sp, int len, char[] dst) { + if (len > dst.length) + len = dst.length; + int dp = 0; + while (dp < len) { + dst[dp] = decode(src[sp++]); + if (dst[dp] == UNMAPPABLE_DECODING) { + dst[dp] = repl; + } + dp++; + } + return dp; + } } - public static class Encoder extends CharsetEncoder { + final public static class Encoder extends CharsetEncoder + implements ArrayEncoder { private Surrogate.Parser sgp; private final char[] c2b; private final char[] c2bIndex; @@ -125,6 +147,11 @@ public class SingleByte return encode(c) != UNMAPPABLE_ENCODING; } + public boolean isLegalReplacement(byte[] repl) { + return ((repl.length == 1 && repl[0] == (byte)'?') || + super.isLegalReplacement(repl)); + } + private CoderResult encodeArrayLoop(CharBuffer src, ByteBuffer dst) { char[] sa = src.array(); int sp = src.arrayOffset() + src.position(); @@ -200,6 +227,34 @@ public class SingleByte return UNMAPPABLE_ENCODING; return c2b[index + (ch & 0xff)]; } + + private byte repl = (byte)'?'; + protected void implReplaceWith(byte[] newReplacement) { + repl = newReplacement[0]; + } + + public int encode(char[] src, int sp, int len, byte[] dst) { + int dp = 0; + int sl = sp + Math.min(len, dst.length); + while (sp < sl) { + char c = src[sp++]; + int b = encode(c); + if (b != UNMAPPABLE_ENCODING) { + dst[dp++] = (byte)b; + continue; + } + if (Surrogate.isHigh(c) && sp < sl && + Surrogate.isLow(src[sp])) { + if (len > dst.length) { + sl++; + len--; + } + sp++; + } + dst[dp++] = repl; + } + return dp; + } } // init the c2b and c2bIndex tables from b2c. diff --git a/src/share/classes/sun/nio/cs/US_ASCII.java b/src/share/classes/sun/nio/cs/US_ASCII.java index d22fa64e352446fdd73f4218fc9bdb32ac8a526d..fa718450768cb1f6609496f796e3cc23f9c5a6ac 100644 --- a/src/share/classes/sun/nio/cs/US_ASCII.java +++ b/src/share/classes/sun/nio/cs/US_ASCII.java @@ -31,10 +31,7 @@ import java.nio.charset.Charset; import java.nio.charset.CharsetDecoder; import java.nio.charset.CharsetEncoder; import java.nio.charset.CoderResult; -import java.nio.charset.CharacterCodingException; -import java.nio.charset.MalformedInputException; -import java.nio.charset.UnmappableCharacterException; - +import java.util.Arrays; public class US_ASCII extends Charset @@ -61,7 +58,8 @@ public class US_ASCII return new Encoder(this); } - private static class Decoder extends CharsetDecoder { + private static class Decoder extends CharsetDecoder + implements ArrayDecoder { private Decoder(Charset cs) { super(cs, 1.0f, 1.0f); @@ -131,9 +129,27 @@ public class US_ASCII return decodeBufferLoop(src, dst); } + private char repl = '\uFFFD'; + protected void implReplaceWith(String newReplacement) { + repl = newReplacement.charAt(0); + } + + public int decode(byte[] src, int sp, int len, char[] dst) { + int dp = 0; + len = Math.min(len, dst.length); + while (dp < len) { + byte b = src[sp++]; + if (b >= 0) + dst[dp++] = (char)b; + else + dst[dp++] = repl; + } + return dp; + } } - private static class Encoder extends CharsetEncoder { + private static class Encoder extends CharsetEncoder + implements ArrayEncoder { private Encoder(Charset cs) { super(cs, 1.0f, 1.0f); @@ -143,8 +159,11 @@ public class US_ASCII return c < 0x80; } - private final Surrogate.Parser sgp = new Surrogate.Parser(); + public boolean isLegalReplacement(byte[] repl) { + return (repl.length == 1 && repl[0] >= 0); + } + private final Surrogate.Parser sgp = new Surrogate.Parser(); private CoderResult encodeArrayLoop(CharBuffer src, ByteBuffer dst) { @@ -213,6 +232,32 @@ public class US_ASCII return encodeBufferLoop(src, dst); } + private byte repl = (byte)'?'; + protected void implReplaceWith(byte[] newReplacement) { + repl = newReplacement[0]; + } + + public int encode(char[] src, int sp, int len, byte[] dst) { + int dp = 0; + int sl = sp + Math.min(len, dst.length); + while (sp < sl) { + char c = src[sp++]; + if (c < 0x80) { + dst[dp++] = (byte)c; + continue; + } + if (Surrogate.isHigh(c) && sp < sl && + Surrogate.isLow(src[sp])) { + if (len > dst.length) { + sl++; + len--; + } + sp++; + } + dst[dp++] = repl; + } + return dp; + } } } diff --git a/src/share/classes/sun/nio/fs/AbstractAclFileAttributeView.java b/src/share/classes/sun/nio/fs/AbstractAclFileAttributeView.java new file mode 100644 index 0000000000000000000000000000000000000000..053e3dcfbb0191aefe6c8c42ebc1b4d28622326d --- /dev/null +++ b/src/share/classes/sun/nio/fs/AbstractAclFileAttributeView.java @@ -0,0 +1,110 @@ +/* + * Copyright 2008-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 sun.nio.fs; + +import java.nio.file.attribute.*; +import java.io.IOException; +import java.util.*; + +/** + * Base implementation of AclFileAttributeView + */ + +abstract class AbstractAclFileAttributeView + implements AclFileAttributeView +{ + private static final String OWNER_NAME = "owner"; + private static final String ACL_NAME = "acl"; + + @Override + public final String name() { + return "acl"; + } + + @Override + public final Object getAttribute(String attribute) throws IOException { + if (attribute.equals(OWNER_NAME)) + return getOwner(); + if (attribute.equals(ACL_NAME)) + return getAcl(); + return null; + } + + @Override + @SuppressWarnings("unchecked") + public final void setAttribute(String attribute, Object value) + throws IOException + { + if (attribute.equals(OWNER_NAME)) { + setOwner((UserPrincipal)value); + return; + } + if (attribute.equals(ACL_NAME)) { + setAcl((List<AclEntry>)value); + return; + } + throw new UnsupportedOperationException(); + } + + @Override + public final Map<String,?> readAttributes(String first, String[] rest) + throws IOException + { + boolean acl = false; + boolean owner = false; + + if (first.equals(ACL_NAME)) acl = true; + else if (first.equals(OWNER_NAME)) owner = true; + else if (first.equals("*")) { + owner = true; + acl = true; + } + + if (!acl || !owner) { + for (String attribute: rest) { + if (attribute.equals("*")) { + owner = true; + acl = true; + break; + } + if (attribute.equals(ACL_NAME)) { + acl = true; + continue; + } + if (attribute.equals(OWNER_NAME)) { + owner = true; + continue; + } + } + } + Map<String,Object> result = new HashMap<String,Object>(2); + if (acl) + result.put(ACL_NAME, getAcl()); + if (owner) + result.put(OWNER_NAME, getOwner()); + return Collections.unmodifiableMap(result); + } +} diff --git a/src/share/classes/sun/nio/fs/AbstractBasicFileAttributeView.java b/src/share/classes/sun/nio/fs/AbstractBasicFileAttributeView.java new file mode 100644 index 0000000000000000000000000000000000000000..18cf00d501c6cb189dd34dc30fe0864ad5fa5194 --- /dev/null +++ b/src/share/classes/sun/nio/fs/AbstractBasicFileAttributeView.java @@ -0,0 +1,208 @@ +/* + * Copyright 2008-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 sun.nio.fs; + +import java.nio.file.attribute.*; +import java.io.IOException; +import java.util.*; +import java.util.concurrent.TimeUnit; + +/** + * Base implementation of BasicFileAttributeView + */ + +abstract class AbstractBasicFileAttributeView + implements BasicFileAttributeView +{ + private static final String SIZE_NAME = "size"; + private static final String CREATION_TIME_NAME = "creationTime"; + private static final String LAST_ACCESS_TIME_NAME = "lastAccessTime"; + private static final String LAST_MODIFIED_TIME_NAME = "lastModifiedTime"; + private static final String RESOLUTION_NAME = "resolution"; + private static final String FILE_KEY_NAME = "fileKey"; + private static final String LINK_COUNT_NAME = "linkCount"; + private static final String IS_DIRECTORY_NAME = "isDirectory"; + private static final String IS_REGULAR_FILE_NAME = "isRegularFile"; + private static final String IS_SYMBOLIC_LINK_NAME = "isSymbolicLink"; + private static final String IS_OTHER_NAME = "isOther"; + + protected AbstractBasicFileAttributeView() { } + + @Override + public String name() { + return "basic"; + } + + @Override + public Object getAttribute(String attribute) throws IOException { + BasicFileAttributes attrs = readAttributes(); + if (attribute.equals(SIZE_NAME)) + return attrs.size(); + if (attribute.equals(CREATION_TIME_NAME)) + return attrs.creationTime(); + if (attribute.equals(LAST_ACCESS_TIME_NAME)) + return attrs.lastAccessTime(); + if (attribute.equals(LAST_MODIFIED_TIME_NAME)) + return attrs.lastModifiedTime(); + if (attribute.equals(RESOLUTION_NAME)) + return attrs.resolution(); + if (attribute.equals(FILE_KEY_NAME)) + return attrs.fileKey(); + if (attribute.equals(LINK_COUNT_NAME)) + return attrs.linkCount(); + if (attribute.equals(IS_DIRECTORY_NAME)) + return attrs.isDirectory(); + if (attribute.equals(IS_REGULAR_FILE_NAME)) + return attrs.isRegularFile(); + if (attribute.equals(IS_SYMBOLIC_LINK_NAME)) + return attrs.isSymbolicLink(); + if (attribute.equals(IS_OTHER_NAME)) + return attrs.isOther(); + return null; + } + + private Long toTimeValue(Object value) { + if (value == null) + throw new NullPointerException(); + Long time = (Long)value; + if (time < 0L && time != -1L) + throw new IllegalArgumentException("time value cannot be negative"); + return time; + } + + @Override + public void setAttribute(String attribute, Object value) + throws IOException + { + if (attribute.equals(LAST_MODIFIED_TIME_NAME)) { + setTimes(toTimeValue(value), null, null, TimeUnit.MILLISECONDS); + return; + } + if (attribute.equals(LAST_ACCESS_TIME_NAME)) { + setTimes(null, toTimeValue(value), null, TimeUnit.MILLISECONDS); + return; + } + if (attribute.equals(CREATION_TIME_NAME)) { + setTimes(null, null, toTimeValue(value), TimeUnit.MILLISECONDS); + return; + } + throw new UnsupportedOperationException("'" + attribute + + "' is unknown or read-only attribute"); + } + + /** + * + */ + static class AttributesBuilder { + private Set<String> set = new HashSet<String>(); + private Map<String,Object> map = new HashMap<String,Object>(); + private boolean copyAll; + + private AttributesBuilder(String first, String[] rest) { + if (first.equals("*")) { + copyAll = true; + } else { + set.add(first); + // copy names into the given Set bailing out if "*" is found + for (String attribute: rest) { + if (attribute.equals("*")) { + copyAll = true; + break; + } + set.add(attribute); + } + } + } + + /** + * Creates builder to build up a map of the matching attributes + */ + static AttributesBuilder create(String first, String[] rest) { + return new AttributesBuilder(first, rest); + } + + /** + * Returns true if the attribute should be returned in the map + */ + boolean match(String attribute) { + if (copyAll) + return true; + return set.contains(attribute); + } + + void add(String attribute, Object value) { + map.put(attribute, value); + } + + /** + * Returns the map. Discard all references to the AttributesBuilder + * after invoking this method. + */ + Map<String,Object> unmodifiableMap() { + return Collections.unmodifiableMap(map); + } + } + + /** + * Invoked by readAttributes or sub-classes to add all matching basic + * attributes to the builder + */ + final void addBasicAttributesToBuilder(BasicFileAttributes attrs, + AttributesBuilder builder) + { + if (builder.match(SIZE_NAME)) + builder.add(SIZE_NAME, attrs.size()); + if (builder.match(CREATION_TIME_NAME)) + builder.add(CREATION_TIME_NAME, attrs.creationTime()); + if (builder.match(LAST_ACCESS_TIME_NAME)) + builder.add(LAST_ACCESS_TIME_NAME, attrs.lastAccessTime()); + if (builder.match(LAST_MODIFIED_TIME_NAME)) + builder.add(LAST_MODIFIED_TIME_NAME, attrs.lastModifiedTime()); + if (builder.match(RESOLUTION_NAME)) + builder.add(RESOLUTION_NAME, attrs.resolution()); + if (builder.match(FILE_KEY_NAME)) + builder.add(FILE_KEY_NAME, attrs.fileKey()); + if (builder.match(LINK_COUNT_NAME)) + builder.add(LINK_COUNT_NAME, attrs.linkCount()); + if (builder.match(IS_DIRECTORY_NAME)) + builder.add(IS_DIRECTORY_NAME, attrs.isDirectory()); + if (builder.match(IS_REGULAR_FILE_NAME)) + builder.add(IS_REGULAR_FILE_NAME, attrs.isRegularFile()); + if (builder.match(IS_SYMBOLIC_LINK_NAME)) + builder.add(IS_SYMBOLIC_LINK_NAME, attrs.isSymbolicLink()); + if (builder.match(IS_OTHER_NAME)) + builder.add(IS_OTHER_NAME, attrs.isOther()); + } + + @Override + public Map<String,?> readAttributes(String first, String[] rest) + throws IOException + { + AttributesBuilder builder = AttributesBuilder.create(first, rest); + addBasicAttributesToBuilder(readAttributes(), builder); + return builder.unmodifiableMap(); + } +} diff --git a/src/share/classes/sun/nio/fs/AbstractFileStoreSpaceAttributeView.java b/src/share/classes/sun/nio/fs/AbstractFileStoreSpaceAttributeView.java new file mode 100644 index 0000000000000000000000000000000000000000..73c8c2a0db1288bb9e72e3c6e7af534f3873b022 --- /dev/null +++ b/src/share/classes/sun/nio/fs/AbstractFileStoreSpaceAttributeView.java @@ -0,0 +1,119 @@ +/* + * Copyright 2008-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 sun.nio.fs; + +import java.nio.file.attribute.*; +import java.io.IOException; +import java.util.*; + +/** + * Base implementation of FileStoreSpaceAttributeView + */ + +abstract class AbstractFileStoreSpaceAttributeView + implements FileStoreSpaceAttributeView +{ + private static final String TOTAL_SPACE_NAME = "totalSpace"; + private static final String USABLE_SPACE_NAME = "usableSpace"; + private static final String UNALLOCATED_SPACE_NAME = "unallocatedSpace"; + + @Override + public final String name() { + return "space"; + } + + @Override + public final Object getAttribute(String attribute) throws IOException { + FileStoreSpaceAttributes attrs = readAttributes(); + if (attribute.equals(TOTAL_SPACE_NAME)) + return attrs.totalSpace(); + if (attribute.equals(USABLE_SPACE_NAME)) + return attrs.usableSpace(); + if (attribute.equals(UNALLOCATED_SPACE_NAME)) + return attrs.unallocatedSpace(); + return null; + } + + @Override + public final void setAttribute(String attribute, Object value) + throws IOException + { + if (attribute == null || value == null) + throw new NullPointerException(); + throw new UnsupportedOperationException(); + } + + @Override + public final Map<String,?> readAttributes(String first, String[] rest) + throws IOException + { + boolean total = false; + boolean usable = false; + boolean unallocated = false; + + if (first.equals(TOTAL_SPACE_NAME)) total = true; + else if (first.equals(USABLE_SPACE_NAME)) usable = true; + else if (first.equals(UNALLOCATED_SPACE_NAME)) unallocated = true; + else if (first.equals("*")) { + total = true; + usable = true; + unallocated = true; + } + + if (!total || !usable || !unallocated) { + for (String attribute: rest) { + if (attribute.equals("*")) { + total = true; + usable = true; + unallocated = true; + break; + } + if (attribute.equals(TOTAL_SPACE_NAME)) { + total = true; + continue; + } + if (attribute.equals(USABLE_SPACE_NAME)) { + usable = true; + continue; + } + if (attribute.equals(UNALLOCATED_SPACE_NAME)) { + unallocated = true; + continue; + } + } + } + + FileStoreSpaceAttributes attrs = readAttributes(); + Map<String,Object> result = new HashMap<String,Object>(2); + if (total) + result.put(TOTAL_SPACE_NAME, attrs.totalSpace()); + if (usable) + result.put(USABLE_SPACE_NAME, attrs.usableSpace()); + if (unallocated) + result.put(UNALLOCATED_SPACE_NAME, attrs.unallocatedSpace()); + return Collections.unmodifiableMap(result); + } +} diff --git a/src/share/classes/sun/nio/fs/AbstractFileTypeDetector.java b/src/share/classes/sun/nio/fs/AbstractFileTypeDetector.java new file mode 100644 index 0000000000000000000000000000000000000000..d8a391b80816b7186c813e242ec2d6c81e81c579 --- /dev/null +++ b/src/share/classes/sun/nio/fs/AbstractFileTypeDetector.java @@ -0,0 +1,69 @@ +/* + * Copyright 2008-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 sun.nio.fs; + +import java.nio.file.FileRef; +import java.nio.file.spi.FileTypeDetector; +import java.io.IOException; +import sun.nio.fs.MimeType; + +/** + * Base implementation of FileTypeDetector + */ + +public abstract class AbstractFileTypeDetector + extends FileTypeDetector +{ + protected AbstractFileTypeDetector() { + super(); + } + + /** + * Invokes the implProbeContentType method to guess the file's content type, + * and this validates that the content type's syntax is valid. + */ + @Override + public final String probeContentType(FileRef file) throws IOException { + if (file == null) + throw new NullPointerException("'file' is null"); + String result = implProbeContentType(file); + if (result != null) { + // check the content type + try { + MimeType.parse(result); + } catch (IllegalArgumentException ignore) { + result = null; + } + } + return result; + } + + /** + * Probes the given file to guess its content type. + */ + protected abstract String implProbeContentType(FileRef file) + throws IOException; +} diff --git a/src/share/classes/sun/nio/fs/AbstractPoller.java b/src/share/classes/sun/nio/fs/AbstractPoller.java new file mode 100644 index 0000000000000000000000000000000000000000..3ab8af8e13b3c3f62fe8524f5008401f5c59769c --- /dev/null +++ b/src/share/classes/sun/nio/fs/AbstractPoller.java @@ -0,0 +1,290 @@ +/* + * Copyright 2008-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 sun.nio.fs; + +import java.nio.file.*; +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.io.IOException; +import java.util.*; + +/** + * Base implementation of background poller thread used in watch service + * implementations. A poller thread waits on events from the file system and + * also services "requests" from clients to register for new events or cancel + * existing registrations. + */ + +abstract class AbstractPoller implements Runnable { + + // list of requests pending to the poller thread + private final LinkedList<Request> requestList; + + // set to true when shutdown + private boolean shutdown; + + protected AbstractPoller() { + this.requestList = new LinkedList<Request>(); + this.shutdown = false; + } + + /** + * Starts the poller thread + */ + public void start() { + final Runnable thisRunnable = this; + AccessController.doPrivileged(new PrivilegedAction<Object>() { + @Override + public Object run() { + Thread thr = new Thread(thisRunnable); + thr.setDaemon(true); + thr.start(); + return null; + } + }); + } + + /** + * Wakeup poller thread so that it can service pending requests + */ + abstract void wakeup() throws IOException; + + /** + * Executed by poller thread to register directory for changes + */ + abstract Object implRegister(Path path, + Set<? extends WatchEvent.Kind<?>> events, + WatchEvent.Modifier... modifiers); + + /** + * Executed by poller thread to cancel key + */ + abstract void implCancelKey(WatchKey key); + + /** + * Executed by poller thread to shutdown and cancel all keys + */ + abstract void implCloseAll(); + + /** + * Requests, and waits on, poller thread to register given file. + */ + final WatchKey register(FileRef dir, + WatchEvent.Kind<?>[] events, + WatchEvent.Modifier... modifiers) + throws IOException + { + // validate arguments before request to poller + if (dir == null) + throw new NullPointerException(); + if (events.length == 0) + throw new IllegalArgumentException("No events to register"); + Set<WatchEvent.Kind<?>> eventSet = new HashSet<WatchEvent.Kind<?>>(events.length); + for (WatchEvent.Kind<?> event: events) { + // standard events + if (event == StandardWatchEventKind.ENTRY_CREATE || + event == StandardWatchEventKind.ENTRY_MODIFY || + event == StandardWatchEventKind.ENTRY_DELETE) + { + eventSet.add(event); + continue; + } + + // OVERFLOW is ignored + if (event == StandardWatchEventKind.OVERFLOW) { + if (events.length == 1) + throw new IllegalArgumentException("No events to register"); + continue; + } + + // null/unsupported + if (event == null) + throw new NullPointerException("An element in event set is 'null'"); + throw new UnsupportedOperationException(event.name()); + } + return (WatchKey)invoke(RequestType.REGISTER, dir, eventSet, modifiers); + } + + /** + * Cancels, and waits on, poller thread to cancel given key. + */ + final void cancel(WatchKey key) { + try { + invoke(RequestType.CANCEL, key); + } catch (IOException x) { + // should not happen + throw new AssertionError(x.getMessage()); + } + } + + /** + * Shutdown poller thread + */ + final void close() throws IOException { + invoke(RequestType.CLOSE); + } + + /** + * Types of request that the poller thread must handle + */ + private static enum RequestType { + REGISTER, + CANCEL, + CLOSE; + } + + /** + * Encapsulates a request (command) to the poller thread. + */ + private static class Request { + private final RequestType type; + private final Object[] params; + + private boolean completed = false; + private Object result = null; + + Request(RequestType type, Object... params) { + this.type = type; + this.params = params; + } + + RequestType type() { + return type; + } + + Object[] parameters() { + return params; + } + + void release(Object result) { + synchronized (this) { + this.completed = true; + this.result = result; + notifyAll(); + } + } + + /** + * Await completion of the request. The return value is the result of + * the request. + */ + Object awaitResult() { + synchronized (this) { + while (!completed) { + try { + wait(); + } catch (InterruptedException x) { + // ignore + } + } + return result; + } + } + } + + /** + * Enqueues request to poller thread and waits for result + */ + private Object invoke(RequestType type, Object... params) throws IOException { + // submit request + Request req = new Request(type, params); + synchronized (requestList) { + if (shutdown) { + throw new ClosedWatchServiceException(); + } + requestList.add(req); + } + + // wakeup thread + wakeup(); + + // wait for result + Object result = req.awaitResult(); + + if (result instanceof RuntimeException) + throw (RuntimeException)result; + if (result instanceof IOException ) + throw (IOException)result; + return result; + } + + /** + * Invoked by poller thread to process all pending requests + * + * @return true if poller thread should shutdown + */ + @SuppressWarnings("unchecked") + boolean processRequests() { + synchronized (requestList) { + Request req; + while ((req = requestList.poll()) != null) { + // if in process of shutdown then reject request + if (shutdown) { + req.release(new ClosedWatchServiceException()); + } + + switch (req.type()) { + /** + * Register directory + */ + case REGISTER: { + Object[] params = req.parameters(); + Path path = (Path)params[0]; + Set<? extends WatchEvent.Kind<?>> events = + (Set<? extends WatchEvent.Kind<?>>)params[1]; + WatchEvent.Modifier[] modifiers = + (WatchEvent.Modifier[])params[2]; + req.release(implRegister(path, events, modifiers)); + break; + } + /** + * Cancel existing key + */ + case CANCEL : { + Object[] params = req.parameters(); + WatchKey key = (WatchKey)params[0]; + implCancelKey(key); + req.release(null); + break; + } + /** + * Close watch service + */ + case CLOSE: { + implCloseAll(); + req.release(null); + shutdown = true; + break; + } + + default: + req.release(new IOException("request not recognized")); + } + } + } + return shutdown; + } +} diff --git a/src/share/classes/sun/nio/fs/AbstractUserDefinedFileAttributeView.java b/src/share/classes/sun/nio/fs/AbstractUserDefinedFileAttributeView.java new file mode 100644 index 0000000000000000000000000000000000000000..3ac9b507fc06042352bfa948e12a96aac1f0a123 --- /dev/null +++ b/src/share/classes/sun/nio/fs/AbstractUserDefinedFileAttributeView.java @@ -0,0 +1,124 @@ +/* + * Copyright 2008-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 sun.nio.fs; + +import java.nio.ByteBuffer; +import java.nio.file.attribute.UserDefinedFileAttributeView; +import java.io.IOException; +import java.util.*; + +/** + * Base implementation of NamedAttributeView + */ + +abstract class AbstractUserDefinedFileAttributeView + implements UserDefinedFileAttributeView +{ + protected AbstractUserDefinedFileAttributeView() { } + + protected void checkAccess(String file, + boolean checkRead, + boolean checkWrite) + { + assert checkRead || checkWrite; + SecurityManager sm = System.getSecurityManager(); + if (sm != null) { + if (checkRead) + sm.checkRead(file); + if (checkWrite) + sm.checkWrite(file); + sm.checkPermission(new RuntimePermission("accessUserDefinedAttributes")); + } + } + + @Override + public final String name() { + return "xattr"; + } + + @Override + public final Object getAttribute(String attribute) throws IOException { + int size; + try { + size = size(attribute); + } catch (IOException e) { + // not found or some other I/O error + if (list().contains(attribute)) + throw e; + return null; + } + byte[] buf = new byte[size]; + int n = read(attribute, ByteBuffer.wrap(buf)); + return (n == size) ? buf : Arrays.copyOf(buf, n); + } + + @Override + public final void setAttribute(String attribute, Object value) + throws IOException + { + ByteBuffer bb; + if (value instanceof byte[]) { + bb = ByteBuffer.wrap((byte[])value); + } else { + bb = (ByteBuffer)value; + } + write(attribute, bb); + } + + @Override + public final Map<String,?> readAttributes(String first, String... rest) + throws IOException + { + // names of attributes to return + List<String> names = new ArrayList<String>(); + + boolean readAll = false; + if (first.equals("*")) { + readAll = true; + } else { + names.add(first); + } + for (String name: rest) { + if (name.equals("*")) { + readAll = true; + } else { + names.add(name); + } + } + if (readAll) + names = list(); + + // read each value and return in map + Map<String,Object> result = new HashMap<String,Object>(); + for (String name: names) { + Object value = getAttribute(name); + if (value != null) + result.put(name, value); + } + + return result; + } +} diff --git a/src/share/classes/sun/nio/fs/AbstractWatchKey.java b/src/share/classes/sun/nio/fs/AbstractWatchKey.java new file mode 100644 index 0000000000000000000000000000000000000000..8e33f81ed8431c38fce563d0771b59580bb6716f --- /dev/null +++ b/src/share/classes/sun/nio/fs/AbstractWatchKey.java @@ -0,0 +1,180 @@ +/* + * Copyright 2008-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 sun.nio.fs; + +import java.nio.file.*; +import java.util.*; + +/** + * Base implementation class for watch keys. + */ + +abstract class AbstractWatchKey extends WatchKey { + + /** + * Maximum size of event list (in the future this may be tunable) + */ + static final int MAX_EVENT_LIST_SIZE = 512; + + /** + * Special event to signal overflow + */ + static final Event<Void> OVERFLOW_EVENT = + new Event<Void>(StandardWatchEventKind.OVERFLOW, null); + + /** + * Possible key states + */ + private static enum State { READY, SIGNALLED }; + + // reference to watcher + private final AbstractWatchService watcher; + + // key state + private State state; + + // pending events + private List<WatchEvent<?>> events; + + protected AbstractWatchKey(AbstractWatchService watcher) { + this.watcher = watcher; + this.state = State.READY; + this.events = new ArrayList<WatchEvent<?>>(); + } + + final AbstractWatchService watcher() { + return watcher; + } + + /** + * Enqueues this key to the watch service + */ + final void signal() { + synchronized (this) { + if (state == State.READY) { + state = State.SIGNALLED; + watcher.enqueueKey(this); + } + } + } + + /** + * Adds the event to this key and signals it. + */ + @SuppressWarnings("unchecked") + final void signalEvent(WatchEvent.Kind<?> kind, Object context) { + synchronized (this) { + int size = events.size(); + if (size > 1) { + // don't let list get too big + if (size >= MAX_EVENT_LIST_SIZE) { + kind = StandardWatchEventKind.OVERFLOW; + context = null; + } + + // repeated event + WatchEvent<?> prev = events.get(size-1); + if (kind == prev.kind()) { + boolean isRepeat; + if (context == null) { + isRepeat = (prev.context() == null); + } else { + isRepeat = context.equals(prev.context()); + } + if (isRepeat) { + ((Event<?>)prev).increment(); + return; + } + } + } + + // non-repeated event + events.add(new Event<Object>((WatchEvent.Kind<Object>)kind, context)); + signal(); + } + } + + @Override + public final List<WatchEvent<?>> pollEvents() { + synchronized (this) { + List<WatchEvent<?>> result = events; + events = new ArrayList<WatchEvent<?>>(); + return result; + } + } + + @Override + public final boolean reset() { + synchronized (this) { + if (state == State.SIGNALLED && isValid()) { + if (events.isEmpty()) { + state = State.READY; + } else { + // pending events so re-queue key + watcher.enqueueKey(this); + } + } + return isValid(); + } + } + + /** + * WatchEvent implementation + */ + private static class Event<T> extends WatchEvent<T> { + private final WatchEvent.Kind<T> kind; + private final T context; + + // synchronize on watch key to access/increment count + private int count; + + Event(WatchEvent.Kind<T> type, T context) { + this.kind = type; + this.context = context; + this.count = 1; + } + + @Override + public WatchEvent.Kind<T> kind() { + return kind; + } + + @Override + public T context() { + return context; + } + + @Override + public int count() { + return count; + } + + // for repeated events + void increment() { + count++; + } + } +} diff --git a/src/share/classes/sun/nio/fs/AbstractWatchService.java b/src/share/classes/sun/nio/fs/AbstractWatchService.java new file mode 100644 index 0000000000000000000000000000000000000000..c29d78b59d2b044c92c9fa283beedfbc5b51af83 --- /dev/null +++ b/src/share/classes/sun/nio/fs/AbstractWatchService.java @@ -0,0 +1,161 @@ +/* + * Copyright 2008-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 sun.nio.fs; + +import java.nio.file.*; +import java.util.concurrent.*; +import java.io.IOException; + +/** + * Base implementation class for watch services. + */ + +abstract class AbstractWatchService extends WatchService { + + // signaled keys waiting to be dequeued + private final LinkedBlockingDeque<WatchKey> pendingKeys = + new LinkedBlockingDeque<WatchKey>(); + + // special key to indicate that watch service is closed + private final WatchKey CLOSE_KEY = + new AbstractWatchKey(null) { + @Override + public boolean isValid() { + return true; + } + + @Override + public void cancel() { + } + }; + + // used when closing watch service + private volatile boolean closed; + private Object closeLock = new Object(); + + protected AbstractWatchService() { + } + + /** + * Register the given object with this watch service + */ + abstract WatchKey register(Path path, + WatchEvent.Kind<?>[] events, + WatchEvent.Modifier... modifers) + throws IOException; + + // used by AbstractWatchKey to enqueue key + final void enqueueKey(WatchKey key) { + pendingKeys.offer(key); + } + + /** + * Throws ClosedWatchServiceException if watch service is closed + */ + private void checkOpen() { + if (closed) + throw new ClosedWatchServiceException(); + } + + /** + * Checks the key isn't the special CLOSE_KEY used to unblock threads when + * the watch service is closed. + */ + private void checkKey(WatchKey key) { + if (key == CLOSE_KEY) { + // re-queue in case there are other threads blocked in take/poll + enqueueKey(key); + } + checkOpen(); + } + + @Override + public final WatchKey poll() { + checkOpen(); + WatchKey key = pendingKeys.poll(); + checkKey(key); + return key; + } + + @Override + public final WatchKey poll(long timeout, TimeUnit unit) + throws InterruptedException + { + checkOpen(); + WatchKey key = pendingKeys.poll(timeout, unit); + checkKey(key); + return key; + } + + @Override + public final WatchKey take() + throws InterruptedException + { + checkOpen(); + WatchKey key = pendingKeys.take(); + checkKey(key); + return key; + } + + /** + * Tells whether or not this watch service is open. + */ + final boolean isOpen() { + return !closed; + } + + /** + * Retrieves the object upon which the close method synchronizes. + */ + final Object closeLock() { + return closeLock; + } + + /** + * Closes this watch service. This method is invoked by the close + * method to perform the actual work of closing the watch service. + */ + abstract void implClose() throws IOException; + + @Override + public final void close() + throws IOException + { + synchronized (closeLock) { + // nothing to do if already closed + if (closed) + return; + closed = true; + + implClose(); + + // clear pending keys and queue special key to ensure that any + // threads blocked in take/poll wakeup + pendingKeys.clear(); + pendingKeys.offer(CLOSE_KEY); + } + } +} diff --git a/src/share/classes/sun/nio/fs/BasicFileAttributesHolder.java b/src/share/classes/sun/nio/fs/BasicFileAttributesHolder.java new file mode 100644 index 0000000000000000000000000000000000000000..28f8691ec737899ab2e62ff4c44ec25b4e0dcce2 --- /dev/null +++ b/src/share/classes/sun/nio/fs/BasicFileAttributesHolder.java @@ -0,0 +1,46 @@ +/* + * Copyright 2008-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 sun.nio.fs; + +import java.nio.file.attribute.BasicFileAttributes; + +/** + * Implemented by objects that may hold or cache the attributes of a file. + */ + +public interface BasicFileAttributesHolder { + /** + * Returns cached attributes (may be null). If file is a symbolic link then + * the attributes are the link attributes and not the final target of the + * file. + */ + BasicFileAttributes get(); + + /** + * Invalidates cached attributes + */ + void invalidate(); +} diff --git a/src/share/classes/sun/nio/fs/Cancellable.java b/src/share/classes/sun/nio/fs/Cancellable.java new file mode 100644 index 0000000000000000000000000000000000000000..3b40ddd1017cb7675920169d1917b233a23d8ee3 --- /dev/null +++ b/src/share/classes/sun/nio/fs/Cancellable.java @@ -0,0 +1,137 @@ +/* + * Copyright 2008-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 sun.nio.fs; + +import sun.misc.Unsafe; +import java.util.concurrent.ExecutionException; + +/** + * Base implementation of a task (typically native) that polls a memory location + * during execution so that it may be aborted/cancelled before completion. The + * task is executed by invoking the {@link runInterruptibly} method defined + * here and cancelled by invoking Thread.interrupt. + */ + +abstract class Cancellable implements Runnable { + private static final Unsafe unsafe = Unsafe.getUnsafe(); + + private final long pollingAddress; + private final Object lock = new Object(); + + // the following require lock when examining or changing + private boolean completed; + private Throwable exception; + + protected Cancellable() { + pollingAddress = unsafe.allocateMemory(4); + unsafe.putIntVolatile(null, pollingAddress, 0); + } + + /** + * Returns the memory address of a 4-byte int that should be polled to + * detect cancellation. + */ + protected long addressToPollForCancel() { + return pollingAddress; + } + + /** + * The value to write to the polled memory location to indicate that the + * task has been cancelled. If this method is not overridden then it + * defaults to MAX_VALUE. + */ + protected int cancelValue() { + return Integer.MAX_VALUE; + } + + /** + * "cancels" the task by writing bits into memory location that it polled + * by the task. + */ + final void cancel() { + synchronized (lock) { + if (!completed) { + unsafe.putIntVolatile(null, pollingAddress, cancelValue()); + } + } + } + + /** + * Returns the exception thrown by the task or null if the task completed + * successfully. + */ + private Throwable exception() { + synchronized (lock) { + return exception; + } + } + + @Override + public final void run() { + try { + implRun(); + } catch (Throwable t) { + synchronized (lock) { + exception = t; + } + } finally { + synchronized (lock) { + completed = true; + unsafe.freeMemory(pollingAddress); + } + } + } + + /** + * The task body. This should periodically poll the memory location + * to check for cancellation. + */ + abstract void implRun() throws Throwable; + + /** + * Invokes the given task in its own thread. If this (meaning the current) + * thread is interrupted then an attempt is make to cancel the background + * thread by writing into the memory location that it polls cooperatively. + */ + static void runInterruptibly(Cancellable task) throws ExecutionException { + Thread t = new Thread(task); + t.start(); + boolean cancelledByInterrupt = false; + while (t.isAlive()) { + try { + t.join(); + } catch (InterruptedException e) { + cancelledByInterrupt = true; + task.cancel(); + } + } + if (cancelledByInterrupt) + Thread.currentThread().interrupt(); + Throwable exc = task.exception(); + if (exc != null) + throw new ExecutionException(exc); + } +} diff --git a/src/share/classes/sun/nio/fs/FileOwnerAttributeViewImpl.java b/src/share/classes/sun/nio/fs/FileOwnerAttributeViewImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..f40c2a797403af727cb533461a6104ea79ed2e07 --- /dev/null +++ b/src/share/classes/sun/nio/fs/FileOwnerAttributeViewImpl.java @@ -0,0 +1,111 @@ +/* + * Copyright 2008-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 sun.nio.fs; + +import java.nio.file.attribute.*; +import java.util.*; +import java.io.IOException; + +/** + * An implementation of FileOwnerAttributeView that delegates to a given + * PosixFileAttributeView or AclFileAttributeView object. + */ + +final class FileOwnerAttributeViewImpl implements FileOwnerAttributeView { + private static final String OWNER_NAME = "owner"; + + private final FileAttributeView view; + private final boolean isPosixView; + + FileOwnerAttributeViewImpl(PosixFileAttributeView view) { + this.view = view; + this.isPosixView = true; + } + + FileOwnerAttributeViewImpl(AclFileAttributeView view) { + this.view = view; + this.isPosixView = false; + } + + @Override + public String name() { + return "owner"; + } + + @Override + public Object getAttribute(String attribute) throws IOException { + if (attribute.equals(OWNER_NAME)) + return getOwner(); + return null; + } + + @Override + public void setAttribute(String attribute, Object value) + throws IOException + { + if (attribute.equals(OWNER_NAME)) { + setOwner((UserPrincipal)value); + return; + } + throw new UnsupportedOperationException(); + } + + @Override + public Map<String,?> readAttributes(String first, String[] rest) throws IOException { + Map<String,Object> result = new HashMap<String,Object>(); + if (first.equals("*") || first.equals(OWNER_NAME)) { + result.put(OWNER_NAME, getOwner()); + } else { + for (String attribute: rest) { + if (attribute.equals("*") || attribute.equals(OWNER_NAME)) { + result.put(OWNER_NAME, getOwner()); + break; + } + } + } + return result; + } + + @Override + public UserPrincipal getOwner() throws IOException { + if (isPosixView) { + return ((PosixFileAttributeView)view).readAttributes().owner(); + } else { + return ((AclFileAttributeView)view).getOwner(); + } + } + + @Override + public void setOwner(UserPrincipal owner) + throws IOException + { + if (isPosixView) { + ((PosixFileAttributeView)view).setOwner(owner); + } else { + ((AclFileAttributeView)view).setOwner(owner); + } + } + } diff --git a/src/share/classes/sun/nio/fs/Globs.java b/src/share/classes/sun/nio/fs/Globs.java new file mode 100644 index 0000000000000000000000000000000000000000..33857ea0cdf1bb007a335aa75e6871e5ddf532e2 --- /dev/null +++ b/src/share/classes/sun/nio/fs/Globs.java @@ -0,0 +1,217 @@ +/* + * Copyright 2008-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 sun.nio.fs; + +import java.util.regex.PatternSyntaxException; + +public class Globs { + private Globs() { } + + private static final String regexMetaChars = ".^$+{[]|()"; + private static final String globMetaChars = "\\*?[{"; + + private static boolean isRegexMeta(char c) { + return regexMetaChars.indexOf(c) != -1; + } + + private static boolean isGlobMeta(char c) { + return globMetaChars.indexOf(c) != -1; + } + private static char EOL = 0; //TBD + + private static char next(String glob, int i) { + if (i < glob.length()) { + return glob.charAt(i); + } + return EOL; + } + + /** + * Creates a regex pattern from the given glob expression. + * + * @throws PatternSyntaxException + */ + private static String toRegexPattern(String globPattern, boolean isDos) { + boolean inGroup = false; + StringBuilder regex = new StringBuilder("^"); + + int i = 0; + while (i < globPattern.length()) { + char c = globPattern.charAt(i++); + switch (c) { + case '\\': + // escape special characters + if (i == globPattern.length()) { + throw new PatternSyntaxException("No character to escape", + globPattern, i - 1); + } + char next = globPattern.charAt(i++); + if (isGlobMeta(next) || isRegexMeta(next)) { + regex.append('\\'); + } + regex.append(next); + break; + case '/': + if (isDos) { + regex.append("\\\\"); + } else { + regex.append(c); + } + break; + case '[': + // don't match name separator in class + if (isDos) { + regex.append("[[^\\\\]&&["); + } else { + regex.append("[[^/]&&["); + } + if (next(globPattern, i) == '^') { + // escape the regex negation char if it appears + regex.append("\\^"); + i++; + } else { + // negation + if (next(globPattern, i) == '!') { + regex.append('^'); + i++; + } + // hyphen allowed at start + if (next(globPattern, i) == '-') { + regex.append('-'); + i++; + } + } + boolean hasRangeStart = false; + char last = 0; + while (i < globPattern.length()) { + c = globPattern.charAt(i++); + if (c == ']') { + break; + } + if (c == '/' || (isDos && c == '\\')) { + throw new PatternSyntaxException("Explicit 'name separator' in class", + globPattern, i - 1); + } + // TBD: how to specify ']' in a class? + if (c == '\\' || c == '[' || + c == '&' && next(globPattern, i) == '&') { + // escape '\', '[' or "&&" for regex class + regex.append('\\'); + } + regex.append(c); + + if (c == '-') { + if (!hasRangeStart) { + throw new PatternSyntaxException("Invalid range", + globPattern, i - 1); + } + if ((c = next(globPattern, i++)) == EOL || c == ']') { + break; + } + if (c < last) { + throw new PatternSyntaxException("Invalid range", + globPattern, i - 3); + } + regex.append(c); + hasRangeStart = false; + } else { + hasRangeStart = true; + last = c; + } + } + if (c != ']') { + throw new PatternSyntaxException("Missing ']", globPattern, i - 1); + } + regex.append("]]"); + break; + case '{': + if (inGroup) { + throw new PatternSyntaxException("Cannot nest groups", + globPattern, i - 1); + } + regex.append("(?:(?:"); + inGroup = true; + break; + case '}': + if (inGroup) { + regex.append("))"); + inGroup = false; + } else { + regex.append('}'); + } + break; + case ',': + if (inGroup) { + regex.append(")|(?:"); + } else { + regex.append(','); + } + break; + case '*': + if (next(globPattern, i) == '*') { + // crosses directory boundaries + regex.append(".*"); + i++; + } else { + // within directory boundary + if (isDos) { + regex.append("[^\\\\]*"); + } else { + regex.append("[^/]*"); + } + } + break; + case '?': + if (isDos) { + regex.append("[^\\\\]"); + } else { + regex.append("[^/]"); + } + break; + + default: + if (isRegexMeta(c)) { + regex.append('\\'); + } + regex.append(c); + } + } + + if (inGroup) { + throw new PatternSyntaxException("Missing '}", globPattern, i - 1); + } + + return regex.append('$').toString(); + } + + static String toUnixRegexPattern(String globPattern) { + return toRegexPattern(globPattern, false); + } + + static String toWindowsRegexPattern(String globPattern) { + return toRegexPattern(globPattern, true); + } +} diff --git a/src/share/classes/sun/nio/fs/MimeType.java b/src/share/classes/sun/nio/fs/MimeType.java new file mode 100644 index 0000000000000000000000000000000000000000..053ea44c205c905ac08ca52dae4c274abb448649 --- /dev/null +++ b/src/share/classes/sun/nio/fs/MimeType.java @@ -0,0 +1,73 @@ +/* + * Copyright 2008-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 sun.nio.fs; + +/** + * Represents a MIME type for the purposes of validation and matching. For + * now this class is implemented using the javax.activation.MimeType class but + * this dependency can easily be eliminated when required. + */ + +public class MimeType { + private final javax.activation.MimeType type; + + private MimeType(javax.activation.MimeType type) { + this.type = type; + } + + /** + * Parses the given string as a MIME type. + * + * @throws IllegalArgumentException + * If the string is not a valid MIME type + */ + public static MimeType parse(String type) { + try { + return new MimeType(new javax.activation.MimeType(type)); + } catch (javax.activation.MimeTypeParseException x) { + throw new IllegalArgumentException(x); + } + } + + /** + * Returns {@code true} if this MIME type has parameters. + */ + public boolean hasParameters() { + return !type.getParameters().isEmpty(); + } + + /** + * Matches this MIME type against a given MIME type. This method returns + * true if the given string is a MIME type and it matches this type. + */ + public boolean match(String other) { + try { + return type.match(other); + } catch (javax.activation.MimeTypeParseException x) { + return false; + } + } +} diff --git a/src/share/classes/sun/nio/fs/NativeBuffer.java b/src/share/classes/sun/nio/fs/NativeBuffer.java new file mode 100644 index 0000000000000000000000000000000000000000..975c1c20b2c05b399ddcc667f25df3091e99094e --- /dev/null +++ b/src/share/classes/sun/nio/fs/NativeBuffer.java @@ -0,0 +1,87 @@ +/* + * Copyright 2008-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 sun.nio.fs; + +import sun.misc.Unsafe; +import sun.misc.Cleaner; + +/** + * A light-weight buffer in native memory. + */ + +class NativeBuffer { + private static final Unsafe unsafe = Unsafe.getUnsafe(); + + private final long address; + private final int size; + private final Cleaner cleaner; + + // optional "owner" to avoid copying + // (only safe for use by thread-local caches) + private Object owner; + + private static class Deallocator implements Runnable { + private final long address; + Deallocator(long address) { + this.address = address; + } + public void run() { + unsafe.freeMemory(address); + } + } + + NativeBuffer(int size) { + this.address = unsafe.allocateMemory(size); + this.size = size; + this.cleaner = Cleaner.create(this, new Deallocator(address)); + } + + void release() { + NativeBuffers.releaseNativeBuffer(this); + } + + long address() { + return address; + } + + int size() { + return size; + } + + Cleaner cleaner() { + return cleaner; + } + + // not synchronized; only safe for use by thread-local caches + void setOwner(Object owner) { + this.owner = owner; + } + + // not synchronized; only safe for use by thread-local caches + Object owner() { + return owner; + } +} diff --git a/src/share/classes/sun/nio/fs/NativeBuffers.java b/src/share/classes/sun/nio/fs/NativeBuffers.java new file mode 100644 index 0000000000000000000000000000000000000000..fa247a6acc0788a1d43cac01bfda338b73db4336 --- /dev/null +++ b/src/share/classes/sun/nio/fs/NativeBuffers.java @@ -0,0 +1,140 @@ +/* + * Copyright 2008-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 sun.nio.fs; + +import sun.misc.Unsafe; + +/** + * Factory for native buffers. + */ + +class NativeBuffers { + private NativeBuffers() { } + + private static final Unsafe unsafe = Unsafe.getUnsafe(); + + private static final int TEMP_BUF_POOL_SIZE = 3; + private static ThreadLocal<NativeBuffer[]> threadLocal = + new ThreadLocal<NativeBuffer[]>(); + + /** + * Allocates a native buffer, of at least the given size, from the heap. + */ + static NativeBuffer allocNativeBuffer(int size) { + // Make a new one of at least 2k + if (size < 2048) size = 2048; + return new NativeBuffer(size); + } + + /** + * Returns a native buffer, of at least the given size, from the thread + * local cache. + */ + static NativeBuffer getNativeBufferFromCache(int size) { + // return from cache if possible + NativeBuffer[] buffers = threadLocal.get(); + if (buffers != null) { + for (int i=0; i<TEMP_BUF_POOL_SIZE; i++) { + NativeBuffer buffer = buffers[i]; + if (buffer != null && buffer.size() >= size) { + buffers[i] = null; + return buffer; + } + } + } + return null; + } + + /** + * Returns a native buffer, of at least the given size. The native buffer + * is taken from the thread local cache if possible; otherwise it is + * allocated from the heap. + */ + static NativeBuffer getNativeBuffer(int size) { + NativeBuffer buffer = getNativeBufferFromCache(size); + if (buffer != null) { + buffer.setOwner(null); + return buffer; + } else { + return allocNativeBuffer(size); + } + } + + /** + * Releases the given buffer. If there is space in the thread local cache + * then the buffer goes into the cache; otherwise the memory is deallocated. + */ + static void releaseNativeBuffer(NativeBuffer buffer) { + // create cache if it doesn't exist + NativeBuffer[] buffers = threadLocal.get(); + if (buffers == null) { + buffers = new NativeBuffer[TEMP_BUF_POOL_SIZE]; + buffers[0] = buffer; + threadLocal.set(buffers); + return; + } + // Put it in an empty slot if such exists + for (int i=0; i<TEMP_BUF_POOL_SIZE; i++) { + if (buffers[i] == null) { + buffers[i] = buffer; + return; + } + } + // Otherwise replace a smaller one in the cache if such exists + for (int i=0; i<TEMP_BUF_POOL_SIZE; i++) { + NativeBuffer existing = buffers[i]; + if (existing.size() < buffer.size()) { + existing.cleaner().clean(); + buffers[i] = buffer; + return; + } + } + + // free it + buffer.cleaner().clean(); + } + + /** + * Copies a byte array and zero terminator into a given native buffer. + */ + static void copyCStringToNativeBuffer(byte[] cstr, NativeBuffer buffer) { + long offset = Unsafe.ARRAY_BYTE_BASE_OFFSET; + long len = cstr.length; + assert buffer.size() >= (len + 1); + unsafe.copyMemory(cstr, offset, null, buffer.address(), len); + unsafe.putByte(buffer.address() + len, (byte)0); + } + + /** + * Copies a byte array and zero terminator into a native buffer, returning + * the buffer. + */ + static NativeBuffer asNativeBuffer(byte[] cstr) { + NativeBuffer buffer = getNativeBuffer(cstr.length+1); + copyCStringToNativeBuffer(cstr, buffer); + return buffer; + } +} diff --git a/src/share/classes/sun/nio/fs/PollingWatchService.java b/src/share/classes/sun/nio/fs/PollingWatchService.java new file mode 100644 index 0000000000000000000000000000000000000000..73a89c27136ed599cae2ee0737d2c2fccd8dcad4 --- /dev/null +++ b/src/share/classes/sun/nio/fs/PollingWatchService.java @@ -0,0 +1,429 @@ +/* + * Copyright 2008-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 sun.nio.fs; + +import java.nio.file.*; +import java.nio.file.attribute.*; +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.security.PrivilegedExceptionAction; +import java.security.PrivilegedActionException; +import java.io.IOException; +import java.util.*; +import java.util.concurrent.*; +import com.sun.nio.file.SensitivityWatchEventModifier; + +/** + * Simple WatchService implementation that uses periodic tasks to poll + * registered directories for changes. This implementation is for use on + * operating systems that do not have native file change notification support. + */ + +class PollingWatchService + extends AbstractWatchService +{ + // map of registrations + private final Map<Object,PollingWatchKey> map = + new HashMap<Object,PollingWatchKey>(); + + // used to execute the periodic tasks that poll for changes + private final ScheduledExecutorService scheduledExecutor; + + PollingWatchService() { + // TBD: Make the number of threads configurable + scheduledExecutor = Executors + .newSingleThreadScheduledExecutor(new ThreadFactory() { + @Override + public Thread newThread(Runnable r) { + Thread t = new Thread(r); + t.setDaemon(true); + return t; + }}); + } + + /** + * Register the given file with this watch service + */ + @Override + WatchKey register(final Path path, + WatchEvent.Kind<?>[] events, + WatchEvent.Modifier... modifiers) + throws IOException + { + // check events - CCE will be thrown if there are invalid elements + if (events.length == 0) + throw new IllegalArgumentException("No events to register"); + final Set<WatchEvent.Kind<?>> eventSet = + new HashSet<WatchEvent.Kind<?>>(events.length); + for (WatchEvent.Kind<?> event: events) { + // standard events + if (event == StandardWatchEventKind.ENTRY_CREATE || + event == StandardWatchEventKind.ENTRY_MODIFY || + event == StandardWatchEventKind.ENTRY_DELETE) + { + eventSet.add(event); + continue; + } + + // OVERFLOW is ignored + if (event == StandardWatchEventKind.OVERFLOW) { + if (events.length == 1) + throw new IllegalArgumentException("No events to register"); + continue; + } + + // null/unsupported + if (event == null) + throw new NullPointerException("An element in event set is 'null'"); + throw new UnsupportedOperationException(event.name()); + } + + // A modifier may be used to specify the sensitivity level + SensitivityWatchEventModifier sensivity = SensitivityWatchEventModifier.MEDIUM; + if (modifiers.length > 0) { + for (WatchEvent.Modifier modifier: modifiers) { + if (modifier == null) + throw new NullPointerException(); + if (modifier instanceof SensitivityWatchEventModifier) { + sensivity = (SensitivityWatchEventModifier)modifier; + continue; + } + throw new UnsupportedOperationException("Modifier not supported"); + } + } + + // check if watch service is closed + if (!isOpen()) + throw new ClosedWatchServiceException(); + + // registration is done in privileged block as it requires the + // attributes of the entries in the directory. + try { + final SensitivityWatchEventModifier s = sensivity; + return AccessController.doPrivileged( + new PrivilegedExceptionAction<PollingWatchKey>() { + @Override + public PollingWatchKey run() throws IOException { + return doPrivilegedRegister(path, eventSet, s); + } + }); + } catch (PrivilegedActionException pae) { + Throwable cause = pae.getCause(); + if (cause != null && cause instanceof IOException) + throw (IOException)cause; + throw new AssertionError(pae); + } + } + + // registers directory returning a new key if not already registered or + // existing key if already registered + private PollingWatchKey doPrivilegedRegister(Path path, + Set<? extends WatchEvent.Kind<?>> events, + SensitivityWatchEventModifier sensivity) + throws IOException + { + // check file is a directory and get its file key if possible + BasicFileAttributes attrs = Attributes.readBasicFileAttributes(path); + if (!attrs.isDirectory()) { + throw new NotDirectoryException(path.toString()); + } + Object fileKey = attrs.fileKey(); + if (fileKey == null) + throw new AssertionError("File keys must be supported"); + + // grab close lock to ensure that watch service cannot be closed + synchronized (closeLock()) { + if (!isOpen()) + throw new ClosedWatchServiceException(); + + PollingWatchKey watchKey; + synchronized (map) { + watchKey = map.get(fileKey); + if (watchKey == null) { + // new registration + watchKey = new PollingWatchKey(this, path, fileKey); + map.put(fileKey, watchKey); + } else { + // update to existing registration + watchKey.disable(); + } + } + watchKey.enable(events, sensivity.sensitivityValueInSeconds()); + return watchKey; + } + + } + + @Override + void implClose() throws IOException { + synchronized (map) { + for (Map.Entry<Object,PollingWatchKey> entry: map.entrySet()) { + PollingWatchKey watchKey = entry.getValue(); + watchKey.disable(); + watchKey.invalidate(); + } + map.clear(); + } + AccessController.doPrivileged(new PrivilegedAction<Void>() { + @Override + public Void run() { + scheduledExecutor.shutdown(); + return null; + } + }); + } + + /** + * Entry in directory cache to record file last-modified-time and tick-count + */ + private static class CacheEntry { + private long lastModified; + private int lastTickCount; + + CacheEntry(long lastModified, int lastTickCount) { + this.lastModified = lastModified; + this.lastTickCount = lastTickCount; + } + + int lastTickCount() { + return lastTickCount; + } + + long lastModified() { + return lastModified; + } + + void update(long lastModified, int tickCount) { + this.lastModified = lastModified; + this.lastTickCount = tickCount; + } + } + + /** + * WatchKey implementation that encapsulates a map of the entries of the + * entries in the directory. Polling the key causes it to re-scan the + * directory and queue keys when entries are added, modified, or deleted. + */ + private class PollingWatchKey extends AbstractWatchKey { + private final Path dir; + private final Object fileKey; + + // current event set + private Set<? extends WatchEvent.Kind<?>> events; + + // the result of the periodic task that causes this key to be polled + private ScheduledFuture<?> poller; + + // indicates if the key is valid + private volatile boolean valid; + + // used to detect files that have been deleted + private int tickCount; + + // map of entries in directory + private Map<Path,CacheEntry> entries; + + PollingWatchKey(PollingWatchService watcher, + Path dir, + Object fileKey) + throws IOException + { + super(watcher); + this.dir = dir; + this.fileKey = fileKey; + this.valid = true; + this.tickCount = 0; + this.entries = new HashMap<Path,CacheEntry>(); + + // get the initial entries in the directory + DirectoryStream<Path> stream = dir.newDirectoryStream(); + try { + for (Path entry: stream) { + // don't follow links + long lastModified = Attributes + .readBasicFileAttributes(entry, LinkOption.NOFOLLOW_LINKS) + .lastModifiedTime(); + entries.put(entry.getName(), + new CacheEntry(lastModified, tickCount)); + } + } catch (ConcurrentModificationException cme) { + // thrown if directory iteration fails + Throwable cause = cme.getCause(); + if (cause != null && cause instanceof IOException) + throw (IOException)cause; + throw new AssertionError(cme); + } finally { + stream.close(); + } + } + + FileRef directory() { + return dir; + } + + Object fileKey() { + return fileKey; + } + + @Override + public boolean isValid() { + return valid; + } + + void invalidate() { + valid = false; + } + + // enables periodic polling + void enable(Set<? extends WatchEvent.Kind<?>> events, long period) { + synchronized (this) { + // update the events + this.events = events; + + // create the periodic task + Runnable thunk = new Runnable() { public void run() { poll(); }}; + this.poller = scheduledExecutor + .scheduleAtFixedRate(thunk, period, period, TimeUnit.SECONDS); + } + } + + // disables periodic polling + void disable() { + synchronized (this) { + if (poller != null) + poller.cancel(false); + } + } + + @Override + public void cancel() { + valid = false; + synchronized (map) { + map.remove(fileKey()); + } + disable(); + } + + /** + * Polls the directory to detect for new files, modified files, or + * deleted files. + */ + synchronized void poll() { + if (!valid) { + return; + } + + // update tick + tickCount++; + + // open directory + DirectoryStream<Path> stream = null; + try { + stream = dir.newDirectoryStream(); + } catch (IOException x) { + // directory is no longer accessible so cancel key + cancel(); + signal(); + return; + } + + // iterate over all entries in directory + try { + for (Path entry: stream) { + long lastModified = 0L; + try { + lastModified = Attributes + .readBasicFileAttributes(entry, LinkOption.NOFOLLOW_LINKS) + .lastModifiedTime(); + } catch (IOException x) { + // unable to get attributes of entry. If file has just + // been deleted then we'll report it as deleted on the + // next poll + continue; + } + + // lookup cache + CacheEntry e = entries.get(entry.getName()); + if (e == null) { + // new file found + entries.put(entry.getName(), + new CacheEntry(lastModified, tickCount)); + + // queue ENTRY_CREATE if event enabled + if (events.contains(StandardWatchEventKind.ENTRY_CREATE)) { + signalEvent(StandardWatchEventKind.ENTRY_CREATE, entry.getName()); + continue; + } else { + // if ENTRY_CREATE is not enabled and ENTRY_MODIFY is + // enabled then queue event to avoid missing out on + // modifications to the file immediately after it is + // created. + if (events.contains(StandardWatchEventKind.ENTRY_MODIFY)) { + signalEvent(StandardWatchEventKind.ENTRY_MODIFY, entry.getName()); + } + } + continue; + } + + // check if file has changed + if (e.lastModified != lastModified) { + if (events.contains(StandardWatchEventKind.ENTRY_MODIFY)) { + signalEvent(StandardWatchEventKind.ENTRY_MODIFY, entry.getName()); + } + } + // entry in cache so update poll time + e.update(lastModified, tickCount); + + } + } catch (ConcurrentModificationException x) { + // FIXME - should handle this + } finally { + + // close directory stream + try { + stream.close(); + } catch (IOException x) { + // ignore + } + } + + // iterate over cache to detect entries that have been deleted + Iterator<Map.Entry<Path,CacheEntry>> i = entries.entrySet().iterator(); + while (i.hasNext()) { + Map.Entry<Path,CacheEntry> mapEntry = i.next(); + CacheEntry entry = mapEntry.getValue(); + if (entry.lastTickCount() != tickCount) { + Path name = mapEntry.getKey(); + // remove from map and queue delete event (if enabled) + i.remove(); + if (events.contains(StandardWatchEventKind.ENTRY_DELETE)) { + signalEvent(StandardWatchEventKind.ENTRY_DELETE, name); + } + } + } + } + } +} diff --git a/src/share/classes/sun/nio/fs/Reflect.java b/src/share/classes/sun/nio/fs/Reflect.java new file mode 100644 index 0000000000000000000000000000000000000000..d425ef2498a875b600148b86ebb285f4782321c7 --- /dev/null +++ b/src/share/classes/sun/nio/fs/Reflect.java @@ -0,0 +1,63 @@ +/* + * Copyright 2008-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 sun.nio.fs; + +import java.lang.reflect.*; +import java.security.AccessController; +import java.security.PrivilegedAction; + +/** + * Utility class for reflection. + */ + +class Reflect { + private Reflect() {} + + private static void setAccessible(final AccessibleObject ao) { + AccessController.doPrivileged(new PrivilegedAction<Object>() { + @Override + public Object run() { + ao.setAccessible(true); + return null; + }}); + } + + /** + * Lookup the field of a given class. + */ + static Field lookupField(String className, String fieldName) { + try { + Class<?> cl = Class.forName(className); + Field f = cl.getDeclaredField(fieldName); + setAccessible(f); + return f; + } catch (ClassNotFoundException x) { + throw new AssertionError(x); + } catch (NoSuchFieldException x) { + throw new AssertionError(x); + } + } +} diff --git a/src/share/classes/sun/print/ServiceDialog.java b/src/share/classes/sun/print/ServiceDialog.java index 8b5bd47890099d33398fbdf205ef138389b37b58..062e6163a6f221b6a75f069fd91f13dc26b1340f 100644 --- a/src/share/classes/sun/print/ServiceDialog.java +++ b/src/share/classes/sun/print/ServiceDialog.java @@ -2149,55 +2149,51 @@ public class ServiceDialog extends JDialog implements ActionListener { } } } + } - rbPortrait.setEnabled(pSupported); - rbLandscape.setEnabled(lSupported); - rbRevPortrait.setEnabled(rpSupported); - rbRevLandscape.setEnabled(rlSupported); - - OrientationRequested or = (OrientationRequested)asCurrent.get(orCategory); - if (or == null || - !psCurrent.isAttributeValueSupported(or, docFlavor, asCurrent)) { - - or = (OrientationRequested)psCurrent.getDefaultAttributeValue(orCategory); - // need to validate if default is not supported - if (!psCurrent.isAttributeValueSupported(or, docFlavor, asCurrent)) { - or = null; - values = - psCurrent.getSupportedAttributeValues(orCategory, - docFlavor, - asCurrent); - if (values instanceof OrientationRequested[]) { - OrientationRequested[] orValues = - (OrientationRequested[])values; - if (orValues.length > 1) { - // get the first in the list - or = orValues[0]; - } - } - } - if (or == null) { - or = OrientationRequested.PORTRAIT; + rbPortrait.setEnabled(pSupported); + rbLandscape.setEnabled(lSupported); + rbRevPortrait.setEnabled(rpSupported); + rbRevLandscape.setEnabled(rlSupported); + + OrientationRequested or = (OrientationRequested)asCurrent.get(orCategory); + if (or == null || + !psCurrent.isAttributeValueSupported(or, docFlavor, asCurrent)) { + + or = (OrientationRequested)psCurrent.getDefaultAttributeValue(orCategory); + // need to validate if default is not supported + if ((or != null) && + !psCurrent.isAttributeValueSupported(or, docFlavor, asCurrent)) { + or = null; + Object values = + psCurrent.getSupportedAttributeValues(orCategory, + docFlavor, + asCurrent); + if (values instanceof OrientationRequested[]) { + OrientationRequested[] orValues = + (OrientationRequested[])values; + if (orValues.length > 1) { + // get the first in the list + or = orValues[0]; + } } - asCurrent.add(or); } - if (or == OrientationRequested.PORTRAIT) { - rbPortrait.setSelected(true); - } else if (or == OrientationRequested.LANDSCAPE) { - rbLandscape.setSelected(true); - } else if (or == OrientationRequested.REVERSE_PORTRAIT) { - rbRevPortrait.setSelected(true); - } else { // if (or == OrientationRequested.REVERSE_LANDSCAPE) - rbRevLandscape.setSelected(true); + if (or == null) { + or = OrientationRequested.PORTRAIT; } - } else { - rbPortrait.setEnabled(pSupported); - rbLandscape.setEnabled(lSupported); - rbRevPortrait.setEnabled(rpSupported); - rbRevLandscape.setEnabled(rlSupported); + asCurrent.add(or); + } + if (or == OrientationRequested.PORTRAIT) { + rbPortrait.setSelected(true); + } else if (or == OrientationRequested.LANDSCAPE) { + rbLandscape.setSelected(true); + } else if (or == OrientationRequested.REVERSE_PORTRAIT) { + rbRevPortrait.setSelected(true); + } else { // if (or == OrientationRequested.REVERSE_LANDSCAPE) + rbRevLandscape.setSelected(true); } } } diff --git a/src/share/classes/sun/reflect/annotation/AnnotationParser.java b/src/share/classes/sun/reflect/annotation/AnnotationParser.java index eac123dc6053360dc6e2c002c01bcec3d2298d68..4bcb0d305426cdc2b4a4f7533dd6c28f875c94a1 100644 --- a/src/share/classes/sun/reflect/annotation/AnnotationParser.java +++ b/src/share/classes/sun/reflect/annotation/AnnotationParser.java @@ -788,4 +788,16 @@ public class AnnotationParser { for (int i = 0; i < length; i++) skipMemberValue(buf); } + + /* + * This method converts the annotation map returned by the parseAnnotations() + * method to an array. It is called by Field.getDeclaredAnnotations(), + * Method.getDeclaredAnnotations(), and Constructor.getDeclaredAnnotations(). + * This avoids the reflection classes to load the Annotation class until + * it is needed. + */ + private static final Annotation[] EMPTY_ANNOTATION_ARRAY = new Annotation[0]; + public static Annotation[] toArray(Map<Class, Annotation> annotations) { + return annotations.values().toArray(EMPTY_ANNOTATION_ARRAY); + } } diff --git a/src/share/classes/sun/security/jca/ProviderConfig.java b/src/share/classes/sun/security/jca/ProviderConfig.java index 9b40307b1668cdcfd7a1393cd312c4605b618e40..576c68032049fd6ea4fe9a5d14de15dfac57a66f 100644 --- a/src/share/classes/sun/security/jca/ProviderConfig.java +++ b/src/share/classes/sun/security/jca/ProviderConfig.java @@ -1,5 +1,5 @@ /* - * Copyright 2003-2006 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2003-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 @@ -60,37 +60,6 @@ final class ProviderConfig { // use by doLoadProvider() private final static Class[] CL_STRING = { String.class }; - // lock to use while loading a provider. it ensures that each provider - // is loaded only once and that we can detect recursion. - // NOTE that because of 4944382 we use the system classloader as lock. - // By using the same lock to load classes as to load providers we avoid - // deadlock due to lock ordering. However, this class may be initialized - // early in the startup when the system classloader has not yet been set - // up. Use a temporary lock object if that is the case. - // Any of this may break if the class loading implementation is changed. - private static volatile Object LOCK = new Object(); - - private static Object getLock() { - Object o = LOCK; - // check if lock is already set to the class loader - if (o instanceof ClassLoader) { - return o; - } - Object cl = AccessController.doPrivileged( - new PrivilegedAction<Object>() { - public Object run() { - return ClassLoader.getSystemClassLoader(); - } - }); - // check if class loader initialized now (non-null) - if (cl != null) { - LOCK = cl; - o = cl; - } - return o; - } - - // name of the provider class private final String className; @@ -194,7 +163,7 @@ final class ProviderConfig { /** * Get the provider object. Loads the provider if it is not already loaded. */ - Provider getProvider() { + synchronized Provider getProvider() { // volatile variable load Provider p = provider; if (p != null) { @@ -203,30 +172,23 @@ final class ProviderConfig { if (shouldLoad() == false) { return null; } - synchronized (getLock()) { - p = provider; - if (p != null) { - // loaded by another thread while we were blocked on lock - return p; - } - if (isLoading) { - // because this method is synchronized, this can only - // happen if there is recursion. - if (debug != null) { - debug.println("Recursion loading provider: " + this); - new Exception("Call trace").printStackTrace(); - } - return null; + if (isLoading) { + // because this method is synchronized, this can only + // happen if there is recursion. + if (debug != null) { + debug.println("Recursion loading provider: " + this); + new Exception("Call trace").printStackTrace(); } - try { - isLoading = true; - tries++; - p = doLoadProvider(); - } finally { - isLoading = false; - } - provider = p; + return null; + } + try { + isLoading = true; + tries++; + p = doLoadProvider(); + } finally { + isLoading = false; } + provider = p; return p; } diff --git a/src/share/classes/sun/security/jgss/spnego/NegTokenInit.java b/src/share/classes/sun/security/jgss/spnego/NegTokenInit.java index 6003cdfaeabbce1225b14bf137807303746c6ba5..9bb77fd7a1d849a3c419cfe9a6671e20ee55095b 100644 --- a/src/share/classes/sun/security/jgss/spnego/NegTokenInit.java +++ b/src/share/classes/sun/security/jgss/spnego/NegTokenInit.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2006 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2005-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 @@ -66,11 +66,11 @@ public class NegTokenInit extends SpNegoToken { private byte[] mechTypes = null; private Oid[] mechTypeList = null; - private byte[] reqFlags = null; + private BitArray reqFlags = null; private byte[] mechToken = null; private byte[] mechListMIC = null; - NegTokenInit(byte[] mechTypes, byte[] flags, + NegTokenInit(byte[] mechTypes, BitArray flags, byte[] token, byte[] mechListMIC) { super(NEG_TOKEN_INIT_ID); @@ -101,7 +101,7 @@ public class NegTokenInit extends SpNegoToken { // write context flags with CONTEXT 01 if (reqFlags != null) { DerOutputStream flags = new DerOutputStream(); - flags.putBitString(reqFlags); + flags.putUnalignedBitString(reqFlags); initToken.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x01), flags); } @@ -237,7 +237,7 @@ public class NegTokenInit extends SpNegoToken { return mechTypeList; } - byte[] getReqFlags() { + BitArray getReqFlags() { return reqFlags; } diff --git a/src/share/classes/sun/security/jgss/spnego/SpNegoContext.java b/src/share/classes/sun/security/jgss/spnego/SpNegoContext.java index 7185b0e08a720a7ce66fd045111a1094f50e5d66..a84e8a260015b125f6ca3a6f142b9e5def545ca6 100644 --- a/src/share/classes/sun/security/jgss/spnego/SpNegoContext.java +++ b/src/share/classes/sun/security/jgss/spnego/SpNegoContext.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2005-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 @@ -53,13 +53,6 @@ public class SpNegoContext implements GSSContextSpi { private int state = STATE_NEW; - private static final int CHECKSUM_DELEG_FLAG = 1; - private static final int CHECKSUM_MUTUAL_FLAG = 2; - private static final int CHECKSUM_REPLAY_FLAG = 4; - private static final int CHECKSUM_SEQUENCE_FLAG = 8; - private static final int CHECKSUM_CONF_FLAG = 16; - private static final int CHECKSUM_INTEG_FLAG = 32; - /* * Optional features that the application can set and their default * values. @@ -697,25 +690,17 @@ public class SpNegoContext implements GSSContextSpi { /** * get the context flags */ - private byte[] getContextFlags() { - int flags = 0; - - if (getCredDelegState()) - flags |= CHECKSUM_DELEG_FLAG; - if (getMutualAuthState()) - flags |= CHECKSUM_MUTUAL_FLAG; - if (getReplayDetState()) - flags |= CHECKSUM_REPLAY_FLAG; - if (getSequenceDetState()) - flags |= CHECKSUM_SEQUENCE_FLAG; - if (getIntegState()) - flags |= CHECKSUM_INTEG_FLAG; - if (getConfState()) - flags |= CHECKSUM_CONF_FLAG; - - byte[] temp = new byte[1]; - temp[0] = (byte)(flags & 0xff); - return temp; + private BitArray getContextFlags() { + BitArray out = new BitArray(7); + + if (getCredDelegState()) out.set(0, true); + if (getMutualAuthState()) out.set(1, true); + if (getReplayDetState()) out.set(2, true); + if (getSequenceDetState()) out.set(3, true); + if (getConfState()) out.set(5, true); + if (getIntegState()) out.set(6, true); + + return out; } private void setContextFlags() { diff --git a/src/share/classes/sun/security/krb5/Realm.java b/src/share/classes/sun/security/krb5/Realm.java index 1dbffe264456224b7ffd6d2f40e1f28bd0288b97..bf57e7a54ceb64cec53349e35b7b80bfaa54d29e 100644 --- a/src/share/classes/sun/security/krb5/Realm.java +++ b/src/share/classes/sun/security/krb5/Realm.java @@ -1,5 +1,5 @@ /* - * Portions Copyright 2000-2006 Sun Microsystems, Inc. All Rights Reserved. + * Portions Copyright 2000-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 @@ -39,7 +39,6 @@ import sun.security.krb5.RealmException; import sun.security.krb5.internal.Krb5; import sun.security.util.*; import java.io.IOException; -import java.io.OutputStream; import java.util.StringTokenizer; import java.util.Vector; import java.util.Stack; @@ -364,7 +363,6 @@ public class Realm implements Cloneable { } String tempTarget = null, tempRealm = null; - StringTokenizer strTok = null; Stack<String> iStack = new Stack<String> (); /* @@ -382,7 +380,7 @@ public class Realm implements Cloneable { tempTarget = sRealm; } - do { + out: do { if (DEBUG) { count++; System.out.println(">>> Realm parseCapaths: loop " + @@ -400,15 +398,21 @@ public class Realm implements Cloneable { /* * We have one or more space-separated intermediary realms. - * Stack them. + * Stack them. A null is always added between intermedies of + * different targets. When this null is popped, it means none + * of the intermedies for this target is useful (because of + * infinite loop), the target is then removed from the partial + * tempList, and the next possible intermediary is tried. */ - strTok = new StringTokenizer(intermediaries, " "); - while (strTok.hasMoreTokens()) + iStack.push(null); + String[] ints = intermediaries.split("\\s+"); + for (int i = ints.length-1; i>=0; i--) { - tempRealm = strTok.nextToken(); - if (!tempRealm.equals(PrincipalName. - REALM_COMPONENT_SEPARATOR_STR) && - !iStack.contains(tempRealm)) { + tempRealm = ints[i]; + if (tempRealm.equals(PrincipalName.REALM_COMPONENT_SEPARATOR_STR)) { + break out; + } + if (!tempList.contains(tempRealm)) { iStack.push(tempRealm); if (DEBUG) { System.out.println(">>> Realm parseCapaths: loop " + @@ -418,16 +422,18 @@ public class Realm implements Cloneable { } } else if (DEBUG) { System.out.println(">>> Realm parseCapaths: loop " + - count + ": ignoring realm: [" + tempRealm + "]"); } } - } else if (DEBUG) { - System.out.println(">>> Realm parseCapaths: loop " + - count + - ": no intermediaries"); + } else { + if (DEBUG) { + System.out.println(">>> Realm parseCapaths: loop " + + count + + ": no intermediaries"); + } + break; } /* @@ -435,7 +441,12 @@ public class Realm implements Cloneable { */ try { - tempTarget = iStack.pop(); + while ((tempTarget = iStack.pop()) == null) { + tempList.removeElementAt(tempList.size()-1); + if (DEBUG) { + System.out.println(">>> Realm parseCapaths: backtrack, remove tail"); + } + } } catch (EmptyStackException exc) { tempTarget = null; } diff --git a/src/share/classes/sun/security/pkcs11/P11Key.java b/src/share/classes/sun/security/pkcs11/P11Key.java index 8949826b19e4e85e09297a1fa17ae527232ef74a..c70642d353173d88fe61eeb36227a74f57869f47 100644 --- a/src/share/classes/sun/security/pkcs11/P11Key.java +++ b/src/share/classes/sun/security/pkcs11/P11Key.java @@ -1,5 +1,5 @@ /* - * Copyright 2003-2006 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2003-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 @@ -26,6 +26,7 @@ package sun.security.pkcs11; import java.io.*; +import java.lang.ref.*; import java.math.BigInteger; import java.util.*; @@ -67,9 +68,6 @@ abstract class P11Key implements Key { // type of key, one of (PUBLIC, PRIVATE, SECRET) final String type; - // session in which the key was created, relevant for session objects - final Session session; - // token instance final Token token; @@ -85,10 +83,12 @@ abstract class P11Key implements Key { // flags indicating whether the key is a token object, sensitive, extractable final boolean tokenObject, sensitive, extractable; + // weak reference notification clean up for session keys + private final SessionKeyRef sessionKeyRef; + P11Key(String type, Session session, long keyID, String algorithm, int keyLength, CK_ATTRIBUTE[] attributes) { this.type = type; - this.session = session; this.token = session.token; this.keyID = keyID; this.algorithm = algorithm; @@ -111,7 +111,9 @@ abstract class P11Key implements Key { this.sensitive = sensitive; this.extractable = extractable; if (tokenObject == false) { - session.addObject(); + sessionKeyRef = new SessionKeyRef(this, keyID, session); + } else { + sessionKeyRef = null; } } @@ -236,24 +238,6 @@ abstract class P11Key implements Key { } } - protected void finalize() throws Throwable { - if (tokenObject || (token.isValid() == false)) { - super.finalize(); - return; - } - Session newSession = null; - try { - newSession = token.getOpSession(); - token.p11.C_DestroyObject(newSession.id(), keyID); - } catch (PKCS11Exception e) { - // ignore - } finally { - token.releaseSession(newSession); - session.removeObject(); - super.finalize(); - } - } - private final static CK_ATTRIBUTE[] A0 = new CK_ATTRIBUTE[0]; private static CK_ATTRIBUTE[] getAttributes(Session session, long keyID, @@ -1055,5 +1039,65 @@ abstract class P11Key implements Key { + "\n parameters: " + params; } } +} + +final class SessionKeyRef extends WeakReference<P11Key> + implements Comparable<SessionKeyRef> { + private static ReferenceQueue<P11Key> refQueue = + new ReferenceQueue<P11Key>(); + private static Set<SessionKeyRef> refList = + Collections.synchronizedSortedSet(new TreeSet<SessionKeyRef>()); + + static ReferenceQueue<P11Key> referenceQueue() { + return refQueue; + } + static final private int MAX_ITERATIONS = 2; + + private static void drainRefQueueBounded() { + int iterations = 0; + while (iterations < MAX_ITERATIONS) { + SessionKeyRef next = (SessionKeyRef) refQueue.poll(); + if (next != null) next.dispose(); + ++iterations; + } + } + + // handle to the native key + private long keyID; + private Session session; + + SessionKeyRef(P11Key key , long keyID, Session session) { + super(key, refQueue); + this.keyID = keyID; + this.session = session; + this.session.addObject(); + refList.add(this); + // TBD: run at some interval and not every time? + drainRefQueueBounded(); + } + + void dispose() { + refList.remove(this); + if (session.token.isValid()) { + Session newSession = null; + try { + newSession = session.token.getOpSession(); + session.token.p11.C_DestroyObject(newSession.id(), keyID); + } catch (PKCS11Exception e) { + // ignore + } finally { + session.token.releaseSession(newSession); + session.removeObject(); + } + } + } + + public int compareTo(SessionKeyRef other) { + if (this.keyID == other.keyID) { + return 0; + } else { + return (this.keyID < other.keyID) ? -1 : 1; + } + } } diff --git a/src/share/classes/sun/security/pkcs11/P11RSACipher.java b/src/share/classes/sun/security/pkcs11/P11RSACipher.java index 3b8244cc413a2ee8d3da6e0a415eab5d690e0b2d..c3709ad5b13102adfd28b36c20b1de5b1ddb6a68 100644 --- a/src/share/classes/sun/security/pkcs11/P11RSACipher.java +++ b/src/share/classes/sun/security/pkcs11/P11RSACipher.java @@ -1,5 +1,5 @@ /* - * Copyright 2003-2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2003-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 @@ -191,7 +191,9 @@ final class P11RSACipher extends CipherSpi { throw new InvalidKeyException ("Unwrap has to be used with private keys"); } - encrypt = false; + // No further setup needed for C_Unwrap(). We'll initialize later + // if we can't use C_Unwrap(). + return; } else { throw new InvalidKeyException("Unsupported mode: " + opmode); } @@ -452,7 +454,7 @@ final class P11RSACipher extends CipherSpi { long keyID = token.p11.C_UnwrapKey(s.id(), new CK_MECHANISM(mechanism), p11Key.keyID, wrappedKey, attributes); - return P11Key.secretKey(session, keyID, algorithm, 48 << 3, + return P11Key.secretKey(s, keyID, algorithm, 48 << 3, attributes); } catch (PKCS11Exception e) { throw new InvalidKeyException("unwrap() failed", e); @@ -461,6 +463,7 @@ final class P11RSACipher extends CipherSpi { } } // XXX implement unwrap using C_Unwrap() for all keys + implInit(Cipher.DECRYPT_MODE, p11Key); if (wrappedKey.length > maxInputSize) { throw new InvalidKeyException("Key is too long for unwrapping"); } diff --git a/src/share/classes/sun/security/pkcs11/P11SecretKeyFactory.java b/src/share/classes/sun/security/pkcs11/P11SecretKeyFactory.java index 59b59237a6ffaa72adcce7ed3b0d1578b5236908..d607900d65148ce3b6488b8740c47d8ef0168317 100644 --- a/src/share/classes/sun/security/pkcs11/P11SecretKeyFactory.java +++ b/src/share/classes/sun/security/pkcs11/P11SecretKeyFactory.java @@ -151,7 +151,7 @@ final class P11SecretKeyFactory extends SecretKeyFactorySpi { session = token.getObjSession(); long newKeyID = token.p11.C_CopyObject(session.id(), p11Key.keyID, extraAttrs); - p11Key = (P11Key) (P11Key.secretKey(p11Key.session, + p11Key = (P11Key) (P11Key.secretKey(session, newKeyID, p11Key.algorithm, p11Key.keyLength, extraAttrs)); } catch (PKCS11Exception p11e) { diff --git a/src/share/classes/sun/security/provider/SeedGenerator.java b/src/share/classes/sun/security/provider/SeedGenerator.java index 3695e7c3cb9f85c45faf1aac0131e9f2c5078955..dd345676a12902508b7d1bef2137a710e79eae12 100644 --- a/src/share/classes/sun/security/provider/SeedGenerator.java +++ b/src/share/classes/sun/security/provider/SeedGenerator.java @@ -1,5 +1,5 @@ /* - * Copyright 1996-2006 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. * * This code is free software; you can redistribute it and/or modify it @@ -68,6 +68,9 @@ import java.io.*; import java.util.Properties; import java.util.Enumeration; import java.net.*; +import java.nio.file.DirectoryStream; +import java.nio.file.Path; +import java.util.Random; import sun.security.util.Debug; abstract class SeedGenerator { @@ -180,10 +183,27 @@ abstract class SeedGenerator { // The temporary dir File f = new File(p.getProperty("java.io.tmpdir")); - String[] sa = f.list(); - for(int i = 0; i < sa.length; i++) - md.update(sa[i].getBytes()); - + int count = 0; + DirectoryStream<Path> ds + = f.toPath().newDirectoryStream(); + try { + // We use a Random object to choose what file names + // should be used. Otherwise on a machine with too + // many files, the same first 1024 files always get + // used. Any, We make sure the first 512 files are + // always used. + Random r = new Random(); + for (Path path: ds) { + if (count < 512 || r.nextBoolean()) { + md.update(path.getName().toString().getBytes()); + } + if (count++ > 1024) { + break; + } + } + } finally { + ds.close(); + } } catch (Exception ex) { md.update((byte)ex.hashCode()); } diff --git a/src/share/classes/sun/security/provider/X509Factory.java b/src/share/classes/sun/security/provider/X509Factory.java index 8fc755cc83d28d7ec02061c91b3fc43eecef0703..ce0d120ae8d8cff2a48937f1404a6acb8d73caef 100644 --- a/src/share/classes/sun/security/provider/X509Factory.java +++ b/src/share/classes/sun/security/provider/X509Factory.java @@ -1,5 +1,5 @@ /* - * Copyright 1998-2006 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 1998-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 @@ -638,10 +638,15 @@ is) // First read all of the data that is found between // the "-----BEGIN" and "-----END" boundaries into a buffer. String temp; - if ((temp=readLine(br))==null || !temp.startsWith("-----BEGIN")) { - throw new IOException("Unsupported encoding"); - } else { + while (true) { + temp=readLine(br); + if (temp == null) { + throw new IOException("Unsupported encoding"); + } len += temp.length(); + if (temp.startsWith("-----BEGIN")) { + break; + } } StringBuffer strBuf = new StringBuffer(); while ((temp=readLine(br))!=null && !temp.startsWith("-----END")) { @@ -683,22 +688,11 @@ is) * Determines if input is binary or Base64 encoded. */ private boolean isBase64(InputStream is) throws IOException { - if (is.available() >= 10) { - is.mark(10); + if (is.available() >= 1) { + is.mark(1); int c1 = is.read(); - int c2 = is.read(); - int c3 = is.read(); - int c4 = is.read(); - int c5 = is.read(); - int c6 = is.read(); - int c7 = is.read(); - int c8 = is.read(); - int c9 = is.read(); - int c10 = is.read(); is.reset(); - if (c1 == '-' && c2 == '-' && c3 == '-' && c4 == '-' - && c5 == '-' && c6 == 'B' && c7 == 'E' && c8 == 'G' - && c9 == 'I' && c10 == 'N') { + if (c1 != DerValue.tag_Sequence) { return true; } else { return false; diff --git a/src/share/classes/sun/security/provider/certpath/OCSPResponse.java b/src/share/classes/sun/security/provider/certpath/OCSPResponse.java index 20bac34f2ccfaa6b098730c466b92703f21961a1..62cd4288ed00f1a58dd65dc80c6fca51ce326564 100644 --- a/src/share/classes/sun/security/provider/certpath/OCSPResponse.java +++ b/src/share/classes/sun/security/provider/certpath/OCSPResponse.java @@ -1,5 +1,5 @@ /* - * Copyright 2003-2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2003-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 @@ -28,8 +28,6 @@ package sun.security.provider.certpath; import java.io.*; import java.math.BigInteger; import java.security.*; -import java.security.cert.Certificate; -import java.security.cert.CertificateFactory; import java.security.cert.CertPathValidatorException; import java.security.cert.CRLReason; import java.security.cert.X509Certificate; @@ -335,7 +333,7 @@ class OCSPResponse { // Check whether the cert returned by the responder is trusted if (x509Certs != null && x509Certs[0] != null) { - X509Certificate cert = x509Certs[0]; + X509CertImpl cert = x509Certs[0]; // First check if the cert matches the responder cert which // was set locally. @@ -344,8 +342,8 @@ class OCSPResponse { // Next check if the cert was issued by the responder cert // which was set locally. - } else if (cert.getIssuerDN().equals( - responderCert.getSubjectDN())) { + } else if (cert.getIssuerX500Principal().equals( + responderCert.getSubjectX500Principal())) { // Check for the OCSPSigning key purpose List<String> keyPurposes = cert.getExtendedKeyUsage(); @@ -360,6 +358,43 @@ class OCSPResponse { "OCSP responses"); } + // check the validity + try { + Date dateCheckedAgainst = params.getDate(); + if (dateCheckedAgainst == null) { + cert.checkValidity(); + } else { + cert.checkValidity(dateCheckedAgainst); + } + } catch (GeneralSecurityException e) { + if (DEBUG != null) { + DEBUG.println("Responder's certificate is not " + + "within the validity period."); + } + throw new CertPathValidatorException( + "Responder's certificate not within the " + + "validity period"); + } + + // check for revocation + // + // A CA may specify that an OCSP client can trust a + // responder for the lifetime of the responder's + // certificate. The CA does so by including the + // extension id-pkix-ocsp-nocheck. + // + Extension noCheck = + cert.getExtension(PKIXExtensions.OCSPNoCheck_Id); + if (noCheck != null) { + if (DEBUG != null) { + DEBUG.println("Responder's certificate includes " + + "the extension id-pkix-ocsp-nocheck."); + } + } else { + // we should do the revocating checking of the + // authorized responder in a future update. + } + // verify the signature try { cert.verify(responderCert.getPublicKey()); @@ -369,6 +404,14 @@ class OCSPResponse { } catch (GeneralSecurityException e) { responderCert = null; } + } else { + if (DEBUG != null) { + DEBUG.println("Responder's certificate is not " + + "authorized to sign OCSP responses."); + } + throw new CertPathValidatorException( + "Responder's certificate not authorized to sign " + + "OCSP responses"); } } diff --git a/src/share/classes/sun/security/provider/certpath/PKIXMasterCertPathValidator.java b/src/share/classes/sun/security/provider/certpath/PKIXMasterCertPathValidator.java index d5f12168ddab2dbca3df7099544d7a538bd8297d..7c3bfc378430113edef1386c726943a37953a7bd 100644 --- a/src/share/classes/sun/security/provider/certpath/PKIXMasterCertPathValidator.java +++ b/src/share/classes/sun/security/provider/certpath/PKIXMasterCertPathValidator.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2008 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. * * This code is free software; you can redistribute it and/or modify it @@ -143,11 +143,15 @@ class PKIXMasterCertPathValidator { } } catch (CertPathValidatorException cpve) { - // Throw the saved OCSP exception - // (when the CRL check has also failed) + // Throw the saved OCSP exception unless the CRL + // checker has determined that the cert is revoked if (ocspCause != null && - currChecker instanceof CrlRevocationChecker) { - throw ocspCause; + currChecker instanceof CrlRevocationChecker) { + if (cpve.getReason() == BasicReason.REVOKED) { + throw cpve; + } else { + throw ocspCause; + } } /* * Handle failover from OCSP to CRLs diff --git a/src/share/classes/sun/security/ssl/AppInputStream.java b/src/share/classes/sun/security/ssl/AppInputStream.java index d638b8f46e9fcbc9fbce954383e7cc82eedb0a32..2ca889593c0131f73285fd2bf4827188ceac1ae5 100644 --- a/src/share/classes/sun/security/ssl/AppInputStream.java +++ b/src/share/classes/sun/security/ssl/AppInputStream.java @@ -1,5 +1,5 @@ /* - * 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. * * This code is free software; you can redistribute it and/or modify it @@ -81,6 +81,14 @@ class AppInputStream extends InputStream { */ public synchronized int read(byte b[], int off, int len) throws IOException { + if (b == null) { + throw new NullPointerException(); + } else if (off < 0 || len < 0 || len > b.length - off) { + throw new IndexOutOfBoundsException(); + } else if (len == 0) { + return 0; + } + if (c.checkEOF()) { return -1; } diff --git a/src/share/classes/sun/security/ssl/AppOutputStream.java b/src/share/classes/sun/security/ssl/AppOutputStream.java index d039cacb8b2c5567c40eef59e076acd7ca51ba53..d8c78a8eb5038d443337e15d2669e7674838786c 100644 --- a/src/share/classes/sun/security/ssl/AppOutputStream.java +++ b/src/share/classes/sun/security/ssl/AppOutputStream.java @@ -1,5 +1,5 @@ /* - * 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. * * This code is free software; you can redistribute it and/or modify it @@ -58,18 +58,25 @@ class AppOutputStream extends OutputStream { */ synchronized public void write(byte b[], int off, int len) throws IOException { + if (b == null) { + throw new NullPointerException(); + } else if (off < 0 || len < 0 || len > b.length - off) { + throw new IndexOutOfBoundsException(); + } else if (len == 0) { + return; + } + // check if the Socket is invalid (error or closed) c.checkWrite(); - // + // Always flush at the end of each application level record. // This lets application synchronize read and write streams // however they like; if we buffered here, they couldn't. - // - // NOTE: *must* call c.writeRecord() even for len == 0 try { do { int howmuch = Math.min(len, r.availableDataBytes()); + // NOTE: *must* call c.writeRecord() even for howmuch == 0 if (howmuch > 0) { r.write(b, off, howmuch); off += howmuch; diff --git a/src/share/classes/sun/security/ssl/ByteBufferInputStream.java b/src/share/classes/sun/security/ssl/ByteBufferInputStream.java index 9c484d87ed3f0f5215de9a3a12e406fabac6eebc..d69e2bfdc54a882ce9036dca8f8f15cc1f6b7c17 100644 --- a/src/share/classes/sun/security/ssl/ByteBufferInputStream.java +++ b/src/share/classes/sun/security/ssl/ByteBufferInputStream.java @@ -1,5 +1,5 @@ /* - * Copyright 2003-2007 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2003-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 @@ -89,8 +89,7 @@ class ByteBufferInputStream extends InputStream { if (b == null) { throw new NullPointerException(); - } else if ((off < 0) || (off > b.length) || (len < 0) || - ((off + len) > b.length) || ((off + len) < 0)) { + } else if (off < 0 || len < 0 || len > b.length - off) { throw new IndexOutOfBoundsException(); } else if (len == 0) { return 0; diff --git a/src/share/classes/sun/security/ssl/SSLSessionContextImpl.java b/src/share/classes/sun/security/ssl/SSLSessionContextImpl.java index c98f1cc2c261848287634eb8d5c1d9e03cf4d380..3aeef2d8eee63b8956045ba17c8d07cc929c55c0 100644 --- a/src/share/classes/sun/security/ssl/SSLSessionContextImpl.java +++ b/src/share/classes/sun/security/ssl/SSLSessionContextImpl.java @@ -1,5 +1,5 @@ /* - * 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. * * This code is free software; you can redistribute it and/or modify it @@ -41,88 +41,112 @@ import javax.net.ssl.SSLSessionBindingEvent; import javax.net.ssl.SSLPeerUnverifiedException; import javax.net.ssl.SSLSession; -import sun.misc.Cache; +import sun.security.util.Cache; -final class SSLSessionContextImpl implements SSLSessionContext -{ - private Cache sessionCache = new Cache(); - private Cache sessionHostPortCache = new Cache(); - private int cacheLimit; - private long timeoutMillis; +final class SSLSessionContextImpl implements SSLSessionContext { + private Cache sessionCache; // session cache, session id as key + private Cache sessionHostPortCache; // session cache, "host:port" as key + private int cacheLimit; // the max cache size + private int timeout; // timeout in seconds + private static final Debug debug = Debug.getInstance("ssl"); - // file private - SSLSessionContextImpl() - { - cacheLimit = getCacheLimit(); - timeoutMillis = 86400000; // default, 24 hours + // package private + SSLSessionContextImpl() { + cacheLimit = getDefaultCacheLimit(); // default cache size + timeout = 86400; // default, 24 hours + + // use soft reference + sessionCache = Cache.newSoftMemoryCache(cacheLimit, timeout); + sessionHostPortCache = Cache.newSoftMemoryCache(cacheLimit, timeout); } /** - * Returns the SSL session object associated with the - * specific session ID passed. + * Returns the <code>SSLSession</code> bound to the specified session id. */ - public SSLSession getSession(byte[] id) - { - SSLSession sess = (SSLSession) sessionCache.get( - new SessionId(id)); - return checkTimeValidity(sess); + public SSLSession getSession(byte[] sessionId) { + if (sessionId == null) { + throw new NullPointerException("session id cannot be null"); + } + + SSLSessionImpl sess = + (SSLSessionImpl)sessionCache.get(new SessionId(sessionId)); + if (!isTimedout(sess)) { + return sess; + } + + return null; } /** * Returns an enumeration of the active SSL sessions. */ public Enumeration<byte[]> getIds() { - Vector<byte[]> v = new Vector<byte[]>(sessionCache.size()); - SessionId sessId; + SessionCacheVisitor scVisitor = new SessionCacheVisitor(); + sessionCache.accept(scVisitor); - for (Enumeration e = sessionCache.keys(); e.hasMoreElements(); ) { - sessId = (SessionId) e.nextElement(); - if (!isTimedout((SSLSession)sessionCache.get(sessId))) - v.addElement(sessId.getId()); - } - return v.elements(); + return scVisitor.getSessionIds(); } + /** + * Sets the timeout limit for cached <code>SSLSession</code> objects + * + * Note that after reset the timeout, the cached session before + * should be timed within the shorter one of the old timeout and the + * new timeout. + */ public void setSessionTimeout(int seconds) throws IllegalArgumentException { - if (seconds < 0) + if (seconds < 0) { throw new IllegalArgumentException(); - timeoutMillis = seconds * 1000L; + } + + if (timeout != seconds) { + sessionCache.setTimeout(seconds); + sessionHostPortCache.setTimeout(seconds); + timeout = seconds; + } } + /** + * Gets the timeout limit for cached <code>SSLSession</code> objects + */ public int getSessionTimeout() { - return (int) (timeoutMillis / 1000); + return timeout; } + /** + * Sets the size of the cache used for storing + * <code>SSLSession</code> objects. + */ public void setSessionCacheSize(int size) throws IllegalArgumentException { if (size < 0) throw new IllegalArgumentException(); - cacheLimit = size; - /** - * If cache size limit is reduced, when the cache is full to its - * previous limit, trim the cache before its contents - * are used. - */ - if ((cacheLimit != 0) && (sessionCache.size() > cacheLimit)) - adjustCacheSizeTo(cacheLimit); + if (cacheLimit != size) { + sessionCache.setCapacity(size); + sessionHostPortCache.setCapacity(size); + cacheLimit = size; + } } + /** + * Gets the size of the cache used for storing + * <code>SSLSession</code> objects. + */ public int getSessionCacheSize() { return cacheLimit; } + + // package-private method, used ONLY by ServerHandshaker SSLSessionImpl get(byte[] id) { - return (SSLSessionImpl) getSession(id); + return (SSLSessionImpl)getSession(id); } - /** - * Returns the SSL session object associated with the - * specific host name and port number passed. - */ + // package-private method, used ONLY by ClientHandshaker SSLSessionImpl get(String hostname, int port) { /* * If no session caching info is available, we won't @@ -131,96 +155,51 @@ final class SSLSessionContextImpl implements SSLSessionContext if (hostname == null && port == -1) { return null; } - SSLSession sess = (SSLSessionImpl) sessionHostPortCache - .get(getKey(hostname, port)); - return (SSLSessionImpl) checkTimeValidity(sess); + + SSLSessionImpl sess = + (SSLSessionImpl)sessionHostPortCache.get(getKey(hostname, port)); + if (!isTimedout(sess)) { + return sess; + } + + return null; } private String getKey(String hostname, int port) { - return (hostname + ":" + String.valueOf(port)) - .toLowerCase(); + return (hostname + ":" + String.valueOf(port)).toLowerCase(); } + // cache a SSLSession + // + // In SunJSSE implementation, a session is created while getting a + // client hello or a server hello message, and cached while the + // handshaking finished. + // Here we time the session from the time it cached instead of the + // time it created, which is a little longer than the expected. So + // please do check isTimedout() while getting entry from the cache. void put(SSLSessionImpl s) { - // make space for the new session to be added - if ((cacheLimit != 0) && (sessionCache.size() >= cacheLimit)) - adjustCacheSizeTo(cacheLimit - 1); - - /* - * Can always add the session id. - */ sessionCache.put(s.getSessionId(), s); - /* - * If no hostname/port info is available, don't add this one. - */ + // If no hostname/port info is available, don't add this one. if ((s.getPeerHost() != null) && (s.getPeerPort() != -1)) { sessionHostPortCache.put( getKey(s.getPeerHost(), s.getPeerPort()), s); } + s.setContext(this); } - private void adjustCacheSizeTo(int targetSize) { - - int cacheSize = sessionCache.size(); - - if (targetSize < 0) - return; - - while (cacheSize > targetSize) { - SSLSessionImpl lru = null; - SSLSessionImpl s = null; - Enumeration e; - - if (debug != null && Debug.isOn("sessioncache")) { - System.out.println("exceeded cache limit of " + cacheLimit); - } - - /* - * Count the number of elements in the cache. The size() method - * does not reflect the cache entries that are no longer available, - * i.e entries that are garbage collected (the cache entries are - * held using soft references and are garbage collected when not - * in use). - */ - int count; - for (count = 0, e = sessionCache.elements(); - e.hasMoreElements(); count++) { - try { - s = (SSLSessionImpl)e.nextElement(); - } catch (NoSuchElementException nsee) { - break; - } - if (isTimedout(s)) { - lru = s; - break; - } else if ((lru == null) || (s.getLastAccessedTime() - < lru.getLastAccessedTime())) { - lru = s; - } - } - if ((lru != null) && (count > targetSize)) { - if (debug != null && Debug.isOn("sessioncache")) { - System.out.println("uncaching " + lru); - } - lru.invalidate(); - count--; // element removed from the cache - } - cacheSize = count; + // package-private method, remove a cached SSLSession + void remove(SessionId key) { + SSLSessionImpl s = (SSLSessionImpl)sessionCache.get(key); + if (s != null) { + sessionCache.remove(key); + sessionHostPortCache.remove( + getKey(s.getPeerHost(), s.getPeerPort())); } } - // file private - void remove(SessionId key) - { - SSLSessionImpl s = (SSLSessionImpl) sessionCache.get(key); - sessionCache.remove(key); - sessionHostPortCache.remove(getKey(s.getPeerHost(), - s.getPeerPort())); - } - - private int getCacheLimit() { + private int getDefaultCacheLimit() { int cacheLimit = 0; try { String s = java.security.AccessController.doPrivileged( @@ -237,21 +216,40 @@ final class SSLSessionContextImpl implements SSLSessionContext return (cacheLimit > 0) ? cacheLimit : 0; } - SSLSession checkTimeValidity(SSLSession sess) { - if (isTimedout(sess)) { - sess.invalidate(); - return null; - } else - return sess; - } - boolean isTimedout(SSLSession sess) { - if (timeoutMillis == 0) + if (timeout == 0) { return false; - if ((sess != null) && - ((sess.getCreationTime() + timeoutMillis) - <= (System.currentTimeMillis()))) + } + + if ((sess != null) && ((sess.getCreationTime() + timeout * 1000L) + <= (System.currentTimeMillis()))) { + sess.invalidate(); return true; + } + return false; } + + final class SessionCacheVisitor + implements sun.security.util.Cache.CacheVisitor { + Vector<byte[]> ids = null; + + // public void visit(java.util.Map<Object, Object> map) {} + public void visit(java.util.Map<Object, Object> map) { + ids = new Vector<byte[]>(map.size()); + + for (Object key : map.keySet()) { + SSLSessionImpl value = (SSLSessionImpl)map.get(key); + if (!isTimedout(value)) { + ids.addElement(((SessionId)key).getId()); + } + } + } + + public Enumeration<byte[]> getSessionIds() { + return ids != null ? ids.elements() : + new Vector<byte[]>().elements(); + } + } + } diff --git a/src/share/classes/sun/security/ssl/SSLSocketImpl.java b/src/share/classes/sun/security/ssl/SSLSocketImpl.java index 7974f1b13b4d2ab383f2295cfc9f04c8e61e9e56..820954f96131596b72a634454d885e007929e975 100644 --- a/src/share/classes/sun/security/ssl/SSLSocketImpl.java +++ b/src/share/classes/sun/security/ssl/SSLSocketImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 1996-2008 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. * * This code is free software; you can redistribute it and/or modify it @@ -368,7 +368,9 @@ final public class SSLSocketImpl extends BaseSSLSocketImpl { super(); this.host = host; init(context, false); - SocketAddress socketAddress = new InetSocketAddress(host, port); + SocketAddress socketAddress = + host != null ? new InetSocketAddress(host, port) : + new InetSocketAddress(InetAddress.getByName(null), port); connect(socketAddress, 0); } @@ -409,7 +411,9 @@ final public class SSLSocketImpl extends BaseSSLSocketImpl { this.host = host; init(context, false); bind(new InetSocketAddress(localAddr, localPort)); - SocketAddress socketAddress = new InetSocketAddress(host, port); + SocketAddress socketAddress = + host != null ? new InetSocketAddress(host, port) : + new InetSocketAddress(InetAddress.getByName(null), port); connect(socketAddress, 0); } @@ -1829,7 +1833,8 @@ final public class SSLSocketImpl extends BaseSSLSocketImpl { } synchronized String getHost() { - if (host == null) { + // Note that the host may be null or empty for localhost. + if (host == null || host.length() == 0) { host = getInetAddress().getHostName(); } return host; diff --git a/src/share/classes/sun/security/tools/JarSigner.java b/src/share/classes/sun/security/tools/JarSigner.java index d8d1ee3d517ed82506a339145f1a61d4347ac3b4..2de2e52b08a64dd80e4ecbe58bd684fd87642664 100644 --- a/src/share/classes/sun/security/tools/JarSigner.java +++ b/src/share/classes/sun/security/tools/JarSigner.java @@ -1,5 +1,5 @@ /* - * Copyright 1997-2007 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 1997-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 @@ -32,28 +32,44 @@ import java.util.jar.*; import java.math.BigInteger; import java.net.URI; import java.net.URISyntaxException; -import java.net.URL; -import java.net.URLClassLoader; -import java.net.SocketTimeoutException; import java.text.Collator; import java.text.MessageFormat; import java.security.cert.Certificate; import java.security.cert.X509Certificate; import java.security.cert.CertificateException; -import java.security.cert.CertificateExpiredException; -import java.security.cert.CertificateNotYetValidException; import java.security.*; import java.lang.reflect.Constructor; import com.sun.jarsigner.ContentSigner; import com.sun.jarsigner.ContentSignerParameters; +import java.net.SocketTimeoutException; +import java.net.URL; +import java.net.URLClassLoader; +import java.security.cert.CertPath; +import java.security.cert.CertPathValidator; +import java.security.cert.CertificateExpiredException; +import java.security.cert.CertificateFactory; +import java.security.cert.CertificateNotYetValidException; +import java.security.cert.PKIXParameters; +import java.security.cert.TrustAnchor; +import java.util.Map.Entry; import sun.security.x509.*; import sun.security.util.*; import sun.misc.BASE64Encoder; + /** * <p>The jarsigner utility. * + * The exit codes for the main method are: + * + * 0: success + * 1: any error that the jar cannot be signed or verified, including: + * keystore loading error + * TSP communciation error + * jarsigner command line error... + * otherwise: error codes from -strict + * * @author Roland Schemers * @author Jan Luehe */ @@ -84,8 +100,6 @@ public class JarSigner { // Attention: // This is the entry that get launched by the security tool jarsigner. - // It's marked as exported private per AppServer Team's request. - // See http://ccc.sfbay/6428446 public static void main(String args[]) throws Exception { JarSigner js = new JarSigner(); js.run(args); @@ -93,31 +107,32 @@ public class JarSigner { static final String VERSION = "1.0"; - static final int IN_KEYSTORE = 0x01; + static final int IN_KEYSTORE = 0x01; // signer is in keystore static final int IN_SCOPE = 0x02; + static final int NOT_ALIAS = 0x04; // alias list is NOT empty and + // signer is not in alias list + static final int SIGNED_BY_ALIAS = 0x08; // signer is in alias list - // signer's certificate chain (when composing) - X509Certificate[] certChain; - - /* - * private key - */ - PrivateKey privateKey; - KeyStore store; + X509Certificate[] certChain; // signer's cert chain (when composing) + PrivateKey privateKey; // private key + KeyStore store; // the keystore specified by -keystore + // or the default keystore, never null IdentityScope scope; String keystore; // key store file boolean nullStream = false; // null keystore input stream (NONE) boolean token = false; // token-based keystore - String jarfile; // jar file to sign + String jarfile; // jar file to sign or verify String alias; // alias to sign jar with + List<String> ckaliases = new ArrayList<String>(); // aliases in -verify char[] storepass; // keystore password boolean protectedPath; // protected authentication path String storetype; // keystore type String providerName; // provider name Vector<String> providers = null; // list of providers - HashMap<String,String> providerArgs = new HashMap<String, String>(); // arguments for provider constructors + // arguments for provider constructors + HashMap<String,String> providerArgs = new HashMap<String, String>(); char[] keypass; // private key password String sigfile; // name of .SF file String sigalg; // name of signature algorithm @@ -125,12 +140,14 @@ public class JarSigner { String signedjar; // output filename String tsaUrl; // location of the Timestamping Authority String tsaAlias; // alias for the Timestamping Authority's certificate + String altCertChain; // file to read alternative cert chain from boolean verify = false; // verify the jar - boolean verbose = false; // verbose output when signing/verifying + String verbose = null; // verbose output when signing/verifying boolean showcerts = false; // show certs when verifying boolean debug = false; // debug boolean signManifest = true; // "sign" the whole manifest boolean externalSF = true; // leave the .SF out of the PKCS7 block + boolean strict = false; // treat warnings as error // read zip entry raw bytes private ByteArrayOutputStream baos = new ByteArrayOutputStream(2048); @@ -139,14 +156,22 @@ public class JarSigner { private String altSignerClass = null; private String altSignerClasspath = null; private ZipFile zipFile = null; + private boolean hasExpiredCert = false; private boolean hasExpiringCert = false; private boolean notYetValidCert = false; - + private boolean chainNotValidated = false; + private boolean notSignedByAlias = false; + private boolean aliasNotInStore = false; + private boolean hasUnsignedEntry = false; private boolean badKeyUsage = false; private boolean badExtendedKeyUsage = false; private boolean badNetscapeCertType = false; + CertificateFactory certificateFactory; + CertPathValidator validator; + PKIXParameters pkixParameters; + public void run(String args[]) { try { parseArgs(args); @@ -184,14 +209,6 @@ public class JarSigner { } } - hasExpiredCert = false; - hasExpiringCert = false; - notYetValidCert = false; - - badKeyUsage = false; - badExtendedKeyUsage = false; - badNetscapeCertType = false; - if (verify) { try { loadKeyStore(keystore, false); @@ -238,6 +255,29 @@ public class JarSigner { storepass = null; } } + + if (strict) { + int exitCode = 0; + if (hasExpiringCert) { + exitCode |= 2; + } + if (chainNotValidated) { + // hasExpiredCert and notYetValidCert included in this case + exitCode |= 4; + } + if (badKeyUsage || badExtendedKeyUsage || badNetscapeCertType) { + exitCode |= 8; + } + if (hasUnsignedEntry) { + exitCode |= 16; + } + if (notSignedByAlias || aliasNotInStore) { + exitCode |= 32; + } + if (exitCode != 0) { + System.exit(exitCode); + } + } } /* @@ -247,25 +287,26 @@ public class JarSigner { /* parse flags */ int n = 0; - for (n=0; (n < args.length) && args[n].startsWith("-"); n++) { + if (args.length == 0) fullusage(); + for (n=0; n < args.length; n++) { String flags = args[n]; if (collator.compare(flags, "-keystore") == 0) { - if (++n == args.length) usage(); + if (++n == args.length) usageNoArg(); keystore = args[n]; } else if (collator.compare(flags, "-storepass") ==0) { - if (++n == args.length) usage(); + if (++n == args.length) usageNoArg(); storepass = args[n].toCharArray(); } else if (collator.compare(flags, "-storetype") ==0) { - if (++n == args.length) usage(); + if (++n == args.length) usageNoArg(); storetype = args[n]; } else if (collator.compare(flags, "-providerName") ==0) { - if (++n == args.length) usage(); + if (++n == args.length) usageNoArg(); providerName = args[n]; } else if ((collator.compare(flags, "-provider") == 0) || (collator.compare(flags, "-providerClass") == 0)) { - if (++n == args.length) usage(); + if (++n == args.length) usageNoArg(); if (providers == null) { providers = new Vector<String>(3); } @@ -274,35 +315,38 @@ public class JarSigner { if (args.length > (n+1)) { flags = args[n+1]; if (collator.compare(flags, "-providerArg") == 0) { - if (args.length == (n+2)) usage(); + if (args.length == (n+2)) usageNoArg(); providerArgs.put(args[n], args[n+2]); n += 2; } } } else if (collator.compare(flags, "-protected") ==0) { protectedPath = true; + } else if (collator.compare(flags, "-certchain") ==0) { + if (++n == args.length) usageNoArg(); + altCertChain = args[n]; } else if (collator.compare(flags, "-debug") ==0) { debug = true; } else if (collator.compare(flags, "-keypass") ==0) { - if (++n == args.length) usage(); + if (++n == args.length) usageNoArg(); keypass = args[n].toCharArray(); } else if (collator.compare(flags, "-sigfile") ==0) { - if (++n == args.length) usage(); + if (++n == args.length) usageNoArg(); sigfile = args[n]; } else if (collator.compare(flags, "-signedjar") ==0) { - if (++n == args.length) usage(); + if (++n == args.length) usageNoArg(); signedjar = args[n]; } else if (collator.compare(flags, "-tsa") ==0) { - if (++n == args.length) usage(); + if (++n == args.length) usageNoArg(); tsaUrl = args[n]; } else if (collator.compare(flags, "-tsacert") ==0) { - if (++n == args.length) usage(); + if (++n == args.length) usageNoArg(); tsaAlias = args[n]; } else if (collator.compare(flags, "-altsigner") ==0) { - if (++n == args.length) usage(); + if (++n == args.length) usageNoArg(); altSignerClass = args[n]; } else if (collator.compare(flags, "-altsignerpath") ==0) { - if (++n == args.length) usage(); + if (++n == args.length) usageNoArg(); altSignerClasspath = args[n]; } else if (collator.compare(flags, "-sectionsonly") ==0) { signManifest = false; @@ -311,30 +355,56 @@ public class JarSigner { } else if (collator.compare(flags, "-verify") ==0) { verify = true; } else if (collator.compare(flags, "-verbose") ==0) { - verbose = true; + verbose = "all"; + } else if (collator.compare(flags, "-verbose:all") ==0) { + verbose = "all"; + } else if (collator.compare(flags, "-verbose:summary") ==0) { + verbose = "summary"; + } else if (collator.compare(flags, "-verbose:grouped") ==0) { + verbose = "grouped"; } else if (collator.compare(flags, "-sigalg") ==0) { - if (++n == args.length) usage(); + if (++n == args.length) usageNoArg(); sigalg = args[n]; } else if (collator.compare(flags, "-digestalg") ==0) { - if (++n == args.length) usage(); + if (++n == args.length) usageNoArg(); digestalg = args[n]; } else if (collator.compare(flags, "-certs") ==0) { showcerts = true; + } else if (collator.compare(flags, "-strict") ==0) { + strict = true; } else if (collator.compare(flags, "-h") == 0 || collator.compare(flags, "-help") == 0) { - usage(); + fullusage(); } else { - System.err.println(rb.getString("Illegal option: ") + flags); - usage(); + if (!flags.startsWith("-")) { + if (jarfile == null) { + jarfile = flags; + } else { + alias = flags; + ckaliases.add(alias); + } + } else { + System.err.println( + rb.getString("Illegal option: ") + flags); + usage(); + } } } - if (n == args.length) usage(); - jarfile = args[n++]; + // -certs must always be specified with -verbose + if (verbose == null) showcerts = false; - if (!verify) { - if (n == args.length) usage(); - alias = args[n++]; + if (jarfile == null) { + System.err.println(rb.getString("Please specify jarfile name")); + usage(); + } + if (!verify && alias == null) { + System.err.println(rb.getString("Please specify alias name")); + usage(); + } + if (!verify && ckaliases.size() > 1) { + System.err.println(rb.getString("Only one alias can be specified")); + usage(); } if (storetype == null) { @@ -357,7 +427,6 @@ public class JarSigner { if (token && !nullStream) { System.err.println(MessageFormat.format(rb.getString ("-keystore must be NONE if -storetype is {0}"), storetype)); - System.err.println(); usage(); } @@ -365,7 +434,6 @@ public class JarSigner { System.err.println(MessageFormat.format(rb.getString ("-keypass can not be specified " + "if -storetype is {0}"), storetype)); - System.err.println(); usage(); } @@ -374,7 +442,6 @@ public class JarSigner { System.err.println(rb.getString ("If -protected is specified, " + "then -storepass and -keypass must not be specified")); - System.err.println(); usage(); } } @@ -383,17 +450,27 @@ public class JarSigner { System.err.println(rb.getString ("If keystore is not password protected, " + "then -storepass and -keypass must not be specified")); - System.err.println(); usage(); } } } + void usageNoArg() { + System.out.println(rb.getString("Option lacks argument")); + usage(); + } + void usage() { + System.out.println(); + System.out.println(rb.getString("Please type jarsigner -help for usage")); + System.exit(1); + } + + void fullusage() { System.out.println(rb.getString ("Usage: jarsigner [options] jar-file alias")); System.out.println(rb.getString - (" jarsigner -verify [options] jar-file")); + (" jarsigner -verify [options] jar-file [alias...]")); System.out.println(); System.out.println(rb.getString ("[-keystore <url>] keystore location")); @@ -407,6 +484,9 @@ public class JarSigner { System.out.println(rb.getString ("[-keypass <password>] password for private key (if different)")); System.out.println(); + System.out.println(rb.getString + ("[-certchain <file>] name of alternative certchain file")); + System.out.println(); System.out.println(rb.getString ("[-sigfile <file>] name of .SF/.DSA file")); System.out.println(); @@ -423,7 +503,9 @@ public class JarSigner { ("[-verify] verify a signed JAR file")); System.out.println(); System.out.println(rb.getString - ("[-verbose] verbose output when signing/verifying")); + ("[-verbose[:suboptions]] verbose output when signing/verifying.")); + System.out.println(rb.getString + (" suboptions can be all, grouped or summary")); System.out.println(); System.out.println(rb.getString ("[-certs] display certificates when verbose and verifying")); @@ -457,15 +539,17 @@ public class JarSigner { System.out.println(rb.getString (" [-providerArg <arg>]] ... master class file and constructor argument")); System.out.println(); + System.out.println(rb.getString + ("[-strict] treat warnings as errors")); + System.out.println(); - System.exit(1); + System.exit(0); } void verifyJar(String jarName) throws Exception { - boolean anySigned = false; - boolean hasUnsignedEntry = false; + boolean anySigned = false; // if there exists entry inside jar signed JarFile jf = null; try { @@ -494,11 +578,18 @@ public class JarSigner { Manifest man = jf.getManifest(); + // The map to record display info, only used when -verbose provided + // key: signer info string + // value: the list of files with common key + Map<String,List<String>> output = + new LinkedHashMap<String,List<String>>(); + if (man != null) { - if (verbose) System.out.println(); + if (verbose != null) System.out.println(); Enumeration<JarEntry> e = entriesVec.elements(); long now = System.currentTimeMillis(); + String tab = rb.getString(" "); while (e.hasMoreElements()) { JarEntry je = e.nextElement(); @@ -509,77 +600,118 @@ public class JarSigner { hasUnsignedEntry |= !je.isDirectory() && !isSigned && !signatureRelated(name); - if (verbose) { - int inStoreOrScope = inKeyStore(signers); - boolean inStore = (inStoreOrScope & IN_KEYSTORE) != 0; - boolean inScope = (inStoreOrScope & IN_SCOPE) != 0; + int inStoreOrScope = inKeyStore(signers); + + boolean inStore = (inStoreOrScope & IN_KEYSTORE) != 0; + boolean inScope = (inStoreOrScope & IN_SCOPE) != 0; + + notSignedByAlias |= (inStoreOrScope & NOT_ALIAS) != 0; + aliasNotInStore |= isSigned && (!inStore && !inScope); + + // Only used when -verbose provided + StringBuffer sb = null; + if (verbose != null) { + sb = new StringBuffer(); boolean inManifest = ((man.getAttributes(name) != null) || (man.getAttributes("./"+name) != null) || (man.getAttributes("/"+name) != null)); - System.out.print( + sb.append( (isSigned ? rb.getString("s") : rb.getString(" ")) + (inManifest ? rb.getString("m") : rb.getString(" ")) + (inStore ? rb.getString("k") : rb.getString(" ")) + (inScope ? rb.getString("i") : rb.getString(" ")) + - rb.getString(" ")); - StringBuffer sb = new StringBuffer(); + ((inStoreOrScope & NOT_ALIAS) != 0 ?"X":" ") + + rb.getString(" ")); + sb.append("|"); + } + + // When -certs provided, display info has extra empty + // lines at the beginning and end. + if (isSigned) { + if (showcerts) sb.append('\n'); + for (CodeSigner signer: signers) { + // signerInfo() must be called even if -verbose + // not provided. The method updates various + // warning flags. + String si = signerInfo(signer, tab, now); + if (showcerts) { + sb.append(si); + sb.append('\n'); + } + } + } else if (showcerts && !verbose.equals("all")) { + // Print no info for unsigned entries when -verbose:all, + // to be consistent with old behavior. + if (signatureRelated(name)) { + sb.append("\n" + tab + rb.getString( + "(Signature related entries)") + "\n\n"); + } else { + sb.append("\n" + tab + rb.getString( + "(Unsigned entries)") + "\n\n"); + } + } + + if (verbose != null) { + String label = sb.toString(); + if (signatureRelated(name)) { + // Entries inside META-INF and other unsigned + // entries are grouped separately. + label = "-" + label.substring(1); + } + + // The label finally contains 2 parts separated by '|': + // The legend displayed before the entry names, and + // the cert info (if -certs specfied). + + if (!output.containsKey(label)) { + output.put(label, new ArrayList<String>()); + } + + StringBuffer fb = new StringBuffer(); String s = Long.toString(je.getSize()); for (int i = 6 - s.length(); i > 0; --i) { - sb.append(' '); - } - sb.append(s).append(' '). - append(new Date(je.getTime()).toString()); - sb.append(' ').append(je.getName()); - System.out.println(sb.toString()); - - if (signers != null && showcerts) { - String tab = rb.getString(" "); - for (int i = 0; i < signers.length; i++) { - System.out.println(); - List<? extends Certificate> certs = - signers[i].getSignerCertPath() - .getCertificates(); - // display the signature timestamp, if present - Timestamp timestamp = signers[i].getTimestamp(); - if (timestamp != null) { - System.out.println( - printTimestamp(tab, timestamp)); - } - // display the certificate(s) - for (Certificate c : certs) { - System.out.println( - printCert(tab, c, true, now)); - } - } - System.out.println(); + fb.append(' '); } + fb.append(s).append(' '). + append(new Date(je.getTime()).toString()); + fb.append(' ').append(name); + output.get(label).add(fb.toString()); } - if (isSigned) { - for (int i = 0; i < signers.length; i++) { - Certificate cert = - signers[i].getSignerCertPath() - .getCertificates().get(0); - if (cert instanceof X509Certificate) { - checkCertUsage((X509Certificate)cert, null); - if (!showcerts) { - long notAfter = ((X509Certificate)cert) - .getNotAfter().getTime(); - - if (notAfter < now) { - hasExpiredCert = true; - } else if (notAfter < now + SIX_MONTHS) { - hasExpiringCert = true; - } - } + } + } + if (verbose != null) { + for (Entry<String,List<String>> s: output.entrySet()) { + List<String> files = s.getValue(); + String key = s.getKey(); + if (key.charAt(0) == '-') { // the signature-related group + key = ' ' + key.substring(1); + } + int pipe = key.indexOf('|'); + if (verbose.equals("all")) { + for (String f: files) { + System.out.println(key.substring(0, pipe) + f); + System.out.printf(key.substring(pipe+1)); + } + } else { + if (verbose.equals("grouped")) { + for (String f: files) { + System.out.println(key.substring(0, pipe) + f); + } + } else if (verbose.equals("summary")) { + System.out.print(key.substring(0, pipe)); + if (files.size() > 1) { + System.out.println(files.get(0) + " " + + String.format(rb.getString( + "(and %d more)"), files.size()-1)); + } else { + System.out.println(files.get(0)); } } + System.out.printf(key.substring(pipe+1)); } - } - } - if (verbose) { System.out.println(); System.out.println(rb.getString( " s = signature was verified ")); @@ -589,9 +721,12 @@ public class JarSigner { " k = at least one certificate was found in keystore")); System.out.println(rb.getString( " i = at least one certificate was found in identity scope")); + if (ckaliases.size() > 0) { + System.out.println(( + " X = not signed by specified alias(es)")); + } System.out.println(); } - if (man == null) System.out.println(rb.getString("no manifest.")); @@ -602,7 +737,8 @@ public class JarSigner { System.out.println(rb.getString("jar verified.")); if (hasUnsignedEntry || hasExpiredCert || hasExpiringCert || badKeyUsage || badExtendedKeyUsage || badNetscapeCertType || - notYetValidCert) { + notYetValidCert || chainNotValidated || + aliasNotInStore || notSignedByAlias) { System.out.println(); System.out.println(rb.getString("Warning: ")); @@ -638,14 +774,27 @@ public class JarSigner { "This jar contains entries whose signer certificate is not yet valid. ")); } - if (! (verbose && showcerts)) { + if (chainNotValidated) { + System.out.println( + rb.getString("This jar contains entries whose certificate chain is not validated.")); + } + + if (notSignedByAlias) { + System.out.println( + rb.getString("This jar contains signed entries which is not signed by the specified alias(es).")); + } + + if (aliasNotInStore) { + System.out.println(rb.getString("This jar contains signed entries that's not signed by alias in this keystore.")); + } + if (! (verbose != null && showcerts)) { System.out.println(); System.out.println(rb.getString( "Re-run with the -verbose and -certs options for more details.")); } } } - System.exit(0); + return; } catch (Exception e) { System.out.println(rb.getString("jarsigner: ") + e); if (debug) { @@ -660,15 +809,6 @@ public class JarSigner { System.exit(1); } - /* - * Display some details about a certificate: - * - * <cert-type> [", " <subject-DN>] [" (" <keystore-entry-alias> ")"] - */ - String printCert(Certificate c) { - return printCert("", c, false, 0); - } - private static MessageFormat validityTimeForm = null; private static MessageFormat notYetTimeForm = null; private static MessageFormat expiredTimeForm = null; @@ -679,6 +819,8 @@ public class JarSigner { * * [<tab>] <cert-type> [", " <subject-DN>] [" (" <keystore-entry-alias> ")"] * [<validity-period> | <expiry-warning>] + * + * Note: no newline character at the end */ String printCert(String tab, Certificate c, boolean checkValidityPeriod, long now) { @@ -788,54 +930,75 @@ public class JarSigner { .append(signTimeForm.format(source)).append("]").toString(); } + private Map<CodeSigner,Integer> cacheForInKS = + new IdentityHashMap<CodeSigner,Integer>(); + + private int inKeyStoreForOneSigner(CodeSigner signer) { + if (cacheForInKS.containsKey(signer)) { + return cacheForInKS.get(signer); + } + + boolean found = false; + int result = 0; + List<? extends Certificate> certs = signer.getSignerCertPath().getCertificates(); + for (Certificate c : certs) { + String alias = storeHash.get(c); + if (alias != null) { + if (alias.startsWith("(")) { + result |= IN_KEYSTORE; + } else if (alias.startsWith("[")) { + result |= IN_SCOPE; + } + if (ckaliases.contains(alias.substring(1, alias.length() - 1))) { + result |= SIGNED_BY_ALIAS; + } + } else { + if (store != null) { + try { + alias = store.getCertificateAlias(c); + } catch (KeyStoreException kse) { + // never happens, because keystore has been loaded + } + if (alias != null) { + storeHash.put(c, "(" + alias + ")"); + found = true; + result |= IN_KEYSTORE; + } + } + if (!found && (scope != null)) { + Identity id = scope.getIdentity(c.getPublicKey()); + if (id != null) { + result |= IN_SCOPE; + storeHash.put(c, "[" + id.getName() + "]"); + } + } + if (ckaliases.contains(alias)) { + result |= SIGNED_BY_ALIAS; + } + } + } + cacheForInKS.put(signer, result); + return result; + } + Hashtable<Certificate, String> storeHash = new Hashtable<Certificate, String>(); int inKeyStore(CodeSigner[] signers) { - int result = 0; if (signers == null) return 0; - boolean found = false; - - for (int i = 0; i < signers.length; i++) { - found = false; - List<? extends Certificate> certs = - signers[i].getSignerCertPath().getCertificates(); + int output = 0; - for (Certificate c : certs) { - String alias = storeHash.get(c); - - if (alias != null) { - if (alias.startsWith("(")) - result |= IN_KEYSTORE; - else if (alias.startsWith("[")) - result |= IN_SCOPE; - } else { - if (store != null) { - try { - alias = store.getCertificateAlias(c); - } catch (KeyStoreException kse) { - // never happens, because keystore has been loaded - } - if (alias != null) { - storeHash.put(c, "("+alias+")"); - found = true; - result |= IN_KEYSTORE; - } - } - if (!found && (scope != null)) { - Identity id = scope.getIdentity(c.getPublicKey()); - if (id != null) { - result |= IN_SCOPE; - storeHash.put(c, "["+id.getName()+"]"); - } - } - } - } + for (CodeSigner signer: signers) { + int result = inKeyStoreForOneSigner(signer); + output |= result; } - return result; + if (ckaliases.size() > 0 && (output & SIGNED_BY_ALIAS) == 0) { + output |= NOT_ALIAS; + } + return output; } void signJar(String jarName, String alias, String[] args) @@ -1025,7 +1188,7 @@ public class JarSigner { // manifest file has new length mfFile = new ZipEntry(JarFile.MANIFEST_NAME); } - if (verbose) { + if (verbose != null) { if (mfCreated) { System.out.println(rb.getString(" adding: ") + mfFile.getName()); @@ -1076,7 +1239,7 @@ public class JarSigner { // signature file zos.putNextEntry(sfFile); sf.write(zos); - if (verbose) { + if (verbose != null) { if (zipFile.getEntry(sfFilename) != null) { System.out.println(rb.getString(" updating: ") + sfFilename); @@ -1086,7 +1249,7 @@ public class JarSigner { } } - if (verbose) { + if (verbose != null) { if (tsaUrl != null || tsaCert != null) { System.out.println( rb.getString("requesting a signature timestamp")); @@ -1101,8 +1264,8 @@ public class JarSigner { System.out.println(rb.getString("TSA location: ") + certUrl); } - System.out.println( - rb.getString("TSA certificate: ") + printCert(tsaCert)); + System.out.println(rb.getString("TSA certificate: ") + + printCert("", tsaCert, false, 0)); } if (signingMechanism != null) { System.out.println( @@ -1113,7 +1276,7 @@ public class JarSigner { // signature block file zos.putNextEntry(bkFile); block.write(zos); - if (verbose) { + if (verbose != null) { if (zipFile.getEntry(bkFilename) != null) { System.out.println(rb.getString(" updating: ") + bkFilename); @@ -1140,7 +1303,7 @@ public class JarSigner { ZipEntry ze = enum_.nextElement(); if (!ze.getName().startsWith(META_INF)) { - if (verbose) { + if (verbose != null) { if (manifest.getAttributes(ze.getName()) != null) System.out.println(rb.getString(" signing: ") + ze.getName()); @@ -1194,7 +1357,8 @@ public class JarSigner { } if (hasExpiredCert || hasExpiringCert || notYetValidCert - || badKeyUsage || badExtendedKeyUsage || badNetscapeCertType) { + || badKeyUsage || badExtendedKeyUsage + || badNetscapeCertType || chainNotValidated) { System.out.println(); System.out.println(rb.getString("Warning: ")); @@ -1223,6 +1387,11 @@ public class JarSigner { System.out.println( rb.getString("The signer certificate is not yet valid.")); } + + if (chainNotValidated) { + System.out.println( + rb.getString("The signer's certificate chain is not validated.")); + } } // no IOException thrown in the above try clause, so disable @@ -1274,6 +1443,40 @@ public class JarSigner { return false; } + Map<CodeSigner,String> cacheForSignerInfo = new IdentityHashMap<CodeSigner,String>(); + + /** + * Returns a string of singer info, with a newline at the end + */ + private String signerInfo(CodeSigner signer, String tab, long now) { + if (cacheForSignerInfo.containsKey(signer)) { + return cacheForSignerInfo.get(signer); + } + StringBuffer s = new StringBuffer(); + List<? extends Certificate> certs = signer.getSignerCertPath().getCertificates(); + // display the signature timestamp, if present + Timestamp timestamp = signer.getTimestamp(); + if (timestamp != null) { + s.append(printTimestamp(tab, timestamp)); + } + // display the certificate(s) + for (Certificate c : certs) { + s.append(printCert(tab, c, true, now)); + s.append('\n'); + } + try { + CertPath cp = certificateFactory.generateCertPath(certs); + validator.validate(cp, pkixParameters); + } catch (Exception e) { + chainNotValidated = true; + s.append(tab + rb.getString("[CertPath not validated: ") + + e.getLocalizedMessage() + "]\n"); // TODO + } + String result = s.toString(); + cacheForSignerInfo.put(signer, result); + return result; + } + private void writeEntry(ZipFile zf, ZipOutputStream os, ZipEntry ze) throws IOException { @@ -1360,6 +1563,48 @@ public class JarSigner { } } } + Set<TrustAnchor> tas = new HashSet<TrustAnchor>(); + try { + KeyStore caks = KeyTool.getCacertsKeyStore(); + if (caks != null) { + Enumeration<String> aliases = caks.aliases(); + while (aliases.hasMoreElements()) { + String a = aliases.nextElement(); + try { + tas.add(new TrustAnchor((X509Certificate)caks.getCertificate(a), null)); + } catch (Exception e2) { + // ignore, when a SecretkeyEntry does not include a cert + } + } + } + } catch (Exception e) { + // Ignore, if cacerts cannot be loaded + } + if (store != null) { + Enumeration<String> aliases = store.aliases(); + while (aliases.hasMoreElements()) { + String a = aliases.nextElement(); + try { + X509Certificate c = (X509Certificate)store.getCertificate(a); + // Only add TrustedCertificateEntry and self-signed + // PrivateKeyEntry + if (store.isCertificateEntry(a) || + c.getSubjectDN().equals(c.getIssuerDN())) { + tas.add(new TrustAnchor(c, null)); + } + } catch (Exception e2) { + // ignore, when a SecretkeyEntry does not include a cert + } + } + } + certificateFactory = CertificateFactory.getInstance("X.509"); + validator = CertPathValidator.getInstance("PKIX"); + try { + pkixParameters = new PKIXParameters(tas); + pkixParameters.setRevocationEnabled(false); + } catch (InvalidAlgorithmParameterException ex) { + // Only if tas is empty + } } catch (IOException ioe) { throw new RuntimeException(rb.getString("keystore load: ") + ioe.getMessage()); @@ -1408,7 +1653,8 @@ public class JarSigner { void checkCertUsage(X509Certificate userCert, boolean[] bad) { // Can act as a signer? - // 1. if KeyUsage, then [0] should be true + // 1. if KeyUsage, then [0:digitalSignature] or + // [1:nonRepudiation] should be true // 2. if ExtendedKeyUsage, then should contains ANY or CODE_SIGNING // 3. if NetscapeCertType, then should contains OBJECT_SIGNING // 1,2,3 must be true @@ -1419,10 +1665,10 @@ public class JarSigner { boolean[] keyUsage = userCert.getKeyUsage(); if (keyUsage != null) { - if (keyUsage.length < 1 || !keyUsage[0]) { + keyUsage = Arrays.copyOf(keyUsage, 9); + if (!keyUsage[0] && !keyUsage[1]) { if (bad != null) { bad[0] = true; - } else { badKeyUsage = true; } } @@ -1435,7 +1681,6 @@ public class JarSigner { && !xKeyUsage.contains("1.3.6.1.5.5.7.3.3")) { // codeSigning if (bad != null) { bad[1] = true; - } else { badExtendedKeyUsage = true; } } @@ -1462,7 +1707,6 @@ public class JarSigner { if (!val) { if (bad != null) { bad[2] = true; - } else { badNetscapeCertType = true; } } @@ -1477,19 +1721,36 @@ public class JarSigner { Key key = null; try { - java.security.cert.Certificate[] cs = null; - - try { - cs = store.getCertificateChain(alias); - } catch (KeyStoreException kse) { - // this never happens, because keystore has been loaded + if (altCertChain != null) { + try { + cs = CertificateFactory.getInstance("X.509"). + generateCertificates(new FileInputStream(altCertChain)). + toArray(new Certificate[0]); + } catch (CertificateException ex) { + error(rb.getString("Cannot restore certchain from file specified")); + } catch (FileNotFoundException ex) { + error(rb.getString("File specified by -certchain does not exist")); + } + } else { + try { + cs = store.getCertificateChain(alias); + } catch (KeyStoreException kse) { + // this never happens, because keystore has been loaded + } } - if (cs == null) { - MessageFormat form = new MessageFormat(rb.getString - ("Certificate chain not found for: alias. alias must reference a valid KeyStore key entry containing a private key and corresponding public key certificate chain.")); - Object[] source = {alias, alias}; - error(form.format(source)); + if (cs == null || cs.length == 0) { + if (altCertChain != null) { + error(rb.getString + ("Certificate chain not found in the file specified.")); + } else { + MessageFormat form = new MessageFormat(rb.getString + ("Certificate chain not found for: alias. alias must" + + " reference a valid KeyStore key entry containing a" + + " private key and corresponding public key certificate chain.")); + Object[] source = {alias, alias}; + error(form.format(source)); + } } certChain = new X509Certificate[cs.length]; @@ -1501,56 +1762,15 @@ public class JarSigner { certChain[i] = (X509Certificate)cs[i]; } - // order the cert chain if necessary (put user cert first, - // root-cert last in the chain) - X509Certificate userCert - = (X509Certificate)store.getCertificate(alias); + // We don't meant to print anything, the next call + // checks validity and keyUsage etc + printCert("", certChain[0], true, 0); - // check validity of signer certificate try { - userCert.checkValidity(); - - if (userCert.getNotAfter().getTime() < - System.currentTimeMillis() + SIX_MONTHS) { - - hasExpiringCert = true; - } - } catch (CertificateExpiredException cee) { - hasExpiredCert = true; - - } catch (CertificateNotYetValidException cnyve) { - notYetValidCert = true; - } - - checkCertUsage(userCert, null); - - if (!userCert.equals(certChain[0])) { - // need to order ... - X509Certificate[] certChainTmp - = new X509Certificate[certChain.length]; - certChainTmp[0] = userCert; - Principal issuer = userCert.getIssuerDN(); - for (int i=1; i<certChain.length; i++) { - int j; - // look for the cert whose subject corresponds to the - // given issuer - for (j=0; j<certChainTmp.length; j++) { - if (certChainTmp[j] == null) - continue; - Principal subject = certChainTmp[j].getSubjectDN(); - if (issuer.equals(subject)) { - certChain[i] = certChainTmp[j]; - issuer = certChainTmp[j].getIssuerDN(); - certChainTmp[j] = null; - break; - } - } - if (j == certChainTmp.length) { - error(rb.getString("incomplete certificate chain")); - } - - } - certChain = certChainTmp; // ordered + CertPath cp = certificateFactory.generateCertPath(Arrays.asList(certChain)); + validator.validate(cp, pkixParameters); + } catch (Exception e) { + chainNotValidated = true; } try { diff --git a/src/share/classes/sun/security/tools/JarSignerResources.java b/src/share/classes/sun/security/tools/JarSignerResources.java index 473ea3b035d970adbc018f5da5d5e99c4ea7b490..7e259e8e8fec3731652a223307730197a9fc6c12 100644 --- a/src/share/classes/sun/security/tools/JarSignerResources.java +++ b/src/share/classes/sun/security/tools/JarSignerResources.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2005 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. * * This code is free software; you can redistribute it and/or modify it @@ -54,8 +54,8 @@ public class JarSignerResources extends java.util.ListResourceBundle { "If keystore is not password protected, then -storepass and -keypass must not be specified"}, {"Usage: jarsigner [options] jar-file alias", "Usage: jarsigner [options] jar-file alias"}, - {" jarsigner -verify [options] jar-file", - " jarsigner -verify [options] jar-file"}, + {" jarsigner -verify [options] jar-file [alias...]", + " jarsigner -verify [options] jar-file [alias...]"}, {"[-keystore <url>] keystore location", "[-keystore <url>] keystore location"}, {"[-storepass <password>] password for keystore integrity", @@ -64,6 +64,8 @@ public class JarSignerResources extends java.util.ListResourceBundle { "[-storetype <type>] keystore type"}, {"[-keypass <password>] password for private key (if different)", "[-keypass <password>] password for private key (if different)"}, + {"[-certchain <file>] name of alternative certchain file", + "[-certchain <file>] name of alternative certchain file"}, {"[-sigfile <file>] name of .SF/.DSA file", "[-sigfile <file>] name of .SF/.DSA file"}, {"[-signedjar <file>] name of signed JAR file", @@ -74,8 +76,10 @@ public class JarSignerResources extends java.util.ListResourceBundle { "[-sigalg <algorithm>] name of signature algorithm"}, {"[-verify] verify a signed JAR file", "[-verify] verify a signed JAR file"}, - {"[-verbose] verbose output when signing/verifying", - "[-verbose] verbose output when signing/verifying"}, + {"[-verbose[:suboptions]] verbose output when signing/verifying.", + "[-verbose[:suboptions]] verbose output when signing/verifying."}, + {" suboptions can be all, grouped or summary", + " suboptions can be all, grouped or summary"}, {"[-certs] display certificates when verbose and verifying", "[-certs] display certificates when verbose and verifying"}, {"[-tsa <url>] location of the Timestamping Authority", @@ -98,10 +102,22 @@ public class JarSignerResources extends java.util.ListResourceBundle { "[-providerClass <class> name of cryptographic service provider's"}, {" [-providerArg <arg>]] ... master class file and constructor argument", " [-providerArg <arg>]] ... master class file and constructor argument"}, + {"[-strict] treat warnings as errors", + "[-strict] treat warnings as errors"}, + {"Option lacks argument", "Option lacks argument"}, + {"Please type jarsigner -help for usage", "Please type jarsigner -help for usage"}, + {"Please specify jarfile name", "Please specify jarfile name"}, + {"Please specify alias name", "Please specify alias name"}, + {"Only one alias can be specified", "Only one alias can be specified"}, + {"This jar contains signed entries which is not signed by the specified alias(es).", + "This jar contains signed entries which is not signed by the specified alias(es)."}, + {"This jar contains signed entries that's not signed by alias in this keystore.", + "This jar contains signed entries that's not signed by alias in this keystore."}, {"s", "s"}, {"m", "m"}, {"k", "k"}, {"i", "i"}, + {"(and %d more)", "(and %d more)"}, {" s = signature was verified ", " s = signature was verified "}, {" m = entry is listed in manifest", @@ -110,7 +126,11 @@ public class JarSignerResources extends java.util.ListResourceBundle { " k = at least one certificate was found in keystore"}, {" i = at least one certificate was found in identity scope", " i = at least one certificate was found in identity scope"}, + {" X = not signed by specified alias(es)", + " X = not signed by specified alias(es)"}, {"no manifest.", "no manifest."}, + {"(Signature related entries)","(Signature related entries)"}, + {"(Unsigned entries)", "(Unsigned entries)"}, {"jar is unsigned. (signatures missing or not parsable)", "jar is unsigned. (signatures missing or not parsable)"}, {"jar verified.", "jar verified."}, @@ -134,6 +154,12 @@ public class JarSignerResources extends java.util.ListResourceBundle { "unable to instantiate keystore class: "}, {"Certificate chain not found for: alias. alias must reference a valid KeyStore key entry containing a private key and corresponding public key certificate chain.", "Certificate chain not found for: {0}. {1} must reference a valid KeyStore key entry containing a private key and corresponding public key certificate chain."}, + {"File specified by -certchain does not exist", + "File specified by -certchain does not exist"}, + {"Cannot restore certchain from file specified", + "Cannot restore certchain from file specified"}, + {"Certificate chain not found in the file specified.", + "Certificate chain not found in the file specified."}, {"found non-X.509 certificate in signer's chain", "found non-X.509 certificate in signer's chain"}, {"incomplete certificate chain", "incomplete certificate chain"}, @@ -149,6 +175,7 @@ public class JarSignerResources extends java.util.ListResourceBundle { {"certificate is not valid until", "certificate is not valid until {0}"}, {"certificate will expire on", "certificate will expire on {0}"}, + {"[CertPath not validated: ", "[CertPath not validated: "}, {"requesting a signature timestamp", "requesting a signature timestamp"}, {"TSA location: ", "TSA location: "}, @@ -189,14 +216,18 @@ public class JarSignerResources extends java.util.ListResourceBundle { "The signer certificate's ExtendedKeyUsage extension doesn't allow code signing."}, {"The signer certificate's NetscapeCertType extension doesn't allow code signing.", "The signer certificate's NetscapeCertType extension doesn't allow code signing."}, - {"This jar contains entries whose signer certificate's KeyUsage extension doesn't allow code signing.", - "This jar contains entries whose signer certificate's KeyUsage extension doesn't allow code signing."}, - {"This jar contains entries whose signer certificate's ExtendedKeyUsage extension doesn't allow code signing.", - "This jar contains entries whose signer certificate's ExtendedKeyUsage extension doesn't allow code signing."}, - {"This jar contains entries whose signer certificate's NetscapeCertType extension doesn't allow code signing.", - "This jar contains entries whose signer certificate's NetscapeCertType extension doesn't allow code signing."}, + {"This jar contains entries whose signer certificate's KeyUsage extension doesn't allow code signing.", + "This jar contains entries whose signer certificate's KeyUsage extension doesn't allow code signing."}, + {"This jar contains entries whose signer certificate's ExtendedKeyUsage extension doesn't allow code signing.", + "This jar contains entries whose signer certificate's ExtendedKeyUsage extension doesn't allow code signing."}, + {"This jar contains entries whose signer certificate's NetscapeCertType extension doesn't allow code signing.", + "This jar contains entries whose signer certificate's NetscapeCertType extension doesn't allow code signing."}, {"[{0} extension does not support code signing]", "[{0} extension does not support code signing]"}, + {"The signer's certificate chain is not validated.", + "The signer's certificate chain is not validated."}, + {"This jar contains entries whose certificate chain is not validated.", + "This jar contains entries whose certificate chain is not validated."}, }; /** diff --git a/src/share/classes/sun/security/tools/KeyTool.java b/src/share/classes/sun/security/tools/KeyTool.java index 220dbd033b1f5e0ff69399d7fb52613fbb3f36db..9b4b16fa11dacc7eab35d24bba9c3a5300ca9b85 100644 --- a/src/share/classes/sun/security/tools/KeyTool.java +++ b/src/share/classes/sun/security/tools/KeyTool.java @@ -1,5 +1,5 @@ /* - * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 1997-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 @@ -69,6 +69,10 @@ import javax.net.ssl.SSLContext; import javax.net.ssl.SSLSession; import javax.net.ssl.TrustManager; import javax.net.ssl.X509TrustManager; +import sun.misc.BASE64Decoder; +import sun.security.pkcs.PKCS10Attribute; +import sun.security.pkcs.PKCS9Attribute; +import sun.security.util.DerValue; import sun.security.x509.*; import static java.security.KeyStore.*; @@ -85,7 +89,6 @@ import static java.security.KeyStore.*; * * @since 1.2 */ - public final class KeyTool { private boolean debug = false; @@ -100,6 +103,8 @@ public final class KeyTool { private String dname = null; private String dest = null; private String filename = null; + private String infilename = null; + private String outfilename = null; private String srcksfname = null; // User-specified providers are added before any command is called. @@ -117,7 +122,6 @@ public final class KeyTool { private char[] storePassNew = null; private char[] keyPass = null; private char[] keyPassNew = null; - private char[] oldPass = null; private char[] newPass = null; private char[] destKeyPass = null; private char[] srckeyPass = null; @@ -140,6 +144,8 @@ public final class KeyTool { private Set<char[]> passwords = new HashSet<char[]> (); private String startDate = null; + private List <String> v3ext = new ArrayList <String> (); + private static final int CERTREQ = 1; private static final int CHANGEALIAS = 2; private static final int DELETE = 3; @@ -156,6 +162,8 @@ public final class KeyTool { private static final int PRINTCERT = 13; private static final int SELFCERT = 14; private static final int STOREPASSWD = 15; + private static final int GENCERT = 16; + private static final int PRINTCERTREQ = 17; private static final Class[] PARAM_STRING = { String.class }; @@ -184,7 +192,9 @@ public final class KeyTool { private void run(String[] args, PrintStream out) throws Exception { try { parseArgs(args); - doCommands(out); + if (command != -1) { + doCommands(out); + } } catch (Exception e) { System.out.println(rb.getString("keytool error: ") + e); if (verbose) { @@ -214,7 +224,10 @@ public final class KeyTool { */ void parseArgs(String[] args) { - if (args.length == 0) usage(); + if (args.length == 0) { + usage(); + return; + } int i=0; @@ -260,6 +273,10 @@ public final class KeyTool { command = IMPORTKEYSTORE; } else if (collator.compare(flags, "-genseckey") == 0) { command = GENSECKEY; + } else if (collator.compare(flags, "-gencert") == 0) { + command = GENCERT; + } else if (collator.compare(flags, "-printcertreq") == 0) { + command = PRINTCERTREQ; } /* @@ -337,9 +354,18 @@ public final class KeyTool { } else if (collator.compare(flags, "-validity") == 0) { if (++i == args.length) errorNeedArgument(flags); validity = Long.parseLong(args[i]); + } else if (collator.compare(flags, "-ext") == 0) { + if (++i == args.length) errorNeedArgument(flags); + v3ext.add(args[i]); } else if (collator.compare(flags, "-file") == 0) { if (++i == args.length) errorNeedArgument(flags); filename = args[i]; + } else if (collator.compare(flags, "-infile") == 0) { + if (++i == args.length) errorNeedArgument(flags); + infilename = args[i]; + } else if (collator.compare(flags, "-outfile") == 0) { + if (++i == args.length) errorNeedArgument(flags); + outfilename = args[i]; } else if (collator.compare(flags, "-sslserver") == 0) { if (++i == args.length) errorNeedArgument(flags); sslserver = args[i]; @@ -364,7 +390,7 @@ public final class KeyTool { } } providers.add( - new Pair<String, String>(providerClass, providerArg)); + Pair.of(providerClass, providerArg)); } /* @@ -404,6 +430,10 @@ public final class KeyTool { } } + boolean isKeyStoreRelated(int cmd) { + return cmd != PRINTCERT && cmd != PRINTCERTREQ; + } + /** * Execute the commands. */ @@ -568,7 +598,7 @@ public final class KeyTool { // the default, which is located in $HOME/.keystore. // If the command is "genkey", "identitydb", "import", or "printcert", // it is OK not to have a keystore. - if (command != PRINTCERT) { + if (isKeyStoreRelated(command)) { if (ksfname == null) { ksfname = System.getProperty("user.home") + File.separator + ".keystore"; @@ -721,7 +751,7 @@ public final class KeyTool { } } else if (!protectedPath && !KeyStoreUtil.isWindowsKeyStore(storetype) - && !(command == PRINTCERT)) { + && isKeyStoreRelated(command)) { // here we have EXPORTCERT and LIST (info valid until STOREPASSWD) System.err.print(rb.getString("Enter keystore password: ")); System.err.flush(); @@ -763,7 +793,7 @@ public final class KeyTool { // Create a certificate factory if (command == PRINTCERT || command == IMPORTCERT - || command == IDENTITYDB) { + || command == IDENTITYDB) { cf = CertificateFactory.getInstance("X509"); } @@ -845,6 +875,18 @@ public final class KeyTool { if (filename != null) { inStream = new FileInputStream(filename); } + // Read the full stream before feeding to X509Factory, + // otherwise, keytool -gencert | keytool -importcert + // might not work properly, since -gencert is slow + // and there's no data in the pipe at the beginning. + ByteArrayOutputStream bout = new ByteArrayOutputStream(); + byte[] b = new byte[4096]; + while (true) { + int len = inStream.read(b); + if (len < 0) break; + bout.write(b, 0, len); + } + inStream = new ByteArrayInputStream(bout.toByteArray()); try { String importAlias = (alias!=null)?alias:keyAlias; if (keyStore.entryInstanceOf(importAlias, KeyStore.PrivateKeyEntry.class)) { @@ -930,6 +972,41 @@ public final class KeyTool { storePassNew = getNewPasswd("keystore password", storePass); } kssave = true; + } else if (command == GENCERT) { + if (alias == null) { + alias = keyAlias; + } + InputStream inStream = System.in; + if (infilename != null) { + inStream = new FileInputStream(infilename); + } + PrintStream ps = null; + if (outfilename != null) { + ps = new PrintStream(new FileOutputStream(outfilename)); + out = ps; + } + try { + doGenCert(alias, sigAlgName, inStream, out); + } finally { + if (inStream != System.in) { + inStream.close(); + } + if (ps != null) { + ps.close(); + } + } + } else if (command == PRINTCERTREQ) { + InputStream inStream = System.in; + if (filename != null) { + inStream = new FileInputStream(filename); + } + try { + doPrintCertReq(inStream, out); + } finally { + if (inStream != System.in) { + inStream.close(); + } + } } // If we need to save the keystore, do so. @@ -961,6 +1038,91 @@ public final class KeyTool { } } + /** + * Generate a certificate: Read PKCS10 request from in, and print + * certificate to out. Use alias as CA, sigAlgName as the signature + * type. + */ + private void doGenCert(String alias, String sigAlgName, InputStream in, PrintStream out) + throws Exception { + + + Certificate signerCert = keyStore.getCertificate(alias); + byte[] encoded = signerCert.getEncoded(); + X509CertImpl signerCertImpl = new X509CertImpl(encoded); + X509CertInfo signerCertInfo = (X509CertInfo)signerCertImpl.get( + X509CertImpl.NAME + "." + X509CertImpl.INFO); + X500Name owner = (X500Name)signerCertInfo.get(X509CertInfo.SUBJECT + "." + + CertificateSubjectName.DN_NAME); + + Date firstDate = getStartDate(startDate); + Date lastDate = new Date(); + lastDate.setTime(firstDate.getTime() + validity*1000L*24L*60L*60L); + CertificateValidity interval = new CertificateValidity(firstDate, + lastDate); + + PrivateKey privateKey = (PrivateKey)recoverKey(alias, storePass, keyPass).fst; + if (sigAlgName == null) { + sigAlgName = getCompatibleSigAlgName(privateKey.getAlgorithm()); + } + Signature signature = Signature.getInstance(sigAlgName); + signature.initSign(privateKey); + + X500Signer signer = new X500Signer(signature, owner); + + X509CertInfo info = new X509CertInfo(); + info.set(X509CertInfo.VALIDITY, interval); + info.set(X509CertInfo.SERIAL_NUMBER, new CertificateSerialNumber( + new java.util.Random().nextInt() & 0x7fffffff)); + info.set(X509CertInfo.VERSION, + new CertificateVersion(CertificateVersion.V3)); + info.set(X509CertInfo.ALGORITHM_ID, + new CertificateAlgorithmId(signer.getAlgorithmId())); + info.set(X509CertInfo.ISSUER, + new CertificateIssuerName(signer.getSigner())); + + BufferedReader reader = new BufferedReader(new InputStreamReader(in)); + boolean canRead = false; + StringBuffer sb = new StringBuffer(); + while (true) { + String s = reader.readLine(); + if (s == null) break; + // OpenSSL does not use NEW + //if (s.startsWith("-----BEGIN NEW CERTIFICATE REQUEST-----")) { + if (s.startsWith("-----BEGIN") && s.indexOf("REQUEST") >= 0) { + canRead = true; + //} else if (s.startsWith("-----END NEW CERTIFICATE REQUEST-----")) { + } else if (s.startsWith("-----END") && s.indexOf("REQUEST") >= 0) { + break; + } else if (canRead) { + sb.append(s); + } + } + byte[] rawReq = new BASE64Decoder().decodeBuffer(new String(sb)); + PKCS10 req = new PKCS10(rawReq); + + info.set(X509CertInfo.KEY, new CertificateX509Key(req.getSubjectPublicKeyInfo())); + info.set(X509CertInfo.SUBJECT, new CertificateSubjectName(req.getSubjectName())); + CertificateExtensions reqex = null; + Iterator<PKCS10Attribute> attrs = req.getAttributes().getAttributes().iterator(); + while (attrs.hasNext()) { + PKCS10Attribute attr = attrs.next(); + if (attr.getAttributeId().equals(PKCS9Attribute.EXTENSION_REQUEST_OID)) { + reqex = (CertificateExtensions)attr.getAttributeValue(); + } + } + CertificateExtensions ext = createV3Extensions( + reqex, + null, + v3ext, + req.getSubjectPublicKeyInfo(), + signerCert.getPublicKey()); + info.set(X509CertInfo.EXTENSIONS, ext); + X509CertImpl cert = new X509CertImpl(info); + cert.sign(privateKey, sigAlgName); + dumpCert(cert, out); + } + /** * Creates a PKCS#10 cert signing request, corresponding to the * keys (and name) associated with a given alias. @@ -972,10 +1134,10 @@ public final class KeyTool { alias = keyAlias; } - Object[] objs = recoverKey(alias, storePass, keyPass); - PrivateKey privKey = (PrivateKey)objs[0]; + Pair<Key,char[]> objs = recoverKey(alias, storePass, keyPass); + PrivateKey privKey = (PrivateKey)objs.fst; if (keyPass == null) { - keyPass = (char[])objs[1]; + keyPass = objs.snd; } Certificate cert = keyStore.getCertificate(alias); @@ -986,21 +1148,14 @@ public final class KeyTool { throw new Exception(form.format(source)); } PKCS10 request = new PKCS10(cert.getPublicKey()); + CertificateExtensions ext = createV3Extensions(null, null, v3ext, cert.getPublicKey(), null); + // Attribute name is not significant + request.getAttributes().setAttribute(X509CertInfo.EXTENSIONS, + new PKCS10Attribute(PKCS9Attribute.EXTENSION_REQUEST_OID, ext)); // Construct an X500Signer object, so that we can sign the request if (sigAlgName == null) { - // If no signature algorithm was specified at the command line, - // we choose one that is compatible with the selected private key - String keyAlgName = privKey.getAlgorithm(); - if ("DSA".equalsIgnoreCase(keyAlgName) - || "DSS".equalsIgnoreCase(keyAlgName)) { - sigAlgName = "SHA1WithDSA"; - } else if ("RSA".equalsIgnoreCase(keyAlgName)) { - sigAlgName = "SHA1WithRSA"; - } else { - throw new Exception(rb.getString - ("Cannot derive signature algorithm")); - } + sigAlgName = getCompatibleSigAlgName(privKey.getAlgorithm()); } Signature signature = Signature.getInstance(sigAlgName); @@ -1152,6 +1307,23 @@ public final class KeyTool { keyStore.setKeyEntry(alias, secKey, keyPass, null); } + /** + * If no signature algorithm was specified at the command line, + * we choose one that is compatible with the selected private key + */ + private static String getCompatibleSigAlgName(String keyAlgName) + throws Exception { + if ("DSA".equalsIgnoreCase(keyAlgName)) { + return "SHA1WithDSA"; + } else if ("RSA".equalsIgnoreCase(keyAlgName)) { + return "SHA1WithRSA"; + } else if ("EC".equalsIgnoreCase(keyAlgName)) { + return "SHA1withECDSA"; + } else { + throw new Exception(rb.getString + ("Cannot derive signature algorithm")); + } + } /** * Creates a new key pair and self-signed certificate. */ @@ -1179,16 +1351,7 @@ public final class KeyTool { } if (sigAlgName == null) { - if ("DSA".equalsIgnoreCase(keyAlgName)) { - sigAlgName = "SHA1WithDSA"; - } else if ("RSA".equalsIgnoreCase(keyAlgName)) { - sigAlgName = "SHA1WithRSA"; - } else if ("EC".equalsIgnoreCase(keyAlgName)) { - sigAlgName = "SHA1withECDSA"; - } else { - throw new Exception(rb.getString - ("Cannot derive signature algorithm")); - } + sigAlgName = getCompatibleSigAlgName(keyAlgName); } CertAndKeyGen keypair = new CertAndKeyGen(keyAlgName, sigAlgName, providerName); @@ -1225,6 +1388,9 @@ public final class KeyTool { keyPass = promptForKeyPass(alias, null, storePass); } keyStore.setKeyEntry(alias, privKey, keyPass, chain); + + // resign so that -ext are applied. + doSelfCert(alias, null, sigAlgName); } /** @@ -1247,9 +1413,9 @@ public final class KeyTool { throw new Exception(form.format(source)); } - Object[] objs = recoverEntry(keyStore, orig, storePass, keyPass); - Entry entry = (Entry)objs[0]; - keyPass = (char[])objs[1]; + Pair<Entry,char[]> objs = recoverEntry(keyStore, orig, storePass, keyPass); + Entry entry = objs.fst; + keyPass = objs.snd; PasswordProtection pp = null; @@ -1275,10 +1441,10 @@ public final class KeyTool { if (alias == null) { alias = keyAlias; } - Object[] objs = recoverKey(alias, storePass, keyPass); - Key privKey = (Key)objs[0]; + Pair<Key,char[]> objs = recoverKey(alias, storePass, keyPass); + Key privKey = objs.fst; if (keyPass == null) { - keyPass = (char[])objs[1]; + keyPass = objs.snd; } if (keyPassNew == null) { @@ -1629,8 +1795,8 @@ public final class KeyTool { } } - Object[] objs = recoverEntry(srckeystore, alias, srcstorePass, srckeyPass); - Entry entry = (Entry)objs[0]; + Pair<Entry,char[]> objs = recoverEntry(srckeystore, alias, srcstorePass, srckeyPass); + Entry entry = objs.fst; PasswordProtection pp = null; @@ -1640,8 +1806,8 @@ public final class KeyTool { // so always try to protect with destKeyPass. if (destKeyPass != null) { pp = new PasswordProtection(destKeyPass); - } else if (objs[1] != null) { - pp = new PasswordProtection((char[])objs[1]); + } else if (objs.snd != null) { + pp = new PasswordProtection(objs.snd); } try { @@ -1726,9 +1892,52 @@ public final class KeyTool { } } + private void doPrintCertReq(InputStream in, PrintStream out) + throws Exception { + + BufferedReader reader = new BufferedReader(new InputStreamReader(in)); + StringBuffer sb = new StringBuffer(); + boolean started = false; + while (true) { + String s = reader.readLine(); + if (s == null) break; + if (!started) { + if (s.startsWith("-----")) { + started = true; + } + } else { + if (s.startsWith("-----")) { + break; + } + sb.append(s); + } + } + PKCS10 req = new PKCS10(new BASE64Decoder().decodeBuffer(new String(sb))); + + PublicKey pkey = req.getSubjectPublicKeyInfo(); + out.printf(rb.getString("PKCS #10 Certificate Request (Version 1.0)\n" + + "Subject: %s\nPublic Key: %s format %s key\n"), + req.getSubjectName(), pkey.getFormat(), pkey.getAlgorithm()); + for (PKCS10Attribute attr: req.getAttributes().getAttributes()) { + ObjectIdentifier oid = attr.getAttributeId(); + if (oid.equals(PKCS9Attribute.EXTENSION_REQUEST_OID)) { + CertificateExtensions exts = (CertificateExtensions)attr.getAttributeValue(); + if (exts != null) { + printExtensions(rb.getString("Extension Request:"), exts, out); + } + } else { + out.println(attr.getAttributeId()); + out.println(attr.getAttributeValue()); + } + } + if (debug) { + out.println(req); // Just to see more, say, public key length... + } + } + /** * Reads a certificate (or certificate chain) and prints its contents in - * a human readbable format. + * a human readable format. */ private void printCertFromStream(InputStream in, PrintStream out) throws Exception @@ -1840,7 +2049,18 @@ public final class KeyTool { inStream = new FileInputStream(filename); } try { - printCertFromStream(inStream, out); + // Read the full stream before feeding to X509Factory, + // otherwise, keytool -gencert | keytool -printcert + // might not work properly, since -gencert is slow + // and there's no data in the pipe at the beginning. + ByteArrayOutputStream bout = new ByteArrayOutputStream(); + byte[] b = new byte[4096]; + while (true) { + int len = inStream.read(b); + if (len < 0) break; + bout.write(b, 0, len); + } + printCertFromStream(new ByteArrayInputStream(bout.toByteArray()), out); } finally { if (inStream != System.in) { inStream.close(); @@ -1859,27 +2079,14 @@ public final class KeyTool { alias = keyAlias; } - Object[] objs = recoverKey(alias, storePass, keyPass); - PrivateKey privKey = (PrivateKey)objs[0]; + Pair<Key,char[]> objs = recoverKey(alias, storePass, keyPass); + PrivateKey privKey = (PrivateKey)objs.fst; if (keyPass == null) - keyPass = (char[])objs[1]; + keyPass = objs.snd; // Determine the signature algorithm if (sigAlgName == null) { - // If no signature algorithm was specified at the command line, - // we choose one that is compatible with the selected private key - String keyAlgName = privKey.getAlgorithm(); - if ("DSA".equalsIgnoreCase(keyAlgName) - || "DSS".equalsIgnoreCase(keyAlgName)) { - sigAlgName = "SHA1WithDSA"; - } else if ("RSA".equalsIgnoreCase(keyAlgName)) { - sigAlgName = "SHA1WithRSA"; - } else if ("EC".equalsIgnoreCase(keyAlgName)) { - sigAlgName = "SHA1withECDSA"; - } else { - throw new Exception - (rb.getString("Cannot derive signature algorithm")); - } + sigAlgName = getCompatibleSigAlgName(privKey.getAlgorithm()); } // Get the old certificate @@ -1914,8 +2121,8 @@ public final class KeyTool { certInfo.set(X509CertInfo.VALIDITY, interval); // Make new serial number - certInfo.set(X509CertInfo.SERIAL_NUMBER, new CertificateSerialNumber - ((int)(firstDate.getTime()/1000))); + certInfo.set(X509CertInfo.SERIAL_NUMBER, new CertificateSerialNumber( + new java.util.Random().nextInt() & 0x7fffffff)); // Set owner and issuer fields X500Name owner; @@ -1943,11 +2150,16 @@ public final class KeyTool { certInfo.set(CertificateAlgorithmId.NAME + "." + CertificateAlgorithmId.ALGORITHM, sigAlgid); - // first upgrade to version 3 - certInfo.set(X509CertInfo.VERSION, new CertificateVersion(CertificateVersion.V3)); + CertificateExtensions ext = createV3Extensions( + null, + (CertificateExtensions)certInfo.get(X509CertInfo.EXTENSIONS), + v3ext, + oldCert.getPublicKey(), + null); + certInfo.set(X509CertInfo.EXTENSIONS, ext); // Sign the new certificate newCert = new X509CertImpl(certInfo); newCert.sign(privKey, sigAlgName); @@ -1985,10 +2197,10 @@ public final class KeyTool { alias = keyAlias; } - Object[] objs = recoverKey(alias, storePass, keyPass); - PrivateKey privKey = (PrivateKey)objs[0]; + Pair<Key,char[]> objs = recoverKey(alias, storePass, keyPass); + PrivateKey privKey = (PrivateKey)objs.fst; if (keyPass == null) { - keyPass = (char[])objs[1]; + keyPass = objs.snd; } Certificate userCert = keyStore.getCertificate(alias); @@ -2290,36 +2502,42 @@ public final class KeyTool { }; out.println(form.format(source)); - int extnum = 0; if (cert instanceof X509CertImpl) { X509CertImpl impl = (X509CertImpl)cert; - if (cert.getCriticalExtensionOIDs() != null) { - for (String extOID : cert.getCriticalExtensionOIDs()) { - if (extnum == 0) { - out.println(); - out.println(rb.getString("Extensions: ")); - out.println(); - } - out.println("#"+(++extnum)+": "+ - impl.getExtension(new ObjectIdentifier(extOID))); - } + X509CertInfo certInfo = (X509CertInfo)impl.get(X509CertImpl.NAME + + "." + + X509CertImpl.INFO); + CertificateExtensions exts = (CertificateExtensions) + certInfo.get(X509CertInfo.EXTENSIONS); + if (exts != null) { + printExtensions(rb.getString("Extensions: "), exts, out); } - if (cert.getNonCriticalExtensionOIDs() != null) { - for (String extOID : cert.getNonCriticalExtensionOIDs()) { - if (extnum == 0) { - out.println(); - out.println(rb.getString("Extensions: ")); - out.println(); - } - Extension ext = impl.getExtension(new ObjectIdentifier(extOID)); - if (ext != null) { - out.println("#"+(++extnum)+": "+ ext); - } else { - out.println("#"+(++extnum)+": "+ - impl.getUnparseableExtension(new ObjectIdentifier(extOID))); - } + } + } + + private static void printExtensions(String title, CertificateExtensions exts, PrintStream out) + throws Exception { + int extnum = 0; + Iterator<Extension> i1 = exts.getAllExtensions().iterator(); + Iterator<Extension> i2 = exts.getUnparseableExtensions().values().iterator(); + while (i1.hasNext() || i2.hasNext()) { + Extension ext = i1.hasNext()?i1.next():i2.next(); + if (extnum == 0) { + out.println(); + out.println(title); + out.println(); + } + out.print("#"+(++extnum)+": "+ ext); + if (ext.getClass() == Extension.class) { + byte[] v = ext.getExtensionValue(); + if (v.length == 0) { + out.println(rb.getString("(Empty value)")); + } else { + new sun.misc.HexDumpEncoder().encode(ext.getExtensionValue(), out); + out.println(); } } + out.println(); } } @@ -2327,7 +2545,19 @@ public final class KeyTool { * Returns true if the certificate is self-signed, false otherwise. */ private boolean isSelfSigned(X509Certificate cert) { - return cert.getSubjectDN().equals(cert.getIssuerDN()); + return signedBy(cert, cert); + } + + private boolean signedBy(X509Certificate end, X509Certificate ca) { + if (!ca.getSubjectDN().equals(end.getIssuerDN())) { + return false; + } + try { + end.verify(ca.getPublicKey()); + return true; + } catch (Exception e) { + return false; + } } /** @@ -2470,7 +2700,7 @@ public final class KeyTool { * recovered private key, and the 2nd element is the password used to * recover it. */ - private Object[] recoverKey(String alias, char[] storePass, + private Pair<Key,char[]> recoverKey(String alias, char[] storePass, char[] keyPass) throws Exception { @@ -2510,7 +2740,7 @@ public final class KeyTool { key = keyStore.getKey(alias, keyPass); } - return new Object[] {key, keyPass}; + return Pair.of(key, keyPass); } /** @@ -2520,7 +2750,7 @@ public final class KeyTool { * recovered entry, and the 2nd element is the password used to * recover it (null if no password). */ - private Object[] recoverEntry(KeyStore ks, + private Pair<Entry,char[]> recoverEntry(KeyStore ks, String alias, char[] pstore, char[] pkey) throws Exception { @@ -2585,7 +2815,7 @@ public final class KeyTool { } } - return new Object[] {entry, pkey}; + return Pair.of(entry, pkey); } /** * Gets the requested finger print of the certificate. @@ -2651,20 +2881,18 @@ public final class KeyTool { Certificate tmpCert = replyCerts[0]; replyCerts[0] = replyCerts[i]; replyCerts[i] = tmpCert; - Principal issuer = ((X509Certificate)replyCerts[0]).getIssuerDN(); + + X509Certificate thisCert = (X509Certificate)replyCerts[0]; for (i=1; i < replyCerts.length-1; i++) { - // find a cert in the reply whose "subject" is the same as the - // given "issuer" + // find a cert in the reply who signs thisCert int j; for (j=i; j<replyCerts.length; j++) { - Principal subject; - subject = ((X509Certificate)replyCerts[j]).getSubjectDN(); - if (subject.equals(issuer)) { + if (signedBy(thisCert, (X509Certificate)replyCerts[j])) { tmpCert = replyCerts[i]; replyCerts[i] = replyCerts[j]; replyCerts[j] = tmpCert; - issuer = ((X509Certificate)replyCerts[i]).getIssuerDN(); + thisCert = (X509Certificate)replyCerts[i]; break; } } @@ -2674,18 +2902,6 @@ public final class KeyTool { } } - // now verify each cert in the ordered chain - for (i=0; i<replyCerts.length-1; i++) { - PublicKey pubKey = replyCerts[i+1].getPublicKey(); - try { - replyCerts[i].verify(pubKey); - } catch (Exception e) { - throw new Exception(rb.getString - ("Certificate chain in reply does not verify: ") + - e.getMessage()); - } - } - if (noprompt) { return replyCerts; } @@ -2817,9 +3033,8 @@ public final class KeyTool { private boolean buildChain(X509Certificate certToVerify, Vector<Certificate> chain, Hashtable<Principal, Vector<Certificate>> certs) { - Principal subject = certToVerify.getSubjectDN(); Principal issuer = certToVerify.getIssuerDN(); - if (subject.equals(issuer)) { + if (isSelfSigned(certToVerify)) { // reached self-signed root cert; // no verification needed because it's trusted. chain.addElement(certToVerify); @@ -2890,7 +3105,7 @@ public final class KeyTool { /** * Returns the keystore with the configured CA certificates. */ - private KeyStore getCacertsKeyStore() + public static KeyStore getCacertsKeyStore() throws Exception { String sep = File.separator; @@ -3026,6 +3241,443 @@ public final class KeyTool { return c.getTime(); } + /** + * Match a command (may be abbreviated) with a command set. + * @param s the command provided + * @param list the legal command set + * @return the position of a single match, or -1 if none matched + * @throws Exception if s is ambiguous + */ + private static int oneOf(String s, String... list) throws Exception { + int[] match = new int[list.length]; + int nmatch = 0; + for (int i = 0; i<list.length; i++) { + String one = list[i]; + if (one.toLowerCase().startsWith(s.toLowerCase())) { + match[nmatch++] = i; + } else { + StringBuffer sb = new StringBuffer(); + boolean first = true; + for (char c: one.toCharArray()) { + if (first) { + sb.append(c); + first = false; + } else { + if (!Character.isLowerCase(c)) { + sb.append(c); + } + } + } + if (sb.toString().equalsIgnoreCase(s)) { + match[nmatch++] = i; + } + } + } + if (nmatch == 0) return -1; + if (nmatch == 1) return match[0]; + StringBuffer sb = new StringBuffer(); + MessageFormat form = new MessageFormat(rb.getString + ("command {0} is ambiguous:")); + Object[] source = {s}; + sb.append(form.format(source) +"\n "); + for (int i=0; i<nmatch; i++) { + sb.append(" " + list[match[i]]); + } + throw new Exception(sb.toString()); + } + + /** + * Create a GeneralName object from known types + * @param t one of 5 known types + * @param v value + * @return which one + */ + private GeneralName createGeneralName(String t, String v) + throws Exception { + GeneralNameInterface gn; + int p = oneOf(t, "EMAIL", "URI", "DNS", "IP", "OID"); + if (p < 0) { + throw new Exception(rb.getString( + "Unrecognized GeneralName type: ") + t); + } + switch (p) { + case 0: gn = new RFC822Name(v); break; + case 1: gn = new URIName(v); break; + case 2: gn = new DNSName(v); break; + case 3: gn = new IPAddressName(v); break; + default: gn = new OIDName(v); break; //4 + } + return new GeneralName(gn); + } + + private static final String[] extSupported = { + "BasicConstraints", + "KeyUsage", + "ExtendedKeyUsage", + "SubjectAlternativeName", + "IssuerAlternativeName", + "SubjectInfoAccess", + "AuthorityInfoAccess", + }; + + private ObjectIdentifier findOidForExtName(String type) + throws Exception { + switch (oneOf(type, extSupported)) { + case 0: return PKIXExtensions.BasicConstraints_Id; + case 1: return PKIXExtensions.KeyUsage_Id; + case 2: return PKIXExtensions.ExtendedKeyUsage_Id; + case 3: return PKIXExtensions.SubjectAlternativeName_Id; + case 4: return PKIXExtensions.IssuerAlternativeName_Id; + case 5: return PKIXExtensions.SubjectInfoAccess_Id; + case 6: return PKIXExtensions.AuthInfoAccess_Id; + default: return new ObjectIdentifier(type); + } + } + + /** + * Create X509v3 extensions from a string representation. Note that the + * SubjectKeyIdentifierExtension will always be created non-critical besides + * the extension requested in the <code>extstr</code> argument. + * + * @param reqex the requested extensions, can be null, used for -gencert + * @param ext the original extensions, can be null, used for -selfcert + * @param extstrs -ext values, Read keytool doc + * @param pkey the public key for the certificate + * @param akey the public key for the authority (issuer) + * @return the created CertificateExtensions + */ + private CertificateExtensions createV3Extensions( + CertificateExtensions reqex, + CertificateExtensions ext, + List <String> extstrs, + PublicKey pkey, + PublicKey akey) throws Exception { + + if (ext != null && reqex != null) { + // This should not happen + throw new Exception("One of request and original should be null."); + } + if (ext == null) ext = new CertificateExtensions(); + try { + // name{:critical}{=value} + // Honoring requested extensions + if (reqex != null) { + for(String extstr: extstrs) { + if (extstr.toLowerCase().startsWith("honored=")) { + List<String> list = Arrays.asList( + extstr.toLowerCase().substring(8).split(",")); + // First check existence of "all" + if (list.contains("all")) { + ext = reqex; // we know ext was null + } + // one by one for others + for (String item: list) { + if (item.equals("all")) continue; + + // add or remove + boolean add = true; + // -1, unchanged, 0 crtical, 1 non-critical + int action = -1; + String type = null; + if (item.startsWith("-")) { + add = false; + type = item.substring(1); + } else { + int colonpos = item.indexOf(':'); + if (colonpos >= 0) { + type = item.substring(0, colonpos); + action = oneOf(item.substring(colonpos+1), + "critical", "non-critical"); + if (action == -1) { + throw new Exception(rb.getString + ("Illegal value: ") + item); + } + } + } + String n = reqex.getNameByOid(findOidForExtName(type)); + if (add) { + Extension e = (Extension)reqex.get(n); + if (!e.isCritical() && action == 0 + || e.isCritical() && action == 1) { + e = Extension.newExtension( + e.getExtensionId(), + !e.isCritical(), + e.getExtensionValue()); + ext.set(n, e); + } + } else { + ext.delete(n); + } + } + break; + } + } + } + for(String extstr: extstrs) { + String name, value; + boolean isCritical = false; + + int eqpos = extstr.indexOf('='); + if (eqpos >= 0) { + name = extstr.substring(0, eqpos); + value = extstr.substring(eqpos+1); + } else { + name = extstr; + value = null; + } + + int colonpos = name.indexOf(':'); + if (colonpos >= 0) { + if (name.substring(colonpos+1).equalsIgnoreCase("critical")) { + isCritical = true; + } + name = name.substring(0, colonpos); + } + + if (name.equalsIgnoreCase("honored")) { + continue; + } + int exttype = oneOf(name, extSupported); + switch (exttype) { + case 0: // BC + int pathLen = -1; + boolean isCA = false; + if (value == null) { + isCA = true; + } else { + try { // the abbr format + pathLen = Integer.parseInt(value); + isCA = true; + } catch (NumberFormatException ufe) { + // ca:true,pathlen:1 + for (String part: value.split(",")) { + String[] nv = part.split(":"); + if (nv.length != 2) { + throw new Exception(rb.getString + ("Illegal value: ") + extstr); + } else { + if (nv[0].equalsIgnoreCase("ca")) { + isCA = Boolean.parseBoolean(nv[1]); + } else if (nv[0].equalsIgnoreCase("pathlen")) { + pathLen = Integer.parseInt(nv[1]); + } else { + throw new Exception(rb.getString + ("Illegal value: ") + extstr); + } + } + } + } + } + ext.set(BasicConstraintsExtension.NAME, + new BasicConstraintsExtension(isCritical, isCA, + pathLen)); + break; + case 1: // KU + if(value != null) { + boolean[] ok = new boolean[9]; + for (String s: value.split(",")) { + int p = oneOf(s, + "digitalSignature", // (0), + "nonRepudiation", // (1) + "keyEncipherment", // (2), + "dataEncipherment", // (3), + "keyAgreement", // (4), + "keyCertSign", // (5), + "cRLSign", // (6), + "encipherOnly", // (7), + "decipherOnly", // (8) + "contentCommitment" // also (1) + ); + if (p < 0) { + throw new Exception(rb.getString("Unknown keyUsage type: ") + s); + } + if (p == 9) p = 1; + ok[p] = true; + } + KeyUsageExtension kue = new KeyUsageExtension(ok); + // The above KeyUsageExtension constructor does not + // allow isCritical value, so... + ext.set(KeyUsageExtension.NAME, Extension.newExtension( + kue.getExtensionId(), + isCritical, + kue.getExtensionValue())); + } else { + throw new Exception(rb.getString + ("Illegal value: ") + extstr); + } + break; + case 2: // EKU + if(value != null) { + Vector <ObjectIdentifier> v = + new Vector <ObjectIdentifier>(); + for (String s: value.split(",")) { + int p = oneOf(s, + "anyExtendedKeyUsage", + "serverAuth", //1 + "clientAuth", //2 + "codeSigning", //3 + "emailProtection", //4 + "", //5 + "", //6 + "", //7 + "timeStamping", //8 + "OCSPSigning" //9 + ); + if (p < 0) { + try { + v.add(new ObjectIdentifier(s)); + } catch (Exception e) { + throw new Exception(rb.getString( + "Unknown extendedkeyUsage type: ") + s); + } + } else if (p == 0) { + v.add(new ObjectIdentifier("2.5.29.37.0")); + } else { + v.add(new ObjectIdentifier("1.3.6.1.5.5.7.3." + p)); + } + } + ext.set(ExtendedKeyUsageExtension.NAME, + new ExtendedKeyUsageExtension(isCritical, v)); + } else { + throw new Exception(rb.getString + ("Illegal value: ") + extstr); + } + break; + case 3: // SAN + case 4: // IAN + if(value != null) { + String[] ps = value.split(","); + GeneralNames gnames = new GeneralNames(); + for(String item: ps) { + colonpos = item.indexOf(':'); + if (colonpos < 0) { + throw new Exception("Illegal item " + item + " in " + extstr); + } + String t = item.substring(0, colonpos); + String v = item.substring(colonpos+1); + gnames.add(createGeneralName(t, v)); + } + if (exttype == 3) { + ext.set(SubjectAlternativeNameExtension.NAME, + new SubjectAlternativeNameExtension( + isCritical, gnames)); + } else { + ext.set(IssuerAlternativeNameExtension.NAME, + new IssuerAlternativeNameExtension( + isCritical, gnames)); + } + } else { + throw new Exception(rb.getString + ("Illegal value: ") + extstr); + } + break; + case 5: // SIA, always non-critical + case 6: // AIA, always non-critical + if (isCritical) { + throw new Exception(rb.getString( + "This extension cannot be marked as critical. ") + extstr); + } + if(value != null) { + List<AccessDescription> accessDescriptions = + new ArrayList<AccessDescription>(); + String[] ps = value.split(","); + for(String item: ps) { + colonpos = item.indexOf(':'); + int colonpos2 = item.indexOf(':', colonpos+1); + if (colonpos < 0 || colonpos2 < 0) { + throw new Exception(rb.getString + ("Illegal value: ") + extstr); + } + String m = item.substring(0, colonpos); + String t = item.substring(colonpos+1, colonpos2); + String v = item.substring(colonpos2+1); + int p = oneOf(m, + "", + "ocsp", //1 + "caIssuers", //2 + "timeStamping", //3 + "", + "caRepository" //5 + ); + ObjectIdentifier oid; + if (p < 0) { + try { + oid = new ObjectIdentifier(m); + } catch (Exception e) { + throw new Exception(rb.getString( + "Unknown AccessDescription type: ") + m); + } + } else { + oid = new ObjectIdentifier("1.3.6.1.5.5.7.48." + p); + } + accessDescriptions.add(new AccessDescription( + oid, createGeneralName(t, v))); + } + if (exttype == 5) { + ext.set(SubjectInfoAccessExtension.NAME, + new SubjectInfoAccessExtension(accessDescriptions)); + } else { + ext.set(AuthorityInfoAccessExtension.NAME, + new AuthorityInfoAccessExtension(accessDescriptions)); + } + } else { + throw new Exception(rb.getString + ("Illegal value: ") + extstr); + } + break; + case -1: + ObjectIdentifier oid = new ObjectIdentifier(name); + byte[] data = null; + if (value != null) { + data = new byte[value.length() / 2 + 1]; + int pos = 0; + for (char c: value.toCharArray()) { + int hex; + if (c >= '0' && c <= '9') { + hex = c - '0' ; + } else if (c >= 'A' && c <= 'F') { + hex = c - 'A' + 10; + } else if (c >= 'a' && c <= 'f') { + hex = c - 'a' + 10; + } else { + continue; + } + if (pos % 2 == 0) { + data[pos/2] = (byte)(hex << 4); + } else { + data[pos/2] += hex; + } + pos++; + } + if (pos % 2 != 0) { + throw new Exception(rb.getString( + "Odd number of hex digits found: ") + extstr); + } + data = Arrays.copyOf(data, pos/2); + } else { + data = new byte[0]; + } + ext.set(oid.toString(), new Extension(oid, isCritical, + new DerValue(DerValue.tag_OctetString, data) + .toByteArray())); + break; + } + } + // always non-critical + ext.set(SubjectKeyIdentifierExtension.NAME, + new SubjectKeyIdentifierExtension( + new KeyIdentifier(pkey).getIdentifier())); + if (akey != null && !pkey.equals(akey)) { + ext.set(AuthorityKeyIdentifierExtension.NAME, + new AuthorityKeyIdentifierExtension( + new KeyIdentifier(akey), null, null)); + } + } catch(IOException e) { + throw new RuntimeException(e); + } + return ext; + } + /** * Prints the usage of this tool. */ @@ -3098,6 +3750,32 @@ public final class KeyTool { ("\t [-sigalg <sigalg>] [-dname <dname>]")); System.err.println(rb.getString ("\t [-startdate <startdate>]")); + System.err.println(rb.getString + ("\t [-ext <key>[:critical][=<value>]]...")); + System.err.println(rb.getString + ("\t [-validity <valDays>] [-keypass <keypass>]")); + System.err.println(rb.getString + ("\t [-keystore <keystore>] [-storepass <storepass>]")); + System.err.println(rb.getString + ("\t [-storetype <storetype>] [-providername <name>]")); + System.err.println(rb.getString + ("\t [-providerclass <provider_class_name> [-providerarg <arg>]] ...")); + System.err.println(rb.getString + ("\t [-providerpath <pathlist>]")); + System.err.println(); + + System.err.println(rb.getString + ("-gencert [-v] [-rfc] [-protected]")); + System.err.println(rb.getString + ("\t [-infile <infile>] [-outfile <outfile>]")); + System.err.println(rb.getString + ("\t [-alias <alias>]")); + System.err.println(rb.getString + ("\t [-sigalg <sigalg>]")); + System.err.println(rb.getString + ("\t [-startdate <startdate>]")); + System.err.println(rb.getString + ("\t [-ext <key>[:critical][=<value>]]...")); System.err.println(rb.getString ("\t [-validity <valDays>] [-keypass <keypass>]")); System.err.println(rb.getString @@ -3201,6 +3879,10 @@ public final class KeyTool { ("-printcert [-v] [-rfc] [-file <cert_file> | -sslserver <host[:port]>]")); System.err.println(); + System.err.println(rb.getString + ("-printcertreq [-v] [-file <cert_file>]")); + System.err.println(); + System.err.println(rb.getString ("-storepasswd [-v] [-new <new_storepass>]")); System.err.println(rb.getString @@ -3211,12 +3893,6 @@ public final class KeyTool { ("\t [-providerclass <provider_class_name> [-providerarg <arg>]] ...")); System.err.println(rb.getString ("\t [-providerpath <pathlist>]")); - - if (debug) { - throw new RuntimeException("NO ERROR, SORRY"); - } else { - System.exit(1); - } } private void tinyHelp() { @@ -3270,4 +3946,8 @@ class Pair<A, B> { else if (snd == null) return fst.hashCode() + 2; else return fst.hashCode() * 17 + snd.hashCode(); } + + public static <A,B> Pair<A,B> of(A a, B b) { + return new Pair<A,B>(a,b); + } } diff --git a/src/share/classes/sun/security/util/Cache.java b/src/share/classes/sun/security/util/Cache.java index e6eddb6f07d1e2a972c60d68e53d59fb0a9d4166..35d648a5a7fa1dfd9e9c9b6e203da913fdf371e7 100644 --- a/src/share/classes/sun/security/util/Cache.java +++ b/src/share/classes/sun/security/util/Cache.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2006 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2002-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 @@ -100,6 +100,21 @@ public abstract class Cache { */ public abstract void remove(Object key); + /** + * Set the maximum size. + */ + public abstract void setCapacity(int size); + + /** + * Set the timeout(in seconds). + */ + public abstract void setTimeout(int timeout); + + /** + * accept a visitor + */ + public abstract void accept(CacheVisitor visitor); + /** * Return a new memory cache with the specified maximum size, unlimited * lifetime for entries, with the values held by SoftReferences. @@ -178,6 +193,10 @@ public abstract class Cache { } } + public interface CacheVisitor { + public void visit(Map<Object, Object> map); + } + } class NullCache extends Cache { @@ -208,6 +227,18 @@ class NullCache extends Cache { // empty } + public void setCapacity(int size) { + // empty + } + + public void setTimeout(int timeout) { + // empty + } + + public void accept(CacheVisitor visitor) { + // empty + } + } class MemoryCache extends Cache { @@ -218,8 +249,8 @@ class MemoryCache extends Cache { private final static boolean DEBUG = false; private final Map<Object, CacheEntry> cacheMap; - private final int maxSize; - private final int lifetime; + private int maxSize; + private long lifetime; private final ReferenceQueue queue; public MemoryCache(boolean soft, int maxSize) { @@ -328,7 +359,7 @@ class MemoryCache extends Cache { oldEntry.invalidate(); return; } - if (cacheMap.size() > maxSize) { + if (maxSize > 0 && cacheMap.size() > maxSize) { expungeExpiredEntries(); if (cacheMap.size() > maxSize) { // still too large? Iterator<CacheEntry> t = cacheMap.values().iterator(); @@ -368,6 +399,55 @@ class MemoryCache extends Cache { } } + public synchronized void setCapacity(int size) { + expungeExpiredEntries(); + if (size > 0 && cacheMap.size() > size) { + Iterator<CacheEntry> t = cacheMap.values().iterator(); + for (int i = cacheMap.size() - size; i > 0; i--) { + CacheEntry lruEntry = t.next(); + if (DEBUG) { + System.out.println("** capacity reset removal " + + lruEntry.getKey() + " | " + lruEntry.getValue()); + } + t.remove(); + lruEntry.invalidate(); + } + } + + maxSize = size > 0 ? size : 0; + + if (DEBUG) { + System.out.println("** capacity reset to " + size); + } + } + + public synchronized void setTimeout(int timeout) { + emptyQueue(); + lifetime = timeout > 0 ? timeout * 1000L : 0L; + + if (DEBUG) { + System.out.println("** lifetime reset to " + timeout); + } + } + + // it is a heavyweight method. + public synchronized void accept(CacheVisitor visitor) { + expungeExpiredEntries(); + Map<Object, Object> cached = getCachedEntries(); + + visitor.visit(cached); + } + + private Map<Object, Object> getCachedEntries() { + Map<Object,Object> kvmap = new HashMap<Object,Object>(cacheMap.size()); + + for (CacheEntry entry : cacheMap.values()) { + kvmap.put(entry.getKey(), entry.getValue()); + } + + return kvmap; + } + protected CacheEntry newEntry(Object key, Object value, long expirationTime, ReferenceQueue queue) { if (queue != null) { diff --git a/src/share/classes/sun/security/util/DerValue.java b/src/share/classes/sun/security/util/DerValue.java index 74e59f609b9eb853b24c2d5937b749b4bdc3872d..114788beb266550f0fb8b7e386a25d56764ddb23 100644 --- a/src/share/classes/sun/security/util/DerValue.java +++ b/src/share/classes/sun/security/util/DerValue.java @@ -1,5 +1,5 @@ /* - * Copyright 1996-2006 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. * * This code is free software; you can redistribute it and/or modify it @@ -65,7 +65,7 @@ public class DerValue { protected DerInputBuffer buffer; /** - * The DER-encoded data of the value. + * The DER-encoded data of the value, never null */ public final DerInputStream data; @@ -378,8 +378,6 @@ public class DerValue { ("Indefinite length encoding not supported"); length = DerInputStream.getLength(in); } - if (length == 0) - return null; if (fullyBuffered && in.available() != length) throw new IOException("extra data given to DerValue constructor"); @@ -477,6 +475,11 @@ public class DerValue { "DerValue.getOctetString, not an Octet String: " + tag); } bytes = new byte[length]; + // Note: do not tempt to call buffer.read(bytes) at all. There's a + // known bug that it returns -1 instead of 0. + if (length == 0) { + return bytes; + } if (buffer.read(bytes) != length) throw new IOException("short read on DerValue buffer"); if (isConstructed()) { diff --git a/src/share/classes/sun/security/util/ManifestEntryVerifier.java b/src/share/classes/sun/security/util/ManifestEntryVerifier.java index c528d95c8b1b181eb81eeb4a4ec9282986c23b0c..b713f16e768a5a23ea5bdf9b685e12fc72b7b5ef 100644 --- a/src/share/classes/sun/security/util/ManifestEntryVerifier.java +++ b/src/share/classes/sun/security/util/ManifestEntryVerifier.java @@ -44,8 +44,6 @@ public class ManifestEntryVerifier { private static final Debug debug = Debug.getInstance("jar"); - private static final Provider digestProvider = Providers.getSunProvider(); - /** the created digest objects */ HashMap<String, MessageDigest> createdDigests; @@ -127,7 +125,7 @@ public class ManifestEntryVerifier { try { digest = MessageDigest.getInstance - (algorithm, digestProvider); + (algorithm, Providers.getSunProvider()); createdDigests.put(algorithm, digest); } catch (NoSuchAlgorithmException nsae) { // ignore diff --git a/src/share/classes/sun/security/util/Resources.java b/src/share/classes/sun/security/util/Resources.java index e89d6cdfc998c129138bec8ee44be12e6688010a..c8c5e386de1b0adb65394053331c2f43f9ba3ea6 100644 --- a/src/share/classes/sun/security/util/Resources.java +++ b/src/share/classes/sun/security/util/Resources.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2008 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. * * This code is free software; you can redistribute it and/or modify it @@ -49,6 +49,7 @@ public class Resources extends java.util.ListResourceBundle { // keytool {"keytool error: ", "keytool error: "}, {"Illegal option: ", "Illegal option: "}, + {"Illegal value: ", "Illegal value: "}, {"Try keytool -help","Try keytool -help"}, {"Command option <flag> needs an argument.", "Command option {0} needs an argument."}, {"Warning: Different store and key passwords not supported for PKCS12 KeyStores. Ignoring user-specified <command> value.", @@ -281,6 +282,20 @@ public class Resources extends java.util.ListResourceBundle { {"keytool usage:\n", "keytool usage:\n"}, {"Extensions: ", "Extensions: "}, + {"(Empty value)", "(Empty value)"}, + {"Extension Request:", "Extension Request:"}, + {"PKCS #10 Certificate Request (Version 1.0)\n" + + "Subject: %s\nPublic Key: %s format %s key\n", + "PKCS #10 Certificate Request (Version 1.0)\n" + + "Subject: %s\nPublic Key: %s format %s key\n"}, + {"Unknown keyUsage type: ", "Unknown keyUsage type: "}, + {"Unknown extendedkeyUsage type: ", "Unknown extendedkeyUsage type: "}, + {"Unknown AccessDescription type: ", "Unknown AccessDescription type: "}, + {"Unrecognized GeneralName type: ", "Unrecognized GeneralName type: "}, + {"This extension cannot be marked as critical. ", + "This extension cannot be marked as critical. "}, + {"Odd number of hex digits found: ", "Odd number of hex digits found: "}, + {"command {0} is ambiguous:", "command {0} is ambiguous:"}, {"-certreq [-v] [-protected]", "-certreq [-v] [-protected]"}, @@ -322,6 +337,14 @@ public class Resources extends java.util.ListResourceBundle { {"\t [-validity <valDays>] [-keypass <keypass>]", "\t [-validity <valDays>] [-keypass <keypass>]"}, /** rest is same as -certreq starting from -keystore **/ + {"-gencert [-v] [-rfc] [-protected]", + "-gencert [-v] [-rfc] [-protected]"}, + {"\t [-infile <infile>] [-outfile <outfile>]", + "\t [-infile <infile>] [-outfile <outfile>]"}, + {"\t [-sigalg <sigalg>]", + "\t [-sigalg <sigalg>]"}, + {"\t [-ext <key>[:critical][=<value>]]...", + "\t [-ext <key>[:critical][=<value>]]..."}, {"-genseckey [-v] [-protected]", "-genseckey [-v] [-protected]"}, @@ -388,6 +411,8 @@ public class Resources extends java.util.ListResourceBundle { {"-printcert [-v] [-rfc] [-file <cert_file> | -sslserver <host[:port]>]", "-printcert [-v] [-rfc] [-file <cert_file> | -sslserver <host[:port]>]"}, + {"-printcertreq [-v] [-file <cert_file>]", + "-printcertreq [-v] [-file <cert_file>]"}, {"No certificate from the SSL server", "No certificate from the SSL server"}, diff --git a/src/share/classes/sun/security/util/SecurityConstants.java b/src/share/classes/sun/security/util/SecurityConstants.java index 95cd1f57070b45f8d4f302bb8cfe14917ff3b963..43e2cd3d792de6ed9be1fdb7c21f3addda83fc12 100644 --- a/src/share/classes/sun/security/util/SecurityConstants.java +++ b/src/share/classes/sun/security/util/SecurityConstants.java @@ -1,5 +1,5 @@ /* - * Copyright 2003-2005 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2003-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 @@ -52,6 +52,7 @@ public final class SecurityConstants { public static final String FILE_EXECUTE_ACTION = "execute"; public static final String FILE_READ_ACTION = "read"; public static final String FILE_WRITE_ACTION = "write"; + public static final String FILE_READLINK_ACTION = "readlink"; public static final String SOCKET_RESOLVE_ACTION = "resolve"; public static final String SOCKET_CONNECT_ACTION = "connect"; diff --git a/src/share/classes/sun/security/x509/AccessDescription.java b/src/share/classes/sun/security/x509/AccessDescription.java index a9ccbb86824ee1c590260bc556b9884dae65787b..1544ea953bec5864f786be79daf0459cd7614995 100644 --- a/src/share/classes/sun/security/x509/AccessDescription.java +++ b/src/share/classes/sun/security/x509/AccessDescription.java @@ -1,5 +1,5 @@ /* - * Copyright 2003-2005 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2003-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 @@ -48,6 +48,17 @@ public final class AccessDescription { public static final ObjectIdentifier Ad_CAISSUERS_Id = ObjectIdentifier.newInternal(new int[] {1, 3, 6, 1, 5, 5, 7, 48, 2}); + public static final ObjectIdentifier Ad_TIMESTAMPING_Id = + ObjectIdentifier.newInternal(new int[] {1, 3, 6, 1, 5, 5, 7, 48, 3}); + + public static final ObjectIdentifier Ad_CAREPOSITORY_Id = + ObjectIdentifier.newInternal(new int[] {1, 3, 6, 1, 5, 5, 7, 48, 5}); + + public AccessDescription(ObjectIdentifier accessMethod, GeneralName accessLocation) { + this.accessMethod = accessMethod; + this.accessLocation = accessLocation; + } + public AccessDescription(DerValue derValue) throws IOException { DerInputStream derIn = derValue.getData(); accessMethod = derIn.getOID(); @@ -90,7 +101,19 @@ public final class AccessDescription { } public String toString() { - return ("accessMethod: " + accessMethod.toString() + - "\n accessLocation: " + accessLocation.toString()); + String method = null; + if (accessMethod.equals(Ad_CAISSUERS_Id)) { + method = "caIssuers"; + } else if (accessMethod.equals(Ad_CAREPOSITORY_Id)) { + method = "caRepository"; + } else if (accessMethod.equals(Ad_TIMESTAMPING_Id)) { + method = "timeStamping"; + } else if (accessMethod.equals(Ad_OCSP_Id)) { + method = "ocsp"; + } else { + method = accessMethod.toString(); + } + return ("accessMethod: " + method + + "\n accessLocation: " + accessLocation.toString() + "\n"); } } diff --git a/src/share/classes/sun/security/x509/AuthorityInfoAccessExtension.java b/src/share/classes/sun/security/x509/AuthorityInfoAccessExtension.java index 5b0b287fa2424c73f2a7f2ee0a61975e31a2c49c..9e332b10c557b3d7e98df81b3f5651a9ad1d79e5 100644 --- a/src/share/classes/sun/security/x509/AuthorityInfoAccessExtension.java +++ b/src/share/classes/sun/security/x509/AuthorityInfoAccessExtension.java @@ -1,5 +1,5 @@ /* - * Copyright 2004-2006 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2004-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 @@ -43,8 +43,9 @@ import sun.security.util.DerValue; * certificate that identifies the specific OCSP Responder to use when * performing on-line validation of that certificate. * <p> - * This extension is defined in - * <a href="http://www.ietf.org/rfc/rfc3280.txt">Internet X.509 PKI Certificate and Certificate Revocation List (CRL) Profile</a>. The profile permits + * This extension is defined in <a href="http://www.ietf.org/rfc/rfc3280.txt"> + * Internet X.509 PKI Certificate and Certificate Revocation List + * (CRL) Profile</a>. The profile permits * the extension to be included in end-entity or CA certificates, * and it must be marked as non-critical. Its ASN.1 definition is as follows: * <pre> diff --git a/src/share/classes/sun/security/x509/AuthorityKeyIdentifierExtension.java b/src/share/classes/sun/security/x509/AuthorityKeyIdentifierExtension.java index f63dca90a79eaab8377a22dfdd39650142d0bd84..b14c8436292a978759f95e2638d081b0a6ffa69f 100644 --- a/src/share/classes/sun/security/x509/AuthorityKeyIdentifierExtension.java +++ b/src/share/classes/sun/security/x509/AuthorityKeyIdentifierExtension.java @@ -1,5 +1,5 @@ /* - * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 1997-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 @@ -198,7 +198,7 @@ implements CertAttrSet<String> { public String toString() { String s = super.toString() + "AuthorityKeyIdentifier [\n"; if (id != null) { - s += id.toString() + "\n"; + s += id.toString(); // id already has a newline } if (names != null) { s += names.toString() + "\n"; diff --git a/src/share/classes/sun/security/x509/BasicConstraintsExtension.java b/src/share/classes/sun/security/x509/BasicConstraintsExtension.java index 26344ee27f17bca346a5d2fdb010e0ed2f63b705..c38bb002b080f50fb655528d36427f95d4fd2893 100644 --- a/src/share/classes/sun/security/x509/BasicConstraintsExtension.java +++ b/src/share/classes/sun/security/x509/BasicConstraintsExtension.java @@ -1,5 +1,5 @@ /* - * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 1997-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 @@ -70,18 +70,15 @@ implements CertAttrSet<String> { // Encode this extension value private void encodeThis() throws IOException { - if (ca == false && pathLen < 0) { - this.extensionValue = null; - return; - } DerOutputStream out = new DerOutputStream(); DerOutputStream tmp = new DerOutputStream(); if (ca) { tmp.putBoolean(ca); - } - if (pathLen >= 0) { - tmp.putInteger(pathLen); + // Only encode pathLen when ca == true + if (pathLen >= 0) { + tmp.putInteger(pathLen); + } } out.write(DerValue.tag_Sequence, tmp); this.extensionValue = out.toByteArray(); @@ -134,7 +131,7 @@ implements CertAttrSet<String> { throw new IOException("Invalid encoding of BasicConstraints"); } - if (val.data == null) { + if (val.data == null || val.data.available() == 0) { // non-CA cert ("cA" field is FALSE by default), return -1 return; } diff --git a/src/share/classes/sun/security/x509/CertAndKeyGen.java b/src/share/classes/sun/security/x509/CertAndKeyGen.java index 0e0800910ea40b81f2b1c36fde908321201afe5d..2cf34c871ec733e1b12eb0187c6c69b97c3a0aa7 100644 --- a/src/share/classes/sun/security/x509/CertAndKeyGen.java +++ b/src/share/classes/sun/security/x509/CertAndKeyGen.java @@ -1,5 +1,5 @@ /* - * 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. * * This code is free software; you can redistribute it and/or modify it @@ -265,8 +265,8 @@ public final class CertAndKeyGen { // Add all mandatory attributes info.set(X509CertInfo.VERSION, new CertificateVersion(CertificateVersion.V3)); - info.set(X509CertInfo.SERIAL_NUMBER, - new CertificateSerialNumber((int)(firstDate.getTime()/1000))); + info.set(X509CertInfo.SERIAL_NUMBER, new CertificateSerialNumber( + new java.util.Random().nextInt() & 0x7fffffff)); AlgorithmId algID = issuer.getAlgorithmId(); info.set(X509CertInfo.ALGORITHM_ID, new CertificateAlgorithmId(algID)); @@ -276,12 +276,6 @@ public final class CertAndKeyGen { info.set(X509CertInfo.ISSUER, new CertificateIssuerName(issuer.getSigner())); - CertificateExtensions ext = new CertificateExtensions(); - ext.set(SubjectKeyIdentifierExtension.NAME, - new SubjectKeyIdentifierExtension( - new KeyIdentifier(publicKey).getIdentifier())); - info.set(X509CertInfo.EXTENSIONS, ext); - cert = new X509CertImpl(info); cert.sign(privateKey, this.sigAlg); diff --git a/src/share/classes/sun/security/x509/CertificateExtensions.java b/src/share/classes/sun/security/x509/CertificateExtensions.java index 7049d01e974e32e9b56d6ca721f47e57448793f6..cd32e748c742ae7769348fdc844e82ab90008db4 100644 --- a/src/share/classes/sun/security/x509/CertificateExtensions.java +++ b/src/share/classes/sun/security/x509/CertificateExtensions.java @@ -1,5 +1,5 @@ /* - * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 1997-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 @@ -231,6 +231,15 @@ public class CertificateExtensions implements CertAttrSet<Extension> { map.remove(name); } + public String getNameByOid(ObjectIdentifier oid) throws IOException { + for (String name: map.keySet()) { + if (map.get(name).getExtensionId().equals(oid)) { + return name; + } + } + return null; + } + /** * Return an enumeration of names of attributes existing within this * attribute. diff --git a/src/share/classes/sun/security/x509/IssuerAlternativeNameExtension.java b/src/share/classes/sun/security/x509/IssuerAlternativeNameExtension.java index aad153b646a5a768e2c96c21c5b99ef588f55408..73f3ecd5c939fc3bf762efcff10a342abefc23e0 100644 --- a/src/share/classes/sun/security/x509/IssuerAlternativeNameExtension.java +++ b/src/share/classes/sun/security/x509/IssuerAlternativeNameExtension.java @@ -1,5 +1,5 @@ /* - * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 1997-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 @@ -89,6 +89,22 @@ extends Extension implements CertAttrSet<String> { encodeThis(); } + /** + * Create a IssuerAlternativeNameExtension with the passed criticality + * and GeneralNames. + * + * @param critical true if the extension is to be treated as critical. + * @param names the GeneralNames for the issuer. + * @exception IOException on error. + */ + public IssuerAlternativeNameExtension(Boolean critical, GeneralNames names) + throws IOException { + this.names = names; + this.extensionId = PKIXExtensions.IssuerAlternativeName_Id; + this.critical = critical.booleanValue(); + encodeThis(); + } + /** * Create a default IssuerAlternativeNameExtension. */ diff --git a/src/share/classes/sun/security/x509/OCSPNoCheckExtension.java b/src/share/classes/sun/security/x509/OCSPNoCheckExtension.java new file mode 100644 index 0000000000000000000000000000000000000000..b721439d5c9fb064e4a913b651ba9290a9ed926a --- /dev/null +++ b/src/share/classes/sun/security/x509/OCSPNoCheckExtension.java @@ -0,0 +1,132 @@ +/* + * 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 sun.security.x509; + +import java.io.IOException; +import java.io.OutputStream; +import java.util.Enumeration; + +import sun.security.util.*; + +/** + * Represent the OCSP NoCheck Extension from RFC2560. + * <p> + * A CA may specify that an OCSP client can trust a responder for the + * lifetime of the responder's certificate. The CA does so by including + * the extension id-pkix-ocsp-nocheck. This SHOULD be a non-critical + * extension. The value of the extension should be NULL. CAs issuing + * such a certificate should realized that a compromise of the + * responder's key, is as serious as the compromise of a CA key used to + * sign CRLs, at least for the validity period of this certificate. CA's + * may choose to issue this type of certificate with a very short + * lifetime and renew it frequently. + * <pre> + * id-pkix-ocsp-nocheck OBJECT IDENTIFIER ::= { id-pkix-ocsp 5 } + * </pre> + * + * @author Xuelei Fan + * @see Extension + * @see CertAttrSet + */ +public class OCSPNoCheckExtension extends Extension + implements CertAttrSet<String> { + + /** + * Identifier for this attribute, to be used with the + * get, set, delete methods of Certificate, x509 type. + */ + public static final String IDENT = + "x509.info.extensions.OCSPNoCheck"; + /** + * Attribute names. + */ + public static final String NAME = "OCSPNoCheck"; + + /** + * Create a OCSPNoCheckExtension + */ + public OCSPNoCheckExtension() throws IOException { + this.extensionId = PKIXExtensions.OCSPNoCheck_Id; + this.critical = false; + this.extensionValue = new byte[0]; + } + + /** + * Create the extension from the passed DER encoded value. + * + * @param critical true if the extension is to be treated as critical. + * @param value an array of DER encoded bytes of the actual value. + * @exception IOException on error. + */ + public OCSPNoCheckExtension(Boolean critical, Object value) + throws IOException { + + this.extensionId = PKIXExtensions.OCSPNoCheck_Id; + this.critical = critical.booleanValue(); + + // the value should be null, just ignore it here. + this.extensionValue = new byte[0]; + } + + /** + * Set the attribute value. + */ + public void set(String name, Object obj) throws IOException { + throw new IOException("No attribute is allowed by " + + "CertAttrSet:OCSPNoCheckExtension."); + } + + /** + * Get the attribute value. + */ + public Object get(String name) throws IOException { + throw new IOException("No attribute is allowed by " + + "CertAttrSet:OCSPNoCheckExtension."); + } + + /** + * Delete the attribute value. + */ + public void delete(String name) throws IOException { + throw new IOException("No attribute is allowed by " + + "CertAttrSet:OCSPNoCheckExtension."); + } + + /** + * Return an enumeration of names of attributes existing within this + * attribute. + */ + public Enumeration<String> getElements() { + return (new AttributeNameEnumeration()).elements(); + } + + /** + * Return the name of this attribute. + */ + public String getName() { + return NAME; + } +} diff --git a/src/share/classes/sun/security/x509/OIDMap.java b/src/share/classes/sun/security/x509/OIDMap.java index ddbb1d6f60a13df6eba935037c0452b6da552237..f52fab3eeef81352047a89f0228ed91f8032356b 100644 --- a/src/share/classes/sun/security/x509/OIDMap.java +++ b/src/share/classes/sun/security/x509/OIDMap.java @@ -1,5 +1,5 @@ /* - * Copyright 1997-2005 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 1997-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 @@ -90,6 +90,8 @@ public class OIDMap { private static final String CERT_ISSUER = ROOT + "." + CertificateIssuerExtension.NAME; + private static final String SUBJECT_INFO_ACCESS = ROOT + "." + + SubjectInfoAccessExtension.NAME; private static final String AUTH_INFO_ACCESS = ROOT + "." + AuthorityInfoAccessExtension.NAME; private static final String ISSUING_DIST_POINT = ROOT + "." + @@ -98,6 +100,8 @@ public class OIDMap { DeltaCRLIndicatorExtension.NAME; private static final String FRESHEST_CRL = ROOT + "." + FreshestCRLExtension.NAME; + private static final String OCSPNOCHECK = ROOT + "." + + OCSPNoCheckExtension.NAME; private static final int NetscapeCertType_data[] = { 2, 16, 840, 1, 113730, 1, 1 }; @@ -148,6 +152,8 @@ public class OIDMap { "sun.security.x509.CRLDistributionPointsExtension"); addInternal(CERT_ISSUER, PKIXExtensions.CertificateIssuer_Id, "sun.security.x509.CertificateIssuerExtension"); + addInternal(SUBJECT_INFO_ACCESS, PKIXExtensions.SubjectInfoAccess_Id, + "sun.security.x509.SubjectInfoAccessExtension"); addInternal(AUTH_INFO_ACCESS, PKIXExtensions.AuthInfoAccess_Id, "sun.security.x509.AuthorityInfoAccessExtension"); addInternal(ISSUING_DIST_POINT, @@ -157,6 +163,8 @@ public class OIDMap { "sun.security.x509.DeltaCRLIndicatorExtension"); addInternal(FRESHEST_CRL, PKIXExtensions.FreshestCRL_Id, "sun.security.x509.FreshestCRLExtension"); + addInternal(OCSPNOCHECK, PKIXExtensions.OCSPNoCheck_Id, + "sun.security.x509.OCSPNoCheckExtension"); } /** diff --git a/src/share/classes/sun/security/x509/PKIXExtensions.java b/src/share/classes/sun/security/x509/PKIXExtensions.java index 78177944c08bfbe1376111531156bd41860289a2..f140c548551465135e6dd4fd57d1fcc1e8a95467 100644 --- a/src/share/classes/sun/security/x509/PKIXExtensions.java +++ b/src/share/classes/sun/security/x509/PKIXExtensions.java @@ -1,5 +1,5 @@ /* - * Copyright 1997-2005 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 1997-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 @@ -74,6 +74,8 @@ public class PKIXExtensions { private static final int AuthInfoAccess_data [] = { 1, 3, 6, 1, 5, 5, 7, 1, 1}; private static final int SubjectInfoAccess_data [] = { 1, 3, 6, 1, 5, 5, 7, 1, 11}; private static final int FreshestCRL_data [] = { 2, 5, 29, 46 }; + private static final int OCSPNoCheck_data [] = { 1, 3, 6, 1, 5, 5, 7, + 48, 1, 5}; /** * Identifies the particular public key used to sign the certificate. @@ -216,6 +218,12 @@ public class PKIXExtensions { */ public static final ObjectIdentifier FreshestCRL_Id; + /** + * Identifies the OCSP client can trust the responder for the + * lifetime of the responder's certificate. + */ + public static final ObjectIdentifier OCSPNoCheck_Id; + static { AuthorityKey_Id = ObjectIdentifier.newInternal(AuthorityKey_data); SubjectKey_Id = ObjectIdentifier.newInternal(SubjectKey_data); @@ -257,5 +265,6 @@ public class PKIXExtensions { SubjectInfoAccess_Id = ObjectIdentifier.newInternal(SubjectInfoAccess_data); FreshestCRL_Id = ObjectIdentifier.newInternal(FreshestCRL_data); + OCSPNoCheck_Id = ObjectIdentifier.newInternal(OCSPNoCheck_data); } } diff --git a/src/share/classes/sun/security/x509/SubjectInfoAccessExtension.java b/src/share/classes/sun/security/x509/SubjectInfoAccessExtension.java new file mode 100644 index 0000000000000000000000000000000000000000..449f45eb595ef0ea8869880a793b9510d504f8bb --- /dev/null +++ b/src/share/classes/sun/security/x509/SubjectInfoAccessExtension.java @@ -0,0 +1,244 @@ +/* + * 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 sun.security.x509; + +import java.io.IOException; +import java.io.OutputStream; + +import java.util.*; + +import sun.security.util.DerOutputStream; +import sun.security.util.DerValue; + +/** + * The Subject Information Access Extension (OID = 1.3.6.1.5.5.7.1.11). + * <p> + * The subject information access extension indicates how to access + * information and services for the subject of the certificate in which + * the extension appears. When the subject is a CA, information and + * services may include certificate validation services and CA policy + * data. When the subject is an end entity, the information describes + * the type of services offered and how to access them. In this case, + * the contents of this extension are defined in the protocol + * specifications for the supported services. This extension may be + * included in end entity or CA certificates. Conforming CAs MUST mark + * this extension as non-critical. + * <p> + * This extension is defined in <a href="http://www.ietf.org/rfc/rfc3280.txt"> + * Internet X.509 PKI Certificate and Certificate Revocation List + * (CRL) Profile</a>. The profile permits + * the extension to be included in end-entity or CA certificates, + * and it must be marked as non-critical. Its ASN.1 definition is as follows: + * <pre> + * id-pe-subjectInfoAccess OBJECT IDENTIFIER ::= { id-pe 11 } + * + * SubjectInfoAccessSyntax ::= + * SEQUENCE SIZE (1..MAX) OF AccessDescription + * + * AccessDescription ::= SEQUENCE { + * accessMethod OBJECT IDENTIFIER, + * accessLocation GeneralName } + * </pre> + * <p> + * @see Extension + * @see CertAttrSet + */ + +public class SubjectInfoAccessExtension extends Extension + implements CertAttrSet<String> { + + /** + * Identifier for this attribute, to be used with the + * get, set, delete methods of Certificate, x509 type. + */ + public static final String IDENT = + "x509.info.extensions.SubjectInfoAccess"; + + /** + * Attribute name. + */ + public static final String NAME = "SubjectInfoAccess"; + public static final String DESCRIPTIONS = "descriptions"; + + /** + * The List of AccessDescription objects. + */ + private List<AccessDescription> accessDescriptions; + + /** + * Create an SubjectInfoAccessExtension from a List of + * AccessDescription; the criticality is set to false. + * + * @param accessDescriptions the List of AccessDescription + * @throws IOException on error + */ + public SubjectInfoAccessExtension( + List<AccessDescription> accessDescriptions) throws IOException { + this.extensionId = PKIXExtensions.SubjectInfoAccess_Id; + this.critical = false; + this.accessDescriptions = accessDescriptions; + encodeThis(); + } + + /** + * Create the extension from the passed DER encoded value of the same. + * + * @param critical true if the extension is to be treated as critical. + * @param value Array of DER encoded bytes of the actual value. + * @exception IOException on error. + */ + public SubjectInfoAccessExtension(Boolean critical, Object value) + throws IOException { + this.extensionId = PKIXExtensions.SubjectInfoAccess_Id; + this.critical = critical.booleanValue(); + + if (!(value instanceof byte[])) { + throw new IOException("Illegal argument type"); + } + + extensionValue = (byte[])value; + DerValue val = new DerValue(extensionValue); + if (val.tag != DerValue.tag_Sequence) { + throw new IOException("Invalid encoding for " + + "SubjectInfoAccessExtension."); + } + accessDescriptions = new ArrayList<AccessDescription>(); + while (val.data.available() != 0) { + DerValue seq = val.data.getDerValue(); + AccessDescription accessDescription = new AccessDescription(seq); + accessDescriptions.add(accessDescription); + } + } + + /** + * Return the list of AccessDescription objects. + */ + public List<AccessDescription> getAccessDescriptions() { + return accessDescriptions; + } + + /** + * Return the name of this attribute. + */ + public String getName() { + return NAME; + } + + /** + * Write the extension to the DerOutputStream. + * + * @param out the DerOutputStream to write the extension to. + * @exception IOException on encoding errors. + */ + public void encode(OutputStream out) throws IOException { + DerOutputStream tmp = new DerOutputStream(); + if (this.extensionValue == null) { + this.extensionId = PKIXExtensions.SubjectInfoAccess_Id; + this.critical = false; + encodeThis(); + } + super.encode(tmp); + out.write(tmp.toByteArray()); + } + + /** + * Set the attribute value. + */ + public void set(String name, Object obj) throws IOException { + if (name.equalsIgnoreCase(DESCRIPTIONS)) { + if (!(obj instanceof List)) { + throw new IOException("Attribute value should be of type List."); + } + accessDescriptions = (List<AccessDescription>)obj; + } else { + throw new IOException("Attribute name [" + name + + "] not recognized by " + + "CertAttrSet:SubjectInfoAccessExtension."); + } + encodeThis(); + } + + /** + * Get the attribute value. + */ + public Object get(String name) throws IOException { + if (name.equalsIgnoreCase(DESCRIPTIONS)) { + return accessDescriptions; + } else { + throw new IOException("Attribute name [" + name + + "] not recognized by " + + "CertAttrSet:SubjectInfoAccessExtension."); + } + } + + /** + * Delete the attribute value. + */ + public void delete(String name) throws IOException { + if (name.equalsIgnoreCase(DESCRIPTIONS)) { + accessDescriptions = new ArrayList<AccessDescription>(); + } else { + throw new IOException("Attribute name [" + name + + "] not recognized by " + + "CertAttrSet:SubjectInfoAccessExtension."); + } + encodeThis(); + } + + /** + * Return an enumeration of names of attributes existing within this + * attribute. + */ + public Enumeration<String> getElements() { + AttributeNameEnumeration elements = new AttributeNameEnumeration(); + elements.addElement(DESCRIPTIONS); + return elements.elements(); + } + + // Encode this extension value + private void encodeThis() throws IOException { + if (accessDescriptions.isEmpty()) { + this.extensionValue = null; + } else { + DerOutputStream ads = new DerOutputStream(); + for (AccessDescription accessDescription : accessDescriptions) { + accessDescription.encode(ads); + } + DerOutputStream seq = new DerOutputStream(); + seq.write(DerValue.tag_Sequence, ads); + this.extensionValue = seq.toByteArray(); + } + } + + /** + * Return the extension as user readable string. + */ + public String toString() { + return super.toString() + "SubjectInfoAccess [\n " + + accessDescriptions + "\n]\n"; + } + +} diff --git a/src/share/classes/sun/swing/FilePane.java b/src/share/classes/sun/swing/FilePane.java index de5ad7c48312a90b45128ba55df1eadfdb1f4956..71112b319d8c328c91236bc719ce0a0638565faa 100644 --- a/src/share/classes/sun/swing/FilePane.java +++ b/src/share/classes/sun/swing/FilePane.java @@ -34,6 +34,7 @@ import java.text.DateFormat; import java.text.MessageFormat; import java.util.*; import java.util.List; +import java.util.concurrent.Callable; import javax.swing.*; import javax.swing.border.*; @@ -900,6 +901,16 @@ public class FilePane extends JPanel implements PropertyChangeListener { } } + @Override + public void sort() { + ShellFolder.getInvoker().invoke(new Callable<Void>() { + public Void call() throws Exception { + DetailsTableRowSorter.super.sort(); + return null; + } + }); + } + public void modelStructureChanged() { super.modelStructureChanged(); updateComparators(detailsTableModel.getColumns()); diff --git a/src/share/classes/sun/swing/plaf/synth/SynthFileChooserUIImpl.java b/src/share/classes/sun/swing/plaf/synth/SynthFileChooserUIImpl.java index 5ded9d729a4cb79be4f77fae26b34553b6c61fef..7069c394ad6a7019b0f7a824ba8bc3b38ca40252 100644 --- a/src/share/classes/sun/swing/plaf/synth/SynthFileChooserUIImpl.java +++ b/src/share/classes/sun/swing/plaf/synth/SynthFileChooserUIImpl.java @@ -29,6 +29,8 @@ import java.awt.event.*; import java.beans.*; import java.io.*; import java.util.*; +import java.security.AccessController; +import java.security.PrivilegedAction; import javax.swing.*; import javax.swing.event.*; @@ -749,7 +751,11 @@ public class SynthFileChooserUIImpl extends SynthFileChooserUI { File[] baseFolders; if (useShellFolder) { - baseFolders = (File[])ShellFolder.get("fileChooserComboBoxFolders"); + baseFolders = AccessController.doPrivileged(new PrivilegedAction<File[]>() { + public File[] run() { + return (File[]) ShellFolder.get("fileChooserComboBoxFolders"); + } + }); } else { baseFolders = fsv.getRoots(); } diff --git a/src/share/classes/sun/text/normalizer/CharTrie.java b/src/share/classes/sun/text/normalizer/CharTrie.java index 3069de8650e65c6411e9a5e4c77101f0d66e93d5..eadbce37c225c190c797e7b1a4b837c76b4d7b7a 100644 --- a/src/share/classes/sun/text/normalizer/CharTrie.java +++ b/src/share/classes/sun/text/normalizer/CharTrie.java @@ -1,5 +1,5 @@ /* - * Portions Copyright 2003-2005 Sun Microsystems, Inc. All Rights Reserved. + * Portions Copyright 2005-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 @@ -22,10 +22,9 @@ * CA 95054 USA or visit www.sun.com if you need additional information or * have any questions. */ - /* ******************************************************************************* - * (C) Copyright IBM Corp. 1996-2005 - All Rights Reserved * + * (C) Copyright IBM Corp. and others, 1996-2009 - All Rights Reserved * * * * The original version of this source code and documentation is copyrighted * * and owned by IBM, These materials are provided under terms of a License * @@ -77,6 +76,66 @@ public class CharTrie extends Trie m_friendAgent_ = new FriendAgent(); } + /** + * Make a dummy CharTrie. + * A dummy trie is an empty runtime trie, used when a real data trie cannot + * be loaded. + * + * The trie always returns the initialValue, + * or the leadUnitValue for lead surrogate code points. + * The Latin-1 part is always set up to be linear. + * + * @param initialValue the initial value that is set for all code points + * @param leadUnitValue the value for lead surrogate code _units_ that do not + * have associated supplementary data + * @param dataManipulate object which provides methods to parse the char data + */ + public CharTrie(int initialValue, int leadUnitValue, DataManipulate dataManipulate) { + super(new char[BMP_INDEX_LENGTH+SURROGATE_BLOCK_COUNT], HEADER_OPTIONS_LATIN1_IS_LINEAR_MASK_, dataManipulate); + + int dataLength, latin1Length, i, limit; + char block; + + /* calculate the actual size of the dummy trie data */ + + /* max(Latin-1, block 0) */ + dataLength=latin1Length= INDEX_STAGE_1_SHIFT_<=8 ? 256 : DATA_BLOCK_LENGTH; + if(leadUnitValue!=initialValue) { + dataLength+=DATA_BLOCK_LENGTH; + } + m_data_=new char[dataLength]; + m_dataLength_=dataLength; + + m_initialValue_=(char)initialValue; + + /* fill the index and data arrays */ + + /* indexes are preset to 0 (block 0) */ + + /* Latin-1 data */ + for(i=0; i<latin1Length; ++i) { + m_data_[i]=(char)initialValue; + } + + if(leadUnitValue!=initialValue) { + /* indexes for lead surrogate code units to the block after Latin-1 */ + block=(char)(latin1Length>>INDEX_STAGE_2_SHIFT_); + i=0xd800>>INDEX_STAGE_1_SHIFT_; + limit=0xdc00>>INDEX_STAGE_1_SHIFT_; + for(; i<limit; ++i) { + m_index_[i]=block; + } + + /* data for lead surrogate code units */ + limit=latin1Length+DATA_BLOCK_LENGTH; + for(i=latin1Length; i<limit; ++i) { + m_data_[i]=(char)leadUnitValue; + } + } + + m_friendAgent_ = new FriendAgent(); + } + /** * Java friend implementation */ @@ -130,7 +189,18 @@ public class CharTrie extends Trie */ public final char getCodePointValue(int ch) { - int offset = getCodePointOffset(ch); + int offset; + + // fastpath for U+0000..U+D7FF + if(0 <= ch && ch < UTF16.LEAD_SURROGATE_MIN_VALUE) { + // copy of getRawOffset() + offset = (m_index_[ch >> INDEX_STAGE_1_SHIFT_] << INDEX_STAGE_2_SHIFT_) + + (ch & INDEX_STAGE_3_MASK_); + return m_data_[offset]; + } + + // handle U+D800..U+10FFFF + offset = getCodePointOffset(ch); // return -1 if there is an error, in this case we return the default // value: m_initialValue_ diff --git a/src/share/classes/sun/text/normalizer/NormalizerBase.java b/src/share/classes/sun/text/normalizer/NormalizerBase.java index c2fc1ab291dc40a523045e85e7139d7b7b9cd4c4..a82475c6009b3356110a348c26f4a740285cc18a 100644 --- a/src/share/classes/sun/text/normalizer/NormalizerBase.java +++ b/src/share/classes/sun/text/normalizer/NormalizerBase.java @@ -1,5 +1,5 @@ /* - * Portions Copyright 2001-2006 Sun Microsystems, Inc. All Rights Reserved. + * Portions Copyright 2005-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 @@ -22,10 +22,9 @@ * CA 95054 USA or visit www.sun.com if you need additional information or * have any questions. */ - /* ******************************************************************************* - * (C) Copyright IBM Corp. 1996-2005 - All Rights Reserved * + * (C) Copyright IBM Corp. and others, 1996-2009 - All Rights Reserved * * * * The original version of this source code and documentation is copyrighted * * and owned by IBM, These materials are provided under terms of a License * @@ -127,7 +126,7 @@ import java.text.Normalizer; * normalize(FCD) may be implemented with NFD. * * For more details on FCD see the collation design document: - * http://oss.software.ibm.com/cvs/icu/~checkout~/icuhtml/design/collation/ICU_collation_design.htm + * http://source.icu-project.org/repos/icu/icuhtml/trunk/design/collation/ICU_collation_design.htm * * ICU collation performs either NFD or FCD normalization automatically if * normalization is turned on for the collator object. Beyond collation and diff --git a/src/share/classes/sun/text/normalizer/NormalizerDataReader.java b/src/share/classes/sun/text/normalizer/NormalizerDataReader.java index 0378d5b592376b64e851baa685ba04504d144fe6..69b120d36e48de6b32460897af0afa1751d5cbc9 100644 --- a/src/share/classes/sun/text/normalizer/NormalizerDataReader.java +++ b/src/share/classes/sun/text/normalizer/NormalizerDataReader.java @@ -1,5 +1,5 @@ /* - * Portions Copyright 2003-2006 Sun Microsystems, Inc. All Rights Reserved. + * Portions Copyright 2005-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 @@ -22,10 +22,9 @@ * CA 95054 USA or visit www.sun.com if you need additional information or * have any questions. */ - /* ******************************************************************************* - * (C) Copyright IBM Corp. 1996-2005 - All Rights Reserved * + * (C) Copyright IBM Corp. and others, 1996-2009 - All Rights Reserved * * * * The original version of this source code and documentation is copyrighted * * and owned by IBM, These materials are provided under terms of a License * @@ -331,7 +330,7 @@ final class NormalizerDataReader implements ICUBinary.Authenticate { throws IOException{ //Read the bytes that make up the normTrie - dataInputStream.read(normBytes); + dataInputStream.readFully(normBytes); //normTrieStream= new ByteArrayInputStream(normBytes); @@ -346,11 +345,11 @@ final class NormalizerDataReader implements ICUBinary.Authenticate { } //Read the fcdTrie - dataInputStream.read(fcdBytes); + dataInputStream.readFully(fcdBytes); //Read the AuxTrie - dataInputStream.read(auxBytes); + dataInputStream.readFully(auxBytes); } public byte[] getDataFormatVersion(){ diff --git a/src/share/classes/sun/text/normalizer/NormalizerImpl.java b/src/share/classes/sun/text/normalizer/NormalizerImpl.java index cd4669063c6fa0a8b61f1279617440ce1a3c6dd1..112afb0dac0b3c3876dac0739494e4afb745848e 100644 --- a/src/share/classes/sun/text/normalizer/NormalizerImpl.java +++ b/src/share/classes/sun/text/normalizer/NormalizerImpl.java @@ -1,5 +1,5 @@ /* - * Portions Copyright 2003-2006 Sun Microsystems, Inc. All Rights Reserved. + * Portions Copyright 2005-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 @@ -22,10 +22,9 @@ * CA 95054 USA or visit www.sun.com if you need additional information or * have any questions. */ - /* ******************************************************************************* - * (C) Copyright IBM Corp. 1996-2005 - All Rights Reserved * + * (C) Copyright IBM Corp. and others, 1996-2009 - All Rights Reserved * * * * The original version of this source code and documentation is copyrighted * * and owned by IBM, These materials are provided under terms of a License * @@ -102,7 +101,7 @@ public final class NormalizerImpl { private static final long MIN_SPECIAL = (long)(0xfc000000 & UNSIGNED_INT_MASK); private static final long SURROGATES_TOP = (long)(0xfff00000 & UNSIGNED_INT_MASK); private static final long MIN_HANGUL = (long)(0xfff00000 & UNSIGNED_INT_MASK); - private static final long MIN_JAMO_V = (long)(0xfff20000 & UNSIGNED_INT_MASK); +// private static final long MIN_JAMO_V = (long)(0xfff20000 & UNSIGNED_INT_MASK); private static final long JAMO_V_TOP = (long)(0xfff30000 & UNSIGNED_INT_MASK); @@ -908,7 +907,7 @@ public final class NormalizerImpl { buffer = composePart(args,prevStarter,src,srcStart,srcLimit,options,nx); // compare the normalized version with the original - if(0!=strCompare(buffer,0,args.length,src,prevStarter,(srcStart-prevStarter), false)) { + if(0!=strCompare(buffer,0,args.length,src,prevStarter,srcStart, false)) { result=NormalizerBase.NO; // normalization differs break; } @@ -2291,7 +2290,7 @@ public final class NormalizerImpl { private static final int OPTIONS_NX_MASK=0x1f; private static final int OPTIONS_UNICODE_MASK=0xe0; public static final int OPTIONS_SETS_MASK=0xff; - private static final int OPTIONS_UNICODE_SHIFT=5; +// private static final int OPTIONS_UNICODE_SHIFT=5; private static final UnicodeSet[] nxCache = new UnicodeSet[OPTIONS_SETS_MASK+1]; /* Constants for options flags for normalization.*/ diff --git a/src/share/classes/sun/text/normalizer/Trie.java b/src/share/classes/sun/text/normalizer/Trie.java index 378a6005c1cfd82d87d65837d6ab4c873a05df3a..16c0f92108985ec7e8b43b074ecd744e0cfe6454 100644 --- a/src/share/classes/sun/text/normalizer/Trie.java +++ b/src/share/classes/sun/text/normalizer/Trie.java @@ -1,5 +1,5 @@ /* - * Portions Copyright 2003-2005 Sun Microsystems, Inc. All Rights Reserved. + * Portions Copyright 2005-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 @@ -22,10 +22,9 @@ * CA 95054 USA or visit www.sun.com if you need additional information or * have any questions. */ - /* ******************************************************************************* - * (C) Copyright IBM Corp. 1996-2005 - All Rights Reserved * + * (C) Copyright IBM Corp. and others, 1996-2009 - All Rights Reserved * * * * The original version of this source code and documentation is copyrighted * * and owned by IBM, These materials are provided under terms of a License * @@ -37,10 +36,9 @@ package sun.text.normalizer; -import java.io.InputStream; import java.io.DataInputStream; +import java.io.InputStream; import java.io.IOException; -import java.util.Arrays; /** * <p>A trie is a kind of compressed, serializable table of values @@ -81,7 +79,6 @@ public abstract class Trie * This interface specifies methods to be implemented in order for * com.ibm.impl.Trie, to surrogate offset information encapsulated within * the data. - * @draft 2.1 */ public static interface DataManipulate { @@ -92,11 +89,17 @@ public abstract class Trie * @param value data value for a surrogate from the trie, including the * folding offset * @return data offset or 0 if there is no data for the lead surrogate - * @draft 2.1 */ public int getFoldingOffset(int value); } + // default implementation + private static class DefaultGetFoldingOffset implements DataManipulate { + public int getFoldingOffset(int value) { + return value; + } + } + // protected constructor ------------------------------------------- /** @@ -107,7 +110,6 @@ public abstract class Trie * trie data * @throws IOException thrown when input stream does not have the * right header. - * @draft 2.1 */ protected Trie(InputStream inputStream, DataManipulate dataManipulate) throws IOException @@ -121,7 +123,11 @@ public abstract class Trie throw new IllegalArgumentException("ICU data file error: Trie header authentication failed, please check if you have the most updated ICU data file"); } - m_dataManipulate_ = dataManipulate; + if(dataManipulate != null) { + m_dataManipulate_ = dataManipulate; + } else { + m_dataManipulate_ = new DefaultGetFoldingOffset(); + } m_isLatin1Linear_ = (m_options_ & HEADER_OPTIONS_LATIN1_IS_LINEAR_MASK_) != 0; m_dataOffset_ = input.readInt(); @@ -135,19 +141,21 @@ public abstract class Trie * @param options used by the trie * @param dataManipulate object containing the information to parse the * trie data - * @draft 2.2 */ protected Trie(char index[], int options, DataManipulate dataManipulate) { m_options_ = options; - m_dataManipulate_ = dataManipulate; + if(dataManipulate != null) { + m_dataManipulate_ = dataManipulate; + } else { + m_dataManipulate_ = new DefaultGetFoldingOffset(); + } m_isLatin1Linear_ = (m_options_ & HEADER_OPTIONS_LATIN1_IS_LINEAR_MASK_) != 0; m_index_ = index; m_dataOffset_ = m_index_.length; } - // protected data members ------------------------------------------ /** @@ -158,7 +166,6 @@ public abstract class Trie protected static final int LEAD_INDEX_OFFSET_ = 0x2800 >> 5; /** * Shift size for shifting right the input index. 1..9 - * @draft 2.1 */ protected static final int INDEX_STAGE_1_SHIFT_ = 5; /** @@ -168,31 +175,39 @@ public abstract class Trie * This requires blocks of stage 2 data to be aligned by * DATA_GRANULARITY. * 0..INDEX_STAGE_1_SHIFT - * @draft 2.1 */ protected static final int INDEX_STAGE_2_SHIFT_ = 2; + /** + * Number of data values in a stage 2 (data array) block. + */ + protected static final int DATA_BLOCK_LENGTH=1<<INDEX_STAGE_1_SHIFT_; /** * Mask for getting the lower bits from the input index. - * DATA_BLOCK_LENGTH_ - 1. - * @draft 2.1 + * DATA_BLOCK_LENGTH - 1. */ - protected static final int INDEX_STAGE_3_MASK_ = - (1 << INDEX_STAGE_1_SHIFT_) - 1; + protected static final int INDEX_STAGE_3_MASK_ = DATA_BLOCK_LENGTH - 1; + /** Number of bits of a trail surrogate that are used in index table lookups. */ + protected static final int SURROGATE_BLOCK_BITS=10-INDEX_STAGE_1_SHIFT_; + /** + * Number of index (stage 1) entries per lead surrogate. + * Same as number of index entries for 1024 trail surrogates, + * ==0x400>>INDEX_STAGE_1_SHIFT_ + */ + protected static final int SURROGATE_BLOCK_COUNT=(1<<SURROGATE_BLOCK_BITS); + /** Length of the BMP portion of the index (stage 1) array. */ + protected static final int BMP_INDEX_LENGTH=0x10000>>INDEX_STAGE_1_SHIFT_; /** * Surrogate mask to use when shifting offset to retrieve supplementary * values - * @draft 2.1 */ protected static final int SURROGATE_MASK_ = 0x3FF; /** * Index or UTF16 characters - * @draft 2.1 */ protected char m_index_[]; /** * Internal TrieValue which handles the parsing of the data value. * This class is to be implemented by the user - * @draft 2.1 */ protected DataManipulate m_dataManipulate_; /** @@ -200,7 +215,6 @@ public abstract class Trie * index and data into a char array, so this is used to indicate the * initial offset to the data portion. * Note this index always points to the initial value. - * @draft 2.1 */ protected int m_dataOffset_; /** @@ -215,7 +229,6 @@ public abstract class Trie * @param lead lead surrogate * @param trail trailing surrogate * @return offset to data - * @draft 2.1 */ protected abstract int getSurrogateOffset(char lead, char trail); @@ -223,14 +236,12 @@ public abstract class Trie * Gets the value at the argument index * @param index value at index will be retrieved * @return 32 bit value - * @draft 2.1 */ protected abstract int getValue(int index); /** * Gets the default initial value * @return 32 bit value - * @draft 2.1 */ protected abstract int getInitialValue(); @@ -247,7 +258,6 @@ public abstract class Trie * @param offset index offset which ch is to start from * @param ch index to be used after offset * @return offset to the data - * @draft 2.1 */ protected final int getRawOffset(int offset, char ch) { @@ -261,7 +271,6 @@ public abstract class Trie * Treats a lead surrogate as a normal code point. * @param ch BMP character * @return offset to data - * @draft 2.1 */ protected final int getBMPOffset(char ch) { @@ -279,7 +288,6 @@ public abstract class Trie * the next trailing surrogate character. * @param ch lead surrogate character * @return offset to data - * @draft 2.1 */ protected final int getLeadOffset(char ch) { @@ -293,26 +301,27 @@ public abstract class Trie * Gets the offset to data which the codepoint points to * @param ch codepoint * @return offset to data - * @draft 2.1 */ protected final int getCodePointOffset(int ch) { // if ((ch >> 16) == 0) slower - if (ch >= UTF16.CODEPOINT_MIN_VALUE - && ch < UTF16.SUPPLEMENTARY_MIN_VALUE) { + if (ch < 0) { + return -1; + } else if (ch < UTF16.LEAD_SURROGATE_MIN_VALUE) { + // fastpath for the part of the BMP below surrogates (D800) where getRawOffset() works + return getRawOffset(0, (char)ch); + } else if (ch < UTF16.SUPPLEMENTARY_MIN_VALUE) { // BMP codepoint return getBMPOffset((char)ch); - } - // for optimization - if (ch >= UTF16.CODEPOINT_MIN_VALUE - && ch <= UCharacter.MAX_VALUE) { + } else if (ch <= UCharacter.MAX_VALUE) { // look at the construction of supplementary characters // trail forms the ends of it. return getSurrogateOffset(UTF16.getLeadSurrogate(ch), (char)(ch & SURROGATE_MASK_)); + } else { + // return -1 // if there is an error, in this case we return + return -1; } - // return -1 if there is an error, in this case we return - return -1; } /** @@ -320,7 +329,6 @@ public abstract class Trie * <p>This is overwritten by the child classes. * @param inputStream input stream containing the trie information * @exception IOException thrown when data reading fails. - * @draft 2.1 */ protected void unserialize(InputStream inputStream) throws IOException { @@ -335,7 +343,6 @@ public abstract class Trie /** * Determines if this is a 32 bit trie * @return true if options specifies this is a 32 bit trie - * @draft 2.1 */ protected final boolean isIntTrie() { @@ -345,7 +352,6 @@ public abstract class Trie /** * Determines if this is a 16 bit trie * @return true if this is a 16 bit trie - * @draft 2.1 */ protected final boolean isCharTrie() { @@ -354,40 +360,20 @@ public abstract class Trie // private data members -------------------------------------------- - /** - * Signature index - */ - private static final int HEADER_SIGNATURE_INDEX_ = 0; - /** - * Options index - */ - private static final int HEADER_OPTIONS_INDEX_ = 1 << 1; - /** - * Index length index - */ - private static final int HEADER_INDEX_LENGTH_INDEX_ = 2 << 1; - /** - * Data length index - */ - private static final int HEADER_DATA_LENGTH_INDEX_ = 3 << 1; - /** - * Size of header - */ - private static final int HEADER_LENGTH_ = 4 << 1; /** * Latin 1 option mask */ - private static final int HEADER_OPTIONS_LATIN1_IS_LINEAR_MASK_ = 0x200; + protected static final int HEADER_OPTIONS_LATIN1_IS_LINEAR_MASK_ = 0x200; /** * Constant number to authenticate the byte block */ - private static final int HEADER_SIGNATURE_ = 0x54726965; + protected static final int HEADER_SIGNATURE_ = 0x54726965; /** * Header option formatting */ private static final int HEADER_OPTIONS_SHIFT_MASK_ = 0xF; - private static final int HEADER_OPTIONS_INDEX_SHIFT_ = 4; - private static final int HEADER_OPTIONS_DATA_IS_32_BIT_ = 0x100; + protected static final int HEADER_OPTIONS_INDEX_SHIFT_ = 4; + protected static final int HEADER_OPTIONS_DATA_IS_32_BIT_ = 0x100; /** * Flag indicator for Latin quick access data block @@ -409,9 +395,8 @@ public abstract class Trie /** * Authenticates raw data header. * Checking the header information, signature and options. - * @param rawdata array of char data to be checked + * @param signature This contains the options and type of a Trie * @return true if the header is authenticated valid - * @draft 2.1 */ private final boolean checkHeader(int signature) { diff --git a/src/share/classes/sun/text/normalizer/TrieIterator.java b/src/share/classes/sun/text/normalizer/TrieIterator.java index 9810c1002cba83f2c4efa9e28c03af2c3a3f1ce1..b29ab1c569b09d827d919bd28167c52ff1a05dbd 100644 --- a/src/share/classes/sun/text/normalizer/TrieIterator.java +++ b/src/share/classes/sun/text/normalizer/TrieIterator.java @@ -1,5 +1,5 @@ /* - * Portions Copyright 2005-2006 Sun Microsystems, Inc. All Rights Reserved. + * Portions Copyright 2005-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 @@ -22,10 +22,9 @@ * CA 95054 USA or visit www.sun.com if you need additional information or * have any questions. */ - /* ******************************************************************************* - * (C) Copyright IBM Corp. 1996-2005 - All Rights Reserved * + * (C) Copyright IBM Corp. and others, 1996-2009 - All Rights Reserved * * * * The original version of this source code and documentation is copyrighted * * and owned by IBM, These materials are provided under terms of a License * @@ -108,15 +107,14 @@ package sun.text.normalizer; * @since release 2.1, Jan 17 2002 */ public class TrieIterator implements RangeValueIterator - { + // public constructor --------------------------------------------- /** * TrieEnumeration constructor * @param trie to be used * @exception IllegalArgumentException throw when argument is null. - * @draft 2.1 */ public TrieIterator(Trie trie) { @@ -141,7 +139,6 @@ public class TrieIterator implements RangeValueIterator * @return true if we are not at the end of the iteration, false otherwise. * @exception NoSuchElementException - if no more elements exist. * @see com.ibm.icu.util.RangeValueIterator.Element - * @draft 2.1 */ public final boolean next(Element element) { @@ -158,7 +155,6 @@ public class TrieIterator implements RangeValueIterator /** * Resets the iterator to the beginning of the iteration - * @draft 2.1 */ public final void reset() { @@ -186,7 +182,6 @@ public class TrieIterator implements RangeValueIterator * The default function is to return the value as it is. * @param value a value from the trie * @return extracted value - * @draft 2.1 */ protected int extract(int value) { @@ -278,7 +273,6 @@ public class TrieIterator implements RangeValueIterator * Note, if there are no more iterations, it will never get to here. * Blocked out by next(). * @param element return result object - * @draft 2.1 */ private final void calculateNextSupplementaryElement(Element element) { @@ -516,10 +510,6 @@ public class TrieIterator implements RangeValueIterator */ private static final int TRAIL_SURROGATE_MIN_VALUE_ = 0xDC00; /** - * Trail surrogate maximum value - */ - private static final int TRAIL_SURROGATE_MAX_VALUE_ = 0xDFFF; - /** * Number of trail surrogate */ private static final int TRAIL_SURROGATE_COUNT_ = 0x400; @@ -538,11 +528,6 @@ public class TrieIterator implements RangeValueIterator private static final int DATA_BLOCK_LENGTH_ = 1 << Trie.INDEX_STAGE_1_SHIFT_; /** - * Number of codepoints in a stage 2 block - */ - private static final int DATA_BLOCK_SUPPLEMENTARY_LENGTH_ = - DATA_BLOCK_LENGTH_ << 10; - /** * Trie instance */ private Trie m_trie_; @@ -560,10 +545,4 @@ public class TrieIterator implements RangeValueIterator private int m_nextBlock_; private int m_nextBlockIndex_; private int m_nextTrailIndexOffset_; - /** - * This is the return result element - */ - private int m_start_; - private int m_limit_; - private int m_value_; } diff --git a/src/share/classes/sun/text/normalizer/UBiDiProps.java b/src/share/classes/sun/text/normalizer/UBiDiProps.java new file mode 100644 index 0000000000000000000000000000000000000000..0f5d960020362133d6b7625e7bc91a44dbf01c7c --- /dev/null +++ b/src/share/classes/sun/text/normalizer/UBiDiProps.java @@ -0,0 +1,179 @@ +/* + * Portions Copyright 2005-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. + */ +/* + ******************************************************************************* + * (C) Copyright IBM Corp. and others, 1996-2009 - All Rights Reserved * + * * + * The original version of this source code and documentation is copyrighted * + * and owned by IBM, These materials are provided under terms of a License * + * Agreement between IBM and Sun. This technology is protected by multiple * + * US and International patents. This notice and attribution to IBM may not * + * to removed. * + ******************************************************************************* +* file name: UBiDiProps.java +* encoding: US-ASCII +* tab size: 8 (not used) +* indentation:4 +* +* created on: 2005jan16 +* created by: Markus W. Scherer +* +* Low-level Unicode bidi/shaping properties access. +* Java port of ubidi_props.h/.c. +*/ + +package sun.text.normalizer; + +import java.io.BufferedInputStream; +import java.io.DataInputStream; +import java.io.InputStream; +import java.io.IOException; + +public final class UBiDiProps { + // constructors etc. --------------------------------------------------- *** + + // port of ubidi_openProps() + public UBiDiProps() throws IOException{ + InputStream is=ICUData.getStream(DATA_FILE_NAME); + BufferedInputStream b=new BufferedInputStream(is, 4096 /* data buffer size */); + readData(b); + b.close(); + is.close(); + + } + + private void readData(InputStream is) throws IOException { + DataInputStream inputStream=new DataInputStream(is); + + // read the header + ICUBinary.readHeader(inputStream, FMT, new IsAcceptable()); + + // read indexes[] + int i, count; + count=inputStream.readInt(); + if(count<IX_INDEX_TOP) { + throw new IOException("indexes[0] too small in "+DATA_FILE_NAME); + } + indexes=new int[count]; + + indexes[0]=count; + for(i=1; i<count; ++i) { + indexes[i]=inputStream.readInt(); + } + + // read the trie + trie=new CharTrie(inputStream, null); + + // read mirrors[] + count=indexes[IX_MIRROR_LENGTH]; + if(count>0) { + mirrors=new int[count]; + for(i=0; i<count; ++i) { + mirrors[i]=inputStream.readInt(); + } + } + + // read jgArray[] + count=indexes[IX_JG_LIMIT]-indexes[IX_JG_START]; + jgArray=new byte[count]; + for(i=0; i<count; ++i) { + jgArray[i]=inputStream.readByte(); + } + } + + // implement ICUBinary.Authenticate + private final class IsAcceptable implements ICUBinary.Authenticate { + public boolean isDataVersionAcceptable(byte version[]) { + return version[0]==1 && + version[2]==Trie.INDEX_STAGE_1_SHIFT_ && version[3]==Trie.INDEX_STAGE_2_SHIFT_; + } + } + + // UBiDiProps singleton + private static UBiDiProps gBdp=null; + + // port of ubidi_getSingleton() + public static final synchronized UBiDiProps getSingleton() throws IOException { + if(gBdp==null) { + gBdp=new UBiDiProps(); + } + return gBdp; + } + + // UBiDiProps dummy singleton + private static UBiDiProps gBdpDummy=null; + + private UBiDiProps(boolean makeDummy) { // ignore makeDummy, only creates a unique signature + indexes=new int[IX_TOP]; + indexes[0]=IX_TOP; + trie=new CharTrie(0, 0, null); // dummy trie, always returns 0 + } + + /** + * Get a singleton dummy object, one that works with no real data. + * This can be used when the real data is not available. + * Using the dummy can reduce checks for available data after an initial failure. + * Port of ucase_getDummy(). + */ + public static final synchronized UBiDiProps getDummy() { + if(gBdpDummy==null) { + gBdpDummy=new UBiDiProps(true); + } + return gBdpDummy; + } + + public final int getClass(int c) { + return getClassFromProps(trie.getCodePointValue(c)); + } + + // data members -------------------------------------------------------- *** + private int indexes[]; + private int mirrors[]; + private byte jgArray[]; + + private CharTrie trie; + + // data format constants ----------------------------------------------- *** + private static final String DATA_FILE_NAME = "/sun/text/resources/ubidi.icu"; + + /* format "BiDi" */ + private static final byte FMT[]={ 0x42, 0x69, 0x44, 0x69 }; + + /* indexes into indexes[] */ + private static final int IX_INDEX_TOP=0; + private static final int IX_MIRROR_LENGTH=3; + + private static final int IX_JG_START=4; + private static final int IX_JG_LIMIT=5; + + private static final int IX_TOP=16; + + private static final int CLASS_MASK= 0x0000001f; + + private static final int getClassFromProps(int props) { + return props&CLASS_MASK; + } + +} diff --git a/src/share/classes/sun/text/normalizer/UCharacter.java b/src/share/classes/sun/text/normalizer/UCharacter.java index 26a5eca99fce1191cd34863e666f8065ae7cfd74..8225517f07cd9c5b2dda4f1744507867ab5c7c26 100644 --- a/src/share/classes/sun/text/normalizer/UCharacter.java +++ b/src/share/classes/sun/text/normalizer/UCharacter.java @@ -1,5 +1,5 @@ /* - * Portions Copyright 2005 Sun Microsystems, Inc. All Rights Reserved. + * Portions Copyright 2005-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 @@ -24,7 +24,7 @@ */ /* ******************************************************************************* - * (C) Copyright IBM Corp. 1996-2005 - All Rights Reserved * + * (C) Copyright IBM Corp. and others, 1996-2009 - All Rights Reserved * * * * The original version of this source code and documentation is copyrighted * * and owned by IBM, These materials are provided under terms of a License * @@ -36,19 +36,18 @@ package sun.text.normalizer; -import java.lang.ref.SoftReference; -import java.util.HashMap; -import java.util.Locale; -import java.util.Map; +import java.io.IOException; +import java.util.MissingResourceException; /** * <p> * The UCharacter class provides extensions to the - * <a href=http://java.sun.com/j2se/1.3/docs/api/java/lang/Character.html> + * <a href="http://java.sun.com/j2se/1.5/docs/api/java/lang/Character.html"> * java.lang.Character</a> class. These extensions provide support for - * Unicode 3.2 properties and together with the <a href=../text/UTF16.html>UTF16</a> + * more Unicode properties and together with the <a href=../text/UTF16.html>UTF16</a> * class, provide support for supplementary characters (those with code * points above U+FFFF). + * Each ICU release supports the latest version of Unicode available at that time. * </p> * <p> * Code points are represented in these API using ints. While it would be @@ -67,7 +66,7 @@ import java.util.Map; * <i>$ICU4J_CLASS/com.ibm.icu.impl.data</i>. * </p> * <p> - * Aside from the additions for UTF-16 support, and the updated Unicode 3.1 + * Aside from the additions for UTF-16 support, and the updated Unicode * properties, the main differences between UCharacter and Character are: * <ul> * <li> UCharacter is not designed to be a char wrapper and does not have @@ -77,7 +76,7 @@ import java.util.Map; * <li> char charValue(), * <li> int compareTo(java.lang.Character, java.lang.Character), etc. * </ul> - * <li> UCharacter does not include Character APIs that are deprecated, not + * <li> UCharacter does not include Character APIs that are deprecated, nor * does it include the Java-specific character information, such as * boolean isJavaIdentifierPart(char ch). * <li> Character maps characters 'A' - 'Z' and 'a' - 'z' to the numeric @@ -89,10 +88,75 @@ import java.util.Map; * </ul> * <p> * Further detail differences can be determined from the program - * <a href = http://oss.software.ibm.com/developerworks/opensource/cvs/icu4j/~checkout~/icu4j/src/com/ibm/icu/dev/test/lang/UCharacterCompare.java> + * <a href="http://source.icu-project.org/repos/icu/icu4j/trunk/src/com/ibm/icu/dev/test/lang/UCharacterCompare.java"> * com.ibm.icu.dev.test.lang.UCharacterCompare</a> * </p> * <p> + * In addition to Java compatibility functions, which calculate derived properties, + * this API provides low-level access to the Unicode Character Database. + * </p> + * <p> + * Unicode assigns each code point (not just assigned character) values for + * many properties. + * Most of them are simple boolean flags, or constants from a small enumerated list. + * For some properties, values are strings or other relatively more complex types. + * </p> + * <p> + * For more information see + * "About the Unicode Character Database" (http://www.unicode.org/ucd/) + * and the ICU User Guide chapter on Properties (http://www.icu-project.org/userguide/properties.html). + * </p> + * <p> + * There are also functions that provide easy migration from C/POSIX functions + * like isblank(). Their use is generally discouraged because the C/POSIX + * standards do not define their semantics beyond the ASCII range, which means + * that different implementations exhibit very different behavior. + * Instead, Unicode properties should be used directly. + * </p> + * <p> + * There are also only a few, broad C/POSIX character classes, and they tend + * to be used for conflicting purposes. For example, the "isalpha()" class + * is sometimes used to determine word boundaries, while a more sophisticated + * approach would at least distinguish initial letters from continuation + * characters (the latter including combining marks). + * (In ICU, BreakIterator is the most sophisticated API for word boundaries.) + * Another example: There is no "istitle()" class for titlecase characters. + * </p> + * <p> + * ICU 3.4 and later provides API access for all twelve C/POSIX character classes. + * ICU implements them according to the Standard Recommendations in + * Annex C: Compatibility Properties of UTS #18 Unicode Regular Expressions + * (http://www.unicode.org/reports/tr18/#Compatibility_Properties). + * </p> + * <p> + * API access for C/POSIX character classes is as follows: + * - alpha: isUAlphabetic(c) or hasBinaryProperty(c, UProperty.ALPHABETIC) + * - lower: isULowercase(c) or hasBinaryProperty(c, UProperty.LOWERCASE) + * - upper: isUUppercase(c) or hasBinaryProperty(c, UProperty.UPPERCASE) + * - punct: ((1<<getType(c)) & ((1<<DASH_PUNCTUATION)|(1<<START_PUNCTUATION)|(1<<END_PUNCTUATION)|(1<<CONNECTOR_PUNCTUATION)|(1<<OTHER_PUNCTUATION)|(1<<INITIAL_PUNCTUATION)|(1<<FINAL_PUNCTUATION)))!=0 + * - digit: isDigit(c) or getType(c)==DECIMAL_DIGIT_NUMBER + * - xdigit: hasBinaryProperty(c, UProperty.POSIX_XDIGIT) + * - alnum: hasBinaryProperty(c, UProperty.POSIX_ALNUM) + * - space: isUWhiteSpace(c) or hasBinaryProperty(c, UProperty.WHITE_SPACE) + * - blank: hasBinaryProperty(c, UProperty.POSIX_BLANK) + * - cntrl: getType(c)==CONTROL + * - graph: hasBinaryProperty(c, UProperty.POSIX_GRAPH) + * - print: hasBinaryProperty(c, UProperty.POSIX_PRINT) + * </p> + * <p> + * The C/POSIX character classes are also available in UnicodeSet patterns, + * using patterns like [:graph:] or \p{graph}. + * </p> + * <p> + * Note: There are several ICU (and Java) whitespace functions. + * Comparison: + * - isUWhiteSpace=UCHAR_WHITE_SPACE: Unicode White_Space property; + * most of general categories "Z" (separators) + most whitespace ISO controls + * (including no-break spaces, but excluding IS1..IS4 and ZWSP) + * - isWhitespace: Java isWhitespace; Z + whitespace ISO controls but excluding no-break spaces + * - isSpaceChar: just Z (including no-break spaces) + * </p> + * <p> * This class is not subclassable * </p> * @author Syn Wee Quek @@ -110,95 +174,10 @@ public final class UCharacter */ public static interface NumericType { - /** - * @stable ICU 2.4 - */ - public static final int NONE = 0; /** * @stable ICU 2.4 */ public static final int DECIMAL = 1; - /** - * @stable ICU 2.4 - */ - public static final int DIGIT = 2; - /** - * @stable ICU 2.4 - */ - public static final int NUMERIC = 3; - /** - * @stable ICU 2.4 - */ - public static final int COUNT = 4; - } - - /** - * Hangul Syllable Type constants. - * - * @see UProperty#HANGUL_SYLLABLE_TYPE - * @stable ICU 2.6 - */ - public static interface HangulSyllableType - { - /** - * @stable ICU 2.6 - */ - public static final int NOT_APPLICABLE = 0; /*[NA]*/ /*See note !!*/ - /** - * @stable ICU 2.6 - */ - public static final int LEADING_JAMO = 1; /*[L]*/ - /** - * @stable ICU 2.6 - */ - public static final int VOWEL_JAMO = 2; /*[V]*/ - /** - * @stable ICU 2.6 - */ - public static final int TRAILING_JAMO = 3; /*[T]*/ - /** - * @stable ICU 2.6 - */ - public static final int LV_SYLLABLE = 4; /*[LV]*/ - /** - * @stable ICU 2.6 - */ - public static final int LVT_SYLLABLE = 5; /*[LVT]*/ - /** - * @stable ICU 2.6 - */ - public static final int COUNT = 6; - } - - /** - * [Sun] This interface moved from UCharacterEnums.java. - * - * 'Enum' for the CharacterCategory constants. These constants are - * compatible in name <b>but not in value</b> with those defined in - * <code>java.lang.Character</code>. - * @see UCharacterCategory - * @draft ICU 3.0 - * @deprecated This is a draft API and might change in a future release of ICU. - */ - public static interface ECharacterCategory - { - /** - * Character type Lu - * @stable ICU 2.1 - */ - public static final int UPPERCASE_LETTER = 1; - - /** - * Character type Lt - * @stable ICU 2.1 - */ - public static final int TITLECASE_LETTER = 3; - - /** - * Character type Lo - * @stable ICU 2.1 - */ - public static final int OTHER_LETTER = 5; } // public data members ----------------------------------------------- @@ -225,14 +204,6 @@ public final class UCharacter public static final int SUPPLEMENTARY_MIN_VALUE = UTF16.SUPPLEMENTARY_MIN_VALUE; - /** - * Special value that is returned by getUnicodeNumericValue(int) when no - * numeric value is defined for a code point. - * @stable ICU 2.4 - * @see #getUnicodeNumericValue - */ - public static final double NO_NUMERIC_VALUE = -123456789; - // public methods ---------------------------------------------------- /** @@ -262,139 +233,30 @@ public final class UCharacter { // when ch is out of bounds getProperty == 0 int props = getProperty(ch); - if (getNumericType(props) != NumericType.DECIMAL) { - return (radix <= 10) ? -1 : getEuropeanDigit(ch); - } - // if props == 0, it will just fall through and return -1 - if (isNotExceptionIndicator(props)) { - // not contained in exception data - // getSignedValue is just shifting so we can check for the sign - // first - // Optimization - // int result = UCharacterProperty.getSignedValue(props); - // if (result >= 0) { - // return result; - // } - if (props >= 0) { - return UCharacterProperty.getSignedValue(props); - } - } - else { - int index = UCharacterProperty.getExceptionIndex(props); - if (PROPERTY_.hasExceptionValue(index, - UCharacterProperty.EXC_NUMERIC_VALUE_)) { - int result = PROPERTY_.getException(index, - UCharacterProperty.EXC_NUMERIC_VALUE_); - if (result >= 0) { - return result; - } - } - } - - if (radix > 10) { - int result = getEuropeanDigit(ch); - if (result >= 0 && result < radix) { - return result; - } - } - return -1; - } - - /** - * <p>Get the numeric value for a Unicode code point as defined in the - * Unicode Character Database.</p> - * <p>A "double" return type is necessary because some numeric values are - * fractions, negative, or too large for int.</p> - * <p>For characters without any numeric values in the Unicode Character - * Database, this function will return NO_NUMERIC_VALUE.</p> - * <p><em>API Change:</em> In release 2.2 and prior, this API has a - * return type int and returns -1 when the argument ch does not have a - * corresponding numeric value. This has been changed to synch with ICU4C - * </p> - * This corresponds to the ICU4C function u_getNumericValue. - * @param ch Code point to get the numeric value for. - * @return numeric value of ch, or NO_NUMERIC_VALUE if none is defined. - * @stable ICU 2.4 - */ - public static double getUnicodeNumericValue(int ch) - { - // equivalent to c version double u_getNumericValue(UChar32 c) - int props = PROPERTY_.getProperty(ch); - int numericType = getNumericType(props); - if (numericType > NumericType.NONE && numericType < NumericType.COUNT) { - if (isNotExceptionIndicator(props)) { - return UCharacterProperty.getSignedValue(props); - } - else { - int index = UCharacterProperty.getExceptionIndex(props); - boolean nex = false; - boolean dex = false; - double numerator = 0; - if (PROPERTY_.hasExceptionValue(index, - UCharacterProperty.EXC_NUMERIC_VALUE_)) { - int num = PROPERTY_.getException(index, - UCharacterProperty.EXC_NUMERIC_VALUE_); - // There are special values for huge numbers that are - // powers of ten. genprops/store.c documents: - // if numericValue = 0x7fffff00 + x then - // numericValue = 10 ^ x - if (num >= NUMERATOR_POWER_LIMIT_) { - num &= 0xff; - // 10^x without math.h - numerator = Math.pow(10, num); - } - else { - numerator = num; - } - nex = true; - } - double denominator = 0; - if (PROPERTY_.hasExceptionValue(index, - UCharacterProperty.EXC_DENOMINATOR_VALUE_)) { - denominator = PROPERTY_.getException(index, - UCharacterProperty.EXC_DENOMINATOR_VALUE_); - // faster path not in c - if (numerator != 0) { - return numerator / denominator; - } - dex = true; - } - - if (nex) { - if (dex) { - return numerator / denominator; - } - return numerator; - } - if (dex) { - return 1 / denominator; - } - } + int value; + if (getNumericType(props) == NumericType.DECIMAL) { + value = UCharacterProperty.getUnsignedValue(props); + } else { + value = getEuropeanDigit(ch); } - return NO_NUMERIC_VALUE; + return (0 <= value && value < radix) ? value : -1; } /** - * Returns a value indicating a code point's Unicode category. - * Up-to-date Unicode implementation of java.lang.Character.getType() - * except for the above mentioned code points that had their category - * changed.<br> - * Return results are constants from the interface - * <a href=UCharacterCategory.html>UCharacterCategory</a><br> - * <em>NOTE:</em> the UCharacterCategory values are <em>not</em> compatible with - * those returned by java.lang.Character.getType. UCharacterCategory values - * match the ones used in ICU4C, while java.lang.Character type - * values, though similar, skip the value 17.</p> - * @param ch code point whose type is to be determined - * @return category which is a value of UCharacterCategory + * Returns the Bidirection property of a code point. + * For example, 0x0041 (letter A) has the LEFT_TO_RIGHT directional + * property.<br> + * Result returned belongs to the interface + * <a href=UCharacterDirection.html>UCharacterDirection</a> + * @param ch the code point to be determined its direction + * @return direction constant from UCharacterDirection. * @stable ICU 2.1 */ - public static int getType(int ch) + public static int getDirection(int ch) { - return getProperty(ch) & UCharacterProperty.TYPE_MASK; + return gBdp.getClass(ch); } - //// for StringPrep /** * Returns a code point corresponding to the two UTF16 characters. * @param lead the lead char @@ -406,135 +268,12 @@ public final class UCharacter */ public static int getCodePoint(char lead, char trail) { - if (lead >= UTF16.LEAD_SURROGATE_MIN_VALUE && - lead <= UTF16.LEAD_SURROGATE_MAX_VALUE && - trail >= UTF16.TRAIL_SURROGATE_MIN_VALUE && - trail <= UTF16.TRAIL_SURROGATE_MAX_VALUE) { + if (UTF16.isLeadSurrogate(lead) && UTF16.isTrailSurrogate(trail)) { return UCharacterProperty.getRawSupplementary(lead, trail); } throw new IllegalArgumentException("Illegal surrogate characters"); } - //// for StringPrep - /** - * Returns the Bidirection property of a code point. - * For example, 0x0041 (letter A) has the LEFT_TO_RIGHT directional - * property.<br> - * Result returned belongs to the interface - * <a href=UCharacterDirection.html>UCharacterDirection</a> - * @param ch the code point to be determined its direction - * @return direction constant from UCharacterDirection. - * @stable ICU 2.1 - */ - public static int getDirection(int ch) - { - // when ch is out of bounds getProperty == 0 - return (getProperty(ch) >> BIDI_SHIFT_) & BIDI_MASK_AFTER_SHIFT_; - } - - /** - * The given string is mapped to its case folding equivalent according to - * UnicodeData.txt and CaseFolding.txt; if any character has no case - * folding equivalent, the character itself is returned. - * "Full", multiple-code point case folding mappings are returned here. - * For "simple" single-code point mappings use the API - * foldCase(int ch, boolean defaultmapping). - * @param str the String to be converted - * @param defaultmapping Indicates if all mappings defined in - * CaseFolding.txt is to be used, otherwise the - * mappings for dotted I and dotless i marked with - * 'I' in CaseFolding.txt will be skipped. - * @return the case folding equivalent of the character, if - * any; otherwise the character itself. - * @see #foldCase(int, boolean) - * @stable ICU 2.1 - */ - public static String foldCase(String str, boolean defaultmapping) - { - int size = str.length(); - StringBuffer result = new StringBuffer(size); - int offset = 0; - int ch; - - // case mapping loop - while (offset < size) { - ch = UTF16.charAt(str, offset); - offset += UTF16.getCharCount(ch); - int props = PROPERTY_.getProperty(ch); - if (isNotExceptionIndicator(props)) { - int type = UCharacterProperty.TYPE_MASK & props; - if (type == ECharacterCategory.UPPERCASE_LETTER || - type == ECharacterCategory.TITLECASE_LETTER) { - ch += UCharacterProperty.getSignedValue(props); - } - } - else { - int index = UCharacterProperty.getExceptionIndex(props); - if (PROPERTY_.hasExceptionValue(index, - UCharacterProperty.EXC_CASE_FOLDING_)) { - int exception = PROPERTY_.getException(index, - UCharacterProperty.EXC_CASE_FOLDING_); - if (exception != 0) { - PROPERTY_.getFoldCase(exception & LAST_CHAR_MASK_, - exception >> SHIFT_24_, result); - } - else { - // special case folding mappings, hardcoded - if (ch != 0x49 && ch != 0x130) { - // return ch itself because there is no special - // mapping for it - UTF16.append(result, ch); - continue; - } - if (defaultmapping) { - // default mappings - if (ch == 0x49) { - // 0049; C; 0069; # LATIN CAPITAL LETTER I - result.append( - UCharacterProperty.LATIN_SMALL_LETTER_I_); - } - else if (ch == 0x130) { - // 0130; F; 0069 0307; - // # LATIN CAPITAL LETTER I WITH DOT ABOVE - result.append( - UCharacterProperty.LATIN_SMALL_LETTER_I_); - result.append((char)0x307); - } - } - else { - // Turkic mappings - if (ch == 0x49) { - // 0049; T; 0131; # LATIN CAPITAL LETTER I - result.append((char)0x131); - } - else if (ch == 0x130) { - // 0130; T; 0069; - // # LATIN CAPITAL LETTER I WITH DOT ABOVE - result.append( - UCharacterProperty.LATIN_SMALL_LETTER_I_); - } - } - } - // do not fall through to the output of c - continue; - } - else { - if (PROPERTY_.hasExceptionValue(index, - UCharacterProperty.EXC_LOWERCASE_)) { - ch = PROPERTY_.getException(index, - UCharacterProperty.EXC_LOWERCASE_); - } - } - - } - - // handle 1:1 code point mappings from UnicodeData.txt - UTF16.append(result, ch); - } - - return result.toString(); - } - /** * <p>Get the "age" of the code point.</p> * <p>The "age" is the Unicode version when the code point was first @@ -555,83 +294,6 @@ public final class UCharacter return PROPERTY_.getAge(ch); } - /** - * <p>Gets the property value for an Unicode property type of a code point. - * Also returns binary and mask property values.</p> - * <p>Unicode, especially in version 3.2, defines many more properties than - * the original set in UnicodeData.txt.</p> - * <p>The properties APIs are intended to reflect Unicode properties as - * defined in the Unicode Character Database (UCD) and Unicode Technical - * Reports (UTR). For details about the properties see - * http://www.unicode.org/.</p> - * <p>For names of Unicode properties see the UCD file PropertyAliases.txt. - * </p> - * <pre> - * Sample usage: - * int ea = UCharacter.getIntPropertyValue(c, UProperty.EAST_ASIAN_WIDTH); - * int ideo = UCharacter.getIntPropertyValue(c, UProperty.IDEOGRAPHIC); - * boolean b = (ideo == 1) ? true : false; - * </pre> - * @param ch code point to test. - * @param type UProperty selector constant, identifies which binary - * property to check. Must be - * UProperty.BINARY_START <= type < UProperty.BINARY_LIMIT or - * UProperty.INT_START <= type < UProperty.INT_LIMIT or - * UProperty.MASK_START <= type < UProperty.MASK_LIMIT. - * @return numeric value that is directly the property value or, - * for enumerated properties, corresponds to the numeric value of - * the enumerated constant of the respective property value - * enumeration type (cast to enum type if necessary). - * Returns 0 or 1 (for false / true) for binary Unicode properties. - * Returns a bit-mask for mask properties. - * Returns 0 if 'type' is out of bounds or if the Unicode version - * does not have data for the property at all, or not for this code - * point. - * @see UProperty - * @see #hasBinaryProperty - * @see #getIntPropertyMinValue - * @see #getIntPropertyMaxValue - * @see #getUnicodeVersion - * @stable ICU 2.4 - */ - public static int getIntPropertyValue(int ch, int type) - { - /* - * For Normalizer with Unicode 3.2, this method is called only for - * HANGUL_SYLLABLE_TYPE in UnicodeSet.addPropertyStarts(). - */ - if (type == UProperty.HANGUL_SYLLABLE_TYPE) { - /* purely algorithmic; hardcode known characters, check for assigned new ones */ - if(ch<NormalizerImpl.JAMO_L_BASE) { - /* NA */ - } else if(ch<=0x11ff) { - /* Jamo range */ - if(ch<=0x115f) { - /* Jamo L range, HANGUL CHOSEONG ... */ - if(ch==0x115f || ch<=0x1159 || getType(ch)==ECharacterCategory.OTHER_LETTER) { - return HangulSyllableType.LEADING_JAMO; - } - } else if(ch<=0x11a7) { - /* Jamo V range, HANGUL JUNGSEONG ... */ - if(ch<=0x11a2 || getType(ch)==ECharacterCategory.OTHER_LETTER) { - return HangulSyllableType.VOWEL_JAMO; - } - } else { - /* Jamo T range */ - if(ch<=0x11f9 || getType(ch)==ECharacterCategory.OTHER_LETTER) { - return HangulSyllableType.TRAILING_JAMO; - } - } - } else if((ch-=NormalizerImpl.HANGUL_BASE)<0) { - /* NA */ - } else if(ch<NormalizerImpl.HANGUL_COUNT) { - /* Hangul syllable */ - return ch%NormalizerImpl.JAMO_T_COUNT==0 ? HangulSyllableType.LV_SYLLABLE : HangulSyllableType.LVT_SYLLABLE; - } - } - return 0; /* NA */ - } - // private variables ------------------------------------------------- /** @@ -643,143 +305,43 @@ public final class UCharacter */ private static final char[] PROPERTY_TRIE_INDEX_; private static final char[] PROPERTY_TRIE_DATA_; - private static final int[] PROPERTY_DATA_; private static final int PROPERTY_INITIAL_VALUE_; + private static final UBiDiProps gBdp; + // block to initialise character property database static { try { - PROPERTY_ = UCharacterProperty.getInstance(); - PROPERTY_TRIE_INDEX_ = PROPERTY_.m_trieIndex_; - PROPERTY_TRIE_DATA_ = PROPERTY_.m_trieData_; - PROPERTY_DATA_ = PROPERTY_.m_property_; - PROPERTY_INITIAL_VALUE_ - = PROPERTY_DATA_[PROPERTY_.m_trieInitialValue_]; + PROPERTY_ = UCharacterProperty.getInstance(); + PROPERTY_TRIE_INDEX_ = PROPERTY_.m_trieIndex_; + PROPERTY_TRIE_DATA_ = PROPERTY_.m_trieData_; + PROPERTY_INITIAL_VALUE_ = PROPERTY_.m_trieInitialValue_; } catch (Exception e) { - throw new RuntimeException(e.getMessage()); + throw new MissingResourceException(e.getMessage(),"",""); } - } - - /** - * To get the last character out from a data type - */ - private static final int LAST_CHAR_MASK_ = 0xFFFF; - - /** - * To get the last byte out from a data type - */ -// private static final int LAST_BYTE_MASK_ = 0xFF; - - /** - * Shift 16 bits - */ -// private static final int SHIFT_16_ = 16; - /** - * Shift 24 bits - */ - private static final int SHIFT_24_ = 24; + UBiDiProps bdp; + try { + bdp=UBiDiProps.getSingleton(); + } catch(IOException e) { + bdp=UBiDiProps.getDummy(); + } + gBdp=bdp; + } /** * Shift to get numeric type */ - private static final int NUMERIC_TYPE_SHIFT_ = 12; + private static final int NUMERIC_TYPE_SHIFT_ = 5; /** * Mask to get numeric type */ private static final int NUMERIC_TYPE_MASK_ = 0x7 << NUMERIC_TYPE_SHIFT_; - /** - * Shift to get bidi bits - */ - private static final int BIDI_SHIFT_ = 6; - /** - * Mask to be applied after shifting to get bidi bits - */ - private static final int BIDI_MASK_AFTER_SHIFT_ = 0x1F; - - /** - * <p>Numerator power limit. - * There are special values for huge numbers that are powers of ten.</p> - * <p>c version genprops/store.c documents: - * if numericValue = 0x7fffff00 + x then numericValue = 10 ^ x</p> - */ - private static final int NUMERATOR_POWER_LIMIT_ = 0x7fffff00; - /** - * Integer properties mask and shift values for joining type. - * Equivalent to icu4c UPROPS_JT_MASK. - */ - private static final int JOINING_TYPE_MASK_ = 0x00003800; - /** - * Integer properties mask and shift values for joining type. - * Equivalent to icu4c UPROPS_JT_SHIFT. - */ - private static final int JOINING_TYPE_SHIFT_ = 11; - /** - * Integer properties mask and shift values for joining group. - * Equivalent to icu4c UPROPS_JG_MASK. - */ - private static final int JOINING_GROUP_MASK_ = 0x000007e0; - /** - * Integer properties mask and shift values for joining group. - * Equivalent to icu4c UPROPS_JG_SHIFT. - */ - private static final int JOINING_GROUP_SHIFT_ = 5; - /** - * Integer properties mask for decomposition type. - * Equivalent to icu4c UPROPS_DT_MASK. - */ - private static final int DECOMPOSITION_TYPE_MASK_ = 0x0000001f; - /** - * Integer properties mask and shift values for East Asian cell width. - * Equivalent to icu4c UPROPS_EA_MASK - */ - private static final int EAST_ASIAN_MASK_ = 0x00038000; - /** - * Integer properties mask and shift values for East Asian cell width. - * Equivalent to icu4c UPROPS_EA_SHIFT - */ - private static final int EAST_ASIAN_SHIFT_ = 15; - - /** - * Integer properties mask and shift values for line breaks. - * Equivalent to icu4c UPROPS_LB_MASK - */ - private static final int LINE_BREAK_MASK_ = 0x007C0000; - /** - * Integer properties mask and shift values for line breaks. - * Equivalent to icu4c UPROPS_LB_SHIFT - */ - private static final int LINE_BREAK_SHIFT_ = 18; - /** - * Integer properties mask and shift values for blocks. - * Equivalent to icu4c UPROPS_BLOCK_MASK - */ - private static final int BLOCK_MASK_ = 0x00007f80; - /** - * Integer properties mask and shift values for blocks. - * Equivalent to icu4c UPROPS_BLOCK_SHIFT - */ - private static final int BLOCK_SHIFT_ = 7; - /** - * Integer properties mask and shift values for scripts. - * Equivalent to icu4c UPROPS_SHIFT_MASK - */ - private static final int SCRIPT_MASK_ = 0x0000007f; - - // private constructor ----------------------------------------------- - ///CLOVER:OFF - /** - * Private constructor to prevent instantiation - */ - private UCharacter() - { - } - ///CLOVER:ON // private methods --------------------------------------------------- /** @@ -818,17 +380,6 @@ public final class UCharacter return (props & NUMERIC_TYPE_MASK_) >> NUMERIC_TYPE_SHIFT_; } - /** - * Checks if the property value has a exception indicator - * @param props 32 bit property value - * @return true if property does not have a exception indicator, false - * otherwise - */ - private static boolean isNotExceptionIndicator(int props) - { - return (props & UCharacterProperty.EXCEPTION_MASK) == 0; - } - /** * Gets the property value at the index. * This is optimized. @@ -841,35 +392,34 @@ public final class UCharacter * @return property value of code point * @stable ICU 2.6 */ - private static int getProperty(int ch) + private static final int getProperty(int ch) { if (ch < UTF16.LEAD_SURROGATE_MIN_VALUE || (ch > UTF16.LEAD_SURROGATE_MAX_VALUE && ch < UTF16.SUPPLEMENTARY_MIN_VALUE)) { - // BMP codepoint - try { // using try for < 0 ch is faster than using an if statement - return PROPERTY_DATA_[ - PROPERTY_TRIE_DATA_[ + // BMP codepoint 0000..D7FF or DC00..FFFF + try { // using try for ch < 0 is faster than using an if statement + return PROPERTY_TRIE_DATA_[ (PROPERTY_TRIE_INDEX_[ch >> 5] << 2) - + (ch & 0x1f)]]; + + (ch & 0x1f)]; } catch (ArrayIndexOutOfBoundsException e) { return PROPERTY_INITIAL_VALUE_; } } if (ch <= UTF16.LEAD_SURROGATE_MAX_VALUE) { - // surrogate - return PROPERTY_DATA_[ - PROPERTY_TRIE_DATA_[ + // lead surrogate D800..DBFF + return PROPERTY_TRIE_DATA_[ (PROPERTY_TRIE_INDEX_[(0x2800 >> 5) + (ch >> 5)] << 2) - + (ch & 0x1f)]]; + + (ch & 0x1f)]; } // for optimization if (ch <= UTF16.CODEPOINT_MAX_VALUE) { + // supplementary code point 10000..10FFFF // look at the construction of supplementary characters // trail forms the ends of it. - return PROPERTY_DATA_[PROPERTY_.m_trie_.getSurrogateValue( + return PROPERTY_.m_trie_.getSurrogateValue( UTF16.getLeadSurrogate(ch), - (char)(ch & 0x3ff))]; + (char)(ch & 0x3ff)); } // return m_dataOffset_ if there is an error, in this case we return // the default value: m_initialValue_ @@ -877,4 +427,5 @@ public final class UCharacter // this is for optimization. return PROPERTY_INITIAL_VALUE_; } + } diff --git a/src/share/classes/sun/text/normalizer/UCharacterProperty.java b/src/share/classes/sun/text/normalizer/UCharacterProperty.java index 1a748ff173121c420b18d219faad05b7ae5b1445..a7412588ec1a8499de53c0b2221818a2b7113262 100644 --- a/src/share/classes/sun/text/normalizer/UCharacterProperty.java +++ b/src/share/classes/sun/text/normalizer/UCharacterProperty.java @@ -1,5 +1,5 @@ /* - * Portions Copyright 2005-2006 Sun Microsystems, Inc. All Rights Reserved. + * Portions Copyright 2005-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 @@ -22,10 +22,9 @@ * CA 95054 USA or visit www.sun.com if you need additional information or * have any questions. */ - /* ******************************************************************************* - * (C) Copyright IBM Corp. 1996-2005 - All Rights Reserved * + * (C) Copyright IBM Corp. and others, 1996-2009 - All Rights Reserved * * * * The original version of this source code and documentation is copyrighted * * and owned by IBM, These materials are provided under terms of a License * @@ -40,8 +39,7 @@ package sun.text.normalizer; import java.io.BufferedInputStream; import java.io.InputStream; import java.io.IOException; -import java.text.BreakIterator; -import java.util.Locale; +import java.util.MissingResourceException; /** * <p>Internal class used for Unicode character property database.</p> @@ -56,10 +54,9 @@ import java.util.Locale; * <a href=UCharacter.html>UCharacter</a>.</p> * @author Syn Wee Quek * @since release 2.1, february 1st 2002 -* @draft 2.1 */ -public final class UCharacterProperty implements Trie.DataManipulate +public final class UCharacterProperty { // public data members ----------------------------------------------- @@ -83,68 +80,16 @@ public final class UCharacterProperty implements Trie.DataManipulate */ public int m_trieInitialValue_; /** - * Character property table - */ - public int m_property_[]; - /** * Unicode version */ public VersionInfo m_unicodeVersion_; - /** - * Exception indicator for uppercase type - */ - public static final int EXC_UPPERCASE_ = 0; - /** - * Exception indicator for lowercase type - */ - public static final int EXC_LOWERCASE_ = 1; - /** - * Exception indicator for titlecase type - */ - public static final int EXC_TITLECASE_ = 2; - /** - * Exception indicator for digit type - */ - public static final int EXC_UNUSED_ = 3; - /** - * Exception indicator for numeric type - */ - public static final int EXC_NUMERIC_VALUE_ = 4; - /** - * Exception indicator for denominator type - */ - public static final int EXC_DENOMINATOR_VALUE_ = 5; - /** - * Exception indicator for mirror type - */ - public static final int EXC_MIRROR_MAPPING_ = 6; - /** - * Exception indicator for special casing type - */ - public static final int EXC_SPECIAL_CASING_ = 7; - /** - * Exception indicator for case folding type - */ - public static final int EXC_CASE_FOLDING_ = 8; - /** - * EXC_COMBINING_CLASS_ is not found in ICU. - * Used to retrieve the combining class of the character in the exception - * value - */ - public static final int EXC_COMBINING_CLASS_ = 9; - /** - * Latin lowercase i - */ - public static final char LATIN_SMALL_LETTER_I_ = 0x69; - /** - * Character type mask - */ - public static final int TYPE_MASK = 0x1F; - /** - * Exception test mask - */ - public static final int EXCEPTION_MASK = 0x20; + // uprops.h enum UPropertySource --------------------------------------- *** + + /** From uchar.c/uprops.icu properties vectors trie */ + public static final int SRC_PROPSVEC=2; + /** One more than the highest UPropertySource (SRC_) constant. */ + public static final int SRC_COUNT=9; // public methods ---------------------------------------------------- @@ -158,23 +103,6 @@ public final class UCharacterProperty implements Trie.DataManipulate m_trieInitialValue_ = friendagent.getPrivateInitialValue(); } - /** - * Called by com.ibm.icu.util.Trie to extract from a lead surrogate's - * data the index array offset of the indexes for that lead surrogate. - * @param value data value for a surrogate from the trie, including the - * folding offset - * @return data offset or 0 if there is no data for the lead surrogate - */ - public int getFoldingOffset(int value) - { - if ((value & SUPPLEMENTARY_FOLD_INDICATOR_MASK_) != 0) { - return (value & SUPPLEMENTARY_FOLD_OFFSET_MASK_); - } - else { - return 0; - } - } - /** * Gets the property value at the index. * This is optimized. @@ -183,129 +111,79 @@ public final class UCharacterProperty implements Trie.DataManipulate * @param ch code point whose property value is to be retrieved * @return property value of code point */ - public int getProperty(int ch) + public final int getProperty(int ch) { if (ch < UTF16.LEAD_SURROGATE_MIN_VALUE || (ch > UTF16.LEAD_SURROGATE_MAX_VALUE && ch < UTF16.SUPPLEMENTARY_MIN_VALUE)) { - // BMP codepoint + // BMP codepoint 0000..D7FF or DC00..FFFF // optimized - try { - return m_property_[ - m_trieData_[ + try { // using try for ch < 0 is faster than using an if statement + return m_trieData_[ (m_trieIndex_[ch >> Trie.INDEX_STAGE_1_SHIFT_] << Trie.INDEX_STAGE_2_SHIFT_) - + (ch & Trie.INDEX_STAGE_3_MASK_)]]; + + (ch & Trie.INDEX_STAGE_3_MASK_)]; } catch (ArrayIndexOutOfBoundsException e) { - return m_property_[m_trieInitialValue_]; + return m_trieInitialValue_; } } if (ch <= UTF16.LEAD_SURROGATE_MAX_VALUE) { - return m_property_[ - m_trieData_[ + // lead surrogate D800..DBFF + return m_trieData_[ (m_trieIndex_[Trie.LEAD_INDEX_OFFSET_ + (ch >> Trie.INDEX_STAGE_1_SHIFT_)] << Trie.INDEX_STAGE_2_SHIFT_) - + (ch & Trie.INDEX_STAGE_3_MASK_)]]; + + (ch & Trie.INDEX_STAGE_3_MASK_)]; } - // for optimization if (ch <= UTF16.CODEPOINT_MAX_VALUE) { + // supplementary code point 10000..10FFFF // look at the construction of supplementary characters // trail forms the ends of it. - return m_property_[m_trie_.getSurrogateValue( + return m_trie_.getSurrogateValue( UTF16.getLeadSurrogate(ch), - (char)(ch & Trie.SURROGATE_MASK_))]; + (char)(ch & Trie.SURROGATE_MASK_)); } + // ch is out of bounds // return m_dataOffset_ if there is an error, in this case we return // the default value: m_initialValue_ // we cannot assume that m_initialValue_ is at offset 0 // this is for optimization. - return m_property_[m_trieInitialValue_]; - // return m_property_[m_trie_.getCodePointValue(ch)]; + return m_trieInitialValue_; + + // this all is an inlined form of return m_trie_.getCodePointValue(ch); } /** - * Getting the signed numeric value of a character embedded in the property + * Getting the unsigned numeric value of a character embedded in the property * argument * @param prop the character - * @return signed numberic value - */ - public static int getSignedValue(int prop) - { - return (prop >> VALUE_SHIFT_); - } - - /** - * Getting the exception index for argument property - * @param prop character property - * @return exception index + * @return unsigned numberic value */ - public static int getExceptionIndex(int prop) + public static int getUnsignedValue(int prop) { return (prop >> VALUE_SHIFT_) & UNSIGNED_VALUE_MASK_AFTER_SHIFT_; } - /** - * Determines if the exception value passed in has the kind of information - * which the indicator wants, e.g if the exception value contains the digit - * value of the character - * @param index exception index - * @param indicator type indicator - * @return true if type value exist - */ - public boolean hasExceptionValue(int index, int indicator) - { - return (m_exception_[index] & (1 << indicator)) != 0; - } - - /** - * Gets the exception value at the index, assuming that data type is - * available. Result is undefined if data is not available. Use - * hasExceptionValue() to determine data's availability. - * @param index - * @param etype exception data type - * @return exception data type value at index - */ - public int getException(int index, int etype) - { - // contained in exception data - if (etype == EXC_COMBINING_CLASS_) { - return m_exception_[index]; - } - // contained in the exception digit address - index = addExceptionOffset(m_exception_[index], etype, ++ index); - return m_exception_[index]; - } - - /** - * Gets the folded case value at the index - * @param index of the case value to be retrieved - * @param count number of characters to retrieve - * @param str string buffer to which to append the result - */ - public void getFoldCase(int index, int count, StringBuffer str) - { - // first 2 chars are for the simple mappings - index += 2; - while (count > 0) { - str.append(m_case_[index]); - index ++; - count --; - } - } - /** * Gets the unicode additional properties. * C version getUnicodeProperties. * @param codepoint codepoint whose additional properties is to be * retrieved + * @param column * @return unicode properties */ - public int getAdditional(int codepoint) { - return m_additionalVectors_[m_additionalTrie_.getCodePointValue(codepoint)]; + public int getAdditional(int codepoint, int column) { + if (column == -1) { + return getProperty(codepoint); + } + if (column < 0 || column >= m_additionalColumnsCount_) { + return 0; + } + return m_additionalVectors_[ + m_additionalTrie_.getCodePointValue(codepoint) + column]; } - /** + /** * <p>Get the "age" of the code point.</p> * <p>The "age" is the Unicode version when the code point was first * designated (as a non-character or for Private Use) or assigned a @@ -316,11 +194,10 @@ public final class UCharacterProperty implements Trie.DataManipulate * <p>This API does not check the validity of the codepoint.</p> * @param codepoint The code point. * @return the Unicode version number - * @draft ICU 2.1 */ public VersionInfo getAge(int codepoint) { - int version = getAdditional(codepoint) >> AGE_SHIFT_; + int version = getAdditional(codepoint, 0) >> AGE_SHIFT_; return VersionInfo.getInstance( (version >> FIRST_NIBBLE_SHIFT_) & LAST_NIBBLE_MASK_, version & LAST_NIBBLE_MASK_, 0, 0); @@ -341,16 +218,16 @@ public final class UCharacterProperty implements Trie.DataManipulate /** * Loads the property data and initialize the UCharacterProperty instance. - * @throws RuntimeException when data is missing or data has been corrupted + * @throws MissingResourceException when data is missing or data has been corrupted */ - public static UCharacterProperty getInstance() throws RuntimeException + public static UCharacterProperty getInstance() { - if (INSTANCE_ == null) { + if(INSTANCE_ == null) { try { INSTANCE_ = new UCharacterProperty(); } catch (Exception e) { - throw new RuntimeException(e.getMessage()); + throw new MissingResourceException(e.getMessage(),"",""); } } return INSTANCE_; @@ -359,6 +236,9 @@ public final class UCharacterProperty implements Trie.DataManipulate /** * Checks if the argument c is to be treated as a white space in ICU * rules. Usually ICU rule white spaces are ignored unless quoted. + * Equivalent to test for Pattern_White_Space Unicode property. + * Stable set of characters, won't change. + * See UAX #31 Identifier and Pattern Syntax: http://www.unicode.org/reports/tr31/ * @param c codepoint to check * @return true if c is a ICU white space */ @@ -366,8 +246,9 @@ public final class UCharacterProperty implements Trie.DataManipulate { /* "white space" in the sense of ICU rule parsers This is a FIXED LIST that is NOT DEPENDENT ON UNICODE PROPERTIES. - See UTR #31: http://www.unicode.org/reports/tr31/. + See UAX #31 Identifier and Pattern Syntax: http://www.unicode.org/reports/tr31/ U+0009..U+000D, U+0020, U+0085, U+200E..U+200F, and U+2028..U+2029 + Equivalent to test for Pattern_White_Space Unicode property. */ return (c >= 0x0009 && c <= 0x2029 && (c <= 0x000D || c == 0x0020 || c == 0x0085 || @@ -376,15 +257,6 @@ public final class UCharacterProperty implements Trie.DataManipulate // protected variables ----------------------------------------------- - /** - * Case table - */ - char m_case_[]; - - /** - * Exception property table - */ - int m_exception_[]; /** * Extra property trie */ @@ -426,78 +298,20 @@ public final class UCharacterProperty implements Trie.DataManipulate */ private static final int DATA_BUFFER_SIZE_ = 25000; - /** - * This, from what i infer is the max size of the indicators used for the - * exception values. - * Number of bits in an 8-bit integer value - */ - private static final int EXC_GROUP_ = 8; - - /** - * Mask to get the group - */ - private static final int EXC_GROUP_MASK_ = 255; - - /** - * Mask to get the digit value in the exception result - */ - private static final int EXC_DIGIT_MASK_ = 0xFFFF; - - /** - * Offset table for data in exception block.<br> - * Table formed by the number of bits used for the index, e.g. 0 = 0 bits, - * 1 = 1 bits. - */ - private static final byte FLAGS_OFFSET_[] = - { - 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, - 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, - 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, - 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, - 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, - 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, - 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, - 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, - 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, - 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, - 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, - 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, - 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, - 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, - 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, - 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8 - }; - /** * Numeric value shift */ - private static final int VALUE_SHIFT_ = 20; + private static final int VALUE_SHIFT_ = 8; /** * Mask to be applied after shifting to obtain an unsigned numeric value */ - private static final int UNSIGNED_VALUE_MASK_AFTER_SHIFT_ = 0x7FF; - - /** - * - */ - private static final int NUMERIC_TYPE_SHIFT = 12; - - /** - * Folding indicator mask - */ - private static final int SUPPLEMENTARY_FOLD_INDICATOR_MASK_ = 0x8000; - - /** - * Folding offset mask - */ - private static final int SUPPLEMENTARY_FOLD_OFFSET_MASK_ = 0x7FFF; + private static final int UNSIGNED_VALUE_MASK_AFTER_SHIFT_ = 0xFF; /** * Shift value for lead surrogate to form a supplementary character. */ private static final int LEAD_SURROGATE_SHIFT_ = 10; - /** * Offset to add to combined surrogate pair to avoid msking. */ @@ -507,16 +321,12 @@ public final class UCharacterProperty implements Trie.DataManipulate LEAD_SURROGATE_SHIFT_) - UTF16.TRAIL_SURROGATE_MIN_VALUE; - /** - * To get the last character out from a data type - */ - private static final int LAST_CHAR_MASK_ = 0xFFFF; + // additional properties ---------------------------------------------- /** * First nibble shift */ private static final int FIRST_NIBBLE_SHIFT_ = 0x4; - /** * Second nibble mask */ @@ -530,7 +340,7 @@ public final class UCharacterProperty implements Trie.DataManipulate /** * Constructor - * @exception thrown when data reading fails or data corrupted + * @exception IOException thrown when data reading fails or data corrupted */ private UCharacterProperty() throws IOException { @@ -544,275 +354,16 @@ public final class UCharacterProperty implements Trie.DataManipulate m_trie_.putIndexData(this); } - /* Is followed by {case-ignorable}* cased ? */ - /** - * Getting the correct address for data in the exception value - * @param evalue exception value - * @param indicator type of data to retrieve - * @param address current address to move from - * @return the correct address - */ - private int addExceptionOffset(int evalue, int indicator, int address) - { - int result = address; - if (indicator >= EXC_GROUP_) { - result += FLAGS_OFFSET_[evalue & EXC_GROUP_MASK_]; - evalue >>= EXC_GROUP_; - indicator -= EXC_GROUP_; - } - int mask = (1 << indicator) - 1; - result += FLAGS_OFFSET_[evalue & mask]; - return result; - } - - private static final int TAB = 0x0009; - private static final int LF = 0x000a; - private static final int FF = 0x000c; - private static final int CR = 0x000d; - private static final int U_A = 0x0041; - private static final int U_Z = 0x005a; - private static final int U_a = 0x0061; - private static final int U_z = 0x007a; - private static final int DEL = 0x007f; - private static final int NL = 0x0085; - private static final int NBSP = 0x00a0; - private static final int CGJ = 0x034f; - private static final int FIGURESP= 0x2007; - private static final int HAIRSP = 0x200a; - private static final int ZWNJ = 0x200c; - private static final int ZWJ = 0x200d; - private static final int RLM = 0x200f; - private static final int NNBSP = 0x202f; - private static final int WJ = 0x2060; - private static final int INHSWAP = 0x206a; - private static final int NOMDIG = 0x206f; - private static final int ZWNBSP = 0xfeff; - - public UnicodeSet addPropertyStarts(UnicodeSet set) { - int c; - - /* add the start code point of each same-value range of each trie */ - //utrie_enum(&normTrie, NULL, _enumPropertyStartsRange, set); - TrieIterator propsIter = new TrieIterator(m_trie_); - RangeValueIterator.Element propsResult = new RangeValueIterator.Element(); - while(propsIter.next(propsResult)){ - set.add(propsResult.start); - } - //utrie_enum(&propsVectorsTrie, NULL, _enumPropertyStartsRange, set); - TrieIterator propsVectorsIter = new TrieIterator(m_additionalTrie_); - RangeValueIterator.Element propsVectorsResult = new RangeValueIterator.Element(); - while(propsVectorsIter.next(propsVectorsResult)){ - set.add(propsVectorsResult.start); - } - - - /* add code points with hardcoded properties, plus the ones following them */ - - /* add for IS_THAT_CONTROL_SPACE() */ - set.add(TAB); /* range TAB..CR */ - set.add(CR+1); - set.add(0x1c); - set.add(0x1f+1); - set.add(NL); - set.add(NL+1); - - /* add for u_isIDIgnorable() what was not added above */ - set.add(DEL); /* range DEL..NBSP-1, NBSP added below */ - set.add(HAIRSP); - set.add(RLM+1); - set.add(INHSWAP); - set.add(NOMDIG+1); - set.add(ZWNBSP); - set.add(ZWNBSP+1); - - /* add no-break spaces for u_isWhitespace() what was not added above */ - set.add(NBSP); - set.add(NBSP+1); - set.add(FIGURESP); - set.add(FIGURESP+1); - set.add(NNBSP); - set.add(NNBSP+1); - - /* add for u_charDigitValue() */ - set.add(0x3007); - set.add(0x3008); - set.add(0x4e00); - set.add(0x4e01); - set.add(0x4e8c); - set.add(0x4e8d); - set.add(0x4e09); - set.add(0x4e0a); - set.add(0x56db); - set.add(0x56dc); - set.add(0x4e94); - set.add(0x4e95); - set.add(0x516d); - set.add(0x516e); - set.add(0x4e03); - set.add(0x4e04); - set.add(0x516b); - set.add(0x516c); - set.add(0x4e5d); - set.add(0x4e5e); - - /* add for u_digit() */ - set.add(U_a); - set.add(U_z+1); - set.add(U_A); - set.add(U_Z+1); - - /* add for UCHAR_DEFAULT_IGNORABLE_CODE_POINT what was not added above */ - set.add(WJ); /* range WJ..NOMDIG */ - set.add(0xfff0); - set.add(0xfffb+1); - set.add(0xe0000); - set.add(0xe0fff+1); - - /* add for UCHAR_GRAPHEME_BASE and others */ - set.add(CGJ); - set.add(CGJ+1); - - /* add for UCHAR_JOINING_TYPE */ - set.add(ZWNJ); /* range ZWNJ..ZWJ */ - set.add(ZWJ+1); - - /* add Jamo type boundaries for UCHAR_HANGUL_SYLLABLE_TYPE */ - set.add(0x1100); - int value= UCharacter.HangulSyllableType.LEADING_JAMO; - int value2; - for(c=0x115a; c<=0x115f; ++c) { - value2= UCharacter.getIntPropertyValue(c, UProperty.HANGUL_SYLLABLE_TYPE); - if(value!=value2) { - value=value2; - set.add(c); - } - } - - set.add(0x1160); - value=UCharacter.HangulSyllableType.VOWEL_JAMO; - for(c=0x11a3; c<=0x11a7; ++c) { - value2=UCharacter.getIntPropertyValue(c, UProperty.HANGUL_SYLLABLE_TYPE); - if(value!=value2) { - value=value2; - set.add(c); - } - } - - set.add(0x11a8); - value=UCharacter.HangulSyllableType.TRAILING_JAMO; - for(c=0x11fa; c<=0x11ff; ++c) { - value2=UCharacter.getIntPropertyValue(c, UProperty.HANGUL_SYLLABLE_TYPE); - if(value!=value2) { - value=value2; - set.add(c); + public void upropsvec_addPropertyStarts(UnicodeSet set) { + /* add the start code point of each same-value range of the properties vectors trie */ + if(m_additionalColumnsCount_>0) { + /* if m_additionalColumnsCount_==0 then the properties vectors trie may not be there at all */ + TrieIterator propsVectorsIter = new TrieIterator(m_additionalTrie_); + RangeValueIterator.Element propsVectorsResult = new RangeValueIterator.Element(); + while(propsVectorsIter.next(propsVectorsResult)){ + set.add(propsVectorsResult.start); } } - - - /* - * Omit code points for u_charCellWidth() because - * - it is deprecated and not a real Unicode property - * - they are probably already set from the trie enumeration - */ - - /* - * Omit code points with hardcoded specialcasing properties - * because we do not build property UnicodeSets for them right now. - */ - return set; // for chaining - } -/*---------------------------------------------------------------- - * Inclusions list - *----------------------------------------------------------------*/ - - /* - * Return a set of characters for property enumeration. - * The set implicitly contains 0x110000 as well, which is one more than the highest - * Unicode code point. - * - * This set is used as an ordered list - its code points are ordered, and - * consecutive code points (in Unicode code point order) in the set define a range. - * For each two consecutive characters (start, limit) in the set, - * all of the UCD/normalization and related properties for - * all code points start..limit-1 are all the same, - * except for character names and ISO comments. - * - * All Unicode code points U+0000..U+10ffff are covered by these ranges. - * The ranges define a partition of the Unicode code space. - * ICU uses the inclusions set to enumerate properties for generating - * UnicodeSets containing all code points that have a certain property value. - * - * The Inclusion List is generated from the UCD. It is generated - * by enumerating the data tries, and code points for hardcoded properties - * are added as well. - * - * -------------------------------------------------------------------------- - * - * The following are ideas for getting properties-unique code point ranges, - * with possible optimizations beyond the current implementation. - * These optimizations would require more code and be more fragile. - * The current implementation generates one single list (set) for all properties. - * - * To enumerate properties efficiently, one needs to know ranges of - * repetitive values, so that the value of only each start code point - * can be applied to the whole range. - * This information is in principle available in the uprops.icu/unorm.icu data. - * - * There are two obstacles: - * - * 1. Some properties are computed from multiple data structures, - * making it necessary to get repetitive ranges by intersecting - * ranges from multiple tries. - * - * 2. It is not economical to write code for getting repetitive ranges - * that are precise for each of some 50 properties. - * - * Compromise ideas: - * - * - Get ranges per trie, not per individual property. - * Each range contains the same values for a whole group of properties. - * This would generate currently five range sets, two for uprops.icu tries - * and three for unorm.icu tries. - * - * - Combine sets of ranges for multiple tries to get sufficient sets - * for properties, e.g., the uprops.icu main and auxiliary tries - * for all non-normalization properties. - * - * Ideas for representing ranges and combining them: - * - * - A UnicodeSet could hold just the start code points of ranges. - * Multiple sets are easily combined by or-ing them together. - * - * - Alternatively, a UnicodeSet could hold each even-numbered range. - * All ranges could be enumerated by using each start code point - * (for the even-numbered ranges) as well as each limit (end+1) code point - * (for the odd-numbered ranges). - * It should be possible to combine two such sets by xor-ing them, - * but no more than two. - * - * The second way to represent ranges may(?!) yield smaller UnicodeSet arrays, - * but the first one is certainly simpler and applicable for combining more than - * two range sets. - * - * It is possible to combine all range sets for all uprops/unorm tries into one - * set that can be used for all properties. - * As an optimization, there could be less-combined range sets for certain - * groups of properties. - * The relationship of which less-combined range set to use for which property - * depends on the implementation of the properties and must be hardcoded - * - somewhat error-prone and higher maintenance but can be tested easily - * by building property sets "the simple way" in test code. - * - * --- - * - * Do not use a UnicodeSet pattern because that causes infinite recursion; - * UnicodeSet depends on the inclusions set. - */ - public UnicodeSet getInclusions() { - UnicodeSet set = new UnicodeSet(); - NormalizerImpl.addPropertyStarts(set); - addPropertyStarts(set); - return set; } } diff --git a/src/share/classes/sun/text/normalizer/UCharacterPropertyReader.java b/src/share/classes/sun/text/normalizer/UCharacterPropertyReader.java index bb44a8f9b4ca045b7ad31cdc6805b514dfbd8ee1..60cb327c4d80c39402b27fc130f2e6575996ec15 100644 --- a/src/share/classes/sun/text/normalizer/UCharacterPropertyReader.java +++ b/src/share/classes/sun/text/normalizer/UCharacterPropertyReader.java @@ -1,5 +1,5 @@ /* - * Portions Copyright 2005 Sun Microsystems, Inc. All Rights Reserved. + * Portions Copyright 2005-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 @@ -22,10 +22,9 @@ * CA 95054 USA or visit www.sun.com if you need additional information or * have any questions. */ - /* ******************************************************************************* - * (C) Copyright IBM Corp. 1996-2005 - All Rights Reserved * + * (C) Copyright IBM Corp. and others, 1996-2009 - All Rights Reserved * * * * The original version of this source code and documentation is copyrighted * * and owned by IBM, These materials are provided under terms of a License * @@ -37,8 +36,8 @@ package sun.text.normalizer; -import java.io.InputStream; import java.io.DataInputStream; +import java.io.InputStream; import java.io.IOException; /** @@ -50,254 +49,13 @@ import java.io.IOException; * </p> * <p>uprops.icu which is in big-endian format is jared together with this * package.</p> +* +* Unicode character properties file format see +* (ICU4C)/source/tools/genprops/store.c +* * @author Syn Wee Quek * @since release 2.1, February 1st 2002 -* @draft 2.1 */ -/* Unicode character properties file format ------------------------------------ - -The file format prepared and written here contains several data -structures that store indexes or data. - - - -The following is a description of format version 3 . - -Data contents: - -The contents is a parsed, binary form of several Unicode character -database files, most prominently UnicodeData.txt. - -Any Unicode code point from 0 to 0x10ffff can be looked up to get -the properties, if any, for that code point. This means that the input -to the lookup are 21-bit unsigned integers, with not all of the -21-bit range used. - -It is assumed that client code keeps a uint32_t pointer -to the beginning of the data: - - const uint32_t *p32; - -Formally, the file contains the following structures: - - const int32_t indexes[16] with values i0..i15: - - i0 propsIndex; -- 32-bit unit index to the table of 32-bit properties words - i1 exceptionsIndex; -- 32-bit unit index to the table of 32-bit exception words - i2 exceptionsTopIndex; -- 32-bit unit index to the array of UChars for special mappings - - i3 additionalTrieIndex; -- 32-bit unit index to the additional trie for more properties - i4 additionalVectorsIndex; -- 32-bit unit index to the table of properties vectors - i5 additionalVectorsColumns; -- number of 32-bit words per properties vector - - i6 reservedItemIndex; -- 32-bit unit index to the top of the properties vectors table - i7..i9 reservedIndexes; -- reserved values; 0 for now - - i10 maxValues; -- maximum code values for vector word 0, see uprops.h (format version 3.1+) - i11 maxValues2; -- maximum code values for vector word 2, see uprops.h (format version 3.2) - i12..i15 reservedIndexes; -- reserved values; 0 for now - - PT serialized properties trie, see utrie.h (byte size: 4*(i0-16)) - - P const uint32_t props32[i1-i0]; - E const uint32_t exceptions[i2-i1]; - U const UChar uchars[2*(i3-i2)]; - - AT serialized trie for additional properties (byte size: 4*(i4-i3)) - PV const uint32_t propsVectors[(i6-i4)/i5][i5]==uint32_t propsVectors[i6-i4]; - -Trie lookup and properties: - -In order to condense the data for the 21-bit code space, several properties of -the Unicode code assignment are exploited: -- The code space is sparse. -- There are several 10k of consecutive codes with the same properties. -- Characters and scripts are allocated in groups of 16 code points. -- Inside blocks for scripts the properties are often repetitive. -- The 21-bit space is not fully used for Unicode. - -The lookup of properties for a given code point is done with a trie lookup, -using the UTrie implementation. -The trie lookup result is a 16-bit index in the props32[] table where the -actual 32-bit properties word is stored. This is done to save space. - -(There are thousands of 16-bit entries in the trie data table, but -only a few hundred unique 32-bit properties words. -If the trie data table contained 32-bit words directly, then that would be -larger because the length of the table would be the same as now but the -width would be 32 bits instead of 16. This saves more than 10kB.) - -With a given Unicode code point - - UChar32 c; - -and 0<=c<0x110000, the lookup is done like this: - - uint16_t i; - UTRIE_GET16(c, i); - uint32_t props=p32[i]; - -For some characters, not all of the properties can be efficiently encoded -using 32 bits. For them, the 32-bit word contains an index into the exceptions[] -array: - - if(props&EXCEPTION_BIT)) { - uint16_t e=(uint16_t)(props>>VALUE_SHIFT); - ... - } - -The exception values are a variable number of uint32_t starting at - - const uint32_t *pe=p32+exceptionsIndex+e; - -The first uint32_t there contains flags about what values actually follow it. -Some of the exception values are UChar32 code points for the case mappings, -others are numeric values etc. - -32-bit properties sets: - -Each 32-bit properties word contains: - - 0.. 4 general category - 5 has exception values - 6..10 BiDi category -11 is mirrored -12..14 numericType: - 0 no numeric value - 1 decimal digit value - 2 digit value - 3 numeric value - ### TODO: type 4 for Han digits & numbers?! -15..19 reserved -20..31 value according to bits 0..5: - if(has exception) { - exception index; - } else switch(general category) { - case Ll: delta to uppercase; -- same as titlecase - case Lu: -delta to lowercase; -- titlecase is same as c - case Lt: -delta to lowercase; -- uppercase is same as c - default: - if(is mirrored) { - delta to mirror; - } else if(numericType!=0) { - numericValue; - } else { - 0; - }; - } - -Exception values: - -In the first uint32_t exception word for a code point, -bits -31..16 reserved -15..0 flags that indicate which values follow: - -bit - 0 has uppercase mapping - 1 has lowercase mapping - 2 has titlecase mapping - 3 unused - 4 has numeric value (numerator) - if numericValue=0x7fffff00+x then numericValue=10^x - 5 has denominator value - 6 has a mirror-image Unicode code point - 7 has SpecialCasing.txt entries - 8 has CaseFolding.txt entries - -According to the flags in this word, one or more uint32_t words follow it -in the sequence of the bit flags in the flags word; if a flag is not set, -then the value is missing or 0: - -For the case mappings and the mirror-image Unicode code point, -one uint32_t or UChar32 each is the code point. -If the titlecase mapping is missing, then it is the same as the uppercase mapping. - -For the digit values, bits 31..16 contain the decimal digit value, and -bits 15..0 contain the digit value. A value of -1 indicates that -this value is missing. - -For the numeric/numerator value, an int32_t word contains the value directly, -except for when there is no numerator but a denominator, then the numerator -is implicitly 1. This means: - numerator denominator result - none none none - x none x - none y 1/y - x y x/y - -If the numerator value is 0x7fffff00+x then it is replaced with 10^x. - -For the denominator value, a uint32_t word contains the value directly. - -For special casing mappings, the 32-bit exception word contains: -31 if set, this character has complex, conditional mappings - that are not stored; - otherwise, the mappings are stored according to the following bits -30..24 number of UChars used for mappings -23..16 reserved -15.. 0 UChar offset from the beginning of the UChars array where the - UChars for the special case mappings are stored in the following format: - -Format of special casing UChars: -One UChar value with lengths as follows: -14..10 number of UChars for titlecase mapping - 9.. 5 number of UChars for uppercase mapping - 4.. 0 number of UChars for lowercase mapping - -Followed by the UChars for lowercase, uppercase, titlecase mappings in this order. - -For case folding mappings, the 32-bit exception word contains: -31..24 number of UChars used for the full mapping -23..16 reserved -15.. 0 UChar offset from the beginning of the UChars array where the - UChars for the special case mappings are stored in the following format: - -Format of case folding UChars: -Two UChars contain the simple mapping as follows: - 0, 0 no simple mapping - BMP,0 a simple mapping to a BMP code point - s1, s2 a simple mapping to a supplementary code point stored as two surrogates -This is followed by the UChars for the full case folding mappings. - -Example: -U+2160, ROMAN NUMERAL ONE, needs an exception because it has a lowercase -mapping and a numeric value. -Its exception values would be stored as 3 uint32_t words: - -- flags=0x0a (see above) with combining class 0 -- lowercase mapping 0x2170 -- numeric value=1 - ---- Additional properties (new in format version 2.1) --- - -The second trie for additional properties (AT) is also a UTrie with 16-bit data. -The data words consist of 32-bit unit indexes (not row indexes!) into the -table of unique properties vectors (PV). -Each vector contains a set of properties. -The width of a vector (number of uint32_t per row) may change -with the formatVersion, it is stored in i5. - -Current properties: see icu/source/common/uprops.h - ---- Changes in format version 3.1 --- - -See i10 maxValues above, contains only UBLOCK_COUNT and USCRIPT_CODE_LIMIT. - ---- Changes in format version 3.2 --- - -- The tries use linear Latin-1 ranges. -- The additional properties bits store full properties XYZ instead - of partial Other_XYZ, so that changes in the derivation formulas - need not be tracked in runtime library code. -- Joining Type and Line Break are also stored completely, so that uprops.c - needs no runtime formulas for enumerated properties either. -- Store the case-sensitive flag in the main properties word. -- i10 also contains U_LB_COUNT and U_EA_COUNT. -- i11 contains maxValues2 for vector word 2. - ------------------------------------------------------------------------------ */ - final class UCharacterPropertyReader implements ICUBinary.Authenticate { // public methods ---------------------------------------------------- @@ -315,7 +73,6 @@ final class UCharacterPropertyReader implements ICUBinary.Authenticate * <p>Protected constructor.</p> * @param inputStream ICU uprop.dat file input stream * @exception IOException throw if data file fails authentication - * @draft 2.1 */ protected UCharacterPropertyReader(InputStream inputStream) throws IOException @@ -331,8 +88,7 @@ final class UCharacterPropertyReader implements ICUBinary.Authenticate * <p>Reads uprops.icu, parse it into blocks of data to be stored in * UCharacterProperty.</P * @param ucharppty UCharacterProperty instance - * @exception thrown when data reading fails - * @draft 2.1 + * @exception IOException thrown when data reading fails */ protected void read(UCharacterProperty ucharppty) throws IOException { @@ -362,38 +118,30 @@ final class UCharacterPropertyReader implements ICUBinary.Authenticate // read the trie index block // m_props_index_ in terms of ints - ucharppty.m_trie_ = new CharTrie(m_dataInputStream_, ucharppty); + ucharppty.m_trie_ = new CharTrie(m_dataInputStream_, null); - // reads the 32 bit properties block + // skip the 32 bit properties block int size = m_exceptionOffset_ - m_propertyOffset_; - ucharppty.m_property_ = new int[size]; - for (int i = 0; i < size; i ++) { - ucharppty.m_property_[i] = m_dataInputStream_.readInt(); - } + m_dataInputStream_.skipBytes(size * 4); // reads the 32 bit exceptions block size = m_caseOffset_ - m_exceptionOffset_; - ucharppty.m_exception_ = new int[size]; - for (int i = 0; i < size; i ++) { - ucharppty.m_exception_[i] = m_dataInputStream_.readInt(); - } + m_dataInputStream_.skipBytes(size * 4); // reads the 32 bit case block size = (m_additionalOffset_ - m_caseOffset_) << 1; - ucharppty.m_case_ = new char[size]; - for (int i = 0; i < size; i ++) { - ucharppty.m_case_[i] = m_dataInputStream_.readChar(); - } - - // reads the additional property block - ucharppty.m_additionalTrie_ = new CharTrie(m_dataInputStream_, - ucharppty); - - // additional properties - size = m_reservedOffset_ - m_additionalVectorsOffset_; - ucharppty.m_additionalVectors_ = new int[size]; - for (int i = 0; i < size; i ++) { - ucharppty.m_additionalVectors_[i] = m_dataInputStream_.readInt(); + m_dataInputStream_.skipBytes(size * 2); + + if(m_additionalColumnsCount_ > 0) { + // reads the additional property block + ucharppty.m_additionalTrie_ = new CharTrie(m_dataInputStream_, null); + + // additional properties + size = m_reservedOffset_ - m_additionalVectorsOffset_; + ucharppty.m_additionalVectors_ = new int[size]; + for (int i = 0; i < size; i ++) { + ucharppty.m_additionalVectors_[i] = m_dataInputStream_.readInt(); + } } m_dataInputStream_.close(); @@ -428,12 +176,15 @@ final class UCharacterPropertyReader implements ICUBinary.Authenticate private byte m_unicodeVersion_[]; /** - * File format version that this class understands. - * No guarantees are made if a older version is used + * Data format "UPro". */ private static final byte DATA_FORMAT_ID_[] = {(byte)0x55, (byte)0x50, (byte)0x72, (byte)0x6F}; - private static final byte DATA_FORMAT_VERSION_[] = {(byte)0x3, (byte)0x1, + /** + * Format version; this code works with all versions with the same major + * version number and the same Trie bit distribution. + */ + private static final byte DATA_FORMAT_VERSION_[] = {(byte)0x5, (byte)0, (byte)Trie.INDEX_STAGE_1_SHIFT_, (byte)Trie.INDEX_STAGE_2_SHIFT_}; } diff --git a/src/share/classes/sun/text/normalizer/UProperty.java b/src/share/classes/sun/text/normalizer/UProperty.java deleted file mode 100644 index 3b8c097f43a37583b0cf18410e32962ae16e7776..0000000000000000000000000000000000000000 --- a/src/share/classes/sun/text/normalizer/UProperty.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Portions Copyright 2005 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. - */ - -/* - ******************************************************************************* - * (C) Copyright IBM Corp. 1996-2005 - All Rights Reserved * - * * - * The original version of this source code and documentation is copyrighted * - * and owned by IBM, These materials are provided under terms of a License * - * Agreement between IBM and Sun. This technology is protected by multiple * - * US and International patents. This notice and attribution to IBM may not * - * to removed. * - ******************************************************************************* - */ - -package sun.text.normalizer; - -/** - * <p>Selection constants for Unicode properties. </p> - * <p>These constants are used in functions like - * UCharacter.hasBinaryProperty(int) to select one of the Unicode properties. - * </p> - * <p>The properties APIs are intended to reflect Unicode properties as - * defined in the Unicode Character Database (UCD) and Unicode Technical - * Reports (UTR).</p> - * <p>For details about the properties see <a href=http://www.unicode.org> - * http://www.unicode.org</a>.</p> - * <p>For names of Unicode properties see the UCD file PropertyAliases.txt. - * </p> - * <p>Important: If ICU is built with UCD files from Unicode versions below - * 3.2, then properties marked with "new" are not or not fully - * available. Check UCharacter.getUnicodeVersion() to be sure.</p> - * @author Syn Wee Quek - * @stable ICU 2.6 - * @see com.ibm.icu.lang.UCharacter - */ -public interface UProperty -{ - // public data member -------------------------------------------------- - - /** - * Enumerated property Hangul_Syllable_Type, new in Unicode 4. - * Returns HangulSyllableType values. - * @stable ICU 2.6 - */ - public static final int HANGUL_SYLLABLE_TYPE = 0x100B; - - /** - * Bitmask property General_Category_Mask. - * This is the General_Category property returned as a bit mask. - * When used in UCharacter.getIntPropertyValue(c), - * returns bit masks for UCharacterCategory values where exactly one bit is set. - * When used with UCharacter.getPropertyValueName() and UCharacter.getPropertyValueEnum(), - * a multi-bit mask is used for sets of categories like "Letters". - * @stable ICU 2.4 - */ - public static final int GENERAL_CATEGORY_MASK = 0x2000; -} diff --git a/src/share/classes/sun/text/normalizer/UTF16.java b/src/share/classes/sun/text/normalizer/UTF16.java index 3b872a6063fe68bee273f8390fbb701e9706684a..2aa7c6d3571961f59ad12858f44441c992dde9af 100644 --- a/src/share/classes/sun/text/normalizer/UTF16.java +++ b/src/share/classes/sun/text/normalizer/UTF16.java @@ -1,5 +1,5 @@ /* - * Portions Copyright 2005-2006 Sun Microsystems, Inc. All Rights Reserved. + * Portions Copyright 2005-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 @@ -22,10 +22,9 @@ * CA 95054 USA or visit www.sun.com if you need additional information or * have any questions. */ - /* ******************************************************************************* - * (C) Copyright IBM Corp. 1996-2005 - All Rights Reserved * + * (C) Copyright IBM Corp. and others, 1996-2009 - All Rights Reserved * * * * The original version of this source code and documentation is copyrighted * * and owned by IBM, These materials are provided under terms of a License * @@ -184,15 +183,16 @@ public final class UTF16 * bounds. * @stable ICU 2.1 */ - public static int charAt(String source, int offset16) - { - if (offset16 < 0 || offset16 >= source.length()) { - throw new StringIndexOutOfBoundsException(offset16); + public static int charAt(String source, int offset16) { + char single = source.charAt(offset16); + if (single < LEAD_SURROGATE_MIN_VALUE) { + return single; } + return _charAt(source, offset16, single); + } - char single = source.charAt(offset16); - if (single < LEAD_SURROGATE_MIN_VALUE || - single > TRAIL_SURROGATE_MAX_VALUE) { + private static int _charAt(String source, int offset16, char single) { + if (single > TRAIL_SURROGATE_MAX_VALUE) { return single; } @@ -201,29 +201,23 @@ public final class UTF16 // low, look both directions. if (single <= LEAD_SURROGATE_MAX_VALUE) { - ++ offset16; + ++offset16; if (source.length() != offset16) { char trail = source.charAt(offset16); - if (trail >= TRAIL_SURROGATE_MIN_VALUE && - trail <= TRAIL_SURROGATE_MAX_VALUE) { - return UCharacterProperty.getRawSupplementary(single, - trail); + if (trail >= TRAIL_SURROGATE_MIN_VALUE && trail <= TRAIL_SURROGATE_MAX_VALUE) { + return UCharacterProperty.getRawSupplementary(single, trail); } } - } - else - { - -- offset16; - if (offset16 >= 0) { - // single is a trail surrogate so - char lead = source.charAt(offset16); - if (lead >= LEAD_SURROGATE_MIN_VALUE && - lead <= LEAD_SURROGATE_MAX_VALUE) { - return UCharacterProperty.getRawSupplementary(lead, - single); - } + } else { + --offset16; + if (offset16 >= 0) { + // single is a trail surrogate so + char lead = source.charAt(offset16); + if (lead >= LEAD_SURROGATE_MIN_VALUE && lead <= LEAD_SURROGATE_MAX_VALUE) { + return UCharacterProperty.getRawSupplementary(lead, single); } } + } return single; // return unmatched surrogate } diff --git a/src/share/classes/sun/text/normalizer/UnicodeSet.java b/src/share/classes/sun/text/normalizer/UnicodeSet.java index eaffb7c8b44160a09d469bff9932bb646d839dad..21ab0c883de4ac8a9b18f62d32e526ae2eb85f12 100644 --- a/src/share/classes/sun/text/normalizer/UnicodeSet.java +++ b/src/share/classes/sun/text/normalizer/UnicodeSet.java @@ -1,5 +1,5 @@ /* - * Portions Copyright 2005-2006 Sun Microsystems, Inc. All Rights Reserved. + * Portions Copyright 2005-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 @@ -22,10 +22,9 @@ * CA 95054 USA or visit www.sun.com if you need additional information or * have any questions. */ - /* ******************************************************************************* - * (C) Copyright IBM Corp. 1996-2005 - All Rights Reserved * + * (C) Copyright IBM Corp. and others, 1996-2009 - All Rights Reserved * * * * The original version of this source code and documentation is copyrighted * * and owned by IBM, These materials are provided under terms of a License * @@ -38,11 +37,8 @@ package sun.text.normalizer; import java.text.ParsePosition; -import java.util.Map; -import java.util.HashMap; -import java.util.TreeSet; import java.util.Iterator; -import java.util.Collection; +import java.util.TreeSet; /** * A mutable set of Unicode characters and multicharacter strings. Objects of this class @@ -130,8 +126,8 @@ import java.util.Collection; * "[:Lu:]" and the Perl-like syntax "\p{Lu}" are recognized. For a * complete list of supported property patterns, see the User's Guide * for UnicodeSet at - * <a href="http://oss.software.ibm.com/icu/userguide/unicodeSet.html"> - * http://oss.software.ibm.com/icu/userguide/unicodeSet.html</a>. + * <a href="http://www.icu-project.org/userguide/unicodeSet.html"> + * http://www.icu-project.org/userguide/unicodeSet.html</a>. * Actual determination of property data is defined by the underlying * Unicode database as implemented by UCharacter. * @@ -271,9 +267,11 @@ import java.util.Collection; * </tr> * </table> * </blockquote> + * <p>To iterate over contents of UnicodeSet, use UnicodeSetIterator class. * * @author Alan Liu * @stable ICU 2.0 + * @see UnicodeSetIterator */ public class UnicodeSet implements UnicodeMatcher { @@ -322,7 +320,7 @@ public class UnicodeSet implements UnicodeMatcher { * properties are all exactly alike, e.g. CJK Ideographs from * U+4E00 to U+9FA5. */ - private static UnicodeSet INCLUSIONS = null; + private static UnicodeSet INCLUSIONS[] = null; //---------------------------------------------------------------- // Public API @@ -471,17 +469,18 @@ public class UnicodeSet implements UnicodeMatcher { return result; } - return _generatePattern(result, escapeUnprintable); + return _generatePattern(result, escapeUnprintable, true); } /** * Generate and append a string representation of this set to result. * This does not use this.pat, the cleaned up copy of the string * passed to applyPattern(). - * @stable ICU 2.0 + * @param includeStrings if false, doesn't include the strings. + * @stable ICU 3.8 */ public StringBuffer _generatePattern(StringBuffer result, - boolean escapeUnprintable) { + boolean escapeUnprintable, boolean includeStrings) { result.append('['); int count = getRangeCount(); @@ -524,7 +523,7 @@ public class UnicodeSet implements UnicodeMatcher { } } - if (strings.size() > 0) { + if (includeStrings && strings.size() > 0) { Iterator it = strings.iterator(); while (it.hasNext()) { result.append('{'); @@ -535,19 +534,8 @@ public class UnicodeSet implements UnicodeMatcher { return result.append(']'); } - /** - * Adds the specified range to this set if it is not already - * present. If this set already contains the specified range, - * the call leaves this set unchanged. If <code>end > start</code> - * then an empty range is added, leaving the set unchanged. - * - * @param start first character, inclusive, of range to be added - * to this set. - * @param end last character, inclusive, of range to be added - * to this set. - * @stable ICU 2.0 - */ - public UnicodeSet add(int start, int end) { + // for internal use, after checkFrozen has been called + private UnicodeSet add_unchecked(int start, int end) { if (start < MIN_VALUE || start > MAX_VALUE) { throw new IllegalArgumentException("Invalid code point U+" + Utility.hex(start, 6)); } @@ -569,6 +557,11 @@ public class UnicodeSet implements UnicodeMatcher { * @stable ICU 2.0 */ public final UnicodeSet add(int c) { + return add_unchecked(c); + } + + // for internal use only, after checkFrozen has been called + private final UnicodeSet add_unchecked(int c) { if (c < MIN_VALUE || c > MAX_VALUE) { throw new IllegalArgumentException("Invalid code point U+" + Utility.hex(c, 6)); } @@ -663,13 +656,12 @@ public class UnicodeSet implements UnicodeMatcher { * @stable ICU 2.0 */ public final UnicodeSet add(String s) { - int cp = getSingleCP(s); if (cp < 0) { strings.add(s); pat = null; } else { - add(cp, cp); + add_unchecked(cp, cp); } return this; } @@ -981,7 +973,6 @@ public class UnicodeSet implements UnicodeMatcher { */ void applyPattern(RuleCharacterIterator chars, SymbolTable symbols, StringBuffer rebuiltPat, int options) { - // Syntax characters: [ ] ^ - & { } // Recognized special forms for chars, sets: c-c s-s s&s @@ -992,7 +983,7 @@ public class UnicodeSet implements UnicodeMatcher { opts |= RuleCharacterIterator.SKIP_WHITESPACE; } - StringBuffer pat = new StringBuffer(), buf = null; + StringBuffer patBuf = new StringBuffer(), buf = null; boolean usePat = false; UnicodeSet scratch = null; Object backup = null; @@ -1049,13 +1040,13 @@ public class UnicodeSet implements UnicodeMatcher { } else { // Handle opening '[' delimiter mode = 1; - pat.append('['); + patBuf.append('['); backup = chars.getPos(backup); // prepare to backup c = chars.next(opts); literal = chars.isEscaped(); if (c == '^' && !literal) { invert = true; - pat.append('^'); + patBuf.append('^'); backup = chars.getPos(backup); // prepare to backup c = chars.next(opts); literal = chars.isEscaped(); @@ -1093,13 +1084,13 @@ public class UnicodeSet implements UnicodeMatcher { if (op != 0) { syntaxError(chars, "Char expected after operator"); } - add(lastChar, lastChar); - _appendToPat(pat, lastChar, false); + add_unchecked(lastChar, lastChar); + _appendToPat(patBuf, lastChar, false); lastItem = op = 0; } if (op == '-' || op == '&') { - pat.append(op); + patBuf.append(op); } if (nested == null) { @@ -1108,14 +1099,14 @@ public class UnicodeSet implements UnicodeMatcher { } switch (setMode) { case 1: - nested.applyPattern(chars, symbols, pat, options); + nested.applyPattern(chars, symbols, patBuf, options); break; case 2: chars.skipIgnored(opts); - nested.applyPropertyPattern(chars, pat, symbols); + nested.applyPropertyPattern(chars, patBuf, symbols); break; case 3: // `nested' already parsed - nested._toPattern(pat, false); + nested._toPattern(patBuf, false); break; } @@ -1158,17 +1149,17 @@ public class UnicodeSet implements UnicodeMatcher { switch (c) { case ']': if (lastItem == 1) { - add(lastChar, lastChar); - _appendToPat(pat, lastChar, false); + add_unchecked(lastChar, lastChar); + _appendToPat(patBuf, lastChar, false); } // Treat final trailing '-' as a literal if (op == '-') { - add(op, op); - pat.append(op); + add_unchecked(op, op); + patBuf.append(op); } else if (op == '&') { syntaxError(chars, "Trailing '&'"); } - pat.append(']'); + patBuf.append(']'); mode = 2; continue; case '-': @@ -1178,11 +1169,11 @@ public class UnicodeSet implements UnicodeMatcher { continue; } else { // Treat final trailing '-' as a literal - add(c, c); + add_unchecked(c, c); c = chars.next(opts); literal = chars.isEscaped(); if (c == ']' && !literal) { - pat.append("-]"); + patBuf.append("-]"); mode = 2; continue; } @@ -1202,8 +1193,8 @@ public class UnicodeSet implements UnicodeMatcher { syntaxError(chars, "Missing operand after operator"); } if (lastItem == 1) { - add(lastChar, lastChar); - _appendToPat(pat, lastChar, false); + add_unchecked(lastChar, lastChar); + _appendToPat(patBuf, lastChar, false); } lastItem = 0; if (buf == null) { @@ -1228,9 +1219,9 @@ public class UnicodeSet implements UnicodeMatcher { // we don't need to drop through to the further // processing add(buf.toString()); - pat.append('{'); - _appendToPat(pat, buf.toString(), false); - pat.append('}'); + patBuf.append('{'); + _appendToPat(patBuf, buf.toString(), false); + patBuf.append('}'); continue; case SymbolTable.SYMBOL_REF: // symbols nosymbols @@ -1250,12 +1241,12 @@ public class UnicodeSet implements UnicodeMatcher { } if (anchor && op == 0) { if (lastItem == 1) { - add(lastChar, lastChar); - _appendToPat(pat, lastChar, false); + add_unchecked(lastChar, lastChar); + _appendToPat(patBuf, lastChar, false); } - add(UnicodeMatcher.ETHER); + add_unchecked(UnicodeMatcher.ETHER); usePat = true; - pat.append(SymbolTable.SYMBOL_REF).append(']'); + patBuf.append(SymbolTable.SYMBOL_REF).append(']'); mode = 2; continue; } @@ -1281,14 +1272,14 @@ public class UnicodeSet implements UnicodeMatcher { // these are most likely typos. syntaxError(chars, "Invalid range"); } - add(lastChar, c); - _appendToPat(pat, lastChar, false); - pat.append(op); - _appendToPat(pat, c, false); + add_unchecked(lastChar, c); + _appendToPat(patBuf, lastChar, false); + patBuf.append(op); + _appendToPat(patBuf, c, false); lastItem = op = 0; } else { - add(lastChar, lastChar); - _appendToPat(pat, lastChar, false); + add_unchecked(lastChar, lastChar); + _appendToPat(patBuf, lastChar, false); lastChar = c; } break; @@ -1315,9 +1306,9 @@ public class UnicodeSet implements UnicodeMatcher { // Use the rebuilt pattern (pat) only if necessary. Prefer the // generated pattern. if (usePat) { - rebuiltPat.append(pat.toString()); + rebuiltPat.append(patBuf.toString()); } else { - _generatePattern(rebuiltPat, false); + _generatePattern(rebuiltPat, false, true); } } @@ -1590,7 +1581,9 @@ public class UnicodeSet implements UnicodeMatcher { private static class VersionFilter implements Filter { VersionInfo version; + VersionFilter(VersionInfo version) { this.version = version; } + public boolean contains(int ch) { VersionInfo v = UCharacter.getAge(ch); // Reference comparison ok; VersionInfo caches and reuses @@ -1600,18 +1593,28 @@ public class UnicodeSet implements UnicodeMatcher { } } - private static synchronized UnicodeSet getInclusions() { + private static synchronized UnicodeSet getInclusions(int src) { if (INCLUSIONS == null) { - UCharacterProperty property = UCharacterProperty.getInstance(); - INCLUSIONS = property.getInclusions(); + INCLUSIONS = new UnicodeSet[UCharacterProperty.SRC_COUNT]; + } + if(INCLUSIONS[src] == null) { + UnicodeSet incl = new UnicodeSet(); + switch(src) { + case UCharacterProperty.SRC_PROPSVEC: + UCharacterProperty.getInstance().upropsvec_addPropertyStarts(incl); + break; + default: + throw new IllegalStateException("UnicodeSet.getInclusions(unknown src "+src+")"); + } + INCLUSIONS[src] = incl; } - return INCLUSIONS; + return INCLUSIONS[src]; } /** * Generic filter-based scanning code for UCD property UnicodeSets. */ - private UnicodeSet applyFilter(Filter filter) { + private UnicodeSet applyFilter(Filter filter, int src) { // Walk through all Unicode characters, noting the start // and end of each range for which filter.contain(c) is // true. Add each range to a set. @@ -1629,7 +1632,7 @@ public class UnicodeSet implements UnicodeMatcher { clear(); int startHasProperty = -1; - UnicodeSet inclusions = getInclusions(); + UnicodeSet inclusions = getInclusions(src); int limitRange = inclusions.getRangeCount(); for (int j=0; j<limitRange; ++j) { @@ -1646,19 +1649,18 @@ public class UnicodeSet implements UnicodeMatcher { startHasProperty = ch; } } else if (startHasProperty >= 0) { - add(startHasProperty, ch-1); + add_unchecked(startHasProperty, ch-1); startHasProperty = -1; } } } if (startHasProperty >= 0) { - add(startHasProperty, 0x10FFFF); + add_unchecked(startHasProperty, 0x10FFFF); } return this; } - /** * Remove leading and trailing rule white space and compress * internal rule white space to a single space character. @@ -1686,10 +1688,6 @@ public class UnicodeSet implements UnicodeMatcher { return buf.toString(); } - //---------------------------------------------------------------- - // Property set API - //---------------------------------------------------------------- - /** * Modifies this set to contain those code points which have the * given value for the given property. Prior contents of this @@ -1699,22 +1697,21 @@ public class UnicodeSet implements UnicodeMatcher { * @param symbols if not null, then symbols are first called to see if a property * is available. If true, then everything else is skipped. * @return this set - * @draft ICU 3.2 - * @deprecated This is a draft API and might change in a future release of ICU. + * @stable ICU 3.2 */ public UnicodeSet applyPropertyAlias(String propertyAlias, String valueAlias, SymbolTable symbols) { - if (propertyAlias.equals("Age")) - { - // Must munge name, since - // VersionInfo.getInstance() does not do - // 'loose' matching. - VersionInfo version = VersionInfo.getInstance(mungeCharName(valueAlias)); - applyFilter(new VersionFilter(version)); - return this; - } - else - throw new IllegalArgumentException("Unsupported property"); + if (valueAlias.length() > 0) { + if (propertyAlias.equals("Age")) { + // Must munge name, since + // VersionInfo.getInstance() does not do + // 'loose' matching. + VersionInfo version = VersionInfo.getInstance(mungeCharName(valueAlias)); + applyFilter(new VersionFilter(version), UCharacterProperty.SRC_PROPSVEC); + return this; + } + } + throw new IllegalArgumentException("Unsupported property: " + propertyAlias); } /** @@ -1840,14 +1837,14 @@ public class UnicodeSet implements UnicodeMatcher { */ private void applyPropertyPattern(RuleCharacterIterator chars, StringBuffer rebuiltPat, SymbolTable symbols) { - String pat = chars.lookahead(); + String patStr = chars.lookahead(); ParsePosition pos = new ParsePosition(0); - applyPropertyPattern(pat, pos, symbols); + applyPropertyPattern(patStr, pos, symbols); if (pos.getIndex() == 0) { syntaxError(chars, "Invalid property pattern"); } chars.jumpahead(pos.getIndex()); - rebuiltPat.append(pat.substring(0, pos.getIndex())); + rebuiltPat.append(patStr.substring(0, pos.getIndex())); } //---------------------------------------------------------------- @@ -1860,8 +1857,9 @@ public class UnicodeSet implements UnicodeMatcher { * which UCharacterProperty.isRuleWhiteSpace() returns true, * unless they are quoted or escaped. This may be ORed together * with other selectors. - * @internal + * @stable ICU 3.8 */ public static final int IGNORE_SPACE = 1; } + diff --git a/src/share/classes/sun/text/normalizer/UnicodeSetIterator.java b/src/share/classes/sun/text/normalizer/UnicodeSetIterator.java index 4d558da18dd9650bc01f45ac5b7b9fd2090bfa6d..0d8ffe84f2dc48cd9c6ded13b24947652f8ee65e 100644 --- a/src/share/classes/sun/text/normalizer/UnicodeSetIterator.java +++ b/src/share/classes/sun/text/normalizer/UnicodeSetIterator.java @@ -1,5 +1,5 @@ /* - * Portions Copyright 2005 Sun Microsystems, Inc. All Rights Reserved. + * Portions Copyright 2005-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 @@ -22,10 +22,9 @@ * CA 95054 USA or visit www.sun.com if you need additional information or * have any questions. */ - /* ******************************************************************************* - * (C) Copyright IBM Corp. 1996-2005 - All Rights Reserved * + * (C) Copyright IBM Corp. and others, 1996-2009 - All Rights Reserved * * * * The original version of this source code and documentation is copyrighted * * and owned by IBM, These materials are provided under terms of a License * @@ -167,8 +166,8 @@ public class UnicodeSetIterator { * @param set the set to iterate over. * @stable ICU 2.0 */ - public void reset(UnicodeSet set) { - this.set = set; + public void reset(UnicodeSet uset) { + set = uset; reset(); } @@ -213,8 +212,8 @@ public class UnicodeSetIterator { /** * @internal */ - protected void loadRange(int range) { - nextElement = set.getRangeStart(range); - endElement = set.getRangeEnd(range); + protected void loadRange(int aRange) { + nextElement = set.getRangeStart(aRange); + endElement = set.getRangeEnd(aRange); } } diff --git a/src/share/classes/sun/text/normalizer/Utility.java b/src/share/classes/sun/text/normalizer/Utility.java index 895097f13d25566434db7a558b12499b16f61fbb..7d8b33b9d59ecf8bb929e08e96c40821fe313532 100644 --- a/src/share/classes/sun/text/normalizer/Utility.java +++ b/src/share/classes/sun/text/normalizer/Utility.java @@ -1,5 +1,5 @@ /* - * Portions Copyright 2005 Sun Microsystems, Inc. All Rights Reserved. + * Portions Copyright 2005-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 @@ -24,7 +24,7 @@ */ /* ******************************************************************************* - * (C) Copyright IBM Corp. 1996-2005 - All Rights Reserved * + * (C) Copyright IBM Corp. and others, 1996-2009 - All Rights Reserved * * * * The original version of this source code and documentation is copyrighted * * and owned by IBM, These materials are provided under terms of a License * @@ -36,10 +36,27 @@ package sun.text.normalizer; -// This class contains utility functions so testing not needed -///CLOVER:OFF public final class Utility { + /** + * Convenience utility to compare two Object[]s + * Ought to be in System. + * @param len the length to compare. + * The start indices and start+len must be valid. + */ + public final static boolean arrayRegionMatches(char[] source, int sourceStart, + char[] target, int targetStart, + int len) + { + int sourceEnd = sourceStart + len; + int delta = targetStart - sourceStart; + for (int i = sourceStart; i < sourceEnd; i++) { + if (source[i]!=target[i + delta]) + return false; + } + return true; + } + /** * Convert characters outside the range U+0020 to U+007F to * Unicode escapes, and convert backslash to a double backslash. @@ -344,7 +361,6 @@ public final class Utility { return false; } - //// for StringPrep /** * Similar to StringBuffer.getChars, version 1.3. * Since JDK 1.2 implements StringBuffer.getChars differently, this method @@ -356,7 +372,6 @@ public final class Utility { * @param dst char array to store the retrieved chars * @param dstBegin offset to the start of the destination char array to * store the retrieved chars - * @draft since ICU4J 2.0 */ public static void getChars(StringBuffer src, int srcBegin, int srcEnd, char dst[], int dstBegin) @@ -367,23 +382,4 @@ public final class Utility { src.getChars(srcBegin, srcEnd, dst, dstBegin); } - /** - * Convenience utility to compare two char[]s. - * @param len the length to compare. - * The start indices and start+len must be valid. - */ - public final static boolean arrayRegionMatches(char[] source, int sourceStart, - char[] target, int targetStart, - int len) - { - int sourceEnd = sourceStart + len; - int delta = targetStart - sourceStart; - for (int i = sourceStart; i < sourceEnd; i++) { - if (source[i] != target[i + delta]) - return false; - } - return true; - } - } -///CLOVER:ON diff --git a/src/share/classes/sun/text/normalizer/VersionInfo.java b/src/share/classes/sun/text/normalizer/VersionInfo.java index e1a0d92ddb5f3428b4996fb04442681b5977bec0..2b0f7c7918b3ac9c93677fe628c99196ea9fec78 100644 --- a/src/share/classes/sun/text/normalizer/VersionInfo.java +++ b/src/share/classes/sun/text/normalizer/VersionInfo.java @@ -1,5 +1,5 @@ /* - * Portions Copyright 2005-2008 Sun Microsystems, Inc. All Rights Reserved. + * Portions Copyright 2005-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 @@ -24,7 +24,7 @@ */ /* ******************************************************************************* - * (C) Copyright IBM Corp. 1996-2005 - All Rights Reserved * + * (C) Copyright IBM Corp. and others, 1996-2009 - All Rights Reserved * * * * The original version of this source code and documentation is copyrighted * * and owned by IBM, These materials are provided under terms of a License * diff --git a/src/share/classes/sun/text/resources/ubidi.icu b/src/share/classes/sun/text/resources/ubidi.icu new file mode 100644 index 0000000000000000000000000000000000000000..e4a2d8194077ab61854c6137d99294cca071a401 Binary files /dev/null and b/src/share/classes/sun/text/resources/ubidi.icu differ diff --git a/src/share/classes/sun/text/resources/unorm.icu b/src/share/classes/sun/text/resources/unorm.icu index 5d56aa22fc2d496f555fa7ccab2c4d42b3363972..96560e6dcfbe398ac577a9017acf6359017d6138 100644 Binary files a/src/share/classes/sun/text/resources/unorm.icu and b/src/share/classes/sun/text/resources/unorm.icu differ diff --git a/src/share/classes/sun/text/resources/uprops.icu b/src/share/classes/sun/text/resources/uprops.icu index 610ad5abee0bb4f0d30b18adb3c4591f473a0c80..0140aa29928e3a10a42fbf93dc8a46c2d708852a 100644 Binary files a/src/share/classes/sun/text/resources/uprops.icu and b/src/share/classes/sun/text/resources/uprops.icu differ diff --git a/src/share/lib/security/java.policy b/src/share/lib/security/java.policy index bcb5a6c4d8674106518e0b5f48ff96be2e21e1fa..3312bdf92f2135c5fe0e137a4cd07d6fc06258f5 100644 --- a/src/share/lib/security/java.policy +++ b/src/share/lib/security/java.policy @@ -15,7 +15,8 @@ grant { // It is strongly recommended that you either remove this permission // from this policy file or further restrict it to code sources // that you specify, because Thread.stop() is potentially unsafe. - // See "http://java.sun.com/notes" for more information. + // See the API specification of java.lang.Thread.stop() for more + // information. permission java.lang.RuntimePermission "stopThread"; // allows anyone to listen on un-privileged ports diff --git a/src/share/native/java/lang/ClassLoader.c b/src/share/native/java/lang/ClassLoader.c index 6f5960af5bf54fe8c1651e252df603193a3eaffe..bedf87ce7e6571ad4fa3cce43edf456ff4581d6b 100644 --- a/src/share/native/java/lang/ClassLoader.c +++ b/src/share/native/java/lang/ClassLoader.c @@ -1,5 +1,5 @@ /* - * Copyright 1996-2005 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. * * This code is free software; you can redistribute it and/or modify it @@ -437,3 +437,21 @@ Java_java_lang_ClassLoader_00024NativeLibrary_find (*env)->ReleaseStringUTFChars(env, name, cname); return res; } + +JNIEXPORT jobject JNICALL +Java_java_lang_ClassLoader_getCaller(JNIEnv *env, jclass cls, jint index) +{ + jobjectArray jcallerStack; + int len; + + jcallerStack = JVM_GetClassContext(env); + if ((*env)->ExceptionCheck(env)) { + return NULL; + } + len = (*env)->GetArrayLength(env, jcallerStack); + if (index < len) { + return (*env)->GetObjectArrayElement(env, jcallerStack, index); + } + return NULL; +} + diff --git a/src/share/native/java/util/zip/zip_util.c b/src/share/native/java/util/zip/zip_util.c index 3b00b9500ac65bc202c87353fb9df0a15ef6efeb..89f52ae3bcc12d95a72189b4b4f7d4d9ea79cfe4 100644 --- a/src/share/native/java/util/zip/zip_util.c +++ b/src/share/native/java/util/zip/zip_util.c @@ -1,5 +1,5 @@ /* - * Copyright 1995-2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 1995-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 @@ -135,11 +135,6 @@ ZFILE_Close(ZFILE zfd) { #endif } -static jlong -ZFILE_Lseek(ZFILE zfd, off_t offset, int whence) { - return IO_Lseek(zfd, offset, whence); -} - static int ZFILE_read(ZFILE zfd, char *buf, jint nbytes) { #ifdef WIN32 @@ -216,7 +211,7 @@ readFully(ZFILE zfd, void *buf, jlong len) { static int readFullyAt(ZFILE zfd, void *buf, jlong len, jlong offset) { - if (ZFILE_Lseek(zfd, (off_t) offset, SEEK_SET) == -1) { + if (IO_Lseek(zfd, offset, SEEK_SET) == -1) { return -1; /* lseek failure. */ } @@ -317,6 +312,38 @@ findEND(jzfile *zip, void *endbuf) return -1; /* END header not found */ } +/* + * Searches for the ZIP64 end of central directory (END) header. The + * contents of the ZIP64 END header will be read and placed in end64buf. + * Returns the file position of the ZIP64 END header, otherwise returns + * -1 if the END header was not found or an error occurred. + * + * The ZIP format specifies the "position" of each related record as + * ... + * [central directory] + * [zip64 end of central directory record] + * [zip64 end of central directory locator] + * [end of central directory record] + * + * The offset of zip64 end locator can be calculated from endpos as + * "endpos - ZIP64_LOCHDR". + * The "offset" of zip64 end record is stored in zip64 end locator. + */ +static jlong +findEND64(jzfile *zip, void *end64buf, jlong endpos) +{ + char loc64[ZIP64_LOCHDR]; + jlong end64pos; + if (readFullyAt(zip->zfd, loc64, ZIP64_LOCHDR, endpos - ZIP64_LOCHDR) == -1) { + return -1; // end64 locator not found + } + end64pos = ZIP64_LOCOFF(loc64); + if (readFullyAt(zip->zfd, end64buf, ZIP64_ENDHDR, end64pos) == -1) { + return -1; // end64 record not found + } + return end64pos; +} + /* * Returns a hash code value for a C-style NUL-terminated string. */ @@ -468,7 +495,7 @@ static jlong readCEN(jzfile *zip, jint knownTotal) { /* Following are unsigned 32-bit */ - jlong endpos, cenpos, cenlen; + jlong endpos, end64pos, cenpos, cenlen, cenoff; /* Following are unsigned 16-bit */ jint total, tablelen, i, j; unsigned char *cenbuf = NULL; @@ -476,9 +503,10 @@ readCEN(jzfile *zip, jint knownTotal) unsigned char *cp; #ifdef USE_MMAP static jlong pagesize; - off_t offset; + jlong offset; #endif unsigned char endbuf[ENDHDR]; + jint endhdrlen = ENDHDR; jzcell *entries; jint *table; @@ -495,13 +523,27 @@ readCEN(jzfile *zip, jint knownTotal) /* Get position and length of central directory */ cenlen = ENDSIZ(endbuf); + cenoff = ENDOFF(endbuf); + total = ENDTOT(endbuf); + if (cenlen == ZIP64_MAGICVAL || cenoff == ZIP64_MAGICVAL || + total == ZIP64_MAGICCOUNT) { + unsigned char end64buf[ZIP64_ENDHDR]; + if ((end64pos = findEND64(zip, end64buf, endpos)) != -1) { + cenlen = ZIP64_ENDSIZ(end64buf); + cenoff = ZIP64_ENDOFF(end64buf); + total = (jint)ZIP64_ENDTOT(end64buf); + endpos = end64pos; + endhdrlen = ZIP64_ENDHDR; + } + } + if (cenlen > endpos) ZIP_FORMAT_ERROR("invalid END header (bad central directory size)"); cenpos = endpos - cenlen; /* Get position of first local file (LOC) header, taking into * account that there may be a stub prefixed to the zip file. */ - zip->locpos = cenpos - ENDOFF(endbuf); + zip->locpos = cenpos - cenoff; if (zip->locpos < 0) ZIP_FORMAT_ERROR("invalid END header (bad central directory offset)"); @@ -532,9 +574,9 @@ readCEN(jzfile *zip, jint knownTotal) out the page size in order to make offset to be multiples of page size. */ - zip->mlen = cenpos - offset + cenlen + ENDHDR; + zip->mlen = cenpos - offset + cenlen + endhdrlen; zip->offset = offset; - mappedAddr = mmap(0, zip->mlen, PROT_READ, MAP_SHARED, zip->zfd, offset); + mappedAddr = mmap64(0, zip->mlen, PROT_READ, MAP_SHARED, zip->zfd, (off64_t) offset); zip->maddr = (mappedAddr == (void*) MAP_FAILED) ? NULL : (unsigned char*)mappedAddr; @@ -556,8 +598,13 @@ readCEN(jzfile *zip, jint knownTotal) * is a 2-byte field, but we (and other zip implementations) * support approx. 2**31 entries, we do not trust ENDTOT, but * treat it only as a strong hint. When we call ourselves - * recursively, knownTotal will have the "true" value. */ - total = (knownTotal != -1) ? knownTotal : ENDTOT(endbuf); + * recursively, knownTotal will have the "true" value. + * + * Keep this path alive even with the Zip64 END support added, just + * for zip files that have more than 0xffff entries but don't have + * the Zip64 enabled. + */ + total = (knownTotal != -1) ? knownTotal : total; entries = zip->entries = calloc(total, sizeof(entries[0])); tablelen = zip->tablelen = ((total/2) | 1); // Odd -> fewer collisions table = zip->table = malloc(tablelen * sizeof(table[0])); @@ -720,7 +767,7 @@ ZIP_Put_In_Cache(const char *name, ZFILE zfd, char **pmsg, jlong lastModified) return NULL; } - len = zip->len = ZFILE_Lseek(zfd, 0, SEEK_END); + len = zip->len = IO_Lseek(zfd, 0, SEEK_END); if (len <= 0) { if (len == 0) { /* zip file is empty */ if (pmsg) { @@ -859,6 +906,7 @@ typedef enum { ACCESS_RANDOM, ACCESS_SEQUENTIAL } AccessHint; static jzentry * newEntry(jzfile *zip, jzcell *zc, AccessHint accessHint) { + jlong locoff; jint nlen, elen, clen; jzentry *ze; char *cen; @@ -885,18 +933,55 @@ newEntry(jzfile *zip, jzcell *zc, AccessHint accessHint) ze->size = CENLEN(cen); ze->csize = (CENHOW(cen) == STORED) ? 0 : CENSIZ(cen); ze->crc = CENCRC(cen); - ze->pos = -(zip->locpos + CENOFF(cen)); + locoff = CENOFF(cen); + ze->pos = -(zip->locpos + locoff); if ((ze->name = malloc(nlen + 1)) == NULL) goto Catch; memcpy(ze->name, cen + CENHDR, nlen); ze->name[nlen] = '\0'; if (elen > 0) { + char *extra = cen + CENHDR + nlen; + /* This entry has "extra" data */ if ((ze->extra = malloc(elen + 2)) == NULL) goto Catch; ze->extra[0] = (unsigned char) elen; ze->extra[1] = (unsigned char) (elen >> 8); - memcpy(ze->extra+2, cen + CENHDR + nlen, elen); + memcpy(ze->extra+2, extra, elen); + if (ze->csize == ZIP64_MAGICVAL || ze->size == ZIP64_MAGICVAL || + locoff == ZIP64_MAGICVAL) { + jint off = 0; + while ((off + 4) < elen) { // spec: HeaderID+DataSize+Data + jint sz = SH(extra, off + 2); + if (SH(extra, off) == ZIP64_EXTID) { + off += 4; + if (ze->size == ZIP64_MAGICVAL) { + // if invalid zip64 extra fields, just skip + if (sz < 8 || (off + 8) > elen) + break; + ze->size = LL(extra, off); + sz -= 8; + off += 8; + } + if (ze->csize == ZIP64_MAGICVAL) { + if (sz < 8 || (off + 8) > elen) + break; + ze->csize = LL(extra, off); + sz -= 8; + off += 8; + } + if (locoff == ZIP64_MAGICVAL) { + if (sz < 8 || (off + 8) > elen) + break; + ze->pos = -(zip->locpos + LL(extra, off)); + sz -= 8; + off += 8; + } + break; + } + off += (sz + 4); + } + } } if (clen > 0) { diff --git a/src/share/native/java/util/zip/zip_util.h b/src/share/native/java/util/zip/zip_util.h index 5fdebaf13473d2c0ea1285b94889e45eafedefac..7ad11715e5a5fd6d7ad886244bd1753a3e84f3ce 100644 --- a/src/share/native/java/util/zip/zip_util.h +++ b/src/share/native/java/util/zip/zip_util.h @@ -1,5 +1,5 @@ /* - * Copyright 1995-2006 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 1995-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 @@ -38,9 +38,13 @@ #define CENSIG 0x02014b50L /* "PK\001\002" */ #define ENDSIG 0x06054b50L /* "PK\005\006" */ +#define ZIP64_ENDSIG 0x06064b50L /* "PK\006\006" */ +#define ZIP64_LOCSIG 0x07064b50L /* "PK\006\007" */ + /* * Header sizes including signatures */ + #ifdef USE_MMAP #define SIGSIZ 4 #endif @@ -49,12 +53,22 @@ #define CENHDR 46 #define ENDHDR 22 +#define ZIP64_ENDHDR 56 // ZIP64 end header size +#define ZIP64_LOCHDR 20 // ZIP64 end loc header size +#define ZIP64_EXTHDR 24 // EXT header size +#define ZIP64_EXTID 1 // Extra field Zip64 header ID + +#define ZIP64_MAGICVAL 0xffffffffLL +#define ZIP64_MAGICCOUNT 0xffff + + /* * Header field access macros */ #define CH(b, n) (((unsigned char *)(b))[n]) #define SH(b, n) (CH(b, n) | (CH(b, n+1) << 8)) -#define LG(b, n) (SH(b, n) | (SH(b, n+2) << 16)) +#define LG(b, n) ((SH(b, n) | (SH(b, n+2) << 16)) &0xffffffffUL) +#define LL(b, n) (((jlong)LG(b, n)) | (((jlong)LG(b, n+4)) << 32)) #define GETSIG(b) LG(b, 0) /* @@ -105,6 +119,26 @@ #define ENDOFF(b) LG(b, 16) /* central directory offset */ #define ENDCOM(b) SH(b, 20) /* size of zip file comment */ +/* + * Macros for getting Zip64 end of central directory header fields + */ +#define ZIP64_ENDLEN(b) LL(b, 4) /* size of zip64 end of central dir */ +#define ZIP64_ENDVEM(b) SH(b, 12) /* version made by */ +#define ZIP64_ENDVER(b) SH(b, 14) /* version needed to extract */ +#define ZIP64_ENDNMD(b) LG(b, 16) /* number of this disk */ +#define ZIP64_ENDDSK(b) LG(b, 20) /* disk number of start */ +#define ZIP64_ENDTOD(b) LL(b, 24) /* total number of entries on this disk */ +#define ZIP64_ENDTOT(b) LL(b, 32) /* total number of entries */ +#define ZIP64_ENDSIZ(b) LL(b, 40) /* central directory size in bytes */ +#define ZIP64_ENDOFF(b) LL(b, 48) /* offset of first CEN header */ + +/* + * Macros for getting Zip64 end of central directory locator fields + */ +#define ZIP64_LOCDSK(b) LG(b, 4) /* disk number start */ +#define ZIP64_LOCOFF(b) LL(b, 8) /* offset of zip64 end */ +#define ZIP64_LOCTOT(b) LG(b, 16) /* total number of disks */ + /* * Supported compression methods */ @@ -145,7 +179,7 @@ typedef struct jzentry { /* Zip file entry */ */ typedef struct jzcell { unsigned int hash; /* 32 bit hashcode on name */ - unsigned int cenpos; /* Offset of central directory file header */ + jlong cenpos; /* Offset of central directory file header */ unsigned int next; /* hash chain: index into jzfile->entries */ } jzcell; @@ -174,7 +208,7 @@ typedef struct jzfile { /* Zip file */ #ifdef USE_MMAP unsigned char *maddr; /* beginning address of the CEN & ENDHDR */ jlong mlen; /* length (in bytes) mmaped */ - off_t offset; /* offset of the mmapped region from the + jlong offset; /* offset of the mmapped region from the start of the file. */ #else cencache cencache; /* CEN header cache */ diff --git a/src/share/native/java/util/zip/zlib-1.1.3/zlib.h b/src/share/native/java/util/zip/zlib-1.1.3/zlib.h index 9576715b2fa26e90404fc0cd280d53e7bc3e365a..00fdf06007d12dcf564ef8618ea15f8913dd207f 100644 --- a/src/share/native/java/util/zip/zlib-1.1.3/zlib.h +++ b/src/share/native/java/util/zip/zlib-1.1.3/zlib.h @@ -106,11 +106,11 @@ struct internal_state; typedef struct z_stream_s { Bytef *next_in; /* next input byte */ uInt avail_in; /* number of bytes available at next_in */ - uLong total_in; /* total nb of input bytes read so far */ + long long total_in; /* total nb of input bytes read so far */ Bytef *next_out; /* next output byte should be put there */ uInt avail_out; /* remaining free space at next_out */ - uLong total_out; /* total nb of bytes output so far */ + long long total_out; /* total nb of bytes output so far */ char *msg; /* last error message, NULL if no error */ struct internal_state FAR *state; /* not visible by applications */ diff --git a/src/share/native/sun/awt/image/dither.c b/src/share/native/sun/awt/image/dither.c index a935d6766f611a2b4028e933d9829e65f1bdf5f4..cb2303e76d709bd101130860810caa8419bc8da4 100644 --- a/src/share/native/sun/awt/image/dither.c +++ b/src/share/native/sun/awt/image/dither.c @@ -169,6 +169,7 @@ initCubemap(int* cmap, int cubesize = cube_dim * cube_dim * cube_dim; unsigned char *useFlags; unsigned char *newILut = (unsigned char*)malloc(cubesize); + int cmap_mid = (cmap_len >> 1) + (cmap_len & 0x1); if (newILut) { useFlags = (unsigned char *)calloc(cubesize, 1); @@ -188,7 +189,7 @@ initCubemap(int* cmap, currentState.iLUT = newILut; currentState.rgb = (unsigned short *) - malloc(256 * sizeof(unsigned short)); + malloc(cmap_len * sizeof(unsigned short)); if (currentState.rgb == NULL) { free(newILut); free(useFlags); @@ -199,7 +200,7 @@ initCubemap(int* cmap, } currentState.indices = (unsigned char *) - malloc(256 * sizeof(unsigned char)); + malloc(cmap_len * sizeof(unsigned char)); if (currentState.indices == NULL) { free(currentState.rgb); free(newILut); @@ -210,18 +211,18 @@ initCubemap(int* cmap, return NULL; } - for (i = 0; i < 128; i++) { + for (i = 0; i < cmap_mid; i++) { unsigned short rgb; int pixel = cmap[i]; rgb = (pixel & 0x00f80000) >> 9; rgb |= (pixel & 0x0000f800) >> 6; rgb |= (pixel & 0xf8) >> 3; INSERTNEW(currentState, rgb, i); - pixel = cmap[255-i]; + pixel = cmap[cmap_len - i - 1]; rgb = (pixel & 0x00f80000) >> 9; rgb |= (pixel & 0x0000f800) >> 6; rgb |= (pixel & 0xf8) >> 3; - INSERTNEW(currentState, rgb, 255-i); + INSERTNEW(currentState, rgb, cmap_len - i - 1); } if (!recurseLevel(¤tState)) { diff --git a/src/share/native/sun/awt/image/jpeg/imageioJPEG.c b/src/share/native/sun/awt/image/jpeg/imageioJPEG.c index 8c30b5ce69e4215a67d91388d4ecc6b9e5459107..0a99c3fdb934a5947bcdf6839f895dc3f120e5ae 100644 --- a/src/share/native/sun/awt/image/jpeg/imageioJPEG.c +++ b/src/share/native/sun/awt/image/jpeg/imageioJPEG.c @@ -396,7 +396,7 @@ static imageIODataPtr initImageioData (JNIEnv *env, data->jpegObj = cinfo; cinfo->client_data = data; -#ifdef DEBUG +#ifdef DEBUG_IIO_JPEG printf("new structures: data is %p, cinfo is %p\n", data, cinfo); #endif @@ -673,7 +673,7 @@ static int setQTables(JNIEnv *env, j_decompress_ptr decomp; qlen = (*env)->GetArrayLength(env, qtables); -#ifdef DEBUG +#ifdef DEBUG_IIO_JPEG printf("in setQTables, qlen = %d, write is %d\n", qlen, write); #endif for (i = 0; i < qlen; i++) { @@ -876,7 +876,7 @@ imageio_fill_input_buffer(j_decompress_ptr cinfo) return FALSE; } -#ifdef DEBUG +#ifdef DEBUG_IIO_JPEG printf("Filling input buffer, remaining skip is %ld, ", sb->remaining_skip); printf("Buffer length is %d\n", sb->bufferLength); @@ -906,7 +906,7 @@ imageio_fill_input_buffer(j_decompress_ptr cinfo) cinfo->err->error_exit((j_common_ptr) cinfo); } -#ifdef DEBUG +#ifdef DEBUG_IIO_JPEG printf("Buffer filled. ret = %d\n", ret); #endif /* @@ -917,7 +917,7 @@ imageio_fill_input_buffer(j_decompress_ptr cinfo) */ if (ret <= 0) { jobject reader = data->imageIOobj; -#ifdef DEBUG +#ifdef DEBUG_IIO_JPEG printf("YO! Early EOI! ret = %d\n", ret); #endif RELEASE_ARRAYS(env, data, src->next_input_byte); @@ -1216,21 +1216,24 @@ read_icc_profile (JNIEnv *env, j_decompress_ptr cinfo) { jpeg_saved_marker_ptr marker; int num_markers = 0; + int num_found_markers = 0; int seq_no; JOCTET *icc_data; + JOCTET *dst_ptr; unsigned int total_length; #define MAX_SEQ_NO 255 // sufficient since marker numbers are bytes - char marker_present[MAX_SEQ_NO+1]; // 1 if marker found - unsigned int data_length[MAX_SEQ_NO+1]; // size of profile data in marker - unsigned int data_offset[MAX_SEQ_NO+1]; // offset for data in marker + jpeg_saved_marker_ptr icc_markers[MAX_SEQ_NO + 1]; + int first; // index of the first marker in the icc_markers array + int last; // index of the last marker in the icc_markers array jbyteArray data = NULL; /* This first pass over the saved markers discovers whether there are * any ICC markers and verifies the consistency of the marker numbering. */ - for (seq_no = 1; seq_no <= MAX_SEQ_NO; seq_no++) - marker_present[seq_no] = 0; + for (seq_no = 0; seq_no <= MAX_SEQ_NO; seq_no++) + icc_markers[seq_no] = NULL; + for (marker = cinfo->marker_list; marker != NULL; marker = marker->next) { if (marker_is_icc(marker)) { @@ -1242,37 +1245,58 @@ read_icc_profile (JNIEnv *env, j_decompress_ptr cinfo) return NULL; } seq_no = GETJOCTET(marker->data[12]); - if (seq_no <= 0 || seq_no > num_markers) { + + /* Some third-party tools produce images with profile chunk + * numeration started from zero. It is inconsistent with ICC + * spec, but seems to be recognized by majority of image + * processing tools, so we should be more tolerant to this + * departure from the spec. + */ + if (seq_no < 0 || seq_no > num_markers) { JNU_ThrowByName(env, "javax/imageio/IIOException", "Invalid icc profile: bad sequence number"); return NULL; } - if (marker_present[seq_no]) { + if (icc_markers[seq_no] != NULL) { JNU_ThrowByName(env, "javax/imageio/IIOException", "Invalid icc profile: duplicate sequence numbers"); return NULL; } - marker_present[seq_no] = 1; - data_length[seq_no] = marker->data_length - ICC_OVERHEAD_LEN; + icc_markers[seq_no] = marker; + num_found_markers ++; } } if (num_markers == 0) return NULL; // There is no profile - /* Check for missing markers, count total space needed, - * compute offset of each marker's part of the data. - */ + if (num_markers != num_found_markers) { + JNU_ThrowByName(env, "javax/imageio/IIOException", + "Invalid icc profile: invalid number of icc markers"); + return NULL; + } + + first = icc_markers[0] ? 0 : 1; + last = num_found_markers + first; + /* Check for missing markers, count total space needed. + */ total_length = 0; - for (seq_no = 1; seq_no <= num_markers; seq_no++) { - if (marker_present[seq_no] == 0) { + for (seq_no = first; seq_no < last; seq_no++) { + unsigned int length; + if (icc_markers[seq_no] == NULL) { JNU_ThrowByName(env, "javax/imageio/IIOException", "Invalid icc profile: missing sequence number"); return NULL; } - data_offset[seq_no] = total_length; - total_length += data_length[seq_no]; + /* check the data length correctness */ + length = icc_markers[seq_no]->data_length; + if (ICC_OVERHEAD_LEN > length || length > MAX_BYTES_IN_MARKER) { + JNU_ThrowByName(env, "javax/imageio/IIOException", + "Invalid icc profile: invalid data length"); + return NULL; + } + total_length += (length - ICC_OVERHEAD_LEN); } if (total_length <= 0) { @@ -1301,19 +1325,14 @@ read_icc_profile (JNIEnv *env, j_decompress_ptr cinfo) } /* and fill it in */ - for (marker = cinfo->marker_list; marker != NULL; marker = marker->next) { - if (marker_is_icc(marker)) { - JOCTET FAR *src_ptr; - JOCTET *dst_ptr; - unsigned int length; - seq_no = GETJOCTET(marker->data[12]); - dst_ptr = icc_data + data_offset[seq_no]; - src_ptr = marker->data + ICC_OVERHEAD_LEN; - length = data_length[seq_no]; - while (length--) { - *dst_ptr++ = *src_ptr++; - } - } + dst_ptr = icc_data; + for (seq_no = first; seq_no < last; seq_no++) { + JOCTET FAR *src_ptr = icc_markers[seq_no]->data + ICC_OVERHEAD_LEN; + unsigned int length = + icc_markers[seq_no]->data_length - ICC_OVERHEAD_LEN; + + memcpy(dst_ptr, src_ptr, length); + dst_ptr += length; } /* finally, unpin the array */ @@ -1530,6 +1549,7 @@ Java_com_sun_imageio_plugins_jpeg_JPEGImageReader_readImageHeader j_decompress_ptr cinfo; struct jpeg_source_mgr *src; sun_jpeg_error_ptr jerr; + jbyteArray profileData = NULL; if (data == NULL) { JNU_ThrowByName(env, @@ -1557,7 +1577,7 @@ Java_com_sun_imageio_plugins_jpeg_JPEGImageReader_readImageHeader return retval; } -#ifdef DEBUG +#ifdef DEBUG_IIO_JPEG printf("In readImageHeader, data is %p cinfo is %p\n", data, cinfo); printf("clearFirst is %d\n", clearFirst); #endif @@ -1584,7 +1604,7 @@ Java_com_sun_imageio_plugins_jpeg_JPEGImageReader_readImageHeader if (ret == JPEG_HEADER_TABLES_ONLY) { retval = JNI_TRUE; imageio_term_source(cinfo); // Pushback remaining buffer contents -#ifdef DEBUG +#ifdef DEBUG_IIO_JPEG printf("just read tables-only image; q table 0 at %p\n", cinfo->quant_tbl_ptrs[0]); #endif @@ -1691,6 +1711,14 @@ Java_com_sun_imageio_plugins_jpeg_JPEGImageReader_readImageHeader } } RELEASE_ARRAYS(env, data, src->next_input_byte); + + /* read icc profile data */ + profileData = read_icc_profile(env, cinfo); + + if ((*env)->ExceptionCheck(env)) { + return retval; + } + (*env)->CallVoidMethod(env, this, JPEGImageReader_setImageDataID, cinfo->image_width, @@ -1698,7 +1726,7 @@ Java_com_sun_imageio_plugins_jpeg_JPEGImageReader_readImageHeader cinfo->jpeg_color_space, cinfo->out_color_space, cinfo->num_components, - read_icc_profile(env, cinfo)); + profileData); if (reset) { jpeg_abort_decompress(cinfo); } @@ -1827,7 +1855,7 @@ Java_com_sun_imageio_plugins_jpeg_JPEGImageReader_readImage (*env)->ReleaseIntArrayElements(env, srcBands, body, JNI_ABORT); -#ifdef DEBUG +#ifdef DEBUG_IIO_JPEG printf("---- in reader.read ----\n"); printf("numBands is %d\n", numBands); printf("bands array: "); @@ -2487,7 +2515,7 @@ Java_com_sun_imageio_plugins_jpeg_JPEGImageWriter_writeTables data->streamBuf.suspendable = FALSE; if (qtables != NULL) { -#ifdef DEBUG +#ifdef DEBUG_IIO_JPEG printf("in writeTables: qtables not NULL\n"); #endif setQTables(env, (j_common_ptr) cinfo, qtables, TRUE); @@ -2763,7 +2791,7 @@ Java_com_sun_imageio_plugins_jpeg_JPEGImageWriter_writeImage cinfo->restart_interval = restartInterval; -#ifdef DEBUG +#ifdef DEBUG_IIO_JPEG printf("writer setup complete, starting compressor\n"); #endif @@ -2812,13 +2840,13 @@ Java_com_sun_imageio_plugins_jpeg_JPEGImageWriter_writeImage for (i = 0; i < numBands; i++) { if (scale !=NULL && scale[i] != NULL) { *out++ = scale[i][*(in+i)]; -#ifdef DEBUG +#ifdef DEBUG_IIO_JPEG if (in == data->pixelBuf.buf.bp){ // Just the first pixel printf("in %d -> out %d, ", *(in+i), *(out-i-1)); } #endif -#ifdef DEBUG +#ifdef DEBUG_IIO_JPEG if (in == data->pixelBuf.buf.bp){ // Just the first pixel printf("\n"); } diff --git a/src/share/native/sun/font/freetypeScaler.c b/src/share/native/sun/font/freetypeScaler.c index 59c1a180c29e14b3f15b10a11f15fca0bc011b5f..4028d4d97c4bb68abdd41452bfdd373c848235a0 100644 --- a/src/share/native/sun/font/freetypeScaler.c +++ b/src/share/native/sun/font/freetypeScaler.c @@ -394,12 +394,14 @@ static int setupFTContext(JNIEnv *env, scalerInfo->env = env; scalerInfo->font2D = font2D; - FT_Set_Transform(scalerInfo->face, &context->transform, NULL); + if (context != NULL) { + FT_Set_Transform(scalerInfo->face, &context->transform, NULL); - errCode = FT_Set_Char_Size(scalerInfo->face, 0, context->ptsz, 72, 72); + errCode = FT_Set_Char_Size(scalerInfo->face, 0, context->ptsz, 72, 72); - if (errCode == 0) { - errCode = FT_Activate_Size(scalerInfo->face->size); + if (errCode == 0) { + errCode = FT_Activate_Size(scalerInfo->face->size); + } } return errCode; @@ -885,6 +887,14 @@ Java_sun_font_FreetypeFontScaler_disposeNativeScaler( JNIEnv *env, jobject scaler, jlong pScaler) { FTScalerInfo* scalerInfo = (FTScalerInfo *) jlong_to_ptr(pScaler); + /* Freetype functions *may* cause callback to java + that can use cached values. Make sure our cache is up to date. + NB: scaler context is not important at this point, can use NULL. */ + int errCode = setupFTContext(env, scaler, scalerInfo, NULL); + if (errCode) { + return; + } + freeNativeResources(env, scalerInfo); } @@ -932,12 +942,21 @@ Java_sun_font_FreetypeFontScaler_getGlyphCodeNative( JNIEnv *env, jobject scaler, jlong pScaler, jchar charCode) { FTScalerInfo* scalerInfo = (FTScalerInfo *) jlong_to_ptr(pScaler); + int errCode; if (scaler == NULL || scalerInfo->face == NULL) { /* bad/null scaler */ invalidateJavaScaler(env, scaler, scalerInfo); return 0; } + /* Freetype functions *may* cause callback to java + that can use cached values. Make sure our cache is up to date. + Scaler context is not important here, can use NULL. */ + errCode = setupFTContext(env, scaler, scalerInfo, NULL); + if (errCode) { + return 0; + } + return FT_Get_Char_Index(scalerInfo->face, charCode); } diff --git a/src/share/native/sun/java2d/cmm/lcms/LCMS.c b/src/share/native/sun/java2d/cmm/lcms/LCMS.c index 0573a021876ba0e29128aca25d79402400315e92..42a5cc23f302b22d6c73eb03c6c7d3caab0c4d9b 100644 --- a/src/share/native/sun/java2d/cmm/lcms/LCMS.c +++ b/src/share/native/sun/java2d/cmm/lcms/LCMS.c @@ -30,6 +30,41 @@ #include "Disposer.h" #include "lcms.h" + +#define ALIGNLONG(x) (((x)+3) & ~(3)) // Aligns to DWORD boundary + +#ifdef USE_BIG_ENDIAN +#define AdjustEndianess32(a) +#else + +static +void AdjustEndianess32(LPBYTE pByte) +{ + BYTE temp1; + BYTE temp2; + + temp1 = *pByte++; + temp2 = *pByte++; + *(pByte-1) = *pByte; + *pByte++ = temp2; + *(pByte-3) = *pByte; + *pByte = temp1; +} + +#endif + +// Transports to properly encoded values - note that icc profiles does use +// big endian notation. + +static +icInt32Number TransportValue32(icInt32Number Value) +{ + icInt32Number Temp = Value; + + AdjustEndianess32((LPBYTE) &Temp); + return Temp; +} + #define SigMake(a,b,c,d) \ ( ( ((int) ((unsigned char) (a))) << 24) | \ ( ((int) ((unsigned char) (b))) << 16) | \ @@ -182,6 +217,8 @@ JNIEXPORT jlong JNICALL Java_sun_java2d_cmm_lcms_LCMS_loadProfile sProf.pf = cmsOpenProfileFromMem((LPVOID)dataArray, (DWORD) dataSize); + (*env)->ReleaseByteArrayElements (env, data, dataArray, 0); + if (sProf.pf == NULL) { JNU_ThrowIllegalArgumentException(env, "Invalid profile data"); } @@ -337,6 +374,10 @@ JNIEXPORT void JNICALL Java_sun_java2d_cmm_lcms_LCMS_getTagData return; } +// Modify data for a tag in a profile +LCMSBOOL LCMSEXPORT _cmsModifyTagData(cmsHPROFILE hProfile, + icTagSignature sig, void *data, size_t size); + /* * Class: sun_java2d_cmm_lcms_LCMS * Method: setTagData @@ -345,7 +386,23 @@ JNIEXPORT void JNICALL Java_sun_java2d_cmm_lcms_LCMS_getTagData JNIEXPORT void JNICALL Java_sun_java2d_cmm_lcms_LCMS_setTagData (JNIEnv *env, jobject obj, jlong id, jint tagSig, jbyteArray data) { - fprintf(stderr, "setTagData operation is not implemented"); + cmsHPROFILE profile; + storeID_t sProf; + jbyte* dataArray; + int tagSize; + + if (tagSig == SigHead) { + J2dRlsTraceLn(J2D_TRACE_ERROR, "LCMS_setTagData on icSigHead not " + "permitted"); + return; + } + + sProf.j = id; + profile = (cmsHPROFILE) sProf.pf; + dataArray = (*env)->GetByteArrayElements(env, data, 0); + tagSize =(*env)->GetArrayLength(env, data); + _cmsModifyTagData(profile, (icTagSignature) tagSig, dataArray, tagSize); + (*env)->ReleaseByteArrayElements(env, data, dataArray, 0); } void* getILData (JNIEnv *env, jobject img, jint* pDataType, @@ -507,3 +564,174 @@ JNIEXPORT void JNICALL Java_sun_java2d_cmm_lcms_LCMS_initLCMS PF_ID_fID = (*env)->GetFieldID (env, Pf, "ID", "J"); } + +LCMSBOOL _cmsModifyTagData(cmsHPROFILE hProfile, icTagSignature sig, + void *data, size_t size) +{ + LCMSBOOL isNew; + int i, idx, delta, count; + LPBYTE padChars[3] = {0, 0, 0}; + LPBYTE beforeBuf, afterBuf, ptr; + size_t beforeSize, afterSize; + icUInt32Number profileSize, temp; + LPLCMSICCPROFILE Icc = (LPLCMSICCPROFILE) (LPSTR) hProfile; + + isNew = FALSE; + idx = _cmsSearchTag(Icc, sig, FALSE); + if (idx < 0) { + isNew = TRUE; + idx = Icc->TagCount++; + if (Icc->TagCount >= MAX_TABLE_TAG) { + J2dRlsTraceLn1(J2D_TRACE_ERROR, "_cmsModifyTagData: Too many tags " + "(%d)\n", Icc->TagCount); + Icc->TagCount = MAX_TABLE_TAG-1; + return FALSE; + } + } + + /* Read in size from header */ + Icc->Seek(Icc, 0); + Icc->Read(&profileSize, sizeof(icUInt32Number), 1, Icc); + AdjustEndianess32((LPBYTE) &profileSize); + + /* Compute the change in profile size */ + if (isNew) { + delta = sizeof(icTag) + ALIGNLONG(size); + } else { + delta = ALIGNLONG(size) - ALIGNLONG(Icc->TagSizes[idx]); + } + /* Add tag to internal structures */ + ptr = malloc(size); + if (ptr == NULL) { + if(isNew) { + Icc->TagCount--; + } + J2dRlsTraceLn(J2D_TRACE_ERROR, "_cmsModifyTagData: ptr == NULL"); + return FALSE; + } + + if (!Icc->Grow(Icc, delta)) { + free(ptr); + if(isNew) { + Icc->TagCount--; + } + J2dRlsTraceLn(J2D_TRACE_ERROR, + "_cmsModifyTagData: Icc->Grow() == FALSE"); + return FALSE; + } + + /* Compute size of tag data before/after the modified tag */ + beforeSize = ((isNew)?profileSize:Icc->TagOffsets[idx]) - + Icc->TagOffsets[0]; + if (Icc->TagCount == (idx + 1)) { + afterSize = 0; + } else { + afterSize = profileSize - Icc->TagOffsets[idx+1]; + } + /* Make copies of the data before/after the modified tag */ + if (beforeSize > 0) { + beforeBuf = malloc(beforeSize); + if (!beforeBuf) { + if(isNew) { + Icc->TagCount--; + } + free(ptr); + J2dRlsTraceLn(J2D_TRACE_ERROR, + "_cmsModifyTagData: beforeBuf == NULL"); + return FALSE; + } + Icc->Seek(Icc, Icc->TagOffsets[0]); + Icc->Read(beforeBuf, beforeSize, 1, Icc); + } + + if (afterSize > 0) { + afterBuf = malloc(afterSize); + if (!afterBuf) { + free(ptr); + if(isNew) { + Icc->TagCount--; + } + if (beforeSize > 0) { + free(beforeBuf); + } + J2dRlsTraceLn(J2D_TRACE_ERROR, + "_cmsModifyTagData: afterBuf == NULL"); + return FALSE; + } + Icc->Seek(Icc, Icc->TagOffsets[idx+1]); + Icc->Read(afterBuf, afterSize, 1, Icc); + } + + CopyMemory(ptr, data, size); + Icc->TagSizes[idx] = size; + Icc->TagNames[idx] = sig; + if (Icc->TagPtrs[idx]) { + free(Icc->TagPtrs[idx]); + } + Icc->TagPtrs[idx] = ptr; + if (isNew) { + Icc->TagOffsets[idx] = profileSize; + } + + + /* Update the profile size in the header */ + profileSize += delta; + Icc->Seek(Icc, 0); + temp = TransportValue32(profileSize); + Icc->Write(Icc, sizeof(icUInt32Number), &temp); + + + /* Adjust tag offsets: if the tag is new, we must account + for the new tag table entry; otherwise, only those tags after + the modified tag are changed (by delta) */ + if (isNew) { + for (i = 0; i < Icc->TagCount; ++i) { + Icc->TagOffsets[i] += sizeof(icTag); + } + } else { + for (i = idx+1; i < Icc->TagCount; ++i) { + Icc->TagOffsets[i] += delta; + } + } + + /* Write out a new tag table */ + count = 0; + for (i = 0; i < Icc->TagCount; ++i) { + if (Icc->TagNames[i] != 0) { + ++count; + } + } + Icc->Seek(Icc, sizeof(icHeader)); + temp = TransportValue32(count); + Icc->Write(Icc, sizeof(icUInt32Number), &temp); + + for (i = 0; i < Icc->TagCount; ++i) { + if (Icc->TagNames[i] != 0) { + icTag tag; + tag.sig = TransportValue32(Icc->TagNames[i]); + tag.offset = TransportValue32((icInt32Number) Icc->TagOffsets[i]); + tag.size = TransportValue32((icInt32Number) Icc->TagSizes[i]); + Icc->Write(Icc, sizeof(icTag), &tag); + } + } + + /* Write unchanged data before the modified tag */ + if (beforeSize > 0) { + Icc->Write(Icc, beforeSize, beforeBuf); + free(beforeBuf); + } + + /* Write modified tag data */ + Icc->Write(Icc, size, data); + if (size % 4) { + Icc->Write(Icc, 4 - (size % 4), padChars); + } + + /* Write unchanged data after the modified tag */ + if (afterSize > 0) { + Icc->Write(Icc, afterSize, afterBuf); + free(afterBuf); + } + + return TRUE; +} diff --git a/src/share/native/sun/java2d/cmm/lcms/cmscam02.c b/src/share/native/sun/java2d/cmm/lcms/cmscam02.c index 9aa971cb8781354494c78fc1fbce0fe51aafcd40..c560470c4999cf4500ff3dafc8aefb376ff86280 100644 --- a/src/share/native/sun/java2d/cmm/lcms/cmscam02.c +++ b/src/share/native/sun/java2d/cmm/lcms/cmscam02.c @@ -29,7 +29,7 @@ // // // Little cms -// Copyright (C) 1998-2006 Marti Maria +// Copyright (C) 1998-2007 Marti Maria // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the "Software"), @@ -51,7 +51,7 @@ -// CIECAM 02 appearance model +// CIECAM 02 appearance model. Many thanks to Jordi Vilar for the debugging. #include "lcms.h" @@ -196,6 +196,10 @@ CAM02COLOR NonlinearCompression(CAM02COLOR clr, LPcmsCIECAM02 pMod) clr.RGBpa[i] = (400.0 * temp) / (temp + 27.13) + 0.1; } } + + clr.A = (((2.0 * clr.RGBpa[0]) + clr.RGBpa[1] + + (clr.RGBpa[2] / 20.0)) - 0.305) * pMod->Nbb; + return clr; } @@ -249,9 +253,6 @@ CAM02COLOR ComputeCorrelates(CAM02COLOR clr, LPcmsCIECAM02 pMod) clr.H = 300 + ((100*((clr.h - 237.53)/1.2)) / temp); } - clr.A = (((2.0 * clr.RGBpa[0]) + clr.RGBpa[1] + - (clr.RGBpa[2] / 20.0)) - 0.305) * pMod->Nbb; - clr.J = 100.0 * pow((clr.A / pMod->adoptedWhite.A), (pMod->c * pMod->z)); @@ -395,7 +396,7 @@ LCMSHANDLE LCMSEXPORT cmsCIECAM02Init(LPcmsViewingConditions pVC) LPcmsCIECAM02 lpMod; - if((lpMod = (LPcmsCIECAM02) malloc(sizeof(cmsCIECAM02))) == NULL) { + if((lpMod = (LPcmsCIECAM02) _cmsMalloc(sizeof(cmsCIECAM02))) == NULL) { return (LCMSHANDLE) NULL; } @@ -449,14 +450,19 @@ LCMSHANDLE LCMSEXPORT cmsCIECAM02Init(LPcmsViewingConditions pVC) lpMod -> z = compute_z(lpMod); lpMod -> Nbb = computeNbb(lpMod); lpMod -> FL = computeFL(lpMod); + + if (lpMod -> D == D_CALCULATE || + lpMod -> D == D_CALCULATE_DISCOUNT) { + lpMod -> D = computeD(lpMod); + } + lpMod -> Ncb = lpMod -> Nbb; lpMod -> adoptedWhite = XYZtoCAT02(lpMod -> adoptedWhite); lpMod -> adoptedWhite = ChromaticAdaptation(lpMod -> adoptedWhite, lpMod); lpMod -> adoptedWhite = CAT02toHPE(lpMod -> adoptedWhite); lpMod -> adoptedWhite = NonlinearCompression(lpMod -> adoptedWhite, lpMod); - lpMod -> adoptedWhite = ComputeCorrelates(lpMod -> adoptedWhite, lpMod); return (LCMSHANDLE) lpMod; @@ -465,7 +471,7 @@ LCMSHANDLE LCMSEXPORT cmsCIECAM02Init(LPcmsViewingConditions pVC) void LCMSEXPORT cmsCIECAM02Done(LCMSHANDLE hModel) { LPcmsCIECAM02 lpMod = (LPcmsCIECAM02) (LPSTR) hModel; - if (lpMod) free(lpMod); + if (lpMod) _cmsFree(lpMod); } @@ -510,3 +516,4 @@ void LCMSEXPORT cmsCIECAM02Reverse(LCMSHANDLE hModel, LPcmsJCh pIn, LPcmsCIEXYZ pOut ->Z = clr.XYZ[2]; } + diff --git a/src/share/native/sun/java2d/cmm/lcms/cmscam97.c b/src/share/native/sun/java2d/cmm/lcms/cmscam97.c index a49a3e6dc0e153f7aa4e4ed3bfe750a0d8a71b2a..5c70ff458b71167a3f681364949e28d780634c67 100644 --- a/src/share/native/sun/java2d/cmm/lcms/cmscam97.c +++ b/src/share/native/sun/java2d/cmm/lcms/cmscam97.c @@ -29,7 +29,7 @@ // // // Little cms -// Copyright (C) 1998-2006 Marti Maria +// Copyright (C) 1998-2007 Marti Maria // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the "Software"), @@ -174,7 +174,7 @@ typedef struct { LCMSAPI void LCMSEXPORT cmsCIECAM97sDone(LCMSHANDLE hModel) { LPcmsCIECAM97s lpMod = (LPcmsCIECAM97s) (LPSTR) hModel; - if (lpMod) free(lpMod); + if (lpMod) _cmsFree(lpMod); } // Partial discounting for adaptation degree computation @@ -331,7 +331,7 @@ LCMSAPI LCMSHANDLE LCMSEXPORT cmsCIECAM97sInit(LPcmsViewingConditions pVC) LPcmsCIECAM97s lpMod; VEC3 tmp; - if((lpMod = (LPcmsCIECAM97s) malloc(sizeof(cmsCIECAM97s))) == NULL) { + if((lpMod = (LPcmsCIECAM97s) _cmsMalloc(sizeof(cmsCIECAM97s))) == NULL) { return (LCMSHANDLE) NULL; } @@ -449,7 +449,7 @@ LCMSAPI LCMSHANDLE LCMSEXPORT cmsCIECAM97sInit(LPcmsViewingConditions pVC) // RGB_subw = [MlamRigg][WP/YWp] #ifdef USE_CIECAM97s2 - MAT3eval(&lpMod -> RGB_subw, &lpMod -> MlamRigg, (LPVEC3) &lpMod -> WP); + MAT3eval(&lpMod -> RGB_subw, &lpMod -> MlamRigg, &lpMod -> WP); #else VEC3divK(&tmp, (LPVEC3) &lpMod -> WP, lpMod->WP.Y); MAT3eval(&lpMod -> RGB_subw, &lpMod -> MlamRigg, &tmp); diff --git a/src/share/native/sun/java2d/cmm/lcms/cmscgats.c b/src/share/native/sun/java2d/cmm/lcms/cmscgats.c index 2b486437a7749efe52f0ab11f35831e9e3bfa6cf..9f26b854476e840043e7fd9220cd9f4c11d0d2d6 100644 --- a/src/share/native/sun/java2d/cmm/lcms/cmscgats.c +++ b/src/share/native/sun/java2d/cmm/lcms/cmscgats.c @@ -29,7 +29,7 @@ // // // Little cms -// Copyright (C) 1998-2006 Marti Maria +// Copyright (C) 1998-2007 Marti Maria // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the "Software"), @@ -65,22 +65,25 @@ LCMSAPI int LCMSEXPORT cmsIT8SetTable(LCMSHANDLE IT8, int nTable); // Persistence LCMSAPI LCMSHANDLE LCMSEXPORT cmsIT8LoadFromFile(const char* cFileName); LCMSAPI LCMSHANDLE LCMSEXPORT cmsIT8LoadFromMem(void *Ptr, size_t len); -LCMSAPI BOOL LCMSEXPORT cmsIT8SaveToFile(LCMSHANDLE IT8, const char* cFileName); +LCMSAPI LCMSBOOL LCMSEXPORT cmsIT8SaveToFile(LCMSHANDLE IT8, const char* cFileName); // Properties LCMSAPI const char* LCMSEXPORT cmsIT8GetSheetType(LCMSHANDLE hIT8); -LCMSAPI BOOL LCMSEXPORT cmsIT8SetSheetType(LCMSHANDLE hIT8, const char* Type); +LCMSAPI LCMSBOOL LCMSEXPORT cmsIT8SetSheetType(LCMSHANDLE hIT8, const char* Type); -LCMSAPI BOOL LCMSEXPORT cmsIT8SetComment(LCMSHANDLE hIT8, const char* cComment); +LCMSAPI LCMSBOOL LCMSEXPORT cmsIT8SetComment(LCMSHANDLE hIT8, const char* cComment); -LCMSAPI BOOL LCMSEXPORT cmsIT8SetPropertyStr(LCMSHANDLE hIT8, const char* cProp, const char *Str); -LCMSAPI BOOL LCMSEXPORT cmsIT8SetPropertyDbl(LCMSHANDLE hIT8, const char* cProp, double Val); -LCMSAPI BOOL LCMSEXPORT cmsIT8SetPropertyHex(LCMSHANDLE hIT8, const char* cProp, int Val); -LCMSAPI BOOL LCMSEXPORT cmsIT8SetPropertyUncooked(LCMSHANDLE hIT8, const char* Key, const char* Buffer); +LCMSAPI LCMSBOOL LCMSEXPORT cmsIT8SetPropertyStr(LCMSHANDLE hIT8, const char* cProp, const char *Str); +LCMSAPI LCMSBOOL LCMSEXPORT cmsIT8SetPropertyDbl(LCMSHANDLE hIT8, const char* cProp, double Val); +LCMSAPI LCMSBOOL LCMSEXPORT cmsIT8SetPropertyHex(LCMSHANDLE hIT8, const char* cProp, int Val); +LCMSAPI LCMSBOOL LCMSEXPORT cmsIT8SetPropertyMulti(LCMSHANDLE hIT8, const char* cProp, const char* cSubProp, const char *Val); +LCMSAPI LCMSBOOL LCMSEXPORT cmsIT8SetPropertyUncooked(LCMSHANDLE hIT8, const char* Key, const char* Buffer); LCMSAPI const char* LCMSEXPORT cmsIT8GetProperty(LCMSHANDLE hIT8, const char* cProp); LCMSAPI double LCMSEXPORT cmsIT8GetPropertyDbl(LCMSHANDLE hIT8, const char* cProp); -LCMSAPI int LCMSEXPORT cmsIT8EnumProperties(LCMSHANDLE IT8, char ***PropertyNames); +LCMSAPI const char* LCMSEXPORT cmsIT8GetPropertyMulti(LCMSHANDLE hIT8, const char* cProp, const char *cSubProp); +LCMSAPI int LCMSEXPORT cmsIT8EnumProperties(LCMSHANDLE IT8, const char ***PropertyNames); +LCMSAPI int LCMSEXPORT cmsIT8EnumPropertyMulti(LCMSHANDLE hIT8, const char* cProp, const char*** SubpropertyNames); // Datasets @@ -89,10 +92,10 @@ LCMSAPI const char* LCMSEXPORT cmsIT8GetPatchName(LCMSHANDLE hIT8, int nPatc LCMSAPI const char* LCMSEXPORT cmsIT8GetDataRowCol(LCMSHANDLE IT8, int row, int col); LCMSAPI double LCMSEXPORT cmsIT8GetDataRowColDbl(LCMSHANDLE IT8, int col, int row); -LCMSAPI BOOL LCMSEXPORT cmsIT8SetDataRowCol(LCMSHANDLE hIT8, int row, int col, +LCMSAPI LCMSBOOL LCMSEXPORT cmsIT8SetDataRowCol(LCMSHANDLE hIT8, int row, int col, const char* Val); -LCMSAPI BOOL LCMSEXPORT cmsIT8SetDataRowColDbl(LCMSHANDLE hIT8, int row, int col, +LCMSAPI LCMSBOOL LCMSEXPORT cmsIT8SetDataRowColDbl(LCMSHANDLE hIT8, int row, int col, double Val); LCMSAPI const char* LCMSEXPORT cmsIT8GetData(LCMSHANDLE IT8, const char* cPatch, const char* cSample); @@ -100,15 +103,15 @@ LCMSAPI const char* LCMSEXPORT cmsIT8GetData(LCMSHANDLE IT8, const char* cPa LCMSAPI double LCMSEXPORT cmsIT8GetDataDbl(LCMSHANDLE IT8, const char* cPatch, const char* cSample); -LCMSAPI BOOL LCMSEXPORT cmsIT8SetData(LCMSHANDLE IT8, const char* cPatch, +LCMSAPI LCMSBOOL LCMSEXPORT cmsIT8SetData(LCMSHANDLE IT8, const char* cPatch, const char* cSample, const char *Val); -LCMSAPI BOOL LCMSEXPORT cmsIT8SetDataDbl(LCMSHANDLE hIT8, const char* cPatch, +LCMSAPI LCMSBOOL LCMSEXPORT cmsIT8SetDataDbl(LCMSHANDLE hIT8, const char* cPatch, const char* cSample, double Val); -LCMSAPI BOOL LCMSEXPORT cmsIT8SetDataFormat(LCMSHANDLE IT8, int n, const char *Sample); +LCMSAPI LCMSBOOL LCMSEXPORT cmsIT8SetDataFormat(LCMSHANDLE IT8, int n, const char *Sample); LCMSAPI int LCMSEXPORT cmsIT8EnumDataFormat(LCMSHANDLE IT8, char ***SampleNames); LCMSAPI void LCMSEXPORT cmsIT8DefineDblFormat(LCMSHANDLE IT8, const char* Formatter); @@ -126,7 +129,7 @@ LCMSAPI int LCMSEXPORT cmsIT8SetTableByLabel(LCMSHANDLE hIT8, const // #define STRICT_CGATS 1 #define MAXID 128 // Max lenght of identifier -#define MAXSTR 255 // Max lenght of string +#define MAXSTR 1024 // Max lenght of string #define MAXTABLES 255 // Max Number of tables in a single stream #define MAXINCLUDE 20 // Max number of nested includes @@ -137,6 +140,9 @@ LCMSAPI int LCMSEXPORT cmsIT8SetTableByLabel(LCMSHANDLE hIT8, const #ifndef NON_WINDOWS #include <io.h> +#define DIR_CHAR '\\' +#else +#define DIR_CHAR '/' #endif // Symbols @@ -160,6 +166,7 @@ typedef enum { SEND_DATA, SEND_DATA_FORMAT, SKEYWORD, + SDATA_FORMAT_ID, SINCLUDE } SYMBOL; @@ -171,7 +178,8 @@ typedef enum { WRITE_UNCOOKED, WRITE_STRINGIFY, WRITE_HEXADECIMAL, - WRITE_BINARY + WRITE_BINARY, + WRITE_PAIR } WRITEMODE; @@ -181,6 +189,8 @@ typedef struct _KeyVal { struct _KeyVal* Next; char* Keyword; // Name of variable + struct _KeyVal* NextSubkey; // If key is a dictionary, points to the next item + char* Subkey; // If key is a dictionary, points to the subkey name char* Value; // Points to value WRITEMODE WriteAs; // How to write the value @@ -220,7 +230,12 @@ typedef struct _Table { } TABLE, *LPTABLE; +// File stream being parsed +typedef struct _FileContext { + char FileName[MAX_PATH]; // File name if being readed from file + FILE* Stream; // File stream or NULL if holded in memory + } FILECTX, *LPFILECTX; // This struct hold all information about an openened // IT8 handler. Only one dataset is allowed. @@ -257,9 +272,9 @@ typedef struct { char* Source; // Points to loc. being parsed int lineno; // line counter for error reporting - char FileName[MAX_PATH]; // File name if being readed from file - FILE* Stream[MAXINCLUDE]; // File stream or NULL if holded in memory + LPFILECTX FileStack[MAXINCLUDE]; // Stack of files being parsed int IncludeSP; // Include Stack Pointer + char* MemoryBlock; // The stream if holded in memory char DoubleFormatter[MAXID]; // Printf-like 'double' formatter @@ -270,14 +285,14 @@ typedef struct { typedef struct { - FILE* stream; // For save-to-file behaviour + FILE* stream; // For save-to-file behaviour - LPBYTE Base; - LPBYTE Ptr; // For save-to-mem behaviour - size_t Used; - size_t Max; + LPBYTE Base; + LPBYTE Ptr; // For save-to-mem behaviour + size_t Used; + size_t Max; - } SAVESTREAM, FAR* LPSAVESTREAM; + } SAVESTREAM, FAR* LPSAVESTREAM; // ------------------------------------------------------ IT8 parsing routines @@ -298,59 +313,104 @@ static const KEYWORD TabKeys[] = { {".INCLUDE", SINCLUDE}, {"BEGIN_DATA", SBEGIN_DATA }, {"BEGIN_DATA_FORMAT", SBEGIN_DATA_FORMAT }, + {"DATA_FORMAT_IDENTIFIER", SDATA_FORMAT_ID}, {"END_DATA", SEND_DATA}, {"END_DATA_FORMAT", SEND_DATA_FORMAT}, {"KEYWORD", SKEYWORD} - }; #define NUMKEYS (sizeof(TabKeys)/sizeof(KEYWORD)) // Predefined properties -static const char* PredefinedProperties[] = { - - "NUMBER_OF_FIELDS", // Required - NUMBER OF FIELDS - "NUMBER_OF_SETS", // Required - NUMBER OF SETS - "ORIGINATOR", // Required - Identifies the specific system, organization or individual that created the data file. - "FILE_DESCRIPTOR", // Required - Describes the purpose or contents of the data file. - "CREATED", // Required - Indicates date of creation of the data file. - "DESCRIPTOR", // Required - Describes the purpose or contents of the data file. - "DIFFUSE_GEOMETRY", // The diffuse geometry used. Allowed values are "sphere" or "opal". - "MANUFACTURER", - "MANUFACTURE", // Some broken Fuji targets does store this value - "PROD_DATE", // Identifies year and month of production of the target in the form yyyy:mm. - "SERIAL", // Uniquely identifies individual physical target. - - "MATERIAL", // Identifies the material on which the target was produced using a code +// A property +typedef struct { + const char *id; + WRITEMODE as; + } PROPERTY; + +static PROPERTY PredefinedProperties[] = { + + {"NUMBER_OF_FIELDS", WRITE_UNCOOKED}, // Required - NUMBER OF FIELDS + {"NUMBER_OF_SETS", WRITE_UNCOOKED}, // Required - NUMBER OF SETS + {"ORIGINATOR", WRITE_STRINGIFY}, // Required - Identifies the specific system, organization or individual that created the data file. + {"FILE_DESCRIPTOR", WRITE_STRINGIFY}, // Required - Describes the purpose or contents of the data file. + {"CREATED", WRITE_STRINGIFY}, // Required - Indicates date of creation of the data file. + {"DESCRIPTOR", WRITE_STRINGIFY}, // Required - Describes the purpose or contents of the data file. + {"DIFFUSE_GEOMETRY", WRITE_STRINGIFY}, // The diffuse geometry used. Allowed values are "sphere" or "opal". + {"MANUFACTURER", WRITE_STRINGIFY}, + {"MANUFACTURE", WRITE_STRINGIFY}, // Some broken Fuji targets does store this value + {"PROD_DATE", WRITE_STRINGIFY}, // Identifies year and month of production of the target in the form yyyy:mm. + {"SERIAL", WRITE_STRINGIFY}, // Uniquely identifies individual physical target. + + {"MATERIAL", WRITE_STRINGIFY}, // Identifies the material on which the target was produced using a code // uniquely identifying th e material. This is intend ed to be used for IT8.7 // physical targets only (i.e . IT8.7/1 a nd IT8.7/2). - "INSTRUMENTATION", // Used to report the specific instrumentation used (manufacturer and + {"INSTRUMENTATION", WRITE_STRINGIFY}, // Used to report the specific instrumentation used (manufacturer and // model number) to generate the data reported. This data will often // provide more information about the particular data collected than an // extensive list of specific details. This is particularly important for // spectral data or data derived from spectrophotometry. - "MEASUREMENT_SOURCE", // Illumination used for spectral measurements. This data helps provide + {"MEASUREMENT_SOURCE", WRITE_STRINGIFY}, // Illumination used for spectral measurements. This data helps provide // a guide to the potential for issues of paper fluorescence, etc. - "PRINT_CONDITIONS", // Used to define the characteristics of the printed sheet being reported. + {"PRINT_CONDITIONS", WRITE_STRINGIFY}, // Used to define the characteristics of the printed sheet being reported. // Where standard conditions have been defined (e.g., SWOP at nominal) // named conditions may suffice. Otherwise, detailed information is // needed. - "SAMPLE_BACKING", // Identifies the backing material used behind the sample during - // measurement. Allowed values are “black”, “white”, or "na". + {"SAMPLE_BACKING", WRITE_STRINGIFY}, // Identifies the backing material used behind the sample during + // measurement. Allowed values are “black”, “white”, or {"na". + + {"CHISQ_DOF", WRITE_STRINGIFY}, // Degrees of freedom associated with the Chi squared statistic + +// new in recent specs: + {"MEASUREMENT_GEOMETRY", WRITE_STRINGIFY}, // The type of measurement, either reflection or transmission, should be indicated + // along with details of the geometry and the aperture size and shape. For example, + // for transmission measurements it is important to identify 0/diffuse, diffuse/0, + // opal or integrating sphere, etc. For reflection it is important to identify 0/45, + // 45/0, sphere (specular included or excluded), etc. + + {"FILTER", WRITE_STRINGIFY}, // Identifies the use of physical filter(s) during measurement. Typically used to + // denote the use of filters such as none, D65, Red, Green or Blue. + + {"POLARIZATION", WRITE_STRINGIFY}, // Identifies the use of a physical polarization filter during measurement. Allowed + // values are {"yes”, “white”, “none” or “na”. + + {"WEIGHTING_FUNCTION", WRITE_PAIR}, // Indicates such functions as: the CIE standard observer functions used in the + // calculation of various data parameters (2 degree and 10 degree), CIE standard + // illuminant functions used in the calculation of various data parameters (e.g., D50, + // D65, etc.), density status response, etc. If used there shall be at least one + // name-value pair following the WEIGHTING_FUNCTION tag/keyword. The first attribute + // in the set shall be {"name" and shall identify the particular parameter used. + // The second shall be {"value" and shall provide the value associated with that name. + // For ASCII data, a string containing the Name and Value attribute pairs shall follow + // the weighting function keyword. A semi-colon separates attribute pairs from each + // other and within the attribute the name and value are separated by a comma. - "CHISQ_DOF" // Degrees of freedom associated with the Chi squared statistic + {"COMPUTATIONAL_PARAMETER", WRITE_PAIR}, // Parameter that is used in computing a value from measured data. Name is the name + // of the calculation, parameter is the name of the parameter used in the calculation + // and value is the value of the parameter. + + {"TARGET_TYPE", WRITE_STRINGIFY}, // The type of target being measured, e.g. IT8.7/1, IT8.7/3, user defined, etc. + + {"COLORANT", WRITE_STRINGIFY}, // Identifies the colorant(s) used in creating the target. + + {"TABLE_DESCRIPTOR", WRITE_STRINGIFY}, // Describes the purpose or contents of a data table. + + {"TABLE_NAME", WRITE_STRINGIFY} // Provides a short name for a data table. }; -#define NUMPREDEFINEDPROPS (sizeof(PredefinedProperties)/sizeof(char *)) +#define NUMPREDEFINEDPROPS (sizeof(PredefinedProperties)/sizeof(PROPERTY)) // Predefined sample types on dataset static const char* PredefinedSampleID[] = { + "SAMPLE_ID", // Identifies sample that data represents + "STRING", // Identifies label, or other non-machine readable value. + // Value must begin and end with a " symbol "CMYK_C", // Cyan component of CMYK data expressed as a percentage "CMYK_M", // Magenta component of CMYK data expressed as a percentage @@ -378,7 +438,7 @@ static const char* PredefinedSampleID[] = { "LAB_B", // b* component of Lab data "LAB_C", // C*ab component of Lab data "LAB_H", // hab component of Lab data - "LAB_DE" // CIE dE + "LAB_DE", // CIE dE "LAB_DE_94", // CIE dE using CIE 94 "LAB_DE_CMC", // dE using CMC "LAB_DE_2000", // CIE dE using CIE DE 2000 @@ -388,7 +448,7 @@ static const char* PredefinedSampleID[] = { "STDEV_Y", // Standard deviation of Y (tristimulus data) "STDEV_Z", // Standard deviation of Z (tristimulus data) "STDEV_L", // Standard deviation of L* - "STDEV_A" // Standard deviation of a* + "STDEV_A", // Standard deviation of a* "STDEV_B", // Standard deviation of b* "STDEV_DE", // Standard deviation of CIE dE "CHI_SQD_PAR"}; // The average of the standard deviations of L*, a* and b*. It is @@ -397,57 +457,120 @@ static const char* PredefinedSampleID[] = { #define NUMPREDEFINEDSAMPLEID (sizeof(PredefinedSampleID)/sizeof(char *)) +//Forward declaration of some internal functions +static +void* AllocChunk(LPIT8 it8, size_t size); + // Checks if c is a separator static -BOOL isseparator(int c) +LCMSBOOL isseparator(int c) { return (c == ' ') || (c == '\t') || (c == '\r'); } // Checks whatever if c is a valid identifier char - static -BOOL ismiddle(int c) +LCMSBOOL ismiddle(int c) { return (!isseparator(c) && (c != '#') && (c !='\"') && (c != '\'') && (c > 32) && (c < 127)); } // Checks whatsever if c is a valid identifier middle char. static -BOOL isidchar(int c) +LCMSBOOL isidchar(int c) { return isalnum(c) || ismiddle(c); } // Checks whatsever if c is a valid identifier first char. static -BOOL isfirstidchar(int c) +LCMSBOOL isfirstidchar(int c) { return !isdigit(c) && ismiddle(c); } +// checks whether the supplied path looks like an absolute path +// NOTE: this function doesn't checks if the path exists or even if it's legal +static +LCMSBOOL isabsolutepath(const char *path) +{ + if(path == NULL) + return FALSE; + + if(path[0] == DIR_CHAR) + return TRUE; + +#ifndef NON_WINDOWS + if(isalpha(path[0]) && path[1] == ':') + return TRUE; +#endif + return FALSE; +} + +// Makes a file path based on a given reference path +// NOTE: buffer is assumed to point to at least MAX_PATH bytes +// NOTE: both relPath and basePath are assumed to be no more than MAX_PATH characters long (including the null terminator!) +// NOTE: this function doesn't check if the path exists or even if it's legal +static +LCMSBOOL _cmsMakePath(const char *relPath, const char *basePath, char *buffer) +{ + if (!isabsolutepath(relPath)) { + + char *tail; + + strncpy(buffer, basePath, MAX_PATH-1); + tail = strrchr(buffer, DIR_CHAR); + if (tail != NULL) { + + size_t len = tail - buffer; + strncpy(tail + 1, relPath, MAX_PATH - len -1); + // TODO: if combined path is longer than MAX_PATH, this should return FALSE! + return TRUE; + } + } + strncpy(buffer, relPath, MAX_PATH - 1); + buffer[MAX_PATH-1] = 0; + return TRUE; +} + + +// Make sure no exploit is being even tried + +static +const char* NoMeta(const char* str) +{ + if (strchr(str, '%') != NULL) + return "**** CORRUPTED FORMAT STRING ***"; + + return str; +} + +// Syntax error static -BOOL SynError(LPIT8 it8, const char *Txt, ...) +LCMSBOOL SynError(LPIT8 it8, const char *Txt, ...) { char Buffer[256], ErrMsg[1024]; va_list args; va_start(args, Txt); - vsprintf(Buffer, Txt, args); + vsnprintf(Buffer, 255, Txt, args); + Buffer[255] = 0; va_end(args); - sprintf(ErrMsg, "%s: Line %d, %s", it8->FileName, it8->lineno, Buffer); + snprintf(ErrMsg, 1023, "%s: Line %d, %s", it8->FileStack[it8 ->IncludeSP]->FileName, it8->lineno, Buffer); + ErrMsg[1023] = 0; it8->sy = SSYNERROR; - cmsSignalError(LCMS_ERRC_ABORTED, ErrMsg); + cmsSignalError(LCMS_ERRC_ABORTED, "%s", ErrMsg); return FALSE; } +// Check if current symbol is same as specified. issue an error else. static -BOOL Check(LPIT8 it8, SYMBOL sy, const char* Err) +LCMSBOOL Check(LPIT8 it8, SYMBOL sy, const char* Err) { if (it8 -> sy != sy) - return SynError(it8, Err); + return SynError(it8, NoMeta(Err)); return TRUE; } @@ -457,15 +580,15 @@ BOOL Check(LPIT8 it8, SYMBOL sy, const char* Err) static void NextCh(LPIT8 it8) { - if (it8 -> Stream[it8 ->IncludeSP]) { + if (it8 -> FileStack[it8 ->IncludeSP]->Stream) { - it8 ->ch = fgetc(it8 ->Stream[it8 ->IncludeSP]); + it8 ->ch = fgetc(it8 ->FileStack[it8 ->IncludeSP]->Stream); - if (feof(it8 -> Stream[it8 ->IncludeSP])) { + if (feof(it8 -> FileStack[it8 ->IncludeSP]->Stream)) { if (it8 ->IncludeSP > 0) { - fclose(it8 ->Stream[it8->IncludeSP--]); + fclose(it8 ->FileStack[it8->IncludeSP--]->Stream); it8 -> ch = ' '; // Whitespace to be ignored } else @@ -476,7 +599,6 @@ void NextCh(LPIT8 it8) } else { - it8->ch = *it8->Source; if (it8->ch) it8->Source++; } @@ -799,18 +921,39 @@ void InSymbol(LPIT8 it8) if (it8 -> sy == SINCLUDE) { - FILE* IncludeFile; + LPFILECTX FileNest; + + if(it8 -> IncludeSP >= (MAXINCLUDE-1)) + { + SynError(it8, "Too many recursion levels"); + return; + } InSymbol(it8); if (!Check(it8, SSTRING, "Filename expected")) return; - IncludeFile = fopen(it8 -> str, "rt"); - if (IncludeFile == NULL) { - SynError(it8, "File %s not found", it8 ->str); + FileNest = it8 -> FileStack[it8 -> IncludeSP + 1]; + if(FileNest == NULL) + { + FileNest = it8 ->FileStack[it8 -> IncludeSP + 1] = (LPFILECTX)AllocChunk(it8, sizeof(FILECTX)); + //if(FileNest == NULL) + // TODO: how to manage out-of-memory conditions? + } + + if(_cmsMakePath(it8->str, it8->FileStack[it8->IncludeSP]->FileName, FileNest->FileName) == FALSE) + { + SynError(it8, "File path too long"); + return; + } + + FileNest->Stream = fopen(FileNest->FileName, "rt"); + if (FileNest->Stream == NULL) { + + SynError(it8, "File %s not found", FileNest->FileName); return; } + it8->IncludeSP++; - it8 -> Stream[++it8 -> IncludeSP] = IncludeFile; it8 ->ch = ' '; InSymbol(it8); } @@ -819,7 +962,7 @@ void InSymbol(LPIT8 it8) // Checks end of line separator static -BOOL CheckEOLN(LPIT8 it8) +LCMSBOOL CheckEOLN(LPIT8 it8) { if (!Check(it8, SEOLN, "Expected separator")) return FALSE; while (it8 -> sy == SEOLN) @@ -850,21 +993,26 @@ void SkipEOLN(LPIT8 it8) // Returns a string holding current value static -BOOL GetVal(LPIT8 it8, char* Buffer, const char* ErrorTitle) +LCMSBOOL GetVal(LPIT8 it8, char* Buffer, size_t max, const char* ErrorTitle) { switch (it8->sy) { - case SIDENT: strncpy(Buffer, it8->id, MAXID-1); break; - case SINUM: sprintf(Buffer, "%d", it8 -> inum); break; - case SDNUM: sprintf(Buffer, it8->DoubleFormatter, it8 -> dnum); break; - case SSTRING: strncpy(Buffer, it8->str, MAXSTR-1); break; + case SIDENT: strncpy(Buffer, it8->id, max); + Buffer[max-1]=0; + break; + case SINUM: snprintf(Buffer, max, "%d", it8 -> inum); break; + case SDNUM: snprintf(Buffer, max, it8->DoubleFormatter, it8 -> dnum); break; + case SSTRING: strncpy(Buffer, it8->str, max); + Buffer[max-1] = 0; + break; default: - return SynError(it8, ErrorTitle); + return SynError(it8, "%s", ErrorTitle); } - return TRUE; + Buffer[max] = 0; + return TRUE; } // ---------------------------------------------------------- Table @@ -872,7 +1020,13 @@ BOOL GetVal(LPIT8 it8, char* Buffer, const char* ErrorTitle) static LPTABLE GetTable(LPIT8 it8) { - return it8 ->Tab + it8 ->nTable; + if ((it8 -> nTable >= it8 ->TablesCount) || (it8 -> nTable < 0)) { + + SynError(it8, "Table %d out of sequence", it8 -> nTable); + return it8 -> Tab; + } + + return it8 ->Tab + it8 ->nTable; } // ---------------------------------------------------------- Memory management @@ -896,15 +1050,15 @@ void LCMSEXPORT cmsIT8Free(LCMSHANDLE hIT8) for (p = it8->MemorySink; p != NULL; p = n) { n = p->Next; - if (p->Ptr) free(p->Ptr); - free(p); + if (p->Ptr) _cmsFree(p->Ptr); + _cmsFree(p); } } if (it8->MemoryBlock) - free(it8->MemoryBlock); + _cmsFree(it8->MemoryBlock); - free(it8); + _cmsFree(it8); } @@ -913,16 +1067,16 @@ static void* AllocBigBlock(LPIT8 it8, size_t size) { LPOWNEDMEM ptr1; - void* ptr = malloc(size); + void* ptr = _cmsMalloc(size); if (ptr) { ZeroMemory(ptr, size); - ptr1 = (LPOWNEDMEM) malloc(sizeof(OWNEDMEM)); + ptr1 = (LPOWNEDMEM) _cmsMalloc(sizeof(OWNEDMEM)); if (ptr1 == NULL) { - free(ptr); + _cmsFree(ptr); return NULL; } @@ -986,8 +1140,9 @@ char *AllocString(LPIT8 it8, const char* str) // Searches through linked list static -BOOL IsAvailableOnList(LPKEYVALUE p, const char* Key, LPKEYVALUE* LastPtr) +LCMSBOOL IsAvailableOnList(LPKEYVALUE p, const char* Key, const char* Subkey, LPKEYVALUE* LastPtr) { + if (LastPtr) *LastPtr = p; for (; p != NULL; p = p->Next) { @@ -996,8 +1151,22 @@ BOOL IsAvailableOnList(LPKEYVALUE p, const char* Key, LPKEYVALUE* LastPtr) if (*Key != '#') { // Comments are ignored if (stricmp(Key, p->Keyword) == 0) - return TRUE; + break; } + } + + if (p == NULL) + return FALSE; + + if (Subkey == 0) + return TRUE; + + for (; p != NULL; p = p->NextSubkey) { + + if (LastPtr) *LastPtr = p; + + if (stricmp(Subkey, p->Subkey) == 0) + return TRUE; } return FALSE; @@ -1007,35 +1176,55 @@ BOOL IsAvailableOnList(LPKEYVALUE p, const char* Key, LPKEYVALUE* LastPtr) // Add a property into a linked list static -BOOL AddToList(LPIT8 it8, LPKEYVALUE* Head, const char *Key, const char* xValue, WRITEMODE WriteAs) +LPKEYVALUE AddToList(LPIT8 it8, LPKEYVALUE* Head, const char *Key, const char *Subkey, const char* xValue, WRITEMODE WriteAs) { LPKEYVALUE p; - LPKEYVALUE last; - // Check if property is already in list (this is an error) - if (IsAvailableOnList(*Head, Key, &last)) { - - // This may work for editing properties + if (IsAvailableOnList(*Head, Key, Subkey, &p)) { - last->Value = AllocString(it8, xValue); - last->WriteAs = WriteAs; - return TRUE; + // This may work for editing properties - // return SynError(it8, "duplicate key <%s>", Key); + // return SynError(it8, "duplicate key <%s>", Key); } + else { + LPKEYVALUE last = p; - // Allocate the container + // Allocate the container p = (LPKEYVALUE) AllocChunk(it8, sizeof(KEYVALUE)); if (p == NULL) { - return SynError(it8, "AddToList: out of memory"); + SynError(it8, "AddToList: out of memory"); + return NULL; } // Store name and value p->Keyword = AllocString(it8, Key); + p->Subkey = (Subkey == NULL) ? NULL : AllocString(it8, Subkey); + + // Keep the container in our list + if (*Head == NULL) + *Head = p; + else + { + if(Subkey != 0 && last != 0) { + last->NextSubkey = p; + + // If Subkey is not null, then last is the last property with the same key, + // but not necessarily is the last property in the list, so we need to move + // to the actual list end + while(last->Next != 0) + last = last->Next; + } + last->Next = p; + } + + p->Next = NULL; + p->NextSubkey = NULL; + } + p->WriteAs = WriteAs; if (xValue != NULL) { p->Value = AllocString(it8, xValue); @@ -1044,29 +1233,20 @@ BOOL AddToList(LPIT8 it8, LPKEYVALUE* Head, const char *Key, const char* xValue, p->Value = NULL; } - p->Next = NULL; - p->WriteAs = WriteAs; - - // Keep the container in our list - if (*Head == NULL) - *Head = p; - else - last->Next = p; - - return TRUE; + return p; } static -BOOL AddAvailableProperty(LPIT8 it8, const char* Key) +LPKEYVALUE AddAvailableProperty(LPIT8 it8, const char* Key, WRITEMODE as) { - return AddToList(it8, &it8->ValidKeywords, Key, NULL, WRITE_UNCOOKED); + return AddToList(it8, &it8->ValidKeywords, Key, NULL, NULL, as); } static -BOOL AddAvailableSampleID(LPIT8 it8, const char* Key) +LPKEYVALUE AddAvailableSampleID(LPIT8 it8, const char* Key) { - return AddToList(it8, &it8->ValidSampleID, Key, NULL, WRITE_UNCOOKED); + return AddToList(it8, &it8->ValidSampleID, Key, NULL, NULL, WRITE_UNCOOKED); } @@ -1122,8 +1302,6 @@ LCMSHANDLE LCMSEXPORT cmsIT8Alloc(void) AllocTable(it8); it8->MemoryBlock = NULL; - it8->Stream[0] = NULL; - it8->IncludeSP = 0; it8->MemorySink = NULL; it8 ->nTable = 0; @@ -1141,6 +1319,8 @@ LCMSHANDLE LCMSEXPORT cmsIT8Alloc(void) it8 -> inum = 0; it8 -> dnum = 0.0; + it8->FileStack[0] = (LPFILECTX)AllocChunk(it8, sizeof(FILECTX)); + it8->IncludeSP = 0; it8 -> lineno = 1; strcpy(it8->DoubleFormatter, DEFAULT_DBL_FORMAT); @@ -1149,7 +1329,7 @@ LCMSHANDLE LCMSEXPORT cmsIT8Alloc(void) // Initialize predefined properties & data for (i=0; i < NUMPREDEFINEDPROPS; i++) - AddAvailableProperty(it8, PredefinedProperties[i]); + AddAvailableProperty(it8, PredefinedProperties[i].id, PredefinedProperties[i].as); for (i=0; i < NUMPREDEFINEDSAMPLEID; i++) AddAvailableSampleID(it8, PredefinedSampleID[i]); @@ -1167,65 +1347,72 @@ const char* LCMSEXPORT cmsIT8GetSheetType(LCMSHANDLE hIT8) } -BOOL LCMSEXPORT cmsIT8SetSheetType(LCMSHANDLE hIT8, const char* Type) +LCMSBOOL LCMSEXPORT cmsIT8SetSheetType(LCMSHANDLE hIT8, const char* Type) { LPIT8 it8 = (LPIT8) hIT8; strncpy(it8 ->SheetType, Type, MAXSTR-1); + it8 ->SheetType[MAXSTR-1] = 0; return TRUE; } -BOOL LCMSEXPORT cmsIT8SetComment(LCMSHANDLE hIT8, const char* Val) +LCMSBOOL LCMSEXPORT cmsIT8SetComment(LCMSHANDLE hIT8, const char* Val) { LPIT8 it8 = (LPIT8) hIT8; if (!Val) return FALSE; if (!*Val) return FALSE; - return AddToList(it8, &GetTable(it8)->HeaderList, "# ", Val, WRITE_UNCOOKED); + return AddToList(it8, &GetTable(it8)->HeaderList, "# ", NULL, Val, WRITE_UNCOOKED) != NULL; } // Sets a property -BOOL LCMSEXPORT cmsIT8SetPropertyStr(LCMSHANDLE hIT8, const char* Key, const char *Val) +LCMSBOOL LCMSEXPORT cmsIT8SetPropertyStr(LCMSHANDLE hIT8, const char* Key, const char *Val) { LPIT8 it8 = (LPIT8) hIT8; if (!Val) return FALSE; if (!*Val) return FALSE; - return AddToList(it8, &GetTable(it8)->HeaderList, Key, Val, WRITE_STRINGIFY); + return AddToList(it8, &GetTable(it8)->HeaderList, Key, NULL, Val, WRITE_STRINGIFY) != NULL; } -BOOL LCMSEXPORT cmsIT8SetPropertyDbl(LCMSHANDLE hIT8, const char* cProp, double Val) +LCMSBOOL LCMSEXPORT cmsIT8SetPropertyDbl(LCMSHANDLE hIT8, const char* cProp, double Val) { LPIT8 it8 = (LPIT8) hIT8; char Buffer[1024]; sprintf(Buffer, it8->DoubleFormatter, Val); - return AddToList(it8, &GetTable(it8)->HeaderList, cProp, Buffer, WRITE_UNCOOKED); + return AddToList(it8, &GetTable(it8)->HeaderList, cProp, NULL, Buffer, WRITE_UNCOOKED) != NULL; } -BOOL LCMSEXPORT cmsIT8SetPropertyHex(LCMSHANDLE hIT8, const char* cProp, int Val) +LCMSBOOL LCMSEXPORT cmsIT8SetPropertyHex(LCMSHANDLE hIT8, const char* cProp, int Val) { LPIT8 it8 = (LPIT8) hIT8; char Buffer[1024]; sprintf(Buffer, "%d", Val); - return AddToList(it8, &GetTable(it8)->HeaderList, cProp, Buffer, WRITE_HEXADECIMAL); + return AddToList(it8, &GetTable(it8)->HeaderList, cProp, NULL, Buffer, WRITE_HEXADECIMAL) != NULL; } -BOOL LCMSEXPORT cmsIT8SetPropertyUncooked(LCMSHANDLE hIT8, const char* Key, const char* Buffer) +LCMSBOOL LCMSEXPORT cmsIT8SetPropertyUncooked(LCMSHANDLE hIT8, const char* Key, const char* Buffer) { LPIT8 it8 = (LPIT8) hIT8; - return AddToList(it8, &GetTable(it8)->HeaderList, Key, Buffer, WRITE_UNCOOKED); + return AddToList(it8, &GetTable(it8)->HeaderList, Key, NULL, Buffer, WRITE_UNCOOKED) != NULL; } +LCMSBOOL LCMSEXPORT cmsIT8SetPropertyMulti(LCMSHANDLE hIT8, const char* Key, const char* SubKey, const char *Buffer) +{ + LPIT8 it8 = (LPIT8) hIT8; + + return AddToList(it8, &GetTable(it8)->HeaderList, Key, SubKey, Buffer, WRITE_PAIR) != NULL; +} // Gets a property const char* LCMSEXPORT cmsIT8GetProperty(LCMSHANDLE hIT8, const char* Key) @@ -1233,7 +1420,7 @@ const char* LCMSEXPORT cmsIT8GetProperty(LCMSHANDLE hIT8, const char* Key) LPIT8 it8 = (LPIT8) hIT8; LPKEYVALUE p; - if (IsAvailableOnList(GetTable(it8) -> HeaderList, Key, &p)) + if (IsAvailableOnList(GetTable(it8) -> HeaderList, Key, NULL, &p)) { return p -> Value; } @@ -1249,6 +1436,18 @@ double LCMSEXPORT cmsIT8GetPropertyDbl(LCMSHANDLE hIT8, const char* cProp) else return 0.0; } +const char* LCMSEXPORT cmsIT8GetPropertyMulti(LCMSHANDLE hIT8, const char* Key, const char *SubKey) +{ + LPIT8 it8 = (LPIT8) hIT8; + LPKEYVALUE p; + + if (IsAvailableOnList(GetTable(it8) -> HeaderList, Key, SubKey, &p)) + { + return p -> Value; + } + return NULL; +} + // ----------------------------------------------------------------- Datasets @@ -1287,10 +1486,17 @@ const char *GetDataFormat(LPIT8 it8, int n) } static -BOOL SetDataFormat(LPIT8 it8, int n, const char *label) +LCMSBOOL SetDataFormat(LPIT8 it8, int n, const char *label) { LPTABLE t = GetTable(it8); +#ifdef STRICT_CGATS + if (!IsAvailableOnList(it8-> ValidSampleID, label, NULL, NULL)) { + SynError(it8, "Invalid data format '%s'.", label); + return FALSE; + } +#endif + if (!t->DataFormat) AllocateDataFormat(it8); @@ -1308,7 +1514,7 @@ BOOL SetDataFormat(LPIT8 it8, int n, const char *label) } -BOOL LCMSEXPORT cmsIT8SetDataFormat(LCMSHANDLE h, int n, const char *Sample) +LCMSBOOL LCMSEXPORT cmsIT8SetDataFormat(LCMSHANDLE h, int n, const char *Sample) { LPIT8 it8 = (LPIT8) h; return SetDataFormat(it8, n, Sample); @@ -1348,7 +1554,7 @@ char* GetData(LPIT8 it8, int nSet, int nField) } static -BOOL SetData(LPIT8 it8, int nSet, int nField, const char *Val) +LCMSBOOL SetData(LPIT8 it8, int nSet, int nField, const char *Val) { LPTABLE t = GetTable(it8); @@ -1383,42 +1589,43 @@ static void WriteStr(LPSAVESTREAM f, const char *str) { - size_t len; + size_t len; - if (str == NULL) - str = " "; + if (str == NULL) + str = " "; - // Lenghth to write - len = strlen(str); + // Lenghth to write + len = strlen(str); f ->Used += len; - if (f ->stream) { // Should I write it to a file? - - fwrite(str, 1, len, f->stream); + if (f ->stream) { // Should I write it to a file? - } - else { // Or to a memory block? + fwrite(str, 1, len, f->stream); + } + else { // Or to a memory block? - if (f ->Base) { // Am I just counting the bytes? - if (f ->Used > f ->Max) { + if (f ->Base) { // Am I just counting the bytes? - cmsSignalError(LCMS_ERRC_ABORTED, "Write to memory overflows in CGATS parser"); - return; - } + if (f ->Used > f ->Max) { - CopyMemory(f ->Ptr, str, len); - f->Ptr += len; + cmsSignalError(LCMS_ERRC_ABORTED, "Write to memory overflows in CGATS parser"); + return; + } - } + CopyMemory(f ->Ptr, str, len); + f->Ptr += len; } + + } } -// +// Write formatted + static void Writef(LPSAVESTREAM f, const char* frm, ...) { @@ -1426,7 +1633,8 @@ void Writef(LPSAVESTREAM f, const char* frm, ...) va_list args; va_start(args, frm); - vsprintf(Buffer, frm, args); + vsnprintf(Buffer, 4095, frm, args); + Buffer[4095] = 0; WriteStr(f, Buffer); va_end(args); @@ -1450,7 +1658,7 @@ void WriteHeader(LPIT8 it8, LPSAVESTREAM fp) for (Pt = p ->Value; *Pt; Pt++) { - Writef(fp, "%c", *Pt); + Writef(fp, "%c", *Pt); if (*Pt == '\n') { WriteStr(fp, "# "); @@ -1462,7 +1670,7 @@ void WriteHeader(LPIT8 it8, LPSAVESTREAM fp) } - if (!IsAvailableOnList(it8-> ValidKeywords, p->Keyword, NULL)) { + if (!IsAvailableOnList(it8-> ValidKeywords, p->Keyword, NULL, NULL)) { #ifdef STRICT_CGATS WriteStr(fp, "KEYWORD\t\""); @@ -1470,7 +1678,7 @@ void WriteHeader(LPIT8 it8, LPSAVESTREAM fp) WriteStr(fp, "\"\n"); #endif - AddAvailableProperty(it8, p->Keyword); + AddAvailableProperty(it8, p->Keyword, WRITE_UNCOOKED); } @@ -1495,6 +1703,10 @@ void WriteHeader(LPIT8 it8, LPSAVESTREAM fp) Writef(fp, "\t0x%B", atoi(p ->Value)); break; + case WRITE_PAIR: + Writef(fp, "\t\"%s,%s\"", p->Subkey, p->Value); + break; + default: SynError(it8, "Unknown write mode %d", p ->WriteAs); return; } @@ -1573,13 +1785,13 @@ void WriteData(LPSAVESTREAM fp, LPIT8 it8) // Saves whole file -BOOL LCMSEXPORT cmsIT8SaveToFile(LCMSHANDLE hIT8, const char* cFileName) +LCMSBOOL LCMSEXPORT cmsIT8SaveToFile(LCMSHANDLE hIT8, const char* cFileName) { SAVESTREAM sd; int i; LPIT8 it8 = (LPIT8) hIT8; - ZeroMemory(&sd, sizeof(SAVESTREAM)); + ZeroMemory(&sd, sizeof(SAVESTREAM)); sd.stream = fopen(cFileName, "wt"); if (!sd.stream) return FALSE; @@ -1594,31 +1806,31 @@ BOOL LCMSEXPORT cmsIT8SaveToFile(LCMSHANDLE hIT8, const char* cFileName) WriteData(&sd, it8); } - fclose(sd.stream); + fclose(sd.stream); return TRUE; } // Saves to memory -BOOL LCMSEXPORT cmsIT8SaveToMem(LCMSHANDLE hIT8, void *MemPtr, size_t* BytesNeeded) +LCMSBOOL LCMSEXPORT cmsIT8SaveToMem(LCMSHANDLE hIT8, void *MemPtr, size_t* BytesNeeded) { SAVESTREAM sd; int i; LPIT8 it8 = (LPIT8) hIT8; - ZeroMemory(&sd, sizeof(SAVESTREAM)); + ZeroMemory(&sd, sizeof(SAVESTREAM)); sd.stream = NULL; - sd.Base = (LPBYTE) MemPtr; - sd.Ptr = sd.Base; + sd.Base = (LPBYTE) MemPtr; + sd.Ptr = sd.Base; - sd.Used = 0; + sd.Used = 0; - if (sd.Base) - sd.Max = *BytesNeeded; // Write to memory? - else - sd.Max = 0; // Just counting the needed bytes + if (sd.Base) + sd.Max = *BytesNeeded; // Write to memory? + else + sd.Max = 0; // Just counting the needed bytes WriteStr(&sd, it8->SheetType); WriteStr(&sd, "\n"); @@ -1630,12 +1842,12 @@ BOOL LCMSEXPORT cmsIT8SaveToMem(LCMSHANDLE hIT8, void *MemPtr, size_t* BytesNeed WriteData(&sd, it8); } - sd.Used++; // The \0 at the very end + sd.Used++; // The \0 at the very end - if (sd.Base) - sd.Ptr = 0; + if (sd.Base) + sd.Ptr = 0; - *BytesNeeded = sd.Used; + *BytesNeeded = sd.Used; return TRUE; } @@ -1644,7 +1856,7 @@ BOOL LCMSEXPORT cmsIT8SaveToMem(LCMSHANDLE hIT8, void *MemPtr, size_t* BytesNeed // -------------------------------------------------------------- Higer level parsing static -BOOL DataFormatSection(LPIT8 it8) +LCMSBOOL DataFormatSection(LPIT8 it8) { int iField = 0; LPTABLE t = GetTable(it8); @@ -1685,16 +1897,19 @@ BOOL DataFormatSection(LPIT8 it8) static -BOOL DataSection (LPIT8 it8) +LCMSBOOL DataSection (LPIT8 it8) { int iField = 0; int iSet = 0; - char Buffer[256]; + char Buffer[MAXSTR]; LPTABLE t = GetTable(it8); InSymbol(it8); // Eats "BEGIN_DATA" CheckEOLN(it8); + if (!t->Data) + AllocateDataSet(it8); + while (it8->sy != SEND_DATA && it8->sy != SEOF) { if (iField >= t -> nSamples) { @@ -1705,7 +1920,7 @@ BOOL DataSection (LPIT8 it8) if (it8->sy != SEND_DATA && it8->sy != SEOF) { - if (!GetVal(it8, Buffer, "Sample data expected")) + if (!GetVal(it8, Buffer, 255, "Sample data expected")) return FALSE; if (!SetData(it8, iSet, iField, Buffer)) @@ -1734,10 +1949,11 @@ BOOL DataSection (LPIT8 it8) static -BOOL HeaderSection(LPIT8 it8) +LCMSBOOL HeaderSection(LPIT8 it8) { char VarName[MAXID]; char Buffer[MAXSTR]; + LPKEYVALUE Key; while (it8->sy != SEOF && it8->sy != SSYNERROR && @@ -1749,30 +1965,79 @@ BOOL HeaderSection(LPIT8 it8) case SKEYWORD: InSymbol(it8); - if (!GetVal(it8, Buffer, "Keyword expected")) return FALSE; - if (!AddAvailableProperty(it8, Buffer)) return FALSE; + if (!GetVal(it8, Buffer, MAXSTR-1, "Keyword expected")) return FALSE; + if (!AddAvailableProperty(it8, Buffer, WRITE_UNCOOKED)) return FALSE; + InSymbol(it8); + break; + + + case SDATA_FORMAT_ID: + InSymbol(it8); + if (!GetVal(it8, Buffer, MAXSTR-1, "Keyword expected")) return FALSE; + if (!AddAvailableSampleID(it8, Buffer)) return FALSE; InSymbol(it8); break; case SIDENT: strncpy(VarName, it8->id, MAXID-1); + VarName[MAXID-1] = 0; - if (!IsAvailableOnList(it8-> ValidKeywords, VarName, NULL)) { + if (!IsAvailableOnList(it8-> ValidKeywords, VarName, NULL, &Key)) { #ifdef STRICT_CGATS return SynError(it8, "Undefined keyword '%s'", VarName); #else - if (!AddAvailableProperty(it8, VarName)) return FALSE; + Key = AddAvailableProperty(it8, VarName, WRITE_UNCOOKED); + if (Key == NULL) return FALSE; #endif } InSymbol(it8); - if (!GetVal(it8, Buffer, "Property data expected")) return FALSE; - + if (!GetVal(it8, Buffer, MAXSTR-1, "Property data expected")) return FALSE; - AddToList(it8, &GetTable(it8)->HeaderList, VarName, Buffer, - (it8->sy == SSTRING) ? WRITE_STRINGIFY : WRITE_UNCOOKED); + if(Key->WriteAs != WRITE_PAIR) { + AddToList(it8, &GetTable(it8)->HeaderList, VarName, NULL, Buffer, + (it8->sy == SSTRING) ? WRITE_STRINGIFY : WRITE_UNCOOKED); + } + else { + const char *Subkey; + char *Nextkey; + if (it8->sy != SSTRING) + return SynError(it8, "Invalid value '%s' for property '%s'.", Buffer, VarName); + + // chop the string as a list of "subkey, value" pairs, using ';' as a separator + for(Subkey = Buffer; Subkey != NULL; Subkey = Nextkey) + { + char *Value, *temp; + + // identify token pair boundary + Nextkey = (char*) strchr(Subkey, ';'); + if(Nextkey) + *Nextkey++ = '\0'; + + // for each pair, split the subkey and the value + Value = (char*) strrchr(Subkey, ','); + if(Value == NULL) + return SynError(it8, "Invalid value for property '%s'.", VarName); + + // gobble the spaces before the coma, and the coma itself + temp = Value++; + do *temp-- = '\0'; while(temp >= Subkey && *temp == ' '); + + // gobble any space at the right + temp = Value + strlen(Value) - 1; + while(*temp == ' ') *temp-- = '\0'; + + // trim the strings from the left + Subkey += strspn(Subkey, " "); + Value += strspn(Value, " "); + + if(Subkey[0] == 0 || Value[0] == 0) + return SynError(it8, "Invalid value for property '%s'.", VarName); + AddToList(it8, &GetTable(it8)->HeaderList, VarName, Subkey, Value, WRITE_PAIR); + } + } InSymbol(it8); break; @@ -1793,22 +2058,23 @@ BOOL HeaderSection(LPIT8 it8) static -BOOL ParseIT8(LPIT8 it8) +LCMSBOOL ParseIT8(LPIT8 it8, LCMSBOOL nosheet) { - char* SheetTypePtr; + char* SheetTypePtr = it8 ->SheetType; + + if (nosheet == 0) { // First line is a very special case. while (isseparator(it8->ch)) NextCh(it8); - SheetTypePtr = it8 ->SheetType; - while (it8->ch != '\r' && it8 ->ch != '\n' && it8->ch != '\t' && it8 -> ch != -1) { *SheetTypePtr++= (char) it8 ->ch; NextCh(it8); } + } *SheetTypePtr = 0; InSymbol(it8); @@ -1869,6 +2135,12 @@ void CookPointers(LPIT8 it8) for (idField = 0; idField < t -> nSamples; idField++) { + if (t ->DataFormat == NULL) { + SynError(it8, "Undefined DATA_FORMAT"); + return; + + } + Fld = t->DataFormat[idField]; if (!Fld) continue; @@ -1884,6 +2156,7 @@ void CookPointers(LPIT8 it8) char Buffer[256]; strncpy(Buffer, Data, 255); + Buffer[255] = 0; if (strlen(Buffer) <= strlen(Data)) strcpy(Data, Buffer); @@ -1916,7 +2189,7 @@ void CookPointers(LPIT8 it8) LPTABLE Table = it8 ->Tab + k; LPKEYVALUE p; - if (IsAvailableOnList(Table->HeaderList, Label, &p)) { + if (IsAvailableOnList(Table->HeaderList, Label, NULL, &p)) { // Available, keep type and table char Buffer[256]; @@ -1924,7 +2197,7 @@ void CookPointers(LPIT8 it8) char *Type = p ->Value; int nTable = k; - sprintf(Buffer, "%s %d %s", Label, nTable, Type ); + snprintf(Buffer, 255, "%s %d %s", Label, nTable, Type ); SetData(it8, i, idField, Buffer); } @@ -1948,8 +2221,9 @@ void CookPointers(LPIT8 it8) // that should be something like some printable characters plus a \n static -BOOL IsMyBlock(LPBYTE Buffer, size_t n) +int IsMyBlock(LPBYTE Buffer, size_t n) { + int cols = 1, space = 0, quot = 0; size_t i; if (n < 10) return FALSE; // Too small @@ -1959,9 +2233,26 @@ BOOL IsMyBlock(LPBYTE Buffer, size_t n) for (i = 1; i < n; i++) { - if (Buffer[i] == '\n' || Buffer[i] == '\r' || Buffer[i] == '\t') return TRUE; - if (Buffer[i] < 32) return FALSE; - + switch(Buffer[i]) + { + case '\n': + case '\r': + return quot == 1 || cols > 2 ? 0 : cols; + case '\t': + case ' ': + if(!quot && !space) + space = 1; + break; + case '\"': + quot = !quot; + break; + default: + if (Buffer[i] < 32) return 0; + if (Buffer[i] > 127) return 0; + cols += space; + space = 0; + break; + } } return FALSE; @@ -1970,7 +2261,7 @@ BOOL IsMyBlock(LPBYTE Buffer, size_t n) static -BOOL IsMyFile(const char* FileName) +int IsMyFile(const char* FileName) { FILE *fp; size_t Size; @@ -1998,21 +2289,22 @@ LCMSHANDLE LCMSEXPORT cmsIT8LoadFromMem(void *Ptr, size_t len) LCMSHANDLE hIT8; LPIT8 it8; - if (!IsMyBlock((LPBYTE) Ptr, len)) return NULL; + int type = IsMyBlock((LPBYTE) Ptr, len); + if (type == 0) return NULL; hIT8 = cmsIT8Alloc(); if (!hIT8) return NULL; it8 = (LPIT8) hIT8; - it8 ->MemoryBlock = (char*) malloc(len + 1); + it8 ->MemoryBlock = (char*) _cmsMalloc(len + 1); strncpy(it8 ->MemoryBlock, (const char*) Ptr, len); it8 ->MemoryBlock[len] = 0; - strncpy(it8->FileName, "", MAX_PATH-1); + strncpy(it8->FileStack[0]->FileName, "", MAX_PATH-1); it8-> Source = it8 -> MemoryBlock; - if (!ParseIT8(it8)) { + if (!ParseIT8(it8, type-1)) { cmsIT8Free(hIT8); return FALSE; @@ -2021,7 +2313,7 @@ LCMSHANDLE LCMSEXPORT cmsIT8LoadFromMem(void *Ptr, size_t len) CookPointers(it8); it8 ->nTable = 0; - free(it8->MemoryBlock); + _cmsFree(it8->MemoryBlock); it8 -> MemoryBlock = NULL; return hIT8; @@ -2036,26 +2328,28 @@ LCMSHANDLE LCMSEXPORT cmsIT8LoadFromFile(const char* cFileName) LCMSHANDLE hIT8; LPIT8 it8; - if (!IsMyFile(cFileName)) return NULL; + int type = IsMyFile(cFileName); + if (type == 0) return NULL; hIT8 = cmsIT8Alloc(); it8 = (LPIT8) hIT8; if (!hIT8) return NULL; - it8 ->Stream[0] = fopen(cFileName, "rt"); + it8 ->FileStack[0]->Stream = fopen(cFileName, "rt"); - if (!it8 ->Stream[0]) { + if (!it8 ->FileStack[0]->Stream) { cmsIT8Free(hIT8); return NULL; } - strncpy(it8->FileName, cFileName, MAX_PATH-1); + strncpy(it8->FileStack[0]->FileName, cFileName, MAX_PATH-1); + it8->FileStack[0]->FileName[MAX_PATH-1] = 0; - if (!ParseIT8(it8)) { + if (!ParseIT8(it8, type-1)) { - fclose(it8 ->Stream[0]); + fclose(it8 ->FileStack[0]->Stream); cmsIT8Free(hIT8); return NULL; } @@ -2063,7 +2357,7 @@ LCMSHANDLE LCMSEXPORT cmsIT8LoadFromFile(const char* cFileName) CookPointers(it8); it8 ->nTable = 0; - fclose(it8 ->Stream[0]); + fclose(it8 ->FileStack[0]->Stream); return hIT8; } @@ -2078,12 +2372,12 @@ int LCMSEXPORT cmsIT8EnumDataFormat(LCMSHANDLE hIT8, char ***SampleNames) } -int LCMSEXPORT cmsIT8EnumProperties(LCMSHANDLE hIT8, char ***PropertyNames) +int LCMSEXPORT cmsIT8EnumProperties(LCMSHANDLE hIT8, const char ***PropertyNames) { LPIT8 it8 = (LPIT8) hIT8; LPKEYVALUE p; int n; - char **Props; + const char **Props; LPTABLE t = GetTable(it8); // Pass#1 - count properties @@ -2094,7 +2388,7 @@ int LCMSEXPORT cmsIT8EnumProperties(LCMSHANDLE hIT8, char ***PropertyNames) } - Props = (char **) AllocChunk(it8, sizeof(char *) * n); + Props = (const char **) AllocChunk(it8, sizeof(char *) * n); // Pass#2 - Fill pointers n = 0; @@ -2106,6 +2400,41 @@ int LCMSEXPORT cmsIT8EnumProperties(LCMSHANDLE hIT8, char ***PropertyNames) return n; } +int LCMSEXPORT cmsIT8EnumPropertyMulti(LCMSHANDLE hIT8, const char* cProp, const char ***SubpropertyNames) +{ + LPIT8 it8 = (LPIT8) hIT8; + LPKEYVALUE p, tmp; + int n; + const char **Props; + LPTABLE t = GetTable(it8); + + if(!IsAvailableOnList(t->HeaderList, cProp, NULL, &p)) { + *SubpropertyNames = 0; + return 0; + } + + // Pass#1 - count properties + + n = 0; + for (tmp = p; tmp != NULL; tmp = tmp->NextSubkey) { + if(tmp->Subkey != NULL) + n++; + } + + + Props = (const char **) AllocChunk(it8, sizeof(char *) * n); + + // Pass#2 - Fill pointers + n = 0; + for (tmp = p; tmp != NULL; tmp = tmp->NextSubkey) { + if(tmp->Subkey != NULL) + Props[n++] = p ->Subkey; + } + + *SubpropertyNames = Props; + return n; +} + static int LocatePatch(LPIT8 it8, const char* cPatch) { @@ -2201,7 +2530,7 @@ double LCMSEXPORT cmsIT8GetDataRowColDbl(LCMSHANDLE hIT8, int row, int col) } -BOOL LCMSEXPORT cmsIT8SetDataRowCol(LCMSHANDLE hIT8, int row, int col, const char* Val) +LCMSBOOL LCMSEXPORT cmsIT8SetDataRowCol(LCMSHANDLE hIT8, int row, int col, const char* Val) { LPIT8 it8 = (LPIT8) hIT8; @@ -2209,7 +2538,7 @@ BOOL LCMSEXPORT cmsIT8SetDataRowCol(LCMSHANDLE hIT8, int row, int col, const cha } -BOOL LCMSEXPORT cmsIT8SetDataRowColDbl(LCMSHANDLE hIT8, int row, int col, double Val) +LCMSBOOL LCMSEXPORT cmsIT8SetDataRowColDbl(LCMSHANDLE hIT8, int row, int col, double Val) { LPIT8 it8 = (LPIT8) hIT8; char Buff[256]; @@ -2260,7 +2589,7 @@ double LCMSEXPORT cmsIT8GetDataDbl(LCMSHANDLE it8, const char* cPatch, const cha -BOOL LCMSEXPORT cmsIT8SetData(LCMSHANDLE hIT8, const char* cPatch, +LCMSBOOL LCMSEXPORT cmsIT8SetData(LCMSHANDLE hIT8, const char* cPatch, const char* cSample, const char *Val) { @@ -2305,18 +2634,19 @@ BOOL LCMSEXPORT cmsIT8SetData(LCMSHANDLE hIT8, const char* cPatch, } -BOOL LCMSEXPORT cmsIT8SetDataDbl(LCMSHANDLE hIT8, const char* cPatch, +LCMSBOOL LCMSEXPORT cmsIT8SetDataDbl(LCMSHANDLE hIT8, const char* cPatch, const char* cSample, double Val) { LPIT8 it8 = (LPIT8) hIT8; char Buff[256]; - sprintf(Buff, it8->DoubleFormatter, Val); + snprintf(Buff, 255, it8->DoubleFormatter, Val); return cmsIT8SetData(hIT8, cPatch, cSample, Buff); } +// Buffer should get MAXSTR at least const char* LCMSEXPORT cmsIT8GetPatchName(LCMSHANDLE hIT8, int nPatch, char* buffer) { @@ -2327,10 +2657,16 @@ const char* LCMSEXPORT cmsIT8GetPatchName(LCMSHANDLE hIT8, int nPatch, char* buf if (!Data) return NULL; if (!buffer) return Data; - strcpy(buffer, Data); + strncpy(buffer, Data, MAXSTR-1); + buffer[MAXSTR-1] = 0; return buffer; } +int LCMSEXPORT cmsIT8GetPatchByName(LCMSHANDLE hIT8, const char *cPatch) +{ + return LocatePatch((LPIT8)hIT8, cPatch); +} + int LCMSEXPORT cmsIT8TableCount(LCMSHANDLE hIT8) { LPIT8 it8 = (LPIT8) hIT8; @@ -2356,7 +2692,7 @@ int LCMSEXPORT cmsIT8SetTableByLabel(LCMSHANDLE hIT8, const char* cSet, const ch cLabelFld = cmsIT8GetData(hIT8, cSet, cField); if (!cLabelFld) return -1; - if (sscanf(cLabelFld, "%s %d %s", Label, &nTable, Type) != 3) + if (sscanf(cLabelFld, "%255s %d %255s", Label, &nTable, Type) != 3) return -1; if (ExpectedType != NULL && *ExpectedType == 0) @@ -2371,6 +2707,19 @@ int LCMSEXPORT cmsIT8SetTableByLabel(LCMSHANDLE hIT8, const char* cSet, const ch } +LCMSBOOL LCMSEXPORT cmsIT8SetIndexColumn(LCMSHANDLE hIT8, const char* cSample) +{ + LPIT8 it8 = (LPIT8) hIT8; + + int pos = LocateSample(it8, cSample); + if(pos == -1) + return FALSE; + + it8->Tab[it8->nTable].SampleID = pos; + return TRUE; +} + + void LCMSEXPORT cmsIT8DefineDblFormat(LCMSHANDLE hIT8, const char* Formatter) { LPIT8 it8 = (LPIT8) hIT8; @@ -2380,3 +2729,4 @@ void LCMSEXPORT cmsIT8DefineDblFormat(LCMSHANDLE hIT8, const char* Formatter) else strcpy(it8->DoubleFormatter, Formatter); } + diff --git a/src/share/native/sun/java2d/cmm/lcms/cmscnvrt.c b/src/share/native/sun/java2d/cmm/lcms/cmscnvrt.c index 81579bc4f112057b08432c62fa5c0abca02d0055..4d56b3ef465108e96d54a12fe7ccae3def638a8e 100644 --- a/src/share/native/sun/java2d/cmm/lcms/cmscnvrt.c +++ b/src/share/native/sun/java2d/cmm/lcms/cmscnvrt.c @@ -29,7 +29,7 @@ // // // Little cms -// Copyright (C) 1998-2006 Marti Maria +// Copyright (C) 1998-2007 Marti Maria // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the "Software"), @@ -256,7 +256,7 @@ void ComputeBlackPointCompensationFactors(LPcmsCIEXYZ BlackPointIn, // Return TRUE if both m and of are empy -- "m" being identity and "of" being 0 static -BOOL IdentityParameters(LPWMAT3 m, LPWVEC3 of) +LCMSBOOL IdentityParameters(LPWMAT3 m, LPWVEC3 of) { WVEC3 wv0; @@ -661,3 +661,6 @@ int cmsChooseCnvrt(int Absolute, return rc; } + + + diff --git a/src/share/native/sun/java2d/cmm/lcms/cmserr.c b/src/share/native/sun/java2d/cmm/lcms/cmserr.c index 016d0c4c669b4fc926b9353e0a035ed811f671c2..a8947d4aee95d0394a12714123a918871658350a 100644 --- a/src/share/native/sun/java2d/cmm/lcms/cmserr.c +++ b/src/share/native/sun/java2d/cmm/lcms/cmserr.c @@ -29,7 +29,7 @@ // // // Little cms -// Copyright (C) 1998-2006 Marti Maria +// Copyright (C) 1998-2007 Marti Maria // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the "Software"), @@ -57,6 +57,7 @@ // errors. void cdecl cmsSignalError(int ErrorCode, const char *ErrorText, ...); + int LCMSEXPORT cmsErrorAction(int lAbort); void LCMSEXPORT cmsSetErrorHandler(cmsErrorHandlerFunction Fn); @@ -96,7 +97,7 @@ void cmsSignalError(int ErrorCode, const char *ErrorText, ...) char Buffer[1024]; - vsprintf(Buffer, ErrorText, args); + vsnprintf(Buffer, 1023, ErrorText, args); va_end(args); if (UserErrorHandler(ErrorCode, Buffer)) { @@ -118,8 +119,8 @@ void cmsSignalError(int ErrorCode, const char *ErrorText, ...) char Buffer1[1024]; char Buffer2[256]; - sprintf(Buffer1, "Error #%x; ", ErrorCode); - vsprintf(Buffer2, ErrorText, args); + snprintf(Buffer1, 767, "Error #%x; ", ErrorCode); + vsnprintf(Buffer2, 255, ErrorText, args); strcat(Buffer1, Buffer2); MessageBox(NULL, Buffer1, "Little cms", MB_OK|MB_ICONSTOP|MB_TASKMODAL); diff --git a/src/share/native/sun/java2d/cmm/lcms/cmsgamma.c b/src/share/native/sun/java2d/cmm/lcms/cmsgamma.c index 1b223c6134281de181a032ddbd17401797166233..7d134389dff5c847b806951a836e9d0b5b3e7f33 100644 --- a/src/share/native/sun/java2d/cmm/lcms/cmsgamma.c +++ b/src/share/native/sun/java2d/cmm/lcms/cmsgamma.c @@ -29,7 +29,7 @@ // // // Little cms -// Copyright (C) 1998-2006 Marti Maria +// Copyright (C) 1998-2007 Marti Maria // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the "Software"), @@ -63,9 +63,9 @@ LPGAMMATABLE LCMSEXPORT cmsReverseGamma(int nResultSamples, LPGAMMATABLE InGamma LPGAMMATABLE LCMSEXPORT cmsBuildParametricGamma(int nEntries, int Type, double Params[]); LPGAMMATABLE LCMSEXPORT cmsJoinGamma(LPGAMMATABLE InGamma, LPGAMMATABLE OutGamma); LPGAMMATABLE LCMSEXPORT cmsJoinGammaEx(LPGAMMATABLE InGamma, LPGAMMATABLE OutGamma, int nPoints); -BOOL LCMSEXPORT cmsSmoothGamma(LPGAMMATABLE Tab, double lambda); +LCMSBOOL LCMSEXPORT cmsSmoothGamma(LPGAMMATABLE Tab, double lambda); -BOOL cdecl _cmsSmoothEndpoints(LPWORD Table, int nPoints); +LCMSBOOL cdecl _cmsSmoothEndpoints(LPWORD Table, int nPoints); // Sampled curves @@ -74,7 +74,7 @@ LPSAMPLEDCURVE cdecl cmsAllocSampledCurve(int nItems); void cdecl cmsFreeSampledCurve(LPSAMPLEDCURVE p); void cdecl cmsEndpointsOfSampledCurve(LPSAMPLEDCURVE p, double* Min, double* Max); void cdecl cmsClampSampledCurve(LPSAMPLEDCURVE p, double Min, double Max); -BOOL cdecl cmsSmoothSampledCurve(LPSAMPLEDCURVE Tab, double SmoothingLambda); +LCMSBOOL cdecl cmsSmoothSampledCurve(LPSAMPLEDCURVE Tab, double SmoothingLambda); void cdecl cmsRescaleSampledCurve(LPSAMPLEDCURVE p, double Min, double Max, int nPoints); LPSAMPLEDCURVE cdecl cmsJoinSampledCurves(LPSAMPLEDCURVE X, LPSAMPLEDCURVE Y, int nResultingPoints); @@ -84,7 +84,6 @@ double LCMSEXPORT cmsEstimateGammaEx(LPWORD GammaTable, int nEntries, double The // ---------------------------------------------------------------------------------------- -// #define DEBUG 1 #define MAX_KNOTS 4096 typedef float vec[MAX_KNOTS+1]; @@ -144,14 +143,14 @@ LPGAMMATABLE LCMSEXPORT cmsAllocGamma(int nEntries) LPGAMMATABLE p; size_t size; - if (nEntries > 65530) { - cmsSignalError(LCMS_ERRC_WARNING, "Couldn't create gammatable of more than 65530 entries; 65530 assumed"); - nEntries = 65530; + if (nEntries > 65530 || nEntries <= 0) { + cmsSignalError(LCMS_ERRC_ABORTED, "Couldn't create gammatable of more than 65530 entries"); + return NULL; } size = sizeof(GAMMATABLE) + (sizeof(WORD) * (nEntries-1)); - p = (LPGAMMATABLE) malloc(size); + p = (LPGAMMATABLE) _cmsMalloc(size); if (!p) return NULL; ZeroMemory(p, size); @@ -164,7 +163,7 @@ LPGAMMATABLE LCMSEXPORT cmsAllocGamma(int nEntries) void LCMSEXPORT cmsFreeGamma(LPGAMMATABLE Gamma) { - if (Gamma) free(Gamma); + if (Gamma) _cmsFree(Gamma); } @@ -278,6 +277,15 @@ LPGAMMATABLE LCMSEXPORT cmsReverseGamma(int nResultSamples, LPGAMMATABLE InGamma LPWORD InPtr; LPGAMMATABLE p; + // Try to reverse it analytically whatever possible + if (InGamma -> Seed.Type > 0 && InGamma -> Seed.Type <= 5 && + _cmsCrc32OfGammaTable(InGamma) == InGamma -> Seed.Crc32) { + + return cmsBuildParametricGamma(nResultSamples, -(InGamma -> Seed.Type), InGamma ->Seed.Params); + } + + + // Nope, reverse the table p = cmsAllocGamma(nResultSamples); if (!p) return NULL; @@ -528,7 +536,7 @@ void smooth2(vec w, vec y, vec z, float lambda, int m) // Smooths a curve sampled at regular intervals -BOOL LCMSEXPORT cmsSmoothGamma(LPGAMMATABLE Tab, double lambda) +LCMSBOOL LCMSEXPORT cmsSmoothGamma(LPGAMMATABLE Tab, double lambda) { vec w, y, z; @@ -640,13 +648,13 @@ LPSAMPLEDCURVE cmsAllocSampledCurve(int nItems) { LPSAMPLEDCURVE pOut; - pOut = (LPSAMPLEDCURVE) malloc(sizeof(SAMPLEDCURVE)); + pOut = (LPSAMPLEDCURVE) _cmsMalloc(sizeof(SAMPLEDCURVE)); if (pOut == NULL) return NULL; - if((pOut->Values = (double *) malloc(nItems * sizeof(double))) == NULL) + if((pOut->Values = (double *) _cmsMalloc(nItems * sizeof(double))) == NULL) { - free(pOut); + _cmsFree(pOut); return NULL; } @@ -659,8 +667,8 @@ LPSAMPLEDCURVE cmsAllocSampledCurve(int nItems) void cmsFreeSampledCurve(LPSAMPLEDCURVE p) { - free((LPVOID) p -> Values); - free((LPVOID) p); + _cmsFree((LPVOID) p -> Values); + _cmsFree((LPVOID) p); } @@ -731,7 +739,7 @@ void cmsClampSampledCurve(LPSAMPLEDCURVE p, double Min, double Max) // Smooths a curve sampled at regular intervals -BOOL cmsSmoothSampledCurve(LPSAMPLEDCURVE Tab, double lambda) +LCMSBOOL cmsSmoothSampledCurve(LPSAMPLEDCURVE Tab, double lambda) { vec w, y, z; int i, nItems; @@ -915,14 +923,11 @@ LPSAMPLEDCURVE cmsConvertGammaToSampledCurve(LPGAMMATABLE Gamma, int nPoints) // Smooth endpoints (used in Black/White compensation) -BOOL _cmsSmoothEndpoints(LPWORD Table, int nEntries) +LCMSBOOL _cmsSmoothEndpoints(LPWORD Table, int nEntries) { vec w, y, z; int i, Zeros, Poles; -#ifdef DEBUG - ASAVE(Table, nEntries, "nonsmt.txt"); -#endif if (cmsIsLinear(Table, nEntries)) return FALSE; // Nothing to do diff --git a/src/share/native/sun/java2d/cmm/lcms/cmsgmt.c b/src/share/native/sun/java2d/cmm/lcms/cmsgmt.c index 071cb4e477401ba83e17815049b554dc5bd211cf..90e9181dcdb11ecf34954a22cf60eed1af7ee15d 100644 --- a/src/share/native/sun/java2d/cmm/lcms/cmsgmt.c +++ b/src/share/native/sun/java2d/cmm/lcms/cmsgmt.c @@ -29,7 +29,7 @@ // // // Little cms -// Copyright (C) 1998-2006 Marti Maria +// Copyright (C) 1998-2007 Marti Maria // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the "Software"), @@ -66,7 +66,7 @@ to use highlights, then it will be lost. */ -BOOL _cmsEndPointsBySpace(icColorSpaceSignature Space, WORD **White, WORD **Black, +LCMSBOOL _cmsEndPointsBySpace(icColorSpaceSignature Space, WORD **White, WORD **Black, int *nOutputs) { // Only most common spaces @@ -376,7 +376,6 @@ double LCMSEXPORT cmsCIE2000DeltaE(LPcmsCIELab Lab1, LPcmsCIELab Lab2, double bs = Lab2 ->b; double Cs = sqrt( Sqr(as) + Sqr(bs) ); - double G = 0.5 * ( 1 - sqrt(pow((C + Cs) / 2 , 7.0) / (pow((C + Cs) / 2, 7.0) + pow(25.0, 7.0) ) )); double a_p = (1 + G ) * a1; @@ -390,15 +389,21 @@ double LCMSEXPORT cmsCIE2000DeltaE(LPcmsCIELab Lab1, LPcmsCIELab Lab2, double C_ps = sqrt(Sqr(a_ps) + Sqr(b_ps)); double h_ps = atan2deg(a_ps, b_ps); + double meanC_p =(C_p + C_ps) / 2; + double hps_plus_hp = h_ps + h_p; + double hps_minus_hp = h_ps - h_p; - double meanC_p =(C_p + C_ps) / 2; + double meanh_p = fabs(hps_minus_hp) <= 180.000001 ? (hps_plus_hp)/2 : + (hps_plus_hp) < 360 ? (hps_plus_hp + 360)/2 : + (hps_plus_hp - 360)/2; - double meanh_p = fabs(h_ps-h_p) <= 180 ? (h_ps + h_p)/2 : (h_ps+h_p-360)/2; + double delta_h = (hps_minus_hp) <= -180.000001 ? (hps_minus_hp + 360) : + (hps_minus_hp) > 180 ? (hps_minus_hp - 360) : + (hps_minus_hp); + double delta_L = (Ls - L1); + double delta_C = (C_ps - C_p ); - double delta_h = fabs(h_p - h_ps) <= 180 ? fabs(h_p - h_ps) : 360 - fabs(h_p - h_ps); - double delta_L = fabs(L1 - Ls); - double delta_C = fabs(C_p - C_ps); double delta_H =2 * sqrt(C_ps*C_p) * sin(RADIANES(delta_h) / 2); @@ -1065,7 +1070,7 @@ void SlopeLimiting(WORD Table[], int nEntries) // Check for monotonicity. static -BOOL IsMonotonic(LPGAMMATABLE t) +LCMSBOOL IsMonotonic(LPGAMMATABLE t) { int n = t -> nEntries; int i, last; @@ -1088,7 +1093,7 @@ BOOL IsMonotonic(LPGAMMATABLE t) // Check for endpoints static -BOOL HasProperEndpoints(LPGAMMATABLE t) +LCMSBOOL HasProperEndpoints(LPGAMMATABLE t) { if (t ->GammaTable[0] != 0) return FALSE; if (t ->GammaTable[t ->nEntries-1] != 0xFFFF) return FALSE; @@ -1109,7 +1114,7 @@ void _cmsComputePrelinearizationTablesFromXFORM(cmsHTRANSFORM h[], int nTransfor unsigned int t, i, v; int j; WORD In[MAXCHANNELS], Out[MAXCHANNELS]; - BOOL lIsSuitable; + LCMSBOOL lIsSuitable; _LPcmsTRANSFORM InputXForm = (_LPcmsTRANSFORM) h[0]; _LPcmsTRANSFORM OutputXForm = (_LPcmsTRANSFORM) h[nTransforms-1]; @@ -1126,10 +1131,10 @@ void _cmsComputePrelinearizationTablesFromXFORM(cmsHTRANSFORM h[], int nTransfor } - // Do nothing on all but RGB to RGB transforms + // Do nothing on all but Gray/RGB to Gray/RGB transforms - if ((InputXForm ->EntryColorSpace != icSigRgbData) || - (OutputXForm->ExitColorSpace != icSigRgbData)) return; + if (((InputXForm ->EntryColorSpace != icSigRgbData) && (InputXForm ->EntryColorSpace != icSigGrayData)) || + ((OutputXForm->ExitColorSpace != icSigRgbData) && (OutputXForm->ExitColorSpace != icSigGrayData))) return; for (t = 0; t < Grid -> InputChan; t++) @@ -1169,10 +1174,13 @@ void _cmsComputePrelinearizationTablesFromXFORM(cmsHTRANSFORM h[], int nTransfor if (!HasProperEndpoints(Trans[t])) lIsSuitable = FALSE; + /* // Exclude if transfer function is not smooth enough // to be modelled as a gamma function, or the gamma is reversed + if (cmsEstimateGamma(Trans[t]) < 1.0) lIsSuitable = FALSE; + */ } diff --git a/src/share/native/sun/java2d/cmm/lcms/cmsintrp.c b/src/share/native/sun/java2d/cmm/lcms/cmsintrp.c index 059f23d0104e0f4f8fbfe85a5bf3a20dd39360df..43432f37e9b8fecf2a74c5ad6497608388af5846 100644 --- a/src/share/native/sun/java2d/cmm/lcms/cmsintrp.c +++ b/src/share/native/sun/java2d/cmm/lcms/cmsintrp.c @@ -29,7 +29,7 @@ // // // Little cms -// Copyright (C) 1998-2006 Marti Maria +// Copyright (C) 1998-2007 Marti Maria // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the "Software"), @@ -282,7 +282,7 @@ void Eval8Inputs(WORD StageABC[], WORD StageLMN[], WORD LutTable[], LPL16PARAMS // Fills optimization parameters void cmsCalcCLUT16ParamsEx(int nSamples, int InputChan, int OutputChan, - BOOL lUseTetrahedral, LPL16PARAMS p) + LCMSBOOL lUseTetrahedral, LPL16PARAMS p) { int clutPoints; @@ -579,7 +579,7 @@ WORD cmsReverseLinearInterpLUT16(WORD Value, WORD LutTable[], LPL16PARAMS p) // Identify if value fall downto 0 or FFFF zone if (Value == 0) return 0; - if (Value == 0xFFFF) return 0xFFFF; + // if (Value == 0xFFFF) return 0xFFFF; // else restrict to valid zone @@ -631,7 +631,7 @@ WORD cmsReverseLinearInterpLUT16(WORD Value, WORD LutTable[], LPL16PARAMS p) a = (y1 - y0) / (x1 - x0); b = y0 - a * x0; - if (a == 0) return (WORD) x; + if (fabs(a) < 0.01) return (WORD) x; f = ((Value - b) / a); @@ -763,7 +763,7 @@ void cmsTrilinearInterp16(WORD Input[], WORD Output[], X0 = p -> opta3 * x0; X1 = X0 + (Input[0] == 0xFFFFU ? 0 : p->opta3); - Y0 = p -> opta2 * y0; + Y0 = p -> opta2 * y0; Y1 = Y0 + (Input[1] == 0xFFFFU ? 0 : p->opta2); Z0 = p -> opta1 * z0; @@ -942,7 +942,7 @@ void cmsTetrahedralInterp16(WORD Input[], X0 = p -> opta3 * x0; X1 = X0 + (Input[0] == 0xFFFFU ? 0 : p->opta3); - Y0 = p -> opta2 * y0; + Y0 = p -> opta2 * y0; Y1 = Y0 + (Input[1] == 0xFFFFU ? 0 : p->opta2); Z0 = p -> opta1 * z0; @@ -1009,11 +1009,11 @@ void cmsTetrahedralInterp16(WORD Input[], Rest = c1 * rx + c2 * ry + c3 * rz; - // There is a lot of math hidden in this expression. The rest is in fixed domain - // and the result in 0..ffff domain. So the complete expression should be - // ROUND_FIXED_TO_INT(ToFixedDomain(Rest)) But that can be optimized as (Rest + 0x7FFF) / 0xFFFF + // There is a lot of math hidden in this expression. The rest is in fixed domain + // and the result in 0..ffff domain. So the complete expression should be + // ROUND_FIXED_TO_INT(ToFixedDomain(Rest)) But that can be optimized as (Rest + 0x7FFF) / 0xFFFF - Output[OutChan] = (WORD) (c0 + ((Rest + 0x7FFF) / 0xFFFF)); + Output[OutChan] = (WORD) (c0 + ((Rest + 0x7FFF) / 0xFFFF)); } @@ -1131,3 +1131,4 @@ void cmsTetrahedralInterp8(WORD Input[], } #undef DENS + diff --git a/src/share/native/sun/java2d/cmm/lcms/cmsio0.c b/src/share/native/sun/java2d/cmm/lcms/cmsio0.c index 1556fa5e8afb463e665495dc5ea98da5f9fdf349..7f8cbf06779161876aeac26f1d1f486cceda97f8 100644 --- a/src/share/native/sun/java2d/cmm/lcms/cmsio0.c +++ b/src/share/native/sun/java2d/cmm/lcms/cmsio0.c @@ -29,7 +29,7 @@ // // // Little cms -// Copyright (C) 1998-2006 Marti Maria +// Copyright (C) 1998-2007 Marti Maria // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the "Software"), @@ -62,7 +62,7 @@ typedef struct { LPBYTE Block; // Points to allocated memory size_t Size; // Size of allocated memory - int Pointer; // Points to current location + size_t Pointer; // Points to current location int FreeBlockOnClose; // As title } FILEMEM; @@ -70,18 +70,19 @@ typedef struct { static LPVOID MemoryOpen(LPBYTE Block, size_t Size, char Mode) { - FILEMEM* fm = (FILEMEM*) malloc(sizeof(FILEMEM)); + FILEMEM* fm = (FILEMEM*) _cmsMalloc(sizeof(FILEMEM)); + if (fm == NULL) return NULL; + ZeroMemory(fm, sizeof(FILEMEM)); if (Mode == 'r') { - fm ->Block = (LPBYTE) malloc(Size); + fm ->Block = (LPBYTE) _cmsMalloc(Size); if (fm ->Block == NULL) { - free(fm); + _cmsFree(fm); return NULL; } - CopyMemory(fm->Block, Block, Size); fm ->FreeBlockOnClose = TRUE; } @@ -103,13 +104,27 @@ size_t MemoryRead(LPVOID buffer, size_t size, size_t count, struct _lcms_iccprof FILEMEM* ResData = (FILEMEM*) Icc ->stream; LPBYTE Ptr; size_t len = size * count; + size_t extent = ResData -> Pointer + len; + + if (len == 0) { + return 0; + } + if (len / size != count) { + cmsSignalError(LCMS_ERRC_ABORTED, "Read from memory error. Integer overflow with count / size."); + return 0; + } - if (ResData -> Pointer + len > ResData -> Size){ + if (extent < len || extent < ResData -> Pointer) { + cmsSignalError(LCMS_ERRC_ABORTED, "Read from memory error. Integer overflow with len."); + return 0; + } - len = (ResData -> Size - ResData -> Pointer); - cmsSignalError(LCMS_ERRC_WARNING, "Read from memory error. Got %d bytes, block should be of %d bytes", len * size, count * size); + if (ResData -> Pointer + len > ResData -> Size) { + len = (ResData -> Size - ResData -> Pointer); + cmsSignalError(LCMS_ERRC_ABORTED, "Read from memory error. Got %d bytes, block should be of %d bytes", len * size, count * size); + return 0; } Ptr = ResData -> Block; @@ -123,7 +138,7 @@ size_t MemoryRead(LPVOID buffer, size_t size, size_t count, struct _lcms_iccprof // SEEK_CUR is assumed static -BOOL MemorySeek(struct _lcms_iccprofile_struct* Icc, size_t offset) +LCMSBOOL MemorySeek(struct _lcms_iccprofile_struct* Icc, size_t offset) { FILEMEM* ResData = (FILEMEM*) Icc ->stream; @@ -147,18 +162,19 @@ size_t MemoryTell(struct _lcms_iccprofile_struct* Icc) } -// Writes data to memory, also keeps used space for further reference +// Writes data to memory, also keeps used space for further reference. NO CHECK IS PERFORMED static -BOOL MemoryWrite(struct _lcms_iccprofile_struct* Icc, size_t size, void *Ptr) +LCMSBOOL MemoryWrite(struct _lcms_iccprofile_struct* Icc, size_t size, void *Ptr) { FILEMEM* ResData = (FILEMEM*) Icc ->stream; if (size == 0) return TRUE; if (ResData != NULL) - CopyMemory(ResData ->Block + Icc ->UsedSpace, Ptr, size); + CopyMemory(ResData ->Block + ResData ->Pointer, Ptr, size); + ResData->Pointer += size; Icc->UsedSpace += size; return TRUE; @@ -166,15 +182,37 @@ BOOL MemoryWrite(struct _lcms_iccprofile_struct* Icc, size_t size, void *Ptr) static -BOOL MemoryClose(struct _lcms_iccprofile_struct* Icc) +LCMSBOOL MemoryGrow(struct _lcms_iccprofile_struct* Icc, size_t size) +{ + FILEMEM* ResData = (FILEMEM*) Icc->stream; + + void* newBlock = NULL; + + /* Follow same policies as functions in lcms.h */ + if (ResData->Size + size < 0) return NULL; + if (ResData->Size + size > ((size_t)1024*1024*500)) return NULL; + + newBlock = realloc(ResData->Block, ResData->Size + size); + + if (!newBlock) { + return FALSE; + } + ResData->Block = newBlock; + ResData->Size += size; + return TRUE; +} + + +static +LCMSBOOL MemoryClose(struct _lcms_iccprofile_struct* Icc) { FILEMEM* ResData = (FILEMEM*) Icc ->stream; if (ResData ->FreeBlockOnClose) { - if (ResData ->Block) free(ResData ->Block); + if (ResData ->Block) _cmsFree(ResData ->Block); } - free(ResData); + _cmsFree(ResData); return 0; } @@ -192,7 +230,7 @@ size_t FileRead(void *buffer, size_t size, size_t count, struct _lcms_iccprofile { size_t nReaded = fread(buffer, size, count, (FILE*) Icc->stream); if (nReaded != count) { - cmsSignalError(LCMS_ERRC_WARNING, "Read error. Got %d bytes, block should be of %d bytes", nReaded * size, count * size); + cmsSignalError(LCMS_ERRC_ABORTED, "Read error. Got %d bytes, block should be of %d bytes", nReaded * size, count * size); return 0; } @@ -201,7 +239,7 @@ size_t FileRead(void *buffer, size_t size, size_t count, struct _lcms_iccprofile static -BOOL FileSeek(struct _lcms_iccprofile_struct* Icc, size_t offset) +LCMSBOOL FileSeek(struct _lcms_iccprofile_struct* Icc, size_t offset) { if (fseek((FILE*) Icc ->stream, (long) offset, SEEK_SET) != 0) { @@ -223,7 +261,7 @@ size_t FileTell(struct _lcms_iccprofile_struct* Icc) static -BOOL FileWrite(struct _lcms_iccprofile_struct* Icc, size_t size, LPVOID Ptr) +LCMSBOOL FileWrite(struct _lcms_iccprofile_struct* Icc, size_t size, LPVOID Ptr) { if (size == 0) return TRUE; @@ -239,7 +277,14 @@ BOOL FileWrite(struct _lcms_iccprofile_struct* Icc, size_t size, LPVOID Ptr) static -BOOL FileClose(struct _lcms_iccprofile_struct* Icc) +LCMSBOOL FileGrow(struct _lcms_iccprofile_struct* Icc, size_t size) +{ + return TRUE; +} + + +static +LCMSBOOL FileClose(struct _lcms_iccprofile_struct* Icc) { return fclose((FILE*) Icc ->stream); } @@ -252,7 +297,7 @@ BOOL FileClose(struct _lcms_iccprofile_struct* Icc) cmsHPROFILE _cmsCreateProfilePlaceholder(void) { - LPLCMSICCPROFILE Icc = (LPLCMSICCPROFILE) malloc(sizeof(LCMSICCPROFILE)); + LPLCMSICCPROFILE Icc = (LPLCMSICCPROFILE) _cmsMalloc(sizeof(LCMSICCPROFILE)); if (Icc == NULL) return NULL; // Empty values @@ -290,7 +335,7 @@ icTagSignature LCMSEXPORT cmsGetTagSignature(cmsHPROFILE hProfile, icInt32Number // Search for a specific tag in tag dictionary // Returns position or -1 if tag not found -icInt32Number _cmsSearchTag(LPLCMSICCPROFILE Profile, icTagSignature sig, BOOL lSignalError) +icInt32Number _cmsSearchTag(LPLCMSICCPROFILE Profile, icTagSignature sig, LCMSBOOL lSignalError) { icInt32Number i; @@ -311,7 +356,7 @@ icInt32Number _cmsSearchTag(LPLCMSICCPROFILE Profile, icTagSignature sig, BOOL l // Check existance -BOOL LCMSEXPORT cmsIsTag(cmsHPROFILE hProfile, icTagSignature sig) +LCMSBOOL LCMSEXPORT cmsIsTag(cmsHPROFILE hProfile, icTagSignature sig) { LPLCMSICCPROFILE Icc = (LPLCMSICCPROFILE) (LPSTR) hProfile; return _cmsSearchTag(Icc, sig, FALSE) >= 0; @@ -330,7 +375,7 @@ LPVOID _cmsInitTag(LPLCMSICCPROFILE Icc, icTagSignature sig, size_t size, const if (i >=0) { - if (Icc -> TagPtrs[i]) free(Icc -> TagPtrs[i]); + if (Icc -> TagPtrs[i]) _cmsFree(Icc -> TagPtrs[i]); } else { @@ -341,11 +386,14 @@ LPVOID _cmsInitTag(LPLCMSICCPROFILE Icc, icTagSignature sig, size_t size, const cmsSignalError(LCMS_ERRC_ABORTED, "Too many tags (%d)", MAX_TABLE_TAG); Icc ->TagCount = MAX_TABLE_TAG-1; + return NULL; } } - Ptr = malloc(size); + Ptr = _cmsMalloc(size); + if (Ptr == NULL) return NULL; + CopyMemory(Ptr, Init, size); Icc ->TagNames[i] = sig; @@ -376,12 +424,15 @@ LPLCMSICCPROFILE _cmsCreateProfileFromFilePlaceholder(const char* FileName) if (NewIcc == NULL) return NULL; strncpy(NewIcc -> PhysicalFile, FileName, MAX_PATH-1); + NewIcc -> PhysicalFile[MAX_PATH-1] = 0; + NewIcc ->stream = ICCfile; NewIcc ->Read = FileRead; NewIcc ->Seek = FileSeek; NewIcc ->Tell = FileTell; NewIcc ->Close = FileClose; + NewIcc ->Grow = FileGrow; NewIcc ->Write = NULL; NewIcc ->IsWrite = FALSE; @@ -419,7 +470,8 @@ LPLCMSICCPROFILE _cmsCreateProfileFromMemPlaceholder(LPVOID MemPtr, DWORD dwSize NewIcc ->Seek = MemorySeek; NewIcc ->Tell = MemoryTell; NewIcc ->Close = MemoryClose; - NewIcc ->Write = NULL; + NewIcc ->Grow = MemoryGrow; + NewIcc ->Write = MemoryWrite; NewIcc ->IsWrite = FALSE; @@ -476,7 +528,7 @@ void _cmsSetSaveToMemory(LPLCMSICCPROFILE Icc, LPVOID MemPtr, size_t dwSize) -BOOL LCMSEXPORT cmsTakeMediaWhitePoint(LPcmsCIEXYZ Dest, cmsHPROFILE hProfile) +LCMSBOOL LCMSEXPORT cmsTakeMediaWhitePoint(LPcmsCIEXYZ Dest, cmsHPROFILE hProfile) { LPLCMSICCPROFILE Icc = (LPLCMSICCPROFILE) hProfile; *Dest = Icc -> MediaWhitePoint; @@ -484,14 +536,14 @@ BOOL LCMSEXPORT cmsTakeMediaWhitePoint(LPcmsCIEXYZ Dest, cmsHPROFILE hProfile) } -BOOL LCMSEXPORT cmsTakeMediaBlackPoint(LPcmsCIEXYZ Dest, cmsHPROFILE hProfile) +LCMSBOOL LCMSEXPORT cmsTakeMediaBlackPoint(LPcmsCIEXYZ Dest, cmsHPROFILE hProfile) { LPLCMSICCPROFILE Icc = (LPLCMSICCPROFILE) hProfile; *Dest = Icc -> MediaBlackPoint; return TRUE; } -BOOL LCMSEXPORT cmsTakeIluminant(LPcmsCIEXYZ Dest, cmsHPROFILE hProfile) +LCMSBOOL LCMSEXPORT cmsTakeIluminant(LPcmsCIEXYZ Dest, cmsHPROFILE hProfile) { LPLCMSICCPROFILE Icc = (LPLCMSICCPROFILE) hProfile; *Dest = Icc -> Illuminant; @@ -549,7 +601,7 @@ void LCMSEXPORT cmsSetProfileID(cmsHPROFILE hProfile, LPBYTE ProfileID) } -BOOL LCMSEXPORT cmsTakeCreationDateTime(struct tm *Dest, cmsHPROFILE hProfile) +LCMSBOOL LCMSEXPORT cmsTakeCreationDateTime(struct tm *Dest, cmsHPROFILE hProfile) { LPLCMSICCPROFILE Icc = (LPLCMSICCPROFILE) (LPSTR) hProfile; CopyMemory(Dest, &Icc ->Created, sizeof(struct tm)); @@ -570,23 +622,18 @@ void LCMSEXPORT cmsSetPCS(cmsHPROFILE hProfile, icColorSpaceSignature pcs) Icc -> PCS = pcs; } - - icColorSpaceSignature LCMSEXPORT cmsGetColorSpace(cmsHPROFILE hProfile) { LPLCMSICCPROFILE Icc = (LPLCMSICCPROFILE) hProfile; return Icc -> ColorSpace; } - - void LCMSEXPORT cmsSetColorSpace(cmsHPROFILE hProfile, icColorSpaceSignature sig) { LPLCMSICCPROFILE Icc = (LPLCMSICCPROFILE) hProfile; Icc -> ColorSpace = sig; } - icProfileClassSignature LCMSEXPORT cmsGetDeviceClass(cmsHPROFILE hProfile) { LPLCMSICCPROFILE Icc = (LPLCMSICCPROFILE) hProfile; @@ -599,7 +646,6 @@ DWORD LCMSEXPORT cmsGetProfileICCversion(cmsHPROFILE hProfile) return (DWORD) Icc -> Version; } - void LCMSEXPORT cmsSetProfileICCversion(cmsHPROFILE hProfile, DWORD Version) { LPLCMSICCPROFILE Icc = (LPLCMSICCPROFILE) hProfile; @@ -638,7 +684,7 @@ LPVOID DupBlock(LPLCMSICCPROFILE Icc, LPVOID Block, size_t size) // This is tricky, since LUT structs does have pointers -BOOL LCMSEXPORT _cmsAddLUTTag(cmsHPROFILE hProfile, icTagSignature sig, const void* lut) +LCMSBOOL LCMSEXPORT _cmsAddLUTTag(cmsHPROFILE hProfile, icTagSignature sig, const void* lut) { LPLCMSICCPROFILE Icc = (LPLCMSICCPROFILE) (LPSTR) hProfile; LPLUT Orig, Stored; @@ -666,7 +712,7 @@ BOOL LCMSEXPORT _cmsAddLUTTag(cmsHPROFILE hProfile, icTagSignature sig, const vo } -BOOL LCMSEXPORT _cmsAddXYZTag(cmsHPROFILE hProfile, icTagSignature sig, const cmsCIEXYZ* XYZ) +LCMSBOOL LCMSEXPORT _cmsAddXYZTag(cmsHPROFILE hProfile, icTagSignature sig, const cmsCIEXYZ* XYZ) { LPLCMSICCPROFILE Icc = (LPLCMSICCPROFILE) (LPSTR) hProfile; @@ -675,7 +721,7 @@ BOOL LCMSEXPORT _cmsAddXYZTag(cmsHPROFILE hProfile, icTagSignature sig, const cm } -BOOL LCMSEXPORT _cmsAddTextTag(cmsHPROFILE hProfile, icTagSignature sig, const char* Text) +LCMSBOOL LCMSEXPORT _cmsAddTextTag(cmsHPROFILE hProfile, icTagSignature sig, const char* Text) { LPLCMSICCPROFILE Icc = (LPLCMSICCPROFILE) (LPSTR) hProfile; @@ -683,7 +729,7 @@ BOOL LCMSEXPORT _cmsAddTextTag(cmsHPROFILE hProfile, icTagSignature sig, const c return TRUE; } -BOOL LCMSEXPORT _cmsAddGammaTag(cmsHPROFILE hProfile, icTagSignature sig, LPGAMMATABLE TransferFunction) +LCMSBOOL LCMSEXPORT _cmsAddGammaTag(cmsHPROFILE hProfile, icTagSignature sig, LPGAMMATABLE TransferFunction) { LPLCMSICCPROFILE Icc = (LPLCMSICCPROFILE) (LPSTR) hProfile; @@ -692,7 +738,7 @@ BOOL LCMSEXPORT _cmsAddGammaTag(cmsHPROFILE hProfile, icTagSignature sig, LPGAMM } -BOOL LCMSEXPORT _cmsAddChromaticityTag(cmsHPROFILE hProfile, icTagSignature sig, LPcmsCIExyYTRIPLE Chrm) +LCMSBOOL LCMSEXPORT _cmsAddChromaticityTag(cmsHPROFILE hProfile, icTagSignature sig, LPcmsCIExyYTRIPLE Chrm) { LPLCMSICCPROFILE Icc = (LPLCMSICCPROFILE) (LPSTR) hProfile; @@ -701,7 +747,7 @@ BOOL LCMSEXPORT _cmsAddChromaticityTag(cmsHPROFILE hProfile, icTagSignature sig, } -BOOL LCMSEXPORT _cmsAddSequenceDescriptionTag(cmsHPROFILE hProfile, icTagSignature sig, LPcmsSEQ pseq) +LCMSBOOL LCMSEXPORT _cmsAddSequenceDescriptionTag(cmsHPROFILE hProfile, icTagSignature sig, LPcmsSEQ pseq) { LPLCMSICCPROFILE Icc = (LPLCMSICCPROFILE) (LPSTR) hProfile; @@ -711,28 +757,40 @@ BOOL LCMSEXPORT _cmsAddSequenceDescriptionTag(cmsHPROFILE hProfile, icTagSignatu } -BOOL LCMSEXPORT _cmsAddNamedColorTag(cmsHPROFILE hProfile, icTagSignature sig, LPcmsNAMEDCOLORLIST nc) +LCMSBOOL LCMSEXPORT _cmsAddNamedColorTag(cmsHPROFILE hProfile, icTagSignature sig, LPcmsNAMEDCOLORLIST nc) { LPLCMSICCPROFILE Icc = (LPLCMSICCPROFILE) (LPSTR) hProfile; _cmsInitTag(Icc, sig, sizeof(cmsNAMEDCOLORLIST) + (nc ->nColors - 1) * sizeof(cmsNAMEDCOLOR), nc); - return FALSE; + return TRUE; } -BOOL LCMSEXPORT _cmsAddDateTimeTag(cmsHPROFILE hProfile, icTagSignature sig, struct tm *DateTime) +LCMSBOOL LCMSEXPORT _cmsAddDateTimeTag(cmsHPROFILE hProfile, icTagSignature sig, struct tm *DateTime) { LPLCMSICCPROFILE Icc = (LPLCMSICCPROFILE) (LPSTR) hProfile; _cmsInitTag(Icc, sig, sizeof(struct tm), DateTime); - return FALSE; + return TRUE; } -BOOL LCMSEXPORT _cmsAddColorantTableTag(cmsHPROFILE hProfile, icTagSignature sig, LPcmsNAMEDCOLORLIST nc) +LCMSBOOL LCMSEXPORT _cmsAddColorantTableTag(cmsHPROFILE hProfile, icTagSignature sig, LPcmsNAMEDCOLORLIST nc) { LPLCMSICCPROFILE Icc = (LPLCMSICCPROFILE) (LPSTR) hProfile; _cmsInitTag(Icc, sig, sizeof(cmsNAMEDCOLORLIST) + (nc ->nColors - 1) * sizeof(cmsNAMEDCOLOR), nc); - return FALSE; + return TRUE; +} + + +LCMSBOOL LCMSEXPORT _cmsAddChromaticAdaptationTag(cmsHPROFILE hProfile, icTagSignature sig, const cmsCIEXYZ* mat) +{ + LPLCMSICCPROFILE Icc = (LPLCMSICCPROFILE) (LPSTR) hProfile; + + _cmsInitTag(Icc, sig, 3*sizeof(cmsCIEXYZ), mat); + return TRUE; + } + + diff --git a/src/share/native/sun/java2d/cmm/lcms/cmsio1.c b/src/share/native/sun/java2d/cmm/lcms/cmsio1.c index 77419f809f38149e7ef93c4cfde160d020315156..16aec6c53627834a209627a0bbc5de7bbbee116a 100644 --- a/src/share/native/sun/java2d/cmm/lcms/cmsio1.c +++ b/src/share/native/sun/java2d/cmm/lcms/cmsio1.c @@ -29,7 +29,7 @@ // // // Little cms -// Copyright (C) 1998-2006 Marti Maria +// Copyright (C) 1998-2007 Marti Maria // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the "Software"), @@ -149,6 +149,7 @@ void AdjustEndianessArray16(LPWORD p, size_t num_words) #endif + // Transports to properly encoded values - note that icc profiles does use // big endian notation. @@ -216,7 +217,8 @@ icTagTypeSignature ReadBase(LPLCMSICCPROFILE Icc) { icTagBase Base; - Icc -> Read(&Base, sizeof(icTagBase), 1, Icc); + if (Icc -> Read(&Base, sizeof(icTagBase), 1, Icc) != 1) + return (icTagTypeSignature) 0; AdjustEndianess32((LPBYTE) &Base.sig); return Base.sig; @@ -288,13 +290,15 @@ void EvalCHRM(LPcmsCIEXYZ Dest, LPMAT3 Chrm, LPcmsCIEXYZ Src) // Read profile header and validate it static -LPLCMSICCPROFILE ReadHeader(LPLCMSICCPROFILE Icc, BOOL lIsFromMemory) +LPLCMSICCPROFILE ReadHeader(LPLCMSICCPROFILE Icc, LCMSBOOL lIsFromMemory) { icTag Tag; icHeader Header; icInt32Number TagCount, i; + icUInt32Number extent; - Icc -> Read(&Header, sizeof(icHeader), 1, Icc); + if (Icc -> Read(&Header, sizeof(icHeader), 1, Icc) != 1) + goto ErrorCleanup; // Convert endian @@ -306,14 +310,13 @@ LPLCMSICCPROFILE ReadHeader(LPLCMSICCPROFILE Icc, BOOL lIsFromMemory) AdjustEndianess32((LPBYTE) &Header.pcs); AdjustEndianess32((LPBYTE) &Header.magic); AdjustEndianess32((LPBYTE) &Header.flags); - AdjustEndianess32((LPBYTE) &Header.attributes[0]); + AdjustEndianess32((LPBYTE) &Header.attributes[0]); AdjustEndianess32((LPBYTE) &Header.renderingIntent); // Validate it if (Header.magic != icMagicNumber) goto ErrorCleanup; - if (Icc ->Read(&TagCount, sizeof(icInt32Number), 1, Icc) != 1) goto ErrorCleanup; @@ -324,7 +327,7 @@ LPLCMSICCPROFILE ReadHeader(LPLCMSICCPROFILE Icc, BOOL lIsFromMemory) Icc -> PCS = Header.pcs; Icc -> RenderingIntent = (icRenderingIntent) Header.renderingIntent; Icc -> flags = Header.flags; - Icc -> attributes = Header.attributes[0]; + Icc -> attributes = Header.attributes[0]; Icc -> Illuminant.X = Convert15Fixed16(Header.illuminant.X); Icc -> Illuminant.Y = Convert15Fixed16(Header.illuminant.Y); Icc -> Illuminant.Z = Convert15Fixed16(Header.illuminant.Z); @@ -348,7 +351,7 @@ LPLCMSICCPROFILE ReadHeader(LPLCMSICCPROFILE Icc, BOOL lIsFromMemory) // Read tag directory - if (TagCount > MAX_TABLE_TAG) { + if (TagCount > MAX_TABLE_TAG || TagCount < 0) { cmsSignalError(LCMS_ERRC_ABORTED, "Too many tags (%d)", TagCount); goto ErrorCleanup; @@ -357,12 +360,18 @@ LPLCMSICCPROFILE ReadHeader(LPLCMSICCPROFILE Icc, BOOL lIsFromMemory) Icc -> TagCount = TagCount; for (i=0; i < TagCount; i++) { - Icc ->Read(&Tag, sizeof(icTag), 1, Icc); + if (Icc ->Read(&Tag, sizeof(icTag), 1, Icc) != 1) + goto ErrorCleanup; AdjustEndianess32((LPBYTE) &Tag.offset); AdjustEndianess32((LPBYTE) &Tag.size); AdjustEndianess32((LPBYTE) &Tag.sig); // Signature + // Perform some sanity check. Offset + size should fall inside file. + extent = Tag.offset + Tag.size; + if (extent > Header.size || extent < Tag.offset) + goto ErrorCleanup; + Icc -> TagNames[i] = Tag.sig; Icc -> TagOffsets[i] = Tag.offset; Icc -> TagSizes[i] = Tag.size; @@ -381,13 +390,10 @@ ErrorCleanup: cmsSignalError(LCMS_ERRC_ABORTED, "Corrupted profile: '%s'", Icc->PhysicalFile); - free(Icc); + _cmsFree(Icc); return NULL; } - - - static unsigned int uipow(unsigned int a, unsigned int b) { unsigned int rv = 1; @@ -497,7 +503,7 @@ void FixLUT8bothSides(LPLUT Lut, size_t nTabSize) // The infamous LUT 8 static -void ReadLUT8(LPLCMSICCPROFILE Icc, LPLUT NewLUT, icTagSignature sig) +LCMSBOOL ReadLUT8(LPLCMSICCPROFILE Icc, LPLUT NewLUT, icTagSignature sig) { icLut8 LUT8; LPBYTE Temp; @@ -506,7 +512,7 @@ void ReadLUT8(LPLCMSICCPROFILE Icc, LPLUT NewLUT, icTagSignature sig) unsigned int AllLinear; LPWORD PtrW; - Icc ->Read(&LUT8, sizeof(icLut8) - SIZEOF_UINT8_ALIGNED, 1, Icc); + if (Icc ->Read(&LUT8, sizeof(icLut8) - SIZEOF_UINT8_ALIGNED, 1, Icc) != 1) return FALSE; NewLUT -> wFlags = LUT_HASTL1|LUT_HASTL2|LUT_HAS3DGRID; NewLUT -> cLutPoints = LUT8.clutPoints; @@ -515,6 +521,10 @@ void ReadLUT8(LPLCMSICCPROFILE Icc, LPLUT NewLUT, icTagSignature sig) NewLUT -> InputEntries = 256; NewLUT -> OutputEntries = 256; + // Do some checking + if (!_cmsValidateLUT(NewLUT)) { + return FALSE; + } AdjustEndianess32((LPBYTE) &LUT8.e00); AdjustEndianess32((LPBYTE) &LUT8.e01); @@ -550,13 +560,24 @@ void ReadLUT8(LPLCMSICCPROFILE Icc, LPLUT NewLUT, icTagSignature sig) // Copy input tables - Temp = (LPBYTE) malloc(256); + Temp = (LPBYTE) _cmsMalloc(256); + if (Temp == NULL) return FALSE; + AllLinear = 0; for (i=0; i < NewLUT -> InputChan; i++) { - PtrW = (LPWORD) malloc(sizeof(WORD) * 256); + PtrW = (LPWORD) _cmsMalloc(sizeof(WORD) * 256); + if (PtrW == NULL) { + _cmsFree(Temp); + return FALSE; + } + NewLUT -> L1[i] = PtrW; - Icc ->Read(Temp, 1, 256, Icc); + if (Icc ->Read(Temp, 1, 256, Icc) != 256) { + _cmsFree(Temp); + return FALSE; + } + for (j=0; j < 256; j++) PtrW[j] = TO16_TAB(Temp[j]); AllLinear += cmsIsLinear(NewLUT -> L1[i], NewLUT -> InputEntries); @@ -569,7 +590,7 @@ void ReadLUT8(LPLCMSICCPROFILE Icc, LPLUT NewLUT, icTagSignature sig) NewLUT -> wFlags &= ~LUT_HASTL1; } - free(Temp); + _cmsFree(Temp); // Copy 3D CLUT @@ -578,9 +599,20 @@ void ReadLUT8(LPLCMSICCPROFILE Icc, LPLUT NewLUT, icTagSignature sig) if (nTabSize > 0) { - PtrW = (LPWORD) malloc(sizeof(WORD) * nTabSize); - Temp = (LPBYTE) malloc(nTabSize); - Icc ->Read(Temp, 1, nTabSize, Icc); + PtrW = (LPWORD) _cmsCalloc(sizeof(WORD), nTabSize); + if (PtrW == NULL) return FALSE; + + Temp = (LPBYTE) _cmsMalloc(nTabSize); + if (Temp == NULL) { + _cmsFree(PtrW); + return FALSE; + } + + if (Icc ->Read(Temp, 1, nTabSize, Icc) != nTabSize) { + _cmsFree(Temp); + _cmsFree(PtrW); + return FALSE; + } NewLUT -> T = PtrW; NewLUT -> Tsize = (unsigned int) (nTabSize * sizeof(WORD)); @@ -589,25 +621,37 @@ void ReadLUT8(LPLCMSICCPROFILE Icc, LPLUT NewLUT, icTagSignature sig) *PtrW++ = TO16_TAB(Temp[i]); } - free(Temp); + _cmsFree(Temp); } else { NewLUT ->T = NULL; NewLUT ->Tsize = 0; - NewLUT -> wFlags &= ~LUT_HAS3DGRID; + NewLUT ->wFlags &= ~LUT_HAS3DGRID; } - // Copy output tables - Temp = (LPBYTE) malloc(256); + Temp = (LPBYTE) _cmsMalloc(256); + if (Temp == NULL) { + return FALSE; + } + AllLinear = 0; for (i=0; i < NewLUT -> OutputChan; i++) { - PtrW = (LPWORD) malloc(sizeof(WORD) * 256); + PtrW = (LPWORD) _cmsMalloc(sizeof(WORD) * 256); + if (PtrW == NULL) { + _cmsFree(Temp); + return FALSE; + } + NewLUT -> L2[i] = PtrW; - Icc ->Read(Temp, 1, 256, Icc); + if (Icc ->Read(Temp, 1, 256, Icc) != 256) { + _cmsFree(Temp); + return FALSE; + } + for (j=0; j < 256; j++) PtrW[j] = TO16_TAB(Temp[j]); AllLinear += cmsIsLinear(NewLUT -> L2[i], 256); @@ -621,7 +665,7 @@ void ReadLUT8(LPLCMSICCPROFILE Icc, LPLUT NewLUT, icTagSignature sig) } - free(Temp); + _cmsFree(Temp); cmsCalcL16Params(NewLUT -> InputEntries, &NewLUT -> In16params); cmsCalcL16Params(NewLUT -> OutputEntries, &NewLUT -> Out16params); @@ -646,6 +690,15 @@ void ReadLUT8(LPLCMSICCPROFILE Icc, LPLUT NewLUT, icTagSignature sig) // some profiles does claim to do that. Poor lcms will try // to detect such condition and fix up "on the fly". + switch (sig) { + + case icSigBToA0Tag: + case icSigBToA1Tag: + case icSigBToA2Tag: + case icSigGamutTag: + case icSigPreview0Tag: + case icSigPreview1Tag: + case icSigPreview2Tag: { LPWORD WhiteLab, ExpectedWhite; WORD WhiteFixed[MAXCHANNELS], WhiteUnfixed[MAXCHANNELS]; @@ -685,9 +738,13 @@ void ReadLUT8(LPLCMSICCPROFILE Icc, LPLUT NewLUT, icTagSignature sig) } } + break; + default:; + } } + return TRUE; } @@ -696,7 +753,7 @@ void ReadLUT8(LPLCMSICCPROFILE Icc, LPLUT NewLUT, icTagSignature sig) // Case LUT 16 static -void ReadLUT16(LPLCMSICCPROFILE Icc, LPLUT NewLUT) +LCMSBOOL ReadLUT16(LPLCMSICCPROFILE Icc, LPLUT NewLUT) { icLut16 LUT16; size_t nTabSize; @@ -705,7 +762,8 @@ void ReadLUT16(LPLCMSICCPROFILE Icc, LPLUT NewLUT) LPWORD PtrW; - Icc ->Read(&LUT16, sizeof(icLut16)- SIZEOF_UINT16_ALIGNED, 1, Icc); + if (Icc ->Read(&LUT16, sizeof(icLut16)- SIZEOF_UINT16_ALIGNED, 1, Icc) != 1) + return FALSE; NewLUT -> wFlags = LUT_HASTL1 | LUT_HASTL2 | LUT_HAS3DGRID; NewLUT -> cLutPoints = LUT16.clutPoints; @@ -718,6 +776,9 @@ void ReadLUT16(LPLCMSICCPROFILE Icc, LPLUT NewLUT) NewLUT -> InputEntries = LUT16.inputEnt; NewLUT -> OutputEntries = LUT16.outputEnt; + if (!_cmsValidateLUT(NewLUT)) { + return FALSE; + } // Matrix handling @@ -754,9 +815,14 @@ void ReadLUT16(LPLCMSICCPROFILE Icc, LPLUT NewLUT) AllLinear = 0; for (i=0; i < NewLUT -> InputChan; i++) { - PtrW = (LPWORD) malloc(sizeof(WORD) * NewLUT -> InputEntries); + PtrW = (LPWORD) _cmsMalloc(sizeof(WORD) * NewLUT -> InputEntries); + if (PtrW == NULL) return FALSE; + NewLUT -> L1[i] = PtrW; - Icc ->Read(PtrW, sizeof(WORD), NewLUT -> InputEntries, Icc); + if (Icc ->Read(PtrW, sizeof(WORD), NewLUT -> InputEntries, Icc) != NewLUT -> InputEntries) { + return FALSE; + } + AdjustEndianessArray16(PtrW, NewLUT -> InputEntries); AllLinear += cmsIsLinear(NewLUT -> L1[i], NewLUT -> InputEntries); } @@ -775,12 +841,17 @@ void ReadLUT16(LPLCMSICCPROFILE Icc, LPLUT NewLUT) NewLUT->InputChan)); if (nTabSize > 0) { - PtrW = (LPWORD) malloc(sizeof(WORD) * nTabSize); + PtrW = (LPWORD) _cmsCalloc(sizeof(WORD), nTabSize); + if (PtrW == NULL) + return FALSE; NewLUT -> T = PtrW; NewLUT -> Tsize = (unsigned int) (nTabSize * sizeof(WORD)); - Icc -> Read(PtrW, sizeof(WORD), nTabSize, Icc); + if (Icc -> Read(PtrW, sizeof(WORD), nTabSize, Icc) != nTabSize) { + return FALSE; + } + AdjustEndianessArray16(NewLUT -> T, nTabSize); } else { @@ -794,9 +865,16 @@ void ReadLUT16(LPLCMSICCPROFILE Icc, LPLUT NewLUT) AllLinear = 0; for (i=0; i < NewLUT -> OutputChan; i++) { - PtrW = (LPWORD) malloc(sizeof(WORD) * NewLUT -> OutputEntries); + PtrW = (LPWORD) _cmsMalloc(sizeof(WORD) * NewLUT -> OutputEntries); + if (PtrW == NULL) { + return FALSE; + } + NewLUT -> L2[i] = PtrW; - Icc ->Read(PtrW, sizeof(WORD), NewLUT -> OutputEntries, Icc); + if (Icc ->Read(PtrW, sizeof(WORD), NewLUT -> OutputEntries, Icc) != NewLUT -> OutputEntries) { + return FALSE; + } + AdjustEndianessArray16(PtrW, NewLUT -> OutputEntries); AllLinear += cmsIsLinear(NewLUT -> L2[i], NewLUT -> OutputEntries); } @@ -814,6 +892,8 @@ void ReadLUT16(LPLCMSICCPROFILE Icc, LPLUT NewLUT) cmsCalcCLUT16Params(NewLUT -> cLutPoints, NewLUT -> InputChan, NewLUT -> OutputChan, &NewLUT -> CLut16params); + + return TRUE; } @@ -830,17 +910,15 @@ LPGAMMATABLE ReadCurve(LPLCMSICCPROFILE Icc) BaseType = ReadBase(Icc); - switch (BaseType) { - case 0x9478ee00L: // Monaco 2 profiler is BROKEN! + case ((icTagTypeSignature) 0x9478ee00): // Monaco 2 profiler is BROKEN! case icSigCurveType: - Icc ->Read(&Count, sizeof(icUInt32Number), 1, Icc); + if (Icc ->Read(&Count, sizeof(icUInt32Number), 1, Icc) != 1) return NULL; AdjustEndianess32((LPBYTE) &Count); - switch (Count) { case 0: // Linear. @@ -855,7 +933,7 @@ LPGAMMATABLE ReadCurve(LPLCMSICCPROFILE Icc) { WORD SingleGammaFixed; - Icc ->Read(&SingleGammaFixed, sizeof(WORD), 1, Icc); + if (Icc ->Read(&SingleGammaFixed, sizeof(WORD), 1, Icc) != 1) return NULL; AdjustEndianess16((LPBYTE) &SingleGammaFixed); return cmsBuildGamma(4096, Convert8Fixed8(SingleGammaFixed)); } @@ -865,10 +943,9 @@ LPGAMMATABLE ReadCurve(LPLCMSICCPROFILE Icc) NewGamma = cmsAllocGamma(Count); if (!NewGamma) return NULL; - Icc ->Read(NewGamma -> GammaTable, sizeof(WORD), Count, Icc); - + if (Icc ->Read(NewGamma -> GammaTable, sizeof(WORD), Count, Icc) != Count) + return NULL; AdjustEndianessArray16(NewGamma -> GammaTable, Count); - return NewGamma; } } @@ -885,11 +962,11 @@ LPGAMMATABLE ReadCurve(LPLCMSICCPROFILE Icc) icUInt16Number Type; int i; - Icc -> Read(&Type, sizeof(icUInt16Number), 1, Icc); - Icc -> Read(&Reserved, sizeof(icUInt16Number), 1, Icc); + if (Icc -> Read(&Type, sizeof(icUInt16Number), 1, Icc) != 1) return NULL; + if (Icc -> Read(&Reserved, sizeof(icUInt16Number), 1, Icc) != 1) return NULL; AdjustEndianess16((LPBYTE) &Type); - if (Type > 5) { + if (Type > 4) { cmsSignalError(LCMS_ERRC_ABORTED, "Unknown parametric curve type '%d' found.", Type); return NULL; @@ -900,7 +977,7 @@ LPGAMMATABLE ReadCurve(LPLCMSICCPROFILE Icc) for (i=0; i < n; i++) { Num = 0; - Icc -> Read(&Num, sizeof(icS15Fixed16Number), 1, Icc); + if (Icc -> Read(&Num, sizeof(icS15Fixed16Number), 1, Icc) != 1) return NULL; Params[i] = Convert15Fixed16(Num); } @@ -938,7 +1015,7 @@ LPGAMMATABLE ReadCurveReversed(LPLCMSICCPROFILE Icc) case 0x9478ee00L: // Monaco 2 profiler is BROKEN! case icSigCurveType: - Icc -> Read(&Count, sizeof(icUInt32Number), 1, Icc); + if (Icc -> Read(&Count, sizeof(icUInt32Number), 1, Icc) != 1) return NULL; AdjustEndianess32((LPBYTE) &Count); @@ -948,6 +1025,7 @@ LPGAMMATABLE ReadCurveReversed(LPLCMSICCPROFILE Icc) NewGamma = cmsAllocGamma(2); if (!NewGamma) return NULL; + NewGamma -> GammaTable[0] = 0; NewGamma -> GammaTable[1] = 0xFFFF; return NewGamma; @@ -955,7 +1033,7 @@ LPGAMMATABLE ReadCurveReversed(LPLCMSICCPROFILE Icc) case 1: { WORD SingleGammaFixed; - Icc -> Read(&SingleGammaFixed, sizeof(WORD), 1, Icc); + if (Icc -> Read(&SingleGammaFixed, sizeof(WORD), 1, Icc) != 1) return NULL; AdjustEndianess16((LPBYTE) &SingleGammaFixed); return cmsBuildGamma(4096, 1./Convert8Fixed8(SingleGammaFixed)); } @@ -965,7 +1043,8 @@ LPGAMMATABLE ReadCurveReversed(LPLCMSICCPROFILE Icc) NewGamma = cmsAllocGamma(Count); if (!NewGamma) return NULL; - Icc -> Read(NewGamma -> GammaTable, sizeof(WORD), Count, Icc); + if (Icc -> Read(NewGamma -> GammaTable, sizeof(WORD), Count, Icc) != Count) + return NULL; AdjustEndianessArray16(NewGamma -> GammaTable, Count); @@ -992,11 +1071,11 @@ LPGAMMATABLE ReadCurveReversed(LPLCMSICCPROFILE Icc) int i; - Icc -> Read(&Type, sizeof(icUInt16Number), 1, Icc); - Icc -> Read(&Reserved, sizeof(icUInt16Number), 1, Icc); + if (Icc -> Read(&Type, sizeof(icUInt16Number), 1, Icc) != 1) return NULL; + if (Icc -> Read(&Reserved, sizeof(icUInt16Number), 1, Icc) != 1) return NULL; AdjustEndianess16((LPBYTE) &Type); - if (Type > 5) { + if (Type > 4) { cmsSignalError(LCMS_ERRC_ABORTED, "Unknown parametric curve type '%d' found.", Type); return NULL; @@ -1006,7 +1085,7 @@ LPGAMMATABLE ReadCurveReversed(LPLCMSICCPROFILE Icc) n = ParamsByType[Type]; for (i=0; i < n; i++) { - Icc -> Read(&Num, sizeof(icS15Fixed16Number), 1, Icc); + if (Icc -> Read(&Num, sizeof(icS15Fixed16Number), 1, Icc) != 1) return NULL; Params[i] = Convert15Fixed16(Num); } @@ -1028,7 +1107,7 @@ LPGAMMATABLE ReadCurveReversed(LPLCMSICCPROFILE Icc) // V4 stuff. Read matrix for LutAtoB and LutBtoA static -BOOL ReadMatrixOffset(LPLCMSICCPROFILE Icc, size_t Offset, LPLUT NewLUT, DWORD dwFlags) +LCMSBOOL ReadMatrixOffset(LPLCMSICCPROFILE Icc, size_t Offset, LPLUT NewLUT, DWORD dwFlags) { icS15Fixed16Number All[12]; @@ -1038,7 +1117,8 @@ BOOL ReadMatrixOffset(LPLCMSICCPROFILE Icc, size_t Offset, LPLUT NewLUT, DWORD d if (Icc -> Seek(Icc, Offset)) return FALSE; - Icc ->Read(All, sizeof(icS15Fixed16Number), 12, Icc); + if (Icc ->Read(All, sizeof(icS15Fixed16Number), 12, Icc) != 12) + return FALSE; for (i=0; i < 12; i++) AdjustEndianess32((LPBYTE) &All[i]); @@ -1067,17 +1147,26 @@ BOOL ReadMatrixOffset(LPLCMSICCPROFILE Icc, size_t Offset, LPLUT NewLUT, DWORD d // V4 stuff. Read CLUT part for LutAtoB and LutBtoA static -BOOL ReadCLUT(LPLCMSICCPROFILE Icc, size_t Offset, LPLUT NewLUT) +LCMSBOOL ReadCLUT(LPLCMSICCPROFILE Icc, size_t Offset, LPLUT NewLUT) { - + unsigned int j; icCLutStruct CLUT; if (Icc -> Seek(Icc, Offset)) return FALSE; - Icc ->Read(&CLUT, sizeof(icCLutStruct), 1, Icc); + if (Icc ->Read(&CLUT, sizeof(icCLutStruct), 1, Icc) != 1) return FALSE; - cmsAlloc3DGrid(NewLUT, CLUT.gridPoints[0], NewLUT ->InputChan, - NewLUT ->OutputChan); + for (j=1; j < NewLUT ->InputChan; j++) { + if (CLUT.gridPoints[0] != CLUT.gridPoints[j]) { + cmsSignalError(LCMS_ERRC_ABORTED, "CLUT with different granulatity is currently unsupported."); + return FALSE; + } + + + } + + if (cmsAlloc3DGrid(NewLUT, CLUT.gridPoints[0], NewLUT ->InputChan, + NewLUT ->OutputChan) == NULL) return FALSE; // Precission can be 1 or 2 bytes @@ -1087,7 +1176,7 @@ BOOL ReadCLUT(LPLCMSICCPROFILE Icc, size_t Offset, LPLUT NewLUT) unsigned int i; for (i=0; i < NewLUT->Tsize / sizeof(WORD); i++) { - Icc ->Read(&v, sizeof(BYTE), 1, Icc); + if (Icc ->Read(&v, sizeof(BYTE), 1, Icc) != 1) return FALSE; NewLUT->T[i] = TO16_TAB(v); } @@ -1095,10 +1184,10 @@ BOOL ReadCLUT(LPLCMSICCPROFILE Icc, size_t Offset, LPLUT NewLUT) else if (CLUT.prec == 2) { - Icc ->Read(NewLUT ->T, sizeof(WORD), - NewLUT->Tsize / sizeof(WORD), Icc); + size_t n = NewLUT->Tsize / sizeof(WORD); - AdjustEndianessArray16(NewLUT ->T, NewLUT->Tsize / sizeof(WORD)); + if (Icc ->Read(NewLUT ->T, sizeof(WORD), n, Icc) != n) return FALSE; + AdjustEndianessArray16(NewLUT ->T, NewLUT->Tsize / sizeof(WORD)); } else { cmsSignalError(LCMS_ERRC_ABORTED, "Unknow precission of '%d'", CLUT.prec); @@ -1109,6 +1198,22 @@ BOOL ReadCLUT(LPLCMSICCPROFILE Icc, size_t Offset, LPLUT NewLUT) } +static +void ResampleCurves(LPGAMMATABLE Curves[], int nCurves) +{ + int i; + LPSAMPLEDCURVE sc; + + for (i=0; i < nCurves; i++) { + sc = cmsConvertGammaToSampledCurve(Curves[i], 4096); + cmsFreeGamma(Curves[i]); + Curves[i] = cmsConvertSampledCurveToGamma(sc, 0xFFFF); + cmsFreeSampledCurve(sc); + } + +} + + static void SkipAlignment(LPLCMSICCPROFILE Icc) { @@ -1121,7 +1226,7 @@ void SkipAlignment(LPLCMSICCPROFILE Icc) // Read a set of curves from specific offset static -BOOL ReadSetOfCurves(LPLCMSICCPROFILE Icc, size_t Offset, LPLUT NewLUT, int nLocation) +LCMSBOOL ReadSetOfCurves(LPLCMSICCPROFILE Icc, size_t Offset, LPLUT NewLUT, int nLocation) { LPGAMMATABLE Curves[MAXCHANNELS]; unsigned int i, nCurves; @@ -1134,20 +1239,41 @@ BOOL ReadSetOfCurves(LPLCMSICCPROFILE Icc, size_t Offset, LPLUT NewLUT, int nLoc else nCurves = NewLUT ->OutputChan; + ZeroMemory(Curves, sizeof(Curves)); for (i=0; i < nCurves; i++) { Curves[i] = ReadCurve(Icc); + if (Curves[i] == NULL) goto Error; SkipAlignment(Icc); + } + + // March-26'08: some V4 profiles may have different sampling + // rates, in this case resample all curves to maximum + for (i=1; i < nCurves; i++) { + if (Curves[i]->nEntries != Curves[0]->nEntries) { + ResampleCurves(Curves, nCurves); + break; + } } NewLUT = cmsAllocLinearTable(NewLUT, Curves, nLocation); + if (NewLUT == NULL) goto Error; for (i=0; i < nCurves; i++) cmsFreeGamma(Curves[i]); return TRUE; +Error: + + for (i=0; i < nCurves; i++) + if (Curves[i]) + cmsFreeGamma(Curves[i]); + + return FALSE; + + } // V4 stuff. LutAtoB type @@ -1160,22 +1286,28 @@ BOOL ReadSetOfCurves(LPLCMSICCPROFILE Icc, size_t Offset, LPLUT NewLUT, int nLoc // L2 = B curves static -BOOL ReadLUT_A2B(LPLCMSICCPROFILE Icc, LPLUT NewLUT, size_t BaseOffset, icTagSignature sig) +LCMSBOOL ReadLUT_A2B(LPLCMSICCPROFILE Icc, LPLUT NewLUT, size_t BaseOffset, icTagSignature sig) { icLutAtoB LUT16; - Icc ->Read(&LUT16, sizeof(icLutAtoB), 1, Icc); + if (Icc ->Read(&LUT16, sizeof(icLutAtoB), 1, Icc) != 1) return FALSE; NewLUT -> InputChan = LUT16.inputChan; NewLUT -> OutputChan = LUT16.outputChan; + // Validate the NewLUT here to avoid excessive number of channels + // (leading to stack-based buffer overflow in ReadSetOfCurves). + // Needs revalidation after table size is filled in. + if (!_cmsValidateLUT(NewLUT)) { + return FALSE; + } + AdjustEndianess32((LPBYTE) &LUT16.offsetB); AdjustEndianess32((LPBYTE) &LUT16.offsetMat); AdjustEndianess32((LPBYTE) &LUT16.offsetM); AdjustEndianess32((LPBYTE) &LUT16.offsetC); AdjustEndianess32((LPBYTE) &LUT16.offsetA); - if (LUT16.offsetB != 0) ReadSetOfCurves(Icc, BaseOffset + LUT16.offsetB, NewLUT, 2); @@ -1220,15 +1352,22 @@ BOOL ReadLUT_A2B(LPLCMSICCPROFILE Icc, LPLUT NewLUT, size_t BaseOffset, icTagSig // V4 stuff. LutBtoA type static -BOOL ReadLUT_B2A(LPLCMSICCPROFILE Icc, LPLUT NewLUT, size_t BaseOffset, icTagSignature sig) +LCMSBOOL ReadLUT_B2A(LPLCMSICCPROFILE Icc, LPLUT NewLUT, size_t BaseOffset, icTagSignature sig) { icLutBtoA LUT16; - Icc ->Read(&LUT16, sizeof(icLutBtoA), 1, Icc); + if (Icc ->Read(&LUT16, sizeof(icLutBtoA), 1, Icc) != 1) return FALSE; NewLUT -> InputChan = LUT16.inputChan; NewLUT -> OutputChan = LUT16.outputChan; + // Validate the NewLUT here to avoid excessive number of channels + // (leading to stack-based buffer overflow in ReadSetOfCurves). + // Needs revalidation after table size is filled in. + if (!_cmsValidateLUT(NewLUT)) { + return FALSE; + } + AdjustEndianess32((LPBYTE) &LUT16.offsetB); AdjustEndianess32((LPBYTE) &LUT16.offsetMat); AdjustEndianess32((LPBYTE) &LUT16.offsetM); @@ -1242,7 +1381,6 @@ BOOL ReadLUT_B2A(LPLCMSICCPROFILE Icc, LPLUT NewLUT, size_t BaseOffset, icTagSi if (LUT16.offsetMat != 0) ReadMatrixOffset(Icc, BaseOffset + LUT16.offsetMat, NewLUT, LUT_HASMATRIX3); - if (LUT16.offsetM != 0) ReadSetOfCurves(Icc, BaseOffset + LUT16.offsetM, NewLUT, 3); @@ -1294,7 +1432,7 @@ LPLUT LCMSEXPORT cmsReadICCLut(cmsHPROFILE hProfile, icTagSignature sig) // If is in memory, the LUT is already there, so throw a copy - if (!Icc -> stream) { + if (Icc -> TagPtrs[n]) { return cmsDupLUT((LPLUT) Icc ->TagPtrs[n]); } @@ -1308,8 +1446,8 @@ LPLUT LCMSEXPORT cmsReadICCLut(cmsHPROFILE hProfile, icTagSignature sig) NewLUT = cmsAllocLUT(); - if (!NewLUT) - { + if (!NewLUT) { + cmsSignalError(LCMS_ERRC_ABORTED, "cmsAllocLUT() failed"); return NULL; } @@ -1317,11 +1455,29 @@ LPLUT LCMSEXPORT cmsReadICCLut(cmsHPROFILE hProfile, icTagSignature sig) switch (BaseType) { - case icSigLut8Type: ReadLUT8(Icc, NewLUT, sig); break; - case icSigLut16Type: ReadLUT16(Icc, NewLUT); break; - - case icSiglutAtoBType: ReadLUT_A2B(Icc, NewLUT, offset, sig); break; - case icSiglutBtoAType: ReadLUT_B2A(Icc, NewLUT, offset, sig); break; + case icSigLut8Type: if (!ReadLUT8(Icc, NewLUT, sig)) { + cmsFreeLUT(NewLUT); + return NULL; + } + break; + + case icSigLut16Type: if (!ReadLUT16(Icc, NewLUT)) { + cmsFreeLUT(NewLUT); + return NULL; + } + break; + + case icSiglutAtoBType: if (!ReadLUT_A2B(Icc, NewLUT, offset, sig)) { + cmsFreeLUT(NewLUT); + return NULL; + } + break; + + case icSiglutBtoAType: if (!ReadLUT_B2A(Icc, NewLUT, offset, sig)) { + cmsFreeLUT(NewLUT); + return NULL; + } + break; default: cmsSignalError(LCMS_ERRC_ABORTED, "Bad tag signature %lx found.", BaseType); cmsFreeLUT(NewLUT); @@ -1335,16 +1491,23 @@ LPLUT LCMSEXPORT cmsReadICCLut(cmsHPROFILE hProfile, icTagSignature sig) // Sets the language & country preferences. Used only in ICC 4.0 profiles -void LCMSEXPORT cmsSetLanguage(int LanguageCode, int CountryCode) +void LCMSEXPORT cmsSetLanguage(const char LanguageCode[4], const char CountryCode[4]) { - GlobalLanguageCode = LanguageCode; - GlobalCountryCode = CountryCode; + + int LanguageCodeInt = *(int *) LanguageCode; + int CountryCodeInt = *(int *) CountryCode; + + AdjustEndianess32((LPBYTE) &LanguageCodeInt); + AdjustEndianess32((LPBYTE) &CountryCodeInt); + + GlobalLanguageCode = LanguageCodeInt; + GlobalCountryCode = CountryCodeInt; } // Some tags (e.g, 'pseq') can have text tags embedded. This function -// handles such special case. +// handles such special case. Returns -1 on error, or the number of bytes left on success. static int ReadEmbeddedTextTag(LPLCMSICCPROFILE Icc, size_t size, char* Name, size_t size_max) @@ -1353,7 +1516,6 @@ int ReadEmbeddedTextTag(LPLCMSICCPROFILE Icc, size_t size, char* Name, size_t si BaseType = ReadBase(Icc); - size -= sizeof(icTagBase); switch (BaseType) { @@ -1365,50 +1527,54 @@ int ReadEmbeddedTextTag(LPLCMSICCPROFILE Icc, size_t size, char* Name, size_t si icUInt16Number ScriptCodeCode, Dummy; icUInt8Number ScriptCodeCount; - Icc ->Read(&AsciiCount, sizeof(icUInt32Number), 1, Icc); + if (Icc ->Read(&AsciiCount, sizeof(icUInt32Number), 1, Icc) != 1) return -1; - if (size < sizeof(icUInt32Number)) return (int) size; + if (size < sizeof(icUInt32Number)) return (int) size; size -= sizeof(icUInt32Number); AdjustEndianess32((LPBYTE) &AsciiCount); Icc ->Read(Name, 1, (AsciiCount >= size_max) ? (size_max-1) : AsciiCount, Icc); - if (size < AsciiCount) return (int) size; + if (size < AsciiCount) return (int) size; size -= AsciiCount; // Skip Unicode code - Icc ->Read(&UnicodeCode, sizeof(icUInt32Number), 1, Icc); - if (size < sizeof(icUInt32Number)) return (int) size; + if (Icc ->Read(&UnicodeCode, sizeof(icUInt32Number), 1, Icc) != 1) return -1; + if (size < sizeof(icUInt32Number)) return (int) size; size -= sizeof(icUInt32Number); - Icc ->Read(&UnicodeCount, sizeof(icUInt32Number), 1, Icc); - if (size < sizeof(icUInt32Number)) return (int) size; + if (Icc ->Read(&UnicodeCount, sizeof(icUInt32Number), 1, Icc) != 1) return -1; + if (size < sizeof(icUInt32Number)) return (int) size; size -= sizeof(icUInt32Number); AdjustEndianess32((LPBYTE) &UnicodeCount); if (UnicodeCount > size) return (int) size; - for (i=0; i < UnicodeCount; i++) - Icc ->Read(&Dummy, sizeof(icUInt16Number), 1, Icc); - - size -= UnicodeCount * sizeof(icUInt16Number); + for (i=0; i < UnicodeCount; i++) { + size_t nread = Icc ->Read(&Dummy, sizeof(icUInt16Number), 1, Icc); + if (nread != 1) return (int) size; + size -= sizeof(icUInt16Number); + } // Skip ScriptCode code - Icc ->Read(&ScriptCodeCode, sizeof(icUInt16Number), 1, Icc); + if (Icc ->Read(&ScriptCodeCode, sizeof(icUInt16Number), 1, Icc) != 1) return -1; size -= sizeof(icUInt16Number); - Icc ->Read(&ScriptCodeCount, sizeof(icUInt8Number), 1, Icc); + if (Icc ->Read(&ScriptCodeCount, sizeof(icUInt8Number), 1, Icc) != 1) return -1; size -= sizeof(icUInt8Number); - if (size < 67) return (int) size; + // Should remain 67 bytes as filler - for (i=0; i < 67; i++) - Icc ->Read(&Dummy, sizeof(icUInt8Number), 1, Icc); + if (size < 67) return (int) size; - size -= 67; + for (i=0; i < 67; i++) { + size_t nread = Icc ->Read(&Dummy, sizeof(icUInt8Number), 1, Icc); + if (nread != 1) return (int) size; + size --; + } } break; @@ -1425,7 +1591,7 @@ int ReadEmbeddedTextTag(LPLCMSICCPROFILE Icc, size_t size, char* Name, size_t si size = size_max - 1; } - Icc -> Read(Name, 1, size, Icc); + if (Icc -> Read(Name, 1, size, Icc) != size) return -1; for (i=0; i < Missing; i++) Icc -> Read(&Dummy, 1, 1, Icc); @@ -1445,9 +1611,9 @@ int ReadEmbeddedTextTag(LPLCMSICCPROFILE Icc, size_t size, char* Name, size_t si wchar_t* wchar = L""; - Icc ->Read(&Count, sizeof(icUInt32Number), 1, Icc); + if (Icc ->Read(&Count, sizeof(icUInt32Number), 1, Icc) != 1) return -1; AdjustEndianess32((LPBYTE) &Count); - Icc ->Read(&RecLen, sizeof(icUInt32Number), 1, Icc); + if (Icc ->Read(&RecLen, sizeof(icUInt32Number), 1, Icc) != 1) return -1; AdjustEndianess32((LPBYTE) &RecLen); if (RecLen != 12) { @@ -1458,15 +1624,15 @@ int ReadEmbeddedTextTag(LPLCMSICCPROFILE Icc, size_t size, char* Name, size_t si for (i=0; i < Count; i++) { - Icc ->Read(&Language, sizeof(icUInt16Number), 1, Icc); + if (Icc ->Read(&Language, sizeof(icUInt16Number), 1, Icc) != 1) return -1; AdjustEndianess16((LPBYTE) &Language); - Icc ->Read(&Country, sizeof(icUInt16Number), 1, Icc); + if (Icc ->Read(&Country, sizeof(icUInt16Number), 1, Icc) != 1) return -1; AdjustEndianess16((LPBYTE) &Country); - Icc ->Read(&ThisLen, sizeof(icUInt32Number), 1, Icc); + if (Icc ->Read(&ThisLen, sizeof(icUInt32Number), 1, Icc) != 1) return -1; AdjustEndianess32((LPBYTE) &ThisLen); - Icc ->Read(&ThisOffset, sizeof(icUInt32Number), 1, Icc); + if (Icc ->Read(&ThisOffset, sizeof(icUInt32Number), 1, Icc) != 1) return -1; AdjustEndianess32((LPBYTE) &ThisOffset); if (Language == GlobalLanguageCode || Offset == 0) { @@ -1492,14 +1658,18 @@ int ReadEmbeddedTextTag(LPLCMSICCPROFILE Icc, size_t size, char* Name, size_t si for (i=0; i < Offset; i++) { char Discard; - - Icc ->Read(&Discard, 1, 1, Icc); + if (Icc ->Read(&Discard, 1, 1, Icc) != 1) return -1; } - wchar = (wchar_t*) malloc(Len+2); + + // Bound len + if (Len < 0) Len = 0; + if (Len > 20*1024) Len = 20 * 1024; + + wchar = (wchar_t*) _cmsMalloc(Len*sizeof(wchar_t)+2); if (!wchar) return -1; - Icc ->Read(wchar, 1, Len, Icc); + if (Icc ->Read(wchar, 1, Len, Icc) != Len) return -1; AdjustEndianessArray16((LPWORD) wchar, Len / 2); wchar[Len / 2] = L'\0'; @@ -1509,7 +1679,7 @@ int ReadEmbeddedTextTag(LPLCMSICCPROFILE Icc, size_t size, char* Name, size_t si Name[0] = 0; // Error } - free((void*) wchar); + _cmsFree((void*) wchar); } break; @@ -1522,8 +1692,7 @@ int ReadEmbeddedTextTag(LPLCMSICCPROFILE Icc, size_t size, char* Name, size_t si } -// Take an ASCII item. Takes at most LCMS_DESC_MAX - +// Take an ASCII item. Takes at most size_max bytes int LCMSEXPORT cmsReadICCTextEx(cmsHPROFILE hProfile, icTagSignature sig, char *Name, size_t size_max) { @@ -1535,19 +1704,27 @@ int LCMSEXPORT cmsReadICCTextEx(cmsHPROFILE hProfile, icTagSignature sig, char * if (n < 0) return -1; - if (!Icc -> stream) { + size = Icc -> TagSizes[n]; + + if (Icc -> TagPtrs[n]) { + + if (size > size_max) + size = size_max; + + CopyMemory(Name, Icc -> TagPtrs[n], size); - CopyMemory(Name, Icc -> TagPtrs[n], Icc -> TagSizes[n]); return (int) Icc -> TagSizes[n]; } offset = Icc -> TagOffsets[n]; - size = Icc -> TagSizes[n]; + if (Icc -> Seek(Icc, offset)) return -1; - return ReadEmbeddedTextTag(Icc, size, Name, size_max); + if (ReadEmbeddedTextTag(Icc, size, Name, size_max) < 0) return -1; + + return size; } // Keep compatibility with older versions @@ -1561,7 +1738,7 @@ int LCMSEXPORT cmsReadICCText(cmsHPROFILE hProfile, icTagSignature sig, char *Te // Take an XYZ item static -int ReadICCXYZ(cmsHPROFILE hProfile, icTagSignature sig, LPcmsCIEXYZ Value, BOOL lIsFatal) +int ReadICCXYZ(cmsHPROFILE hProfile, icTagSignature sig, LPcmsCIEXYZ Value, LCMSBOOL lIsFatal) { LPLCMSICCPROFILE Icc = (LPLCMSICCPROFILE) (LPSTR) hProfile; icTagTypeSignature BaseType; @@ -1573,7 +1750,7 @@ int ReadICCXYZ(cmsHPROFILE hProfile, icTagSignature sig, LPcmsCIEXYZ Value, BOOL if (n < 0) return -1; - if (!Icc -> stream) { + if (Icc -> TagPtrs[n]) { CopyMemory(Value, Icc -> TagPtrs[n], Icc -> TagSizes[n]); return (int) Icc -> TagSizes[n]; @@ -1628,7 +1805,7 @@ int ReadICCXYZArray(cmsHPROFILE hProfile, icTagSignature sig, LPMAT3 v) if (n < 0) return -1; // Not found - if (!Icc -> stream) { + if (Icc -> TagPtrs[n]) { CopyMemory(v, Icc -> TagPtrs[n], Icc -> TagSizes[n]); return (int) Icc -> TagSizes[n]; @@ -1677,7 +1854,7 @@ int ReadICCXYZArray(cmsHPROFILE hProfile, icTagSignature sig, LPMAT3 v) // Primaries are to be in xyY notation -BOOL LCMSEXPORT cmsTakeColorants(LPcmsCIEXYZTRIPLE Dest, cmsHPROFILE hProfile) +LCMSBOOL LCMSEXPORT cmsTakeColorants(LPcmsCIEXYZTRIPLE Dest, cmsHPROFILE hProfile) { if (ReadICCXYZ(hProfile, icSigRedColorantTag, &Dest -> Red, TRUE) < 0) return FALSE; if (ReadICCXYZ(hProfile, icSigGreenColorantTag, &Dest -> Green, TRUE) < 0) return FALSE; @@ -1687,7 +1864,7 @@ BOOL LCMSEXPORT cmsTakeColorants(LPcmsCIEXYZTRIPLE Dest, cmsHPROFILE hProfile) } -BOOL cmsReadICCMatrixRGB2XYZ(LPMAT3 r, cmsHPROFILE hProfile) +LCMSBOOL cmsReadICCMatrixRGB2XYZ(LPMAT3 r, cmsHPROFILE hProfile) { cmsCIEXYZTRIPLE Primaries; @@ -1704,7 +1881,7 @@ BOOL cmsReadICCMatrixRGB2XYZ(LPMAT3 r, cmsHPROFILE hProfile) // Always return a suitable matrix -BOOL cmsReadChromaticAdaptationMatrix(LPMAT3 r, cmsHPROFILE hProfile) +LCMSBOOL cmsReadChromaticAdaptationMatrix(LPMAT3 r, cmsHPROFILE hProfile) { if (ReadICCXYZArray(hProfile, icSigChromaticAdaptationTag, r) < 0) { @@ -1741,7 +1918,7 @@ LPGAMMATABLE LCMSEXPORT cmsReadICCGamma(cmsHPROFILE hProfile, icTagSignature sig if (n < 0) return NULL; - if (!Icc -> stream) { + if (Icc -> TagPtrs[n]) { return cmsDupGamma((LPGAMMATABLE) Icc -> TagPtrs[n]); } @@ -1769,7 +1946,7 @@ LPGAMMATABLE LCMSEXPORT cmsReadICCGammaReversed(cmsHPROFILE hProfile, icTagSigna if (n < 0) return NULL; - if (!Icc -> stream) { + if (Icc -> TagPtrs[n]) { return cmsReverseGamma(256, (LPGAMMATABLE) Icc -> TagPtrs[n]); } @@ -1785,7 +1962,7 @@ LPGAMMATABLE LCMSEXPORT cmsReadICCGammaReversed(cmsHPROFILE hProfile, icTagSigna // Check Named color header static -BOOL CheckHeader(LPcmsNAMEDCOLORLIST v, icNamedColor2* nc2) +LCMSBOOL CheckHeader(LPcmsNAMEDCOLORLIST v, icNamedColor2* nc2) { if (v ->Prefix[0] == 0 && v ->Suffix[0] == 0 && v ->ColorantCount == 0) return TRUE; @@ -1809,13 +1986,13 @@ int cmsReadICCnamedColorList(cmsHTRANSFORM xform, cmsHPROFILE hProfile, icTagSig if (n < 0) return 0; - if (!Icc -> stream) { + if (Icc -> TagPtrs[n]) { // This replaces actual named color list. size_t size = Icc -> TagSizes[n]; if (v ->NamedColorList) cmsFreeNamedColorList(v ->NamedColorList); - v -> NamedColorList = (LPcmsNAMEDCOLORLIST) malloc(size); + v -> NamedColorList = (LPcmsNAMEDCOLORLIST) _cmsMalloc(size); CopyMemory(v -> NamedColorList, Icc ->TagPtrs[n], size); return v ->NamedColorList->nColors; } @@ -1844,7 +2021,7 @@ int cmsReadICCnamedColorList(cmsHTRANSFORM xform, cmsHPROFILE hProfile, icTagSig icNamedColor2 nc2; unsigned int i, j; - Icc -> Read(&nc2, sizeof(icNamedColor2) - SIZEOF_UINT8_ALIGNED, 1, Icc); + if (Icc -> Read(&nc2, sizeof(icNamedColor2) - SIZEOF_UINT8_ALIGNED, 1, Icc) != 1) return 0; AdjustEndianess32((LPBYTE) &nc2.vendorFlag); AdjustEndianess32((LPBYTE) &nc2.count); AdjustEndianess32((LPBYTE) &nc2.nDeviceCoords); @@ -1854,6 +2031,11 @@ int cmsReadICCnamedColorList(cmsHTRANSFORM xform, cmsHPROFILE hProfile, icTagSig return 0; } + if (nc2.nDeviceCoords > MAXCHANNELS) { + cmsSignalError(LCMS_ERRC_WARNING, "Too many device coordinates."); + return 0; + } + strncpy(v ->NamedColorList->Prefix, (const char*) nc2.prefix, 32); strncpy(v ->NamedColorList->Suffix, (const char*) nc2.suffix, 32); v ->NamedColorList->Prefix[32] = v->NamedColorList->Suffix[32] = 0; @@ -1900,7 +2082,8 @@ int cmsReadICCnamedColorList(cmsHTRANSFORM xform, cmsHPROFILE hProfile, icTagSig LPcmsNAMEDCOLORLIST LCMSEXPORT cmsReadColorantTable(cmsHPROFILE hProfile, icTagSignature sig) { - icInt32Number n, Count, i; + icInt32Number n; + icUInt32Number Count, i; size_t offset; icTagTypeSignature BaseType; LPLCMSICCPROFILE Icc = (LPLCMSICCPROFILE) (LPSTR) hProfile; @@ -1910,10 +2093,12 @@ LPcmsNAMEDCOLORLIST LCMSEXPORT cmsReadColorantTable(cmsHPROFILE hProfile, icTagS if (n < 0) return NULL; // Not found - if (!Icc -> stream) { + if (Icc -> TagPtrs[n]) { size_t size = Icc -> TagSizes[n]; - void* v = malloc(size); + void* v = _cmsMalloc(size); + + if (v == NULL) return NULL; CopyMemory(v, Icc -> TagPtrs[n], size); return (LPcmsNAMEDCOLORLIST) v; } @@ -1932,13 +2117,17 @@ LPcmsNAMEDCOLORLIST LCMSEXPORT cmsReadColorantTable(cmsHPROFILE hProfile, icTagS } - Icc ->Read(&Count, sizeof(icUInt32Number), 1, Icc); + if (Icc ->Read(&Count, sizeof(icUInt32Number), 1, Icc) != 1) return NULL; AdjustEndianess32((LPBYTE) &Count); + if (Count > MAXCHANNELS) { + cmsSignalError(LCMS_ERRC_ABORTED, "Too many colorants '%lx'", Count); + return NULL; + } + List = cmsAllocNamedColorList(Count); for (i=0; i < Count; i++) { - if (!Icc ->Read(List->List[i].Name, 1, 32 , Icc)) goto Error; if (!Icc ->Read(List->List[i].PCS, sizeof(icUInt16Number), 3, Icc)) goto Error; AdjustEndianessArray16(List->List[i].PCS, 3); @@ -1965,7 +2154,7 @@ const char* LCMSEXPORT cmsTakeManufacturer(cmsHPROFILE hProfile) if (cmsIsTag(hProfile, icSigDeviceMfgDescTag)) { - cmsReadICCText(hProfile, icSigDeviceMfgDescTag, Manufacturer); + cmsReadICCTextEx(hProfile, icSigDeviceMfgDescTag, Manufacturer, LCMS_DESC_MAX); } return Manufacturer; @@ -1982,7 +2171,7 @@ const char* LCMSEXPORT cmsTakeModel(cmsHPROFILE hProfile) if (cmsIsTag(hProfile, icSigDeviceModelDescTag)) { - cmsReadICCText(hProfile, icSigDeviceModelDescTag, Model); + cmsReadICCTextEx(hProfile, icSigDeviceModelDescTag, Model, LCMS_DESC_MAX); } return Model; @@ -1995,10 +2184,9 @@ const char* LCMSEXPORT cmsTakeCopyright(cmsHPROFILE hProfile) static char Copyright[LCMS_DESC_MAX] = ""; Copyright[0] = 0; - if (cmsIsTag(hProfile, icSigCopyrightTag)) { - cmsReadICCText(hProfile, icSigCopyrightTag, Copyright); + cmsReadICCTextEx(hProfile, icSigCopyrightTag, Copyright, LCMS_DESC_MAX); } return Copyright; @@ -2009,7 +2197,7 @@ const char* LCMSEXPORT cmsTakeCopyright(cmsHPROFILE hProfile) const char* LCMSEXPORT cmsTakeProductName(cmsHPROFILE hProfile) { - static char Name[2048]; + static char Name[LCMS_DESC_MAX*2+4]; char Manufacturer[LCMS_DESC_MAX], Model[LCMS_DESC_MAX]; Name[0] = '\0'; @@ -2017,19 +2205,19 @@ const char* LCMSEXPORT cmsTakeProductName(cmsHPROFILE hProfile) if (cmsIsTag(hProfile, icSigDeviceMfgDescTag)) { - cmsReadICCText(hProfile, icSigDeviceMfgDescTag, Manufacturer); + cmsReadICCTextEx(hProfile, icSigDeviceMfgDescTag, Manufacturer, LCMS_DESC_MAX); } if (cmsIsTag(hProfile, icSigDeviceModelDescTag)) { - cmsReadICCText(hProfile, icSigDeviceModelDescTag, Model); + cmsReadICCTextEx(hProfile, icSigDeviceModelDescTag, Model, LCMS_DESC_MAX); } if (!Manufacturer[0] && !Model[0]) { if (cmsIsTag(hProfile, icSigProfileDescriptionTag)) { - cmsReadICCText(hProfile, icSigProfileDescriptionTag, Name); + cmsReadICCTextEx(hProfile, icSigProfileDescriptionTag, Name, LCMS_DESC_MAX); return Name; } else return "{no name}"; @@ -2129,7 +2317,7 @@ const char* LCMSEXPORT cmsTakeProductInfo(cmsHPROFILE hProfile) // Extract the target data as a big string. Does not signal if tag is not present. -BOOL LCMSEXPORT cmsTakeCharTargetData(cmsHPROFILE hProfile, char** Data, size_t* len) +LCMSBOOL LCMSEXPORT cmsTakeCharTargetData(cmsHPROFILE hProfile, char** Data, size_t* len) { LPLCMSICCPROFILE Icc = (LPLCMSICCPROFILE) (LPSTR) hProfile; int n; @@ -2142,7 +2330,11 @@ BOOL LCMSEXPORT cmsTakeCharTargetData(cmsHPROFILE hProfile, char** Data, size_t* *len = Icc -> TagSizes[n]; - *Data = (char*) malloc(*len + 1); // Plus zero marker + + // Make sure that is reasonable (600K) + if (*len > 600*1024) *len = 600*1024; + + *Data = (char*) _cmsMalloc(*len + 1); // Plus zero marker if (!*Data) { @@ -2162,7 +2354,7 @@ BOOL LCMSEXPORT cmsTakeCharTargetData(cmsHPROFILE hProfile, char** Data, size_t* -BOOL LCMSEXPORT cmsTakeCalibrationDateTime(struct tm *Dest, cmsHPROFILE hProfile) +LCMSBOOL LCMSEXPORT cmsTakeCalibrationDateTime(struct tm *Dest, cmsHPROFILE hProfile) { LPLCMSICCPROFILE Icc = (LPLCMSICCPROFILE) (LPSTR) hProfile; int n; @@ -2170,8 +2362,8 @@ BOOL LCMSEXPORT cmsTakeCalibrationDateTime(struct tm *Dest, cmsHPROFILE hProfile n = _cmsSearchTag(Icc, icSigCalibrationDateTimeTag, FALSE); if (n < 0) return FALSE; - if (!Icc ->stream) - { + if (Icc ->TagPtrs[n]) { + CopyMemory(Dest, Icc ->TagPtrs[n], sizeof(struct tm)); } else @@ -2212,9 +2404,10 @@ LPcmsSEQ LCMSEXPORT cmsReadProfileSequenceDescription(cmsHPROFILE hProfile) size = Icc -> TagSizes[n]; if (size < 12) return NULL; - if (!Icc -> stream) { + if (Icc -> TagPtrs[n]) { - OutSeq = (LPcmsSEQ) malloc(size); + OutSeq = (LPcmsSEQ) _cmsMalloc(size); + if (OutSeq == NULL) return NULL; CopyMemory(OutSeq, Icc ->TagPtrs[n], size); return OutSeq; } @@ -2231,8 +2424,13 @@ LPcmsSEQ LCMSEXPORT cmsReadProfileSequenceDescription(cmsHPROFILE hProfile) Icc ->Read(&Count, sizeof(icUInt32Number), 1, Icc); AdjustEndianess32((LPBYTE) &Count); + if (Count > 1000) { + return NULL; + } + size = sizeof(int) + Count * sizeof(cmsPSEQDESC); - OutSeq = (LPcmsSEQ) malloc(size); + OutSeq = (LPcmsSEQ) _cmsMalloc(size); + if (OutSeq == NULL) return NULL; OutSeq ->n = Count; @@ -2268,181 +2466,11 @@ LPcmsSEQ LCMSEXPORT cmsReadProfileSequenceDescription(cmsHPROFILE hProfile) void LCMSEXPORT cmsFreeProfileSequenceDescription(LPcmsSEQ pseq) { if (pseq) - free(pseq); -} - - - -// Extended gamut -- an HP extension - - -LPcmsGAMUTEX LCMSEXPORT cmsReadExtendedGamut(cmsHPROFILE hProfile, int index) -{ - LPLCMSICCPROFILE Icc = (LPLCMSICCPROFILE) (LPSTR) hProfile; - size_t size, offset; - icUInt32Number off_samp, off_desc, off_vc; - int n; - icTagTypeSignature BaseType; - icColorSpaceSignature CoordSig; - icUInt16Number Method, Usage; - icUInt32Number GamutCount, SamplesCount; - LPcmsGAMUTEX gex; - size_t Offsets[256]; - size_t i, Actual, Loc; - icS15Fixed16Number Num; - icUInt16Number Surround; - - - n = _cmsSearchTag(Icc, icSigHPGamutDescTag, FALSE); - if (n < 0) return NULL; - - if (!Icc ->stream) return NULL; // In memory is not supported - - // Read the header - - offset = Icc -> TagOffsets[n]; - - if (Icc -> Seek(Icc, offset)) - return NULL; - - // Here is the beginning of tag - Actual = Icc ->Tell(Icc); - - - BaseType = ReadBase(Icc); - - if (BaseType != icSigHPGamutDescType) { - cmsSignalError(LCMS_ERRC_ABORTED, "Bad tag signature '%lx' found.", BaseType); - return NULL; - } - - - // Read the gamut descriptors count - Icc ->Read(&GamutCount, sizeof(icUInt32Number), 1, Icc); - AdjustEndianess32((LPBYTE) &GamutCount); - - - if (GamutCount >= 256) { - cmsSignalError(LCMS_ERRC_ABORTED, "Too many gamut structures '%d'.", GamutCount); - return NULL; - } - - // Read the directory - - for (i=0; i < GamutCount; i++) { - - Icc ->Read(&Offsets[i], sizeof(icUInt32Number), 1, Icc); - AdjustEndianess32((LPBYTE) &Offsets[i]); - } - - - // Is there such element? - if (index >= (int) GamutCount) return NULL; - Loc = Actual + Offsets[index]; - - - // Go to specified index - if (Icc -> Seek(Icc, Loc)) - return NULL; - - - // Read all members - Icc ->Read(&CoordSig, sizeof(icColorSpaceSignature), 1, Icc); - AdjustEndianess32((LPBYTE) &CoordSig); - - Icc ->Read(&Method, sizeof(icUInt16Number), 1, Icc); - AdjustEndianess16((LPBYTE) &Method); - - Icc ->Read(&Usage, sizeof(icUInt16Number), 1, Icc); - AdjustEndianess16((LPBYTE) &Usage); - - Icc ->Read(&SamplesCount, sizeof(icUInt32Number), 1, Icc); - AdjustEndianess32((LPBYTE) &SamplesCount); - - Icc ->Read(&off_samp, sizeof(icUInt32Number), 1, Icc); - AdjustEndianess32((LPBYTE) &off_samp); - - Icc ->Read(&off_desc, sizeof(icUInt32Number), 1, Icc); - AdjustEndianess32((LPBYTE) &off_desc); - - Icc ->Read(&off_vc, sizeof(icUInt32Number), 1, Icc); - AdjustEndianess32((LPBYTE) &off_vc); - - - size = sizeof(cmsGAMUTEX) + (SamplesCount - 1) * sizeof(double); - - gex = (LPcmsGAMUTEX) malloc(size); - if (gex == NULL) return NULL; - - - gex ->CoordSig = CoordSig; - gex ->Method = Method; - gex ->Usage = Usage; - gex ->Count = SamplesCount; - - - // Read data - if (Icc -> Seek(Icc, Loc + off_samp)) - return NULL; - - for (i=0; i < SamplesCount; i++) { - Icc -> Read(&Num, sizeof(icS15Fixed16Number), 1, Icc); - gex ->Data[i] = Convert15Fixed16(Num); - } - - - // Read mluc - if (Icc -> Seek(Icc, Loc + off_desc)) { - - free(gex); - return NULL; - } - - ReadEmbeddedTextTag(Icc, 256, gex ->Description, LCMS_DESC_MAX); - - - // Read viewing conditions - if (Icc -> Seek(Icc, Loc + off_vc)) { - free(gex); - return NULL; - } - - - Icc -> Read(&Num, sizeof(icS15Fixed16Number), 1, Icc); - gex ->Vc.whitePoint.X = Convert15Fixed16(Num); - - Icc -> Read(&Num, sizeof(icS15Fixed16Number), 1, Icc); - gex ->Vc.whitePoint.Y = Convert15Fixed16(Num); - - Icc -> Read(&Num, sizeof(icS15Fixed16Number), 1, Icc); - gex ->Vc.whitePoint.Z = Convert15Fixed16(Num); - - Icc -> Read(&Num, sizeof(icS15Fixed16Number), 1, Icc); - gex ->Vc.La = Convert15Fixed16(Num); - - Icc -> Read(&Num, sizeof(icS15Fixed16Number), 1, Icc); - gex ->Vc.Yb = Convert15Fixed16(Num); - - Icc -> Read(&Num, sizeof(icS15Fixed16Number), 1, Icc); - gex ->Vc.D_value = Convert15Fixed16(Num); - - Icc -> Read(&Surround, sizeof(icUInt16Number), 1, Icc); - AdjustEndianess16((LPBYTE) &Surround); - gex ->Vc.surround = Surround; - - - // All OK - return gex; - + _cmsFree(pseq); } -void LCMSEXPORT cmsFreeExtendedGamut(LPcmsGAMUTEX gex) -{ - if (gex) - free(gex); -} // Read a few tags that are hardly required @@ -2564,6 +2592,7 @@ cmsHPROFILE LCMSEXPORT cmsOpenProfileFromFile(const char *lpFileName, const char NewIcc = (LPLCMSICCPROFILE) (LPSTR) hEmpty; NewIcc -> IsWrite = TRUE; strncpy(NewIcc ->PhysicalFile, lpFileName, MAX_PATH-1); + NewIcc ->PhysicalFile[MAX_PATH-1] = 0; // Save LUT as 8 bit @@ -2609,14 +2638,14 @@ cmsHPROFILE LCMSEXPORT cmsOpenProfileFromMem(LPVOID MemPtr, DWORD dwSize) -BOOL LCMSEXPORT cmsCloseProfile(cmsHPROFILE hProfile) +LCMSBOOL LCMSEXPORT cmsCloseProfile(cmsHPROFILE hProfile) { LPLCMSICCPROFILE Icc = (LPLCMSICCPROFILE) (LPSTR) hProfile; - BOOL rc = TRUE; + LCMSBOOL rc = TRUE; + icInt32Number i; if (!Icc) return FALSE; - // Was open in write mode? if (Icc ->IsWrite) { @@ -2624,21 +2653,15 @@ BOOL LCMSEXPORT cmsCloseProfile(cmsHPROFILE hProfile) rc = _cmsSaveProfile(hProfile, Icc ->PhysicalFile); } - - if (Icc -> stream == NULL) { // Was a memory (i.e. not serialized) profile? - - - icInt32Number i; // Yes, free tags - - for (i=0; i < Icc -> TagCount; i++) { + for (i=0; i < Icc -> TagCount; i++) { if (Icc -> TagPtrs[i]) free(Icc -> TagPtrs[i]); - } - } - else Icc -> Close(Icc); // No, close the stream + if (Icc -> stream != NULL) { // Was a memory (i.e. not serialized) profile? + Icc -> Close(Icc); // No, close the stream + } free(Icc); // Free placeholder memory @@ -2652,11 +2675,11 @@ BOOL LCMSEXPORT cmsCloseProfile(cmsHPROFILE hProfile) static -BOOL SaveWordsTable(int nEntries, LPWORD Tab, LPLCMSICCPROFILE Icc) +LCMSBOOL SaveWordsTable(int nEntries, LPWORD Tab, LPLCMSICCPROFILE Icc) { size_t nTabSize = sizeof(WORD) * nEntries; - LPWORD PtrW = (LPWORD) malloc(nTabSize); - BOOL rc; + LPWORD PtrW = (LPWORD) _cmsMalloc(nTabSize); + LCMSBOOL rc; if (!PtrW) return FALSE; CopyMemory(PtrW, Tab, nTabSize); @@ -2672,7 +2695,7 @@ BOOL SaveWordsTable(int nEntries, LPWORD Tab, LPLCMSICCPROFILE Icc) // Saves profile header static -BOOL SaveHeader(LPLCMSICCPROFILE Icc) +LCMSBOOL SaveHeader(LPLCMSICCPROFILE Icc) { icHeader Header; time_t now = time(NULL); @@ -2727,7 +2750,7 @@ BOOL SaveHeader(LPLCMSICCPROFILE Icc) // Setup base marker static -BOOL SetupBase(icTagTypeSignature sig, LPLCMSICCPROFILE Icc) +LCMSBOOL SetupBase(icTagTypeSignature sig, LPLCMSICCPROFILE Icc) { icTagBase Base; @@ -2737,10 +2760,10 @@ BOOL SetupBase(icTagTypeSignature sig, LPLCMSICCPROFILE Icc) } -// Store an XYZ tag +// Store a XYZ tag static -BOOL SaveXYZNumber(LPcmsCIEXYZ Value, LPLCMSICCPROFILE Icc) +LCMSBOOL SaveXYZNumber(LPcmsCIEXYZ Value, LPLCMSICCPROFILE Icc) { icXYZNumber XYZ; @@ -2756,72 +2779,97 @@ BOOL SaveXYZNumber(LPcmsCIEXYZ Value, LPLCMSICCPROFILE Icc) } +// Store a XYZ array. + +static +LCMSBOOL SaveXYZArray(int n, LPcmsCIEXYZ Value, LPLCMSICCPROFILE Icc) +{ + int i; + icXYZNumber XYZ; + + if (!SetupBase(icSigS15Fixed16ArrayType, Icc)) return FALSE; + + for (i=0; i < n; i++) { + + XYZ.X = TransportValue32(DOUBLE_TO_FIXED(Value -> X)); + XYZ.Y = TransportValue32(DOUBLE_TO_FIXED(Value -> Y)); + XYZ.Z = TransportValue32(DOUBLE_TO_FIXED(Value -> Z)); + + if (!Icc -> Write(Icc, sizeof(icXYZNumber), &XYZ)) return FALSE; + + Value++; + } + + return TRUE; +} + + // Save a gamma structure as a table static -BOOL SaveGammaTable(LPGAMMATABLE Gamma, LPLCMSICCPROFILE Icc) +LCMSBOOL SaveGammaTable(LPGAMMATABLE Gamma, LPLCMSICCPROFILE Icc) { - icInt32Number Count; + icInt32Number Count; - if (!SetupBase(icSigCurveType, Icc)) return FALSE; + if (!SetupBase(icSigCurveType, Icc)) return FALSE; - Count = TransportValue32(Gamma->nEntries); + Count = TransportValue32(Gamma->nEntries); - if (!Icc ->Write(Icc, sizeof(icInt32Number), &Count)) return FALSE; + if (!Icc ->Write(Icc, sizeof(icInt32Number), &Count)) return FALSE; - return SaveWordsTable(Gamma->nEntries, Gamma ->GammaTable, Icc); + return SaveWordsTable(Gamma->nEntries, Gamma ->GammaTable, Icc); } // Save a gamma structure as a one-value static -BOOL SaveGammaOneValue(LPGAMMATABLE Gamma, LPLCMSICCPROFILE Icc) +LCMSBOOL SaveGammaOneValue(LPGAMMATABLE Gamma, LPLCMSICCPROFILE Icc) { - icInt32Number Count; - Fixed32 GammaFixed32; - WORD GammaFixed8; + icInt32Number Count; + Fixed32 GammaFixed32; + WORD GammaFixed8; - if (!SetupBase(icSigCurveType, Icc)) return FALSE; + if (!SetupBase(icSigCurveType, Icc)) return FALSE; - Count = TransportValue32(1); - if (!Icc ->Write(Icc, sizeof(icInt32Number), &Count)) return FALSE; + Count = TransportValue32(1); + if (!Icc ->Write(Icc, sizeof(icInt32Number), &Count)) return FALSE; - GammaFixed32 = DOUBLE_TO_FIXED(Gamma ->Seed.Params[0]); - GammaFixed8 = (WORD) ((GammaFixed32 >> 8) & 0xFFFF); - GammaFixed8 = TransportValue16(GammaFixed8); + GammaFixed32 = DOUBLE_TO_FIXED(Gamma ->Seed.Params[0]); + GammaFixed8 = (WORD) ((GammaFixed32 >> 8) & 0xFFFF); + GammaFixed8 = TransportValue16(GammaFixed8); - return Icc ->Write(Icc, sizeof(icInt16Number), &GammaFixed8); + return Icc ->Write(Icc, sizeof(icInt16Number), &GammaFixed8); } // Save a gamma structure as a parametric gamma static -BOOL SaveGammaParametric(LPGAMMATABLE Gamma, LPLCMSICCPROFILE Icc) +LCMSBOOL SaveGammaParametric(LPGAMMATABLE Gamma, LPLCMSICCPROFILE Icc) { - icUInt16Number Type, Reserved; - int i, nParams; - int ParamsByType[] = { 1, 3, 4, 5, 7 }; + icUInt16Number Type, Reserved; + int i, nParams; + int ParamsByType[] = { 1, 3, 4, 5, 7 }; - if (!SetupBase(icSigParametricCurveType, Icc)) return FALSE; + if (!SetupBase(icSigParametricCurveType, Icc)) return FALSE; - nParams = ParamsByType[Gamma -> Seed.Type]; + nParams = ParamsByType[Gamma -> Seed.Type]; - Type = (icUInt16Number) TransportValue16((WORD) Gamma -> Seed. Type); - Reserved = (icUInt16Number) TransportValue16((WORD) 0); + Type = (icUInt16Number) TransportValue16((WORD) Gamma -> Seed. Type); + Reserved = (icUInt16Number) TransportValue16((WORD) 0); - Icc -> Write(Icc, sizeof(icInt16Number), &Type); - Icc -> Write(Icc, sizeof(icUInt16Number), &Reserved); + Icc -> Write(Icc, sizeof(icInt16Number), &Type); + Icc -> Write(Icc, sizeof(icUInt16Number), &Reserved); - for (i=0; i < nParams; i++) { + for (i=0; i < nParams; i++) { - icInt32Number val = TransportValue32(DOUBLE_TO_FIXED(Gamma -> Seed.Params[i])); - Icc ->Write(Icc, sizeof(icInt32Number), &val); - } + icInt32Number val = TransportValue32(DOUBLE_TO_FIXED(Gamma -> Seed.Params[i])); + Icc ->Write(Icc, sizeof(icInt32Number), &val); + } - return TRUE; + return TRUE; } @@ -2829,29 +2877,29 @@ BOOL SaveGammaParametric(LPGAMMATABLE Gamma, LPLCMSICCPROFILE Icc) // Save a gamma table static -BOOL SaveGamma(LPGAMMATABLE Gamma, LPLCMSICCPROFILE Icc) +LCMSBOOL SaveGamma(LPGAMMATABLE Gamma, LPLCMSICCPROFILE Icc) { - // Is the gamma curve type supported by ICC format? + // Is the gamma curve type supported by ICC format? - if (Gamma -> Seed.Type < 0 || Gamma -> Seed.Type > 5 || + if (Gamma -> Seed.Type < 0 || Gamma -> Seed.Type > 5 || - // has been modified by user? + // has been modified by user? - _cmsCrc32OfGammaTable(Gamma) != Gamma -> Seed.Crc32) { + _cmsCrc32OfGammaTable(Gamma) != Gamma -> Seed.Crc32) { - return SaveGammaTable(Gamma, Icc); - } + return SaveGammaTable(Gamma, Icc); + } - if (Gamma -> Seed.Type == 1) return SaveGammaOneValue(Gamma, Icc); + if (Gamma -> Seed.Type == 1) return SaveGammaOneValue(Gamma, Icc); - // Only v4 profiles are allowed to hold parametric curves + // Only v4 profiles are allowed to hold parametric curves - if (cmsGetProfileICCversion((cmsHPROFILE) Icc) >= 0x4000000) - return SaveGammaParametric(Gamma, Icc); + if (cmsGetProfileICCversion((cmsHPROFILE) Icc) >= 0x4000000) + return SaveGammaParametric(Gamma, Icc); - // Defaults to save as table + // Defaults to save as table - return SaveGammaTable(Gamma, Icc); + return SaveGammaTable(Gamma, Icc); } @@ -2861,7 +2909,7 @@ BOOL SaveGamma(LPGAMMATABLE Gamma, LPLCMSICCPROFILE Icc) // Save an DESC Tag static -BOOL SaveDescription(const char *Text, LPLCMSICCPROFILE Icc) +LCMSBOOL SaveDescription(const char *Text, LPLCMSICCPROFILE Icc) { icUInt32Number len, Count, TotalSize, AlignedSize; @@ -2893,6 +2941,11 @@ BOOL SaveDescription(const char *Text, LPLCMSICCPROFILE Icc) if (!Icc ->Write(Icc, len, (LPVOID)Text)) return FALSE; AlignedSize -= len; + if (AlignedSize < 0) + AlignedSize = 0; + if (AlignedSize > 255) + AlignedSize = 255; + ZeroMemory(Filler, AlignedSize); if (!Icc ->Write(Icc, AlignedSize, Filler)) return FALSE; @@ -2902,7 +2955,7 @@ BOOL SaveDescription(const char *Text, LPLCMSICCPROFILE Icc) // Save an ASCII Tag static -BOOL SaveText(const char *Text, LPLCMSICCPROFILE Icc) +LCMSBOOL SaveText(const char *Text, LPLCMSICCPROFILE Icc) { size_t len = strlen(Text) + 1; @@ -2915,7 +2968,7 @@ BOOL SaveText(const char *Text, LPLCMSICCPROFILE Icc) // Save one of these new chromaticity values static -BOOL SaveOneChromaticity(double x, double y, LPLCMSICCPROFILE Icc) +LCMSBOOL SaveOneChromaticity(double x, double y, LPLCMSICCPROFILE Icc) { Fixed32 xf, yf; @@ -2932,7 +2985,7 @@ BOOL SaveOneChromaticity(double x, double y, LPLCMSICCPROFILE Icc) // New tag added in Addendum II of old spec. static -BOOL SaveChromaticities(LPcmsCIExyYTRIPLE chrm, LPLCMSICCPROFILE Icc) +LCMSBOOL SaveChromaticities(LPcmsCIExyYTRIPLE chrm, LPLCMSICCPROFILE Icc) { WORD nChans, Table; @@ -2952,7 +3005,7 @@ BOOL SaveChromaticities(LPcmsCIExyYTRIPLE chrm, LPLCMSICCPROFILE Icc) static -BOOL SaveSequenceDescriptionTag(LPcmsSEQ seq, LPLCMSICCPROFILE Icc) +LCMSBOOL SaveSequenceDescriptionTag(LPcmsSEQ seq, LPLCMSICCPROFILE Icc) { icUInt32Number nSeqs; icDescStruct DescStruct; @@ -2989,7 +3042,7 @@ BOOL SaveSequenceDescriptionTag(LPcmsSEQ seq, LPLCMSICCPROFILE Icc) // Saves a timestamp tag static -BOOL SaveDateTimeNumber(const struct tm *DateTime, LPLCMSICCPROFILE Icc) +LCMSBOOL SaveDateTimeNumber(const struct tm *DateTime, LPLCMSICCPROFILE Icc) { icDateTimeNumber Dest; @@ -3003,14 +3056,14 @@ BOOL SaveDateTimeNumber(const struct tm *DateTime, LPLCMSICCPROFILE Icc) // Saves a named color list into a named color profile static -BOOL SaveNamedColorList(LPcmsNAMEDCOLORLIST NamedColorList, LPLCMSICCPROFILE Icc) +LCMSBOOL SaveNamedColorList(LPcmsNAMEDCOLORLIST NamedColorList, LPLCMSICCPROFILE Icc) { icUInt32Number vendorFlag; // Bottom 16 bits for IC use icUInt32Number count; // Count of named colors icUInt32Number nDeviceCoords; // Num of device coordinates - icInt8Number prefix[32]; // Prefix for each color name - icInt8Number suffix[32]; // Suffix for each color name + char prefix[32]; // Prefix for each color name + char suffix[32]; // Suffix for each color name int i; if (!SetupBase(icSigNamedColor2Type, Icc)) return FALSE; @@ -3019,8 +3072,10 @@ BOOL SaveNamedColorList(LPcmsNAMEDCOLORLIST NamedColorList, LPLCMSICCPROFILE Icc count = TransportValue32(NamedColorList ->nColors); nDeviceCoords = TransportValue32(NamedColorList ->ColorantCount); - strncpy(prefix, (const char*) NamedColorList->Prefix, 32); - strncpy(suffix, (const char*) NamedColorList->Suffix, 32); + strncpy(prefix, (const char*) NamedColorList->Prefix, 31); + strncpy(suffix, (const char*) NamedColorList->Suffix, 31); + + suffix[31] = prefix[31] = 0; if (!Icc ->Write(Icc, sizeof(icUInt32Number), &vendorFlag)) return FALSE; if (!Icc ->Write(Icc, sizeof(icUInt32Number), &count)) return FALSE; @@ -3030,15 +3085,17 @@ BOOL SaveNamedColorList(LPcmsNAMEDCOLORLIST NamedColorList, LPLCMSICCPROFILE Icc for (i=0; i < NamedColorList ->nColors; i++) { - icUInt16Number PCS[3]; - icUInt16Number Colorant[MAXCHANNELS]; - icInt8Number root[32]; + icUInt16Number PCS[3]; + icUInt16Number Colorant[MAXCHANNELS]; + char root[32]; LPcmsNAMEDCOLOR Color; int j; Color = NamedColorList ->List + i; - strncpy((char*) root, Color ->Name, 32); + strncpy(root, Color ->Name, 32); + Color ->Name[32] = 0; + if (!Icc ->Write(Icc, 32 , root)) return FALSE; for (j=0; j < 3; j++) @@ -3062,7 +3119,7 @@ BOOL SaveNamedColorList(LPcmsNAMEDCOLORLIST NamedColorList, LPLCMSICCPROFILE Icc // Saves a colorant table. It is using the named color structure for simplicity sake static -BOOL SaveColorantTable(LPcmsNAMEDCOLORLIST NamedColorList, LPLCMSICCPROFILE Icc) +LCMSBOOL SaveColorantTable(LPcmsNAMEDCOLORLIST NamedColorList, LPLCMSICCPROFILE Icc) { icUInt32Number count; // Count of named colors int i; @@ -3076,13 +3133,15 @@ BOOL SaveColorantTable(LPcmsNAMEDCOLORLIST NamedColorList, LPLCMSICCPROFILE Icc) for (i=0; i < NamedColorList ->nColors; i++) { icUInt16Number PCS[3]; - icInt8Number root[32]; + icInt8Number root[33]; LPcmsNAMEDCOLOR Color; int j; Color = NamedColorList ->List + i; strncpy((char*) root, Color ->Name, 32); + root[32] = 0; + if (!Icc ->Write(Icc, 32 , root)) return FALSE; for (j=0; j < 3; j++) @@ -3099,7 +3158,7 @@ BOOL SaveColorantTable(LPcmsNAMEDCOLORLIST NamedColorList, LPLCMSICCPROFILE Icc) // Does serialization of LUT16 and writes it. static -BOOL SaveLUT(const LUT* NewLUT, LPLCMSICCPROFILE Icc) +LCMSBOOL SaveLUT(const LUT* NewLUT, LPLCMSICCPROFILE Icc) { icLut16 LUT16; unsigned int i; @@ -3189,7 +3248,7 @@ BOOL SaveLUT(const LUT* NewLUT, LPLCMSICCPROFILE Icc) // Does serialization of LUT8 and writes it static -BOOL SaveLUT8(const LUT* NewLUT, LPLCMSICCPROFILE Icc) +LCMSBOOL SaveLUT8(const LUT* NewLUT, LPLCMSICCPROFILE Icc) { icLut8 LUT8; unsigned int i, j; @@ -3323,7 +3382,7 @@ void LCMSEXPORT _cmsSetLUTdepth(cmsHPROFILE hProfile, int depth) // Saves Tag directory static -BOOL SaveTagDirectory(LPLCMSICCPROFILE Icc) +LCMSBOOL SaveTagDirectory(LPLCMSICCPROFILE Icc) { icInt32Number i; icTag Tag; @@ -3356,7 +3415,7 @@ BOOL SaveTagDirectory(LPLCMSICCPROFILE Icc) // Dump tag contents static -BOOL SaveTags(LPLCMSICCPROFILE Icc) +LCMSBOOL SaveTags(LPLCMSICCPROFILE Icc, LPLCMSICCPROFILE FileOrig) { LPBYTE Data; @@ -3384,8 +3443,31 @@ BOOL SaveTags(LPLCMSICCPROFILE Icc) Icc -> TagOffsets[i] = Begin = Icc ->UsedSpace; Data = (LPBYTE) Icc -> TagPtrs[i]; - if (!Data) + if (!Data) { + + // Reach here if we are copying a tag from a disk-based ICC profile which has not been modified by user. + // In this case a blind copy of the block data is performed + + if (Icc -> TagOffsets[i]) { + + size_t TagSize = FileOrig -> TagSizes[i]; + size_t TagOffset = FileOrig -> TagOffsets[i]; + void* Mem; + + if (FileOrig ->Seek(FileOrig, TagOffset)) return FALSE; + + Mem = _cmsMalloc(TagSize); + + if (FileOrig ->Read(Mem, TagSize, 1, FileOrig) != 1) return FALSE; + if (!Icc ->Write(Icc, TagSize, Mem)) return FALSE; + + Icc -> TagSizes[i] = (Icc ->UsedSpace - Begin); + free(Mem); + } + continue; + } + switch (Icc -> TagNames[i]) { @@ -3464,6 +3546,10 @@ BOOL SaveTags(LPLCMSICCPROFILE Icc) break; + case icSigChromaticAdaptationTag: + if (!SaveXYZArray(3, (LPcmsCIEXYZ) Data, Icc)) return FALSE; + break; + default: return FALSE; } @@ -3480,9 +3566,9 @@ BOOL SaveTags(LPLCMSICCPROFILE Icc) // Add tags to profile structure -BOOL LCMSEXPORT cmsAddTag(cmsHPROFILE hProfile, icTagSignature sig, const void* Tag) +LCMSBOOL LCMSEXPORT cmsAddTag(cmsHPROFILE hProfile, icTagSignature sig, const void* Tag) { - BOOL rc; + LCMSBOOL rc; switch (sig) { @@ -3543,6 +3629,11 @@ BOOL LCMSEXPORT cmsAddTag(cmsHPROFILE hProfile, icTagSignature sig, const void* rc = _cmsAddColorantTableTag(hProfile, sig, (LPcmsNAMEDCOLORLIST) Tag); break; + + case icSigChromaticAdaptationTag: + rc = _cmsAddChromaticAdaptationTag(hProfile, sig, (const cmsCIEXYZ*) Tag); + break; + default: cmsSignalError(LCMS_ERRC_ABORTED, "cmsAddTag: Tag '%x' is unsupported", sig); return FALSE; @@ -3568,11 +3659,11 @@ BOOL LCMSEXPORT cmsAddTag(cmsHPROFILE hProfile, icTagSignature sig, const void* // Low-level save to disk. It closes the profile on exit -BOOL LCMSEXPORT _cmsSaveProfile(cmsHPROFILE hProfile, const char* FileName) +LCMSBOOL LCMSEXPORT _cmsSaveProfile(cmsHPROFILE hProfile, const char* FileName) { LPLCMSICCPROFILE Icc = (LPLCMSICCPROFILE) (LPSTR) hProfile; LCMSICCPROFILE Keep; - BOOL rc; + LCMSBOOL rc; CopyMemory(&Keep, Icc, sizeof(LCMSICCPROFILE)); _cmsSetSaveToDisk(Icc, NULL); @@ -3581,7 +3672,7 @@ BOOL LCMSEXPORT _cmsSaveProfile(cmsHPROFILE hProfile, const char* FileName) if (!SaveHeader(Icc)) return FALSE; if (!SaveTagDirectory(Icc)) return FALSE; - if (!SaveTags(Icc)) return FALSE; + if (!SaveTags(Icc, &Keep)) return FALSE; _cmsSetSaveToDisk(Icc, FileName); @@ -3591,7 +3682,7 @@ BOOL LCMSEXPORT _cmsSaveProfile(cmsHPROFILE hProfile, const char* FileName) if (!SaveHeader(Icc)) goto CleanUp; if (!SaveTagDirectory(Icc)) goto CleanUp; - if (!SaveTags(Icc)) goto CleanUp; + if (!SaveTags(Icc, &Keep)) goto CleanUp; rc = (Icc ->Close(Icc) == 0); CopyMemory(Icc, &Keep, sizeof(LCMSICCPROFILE)); @@ -3608,7 +3699,7 @@ BOOL LCMSEXPORT _cmsSaveProfile(cmsHPROFILE hProfile, const char* FileName) // Low-level save from open stream -BOOL LCMSEXPORT _cmsSaveProfileToMem(cmsHPROFILE hProfile, void *MemPtr, +LCMSBOOL LCMSEXPORT _cmsSaveProfileToMem(cmsHPROFILE hProfile, void *MemPtr, size_t* BytesNeeded) { LPLCMSICCPROFILE Icc = (LPLCMSICCPROFILE) (LPSTR) hProfile; @@ -3623,20 +3714,20 @@ BOOL LCMSEXPORT _cmsSaveProfileToMem(cmsHPROFILE hProfile, void *MemPtr, if (!SaveHeader(Icc)) return FALSE; if (!SaveTagDirectory(Icc)) return FALSE; - if (!SaveTags(Icc)) return FALSE; + if (!SaveTags(Icc, &Keep)) return FALSE; if (!MemPtr) { // update BytesSaved so caller knows how many bytes are needed for MemPtr *BytesNeeded = Icc ->UsedSpace; - CopyMemory(Icc, &Keep, sizeof(LCMSICCPROFILE)); + CopyMemory(Icc, &Keep, sizeof(LCMSICCPROFILE)); return TRUE; } if (*BytesNeeded < Icc ->UsedSpace) { // need at least UsedSpace in MemPtr to continue - CopyMemory(Icc, &Keep, sizeof(LCMSICCPROFILE)); + CopyMemory(Icc, &Keep, sizeof(LCMSICCPROFILE)); return FALSE; } @@ -3646,7 +3737,7 @@ BOOL LCMSEXPORT _cmsSaveProfileToMem(cmsHPROFILE hProfile, void *MemPtr, // Pass #2 does save to file into supplied stream if (!SaveHeader(Icc)) goto CleanUp; if (!SaveTagDirectory(Icc)) goto CleanUp; - if (!SaveTags(Icc)) goto CleanUp; + if (!SaveTags(Icc, &Keep)) goto CleanUp; // update BytesSaved so caller knows how many bytes put into stream *BytesNeeded = Icc ->UsedSpace; @@ -3661,3 +3752,4 @@ CleanUp: CopyMemory(Icc, &Keep, sizeof(LCMSICCPROFILE)); return FALSE; } + diff --git a/src/share/native/sun/java2d/cmm/lcms/cmslut.c b/src/share/native/sun/java2d/cmm/lcms/cmslut.c index 4303210912170f717dcc8bb5651fb3a69d9c52f5..1a222febf86590545494b91c900d15e368478d72 100644 --- a/src/share/native/sun/java2d/cmm/lcms/cmslut.c +++ b/src/share/native/sun/java2d/cmm/lcms/cmslut.c @@ -29,7 +29,7 @@ // // // Little cms -// Copyright (C) 1998-2006 Marti Maria +// Copyright (C) 1998-2007 Marti Maria // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the "Software"), @@ -118,7 +118,7 @@ LPLUT LCMSEXPORT cmsAllocLUT(void) { LPLUT NewLUT; - NewLUT = (LPLUT) malloc(sizeof(LUT)); + NewLUT = (LPLUT) _cmsMalloc(sizeof(LUT)); if (NewLUT) ZeroMemory(NewLUT, sizeof(LUT)); @@ -171,9 +171,10 @@ void LCMSEXPORT cmsFreeLUT(LPLUT Lut) static LPVOID DupBlockTab(LPVOID Org, size_t size) { - LPVOID mem = malloc(size); + LPVOID mem = _cmsMalloc(size); + if (mem != NULL) + CopyMemory(mem, Org, size); - CopyMemory(mem, Org, size); return mem; } @@ -211,6 +212,37 @@ unsigned int UIpow(unsigned int a, unsigned int b) } +LCMSBOOL _cmsValidateLUT(LPLUT NewLUT) +{ + unsigned int calc = 1; + unsigned int oldCalc; + unsigned int power = NewLUT -> InputChan; + + if (NewLUT -> cLutPoints > 100) return FALSE; + if (NewLUT -> InputChan > MAXCHANNELS) return FALSE; + if (NewLUT -> OutputChan > MAXCHANNELS) return FALSE; + + if (NewLUT -> cLutPoints == 0) return TRUE; + + for (; power > 0; power--) { + + oldCalc = calc; + calc *= NewLUT -> cLutPoints; + + if (calc / NewLUT -> cLutPoints != oldCalc) { + return FALSE; + } + } + + oldCalc = calc; + calc *= NewLUT -> OutputChan; + if (NewLUT -> OutputChan && calc / NewLUT -> OutputChan != oldCalc) { + return FALSE; + } + + return TRUE; +} + LPLUT LCMSEXPORT cmsAlloc3DGrid(LPLUT NewLUT, int clutPoints, int inputChan, int outputChan) { DWORD nTabSize; @@ -220,12 +252,17 @@ LPLUT LCMSEXPORT cmsAlloc3DGrid(LPLUT NewLUT, int clutPoints, int inputChan, int NewLUT -> InputChan = inputChan; NewLUT -> OutputChan = outputChan; + if (!_cmsValidateLUT(NewLUT)) { + return NULL; + } + + nTabSize = NewLUT -> OutputChan * UIpow(NewLUT->cLutPoints, + NewLUT->InputChan); - nTabSize = (NewLUT -> OutputChan * UIpow(NewLUT->cLutPoints, - NewLUT->InputChan) - * sizeof(WORD)); + NewLUT -> T = (LPWORD) _cmsCalloc(sizeof(WORD), nTabSize); + nTabSize *= sizeof(WORD); + if (NewLUT -> T == NULL) return NULL; - NewLUT -> T = (LPWORD) malloc(nTabSize); ZeroMemory(NewLUT -> T, nTabSize); NewLUT ->Tsize = nTabSize; @@ -254,10 +291,12 @@ LPLUT LCMSEXPORT cmsAllocLinearTable(LPLUT NewLUT, LPGAMMATABLE Tables[], int nT for (i=0; i < NewLUT -> InputChan; i++) { - PtrW = (LPWORD) malloc(sizeof(WORD) * NewLUT -> InputEntries); + PtrW = (LPWORD) _cmsMalloc(sizeof(WORD) * NewLUT -> InputEntries); + if (PtrW == NULL) return NULL; + NewLUT -> L1[i] = PtrW; CopyMemory(PtrW, Tables[i]->GammaTable, sizeof(WORD) * NewLUT -> InputEntries); - CopyMemory(&NewLUT -> LCurvesSeed[0][i], &Tables[i] -> Seed, sizeof(LCMSGAMMAPARAMS)); + CopyMemory(&NewLUT -> LCurvesSeed[0][i], &Tables[i] -> Seed, sizeof(LCMSGAMMAPARAMS)); } @@ -268,10 +307,12 @@ LPLUT LCMSEXPORT cmsAllocLinearTable(LPLUT NewLUT, LPGAMMATABLE Tables[], int nT NewLUT -> OutputEntries = Tables[0] -> nEntries; for (i=0; i < NewLUT -> OutputChan; i++) { - PtrW = (LPWORD) malloc(sizeof(WORD) * NewLUT -> OutputEntries); + PtrW = (LPWORD) _cmsMalloc(sizeof(WORD) * NewLUT -> OutputEntries); + if (PtrW == NULL) return NULL; + NewLUT -> L2[i] = PtrW; CopyMemory(PtrW, Tables[i]->GammaTable, sizeof(WORD) * NewLUT -> OutputEntries); - CopyMemory(&NewLUT -> LCurvesSeed[1][i], &Tables[i] -> Seed, sizeof(LCMSGAMMAPARAMS)); + CopyMemory(&NewLUT -> LCurvesSeed[1][i], &Tables[i] -> Seed, sizeof(LCMSGAMMAPARAMS)); } break; @@ -285,10 +326,12 @@ LPLUT LCMSEXPORT cmsAllocLinearTable(LPLUT NewLUT, LPGAMMATABLE Tables[], int nT for (i=0; i < NewLUT -> InputChan; i++) { - PtrW = (LPWORD) malloc(sizeof(WORD) * NewLUT -> L3Entries); + PtrW = (LPWORD) _cmsMalloc(sizeof(WORD) * NewLUT -> L3Entries); + if (PtrW == NULL) return NULL; + NewLUT -> L3[i] = PtrW; CopyMemory(PtrW, Tables[i]->GammaTable, sizeof(WORD) * NewLUT -> L3Entries); - CopyMemory(&NewLUT -> LCurvesSeed[2][i], &Tables[i] -> Seed, sizeof(LCMSGAMMAPARAMS)); + CopyMemory(&NewLUT -> LCurvesSeed[2][i], &Tables[i] -> Seed, sizeof(LCMSGAMMAPARAMS)); } break; @@ -298,10 +341,12 @@ LPLUT LCMSEXPORT cmsAllocLinearTable(LPLUT NewLUT, LPGAMMATABLE Tables[], int nT NewLUT -> L4Entries = Tables[0] -> nEntries; for (i=0; i < NewLUT -> OutputChan; i++) { - PtrW = (LPWORD) malloc(sizeof(WORD) * NewLUT -> L4Entries); + PtrW = (LPWORD) _cmsMalloc(sizeof(WORD) * NewLUT -> L4Entries); + if (PtrW == NULL) return NULL; + NewLUT -> L4[i] = PtrW; CopyMemory(PtrW, Tables[i]->GammaTable, sizeof(WORD) * NewLUT -> L4Entries); - CopyMemory(&NewLUT -> LCurvesSeed[3][i], &Tables[i] -> Seed, sizeof(LCMSGAMMAPARAMS)); + CopyMemory(&NewLUT -> LCurvesSeed[3][i], &Tables[i] -> Seed, sizeof(LCMSGAMMAPARAMS)); } break; @@ -580,7 +625,7 @@ LPLUT _cmsBlessLUT8(LPLUT Lut) LPL16PARAMS p = &Lut ->CLut16params; - p8 = (LPL8PARAMS) malloc(sizeof(L8PARAMS)); + p8 = (LPL8PARAMS) _cmsMalloc(sizeof(L8PARAMS)); if (p8 == NULL) return NULL; // values comes * 257, so we can safely take first byte (x << 8 + x) @@ -593,8 +638,8 @@ LPLUT _cmsBlessLUT8(LPLUT Lut) if (Lut ->wFlags & LUT_HASTL1) { for (j=0; j < 3; j++) - StageABC[i] = cmsLinearInterpLUT16(StageABC[i], - Lut -> L1[i], + StageABC[j] = cmsLinearInterpLUT16(StageABC[j], + Lut -> L1[j], &Lut -> In16params); Lut ->wFlags &= ~LUT_HASTL1; } @@ -697,7 +742,7 @@ void EvalLUTdoubleKLab(LPLUT Lut, const VEC3* In, WORD FixedK, LPcmsCIELab Out) wIn[3] = FixedK; cmsEvalLUT(Lut, wIn, wOut); - cmsLabEncoded2Float(Out, wOut); + cmsLabEncoded2Float(Out, wOut); } // Builds a Jacobian CMY->Lab @@ -722,9 +767,9 @@ void ComputeJacobianLab(LPLUT Lut, LPMAT3 Jacobian, const VEC3* Colorant, WORD K EvalLUTdoubleKLab(Lut, &ColorantD, K, &LabD); - Jacobian->v[0].n[j] = ((LabD.L - Lab.L) / JACOBIAN_EPSILON); - Jacobian->v[1].n[j] = ((LabD.a - Lab.a) / JACOBIAN_EPSILON); - Jacobian->v[2].n[j] = ((LabD.b - Lab.b) / JACOBIAN_EPSILON); + Jacobian->v[0].n[j] = ((LabD.L - Lab.L) / JACOBIAN_EPSILON); + Jacobian->v[1].n[j] = ((LabD.a - Lab.a) / JACOBIAN_EPSILON); + Jacobian->v[2].n[j] = ((LabD.b - Lab.b) / JACOBIAN_EPSILON); } } @@ -797,18 +842,18 @@ LCMSAPI double LCMSEXPORT cmsEvalLUTreverse(LPLUT Lut, WORD Target[], WORD Resul // Obtain slope ComputeJacobianLab(Lut, &Jacobian, &x, FixedK); - // Solve system - tmp2.n[0] = fx.L - Goal.L; - tmp2.n[1] = fx.a - Goal.a; - tmp2.n[2] = fx.b - Goal.b; + // Solve system + tmp2.n[0] = fx.L - Goal.L; + tmp2.n[1] = fx.a - Goal.a; + tmp2.n[2] = fx.b - Goal.b; - if (!MAT3solve(&tmp, &Jacobian, &tmp2)) - break; + if (!MAT3solve(&tmp, &Jacobian, &tmp2)) + break; // Move our guess - x.n[0] -= tmp.n[0]; - x.n[1] -= tmp.n[1]; - x.n[2] -= tmp.n[2]; + x.n[0] -= tmp.n[0]; + x.n[1] -= tmp.n[1]; + x.n[2] -= tmp.n[2]; // Some clipping.... VEC3saturate(&x); @@ -822,3 +867,6 @@ LCMSAPI double LCMSEXPORT cmsEvalLUTreverse(LPLUT Lut, WORD Target[], WORD Resul return LastError; } + + + diff --git a/src/share/native/sun/java2d/cmm/lcms/cmsmatsh.c b/src/share/native/sun/java2d/cmm/lcms/cmsmatsh.c index c70829989b246826ccb72e1d9085f6c66c51ab81..9a6576bce23dbfeb94718d431389ee7cbfacb801 100644 --- a/src/share/native/sun/java2d/cmm/lcms/cmsmatsh.c +++ b/src/share/native/sun/java2d/cmm/lcms/cmsmatsh.c @@ -29,7 +29,7 @@ // // // Little cms -// Copyright (C) 1998-2006 Marti Maria +// Copyright (C) 1998-2007 Marti Maria // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the "Software"), @@ -62,6 +62,7 @@ // data yet in fixed point, so no additional process is required. // Then, we obtain data on 15.16, so we need to shift >> by 1 to // obtain 1.15 PCS format. + // On OUTPUT profiles, things are inverse, we must first expand 1 bit // by shifting left, and then convert result between 0 and 1.000 to // RGB, so FromFixedDomain() must be called before pass values to @@ -71,6 +72,7 @@ // input is encoded from 0 to 0xffff, we must first use the shaper and // then the matrix, an additional FromFixedDomain() must be used to // accomodate output values. + // For a sake of simplicity, I will handle this three behaviours // with different routines, so the flags MATSHAPER_INPUT and MATSHAPER_OUTPUT // can be conbined to signal smelted matrix-shapers @@ -89,7 +91,7 @@ int ComputeTables(LPGAMMATABLE Table[3], LPWORD Out[3], LPL16PARAMS p16) { LPWORD PtrW; - PtrW = (LPWORD) malloc(sizeof(WORD) * p16 -> nSamples); + PtrW = (LPWORD) _cmsMalloc(sizeof(WORD) * p16 -> nSamples); if (PtrW == NULL) return -1; // Signal error @@ -119,7 +121,7 @@ LPMATSHAPER cmsAllocMatShaper2(LPMAT3 Matrix, LPGAMMATABLE In[], LPGAMMATABLE Ou LPMATSHAPER NewMatShaper; int rc; - NewMatShaper = (LPMATSHAPER) malloc(sizeof(MATSHAPER)); + NewMatShaper = (LPMATSHAPER) _cmsMalloc(sizeof(MATSHAPER)); if (NewMatShaper) ZeroMemory(NewMatShaper, sizeof(MATSHAPER)); @@ -171,7 +173,13 @@ LPMATSHAPER cmsAllocMatShaper(LPMAT3 Matrix, LPGAMMATABLE Tables[], DWORD Behavi LPMATSHAPER NewMatShaper; int i, AllLinear; - NewMatShaper = (LPMATSHAPER) malloc(sizeof(MATSHAPER)); + if (Matrix == NULL) return NULL; + for (i=0; i < 3; i++) { + + if (Tables[i] == NULL) return NULL; + } + + NewMatShaper = (LPMATSHAPER) _cmsMalloc(sizeof(MATSHAPER)); if (NewMatShaper) ZeroMemory(NewMatShaper, sizeof(MATSHAPER)); @@ -187,17 +195,16 @@ LPMATSHAPER cmsAllocMatShaper(LPMAT3 Matrix, LPGAMMATABLE Tables[], DWORD Behavi NewMatShaper -> dwFlags |= MATSHAPER_HASMATRIX; // Now, on the table characteristics - cmsCalcL16Params(Tables[0] -> nEntries, &NewMatShaper -> p16); // Copy tables AllLinear = 0; - for (i=0; i < 3; i++) - { + for (i=0; i < 3; i++) { + LPWORD PtrW; - PtrW = (LPWORD) malloc(sizeof(WORD) * NewMatShaper -> p16.nSamples); + PtrW = (LPWORD) _cmsMalloc(sizeof(WORD) * NewMatShaper -> p16.nSamples); if (PtrW == NULL) { cmsFreeMatShaper(NewMatShaper); @@ -235,11 +242,11 @@ void cmsFreeMatShaper(LPMATSHAPER MatShaper) for (i=0; i < 3; i++) { - if (MatShaper -> L[i]) free(MatShaper ->L[i]); - if (MatShaper -> L2[i]) free(MatShaper ->L2[i]); + if (MatShaper -> L[i]) _cmsFree(MatShaper ->L[i]); + if (MatShaper -> L2[i]) _cmsFree(MatShaper ->L2[i]); } - free(MatShaper); + _cmsFree(MatShaper); } diff --git a/src/share/native/sun/java2d/cmm/lcms/cmsmtrx.c b/src/share/native/sun/java2d/cmm/lcms/cmsmtrx.c index b404fdc6924d1443f43e4943161d1075d30e7f7a..f6bc3cb5a595bc00abcb6db36eb7cc05cfae69d3 100644 --- a/src/share/native/sun/java2d/cmm/lcms/cmsmtrx.c +++ b/src/share/native/sun/java2d/cmm/lcms/cmsmtrx.c @@ -29,7 +29,7 @@ // // // Little cms -// Copyright (C) 1998-2006 Marti Maria +// Copyright (C) 1998-2007 Marti Maria // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the "Software"), @@ -71,16 +71,16 @@ double cdecl VEC3length(LPVEC3 a); double cdecl VEC3distance(LPVEC3 a, LPVEC3 b); -void cdecl MAT3identity(LPMAT3 a); -void cdecl MAT3per(LPMAT3 r, LPMAT3 a, LPMAT3 b); -int cdecl MAT3inverse(LPMAT3 a, LPMAT3 b); -BOOL cdecl MAT3solve(LPVEC3 x, LPMAT3 a, LPVEC3 b); -double cdecl MAT3det(LPMAT3 m); -void cdecl MAT3eval(LPVEC3 r, LPMAT3 a, LPVEC3 v); -void cdecl MAT3toFix(LPWMAT3 r, LPMAT3 v); -void cdecl MAT3evalW(LPWVEC3 r, LPWMAT3 a, LPWVEC3 v); -void cdecl MAT3perK(LPMAT3 r, LPMAT3 v, double d); -void cdecl MAT3scaleAndCut(LPWMAT3 r, LPMAT3 v, double d); +void cdecl MAT3identity(LPMAT3 a); +void cdecl MAT3per(LPMAT3 r, LPMAT3 a, LPMAT3 b); +int cdecl MAT3inverse(LPMAT3 a, LPMAT3 b); +LCMSBOOL cdecl MAT3solve(LPVEC3 x, LPMAT3 a, LPVEC3 b); +double cdecl MAT3det(LPMAT3 m); +void cdecl MAT3eval(LPVEC3 r, LPMAT3 a, LPVEC3 v); +void cdecl MAT3toFix(LPWMAT3 r, LPMAT3 v); +void cdecl MAT3evalW(LPWVEC3 r, LPWMAT3 a, LPWVEC3 v); +void cdecl MAT3perK(LPMAT3 r, LPMAT3 v, double d); +void cdecl MAT3scaleAndCut(LPWMAT3 r, LPMAT3 v, double d); // --------------------- Implementation ---------------------------- @@ -345,13 +345,13 @@ void VEC3minus(LPVEC3 r, LPVEC3 a, LPVEC3 b) // Check id two vectors are the same, allowing tolerance static -BOOL RangeCheck(double l, double h, double v) +LCMSBOOL RangeCheck(double l, double h, double v) { return (v >= l && v <= h); } -BOOL VEC3equal(LPWVEC3 a, LPWVEC3 b, double Tolerance) +LCMSBOOL VEC3equal(LPWVEC3 a, LPWVEC3 b, double Tolerance) { int i; double c; @@ -367,7 +367,7 @@ BOOL VEC3equal(LPWVEC3 a, LPWVEC3 b, double Tolerance) return TRUE; } -BOOL VEC3equalF(LPVEC3 a, LPVEC3 b, double Tolerance) +LCMSBOOL VEC3equalF(LPVEC3 a, LPVEC3 b, double Tolerance) { int i; double c; @@ -462,7 +462,7 @@ void MAT3identity(LPMAT3 a) // Check if matrix is Identity. Allow a tolerance as % -BOOL MAT3isIdentity(LPWMAT3 a, double Tolerance) +LCMSBOOL MAT3isIdentity(LPWMAT3 a, double Tolerance) { int i; MAT3 Idd; @@ -545,16 +545,16 @@ int MAT3inverse(LPMAT3 a, LPMAT3 b) // Solve a system in the form Ax = b -BOOL MAT3solve(LPVEC3 x, LPMAT3 a, LPVEC3 b) +LCMSBOOL MAT3solve(LPVEC3 x, LPMAT3 a, LPVEC3 b) { - MAT3 m, a_1; + MAT3 m, a_1; - CopyMemory(&m, a, sizeof(MAT3)); + CopyMemory(&m, a, sizeof(MAT3)); - if (!MAT3inverse(&m, &a_1)) return FALSE; // Singular matrix + if (!MAT3inverse(&m, &a_1)) return FALSE; // Singular matrix - MAT3eval(x, &a_1, b); - return TRUE; + MAT3eval(x, &a_1, b); + return TRUE; } @@ -839,3 +839,7 @@ void MAT3scaleAndCut(LPWMAT3 r, LPMAT3 v, double d) VEC3scaleAndCut(&r -> v[1], &v -> v[1], d); VEC3scaleAndCut(&r -> v[2], &v -> v[2], d); } + + + + diff --git a/src/share/native/sun/java2d/cmm/lcms/cmsnamed.c b/src/share/native/sun/java2d/cmm/lcms/cmsnamed.c index c943badcb3baffddc8fa8733a8d58d4f28e9496c..c47d002f7cf3ffcd6d703f46e1a4f7ff12a14e1d 100644 --- a/src/share/native/sun/java2d/cmm/lcms/cmsnamed.c +++ b/src/share/native/sun/java2d/cmm/lcms/cmsnamed.c @@ -29,7 +29,7 @@ // // // Little cms -// Copyright (C) 1998-2006 Marti Maria +// Copyright (C) 1998-2007 Marti Maria // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the "Software"), @@ -74,7 +74,7 @@ LPcmsNAMEDCOLORLIST GrowNamedColorList(LPcmsNAMEDCOLORLIST v, int ByElements) NewElements *= 2; size = sizeof(cmsNAMEDCOLORLIST) + (sizeof(cmsNAMEDCOLOR) * NewElements); - TheNewList = (LPcmsNAMEDCOLORLIST) malloc(size); + TheNewList = (LPcmsNAMEDCOLORLIST) _cmsMalloc(size); if (TheNewList == NULL) { @@ -86,7 +86,7 @@ LPcmsNAMEDCOLORLIST GrowNamedColorList(LPcmsNAMEDCOLORLIST v, int ByElements) CopyMemory(TheNewList, v, sizeof(cmsNAMEDCOLORLIST) + (v ->nColors - 1) * sizeof(cmsNAMEDCOLOR)); TheNewList -> Allocated = NewElements; - free(v); + _cmsFree(v); return TheNewList; } } @@ -99,7 +99,7 @@ LPcmsNAMEDCOLORLIST cmsAllocNamedColorList(int n) { size_t size = sizeof(cmsNAMEDCOLORLIST) + (n - 1) * sizeof(cmsNAMEDCOLOR); - LPcmsNAMEDCOLORLIST v = (LPcmsNAMEDCOLORLIST) malloc(size); + LPcmsNAMEDCOLORLIST v = (LPcmsNAMEDCOLORLIST) _cmsMalloc(size); if (v == NULL) { @@ -124,10 +124,10 @@ void cmsFreeNamedColorList(LPcmsNAMEDCOLORLIST v) return; } - free(v); + _cmsFree(v); } -BOOL cmsAppendNamedColor(cmsHTRANSFORM xform, const char* Name, WORD PCS[3], WORD Colorant[MAXCHANNELS]) +LCMSBOOL cmsAppendNamedColor(cmsHTRANSFORM xform, const char* Name, WORD PCS[3], WORD Colorant[MAXCHANNELS]) { _LPcmsTRANSFORM v = (_LPcmsTRANSFORM) xform; LPcmsNAMEDCOLORLIST List; @@ -146,6 +146,7 @@ BOOL cmsAppendNamedColor(cmsHTRANSFORM xform, const char* Name, WORD PCS[3], WOR List ->List[List ->nColors].PCS[i] = PCS[i]; strncpy(List ->List[List ->nColors].Name, Name, MAX_PATH-1); + List ->List[List ->nColors].Name[MAX_PATH-1] = 0; List ->nColors++; return TRUE; @@ -164,18 +165,17 @@ int LCMSEXPORT cmsNamedColorCount(cmsHTRANSFORM xform) } -BOOL LCMSEXPORT cmsNamedColorInfo(cmsHTRANSFORM xform, int nColor, char* Name, char* Prefix, char* Suffix) +LCMSBOOL LCMSEXPORT cmsNamedColorInfo(cmsHTRANSFORM xform, int nColor, char* Name, char* Prefix, char* Suffix) { _LPcmsTRANSFORM v = (_LPcmsTRANSFORM) xform; - if (v ->NamedColorList == NULL) return FALSE; if (nColor < 0 || nColor >= cmsNamedColorCount(xform)) return FALSE; - if (Name) strncpy(Name, v ->NamedColorList->List[nColor].Name, 31); - if (Prefix) strncpy(Prefix, v ->NamedColorList->Prefix, 31); - if (Suffix) strncpy(Suffix, v ->NamedColorList->Suffix, 31); + if (Name) { strncpy(Name, v ->NamedColorList->List[nColor].Name, 31); Name[31] = 0; } + if (Prefix) { strncpy(Prefix, v ->NamedColorList->Prefix, 31); Prefix[31] = 0; } + if (Suffix) { strncpy(Suffix, v ->NamedColorList->Suffix, 31); Suffix[31] = 0; } return TRUE; } @@ -196,3 +196,5 @@ int LCMSEXPORT cmsNamedColorIndex(cmsHTRANSFORM xform, const char* Name) return -1; } + + diff --git a/src/share/native/sun/java2d/cmm/lcms/cmspack.c b/src/share/native/sun/java2d/cmm/lcms/cmspack.c index ca76c07844ac8ce5a4dfbdd03e4f0af88bdd41a0..6c5ef725635e86062dfa4d807b02bd51900185e3 100644 --- a/src/share/native/sun/java2d/cmm/lcms/cmspack.c +++ b/src/share/native/sun/java2d/cmm/lcms/cmspack.c @@ -28,7 +28,7 @@ // file: // // Little cms -// Copyright (C) 1998-2006 Marti Maria +// Copyright (C) 1998-2007 Marti Maria // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the "Software"), @@ -639,9 +639,81 @@ LPBYTE UnrollDouble(register _LPcmsTRANSFORM info, register WORD wIn[], register +static +LPBYTE UnrollDouble1Chan(register _LPcmsTRANSFORM info, register WORD wIn[], register LPBYTE accum) +{ + double* Inks = (double*) accum; + double v; + + + v = floor(Inks[0] * 65535.0 + 0.5); + + if (v > 65535.0) v = 65535.0; + if (v < 0) v = 0; + + + wIn[0] = wIn[1] = wIn[2] = (WORD) v; + + return accum + sizeof(double); +} + + // ----------------------------------------------------------- Packing routines +// Generic N-bytes plus dither 16-to-8 conversion. Currently is just a quick hack + +static int err[MAXCHANNELS]; + +static +LPBYTE PackNBytesDither(register _LPcmsTRANSFORM info, register WORD wOut[], register LPBYTE output) +{ + int nChan = T_CHANNELS(info -> OutputFormat); + register int i; + unsigned int n, pe, pf; + + for (i=0; i < nChan; i++) { + + n = wOut[i] + err[i]; // Value + + pe = (n / 257); // Whole part + pf = (n % 257); // Fractional part + + err[i] = pf; // Store it for next pixel + + *output++ = (BYTE) pe; + } + + return output + T_EXTRA(info ->OutputFormat); +} + + + +static +LPBYTE PackNBytesSwapDither(register _LPcmsTRANSFORM info, register WORD wOut[], register LPBYTE output) +{ + int nChan = T_CHANNELS(info -> OutputFormat); + register int i; + unsigned int n, pe, pf; + + for (i=nChan-1; i >= 0; --i) { + + n = wOut[i] + err[i]; // Value + + pe = (n / 257); // Whole part + pf = (n % 257); // Fractional part + + err[i] = pf; // Store it for next pixel + + *output++ = (BYTE) pe; + } + + + return output + T_EXTRA(info ->OutputFormat); +} + + + // Generic chunky for byte static @@ -1486,7 +1558,10 @@ _cmsFIXFN _cmsIdentifyInputFormat(_LPcmsTRANSFORM xform, DWORD dwInput) case PT_HSV: case PT_HLS: case PT_Yxy: - FromInput = UnrollDouble; + if (T_CHANNELS(dwInput) == 1) + FromInput = UnrollDouble1Chan; + else + FromInput = UnrollDouble; break; // Inks (%) 0.0 .. 100.0 @@ -1749,6 +1824,9 @@ _cmsFIXFN _cmsIdentifyOutputFormat(_LPcmsTRANSFORM xform, DWORD dwOutput) switch (T_CHANNELS(dwOutput)) { case 1: + if (T_DITHER(dwOutput)) + ToOutput = PackNBytesDither; + else ToOutput = Pack1Byte; if (T_EXTRA(dwOutput) == 1) { if (T_SWAPFIRST(dwOutput)) @@ -1766,8 +1844,12 @@ _cmsFIXFN _cmsIdentifyOutputFormat(_LPcmsTRANSFORM xform, DWORD dwOutput) else if (T_COLORSPACE(dwOutput) == PT_Lab) ToOutput = Pack3BytesLab; + else { + if (T_DITHER(dwOutput)) + ToOutput = PackNBytesDither; else ToOutput = Pack3Bytes; + } break; case 1: // TODO: ALab8 should be handled here @@ -1793,12 +1875,22 @@ _cmsFIXFN _cmsIdentifyOutputFormat(_LPcmsTRANSFORM xform, DWORD dwOutput) case 4: if (T_EXTRA(dwOutput) == 0) { + if (T_DOSWAP(dwOutput)) { - if (T_SWAPFIRST(dwOutput)) + + if (T_SWAPFIRST(dwOutput)) { ToOutput = Pack4BytesSwapSwapFirst; - else + } + else { + + if (T_DITHER(dwOutput)) { + ToOutput = PackNBytesSwapDither; + } + else { ToOutput = Pack4BytesSwap; + } + } } else { if (T_SWAPFIRST(dwOutput)) @@ -1807,11 +1899,15 @@ _cmsFIXFN _cmsIdentifyOutputFormat(_LPcmsTRANSFORM xform, DWORD dwOutput) if (T_FLAVOR(dwOutput)) ToOutput = Pack4BytesReverse; + else { + if (T_DITHER(dwOutput)) + ToOutput = PackNBytesDither; else ToOutput = Pack4Bytes; } } } + } else { if (!T_DOSWAP(dwOutput) && !T_SWAPFIRST(dwOutput)) ToOutput = PackNBytes; @@ -1833,7 +1929,7 @@ _cmsFIXFN _cmsIdentifyOutputFormat(_LPcmsTRANSFORM xform, DWORD dwOutput) } break; - case 2: + case 2: case 5: case 7: case 8: @@ -1849,8 +1945,13 @@ _cmsFIXFN _cmsIdentifyOutputFormat(_LPcmsTRANSFORM xform, DWORD dwOutput) { if (T_DOSWAP(dwOutput)) ToOutput = PackNBytesSwap; + else { + + if (T_DITHER(dwOutput)) + ToOutput = PackNBytesDither; else ToOutput = PackNBytes; + } } break; @@ -1984,7 +2085,7 @@ _cmsFIXFN _cmsIdentifyOutputFormat(_LPcmsTRANSFORM xform, DWORD dwOutput) break; - case 2: + case 2: case 5: case 7: case 8: diff --git a/src/share/native/sun/java2d/cmm/lcms/cmspcs.c b/src/share/native/sun/java2d/cmm/lcms/cmspcs.c index 4ad975550c3a42ada54ce1e7b6688487dc8a99fc..e9b3d2ed545a0233238cc9043b5d92632b0c514a 100644 --- a/src/share/native/sun/java2d/cmm/lcms/cmspcs.c +++ b/src/share/native/sun/java2d/cmm/lcms/cmspcs.c @@ -29,7 +29,7 @@ // // // Little cms -// Copyright (C) 1998-2006 Marti Maria +// Copyright (C) 1998-2007 Marti Maria // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the "Software"), @@ -624,3 +624,7 @@ void LCMSEXPORT cmsXYZEncoded2Float(LPcmsCIEXYZ fXYZ, const WORD XYZ[3]) fXYZ -> Z = XYZ2float(XYZ[2]); } + + + + diff --git a/src/share/native/sun/java2d/cmm/lcms/cmsps2.c b/src/share/native/sun/java2d/cmm/lcms/cmsps2.c index f3bf7ec6fe8763b1b269fc78c9887c65b2669039..22a67c0772d2eb183fe4655b54cce7c551a3a728 100644 --- a/src/share/native/sun/java2d/cmm/lcms/cmsps2.c +++ b/src/share/native/sun/java2d/cmm/lcms/cmsps2.c @@ -29,7 +29,7 @@ // // // Little cms -// Copyright (C) 1998-2006 Marti Maria +// Copyright (C) 1998-2007 Marti Maria // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the "Software"), @@ -144,6 +144,8 @@ LCMSAPI DWORD LCMSEXPORT cmsGetPostScriptCRDEx(cmsHPROFILE hProfile, int Intent, /Table [ p p p [<...>]] /RangeABC [ 0 1 0 1 0 1] /DecodeABC[ <postlinearization> ] + /RangeLMN [ -0.236 1.254 0 1 -0.635 1.640 ] + % -128/500 1+127/500 0 1 -127/200 1+128/200 /MatrixABC [ 1 1 1 1 0 0 0 0 -1] /WhitePoint [D50] /BlackPoint [BP] @@ -347,7 +349,8 @@ typedef struct { static LPMEMSTREAM CreateMemStream(LPBYTE Buffer, DWORD dwMax, int MaxCols) { - LPMEMSTREAM m = (LPMEMSTREAM) malloc(sizeof(MEMSTREAM)); + LPMEMSTREAM m = (LPMEMSTREAM) _cmsMalloc(sizeof(MEMSTREAM)); + if (m == NULL) return NULL; ZeroMemory(m, sizeof(MEMSTREAM)); @@ -376,9 +379,9 @@ BYTE Word2Byte(WORD w) static BYTE L2Byte(WORD w) { - int ww = w + 0x0080; + int ww = w + 0x0080; - if (ww > 0xFFFF) return 0xFF; + if (ww > 0xFFFF) return 0xFF; return (BYTE) ((WORD) (ww >> 8) & 0xFF); } @@ -387,7 +390,6 @@ BYTE L2Byte(WORD w) static void WriteRawByte(LPMEMSTREAM m, BYTE b) { - if (m -> dwUsed + 1 > m -> dwMax) { m -> HasError = 1; } @@ -422,7 +424,7 @@ void WriteByte(LPMEMSTREAM m, BYTE b) } -// Does write a formatted string +// Does write a formatted string. Guaranteed to be 2048 bytes at most. static void Writef(LPMEMSTREAM m, const char *frm, ...) { @@ -432,7 +434,7 @@ void Writef(LPMEMSTREAM m, const char *frm, ...) va_start(args, frm); - vsprintf((char*) Buffer, frm, args); + vsnprintf((char*) Buffer, 2048, frm, args); for (pt = Buffer; *pt; pt++) { @@ -562,7 +564,7 @@ void EmitLab2XYZ(LPMEMSTREAM m) Writef(m, "{255 mul 128 sub 200 div } bind\n"); Writef(m, "]\n"); Writef(m, "/MatrixABC [ 1 1 1 1 0 0 0 0 -1]\n"); - Writef(m, "/RangeLMN [ 0.0 0.9642 0.0 1.0000 0.0 0.8249 ]\n"); + Writef(m, "/RangeLMN [ -0.236 1.254 0 1 -0.635 1.640 ]\n"); Writef(m, "/DecodeLMN [\n"); Writef(m, "{dup 6 29 div ge {dup dup mul mul} {4 29 div sub 108 841 div mul} ifelse 0.964200 mul} bind\n"); Writef(m, "{dup 6 29 div ge {dup dup mul mul} {4 29 div sub 108 841 div mul} ifelse } bind\n"); @@ -584,7 +586,11 @@ void Emit1Gamma(LPMEMSTREAM m, LPWORD Table, int nEntries) if (nEntries <= 0) return; // Empty table // Suppress whole if identity - if (cmsIsLinear(Table, nEntries)) return; + if (cmsIsLinear(Table, nEntries)) { + Writef(m, "{} "); + return; + } + // Check if is really an exponential. If so, emit "exp" gamma = cmsEstimateGammaEx(Table, nEntries, 0.001); @@ -646,7 +652,7 @@ void Emit1Gamma(LPMEMSTREAM m, LPWORD Table, int nEntries) // Compare gamma table static -BOOL GammaTableEquals(LPWORD g1, LPWORD g2, int nEntries) +LCMSBOOL GammaTableEquals(LPWORD g1, LPWORD g2, int nEntries) { return memcmp(g1, g2, nEntries* sizeof(WORD)) == 0; } @@ -676,7 +682,7 @@ void EmitNGamma(LPMEMSTREAM m, int n, LPWORD g[], int nEntries) // Check whatever a profile has CLUT tables (only on input) static -BOOL IsLUTbased(cmsHPROFILE hProfile, int Intent) +LCMSBOOL IsLUTbased(cmsHPROFILE hProfile, int Intent) { icTagSignature Tag; @@ -718,10 +724,10 @@ int OutputValueSampler(register WORD In[], register WORD Out[], register LPVOID if (sc -> FixWhite) { - if (In[0] == 0xFFFF) { // Only in L* = 100 + if (In[0] == 0xFFFF) { // Only in L* = 100, ab = [-8..8] - if ((In[1] >= 0x8000 && In[1] <= 0x87FF) || - (In[2] >= 0x8000 && In[2] <= 0x87FF)) { + if ((In[1] >= 0x7800 && In[1] <= 0x8800) && + (In[2] >= 0x7800 && In[2] <= 0x8800)) { WORD* Black; WORD* White; @@ -829,8 +835,8 @@ void WriteCLUT(LPMEMSTREAM m, LPLUT Lut, int bps, const char* PreMaj, sc.PreMaj = PreMaj; sc.PostMaj= PostMaj; - sc.PreMin = PreMin; - sc.PostMin= PostMin; + sc.PreMin = PreMin; + sc.PostMin = PostMin; sc.lIsInput = lIsInput; sc.FixWhite = FixWhite; sc.ColorSpace = ColorSpace; @@ -1231,7 +1237,7 @@ DWORD LCMSEXPORT cmsGetPostScriptCSA(cmsHPROFILE hProfile, if (!WriteNamedColorCSA(mem, hProfile, Intent)) { - free((void*) mem); + _cmsFree((void*) mem); return 0; } } @@ -1246,7 +1252,7 @@ DWORD LCMSEXPORT cmsGetPostScriptCSA(cmsHPROFILE hProfile, ColorSpace != icSigLabData) { cmsSignalError(LCMS_ERRC_ABORTED, "Invalid output color space"); - free((void*) mem); + _cmsFree((void*) mem); return 0; } @@ -1256,7 +1262,7 @@ DWORD LCMSEXPORT cmsGetPostScriptCSA(cmsHPROFILE hProfile, // Yes, so handle as LUT-based if (!WriteInputLUT(mem, hProfile, Intent)) { - free((void*) mem); + _cmsFree((void*) mem); return 0; } } @@ -1266,7 +1272,7 @@ DWORD LCMSEXPORT cmsGetPostScriptCSA(cmsHPROFILE hProfile, if (!WriteInputMatrixShaper(mem, hProfile)) { - free((void*) mem); // Something went wrong + _cmsFree((void*) mem); // Something went wrong return 0; } } @@ -1277,7 +1283,7 @@ DWORD LCMSEXPORT cmsGetPostScriptCSA(cmsHPROFILE hProfile, dwBytesUsed = mem ->dwUsed; // Get rid of memory stream - free((void*) mem); + _cmsFree((void*) mem); // Finally, return used byte count return dwBytesUsed; @@ -1350,27 +1356,40 @@ DWORD LCMSEXPORT cmsGetPostScriptCSA(cmsHPROFILE hProfile, static -void EmitPQRStage(LPMEMSTREAM m, int DoBPC, int lIsAbsolute) +void EmitPQRStage(LPMEMSTREAM m, cmsHPROFILE hProfile, int DoBPC, int lIsAbsolute) { - Writef(m,"%% Bradford Cone Space\n" - "/MatrixPQR [0.8951 -0.7502 0.0389 0.2664 1.7135 -0.0685 -0.1614 0.0367 1.0296 ] \n"); + if (lIsAbsolute) { - Writef(m, "/RangePQR [ -0.5 2 -0.5 2 -0.5 2 ]\n"); + // For absolute colorimetric intent, encode back to relative + // and generate a relative LUT + // Relative encoding is obtained across XYZpcs*(D50/WhitePoint) - if (lIsAbsolute) { + cmsCIEXYZ White; + + cmsTakeMediaWhitePoint(&White, hProfile); - // For absolute colorimetric intent, do nothing + Writef(m,"/MatrixPQR [1 0 0 0 1 0 0 0 1 ]\n"); + Writef(m,"/RangePQR [ -0.5 2 -0.5 2 -0.5 2 ]\n"); - Writef(m, "%% Absolute colorimetric -- no transformation\n" + Writef(m, "%% Absolute colorimetric -- encode to relative to maximize LUT usage\n" "/TransformPQR [\n" - "{exch pop exch pop exch pop exch pop} bind dup dup]\n"); + "{0.9642 mul %g div exch pop exch pop exch pop exch pop} bind\n" + "{1.0000 mul %g div exch pop exch pop exch pop exch pop} bind\n" + "{0.8249 mul %g div exch pop exch pop exch pop exch pop} bind\n]\n", + White.X, White.Y, White.Z); return; } + Writef(m,"%% Bradford Cone Space\n" + "/MatrixPQR [0.8951 -0.7502 0.0389 0.2664 1.7135 -0.0685 -0.1614 0.0367 1.0296 ] \n"); + + Writef(m, "/RangePQR [ -0.5 2 -0.5 2 -0.5 2 ]\n"); + + // No BPC if (!DoBPC) { @@ -1414,6 +1433,7 @@ void EmitPQRStage(LPMEMSTREAM m, int DoBPC, int lIsAbsolute) static void EmitXYZ2Lab(LPMEMSTREAM m) { + Writef(m, "/RangeLMN [ -0.635 2.0 0 2 -0.635 2.0 ]\n"); Writef(m, "/EncodeLMN [\n"); Writef(m, "{ 0.964200 div dup 0.008856 le {7.787 mul 16 116 div add}{1 3 div exp} ifelse } bind\n"); Writef(m, "{ 1.000000 div dup 0.008856 le {7.787 mul 16 116 div add}{1 3 div exp} ifelse } bind\n"); @@ -1423,18 +1443,11 @@ void EmitXYZ2Lab(LPMEMSTREAM m) Writef(m, "/EncodeABC [\n"); - Writef(m, "{ 116 mul 16 sub 100 div } bind\n"); - Writef(m, "{ 500 mul 128 add 255 div } bind\n"); - Writef(m, "{ 200 mul 128 add 255 div } bind\n"); + Writef(m, "{ 500 mul 128 add 256 div } bind\n"); + Writef(m, "{ 200 mul 128 add 256 div } bind\n"); - /* - Writef(m, "{ 116 mul 16 sub 256 mul 25700 div } bind\n"); - Writef(m, "{ 500 mul 128 add 256 mul 65535 div } bind\n"); - Writef(m, "{ 200 mul 128 add 256 mul 65535 div } bind\n"); - */ - Writef(m, "]\n"); @@ -1458,20 +1471,27 @@ int WriteOutputLUT(LPMEMSTREAM m, cmsHPROFILE hProfile, int Intent, DWORD dwFlag LPLUT DeviceLink; cmsHPROFILE Profiles[3]; cmsCIEXYZ BlackPointAdaptedToD50; - BOOL lFreeDeviceLink = FALSE; - BOOL lDoBPC = (dwFlags & cmsFLAGS_BLACKPOINTCOMPENSATION); + LCMSBOOL lFreeDeviceLink = FALSE; + LCMSBOOL lDoBPC = (dwFlags & cmsFLAGS_BLACKPOINTCOMPENSATION); + LCMSBOOL lFixWhite = !(dwFlags & cmsFLAGS_NOWHITEONWHITEFIXUP); + int RelativeEncodingIntent; - // Trick our v4 profile as it were v2. This prevents the ajusting done - // in perceptual & saturation. We only neew v4 encoding! - hLab = cmsCreateLab4Profile(NULL); - cmsSetProfileICCversion(hLab, 0); + hLab = cmsCreateLabProfile(NULL); ColorSpace = cmsGetColorSpace(hProfile); nChannels = _cmsChannelsOf(ColorSpace); OutputFormat = CHANNELS_SH(nChannels) | BYTES_SH(2); + // For absolute colorimetric, the LUT is encoded as relative + // in order to preserve precission. + + RelativeEncodingIntent = Intent; + if (RelativeEncodingIntent == INTENT_ABSOLUTE_COLORIMETRIC) + RelativeEncodingIntent = INTENT_RELATIVE_COLORIMETRIC; + + // Is a devicelink profile? if (cmsGetDeviceClass(hProfile) == icSigLinkClass) { @@ -1479,13 +1499,14 @@ int WriteOutputLUT(LPMEMSTREAM m, cmsHPROFILE hProfile, int Intent, DWORD dwFlag if (ColorSpace == icSigLabData) { - // adjust input to Lab to out v4 + // adjust input to Lab to our v4 Profiles[0] = hLab; Profiles[1] = hProfile; xform = cmsCreateMultiprofileTransform(Profiles, 2, TYPE_Lab_DBL, - OutputFormat, Intent, cmsFLAGS_NOPRELINEARIZATION); + OutputFormat, RelativeEncodingIntent, + dwFlags|cmsFLAGS_NOWHITEONWHITEFIXUP|cmsFLAGS_NOPRELINEARIZATION); } else { @@ -1499,7 +1520,7 @@ int WriteOutputLUT(LPMEMSTREAM m, cmsHPROFILE hProfile, int Intent, DWORD dwFlag // This is a normal profile xform = cmsCreateTransform(hLab, TYPE_Lab_DBL, hProfile, - OutputFormat, Intent, cmsFLAGS_NOPRELINEARIZATION); + OutputFormat, RelativeEncodingIntent, dwFlags|cmsFLAGS_NOWHITEONWHITEFIXUP|cmsFLAGS_NOPRELINEARIZATION); } if (xform == NULL) { @@ -1515,7 +1536,7 @@ int WriteOutputLUT(LPMEMSTREAM m, cmsHPROFILE hProfile, int Intent, DWORD dwFlag if (!DeviceLink) { - DeviceLink = _cmsPrecalculateDeviceLink(xform, 0); + DeviceLink = _cmsPrecalculateDeviceLink(xform, cmsFLAGS_NOPRELINEARIZATION); lFreeDeviceLink = TRUE; } @@ -1527,7 +1548,7 @@ int WriteOutputLUT(LPMEMSTREAM m, cmsHPROFILE hProfile, int Intent, DWORD dwFlag // Emit headers, etc. EmitWhiteBlackD50(m, &BlackPointAdaptedToD50); - EmitPQRStage(m, lDoBPC, Intent == INTENT_ABSOLUTE_COLORIMETRIC); + EmitPQRStage(m, hProfile, lDoBPC, Intent == INTENT_ABSOLUTE_COLORIMETRIC); EmitXYZ2Lab(m); if (DeviceLink ->wFlags & LUT_HASTL1) { @@ -1544,10 +1565,13 @@ int WriteOutputLUT(LPMEMSTREAM m, cmsHPROFILE hProfile, int Intent, DWORD dwFlag // zero. This would sacrifice a bit of highlights, but failure to do so would cause // scum dot. Ouch. + if (Intent == INTENT_ABSOLUTE_COLORIMETRIC) + lFixWhite = FALSE; + Writef(m, "/RenderTable "); WriteCLUT(m, DeviceLink, 8, "<", ">\n", "", "", FALSE, - (Intent != INTENT_ABSOLUTE_COLORIMETRIC), ColorSpace); + lFixWhite, ColorSpace); Writef(m, " %d {} bind ", nChannels); @@ -1582,6 +1606,9 @@ void BuildColorantList(char *Colorant, int nColorant, WORD Out[]) int j; Colorant[0] = 0; + if (nColorant > MAXCHANNELS) + nColorant = MAXCHANNELS; + for (j=0; j < nColorant; j++) { sprintf(Buff, "%.3f", Out[j] / 65535.0); @@ -1677,7 +1704,7 @@ DWORD LCMSEXPORT cmsGetPostScriptCRDEx(cmsHPROFILE hProfile, if (!WriteNamedColorCRD(mem, hProfile, Intent, dwFlags)) { - free((void*) mem); + _cmsFree((void*) mem); return 0; } } @@ -1687,7 +1714,7 @@ DWORD LCMSEXPORT cmsGetPostScriptCRDEx(cmsHPROFILE hProfile, if (!WriteOutputLUT(mem, hProfile, Intent, dwFlags)) { - free((void*) mem); + _cmsFree((void*) mem); return 0; } } @@ -1702,7 +1729,7 @@ DWORD LCMSEXPORT cmsGetPostScriptCRDEx(cmsHPROFILE hProfile, dwBytesUsed = mem ->dwUsed; // Get rid of memory stream - free((void*) mem); + _cmsFree((void*) mem); // Finally, return used byte count return dwBytesUsed; diff --git a/src/share/native/sun/java2d/cmm/lcms/cmssamp.c b/src/share/native/sun/java2d/cmm/lcms/cmssamp.c index 023a732dfeb90ebc8985075e4091af9cf4aa6cc1..2b52b2daf88b22297d51a95e05350a0ca0d7c2d6 100644 --- a/src/share/native/sun/java2d/cmm/lcms/cmssamp.c +++ b/src/share/native/sun/java2d/cmm/lcms/cmssamp.c @@ -29,7 +29,7 @@ // // // Little cms -// Copyright (C) 1998-2006 Marti Maria +// Copyright (C) 1998-2007 Marti Maria // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the "Software"), @@ -120,7 +120,7 @@ int ComponentOf(int n, int clut, int nColorant) // This routine does a sweep on whole input space, and calls its callback // function on knots. returns TRUE if all ok, FALSE otherwise. -BOOL LCMSEXPORT cmsSample3DGrid(LPLUT Lut, _cmsSAMPLER Sampler, LPVOID Cargo, DWORD dwFlags) +LCMSBOOL LCMSEXPORT cmsSample3DGrid(LPLUT Lut, _cmsSAMPLER Sampler, LPVOID Cargo, DWORD dwFlags) { int i, t, nTotalPoints, Colorant, index; WORD In[MAXCHANNELS], Out[MAXCHANNELS]; @@ -145,12 +145,16 @@ BOOL LCMSEXPORT cmsSample3DGrid(LPLUT Lut, _cmsSAMPLER Sampler, LPVOID Cargo, DW &Lut -> In16params); } + for (t=0; t < (int) Lut -> OutputChan; t++) + Out[t] = Lut->T[index + t]; - // if (dwFlags & SAMPLER_INSPECT) { + if (dwFlags & SAMPLER_HASTL2) { for (t=0; t < (int) Lut -> OutputChan; t++) - Out[t] = Lut->T[index + t]; - // } + Out[t] = cmsLinearInterpLUT16(Out[t], + Lut -> L2[t], + &Lut -> Out16params); + } if (!Sampler(In, Out, Cargo)) @@ -255,9 +259,11 @@ LPLUT _cmsPrecalculateDeviceLink(cmsHTRANSFORM h, DWORD dwFlags) LPLUT Grid; int nGridPoints; DWORD dwFormatIn, dwFormatOut; + DWORD SaveFormatIn, SaveFormatOut; int ChannelsIn, ChannelsOut; LPLUT SaveGamutLUT; + // Remove any gamut checking SaveGamutLUT = p ->Gamut; p ->Gamut = NULL; @@ -276,8 +282,13 @@ LPLUT _cmsPrecalculateDeviceLink(cmsHTRANSFORM h, DWORD dwFlags) dwFormatIn = (CHANNELS_SH(ChannelsIn)|BYTES_SH(2)); dwFormatOut = (CHANNELS_SH(ChannelsOut)|BYTES_SH(2)); - p -> FromInput = _cmsIdentifyInputFormat(p, dwFormatIn); - p -> ToOutput = _cmsIdentifyOutputFormat(p, dwFormatOut); + SaveFormatIn = p ->InputFormat; + SaveFormatOut = p ->OutputFormat; + + p -> InputFormat = dwFormatIn; + p -> OutputFormat = dwFormatOut; + p -> FromInput = _cmsIdentifyInputFormat(p, dwFormatIn); + p -> ToOutput = _cmsIdentifyOutputFormat(p, dwFormatOut); // Fix gamut & gamma possible mismatches. @@ -289,7 +300,6 @@ LPLUT _cmsPrecalculateDeviceLink(cmsHTRANSFORM h, DWORD dwFlags) _cmsComputePrelinearizationTablesFromXFORM(hOne, 1, Grid); } - // Attention to this typecast! we can take the luxury to // do this since cmsHTRANSFORM is only an alias to a pointer // to the transform struct. @@ -297,11 +307,13 @@ LPLUT _cmsPrecalculateDeviceLink(cmsHTRANSFORM h, DWORD dwFlags) if (!cmsSample3DGrid(Grid, XFormSampler, (LPVOID) p, Grid -> wFlags)) { cmsFreeLUT(Grid); - return NULL; + Grid = NULL; } + p ->Gamut = SaveGamutLUT; + p ->InputFormat = SaveFormatIn; + p ->OutputFormat = SaveFormatOut; - p ->Gamut = SaveGamutLUT; return Grid; } @@ -348,7 +360,7 @@ int BlackPreservingGrayOnlySampler(register WORD In[], register WORD Out[], regi -// That is our K-preserving callback. +// Preserve all K plane. static int BlackPreservingSampler(register WORD In[], register WORD Out[], register LPVOID Cargo) { @@ -469,6 +481,7 @@ int LCMSEXPORT cmsSetCMYKPreservationStrategy(int n) return OldVal; } +#pragma warning(disable: 4550) // Get a pointer to callback on depending of strategy static @@ -504,11 +517,10 @@ LPLUT _cmsPrecalculateBlackPreservingDeviceLink(cmsHTRANSFORM hCMYK2CMYK, DWORD if (p -> dwOriginalFlags & cmsFLAGS_BLACKPOINTCOMPENSATION) LocalFlags |= cmsFLAGS_BLACKPOINTCOMPENSATION; - // Fill in cargo struct Cargo.cmyk2cmyk = hCMYK2CMYK; - // Compute tone curve + // Compute tone curve. Cargo.KTone = _cmsBuildKToneCurve(hCMYK2CMYK, 256); if (Cargo.KTone == NULL) return NULL; cmsCalcL16Params(Cargo.KTone ->nEntries, &Cargo.KToneParams); @@ -522,11 +534,11 @@ LPLUT _cmsPrecalculateBlackPreservingDeviceLink(cmsHTRANSFORM hCMYK2CMYK, DWORD Cargo.LabK2cmyk = cmsReadICCLut(p->OutputProfile, Device2PCS[p->Intent]); // Is there any table available? - if (Cargo.LabK2cmyk == NULL) { + if (Cargo.LabK2cmyk == NULL) { - Grid = NULL; + Grid = NULL; goto Cleanup; - } + } // Setup a roundtrip on output profile for TAC estimation Cargo.hRoundTrip = cmsCreateTransform(p ->OutputProfile, TYPE_CMYK_16, @@ -654,7 +666,7 @@ void PatchLUT(LPLUT Grid, WORD At[], WORD Value[], -BOOL _cmsFixWhiteMisalignment(_LPcmsTRANSFORM p) +LCMSBOOL _cmsFixWhiteMisalignment(_LPcmsTRANSFORM p) { WORD *WhitePointIn, *WhitePointOut, *BlackPointIn, *BlackPointOut; @@ -682,3 +694,4 @@ BOOL _cmsFixWhiteMisalignment(_LPcmsTRANSFORM p) return TRUE; } + diff --git a/src/share/native/sun/java2d/cmm/lcms/cmsvirt.c b/src/share/native/sun/java2d/cmm/lcms/cmsvirt.c index cd128dab6a4c89f16d1f78aa4ce438365dac1ba7..9c3afc451dd706521818060bad34fb69b86d21cf 100644 --- a/src/share/native/sun/java2d/cmm/lcms/cmsvirt.c +++ b/src/share/native/sun/java2d/cmm/lcms/cmsvirt.c @@ -29,7 +29,7 @@ // // // Little cms -// Copyright (C) 1998-2006 Marti Maria +// Copyright (C) 1998-2007 Marti Maria // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the "Software"), @@ -320,7 +320,7 @@ cmsHPROFILE LCMSEXPORT cmsTransform2DeviceLink(cmsHTRANSFORM hTransform, DWORD d cmsHPROFILE hICC; _LPcmsTRANSFORM v = (_LPcmsTRANSFORM) hTransform; LPLUT Lut; - BOOL MustFreeLUT; + LCMSBOOL MustFreeLUT; LPcmsNAMEDCOLORLIST InputColorant = NULL; LPcmsNAMEDCOLORLIST OutputColorant = NULL; @@ -373,10 +373,8 @@ cmsHPROFILE LCMSEXPORT cmsTransform2DeviceLink(cmsHTRANSFORM hTransform, DWORD d if (cmsGetDeviceClass(hICC) == icSigOutputClass) { - cmsAddTag(hICC, icSigBToA0Tag, (LPVOID) Lut); } - else cmsAddTag(hICC, icSigAToB0Tag, (LPVOID) Lut); @@ -404,7 +402,7 @@ cmsHPROFILE LCMSEXPORT cmsTransform2DeviceLink(cmsHTRANSFORM hTransform, DWORD d OutputColorant = cmsReadColorantTable(v ->OutputProfile, icSigColorantTableTag); } - } + } if (InputColorant) cmsAddTag(hICC, icSigColorantTableTag, InputColorant); @@ -446,6 +444,7 @@ cmsHPROFILE LCMSEXPORT cmsCreateLinearizationDeviceLink(icColorSpaceSignature Co // Creates a LUT with prelinearization step only Lut = cmsAllocLUT(); + if (Lut == NULL) return NULL; // Set up channels Lut ->InputChan = Lut ->OutputChan = _cmsChannelsOf(ColorSpace); @@ -548,6 +547,10 @@ cmsHPROFILE LCMSEXPORT cmsCreateInkLimitingDeviceLink(icColorSpaceSignature Colo // Creates a LUT with 3D grid only Lut = cmsAllocLUT(); + if (Lut == NULL) { + cmsCloseProfile(hICC); + return NULL; + } cmsAlloc3DGrid(Lut, 17, _cmsChannelsOf(ColorSpace), @@ -584,8 +587,9 @@ static LPLUT Create3x3EmptyLUT(void) { LPLUT AToB0 = cmsAllocLUT(); - AToB0 -> InputChan = AToB0 -> OutputChan = 3; + if (AToB0 == NULL) return NULL; + AToB0 -> InputChan = AToB0 -> OutputChan = 3; return AToB0; } @@ -597,8 +601,8 @@ cmsHPROFILE LCMSEXPORT cmsCreateLabProfile(LPcmsCIExyY WhitePoint) cmsHPROFILE hProfile; LPLUT Lut; - hProfile = cmsCreateRGBProfile(WhitePoint == NULL ? cmsD50_xyY() : WhitePoint, NULL, NULL); + if (hProfile == NULL) return NULL; cmsSetDeviceClass(hProfile, icSigAbstractClass); cmsSetColorSpace(hProfile, icSigLabData); @@ -611,7 +615,10 @@ cmsHPROFILE LCMSEXPORT cmsCreateLabProfile(LPcmsCIExyY WhitePoint) // An empty LUTs is all we need Lut = Create3x3EmptyLUT(); - if (Lut == NULL) return NULL; + if (Lut == NULL) { + cmsCloseProfile(hProfile); + return NULL; + } cmsAddTag(hProfile, icSigAToB0Tag, (LPVOID) Lut); cmsAddTag(hProfile, icSigBToA0Tag, (LPVOID) Lut); @@ -628,8 +635,8 @@ cmsHPROFILE LCMSEXPORT cmsCreateLab4Profile(LPcmsCIExyY WhitePoint) cmsHPROFILE hProfile; LPLUT Lut; - hProfile = cmsCreateRGBProfile(WhitePoint == NULL ? cmsD50_xyY() : WhitePoint, NULL, NULL); + if (hProfile == NULL) return NULL; cmsSetProfileICCversion(hProfile, 0x4000000); @@ -644,7 +651,10 @@ cmsHPROFILE LCMSEXPORT cmsCreateLab4Profile(LPcmsCIExyY WhitePoint) // An empty LUTs is all we need Lut = Create3x3EmptyLUT(); - if (Lut == NULL) return NULL; + if (Lut == NULL) { + cmsCloseProfile(hProfile); + return NULL; + } Lut -> wFlags |= LUT_V4_INPUT_EMULATE_V2; cmsAddTag(hProfile, icSigAToB0Tag, (LPVOID) Lut); @@ -666,6 +676,7 @@ cmsHPROFILE LCMSEXPORT cmsCreateXYZProfile(void) LPLUT Lut; hProfile = cmsCreateRGBProfile(cmsD50_xyY(), NULL, NULL); + if (hProfile == NULL) return NULL; cmsSetDeviceClass(hProfile, icSigAbstractClass); cmsSetColorSpace(hProfile, icSigXYZData); @@ -677,15 +688,16 @@ cmsHPROFILE LCMSEXPORT cmsCreateXYZProfile(void) // An empty LUTs is all we need Lut = Create3x3EmptyLUT(); - if (Lut == NULL) return NULL; + if (Lut == NULL) { + cmsCloseProfile(hProfile); + return NULL; + } cmsAddTag(hProfile, icSigAToB0Tag, (LPVOID) Lut); cmsAddTag(hProfile, icSigBToA0Tag, (LPVOID) Lut); cmsAddTag(hProfile, icSigPreview0Tag, (LPVOID) Lut); cmsFreeLUT(Lut); - - return hProfile; } @@ -723,6 +735,7 @@ LPGAMMATABLE Build_sRGBGamma(void) return cmsBuildParametricGamma(1024, 4, Parameters); } +// Create the ICC virtual profile for sRGB space cmsHPROFILE LCMSEXPORT cmsCreate_sRGBProfile(void) { cmsCIExyY D65; @@ -739,6 +752,7 @@ cmsHPROFILE LCMSEXPORT cmsCreate_sRGBProfile(void) hsRGB = cmsCreateRGBProfile(&D65, &Rec709Primaries, Gamma22); cmsFreeGamma(Gamma22[0]); + if (hsRGB == NULL) return NULL; cmsAddTag(hsRGB, icSigDeviceMfgDescTag, (LPVOID) "(lcms internal)"); @@ -750,7 +764,6 @@ cmsHPROFILE LCMSEXPORT cmsCreate_sRGBProfile(void) - typedef struct { double Brightness; double Contrast; @@ -793,7 +806,6 @@ int bchswSampler(register WORD In[], register WORD Out[], register LPVOID Cargo) cmsFloat2LabEncoded(Out, &LabOut); - return TRUE; } @@ -839,7 +851,10 @@ cmsHPROFILE LCMSEXPORT cmsCreateBCHSWabstractProfile(int nLUTPoints, // Creates a LUT with 3D grid only Lut = cmsAllocLUT(); - + if (Lut == NULL) { + cmsCloseProfile(hICC); + return NULL; + } cmsAlloc3DGrid(Lut, nLUTPoints, 3, 3); @@ -890,7 +905,10 @@ cmsHPROFILE LCMSEXPORT cmsCreateNULLProfile(void) // An empty LUTs is all we need Lut = cmsAllocLUT(); - if (Lut == NULL) return NULL; + if (Lut == NULL) { + cmsCloseProfile(hProfile); + return NULL; + } Lut -> InputChan = 3; Lut -> OutputChan = 1; diff --git a/src/share/native/sun/java2d/cmm/lcms/cmswtpnt.c b/src/share/native/sun/java2d/cmm/lcms/cmswtpnt.c index 3f3beb76665da77088a0d67f9371e4ceba23370f..b7e38844de1d191f6aa82c70bd9185ce97856bd7 100644 --- a/src/share/native/sun/java2d/cmm/lcms/cmswtpnt.c +++ b/src/share/native/sun/java2d/cmm/lcms/cmswtpnt.c @@ -29,7 +29,7 @@ // // // Little cms -// Copyright (C) 1998-2006 Marti Maria +// Copyright (C) 1998-2007 Marti Maria // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the "Software"), @@ -51,10 +51,6 @@ #include "lcms.h" -// Uncomment this line if you want lcms to use the black point tag in profile, -// if commented, lcms will compute the black point by its own. -// It is safer to leve it commented out -// #define HONOR_BLACK_POINT_TAG // Conversions @@ -79,10 +75,9 @@ void LCMSEXPORT cmsxyY2XYZ(LPcmsCIEXYZ Dest, const cmsCIExyY* Source) } - // Obtains WhitePoint from Temperature -BOOL LCMSEXPORT cmsWhitePointFromTemp(int TempK, LPcmsCIExyY WhitePoint) +LCMSBOOL LCMSEXPORT cmsWhitePointFromTemp(int TempK, LPcmsCIExyY WhitePoint) { double x, y; double T, T2, T3; @@ -147,7 +142,7 @@ BOOL LCMSEXPORT cmsWhitePointFromTemp(int TempK, LPcmsCIExyY WhitePoint) // - Then, I apply these coeficients to the original matrix -BOOL LCMSEXPORT cmsBuildRGB2XYZtransferMatrix(LPMAT3 r, LPcmsCIExyY WhitePt, +LCMSBOOL LCMSEXPORT cmsBuildRGB2XYZtransferMatrix(LPMAT3 r, LPcmsCIExyY WhitePt, LPcmsCIExyYTRIPLE Primrs) { VEC3 WhitePoint, Coef; @@ -169,14 +164,12 @@ BOOL LCMSEXPORT cmsBuildRGB2XYZtransferMatrix(LPMAT3 r, LPcmsCIExyY WhitePt, // Build Primaries matrix - VEC3init(&Primaries.v[0], xr, xg, xb); VEC3init(&Primaries.v[1], yr, yg, yb); VEC3init(&Primaries.v[2], (1-xr-yr), (1-xg-yg), (1-xb-yb)); // Result = Primaries ^ (-1) inverse matrix - if (!MAT3inverse(&Primaries, &Result)) return FALSE; @@ -184,11 +177,9 @@ BOOL LCMSEXPORT cmsBuildRGB2XYZtransferMatrix(LPMAT3 r, LPcmsCIExyY WhitePt, VEC3init(&WhitePoint, xn/yn, 1.0, (1.0-xn-yn)/yn); // Across inverse primaries ... - MAT3eval(&Coef, &Result, &WhitePoint); // Give us the Coefs, then I build transformation matrix - VEC3init(&r -> v[0], Coef.n[VX]*xr, Coef.n[VY]*xg, Coef.n[VZ]*xb); VEC3init(&r -> v[1], Coef.n[VX]*yr, Coef.n[VY]*yg, Coef.n[VZ]*yb); VEC3init(&r -> v[2], Coef.n[VX]*(1.0-xr-yr), Coef.n[VY]*(1.0-xg-yg), Coef.n[VZ]*(1.0-xb-yb)); @@ -246,7 +237,7 @@ void ComputeChromaticAdaptation(LPMAT3 Conversion, // Returns the final chrmatic adaptation from illuminant FromIll to Illuminant ToIll // The cone matrix can be specified in ConeMatrix. If NULL, Bradford is assumed -BOOL cmsAdaptationMatrix(LPMAT3 r, LPMAT3 ConeMatrix, LPcmsCIEXYZ FromIll, LPcmsCIEXYZ ToIll) +LCMSBOOL cmsAdaptationMatrix(LPMAT3 r, LPMAT3 ConeMatrix, LPcmsCIEXYZ FromIll, LPcmsCIEXYZ ToIll) { MAT3 LamRigg = {{ // Bradford matrix {{ 0.8951, 0.2664, -0.1614 }}, @@ -265,7 +256,7 @@ BOOL cmsAdaptationMatrix(LPMAT3 r, LPMAT3 ConeMatrix, LPcmsCIEXYZ FromIll, LPcms // Same as anterior, but assuming D50 destination. White point is given in xyY -BOOL cmsAdaptMatrixToD50(LPMAT3 r, LPcmsCIExyY SourceWhitePt) +LCMSBOOL cmsAdaptMatrixToD50(LPMAT3 r, LPcmsCIExyY SourceWhitePt) { cmsCIEXYZ Dn; MAT3 Bradford; @@ -284,7 +275,7 @@ BOOL cmsAdaptMatrixToD50(LPMAT3 r, LPcmsCIExyY SourceWhitePt) // Same as anterior, but assuming D50 source. White point is given in xyY -BOOL cmsAdaptMatrixFromD50(LPMAT3 r, LPcmsCIExyY DestWhitePt) +LCMSBOOL cmsAdaptMatrixFromD50(LPMAT3 r, LPcmsCIExyY DestWhitePt) { cmsCIEXYZ Dn; MAT3 Bradford; @@ -304,7 +295,7 @@ BOOL cmsAdaptMatrixFromD50(LPMAT3 r, LPcmsCIExyY DestWhitePt) // Adapts a color to a given illuminant. Original color is expected to have // a SourceWhitePt white point. -BOOL LCMSEXPORT cmsAdaptToIlluminant(LPcmsCIEXYZ Result, +LCMSBOOL LCMSEXPORT cmsAdaptToIlluminant(LPcmsCIEXYZ Result, LPcmsCIEXYZ SourceWhitePt, LPcmsCIEXYZ Illuminant, LPcmsCIEXYZ Value) @@ -404,8 +395,6 @@ double Robertson(LPcmsCIExyY v) dj = ((vs - vj) - tj * (us - uj)) / sqrt(1 + tj*tj); - - if ((j!=0) && (di/dj < 0.0)) { Tc = 1000000.0 / (mi + (di / (di - dj)) * (mj - mi)); break; @@ -423,7 +412,7 @@ double Robertson(LPcmsCIExyY v) static -BOOL InRange(LPcmsCIExyY a, LPcmsCIExyY b, double tolerance) +LCMSBOOL InRange(LPcmsCIExyY a, LPcmsCIExyY b, double tolerance) { double dist_x, dist_y; @@ -458,6 +447,7 @@ int FromD40toD150(LPWHITEPOINTS pts) } +// To be removed in future versions void _cmsIdentifyWhitePoint(char *Buffer, LPcmsCIEXYZ WhitePt) { int i, n; @@ -518,7 +508,6 @@ int BlackPointAsDarkerColorant(cmsHPROFILE hInput, cmsCIEXYZ BlackXYZ, MediaWhite; // If the profile does not support input direction, assume Black point 0 - if (!cmsIsIntentSupported(hInput, Intent, LCMS_USED_AS_INPUT)) { BlackPoint -> X = BlackPoint ->Y = BlackPoint -> Z = 0.0; @@ -527,7 +516,6 @@ int BlackPointAsDarkerColorant(cmsHPROFILE hInput, // Try to get black by using black colorant - Space = cmsGetColorSpace(hInput); if (!_cmsEndPointsBySpace(Space, &White, &Black, &nChannels)) { @@ -576,7 +564,7 @@ int BlackPointAsDarkerColorant(cmsHPROFILE hInput, // Get a black point of output CMYK profile, discounting any ink-limiting embedded -// in the profile. Fou doing that, use perceptual intent in input direction: +// in the profile. For doing that, use perceptual intent in input direction: // Lab (0, 0, 0) -> [Perceptual] Profile -> CMYK -> [Rel. colorimetric] Profile -> Lab static @@ -651,6 +639,8 @@ int GetV4PerceptualBlack(LPcmsCIEXYZ BlackPoint, cmsHPROFILE hProfile, DWORD dwF D50BlackPoint.X = PERCEPTUAL_BLACK_X; D50BlackPoint.Y = PERCEPTUAL_BLACK_Y; D50BlackPoint.Z = PERCEPTUAL_BLACK_Z; + + // Obtain the absolute XYZ. Adapt perceptual black back from D50 to whatever media white cmsAdaptToIlluminant(BlackPoint, cmsD50_XYZ(), &MediaWhite, &D50BlackPoint); } @@ -662,26 +652,24 @@ int GetV4PerceptualBlack(LPcmsCIEXYZ BlackPoint, cmsHPROFILE hProfile, DWORD dwF // This function shouldn't exist at all -- there is such quantity of broken // profiles on black point tag, that we must somehow fix chromaticity to // avoid huge tint when doing Black point compensation. This function does -// just that. If BP is specified, then forces it to neutral and uses only L -// component. If does not exist, computes it by taking 400% of ink or RGB=0 This -// works well on relative intent and is undefined on perceptual & saturation. -// However, I will support all intents for tricking & trapping. - +// just that. There is a special flag for using black point tag, but turned +// off by default because it is bogus on most profiles. The detection algorithm +// involves to turn BP to neutral and to use only L component. int cmsDetectBlackPoint(LPcmsCIEXYZ BlackPoint, cmsHPROFILE hProfile, int Intent, DWORD dwFlags) { - // v4 + perceptual & saturation intents does have its own black point + // v4 + perceptual & saturation intents does have its own black point, and it is + // well specified enough to use it. if ((cmsGetProfileICCversion(hProfile) >= 0x4000000) && (Intent == INTENT_PERCEPTUAL || Intent == INTENT_SATURATION)) { // Matrix shaper share MRC & perceptual intents - if (_cmsIsMatrixShaper(hProfile)) return BlackPointAsDarkerColorant(hProfile, INTENT_RELATIVE_COLORIMETRIC, BlackPoint, cmsFLAGS_NOTPRECALC); - // Get fixed value + // CLUT based - Get perceptual black point (fixed value) return GetV4PerceptualBlack(BlackPoint, hProfile, dwFlags); } @@ -701,7 +689,6 @@ int cmsDetectBlackPoint(LPcmsCIEXYZ BlackPoint, cmsHPROFILE hProfile, int Intent cmsTakeMediaWhitePoint(&MediaWhite, hProfile); // Black point is absolute XYZ, so adapt to D50 to get PCS value - cmsAdaptToIlluminant(&UntrustedBlackPoint, &MediaWhite, cmsD50_XYZ(), &BlackXYZ); // Force a=b=0 to get rid of any chroma @@ -713,7 +700,6 @@ int cmsDetectBlackPoint(LPcmsCIEXYZ BlackPoint, cmsHPROFILE hProfile, int Intent cmsLab2XYZ(NULL, &TrustedBlackPoint, &Lab); // Return BP as D50 relative or absolute XYZ (depends on flags) - if (!(dwFlags & LCMS_BPFLAGS_D50_ADAPTED)) cmsAdaptToIlluminant(BlackPoint, cmsD50_XYZ(), &MediaWhite, &TrustedBlackPoint); else @@ -724,15 +710,15 @@ int cmsDetectBlackPoint(LPcmsCIEXYZ BlackPoint, cmsHPROFILE hProfile, int Intent #endif - // If output profile, discount ink-limiting + // That is about v2 profiles. + // If output profile, discount ink-limiting and that's all if (Intent == INTENT_RELATIVE_COLORIMETRIC && (cmsGetDeviceClass(hProfile) == icSigOutputClass) && (cmsGetColorSpace(hProfile) == icSigCmykData)) return BlackPointUsingPerceptualBlack(BlackPoint, hProfile, dwFlags); // Nope, compute BP using current intent. - return BlackPointAsDarkerColorant(hProfile, Intent, BlackPoint, dwFlags); } diff --git a/src/share/native/sun/java2d/cmm/lcms/cmsxform.c b/src/share/native/sun/java2d/cmm/lcms/cmsxform.c index 8b82f26c5f22e49d8417f7c144911621d9a0e891..ec37bebb1e3c76e8a36bc2f357ebeda392ec9aab 100644 --- a/src/share/native/sun/java2d/cmm/lcms/cmsxform.c +++ b/src/share/native/sun/java2d/cmm/lcms/cmsxform.c @@ -29,7 +29,7 @@ // // // Little cms -// Copyright (C) 1998-2006 Marti Maria +// Copyright (C) 1998-2007 Marti Maria // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the "Software"), @@ -52,7 +52,6 @@ #include "lcms.h" -// #define DEBUG 1 // Transformations stuff // ----------------------------------------------------------------------- @@ -85,7 +84,7 @@ void LCMSEXPORT cmsDoTransform(cmsHTRANSFORM Transform, void LCMSEXPORT cmsGetAlarmCodes(int *r, int *g, int *b); void LCMSEXPORT cmsSetAlarmCodes(int r, int g, int b); -BOOL LCMSEXPORT cmsIsIntentSupported(cmsHPROFILE hProfile, +LCMSBOOL LCMSEXPORT cmsIsIntentSupported(cmsHPROFILE hProfile, int Intent, int UsedDirection); // ------------------------------------------------------------------------- @@ -343,7 +342,7 @@ void PrecalculatedXFORM(_LPcmsTRANSFORM p, p ->DeviceLink ->CLut16params.Interp3D(wIn, wOut, p ->DeviceLink -> T, &p ->DeviceLink -> CLut16params); - } + } else cmsEvalLUT(p -> DeviceLink, wIn, wOut); @@ -414,7 +413,7 @@ void CachedXFORM(_LPcmsTRANSFORM p, register LPBYTE output; WORD wIn[MAXCHANNELS], wOut[MAXCHANNELS]; register unsigned int i, n; - WORD CacheIn[MAXCHANNELS], CacheOut[MAXCHANNELS]; + WORD CacheIn[MAXCHANNELS], CacheOut[MAXCHANNELS]; accum = (LPBYTE) in; @@ -427,10 +426,10 @@ void CachedXFORM(_LPcmsTRANSFORM p, ZeroMemory(wOut, sizeof(WORD) * MAXCHANNELS); - LCMS_READ_LOCK(&p ->rwlock); - CopyMemory(CacheIn, p ->CacheIn, sizeof(WORD) * MAXCHANNELS); - CopyMemory(CacheOut, p ->CacheOut, sizeof(WORD) * MAXCHANNELS); - LCMS_UNLOCK(&p ->rwlock); + LCMS_READ_LOCK(&p ->rwlock); + CopyMemory(CacheIn, p ->CacheIn, sizeof(WORD) * MAXCHANNELS); + CopyMemory(CacheOut, p ->CacheOut, sizeof(WORD) * MAXCHANNELS); + LCMS_UNLOCK(&p ->rwlock); for (i=0; i < n; i++) { @@ -443,14 +442,14 @@ void CachedXFORM(_LPcmsTRANSFORM p, } else { - // Try to speedup things on plain devicelinks + // Try to speedup things on plain devicelinks - if (p ->DeviceLink ->wFlags == LUT_HAS3DGRID) { + if (p ->DeviceLink ->wFlags == LUT_HAS3DGRID) { p ->DeviceLink ->CLut16params.Interp3D(wIn, wOut, p ->DeviceLink -> T, &p ->DeviceLink -> CLut16params); - } + } else cmsEvalLUT(p -> DeviceLink, wIn, wOut); @@ -463,10 +462,10 @@ void CachedXFORM(_LPcmsTRANSFORM p, } - LCMS_WRITE_LOCK(&p ->rwlock); - CopyMemory(p->CacheIn, CacheIn, sizeof(WORD) * MAXCHANNELS); - CopyMemory(p->CacheOut, CacheOut, sizeof(WORD) * MAXCHANNELS); - LCMS_UNLOCK(&p ->rwlock); + LCMS_WRITE_LOCK(&p ->rwlock); + CopyMemory(p->CacheIn, CacheIn, sizeof(WORD) * MAXCHANNELS); + CopyMemory(p->CacheOut, CacheOut, sizeof(WORD) * MAXCHANNELS); + LCMS_UNLOCK(&p ->rwlock); } @@ -483,7 +482,7 @@ void CachedXFORMGamutCheck(_LPcmsTRANSFORM p, register LPBYTE output; WORD wIn[MAXCHANNELS], wOut[MAXCHANNELS]; register unsigned int i, n; - WORD CacheIn[MAXCHANNELS], CacheOut[MAXCHANNELS]; + WORD CacheIn[MAXCHANNELS], CacheOut[MAXCHANNELS]; accum = (LPBYTE) in; @@ -495,10 +494,10 @@ void CachedXFORMGamutCheck(_LPcmsTRANSFORM p, ZeroMemory(wIn, sizeof(WORD) * MAXCHANNELS); ZeroMemory(wOut, sizeof(WORD) * MAXCHANNELS); - LCMS_READ_LOCK(&p ->rwlock); - CopyMemory(CacheIn, p ->CacheIn, sizeof(WORD) * MAXCHANNELS); - CopyMemory(CacheOut, p ->CacheOut, sizeof(WORD) * MAXCHANNELS); - LCMS_UNLOCK(&p ->rwlock); + LCMS_READ_LOCK(&p ->rwlock); + CopyMemory(CacheIn, p ->CacheIn, sizeof(WORD) * MAXCHANNELS); + CopyMemory(CacheOut, p ->CacheOut, sizeof(WORD) * MAXCHANNELS); + LCMS_UNLOCK(&p ->rwlock); for (i=0; i < n; i++) { @@ -520,10 +519,10 @@ void CachedXFORMGamutCheck(_LPcmsTRANSFORM p, output = p -> ToOutput(p, wOut, output); } - LCMS_WRITE_LOCK(&p ->rwlock); - CopyMemory(p->CacheIn, CacheIn, sizeof(WORD) * MAXCHANNELS); - CopyMemory(p->CacheOut, CacheOut, sizeof(WORD) * MAXCHANNELS); - LCMS_UNLOCK(&p ->rwlock); + LCMS_WRITE_LOCK(&p ->rwlock); + CopyMemory(p->CacheIn, CacheIn, sizeof(WORD) * MAXCHANNELS); + CopyMemory(p->CacheOut, CacheOut, sizeof(WORD) * MAXCHANNELS); + LCMS_UNLOCK(&p ->rwlock); } @@ -635,6 +634,8 @@ LPMATSHAPER cmsBuildGrayInputMatrixShaper(cmsHPROFILE hProfile) MAT3 Scale; GrayTRC = cmsReadICCGamma(hProfile, icSigGrayTRCTag); // Y + if (GrayTRC == NULL) return NULL; + cmsTakeIluminant(&Illuminant, hProfile); if (cmsGetPCS(hProfile) == icSigLabData) { @@ -789,6 +790,10 @@ LPMATSHAPER cmsBuildOutputMatrixShaper(cmsHPROFILE OutputProfile) InverseShapes[1] = cmsReadICCGammaReversed(OutputProfile, icSigGreenTRCTag); InverseShapes[2] = cmsReadICCGammaReversed(OutputProfile, icSigBlueTRCTag); + if (InverseShapes[0] == NULL || + InverseShapes[1] == NULL || + InverseShapes[2] == NULL) return NULL; + OutMatSh = cmsAllocMatShaper(&DoubleInv, InverseShapes, MATSHAPER_OUTPUT); cmsFreeGammaTriple(InverseShapes); @@ -801,7 +806,7 @@ LPMATSHAPER cmsBuildOutputMatrixShaper(cmsHPROFILE OutputProfile) // This function builds a transform matrix chaining parameters static -BOOL cmsBuildSmeltMatShaper(_LPcmsTRANSFORM p) +LCMSBOOL cmsBuildSmeltMatShaper(_LPcmsTRANSFORM p) { MAT3 From, To, ToInv, Transfer; LPGAMMATABLE In[3], InverseOut[3]; @@ -814,7 +819,6 @@ BOOL cmsBuildSmeltMatShaper(_LPcmsTRANSFORM p) if (!cmsReadICCMatrixRGB2XYZ(&To, p -> OutputProfile)) return FALSE; - // invert dest if (MAT3inverse(&To, &ToInv) < 0) @@ -838,10 +842,14 @@ BOOL cmsBuildSmeltMatShaper(_LPcmsTRANSFORM p) InverseOut[1] = cmsReadICCGammaReversed(p -> OutputProfile, icSigGreenTRCTag); InverseOut[2] = cmsReadICCGammaReversed(p -> OutputProfile, icSigBlueTRCTag); + if (!InverseOut[0] || !InverseOut[1] || !InverseOut[2]) { + cmsFreeGammaTriple(In); + return FALSE; + } + p -> SmeltMatShaper = cmsAllocMatShaper2(&Transfer, In, InverseOut, MATSHAPER_ALLSMELTED); cmsFreeGammaTriple(In); - cmsFreeGammaTriple(InverseOut); return (p -> SmeltMatShaper != NULL); @@ -1029,7 +1037,7 @@ void TakeConversionRoutines(_LPcmsTRANSFORM p, int DoBPC) // Check colorspace static -BOOL IsProperColorSpace(cmsHPROFILE hProfile, DWORD dwFormat, BOOL lUsePCS) +LCMSBOOL IsProperColorSpace(cmsHPROFILE hProfile, DWORD dwFormat, LCMSBOOL lUsePCS) { int Space = T_COLORSPACE(dwFormat); @@ -1049,10 +1057,10 @@ _LPcmsTRANSFORM AllocEmptyTransform(void) { // Allocate needed memory - _LPcmsTRANSFORM p = (_LPcmsTRANSFORM) malloc(sizeof(_cmsTRANSFORM)); + _LPcmsTRANSFORM p = (_LPcmsTRANSFORM) _cmsMalloc(sizeof(_cmsTRANSFORM)); if (!p) { - cmsSignalError(LCMS_ERRC_ABORTED, "cmsCreateTransform: malloc() failed"); + cmsSignalError(LCMS_ERRC_ABORTED, "cmsCreateTransform: _cmsMalloc() failed"); return NULL; } @@ -1078,7 +1086,7 @@ _LPcmsTRANSFORM AllocEmptyTransform(void) p -> ExitColorSpace = (icColorSpaceSignature) 0; p -> AdaptationState = GlobalAdaptationState; - LCMS_CREATE_LOCK(&p->rwlock); + LCMS_CREATE_LOCK(&p->rwlock); return p; } @@ -1269,12 +1277,12 @@ _LPcmsTRANSFORM PickTransformRoutine(_LPcmsTRANSFORM p, else { // Can we optimize matrix-shaper only transform? - if (*FromTagPtr == 0 && - *ToTagPtr == 0 && - !p->PreviewProfile && - p -> Intent != INTENT_ABSOLUTE_COLORIMETRIC && + if ((*FromTagPtr == 0) && + (*ToTagPtr == 0) && + (!p->PreviewProfile) && + (p -> Intent != INTENT_ABSOLUTE_COLORIMETRIC) && (p -> EntryColorSpace == icSigRgbData) && - (p -> ExitColorSpace == icSigRgbData) && + (p -> ExitColorSpace == icSigRgbData) && !(p -> dwOriginalFlags & cmsFLAGS_BLACKPOINTCOMPENSATION)) { // Yes... try to smelt matrix-shapers @@ -1530,7 +1538,6 @@ cmsHTRANSFORM LCMSEXPORT cmsCreateProofingTransform(cmsHPROFILE InputProfile, TakeConversionRoutines(p, dwFlags & cmsFLAGS_BLACKPOINTCOMPENSATION); - if (!(p -> dwOriginalFlags & cmsFLAGS_NOTPRECALC)) { LPLUT DeviceLink; @@ -1553,7 +1560,8 @@ cmsHTRANSFORM LCMSEXPORT cmsCreateProofingTransform(cmsHPROFILE InputProfile, DeviceLink = _cmsPrecalculateDeviceLink((cmsHTRANSFORM) p, dwFlags); } - if (p -> dwOriginalFlags & cmsFLAGS_GAMUTCHECK) { + // Allow to specify cmsFLAGS_GAMUTCHECK, even if no proofing profile is given + if ((p ->PreviewProfile != NULL) && (p -> dwOriginalFlags & cmsFLAGS_GAMUTCHECK)) { GamutCheck = _cmsPrecalculateGamutCheck((cmsHTRANSFORM) p); } @@ -1561,7 +1569,6 @@ cmsHTRANSFORM LCMSEXPORT cmsCreateProofingTransform(cmsHPROFILE InputProfile, // If input colorspace is Rgb, Cmy, then use tetrahedral interpolation // for speed reasons (it only works well on spaces on Luma is diagonal, and // not if luma is in separate channel) - if (p ->EntryColorSpace == icSigRgbData || p ->EntryColorSpace == icSigCmyData) { @@ -1663,12 +1670,12 @@ void LCMSEXPORT cmsDeleteTransform(cmsHTRANSFORM hTransform) cmsFreeMatShaper(p -> SmeltMatShaper); if (p ->NamedColorList) cmsFreeNamedColorList(p ->NamedColorList); - if (p -> GamutCheck) - cmsFreeLUT(p -> GamutCheck); + if (p -> GamutCheck) + cmsFreeLUT(p -> GamutCheck); - LCMS_FREE_LOCK(&p->rwlock); + LCMS_FREE_LOCK(&p->rwlock); - free((void *) p); + _cmsFree((void *) p); } @@ -1704,7 +1711,7 @@ void LCMSEXPORT cmsGetAlarmCodes(int *r, int *g, int *b) // Returns TRUE if the profile is implemented as matrix-shaper -BOOL LCMSEXPORT _cmsIsMatrixShaper(cmsHPROFILE hProfile) +LCMSBOOL LCMSEXPORT _cmsIsMatrixShaper(cmsHPROFILE hProfile) { switch (cmsGetColorSpace(hProfile)) { @@ -1728,7 +1735,7 @@ BOOL LCMSEXPORT _cmsIsMatrixShaper(cmsHPROFILE hProfile) } -BOOL LCMSEXPORT cmsIsIntentSupported(cmsHPROFILE hProfile, +LCMSBOOL LCMSEXPORT cmsIsIntentSupported(cmsHPROFILE hProfile, int Intent, int UsedDirection) { @@ -1774,6 +1781,16 @@ int MultiprofileSampler(register WORD In[], register WORD Out[], register LPVOID } +static +int IsAllowedInSingleXform(icProfileClassSignature aClass) +{ + return (aClass == icSigInputClass) || + (aClass == icSigDisplayClass) || + (aClass == icSigOutputClass) || + (aClass == icSigColorSpaceClass); +} + + // A multiprofile transform does chain several profiles into a single // devicelink. It couls also be used to merge named color profiles into // a single database. @@ -1805,10 +1822,16 @@ cmsHTRANSFORM LCMSEXPORT cmsCreateMultiprofileTransform(cmsHPROFILE hProfiles[], // There is a simple case with just two profiles, try to catch it in order of getting // black preservation to work on this function, at least with two profiles. + if (nProfiles == 2) { - if ((cmsGetDeviceClass(hProfiles[0]) != icSigLinkClass) && - (cmsGetDeviceClass(hProfiles[1]) != icSigLinkClass)) + icProfileClassSignature Class1 = cmsGetDeviceClass(hProfiles[0]); + icProfileClassSignature Class2 = cmsGetDeviceClass(hProfiles[1]); + + // Only input, output and display are allowed + + if (IsAllowedInSingleXform(Class1) && + IsAllowedInSingleXform(Class2)) return cmsCreateTransform(hProfiles[0], dwInput, hProfiles[1], dwOutput, Intent, dwFlags); } @@ -1984,6 +2007,14 @@ cmsHTRANSFORM LCMSEXPORT cmsCreateMultiprofileTransform(cmsHPROFILE hProfiles[], if (hLab) cmsCloseProfile(hLab); if (hXYZ) cmsCloseProfile(hXYZ); + + if (p ->EntryColorSpace == icSigRgbData || + p ->EntryColorSpace == icSigCmyData) { + + p->DeviceLink -> CLut16params.Interp3D = cmsTetrahedralInterp16; + } + + if ((Intent != INTENT_ABSOLUTE_COLORIMETRIC) && !(dwFlags & cmsFLAGS_NOWHITEONWHITEFIXUP)) _cmsFixWhiteMisalignment(p); diff --git a/src/share/native/sun/java2d/cmm/lcms/icc34.h b/src/share/native/sun/java2d/cmm/lcms/icc34.h index 409928362acf0bbbc52443a9449e317f3ed3a96a..6ae0518888940ddf363b316b3db12e731f517b17 100644 --- a/src/share/native/sun/java2d/cmm/lcms/icc34.h +++ b/src/share/native/sun/java2d/cmm/lcms/icc34.h @@ -206,6 +206,11 @@ typedef __int32_t icInt64Number[2]; #if defined(__sun) || defined(__hpux) || defined (__MINGW) || defined(__MINGW32__) +#if defined (__MINGW) || defined(__MINGW32__) +#include <stdint.h> +#endif + + typedef uint8_t icUInt8Number; typedef uint16_t icUInt16Number; typedef uint32_t icUInt32Number; diff --git a/src/share/native/sun/java2d/cmm/lcms/lcms.h b/src/share/native/sun/java2d/cmm/lcms/lcms.h index 81184b098fbe36f2856b2c491408c4eee1633246..33b3cca67fd60bbe36bdf6459d52f33fc6d3f29c 100644 --- a/src/share/native/sun/java2d/cmm/lcms/lcms.h +++ b/src/share/native/sun/java2d/cmm/lcms/lcms.h @@ -29,7 +29,7 @@ // // // Little cms -// Copyright (C) 1998-2006 Marti Maria +// Copyright (C) 1998-2007 Marti Maria // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the "Software"), @@ -49,8 +49,8 @@ // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// Version 1.16 -#undef DEBUG +// Version 1.18 + #ifndef __cms_H // ********** Configuration toggles **************************************** @@ -62,13 +62,8 @@ // virtually any machine. //#define USE_FLOAT 1 -#ifdef _WIN64 -#define USE_C 1 -#undef USE_ASSEMBLER -#else -#undef USE_C +// #define USE_C 1 #define USE_ASSEMBLER 1 -#endif // Define this if you are using this package as a DLL (windows only) @@ -77,15 +72,11 @@ // Uncomment if you are trying the engine in a non-windows environment // like linux, SGI, VAX, FreeBSD, BeOS, etc. -#if !defined(_WIN32) || !defined(_WIN64) #define NON_WINDOWS 1 -#endif // Uncomment this one if you are using big endian machines (only meaningful // when NON_WINDOWS is used) -#ifndef _LITTLE_ENDIAN -#define USE_BIG_ENDIAN 1 -#endif +// #define USE_BIG_ENDIAN 1 // Uncomment this one if your compiler/machine does support the // "long long" type This will speedup fixed point math. (USE_C only) @@ -104,18 +95,24 @@ // Uncomment this line on multithreading environments // #define USE_PTHREADS 1 +// Uncomment this line if you want lcms to use the black point tag in profile, +// if commented, lcms will compute the black point by its own. +// It is safer to leve it commented out +// #define HONOR_BLACK_POINT_TAG 1 + // ********** End of configuration toggles ****************************** -#define LCMS_VERSION 116 +#define LCMS_VERSION 118 // Microsoft VisualC++ // Deal with Microsoft's attempt at deprecating C standard runtime functions - #ifdef _MSC_VER # undef NON_WINDOWS # if (_MSC_VER >= 1400) +# ifndef _CRT_SECURE_NO_DEPRECATE # define _CRT_SECURE_NO_DEPRECATE 1 +# endif # endif #endif @@ -125,7 +122,6 @@ # undef NON_WINDOWS #endif - #include <stdio.h> #include <stdlib.h> #include <math.h> @@ -134,11 +130,11 @@ #include <time.h> // Metroworks CodeWarrior - #ifdef __MWERKS__ # define unlink remove # if WIN32 # define USE_CUSTOM_SWAB 1 +# undef NON_WINDOWS # else # define NON_WINDOWS 1 # endif @@ -172,15 +168,21 @@ typedef pthread_rwlock_t LCMS_RWLOCK_T; # define USE_BIG_ENDIAN 1 #endif -#if defined(__sgi__) || defined(__sgi) || defined(__powerpc__) || defined(sparc) || defined(__ppc__) +#if defined(__sgi__) || defined(__sgi) || defined(__powerpc__) || defined(sparc) || defined(__ppc__) || defined(__s390__) || defined(__s390x__) # define USE_BIG_ENDIAN 1 #endif -#ifdef TARGET_CPU_PPC +#if TARGET_CPU_PPC # define USE_BIG_ENDIAN 1 #endif -#ifdef macintosh +#if macintosh +# ifndef __LITTLE_ENDIAN__ +# define USE_BIG_ENDIAN 1 +# endif +#endif + +#ifdef __BIG_ENDIAN__ # define USE_BIG_ENDIAN 1 #endif @@ -217,11 +219,8 @@ typedef pthread_rwlock_t LCMS_RWLOCK_T; typedef unsigned char BYTE, *LPBYTE; typedef unsigned short WORD, *LPWORD; typedef unsigned long DWORD, *LPDWORD; -typedef int BOOL; typedef char *LPSTR; typedef void *LPVOID; -typedef void* LCMSHANDLE; - #define ZeroMemory(p,l) memset((p),0,(l)) #define CopyMemory(d,s,l) memcpy((d),(s),(l)) @@ -263,8 +262,12 @@ typedef void* LCMSHANDLE; #include <windows.h> -typedef HANDLE LCMSHANDLE; - +#ifdef _WIN64 +# ifdef USE_ASSEMBLER +# undef USE_ASSEMBLER +# define USE_C 1 +# endif +#endif #ifdef USE_INT64 # ifndef LCMSULONGLONG @@ -296,6 +299,10 @@ typedef int LCMS_RWLOCK_T; # define LCMS_UNLOCK(x) #endif +// Base types + +typedef int LCMSBOOL; +typedef void* LCMSHANDLE; #include "icc34.h" // ICC header file @@ -322,16 +329,10 @@ typedef int LCMS_RWLOCK_T; #define icSigMCHEData ((icColorSpaceSignature) 0x4d434845L) // MCHE #define icSigMCHFData ((icColorSpaceSignature) 0x4d434846L) // MCHF -#define icSigCAM97JABData ((icColorSpaceSignature) 0x4A616231L) // 'Jab1' H. Zeng -#define icSigCAM02JABData ((icColorSpaceSignature) 0x4A616232L) // 'Jab2' H. Zeng -#define icSigCAM02JCHData ((icColorSpaceSignature) 0x4A636A32L) // 'Jch2' H. Zeng - #define icSigChromaticityTag ((icTagSignature) 0x6368726dL) // As per Addendum 2 to Spec. ICC.1:1998-09 #define icSigChromaticAdaptationTag ((icTagSignature) 0x63686164L) // 'chad' #define icSigColorantTableTag ((icTagSignature) 0x636c7274L) // 'clrt' #define icSigColorantTableOutTag ((icTagSignature) 0x636c6f74L) // 'clot' -#define icSigHPGamutDescTag ((icTagSignature) 0x676D7441L) // 'gmtA' H. Zeng - #define icSigParametricCurveType ((icTagTypeSignature) 0x70617261L) // parametric (ICC 4.0) #define icSigMultiLocalizedUnicodeType ((icTagTypeSignature) 0x6D6C7563L) @@ -340,7 +341,6 @@ typedef int LCMS_RWLOCK_T; #define icSiglutAtoBType ((icTagTypeSignature) 0x6d414220L) // mAB #define icSiglutBtoAType ((icTagTypeSignature) 0x6d424120L) // mBA #define icSigColorantTableType ((icTagTypeSignature) 0x636c7274L) // clrt -#define icSigHPGamutDescType ((icTagTypeSignature) 0x676D7441L) // gmtA H. Zeng typedef struct { @@ -438,9 +438,6 @@ extern "C" { #ifndef itoa # define itoa _itoa #endif -#ifndef filelength -# define filelength _filelength -#endif #ifndef fileno # define fileno _fileno #endif @@ -450,6 +447,14 @@ extern "C" { #ifndef hypot # define hypot _hypot #endif +#ifndef snprintf +# define snprintf _snprintf +#endif +#ifndef vsnprintf +# define vsnprintf _vsnprintf +#endif + + #endif @@ -470,8 +475,9 @@ typedef LCMSHANDLE cmsHTRANSFORM; // Format of pixel is defined by one DWORD, using bit fields as follows // -// TTTTT U Y F P X S EEE CCCC BBB +// D TTTTT U Y F P X S EEE CCCC BBB // +// D: Use dither (8 bits only) // T: Pixeltype // F: Flavor 0=MinIsBlack(Chocolate) 1=MinIsWhite(Vanilla) // P: Planar? 0=Chunky, 1=Planar @@ -483,6 +489,7 @@ typedef LCMSHANDLE cmsHTRANSFORM; // Y: Swap first - changes ABGR to BGRA and KCMY to CMYK +#define DITHER_SH(s) ((s) << 22) #define COLORSPACE_SH(s) ((s) << 16) #define SWAPFIRST_SH(s) ((s) << 14) #define FLAVOR_SH(s) ((s) << 13) @@ -711,20 +718,20 @@ typedef LCMSHANDLE cmsHTRANSFORM; typedef struct { - unsigned int Crc32; // Has my table been touched? + unsigned int Crc32; // Has my table been touched? - // Keep initial parameters for further serialization + // Keep initial parameters for further serialization int Type; double Params[10]; - } LCMSGAMMAPARAMS, FAR* LPLCMSGAMMAPARAMS; + } LCMSGAMMAPARAMS, FAR* LPLCMSGAMMAPARAMS; // Gamma tables. typedef struct { - LCMSGAMMAPARAMS Seed; // Parameters used for table creation + LCMSGAMMAPARAMS Seed; // Parameters used for table creation // Table-based representation follows @@ -858,7 +865,7 @@ LCMSAPI LPcmsCIExyY LCMSEXPORT cmsD50_xyY(void); LCMSAPI cmsHPROFILE LCMSEXPORT cmsOpenProfileFromFile(const char *ICCProfile, const char *sAccess); LCMSAPI cmsHPROFILE LCMSEXPORT cmsOpenProfileFromMem(LPVOID MemPtr, DWORD dwSize); -LCMSAPI BOOL LCMSEXPORT cmsCloseProfile(cmsHPROFILE hProfile); +LCMSAPI LCMSBOOL LCMSEXPORT cmsCloseProfile(cmsHPROFILE hProfile); // Predefined run-time profiles @@ -915,14 +922,14 @@ LCMSAPI double LCMSEXPORT cmsCIE2000DeltaE(LPcmsCIELab Lab1, LPcmsCIELab LCMSAPI void LCMSEXPORT cmsClampLab(LPcmsCIELab Lab, double amax, double amin, double bmax, double bmin); -LCMSAPI BOOL LCMSEXPORT cmsWhitePointFromTemp(int TempK, LPcmsCIExyY WhitePoint); +LCMSAPI LCMSBOOL LCMSEXPORT cmsWhitePointFromTemp(int TempK, LPcmsCIExyY WhitePoint); -LCMSAPI BOOL LCMSEXPORT cmsAdaptToIlluminant(LPcmsCIEXYZ Result, +LCMSAPI LCMSBOOL LCMSEXPORT cmsAdaptToIlluminant(LPcmsCIEXYZ Result, LPcmsCIEXYZ SourceWhitePt, LPcmsCIEXYZ Illuminant, LPcmsCIEXYZ Value); -LCMSAPI BOOL LCMSEXPORT cmsBuildRGB2XYZtransferMatrix(LPMAT3 r, +LCMSAPI LCMSBOOL LCMSEXPORT cmsBuildRGB2XYZtransferMatrix(LPMAT3 r, LPcmsCIExyY WhitePoint, LPcmsCIExyYTRIPLE Primaries); @@ -976,7 +983,7 @@ LCMSAPI LPGAMMATABLE LCMSEXPORT cmsDupGamma(LPGAMMATABLE Src); LCMSAPI LPGAMMATABLE LCMSEXPORT cmsReverseGamma(int nResultSamples, LPGAMMATABLE InGamma); LCMSAPI LPGAMMATABLE LCMSEXPORT cmsJoinGamma(LPGAMMATABLE InGamma, LPGAMMATABLE OutGamma); LCMSAPI LPGAMMATABLE LCMSEXPORT cmsJoinGammaEx(LPGAMMATABLE InGamma, LPGAMMATABLE OutGamma, int nPoints); -LCMSAPI BOOL LCMSEXPORT cmsSmoothGamma(LPGAMMATABLE Tab, double lambda); +LCMSAPI LCMSBOOL LCMSEXPORT cmsSmoothGamma(LPGAMMATABLE Tab, double lambda); LCMSAPI double LCMSEXPORT cmsEstimateGamma(LPGAMMATABLE t); LCMSAPI double LCMSEXPORT cmsEstimateGammaEx(LPWORD Table, int nEntries, double Thereshold); LCMSAPI LPGAMMATABLE LCMSEXPORT cmsReadICCGamma(cmsHPROFILE hProfile, icTagSignature sig); @@ -984,14 +991,14 @@ LCMSAPI LPGAMMATABLE LCMSEXPORT cmsReadICCGammaReversed(cmsHPROFILE hProfile, i // Access to Profile data. -LCMSAPI BOOL LCMSEXPORT cmsTakeMediaWhitePoint(LPcmsCIEXYZ Dest, cmsHPROFILE hProfile); -LCMSAPI BOOL LCMSEXPORT cmsTakeMediaBlackPoint(LPcmsCIEXYZ Dest, cmsHPROFILE hProfile); -LCMSAPI BOOL LCMSEXPORT cmsTakeIluminant(LPcmsCIEXYZ Dest, cmsHPROFILE hProfile); -LCMSAPI BOOL LCMSEXPORT cmsTakeColorants(LPcmsCIEXYZTRIPLE Dest, cmsHPROFILE hProfile); +LCMSAPI LCMSBOOL LCMSEXPORT cmsTakeMediaWhitePoint(LPcmsCIEXYZ Dest, cmsHPROFILE hProfile); +LCMSAPI LCMSBOOL LCMSEXPORT cmsTakeMediaBlackPoint(LPcmsCIEXYZ Dest, cmsHPROFILE hProfile); +LCMSAPI LCMSBOOL LCMSEXPORT cmsTakeIluminant(LPcmsCIEXYZ Dest, cmsHPROFILE hProfile); +LCMSAPI LCMSBOOL LCMSEXPORT cmsTakeColorants(LPcmsCIEXYZTRIPLE Dest, cmsHPROFILE hProfile); LCMSAPI DWORD LCMSEXPORT cmsTakeHeaderFlags(cmsHPROFILE hProfile); LCMSAPI DWORD LCMSEXPORT cmsTakeHeaderAttributes(cmsHPROFILE hProfile); -LCMSAPI void LCMSEXPORT cmsSetLanguage(int LanguageCode, int CountryCode); +LCMSAPI void LCMSEXPORT cmsSetLanguage(const char LanguageCode[4], const char CountryCode[4]); LCMSAPI const char* LCMSEXPORT cmsTakeProductName(cmsHPROFILE hProfile); LCMSAPI const char* LCMSEXPORT cmsTakeProductDesc(cmsHPROFILE hProfile); LCMSAPI const char* LCMSEXPORT cmsTakeProductInfo(cmsHPROFILE hProfile); @@ -1000,13 +1007,13 @@ LCMSAPI const char* LCMSEXPORT cmsTakeModel(cmsHPROFILE hProfile); LCMSAPI const char* LCMSEXPORT cmsTakeCopyright(cmsHPROFILE hProfile); LCMSAPI const BYTE* LCMSEXPORT cmsTakeProfileID(cmsHPROFILE hProfile); -LCMSAPI BOOL LCMSEXPORT cmsTakeCreationDateTime(struct tm *Dest, cmsHPROFILE hProfile); -LCMSAPI BOOL LCMSEXPORT cmsTakeCalibrationDateTime(struct tm *Dest, cmsHPROFILE hProfile); +LCMSAPI LCMSBOOL LCMSEXPORT cmsTakeCreationDateTime(struct tm *Dest, cmsHPROFILE hProfile); +LCMSAPI LCMSBOOL LCMSEXPORT cmsTakeCalibrationDateTime(struct tm *Dest, cmsHPROFILE hProfile); -LCMSAPI BOOL LCMSEXPORT cmsIsTag(cmsHPROFILE hProfile, icTagSignature sig); +LCMSAPI LCMSBOOL LCMSEXPORT cmsIsTag(cmsHPROFILE hProfile, icTagSignature sig); LCMSAPI int LCMSEXPORT cmsTakeRenderingIntent(cmsHPROFILE hProfile); -LCMSAPI BOOL LCMSEXPORT cmsTakeCharTargetData(cmsHPROFILE hProfile, char** Data, size_t* len); +LCMSAPI LCMSBOOL LCMSEXPORT cmsTakeCharTargetData(cmsHPROFILE hProfile, char** Data, size_t* len); LCMSAPI int LCMSEXPORT cmsReadICCTextEx(cmsHPROFILE hProfile, icTagSignature sig, char *Text, size_t size); LCMSAPI int LCMSEXPORT cmsReadICCText(cmsHPROFILE hProfile, icTagSignature sig, char *Text); @@ -1038,50 +1045,18 @@ LCMSAPI LPcmsSEQ LCMSEXPORT cmsReadProfileSequenceDescription(cmsHPROFILE h LCMSAPI void LCMSEXPORT cmsFreeProfileSequenceDescription(LPcmsSEQ pseq); -// Extended gamut tag -- an HP extension - -#define LCMSGAMUTMETHOD_SEGMENTMAXIMA 0 -#define LCMSGAMUTMETHOD_CONVEXHULL 1 -#define LCMSGAMUTMETHOD_ALPHASHAPE 2 - - -#define LCMSGAMUT_PHYSICAL 0 -#define LCMSGAMUT_HP1 1 -#define LCMSGAMUT_HP2 2 - -typedef struct { - - icColorSpaceSignature CoordSig; // Gamut coordinates signature - icUInt16Number Method; // Method used to generate gamut - icUInt16Number Usage; // Gamut usage or intent - - char Description[LCMS_DESC_MAX]; // Textual description - - cmsViewingConditions Vc; // The viewing conditions - - icUInt32Number Count; // Number of entries - double Data[1]; // The current data - - } cmsGAMUTEX, FAR* LPcmsGAMUTEX; - - -LCMSAPI LPcmsGAMUTEX LCMSEXPORT cmsReadExtendedGamut(cmsHPROFILE hProfile, int index); -LCMSAPI void LCMSEXPORT cmsFreeExtendedGamut(LPcmsGAMUTEX gex); - - - - // Translate form/to our notation to ICC LCMSAPI icColorSpaceSignature LCMSEXPORT _cmsICCcolorSpace(int OurNotation); -LCMSAPI int LCMSEXPORT _cmsLCMScolorSpace(icColorSpaceSignature ProfileSpace); -LCMSAPI int LCMSEXPORT _cmsChannelsOf(icColorSpaceSignature ColorSpace); -LCMSAPI BOOL LCMSEXPORT _cmsIsMatrixShaper(cmsHPROFILE hProfile); +LCMSAPI int LCMSEXPORT _cmsLCMScolorSpace(icColorSpaceSignature ProfileSpace); +LCMSAPI int LCMSEXPORT _cmsChannelsOf(icColorSpaceSignature ColorSpace); +LCMSAPI LCMSBOOL LCMSEXPORT _cmsIsMatrixShaper(cmsHPROFILE hProfile); +// How profiles may be used #define LCMS_USED_AS_INPUT 0 #define LCMS_USED_AS_OUTPUT 1 #define LCMS_USED_AS_PROOF 2 -LCMSAPI BOOL LCMSEXPORT cmsIsIntentSupported(cmsHPROFILE hProfile, int Intent, int UsedDirection); +LCMSAPI LCMSBOOL LCMSEXPORT cmsIsIntentSupported(cmsHPROFILE hProfile, int Intent, int UsedDirection); LCMSAPI icColorSpaceSignature LCMSEXPORT cmsGetPCS(cmsHPROFILE hProfile); LCMSAPI icColorSpaceSignature LCMSEXPORT cmsGetColorSpace(cmsHPROFILE hProfile); @@ -1141,7 +1116,7 @@ LCMSAPI void LCMSEXPORT cmsSetProfileID(cmsHPROFILE hProfile, LPBYTE Pr // CRD special -#define cmsFLAGS_NODEFAULTRESOURCEDEF 0x00010000 +#define cmsFLAGS_NODEFAULTRESOURCEDEF 0x01000000 // Gridpoints @@ -1220,9 +1195,9 @@ typedef struct { // Named color support -LCMSAPI int LCMSEXPORT cmsNamedColorCount(cmsHTRANSFORM xform); -LCMSAPI BOOL LCMSEXPORT cmsNamedColorInfo(cmsHTRANSFORM xform, int nColor, char* Name, char* Prefix, char* Suffix); -LCMSAPI int LCMSEXPORT cmsNamedColorIndex(cmsHTRANSFORM xform, const char* Name); +LCMSAPI int LCMSEXPORT cmsNamedColorCount(cmsHTRANSFORM xform); +LCMSAPI LCMSBOOL LCMSEXPORT cmsNamedColorInfo(cmsHTRANSFORM xform, int nColor, char* Name, char* Prefix, char* Suffix); +LCMSAPI int LCMSEXPORT cmsNamedColorIndex(cmsHTRANSFORM xform, const char* Name); // Colorant tables @@ -1230,7 +1205,7 @@ LCMSAPI LPcmsNAMEDCOLORLIST LCMSEXPORT cmsReadColorantTable(cmsHPROFILE hProfile // Profile creation -LCMSAPI BOOL LCMSEXPORT cmsAddTag(cmsHPROFILE hProfile, icTagSignature sig, const void* data); +LCMSAPI LCMSBOOL LCMSEXPORT cmsAddTag(cmsHPROFILE hProfile, icTagSignature sig, const void* data); // Converts a transform to a devicelink profile LCMSAPI cmsHPROFILE LCMSEXPORT cmsTransform2DeviceLink(cmsHTRANSFORM hTransform, DWORD dwFlags); @@ -1240,8 +1215,8 @@ LCMSAPI void LCMSEXPORT _cmsSetLUTdepth(cmsHPROFILE hProfile, int depth); // Save profile -LCMSAPI BOOL LCMSEXPORT _cmsSaveProfile(cmsHPROFILE hProfile, const char* FileName); -LCMSAPI BOOL LCMSEXPORT _cmsSaveProfileToMem(cmsHPROFILE hProfile, void *MemPtr, +LCMSAPI LCMSBOOL LCMSEXPORT _cmsSaveProfile(cmsHPROFILE hProfile, const char* FileName); +LCMSAPI LCMSBOOL LCMSEXPORT _cmsSaveProfileToMem(cmsHPROFILE hProfile, void *MemPtr, size_t* BytesNeeded); @@ -1286,6 +1261,7 @@ LCMSAPI double LCMSEXPORT cmsEvalLUTreverse(LPLUT Lut, WORD Target[], WORD Resul LCMSAPI LPLUT LCMSEXPORT cmsReadICCLut(cmsHPROFILE hProfile, icTagSignature sig); LCMSAPI LPLUT LCMSEXPORT cmsDupLUT(LPLUT Orig); + // LUT Sampling typedef int (* _cmsSAMPLER)(register WORD In[], @@ -1325,35 +1301,37 @@ LCMSAPI int LCMSEXPORT cmsIT8SetTable(LCMSHANDLE IT8, int nTable); // Persistence LCMSAPI LCMSHANDLE LCMSEXPORT cmsIT8LoadFromFile(const char* cFileName); LCMSAPI LCMSHANDLE LCMSEXPORT cmsIT8LoadFromMem(void *Ptr, size_t len); -LCMSAPI BOOL LCMSEXPORT cmsIT8SaveToFile(LCMSHANDLE IT8, const char* cFileName); -LCMSAPI BOOL LCMSEXPORT cmsIT8SaveToMem(LCMSHANDLE hIT8, void *MemPtr, size_t* BytesNeeded); +LCMSAPI LCMSBOOL LCMSEXPORT cmsIT8SaveToFile(LCMSHANDLE IT8, const char* cFileName); +LCMSAPI LCMSBOOL LCMSEXPORT cmsIT8SaveToMem(LCMSHANDLE hIT8, void *MemPtr, size_t* BytesNeeded); // Properties LCMSAPI const char* LCMSEXPORT cmsIT8GetSheetType(LCMSHANDLE hIT8); -LCMSAPI BOOL LCMSEXPORT cmsIT8SetSheetType(LCMSHANDLE hIT8, const char* Type); - -LCMSAPI BOOL LCMSEXPORT cmsIT8SetComment(LCMSHANDLE hIT8, const char* cComment); +LCMSAPI LCMSBOOL LCMSEXPORT cmsIT8SetSheetType(LCMSHANDLE hIT8, const char* Type); -LCMSAPI BOOL LCMSEXPORT cmsIT8SetPropertyStr(LCMSHANDLE hIT8, const char* cProp, const char *Str); -LCMSAPI BOOL LCMSEXPORT cmsIT8SetPropertyDbl(LCMSHANDLE hIT8, const char* cProp, double Val); -LCMSAPI BOOL LCMSEXPORT cmsIT8SetPropertyHex(LCMSHANDLE hIT8, const char* cProp, int Val); +LCMSAPI LCMSBOOL LCMSEXPORT cmsIT8SetComment(LCMSHANDLE hIT8, const char* cComment); -LCMSAPI BOOL LCMSEXPORT cmsIT8SetPropertyUncooked(LCMSHANDLE hIT8, const char* Key, const char* Buffer); +LCMSAPI LCMSBOOL LCMSEXPORT cmsIT8SetPropertyStr(LCMSHANDLE hIT8, const char* cProp, const char *Str); +LCMSAPI LCMSBOOL LCMSEXPORT cmsIT8SetPropertyDbl(LCMSHANDLE hIT8, const char* cProp, double Val); +LCMSAPI LCMSBOOL LCMSEXPORT cmsIT8SetPropertyHex(LCMSHANDLE hIT8, const char* cProp, int Val); +LCMSAPI LCMSBOOL LCMSEXPORT cmsIT8SetPropertyMulti(LCMSHANDLE hIT8, const char* cProp, const char* cSubProp, const char *Val); +LCMSAPI LCMSBOOL LCMSEXPORT cmsIT8SetPropertyUncooked(LCMSHANDLE hIT8, const char* Key, const char* Buffer); LCMSAPI const char* LCMSEXPORT cmsIT8GetProperty(LCMSHANDLE hIT8, const char* cProp); LCMSAPI double LCMSEXPORT cmsIT8GetPropertyDbl(LCMSHANDLE hIT8, const char* cProp); -LCMSAPI int LCMSEXPORT cmsIT8EnumProperties(LCMSHANDLE IT8, char ***PropertyNames); +LCMSAPI const char* LCMSEXPORT cmsIT8GetPropertyMulti(LCMSHANDLE hIT8, const char* cProp, const char *cSubProp); +LCMSAPI int LCMSEXPORT cmsIT8EnumProperties(LCMSHANDLE hIT8, const char ***PropertyNames); +LCMSAPI int LCMSEXPORT cmsIT8EnumPropertyMulti(LCMSHANDLE hIT8, const char* cProp, const char*** SubpropertyNames); // Datasets LCMSAPI const char* LCMSEXPORT cmsIT8GetDataRowCol(LCMSHANDLE IT8, int row, int col); LCMSAPI double LCMSEXPORT cmsIT8GetDataRowColDbl(LCMSHANDLE IT8, int row, int col); -LCMSAPI BOOL LCMSEXPORT cmsIT8SetDataRowCol(LCMSHANDLE hIT8, int row, int col, +LCMSAPI LCMSBOOL LCMSEXPORT cmsIT8SetDataRowCol(LCMSHANDLE hIT8, int row, int col, const char* Val); -LCMSAPI BOOL LCMSEXPORT cmsIT8SetDataRowColDbl(LCMSHANDLE hIT8, int row, int col, +LCMSAPI LCMSBOOL LCMSEXPORT cmsIT8SetDataRowColDbl(LCMSHANDLE hIT8, int row, int col, double Val); LCMSAPI const char* LCMSEXPORT cmsIT8GetData(LCMSHANDLE IT8, const char* cPatch, const char* cSample); @@ -1361,25 +1339,28 @@ LCMSAPI const char* LCMSEXPORT cmsIT8GetData(LCMSHANDLE IT8, const char* cPa LCMSAPI double LCMSEXPORT cmsIT8GetDataDbl(LCMSHANDLE IT8, const char* cPatch, const char* cSample); -LCMSAPI BOOL LCMSEXPORT cmsIT8SetData(LCMSHANDLE IT8, const char* cPatch, +LCMSAPI LCMSBOOL LCMSEXPORT cmsIT8SetData(LCMSHANDLE IT8, const char* cPatch, const char* cSample, const char *Val); -LCMSAPI BOOL LCMSEXPORT cmsIT8SetDataDbl(LCMSHANDLE hIT8, const char* cPatch, +LCMSAPI LCMSBOOL LCMSEXPORT cmsIT8SetDataDbl(LCMSHANDLE hIT8, const char* cPatch, const char* cSample, double Val); LCMSAPI int LCMSEXPORT cmsIT8GetDataFormat(LCMSHANDLE hIT8, const char* cSample); -LCMSAPI BOOL LCMSEXPORT cmsIT8SetDataFormat(LCMSHANDLE IT8, int n, const char *Sample); +LCMSAPI LCMSBOOL LCMSEXPORT cmsIT8SetDataFormat(LCMSHANDLE IT8, int n, const char *Sample); LCMSAPI int LCMSEXPORT cmsIT8EnumDataFormat(LCMSHANDLE IT8, char ***SampleNames); LCMSAPI const char* LCMSEXPORT cmsIT8GetPatchName(LCMSHANDLE hIT8, int nPatch, char* buffer); +LCMSAPI int LCMSEXPORT cmsIT8GetPatchByName(LCMSHANDLE hIT8, const char *cSample); // The LABEL extension LCMSAPI int LCMSEXPORT cmsIT8SetTableByLabel(LCMSHANDLE hIT8, const char* cSet, const char* cField, const char* ExpectedType); +LCMSAPI LCMSBOOL LCMSEXPORT cmsIT8SetIndexColumn(LCMSHANDLE hIT8, const char* cSample); + // Formatter for double LCMSAPI void LCMSEXPORT cmsIT8DefineDblFormat(LCMSHANDLE IT8, const char* Formatter); @@ -1405,15 +1386,16 @@ LCMSAPI void LCMSEXPORT cmsFloat2XYZEncoded(WORD XYZ[3], const cmsCIEXY // Profiling Extensions --- Would be removed from API in future revisions -LCMSAPI BOOL LCMSEXPORT _cmsAddTextTag(cmsHPROFILE hProfile, icTagSignature sig, const char* Text); -LCMSAPI BOOL LCMSEXPORT _cmsAddXYZTag(cmsHPROFILE hProfile, icTagSignature sig, const cmsCIEXYZ* XYZ); -LCMSAPI BOOL LCMSEXPORT _cmsAddLUTTag(cmsHPROFILE hProfile, icTagSignature sig, const void* lut); -LCMSAPI BOOL LCMSEXPORT _cmsAddGammaTag(cmsHPROFILE hProfile, icTagSignature sig, LPGAMMATABLE TransferFunction); -LCMSAPI BOOL LCMSEXPORT _cmsAddChromaticityTag(cmsHPROFILE hProfile, icTagSignature sig, LPcmsCIExyYTRIPLE Chrm); -LCMSAPI BOOL LCMSEXPORT _cmsAddSequenceDescriptionTag(cmsHPROFILE hProfile, icTagSignature sig, LPcmsSEQ PSeq); -LCMSAPI BOOL LCMSEXPORT _cmsAddNamedColorTag(cmsHPROFILE hProfile, icTagSignature sig, LPcmsNAMEDCOLORLIST nc); -LCMSAPI BOOL LCMSEXPORT _cmsAddDateTimeTag(cmsHPROFILE hProfile, icTagSignature sig, struct tm *DateTime); -LCMSAPI BOOL LCMSEXPORT _cmsAddColorantTableTag(cmsHPROFILE hProfile, icTagSignature sig, LPcmsNAMEDCOLORLIST nc); +LCMSAPI LCMSBOOL LCMSEXPORT _cmsAddTextTag(cmsHPROFILE hProfile, icTagSignature sig, const char* Text); +LCMSAPI LCMSBOOL LCMSEXPORT _cmsAddXYZTag(cmsHPROFILE hProfile, icTagSignature sig, const cmsCIEXYZ* XYZ); +LCMSAPI LCMSBOOL LCMSEXPORT _cmsAddLUTTag(cmsHPROFILE hProfile, icTagSignature sig, const void* lut); +LCMSAPI LCMSBOOL LCMSEXPORT _cmsAddGammaTag(cmsHPROFILE hProfile, icTagSignature sig, LPGAMMATABLE TransferFunction); +LCMSAPI LCMSBOOL LCMSEXPORT _cmsAddChromaticityTag(cmsHPROFILE hProfile, icTagSignature sig, LPcmsCIExyYTRIPLE Chrm); +LCMSAPI LCMSBOOL LCMSEXPORT _cmsAddSequenceDescriptionTag(cmsHPROFILE hProfile, icTagSignature sig, LPcmsSEQ PSeq); +LCMSAPI LCMSBOOL LCMSEXPORT _cmsAddNamedColorTag(cmsHPROFILE hProfile, icTagSignature sig, LPcmsNAMEDCOLORLIST nc); +LCMSAPI LCMSBOOL LCMSEXPORT _cmsAddDateTimeTag(cmsHPROFILE hProfile, icTagSignature sig, struct tm *DateTime); +LCMSAPI LCMSBOOL LCMSEXPORT _cmsAddColorantTableTag(cmsHPROFILE hProfile, icTagSignature sig, LPcmsNAMEDCOLORLIST nc); +LCMSAPI LCMSBOOL LCMSEXPORT _cmsAddChromaticAdaptationTag(cmsHPROFILE hProfile, icTagSignature sig, const cmsCIEXYZ* mat); // --------------------------------------------------------------------------------------------------- Inline functions @@ -1455,6 +1437,38 @@ LCMS_INLINE WORD _cmsClampWord(int in) return (WORD) in; } +#ifndef LCMS_USER_ALLOC + +// Low-level alloc hook + +LCMS_INLINE void* _cmsMalloc(size_t size) +{ + if (size > ((size_t) 1024*1024*500)) return NULL; // Never allow over 500Mb + if (size < 0) return NULL; // Prevent signed size_t exploits + + return (void*) malloc(size); +} + +LCMS_INLINE void* _cmsCalloc(size_t nmemb, size_t size) +{ + size_t alloc = nmemb * size; + + if (size == 0) { + return _cmsMalloc(0); + } + if (alloc / size != nmemb) { + return NULL; + } + return _cmsMalloc(alloc); +} + +LCMS_INLINE void _cmsFree(void *Ptr) +{ + if (Ptr) free(Ptr); +} + +#endif + // ------------------------------------------------------------------------------------------- end of inline functions // Signal error from inside lcms code @@ -1531,36 +1545,36 @@ typedef struct { // Matrix (Fixed 15.16) -void cdecl VEC3init(LPVEC3 r, double x, double y, double z); // double version -void cdecl VEC3initF(LPWVEC3 r, double x, double y, double z); // Fix32 version -void cdecl VEC3toFix(LPWVEC3 r, LPVEC3 v); -void cdecl VEC3fromFix(LPVEC3 r, LPWVEC3 v); -void cdecl VEC3scaleFix(LPWORD r, LPWVEC3 Scale); -void cdecl VEC3swap(LPVEC3 a, LPVEC3 b); -void cdecl VEC3divK(LPVEC3 r, LPVEC3 v, double d); -void cdecl VEC3perK(LPVEC3 r, LPVEC3 v, double d); -void cdecl VEC3minus(LPVEC3 r, LPVEC3 a, LPVEC3 b); -void cdecl VEC3perComp(LPVEC3 r, LPVEC3 a, LPVEC3 b); -BOOL cdecl VEC3equal(LPWVEC3 a, LPWVEC3 b, double Tolerance); -BOOL cdecl VEC3equalF(LPVEC3 a, LPVEC3 b, double Tolerance); -void cdecl VEC3scaleAndCut(LPWVEC3 r, LPVEC3 v, double d); -void cdecl VEC3cross(LPVEC3 r, LPVEC3 u, LPVEC3 v); -void cdecl VEC3saturate(LPVEC3 v); -double cdecl VEC3distance(LPVEC3 a, LPVEC3 b); -double cdecl VEC3length(LPVEC3 a); - -void cdecl MAT3identity(LPMAT3 a); -void cdecl MAT3per(LPMAT3 r, LPMAT3 a, LPMAT3 b); -void cdecl MAT3perK(LPMAT3 r, LPMAT3 v, double d); -int cdecl MAT3inverse(LPMAT3 a, LPMAT3 b); -BOOL cdecl MAT3solve(LPVEC3 x, LPMAT3 a, LPVEC3 b); -double cdecl MAT3det(LPMAT3 m); -void cdecl MAT3eval(LPVEC3 r, LPMAT3 a, LPVEC3 v); -void cdecl MAT3toFix(LPWMAT3 r, LPMAT3 v); -void cdecl MAT3fromFix(LPMAT3 r, LPWMAT3 v); -void cdecl MAT3evalW(LPWVEC3 r, LPWMAT3 a, LPWVEC3 v); -BOOL cdecl MAT3isIdentity(LPWMAT3 a, double Tolerance); -void cdecl MAT3scaleAndCut(LPWMAT3 r, LPMAT3 v, double d); +void cdecl VEC3init(LPVEC3 r, double x, double y, double z); // double version +void cdecl VEC3initF(LPWVEC3 r, double x, double y, double z); // Fix32 version +void cdecl VEC3toFix(LPWVEC3 r, LPVEC3 v); +void cdecl VEC3fromFix(LPVEC3 r, LPWVEC3 v); +void cdecl VEC3scaleFix(LPWORD r, LPWVEC3 Scale); +void cdecl VEC3swap(LPVEC3 a, LPVEC3 b); +void cdecl VEC3divK(LPVEC3 r, LPVEC3 v, double d); +void cdecl VEC3perK(LPVEC3 r, LPVEC3 v, double d); +void cdecl VEC3minus(LPVEC3 r, LPVEC3 a, LPVEC3 b); +void cdecl VEC3perComp(LPVEC3 r, LPVEC3 a, LPVEC3 b); +LCMSBOOL cdecl VEC3equal(LPWVEC3 a, LPWVEC3 b, double Tolerance); +LCMSBOOL cdecl VEC3equalF(LPVEC3 a, LPVEC3 b, double Tolerance); +void cdecl VEC3scaleAndCut(LPWVEC3 r, LPVEC3 v, double d); +void cdecl VEC3cross(LPVEC3 r, LPVEC3 u, LPVEC3 v); +void cdecl VEC3saturate(LPVEC3 v); +double cdecl VEC3distance(LPVEC3 a, LPVEC3 b); +double cdecl VEC3length(LPVEC3 a); + +void cdecl MAT3identity(LPMAT3 a); +void cdecl MAT3per(LPMAT3 r, LPMAT3 a, LPMAT3 b); +void cdecl MAT3perK(LPMAT3 r, LPMAT3 v, double d); +int cdecl MAT3inverse(LPMAT3 a, LPMAT3 b); +LCMSBOOL cdecl MAT3solve(LPVEC3 x, LPMAT3 a, LPVEC3 b); +double cdecl MAT3det(LPMAT3 m); +void cdecl MAT3eval(LPVEC3 r, LPMAT3 a, LPVEC3 v); +void cdecl MAT3toFix(LPWMAT3 r, LPMAT3 v); +void cdecl MAT3fromFix(LPMAT3 r, LPWMAT3 v); +void cdecl MAT3evalW(LPWVEC3 r, LPWMAT3 a, LPWVEC3 v); +LCMSBOOL cdecl MAT3isIdentity(LPWMAT3 a, double Tolerance); +void cdecl MAT3scaleAndCut(LPWMAT3 r, LPMAT3 v, double d); // Is a table linear? @@ -1608,7 +1622,7 @@ typedef struct _lcms_l16params_struc { // Used on 16 bits interpolations void cdecl cmsCalcL16Params(int nSamples, LPL16PARAMS p); void cdecl cmsCalcCLUT16Params(int nSamples, int InputChan, int OutputChan, LPL16PARAMS p); void cdecl cmsCalcCLUT16ParamsEx(int nSamples, int InputChan, int OutputChan, - BOOL lUseTetrahedral, LPL16PARAMS p); + LCMSBOOL lUseTetrahedral, LPL16PARAMS p); WORD cdecl cmsLinearInterpLUT16(WORD Value, WORD LutTable[], LPL16PARAMS p); Fixed32 cdecl cmsLinearInterpFixed(WORD Value1, WORD LutTable[], LPL16PARAMS p); @@ -1692,18 +1706,18 @@ struct _lcms_LUT_struc { // Gray axes fixup. Only on v2 8-bit Lab LUT - BOOL FixGrayAxes; + LCMSBOOL FixGrayAxes; - // Parameters used for curve creation + // Parameters used for curve creation - LCMSGAMMAPARAMS LCurvesSeed[4][MAXCHANNELS]; + LCMSGAMMAPARAMS LCurvesSeed[4][MAXCHANNELS]; }; // LUT, FAR* LPLUT; -BOOL cdecl _cmsSmoothEndpoints(LPWORD Table, int nEntries); +LCMSBOOL cdecl _cmsSmoothEndpoints(LPWORD Table, int nEntries); // CRC of gamma tables @@ -1721,7 +1735,7 @@ LPGAMMATABLE cdecl cmsConvertSampledCurveToGamma(LPSAMPLEDCURVE Sampled, doubl void cdecl cmsEndpointsOfSampledCurve(LPSAMPLEDCURVE p, double* Min, double* Max); void cdecl cmsClampSampledCurve(LPSAMPLEDCURVE p, double Min, double Max); -BOOL cdecl cmsSmoothSampledCurve(LPSAMPLEDCURVE Tab, double SmoothingLambda); +LCMSBOOL cdecl cmsSmoothSampledCurve(LPSAMPLEDCURVE Tab, double SmoothingLambda); void cdecl cmsRescaleSampledCurve(LPSAMPLEDCURVE p, double Min, double Max, int nPoints); LPSAMPLEDCURVE cdecl cmsJoinSampledCurves(LPSAMPLEDCURVE X, LPSAMPLEDCURVE Y, int nResultingPoints); @@ -1755,19 +1769,19 @@ LPMATSHAPER cdecl cmsAllocMatShaper2(LPMAT3 matrix, LPGAMMATABLE In[], LPGAMMATA void cdecl cmsFreeMatShaper(LPMATSHAPER MatShaper); void cdecl cmsEvalMatShaper(LPMATSHAPER MatShaper, WORD In[], WORD Out[]); -BOOL cdecl cmsReadICCMatrixRGB2XYZ(LPMAT3 r, cmsHPROFILE hProfile); +LCMSBOOL cdecl cmsReadICCMatrixRGB2XYZ(LPMAT3 r, cmsHPROFILE hProfile); -LPMATSHAPER cdecl cmsBuildInputMatrixShaper(cmsHPROFILE InputProfile); -LPMATSHAPER cdecl cmsBuildOutputMatrixShaper(cmsHPROFILE OutputProfile); +LPMATSHAPER cdecl cmsBuildInputMatrixShaper(cmsHPROFILE InputProfile); +LPMATSHAPER cdecl cmsBuildOutputMatrixShaper(cmsHPROFILE OutputProfile); // White Point & Primary chromas handling -BOOL cdecl cmsAdaptationMatrix(LPMAT3 r, LPMAT3 ConeMatrix, LPcmsCIEXYZ FromIll, LPcmsCIEXYZ ToIll); -BOOL cdecl cmsAdaptMatrixToD50(LPMAT3 r, LPcmsCIExyY SourceWhitePt); -BOOL cdecl cmsAdaptMatrixFromD50(LPMAT3 r, LPcmsCIExyY DestWhitePt); +LCMSBOOL cdecl cmsAdaptationMatrix(LPMAT3 r, LPMAT3 ConeMatrix, LPcmsCIEXYZ FromIll, LPcmsCIEXYZ ToIll); +LCMSBOOL cdecl cmsAdaptMatrixToD50(LPMAT3 r, LPcmsCIExyY SourceWhitePt); +LCMSBOOL cdecl cmsAdaptMatrixFromD50(LPMAT3 r, LPcmsCIExyY DestWhitePt); -BOOL cdecl cmsReadChromaticAdaptationMatrix(LPMAT3 r, cmsHPROFILE hProfile); +LCMSBOOL cdecl cmsReadChromaticAdaptationMatrix(LPMAT3 r, cmsHPROFILE hProfile); // Inter-PCS conversion routines. They assume D50 as white point. void cdecl cmsXYZ2LabEncoded(WORD XYZ[3], WORD Lab[3]); @@ -1782,7 +1796,7 @@ WORD cdecl _cmsQuantizeVal(double i, int MaxSamples); LPcmsNAMEDCOLORLIST cdecl cmsAllocNamedColorList(int n); int cdecl cmsReadICCnamedColorList(cmsHTRANSFORM xform, cmsHPROFILE hProfile, icTagSignature sig); void cdecl cmsFreeNamedColorList(LPcmsNAMEDCOLORLIST List); -BOOL cdecl cmsAppendNamedColor(cmsHTRANSFORM xform, const char* Name, WORD PCS[3], WORD Colorant[MAXCHANNELS]); +LCMSBOOL cdecl cmsAppendNamedColor(cmsHTRANSFORM xform, const char* Name, WORD PCS[3], WORD Colorant[MAXCHANNELS]); // I/O @@ -1804,7 +1818,7 @@ typedef struct _lcms_iccprofile_struct { icColorSpaceSignature PCS; icRenderingIntent RenderingIntent; icUInt32Number flags; - icUInt32Number attributes; + icUInt32Number attributes; cmsCIEXYZ Illuminant; // Additions for V4 profiles @@ -1826,22 +1840,23 @@ typedef struct _lcms_iccprofile_struct { char PhysicalFile[MAX_PATH]; - BOOL IsWrite; - BOOL SaveAs8Bits; + LCMSBOOL IsWrite; + LCMSBOOL SaveAs8Bits; struct tm Created; // I/O handlers - size_t (* Read)(void *buffer, size_t size, size_t count, struct _lcms_iccprofile_struct* Icc); + size_t (* Read)(void *buffer, size_t size, size_t count, struct _lcms_iccprofile_struct* Icc); - BOOL (* Seek)(struct _lcms_iccprofile_struct* Icc, size_t offset); - BOOL (* Close)(struct _lcms_iccprofile_struct* Icc); - size_t (* Tell)(struct _lcms_iccprofile_struct* Icc); + LCMSBOOL (* Seek)(struct _lcms_iccprofile_struct* Icc, size_t offset); + LCMSBOOL (* Close)(struct _lcms_iccprofile_struct* Icc); + size_t (* Tell)(struct _lcms_iccprofile_struct* Icc); + LCMSBOOL (* Grow)(struct _lcms_iccprofile_struct* Icc, size_t amount); // Writting - BOOL (* Write)(struct _lcms_iccprofile_struct* Icc, size_t size, LPVOID Ptr); + LCMSBOOL (* Write)(struct _lcms_iccprofile_struct* Icc, size_t size, LPVOID Ptr); size_t UsedSpace; @@ -1853,7 +1868,7 @@ typedef struct _lcms_iccprofile_struct { cmsHPROFILE cdecl _cmsCreateProfilePlaceholder(void); // Search into tag dictionary -icInt32Number cdecl _cmsSearchTag(LPLCMSICCPROFILE Profile, icTagSignature sig, BOOL lSignalError); +icInt32Number cdecl _cmsSearchTag(LPLCMSICCPROFILE Profile, icTagSignature sig, LCMSBOOL lSignalError); // Search for a particular tag, replace if found or add new one else LPVOID _cmsInitTag(LPLCMSICCPROFILE Icc, icTagSignature sig, size_t size, const void* Init); @@ -1869,6 +1884,7 @@ void _cmsSetSaveToMemory(LPLCMSICCPROFILE Icc, LPVOID MemPtr, size_t dwSize); // These macros unpack format specifiers into integers +#define T_DITHER(s) (((s)>>22)&1) #define T_COLORSPACE(s) (((s)>>16)&31) #define T_SWAPFIRST(s) (((s)>>14)&1) #define T_FLAVOR(s) (((s)>>13)&1) @@ -1965,7 +1981,7 @@ typedef struct _cmstransform_struct { // Flag for transform involving v4 profiles - BOOL lInputV4Lab, lOutputV4Lab; + LCMSBOOL lInputV4Lab, lOutputV4Lab; // 1-pixel cache @@ -1975,7 +1991,7 @@ typedef struct _cmstransform_struct { double AdaptationState; // Figure for v4 incomplete state of adaptation - LCMS_RWLOCK_T rwlock; + LCMS_RWLOCK_T rwlock; } _cmsTRANSFORM,FAR *_LPcmsTRANSFORM; @@ -2012,7 +2028,7 @@ int cdecl cmsChooseCnvrt(int Absolute, // Clamping & Gamut handling -BOOL cdecl _cmsEndPointsBySpace(icColorSpaceSignature Space, +LCMSBOOL cdecl _cmsEndPointsBySpace(icColorSpaceSignature Space, WORD **White, WORD **Black, int *nOutputs); WORD * cdecl _cmsWhiteBySpace(icColorSpaceSignature Space); @@ -2041,7 +2057,7 @@ LPLUT _cmsPrecalculateBlackPreservingDeviceLink(cmsHTRANSFORM hCMYK2CMYK, DWORD LPLUT cdecl _cmsPrecalculateGamutCheck(cmsHTRANSFORM h); // Hot fixes bad profiles -BOOL cdecl _cmsFixWhiteMisalignment(_LPcmsTRANSFORM p); +LCMSBOOL cdecl _cmsFixWhiteMisalignment(_LPcmsTRANSFORM p); // Marks LUT as 8 bit on input LPLUT cdecl _cmsBlessLUT8(LPLUT Lut); @@ -2059,6 +2075,10 @@ void cdecl _cmsComputePrelinearizationTablesFromXFORM(cmsHTRANSFORM h[], int nTr // Build a tone curve for K->K' if possible (only works on CMYK) LPGAMMATABLE _cmsBuildKToneCurve(cmsHTRANSFORM hCMYK2CMYK, int nPoints); +// Validates a LUT +LCMSBOOL cdecl _cmsValidateLUT(LPLUT NewLUT); + + // These are two VITAL macros, from converting between 8 and 16 bit // representation. @@ -2076,3 +2096,4 @@ LPGAMMATABLE _cmsBuildKToneCurve(cmsHTRANSFORM hCMYK2CMYK, int nPoints); #endif #endif + diff --git a/src/share/native/sun/nio/ch/genSocketOptionRegistry.c b/src/share/native/sun/nio/ch/genSocketOptionRegistry.c index 70f95c6c59b231673eb895f6478555470fd30fda..bcd546b139477158745140e2a73305cd3f22302c 100644 --- a/src/share/native/sun/nio/ch/genSocketOptionRegistry.c +++ b/src/share/native/sun/nio/ch/genSocketOptionRegistry.c @@ -1,5 +1,5 @@ /* - * Copyright 2007-2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2008-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 @@ -71,9 +71,9 @@ int main(int argc, const char* argv[]) { out("class SocketOptionRegistry { "); out(" private SocketOptionRegistry() { } "); out(" private static class RegistryKey { "); - out(" private final SocketOption name; "); + out(" private final SocketOption<?> name; "); out(" private final ProtocolFamily family; "); - out(" RegistryKey(SocketOption name, ProtocolFamily family) { "); + out(" RegistryKey(SocketOption<?> name, ProtocolFamily family) { "); out(" this.name = name; "); out(" this.family = family; "); out(" } "); @@ -119,7 +119,7 @@ int main(int argc, const char* argv[]) { out(" return map; "); out(" } "); out(" } "); - out(" public static OptionKey findOption(SocketOption name, ProtocolFamily family) { "); + out(" public static OptionKey findOption(SocketOption<?> name, ProtocolFamily family) { "); out(" RegistryKey key = new RegistryKey(name, family); "); out(" return LazyInitialization.options.get(key); "); out(" } "); diff --git a/src/share/native/sun/security/pkcs11/wrapper/p11_convert.c b/src/share/native/sun/security/pkcs11/wrapper/p11_convert.c index 81ecab813f9e3882419ad97ae949e1dc364bbd61..473729437d0bf5cf7ae1d75a08dfc27f943d7194 100644 --- a/src/share/native/sun/security/pkcs11/wrapper/p11_convert.c +++ b/src/share/native/sun/security/pkcs11/wrapper/p11_convert.c @@ -1,5 +1,5 @@ /* - * Portions Copyright 2003-2005 Sun Microsystems, Inc. All Rights Reserved. + * Portions Copyright 2003-2009 Sun Microsystems, Inc. All Rights Reserved. */ /* Copyright (c) 2002 Graz University of Technology. All rights reserved. @@ -89,21 +89,24 @@ jobject ckDatePtrToJDateObject(JNIEnv *env, const CK_DATE *ckpDate) /* load CK_DATE class */ jDateClass = (*env)->FindClass(env, CLASS_DATE); - assert(jDateClass != 0); + if (jDateClass == NULL) { return NULL; } /* load CK_DATE constructor */ jCtrId = (*env)->GetMethodID(env, jDateClass, "<init>", "([C[C[C)V"); - assert(jCtrId != 0); + if (jCtrId == NULL) { return NULL; } /* prep all fields */ jYear = ckCharArrayToJCharArray(env, (CK_CHAR_PTR)(ckpDate->year), 4); + if (jYear == NULL) { return NULL; } jMonth = ckCharArrayToJCharArray(env, (CK_CHAR_PTR)(ckpDate->month), 2); + if (jMonth == NULL) { return NULL; } jDay = ckCharArrayToJCharArray(env, (CK_CHAR_PTR)(ckpDate->day), 2); + if (jDay == NULL) { return NULL; } /* create new CK_DATE object */ jDateObject = (*env)->NewObject(env, jDateClass, jCtrId, jYear, jMonth, jDay); - assert(jDateObject != 0); + if (jDateObject == NULL) { return NULL; } /* free local references */ (*env)->DeleteLocalRef(env, jDateClass); @@ -131,11 +134,11 @@ jobject ckVersionPtrToJVersion(JNIEnv *env, const CK_VERSION_PTR ckpVersion) /* load CK_VERSION class */ jVersionClass = (*env)->FindClass(env, CLASS_VERSION); - assert(jVersionClass != 0); + if (jVersionClass == NULL) { return NULL; } /* load CK_VERSION constructor */ jCtrId = (*env)->GetMethodID(env, jVersionClass, "<init>", "(II)V"); - assert(jCtrId != 0); + if (jCtrId == NULL) { return NULL; } /* prep both fields */ jMajor = ckpVersion->major; @@ -144,7 +147,7 @@ jobject ckVersionPtrToJVersion(JNIEnv *env, const CK_VERSION_PTR ckpVersion) /* create new CK_VERSION object */ jVersionObject = (*env)->NewObject(env, jVersionClass, jCtrId, jMajor, jMinor); - assert(jVersionObject != 0); + if (jVersionObject == NULL) { return NULL; } /* free local references */ (*env)->DeleteLocalRef(env, jVersionClass); @@ -171,11 +174,11 @@ jobject ckSessionInfoPtrToJSessionInfo(JNIEnv *env, const CK_SESSION_INFO_PTR ck /* load CK_SESSION_INFO class */ jSessionInfoClass = (*env)->FindClass(env, CLASS_SESSION_INFO); - assert(jSessionInfoClass != 0); + if (jSessionInfoClass == NULL) { return NULL; } /* load CK_SESSION_INFO constructor */ jCtrId = (*env)->GetMethodID(env, jSessionInfoClass, "<init>", "(JJJJ)V"); - assert(jCtrId != 0); + if (jCtrId == NULL) { return NULL; } /* prep all fields */ jSlotID = ckULongToJLong(ckpSessionInfo->slotID); @@ -187,7 +190,7 @@ jobject ckSessionInfoPtrToJSessionInfo(JNIEnv *env, const CK_SESSION_INFO_PTR ck jSessionInfoObject = (*env)->NewObject(env, jSessionInfoClass, jCtrId, jSlotID, jState, jFlags, jDeviceError); - assert(jSessionInfoObject != 0); + if (jSessionInfoObject == NULL) { return NULL; } /* free local references */ (*env)->DeleteLocalRef(env, jSessionInfoClass); @@ -211,20 +214,21 @@ jobject ckAttributePtrToJAttribute(JNIEnv *env, const CK_ATTRIBUTE_PTR ckpAttrib jobject jPValue = NULL; jAttributeClass = (*env)->FindClass(env, CLASS_ATTRIBUTE); - assert(jAttributeClass != 0); + if (jAttributeClass == NULL) { return NULL; } /* load CK_INFO constructor */ jCtrId = (*env)->GetMethodID(env, jAttributeClass, "<init>", "(JLjava/lang/Object;)V"); - assert(jCtrId != 0); + if (jCtrId == NULL) { return NULL; } /* prep both fields */ jType = ckULongToJLong(ckpAttribute->type); jPValue = ckAttributeValueToJObject(env, ckpAttribute); + if ((*env)->ExceptionCheck(env)) { return NULL; } /* create new CK_ATTRIBUTE object */ jAttributeObject = (*env)->NewObject(env, jAttributeClass, jCtrId, jType, jPValue); - assert(jAttributeObject != 0); + if (jAttributeObject == NULL) { return NULL; } /* free local references */ (*env)->DeleteLocalRef(env, jAttributeClass); @@ -252,23 +256,27 @@ CK_VERSION_PTR jVersionToCKVersionPtr(JNIEnv *env, jobject jVersion) return NULL; } - /* allocate memory for CK_VERSION pointer */ - ckpVersion = (CK_VERSION_PTR) malloc(sizeof(CK_VERSION)); - /* get CK_VERSION class */ jVersionClass = (*env)->GetObjectClass(env, jVersion); - assert(jVersionClass != 0); + if (jVersionClass == NULL) { return NULL; } /* get Major */ jFieldID = (*env)->GetFieldID(env, jVersionClass, "major", "B"); - assert(jFieldID != 0); + if (jFieldID == NULL) { return NULL; } jMajor = (*env)->GetByteField(env, jVersion, jFieldID); - ckpVersion->major = jByteToCKByte(jMajor); /* get Minor */ jFieldID = (*env)->GetFieldID(env, jVersionClass, "minor", "B"); - assert(jFieldID != 0); + if (jFieldID == NULL) { return NULL; } jMinor = (*env)->GetByteField(env, jVersion, jFieldID); + + /* allocate memory for CK_VERSION pointer */ + ckpVersion = (CK_VERSION_PTR) malloc(sizeof(CK_VERSION)); + if (ckpVersion == NULL) { + JNU_ThrowOutOfMemoryError(env, 0); + return NULL; + } + ckpVersion->major = jByteToCKByte(jMajor); ckpVersion->minor = jByteToCKByte(jMinor); return ckpVersion ; @@ -292,18 +300,36 @@ CK_DATE * jDateObjectPtrToCKDatePtr(JNIEnv *env, jobject jDate) jchar *jTempChars; CK_ULONG i; - /* allocate memory for CK_DATE pointer */ - ckpDate = (CK_DATE *) malloc(sizeof(CK_DATE)); + if (jDate == NULL) { + return NULL; + } /* get CK_DATE class */ jDateClass = (*env)->FindClass(env, CLASS_DATE); - assert(jDateClass != 0); + if (jDateClass == NULL) { return NULL; } /* get Year */ jFieldID = (*env)->GetFieldID(env, jDateClass, "year", "[C"); - assert(jFieldID != 0); + if (jFieldID == NULL) { return NULL; } jYear = (*env)->GetObjectField(env, jDate, jFieldID); + /* get Month */ + jFieldID = (*env)->GetFieldID(env, jDateClass, "month", "[C"); + if (jFieldID == NULL) { return NULL; } + jMonth = (*env)->GetObjectField(env, jDate, jFieldID); + + /* get Day */ + jFieldID = (*env)->GetFieldID(env, jDateClass, "day", "[C"); + if (jFieldID == NULL) { return NULL; } + jDay = (*env)->GetObjectField(env, jDate, jFieldID); + + /* allocate memory for CK_DATE pointer */ + ckpDate = (CK_DATE *) malloc(sizeof(CK_DATE)); + if (ckpDate == NULL) { + JNU_ThrowOutOfMemoryError(env, 0); + return NULL; + } + if (jYear == NULL) { ckpDate->year[0] = 0; ckpDate->year[1] = 0; @@ -312,43 +338,66 @@ CK_DATE * jDateObjectPtrToCKDatePtr(JNIEnv *env, jobject jDate) } else { ckLength = (*env)->GetArrayLength(env, jYear); jTempChars = (jchar*) malloc((ckLength) * sizeof(jchar)); + if (jTempChars == NULL) { + free(ckpDate); + JNU_ThrowOutOfMemoryError(env, 0); + return NULL; + } (*env)->GetCharArrayRegion(env, jYear, 0, ckLength, jTempChars); + if ((*env)->ExceptionCheck(env)) { + free(ckpDate); + free(jTempChars); + return NULL; + } + for (i = 0; (i < ckLength) && (i < 4) ; i++) { ckpDate->year[i] = jCharToCKChar(jTempChars[i]); } free(jTempChars); } - /* get Month */ - jFieldID = (*env)->GetFieldID(env, jDateClass, "month", "[C"); - assert(jFieldID != 0); - jMonth = (*env)->GetObjectField(env, jDate, jFieldID); - if (jMonth == NULL) { ckpDate->month[0] = 0; ckpDate->month[1] = 0; } else { ckLength = (*env)->GetArrayLength(env, jMonth); jTempChars = (jchar*) malloc((ckLength) * sizeof(jchar)); + if (jTempChars == NULL) { + free(ckpDate); + JNU_ThrowOutOfMemoryError(env, 0); + return NULL; + } (*env)->GetCharArrayRegion(env, jMonth, 0, ckLength, jTempChars); + if ((*env)->ExceptionCheck(env)) { + free(ckpDate); + free(jTempChars); + return NULL; + } + for (i = 0; (i < ckLength) && (i < 4) ; i++) { ckpDate->month[i] = jCharToCKChar(jTempChars[i]); } free(jTempChars); } - /* get Day */ - jFieldID = (*env)->GetFieldID(env, jDateClass, "day", "[C"); - assert(jFieldID != 0); - jDay = (*env)->GetObjectField(env, jDate, jFieldID); - if (jDay == NULL) { ckpDate->day[0] = 0; ckpDate->day[1] = 0; } else { ckLength = (*env)->GetArrayLength(env, jDay); jTempChars = (jchar*) malloc((ckLength) * sizeof(jchar)); + if (jTempChars == NULL) { + free(ckpDate); + JNU_ThrowOutOfMemoryError(env, 0); + return NULL; + } (*env)->GetCharArrayRegion(env, jDay, 0, ckLength, jTempChars); + if ((*env)->ExceptionCheck(env)) { + free(ckpDate); + free(jTempChars); + return NULL; + } + for (i = 0; (i < ckLength) && (i < 4) ; i++) { ckpDate->day[i] = jCharToCKChar(jTempChars[i]); } @@ -374,23 +423,25 @@ CK_ATTRIBUTE jAttributeToCKAttribute(JNIEnv *env, jobject jAttribute) jlong jType; jobject jPValue; + // TBD: what if jAttribute == NULL?! + TRACE0("\nDEBUG: jAttributeToCKAttribute"); /* get CK_ATTRIBUTE class */ TRACE0(", getting attribute object class"); jAttributeClass = (*env)->GetObjectClass(env, jAttribute); - assert(jAttributeClass != 0); + if (jAttributeClass == NULL) { return ckAttribute; } /* get type */ TRACE0(", getting type field"); jFieldID = (*env)->GetFieldID(env, jAttributeClass, "type", "J"); - assert(jFieldID != 0); + if (jFieldID == NULL) { return ckAttribute; } jType = (*env)->GetLongField(env, jAttribute, jFieldID); TRACE1(", type=0x%X", jType); /* get pValue */ TRACE0(", getting pValue field"); jFieldID = (*env)->GetFieldID(env, jAttributeClass, "pValue", "Ljava/lang/Object;"); - assert(jFieldID != 0); + if (jFieldID == NULL) { return ckAttribute; } jPValue = (*env)->GetObjectField(env, jAttribute, jFieldID); TRACE1(", pValue=%p", jPValue); @@ -417,36 +468,50 @@ CK_SSL3_MASTER_KEY_DERIVE_PARAMS jSsl3MasterKeyDeriveParamToCKSsl3MasterKeyDeriv { // XXX don't return structs // XXX prefetch class and field ids - jclass jSsl3MasterKeyDeriveParamsClass = (*env)->FindClass(env, CLASS_SSL3_MASTER_KEY_DERIVE_PARAMS); + jclass jSsl3MasterKeyDeriveParamsClass; CK_SSL3_MASTER_KEY_DERIVE_PARAMS ckParam; jfieldID fieldID; - jobject jObject; jclass jSsl3RandomDataClass; - jobject jRandomInfo; + jobject jRandomInfo, jRIClientRandom, jRIServerRandom, jVersion; /* get RandomInfo */ - jSsl3RandomDataClass = (*env)->FindClass(env, CLASS_SSL3_RANDOM_DATA); + jSsl3MasterKeyDeriveParamsClass = (*env)->FindClass(env, CLASS_SSL3_MASTER_KEY_DERIVE_PARAMS); + if (jSsl3MasterKeyDeriveParamsClass == NULL) { return ckParam; } fieldID = (*env)->GetFieldID(env, jSsl3MasterKeyDeriveParamsClass, "RandomInfo", "Lsun/security/pkcs11/wrapper/CK_SSL3_RANDOM_DATA;"); - assert(fieldID != 0); + if (fieldID == NULL) { return ckParam; } jRandomInfo = (*env)->GetObjectField(env, jParam, fieldID); /* get pClientRandom and ulClientRandomLength out of RandomInfo */ + jSsl3RandomDataClass = (*env)->FindClass(env, CLASS_SSL3_RANDOM_DATA); + if (jSsl3RandomDataClass == NULL) { return ckParam; } fieldID = (*env)->GetFieldID(env, jSsl3RandomDataClass, "pClientRandom", "[B"); - assert(fieldID != 0); - jObject = (*env)->GetObjectField(env, jRandomInfo, fieldID); - jByteArrayToCKByteArray(env, jObject, &(ckParam.RandomInfo.pClientRandom), &(ckParam.RandomInfo.ulClientRandomLen)); + if (fieldID == NULL) { return ckParam; } + jRIClientRandom = (*env)->GetObjectField(env, jRandomInfo, fieldID); /* get pServerRandom and ulServerRandomLength out of RandomInfo */ fieldID = (*env)->GetFieldID(env, jSsl3RandomDataClass, "pServerRandom", "[B"); - assert(fieldID != 0); - jObject = (*env)->GetObjectField(env, jRandomInfo, fieldID); - jByteArrayToCKByteArray(env, jObject, &(ckParam.RandomInfo.pServerRandom), &(ckParam.RandomInfo.ulServerRandomLen)); + if (fieldID == NULL) { return ckParam; } + jRIServerRandom = (*env)->GetObjectField(env, jRandomInfo, fieldID); /* get pVersion */ fieldID = (*env)->GetFieldID(env, jSsl3MasterKeyDeriveParamsClass, "pVersion", "Lsun/security/pkcs11/wrapper/CK_VERSION;"); - assert(fieldID != 0); - jObject = (*env)->GetObjectField(env, jParam, fieldID); - ckParam.pVersion = jVersionToCKVersionPtr(env, jObject); + if (fieldID == NULL) { return ckParam; } + jVersion = (*env)->GetObjectField(env, jParam, fieldID); + + /* populate java values */ + ckParam.pVersion = jVersionToCKVersionPtr(env, jVersion); + if ((*env)->ExceptionCheck(env)) { return ckParam; } + jByteArrayToCKByteArray(env, jRIClientRandom, &(ckParam.RandomInfo.pClientRandom), &(ckParam.RandomInfo.ulClientRandomLen)); + if ((*env)->ExceptionCheck(env)) { + free(ckParam.pVersion); + return ckParam; + } + jByteArrayToCKByteArray(env, jRIServerRandom, &(ckParam.RandomInfo.pServerRandom), &(ckParam.RandomInfo.ulServerRandomLen)); + if ((*env)->ExceptionCheck(env)) { + free(ckParam.pVersion); + free(ckParam.RandomInfo.pClientRandom); + return ckParam; + } return ckParam ; } @@ -457,27 +522,52 @@ CK_SSL3_MASTER_KEY_DERIVE_PARAMS jSsl3MasterKeyDeriveParamToCKSsl3MasterKeyDeriv */ CK_TLS_PRF_PARAMS jTlsPrfParamsToCKTlsPrfParam(JNIEnv *env, jobject jParam) { - jclass jTlsPrfParamsClass = (*env)->FindClass(env, CLASS_TLS_PRF_PARAMS); + jclass jTlsPrfParamsClass; CK_TLS_PRF_PARAMS ckParam; jfieldID fieldID; - jobject jObject; + jobject jSeed, jLabel, jOutput; + // TBD: what if jParam == NULL?! + + /* get pSeed */ + jTlsPrfParamsClass = (*env)->FindClass(env, CLASS_TLS_PRF_PARAMS); + if (jTlsPrfParamsClass == NULL) { return ckParam; } fieldID = (*env)->GetFieldID(env, jTlsPrfParamsClass, "pSeed", "[B"); - assert(fieldID != 0); - jObject = (*env)->GetObjectField(env, jParam, fieldID); - jByteArrayToCKByteArray(env, jObject, &(ckParam.pSeed), &(ckParam.ulSeedLen)); + if (fieldID == NULL) { return ckParam; } + jSeed = (*env)->GetObjectField(env, jParam, fieldID); + /* get pLabel */ fieldID = (*env)->GetFieldID(env, jTlsPrfParamsClass, "pLabel", "[B"); - assert(fieldID != 0); - jObject = (*env)->GetObjectField(env, jParam, fieldID); - jByteArrayToCKByteArray(env, jObject, &(ckParam.pLabel), &(ckParam.ulLabelLen)); - - ckParam.pulOutputLen = malloc(sizeof(CK_ULONG)); + if (fieldID == NULL) { return ckParam; } + jLabel = (*env)->GetObjectField(env, jParam, fieldID); + /* get pOutput */ fieldID = (*env)->GetFieldID(env, jTlsPrfParamsClass, "pOutput", "[B"); - assert(fieldID != 0); - jObject = (*env)->GetObjectField(env, jParam, fieldID); - jByteArrayToCKByteArray(env, jObject, &(ckParam.pOutput), ckParam.pulOutputLen); + if (fieldID == NULL) { return ckParam; } + jOutput = (*env)->GetObjectField(env, jParam, fieldID); + + /* populate java values */ + jByteArrayToCKByteArray(env, jSeed, &(ckParam.pSeed), &(ckParam.ulSeedLen)); + if ((*env)->ExceptionCheck(env)) { return ckParam; } + jByteArrayToCKByteArray(env, jLabel, &(ckParam.pLabel), &(ckParam.ulLabelLen)); + if ((*env)->ExceptionCheck(env)) { + free(ckParam.pSeed); + return ckParam; + } + ckParam.pulOutputLen = malloc(sizeof(CK_ULONG)); + if (ckParam.pulOutputLen == NULL) { + free(ckParam.pSeed); + free(ckParam.pLabel); + JNU_ThrowOutOfMemoryError(env, 0); + return ckParam; + } + jByteArrayToCKByteArray(env, jOutput, &(ckParam.pOutput), ckParam.pulOutputLen); + if ((*env)->ExceptionCheck(env)) { + free(ckParam.pSeed); + free(ckParam.pLabel); + free(ckParam.pulOutputLen); + return ckParam; + } return ckParam ; } @@ -493,68 +583,91 @@ CK_SSL3_KEY_MAT_PARAMS jSsl3KeyMatParamToCKSsl3KeyMatParam(JNIEnv *env, jobject { // XXX don't return structs // XXX prefetch class and field ids - jclass jSsl3KeyMatParamsClass = (*env)->FindClass(env, CLASS_SSL3_KEY_MAT_PARAMS); + jclass jSsl3KeyMatParamsClass, jSsl3RandomDataClass, jSsl3KeyMatOutClass; CK_SSL3_KEY_MAT_PARAMS ckParam; jfieldID fieldID; - jlong jLong; - jboolean jBoolean; - jobject jObject; - jobject jRandomInfo; - jobject jReturnedKeyMaterial; - jclass jSsl3RandomDataClass; - jclass jSsl3KeyMatOutClass; + jlong jMacSizeInBits, jKeySizeInBits, jIVSizeInBits; + jboolean jIsExport; + jobject jRandomInfo, jRIClientRandom, jRIServerRandom; + jobject jReturnedKeyMaterial, jRMIvClient, jRMIvServer; CK_ULONG ckTemp; /* get ulMacSizeInBits */ + jSsl3KeyMatParamsClass = (*env)->FindClass(env, CLASS_SSL3_KEY_MAT_PARAMS); + if (jSsl3KeyMatParamsClass == NULL) { return ckParam; } fieldID = (*env)->GetFieldID(env, jSsl3KeyMatParamsClass, "ulMacSizeInBits", "J"); - assert(fieldID != 0); - jLong = (*env)->GetLongField(env, jParam, fieldID); - ckParam.ulMacSizeInBits = jLongToCKULong(jLong); + if (fieldID == NULL) { return ckParam; } + jMacSizeInBits = (*env)->GetLongField(env, jParam, fieldID); /* get ulKeySizeInBits */ fieldID = (*env)->GetFieldID(env, jSsl3KeyMatParamsClass, "ulKeySizeInBits", "J"); - assert(fieldID != 0); - jLong = (*env)->GetLongField(env, jParam, fieldID); - ckParam.ulKeySizeInBits = jLongToCKULong(jLong); + if (fieldID == NULL) { return ckParam; } + jKeySizeInBits = (*env)->GetLongField(env, jParam, fieldID); /* get ulIVSizeInBits */ fieldID = (*env)->GetFieldID(env, jSsl3KeyMatParamsClass, "ulIVSizeInBits", "J"); - assert(fieldID != 0); - jLong = (*env)->GetLongField(env, jParam, fieldID); - ckParam.ulIVSizeInBits = jLongToCKULong(jLong); + if (fieldID == NULL) { return ckParam; } + jIVSizeInBits = (*env)->GetLongField(env, jParam, fieldID); /* get bIsExport */ fieldID = (*env)->GetFieldID(env, jSsl3KeyMatParamsClass, "bIsExport", "Z"); - assert(fieldID != 0); - jBoolean = (*env)->GetBooleanField(env, jParam, fieldID); - ckParam.bIsExport = jBooleanToCKBBool(jBoolean); + if (fieldID == NULL) { return ckParam; } + jIsExport = (*env)->GetBooleanField(env, jParam, fieldID); /* get RandomInfo */ jSsl3RandomDataClass = (*env)->FindClass(env, CLASS_SSL3_RANDOM_DATA); + if (jSsl3RandomDataClass == NULL) { return ckParam; } fieldID = (*env)->GetFieldID(env, jSsl3KeyMatParamsClass, "RandomInfo", "Lsun/security/pkcs11/wrapper/CK_SSL3_RANDOM_DATA;"); - assert(fieldID != 0); + if (fieldID == NULL) { return ckParam; } jRandomInfo = (*env)->GetObjectField(env, jParam, fieldID); /* get pClientRandom and ulClientRandomLength out of RandomInfo */ fieldID = (*env)->GetFieldID(env, jSsl3RandomDataClass, "pClientRandom", "[B"); - assert(fieldID != 0); - jObject = (*env)->GetObjectField(env, jRandomInfo, fieldID); - jByteArrayToCKByteArray(env, jObject, &(ckParam.RandomInfo.pClientRandom), &(ckParam.RandomInfo.ulClientRandomLen)); + if (fieldID == NULL) { return ckParam; } + jRIClientRandom = (*env)->GetObjectField(env, jRandomInfo, fieldID); /* get pServerRandom and ulServerRandomLength out of RandomInfo */ fieldID = (*env)->GetFieldID(env, jSsl3RandomDataClass, "pServerRandom", "[B"); - assert(fieldID != 0); - jObject = (*env)->GetObjectField(env, jRandomInfo, fieldID); - jByteArrayToCKByteArray(env, jObject, &(ckParam.RandomInfo.pServerRandom), &(ckParam.RandomInfo.ulServerRandomLen)); + if (fieldID == NULL) { return ckParam; } + jRIServerRandom = (*env)->GetObjectField(env, jRandomInfo, fieldID); /* get pReturnedKeyMaterial */ jSsl3KeyMatOutClass = (*env)->FindClass(env, CLASS_SSL3_KEY_MAT_OUT); + if (jSsl3KeyMatOutClass == NULL) { return ckParam; } fieldID = (*env)->GetFieldID(env, jSsl3KeyMatParamsClass, "pReturnedKeyMaterial", "Lsun/security/pkcs11/wrapper/CK_SSL3_KEY_MAT_OUT;"); - assert(fieldID != 0); + if (fieldID == NULL) { return ckParam; } jReturnedKeyMaterial = (*env)->GetObjectField(env, jParam, fieldID); + /* get pIVClient out of pReturnedKeyMaterial */ + fieldID = (*env)->GetFieldID(env, jSsl3KeyMatOutClass, "pIVClient", "[B"); + if (fieldID == NULL) { return ckParam; } + jRMIvClient = (*env)->GetObjectField(env, jReturnedKeyMaterial, fieldID); + + /* get pIVServer out of pReturnedKeyMaterial */ + fieldID = (*env)->GetFieldID(env, jSsl3KeyMatOutClass, "pIVServer", "[B"); + if (fieldID == NULL) { return ckParam; } + jRMIvServer = (*env)->GetObjectField(env, jReturnedKeyMaterial, fieldID); + + /* populate java values */ + ckParam.ulMacSizeInBits = jLongToCKULong(jMacSizeInBits); + ckParam.ulKeySizeInBits = jLongToCKULong(jKeySizeInBits); + ckParam.ulIVSizeInBits = jLongToCKULong(jIVSizeInBits); + ckParam.bIsExport = jBooleanToCKBBool(jIsExport); + jByteArrayToCKByteArray(env, jRIClientRandom, &(ckParam.RandomInfo.pClientRandom), &(ckParam.RandomInfo.ulClientRandomLen)); + if ((*env)->ExceptionCheck(env)) { return ckParam; } + jByteArrayToCKByteArray(env, jRIServerRandom, &(ckParam.RandomInfo.pServerRandom), &(ckParam.RandomInfo.ulServerRandomLen)); + if ((*env)->ExceptionCheck(env)) { + free(ckParam.RandomInfo.pClientRandom); + return ckParam; + } /* allocate memory for pRetrunedKeyMaterial */ ckParam.pReturnedKeyMaterial = (CK_SSL3_KEY_MAT_OUT_PTR) malloc(sizeof(CK_SSL3_KEY_MAT_OUT)); + if (ckParam.pReturnedKeyMaterial == NULL) { + free(ckParam.RandomInfo.pClientRandom); + free(ckParam.RandomInfo.pServerRandom); + JNU_ThrowOutOfMemoryError(env, 0); + return ckParam; + } // the handles are output params only, no need to fetch them from Java ckParam.pReturnedKeyMaterial->hClientMacSecret = 0; @@ -562,17 +675,21 @@ CK_SSL3_KEY_MAT_PARAMS jSsl3KeyMatParamToCKSsl3KeyMatParam(JNIEnv *env, jobject ckParam.pReturnedKeyMaterial->hClientKey = 0; ckParam.pReturnedKeyMaterial->hServerKey = 0; - /* get pIVClient out of pReturnedKeyMaterial */ - fieldID = (*env)->GetFieldID(env, jSsl3KeyMatOutClass, "pIVClient", "[B"); - assert(fieldID != 0); - jObject = (*env)->GetObjectField(env, jReturnedKeyMaterial, fieldID); - jByteArrayToCKByteArray(env, jObject, &(ckParam.pReturnedKeyMaterial->pIVClient), &ckTemp); - - /* get pIVServer out of pReturnedKeyMaterial */ - fieldID = (*env)->GetFieldID(env, jSsl3KeyMatOutClass, "pIVServer", "[B"); - assert(fieldID != 0); - jObject = (*env)->GetObjectField(env, jReturnedKeyMaterial, fieldID); - jByteArrayToCKByteArray(env, jObject, &(ckParam.pReturnedKeyMaterial->pIVServer), &ckTemp); + jByteArrayToCKByteArray(env, jRMIvClient, &(ckParam.pReturnedKeyMaterial->pIVClient), &ckTemp); + if ((*env)->ExceptionCheck(env)) { + free(ckParam.RandomInfo.pClientRandom); + free(ckParam.RandomInfo.pServerRandom); + free(ckParam.pReturnedKeyMaterial); + return ckParam; + } + jByteArrayToCKByteArray(env, jRMIvServer, &(ckParam.pReturnedKeyMaterial->pIVServer), &ckTemp); + if ((*env)->ExceptionCheck(env)) { + free(ckParam.RandomInfo.pClientRandom); + free(ckParam.RandomInfo.pServerRandom); + free(ckParam.pReturnedKeyMaterial); + free(ckParam.pReturnedKeyMaterial->pIVClient); + return ckParam; + } return ckParam ; } @@ -811,7 +928,7 @@ void jMechanismParameterToCKMechanismParameter(JNIEnv *env, jobject jParam, CK_V *ckpParamPtr = jLongObjectToCKULongPtr(env, jParam); *ckpLength = sizeof(CK_ULONG); } else { - /* printf("slow path jMechanismParameterToCKMechanismParameter\n"); */ + TRACE0("\nSLOW PATH jMechanismParameterToCKMechanismParameter\n"); jMechanismParameterToCKMechanismParameterSlow(env, jParam, ckpParamPtr, ckpLength); } } @@ -819,40 +936,24 @@ void jMechanismParameterToCKMechanismParameter(JNIEnv *env, jobject jParam, CK_V void jMechanismParameterToCKMechanismParameterSlow(JNIEnv *env, jobject jParam, CK_VOID_PTR *ckpParamPtr, CK_ULONG *ckpLength) { /* get all Java mechanism parameter classes */ - jclass jVersionClass = (*env)->FindClass(env, CLASS_VERSION); - jclass jRsaPkcsOaepParamsClass = (*env)->FindClass(env, CLASS_RSA_PKCS_OAEP_PARAMS); - jclass jPbeParamsClass = (*env)->FindClass(env, CLASS_PBE_PARAMS); - jclass jPkcs5Pbkd2ParamsClass = (*env)->FindClass(env, CLASS_PKCS5_PBKD2_PARAMS); - - jclass jRsaPkcsPssParamsClass = (*env)->FindClass(env, CLASS_RSA_PKCS_PSS_PARAMS); - jclass jEcdh1DeriveParamsClass = (*env)->FindClass(env, CLASS_ECDH1_DERIVE_PARAMS); - jclass jEcdh2DeriveParamsClass = (*env)->FindClass(env, CLASS_ECDH2_DERIVE_PARAMS); - jclass jX942Dh1DeriveParamsClass = (*env)->FindClass(env, CLASS_X9_42_DH1_DERIVE_PARAMS); - jclass jX942Dh2DeriveParamsClass = (*env)->FindClass(env, CLASS_X9_42_DH2_DERIVE_PARAMS); - - jclass jSsl3MasterKeyDeriveParamsClass = (*env)->FindClass(env, CLASS_SSL3_MASTER_KEY_DERIVE_PARAMS); - jclass jSsl3KeyMatParamsClass = (*env)->FindClass(env, CLASS_SSL3_KEY_MAT_PARAMS); - jclass jTlsPrfParamsClass = (*env)->FindClass(env, CLASS_TLS_PRF_PARAMS); + jclass jVersionClass, jSsl3MasterKeyDeriveParamsClass, jSsl3KeyMatParamsClass; + jclass jTlsPrfParamsClass, jRsaPkcsOaepParamsClass, jPbeParamsClass; + jclass jPkcs5Pbkd2ParamsClass, jRsaPkcsPssParamsClass; + jclass jEcdh1DeriveParamsClass, jEcdh2DeriveParamsClass; + jclass jX942Dh1DeriveParamsClass, jX942Dh2DeriveParamsClass; + /* get all Java mechanism parameter classes */ TRACE0("\nDEBUG: jMechanismParameterToCKMechanismParameter"); - /* first check the most common cases */ -/* - if (jParam == NULL) { - *ckpParamPtr = NULL; - *ckpLength = 0; - } else if ((*env)->IsInstanceOf(env, jParam, jByteArrayClass)) { - jByteArrayToCKByteArray(env, jParam, (CK_BYTE_PTR *)ckpParamPtr, ckpLength); - } else if ((*env)->IsInstanceOf(env, jParam, jLongClass)) { - *ckpParamPtr = jLongObjectToCKULongPtr(env, jParam); - *ckpLength = sizeof(CK_ULONG); - } else if ((*env)->IsInstanceOf(env, jParam, jVersionClass)) { -*/ + /* most common cases, i.e. NULL/byte[]/long, are already handled by + * jMechanismParameterToCKMechanismParameter before calling this method. + */ + jVersionClass = (*env)->FindClass(env, CLASS_VERSION); + if (jVersionClass == NULL) { return; } if ((*env)->IsInstanceOf(env, jParam, jVersionClass)) { /* * CK_VERSION used by CKM_SSL3_PRE_MASTER_KEY_GEN */ - CK_VERSION_PTR ckpParam; /* convert jParameter to CKParameter */ @@ -861,191 +962,312 @@ void jMechanismParameterToCKMechanismParameterSlow(JNIEnv *env, jobject jParam, /* get length and pointer of parameter */ *ckpLength = sizeof(CK_VERSION); *ckpParamPtr = ckpParam; + return; + } - } else if ((*env)->IsInstanceOf(env, jParam, jSsl3MasterKeyDeriveParamsClass)) { + jSsl3MasterKeyDeriveParamsClass = (*env)->FindClass(env, CLASS_SSL3_MASTER_KEY_DERIVE_PARAMS); + if (jSsl3MasterKeyDeriveParamsClass == NULL) { return; } + if ((*env)->IsInstanceOf(env, jParam, jSsl3MasterKeyDeriveParamsClass)) { /* * CK_SSL3_MASTER_KEY_DERIVE_PARAMS */ - CK_SSL3_MASTER_KEY_DERIVE_PARAMS_PTR ckpParam; ckpParam = (CK_SSL3_MASTER_KEY_DERIVE_PARAMS_PTR) malloc(sizeof(CK_SSL3_MASTER_KEY_DERIVE_PARAMS)); + if (ckpParam == NULL) { + JNU_ThrowOutOfMemoryError(env, 0); + return; + } /* convert jParameter to CKParameter */ *ckpParam = jSsl3MasterKeyDeriveParamToCKSsl3MasterKeyDeriveParam(env, jParam); + if ((*env)->ExceptionCheck(env)) { + free(ckpParam); + return; + } /* get length and pointer of parameter */ *ckpLength = sizeof(CK_SSL3_MASTER_KEY_DERIVE_PARAMS); *ckpParamPtr = ckpParam; + return; + } - } else if ((*env)->IsInstanceOf(env, jParam, jSsl3KeyMatParamsClass)) { + jSsl3KeyMatParamsClass = (*env)->FindClass(env, CLASS_SSL3_KEY_MAT_PARAMS); + if (jSsl3KeyMatParamsClass == NULL) { return; } + if ((*env)->IsInstanceOf(env, jParam, jSsl3KeyMatParamsClass)) { /* * CK_SSL3_KEY_MAT_PARAMS */ - CK_SSL3_KEY_MAT_PARAMS_PTR ckpParam; ckpParam = (CK_SSL3_KEY_MAT_PARAMS_PTR) malloc(sizeof(CK_SSL3_KEY_MAT_PARAMS)); + if (ckpParam == NULL) { + JNU_ThrowOutOfMemoryError(env, 0); + return; + } /* convert jParameter to CKParameter */ *ckpParam = jSsl3KeyMatParamToCKSsl3KeyMatParam(env, jParam); + if ((*env)->ExceptionCheck(env)) { + free(ckpParam); + return; + } /* get length and pointer of parameter */ *ckpLength = sizeof(CK_SSL3_KEY_MAT_PARAMS); *ckpParamPtr = ckpParam; + return; + } - } else if ((*env)->IsInstanceOf(env, jParam, jTlsPrfParamsClass)) { - // - // CK_TLS_PRF_PARAMS - // - + jTlsPrfParamsClass = (*env)->FindClass(env, CLASS_TLS_PRF_PARAMS); + if (jTlsPrfParamsClass == NULL) { return; } + if ((*env)->IsInstanceOf(env, jParam, jTlsPrfParamsClass)) { + /* + * CK_TLS_PRF_PARAMS + */ CK_TLS_PRF_PARAMS_PTR ckpParam; ckpParam = (CK_TLS_PRF_PARAMS_PTR) malloc(sizeof(CK_TLS_PRF_PARAMS)); + if (ckpParam == NULL) { + JNU_ThrowOutOfMemoryError(env, 0); + return; + } - // convert jParameter to CKParameter + /* convert jParameter to CKParameter */ *ckpParam = jTlsPrfParamsToCKTlsPrfParam(env, jParam); + if ((*env)->ExceptionCheck(env)) { + free(ckpParam); + return; + } - // get length and pointer of parameter + /* get length and pointer of parameter */ *ckpLength = sizeof(CK_TLS_PRF_PARAMS); *ckpParamPtr = ckpParam; + return; + } - } else if ((*env)->IsInstanceOf(env, jParam, jRsaPkcsOaepParamsClass)) { + jRsaPkcsOaepParamsClass = (*env)->FindClass(env, CLASS_RSA_PKCS_OAEP_PARAMS); + if (jRsaPkcsOaepParamsClass == NULL) { return; } + if ((*env)->IsInstanceOf(env, jParam, jRsaPkcsOaepParamsClass)) { /* * CK_RSA_PKCS_OAEP_PARAMS */ - CK_RSA_PKCS_OAEP_PARAMS_PTR ckpParam; ckpParam = (CK_RSA_PKCS_OAEP_PARAMS_PTR) malloc(sizeof(CK_RSA_PKCS_OAEP_PARAMS)); + if (ckpParam == NULL) { + JNU_ThrowOutOfMemoryError(env, 0); + return; + } /* convert jParameter to CKParameter */ *ckpParam = jRsaPkcsOaepParamToCKRsaPkcsOaepParam(env, jParam); + if ((*env)->ExceptionCheck(env)) { + free(ckpParam); + return; + } /* get length and pointer of parameter */ *ckpLength = sizeof(CK_RSA_PKCS_OAEP_PARAMS); *ckpParamPtr = ckpParam; + return; + } - } else if ((*env)->IsInstanceOf(env, jParam, jPbeParamsClass)) { + jPbeParamsClass = (*env)->FindClass(env, CLASS_PBE_PARAMS); + if (jPbeParamsClass == NULL) { return; } + if ((*env)->IsInstanceOf(env, jParam, jPbeParamsClass)) { /* * CK_PBE_PARAMS */ - CK_PBE_PARAMS_PTR ckpParam; ckpParam = (CK_PBE_PARAMS_PTR) malloc(sizeof(CK_PBE_PARAMS)); + if (ckpParam == NULL) { + JNU_ThrowOutOfMemoryError(env, 0); + return; + } /* convert jParameter to CKParameter */ *ckpParam = jPbeParamToCKPbeParam(env, jParam); + if ((*env)->ExceptionCheck(env)) { + free(ckpParam); + return; + } /* get length and pointer of parameter */ *ckpLength = sizeof(CK_PBE_PARAMS); *ckpParamPtr = ckpParam; + return; + } - } else if ((*env)->IsInstanceOf(env, jParam, jPkcs5Pbkd2ParamsClass)) { + jPkcs5Pbkd2ParamsClass = (*env)->FindClass(env, CLASS_PKCS5_PBKD2_PARAMS); + if (jPkcs5Pbkd2ParamsClass == NULL) { return; } + if ((*env)->IsInstanceOf(env, jParam, jPkcs5Pbkd2ParamsClass)) { /* * CK_PKCS5_PBKD2_PARAMS */ - CK_PKCS5_PBKD2_PARAMS_PTR ckpParam; ckpParam = (CK_PKCS5_PBKD2_PARAMS_PTR) malloc(sizeof(CK_PKCS5_PBKD2_PARAMS)); + if (ckpParam == NULL) { + JNU_ThrowOutOfMemoryError(env, 0); + return; + } /* convert jParameter to CKParameter */ *ckpParam = jPkcs5Pbkd2ParamToCKPkcs5Pbkd2Param(env, jParam); + if ((*env)->ExceptionCheck(env)) { + free(ckpParam); + return; + } /* get length and pointer of parameter */ *ckpLength = sizeof(CK_PKCS5_PBKD2_PARAMS); *ckpParamPtr = ckpParam; + return; + } - } else if ((*env)->IsInstanceOf(env, jParam, jRsaPkcsPssParamsClass)) { + jRsaPkcsPssParamsClass = (*env)->FindClass(env, CLASS_RSA_PKCS_PSS_PARAMS); + if (jRsaPkcsPssParamsClass == NULL) { return; } + if ((*env)->IsInstanceOf(env, jParam, jRsaPkcsPssParamsClass)) { /* * CK_RSA_PKCS_PSS_PARAMS */ - CK_RSA_PKCS_PSS_PARAMS_PTR ckpParam; ckpParam = (CK_RSA_PKCS_PSS_PARAMS_PTR) malloc(sizeof(CK_RSA_PKCS_PSS_PARAMS)); + if (ckpParam == NULL) { + JNU_ThrowOutOfMemoryError(env, 0); + return; + } /* convert jParameter to CKParameter */ *ckpParam = jRsaPkcsPssParamToCKRsaPkcsPssParam(env, jParam); + if ((*env)->ExceptionCheck(env)) { + free(ckpParam); + return; + } /* get length and pointer of parameter */ *ckpLength = sizeof(CK_RSA_PKCS_PSS_PARAMS); *ckpParamPtr = ckpParam; + return; + } - } else if ((*env)->IsInstanceOf(env, jParam, jEcdh1DeriveParamsClass)) { + jEcdh1DeriveParamsClass = (*env)->FindClass(env, CLASS_ECDH1_DERIVE_PARAMS); + if (jEcdh1DeriveParamsClass == NULL) { return; } + if ((*env)->IsInstanceOf(env, jParam, jEcdh1DeriveParamsClass)) { /* * CK_ECDH1_DERIVE_PARAMS */ - CK_ECDH1_DERIVE_PARAMS_PTR ckpParam; ckpParam = (CK_ECDH1_DERIVE_PARAMS_PTR) malloc(sizeof(CK_ECDH1_DERIVE_PARAMS)); + if (ckpParam == NULL) { + JNU_ThrowOutOfMemoryError(env, 0); + return; + } /* convert jParameter to CKParameter */ *ckpParam = jEcdh1DeriveParamToCKEcdh1DeriveParam(env, jParam); + if ((*env)->ExceptionCheck(env)) { + free(ckpParam); + return; + } /* get length and pointer of parameter */ *ckpLength = sizeof(CK_ECDH1_DERIVE_PARAMS); *ckpParamPtr = ckpParam; + return; + } - } else if ((*env)->IsInstanceOf(env, jParam, jEcdh2DeriveParamsClass)) { + jEcdh2DeriveParamsClass = (*env)->FindClass(env, CLASS_ECDH2_DERIVE_PARAMS); + if (jEcdh2DeriveParamsClass == NULL) { return; } + if ((*env)->IsInstanceOf(env, jParam, jEcdh2DeriveParamsClass)) { /* * CK_ECDH2_DERIVE_PARAMS */ - CK_ECDH2_DERIVE_PARAMS_PTR ckpParam; ckpParam = (CK_ECDH2_DERIVE_PARAMS_PTR) malloc(sizeof(CK_ECDH2_DERIVE_PARAMS)); + if (ckpParam == NULL) { + JNU_ThrowOutOfMemoryError(env, 0); + return; + } /* convert jParameter to CKParameter */ *ckpParam = jEcdh2DeriveParamToCKEcdh2DeriveParam(env, jParam); + if ((*env)->ExceptionCheck(env)) { + free(ckpParam); + return; + } /* get length and pointer of parameter */ *ckpLength = sizeof(CK_ECDH2_DERIVE_PARAMS); *ckpParamPtr = ckpParam; + return; + } - } else if ((*env)->IsInstanceOf(env, jParam, jX942Dh1DeriveParamsClass)) { + jX942Dh1DeriveParamsClass = (*env)->FindClass(env, CLASS_X9_42_DH1_DERIVE_PARAMS); + if (jX942Dh1DeriveParamsClass == NULL) { return; } + if ((*env)->IsInstanceOf(env, jParam, jX942Dh1DeriveParamsClass)) { /* * CK_X9_42_DH1_DERIVE_PARAMS */ - CK_X9_42_DH1_DERIVE_PARAMS_PTR ckpParam; ckpParam = (CK_X9_42_DH1_DERIVE_PARAMS_PTR) malloc(sizeof(CK_X9_42_DH1_DERIVE_PARAMS)); + if (ckpParam == NULL) { + JNU_ThrowOutOfMemoryError(env, 0); + return; + } /* convert jParameter to CKParameter */ *ckpParam = jX942Dh1DeriveParamToCKX942Dh1DeriveParam(env, jParam); + if ((*env)->ExceptionCheck(env)) { + free(ckpParam); + return; + } /* get length and pointer of parameter */ *ckpLength = sizeof(CK_X9_42_DH1_DERIVE_PARAMS); *ckpParamPtr = ckpParam; + return; + } - } else if ((*env)->IsInstanceOf(env, jParam, jX942Dh2DeriveParamsClass)) { + jX942Dh2DeriveParamsClass = (*env)->FindClass(env, CLASS_X9_42_DH2_DERIVE_PARAMS); + if (jX942Dh2DeriveParamsClass == NULL) { return; } + if ((*env)->IsInstanceOf(env, jParam, jX942Dh2DeriveParamsClass)) { /* * CK_X9_42_DH2_DERIVE_PARAMS */ - CK_X9_42_DH2_DERIVE_PARAMS_PTR ckpParam; ckpParam = (CK_X9_42_DH2_DERIVE_PARAMS_PTR) malloc(sizeof(CK_X9_42_DH2_DERIVE_PARAMS)); + if (ckpParam == NULL) { + JNU_ThrowOutOfMemoryError(env, 0); + return; + } /* convert jParameter to CKParameter */ *ckpParam = jX942Dh2DeriveParamToCKX942Dh2DeriveParam(env, jParam); + if ((*env)->ExceptionCheck(env)) { + free(ckpParam); + return; + } /* get length and pointer of parameter */ *ckpLength = sizeof(CK_X9_42_DH2_DERIVE_PARAMS); *ckpParamPtr = ckpParam; - - } else { - /* if everything faild up to here */ - /* try if the parameter is a primitive Java type */ - jObjectToPrimitiveCKObjectPtrPtr(env, jParam, ckpParamPtr, ckpLength); - /* *ckpParamPtr = jObjectToCKVoidPtr(jParam); */ - /* *ckpLength = 1; */ + return; } + /* if everything faild up to here */ + /* try if the parameter is a primitive Java type */ + jObjectToPrimitiveCKObjectPtrPtr(env, jParam, ckpParamPtr, ckpLength); + /* *ckpParamPtr = jObjectToCKVoidPtr(jParam); */ + /* *ckpLength = 1; */ + TRACE0("FINISHED\n"); } @@ -1061,36 +1283,41 @@ void jMechanismParameterToCKMechanismParameterSlow(JNIEnv *env, jobject jParam, */ CK_RSA_PKCS_OAEP_PARAMS jRsaPkcsOaepParamToCKRsaPkcsOaepParam(JNIEnv *env, jobject jParam) { - jclass jRsaPkcsOaepParamsClass = (*env)->FindClass(env, CLASS_RSA_PKCS_OAEP_PARAMS); + jclass jRsaPkcsOaepParamsClass; CK_RSA_PKCS_OAEP_PARAMS ckParam; jfieldID fieldID; - jlong jLong; - jobject jObject; + jlong jHashAlg, jMgf, jSource; + jobject jSourceData; CK_BYTE_PTR ckpByte; /* get hashAlg */ + jRsaPkcsOaepParamsClass = (*env)->FindClass(env, CLASS_RSA_PKCS_OAEP_PARAMS); + if (jRsaPkcsOaepParamsClass == NULL) { return ckParam; } fieldID = (*env)->GetFieldID(env, jRsaPkcsOaepParamsClass, "hashAlg", "J"); - assert(fieldID != 0); - jLong = (*env)->GetLongField(env, jParam, fieldID); - ckParam.hashAlg = jLongToCKULong(jLong); + if (fieldID == NULL) { return ckParam; } + jHashAlg = (*env)->GetLongField(env, jParam, fieldID); /* get mgf */ fieldID = (*env)->GetFieldID(env, jRsaPkcsOaepParamsClass, "mgf", "J"); - assert(fieldID != 0); - jLong = (*env)->GetLongField(env, jParam, fieldID); - ckParam.mgf = jLongToCKULong(jLong); + if (fieldID == NULL) { return ckParam; } + jMgf = (*env)->GetLongField(env, jParam, fieldID); /* get source */ fieldID = (*env)->GetFieldID(env, jRsaPkcsOaepParamsClass, "source", "J"); - assert(fieldID != 0); - jLong = (*env)->GetLongField(env, jParam, fieldID); - ckParam.source = jLongToCKULong(jLong); + if (fieldID == NULL) { return ckParam; } + jSource = (*env)->GetLongField(env, jParam, fieldID); /* get sourceData and sourceDataLength */ fieldID = (*env)->GetFieldID(env, jRsaPkcsOaepParamsClass, "pSourceData", "[B"); - assert(fieldID != 0); - jObject = (*env)->GetObjectField(env, jParam, fieldID); - jByteArrayToCKByteArray(env, jObject, &ckpByte, &(ckParam.ulSourceDataLen)); + if (fieldID == NULL) { return ckParam; } + jSourceData = (*env)->GetObjectField(env, jParam, fieldID); + + /* populate java values */ + ckParam.hashAlg = jLongToCKULong(jHashAlg); + ckParam.mgf = jLongToCKULong(jMgf); + ckParam.source = jLongToCKULong(jSource); + jByteArrayToCKByteArray(env, jSourceData, & ckpByte, &(ckParam.ulSourceDataLen)); + if ((*env)->ExceptionCheck(env)) { return ckParam; } ckParam.pSourceData = (CK_VOID_PTR) ckpByte; return ckParam ; @@ -1105,36 +1332,50 @@ CK_RSA_PKCS_OAEP_PARAMS jRsaPkcsOaepParamToCKRsaPkcsOaepParam(JNIEnv *env, jobje */ CK_PBE_PARAMS jPbeParamToCKPbeParam(JNIEnv *env, jobject jParam) { - jclass jPbeParamsClass = (*env)->FindClass(env, CLASS_PBE_PARAMS); + jclass jPbeParamsClass; CK_PBE_PARAMS ckParam; jfieldID fieldID; - jlong jLong; - jobject jObject; + jlong jIteration; + jobject jInitVector, jPassword, jSalt; CK_ULONG ckTemp; /* get pInitVector */ + jPbeParamsClass = (*env)->FindClass(env, CLASS_PBE_PARAMS); + if (jPbeParamsClass == NULL) { return ckParam; } fieldID = (*env)->GetFieldID(env, jPbeParamsClass, "pInitVector", "[C"); - assert(fieldID != 0); - jObject = (*env)->GetObjectField(env, jParam, fieldID); - jCharArrayToCKCharArray(env, jObject, &(ckParam.pInitVector), &ckTemp); + if (fieldID == NULL) { return ckParam; } + jInitVector = (*env)->GetObjectField(env, jParam, fieldID); /* get pPassword and ulPasswordLength */ fieldID = (*env)->GetFieldID(env, jPbeParamsClass, "pPassword", "[C"); - assert(fieldID != 0); - jObject = (*env)->GetObjectField(env, jParam, fieldID); - jCharArrayToCKCharArray(env, jObject, &(ckParam.pPassword), &(ckParam.ulPasswordLen)); + if (fieldID == NULL) { return ckParam; } + jPassword = (*env)->GetObjectField(env, jParam, fieldID); /* get pSalt and ulSaltLength */ fieldID = (*env)->GetFieldID(env, jPbeParamsClass, "pSalt", "[C"); - assert(fieldID != 0); - jObject = (*env)->GetObjectField(env, jParam, fieldID); - jCharArrayToCKCharArray(env, jObject, &(ckParam.pSalt), &(ckParam.ulSaltLen)); + if (fieldID == NULL) { return ckParam; } + jSalt = (*env)->GetObjectField(env, jParam, fieldID); /* get ulIteration */ fieldID = (*env)->GetFieldID(env, jPbeParamsClass, "ulIteration", "J"); - assert(fieldID != 0); - jLong = (*env)->GetLongField(env, jParam, fieldID); - ckParam.ulIteration = jLongToCKULong(jLong); + if (fieldID == NULL) { return ckParam; } + jIteration = (*env)->GetLongField(env, jParam, fieldID); + + /* populate java values */ + ckParam.ulIteration = jLongToCKULong(jIteration); + jCharArrayToCKCharArray(env, jInitVector, &(ckParam.pInitVector), &ckTemp); + if ((*env)->ExceptionCheck(env)) { return ckParam; } + jCharArrayToCKCharArray(env, jPassword, &(ckParam.pPassword), &(ckParam.ulPasswordLen)); + if ((*env)->ExceptionCheck(env)) { + free(ckParam.pInitVector); + return ckParam; + } + jCharArrayToCKCharArray(env, jSalt, &(ckParam.pSalt), &(ckParam.ulSaltLen)); + if ((*env)->ExceptionCheck(env)) { + free(ckParam.pInitVector); + free(ckParam.pPassword); + return ckParam; + } return ckParam ; } @@ -1147,8 +1388,7 @@ CK_PBE_PARAMS jPbeParamToCKPbeParam(JNIEnv *env, jobject jParam) */ void copyBackPBEInitializationVector(JNIEnv *env, CK_MECHANISM *ckMechanism, jobject jMechanism) { - jclass jMechanismClass= (*env)->FindClass(env, CLASS_MECHANISM); - jclass jPbeParamsClass = (*env)->FindClass(env, CLASS_PBE_PARAMS); + jclass jMechanismClass, jPbeParamsClass; CK_PBE_PARAMS *ckParam; jfieldID fieldID; CK_MECHANISM_TYPE ckMechanismType; @@ -1161,8 +1401,10 @@ void copyBackPBEInitializationVector(JNIEnv *env, CK_MECHANISM *ckMechanism, job jchar* jInitVectorChars; /* get mechanism */ + jMechanismClass = (*env)->FindClass(env, CLASS_MECHANISM); + if (jMechanismClass == NULL) { return; } fieldID = (*env)->GetFieldID(env, jMechanismClass, "mechanism", "J"); - assert(fieldID != 0); + if (fieldID == NULL) { return; } jMechanismType = (*env)->GetLongField(env, jMechanism, fieldID); ckMechanismType = jLongToCKULong(jMechanismType); if (ckMechanismType != ckMechanism->mechanism) { @@ -1170,21 +1412,25 @@ void copyBackPBEInitializationVector(JNIEnv *env, CK_MECHANISM *ckMechanism, job return; } + jPbeParamsClass = (*env)->FindClass(env, CLASS_PBE_PARAMS); + if (jPbeParamsClass == NULL) { return; } ckParam = (CK_PBE_PARAMS *) ckMechanism->pParameter; if (ckParam != NULL_PTR) { initVector = ckParam->pInitVector; if (initVector != NULL_PTR) { /* get pParameter */ fieldID = (*env)->GetFieldID(env, jMechanismClass, "pParameter", "Ljava/lang/Object;"); - assert(fieldID != 0); + if (fieldID == NULL) { return; } jParameter = (*env)->GetObjectField(env, jMechanism, fieldID); fieldID = (*env)->GetFieldID(env, jPbeParamsClass, "pInitVektor", "[C"); - assert(fieldID != 0); + if (fieldID == NULL) { return; } jInitVector = (*env)->GetObjectField(env, jParameter, fieldID); if (jInitVector != NULL) { jInitVectorLength = (*env)->GetArrayLength(env, jInitVector); jInitVectorChars = (*env)->GetCharArrayElements(env, jInitVector, NULL); + if (jInitVectorChars == NULL) { return; } + /* copy the chars to the Java buffer */ for (i=0; i < jInitVectorLength; i++) { jInitVectorChars[i] = ckCharToJChar(initVector[i]); @@ -1205,41 +1451,50 @@ void copyBackPBEInitializationVector(JNIEnv *env, CK_MECHANISM *ckMechanism, job */ CK_PKCS5_PBKD2_PARAMS jPkcs5Pbkd2ParamToCKPkcs5Pbkd2Param(JNIEnv *env, jobject jParam) { - jclass jPkcs5Pbkd2ParamsClass = (*env)->FindClass(env, CLASS_PKCS5_PBKD2_PARAMS); + jclass jPkcs5Pbkd2ParamsClass; CK_PKCS5_PBKD2_PARAMS ckParam; jfieldID fieldID; - jlong jLong; - jobject jObject; + jlong jSaltSource, jIteration, jPrf; + jobject jSaltSourceData, jPrfData; /* get saltSource */ + jPkcs5Pbkd2ParamsClass = (*env)->FindClass(env, CLASS_PKCS5_PBKD2_PARAMS); + if (jPkcs5Pbkd2ParamsClass == NULL) { return ckParam; } fieldID = (*env)->GetFieldID(env, jPkcs5Pbkd2ParamsClass, "saltSource", "J"); - assert(fieldID != 0); - jLong = (*env)->GetLongField(env, jParam, fieldID); - ckParam.saltSource = jLongToCKULong(jLong); + if (fieldID == NULL) { return ckParam; } + jSaltSource = (*env)->GetLongField(env, jParam, fieldID); /* get pSaltSourceData */ fieldID = (*env)->GetFieldID(env, jPkcs5Pbkd2ParamsClass, "pSaltSourceData", "[B"); - assert(fieldID != 0); - jObject = (*env)->GetObjectField(env, jParam, fieldID); - jByteArrayToCKByteArray(env, jObject, (CK_BYTE_PTR *) &(ckParam.pSaltSourceData), &(ckParam.ulSaltSourceDataLen)); + if (fieldID == NULL) { return ckParam; } + jSaltSourceData = (*env)->GetObjectField(env, jParam, fieldID); /* get iterations */ fieldID = (*env)->GetFieldID(env, jPkcs5Pbkd2ParamsClass, "iterations", "J"); - assert(fieldID != 0); - jLong = (*env)->GetLongField(env, jParam, fieldID); - ckParam.iterations = jLongToCKULong(jLong); + if (fieldID == NULL) { return ckParam; } + jIteration = (*env)->GetLongField(env, jParam, fieldID); /* get prf */ fieldID = (*env)->GetFieldID(env, jPkcs5Pbkd2ParamsClass, "prf", "J"); - assert(fieldID != 0); - jLong = (*env)->GetLongField(env, jParam, fieldID); - ckParam.prf = jLongToCKULong(jLong); + if (fieldID == NULL) { return ckParam; } + jPrf = (*env)->GetLongField(env, jParam, fieldID); /* get pPrfData and ulPrfDataLength in byte */ fieldID = (*env)->GetFieldID(env, jPkcs5Pbkd2ParamsClass, "pPrfData", "[B"); - assert(fieldID != 0); - jObject = (*env)->GetObjectField(env, jParam, fieldID); - jByteArrayToCKByteArray(env, jObject, (CK_BYTE_PTR *) &(ckParam.pPrfData), &(ckParam.ulPrfDataLen)); + if (fieldID == NULL) { return ckParam; } + jPrfData = (*env)->GetObjectField(env, jParam, fieldID); + + /* populate java values */ + ckParam.saltSource = jLongToCKULong(jSaltSource); + jByteArrayToCKByteArray(env, jSaltSourceData, (CK_BYTE_PTR *) &(ckParam.pSaltSourceData), &(ckParam.ulSaltSourceDataLen)); + if ((*env)->ExceptionCheck(env)) { return ckParam; } + ckParam.iterations = jLongToCKULong(jIteration); + ckParam.prf = jLongToCKULong(jPrf); + jByteArrayToCKByteArray(env, jPrfData, (CK_BYTE_PTR *) &(ckParam.pPrfData), &(ckParam.ulPrfDataLen)); + if ((*env)->ExceptionCheck(env)) { + free(ckParam.pSaltSourceData); + return ckParam; + } return ckParam ; } @@ -1253,28 +1508,32 @@ CK_PKCS5_PBKD2_PARAMS jPkcs5Pbkd2ParamToCKPkcs5Pbkd2Param(JNIEnv *env, jobject j */ CK_RSA_PKCS_PSS_PARAMS jRsaPkcsPssParamToCKRsaPkcsPssParam(JNIEnv *env, jobject jParam) { - jclass jRsaPkcsPssParamsClass = (*env)->FindClass(env, CLASS_RSA_PKCS_PSS_PARAMS); + jclass jRsaPkcsPssParamsClass; CK_RSA_PKCS_PSS_PARAMS ckParam; jfieldID fieldID; - jlong jLong; + jlong jHashAlg, jMgf, jSLen; /* get hashAlg */ + jRsaPkcsPssParamsClass = (*env)->FindClass(env, CLASS_RSA_PKCS_PSS_PARAMS); + if (jRsaPkcsPssParamsClass == NULL) { return ckParam; } fieldID = (*env)->GetFieldID(env, jRsaPkcsPssParamsClass, "hashAlg", "J"); - assert(fieldID != 0); - jLong = (*env)->GetLongField(env, jParam, fieldID); - ckParam.hashAlg = jLongToCKULong(jLong); + if (fieldID == NULL) { return ckParam; } + jHashAlg = (*env)->GetLongField(env, jParam, fieldID); /* get mgf */ fieldID = (*env)->GetFieldID(env, jRsaPkcsPssParamsClass, "mgf", "J"); - assert(fieldID != 0); - jLong = (*env)->GetLongField(env, jParam, fieldID); - ckParam.mgf = jLongToCKULong(jLong); + if (fieldID == NULL) { return ckParam; } + jMgf = (*env)->GetLongField(env, jParam, fieldID); /* get sLen */ fieldID = (*env)->GetFieldID(env, jRsaPkcsPssParamsClass, "sLen", "J"); - assert(fieldID != 0); - jLong = (*env)->GetLongField(env, jParam, fieldID); - ckParam.sLen = jLongToCKULong(jLong); + if (fieldID == NULL) { return ckParam; } + jSLen = (*env)->GetLongField(env, jParam, fieldID); + + /* populate java values */ + ckParam.hashAlg = jLongToCKULong(jHashAlg); + ckParam.mgf = jLongToCKULong(jMgf); + ckParam.sLen = jLongToCKULong(jSLen); return ckParam ; } @@ -1288,29 +1547,39 @@ CK_RSA_PKCS_PSS_PARAMS jRsaPkcsPssParamToCKRsaPkcsPssParam(JNIEnv *env, jobject */ CK_ECDH1_DERIVE_PARAMS jEcdh1DeriveParamToCKEcdh1DeriveParam(JNIEnv *env, jobject jParam) { - jclass jEcdh1DeriveParamsClass = (*env)->FindClass(env, CLASS_ECDH1_DERIVE_PARAMS); + jclass jEcdh1DeriveParamsClass; CK_ECDH1_DERIVE_PARAMS ckParam; jfieldID fieldID; jlong jLong; - jobject jObject; + jobject jSharedData, jPublicData; /* get kdf */ + jEcdh1DeriveParamsClass = (*env)->FindClass(env, CLASS_ECDH1_DERIVE_PARAMS); + if (jEcdh1DeriveParamsClass == NULL) { return ckParam; } fieldID = (*env)->GetFieldID(env, jEcdh1DeriveParamsClass, "kdf", "J"); - assert(fieldID != 0); + if (fieldID == NULL) { return ckParam; } jLong = (*env)->GetLongField(env, jParam, fieldID); ckParam.kdf = jLongToCKULong(jLong); /* get pSharedData and ulSharedDataLen */ fieldID = (*env)->GetFieldID(env, jEcdh1DeriveParamsClass, "pSharedData", "[B"); - assert(fieldID != 0); - jObject = (*env)->GetObjectField(env, jParam, fieldID); - jByteArrayToCKByteArray(env, jObject, &(ckParam.pSharedData), &(ckParam.ulSharedDataLen)); + if (fieldID == NULL) { return ckParam; } + jSharedData = (*env)->GetObjectField(env, jParam, fieldID); /* get pPublicData and ulPublicDataLen */ fieldID = (*env)->GetFieldID(env, jEcdh1DeriveParamsClass, "pPublicData", "[B"); - assert(fieldID != 0); - jObject = (*env)->GetObjectField(env, jParam, fieldID); - jByteArrayToCKByteArray(env, jObject, &(ckParam.pPublicData), &(ckParam.ulPublicDataLen)); + if (fieldID == NULL) { return ckParam; } + jPublicData = (*env)->GetObjectField(env, jParam, fieldID); + + /* populate java values */ + ckParam.kdf = jLongToCKULong(jLong); + jByteArrayToCKByteArray(env, jSharedData, &(ckParam.pSharedData), &(ckParam.ulSharedDataLen)); + if ((*env)->ExceptionCheck(env)) { return ckParam; } + jByteArrayToCKByteArray(env, jPublicData, &(ckParam.pPublicData), &(ckParam.ulPublicDataLen)); + if ((*env)->ExceptionCheck(env)) { + free(ckParam.pSharedData); + return ckParam; + } return ckParam ; } @@ -1324,48 +1593,61 @@ CK_ECDH1_DERIVE_PARAMS jEcdh1DeriveParamToCKEcdh1DeriveParam(JNIEnv *env, jobjec */ CK_ECDH2_DERIVE_PARAMS jEcdh2DeriveParamToCKEcdh2DeriveParam(JNIEnv *env, jobject jParam) { - jclass jEcdh2DeriveParamsClass = (*env)->FindClass(env, CLASS_ECDH2_DERIVE_PARAMS); + jclass jEcdh2DeriveParamsClass; CK_ECDH2_DERIVE_PARAMS ckParam; jfieldID fieldID; - jlong jLong; - jobject jObject; + jlong jKdf, jPrivateDataLen, jPrivateData; + jobject jSharedData, jPublicData, jPublicData2; /* get kdf */ + jEcdh2DeriveParamsClass = (*env)->FindClass(env, CLASS_ECDH2_DERIVE_PARAMS); + if (jEcdh2DeriveParamsClass == NULL) { return ckParam; } fieldID = (*env)->GetFieldID(env, jEcdh2DeriveParamsClass, "kdf", "J"); - assert(fieldID != 0); - jLong = (*env)->GetLongField(env, jParam, fieldID); - ckParam.kdf = jLongToCKULong(jLong); + if (fieldID == NULL) { return ckParam; } + jKdf = (*env)->GetLongField(env, jParam, fieldID); /* get pSharedData and ulSharedDataLen */ fieldID = (*env)->GetFieldID(env, jEcdh2DeriveParamsClass, "pSharedData", "[B"); - assert(fieldID != 0); - jObject = (*env)->GetObjectField(env, jParam, fieldID); - jByteArrayToCKByteArray(env, jObject, &(ckParam.pSharedData), &(ckParam.ulSharedDataLen)); + if (fieldID == NULL) { return ckParam; } + jSharedData = (*env)->GetObjectField(env, jParam, fieldID); /* get pPublicData and ulPublicDataLen */ fieldID = (*env)->GetFieldID(env, jEcdh2DeriveParamsClass, "pPublicData", "[B"); - assert(fieldID != 0); - jObject = (*env)->GetObjectField(env, jParam, fieldID); - jByteArrayToCKByteArray(env, jObject, &(ckParam.pPublicData), &(ckParam.ulPublicDataLen)); + if (fieldID == NULL) { return ckParam; } + jPublicData = (*env)->GetObjectField(env, jParam, fieldID); /* get ulPrivateDataLen */ fieldID = (*env)->GetFieldID(env, jEcdh2DeriveParamsClass, "ulPrivateDataLen", "J"); - assert(fieldID != 0); - jLong = (*env)->GetLongField(env, jParam, fieldID); - ckParam.ulPrivateDataLen = jLongToCKULong(jLong); + if (fieldID == NULL) { return ckParam; } + jPrivateDataLen = (*env)->GetLongField(env, jParam, fieldID); /* get hPrivateData */ fieldID = (*env)->GetFieldID(env, jEcdh2DeriveParamsClass, "hPrivateData", "J"); - assert(fieldID != 0); - jLong = (*env)->GetLongField(env, jParam, fieldID); - ckParam.hPrivateData = jLongToCKULong(jLong); + if (fieldID == NULL) { return ckParam; } + jPrivateData = (*env)->GetLongField(env, jParam, fieldID); /* get pPublicData2 and ulPublicDataLen2 */ fieldID = (*env)->GetFieldID(env, jEcdh2DeriveParamsClass, "pPublicData2", "[B"); - assert(fieldID != 0); - jObject = (*env)->GetObjectField(env, jParam, fieldID); - jByteArrayToCKByteArray(env, jObject, &(ckParam.pPublicData2), &(ckParam.ulPublicDataLen2)); - + if (fieldID == NULL) { return ckParam; } + jPublicData2 = (*env)->GetObjectField(env, jParam, fieldID); + + /* populate java values */ + ckParam.kdf = jLongToCKULong(jKdf); + jByteArrayToCKByteArray(env, jSharedData, &(ckParam.pSharedData), &(ckParam.ulSharedDataLen)); + if ((*env)->ExceptionCheck(env)) { return ckParam; } + jByteArrayToCKByteArray(env, jPublicData, &(ckParam.pPublicData), &(ckParam.ulPublicDataLen)); + if ((*env)->ExceptionCheck(env)) { + free(ckParam.pSharedData); + return ckParam; + } + ckParam.ulPrivateDataLen = jLongToCKULong(jPrivateDataLen); + ckParam.hPrivateData = jLongToCKULong(jPrivateData); + jByteArrayToCKByteArray(env, jPublicData2, &(ckParam.pPublicData2), &(ckParam.ulPublicDataLen2)); + if ((*env)->ExceptionCheck(env)) { + free(ckParam.pSharedData); + free(ckParam.pPublicData); + return ckParam; + } return ckParam ; } @@ -1378,29 +1660,38 @@ CK_ECDH2_DERIVE_PARAMS jEcdh2DeriveParamToCKEcdh2DeriveParam(JNIEnv *env, jobjec */ CK_X9_42_DH1_DERIVE_PARAMS jX942Dh1DeriveParamToCKX942Dh1DeriveParam(JNIEnv *env, jobject jParam) { - jclass jX942Dh1DeriveParamsClass = (*env)->FindClass(env, CLASS_X9_42_DH1_DERIVE_PARAMS); + jclass jX942Dh1DeriveParamsClass; CK_X9_42_DH1_DERIVE_PARAMS ckParam; jfieldID fieldID; - jlong jLong; - jobject jObject; + jlong jKdf; + jobject jOtherInfo, jPublicData; /* get kdf */ + jX942Dh1DeriveParamsClass = (*env)->FindClass(env, CLASS_X9_42_DH1_DERIVE_PARAMS); + if (jX942Dh1DeriveParamsClass == NULL) { return ckParam; } fieldID = (*env)->GetFieldID(env, jX942Dh1DeriveParamsClass, "kdf", "J"); - assert(fieldID != 0); - jLong = (*env)->GetLongField(env, jParam, fieldID); - ckParam.kdf = jLongToCKULong(jLong); + if (fieldID == NULL) { return ckParam; } + jKdf = (*env)->GetLongField(env, jParam, fieldID); /* get pOtherInfo and ulOtherInfoLen */ fieldID = (*env)->GetFieldID(env, jX942Dh1DeriveParamsClass, "pOtherInfo", "[B"); - assert(fieldID != 0); - jObject = (*env)->GetObjectField(env, jParam, fieldID); - jByteArrayToCKByteArray(env, jObject, &(ckParam.pOtherInfo), &(ckParam.ulOtherInfoLen)); + if (fieldID == NULL) { return ckParam; } + jOtherInfo = (*env)->GetObjectField(env, jParam, fieldID); /* get pPublicData and ulPublicDataLen */ fieldID = (*env)->GetFieldID(env, jX942Dh1DeriveParamsClass, "pPublicData", "[B"); - assert(fieldID != 0); - jObject = (*env)->GetObjectField(env, jParam, fieldID); - jByteArrayToCKByteArray(env, jObject, &(ckParam.pPublicData), &(ckParam.ulPublicDataLen)); + if (fieldID == NULL) { return ckParam; } + jPublicData = (*env)->GetObjectField(env, jParam, fieldID); + + /* populate java values */ + ckParam.kdf = jLongToCKULong(jKdf); + jByteArrayToCKByteArray(env, jOtherInfo, &(ckParam.pOtherInfo), &(ckParam.ulOtherInfoLen)); + if ((*env)->ExceptionCheck(env)) { return ckParam; } + jByteArrayToCKByteArray(env, jPublicData, &(ckParam.pPublicData), &(ckParam.ulPublicDataLen)); + if ((*env)->ExceptionCheck(env)) { + free(ckParam.pOtherInfo); + return ckParam; + } return ckParam ; } @@ -1414,47 +1705,61 @@ CK_X9_42_DH1_DERIVE_PARAMS jX942Dh1DeriveParamToCKX942Dh1DeriveParam(JNIEnv *env */ CK_X9_42_DH2_DERIVE_PARAMS jX942Dh2DeriveParamToCKX942Dh2DeriveParam(JNIEnv *env, jobject jParam) { - jclass jX942Dh2DeriveParamsClass = (*env)->FindClass(env, CLASS_X9_42_DH2_DERIVE_PARAMS); + jclass jX942Dh2DeriveParamsClass; CK_X9_42_DH2_DERIVE_PARAMS ckParam; jfieldID fieldID; - jlong jLong; - jobject jObject; + jlong jKdf, jPrivateDataLen, jPrivateData; + jobject jOtherInfo, jPublicData, jPublicData2; /* get kdf */ + jX942Dh2DeriveParamsClass = (*env)->FindClass(env, CLASS_X9_42_DH2_DERIVE_PARAMS); + if (jX942Dh2DeriveParamsClass == NULL) { return ckParam; } fieldID = (*env)->GetFieldID(env, jX942Dh2DeriveParamsClass, "kdf", "J"); - assert(fieldID != 0); - jLong = (*env)->GetLongField(env, jParam, fieldID); - ckParam.kdf = jLongToCKULong(jLong); + if (fieldID == NULL) { return ckParam; } + jKdf = (*env)->GetLongField(env, jParam, fieldID); /* get pOtherInfo and ulOtherInfoLen */ fieldID = (*env)->GetFieldID(env, jX942Dh2DeriveParamsClass, "pOtherInfo", "[B"); - assert(fieldID != 0); - jObject = (*env)->GetObjectField(env, jParam, fieldID); - jByteArrayToCKByteArray(env, jObject, &(ckParam.pOtherInfo), &(ckParam.ulOtherInfoLen)); + if (fieldID == NULL) { return ckParam; } + jOtherInfo = (*env)->GetObjectField(env, jParam, fieldID); /* get pPublicData and ulPublicDataLen */ fieldID = (*env)->GetFieldID(env, jX942Dh2DeriveParamsClass, "pPublicData", "[B"); - assert(fieldID != 0); - jObject = (*env)->GetObjectField(env, jParam, fieldID); - jByteArrayToCKByteArray(env, jObject, &(ckParam.pPublicData), &(ckParam.ulPublicDataLen)); + if (fieldID == NULL) { return ckParam; } + jPublicData = (*env)->GetObjectField(env, jParam, fieldID); /* get ulPrivateDataLen */ fieldID = (*env)->GetFieldID(env, jX942Dh2DeriveParamsClass, "ulPrivateDataLen", "J"); - assert(fieldID != 0); - jLong = (*env)->GetLongField(env, jParam, fieldID); - ckParam.ulPrivateDataLen = jLongToCKULong(jLong); + if (fieldID == NULL) { return ckParam; } + jPrivateDataLen = (*env)->GetLongField(env, jParam, fieldID); /* get hPrivateData */ fieldID = (*env)->GetFieldID(env, jX942Dh2DeriveParamsClass, "hPrivateData", "J"); - assert(fieldID != 0); - jLong = (*env)->GetLongField(env, jParam, fieldID); - ckParam.hPrivateData = jLongToCKULong(jLong); + if (fieldID == NULL) { return ckParam; } + jPrivateData = (*env)->GetLongField(env, jParam, fieldID); /* get pPublicData2 and ulPublicDataLen2 */ fieldID = (*env)->GetFieldID(env, jX942Dh2DeriveParamsClass, "pPublicData2", "[B"); - assert(fieldID != 0); - jObject = (*env)->GetObjectField(env, jParam, fieldID); - jByteArrayToCKByteArray(env, jObject, &(ckParam.pPublicData2), &(ckParam.ulPublicDataLen2)); + if (fieldID == NULL) { return ckParam; } + jPublicData2 = (*env)->GetObjectField(env, jParam, fieldID); + + /* populate java values */ + ckParam.kdf = jLongToCKULong(jKdf); + jByteArrayToCKByteArray(env, jOtherInfo, &(ckParam.pOtherInfo), &(ckParam.ulOtherInfoLen)); + if ((*env)->ExceptionCheck(env)) { return ckParam; } + jByteArrayToCKByteArray(env, jPublicData, &(ckParam.pPublicData), &(ckParam.ulPublicDataLen)); + if ((*env)->ExceptionCheck(env)) { + free(ckParam.pOtherInfo); + return ckParam; + } + ckParam.ulPrivateDataLen = jLongToCKULong(jPrivateDataLen); + ckParam.hPrivateData = jLongToCKULong(jPrivateData); + jByteArrayToCKByteArray(env, jPublicData2, &(ckParam.pPublicData2), &(ckParam.ulPublicDataLen2)); + if ((*env)->ExceptionCheck(env)) { + free(ckParam.pOtherInfo); + free(ckParam.pPublicData); + return ckParam; + } return ckParam ; } diff --git a/src/share/native/sun/security/pkcs11/wrapper/p11_crypt.c b/src/share/native/sun/security/pkcs11/wrapper/p11_crypt.c index bbcbe90e3178fb213adeb9cc1508a7805e4f00f5..63366d4358021a092b45f7e46028bec24f58b6e8 100644 --- a/src/share/native/sun/security/pkcs11/wrapper/p11_crypt.c +++ b/src/share/native/sun/security/pkcs11/wrapper/p11_crypt.c @@ -1,5 +1,5 @@ /* - * Portions Copyright 2003-2007 Sun Microsystems, Inc. All Rights Reserved. + * Portions Copyright 2003-2009 Sun Microsystems, Inc. All Rights Reserved. */ /* Copyright (c) 2002 Graz University of Technology. All rights reserved. @@ -81,6 +81,7 @@ Java_sun_security_pkcs11_wrapper_PKCS11_C_1EncryptInit ckSessionHandle = jLongToCKULong(jSessionHandle); ckKeyHandle = jLongToCKULong(jKeyHandle); jMechanismToCKMechanism(env, jMechanism, &ckMechanism); + if ((*env)->ExceptionCheck(env)) { return; } rv = (*ckpFunctions->C_EncryptInit)(ckSessionHandle, &ckMechanism, ckKeyHandle); @@ -126,14 +127,29 @@ Java_sun_security_pkcs11_wrapper_PKCS11_C_1Encrypt if (jInLen > MAX_STACK_BUFFER_LEN) { inBufP = (CK_BYTE_PTR)malloc((size_t)jInLen); + if (inBufP == NULL) { + JNU_ThrowOutOfMemoryError(env, 0); + return 0; + } } else { inBufP = IBUF; } (*env)->GetByteArrayRegion(env, jIn, jInOfs, jInLen, (jbyte *)inBufP); + if ((*env)->ExceptionCheck(env)) { + if (inBufP != IBUF) { free(inBufP); } + return 0; + } ckEncryptedPartLen = jOutLen; if (jOutLen > MAX_STACK_BUFFER_LEN) { outBufP = (CK_BYTE_PTR)malloc((size_t)jOutLen); + if (outBufP == NULL) { + if (inBufP != IBUF) { + free(inBufP); + } + JNU_ThrowOutOfMemoryError(env, 0); + return 0; + } } else { outBufP = OBUF; } @@ -193,10 +209,18 @@ Java_sun_security_pkcs11_wrapper_PKCS11_C_1EncryptUpdate } else { if (jInLen > MAX_STACK_BUFFER_LEN) { inBufP = (CK_BYTE_PTR)malloc((size_t)jInLen); + if (inBufP == NULL) { + JNU_ThrowOutOfMemoryError(env, 0); + return 0; + } } else { inBufP = IBUF; } (*env)->GetByteArrayRegion(env, jIn, jInOfs, jInLen, (jbyte *)inBufP); + if ((*env)->ExceptionCheck(env)) { + if (directIn == 0 && inBufP != IBUF) { free(inBufP); } + return 0; + } } ckEncryptedPartLen = jOutLen; @@ -205,6 +229,13 @@ Java_sun_security_pkcs11_wrapper_PKCS11_C_1EncryptUpdate } else { if (jOutLen > MAX_STACK_BUFFER_LEN) { outBufP = (CK_BYTE_PTR)malloc((size_t)jOutLen); + if (outBufP == NULL) { + if (directIn == 0 && inBufP != IBUF) { + free(inBufP); + } + JNU_ThrowOutOfMemoryError(env, 0); + return 0; + } } else { outBufP = OBUF; } @@ -317,6 +348,7 @@ Java_sun_security_pkcs11_wrapper_PKCS11_C_1DecryptInit ckSessionHandle = jLongToCKULong(jSessionHandle); ckKeyHandle = jLongToCKULong(jKeyHandle); jMechanismToCKMechanism(env, jMechanism, &ckMechanism); + if ((*env)->ExceptionCheck(env)) { return; } rv = (*ckpFunctions->C_DecryptInit)(ckSessionHandle, &ckMechanism, ckKeyHandle); @@ -362,14 +394,29 @@ Java_sun_security_pkcs11_wrapper_PKCS11_C_1Decrypt if (jInLen > MAX_STACK_BUFFER_LEN) { inBufP = (CK_BYTE_PTR)malloc((size_t)jInLen); + if (inBufP == NULL) { + JNU_ThrowOutOfMemoryError(env, 0); + return 0; + } } else { inBufP = IBUF; } (*env)->GetByteArrayRegion(env, jIn, jInOfs, jInLen, (jbyte *)inBufP); + if ((*env)->ExceptionCheck(env)) { + if (inBufP != IBUF) { free(inBufP); } + return 0; + } ckPartLen = jOutLen; if (jOutLen > MAX_STACK_BUFFER_LEN) { outBufP = (CK_BYTE_PTR)malloc((size_t)jOutLen); + if (outBufP == NULL) { + if (inBufP != IBUF) { + free(inBufP); + } + JNU_ThrowOutOfMemoryError(env, 0); + return 0; + } } else { outBufP = OBUF; } @@ -429,10 +476,18 @@ Java_sun_security_pkcs11_wrapper_PKCS11_C_1DecryptUpdate } else { if (jInLen > MAX_STACK_BUFFER_LEN) { inBufP = (CK_BYTE_PTR)malloc((size_t)jInLen); + if (inBufP == NULL) { + JNU_ThrowOutOfMemoryError(env, 0); + return 0; + } } else { inBufP = IBUF; } (*env)->GetByteArrayRegion(env, jIn, jInOfs, jInLen, (jbyte *)inBufP); + if ((*env)->ExceptionCheck(env)) { + if (directIn == 0 && inBufP != IBUF) { free(inBufP); } + return 0; + } } ckDecryptedPartLen = jOutLen; @@ -441,6 +496,13 @@ Java_sun_security_pkcs11_wrapper_PKCS11_C_1DecryptUpdate } else { if (jOutLen > MAX_STACK_BUFFER_LEN) { outBufP = (CK_BYTE_PTR)malloc((size_t)jOutLen); + if (outBufP == NULL) { + if (directIn == 0 && inBufP != IBUF) { + free(inBufP); + } + JNU_ThrowOutOfMemoryError(env, 0); + return 0; + } } else { outBufP = OBUF; } diff --git a/src/share/native/sun/security/pkcs11/wrapper/p11_digest.c b/src/share/native/sun/security/pkcs11/wrapper/p11_digest.c index 978479bb311ddbf03a42cc01f08624c355924ea2..8ff5ecc1b0290253eb3f79e7bec40927ea211d90 100644 --- a/src/share/native/sun/security/pkcs11/wrapper/p11_digest.c +++ b/src/share/native/sun/security/pkcs11/wrapper/p11_digest.c @@ -1,5 +1,5 @@ /* - * Portions Copyright 2003 Sun Microsystems, Inc. All Rights Reserved. + * Portions Copyright 2003-2009 Sun Microsystems, Inc. All Rights Reserved. */ /* Copyright (c) 2002 Graz University of Technology. All rights reserved. @@ -75,6 +75,7 @@ JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1DigestInit ckSessionHandle = jLongToCKULong(jSessionHandle); jMechanismToCKMechanism(env, jMechanism, &ckMechanism); + if ((*env)->ExceptionCheck(env)) { return; } rv = (*ckpFunctions->C_DigestInit)(ckSessionHandle, &ckMechanism); @@ -82,7 +83,7 @@ JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1DigestInit free(ckMechanism.pParameter); } - if(ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return; } + if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return; } } #endif @@ -114,6 +115,7 @@ JNIEXPORT jint JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1DigestSingle ckSessionHandle = jLongToCKULong(jSessionHandle); jMechanismToCKMechanism(env, jMechanism, &ckMechanism); + if ((*env)->ExceptionCheck(env)) { return 0; } rv = (*ckpFunctions->C_DigestInit)(ckSessionHandle, &ckMechanism); @@ -121,29 +123,32 @@ JNIEXPORT jint JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1DigestSingle free(ckMechanism.pParameter); } - if(ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return 0; } + if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return 0; } if (jInLen <= MAX_STACK_BUFFER_LEN) { bufP = BUF; } else { /* always use single part op, even for large data */ - bufP = (CK_BYTE_PTR)malloc((size_t)jInLen); + bufP = (CK_BYTE_PTR) malloc((size_t)jInLen); + if (bufP == NULL) { + JNU_ThrowOutOfMemoryError(env, 0); + return 0; + } } (*env)->GetByteArrayRegion(env, jIn, jInOfs, jInLen, (jbyte *)bufP); - rv = (*ckpFunctions->C_Digest)(ckSessionHandle, bufP, jInLen, DIGESTBUF, &ckDigestLength); - if(ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { - if (bufP != BUF) { - free(bufP); - } + if ((*env)->ExceptionCheck(env)) { + if (bufP != BUF) { free(bufP); } return 0; } - (*env)->SetByteArrayRegion(env, jDigest, jDigestOfs, ckDigestLength, (jbyte *)DIGESTBUF); - - if (bufP != BUF) { - free(bufP); + rv = (*ckpFunctions->C_Digest)(ckSessionHandle, bufP, jInLen, DIGESTBUF, &ckDigestLength); + if (ckAssertReturnValueOK(env, rv) == CK_ASSERT_OK) { + (*env)->SetByteArrayRegion(env, jDigest, jDigestOfs, ckDigestLength, (jbyte *)DIGESTBUF); } + + if (bufP != BUF) { free(bufP); } + return ckDigestLength; } #endif @@ -183,17 +188,23 @@ JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1DigestUpdate bufP = BUF; } else { bufLen = min(MAX_HEAP_BUFFER_LEN, jInLen); - bufP = (CK_BYTE_PTR)malloc((size_t)bufLen); + bufP = (CK_BYTE_PTR) malloc((size_t)bufLen); + if (bufP == NULL) { + JNU_ThrowOutOfMemoryError(env, 0); + return; + } } while (jInLen > 0) { jsize chunkLen = min(bufLen, jInLen); (*env)->GetByteArrayRegion(env, jIn, jInOfs, chunkLen, (jbyte *)bufP); + if ((*env)->ExceptionCheck(env)) { + if (bufP != BUF) { free(bufP); } + return; + } rv = (*ckpFunctions->C_DigestUpdate)(ckSessionHandle, bufP, chunkLen); - if(ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { - if (bufP != BUF) { - free(bufP); - } + if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { + if (bufP != BUF) { free(bufP); } return; } jInOfs += chunkLen; @@ -229,7 +240,7 @@ JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1DigestKey ckKeyHandle = jLongToCKULong(jKeyHandle); rv = (*ckpFunctions->C_DigestKey)(ckSessionHandle, ckKeyHandle); - if(ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return; } + if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return; } } #endif @@ -257,10 +268,9 @@ JNIEXPORT jint JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1DigestFinal ckSessionHandle = jLongToCKULong(jSessionHandle); rv = (*ckpFunctions->C_DigestFinal)(ckSessionHandle, BUF, &ckDigestLength); - if(ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return 0 ; } - - (*env)->SetByteArrayRegion(env, jDigest, jDigestOfs, ckDigestLength, (jbyte *)BUF); - + if (ckAssertReturnValueOK(env, rv) == CK_ASSERT_OK) { + (*env)->SetByteArrayRegion(env, jDigest, jDigestOfs, ckDigestLength, (jbyte *)BUF); + } return ckDigestLength; } #endif @@ -288,12 +298,13 @@ JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1SeedRandom ckSessionHandle = jLongToCKULong(jSessionHandle); jByteArrayToCKByteArray(env, jSeed, &ckpSeed, &ckSeedLength); + if ((*env)->ExceptionCheck(env)) { return; } rv = (*ckpFunctions->C_SeedRandom)(ckSessionHandle, ckpSeed, ckSeedLength); free(ckpSeed); - if(ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return; } + if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return; } } #endif @@ -322,6 +333,7 @@ JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1GenerateRandom jRandomBufferLength = (*env)->GetArrayLength(env, jRandomData); jRandomBuffer = (*env)->GetByteArrayElements(env, jRandomData, NULL); + if (jRandomBuffer == NULL) { return; } rv = (*ckpFunctions->C_GenerateRandom)(ckSessionHandle, (CK_BYTE_PTR) jRandomBuffer, @@ -330,6 +342,6 @@ JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1GenerateRandom /* copy back generated bytes */ (*env)->ReleaseByteArrayElements(env, jRandomData, jRandomBuffer, 0); - if(ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return; } + if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return; } } #endif diff --git a/src/share/native/sun/security/pkcs11/wrapper/p11_dual.c b/src/share/native/sun/security/pkcs11/wrapper/p11_dual.c index ead1fe429894b149fcae1f86bf65c8bb0ce617bb..24bae5e1626e6cd9b37a4a757d432c46b7b9efd8 100644 --- a/src/share/native/sun/security/pkcs11/wrapper/p11_dual.c +++ b/src/share/native/sun/security/pkcs11/wrapper/p11_dual.c @@ -1,5 +1,5 @@ /* - * Portions Copyright 2003-2007 Sun Microsystems, Inc. All Rights Reserved. + * Portions Copyright 2003-2009 Sun Microsystems, Inc. All Rights Reserved. */ /* Copyright (c) 2002 Graz University of Technology. All rights reserved. @@ -73,7 +73,7 @@ JNIEXPORT jbyteArray JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1DigestEn CK_SESSION_HANDLE ckSessionHandle; CK_BYTE_PTR ckpPart = NULL_PTR, ckpEncryptedPart; CK_ULONG ckPartLength, ckEncryptedPartLength = 0; - jbyteArray jEncryptedPart; + jbyteArray jEncryptedPart = NULL; CK_RV rv; CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj); @@ -81,20 +81,28 @@ JNIEXPORT jbyteArray JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1DigestEn ckSessionHandle = jLongToCKULong(jSessionHandle); jByteArrayToCKByteArray(env, jPart, &ckpPart, &ckPartLength); + if ((*env)->ExceptionCheck(env)) { return NULL; } rv = (*ckpFunctions->C_DigestEncryptUpdate)(ckSessionHandle, ckpPart, ckPartLength, NULL_PTR, &ckEncryptedPartLength); - if(ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return NULL ; } + if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { + free(ckpPart); + return NULL; + } ckpEncryptedPart = (CK_BYTE_PTR) malloc(ckEncryptedPartLength * sizeof(CK_BYTE)); + if (ckpEncryptedPart == NULL) { + free(ckpPart); + JNU_ThrowOutOfMemoryError(env, 0); + return NULL; + } rv = (*ckpFunctions->C_DigestEncryptUpdate)(ckSessionHandle, ckpPart, ckPartLength, ckpEncryptedPart, &ckEncryptedPartLength); - - jEncryptedPart = ckByteArrayToJByteArray(env, ckpEncryptedPart, ckEncryptedPartLength); + if (ckAssertReturnValueOK(env, rv) == CK_ASSERT_OK) { + jEncryptedPart = ckByteArrayToJByteArray(env, ckpEncryptedPart, ckEncryptedPartLength); + } free(ckpPart); free(ckpEncryptedPart); - if(ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return NULL ; } - return jEncryptedPart ; } #endif @@ -117,7 +125,7 @@ JNIEXPORT jbyteArray JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1DecryptD CK_SESSION_HANDLE ckSessionHandle; CK_BYTE_PTR ckpPart, ckpEncryptedPart = NULL_PTR; CK_ULONG ckPartLength = 0, ckEncryptedPartLength; - jbyteArray jPart; + jbyteArray jPart = NULL; CK_RV rv; CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj); @@ -125,19 +133,27 @@ JNIEXPORT jbyteArray JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1DecryptD ckSessionHandle = jLongToCKULong(jSessionHandle); jByteArrayToCKByteArray(env, jEncryptedPart, &ckpEncryptedPart, &ckEncryptedPartLength); + if ((*env)->ExceptionCheck(env)) { return NULL; } rv = (*ckpFunctions->C_DecryptDigestUpdate)(ckSessionHandle, ckpEncryptedPart, ckEncryptedPartLength, NULL_PTR, &ckPartLength); - if(ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return NULL; } + if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { + free(ckpEncryptedPart); + return NULL; + } ckpPart = (CK_BYTE_PTR) malloc(ckPartLength * sizeof(CK_BYTE)); + if (ckpPart == NULL) { + free(ckpEncryptedPart); + JNU_ThrowOutOfMemoryError(env, 0); + return NULL; + } rv = (*ckpFunctions->C_DecryptDigestUpdate)(ckSessionHandle, ckpEncryptedPart, ckEncryptedPartLength, ckpPart, &ckPartLength); - - jPart = ckByteArrayToJByteArray(env, ckpPart, ckPartLength); - free(ckpPart); + if (ckAssertReturnValueOK(env, rv) == CK_ASSERT_OK) { + jPart = ckByteArrayToJByteArray(env, ckpPart, ckPartLength); + } free(ckpEncryptedPart); - - if(ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return NULL ; } + free(ckpPart); return jPart ; } @@ -161,7 +177,7 @@ JNIEXPORT jbyteArray JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1SignEncr CK_SESSION_HANDLE ckSessionHandle; CK_BYTE_PTR ckpPart = NULL_PTR, ckpEncryptedPart; CK_ULONG ckPartLength, ckEncryptedPartLength = 0; - jbyteArray jEncryptedPart; + jbyteArray jEncryptedPart = NULL; CK_RV rv; CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj); @@ -169,20 +185,28 @@ JNIEXPORT jbyteArray JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1SignEncr ckSessionHandle = jLongToCKULong(jSessionHandle); jByteArrayToCKByteArray(env, jPart, &ckpPart, &ckPartLength); + if ((*env)->ExceptionCheck(env)) { return NULL; } rv = (*ckpFunctions->C_SignEncryptUpdate)(ckSessionHandle, ckpPart, ckPartLength, NULL_PTR, &ckEncryptedPartLength); - if(ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return NULL ; } + if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { + free(ckpPart); + return NULL; + } ckpEncryptedPart = (CK_BYTE_PTR) malloc(ckEncryptedPartLength * sizeof(CK_BYTE)); + if (ckpEncryptedPart == NULL) { + free(ckpPart); + JNU_ThrowOutOfMemoryError(env, 0); + return NULL; + } rv = (*ckpFunctions->C_SignEncryptUpdate)(ckSessionHandle, ckpPart, ckPartLength, ckpEncryptedPart, &ckEncryptedPartLength); - - jEncryptedPart = ckByteArrayToJByteArray(env, ckpEncryptedPart, ckEncryptedPartLength); + if (ckAssertReturnValueOK(env, rv) == CK_ASSERT_OK) { + jEncryptedPart = ckByteArrayToJByteArray(env, ckpEncryptedPart, ckEncryptedPartLength); + } free(ckpPart); free(ckpEncryptedPart); - if(ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return NULL ; } - return jEncryptedPart ; } #endif @@ -205,7 +229,7 @@ JNIEXPORT jbyteArray JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1DecryptV CK_SESSION_HANDLE ckSessionHandle; CK_BYTE_PTR ckpPart, ckpEncryptedPart = NULL_PTR; CK_ULONG ckPartLength = 0, ckEncryptedPartLength; - jbyteArray jPart; + jbyteArray jPart = NULL; CK_RV rv; CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj); @@ -213,19 +237,28 @@ JNIEXPORT jbyteArray JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1DecryptV ckSessionHandle = jLongToCKULong(jSessionHandle); jByteArrayToCKByteArray(env, jEncryptedPart, &ckpEncryptedPart, &ckEncryptedPartLength); + if ((*env)->ExceptionCheck(env)) { return NULL; } rv = (*ckpFunctions->C_DecryptVerifyUpdate)(ckSessionHandle, ckpEncryptedPart, ckEncryptedPartLength, NULL_PTR, &ckPartLength); - if(ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return NULL ; } + if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { + free(ckpEncryptedPart); + return NULL; + } ckpPart = (CK_BYTE_PTR) malloc(ckPartLength * sizeof(CK_BYTE)); + if (ckpPart == NULL) { + free(ckpEncryptedPart); + JNU_ThrowOutOfMemoryError(env, 0); + return NULL; + } rv = (*ckpFunctions->C_DecryptVerifyUpdate)(ckSessionHandle, ckpEncryptedPart, ckEncryptedPartLength, ckpPart, &ckPartLength); - jPart = ckByteArrayToJByteArray(env, ckpPart, ckPartLength); - free(ckpPart); + if (ckAssertReturnValueOK(env, rv) == CK_ASSERT_OK) { + jPart = ckByteArrayToJByteArray(env, ckpPart, ckPartLength); + } free(ckpEncryptedPart); - - if(ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return NULL ; } + free(ckpPart); return jPart ; } @@ -252,7 +285,7 @@ JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1GetFunctionSta /* C_GetFunctionStatus should always return CKR_FUNCTION_NOT_PARALLEL */ rv = (*ckpFunctions->C_GetFunctionStatus)(ckSessionHandle); - if(ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return; } + if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return; } } #endif @@ -277,6 +310,6 @@ JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1CancelFunction /* C_GetFunctionStatus should always return CKR_FUNCTION_NOT_PARALLEL */ rv = (*ckpFunctions->C_CancelFunction)(ckSessionHandle); - if(ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return; } + if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return; } } #endif diff --git a/src/share/native/sun/security/pkcs11/wrapper/p11_general.c b/src/share/native/sun/security/pkcs11/wrapper/p11_general.c index 05821a15d364190cc300c4ece64aaa446883aaa3..e6cbe2b6d917f27b494f2c7eb153c8b586c6a708 100644 --- a/src/share/native/sun/security/pkcs11/wrapper/p11_general.c +++ b/src/share/native/sun/security/pkcs11/wrapper/p11_general.c @@ -1,5 +1,5 @@ /* - * Portions Copyright 2003-2006 Sun Microsystems, Inc. All Rights Reserved. + * Portions Copyright 2003-2009 Sun Microsystems, Inc. All Rights Reserved. */ /* Copyright (c) 2002 Graz University of Technology. All rights reserved. @@ -102,6 +102,7 @@ Java_sun_security_pkcs11_wrapper_PKCS11_initializeLibrary jclass fetchClass(JNIEnv *env, const char *name) { jclass tmpClass = (*env)->FindClass(env, name); + if (tmpClass == NULL) { return NULL; } return (*env)->NewGlobalRef(env, tmpClass); } @@ -110,14 +111,18 @@ void prefetchFields(JNIEnv *env, jclass thisClass) { /* PKCS11 */ pNativeDataID = (*env)->GetFieldID(env, thisClass, "pNativeData", "J"); + if (pNativeDataID == NULL) { return; } /* CK_MECHANISM */ tmpClass = (*env)->FindClass(env, CLASS_MECHANISM); + if (tmpClass == NULL) { return; } mech_mechanismID = (*env)->GetFieldID(env, tmpClass, "mechanism", "J"); + if (mech_mechanismID == NULL) { return; } mech_pParameterID = (*env)->GetFieldID(env, tmpClass, "pParameter", "Ljava/lang/Object;"); - + if (mech_pParameterID == NULL) { return; } jByteArrayClass = fetchClass(env, "[B"); + if (jByteArrayClass == NULL) { return; } jLongClass = fetchClass(env, "java/lang/Long"); } @@ -252,10 +257,9 @@ Java_sun_security_pkcs11_wrapper_PKCS11_C_1GetInfo if (ckpFunctions == NULL) { return NULL; } rv = (*ckpFunctions->C_GetInfo)(&ckLibInfo); - if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return NULL ; } - - jInfoObject = ckInfoPtrToJInfo(env, &ckLibInfo); - + if (ckAssertReturnValueOK(env, rv) == CK_ASSERT_OK) { + jInfoObject = ckInfoPtrToJInfo(env, &ckLibInfo); + } return jInfoObject ; } @@ -279,28 +283,31 @@ jobject ckInfoPtrToJInfo(JNIEnv *env, const CK_INFO_PTR ckpInfo) /* load CK_INFO class */ jInfoClass = (*env)->FindClass(env, CLASS_INFO); - assert(jInfoClass != 0); + if (jInfoClass == NULL) { return NULL; }; /* load CK_INFO constructor */ jCtrId = (*env)->GetMethodID (env, jInfoClass, "<init>", "(Lsun/security/pkcs11/wrapper/CK_VERSION;[CJ[CLsun/security/pkcs11/wrapper/CK_VERSION;)V"); - - assert(jCtrId != 0); + if (jCtrId == NULL) { return NULL; } /* prep all fields */ jCryptokiVer = ckVersionPtrToJVersion(env, &(ckpInfo->cryptokiVersion)); + if (jCryptokiVer == NULL) { return NULL; } jVendor = ckUTF8CharArrayToJCharArray(env, &(ckpInfo->manufacturerID[0]), 32); + if (jVendor == NULL) { return NULL; } jFlags = ckULongToJLong(ckpInfo->flags); jLibraryDesc = ckUTF8CharArrayToJCharArray(env, &(ckpInfo->libraryDescription[0]), 32); + if (jLibraryDesc == NULL) { return NULL; } jLibraryVer = ckVersionPtrToJVersion(env, &(ckpInfo->libraryVersion)); + if (jLibraryVer == NULL) { return NULL; } /* create new CK_INFO object */ jInfoObject = (*env)->NewObject(env, jInfoClass, jCtrId, jCryptokiVer, jVendor, jFlags, jLibraryDesc, jLibraryVer); - assert(jInfoObject != 0); + if (jInfoObject == NULL) { return NULL; } /* free local references */ (*env)->DeleteLocalRef(env, jInfoClass); @@ -343,15 +350,18 @@ Java_sun_security_pkcs11_wrapper_PKCS11_C_1GetSlotList if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return NULL ; } ckpSlotList = (CK_SLOT_ID_PTR) malloc(ckTokenNumber * sizeof(CK_SLOT_ID)); + if (ckpSlotList == NULL) { + JNU_ThrowOutOfMemoryError(env, 0); + return NULL; + } rv = (*ckpFunctions->C_GetSlotList)(ckTokenPresent, ckpSlotList, &ckTokenNumber); - - jSlotList = ckULongArrayToJLongArray(env, ckpSlotList, ckTokenNumber); + if (ckAssertReturnValueOK(env, rv) == CK_ASSERT_OK) { + jSlotList = ckULongArrayToJLongArray(env, ckpSlotList, ckTokenNumber); + } free(ckpSlotList); - if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return NULL ; } - return jSlotList ; } #endif @@ -380,10 +390,9 @@ Java_sun_security_pkcs11_wrapper_PKCS11_C_1GetSlotInfo ckSlotID = jLongToCKULong(jSlotID); rv = (*ckpFunctions->C_GetSlotInfo)(ckSlotID, &ckSlotInfo); - if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return NULL ; } - - jSlotInfoObject = ckSlotInfoPtrToJSlotInfo(env, &ckSlotInfo); - + if (ckAssertReturnValueOK(env, rv) == CK_ASSERT_OK) { + jSlotInfoObject = ckSlotInfoPtrToJSlotInfo(env, &ckSlotInfo); + } return jSlotInfoObject ; } @@ -410,28 +419,32 @@ ckSlotInfoPtrToJSlotInfo /* load CK_SLOT_INFO class */ jSlotInfoClass = (*env)->FindClass(env, CLASS_SLOT_INFO); - assert(jSlotInfoClass != 0); + if (jSlotInfoClass == NULL) { return NULL; }; /* load CK_SLOT_INFO constructor */ jCtrId = (*env)->GetMethodID (env, jSlotInfoClass, "<init>", "([C[CJLsun/security/pkcs11/wrapper/CK_VERSION;Lsun/security/pkcs11/wrapper/CK_VERSION;)V"); - assert(jCtrId != 0); + if (jCtrId == NULL) { return NULL; } /* prep all fields */ jSlotDesc = ckUTF8CharArrayToJCharArray(env, &(ckpSlotInfo->slotDescription[0]), 64); + if (jSlotDesc == NULL) { return NULL; } jVendor = ckUTF8CharArrayToJCharArray(env, &(ckpSlotInfo->manufacturerID[0]), 32); + if (jVendor == NULL) { return NULL; } jFlags = ckULongToJLong(ckpSlotInfo->flags); jHardwareVer = ckVersionPtrToJVersion(env, &(ckpSlotInfo->hardwareVersion)); + if (jHardwareVer == NULL) { return NULL; } jFirmwareVer = ckVersionPtrToJVersion(env, &(ckpSlotInfo->firmwareVersion)); + if (jFirmwareVer == NULL) { return NULL; } /* create new CK_SLOT_INFO object */ jSlotInfoObject = (*env)->NewObject (env, jSlotInfoClass, jCtrId, jSlotDesc, jVendor, jFlags, jHardwareVer, jFirmwareVer); - assert(jSlotInfoObject != 0); + if (jSlotInfoObject == NULL) { return NULL; } /* free local references */ (*env)->DeleteLocalRef(env, jSlotInfoClass); @@ -460,7 +473,7 @@ Java_sun_security_pkcs11_wrapper_PKCS11_C_1GetTokenInfo { CK_SLOT_ID ckSlotID; CK_TOKEN_INFO ckTokenInfo; - jobject jInfoTokenObject; + jobject jInfoTokenObject = NULL; CK_RV rv; CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj); @@ -469,10 +482,9 @@ Java_sun_security_pkcs11_wrapper_PKCS11_C_1GetTokenInfo ckSlotID = jLongToCKULong(jSlotID); rv = (*ckpFunctions->C_GetTokenInfo)(ckSlotID, &ckTokenInfo); - if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return NULL ; } - - jInfoTokenObject = ckTokenInfoPtrToJTokenInfo(env, &ckTokenInfo); - + if (ckAssertReturnValueOK(env, rv) == CK_ASSERT_OK) { + jInfoTokenObject = ckTokenInfoPtrToJTokenInfo(env, &ckTokenInfo); + } return jInfoTokenObject ; } @@ -512,21 +524,25 @@ ckTokenInfoPtrToJTokenInfo /* load CK_TOKEN_INFO class */ jTokenInfoClass = (*env)->FindClass(env, CLASS_TOKEN_INFO); - assert(jTokenInfoClass != 0); + if (jTokenInfoClass == NULL) { return NULL; }; /* load CK_TOKEN_INFO constructor */ jCtrId = (*env)->GetMethodID (env, jTokenInfoClass, "<init>", "([C[C[C[CJJJJJJJJJJJLsun/security/pkcs11/wrapper/CK_VERSION;Lsun/security/pkcs11/wrapper/CK_VERSION;[C)V"); - assert(jCtrId != 0); + if (jCtrId == NULL) { return NULL; }; /* prep all fields */ jLabel = ckUTF8CharArrayToJCharArray(env, &(ckpTokenInfo->label[0]), 32); + if (jLabel == NULL) { return NULL; }; jVendor = ckUTF8CharArrayToJCharArray(env, &(ckpTokenInfo->manufacturerID[0]), 32); + if (jVendor == NULL) { return NULL; }; jModel = ckUTF8CharArrayToJCharArray(env, &(ckpTokenInfo->model[0]), 16); + if (jModel == NULL) { return NULL; }; jSerialNo = ckUTF8CharArrayToJCharArray(env, &(ckpTokenInfo->serialNumber[0]), 16); + if (jSerialNo == NULL) { return NULL; }; jFlags = ckULongToJLong(ckpTokenInfo->flags); jMaxSnCnt = ckULongSpecialToJLong(ckpTokenInfo->ulMaxSessionCount); jSnCnt = ckULongSpecialToJLong(ckpTokenInfo->ulSessionCount); @@ -540,10 +556,13 @@ ckTokenInfoPtrToJTokenInfo jFreePrivMem = ckULongSpecialToJLong(ckpTokenInfo->ulFreePrivateMemory); jHardwareVer = ckVersionPtrToJVersion(env, &(ckpTokenInfo->hardwareVersion)); + if (jHardwareVer == NULL) { return NULL; } jFirmwareVer = ckVersionPtrToJVersion(env, &(ckpTokenInfo->firmwareVersion)); + if (jFirmwareVer == NULL) { return NULL; } jUtcTime = ckUTF8CharArrayToJCharArray(env, &(ckpTokenInfo->utcTime[0]), 16); + if (jUtcTime == NULL) { return NULL; } /* create new CK_TOKEN_INFO object */ jTokenInfoObject = @@ -553,7 +572,7 @@ ckTokenInfoPtrToJTokenInfo jMaxPinLen, jMinPinLen, jTotalPubMem, jFreePubMem, jTotalPrivMem, jFreePrivMem, jHardwareVer, jFirmwareVer, jUtcTime); - assert(jTokenInfoObject != 0); + if (jTokenInfoObject == NULL) { return NULL; } /* free local references */ (*env)->DeleteLocalRef(env, jTokenInfoClass); @@ -584,7 +603,7 @@ Java_sun_security_pkcs11_wrapper_PKCS11_C_1WaitForSlotEvent { CK_FLAGS ckFlags; CK_SLOT_ID ckSlotID; - jlong jSlotID; + jlong jSlotID = 0L; CK_RV rv; CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj); @@ -593,9 +612,9 @@ Java_sun_security_pkcs11_wrapper_PKCS11_C_1WaitForSlotEvent ckFlags = jLongToCKULong(jFlags); rv = (*ckpFunctions->C_WaitForSlotEvent)(ckFlags, &ckSlotID, NULL_PTR); - if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return 0L; } - - jSlotID = ckULongToJLong(ckSlotID); + if (ckAssertReturnValueOK(env, rv) == CK_ASSERT_OK) { + jSlotID = ckULongToJLong(ckSlotID); + } return jSlotID ; } @@ -632,16 +651,19 @@ Java_sun_security_pkcs11_wrapper_PKCS11_C_1GetMechanismList ckpMechanismList = (CK_MECHANISM_TYPE_PTR) malloc(ckMechanismNumber * sizeof(CK_MECHANISM_TYPE)); + if (ckpMechanismList == NULL) { + JNU_ThrowOutOfMemoryError(env, 0); + return NULL; + } rv = (*ckpFunctions->C_GetMechanismList)(ckSlotID, ckpMechanismList, &ckMechanismNumber); - - jMechanismList = ckULongArrayToJLongArray(env, ckpMechanismList, - ckMechanismNumber); + if (ckAssertReturnValueOK(env, rv) == CK_ASSERT_OK) { + jMechanismList = ckULongArrayToJLongArray(env, ckpMechanismList, + ckMechanismNumber); + } free(ckpMechanismList); - if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return NULL ; } - return jMechanismList ; } #endif @@ -663,7 +685,7 @@ Java_sun_security_pkcs11_wrapper_PKCS11_C_1GetMechanismInfo CK_SLOT_ID ckSlotID; CK_MECHANISM_TYPE ckMechanismType; CK_MECHANISM_INFO ckMechanismInfo; - jobject jMechanismInfo; + jobject jMechanismInfo = NULL; CK_RV rv; CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj); @@ -674,10 +696,9 @@ Java_sun_security_pkcs11_wrapper_PKCS11_C_1GetMechanismInfo rv = (*ckpFunctions->C_GetMechanismInfo)(ckSlotID, ckMechanismType, &ckMechanismInfo); - if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return NULL ; } - - jMechanismInfo = ckMechanismInfoPtrToJMechanismInfo(env, &ckMechanismInfo); - + if (ckAssertReturnValueOK(env, rv) == CK_ASSERT_OK) { + jMechanismInfo = ckMechanismInfoPtrToJMechanismInfo(env, &ckMechanismInfo); + } return jMechanismInfo ; } @@ -703,11 +724,11 @@ ckMechanismInfoPtrToJMechanismInfo /* load CK_MECHANISM_INFO class */ jMechanismInfoClass = (*env)->FindClass(env, CLASS_MECHANISM_INFO); - assert(jMechanismInfoClass != 0); + if (jMechanismInfoClass == NULL) { return NULL; }; /* load CK_MECHANISM_INFO constructor */ jCtrId = (*env)->GetMethodID(env, jMechanismInfoClass, "<init>", "(JJJ)V"); - assert(jCtrId != 0); + if (jCtrId == NULL) { return NULL; }; /* prep all fields */ jMinKeySize = ckULongToJLong(ckpMechanismInfo->ulMinKeySize); @@ -717,7 +738,7 @@ ckMechanismInfoPtrToJMechanismInfo /* create new CK_MECHANISM_INFO object */ jMechanismInfoObject = (*env)->NewObject(env, jMechanismInfoClass, jCtrId, jMinKeySize, jMaxKeySize, jFlags); - assert(jMechanismInfoObject != 0); + if (jMechanismInfoObject == NULL) { return NULL; }; /* free local references */ (*env)->DeleteLocalRef(env, jMechanismInfoClass); @@ -753,8 +774,13 @@ Java_sun_security_pkcs11_wrapper_PKCS11_C_1InitToken ckSlotID = jLongToCKULong(jSlotID); jCharArrayToCKCharArray(env, jPin, &ckpPin, &ckPinLength); - jCharArrayToCKUTF8CharArray(env, jLabel, &ckpLabel, &ckLabelLength); + if ((*env)->ExceptionCheck(env)) { return; } /* ckLabelLength <= 32 !!! */ + jCharArrayToCKUTF8CharArray(env, jLabel, &ckpLabel, &ckLabelLength); + if ((*env)->ExceptionCheck(env)) { + free(ckpPin); + return; + } rv = (*ckpFunctions->C_InitToken)(ckSlotID, ckpPin, ckPinLength, ckpLabel); TRACE1("InitToken return code: %d", rv); @@ -790,6 +816,7 @@ Java_sun_security_pkcs11_wrapper_PKCS11_C_1InitPIN ckSessionHandle = jLongToCKULong(jSessionHandle); jCharArrayToCKCharArray(env, jPin, &ckpPin, &ckPinLength); + if ((*env)->ExceptionCheck(env)) { return; } rv = (*ckpFunctions->C_InitPIN)(ckSessionHandle, ckpPin, ckPinLength); @@ -828,7 +855,12 @@ jcharArray jNewPin) ckSessionHandle = jLongToCKULong(jSessionHandle); jCharArrayToCKCharArray(env, jOldPin, &ckpOldPin, &ckOldPinLength); + if ((*env)->ExceptionCheck(env)) { return; } jCharArrayToCKCharArray(env, jNewPin, &ckpNewPin, &ckNewPinLength); + if ((*env)->ExceptionCheck(env)) { + free(ckpOldPin); + return; + } rv = (*ckpFunctions->C_SetPIN)(ckSessionHandle, ckpOldPin, ckOldPinLength, ckpNewPin, ckNewPinLength); diff --git a/src/share/native/sun/security/pkcs11/wrapper/p11_keymgmt.c b/src/share/native/sun/security/pkcs11/wrapper/p11_keymgmt.c index 65fbfd800572a0481a6fdef764eb7c516daffb70..aab0491a30e05e50d21be9e348db88c51700df76 100644 --- a/src/share/native/sun/security/pkcs11/wrapper/p11_keymgmt.c +++ b/src/share/native/sun/security/pkcs11/wrapper/p11_keymgmt.c @@ -1,5 +1,5 @@ /* - * Portions Copyright 2003-2006 Sun Microsystems, Inc. All Rights Reserved. + * Portions Copyright 2003-2009 Sun Microsystems, Inc. All Rights Reserved. */ /* Copyright (c) 2002 Graz University of Technology. All rights reserved. @@ -74,7 +74,7 @@ JNIEXPORT jlong JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1GenerateKey CK_ATTRIBUTE_PTR ckpAttributes = NULL_PTR; CK_ULONG ckAttributesLength; CK_OBJECT_HANDLE ckKeyHandle; - jlong jKeyHandle; + jlong jKeyHandle = 0L; CK_ULONG i; CK_RV rv; @@ -83,21 +83,23 @@ JNIEXPORT jlong JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1GenerateKey ckSessionHandle = jLongToCKULong(jSessionHandle); jMechanismToCKMechanism(env, jMechanism, &ckMechanism); - if ((*env)->ExceptionOccurred(env)) { return 0L ; } + if ((*env)->ExceptionCheck(env)) { return 0L ; } + jAttributeArrayToCKAttributeArray(env, jTemplate, &ckpAttributes, &ckAttributesLength); + if ((*env)->ExceptionCheck(env)) { + if (ckMechanism.pParameter != NULL_PTR) { + free(ckMechanism.pParameter); + } + return 0L; + } rv = (*ckpFunctions->C_GenerateKey)(ckSessionHandle, &ckMechanism, ckpAttributes, ckAttributesLength, &ckKeyHandle); - jKeyHandle = ckULongToJLong(ckKeyHandle); - for(i=0; i<ckAttributesLength; i++) { - if(ckpAttributes[i].pValue != NULL_PTR) { - free(ckpAttributes[i].pValue); - } - } - free(ckpAttributes); + if (ckAssertReturnValueOK(env, rv) == CK_ASSERT_OK) { + jKeyHandle = ckULongToJLong(ckKeyHandle); - /* cheack, if we must give a initialization vector back to Java */ - switch (ckMechanism.mechanism) { + /* cheack, if we must give a initialization vector back to Java */ + switch (ckMechanism.mechanism) { case CKM_PBE_MD2_DES_CBC: case CKM_PBE_MD5_DES_CBC: case CKM_PBE_MD5_CAST_CBC: @@ -109,13 +111,13 @@ JNIEXPORT jlong JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1GenerateKey /* we must copy back the initialization vector to the jMechanism object */ copyBackPBEInitializationVector(env, &ckMechanism, jMechanism); break; + } } - if(ckMechanism.pParameter != NULL_PTR) { + if (ckMechanism.pParameter != NULL_PTR) { free(ckMechanism.pParameter); } - - if(ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return 0L ; } + freeCKAttributeArray(ckpAttributes, ckAttributesLength); return jKeyHandle ; } @@ -158,40 +160,53 @@ JNIEXPORT jlongArray JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1Generate ckSessionHandle = jLongToCKULong(jSessionHandle); jMechanismToCKMechanism(env, jMechanism, &ckMechanism); - jAttributeArrayToCKAttributeArray(env, jPublicKeyTemplate, &ckpPublicKeyAttributes, &ckPublicKeyAttributesLength); - jAttributeArrayToCKAttributeArray(env, jPrivateKeyTemplate, &ckpPrivateKeyAttributes, &ckPrivateKeyAttributesLength); + if ((*env)->ExceptionCheck(env)) { return NULL; } + ckpKeyHandles = (CK_OBJECT_HANDLE_PTR) malloc(2 * sizeof(CK_OBJECT_HANDLE)); + if (ckpKeyHandles == NULL) { + if (ckMechanism.pParameter != NULL_PTR) { + free(ckMechanism.pParameter); + } + JNU_ThrowOutOfMemoryError(env, 0); + return NULL; + } ckpPublicKeyHandle = ckpKeyHandles; /* first element of array is Public Key */ ckpPrivateKeyHandle = (ckpKeyHandles + 1); /* second element of array is Private Key */ + jAttributeArrayToCKAttributeArray(env, jPublicKeyTemplate, &ckpPublicKeyAttributes, &ckPublicKeyAttributesLength); + if ((*env)->ExceptionCheck(env)) { + if (ckMechanism.pParameter != NULL_PTR) { + free(ckMechanism.pParameter); + } + free(ckpKeyHandles); + return NULL; + } + + jAttributeArrayToCKAttributeArray(env, jPrivateKeyTemplate, &ckpPrivateKeyAttributes, &ckPrivateKeyAttributesLength); + if ((*env)->ExceptionCheck(env)) { + if (ckMechanism.pParameter != NULL_PTR) { + free(ckMechanism.pParameter); + } + free(ckpKeyHandles); + freeCKAttributeArray(ckpPublicKeyAttributes, ckPublicKeyAttributesLength); + return NULL; + } + rv = (*ckpFunctions->C_GenerateKeyPair)(ckSessionHandle, &ckMechanism, ckpPublicKeyAttributes, ckPublicKeyAttributesLength, ckpPrivateKeyAttributes, ckPrivateKeyAttributesLength, ckpPublicKeyHandle, ckpPrivateKeyHandle); - jKeyHandles = ckULongArrayToJLongArray(env, ckpKeyHandles, 2); - - for(i=0; i<ckPublicKeyAttributesLength; i++) { - if(ckpPublicKeyAttributes[i].pValue != NULL_PTR) { - free(ckpPublicKeyAttributes[i].pValue); - } - } - free(ckpPublicKeyAttributes); - - for(i=0; i<ckPrivateKeyAttributesLength; i++) { - if(ckpPrivateKeyAttributes[i].pValue != NULL_PTR) { - free(ckpPrivateKeyAttributes[i].pValue); - } + if (ckAssertReturnValueOK(env, rv) == CK_ASSERT_OK) { + jKeyHandles = ckULongArrayToJLongArray(env, ckpKeyHandles, 2); } - free(ckpPrivateKeyAttributes); if(ckMechanism.pParameter != NULL_PTR) { free(ckMechanism.pParameter); } - free(ckpKeyHandles); - - if(ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return NULL; } + freeCKAttributeArray(ckpPublicKeyAttributes, ckPublicKeyAttributesLength); + freeCKAttributeArray(ckpPrivateKeyAttributes, ckPrivateKeyAttributesLength); return jKeyHandles ; } @@ -217,7 +232,7 @@ JNIEXPORT jbyteArray JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1WrapKey CK_MECHANISM ckMechanism; CK_OBJECT_HANDLE ckWrappingKeyHandle; CK_OBJECT_HANDLE ckKeyHandle; - jbyteArray jWrappedKey; + jbyteArray jWrappedKey = NULL; CK_RV rv; CK_BYTE BUF[MAX_STACK_BUFFER_LEN]; CK_BYTE_PTR ckpWrappedKey = BUF; @@ -228,24 +243,32 @@ JNIEXPORT jbyteArray JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1WrapKey ckSessionHandle = jLongToCKULong(jSessionHandle); jMechanismToCKMechanism(env, jMechanism, &ckMechanism); + if ((*env)->ExceptionCheck(env)) { return NULL; } + ckWrappingKeyHandle = jLongToCKULong(jWrappingKeyHandle); ckKeyHandle = jLongToCKULong(jKeyHandle); rv = (*ckpFunctions->C_WrapKey)(ckSessionHandle, &ckMechanism, ckWrappingKeyHandle, ckKeyHandle, ckpWrappedKey, &ckWrappedKeyLength); if (rv == CKR_BUFFER_TOO_SMALL) { ckpWrappedKey = (CK_BYTE_PTR) malloc(ckWrappedKeyLength); + if (ckpWrappedKey == NULL) { + if (ckMechanism.pParameter != NULL_PTR) { + free(ckMechanism.pParameter); + } + JNU_ThrowOutOfMemoryError(env, 0); + return NULL; + } + rv = (*ckpFunctions->C_WrapKey)(ckSessionHandle, &ckMechanism, ckWrappingKeyHandle, ckKeyHandle, ckpWrappedKey, &ckWrappedKeyLength); } if (ckAssertReturnValueOK(env, rv) == CK_ASSERT_OK) { jWrappedKey = ckByteArrayToJByteArray(env, ckpWrappedKey, ckWrappedKeyLength); } - if (ckpWrappedKey != BUF) { - free(ckpWrappedKey); - } - if(ckMechanism.pParameter != NULL_PTR) + if (ckpWrappedKey != BUF) { free(ckpWrappedKey); } + if (ckMechanism.pParameter != NULL_PTR) { free(ckMechanism.pParameter); - + } return jWrappedKey ; } #endif @@ -277,7 +300,7 @@ JNIEXPORT jlong JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1UnwrapKey CK_ATTRIBUTE_PTR ckpAttributes = NULL_PTR; CK_ULONG ckAttributesLength; CK_OBJECT_HANDLE ckKeyHandle; - jlong jKeyHandle; + jlong jKeyHandle = 0L; CK_ULONG i; CK_RV rv; @@ -286,37 +309,48 @@ JNIEXPORT jlong JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1UnwrapKey ckSessionHandle = jLongToCKULong(jSessionHandle); jMechanismToCKMechanism(env, jMechanism, &ckMechanism); + if ((*env)->ExceptionCheck(env)) { return 0L; } + ckUnwrappingKeyHandle = jLongToCKULong(jUnwrappingKeyHandle); jByteArrayToCKByteArray(env, jWrappedKey, &ckpWrappedKey, &ckWrappedKeyLength); + if ((*env)->ExceptionCheck(env)) { + if (ckMechanism.pParameter != NULL_PTR) { + free(ckMechanism.pParameter); + } + return 0L; + } + jAttributeArrayToCKAttributeArray(env, jTemplate, &ckpAttributes, &ckAttributesLength); + if ((*env)->ExceptionCheck(env)) { + if (ckMechanism.pParameter != NULL_PTR) { + free(ckMechanism.pParameter); + } + free(ckpWrappedKey); + return 0L; + } + rv = (*ckpFunctions->C_UnwrapKey)(ckSessionHandle, &ckMechanism, ckUnwrappingKeyHandle, ckpWrappedKey, ckWrappedKeyLength, ckpAttributes, ckAttributesLength, &ckKeyHandle); - jKeyHandle = ckLongToJLong(ckKeyHandle); - - for(i=0; i<ckAttributesLength; i++) { - if(ckpAttributes[i].pValue != NULL_PTR) { - free(ckpAttributes[i].pValue); - } - } - free(ckpAttributes); + if (ckAssertReturnValueOK(env, rv) == CK_ASSERT_OK) { + jKeyHandle = ckLongToJLong(ckKeyHandle); #if 0 - /* cheack, if we must give a initialization vector back to Java */ - if (ckMechanism.mechanism == CKM_KEY_WRAP_SET_OAEP) { - /* we must copy back the unwrapped key info to the jMechanism object */ - copyBackSetUnwrappedKey(env, &ckMechanism, jMechanism); - } + /* cheack, if we must give a initialization vector back to Java */ + if (ckMechanism.mechanism == CKM_KEY_WRAP_SET_OAEP) { + /* we must copy back the unwrapped key info to the jMechanism object */ + copyBackSetUnwrappedKey(env, &ckMechanism, jMechanism); + } #endif + } - free(ckpWrappedKey); - if(ckMechanism.pParameter != NULL_PTR) { + if (ckMechanism.pParameter != NULL_PTR) { free(ckMechanism.pParameter); } - - if(ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return 0L ; } + freeCKAttributeArray(ckpAttributes, ckAttributesLength); + free(ckpWrappedKey); return jKeyHandle ; } @@ -360,8 +394,7 @@ void freeEcdh1DeriveParams(CK_MECHANISM_PTR ckMechanism) { */ void copyBackTLSPrfParams(JNIEnv *env, CK_MECHANISM *ckMechanism, jobject jMechanism) { - jclass jMechanismClass= (*env)->FindClass(env, CLASS_MECHANISM); - jclass jTLSPrfParamsClass = (*env)->FindClass(env, CLASS_TLS_PRF_PARAMS); + jclass jMechanismClass, jTLSPrfParamsClass; CK_TLS_PRF_PARAMS *ckTLSPrfParams; jobject jTLSPrfParams; jfieldID fieldID; @@ -374,8 +407,10 @@ void copyBackTLSPrfParams(JNIEnv *env, CK_MECHANISM *ckMechanism, jobject jMecha int i; /* get mechanism */ + jMechanismClass = (*env)->FindClass(env, CLASS_MECHANISM); + if (jMechanismClass == NULL) { return; } fieldID = (*env)->GetFieldID(env, jMechanismClass, "mechanism", "J"); - assert(fieldID != 0); + if (fieldID == NULL) { return; } jMechanismType = (*env)->GetLongField(env, jMechanism, fieldID); ckMechanismType = jLongToCKULong(jMechanismType); if (ckMechanismType != ckMechanism->mechanism) { @@ -388,12 +423,14 @@ void copyBackTLSPrfParams(JNIEnv *env, CK_MECHANISM *ckMechanism, jobject jMecha if (ckTLSPrfParams != NULL_PTR) { /* get the Java CK_TLS_PRF_PARAMS object (pParameter) */ fieldID = (*env)->GetFieldID(env, jMechanismClass, "pParameter", "Ljava/lang/Object;"); - assert(fieldID != 0); + if (fieldID == NULL) { return; } jTLSPrfParams = (*env)->GetObjectField(env, jMechanism, fieldID); /* copy back the client IV */ + jTLSPrfParamsClass = (*env)->FindClass(env, CLASS_TLS_PRF_PARAMS); + if (jTLSPrfParamsClass == NULL) { return; } fieldID = (*env)->GetFieldID(env, jTLSPrfParamsClass, "pOutput", "[B"); - assert(fieldID != 0); + if (fieldID == NULL) { return; } jOutput = (*env)->GetObjectField(env, jTLSPrfParams, fieldID); output = ckTLSPrfParams->pOutput; @@ -402,26 +439,21 @@ void copyBackTLSPrfParams(JNIEnv *env, CK_MECHANISM *ckMechanism, jobject jMecha if (jOutput != NULL) { jLength = (*env)->GetArrayLength(env, jOutput); jBytes = (*env)->GetByteArrayElements(env, jOutput, NULL); + if (jBytes == NULL) { return; } + /* copy the bytes to the Java buffer */ for (i=0; i < jLength; i++) { jBytes[i] = ckByteToJByte(output[i]); } /* copy back the Java buffer to the object */ (*env)->ReleaseByteArrayElements(env, jOutput, jBytes, 0); - // free malloc'd data - free(output); } // free malloc'd data - if (ckTLSPrfParams->pSeed != NULL) { - free(ckTLSPrfParams->pSeed); - } - if (ckTLSPrfParams->pLabel != NULL) { - free(ckTLSPrfParams->pLabel); - } - if (ckTLSPrfParams->pulOutputLen != NULL) { - free(ckTLSPrfParams->pulOutputLen); - } + free(ckTLSPrfParams->pSeed); + free(ckTLSPrfParams->pLabel); + free(ckTLSPrfParams->pulOutputLen); + free(ckTLSPrfParams->pOutput); } } @@ -456,8 +488,16 @@ JNIEXPORT jlong JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1DeriveKey ckSessionHandle = jLongToCKULong(jSessionHandle); jMechanismToCKMechanism(env, jMechanism, &ckMechanism); + if ((*env)->ExceptionCheck(env)) { return 0L; } + ckBaseKeyHandle = jLongToCKULong(jBaseKeyHandle); jAttributeArrayToCKAttributeArray(env, jTemplate, &ckpAttributes, &ckAttributesLength); + if ((*env)->ExceptionCheck(env)) { + if (ckMechanism.pParameter != NULL_PTR) { + free(ckMechanism.pParameter); + } + return 0L; + } switch (ckMechanism.mechanism) { case CKM_SSL3_KEY_AND_MAC_DERIVE: @@ -476,14 +516,8 @@ JNIEXPORT jlong JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1DeriveKey ckpAttributes, ckAttributesLength, phKey); jKeyHandle = ckLongToJLong(ckKeyHandle); - for(i=0; i<ckAttributesLength; i++) { - if(ckpAttributes[i].pValue != NULL_PTR) { - free(ckpAttributes[i].pValue); - } - } - if (ckpAttributes != NULL) { - free(ckpAttributes); - } + + freeCKAttributeArray(ckpAttributes, ckAttributesLength); switch (ckMechanism.mechanism) { case CKM_SSL3_MASTER_KEY_DERIVE: @@ -512,11 +546,10 @@ JNIEXPORT jlong JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1DeriveKey break; } - if(ckMechanism.pParameter != NULL_PTR) { + if (ckMechanism.pParameter != NULL_PTR) { free(ckMechanism.pParameter); } - - if(ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return 0L ; } + if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return 0L ; } return jKeyHandle ; } @@ -529,9 +562,7 @@ JNIEXPORT jlong JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1DeriveKey */ void copyBackClientVersion(JNIEnv *env, CK_MECHANISM *ckMechanism, jobject jMechanism) { - jclass jMechanismClass= (*env)->FindClass(env, CLASS_MECHANISM); - jclass jSSL3MasterKeyDeriveParamsClass = (*env)->FindClass(env, CLASS_SSL3_MASTER_KEY_DERIVE_PARAMS); - jclass jVersionClass = (*env)->FindClass(env, CLASS_VERSION); + jclass jMechanismClass, jSSL3MasterKeyDeriveParamsClass, jVersionClass; CK_SSL3_MASTER_KEY_DERIVE_PARAMS *ckSSL3MasterKeyDeriveParams; CK_VERSION *ckVersion; jfieldID fieldID; @@ -541,8 +572,10 @@ void copyBackClientVersion(JNIEnv *env, CK_MECHANISM *ckMechanism, jobject jMech jobject jVersion; /* get mechanism */ + jMechanismClass = (*env)->FindClass(env, CLASS_MECHANISM); + if (jMechanismClass == NULL) { return; } fieldID = (*env)->GetFieldID(env, jMechanismClass, "mechanism", "J"); - assert(fieldID != 0); + if (fieldID == NULL) { return; } jMechanismType = (*env)->GetLongField(env, jMechanism, fieldID); ckMechanismType = jLongToCKULong(jMechanismType); if (ckMechanismType != ckMechanism->mechanism) { @@ -558,27 +591,31 @@ void copyBackClientVersion(JNIEnv *env, CK_MECHANISM *ckMechanism, jobject jMech if (ckVersion != NULL_PTR) { /* get the Java CK_SSL3_MASTER_KEY_DERIVE_PARAMS (pParameter) */ fieldID = (*env)->GetFieldID(env, jMechanismClass, "pParameter", "Ljava/lang/Object;"); - assert(fieldID != 0); + if (fieldID == NULL) { return; } + jSSL3MasterKeyDeriveParams = (*env)->GetObjectField(env, jMechanism, fieldID); /* get the Java CK_VERSION */ + jSSL3MasterKeyDeriveParamsClass = (*env)->FindClass(env, CLASS_SSL3_MASTER_KEY_DERIVE_PARAMS); + if (jSSL3MasterKeyDeriveParamsClass == NULL) { return; } fieldID = (*env)->GetFieldID(env, jSSL3MasterKeyDeriveParamsClass, "pVersion", "L"CLASS_VERSION";"); - assert(fieldID != 0); + if (fieldID == NULL) { return; } jVersion = (*env)->GetObjectField(env, jSSL3MasterKeyDeriveParams, fieldID); /* now copy back the version from the native structure to the Java structure */ /* copy back the major version */ + jVersionClass = (*env)->FindClass(env, CLASS_VERSION); + if (jVersionClass == NULL) { return; } fieldID = (*env)->GetFieldID(env, jVersionClass, "major", "B"); - assert(fieldID != 0); + if (fieldID == NULL) { return; } (*env)->SetByteField(env, jVersion, fieldID, ckByteToJByte(ckVersion->major)); /* copy back the minor version */ fieldID = (*env)->GetFieldID(env, jVersionClass, "minor", "B"); - assert(fieldID != 0); + if (fieldID == NULL) { return; } (*env)->SetByteField(env, jVersion, fieldID, ckByteToJByte(ckVersion->minor)); } - } } @@ -591,9 +628,7 @@ void copyBackClientVersion(JNIEnv *env, CK_MECHANISM *ckMechanism, jobject jMech */ void copyBackSSLKeyMatParams(JNIEnv *env, CK_MECHANISM *ckMechanism, jobject jMechanism) { - jclass jMechanismClass= (*env)->FindClass(env, CLASS_MECHANISM); - jclass jSSL3KeyMatParamsClass = (*env)->FindClass(env, CLASS_SSL3_KEY_MAT_PARAMS); - jclass jSSL3KeyMatOutClass = (*env)->FindClass(env, CLASS_SSL3_KEY_MAT_OUT); + jclass jMechanismClass, jSSL3KeyMatParamsClass, jSSL3KeyMatOutClass; CK_SSL3_KEY_MAT_PARAMS *ckSSL3KeyMatParam; CK_SSL3_KEY_MAT_OUT *ckSSL3KeyMatOut; jfieldID fieldID; @@ -608,8 +643,10 @@ void copyBackSSLKeyMatParams(JNIEnv *env, CK_MECHANISM *ckMechanism, jobject jMe int i; /* get mechanism */ + jMechanismClass= (*env)->FindClass(env, CLASS_MECHANISM); + if (jMechanismClass == NULL) { return; } fieldID = (*env)->GetFieldID(env, jMechanismClass, "mechanism", "J"); - assert(fieldID != 0); + if (fieldID == NULL) { return; } jMechanismType = (*env)->GetLongField(env, jMechanism, fieldID); ckMechanismType = jLongToCKULong(jMechanismType); if (ckMechanismType != ckMechanism->mechanism) { @@ -633,74 +670,78 @@ void copyBackSSLKeyMatParams(JNIEnv *env, CK_MECHANISM *ckMechanism, jobject jMe if (ckSSL3KeyMatOut != NULL_PTR) { /* get the Java CK_SSL3_KEY_MAT_PARAMS (pParameter) */ fieldID = (*env)->GetFieldID(env, jMechanismClass, "pParameter", "Ljava/lang/Object;"); - assert(fieldID != 0); + if (fieldID == NULL) { return; } jSSL3KeyMatParam = (*env)->GetObjectField(env, jMechanism, fieldID); /* get the Java CK_SSL3_KEY_MAT_OUT */ + jSSL3KeyMatParamsClass = (*env)->FindClass(env, CLASS_SSL3_KEY_MAT_PARAMS); + if (jSSL3KeyMatParamsClass == NULL) { return; } fieldID = (*env)->GetFieldID(env, jSSL3KeyMatParamsClass, "pReturnedKeyMaterial", "L"CLASS_SSL3_KEY_MAT_OUT";"); - assert(fieldID != 0); + if (fieldID == NULL) { return; } jSSL3KeyMatOut = (*env)->GetObjectField(env, jSSL3KeyMatParam, fieldID); /* now copy back all the key handles and the initialization vectors */ /* copy back client MAC secret handle */ + jSSL3KeyMatOutClass = (*env)->FindClass(env, CLASS_SSL3_KEY_MAT_OUT); + if (jSSL3KeyMatOutClass == NULL) { return; } fieldID = (*env)->GetFieldID(env, jSSL3KeyMatOutClass, "hClientMacSecret", "J"); - assert(fieldID != 0); + if (fieldID == NULL) { return; } (*env)->SetLongField(env, jSSL3KeyMatOut, fieldID, ckULongToJLong(ckSSL3KeyMatOut->hClientMacSecret)); /* copy back server MAC secret handle */ fieldID = (*env)->GetFieldID(env, jSSL3KeyMatOutClass, "hServerMacSecret", "J"); - assert(fieldID != 0); + if (fieldID == NULL) { return; } (*env)->SetLongField(env, jSSL3KeyMatOut, fieldID, ckULongToJLong(ckSSL3KeyMatOut->hServerMacSecret)); /* copy back client secret key handle */ fieldID = (*env)->GetFieldID(env, jSSL3KeyMatOutClass, "hClientKey", "J"); - assert(fieldID != 0); + if (fieldID == NULL) { return; } (*env)->SetLongField(env, jSSL3KeyMatOut, fieldID, ckULongToJLong(ckSSL3KeyMatOut->hClientKey)); /* copy back server secret key handle */ fieldID = (*env)->GetFieldID(env, jSSL3KeyMatOutClass, "hServerKey", "J"); - assert(fieldID != 0); + if (fieldID == NULL) { return; } (*env)->SetLongField(env, jSSL3KeyMatOut, fieldID, ckULongToJLong(ckSSL3KeyMatOut->hServerKey)); /* copy back the client IV */ fieldID = (*env)->GetFieldID(env, jSSL3KeyMatOutClass, "pIVClient", "[B"); - assert(fieldID != 0); + if (fieldID == NULL) { return; } jIV = (*env)->GetObjectField(env, jSSL3KeyMatOut, fieldID); iv = ckSSL3KeyMatOut->pIVClient; if (jIV != NULL) { jLength = (*env)->GetArrayLength(env, jIV); jBytes = (*env)->GetByteArrayElements(env, jIV, NULL); + if (jBytes == NULL) { return; } /* copy the bytes to the Java buffer */ for (i=0; i < jLength; i++) { jBytes[i] = ckByteToJByte(iv[i]); } /* copy back the Java buffer to the object */ (*env)->ReleaseByteArrayElements(env, jIV, jBytes, 0); - // free malloc'd data - free(iv); } + // free malloc'd data + free(ckSSL3KeyMatOut->pIVClient); /* copy back the server IV */ fieldID = (*env)->GetFieldID(env, jSSL3KeyMatOutClass, "pIVServer", "[B"); - assert(fieldID != 0); + if (fieldID == NULL) { return; } jIV = (*env)->GetObjectField(env, jSSL3KeyMatOut, fieldID); iv = ckSSL3KeyMatOut->pIVServer; if (jIV != NULL) { jLength = (*env)->GetArrayLength(env, jIV); jBytes = (*env)->GetByteArrayElements(env, jIV, NULL); + if (jBytes == NULL) { return; } /* copy the bytes to the Java buffer */ for (i=0; i < jLength; i++) { jBytes[i] = ckByteToJByte(iv[i]); } /* copy back the Java buffer to the object */ (*env)->ReleaseByteArrayElements(env, jIV, jBytes, 0); - // free malloc'd data - free(iv); } - // free malloc'd data + free(ckSSL3KeyMatOut->pIVServer); free(ckSSL3KeyMatOut); } } diff --git a/src/share/native/sun/security/pkcs11/wrapper/p11_mutex.c b/src/share/native/sun/security/pkcs11/wrapper/p11_mutex.c index 31674f4ef9cd2e62b65260d1e6a160bc698111ee..cb04af5a37327e1e6dd809d7cc9156a466342072 100644 --- a/src/share/native/sun/security/pkcs11/wrapper/p11_mutex.c +++ b/src/share/native/sun/security/pkcs11/wrapper/p11_mutex.c @@ -1,5 +1,5 @@ /* - * Portions Copyright 2003 Sun Microsystems, Inc. All Rights Reserved. + * Portions Copyright 2003-2009 Sun Microsystems, Inc. All Rights Reserved. */ /* Copyright (c) 2002 Graz University of Technology. All rights reserved. @@ -76,7 +76,7 @@ CK_C_INITIALIZE_ARGS_PTR ckpGlobalInitArgs; CK_C_INITIALIZE_ARGS_PTR makeCKInitArgsAdapter(JNIEnv *env, jobject jInitArgs) { CK_C_INITIALIZE_ARGS_PTR ckpInitArgs; - jclass jInitArgsClass = (*env)->FindClass(env, CLASS_C_INITIALIZE_ARGS); + jclass jInitArgsClass; jfieldID fieldID; jlong jFlags; jobject jReserved; @@ -91,10 +91,20 @@ CK_C_INITIALIZE_ARGS_PTR makeCKInitArgsAdapter(JNIEnv *env, jobject jInitArgs) /* convert the Java InitArgs object to a pointer to a CK_C_INITIALIZE_ARGS structure */ ckpInitArgs = (CK_C_INITIALIZE_ARGS_PTR) malloc(sizeof(CK_C_INITIALIZE_ARGS)); + if (ckpInitArgs == NULL) { + JNU_ThrowOutOfMemoryError(env, 0); + return NULL_PTR; + } /* Set the mutex functions that will call the Java mutex functions, but * only set it, if the field is not null. */ + jInitArgsClass = (*env)->FindClass(env, CLASS_C_INITIALIZE_ARGS); + if (jInitArgsClass == NULL) { + free(ckpInitArgs); + return NULL; + } + #ifdef NO_CALLBACKS ckpInitArgs->CreateMutex = NULL_PTR; ckpInitArgs->DestroyMutex = NULL_PTR; @@ -102,22 +112,22 @@ CK_C_INITIALIZE_ARGS_PTR makeCKInitArgsAdapter(JNIEnv *env, jobject jInitArgs) ckpInitArgs->UnlockMutex = NULL_PTR; #else fieldID = (*env)->GetFieldID(env, jInitArgsClass, "CreateMutex", "Lsun/security/pkcs11/wrapper/CK_CREATEMUTEX;"); - assert(fieldID != 0); + if (fieldID == NULL) { return NULL; } jMutexHandler = (*env)->GetObjectField(env, jInitArgs, fieldID); ckpInitArgs->CreateMutex = (jMutexHandler != NULL) ? &callJCreateMutex : NULL_PTR; fieldID = (*env)->GetFieldID(env, jInitArgsClass, "DestroyMutex", "Lsun/security/pkcs11/wrapper/CK_DESTROYMUTEX;"); - assert(fieldID != 0); + if (fieldID == NULL) { return NULL; } jMutexHandler = (*env)->GetObjectField(env, jInitArgs, fieldID); ckpInitArgs->DestroyMutex = (jMutexHandler != NULL) ? &callJDestroyMutex : NULL_PTR; fieldID = (*env)->GetFieldID(env, jInitArgsClass, "LockMutex", "Lsun/security/pkcs11/wrapper/CK_LOCKMUTEX;"); - assert(fieldID != 0); + if (fieldID == NULL) { return NULL; } jMutexHandler = (*env)->GetObjectField(env, jInitArgs, fieldID); ckpInitArgs->LockMutex = (jMutexHandler != NULL) ? &callJLockMutex : NULL_PTR; fieldID = (*env)->GetFieldID(env, jInitArgsClass, "UnlockMutex", "Lsun/security/pkcs11/wrapper/CK_UNLOCKMUTEX;"); - assert(fieldID != 0); + if (fieldID == NULL) { return NULL; } jMutexHandler = (*env)->GetObjectField(env, jInitArgs, fieldID); ckpInitArgs->UnlockMutex = (jMutexHandler != NULL) ? &callJUnlockMutex : NULL_PTR; @@ -129,19 +139,25 @@ CK_C_INITIALIZE_ARGS_PTR makeCKInitArgsAdapter(JNIEnv *env, jobject jInitArgs) /* set the global object jInitArgs so that the right Java mutex functions will be called */ jInitArgsObject = (*env)->NewGlobalRef(env, jInitArgs); ckpGlobalInitArgs = (CK_C_INITIALIZE_ARGS_PTR) malloc(sizeof(CK_C_INITIALIZE_ARGS)); + if (ckpGlobalInitArgs == NULL) { + free(ckpInitArgs); + JNU_ThrowOutOfMemoryError(env, 0); + return NULL_PTR; + } + memcpy(ckpGlobalInitArgs, ckpInitArgs, sizeof(CK_C_INITIALIZE_ARGS)); } #endif /* NO_CALLBACKS */ /* convert and set the flags field */ fieldID = (*env)->GetFieldID(env, jInitArgsClass, "flags", "J"); - assert(fieldID != 0); + if (fieldID == NULL) { return NULL; } jFlags = (*env)->GetLongField(env, jInitArgs, fieldID); ckpInitArgs->flags = jLongToCKULong(jFlags); /* pReserved should be NULL_PTR in this version */ fieldID = (*env)->GetFieldID(env, jInitArgsClass, "pReserved", "Ljava/lang/Object;"); - assert(fieldID != 0); + if (fieldID == NULL) { return NULL; } jReserved = (*env)->GetObjectField(env, jInitArgs, fieldID); /* we try to convert the reserved parameter also */ @@ -201,20 +217,21 @@ CK_RV callJCreateMutex(CK_VOID_PTR_PTR ppMutex) wasAttached = 1; } - jCreateMutexClass = (*env)->FindClass(env, CLASS_CREATEMUTEX); + if (jCreateMutexClass == NULL) { return rv; } jInitArgsClass = (*env)->FindClass(env, CLASS_C_INITIALIZE_ARGS); + if (jInitArgsClass == NULL) { return rv; } /* get the CreateMutex object out of the jInitArgs object */ fieldID = (*env)->GetFieldID(env, jInitArgsClass, "CreateMutex", "Lsun/security/pkcs11/wrapper/CK_CREATEMUTEX;"); - assert(fieldID != 0); + if (fieldID == NULL) { return rv; } jCreateMutex = (*env)->GetObjectField(env, jInitArgsObject, fieldID); assert(jCreateMutex != 0); /* call the CK_CREATEMUTEX function of the CreateMutex object */ /* and get the new Java mutex object */ methodID = (*env)->GetMethodID(env, jCreateMutexClass, "CK_CREATEMUTEX", "()Ljava/lang/Object;"); - assert(methodID != 0); + if (methodID == NULL) { return rv; } jMutex = (*env)->CallObjectMethod(env, jCreateMutex, methodID); /* set a global reference on the Java mutex */ @@ -227,10 +244,13 @@ CK_RV callJCreateMutex(CK_VOID_PTR_PTR ppMutex) pkcs11Exception = (*env)->ExceptionOccurred(env); if (pkcs11Exception != NULL) { + /* TBD: clear the pending exception with ExceptionClear? */ /* The was an exception thrown, now we get the error-code from it */ pkcs11ExceptionClass = (*env)->FindClass(env, CLASS_PKCS11EXCEPTION); + if (pkcs11ExceptionClass == NULL) { return rv; } methodID = (*env)->GetMethodID(env, pkcs11ExceptionClass, "getErrorCode", "()J"); - assert(methodID != 0); + if (methodID == NULL) { return rv; } + errorCode = (*env)->CallLongMethod(env, pkcs11Exception, methodID); rv = jLongToCKULong(errorCode); } @@ -292,22 +312,23 @@ CK_RV callJDestroyMutex(CK_VOID_PTR pMutex) wasAttached = 1; } - jDestroyMutexClass = (*env)->FindClass(env, CLASS_DESTROYMUTEX); + if (jDestroyMutexClass == NULL) { return rv; } jInitArgsClass = (*env)->FindClass(env, CLASS_C_INITIALIZE_ARGS); + if (jInitArgsClass == NULL) { return rv; } /* convert the CK mutex to a Java mutex */ jMutex = ckVoidPtrToJObject(pMutex); /* get the DestroyMutex object out of the jInitArgs object */ fieldID = (*env)->GetFieldID(env, jInitArgsClass, "DestroyMutex", "Lsun/security/pkcs11/wrapper/CK_DESTROYMUTEX;"); - assert(fieldID != 0); + if (fieldID == NULL) { return rv; } jDestroyMutex = (*env)->GetObjectField(env, jInitArgsObject, fieldID); assert(jDestroyMutex != 0); /* call the CK_DESTROYMUTEX method of the DestroyMutex object */ methodID = (*env)->GetMethodID(env, jDestroyMutexClass, "CK_DESTROYMUTEX", "(Ljava/lang/Object;)V"); - assert(methodID != 0); + if (methodID == NULL) { return rv; } (*env)->CallVoidMethod(env, jDestroyMutex, methodID, jMutex); /* delete the global reference on the Java mutex */ @@ -318,10 +339,12 @@ CK_RV callJDestroyMutex(CK_VOID_PTR pMutex) pkcs11Exception = (*env)->ExceptionOccurred(env); if (pkcs11Exception != NULL) { + /* TBD: clear the pending exception with ExceptionClear? */ /* The was an exception thrown, now we get the error-code from it */ pkcs11ExceptionClass = (*env)->FindClass(env, CLASS_PKCS11EXCEPTION); + if (pkcs11ExceptionClass == NULL) { return rv; } methodID = (*env)->GetMethodID(env, pkcs11ExceptionClass, "getErrorCode", "()J"); - assert(methodID != 0); + if (methodID == NULL) { return rv; } errorCode = (*env)->CallLongMethod(env, pkcs11Exception, methodID); rv = jLongToCKULong(errorCode); } @@ -383,33 +406,35 @@ CK_RV callJLockMutex(CK_VOID_PTR pMutex) wasAttached = 1; } - jLockMutexClass = (*env)->FindClass(env, CLASS_LOCKMUTEX); + if (jLockMutexClass == NULL) { return rv; } jInitArgsClass = (*env)->FindClass(env, CLASS_C_INITIALIZE_ARGS); + if (jInitArgsClass == NULL) { return rv; } /* convert the CK mutex to a Java mutex */ jMutex = ckVoidPtrToJObject(pMutex); /* get the LockMutex object out of the jInitArgs object */ fieldID = (*env)->GetFieldID(env, jInitArgsClass, "LockMutex", "Lsun/security/pkcs11/wrapper/CK_LOCKMUTEX;"); - assert(fieldID != 0); + if (fieldID == NULL) { return rv; } jLockMutex = (*env)->GetObjectField(env, jInitArgsObject, fieldID); assert(jLockMutex != 0); /* call the CK_LOCKMUTEX method of the LockMutex object */ methodID = (*env)->GetMethodID(env, jLockMutexClass, "CK_LOCKMUTEX", "(Ljava/lang/Object;)V"); - assert(methodID != 0); + if (methodID == NULL) { return rv; } (*env)->CallVoidMethod(env, jLockMutex, methodID, jMutex); - /* check, if callback threw an exception */ pkcs11Exception = (*env)->ExceptionOccurred(env); if (pkcs11Exception != NULL) { + /* TBD: clear the pending exception with ExceptionClear? */ /* The was an exception thrown, now we get the error-code from it */ pkcs11ExceptionClass = (*env)->FindClass(env, CLASS_PKCS11EXCEPTION); + if (pkcs11ExceptionClass == NULL) { return rv; } methodID = (*env)->GetMethodID(env, pkcs11ExceptionClass, "getErrorCode", "()J"); - assert(methodID != 0); + if (methodID == NULL) { return rv; } errorCode = (*env)->CallLongMethod(env, pkcs11Exception, methodID); rv = jLongToCKULong(errorCode); } @@ -471,33 +496,35 @@ CK_RV callJUnlockMutex(CK_VOID_PTR pMutex) wasAttached = 1; } - jUnlockMutexClass = (*env)->FindClass(env, CLASS_UNLOCKMUTEX); + if (jUnlockMutexClass == NULL) { return rv; } jInitArgsClass = (*env)->FindClass(env, CLASS_C_INITIALIZE_ARGS); + if (jInitArgsClass == NULL) { return rv; } /* convert the CK-type mutex to a Java mutex */ jMutex = ckVoidPtrToJObject(pMutex); /* get the UnlockMutex object out of the jInitArgs object */ fieldID = (*env)->GetFieldID(env, jInitArgsClass, "UnlockMutex", "Lsun/security/pkcs11/wrapper/CK_UNLOCKMUTEX;"); - assert(fieldID != 0); + if (fieldID == NULL) { return rv; } jUnlockMutex = (*env)->GetObjectField(env, jInitArgsObject, fieldID); assert(jUnlockMutex != 0); /* call the CK_UNLOCKMUTEX method of the UnLockMutex object */ methodID = (*env)->GetMethodID(env, jUnlockMutexClass, "CK_UNLOCKMUTEX", "(Ljava/lang/Object;)V"); - assert(methodID != 0); + if (methodID == NULL) { return rv; } (*env)->CallVoidMethod(env, jUnlockMutex, methodID, jMutex); - /* check, if callback threw an exception */ pkcs11Exception = (*env)->ExceptionOccurred(env); if (pkcs11Exception != NULL) { + /* TBD: clear the pending exception with ExceptionClear? */ /* The was an exception thrown, now we get the error-code from it */ pkcs11ExceptionClass = (*env)->FindClass(env, CLASS_PKCS11EXCEPTION); + if (pkcs11ExceptionClass == NULL) { return rv; } methodID = (*env)->GetMethodID(env, pkcs11ExceptionClass, "getErrorCode", "()J"); - assert(methodID != 0); + if (methodID == NULL) { return rv; } errorCode = (*env)->CallLongMethod(env, pkcs11Exception, methodID); rv = jLongToCKULong(errorCode); } diff --git a/src/share/native/sun/security/pkcs11/wrapper/p11_objmgmt.c b/src/share/native/sun/security/pkcs11/wrapper/p11_objmgmt.c index 0fb10f151a0c4a41576297f6ee4cef1d1c257058..a72f20d2719f7655e5dbb885330b2158d6b5588d 100644 --- a/src/share/native/sun/security/pkcs11/wrapper/p11_objmgmt.c +++ b/src/share/native/sun/security/pkcs11/wrapper/p11_objmgmt.c @@ -1,5 +1,5 @@ /* - * Portions Copyright 2003 Sun Microsystems, Inc. All Rights Reserved. + * Portions Copyright 2003-2009 Sun Microsystems, Inc. All Rights Reserved. */ /* Copyright (c) 2002 Graz University of Technology. All rights reserved. @@ -81,16 +81,14 @@ JNIEXPORT jlong JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1CreateObject ckSessionHandle = jLongToCKULong(jSessionHandle); jAttributeArrayToCKAttributeArray(env, jTemplate, &ckpAttributes, &ckAttributesLength); + if ((*env)->ExceptionCheck(env)) { return 0L; } rv = (*ckpFunctions->C_CreateObject)(ckSessionHandle, ckpAttributes, ckAttributesLength, &ckObjectHandle); jObjectHandle = ckULongToJLong(ckObjectHandle); - for(i=0; i<ckAttributesLength; i++) - if(ckpAttributes[i].pValue != NULL_PTR) - free(ckpAttributes[i].pValue); - free(ckpAttributes); + freeCKAttributeArray(ckpAttributes, ckAttributesLength); - if(ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return 0L ; } + if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return 0L ; } return jObjectHandle ; } @@ -126,14 +124,12 @@ JNIEXPORT jlong JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1CopyObject ckSessionHandle = jLongToCKULong(jSessionHandle); ckObjectHandle = jLongToCKULong(jObjectHandle); jAttributeArrayToCKAttributeArray(env, jTemplate, &ckpAttributes, &ckAttributesLength); + if ((*env)->ExceptionCheck(env)) { return 0L; } rv = (*ckpFunctions->C_CopyObject)(ckSessionHandle, ckObjectHandle, ckpAttributes, ckAttributesLength, &ckNewObjectHandle); jNewObjectHandle = ckULongToJLong(ckNewObjectHandle); - for(i=0; i<ckAttributesLength; i++) - if(ckpAttributes[i].pValue != NULL_PTR) - free(ckpAttributes[i].pValue); - free(ckpAttributes); + freeCKAttributeArray(ckpAttributes, ckAttributesLength); if(ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return 0L ; } @@ -164,7 +160,7 @@ JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1DestroyObject ckObjectHandle = jLongToCKULong(jObjectHandle); rv = (*ckpFunctions->C_DestroyObject)(ckSessionHandle, ckObjectHandle); - if(ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return; } + if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return; } } #endif @@ -194,7 +190,7 @@ JNIEXPORT jlong JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1GetObjectSize ckObjectHandle = jLongToCKULong(jObjectHandle); rv = (*ckpFunctions->C_GetObjectSize)(ckSessionHandle, ckObjectHandle, &ckObjectSize); - if(ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return 0L ; } + if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return 0L ; } jObjectSize = ckULongToJLong(ckObjectSize); @@ -221,7 +217,7 @@ JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1GetAttributeVa CK_ATTRIBUTE_PTR ckpAttributes = NULL_PTR; CK_ULONG ckAttributesLength; CK_ULONG ckBufferLength; - CK_ULONG i; + CK_ULONG i, j; jobject jAttribute; CK_RV rv; @@ -238,19 +234,20 @@ JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1GetAttributeVa ckObjectHandle = jLongToCKULong(jObjectHandle); TRACE1("jAttributeArrayToCKAttributeArray now with jTemplate = %d", jTemplate); jAttributeArrayToCKAttributeArray(env, jTemplate, &ckpAttributes, &ckAttributesLength); + if ((*env)->ExceptionCheck(env)) { return; } + TRACE2("DEBUG: jAttributeArrayToCKAttributeArray finished with ckpAttribute = %d, Length = %d\n", ckpAttributes, ckAttributesLength); /* first set all pValue to NULL, to get the needed buffer length */ for(i = 0; i < ckAttributesLength; i++) { - if(ckpAttributes[i].pValue != NULL_PTR) { + if (ckpAttributes[i].pValue != NULL_PTR) { free(ckpAttributes[i].pValue); + ckpAttributes[i].pValue = NULL_PTR; } } - for (i = 0; i < ckAttributesLength; i++) { - ckpAttributes[i].pValue = NULL_PTR; - } + rv = (*ckpFunctions->C_GetAttributeValue)(ckSessionHandle, ckObjectHandle, ckpAttributes, ckAttributesLength); - if(ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { + if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { free(ckpAttributes); return ; } @@ -261,27 +258,34 @@ JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1GetAttributeVa for (i = 0; i < ckAttributesLength; i++) { ckBufferLength = sizeof(CK_BYTE) * ckpAttributes[i].ulValueLen; ckpAttributes[i].pValue = (void *) malloc(ckBufferLength); + if (ckpAttributes[i].pValue == NULL) { + freeCKAttributeArray(ckpAttributes, i); + JNU_ThrowOutOfMemoryError(env, 0); + return; + } ckpAttributes[i].ulValueLen = ckBufferLength; } /* now get the attributes with all values */ rv = (*ckpFunctions->C_GetAttributeValue)(ckSessionHandle, ckObjectHandle, ckpAttributes, ckAttributesLength); - /* copy back the values to the Java attributes */ - for (i = 0; i < ckAttributesLength; i++) { - jAttribute = ckAttributePtrToJAttribute(env, &(ckpAttributes[i])); - (*env)->SetObjectArrayElement(env, jTemplate, i, jAttribute); - } - - for(i=0; i<ckAttributesLength; i++) { - if(ckpAttributes[i].pValue != NULL_PTR) { - free(ckpAttributes[i].pValue); + if (ckAssertReturnValueOK(env, rv) == CK_ASSERT_OK) { + /* copy back the values to the Java attributes */ + for (i = 0; i < ckAttributesLength; i++) { + jAttribute = ckAttributePtrToJAttribute(env, &(ckpAttributes[i])); + if (jAttribute == NULL) { + freeCKAttributeArray(ckpAttributes, ckAttributesLength); + return; + } + (*env)->SetObjectArrayElement(env, jTemplate, i, jAttribute); + if ((*env)->ExceptionCheck(env)) { + freeCKAttributeArray(ckpAttributes, ckAttributesLength); + return; + } } } - free(ckpAttributes); + freeCKAttributeArray(ckpAttributes, ckAttributesLength); TRACE0("FINISHED\n"); - - if(ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return ; } } #endif @@ -312,15 +316,11 @@ JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1SetAttributeVa ckSessionHandle = jLongToCKULong(jSessionHandle); ckObjectHandle = jLongToCKULong(jObjectHandle); jAttributeArrayToCKAttributeArray(env, jTemplate, &ckpAttributes, &ckAttributesLength); + if ((*env)->ExceptionCheck(env)) { return; } rv = (*ckpFunctions->C_SetAttributeValue)(ckSessionHandle, ckObjectHandle, ckpAttributes, ckAttributesLength); - for(i=0; i<ckAttributesLength; i++) { - if(ckpAttributes[i].pValue != NULL_PTR) { - free(ckpAttributes[i].pValue); - } - } - free(ckpAttributes); + freeCKAttributeArray(ckpAttributes, ckAttributesLength); if(ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return; } } @@ -355,15 +355,11 @@ JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1FindObjectsIni ckSessionHandle = jLongToCKULong(jSessionHandle); jAttributeArrayToCKAttributeArray(env, jTemplate, &ckpAttributes, &ckAttributesLength); + if ((*env)->ExceptionCheck(env)) { return; } rv = (*ckpFunctions->C_FindObjectsInit)(ckSessionHandle, ckpAttributes, ckAttributesLength); - for(i=0; i<ckAttributesLength; i++) { - if(ckpAttributes[i].pValue != NULL_PTR) { - free(ckpAttributes[i].pValue); - } - } - free(ckpAttributes); + freeCKAttributeArray(ckpAttributes, ckAttributesLength); TRACE0("FINISHED\n"); if(ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return; } @@ -397,14 +393,18 @@ JNIEXPORT jlongArray JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1FindObje ckSessionHandle = jLongToCKULong(jSessionHandle); ckMaxObjectLength = jLongToCKULong(jMaxObjectCount); ckpObjectHandleArray = (CK_OBJECT_HANDLE_PTR) malloc(sizeof(CK_OBJECT_HANDLE) * ckMaxObjectLength); + if (ckpObjectHandleArray == NULL) { + JNU_ThrowOutOfMemoryError(env, 0); + return NULL; + } rv = (*ckpFunctions->C_FindObjects)(ckSessionHandle, ckpObjectHandleArray, ckMaxObjectLength, &ckActualObjectCount); + if (ckAssertReturnValueOK(env, rv) == CK_ASSERT_OK) { + jObjectHandleArray = ckULongArrayToJLongArray(env, ckpObjectHandleArray, ckActualObjectCount); + } - jObjectHandleArray = ckULongArrayToJLongArray(env, ckpObjectHandleArray, ckActualObjectCount); free(ckpObjectHandleArray); - if(ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return NULL ; } - return jObjectHandleArray ; } #endif diff --git a/src/share/native/sun/security/pkcs11/wrapper/p11_sessmgmt.c b/src/share/native/sun/security/pkcs11/wrapper/p11_sessmgmt.c index cc2364cd7d94ee26b90b297e6a8c03d5c4ae6b7d..950b90641705fb91d36f78f51ebcdf5f53003c73 100644 --- a/src/share/native/sun/security/pkcs11/wrapper/p11_sessmgmt.c +++ b/src/share/native/sun/security/pkcs11/wrapper/p11_sessmgmt.c @@ -1,5 +1,5 @@ /* - * Portions Copyright 2003 Sun Microsystems, Inc. All Rights Reserved. + * Portions Copyright 2003-2009 Sun Microsystems, Inc. All Rights Reserved. */ /* Copyright (c) 2002 Graz University of Technology. All rights reserved. @@ -97,6 +97,10 @@ JNIEXPORT jlong JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1OpenSession #ifndef NO_CALLBACKS if (jNotify != NULL) { notifyEncapsulation = (NotifyEncapsulation *) malloc(sizeof(NotifyEncapsulation)); + if (notifyEncapsulation == NULL) { + JNU_ThrowOutOfMemoryError(env, 0); + return 0L; + } notifyEncapsulation->jApplicationData = (jApplication != NULL) ? (*env)->NewGlobalRef(env, jApplication) : NULL; @@ -118,7 +122,18 @@ JNIEXPORT jlong JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1OpenSession TRACE0(" ... "); rv = (*ckpFunctions->C_OpenSession)(ckSlotID, ckFlags, ckpApplication, ckNotify, &ckSessionHandle); - if(ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return 0L ; } + if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { +#ifndef NO_CALLBACKS + if (notifyEncapsulation != NULL) { + if (notifyEncapsulation->jApplicationData != NULL) { + (*env)->DeleteGlobalRef(env, jApplication); + } + (*env)->DeleteGlobalRef(env, jNotify); + free(notifyEncapsulation); + } +#endif /* NO_CALLBACKS */ + return 0L; + } TRACE0("got session"); TRACE1(", SessionHandle=%u", ckSessionHandle); @@ -163,7 +178,7 @@ JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1CloseSession ckSessionHandle = jLongToCKULong(jSessionHandle); rv = (*ckpFunctions->C_CloseSession)(ckSessionHandle); - if(ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return; } + if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return; } #ifndef NO_CALLBACKS notifyEncapsulation = removeNotifyEntry(env, ckSessionHandle); @@ -208,7 +223,7 @@ JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1CloseAllSessio ckSlotID = jLongToCKULong(jSlotID); rv = (*ckpFunctions->C_CloseAllSessions)(ckSlotID); - if(ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return; } + if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return; } #ifndef NO_CALLBACKS /* Remove all notify callback helper objects. */ @@ -250,10 +265,9 @@ JNIEXPORT jobject JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1GetSessionI ckSessionHandle = jLongToCKULong(jSessionHandle); rv = (*ckpFunctions->C_GetSessionInfo)(ckSessionHandle, &ckSessionInfo); - if(ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return NULL ; } - - jSessionInfo = ckSessionInfoPtrToJSessionInfo(env, &ckSessionInfo); - + if (ckAssertReturnValueOK(env, rv) == CK_ASSERT_OK) { + jSessionInfo = ckSessionInfoPtrToJSessionInfo(env, &ckSessionInfo); + } return jSessionInfo ; } #endif @@ -274,7 +288,7 @@ JNIEXPORT jbyteArray JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1GetOpera CK_SESSION_HANDLE ckSessionHandle; CK_BYTE_PTR ckpState; CK_ULONG ckStateLength; - jbyteArray jState; + jbyteArray jState = NULL; CK_RV rv; CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj); @@ -283,17 +297,20 @@ JNIEXPORT jbyteArray JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1GetOpera ckSessionHandle = jLongToCKULong(jSessionHandle); rv = (*ckpFunctions->C_GetOperationState)(ckSessionHandle, NULL_PTR, &ckStateLength); - if(ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return NULL ; } + if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return NULL ; } ckpState = (CK_BYTE_PTR) malloc(ckStateLength); + if (ckpState == NULL) { + JNU_ThrowOutOfMemoryError(env, 0); + return NULL; + } rv = (*ckpFunctions->C_GetOperationState)(ckSessionHandle, ckpState, &ckStateLength); - - jState = ckByteArrayToJByteArray(env, ckpState, ckStateLength); + if (ckAssertReturnValueOK(env, rv) == CK_ASSERT_OK) { + jState = ckByteArrayToJByteArray(env, ckpState, ckStateLength); + } free(ckpState); - if(ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return NULL ; } - return jState ; } #endif @@ -325,6 +342,8 @@ JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1SetOperationSt ckSessionHandle = jLongToCKULong(jSessionHandle); jByteArrayToCKByteArray(env, jOperationState, &ckpState, &ckStateLength); + if ((*env)->ExceptionCheck(env)) { return; } + ckEncryptionKeyHandle = jLongToCKULong(jEncryptionKeyHandle); ckAuthenticationKeyHandle = jLongToCKULong(jAuthenticationKeyHandle); @@ -332,7 +351,7 @@ JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1SetOperationSt free(ckpState); - if(ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return; } + if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return; } } #endif @@ -362,12 +381,13 @@ JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1Login ckSessionHandle = jLongToCKULong(jSessionHandle); ckUserType = jLongToCKULong(jUserType); jCharArrayToCKCharArray(env, jPin, &ckpPinArray, &ckPinLength); + if ((*env)->ExceptionCheck(env)) { return; } rv = (*ckpFunctions->C_Login)(ckSessionHandle, ckUserType, ckpPinArray, ckPinLength); free(ckpPinArray); - if(ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return; } + if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return; } } #endif @@ -391,7 +411,7 @@ JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1Logout ckSessionHandle = jLongToCKULong(jSessionHandle); rv = (*ckpFunctions->C_Logout)(ckSessionHandle); - if(ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return; } + if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return; } } #endif @@ -410,10 +430,14 @@ void putNotifyEntry(JNIEnv *env, CK_SESSION_HANDLE hSession, NotifyEncapsulation NotifyListNode *currentNode, *newNode; if (notifyEncapsulation == NULL) { - return ; + return; } newNode = (NotifyListNode *) malloc(sizeof(NotifyListNode)); + if (newNode == NULL) { + JNU_ThrowOutOfMemoryError(env, 0); + return; + } newNode->hSession = hSession; newNode->notifyEncapsulation = notifyEncapsulation; newNode->next = NULL; @@ -578,9 +602,10 @@ CK_RV notifyCallback( jEvent = ckULongToJLong(event); ckNotifyClass = (*env)->FindClass(env, CLASS_NOTIFY); - assert(ckNotifyClass != 0); + if (ckNotifyClass == NULL) { return rv; } jmethod = (*env)->GetMethodID(env, ckNotifyClass, "CK_NOTIFY", "(JJLjava/lang/Object;)V"); - assert(jmethod != 0); + if (jmethod == NULL) { return rv; } + (*env)->CallVoidMethod(env, notifyEncapsulation->jNotifyObject, jmethod, jSessionHandle, jEvent, notifyEncapsulation->jApplicationData); @@ -588,10 +613,14 @@ CK_RV notifyCallback( pkcs11Exception = (*env)->ExceptionOccurred(env); if (pkcs11Exception != NULL) { + /* TBD: clear the pending exception with ExceptionClear? */ /* The was an exception thrown, now we get the error-code from it */ pkcs11ExceptionClass = (*env)->FindClass(env, CLASS_PKCS11EXCEPTION); + if (pkcs11ExceptionClass == NULL) { return rv; } + jmethod = (*env)->GetMethodID(env, pkcs11ExceptionClass, "getErrorCode", "()J"); - assert(jmethod != 0); + if (jmethod == NULL) { return rv; } + errorCode = (*env)->CallLongMethod(env, pkcs11Exception, jmethod); rv = jLongToCKULong(errorCode); } diff --git a/src/share/native/sun/security/pkcs11/wrapper/p11_sign.c b/src/share/native/sun/security/pkcs11/wrapper/p11_sign.c index 0ac75784c8384f6651574accfdc6aa6b44f10daf..e55755d1cf07bd7030841403d7f5632d1f32d326 100644 --- a/src/share/native/sun/security/pkcs11/wrapper/p11_sign.c +++ b/src/share/native/sun/security/pkcs11/wrapper/p11_sign.c @@ -1,5 +1,5 @@ /* - * Portions Copyright 2003-2005 Sun Microsystems, Inc. All Rights Reserved. + * Portions Copyright 2003-2009 Sun Microsystems, Inc. All Rights Reserved. */ /* Copyright (c) 2002 Graz University of Technology. All rights reserved. @@ -77,15 +77,16 @@ JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1SignInit ckSessionHandle = jLongToCKULong(jSessionHandle); jMechanismToCKMechanism(env, jMechanism, &ckMechanism); + if ((*env)->ExceptionCheck(env)) { return; } ckKeyHandle = jLongToCKULong(jKeyHandle); rv = (*ckpFunctions->C_SignInit)(ckSessionHandle, &ckMechanism, ckKeyHandle); - if(ckMechanism.pParameter != NULL_PTR) { + if (ckMechanism.pParameter != NULL_PTR) { free(ckMechanism.pParameter); } - if(ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return; } + if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return; } } #endif @@ -117,14 +118,23 @@ JNIEXPORT jbyteArray JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1Sign ckSessionHandle = jLongToCKULong(jSessionHandle); jByteArrayToCKByteArray(env, jData, &ckpData, &ckDataLength); + if ((*env)->ExceptionCheck(env)) { return NULL; } /* START standard code */ /* first determine the length of the signature */ rv = (*ckpFunctions->C_Sign)(ckSessionHandle, ckpData, ckDataLength, NULL_PTR, &ckSignatureLength); - if(ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return NULL ; } + if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { + free(ckpData); + return NULL; + } ckpSignature = (CK_BYTE_PTR) malloc(ckSignatureLength * sizeof(CK_BYTE)); + if (ckpSignature == NULL) { + free(ckpData); + JNU_ThrowOutOfMemoryError(env, 0); + return NULL; + } /* now get the signature */ rv = (*ckpFunctions->C_Sign)(ckSessionHandle, ckpData, ckDataLength, ckpSignature, &ckSignatureLength); @@ -134,22 +144,31 @@ JNIEXPORT jbyteArray JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1Sign /* START workaround code for operation abort bug in pkcs#11 of Datakey and iButton */ /* ckpSignature = (CK_BYTE_PTR) malloc(256 * sizeof(CK_BYTE)); + if (ckpSignature == NULL) { + free(ckpData); + JNU_ThrowOutOfMemoryError(env, 0); + return NULL; + } rv = (*ckpFunctions->C_Sign)(ckSessionHandle, ckpData, ckDataLength, ckpSignature, &ckSignatureLength); if (rv == CKR_BUFFER_TOO_SMALL) { free(ckpSignature); ckpSignature = (CK_BYTE_PTR) malloc(ckSignatureLength * sizeof(CK_BYTE)); + if (ckpSignature == NULL) { + free(ckpData); + JNU_ThrowOutOfMemoryError(env, 0); + return NULL; + } rv = (*ckpFunctions->C_Sign)(ckSessionHandle, ckpData, ckDataLength, ckpSignature, &ckSignatureLength); } */ /* END workaround code */ - - jSignature = ckByteArrayToJByteArray(env, ckpSignature, ckSignatureLength); + if (ckAssertReturnValueOK(env, rv) == CK_ASSERT_OK) { + jSignature = ckByteArrayToJByteArray(env, ckpSignature, ckSignatureLength); + } free(ckpData); free(ckpSignature); - if(ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return NULL ; } - return jSignature ; } #endif @@ -189,14 +208,22 @@ JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1SignUpdate bufP = BUF; } else { bufLen = min(MAX_HEAP_BUFFER_LEN, jInLen); - bufP = (CK_BYTE_PTR)malloc((size_t)bufLen); + bufP = (CK_BYTE_PTR) malloc((size_t)bufLen); + if (bufP == NULL) { + JNU_ThrowOutOfMemoryError(env, 0); + return; + } } while (jInLen > 0) { jsize chunkLen = min(bufLen, jInLen); (*env)->GetByteArrayRegion(env, jIn, jInOfs, chunkLen, (jbyte *)bufP); + if ((*env)->ExceptionCheck(env)) { + if (bufP != BUF) { free(bufP); } + return; + } rv = (*ckpFunctions->C_SignUpdate)(ckSessionHandle, bufP, chunkLen); - if(ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { + if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { if (bufP != BUF) { free(bufP); } @@ -206,9 +233,7 @@ JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1SignUpdate jInLen -= chunkLen; } - if (bufP != BUF) { - free(bufP); - } + if (bufP != BUF) { free(bufP); } } #endif @@ -244,15 +269,18 @@ JNIEXPORT jbyteArray JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1SignFina rv = (*ckpFunctions->C_SignFinal)(ckSessionHandle, bufP, &ckSignatureLength); if (rv == CKR_BUFFER_TOO_SMALL) { bufP = (CK_BYTE_PTR) malloc(ckSignatureLength); + if (bufP == NULL) { + JNU_ThrowOutOfMemoryError(env, 0); + return NULL; + } rv = (*ckpFunctions->C_SignFinal)(ckSessionHandle, bufP, &ckSignatureLength); } if (ckAssertReturnValueOK(env, rv) == CK_ASSERT_OK) { jSignature = ckByteArrayToJByteArray(env, bufP, ckSignatureLength); } - if (bufP != BUF) { - free(bufP); - } + if (bufP != BUF) { free(bufP); } + return jSignature; } #endif @@ -280,11 +308,13 @@ JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1SignRecoverIni ckSessionHandle = jLongToCKULong(jSessionHandle); jMechanismToCKMechanism(env, jMechanism, &ckMechanism); + if ((*env)->ExceptionCheck(env)) { return; } + ckKeyHandle = jLongToCKULong(jKeyHandle); rv = (*ckpFunctions->C_SignRecoverInit)(ckSessionHandle, &ckMechanism, ckKeyHandle); - if(ckMechanism.pParameter != NULL_PTR) { + if (ckMechanism.pParameter != NULL_PTR) { free(ckMechanism.pParameter); } @@ -323,26 +353,38 @@ JNIEXPORT jint JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1SignRecover if (jInLen <= MAX_STACK_BUFFER_LEN) { inBufP = INBUF; } else { - inBufP = (CK_BYTE_PTR)malloc((size_t)jInLen); + inBufP = (CK_BYTE_PTR) malloc((size_t)jInLen); + if (inBufP == NULL) { + JNU_ThrowOutOfMemoryError(env, 0); + return 0; + } } (*env)->GetByteArrayRegion(env, jIn, jInOfs, jInLen, (jbyte *)inBufP); + if ((*env)->ExceptionCheck(env)) { + if (inBufP != INBUF) { free(inBufP); } + return 0; + } rv = (*ckpFunctions->C_SignRecover)(ckSessionHandle, inBufP, jInLen, outBufP, &ckSignatureLength); /* re-alloc larger buffer if it fits into our Java buffer */ if ((rv == CKR_BUFFER_TOO_SMALL) && (ckSignatureLength <= jIntToCKULong(jOutLen))) { outBufP = (CK_BYTE_PTR) malloc(ckSignatureLength); + if (outBufP == NULL) { + if (inBufP != INBUF) { + free(inBufP); + } + JNU_ThrowOutOfMemoryError(env, 0); + return 0; + } rv = (*ckpFunctions->C_SignRecover)(ckSessionHandle, inBufP, jInLen, outBufP, &ckSignatureLength); } if (ckAssertReturnValueOK(env, rv) == CK_ASSERT_OK) { (*env)->SetByteArrayRegion(env, jOut, jOutOfs, ckSignatureLength, (jbyte *)outBufP); } - if (inBufP != INBUF) { - free(inBufP); - } - if (outBufP != OUTBUF) { - free(outBufP); - } + if (inBufP != INBUF) { free(inBufP); } + if (outBufP != OUTBUF) { free(outBufP); } + return ckSignatureLength; } #endif @@ -370,6 +412,8 @@ JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1VerifyInit ckSessionHandle = jLongToCKULong(jSessionHandle); jMechanismToCKMechanism(env, jMechanism, &ckMechanism); + if ((*env)->ExceptionCheck(env)) { return; } + ckKeyHandle = jLongToCKULong(jKeyHandle); rv = (*ckpFunctions->C_VerifyInit)(ckSessionHandle, &ckMechanism, ckKeyHandle); @@ -378,7 +422,7 @@ JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1VerifyInit free(ckMechanism.pParameter); } - if(ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return; } + if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return; } } #endif @@ -409,7 +453,13 @@ JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1Verify ckSessionHandle = jLongToCKULong(jSessionHandle); jByteArrayToCKByteArray(env, jData, &ckpData, &ckDataLength); + if ((*env)->ExceptionCheck(env)) { return; } + jByteArrayToCKByteArray(env, jSignature, &ckpSignature, &ckSignatureLength); + if ((*env)->ExceptionCheck(env)) { + free(ckpData); + return; + } /* verify the signature */ rv = (*ckpFunctions->C_Verify)(ckSessionHandle, ckpData, ckDataLength, ckpSignature, ckSignatureLength); @@ -417,7 +467,7 @@ JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1Verify free(ckpData); free(ckpSignature); - if(ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return; } + if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return; } } #endif @@ -456,26 +506,31 @@ JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1VerifyUpdate bufP = BUF; } else { bufLen = min(MAX_HEAP_BUFFER_LEN, jInLen); - bufP = (CK_BYTE_PTR)malloc((size_t)bufLen); + bufP = (CK_BYTE_PTR) malloc((size_t)bufLen); + if (bufP == NULL) { + JNU_ThrowOutOfMemoryError(env, 0); + return; + } } while (jInLen > 0) { jsize chunkLen = min(bufLen, jInLen); (*env)->GetByteArrayRegion(env, jIn, jInOfs, chunkLen, (jbyte *)bufP); + if ((*env)->ExceptionCheck(env)) { + if (bufP != BUF) { free(bufP); } + return; + } + rv = (*ckpFunctions->C_VerifyUpdate)(ckSessionHandle, bufP, chunkLen); - if(ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { - if (bufP != BUF) { - free(bufP); - } + if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { + if (bufP != BUF) { free(bufP); } return; } jInOfs += chunkLen; jInLen -= chunkLen; } - if (bufP != BUF) { - free(bufP); - } + if (bufP != BUF) { free(bufP); } } #endif @@ -502,13 +557,14 @@ JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1VerifyFinal ckSessionHandle = jLongToCKULong(jSessionHandle); jByteArrayToCKByteArray(env, jSignature, &ckpSignature, &ckSignatureLength); + if ((*env)->ExceptionCheck(env)) { return; } /* verify the signature */ rv = (*ckpFunctions->C_VerifyFinal)(ckSessionHandle, ckpSignature, ckSignatureLength); free(ckpSignature); - if(ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return; } + if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return; } } #endif @@ -535,15 +591,17 @@ JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1VerifyRecoverI ckSessionHandle = jLongToCKULong(jSessionHandle); jMechanismToCKMechanism(env, jMechanism, &ckMechanism); + if ((*env)->ExceptionCheck(env)) { return; } + ckKeyHandle = jLongToCKULong(jKeyHandle); rv = (*ckpFunctions->C_VerifyRecoverInit)(ckSessionHandle, &ckMechanism, ckKeyHandle); - if(ckMechanism.pParameter != NULL_PTR) { + if (ckMechanism.pParameter != NULL_PTR) { free(ckMechanism.pParameter); } - if(ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return; } + if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return; } } #endif @@ -578,26 +636,38 @@ JNIEXPORT jint JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1VerifyRecover if (jInLen <= MAX_STACK_BUFFER_LEN) { inBufP = INBUF; } else { - inBufP = (CK_BYTE_PTR)malloc((size_t)jInLen); + inBufP = (CK_BYTE_PTR) malloc((size_t)jInLen); + if (inBufP == NULL) { + JNU_ThrowOutOfMemoryError(env, 0); + return 0; + } } (*env)->GetByteArrayRegion(env, jIn, jInOfs, jInLen, (jbyte *)inBufP); + if ((*env)->ExceptionCheck(env)) { + if (inBufP != INBUF) { free(inBufP); } + return 0; + } + rv = (*ckpFunctions->C_VerifyRecover)(ckSessionHandle, inBufP, jInLen, outBufP, &ckDataLength); + /* re-alloc larger buffer if it fits into our Java buffer */ if ((rv == CKR_BUFFER_TOO_SMALL) && (ckDataLength <= jIntToCKULong(jOutLen))) { outBufP = (CK_BYTE_PTR) malloc(ckDataLength); + if (outBufP == NULL) { + if (inBufP != INBUF) { free(inBufP); } + JNU_ThrowOutOfMemoryError(env, 0); + return 0; + } rv = (*ckpFunctions->C_VerifyRecover)(ckSessionHandle, inBufP, jInLen, outBufP, &ckDataLength); } if (ckAssertReturnValueOK(env, rv) == CK_ASSERT_OK) { (*env)->SetByteArrayRegion(env, jOut, jOutOfs, ckDataLength, (jbyte *)outBufP); } - if (inBufP != INBUF) { - free(inBufP); - } - if (outBufP != OUTBUF) { - free(outBufP); - } + if (inBufP != INBUF) { free(inBufP); } + if (outBufP != OUTBUF) { free(outBufP); } + return ckDataLength; } #endif diff --git a/src/share/native/sun/security/pkcs11/wrapper/p11_util.c b/src/share/native/sun/security/pkcs11/wrapper/p11_util.c index 2276cb101c527f8de8537a43e57ccffdc9f4237d..d4c12a06baadfaf996a8d6efade62722e9a561ae 100644 --- a/src/share/native/sun/security/pkcs11/wrapper/p11_util.c +++ b/src/share/native/sun/security/pkcs11/wrapper/p11_util.c @@ -1,5 +1,5 @@ /* - * Portions Copyright 2003 Sun Microsystems, Inc. All Rights Reserved. + * Portions Copyright 2003-2009 Sun Microsystems, Inc. All Rights Reserved. */ /* Copyright (c) 2002 Graz University of Technology. All rights reserved. @@ -73,11 +73,11 @@ jobject createLockObject(JNIEnv *env) { jmethodID jConstructor; jObjectClass = (*env)->FindClass(env, "java/lang/Object"); - assert(jObjectClass != 0); + if (jObjectClass == NULL) { return NULL; } jConstructor = (*env)->GetMethodID(env, jObjectClass, "<init>", "()V"); - assert(jConstructor != 0); + if (jConstructor == NULL) { return NULL; } jLockObject = (*env)->NewObject(env, jObjectClass, jConstructor); - assert(jLockObject != 0); + if (jLockObject == NULL) { return NULL; } jLockObject = (*env)->NewGlobalRef(env, jLockObject); return jLockObject ; @@ -200,84 +200,30 @@ jlong ckAssertReturnValueOK(JNIEnv *env, CK_RV returnValue) return 0L ; } else { jPKCS11ExceptionClass = (*env)->FindClass(env, CLASS_PKCS11EXCEPTION); - assert(jPKCS11ExceptionClass != 0); - jConstructor = (*env)->GetMethodID(env, jPKCS11ExceptionClass, "<init>", "(J)V"); - assert(jConstructor != 0); - jErrorCode = ckULongToJLong(returnValue); - jPKCS11Exception = (jthrowable) (*env)->NewObject(env, jPKCS11ExceptionClass, jConstructor, jErrorCode); - (*env)->Throw(env, jPKCS11Exception); + if (jPKCS11ExceptionClass != NULL) { + jConstructor = (*env)->GetMethodID(env, jPKCS11ExceptionClass, "<init>", "(J)V"); + if (jConstructor != NULL) { + jErrorCode = ckULongToJLong(returnValue); + jPKCS11Exception = (jthrowable) (*env)->NewObject(env, jPKCS11ExceptionClass, jConstructor, jErrorCode); + if (jPKCS11Exception != NULL) { + (*env)->Throw(env, jPKCS11Exception); + } + } + } + (*env)->DeleteLocalRef(env, jPKCS11ExceptionClass); return jErrorCode ; } } /* - * this function simply throws a FileNotFoundException - * - * @param env Used to call JNI funktions and to get the Exception class. - * @param jmessage The message string of the Exception object. - */ -void throwFileNotFoundException(JNIEnv *env, jstring jmessage) -{ - jclass jFileNotFoundExceptionClass; - jmethodID jConstructor; - jthrowable jFileNotFoundException; - - jFileNotFoundExceptionClass = (*env)->FindClass(env, CLASS_FILE_NOT_FOUND_EXCEPTION); - assert(jFileNotFoundExceptionClass != 0); - - jConstructor = (*env)->GetMethodID(env, jFileNotFoundExceptionClass, "<init>", "(Ljava/lang/String;)V"); - assert(jConstructor != 0); - jFileNotFoundException = (jthrowable) (*env)->NewObject(env, jFileNotFoundExceptionClass, jConstructor, jmessage); - (*env)->Throw(env, jFileNotFoundException); -} - -/* - * this function simply throws an IOException + * This function simply throws an IOException * * @param env Used to call JNI funktions and to get the Exception class. * @param message The message string of the Exception object. */ -void throwIOException(JNIEnv *env, const char * message) +void throwIOException(JNIEnv *env, const char *message) { - jclass jIOExceptionClass; - - jIOExceptionClass = (*env)->FindClass(env, CLASS_IO_EXCEPTION); - assert(jIOExceptionClass != 0); - - (*env)->ThrowNew(env, jIOExceptionClass, message); -} - -/* - * this function simply throws an IOException and takes a unicode - * messge. - * - * @param env Used to call JNI funktions and to get the Exception class. - * @param message The unicode message string of the Exception object. - */ -void throwIOExceptionUnicodeMessage(JNIEnv *env, const short *message) -{ - jclass jIOExceptionClass; - jmethodID jConstructor; - jthrowable jIOException; - jstring jmessage; - jsize length; - short *currentCharacter; - - jIOExceptionClass = (*env)->FindClass(env, CLASS_IO_EXCEPTION); - assert(jIOExceptionClass != 0); - - length = 0; - if (message != NULL) { - currentCharacter = (short *) message; - while (*(currentCharacter++) != 0) length++; - } - - jmessage = (*env)->NewString(env, (const jchar *)message, length); - - jConstructor = (*env)->GetMethodID(env, jIOExceptionClass, "<init>", "(Ljava/lang/String;)V"); - assert(jConstructor != 0); - jIOException = (jthrowable) (*env)->NewObject(env, jIOExceptionClass, jConstructor, jmessage); - (*env)->Throw(env, jIOException); + JNU_ThrowByName(env, CLASS_IO_EXCEPTION, message); } /* @@ -288,26 +234,9 @@ void throwIOExceptionUnicodeMessage(JNIEnv *env, const short *message) * @param env Used to call JNI funktions and to get the Exception class. * @param jmessage The message string of the Exception object. */ -void throwPKCS11RuntimeException(JNIEnv *env, jstring jmessage) +void throwPKCS11RuntimeException(JNIEnv *env, const char *message) { - jclass jPKCS11RuntimeExceptionClass; - jmethodID jConstructor; - jthrowable jPKCS11RuntimeException; - - jPKCS11RuntimeExceptionClass = (*env)->FindClass(env, CLASS_PKCS11RUNTIMEEXCEPTION); - assert(jPKCS11RuntimeExceptionClass != 0); - - if (jmessage == NULL) { - jConstructor = (*env)->GetMethodID(env, jPKCS11RuntimeExceptionClass, "<init>", "()V"); - assert(jConstructor != 0); - jPKCS11RuntimeException = (jthrowable) (*env)->NewObject(env, jPKCS11RuntimeExceptionClass, jConstructor); - (*env)->Throw(env, jPKCS11RuntimeException); - } else { - jConstructor = (*env)->GetMethodID(env, jPKCS11RuntimeExceptionClass, "<init>", "(Ljava/lang/String;)V"); - assert(jConstructor != 0); - jPKCS11RuntimeException = (jthrowable) (*env)->NewObject(env, jPKCS11RuntimeExceptionClass, jConstructor, jmessage); - (*env)->Throw(env, jPKCS11RuntimeException); - } + JNU_ThrowByName(env, CLASS_PKCS11RUNTIMEEXCEPTION, message); } /* @@ -318,9 +247,24 @@ void throwPKCS11RuntimeException(JNIEnv *env, jstring jmessage) */ void throwDisconnectedRuntimeException(JNIEnv *env) { - jstring jExceptionMessage = (*env)->NewStringUTF(env, "This object is not connected to a module."); + throwPKCS11RuntimeException(env, "This object is not connected to a module."); +} - throwPKCS11RuntimeException(env, jExceptionMessage); +/* This function frees the specified CK_ATTRIBUTE array. + * + * @param attrPtr pointer to the to-be-freed CK_ATTRIBUTE array. + * @param len the length of the array + */ +void freeCKAttributeArray(CK_ATTRIBUTE_PTR attrPtr, int len) +{ + int i; + + for (i=0; i<len; i++) { + if (attrPtr[i].pValue != NULL_PTR) { + free(attrPtr[i].pValue); + } + } + free(attrPtr); } /* @@ -375,8 +319,22 @@ void jBooleanArrayToCKBBoolArray(JNIEnv *env, const jbooleanArray jArray, CK_BBO } *ckpLength = (*env)->GetArrayLength(env, jArray); jpTemp = (jboolean*) malloc((*ckpLength) * sizeof(jboolean)); + if (jpTemp == NULL) { + JNU_ThrowOutOfMemoryError(env, 0); + return; + } (*env)->GetBooleanArrayRegion(env, jArray, 0, *ckpLength, jpTemp); + if ((*env)->ExceptionCheck(env)) { + free(jpTemp); + return; + } + *ckpArray = (CK_BBOOL*) malloc ((*ckpLength) * sizeof(CK_BBOOL)); + if (*ckpArray == NULL) { + free(jpTemp); + JNU_ThrowOutOfMemoryError(env, 0); + return; + } for (i=0; i<(*ckpLength); i++) { (*ckpArray)[i] = jBooleanToCKBBool(jpTemp[i]); } @@ -403,13 +361,26 @@ void jByteArrayToCKByteArray(JNIEnv *env, const jbyteArray jArray, CK_BYTE_PTR * } *ckpLength = (*env)->GetArrayLength(env, jArray); jpTemp = (jbyte*) malloc((*ckpLength) * sizeof(jbyte)); + if (jpTemp == NULL) { + JNU_ThrowOutOfMemoryError(env, 0); + return; + } (*env)->GetByteArrayRegion(env, jArray, 0, *ckpLength, jpTemp); + if ((*env)->ExceptionCheck(env)) { + free(jpTemp); + return; + } /* if CK_BYTE is the same size as jbyte, we save an additional copy */ if (sizeof(CK_BYTE) == sizeof(jbyte)) { *ckpArray = (CK_BYTE_PTR) jpTemp; } else { *ckpArray = (CK_BYTE_PTR) malloc ((*ckpLength) * sizeof(CK_BYTE)); + if (*ckpArray == NULL) { + free(jpTemp); + JNU_ThrowOutOfMemoryError(env, 0); + return; + } for (i=0; i<(*ckpLength); i++) { (*ckpArray)[i] = jByteToCKByte(jpTemp[i]); } @@ -437,8 +408,22 @@ void jLongArrayToCKULongArray(JNIEnv *env, const jlongArray jArray, CK_ULONG_PTR } *ckpLength = (*env)->GetArrayLength(env, jArray); jTemp = (jlong*) malloc((*ckpLength) * sizeof(jlong)); + if (jTemp == NULL) { + JNU_ThrowOutOfMemoryError(env, 0); + return; + } (*env)->GetLongArrayRegion(env, jArray, 0, *ckpLength, jTemp); + if ((*env)->ExceptionCheck(env)) { + free(jTemp); + return; + } + *ckpArray = (CK_ULONG_PTR) malloc (*ckpLength * sizeof(CK_ULONG)); + if (*ckpArray == NULL) { + free(jTemp); + JNU_ThrowOutOfMemoryError(env, 0); + return; + } for (i=0; i<(*ckpLength); i++) { (*ckpArray)[i] = jLongToCKULong(jTemp[i]); } @@ -465,8 +450,22 @@ void jCharArrayToCKCharArray(JNIEnv *env, const jcharArray jArray, CK_CHAR_PTR * } *ckpLength = (*env)->GetArrayLength(env, jArray); jpTemp = (jchar*) malloc((*ckpLength) * sizeof(jchar)); + if (jpTemp == NULL) { + JNU_ThrowOutOfMemoryError(env, 0); + return; + } (*env)->GetCharArrayRegion(env, jArray, 0, *ckpLength, jpTemp); + if ((*env)->ExceptionCheck(env)) { + free(jpTemp); + return; + } + *ckpArray = (CK_CHAR_PTR) malloc (*ckpLength * sizeof(CK_CHAR)); + if (*ckpArray == NULL) { + free(jpTemp); + JNU_ThrowOutOfMemoryError(env, 0); + return; + } for (i=0; i<(*ckpLength); i++) { (*ckpArray)[i] = jCharToCKChar(jpTemp[i]); } @@ -493,8 +492,22 @@ void jCharArrayToCKUTF8CharArray(JNIEnv *env, const jcharArray jArray, CK_UTF8CH } *ckpLength = (*env)->GetArrayLength(env, jArray); jTemp = (jchar*) malloc((*ckpLength) * sizeof(jchar)); + if (jTemp == NULL) { + JNU_ThrowOutOfMemoryError(env, 0); + return; + } (*env)->GetCharArrayRegion(env, jArray, 0, *ckpLength, jTemp); + if ((*env)->ExceptionCheck(env)) { + free(jTemp); + return; + } + *ckpArray = (CK_UTF8CHAR_PTR) malloc (*ckpLength * sizeof(CK_UTF8CHAR)); + if (*ckpArray == NULL) { + free(jTemp); + JNU_ThrowOutOfMemoryError(env, 0); + return; + } for (i=0; i<(*ckpLength); i++) { (*ckpArray)[i] = jCharToCKUTF8Char(jTemp[i]); } @@ -521,8 +534,15 @@ void jStringToCKUTF8CharArray(JNIEnv *env, const jstring jArray, CK_UTF8CHAR_PTR } pCharArray = (*env)->GetStringUTFChars(env, jArray, &isCopy); + if (pCharArray == NULL) { return; } + *ckpLength = strlen(pCharArray); *ckpArray = (CK_UTF8CHAR_PTR) malloc((*ckpLength + 1) * sizeof(CK_UTF8CHAR)); + if (*ckpArray == NULL) { + (*env)->ReleaseStringUTFChars(env, (jstring) jArray, pCharArray); + JNU_ThrowOutOfMemoryError(env, 0); + return; + } strcpy((char*)*ckpArray, pCharArray); (*env)->ReleaseStringUTFChars(env, (jstring) jArray, pCharArray); } @@ -552,55 +572,36 @@ void jAttributeArrayToCKAttributeArray(JNIEnv *env, jobjectArray jArray, CK_ATTR jLength = (*env)->GetArrayLength(env, jArray); *ckpLength = jLongToCKULong(jLength); *ckpArray = (CK_ATTRIBUTE_PTR) malloc(*ckpLength * sizeof(CK_ATTRIBUTE)); + if (*ckpArray == NULL) { + JNU_ThrowOutOfMemoryError(env, 0); + return; + } TRACE1(", converting %d attibutes", jLength); for (i=0; i<(*ckpLength); i++) { TRACE1(", getting %d. attibute", i); jAttribute = (*env)->GetObjectArrayElement(env, jArray, i); + if ((*env)->ExceptionCheck(env)) { + freeCKAttributeArray(*ckpArray, i); + return; + } TRACE1(", jAttribute = %d", jAttribute); TRACE1(", converting %d. attibute", i); (*ckpArray)[i] = jAttributeToCKAttribute(env, jAttribute); + if ((*env)->ExceptionCheck(env)) { + freeCKAttributeArray(*ckpArray, i); + return; + } } TRACE0("FINISHED\n"); } -/* - * converts a jobjectArray to a CK_VOID_PTR array. The allocated memory has to be freed after - * use! - * NOTE: this function does not work and is not used yet - * - * @param env - used to call JNI funktions to get the array informtaion - * @param jArray - the Java object array to convert - * @param ckpArray - the reference, where the pointer to the new CK_VOID_PTR array will be stored - * @param ckpLength - the reference, where the array length will be stored - */ -/* -void jObjectArrayToCKVoidPtrArray(JNIEnv *env, const jobjectArray jArray, CK_VOID_PTR_PTR *ckpArray, CK_ULONG_PTR ckpLength) -{ - jobject jTemp; - CK_ULONG i; - - if(jArray == NULL) { - *ckpArray = NULL_PTR; - *ckpLength = 0L; - return; - } - *ckpLength = (*env)->GetArrayLength(env, jArray); - *ckpArray = (CK_VOID_PTR_PTR) malloc (*ckpLength * sizeof(CK_VOID_PTR)); - for (i=0; i<(*ckpLength); i++) { - jTemp = (*env)->GetObjectArrayElement(env, jArray, i); - (*ckpArray)[i] = jObjectToCKVoidPtr(jTemp); - } - free(jTemp); -} -*/ - /* * converts a CK_BYTE array and its length to a jbyteArray. * * @param env - used to call JNI funktions to create the new Java array * @param ckpArray - the pointer to the CK_BYTE array to convert * @param ckpLength - the length of the array to convert - * @return - the new Java byte array + * @return - the new Java byte array or NULL if error occurred */ jbyteArray ckByteArrayToJByteArray(JNIEnv *env, const CK_BYTE_PTR ckpArray, CK_ULONG ckLength) { @@ -613,18 +614,22 @@ jbyteArray ckByteArrayToJByteArray(JNIEnv *env, const CK_BYTE_PTR ckpArray, CK_U jpTemp = (jbyte*) ckpArray; } else { jpTemp = (jbyte*) malloc((ckLength) * sizeof(jbyte)); + if (jpTemp == NULL) { + JNU_ThrowOutOfMemoryError(env, 0); + return NULL; + } for (i=0; i<ckLength; i++) { jpTemp[i] = ckByteToJByte(ckpArray[i]); } } jArray = (*env)->NewByteArray(env, ckULongToJSize(ckLength)); - (*env)->SetByteArrayRegion(env, jArray, 0, ckULongToJSize(ckLength), jpTemp); - - if (sizeof(CK_BYTE) != sizeof(jbyte)) { - free(jpTemp); + if (jArray != NULL) { + (*env)->SetByteArrayRegion(env, jArray, 0, ckULongToJSize(ckLength), jpTemp); } + if (sizeof(CK_BYTE) != sizeof(jbyte)) { free(jpTemp); } + return jArray ; } @@ -643,11 +648,17 @@ jlongArray ckULongArrayToJLongArray(JNIEnv *env, const CK_ULONG_PTR ckpArray, CK jlongArray jArray; jpTemp = (jlong*) malloc((ckLength) * sizeof(jlong)); + if (jpTemp == NULL) { + JNU_ThrowOutOfMemoryError(env, 0); + return NULL; + } for (i=0; i<ckLength; i++) { jpTemp[i] = ckLongToJLong(ckpArray[i]); } jArray = (*env)->NewLongArray(env, ckULongToJSize(ckLength)); - (*env)->SetLongArrayRegion(env, jArray, 0, ckULongToJSize(ckLength), jpTemp); + if (jArray != NULL) { + (*env)->SetLongArrayRegion(env, jArray, 0, ckULongToJSize(ckLength), jpTemp); + } free(jpTemp); return jArray ; @@ -668,11 +679,17 @@ jcharArray ckCharArrayToJCharArray(JNIEnv *env, const CK_CHAR_PTR ckpArray, CK_U jcharArray jArray; jpTemp = (jchar*) malloc(ckLength * sizeof(jchar)); + if (jpTemp == NULL) { + JNU_ThrowOutOfMemoryError(env, 0); + return NULL; + } for (i=0; i<ckLength; i++) { jpTemp[i] = ckCharToJChar(ckpArray[i]); } jArray = (*env)->NewCharArray(env, ckULongToJSize(ckLength)); - (*env)->SetCharArrayRegion(env, jArray, 0, ckULongToJSize(ckLength), jpTemp); + if (jArray != NULL) { + (*env)->SetCharArrayRegion(env, jArray, 0, ckULongToJSize(ckLength), jpTemp); + } free(jpTemp); return jArray ; @@ -693,11 +710,17 @@ jcharArray ckUTF8CharArrayToJCharArray(JNIEnv *env, const CK_UTF8CHAR_PTR ckpArr jcharArray jArray; jpTemp = (jchar*) malloc(ckLength * sizeof(jchar)); + if (jpTemp == NULL) { + JNU_ThrowOutOfMemoryError(env, 0); + return NULL; + } for (i=0; i<ckLength; i++) { jpTemp[i] = ckUTF8CharToJChar(ckpArray[i]); } jArray = (*env)->NewCharArray(env, ckULongToJSize(ckLength)); - (*env)->SetCharArrayRegion(env, jArray, 0, ckULongToJSize(ckLength), jpTemp); + if (jArray != NULL) { + (*env)->SetCharArrayRegion(env, jArray, 0, ckULongToJSize(ckLength), jpTemp); + } free(jpTemp); return jArray ; @@ -736,12 +759,11 @@ jobject ckBBoolPtrToJBooleanObject(JNIEnv *env, const CK_BBOOL *ckpValue) jboolean jValue; jValueObjectClass = (*env)->FindClass(env, "java/lang/Boolean"); - assert(jValueObjectClass != 0); + if (jValueObjectClass == NULL) { return NULL; } jConstructor = (*env)->GetMethodID(env, jValueObjectClass, "<init>", "(Z)V"); - assert(jConstructor != 0); + if (jConstructor == NULL) { return NULL; } jValue = ckBBoolToJBoolean(*ckpValue); jValueObject = (*env)->NewObject(env, jValueObjectClass, jConstructor, jValue); - assert(jValueObject != 0); return jValueObject ; } @@ -761,12 +783,11 @@ jobject ckULongPtrToJLongObject(JNIEnv *env, const CK_ULONG_PTR ckpValue) jlong jValue; jValueObjectClass = (*env)->FindClass(env, "java/lang/Long"); - assert(jValueObjectClass != 0); + if (jValueObjectClass == NULL) { return NULL; } jConstructor = (*env)->GetMethodID(env, jValueObjectClass, "<init>", "(J)V"); - assert(jConstructor != 0); + if (jConstructor == NULL) { return NULL; } jValue = ckULongToJLong(*ckpValue); jValueObject = (*env)->NewObject(env, jValueObjectClass, jConstructor, jValue); - assert(jValueObject != 0); return jValueObject ; } @@ -787,11 +808,15 @@ CK_BBOOL* jBooleanObjectToCKBBoolPtr(JNIEnv *env, jobject jObject) CK_BBOOL *ckpValue; jObjectClass = (*env)->FindClass(env, "java/lang/Boolean"); - assert(jObjectClass != 0); + if (jObjectClass == NULL) { return NULL; } jValueMethod = (*env)->GetMethodID(env, jObjectClass, "booleanValue", "()Z"); - assert(jValueMethod != 0); + if (jValueMethod == NULL) { return NULL; } jValue = (*env)->CallBooleanMethod(env, jObject, jValueMethod); ckpValue = (CK_BBOOL *) malloc(sizeof(CK_BBOOL)); + if (ckpValue == NULL) { + JNU_ThrowOutOfMemoryError(env, 0); + return NULL; + } *ckpValue = jBooleanToCKBBool(jValue); return ckpValue ; @@ -813,13 +838,16 @@ CK_BYTE_PTR jByteObjectToCKBytePtr(JNIEnv *env, jobject jObject) CK_BYTE_PTR ckpValue; jObjectClass = (*env)->FindClass(env, "java/lang/Byte"); - assert(jObjectClass != 0); + if (jObjectClass == NULL) { return NULL; } jValueMethod = (*env)->GetMethodID(env, jObjectClass, "byteValue", "()B"); - assert(jValueMethod != 0); + if (jValueMethod == NULL) { return NULL; } jValue = (*env)->CallByteMethod(env, jObject, jValueMethod); ckpValue = (CK_BYTE_PTR) malloc(sizeof(CK_BYTE)); + if (ckpValue == NULL) { + JNU_ThrowOutOfMemoryError(env, 0); + return NULL; + } *ckpValue = jByteToCKByte(jValue); - return ckpValue ; } @@ -839,13 +867,16 @@ CK_ULONG* jIntegerObjectToCKULongPtr(JNIEnv *env, jobject jObject) CK_ULONG *ckpValue; jObjectClass = (*env)->FindClass(env, "java/lang/Integer"); - assert(jObjectClass != 0); + if (jObjectClass == NULL) { return NULL; } jValueMethod = (*env)->GetMethodID(env, jObjectClass, "intValue", "()I"); - assert(jValueMethod != 0); + if (jValueMethod == NULL) { return NULL; } jValue = (*env)->CallIntMethod(env, jObject, jValueMethod); ckpValue = (CK_ULONG *) malloc(sizeof(CK_ULONG)); + if (ckpValue == NULL) { + JNU_ThrowOutOfMemoryError(env, 0); + return NULL; + } *ckpValue = jLongToCKLong(jValue); - return ckpValue ; } @@ -865,11 +896,15 @@ CK_ULONG* jLongObjectToCKULongPtr(JNIEnv *env, jobject jObject) CK_ULONG *ckpValue; jObjectClass = (*env)->FindClass(env, "java/lang/Long"); - assert(jObjectClass != 0); + if (jObjectClass == NULL) { return NULL; } jValueMethod = (*env)->GetMethodID(env, jObjectClass, "longValue", "()J"); - assert(jValueMethod != 0); + if (jValueMethod == NULL) { return NULL; } jValue = (*env)->CallLongMethod(env, jObject, jValueMethod); ckpValue = (CK_ULONG *) malloc(sizeof(CK_ULONG)); + if (ckpValue == NULL) { + JNU_ThrowOutOfMemoryError(env, 0); + return NULL; + } *ckpValue = jLongToCKULong(jValue); return ckpValue ; @@ -891,11 +926,15 @@ CK_CHAR_PTR jCharObjectToCKCharPtr(JNIEnv *env, jobject jObject) CK_CHAR_PTR ckpValue; jObjectClass = (*env)->FindClass(env, "java/lang/Char"); - assert(jObjectClass != 0); + if (jObjectClass == NULL) { return NULL; } jValueMethod = (*env)->GetMethodID(env, jObjectClass, "charValue", "()C"); - assert(jValueMethod != 0); + if (jValueMethod == NULL) { return NULL; } jValue = (*env)->CallCharMethod(env, jObject, jValueMethod); ckpValue = (CK_CHAR_PTR) malloc(sizeof(CK_CHAR)); + if (ckpValue == NULL) { + JNU_ThrowOutOfMemoryError(env, 0); + return NULL; + } *ckpValue = jCharToCKChar(jValue); return ckpValue ; @@ -913,124 +952,172 @@ CK_CHAR_PTR jCharObjectToCKCharPtr(JNIEnv *env, jobject jObject) */ void jObjectToPrimitiveCKObjectPtrPtr(JNIEnv *env, jobject jObject, CK_VOID_PTR *ckpObjectPtr, CK_ULONG *ckpLength) { - jclass jBooleanClass = (*env)->FindClass(env, "java/lang/Boolean"); - jclass jByteClass = (*env)->FindClass(env, "java/lang/Byte"); - jclass jCharacterClass = (*env)->FindClass(env, "java/lang/Character"); - jclass jClassClass = (*env)->FindClass(env, "java/lang/Class"); - /* jclass jShortClass = (*env)->FindClass(env, "java/lang/Short"); */ - jclass jIntegerClass = (*env)->FindClass(env, "java/lang/Integer"); - jclass jLongClass = (*env)->FindClass(env, "java/lang/Long"); - /* jclass jFloatClass = (*env)->FindClass(env, "java/lang/Float"); */ - /* jclass jDoubleClass = (*env)->FindClass(env, "java/lang/Double"); */ - jclass jDateClass = (*env)->FindClass(env, CLASS_DATE); - jclass jStringClass = (*env)->FindClass(env, "java/lang/String"); - jclass jStringBufferClass = (*env)->FindClass(env, "java/lang/StringBuffer"); - jclass jBooleanArrayClass = (*env)->FindClass(env, "[Z"); - jclass jByteArrayClass = (*env)->FindClass(env, "[B"); - jclass jCharArrayClass = (*env)->FindClass(env, "[C"); - /* jclass jShortArrayClass = (*env)->FindClass(env, "[S"); */ - jclass jIntArrayClass = (*env)->FindClass(env, "[I"); - jclass jLongArrayClass = (*env)->FindClass(env, "[J"); - /* jclass jFloatArrayClass = (*env)->FindClass(env, "[F"); */ - /* jclass jDoubleArrayClass = (*env)->FindClass(env, "[D"); */ - jclass jObjectClass = (*env)->FindClass(env, "java/lang/Object"); - /* jclass jObjectArrayClass = (*env)->FindClass(env, "[java/lang/Object"); */ - /* ATTENTION: jObjectArrayClass is always NULL !! */ - /* CK_ULONG ckArrayLength; */ - /* CK_VOID_PTR *ckpElementObject; */ - /* CK_ULONG ckElementLength; */ - /* CK_ULONG i; */ + jclass jLongClass, jBooleanClass, jByteArrayClass, jCharArrayClass; + jclass jByteClass, jDateClass, jCharacterClass, jIntegerClass; + jclass jBooleanArrayClass, jIntArrayClass, jLongArrayClass; + jclass jStringClass; + jclass jObjectClass, jClassClass; CK_VOID_PTR ckpVoid = *ckpObjectPtr; jmethodID jMethod; jobject jClassObject; jstring jClassNameString; - jstring jExceptionMessagePrefix; - jobject jExceptionMessageStringBuffer; - jstring jExceptionMessage; + char *classNameString, *exceptionMsgPrefix, *exceptionMsg; TRACE0("\nDEBUG: jObjectToPrimitiveCKObjectPtrPtr"); if (jObject == NULL) { *ckpObjectPtr = NULL; *ckpLength = 0; - } else if ((*env)->IsInstanceOf(env, jObject, jLongClass)) { + return; + } + + jLongClass = (*env)->FindClass(env, "java/lang/Long"); + if (jLongClass == NULL) { return; } + if ((*env)->IsInstanceOf(env, jObject, jLongClass)) { *ckpObjectPtr = jLongObjectToCKULongPtr(env, jObject); *ckpLength = sizeof(CK_ULONG); TRACE1("<converted long value %X>", *((CK_ULONG *) *ckpObjectPtr)); - } else if ((*env)->IsInstanceOf(env, jObject, jBooleanClass)) { + return; + } + + jBooleanClass = (*env)->FindClass(env, "java/lang/Boolean"); + if (jBooleanClass == NULL) { return; } + if ((*env)->IsInstanceOf(env, jObject, jBooleanClass)) { *ckpObjectPtr = jBooleanObjectToCKBBoolPtr(env, jObject); *ckpLength = sizeof(CK_BBOOL); TRACE0(" <converted boolean value "); TRACE0((*((CK_BBOOL *) *ckpObjectPtr) == TRUE) ? "TRUE>" : "FALSE>"); - } else if ((*env)->IsInstanceOf(env, jObject, jByteArrayClass)) { + return; + } + + jByteArrayClass = (*env)->FindClass(env, "[B"); + if (jByteArrayClass == NULL) { return; } + if ((*env)->IsInstanceOf(env, jObject, jByteArrayClass)) { jByteArrayToCKByteArray(env, jObject, (CK_BYTE_PTR*)ckpObjectPtr, ckpLength); - } else if ((*env)->IsInstanceOf(env, jObject, jCharArrayClass)) { + return; + } + + jCharArrayClass = (*env)->FindClass(env, "[C"); + if (jCharArrayClass == NULL) { return; } + if ((*env)->IsInstanceOf(env, jObject, jCharArrayClass)) { jCharArrayToCKUTF8CharArray(env, jObject, (CK_UTF8CHAR_PTR*)ckpObjectPtr, ckpLength); - } else if ((*env)->IsInstanceOf(env, jObject, jByteClass)) { + return; + } + + jByteClass = (*env)->FindClass(env, "java/lang/Byte"); + if (jByteClass == NULL) { return; } + if ((*env)->IsInstanceOf(env, jObject, jByteClass)) { *ckpObjectPtr = jByteObjectToCKBytePtr(env, jObject); *ckpLength = sizeof(CK_BYTE); TRACE1("<converted byte value %X>", *((CK_BYTE *) *ckpObjectPtr)); - } else if ((*env)->IsInstanceOf(env, jObject, jDateClass)) { + return; + } + + jDateClass = (*env)->FindClass(env, CLASS_DATE); + if (jDateClass == NULL) { return; } + if ((*env)->IsInstanceOf(env, jObject, jDateClass)) { *ckpObjectPtr = jDateObjectPtrToCKDatePtr(env, jObject); *ckpLength = sizeof(CK_DATE); - TRACE3("<converted date value %.4s-%.2s-%.2s>", (*((CK_DATE *) *ckpObjectPtr)).year, - (*((CK_DATE *) *ckpObjectPtr)).month, - (*((CK_DATE *) *ckpObjectPtr)).day); - } else if ((*env)->IsInstanceOf(env, jObject, jCharacterClass)) { + TRACE3("<converted date value %.4s-%.2s-%.2s>", (*((CK_DATE *) *ckpObjectPtr)).year, (*((CK_DATE *) *ckpObjectPtr)).month, (*((CK_DATE *) *ckpObjectPtr)).day); + return; + } + + jCharacterClass = (*env)->FindClass(env, "java/lang/Character"); + if (jCharacterClass == NULL) { return; } + if ((*env)->IsInstanceOf(env, jObject, jCharacterClass)) { *ckpObjectPtr = jCharObjectToCKCharPtr(env, jObject); *ckpLength = sizeof(CK_UTF8CHAR); TRACE1("<converted char value %c>", *((CK_CHAR *) *ckpObjectPtr)); - } else if ((*env)->IsInstanceOf(env, jObject, jIntegerClass)) { + return; + } + + jIntegerClass = (*env)->FindClass(env, "java/lang/Integer"); + if (jIntegerClass == NULL) { return; } + if ((*env)->IsInstanceOf(env, jObject, jIntegerClass)) { *ckpObjectPtr = jIntegerObjectToCKULongPtr(env, jObject); *ckpLength = sizeof(CK_ULONG); TRACE1("<converted integer value %X>", *((CK_ULONG *) *ckpObjectPtr)); - } else if ((*env)->IsInstanceOf(env, jObject, jBooleanArrayClass)) { + return; + } + + jBooleanArrayClass = (*env)->FindClass(env, "[Z"); + if (jBooleanArrayClass == NULL) { return; } + if ((*env)->IsInstanceOf(env, jObject, jBooleanArrayClass)) { jBooleanArrayToCKBBoolArray(env, jObject, (CK_BBOOL**)ckpObjectPtr, ckpLength); - } else if ((*env)->IsInstanceOf(env, jObject, jIntArrayClass)) { + return; + } + + jIntArrayClass = (*env)->FindClass(env, "[I"); + if (jIntArrayClass == NULL) { return; } + if ((*env)->IsInstanceOf(env, jObject, jIntArrayClass)) { jLongArrayToCKULongArray(env, jObject, (CK_ULONG_PTR*)ckpObjectPtr, ckpLength); - } else if ((*env)->IsInstanceOf(env, jObject, jLongArrayClass)) { + return; + } + + jLongArrayClass = (*env)->FindClass(env, "[J"); + if (jLongArrayClass == NULL) { return; } + if ((*env)->IsInstanceOf(env, jObject, jLongArrayClass)) { jLongArrayToCKULongArray(env, jObject, (CK_ULONG_PTR*)ckpObjectPtr, ckpLength); - } else if ((*env)->IsInstanceOf(env, jObject, jStringClass)) { - jStringToCKUTF8CharArray(env, jObject, (CK_UTF8CHAR_PTR*)ckpObjectPtr, ckpLength); + return; + } - /* a Java object array is not used by CK_ATTRIBUTE by now... */ -/* } else if ((*env)->IsInstanceOf(env, jObject, jObjectArrayClass)) { - ckArrayLength = (*env)->GetArrayLength(env, (jarray) jObject); - ckpObjectPtr = (CK_VOID_PTR_PTR) malloc(sizeof(CK_VOID_PTR) * ckArrayLength); - *ckpLength = 0; - for (i = 0; i < ckArrayLength; i++) { - jObjectToPrimitiveCKObjectPtrPtr(env, (*env)->GetObjectArrayElement(env, (jarray) jObject, i), - ckpElementObject, &ckElementLength); - (*ckpObjectPtr)[i] = *ckpElementObject; - *ckpLength += ckElementLength; - } -*/ - } else { - /* type of jObject unknown, throw PKCS11RuntimeException */ - jMethod = (*env)->GetMethodID(env, jObjectClass, "getClass", "()Ljava/lang/Class;"); - assert(jMethod != 0); - jClassObject = (*env)->CallObjectMethod(env, jObject, jMethod); - assert(jClassObject != 0); - jMethod = (*env)->GetMethodID(env, jClassClass, "getName", "()Ljava/lang/String;"); - assert(jMethod != 0); - jClassNameString = (jstring) - (*env)->CallObjectMethod(env, jClassObject, jMethod); - assert(jClassNameString != 0); - jExceptionMessagePrefix = (*env)->NewStringUTF(env, "Java object of this class cannot be converted to native PKCS#11 type: "); - jMethod = (*env)->GetMethodID(env, jStringBufferClass, "<init>", "(Ljava/lang/String;)V"); - assert(jMethod != 0); - jExceptionMessageStringBuffer = (*env)->NewObject(env, jStringBufferClass, jMethod, jExceptionMessagePrefix); - assert(jClassNameString != 0); - jMethod = (*env)->GetMethodID(env, jStringBufferClass, "append", "(Ljava/lang/String;)Ljava/lang/StringBuffer;"); - assert(jMethod != 0); - jExceptionMessage = (jstring) - (*env)->CallObjectMethod(env, jExceptionMessageStringBuffer, jMethod, jClassNameString); - assert(jExceptionMessage != 0); - - throwPKCS11RuntimeException(env, jExceptionMessage); + jStringClass = (*env)->FindClass(env, "java/lang/String"); + if (jStringClass == NULL) { return; } + if ((*env)->IsInstanceOf(env, jObject, jStringClass)) { + jStringToCKUTF8CharArray(env, jObject, (CK_UTF8CHAR_PTR*)ckpObjectPtr, ckpLength); + return; + } - *ckpObjectPtr = NULL; - *ckpLength = 0; + /* type of jObject unknown, throw PKCS11RuntimeException */ + jObjectClass = (*env)->FindClass(env, "java/lang/Object"); + if (jObjectClass == NULL) { return; } + jMethod = (*env)->GetMethodID(env, jObjectClass, "getClass", "()Ljava/lang/Class;"); + if (jMethod == NULL) { return; } + jClassObject = (*env)->CallObjectMethod(env, jObject, jMethod); + assert(jClassObject != 0); + jClassClass = (*env)->FindClass(env, "java/lang/Class"); + if (jClassClass == NULL) { return; } + jMethod = (*env)->GetMethodID(env, jClassClass, "getName", "()Ljava/lang/String;"); + if (jMethod == NULL) { return; } + jClassNameString = (jstring) + (*env)->CallObjectMethod(env, jClassObject, jMethod); + assert(jClassNameString != 0); + classNameString = (char*) + (*env)->GetStringUTFChars(env, jClassNameString, NULL); + if (classNameString == NULL) { return; } + exceptionMsgPrefix = "Java object of this class cannot be converted to native PKCS#11 type: "; + exceptionMsg = (char *) + malloc((strlen(exceptionMsgPrefix) + strlen(classNameString) + 1)); + if (exceptionMsg == NULL) { + (*env)->ReleaseStringUTFChars(env, jClassNameString, classNameString); + JNU_ThrowOutOfMemoryError(env, 0); + return; } + strcpy(exceptionMsg, exceptionMsgPrefix); + strcat(exceptionMsg, classNameString); + (*env)->ReleaseStringUTFChars(env, jClassNameString, classNameString); + throwPKCS11RuntimeException(env, exceptionMsg); + free(exceptionMsg); + *ckpObjectPtr = NULL; + *ckpLength = 0; TRACE0("FINISHED\n"); } + +#ifdef P11_MEMORYDEBUG + +#undef malloc +#undef free + +void *p11malloc(size_t c, char *file, int line) { + void *p = malloc(c); + printf("malloc\t%08x\t%d\t%s:%d\n", p, c, file, line); fflush(stdout); + return p; +} + +void p11free(void *p, char *file, int line) { + printf("free\t%08x\t\t%s:%d\n", p, file, line); fflush(stdout); + free(p); +} + +#endif + diff --git a/src/share/native/sun/security/pkcs11/wrapper/pkcs11wrapper.h b/src/share/native/sun/security/pkcs11/wrapper/pkcs11wrapper.h index 2b67e2b3df7423c502401db938d8fcc0cc8e900a..9dd90c304665fa813d0b7b11695ee5d55b44cc0e 100644 --- a/src/share/native/sun/security/pkcs11/wrapper/pkcs11wrapper.h +++ b/src/share/native/sun/security/pkcs11/wrapper/pkcs11wrapper.h @@ -1,5 +1,5 @@ /* - * Portions Copyright 2003-2006 Sun Microsystems, Inc. All Rights Reserved. + * Portions Copyright 2003-2009 Sun Microsystems, Inc. All Rights Reserved. */ /* Copyright (c) 2002 Graz University of Technology. All rights reserved. @@ -154,6 +154,7 @@ #include "pkcs11.h" #include <jni.h> +#include <jni_util.h> #define MAX_STACK_BUFFER_LEN (4 * 1024) #define MAX_HEAP_BUFFER_LEN (64 * 1024) @@ -277,12 +278,14 @@ */ jlong ckAssertReturnValueOK(JNIEnv *env, CK_RV returnValue); -void throwPKCS11RuntimeException(JNIEnv *env, jstring jmessage); -void throwFileNotFoundException(JNIEnv *env, jstring jmessage); void throwIOException(JNIEnv *env, const char *message); -void throwIOExceptionUnicodeMessage(JNIEnv *env, const short *message); +void throwPKCS11RuntimeException(JNIEnv *env, const char *message); void throwDisconnectedRuntimeException(JNIEnv *env); +/* function to free CK_ATTRIBUTE array + */ +void freeCKAttributeArray(CK_ATTRIBUTE_PTR attrPtr, int len); + /* funktions to convert Java arrays to a CK-type array and the array length */ void jBooleanArrayToCKBBoolArray(JNIEnv *env, const jbooleanArray jArray, CK_BBOOL **ckpArray, CK_ULONG_PTR ckLength); @@ -438,3 +441,15 @@ extern jobject notifyListLock; extern jobject jInitArgsObject; extern CK_C_INITIALIZE_ARGS_PTR ckpGlobalInitArgs; #endif /* NO_CALLBACKS */ + +#ifdef P11_MEMORYDEBUG +#include <stdlib.h> + +/* Simple malloc/free dumper */ +void *p11malloc(size_t c, char *file, int line); +void p11free(void *p, char *file, int line); + +#define malloc(c) (p11malloc((c), __FILE__, __LINE__)) +#define free(c) (p11free((c), __FILE__, __LINE__)) + +#endif diff --git a/src/share/sample/nio/file/AclEdit.java b/src/share/sample/nio/file/AclEdit.java new file mode 100644 index 0000000000000000000000000000000000000000..55ed9c00bee563bb5bd2ad3a7f3b1e6782cb5024 --- /dev/null +++ b/src/share/sample/nio/file/AclEdit.java @@ -0,0 +1,296 @@ +/* + * Copyright 2008-2009 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * - Neither the name of Sun Microsystems nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import java.nio.file.*; +import java.nio.file.attribute.*; +import java.io.IOException; +import java.util.*; +import java.util.regex.Pattern; + +/** + * Sample utility for editing a file's ACL. + */ + +public class AclEdit { + + // parse string as list of ACE permissions separated by / + static Set<AclEntryPermission> parsePermissions(String permsString) { + Set<AclEntryPermission> perms = new HashSet<AclEntryPermission>(); + String[] result = permsString.split("/"); + for (String s : result) { + if (s.equals("")) + continue; + try { + perms.add(AclEntryPermission.valueOf(s.toUpperCase())); + } catch (IllegalArgumentException x) { + System.err.format("Invalid permission '%s'\n", s); + System.exit(-1); + } + } + return perms; + } + + // parse string as list of ACE flags separated by / + static Set<AclEntryFlag> parseFlags(String flagsString) { + Set<AclEntryFlag> flags = new HashSet<AclEntryFlag>(); + String[] result = flagsString.split("/"); + for (String s : result) { + if (s.equals("")) + continue; + try { + flags.add(AclEntryFlag.valueOf(s.toUpperCase())); + } catch (IllegalArgumentException x) { + System.err.format("Invalid flag '%s'\n", s); + System.exit(-1); + } + } + return flags; + } + + // parse ACE type + static AclEntryType parseType(String typeString) { + // FIXME: support audit and alarm types in the future + if (typeString.equalsIgnoreCase("allow")) + return AclEntryType.ALLOW; + if (typeString.equalsIgnoreCase("deny")) + return AclEntryType.DENY; + System.err.format("Invalid type '%s'\n", typeString); + System.exit(-1); + return null; // keep compiler happy + } + + /** + * Parse string of the form: + * [user|group:]<username|groupname>:<perms>[:flags]:<allow|deny> + */ + static AclEntry parseAceString(String s, + UserPrincipalLookupService lookupService) + { + String[] result = s.split(":"); + + // must have at least 3 components (username:perms:type) + if (result.length < 3) + usage(); + + int index = 0; + int remaining = result.length; + + // optional first component can indicate user or group type + boolean isGroup = false; + if (result[index].equalsIgnoreCase("user") || + result[index].equalsIgnoreCase("group")) + { + if (--remaining < 3) + usage(); + isGroup = result[index++].equalsIgnoreCase("group"); + } + + // user and permissions required + String userString = result[index++]; remaining--; + String permsString = result[index++]; remaining--; + + // flags are optional + String flagsString = ""; + String typeString = null; + if (remaining == 1) { + typeString = result[index++]; + } else { + if (remaining == 2) { + flagsString = result[index++]; + typeString = result[index++]; + } else { + usage(); + } + } + + // lookup UserPrincipal + UserPrincipal user = null; + try { + user = (isGroup) ? + lookupService.lookupPrincipalByGroupName(userString) : + lookupService.lookupPrincipalByName(userString); + } catch (UserPrincipalNotFoundException x) { + System.err.format("Invalid %s '%s'\n", + ((isGroup) ? "group" : "user"), + userString); + System.exit(-1); + } catch (IOException x) { + System.err.format("Lookup of '%s' failed: %s\n", userString, x); + System.exit(-1); + } + + // map string representation of permissions, flags, and type + Set<AclEntryPermission> perms = parsePermissions(permsString); + Set<AclEntryFlag> flags = parseFlags(flagsString); + AclEntryType type = parseType(typeString); + + // build the ACL entry + return AclEntry.newBuilder() + .setType(type) + .setPrincipal(user) + .setPermissions(perms).setFlags(flags).build(); + } + + static void usage() { + System.err.println("usage: java AclEdit [ACL-operation] file"); + System.err.println(""); + System.err.println("Example 1: Prepends access control entry to the begining of the myfile's ACL"); + System.err.println(" java AclEdit A+alice:read_data/read_attributes:allow myfile"); + System.err.println(""); + System.err.println("Example 2: Remove the entry at index 6 of myfile's ACL"); + System.err.println(" java AclEdit A6- myfile"); + System.err.println(""); + System.err.println("Example 3: Replace the entry at index 2 of myfile's ACL"); + System.err.println(" java AclEdit A2=bob:write_data/append_data:deny myfile"); + System.exit(-1); + } + + static enum Action { + PRINT, + ADD, + REMOVE, + REPLACE; + } + + /** + * Main class: parses arguments and prints or edits ACL + */ + public static void main(String[] args) throws IOException { + Action action = null; + int index = -1; + String entryString = null; + + // parse arguments + if (args.length < 1 || args[0].equals("-help") || args[0].equals("-?")) + usage(); + + if (args.length == 1) { + action = Action.PRINT; + } else { + String s = args[0]; + + // A[index]+entry + if (Pattern.matches("^A[0-9]*\\+.*", s)) { + String[] result = s.split("\\+", 2); + if (result.length == 2) { + if (result[0].length() < 2) { + index = 0; + } else { + index = Integer.parseInt(result[0].substring(1)); + } + entryString = result[1]; + action = Action.ADD; + } + } + + // Aindex- + if (Pattern.matches("^A[0-9]+\\-", s)) { + String[] result = s.split("\\-", 2); + if (result.length == 2) { + index = Integer.parseInt(result[0].substring(1)); + entryString = result[1]; + action = Action.REMOVE; + } + } + + // Aindex=entry + if (Pattern.matches("^A[0-9]+=.*", s)) { + String[] result = s.split("=", 2); + if (result.length == 2) { + index = Integer.parseInt(result[0].substring(1)); + entryString = result[1]; + action = Action.REPLACE; + } + } + } + if (action == null) + usage(); + + int fileArg = (action == Action.PRINT) ? 0 : 1; + Path file = Paths.get(args[fileArg]); + + // read file's ACL + AclFileAttributeView view = + file.getFileAttributeView(AclFileAttributeView.class); + if (view == null) { + System.err.println("ACLs not supported on this platform"); + System.exit(-1); + } + List<AclEntry> acl = view.getAcl(); + + switch (action) { + // print ACL + case PRINT : { + for (int i=0; i<acl.size(); i++) { + System.out.format("%5d: %s\n", i, acl.get(i)); + } + break; + } + + // add ACE to existing ACL + case ADD: { + AclEntry entry = parseAceString(entryString, file + .getFileSystem().getUserPrincipalLookupService()); + if (index >= acl.size()) { + acl.add(entry); + } else { + acl.add(index, entry); + } + view.setAcl(acl); + break; + } + + // remove ACE + case REMOVE: { + if (index >= acl.size()) { + System.err.format("Index '%d' is invalid", index); + System.exit(-1); + } + acl.remove(index); + view.setAcl(acl); + break; + } + + // replace ACE + case REPLACE: { + if (index >= acl.size()) { + System.err.format("Index '%d' is invalid", index); + System.exit(-1); + } + AclEntry entry = parseAceString(entryString, file + .getFileSystem().getUserPrincipalLookupService()); + acl.set(index, entry); + view.setAcl(acl); + break; + } + } + } +} diff --git a/src/share/sample/nio/file/Chmod.java b/src/share/sample/nio/file/Chmod.java new file mode 100644 index 0000000000000000000000000000000000000000..eeb54ad6cd5ea943c969d6a92bb9ed4d91a1745a --- /dev/null +++ b/src/share/sample/nio/file/Chmod.java @@ -0,0 +1,347 @@ +/* + * Copyright 2008-2009 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * - Neither the name of Sun Microsystems nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import java.nio.file.*; +import java.nio.file.attribute.*; +import static java.nio.file.attribute.PosixFilePermission.*; +import static java.nio.file.FileVisitResult.*; +import java.io.IOException; +import java.util.*; + +/** + * Sample code that changes the permissions of files in a similar manner to the + * chmod(1) program. + */ + +public class Chmod { + + /** + * Compiles a list of one or more <em>symbolic mode expressions</em> that + * may be used to change a set of file permissions. This method is + * intended for use where file permissions are required to be changed in + * a manner similar to the UNIX <i>chmod</i> program. + * + * <p> The {@code exprs} parameter is a comma separated list of expressions + * where each takes the form: + * <blockquote> + * <i>who operator</i> [<i>permissions</i>] + * </blockquote> + * where <i>who</i> is one or more of the characters {@code 'u'}, {@code 'g'}, + * {@code 'o'}, or {@code 'a'} meaning the owner (user), group, others, or + * all (owner, group, and others) respectively. + * + * <p> <i>operator</i> is the character {@code '+'}, {@code '-'}, or {@code + * '='} signifying how permissions are to be changed. {@code '+'} means the + * permissions are added, {@code '-'} means the permissions are removed, and + * {@code '='} means the permissions are assigned absolutely. + * + * <p> <i>permissions</i> is a sequence of zero or more of the following: + * {@code 'r'} for read permission, {@code 'w'} for write permission, and + * {@code 'x'} for execute permission. If <i>permissions</i> is omitted + * when assigned absolutely, then the permissions are cleared for + * the owner, group, or others as identified by <i>who</i>. When omitted + * when adding or removing then the expression is ignored. + * + * <p> The following examples demonstrate possible values for the {@code + * exprs} parameter: + * + * <table border="0"> + * <tr> + * <td> {@code u=rw} </td> + * <td> Sets the owner permissions to be read and write. </td> + * </tr> + * <tr> + * <td> {@code ug+w} </td> + * <td> Sets the owner write and group write permissions. </td> + * </tr> + * <tr> + * <td> {@code u+w,o-rwx} </td> + * <td> Sets the owner write, and removes the others read, others write + * and others execute permissions. </td> + * </tr> + * <tr> + * <td> {@code o=} </td> + * <td> Sets the others permission to none (others read, others write and + * others execute permissions are removed if set) </td> + * </tr> + * </table> + * + * @param exprs + * List of one or more <em>symbolic mode expressions</em> + * + * @return A {@code Changer} that may be used to changer a set of + * file permissions + * + * @throws IllegalArgumentException + * If the value of the {@code exprs} parameter is invalid + */ + public static Changer compile(String exprs) { + // minimum is who and operator (u= for example) + if (exprs.length() < 2) + throw new IllegalArgumentException("Invalid mode"); + + // permissions that the changer will add or remove + final Set<PosixFilePermission> toAdd = new HashSet<PosixFilePermission>(); + final Set<PosixFilePermission> toRemove = new HashSet<PosixFilePermission>(); + + // iterate over each of expression modes + for (String expr: exprs.split(",")) { + // minimum of who and operator + if (expr.length() < 2) + throw new IllegalArgumentException("Invalid mode"); + + int pos = 0; + + // who + boolean u = false; + boolean g = false; + boolean o = false; + boolean done = false; + for (;;) { + switch (expr.charAt(pos)) { + case 'u' : u = true; break; + case 'g' : g = true; break; + case 'o' : o = true; break; + case 'a' : u = true; g = true; o = true; break; + default : done = true; + } + if (done) + break; + pos++; + } + if (!u && !g && !o) + throw new IllegalArgumentException("Invalid mode"); + + // get operator and permissions + char op = expr.charAt(pos++); + String mask = (expr.length() == pos) ? "" : expr.substring(pos); + + // operator + boolean add = (op == '+'); + boolean remove = (op == '-'); + boolean assign = (op == '='); + if (!add && !remove && !assign) + throw new IllegalArgumentException("Invalid mode"); + + // who= means remove all + if (assign && mask.length() == 0) { + assign = false; + remove = true; + mask = "rwx"; + } + + // permissions + boolean r = false; + boolean w = false; + boolean x = false; + for (int i=0; i<mask.length(); i++) { + switch (mask.charAt(i)) { + case 'r' : r = true; break; + case 'w' : w = true; break; + case 'x' : x = true; break; + default: + throw new IllegalArgumentException("Invalid mode"); + } + } + + // update permissions set + if (add) { + if (u) { + if (r) toAdd.add(OWNER_READ); + if (w) toAdd.add(OWNER_WRITE); + if (x) toAdd.add(OWNER_EXECUTE); + } + if (g) { + if (r) toAdd.add(GROUP_READ); + if (w) toAdd.add(GROUP_WRITE); + if (x) toAdd.add(GROUP_EXECUTE); + } + if (o) { + if (r) toAdd.add(OTHERS_READ); + if (w) toAdd.add(OTHERS_WRITE); + if (x) toAdd.add(OTHERS_EXECUTE); + } + } + if (remove) { + if (u) { + if (r) toRemove.add(OWNER_READ); + if (w) toRemove.add(OWNER_WRITE); + if (x) toRemove.add(OWNER_EXECUTE); + } + if (g) { + if (r) toRemove.add(GROUP_READ); + if (w) toRemove.add(GROUP_WRITE); + if (x) toRemove.add(GROUP_EXECUTE); + } + if (o) { + if (r) toRemove.add(OTHERS_READ); + if (w) toRemove.add(OTHERS_WRITE); + if (x) toRemove.add(OTHERS_EXECUTE); + } + } + if (assign) { + if (u) { + if (r) toAdd.add(OWNER_READ); + else toRemove.add(OWNER_READ); + if (w) toAdd.add(OWNER_WRITE); + else toRemove.add(OWNER_WRITE); + if (x) toAdd.add(OWNER_EXECUTE); + else toRemove.add(OWNER_EXECUTE); + } + if (g) { + if (r) toAdd.add(GROUP_READ); + else toRemove.add(GROUP_READ); + if (w) toAdd.add(GROUP_WRITE); + else toRemove.add(GROUP_WRITE); + if (x) toAdd.add(GROUP_EXECUTE); + else toRemove.add(GROUP_EXECUTE); + } + if (o) { + if (r) toAdd.add(OTHERS_READ); + else toRemove.add(OTHERS_READ); + if (w) toAdd.add(OTHERS_WRITE); + else toRemove.add(OTHERS_WRITE); + if (x) toAdd.add(OTHERS_EXECUTE); + else toRemove.add(OTHERS_EXECUTE); + } + } + } + + // return changer + return new Changer() { + @Override + public Set<PosixFilePermission> change(Set<PosixFilePermission> perms) { + perms.addAll(toAdd); + perms.removeAll(toRemove); + return perms; + } + }; + } + + /** + * A task that <i>changes</i> a set of {@link PosixFilePermission} elements. + */ + public interface Changer { + /** + * Applies the changes to the given set of permissions. + * + * @param perms + * The set of permissions to change + * + * @return The {@code perms} parameter + */ + Set<PosixFilePermission> change(Set<PosixFilePermission> perms); + } + + /** + * Changes the permissions of the file using the given Changer. + */ + static void chmod(FileRef file, Changer changer) { + try { + Set<PosixFilePermission> perms = Attributes + .readPosixFileAttributes(file).permissions(); + Attributes.setPosixFilePermissions(file, changer.change(perms)); + } catch (IOException x) { + System.err.println(x); + } + } + + /** + * Changes the permission of each file and directory visited + */ + static class TreeVisitor implements FileVisitor<FileRef> { + private final Changer changer; + + TreeVisitor(Changer changer) { + this.changer = changer; + } + + @Override + public FileVisitResult preVisitDirectory(FileRef dir) { + chmod(dir, changer); + return CONTINUE; + } + + @Override + public FileVisitResult preVisitDirectoryFailed(FileRef dir, IOException exc) { + System.err.println("WARNING: " + exc); + return CONTINUE; + } + + @Override + public FileVisitResult visitFile(FileRef file, BasicFileAttributes attrs) { + chmod(file, changer); + return CONTINUE; + } + + @Override + public FileVisitResult postVisitDirectory(FileRef dir, IOException exc) { + if (exc != null) + System.err.println("WARNING: " + exc); + return CONTINUE; + } + + @Override + public FileVisitResult visitFileFailed(FileRef file, IOException exc) { + System.err.println("WARNING: " + exc); + return CONTINUE; + } + } + + static void usage() { + System.err.println("java Chmod [-R] symbolic-mode-list file..."); + System.exit(-1); + } + + public static void main(String[] args) throws IOException { + if (args.length < 2) + usage(); + int argi = 0; + int maxDepth = 0; + if (args[argi].equals("-R")) { + if (args.length < 3) + usage(); + argi++; + maxDepth = Integer.MAX_VALUE; + } + + // compile the symbolic mode expressions + Changer changer = compile(args[argi++]); + TreeVisitor visitor = new TreeVisitor(changer); + + Set<FileVisitOption> opts = Collections.emptySet(); + while (argi < args.length) { + Path file = Paths.get(args[argi]); + Files.walkFileTree(file, opts, maxDepth, visitor); + argi++; + } + } +} diff --git a/src/share/sample/nio/file/Copy.java b/src/share/sample/nio/file/Copy.java new file mode 100644 index 0000000000000000000000000000000000000000..e1d5d044ef5192e0f3cb5fb4a99a5840e908ab14 --- /dev/null +++ b/src/share/sample/nio/file/Copy.java @@ -0,0 +1,217 @@ +/* + * Copyright 2008-2009 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * - Neither the name of Sun Microsystems nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import java.nio.file.*; +import static java.nio.file.StandardCopyOption.*; +import java.nio.file.attribute.*; +import static java.nio.file.FileVisitResult.*; +import java.io.IOException; +import java.util.*; + +/** + * Sample code that copies files in a similar manner to the cp(1) program. + */ + +public class Copy { + + /** + * Returns {@code true} if okay to overwrite a file ("cp -i") + */ + static boolean okayToOverwrite(FileRef file) { + String answer = System.console().readLine("overwrite %s (yes/no)? ", file); + return (answer.equalsIgnoreCase("y") || answer.equalsIgnoreCase("yes")); + } + + /** + * Copy source file to target location. If {@code prompt} is true then + * prompted user to overwrite target if it exists. The {@code preserve} + * parameter determines if file attributes should be copied/preserved. + */ + static void copyFile(Path source, Path target, boolean prompt, boolean preserve) { + CopyOption[] options = (preserve) ? + new CopyOption[] { COPY_ATTRIBUTES, REPLACE_EXISTING } : + new CopyOption[] { REPLACE_EXISTING }; + if (!prompt || target.notExists() || okayToOverwrite(target)) { + try { + source.copyTo(target, options); + } catch (IOException x) { + System.err.format("Unable to create: %s: %s%n", target, x); + } + } + } + + /** + * A {@code FileVisitor} that copies a file-tree ("cp -r") + */ + static class TreeCopier implements FileVisitor<Path> { + private final Path source; + private final Path target; + private final boolean prompt; + private final boolean preserve; + + TreeCopier(Path source, Path target, boolean prompt, boolean preserve) { + this.source = source; + this.target = target; + this.prompt = prompt; + this.preserve = preserve; + } + + @Override + public FileVisitResult preVisitDirectory(Path dir) { + // before visiting entries in a directory we copy the directory + // (okay if directory already exists). + CopyOption[] options = (preserve) ? + new CopyOption[] { COPY_ATTRIBUTES } : new CopyOption[0]; + + Path newdir = target.resolve(source.relativize(dir)); + try { + dir.copyTo(newdir, options); + } catch (FileAlreadyExistsException x) { + // ignore + } catch (IOException x) { + System.err.format("Unable to create: %s: %s%n", newdir, x); + return SKIP_SUBTREE; + } + return CONTINUE; + } + + @Override + public FileVisitResult preVisitDirectoryFailed(Path dir, IOException exc) { + System.err.format("Unable to copy: %s: %s%n", dir, exc); + return CONTINUE; + } + + @Override + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) { + if (attrs.isDirectory()) { + System.err.println("cycle detected: " + file); + } else { + copyFile(file, target.resolve(source.relativize(file)), + prompt, preserve); + } + return CONTINUE; + } + + @Override + public FileVisitResult postVisitDirectory(Path dir, IOException exc) { + // fix up modification time of directory when done + if (exc == null && preserve) { + try { + BasicFileAttributes attrs = Attributes.readBasicFileAttributes(dir); + Path newdir = target.resolve(source.relativize(dir)); + Attributes.setLastModifiedTime(newdir, + attrs.lastModifiedTime(), attrs.resolution()); + } catch (IOException x) { + // ignore + } + } + return CONTINUE; + } + + @Override + public FileVisitResult visitFileFailed(Path file, IOException exc) { + System.err.format("Unable to copy: %s: %s%n", file, exc); + return CONTINUE; + } + } + + static void usage() { + System.err.println("java Copy [-ip] source... target"); + System.err.println("java Copy -r [-ip] source-dir... target"); + System.exit(-1); + } + + public static void main(String[] args) throws IOException { + boolean recursive = false; + boolean prompt = false; + boolean preserve = false; + + // process options + int argi = 0; + while (argi < args.length) { + String arg = args[argi]; + if (!arg.startsWith("-")) + break; + if (arg.length() < 2) + usage(); + for (int i=1; i<arg.length(); i++) { + char c = arg.charAt(i); + switch (c) { + case 'r' : recursive = true; break; + case 'i' : prompt = true; break; + case 'p' : preserve = true; break; + default : usage(); + } + } + argi++; + } + + // remaining arguments are the source files(s) and the target location + int remaining = args.length - argi; + if (remaining < 2) + usage(); + Path[] source = new Path[remaining-1]; + int i=0; + while (remaining > 1) { + source[i++] = Paths.get(args[argi++]); + remaining--; + } + Path target = Paths.get(args[argi]); + + // check if target is a directory + boolean isDir = false; + try { + isDir = Attributes.readBasicFileAttributes(target).isDirectory(); + } catch (IOException x) { + } + + // copy each source file/directory to target + for (i=0; i<source.length; i++) { + Path dest = (isDir) ? target.resolve(source[i].getName()) : target; + + if (recursive) { + // follow links when copying files + EnumSet<FileVisitOption> opts = EnumSet.of(FileVisitOption.FOLLOW_LINKS); + TreeCopier tc = new TreeCopier(source[i], dest, prompt, preserve); + Files.walkFileTree(source[i], opts, -1, tc); + } else { + // not recursive so source must not be a directory + try { + if (Attributes.readBasicFileAttributes(source[i]).isDirectory()) { + System.err.format("%s: is a directory%n", source[i]); + continue; + } + } catch (IOException x) { } + copyFile(source[i], dest, prompt, preserve); + } + } + } +} diff --git a/src/share/sample/nio/file/DiskUsage.java b/src/share/sample/nio/file/DiskUsage.java new file mode 100644 index 0000000000000000000000000000000000000000..ff16d8884908487c06c2f1167997135409f952e6 --- /dev/null +++ b/src/share/sample/nio/file/DiskUsage.java @@ -0,0 +1,74 @@ +/* + * Copyright 2008-2009 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * - Neither the name of Sun Microsystems nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import java.nio.file.*; +import java.nio.file.attribute.*; +import java.io.IOException; + +/** + * Example utility that works like the df(1M) program to print out disk space + * information + */ + +public class DiskUsage { + + static final long K = 1024; + + static void printFileStore(FileStore store) throws IOException { + FileStoreSpaceAttributes attrs = Attributes.readFileStoreSpaceAttributes(store); + + long total = attrs.totalSpace() / K; + long used = (attrs.totalSpace() - attrs.unallocatedSpace()) / K; + long avail = attrs.usableSpace() / K; + + String s = store.toString(); + if (s.length() > 20) { + System.out.println(s); + s = ""; + } + System.out.format("%-20s %12d %12d %12d\n", s, total, used, avail); + } + + public static void main(String[] args) throws IOException { + System.out.format("%-20s %12s %12s %12s\n", "Filesystem", "kbytes", "used", "avail"); + if (args.length == 0) { + FileSystem fs = FileSystems.getDefault(); + for (FileStore store: fs.getFileStores()) { + printFileStore(store); + } + } else { + for (String file: args) { + FileStore store = Paths.get(file).getFileStore(); + printFileStore(store); + } + } + } +} diff --git a/src/share/sample/nio/file/FileType.java b/src/share/sample/nio/file/FileType.java new file mode 100644 index 0000000000000000000000000000000000000000..31fb45299a25ce6a885b861d55e9e28632e3a0f7 --- /dev/null +++ b/src/share/sample/nio/file/FileType.java @@ -0,0 +1,57 @@ +/* + * Copyright 2008-2009 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * - Neither the name of Sun Microsystems nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import java.nio.file.*; +import java.nio.file.attribute.*; +import java.io.IOException; + +public class FileType { + public static void main(String[] args) throws IOException { + if (args.length == 0) { + System.err.println("usage: java FileType file..."); + System.exit(-1); + } + for (String arg: args) { + Path file = Paths.get(arg); + BasicFileAttributes attrs = Attributes.readBasicFileAttributes(file); + + String type; + if (attrs.isDirectory()) { + type = "directory"; + } else { + type = Files.probeContentType(file); + if (type == null) + type = "<not recognized>"; + } + System.out.format("%s\t%s%n", file, type); + } + } +} diff --git a/src/share/sample/nio/file/WatchDir.java b/src/share/sample/nio/file/WatchDir.java new file mode 100644 index 0000000000000000000000000000000000000000..b8b6474dc6fb929004e7aeff58398004618fc668 --- /dev/null +++ b/src/share/sample/nio/file/WatchDir.java @@ -0,0 +1,196 @@ +/* + * Copyright 2008-2009 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * - Neither the name of Sun Microsystems nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import java.nio.file.*; +import static java.nio.file.StandardWatchEventKind.*; +import static java.nio.file.LinkOption.*; +import java.nio.file.attribute.*; +import java.io.*; +import java.util.*; + +/** + * Example to watch a directory (or tree) for changes to files. + */ + +public class WatchDir { + + private final WatchService watcher; + private final Map<WatchKey,Path> keys; + private final boolean recursive; + private boolean trace = false; + + @SuppressWarnings("unchecked") + static <T> WatchEvent<T> cast(WatchEvent<?> event) { + return (WatchEvent<T>)event; + } + + /** + * Register the given directory with the WatchService + */ + private void register(Path dir) throws IOException { + WatchKey key = dir.register(watcher, ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY); + if (trace) { + FileRef prev = keys.get(key); + if (prev == null) { + System.out.format("register: %s\n", dir); + } else { + if (!dir.equals(prev)) { + System.out.format("update: %s -> %s\n", prev, dir); + } + } + } + keys.put(key, dir); + } + + /** + * Register the given directory, and all its sub-directories, with the + * WatchService. + */ + private void registerAll(final Path start) throws IOException { + // register directory and sub-directories + Files.walkFileTree(start, new SimpleFileVisitor<Path>() { + @Override + public FileVisitResult preVisitDirectory(Path dir) { + try { + register(dir); + } catch (IOException x) { + throw new IOError(x); + } + return FileVisitResult.CONTINUE; + } + }); + } + + /** + * Creates a WatchService and registers the given directory + */ + WatchDir(Path dir, boolean recursive) throws IOException { + this.watcher = FileSystems.getDefault().newWatchService(); + this.keys = new HashMap<WatchKey,Path>(); + this.recursive = recursive; + + if (recursive) { + System.out.format("Scanning %s ...\n", dir); + registerAll(dir); + System.out.println("Done."); + } else { + register(dir); + } + + // enable trace after initial registration + this.trace = true; + } + + /** + * Process all events for keys queued to the watcher + */ + void processEvents() { + for (;;) { + + // wait for key to be signalled + WatchKey key; + try { + key = watcher.take(); + } catch (InterruptedException x) { + return; + } + + Path dir = keys.get(key); + if (dir == null) { + System.err.println("WatchKey not recognized!!"); + continue; + } + + for (WatchEvent<?> event: key.pollEvents()) { + WatchEvent.Kind kind = event.kind(); + + // TBD - provide example of how OVERFLOW event is handled + if (kind == OVERFLOW) { + continue; + } + + // Context for directory entry event is the file name of entry + WatchEvent<Path> ev = cast(event); + Path name = ev.context(); + Path child = dir.resolve(name); + + // print out event + System.out.format("%s: %s\n", event.kind().name(), child); + + // if directory is created, and watching recursively, then + // register it and its sub-directories + if (recursive && (kind == ENTRY_CREATE)) { + try { + if (Attributes.readBasicFileAttributes(child, NOFOLLOW_LINKS).isDirectory()) { + registerAll(child); + } + } catch (IOException x) { + // ignore to keep sample readbale + } + } + } + + // reset key and remove from set if directory no longer accessible + boolean valid = key.reset(); + if (!valid) { + keys.remove(key); + + // all directories are inaccessible + if (keys.isEmpty()) { + break; + } + } + } + } + + static void usage() { + System.err.println("usage: java WatchDir [-r] dir"); + System.exit(-1); + } + + public static void main(String[] args) throws IOException { + // parse arguments + if (args.length == 0 || args.length > 2) + usage(); + boolean recursive = false; + int dirArg = 0; + if (args[0].equals("-r")) { + if (args.length < 2) + usage(); + recursive = true; + dirArg++; + } + + // register directory and process its events + Path dir = Paths.get(args[dirArg]); + new WatchDir(dir, recursive).processEvents(); + } +} diff --git a/src/share/sample/nio/file/Xdd.java b/src/share/sample/nio/file/Xdd.java new file mode 100644 index 0000000000000000000000000000000000000000..f66597eddd42f434cde4f43e05facf5da1b9bbb3 --- /dev/null +++ b/src/share/sample/nio/file/Xdd.java @@ -0,0 +1,112 @@ +/* + * Copyright 2008-2009 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * - Neither the name of Sun Microsystems nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import java.nio.ByteBuffer; +import java.nio.charset.Charset; +import java.nio.file.*; +import java.nio.file.attribute.*; +import java.io.IOException; + +/** + * Example code to list/set/get/delete the user-defined attributes of a file. + */ + +public class Xdd { + + static void usage() { + System.out.println("Usage: java Xdd <file>"); + System.out.println(" java Xdd -set <name>=<value> <file>"); + System.out.println(" java Xdd -get <name> <file>"); + System.out.println(" java Xdd -del <name> <file>"); + System.exit(-1); + } + + public static void main(String[] args) throws IOException { + // one or three parameters + if (args.length != 1 && args.length != 3) + usage(); + + Path file = (args.length == 1) ? + Paths.get(args[0]) : Paths.get(args[2]); + + // check that user defined attributes are supported by the file system + FileStore store = file.getFileStore(); + if (!store.supportsFileAttributeView("xattr")) { + System.err.format("UserDefinedFileAttributeView not supported on %s\n", store); + System.exit(-1); + + } + UserDefinedFileAttributeView view = file. + getFileAttributeView(UserDefinedFileAttributeView.class); + + // list user defined attributes + if (args.length == 1) { + System.out.println(" Size Name"); + System.out.println("-------- --------------------------------------"); + for (String name: view.list()) { + System.out.format("%8d %s\n", view.size(name), name); + } + return; + } + + // Add/replace a file's user defined attribute + if (args[0].equals("-set")) { + // name=value + String[] s = args[1].split("="); + if (s.length != 2) + usage(); + String name = s[0]; + String value = s[1]; + view.write(name, Charset.defaultCharset().encode(value)); + return; + } + + // Print out the value of a file's user defined attribute + if (args[0].equals("-get")) { + String name = args[1]; + int size = view.size(name); + ByteBuffer buf = ByteBuffer.allocateDirect(size); + view.read(name, buf); + buf.flip(); + System.out.println(Charset.defaultCharset().decode(buf).toString()); + return; + } + + // Delete a file's user defined attribute + if (args[0].equals("-del")) { + view.delete(args[1]); + return; + } + + // option not recognized + usage(); + } + } diff --git a/src/solaris/classes/sun/awt/X11/XFontPeer.java b/src/solaris/classes/sun/awt/X11/XFontPeer.java index 62044ace53e842b5413d38d3df4a25c2662de788..3d03a2503aad61123924dd169c63e6e00ebcde6f 100644 --- a/src/solaris/classes/sun/awt/X11/XFontPeer.java +++ b/src/solaris/classes/sun/awt/X11/XFontPeer.java @@ -27,9 +27,6 @@ package sun.awt.X11; import sun.awt.PlatformFont; import java.awt.GraphicsEnvironment; -/* FIX ME */ -import sun.awt.motif.MFontConfiguration; - public class XFontPeer extends PlatformFont { /* @@ -51,10 +48,6 @@ public class XFontPeer extends PlatformFont { public XFontPeer(String name, int style){ super(name, style); - - if (fontConfig != null){ - xfsname = ((MFontConfiguration) fontConfig).getMotifFontSet(familyName, style); - } } protected char getMissingGlyphCharacter() { diff --git a/src/solaris/classes/sun/font/FcFontConfiguration.java b/src/solaris/classes/sun/font/FcFontConfiguration.java index fe2e5dbf83658b432499c0db4f2f3e1ac52ecb3f..a34fed02e156fd5f4ea8852ee09a541976a5835c 100644 --- a/src/solaris/classes/sun/font/FcFontConfiguration.java +++ b/src/solaris/classes/sun/font/FcFontConfiguration.java @@ -15,7 +15,7 @@ * accompanied this code). * * You should have received a copy of the GNU General Public License version - * along with this work; if not, write to the Free Software Foundation, + * 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, @@ -87,6 +87,7 @@ public class FcFontConfiguration extends FontConfiguration { return true; } + setFontConfiguration(); readFcInfo(); if (fcCompFonts == null) { fcCompFonts = FontManager.loadFontConfig(); @@ -172,7 +173,7 @@ public class FcFontConfiguration extends FontConfiguration { @Override public FontDescriptor[] getFontDescriptors(String fontName, int style) { - throw new InternalError("Not implemented"); + return new FontDescriptor[0]; } @Override diff --git a/src/solaris/classes/sun/net/NetHooks.java b/src/solaris/classes/sun/net/NetHooks.java new file mode 100644 index 0000000000000000000000000000000000000000..f847934190c4231e59a0628b964e5a0a718c837c --- /dev/null +++ b/src/solaris/classes/sun/net/NetHooks.java @@ -0,0 +1,122 @@ +/* + * 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 sun.net; + +import java.net.InetAddress; +import java.io.FileDescriptor; +import java.io.IOException; +import java.security.AccessController; +import java.security.PrivilegedAction; +import sun.security.action.GetPropertyAction; + +/** + * Defines static methods to be invoked prior to binding or connecting TCP sockets. + */ + +public final class NetHooks { + + /** + * A provider with hooks to allow sockets be converted prior to binding or + * connecting a TCP socket. + * + * <p> Concrete implementations of this class should define a zero-argument + * constructor and implement the abstract methods specified below. + */ + public static abstract class Provider { + /** + * Initializes a new instance of this class. + */ + protected Provider() {} + + /** + * Invoked prior to binding a TCP socket. + */ + public abstract void implBeforeTcpBind(FileDescriptor fdObj, + InetAddress address, + int port) + throws IOException; + + /** + * Invoked prior to connecting an unbound TCP socket. + */ + public abstract void implBeforeTcpConnect(FileDescriptor fdObj, + InetAddress address, + int port) + throws IOException; + } + + /** + * For now, we load the SDP provider on Solaris. In the future this may + * be changed to use the ServiceLoader facility to allow the deployment of + * other providers. + */ + private static Provider loadProvider(final String cn) { + return AccessController + .doPrivileged(new PrivilegedAction<Provider>() { + @Override public Provider run() { + Class<Provider> c; + try { + c = (Class<Provider>)Class.forName(cn, true, null); + } catch (ClassNotFoundException x) { + throw new AssertionError(x); + } + try { + return c.newInstance(); + } catch (IllegalAccessException x) { + throw new AssertionError(x); + } catch (InstantiationException x) { + throw new AssertionError(x); + } + }}); + } + private static final Provider provider = AccessController + .doPrivileged(new GetPropertyAction("os.name")).equals("SunOS") ? + loadProvider("sun.net.spi.SdpProvider") : null; + + /** + * Invoke prior to binding a TCP socket. + */ + public static void beforeTcpBind(FileDescriptor fdObj, + InetAddress address, + int port) + throws IOException + { + if (provider != null) + provider.implBeforeTcpBind(fdObj, address, port); + } + + /** + * Invoke prior to connecting an unbound TCP socket. + */ + public static void beforeTcpConnect(FileDescriptor fdObj, + InetAddress address, + int port) + throws IOException + { + if (provider != null) + provider.implBeforeTcpConnect(fdObj, address, port); + } +} diff --git a/src/solaris/classes/sun/net/spi/SdpProvider.java b/src/solaris/classes/sun/net/spi/SdpProvider.java new file mode 100644 index 0000000000000000000000000000000000000000..4ae7d9fa58cd7fb50161b75809d0b00d98aed608 --- /dev/null +++ b/src/solaris/classes/sun/net/spi/SdpProvider.java @@ -0,0 +1,339 @@ +/* + * 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 sun.net.spi; + +import sun.net.NetHooks; +import java.net.InetAddress; +import java.net.Inet4Address; +import java.net.UnknownHostException; +import java.util.*; +import java.io.File; +import java.io.FileDescriptor; +import java.io.IOException; +import java.io.PrintStream; + +import sun.misc.SharedSecrets; +import sun.misc.JavaIOFileDescriptorAccess; + +/** + * A NetHooks provider that converts sockets from the TCP to SDP protocol prior + * to binding or connecting. + */ + +public class SdpProvider extends NetHooks.Provider { + private static final JavaIOFileDescriptorAccess fdAccess = + SharedSecrets.getJavaIOFileDescriptorAccess(); + + // maximum port + private static final int MAX_PORT = 65535; + + // indicates if SDP is enabled and the rules for when the protocol is used + private final boolean enabled; + private final List<Rule> rules; + + // logging for debug purposes + private PrintStream log; + + public SdpProvider() { + // if this property is not defined then there is nothing to do. + String file = System.getProperty("com.sun.sdp.conf"); + if (file == null) { + this.enabled = false; + this.rules = null; + return; + } + + // load configuration file + List<Rule> list = null; + if (file != null) { + try { + list = loadRulesFromFile(file); + } catch (IOException e) { + fail("Error reading %s: %s", file, e.getMessage()); + } + } + + // check if debugging is enabled + PrintStream out = null; + String logfile = System.getProperty("com.sun.sdp.debug"); + if (logfile != null) { + out = System.out; + if (logfile.length() > 0) { + try { + out = new PrintStream(logfile); + } catch (IOException ignore) { } + } + } + + this.enabled = !list.isEmpty(); + this.rules = list; + this.log = out; + } + + // supported actions + private static enum Action { + BIND, + CONNECT; + } + + // a rule for matching a bind or connect request + private static interface Rule { + boolean match(Action action, InetAddress address, int port); + } + + // rule to match port[-end] + private static class PortRangeRule implements Rule { + private final Action action; + private final int portStart; + private final int portEnd; + PortRangeRule(Action action, int portStart, int portEnd) { + this.action = action; + this.portStart = portStart; + this.portEnd = portEnd; + } + Action action() { + return action; + } + @Override + public boolean match(Action action, InetAddress address, int port) { + return (action == this.action && + port >= this.portStart && + port <= this.portEnd); + } + } + + // rule to match address[/prefix] port[-end] + private static class AddressPortRangeRule extends PortRangeRule { + private final byte[] addressAsBytes; + private final int prefixByteCount; + private final byte mask; + AddressPortRangeRule(Action action, InetAddress address, + int prefix, int port, int end) + { + super(action, port, end); + this.addressAsBytes = address.getAddress(); + this.prefixByteCount = prefix >> 3; + this.mask = (byte)(0xff << (8 - (prefix % 8))); + } + @Override + public boolean match(Action action, InetAddress address, int port) { + if (action != action()) + return false; + byte[] candidate = address.getAddress(); + // same address type? + if (candidate.length != addressAsBytes.length) + return false; + // check bytes + for (int i=0; i<prefixByteCount; i++) { + if (candidate[i] != addressAsBytes[i]) + return false; + } + // check remaining bits + if ((prefixByteCount < addressAsBytes.length) && + ((candidate[prefixByteCount] & mask) != + (addressAsBytes[prefixByteCount] & mask))) + return false; + return super.match(action, address, port); + } + } + + // parses port:[-end] + private static int[] parsePortRange(String s) { + int pos = s.indexOf('-'); + try { + int[] result = new int[2]; + if (pos < 0) { + boolean all = s.equals("*"); + result[0] = all ? 0 : Integer.parseInt(s); + result[1] = all ? MAX_PORT : result[0]; + } else { + String low = s.substring(0, pos); + if (low.length() == 0) low = "*"; + String high = s.substring(pos+1); + if (high.length() == 0) high = "*"; + result[0] = low.equals("*") ? 0 : Integer.parseInt(low); + result[1] = high.equals("*") ? MAX_PORT : Integer.parseInt(high); + } + return result; + } catch (NumberFormatException e) { + return new int[0]; + } + } + + private static void fail(String msg, Object... args) { + Formatter f = new Formatter(); + f.format(msg, args); + throw new RuntimeException(f.out().toString()); + } + + // loads rules from the given file + // Each non-blank/non-comment line must have the format: + // ("bind" | "connect") 1*LWSP-char (hostname | ipaddress["/" prefix]) + // 1*LWSP-char ("*" | port) [ "-" ("*" | port) ] + private static List<Rule> loadRulesFromFile(String file) + throws IOException + { + Scanner scanner = new Scanner(new File(file)); + try { + List<Rule> result = new ArrayList<Rule>(); + while (scanner.hasNextLine()) { + String line = scanner.nextLine().trim(); + + // skip blank lines and comments + if (line.length() == 0 || line.charAt(0) == '#') + continue; + + // must have 3 fields + String[] s = line.split("\\s+"); + if (s.length != 3) { + fail("Malformed line '%s'", line); + continue; + } + + // first field is the action ("bind" or "connect") + Action action = null; + for (Action a: Action.values()) { + if (s[0].equalsIgnoreCase(a.name())) { + action = a; + break; + } + } + if (action == null) { + fail("Action '%s' not recognized", s[0]); + continue; + } + + // * port[-end] + int[] ports = parsePortRange(s[2]); + if (ports.length == 0) { + fail("Malformed port range '%s'", s[2]); + continue; + } + + // match all addresses + if (s[1].equals("*")) { + result.add(new PortRangeRule(action, ports[0], ports[1])); + continue; + } + + // hostname | ipaddress[/prefix] + int pos = s[1].indexOf('/'); + try { + if (pos < 0) { + // hostname or ipaddress (no prefix) + InetAddress[] addresses = InetAddress.getAllByName(s[1]); + for (InetAddress address: addresses) { + int prefix = + (address instanceof Inet4Address) ? 32 : 128; + result.add(new AddressPortRangeRule(action, address, + prefix, ports[0], ports[1])); + } + } else { + // ipaddress/prefix + InetAddress address = InetAddress + .getByName(s[1].substring(0, pos)); + int prefix = -1; + try { + prefix = Integer.parseInt(s[1].substring(pos+1)); + if (address instanceof Inet4Address) { + // must be 1-31 + if (prefix < 0 || prefix > 32) prefix = -1; + } else { + // must be 1-128 + if (prefix < 0 || prefix > 128) prefix = -1; + } + } catch (NumberFormatException e) { + } + + if (prefix > 0) { + result.add(new AddressPortRangeRule(action, + address, prefix, ports[0], ports[1])); + } else { + fail("Malformed prefix '%s'", s[1]); + continue; + } + } + } catch (UnknownHostException uhe) { + fail("Unknown host or malformed IP address '%s'", s[1]); + continue; + } + } + return result; + } finally { + scanner.close(); + } + } + + // converts unbound TCP socket to a SDP socket if it matches the rules + private void convertTcpToSdpIfMatch(FileDescriptor fdObj, + Action action, + InetAddress address, + int port) + throws IOException + { + boolean matched = false; + for (Rule rule: rules) { + if (rule.match(action, address, port)) { + int fd = fdAccess.get(fdObj); + convert(fd); + matched = true; + break; + } + } + if (log != null) { + String addr = (address instanceof Inet4Address) ? + address.getHostAddress() : "[" + address.getHostAddress() + "]"; + if (matched) { + log.format("%s to %s:%d (socket converted to SDP protocol)\n", action, addr, port); + } else { + log.format("%s to %s:%d (no match)\n", action, addr, port); + } + } + } + + @Override + public void implBeforeTcpBind(FileDescriptor fdObj, + InetAddress address, + int port) + throws IOException + { + if (enabled) + convertTcpToSdpIfMatch(fdObj, Action.BIND, address, port); + } + + @Override + public void implBeforeTcpConnect(FileDescriptor fdObj, + InetAddress address, + int port) + throws IOException + { + if (enabled) + convertTcpToSdpIfMatch(fdObj, Action.CONNECT, address, port); + } + + // -- native methods -- + private static native void convert(int fd) throws IOException; +} diff --git a/src/solaris/classes/sun/nio/ch/DatagramDispatcher.java b/src/solaris/classes/sun/nio/ch/DatagramDispatcher.java index 8ac3e1e8d4f7fd45eaf12acb97718510e8d85c59..9d0a1d1d7d33863cd16145ff07ae5b223f0c0820 100644 --- a/src/solaris/classes/sun/nio/ch/DatagramDispatcher.java +++ b/src/solaris/classes/sun/nio/ch/DatagramDispatcher.java @@ -1,5 +1,5 @@ /* - * Copyright 2001-2005 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2001-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 @@ -56,11 +56,11 @@ class DatagramDispatcher extends NativeDispatcher } void close(FileDescriptor fd) throws IOException { - FileDispatcher.close0(fd); + FileDispatcherImpl.close0(fd); } void preClose(FileDescriptor fd) throws IOException { - FileDispatcher.preClose0(fd); + FileDispatcherImpl.preClose0(fd); } static native int read0(FileDescriptor fd, long address, int len) diff --git a/src/solaris/classes/sun/nio/ch/DefaultAsynchronousChannelProvider.java b/src/solaris/classes/sun/nio/ch/DefaultAsynchronousChannelProvider.java new file mode 100644 index 0000000000000000000000000000000000000000..949c817ff1e665d332537ee8599a228d817470d1 --- /dev/null +++ b/src/solaris/classes/sun/nio/ch/DefaultAsynchronousChannelProvider.java @@ -0,0 +1,56 @@ +/* + * Copyright 2008-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 sun.nio.ch; + +import java.nio.channels.spi.AsynchronousChannelProvider; +import java.security.AccessController; +import sun.security.action.GetPropertyAction; + +/** + * Creates this platform's default asynchronous channel provider + */ + +public class DefaultAsynchronousChannelProvider { + + /** + * Prevent instantiation. + */ + private DefaultAsynchronousChannelProvider() { } + + /** + * Returns the default AsynchronousChannelProvider. + */ + public static AsynchronousChannelProvider create() { + String osname = AccessController + .doPrivileged(new GetPropertyAction("os.name")); + if (osname.equals("SunOS")) + return new SolarisAsynchronousChannelProvider(); + if (osname.equals("Linux")) + return new LinuxAsynchronousChannelProvider(); + throw new InternalError("platform not recognized"); + } + +} diff --git a/src/solaris/classes/sun/nio/ch/DevPollArrayWrapper.java b/src/solaris/classes/sun/nio/ch/DevPollArrayWrapper.java index 7317a8eab1c0eb318956f1dbd5cacdba65005be5..53693383eeda5532c875a2b679cff3d44d69b82c 100644 --- a/src/solaris/classes/sun/nio/ch/DevPollArrayWrapper.java +++ b/src/solaris/classes/sun/nio/ch/DevPollArrayWrapper.java @@ -1,5 +1,5 @@ /* - * Copyright 2001-2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2001-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 @@ -76,20 +76,19 @@ class DevPollArrayWrapper { // Base address of the native pollArray private long pollArrayAddress; + // Array of pollfd structs used for driver updates + private AllocatedNativeObject updatePollArray; + // Maximum number of POLL_FD structs to update at once - private int MAX_UPDATE_SIZE = 10000; + private int MAX_UPDATE_SIZE = Math.min(OPEN_MAX, 10000); DevPollArrayWrapper() { int allocationSize = NUM_POLLFDS * SIZE_POLLFD; pollArray = new AllocatedNativeObject(allocationSize, true); pollArrayAddress = pollArray.address(); + allocationSize = MAX_UPDATE_SIZE * SIZE_POLLFD; + updatePollArray = new AllocatedNativeObject(allocationSize, true); wfd = init(); - - for (int i=0; i<NUM_POLLFDS; i++) { - putDescriptor(i, 0); - putEventOps(i, 0); - putReventOps(i, 0); - } } // Machinery for remembering fd registration changes @@ -129,21 +128,11 @@ class DevPollArrayWrapper { register(wfd, fd0, POLLIN); } - void putEventOps(int i, int event) { - int offset = SIZE_POLLFD * i + EVENT_OFFSET; - pollArray.putShort(offset, (short)event); - } - void putReventOps(int i, int revent) { int offset = SIZE_POLLFD * i + REVENT_OFFSET; pollArray.putShort(offset, (short)revent); } - void putDescriptor(int i, int fd) { - int offset = SIZE_POLLFD * i + FD_OFFSET; - pollArray.putInt(offset, fd); - } - int getEventOps(int i) { int offset = SIZE_POLLFD * i + EVENT_OFFSET; return pollArray.getShort(offset); @@ -172,11 +161,12 @@ class DevPollArrayWrapper { } void closeDevPollFD() throws IOException { - FileDispatcher.closeIntFD(wfd); + FileDispatcherImpl.closeIntFD(wfd); pollArray.free(); + updatePollArray.free(); } - int poll(long timeout) { + int poll(long timeout) throws IOException { updateRegistrations(); updated = poll0(pollArrayAddress, NUM_POLLFDS, timeout, wfd); for (int i=0; i<updated; i++) { @@ -189,60 +179,34 @@ class DevPollArrayWrapper { return updated; } - void updateRegistrations() { - // take snapshot of the updateList size to see if there are - // any registrations to update - int updateSize; + void updateRegistrations() throws IOException { + // Populate pollfd array with updated masks synchronized (updateList) { - updateSize = updateList.size(); - } - if (updateSize > 0) { - // Construct a pollfd array with updated masks; we may overallocate - // by some amount because if the events are already POLLREMOVE - // then the second pollfd of that pair will not be needed. The - // number of entries is limited to a reasonable number to avoid - // allocating a lot of memory. - int maxUpdates = Math.min(updateSize * 2, MAX_UPDATE_SIZE); - int allocationSize = maxUpdates * SIZE_POLLFD; - AllocatedNativeObject updatePollArray = - new AllocatedNativeObject(allocationSize, true); - - try { - synchronized (updateList) { - while (updateList.size() > 0) { - // We have to insert a dummy node in between each - // real update to use POLLREMOVE on the fd first because - // otherwise the changes are simply OR'd together - int index = 0; - Updator u = null; - while ((u = updateList.poll()) != null) { - // First add pollfd struct to clear out this fd - putPollFD(updatePollArray, index, u.fd, POLLREMOVE); - index++; - // Now add pollfd to update this fd, if necessary - if (u.mask != POLLREMOVE) { - putPollFD(updatePollArray, index, u.fd, - (short)u.mask); - index++; - } - - // Check against the max allocation size; these are - // all we will process. Valid index ranges from 0 to - // (maxUpdates - 1) and we can use up to 2 per loop - if (index > maxUpdates - 2) - break; - } - // Register the changes with /dev/poll - registerMultiple(wfd, updatePollArray.address(), index); - } + while (updateList.size() > 0) { + // We have to insert a dummy node in between each + // real update to use POLLREMOVE on the fd first because + // otherwise the changes are simply OR'd together + int index = 0; + Updator u = null; + while ((u = updateList.poll()) != null) { + // First add pollfd struct to clear out this fd + putPollFD(updatePollArray, index, u.fd, POLLREMOVE); + index++; + // Now add pollfd to update this fd, if necessary + if (u.mask != POLLREMOVE) { + putPollFD(updatePollArray, index, u.fd, (short)u.mask); + index++; + } + + // Check against the max update size; these are + // all we will process. Valid index ranges from 0 to + // (MAX_UPDATE_SIZE - 1) and we can use up to 2 per loop + if (index > MAX_UPDATE_SIZE - 2) + break; } - } finally { - // Free the native array - updatePollArray.free(); - // BUG: If an exception was thrown then the selector now believes - // that the last set of changes was updated but it probably - // was not. This should not be a likely occurrence. - } + // Register the changes with /dev/poll + registerMultiple(wfd, updatePollArray.address(), index); + } } } @@ -275,7 +239,8 @@ class DevPollArrayWrapper { private native int init(); private native void register(int wfd, int fd, int mask); - private native void registerMultiple(int wfd, long address, int len); + private native void registerMultiple(int wfd, long address, int len) + throws IOException; private native int poll0(long pollAddress, int numfds, long timeout, int wfd); private static native void interrupt(int fd); diff --git a/src/solaris/classes/sun/nio/ch/DevPollSelectorImpl.java b/src/solaris/classes/sun/nio/ch/DevPollSelectorImpl.java index cdf19cda20760840a79104c0782d4f1f6616472a..f3f26e48e7f5cb9dc50bc21d1e42b4e08612384a 100644 --- a/src/solaris/classes/sun/nio/ch/DevPollSelectorImpl.java +++ b/src/solaris/classes/sun/nio/ch/DevPollSelectorImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2001-2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2001-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 @@ -139,8 +139,8 @@ class DevPollSelectorImpl interruptTriggered = true; } - FileDispatcher.closeIntFD(fd0); - FileDispatcher.closeIntFD(fd1); + FileDispatcherImpl.closeIntFD(fd0); + FileDispatcherImpl.closeIntFD(fd1); pollWrapper.release(fd0); pollWrapper.closeDevPollFD(); diff --git a/src/solaris/classes/sun/nio/ch/EPoll.java b/src/solaris/classes/sun/nio/ch/EPoll.java new file mode 100644 index 0000000000000000000000000000000000000000..065dced7a8afe37d3e2360f53a291601e81fc56f --- /dev/null +++ b/src/solaris/classes/sun/nio/ch/EPoll.java @@ -0,0 +1,121 @@ +/* + * Copyright 2008-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 sun.nio.ch; + +import java.io.IOException; +import sun.misc.Unsafe; + +/** + * Provides access to the Linux epoll facility. + */ + +class EPoll { + private EPoll() { } + + private static final Unsafe unsafe = Unsafe.getUnsafe(); + + /** + * typedef union epoll_data { + * void *ptr; + * int fd; + * __uint32_t u32; + * __uint64_t u64; + * } epoll_data_t; + * + * struct epoll_event { + * __uint32_t events; + * epoll_data_t data; + * } + */ + private static final int SIZEOF_EPOLLEVENT = eventSize(); + private static final int OFFSETOF_EVENTS = eventsOffset(); + private static final int OFFSETOF_FD = dataOffset(); + + // opcodes + static final int EPOLL_CTL_ADD = 1; + static final int EPOLL_CTL_DEL = 2; + static final int EPOLL_CTL_MOD = 3; + + // flags + static final int EPOLLONESHOT = (1 << 30); + + /** + * Allocates a poll array to handle up to {@code count} events. + */ + static long allocatePollArray(int count) { + return unsafe.allocateMemory(count * SIZEOF_EPOLLEVENT); + } + + /** + * Free a poll array + */ + static void freePollArray(long address) { + unsafe.freeMemory(address); + } + + /** + * Returns event[i]; + */ + static long getEvent(long address, int i) { + return address + (SIZEOF_EPOLLEVENT*i); + } + + /** + * Returns event->data.fd + */ + static int getDescriptor(long eventAddress) { + return unsafe.getInt(eventAddress + OFFSETOF_FD); + } + + /** + * Returns event->events + */ + static int getEvents(long eventAddress) { + return unsafe.getInt(eventAddress + OFFSETOF_EVENTS); + } + + // -- Native methods -- + + private static native void init(); + + private static native int eventSize(); + + private static native int eventsOffset(); + + private static native int dataOffset(); + + static native int epollCreate() throws IOException; + + static native int epollCtl(int epfd, int opcode, int fd, int events); + + static native int epollWait(int epfd, long pollAddress, int numfds) + throws IOException; + + static { + Util.load(); + init(); + } +} diff --git a/src/solaris/classes/sun/nio/ch/EPollArrayWrapper.java b/src/solaris/classes/sun/nio/ch/EPollArrayWrapper.java index d8542e1b03d69082d9a6580a5533d3bcb8e2f81d..622ff8d4764ee5306c1b2fdb0cc1ddbc6d8e3aab 100644 --- a/src/solaris/classes/sun/nio/ch/EPollArrayWrapper.java +++ b/src/solaris/classes/sun/nio/ch/EPollArrayWrapper.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2005-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 @@ -78,8 +78,8 @@ class EPollArrayWrapper { // Base address of the native pollArray private final long pollArrayAddress; - // Set of "idle" file descriptors - private final HashSet<Integer> idleSet; + // Set of "idle" channels + private final HashSet<SelChImpl> idleSet; EPollArrayWrapper() { // creates the epoll file descriptor @@ -96,19 +96,22 @@ class EPollArrayWrapper { } // create idle set - idleSet = new HashSet<Integer>(); + idleSet = new HashSet<SelChImpl>(); } // Used to update file description registrations private static class Updator { + SelChImpl channel; int opcode; - int fd; int events; - Updator(int opcode, int fd, int events) { + Updator(SelChImpl channel, int opcode, int events) { + this.channel = channel; this.opcode = opcode; - this.fd = fd; this.events = events; } + Updator(SelChImpl channel, int opcode) { + this(channel, opcode, 0); + } } private LinkedList<Updator> updateList = new LinkedList<Updator>(); @@ -163,60 +166,54 @@ class EPollArrayWrapper { } /** - * Update the events for a given file descriptor. + * Update the events for a given channel. */ - void setInterest(int fd, int mask) { + void setInterest(SelChImpl channel, int mask) { synchronized (updateList) { - - // if the interest events are 0 then add to idle set, and delete - // from epoll if registered (or pending) - if (mask == 0) { - if (idleSet.add(fd)) { - updateList.add(new Updator(EPOLL_CTL_DEL, fd, 0)); - } - return; - } - - // if file descriptor is idle then add to epoll - if (!idleSet.isEmpty() && idleSet.remove(fd)) { - updateList.add(new Updator(EPOLL_CTL_ADD, fd, mask)); - return; - } - // if the previous pending operation is to add this file descriptor // to epoll then update its event set if (updateList.size() > 0) { Updator last = updateList.getLast(); - if (last.fd == fd && last.opcode == EPOLL_CTL_ADD) { + if (last.channel == channel && last.opcode == EPOLL_CTL_ADD) { last.events = mask; return; } } // update existing registration - updateList.add(new Updator(EPOLL_CTL_MOD, fd, mask)); + updateList.add(new Updator(channel, EPOLL_CTL_MOD, mask)); } } /** - * Add a new file descriptor to epoll + * Add a channel's file descriptor to epoll */ - void add(int fd) { + void add(SelChImpl channel) { synchronized (updateList) { - updateList.add(new Updator(EPOLL_CTL_ADD, fd, 0)); + updateList.add(new Updator(channel, EPOLL_CTL_ADD)); } } /** - * Remove a file descriptor from epoll + * Remove a channel's file descriptor from epoll */ - void release(int fd) { + void release(SelChImpl channel) { synchronized (updateList) { - // if file descriptor is idle then remove from idle set, otherwise - // delete from epoll - if (!idleSet.remove(fd)) { - updateList.add(new Updator(EPOLL_CTL_DEL, fd, 0)); + // flush any pending updates + int i = 0; + while (i < updateList.size()) { + if (updateList.get(i).channel == channel) { + updateList.remove(i); + } else { + i++; + } } + + // remove from the idle set (if present) + idleSet.remove(channel); + + // remove from epoll (if registered) + epollCtl(epfd, EPOLL_CTL_DEL, channel.getFDVal(), 0); } } @@ -224,7 +221,7 @@ class EPollArrayWrapper { * Close epoll file descriptor and free poll array */ void closeEPollFD() throws IOException { - FileDispatcher.closeIntFD(epfd); + FileDispatcherImpl.closeIntFD(epfd); pollArray.free(); } @@ -248,7 +245,26 @@ class EPollArrayWrapper { synchronized (updateList) { Updator u = null; while ((u = updateList.poll()) != null) { - epollCtl(epfd, u.opcode, u.fd, u.events); + SelChImpl ch = u.channel; + if (!ch.isOpen()) + continue; + + // if the events are 0 then file descriptor is put into "idle + // set" to prevent it being polled + if (u.events == 0) { + boolean added = idleSet.add(u.channel); + // if added to idle set then remove from epoll if registered + if (added && (u.opcode == EPOLL_CTL_MOD)) + epollCtl(epfd, EPOLL_CTL_DEL, ch.getFDVal(), 0); + } else { + // events are specified. If file descriptor was in idle set + // it must be re-registered (by converting opcode to ADD) + boolean idle = false; + if (!idleSet.isEmpty()) + idle = idleSet.remove(u.channel); + int opcode = (idle) ? EPOLL_CTL_ADD : u.opcode; + epollCtl(epfd, opcode, ch.getFDVal(), u.events); + } } } } diff --git a/src/solaris/classes/sun/nio/ch/EPollPort.java b/src/solaris/classes/sun/nio/ch/EPollPort.java new file mode 100644 index 0000000000000000000000000000000000000000..a79cb731841ad6c212a472242e5f9f9aac58883a --- /dev/null +++ b/src/solaris/classes/sun/nio/ch/EPollPort.java @@ -0,0 +1,322 @@ +/* + * Copyright 2008-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 sun.nio.ch; + +import java.nio.channels.spi.AsynchronousChannelProvider; +import java.io.IOException; +import java.util.concurrent.ArrayBlockingQueue; +import java.util.concurrent.RejectedExecutionException; +import java.util.concurrent.atomic.AtomicInteger; +import static sun.nio.ch.EPoll.*; + +/** + * AsynchronousChannelGroup implementation based on the Linux epoll facility. + */ + +final class EPollPort + extends Port +{ + // maximum number of events to poll at a time + private static final int MAX_EPOLL_EVENTS = 512; + + // errors + private static final int ENOENT = 2; + + // epoll file descriptor + private final int epfd; + + // true if epoll closed + private boolean closed; + + // socket pair used for wakeup + private final int sp[]; + + // number of wakeups pending + private final AtomicInteger wakeupCount = new AtomicInteger(); + + // address of the poll array passed to epoll_wait + private final long address; + + // encapsulates an event for a channel + static class Event { + final PollableChannel channel; + final int events; + + Event(PollableChannel channel, int events) { + this.channel = channel; + this.events = events; + } + + PollableChannel channel() { return channel; } + int events() { return events; } + } + + // queue of events for cases that a polling thread dequeues more than one + // event + private final ArrayBlockingQueue<Event> queue; + private final Event NEED_TO_POLL = new Event(null, 0); + private final Event EXECUTE_TASK_OR_SHUTDOWN = new Event(null, 0); + + EPollPort(AsynchronousChannelProvider provider, ThreadPool pool) + throws IOException + { + super(provider, pool); + + // open epoll + this.epfd = epollCreate(); + + // create socket pair for wakeup mechanism + int[] sv = new int[2]; + try { + socketpair(sv); + // register one end with epoll + epollCtl(epfd, EPOLL_CTL_ADD, sv[0], POLLIN); + } catch (IOException x) { + close0(epfd); + throw x; + } + this.sp = sv; + + // allocate the poll array + this.address = allocatePollArray(MAX_EPOLL_EVENTS); + + // create the queue and offer the special event to ensure that the first + // threads polls + this.queue = new ArrayBlockingQueue<Event>(MAX_EPOLL_EVENTS); + this.queue.offer(NEED_TO_POLL); + } + + EPollPort start() { + startThreads(new EventHandlerTask()); + return this; + } + + /** + * Release all resources + */ + private void implClose() { + synchronized (this) { + if (closed) + return; + closed = true; + } + freePollArray(address); + close0(sp[0]); + close0(sp[1]); + close0(epfd); + } + + private void wakeup() { + if (wakeupCount.incrementAndGet() == 1) { + // write byte to socketpair to force wakeup + try { + interrupt(sp[1]); + } catch (IOException x) { + throw new AssertionError(x); + } + } + } + + @Override + void executeOnHandlerTask(Runnable task) { + synchronized (this) { + if (closed) + throw new RejectedExecutionException(); + offerTask(task); + wakeup(); + } + } + + @Override + void shutdownHandlerTasks() { + /* + * If no tasks are running then just release resources; otherwise + * write to the one end of the socketpair to wakeup any polling threads. + */ + int nThreads = threadCount(); + if (nThreads == 0) { + implClose(); + } else { + // send interrupt to each thread + while (nThreads-- > 0) { + wakeup(); + } + } + } + + // invoke by clients to register a file descriptor + @Override + void startPoll(int fd, int events) { + // update events (or add to epoll on first usage) + int err = epollCtl(epfd, EPOLL_CTL_MOD, fd, (events | EPOLLONESHOT)); + if (err == ENOENT) + err = epollCtl(epfd, EPOLL_CTL_ADD, fd, (events | EPOLLONESHOT)); + if (err != 0) + throw new AssertionError(); // should not happen + } + + /* + * Task to process events from epoll and dispatch to the channel's + * onEvent handler. + * + * Events are retreived from epoll in batch and offered to a BlockingQueue + * where they are consumed by handler threads. A special "NEED_TO_POLL" + * event is used to signal one consumer to re-poll when all events have + * been consumed. + */ + private class EventHandlerTask implements Runnable { + private Event poll() throws IOException { + try { + for (;;) { + int n = epollWait(epfd, address, MAX_EPOLL_EVENTS); + /* + * 'n' events have been read. Here we map them to their + * corresponding channel in batch and queue n-1 so that + * they can be handled by other handler threads. The last + * event is handled by this thread (and so is not queued). + */ + fdToChannelLock.readLock().lock(); + try { + while (n-- > 0) { + long eventAddress = getEvent(address, n); + int fd = getDescriptor(eventAddress); + + // wakeup + if (fd == sp[0]) { + if (wakeupCount.decrementAndGet() == 0) { + // no more wakeups so drain pipe + drain1(sp[0]); + } + + // queue special event if there are more events + // to handle. + if (n > 0) { + queue.offer(EXECUTE_TASK_OR_SHUTDOWN); + continue; + } + return EXECUTE_TASK_OR_SHUTDOWN; + } + + PollableChannel channel = fdToChannel.get(fd); + if (channel != null) { + int events = getEvents(eventAddress); + Event ev = new Event(channel, events); + + // n-1 events are queued; This thread handles + // the last one except for the wakeup + if (n > 0) { + queue.offer(ev); + } else { + return ev; + } + } + } + } finally { + fdToChannelLock.readLock().unlock(); + } + } + } finally { + // to ensure that some thread will poll when all events have + // been consumed + queue.offer(NEED_TO_POLL); + } + } + + public void run() { + Invoker.GroupAndInvokeCount myGroupAndInvokeCount = + Invoker.getGroupAndInvokeCount(); + boolean replaceMe = false; + Event ev; + try { + for (;;) { + // reset invoke count + if (myGroupAndInvokeCount != null) + myGroupAndInvokeCount.resetInvokeCount(); + + try { + replaceMe = false; + ev = queue.take(); + + // no events and this thread has been "selected" to + // poll for more. + if (ev == NEED_TO_POLL) { + try { + ev = poll(); + } catch (IOException x) { + x.printStackTrace(); + return; + } + } + } catch (InterruptedException x) { + continue; + } + + // handle wakeup to execute task or shutdown + if (ev == EXECUTE_TASK_OR_SHUTDOWN) { + Runnable task = pollTask(); + if (task == null) { + // shutdown request + return; + } + // run task (may throw error/exception) + replaceMe = true; + task.run(); + continue; + } + + // process event + try { + ev.channel().onEvent(ev.events()); + } catch (Error x) { + replaceMe = true; throw x; + } catch (RuntimeException x) { + replaceMe = true; throw x; + } + } + } finally { + // last handler to exit when shutdown releases resources + int remaining = threadExit(this, replaceMe); + if (remaining == 0 && isShutdown()) { + implClose(); + } + } + } + } + + // -- Native methods -- + + private static native void socketpair(int[] sv) throws IOException; + + private static native void interrupt(int fd) throws IOException; + + private static native void drain1(int fd) throws IOException; + + private static native void close0(int fd); + + static { + Util.load(); + } +} diff --git a/src/solaris/classes/sun/nio/ch/EPollSelectorImpl.java b/src/solaris/classes/sun/nio/ch/EPollSelectorImpl.java index 5dc17bb014ca1d1717e79959f135b7cd4f36421a..505d8b7bb4ef961ea9852a5600f7ac44680844b7 100644 --- a/src/solaris/classes/sun/nio/ch/EPollSelectorImpl.java +++ b/src/solaris/classes/sun/nio/ch/EPollSelectorImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2005-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 @@ -136,10 +136,9 @@ class EPollSelectorImpl interruptTriggered = true; } - FileDispatcher.closeIntFD(fd0); - FileDispatcher.closeIntFD(fd1); + FileDispatcherImpl.closeIntFD(fd0); + FileDispatcherImpl.closeIntFD(fd1); - pollWrapper.release(fd0); pollWrapper.closeEPollFD(); // it is possible selectedKeys = null; @@ -162,17 +161,18 @@ class EPollSelectorImpl protected void implRegister(SelectionKeyImpl ski) { if (closed) throw new ClosedSelectorException(); - int fd = IOUtil.fdVal(ski.channel.getFD()); - fdToKey.put(Integer.valueOf(fd), ski); - pollWrapper.add(fd); + SelChImpl ch = ski.channel; + fdToKey.put(Integer.valueOf(ch.getFDVal()), ski); + pollWrapper.add(ch); keys.add(ski); } protected void implDereg(SelectionKeyImpl ski) throws IOException { assert (ski.getIndex() >= 0); - int fd = ski.channel.getFDVal(); + SelChImpl ch = ski.channel; + int fd = ch.getFDVal(); fdToKey.remove(Integer.valueOf(fd)); - pollWrapper.release(fd); + pollWrapper.release(ch); ski.setIndex(-1); keys.remove(ski); selectedKeys.remove(ski); @@ -185,8 +185,7 @@ class EPollSelectorImpl void putEventOps(SelectionKeyImpl sk, int ops) { if (closed) throw new ClosedSelectorException(); - int fd = IOUtil.fdVal(sk.channel.getFD()); - pollWrapper.setInterest(fd, ops); + pollWrapper.setInterest(sk.channel, ops); } public Selector wakeup() { diff --git a/src/solaris/classes/sun/nio/ch/FileDispatcher.java b/src/solaris/classes/sun/nio/ch/FileDispatcherImpl.java similarity index 72% rename from src/solaris/classes/sun/nio/ch/FileDispatcher.java rename to src/solaris/classes/sun/nio/ch/FileDispatcherImpl.java index 335ac49b951cfa8ae43fc8aa9a7939f154cf8e05..34d3451bb2031544d03119db3470ed8509f5230b 100644 --- a/src/solaris/classes/sun/nio/ch/FileDispatcher.java +++ b/src/solaris/classes/sun/nio/ch/FileDispatcherImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2002 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. * * This code is free software; you can redistribute it and/or modify it @@ -27,12 +27,7 @@ package sun.nio.ch; import java.io.*; -/** - * Allows different platforms to call different native methods - * for read and write operations. - */ - -class FileDispatcher extends NativeDispatcher +class FileDispatcherImpl extends FileDispatcher { static { @@ -69,6 +64,28 @@ class FileDispatcher extends NativeDispatcher return writev0(fd, address, len); } + int force(FileDescriptor fd, boolean metaData) throws IOException { + return force0(fd, metaData); + } + + int truncate(FileDescriptor fd, long size) throws IOException { + return truncate0(fd, size); + } + + long size(FileDescriptor fd) throws IOException { + return size0(fd); + } + + int lock(FileDescriptor fd, boolean blocking, long pos, long size, + boolean shared) throws IOException + { + return lock0(fd, blocking, pos, size, shared); + } + + void release(FileDescriptor fd, long pos, long size) throws IOException { + release0(fd, pos, size); + } + void close(FileDescriptor fd) throws IOException { close0(fd); } @@ -97,6 +114,20 @@ class FileDispatcher extends NativeDispatcher static native long writev0(FileDescriptor fd, long address, int len) throws IOException; + static native int force0(FileDescriptor fd, boolean metaData) + throws IOException; + + static native int truncate0(FileDescriptor fd, long size) + throws IOException; + + static native long size0(FileDescriptor fd) throws IOException; + + static native int lock0(FileDescriptor fd, boolean blocking, long pos, + long size, boolean shared) throws IOException; + + static native void release0(FileDescriptor fd, long pos, long size) + throws IOException; + static native void close0(FileDescriptor fd) throws IOException; static native void preClose0(FileDescriptor fd) throws IOException; diff --git a/src/solaris/classes/sun/nio/ch/LinuxAsynchronousChannelProvider.java b/src/solaris/classes/sun/nio/ch/LinuxAsynchronousChannelProvider.java new file mode 100644 index 0000000000000000000000000000000000000000..775380e8bc621a44b9a097a71e982af75457d928 --- /dev/null +++ b/src/solaris/classes/sun/nio/ch/LinuxAsynchronousChannelProvider.java @@ -0,0 +1,99 @@ +/* + * Copyright 2008-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 sun.nio.ch; + +import java.nio.channels.*; +import java.nio.channels.spi.AsynchronousChannelProvider; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.ThreadFactory; +import java.net.ProtocolFamily; +import java.io.IOException; + +public class LinuxAsynchronousChannelProvider + extends AsynchronousChannelProvider +{ + private static volatile EPollPort defaultPort; + + private EPollPort defaultEventPort() throws IOException { + if (defaultPort == null) { + synchronized (LinuxAsynchronousChannelProvider.class) { + if (defaultPort == null) { + defaultPort = new EPollPort(this, ThreadPool.getDefault()).start(); + } + } + } + return defaultPort; + } + + public LinuxAsynchronousChannelProvider() { + } + + @Override + public AsynchronousChannelGroup openAsynchronousChannelGroup(int nThreads, ThreadFactory factory) + throws IOException + { + return new EPollPort(this, ThreadPool.create(nThreads, factory)).start(); + } + + @Override + public AsynchronousChannelGroup openAsynchronousChannelGroup(ExecutorService executor, int initialSize) + throws IOException + { + return new EPollPort(this, ThreadPool.wrap(executor, initialSize)).start(); + } + + private Port toPort(AsynchronousChannelGroup group) throws IOException { + if (group == null) { + return defaultEventPort(); + } else { + if (!(group instanceof EPollPort)) + throw new IllegalChannelGroupException(); + return (Port)group; + } + } + + @Override + public AsynchronousServerSocketChannel openAsynchronousServerSocketChannel(AsynchronousChannelGroup group) + throws IOException + { + return new UnixAsynchronousServerSocketChannelImpl(toPort(group)); + } + + @Override + public AsynchronousSocketChannel openAsynchronousSocketChannel(AsynchronousChannelGroup group) + throws IOException + { + return new UnixAsynchronousSocketChannelImpl(toPort(group)); + } + + @Override + public AsynchronousDatagramChannel openAsynchronousDatagramChannel(ProtocolFamily family, + AsynchronousChannelGroup group) + throws IOException + { + return new SimpleAsynchronousDatagramChannelImpl(family, toPort(group)); + } +} diff --git a/src/solaris/classes/sun/nio/ch/PollSelectorImpl.java b/src/solaris/classes/sun/nio/ch/PollSelectorImpl.java index ab135c9b105a4a5c2abe5f863247b161bd6ec645..05fbda57d97a45c5e39c82dc3ff68218102b5162 100644 --- a/src/solaris/classes/sun/nio/ch/PollSelectorImpl.java +++ b/src/solaris/classes/sun/nio/ch/PollSelectorImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2001-2007 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2001-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 @@ -93,8 +93,8 @@ class PollSelectorImpl synchronized (interruptLock) { interruptTriggered = true; } - FileDispatcher.closeIntFD(fd0); - FileDispatcher.closeIntFD(fd1); + FileDispatcherImpl.closeIntFD(fd0); + FileDispatcherImpl.closeIntFD(fd1); fd0 = -1; fd1 = -1; pollWrapper.release(0); diff --git a/src/solaris/classes/sun/nio/ch/Port.java b/src/solaris/classes/sun/nio/ch/Port.java new file mode 100644 index 0000000000000000000000000000000000000000..8b19637bc2a2608452c91591fb8eb1540e6b5fc2 --- /dev/null +++ b/src/solaris/classes/sun/nio/ch/Port.java @@ -0,0 +1,168 @@ +/* + * Copyright 2008-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 sun.nio.ch; + +import java.nio.channels.spi.AsynchronousChannelProvider; +import java.nio.channels.*; +import java.io.IOException; +import java.io.Closeable; +import java.io.FileDescriptor; +import java.util.Map; +import java.util.HashMap; +import java.util.concurrent.locks.ReadWriteLock; +import java.util.concurrent.locks.ReentrantReadWriteLock; + +/** + * Base implementation of AsynchronousChannelGroupImpl for Unix systems. + */ + +abstract class Port extends AsynchronousChannelGroupImpl { + static final short POLLIN = 0x0001; + static final short POLLOUT = 0x0004; + static final short POLLERR = 0x0008; + static final short POLLHUP = 0x0010; + + /** + * Implemented by clients registered with this port. + */ + interface PollableChannel extends Closeable { + void onEvent(int events); + } + + // maps fd to "pollable" channel + protected final ReadWriteLock fdToChannelLock = new ReentrantReadWriteLock(); + protected final Map<Integer,PollableChannel> fdToChannel = + new HashMap<Integer,PollableChannel>(); + + + Port(AsynchronousChannelProvider provider, ThreadPool pool) { + super(provider, pool); + } + + /** + * Register channel identified by its file descriptor + */ + final void register(int fd, PollableChannel ch) { + fdToChannelLock.writeLock().lock(); + try { + if (isShutdown()) + throw new ShutdownChannelGroupException(); + fdToChannel.put(Integer.valueOf(fd), ch); + } finally { + fdToChannelLock.writeLock().unlock(); + } + } + + /** + * Unregister channel identified by its file descriptor + */ + final void unregister(int fd) { + boolean checkForShutdown = false; + + fdToChannelLock.writeLock().lock(); + try { + fdToChannel.remove(Integer.valueOf(fd)); + + // last key to be removed so check if group is shutdown + if (fdToChannel.isEmpty()) + checkForShutdown = true; + + } finally { + fdToChannelLock.writeLock().unlock(); + } + + // continue shutdown + if (checkForShutdown && isShutdown()) { + try { + shutdownNow(); + } catch (IOException ignore) { } + } + } + /** + * Register file descriptor with polling mechanism for given events. + * The implementation should translate the events as required. + */ + abstract void startPoll(int fd, int events); + + @Override + final boolean isEmpty() { + fdToChannelLock.writeLock().lock(); + try { + return fdToChannel.isEmpty(); + } finally { + fdToChannelLock.writeLock().unlock(); + } + } + + @Override + final Object attachForeignChannel(final Channel channel, FileDescriptor fd) { + int fdVal = IOUtil.fdVal(fd); + register(fdVal, new PollableChannel() { + public void onEvent(int events) { } + public void close() throws IOException { + channel.close(); + } + }); + return Integer.valueOf(fdVal); + } + + @Override + final void detachForeignChannel(Object key) { + unregister((Integer)key); + } + + @Override + final void closeAllChannels() { + /** + * Close channels in batches of up to 128 channels. This allows close + * to remove the channel from the map without interference. + */ + final int MAX_BATCH_SIZE = 128; + PollableChannel channels[] = new PollableChannel[MAX_BATCH_SIZE]; + int count; + do { + // grab a batch of up to 128 channels + fdToChannelLock.writeLock().lock(); + count = 0; + try { + for (Integer fd: fdToChannel.keySet()) { + channels[count++] = fdToChannel.get(fd); + if (count >= MAX_BATCH_SIZE) + break; + } + } finally { + fdToChannelLock.writeLock().unlock(); + } + + // close them + for (int i=0; i<count; i++) { + try { + channels[i].close(); + } catch (IOException ignore) { } + } + } while (count > 0); + } +} diff --git a/src/solaris/classes/sun/nio/ch/SinkChannelImpl.java b/src/solaris/classes/sun/nio/ch/SinkChannelImpl.java index bc58ba9ab3c813c61be4958ca86c69ad5e485a46..ced3b608e776a52e00809db4b5b986323bd2aa8f 100644 --- a/src/solaris/classes/sun/nio/ch/SinkChannelImpl.java +++ b/src/solaris/classes/sun/nio/ch/SinkChannelImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2006 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. * * This code is free software; you can redistribute it and/or modify it @@ -208,7 +208,7 @@ class SinkChannelImpl static { Util.load(); - nd = new FileDispatcher(); + nd = new FileDispatcherImpl(); } } diff --git a/src/solaris/classes/sun/nio/ch/SocketDispatcher.java b/src/solaris/classes/sun/nio/ch/SocketDispatcher.java index 46c8e135e02bd4f7ad37b5dac2fb61bd64097083..fc884c4c9a0623c708cc2e553577a96cb6310496 100644 --- a/src/solaris/classes/sun/nio/ch/SocketDispatcher.java +++ b/src/solaris/classes/sun/nio/ch/SocketDispatcher.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2005 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. * * This code is free software; you can redistribute it and/or modify it @@ -36,26 +36,26 @@ class SocketDispatcher extends NativeDispatcher { int read(FileDescriptor fd, long address, int len) throws IOException { - return FileDispatcher.read0(fd, address, len); + return FileDispatcherImpl.read0(fd, address, len); } long readv(FileDescriptor fd, long address, int len) throws IOException { - return FileDispatcher.readv0(fd, address, len); + return FileDispatcherImpl.readv0(fd, address, len); } int write(FileDescriptor fd, long address, int len) throws IOException { - return FileDispatcher.write0(fd, address, len); + return FileDispatcherImpl.write0(fd, address, len); } long writev(FileDescriptor fd, long address, int len) throws IOException { - return FileDispatcher.writev0(fd, address, len); + return FileDispatcherImpl.writev0(fd, address, len); } void close(FileDescriptor fd) throws IOException { - FileDispatcher.close0(fd); + FileDispatcherImpl.close0(fd); } void preClose(FileDescriptor fd) throws IOException { - FileDispatcher.preClose0(fd); + FileDispatcherImpl.preClose0(fd); } } diff --git a/src/solaris/classes/sun/nio/ch/SolarisAsynchronousChannelProvider.java b/src/solaris/classes/sun/nio/ch/SolarisAsynchronousChannelProvider.java new file mode 100644 index 0000000000000000000000000000000000000000..0da0935cac7874647680b16889a1e32d46961fff --- /dev/null +++ b/src/solaris/classes/sun/nio/ch/SolarisAsynchronousChannelProvider.java @@ -0,0 +1,102 @@ +/* + * Copyright 2008-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 sun.nio.ch; + +import java.nio.channels.*; +import java.nio.channels.spi.AsynchronousChannelProvider; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.ThreadFactory; +import java.net.ProtocolFamily; +import java.io.IOException; + +public class SolarisAsynchronousChannelProvider + extends AsynchronousChannelProvider +{ + private static volatile SolarisEventPort defaultEventPort; + + private SolarisEventPort defaultEventPort() throws IOException { + if (defaultEventPort == null) { + synchronized (SolarisAsynchronousChannelProvider.class) { + if (defaultEventPort == null) { + defaultEventPort = + new SolarisEventPort(this, ThreadPool.getDefault()).start(); + } + } + } + return defaultEventPort; + } + + public SolarisAsynchronousChannelProvider() { + } + + @Override + public AsynchronousChannelGroup openAsynchronousChannelGroup(int nThreads, ThreadFactory factory) + throws IOException + { + return new SolarisEventPort(this, ThreadPool.create(nThreads, factory)).start(); + } + + @Override + public AsynchronousChannelGroup openAsynchronousChannelGroup(ExecutorService executor, int initialSize) + throws IOException + { + return new SolarisEventPort(this, ThreadPool.wrap(executor, initialSize)).start(); + } + + private SolarisEventPort toEventPort(AsynchronousChannelGroup group) + throws IOException + { + if (group == null) { + return defaultEventPort(); + } else { + if (!(group instanceof SolarisEventPort)) + throw new IllegalChannelGroupException(); + return (SolarisEventPort)group; + } + } + + @Override + public AsynchronousServerSocketChannel openAsynchronousServerSocketChannel(AsynchronousChannelGroup group) + throws IOException + { + return new UnixAsynchronousServerSocketChannelImpl(toEventPort(group)); + } + + @Override + public AsynchronousSocketChannel openAsynchronousSocketChannel(AsynchronousChannelGroup group) + throws IOException + { + return new UnixAsynchronousSocketChannelImpl(toEventPort(group)); + } + + @Override + public AsynchronousDatagramChannel openAsynchronousDatagramChannel(ProtocolFamily family, + AsynchronousChannelGroup group) + throws IOException + { + return new SimpleAsynchronousDatagramChannelImpl(family, toEventPort(group)); + } +} diff --git a/src/solaris/classes/sun/nio/ch/SolarisEventPort.java b/src/solaris/classes/sun/nio/ch/SolarisEventPort.java new file mode 100644 index 0000000000000000000000000000000000000000..908eecce02420fe654ae2d01ae13a9630c708249 --- /dev/null +++ b/src/solaris/classes/sun/nio/ch/SolarisEventPort.java @@ -0,0 +1,244 @@ +/* + * Copyright 2008-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 sun.nio.ch; + +import java.nio.channels.spi.AsynchronousChannelProvider; +import java.util.concurrent.RejectedExecutionException; +import java.io.IOException; +import sun.misc.Unsafe; + +/** + * AsynchronousChannelGroup implementation based on the Solaris 10 event port + * framework. + */ + +class SolarisEventPort + extends Port +{ + private static final Unsafe unsafe = Unsafe.getUnsafe(); + private static final int addressSize = unsafe.addressSize(); + + private static int dependsArch(int value32, int value64) { + return (addressSize == 4) ? value32 : value64; + } + + /* + * typedef struct port_event { + * int portev_events; + * ushort_t portev_source; + * ushort_t portev_pad; + * uintptr_t portev_object; + * void *portev_user; + * } port_event_t; + */ + private static final int SIZEOF_PORT_EVENT = dependsArch(16, 24); + private static final int OFFSETOF_EVENTS = 0; + private static final int OFFSETOF_SOURCE = 4; + private static final int OFFSETOF_OBJECT = 8; + + // port sources + private static final short PORT_SOURCE_USER = 3; + private static final short PORT_SOURCE_FD = 4; + + // file descriptor to event port. + private final int port; + + // true when port is closed + private boolean closed; + + SolarisEventPort(AsynchronousChannelProvider provider, ThreadPool pool) + throws IOException + { + super(provider, pool); + + // create event port + this.port = portCreate(); + } + + SolarisEventPort start() { + startThreads(new EventHandlerTask()); + return this; + } + + // releass resources + private void implClose() { + synchronized (this) { + if (closed) + return; + closed = true; + } + portClose(port); + } + + private void wakeup() { + try { + portSend(port, 0); + } catch (IOException x) { + throw new AssertionError(x); + } + } + + @Override + void executeOnHandlerTask(Runnable task) { + synchronized (this) { + if (closed) + throw new RejectedExecutionException(); + offerTask(task); + wakeup(); + } + } + + @Override + void shutdownHandlerTasks() { + /* + * If no tasks are running then just release resources; otherwise + * write to the one end of the socketpair to wakeup any polling threads.. + */ + int nThreads = threadCount(); + if (nThreads == 0) { + implClose(); + } else { + // send user event to wakeup each thread + while (nThreads-- > 0) { + try { + portSend(port, 0); + } catch (IOException x) { + throw new AssertionError(x); + } + } + } + } + + @Override + void startPoll(int fd, int events) { + // (re-)associate file descriptor + // no need to translate events + try { + portAssociate(port, PORT_SOURCE_FD, fd, events); + } catch (IOException x) { + throw new AssertionError(); // should not happen + } + } + + /* + * Task to read a single event from the port and dispatch it to the + * channel's onEvent handler. + */ + private class EventHandlerTask implements Runnable { + public void run() { + Invoker.GroupAndInvokeCount myGroupAndInvokeCount = + Invoker.getGroupAndInvokeCount(); + boolean replaceMe = false; + long address = unsafe.allocateMemory(SIZEOF_PORT_EVENT); + try { + for (;;) { + // reset invoke count + if (myGroupAndInvokeCount != null) + myGroupAndInvokeCount.resetInvokeCount(); + + // wait for I/O completion event + // A error here is fatal (thread will not be replaced) + replaceMe = false; + try { + portGet(port, address); + } catch (IOException x) { + x.printStackTrace(); + return; + } + + // event source + short source = unsafe.getShort(address + OFFSETOF_SOURCE); + if (source != PORT_SOURCE_FD) { + // user event is trigger to invoke task or shutdown + if (source == PORT_SOURCE_USER) { + Runnable task = pollTask(); + if (task == null) { + // shutdown request + return; + } + // run task (may throw error/exception) + replaceMe = true; + task.run(); + } + // ignore + continue; + } + + // pe->portev_object is file descriptor + int fd = (int)unsafe.getAddress(address + OFFSETOF_OBJECT); + // pe->portev_events + int events = unsafe.getInt(address + OFFSETOF_EVENTS); + + // lookup channel + PollableChannel ch; + fdToChannelLock.readLock().lock(); + try { + ch = fdToChannel.get(fd); + } finally { + fdToChannelLock.readLock().unlock(); + } + + // notify channel + if (ch != null) { + replaceMe = true; + // no need to translate events + ch.onEvent(events); + } + } + } finally { + // free per-thread resources + unsafe.freeMemory(address); + // last task to exit when shutdown release resources + int remaining = threadExit(this, replaceMe); + if (remaining == 0 && isShutdown()) + implClose(); + } + } + } + + // -- Native methods -- + + private static native void init(); + + private static native int portCreate() throws IOException; + + private static native void portAssociate(int port, int source, long object, + int events) throws IOException; + + private static native void portGet(int port, long pe) throws IOException; + + private static native int portGetn(int port, long address, int max) + throws IOException; + + private static native void portSend(int port, int events) throws IOException; + + private static native void portClose(int port); + + static { + Util.load(); + init(); + } +} diff --git a/src/solaris/classes/sun/nio/ch/SourceChannelImpl.java b/src/solaris/classes/sun/nio/ch/SourceChannelImpl.java index a55543e923e78c02bc9519538be7c557b41d5bd0..e1080c917d1db93418c3e491a41e543934c4bcbd 100644 --- a/src/solaris/classes/sun/nio/ch/SourceChannelImpl.java +++ b/src/solaris/classes/sun/nio/ch/SourceChannelImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2006 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. * * This code is free software; you can redistribute it and/or modify it @@ -208,7 +208,7 @@ class SourceChannelImpl static { Util.load(); - nd = new FileDispatcher(); + nd = new FileDispatcherImpl(); } } diff --git a/src/solaris/classes/sun/nio/ch/UnixAsynchronousServerSocketChannelImpl.java b/src/solaris/classes/sun/nio/ch/UnixAsynchronousServerSocketChannelImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..1a8c92352d2406f3d8db22c419ebe7ce38a381c7 --- /dev/null +++ b/src/solaris/classes/sun/nio/ch/UnixAsynchronousServerSocketChannelImpl.java @@ -0,0 +1,327 @@ +/* + * Copyright 2008-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 sun.nio.ch; + +import java.nio.channels.*; +import java.util.concurrent.*; +import java.io.IOException; +import java.io.FileDescriptor; +import java.net.InetSocketAddress; +import java.util.concurrent.atomic.AtomicBoolean; +import java.security.AccessControlContext; +import java.security.AccessController; +import java.security.PrivilegedAction; + +/** + * Unix implementation of AsynchronousServerSocketChannel + */ + +class UnixAsynchronousServerSocketChannelImpl + extends AsynchronousServerSocketChannelImpl + implements Port.PollableChannel +{ + private final static NativeDispatcher nd = new SocketDispatcher(); + + private final Port port; + private final int fdVal; + + // flag to indicate an accept is outstanding + private final AtomicBoolean accepting = new AtomicBoolean(); + private void enableAccept() { + accepting.set(false); + } + + // used to ensure that the context for an asynchronous accept is visible + // the pooled thread that handles the I/O event + private final Object updateLock = new Object(); + + // pending accept + private PendingFuture<AsynchronousSocketChannel,Object> pendingAccept; + + // context for permission check when security manager set + private AccessControlContext acc; + + + UnixAsynchronousServerSocketChannelImpl(Port port) + throws IOException + { + super(port); + + try { + IOUtil.configureBlocking(fd, false); + } catch (IOException x) { + nd.close(fd); // prevent leak + throw x; + } + this.port = port; + this.fdVal = IOUtil.fdVal(fd); + + // add mapping from file descriptor to this channel + port.register(fdVal, this); + } + + // returns and clears the result of a pending accept + private PendingFuture<AsynchronousSocketChannel,Object> grabPendingAccept() { + synchronized (updateLock) { + PendingFuture<AsynchronousSocketChannel,Object> result = pendingAccept; + pendingAccept = null; + return result; + } + } + + @Override + void implClose() throws IOException { + // remove the mapping + port.unregister(fdVal); + + // close file descriptor + nd.close(fd); + + // if there is a pending accept then complete it + final PendingFuture<AsynchronousSocketChannel,Object> result = + grabPendingAccept(); + if (result != null) { + // discard the stack trace as otherwise it may appear that implClose + // has thrown the exception. + AsynchronousCloseException x = new AsynchronousCloseException(); + x.setStackTrace(new StackTraceElement[0]); + result.setFailure(x); + + // invoke by submitting task rather than directly + Invoker.invokeIndirectly(result.handler(), result); + } + } + + @Override + public AsynchronousChannelGroupImpl group() { + return port; + } + + /** + * Invoked by event handling thread when listener socket is polled + */ + @Override + public void onEvent(int events) { + PendingFuture<AsynchronousSocketChannel,Object> result = grabPendingAccept(); + if (result == null) + return; // may have been grabbed by asynchronous close + + // attempt to accept connection + FileDescriptor newfd = new FileDescriptor(); + InetSocketAddress[] isaa = new InetSocketAddress[1]; + boolean accepted = false; + try { + begin(); + int n = accept0(this.fd, newfd, isaa); + + // spurious wakeup, is this possible? + if (n == IOStatus.UNAVAILABLE) { + synchronized (updateLock) { + this.pendingAccept = result; + } + port.startPoll(fdVal, Port.POLLIN); + return; + } + + // connection accepted + accepted = true; + + } catch (Throwable x) { + if (x instanceof ClosedChannelException) + x = new AsynchronousCloseException(); + enableAccept(); + result.setFailure(x); + } finally { + end(); + } + + // Connection accepted so finish it when not holding locks. + AsynchronousSocketChannel child = null; + if (accepted) { + try { + child = finishAccept(newfd, isaa[0], acc); + enableAccept(); + result.setResult(child); + } catch (Throwable x) { + enableAccept(); + if (!(x instanceof IOException) && !(x instanceof SecurityException)) + x = new IOException(x); + result.setFailure(x); + } + } + + // if an async cancel has already cancelled the operation then + // close the new channel so as to free resources + if (child != null && result.isCancelled()) { + try { + child.close(); + } catch (IOException ignore) { } + } + + // invoke the handler + Invoker.invoke(result.handler(), result); + } + + /** + * Completes the accept by creating the AsynchronousSocketChannel for + * the given file descriptor and remote address. If this method completes + * with an IOException or SecurityException then the channel/file descriptor + * will be closed. + */ + private AsynchronousSocketChannel finishAccept(FileDescriptor newfd, + final InetSocketAddress remote, + AccessControlContext acc) + throws IOException, SecurityException + { + AsynchronousSocketChannel ch = null; + try { + ch = new UnixAsynchronousSocketChannelImpl(port, newfd, remote); + } catch (IOException x) { + nd.close(newfd); + throw x; + } + + // permission check must always be in initiator's context + try { + if (acc != null) { + AccessController.doPrivileged(new PrivilegedAction<Void>() { + public Void run() { + SecurityManager sm = System.getSecurityManager(); + if (sm != null) { + sm.checkAccept(remote.getAddress().getHostAddress(), + remote.getPort()); + } + return null; + } + }, acc); + } else { + SecurityManager sm = System.getSecurityManager(); + if (sm != null) { + sm.checkAccept(remote.getAddress().getHostAddress(), + remote.getPort()); + } + } + } catch (SecurityException x) { + try { + ch.close(); + } catch (IOException ignore) { } + throw x; + } + return ch; + } + + @Override + @SuppressWarnings("unchecked") + public <A> Future<AsynchronousSocketChannel> accept(A attachment, + final CompletionHandler<AsynchronousSocketChannel,? super A> handler) + { + // complete immediately if channel is closed + if (!isOpen()) { + CompletedFuture<AsynchronousSocketChannel,A> result = CompletedFuture + .withFailure(this, new ClosedChannelException(), attachment); + Invoker.invokeIndirectly(handler, result); + return result; + } + if (localAddress == null) + throw new NotYetBoundException(); + + // cancel was invoked with pending accept so connection may have been + // dropped. + if (isAcceptKilled()) + throw new RuntimeException("Accept not allowed due cancellation"); + + // check and set flag to prevent concurrent accepting + if (!accepting.compareAndSet(false, true)) + throw new AcceptPendingException(); + + // attempt accept + AbstractFuture<AsynchronousSocketChannel,A> result = null; + FileDescriptor newfd = new FileDescriptor(); + InetSocketAddress[] isaa = new InetSocketAddress[1]; + try { + begin(); + + int n = accept0(this.fd, newfd, isaa); + if (n == IOStatus.UNAVAILABLE) { + // no connection to accept + result = new PendingFuture<AsynchronousSocketChannel,A>(this, handler, attachment); + + // need calling context when there is security manager as + // permission check may be done in a different thread without + // any application call frames on the stack + synchronized (this) { + this.acc = (System.getSecurityManager() == null) ? + null : AccessController.getContext(); + this.pendingAccept = + (PendingFuture<AsynchronousSocketChannel,Object>)result; + } + + // register for connections + port.startPoll(fdVal, Port.POLLIN); + return result; + } + } catch (Throwable x) { + // accept failed + if (x instanceof ClosedChannelException) + x = new AsynchronousCloseException(); + result = CompletedFuture.withFailure(this, x, attachment); + } finally { + end(); + } + + // connection accepted immediately + if (result == null) { + try { + AsynchronousSocketChannel ch = finishAccept(newfd, isaa[0], null); + result = CompletedFuture.withResult(this, ch, attachment); + } catch (Throwable x) { + result = CompletedFuture.withFailure(this, x, attachment); + } + } + + // re-enable accepting and invoke handler + enableAccept(); + Invoker.invokeIndirectly(handler, result); + return result; + } + + // -- Native methods -- + + private static native void initIDs(); + + // Accepts a new connection, setting the given file descriptor to refer to + // the new socket and setting isaa[0] to the socket's remote address. + // Returns 1 on success, or IOStatus.UNAVAILABLE. + // + private native int accept0(FileDescriptor ssfd, FileDescriptor newfd, + InetSocketAddress[] isaa) + throws IOException; + + static { + Util.load(); + initIDs(); + } +} diff --git a/src/solaris/classes/sun/nio/ch/UnixAsynchronousSocketChannelImpl.java b/src/solaris/classes/sun/nio/ch/UnixAsynchronousSocketChannelImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..e80f202bdff96c2324a63f36d4d82bedc1faab9c --- /dev/null +++ b/src/solaris/classes/sun/nio/ch/UnixAsynchronousSocketChannelImpl.java @@ -0,0 +1,679 @@ +/* + * Copyright 2008-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 sun.nio.ch; + +import java.nio.channels.*; +import java.nio.ByteBuffer; +import java.net.*; +import java.util.concurrent.*; +import java.io.IOException; +import java.io.FileDescriptor; +import java.security.AccessController; +import sun.net.NetHooks; +import sun.security.action.GetPropertyAction; + +/** + * Unix implementation of AsynchronousSocketChannel + */ + +class UnixAsynchronousSocketChannelImpl + extends AsynchronousSocketChannelImpl implements Port.PollableChannel +{ + private final static NativeDispatcher nd = new SocketDispatcher(); + private static enum OpType { CONNECT, READ, WRITE }; + + private static final boolean disableSynchronousRead; + static { + String propValue = AccessController.doPrivileged( + new GetPropertyAction("sun.nio.ch.disableSynchronousRead", "false")); + disableSynchronousRead = (propValue.length() == 0) ? + true : Boolean.valueOf(propValue); + } + + private final Port port; + private final int fdVal; + + // used to ensure that the context for I/O operations that complete + // ascynrhonously is visible to the pooled threads handling I/O events. + private final Object updateLock = new Object(); + + // pending connect (updateLock) + private PendingFuture<Void,Object> pendingConnect; + + // pending remote address (statLock) + private SocketAddress pendingRemote; + + // pending read (updateLock) + private ByteBuffer[] readBuffers; + private boolean scatteringRead; + private PendingFuture<Number,Object> pendingRead; + + // pending write (updateLock) + private ByteBuffer[] writeBuffers; + private boolean gatheringWrite; + private PendingFuture<Number,Object> pendingWrite; + + + UnixAsynchronousSocketChannelImpl(Port port) + throws IOException + { + super(port); + + // set non-blocking + try { + IOUtil.configureBlocking(fd, false); + } catch (IOException x) { + nd.close(fd); + throw x; + } + + this.port = port; + this.fdVal = IOUtil.fdVal(fd); + + // add mapping from file descriptor to this channel + port.register(fdVal, this); + } + + // Constructor for sockets created by UnixAsynchronousServerSocketChannelImpl + UnixAsynchronousSocketChannelImpl(Port port, + FileDescriptor fd, + InetSocketAddress remote) + throws IOException + { + super(port, fd, remote); + + this.fdVal = IOUtil.fdVal(fd); + IOUtil.configureBlocking(fd, false); + + try { + port.register(fdVal, this); + } catch (ShutdownChannelGroupException x) { + // ShutdownChannelGroupException thrown if we attempt to register a + // new channel after the group is shutdown + throw new IOException(x); + } + + this.port = port; + } + + @Override + public AsynchronousChannelGroupImpl group() { + return port; + } + + // register for events if there are outstanding I/O operations + private void updateEvents() { + assert Thread.holdsLock(updateLock); + int events = 0; + if (pendingRead != null) + events |= Port.POLLIN; + if (pendingConnect != null || pendingWrite != null) + events |= Port.POLLOUT; + if (events != 0) + port.startPoll(fdVal, events); + } + + /** + * Invoked by event handler thread when file descriptor is polled + */ + @Override + public void onEvent(int events) { + boolean readable = (events & Port.POLLIN) > 0; + boolean writable = (events & Port.POLLOUT) > 0; + if ((events & (Port.POLLERR | Port.POLLHUP)) > 0) { + readable = true; + writable = true; + } + + PendingFuture<Void,Object> connectResult = null; + PendingFuture<Number,Object> readResult = null; + PendingFuture<Number,Object> writeResult = null; + + // map event to pending result + synchronized (updateLock) { + if (readable && (pendingRead != null)) { + readResult = pendingRead; + pendingRead = null; + } + if (writable) { + if (pendingWrite != null) { + writeResult = pendingWrite; + pendingWrite = null; + } else if (pendingConnect != null) { + connectResult = pendingConnect; + pendingConnect = null; + } + } + } + + // complete the I/O operation. Special case for when channel is + // ready for both reading and writing. In that case, submit task to + // complete write if write operation has a completion handler. + if (readResult != null) { + if (writeResult != null) + finishWrite(writeResult, false); + finishRead(readResult, true); + return; + } + if (writeResult != null) { + finishWrite(writeResult, true); + } + if (connectResult != null) { + finishConnect(connectResult, true); + } + } + + // returns and clears the result of a pending read + PendingFuture<Number,Object> grabPendingRead() { + synchronized (updateLock) { + PendingFuture<Number,Object> result = pendingRead; + pendingRead = null; + return result; + } + } + + // returns and clears the result of a pending write + PendingFuture<Number,Object> grabPendingWrite() { + synchronized (updateLock) { + PendingFuture<Number,Object> result = pendingWrite; + pendingWrite = null; + return result; + } + } + + @Override + void implClose() throws IOException { + // remove the mapping + port.unregister(fdVal); + + // close file descriptor + nd.close(fd); + + // All outstanding I/O operations are required to fail + final PendingFuture<Void,Object> readyToConnect; + final PendingFuture<Number,Object> readyToRead; + final PendingFuture<Number,Object> readyToWrite; + synchronized (updateLock) { + readyToConnect = pendingConnect; + pendingConnect = null; + readyToRead = pendingRead; + pendingRead = null; + readyToWrite = pendingWrite; + pendingWrite = null; + } + if (readyToConnect != null) { + finishConnect(readyToConnect, false); + } + if (readyToRead != null) { + finishRead(readyToRead, false); + } + if (readyToWrite != null) { + finishWrite(readyToWrite, false); + } + } + + @Override + public void onCancel(PendingFuture<?,?> task) { + if (task.getContext() == OpType.CONNECT) + killConnect(); + if (task.getContext() == OpType.READ) + killConnect(); + if (task.getContext() == OpType.WRITE) + killConnect(); + } + + // -- connect -- + + private void setConnected() throws IOException { + synchronized (stateLock) { + state = ST_CONNECTED; + localAddress = Net.localAddress(fd); + remoteAddress = pendingRemote; + } + } + + private void finishConnect(PendingFuture<Void,Object> result, + boolean invokeDirect) + { + Throwable e = null; + try { + begin(); + checkConnect(fdVal); + setConnected(); + result.setResult(null); + } catch (Throwable x) { + if (x instanceof ClosedChannelException) + x = new AsynchronousCloseException(); + e = x; + } finally { + end(); + } + if (e != null) { + // close channel if connection cannot be established + try { + close(); + } catch (IOException ignore) { } + result.setFailure(e); + } + if (invokeDirect) { + Invoker.invoke(result.handler(), result); + } else { + Invoker.invokeIndirectly(result.handler(), result); + } + } + + @Override + @SuppressWarnings("unchecked") + public <A> Future<Void> connect(SocketAddress remote, + A attachment, + CompletionHandler<Void,? super A> handler) + { + if (!isOpen()) { + CompletedFuture<Void,A> result = CompletedFuture + .withFailure(this, new ClosedChannelException(), attachment); + Invoker.invoke(handler, result); + return result; + } + + InetSocketAddress isa = Net.checkAddress(remote); + + // permission check + SecurityManager sm = System.getSecurityManager(); + if (sm != null) + sm.checkConnect(isa.getAddress().getHostAddress(), isa.getPort()); + + // check and set state + boolean notifyBeforeTcpConnect; + synchronized (stateLock) { + if (state == ST_CONNECTED) + throw new AlreadyConnectedException(); + if (state == ST_PENDING) + throw new ConnectionPendingException(); + state = ST_PENDING; + pendingRemote = remote; + notifyBeforeTcpConnect = (localAddress == null); + } + + AbstractFuture<Void,A> result = null; + Throwable e = null; + try { + begin(); + // notify hook if unbound + if (notifyBeforeTcpConnect) + NetHooks.beforeTcpConnect(fd, isa.getAddress(), isa.getPort()); + int n = Net.connect(fd, isa.getAddress(), isa.getPort()); + if (n == IOStatus.UNAVAILABLE) { + // connection could not be established immediately + result = new PendingFuture<Void,A>(this, handler, attachment, OpType.CONNECT); + synchronized (updateLock) { + this.pendingConnect = (PendingFuture<Void,Object>)result; + updateEvents(); + } + return result; + } + setConnected(); + result = CompletedFuture.withResult(this, null, attachment); + } catch (Throwable x) { + if (x instanceof ClosedChannelException) + x = new AsynchronousCloseException(); + e = x; + } finally { + end(); + } + + // close channel if connect fails + if (e != null) { + try { + close(); + } catch (IOException ignore) { } + result = CompletedFuture.withFailure(this, e, attachment); + } + + Invoker.invoke(handler, result); + return result; + } + + // -- read -- + + @SuppressWarnings("unchecked") + private void finishRead(PendingFuture<Number,Object> result, + boolean invokeDirect) + { + int n = -1; + PendingFuture<Number,Object> pending = null; + try { + begin(); + + ByteBuffer[] dsts = readBuffers; + if (dsts.length == 1) { + n = IOUtil.read(fd, dsts[0], -1, nd, null); + } else { + n = (int)IOUtil.read(fd, dsts, nd); + } + if (n == IOStatus.UNAVAILABLE) { + // spurious wakeup, is this possible? + pending = result; + return; + } + + // allow buffer(s) to be GC'ed. + readBuffers = null; + + // allow another read to be initiated + boolean wasScatteringRead = scatteringRead; + enableReading(); + + // result is Integer or Long + if (wasScatteringRead) { + result.setResult(Long.valueOf(n)); + } else { + result.setResult(Integer.valueOf(n)); + } + + } catch (Throwable x) { + enableReading(); + if (x instanceof ClosedChannelException) + x = new AsynchronousCloseException(); + result.setFailure(x); + } finally { + // restart poll in case of concurrent write + synchronized (updateLock) { + if (pending != null) + this.pendingRead = pending; + updateEvents(); + } + end(); + } + + if (invokeDirect) { + Invoker.invoke(result.handler(), result); + } else { + Invoker.invokeIndirectly(result.handler(), result); + } + } + + private Runnable readTimeoutTask = new Runnable() { + public void run() { + PendingFuture<Number,Object> result = grabPendingRead(); + if (result == null) + return; // already completed + + // kill further reading before releasing waiters + enableReading(true); + + // set completed and invoke handler + result.setFailure(new InterruptedByTimeoutException()); + Invoker.invokeIndirectly(result.handler(), result); + } + }; + + /** + * Initiates a read or scattering read operation + */ + @Override + @SuppressWarnings("unchecked") + <V extends Number,A> Future<V> readImpl(ByteBuffer[] dsts, + boolean isScatteringRead, + long timeout, + TimeUnit unit, + A attachment, + CompletionHandler<V,? super A> handler) + { + // A synchronous read is not attempted if disallowed by system property + // or, we are using a fixed thread pool and the completion handler may + // not be invoked directly (because the thread is not a pooled thread or + // there are too many handlers on the stack). + Invoker.GroupAndInvokeCount myGroupAndInvokeCount = null; + boolean invokeDirect = false; + boolean attemptRead = false; + if (!disableSynchronousRead) { + myGroupAndInvokeCount = Invoker.getGroupAndInvokeCount(); + invokeDirect = Invoker.mayInvokeDirect(myGroupAndInvokeCount, port); + attemptRead = (handler == null) || invokeDirect || + !port.isFixedThreadPool(); // okay to attempt read with user thread pool + } + + AbstractFuture<V,A> result; + try { + begin(); + + int n; + if (attemptRead) { + if (isScatteringRead) { + n = (int)IOUtil.read(fd, dsts, nd); + } else { + n = IOUtil.read(fd, dsts[0], -1, nd, null); + } + } else { + n = IOStatus.UNAVAILABLE; + } + + if (n == IOStatus.UNAVAILABLE) { + result = new PendingFuture<V,A>(this, handler, attachment, OpType.READ); + + // update evetns so that read will complete asynchronously + synchronized (updateLock) { + this.readBuffers = dsts; + this.scatteringRead = isScatteringRead; + this.pendingRead = (PendingFuture<Number,Object>)result; + updateEvents(); + } + + // schedule timeout + if (timeout > 0L) { + Future<?> timeoutTask = + port.schedule(readTimeoutTask, timeout, unit); + ((PendingFuture<V,A>)result).setTimeoutTask(timeoutTask); + } + return result; + } + + // data available + enableReading(); + + // result type is Long or Integer + if (isScatteringRead) { + result = (CompletedFuture<V,A>)CompletedFuture + .withResult(this, Long.valueOf(n), attachment); + } else { + result = (CompletedFuture<V,A>)CompletedFuture + .withResult(this, Integer.valueOf(n), attachment); + } + } catch (Throwable x) { + enableReading(); + if (x instanceof ClosedChannelException) + x = new AsynchronousCloseException(); + result = CompletedFuture.withFailure(this, x, attachment); + } finally { + end(); + } + + if (invokeDirect) { + Invoker.invokeDirect(myGroupAndInvokeCount, handler, result); + } else { + Invoker.invokeIndirectly(handler, result); + } + return result; + } + + // -- write -- + + private void finishWrite(PendingFuture<Number,Object> result, + boolean invokeDirect) + { + PendingFuture<Number,Object> pending = null; + try { + begin(); + + ByteBuffer[] srcs = writeBuffers; + int n; + if (srcs.length == 1) { + n = IOUtil.write(fd, srcs[0], -1, nd, null); + } else { + n = (int)IOUtil.write(fd, srcs, nd); + } + if (n == IOStatus.UNAVAILABLE) { + // spurious wakeup, is this possible? + pending = result; + return; + } + + // allow buffer(s) to be GC'ed. + writeBuffers = null; + + // allow another write to be initiated + boolean wasGatheringWrite = gatheringWrite; + enableWriting(); + + // result is a Long or Integer + if (wasGatheringWrite) { + result.setResult(Long.valueOf(n)); + } else { + result.setResult(Integer.valueOf(n)); + } + + } catch (Throwable x) { + enableWriting(); + if (x instanceof ClosedChannelException) + x = new AsynchronousCloseException(); + result.setFailure(x); + } finally { + // restart poll in case of concurrent read + synchronized (this) { + if (pending != null) + this.pendingWrite = pending; + updateEvents(); + } + end(); + } + if (invokeDirect) { + Invoker.invoke(result.handler(), result); + } else { + Invoker.invokeIndirectly(result.handler(), result); + } + } + + private Runnable writeTimeoutTask = new Runnable() { + public void run() { + PendingFuture<Number,Object> result = grabPendingWrite(); + if (result == null) + return; // already completed + + // kill further writing before releasing waiters + enableWriting(true); + + // set completed and invoke handler + result.setFailure(new InterruptedByTimeoutException()); + Invoker.invokeIndirectly(result.handler(), result); + } + }; + + /** + * Initiates a read or scattering read operation + */ + @Override + @SuppressWarnings("unchecked") + <V extends Number,A> Future<V> writeImpl(ByteBuffer[] srcs, + boolean isGatheringWrite, + long timeout, + TimeUnit unit, + A attachment, + CompletionHandler<V,? super A> handler) + { + Invoker.GroupAndInvokeCount myGroupAndInvokeCount = + Invoker.getGroupAndInvokeCount(); + boolean invokeDirect = Invoker.mayInvokeDirect(myGroupAndInvokeCount, port); + boolean attemptWrite = (handler == null) || invokeDirect || + !port.isFixedThreadPool(); // okay to attempt read with user thread pool + + AbstractFuture<V,A> result; + try { + begin(); + + int n; + if (attemptWrite) { + if (isGatheringWrite) { + n = (int)IOUtil.write(fd, srcs, nd); + } else { + n = IOUtil.write(fd, srcs[0], -1, nd, null); + } + } else { + n = IOStatus.UNAVAILABLE; + } + + if (n == IOStatus.UNAVAILABLE) { + result = new PendingFuture<V,A>(this, handler, attachment, OpType.WRITE); + + // update evetns so that read will complete asynchronously + synchronized (updateLock) { + this.writeBuffers = srcs; + this.gatheringWrite = isGatheringWrite; + this.pendingWrite = (PendingFuture<Number,Object>)result; + updateEvents(); + } + + // schedule timeout + if (timeout > 0L) { + Future<?> timeoutTask = + port.schedule(writeTimeoutTask, timeout, unit); + ((PendingFuture<V,A>)result).setTimeoutTask(timeoutTask); + } + return result; + } + + // data available + enableWriting(); + if (isGatheringWrite) { + result = (CompletedFuture<V,A>)CompletedFuture + .withResult(this, Long.valueOf(n), attachment); + } else { + result = (CompletedFuture<V,A>)CompletedFuture + .withResult(this, Integer.valueOf(n), attachment); + } + } catch (Throwable x) { + enableWriting(); + if (x instanceof ClosedChannelException) + x = new AsynchronousCloseException(); + result = CompletedFuture.withFailure(this, x, attachment); + } finally { + end(); + } + if (invokeDirect) { + Invoker.invokeDirect(myGroupAndInvokeCount, handler, result); + } else { + Invoker.invokeIndirectly(handler, result); + } + return result; + } + + // -- Native methods -- + + private static native void checkConnect(int fdVal) throws IOException; + + static { + Util.load(); + } +} diff --git a/src/solaris/classes/sun/nio/fs/DefaultFileSystemProvider.java b/src/solaris/classes/sun/nio/fs/DefaultFileSystemProvider.java new file mode 100644 index 0000000000000000000000000000000000000000..e86ff075c4ec34b4a6387287dc67bdf88598f9e0 --- /dev/null +++ b/src/solaris/classes/sun/nio/fs/DefaultFileSystemProvider.java @@ -0,0 +1,73 @@ +/* + * Copyright 2008-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 sun.nio.fs; + +import java.nio.file.spi.FileSystemProvider; +import java.security.AccessController; +import java.security.PrivilegedAction; +import sun.security.action.GetPropertyAction; + +/** + * Creates this platform's default FileSystemProvider. + */ + +public class DefaultFileSystemProvider { + private DefaultFileSystemProvider() { } + + @SuppressWarnings("unchecked") + private static FileSystemProvider createProvider(final String cn) { + return AccessController + .doPrivileged(new PrivilegedAction<FileSystemProvider>() { + public FileSystemProvider run() { + Class<FileSystemProvider> c; + try { + c = (Class<FileSystemProvider>)Class.forName(cn, true, null); + } catch (ClassNotFoundException x) { + throw new AssertionError(x); + } + try { + return c.newInstance(); + } catch (IllegalAccessException x) { + throw new AssertionError(x); + } catch (InstantiationException x) { + throw new AssertionError(x); + } + }}); + } + + /** + * Returns the default FileSystemProvider. + */ + public static FileSystemProvider create() { + String osname = AccessController + .doPrivileged(new GetPropertyAction("os.name")); + if (osname.equals("SunOS")) + return createProvider("sun.nio.fs.SolarisFileSystemProvider"); + if (osname.equals("Linux")) + return createProvider("sun.nio.fs.LinuxFileSystemProvider"); + throw new AssertionError("Platform not recognized"); + } +} diff --git a/src/solaris/classes/sun/nio/fs/DefaultFileTypeDetector.java b/src/solaris/classes/sun/nio/fs/DefaultFileTypeDetector.java new file mode 100644 index 0000000000000000000000000000000000000000..22db3165d0123a381191bf40f98c9af5dfd491ab --- /dev/null +++ b/src/solaris/classes/sun/nio/fs/DefaultFileTypeDetector.java @@ -0,0 +1,36 @@ +/* + * Copyright 2008-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 sun.nio.fs; + +import java.nio.file.spi.FileTypeDetector; + +public class DefaultFileTypeDetector { + private DefaultFileTypeDetector() { } + + public static FileTypeDetector create() { + return new GnomeFileTypeDetector(); + } +} diff --git a/src/solaris/classes/sun/nio/fs/GnomeFileTypeDetector.java b/src/solaris/classes/sun/nio/fs/GnomeFileTypeDetector.java new file mode 100644 index 0000000000000000000000000000000000000000..bf9e87a89120bf8389e86058178f55ee2563d0ff --- /dev/null +++ b/src/solaris/classes/sun/nio/fs/GnomeFileTypeDetector.java @@ -0,0 +1,101 @@ +/* + * Copyright 2008-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 sun.nio.fs; + +import java.nio.file.FileRef; +import java.io.IOException; +import java.security.AccessController; +import java.security.PrivilegedAction; + +/** + * File type detector that uses the GNOME I/O library or the deprecated + * GNOME VFS to guess the MIME type of a file. + */ + +public class GnomeFileTypeDetector + extends AbstractFileTypeDetector +{ + private static final String GNOME_VFS_MIME_TYPE_UNKNOWN = + "application/octet-stream"; + + // true if GIO available + private final boolean gioAvailable; + + // true if GNOME VFS available and GIO is not available + private final boolean gnomeVfsAvailable; + + public GnomeFileTypeDetector() { + gioAvailable = initializeGio(); + if (gioAvailable) { + gnomeVfsAvailable = false; + } else { + gnomeVfsAvailable = initializeGnomeVfs(); + } + } + + @Override + public String implProbeContentType(FileRef obj) throws IOException { + if (!gioAvailable && !gnomeVfsAvailable) + return null; + if (!(obj instanceof UnixPath)) + return null; + + UnixPath path = (UnixPath)obj; + NativeBuffer buffer = NativeBuffers.asNativeBuffer(path.getByteArrayForSysCalls()); + try { + if (gioAvailable) { + byte[] type = probeUsingGio(buffer.address()); + return (type == null) ? null : new String(type); + } else { + byte[] type = probeUsingGnomeVfs(buffer.address()); + if (type == null) + return null; + String s = new String(type); + return s.equals(GNOME_VFS_MIME_TYPE_UNKNOWN) ? null : s; + } + + } finally { + buffer.release(); + } + + } + + // GIO + private static native boolean initializeGio(); + private static native byte[] probeUsingGio(long pathAddress); + + // GNOME VFS + private static native boolean initializeGnomeVfs(); + private static native byte[] probeUsingGnomeVfs(long pathAddress); + + static { + AccessController.doPrivileged(new PrivilegedAction<Void>() { + public Void run() { + System.loadLibrary("nio"); + return null; + }}); + } +} diff --git a/src/solaris/classes/sun/nio/fs/LinuxDosFileAttributeView.java b/src/solaris/classes/sun/nio/fs/LinuxDosFileAttributeView.java new file mode 100644 index 0000000000000000000000000000000000000000..85f83e235539e9d28e73c4efff11777362d7343c --- /dev/null +++ b/src/solaris/classes/sun/nio/fs/LinuxDosFileAttributeView.java @@ -0,0 +1,297 @@ +/* + * Copyright 2008-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 sun.nio.fs; + +import java.nio.file.attribute.*; +import java.util.*; +import java.util.concurrent.TimeUnit; +import java.io.IOException; +import sun.misc.Unsafe; + +import static sun.nio.fs.UnixNativeDispatcher.*; +import static sun.nio.fs.UnixConstants.*; + +/** + * Linux implementation of DosFileAttributeView for use on file systems such + * as ext3 that have extended attributes enabled and SAMBA configured to store + * DOS attributes. + */ + +class LinuxDosFileAttributeView + extends UnixFileAttributeViews.Basic implements DosFileAttributeView +{ + private static final Unsafe unsafe = Unsafe.getUnsafe(); + + private static final String READONLY_NAME = "readonly"; + private static final String ARCHIVE_NAME = "archive"; + private static final String SYSTEM_NAME = "system"; + private static final String HIDDEN_NAME = "hidden"; + + private static final String DOS_XATTR_NAME = "user.DOSATTRIB"; + private static final byte[] DOS_XATTR_NAME_AS_BYTES = DOS_XATTR_NAME.getBytes(); + + private static final int DOS_XATTR_READONLY = 0x01; + private static final int DOS_XATTR_HIDDEN = 0x02; + private static final int DOS_XATTR_SYSTEM = 0x04; + private static final int DOS_XATTR_ARCHIVE = 0x20; + + LinuxDosFileAttributeView(UnixPath file, boolean followLinks) { + super(file, followLinks); + } + + @Override + public String name() { + return "dos"; + } + + @Override + public Object getAttribute(String attribute) throws IOException { + if (attribute.equals(READONLY_NAME)) + return readAttributes().isReadOnly(); + if (attribute.equals(ARCHIVE_NAME)) + return readAttributes().isArchive(); + if (attribute.equals(SYSTEM_NAME)) + return readAttributes().isSystem(); + if (attribute.equals(HIDDEN_NAME)) + return readAttributes().isHidden(); + return super.getAttribute(attribute); + } + + @Override + public void setAttribute(String attribute, Object value) + throws IOException + { + if (attribute.equals(READONLY_NAME)) { + setReadOnly((Boolean)value); + return; + } + if (attribute.equals(ARCHIVE_NAME)) { + setArchive((Boolean)value); + return; + } + if (attribute.equals(SYSTEM_NAME)) { + setSystem((Boolean)value); + return; + } + if (attribute.equals(HIDDEN_NAME)) { + setHidden((Boolean)value); + return; + } + super.setAttribute(attribute, value); + } + + @Override + public Map<String,?> readAttributes(String first, String[] rest) + throws IOException + { + AttributesBuilder builder = AttributesBuilder.create(first, rest); + DosFileAttributes attrs = readAttributes(); + addBasicAttributesToBuilder(attrs, builder); + if (builder.match(READONLY_NAME)) + builder.add(READONLY_NAME, attrs.isReadOnly()); + if (builder.match(ARCHIVE_NAME)) + builder.add(ARCHIVE_NAME, attrs.isArchive()); + if (builder.match(SYSTEM_NAME)) + builder.add(SYSTEM_NAME, attrs.isSystem()); + if (builder.match(HIDDEN_NAME)) + builder.add(HIDDEN_NAME, attrs.isHidden()); + return builder.unmodifiableMap(); + } + + @Override + public DosFileAttributes readAttributes() throws IOException { + file.checkRead(); + + int fd = file.openForAttributeAccess(followLinks); + try { + final UnixFileAttributes attrs = UnixFileAttributes.get(fd); + final int dosAttribute = getDosAttribute(fd); + + return new DosFileAttributes() { + @Override + public long lastModifiedTime() { + return attrs.lastModifiedTime(); + } + @Override + public long lastAccessTime() { + return attrs.lastAccessTime(); + } + @Override + public long creationTime() { + return attrs.creationTime(); + } + @Override + public TimeUnit resolution() { + return attrs.resolution(); + } + @Override + public boolean isRegularFile() { + return attrs.isRegularFile(); + } + @Override + public boolean isDirectory() { + return attrs.isDirectory(); + } + @Override + public boolean isSymbolicLink() { + return attrs.isSymbolicLink(); + } + @Override + public boolean isOther() { + return attrs.isOther(); + } + @Override + public long size() { + return attrs.size(); + } + @Override + public int linkCount() { + return attrs.linkCount(); + } + @Override + public Object fileKey() { + return attrs.fileKey(); + } + @Override + public boolean isReadOnly() { + return (dosAttribute & DOS_XATTR_READONLY) != 0; + } + @Override + public boolean isHidden() { + return (dosAttribute & DOS_XATTR_HIDDEN) != 0; + } + @Override + public boolean isArchive() { + return (dosAttribute & DOS_XATTR_ARCHIVE) != 0; + } + @Override + public boolean isSystem() { + return (dosAttribute & DOS_XATTR_SYSTEM) != 0; + } + }; + + } catch (UnixException x) { + x.rethrowAsIOException(file); + return null; // keep compiler happy + } finally { + close(fd); + } + } + + @Override + public void setReadOnly(boolean value) throws IOException { + updateDosAttribute(DOS_XATTR_READONLY, value); + } + + @Override + public void setHidden(boolean value) throws IOException { + updateDosAttribute(DOS_XATTR_HIDDEN, value); + } + + @Override + public void setArchive(boolean value) throws IOException { + updateDosAttribute(DOS_XATTR_ARCHIVE, value); + } + + @Override + public void setSystem(boolean value) throws IOException { + updateDosAttribute(DOS_XATTR_SYSTEM, value); + } + + /** + * Reads the value of the user.DOSATTRIB extended attribute + */ + private int getDosAttribute(int fd) throws UnixException { + final int size = 24; + + NativeBuffer buffer = NativeBuffers.getNativeBuffer(size); + try { + int len = LinuxNativeDispatcher + .fgetxattr(fd, DOS_XATTR_NAME_AS_BYTES, buffer.address(), size); + + if (len > 0) { + // ignore null terminator + if (unsafe.getByte(buffer.address()+len-1) == 0) + len--; + + // convert to String and parse + byte[] buf = new byte[len]; + unsafe.copyMemory(null, buffer.address(), buf, + Unsafe.ARRAY_BYTE_BASE_OFFSET, len); + String value = new String(buf); // platform encoding + + // should be something like 0x20 + if (value.length() >= 3 && value.startsWith("0x")) { + try { + return Integer.parseInt(value.substring(2), 16); + } catch (NumberFormatException x) { + // ignore + } + } + } + throw new UnixException("Value of " + DOS_XATTR_NAME + " attribute is invalid"); + } catch (UnixException x) { + // default value when attribute does not exist + if (x.errno() == ENODATA) + return 0; + throw x; + } finally { + buffer.release(); + } + } + + /** + * Updates the value of the user.DOSATTRIB extended attribute + */ + private void updateDosAttribute(int flag, boolean enable) throws IOException { + file.checkWrite(); + + int fd = file.openForAttributeAccess(followLinks); + try { + int oldValue = getDosAttribute(fd); + int newValue = oldValue; + if (enable) { + newValue |= flag; + } else { + newValue &= ~flag; + } + if (newValue != oldValue) { + byte[] value = ("0x" + Integer.toHexString(newValue)).getBytes(); + NativeBuffer buffer = NativeBuffers.asNativeBuffer(value); + try { + LinuxNativeDispatcher.fsetxattr(fd, DOS_XATTR_NAME_AS_BYTES, + buffer.address(), value.length+1); + } finally { + buffer.release(); + } + } + } catch (UnixException x) { + x.rethrowAsIOException(file); + } finally { + close(fd); + } + } +} diff --git a/src/solaris/classes/sun/nio/fs/LinuxFileStore.java b/src/solaris/classes/sun/nio/fs/LinuxFileStore.java new file mode 100644 index 0000000000000000000000000000000000000000..8c07ce5f66aa9bb499d6d2b69f26ca6d28831f7c --- /dev/null +++ b/src/solaris/classes/sun/nio/fs/LinuxFileStore.java @@ -0,0 +1,152 @@ +/* + * Copyright 2008-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 sun.nio.fs; + +import java.util.*; +import java.io.IOException; + +/** + * Linux implementation of FileStore + */ + +class LinuxFileStore + extends UnixFileStore +{ + // used when checking if extended attributes are enabled or not + private volatile boolean xattrChecked; + private volatile boolean xattrEnabled; + + LinuxFileStore(UnixPath file) throws IOException { + super(file); + } + + LinuxFileStore(UnixFileSystem fs, UnixMountEntry entry) throws IOException { + super(fs, entry); + } + + /** + * Finds, and returns, the mount entry for the file system where the file + * resides. + */ + @Override + UnixMountEntry findMountEntry() throws IOException { + UnixFileSystem fs = file().getFileSystem(); + + // step 1: get realpath + UnixPath path = null; + try { + byte[] rp = UnixNativeDispatcher.realpath(file()); + path = new UnixPath(fs, rp); + } catch (UnixException x) { + x.rethrowAsIOException(file()); + } + + // step 2: find mount point + UnixPath parent = path.getParent(); + while (parent != null) { + UnixFileAttributes attrs = null; + try { + attrs = UnixFileAttributes.get(parent, true); + } catch (UnixException x) { + x.rethrowAsIOException(parent); + } + if (attrs.dev() != dev()) + break; + path = parent; + parent = parent.getParent(); + } + + // step 3: lookup mounted file systems + byte[] dir = path.asByteArray(); + for (UnixMountEntry entry: fs.getMountEntries()) { + if (Arrays.equals(dir, entry.dir())) + return entry; + } + + throw new IOException("Mount point not found in mtab"); + } + + // returns true if extended attributes enabled on file system where given + // file resides, returns false if disabled or unable to determine. + private boolean isExtendedAttributesEnabled(UnixPath path) { + try { + int fd = path.openForAttributeAccess(false); + try { + // fgetxattr returns size if called with size==0 + LinuxNativeDispatcher.fgetxattr(fd, "user.java".getBytes(), 0L, 0); + return true; + } catch (UnixException e) { + // attribute does not exist + if (e.errno() == UnixConstants.ENODATA) + return true; + } finally { + UnixNativeDispatcher.close(fd); + } + } catch (IOException ignore) { + // nothing we can do + } + return false; + } + + @Override + public boolean supportsFileAttributeView(String name) { + // support DosFileAttributeView and NamedAttributeView if extended + // attributes enabled + if (name.equals("dos") || name.equals("xattr")) { + // lookup fstypes.properties + FeatureStatus status = checkIfFeaturePresent("user_xattr"); + if (status == FeatureStatus.PRESENT) + return true; + if (status == FeatureStatus.NOT_PRESENT) + return false; + + // if file system is mounted with user_xattr option then assume + // extended attributes are enabled + if ((entry().hasOption("user_xattr"))) + return true; + + // user_xattr option not present but we special-case ext3/4 as we + // know that extended attributes are not enabled by default. + if (entry().fstype().equals("ext3") || entry().fstype().equals("ext4")) + return false; + + // not ext3/4 so probe mount point + if (!xattrChecked) { + UnixPath dir = new UnixPath(file().getFileSystem(), entry().dir()); + xattrEnabled = isExtendedAttributesEnabled(dir); + xattrChecked = true; + } + return xattrEnabled; + } + + return super.supportsFileAttributeView(name); + } + + @Override + boolean isLoopback() { + return false; + } +} diff --git a/src/solaris/classes/sun/nio/fs/LinuxFileSystem.java b/src/solaris/classes/sun/nio/fs/LinuxFileSystem.java new file mode 100644 index 0000000000000000000000000000000000000000..d574c9dff09c76795b78627ac72696f2bd81eacd --- /dev/null +++ b/src/solaris/classes/sun/nio/fs/LinuxFileSystem.java @@ -0,0 +1,175 @@ +/* + * Copyright 2008-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 sun.nio.fs; + +import java.nio.file.*; +import java.nio.file.attribute.*; +import java.io.IOException; +import java.util.*; +import java.security.AccessController; +import sun.security.action.GetPropertyAction; +import static sun.nio.fs.LinuxNativeDispatcher.*; + +/** + * Linux implementation of FileSystem + */ + +class LinuxFileSystem extends UnixFileSystem { + private final boolean hasInotify; + private final boolean hasAtSysCalls; + + LinuxFileSystem(UnixFileSystemProvider provider, String dir) { + super(provider, dir); + + // assume X.Y[-Z] format + String osversion = AccessController + .doPrivileged(new GetPropertyAction("os.version")); + String[] vers = osversion.split("\\.", 0); + assert vers.length >= 2; + + int majorVersion = Integer.parseInt(vers[0]); + int minorVersion = Integer.parseInt(vers[1]); + int microVersion = 0; + if (vers.length > 2) { + String[] microVers = vers[2].split("-", 0); + microVersion = (microVers.length > 0) ? + Integer.parseInt(microVers[0]) : 0; + } + + // inotify available since 2.6.13 + this.hasInotify = ((majorVersion > 2) || + (majorVersion == 2 && minorVersion > 6) || + ((majorVersion == 2) && (minorVersion == 6) && (microVersion >= 13))); + + // openat etc. available since 2.6.16 + this.hasAtSysCalls = ((majorVersion > 2) || + (majorVersion == 2 && minorVersion > 6) || + ((majorVersion == 2) && (minorVersion == 6) && (microVersion >= 16))); + } + + @Override + public WatchService newWatchService() + throws IOException + { + if (hasInotify) { + return new LinuxWatchService(this); + } else { + // use polling implementation on older kernels + return new PollingWatchService(); + } + } + + @Override + @SuppressWarnings("unchecked") + public <V extends FileAttributeView> V newFileAttributeView(Class<V> view, + UnixPath file, + LinkOption... options) + { + if (view == DosFileAttributeView.class) + return (V) new LinuxDosFileAttributeView(file, followLinks(options)); + if (view == UserDefinedFileAttributeView.class) + return (V) new LinuxUserDefinedFileAttributeView(file, followLinks(options)); + return super.newFileAttributeView(view, file, options); + } + + @Override + @SuppressWarnings("unchecked") + public FileAttributeView newFileAttributeView(String name, + UnixPath file, + LinkOption... options) + { + if (name.equals("dos")) + return new LinuxDosFileAttributeView(file, followLinks(options)); + if (name.equals("xattr")) + return new LinuxUserDefinedFileAttributeView(file, followLinks(options)); + return super.newFileAttributeView(name, file, options); + } + + // lazy initialization of the list of supported attribute views + private static class SupportedFileFileAttributeViewsHolder { + static final Set<String> supportedFileAttributeViews = + supportedFileAttributeViews(); + private static Set<String> supportedFileAttributeViews() { + Set<String> result = new HashSet<String>(); + result.addAll(UnixFileSystem.standardFileAttributeViews()); + // additional Linux-specific views + result.add("dos"); + result.add("xattr"); + return Collections.unmodifiableSet(result); + } + } + + @Override + public Set<String> supportedFileAttributeViews() { + return SupportedFileFileAttributeViewsHolder.supportedFileAttributeViews; + } + + @Override + void copyNonPosixAttributes(int ofd, int nfd) { + LinuxUserDefinedFileAttributeView.copyExtendedAttributes(ofd, nfd); + } + + @Override + boolean supportsSecureDirectoryStreams() { + return hasAtSysCalls; + } + + /** + * Returns object to iterate over entries in /etc/mtab + */ + @Override + Iterable<UnixMountEntry> getMountEntries() { + ArrayList<UnixMountEntry> entries = new ArrayList<UnixMountEntry>(); + try { + long fp = setmntent("/etc/mtab".getBytes(), "r".getBytes()); + try { + for (;;) { + UnixMountEntry entry = new UnixMountEntry(); + int res = getextmntent(fp, entry); + if (res < 0) + break; + entries.add(entry); + } + } finally { + endmntent(fp); + } + + } catch (UnixException x) { + // nothing we can do + } + return entries; + } + + @Override + FileStore getFileStore(UnixPath path) throws IOException { + return new LinuxFileStore(path); + } + + @Override + FileStore getFileStore(UnixMountEntry entry) throws IOException { + return new LinuxFileStore(this, entry); + } +} diff --git a/src/solaris/classes/sun/nio/fs/LinuxFileSystemProvider.java b/src/solaris/classes/sun/nio/fs/LinuxFileSystemProvider.java new file mode 100644 index 0000000000000000000000000000000000000000..aa979c4759a7fa1520cec8c0e15b3e5729c3c076 --- /dev/null +++ b/src/solaris/classes/sun/nio/fs/LinuxFileSystemProvider.java @@ -0,0 +1,41 @@ +/* + * Copyright 2008-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 sun.nio.fs; + +/** + * Linux implementation of FileSystemProvider + */ + +public class LinuxFileSystemProvider extends UnixFileSystemProvider { + public LinuxFileSystemProvider() { + super(); + } + + @Override + LinuxFileSystem newFileSystem(String dir) { + return new LinuxFileSystem(this, dir); + } +} diff --git a/src/solaris/classes/sun/nio/fs/LinuxNativeDispatcher.java b/src/solaris/classes/sun/nio/fs/LinuxNativeDispatcher.java new file mode 100644 index 0000000000000000000000000000000000000000..65547badccb0dd8006053c2f49c361b411d6c371 --- /dev/null +++ b/src/solaris/classes/sun/nio/fs/LinuxNativeDispatcher.java @@ -0,0 +1,126 @@ +/* + * Copyright 2008-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 sun.nio.fs; + +import java.security.AccessController; +import java.security.PrivilegedAction; + +/** + * Linux specific system calls. + */ + +class LinuxNativeDispatcher extends UnixNativeDispatcher { + private LinuxNativeDispatcher() { } + + /** + * FILE *setmntent(const char *filename, const char *type); + */ + static long setmntent(byte[] filename, byte[] type) throws UnixException { + NativeBuffer pathBuffer = NativeBuffers.asNativeBuffer(filename); + NativeBuffer typeBuffer = NativeBuffers.asNativeBuffer(type); + try { + return setmntent0(pathBuffer.address(), typeBuffer.address()); + } finally { + typeBuffer.release(); + pathBuffer.release(); + } + } + private static native long setmntent0(long pathAddress, long typeAddress) + throws UnixException; + + /** + * int endmntent(FILE* filep); + */ + static native void endmntent(long stream) throws UnixException; + + /** + * ssize_t fgetxattr(int filedes, const char *name, void *value, size_t size); + */ + static int fgetxattr(int filedes, byte[] name, long valueAddress, + int valueLen) throws UnixException + { + NativeBuffer buffer = NativeBuffers.asNativeBuffer(name); + try { + return fgetxattr0(filedes, buffer.address(), valueAddress, valueLen); + } finally { + buffer.release(); + } + } + + private static native int fgetxattr0(int filedes, long nameAddress, + long valueAdddress, int valueLen) throws UnixException; + + /** + * fsetxattr(int filedes, const char *name, const void *value, size_t size, int flags); + */ + static void fsetxattr(int filedes, byte[] name, long valueAddress, + int valueLen) throws UnixException + { + NativeBuffer buffer = NativeBuffers.asNativeBuffer(name); + try { + fsetxattr0(filedes, buffer.address(), valueAddress, valueLen); + } finally { + buffer.release(); + } + } + + private static native void fsetxattr0(int filedes, long nameAddress, + long valueAdddress, int valueLen) throws UnixException; + + + /** + * fremovexattr(int filedes, const char *name); + */ + static void fremovexattr(int filedes, byte[] name) throws UnixException { + NativeBuffer buffer = NativeBuffers.asNativeBuffer(name); + try { + fremovexattr0(filedes, buffer.address()); + } finally { + buffer.release(); + } + } + + private static native void fremovexattr0(int filedes, long nameAddress) + throws UnixException; + + /** + * size_t flistxattr(int filedes, const char *list, size_t size) + */ + static native int flistxattr(int filedes, long listAddress, int size) + throws UnixException; + + // initialize + private static native void init(); + + static { + AccessController.doPrivileged(new PrivilegedAction<Void>() { + public Void run() { + System.loadLibrary("nio"); + return null; + }}); + init(); + } +} diff --git a/src/solaris/classes/sun/nio/fs/LinuxUserDefinedFileAttributeView.java b/src/solaris/classes/sun/nio/fs/LinuxUserDefinedFileAttributeView.java new file mode 100644 index 0000000000000000000000000000000000000000..b51a9e9cb266e0dfa39927ba6baf3f445f87f7df --- /dev/null +++ b/src/solaris/classes/sun/nio/fs/LinuxUserDefinedFileAttributeView.java @@ -0,0 +1,350 @@ +/* + * Copyright 2008-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 sun.nio.fs; + +import java.nio.file.*; +import java.nio.ByteBuffer; +import java.io.IOException; +import java.util.*; +import sun.misc.Unsafe; + +import static sun.nio.fs.UnixConstants.*; +import static sun.nio.fs.LinuxNativeDispatcher.*; + +/** + * Linux implementation of UserDefinedFileAttributeView using extended attributes. + */ + +class LinuxUserDefinedFileAttributeView + extends AbstractUserDefinedFileAttributeView +{ + private static final Unsafe unsafe = Unsafe.getUnsafe(); + + // namespace for extended user attributes + private static final String USER_NAMESPACE = "user."; + + // maximum bytes in extended attribute name (includes namespace) + private static final int XATTR_NAME_MAX = 255; + + private byte[] nameAsBytes(UnixPath file, String name) throws IOException { + if (name == null) + throw new NullPointerException("'name' is null"); + name = USER_NAMESPACE + name; + byte[] bytes = name.getBytes(); + if (bytes.length > XATTR_NAME_MAX) { + throw new FileSystemException(file.getPathForExecptionMessage(), + null, "'" + name + "' is too big"); + } + return bytes; + } + + // Parses buffer as array of NULL-terminated C strings. + private List<String> asList(long address, int size) { + final List<String> list = new ArrayList<String>(); + int start = 0; + int pos = 0; + while (pos < size) { + if (unsafe.getByte(address + pos) == 0) { + int len = pos - start; + byte[] value = new byte[len]; + unsafe.copyMemory(null, address+start, value, + Unsafe.ARRAY_BYTE_BASE_OFFSET, len); + String s = new String(value); + if (s.startsWith(USER_NAMESPACE)) { + s = s.substring(USER_NAMESPACE.length()); + list.add(s); + } + start = pos + 1; + } + pos++; + } + return list; + } + + private final UnixPath file; + private final boolean followLinks; + + LinuxUserDefinedFileAttributeView(UnixPath file, boolean followLinks) { + this.file = file; + this.followLinks = followLinks; + } + + @Override + public List<String> list() throws IOException { + if (System.getSecurityManager() != null) + checkAccess(file.getPathForPermissionCheck(), true, false); + + int fd = file.openForAttributeAccess(followLinks); + NativeBuffer buffer = null; + try { + int size = 1024; + buffer = NativeBuffers.getNativeBuffer(size); + for (;;) { + try { + int n = flistxattr(fd, buffer.address(), size); + List<String> list = asList(buffer.address(), n); + return Collections.unmodifiableList(list); + } catch (UnixException x) { + // allocate larger buffer if required + if (x.errno() == ERANGE && size < 32*1024) { + buffer.release(); + size *= 2; + buffer = null; + buffer = NativeBuffers.getNativeBuffer(size); + continue; + } + throw new FileSystemException(file.getPathForExecptionMessage(), + null, "Unable to get list of extended attributes: " + + x.getMessage()); + } + } + } finally { + if (buffer != null) + buffer.release(); + close(fd); + } + } + + @Override + public int size(String name) throws IOException { + if (System.getSecurityManager() != null) + checkAccess(file.getPathForPermissionCheck(), true, false); + + int fd = file.openForAttributeAccess(followLinks); + try { + // fgetxattr returns size if called with size==0 + return fgetxattr(fd, nameAsBytes(file,name), 0L, 0); + } catch (UnixException x) { + throw new FileSystemException(file.getPathForExecptionMessage(), + null, "Unable to get size of extended attribute '" + name + + "': " + x.getMessage()); + } finally { + close(fd); + } + } + + @Override + public int read(String name, ByteBuffer dst) throws IOException { + if (System.getSecurityManager() != null) + checkAccess(file.getPathForPermissionCheck(), true, false); + + if (dst.isReadOnly()) + throw new IllegalArgumentException("Read-only buffer"); + int pos = dst.position(); + int lim = dst.limit(); + assert (pos <= lim); + int rem = (pos <= lim ? lim - pos : 0); + + NativeBuffer nb; + long address; + if (dst instanceof sun.nio.ch.DirectBuffer) { + nb = null; + address = ((sun.nio.ch.DirectBuffer)dst).address() + pos; + } else { + // substitute with native buffer + nb = NativeBuffers.getNativeBuffer(rem); + address = nb.address(); + } + + int fd = file.openForAttributeAccess(followLinks); + try { + try { + int n = fgetxattr(fd, nameAsBytes(file,name), address, rem); + + // if remaining is zero then fgetxattr returns the size + if (rem == 0) { + if (n > 0) + throw new UnixException(ERANGE); + return 0; + } + + // copy from buffer into backing array if necessary + if (nb != null) { + int off = dst.arrayOffset() + pos + Unsafe.ARRAY_BYTE_BASE_OFFSET; + unsafe.copyMemory(null, address, dst.array(), off, n); + } + dst.position(pos + n); + return n; + } catch (UnixException x) { + String msg = (x.errno() == ERANGE) ? + "Insufficient space in buffer" : x.getMessage(); + throw new FileSystemException(file.getPathForExecptionMessage(), + null, "Error reading extended attribute '" + name + "': " + msg); + } finally { + close(fd); + } + } finally { + if (nb != null) + nb.release(); + } + } + + @Override + public int write(String name, ByteBuffer src) throws IOException { + if (System.getSecurityManager() != null) + checkAccess(file.getPathForPermissionCheck(), false, true); + + int pos = src.position(); + int lim = src.limit(); + assert (pos <= lim); + int rem = (pos <= lim ? lim - pos : 0); + + NativeBuffer nb; + long address; + if (src instanceof sun.nio.ch.DirectBuffer) { + nb = null; + address = ((sun.nio.ch.DirectBuffer)src).address() + pos; + } else { + // substitute with native buffer + nb = NativeBuffers.getNativeBuffer(rem); + address = nb.address(); + + if (src.hasArray()) { + // copy from backing array into buffer + int off = src.arrayOffset() + pos + Unsafe.ARRAY_BYTE_BASE_OFFSET; + unsafe.copyMemory(src.array(), off, null, address, rem); + } else { + // backing array not accessible so transfer via temporary array + byte[] tmp = new byte[rem]; + src.get(tmp); + src.position(pos); // reset position as write may fail + unsafe.copyMemory(tmp, Unsafe.ARRAY_BYTE_BASE_OFFSET, null, + address, rem); + } + } + + int fd = file.openForAttributeAccess(followLinks); + try { + try { + fsetxattr(fd, nameAsBytes(file,name), address, rem); + src.position(pos + rem); + return rem; + } catch (UnixException x) { + throw new FileSystemException(file.getPathForExecptionMessage(), + null, "Error writing extended attribute '" + name + "': " + + x.getMessage()); + } finally { + close(fd); + } + } finally { + if (nb != null) + nb.release(); + } + } + + @Override + public void delete(String name) throws IOException { + if (System.getSecurityManager() != null) + checkAccess(file.getPathForPermissionCheck(), false, true); + + int fd = file.openForAttributeAccess(followLinks); + try { + fremovexattr(fd, nameAsBytes(file,name)); + } catch (UnixException x) { + throw new FileSystemException(file.getPathForExecptionMessage(), + null, "Unable to delete extended attribute '" + name + "': " + x.getMessage()); + } finally { + close(fd); + } + } + + /** + * Used by copyTo/moveTo to copy extended attributes from source to target. + * + * @param ofd + * file descriptor for source file + * @param nfd + * file descriptor for target file + */ + static void copyExtendedAttributes(int ofd, int nfd) { + NativeBuffer buffer = null; + try { + + // call flistxattr to get list of extended attributes. + int size = 1024; + buffer = NativeBuffers.getNativeBuffer(size); + for (;;) { + try { + size = flistxattr(ofd, buffer.address(), size); + break; + } catch (UnixException x) { + // allocate larger buffer if required + if (x.errno() == ERANGE && size < 32*1024) { + buffer.release(); + size *= 2; + buffer = null; + buffer = NativeBuffers.getNativeBuffer(size); + continue; + } + + // unable to get list of attributes + return; + } + } + + // parse buffer as array of NULL-terminated C strings. + long address = buffer.address(); + int start = 0; + int pos = 0; + while (pos < size) { + if (unsafe.getByte(address + pos) == 0) { + // extract attribute name and copy attribute to target. + // FIXME: We can avoid needless copying by using address+pos + // as the address of the name. + int len = pos - start; + byte[] name = new byte[len]; + unsafe.copyMemory(null, address+start, name, + Unsafe.ARRAY_BYTE_BASE_OFFSET, len); + try { + copyExtendedAttribute(ofd, name, nfd); + } catch (UnixException ignore) { + // ignore + } + start = pos + 1; + } + pos++; + } + + } finally { + if (buffer != null) + buffer.release(); + } + } + + private static void copyExtendedAttribute(int ofd, byte[] name, int nfd) + throws UnixException + { + int size = fgetxattr(ofd, name, 0L, 0); + NativeBuffer buffer = NativeBuffers.getNativeBuffer(size); + try { + long address = buffer.address(); + size = fgetxattr(ofd, name, address, size); + fsetxattr(nfd, name, address, size); + } finally { + buffer.release(); + } + } +} diff --git a/src/solaris/classes/sun/nio/fs/LinuxWatchService.java b/src/solaris/classes/sun/nio/fs/LinuxWatchService.java new file mode 100644 index 0000000000000000000000000000000000000000..0d4a2ffddff8b903282977acc62bdb48b2560a00 --- /dev/null +++ b/src/solaris/classes/sun/nio/fs/LinuxWatchService.java @@ -0,0 +1,466 @@ +/* + * Copyright 2008-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 sun.nio.fs; + +import java.nio.file.*; +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.util.*; +import java.io.IOException; +import sun.misc.Unsafe; + +import static sun.nio.fs.UnixNativeDispatcher.*; +import static sun.nio.fs.UnixConstants.*; + +/** + * Linux implementation of WatchService based on inotify. + * + * In summary a background thread polls inotify plus a socket used for the wakeup + * mechanism. Requests to add or remove a watch, or close the watch service, + * cause the thread to wakeup and process the request. Events are processed + * by the thread which causes it to signal/queue the corresponding watch keys. + */ + +class LinuxWatchService + extends AbstractWatchService +{ + private static final Unsafe unsafe = Unsafe.getUnsafe(); + + // background thread to read change events + private final Poller poller; + + LinuxWatchService(UnixFileSystem fs) throws IOException { + // initialize inotify + int ifd = - 1; + try { + ifd = inotifyInit(); + } catch (UnixException x) { + throw new IOException(x.errorString()); + } + + // configure inotify to be non-blocking + // create socketpair used in the close mechanism + int sp[] = new int[2]; + try { + configureBlocking(ifd, false); + socketpair(sp); + configureBlocking(sp[0], false); + } catch (UnixException x) { + UnixNativeDispatcher.close(ifd); + throw new IOException(x.errorString()); + } + + this.poller = new Poller(fs, this, ifd, sp); + this.poller.start(); + } + + @Override + WatchKey register(Path dir, + WatchEvent.Kind<?>[] events, + WatchEvent.Modifier... modifiers) + throws IOException + { + // delegate to poller + return poller.register(dir, events, modifiers); + } + + @Override + void implClose() throws IOException { + // delegate to poller + poller.close(); + } + + /** + * WatchKey implementation + */ + private static class LinuxWatchKey extends AbstractWatchKey { + // inotify descriptor + private final int ifd; + // watch descriptor + private volatile int wd; + + LinuxWatchKey(LinuxWatchService watcher, int ifd, int wd) { + super(watcher); + this.ifd = ifd; + this.wd = wd; + } + + int descriptor() { + return wd; + } + + void invalidate(boolean remove) { + if (remove) { + try { + inotifyRmWatch(ifd, wd); + } catch (UnixException x) { + // ignore + } + } + wd = -1; + } + + @Override + public boolean isValid() { + return (wd != -1); + } + + @Override + public void cancel() { + if (isValid()) { + // delegate to poller + ((LinuxWatchService)watcher()).poller.cancel(this); + } + } + } + + /** + * Background thread to read from inotify + */ + private static class Poller extends AbstractPoller { + /** + * struct inotify_event { + * int wd; + * uint32_t mask; + * uint32_t len; + * char name __flexarr; // present if len > 0 + * } act_t; + */ + private static final int SIZEOF_INOTIFY_EVENT = eventSize(); + private static final int[] offsets = eventOffsets(); + private static final int OFFSETOF_WD = offsets[0]; + private static final int OFFSETOF_MASK = offsets[1]; + private static final int OFFSETOF_LEN = offsets[3]; + private static final int OFFSETOF_NAME = offsets[4]; + + private static final int IN_MODIFY = 0x00000002; + private static final int IN_ATTRIB = 0x00000004; + private static final int IN_MOVED_FROM = 0x00000040; + private static final int IN_MOVED_TO = 0x00000080; + private static final int IN_CREATE = 0x00000100; + private static final int IN_DELETE = 0x00000200; + + private static final int IN_UNMOUNT = 0x00002000; + private static final int IN_Q_OVERFLOW = 0x00004000; + private static final int IN_IGNORED = 0x00008000; + + // sizeof buffer for when polling inotify + private static final int BUFFER_SIZE = 8192; + + private final UnixFileSystem fs; + private final LinuxWatchService watcher; + + // inotify file descriptor + private final int ifd; + // socketpair used to shutdown polling thread + private final int socketpair[]; + // maps watch descriptor to Key + private final Map<Integer,LinuxWatchKey> wdToKey; + // address of read buffer + private final long address; + + Poller(UnixFileSystem fs, LinuxWatchService watcher, int ifd, int[] sp) { + this.fs = fs; + this.watcher = watcher; + this.ifd = ifd; + this.socketpair = sp; + this.wdToKey = new HashMap<Integer,LinuxWatchKey>(); + this.address = unsafe.allocateMemory(BUFFER_SIZE); + } + + @Override + void wakeup() throws IOException { + // write to socketpair to wakeup polling thread + try { + write(socketpair[1], address, 1); + } catch (UnixException x) { + throw new IOException(x.errorString()); + } + } + + @Override + Object implRegister(Path obj, + Set<? extends WatchEvent.Kind<?>> events, + WatchEvent.Modifier... modifiers) + { + UnixPath dir = (UnixPath)obj; + + int mask = 0; + for (WatchEvent.Kind<?> event: events) { + if (event == StandardWatchEventKind.ENTRY_CREATE) { + mask |= IN_CREATE | IN_MOVED_TO; + continue; + } + if (event == StandardWatchEventKind.ENTRY_DELETE) { + mask |= IN_DELETE | IN_MOVED_FROM; + continue; + } + if (event == StandardWatchEventKind.ENTRY_MODIFY) { + mask |= IN_MODIFY | IN_ATTRIB; + continue; + } + } + + // no modifiers supported at this time + if (modifiers.length > 0) { + for (WatchEvent.Modifier modifier: modifiers) { + if (modifier == null) + return new NullPointerException(); + if (modifier instanceof com.sun.nio.file.SensitivityWatchEventModifier) + continue; // ignore + return new UnsupportedOperationException("Modifier not supported"); + } + } + + // check file is directory + UnixFileAttributes attrs = null; + try { + attrs = UnixFileAttributes.get(dir, true); + } catch (UnixException x) { + return x.asIOException(dir); + } + if (!attrs.isDirectory()) { + return new NotDirectoryException(dir.getPathForExecptionMessage()); + } + + // register with inotify (replaces existing mask if already registered) + int wd = -1; + try { + NativeBuffer buffer = + NativeBuffers.asNativeBuffer(dir.getByteArrayForSysCalls()); + try { + wd = inotifyAddWatch(ifd, buffer.address(), mask); + } finally { + buffer.release(); + } + } catch (UnixException x) { + if (x.errno() == ENOSPC) { + return new IOException("User limit of inotify watches reached"); + } + return x.asIOException(dir); + } + + // ensure watch descriptor is in map + LinuxWatchKey key = wdToKey.get(wd); + if (key == null) { + key = new LinuxWatchKey(watcher, ifd, wd); + wdToKey.put(wd, key); + } + return key; + } + + // cancel single key + @Override + void implCancelKey(WatchKey obj) { + LinuxWatchKey key = (LinuxWatchKey)obj; + if (key.isValid()) { + wdToKey.remove(key.descriptor()); + key.invalidate(true); + } + } + + // close watch service + @Override + void implCloseAll() { + // invalidate all keys + for (Map.Entry<Integer,LinuxWatchKey> entry: wdToKey.entrySet()) { + entry.getValue().invalidate(true); + } + wdToKey.clear(); + + // free resources + unsafe.freeMemory(address); + UnixNativeDispatcher.close(socketpair[0]); + UnixNativeDispatcher.close(socketpair[1]); + UnixNativeDispatcher.close(ifd); + } + + /** + * Poller main loop + */ + @Override + public void run() { + try { + for (;;) { + int nReady, bytesRead; + + // wait for close or inotify event + nReady = poll(ifd, socketpair[0]); + + // read from inotify + try { + bytesRead = read(ifd, address, BUFFER_SIZE); + } catch (UnixException x) { + if (x.errno() != EAGAIN) + throw x; + bytesRead = 0; + } + + // process any pending requests + if ((nReady > 1) || (nReady == 1 && bytesRead == 0)) { + try { + read(socketpair[0], address, BUFFER_SIZE); + boolean shutdown = processRequests(); + if (shutdown) + break; + } catch (UnixException x) { + if (x.errno() != UnixConstants.EAGAIN) + throw x; + } + } + + // iterate over buffer to decode events + int offset = 0; + while (offset < bytesRead) { + long event = address + offset; + int wd = unsafe.getInt(event + OFFSETOF_WD); + int mask = unsafe.getInt(event + OFFSETOF_MASK); + int len = unsafe.getInt(event + OFFSETOF_LEN); + + // file name + UnixPath name = null; + if (len > 0) { + int actual = len; + + // null-terminated and maybe additional null bytes to + // align the next event + while (actual > 0) { + long last = event + OFFSETOF_NAME + actual - 1; + if (unsafe.getByte(last) != 0) + break; + actual--; + } + if (actual > 0) { + byte[] buf = new byte[actual]; + unsafe.copyMemory(null, event + OFFSETOF_NAME, + buf, Unsafe.ARRAY_BYTE_BASE_OFFSET, actual); + name = new UnixPath(fs, buf); + } + } + + // process event + processEvent(wd, mask, name); + + offset += (SIZEOF_INOTIFY_EVENT + len); + } + } + } catch (UnixException x) { + x.printStackTrace(); + } + } + + + /** + * map inotify event to WatchEvent.Kind + */ + private WatchEvent.Kind<?> maskToEventKind(int mask) { + if ((mask & IN_MODIFY) > 0) + return StandardWatchEventKind.ENTRY_MODIFY; + if ((mask & IN_ATTRIB) > 0) + return StandardWatchEventKind.ENTRY_MODIFY; + if ((mask & IN_CREATE) > 0) + return StandardWatchEventKind.ENTRY_CREATE; + if ((mask & IN_MOVED_TO) > 0) + return StandardWatchEventKind.ENTRY_CREATE; + if ((mask & IN_DELETE) > 0) + return StandardWatchEventKind.ENTRY_DELETE; + if ((mask & IN_MOVED_FROM) > 0) + return StandardWatchEventKind.ENTRY_DELETE; + return null; + } + + /** + * Process event from inotify + */ + private void processEvent(int wd, int mask, final UnixPath name) { + // overflow - signal all keys + if ((mask & IN_Q_OVERFLOW) > 0) { + for (Map.Entry<Integer,LinuxWatchKey> entry: wdToKey.entrySet()) { + entry.getValue() + .signalEvent(StandardWatchEventKind.OVERFLOW, null); + } + return; + } + + // lookup wd to get key + LinuxWatchKey key = wdToKey.get(wd); + if (key == null) + return; // should not happen + + // file deleted + if ((mask & IN_IGNORED) > 0) { + wdToKey.remove(wd); + key.invalidate(false); + key.signal(); + return; + } + + // event for directory itself + if (name == null) + return; + + // map to event and queue to key + WatchEvent.Kind<?> kind = maskToEventKind(mask); + if (kind != null) { + key.signalEvent(kind, name); + } + } + } + + // -- native methods -- + + private static native void init(); + + // sizeof inotify_event + private static native int eventSize(); + + // offsets of inotify_event + private static native int[] eventOffsets(); + + private static native int inotifyInit() throws UnixException; + + private static native int inotifyAddWatch(int fd, long pathAddress, int mask) + throws UnixException; + + private static native void inotifyRmWatch(int fd, int wd) + throws UnixException; + + private static native void configureBlocking(int fd, boolean blocking) + throws UnixException; + + private static native void socketpair(int[] sv) throws UnixException; + + private static native int poll(int fd1, int fd2) throws UnixException; + + static { + AccessController.doPrivileged(new PrivilegedAction<Void>() { + public Void run() { + System.loadLibrary("nio"); + return null; + }}); + init(); + } +} diff --git a/src/solaris/classes/sun/nio/fs/SolarisAclFileAttributeView.java b/src/solaris/classes/sun/nio/fs/SolarisAclFileAttributeView.java new file mode 100644 index 0000000000000000000000000000000000000000..e96361e20bae9a7553584943f24b8316ab34685d --- /dev/null +++ b/src/solaris/classes/sun/nio/fs/SolarisAclFileAttributeView.java @@ -0,0 +1,408 @@ +/* + * Copyright 2008-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 sun.nio.fs; + +import java.nio.file.*; +import java.nio.file.attribute.*; +import java.util.*; +import java.io.IOException; +import sun.misc.Unsafe; + +import static sun.nio.fs.UnixConstants.*; +import static sun.nio.fs.SolarisConstants.*; +import static sun.nio.fs.SolarisNativeDispatcher.*; + + +/** + * Solaris implementation of AclFileAttributeView with native support for + * NFSv4 ACLs on ZFS. + */ + +class SolarisAclFileAttributeView + extends AbstractAclFileAttributeView +{ + private static final Unsafe unsafe = Unsafe.getUnsafe(); + + // Maximum number of entries allowed in an ACL + private static final int MAX_ACL_ENTRIES = 1024; + + /** + * typedef struct ace { + * uid_t a_who; + * uitn32_t a_access_mark; + * uint16_t a_flags; + * uint16_t a_type; + * } act_t; + */ + private static final short SIZEOF_ACE_T = 12; + private static final short OFFSETOF_UID = 0; + private static final short OFFSETOF_MASK = 4; + private static final short OFFSETOF_FLAGS = 8; + private static final short OFFSETOF_TYPE = 10; + + private final UnixPath file; + private final boolean followLinks; + + SolarisAclFileAttributeView(UnixPath file, boolean followLinks) { + this.file = file; + this.followLinks = followLinks; + } + + /** + * Permission checks to access file + */ + private void checkAccess(UnixPath file, + boolean checkRead, + boolean checkWrite) + { + SecurityManager sm = System.getSecurityManager(); + if (sm != null) { + if (checkRead) + file.checkRead(); + if (checkWrite) + file.checkWrite(); + sm.checkPermission(new RuntimePermission("accessUserInformation")); + } + } + + /** + * Encode the ACL to the given buffer + */ + private static void encode(List<AclEntry> acl, long address) { + long offset = address; + for (AclEntry ace: acl) { + int flags = 0; + + // map UserPrincipal to uid and flags + UserPrincipal who = ace.principal(); + if (!(who instanceof UnixUserPrincipals)) + throw new ProviderMismatchException(); + UnixUserPrincipals.User user = (UnixUserPrincipals.User)who; + int uid; + if (user.isSpecial()) { + uid = -1; + if (who.getName().equals(UnixUserPrincipals.SPECIAL_OWNER.getName())) + flags |= ACE_OWNER; + else if (who.getName().equals(UnixUserPrincipals.SPECIAL_GROUP.getName())) + flags |= ACE_GROUP; + else if (who.getName().equals(UnixUserPrincipals.SPECIAL_EVERYONE.getName())) + flags |= ACE_EVERYONE; + else + throw new AssertionError("Unable to map special identifier"); + } else { + if (user instanceof UnixUserPrincipals.Group) { + uid = user.gid(); + flags |= ACE_IDENTIFIER_GROUP; + } else { + uid = user.uid(); + } + } + + // map ACE type + int type; + switch (ace.type()) { + case ALLOW: + type = ACE_ACCESS_ALLOWED_ACE_TYPE; + break; + case DENY: + type = ACE_ACCESS_DENIED_ACE_TYPE; + break; + case AUDIT: + type = ACE_SYSTEM_AUDIT_ACE_TYPE; + break; + case ALARM: + type = ACE_SYSTEM_ALARM_ACE_TYPE; + break; + default: + throw new AssertionError("Unable to map ACE type"); + } + + // map permissions + Set<AclEntryPermission> aceMask = ace.permissions(); + int mask = 0; + if (aceMask.contains(AclEntryPermission.READ_DATA)) + mask |= ACE_READ_DATA; + if (aceMask.contains(AclEntryPermission.WRITE_DATA)) + mask |= ACE_WRITE_DATA; + if (aceMask.contains(AclEntryPermission.APPEND_DATA)) + mask |= ACE_APPEND_DATA; + if (aceMask.contains(AclEntryPermission.READ_NAMED_ATTRS)) + mask |= ACE_READ_NAMED_ATTRS; + if (aceMask.contains(AclEntryPermission.WRITE_NAMED_ATTRS)) + mask |= ACE_WRITE_NAMED_ATTRS; + if (aceMask.contains(AclEntryPermission.EXECUTE)) + mask |= ACE_EXECUTE; + if (aceMask.contains(AclEntryPermission.DELETE_CHILD)) + mask |= ACE_DELETE_CHILD; + if (aceMask.contains(AclEntryPermission.READ_ATTRIBUTES)) + mask |= ACE_READ_ATTRIBUTES; + if (aceMask.contains(AclEntryPermission.WRITE_ATTRIBUTES)) + mask |= ACE_WRITE_ATTRIBUTES; + if (aceMask.contains(AclEntryPermission.DELETE)) + mask |= ACE_DELETE; + if (aceMask.contains(AclEntryPermission.READ_ACL)) + mask |= ACE_READ_ACL; + if (aceMask.contains(AclEntryPermission.WRITE_ACL)) + mask |= ACE_WRITE_ACL; + if (aceMask.contains(AclEntryPermission.WRITE_OWNER)) + mask |= ACE_WRITE_OWNER; + if (aceMask.contains(AclEntryPermission.SYNCHRONIZE)) + mask |= ACE_SYNCHRONIZE; + + // FIXME - it would be desirable to know here if the file is a + // directory or not. Solaris returns EINVAL if an ACE has a directory + // -only flag and the file is not a directory. + Set<AclEntryFlag> aceFlags = ace.flags(); + if (aceFlags.contains(AclEntryFlag.FILE_INHERIT)) + flags |= ACE_FILE_INHERIT_ACE; + if (aceFlags.contains(AclEntryFlag.DIRECTORY_INHERIT)) + flags |= ACE_DIRECTORY_INHERIT_ACE; + if (aceFlags.contains(AclEntryFlag.NO_PROPAGATE_INHERIT)) + flags |= ACE_NO_PROPAGATE_INHERIT_ACE; + if (aceFlags.contains(AclEntryFlag.INHERIT_ONLY)) + flags |= ACE_INHERIT_ONLY_ACE; + + unsafe.putInt(offset + OFFSETOF_UID, uid); + unsafe.putInt(offset + OFFSETOF_MASK, mask); + unsafe.putShort(offset + OFFSETOF_FLAGS, (short)flags); + unsafe.putShort(offset + OFFSETOF_TYPE, (short)type); + + offset += SIZEOF_ACE_T; + } + } + + /** + * Decode the buffer, returning an ACL + */ + private static List<AclEntry> decode(long address, int n) { + ArrayList<AclEntry> acl = new ArrayList<AclEntry>(n); + for (int i=0; i<n; i++) { + long offset = address + i*SIZEOF_ACE_T; + + int uid = unsafe.getInt(offset + OFFSETOF_UID); + int mask = unsafe.getInt(offset + OFFSETOF_MASK); + int flags = (int)unsafe.getShort(offset + OFFSETOF_FLAGS); + int type = (int)unsafe.getShort(offset + OFFSETOF_TYPE); + + // map uid and flags to UserPrincipal + UnixUserPrincipals.User who = null; + if (uid == -1) { + if ((flags & ACE_OWNER) > 0) + who = UnixUserPrincipals.SPECIAL_OWNER; + if ((flags & ACE_GROUP) > 0) + who = UnixUserPrincipals.SPECIAL_GROUP; + if ((flags & ACE_EVERYONE) > 0) + who = UnixUserPrincipals.SPECIAL_EVERYONE; + if (who == null) + throw new AssertionError("ACE who not handled"); + } else { + // can be gid + if ((flags & ACE_IDENTIFIER_GROUP) > 0) + who = UnixUserPrincipals.fromGid(uid); + else + who = UnixUserPrincipals.fromUid(uid); + } + + AclEntryType aceType = null; + switch (type) { + case ACE_ACCESS_ALLOWED_ACE_TYPE: + aceType = AclEntryType.ALLOW; + break; + case ACE_ACCESS_DENIED_ACE_TYPE: + aceType = AclEntryType.DENY; + break; + case ACE_SYSTEM_AUDIT_ACE_TYPE: + aceType = AclEntryType.AUDIT; + break; + case ACE_SYSTEM_ALARM_ACE_TYPE: + aceType = AclEntryType.ALARM; + break; + default: + assert false; + } + + HashSet<AclEntryPermission> aceMask = new HashSet<AclEntryPermission>(); + if ((mask & ACE_READ_DATA) > 0) + aceMask.add(AclEntryPermission.READ_DATA); + if ((mask & ACE_WRITE_DATA) > 0) + aceMask.add(AclEntryPermission.WRITE_DATA); + if ((mask & ACE_APPEND_DATA ) > 0) + aceMask.add(AclEntryPermission.APPEND_DATA); + if ((mask & ACE_READ_NAMED_ATTRS) > 0) + aceMask.add(AclEntryPermission.READ_NAMED_ATTRS); + if ((mask & ACE_WRITE_NAMED_ATTRS) > 0) + aceMask.add(AclEntryPermission.WRITE_NAMED_ATTRS); + if ((mask & ACE_EXECUTE) > 0) + aceMask.add(AclEntryPermission.EXECUTE); + if ((mask & ACE_DELETE_CHILD ) > 0) + aceMask.add(AclEntryPermission.DELETE_CHILD); + if ((mask & ACE_READ_ATTRIBUTES) > 0) + aceMask.add(AclEntryPermission.READ_ATTRIBUTES); + if ((mask & ACE_WRITE_ATTRIBUTES) > 0) + aceMask.add(AclEntryPermission.WRITE_ATTRIBUTES); + if ((mask & ACE_DELETE) > 0) + aceMask.add(AclEntryPermission.DELETE); + if ((mask & ACE_READ_ACL) > 0) + aceMask.add(AclEntryPermission.READ_ACL); + if ((mask & ACE_WRITE_ACL) > 0) + aceMask.add(AclEntryPermission.WRITE_ACL); + if ((mask & ACE_WRITE_OWNER) > 0) + aceMask.add(AclEntryPermission.WRITE_OWNER); + if ((mask & ACE_SYNCHRONIZE) > 0) + aceMask.add(AclEntryPermission.SYNCHRONIZE); + + HashSet<AclEntryFlag> aceFlags = new HashSet<AclEntryFlag>(); + if ((flags & ACE_FILE_INHERIT_ACE) > 0) + aceFlags.add(AclEntryFlag.FILE_INHERIT); + if ((flags & ACE_DIRECTORY_INHERIT_ACE) > 0) + aceFlags.add(AclEntryFlag.DIRECTORY_INHERIT); + if ((flags & ACE_NO_PROPAGATE_INHERIT_ACE) > 0) + aceFlags.add(AclEntryFlag.NO_PROPAGATE_INHERIT); + if ((flags & ACE_INHERIT_ONLY_ACE ) > 0) + aceFlags.add(AclEntryFlag.INHERIT_ONLY); + + // build the ACL entry and add it to the list + AclEntry ace = AclEntry.newBuilder() + .setType(aceType) + .setPrincipal(who) + .setPermissions(aceMask).setFlags(aceFlags).build(); + acl.add(ace); + } + + return acl; + } + + // Retrns true if NFSv4 ACLs not enabled on file system + private static boolean isAclsEnabled(int fd) { + try { + long enabled = fpathconf(fd, _PC_ACL_ENABLED); + if (enabled == _ACL_ACE_ENABLED) + return true; + } catch (UnixException x) { + } + return false; + } + + @Override + public List<AclEntry> getAcl() + throws IOException + { + // permission check + checkAccess(file, true, false); + + // open file (will fail if file is a link and not following links) + int fd = file.openForAttributeAccess(followLinks); + try { + long address = unsafe.allocateMemory(SIZEOF_ACE_T * MAX_ACL_ENTRIES); + try { + // read ACL and decode it + int n = facl(fd, ACE_GETACL, MAX_ACL_ENTRIES, address); + assert n >= 0; + return decode(address, n); + } catch (UnixException x) { + if ((x.errno() == ENOSYS) || !isAclsEnabled(fd)) { + throw new FileSystemException(file.getPathForExecptionMessage(), + null, x.getMessage() + " (file system does not support NFSv4 ACLs)"); + } + x.rethrowAsIOException(file); + return null; // keep compiler happy + } finally { + unsafe.freeMemory(address); + } + } finally { + close(fd); + } + } + + @Override + public void setAcl(List<AclEntry> acl) throws IOException { + // permission check + checkAccess(file, false, true); + + // open file (will fail if file is a link and not following links) + int fd = file.openForAttributeAccess(followLinks); + try { + // SECURITY: need to copy list as can change during processing + acl = new ArrayList<AclEntry>(acl); + int n = acl.size(); + + long address = unsafe.allocateMemory(SIZEOF_ACE_T * n); + try { + encode(acl, address); + facl(fd, ACE_SETACL, n, address); + } catch (UnixException x) { + if ((x.errno() == ENOSYS) || !isAclsEnabled(fd)) { + throw new FileSystemException(file.getPathForExecptionMessage(), + null, x.getMessage() + " (file system does not support NFSv4 ACLs)"); + } + if (x.errno() == EINVAL && (n < 3)) + throw new IOException("ACL must contain at least 3 entries"); + x.rethrowAsIOException(file); + } finally { + unsafe.freeMemory(address); + } + } finally { + close(fd); + } + } + + @Override + public UserPrincipal getOwner() + throws IOException + { + checkAccess(file, true, false); + + try { + UnixFileAttributes attrs = + UnixFileAttributes.get(file, followLinks); + return UnixUserPrincipals.fromUid(attrs.uid()); + } catch (UnixException x) { + x.rethrowAsIOException(file); + return null; // keep compile happy + } + } + + @Override + public void setOwner(UserPrincipal owner) throws IOException { + checkAccess(file, true, false); + + if (!(owner instanceof UnixUserPrincipals.User)) + throw new ProviderMismatchException(); + if (owner instanceof UnixUserPrincipals.Group) + throw new IOException("'owner' parameter is a group"); + int uid = ((UnixUserPrincipals.User)owner).uid(); + + try { + if (followLinks) { + lchown(file, uid, -1); + } else { + chown(file, uid, -1); + } + } catch (UnixException x) { + x.rethrowAsIOException(file); + } + } +} diff --git a/src/solaris/classes/sun/nio/fs/SolarisFileStore.java b/src/solaris/classes/sun/nio/fs/SolarisFileStore.java new file mode 100644 index 0000000000000000000000000000000000000000..bdf71a5593ce6df5fb45476e5990786ab9331bf5 --- /dev/null +++ b/src/solaris/classes/sun/nio/fs/SolarisFileStore.java @@ -0,0 +1,103 @@ +/* + * Copyright 2008-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 sun.nio.fs; + +import java.io.IOException; + +import static sun.nio.fs.UnixNativeDispatcher.*; +import static sun.nio.fs.SolarisConstants.*; + +/** + * Solaris implementation of FileStore + */ + +class SolarisFileStore + extends UnixFileStore +{ + private final boolean xattrEnabled; + + SolarisFileStore(UnixPath file) throws IOException { + super(file); + this.xattrEnabled = xattrEnabled(); + } + + SolarisFileStore(UnixFileSystem fs, UnixMountEntry entry) throws IOException { + super(fs, entry); + this.xattrEnabled = xattrEnabled(); + } + + // returns true if extended attributes enabled + private boolean xattrEnabled() { + long res = 0L; + try { + res = pathconf(file(), _PC_XATTR_ENABLED); + } catch (UnixException x) { + // ignore + } + return (res != 0L); + } + + @Override + UnixMountEntry findMountEntry() throws IOException { + // On Solaris iterate over the entries in the mount table to find device + for (UnixMountEntry entry: file().getFileSystem().getMountEntries()) { + if (entry.dev() == dev()) { + return entry; + } + } + throw new IOException("Device not found in mnttab"); + } + + @Override + public boolean supportsFileAttributeView(String name) { + if (name.equals("acl")) { + // lookup fstypes.properties + FeatureStatus status = checkIfFeaturePresent("nfsv4acl"); + if (status == FeatureStatus.PRESENT) + return true; + if (status == FeatureStatus.NOT_PRESENT) + return false; + // AclFileAttributeView available on ZFS + return (type().equals("zfs")); + } + if (name.equals("xattr")) { + // lookup fstypes.properties + FeatureStatus status = checkIfFeaturePresent("xattr"); + if (status == FeatureStatus.PRESENT) + return true; + if (status == FeatureStatus.NOT_PRESENT) + return false; + return xattrEnabled; + } + + return super.supportsFileAttributeView(name); + } + + @Override + boolean isLoopback() { + return type().equals("lofs"); + } +} diff --git a/src/solaris/classes/sun/nio/fs/SolarisFileSystem.java b/src/solaris/classes/sun/nio/fs/SolarisFileSystem.java new file mode 100644 index 0000000000000000000000000000000000000000..fa7f34f53b05687aca88081d574f415852cd3d63 --- /dev/null +++ b/src/solaris/classes/sun/nio/fs/SolarisFileSystem.java @@ -0,0 +1,164 @@ +/* + * Copyright 2008-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 sun.nio.fs; + +import java.nio.file.*; +import java.nio.file.attribute.*; +import java.io.IOException; +import java.util.*; +import java.security.AccessController; +import sun.security.action.GetPropertyAction; +import static sun.nio.fs.UnixNativeDispatcher.*; + +/** + * Solaris implementation of FileSystem + */ + +class SolarisFileSystem extends UnixFileSystem { + private final boolean hasSolaris11Features; + + SolarisFileSystem(UnixFileSystemProvider provider, String dir) { + super(provider, dir); + + // check os.version + String osversion = AccessController + .doPrivileged(new GetPropertyAction("os.version")); + String[] vers = osversion.split("\\.", 0); + assert vers.length >= 2; + int majorVersion = Integer.parseInt(vers[0]); + int minorVersion = Integer.parseInt(vers[1]); + this.hasSolaris11Features = + (majorVersion > 5 || (majorVersion == 5 && minorVersion >= 11)); + } + + @Override + boolean isSolaris() { + return true; + } + + @Override + public WatchService newWatchService() + throws IOException + { + // FEN available since Solaris 11 + if (hasSolaris11Features) { + return new SolarisWatchService(this); + } else { + return new PollingWatchService(); + } + } + + @Override + @SuppressWarnings("unchecked") + public <V extends FileAttributeView> V newFileAttributeView(Class<V> view, + UnixPath file, LinkOption... options) + { + if (view == AclFileAttributeView.class) + return (V) new SolarisAclFileAttributeView(file, followLinks(options)); + if (view == UserDefinedFileAttributeView.class) { + return(V) new SolarisUserDefinedFileAttributeView(file, followLinks(options)); + } + return super.newFileAttributeView(view, file, options); + } + + @Override + protected FileAttributeView newFileAttributeView(String name, + UnixPath file, + LinkOption... options) + { + if (name.equals("acl")) + return new SolarisAclFileAttributeView(file, followLinks(options)); + if (name.equals("xattr")) + return new SolarisUserDefinedFileAttributeView(file, followLinks(options)); + return super.newFileAttributeView(name, file, options); + } + + // lazy initialization of the list of supported attribute views + private static class SupportedFileFileAttributeViewsHolder { + static final Set<String> supportedFileAttributeViews = + supportedFileAttributeViews(); + private static Set<String> supportedFileAttributeViews() { + Set<String> result = new HashSet<String>(); + result.addAll(UnixFileSystem.standardFileAttributeViews()); + // additional Solaris-specific views + result.add("acl"); + result.add("xattr"); + return Collections.unmodifiableSet(result); + } + } + + @Override + public Set<String> supportedFileAttributeViews() { + return SupportedFileFileAttributeViewsHolder.supportedFileAttributeViews; + } + + @Override + void copyNonPosixAttributes(int ofd, int nfd) { + SolarisUserDefinedFileAttributeView.copyExtendedAttributes(ofd, nfd); + // TDB: copy ACL from source to target + } + + @Override + boolean supportsSecureDirectoryStreams() { + return true; + } + + /** + * Returns object to iterate over entries in /etc/mnttab + */ + @Override + Iterable<UnixMountEntry> getMountEntries() { + ArrayList<UnixMountEntry> entries = new ArrayList<UnixMountEntry>(); + try { + UnixPath mnttab = new UnixPath(this, "/etc/mnttab"); + long fp = fopen(mnttab, "r"); + try { + for (;;) { + UnixMountEntry entry = new UnixMountEntry(); + int res = getextmntent(fp, entry); + if (res < 0) + break; + entries.add(entry); + } + } finally { + fclose(fp); + } + } catch (UnixException x) { + // nothing we can do + } + return entries; + } + + @Override + FileStore getFileStore(UnixPath path) throws IOException { + return new SolarisFileStore(path); + } + + @Override + FileStore getFileStore(UnixMountEntry entry) throws IOException { + return new SolarisFileStore(this, entry); + } +} diff --git a/src/solaris/classes/sun/nio/fs/SolarisFileSystemProvider.java b/src/solaris/classes/sun/nio/fs/SolarisFileSystemProvider.java new file mode 100644 index 0000000000000000000000000000000000000000..9d3c0845773bf2552b216b26e70254a708c98d9a --- /dev/null +++ b/src/solaris/classes/sun/nio/fs/SolarisFileSystemProvider.java @@ -0,0 +1,41 @@ +/* + * Copyright 2008-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 sun.nio.fs; + +/** + * Solaris implementation of FileSystemProvider + */ + +public class SolarisFileSystemProvider extends UnixFileSystemProvider { + public SolarisFileSystemProvider() { + super(); + } + + @Override + SolarisFileSystem newFileSystem(String dir) { + return new SolarisFileSystem(this, dir); + } +} diff --git a/src/solaris/classes/sun/nio/fs/SolarisNativeDispatcher.java b/src/solaris/classes/sun/nio/fs/SolarisNativeDispatcher.java new file mode 100644 index 0000000000000000000000000000000000000000..36f2326ce7676b4939f08cf190b781992d1ab386 --- /dev/null +++ b/src/solaris/classes/sun/nio/fs/SolarisNativeDispatcher.java @@ -0,0 +1,56 @@ +/* + * Copyright 2008-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 sun.nio.fs; + +import java.security.AccessController; +import java.security.PrivilegedAction; + +/** + * Solaris specific system calls. + */ + +class SolarisNativeDispatcher extends UnixNativeDispatcher { + private SolarisNativeDispatcher() { } + + /** + * int facl(int filedes, int cmd, int nentries, void aclbufp) + */ + static native int facl(int fd, int cmd, int nentries, long aclbufp) + throws UnixException; + + + // initialize + private static native void init(); + + static { + AccessController.doPrivileged(new PrivilegedAction<Void>() { + public Void run() { + System.loadLibrary("nio"); + return null; + }}); + init(); + } +} diff --git a/src/solaris/classes/sun/nio/fs/SolarisUserDefinedFileAttributeView.java b/src/solaris/classes/sun/nio/fs/SolarisUserDefinedFileAttributeView.java new file mode 100644 index 0000000000000000000000000000000000000000..040628f60931f49b41ed57165946a62f192a4161 --- /dev/null +++ b/src/solaris/classes/sun/nio/fs/SolarisUserDefinedFileAttributeView.java @@ -0,0 +1,293 @@ +/* + * Copyright 2008-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 sun.nio.fs; + +import java.nio.file.*; +import java.nio.ByteBuffer; +import java.nio.channels.FileChannel; +import java.io.IOException; +import java.util.*; + +import static sun.nio.fs.UnixNativeDispatcher.*; +import static sun.nio.fs.UnixConstants.*; +import static sun.nio.fs.SolarisConstants.*; + +/** + * Solaris emulation of NamedAttributeView using extended attributes. + */ + +class SolarisUserDefinedFileAttributeView + extends AbstractUserDefinedFileAttributeView +{ + private byte[] nameAsBytes(UnixPath file, String name) throws IOException { + byte[] bytes = name.getBytes(); + // "", "." and ".." not allowed + if (bytes.length == 0 || bytes[0] == '.') { + if (bytes.length <= 1 || + (bytes.length == 2 && bytes[1] == '.')) + { + throw new FileSystemException(file.getPathForExecptionMessage(), + null, "'" + name + "' is not a valid name"); + } + } + return bytes; + } + + private final UnixPath file; + private final boolean followLinks; + + SolarisUserDefinedFileAttributeView(UnixPath file, boolean followLinks) { + this.file = file; + this.followLinks = followLinks; + } + + @Override + public List<String> list() throws IOException { + if (System.getSecurityManager() != null) + checkAccess(file.getPathForPermissionCheck(), true, false); + + int fd = file.openForAttributeAccess(followLinks); + try { + try { + // open extended attribute directory + int dfd = openat(fd, ".".getBytes(), (O_RDONLY|O_XATTR), 0); + long dp; + try { + dp = fdopendir(dfd); + } catch (UnixException x) { + close(dfd); + throw x; + } + + // read list of extended attributes + final List<String> list = new ArrayList<String>(); + try { + byte[] name; + while ((name = readdir(dp)) != null) { + String s = new String(name); + if (!s.equals(".") && !s.equals("..")) + list.add(s); + } + } finally { + closedir(dp); + } + return Collections.unmodifiableList(list); + } catch (UnixException x) { + throw new FileSystemException(file.getPathForExecptionMessage(), + null, "Unable to get list of extended attributes: " + + x.getMessage()); + } + } finally { + close(fd); + } + } + + @Override + public int size(String name) throws IOException { + if (System.getSecurityManager() != null) + checkAccess(file.getPathForPermissionCheck(), true, false); + + int fd = file.openForAttributeAccess(followLinks); + try { + try { + // open attribute file + int afd = openat(fd, nameAsBytes(file,name), (O_RDONLY|O_XATTR), 0); + try { + // read attribute's attributes + UnixFileAttributes attrs = UnixFileAttributes.get(afd); + long size = attrs.size(); + if (size > Integer.MAX_VALUE) + throw new ArithmeticException("Extended attribute value too large"); + return (int)size; + } finally { + close(afd); + } + } catch (UnixException x) { + throw new FileSystemException(file.getPathForExecptionMessage(), + null, "Unable to get size of extended attribute '" + name + + "': " + x.getMessage()); + } + } finally { + close(fd); + } + } + + @Override + public int read(String name, ByteBuffer dst) throws IOException { + if (System.getSecurityManager() != null) + checkAccess(file.getPathForPermissionCheck(), true, false); + + int fd = file.openForAttributeAccess(followLinks); + try { + try { + // open attribute file + int afd = openat(fd, nameAsBytes(file,name), (O_RDONLY|O_XATTR), 0); + + // wrap with channel + FileChannel fc = UnixChannelFactory.newFileChannel(afd, true, false); + + // read to EOF (nothing we can do if I/O error occurs) + try { + if (fc.size() > dst.remaining()) + throw new IOException("Extended attribute file too large"); + int total = 0; + while (dst.hasRemaining()) { + int n = fc.read(dst); + if (n < 0) + break; + total += n; + } + return total; + } finally { + fc.close(); + } + } catch (UnixException x) { + throw new FileSystemException(file.getPathForExecptionMessage(), + null, "Unable to read extended attribute '" + name + + "': " + x.getMessage()); + } + } finally { + close(fd); + } + } + + @Override + public int write(String name, ByteBuffer src) throws IOException { + if (System.getSecurityManager() != null) + checkAccess(file.getPathForPermissionCheck(), false, true); + + int fd = file.openForAttributeAccess(followLinks); + try { + try { + // open/create attribute file + int afd = openat(fd, nameAsBytes(file,name), + (O_CREAT|O_WRONLY|O_TRUNC|O_XATTR), + UnixFileModeAttribute.ALL_PERMISSIONS); + + // wrap with channel + FileChannel fc = UnixChannelFactory.newFileChannel(afd, false, true); + + // write value (nothing we can do if I/O error occurs) + try { + int rem = src.remaining(); + while (src.hasRemaining()) { + fc.write(src); + } + return rem; + } finally { + fc.close(); + } + } catch (UnixException x) { + throw new FileSystemException(file.getPathForExecptionMessage(), + null, "Unable to write extended attribute '" + name + + "': " + x.getMessage()); + } + } finally { + close(fd); + } + } + + @Override + public void delete(String name) throws IOException { + if (System.getSecurityManager() != null) + checkAccess(file.getPathForPermissionCheck(), false, true); + + int fd = file.openForAttributeAccess(followLinks); + try { + int dfd = openat(fd, ".".getBytes(), (O_RDONLY|O_XATTR), 0); + try { + unlinkat(dfd, nameAsBytes(file,name), 0); + } finally { + close(dfd); + } + } catch (UnixException x) { + throw new FileSystemException(file.getPathForExecptionMessage(), + null, "Unable to delete extended attribute '" + name + + "': " + x.getMessage()); + } finally { + close(fd); + } + } + + /** + * Used by copyTo/moveTo to copy extended attributes from source to target. + * + * @param ofd + * file descriptor for source file + * @param nfd + * file descriptor for target file + */ + static void copyExtendedAttributes(int ofd, int nfd) { + try { + // open extended attribute directory + int dfd = openat(ofd, ".".getBytes(), (O_RDONLY|O_XATTR), 0); + long dp = 0L; + try { + dp = fdopendir(dfd); + } catch (UnixException x) { + close(dfd); + throw x; + } + + // copy each extended attribute + try { + byte[] name; + while ((name = readdir(dp)) != null) { + // ignore "." and ".." + if (name[0] == '.') { + if (name.length == 1) + continue; + if (name.length == 2 && name[1] == '.') + continue; + } + copyExtendedAttribute(ofd, name, nfd); + } + } finally { + closedir(dp); + } + } catch (UnixException ignore) { + } + } + + private static void copyExtendedAttribute(int ofd, byte[] name, int nfd) + throws UnixException + { + // open source attribute file + int src = openat(ofd, name, (O_RDONLY|O_XATTR), 0); + try { + // create target attribute file + int dst = openat(nfd, name, (O_CREAT|O_WRONLY|O_TRUNC|O_XATTR), + UnixFileModeAttribute.ALL_PERMISSIONS); + try { + UnixCopyFile.transfer(dst, src, 0L); + } finally { + close(dst); + } + } finally { + close(src); + } + } +} diff --git a/src/solaris/classes/sun/nio/fs/SolarisWatchService.java b/src/solaris/classes/sun/nio/fs/SolarisWatchService.java new file mode 100644 index 0000000000000000000000000000000000000000..6a11ebdd7f74f099fc6cdb5ebd680b30fb6f4e54 --- /dev/null +++ b/src/solaris/classes/sun/nio/fs/SolarisWatchService.java @@ -0,0 +1,770 @@ +/* + * Copyright 2008-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 sun.nio.fs; + +import java.nio.file.*; +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.util.*; +import java.io.IOException; +import sun.misc.Unsafe; + +import static sun.nio.fs.UnixConstants.*; + +/** + * Solaris implementation of WatchService based on file events notification + * facility. + */ + +class SolarisWatchService + extends AbstractWatchService +{ + private static final Unsafe unsafe = Unsafe.getUnsafe(); + private static int addressSize = unsafe.addressSize(); + + private static int dependsArch(int value32, int value64) { + return (addressSize == 4) ? value32 : value64; + } + + /* + * typedef struct port_event { + * int portev_events; + * ushort_t portev_source; + * ushort_t portev_pad; + * uintptr_t portev_object; + * void *portev_user; + * } port_event_t; + */ + private static final int SIZEOF_PORT_EVENT = dependsArch(16, 24); + private static final int OFFSETOF_EVENTS = 0; + private static final int OFFSETOF_SOURCE = 4; + private static final int OFFSETOF_OBJECT = 8; + + /* + * typedef struct file_obj { + * timestruc_t fo_atime; + * timestruc_t fo_mtime; + * timestruc_t fo_ctime; + * uintptr_t fo_pad[3]; + * char *fo_name; + * } file_obj_t; + */ + private static final int SIZEOF_FILEOBJ = dependsArch(40, 80); + private static final int OFFSET_FO_NAME = dependsArch(36, 72); + + // port sources + private static final short PORT_SOURCE_USER = 3; + private static final short PORT_SOURCE_FILE = 7; + + // user-watchable events + private static final int FILE_MODIFIED = 0x00000002; + private static final int FILE_ATTRIB = 0x00000004; + private static final int FILE_NOFOLLOW = 0x10000000; + + // exception events + private static final int FILE_DELETE = 0x00000010; + private static final int FILE_RENAME_TO = 0x00000020; + private static final int FILE_RENAME_FROM = 0x00000040; + private static final int UNMOUNTED = 0x20000000; + private static final int MOUNTEDOVER = 0x40000000; + + // background thread to read change events + private final Poller poller; + + SolarisWatchService(UnixFileSystem fs) throws IOException { + int port = -1; + try { + port = portCreate(); + } catch (UnixException x) { + throw new IOException(x.errorString()); + } + + this.poller = new Poller(fs, this, port); + this.poller.start(); + } + + @Override + WatchKey register(Path dir, + WatchEvent.Kind<?>[] events, + WatchEvent.Modifier... modifiers) + throws IOException + { + // delegate to poller + return poller.register(dir, events, modifiers); + } + + @Override + void implClose() throws IOException { + // delegate to poller + poller.close(); + } + + /** + * WatchKey implementation + */ + private class SolarisWatchKey extends AbstractWatchKey + implements DirectoryNode + { + private final UnixPath dir; + private final UnixFileKey fileKey; + + // pointer to native file_obj object + private final long object; + + // events (may be changed). set to null when watch key is invalid + private volatile Set<? extends WatchEvent.Kind<?>> events; + + // map of entries in directory; created lazily; accessed only by + // poller thread. + private Map<Path,EntryNode> children; + + SolarisWatchKey(SolarisWatchService watcher, + UnixPath dir, + UnixFileKey fileKey, + long object, + Set<? extends WatchEvent.Kind<?>> events) + { + super(watcher); + this.dir = dir; + this.fileKey = fileKey; + this.object = object; + this.events = events; + } + + UnixPath getFileRef() { + return dir; + } + + UnixFileKey getFileKey() { + return fileKey; + } + + @Override + public long object() { + return object; + } + + void invalidate() { + events = null; + } + + Set<? extends WatchEvent.Kind<?>> events() { + return events; + } + + void setEvents(Set<? extends WatchEvent.Kind<?>> events) { + this.events = events; + } + + @Override + public boolean isValid() { + return events != null; + } + + @Override + public void cancel() { + if (isValid()) { + // delegate to poller + poller.cancel(this); + } + } + + @Override + public void addChild(Path name, EntryNode node) { + if (children == null) + children = new HashMap<Path,EntryNode>(); + children.put(name, node); + } + + @Override + public void removeChild(Path name) { + children.remove(name); + } + + @Override + public EntryNode getChild(Path name) { + if (children != null) + return children.get(name); + return null; + } + } + + /** + * Background thread to read from port + */ + private class Poller extends AbstractPoller { + + // maximum number of events to read per call to port_getn + private static final int MAX_EVENT_COUNT = 128; + + // events that map to ENTRY_DELETE + private static final int FILE_REMOVED = + (FILE_DELETE|FILE_RENAME_TO|FILE_RENAME_FROM); + + // events that tell us not to re-associate the object + private static final int FILE_EXCEPTION = + (FILE_REMOVED|UNMOUNTED|MOUNTEDOVER); + + // address of event buffers (used to receive events with port_getn) + private final long bufferAddress; + + private final SolarisWatchService watcher; + + // the I/O port + private final int port; + + // maps file key (dev/inode) to WatchKey + private final Map<UnixFileKey,SolarisWatchKey> fileKey2WatchKey; + + // maps file_obj object to Node + private final Map<Long,Node> object2Node; + + /** + * Create a new instance + */ + Poller(UnixFileSystem fs, SolarisWatchService watcher, int port) { + this.watcher = watcher; + this.port = port; + this.bufferAddress = + unsafe.allocateMemory(SIZEOF_PORT_EVENT * MAX_EVENT_COUNT); + this.fileKey2WatchKey = new HashMap<UnixFileKey,SolarisWatchKey>(); + this.object2Node = new HashMap<Long,Node>(); + } + + @Override + void wakeup() throws IOException { + // write to port to wakeup polling thread + try { + portSend(port, 0); + } catch (UnixException x) { + throw new IOException(x.errorString()); + } + } + + @Override + Object implRegister(Path obj, + Set<? extends WatchEvent.Kind<?>> events, + WatchEvent.Modifier... modifiers) + { + // no modifiers supported at this time + if (modifiers.length > 0) { + for (WatchEvent.Modifier modifier: modifiers) { + if (modifier == null) + return new NullPointerException(); + if (modifier instanceof com.sun.nio.file.SensitivityWatchEventModifier) + continue; // ignore + return new UnsupportedOperationException("Modifier not supported"); + } + } + + UnixPath dir = (UnixPath)obj; + + // check file is directory + UnixFileAttributes attrs = null; + try { + attrs = UnixFileAttributes.get(dir, true); + } catch (UnixException x) { + return x.asIOException(dir); + } + if (!attrs.isDirectory()) { + return new NotDirectoryException(dir.getPathForExecptionMessage()); + } + + // return existing watch key after updating events if already + // registered + UnixFileKey fileKey = attrs.fileKey(); + SolarisWatchKey watchKey = fileKey2WatchKey.get(fileKey); + if (watchKey != null) { + updateEvents(watchKey, events); + return watchKey; + } + + // register directory + long object = 0L; + try { + object = registerImpl(dir, (FILE_MODIFIED | FILE_ATTRIB)); + } catch (UnixException x) { + return x.asIOException(dir); + } + + // create watch key and insert it into maps + watchKey = new SolarisWatchKey(watcher, dir, fileKey, object, events); + object2Node.put(object, watchKey); + fileKey2WatchKey.put(fileKey, watchKey); + + // register all entries in directory + registerChildren(dir, watchKey, false); + + return watchKey; + } + + // cancel single key + @Override + void implCancelKey(WatchKey obj) { + SolarisWatchKey key = (SolarisWatchKey)obj; + if (key.isValid()) { + fileKey2WatchKey.remove(key.getFileKey()); + + // release resources for entries in directory + if (key.children != null) { + for (Map.Entry<Path,EntryNode> entry: key.children.entrySet()) { + EntryNode node = entry.getValue(); + long object = node.object(); + object2Node.remove(object); + releaseObject(object, true); + } + } + + // release resources for directory + long object = key.object(); + object2Node.remove(object); + releaseObject(object, true); + + // and finally invalidate the key + key.invalidate(); + } + } + + // close watch service + @Override + void implCloseAll() { + // release all native resources + for (Long object: object2Node.keySet()) { + releaseObject(object, true); + } + + // invalidate all keys + for (Map.Entry<UnixFileKey,SolarisWatchKey> entry: fileKey2WatchKey.entrySet()) { + entry.getValue().invalidate(); + } + + // clean-up + object2Node.clear(); + fileKey2WatchKey.clear(); + + // free global resources + unsafe.freeMemory(bufferAddress); + UnixNativeDispatcher.close(port); + } + + /** + * Poller main loop. Blocks on port_getn waiting for events and then + * processes them. + */ + @Override + public void run() { + try { + for (;;) { + int n = portGetn(port, bufferAddress, MAX_EVENT_COUNT); + assert n > 0; + + long address = bufferAddress; + for (int i=0; i<n; i++) { + boolean shutdown = processEvent(address); + if (shutdown) + return; + address += SIZEOF_PORT_EVENT; + } + } + } catch (UnixException x) { + x.printStackTrace(); + } + } + + /** + * Process a single port_event + * + * Returns true if poller thread is requested to shutdown. + */ + boolean processEvent(long address) { + // pe->portev_source + short source = unsafe.getShort(address + OFFSETOF_SOURCE); + // pe->portev_object + long object = unsafe.getAddress(address + OFFSETOF_OBJECT); + // pe->portev_events + int events = unsafe.getInt(address + OFFSETOF_EVENTS); + + // user event is trigger to process pending requests + if (source != PORT_SOURCE_FILE) { + if (source == PORT_SOURCE_USER) { + // process any pending requests + boolean shutdown = processRequests(); + if (shutdown) + return true; + } + return false; + } + + // lookup object to get Node + Node node = object2Node.get(object); + if (node == null) { + // should not happen + return false; + } + + // As a workaround for 6642290 and 6636438/6636412 we don't use + // FILE_EXCEPTION events to tell use not to register the file. + // boolean reregister = (events & FILE_EXCEPTION) == 0; + boolean reregister = true; + + // If node is EntryNode then event relates to entry in directory + // If node is a SolarisWatchKey (DirectoryNode) then event relates + // to a watched directory. + boolean isDirectory = (node instanceof SolarisWatchKey); + if (isDirectory) { + processDirectoryEvents((SolarisWatchKey)node, events); + } else { + boolean ignore = processEntryEvents((EntryNode)node, events); + if (ignore) + reregister = false; + } + + // need to re-associate to get further events + if (reregister) { + try { + events = FILE_MODIFIED | FILE_ATTRIB; + if (!isDirectory) events |= FILE_NOFOLLOW; + portAssociate(port, + PORT_SOURCE_FILE, + object, + events); + } catch (UnixException x) { + // unable to re-register + reregister = false; + } + } + + // object is not re-registered so release resources. If + // object is a watched directory then signal key + if (!reregister) { + // release resources + object2Node.remove(object); + releaseObject(object, false); + + // if watch key then signal it + if (isDirectory) { + SolarisWatchKey key = (SolarisWatchKey)node; + fileKey2WatchKey.remove( key.getFileKey() ); + key.invalidate(); + key.signal(); + } else { + // if entry then remove it from parent + EntryNode entry = (EntryNode)node; + SolarisWatchKey key = (SolarisWatchKey)entry.parent(); + key.removeChild(entry.name()); + } + } + + return false; + } + + /** + * Process directory events. If directory is modified then re-scan + * directory to register any new entries + */ + void processDirectoryEvents(SolarisWatchKey key, int mask) { + if ((mask & (FILE_MODIFIED | FILE_ATTRIB)) != 0) { + registerChildren(key.getFileRef(), key, + key.events().contains(StandardWatchEventKind.ENTRY_CREATE)); + } + } + + /** + * Process events for entries in registered directories. Returns {@code + * true} if events are ignored because the watch key has been cancelled. + */ + boolean processEntryEvents(EntryNode node, int mask) { + SolarisWatchKey key = (SolarisWatchKey)node.parent(); + Set<? extends WatchEvent.Kind<?>> events = key.events(); + if (events == null) { + // key has been cancelled so ignore event + return true; + } + + // entry modified + if (((mask & (FILE_MODIFIED | FILE_ATTRIB)) != 0) && + events.contains(StandardWatchEventKind.ENTRY_MODIFY)) + { + key.signalEvent(StandardWatchEventKind.ENTRY_MODIFY, node.name()); + } + + // entry removed + if (((mask & (FILE_REMOVED)) != 0) && + events.contains(StandardWatchEventKind.ENTRY_DELETE)) + { + // Due to 6636438/6636412 we may get a remove event for cases + // where a rmdir/unlink/rename is attempted but fails. Until + // this issue is resolved we re-lstat the file to check if it + // exists. If it exists then we ignore the event. To keep the + // workaround simple we don't check the st_ino so it isn't + // effective when the file is replaced. + boolean removed = true; + try { + UnixFileAttributes + .get(key.getFileRef().resolve(node.name()), false); + removed = false; + } catch (UnixException x) { } + + if (removed) + key.signalEvent(StandardWatchEventKind.ENTRY_DELETE, node.name()); + } + return false; + } + + /** + * Registers all entries in the given directory + * + * The {@code sendEvents} parameter indicates if ENTRY_CREATE events + * should be queued when new entries are found. When initially + * registering a directory then will always be false. When re-scanning + * a directory then it depends on if the event is enabled or not. + */ + void registerChildren(UnixPath dir, + SolarisWatchKey parent, + boolean sendEvents) + { + // if the ENTRY_MODIFY event is not enabled then we don't need + // modification events for entries in the directory + int events = FILE_NOFOLLOW; + if (parent.events().contains(StandardWatchEventKind.ENTRY_MODIFY)) + events |= (FILE_MODIFIED | FILE_ATTRIB); + + DirectoryStream<Path> stream = null; + try { + stream = dir.newDirectoryStream(); + } catch (IOException x) { + // nothing we can do + return; + } + try { + for (Path entry: stream) { + Path name = entry.getName(); + + // skip entry if already registered + if (parent.getChild(name) != null) + continue; + + // send ENTRY_CREATE if enabled + if (sendEvents) { + parent.signalEvent(StandardWatchEventKind.ENTRY_CREATE, name); + } + + // register it + long object = 0L; + try { + object = registerImpl((UnixPath)entry, events); + } catch (UnixException x) { + // can't register so ignore for now. + continue; + } + + // create node + EntryNode node = new EntryNode(object, entry.getName(), parent); + // tell the parent about it + parent.addChild(entry.getName(), node); + object2Node.put(object, node); + } + } catch (ConcurrentModificationException x) { + // error during iteration which we ignore for now + } finally { + try { + stream.close(); + } catch (IOException x) { } + } + } + + /** + * Update watch key's events. Where the ENTRY_MODIFY changes then we + * need to update the events of registered children. + */ + void updateEvents(SolarisWatchKey key, Set<? extends WatchEvent.Kind<?>> events) { + // update events, rembering if ENTRY_MODIFY was previously + // enabled or disabled. + boolean wasModifyEnabled = key.events() + .contains(StandardWatchEventKind.ENTRY_MODIFY); + key.setEvents(events); + + // check if ENTRY_MODIFY has changed + boolean isModifyEnabled = events + .contains(StandardWatchEventKind.ENTRY_MODIFY); + if (wasModifyEnabled == isModifyEnabled) { + return; + } + + // if changed then update events of children + if (key.children != null) { + int ev = FILE_NOFOLLOW; + if (isModifyEnabled) + ev |= (FILE_MODIFIED | FILE_ATTRIB); + + for (Map.Entry<Path,EntryNode> entry: key.children.entrySet()) { + long object = entry.getValue().object(); + try { + portAssociate(port, + PORT_SOURCE_FILE, + object, + ev); + } catch (UnixException x) { + // nothing we can do. + } + } + } + } + + /** + * Calls port_associate to register the given path. + * Returns pointer to fileobj structure that is allocated for + * the registration. + */ + long registerImpl(UnixPath dir, int events) + throws UnixException + { + // allocate memory for the path (file_obj->fo_name field) + byte[] path = dir.getByteArrayForSysCalls(); + int len = path.length; + long name = unsafe.allocateMemory(len+1); + unsafe.copyMemory(path, Unsafe.ARRAY_BYTE_BASE_OFFSET, null, + name, (long)len); + unsafe.putByte(name + len, (byte)0); + + // allocate memory for filedatanode structure - this is the object + // to port_associate + long object = unsafe.allocateMemory(SIZEOF_FILEOBJ); + unsafe.setMemory(null, object, SIZEOF_FILEOBJ, (byte)0); + unsafe.putAddress(object + OFFSET_FO_NAME, name); + + // associate the object with the port + try { + portAssociate(port, + PORT_SOURCE_FILE, + object, + events); + } catch (UnixException x) { + // debugging + if (x.errno() == EAGAIN) { + System.err.println("The maximum number of objects associated "+ + "with the port has been reached"); + } + + unsafe.freeMemory(name); + unsafe.freeMemory(object); + throw x; + } + return object; + } + + /** + * Frees all resources for an file_obj object; optionally remove + * association from port + */ + void releaseObject(long object, boolean dissociate) { + // remove association + if (dissociate) { + try { + portDissociate(port, PORT_SOURCE_FILE, object); + } catch (UnixException x) { + // ignore + } + } + + // free native memory + long name = unsafe.getAddress(object + OFFSET_FO_NAME); + unsafe.freeMemory(name); + unsafe.freeMemory(object); + } + } + + /** + * A node with native (file_obj) resources + */ + private static interface Node { + long object(); + } + + /** + * A directory node with a map of the entries in the directory + */ + private static interface DirectoryNode extends Node { + void addChild(Path name, EntryNode node); + void removeChild(Path name); + EntryNode getChild(Path name); + } + + /** + * An implementation of a node that is an entry in a directory. + */ + private static class EntryNode implements Node { + private final long object; + private final Path name; + private final DirectoryNode parent; + + EntryNode(long object, Path name, DirectoryNode parent) { + this.object = object; + this.name = name; + this.parent = parent; + } + + @Override + public long object() { + return object; + } + + Path name() { + return name; + } + + DirectoryNode parent() { + return parent; + } + } + + // -- native methods -- + + private static native void init(); + + private static native int portCreate() throws UnixException; + + private static native void portAssociate(int port, int source, long object, int events) + throws UnixException; + + private static native void portDissociate(int port, int source, long object) + throws UnixException; + + private static native void portSend(int port, int events) + throws UnixException; + + private static native int portGetn(int port, long address, int max) + throws UnixException; + + static { + AccessController.doPrivileged(new PrivilegedAction<Void>() { + public Void run() { + System.loadLibrary("nio"); + return null; + }}); + init(); + } +} diff --git a/src/solaris/classes/sun/nio/fs/UnixChannelFactory.java b/src/solaris/classes/sun/nio/fs/UnixChannelFactory.java new file mode 100644 index 0000000000000000000000000000000000000000..a8265dca7f6e8a0d2aecf465048ace7a9ff574e6 --- /dev/null +++ b/src/solaris/classes/sun/nio/fs/UnixChannelFactory.java @@ -0,0 +1,286 @@ +/* + * Copyright 2008-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 sun.nio.fs; + +import java.nio.file.*; +import java.nio.channels.*; +import java.io.FileDescriptor; +import java.util.Set; + +import sun.nio.ch.FileChannelImpl; +import sun.nio.ch.ThreadPool; +import sun.nio.ch.SimpleAsynchronousFileChannelImpl; +import sun.misc.SharedSecrets; +import sun.misc.JavaIOFileDescriptorAccess; + +import com.sun.nio.file.ExtendedOpenOption; + +import static sun.nio.fs.UnixNativeDispatcher.*; +import static sun.nio.fs.UnixConstants.*; + +/** + * Factory for FileChannels and AsynchronousFileChannels + */ + +class UnixChannelFactory { + private static final JavaIOFileDescriptorAccess fdAccess = + SharedSecrets.getJavaIOFileDescriptorAccess(); + + private UnixChannelFactory() { + } + + /** + * Represents the flags from a user-supplied set of open options. + */ + private static class Flags { + boolean read; + boolean write; + boolean append; + boolean truncateExisting; + boolean noFollowLinks; + boolean create; + boolean createNew; + boolean deleteOnClose; + boolean sync; + boolean dsync; + + static Flags toFlags(Set<? extends OpenOption> options) { + Flags flags = new Flags(); + for (OpenOption option: options) { + if (option instanceof StandardOpenOption) { + switch ((StandardOpenOption)option) { + case READ : flags.read = true; break; + case WRITE : flags.write = true; break; + case APPEND : flags.append = true; break; + case TRUNCATE_EXISTING : flags.truncateExisting = true; break; + case CREATE : flags.create = true; break; + case CREATE_NEW : flags.createNew = true; break; + case DELETE_ON_CLOSE : flags.deleteOnClose = true; break; + case SPARSE : /* ignore */ break; + case SYNC : flags.sync = true; break; + case DSYNC : flags.dsync = true; break; + default: throw new UnsupportedOperationException(); + } + continue; + } + if (option == LinkOption.NOFOLLOW_LINKS) { + flags.noFollowLinks = true; + continue; + } + if (option == null) + throw new NullPointerException(); + throw new UnsupportedOperationException(); + } + return flags; + } + } + + + /** + * Constructs a file channel from an existing (open) file descriptor + */ + static FileChannel newFileChannel(int fd, boolean reading, boolean writing) { + FileDescriptor fdObj = new FileDescriptor(); + fdAccess.set(fdObj, fd); + return FileChannelImpl.open(fdObj, reading, writing, null); + } + + /** + * Constructs a file channel by opening a file using a dfd/path pair + */ + static FileChannel newFileChannel(int dfd, + UnixPath path, + String pathForPermissionCheck, + Set<? extends OpenOption> options, + int mode) + throws UnixException + { + Flags flags = Flags.toFlags(options); + + // default is reading; append => writing + if (!flags.read && !flags.write) { + if (flags.append) { + flags.write = true; + } else { + flags.read = true; + } + } + + // validation + if (flags.read && flags.append) + throw new IllegalArgumentException("READ + APPEND not allowed"); + if (flags.append && flags.truncateExisting) + throw new IllegalArgumentException("APPEND + TRUNCATE_EXISTING not allowed"); + + FileDescriptor fdObj = open(dfd, path, pathForPermissionCheck, flags, mode); + return FileChannelImpl.open(fdObj, flags.read, flags.write, null); + } + + /** + * Constructs a file channel by opening the given file. + */ + static FileChannel newFileChannel(UnixPath path, + Set<? extends OpenOption> options, + int mode) + throws UnixException + { + return newFileChannel(-1, path, null, options, mode); + } + + /** + * Constructs an asynchronous file channel by opening the given file. + */ + static AsynchronousFileChannel newAsynchronousFileChannel(UnixPath path, + Set<? extends OpenOption> options, + int mode, + ThreadPool pool) + throws UnixException + { + Flags flags = Flags.toFlags(options); + + // default is reading + if (!flags.read && !flags.write) { + flags.read = true; + } + + // validation + if (flags.append) + throw new UnsupportedOperationException("APPEND not allowed"); + + // for now use simple implementation + FileDescriptor fdObj = open(-1, path, null, flags, mode); + return SimpleAsynchronousFileChannelImpl.open(fdObj, flags.read, flags.write, pool); + } + + /** + * Opens file based on parameters and options, returning a FileDescriptor + * encapsulating the handle to the open file. + */ + static FileDescriptor open(int dfd, + UnixPath path, + String pathForPermissionCheck, + Flags flags, + int mode) + throws UnixException + { + // map to oflags + int oflags; + if (flags.read && flags.write) { + oflags = O_RDWR; + } else { + oflags = (flags.write) ? O_WRONLY : O_RDONLY; + } + if (flags.write) { + if (flags.truncateExisting) + oflags |= O_TRUNC; + if (flags.append) + oflags |= O_APPEND; + + // create flags + if (flags.createNew) { + byte[] pathForSysCall = path.asByteArray(); + + // throw exception if file name is "." to avoid confusing error + if ((pathForSysCall[pathForSysCall.length-1] == '.') && + (pathForSysCall.length == 1 || + (pathForSysCall[pathForSysCall.length-2] == '/'))) + { + throw new UnixException(EEXIST); + } + oflags |= (O_CREAT | O_EXCL); + } else { + if (flags.create) + oflags |= O_CREAT; + } + } + + // follow links by default + boolean followLinks = true; + if (!flags.createNew && (flags.noFollowLinks || flags.deleteOnClose)) { + followLinks = false; + oflags |= O_NOFOLLOW; + } + + if (flags.dsync) + oflags |= O_DSYNC; + if (flags.sync) + oflags |= O_SYNC; + + // permission check before we open the file + SecurityManager sm = System.getSecurityManager(); + if (sm != null) { + if (pathForPermissionCheck == null) + pathForPermissionCheck = path.getPathForPermissionCheck(); + if (flags.read) + sm.checkRead(pathForPermissionCheck); + if (flags.write) + sm.checkWrite(pathForPermissionCheck); + if (flags.deleteOnClose) + sm.checkDelete(pathForPermissionCheck); + } + + int fd; + try { + if (dfd >= 0) { + fd = openat(dfd, path.asByteArray(), oflags, mode); + } else { + fd = UnixNativeDispatcher.open(path, oflags, mode); + } + } catch (UnixException x) { + // Linux error can be EISDIR or EEXIST when file exists + if (flags.createNew && (x.errno() == EISDIR)) { + x.setError(EEXIST); + } + + // handle ELOOP to avoid confusing message + if (!followLinks && (x.errno() == ELOOP)) { + x = new UnixException(x.getMessage() + " (NOFOLLOW_LINKS specified)"); + } + + throw x; + } + + // unlink file immediately if delete on close. The spec is clear that + // an implementation cannot guarantee to unlink the correct file when + // replaced by an attacker after it is opened. + if (flags.deleteOnClose) { + try { + if (dfd >= 0) { + unlinkat(dfd, path.asByteArray(), 0); + } else { + unlink(path); + } + } catch (UnixException ignore) { + // best-effort + } + } + + // create java.io.FileDescriptor + FileDescriptor fdObj = new FileDescriptor(); + fdAccess.set(fdObj, fd); + return fdObj; + } +} diff --git a/src/solaris/classes/sun/nio/fs/UnixCopyFile.java b/src/solaris/classes/sun/nio/fs/UnixCopyFile.java new file mode 100644 index 0000000000000000000000000000000000000000..808cc1e34dced1cf59a52c0fd76dca326b0088b4 --- /dev/null +++ b/src/solaris/classes/sun/nio/fs/UnixCopyFile.java @@ -0,0 +1,608 @@ +/* + * Copyright 2008-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 sun.nio.fs; + +import java.nio.file.*; +import java.io.IOException; +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.util.concurrent.ExecutionException; +import com.sun.nio.file.ExtendedCopyOption; + +import static sun.nio.fs.UnixNativeDispatcher.*; +import static sun.nio.fs.UnixConstants.*; + + +/** + * Unix implementation of Path#copyTo and Path#moveTo methods. + */ + +class UnixCopyFile { + private UnixCopyFile() { } + + // The flags that control how a file is copied or moved + private static class Flags { + boolean replaceExisting; + boolean atomicMove; + boolean followLinks; + boolean interruptible; + + // the attributes to copy + boolean copyBasicAttributes; + boolean copyPosixAttributes; + boolean copyNonPosixAttributes; + + // flags that indicate if we should fail if attributes cannot be copied + boolean failIfUnableToCopyBasic; + boolean failIfUnableToCopyPosix; + boolean failIfUnableToCopyNonPosix; + + static Flags fromCopyOptions(CopyOption... options) { + Flags flags = new Flags(); + flags.followLinks = true; + for (CopyOption option: options) { + if (option == StandardCopyOption.REPLACE_EXISTING) { + flags.replaceExisting = true; + continue; + } + if (option == LinkOption.NOFOLLOW_LINKS) { + flags.followLinks = false; + continue; + } + if (option == StandardCopyOption.COPY_ATTRIBUTES) { + // copy all attributes but only fail if basic attributes + // cannot be copied + flags.copyBasicAttributes = true; + flags.copyPosixAttributes = true; + flags.copyNonPosixAttributes = true; + flags.failIfUnableToCopyBasic = true; + continue; + } + if (option == ExtendedCopyOption.INTERRUPTIBLE) { + flags.interruptible = true; + continue; + } + if (option == null) + throw new NullPointerException(); + throw new UnsupportedOperationException("Unsupported copy option"); + } + return flags; + } + + static Flags fromMoveOptions(CopyOption... options) { + Flags flags = new Flags(); + for (CopyOption option: options) { + if (option == StandardCopyOption.ATOMIC_MOVE) { + flags.atomicMove = true; + continue; + } + if (option == StandardCopyOption.REPLACE_EXISTING) { + flags.replaceExisting = true; + continue; + } + if (option == LinkOption.NOFOLLOW_LINKS) { + // ignore + continue; + } + if (option == null) + throw new NullPointerException(); + throw new UnsupportedOperationException("Unsupported copy option"); + } + + // a move requires that all attributes be copied but only fail if + // the basic attributes cannot be copied + flags.copyBasicAttributes = true; + flags.copyPosixAttributes = true; + flags.copyNonPosixAttributes = true; + flags.failIfUnableToCopyBasic = true; + return flags; + } + } + + // copy directory from source to target + private static void copyDirectory(UnixPath source, + UnixFileAttributes attrs, + UnixPath target, + Flags flags) + throws IOException + { + try { + mkdir(target, attrs.mode()); + } catch (UnixException x) { + x.rethrowAsIOException(target); + } + + // no attributes to copy + if (!flags.copyBasicAttributes && + !flags.copyPosixAttributes && + !flags.copyNonPosixAttributes) return; + + // open target directory if possible (this can fail when copying a + // directory for which we don't have read access). + int dfd = -1; + try { + dfd = open(target, O_RDONLY, 0); + } catch (UnixException x) { + // access to target directory required to copy named attributes + if (flags.copyNonPosixAttributes && flags.failIfUnableToCopyNonPosix) { + try { rmdir(target); } catch (UnixException ignore) { } + x.rethrowAsIOException(target); + } + } + + boolean done = false; + try { + // copy owner/group/permissions + if (flags.copyPosixAttributes){ + try { + if (dfd >= 0) { + fchown(dfd, attrs.uid(), attrs.gid()); + fchmod(dfd, attrs.mode()); + } else { + chown(target, attrs.uid(), attrs.gid()); + chmod(target, attrs.mode()); + } + } catch (UnixException x) { + // unable to set owner/group + if (flags.failIfUnableToCopyPosix) + x.rethrowAsIOException(target); + } + } + // copy other attributes + if (flags.copyNonPosixAttributes && (dfd >= 0)) { + int sfd = -1; + try { + sfd = open(source, O_RDONLY, 0); + } catch (UnixException x) { + if (flags.failIfUnableToCopyNonPosix) + x.rethrowAsIOException(source); + } + if (sfd >= 0) { + source.getFileSystem().copyNonPosixAttributes(sfd, dfd); + close(sfd); + } + } + // copy time stamps last + if (flags.copyBasicAttributes) { + try { + if (dfd >= 0) { + futimes(dfd, attrs.lastAccessTime(), + attrs.lastModifiedTime()); + } else { + utimes(target, attrs.lastAccessTime(), + attrs.lastModifiedTime()); + } + } catch (UnixException x) { + // unable to set times + if (flags.failIfUnableToCopyBasic) + x.rethrowAsIOException(target); + } + } + done = true; + } finally { + if (dfd >= 0) + close(dfd); + if (!done) { + // rollback + try { rmdir(target); } catch (UnixException ignore) { } + } + } + } + + // copy regular file from source to target + private static void copyFile(UnixPath source, + UnixFileAttributes attrs, + UnixPath target, + Flags flags, + long addressToPollForCancel) + throws IOException + { + int fi = -1; + try { + fi = open(source, O_RDONLY, 0); + } catch (UnixException x) { + x.rethrowAsIOException(source); + } + + try { + // open new file + int fo = -1; + try { + fo = open(target, + (O_WRONLY | + O_CREAT | + O_TRUNC), + attrs.mode()); + } catch (UnixException x) { + x.rethrowAsIOException(target); + } + + // set to true when file and attributes copied + boolean complete = false; + try { + // transfer bytes to target file + try { + transfer(fo, fi, addressToPollForCancel); + } catch (UnixException x) { + x.rethrowAsIOException(source, target); + } + // copy owner/permissions + if (flags.copyPosixAttributes) { + try { + fchown(fo, attrs.uid(), attrs.gid()); + fchmod(fo, attrs.mode()); + } catch (UnixException x) { + if (flags.failIfUnableToCopyPosix) + x.rethrowAsIOException(target); + } + } + // copy non POSIX attributes (depends on file system) + if (flags.copyNonPosixAttributes) { + source.getFileSystem().copyNonPosixAttributes(fi, fo); + } + // copy time attributes + if (flags.copyBasicAttributes) { + try { + futimes(fo, attrs.lastAccessTime(), attrs.lastModifiedTime()); + } catch (UnixException x) { + if (flags.failIfUnableToCopyBasic) + x.rethrowAsIOException(target); + } + } + complete = true; + } finally { + close(fo); + + // copy of file or attributes failed so rollback + if (!complete) { + try { + unlink(target); + } catch (UnixException ignore) { } + } + } + } finally { + close(fi); + } + } + + // copy symbolic link from source to target + private static void copyLink(UnixPath source, + UnixFileAttributes attrs, + UnixPath target, + Flags flags) + throws IOException + { + byte[] linktarget = null; + try { + linktarget = readlink(source); + } catch (UnixException x) { + x.rethrowAsIOException(source); + } + try { + symlink(linktarget, target); + + if (flags.copyPosixAttributes) { + try { + lchown(target, attrs.uid(), attrs.gid()); + } catch (UnixException x) { + // ignore since link attributes not required to be copied + } + } + } catch (UnixException x) { + x.rethrowAsIOException(target); + } + } + + // copy special file from source to target + private static void copySpecial(UnixPath source, + UnixFileAttributes attrs, + UnixPath target, + Flags flags) + throws IOException + { + try { + mknod(target, attrs.mode(), attrs.rdev()); + } catch (UnixException x) { + x.rethrowAsIOException(target); + } + boolean done = false; + try { + if (flags.copyPosixAttributes) { + try { + chown(target, attrs.uid(), attrs.gid()); + chmod(target, attrs.mode()); + } catch (UnixException x) { + if (flags.failIfUnableToCopyPosix) + x.rethrowAsIOException(target); + } + } + if (flags.copyBasicAttributes) { + try { + utimes(target, attrs.lastAccessTime(), attrs.lastModifiedTime()); + } catch (UnixException x) { + if (flags.failIfUnableToCopyBasic) + x.rethrowAsIOException(target); + } + } + done = true; + } finally { + if (!done) { + try { unlink(target); } catch (UnixException ignore) { } + } + } + } + + // move file from source to target + static void move(UnixPath source, UnixPath target, CopyOption... options) + throws IOException + { + // permission check + SecurityManager sm = System.getSecurityManager(); + if (sm != null) { + source.checkWrite(); + target.checkWrite(); + } + + // translate options into flags + Flags flags = Flags.fromMoveOptions(options); + + // handle atomic rename case + if (flags.atomicMove) { + try { + rename(source, target); + } catch (UnixException x) { + if (x.errno() == EXDEV) { + throw new AtomicMoveNotSupportedException( + source.getPathForExecptionMessage(), + target.getPathForExecptionMessage(), + x.errorString()); + } + x.rethrowAsIOException(source, target); + } + return; + } + + // move using rename or copy+delete + UnixFileAttributes sourceAttrs = null; + UnixFileAttributes targetAttrs = null; + + // get attributes of source file (don't follow links) + try { + sourceAttrs = UnixFileAttributes.get(source, false); + } catch (UnixException x) { + x.rethrowAsIOException(source); + } + + // get attributes of target file (don't follow links) + try { + targetAttrs = UnixFileAttributes.get(target, false); + } catch (UnixException x) { + // ignore + } + boolean targetExists = (targetAttrs != null); + + // if the target exists: + // 1. check if source and target are the same file + // 2. throw exception if REPLACE_EXISTING option is not set + // 3. delete target if REPLACE_EXISTING option set + if (targetExists) { + if (sourceAttrs.isSameFile(targetAttrs)) + return; // nothing to do as files are identical + if (!flags.replaceExisting) { + throw new FileAlreadyExistsException( + target.getPathForExecptionMessage()); + } + + // attempt to delete target + try { + if (targetAttrs.isDirectory()) { + rmdir(target); + } else { + unlink(target); + } + } catch (UnixException x) { + // target is non-empty directory that can't be replaced. + if (targetAttrs.isDirectory() && + (x.errno() == EEXIST || x.errno() == ENOTEMPTY)) + { + throw new FileAlreadyExistsException( + source.getPathForExecptionMessage(), + target.getPathForExecptionMessage(), + x.getMessage()); + } + x.rethrowAsIOException(target); + } + } + + // first try rename + try { + rename(source, target); + return; + } catch (UnixException x) { + if (x.errno() != EXDEV && x.errno() != EISDIR) { + x.rethrowAsIOException(source, target); + } + } + + // copy source to target + if (sourceAttrs.isDirectory()) { + copyDirectory(source, sourceAttrs, target, flags); + } else { + if (sourceAttrs.isSymbolicLink()) { + copyLink(source, sourceAttrs, target, flags); + } else { + if (sourceAttrs.isDevice()) { + copySpecial(source, sourceAttrs, target, flags); + } else { + copyFile(source, sourceAttrs, target, flags, 0L); + } + } + } + + // delete source + try { + if (sourceAttrs.isDirectory()) { + rmdir(source); + } else { + unlink(source); + } + } catch (UnixException x) { + // file was copied but unable to unlink the source file so attempt + // to remove the target and throw a reasonable exception + try { + if (sourceAttrs.isDirectory()) { + rmdir(target); + } else { + unlink(target); + } + } catch (UnixException ignore) { } + + if (sourceAttrs.isDirectory() && + (x.errno() == EEXIST || x.errno() == ENOTEMPTY)) + { + throw new DirectoryNotEmptyException( + source.getPathForExecptionMessage()); + } + x.rethrowAsIOException(source); + } + } + + // copy file from source to target + static void copy(final UnixPath source, + final UnixPath target, + CopyOption... options) throws IOException + { + // permission checks + SecurityManager sm = System.getSecurityManager(); + if (sm != null) { + source.checkRead(); + target.checkWrite(); + } + + // translate options into flags + final Flags flags = Flags.fromCopyOptions(options); + + UnixFileAttributes sourceAttrs = null; + UnixFileAttributes targetAttrs = null; + + // get attributes of source file + try { + sourceAttrs = UnixFileAttributes.get(source, flags.followLinks); + } catch (UnixException x) { + x.rethrowAsIOException(source); + } + + // if source file is symbolic link then we must check LinkPermission + if (sm != null && sourceAttrs.isSymbolicLink()) { + sm.checkPermission(new LinkPermission("symbolic")); + } + + // get attributes of target file (don't follow links) + try { + targetAttrs = UnixFileAttributes.get(target, false); + } catch (UnixException x) { + // ignore + } + boolean targetExists = (targetAttrs != null); + + // if the target exists: + // 1. check if source and target are the same file + // 2. throw exception if REPLACE_EXISTING option is not set + // 3. try to unlink the target + if (targetExists) { + if (sourceAttrs.isSameFile(targetAttrs)) + return; // nothing to do as files are identical + if (!flags.replaceExisting) + throw new FileAlreadyExistsException( + target.getPathForExecptionMessage()); + try { + if (targetAttrs.isDirectory()) { + rmdir(target); + } else { + unlink(target); + } + } catch (UnixException x) { + // target is non-empty directory that can't be replaced. + if (targetAttrs.isDirectory() && + (x.errno() == EEXIST || x.errno() == ENOTEMPTY)) + { + throw new FileAlreadyExistsException( + source.getPathForExecptionMessage(), + target.getPathForExecptionMessage(), + x.getMessage()); + } + x.rethrowAsIOException(target); + } + } + + // do the copy + if (sourceAttrs.isDirectory()) { + copyDirectory(source, sourceAttrs, target, flags); + return; + } + if (sourceAttrs.isSymbolicLink()) { + copyLink(source, sourceAttrs, target, flags); + return; + } + if (!flags.interruptible) { + // non-interruptible file copy + copyFile(source, sourceAttrs, target, flags, 0L); + return; + } + + // interruptible file copy + final UnixFileAttributes attrsToCopy = sourceAttrs; + Cancellable copyTask = new Cancellable() { + @Override public void implRun() throws IOException { + copyFile(source, attrsToCopy, target, flags, + addressToPollForCancel()); + } + }; + try { + Cancellable.runInterruptibly(copyTask); + } catch (ExecutionException e) { + Throwable t = e.getCause(); + if (t instanceof IOException) + throw (IOException)t; + throw new IOException(t); + } + } + + // -- native methods -- + + static native void transfer(int dst, int src, long addressToPollForCancel) + throws UnixException; + + static { + AccessController.doPrivileged(new PrivilegedAction<Void>() { + @Override + public Void run() { + System.loadLibrary("nio"); + return null; + }}); + } + +} diff --git a/src/solaris/classes/sun/nio/fs/UnixDirectoryStream.java b/src/solaris/classes/sun/nio/fs/UnixDirectoryStream.java new file mode 100644 index 0000000000000000000000000000000000000000..a723d71adb22fc5d1382691eb4864b162a113cce --- /dev/null +++ b/src/solaris/classes/sun/nio/fs/UnixDirectoryStream.java @@ -0,0 +1,267 @@ +/* + * Copyright 2008-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 sun.nio.fs; + +import java.nio.file.*; +import java.util.Iterator; +import java.util.ConcurrentModificationException; +import java.util.NoSuchElementException; +import java.util.concurrent.locks.*; +import java.io.IOException; +import static sun.nio.fs.UnixNativeDispatcher.*; + +/** + * Unix implementation of java.nio.file.DirectoryStream + */ + +class UnixDirectoryStream + implements DirectoryStream<Path> +{ + // path to directory when originally opened + private final UnixPath dir; + + // directory pointer (returned by opendir) + private final long dp; + + // filter (may be null) + private final DirectoryStream.Filter<? super Path> filter; + + // used to coorindate closing of directory stream + private final ReentrantReadWriteLock streamLock = + new ReentrantReadWriteLock(true); + + // indicates if directory stream is open (synchronize on closeLock) + private volatile boolean isClosed; + + // directory iterator + private Iterator<Path> iterator; + + /** + * Initializes a new instance + */ + UnixDirectoryStream(UnixPath dir, long dp, DirectoryStream.Filter<? super Path> filter) { + this.dir = dir; + this.dp = dp; + this.filter = filter; + } + + protected final UnixPath directory() { + return dir; + } + + protected final Lock readLock() { + return streamLock.readLock(); + } + + protected final Lock writeLock() { + return streamLock.writeLock(); + } + + protected final boolean isOpen() { + return !isClosed; + } + + protected final boolean closeImpl() throws IOException { + if (!isClosed) { + isClosed = true; + try { + closedir(dp); + } catch (UnixException x) { + throw new IOException(x.errorString()); + } + return true; + } else { + return false; + } + } + + @Override + public void close() + throws IOException + { + writeLock().lock(); + try { + closeImpl(); + } finally { + writeLock().unlock(); + } + } + + protected final Iterator<Path> iterator(DirectoryStream<Path> ds) { + if (isClosed) { + throw new IllegalStateException("Directory stream is closed"); + } + synchronized (this) { + if (iterator != null) + throw new IllegalStateException("Iterator already obtained"); + iterator = new UnixDirectoryIterator(ds); + return iterator; + } + } + + @Override + public Iterator<Path> iterator() { + return iterator(this); + } + + /** + * Iterator implementation + */ + private class UnixDirectoryIterator implements Iterator<Path> { + private final DirectoryStream<Path> stream; + + // true when at EOF + private boolean atEof; + + // next entry to return + private Path nextEntry; + + // previous entry returned by next method (needed by remove method) + private Path prevEntry; + + UnixDirectoryIterator(DirectoryStream<Path> stream) { + atEof = false; + this.stream = stream; + } + + // Return true if file name is "." or ".." + private boolean isSelfOrParent(byte[] nameAsBytes) { + if (nameAsBytes[0] == '.') { + if ((nameAsBytes.length == 1) || + (nameAsBytes.length == 2 && nameAsBytes[1] == '.')) { + return true; + } + } + return false; + } + + // Returns next entry (or null) + private Path readNextEntry() { + assert Thread.holdsLock(this); + + for (;;) { + byte[] nameAsBytes = null; + + // prevent close while reading + readLock().lock(); + try { + if (isClosed) + throwAsConcurrentModificationException(new + ClosedDirectoryStreamException()); + try { + nameAsBytes = readdir(dp); + } catch (UnixException x) { + try { + x.rethrowAsIOException(dir); + } catch (IOException ioe) { + throwAsConcurrentModificationException(ioe); + } + } + } finally { + readLock().unlock(); + } + + // EOF + if (nameAsBytes == null) { + return null; + } + + // ignore "." and ".." + if (!isSelfOrParent(nameAsBytes)) { + Path entry = dir.resolve(nameAsBytes); + + // return entry if no filter or filter accepts it + if (filter.accept(entry)) { + return entry; + } + } + } + } + + @Override + public synchronized boolean hasNext() { + if (nextEntry == null && !atEof) { + nextEntry = readNextEntry(); + + // at EOF? + if (nextEntry == null) + atEof = true; + } + return nextEntry != null; + } + + @Override + public synchronized Path next() { + if (nextEntry == null) { + if (!atEof) { + nextEntry = readNextEntry(); + } + if (nextEntry == null) { + atEof = true; + throw new NoSuchElementException(); + } + } + prevEntry = nextEntry; + nextEntry = null; + return prevEntry; + } + + @Override + public void remove() { + if (isClosed) { + throw new ClosedDirectoryStreamException(); + } + Path entry; + synchronized (this) { + if (prevEntry == null) + throw new IllegalStateException("No previous entry to remove"); + entry = prevEntry; + prevEntry = null; + } + + // use (race-free) unlinkat if available + try { + if (stream instanceof UnixSecureDirectoryStream) { + ((UnixSecureDirectoryStream)stream) + .implDelete(entry.getName(), false, 0); + } else { + entry.delete(true); + } + } catch (IOException ioe) { + throwAsConcurrentModificationException(ioe); + } catch (SecurityException se) { + throwAsConcurrentModificationException(se); + } + } + } + + private static void throwAsConcurrentModificationException(Throwable t) { + ConcurrentModificationException cme = new ConcurrentModificationException(); + cme.initCause(t); + throw cme; + } + +} diff --git a/src/solaris/classes/sun/nio/fs/UnixException.java b/src/solaris/classes/sun/nio/fs/UnixException.java new file mode 100644 index 0000000000000000000000000000000000000000..3a9967540ae0b443ce40ad0df615cfdfa9162869 --- /dev/null +++ b/src/solaris/classes/sun/nio/fs/UnixException.java @@ -0,0 +1,113 @@ +/* + * Copyright 2008-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 sun.nio.fs; + +import java.nio.file.*; +import java.io.IOException; + +/** + * Internal exception thrown by native methods when error detected. + */ + +class UnixException extends Exception { + static final long serialVersionUID = 7227016794320723218L; + + private int errno; + private String msg; + + UnixException(int errno) { + this.errno = errno; + this.msg = null; + } + + UnixException(String msg) { + this.errno = 0; + this.msg = msg; + } + + int errno() { + return errno; + } + + void setError(int errno) { + this.errno = errno; + this.msg = null; + } + + String errorString() { + if (msg != null) { + return msg; + } else { + return new String(UnixNativeDispatcher.strerror(errno())); + } + } + + @Override + public String getMessage() { + return errorString(); + } + + /** + * Map well known errors to specific exceptions where possible; otherwise + * return more general FileSystemException. + */ + private IOException translateToIOException(String file, String other) { + // created with message rather than errno + if (msg != null) + return new IOException(msg); + + // handle specific cases + if (errno() == UnixConstants.EACCES) + return new AccessDeniedException(file, other, null); + if (errno() == UnixConstants.ENOENT) + return new NoSuchFileException(file, other, null); + if (errno() == UnixConstants.EEXIST) + return new FileAlreadyExistsException(file, other, null); + + // fallback to the more general exception + return new FileSystemException(file, other, errorString()); + } + + void rethrowAsIOException(String file) throws IOException { + IOException x = translateToIOException(file, null); + throw x; + } + + void rethrowAsIOException(UnixPath file, UnixPath other) throws IOException { + String a = (file == null) ? null : file.getPathForExecptionMessage(); + String b = (other == null) ? null : other.getPathForExecptionMessage(); + IOException x = translateToIOException(a, b); + throw x; + } + + void rethrowAsIOException(UnixPath file) throws IOException { + rethrowAsIOException(file, null); + } + + IOException asIOException(UnixPath file) { + return translateToIOException(file.getPathForExecptionMessage(), null); + } +} diff --git a/src/solaris/classes/sun/nio/fs/UnixFileAttributeViews.java b/src/solaris/classes/sun/nio/fs/UnixFileAttributeViews.java new file mode 100644 index 0000000000000000000000000000000000000000..7bbf925b734e8dde2f70c61c163fbd2b02222c80 --- /dev/null +++ b/src/solaris/classes/sun/nio/fs/UnixFileAttributeViews.java @@ -0,0 +1,392 @@ +/* + * Copyright 2008-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 sun.nio.fs; + +import java.nio.file.*; +import java.nio.file.attribute.*; +import java.util.*; +import java.util.concurrent.TimeUnit; +import java.io.IOException; + +import static sun.nio.fs.UnixNativeDispatcher.*; + +class UnixFileAttributeViews { + + static class Basic extends AbstractBasicFileAttributeView { + protected final UnixPath file; + protected final boolean followLinks; + + Basic(UnixPath file, boolean followLinks) { + this.file = file; + this.followLinks = followLinks; + } + + @Override + public BasicFileAttributes readAttributes() throws IOException { + file.checkRead(); + try { + UnixFileAttributes attrs = + UnixFileAttributes.get(file, followLinks); + return attrs.asBasicFileAttributes(); + } catch (UnixException x) { + x.rethrowAsIOException(file); + return null; // keep compiler happy + } + } + @Override + public void setTimes(Long lastModifiedTime, + Long lastAccessTime, + Long createTime, + TimeUnit unit) throws IOException + { + // null => don't change + if (lastModifiedTime == null && lastAccessTime == null) { + // no effect + return; + } + + file.checkWrite(); + + int fd = file.openForAttributeAccess(followLinks); + try { + UnixFileAttributes attrs = null; + + // if not changing both attributes then need existing attributes + if (lastModifiedTime == null || lastAccessTime == null) { + try { + attrs = UnixFileAttributes.get(fd); + } catch (UnixException x) { + x.rethrowAsIOException(file); + } + } + + // modified time = existing, now, or new value + long modTime; + if (lastModifiedTime == null) { + modTime = attrs.lastModifiedTime(); + } else { + if (lastModifiedTime >= 0L) { + modTime = TimeUnit.MILLISECONDS.convert(lastModifiedTime, unit); + } else { + if (lastModifiedTime != -1L) + throw new IllegalArgumentException(); + modTime = System.currentTimeMillis(); + } + } + + // access time = existing, now, or new value + long accTime; + if (lastAccessTime == null) { + accTime = attrs.lastAccessTime(); + } else { + if (lastAccessTime >= 0L) { + accTime = TimeUnit.MILLISECONDS.convert(lastAccessTime, unit); + } else { + if (lastAccessTime != -1L) + throw new IllegalArgumentException(); + accTime = System.currentTimeMillis(); + } + } + + try { + futimes(fd, accTime, modTime); + } catch (UnixException x) { + x.rethrowAsIOException(file); + } + } finally { + close(fd); + } + } + } + + private static class Posix extends Basic implements PosixFileAttributeView { + private static final String PERMISSIONS_NAME = "permissions"; + private static final String OWNER_NAME = "owner"; + private static final String GROUP_NAME = "group"; + + Posix(UnixPath file, boolean followLinks) { + super(file, followLinks); + } + + final void checkReadExtended() { + SecurityManager sm = System.getSecurityManager(); + if (sm != null) { + file.checkRead(); + sm.checkPermission(new RuntimePermission("accessUserInformation")); + } + } + + final void checkWriteExtended() { + SecurityManager sm = System.getSecurityManager(); + if (sm != null) { + file.checkWrite(); + sm.checkPermission(new RuntimePermission("accessUserInformation")); + } + } + + @Override + public String name() { + return "posix"; + } + + @Override + public Object getAttribute(String attribute) throws IOException { + if (attribute.equals(PERMISSIONS_NAME)) + return readAttributes().permissions(); + if (attribute.equals(OWNER_NAME)) + return readAttributes().owner(); + if (attribute.equals(GROUP_NAME)) + return readAttributes().group(); + return super.getAttribute(attribute); + } + + @Override + @SuppressWarnings("unchecked") + public void setAttribute(String attribute, Object value) + throws IOException + { + if (attribute.equals(PERMISSIONS_NAME)) { + setPermissions((Set<PosixFilePermission>)value); + return; + } + if (attribute.equals(OWNER_NAME)) { + setOwner((UserPrincipal)value); + return; + } + if (attribute.equals(GROUP_NAME)) { + setGroup((GroupPrincipal)value); + return; + } + super.setAttribute(attribute, value); + } + + /** + * Invoked by readAttributes or sub-classes to add all matching posix + * attributes to the builder + */ + final void addPosixAttributesToBuilder(PosixFileAttributes attrs, + AttributesBuilder builder) + { + if (builder.match(PERMISSIONS_NAME)) + builder.add(PERMISSIONS_NAME, attrs.permissions()); + if (builder.match(OWNER_NAME)) + builder.add(OWNER_NAME, attrs.owner()); + if (builder.match(GROUP_NAME)) + builder.add(GROUP_NAME, attrs.group()); + } + + @Override + public Map<String,?> readAttributes(String first, String[] rest) + throws IOException + { + AttributesBuilder builder = AttributesBuilder.create(first, rest); + PosixFileAttributes attrs = readAttributes(); + addBasicAttributesToBuilder(attrs, builder); + addPosixAttributesToBuilder(attrs, builder); + return builder.unmodifiableMap(); + } + + @Override + public UnixFileAttributes readAttributes() throws IOException { + checkReadExtended(); + try { + return UnixFileAttributes.get(file, followLinks); + } catch (UnixException x) { + x.rethrowAsIOException(file); + return null; // keep compiler happy + } + } + + // chmod + final void setMode(int mode) throws IOException { + checkWriteExtended(); + try { + if (followLinks) { + chmod(file, mode); + } else { + int fd = file.openForAttributeAccess(false); + try { + fchmod(fd, mode); + } finally { + close(fd); + } + } + } catch (UnixException x) { + x.rethrowAsIOException(file); + } + } + + // chown + final void setOwners(int uid, int gid) throws IOException { + checkWriteExtended(); + try { + if (followLinks) { + chown(file, uid, gid); + } else { + lchown(file, uid, gid); + } + } catch (UnixException x) { + x.rethrowAsIOException(file); + } + } + + @Override + public void setPermissions(Set<PosixFilePermission> perms) + throws IOException + { + setMode(UnixFileModeAttribute.toUnixMode(perms)); + } + + @Override + public void setOwner(UserPrincipal owner) + throws IOException + { + if (owner == null) + throw new NullPointerException("'owner' is null"); + if (!(owner instanceof UnixUserPrincipals.User)) + throw new ProviderMismatchException(); + if (owner instanceof UnixUserPrincipals.Group) + throw new IOException("'owner' parameter can't be a group"); + int uid = ((UnixUserPrincipals.User)owner).uid(); + setOwners(uid, -1); + } + + @Override + public UserPrincipal getOwner() throws IOException { + return readAttributes().owner(); + } + + @Override + public void setGroup(GroupPrincipal group) + throws IOException + { + if (group == null) + throw new NullPointerException("'owner' is null"); + if (!(group instanceof UnixUserPrincipals.Group)) + throw new ProviderMismatchException(); + int gid = ((UnixUserPrincipals.Group)group).gid(); + setOwners(-1, gid); + } + } + + private static class Unix extends Posix { + private static final String MODE_NAME = "mode"; + private static final String INO_NAME = "ino"; + private static final String DEV_NAME = "dev"; + private static final String RDEV_NAME = "rdev"; + private static final String UID_NAME = "uid"; + private static final String GID_NAME = "gid"; + private static final String CTIME_NAME = "ctime"; + + Unix(UnixPath file, boolean followLinks) { + super(file, followLinks); + } + + @Override + public String name() { + return "unix"; + } + + @Override + public Object getAttribute(String attribute) throws IOException { + if (attribute.equals(MODE_NAME)) + return readAttributes().mode(); + if (attribute.equals(INO_NAME)) + return readAttributes().ino(); + if (attribute.equals(DEV_NAME)) + return readAttributes().dev(); + if (attribute.equals(RDEV_NAME)) + return readAttributes().rdev(); + if (attribute.equals(UID_NAME)) + return readAttributes().uid(); + if (attribute.equals(GID_NAME)) + return readAttributes().gid(); + if (attribute.equals(CTIME_NAME)) + return readAttributes().ctime(); + return super.getAttribute(attribute); + } + + @Override + public void setAttribute(String attribute, Object value) + throws IOException + { + if (attribute.equals(MODE_NAME)) { + setMode((Integer)value); + return; + } + if (attribute.equals(UID_NAME)) { + setOwners((Integer)value, -1); + return; + } + if (attribute.equals(GID_NAME)) { + setOwners(-1, (Integer)value); + return; + } + super.setAttribute(attribute, value); + } + + @Override + public Map<String,?> readAttributes(String first, String[] rest) + throws IOException + { + AttributesBuilder builder = AttributesBuilder.create(first, rest); + UnixFileAttributes attrs = readAttributes(); + addBasicAttributesToBuilder(attrs, builder); + addPosixAttributesToBuilder(attrs, builder); + if (builder.match(MODE_NAME)) + builder.add(MODE_NAME, attrs.mode()); + if (builder.match(INO_NAME)) + builder.add(INO_NAME, attrs.ino()); + if (builder.match(DEV_NAME)) + builder.add(DEV_NAME, attrs.dev()); + if (builder.match(RDEV_NAME)) + builder.add(RDEV_NAME, attrs.rdev()); + if (builder.match(UID_NAME)) + builder.add(UID_NAME, attrs.uid()); + if (builder.match(GID_NAME)) + builder.add(GID_NAME, attrs.gid()); + if (builder.match(CTIME_NAME)) + builder.add(CTIME_NAME, attrs.ctime()); + return builder.unmodifiableMap(); + } + } + + static BasicFileAttributeView createBasicView(UnixPath file, boolean followLinks) { + return new Basic(file, followLinks); + } + + static PosixFileAttributeView createPosixView(UnixPath file, boolean followLinks) { + return new Posix(file, followLinks); + } + + static PosixFileAttributeView createUnixView(UnixPath file, boolean followLinks) { + return new Unix(file, followLinks); + } + + static FileOwnerAttributeView createOwnerView(UnixPath file, boolean followLinks) { + return new FileOwnerAttributeViewImpl(createPosixView(file, followLinks)); + } +} diff --git a/src/solaris/classes/sun/nio/fs/UnixFileAttributes.java b/src/solaris/classes/sun/nio/fs/UnixFileAttributes.java new file mode 100644 index 0000000000000000000000000000000000000000..c1882d7536b2b682ff81e35135f52af71cf9289b --- /dev/null +++ b/src/solaris/classes/sun/nio/fs/UnixFileAttributes.java @@ -0,0 +1,307 @@ +/* + * Copyright 2008-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 sun.nio.fs; + +import java.nio.file.attribute.*; +import java.util.concurrent.TimeUnit; +import java.util.Set; +import java.util.HashSet; + +/** + * Unix implementation of PosixFileAttributes. + */ + +class UnixFileAttributes + implements PosixFileAttributes +{ + private int st_mode; + private long st_ino; + private long st_dev; + private long st_rdev; + private int st_nlink; + private int st_uid; + private int st_gid; + private long st_size; + private long st_atime; + private long st_mtime; + private long st_ctime; + + // created lazily + private volatile UserPrincipal owner; + private volatile GroupPrincipal group; + private volatile UnixFileKey key; + + private UnixFileAttributes() { + } + + // get the UnixFileAttributes for a given file + static UnixFileAttributes get(UnixPath path, boolean followLinks) + throws UnixException + { + UnixFileAttributes attrs = new UnixFileAttributes(); + if (followLinks) { + UnixNativeDispatcher.stat(path, attrs); + } else { + UnixNativeDispatcher.lstat(path, attrs); + } + return attrs; + } + + // get the UnixFileAttributes for an open file + static UnixFileAttributes get(int fd) throws UnixException { + UnixFileAttributes attrs = new UnixFileAttributes(); + UnixNativeDispatcher.fstat(fd, attrs); + return attrs; + } + + // get the UnixFileAttributes for a given file, relative to open directory + static UnixFileAttributes get(int dfd, UnixPath path, boolean followLinks) + throws UnixException + { + UnixFileAttributes attrs = new UnixFileAttributes(); + int flag = (followLinks) ? 0 : UnixConstants.AT_SYMLINK_NOFOLLOW; + UnixNativeDispatcher.fstatat(dfd, path.asByteArray(), flag, attrs); + return attrs; + } + + // package-private + boolean isSameFile(UnixFileAttributes attrs) { + return ((st_ino == attrs.st_ino) && (st_dev == attrs.st_dev)); + } + + // package-private + int mode() { return st_mode; } + long ino() { return st_ino; } + long dev() { return st_dev; } + long rdev() { return st_rdev; } + int uid() { return st_uid; } + int gid() { return st_gid; } + long ctime() { return st_ctime; } + + boolean isDevice() { + int type = st_mode & UnixConstants.S_IFMT; + return (type == UnixConstants.S_IFCHR || + type == UnixConstants.S_IFBLK || + type == UnixConstants.S_IFIFO); + } + + @Override + public long lastModifiedTime() { + return st_mtime; + } + + @Override + public long lastAccessTime() { + return st_atime; + } + + @Override + public long creationTime() { + return -1L; + } + + @Override + public TimeUnit resolution() { + return TimeUnit.MILLISECONDS; + } + + @Override + public boolean isRegularFile() { + return ((st_mode & UnixConstants.S_IFMT) == UnixConstants.S_IFREG); + } + + @Override + public boolean isDirectory() { + return ((st_mode & UnixConstants.S_IFMT) == UnixConstants.S_IFDIR); + } + + @Override + public boolean isSymbolicLink() { + return ((st_mode & UnixConstants.S_IFMT) == UnixConstants.S_IFLNK); + } + + @Override + public boolean isOther() { + int type = st_mode & UnixConstants.S_IFMT; + return (type != UnixConstants.S_IFREG && + type != UnixConstants.S_IFDIR && + type != UnixConstants.S_IFLNK); + } + + @Override + public long size() { + return st_size; + } + + @Override + public int linkCount() { + return st_nlink; + } + + @Override + public UnixFileKey fileKey() { + if (key == null) { + synchronized (this) { + if (key == null) { + key = new UnixFileKey(st_dev, st_ino); + } + } + } + return key; + } + + @Override + public UserPrincipal owner() { + if (owner == null) { + synchronized (this) { + if (owner == null) { + owner = UnixUserPrincipals.fromUid(st_uid); + } + } + } + return owner; + } + + @Override + public GroupPrincipal group() { + if (group == null) { + synchronized (this) { + if (group == null) { + group = UnixUserPrincipals.fromGid(st_gid); + } + } + } + return group; + } + + @Override + public Set<PosixFilePermission> permissions() { + int bits = (st_mode & UnixConstants.S_IAMB); + HashSet<PosixFilePermission> perms = new HashSet<PosixFilePermission>(); + + if ((bits & UnixConstants.S_IRUSR) > 0) + perms.add(PosixFilePermission.OWNER_READ); + if ((bits & UnixConstants.S_IWUSR) > 0) + perms.add(PosixFilePermission.OWNER_WRITE); + if ((bits & UnixConstants.S_IXUSR) > 0) + perms.add(PosixFilePermission.OWNER_EXECUTE); + + if ((bits & UnixConstants.S_IRGRP) > 0) + perms.add(PosixFilePermission.GROUP_READ); + if ((bits & UnixConstants.S_IWGRP) > 0) + perms.add(PosixFilePermission.GROUP_WRITE); + if ((bits & UnixConstants.S_IXGRP) > 0) + perms.add(PosixFilePermission.GROUP_EXECUTE); + + if ((bits & UnixConstants.S_IROTH) > 0) + perms.add(PosixFilePermission.OTHERS_READ); + if ((bits & UnixConstants.S_IWOTH) > 0) + perms.add(PosixFilePermission.OTHERS_WRITE); + if ((bits & UnixConstants.S_IXOTH) > 0) + perms.add(PosixFilePermission.OTHERS_EXECUTE); + + return perms; + } + + // wrap this object with BasicFileAttributes object to prevent leaking of + // user information + BasicFileAttributes asBasicFileAttributes() { + return UnixAsBasicFileAttributes.wrap(this); + } + + // unwrap BasicFileAttributes to get the underlying UnixFileAttributes + // object. Returns null is not wrapped. + static UnixFileAttributes toUnixFileAttributes(BasicFileAttributes attrs) { + if (attrs instanceof UnixFileAttributes) + return (UnixFileAttributes)attrs; + if (attrs instanceof UnixAsBasicFileAttributes) { + return ((UnixAsBasicFileAttributes)attrs).unwrap(); + } + return null; + } + + // wrap a UnixFileAttributes object as a BasicFileAttributes + private static class UnixAsBasicFileAttributes implements BasicFileAttributes { + private final UnixFileAttributes attrs; + + private UnixAsBasicFileAttributes(UnixFileAttributes attrs) { + this.attrs = attrs; + } + + static UnixAsBasicFileAttributes wrap(UnixFileAttributes attrs) { + return new UnixAsBasicFileAttributes(attrs); + } + + UnixFileAttributes unwrap() { + return attrs; + } + + @Override + public long lastModifiedTime() { + return attrs.lastModifiedTime(); + } + @Override + public long lastAccessTime() { + return attrs.lastAccessTime(); + } + @Override + public long creationTime() { + return attrs.creationTime(); + } + @Override + public TimeUnit resolution() { + return attrs.resolution(); + } + @Override + public boolean isRegularFile() { + return attrs.isRegularFile(); + } + @Override + public boolean isDirectory() { + return attrs.isDirectory(); + } + @Override + public boolean isSymbolicLink() { + return attrs.isSymbolicLink(); + } + @Override + public boolean isOther() { + return attrs.isOther(); + } + @Override + public long size() { + return attrs.size(); + } + @Override + public int linkCount() { + return attrs.linkCount(); + } + @Override + public Object fileKey() { + return attrs.fileKey(); + } + } +} diff --git a/src/solaris/classes/sun/nio/fs/UnixFileKey.java b/src/solaris/classes/sun/nio/fs/UnixFileKey.java new file mode 100644 index 0000000000000000000000000000000000000000..4ab3aec6c302875ed56822ee02a35ede4ca8e51a --- /dev/null +++ b/src/solaris/classes/sun/nio/fs/UnixFileKey.java @@ -0,0 +1,56 @@ +/* + * Copyright 2008-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 sun.nio.fs; + +/** + * Container for device/inode to uniquely identify file. + */ + +class UnixFileKey { + private final long st_dev; + private final long st_ino; + + UnixFileKey(long st_dev, long st_ino) { + this.st_dev = st_dev; + this.st_ino = st_ino; + } + + @Override + public int hashCode() { + return (int)(st_dev ^ (st_dev >>> 32)) + + (int)(st_ino ^ (st_ino >>> 32)); + } + + @Override + public boolean equals(Object obj) { + if (obj == this) + return true; + if (!(obj instanceof UnixFileKey)) + return false; + UnixFileKey other = (UnixFileKey)obj; + return (this.st_dev == other.st_dev) && (this.st_ino == other.st_ino); + } +} diff --git a/src/solaris/classes/sun/nio/fs/UnixFileModeAttribute.java b/src/solaris/classes/sun/nio/fs/UnixFileModeAttribute.java new file mode 100644 index 0000000000000000000000000000000000000000..67ea59e943dad9280a678040af14c52b6359cae5 --- /dev/null +++ b/src/solaris/classes/sun/nio/fs/UnixFileModeAttribute.java @@ -0,0 +1,84 @@ +/* + * Copyright 2008-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 sun.nio.fs; + +import java.nio.file.attribute.*; +import java.util.*; + +class UnixFileModeAttribute { + static final int ALL_PERMISSIONS = + UnixConstants.S_IRUSR | UnixConstants.S_IWUSR | UnixConstants.S_IXUSR | + UnixConstants.S_IRGRP | UnixConstants.S_IWGRP | UnixConstants.S_IXGRP | + UnixConstants.S_IROTH | UnixConstants.S_IWOTH | UnixConstants. S_IXOTH; + + static final int ALL_READWRITE = + UnixConstants.S_IRUSR | UnixConstants.S_IWUSR | + UnixConstants.S_IRGRP | UnixConstants.S_IWGRP | + UnixConstants.S_IROTH | UnixConstants.S_IWOTH; + + static final int TEMPFILE_PERMISSIONS = + UnixConstants.S_IRUSR | UnixConstants.S_IWUSR | UnixConstants.S_IXUSR; + + private Set<PosixFilePermission> perms; + + UnixFileModeAttribute() { + perms = Collections.emptySet(); + } + + static int toUnixMode(Set<PosixFilePermission> perms) { + int mode = 0; + for (PosixFilePermission perm: perms) { + if (perm == null) + throw new NullPointerException(); + switch (perm) { + case OWNER_READ : mode |= UnixConstants.S_IRUSR; break; + case OWNER_WRITE : mode |= UnixConstants.S_IWUSR; break; + case OWNER_EXECUTE : mode |= UnixConstants.S_IXUSR; break; + case GROUP_READ : mode |= UnixConstants.S_IRGRP; break; + case GROUP_WRITE : mode |= UnixConstants.S_IWGRP; break; + case GROUP_EXECUTE : mode |= UnixConstants.S_IXGRP; break; + case OTHERS_READ : mode |= UnixConstants.S_IROTH; break; + case OTHERS_WRITE : mode |= UnixConstants.S_IWOTH; break; + case OTHERS_EXECUTE : mode |= UnixConstants.S_IXOTH; break; + } + } + return mode; + } + + @SuppressWarnings("unchecked") + static int toUnixMode(int defaultMode, FileAttribute<?>... attrs) { + int mode = defaultMode; + for (FileAttribute<?> attr: attrs) { + String name = attr.name(); + if (!name.equals("posix:permissions") && !name.equals("unix:permissions")) { + throw new UnsupportedOperationException("'" + attr.name() + + "' not supported as initial attribute"); + } + mode = toUnixMode((Set<PosixFilePermission>)attr.value()); + } + return mode; + } +} diff --git a/src/solaris/classes/sun/nio/fs/UnixFileStore.java b/src/solaris/classes/sun/nio/fs/UnixFileStore.java new file mode 100644 index 0000000000000000000000000000000000000000..483a4ea48251432498d148bbe0d1b0b42e7c8bba --- /dev/null +++ b/src/solaris/classes/sun/nio/fs/UnixFileStore.java @@ -0,0 +1,290 @@ +/* + * Copyright 2008-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 sun.nio.fs; + +import java.nio.file.*; +import java.nio.file.attribute.*; +import java.nio.channels.*; +import java.util.*; +import java.io.IOException; +import java.security.AccessController; +import java.security.PrivilegedAction; + +/** + * Base implementation of FileStore for Unix/like implementations. + */ + +abstract class UnixFileStore + extends FileStore +{ + // original path of file that identified file system + private final UnixPath file; + + // device ID + private final long dev; + + // entry in the mount tab + private final UnixMountEntry entry; + + // return the device ID where the given file resides + private static long devFor(UnixPath file) throws IOException { + try { + return UnixFileAttributes.get(file, true).dev(); + } catch (UnixException x) { + x.rethrowAsIOException(file); + return 0L; // keep compiler happy + } + } + + UnixFileStore(UnixPath file) throws IOException { + this.file = file; + this.dev = devFor(file); + this.entry = findMountEntry(); + } + + UnixFileStore(UnixFileSystem fs, UnixMountEntry entry) throws IOException { + this.file = new UnixPath(fs, entry.dir()); + this.dev = (entry.dev() == 0L) ? devFor(this.file) : entry.dev(); + this.entry = entry; + } + + /** + * Find the mount entry for the file store + */ + abstract UnixMountEntry findMountEntry() throws IOException; + + /** + * Returns true if this file store represents a loopback file system that + * will have the same device ID as undelrying file system. + */ + abstract boolean isLoopback(); + + UnixPath file() { + return file; + } + + long dev() { + return dev; + } + + UnixMountEntry entry() { + return entry; + } + + @Override + public String name() { + return entry.name(); + } + + @Override + public String type() { + return entry.fstype(); + } + + @Override + public boolean isReadOnly() { + return entry.isReadOnly(); + } + + @Override + @SuppressWarnings("unchecked") + public <V extends FileStoreAttributeView> V getFileStoreAttributeView(Class<V> viewType) + { + if (viewType == FileStoreSpaceAttributeView.class) + return (V) new UnixFileStoreSpaceAttributeView(this); + return (V) null; + } + + @Override + public FileStoreAttributeView getFileStoreAttributeView(String name) { + if (name.equals("space")) + return new UnixFileStoreSpaceAttributeView(this); + return null; + } + + @Override + public boolean supportsFileAttributeView(Class<? extends FileAttributeView> type) { + if (type == BasicFileAttributeView.class) + return true; + if (type == PosixFileAttributeView.class || + type == FileOwnerAttributeView.class) + { + // lookup fstypes.properties + FeatureStatus status = checkIfFeaturePresent("posix"); + if (status == FeatureStatus.NOT_PRESENT) + return false; + return true; + } + return false; + } + + @Override + public boolean supportsFileAttributeView(String name) { + if (name.equals("basic") || name.equals("unix")) + return true; + if (name.equals("posix")) + return supportsFileAttributeView(PosixFileAttributeView.class); + if (name.equals("owner")) + return supportsFileAttributeView(FileOwnerAttributeView.class); + return false; + } + + @Override + public boolean equals(Object ob) { + if (ob == this) + return true; + if (!(ob instanceof UnixFileStore)) + return false; + UnixFileStore other = (UnixFileStore)ob; + if (dev != other.dev) + return false; + // deviceIDs are equal but they may not be equal if one or both of + // them is a loopback file system + boolean thisIsLoopback = isLoopback(); + if (thisIsLoopback != other.isLoopback()) + return false; // one, but not both, are lofs + if (!thisIsLoopback) + return true; // neither is lofs + // both are lofs so compare mount points + return Arrays.equals(this.entry.dir(), other.entry.dir()); + } + + @Override + public int hashCode() { + return (int)(dev ^ (dev >>> 32)); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(new String(entry.dir())); + sb.append(" ("); + sb.append(entry.name()); + sb.append(")"); + return sb.toString(); + } + + private static class UnixFileStoreSpaceAttributeView + extends AbstractFileStoreSpaceAttributeView + { + private final UnixFileStore fs; + + UnixFileStoreSpaceAttributeView(UnixFileStore fs) { + this.fs = fs; + } + + @Override + public FileStoreSpaceAttributes readAttributes() + throws IOException + { + UnixPath file = fs.file(); + final UnixFileStoreAttributes attrs; + try { + attrs = UnixFileStoreAttributes.get(file); + } catch (UnixException x) { + x.rethrowAsIOException(file); + return null; // keep compile happy + } + + return new FileStoreSpaceAttributes() { + @Override + public long totalSpace() { + return attrs.blockSize() * attrs.totalBlocks(); + } + @Override + public long usableSpace() { + return attrs.blockSize() * attrs.availableBlocks(); + } + @Override + public long unallocatedSpace() { + return attrs.blockSize() * attrs.freeBlocks(); + } + }; + } + } + + // -- fstypes.properties -- + + private static final Object loadLock = new Object(); + private static volatile Properties props; + + enum FeatureStatus { + PRESENT, + NOT_PRESENT, + UNKNOWN; + } + + /** + * Returns status to indicate if file system supports a given feature + */ + FeatureStatus checkIfFeaturePresent(String feature) { + if (props == null) { + synchronized (loadLock) { + if (props == null) { + props = AccessController.doPrivileged( + new PrivilegedAction<Properties>() { + @Override + public Properties run() { + return loadProperties(); + }}); + } + } + } + + String value = props.getProperty(type()); + if (value != null) { + String[] values = value.split("\\s"); + for (String s: values) { + s = s.trim().toLowerCase(); + if (s.equals(feature)) { + return FeatureStatus.PRESENT; + } + if (s.startsWith("no")) { + s = s.substring(2); + if (s.equals(feature)) { + return FeatureStatus.NOT_PRESENT; + } + } + } + } + return FeatureStatus.UNKNOWN; + } + + private static Properties loadProperties() { + Properties result = new Properties(); + String fstypes = System.getProperty("java.home") + "/lib/fstypes.properties"; + FileRef file = Paths.get(fstypes); + try { + ReadableByteChannel rbc = file.newByteChannel(); + try { + result.load(Channels.newReader(rbc, "UTF-8")); + } finally { + rbc.close(); + } + } catch (IOException x) { + } + return result; + } +} diff --git a/src/solaris/classes/sun/nio/fs/UnixFileStoreAttributes.java b/src/solaris/classes/sun/nio/fs/UnixFileStoreAttributes.java new file mode 100644 index 0000000000000000000000000000000000000000..f2cbd17cc1acd875110871d24e46fc5c2e036ac4 --- /dev/null +++ b/src/solaris/classes/sun/nio/fs/UnixFileStoreAttributes.java @@ -0,0 +1,59 @@ +/* + * Copyright 2008-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 sun.nio.fs; + +class UnixFileStoreAttributes { + private long f_frsize; // block size + private long f_blocks; // total + private long f_bfree; // free + private long f_bavail; // usable + + private UnixFileStoreAttributes() { + } + + static UnixFileStoreAttributes get(UnixPath path) throws UnixException { + UnixFileStoreAttributes attrs = new UnixFileStoreAttributes(); + UnixNativeDispatcher.statvfs(path, attrs); + return attrs; + } + + long blockSize() { + return f_frsize; + } + + long totalBlocks() { + return f_blocks; + } + + long freeBlocks() { + return f_bfree; + } + + long availableBlocks() { + return f_bavail; + } + +} diff --git a/src/solaris/classes/sun/nio/fs/UnixFileSystem.java b/src/solaris/classes/sun/nio/fs/UnixFileSystem.java new file mode 100644 index 0000000000000000000000000000000000000000..6e46b2647d9c538d8ad316bfb09f25723993ab02 --- /dev/null +++ b/src/solaris/classes/sun/nio/fs/UnixFileSystem.java @@ -0,0 +1,380 @@ +/* + * Copyright 2008-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 sun.nio.fs; + +import java.nio.file.*; +import java.nio.file.attribute.*; +import java.nio.file.spi.*; +import java.io.IOException; +import java.util.*; +import java.util.regex.Pattern; +import java.security.AccessController; +import sun.security.action.GetPropertyAction; + +/** + * Base implementation of FileSystem for Unix-like implementations. + */ + +abstract class UnixFileSystem + extends FileSystem +{ + private final UnixFileSystemProvider provider; + private final byte[] defaultDirectory; + private final boolean needToResolveAgainstDefaultDirectory; + private final UnixPath rootDirectory; + + // package-private + UnixFileSystem(UnixFileSystemProvider provider, String dir) { + this.provider = provider; + this.defaultDirectory = UnixPath.normalizeAndCheck(dir).getBytes(); + if (this.defaultDirectory[0] != '/') { + throw new RuntimeException("default directory must be absolute"); + } + + // if process-wide chdir is allowed or default directory is not the + // process working directory then paths must be resolved against the + // default directory. + String propValue = AccessController.doPrivileged( + new GetPropertyAction("sun.nio.fs.chdirAllowed", "false")); + boolean chdirAllowed = (propValue.length() == 0) ? + true : Boolean.valueOf(propValue); + if (chdirAllowed) { + this.needToResolveAgainstDefaultDirectory = true; + } else { + byte[] cwd = UnixNativeDispatcher.getcwd(); + boolean defaultIsCwd = (cwd.length == defaultDirectory.length); + if (defaultIsCwd) { + for (int i=0; i<cwd.length; i++) { + if (cwd[i] != defaultDirectory[i]) { + defaultIsCwd = false; + break; + } + } + } + this.needToResolveAgainstDefaultDirectory = !defaultIsCwd; + } + + // the root directory + this.rootDirectory = new UnixPath(this, "/"); + } + + // package-private + byte[] defaultDirectory() { + return defaultDirectory; + } + + boolean needToResolveAgainstDefaultDirectory() { + return needToResolveAgainstDefaultDirectory; + } + + UnixPath rootDirectory() { + return rootDirectory; + } + + boolean isSolaris() { + return false; + } + + @Override + public final FileSystemProvider provider() { + return provider; + } + + @Override + public final String getSeparator() { + return "/"; + } + + @Override + public final boolean isOpen() { + return true; + } + + @Override + public final boolean isReadOnly() { + return false; + } + + @Override + public final void close() throws IOException { + throw new UnsupportedOperationException(); + } + + /** + * Copies non-POSIX attributes from the source to target file. + * + * Copying a file preserving attributes, or moving a file, will preserve + * the file owner/group/permissions/timestamps but it does not preserve + * other non-POSIX attributes. This method is invoked by the + * copy or move operation to preserve these attributes. It should copy + * extended attributes, ACLs, or other attributes. + * + * @param sfd + * Open file descriptor to source file + * @param tfd + * Open file descriptor to target file + */ + abstract void copyNonPosixAttributes(int sfd, int tfd); + + /** + * Tells if directory relative system calls (openat, etc.) are available + * on this operating system. + */ + abstract boolean supportsSecureDirectoryStreams(); + + /** + * Unix systems only have a single root directory (/) + */ + @Override + public final Iterable<Path> getRootDirectories() { + final List<Path> allowedList = + Collections.unmodifiableList(Arrays.asList((Path)rootDirectory)); + return new Iterable<Path>() { + public Iterator<Path> iterator() { + try { + SecurityManager sm = System.getSecurityManager(); + if (sm != null) + sm.checkRead(rootDirectory.toString()); + return allowedList.iterator(); + } catch (SecurityException x) { + List<Path> disallowed = Collections.emptyList(); + return disallowed.iterator(); + } + } + }; + } + + /** + * Returns object to iterate over entries in mounttab or equivalent + */ + abstract Iterable<UnixMountEntry> getMountEntries(); + + /** + * Returns a FileStore to represent the file system where the given file + * reside. + */ + abstract FileStore getFileStore(UnixPath path) throws IOException; + + /** + * Returns a FileStore to represent the file system for the given mount + * mount. + */ + abstract FileStore getFileStore(UnixMountEntry entry) throws IOException; + + /** + * Iterator returned by getFileStores method. + */ + private class FileStoreIterator implements Iterator<FileStore> { + private final Iterator<UnixMountEntry> entries; + private FileStore next; + + FileStoreIterator() { + this.entries = getMountEntries().iterator(); + } + + private FileStore readNext() { + assert Thread.holdsLock(this); + for (;;) { + if (!entries.hasNext()) + return null; + UnixMountEntry entry = entries.next(); + + // skip entries with the "ignore" option + if (entry.isIgnored()) + continue; + + // check permission to read mount point + SecurityManager sm = System.getSecurityManager(); + if (sm != null) { + try { + sm.checkRead(new String(entry.dir())); + } catch (SecurityException x) { + continue; + } + } + try { + return getFileStore(entry); + } catch (IOException ignore) { + // ignore as per spec + } + } + } + + @Override + public synchronized boolean hasNext() { + if (next != null) + return true; + next = readNext(); + return next != null; + } + + @Override + public synchronized FileStore next() { + if (next == null) + next = readNext(); + if (next == null) { + throw new NoSuchElementException(); + } else { + FileStore result = next; + next = null; + return result; + } + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + } + + @Override + public final Iterable<FileStore> getFileStores() { + SecurityManager sm = System.getSecurityManager(); + if (sm != null) { + try { + sm.checkPermission(new RuntimePermission("getFileStoreAttributes")); + } catch (SecurityException se) { + return Collections.emptyList(); + } + } + return new Iterable<FileStore>() { + public Iterator<FileStore> iterator() { + return new FileStoreIterator(); + } + }; + } + + @Override + public final UnixPath getPath(String path) { + return new UnixPath(this, path); + } + + @Override + public PathMatcher getPathMatcher(String syntaxAndInput) { + int pos = syntaxAndInput.indexOf(':'); + if (pos <= 0 || pos == syntaxAndInput.length()) + throw new IllegalArgumentException(); + String syntax = syntaxAndInput.substring(0, pos); + String input = syntaxAndInput.substring(pos+1); + + String expr; + if (syntax.equals(GLOB_SYNTAX)) { + expr = Globs.toUnixRegexPattern(input); + } else { + if (syntax.equals(REGEX_SYNTAX)) { + expr = input; + } else { + throw new UnsupportedOperationException("Syntax '" + syntax + + "' not recognized"); + } + } + + // return matcher + final Pattern pattern = Pattern.compile(expr); + return new PathMatcher() { + @Override + public boolean matches(Path path) { + return pattern.matcher(path.toString()).matches(); + } + }; + } + private static final String GLOB_SYNTAX = "glob"; + private static final String REGEX_SYNTAX = "regex"; + + protected boolean followLinks(LinkOption... options) { + boolean followLinks = true; + for (LinkOption option: options) { + if (option == LinkOption.NOFOLLOW_LINKS) { + followLinks = false; + continue; + } + if (option == null) + throw new NullPointerException(); + throw new AssertionError("Should not get here"); + } + return followLinks; + } + + @SuppressWarnings("unchecked") + protected <V extends FileAttributeView> V newFileAttributeView(Class<V> view, + UnixPath file, + LinkOption... options) + { + if (view == null) + throw new NullPointerException(); + boolean followLinks = followLinks(options); + Class<?> c = view; + if (c == BasicFileAttributeView.class) + return (V) UnixFileAttributeViews.createBasicView(file, followLinks); + if (c == PosixFileAttributeView.class) + return (V) UnixFileAttributeViews.createPosixView(file, followLinks); + if (c == FileOwnerAttributeView.class) + return (V) UnixFileAttributeViews.createOwnerView(file, followLinks); + return (V) null; + } + + static List<String> standardFileAttributeViews() { + return Arrays.asList("basic", "posix", "unix", "owner"); + } + + protected FileAttributeView newFileAttributeView(String name, + UnixPath file, + LinkOption... options) + { + boolean followLinks = followLinks(options); + if (name.equals("basic")) + return UnixFileAttributeViews.createBasicView(file, followLinks); + if (name.equals("posix")) + return UnixFileAttributeViews.createPosixView(file, followLinks); + if (name.equals("unix")) + return UnixFileAttributeViews.createUnixView(file, followLinks); + if (name.equals("owner")) + return UnixFileAttributeViews.createOwnerView(file, followLinks); + return null; + } + + @Override + public final UserPrincipalLookupService getUserPrincipalLookupService() { + return theLookupService; + } + + private static final UserPrincipalLookupService theLookupService = + new UserPrincipalLookupService() { + @Override + public UserPrincipal lookupPrincipalByName(String name) + throws IOException + { + return UnixUserPrincipals.lookupUser(name); + } + + @Override + public GroupPrincipal lookupPrincipalByGroupName(String group) + throws IOException + { + return UnixUserPrincipals.lookupGroup(group); + } + }; +} diff --git a/src/solaris/classes/sun/nio/fs/UnixFileSystemProvider.java b/src/solaris/classes/sun/nio/fs/UnixFileSystemProvider.java new file mode 100644 index 0000000000000000000000000000000000000000..878fe25c5e407781cca46e625ceacb97e5618711 --- /dev/null +++ b/src/solaris/classes/sun/nio/fs/UnixFileSystemProvider.java @@ -0,0 +1,139 @@ +/* + * Copyright 2008-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 sun.nio.fs; + +import java.nio.file.*; +import java.nio.file.attribute.*; +import java.nio.file.spi.FileSystemProvider; +import java.nio.channels.*; +import java.net.URI; +import java.util.concurrent.ExecutorService; +import java.io.IOException; +import java.util.*; + +import sun.nio.ch.ThreadPool; + +/** + * Base implementation of FileSystemProvider + */ + +public abstract class UnixFileSystemProvider + extends FileSystemProvider +{ + private static final String USER_DIR = "user.dir"; + private final UnixFileSystem theFileSystem; + + public UnixFileSystemProvider() { + String userDir = System.getProperty(USER_DIR); + theFileSystem = newFileSystem(userDir); + } + + /** + * Constructs a new file system using the given default directory. + */ + abstract UnixFileSystem newFileSystem(String dir); + + @Override + public final String getScheme() { + return "file"; + } + + private void checkUri(URI uri) { + if (!uri.getScheme().equalsIgnoreCase(getScheme())) + throw new IllegalArgumentException("URI does not match this provider"); + if (uri.getAuthority() != null) + throw new IllegalArgumentException("Authority component present"); + if (uri.getPath() == null) + throw new IllegalArgumentException("Path component is undefined"); + if (!uri.getPath().equals("/")) + throw new IllegalArgumentException("Path component should be '/'"); + if (uri.getQuery() != null) + throw new IllegalArgumentException("Query component present"); + if (uri.getFragment() != null) + throw new IllegalArgumentException("Fragment component present"); + } + + @Override + public final FileSystem newFileSystem(URI uri, Map<String,?> env) { + checkUri(uri); + throw new FileSystemAlreadyExistsException(); + } + + @Override + public final FileSystem getFileSystem(URI uri) { + checkUri(uri); + return theFileSystem; + } + + @Override + public Path getPath(URI uri) { + return UnixUriUtils.fromUri(theFileSystem, uri); + } + + private UnixPath checkPath(Path obj) { + if (obj == null) + throw new NullPointerException(); + if (!(obj instanceof UnixPath)) + throw new ProviderMismatchException(); + return (UnixPath)obj; + } + + @Override + public final FileChannel newFileChannel(Path obj, + Set<? extends OpenOption> options, + FileAttribute<?>... attrs) + throws IOException + { + UnixPath file = checkPath(obj); + int mode = UnixFileModeAttribute + .toUnixMode(UnixFileModeAttribute.ALL_READWRITE, attrs); + try { + return UnixChannelFactory.newFileChannel(file, options, mode); + } catch (UnixException x) { + x.rethrowAsIOException(file); + return null; + } + } + + @Override + public final AsynchronousFileChannel newAsynchronousFileChannel(Path obj, + Set<? extends OpenOption> options, + ExecutorService executor, + FileAttribute<?>... attrs) throws IOException + { + UnixPath file = checkPath(obj); + int mode = UnixFileModeAttribute + .toUnixMode(UnixFileModeAttribute.ALL_READWRITE, attrs); + ThreadPool pool = (executor == null) ? null : ThreadPool.wrap(executor, 0); + try { + return UnixChannelFactory + .newAsynchronousFileChannel(file, options, mode, pool); + } catch (UnixException x) { + x.rethrowAsIOException(file); + return null; + } + } +} diff --git a/src/solaris/classes/sun/nio/fs/UnixMountEntry.java b/src/solaris/classes/sun/nio/fs/UnixMountEntry.java new file mode 100644 index 0000000000000000000000000000000000000000..c4769e7a7d8009c5f76a50cbd74eb12ed3795be9 --- /dev/null +++ b/src/solaris/classes/sun/nio/fs/UnixMountEntry.java @@ -0,0 +1,85 @@ +/* + * Copyright 2008-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 sun.nio.fs; + +/** + * Represents an entry in the mount table. + */ + +class UnixMountEntry { + private byte[] name; // file system name + private byte[] dir; // directory (mount point) + private byte[] fstype; // ufs, nfs, ... + private byte[] opts; // mount options + private long dev; // device ID + + private volatile String fstypeAsString; + private volatile String optionsAsString; + + UnixMountEntry() { + } + + String name() { + return new String(name); + } + + String fstype() { + if (fstypeAsString == null) + fstypeAsString = new String(fstype); + return fstypeAsString; + } + + byte[] dir() { + return dir; + } + + long dev() { + return dev; + } + + /** + * Tells whether the mount entry has the given option. + */ + boolean hasOption(String requested) { + if (optionsAsString == null) + optionsAsString = new String(opts); + for (String opt: optionsAsString.split("\\,", 0)) { + if (opt.equals(requested)) + return true; + } + return false; + } + + // generic option + boolean isIgnored() { + return hasOption("ignore"); + } + + // generic option + boolean isReadOnly() { + return hasOption("ro"); + } +} diff --git a/src/solaris/classes/sun/nio/fs/UnixNativeDispatcher.java b/src/solaris/classes/sun/nio/fs/UnixNativeDispatcher.java new file mode 100644 index 0000000000000000000000000000000000000000..29140e3ec31dd2dac8a5f9dc11e32738e806b87c --- /dev/null +++ b/src/solaris/classes/sun/nio/fs/UnixNativeDispatcher.java @@ -0,0 +1,556 @@ +/* + * Copyright 2008-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 sun.nio.fs; + +import java.security.AccessController; +import java.security.PrivilegedAction; + +/** + * Unix system and library calls. + */ + +class UnixNativeDispatcher { + protected UnixNativeDispatcher() { } + + // returns a NativeBuffer containing the given path + private static NativeBuffer copyToNativeBuffer(UnixPath path) { + byte[] cstr = path.getByteArrayForSysCalls(); + int size = cstr.length + 1; + NativeBuffer buffer = NativeBuffers.getNativeBufferFromCache(size); + if (buffer == null) { + buffer = NativeBuffers.allocNativeBuffer(size); + } else { + // buffer already contains the path + if (buffer.owner() == path) + return buffer; + } + NativeBuffers.copyCStringToNativeBuffer(cstr, buffer); + buffer.setOwner(path); + return buffer; + } + + /** + * char *getcwd(char *buf, size_t size); + */ + static native byte[] getcwd(); + + /** + * int dup(int filedes) + */ + static native int dup(int filedes) throws UnixException; + + /** + * int open(const char* path, int oflag, mode_t mode) + */ + static int open(UnixPath path, int flags, int mode) throws UnixException { + NativeBuffer buffer = copyToNativeBuffer(path); + try { + return open0(buffer.address(), flags, mode); + } finally { + buffer.release(); + } + } + private static native int open0(long pathAddress, int flags, int mode) + throws UnixException; + + /** + * int openat(int dfd, const char* path, int oflag, mode_t mode) + */ + static int openat(int dfd, byte[] path, int flags, int mode) throws UnixException { + NativeBuffer buffer = NativeBuffers.asNativeBuffer(path); + try { + return openat0(dfd, buffer.address(), flags, mode); + } finally { + buffer.release(); + } + } + private static native int openat0(int dfd, long pathAddress, int flags, int mode) + throws UnixException; + + /** + * close(int filedes) + */ + static native void close(int fd); + + /** + * FILE* fopen(const char *filename, const char* mode); + */ + static long fopen(UnixPath filename, String mode) throws UnixException { + NativeBuffer pathBuffer = copyToNativeBuffer(filename); + NativeBuffer modeBuffer = NativeBuffers.asNativeBuffer(mode.getBytes()); + try { + return fopen0(pathBuffer.address(), modeBuffer.address()); + } finally { + modeBuffer.release(); + pathBuffer.release(); + } + } + private static native long fopen0(long pathAddress, long modeAddress) + throws UnixException; + + /** + * fclose(FILE* stream) + */ + static native void fclose(long stream) throws UnixException; + + /** + * link(const char* existing, const char* new) + */ + static void link(UnixPath existing, UnixPath newfile) throws UnixException { + NativeBuffer existingBuffer = copyToNativeBuffer(existing); + NativeBuffer newBuffer = copyToNativeBuffer(newfile); + try { + link0(existingBuffer.address(), newBuffer.address()); + } finally { + newBuffer.release(); + existingBuffer.release(); + } + } + private static native void link0(long existingAddress, long newAddress) + throws UnixException; + + /** + * unlink(const char* path) + */ + static void unlink(UnixPath path) throws UnixException { + NativeBuffer buffer = copyToNativeBuffer(path); + try { + unlink0(buffer.address()); + } finally { + buffer.release(); + } + } + private static native void unlink0(long pathAddress) throws UnixException; + + /** + * unlinkat(int dfd, const char* path, int flag) + */ + static void unlinkat(int dfd, byte[] path, int flag) throws UnixException { + NativeBuffer buffer = NativeBuffers.asNativeBuffer(path); + try { + unlinkat0(dfd, buffer.address(), flag); + } finally { + buffer.release(); + } + } + private static native void unlinkat0(int dfd, long pathAddress, int flag) + throws UnixException; + + /** + * mknod(const char* path, mode_t mode, dev_t dev) + */ + static void mknod(UnixPath path, int mode, long dev) throws UnixException { + NativeBuffer buffer = copyToNativeBuffer(path); + try { + mknod0(buffer.address(), mode, dev); + } finally { + buffer.release(); + } + } + private static native void mknod0(long pathAddress, int mode, long dev) + throws UnixException; + + /** + * rename(const char* old, const char* new) + */ + static void rename(UnixPath from, UnixPath to) throws UnixException { + NativeBuffer fromBuffer = copyToNativeBuffer(from); + NativeBuffer toBuffer = copyToNativeBuffer(to); + try { + rename0(fromBuffer.address(), toBuffer.address()); + } finally { + toBuffer.release(); + fromBuffer.release(); + } + } + private static native void rename0(long fromAddress, long toAddress) + throws UnixException; + + /** + * renameat(int fromfd, const char* old, int tofd, const char* new) + */ + static void renameat(int fromfd, byte[] from, int tofd, byte[] to) throws UnixException { + NativeBuffer fromBuffer = NativeBuffers.asNativeBuffer(from); + NativeBuffer toBuffer = NativeBuffers.asNativeBuffer(to); + try { + renameat0(fromfd, fromBuffer.address(), tofd, toBuffer.address()); + } finally { + toBuffer.release(); + fromBuffer.release(); + } + } + private static native void renameat0(int fromfd, long fromAddress, int tofd, long toAddress) + throws UnixException; + + /** + * mkdir(const char* path, mode_t mode) + */ + static void mkdir(UnixPath path, int mode) throws UnixException { + NativeBuffer buffer = copyToNativeBuffer(path); + try { + mkdir0(buffer.address(), mode); + } finally { + buffer.release(); + } + } + private static native void mkdir0(long pathAddress, int mode) throws UnixException; + + /** + * rmdir(const char* path) + */ + static void rmdir(UnixPath path) throws UnixException { + NativeBuffer buffer = copyToNativeBuffer(path); + try { + rmdir0(buffer.address()); + } finally { + buffer.release(); + } + } + private static native void rmdir0(long pathAddress) throws UnixException; + + /** + * readlink(const char* path, char* buf, size_t bufsize) + * + * @return link target + */ + static byte[] readlink(UnixPath path) throws UnixException { + NativeBuffer buffer = copyToNativeBuffer(path); + try { + return readlink0(buffer.address()); + } finally { + buffer.release(); + } + } + private static native byte[] readlink0(long pathAddress) throws UnixException; + + /** + * realpath(const char* path, char* resolved_name) + * + * @return resolved path + */ + static byte[] realpath(UnixPath path) throws UnixException { + NativeBuffer buffer = copyToNativeBuffer(path); + try { + return realpath0(buffer.address()); + } finally { + buffer.release(); + } + } + private static native byte[] realpath0(long pathAddress) throws UnixException; + + /** + * symlink(const char* name1, const char* name2) + */ + static void symlink(byte[] name1, UnixPath name2) throws UnixException { + NativeBuffer targetBuffer = NativeBuffers.asNativeBuffer(name1); + NativeBuffer linkBuffer = copyToNativeBuffer(name2); + try { + symlink0(targetBuffer.address(), linkBuffer.address()); + } finally { + linkBuffer.release(); + targetBuffer.release(); + } + } + private static native void symlink0(long name1, long name2) + throws UnixException; + + /** + * stat(const char* path, struct stat* buf) + */ + static void stat(UnixPath path, UnixFileAttributes attrs) throws UnixException { + NativeBuffer buffer = copyToNativeBuffer(path); + try { + stat0(buffer.address(), attrs); + } finally { + buffer.release(); + } + } + private static native void stat0(long pathAddress, UnixFileAttributes attrs) + throws UnixException; + + /** + * lstat(const char* path, struct stat* buf) + */ + static void lstat(UnixPath path, UnixFileAttributes attrs) throws UnixException { + NativeBuffer buffer = copyToNativeBuffer(path); + try { + lstat0(buffer.address(), attrs); + } finally { + buffer.release(); + } + } + private static native void lstat0(long pathAddress, UnixFileAttributes attrs) + throws UnixException; + + /** + * fstat(int filedes, struct stat* buf) + */ + static native void fstat(int fd, UnixFileAttributes attrs) throws UnixException; + + /** + * fstatat(int filedes,const char* path, struct stat* buf, int flag) + */ + static void fstatat(int dfd, byte[] path, int flag, UnixFileAttributes attrs) + throws UnixException + { + NativeBuffer buffer = NativeBuffers.asNativeBuffer(path); + try { + fstatat0(dfd, buffer.address(), flag, attrs); + } finally { + buffer.release(); + } + } + private static native void fstatat0(int dfd, long pathAddress, int flag, + UnixFileAttributes attrs) throws UnixException; + + /** + * chown(const char* path, uid_t owner, gid_t group) + */ + static void chown(UnixPath path, int uid, int gid) throws UnixException { + NativeBuffer buffer = copyToNativeBuffer(path); + try { + chown0(buffer.address(), uid, gid); + } finally { + buffer.release(); + } + } + private static native void chown0(long pathAddress, int uid, int gid) + throws UnixException; + + /** + * lchown(const char* path, uid_t owner, gid_t group) + */ + static void lchown(UnixPath path, int uid, int gid) throws UnixException { + NativeBuffer buffer = copyToNativeBuffer(path); + try { + lchown0(buffer.address(), uid, gid); + } finally { + buffer.release(); + } + } + private static native void lchown0(long pathAddress, int uid, int gid) + throws UnixException; + + /** + * fchown(int filedes, uid_t owner, gid_t group) + */ + static native void fchown(int fd, int uid, int gid) throws UnixException; + + /** + * chmod(const char* path, mode_t mode) + */ + static void chmod(UnixPath path, int mode) throws UnixException { + NativeBuffer buffer = copyToNativeBuffer(path); + try { + chmod0(buffer.address(), mode); + } finally { + buffer.release(); + } + } + private static native void chmod0(long pathAddress, int mode) + throws UnixException; + + /** + * fchmod(int fildes, mode_t mode) + */ + static native void fchmod(int fd, int mode) throws UnixException; + + /** + * utimes(conar char* path, const struct timeval times[2]) + */ + static void utimes(UnixPath path, long times0, long times1) + throws UnixException + { + NativeBuffer buffer = copyToNativeBuffer(path); + try { + utimes0(buffer.address(), times0, times1); + } finally { + buffer.release(); + } + } + private static native void utimes0(long pathAddress, long times0, long times1) + throws UnixException; + + /** + * futimes(int fildes,, const struct timeval times[2]) + */ + static native void futimes(int fd, long times0, long times1) throws UnixException; + + /** + * DIR *opendir(const char* dirname) + */ + static long opendir(UnixPath path) throws UnixException { + NativeBuffer buffer = copyToNativeBuffer(path); + try { + return opendir0(buffer.address()); + } finally { + buffer.release(); + } + } + private static native long opendir0(long pathAddress) throws UnixException; + + /** + * DIR* fdopendir(int filedes) + */ + static native long fdopendir(int dfd) throws UnixException; + + + /** + * closedir(DIR* dirp) + */ + static native void closedir(long dir) throws UnixException; + + /** + * struct dirent* readdir(DIR *dirp) + * + * @return dirent->d_name + */ + static native byte[] readdir(long dir) throws UnixException; + + /** + * size_t read(int fildes, void* buf, size_t nbyte) + */ + static native int read(int fildes, long buf, int nbyte) throws UnixException; + + /** + * size_t writeint fildes, void* buf, size_t nbyte) + */ + static native int write(int fildes, long buf, int nbyte) throws UnixException; + + /** + * access(const char* path, int amode); + */ + static void access(UnixPath path, int amode) throws UnixException { + NativeBuffer buffer = copyToNativeBuffer(path); + try { + access0(buffer.address(), amode); + } finally { + buffer.release(); + } + } + private static native void access0(long pathAddress, int amode) throws UnixException; + + /** + * struct passwd *getpwuid(uid_t uid); + * + * @return passwd->pw_name + */ + static native byte[] getpwuid(int uid) throws UnixException; + + /** + * struct group *getgrgid(gid_t gid); + * + * @return group->gr_name + */ + static native byte[] getgrgid(int gid) throws UnixException; + + /** + * struct passwd *getpwnam(const char *name); + * + * @return passwd->pw_uid + */ + static int getpwnam(String name) throws UnixException { + NativeBuffer buffer = NativeBuffers.asNativeBuffer(name.getBytes()); + try { + return getpwnam0(buffer.address()); + } finally { + buffer.release(); + } + } + private static native int getpwnam0(long nameAddress) throws UnixException; + + /** + * struct group *getgrnam(const char *name); + * + * @return group->gr_name + */ + static int getgrnam(String name) throws UnixException { + NativeBuffer buffer = NativeBuffers.asNativeBuffer(name.getBytes()); + try { + return getgrnam0(buffer.address()); + } finally { + buffer.release(); + } + } + private static native int getgrnam0(long nameAddress) throws UnixException; + + /** + * int getextmntent(FILE *fp, struct extmnttab *mp, int len); + */ + static native int getextmntent(long fp, UnixMountEntry entry) throws UnixException; + + /** + * statvfs(const char* path, struct statvfs *buf) + */ + static void statvfs(UnixPath path, UnixFileStoreAttributes attrs) + throws UnixException + { + NativeBuffer buffer = copyToNativeBuffer(path); + try { + statvfs0(buffer.address(), attrs); + } finally { + buffer.release(); + } + } + private static native void statvfs0(long pathAddress, UnixFileStoreAttributes attrs) + throws UnixException; + + /** + * long int pathconf(const char *path, int name); + */ + static long pathconf(UnixPath path, int name) throws UnixException { + NativeBuffer buffer = copyToNativeBuffer(path); + try { + return pathconf0(buffer.address(), name); + } finally { + buffer.release(); + } + } + private static native long pathconf0(long pathAddress, int name) + throws UnixException; + + /** + * long fpathconf(int fildes, int name); + */ + static native long fpathconf(int filedes, int name) throws UnixException; + + /** + * char* strerror(int errnum) + */ + static native byte[] strerror(int errnum); + + // initialize field IDs + private static native void initIDs(); + + static { + AccessController.doPrivileged(new PrivilegedAction<Void>() { + public Void run() { + System.loadLibrary("nio"); + return null; + }}); + initIDs(); + } +} diff --git a/src/solaris/classes/sun/nio/fs/UnixPath.java b/src/solaris/classes/sun/nio/fs/UnixPath.java new file mode 100644 index 0000000000000000000000000000000000000000..c1330f005ce8a3abcd8831613c3fbb1fe112e99e --- /dev/null +++ b/src/solaris/classes/sun/nio/fs/UnixPath.java @@ -0,0 +1,1228 @@ +/* + * Copyright 2008-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 sun.nio.fs; + +import java.nio.*; +import java.nio.file.*; +import java.nio.file.attribute.*; +import java.nio.file.spi.AbstractPath; +import java.nio.charset.*; +import java.nio.channels.*; +import java.security.AccessController; +import java.io.*; +import java.net.URI; +import java.util.*; +import java.lang.ref.SoftReference; +import sun.security.util.SecurityConstants; + +import static sun.nio.fs.UnixNativeDispatcher.*; +import static sun.nio.fs.UnixConstants.*; + +/** + * Solaris/Linux implementation of java.nio.file.Path + */ + +class UnixPath + extends AbstractPath +{ + private static ThreadLocal<SoftReference<CharsetEncoder>> encoder = + new ThreadLocal<SoftReference<CharsetEncoder>>(); + + // FIXME - eliminate this reference to reduce space + private final UnixFileSystem fs; + + // internal representation + private final byte[] path; + + // String representation (created lazily) + private volatile String stringValue; + + // cached hashcode (created lazily, no need to be volatile) + private int hash; + + // array of offsets of elements in path (created lazily) + private volatile int[] offsets; + + // file permissions (created lazily) + private volatile FilePermission[] perms; + + UnixPath(UnixFileSystem fs, byte[] path) { + this.fs = fs; + this.path = path; + } + + UnixPath(UnixFileSystem fs, String input) { + // removes redundant slashes and checks for invalid characters + this(fs, encode(normalizeAndCheck(input))); + } + + // package-private + // removes redundant slashes and check input for invalid characters + static String normalizeAndCheck(String input) { + int n = input.length(); + if (n == 0) + throw new InvalidPathException(input, "Path is empty"); + char prevChar = 0; + for (int i=0; i < n; i++) { + char c = input.charAt(i); + if (c == '\u0000') + throw new InvalidPathException(input, "Nul character not allowed"); + if ((c == '/') && (prevChar == '/')) + return normalize(input, n, i - 1); + prevChar = c; + } + if (prevChar == '/') + return normalize(input, n, n - 1); + return input; + } + + private static String normalize(String input, int len, int off) { + if (len == 0) + return input; + int n = len; + while ((n > 0) && (input.charAt(n - 1) == '/')) n--; + if (n == 0) + return "/"; + StringBuilder sb = new StringBuilder(input.length()); + if (off > 0) + sb.append(input.substring(0, off)); + char prevChar = 0; + for (int i=off; i < n; i++) { + char c = input.charAt(i); + if ((c == '/') && (prevChar == '/')) + continue; + sb.append(c); + prevChar = c; + } + return sb.toString(); + } + + // encodes the given path-string into a sequence of bytes + private static byte[] encode(String input) { + SoftReference<CharsetEncoder> ref = encoder.get(); + CharsetEncoder ce = (ref != null) ? ref.get() : null; + if (ce == null) { + ce = Charset.defaultCharset().newEncoder() + .onMalformedInput(CodingErrorAction.REPORT) + .onUnmappableCharacter(CodingErrorAction.REPORT); + encoder.set(new SoftReference<CharsetEncoder>(ce)); + } + + char[] ca = input.toCharArray(); + + // size output buffer for worse-case size + byte[] ba = new byte[(int)(ca.length * (double)ce.maxBytesPerChar())]; + + // encode + ByteBuffer bb = ByteBuffer.wrap(ba); + CharBuffer cb = CharBuffer.wrap(ca); + ce.reset(); + CoderResult cr = ce.encode(cb, bb, true); + boolean error; + if (!cr.isUnderflow()) { + error = true; + } else { + cr = ce.flush(bb); + error = !cr.isUnderflow(); + } + if (error) { + throw new InvalidPathException(input, + "Malformed input or input contains unmappable chacraters"); + } + + // trim result to actual length if required + int len = bb.position(); + if (len != ba.length) + ba = Arrays.copyOf(ba, len); + + return ba; + } + + // package-private + byte[] asByteArray() { + return path; + } + + // use this path when making system/library calls + byte[] getByteArrayForSysCalls() { + // resolve against default directory if required (chdir allowed or + // file system default directory is not working directory) + if (getFileSystem().needToResolveAgainstDefaultDirectory()) { + return resolve(getFileSystem().defaultDirectory(), path); + } else { + return path; + } + } + + // use this message when throwing exceptions + String getPathForExecptionMessage() { + return toString(); + } + + // use this path for permission checks + String getPathForPermissionCheck() { + if (getFileSystem().needToResolveAgainstDefaultDirectory()) { + return new String(getByteArrayForSysCalls()); + } else { + return toString(); + } + } + + // Checks that the given file is a UnixPath + private UnixPath checkPath(FileRef obj) { + if (obj == null) + throw new NullPointerException(); + if (!(obj instanceof UnixPath)) + throw new ProviderMismatchException(); + return (UnixPath)obj; + } + + // create offset list if not already created + private void initOffsets() { + if (offsets == null) { + int count, index; + + // count names + count = 0; + index = 0; + while (index < path.length) { + byte c = path[index++]; + if (c != '/') { + count++; + while (index < path.length && path[index] != '/') + index++; + } + } + + // populate offsets + int[] result = new int[count]; + count = 0; + index = 0; + while (index < path.length) { + byte c = path[index]; + if (c == '/') { + index++; + } else { + result[count++] = index++; + while (index < path.length && path[index] != '/') + index++; + } + } + synchronized (this) { + if (offsets == null) + offsets = result; + } + } + } + + @Override + public UnixFileSystem getFileSystem() { + return fs; + } + + @Override + public UnixPath getRoot() { + if (path[0] == '/') { + return getFileSystem().rootDirectory(); + } else { + return null; + } + } + + @Override + public UnixPath getName() { + initOffsets(); + + int count = offsets.length; + if (count == 0) + return null; // no elements so no name + + if (count == 1 && path[0] != '/') + return this; + + int lastOffset = offsets[count-1]; + int len = path.length - lastOffset; + byte[] result = new byte[len]; + System.arraycopy(path, lastOffset, result, 0, len); + return new UnixPath(getFileSystem(), result); + } + + @Override + public UnixPath getParent() { + initOffsets(); + + int count = offsets.length; + if (count == 0) { + // no elements so no parent + return null; + } + int len = offsets[count-1] - 1; + if (len <= 0) { + // parent is root only (may be null) + return getRoot(); + } + byte[] result = new byte[len]; + System.arraycopy(path, 0, result, 0, len); + return new UnixPath(getFileSystem(), result); + } + + @Override + public int getNameCount() { + initOffsets(); + return offsets.length; + } + + @Override + public UnixPath getName(int index) { + initOffsets(); + if (index < 0) + throw new IllegalArgumentException(); + if (index >= offsets.length) + throw new IllegalArgumentException(); + + int begin = offsets[index]; + int len; + if (index == (offsets.length-1)) { + len = path.length - begin; + } else { + len = offsets[index+1] - begin - 1; + } + + // construct result + byte[] result = new byte[len]; + System.arraycopy(path, begin, result, 0, len); + return new UnixPath(getFileSystem(), result); + } + + @Override + public UnixPath subpath(int beginIndex, int endIndex) { + initOffsets(); + + if (beginIndex < 0) + throw new IllegalArgumentException(); + if (beginIndex >= offsets.length) + throw new IllegalArgumentException(); + if (endIndex > offsets.length) + throw new IllegalArgumentException(); + if (beginIndex >= endIndex) { + throw new IllegalArgumentException(); + } + + // starting offset and length + int begin = offsets[beginIndex]; + int len; + if (endIndex == offsets.length) { + len = path.length - begin; + } else { + len = offsets[endIndex] - begin - 1; + } + + // construct result + byte[] result = new byte[len]; + System.arraycopy(path, begin, result, 0, len); + return new UnixPath(getFileSystem(), result); + } + + @Override + public boolean isAbsolute() { + return (path[0] == '/'); + } + + // Resolve child against given base + private static byte[] resolve(byte[] base, byte[] child) { + if (child[0] == '/') + return child; + byte[] result; + if (base.length == 1 && base[0] == '/') { + result = new byte[child.length + 1]; + result[0] = '/'; + System.arraycopy(child, 0, result, 1, child.length); + } else { + result = new byte[base.length + 1 + child.length]; + System.arraycopy(base, 0, result, 0, base.length); + result[base.length] = '/'; + System.arraycopy(child, 0, result, base.length+1, child.length); + } + return result; + } + + @Override + public UnixPath resolve(Path obj) { + if (obj == null) + return this; + byte[] other = checkPath(obj).path; + if (other[0] == '/') + return ((UnixPath)obj); + byte[] result = resolve(path, other); + return new UnixPath(getFileSystem(), result); + } + + @Override + public UnixPath resolve(String other) { + return resolve(new UnixPath(getFileSystem(), other)); + } + + UnixPath resolve(byte[] other) { + return resolve(new UnixPath(getFileSystem(), other)); + } + + @Override + public UnixPath relativize(Path obj) { + UnixPath other = checkPath(obj); + if (other.equals(this)) + return null; + + // can only relativize paths of the same type + if (this.isAbsolute() != other.isAbsolute()) + throw new IllegalArgumentException("'other' is different type of Path"); + + int bn = this.getNameCount(); + int cn = other.getNameCount(); + + // skip matching names + int n = (bn > cn) ? cn : bn; + int i = 0; + while (i < n) { + if (!this.getName(i).equals(other.getName(i))) + break; + i++; + } + + int dotdots = bn - i; + if (i < cn) { + // remaining name components in other + UnixPath remainder = other.subpath(i, cn); + if (dotdots == 0) + return remainder; + + // result is a "../" for each remaining name in base + // followed by the remaining names in other + byte[] result = new byte[dotdots*3 + remainder.path.length]; + int pos = 0; + while (dotdots > 0) { + result[pos++] = (byte)'.'; + result[pos++] = (byte)'.'; + result[pos++] = (byte)'/'; + dotdots--; + } + System.arraycopy(remainder.path, 0, result, pos, remainder.path.length); + return new UnixPath(getFileSystem(), result); + } else { + // no remaining names in other so result is simply a sequence of ".." + byte[] result = new byte[dotdots*3 - 1]; + int pos = 0; + while (dotdots > 0) { + result[pos++] = (byte)'.'; + result[pos++] = (byte)'.'; + // no tailing slash at the end + if (dotdots > 1) + result[pos++] = (byte)'/'; + dotdots--; + } + return new UnixPath(getFileSystem(), result); + } + } + + @Override + public Path normalize() { + final int count = getNameCount(); + if (count == 0) + return this; + + boolean[] ignore = new boolean[count]; // true => ignore name + int[] size = new int[count]; // length of name + int remaining = count; // number of names remaining + boolean hasDotDot = false; // has at least one .. + boolean isAbsolute = path[0] == '/'; + + // first pass: + // 1. compute length of names + // 2. mark all occurences of "." to ignore + // 3. and look for any occurences of ".." + for (int i=0; i<count; i++) { + int begin = offsets[i]; + int len; + if (i == (offsets.length-1)) { + len = path.length - begin; + } else { + len = offsets[i+1] - begin - 1; + } + size[i] = len; + + if (path[begin] == '.') { + if (len == 1) { + ignore[i] = true; // ignore "." + remaining--; + } + else { + if (path[begin+1] == '.') // ".." found + hasDotDot = true; + } + } + } + + // multiple passes to eliminate all occurences of name/.. + if (hasDotDot) { + int prevRemaining; + do { + prevRemaining = remaining; + int prevName = -1; + for (int i=0; i<count; i++) { + if (ignore[i]) + continue; + + // not a ".." + if (size[i] != 2) { + prevName = i; + continue; + } + + int begin = offsets[i]; + if (path[begin] != '.' || path[begin+1] != '.') { + prevName = i; + continue; + } + + // ".." found + if (prevName >= 0) { + // name/<ignored>/.. found so mark name and ".." to be + // ignored + ignore[prevName] = true; + ignore[i] = true; + remaining = remaining - 2; + prevName = -1; + } else { + // Case: /<ignored>/.. so mark ".." as ignored + if (isAbsolute) { + boolean hasPrevious = false; + for (int j=0; j<i; j++) { + if (!ignore[j]) { + hasPrevious = true; + break; + } + } + if (!hasPrevious) { + // all proceeding names are ignored + ignore[i] = true; + remaining--; + } + } + } + } + } while (prevRemaining > remaining); + } + + // no redundant names + if (remaining == count) + return this; + + // corner case - all names removed + if (remaining == 0) { + return isAbsolute ? getFileSystem().rootDirectory() : null; + } + + // compute length of result + int len = remaining - 1; + if (isAbsolute) + len++; + + for (int i=0; i<count; i++) { + if (!ignore[i]) + len += size[i]; + } + byte[] result = new byte[len]; + + // copy names into result + int pos = 0; + if (isAbsolute) + result[pos++] = '/'; + for (int i=0; i<count; i++) { + if (!ignore[i]) { + System.arraycopy(path, offsets[i], result, pos, size[i]); + pos += size[i]; + if (--remaining > 0) { + result[pos++] = '/'; + } + } + } + return new UnixPath(getFileSystem(), result); + } + + @Override + public boolean startsWith(Path other) { + UnixPath that = checkPath(other); + + // other path is longer + if (that.path.length > path.length) + return false; + + int thisOffsetCount = getNameCount(); + int thatOffsetCount = that.getNameCount(); + + // other path has no name elements + if (thatOffsetCount == 0 && this.isAbsolute()) + return true; + + // given path has more elements that this path + if (thatOffsetCount > thisOffsetCount) + return false; + + // same number of elements so must be exact match + if ((thatOffsetCount == thisOffsetCount) && + (path.length != that.path.length)) { + return false; + } + + // check offsets of elements match + for (int i=0; i<thatOffsetCount; i++) { + Integer o1 = offsets[i]; + Integer o2 = that.offsets[i]; + if (!o1.equals(o2)) + return false; + } + + // offsets match so need to compare bytes + int i=0; + while (i < that.path.length) { + if (this.path[i] != that.path[i]) + return false; + i++; + } + + // final check that match is on name boundary + if (i < path.length && this.path[i] != '/') + return false; + + return true; + } + + @Override + public boolean endsWith(Path other) { + UnixPath that = checkPath(other); + + // other path is longer + if (that.path.length > path.length) + return false; + + // other path is absolute so this path must be absolute + if (that.isAbsolute() && !this.isAbsolute()) + return false; + + int thisOffsetCount = getNameCount(); + int thatOffsetCount = that.getNameCount(); + + // given path has more elements that this path + if (thatOffsetCount > thisOffsetCount) { + return false; + } else { + // same number of elements + if (thatOffsetCount == thisOffsetCount) { + if (thisOffsetCount == 0) + return true; + int expectedLen = path.length; + if (this.isAbsolute() && !that.isAbsolute()) + expectedLen--; + if (that.path.length != expectedLen) + return false; + } else { + // this path has more elements so given path must be relative + if (that.isAbsolute()) + return false; + } + } + + // compare bytes + int thisPos = offsets[thisOffsetCount - thatOffsetCount]; + int thatPos = that.offsets[0]; + while (thatPos < that.path.length) { + if (this.path[thisPos++] != that.path[thatPos++]) + return false; + } + + return true; + } + + @Override + public int compareTo(Path other) { + int len1 = path.length; + int len2 = ((UnixPath) other).path.length; + + int n = Math.min(len1, len2); + byte v1[] = path; + byte v2[] = ((UnixPath) other).path; + + int k = 0; + while (k < n) { + int c1 = v1[k] & 0xff; + int c2 = v2[k] & 0xff; + if (c1 != c2) { + return c1 - c2; + } + k++; + } + return len1 - len2; + } + + @Override + public boolean equals(Object ob) { + if ((ob != null) && (ob instanceof UnixPath)) { + return compareTo((Path)ob) == 0; + } + return false; + } + + @Override + public int hashCode() { + // OK if two or more threads compute hash + int h = hash; + if (h == 0) { + for (int i = 0; i< path.length; i++) { + h = 31*h + (path[i] & 0xff); + } + hash = h; + } + return h; + } + + @Override + public String toString() { + // OK if two or more threads create a String + if (stringValue == null) + stringValue = new String(path); // platform encoding + return stringValue; + } + + @Override + public Iterator<Path> iterator() { + initOffsets(); + return new Iterator<Path>() { + int i = 0; + @Override + public boolean hasNext() { + return (i < offsets.length); + } + @Override + public Path next() { + if (i < offsets.length) { + Path result = getName(i); + i++; + return result; + } else { + throw new NoSuchElementException(); + } + } + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + // -- file operations -- + + // package-private + int openForAttributeAccess(boolean followLinks) throws IOException { + int flags = O_RDONLY; + if (!followLinks) + flags |= O_NOFOLLOW; + try { + return open(this, flags, 0); + } catch (UnixException x) { + // HACK: EINVAL instead of ELOOP on Solaris 10 prior to u4 (see 6460380) + if (getFileSystem().isSolaris() && x.errno() == EINVAL) + x.setError(ELOOP); + + if (x.errno() == ELOOP) + throw new FileSystemException(getPathForExecptionMessage(), null, + x.getMessage() + " or unable to access attributes of symbolic link"); + + x.rethrowAsIOException(this); + return -1; // keep compile happy + } + } + + // create file permissions used for read and write checks + private void checkReadOrWrite(boolean checkRead) { + SecurityManager sm = System.getSecurityManager(); + if (sm == null) + return; + if (perms == null) { + synchronized (this) { + if (perms == null) { + FilePermission[] p = new FilePermission[2]; + String pathForPermCheck = getPathForPermissionCheck(); + p[0] = new FilePermission(pathForPermCheck, + SecurityConstants.FILE_READ_ACTION); + p[1] = new FilePermission(pathForPermCheck, + SecurityConstants.FILE_WRITE_ACTION); + perms = p; + } + } + } + if (checkRead) { + sm.checkPermission(perms[0]); + } else { + sm.checkPermission(perms[1]); + } + } + + void checkRead() { + checkReadOrWrite(true); + } + + void checkWrite() { + checkReadOrWrite(false); + } + + void checkDelete() { + SecurityManager sm = System.getSecurityManager(); + if (sm != null) { + // permission not cached + sm.checkDelete(getPathForPermissionCheck()); + } + } + + @Override + public FileStore getFileStore() + throws IOException + { + SecurityManager sm = System.getSecurityManager(); + if (sm != null) { + sm.checkPermission(new RuntimePermission("getFileStoreAttributes")); + checkRead(); + } + return getFileSystem().getFileStore(this); + } + + @Override + public void checkAccess(AccessMode... modes) throws IOException { + boolean e = false; + boolean r = false; + boolean w = false; + boolean x = false; + + if (modes.length == 0) { + e = true; + } else { + for (AccessMode mode: modes) { + switch (mode) { + case READ : r = true; break; + case WRITE : w = true; break; + case EXECUTE : x = true; break; + default: throw new AssertionError("Should not get here"); + } + } + } + + int mode = 0; + if (e || r) { + checkRead(); + mode |= (r) ? R_OK : F_OK; + } + if (w) { + checkWrite(); + mode |= W_OK; + } + if (x) { + SecurityManager sm = System.getSecurityManager(); + if (sm != null) { + // not cached + sm.checkExec(getPathForPermissionCheck()); + } + mode |= X_OK; + } + try { + access(this, mode); + } catch (UnixException exc) { + exc.rethrowAsIOException(this); + } + } + + @Override + public void delete(boolean failIfNotExists) throws IOException { + checkDelete(); + + // need file attributes to know if file is directory + UnixFileAttributes attrs = null; + try { + attrs = UnixFileAttributes.get(this, false); + if (attrs.isDirectory()) { + rmdir(this); + } else { + unlink(this); + } + } catch (UnixException x) { + // no-op if file does not exist + if (!failIfNotExists && x.errno() == ENOENT) + return; + + // DirectoryNotEmptyException if not empty + if (attrs != null && attrs.isDirectory() && + (x.errno() == EEXIST || x.errno() == ENOTEMPTY)) + throw new DirectoryNotEmptyException(getPathForExecptionMessage()); + + x.rethrowAsIOException(this); + } + } + + @Override + public DirectoryStream<Path> newDirectoryStream(DirectoryStream.Filter<? super Path> filter) + throws IOException + { + if (filter == null) + throw new NullPointerException(); + checkRead(); + + // can't return SecureDirectoryStream on older kernels. + if (!getFileSystem().supportsSecureDirectoryStreams()) { + try { + long ptr = opendir(this); + return new UnixDirectoryStream(this, ptr, filter); + } catch (UnixException x) { + if (x.errno() == UnixConstants.ENOTDIR) + throw new NotDirectoryException(getPathForExecptionMessage()); + x.rethrowAsIOException(this); + } + } + + // open directory and dup file descriptor for use by + // opendir/readdir/closedir + int dfd1 = -1; + int dfd2 = -1; + long dp = 0L; + try { + dfd1 = open(this, O_RDONLY, 0); + dfd2 = dup(dfd1); + dp = fdopendir(dfd1); + } catch (UnixException x) { + if (dfd1 != -1) + close(dfd1); + if (dfd2 != -1) + close(dfd2); + if (x.errno() == UnixConstants.ENOTDIR) + throw new NotDirectoryException(getPathForExecptionMessage()); + x.rethrowAsIOException(this); + } + return new UnixSecureDirectoryStream(this, dp, dfd2, filter); + } + + // invoked by AbstractPath#copyTo + @Override + public void implCopyTo(Path obj, CopyOption... options) + throws IOException + { + UnixPath target = (UnixPath)obj; + UnixCopyFile.copy(this, target, options); + } + + @Override + public void implMoveTo(Path obj, CopyOption... options) + throws IOException + { + UnixPath target = (UnixPath)obj; + UnixCopyFile.move(this, target, options); + } + + @Override + @SuppressWarnings("unchecked") + public <V extends FileAttributeView> V + getFileAttributeView(Class<V> type, LinkOption... options) + { + FileAttributeView view = getFileSystem() + .newFileAttributeView(type, this, options); + if (view == null) + return null; + return (V) view; + } + + @Override + public FileAttributeView getFileAttributeView(String name, LinkOption... options) { + return getFileSystem().newFileAttributeView(name, this, options); + } + + @Override + public Path createDirectory(FileAttribute<?>... attrs) + throws IOException + { + checkWrite(); + + int mode = UnixFileModeAttribute + .toUnixMode(UnixFileModeAttribute.ALL_PERMISSIONS, attrs); + try { + mkdir(this, mode); + } catch (UnixException x) { + x.rethrowAsIOException(this); + } + return this; + } + + @Override + public InputStream newInputStream()throws IOException { + try { + Set<OpenOption> options = Collections.emptySet(); + FileChannel fc = UnixChannelFactory.newFileChannel(this, options, 0); + return Channels.newInputStream(fc); + } catch (UnixException x) { + x.rethrowAsIOException(this); + return null; // keep compiler happy + } + } + + @Override + public SeekableByteChannel newByteChannel(Set<? extends OpenOption> options, + FileAttribute<?>... attrs) + throws IOException + { + int mode = UnixFileModeAttribute + .toUnixMode(UnixFileModeAttribute.ALL_READWRITE, attrs); + try { + return UnixChannelFactory.newFileChannel(this, options, mode); + } catch (UnixException x) { + x.rethrowAsIOException(this); + return null; // keep compiler happy + } + } + + @Override + public OutputStream newOutputStream(Set<? extends OpenOption> options, + FileAttribute<?>... attrs) + throws IOException + { + // need to copy options to add WRITE + Set<OpenOption> opts = new HashSet<OpenOption>(options); + if (opts.contains(StandardOpenOption.READ)) + throw new IllegalArgumentException("READ not allowed"); + opts.add(StandardOpenOption.WRITE); + + int mode = UnixFileModeAttribute + .toUnixMode(UnixFileModeAttribute.ALL_READWRITE, attrs); + try { + FileChannel fc = UnixChannelFactory.newFileChannel(this, opts, mode); + return Channels.newOutputStream(fc); + } catch (UnixException x) { + x.rethrowAsIOException(this); + return null; // keep compiler happy + } + } + + @Override + public boolean isSameFile(FileRef obj) throws IOException { + if (this.equals(obj)) + return true; + if (!(obj instanceof UnixPath)) // includes null check + return false; + UnixPath other = (UnixPath)obj; + + // check security manager access to both files + this.checkRead(); + other.checkRead(); + + UnixFileAttributes thisAttrs; + UnixFileAttributes otherAttrs; + try { + thisAttrs = UnixFileAttributes.get(this, true); + } catch (UnixException x) { + x.rethrowAsIOException(this); + return false; // keep compiler happy + } + try { + otherAttrs = UnixFileAttributes.get(other, true); + } catch (UnixException x) { + x.rethrowAsIOException(other); + return false; // keep compiler happy + } + return thisAttrs.isSameFile(otherAttrs); + } + + @Override + public Path createSymbolicLink(Path obj, FileAttribute<?>... attrs) + throws IOException + { + UnixPath target = checkPath(obj); + + // no attributes supported when creating links + if (attrs.length > 0) { + UnixFileModeAttribute.toUnixMode(0, attrs); // may throw NPE or UOE + throw new UnsupportedOperationException("Initial file attributes" + + "not supported when creating symbolic link"); + } + + // permission check + SecurityManager sm = System.getSecurityManager(); + if (sm != null) { + sm.checkPermission(new LinkPermission("symbolic")); + checkWrite(); + } + + // create link + try { + symlink(target.asByteArray(), this); + } catch (UnixException x) { + x.rethrowAsIOException(this); + } + + return this; + } + + @Override + public Path createLink(Path obj) throws IOException { + UnixPath existing = checkPath(obj); + + // permission check + SecurityManager sm = System.getSecurityManager(); + if (sm != null) { + sm.checkPermission(new LinkPermission("hard")); + this.checkWrite(); + existing.checkWrite(); + } + try { + link(existing, this); + } catch (UnixException x) { + x.rethrowAsIOException(this, existing); + } + return this; + } + + @Override + public Path readSymbolicLink() throws IOException { + // permission check + SecurityManager sm = System.getSecurityManager(); + if (sm != null) { + FilePermission perm = new FilePermission(getPathForPermissionCheck(), + SecurityConstants.FILE_READLINK_ACTION); + AccessController.checkPermission(perm); + } + try { + byte[] target = readlink(this); + return new UnixPath(getFileSystem(), target); + } catch (UnixException x) { + if (x.errno() == UnixConstants.EINVAL) + throw new NotLinkException(getPathForExecptionMessage()); + x.rethrowAsIOException(this); + return null; // keep compiler happy + } + } + + @Override + public UnixPath toAbsolutePath() { + if (isAbsolute()) { + return this; + } + // The path is relative so need to resolve against default directory, + // taking care not to reveal the user.dir + SecurityManager sm = System.getSecurityManager(); + if (sm != null) { + sm.checkPropertyAccess("user.dir"); + } + return new UnixPath(getFileSystem(), + resolve(getFileSystem().defaultDirectory(), path)); + } + + @Override + public UnixPath toRealPath(boolean resolveLinks) throws IOException { + checkRead(); + + UnixPath absolute = toAbsolutePath(); + + // if resolveLinks is true then use realpath + if (resolveLinks) { + try { + byte[] rp = realpath(absolute); + return new UnixPath(getFileSystem(), rp); + } catch (UnixException x) { + x.rethrowAsIOException(this); + } + } + + // if resolveLinks is false then eliminate "." and also ".." + // where the previous element is not a link. + UnixPath root = getFileSystem().rootDirectory(); + UnixPath result = root; + for (int i=0; i<absolute.getNameCount(); i++) { + UnixPath element = absolute.getName(i); + + // eliminate "." + if ((element.asByteArray().length == 1) && (element.asByteArray()[0] == '.')) + continue; + + // cannot eliminate ".." if previous element is a link + if ((element.asByteArray().length == 2) && (element.asByteArray()[0] == '.') && + (element.asByteArray()[1] == '.')) + { + UnixFileAttributes attrs = null; + try { + attrs = UnixFileAttributes.get(result, false); + } catch (UnixException x) { + x.rethrowAsIOException(result); + } + if (!attrs.isSymbolicLink()) { + result = result.getParent(); + if (result == null) { + result = root; + } + continue; + } + } + result = result.resolve(element); + } + + // finally check that file exists + try { + UnixFileAttributes.get(result, true); + } catch (UnixException x) { + x.rethrowAsIOException(result); + } + return result; + } + + @Override + public boolean isHidden() { + checkRead(); + UnixPath name = getName(); + if (name == null) + return false; + return (name.asByteArray()[0] == '.'); + } + + @Override + public URI toUri() { + return UnixUriUtils.toUri(this); + } + + @Override + public WatchKey register(WatchService watcher, + WatchEvent.Kind<?>[] events, + WatchEvent.Modifier... modifiers) + throws IOException + { + if (watcher == null) + throw new NullPointerException(); + if (!(watcher instanceof AbstractWatchService)) + throw new ProviderMismatchException(); + checkRead(); + return ((AbstractWatchService)watcher).register(this, events, modifiers); + } +} diff --git a/src/solaris/classes/sun/nio/fs/UnixSecureDirectoryStream.java b/src/solaris/classes/sun/nio/fs/UnixSecureDirectoryStream.java new file mode 100644 index 0000000000000000000000000000000000000000..e5894878709e0d749920105a373f0bdb4dea9890 --- /dev/null +++ b/src/solaris/classes/sun/nio/fs/UnixSecureDirectoryStream.java @@ -0,0 +1,643 @@ +/* + * Copyright 2008-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 sun.nio.fs; + +import java.nio.file.*; +import java.nio.file.attribute.*; +import java.nio.channels.SeekableByteChannel; +import java.util.*; +import java.util.concurrent.TimeUnit; +import java.io.IOException; + +import static sun.nio.fs.UnixNativeDispatcher.*; +import static sun.nio.fs.UnixConstants.*; + +/** + * Unix implementation of SecureDirectoryStream. + */ + +class UnixSecureDirectoryStream + extends SecureDirectoryStream +{ + private final UnixDirectoryStream ds; + private final int dfd; + + UnixSecureDirectoryStream(UnixPath dir, + long dp, + int dfd, + DirectoryStream.Filter<? super Path> filter) + { + this.ds = new UnixDirectoryStream(dir, dp, filter); + this.dfd = dfd; + } + + @Override + public void close() + throws IOException + { + ds.writeLock().lock(); + try { + if (ds.closeImpl()) { + UnixNativeDispatcher.close(dfd); + } + } finally { + ds.writeLock().unlock(); + } + } + + @Override + public Iterator<Path> iterator() { + return ds.iterator(this); + } + + private UnixPath getName(Path obj) { + if (obj == null) + throw new NullPointerException(); + if (!(obj instanceof UnixPath)) + throw new ProviderMismatchException(); + return (UnixPath)obj; + } + + /** + * Opens sub-directory in this directory + */ + @Override + public SecureDirectoryStream newDirectoryStream(Path obj, + boolean followLinks, + DirectoryStream.Filter<? super Path> filter) + throws IOException + { + UnixPath file = getName(obj); + UnixPath child = ds.directory().resolve(file); + + // permission check using name resolved against original path of directory + SecurityManager sm = System.getSecurityManager(); + if (sm != null) { + child.checkRead(); + } + + ds.readLock().lock(); + try { + if (!ds.isOpen()) + throw new ClosedDirectoryStreamException(); + + // open directory and create new secure directory stream + int newdfd1 = -1; + int newdfd2 = -1; + long ptr = 0L; + try { + int flags = O_RDONLY; + if (!followLinks) + flags |= O_NOFOLLOW; + newdfd1 = openat(dfd, file.asByteArray(), flags , 0); + newdfd2 = dup(newdfd1); + ptr = fdopendir(newdfd1); + } catch (UnixException x) { + if (newdfd1 != -1) + UnixNativeDispatcher.close(newdfd1); + if (newdfd2 != -1) + UnixNativeDispatcher.close(newdfd2); + if (x.errno() == UnixConstants.ENOTDIR) + throw new NotDirectoryException(file.toString()); + x.rethrowAsIOException(file); + } + return new UnixSecureDirectoryStream(child, ptr, newdfd2, filter); + } finally { + ds.readLock().unlock(); + } + } + + /** + * Opens file in this directory + */ + @Override + public SeekableByteChannel newByteChannel(Path obj, + Set<? extends OpenOption> options, + FileAttribute<?>... attrs) + throws IOException + { + UnixPath file = getName(obj); + + int mode = UnixFileModeAttribute + .toUnixMode(UnixFileModeAttribute.ALL_READWRITE, attrs); + + // path for permission check + String pathToCheck = ds.directory().resolve(file).getPathForPermissionCheck(); + + ds.readLock().lock(); + try { + if (!ds.isOpen()) + throw new ClosedDirectoryStreamException(); + try { + return UnixChannelFactory.newFileChannel(dfd, file, pathToCheck, options, mode); + } catch (UnixException x) { + x.rethrowAsIOException(file); + return null; // keep compiler happy + } + } finally { + ds.readLock().unlock(); + } + } + + /** + * Deletes file/directory in this directory. Works in a race-free manner + * when invoked with flags. + */ + void implDelete(Path obj, boolean haveFlags, int flags) + throws IOException + { + UnixPath file = getName(obj); + + // permission check using name resolved against original path of directory + SecurityManager sm = System.getSecurityManager(); + if (sm != null) { + ds.directory().resolve(file).checkDelete(); + } + + ds.readLock().lock(); + try { + if (!ds.isOpen()) + throw new ClosedDirectoryStreamException(); + + if (!haveFlags) { + // need file attribute to know if file is directory. This creates + // a race in that the file may be replaced by a directory or a + // directory replaced by a file between the time we query the + // file type and unlink it. + UnixFileAttributes attrs = null; + try { + attrs = UnixFileAttributes.get(dfd, file, false); + } catch (UnixException x) { + x.rethrowAsIOException(file); + } + flags = (attrs.isDirectory()) ? AT_REMOVEDIR : 0; + } + + try { + unlinkat(dfd, file.asByteArray(), flags); + } catch (UnixException x) { + if ((flags & AT_REMOVEDIR) != 0) { + if (x.errno() == EEXIST || x.errno() == ENOTEMPTY) { + throw new DirectoryNotEmptyException(null); + } + } + x.rethrowAsIOException(file); + } + } finally { + ds.readLock().unlock(); + } + } + + @Override + public void deleteFile(Path file) throws IOException { + implDelete(file, true, 0); + } + + @Override + public void deleteDirectory(Path dir) throws IOException { + implDelete(dir, true, AT_REMOVEDIR); + } + + /** + * Rename/move file in this directory to another (open) directory + */ + @Override + public void move(Path fromObj, SecureDirectoryStream dir, Path toObj) + throws IOException + { + UnixPath from = getName(fromObj); + UnixPath to = getName(toObj); + if (dir == null) + throw new NullPointerException(); + if (!(dir instanceof UnixSecureDirectoryStream)) + throw new ProviderMismatchException(); + UnixSecureDirectoryStream that = (UnixSecureDirectoryStream)dir; + + // permission check + SecurityManager sm = System.getSecurityManager(); + if (sm != null) { + this.ds.directory().resolve(from).checkWrite(); + that.ds.directory().resolve(to).checkWrite(); + } + + // lock ordering doesn't matter + this.ds.readLock().lock(); + try { + that.ds.readLock().lock(); + try { + if (!this.ds.isOpen() || !that.ds.isOpen()) + throw new ClosedDirectoryStreamException(); + try { + renameat(this.dfd, from.asByteArray(), that.dfd, to.asByteArray()); + } catch (UnixException x) { + if (x.errno() == EXDEV) { + throw new AtomicMoveNotSupportedException( + from.toString(), to.toString(), x.errorString()); + } + x.rethrowAsIOException(from, to); + } + } finally { + that.ds.readLock().unlock(); + } + } finally { + this.ds.readLock().unlock(); + } + } + + @SuppressWarnings("unchecked") + private <V extends FileAttributeView> V getFileAttributeViewImpl(UnixPath file, + Class<V> type, + boolean followLinks) + { + if (type == null) + throw new NullPointerException(); + Class<?> c = type; + if (c == BasicFileAttributeView.class) { + return (V) new BasicFileAttributeViewImpl(file, followLinks); + } + if (c == PosixFileAttributeView.class || c == FileOwnerAttributeView.class) { + return (V) new PosixFileAttributeViewImpl(file, followLinks); + } + // TBD - should also support AclFileAttributeView + return (V) null; + } + + /** + * Returns file attribute view bound to this directory + */ + @Override + public <V extends FileAttributeView> V getFileAttributeView(Class<V> type) { + return getFileAttributeViewImpl(null, type, false); + } + + /** + * Returns file attribute view bound to dfd/filename. + */ + @Override + public <V extends FileAttributeView> V getFileAttributeView(Path obj, + Class<V> type, + LinkOption... options) + { + UnixPath file = getName(obj); + boolean followLinks = file.getFileSystem().followLinks(options); + return getFileAttributeViewImpl(file, type, followLinks); + } + + /** + * A BasicFileAttributeView implementation that using a dfd/name pair. + */ + private class BasicFileAttributeViewImpl + extends AbstractBasicFileAttributeView + { + final UnixPath file; + final boolean followLinks; + + // set to true when binding to another object + volatile boolean forwarding; + + BasicFileAttributeViewImpl(UnixPath file, boolean followLinks) + { + this.file = file; + this.followLinks = followLinks; + } + + int open() throws IOException { + int oflags = O_RDONLY; + if (!followLinks) + oflags |= O_NOFOLLOW; + try { + return openat(dfd, file.asByteArray(), oflags, 0); + } catch (UnixException x) { + x.rethrowAsIOException(file); + return -1; // keep compiler happy + } + } + + private void checkWriteAccess() { + SecurityManager sm = System.getSecurityManager(); + if (sm != null) { + ds.directory().resolve(file).checkWrite(); + } + } + + @Override + public String name() { + return "basic"; + } + + @Override + public BasicFileAttributes readAttributes() throws IOException { + ds.readLock().lock(); + try { + if (!ds.isOpen()) + throw new ClosedDirectoryStreamException(); + + SecurityManager sm = System.getSecurityManager(); + if (sm != null) { + if (file == null) { + ds.directory().checkRead(); + } else { + ds.directory().resolve(file).checkRead(); + } + } + try { + UnixFileAttributes attrs = (file == null) ? + UnixFileAttributes.get(dfd) : + UnixFileAttributes.get(dfd, file, followLinks); + + // SECURITY: must return as BasicFileAttribute + return attrs.asBasicFileAttributes(); + } catch (UnixException x) { + x.rethrowAsIOException(file); + return null; // keep compiler happy + } + } finally { + ds.readLock().unlock(); + } + } + + @Override + public void setTimes(Long lastModifiedTime, + Long lastAccessTime, + Long createTime, // ignore + TimeUnit unit) + throws IOException + { + // no effect + if (lastModifiedTime == null && lastAccessTime == null) { + return; + } + + checkWriteAccess(); + + ds.readLock().lock(); + try { + if (!ds.isOpen()) + throw new ClosedDirectoryStreamException(); + + int fd = (file == null) ? dfd : open(); + try { + UnixFileAttributes attrs = null; + + // if not changing both attributes then need existing attributes + if (lastModifiedTime == null || lastAccessTime == null) { + try { + attrs = UnixFileAttributes.get(fd); + } catch (UnixException x) { + x.rethrowAsIOException(file); + } + } + + // modified time = existing, now, or new value + long modTime; + if (lastModifiedTime == null) { + modTime = attrs.lastModifiedTime(); + } else { + if (lastModifiedTime >= 0L) { + modTime = TimeUnit.MILLISECONDS.convert(lastModifiedTime, unit); + } else { + if (lastModifiedTime != -1L) + throw new IllegalArgumentException(); + modTime = System.currentTimeMillis(); + } + } + + // access time = existing, now, or new value + long accTime; + if (lastAccessTime == null) { + accTime = attrs.lastAccessTime(); + } else { + if (lastAccessTime >= 0L) { + accTime = TimeUnit.MILLISECONDS.convert(lastAccessTime, unit); + } else { + if (lastAccessTime != -1L) + throw new IllegalArgumentException(); + accTime = System.currentTimeMillis(); + } + } + + try { + futimes(fd, accTime, modTime); + } catch (UnixException x) { + x.rethrowAsIOException(file); + } + } finally { + if (file != null) + UnixNativeDispatcher.close(fd); + } + } finally { + ds.readLock().unlock(); + } + } + } + + /** + * A PosixFileAttributeView implementation that using a dfd/name pair. + */ + private class PosixFileAttributeViewImpl + extends BasicFileAttributeViewImpl implements PosixFileAttributeView + { + private static final String PERMISSIONS_NAME = "permissions"; + private static final String OWNER_NAME = "owner"; + private static final String GROUP_NAME = "group"; + + PosixFileAttributeViewImpl(UnixPath file, boolean followLinks) { + super(file, followLinks); + } + + private void checkWriteAndUserAccess() { + SecurityManager sm = System.getSecurityManager(); + if (sm != null) { + super.checkWriteAccess(); + sm.checkPermission(new RuntimePermission("accessUserInformation")); + } + } + + @Override + public String name() { + return "posix"; + } + + @Override + public Object getAttribute(String attribute) throws IOException { + if (attribute.equals(PERMISSIONS_NAME)) + return readAttributes().permissions(); + if (attribute.equals(OWNER_NAME)) + return readAttributes().owner(); + if (attribute.equals(GROUP_NAME)) + return readAttributes().group(); + return super.getAttribute(attribute); + } + + @Override + @SuppressWarnings("unchecked") + public void setAttribute(String attribute, Object value) + throws IOException + { + if (attribute.equals(PERMISSIONS_NAME)) { + setPermissions((Set<PosixFilePermission>)value); + return; + } + if (attribute.equals(OWNER_NAME)) { + setOwner((UserPrincipal)value); + return; + } + if (attribute.equals(GROUP_NAME)) { + setGroup((GroupPrincipal)value); + return; + } + super.setAttribute(attribute, value); + } + + final void addPosixAttributesToBuilder(PosixFileAttributes attrs, + AttributesBuilder builder) + { + if (builder.match(PERMISSIONS_NAME)) + builder.add(PERMISSIONS_NAME, attrs.permissions()); + if (builder.match(OWNER_NAME)) + builder.add(OWNER_NAME, attrs.owner()); + if (builder.match(GROUP_NAME)) + builder.add(GROUP_NAME, attrs.group()); + } + + @Override + public Map<String,?> readAttributes(String first, String[] rest) + throws IOException + { + AttributesBuilder builder = AttributesBuilder.create(first, rest); + PosixFileAttributes attrs = readAttributes(); + addBasicAttributesToBuilder(attrs, builder); + addPosixAttributesToBuilder(attrs, builder); + return builder.unmodifiableMap(); + } + + @Override + public PosixFileAttributes readAttributes() throws IOException { + SecurityManager sm = System.getSecurityManager(); + if (sm != null) { + if (file == null) + ds.directory().checkRead(); + else + ds.directory().resolve(file).checkRead(); + sm.checkPermission(new RuntimePermission("accessUserInformation")); + } + + ds.readLock().lock(); + try { + if (!ds.isOpen()) + throw new ClosedDirectoryStreamException(); + + try { + UnixFileAttributes attrs = (file == null) ? + UnixFileAttributes.get(dfd) : + UnixFileAttributes.get(dfd, file, followLinks); + return attrs; + } catch (UnixException x) { + x.rethrowAsIOException(file); + return null; // keep compiler happy + } + } finally { + ds.readLock().unlock(); + } + } + + @Override + public void setPermissions(Set<PosixFilePermission> perms) + throws IOException + { + // permission check + checkWriteAndUserAccess(); + + ds.readLock().lock(); + try { + if (!ds.isOpen()) + throw new ClosedDirectoryStreamException(); + + int fd = (file == null) ? dfd : open(); + try { + fchmod(fd, UnixFileModeAttribute.toUnixMode(perms)); + } catch (UnixException x) { + x.rethrowAsIOException(file); + } finally { + if (file != null && fd >= 0) + UnixNativeDispatcher.close(fd); + } + } finally { + ds.readLock().unlock(); + } + } + + private void setOwners(int uid, int gid) throws IOException { + // permission check + checkWriteAndUserAccess(); + + ds.readLock().lock(); + try { + if (!ds.isOpen()) + throw new ClosedDirectoryStreamException(); + + int fd = (file == null) ? dfd : open(); + try { + fchown(fd, uid, gid); + } catch (UnixException x) { + x.rethrowAsIOException(file); + } finally { + if (file != null && fd >= 0) + UnixNativeDispatcher.close(fd); + } + } finally { + ds.readLock().unlock(); + } + } + + @Override + public UserPrincipal getOwner() throws IOException { + return readAttributes().owner(); + } + + @Override + public void setOwner(UserPrincipal owner) + throws IOException + { + if (!(owner instanceof UnixUserPrincipals.User)) + throw new ProviderMismatchException(); + if (owner instanceof UnixUserPrincipals.Group) + throw new IOException("'owner' parameter can't be a group"); + int uid = ((UnixUserPrincipals.User)owner).uid(); + setOwners(uid, -1); + } + + @Override + public void setGroup(GroupPrincipal group) + throws IOException + { + if (!(group instanceof UnixUserPrincipals.Group)) + throw new ProviderMismatchException(); + int gid = ((UnixUserPrincipals.Group)group).gid(); + setOwners(-1, gid); + } + } +} diff --git a/src/solaris/classes/sun/nio/fs/UnixUriUtils.java b/src/solaris/classes/sun/nio/fs/UnixUriUtils.java new file mode 100644 index 0000000000000000000000000000000000000000..bf3c78d63528a5182bd5fd6108131671f296b7c5 --- /dev/null +++ b/src/solaris/classes/sun/nio/fs/UnixUriUtils.java @@ -0,0 +1,216 @@ +/* + * Copyright 2008-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 sun.nio.fs; + +import java.net.URI; +import java.net.URISyntaxException; + +/** + * Unix specific Path <--> URI conversion + */ + +class UnixUriUtils { + private UnixUriUtils() { } + + /** + * Converts URI to Path + */ + static UnixPath fromUri(UnixFileSystem fs, URI uri) { + if (!uri.isAbsolute()) + throw new IllegalArgumentException("URI is not absolute"); + if (uri.isOpaque()) + throw new IllegalArgumentException("URI is not hierarchical"); + String scheme = uri.getScheme(); + if ((scheme == null) || !scheme.equalsIgnoreCase("file")) + throw new IllegalArgumentException("URI scheme is not \"file\""); + if (uri.getAuthority() != null) + throw new IllegalArgumentException("URI has an authority component"); + if (uri.getFragment() != null) + throw new IllegalArgumentException("URI has a fragment component"); + if (uri.getQuery() != null) + throw new IllegalArgumentException("URI has a query component"); + + String path = uri.getPath(); + if (path.equals("")) + throw new IllegalArgumentException("URI path component is empty"); + if (path.endsWith("/") && (path.length() > 1)) { + // "/foo/" --> "/foo", but "/" --> "/" + path = path.substring(0, path.length() - 1); + } + + // preserve bytes + byte[] result = new byte[path.length()]; + for (int i=0; i<path.length(); i++) { + byte v = (byte)(path.charAt(i)); + if (v == 0) + throw new IllegalArgumentException("Nul character not allowed"); + result[i] = v; + } + return new UnixPath(fs, result); + } + + /** + * Converts Path to URI + */ + static URI toUri(UnixPath up) { + byte[] path = up.toAbsolutePath().asByteArray(); + StringBuilder sb = new StringBuilder("file:///"); + assert path[0] == '/'; + for (int i=1; i<path.length; i++) { + char c = (char)(path[i] & 0xff); + if (match(c, L_PATH, H_PATH)) { + sb.append(c); + } else { + sb.append('%'); + sb.append(hexDigits[(c >> 4) & 0x0f]); + sb.append(hexDigits[(c >> 0) & 0x0f]); + } + } + + // trailing slash if directory + if (sb.charAt(sb.length()-1) != '/') { + try { + if (UnixFileAttributes.get(up, true).isDirectory()) + sb.append('/'); + } catch (UnixException x) { + // ignore + } + } + + try { + return new URI(sb.toString()); + } catch (URISyntaxException x) { + throw new AssertionError(x); // should not happen + } + } + + // The following is copied from java.net.URI + + // Compute the low-order mask for the characters in the given string + private static long lowMask(String chars) { + int n = chars.length(); + long m = 0; + for (int i = 0; i < n; i++) { + char c = chars.charAt(i); + if (c < 64) + m |= (1L << c); + } + return m; + } + + // Compute the high-order mask for the characters in the given string + private static long highMask(String chars) { + int n = chars.length(); + long m = 0; + for (int i = 0; i < n; i++) { + char c = chars.charAt(i); + if ((c >= 64) && (c < 128)) + m |= (1L << (c - 64)); + } + return m; + } + + // Compute a low-order mask for the characters + // between first and last, inclusive + private static long lowMask(char first, char last) { + long m = 0; + int f = Math.max(Math.min(first, 63), 0); + int l = Math.max(Math.min(last, 63), 0); + for (int i = f; i <= l; i++) + m |= 1L << i; + return m; + } + + // Compute a high-order mask for the characters + // between first and last, inclusive + private static long highMask(char first, char last) { + long m = 0; + int f = Math.max(Math.min(first, 127), 64) - 64; + int l = Math.max(Math.min(last, 127), 64) - 64; + for (int i = f; i <= l; i++) + m |= 1L << i; + return m; + } + + // Tell whether the given character is permitted by the given mask pair + private static boolean match(char c, long lowMask, long highMask) { + if (c < 64) + return ((1L << c) & lowMask) != 0; + if (c < 128) + return ((1L << (c - 64)) & highMask) != 0; + return false; + } + + // digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | + // "8" | "9" + private static final long L_DIGIT = lowMask('0', '9'); + private static final long H_DIGIT = 0L; + + // upalpha = "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" | "I" | + // "J" | "K" | "L" | "M" | "N" | "O" | "P" | "Q" | "R" | + // "S" | "T" | "U" | "V" | "W" | "X" | "Y" | "Z" + private static final long L_UPALPHA = 0L; + private static final long H_UPALPHA = highMask('A', 'Z'); + + // lowalpha = "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | + // "j" | "k" | "l" | "m" | "n" | "o" | "p" | "q" | "r" | + // "s" | "t" | "u" | "v" | "w" | "x" | "y" | "z" + private static final long L_LOWALPHA = 0L; + private static final long H_LOWALPHA = highMask('a', 'z'); + + // alpha = lowalpha | upalpha + private static final long L_ALPHA = L_LOWALPHA | L_UPALPHA; + private static final long H_ALPHA = H_LOWALPHA | H_UPALPHA; + + // alphanum = alpha | digit + private static final long L_ALPHANUM = L_DIGIT | L_ALPHA; + private static final long H_ALPHANUM = H_DIGIT | H_ALPHA; + + // mark = "-" | "_" | "." | "!" | "~" | "*" | "'" | + // "(" | ")" + private static final long L_MARK = lowMask("-_.!~*'()"); + private static final long H_MARK = highMask("-_.!~*'()"); + + // unreserved = alphanum | mark + private static final long L_UNRESERVED = L_ALPHANUM | L_MARK; + private static final long H_UNRESERVED = H_ALPHANUM | H_MARK; + + // pchar = unreserved | escaped | + // ":" | "@" | "&" | "=" | "+" | "$" | "," + private static final long L_PCHAR + = L_UNRESERVED | lowMask(":@&=+$,"); + private static final long H_PCHAR + = H_UNRESERVED | highMask(":@&=+$,"); + + // All valid path characters + private static final long L_PATH = L_PCHAR | lowMask(";/"); + private static final long H_PATH = H_PCHAR | highMask(";/"); + + private final static char[] hexDigits = { + '0', '1', '2', '3', '4', '5', '6', '7', + '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' + }; +} diff --git a/src/solaris/classes/sun/nio/fs/UnixUserPrincipals.java b/src/solaris/classes/sun/nio/fs/UnixUserPrincipals.java new file mode 100644 index 0000000000000000000000000000000000000000..88dfe9c4d90c230f637f06166f97b4cc9e7915d3 --- /dev/null +++ b/src/solaris/classes/sun/nio/fs/UnixUserPrincipals.java @@ -0,0 +1,175 @@ +/* + * Copyright 2008-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 sun.nio.fs; + +import java.nio.file.attribute.*; +import java.io.IOException; +import static sun.nio.fs.UnixNativeDispatcher.*; + +/** + * Unix implementation of java.nio.file.attribute.UserPrincipal + */ + +class UnixUserPrincipals { + private static User createSpecial(String name) { return new User(-1, name); } + + static final User SPECIAL_OWNER = createSpecial("OWNER@"); + static final User SPECIAL_GROUP = createSpecial("GROUP@"); + static final User SPECIAL_EVERYONE = createSpecial("EVERYONE@"); + + static class User implements UserPrincipal { + private final int id; // uid or gid + private final boolean isGroup; + private final String name; + + private User(int id, boolean isGroup, String name) { + this.id = id; + this.isGroup = isGroup; + this.name = name; + } + + User(int id, String name) { + this(id, false, name); + } + + int uid() { + if (isGroup) + throw new AssertionError(); + return id; + } + + int gid() { + if (isGroup) + return id; + throw new AssertionError(); + } + + boolean isSpecial() { + return id == -1; + } + + @Override + public String getName() { + return name; + } + + @Override + public String toString() { + return name; + } + + @Override + public boolean equals(Object obj) { + if (obj == this) + return true; + if (!(obj instanceof User)) + return false; + User other = (User)obj; + if ((this.id != other.id) || + (this.isGroup != other.isGroup)) { + return false; + } + // specials + if (this.id == -1 && other.id == -1) + return this.name.equals(other.name); + + return true; + } + + @Override + public int hashCode() { + return (id != -1) ? id : name.hashCode(); + } + } + + static class Group extends User implements GroupPrincipal { + Group(int id, String name) { + super(id, true, name); + } + } + + // return UserPrincipal representing given uid + static User fromUid(int uid) { + String name = null; + try { + name = new String(getpwuid(uid)); + } catch (UnixException x) { + name = Integer.toString(uid); + } + return new User(uid, name); + } + + // return GroupPrincipal representing given gid + static Group fromGid(int gid) { + String name = null; + try { + name = new String(getgrgid(gid)); + } catch (UnixException x) { + name = Integer.toString(gid); + } + return new Group(gid, name); + } + + // lookup user or group name + private static int lookupName(String name, boolean isGroup) + throws IOException + { + SecurityManager sm = System.getSecurityManager(); + if (sm != null) { + sm.checkPermission(new RuntimePermission("lookupUserInformation")); + } + int id = -1; + try { + id = (isGroup) ? getgrnam(name) : getpwnam(name); + } catch (UnixException x) { + throw new IOException(name + ": " + x.errorString()); + } + if (id == -1) + throw new UserPrincipalNotFoundException(name); + return id; + + } + + // lookup user name + static UserPrincipal lookupUser(String name) throws IOException { + if (name.equals(SPECIAL_OWNER.getName())) + return SPECIAL_OWNER; + if (name.equals(SPECIAL_GROUP.getName())) + return SPECIAL_GROUP; + if (name.equals(SPECIAL_EVERYONE.getName())) + return SPECIAL_EVERYONE; + int uid = lookupName(name, false); + return new User(uid, name); + } + + // lookup group name + static GroupPrincipal lookupGroup(String group) + throws IOException + { + int gid = lookupName(group, true); + return new Group(gid, group); + } +} diff --git a/src/solaris/classes/sun/print/IPPPrintService.java b/src/solaris/classes/sun/print/IPPPrintService.java index 07b68b18fa8b4bb8ed02fc24035a49589cae4c31..ec5344ae379cfba369a3590f82afe22ab14266e4 100644 --- a/src/solaris/classes/sun/print/IPPPrintService.java +++ b/src/solaris/classes/sun/print/IPPPrintService.java @@ -661,6 +661,12 @@ public class IPPPrintService implements PrintService, SunPrinterJobService { } } } else if (category == OrientationRequested.class) { + if (flavor.equals(DocFlavor.INPUT_STREAM.POSTSCRIPT) || + flavor.equals(DocFlavor.URL.POSTSCRIPT) || + flavor.equals(DocFlavor.BYTE_ARRAY.POSTSCRIPT)) { + return null; + } + boolean revPort = false; OrientationRequested[] orientSup = null; diff --git a/src/solaris/classes/sun/print/UnixPrintJob.java b/src/solaris/classes/sun/print/UnixPrintJob.java index 1a96e92f2c85717534ef3b771434b01892061928..b4da652a8fc03ce8c48edd6a9fac53a91cf7d880 100644 --- a/src/solaris/classes/sun/print/UnixPrintJob.java +++ b/src/solaris/classes/sun/print/UnixPrintJob.java @@ -362,10 +362,10 @@ public class UnixPrintJob implements CancelablePrintJob { mOptions += " number-up="+nUp.getValue(); } - if (orient == OrientationRequested.LANDSCAPE && + if (orient != OrientationRequested.PORTRAIT && (flavor != null) && !flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE)) { - mOptions += " landscape"; + mOptions += " orientation-requested="+orient.getValue(); } if (sides != null) { diff --git a/src/solaris/lib/sdp/sdp.conf.template b/src/solaris/lib/sdp/sdp.conf.template new file mode 100644 index 0000000000000000000000000000000000000000..71cb5c2ce84d0447d2714121efac0b71b7544831 --- /dev/null +++ b/src/solaris/lib/sdp/sdp.conf.template @@ -0,0 +1,30 @@ +# +# Configuration file to enable InfiniBand Sockets Direct Protocol. +# +# Each line that does not start with a comment (#) is a rule to indicate when +# the SDP transport protocol should be used. The format of a rule is as follows: +# ("bind"|"connect") 1*LWSP-char (hostname|ipaddress["/"prefix]) 1*LWSP-char ("*"|port)["-"("*"|port)] +# +# A "bind" rule indicates that the SDP protocol transport should be used when +# a TCP socket binds to an address/port that matches the rule. A "connect" rule +# indicates that the SDP protocol transport should be used when an unbound +# TCP socket attempts to connect to an address/port that matches the rule. +# Addresses may be specified as hostnames or literal Internet Protocol (IP) +# addresses. When a literal IP address is used then a prefix length may be used +# to indicate the number of bits for matching (useful when a block of addresses +# or subnet is allocated to the InfiniBand fabric). + +# Use SDP for all sockets that bind to specific local addresses +#bind 192.168.1.1 * +#bind fe80::21b:24ff:fe3d:7896 * + +# Use SDP for all sockets that bind to the wildcard address in a port range +#bind 0.0.0.0 5000-5999 +#bind ::0 5000-5999 + +# Use SDP when connecting to all application services on 192.168.1.* +#connect 192.168.1.0/24 1024-* + +# Use SDP when connecting to the http server or MySQL database on hpccluster. +#connect hpccluster.foo.com 80 +#connect hpccluster.foo.com 3306 diff --git a/src/solaris/native/java/net/Inet4AddressImpl.c b/src/solaris/native/java/net/Inet4AddressImpl.c index a41aa96e10fb1b5b6ed6b16a1ba3e3cb0dc31516..9e3cca486db5f9026ede3418ebcac656d1ab8491 100644 --- a/src/solaris/native/java/net/Inet4AddressImpl.c +++ b/src/solaris/native/java/net/Inet4AddressImpl.c @@ -165,16 +165,18 @@ Java_java_net_Inet4AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this, hostname = JNU_GetStringPlatformChars(env, host, JNI_FALSE); CHECK_NULL_RETURN(hostname, NULL); +#ifdef __solaris__ /* * Workaround for Solaris bug 4160367 - if a hostname contains a * white space then 0.0.0.0 is returned */ - if (isspace(hostname[0])) { + if (isspace((unsigned char)hostname[0])) { JNU_ThrowByName(env, JNU_JAVANETPKG "UnknownHostException", (char *)hostname); JNU_ReleaseStringPlatformChars(env, host, hostname); return NULL; } +#endif /* Try once, with our static buffer. */ #ifdef __GLIBC__ @@ -325,7 +327,8 @@ static jboolean ping4(JNIEnv *env, jint fd, struct sockaddr_in* him, jint timeout, struct sockaddr_in* netif, jint ttl) { jint size; - jint n, len, hlen1, icmplen; + jint n, hlen1, icmplen; + socklen_t len; char sendbuf[1500]; char recvbuf[1500]; struct icmp *icmp; diff --git a/src/solaris/native/java/net/Inet6AddressImpl.c b/src/solaris/native/java/net/Inet6AddressImpl.c index 181307fcba833c107a39a386d36b1ae2cbdf6ef0..5ecedbc6c4f9611b88d14aeb4b4217773f3e8864 100644 --- a/src/solaris/native/java/net/Inet6AddressImpl.c +++ b/src/solaris/native/java/net/Inet6AddressImpl.c @@ -196,16 +196,18 @@ Java_java_net_Inet6AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this, hints.ai_flags = AI_CANONNAME; hints.ai_family = AF_UNSPEC; +#ifdef __solaris__ /* * Workaround for Solaris bug 4160367 - if a hostname contains a * white space then 0.0.0.0 is returned */ - if (isspace(hostname[0])) { + if (isspace((unsigned char)hostname[0])) { JNU_ThrowByName(env, JNU_JAVANETPKG "UnknownHostException", (char *)hostname); JNU_ReleaseStringPlatformChars(env, host, hostname); return NULL; } +#endif error = (*getaddrinfo_ptr)(hostname, NULL, &hints, &res); @@ -455,7 +457,8 @@ static jboolean ping6(JNIEnv *env, jint fd, struct sockaddr_in6* him, jint timeout, struct sockaddr_in6* netif, jint ttl) { jint size; - jint n, len; + jint n; + socklen_t len; char sendbuf[1500]; unsigned char recvbuf[1500]; struct icmp6_hdr *icmp6; diff --git a/src/solaris/native/java/net/NetworkInterface.c b/src/solaris/native/java/net/NetworkInterface.c index 14273f5c132d26893778a0d8e3fb6931fbf2e578..9580c81645528b61c2cb01b905e1fd28c00a2b4f 100644 --- a/src/solaris/native/java/net/NetworkInterface.c +++ b/src/solaris/native/java/net/NetworkInterface.c @@ -1,5 +1,5 @@ /* - * Copyright 2000-2008 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. * * This code is free software; you can redistribute it and/or modify it @@ -969,13 +969,39 @@ netif *addif(JNIEnv *env, netif *ifs, char *if_name, int index, int family, // Got access to parent, so create it if necessary. strcpy(vname, name); *unit = '\0'; - } - else { + } else { +#if defined(__solaris__) && defined(AF_INET6) + struct lifreq lifr; + memset((char *) &lifr, 0, sizeof(lifr)); + strcpy(lifr.lifr_name, vname); + + /* Try with an IPv6 socket in case the interface has only IPv6 + * addresses assigned to it */ + close(sock); + sock = JVM_Socket(AF_INET6, SOCK_DGRAM, 0); + + if (sock < 0) { + NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", + "Socket creation failed"); + return ifs; /* return untouched list */ + } + + if (ioctl(sock, SIOCGLIFFLAGS, (char *)&lifr) >= 0) { + // Got access to parent, so create it if necessary. + strcpy(vname, name); + *unit = '\0'; + } else { + // failed to access parent interface do not create parent. + // We are a virtual interface with no parent. + isVirtual = 1; + vname[0] = 0; + } +#else // failed to access parent interface do not create parent. // We are a virtual interface with no parent. isVirtual = 1; - vname[0] = 0; +#endif } } close(sock); diff --git a/src/solaris/native/sun/awt/gtk2_interface.c b/src/solaris/native/sun/awt/gtk2_interface.c index cfbc5ef6f6ea6344e32157935b1fad3e3b6a31b8..1afeeef173b292515b6ee55ab846078eb0842970 100644 --- a/src/solaris/native/sun/awt/gtk2_interface.c +++ b/src/solaris/native/sun/awt/gtk2_interface.c @@ -93,6 +93,7 @@ static int gtk2_pixbuf_height = 0; /* Static buffer for conversion from java.lang.String to UTF-8 */ static char convertionBuffer[CONV_BUFFER_SIZE]; +static gboolean new_combo = TRUE; const char ENV_PREFIX[] = "GTK_MODULES="; /*******************/ @@ -608,6 +609,7 @@ gboolean gtk2_load() dlsym(gtk2_libhandle, "gtk_combo_box_entry_new"); if (fp_gtk_combo_box_entry_new == NULL) { fp_gtk_combo_box_entry_new = dl_symbol("gtk_combo_new"); + new_combo = FALSE; } fp_gtk_separator_tool_item_new = @@ -1423,17 +1425,13 @@ static GtkWidget *gtk2_get_widget(WidgetType widget_type) */ GtkWidget *combo = (*fp_gtk_combo_box_entry_new)(); - if (widget_type == COMBO_BOX_TEXT_FIELD) - (*fp_gtk_container_add)((GtkContainer *)combo, result); - else - { + if (new_combo && widget_type == COMBO_BOX_ARROW_BUTTON) { (*fp_gtk_widget_set_parent)(result, combo); ((GtkBin*)combo)->child = result; + } else { + (*fp_gtk_container_add)((GtkContainer *)combo, result); } - (*fp_gtk_container_add)((GtkContainer *)gtk2_fixed, combo); - (*fp_gtk_widget_realize)(result); - return result; } else if (widget_type != TOOL_TIP && widget_type != INTERNAL_FRAME && diff --git a/src/solaris/native/sun/net/spi/SdpProvider.c b/src/solaris/native/sun/net/spi/SdpProvider.c new file mode 100644 index 0000000000000000000000000000000000000000..00d7f4ba6dc5591d1d4fe671ef50408d5bedc8d4 --- /dev/null +++ b/src/solaris/native/sun/net/spi/SdpProvider.c @@ -0,0 +1,74 @@ +/* + * 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. + */ + +#include <sys/types.h> +#include <sys/socket.h> + +#if defined(__solaris__) && !defined(PROTO_SDP) +#define PROTO_SDP 257 +#endif + +#include "jni.h" +#include "jni_util.h" +#include "net_util.h" + +#define RESTARTABLE(_cmd, _result) do { \ + do { \ + _result = _cmd; \ + } while((_result == -1) && (errno == EINTR)); \ +} while(0) + +JNIEXPORT void JNICALL +Java_sun_net_spi_SdpProvider_convert(JNIEnv *env, jclass cls, jint fd) +{ +#ifdef PROTO_SDP + int domain = ipv6_available() ? AF_INET6 : AF_INET; + int s = socket(domain, SOCK_STREAM, PROTO_SDP); + if (s < 0) { + JNU_ThrowIOExceptionWithLastError(env, "socket"); + } else { + int arg, len, res; + struct linger linger; + + /* copy socket options that are relevant to SDP */ + len = sizeof(arg); + if (getsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char*)&arg, &len) == 0) + setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char*)&arg, len); + len = sizeof(arg); + if (getsockopt(fd, SOL_SOCKET, SO_OOBINLINE, (char*)&arg, &len) == 0) + setsockopt(s, SOL_SOCKET, SO_OOBINLINE, (char*)&arg, len); + len = sizeof(linger); + if (getsockopt(fd, SOL_SOCKET, SO_LINGER, (void*)&linger, &len) == 0) + setsockopt(s, SOL_SOCKET, SO_LINGER, (char*)&linger, len); + + RESTARTABLE(dup2(s, fd), res); + if (res < 0) + JNU_ThrowIOExceptionWithLastError(env, "dup2"); + RESTARTABLE(close(s), res); + } +#else + JNU_ThrowInternalError(env, "should not reach here"); +#endif +} diff --git a/src/solaris/native/sun/nio/ch/DevPollArrayWrapper.c b/src/solaris/native/sun/nio/ch/DevPollArrayWrapper.c index 090c77e6774d300a080f69485f742b076f958629..fa36f612bfff6a50f540d2ba6f6ae164acffde4a 100644 --- a/src/solaris/native/sun/nio/ch/DevPollArrayWrapper.c +++ b/src/solaris/native/sun/nio/ch/DevPollArrayWrapper.c @@ -28,6 +28,7 @@ #include "jvm.h" #include "jlong.h" #include "sun_nio_ch_DevPollArrayWrapper.h" +#include "java_lang_Integer.h" #include <sys/poll.h> #include <sys/resource.h> #include <unistd.h> @@ -192,7 +193,11 @@ Java_sun_nio_ch_DevPollArrayWrapper_fdLimit(JNIEnv *env, jclass this) JNU_ThrowIOExceptionWithLastError(env, "getrlimit failed"); } - return (jint)rlp.rlim_max; + if (rlp.rlim_max < 0 || rlp.rlim_max > java_lang_Integer_MAX_VALUE) { + return java_lang_Integer_MAX_VALUE; + } else { + return (jint)rlp.rlim_max; + } } JNIEXPORT void JNICALL diff --git a/src/solaris/native/sun/nio/ch/EPoll.c b/src/solaris/native/sun/nio/ch/EPoll.c new file mode 100644 index 0000000000000000000000000000000000000000..fc9cab72cc2248c5590f84517d525e37796104d3 --- /dev/null +++ b/src/solaris/native/sun/nio/ch/EPoll.c @@ -0,0 +1,151 @@ +/* + * Copyright 2008-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. + */ + +#include "jni.h" +#include "jni_util.h" +#include "jvm.h" +#include "jlong.h" +#include "nio_util.h" + +#include "sun_nio_ch_EPoll.h" + +#include <dlfcn.h> +#include <unistd.h> +#include <sys/types.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/* epoll_wait(2) man page */ + +typedef union epoll_data { + void *ptr; + int fd; + __uint32_t u32; + __uint64_t u64; +} epoll_data_t; + +struct epoll_event { + __uint32_t events; /* Epoll events */ + epoll_data_t data; /* User data variable */ +} __attribute__ ((__packed__)); + +#ifdef __cplusplus +} +#endif + +/* + * epoll event notification is new in 2.6 kernel. As the offical build + * platform for the JDK is on a 2.4-based distribution then we must + * obtain the addresses of the epoll functions dynamically. + */ +typedef int (*epoll_create_t)(int size); +typedef int (*epoll_ctl_t) (int epfd, int op, int fd, struct epoll_event *event); +typedef int (*epoll_wait_t) (int epfd, struct epoll_event *events, int maxevents, int timeout); + +static epoll_create_t epoll_create_func; +static epoll_ctl_t epoll_ctl_func; +static epoll_wait_t epoll_wait_func; + + +JNIEXPORT void JNICALL +Java_sun_nio_ch_EPoll_init(JNIEnv *env, jclass this) +{ + epoll_create_func = (epoll_create_t) dlsym(RTLD_DEFAULT, "epoll_create"); + epoll_ctl_func = (epoll_ctl_t) dlsym(RTLD_DEFAULT, "epoll_ctl"); + epoll_wait_func = (epoll_wait_t) dlsym(RTLD_DEFAULT, "epoll_wait"); + + if ((epoll_create_func == NULL) || (epoll_ctl_func == NULL) || + (epoll_wait_func == NULL)) { + JNU_ThrowInternalError(env, "unable to get address of epoll functions, pre-2.6 kernel?"); + } +} + +JNIEXPORT jint JNICALL +Java_sun_nio_ch_EPoll_eventSize(JNIEnv* env, jclass this) +{ + return sizeof(struct epoll_event); +} + +JNIEXPORT jint JNICALL +Java_sun_nio_ch_EPoll_eventsOffset(JNIEnv* env, jclass this) +{ + return offsetof(struct epoll_event, events); +} + +JNIEXPORT jint JNICALL +Java_sun_nio_ch_EPoll_dataOffset(JNIEnv* env, jclass this) +{ + return offsetof(struct epoll_event, data); +} + +JNIEXPORT jint JNICALL +Java_sun_nio_ch_EPoll_epollCreate(JNIEnv *env, jclass c) { + /* + * epoll_create expects a size as a hint to the kernel about how to + * dimension internal structures. We can't predict the size in advance. + */ + int epfd = (*epoll_create_func)(256); + if (epfd < 0) { + JNU_ThrowIOExceptionWithLastError(env, "epoll_create failed"); + } + return epfd; +} + +JNIEXPORT jint JNICALL +Java_sun_nio_ch_EPoll_epollCtl(JNIEnv *env, jclass c, jint epfd, + jint opcode, jint fd, jint events) +{ + struct epoll_event event; + int res; + + event.events = events; + event.data.fd = fd; + + RESTARTABLE((*epoll_ctl_func)(epfd, (int)opcode, (int)fd, &event), res); + + return (res == 0) ? 0 : errno; +} + +JNIEXPORT jint JNICALL +Java_sun_nio_ch_EPoll_epollWait(JNIEnv *env, jclass c, + jint epfd, jlong address, jint numfds) +{ + struct epoll_event *events = jlong_to_ptr(address); + int res; + + RESTARTABLE((*epoll_wait_func)(epfd, events, numfds, -1), res); + if (res < 0) { + JNU_ThrowIOExceptionWithLastError(env, "epoll_wait failed"); + } + return res; +} + +JNIEXPORT void JNICALL +Java_sun_nio_ch_EPoll_close0(JNIEnv *env, jclass c, jint epfd) { + int res; + RESTARTABLE(close(epfd), res); +} diff --git a/src/solaris/native/sun/nio/ch/EPollPort.c b/src/solaris/native/sun/nio/ch/EPollPort.c new file mode 100644 index 0000000000000000000000000000000000000000..8d34dd8dd4b73c96720ee4269d1843b85b4a673f --- /dev/null +++ b/src/solaris/native/sun/nio/ch/EPollPort.c @@ -0,0 +1,76 @@ +/* + * Copyright 2008-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. + */ + +#include "jni.h" +#include "jni_util.h" +#include "jvm.h" +#include "jlong.h" +#include "nio_util.h" + +#include "sun_nio_ch_EPollPort.h" + +#include <unistd.h> +#include <sys/types.h> +#include <sys/socket.h> + +JNIEXPORT void JNICALL +Java_sun_nio_ch_EPollPort_socketpair(JNIEnv* env, jclass clazz, jintArray sv) { + int sp[2]; + if (socketpair(PF_UNIX, SOCK_STREAM, 0, sp) == -1) { + JNU_ThrowIOExceptionWithLastError(env, "socketpair failed"); + } else { + jint res[2]; + res[0] = (jint)sp[0]; + res[1] = (jint)sp[1]; + (*env)->SetIntArrayRegion(env, sv, 0, 2, &res[0]); + } +} + +JNIEXPORT void JNICALL +Java_sun_nio_ch_EPollPort_interrupt(JNIEnv *env, jclass c, jint fd) { + int res; + int buf[1]; + buf[0] = 1; + RESTARTABLE(write(fd, buf, 1), res); + if (res < 0) { + JNU_ThrowIOExceptionWithLastError(env, "write failed"); + } +} + +JNIEXPORT void JNICALL +Java_sun_nio_ch_EPollPort_drain1(JNIEnv *env, jclass cl, jint fd) { + int res; + char buf[1]; + RESTARTABLE(read(fd, buf, 1), res); + if (res < 0) { + JNU_ThrowIOExceptionWithLastError(env, "drain1 failed"); + } +} + +JNIEXPORT void JNICALL +Java_sun_nio_ch_EPollPort_close0(JNIEnv *env, jclass c, jint fd) { + int res; + RESTARTABLE(close(fd), res); +} diff --git a/src/solaris/native/sun/nio/ch/FileChannelImpl.c b/src/solaris/native/sun/nio/ch/FileChannelImpl.c index b42c899e521c7fd2073e50dd5d194c5bfd8fad14..c1c3cc9e82678ae1105705639161ed03b555e48a 100644 --- a/src/solaris/native/sun/nio/ch/FileChannelImpl.c +++ b/src/solaris/native/sun/nio/ch/FileChannelImpl.c @@ -1,5 +1,5 @@ /* - * Copyright 2000-2008 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. * * This code is free software; you can redistribute it and/or modify it @@ -31,7 +31,6 @@ #include <sys/stat.h> #include "sun_nio_ch_FileChannelImpl.h" #include "java_lang_Integer.h" -#include "java_lang_Long.h" #include "nio.h" #include "nio_util.h" #include <dlfcn.h> @@ -145,32 +144,6 @@ Java_sun_nio_ch_FileChannelImpl_unmap0(JNIEnv *env, jobject this, } -JNIEXPORT jint JNICALL -Java_sun_nio_ch_FileChannelImpl_truncate0(JNIEnv *env, jobject this, - jobject fdo, jlong size) -{ - return handle(env, - ftruncate64(fdval(env, fdo), size), - "Truncation failed"); -} - - -JNIEXPORT jint JNICALL -Java_sun_nio_ch_FileChannelImpl_force0(JNIEnv *env, jobject this, - jobject fdo, jboolean md) -{ - jint fd = fdval(env, fdo); - int result = 0; - - if (md == JNI_FALSE) { - result = fdatasync(fd); - } else { - result = fsync(fd); - } - return handle(env, result, "Force failed"); -} - - JNIEXPORT jlong JNICALL Java_sun_nio_ch_FileChannelImpl_position0(JNIEnv *env, jobject this, jobject fdo, jlong offset) @@ -187,17 +160,6 @@ Java_sun_nio_ch_FileChannelImpl_position0(JNIEnv *env, jobject this, } -JNIEXPORT jlong JNICALL -Java_sun_nio_ch_FileChannelImpl_size0(JNIEnv *env, jobject this, jobject fdo) -{ - struct stat64 fbuf; - - if (fstat64(fdval(env, fdo), &fbuf) < 0) - return handle(env, -1, "Size failed"); - return fbuf.st_size; -} - - JNIEXPORT void JNICALL Java_sun_nio_ch_FileChannelImpl_close0(JNIEnv *env, jobject this, jobject fdo) { @@ -269,6 +231,8 @@ Java_sun_nio_ch_FileChannelImpl_transferTo0(JNIEnv *env, jobject this, if (result < 0) { if (errno == EAGAIN) return IOS_UNAVAILABLE; + if (errno == EOPNOTSUPP) + return IOS_UNSUPPORTED_CASE; if ((errno == EINVAL) && ((ssize_t)count >= 0)) return IOS_UNSUPPORTED_CASE; if (errno == EINTR) @@ -280,65 +244,3 @@ Java_sun_nio_ch_FileChannelImpl_transferTo0(JNIEnv *env, jobject this, } #endif } - -JNIEXPORT jint JNICALL -Java_sun_nio_ch_FileChannelImpl_lock0(JNIEnv *env, jobject this, jobject fdo, - jboolean block, jlong pos, jlong size, - jboolean shared) -{ - jint fd = fdval(env, fdo); - jint lockResult = 0; - int cmd = 0; - struct flock64 fl; - - fl.l_whence = SEEK_SET; - if (size == (jlong)java_lang_Long_MAX_VALUE) { - fl.l_len = (off64_t)0; - } else { - fl.l_len = (off64_t)size; - } - fl.l_start = (off64_t)pos; - if (shared == JNI_TRUE) { - fl.l_type = F_RDLCK; - } else { - fl.l_type = F_WRLCK; - } - if (block == JNI_TRUE) { - cmd = F_SETLKW64; - } else { - cmd = F_SETLK64; - } - lockResult = fcntl(fd, cmd, &fl); - if (lockResult < 0) { - if ((cmd == F_SETLK64) && (errno == EAGAIN)) - return sun_nio_ch_FileChannelImpl_NO_LOCK; - if (errno == EINTR) - return sun_nio_ch_FileChannelImpl_INTERRUPTED; - JNU_ThrowIOExceptionWithLastError(env, "Lock failed"); - } - return 0; -} - - -JNIEXPORT void JNICALL -Java_sun_nio_ch_FileChannelImpl_release0(JNIEnv *env, jobject this, - jobject fdo, jlong pos, jlong size) -{ - jint fd = fdval(env, fdo); - jint lockResult = 0; - struct flock64 fl; - int cmd = F_SETLK64; - - fl.l_whence = SEEK_SET; - if (size == (jlong)java_lang_Long_MAX_VALUE) { - fl.l_len = (off64_t)0; - } else { - fl.l_len = (off64_t)size; - } - fl.l_start = (off64_t)pos; - fl.l_type = F_UNLCK; - lockResult = fcntl(fd, cmd, &fl); - if (lockResult < 0) { - JNU_ThrowIOExceptionWithLastError(env, "Release failed"); - } -} diff --git a/src/solaris/native/sun/nio/ch/FileDispatcher.c b/src/solaris/native/sun/nio/ch/FileDispatcherImpl.c similarity index 50% rename from src/solaris/native/sun/nio/ch/FileDispatcher.c rename to src/solaris/native/sun/nio/ch/FileDispatcherImpl.c index fd3c0e3d6eee723dcee0f7bdcdcea1eebfefa302..ed65889333852833772d905c4adb3bdbbdcd934b 100644 --- a/src/solaris/native/sun/nio/ch/FileDispatcher.c +++ b/src/solaris/native/sun/nio/ch/FileDispatcherImpl.c @@ -1,5 +1,5 @@ /* - * Copyright 2000-2002 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. * * This code is free software; you can redistribute it and/or modify it @@ -27,11 +27,13 @@ #include "jni_util.h" #include "jvm.h" #include "jlong.h" -#include "sun_nio_ch_FileDispatcher.h" +#include "sun_nio_ch_FileDispatcherImpl.h" +#include "java_lang_Long.h" #include <sys/types.h> #include <sys/socket.h> #include <fcntl.h> #include <sys/uio.h> +#include "nio.h" #include "nio_util.h" @@ -40,7 +42,7 @@ static int preCloseFD = -1; /* File descriptor to which we dup other fd's JNIEXPORT void JNICALL -Java_sun_nio_ch_FileDispatcher_init(JNIEnv *env, jclass cl) +Java_sun_nio_ch_FileDispatcherImpl_init(JNIEnv *env, jclass cl) { int sp[2]; if (socketpair(PF_UNIX, SOCK_STREAM, 0, sp) < 0) { @@ -52,7 +54,7 @@ Java_sun_nio_ch_FileDispatcher_init(JNIEnv *env, jclass cl) } JNIEXPORT jint JNICALL -Java_sun_nio_ch_FileDispatcher_read0(JNIEnv *env, jclass clazz, +Java_sun_nio_ch_FileDispatcherImpl_read0(JNIEnv *env, jclass clazz, jobject fdo, jlong address, jint len) { jint fd = fdval(env, fdo); @@ -62,7 +64,7 @@ Java_sun_nio_ch_FileDispatcher_read0(JNIEnv *env, jclass clazz, } JNIEXPORT jint JNICALL -Java_sun_nio_ch_FileDispatcher_pread0(JNIEnv *env, jclass clazz, jobject fdo, +Java_sun_nio_ch_FileDispatcherImpl_pread0(JNIEnv *env, jclass clazz, jobject fdo, jlong address, jint len, jlong offset) { jint fd = fdval(env, fdo); @@ -72,7 +74,7 @@ Java_sun_nio_ch_FileDispatcher_pread0(JNIEnv *env, jclass clazz, jobject fdo, } JNIEXPORT jlong JNICALL -Java_sun_nio_ch_FileDispatcher_readv0(JNIEnv *env, jclass clazz, +Java_sun_nio_ch_FileDispatcherImpl_readv0(JNIEnv *env, jclass clazz, jobject fdo, jlong address, jint len) { jint fd = fdval(env, fdo); @@ -84,7 +86,7 @@ Java_sun_nio_ch_FileDispatcher_readv0(JNIEnv *env, jclass clazz, } JNIEXPORT jint JNICALL -Java_sun_nio_ch_FileDispatcher_write0(JNIEnv *env, jclass clazz, +Java_sun_nio_ch_FileDispatcherImpl_write0(JNIEnv *env, jclass clazz, jobject fdo, jlong address, jint len) { jint fd = fdval(env, fdo); @@ -94,7 +96,7 @@ Java_sun_nio_ch_FileDispatcher_write0(JNIEnv *env, jclass clazz, } JNIEXPORT jint JNICALL -Java_sun_nio_ch_FileDispatcher_pwrite0(JNIEnv *env, jclass clazz, jobject fdo, +Java_sun_nio_ch_FileDispatcherImpl_pwrite0(JNIEnv *env, jclass clazz, jobject fdo, jlong address, jint len, jlong offset) { jint fd = fdval(env, fdo); @@ -104,7 +106,7 @@ Java_sun_nio_ch_FileDispatcher_pwrite0(JNIEnv *env, jclass clazz, jobject fdo, } JNIEXPORT jlong JNICALL -Java_sun_nio_ch_FileDispatcher_writev0(JNIEnv *env, jclass clazz, +Java_sun_nio_ch_FileDispatcherImpl_writev0(JNIEnv *env, jclass clazz, jobject fdo, jlong address, jint len) { jint fd = fdval(env, fdo); @@ -115,6 +117,113 @@ Java_sun_nio_ch_FileDispatcher_writev0(JNIEnv *env, jclass clazz, return convertLongReturnVal(env, writev(fd, iov, len), JNI_FALSE); } +static jlong +handle(JNIEnv *env, jlong rv, char *msg) +{ + if (rv >= 0) + return rv; + if (errno == EINTR) + return IOS_INTERRUPTED; + JNU_ThrowIOExceptionWithLastError(env, msg); + return IOS_THROWN; +} + +JNIEXPORT jint JNICALL +Java_sun_nio_ch_FileDispatcherImpl_force0(JNIEnv *env, jobject this, + jobject fdo, jboolean md) +{ + jint fd = fdval(env, fdo); + int result = 0; + + if (md == JNI_FALSE) { + result = fdatasync(fd); + } else { + result = fsync(fd); + } + return handle(env, result, "Force failed"); +} + +JNIEXPORT jint JNICALL +Java_sun_nio_ch_FileDispatcherImpl_truncate0(JNIEnv *env, jobject this, + jobject fdo, jlong size) +{ + return handle(env, + ftruncate64(fdval(env, fdo), size), + "Truncation failed"); +} + +JNIEXPORT jlong JNICALL +Java_sun_nio_ch_FileDispatcherImpl_size0(JNIEnv *env, jobject this, jobject fdo) +{ + struct stat64 fbuf; + + if (fstat64(fdval(env, fdo), &fbuf) < 0) + return handle(env, -1, "Size failed"); + return fbuf.st_size; +} + +JNIEXPORT jint JNICALL +Java_sun_nio_ch_FileDispatcherImpl_lock0(JNIEnv *env, jobject this, jobject fdo, + jboolean block, jlong pos, jlong size, + jboolean shared) +{ + jint fd = fdval(env, fdo); + jint lockResult = 0; + int cmd = 0; + struct flock64 fl; + + fl.l_whence = SEEK_SET; + if (size == (jlong)java_lang_Long_MAX_VALUE) { + fl.l_len = (off64_t)0; + } else { + fl.l_len = (off64_t)size; + } + fl.l_start = (off64_t)pos; + if (shared == JNI_TRUE) { + fl.l_type = F_RDLCK; + } else { + fl.l_type = F_WRLCK; + } + if (block == JNI_TRUE) { + cmd = F_SETLKW64; + } else { + cmd = F_SETLK64; + } + lockResult = fcntl(fd, cmd, &fl); + if (lockResult < 0) { + if ((cmd == F_SETLK64) && (errno == EAGAIN)) + return sun_nio_ch_FileDispatcherImpl_NO_LOCK; + if (errno == EINTR) + return sun_nio_ch_FileDispatcherImpl_INTERRUPTED; + JNU_ThrowIOExceptionWithLastError(env, "Lock failed"); + } + return 0; +} + +JNIEXPORT void JNICALL +Java_sun_nio_ch_FileDispatcherImpl_release0(JNIEnv *env, jobject this, + jobject fdo, jlong pos, jlong size) +{ + jint fd = fdval(env, fdo); + jint lockResult = 0; + struct flock64 fl; + int cmd = F_SETLK64; + + fl.l_whence = SEEK_SET; + if (size == (jlong)java_lang_Long_MAX_VALUE) { + fl.l_len = (off64_t)0; + } else { + fl.l_len = (off64_t)size; + } + fl.l_start = (off64_t)pos; + fl.l_type = F_UNLCK; + lockResult = fcntl(fd, cmd, &fl); + if (lockResult < 0) { + JNU_ThrowIOExceptionWithLastError(env, "Release failed"); + } +} + + static void closeFileDescriptor(JNIEnv *env, int fd) { if (fd != -1) { int result = close(fd); @@ -124,14 +233,14 @@ static void closeFileDescriptor(JNIEnv *env, int fd) { } JNIEXPORT void JNICALL -Java_sun_nio_ch_FileDispatcher_close0(JNIEnv *env, jclass clazz, jobject fdo) +Java_sun_nio_ch_FileDispatcherImpl_close0(JNIEnv *env, jclass clazz, jobject fdo) { jint fd = fdval(env, fdo); closeFileDescriptor(env, fd); } JNIEXPORT void JNICALL -Java_sun_nio_ch_FileDispatcher_preClose0(JNIEnv *env, jclass clazz, jobject fdo) +Java_sun_nio_ch_FileDispatcherImpl_preClose0(JNIEnv *env, jclass clazz, jobject fdo) { jint fd = fdval(env, fdo); if (preCloseFD >= 0) { @@ -141,7 +250,7 @@ Java_sun_nio_ch_FileDispatcher_preClose0(JNIEnv *env, jclass clazz, jobject fdo) } JNIEXPORT void JNICALL -Java_sun_nio_ch_FileDispatcher_closeIntFD(JNIEnv *env, jclass clazz, jint fd) +Java_sun_nio_ch_FileDispatcherImpl_closeIntFD(JNIEnv *env, jclass clazz, jint fd) { closeFileDescriptor(env, fd); } diff --git a/src/solaris/native/sun/nio/ch/SocketDispatcher.c b/src/solaris/native/sun/nio/ch/SocketDispatcher.c index 1524326b6b055673b277e57aadd6391e5726dd5b..812ff4bedd892544e588b0b29bdc75ac0ddf7db1 100644 --- a/src/solaris/native/sun/nio/ch/SocketDispatcher.c +++ b/src/solaris/native/sun/nio/ch/SocketDispatcher.c @@ -1,5 +1,5 @@ /* - * Copyright 2000-2001 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. * * This code is free software; you can redistribute it and/or modify it @@ -27,7 +27,6 @@ #include "jni_util.h" #include "jvm.h" #include "jlong.h" -#include "sun_nio_ch_FileDispatcher.h" /* this is a fake c file to make the build happy since there is no real SocketDispatcher.c file on Solaris but there is on windows. */ diff --git a/src/solaris/native/sun/nio/ch/SolarisEventPort.c b/src/solaris/native/sun/nio/ch/SolarisEventPort.c new file mode 100644 index 0000000000000000000000000000000000000000..649475946abf27400b63573b3ebbf3a57ca12efa --- /dev/null +++ b/src/solaris/native/sun/nio/ch/SolarisEventPort.c @@ -0,0 +1,120 @@ +/* + * Copyright 2008-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. + */ + +#include "jni.h" +#include "jni_util.h" +#include "jvm.h" +#include "jlong.h" +#include "nio_util.h" + +#include <stdlib.h> +#include <dlfcn.h> +#include <sys/types.h> +#include <port.h> // Solaris 10 + +#include "sun_nio_ch_SolarisEventPort.h" + +JNIEXPORT void JNICALL +Java_sun_nio_ch_SolarisEventPort_init(JNIEnv *env, jclass clazz) +{ +} + +JNIEXPORT jint JNICALL +Java_sun_nio_ch_SolarisEventPort_portCreate + (JNIEnv* env, jclass clazz) +{ + int port = port_create(); + if (port == -1) { + JNU_ThrowIOExceptionWithLastError(env, "port_create"); + } + return (jint)port; +} + +JNIEXPORT void JNICALL +Java_sun_nio_ch_SolarisEventPort_portClose + (JNIEnv* env, jclass clazz, jint port) +{ + int res; + RESTARTABLE(close(port), res); +} + +JNIEXPORT void JNICALL +Java_sun_nio_ch_SolarisEventPort_portAssociate + (JNIEnv* env, jclass clazz, jint port, jint source, jlong objectAddress, jint events) +{ + uintptr_t object = (uintptr_t)jlong_to_ptr(objectAddress); + + if (port_associate((int)port, (int)source, object, (int)events, NULL) == -1) { + JNU_ThrowIOExceptionWithLastError(env, "port_associate"); + } +} + +JNIEXPORT void JNICALL +Java_sun_nio_ch_SolarisEventPort_portDissociate + (JNIEnv* env, jclass clazz, jint port, jint source, jlong objectAddress) +{ + uintptr_t object = (uintptr_t)jlong_to_ptr(objectAddress); + + if (port_dissociate((int)port, (int)source, object) == -1) { + JNU_ThrowIOExceptionWithLastError(env, "port_dissociate"); + } +} + +JNIEXPORT void JNICALL +Java_sun_nio_ch_SolarisEventPort_portSend(JNIEnv* env, jclass clazz, + jint port, jint events) +{ + if (port_send((int)port, (int)events, NULL) == -1) { + JNU_ThrowIOExceptionWithLastError(env, "port_send"); + } +} + +JNIEXPORT void JNICALL +Java_sun_nio_ch_SolarisEventPort_portGet(JNIEnv* env, jclass clazz, + jint port, jlong eventAddress) +{ + int res; + port_event_t* ev = (port_event_t*)jlong_to_ptr(eventAddress); + + RESTARTABLE(port_get((int)port, ev, NULL), res); + if (res == -1) { + JNU_ThrowIOExceptionWithLastError(env, "port_get"); + } +} + +JNIEXPORT jint JNICALL +Java_sun_nio_ch_SolarisEventPort_portGetn(JNIEnv* env, jclass clazz, + jint port, jlong arrayAddress, jint max) +{ + int res; + uint_t n = 1; + port_event_t* list = (port_event_t*)jlong_to_ptr(arrayAddress); + + RESTARTABLE(port_getn((int)port, list, (uint_t)max, &n, NULL), res); + if (res == -1) { + JNU_ThrowIOExceptionWithLastError(env, "port_getn"); + } + return (jint)n; +} diff --git a/src/solaris/native/sun/nio/ch/UnixAsynchronousServerSocketChannelImpl.c b/src/solaris/native/sun/nio/ch/UnixAsynchronousServerSocketChannelImpl.c new file mode 100644 index 0000000000000000000000000000000000000000..9c92cc2ad51c748d8ff9b84f1aae65f14606d8d6 --- /dev/null +++ b/src/solaris/native/sun/nio/ch/UnixAsynchronousServerSocketChannelImpl.c @@ -0,0 +1,47 @@ +/* + * Copyright 2008-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. + */ + +#include "sun_nio_ch_UnixAsynchronousServerSocketChannelImpl.h" + +extern void Java_sun_nio_ch_ServerSocketChannelImpl_initIDs(JNIEnv* env, + jclass c); + +extern jint Java_sun_nio_ch_ServerSocketChannelImpl_accept0(JNIEnv* env, + jobject this, jobject ssfdo, jobject newfdo, jobjectArray isaa); + +JNIEXPORT void JNICALL +Java_sun_nio_ch_UnixAsynchronousServerSocketChannelImpl_initIDs(JNIEnv* env, + jclass c) +{ + Java_sun_nio_ch_ServerSocketChannelImpl_initIDs(env, c); +} + +JNIEXPORT jint JNICALL +Java_sun_nio_ch_UnixAsynchronousServerSocketChannelImpl_accept0(JNIEnv* env, + jobject this, jobject ssfdo, jobject newfdo, jobjectArray isaa) +{ + return Java_sun_nio_ch_ServerSocketChannelImpl_accept0(env, this, + ssfdo, newfdo, isaa); +} diff --git a/src/solaris/native/sun/nio/ch/UnixAsynchronousSocketChannelImpl.c b/src/solaris/native/sun/nio/ch/UnixAsynchronousSocketChannelImpl.c new file mode 100644 index 0000000000000000000000000000000000000000..461d97f405c4009beba4eb4d21cbac08c4f848a7 --- /dev/null +++ b/src/solaris/native/sun/nio/ch/UnixAsynchronousSocketChannelImpl.c @@ -0,0 +1,53 @@ +/* + * Copyright 2008-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. + */ + +#include <sys/types.h> +#include <sys/socket.h> + +#include "jni.h" +#include "jni_util.h" +#include "net_util.h" +#include "jlong.h" +#include "sun_nio_ch_UnixAsynchronousSocketChannelImpl.h" +#include "nio_util.h" +#include "nio.h" + + +JNIEXPORT void JNICALL +Java_sun_nio_ch_UnixAsynchronousSocketChannelImpl_checkConnect(JNIEnv *env, + jobject this, int fd) +{ + int error = 0; + int n = sizeof(error); + int result; + + result = getsockopt(fd, SOL_SOCKET, SO_ERROR, &error, &n); + if (result < 0) { + JNU_ThrowIOExceptionWithLastError(env, "getsockopt"); + } else { + if (error) + handleSocketError(env, error); + } +} diff --git a/src/solaris/native/sun/nio/fs/GnomeFileTypeDetector.c b/src/solaris/native/sun/nio/fs/GnomeFileTypeDetector.c new file mode 100644 index 0000000000000000000000000000000000000000..0a169a94d89d9be2fb916702246028da25e6d2cd --- /dev/null +++ b/src/solaris/native/sun/nio/fs/GnomeFileTypeDetector.c @@ -0,0 +1,205 @@ +/* + * Copyright 2008-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. + */ + +#include "jni.h" +#include "jni_util.h" +#include "jvm.h" +#include "jlong.h" + +#include <stdlib.h> +#include <dlfcn.h> +#include <link.h> + +#ifdef __solaris__ +#include <strings.h> +#endif + +#ifdef __linux__ +#include <string.h> +#endif + +/* Definitions for GIO */ + +#define G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE "standard::content-type" + +typedef void* gpointer; +typedef struct _GFile GFile; +typedef struct _GFileInfo GFileInfo; +typedef struct _GCancellable GCancellable; +typedef struct _GError GError; + +typedef enum { + G_FILE_QUERY_INFO_NONE = 0 +} GFileQueryInfoFlags; + +typedef void (*g_type_init_func)(void); +typedef void (*g_object_unref_func)(gpointer object); +typedef GFile* (*g_file_new_for_path_func)(const char* path); +typedef GFileInfo* (*g_file_query_info_func)(GFile *file, + const char *attributes, GFileQueryInfoFlags flags, + GCancellable *cancellable, GError **error); +typedef char* (*g_file_info_get_content_type_func)(GFileInfo *info); + +static g_type_init_func g_type_init; +static g_object_unref_func g_object_unref; +static g_file_new_for_path_func g_file_new_for_path; +static g_file_query_info_func g_file_query_info; +static g_file_info_get_content_type_func g_file_info_get_content_type; + + +/* Definitions for GNOME VFS */ + +typedef int gboolean; + +typedef gboolean (*gnome_vfs_init_function)(void); +typedef const char* (*gnome_vfs_mime_type_from_name_function) + (const char* filename); + +static gnome_vfs_init_function gnome_vfs_init; +static gnome_vfs_mime_type_from_name_function gnome_vfs_mime_type_from_name; + + +#include "sun_nio_fs_GnomeFileTypeDetector.h" + + +JNIEXPORT jboolean JNICALL +Java_sun_nio_fs_GnomeFileTypeDetector_initializeGio + (JNIEnv* env, jclass this) +{ + void* gio_handle; + + gio_handle = dlopen("libgio-2.0.so", RTLD_LAZY); + if (gio_handle == NULL) { + gio_handle = dlopen("libgio-2.0.so.0", RTLD_LAZY); + if (gio_handle == NULL) { + return JNI_FALSE; + } + } + + g_type_init = (g_type_init_func)dlsym(gio_handle, "g_type_init"); + (*g_type_init)(); + + g_object_unref = (g_object_unref_func)dlsym(gio_handle, "g_object_unref"); + + g_file_new_for_path = + (g_file_new_for_path_func)dlsym(gio_handle, "g_file_new_for_path"); + + g_file_query_info = + (g_file_query_info_func)dlsym(gio_handle, "g_file_query_info"); + + g_file_info_get_content_type = (g_file_info_get_content_type_func) + dlsym(gio_handle, "g_file_info_get_content_type"); + + + if (g_type_init == NULL || + g_object_unref == NULL || + g_file_new_for_path == NULL || + g_file_query_info == NULL || + g_file_info_get_content_type == NULL) + { + dlclose(gio_handle); + return JNI_FALSE; + } + + (*g_type_init)(); + return JNI_TRUE; +} + +JNIEXPORT jbyteArray JNICALL +Java_sun_nio_fs_GnomeFileTypeDetector_probeUsingGio + (JNIEnv* env, jclass this, jlong pathAddress) +{ + char* path = (char*)jlong_to_ptr(pathAddress); + GFile* gfile; + GFileInfo* gfileinfo; + jbyteArray result = NULL; + + gfile = (*g_file_new_for_path)(path); + gfileinfo = (*g_file_query_info)(gfile, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, + G_FILE_QUERY_INFO_NONE, NULL, NULL); + if (gfileinfo != NULL) { + const char* mime = (*g_file_info_get_content_type)(gfileinfo); + if (mime != NULL) { + jsize len = strlen(mime); + result = (*env)->NewByteArray(env, len); + if (result != NULL) { + (*env)->SetByteArrayRegion(env, result, 0, len, (jbyte*)mime); + } + } + (*g_object_unref)(gfileinfo); + } + (*g_object_unref)(gfile); + + return result; +} + +JNIEXPORT jboolean JNICALL +Java_sun_nio_fs_GnomeFileTypeDetector_initializeGnomeVfs + (JNIEnv* env, jclass this) +{ + void* vfs_handle; + + vfs_handle = dlopen("libgnomevfs-2.so", RTLD_LAZY); + if (vfs_handle == NULL) { + vfs_handle = dlopen("libgnomevfs-2.so.0", RTLD_LAZY); + } + if (vfs_handle == NULL) { + return JNI_FALSE; + } + + gnome_vfs_init = (gnome_vfs_init_function)dlsym(vfs_handle, "gnome_vfs_init"); + gnome_vfs_mime_type_from_name = (gnome_vfs_mime_type_from_name_function) + dlsym(vfs_handle, "gnome_vfs_mime_type_from_name"); + + if (gnome_vfs_init == NULL || + gnome_vfs_mime_type_from_name == NULL) + { + dlclose(vfs_handle); + return JNI_FALSE; + } + + (*gnome_vfs_init)(); + return JNI_TRUE; +} + +JNIEXPORT jbyteArray JNICALL +Java_sun_nio_fs_GnomeFileTypeDetector_probeUsingGnomeVfs + (JNIEnv* env, jclass this, jlong pathAddress) +{ + char* path = (char*)jlong_to_ptr(pathAddress); + const char* mime = (*gnome_vfs_mime_type_from_name)(path); + + if (mime == NULL) { + return NULL; + } else { + jbyteArray result; + jsize len = strlen(mime); + result = (*env)->NewByteArray(env, len); + if (result != NULL) { + (*env)->SetByteArrayRegion(env, result, 0, len, (jbyte*)mime); + } + return result; + } +} diff --git a/src/solaris/native/sun/nio/fs/LinuxNativeDispatcher.c b/src/solaris/native/sun/nio/fs/LinuxNativeDispatcher.c new file mode 100644 index 0000000000000000000000000000000000000000..8e4fa669611033d71c800e71dd697d34178d5754 --- /dev/null +++ b/src/solaris/native/sun/nio/fs/LinuxNativeDispatcher.c @@ -0,0 +1,160 @@ +/* + * Copyright 2008-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. + */ + +#include "jni.h" +#include "jni_util.h" +#include "jvm.h" +#include "jlong.h" + +#include <stdio.h> +#include <dlfcn.h> +#include <errno.h> +#include <mntent.h> + +#include "sun_nio_fs_LinuxNativeDispatcher.h" + +typedef size_t fgetxattr_func(int fd, const char* name, void* value, size_t size); +typedef int fsetxattr_func(int fd, const char* name, void* value, size_t size, int flags); +typedef int fremovexattr_func(int fd, const char* name); +typedef int flistxattr_func(int fd, char* list, size_t size); + +fgetxattr_func* my_fgetxattr_func = NULL; +fsetxattr_func* my_fsetxattr_func = NULL; +fremovexattr_func* my_fremovexattr_func = NULL; +flistxattr_func* my_flistxattr_func = NULL; + +static void throwUnixException(JNIEnv* env, int errnum) { + jobject x = JNU_NewObjectByName(env, "sun/nio/fs/UnixException", + "(I)V", errnum); + if (x != NULL) { + (*env)->Throw(env, x); + } +} + +JNIEXPORT void JNICALL +Java_sun_nio_fs_LinuxNativeDispatcher_init(JNIEnv *env, jclass clazz) +{ + my_fgetxattr_func = (fgetxattr_func*)dlsym(RTLD_DEFAULT, "fgetxattr"); + my_fsetxattr_func = (fsetxattr_func*)dlsym(RTLD_DEFAULT, "fsetxattr"); + my_fremovexattr_func = (fremovexattr_func*)dlsym(RTLD_DEFAULT, "fremovexattr"); + my_flistxattr_func = (flistxattr_func*)dlsym(RTLD_DEFAULT, "flistxattr"); +} + +JNIEXPORT jint JNICALL +Java_sun_nio_fs_LinuxNativeDispatcher_fgetxattr0(JNIEnv* env, jclass clazz, + jint fd, jlong nameAddress, jlong valueAddress, jint valueLen) +{ + size_t res = -1; + const char* name = jlong_to_ptr(nameAddress); + void* value = jlong_to_ptr(valueAddress); + + if (my_fgetxattr_func == NULL) { + errno = ENOTSUP; + } else { + /* EINTR not documented */ + res = (*my_fgetxattr_func)(fd, name, value, valueLen); + } + if (res == (size_t)-1) + throwUnixException(env, errno); + return (jint)res; +} + +JNIEXPORT void JNICALL +Java_sun_nio_fs_LinuxNativeDispatcher_fsetxattr0(JNIEnv* env, jclass clazz, + jint fd, jlong nameAddress, jlong valueAddress, jint valueLen) +{ + int res = -1; + const char* name = jlong_to_ptr(nameAddress); + void* value = jlong_to_ptr(valueAddress); + + if (my_fsetxattr_func == NULL) { + errno = ENOTSUP; + } else { + /* EINTR not documented */ + res = (*my_fsetxattr_func)(fd, name, value, valueLen, 0); + } + if (res == -1) + throwUnixException(env, errno); +} + +JNIEXPORT void JNICALL +Java_sun_nio_fs_LinuxNativeDispatcher_fremovexattr0(JNIEnv* env, jclass clazz, + jint fd, jlong nameAddress) +{ + int res = -1; + const char* name = jlong_to_ptr(nameAddress); + + if (my_fremovexattr_func == NULL) { + errno = ENOTSUP; + } else { + /* EINTR not documented */ + res = (*my_fremovexattr_func)(fd, name); + } + if (res == -1) + throwUnixException(env, errno); +} + +JNIEXPORT jint JNICALL +Java_sun_nio_fs_LinuxNativeDispatcher_flistxattr(JNIEnv* env, jclass clazz, + jint fd, jlong listAddress, jint size) +{ + size_t res = -1; + char* list = jlong_to_ptr(listAddress); + + if (my_flistxattr_func == NULL) { + errno = ENOTSUP; + } else { + /* EINTR not documented */ + res = (*my_flistxattr_func)(fd, list, (size_t)size); + } + if (res == (size_t)-1) + throwUnixException(env, errno); + return (jint)res; +} + +JNIEXPORT jlong JNICALL +Java_sun_nio_fs_LinuxNativeDispatcher_setmntent0(JNIEnv* env, jclass this, jlong pathAddress, + jlong modeAddress) +{ + FILE* fp = NULL; + const char* path = (const char*)jlong_to_ptr(pathAddress); + const char* mode = (const char*)jlong_to_ptr(modeAddress); + + do { + fp = setmntent(path, mode); + } while (fp == NULL && errno == EINTR); + if (fp == NULL) { + throwUnixException(env, errno); + } + return ptr_to_jlong(fp); +} + +JNIEXPORT void JNICALL +Java_sun_nio_fs_LinuxNativeDispatcher_endmntent(JNIEnv* env, jclass this, jlong stream) +{ + FILE* fp = jlong_to_ptr(stream); + /* FIXME - man page doesn't explain how errors are returned */ + endmntent(fp); +} diff --git a/src/solaris/native/sun/nio/fs/LinuxWatchService.c b/src/solaris/native/sun/nio/fs/LinuxWatchService.c new file mode 100644 index 0000000000000000000000000000000000000000..74a1540791604794c0f40cf23e5bcc19c12828cb --- /dev/null +++ b/src/solaris/native/sun/nio/fs/LinuxWatchService.c @@ -0,0 +1,195 @@ +/* + * Copyright 2008-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. + */ + +#include "jni.h" +#include "jni_util.h" +#include "jvm.h" +#include "jlong.h" + +#include <stdlib.h> +#include <dlfcn.h> +#include <sys/types.h> +#include <sys/socket.h> +#include <sys/poll.h> + +#include "sun_nio_fs_LinuxWatchService.h" + +/* inotify.h may not be available at build time */ +#ifdef __cplusplus +extern "C" { +#endif +struct inotify_event +{ + int wd; + uint32_t mask; + uint32_t cookie; + uint32_t len; + char name __flexarr; +}; +#ifdef __cplusplus +} +#endif + +typedef int inotify_init_func(void); +typedef int inotify_add_watch_func(int fd, const char* path, uint32_t mask); +typedef int inotify_rm_watch_func(int fd, uint32_t wd); + +inotify_init_func* my_inotify_init_func = NULL; +inotify_add_watch_func* my_inotify_add_watch_func = NULL; +inotify_rm_watch_func* my_inotify_rm_watch_func = NULL; + +static void throwUnixException(JNIEnv* env, int errnum) { + jobject x = JNU_NewObjectByName(env, "sun/nio/fs/UnixException", + "(I)V", errnum); + if (x != NULL) { + (*env)->Throw(env, x); + } +} + +JNIEXPORT void JNICALL +Java_sun_nio_fs_LinuxWatchService_init(JNIEnv *env, jclass clazz) +{ + my_inotify_init_func = (inotify_init_func*) + dlsym(RTLD_DEFAULT, "inotify_init"); + my_inotify_add_watch_func = + (inotify_add_watch_func*) dlsym(RTLD_DEFAULT, "inotify_add_watch"); + my_inotify_rm_watch_func = + (inotify_rm_watch_func*) dlsym(RTLD_DEFAULT, "inotify_rm_watch"); + + if ((my_inotify_init_func == NULL) || (my_inotify_add_watch_func == NULL) || + (my_inotify_rm_watch_func == NULL)) { + JNU_ThrowInternalError(env, "unable to get address of inotify functions"); + } +} + +JNIEXPORT jint JNICALL +Java_sun_nio_fs_LinuxWatchService_eventSize(JNIEnv *env, jclass clazz) +{ + return (jint)sizeof(struct inotify_event); +} + +JNIEXPORT jintArray JNICALL +Java_sun_nio_fs_LinuxWatchService_eventOffsets(JNIEnv *env, jclass clazz) +{ + jintArray result = (*env)->NewIntArray(env, 5); + if (result != NULL) { + jint arr[5]; + arr[0] = (jint)offsetof(struct inotify_event, wd); + arr[1] = (jint)offsetof(struct inotify_event, mask); + arr[2] = (jint)offsetof(struct inotify_event, cookie); + arr[3] = (jint)offsetof(struct inotify_event, len); + arr[4] = (jint)offsetof(struct inotify_event, name); + (*env)->SetIntArrayRegion(env, result, 0, 5, arr); + } + return result; +} + + +JNIEXPORT jint JNICALL +Java_sun_nio_fs_LinuxWatchService_inotifyInit + (JNIEnv* env, jclass clazz) +{ + int ifd = (*my_inotify_init_func)(); + if (ifd == -1) { + throwUnixException(env, errno); + } + return (jint)ifd; +} + +JNIEXPORT jint JNICALL +Java_sun_nio_fs_LinuxWatchService_inotifyAddWatch + (JNIEnv* env, jclass clazz, jint fd, jlong address, jint mask) +{ + int wfd = -1; + const char* path = (const char*)jlong_to_ptr(address); + + wfd = (*my_inotify_add_watch_func)((int)fd, path, mask); + if (wfd == -1) { + throwUnixException(env, errno); + } + return (jint)wfd; +} + +JNIEXPORT void JNICALL +Java_sun_nio_fs_LinuxWatchService_inotifyRmWatch + (JNIEnv* env, jclass clazz, jint fd, jint wd) +{ + int err = (*my_inotify_rm_watch_func)((int)fd, (int)wd); + if (err == -1) + throwUnixException(env, errno); +} + +JNIEXPORT void JNICALL +Java_sun_nio_fs_LinuxWatchService_configureBlocking + (JNIEnv* env, jclass clazz, jint fd, jboolean blocking) +{ + int flags = fcntl(fd, F_GETFL); + + if ((blocking == JNI_FALSE) && !(flags & O_NONBLOCK)) + fcntl(fd, F_SETFL, flags | O_NONBLOCK); + else if ((blocking == JNI_TRUE) && (flags & O_NONBLOCK)) + fcntl(fd, F_SETFL, flags & ~O_NONBLOCK); +} + +JNIEXPORT void JNICALL +Java_sun_nio_fs_LinuxWatchService_socketpair + (JNIEnv* env, jclass clazz, jintArray sv) +{ + int sp[2]; + if (socketpair(PF_UNIX, SOCK_STREAM, 0, sp) == -1) { + throwUnixException(env, errno); + } else { + jint res[2]; + res[0] = (jint)sp[0]; + res[1] = (jint)sp[1]; + (*env)->SetIntArrayRegion(env, sv, 0, 2, &res[0]); + } + +} + +JNIEXPORT jint JNICALL +Java_sun_nio_fs_LinuxWatchService_poll + (JNIEnv* env, jclass clazz, jint fd1, jint fd2) +{ + struct pollfd ufds[2]; + int n; + + ufds[0].fd = fd1; + ufds[0].events = POLLIN; + ufds[1].fd = fd2; + ufds[1].events = POLLIN; + + n = poll(&ufds[0], 2, -1); + if (n == -1) { + if (errno == EINTR) { + n = 0; + } else { + throwUnixException(env, errno); + } + } + return (jint)n; + + +} diff --git a/src/solaris/native/sun/nio/fs/SolarisNativeDispatcher.c b/src/solaris/native/sun/nio/fs/SolarisNativeDispatcher.c new file mode 100644 index 0000000000000000000000000000000000000000..a57009c67bcd1e3e5ab62aae3691840c3e8409b2 --- /dev/null +++ b/src/solaris/native/sun/nio/fs/SolarisNativeDispatcher.c @@ -0,0 +1,61 @@ +/* + * Copyright 2008-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. + */ + +#include "jni.h" +#include "jni_util.h" +#include "jvm.h" +#include "jlong.h" + +#include <dlfcn.h> +#include <errno.h> +#include <sys/acl.h> + +#include "sun_nio_fs_SolarisNativeDispatcher.h" + +static void throwUnixException(JNIEnv* env, int errnum) { + jobject x = JNU_NewObjectByName(env, "sun/nio/fs/UnixException", + "(I)V", errnum); + if (x != NULL) { + (*env)->Throw(env, x); + } +} + +JNIEXPORT void JNICALL +Java_sun_nio_fs_SolarisNativeDispatcher_init(JNIEnv *env, jclass clazz) { +} + +JNIEXPORT jint JNICALL +Java_sun_nio_fs_SolarisNativeDispatcher_facl(JNIEnv* env, jclass this, jint fd, + jint cmd, jint nentries, jlong address) +{ + void* aclbufp = jlong_to_ptr(address); + int n = -1; + + n = facl((int)fd, (int)cmd, (int)nentries, aclbufp); + if (n == -1) { + throwUnixException(env, errno); + } + return (jint)n; +} diff --git a/src/solaris/native/sun/nio/fs/SolarisWatchService.c b/src/solaris/native/sun/nio/fs/SolarisWatchService.c new file mode 100644 index 0000000000000000000000000000000000000000..776227f99554aaeaee258579b4a2386ea4ac119c --- /dev/null +++ b/src/solaris/native/sun/nio/fs/SolarisWatchService.c @@ -0,0 +1,104 @@ +/* + * Copyright 2008-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. + */ + +#include "jni.h" +#include "jni_util.h" +#include "jvm.h" +#include "jlong.h" + +#include <stdlib.h> +#include <dlfcn.h> +#include <sys/types.h> +#include <port.h> // Solaris 10 + +#include "sun_nio_fs_SolarisWatchService.h" + +static void throwUnixException(JNIEnv* env, int errnum) { + jobject x = JNU_NewObjectByName(env, "sun/nio/fs/UnixException", + "(I)V", errnum); + if (x != NULL) { + (*env)->Throw(env, x); + } +} + +JNIEXPORT void JNICALL +Java_sun_nio_fs_SolarisWatchService_init(JNIEnv *env, jclass clazz) +{ +} + +JNIEXPORT jint JNICALL +Java_sun_nio_fs_SolarisWatchService_portCreate + (JNIEnv* env, jclass clazz) +{ + int port = port_create(); + if (port == -1) { + throwUnixException(env, errno); + } + return (jint)port; +} + +JNIEXPORT void JNICALL +Java_sun_nio_fs_SolarisWatchService_portAssociate + (JNIEnv* env, jclass clazz, jint port, jint source, jlong objectAddress, jint events) +{ + uintptr_t object = (uintptr_t)jlong_to_ptr(objectAddress); + + if (port_associate((int)port, (int)source, object, (int)events, NULL) == -1) { + throwUnixException(env, errno); + } +} + +JNIEXPORT void JNICALL +Java_sun_nio_fs_SolarisWatchService_portDissociate + (JNIEnv* env, jclass clazz, jint port, jint source, jlong objectAddress) +{ + uintptr_t object = (uintptr_t)jlong_to_ptr(objectAddress); + + if (port_dissociate((int)port, (int)source, object) == -1) { + throwUnixException(env, errno); + } +} + +JNIEXPORT void JNICALL +Java_sun_nio_fs_SolarisWatchService_portSend(JNIEnv* env, jclass clazz, + jint port, jint events) +{ + if (port_send((int)port, (int)events, NULL) == -1) { + throwUnixException(env, errno); + } +} + +JNIEXPORT jint JNICALL +Java_sun_nio_fs_SolarisWatchService_portGetn(JNIEnv* env, jclass clazz, + jint port, jlong arrayAddress, jint max) +{ + uint_t n = 1; + port_event_t* list = (port_event_t*)jlong_to_ptr(arrayAddress); + + if (port_getn((int)port, list, (uint_t)max, &n, NULL) == -1) { + throwUnixException(env, errno); + } + return (jint)n; +} diff --git a/src/solaris/native/sun/nio/fs/UnixCopyFile.c b/src/solaris/native/sun/nio/fs/UnixCopyFile.c new file mode 100644 index 0000000000000000000000000000000000000000..526ccba96688daa982bdd6557ca557668da42182 --- /dev/null +++ b/src/solaris/native/sun/nio/fs/UnixCopyFile.c @@ -0,0 +1,85 @@ +/* + * Copyright 2008-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. + */ + +#include "jni.h" +#include "jni_util.h" +#include "jlong.h" + +#include <unistd.h> +#include <errno.h> + +#include "sun_nio_fs_UnixCopyFile.h" + +#define RESTARTABLE(_cmd, _result) do { \ + do { \ + _result = _cmd; \ + } while((_result == -1) && (errno == EINTR)); \ +} while(0) + +static void throwUnixException(JNIEnv* env, int errnum) { + jobject x = JNU_NewObjectByName(env, "sun/nio/fs/UnixException", + "(I)V", errnum); + if (x != NULL) { + (*env)->Throw(env, x); + } +} + +/** + * Transfer all bytes from src to dst via user-space buffers + */ +JNIEXPORT void JNICALL +Java_sun_nio_fs_UnixCopyFile_transfer + (JNIEnv* env, jclass this, jint dst, jint src, jlong cancelAddress) +{ + char buf[8192]; + volatile jint* cancel = (jint*)jlong_to_ptr(cancelAddress); + + for (;;) { + ssize_t n, pos, len; + RESTARTABLE(read((int)src, &buf, sizeof(buf)), n); + if (n <= 0) { + if (n < 0) + throwUnixException(env, errno); + return; + } + if (cancel != NULL && *cancel != 0) { + throwUnixException(env, ECANCELED); + return; + } + pos = 0; + len = n; + do { + char* bufp = buf; + bufp += pos; + RESTARTABLE(write((int)dst, bufp, len), n); + if (n == -1) { + throwUnixException(env, errno); + return; + } + pos += n; + len -= n; + } while (len > 0); + } +} diff --git a/src/solaris/native/sun/nio/fs/UnixNativeDispatcher.c b/src/solaris/native/sun/nio/fs/UnixNativeDispatcher.c new file mode 100644 index 0000000000000000000000000000000000000000..13a1a3a215f9434abf6de9a8bbc69d22e92ff023 --- /dev/null +++ b/src/solaris/native/sun/nio/fs/UnixNativeDispatcher.c @@ -0,0 +1,1080 @@ +/* + * Copyright 2008-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. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <limits.h> +#include <fcntl.h> +#include <dirent.h> +#include <unistd.h> +#include <pwd.h> +#include <grp.h> +#include <errno.h> +#include <dlfcn.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <sys/statvfs.h> +#include <sys/time.h> + +#ifdef __solaris__ +#include <strings.h> +#include <sys/mnttab.h> +#include <sys/mkdev.h> +#endif + +#ifdef __linux__ +#include <string.h> +#include <mntent.h> +#endif + +#include "jni.h" +#include "jni_util.h" +#include "jlong.h" + +#include "sun_nio_fs_UnixNativeDispatcher.h" + +#define RESTARTABLE(_cmd, _result) do { \ + do { \ + _result = _cmd; \ + } while((_result == -1) && (errno == EINTR)); \ +} while(0) + +static jfieldID attrs_st_mode; +static jfieldID attrs_st_ino; +static jfieldID attrs_st_dev; +static jfieldID attrs_st_rdev; +static jfieldID attrs_st_nlink; +static jfieldID attrs_st_uid; +static jfieldID attrs_st_gid; +static jfieldID attrs_st_size; +static jfieldID attrs_st_atime; +static jfieldID attrs_st_mtime; +static jfieldID attrs_st_ctime; + +static jfieldID attrs_f_frsize; +static jfieldID attrs_f_blocks; +static jfieldID attrs_f_bfree; +static jfieldID attrs_f_bavail; + +static jfieldID entry_name; +static jfieldID entry_dir; +static jfieldID entry_fstype; +static jfieldID entry_options; +static jfieldID entry_dev; + +/** + * System calls that may not be available at build time. + */ +typedef int openat64_func(int, const char *, int, ...); +typedef int fstatat64_func(int, const char *, struct stat64 *, int); +typedef int unlinkat_func(int, const char*, int); +typedef int renameat_func(int, const char*, int, const char*); +typedef int futimesat_func(int, const char *, const struct timeval *); +typedef DIR* fdopendir_func(int); + +static openat64_func* my_openat64_func = NULL; +static fstatat64_func* my_fstatat64_func = NULL; +static unlinkat_func* my_unlinkat_func = NULL; +static renameat_func* my_renameat_func = NULL; +static futimesat_func* my_futimesat_func = NULL; +static fdopendir_func* my_fdopendir_func = NULL; + +/** + * fstatat missing from glibc on Linux. Temporary workaround + * for x86/x64. + */ +#if defined(__linux__) && defined(__i386) +#define FSTATAT64_SYSCALL_AVAILABLE +static int fstatat64_wrapper(int dfd, const char *path, + struct stat64 *statbuf, int flag) +{ + #ifndef __NR_fstatat64 + #define __NR_fstatat64 300 + #endif + return syscall(__NR_fstatat64, dfd, path, statbuf, flag); +} +#endif + +#if defined(__linux__) && defined(__x86_64__) +#define FSTATAT64_SYSCALL_AVAILABLE +static int fstatat64_wrapper(int dfd, const char *path, + struct stat64 *statbuf, int flag) +{ + #ifndef __NR_newfstatat + #define __NR_newfstatat 262 + #endif + return syscall(__NR_newfstatat, dfd, path, statbuf, flag); +} +#endif + +/** + * Call this to throw an internal UnixException when a system/library + * call fails + */ +static void throwUnixException(JNIEnv* env, int errnum) { + jobject x = JNU_NewObjectByName(env, "sun/nio/fs/UnixException", + "(I)V", errnum); + if (x != NULL) { + (*env)->Throw(env, x); + } +} + +/** + * Initialize jfieldIDs + */ +JNIEXPORT void JNICALL +Java_sun_nio_fs_UnixNativeDispatcher_initIDs(JNIEnv* env, jclass this) +{ + jclass clazz; + + clazz = (*env)->FindClass(env, "sun/nio/fs/UnixFileAttributes"); + if (clazz == NULL) { + return; + } + attrs_st_mode = (*env)->GetFieldID(env, clazz, "st_mode", "I"); + attrs_st_ino = (*env)->GetFieldID(env, clazz, "st_ino", "J"); + attrs_st_dev = (*env)->GetFieldID(env, clazz, "st_dev", "J"); + attrs_st_rdev = (*env)->GetFieldID(env, clazz, "st_rdev", "J"); + attrs_st_nlink = (*env)->GetFieldID(env, clazz, "st_nlink", "I"); + attrs_st_uid = (*env)->GetFieldID(env, clazz, "st_uid", "I"); + attrs_st_gid = (*env)->GetFieldID(env, clazz, "st_gid", "I"); + attrs_st_size = (*env)->GetFieldID(env, clazz, "st_size", "J"); + attrs_st_atime = (*env)->GetFieldID(env, clazz, "st_atime", "J"); + attrs_st_mtime = (*env)->GetFieldID(env, clazz, "st_mtime", "J"); + attrs_st_ctime = (*env)->GetFieldID(env, clazz, "st_ctime", "J"); + + clazz = (*env)->FindClass(env, "sun/nio/fs/UnixFileStoreAttributes"); + if (clazz == NULL) { + return; + } + attrs_f_frsize = (*env)->GetFieldID(env, clazz, "f_frsize", "J"); + attrs_f_blocks = (*env)->GetFieldID(env, clazz, "f_blocks", "J"); + attrs_f_bfree = (*env)->GetFieldID(env, clazz, "f_bfree", "J"); + attrs_f_bavail = (*env)->GetFieldID(env, clazz, "f_bavail", "J"); + + clazz = (*env)->FindClass(env, "sun/nio/fs/UnixMountEntry"); + if (clazz == NULL) { + return; + } + entry_name = (*env)->GetFieldID(env, clazz, "name", "[B"); + entry_dir = (*env)->GetFieldID(env, clazz, "dir", "[B"); + entry_fstype = (*env)->GetFieldID(env, clazz, "fstype", "[B"); + entry_options = (*env)->GetFieldID(env, clazz, "opts", "[B"); + entry_dev = (*env)->GetFieldID(env, clazz, "dev", "J"); + + /* system calls that might not be available at build time */ + +#if defined(__solaris__) && defined(_LP64) + /* Solaris 64-bit does not have openat64/fstatat64 */ + my_openat64_func = (openat64_func*)dlsym(RTLD_DEFAULT, "openat"); + my_fstatat64_func = (fstatat64_func*)dlsym(RTLD_DEFAULT, "fstatat"); +#else + my_openat64_func = (openat64_func*) dlsym(RTLD_DEFAULT, "openat64"); + my_fstatat64_func = (fstatat64_func*) dlsym(RTLD_DEFAULT, "fstatat64"); +#endif + my_unlinkat_func = (unlinkat_func*) dlsym(RTLD_DEFAULT, "unlinkat"); + my_renameat_func = (renameat_func*) dlsym(RTLD_DEFAULT, "renameat"); + my_futimesat_func = (futimesat_func*) dlsym(RTLD_DEFAULT, "futimesat"); + my_fdopendir_func = (fdopendir_func*) dlsym(RTLD_DEFAULT, "fdopendir"); + +#if defined(FSTATAT64_SYSCALL_AVAILABLE) + /* fstatat64 missing from glibc */ + if (my_fstatat64_func == NULL) + my_fstatat64_func = (fstatat64_func*)&fstatat64_wrapper; +#endif +} + +JNIEXPORT jbyteArray JNICALL +Java_sun_nio_fs_UnixNativeDispatcher_getcwd(JNIEnv* env, jclass this) { + jbyteArray result = NULL; + char buf[PATH_MAX+1]; + + /* EINTR not listed as a possible error */ + char* cwd = getcwd(buf, sizeof(buf)); + if (cwd == NULL) { + throwUnixException(env, errno); + } else { + jsize len = (jsize)strlen(buf); + result = (*env)->NewByteArray(env, len); + if (result != NULL) { + (*env)->SetByteArrayRegion(env, result, 0, len, (jbyte*)buf); + } + } + return result; +} + +JNIEXPORT jbyteArray +Java_sun_nio_fs_UnixNativeDispatcher_strerror(JNIEnv* env, jclass this, jint error) +{ + char* msg; + jsize len; + jbyteArray bytes; + + msg = strerror((int)error); + len = strlen(msg); + bytes = (*env)->NewByteArray(env, len); + if (bytes != NULL) { + (*env)->SetByteArrayRegion(env, bytes, 0, len, (jbyte*)msg); + } + return bytes; +} + +JNIEXPORT jint +Java_sun_nio_fs_UnixNativeDispatcher_dup(JNIEnv* env, jclass this, jint fd) { + + int res = -1; + + RESTARTABLE(dup((int)fd), res); + if (fd == -1) { + throwUnixException(env, errno); + } + return (jint)res; +} + +JNIEXPORT jlong JNICALL +Java_sun_nio_fs_UnixNativeDispatcher_fopen0(JNIEnv* env, jclass this, + jlong pathAddress, jlong modeAddress) +{ + FILE* fp = NULL; + const char* path = (const char*)jlong_to_ptr(pathAddress); + const char* mode = (const char*)jlong_to_ptr(modeAddress); + + do { + fp = fopen(path, mode); + } while (fp == NULL && errno == EINTR); + + if (fp == NULL) { + throwUnixException(env, errno); + } + + return ptr_to_jlong(fp); +} + +JNIEXPORT void JNICALL +Java_sun_nio_fs_UnixNativeDispatcher_fclose(JNIEnv* env, jclass this, jlong stream) +{ + int res; + FILE* fp = jlong_to_ptr(stream); + + do { + res = fclose(fp); + } while (res == EOF && errno == EINTR); + if (res == EOF) { + throwUnixException(env, errno); + } +} + +JNIEXPORT jint JNICALL +Java_sun_nio_fs_UnixNativeDispatcher_open0(JNIEnv* env, jclass this, + jlong pathAddress, jint oflags, jint mode) +{ + jint fd; + const char* path = (const char*)jlong_to_ptr(pathAddress); + + RESTARTABLE(open64(path, (int)oflags, (mode_t)mode), fd); + if (fd == -1) { + throwUnixException(env, errno); + } + return fd; +} + +JNIEXPORT jint JNICALL +Java_sun_nio_fs_UnixNativeDispatcher_openat0(JNIEnv* env, jclass this, jint dfd, + jlong pathAddress, jint oflags, jint mode) +{ + jint fd; + const char* path = (const char*)jlong_to_ptr(pathAddress); + + if (my_openat64_func == NULL) { + JNU_ThrowInternalError(env, "should not reach here"); + return -1; + } + + RESTARTABLE((*my_openat64_func)(dfd, path, (int)oflags, (mode_t)mode), fd); + if (fd == -1) { + throwUnixException(env, errno); + } + return fd; +} + +JNIEXPORT void JNICALL +Java_sun_nio_fs_UnixNativeDispatcher_close(JNIEnv* env, jclass this, jint fd) { + int err; + /* TDB - need to decide if EIO and other errors should cause exception */ + RESTARTABLE(close((int)fd), err); +} + +JNIEXPORT jint JNICALL +Java_sun_nio_fs_UnixNativeDispatcher_read(JNIEnv* env, jclass this, jint fd, + jlong address, jint nbytes) +{ + ssize_t n; + void* bufp = jlong_to_ptr(address); + RESTARTABLE(read((int)fd, bufp, (size_t)nbytes), n); + if (n == -1) { + throwUnixException(env, errno); + } + return (jint)n; +} + +JNIEXPORT jint JNICALL +Java_sun_nio_fs_UnixNativeDispatcher_write(JNIEnv* env, jclass this, jint fd, + jlong address, jint nbytes) +{ + ssize_t n; + void* bufp = jlong_to_ptr(address); + RESTARTABLE(write((int)fd, bufp, (size_t)nbytes), n); + if (n == -1) { + throwUnixException(env, errno); + } + return (jint)n; +} + +/** + * Copy stat64 members into sun.nio.fs.UnixFileAttributes + */ +static void prepAttributes(JNIEnv* env, struct stat64* buf, jobject attrs) { + (*env)->SetIntField(env, attrs, attrs_st_mode, (jint)buf->st_mode); + (*env)->SetLongField(env, attrs, attrs_st_ino, (jlong)buf->st_ino); + (*env)->SetLongField(env, attrs, attrs_st_dev, (jlong)buf->st_dev); + (*env)->SetLongField(env, attrs, attrs_st_rdev, (jlong)buf->st_rdev); + (*env)->SetIntField(env, attrs, attrs_st_nlink, (jint)buf->st_nlink); + (*env)->SetIntField(env, attrs, attrs_st_uid, (jint)buf->st_uid); + (*env)->SetIntField(env, attrs, attrs_st_gid, (jint)buf->st_gid); + (*env)->SetLongField(env, attrs, attrs_st_size, (jlong)buf->st_size); + (*env)->SetLongField(env, attrs, attrs_st_atime, (jlong)buf->st_atime * 1000); + (*env)->SetLongField(env, attrs, attrs_st_mtime, (jlong)buf->st_mtime * 1000); + (*env)->SetLongField(env, attrs, attrs_st_ctime, (jlong)buf->st_ctime * 1000); +} + +JNIEXPORT void JNICALL +Java_sun_nio_fs_UnixNativeDispatcher_stat0(JNIEnv* env, jclass this, + jlong pathAddress, jobject attrs) +{ + int err; + struct stat64 buf; + const char* path = (const char*)jlong_to_ptr(pathAddress); + + RESTARTABLE(stat64(path, &buf), err); + if (err == -1) { + throwUnixException(env, errno); + } else { + prepAttributes(env, &buf, attrs); + } +} + +JNIEXPORT void JNICALL +Java_sun_nio_fs_UnixNativeDispatcher_lstat0(JNIEnv* env, jclass this, + jlong pathAddress, jobject attrs) +{ + int err; + struct stat64 buf; + const char* path = (const char*)jlong_to_ptr(pathAddress); + + RESTARTABLE(lstat64(path, &buf), err); + if (err == -1) { + throwUnixException(env, errno); + } else { + prepAttributes(env, &buf, attrs); + } +} + +JNIEXPORT void JNICALL +Java_sun_nio_fs_UnixNativeDispatcher_fstat(JNIEnv* env, jclass this, jint fd, + jobject attrs) +{ + int err; + struct stat64 buf; + + RESTARTABLE(fstat64((int)fd, &buf), err); + if (err == -1) { + throwUnixException(env, errno); + } else { + prepAttributes(env, &buf, attrs); + } +} + +JNIEXPORT void JNICALL +Java_sun_nio_fs_UnixNativeDispatcher_fstatat0(JNIEnv* env, jclass this, jint dfd, + jlong pathAddress, jint flag, jobject attrs) +{ + int err; + struct stat64 buf; + const char* path = (const char*)jlong_to_ptr(pathAddress); + + if (my_fstatat64_func == NULL) { + JNU_ThrowInternalError(env, "should not reach here"); + return; + } + RESTARTABLE((*my_fstatat64_func)((int)dfd, path, &buf, (int)flag), err); + if (err == -1) { + throwUnixException(env, errno); + } else { + prepAttributes(env, &buf, attrs); + } +} + +JNIEXPORT void JNICALL +Java_sun_nio_fs_UnixNativeDispatcher_chmod0(JNIEnv* env, jclass this, + jlong pathAddress, jint mode) +{ + int err; + const char* path = (const char*)jlong_to_ptr(pathAddress); + + RESTARTABLE(chmod(path, (mode_t)mode), err); + if (err == -1) { + throwUnixException(env, errno); + } +} + +JNIEXPORT void JNICALL +Java_sun_nio_fs_UnixNativeDispatcher_fchmod(JNIEnv* env, jclass this, jint filedes, + jint mode) +{ + int err; + + RESTARTABLE(fchmod((int)filedes, (mode_t)mode), err); + if (err == -1) { + throwUnixException(env, errno); + } +} + + +JNIEXPORT void JNICALL +Java_sun_nio_fs_UnixNativeDispatcher_chown0(JNIEnv* env, jclass this, + jlong pathAddress, jint uid, jint gid) +{ + int err; + const char* path = (const char*)jlong_to_ptr(pathAddress); + + RESTARTABLE(chown(path, (uid_t)uid, (gid_t)gid), err); + if (err == -1) { + throwUnixException(env, errno); + } +} + +JNIEXPORT void JNICALL +Java_sun_nio_fs_UnixNativeDispatcher_lchown0(JNIEnv* env, jclass this, jlong pathAddress, jint uid, jint gid) +{ + int err; + const char* path = (const char*)jlong_to_ptr(pathAddress); + + RESTARTABLE(lchown(path, (uid_t)uid, (gid_t)gid), err); + if (err == -1) { + throwUnixException(env, errno); + } +} + +JNIEXPORT void JNICALL +Java_sun_nio_fs_UnixNativeDispatcher_fchown(JNIEnv* env, jclass this, jint filedes, jint uid, jint gid) +{ + int err; + + RESTARTABLE(fchown(filedes, (uid_t)uid, (gid_t)gid), err); + if (err == -1) { + throwUnixException(env, errno); + } +} + +JNIEXPORT void JNICALL +Java_sun_nio_fs_UnixNativeDispatcher_utimes0(JNIEnv* env, jclass this, + jlong pathAddress, jlong accessTime, jlong modificationTime) +{ + int err; + struct timeval times[2]; + const char* path = (const char*)jlong_to_ptr(pathAddress); + + times[0].tv_sec = accessTime / 1000; + times[0].tv_usec = (accessTime % 1000) * 1000; + + times[1].tv_sec = modificationTime / 1000; + times[1].tv_usec = (modificationTime % 1000) * 1000; + + RESTARTABLE(utimes(path, ×[0]), err); + if (err == -1) { + throwUnixException(env, errno); + } +} + +JNIEXPORT void JNICALL +Java_sun_nio_fs_UnixNativeDispatcher_futimes(JNIEnv* env, jclass this, jint filedes, + jlong accessTime, jlong modificationTime) +{ + struct timeval times[2]; + int err = 0; + + times[0].tv_sec = accessTime / 1000; + times[0].tv_usec = (accessTime % 1000) * 1000; + + times[1].tv_sec = modificationTime / 1000; + times[1].tv_usec = (modificationTime % 1000) * 1000; + + if (my_futimesat_func != NULL) { + RESTARTABLE((*my_futimesat_func)(filedes, NULL, ×[0]), err); + if (err == -1) { + throwUnixException(env, errno); + } + } +} + +JNIEXPORT jlong JNICALL +Java_sun_nio_fs_UnixNativeDispatcher_opendir0(JNIEnv* env, jclass this, + jlong pathAddress) +{ + DIR* dir; + const char* path = (const char*)jlong_to_ptr(pathAddress); + + /* EINTR not listed as a possible error */ + dir = opendir(path); + if (dir == NULL) { + throwUnixException(env, errno); + } + return ptr_to_jlong(dir); +} + +JNIEXPORT jlong JNICALL +Java_sun_nio_fs_UnixNativeDispatcher_fdopendir(JNIEnv* env, jclass this, int dfd) { + DIR* dir; + + if (my_fdopendir_func == NULL) { + JNU_ThrowInternalError(env, "should not reach here"); + return (jlong)-1; + } + + /* EINTR not listed as a possible error */ + dir = (*my_fdopendir_func)((int)dfd); + if (dir == NULL) { + throwUnixException(env, errno); + } + return ptr_to_jlong(dir); +} + +JNIEXPORT void JNICALL +Java_sun_nio_fs_UnixNativeDispatcher_closedir(JNIEnv* env, jclass this, jlong dir) { + int err; + DIR* dirp = jlong_to_ptr(dir); + + RESTARTABLE(closedir(dirp), err); + if (errno == -1) { + throwUnixException(env, errno); + } +} + +JNIEXPORT jbyteArray JNICALL +Java_sun_nio_fs_UnixNativeDispatcher_readdir(JNIEnv* env, jclass this, jlong value) { + char entry[sizeof(struct dirent64) + PATH_MAX + 1]; + struct dirent64* ptr = (struct dirent64*)&entry; + struct dirent64* result; + int res; + DIR* dirp = jlong_to_ptr(value); + + /* EINTR not listed as a possible error */ + /* TDB: reentrant version probably not required here */ + res = readdir64_r(dirp, ptr, &result); + if (res != 0) { + throwUnixException(env, res); + return NULL; + } else { + if (result == NULL) { + return NULL; + } else { + jsize len = strlen(ptr->d_name); + jbyteArray bytes = (*env)->NewByteArray(env, len); + if (bytes != NULL) { + (*env)->SetByteArrayRegion(env, bytes, 0, len, (jbyte*)(ptr->d_name)); + } + return bytes; + } + } +} + +JNIEXPORT void JNICALL +Java_sun_nio_fs_UnixNativeDispatcher_mkdir0(JNIEnv* env, jclass this, + jlong pathAddress, jint mode) +{ + const char* path = (const char*)jlong_to_ptr(pathAddress); + + /* EINTR not listed as a possible error */ + if (mkdir(path, (mode_t)mode) == -1) { + throwUnixException(env, errno); + } +} + +JNIEXPORT void JNICALL +Java_sun_nio_fs_UnixNativeDispatcher_rmdir0(JNIEnv* env, jclass this, + jlong pathAddress) +{ + const char* path = (const char*)jlong_to_ptr(pathAddress); + + /* EINTR not listed as a possible error */ + if (rmdir(path) == -1) { + throwUnixException(env, errno); + } +} + +JNIEXPORT void JNICALL +Java_sun_nio_fs_UnixNativeDispatcher_link0(JNIEnv* env, jclass this, + jlong existingAddress, jlong newAddress) +{ + int err; + const char* existing = (const char*)jlong_to_ptr(existingAddress); + const char* newname = (const char*)jlong_to_ptr(newAddress); + + RESTARTABLE(link(existing, newname), err); + if (err == -1) { + throwUnixException(env, errno); + } +} + + +JNIEXPORT void JNICALL +Java_sun_nio_fs_UnixNativeDispatcher_unlink0(JNIEnv* env, jclass this, + jlong pathAddress) +{ + const char* path = (const char*)jlong_to_ptr(pathAddress); + + /* EINTR not listed as a possible error */ + if (unlink(path) == -1) { + throwUnixException(env, errno); + } +} + +JNIEXPORT void JNICALL +Java_sun_nio_fs_UnixNativeDispatcher_unlinkat0(JNIEnv* env, jclass this, jint dfd, + jlong pathAddress, jint flags) +{ + const char* path = (const char*)jlong_to_ptr(pathAddress); + + if (my_unlinkat_func == NULL) { + JNU_ThrowInternalError(env, "should not reach here"); + return; + } + + /* EINTR not listed as a possible error */ + if ((*my_unlinkat_func)((int)dfd, path, (int)flags) == -1) { + throwUnixException(env, errno); + } +} + +JNIEXPORT void JNICALL +Java_sun_nio_fs_UnixNativeDispatcher_rename0(JNIEnv* env, jclass this, + jlong fromAddress, jlong toAddress) +{ + const char* from = (const char*)jlong_to_ptr(fromAddress); + const char* to = (const char*)jlong_to_ptr(toAddress); + + /* EINTR not listed as a possible error */ + if (rename(from, to) == -1) { + throwUnixException(env, errno); + } +} + +JNIEXPORT void JNICALL +Java_sun_nio_fs_UnixNativeDispatcher_renameat0(JNIEnv* env, jclass this, + jint fromfd, jlong fromAddress, jint tofd, jlong toAddress) +{ + const char* from = (const char*)jlong_to_ptr(fromAddress); + const char* to = (const char*)jlong_to_ptr(toAddress); + + if (my_renameat_func == NULL) { + JNU_ThrowInternalError(env, "should not reach here"); + return; + } + + /* EINTR not listed as a possible error */ + if ((*my_renameat_func)((int)fromfd, from, (int)tofd, to) == -1) { + throwUnixException(env, errno); + } +} + +JNIEXPORT void JNICALL +Java_sun_nio_fs_UnixNativeDispatcher_symlink0(JNIEnv* env, jclass this, + jlong targetAddress, jlong linkAddress) +{ + const char* target = (const char*)jlong_to_ptr(targetAddress); + const char* link = (const char*)jlong_to_ptr(linkAddress); + + /* EINTR not listed as a possible error */ + if (symlink(target, link) == -1) { + throwUnixException(env, errno); + } +} + +JNIEXPORT jbyteArray JNICALL +Java_sun_nio_fs_UnixNativeDispatcher_readlink0(JNIEnv* env, jclass this, + jlong pathAddress) +{ + jbyteArray result = NULL; + char target[PATH_MAX+1]; + const char* path = (const char*)jlong_to_ptr(pathAddress); + + /* EINTR not listed as a possible error */ + int n = readlink(path, target, sizeof(target)); + if (n == -1) { + throwUnixException(env, errno); + } else { + jsize len; + if (n == sizeof(target)) { + n--; + } + target[n] = '\0'; + len = (jsize)strlen(target); + result = (*env)->NewByteArray(env, len); + if (result != NULL) { + (*env)->SetByteArrayRegion(env, result, 0, len, (jbyte*)target); + } + } + return result; +} + +JNIEXPORT jbyteArray JNICALL +Java_sun_nio_fs_UnixNativeDispatcher_realpath0(JNIEnv* env, jclass this, + jlong pathAddress) +{ + jbyteArray result = NULL; + char resolved[PATH_MAX+1]; + const char* path = (const char*)jlong_to_ptr(pathAddress); + + /* EINTR not listed as a possible error */ + if (realpath(path, resolved) == NULL) { + throwUnixException(env, errno); + } else { + jsize len = (jsize)strlen(resolved); + result = (*env)->NewByteArray(env, len); + if (result != NULL) { + (*env)->SetByteArrayRegion(env, result, 0, len, (jbyte*)resolved); + } + } + return result; +} + +JNIEXPORT void JNICALL +Java_sun_nio_fs_UnixNativeDispatcher_access0(JNIEnv* env, jclass this, + jlong pathAddress, jint amode) +{ + int err; + const char* path = (const char*)jlong_to_ptr(pathAddress); + + RESTARTABLE(access(path, (int)amode), err); + if (err == -1) { + throwUnixException(env, errno); + } +} + +JNIEXPORT void JNICALL +Java_sun_nio_fs_UnixNativeDispatcher_statvfs0(JNIEnv* env, jclass this, + jlong pathAddress, jobject attrs) +{ + int err; + struct statvfs64 buf; + const char* path = (const char*)jlong_to_ptr(pathAddress); + + + RESTARTABLE(statvfs64(path, &buf), err); + if (err == -1) { + throwUnixException(env, errno); + } else { + (*env)->SetLongField(env, attrs, attrs_f_frsize, long_to_jlong(buf.f_frsize)); + (*env)->SetLongField(env, attrs, attrs_f_blocks, long_to_jlong(buf.f_blocks)); + (*env)->SetLongField(env, attrs, attrs_f_bfree, long_to_jlong(buf.f_bfree)); + (*env)->SetLongField(env, attrs, attrs_f_bavail, long_to_jlong(buf.f_bavail)); + } +} + +JNIEXPORT jlong JNICALL +Java_sun_nio_fs_UnixNativeDispatcher_pathconf0(JNIEnv* env, jclass this, + jlong pathAddress, jint name) +{ + long err; + const char* path = (const char*)jlong_to_ptr(pathAddress); + + err = pathconf(path, (int)name); + if (err == -1) { + throwUnixException(env, errno); + } + return (jlong)err; +} + +JNIEXPORT jlong JNICALL +Java_sun_nio_fs_UnixNativeDispatcher_fpathconf(JNIEnv* env, jclass this, + jint fd, jint name) +{ + long err; + + err = fpathconf((int)fd, (int)name); + if (err == -1) { + throwUnixException(env, errno); + } + return (jlong)err; +} + +JNIEXPORT void JNICALL +Java_sun_nio_fs_UnixNativeDispatcher_mknod0(JNIEnv* env, jclass this, + jlong pathAddress, jint mode, jlong dev) +{ + int err; + const char* path = (const char*)jlong_to_ptr(pathAddress); + + RESTARTABLE(mknod(path, (mode_t)mode, (dev_t)dev), err); + if (err == -1) { + throwUnixException(env, errno); + } +} + +JNIEXPORT jbyteArray JNICALL +Java_sun_nio_fs_UnixNativeDispatcher_getpwuid(JNIEnv* env, jclass this, jint uid) +{ + jbyteArray result = NULL; + int buflen; + + buflen = (int)sysconf(_SC_GETPW_R_SIZE_MAX); + if (buflen == -1) { + throwUnixException(env, errno); + } else { + char* pwbuf = (char*)malloc(buflen); + if (pwbuf == NULL) { + JNU_ThrowOutOfMemoryError(env, "native heap"); + } else { + struct passwd pwent; + struct passwd* p; + int res = 0; + +#ifdef __solaris__ + p = getpwuid_r((uid_t)uid, &pwent, pwbuf, (size_t)buflen); +#else + res = getpwuid_r((uid_t)uid, &pwent, pwbuf, (size_t)buflen, &p); +#endif + + if (res != 0 || p == NULL || p->pw_name == NULL || *(p->pw_name) == '\0') { + throwUnixException(env, errno); + } else { + jsize len = strlen(p->pw_name); + result = (*env)->NewByteArray(env, len); + if (result != NULL) { + (*env)->SetByteArrayRegion(env, result, 0, len, (jbyte*)(p->pw_name)); + } + } + free(pwbuf); + } + } + return result; +} + + +JNIEXPORT jbyteArray JNICALL +Java_sun_nio_fs_UnixNativeDispatcher_getgrgid(JNIEnv* env, jclass this, jint gid) +{ + jbyteArray result = NULL; + int buflen; + + buflen = (int)sysconf(_SC_GETGR_R_SIZE_MAX); + if (buflen == -1) { + throwUnixException(env, errno); + } else { + char* grbuf = (char*)malloc(buflen); + if (grbuf == NULL) { + JNU_ThrowOutOfMemoryError(env, "native heap"); + } else { + struct group grent; + struct group* g; + int res = 0; + +#ifdef __solaris__ + g = getgrgid_r((gid_t)gid, &grent, grbuf, (size_t)buflen); +#else + res = getgrgid_r((gid_t)gid, &grent, grbuf, (size_t)buflen, &g); +#endif + if (res != 0 || g == NULL || g->gr_name == NULL || *(g->gr_name) == '\0') { + throwUnixException(env, errno); + } else { + jsize len = strlen(g->gr_name); + result = (*env)->NewByteArray(env, len); + if (result != NULL) { + (*env)->SetByteArrayRegion(env, result, 0, len, (jbyte*)(g->gr_name)); + } + } + free(grbuf); + } + } + return result; +} + +JNIEXPORT jint JNICALL +Java_sun_nio_fs_UnixNativeDispatcher_getpwnam0(JNIEnv* env, jclass this, + jlong nameAddress) +{ + jint uid = -1; + int buflen; + char* pwbuf; + struct passwd pwent; + struct passwd* p; + int res = 0; + const char* name = (const char*)jlong_to_ptr(nameAddress); + + buflen = (int)sysconf(_SC_GETPW_R_SIZE_MAX); + if (buflen == -1) { + throwUnixException(env, errno); + return -1; + } + pwbuf = (char*)malloc(buflen); + if (pwbuf == NULL) { + JNU_ThrowOutOfMemoryError(env, "native heap"); + return -1; + } + +#ifdef __solaris__ + p = getpwnam_r(name, &pwent, pwbuf, (size_t)buflen); +#else + res = getpwnam_r(name, &pwent, pwbuf, (size_t)buflen, &p); +#endif + + if (res != 0 || p == NULL || p->pw_name == NULL || *(p->pw_name) == '\0') { + /* not found or error */ + } else { + uid = p->pw_uid; + } + + free(pwbuf); + + return uid; +} + +JNIEXPORT jint JNICALL +Java_sun_nio_fs_UnixNativeDispatcher_getgrnam0(JNIEnv* env, jclass this, + jlong nameAddress) +{ + jint gid = -1; + int buflen; + char* grbuf; + struct group grent; + struct group* g; + int res = 0; + const char* name = (const char*)jlong_to_ptr(nameAddress); + + buflen = (int)sysconf(_SC_GETGR_R_SIZE_MAX); + if (buflen == -1) { + throwUnixException(env, errno); + return -1; + } + grbuf = (char*)malloc(buflen); + if (grbuf == NULL) { + JNU_ThrowOutOfMemoryError(env, "native heap"); + return -1; + } + +#ifdef __solaris__ + g = getgrnam_r(name, &grent, grbuf, (size_t)buflen); +#else + res = getgrnam_r(name, &grent, grbuf, (size_t)buflen, &g); +#endif + + if (res != 0 || g == NULL || g->gr_name == NULL || *(g->gr_name) == '\0') { + /* not found or error */ + } else { + gid = g->gr_gid; + } + free(grbuf); + + return gid; +} + +JNIEXPORT jint JNICALL +Java_sun_nio_fs_UnixNativeDispatcher_getextmntent(JNIEnv* env, jclass this, + jlong value, jobject entry) +{ +#ifdef __solaris__ + struct extmnttab ent; +#else + struct mntent ent; + char buf[1024]; + int buflen = sizeof(buf); + struct mntent* m; +#endif + FILE* fp = jlong_to_ptr(value); + jsize len; + jbyteArray bytes; + char* name; + char* dir; + char* fstype; + char* options; + dev_t dev; + +#ifdef __solaris__ + if (getextmntent(fp, &ent, 0)) + return -1; + name = ent.mnt_special; + dir = ent.mnt_mountp; + fstype = ent.mnt_fstype; + options = ent.mnt_mntopts; + dev = makedev(ent.mnt_major, ent.mnt_minor); + if (dev == NODEV) { + /* possible bug on Solaris 8 and 9 */ + throwUnixException(env, errno); + return -1; + } +#else + m = getmntent_r(fp, &ent, (char*)&buf, buflen); + if (m == NULL) + return -1; + name = m->mnt_fsname; + dir = m->mnt_dir; + fstype = m->mnt_type; + options = m->mnt_opts; + dev = 0; +#endif + + len = strlen(name); + bytes = (*env)->NewByteArray(env, len); + if (bytes == NULL) + return -1; + (*env)->SetByteArrayRegion(env, bytes, 0, len, (jbyte*)name); + (*env)->SetObjectField(env, entry, entry_name, bytes); + + len = strlen(dir); + bytes = (*env)->NewByteArray(env, len); + if (bytes == NULL) + return -1; + (*env)->SetByteArrayRegion(env, bytes, 0, len, (jbyte*)dir); + (*env)->SetObjectField(env, entry, entry_dir, bytes); + + len = strlen(fstype); + bytes = (*env)->NewByteArray(env, len); + if (bytes == NULL) + return -1; + (*env)->SetByteArrayRegion(env, bytes, 0, len, (jbyte*)fstype); + (*env)->SetObjectField(env, entry, entry_fstype, bytes); + + len = strlen(options); + bytes = (*env)->NewByteArray(env, len); + if (bytes == NULL) + return -1; + (*env)->SetByteArrayRegion(env, bytes, 0, len, (jbyte*)options); + (*env)->SetObjectField(env, entry, entry_options, bytes); + + if (dev != 0) + (*env)->SetLongField(env, entry, entry_dev, (jlong)dev); + + return 0; +} diff --git a/src/solaris/native/sun/nio/fs/genSolarisConstants.c b/src/solaris/native/sun/nio/fs/genSolarisConstants.c new file mode 100644 index 0000000000000000000000000000000000000000..182449e4ab5b389510eecfa9c806f25182e778d5 --- /dev/null +++ b/src/solaris/native/sun/nio/fs/genSolarisConstants.c @@ -0,0 +1,105 @@ +/* + * Copyright 2008-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. + */ + +#include <stdio.h> +#include <errno.h> +#include <unistd.h> +#include <sys/acl.h> +#include <sys/fcntl.h> +#include <sys/stat.h> + +/** + * Generates sun.nio.fs.SolarisConstants + */ + +static void out(char* s) { + printf("%s\n", s); +} + +static void emit(char* name, int value) { + printf(" static final int %s = %d;\n", name, value); +} + +static void emitX(char* name, int value) { + printf(" static final int %s = 0x%x;\n", name, value); +} + +#define DEF(X) emit(#X, X); +#define DEFX(X) emitX(#X, X); + +int main(int argc, const char* argv[]) { + out("// AUTOMATICALLY GENERATED FILE - DO NOT EDIT "); + out("package sun.nio.fs; "); + out("class SolarisConstants { "); + out(" private SolarisConstants() { } "); + + // extended attributes + DEFX(O_XATTR); + DEF(_PC_XATTR_ENABLED); + + // ACL configuration + DEF(_PC_ACL_ENABLED); + DEFX(_ACL_ACE_ENABLED); + + // ACL commands + DEFX(ACE_GETACL); + DEFX(ACE_SETACL); + + // ACL mask/flags/types + emitX("ACE_ACCESS_ALLOWED_ACE_TYPE", 0x0000); + emitX("ACE_ACCESS_DENIED_ACE_TYPE", 0x0001); + emitX("ACE_SYSTEM_AUDIT_ACE_TYPE", 0x0002); + emitX("ACE_SYSTEM_ALARM_ACE_TYPE", 0x0003); + emitX("ACE_READ_DATA", 0x00000001); + emitX("ACE_LIST_DIRECTORY", 0x00000001); + emitX("ACE_WRITE_DATA", 0x00000002); + emitX("ACE_ADD_FILE", 0x00000002); + emitX("ACE_APPEND_DATA", 0x00000004); + emitX("ACE_ADD_SUBDIRECTORY", 0x00000004); + emitX("ACE_READ_NAMED_ATTRS", 0x00000008); + emitX("ACE_WRITE_NAMED_ATTRS", 0x00000010); + emitX("ACE_EXECUTE", 0x00000020); + emitX("ACE_DELETE_CHILD", 0x00000040); + emitX("ACE_READ_ATTRIBUTES", 0x00000080); + emitX("ACE_WRITE_ATTRIBUTES", 0x00000100); + emitX("ACE_DELETE", 0x00010000); + emitX("ACE_READ_ACL", 0x00020000); + emitX("ACE_WRITE_ACL", 0x00040000); + emitX("ACE_WRITE_OWNER", 0x00080000); + emitX("ACE_SYNCHRONIZE", 0x00100000); + emitX("ACE_FILE_INHERIT_ACE", 0x0001); + emitX("ACE_DIRECTORY_INHERIT_ACE", 0x0002); + emitX("ACE_NO_PROPAGATE_INHERIT_ACE", 0x0004); + emitX("ACE_INHERIT_ONLY_ACE", 0x0008); + emitX("ACE_SUCCESSFUL_ACCESS_ACE_FLAG", 0x0010); + emitX("ACE_FAILED_ACCESS_ACE_FLAG", 0x0020); + emitX("ACE_IDENTIFIER_GROUP", 0x0040); + emitX("ACE_OWNER", 0x1000); + emitX("ACE_GROUP", 0x2000); + emitX("ACE_EVERYONE", 0x4000); + + out("} "); + return 0; +} diff --git a/src/solaris/native/sun/nio/fs/genUnixConstants.c b/src/solaris/native/sun/nio/fs/genUnixConstants.c new file mode 100644 index 0000000000000000000000000000000000000000..c01f641a690e1418c29b51bd2f0cf0a3abebe796 --- /dev/null +++ b/src/solaris/native/sun/nio/fs/genUnixConstants.c @@ -0,0 +1,125 @@ +/* + * Copyright 2008-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. + */ + +#include <stdio.h> +#include <errno.h> +#include <unistd.h> +#include <sys/fcntl.h> +#include <sys/stat.h> + +/** + * Generates sun.nio.fs.UnixConstants + */ + +static void out(char* s) { + printf("%s\n", s); +} + +static void emit(char* name, int value) { + printf(" static final int %s = %d;\n", name, value); +} + +static void emitX(char* name, int value) { + printf(" static final int %s = 0x%x;\n", name, value); +} + +#define DEF(X) emit(#X, X); +#define DEFX(X) emitX(#X, X); + +int main(int argc, const char* argv[]) { + out("// AUTOMATICALLY GENERATED FILE - DO NOT EDIT "); + out("package sun.nio.fs; "); + out("class UnixConstants { "); + out(" private UnixConstants() { } "); + + // open flags + DEF(O_RDONLY); + DEF(O_WRONLY); + DEF(O_RDWR); + DEFX(O_APPEND); + DEFX(O_CREAT); + DEFX(O_EXCL); + DEFX(O_TRUNC); + DEFX(O_SYNC); + DEFX(O_DSYNC); + DEFX(O_NOFOLLOW); + + // flags used with openat/unlinkat/etc. +#ifdef __solaris__ + DEFX(AT_SYMLINK_NOFOLLOW); + DEFX(AT_REMOVEDIR); +#endif +#ifdef __linux__ + emitX("AT_SYMLINK_NOFOLLOW", 0x100); // since 2.6.16 + emitX("AT_REMOVEDIR", 0x200); +#endif + + // mode masks + emitX("S_IAMB", + (S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IWGRP|S_IXGRP|S_IROTH|S_IWOTH|S_IXOTH)); + DEF(S_IRUSR); + DEF(S_IWUSR); + DEF(S_IXUSR); + DEF(S_IRGRP); + DEF(S_IWGRP); + DEF(S_IXGRP); + DEF(S_IROTH); + DEF(S_IWOTH); + DEF(S_IXOTH); + DEFX(S_IFMT); + DEFX(S_IFREG); + DEFX(S_IFDIR); + DEFX(S_IFLNK); + DEFX(S_IFCHR); + DEFX(S_IFBLK); + DEFX(S_IFIFO); + + // access modes + DEF(R_OK); + DEF(W_OK); + DEF(X_OK); + DEF(F_OK); + + // errors + DEF(ENOENT); + DEF(EACCES); + DEF(EEXIST); + DEF(ENOTDIR); + DEF(EINVAL); + DEF(EXDEV); + DEF(EISDIR); + DEF(ENOTEMPTY); + DEF(ENOSPC); + DEF(EAGAIN); + DEF(ENOSYS); + DEF(ELOOP); + DEF(EROFS); + DEF(ENODATA); + DEF(ERANGE); + + out("} "); + + return 0; +} diff --git a/src/windows/classes/sun/awt/shell/Win32ShellFolder2.java b/src/windows/classes/sun/awt/shell/Win32ShellFolder2.java index 418dc8f59dbb83417600c6f6ff5a1702d2beeb11..bc81b80e7931e85842640bb1965f25cd4d454a40 100644 --- a/src/windows/classes/sun/awt/shell/Win32ShellFolder2.java +++ b/src/windows/classes/sun/awt/shell/Win32ShellFolder2.java @@ -32,6 +32,7 @@ import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.util.*; +import java.util.concurrent.*; import javax.swing.SwingConstants; // NOTE: This class supersedes Win32ShellFolder, which was removed from @@ -184,15 +185,20 @@ final class Win32ShellFolder2 extends ShellFolder { boolean disposed; public void dispose() { if (disposed) return; - if (relativePIDL != 0) { - releasePIDL(relativePIDL); - } - if (absolutePIDL != 0) { - releasePIDL(absolutePIDL); - } - if (pIShellFolder != 0) { - releaseIShellFolder(pIShellFolder); - } + ShellFolder.getInvoker().invoke(new Callable<Void>() { + public Void call() throws Exception { + if (relativePIDL != 0) { + releasePIDL(relativePIDL); + } + if (absolutePIDL != 0) { + releasePIDL(absolutePIDL); + } + if (pIShellFolder != 0) { + releaseIShellFolder(pIShellFolder); + } + return null; + } + }); disposed = true; } } @@ -218,50 +224,59 @@ final class Win32ShellFolder2 extends ShellFolder { */ private boolean isPersonal; + private static String composePathForCsidl(int csidl) throws IOException { + String path = getFileSystemPath(csidl); + return path == null + ? ("ShellFolder: 0x" + Integer.toHexString(csidl)) + : path; + } /** * Create a system special shell folder, such as the * desktop or Network Neighborhood. */ - Win32ShellFolder2(int csidl) throws IOException { + Win32ShellFolder2(final int csidl) throws IOException { // Desktop is parent of DRIVES and NETWORK, not necessarily // other special shell folders. - super(null, - (getFileSystemPath(csidl) == null) - ? ("ShellFolder: 0x"+Integer.toHexString(csidl)) : getFileSystemPath(csidl)); - if (csidl == DESKTOP) { - initDesktop(); - } else { - initSpecial(getDesktop().getIShellFolder(), csidl); - // At this point, the native method initSpecial() has set our relativePIDL - // relative to the Desktop, which may not be our immediate parent. We need - // to traverse this ID list and break it into a chain of shell folders from - // the top, with each one having an immediate parent and a relativePIDL - // relative to that parent. - long pIDL = disposer.relativePIDL; - parent = getDesktop(); - while (pIDL != 0) { - // Get a child pidl relative to 'parent' - long childPIDL = copyFirstPIDLEntry(pIDL); - if (childPIDL != 0) { - // Get a handle to the the rest of the ID list - // i,e, parent's grandchilren and down - pIDL = getNextPIDLEntry(pIDL); - if (pIDL != 0) { - // Now we know that parent isn't immediate to 'this' because it - // has a continued ID list. Create a shell folder for this child - // pidl and make it the new 'parent'. - parent = new Win32ShellFolder2((Win32ShellFolder2)parent, childPIDL); - } else { - // No grandchildren means we have arrived at the parent of 'this', - // and childPIDL is directly relative to parent. - disposer.relativePIDL = childPIDL; - } + super(null, composePathForCsidl(csidl)); + ShellFolder.getInvoker().invoke(new Callable<Void>() { + public Void call() throws Exception { + if (csidl == DESKTOP) { + initDesktop(); } else { - break; + initSpecial(getDesktop().getIShellFolder(), csidl); + // At this point, the native method initSpecial() has set our relativePIDL + // relative to the Desktop, which may not be our immediate parent. We need + // to traverse this ID list and break it into a chain of shell folders from + // the top, with each one having an immediate parent and a relativePIDL + // relative to that parent. + long pIDL = disposer.relativePIDL; + parent = getDesktop(); + while (pIDL != 0) { + // Get a child pidl relative to 'parent' + long childPIDL = copyFirstPIDLEntry(pIDL); + if (childPIDL != 0) { + // Get a handle to the the rest of the ID list + // i,e, parent's grandchilren and down + pIDL = getNextPIDLEntry(pIDL); + if (pIDL != 0) { + // Now we know that parent isn't immediate to 'this' because it + // has a continued ID list. Create a shell folder for this child + // pidl and make it the new 'parent'. + parent = new Win32ShellFolder2((Win32ShellFolder2) parent, childPIDL); + } else { + // No grandchildren means we have arrived at the parent of 'this', + // and childPIDL is directly relative to parent. + disposer.relativePIDL = childPIDL; + } + } else { + break; + } + } } + return null; } - } + }); sun.java2d.Disposer.addRecord(this, disposer); } @@ -281,17 +296,26 @@ final class Win32ShellFolder2 extends ShellFolder { /** * Creates a shell folder with a parent and relative PIDL */ - Win32ShellFolder2(Win32ShellFolder2 parent, long relativePIDL) { - super(parent, getFileSystemPath(parent.getIShellFolder(), relativePIDL)); + Win32ShellFolder2(final Win32ShellFolder2 parent, final long relativePIDL) { + super(parent, + ShellFolder.getInvoker().invoke(new Callable<String>() { + public String call() throws Exception { + return getFileSystemPath(parent.getIShellFolder(), relativePIDL); + } + }) + ); this.disposer.relativePIDL = relativePIDL; getAbsolutePath(); sun.java2d.Disposer.addRecord(this, disposer); } // Initializes the desktop shell folder + // NOTE: this method uses COM and must be called on the 'COM thread'. See ComInvoker for the details private native void initDesktop(); + // Initializes a special, non-file system shell folder // from one of the above constants + // NOTE: this method uses COM and must be called on the 'COM thread'. See ComInvoker for the details private native void initSpecial(long desktopIShellFolder, int csidl); /** Marks this folder as being the My Documents (Personal) folder */ @@ -311,26 +335,30 @@ final class Win32ShellFolder2 extends ShellFolder { * drive (normally "C:\"). */ protected Object writeReplace() throws java.io.ObjectStreamException { - if (isFileSystem()) { - return new File(getPath()); - } else { - Win32ShellFolder2 drives = Win32ShellFolderManager2.getDrives(); - if (drives != null) { - File[] driveRoots = drives.listFiles(); - if (driveRoots != null) { - for (int i = 0; i < driveRoots.length; i++) { - if (driveRoots[i] instanceof Win32ShellFolder2) { - Win32ShellFolder2 sf = (Win32ShellFolder2)driveRoots[i]; - if (sf.isFileSystem() && !sf.hasAttribute(ATTRIB_REMOVABLE)) { - return new File(sf.getPath()); + return ShellFolder.getInvoker().invoke(new Callable<File>() { + public File call() throws Exception { + if (isFileSystem()) { + return new File(getPath()); + } else { + Win32ShellFolder2 drives = Win32ShellFolderManager2.getDrives(); + if (drives != null) { + File[] driveRoots = drives.listFiles(); + if (driveRoots != null) { + for (int i = 0; i < driveRoots.length; i++) { + if (driveRoots[i] instanceof Win32ShellFolder2) { + Win32ShellFolder2 sf = (Win32ShellFolder2) driveRoots[i]; + if (sf.isFileSystem() && !sf.hasAttribute(ATTRIB_REMOVABLE)) { + return new File(sf.getPath()); + } + } } } } + // Ouch, we have no hard drives. Return something "valid" anyway. + return new File("C:\\"); } } - // Ouch, we have no hard drives. Return something "valid" anyway. - return new File("C:\\"); - } + }); } @@ -364,6 +392,7 @@ final class Win32ShellFolder2 extends ShellFolder { static native void releasePIDL(long pIDL); // Release an IShellFolder object + // NOTE: this method uses COM and must be called on the 'COM thread'. See ComInvoker for the details private static native void releaseIShellFolder(long pIShellFolder); /** @@ -371,18 +400,28 @@ final class Win32ShellFolder2 extends ShellFolder { */ public long getIShellFolder() { if (disposer.pIShellFolder == 0) { - assert(isDirectory()); - assert(parent != null); - long parentIShellFolder = getParentIShellFolder(); - if (parentIShellFolder == 0) { - throw new InternalError("Parent IShellFolder was null for " + getAbsolutePath()); - } - // We are a directory with a parent and a relative PIDL. - // We want to bind to the parent so we get an IShellFolder instance associated with us. - disposer.pIShellFolder = bindToObject(parentIShellFolder, disposer.relativePIDL); - if (disposer.pIShellFolder == 0) { - throw new InternalError("Unable to bind " + getAbsolutePath() + " to parent"); - } + disposer.pIShellFolder = + ShellFolder.getInvoker().invoke(new Callable<Long>() { + public Long call() throws Exception { + assert(isDirectory()); + assert(parent != null); + long parentIShellFolder = getParentIShellFolder(); + if (parentIShellFolder == 0) { + throw new InternalError("Parent IShellFolder was null for " + + getAbsolutePath()); + } + // We are a directory with a parent and a relative PIDL. + // We want to bind to the parent so we get an + // IShellFolder instance associated with us. + long pIShellFolder = bindToObject(parentIShellFolder, + disposer.relativePIDL); + if (pIShellFolder == 0) { + throw new InternalError("Unable to bind " + + getAbsolutePath() + " to parent"); + } + return pIShellFolder; + } + }); } return disposer.pIShellFolder; } @@ -472,24 +511,42 @@ final class Win32ShellFolder2 extends ShellFolder { return false; } - private static boolean pidlsEqual(long pIShellFolder, long pidl1, long pidl2) { - return (compareIDs(pIShellFolder, pidl1, pidl2) == 0); + private static boolean pidlsEqual(final long pIShellFolder, final long pidl1, final long pidl2) { + return ShellFolder.getInvoker().invoke(new Callable<Boolean>() { + public Boolean call() throws Exception { + return (compareIDs(pIShellFolder, pidl1, pidl2) == 0); + } + }); } + + // NOTE: this method uses COM and must be called on the 'COM thread'. See ComInvoker for the details private static native int compareIDs(long pParentIShellFolder, long pidl1, long pidl2); + private Boolean cachedIsFileSystem; + /** * @return Whether this is a file system shell folder */ - public boolean isFileSystem() { - return hasAttribute(ATTRIB_FILESYSTEM); + public synchronized boolean isFileSystem() { + if (cachedIsFileSystem == null) { + cachedIsFileSystem = hasAttribute(ATTRIB_FILESYSTEM); + } + + return cachedIsFileSystem; } /** * Return whether the given attribute flag is set for this object */ - public boolean hasAttribute(int attribute) { - // Caching at this point doesn't seem to be cost efficient - return (getAttributes0(getParentIShellFolder(), getRelativePIDL(), attribute) & attribute) != 0; + public boolean hasAttribute(final int attribute) { + return ShellFolder.getInvoker().invoke(new Callable<Boolean>() { + public Boolean call() throws Exception { + // Caching at this point doesn't seem to be cost efficient + return (getAttributes0(getParentIShellFolder(), + getRelativePIDL(), attribute) + & attribute) != 0; + } + }); } /** @@ -498,26 +555,42 @@ final class Win32ShellFolder2 extends ShellFolder { * Could plausibly be used for attribute caching but have to be * very careful not to touch network drives and file system roots * with a full attrsMask + * NOTE: this method uses COM and must be called on the 'COM thread'. See ComInvoker for the details */ + private static native int getAttributes0(long pParentIShellFolder, long pIDL, int attrsMask); // Return the path to the underlying file system object - private static String getFileSystemPath(long parentIShellFolder, long relativePIDL) { - int linkedFolder = ATTRIB_LINK | ATTRIB_FOLDER; - if (parentIShellFolder == Win32ShellFolderManager2.getNetwork().getIShellFolder() && - getAttributes0(parentIShellFolder, relativePIDL, linkedFolder) == linkedFolder) { - - String s = - getFileSystemPath(Win32ShellFolderManager2.getDesktop().getIShellFolder(), - getLinkLocation(parentIShellFolder, relativePIDL, false)); - if (s != null && s.startsWith("\\\\")) { - return s; + private static String getFileSystemPath(final long parentIShellFolder, final long relativePIDL) { + return ShellFolder.getInvoker().invoke(new Callable<String>() { + public String call() throws Exception { + int linkedFolder = ATTRIB_LINK | ATTRIB_FOLDER; + if (parentIShellFolder == Win32ShellFolderManager2.getNetwork().getIShellFolder() && + getAttributes0(parentIShellFolder, relativePIDL, linkedFolder) == linkedFolder) { + + String s = + getFileSystemPath(Win32ShellFolderManager2.getDesktop().getIShellFolder(), + getLinkLocation(parentIShellFolder, relativePIDL, false)); + if (s != null && s.startsWith("\\\\")) { + return s; + } + } + return getDisplayNameOf(parentIShellFolder, relativePIDL, SHGDN_FORPARSING); } - } - return getDisplayNameOf(parentIShellFolder, relativePIDL, SHGDN_NORMAL | SHGDN_FORPARSING); + }); } + // Needs to be accessible to Win32ShellFolderManager2 - static native String getFileSystemPath(int csidl) throws IOException; + static String getFileSystemPath(final int csidl) throws IOException { + return ShellFolder.getInvoker().invoke(new Callable<String>() { + public String call() throws Exception { + return getFileSystemPath0(csidl); + } + }); + } + + // NOTE: this method uses COM and must be called on the 'COM thread'. See ComInvoker for the details + private static native String getFileSystemPath0(int csidl) throws IOException; // Return whether the path is a network root. // Path is assumed to be non-null @@ -557,24 +630,33 @@ final class Win32ShellFolder2 extends ShellFolder { */ // Returns an IEnumIDList interface for an IShellFolder. The value // returned must be released using releaseEnumObjects(). - private long getEnumObjects(long pIShellFolder, boolean includeHiddenFiles) { - boolean isDesktop = (disposer.pIShellFolder == getDesktopIShellFolder()); - return getEnumObjects(disposer.pIShellFolder, isDesktop, includeHiddenFiles); + private long getEnumObjects(long pIShellFolder, final boolean includeHiddenFiles) { + final boolean isDesktop = (disposer.pIShellFolder == getDesktopIShellFolder()); + return ShellFolder.getInvoker().invoke(new Callable<Long>() { + public Long call() throws Exception { + return getEnumObjects(disposer.pIShellFolder, isDesktop, includeHiddenFiles); + } + }); } + // Returns an IEnumIDList interface for an IShellFolder. The value // returned must be released using releaseEnumObjects(). + // NOTE: this method uses COM and must be called on the 'COM thread'. See ComInvoker for the details private native long getEnumObjects(long pIShellFolder, boolean isDesktop, boolean includeHiddenFiles); // Returns the next sequential child as a relative PIDL // from an IEnumIDList interface. The value returned must // be released using releasePIDL(). + // NOTE: this method uses COM and must be called on the 'COM thread'. See ComInvoker for the details private native long getNextChild(long pEnumObjects); // Releases the IEnumIDList interface + // NOTE: this method uses COM and must be called on the 'COM thread'. See ComInvoker for the details private native void releaseEnumObjects(long pEnumObjects); // Returns the IShellFolder of a child from a parent IShellFolder // and a relative PIDL. The value returned must be released // using releaseIShellFolder(). + // NOTE: this method uses COM and must be called on the 'COM thread'. See ComInvoker for the details private static native long bindToObject(long parentIShellFolder, long pIDL); /** @@ -582,60 +664,64 @@ final class Win32ShellFolder2 extends ShellFolder { * object. The array will be empty if the folder is empty. Returns * <code>null</code> if this shellfolder does not denote a directory. */ - public File[] listFiles(boolean includeHiddenFiles) { + public File[] listFiles(final boolean includeHiddenFiles) { SecurityManager security = System.getSecurityManager(); if (security != null) { security.checkRead(getPath()); } - if (!isDirectory()) { - return null; - } - // Links to directories are not directories and cannot be parents. - // This does not apply to folders in My Network Places (NetHood) - // because they are both links and real directories! - if (isLink() && !hasAttribute(ATTRIB_FOLDER)) { - return new File[0]; - } - Win32ShellFolder2 desktop = Win32ShellFolderManager2.getDesktop(); - Win32ShellFolder2 personal = Win32ShellFolderManager2.getPersonal(); - - // If we are a directory, we have a parent and (at least) a - // relative PIDL. We must first ensure we are bound to the - // parent so we have an IShellFolder to query. - long pIShellFolder = getIShellFolder(); - // Now we can enumerate the objects in this folder. - ArrayList<Win32ShellFolder2> list = new ArrayList<Win32ShellFolder2>(); - long pEnumObjects = getEnumObjects(pIShellFolder, includeHiddenFiles); - if (pEnumObjects != 0) { - long childPIDL; - int testedAttrs = ATTRIB_FILESYSTEM | ATTRIB_FILESYSANCESTOR; - do { - if (Thread.currentThread().isInterrupted()) { - return new File[0]; + return ShellFolder.getInvoker().invoke(new Callable<File[]>() { + public File[] call() throws Exception { + if (!isDirectory()) { + return null; } - childPIDL = getNextChild(pEnumObjects); - boolean releasePIDL = true; - if (childPIDL != 0 && - (getAttributes0(pIShellFolder, childPIDL, testedAttrs) & testedAttrs) != 0) { - Win32ShellFolder2 childFolder = null; - if (this.equals(desktop) - && personal != null - && pidlsEqual(pIShellFolder, childPIDL, personal.disposer.relativePIDL)) { - childFolder = personal; - } else { - childFolder = new Win32ShellFolder2(this, childPIDL); - releasePIDL = false; - } - list.add(childFolder); + // Links to directories are not directories and cannot be parents. + // This does not apply to folders in My Network Places (NetHood) + // because they are both links and real directories! + if (isLink() && !hasAttribute(ATTRIB_FOLDER)) { + return new File[0]; } - if (releasePIDL) { - releasePIDL(childPIDL); + + Win32ShellFolder2 desktop = Win32ShellFolderManager2.getDesktop(); + Win32ShellFolder2 personal = Win32ShellFolderManager2.getPersonal(); + + // If we are a directory, we have a parent and (at least) a + // relative PIDL. We must first ensure we are bound to the + // parent so we have an IShellFolder to query. + long pIShellFolder = getIShellFolder(); + // Now we can enumerate the objects in this folder. + ArrayList<Win32ShellFolder2> list = new ArrayList<Win32ShellFolder2>(); + long pEnumObjects = getEnumObjects(pIShellFolder, includeHiddenFiles); + if (pEnumObjects != 0) { + long childPIDL; + int testedAttrs = ATTRIB_FILESYSTEM | ATTRIB_FILESYSANCESTOR; + do { + childPIDL = getNextChild(pEnumObjects); + boolean releasePIDL = true; + if (childPIDL != 0 && + (getAttributes0(pIShellFolder, childPIDL, testedAttrs) & testedAttrs) != 0) { + Win32ShellFolder2 childFolder; + if (Win32ShellFolder2.this.equals(desktop) + && personal != null + && pidlsEqual(pIShellFolder, childPIDL, personal.disposer.relativePIDL)) { + childFolder = personal; + } else { + childFolder = new Win32ShellFolder2(Win32ShellFolder2.this, childPIDL); + releasePIDL = false; + } + list.add(childFolder); + } + if (releasePIDL) { + releasePIDL(childPIDL); + } + } while (childPIDL != 0 && !Thread.currentThread().isInterrupted()); + releaseEnumObjects(pEnumObjects); } - } while (childPIDL != 0); - releaseEnumObjects(pEnumObjects); - } - return list.toArray(new ShellFolder[list.size()]); + return Thread.currentThread().isInterrupted() + ? new File[0] + : list.toArray(new ShellFolder[list.size()]); + } + }); } @@ -644,33 +730,43 @@ final class Win32ShellFolder2 extends ShellFolder { * * @return The child shellfolder, or null if not found. */ - Win32ShellFolder2 getChildByPath(String filePath) { - long pIShellFolder = getIShellFolder(); - long pEnumObjects = getEnumObjects(pIShellFolder, true); - Win32ShellFolder2 child = null; - long childPIDL; - - while ((childPIDL = getNextChild(pEnumObjects)) != 0) { - if (getAttributes0(pIShellFolder, childPIDL, ATTRIB_FILESYSTEM) != 0) { - String path = getFileSystemPath(pIShellFolder, childPIDL); - if (path != null && path.equalsIgnoreCase(filePath)) { - long childIShellFolder = bindToObject(pIShellFolder, childPIDL); - child = new Win32ShellFolder2(this, childIShellFolder, childPIDL, path); - break; + Win32ShellFolder2 getChildByPath(final String filePath) { + return ShellFolder.getInvoker().invoke(new Callable<Win32ShellFolder2>() { + public Win32ShellFolder2 call() throws Exception { + long pIShellFolder = getIShellFolder(); + long pEnumObjects = getEnumObjects(pIShellFolder, true); + Win32ShellFolder2 child = null; + long childPIDL = 0; + + while ((childPIDL = getNextChild(pEnumObjects)) != 0) { + if (getAttributes0(pIShellFolder, childPIDL, ATTRIB_FILESYSTEM) != 0) { + String path = getFileSystemPath(pIShellFolder, childPIDL); + if (path != null && path.equalsIgnoreCase(filePath)) { + long childIShellFolder = bindToObject(pIShellFolder, childPIDL); + child = new Win32ShellFolder2(Win32ShellFolder2.this, + childIShellFolder, childPIDL, path); + break; + } + } + releasePIDL(childPIDL); } + releaseEnumObjects(pEnumObjects); + return child; } - releasePIDL(childPIDL); - } - releaseEnumObjects(pEnumObjects); - return child; + }); } + private Boolean cachedIsLink; /** * @return Whether this shell folder is a link */ - public boolean isLink() { - return hasAttribute(ATTRIB_LINK); + public synchronized boolean isLink() { + if (cachedIsLink == null) { + cachedIsLink = hasAttribute(ATTRIB_LINK); + } + + return cachedIsLink; } /** @@ -682,6 +778,7 @@ final class Win32ShellFolder2 extends ShellFolder { // Return the link location of a shell folder + // NOTE: this method uses COM and must be called on the 'COM thread'. See ComInvoker for the details private static native long getLinkLocation(long parentIShellFolder, long relativePIDL, boolean resolve); @@ -693,38 +790,52 @@ final class Win32ShellFolder2 extends ShellFolder { return getLinkLocation(true); } - private ShellFolder getLinkLocation(boolean resolve) { - if (!isLink()) { - return null; - } + private ShellFolder getLinkLocation(final boolean resolve) { + return ShellFolder.getInvoker().invoke(new Callable<ShellFolder>() { + public ShellFolder call() throws Exception { + if (!isLink()) { + return null; + } - ShellFolder location = null; - long linkLocationPIDL = getLinkLocation(getParentIShellFolder(), - getRelativePIDL(), resolve); - if (linkLocationPIDL != 0) { - try { - location = - Win32ShellFolderManager2.createShellFolderFromRelativePIDL(getDesktop(), - linkLocationPIDL); - } catch (InternalError e) { - // Could be a link to a non-bindable object, such as a network connection - // TODO: getIShellFolder() should throw FileNotFoundException instead + ShellFolder location = null; + long linkLocationPIDL = getLinkLocation(getParentIShellFolder(), + getRelativePIDL(), resolve); + if (linkLocationPIDL != 0) { + try { + location = + Win32ShellFolderManager2.createShellFolderFromRelativePIDL(getDesktop(), + linkLocationPIDL); + } catch (InternalError e) { + // Could be a link to a non-bindable object, such as a network connection + // TODO: getIShellFolder() should throw FileNotFoundException instead + } + } + return location; } - } - return location; + }); } // Parse a display name into a PIDL relative to the current IShellFolder. - long parseDisplayName(String name) throws FileNotFoundException { + long parseDisplayName(final String name) throws FileNotFoundException { try { - return parseDisplayName0(getIShellFolder(), name); - } catch (IOException e) { - throw new FileNotFoundException("Could not find file " + name); + return ShellFolder.getInvoker().invoke(new Callable<Long>() { + public Long call() throws Exception { + return parseDisplayName0(getIShellFolder(), name); + } + }); + } catch (RuntimeException e) { + if (e.getCause() instanceof IOException) { + throw new FileNotFoundException("Could not find file " + name); + } + throw e; } } + + // NOTE: this method uses COM and must be called on the 'COM thread'. See ComInvoker for the details private static native long parseDisplayName0(long pIShellFolder, String name) throws IOException; // Return the display name of a shell folder + // NOTE: this method uses COM and must be called on the 'COM thread'. See ComInvoker for the details private static native String getDisplayNameOf(long parentIShellFolder, long relativePIDL, int attrs); @@ -734,12 +845,19 @@ final class Win32ShellFolder2 extends ShellFolder { */ public String getDisplayName() { if (displayName == null) { - displayName = getDisplayNameOf(getParentIShellFolder(), getRelativePIDL(), SHGDN_NORMAL); + displayName = + ShellFolder.getInvoker().invoke(new Callable<String>() { + public String call() throws Exception { + return getDisplayNameOf(getParentIShellFolder(), + getRelativePIDL(), SHGDN_NORMAL); + } + }); } return displayName; } // Return the folder type of a shell folder + // NOTE: this method uses COM and must be called on the 'COM thread'. See ComInvoker for the details private static native String getFolderType(long pIDL); /** @@ -747,7 +865,13 @@ final class Win32ShellFolder2 extends ShellFolder { */ public String getFolderType() { if (folderType == null) { - folderType = getFolderType(getAbsolutePIDL()); + final long absolutePIDL = getAbsolutePIDL(); + folderType = + ShellFolder.getInvoker().invoke(new Callable<String>() { + public String call() throws Exception { + return getFolderType(absolutePIDL); + } + }); } return folderType; } @@ -774,11 +898,16 @@ final class Win32ShellFolder2 extends ShellFolder { private static Map smallLinkedSystemImages = new HashMap(); private static Map largeLinkedSystemImages = new HashMap(); + // NOTE: this method uses COM and must be called on the 'COM thread'. See ComInvoker for the details private static native long getIShellIcon(long pIShellFolder); + + // NOTE: this method uses COM and must be called on the 'COM thread'. See ComInvoker for the details private static native int getIconIndex(long parentIShellIcon, long relativePIDL); // Return the icon of a file system shell folder in the form of an HICON private static native long getIcon(String absolutePath, boolean getLargeIcon); + + // NOTE: this method uses COM and must be called on the 'COM thread'. See ComInvoker for the details private static native long extractIcon(long parentIShellFolder, long relativePIDL, boolean getLargeIcon); @@ -799,7 +928,12 @@ final class Win32ShellFolder2 extends ShellFolder { private long getIShellIcon() { if (pIShellIcon == -1L) { - pIShellIcon = getIShellIcon(getIShellFolder()); + pIShellIcon = + ShellFolder.getInvoker().invoke(new Callable<Long>() { + public Long call() throws Exception { + return getIShellIcon(getIShellFolder()); + } + }); } return pIShellIcon; } @@ -850,50 +984,60 @@ final class Win32ShellFolder2 extends ShellFolder { /** * @return The icon image used to display this shell folder */ - public Image getIcon(boolean getLargeIcon) { + public Image getIcon(final boolean getLargeIcon) { Image icon = getLargeIcon ? largeIcon : smallIcon; if (icon == null) { - long parentIShellIcon = (parent != null) ? ((Win32ShellFolder2)parent).getIShellIcon() : 0L; - long relativePIDL = getRelativePIDL(); - - if (isFileSystem()) { - // These are cached per type (using the index in the system image list) - int index = getIconIndex(parentIShellIcon, relativePIDL); - if (index > 0) { - Map imageCache; - if (isLink()) { - imageCache = getLargeIcon ? largeLinkedSystemImages : smallLinkedSystemImages; - } else { - imageCache = getLargeIcon ? largeSystemImages : smallSystemImages; - } - icon = (Image)imageCache.get(Integer.valueOf(index)); - if (icon == null) { - long hIcon = getIcon(getAbsolutePath(), getLargeIcon); - icon = makeIcon(hIcon, getLargeIcon); - disposeIcon(hIcon); - if (icon != null) { - imageCache.put(Integer.valueOf(index), icon); + icon = + ShellFolder.getInvoker().invoke(new Callable<Image>() { + public Image call() throws Exception { + Image newIcon = null; + if (isFileSystem()) { + long parentIShellIcon = (parent != null) + ? ((Win32ShellFolder2) parent).getIShellIcon() + : 0L; + long relativePIDL = getRelativePIDL(); + + // These are cached per type (using the index in the system image list) + int index = getIconIndex(parentIShellIcon, relativePIDL); + if (index > 0) { + Map imageCache; + if (isLink()) { + imageCache = getLargeIcon ? largeLinkedSystemImages : smallLinkedSystemImages; + } else { + imageCache = getLargeIcon ? largeSystemImages : smallSystemImages; + } + newIcon = (Image) imageCache.get(Integer.valueOf(index)); + if (newIcon == null) { + long hIcon = getIcon(getAbsolutePath(), getLargeIcon); + newIcon = makeIcon(hIcon, getLargeIcon); + disposeIcon(hIcon); + if (newIcon != null) { + imageCache.put(Integer.valueOf(index), newIcon); + } + } + } } - } - } - } - if (icon == null) { - // These are only cached per object - long hIcon = extractIcon(getParentIShellFolder(), getRelativePIDL(), getLargeIcon); - icon = makeIcon(hIcon, getLargeIcon); - disposeIcon(hIcon); - } + if (newIcon == null) { + // These are only cached per object + long hIcon = extractIcon(getParentIShellFolder(), + getRelativePIDL(), getLargeIcon); + newIcon = makeIcon(hIcon, getLargeIcon); + disposeIcon(hIcon); + } + if (newIcon == null) { + newIcon = Win32ShellFolder2.super.getIcon(getLargeIcon); + } + return newIcon; + } + }); if (getLargeIcon) { largeIcon = icon; } else { smallIcon = icon; } } - if (icon == null) { - icon = super.getIcon(getLargeIcon); - } return icon; } @@ -969,39 +1113,50 @@ final class Win32ShellFolder2 extends ShellFolder { private static final int LVCFMT_CENTER = 2; public ShellFolderColumnInfo[] getFolderColumns() { - ShellFolderColumnInfo[] columns = doGetColumnInfo(getIShellFolder()); - - if (columns != null) { - List<ShellFolderColumnInfo> notNullColumns = - new ArrayList<ShellFolderColumnInfo>(); - for (int i = 0; i < columns.length; i++) { - ShellFolderColumnInfo column = columns[i]; - if (column != null) { - column.setAlignment(column.getAlignment() == LVCFMT_RIGHT - ? SwingConstants.RIGHT - : column.getAlignment() == LVCFMT_CENTER - ? SwingConstants.CENTER - : SwingConstants.LEADING); - - column.setComparator(new ColumnComparator(getIShellFolder(), i)); - - notNullColumns.add(column); + return ShellFolder.getInvoker().invoke(new Callable<ShellFolderColumnInfo[]>() { + public ShellFolderColumnInfo[] call() throws Exception { + ShellFolderColumnInfo[] columns = doGetColumnInfo(getIShellFolder()); + + if (columns != null) { + List<ShellFolderColumnInfo> notNullColumns = + new ArrayList<ShellFolderColumnInfo>(); + for (int i = 0; i < columns.length; i++) { + ShellFolderColumnInfo column = columns[i]; + if (column != null) { + column.setAlignment(column.getAlignment() == LVCFMT_RIGHT + ? SwingConstants.RIGHT + : column.getAlignment() == LVCFMT_CENTER + ? SwingConstants.CENTER + : SwingConstants.LEADING); + + column.setComparator(new ColumnComparator(getIShellFolder(), i)); + + notNullColumns.add(column); + } + } + columns = new ShellFolderColumnInfo[notNullColumns.size()]; + notNullColumns.toArray(columns); } + return columns; } - columns = new ShellFolderColumnInfo[notNullColumns.size()]; - notNullColumns.toArray(columns); - } - return columns; + }); } - public Object getFolderColumnValue(int column) { - return doGetColumnValue(getParentIShellFolder(), getRelativePIDL(), column); + public Object getFolderColumnValue(final int column) { + return ShellFolder.getInvoker().invoke(new Callable<Object>() { + public Object call() throws Exception { + return doGetColumnValue(getParentIShellFolder(), getRelativePIDL(), column); + } + }); } + // NOTE: this method uses COM and must be called on the 'COM thread'. See ComInvoker for the details private native ShellFolderColumnInfo[] doGetColumnInfo(long iShellFolder2); + // NOTE: this method uses COM and must be called on the 'COM thread'. See ComInvoker for the details private native Object doGetColumnValue(long parentIShellFolder2, long childPIDL, int columnIdx); + // NOTE: this method uses COM and must be called on the 'COM thread'. See ComInvoker for the details private static native int compareIDsByColumn(long pParentIShellFolder, long pidl1, long pidl2, int columnIdx); @@ -1020,17 +1175,20 @@ final class Win32ShellFolder2 extends ShellFolder { } // compares 2 objects within this folder by the specified column - public int compare(File o, File o1) { - if (o instanceof Win32ShellFolder2 - && o1 instanceof Win32ShellFolder2) { - // delegates comparison to native method - return compareIDsByColumn(parentIShellFolder, - ((Win32ShellFolder2) o).getRelativePIDL(), - ((Win32ShellFolder2) o1).getRelativePIDL(), - columnIdx); - } - return 0; + public int compare(final File o, final File o1) { + return ShellFolder.getInvoker().invoke(new Callable<Integer>() { + public Integer call() throws Exception { + if (o instanceof Win32ShellFolder2 + && o1 instanceof Win32ShellFolder2) { + // delegates comparison to native method + return compareIDsByColumn(parentIShellFolder, + ((Win32ShellFolder2) o).getRelativePIDL(), + ((Win32ShellFolder2) o1).getRelativePIDL(), + columnIdx); + } + return 0; + } + }); } } - } diff --git a/src/windows/classes/sun/awt/shell/Win32ShellFolderManager2.java b/src/windows/classes/sun/awt/shell/Win32ShellFolderManager2.java index 0259e5533cde627f2a7de78c6d9b333928bbc403..563f474e2f2efe90fe8786f13d789fa56f17a1bc 100644 --- a/src/windows/classes/sun/awt/shell/Win32ShellFolderManager2.java +++ b/src/windows/classes/sun/awt/shell/Win32ShellFolderManager2.java @@ -31,7 +31,10 @@ import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.security.AccessController; +import java.security.PrivilegedAction; import java.util.*; +import java.util.concurrent.*; + import sun.security.action.LoadLibraryAction; import static sun.awt.shell.Win32ShellFolder2.*; @@ -408,4 +411,102 @@ public class Win32ShellFolderManager2 extends ShellFolderManager { return name1.compareTo(name2); } } + + @Override + protected Invoker createInvoker() { + return new ComInvoker(); + } + + private static class ComInvoker extends ThreadPoolExecutor implements ThreadFactory, ShellFolder.Invoker { + private static Thread comThread; + + private ComInvoker() { + super(1, 1, 0, TimeUnit.DAYS, new LinkedBlockingQueue<Runnable>()); + allowCoreThreadTimeOut(false); + setThreadFactory(this); + final Runnable shutdownHook = new Runnable() { + public void run() { + AccessController.doPrivileged(new PrivilegedAction<Void>() { + public Void run() { + shutdownNow(); + return null; + } + }); + } + }; + AccessController.doPrivileged(new PrivilegedAction<Void>() { + public Void run() { + Runtime.getRuntime().addShutdownHook( + new Thread(shutdownHook) + ); + return null; + } + }); + } + + public synchronized Thread newThread(final Runnable task) { + final Runnable comRun = new Runnable() { + public void run() { + try { + initializeCom(); + task.run(); + } finally { + uninitializeCom(); + } + } + }; + comThread = + AccessController.doPrivileged( + new PrivilegedAction<Thread>() { + public Thread run() { + /* The thread must be a member of a thread group + * which will not get GCed before VM exit. + * Make its parent the top-level thread group. + */ + ThreadGroup tg = Thread.currentThread().getThreadGroup(); + for (ThreadGroup tgn = tg; + tgn != null; + tg = tgn, tgn = tg.getParent()); + Thread thread = new Thread(tg, comRun, "Swing-Shell"); + thread.setDaemon(true); + return thread; + } + } + ); + return comThread; + } + + public <T> T invoke(Callable<T> task) { + try { + T result; + if (Thread.currentThread() == comThread) { + // if it's already called from the COM + // thread, we don't need to delegate the task + result = task.call(); + } else { + Future<T> future = submit(task); + try { + result = future.get(); + } catch (InterruptedException e) { + result = null; + future.cancel(true); + } + } + return result; + } catch (Exception e) { + Throwable cause = (e instanceof ExecutionException) ? e.getCause() : e; + if (cause instanceof RuntimeException) { + throw (RuntimeException) cause; + } + if (cause instanceof Error) { + throw (Error) cause; + } + throw new RuntimeException(cause); + } + } + } + + static native void initializeCom(); + + static native void uninitializeCom(); } diff --git a/src/windows/classes/sun/awt/windows/WFontConfiguration.java b/src/windows/classes/sun/awt/windows/WFontConfiguration.java index 4f2f8324ae4f1e252f7dc0cb7914c0b220491b0a..2c7b00124a7bb1bd6804ea82d20954435304adaa 100644 --- a/src/windows/classes/sun/awt/windows/WFontConfiguration.java +++ b/src/windows/classes/sun/awt/windows/WFontConfiguration.java @@ -61,18 +61,10 @@ public class WFontConfiguration extends FontConfiguration { * been opened and its fonts loaded. * Also note this usage is only enabled if a private flag is set. */ - if ("98".equals(osName) || "Me".equals(osName)) { - localeMap.put("dialoginput.plain.japanese", "\uff2d\uff33 \u660e\u671d"); - localeMap.put("dialoginput.bold.japanese", "\uff2d\uff33 \u660e\u671d"); - localeMap.put("dialoginput.italic.japanese", "\uff2d\uff33 \u660e\u671d"); - localeMap.put("dialoginput.bolditalic.japanese", "\uff2d\uff33 \u660e\u671d"); - } else { - - localeMap.put("dialoginput.plain.japanese", "MS Mincho"); - localeMap.put("dialoginput.bold.japanese", "MS Mincho"); - localeMap.put("dialoginput.italic.japanese", "MS Mincho"); - localeMap.put("dialoginput.bolditalic.japanese", "MS Mincho"); - } + localeMap.put("dialoginput.plain.japanese", "MS Mincho"); + localeMap.put("dialoginput.bold.japanese", "MS Mincho"); + localeMap.put("dialoginput.italic.japanese", "MS Mincho"); + localeMap.put("dialoginput.bolditalic.japanese", "MS Mincho"); } reorderMap = new HashMap(); reorderMap.put("UTF-8.hi", "devanagari"); diff --git a/src/windows/classes/sun/awt/windows/fontconfig.98.properties b/src/windows/classes/sun/awt/windows/fontconfig.98.properties deleted file mode 100644 index 8d69d410e25b2700f9428dcf183ad946e28d8a89..0000000000000000000000000000000000000000 --- a/src/windows/classes/sun/awt/windows/fontconfig.98.properties +++ /dev/null @@ -1,241 +0,0 @@ -# -# -# Copyright 2003-2004 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. -# - -# Version - -version=1 - -# Component Font Mappings - -allfonts.chinese-ms936=SimSun -allfonts.dingbats=Wingdings -allfonts.lucida=Lucida Sans Regular -allfonts.symbol=Symbol -allfonts.thai=Lucida Sans Regular - -serif.plain.alphabetic=Times New Roman -serif.plain.chinese-ms950=MingLiU -serif.plain.hebrew=David -serif.plain.japanese=\uff2d\uff33 \u660e\u671d -serif.plain.korean=Batang - -serif.bold.alphabetic=Times New Roman Bold -serif.bold.chinese-ms950=PMingLiU -serif.bold.hebrew=David Bold -serif.bold.japanese=\uff2d\uff33 \u660e\u671d -serif.bold.korean=Batang - -serif.italic.alphabetic=Times New Roman Italic -serif.italic.chinese-ms950=PMingLiU -serif.italic.hebrew=David -serif.italic.japanese=\uff2d\uff33 \u660e\u671d -serif.italic.korean=Batang - -serif.bolditalic.alphabetic=Times New Roman Bold Italic -serif.bolditalic.chinese-ms950=PMingLiU -serif.bolditalic.hebrew=David Bold -serif.bolditalic.japanese=\uff2d\uff33 \u660e\u671d -serif.bolditalic.korean=Batang - -sansserif.plain.alphabetic=Arial -sansserif.plain.chinese-ms950=MingLiU -sansserif.plain.hebrew=David -sansserif.plain.japanese=\uff2d\uff33 \u30b4\u30b7\u30c3\u30af -sansserif.plain.korean=Gulim - -sansserif.bold.alphabetic=Arial Bold -sansserif.bold.chinese-ms950=PMingLiU -sansserif.bold.hebrew=David Bold -sansserif.bold.japanese=\uff2d\uff33 \u30b4\u30b7\u30c3\u30af -sansserif.bold.korean=Gulim - -sansserif.italic.alphabetic=Arial Italic -sansserif.italic.chinese-ms950=PMingLiU -sansserif.italic.hebrew=David -sansserif.italic.japanese=\uff2d\uff33 \u30b4\u30b7\u30c3\u30af -sansserif.italic.korean=Gulim - -sansserif.bolditalic.alphabetic=Arial Bold Italic -sansserif.bolditalic.chinese-ms950=PMingLiU -sansserif.bolditalic.hebrew=David Bold -sansserif.bolditalic.japanese=\uff2d\uff33 \u30b4\u30b7\u30c3\u30af -sansserif.bolditalic.korean=Gulim - -monospaced.plain.alphabetic=Courier New -monospaced.plain.chinese-ms950=MingLiU -monospaced.plain.hebrew=David -monospaced.plain.japanese=\uff2d\uff33 \u30b4\u30b7\u30c3\u30af -monospaced.plain.korean=GulimChe - -monospaced.bold.alphabetic=Courier New Bold -monospaced.bold.chinese-ms950=PMingLiU -monospaced.bold.hebrew=David Bold -monospaced.bold.japanese=\uff2d\uff33 \u30b4\u30b7\u30c3\u30af -monospaced.bold.korean=GulimChe - -monospaced.italic.alphabetic=Courier New Italic -monospaced.italic.chinese-ms950=PMingLiU -monospaced.italic.hebrew=David -monospaced.italic.japanese=\uff2d\uff33 \u30b4\u30b7\u30c3\u30af -monospaced.italic.korean=GulimChe - -monospaced.bolditalic.alphabetic=Courier New Bold Italic -monospaced.bolditalic.chinese-ms950=PMingLiU -monospaced.bolditalic.hebrew=David Bold -monospaced.bolditalic.japanese=\uff2d\uff33 \u30b4\u30b7\u30c3\u30af -monospaced.bolditalic.korean=GulimChe - -dialog.plain.alphabetic=Arial -dialog.plain.chinese-ms950=MingLiU -dialog.plain.hebrew=David -dialog.plain.japanese=\uff2d\uff33 \u30b4\u30b7\u30c3\u30af -dialog.plain.korean=Gulim - -dialog.bold.alphabetic=Arial Bold -dialog.bold.chinese-ms950=PMingLiU -dialog.bold.hebrew=David Bold -dialog.bold.japanese=\uff2d\uff33 \u30b4\u30b7\u30c3\u30af -dialog.bold.korean=Gulim - -dialog.italic.alphabetic=Arial Italic -dialog.italic.chinese-ms950=PMingLiU -dialog.italic.hebrew=David -dialog.italic.japanese=\uff2d\uff33 \u30b4\u30b7\u30c3\u30af -dialog.italic.korean=Gulim - -dialog.bolditalic.alphabetic=Arial Bold Italic -dialog.bolditalic.chinese-ms950=PMingLiU -dialog.bolditalic.hebrew=David Bold -dialog.bolditalic.japanese=\uff2d\uff33 \u30b4\u30b7\u30c3\u30af -dialog.bolditalic.korean=Gulim - -dialoginput.plain.alphabetic=Courier New -dialoginput.plain.chinese-ms950=MingLiU -dialoginput.plain.hebrew=David -dialoginput.plain.japanese=\uff2d\uff33 \u30b4\u30b7\u30c3\u30af -dialoginput.plain.korean=Gulim - -dialoginput.bold.alphabetic=Courier New Bold -dialoginput.bold.chinese-ms950=PMingLiU -dialoginput.bold.hebrew=David Bold -dialoginput.bold.japanese=\uff2d\uff33 \u30b4\u30b7\u30c3\u30af -dialoginput.bold.korean=Gulim - -dialoginput.italic.alphabetic=Courier New Italic -dialoginput.italic.chinese-ms950=PMingLiU -dialoginput.italic.hebrew=David -dialoginput.italic.japanese=\uff2d\uff33 \u30b4\u30b7\u30c3\u30af -dialoginput.italic.korean=Gulim - -dialoginput.bolditalic.alphabetic=Courier New Bold Italic -dialoginput.bolditalic.chinese-ms950=PMingLiU -dialoginput.bolditalic.hebrew=David Bold -dialoginput.bolditalic.japanese=\uff2d\uff33 \u30b4\u30b7\u30c3\u30af -dialoginput.bolditalic.korean=Gulim - -# Search Sequences - -sequence.allfonts=alphabetic/default,dingbats,symbol - -sequence.serif.GBK=alphabetic/1252,chinese-ms936,dingbats,symbol -sequence.sansserif.GBK=alphabetic/1252,chinese-ms936,dingbats,symbol -sequence.monospaced.GBK=chinese-ms936,alphabetic/1252,dingbats,symbol -sequence.dialog.GBK=alphabetic/1252,chinese-ms936,dingbats,symbol -sequence.dialoginput.GBK=alphabetic/1252,chinese-ms936,dingbats,symbol - -sequence.serif.x-windows-950=alphabetic/1252,chinese-ms950,dingbats,symbol -sequence.sansserif.x-windows-950=alphabetic/1252,chinese-ms950,dingbats,symbol -sequence.monospaced.x-windows-950=chinese-ms950,alphabetic/1252,dingbats,symbol -sequence.dialog.x-windows-950=alphabetic/1252,chinese-ms950,dingbats,symbol -sequence.dialoginput.x-windows-950=alphabetic/1252,chinese-ms950,dingbats,symbol - -sequence.allfonts.windows-1255=hebrew,alphabetic/1252,dingbats,symbol - -sequence.serif.windows-31j=alphabetic/1252,japanese,dingbats,symbol -sequence.sansserif.windows-31j=alphabetic/1252,japanese,dingbats,symbol -sequence.monospaced.windows-31j=japanese,alphabetic/1252,dingbats,symbol -sequence.dialog.windows-31j=alphabetic/1252,japanese,dingbats,symbol -sequence.dialoginput.windows-31j=alphabetic/1252,japanese,dingbats,symbol - -sequence.serif.x-windows-949=alphabetic/1252,korean,dingbats,symbol -sequence.sansserif.x-windows-949=alphabetic/1252,korean,dingbats,symbol -sequence.monospaced.x-windows-949=korean,alphabetic/1252,dingbats,symbol -sequence.dialog.x-windows-949=alphabetic/1252,korean,dingbats,symbol -sequence.dialoginput.x-windows-949=alphabetic/1252,korean,dingbats,symbol - -sequence.allfonts.x-windows-874=alphabetic/1252,thai,dingbats,symbol - -sequence.fallback=lucida - -# Exclusion Ranges - -exclusion.alphabetic=0700-1e9f,1f00-20ab,20ad-f8ff -exclusion.hebrew=0041-005a,0060-007a,007f-00ff,20ac-20ac - -# Monospaced to Proportional width variant mapping -# (Experimental private syntax) -proportional.\uff2d\uff33_\u30b4\u30b7\u30c3\u30af=\uff2d\uff33 \uff30\u30b4\u30b7\u30c3\u30af -proportional.\uff2d\uff33_\u660e\u671d=\uff2d\uff33 \uff30\u660e\u671d -proportional.MingLiU=PMingLiU - -# Font File Names - -filename.Arial=ARIAL.TTF -filename.Arial_Bold=ARIALBD.TTF -filename.Arial_Italic=ARIALI.TTF -filename.Arial_Bold_Italic=ARIALBI.TTF - -filename.Courier_New=COUR.TTF -filename.Courier_New_Bold=COURBD.TTF -filename.Courier_New_Italic=COURI.TTF -filename.Courier_New_Bold_Italic=COURBI.TTF - -filename.Times_New_Roman=TIMES.TTF -filename.Times_New_Roman_Bold=TIMESBD.TTF -filename.Times_New_Roman_Italic=TIMESI.TTF -filename.Times_New_Roman_Bold_Italic=TIMESBI.TTF - -filename.SimSun=SIMSUN.TTF - -filename.MingLiU=MINGLIU.TTC -filename.PMingLiU=MINGLIU.TTC - -filename.David=DAVID.TTF -filename.David_Bold=DAVIDBD.TTF - -filename.\uff2d\uff33_\u660e\u671d=MSMINCHO.TTC -filename.\uff2d\uff33_\uff30\u660e\u671d=MSMINCHO.TTC -filename.\uff2d\uff33_\u30b4\u30b7\u30c3\u30af=MSGOTHIC.TTC -filename.\uff2d\uff33_\uff30\u30b4\u30b7\u30c3\u30af=MSGOTHIC.TTC - -filename.Gulim=gulim.TTC -filename.Batang=batang.TTC -filename.GulimChe=gulim.TTC - -filename.Lucida_Sans_Regular=LucidaSansRegular.ttf -filename.Symbol=SYMBOL.TTF -filename.Wingdings=WINGDING.TTF - diff --git a/src/windows/classes/sun/awt/windows/fontconfig.Me.properties b/src/windows/classes/sun/awt/windows/fontconfig.Me.properties deleted file mode 100644 index 8d69d410e25b2700f9428dcf183ad946e28d8a89..0000000000000000000000000000000000000000 --- a/src/windows/classes/sun/awt/windows/fontconfig.Me.properties +++ /dev/null @@ -1,241 +0,0 @@ -# -# -# Copyright 2003-2004 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. -# - -# Version - -version=1 - -# Component Font Mappings - -allfonts.chinese-ms936=SimSun -allfonts.dingbats=Wingdings -allfonts.lucida=Lucida Sans Regular -allfonts.symbol=Symbol -allfonts.thai=Lucida Sans Regular - -serif.plain.alphabetic=Times New Roman -serif.plain.chinese-ms950=MingLiU -serif.plain.hebrew=David -serif.plain.japanese=\uff2d\uff33 \u660e\u671d -serif.plain.korean=Batang - -serif.bold.alphabetic=Times New Roman Bold -serif.bold.chinese-ms950=PMingLiU -serif.bold.hebrew=David Bold -serif.bold.japanese=\uff2d\uff33 \u660e\u671d -serif.bold.korean=Batang - -serif.italic.alphabetic=Times New Roman Italic -serif.italic.chinese-ms950=PMingLiU -serif.italic.hebrew=David -serif.italic.japanese=\uff2d\uff33 \u660e\u671d -serif.italic.korean=Batang - -serif.bolditalic.alphabetic=Times New Roman Bold Italic -serif.bolditalic.chinese-ms950=PMingLiU -serif.bolditalic.hebrew=David Bold -serif.bolditalic.japanese=\uff2d\uff33 \u660e\u671d -serif.bolditalic.korean=Batang - -sansserif.plain.alphabetic=Arial -sansserif.plain.chinese-ms950=MingLiU -sansserif.plain.hebrew=David -sansserif.plain.japanese=\uff2d\uff33 \u30b4\u30b7\u30c3\u30af -sansserif.plain.korean=Gulim - -sansserif.bold.alphabetic=Arial Bold -sansserif.bold.chinese-ms950=PMingLiU -sansserif.bold.hebrew=David Bold -sansserif.bold.japanese=\uff2d\uff33 \u30b4\u30b7\u30c3\u30af -sansserif.bold.korean=Gulim - -sansserif.italic.alphabetic=Arial Italic -sansserif.italic.chinese-ms950=PMingLiU -sansserif.italic.hebrew=David -sansserif.italic.japanese=\uff2d\uff33 \u30b4\u30b7\u30c3\u30af -sansserif.italic.korean=Gulim - -sansserif.bolditalic.alphabetic=Arial Bold Italic -sansserif.bolditalic.chinese-ms950=PMingLiU -sansserif.bolditalic.hebrew=David Bold -sansserif.bolditalic.japanese=\uff2d\uff33 \u30b4\u30b7\u30c3\u30af -sansserif.bolditalic.korean=Gulim - -monospaced.plain.alphabetic=Courier New -monospaced.plain.chinese-ms950=MingLiU -monospaced.plain.hebrew=David -monospaced.plain.japanese=\uff2d\uff33 \u30b4\u30b7\u30c3\u30af -monospaced.plain.korean=GulimChe - -monospaced.bold.alphabetic=Courier New Bold -monospaced.bold.chinese-ms950=PMingLiU -monospaced.bold.hebrew=David Bold -monospaced.bold.japanese=\uff2d\uff33 \u30b4\u30b7\u30c3\u30af -monospaced.bold.korean=GulimChe - -monospaced.italic.alphabetic=Courier New Italic -monospaced.italic.chinese-ms950=PMingLiU -monospaced.italic.hebrew=David -monospaced.italic.japanese=\uff2d\uff33 \u30b4\u30b7\u30c3\u30af -monospaced.italic.korean=GulimChe - -monospaced.bolditalic.alphabetic=Courier New Bold Italic -monospaced.bolditalic.chinese-ms950=PMingLiU -monospaced.bolditalic.hebrew=David Bold -monospaced.bolditalic.japanese=\uff2d\uff33 \u30b4\u30b7\u30c3\u30af -monospaced.bolditalic.korean=GulimChe - -dialog.plain.alphabetic=Arial -dialog.plain.chinese-ms950=MingLiU -dialog.plain.hebrew=David -dialog.plain.japanese=\uff2d\uff33 \u30b4\u30b7\u30c3\u30af -dialog.plain.korean=Gulim - -dialog.bold.alphabetic=Arial Bold -dialog.bold.chinese-ms950=PMingLiU -dialog.bold.hebrew=David Bold -dialog.bold.japanese=\uff2d\uff33 \u30b4\u30b7\u30c3\u30af -dialog.bold.korean=Gulim - -dialog.italic.alphabetic=Arial Italic -dialog.italic.chinese-ms950=PMingLiU -dialog.italic.hebrew=David -dialog.italic.japanese=\uff2d\uff33 \u30b4\u30b7\u30c3\u30af -dialog.italic.korean=Gulim - -dialog.bolditalic.alphabetic=Arial Bold Italic -dialog.bolditalic.chinese-ms950=PMingLiU -dialog.bolditalic.hebrew=David Bold -dialog.bolditalic.japanese=\uff2d\uff33 \u30b4\u30b7\u30c3\u30af -dialog.bolditalic.korean=Gulim - -dialoginput.plain.alphabetic=Courier New -dialoginput.plain.chinese-ms950=MingLiU -dialoginput.plain.hebrew=David -dialoginput.plain.japanese=\uff2d\uff33 \u30b4\u30b7\u30c3\u30af -dialoginput.plain.korean=Gulim - -dialoginput.bold.alphabetic=Courier New Bold -dialoginput.bold.chinese-ms950=PMingLiU -dialoginput.bold.hebrew=David Bold -dialoginput.bold.japanese=\uff2d\uff33 \u30b4\u30b7\u30c3\u30af -dialoginput.bold.korean=Gulim - -dialoginput.italic.alphabetic=Courier New Italic -dialoginput.italic.chinese-ms950=PMingLiU -dialoginput.italic.hebrew=David -dialoginput.italic.japanese=\uff2d\uff33 \u30b4\u30b7\u30c3\u30af -dialoginput.italic.korean=Gulim - -dialoginput.bolditalic.alphabetic=Courier New Bold Italic -dialoginput.bolditalic.chinese-ms950=PMingLiU -dialoginput.bolditalic.hebrew=David Bold -dialoginput.bolditalic.japanese=\uff2d\uff33 \u30b4\u30b7\u30c3\u30af -dialoginput.bolditalic.korean=Gulim - -# Search Sequences - -sequence.allfonts=alphabetic/default,dingbats,symbol - -sequence.serif.GBK=alphabetic/1252,chinese-ms936,dingbats,symbol -sequence.sansserif.GBK=alphabetic/1252,chinese-ms936,dingbats,symbol -sequence.monospaced.GBK=chinese-ms936,alphabetic/1252,dingbats,symbol -sequence.dialog.GBK=alphabetic/1252,chinese-ms936,dingbats,symbol -sequence.dialoginput.GBK=alphabetic/1252,chinese-ms936,dingbats,symbol - -sequence.serif.x-windows-950=alphabetic/1252,chinese-ms950,dingbats,symbol -sequence.sansserif.x-windows-950=alphabetic/1252,chinese-ms950,dingbats,symbol -sequence.monospaced.x-windows-950=chinese-ms950,alphabetic/1252,dingbats,symbol -sequence.dialog.x-windows-950=alphabetic/1252,chinese-ms950,dingbats,symbol -sequence.dialoginput.x-windows-950=alphabetic/1252,chinese-ms950,dingbats,symbol - -sequence.allfonts.windows-1255=hebrew,alphabetic/1252,dingbats,symbol - -sequence.serif.windows-31j=alphabetic/1252,japanese,dingbats,symbol -sequence.sansserif.windows-31j=alphabetic/1252,japanese,dingbats,symbol -sequence.monospaced.windows-31j=japanese,alphabetic/1252,dingbats,symbol -sequence.dialog.windows-31j=alphabetic/1252,japanese,dingbats,symbol -sequence.dialoginput.windows-31j=alphabetic/1252,japanese,dingbats,symbol - -sequence.serif.x-windows-949=alphabetic/1252,korean,dingbats,symbol -sequence.sansserif.x-windows-949=alphabetic/1252,korean,dingbats,symbol -sequence.monospaced.x-windows-949=korean,alphabetic/1252,dingbats,symbol -sequence.dialog.x-windows-949=alphabetic/1252,korean,dingbats,symbol -sequence.dialoginput.x-windows-949=alphabetic/1252,korean,dingbats,symbol - -sequence.allfonts.x-windows-874=alphabetic/1252,thai,dingbats,symbol - -sequence.fallback=lucida - -# Exclusion Ranges - -exclusion.alphabetic=0700-1e9f,1f00-20ab,20ad-f8ff -exclusion.hebrew=0041-005a,0060-007a,007f-00ff,20ac-20ac - -# Monospaced to Proportional width variant mapping -# (Experimental private syntax) -proportional.\uff2d\uff33_\u30b4\u30b7\u30c3\u30af=\uff2d\uff33 \uff30\u30b4\u30b7\u30c3\u30af -proportional.\uff2d\uff33_\u660e\u671d=\uff2d\uff33 \uff30\u660e\u671d -proportional.MingLiU=PMingLiU - -# Font File Names - -filename.Arial=ARIAL.TTF -filename.Arial_Bold=ARIALBD.TTF -filename.Arial_Italic=ARIALI.TTF -filename.Arial_Bold_Italic=ARIALBI.TTF - -filename.Courier_New=COUR.TTF -filename.Courier_New_Bold=COURBD.TTF -filename.Courier_New_Italic=COURI.TTF -filename.Courier_New_Bold_Italic=COURBI.TTF - -filename.Times_New_Roman=TIMES.TTF -filename.Times_New_Roman_Bold=TIMESBD.TTF -filename.Times_New_Roman_Italic=TIMESI.TTF -filename.Times_New_Roman_Bold_Italic=TIMESBI.TTF - -filename.SimSun=SIMSUN.TTF - -filename.MingLiU=MINGLIU.TTC -filename.PMingLiU=MINGLIU.TTC - -filename.David=DAVID.TTF -filename.David_Bold=DAVIDBD.TTF - -filename.\uff2d\uff33_\u660e\u671d=MSMINCHO.TTC -filename.\uff2d\uff33_\uff30\u660e\u671d=MSMINCHO.TTC -filename.\uff2d\uff33_\u30b4\u30b7\u30c3\u30af=MSGOTHIC.TTC -filename.\uff2d\uff33_\uff30\u30b4\u30b7\u30c3\u30af=MSGOTHIC.TTC - -filename.Gulim=gulim.TTC -filename.Batang=batang.TTC -filename.GulimChe=gulim.TTC - -filename.Lucida_Sans_Regular=LucidaSansRegular.ttf -filename.Symbol=SYMBOL.TTF -filename.Wingdings=WINGDING.TTF - diff --git a/src/windows/classes/sun/net/NetHooks.java b/src/windows/classes/sun/net/NetHooks.java new file mode 100644 index 0000000000000000000000000000000000000000..0d8f60b3a42b9d7c0c63fd0febe0b6796f9ab82f --- /dev/null +++ b/src/windows/classes/sun/net/NetHooks.java @@ -0,0 +1,59 @@ +/* + * 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 sun.net; + +import java.net.InetAddress; +import java.io.FileDescriptor; +import java.io.IOException; + +/** + * Defines static methods to ensure that any installed net hooks are invoked + * prior to binding or connecting TCP sockets. + */ + +public final class NetHooks { + + /** + * Invoke prior to binding a TCP socket. + */ + public static void beforeTcpBind(FileDescriptor fdObj, + InetAddress address, + int port) + throws IOException + { + // nothing to do + } + + /** + * Invoke prior to connecting an unbound TCP socket. + */ + public static void beforeTcpConnect(FileDescriptor fdObj, + InetAddress address, + int port) + throws IOException + { + // nothing to do + } +} diff --git a/src/windows/classes/sun/nio/ch/DefaultAsynchronousChannelProvider.java b/src/windows/classes/sun/nio/ch/DefaultAsynchronousChannelProvider.java new file mode 100644 index 0000000000000000000000000000000000000000..6187aa31878a1a21fa34e9a2625380e13a3dcb58 --- /dev/null +++ b/src/windows/classes/sun/nio/ch/DefaultAsynchronousChannelProvider.java @@ -0,0 +1,43 @@ +/* + * Copyright 2008-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 sun.nio.ch; + +import java.nio.channels.spi.AsynchronousChannelProvider; + +/** + * Creates this platform's default asynchronous channel provider + */ + +public class DefaultAsynchronousChannelProvider { + private DefaultAsynchronousChannelProvider() { } + + /** + * Returns the default AsynchronousChannelProvider. + */ + public static AsynchronousChannelProvider create() { + return new WindowsAsynchronousChannelProvider(); + } +} diff --git a/src/windows/classes/sun/nio/ch/FileDispatcher.java b/src/windows/classes/sun/nio/ch/FileDispatcherImpl.java similarity index 71% rename from src/windows/classes/sun/nio/ch/FileDispatcher.java rename to src/windows/classes/sun/nio/ch/FileDispatcherImpl.java index 6928449664f80a492972e708085932d9489ec393..30390f7a61b8f2abfa418f63f72ce3ba2666b136 100644 --- a/src/windows/classes/sun/nio/ch/FileDispatcher.java +++ b/src/windows/classes/sun/nio/ch/FileDispatcherImpl.java @@ -1,5 +1,5 @@ /* - * 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. * * This code is free software; you can redistribute it and/or modify it @@ -27,13 +27,7 @@ package sun.nio.ch; import java.io.*; - -/** - * Allows different platforms to call different native methods - * for read and write operations. - */ - -class FileDispatcher extends NativeDispatcher +class FileDispatcherImpl extends FileDispatcher { static { @@ -74,6 +68,28 @@ class FileDispatcher extends NativeDispatcher return writev0(fd, address, len); } + int force(FileDescriptor fd, boolean metaData) throws IOException { + return force0(fd, metaData); + } + + int truncate(FileDescriptor fd, long size) throws IOException { + return truncate0(fd, size); + } + + long size(FileDescriptor fd) throws IOException { + return size0(fd); + } + + int lock(FileDescriptor fd, boolean blocking, long pos, long size, + boolean shared) throws IOException + { + return lock0(fd, blocking, pos, size, shared); + } + + void release(FileDescriptor fd, long pos, long size) throws IOException { + release0(fd, pos, size); + } + void close(FileDescriptor fd) throws IOException { close0(fd); } @@ -98,6 +114,20 @@ class FileDispatcher extends NativeDispatcher static native long writev0(FileDescriptor fd, long address, int len) throws IOException; + static native int force0(FileDescriptor fd, boolean metaData) + throws IOException; + + static native int truncate0(FileDescriptor fd, long size) + throws IOException; + + static native long size0(FileDescriptor fd) throws IOException; + + static native int lock0(FileDescriptor fd, boolean blocking, long pos, + long size, boolean shared) throws IOException; + + static native void release0(FileDescriptor fd, long pos, long size) + throws IOException; + static native void close0(FileDescriptor fd) throws IOException; static native void closeByHandle(long fd) throws IOException; diff --git a/src/windows/classes/sun/nio/ch/Iocp.java b/src/windows/classes/sun/nio/ch/Iocp.java new file mode 100644 index 0000000000000000000000000000000000000000..b4c2cdef61e469dbb8326d6c0e7389891a33813e --- /dev/null +++ b/src/windows/classes/sun/nio/ch/Iocp.java @@ -0,0 +1,437 @@ +/* + * Copyright 2008-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 sun.nio.ch; + +import java.nio.channels.*; +import java.nio.channels.spi.AsynchronousChannelProvider; +import java.io.Closeable; +import java.io.IOException; +import java.io.FileDescriptor; +import java.util.*; +import java.util.concurrent.*; +import java.util.concurrent.locks.ReadWriteLock; +import java.util.concurrent.locks.ReentrantReadWriteLock; +import sun.misc.Unsafe; + +/** + * Windows implementation of AsynchronousChannelGroup encapsulating an I/O + * completion port. + */ + +class Iocp extends AsynchronousChannelGroupImpl { + private static final Unsafe unsafe = Unsafe.getUnsafe(); + private static final long INVALID_HANDLE_VALUE = -1L; + + // maps completion key to channel + private final ReadWriteLock keyToChannelLock = new ReentrantReadWriteLock(); + private final Map<Integer,OverlappedChannel> keyToChannel = + new HashMap<Integer,OverlappedChannel>(); + private int nextCompletionKey; + + // handle to completion port + private final long port; + + // true if port has been closed + private boolean closed; + + // the set of "stale" OVERLAPPED structures. These OVERLAPPED structures + // relate to I/O operations where the completion notification was not + // received in a timely manner after the channel is closed. + private final Set<Long> staleIoSet = new HashSet<Long>(); + + Iocp(AsynchronousChannelProvider provider, ThreadPool pool) + throws IOException + { + super(provider, pool); + this.port = + createIoCompletionPort(INVALID_HANDLE_VALUE, 0, 0, fixedThreadCount()); + this.nextCompletionKey = 1; + } + + Iocp start() { + startThreads(new EventHandlerTask()); + return this; + } + + /* + * Channels implements this interface support overlapped I/O and can be + * associated with a completion port. + */ + static interface OverlappedChannel extends Closeable { + /** + * Returns a reference to the pending I/O result. + */ + <V,A> PendingFuture<V,A> getByOverlapped(long overlapped); + } + + // release all resources + void implClose() { + synchronized (this) { + if (closed) + return; + closed = true; + } + close0(port); + synchronized (staleIoSet) { + for (Long ov: staleIoSet) { + unsafe.freeMemory(ov); + } + staleIoSet.clear(); + } + } + + @Override + boolean isEmpty() { + keyToChannelLock.writeLock().lock(); + try { + return keyToChannel.isEmpty(); + } finally { + keyToChannelLock.writeLock().unlock(); + } + } + + @Override + final Object attachForeignChannel(final Channel channel, FileDescriptor fdObj) + throws IOException + { + int key = associate(new OverlappedChannel() { + public <V,A> PendingFuture<V,A> getByOverlapped(long overlapped) { + return null; + } + public void close() throws IOException { + channel.close(); + } + }, 0L); + return Integer.valueOf(key); + } + + @Override + final void detachForeignChannel(Object key) { + disassociate((Integer)key); + } + + @Override + void closeAllChannels() { + /** + * On Windows the close operation will close the socket/file handle + * and then wait until all outstanding I/O operations have aborted. + * This is necessary as each channel's cache of OVERLAPPED structures + * can only be freed once all I/O operations have completed. As I/O + * completion requires a lookup of the keyToChannel then we must close + * the channels when not holding the write lock. + */ + final int MAX_BATCH_SIZE = 32; + OverlappedChannel channels[] = new OverlappedChannel[MAX_BATCH_SIZE]; + int count; + do { + // grab a batch of up to 32 channels + keyToChannelLock.writeLock().lock(); + count = 0; + try { + for (Integer key: keyToChannel.keySet()) { + channels[count++] = keyToChannel.get(key); + if (count >= MAX_BATCH_SIZE) + break; + } + } finally { + keyToChannelLock.writeLock().unlock(); + } + + // close them + for (int i=0; i<count; i++) { + try { + channels[i].close(); + } catch (IOException ignore) { } + } + } while (count > 0); + } + + private void wakeup() { + try { + postQueuedCompletionStatus(port, 0); + } catch (IOException e) { + // should not happen + throw new AssertionError(e); + } + } + + @Override + void executeOnHandlerTask(Runnable task) { + synchronized (this) { + if (closed) + throw new RejectedExecutionException(); + offerTask(task); + wakeup(); + } + + } + + @Override + void shutdownHandlerTasks() { + // shutdown all handler threads + int nThreads = threadCount(); + while (nThreads-- > 0) { + wakeup(); + } + } + + /** + * Associate the given handle with this group + */ + int associate(OverlappedChannel ch, long handle) throws IOException { + keyToChannelLock.writeLock().lock(); + + // generate a completion key (if not shutdown) + int key; + try { + if (isShutdown()) + throw new ShutdownChannelGroupException(); + + // generate unique key + do { + key = nextCompletionKey++; + } while ((key == 0) || keyToChannel.containsKey(key)); + + // associate with I/O completion port + if (handle != 0L) + createIoCompletionPort(handle, port, key, 0); + + // setup mapping + keyToChannel.put(key, ch); + } finally { + keyToChannelLock.writeLock().unlock(); + } + return key; + } + + /** + * Disassociate channel from the group. + */ + void disassociate(int key) { + boolean checkForShutdown = false; + + keyToChannelLock.writeLock().lock(); + try { + keyToChannel.remove(key); + + // last key to be removed so check if group is shutdown + if (keyToChannel.isEmpty()) + checkForShutdown = true; + + } finally { + keyToChannelLock.writeLock().unlock(); + } + + // continue shutdown + if (checkForShutdown && isShutdown()) { + try { + shutdownNow(); + } catch (IOException ignore) { } + } + } + + /** + * Invoked when a channel associated with this port is closed before + * notifications for all outstanding I/O operations have been received. + */ + void makeStale(Long overlapped) { + synchronized (staleIoSet) { + staleIoSet.add(overlapped); + } + } + + /** + * Checks if the given OVERLAPPED is stale and if so, releases it. + */ + private void checkIfStale(long ov) { + synchronized (staleIoSet) { + boolean removed = staleIoSet.remove(ov); + if (removed) { + unsafe.freeMemory(ov); + } + } + } + + /** + * The handler for consuming the result of an asynchronous I/O operation. + */ + static interface ResultHandler { + /** + * Invoked if the I/O operation completes successfully. + */ + public void completed(int bytesTransferred); + + /** + * Invoked if the I/O operation fails. + */ + public void failed(int error, IOException ioe); + } + + // Creates IOException for the given I/O error. + private static IOException translateErrorToIOException(int error) { + String msg = getErrorMessage(error); + if (msg == null) + msg = "Unknown error: 0x0" + Integer.toHexString(error); + return new IOException(msg); + } + + /** + * Long-running task servicing system-wide or per-file completion port + */ + private class EventHandlerTask implements Runnable { + public void run() { + Invoker.GroupAndInvokeCount myGroupAndInvokeCount = + Invoker.getGroupAndInvokeCount(); + CompletionStatus ioResult = new CompletionStatus(); + boolean replaceMe = false; + + try { + for (;;) { + // reset invoke count + if (myGroupAndInvokeCount != null) + myGroupAndInvokeCount.resetInvokeCount(); + + // wait for I/O completion event + // A error here is fatal (thread will not be replaced) + replaceMe = false; + try { + getQueuedCompletionStatus(port, ioResult); + } catch (IOException x) { + // should not happen + x.printStackTrace(); + return; + } + + // handle wakeup to execute task or shutdown + if (ioResult.completionKey() == 0 && + ioResult.overlapped() == 0L) + { + Runnable task = pollTask(); + if (task == null) { + // shutdown request + return; + } + + // run task + // (if error/exception then replace thread) + replaceMe = true; + task.run(); + continue; + } + + // map key to channel + OverlappedChannel ch = null; + keyToChannelLock.readLock().lock(); + try { + ch = keyToChannel.get(ioResult.completionKey()); + if (ch == null) { + checkIfStale(ioResult.overlapped()); + continue; + } + } finally { + keyToChannelLock.readLock().unlock(); + } + + // lookup I/O request + PendingFuture<?,?> result = ch.getByOverlapped(ioResult.overlapped()); + if (result == null) { + // we get here if the OVERLAPPED structure is associated + // with an I/O operation on a channel that was closed + // but the I/O operation event wasn't read in a timely + // manner. Alternatively, it may be related to a + // tryLock operation as the OVERLAPPED structures for + // these operations are not in the I/O cache. + checkIfStale(ioResult.overlapped()); + continue; + } + + // synchronize on result in case I/O completed immediately + // and was handled by initiator + synchronized (result) { + if (result.isDone()) { + continue; + } + // not handled by initiator + } + + // invoke I/O result handler + int error = ioResult.error(); + ResultHandler rh = (ResultHandler)result.getContext(); + replaceMe = true; // (if error/exception then replace thread) + if (error == 0) { + rh.completed(ioResult.bytesTransferred()); + } else { + rh.failed(error, translateErrorToIOException(error)); + } + } + } finally { + // last thread to exit when shutdown releases resources + int remaining = threadExit(this, replaceMe); + if (remaining == 0 && isShutdown()) { + implClose(); + } + } + } + } + + /** + * Container for data returned by GetQueuedCompletionStatus + */ + private static class CompletionStatus { + private int error; + private int bytesTransferred; + private int completionKey; + private long overlapped; + + private CompletionStatus() { } + int error() { return error; } + int bytesTransferred() { return bytesTransferred; } + int completionKey() { return completionKey; } + long overlapped() { return overlapped; } + } + + // -- native methods -- + + private static native void initIDs(); + + private static native long createIoCompletionPort(long handle, + long existingPort, int completionKey, int concurrency) throws IOException; + + private static native void close0(long handle); + + private static native void getQueuedCompletionStatus(long completionPort, + CompletionStatus status) throws IOException; + + private static native void postQueuedCompletionStatus(long completionPort, + int completionKey) throws IOException; + + private static native String getErrorMessage(int error); + + static { + Util.load(); + initIDs(); + } +} diff --git a/src/windows/classes/sun/nio/ch/PendingIoCache.java b/src/windows/classes/sun/nio/ch/PendingIoCache.java new file mode 100644 index 0000000000000000000000000000000000000000..2e3d50385fc945dfb05ced2e02dae10b1f07f064 --- /dev/null +++ b/src/windows/classes/sun/nio/ch/PendingIoCache.java @@ -0,0 +1,161 @@ +/* + * Copyright 2008-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 sun.nio.ch; + +import java.nio.channels.*; +import java.util.*; +import sun.misc.Unsafe; + +/** + * Maintains a mapping of pending I/O requests (identified by the address of + * an OVERLAPPED structure) to Futures. + */ + +class PendingIoCache { + private static final Unsafe unsafe = Unsafe.getUnsafe(); + private static final int addressSize = unsafe.addressSize(); + + private static int dependsArch(int value32, int value64) { + return (addressSize == 4) ? value32 : value64; + } + + /* + * typedef struct _OVERLAPPED { + * DWORD Internal; + * DWORD InternalHigh; + * DWORD Offset; + * DWORD OffsetHigh; + * HANDLE hEvent; + * } OVERLAPPED; + */ + private static final int SIZEOF_OVERLAPPED = dependsArch(20, 32); + + // set to true when closed + private boolean closed; + + // set to true when thread is waiting for all I/O operations to complete + private boolean closePending; + + // maps OVERLAPPED to PendingFuture + private final Map<Long,PendingFuture> pendingIoMap = + new HashMap<Long,PendingFuture>(); + + // per-channel cache of OVERLAPPED structures + private long[] overlappedCache = new long[4]; + private int overlappedCacheCount = 0; + + PendingIoCache() { + } + + long add(PendingFuture<?,?> result) { + synchronized (this) { + if (closed) + throw new AssertionError("Should not get here"); + long ov; + if (overlappedCacheCount > 0) { + ov = overlappedCache[--overlappedCacheCount]; + } else { + ov = unsafe.allocateMemory(SIZEOF_OVERLAPPED); + } + pendingIoMap.put(ov, result); + return ov; + } + } + + @SuppressWarnings("unchecked") + <V,A> PendingFuture<V,A> remove(long overlapped) { + synchronized (this) { + PendingFuture<V,A> res = pendingIoMap.remove(overlapped); + if (res != null) { + if (overlappedCacheCount < overlappedCache.length) { + overlappedCache[overlappedCacheCount++] = overlapped; + } else { + // cache full or channel closing + unsafe.freeMemory(overlapped); + } + // notify closing thread. + if (closePending) { + this.notifyAll(); + } + } + return res; + } + } + + void close() { + synchronized (this) { + if (closed) + return; + + // handle the case that where there are I/O operations that have + // not completed. + if (!pendingIoMap.isEmpty()) + clearPendingIoMap(); + + // release memory for any cached OVERLAPPED structures + while (overlappedCacheCount > 0) { + unsafe.freeMemory( overlappedCache[--overlappedCacheCount] ); + } + + // done + closed = true; + } + } + + private void clearPendingIoMap() { + assert Thread.holdsLock(this); + + // wait up to 50ms for the I/O operations to complete + closePending = true; + try { + this.wait(50); + } catch (InterruptedException x) { } + closePending = false; + if (pendingIoMap.isEmpty()) + return; + + // cause all pending I/O operations to fail + // simulate the failure of all pending I/O operations. + for (Long ov: pendingIoMap.keySet()) { + PendingFuture<?,?> result = pendingIoMap.get(ov); + assert !result.isDone(); + + // make I/O port aware of the stale OVERLAPPED structure + Iocp iocp = (Iocp)((Groupable)result.channel()).group(); + iocp.makeStale(ov); + + // execute a task that invokes the result handler's failed method + final Iocp.ResultHandler rh = (Iocp.ResultHandler)result.getContext(); + Runnable task = new Runnable() { + public void run() { + rh.failed(-1, new AsynchronousCloseException()); + } + }; + iocp.executeOnPooledThread(task); + } + pendingIoMap.clear(); + } +} diff --git a/src/windows/classes/sun/nio/ch/WindowsAsynchronousChannelProvider.java b/src/windows/classes/sun/nio/ch/WindowsAsynchronousChannelProvider.java new file mode 100644 index 0000000000000000000000000000000000000000..435b5297b2e79f0de4da021211a5122000d45bc3 --- /dev/null +++ b/src/windows/classes/sun/nio/ch/WindowsAsynchronousChannelProvider.java @@ -0,0 +1,101 @@ +/* + * Copyright 2008-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 sun.nio.ch; + +import java.nio.channels.*; +import java.nio.channels.spi.AsynchronousChannelProvider; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.ThreadFactory; +import java.net.ProtocolFamily; +import java.io.IOException; + +public class WindowsAsynchronousChannelProvider + extends AsynchronousChannelProvider +{ + private static volatile Iocp defaultIocp; + + public WindowsAsynchronousChannelProvider() { + // nothing to do + } + + private Iocp defaultIocp() throws IOException { + if (defaultIocp == null) { + synchronized (WindowsAsynchronousChannelProvider.class) { + if (defaultIocp == null) { + // default thread pool may be shared with AsynchronousFileChannels + defaultIocp = new Iocp(this, ThreadPool.getDefault()).start(); + } + } + } + return defaultIocp; + } + + @Override + public AsynchronousChannelGroup openAsynchronousChannelGroup(int nThreads, ThreadFactory factory) + throws IOException + { + return new Iocp(this, ThreadPool.create(nThreads, factory)).start(); + } + + @Override + public AsynchronousChannelGroup openAsynchronousChannelGroup(ExecutorService executor, int initialSize) + throws IOException + { + return new Iocp(this, ThreadPool.wrap(executor, initialSize)).start(); + } + + private Iocp toIocp(AsynchronousChannelGroup group) throws IOException { + if (group == null) { + return defaultIocp(); + } else { + if (!(group instanceof Iocp)) + throw new IllegalChannelGroupException(); + return (Iocp)group; + } + } + + @Override + public AsynchronousServerSocketChannel openAsynchronousServerSocketChannel(AsynchronousChannelGroup group) + throws IOException + { + return new WindowsAsynchronousServerSocketChannelImpl(toIocp(group)); + } + + @Override + public AsynchronousSocketChannel openAsynchronousSocketChannel(AsynchronousChannelGroup group) + throws IOException + { + return new WindowsAsynchronousSocketChannelImpl(toIocp(group)); + } + + @Override + public AsynchronousDatagramChannel openAsynchronousDatagramChannel(ProtocolFamily family, + AsynchronousChannelGroup group) + throws IOException + { + return new SimpleAsynchronousDatagramChannelImpl(family, toIocp(group)); + } +} diff --git a/src/windows/classes/sun/nio/ch/WindowsAsynchronousFileChannelImpl.java b/src/windows/classes/sun/nio/ch/WindowsAsynchronousFileChannelImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..ef668648d673eaca7ff103a2e2da0192768b46c2 --- /dev/null +++ b/src/windows/classes/sun/nio/ch/WindowsAsynchronousFileChannelImpl.java @@ -0,0 +1,741 @@ +/* + * Copyright 2008-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 sun.nio.ch; + +import java.nio.channels.*; +import java.util.concurrent.*; +import java.nio.ByteBuffer; +import java.nio.BufferOverflowException; +import java.io.IOException; +import java.io.FileDescriptor; +import sun.misc.SharedSecrets; +import sun.misc.JavaIOFileDescriptorAccess; + +/** + * Windows implementation of AsynchronousFileChannel using overlapped I/O. + */ + +public class WindowsAsynchronousFileChannelImpl + extends AsynchronousFileChannelImpl + implements Iocp.OverlappedChannel, Groupable +{ + private static final JavaIOFileDescriptorAccess fdAccess = + SharedSecrets.getJavaIOFileDescriptorAccess(); + + // error when EOF is detected asynchronously. + private static final int ERROR_HANDLE_EOF = 38; + + // Lazy initialization of default I/O completion port + private static class DefaultIocpHolder { + static final Iocp defaultIocp = defaultIocp(); + private static Iocp defaultIocp() { + try { + return new Iocp(null, ThreadPool.createDefault()).start(); + } catch (IOException ioe) { + InternalError e = new InternalError(); + e.initCause(ioe); + throw e; + } + } + } + + // Used for force/truncate/size methods + private static final FileDispatcher nd = new FileDispatcherImpl(); + + // The handle is extracted for use in native methods invoked from this class. + private final long handle; + + // The key that identifies the channel's association with the I/O port + private final int completionKey; + + // I/O completion port (group) + private final Iocp iocp; + + private final boolean isDefaultIocp; + + // Caches OVERLAPPED structure for each outstanding I/O operation + private final PendingIoCache ioCache; + + + private WindowsAsynchronousFileChannelImpl(FileDescriptor fdObj, + boolean reading, + boolean writing, + Iocp iocp, + boolean isDefaultIocp) + throws IOException + { + super(fdObj, reading, writing, iocp.executor()); + this.handle = fdAccess.getHandle(fdObj); + this.iocp = iocp; + this.isDefaultIocp = isDefaultIocp; + this.ioCache = new PendingIoCache(); + this.completionKey = iocp.associate(this, handle); + } + + public static AsynchronousFileChannel open(FileDescriptor fdo, + boolean reading, + boolean writing, + ThreadPool pool) + throws IOException + { + Iocp iocp; + boolean isDefaultIocp; + if (pool == null) { + iocp = DefaultIocpHolder.defaultIocp; + isDefaultIocp = true; + } else { + iocp = new Iocp(null, pool).start(); + isDefaultIocp = false; + } + try { + return new + WindowsAsynchronousFileChannelImpl(fdo, reading, writing, iocp, isDefaultIocp); + } catch (IOException x) { + // error binding to port so need to close it (if created for this channel) + if (!isDefaultIocp) + iocp.implClose(); + throw x; + } + } + + @Override + public <V,A> PendingFuture<V,A> getByOverlapped(long overlapped) { + return ioCache.remove(overlapped); + } + + @Override + public void close() throws IOException { + closeLock.writeLock().lock(); + try { + if (closed) + return; // already closed + closed = true; + } finally { + closeLock.writeLock().unlock(); + } + + // invalidate all locks held for this channel + invalidateAllLocks(); + + // close the file + close0(handle); + + // waits until all I/O operations have completed + ioCache.close(); + + // disassociate from port and shutdown thread pool if not default + iocp.disassociate(completionKey); + if (!isDefaultIocp) + iocp.shutdown(); + } + + @Override + public AsynchronousChannelGroupImpl group() { + return iocp; + } + + /** + * Translates Throwable to IOException + */ + private static IOException toIOException(Throwable x) { + if (x instanceof IOException) { + if (x instanceof ClosedChannelException) + x = new AsynchronousCloseException(); + return (IOException)x; + } + return new IOException(x); + } + + @Override + public long size() throws IOException { + try { + begin(); + return nd.size(fdObj); + } finally { + end(); + } + } + + @Override + public AsynchronousFileChannel truncate(long size) throws IOException { + if (size < 0) + throw new IllegalArgumentException("Negative size"); + if (!writing) + throw new NonWritableChannelException(); + try { + begin(); + if (size > nd.size(fdObj)) + return this; + nd.truncate(fdObj, size); + } finally { + end(); + } + return this; + } + + @Override + public void force(boolean metaData) throws IOException { + try { + begin(); + nd.force(fdObj, metaData); + } finally { + end(); + } + } + + // -- file locking -- + + /** + * Task that initiates locking operation and handles completion result. + */ + private class LockTask<A> implements Runnable, Iocp.ResultHandler { + private final long position; + private final FileLockImpl fli; + private final PendingFuture<FileLock,A> result; + + LockTask(long position, + FileLockImpl fli, + PendingFuture<FileLock,A> result) + { + this.position = position; + this.fli = fli; + this.result = result; + } + + @Override + public void run() { + long overlapped = 0L; + try { + begin(); + + // allocate OVERLAPPED structure + overlapped = ioCache.add(result); + + // synchronize on result to avoid race with handler thread + // when lock is acquired immediately. + synchronized (result) { + int n = lockFile(handle, position, fli.size(), fli.isShared(), + overlapped); + if (n == IOStatus.UNAVAILABLE) { + // I/O is pending + return; + } + // acquired lock immediately + result.setResult(fli); + } + + } catch (Throwable x) { + // lock failed or channel closed + removeFromFileLockTable(fli); + if (overlapped != 0L) + ioCache.remove(overlapped); + result.setFailure(toIOException(x)); + } finally { + end(); + } + + // invoke completion handler + Invoker.invoke(result.handler(), result); + } + + @Override + public void completed(int bytesTransferred) { + // release waiters and invoke completion handler + result.setResult(fli); + Invoker.invoke(result.handler(), result); + } + + @Override + public void failed(int error, IOException x) { + // lock not acquired so remove from lock table + removeFromFileLockTable(fli); + + // release waiters + if (isOpen()) { + result.setFailure(x); + } else { + result.setFailure(new AsynchronousCloseException()); + } + Invoker.invoke(result.handler(), result); + } + } + + @Override + public <A> Future<FileLock> lock(long position, + long size, + boolean shared, + A attachment, + CompletionHandler<FileLock,? super A> handler) + { + if (shared && !reading) + throw new NonReadableChannelException(); + if (!shared && !writing) + throw new NonWritableChannelException(); + + // add to lock table + FileLockImpl fli = addToFileLockTable(position, size, shared); + if (fli == null) { + CompletedFuture<FileLock,A> result = CompletedFuture + .withFailure(this, new ClosedChannelException(), attachment); + Invoker.invoke(handler, result); + return result; + } + + // create Future and task that will be invoked to acquire lock + PendingFuture<FileLock,A> result = + new PendingFuture<FileLock,A>(this, handler, attachment); + LockTask lockTask = new LockTask<A>(position, fli, result); + result.setContext(lockTask); + + // initiate I/O (can only be done from thread in thread pool) + try { + Invoker.invokeOnThreadInThreadPool(this, lockTask); + } catch (ShutdownChannelGroupException e) { + // rollback + removeFromFileLockTable(fli); + throw e; + } + return result; + } + + static final int NO_LOCK = -1; // Failed to lock + static final int LOCKED = 0; // Obtained requested lock + + @Override + public FileLock tryLock(long position, long size, boolean shared) + throws IOException + { + if (shared && !reading) + throw new NonReadableChannelException(); + if (!shared && !writing) + throw new NonWritableChannelException(); + + // add to lock table + final FileLockImpl fli = addToFileLockTable(position, size, shared); + if (fli == null) + throw new ClosedChannelException(); + + boolean gotLock = false; + try { + begin(); + // try to acquire the lock + int res = nd.lock(fdObj, false, position, size, shared); + if (res == NO_LOCK) + return null; + gotLock = true; + return fli; + } finally { + if (!gotLock) + removeFromFileLockTable(fli); + end(); + } + } + + // invoke by FileFileImpl to release lock + @Override + void release(FileLockImpl fli) throws IOException { + try { + begin(); + nd.release(fdObj, fli.position(), fli.size()); + removeFromFileLockTable(fli); + } finally { + end(); + } + } + + /** + * Task that initiates read operation and handles completion result. + */ + private class ReadTask<A> implements Runnable, Iocp.ResultHandler { + private final ByteBuffer dst; + private final int pos, rem; // buffer position/remaining + private final long position; // file position + private final PendingFuture<Integer,A> result; + + // set to dst if direct; otherwise set to substituted direct buffer + private volatile ByteBuffer buf; + + ReadTask(ByteBuffer dst, + int pos, + int rem, + long position, + PendingFuture<Integer,A> result) + { + this.dst = dst; + this.pos = pos; + this.rem = rem; + this.position = position; + this.result = result; + } + + void releaseBufferIfSubstituted() { + if (buf != dst) + Util.releaseTemporaryDirectBuffer(buf); + } + + void updatePosition(int bytesTransferred) { + // if the I/O succeeded then adjust buffer position + if (bytesTransferred > 0) { + if (buf == dst) { + try { + dst.position(pos + bytesTransferred); + } catch (IllegalArgumentException x) { + // someone has changed the position; ignore + } + } else { + // had to substitute direct buffer + buf.position(bytesTransferred).flip(); + try { + dst.put(buf); + } catch (BufferOverflowException x) { + // someone has changed the position; ignore + } + } + } + } + + @Override + public void run() { + int n = -1; + long overlapped = 0L; + long address; + + // Substitute a native buffer if not direct + if (dst instanceof DirectBuffer) { + buf = dst; + address = ((DirectBuffer)dst).address() + pos; + } else { + buf = Util.getTemporaryDirectBuffer(rem); + address = ((DirectBuffer)buf).address(); + } + + try { + begin(); + + // allocate OVERLAPPED + overlapped = ioCache.add(result); + + // synchronize on result to allow this thread handle the case + // where the read completes immediately. + synchronized (result) { + n = readFile(handle, address, rem, position, overlapped); + if (n == IOStatus.UNAVAILABLE) { + // I/O is pending + return; + } + // read completed immediately: + // 1. update buffer position + // 2. release waiters + updatePosition(n); + result.setResult(n); + } + } catch (Throwable x) { + // failed to initiate read + result.setFailure(toIOException(x)); + } finally { + end(); + } + + // read failed or EOF so completion port will not be notified + if (n < 0 && overlapped != 0L) { + ioCache.remove(overlapped); + } + + // return direct buffer to cache if substituted + releaseBufferIfSubstituted(); + + // invoke completion handler + Invoker.invoke(result.handler(), result); + } + + /** + * Executed when the I/O has completed + */ + @Override + public void completed(int bytesTransferred) { + updatePosition(bytesTransferred); + + // return direct buffer to cache if substituted + releaseBufferIfSubstituted(); + + // release waiters and invoke completion handler + result.setResult(bytesTransferred); + Invoker.invoke(result.handler(), result); + } + + @Override + public void failed(int error, IOException x) { + // if EOF detected asynchronously then it is reported as error + if (error == ERROR_HANDLE_EOF) { + completed(-1); + } else { + // return direct buffer to cache if substituted + releaseBufferIfSubstituted(); + + // release waiters + if (isOpen()) { + result.setFailure(x); + } else { + result.setFailure(new AsynchronousCloseException()); + } + Invoker.invoke(result.handler(), result); + } + } + } + + @Override + public <A> Future<Integer> read(ByteBuffer dst, + long position, + A attachment, + CompletionHandler<Integer,? super A> handler) + { + if (!reading) + throw new NonReadableChannelException(); + if (position < 0) + throw new IllegalArgumentException("Negative position"); + if (dst.isReadOnly()) + throw new IllegalArgumentException("Read-only buffer"); + + // check if channel is closed + if (!isOpen()) { + CompletedFuture<Integer,A> result = CompletedFuture + .withFailure(this, new ClosedChannelException(), attachment); + Invoker.invoke(handler, result); + return result; + } + + int pos = dst.position(); + int lim = dst.limit(); + assert (pos <= lim); + int rem = (pos <= lim ? lim - pos : 0); + + // no space remaining + if (rem == 0) { + CompletedFuture<Integer,A> result = + CompletedFuture.withResult(this, 0, attachment); + Invoker.invoke(handler, result); + return result; + } + + // create Future and task that initiates read + PendingFuture<Integer,A> result = + new PendingFuture<Integer,A>(this, handler, attachment); + ReadTask readTask = new ReadTask<A>(dst, pos, rem, position, result); + result.setContext(readTask); + + // initiate I/O (can only be done from thread in thread pool) + Invoker.invokeOnThreadInThreadPool(this, readTask); + return result; + } + + /** + * Task that initiates write operation and handles completion result. + */ + private class WriteTask<A> implements Runnable, Iocp.ResultHandler { + private final ByteBuffer src; + private final int pos, rem; // buffer position/remaining + private final long position; // file position + private final PendingFuture<Integer,A> result; + + // set to src if direct; otherwise set to substituted direct buffer + private volatile ByteBuffer buf; + + WriteTask(ByteBuffer src, + int pos, + int rem, + long position, + PendingFuture<Integer,A> result) + { + this.src = src; + this.pos = pos; + this.rem = rem; + this.position = position; + this.result = result; + } + + void releaseBufferIfSubstituted() { + if (buf != src) + Util.releaseTemporaryDirectBuffer(buf); + } + + void updatePosition(int bytesTransferred) { + // if the I/O succeeded then adjust buffer position + if (bytesTransferred > 0) { + try { + src.position(pos + bytesTransferred); + } catch (IllegalArgumentException x) { + // someone has changed the position + } + } + } + + @Override + public void run() { + int n = -1; + long overlapped = 0L; + long address; + + // Substitute a native buffer if not direct + if (src instanceof DirectBuffer) { + buf = src; + address = ((DirectBuffer)src).address() + pos; + } else { + buf = Util.getTemporaryDirectBuffer(rem); + buf.put(src); + buf.flip(); + // temporarily restore position as we don't know how many bytes + // will be written + src.position(pos); + address = ((DirectBuffer)buf).address(); + } + + try { + begin(); + + // allocate an OVERLAPPED structure + overlapped = ioCache.add(result); + + // synchronize on result to allow this thread handle the case + // where the read completes immediately. + synchronized (result) { + n = writeFile(handle, address, rem, position, overlapped); + if (n == IOStatus.UNAVAILABLE) { + // I/O is pending + return; + } + // read completed immediately: + // 1. update buffer position + // 2. release waiters + updatePosition(n); + result.setResult(n); + } + } catch (Throwable x) { + // failed to initiate read: + result.setFailure(toIOException(x)); + + // release resources + if (overlapped != 0L) + ioCache.remove(overlapped); + releaseBufferIfSubstituted(); + + } finally { + end(); + } + + // invoke completion handler + Invoker.invoke(result.handler(), result); + } + + /** + * Executed when the I/O has completed + */ + @Override + public void completed(int bytesTransferred) { + updatePosition(bytesTransferred); + + // return direct buffer to cache if substituted + releaseBufferIfSubstituted(); + + // release waiters and invoke completion handler + result.setResult(bytesTransferred); + Invoker.invoke(result.handler(), result); + } + + @Override + public void failed(int error, IOException x) { + // return direct buffer to cache if substituted + releaseBufferIfSubstituted(); + + // release waiters and invoker completion handler + if (isOpen()) { + result.setFailure(x); + } else { + result.setFailure(new AsynchronousCloseException()); + } + Invoker.invoke(result.handler(), result); + } + } + + @Override + public <A> Future<Integer> write(ByteBuffer src, + long position, + A attachment, + CompletionHandler<Integer,? super A> handler) + { + if (!writing) + throw new NonWritableChannelException(); + if (position < 0) + throw new IllegalArgumentException("Negative position"); + + // check if channel is closed + if (!isOpen()) { + CompletedFuture<Integer,A> result = CompletedFuture + .withFailure(this, new ClosedChannelException(), attachment); + Invoker.invoke(handler, result); + return result; + } + + int pos = src.position(); + int lim = src.limit(); + assert (pos <= lim); + int rem = (pos <= lim ? lim - pos : 0); + + // nothing to write + if (rem == 0) { + CompletedFuture<Integer,A> result = + CompletedFuture.withResult(this, 0, attachment); + Invoker.invoke(handler, result); + return result; + } + + // create Future and task to initiate write + PendingFuture<Integer,A> result = + new PendingFuture<Integer,A>(this, handler, attachment); + WriteTask writeTask = new WriteTask<A>(src, pos, rem, position, result); + result.setContext(writeTask); + + // initiate I/O (can only be done from thread in thread pool) + Invoker.invokeOnThreadInThreadPool(this, writeTask); + return result; + } + + // -- Native methods -- + + private static native int readFile(long handle, long address, int len, + long offset, long overlapped) throws IOException; + + private static native int writeFile(long handle, long address, int len, + long offset, long overlapped) throws IOException; + + private static native int lockFile(long handle, long position, long size, + boolean shared, long overlapped) throws IOException; + + private static native void close0(long handle); + + static { + Util.load(); + } +} diff --git a/src/windows/classes/sun/nio/ch/WindowsAsynchronousServerSocketChannelImpl.java b/src/windows/classes/sun/nio/ch/WindowsAsynchronousServerSocketChannelImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..8efb10d75e68c9c6873a432fdc1bf9815e72773e --- /dev/null +++ b/src/windows/classes/sun/nio/ch/WindowsAsynchronousServerSocketChannelImpl.java @@ -0,0 +1,367 @@ +/* + * Copyright 2008-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 sun.nio.ch; + +import java.nio.channels.*; +import java.net.InetSocketAddress; +import java.util.concurrent.Future; +import java.util.concurrent.atomic.AtomicBoolean; +import java.io.IOException; +import java.security.AccessControlContext; +import java.security.AccessController; +import java.security.PrivilegedAction; +import sun.misc.Unsafe; + +/** + * Windows implementation of AsynchronousServerSocketChannel using overlapped I/O. + */ + +class WindowsAsynchronousServerSocketChannelImpl + extends AsynchronousServerSocketChannelImpl implements Iocp.OverlappedChannel +{ + private static final Unsafe unsafe = Unsafe.getUnsafe(); + + // 2 * (sizeof(SOCKET_ADDRESS) + 16) + private static final int DATA_BUFFER_SIZE = 88; + + private final long handle; + private final int completionKey; + private final Iocp iocp; + + // typically there will be zero, or one I/O operations pending. In rare + // cases there may be more. These rare cases arise when a sequence of accept + // operations complete immediately and handled by the initiating thread. + // The corresponding OVERLAPPED cannot be reused/released until the completion + // event has been posted. + private final PendingIoCache ioCache; + + // the data buffer to receive the local/remote socket address + private final long dataBuffer; + + // flag to indicate that an accept operation is outstanding + private AtomicBoolean accepting = new AtomicBoolean(); + + + WindowsAsynchronousServerSocketChannelImpl(Iocp iocp) throws IOException { + super(iocp); + + // associate socket with given completion port + long h = IOUtil.fdVal(fd); + int key; + try { + key = iocp.associate(this, h); + } catch (IOException x) { + closesocket0(h); // prevent leak + throw x; + } + + this.handle = h; + this.completionKey = key; + this.iocp = iocp; + this.ioCache = new PendingIoCache(); + this.dataBuffer = unsafe.allocateMemory(DATA_BUFFER_SIZE); + } + + @Override + public <V,A> PendingFuture<V,A> getByOverlapped(long overlapped) { + return ioCache.remove(overlapped); + } + + @Override + void implClose() throws IOException { + // close socket (which may cause outstanding accept to be aborted). + closesocket0(handle); + + // waits until the accept operations have completed + ioCache.close(); + + // finally disassociate from the completion port + iocp.disassociate(completionKey); + + // release other resources + unsafe.freeMemory(dataBuffer); + } + + @Override + public AsynchronousChannelGroupImpl group() { + return iocp; + } + + /** + * Task to initiate accept operation and to handle result. + */ + private class AcceptTask<A> implements Runnable, Iocp.ResultHandler { + private final WindowsAsynchronousSocketChannelImpl channel; + private final AccessControlContext acc; + private final PendingFuture<AsynchronousSocketChannel,A> result; + + AcceptTask(WindowsAsynchronousSocketChannelImpl channel, + AccessControlContext acc, + PendingFuture<AsynchronousSocketChannel,A> result) + { + this.channel = channel; + this.acc = acc; + this.result = result; + } + + void enableAccept() { + accepting.set(false); + } + + void closeChildChannel() { + try { + channel.close(); + } catch (IOException ignore) { } + } + + // caller must have acquired read lock for the listener and child channel. + void finishAccept() throws IOException { + /** + * Set local/remote addresses. This is currently very inefficient + * in that it requires 2 calls to getsockname and 2 calls to getpeername. + * (should change this to use GetAcceptExSockaddrs) + */ + updateAcceptContext(handle, channel.handle()); + + InetSocketAddress local = Net.localAddress(channel.fd); + final InetSocketAddress remote = Net.remoteAddress(channel.fd); + channel.setConnected(local, remote); + + // permission check (in context of initiating thread) + if (acc != null) { + AccessController.doPrivileged(new PrivilegedAction<Void>() { + public Void run() { + SecurityManager sm = System.getSecurityManager(); + sm.checkAccept(remote.getAddress().getHostAddress(), + remote.getPort()); + return null; + } + }, acc); + } + } + + /** + * Initiates the accept operation. + */ + @Override + public void run() { + long overlapped = 0L; + + try { + // begin usage of listener socket + begin(); + try { + // begin usage of child socket (as it is registered with + // completion port and so may be closed in the event that + // the group is forcefully closed). + channel.begin(); + + synchronized (result) { + overlapped = ioCache.add(result); + + int n = accept0(handle, channel.handle(), overlapped, dataBuffer); + if (n == IOStatus.UNAVAILABLE) { + return; + } + + // connection accepted immediately + finishAccept(); + + // allow another accept before the result is set + enableAccept(); + result.setResult(channel); + } + } finally { + // end usage on child socket + channel.end(); + } + } catch (Throwable x) { + // failed to initiate accept so release resources + if (overlapped != 0L) + ioCache.remove(overlapped); + closeChildChannel(); + if (x instanceof ClosedChannelException) + x = new AsynchronousCloseException(); + if (!(x instanceof IOException) && !(x instanceof SecurityException)) + x = new IOException(x); + enableAccept(); + result.setFailure(x); + } finally { + // end of usage of listener socket + end(); + } + + // accept completed immediately but may not have executed on + // initiating thread in which case the operation may have been + // cancelled. + if (result.isCancelled()) { + closeChildChannel(); + } + + // invoke completion handler + Invoker.invokeIndirectly(result.handler(), result); + } + + /** + * Executed when the I/O has completed + */ + @Override + public void completed(int bytesTransferred) { + try { + // connection accept after group has shutdown + if (iocp.isShutdown()) { + throw new IOException(new ShutdownChannelGroupException()); + } + + // finish the accept + try { + begin(); + try { + channel.begin(); + finishAccept(); + } finally { + channel.end(); + } + } finally { + end(); + } + + // allow another accept before the result is set + enableAccept(); + result.setResult(channel); + } catch (Throwable x) { + enableAccept(); + closeChildChannel(); + if (x instanceof ClosedChannelException) + x = new AsynchronousCloseException(); + if (!(x instanceof IOException) && !(x instanceof SecurityException)) + x = new IOException(x); + result.setFailure(x); + } + + // if an async cancel has already cancelled the operation then + // close the new channel so as to free resources + if (result.isCancelled()) { + closeChildChannel(); + } + + // invoke handler (but not directly) + Invoker.invokeIndirectly(result.handler(), result); + } + + @Override + public void failed(int error, IOException x) { + enableAccept(); + closeChildChannel(); + + // release waiters + if (isOpen()) { + result.setFailure(x); + } else { + result.setFailure(new AsynchronousCloseException()); + } + Invoker.invokeIndirectly(result.handler(), result); + } + } + + @Override + public <A> Future<AsynchronousSocketChannel> accept(A attachment, + final CompletionHandler<AsynchronousSocketChannel,? super A> handler) + { + if (!isOpen()) { + CompletedFuture<AsynchronousSocketChannel,A> result = CompletedFuture + .withFailure(this, new ClosedChannelException(), attachment); + Invoker.invokeIndirectly(handler, result); + return result; + } + if (isAcceptKilled()) + throw new RuntimeException("Accept not allowed due to cancellation"); + + // ensure channel is bound to local address + if (localAddress == null) + throw new NotYetBoundException(); + + // create the socket that will be accepted. The creation of the socket + // is enclosed by a begin/end for the listener socket to ensure that + // we check that the listener is open and also to prevent the I/O + // port from being closed as the new socket is registered. + WindowsAsynchronousSocketChannelImpl ch = null; + IOException ioe = null; + try { + begin(); + ch = new WindowsAsynchronousSocketChannelImpl(iocp, false); + } catch (IOException x) { + ioe = x; + } finally { + end(); + } + if (ioe != null) { + CompletedFuture<AsynchronousSocketChannel,A> result = + CompletedFuture.withFailure(this, ioe, attachment); + Invoker.invokeIndirectly(handler, result); + return result; + } + + // need calling context when there is security manager as + // permission check may be done in a different thread without + // any application call frames on the stack + AccessControlContext acc = (System.getSecurityManager() == null) ? + null : AccessController.getContext(); + + PendingFuture<AsynchronousSocketChannel,A> result = + new PendingFuture<AsynchronousSocketChannel,A>(this, handler, attachment); + AcceptTask task = new AcceptTask<A>(ch, acc, result); + result.setContext(task); + + // check and set flag to prevent concurrent accepting + if (!accepting.compareAndSet(false, true)) + throw new AcceptPendingException(); + + // initiate accept. As I/O operations are tied to the initiating thread + // then it will only be invoked direcly if this thread is in the thread + // pool. If this thread is not in the thread pool when a task is + // submitted to initiate the accept. + Invoker.invokeOnThreadInThreadPool(this, task); + return result; + } + + // -- Native methods -- + + private static native void initIDs(); + + private static native int accept0(long listenSocket, long acceptSocket, + long overlapped, long dataBuffer) throws IOException; + + private static native void updateAcceptContext(long listenSocket, + long acceptSocket) throws IOException; + + private static native void closesocket0(long socket) throws IOException; + + static { + Util.load(); + initIDs(); + } +} diff --git a/src/windows/classes/sun/nio/ch/WindowsAsynchronousSocketChannelImpl.java b/src/windows/classes/sun/nio/ch/WindowsAsynchronousSocketChannelImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..d1f8c9307d5cac67d65e6ae167ac2f959e104a53 --- /dev/null +++ b/src/windows/classes/sun/nio/ch/WindowsAsynchronousSocketChannelImpl.java @@ -0,0 +1,911 @@ +/* + * Copyright 2008-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 sun.nio.ch; + +import java.nio.channels.*; +import java.nio.ByteBuffer; +import java.nio.BufferOverflowException; +import java.net.*; +import java.util.concurrent.*; +import java.io.IOException; +import sun.misc.Unsafe; + +/** + * Windows implementation of AsynchronousSocketChannel using overlapped I/O. + */ + +class WindowsAsynchronousSocketChannelImpl + extends AsynchronousSocketChannelImpl implements Iocp.OverlappedChannel +{ + private static final Unsafe unsafe = Unsafe.getUnsafe(); + private static int addressSize = unsafe.addressSize(); + + private static int dependsArch(int value32, int value64) { + return (addressSize == 4) ? value32 : value64; + } + + /* + * typedef struct _WSABUF { + * u_long len; + * char FAR * buf; + * } WSABUF; + */ + private static final int SIZEOF_WSABUF = dependsArch(8, 16); + private static final int OFFSETOF_LEN = 0; + private static final int OFFSETOF_BUF = dependsArch(4, 8); + + // maximum vector size for scatter/gather I/O + private static final int MAX_WSABUF = 16; + + private static final int SIZEOF_WSABUFARRAY = MAX_WSABUF * SIZEOF_WSABUF; + + + // socket handle. Use begin()/end() around each usage of this handle. + final long handle; + + // I/O completion port that the socket is associated with + private final Iocp iocp; + + // completion key to identify channel when I/O completes + private final int completionKey; + + // Pending I/O operations are tied to an OVERLAPPED structure that can only + // be released when the I/O completion event is posted to the completion + // port. Where I/O operations complete immediately then it is possible + // there may be more than two OVERLAPPED structures in use. + private final PendingIoCache ioCache; + + // per-channel arrays of WSABUF structures + private final long readBufferArray; + private final long writeBufferArray; + + + WindowsAsynchronousSocketChannelImpl(Iocp iocp, boolean failIfGroupShutdown) + throws IOException + { + super(iocp); + + // associate socket with default completion port + long h = IOUtil.fdVal(fd); + int key = 0; + try { + key = iocp.associate(this, h); + } catch (ShutdownChannelGroupException x) { + if (failIfGroupShutdown) { + closesocket0(h); + throw x; + } + } catch (IOException x) { + closesocket0(h); + throw x; + } + + this.handle = h; + this.iocp = iocp; + this.completionKey = key; + this.ioCache = new PendingIoCache(); + + // allocate WSABUF arrays + this.readBufferArray = unsafe.allocateMemory(SIZEOF_WSABUFARRAY); + this.writeBufferArray = unsafe.allocateMemory(SIZEOF_WSABUFARRAY); + } + + WindowsAsynchronousSocketChannelImpl(Iocp iocp) throws IOException { + this(iocp, true); + } + + @Override + public AsynchronousChannelGroupImpl group() { + return iocp; + } + + /** + * Invoked by Iocp when an I/O operation competes. + */ + @Override + public <V,A> PendingFuture<V,A> getByOverlapped(long overlapped) { + return ioCache.remove(overlapped); + } + + // invoked by WindowsAsynchronousServerSocketChannelImpl + long handle() { + return handle; + } + + // invoked by WindowsAsynchronousServerSocketChannelImpl when new connection + // accept + void setConnected(SocketAddress localAddress, SocketAddress remoteAddress) { + synchronized (stateLock) { + state = ST_CONNECTED; + this.localAddress = localAddress; + this.remoteAddress = remoteAddress; + } + } + + @Override + void implClose() throws IOException { + // close socket (may cause outstanding async I/O operations to fail). + closesocket0(handle); + + // waits until all I/O operations have completed + ioCache.close(); + + // release arrays of WSABUF structures + unsafe.freeMemory(readBufferArray); + unsafe.freeMemory(writeBufferArray); + + // finally disassociate from the completion port (key can be 0 if + // channel created when group is shutdown) + if (completionKey != 0) + iocp.disassociate(completionKey); + } + + @Override + public void onCancel(PendingFuture<?,?> task) { + if (task.getContext() instanceof ConnectTask) + killConnect(); + if (task.getContext() instanceof ReadTask) + killReading(); + if (task.getContext() instanceof WriteTask) + killWriting(); + } + + /** + * Implements the task to initiate a connection and the handler to + * consume the result when the connection is established (or fails). + */ + private class ConnectTask<A> implements Runnable, Iocp.ResultHandler { + private final InetSocketAddress remote; + private final PendingFuture<Void,A> result; + + ConnectTask(InetSocketAddress remote, PendingFuture<Void,A> result) { + this.remote = remote; + this.result = result; + } + + private void closeChannel() { + try { + close(); + } catch (IOException ignore) { } + } + + private IOException toIOException(Throwable x) { + if (x instanceof IOException) { + if (x instanceof ClosedChannelException) + x = new AsynchronousCloseException(); + return (IOException)x; + } + return new IOException(x); + } + + /** + * Invoke after a connection is successfully established. + */ + private void afterConnect() throws IOException { + updateConnectContext(handle); + synchronized (stateLock) { + state = ST_CONNECTED; + remoteAddress = remote; + } + } + + /** + * Task to initiate a connection. + */ + @Override + public void run() { + long overlapped = 0L; + Throwable exc = null; + try { + begin(); + + // synchronize on result to allow this thread handle the case + // where the connection is established immediately. + synchronized (result) { + overlapped = ioCache.add(result); + // initiate the connection + int n = connect0(handle, Net.isIPv6Available(), remote.getAddress(), + remote.getPort(), overlapped); + if (n == IOStatus.UNAVAILABLE) { + // connection is pending + return; + } + + // connection established immediately + afterConnect(); + result.setResult(null); + } + } catch (Throwable x) { + exc = x; + } finally { + end(); + } + + if (exc != null) { + if (overlapped != 0L) + ioCache.remove(overlapped); + closeChannel(); + result.setFailure(toIOException(exc)); + } + Invoker.invoke(result.handler(), result); + } + + /** + * Invoked by handler thread when connection established. + */ + @Override + public void completed(int bytesTransferred) { + Throwable exc = null; + try { + begin(); + afterConnect(); + result.setResult(null); + } catch (Throwable x) { + // channel is closed or unable to finish connect + exc = x; + } finally { + end(); + } + + // can't close channel while in begin/end block + if (exc != null) { + closeChannel(); + result.setFailure(toIOException(exc)); + } + + Invoker.invoke(result.handler(), result); + } + + /** + * Invoked by handler thread when failed to establish connection. + */ + @Override + public void failed(int error, IOException x) { + if (isOpen()) { + closeChannel(); + result.setFailure(x); + } else { + result.setFailure(new AsynchronousCloseException()); + } + Invoker.invoke(result.handler(), result); + } + } + + @Override + public <A> Future<Void> connect(SocketAddress remote, + A attachment, + CompletionHandler<Void,? super A> handler) + { + if (!isOpen()) { + CompletedFuture<Void,A> result = CompletedFuture + .withFailure(this, new ClosedChannelException(), attachment); + Invoker.invoke(handler, result); + return result; + } + + InetSocketAddress isa = Net.checkAddress(remote); + + // permission check + SecurityManager sm = System.getSecurityManager(); + if (sm != null) + sm.checkConnect(isa.getAddress().getHostAddress(), isa.getPort()); + + // check and update state + // ConnectEx requires the socket to be bound to a local address + IOException bindException = null; + synchronized (stateLock) { + if (state == ST_CONNECTED) + throw new AlreadyConnectedException(); + if (state == ST_PENDING) + throw new ConnectionPendingException(); + if (localAddress == null) { + try { + bind(new InetSocketAddress(0)); + } catch (IOException x) { + bindException = x; + } + } + if (bindException == null) + state = ST_PENDING; + } + + // handle bind failure + if (bindException != null) { + try { + close(); + } catch (IOException ignore) { } + CompletedFuture<Void,A> result = CompletedFuture + .withFailure(this, bindException, attachment); + Invoker.invoke(handler, result); + return result; + } + + // setup task + PendingFuture<Void,A> result = + new PendingFuture<Void,A>(this, handler, attachment); + ConnectTask task = new ConnectTask<A>(isa, result); + result.setContext(task); + + // initiate I/O (can only be done from thread in thread pool) + Invoker.invokeOnThreadInThreadPool(this, task); + return result; + } + + /** + * Implements the task to initiate a read and the handler to consume the + * result when the read completes. + */ + private class ReadTask<V,A> implements Runnable, Iocp.ResultHandler { + private final ByteBuffer[] bufs; + private final int numBufs; + private final boolean scatteringRead; + private final PendingFuture<V,A> result; + + // set by run method + private ByteBuffer[] shadow; + + ReadTask(ByteBuffer[] bufs, + boolean scatteringRead, + PendingFuture<V,A> result) + { + this.bufs = bufs; + this.numBufs = (bufs.length > MAX_WSABUF) ? MAX_WSABUF : bufs.length; + this.scatteringRead = scatteringRead; + this.result = result; + } + + /** + * Invoked prior to read to prepare the WSABUF array. Where necessary, + * it substitutes non-direct buffers with direct buffers. + */ + void prepareBuffers() { + shadow = new ByteBuffer[numBufs]; + long address = readBufferArray; + for (int i=0; i<numBufs; i++) { + ByteBuffer dst = bufs[i]; + int pos = dst.position(); + int lim = dst.limit(); + assert (pos <= lim); + int rem = (pos <= lim ? lim - pos : 0); + long a; + if (!(dst instanceof DirectBuffer)) { + // substitute with direct buffer + ByteBuffer bb = Util.getTemporaryDirectBuffer(rem); + shadow[i] = bb; + a = ((DirectBuffer)bb).address(); + } else { + shadow[i] = dst; + a = ((DirectBuffer)dst).address() + pos; + } + unsafe.putAddress(address + OFFSETOF_BUF, a); + unsafe.putInt(address + OFFSETOF_LEN, rem); + address += SIZEOF_WSABUF; + } + } + + /** + * Invoked after a read has completed to update the buffer positions + * and release any substituted buffers. + */ + void updateBuffers(int bytesRead) { + for (int i=0; i<numBufs; i++) { + ByteBuffer nextBuffer = shadow[i]; + int pos = nextBuffer.position(); + int len = nextBuffer.remaining(); + if (bytesRead >= len) { + bytesRead -= len; + int newPosition = pos + len; + try { + nextBuffer.position(newPosition); + } catch (IllegalArgumentException x) { + // position changed by another + } + } else { // Buffers not completely filled + if (bytesRead > 0) { + assert(pos + bytesRead < (long)Integer.MAX_VALUE); + int newPosition = pos + bytesRead; + try { + nextBuffer.position(newPosition); + } catch (IllegalArgumentException x) { + // position changed by another + } + } + break; + } + } + + // Put results from shadow into the slow buffers + for (int i=0; i<numBufs; i++) { + if (!(bufs[i] instanceof DirectBuffer)) { + shadow[i].flip(); + try { + bufs[i].put(shadow[i]); + } catch (BufferOverflowException x) { + // position changed by another + } + } + } + } + + void releaseBuffers() { + for (int i=0; i<numBufs; i++) { + if (!(bufs[i] instanceof DirectBuffer)) { + Util.releaseTemporaryDirectBuffer(shadow[i]); + } + } + } + + @Override + @SuppressWarnings("unchecked") + public void run() { + long overlapped = 0L; + boolean prepared = false; + boolean pending = false; + + try { + begin(); + + // substitute non-direct buffers + prepareBuffers(); + prepared = true; + + // get an OVERLAPPED structure (from the cache or allocate) + overlapped = ioCache.add(result); + + // synchronize on result to allow this thread handle the case + // where the read completes immediately. + synchronized (result) { + int n = read0(handle, numBufs, readBufferArray, overlapped); + if (n == IOStatus.UNAVAILABLE) { + // I/O is pending + pending = true; + return; + } + // read completed immediately: + // 1. update buffer position + // 2. reset read flag + // 3. release waiters + if (n == 0) { + n = -1; + } else { + updateBuffers(n); + } + enableReading(); + + if (scatteringRead) { + result.setResult((V)Long.valueOf(n)); + } else { + result.setResult((V)Integer.valueOf(n)); + } + } + } catch (Throwable x) { + // failed to initiate read: + // 1. reset read flag + // 2. free resources + // 3. release waiters + enableReading(); + if (overlapped != 0L) + ioCache.remove(overlapped); + if (x instanceof ClosedChannelException) + x = new AsynchronousCloseException(); + if (!(x instanceof IOException)) + x = new IOException(x); + result.setFailure(x); + } finally { + if (prepared && !pending) { + // return direct buffer(s) to cache if substituted + releaseBuffers(); + } + end(); + } + + // invoke completion handler + Invoker.invoke(result.handler(), result); + } + + /** + * Executed when the I/O has completed + */ + @Override + @SuppressWarnings("unchecked") + public void completed(int bytesTransferred) { + if (bytesTransferred == 0) { + bytesTransferred = -1; // EOF + } else { + updateBuffers(bytesTransferred); + } + + // return direct buffer to cache if substituted + releaseBuffers(); + + // release waiters if not already released by timeout + synchronized (result) { + if (result.isDone()) + return; + enableReading(); + if (scatteringRead) { + result.setResult((V)Long.valueOf(bytesTransferred)); + } else { + result.setResult((V)Integer.valueOf(bytesTransferred)); + } + } + Invoker.invoke(result.handler(), result); + } + + @Override + public void failed(int error, IOException x) { + // return direct buffer to cache if substituted + releaseBuffers(); + + // release waiters if not already released by timeout + if (!isOpen()) + x = new AsynchronousCloseException(); + + synchronized (result) { + if (result.isDone()) + return; + enableReading(); + result.setFailure(x); + } + Invoker.invoke(result.handler(), result); + } + + /** + * Invoked if timeout expires before it is cancelled + */ + void timeout() { + // synchronize on result as the I/O could complete/fail + synchronized (result) { + if (result.isDone()) + return; + + // kill further reading before releasing waiters + enableReading(true); + result.setFailure(new InterruptedByTimeoutException()); + } + + // invoke handler without any locks + Invoker.invoke(result.handler(), result); + } + } + + @Override + <V extends Number,A> Future<V> readImpl(ByteBuffer[] bufs, + boolean scatteringRead, + long timeout, + TimeUnit unit, + A attachment, + CompletionHandler<V,? super A> handler) + { + // setup task + PendingFuture<V,A> result = + new PendingFuture<V,A>(this, handler, attachment); + final ReadTask readTask = new ReadTask<V,A>(bufs, scatteringRead, result); + result.setContext(readTask); + + // schedule timeout + if (timeout > 0L) { + Future<?> timeoutTask = iocp.schedule(new Runnable() { + public void run() { + readTask.timeout(); + } + }, timeout, unit); + result.setTimeoutTask(timeoutTask); + } + + // initiate I/O (can only be done from thread in thread pool) + Invoker.invokeOnThreadInThreadPool(this, readTask); + return result; + } + + /** + * Implements the task to initiate a write and the handler to consume the + * result when the write completes. + */ + private class WriteTask<V,A> implements Runnable, Iocp.ResultHandler { + private final ByteBuffer[] bufs; + private final int numBufs; + private final boolean gatheringWrite; + private final PendingFuture<V,A> result; + + // set by run method + private ByteBuffer[] shadow; + + WriteTask(ByteBuffer[] bufs, + boolean gatheringWrite, + PendingFuture<V,A> result) + { + this.bufs = bufs; + this.numBufs = (bufs.length > MAX_WSABUF) ? MAX_WSABUF : bufs.length; + this.gatheringWrite = gatheringWrite; + this.result = result; + } + + /** + * Invoked prior to write to prepare the WSABUF array. Where necessary, + * it substitutes non-direct buffers with direct buffers. + */ + void prepareBuffers() { + shadow = new ByteBuffer[numBufs]; + long address = writeBufferArray; + for (int i=0; i<numBufs; i++) { + ByteBuffer src = bufs[i]; + int pos = src.position(); + int lim = src.limit(); + assert (pos <= lim); + int rem = (pos <= lim ? lim - pos : 0); + long a; + if (!(src instanceof DirectBuffer)) { + // substitute with direct buffer + ByteBuffer bb = Util.getTemporaryDirectBuffer(rem); + bb.put(src); + bb.flip(); + src.position(pos); // leave heap buffer untouched for now + shadow[i] = bb; + a = ((DirectBuffer)bb).address(); + } else { + shadow[i] = src; + a = ((DirectBuffer)src).address() + pos; + } + unsafe.putAddress(address + OFFSETOF_BUF, a); + unsafe.putInt(address + OFFSETOF_LEN, rem); + address += SIZEOF_WSABUF; + } + } + + /** + * Invoked after a write has completed to update the buffer positions + * and release any substituted buffers. + */ + void updateBuffers(int bytesWritten) { + // Notify the buffers how many bytes were taken + for (int i=0; i<numBufs; i++) { + ByteBuffer nextBuffer = bufs[i]; + int pos = nextBuffer.position(); + int lim = nextBuffer.limit(); + int len = (pos <= lim ? lim - pos : lim); + if (bytesWritten >= len) { + bytesWritten -= len; + int newPosition = pos + len; + try { + nextBuffer.position(newPosition); + } catch (IllegalArgumentException x) { + // position changed by someone else + } + } else { // Buffers not completely filled + if (bytesWritten > 0) { + assert(pos + bytesWritten < (long)Integer.MAX_VALUE); + int newPosition = pos + bytesWritten; + try { + nextBuffer.position(newPosition); + } catch (IllegalArgumentException x) { + // position changed by someone else + } + } + break; + } + } + } + + void releaseBuffers() { + for (int i=0; i<numBufs; i++) { + if (!(bufs[i] instanceof DirectBuffer)) { + Util.releaseTemporaryDirectBuffer(shadow[i]); + } + } + } + + @Override + @SuppressWarnings("unchecked") + public void run() { + int n = -1; + long overlapped = 0L; + boolean prepared = false; + boolean pending = false; + boolean shutdown = false; + + try { + begin(); + + // substitute non-direct buffers + prepareBuffers(); + prepared = true; + + // get an OVERLAPPED structure (from the cache or allocate) + overlapped = ioCache.add(result); + + // synchronize on result to allow this thread handle the case + // where the read completes immediately. + synchronized (result) { + n = write0(handle, numBufs, writeBufferArray, overlapped); + if (n == IOStatus.UNAVAILABLE) { + // I/O is pending + pending = true; + return; + } + + enableWriting(); + + if (n == IOStatus.EOF) { + // special case for shutdown output + shutdown = true; + throw new ClosedChannelException(); + } + + // write completed immediately: + // 1. enable writing + // 2. update buffer position + // 3. release waiters + updateBuffers(n); + + // result is a Long or Integer + if (gatheringWrite) { + result.setResult((V)Long.valueOf(n)); + } else { + result.setResult((V)Integer.valueOf(n)); + } + } + } catch (Throwable x) { + enableWriting(); + + // failed to initiate read: + if (!shutdown && (x instanceof ClosedChannelException)) + x = new AsynchronousCloseException(); + if (!(x instanceof IOException)) + x = new IOException(x); + result.setFailure(x); + + // release resources + if (overlapped != 0L) + ioCache.remove(overlapped); + + } finally { + if (prepared && !pending) { + // return direct buffer(s) to cache if substituted + releaseBuffers(); + } + end(); + } + + // invoke completion handler + Invoker.invoke(result.handler(), result); + } + + /** + * Executed when the I/O has completed + */ + @Override + @SuppressWarnings("unchecked") + public void completed(int bytesTransferred) { + updateBuffers(bytesTransferred); + + // return direct buffer to cache if substituted + releaseBuffers(); + + // release waiters if not already released by timeout + synchronized (result) { + if (result.isDone()) + return; + enableWriting(); + if (gatheringWrite) { + result.setResult((V)Long.valueOf(bytesTransferred)); + } else { + result.setResult((V)Integer.valueOf(bytesTransferred)); + } + } + Invoker.invoke(result.handler(), result); + } + + @Override + public void failed(int error, IOException x) { + // return direct buffer to cache if substituted + releaseBuffers(); + + // release waiters if not already released by timeout + if (!isOpen()) + x = new AsynchronousCloseException(); + + synchronized (result) { + if (result.isDone()) + return; + enableWriting(); + result.setFailure(x); + } + Invoker.invoke(result.handler(), result); + } + + /** + * Invoked if timeout expires before it is cancelled + */ + void timeout() { + // synchronize on result as the I/O could complete/fail + synchronized (result) { + if (result.isDone()) + return; + + // kill further writing before releasing waiters + enableWriting(true); + result.setFailure(new InterruptedByTimeoutException()); + } + + // invoke handler without any locks + Invoker.invoke(result.handler(), result); + } + } + + @Override + <V extends Number,A> Future<V> writeImpl(ByteBuffer[] bufs, + boolean gatheringWrite, + long timeout, + TimeUnit unit, + A attachment, + CompletionHandler<V,? super A> handler) + { + // setup task + PendingFuture<V,A> result = + new PendingFuture<V,A>(this, handler, attachment); + final WriteTask writeTask = new WriteTask<V,A>(bufs, gatheringWrite, result); + result.setContext(writeTask); + + // schedule timeout + if (timeout > 0L) { + Future<?> timeoutTask = iocp.schedule(new Runnable() { + public void run() { + writeTask.timeout(); + } + }, timeout, unit); + result.setTimeoutTask(timeoutTask); + } + + // initiate I/O (can only be done from thread in thread pool) + Invoker.invokeOnThreadInThreadPool(this, writeTask); + return result; + } + + // -- Native methods -- + + private static native void initIDs(); + + private static native int connect0(long socket, boolean preferIPv6, + InetAddress remote, int remotePort, long overlapped) throws IOException; + + private static native void updateConnectContext(long socket) throws IOException; + + private static native int read0(long socket, int count, long addres, long overlapped) + throws IOException; + + private static native int write0(long socket, int count, long address, + long overlapped) throws IOException; + + private static native void shutdown0(long socket, int how) throws IOException; + + private static native void closesocket0(long socket) throws IOException; + + static { + Util.load(); + initIDs(); + } +} diff --git a/src/windows/classes/sun/nio/ch/WindowsSelectorImpl.java b/src/windows/classes/sun/nio/ch/WindowsSelectorImpl.java index 5457a2cfb2cf673a8389ef396e7fee1753270c98..5df8c8cd6c06e060509d122620034c2e0684482e 100644 --- a/src/windows/classes/sun/nio/ch/WindowsSelectorImpl.java +++ b/src/windows/classes/sun/nio/ch/WindowsSelectorImpl.java @@ -34,7 +34,6 @@ import java.nio.channels.Selector; import java.nio.channels.ClosedSelectorException; import java.nio.channels.Pipe; import java.nio.channels.SelectableChannel; -import java.nio.channels.SelectionKey; import java.io.IOException; import java.util.List; import java.util.ArrayList; @@ -72,7 +71,7 @@ final class WindowsSelectorImpl extends SelectorImpl { private int threadsCount = 0; // A list of helper threads for select. - private final List<Thread> threads = new ArrayList<Thread>(); + private final List<SelectThread> threads = new ArrayList<SelectThread>(); //Pipe used as a wakeup object. private final Pipe wakeupPipe; @@ -201,7 +200,7 @@ final class WindowsSelectorImpl extends SelectorImpl { Thread.currentThread().interrupt(); } } - if (thread.index >= threads.size()) { // redundant thread + if (thread.isZombie()) { // redundant thread return true; // will cause run() to exit. } else { thread.lastRun = runsCounter; // update lastRun @@ -388,9 +387,10 @@ final class WindowsSelectorImpl extends SelectorImpl { // Represents a helper thread used for select. private final class SelectThread extends Thread { - private int index; // index of this thread - SubSelector subSelector; + private final int index; // index of this thread + final SubSelector subSelector; private long lastRun = 0; // last run number + private volatile boolean zombie; // Creates a new thread private SelectThread(int i) { this.index = i; @@ -398,6 +398,12 @@ final class WindowsSelectorImpl extends SelectorImpl { //make sure we wait for next round of poll this.lastRun = startLock.runsCounter; } + void makeZombie() { + zombie = true; + } + boolean isZombie() { + return zombie; + } public void run() { while (true) { // poll loop // wait for the start of poll. If this thread has become @@ -432,7 +438,7 @@ final class WindowsSelectorImpl extends SelectorImpl { } else if (threadsCount < threads.size()) { // Some threads become redundant. Remove them from the threads List. for (int i = threads.size() - 1 ; i >= threadsCount; i--) - threads.remove(i); + threads.remove(i).makeZombie(); } } @@ -468,10 +474,9 @@ final class WindowsSelectorImpl extends SelectorImpl { updateCount++; int numKeysUpdated = 0; numKeysUpdated += subSelector.processSelectedKeys(updateCount); - Iterator it = threads.iterator(); - while (it.hasNext()) - numKeysUpdated += ((SelectThread)it.next()).subSelector. - processSelectedKeys(updateCount); + for (SelectThread t: threads) { + numKeysUpdated += t.subSelector.processSelectedKeys(updateCount); + } return numKeysUpdated; } @@ -495,13 +500,13 @@ final class WindowsSelectorImpl extends SelectorImpl { } pollWrapper.free(); pollWrapper = null; - selectedKeys = null; - channelArray = null; - threads.clear(); - // Call startThreads. All remaining helper threads now exit, - // since threads.size() = 0; - startLock.startThreads(); - } + selectedKeys = null; + channelArray = null; + // Make all remaining helper threads exit + for (SelectThread t: threads) + t.makeZombie(); + startLock.startThreads(); + } } } } diff --git a/src/windows/classes/sun/nio/fs/DefaultFileSystemProvider.java b/src/windows/classes/sun/nio/fs/DefaultFileSystemProvider.java new file mode 100644 index 0000000000000000000000000000000000000000..93923103e5f8802c8baf275988cb2a9e3c9c38ab --- /dev/null +++ b/src/windows/classes/sun/nio/fs/DefaultFileSystemProvider.java @@ -0,0 +1,38 @@ +/* + * Copyright 2008-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 sun.nio.fs; + +import java.nio.file.spi.FileSystemProvider; + +/** + * Creates default provider on Windows + */ +public class DefaultFileSystemProvider { + private DefaultFileSystemProvider() { } + public static FileSystemProvider create() { + return new WindowsFileSystemProvider(); + } +} diff --git a/src/windows/classes/sun/nio/fs/DefaultFileTypeDetector.java b/src/windows/classes/sun/nio/fs/DefaultFileTypeDetector.java new file mode 100644 index 0000000000000000000000000000000000000000..1e775aee81c16975e0f8faad2fb29153213f32e8 --- /dev/null +++ b/src/windows/classes/sun/nio/fs/DefaultFileTypeDetector.java @@ -0,0 +1,36 @@ +/* + * Copyright 2008-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 sun.nio.fs; + +import java.nio.file.spi.FileTypeDetector; + +public class DefaultFileTypeDetector { + private DefaultFileTypeDetector() { } + + public static FileTypeDetector create() { + return new RegistryFileTypeDetector(); + } +} diff --git a/src/windows/classes/sun/nio/fs/RegistryFileTypeDetector.java b/src/windows/classes/sun/nio/fs/RegistryFileTypeDetector.java new file mode 100644 index 0000000000000000000000000000000000000000..dc4b9c0e2ef5151d3afca333a1be259cddfd07c1 --- /dev/null +++ b/src/windows/classes/sun/nio/fs/RegistryFileTypeDetector.java @@ -0,0 +1,82 @@ +/* + * Copyright 2008-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 sun.nio.fs; + +import java.nio.file.*; +import java.io.IOException; +import java.security.AccessController; +import java.security.PrivilegedAction; + +/** + * File type detector that does lookup of file extension using Windows Registry. + */ + +public class RegistryFileTypeDetector + extends AbstractFileTypeDetector +{ + public RegistryFileTypeDetector() { + super(); + } + + @Override + public String implProbeContentType(FileRef file) throws IOException { + if (!(file instanceof Path)) + return null; + + // get file extension + Path name = ((Path)file).getName(); + if (name == null) + return null; + String filename = name.toString(); + int dot = filename.lastIndexOf('.'); + if ((dot < 0) || (dot == (filename.length()-1))) + return null; + + // query HKEY_CLASSES_ROOT\<ext> + String key = filename.substring(dot); + NativeBuffer keyBuffer = WindowsNativeDispatcher.asNativeBuffer(key); + NativeBuffer nameBuffer = WindowsNativeDispatcher.asNativeBuffer("Content Type"); + try { + return queryStringValue(keyBuffer.address(), nameBuffer.address()); + } finally { + nameBuffer.release(); + keyBuffer.release(); + } + } + + private static native String queryStringValue(long subKey, long name); + + static { + AccessController.doPrivileged(new PrivilegedAction<Void>() { + @Override + public Void run() { + // nio.dll has dependency on net.dll + System.loadLibrary("net"); + System.loadLibrary("nio"); + return null; + }}); + } +} diff --git a/src/windows/classes/sun/nio/fs/WindowsAclFileAttributeView.java b/src/windows/classes/sun/nio/fs/WindowsAclFileAttributeView.java new file mode 100644 index 0000000000000000000000000000000000000000..937aedd85a0cf532da15687102cf11f389bf9287 --- /dev/null +++ b/src/windows/classes/sun/nio/fs/WindowsAclFileAttributeView.java @@ -0,0 +1,226 @@ +/* + * Copyright 2008-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 sun.nio.fs; + +import java.nio.file.ProviderMismatchException; +import java.nio.file.attribute.*; +import java.util.*; +import java.io.IOException; + +import static sun.nio.fs.WindowsNativeDispatcher.*; +import static sun.nio.fs.WindowsConstants.*; + +/** + * Windows implementation of AclFileAttributeView. + */ + +class WindowsAclFileAttributeView + extends AbstractAclFileAttributeView +{ + /** + * typedef struct _SECURITY_DESCRIPTOR { + * BYTE Revision; + * BYTE Sbz1; + * SECURITY_DESCRIPTOR_CONTROL Control; + * PSID Owner; + * PSID Group; + * PACL Sacl; + * PACL Dacl; + * } SECURITY_DESCRIPTOR; + */ + private static final short SIZEOF_SECURITY_DESCRIPTOR = 20; + + private final WindowsPath file; + private final boolean followLinks; + + WindowsAclFileAttributeView(WindowsPath file, boolean followLinks) { + this.file = file; + this.followLinks = followLinks; + } + + // permision check + private void checkAccess(WindowsPath file, + boolean checkRead, + boolean checkWrite) + { + SecurityManager sm = System.getSecurityManager(); + if (sm != null) { + if (checkRead) + sm.checkRead(file.getPathForPermissionCheck()); + if (checkWrite) + sm.checkWrite(file.getPathForPermissionCheck()); + sm.checkPermission(new RuntimePermission("accessUserInformation")); + } + } + + // invokes GetFileSecurity to get requested security information + static NativeBuffer getFileSecurity(String path, int request) + throws IOException + { + // invoke get to buffer size + int size = 0; + try { + size = GetFileSecurity(path, request, 0L, 0); + } catch (WindowsException x) { + x.rethrowAsIOException(path); + } + assert size > 0; + + // allocate buffer and re-invoke to get security information + NativeBuffer buffer = NativeBuffers.getNativeBuffer(size); + try { + for (;;) { + int newSize = GetFileSecurity(path, request, buffer.address(), size); + if (newSize <= size) + return buffer; + + // buffer was insufficient + buffer.release(); + buffer = NativeBuffers.getNativeBuffer(newSize); + size = newSize; + } + } catch (WindowsException x) { + buffer.release(); + x.rethrowAsIOException(path); + return null; + } + } + + @Override + public UserPrincipal getOwner() + throws IOException + { + checkAccess(file, true, false); + + // GetFileSecurity does not follow links so when following links we + // need the final target + String path = WindowsLinkSupport.getFinalPath(file, followLinks); + NativeBuffer buffer = getFileSecurity(path, OWNER_SECURITY_INFORMATION); + try { + // get the address of the SID + long sidAddress = GetSecurityDescriptorOwner(buffer.address()); + if (sidAddress == 0L) + throw new IOException("no owner"); + return WindowsUserPrincipals.fromSid(sidAddress); + } catch (WindowsException x) { + x.rethrowAsIOException(file); + return null; + } finally { + buffer.release(); + } + } + + @Override + public List<AclEntry> getAcl() + throws IOException + { + checkAccess(file, true, false); + + // GetFileSecurity does not follow links so when following links we + // need the final target + String path = WindowsLinkSupport.getFinalPath(file, followLinks); + + // ALLOW and DENY entries in DACL; + // AUDIT entries in SACL (ignore for now as it requires privileges) + NativeBuffer buffer = getFileSecurity(path, DACL_SECURITY_INFORMATION); + try { + return WindowsSecurityDescriptor.getAcl(buffer.address()); + } finally { + buffer.release(); + } + } + + @Override + public void setOwner(UserPrincipal obj) + throws IOException + { + if (obj == null) + throw new NullPointerException("'owner' is null"); + if (!(obj instanceof WindowsUserPrincipals.User)) + throw new ProviderMismatchException(); + WindowsUserPrincipals.User owner = (WindowsUserPrincipals.User)obj; + + // permission check + checkAccess(file, false, true); + + // SetFileSecurity does not follow links so when following links we + // need the final target + String path = WindowsLinkSupport.getFinalPath(file, followLinks); + + // ConvertStringSidToSid allocates memory for SID so must invoke + // LocalFree to free it when we are done + long pOwner = 0L; + try { + pOwner = ConvertStringSidToSid(owner.sidString()); + } catch (WindowsException x) { + throw new IOException("Failed to get SID for " + owner.getName() + + ": " + x.errorString()); + } + + // Allocate buffer for security descriptor, initialize it, set + // owner information and update the file. + try { + NativeBuffer buffer = NativeBuffers.getNativeBuffer(SIZEOF_SECURITY_DESCRIPTOR); + try { + InitializeSecurityDescriptor(buffer.address()); + SetSecurityDescriptorOwner(buffer.address(), pOwner); + // may need SeRestorePrivilege to set the owner + WindowsSecurity.Privilege priv = + WindowsSecurity.enablePrivilege("SeRestorePrivilege"); + try { + SetFileSecurity(path, + OWNER_SECURITY_INFORMATION, + buffer.address()); + } finally { + priv.drop(); + } + } catch (WindowsException x) { + x.rethrowAsIOException(file); + } finally { + buffer.release(); + } + } finally { + LocalFree(pOwner); + } + } + + @Override + public void setAcl(List<AclEntry> acl) throws IOException { + checkAccess(file, false, true); + + // SetFileSecurity does not follow links so when following links we + // need the final target + String path = WindowsLinkSupport.getFinalPath(file, followLinks); + WindowsSecurityDescriptor sd = WindowsSecurityDescriptor.create(acl); + try { + SetFileSecurity(path, DACL_SECURITY_INFORMATION, sd.address()); + } catch (WindowsException x) { + x.rethrowAsIOException(file); + } finally { + sd.release(); + } + } +} diff --git a/src/windows/classes/sun/nio/fs/WindowsChannelFactory.java b/src/windows/classes/sun/nio/fs/WindowsChannelFactory.java new file mode 100644 index 0000000000000000000000000000000000000000..f559166bb6b8fd993c3007c7638123075275350a --- /dev/null +++ b/src/windows/classes/sun/nio/fs/WindowsChannelFactory.java @@ -0,0 +1,341 @@ +/* + * Copyright 2008-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 sun.nio.fs; + +import java.nio.file.*; +import java.nio.channels.*; +import java.io.FileDescriptor; +import java.io.IOException; +import java.util.*; + +import com.sun.nio.file.ExtendedOpenOption; + +import sun.nio.ch.FileChannelImpl; +import sun.nio.ch.ThreadPool; +import sun.nio.ch.WindowsAsynchronousFileChannelImpl; +import sun.misc.SharedSecrets; +import sun.misc.JavaIOFileDescriptorAccess; + +import static sun.nio.fs.WindowsNativeDispatcher.*; +import static sun.nio.fs.WindowsConstants.*; + +/** + * Factory to create FileChannels and AsynchronousFileChannels. + */ + +class WindowsChannelFactory { + private static final JavaIOFileDescriptorAccess fdAccess = + SharedSecrets.getJavaIOFileDescriptorAccess(); + + private WindowsChannelFactory() { } + + /** + * Do not follow reparse points when opening an existing file. Do not fail + * if the file is a reparse point. + */ + static final OpenOption OPEN_REPARSE_POINT = new OpenOption() { }; + + /** + * Represents the flags from a user-supplied set of open options. + */ + private static class Flags { + boolean read; + boolean write; + boolean append; + boolean truncateExisting; + boolean create; + boolean createNew; + boolean deleteOnClose; + boolean sparse; + boolean overlapped; + boolean sync; + boolean dsync; + + // non-standard + boolean shareRead = true; + boolean shareWrite = true; + boolean shareDelete = true; + boolean noFollowLinks; + boolean openReparsePoint; + + static Flags toFlags(Set<? extends OpenOption> options) { + Flags flags = new Flags(); + for (OpenOption option: options) { + if (option instanceof StandardOpenOption) { + switch ((StandardOpenOption)option) { + case READ : flags.read = true; break; + case WRITE : flags.write = true; break; + case APPEND : flags.append = true; break; + case TRUNCATE_EXISTING : flags.truncateExisting = true; break; + case CREATE : flags.create = true; break; + case CREATE_NEW : flags.createNew = true; break; + case DELETE_ON_CLOSE : flags.deleteOnClose = true; break; + case SPARSE : flags.sparse = true; break; + case SYNC : flags.sync = true; break; + case DSYNC : flags.dsync = true; break; + default: throw new UnsupportedOperationException(); + } + continue; + } + if (option instanceof ExtendedOpenOption) { + switch ((ExtendedOpenOption)option) { + case NOSHARE_READ : flags.shareRead = false; break; + case NOSHARE_WRITE : flags.shareWrite = false; break; + case NOSHARE_DELETE : flags.shareDelete = false; break; + default: throw new UnsupportedOperationException(); + } + continue; + } + if (option == LinkOption.NOFOLLOW_LINKS) { + flags.noFollowLinks = true; + continue; + } + if (option == OPEN_REPARSE_POINT) { + flags.openReparsePoint = true; + continue; + } + if (option == null) + throw new NullPointerException(); + throw new UnsupportedOperationException(); + } + return flags; + } + } + + /** + * Open/creates file, returning FileChannel to access the file + * + * @param pathForWindows + * The path of the file to open/create + * @param pathToCheck + * The path used for permission checks (if security manager) + */ + static FileChannel newFileChannel(String pathForWindows, + String pathToCheck, + Set<? extends OpenOption> options, + long pSecurityDescriptor) + throws WindowsException + { + Flags flags = Flags.toFlags(options); + + // default is reading; append => writing + if (!flags.read && !flags.write) { + if (flags.append) { + flags.write = true; + } else { + flags.read = true; + } + } + + // validation + if (flags.read && flags.append) + throw new IllegalArgumentException("READ + APPEND not allowed"); + if (flags.append && flags.truncateExisting) + throw new IllegalArgumentException("APPEND + TRUNCATE_EXISTING not allowed"); + + FileDescriptor fdObj = open(pathForWindows, pathToCheck, flags, pSecurityDescriptor); + return FileChannelImpl.open(fdObj, flags.read, flags.write, null); + } + + /** + * Open/creates file, returning AsynchronousFileChannel to access the file + * + * @param pathForWindows + * The path of the file to open/create + * @param pathToCheck + * The path used for permission checks (if security manager) + * @param pool + * The thread pool that the channel is associated with + */ + static AsynchronousFileChannel newAsynchronousFileChannel(String pathForWindows, + String pathToCheck, + Set<? extends OpenOption> options, + long pSecurityDescriptor, + ThreadPool pool) + throws IOException + { + Flags flags = Flags.toFlags(options); + + // Overlapped I/O required + flags.overlapped = true; + + // default is reading + if (!flags.read && !flags.write) { + flags.read = true; + } + + // validation + if (flags.append) + throw new UnsupportedOperationException("APPEND not allowed"); + + // open file for overlapped I/O + FileDescriptor fdObj; + try { + fdObj = open(pathForWindows, pathToCheck, flags, pSecurityDescriptor); + } catch (WindowsException x) { + x.rethrowAsIOException(pathForWindows); + return null; + } + + // create the AsynchronousFileChannel + try { + return WindowsAsynchronousFileChannelImpl.open(fdObj, flags.read, flags.write, pool); + } catch (IOException x) { + // IOException is thrown if the file handle cannot be associated + // with the completion port. All we can do is close the file. + long handle = fdAccess.getHandle(fdObj); + CloseHandle(handle); + throw x; + } + } + + /** + * Opens file based on parameters and options, returning a FileDescriptor + * encapsulating the handle to the open file. + */ + private static FileDescriptor open(String pathForWindows, + String pathToCheck, + Flags flags, + long pSecurityDescriptor) + throws WindowsException + { + // set to true if file must be truncated after open + boolean truncateAfterOpen = false; + + // map options + int dwDesiredAccess = 0; + if (flags.read) + dwDesiredAccess |= GENERIC_READ; + if (flags.write) + dwDesiredAccess |= (flags.append) ? FILE_APPEND_DATA : GENERIC_WRITE; + + int dwShareMode = 0; + if (flags.shareRead) + dwShareMode |= FILE_SHARE_READ; + if (flags.shareWrite) + dwShareMode |= FILE_SHARE_WRITE; + if (flags.shareDelete) + dwShareMode |= FILE_SHARE_DELETE; + + int dwFlagsAndAttributes = FILE_ATTRIBUTE_NORMAL; + int dwCreationDisposition = OPEN_EXISTING; + if (flags.write) { + if (flags.createNew) { + dwCreationDisposition = CREATE_NEW; + // force create to fail if file is orphaned reparse point + dwFlagsAndAttributes |= FILE_FLAG_OPEN_REPARSE_POINT; + } else { + if (flags.create) + dwCreationDisposition = OPEN_ALWAYS; + if (flags.truncateExisting) { + // Windows doesn't have a creation disposition that exactly + // corresponds to CREATE + TRUNCATE_EXISTING so we use + // the OPEN_ALWAYS mode and then truncate the file. + if (dwCreationDisposition == OPEN_ALWAYS) { + truncateAfterOpen = true; + } else { + dwCreationDisposition = TRUNCATE_EXISTING; + } + } + } + } + + if (flags.dsync || flags.sync) + dwFlagsAndAttributes |= FILE_FLAG_WRITE_THROUGH; + if (flags.overlapped) + dwFlagsAndAttributes |= FILE_FLAG_OVERLAPPED; + if (flags.deleteOnClose) + dwFlagsAndAttributes |= FILE_FLAG_DELETE_ON_CLOSE; + + // NOFOLLOW_LINKS and NOFOLLOW_REPARSEPOINT mean open reparse point + boolean okayToFollowLinks = true; + if (dwCreationDisposition != CREATE_NEW && + (flags.noFollowLinks || + flags.openReparsePoint || + flags.deleteOnClose)) + { + if (flags.noFollowLinks || flags.deleteOnClose) + okayToFollowLinks = false; + dwFlagsAndAttributes |= FILE_FLAG_OPEN_REPARSE_POINT; + } + + // permission check + if (pathToCheck != null) { + SecurityManager sm = System.getSecurityManager(); + if (sm != null) { + if (flags.read) + sm.checkRead(pathToCheck); + if (flags.write) + sm.checkWrite(pathToCheck); + if (flags.deleteOnClose) + sm.checkDelete(pathToCheck); + } + } + + // open file + long handle = CreateFile(pathForWindows, + dwDesiredAccess, + dwShareMode, + pSecurityDescriptor, + dwCreationDisposition, + dwFlagsAndAttributes); + + // make sure this isn't a symbolic link. + if (!okayToFollowLinks) { + try { + if (WindowsFileAttributes.readAttributes(handle).isSymbolicLink()) + throw new WindowsException("File is symbolic link"); + } catch (WindowsException x) { + CloseHandle(handle); + throw x; + } + } + + // truncate file (for CREATE + TRUNCATE_EXISTING case) + if (truncateAfterOpen) { + try { + SetEndOfFile(handle); + } catch (WindowsException x) { + CloseHandle(handle); + throw x; + } + } + + // make the file sparse if needed + if (dwCreationDisposition == CREATE_NEW && flags.sparse) { + try { + DeviceIoControlSetSparse(handle); + } catch (WindowsException x) { + // ignore as sparse option is hint + } + } + + // create FileDescriptor and return + FileDescriptor fdObj = new FileDescriptor(); + fdAccess.setHandle(fdObj, handle); + return fdObj; + } +} diff --git a/src/windows/classes/sun/nio/fs/WindowsConstants.java b/src/windows/classes/sun/nio/fs/WindowsConstants.java new file mode 100644 index 0000000000000000000000000000000000000000..f2619ac806049d0d1109d0db751a7201a6c06a81 --- /dev/null +++ b/src/windows/classes/sun/nio/fs/WindowsConstants.java @@ -0,0 +1,192 @@ +/* + * Copyright 2008-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 sun.nio.fs; + +/** + * Win32 APIs constants. + */ + +class WindowsConstants { + private WindowsConstants() { } + + // general + public static final long INVALID_HANDLE_VALUE = -1L; + + // generic rights + public static final int GENERIC_READ = 0x80000000; + public static final int GENERIC_WRITE = 0x40000000; + + // share modes + public static final int FILE_SHARE_READ = 0x00000001; + public static final int FILE_SHARE_WRITE = 0x00000002; + public static final int FILE_SHARE_DELETE = 0x00000004; + + // creation modes + public static final int CREATE_NEW = 1; + public static final int CREATE_ALWAYS = 2; + public static final int OPEN_EXISTING = 3; + public static final int OPEN_ALWAYS = 4; + public static final int TRUNCATE_EXISTING = 5; + + // attributes and flags + public static final int FILE_ATTRIBUTE_READONLY = 0x00000001; + public static final int FILE_ATTRIBUTE_HIDDEN = 0x00000002; + public static final int FILE_ATTRIBUTE_SYSTEM = 0x00000004; + public static final int FILE_ATTRIBUTE_DIRECTORY = 0x00000010; + public static final int FILE_ATTRIBUTE_ARCHIVE = 0x00000020; + public static final int FILE_ATTRIBUTE_DEVICE = 0x00000040; + public static final int FILE_ATTRIBUTE_NORMAL = 0x00000080; + public static final int FILE_ATTRIBUTE_REPARSE_POINT = 0x400; + public static final int FILE_FLAG_NO_BUFFERING = 0x20000000; + public static final int FILE_FLAG_OVERLAPPED = 0x40000000; + public static final int FILE_FLAG_WRITE_THROUGH = 0x80000000; + public static final int FILE_FLAG_BACKUP_SEMANTICS = 0x02000000; + public static final int FILE_FLAG_DELETE_ON_CLOSE = 0x04000000; + public static final int FILE_FLAG_OPEN_REPARSE_POINT = 0x00200000; + + // stream ids + public static final int BACKUP_ALTERNATE_DATA = 0x00000004; + public static final int BACKUP_SPARSE_BLOCK = 0x00000009; + + // reparse point/symbolic link related constants + public static final int IO_REPARSE_TAG_SYMLINK = 0xA000000C; + public static final int MAXIMUM_REPARSE_DATA_BUFFER_SIZE = 16 * 1024; + public static final int SYMBOLIC_LINK_FLAG_DIRECTORY = 0x1; + + // volume flags + public static final int FILE_CASE_SENSITIVE_SEARCH = 0x00000001; + public static final int FILE_CASE_PRESERVED_NAMES = 0x00000002; + public static final int FILE_PERSISTENT_ACLS = 0x00000008; + public static final int FILE_VOLUME_IS_COMPRESSED = 0x00008000; + public static final int FILE_NAMED_STREAMS = 0x00040000; + public static final int FILE_READ_ONLY_VOLUME = 0x00080000; + + // error codes + public static final int ERROR_FILE_NOT_FOUND = 2; + public static final int ERROR_PATH_NOT_FOUND = 3; + public static final int ERROR_ACCESS_DENIED = 5; + public static final int ERROR_INVALID_HANDLE = 6; + public static final int ERROR_INVALID_DATA = 13; + public static final int ERROR_NOT_SAME_DEVICE = 17; + public static final int ERROR_NOT_READY = 21; + public static final int ERROR_FILE_EXISTS = 80; + public static final int ERROR_DISK_FULL = 112; + public static final int ERROR_INSUFFICIENT_BUFFER = 122; + public static final int ERROR_INVALID_LEVEL = 124; + public static final int ERROR_DIR_NOT_EMPTY = 145; + public static final int ERROR_ALREADY_EXISTS = 183; + public static final int ERROR_DIRECTORY = 267; + public static final int ERROR_NOTIFY_ENUM_DIR = 1022; + public static final int ERROR_NONE_MAPPED = 1332; + public static final int ERROR_NOT_A_REPARSE_POINT = 4390; + public static final int ERROR_INVALID_REPARSE_DATA = 4392; + + // notify filters + public static final int FILE_NOTIFY_CHANGE_FILE_NAME = 0x00000001; + public static final int FILE_NOTIFY_CHANGE_DIR_NAME = 0x00000002; + public static final int FILE_NOTIFY_CHANGE_ATTRIBUTES = 0x00000004; + public static final int FILE_NOTIFY_CHANGE_SIZE = 0x00000008; + public static final int FILE_NOTIFY_CHANGE_LAST_WRITE = 0x00000010; + public static final int FILE_NOTIFY_CHANGE_LAST_ACCESS = 0x00000020; + public static final int FILE_NOTIFY_CHANGE_CREATION = 0x00000040; + public static final int FILE_NOTIFY_CHANGE_SECURITY = 0x00000100; + + // notify actions + public final static int FILE_ACTION_ADDED = 0x00000001; + public final static int FILE_ACTION_REMOVED = 0x00000002; + public final static int FILE_ACTION_MODIFIED = 0x00000003; + public final static int FILE_ACTION_RENAMED_OLD_NAME = 0x00000004; + public final static int FILE_ACTION_RENAMED_NEW_NAME = 0x00000005; + + // copy flags + public static final int COPY_FILE_FAIL_IF_EXISTS = 0x00000001; + public static final int COPY_FILE_COPY_SYMLINK = 0x00000800; + + // move flags + public static final int MOVEFILE_REPLACE_EXISTING = 0x00000001; + public static final int MOVEFILE_COPY_ALLOWED = 0x00000002; + + // drive types + public static final int DRIVE_UNKNOWN = 0; + public static final int DRIVE_NO_ROOT_DIR = 1; + public static final int DRIVE_REMOVABLE = 2; + public static final int DRIVE_FIXED = 3; + public static final int DRIVE_REMOTE = 4; + public static final int DRIVE_CDROM = 5; + public static final int DRIVE_RAMDISK = 6; + + // file security + public static final int OWNER_SECURITY_INFORMATION = 0x00000001; + public static final int GROUP_SECURITY_INFORMATION = 0x00000002; + public static final int DACL_SECURITY_INFORMATION = 0x00000004; + public static final int SACL_SECURITY_INFORMATION = 0x00000008; + + public static final int SidTypeUser = 1; + public static final int SidTypeGroup = 2; + public static final int SidTypeDomain = 3; + public static final int SidTypeAlias = 4; + public static final int SidTypeWellKnownGroup = 5; + public static final int SidTypeDeletedAccount = 6; + public static final int SidTypeInvalid = 7; + public static final int SidTypeUnknown = 8; + public static final int SidTypeComputer= 9; + + public static final byte ACCESS_ALLOWED_ACE_TYPE = 0x0; + public static final byte ACCESS_DENIED_ACE_TYPE = 0x1; + + public static final byte OBJECT_INHERIT_ACE = 0x1; + public static final byte CONTAINER_INHERIT_ACE = 0x2; + public static final byte NO_PROPAGATE_INHERIT_ACE = 0x4; + public static final byte INHERIT_ONLY_ACE = 0x8; + + public static final int DELETE = 0x00010000; + public static final int READ_CONTROL = 0x00020000; + public static final int WRITE_DAC = 0x00040000; + public static final int WRITE_OWNER = 0x00080000; + public static final int SYNCHRONIZE = 0x00100000; + + public static final int FILE_LIST_DIRECTORY = 0x0001; + public static final int FILE_READ_DATA = 0x0001; + public static final int FILE_WRITE_DATA = 0x0002; + public static final int FILE_APPEND_DATA = 0x0004; + public static final int FILE_READ_EA = 0x0008; + public static final int FILE_WRITE_EA = 0x0010; + public static final int FILE_EXECUTE = 0x0020; + public static final int FILE_DELETE_CHILD = 0x0040; + public static final int FILE_READ_ATTRIBUTES = 0x0080; + public static final int FILE_WRITE_ATTRIBUTES = 0x0100; + + // operating system security + public static final int TOKEN_DUPLICATE = 0x0002; + public static final int TOKEN_IMPERSONATE = 0x0004; + public static final int TOKEN_QUERY = 0x0008; + public static final int TOKEN_ADJUST_PRIVILEGES = 0x0020; + + public static final int SE_PRIVILEGE_ENABLED = 0x00000002; + + public static final int TokenUser = 1; + public static final int PROCESS_QUERY_INFORMATION = 0x0400; +} diff --git a/src/windows/classes/sun/nio/fs/WindowsDirectoryStream.java b/src/windows/classes/sun/nio/fs/WindowsDirectoryStream.java new file mode 100644 index 0000000000000000000000000000000000000000..fa0b148346caa6298a520bed93426121847df8f1 --- /dev/null +++ b/src/windows/classes/sun/nio/fs/WindowsDirectoryStream.java @@ -0,0 +1,255 @@ +/* + * Copyright 2008-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 sun.nio.fs; + +import java.nio.file.*; +import java.nio.file.attribute.BasicFileAttributes; +import java.util.Iterator; +import java.util.ConcurrentModificationException; +import java.util.NoSuchElementException; +import java.io.IOException; + +import static sun.nio.fs.WindowsNativeDispatcher.*; +import static sun.nio.fs.WindowsConstants.*; + +/** + * Windows implementation of DirectoryStream + */ + +class WindowsDirectoryStream + implements DirectoryStream<Path> +{ + private final WindowsPath dir; + private final DirectoryStream.Filter<? super Path> filter; + + // handle to directory + private final long handle; + // first entry in the directory + private final String firstName; + + // buffer for WIN32_FIND_DATA structure that receives information about file + private final NativeBuffer findDataBuffer; + + private final Object closeLock = new Object(); + + // need closeLock to access these + private boolean isOpen = true; + private Iterator<Path> iterator; + + + WindowsDirectoryStream(WindowsPath dir, DirectoryStream.Filter<? super Path> filter) + throws IOException + { + this.dir = dir; + this.filter = filter; + + try { + // Need to append * or \* to match entries in directory. + String search = dir.getPathForWin32Calls(); + char last = search.charAt(search.length() -1); + if (last == ':' || last == '\\') { + search += "*"; + } else { + search += "\\*"; + } + + FirstFile first = FindFirstFile(search); + this.handle = first.handle(); + this.firstName = first.name(); + this.findDataBuffer = WindowsFileAttributes.getBufferForFindData(); + } catch (WindowsException x) { + if (x.lastError() == ERROR_DIRECTORY) { + throw new NotDirectoryException(dir.getPathForExceptionMessage()); + } + x.rethrowAsIOException(dir); + + // keep compiler happy + throw new AssertionError(); + } + } + + @Override + public void close() + throws IOException + { + synchronized (closeLock) { + if (!isOpen) + return; + isOpen = false; + } + findDataBuffer.release(); + try { + FindClose(handle); + } catch (WindowsException x) { + x.rethrowAsIOException(dir); + } + } + + @Override + public Iterator<Path> iterator() { + if (!isOpen) { + throw new IllegalStateException("Directory stream is closed"); + } + synchronized (this) { + if (iterator != null) + throw new IllegalStateException("Iterator already obtained"); + iterator = new WindowsDirectoryIterator(firstName); + return iterator; + } + } + + private static void throwAsConcurrentModificationException(Throwable t) { + ConcurrentModificationException cme = new ConcurrentModificationException(); + cme.initCause(t); + throw cme; + } + + private class WindowsDirectoryIterator implements Iterator<Path> { + private boolean atEof; + private String first; + private Path nextEntry; + private Path prevEntry; + + WindowsDirectoryIterator(String first) { + atEof = false; + this.first = first; + } + + // applies filter and also ignores "." and ".." + private Path acceptEntry(String s, BasicFileAttributes attrs) { + if (s.equals(".") || s.equals("..")) + return null; + if (dir.needsSlashWhenResolving()) { + StringBuilder sb = new StringBuilder(dir.toString()); + sb.append('\\'); + sb.append(s); + s = sb.toString(); + } else { + s = dir + s; + } + Path entry = WindowsPath + .createFromNormalizedPath(dir.getFileSystem(), s, attrs); + if (filter.accept(entry)) { + return entry; + } else { + return null; + } + } + + // reads next directory entry + private Path readNextEntry() { + // handle first element returned by search + if (first != null) { + nextEntry = acceptEntry(first, null); + first = null; + if (nextEntry != null) + return nextEntry; + } + + for (;;) { + String name = null; + WindowsFileAttributes attrs; + + // synchronize on closeLock to prevent close while reading + synchronized (closeLock) { + if (!isOpen) + throwAsConcurrentModificationException(new + IllegalStateException("Directory stream is closed")); + try { + name = FindNextFile(handle, findDataBuffer.address()); + if (name == null) { + // NO_MORE_FILES + return null; + } + } catch (WindowsException x) { + try { + x.rethrowAsIOException(dir); + } catch (IOException ioe) { + throwAsConcurrentModificationException(ioe); + } + } + + // grab the attributes from the WIN32_FIND_DATA structure + // (needs to be done while holding closeLock because close + // will release the buffer) + attrs = WindowsFileAttributes + .fromFindData(findDataBuffer.address()); + } + + // return entry if accepted by filter + Path entry = acceptEntry(name, attrs); + if (entry != null) + return entry; + } + } + + @Override + public synchronized boolean hasNext() { + if (nextEntry == null && !atEof) { + nextEntry = readNextEntry(); + atEof = (nextEntry == null); + } + return nextEntry != null; + } + + @Override + public synchronized Path next() { + if (nextEntry == null) { + if (!atEof) { + nextEntry = readNextEntry(); + } + if (nextEntry == null) { + atEof = true; + throw new NoSuchElementException(); + } + } + prevEntry = nextEntry; + nextEntry = null; + return prevEntry; + } + + @Override + public void remove() { + if (!isOpen) { + throw new IllegalStateException("Directory stream is closed"); + } + Path entry; + synchronized (this) { + if (prevEntry == null) + throw new IllegalStateException("no last element"); + entry = prevEntry; + prevEntry = null; + } + try { + entry.delete(true); + } catch (IOException ioe) { + throwAsConcurrentModificationException(ioe); + } catch (SecurityException se) { + throwAsConcurrentModificationException(se); + } + } + } +} diff --git a/src/windows/classes/sun/nio/fs/WindowsException.java b/src/windows/classes/sun/nio/fs/WindowsException.java new file mode 100644 index 0000000000000000000000000000000000000000..7da722076f3d73ae07f9a8b72606237b98a38b7f --- /dev/null +++ b/src/windows/classes/sun/nio/fs/WindowsException.java @@ -0,0 +1,109 @@ +/* + * Copyright 2008-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 sun.nio.fs; + +import java.nio.file.*; +import java.io.IOException; + +import static sun.nio.fs.WindowsConstants.*; + +/** + * Internal exception thrown when a Win32 calls fails. + */ + +class WindowsException extends Exception { + static final long serialVersionUID = 2765039493083748820L; + + private int lastError; + private String msg; + + WindowsException(int lastError) { + this.lastError = lastError; + this.msg = null; + } + + WindowsException(String msg) { + this.lastError = 0; + this.msg = msg; + } + + int lastError() { + return lastError; + } + + String errorString() { + if (msg == null) { + msg = WindowsNativeDispatcher.FormatMessage(lastError); + if (msg == null) { + msg = "Unknown error: 0x" + Integer.toHexString(lastError); + } + } + return msg; + } + + @Override + public String getMessage() { + return errorString(); + } + + private IOException translateToIOException(String file, String other) { + // not created with last error + if (lastError() == 0) + return new IOException(errorString()); + + // handle specific cases + if (lastError() == ERROR_FILE_NOT_FOUND || lastError() == ERROR_PATH_NOT_FOUND) + return new NoSuchFileException(file, other, null); + if (lastError() == ERROR_FILE_EXISTS || lastError() == ERROR_ALREADY_EXISTS) + return new FileAlreadyExistsException(file, other, null); + if (lastError() == ERROR_ACCESS_DENIED) + return new AccessDeniedException(file, other, null); + + // fallback to the more general exception + return new FileSystemException(file, other, errorString()); + } + + void rethrowAsIOException(String file) throws IOException { + IOException x = translateToIOException(file, null); + throw x; + } + + void rethrowAsIOException(WindowsPath file, WindowsPath other) throws IOException { + String a = (file == null) ? null : file.getPathForExceptionMessage(); + String b = (other == null) ? null : other.getPathForExceptionMessage(); + IOException x = translateToIOException(a, b); + throw x; + } + + void rethrowAsIOException(WindowsPath file) throws IOException { + rethrowAsIOException(file, null); + } + + IOException asIOException(WindowsPath file) { + return translateToIOException(file.getPathForExceptionMessage(), null); + } + +} diff --git a/src/windows/classes/sun/nio/fs/WindowsFileAttributeViews.java b/src/windows/classes/sun/nio/fs/WindowsFileAttributeViews.java new file mode 100644 index 0000000000000000000000000000000000000000..39c34a10ea9bfd139428a914daf1fd0dde7cda03 --- /dev/null +++ b/src/windows/classes/sun/nio/fs/WindowsFileAttributeViews.java @@ -0,0 +1,296 @@ +/* + * Copyright 2008-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 sun.nio.fs; + + +import java.nio.file.attribute.*; +import java.util.*; +import java.util.concurrent.TimeUnit; +import java.io.IOException; + +import static sun.nio.fs.WindowsNativeDispatcher.*; +import static sun.nio.fs.WindowsConstants.*; + +class WindowsFileAttributeViews { + + private static class Basic extends AbstractBasicFileAttributeView { + final WindowsPath file; + final boolean followLinks; + + Basic(WindowsPath file, boolean followLinks) { + this.file = file; + this.followLinks = followLinks; + } + + @Override + public WindowsFileAttributes readAttributes() throws IOException { + try { + return WindowsFileAttributes.get(file, followLinks); + } catch (WindowsException x) { + x.rethrowAsIOException(file); + return null; // keep compiler happy + } + } + + /** + * Parameter values in Windows times. + */ + void setFileTimes(long createTime, long lastAccessTime, long lastWriteTime) + throws IOException + { + long handle = -1L; + try { + int flags = FILE_FLAG_BACKUP_SEMANTICS; + if (!followLinks && file.getFileSystem().supportsLinks()) + flags |= FILE_FLAG_OPEN_REPARSE_POINT; + + handle = CreateFile(file.getPathForWin32Calls(), + FILE_WRITE_ATTRIBUTES, + (FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE), + OPEN_EXISTING, + flags); + } catch (WindowsException x) { + x.rethrowAsIOException(file); + } + + // update attributes + try { + SetFileTime(handle, createTime, lastAccessTime, lastWriteTime); + } catch (WindowsException x) { + x.rethrowAsIOException(file); + } finally { + CloseHandle(handle); + } + } + + @Override + public void setTimes(Long lastModifiedTime, + Long lastAccessTime, + Long createTime, + TimeUnit unit) throws IOException + { + file.checkWrite(); + + // if all null then do nothing + if (lastModifiedTime == null && lastAccessTime == null && + createTime == null) + { + // no effect + return; + } + + // null => no change + // -1 => change to current time + long now = System.currentTimeMillis(); + long modTime = 0L, accTime = 0L, crTime = 0L; + if (lastModifiedTime != null) { + if (lastModifiedTime < 0L) { + if (lastModifiedTime != -1L) + throw new IllegalArgumentException(); + modTime = now; + } else { + modTime = TimeUnit.MILLISECONDS.convert(lastModifiedTime, unit); + } + modTime = WindowsFileAttributes.toWindowsTime(modTime); + } + if (lastAccessTime != null) { + if (lastAccessTime < 0L) { + if (lastAccessTime != -1L) + throw new IllegalArgumentException(); + accTime = now; + } else { + accTime = TimeUnit.MILLISECONDS.convert(lastAccessTime, unit); + } + accTime = WindowsFileAttributes.toWindowsTime(accTime); + } + if (createTime != null) { + if (createTime < 0L) { + if (createTime != -1L) + throw new IllegalArgumentException(); + crTime = now; + } else { + crTime = TimeUnit.MILLISECONDS.convert(createTime, unit); + } + crTime = WindowsFileAttributes.toWindowsTime(crTime); + } + + setFileTimes(crTime, accTime, modTime); + } + } + + static class Dos extends Basic implements DosFileAttributeView { + private static final String READONLY_NAME = "readonly"; + private static final String ARCHIVE_NAME = "archive"; + private static final String SYSTEM_NAME = "system"; + private static final String HIDDEN_NAME = "hidden"; + private static final String ATTRIBUTES_NAME = "attributes"; + + Dos(WindowsPath file, boolean followLinks) { + super(file, followLinks); + } + + @Override + public String name() { + return "dos"; + } + + @Override + public Object getAttribute(String attribute) throws IOException { + if (attribute.equals(READONLY_NAME)) + return readAttributes().isReadOnly(); + if (attribute.equals(ARCHIVE_NAME)) + return readAttributes().isArchive(); + if (attribute.equals(SYSTEM_NAME)) + return readAttributes().isSystem(); + if (attribute.equals(HIDDEN_NAME)) + return readAttributes().isHidden(); + // implementation specific + if (attribute.equals(ATTRIBUTES_NAME)) + return readAttributes().attributes(); + return super.getAttribute(attribute); + } + + @Override + public void setAttribute(String attribute, Object value) + throws IOException + { + if (attribute.equals(READONLY_NAME)) { + setReadOnly((Boolean)value); + return; + } + if (attribute.equals(ARCHIVE_NAME)) { + setArchive((Boolean)value); + return; + } + if (attribute.equals(SYSTEM_NAME)) { + setSystem((Boolean)value); + return; + } + if (attribute.equals(HIDDEN_NAME)) { + setHidden((Boolean)value); + return; + } + super.setAttribute(attribute, value); + } + + @Override + public Map<String,?> readAttributes(String first, String[] rest) + throws IOException + { + AttributesBuilder builder = AttributesBuilder.create(first, rest); + WindowsFileAttributes attrs = readAttributes(); + addBasicAttributesToBuilder(attrs, builder); + if (builder.match(READONLY_NAME)) + builder.add(READONLY_NAME, attrs.isReadOnly()); + if (builder.match(ARCHIVE_NAME)) + builder.add(ARCHIVE_NAME, attrs.isArchive()); + if (builder.match(SYSTEM_NAME)) + builder.add(SYSTEM_NAME, attrs.isSystem()); + if (builder.match(HIDDEN_NAME)) + builder.add(HIDDEN_NAME, attrs.isHidden()); + if (builder.match(ATTRIBUTES_NAME)) + builder.add(ATTRIBUTES_NAME, attrs.attributes()); + return builder.unmodifiableMap(); + } + + /** + * Update DOS attributes + */ + private void updateAttributes(int flag, boolean enable) + throws IOException + { + file.checkWrite(); + + // GetFileAttribtues & SetFileAttributes do not follow links so when + // following links we need the final target + String path = WindowsLinkSupport.getFinalPath(file, followLinks); + try { + int oldValue = GetFileAttributes(path); + int newValue = oldValue; + if (enable) { + newValue |= flag; + } else { + newValue &= ~flag; + } + if (newValue != oldValue) { + SetFileAttributes(path, newValue); + } + } catch (WindowsException x) { + // don't reveal target in exception + x.rethrowAsIOException(file); + } + } + + @Override + public void setReadOnly(boolean value) throws IOException { + updateAttributes(FILE_ATTRIBUTE_READONLY, value); + } + + @Override + public void setHidden(boolean value) throws IOException { + updateAttributes(FILE_ATTRIBUTE_HIDDEN, value); + } + + @Override + public void setArchive(boolean value) throws IOException { + updateAttributes(FILE_ATTRIBUTE_ARCHIVE, value); + } + + @Override + public void setSystem(boolean value) throws IOException { + updateAttributes(FILE_ATTRIBUTE_SYSTEM, value); + } + + // package-private + // Copy given attributes to the file. + void setAttributes(WindowsFileAttributes attrs) + throws IOException + { + // copy DOS attributes to target + int flags = 0; + if (attrs.isReadOnly()) flags |= FILE_ATTRIBUTE_READONLY; + if (attrs.isHidden()) flags |= FILE_ATTRIBUTE_HIDDEN; + if (attrs.isArchive()) flags |= FILE_ATTRIBUTE_ARCHIVE; + if (attrs.isSystem()) flags |= FILE_ATTRIBUTE_SYSTEM; + updateAttributes(flags, true); + + // copy file times to target - must be done after updating FAT attributes + // as otherwise the last modified time may be wrong. + setFileTimes( + WindowsFileAttributes.toWindowsTime(attrs.creationTime()), + WindowsFileAttributes.toWindowsTime(attrs.lastModifiedTime()), + WindowsFileAttributes.toWindowsTime(attrs.lastAccessTime())); + } + } + + static BasicFileAttributeView createBasicView(WindowsPath file, boolean followLinks) { + return new Basic(file, followLinks); + } + + static WindowsFileAttributeViews.Dos createDosView(WindowsPath file, boolean followLinks) { + return new Dos(file, followLinks); + } +} diff --git a/src/windows/classes/sun/nio/fs/WindowsFileAttributes.java b/src/windows/classes/sun/nio/fs/WindowsFileAttributes.java new file mode 100644 index 0000000000000000000000000000000000000000..ce053cf901f6763e87127207293ff4c66e7ac941 --- /dev/null +++ b/src/windows/classes/sun/nio/fs/WindowsFileAttributes.java @@ -0,0 +1,461 @@ +/* + * Copyright 2008-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 sun.nio.fs; + +import java.nio.file.attribute.*; +import java.util.concurrent.TimeUnit; +import java.security.AccessController; +import sun.misc.Unsafe; +import sun.security.action.GetPropertyAction; + +import static sun.nio.fs.WindowsNativeDispatcher.*; +import static sun.nio.fs.WindowsConstants.*; + +/** + * Windows implementation of DosFileAttributes/BasicFileAttributes + */ + +class WindowsFileAttributes + implements DosFileAttributes +{ + private static final Unsafe unsafe = Unsafe.getUnsafe(); + + /* + * typedef struct _BY_HANDLE_FILE_INFORMATION { + * DWORD dwFileAttributes; + * FILETIME ftCreationTime; + * FILETIME ftLastAccessTime; + * FILETIME ftLastWriteTime; + * DWORD dwVolumeSerialNumber; + * DWORD nFileSizeHigh; + * DWORD nFileSizeLow; + * DWORD nNumberOfLinks; + * DWORD nFileIndexHigh; + * DWORD nFileIndexLow; + * } BY_HANDLE_FILE_INFORMATION; + */ + private static final short SIZEOF_FILE_INFORMATION = 52; + private static final short OFFSETOF_FILE_INFORMATION_ATTRIBUTES = 0; + private static final short OFFSETOF_FILE_INFORMATION_CREATETIME = 4; + private static final short OFFSETOF_FILE_INFORMATION_LASTACCESSTIME = 12; + private static final short OFFSETOF_FILE_INFORMATION_LASTWRITETIME = 20; + private static final short OFFSETOF_FILE_INFORMATION_VOLSERIALNUM = 28; + private static final short OFFSETOF_FILE_INFORMATION_SIZEHIGH = 32; + private static final short OFFSETOF_FILE_INFORMATION_SIZELOW = 36; + private static final short OFFSETOF_FILE_INFORMATION_NUMLINKS = 40; + private static final short OFFSETOF_FILE_INFORMATION_INDEXHIGH = 44; + private static final short OFFSETOF_FILE_INFORMATION_INDEXLOW = 48; + + /* + * typedef struct _WIN32_FILE_ATTRIBUTE_DATA { + * DWORD dwFileAttributes; + * FILETIME ftCreationTime; + * FILETIME ftLastAccessTime; + * FILETIME ftLastWriteTime; + * DWORD nFileSizeHigh; + * DWORD nFileSizeLow; + * } WIN32_FILE_ATTRIBUTE_DATA; + */ + private static final short SIZEOF_FILE_ATTRIBUTE_DATA = 36; + private static final short OFFSETOF_FILE_ATTRIBUTE_DATA_ATTRIBUTES = 0; + private static final short OFFSETOF_FILE_ATTRIBUTE_DATA_CREATETIME = 4; + private static final short OFFSETOF_FILE_ATTRIBUTE_DATA_LASTACCESSTIME = 12; + private static final short OFFSETOF_FILE_ATTRIBUTE_DATA_LASTWRITETIME = 20; + private static final short OFFSETOF_FILE_ATTRIBUTE_DATA_SIZEHIGH = 28; + private static final short OFFSETOF_FILE_ATTRIBUTE_DATA_SIZELOW = 32; + + /** + * typedef struct _WIN32_FIND_DATA { + * DWORD dwFileAttributes; + * FILETIME ftCreationTime; + * FILETIME ftLastAccessTime; + * FILETIME ftLastWriteTime; + * DWORD nFileSizeHigh; + * DWORD nFileSizeLow; + * DWORD dwReserved0; + * DWORD dwReserved1; + * TCHAR cFileName[MAX_PATH]; + * TCHAR cAlternateFileName[14]; + * } WIN32_FIND_DATA; + */ + private static final short SIZEOF_FIND_DATA = 592; + private static final short OFFSETOF_FIND_DATA_ATTRIBUTES = 0; + private static final short OFFSETOF_FIND_DATA_CREATETIME = 4; + private static final short OFFSETOF_FIND_DATA_LASTACCESSTIME = 12; + private static final short OFFSETOF_FIND_DATA_LASTWRITETIME = 20; + private static final short OFFSETOF_FIND_DATA_SIZEHIGH = 28; + private static final short OFFSETOF_FIND_DATA_SIZELOW = 32; + private static final short OFFSETOF_FIND_DATA_RESERVED0 = 36; + + // indicates if accurate metadata is required (interesting on NTFS only) + private static final boolean ensureAccurateMetadata; + static { + String propValue = AccessController.doPrivileged( + new GetPropertyAction("sun.nio.fs.ensureAccurateMetadata", "false")); + ensureAccurateMetadata = (propValue.length() == 0) ? + true : Boolean.valueOf(propValue); + } + + // attributes + private final int fileAttrs; + private final long creationTime; + private final long lastAccessTime; + private final long lastWriteTime; + private final long size; + private final int reparseTag; + + // additional attributes when using GetFileInformationByHandle + private final int linkCount; + private final int volSerialNumber; + private final int fileIndexHigh; + private final int fileIndexLow; + + /** + * Convert 64-bit value representing the number of 100-nanosecond intervals + * since January 1, 1601 to java time. + */ + private static long toJavaTime(long time) { + time /= 10000L; + time -= 11644473600000L; + return time; + } + + /** + * Convert java time to 64-bit value representing the number of 100-nanosecond + * intervals since January 1, 1601. + */ + static long toWindowsTime(long time) { + time += 11644473600000L; + time *= 10000L; + return time; + } + + /** + * Initialize a new instance of this class + */ + private WindowsFileAttributes(int fileAttrs, + long creationTime, + long lastAccessTime, + long lastWriteTime, + long size, + int reparseTag, + int linkCount, + int volSerialNumber, + int fileIndexHigh, + int fileIndexLow) + { + this.fileAttrs = fileAttrs; + this.creationTime = creationTime; + this.lastAccessTime = lastAccessTime; + this.lastWriteTime = lastWriteTime; + this.size = size; + this.reparseTag = reparseTag; + this.linkCount = linkCount; + this.volSerialNumber = volSerialNumber; + this.fileIndexHigh = fileIndexHigh; + this.fileIndexLow = fileIndexLow; + } + + /** + * Create a WindowsFileAttributes from a BY_HANDLE_FILE_INFORMATION structure + */ + private static WindowsFileAttributes fromFileInformation(long address, int reparseTag) { + int fileAttrs = unsafe.getInt(address + OFFSETOF_FILE_INFORMATION_ATTRIBUTES); + long creationTime = + toJavaTime(unsafe.getLong(address + OFFSETOF_FILE_INFORMATION_CREATETIME)); + long lastAccessTime = + toJavaTime(unsafe.getLong(address + OFFSETOF_FILE_INFORMATION_LASTACCESSTIME)); + long lastWriteTime = + toJavaTime(unsafe.getLong(address + OFFSETOF_FILE_INFORMATION_LASTWRITETIME)); + long size = ((long)(unsafe.getInt(address + OFFSETOF_FILE_INFORMATION_SIZEHIGH)) << 32) + + (unsafe.getInt(address + OFFSETOF_FILE_INFORMATION_SIZELOW) & 0xFFFFFFFFL); + int linkCount = unsafe.getInt(address + OFFSETOF_FILE_INFORMATION_NUMLINKS); + int volSerialNumber = unsafe.getInt(address + OFFSETOF_FILE_INFORMATION_VOLSERIALNUM); + int fileIndexHigh = unsafe.getInt(address + OFFSETOF_FILE_INFORMATION_INDEXHIGH); + int fileIndexLow = unsafe.getInt(address + OFFSETOF_FILE_INFORMATION_INDEXLOW); + return new WindowsFileAttributes(fileAttrs, + creationTime, + lastAccessTime, + lastWriteTime, + size, + reparseTag, + linkCount, + volSerialNumber, + fileIndexHigh, + fileIndexLow); + } + + /** + * Create a WindowsFileAttributes from a WIN32_FILE_ATTRIBUTE_DATA structure + */ + private static WindowsFileAttributes fromFileAttributeData(long address, int reparseTag) { + int fileAttrs = unsafe.getInt(address + OFFSETOF_FILE_ATTRIBUTE_DATA_ATTRIBUTES); + long creationTime = + toJavaTime(unsafe.getLong(address + OFFSETOF_FILE_ATTRIBUTE_DATA_CREATETIME)); + long lastAccessTime = + toJavaTime(unsafe.getLong(address + OFFSETOF_FILE_ATTRIBUTE_DATA_LASTACCESSTIME)); + long lastWriteTime = + toJavaTime(unsafe.getLong(address + OFFSETOF_FILE_ATTRIBUTE_DATA_LASTWRITETIME)); + long size = ((long)(unsafe.getInt(address + OFFSETOF_FILE_ATTRIBUTE_DATA_SIZEHIGH)) << 32) + + (unsafe.getInt(address + OFFSETOF_FILE_ATTRIBUTE_DATA_SIZELOW) & 0xFFFFFFFFL); + return new WindowsFileAttributes(fileAttrs, + creationTime, + lastAccessTime, + lastWriteTime, + size, + reparseTag, + 1, // linkCount + 0, // volSerialNumber + 0, // fileIndexHigh + 0); // fileIndexLow + } + + + /** + * Allocates a native buffer for a WIN32_FIND_DATA structure + */ + static NativeBuffer getBufferForFindData() { + return NativeBuffers.getNativeBuffer(SIZEOF_FIND_DATA); + } + + /** + * Create a WindowsFileAttributes from a WIN32_FIND_DATA structure + */ + static WindowsFileAttributes fromFindData(long address) { + int fileAttrs = unsafe.getInt(address + OFFSETOF_FIND_DATA_ATTRIBUTES); + long creationTime = + toJavaTime(unsafe.getLong(address + OFFSETOF_FIND_DATA_CREATETIME)); + long lastAccessTime = + toJavaTime(unsafe.getLong(address + OFFSETOF_FIND_DATA_LASTACCESSTIME)); + long lastWriteTime = + toJavaTime(unsafe.getLong(address + OFFSETOF_FIND_DATA_LASTWRITETIME)); + long size = ((long)(unsafe.getInt(address + OFFSETOF_FIND_DATA_SIZEHIGH)) << 32) + + (unsafe.getInt(address + OFFSETOF_FIND_DATA_SIZELOW) & 0xFFFFFFFFL); + int reparseTag = ((fileAttrs & FILE_ATTRIBUTE_REPARSE_POINT) != 0) ? + + unsafe.getInt(address + OFFSETOF_FIND_DATA_RESERVED0) : 0; + return new WindowsFileAttributes(fileAttrs, + creationTime, + lastAccessTime, + lastWriteTime, + size, + reparseTag, + 1, // linkCount + 0, // volSerialNumber + 0, // fileIndexHigh + 0); // fileIndexLow + } + + /** + * Reads the attributes of an open file + */ + static WindowsFileAttributes readAttributes(long handle) + throws WindowsException + { + NativeBuffer buffer = NativeBuffers + .getNativeBuffer(SIZEOF_FILE_INFORMATION); + try { + long address = buffer.address(); + GetFileInformationByHandle(handle, address); + + // if file is a reparse point then read the tag + int reparseTag = 0; + int fileAttrs = unsafe + .getInt(address + OFFSETOF_FILE_INFORMATION_ATTRIBUTES); + if ((fileAttrs & FILE_ATTRIBUTE_REPARSE_POINT) != 0) { + int size = MAXIMUM_REPARSE_DATA_BUFFER_SIZE; + NativeBuffer reparseBuffer = NativeBuffers.getNativeBuffer(size); + try { + DeviceIoControlGetReparsePoint(handle, reparseBuffer.address(), size); + reparseTag = (int)unsafe.getLong(reparseBuffer.address()); + } finally { + reparseBuffer.release(); + } + } + + return fromFileInformation(address, reparseTag); + } finally { + buffer.release(); + } + } + + /** + * Returns attributes of given file. + */ + static WindowsFileAttributes get(WindowsPath path, boolean followLinks) + throws WindowsException + { + if (!ensureAccurateMetadata) { + NativeBuffer buffer = + NativeBuffers.getNativeBuffer(SIZEOF_FILE_ATTRIBUTE_DATA); + try { + long address = buffer.address(); + GetFileAttributesEx(path.getPathForWin32Calls(), address); + // if reparse point then file may be a sym link; otherwise + // just return the attributes + int fileAttrs = unsafe + .getInt(address + OFFSETOF_FILE_ATTRIBUTE_DATA_ATTRIBUTES); + if ((fileAttrs & FILE_ATTRIBUTE_REPARSE_POINT) == 0) + return fromFileAttributeData(address, 0); + } finally { + buffer.release(); + } + } + + // file is reparse point so need to open file to get attributes + long handle = path.openForReadAttributeAccess(followLinks); + try { + return readAttributes(handle); + } finally { + CloseHandle(handle); + } + } + + /** + * Returns true if the attribtues are of the same file - both files must + * be open. + */ + static boolean isSameFile(WindowsFileAttributes attrs1, + WindowsFileAttributes attrs2) + { + // volume serial number and file index must be the same + return (attrs1.volSerialNumber == attrs2.volSerialNumber) && + (attrs1.fileIndexHigh == attrs2.fileIndexHigh) && + (attrs1.fileIndexLow == attrs2.fileIndexLow); + } + + // package-private + int attributes() { + return fileAttrs; + } + + int volSerialNumber() { + if (volSerialNumber == 0) + throw new AssertionError("Should not get here"); + return volSerialNumber; + } + + int fileIndexHigh() { + if (volSerialNumber == 0) + throw new AssertionError("Should not get here"); + return fileIndexHigh; + } + + int fileIndexLow() { + if (volSerialNumber == 0) + throw new AssertionError("Should not get here"); + return fileIndexLow; + } + + @Override + public long size() { + return size; + } + + @Override + public long lastModifiedTime() { + return (lastWriteTime >= 0L) ? lastWriteTime : 0L; + } + + @Override + public long lastAccessTime() { + return (lastAccessTime >= 0L) ? lastAccessTime : 0L; + } + + @Override + public long creationTime() { + return (creationTime >= 0L) ? creationTime : 0L; + } + + @Override + public TimeUnit resolution() { + return TimeUnit.MILLISECONDS; + } + + @Override + public int linkCount() { + return linkCount; + } + + @Override + public Object fileKey() { + return null; + } + + // package private + boolean isReparsePoint() { + return (fileAttrs & FILE_ATTRIBUTE_REPARSE_POINT) != 0; + } + + boolean isDirectoryLink() { + return isSymbolicLink() && ((fileAttrs & FILE_ATTRIBUTE_DIRECTORY) != 0); + } + + @Override + public boolean isSymbolicLink() { + return reparseTag == IO_REPARSE_TAG_SYMLINK; + } + + @Override + public boolean isDirectory() { + // ignore FILE_ATTRIBUTE_DIRECTORY attribute if file is a sym link + if (isSymbolicLink()) + return false; + return ((fileAttrs & FILE_ATTRIBUTE_DIRECTORY) != 0); + } + + @Override + public boolean isOther() { + if (isSymbolicLink()) + return false; + // return true if device or reparse point + return ((fileAttrs & (FILE_ATTRIBUTE_DEVICE | FILE_ATTRIBUTE_REPARSE_POINT)) != 0); + } + + @Override + public boolean isRegularFile() { + return !isSymbolicLink() && !isDirectory() && !isOther(); + } + + @Override + public boolean isReadOnly() { + return (fileAttrs & FILE_ATTRIBUTE_READONLY) != 0; + } + + @Override + public boolean isHidden() { + return (fileAttrs & FILE_ATTRIBUTE_HIDDEN) != 0; + } + + @Override + public boolean isArchive() { + return (fileAttrs & FILE_ATTRIBUTE_ARCHIVE) != 0; + } + + @Override + public boolean isSystem() { + return (fileAttrs & FILE_ATTRIBUTE_SYSTEM) != 0; + } +} diff --git a/src/windows/classes/sun/nio/fs/WindowsFileCopy.java b/src/windows/classes/sun/nio/fs/WindowsFileCopy.java new file mode 100644 index 0000000000000000000000000000000000000000..69a41262aed88a1c82a8f9b10d3e731f9446a148 --- /dev/null +++ b/src/windows/classes/sun/nio/fs/WindowsFileCopy.java @@ -0,0 +1,519 @@ +/* + * Copyright 2008-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 sun.nio.fs; + +import java.nio.file.*; +import java.io.IOException; +import java.util.concurrent.ExecutionException; +import com.sun.nio.file.ExtendedCopyOption; + +import static sun.nio.fs.WindowsNativeDispatcher.*; +import static sun.nio.fs.WindowsConstants.*; + +/** + * Utility methods for copying and moving files. + */ + +class WindowsFileCopy { + private WindowsFileCopy() { + } + + /** + * Copy file from source to target + */ + static void copy(final WindowsPath source, + final WindowsPath target, + CopyOption... options) + throws IOException + { + // map options + boolean replaceExisting = false; + boolean copyAttributes = false; + boolean followLinks = true; + boolean interruptible = false; + for (CopyOption option: options) { + if (option == StandardCopyOption.REPLACE_EXISTING) { + replaceExisting = true; + continue; + } + if (option == LinkOption.NOFOLLOW_LINKS) { + followLinks = false; + continue; + } + if (option == StandardCopyOption.COPY_ATTRIBUTES) { + copyAttributes = true; + continue; + } + if (option == ExtendedCopyOption.INTERRUPTIBLE) { + interruptible = true; + continue; + } + if (option == null) + throw new NullPointerException(); + throw new UnsupportedOperationException("Unsupported copy option"); + } + + // check permissions. If the source file is a symbolic link then + // later we must also check LinkPermission + SecurityManager sm = System.getSecurityManager(); + if (sm != null) { + source.checkRead(); + target.checkWrite(); + } + + // get attributes of source file + // attempt to get attributes of target file + // if both files are the same there is nothing to do + // if target exists and !replace then throw exception + + WindowsFileAttributes sourceAttrs = null; + WindowsFileAttributes targetAttrs = null; + + long sourceHandle = 0L; + try { + sourceHandle = source.openForReadAttributeAccess(followLinks); + } catch (WindowsException x) { + x.rethrowAsIOException(source); + } + try { + // source attributes + try { + sourceAttrs = WindowsFileAttributes.readAttributes(sourceHandle); + } catch (WindowsException x) { + x.rethrowAsIOException(source); + } + + // open target (don't follow links) + long targetHandle = 0L; + try { + targetHandle = target.openForReadAttributeAccess(false); + try { + targetAttrs = WindowsFileAttributes.readAttributes(targetHandle); + + // if both files are the same then nothing to do + if (WindowsFileAttributes.isSameFile(sourceAttrs, targetAttrs)) { + return; + } + + // can't replace file + if (!replaceExisting) { + throw new FileAlreadyExistsException( + target.getPathForExceptionMessage()); + } + + } finally { + CloseHandle(targetHandle); + } + } catch (WindowsException x) { + // ignore + } + + } finally { + CloseHandle(sourceHandle); + } + + // if source file is a symbolic link then we must check for LinkPermission + if (sm != null && sourceAttrs.isSymbolicLink()) { + sm.checkPermission(new LinkPermission("symbolic")); + } + + final String sourcePath = asWin32Path(source); + final String targetPath = asWin32Path(target); + + // if target exists then delete it. + if (targetAttrs != null) { + try { + if (targetAttrs.isDirectory() || targetAttrs.isDirectoryLink()) { + RemoveDirectory(targetPath); + } else { + DeleteFile(targetPath); + } + } catch (WindowsException x) { + if (targetAttrs.isDirectory()) { + // ERROR_ALREADY_EXISTS is returned when attempting to delete + // non-empty directory on SAMBA servers. + if (x.lastError() == ERROR_DIR_NOT_EMPTY || + x.lastError() == ERROR_ALREADY_EXISTS) + { + throw new FileAlreadyExistsException( + target.getPathForExceptionMessage()); + } + } + x.rethrowAsIOException(target); + } + } + + // Use CopyFileEx if the file is not a directory or junction + if (!sourceAttrs.isDirectory() && !sourceAttrs.isDirectoryLink()) { + final int flags = + (source.getFileSystem().supportsLinks() && !followLinks) ? + COPY_FILE_COPY_SYMLINK : 0; + + if (interruptible) { + // interruptible copy + Cancellable copyTask = new Cancellable() { + @Override + public int cancelValue() { + return 1; // TRUE + } + @Override + public void implRun() throws IOException { + try { + CopyFileEx(sourcePath, targetPath, flags, + addressToPollForCancel()); + } catch (WindowsException x) { + x.rethrowAsIOException(source, target); + } + } + }; + try { + Cancellable.runInterruptibly(copyTask); + } catch (ExecutionException e) { + Throwable t = e.getCause(); + if (t instanceof IOException) + throw (IOException)t; + throw new IOException(t); + } + } else { + // non-interruptible copy + try { + CopyFileEx(sourcePath, targetPath, flags, 0L); + } catch (WindowsException x) { + x.rethrowAsIOException(source, target); + } + } + if (copyAttributes) { + // CopyFileEx does not copy security attributes + try { + copySecurityAttributes(source, target, followLinks); + } catch (IOException x) { + // ignore + } + } + return; + } + + // copy directory or directory junction + try { + if (sourceAttrs.isDirectory()) { + CreateDirectory(targetPath, 0L); + } else { + String linkTarget = WindowsLinkSupport.readLink(source); + int flags = SYMBOLIC_LINK_FLAG_DIRECTORY; + CreateSymbolicLink(targetPath, + addPrefixIfNeeded(linkTarget), + flags); + } + } catch (WindowsException x) { + x.rethrowAsIOException(target); + } + if (copyAttributes) { + // copy DOS/timestamps attributes + WindowsFileAttributeViews.Dos view = + WindowsFileAttributeViews.createDosView(target, false); + try { + view.setAttributes(sourceAttrs); + } catch (IOException x) { + if (sourceAttrs.isDirectory()) { + try { + RemoveDirectory(targetPath); + } catch (WindowsException ignore) { } + } + } + + // copy security attributes. If this fail it doesn't cause the move + // to fail. + try { + copySecurityAttributes(source, target, followLinks); + } catch (IOException ignore) { } + } + } + + /** + * Move file from source to target + */ + static void move(WindowsPath source, WindowsPath target, CopyOption... options) + throws IOException + { + // map options + boolean atomicMove = false; + boolean replaceExisting = false; + for (CopyOption option: options) { + if (option == StandardCopyOption.ATOMIC_MOVE) { + atomicMove = true; + continue; + } + if (option == StandardCopyOption.REPLACE_EXISTING) { + replaceExisting = true; + continue; + } + if (option == LinkOption.NOFOLLOW_LINKS) { + // ignore + continue; + } + if (option == null) throw new NullPointerException(); + throw new UnsupportedOperationException("Unsupported copy option"); + } + + SecurityManager sm = System.getSecurityManager(); + if (sm != null) { + source.checkWrite(); + target.checkWrite(); + } + + final String sourcePath = asWin32Path(source); + final String targetPath = asWin32Path(target); + + // atomic case + if (atomicMove) { + try { + MoveFileEx(sourcePath, targetPath, MOVEFILE_REPLACE_EXISTING); + } catch (WindowsException x) { + if (x.lastError() == ERROR_NOT_SAME_DEVICE) { + throw new AtomicMoveNotSupportedException( + source.getPathForExceptionMessage(), + target.getPathForExceptionMessage(), + x.errorString()); + } + x.rethrowAsIOException(source, target); + } + return; + } + + // get attributes of source file + // attempt to get attributes of target file + // if both files are the same there is nothing to do + // if target exists and !replace then throw exception + + WindowsFileAttributes sourceAttrs = null; + WindowsFileAttributes targetAttrs = null; + + long sourceHandle = 0L; + try { + sourceHandle = source.openForReadAttributeAccess(false); + } catch (WindowsException x) { + x.rethrowAsIOException(source); + } + try { + // source attributes + try { + sourceAttrs = WindowsFileAttributes.readAttributes(sourceHandle); + } catch (WindowsException x) { + x.rethrowAsIOException(source); + } + + // open target (don't follow links) + long targetHandle = 0L; + try { + targetHandle = target.openForReadAttributeAccess(false); + try { + targetAttrs = WindowsFileAttributes.readAttributes(targetHandle); + + // if both files are the same then nothing to do + if (WindowsFileAttributes.isSameFile(sourceAttrs, targetAttrs)) { + return; + } + + // can't replace file + if (!replaceExisting) { + throw new FileAlreadyExistsException( + target.getPathForExceptionMessage()); + } + + } finally { + CloseHandle(targetHandle); + } + } catch (WindowsException x) { + // ignore + } + + } finally { + CloseHandle(sourceHandle); + } + + // if target exists then delete it. + if (targetAttrs != null) { + try { + if (targetAttrs.isDirectory() || targetAttrs.isDirectoryLink()) { + RemoveDirectory(targetPath); + } else { + DeleteFile(targetPath); + } + } catch (WindowsException x) { + if (targetAttrs.isDirectory()) { + // ERROR_ALREADY_EXISTS is returned when attempting to delete + // non-empty directory on SAMBA servers. + if (x.lastError() == ERROR_DIR_NOT_EMPTY || + x.lastError() == ERROR_ALREADY_EXISTS) + { + throw new FileAlreadyExistsException( + target.getPathForExceptionMessage()); + } + } + x.rethrowAsIOException(target); + } + } + + // first try MoveFileEx (no options). If target is on same volume then + // all attributes (including security attributes) are preserved. + try { + MoveFileEx(sourcePath, targetPath, 0); + return; + } catch (WindowsException x) { + if (x.lastError() != ERROR_NOT_SAME_DEVICE) + x.rethrowAsIOException(source, target); + } + + // target is on different volume so use MoveFileEx with copy option + if (!sourceAttrs.isDirectory() && !sourceAttrs.isDirectoryLink()) { + try { + MoveFileEx(sourcePath, targetPath, MOVEFILE_COPY_ALLOWED); + } catch (WindowsException x) { + x.rethrowAsIOException(source, target); + } + // MoveFileEx does not copy security attributes when moving + // across volumes. + try { + copySecurityAttributes(source, target, false); + } catch (IOException x) { + // ignore + } + return; + } + + // moving directory or directory-link to another file system + assert sourceAttrs.isDirectory() || sourceAttrs.isDirectoryLink(); + + // create new directory or directory junction + try { + if (sourceAttrs.isDirectory()) { + CreateDirectory(targetPath, 0L); + } else { + String linkTarget = WindowsLinkSupport.readLink(source); + CreateSymbolicLink(targetPath, + addPrefixIfNeeded(linkTarget), + SYMBOLIC_LINK_FLAG_DIRECTORY); + } + } catch (WindowsException x) { + x.rethrowAsIOException(target); + } + + // copy timestamps/DOS attributes + WindowsFileAttributeViews.Dos view = + WindowsFileAttributeViews.createDosView(target, false); + try { + view.setAttributes(sourceAttrs); + } catch (IOException x) { + // rollback + try { + RemoveDirectory(targetPath); + } catch (WindowsException ignore) { } + throw x; + } + + // copy security attributes. If this fails it doesn't cause the move + // to fail. + try { + copySecurityAttributes(source, target, false); + } catch (IOException ignore) { } + + // delete source + try { + RemoveDirectory(sourcePath); + } catch (WindowsException x) { + // rollback + try { + RemoveDirectory(targetPath); + } catch (WindowsException ignore) { } + // ERROR_ALREADY_EXISTS is returned when attempting to delete + // non-empty directory on SAMBA servers. + if (x.lastError() == ERROR_DIR_NOT_EMPTY || + x.lastError() == ERROR_ALREADY_EXISTS) + { + throw new DirectoryNotEmptyException( + target.getPathForExceptionMessage()); + } + x.rethrowAsIOException(source); + } + } + + + private static String asWin32Path(WindowsPath path) throws IOException { + try { + return path.getPathForWin32Calls(); + } catch (WindowsException x) { + x.rethrowAsIOException(path); + return null; + } + } + + /** + * Copy DACL/owner/group from source to target + */ + private static void copySecurityAttributes(WindowsPath source, + WindowsPath target, + boolean followLinks) + throws IOException + { + String path = WindowsLinkSupport.getFinalPath(source, followLinks); + + // may need SeRestorePrivilege to set file owner + WindowsSecurity.Privilege priv = + WindowsSecurity.enablePrivilege("SeRestorePrivilege"); + try { + int request = (DACL_SECURITY_INFORMATION | + OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION); + NativeBuffer buffer = + WindowsAclFileAttributeView.getFileSecurity(path, request); + try { + try { + SetFileSecurity(target.getPathForWin32Calls(), request, + buffer.address()); + } catch (WindowsException x) { + x.rethrowAsIOException(target); + } + } finally { + buffer.release(); + } + } finally { + priv.drop(); + } + } + + /** + * Add long path prefix to path if required + */ + private static String addPrefixIfNeeded(String path) { + if (path.length() > 248) { + if (path.startsWith("\\\\")) { + path = "\\\\?\\UNC" + path.substring(1, path.length()); + } else { + path = "\\\\?\\" + path; + } + } + return path; + } +} diff --git a/src/windows/classes/sun/nio/fs/WindowsFileStore.java b/src/windows/classes/sun/nio/fs/WindowsFileStore.java new file mode 100644 index 0000000000000000000000000000000000000000..5d3a0af253330deccf38a5bd6f44008a9be5f260 --- /dev/null +++ b/src/windows/classes/sun/nio/fs/WindowsFileStore.java @@ -0,0 +1,337 @@ +/* + * Copyright 2008-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 sun.nio.fs; + +import java.nio.file.*; +import java.nio.file.attribute.*; +import java.util.*; +import java.io.IOException; + +import static sun.nio.fs.WindowsConstants.*; +import static sun.nio.fs.WindowsNativeDispatcher.*; + +/** + * Windows implementation of FileStore. + */ + +class WindowsFileStore + extends FileStore +{ + private final String root; + private final VolumeInformation volInfo; + private final int volType; + private final String displayName; // returned by toString + + private WindowsFileStore(String root) throws WindowsException { + assert root.charAt(root.length()-1) == '\\'; + this.root = root; + this.volInfo = GetVolumeInformation(root); + this.volType = GetDriveType(root); + + // file store "display name" is the volume name if available + String vol = volInfo.volumeName(); + if (vol.length() > 0) { + this.displayName = vol; + } else { + // TBD - should we map all types? Does this need to be localized? + this.displayName = (volType == DRIVE_REMOVABLE) ? "Removable Disk" : ""; + } + } + + static WindowsFileStore create(String root, boolean ignoreNotReady) + throws IOException + { + try { + return new WindowsFileStore(root); + } catch (WindowsException x) { + if (ignoreNotReady && x.lastError() == ERROR_NOT_READY) + return null; + x.rethrowAsIOException(root); + return null; // keep compiler happy + } + } + + static WindowsFileStore create(WindowsPath file) throws IOException { + try { + // if the file is a link then GetVolumePathName returns the + // volume that the link is on so we need to call it with the + // final target + String target; + if (file.getFileSystem().supportsLinks()) { + target = WindowsLinkSupport.getFinalPath(file, true); + } else { + // file must exist + WindowsFileAttributes.get(file, true); + target = file.getPathForWin32Calls(); + } + String root = GetVolumePathName(target); + return new WindowsFileStore(root); + } catch (WindowsException x) { + x.rethrowAsIOException(file); + return null; // keep compiler happy + } + } + + VolumeInformation volumeInformation() { + return volInfo; + } + + int volumeType() { + return volType; + } + + @Override + public String name() { + return volInfo.volumeName(); // "SYSTEM", "DVD-RW", ... + } + + @Override + public String type() { + return volInfo.fileSystemName(); // "FAT", "NTFS", ... + } + + @Override + public boolean isReadOnly() { + return ((volInfo.flags() & FILE_READ_ONLY_VOLUME) != 0); + } + + @Override + @SuppressWarnings("unchecked") + public <V extends FileStoreAttributeView> V getFileStoreAttributeView(Class<V> view) { + if (view == FileStoreSpaceAttributeView.class) + return (V) new WindowsFileStoreAttributeView(this); + return (V) null; + } + + @Override + public FileStoreAttributeView getFileStoreAttributeView(String name) { + if (name.equals("space")) + return new WindowsFileStoreAttributeView(this); + if (name.equals("volume")) + return new VolumeFileStoreAttributeView(this); + return null; + } + + @Override + public boolean supportsFileAttributeView(Class<? extends FileAttributeView> type) { + if (type == BasicFileAttributeView.class) + return true; + if (type == AclFileAttributeView.class || type == FileOwnerAttributeView.class) + return ((volInfo.flags() & FILE_PERSISTENT_ACLS) != 0); + if (type == UserDefinedFileAttributeView.class) + return ((volInfo.flags() & FILE_NAMED_STREAMS) != 0); + return false; + } + + @Override + public boolean supportsFileAttributeView(String name) { + if (name.equals("basic") || name.equals("dos")) + return true; + if (name.equals("acl")) + return supportsFileAttributeView(AclFileAttributeView.class); + if (name.equals("owner")) + return supportsFileAttributeView(FileOwnerAttributeView.class); + if (name.equals("xattr")) + return supportsFileAttributeView(UserDefinedFileAttributeView.class); + return false; + } + + @Override + public boolean equals(Object ob) { + if (ob == this) + return true; + if (!(ob instanceof WindowsFileStore)) + return false; + WindowsFileStore other = (WindowsFileStore)ob; + return this.volInfo.volumeSerialNumber() == other.volInfo.volumeSerialNumber(); + } + + @Override + public int hashCode() { + // reveals VSN without permission check - okay? + return volInfo.volumeSerialNumber(); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(displayName); + if (sb.length() > 0) + sb.append(" "); + sb.append("("); + // drop trailing slash + sb.append(root.subSequence(0, root.length()-1)); + sb.append(")"); + return sb.toString(); + } + + static class WindowsFileStoreAttributeView + extends AbstractFileStoreSpaceAttributeView + { + private final WindowsFileStore fs; + + WindowsFileStoreAttributeView(WindowsFileStore fs) { + this.fs = fs; + } + + @Override + public FileStoreSpaceAttributes readAttributes() + throws IOException + { + // read the free space info + DiskFreeSpace info = null; + try { + info = GetDiskFreeSpaceEx(fs.root); + } catch (WindowsException x) { + x.rethrowAsIOException(fs.root); + } + + final DiskFreeSpace result = info; + return new FileStoreSpaceAttributes() { + @Override + public long totalSpace() { + return result.totalNumberOfBytes(); + } + @Override + public long usableSpace() { + return result.freeBytesAvailable(); + } + @Override + public long unallocatedSpace() { + return result.totalNumberOfFreeBytes(); + } + }; + } + } + + /** + * Windows-specific attribute view to allow access to volume information. + */ + static class VolumeFileStoreAttributeView + implements FileStoreAttributeView + { + private static final String VSN_NAME = "vsn"; + private static final String COMPRESSED_NAME = "compressed"; + private static final String REMOVABLE_NAME = "removable"; + private static final String CDROM_NAME = "cdrom"; + + private final WindowsFileStore fs; + + VolumeFileStoreAttributeView(WindowsFileStore fs) { + this.fs = fs; + } + + @Override + public String name() { + return "volume"; + } + + private int vsn() { + return fs.volumeInformation().volumeSerialNumber(); + } + + private boolean isCompressed() { + return (fs.volumeInformation().flags() & + FILE_VOLUME_IS_COMPRESSED) > 0; + } + + private boolean isRemovable() { + return fs.volumeType() == DRIVE_REMOVABLE; + } + + private boolean isCdrom() { + return fs.volumeType() == DRIVE_CDROM; + } + + @Override + public Object getAttribute(String attribute) throws IOException { + if (attribute.equals(VSN_NAME)) + return vsn(); + if (attribute.equals(COMPRESSED_NAME)) + return isCompressed(); + if (attribute.equals(REMOVABLE_NAME)) + return isRemovable(); + if (attribute.equals(CDROM_NAME)) + return isCdrom(); + return null; + } + + @Override + public void setAttribute(String attribute, Object value) + throws IOException + { + throw new UnsupportedOperationException(); + } + + @Override + public Map<String,?> readAttributes(String first, String... rest) + throws IOException + { + boolean all = false; + boolean vsn = false; + boolean compressed = false; + boolean removable = false; + boolean cdrom = false; + + if (first.equals(VSN_NAME)) vsn = true; + else if (first.equals(COMPRESSED_NAME)) compressed = true; + else if (first.equals(REMOVABLE_NAME)) removable = true; + else if (first.equals(CDROM_NAME)) cdrom = true; + else if (first.equals("*")) all = true; + + if (!all) { + for (String attribute: rest) { + if (attribute.equals("*")) { + all = true; + break; + } + if (attribute.equals(VSN_NAME)) { + vsn = true; + continue; + } + if (attribute.equals(COMPRESSED_NAME)) { + compressed = true; + continue; + } + if (attribute.equals(REMOVABLE_NAME)) { + removable = true; + continue; + } + } + } + + Map<String,Object> result = new HashMap<String,Object>(); + if (all || vsn) + result.put(VSN_NAME, vsn()); + if (all || compressed) + result.put(COMPRESSED_NAME, isCompressed()); + if (all || removable) + result.put(REMOVABLE_NAME, isRemovable()); + if (all || cdrom) + result.put(CDROM_NAME, isCdrom()); + return result; + } + } +} diff --git a/src/windows/classes/sun/nio/fs/WindowsFileSystem.java b/src/windows/classes/sun/nio/fs/WindowsFileSystem.java new file mode 100644 index 0000000000000000000000000000000000000000..e80c829f311a8cab81fbebf0fec42bea45845096 --- /dev/null +++ b/src/windows/classes/sun/nio/fs/WindowsFileSystem.java @@ -0,0 +1,317 @@ +/* + * Copyright 2008-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 sun.nio.fs; + +import java.nio.file.*; +import java.nio.file.attribute.*; +import java.nio.file.spi.*; +import java.util.*; +import java.util.regex.Pattern; +import java.io.IOException; +import java.security.AccessController; +import java.security.PrivilegedAction; +import sun.security.action.GetPropertyAction; + +class WindowsFileSystem + extends FileSystem +{ + private final WindowsFileSystemProvider provider; + + // default directory (is absolute), and default root + private final String defaultDirectory; + private final String defaultRoot; + + private final boolean supportsLinks; + private final boolean supportsStreamEnumeration; + + // package-private + WindowsFileSystem(WindowsFileSystemProvider provider, + String dir) + { + this.provider = provider; + + // parse default directory and check it is absolute + WindowsPathParser.Result result = WindowsPathParser.parse(dir); + + if (result.type() != WindowsPathType.ABSOLUTE) + throw new AssertionError("Default directory must be absolute/non-UNC"); + this.defaultDirectory = result.path(); + this.defaultRoot = result.root(); + + PrivilegedAction<String> pa = new GetPropertyAction("os.version"); + String osversion = AccessController.doPrivileged(pa); + String[] vers = osversion.split("\\.", 0); + int major = Integer.parseInt(vers[0]); + int minor = Integer.parseInt(vers[1]); + + // symbolic links available on Vista and newer + supportsLinks = (major >= 6); + + // enumeration of data streams available on Windows Server 2003 and newer + supportsStreamEnumeration = (major >= 6) || (major == 5 && minor >= 2); + } + + // package-private + String defaultDirectory() { + return defaultDirectory; + } + + String defaultRoot() { + return defaultRoot; + } + + boolean supportsLinks() { + return supportsLinks; + } + + boolean supportsStreamEnumeration() { + return supportsStreamEnumeration; + } + + @Override + public FileSystemProvider provider() { + return provider; + } + + @Override + public String getSeparator() { + return "\\"; + } + + @Override + public boolean isOpen() { + return true; + } + + @Override + public boolean isReadOnly() { + return false; + } + + @Override + public void close() throws IOException { + throw new UnsupportedOperationException(); + } + + @Override + public Iterable<Path> getRootDirectories() { + int drives = 0; + try { + drives = WindowsNativeDispatcher.GetLogicalDrives(); + } catch (WindowsException x) { + // shouldn't happen + throw new AssertionError(x.getMessage()); + } + + // iterate over roots, ignoring those that the security manager denies + ArrayList<Path> result = new ArrayList<Path>(); + SecurityManager sm = System.getSecurityManager(); + for (int i = 0; i <= 25; i++) { // 0->A, 1->B, 2->C... + if ((drives & (1 << i)) != 0) { + StringBuilder sb = new StringBuilder(3); + sb.append((char)('A' + i)); + sb.append(":\\"); + String root = sb.toString(); + if (sm != null) { + try { + sm.checkRead(root); + } catch (SecurityException x) { + continue; + } + } + result.add(WindowsPath.createFromNormalizedPath(this, root)); + } + } + return Collections.unmodifiableList(result); + } + + /** + * Iterator returned by getFileStores method. + */ + private class FileStoreIterator implements Iterator<FileStore> { + private final Iterator<Path> roots; + private FileStore next; + + FileStoreIterator() { + this.roots = getRootDirectories().iterator(); + } + + private FileStore readNext() { + assert Thread.holdsLock(this); + for (;;) { + if (!roots.hasNext()) + return null; + WindowsPath root = (WindowsPath)roots.next(); + // ignore if security manager denies access + try { + root.checkRead(); + } catch (SecurityException x) { + continue; + } + try { + FileStore fs = WindowsFileStore.create(root.toString(), true); + if (fs != null) + return fs; + } catch (IOException ioe) { + // skip it + } + } + } + + @Override + public synchronized boolean hasNext() { + if (next != null) + return true; + next = readNext(); + return next != null; + } + + @Override + public synchronized FileStore next() { + if (next == null) + next = readNext(); + if (next == null) { + throw new NoSuchElementException(); + } else { + FileStore result = next; + next = null; + return result; + } + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + } + + @Override + public Iterable<FileStore> getFileStores() { + SecurityManager sm = System.getSecurityManager(); + if (sm != null) { + try { + sm.checkPermission(new RuntimePermission("getFileStoreAttributes")); + } catch (SecurityException se) { + return Collections.emptyList(); + } + } + return new Iterable<FileStore>() { + public Iterator<FileStore> iterator() { + return new FileStoreIterator(); + } + }; + } + + // supported views + private static final Set<String> supportedFileAttributeViews = Collections + .unmodifiableSet(new HashSet<String>(Arrays.asList("basic", "dos", "acl", "owner", "xattr"))); + + @Override + public Set<String> supportedFileAttributeViews() { + return supportedFileAttributeViews; + } + + @Override + public Path getPath(String path) { + return WindowsPath.parse(this, path); + } + + @Override + public UserPrincipalLookupService getUserPrincipalLookupService() { + return theLookupService; + } + + private static final UserPrincipalLookupService theLookupService = + new UserPrincipalLookupService() { + @Override + public UserPrincipal lookupPrincipalByName(String name) + throws IOException + { + return WindowsUserPrincipals.lookup(name); + } + @Override + public GroupPrincipal lookupPrincipalByGroupName(String group) + throws IOException + { + UserPrincipal user = WindowsUserPrincipals.lookup(group); + if (!(user instanceof GroupPrincipal)) + throw new UserPrincipalNotFoundException(group); + return (GroupPrincipal)user; + } + }; + + @Override + public PathMatcher getPathMatcher(String syntaxAndInput) { + int pos = syntaxAndInput.indexOf(':'); + if (pos <= 0 || pos == syntaxAndInput.length()) + throw new IllegalArgumentException(); + String syntax = syntaxAndInput.substring(0, pos); + String input = syntaxAndInput.substring(pos+1); + + String expr; + if (syntax.equals(GLOB_SYNTAX)) { + expr = Globs.toWindowsRegexPattern(input); + } else { + if (syntax.equals(REGEX_SYNTAX)) { + expr = input; + } else { + throw new UnsupportedOperationException("Syntax '" + syntax + + "' not recognized"); + } + } + + // match in uppercase + StringBuilder sb = new StringBuilder(expr.length()); + for (int i=0; i<expr.length(); i++) { + sb.append(Character.toUpperCase(expr.charAt(i))); + } + expr = sb.toString(); + + // return matcher + final Pattern pattern = Pattern.compile(expr); + return new PathMatcher() { + @Override + public boolean matches(Path path) { + // match in uppercase + String s = path.toString(); + StringBuilder sb = new StringBuilder(s.length()); + for (int i=0; i<s.length(); i++) { + sb.append( Character.toUpperCase(s.charAt(i)) ); + } + return pattern.matcher(sb).matches(); + } + }; + } + private static final String GLOB_SYNTAX = "glob"; + private static final String REGEX_SYNTAX = "regex"; + + @Override + public WatchService newWatchService() + throws IOException + { + return new WindowsWatchService(this); + } +} diff --git a/src/windows/classes/sun/nio/fs/WindowsFileSystemProvider.java b/src/windows/classes/sun/nio/fs/WindowsFileSystemProvider.java new file mode 100644 index 0000000000000000000000000000000000000000..bc28e95d01dc4780a472561098cbc5a685a86ddf --- /dev/null +++ b/src/windows/classes/sun/nio/fs/WindowsFileSystemProvider.java @@ -0,0 +1,146 @@ +/* + * Copyright 2008-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 sun.nio.fs; + +import java.nio.file.*; +import java.nio.file.spi.*; +import java.nio.file.attribute.*; +import java.nio.channels.*; +import java.net.URI; +import java.util.concurrent.ExecutorService; +import java.io.IOException; +import java.util.*; + +import sun.nio.ch.ThreadPool; + +public class WindowsFileSystemProvider + extends FileSystemProvider +{ + private static final String USER_DIR = "user.dir"; + private final WindowsFileSystem theFileSystem; + + public WindowsFileSystemProvider() { + theFileSystem = new WindowsFileSystem(this, System.getProperty(USER_DIR)); + } + + @Override + public String getScheme() { + return "file"; + } + + private void checkUri(URI uri) { + if (!uri.getScheme().equalsIgnoreCase(getScheme())) + throw new IllegalArgumentException("URI does not match this provider"); + if (uri.getAuthority() != null) + throw new IllegalArgumentException("Authority component present"); + if (uri.getPath() == null) + throw new IllegalArgumentException("Path component is undefined"); + if (!uri.getPath().equals("/")) + throw new IllegalArgumentException("Path component should be '/'"); + if (uri.getQuery() != null) + throw new IllegalArgumentException("Query component present"); + if (uri.getFragment() != null) + throw new IllegalArgumentException("Fragment component present"); + } + + @Override + public FileSystem newFileSystem(URI uri, Map<String,?> env) + throws IOException + { + checkUri(uri); + throw new FileSystemAlreadyExistsException(); + } + + @Override + public final FileSystem getFileSystem(URI uri) { + checkUri(uri); + return theFileSystem; + } + + @Override + public Path getPath(URI uri) { + return WindowsUriSupport.fromUri(theFileSystem, uri); + } + + @Override + public FileChannel newFileChannel(Path path, + Set<? extends OpenOption> options, + FileAttribute<?>... attrs) + throws IOException + { + if (path == null) + throw new NullPointerException(); + if (!(path instanceof WindowsPath)) + throw new ProviderMismatchException(); + WindowsPath file = (WindowsPath)path; + + WindowsSecurityDescriptor sd = WindowsSecurityDescriptor.fromAttribute(attrs); + try { + return WindowsChannelFactory + .newFileChannel(file.getPathForWin32Calls(), + file.getPathForPermissionCheck(), + options, + sd.address()); + } catch (WindowsException x) { + x.rethrowAsIOException(file); + return null; + } finally { + if (sd != null) + sd.release(); + } + } + + @Override + public AsynchronousFileChannel newAsynchronousFileChannel(Path path, + Set<? extends OpenOption> options, + ExecutorService executor, + FileAttribute<?>... attrs) + throws IOException + { + if (path == null) + throw new NullPointerException(); + if (!(path instanceof WindowsPath)) + throw new ProviderMismatchException(); + WindowsPath file = (WindowsPath)path; + ThreadPool pool = (executor == null) ? null : ThreadPool.wrap(executor, 0); + WindowsSecurityDescriptor sd = + WindowsSecurityDescriptor.fromAttribute(attrs); + try { + return WindowsChannelFactory + .newAsynchronousFileChannel(file.getPathForWin32Calls(), + file.getPathForPermissionCheck(), + options, + sd.address(), + pool); + } catch (WindowsException x) { + x.rethrowAsIOException(file); + return null; + } finally { + if (sd != null) + sd.release(); + } + } +} diff --git a/src/windows/classes/sun/nio/fs/WindowsLinkSupport.java b/src/windows/classes/sun/nio/fs/WindowsLinkSupport.java new file mode 100644 index 0000000000000000000000000000000000000000..516275dfe558f24f24d57d8e3fdda081c1bb73d2 --- /dev/null +++ b/src/windows/classes/sun/nio/fs/WindowsLinkSupport.java @@ -0,0 +1,446 @@ +/* + * Copyright 2008-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 sun.nio.fs; + +import java.nio.file.*; +import java.io.IOException; +import java.io.IOError; +import java.security.AccessController; +import java.security.PrivilegedAction; +import sun.misc.Unsafe; + +import static sun.nio.fs.WindowsNativeDispatcher.*; +import static sun.nio.fs.WindowsConstants.*; + +/** + * Utility methods for symbolic link support on Windows Vista and newer. + */ + +class WindowsLinkSupport { + private static final Unsafe unsafe = Unsafe.getUnsafe(); + + private WindowsLinkSupport() { + } + + /** + * Returns the target of a symbolic link + */ + static String readLink(WindowsPath path) throws IOException { + long handle = 0L; + try { + handle = path.openForReadAttributeAccess(false); // don't follow links + } catch (WindowsException x) { + x.rethrowAsIOException(path); + } + try { + return readLinkImpl(handle); + } finally { + CloseHandle(handle); + } + } + + /** + * Returns the final path of a given path as a String. This should be used + * prior to calling Win32 system calls that do not follow links. + */ + static String getFinalPath(WindowsPath input, boolean followLinks) + throws IOException + { + WindowsFileSystem fs = input.getFileSystem(); + + try { + // if not following links then don't need final path + if (!followLinks || !fs.supportsLinks()) + return input.getPathForWin32Calls(); + + // if file is a sym link then don't need final path + if (!WindowsFileAttributes.get(input, false).isSymbolicLink()) { + return input.getPathForWin32Calls(); + } + } catch (WindowsException x) { + x.rethrowAsIOException(input); + } + + // The file is a symbolic link so we open it and try to get the + // normalized path. This should succeed on NTFS but may fail if there + // is a link to a non-NFTS file system. + long h = 0; + try { + h = input.openForReadAttributeAccess(true); + } catch (WindowsException x) { + x.rethrowAsIOException(input); + } + try { + return stripPrefix(GetFinalPathNameByHandle(h)); + } catch (WindowsException x) { + // ERROR_INVALID_LEVEL is the error returned when not supported by + // the file system + if (x.lastError() != ERROR_INVALID_LEVEL) + x.rethrowAsIOException(input); + } finally { + CloseHandle(h); + } + + // Fallback: read target of link, resolve against parent, and repeat + // until file is not a link. + WindowsPath target = input; + int linkCount = 0; + do { + try { + WindowsFileAttributes attrs = + WindowsFileAttributes.get(target, false); + // non a link so we are done + if (!attrs.isSymbolicLink()) { + return target.getPathForWin32Calls(); + } + } catch (WindowsException x) { + x.rethrowAsIOException(target); + } + WindowsPath link = WindowsPath + .createFromNormalizedPath(fs, readLink(target)); + WindowsPath parent = target.getParent(); + if (parent == null) { + // no parent so use parent of absolute path + final WindowsPath t = target; + target = AccessController + .doPrivileged(new PrivilegedAction<WindowsPath>() { + @Override + public WindowsPath run() { + return t.toAbsolutePath(); + }}); + parent = target.getParent(); + } + target = parent.resolve(link); + + } while (++linkCount < 32); + + throw new FileSystemException(input.getPathForExceptionMessage(), null, + "Too many links"); + } + + /** + * Returns the actual path of a file, optionally resolving all symbolic + * links. + */ + static String getRealPath(WindowsPath input, boolean resolveLinks) + throws IOException + { + WindowsFileSystem fs = input.getFileSystem(); + if (!fs.supportsLinks()) + resolveLinks = false; + + // On Vista use GetFinalPathNameByHandle. This should succeed on NTFS + // but may fail if there is a link to a non-NFTS file system. + if (resolveLinks) { + long h = 0; + try { + h = input.openForReadAttributeAccess(true); + } catch (WindowsException x) { + x.rethrowAsIOException(input); + } + try { + return stripPrefix(GetFinalPathNameByHandle(h)); + } catch (WindowsException x) { + if (x.lastError() != ERROR_INVALID_LEVEL) + x.rethrowAsIOException(input); + } finally { + CloseHandle(h); + } + } + + // Not resolving links or we are on Windows Vista (or newer) with a + // link to non-NFTS file system. + + // Start with absolute path + String path = null; + try { + path = input.toAbsolutePath().toString(); + } catch (IOError x) { + throw (IOException)(x.getCause()); + } + + // Collapse "." and ".." + try { + path = GetFullPathName(path); + } catch (WindowsException x) { + x.rethrowAsIOException(input); + } + + // eliminate all symbolic links + if (resolveLinks) { + path = resolveAllLinks(WindowsPath.createFromNormalizedPath(fs, path)); + } + + // string builder to build up components of path + StringBuilder sb = new StringBuilder(path.length()); + + // Copy root component + int start; + char c0 = path.charAt(0); + char c1 = path.charAt(1); + if ((c0 <= 'z' && c0 >= 'a' || c0 <= 'Z' && c0 >= 'A') && + c1 == ':' && path.charAt(2) == '\\') { + // Driver specifier + sb.append(Character.toUpperCase(c0)); + sb.append(":\\"); + start = 3; + } else if (c0 == '\\' && c1 == '\\') { + // UNC pathname, begins with "\\\\host\\share" + int last = path.length() - 1; + int pos = path.indexOf('\\', 2); + // skip both server and share names + if (pos == -1 || (pos == last)) { + // The UNC does not have a share name (collapsed by GetFullPathName) + throw new FileSystemException(input.getPathForExceptionMessage(), + null, "UNC has invalid share"); + } + pos = path.indexOf('\\', pos+1); + if (pos < 0) { + pos = last; + sb.append(path).append("\\"); + } else { + sb.append(path, 0, pos+1); + } + start = pos + 1; + } else { + throw new AssertionError("path type not recognized"); + } + + // check root directory exists + try { + FirstFile fileData = FindFirstFile(sb.toString() + "*"); + FindClose(fileData.handle()); + } catch (WindowsException x) { + x.rethrowAsIOException(path); + } + + // iterate through each component to get its actual name in the + // directory + int curr = start; + while (curr < path.length()) { + int next = path.indexOf('\\', curr); + int end = (next == -1) ? path.length() : next; + String search = sb.toString() + path.substring(curr, end); + try { + FirstFile fileData = FindFirstFile(addLongPathPrefixIfNeeded(search)); + try { + sb.append(fileData.name()); + if (next != -1) { + sb.append('\\'); + } + } finally { + FindClose(fileData.handle()); + } + } catch (WindowsException e) { + e.rethrowAsIOException(path); + } + curr = end + 1; + } + + return sb.toString(); + } + + /** + * Returns target of a symbolic link given the handle of an open file + * (that should be a link). + */ + private static String readLinkImpl(long handle) throws IOException { + int size = MAXIMUM_REPARSE_DATA_BUFFER_SIZE; + NativeBuffer buffer = NativeBuffers.getNativeBuffer(size); + try { + try { + DeviceIoControlGetReparsePoint(handle, buffer.address(), size); + } catch (WindowsException x) { + // FIXME: exception doesn't have file name + if (x.lastError() == ERROR_NOT_A_REPARSE_POINT) + throw new NotLinkException(null, null, x.errorString()); + x.rethrowAsIOException((String)null); + } + + /* + * typedef struct _REPARSE_DATA_BUFFER { + * ULONG ReparseTag; + * USHORT ReparseDataLength; + * USHORT Reserved; + * union { + * struct { + * USHORT SubstituteNameOffset; + * USHORT SubstituteNameLength; + * USHORT PrintNameOffset; + * USHORT PrintNameLength; + * WCHAR PathBuffer[1]; + * } SymbolicLinkReparseBuffer; + * struct { + * USHORT SubstituteNameOffset; + * USHORT SubstituteNameLength; + * USHORT PrintNameOffset; + * USHORT PrintNameLength; + * WCHAR PathBuffer[1]; + * } MountPointReparseBuffer; + * struct { + * UCHAR DataBuffer[1]; + * } GenericReparseBuffer; + * }; + * } REPARSE_DATA_BUFFER + */ + final short OFFSETOF_REPARSETAG = 0; + final short OFFSETOF_PATHOFFSET = 8; + final short OFFSETOF_PATHLENGTH = 10; + final short OFFSETOF_PATHBUFFER = 16 + 4; // check this + + int tag = (int)unsafe.getLong(buffer.address() + OFFSETOF_REPARSETAG); + if (tag != IO_REPARSE_TAG_SYMLINK) { + // FIXME: exception doesn't have file name + throw new NotLinkException(null, null, "Reparse point is not a symbolic link"); + } + + // get offset and length of target + short nameOffset = unsafe.getShort(buffer.address() + OFFSETOF_PATHOFFSET); + short nameLengthInBytes = unsafe.getShort(buffer.address() + OFFSETOF_PATHLENGTH); + if ((nameLengthInBytes % 2) != 0) + throw new FileSystemException(null, null, "Symbolic link corrupted"); + + // copy into char array + char[] name = new char[nameLengthInBytes/2]; + unsafe.copyMemory(null, buffer.address() + OFFSETOF_PATHBUFFER + nameOffset, + name, Unsafe.ARRAY_CHAR_BASE_OFFSET, nameLengthInBytes); + + // remove special prefix + String target = stripPrefix(new String(name)); + if (target.length() == 0) { + throw new IOException("Symbolic link target is invalid"); + } + return target; + } finally { + buffer.release(); + } + } + + /** + * Resolve all symbolic-links in a given absolute and normalized path + */ + private static String resolveAllLinks(WindowsPath path) + throws IOException + { + assert path.isAbsolute(); + WindowsFileSystem fs = path.getFileSystem(); + + // iterate through each name element of the path, resolving links as + // we go. + int linkCount = 0; + int elem = 0; + while (elem < path.getNameCount()) { + WindowsPath current = path.getRoot().resolve(path.subpath(0, elem+1)); + + WindowsFileAttributes attrs = null; + try { + attrs = WindowsFileAttributes.get(current, false); + } catch (WindowsException x) { + x.rethrowAsIOException(current); + } + + /** + * If a symbolic link then we resolve it against the parent + * of the current name element. We then resolve any remaining + * part of the path against the result. The target of the link + * may have "." and ".." components so re-normalize and restart + * the process from the first element. + */ + if (attrs.isSymbolicLink()) { + linkCount++; + if (linkCount > 32) + throw new IOException("Too many links"); + WindowsPath target = WindowsPath + .createFromNormalizedPath(fs, readLink(current)); + WindowsPath remainder = null; + int count = path.getNameCount(); + if ((elem+1) < count) { + remainder = path.subpath(elem+1, count); + } + path = current.getParent().resolve(target); + try { + String full = GetFullPathName(path.toString()); + if (!full.equals(path.toString())) { + path = WindowsPath.createFromNormalizedPath(fs, full); + } + } catch (WindowsException x) { + x.rethrowAsIOException(path); + } + if (remainder != null) { + path = path.resolve(remainder); + } + + // reset + elem = 0; + } else { + // not a link + elem++; + } + } + + return path.toString(); + } + + /** + * Add long path prefix to path if required. + */ + private static String addLongPathPrefixIfNeeded(String path) { + if (path.length() > 248) { + if (path.startsWith("\\\\")) { + path = "\\\\?\\UNC" + path.substring(1, path.length()); + } else { + path = "\\\\?\\" + path; + } + } + return path; + } + + /** + * Strip long path or symbolic link prefix from path + */ + private static String stripPrefix(String path) { + // prefix for resolved/long path + if (path.startsWith("\\\\?\\")) { + if (path.startsWith("\\\\?\\UNC\\")) { + path = "\\" + path.substring(7); + } else { + path = path.substring(4); + } + return path; + } + + // prefix for target of symbolic link + if (path.startsWith("\\??\\")) { + if (path.startsWith("\\??\\UNC\\")) { + path = "\\" + path.substring(7); + } else { + path = path.substring(4); + } + return path; + } + return path; + } +} diff --git a/src/windows/classes/sun/nio/fs/WindowsNativeDispatcher.java b/src/windows/classes/sun/nio/fs/WindowsNativeDispatcher.java new file mode 100644 index 0000000000000000000000000000000000000000..fafee20a4cddec5f7016cfe8fe1d6464cd614e47 --- /dev/null +++ b/src/windows/classes/sun/nio/fs/WindowsNativeDispatcher.java @@ -0,0 +1,1134 @@ +/* + * Copyright 2008-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 sun.nio.fs; + +import java.security.AccessController; +import java.security.PrivilegedAction; +import sun.misc.Unsafe; + +/** + * Win32 and library calls. + */ + +class WindowsNativeDispatcher { + private WindowsNativeDispatcher() { } + + /** + * HANDLE CreateFile( + * LPCTSTR lpFileName, + * DWORD dwDesiredAccess, + * DWORD dwShareMode, + * LPSECURITY_ATTRIBUTES lpSecurityAttributes, + * DWORD dwCreationDisposition, + * DWORD dwFlagsAndAttributes, + * HANDLE hTemplateFile + * ) + */ + static long CreateFile(String path, + int dwDesiredAccess, + int dwShareMode, + long lpSecurityAttributes, + int dwCreationDisposition, + int dwFlagsAndAttributes) + throws WindowsException + { + NativeBuffer buffer = asNativeBuffer(path); + try { + return CreateFile0(buffer.address(), + dwDesiredAccess, + dwShareMode, + lpSecurityAttributes, + dwCreationDisposition, + dwFlagsAndAttributes); + } finally { + buffer.release(); + } + } + static long CreateFile(String path, + int dwDesiredAccess, + int dwShareMode, + int dwCreationDisposition, + int dwFlagsAndAttributes) + throws WindowsException + { + return CreateFile(path, dwDesiredAccess, dwShareMode, 0L, + dwCreationDisposition, dwFlagsAndAttributes); + } + private static native long CreateFile0(long lpFileName, + int dwDesiredAccess, + int dwShareMode, + long lpSecurityAttributes, + int dwCreationDisposition, + int dwFlagsAndAttributes) + throws WindowsException; + + /** + * CloseHandle( + * HANDLE hObject + * ) + */ + static native void CloseHandle(long handle); + + /** + * DeleteFile( + * LPCTSTR lpFileName + * ) + */ + static void DeleteFile(String path) throws WindowsException { + NativeBuffer buffer = asNativeBuffer(path); + try { + DeleteFile0(buffer.address()); + } finally { + buffer.release(); + } + } + private static native void DeleteFile0(long lpFileName) + throws WindowsException; + + /** + * CreateDirectory( + * LPCTSTR lpPathName, + * LPSECURITY_ATTRIBUTES lpSecurityAttributes + * ) + */ + static void CreateDirectory(String path, long lpSecurityAttributes) throws WindowsException { + NativeBuffer buffer = asNativeBuffer(path); + try { + CreateDirectory0(buffer.address(), lpSecurityAttributes); + } finally { + buffer.release(); + } + } + private static native void CreateDirectory0(long lpFileName, long lpSecurityAttributes) + throws WindowsException; + + /** + * RemoveDirectory( + * LPCTSTR lpPathName + * ) + */ + static void RemoveDirectory(String path) throws WindowsException { + NativeBuffer buffer = asNativeBuffer(path); + try { + RemoveDirectory0(buffer.address()); + } finally { + buffer.release(); + } + } + private static native void RemoveDirectory0(long lpFileName) + throws WindowsException; + + /** + * Marks a file as a sparse file. + * + * DeviceIoControl( + * FSCTL_SET_SPARSE + * ) + */ + static native void DeviceIoControlSetSparse(long handle) + throws WindowsException; + + /** + * Retrieves the reparse point data associated with the file or directory. + * + * DeviceIoControl( + * FSCTL_GET_REPARSE_POINT + * ) + */ + static native void DeviceIoControlGetReparsePoint(long handle, + long bufferAddress, int bufferSize) throws WindowsException; + + /** + * HANDLE FindFirstFile( + * LPCTSTR lpFileName, + * LPWIN32_FIND_DATA lpFindFileData + * ) + */ + static FirstFile FindFirstFile(String path) throws WindowsException { + NativeBuffer buffer = asNativeBuffer(path); + try { + FirstFile data = new FirstFile(); + FindFirstFile0(buffer.address(), data); + return data; + } finally { + buffer.release(); + } + } + static class FirstFile { + private long handle; + private String name; + + private FirstFile() { } + public long handle() { return handle; } + public String name() { return name; } + } + private static native void FindFirstFile0(long lpFileName, FirstFile obj) + throws WindowsException; + + /** + * HANDLE FindFirstFile( + * LPCTSTR lpFileName, + * LPWIN32_FIND_DATA lpFindFileData + * ) + */ + static long FindFirstFile(String path, long address) throws WindowsException { + NativeBuffer buffer = asNativeBuffer(path); + try { + return FindFirstFile1(buffer.address(), address); + } finally { + buffer.release(); + } + } + private static native long FindFirstFile1(long lpFileName, long address) + throws WindowsException; + + /** + * FindNextFile( + * HANDLE hFindFile, + * LPWIN32_FIND_DATA lpFindFileData + * ) + * + * @return lpFindFileData->cFileName or null + */ + static native String FindNextFile(long handle, long address) + throws WindowsException; + + /** + * HANDLE FindFirstStreamW( + * LPCWSTR lpFileName, + * STREAM_INFO_LEVELS InfoLevel, + * LPVOID lpFindStreamData, + * DWORD dwFlags + * ) + */ + static FirstStream FindFirstStream(String path) throws WindowsException { + NativeBuffer buffer = asNativeBuffer(path); + try { + FirstStream data = new FirstStream(); + FindFirstStream0(buffer.address(), data); + if (data.handle() == WindowsConstants.INVALID_HANDLE_VALUE) + return null; + return data; + } finally { + buffer.release(); + } + } + static class FirstStream { + private long handle; + private String name; + + private FirstStream() { } + public long handle() { return handle; } + public String name() { return name; } + } + private static native void FindFirstStream0(long lpFileName, FirstStream obj) + throws WindowsException; + + /* + * FindNextStreamW( + * HANDLE hFindStream, + * LPVOID lpFindStreamData + * ) + */ + static native String FindNextStream(long handle) throws WindowsException; + + /** + * FindClose( + * HANDLE hFindFile + * ) + */ + static native void FindClose(long handle) throws WindowsException; + + /** + * GetFileInformationByHandle( + * HANDLE hFile, + * LPBY_HANDLE_FILE_INFORMATION lpFileInformation + * ) + */ + static native void GetFileInformationByHandle(long handle, long address) + throws WindowsException; + + /** + * CopyFileEx( + * LPCWSTR lpExistingFileName + * LPCWSTR lpNewFileName, + * LPPROGRESS_ROUTINE lpProgressRoutine + * LPVOID lpData, + * LPBOOL pbCancel, + * DWORD dwCopyFlags + * ) + */ + static void CopyFileEx(String source, String target, int flags, + long addressToPollForCancel) + throws WindowsException + { + NativeBuffer sourceBuffer = asNativeBuffer(source); + NativeBuffer targetBuffer = asNativeBuffer(target); + try { + CopyFileEx0(sourceBuffer.address(), targetBuffer.address(), flags, + addressToPollForCancel); + } finally { + targetBuffer.release(); + sourceBuffer.release(); + } + } + private static native void CopyFileEx0(long existingAddress, long newAddress, + int flags, long addressToPollForCancel) throws WindowsException; + + /** + * MoveFileEx( + * LPCTSTR lpExistingFileName, + * LPCTSTR lpNewFileName, + * DWORD dwFlags + * ) + */ + static void MoveFileEx(String source, String target, int flags) + throws WindowsException + { + NativeBuffer sourceBuffer = asNativeBuffer(source); + NativeBuffer targetBuffer = asNativeBuffer(target); + try { + MoveFileEx0(sourceBuffer.address(), targetBuffer.address(), flags); + } finally { + targetBuffer.release(); + sourceBuffer.release(); + } + } + private static native void MoveFileEx0(long existingAddress, long newAddress, + int flags) throws WindowsException; + + /** + * DWORD GetFileAttributes( + * LPCTSTR lpFileName + * ) + */ + static int GetFileAttributes(String path) throws WindowsException { + NativeBuffer buffer = asNativeBuffer(path); + try { + return GetFileAttributes0(buffer.address()); + } finally { + buffer.release(); + } + } + private static native int GetFileAttributes0(long lpFileName) + throws WindowsException; + + /** + * SetFileAttributes( + * LPCTSTR lpFileName, + * DWORD dwFileAttributes + */ + static void SetFileAttributes(String path, int dwFileAttributes) + throws WindowsException + { + NativeBuffer buffer = asNativeBuffer(path); + try { + SetFileAttributes0(buffer.address(), dwFileAttributes); + } finally { + buffer.release(); + } + } + private static native void SetFileAttributes0(long lpFileName, + int dwFileAttributes) throws WindowsException; + + /** + * GetFileAttributesEx( + * LPCTSTR lpFileName, + * GET_FILEEX_INFO_LEVELS fInfoLevelId, + * LPVOID lpFileInformation + * ); + */ + static void GetFileAttributesEx(String path, long address) throws WindowsException { + NativeBuffer buffer = asNativeBuffer(path); + try { + GetFileAttributesEx0(buffer.address(), address); + } finally { + buffer.release(); + } + } + private static native void GetFileAttributesEx0(long lpFileName, long address) + throws WindowsException; + /** + * SetFileTime( + * HANDLE hFile, + * CONST FILETIME *lpCreationTime, + * CONST FILETIME *lpLastAccessTime, + * CONST FILETIME *lpLastWriteTime + * ) + */ + static native void SetFileTime(long handle, long createTime, + long lastAccessTime, long lastWriteTime) throws WindowsException; + + /** + * SetEndOfFile( + * HANDLE hFile + * ) + */ + static native void SetEndOfFile(long handle) throws WindowsException; + + /** + * DWORD GetLogicalDrives(VOID) + */ + static native int GetLogicalDrives() throws WindowsException; + + /** + * GetVolumeInformation( + * LPCTSTR lpRootPathName, + * LPTSTR lpVolumeNameBuffer, + * DWORD nVolumeNameSize, + * LPDWORD lpVolumeSerialNumber, + * LPDWORD lpMaximumComponentLength, + * LPDWORD lpFileSystemFlags, + * LPTSTR lpFileSystemNameBuffer, + * DWORD nFileSystemNameSize + * ) + */ + static VolumeInformation GetVolumeInformation(String root) + throws WindowsException + { + NativeBuffer buffer = asNativeBuffer(root); + try { + VolumeInformation info = new VolumeInformation(); + GetVolumeInformation0(buffer.address(), info); + return info; + } finally { + buffer.release(); + } + } + static class VolumeInformation { + private String fileSystemName; + private String volumeName; + private int volumeSerialNumber; + private int flags; + private VolumeInformation() { } + + public String fileSystemName() { return fileSystemName; } + public String volumeName() { return volumeName; } + public int volumeSerialNumber() { return volumeSerialNumber; } + public int flags() { return flags; } + } + private static native void GetVolumeInformation0(long lpRoot, + VolumeInformation obj) + throws WindowsException; + + /** + * UINT GetDriveType( + * LPCTSTR lpRootPathName + * ) + */ + static int GetDriveType(String root) throws WindowsException { + NativeBuffer buffer = asNativeBuffer(root); + try { + return GetDriveType0(buffer.address()); + } finally { + buffer.release(); + } + } + private static native int GetDriveType0(long lpRoot) throws WindowsException; + + /** + * GetDiskFreeSpaceEx( + * LPCTSTR lpDirectoryName, + * PULARGE_INTEGER lpFreeBytesAvailableToCaller, + * PULARGE_INTEGER lpTotalNumberOfBytes, + * PULARGE_INTEGER lpTotalNumberOfFreeBytes + * ) + */ + static DiskFreeSpace GetDiskFreeSpaceEx(String path) + throws WindowsException + { + NativeBuffer buffer = asNativeBuffer(path); + try { + DiskFreeSpace space = new DiskFreeSpace(); + GetDiskFreeSpaceEx0(buffer.address(), space); + return space; + } finally { + buffer.release(); + } + } + static class DiskFreeSpace { + private long freeBytesAvailable; + private long totalNumberOfBytes; + private long totalNumberOfFreeBytes; + private DiskFreeSpace() { } + + public long freeBytesAvailable() { return freeBytesAvailable; } + public long totalNumberOfBytes() { return totalNumberOfBytes; } + public long totalNumberOfFreeBytes() { return totalNumberOfFreeBytes; } + } + private static native void GetDiskFreeSpaceEx0(long lpDirectoryName, + DiskFreeSpace obj) + throws WindowsException; + + + /** + * GetVolumePathName( + * LPCTSTR lpszFileName, + * LPTSTR lpszVolumePathName, + * DWORD cchBufferLength + * ) + * + * @return lpFileName + */ + static String GetVolumePathName(String path) throws WindowsException { + NativeBuffer buffer = asNativeBuffer(path); + try { + return GetVolumePathName0(buffer.address()); + } finally { + buffer.release(); + } + } + private static native String GetVolumePathName0(long lpFileName) + throws WindowsException; + + + /** + * InitializeSecurityDescriptor( + * PSECURITY_DESCRIPTOR pSecurityDescriptor, + * DWORD dwRevision + * ) + */ + static native void InitializeSecurityDescriptor(long sdAddress) + throws WindowsException; + + /** + * InitializeAcl( + * PACL pAcl, + * DWORD nAclLength, + * DWORD dwAclRevision + * ) + */ + static native void InitializeAcl(long aclAddress, int size) + throws WindowsException; + + /** + * GetFileSecurity( + * LPCTSTR lpFileName, + * SECURITY_INFORMATION RequestedInformation, + * PSECURITY_DESCRIPTOR pSecurityDescriptor, + * DWORD nLength, + * LPDWORD lpnLengthNeeded + * ) + */ + static int GetFileSecurity(String path, + int requestedInformation, + long pSecurityDescriptor, + int nLength) throws WindowsException + { + NativeBuffer buffer = asNativeBuffer(path); + try { + return GetFileSecurity0(buffer.address(), requestedInformation, + pSecurityDescriptor, nLength); + } finally { + buffer.release(); + } + } + private static native int GetFileSecurity0(long lpFileName, + int requestedInformation, + long pSecurityDescriptor, + int nLength) throws WindowsException; + + /** + * SetFileSecurity( + * LPCTSTR lpFileName, + * SECURITY_INFORMATION SecurityInformation, + * PSECURITY_DESCRIPTOR pSecurityDescriptor + * ) + */ + static void SetFileSecurity(String path, + int securityInformation, + long pSecurityDescriptor) + throws WindowsException + { + NativeBuffer buffer = asNativeBuffer(path); + try { + SetFileSecurity0(buffer.address(), securityInformation, + pSecurityDescriptor); + } finally { + buffer.release(); + } + } + static native void SetFileSecurity0(long lpFileName, int securityInformation, + long pSecurityDescriptor) throws WindowsException; + + /** + * GetSecurityDescriptorOwner( + * PSECURITY_DESCRIPTOR pSecurityDescriptor + * PSID *pOwner, + * LPBOOL lpbOwnerDefaulted + * ) + * + * @return pOwner + */ + static native long GetSecurityDescriptorOwner(long pSecurityDescriptor) + throws WindowsException; + + /** + * SetSecurityDescriptorOwner( + * PSECURITY_DESCRIPTOR pSecurityDescriptor, + * PSID pOwner, + * BOOL bOwnerDefaulted + * ) + */ + static native void SetSecurityDescriptorOwner(long pSecurityDescriptor, + long pOwner) + throws WindowsException; + + /** + * GetSecurityDescriptorDacl( + * PSECURITY_DESCRIPTOR pSecurityDescriptor, + * LPBOOL lpbDaclPresent, + * PACL *pDacl, + * LPBOOL lpbDaclDefaulted + * ) + */ + static native long GetSecurityDescriptorDacl(long pSecurityDescriptor); + + /** + * SetSecurityDescriptorDacl( + * PSECURITY_DESCRIPTOR pSecurityDescriptor, + * BOOL bDaclPresent, + * PACL pDacl, + * BOOL bDaclDefaulted + * ) + */ + static native void SetSecurityDescriptorDacl(long pSecurityDescriptor, long pAcl) + throws WindowsException; + + + /** + * GetAclInformation( + * PACL pAcl, + * LPVOID pAclInformation, + * DWORD nAclInformationLength, + * ACL_INFORMATION_CLASS dwAclInformationClass + * ) + */ + static AclInformation GetAclInformation(long aclAddress) { + AclInformation info = new AclInformation(); + GetAclInformation0(aclAddress, info); + return info; + } + static class AclInformation { + private int aceCount; + private AclInformation() { } + + public int aceCount() { return aceCount; } + } + private static native void GetAclInformation0(long aclAddress, + AclInformation obj); + + /** + * GetAce( + * PACL pAcl, + * DWORD dwAceIndex, + * LPVOID *pAce + * ) + */ + static native long GetAce(long aclAddress, int aceIndex); + + /** + * AddAccessAllowedAceEx( + * PACL pAcl, + * DWORD dwAceRevision, + * DWORD AceFlags, + * DWORD AccessMask, + * PSID pSid + * ) + */ + static native void AddAccessAllowedAceEx(long aclAddress, int flags, + int mask, long sidAddress) throws WindowsException; + + /** + * AddAccessDeniedAceEx( + * PACL pAcl, + * DWORD dwAceRevision, + * DWORD AceFlags, + * DWORD AccessMask, + * PSID pSid + * ) + */ + static native void AddAccessDeniedAceEx(long aclAddress, int flags, + int mask, long sidAddress) throws WindowsException; + + /** + * LookupAccountSid( + * LPCTSTR lpSystemName, + * PSID Sid, + * LPTSTR Name, + * LPDWORD cbName, + * LPTSTR ReferencedDomainName, + * LPDWORD cbReferencedDomainName, + * PSID_NAME_USE peUse + * ) + */ + static Account LookupAccountSid(long sidAddress) throws WindowsException { + Account acc = new Account(); + LookupAccountSid0(sidAddress, acc); + return acc; + } + static class Account { + private String domain; + private String name; + private int use; + private Account() { } + + public String domain() { return domain; } + public String name() { return name; } + public int use() { return use; } + } + private static native void LookupAccountSid0(long sidAddress, Account obj) + throws WindowsException; + + /** + * LookupAccountName( + * LPCTSTR lpSystemName, + * LPCTSTR lpAccountName, + * PSID Sid, + * LPDWORD cbSid, + * LPTSTR ReferencedDomainName, + * LPDWORD cbReferencedDomainName, + * PSID_NAME_USE peUse + * ) + * + * @return cbSid + */ + static int LookupAccountName(String accountName, + long pSid, + int cbSid) throws WindowsException + { + NativeBuffer buffer = asNativeBuffer(accountName); + try { + return LookupAccountName0(buffer.address(), pSid, cbSid); + } finally { + buffer.release(); + } + } + private static native int LookupAccountName0(long lpAccountName, long pSid, + int cbSid) throws WindowsException; + + /** + * DWORD GetLengthSid( + * PSID pSid + * ) + */ + static native int GetLengthSid(long sidAddress); + + /** + * ConvertSidToStringSid( + * PSID Sid, + * LPTSTR* StringSid + * ) + * + * @return StringSid + */ + static native String ConvertSidToStringSid(long sidAddress) + throws WindowsException; + + /** + * ConvertStringSidToSid( + * LPCTSTR StringSid, + * PSID* pSid + * ) + * + * @return pSid + */ + static long ConvertStringSidToSid(String sidString) + throws WindowsException + { + NativeBuffer buffer = asNativeBuffer(sidString); + try { + return ConvertStringSidToSid0(buffer.address()); + } finally { + buffer.release(); + } + } + private static native long ConvertStringSidToSid0(long lpStringSid) + throws WindowsException; + + /** + * HANDLE GetCurrentProcess(VOID) + */ + static native long GetCurrentProcess(); + + /** + * HANDLE GetCurrentThread(VOID) + */ + static native long GetCurrentThread(); + + /** + * OpenProcessToken( + * HANDLE ProcessHandle, + * DWORD DesiredAccess, + * PHANDLE TokenHandle + * ) + */ + static native long OpenProcessToken(long hProcess, int desiredAccess) + throws WindowsException; + + /** + * OpenThreadToken( + * HANDLE ThreadHandle, + * DWORD DesiredAccess, + * BOOL OpenAsSelf, + * PHANDLE TokenHandle + * ) + */ + static native long OpenThreadToken(long hThread, int desiredAccess, + boolean openAsSelf) throws WindowsException; + + /** + */ + static native long DuplicateTokenEx(long hThread, int desiredAccess) + throws WindowsException; + + /** + * SetThreadToken( + * PHANDLE Thread, + * HANDLE Token + * ) + */ + static native void SetThreadToken(long thread, long hToken) + throws WindowsException; + + /** + * GetTokenInformation( + * HANDLE TokenHandle, + * TOKEN_INFORMATION_CLASS TokenInformationClass, + * LPVOID TokenInformation, + * DWORD TokenInformationLength, + * PDWORD ReturnLength + * ) + */ + static native int GetTokenInformation(long token, int tokenInfoClass, + long pTokenInfo, int tokenInfoLength) throws WindowsException; + + /** + * AdjustTokenPrivileges( + * HANDLE TokenHandle, + * BOOL DisableAllPrivileges + * PTOKEN_PRIVILEGES NewState + * DWORD BufferLength + * PTOKEN_PRIVILEGES + * PDWORD ReturnLength + * ) + */ + static native void AdjustTokenPrivileges(long token, long luid, int attributes) + throws WindowsException; + + /** + */ + static long LookupPrivilegeValue(String name) throws WindowsException { + NativeBuffer buffer = asNativeBuffer(name); + try { + return LookupPrivilegeValue0(buffer.address()); + } finally { + buffer.release(); + } + } + private static native long LookupPrivilegeValue0(long lpName) + throws WindowsException; + + /** + * BuildTrusteeWithSid( + * PTRUSTEE pTrustee, + * PSID pSid + * ) + * + * @return pTrustee + */ + static native long BuildTrusteeWithSid(long pSid); + + /** + * GetEffectiveRightsFromAcl( + * PACL pacl, + * PTRUSTEE pTrustee, + * PACCESS_MASK pAccessRights + * ) + * + * @return AccessRights + */ + static native int GetEffectiveRightsFromAcl(long pAcl, long pTrustee) + throws WindowsException; + + /** + * CreateSymbolicLink( + * LPCWSTR lpSymlinkFileName, + * LPCWSTR lpTargetFileName, + * DWORD dwFlags + * ) + */ + static void CreateSymbolicLink(String link, String target, int flags) + throws WindowsException + { + NativeBuffer linkBuffer = asNativeBuffer(link); + NativeBuffer targetBuffer = asNativeBuffer(target); + try { + CreateSymbolicLink0(linkBuffer.address(), targetBuffer.address(), + flags); + } finally { + targetBuffer.release(); + linkBuffer.release(); + } + } + private static native void CreateSymbolicLink0(long linkAddress, + long targetAddress, int flags) throws WindowsException; + + /** + * CreateHardLink( + * LPCTSTR lpFileName, + * LPCTSTR lpExistingFileName, + * LPSECURITY_ATTRIBUTES lpSecurityAttributes + * ) + */ + static void CreateHardLink(String newFile, String existingFile) + throws WindowsException + { + NativeBuffer newFileBuffer = asNativeBuffer(newFile); + NativeBuffer existingFileBuffer = asNativeBuffer(existingFile); + try { + CreateHardLink0(newFileBuffer.address(), existingFileBuffer.address()); + } finally { + existingFileBuffer.release(); + newFileBuffer.release(); + } + } + private static native void CreateHardLink0(long newFileBuffer, + long existingFiletBuffer) throws WindowsException; + + /** + * GetFullPathName( + * LPCTSTR lpFileName, + * DWORD nBufferLength, + * LPTSTR lpBuffer, + * LPTSTR *lpFilePart + * ) + */ + static String GetFullPathName(String path) throws WindowsException { + NativeBuffer buffer = asNativeBuffer(path); + try { + return GetFullPathName0(buffer.address()); + } finally { + buffer.release(); + } + } + private static native String GetFullPathName0(long pathAddress) + throws WindowsException; + + /** + * GetFinalPathNameByHandle( + * HANDLE hFile, + * LPTSTR lpszFilePath, + * DWORD cchFilePath, + * DWORD dwFlags + * ) + */ + static native String GetFinalPathNameByHandle(long handle) + throws WindowsException; + + /** + * FormatMessage( + * DWORD dwFlags, + * LPCVOID lpSource, + * DWORD dwMessageId, + * DWORD dwLanguageId, + * LPTSTR lpBuffer, + * DWORD nSize, + * va_list *Arguments + * ) + */ + static native String FormatMessage(int errorCode); + + /** + * LocalFree( + * HLOCAL hMem + * ) + */ + static native void LocalFree(long address); + + /** + * HANDLE CreateIoCompletionPort ( + * HANDLE FileHandle, + * HANDLE ExistingCompletionPort, + * DWORD CompletionKey, + * DWORD NumberOfConcurrentThreads + * ) + */ + static native long CreateIoCompletionPort(long fileHandle, long existingPort, + int completionKey) throws WindowsException; + + + /** + * GetQueuedCompletionStatus( + * HANDLE CompletionPort, + * LPDWORD lpNumberOfBytesTransferred, + * LPDWORD lpCompletionKey, + * LPOVERLAPPED *lpOverlapped, + * DWORD dwMilliseconds + */ + static CompletionStatus GetQueuedCompletionStatus(long completionPort) + throws WindowsException + { + CompletionStatus status = new CompletionStatus(); + GetQueuedCompletionStatus0(completionPort, status); + return status; + } + static class CompletionStatus { + private int error; + private int bytesTransferred; + private int completionKey; + private CompletionStatus() { } + + int error() { return error; } + int bytesTransferred() { return bytesTransferred; } + int completionKey() { return completionKey; } + } + private static native void GetQueuedCompletionStatus0(long completionPort, + CompletionStatus status) throws WindowsException; + + /** + * PostQueuedCompletionStatus( + * HANDLE CompletionPort, + * DWORD dwNumberOfBytesTransferred, + * DWORD dwCompletionKey, + * LPOVERLAPPED lpOverlapped + * ) + */ + static native void PostQueuedCompletionStatus(long completionPort, + int completionKey) throws WindowsException; + + /** + * ReadDirectoryChangesW( + * HANDLE hDirectory, + * LPVOID lpBuffer, + * DWORD nBufferLength, + * BOOL bWatchSubtree, + * DWORD dwNotifyFilter, + * LPDWORD lpBytesReturned, + * LPOVERLAPPED lpOverlapped, + * LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine + * ) + */ + static native void ReadDirectoryChangesW(long hDirectory, + long bufferAddress, + int bufferLength, + boolean watchSubTree, + int filter, + long bytesReturnedAddress, + long pOverlapped) + throws WindowsException; + + /** + * BackupRead( + * HANDLE hFile, + * LPBYTE lpBuffer, + * DWORD nNumberOfBytesToRead, + * LPDWORD lpNumberOfBytesRead, + * BOOL bAbort, + * BOOL bProcessSecurity, + * LPVOID* lpContext + * ) + */ + static BackupResult BackupRead(long hFile, + long bufferAddress, + int bufferSize, + boolean abort, + long context) + throws WindowsException + { + BackupResult result = new BackupResult(); + BackupRead0(hFile, bufferAddress, bufferSize, abort, context, result); + return result; + } + static class BackupResult { + private int bytesTransferred; + private long context; + private BackupResult() { } + + int bytesTransferred() { return bytesTransferred; } + long context() { return context; } + } + private static native void BackupRead0(long hFile, long bufferAddress, + int bufferSize, boolean abort, long context, BackupResult result) + throws WindowsException; + + /** + * BackupSeek( + * HANDLE hFile, + * DWORD dwLowBytesToSeek, + * DWORD dwHighBytesToSeek, + * LPDWORD lpdwLowByteSeeked, + * LPDWORD lpdwHighByteSeeked, + * LPVOID* lpContext + * ) + */ + static native void BackupSeek(long hFile, long bytesToSeek, long context) + throws WindowsException; + + + // -- support for copying String with a NativeBuffer -- + + private static final Unsafe unsafe = Unsafe.getUnsafe(); + + static NativeBuffer asNativeBuffer(String s) { + int stringLengthInBytes = s.length() << 1; + int sizeInBytes = stringLengthInBytes + 2; // char terminator + + // get a native buffer of sufficient size + NativeBuffer buffer = NativeBuffers.getNativeBufferFromCache(sizeInBytes); + if (buffer == null) { + buffer = NativeBuffers.allocNativeBuffer(sizeInBytes); + } else { + // buffer already contains the string contents + if (buffer.owner() == s) + return buffer; + } + + // copy into buffer and zero terminate + char[] chars = s.toCharArray(); + unsafe.copyMemory(chars, Unsafe.ARRAY_CHAR_BASE_OFFSET, null, + buffer.address(), (long)stringLengthInBytes); + unsafe.putChar(buffer.address() + stringLengthInBytes, (char)0); + buffer.setOwner(s); + return buffer; + } + + // -- native library initialization -- + + private static native void initIDs(); + + static { + AccessController.doPrivileged(new PrivilegedAction<Void>() { + public Void run() { + // nio.dll has dependency on net.dll + System.loadLibrary("net"); + System.loadLibrary("nio"); + return null; + }}); + initIDs(); + } + +} diff --git a/src/windows/classes/sun/nio/fs/WindowsPath.java b/src/windows/classes/sun/nio/fs/WindowsPath.java new file mode 100644 index 0000000000000000000000000000000000000000..2fda59d2bfb7e1eb92f10319c584a9749e5628b2 --- /dev/null +++ b/src/windows/classes/sun/nio/fs/WindowsPath.java @@ -0,0 +1,1375 @@ +/* + * Copyright 2008-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 sun.nio.fs; + +import java.nio.file.*; +import java.nio.file.attribute.*; +import java.nio.file.spi.AbstractPath; +import java.nio.channels.*; +import java.io.*; +import java.net.URI; +import java.security.AccessController; +import java.util.*; +import java.lang.ref.WeakReference; + +import com.sun.nio.file.ExtendedWatchEventModifier; + +import sun.security.util.SecurityConstants; +import sun.misc.Unsafe; + +import static sun.nio.fs.WindowsNativeDispatcher.*; +import static sun.nio.fs.WindowsConstants.*; + +/** + * Windows implementation of Path + */ + +class WindowsPath extends AbstractPath { + private static final Unsafe unsafe = Unsafe.getUnsafe(); + + // The maximum path that does not require long path prefix. On Windows + // the maximum path is 260 minus 1 (NUL) but for directories it is 260 + // minus 12 minus 1 (to allow for the creation of a 8.3 file in the + // directory). + private static final int MAX_PATH = 247; + + // Maximum extended-length path + private static final int MAX_LONG_PATH = 32000; + + // FIXME - eliminate this reference to reduce space + private final WindowsFileSystem fs; + + // path type + private final WindowsPathType type; + // root component (may be empty) + private final String root; + // normalized path + private final String path; + + // the path to use in Win32 calls. This differs from path for relative + // paths and has a long path prefix for all paths longer than MAX_PATH. + private volatile WeakReference<String> pathForWin32Calls; + + // offsets into name components (computed lazily) + private volatile Integer[] offsets; + + // computed hash code (computed lazily, no need to be volatile) + private int hash; + + + /** + * Initializes a new instance of this class. + */ + private WindowsPath(WindowsFileSystem fs, + WindowsPathType type, + String root, + String path) + { + this.fs = fs; + this.type = type; + this.root = root; + this.path = path; + } + + /** + * Creates a Path by parsing the given path. + */ + static WindowsPath parse(WindowsFileSystem fs, String path) { + WindowsPathParser.Result result = WindowsPathParser.parse(path); + return new WindowsPath(fs, result.type(), result.root(), result.path()); + } + + /** + * Creates a Path from a given path that is known to be normalized. + */ + static WindowsPath createFromNormalizedPath(WindowsFileSystem fs, + String path, + BasicFileAttributes attrs) + { + try { + WindowsPathParser.Result result = + WindowsPathParser.parseNormalizedPath(path); + if (attrs == null) { + return new WindowsPath(fs, + result.type(), + result.root(), + result.path()); + } else { + return new WindowsPathWithAttributes(fs, + result.type(), + result.root(), + result.path(), + attrs); + } + } catch (InvalidPathException x) { + throw new AssertionError(x.getMessage()); + } + } + + /** + * Creates a WindowsPath from a given path that is known to be normalized. + */ + static WindowsPath createFromNormalizedPath(WindowsFileSystem fs, + String path) + { + return createFromNormalizedPath(fs, path, null); + } + + /** + * Special implementation with attached/cached attributes (used to quicken + * file tree traveral) + */ + private static class WindowsPathWithAttributes + extends WindowsPath implements BasicFileAttributesHolder + { + final WeakReference<BasicFileAttributes> ref; + + WindowsPathWithAttributes(WindowsFileSystem fs, + WindowsPathType type, + String root, + String path, + BasicFileAttributes attrs) + { + super(fs, type, root, path); + ref = new WeakReference<BasicFileAttributes>(attrs); + } + + @Override + public BasicFileAttributes get() { + return ref.get(); + } + + @Override + public void invalidate() { + ref.clear(); + } + } + + // use this message when throwing exceptions + String getPathForExceptionMessage() { + return path; + } + + // use this path for permission checks + String getPathForPermissionCheck() { + return path; + } + + // use this path for Win32 calls + // This method will prefix long paths with \\?\ or \\?\UNC as required. + String getPathForWin32Calls() throws WindowsException { + // short absolute paths can be used directly + if (isAbsolute() && path.length() <= MAX_PATH) + return path; + + // return cached values if available + WeakReference<String> ref = pathForWin32Calls; + String resolved = (ref != null) ? ref.get() : null; + if (resolved != null) { + // Win32 path already available + return resolved; + } + + // resolve against default directory + resolved = getAbsolutePath(); + + // Long paths need to have "." and ".." removed and be prefixed with + // "\\?\". Note that it is okay to remove ".." even when it follows + // a link - for example, it is okay for foo/link/../bar to be changed + // to foo/bar. The reason is that Win32 APIs to access foo/link/../bar + // will access foo/bar anyway (which differs to Unix systems) + if (resolved.length() > MAX_PATH) { + if (resolved.length() > MAX_LONG_PATH) { + throw new WindowsException("Cannot access file with path exceeding " + + MAX_LONG_PATH + " characters"); + } + resolved = addPrefixIfNeeded(GetFullPathName(resolved)); + } + + // cache the resolved path (except drive relative paths as the working + // directory on removal media devices can change during the lifetime + // of the VM) + if (type != WindowsPathType.DRIVE_RELATIVE) { + synchronized (path) { + pathForWin32Calls = new WeakReference<String>(resolved); + } + } + return resolved; + } + + // return this path resolved against the file system's default directory + private String getAbsolutePath() throws WindowsException { + if (isAbsolute()) + return path; + + // Relative path ("foo" for example) + if (type == WindowsPathType.RELATIVE) { + String defaultDirectory = getFileSystem().defaultDirectory(); + if (defaultDirectory.endsWith("\\")) { + return defaultDirectory + path; + } else { + StringBuilder sb = + new StringBuilder(defaultDirectory.length() + path.length() + 1); + return sb.append(defaultDirectory).append('\\').append(path).toString(); + } + } + + // Directory relative path ("\foo" for example) + if (type == WindowsPathType.DIRECTORY_RELATIVE) { + String defaultRoot = getFileSystem().defaultRoot(); + return defaultRoot + path.substring(1); + } + + // Drive relative path ("C:foo" for example). + if (isSameDrive(root, getFileSystem().defaultRoot())) { + // relative to default directory + String remaining = path.substring(root.length()); + String defaultDirectory = getFileSystem().defaultDirectory(); + String result; + if (defaultDirectory.endsWith("\\")) { + result = defaultDirectory + remaining; + } else { + result = defaultDirectory + "\\" + remaining; + } + return result; + } else { + // relative to some other drive + String wd; + try { + int dt = GetDriveType(root + "\\"); + if (dt == DRIVE_UNKNOWN || dt == DRIVE_NO_ROOT_DIR) + throw new WindowsException(""); + wd = GetFullPathName(root + "."); + } catch (WindowsException x) { + throw new WindowsException("Unable to get working directory of drive '" + + Character.toUpperCase(root.charAt(0)) + "'"); + } + String result = wd; + if (wd.endsWith("\\")) { + result += path.substring(root.length()); + } else { + if (path.length() > root.length()) + result += "\\" + path.substring(root.length()); + } + return result; + } + } + + // returns true if same drive letter + private static boolean isSameDrive(String root1, String root2) { + return Character.toUpperCase(root1.charAt(0)) == + Character.toUpperCase(root2.charAt(0)); + } + + // Add long path prefix to path if required + private static String addPrefixIfNeeded(String path) { + if (path.length() > 248) { + if (path.startsWith("\\\\")) { + path = "\\\\?\\UNC" + path.substring(1, path.length()); + } else { + path = "\\\\?\\" + path; + } + } + return path; + } + + @Override + public WindowsFileSystem getFileSystem() { + return fs; + } + + // -- Path operations -- + + @Override + public Path getName() { + // represents root component only + if (root.length() == path.length()) + return null; + int off = path.lastIndexOf('\\'); + if (off < root.length()) + off = root.length(); + else + off++; + return new WindowsPath(getFileSystem(), WindowsPathType.RELATIVE, "", path.substring(off)); + } + + @Override + public WindowsPath getParent() { + // represents root component only + if (root.length() == path.length()) + return null; + int off = path.lastIndexOf('\\'); + if (off < root.length()) + return getRoot(); + else + return new WindowsPath(getFileSystem(), + type, + root, + path.substring(0, off)); + } + + @Override + public WindowsPath getRoot() { + if (root.length() == 0) + return null; + return new WindowsPath(getFileSystem(), type, root, root); + } + + // package-private + boolean isUnc() { + return type == WindowsPathType.UNC; + } + + boolean needsSlashWhenResolving() { + if (path.endsWith("\\")) + return false; + return path.length() > root.length(); + } + + @Override + public boolean isAbsolute() { + return type == WindowsPathType.ABSOLUTE || type == WindowsPathType.UNC; + } + + private WindowsPath checkPath(FileRef path) { + if (path == null) + throw new NullPointerException(); + if (!(path instanceof WindowsPath)) { + throw new ProviderMismatchException(); + } + return (WindowsPath)path; + } + + @Override + public WindowsPath relativize(Path obj) { + WindowsPath other = checkPath(obj); + if (this.equals(other)) + return null; + + // can only relativize paths of the same type + if (this.type != other.type) + throw new IllegalArgumentException("'other' is different type of Path"); + + // can only relativize paths if root component matches + if (!this.root.equalsIgnoreCase(other.root)) + throw new IllegalArgumentException("'other' has different root"); + + int bn = this.getNameCount(); + int cn = other.getNameCount(); + + // skip matching names + int n = (bn > cn) ? cn : bn; + int i = 0; + while (i < n) { + if (!this.getName(i).equals(other.getName(i))) + break; + i++; + } + + // append ..\ for remaining names in the base + StringBuilder result = new StringBuilder(); + for (int j=i; j<bn; j++) { + result.append("..\\"); + } + + // append remaining names in child + for (int j=i; j<cn; j++) { + result.append(other.getName(j).toString()); + result.append("\\"); + } + + // drop trailing slash in result + result.setLength(result.length()-1); + return createFromNormalizedPath(getFileSystem(), result.toString()); + } + + @Override + public Path normalize() { + final int count = getNameCount(); + if (count == 0) + return this; + + boolean[] ignore = new boolean[count]; // true => ignore name + int remaining = count; // number of names remaining + + // multiple passes to eliminate all occurences of "." and "name/.." + int prevRemaining; + do { + prevRemaining = remaining; + int prevName = -1; + for (int i=0; i<count; i++) { + if (ignore[i]) + continue; + + String name = elementAsString(i); + + // not "." or ".." + if (name.length() > 2) { + prevName = i; + continue; + } + + // "." or something else + if (name.length() == 1) { + // ignore "." + if (name.charAt(0) == '.') { + ignore[i] = true; + remaining--; + } else { + prevName = i; + } + continue; + } + + // not ".." + if (name.charAt(0) != '.' || name.charAt(1) != '.') { + prevName = i; + continue; + } + + // ".." found + if (prevName >= 0) { + // name/<ignored>/.. found so mark name and ".." to be + // ignored + ignore[prevName] = true; + ignore[i] = true; + remaining = remaining - 2; + prevName = -1; + } else { + // Cases: + // C:\<ignored>\.. + // \\server\\share\<ignored>\.. + // \<ignored>.. + if (isAbsolute() || type == WindowsPathType.DIRECTORY_RELATIVE) { + boolean hasPrevious = false; + for (int j=0; j<i; j++) { + if (!ignore[j]) { + hasPrevious = true; + break; + } + } + if (!hasPrevious) { + // all proceeding names are ignored + ignore[i] = true; + remaining--; + } + } + } + } + } while (prevRemaining > remaining); + + // no redundant names + if (remaining == count) + return this; + + // corner case - all names removed + if (remaining == 0) { + return getRoot(); + } + + // re-constitute the path from the remaining names. + StringBuilder result = new StringBuilder(); + if (root != null) + result.append(root); + for (int i=0; i<count; i++) { + if (!ignore[i]) { + result.append(getName(i).toString()); + result.append("\\"); + } + } + + // drop trailing slash in result + result.setLength(result.length()-1); + return createFromNormalizedPath(getFileSystem(), result.toString()); + } + + @Override + public WindowsPath resolve(Path obj) { + if (obj == null) + return this; + WindowsPath other = checkPath(obj); + if (other.isAbsolute()) + return other; + + switch (other.type) { + case RELATIVE: { + String result; + if (path.endsWith("\\") || (root.length() == path.length())) { + result = path + other.path; + } else { + result = path + "\\" + other.path; + } + return new WindowsPath(getFileSystem(), type, root, result); + } + + case DIRECTORY_RELATIVE: { + String result; + if (root.endsWith("\\")) { + result = root + other.path.substring(1); + } else { + result = root + other.path; + } + return createFromNormalizedPath(getFileSystem(), result); + } + + case DRIVE_RELATIVE: { + if (!root.endsWith("\\")) + return other; + // if different roots then return other + String thisRoot = root.substring(0, root.length()-1); + if (!thisRoot.equalsIgnoreCase(other.root)) + return other; + // same roots + String remaining = other.path.substring(other.root.length()); + String result; + if (path.endsWith("\\")) { + result = path + remaining; + } else { + result = path + "\\" + remaining; + } + return createFromNormalizedPath(getFileSystem(), result); + } + + default: + throw new AssertionError(); + } + } + + @Override + public WindowsPath resolve(String other) { + return resolve(getFileSystem().getPath(other)); + } + + // generate offset array + private void initOffsets() { + if (offsets == null) { + ArrayList<Integer> list = new ArrayList<Integer>(); + int start = root.length(); + int off = root.length(); + while (off < path.length()) { + if (path.charAt(off) != '\\') { + off++; + } else { + list.add(start); + start = ++off; + } + } + if (start != off) + list.add(start); + synchronized (this) { + if (offsets == null) + offsets = list.toArray(new Integer[list.size()]); + } + } + } + + @Override + public int getNameCount() { + initOffsets(); + return offsets.length; + } + + private String elementAsString(int i) { + initOffsets(); + if (i == (offsets.length-1)) + return path.substring(offsets[i]); + return path.substring(offsets[i], offsets[i+1]-1); + } + + @Override + public WindowsPath getName(int index) { + initOffsets(); + if (index < 0 || index >= offsets.length) + throw new IllegalArgumentException(); + return new WindowsPath(getFileSystem(), WindowsPathType.RELATIVE, "", elementAsString(index)); + } + + @Override + public WindowsPath subpath(int beginIndex, int endIndex) { + initOffsets(); + if (beginIndex < 0) + throw new IllegalArgumentException(); + if (beginIndex >= offsets.length) + throw new IllegalArgumentException(); + if (endIndex > offsets.length) + throw new IllegalArgumentException(); + if (beginIndex >= endIndex) + throw new IllegalArgumentException(); + + StringBuilder sb = new StringBuilder(); + Integer[] nelems = new Integer[endIndex - beginIndex]; + for (int i = beginIndex; i < endIndex; i++) { + nelems[i-beginIndex] = sb.length(); + sb.append(elementAsString(i)); + if (i != (endIndex-1)) + sb.append("\\"); + } + return new WindowsPath(getFileSystem(), WindowsPathType.RELATIVE, "", sb.toString()); + } + + @Override + public boolean startsWith(Path obj) { + WindowsPath other = checkPath(obj); + + // if this path has a root component the given path's root must match + if (!this.root.equalsIgnoreCase(other.root)) + return false; + + // roots match so compare elements + int thisCount = getNameCount(); + int otherCount = other.getNameCount(); + if (otherCount <= thisCount) { + while (--otherCount >= 0) { + String thisElement = this.elementAsString(otherCount); + String otherElement = other.elementAsString(otherCount); + // FIXME: should compare in uppercase + if (!thisElement.equalsIgnoreCase(otherElement)) + return false; + } + return true; + } + return false; + } + + @Override + public boolean endsWith(Path obj) { + WindowsPath other = checkPath(obj); + + // other path is longer + if (other.path.length() > path.length()) { + return false; + } + + int thisCount = this.getNameCount(); + int otherCount = other.getNameCount(); + + // given path has more elements that this path + if (otherCount > thisCount) { + return false; + } + + // compare roots + if (other.root.length() > 0) { + if (otherCount < thisCount) + return false; + // FIXME: should compare in uppercase + if (!this.root.equalsIgnoreCase(other.root)) + return false; + } + + // match last 'otherCount' elements + int off = thisCount - otherCount; + while (--otherCount >= 0) { + String thisElement = this.elementAsString(off + otherCount); + String otherElement = other.elementAsString(otherCount); + // FIXME: should compare in uppercase + if (!thisElement.equalsIgnoreCase(otherElement)) + return false; + } + return true; + } + + @Override + public int compareTo(Path obj) { + if (obj == null) + throw new NullPointerException(); + String s1 = path; + String s2 = ((WindowsPath)obj).path; + int n1 = s1.length(); + int n2 = s2.length(); + int min = Math.min(n1, n2); + for (int i = 0; i < min; i++) { + char c1 = s1.charAt(i); + char c2 = s2.charAt(i); + if (c1 != c2) { + c1 = Character.toUpperCase(c1); + c2 = Character.toUpperCase(c2); + if (c1 != c2) { + return c1 - c2; + } + } + } + return n1 - n2; + } + + @Override + public boolean equals(Object obj) { + if ((obj != null) && (obj instanceof WindowsPath)) { + return compareTo((Path)obj) == 0; + } + return false; + } + + @Override + public int hashCode() { + // OK if two or more threads compute hash + int h = hash; + if (h == 0) { + for (int i = 0; i< path.length(); i++) { + h = 31*h + Character.toUpperCase(path.charAt(i)); + } + hash = h; + } + return h; + } + + @Override + public String toString() { + return path; + } + + @Override + public Iterator<Path> iterator() { + return new Iterator<Path>() { + private int i = 0; + @Override + public boolean hasNext() { + return (i < getNameCount()); + } + @Override + public Path next() { + if (i < getNameCount()) { + Path result = getName(i); + i++; + return result; + } else { + throw new NoSuchElementException(); + } + } + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + // -- file operations -- + + // package-private + long openForReadAttributeAccess(boolean followLinks) + throws WindowsException + { + int flags = FILE_FLAG_BACKUP_SEMANTICS; + if (!followLinks && getFileSystem().supportsLinks()) + flags |= FILE_FLAG_OPEN_REPARSE_POINT; + return CreateFile(getPathForWin32Calls(), + FILE_READ_ATTRIBUTES, + (FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE), + 0L, + OPEN_EXISTING, + flags); + } + + void checkRead() { + SecurityManager sm = System.getSecurityManager(); + if (sm != null) { + sm.checkRead(getPathForPermissionCheck()); + } + } + + void checkWrite() { + SecurityManager sm = System.getSecurityManager(); + if (sm != null) { + sm.checkWrite(getPathForPermissionCheck()); + } + } + + void checkDelete() { + SecurityManager sm = System.getSecurityManager(); + if (sm != null) { + sm.checkDelete(getPathForPermissionCheck()); + } + } + + @Override + public FileStore getFileStore() + throws IOException + { + SecurityManager sm = System.getSecurityManager(); + if (sm != null) { + sm.checkPermission(new RuntimePermission("getFileStoreAttributes")); + checkRead(); + } + return WindowsFileStore.create(this); + } + + /** + * Returns buffer with SID_AND_ATTRIBUTES structure representing the user + * associated with the current thread access token. + * FIXME - this should be cached. + */ + private NativeBuffer getUserInfo() throws IOException { + try { + long hToken = WindowsSecurity.processTokenWithQueryAccess; + int size = GetTokenInformation(hToken, TokenUser, 0L, 0); + assert size > 0; + + NativeBuffer buffer = NativeBuffers.getNativeBuffer(size); + try { + int newsize = GetTokenInformation(hToken, TokenUser, + buffer.address(), size); + if (newsize != size) + throw new AssertionError(); + return buffer; + } catch (WindowsException x) { + buffer.release(); + throw x; + } + } catch (WindowsException x) { + throw new IOException(x.getMessage()); + } + } + + /** + * Reads the file ACL and return the effective access as ACCESS_MASK + */ + private int getEffectiveAccess() throws IOException { + // read security descriptor continaing ACL (symlinks are followed) + String target = WindowsLinkSupport.getFinalPath(this, true); + NativeBuffer aclBuffer = WindowsAclFileAttributeView + .getFileSecurity(target, DACL_SECURITY_INFORMATION); + + // retrieves DACL from security descriptor + long pAcl = GetSecurityDescriptorDacl(aclBuffer.address()); + + // Use GetEffectiveRightsFromAcl to get effective access to file + try { + NativeBuffer userBuffer = getUserInfo(); + try { + try { + // SID_AND_ATTRIBUTES->pSid + long pSid = unsafe.getAddress(userBuffer.address()); + long pTrustee = BuildTrusteeWithSid(pSid); + try { + return GetEffectiveRightsFromAcl(pAcl, pTrustee); + } finally { + LocalFree(pTrustee); + } + } catch (WindowsException x) { + throw new IOException("Unable to get effective rights from ACL: " + + x.getMessage()); + } + } finally { + userBuffer.release(); + } + } finally { + aclBuffer.release(); + } + } + + @Override + public void checkAccess(AccessMode... modes) throws IOException { + // if no access modes then simply file attributes + if (modes.length == 0) { + checkRead(); + try { + WindowsFileAttributes.get(this, true); + } catch (WindowsException exc) { + exc.rethrowAsIOException(this); + } + return; + } + + boolean r = false; + boolean w = false; + boolean x = false; + for (AccessMode mode: modes) { + switch (mode) { + case READ : r = true; break; + case WRITE : w = true; break; + case EXECUTE : x = true; break; + default: throw new AssertionError("Should not get here"); + } + } + + int mask = 0; + if (r) { + checkRead(); + mask |= FILE_READ_DATA; + } + if (w) { + checkWrite(); + mask |= FILE_WRITE_DATA; + } + if (x) { + SecurityManager sm = System.getSecurityManager(); + if (sm != null) + sm.checkExec(getPathForPermissionCheck()); + mask |= FILE_EXECUTE; + } + + if ((getEffectiveAccess() & mask) == 0) + throw new AccessDeniedException( + this.getPathForExceptionMessage(), null, + "Effective permissions does not allow requested access"); + + // for write access we neeed to check if the DOS readonly attribute + // and if the volume is read-only + if (w) { + try { + WindowsFileAttributes attrs = WindowsFileAttributes.get(this, true); + if (!attrs.isDirectory() && attrs.isReadOnly()) + throw new AccessDeniedException( + this.getPathForExceptionMessage(), null, + "DOS readonly attribute is set"); + } catch (WindowsException exc) { + exc.rethrowAsIOException(this); + } + + if (WindowsFileStore.create(this).isReadOnly()) { + throw new AccessDeniedException( + this.getPathForExceptionMessage(), null, "Read-only file system"); + } + return; + } + } + + @Override + public void delete(boolean failIfNotExists) throws IOException { + checkDelete(); + + WindowsFileAttributes attrs = null; + try { + // need to know if file is a directory or junction + attrs = WindowsFileAttributes.get(this, false); + if (attrs.isDirectory() || attrs.isDirectoryLink()) { + RemoveDirectory(getPathForWin32Calls()); + } else { + DeleteFile(getPathForWin32Calls()); + } + } catch (WindowsException x) { + + // no-op if file does not exist + if (!failIfNotExists && + (x.lastError() == ERROR_FILE_NOT_FOUND || + x.lastError() == ERROR_PATH_NOT_FOUND)) return; + + if (attrs != null && attrs.isDirectory()) { + // ERROR_ALREADY_EXISTS is returned when attempting to delete + // non-empty directory on SAMBA servers. + if (x.lastError() == ERROR_DIR_NOT_EMPTY || + x.lastError() == ERROR_ALREADY_EXISTS) + { + throw new DirectoryNotEmptyException( + getPathForExceptionMessage()); + } + } + x.rethrowAsIOException(this); + } + } + + @Override + public DirectoryStream<Path> newDirectoryStream(DirectoryStream.Filter<? super Path> filter) + throws IOException + { + checkRead(); + if (filter == null) + throw new NullPointerException(); + return new WindowsDirectoryStream(this, filter); + } + + @Override + public void implCopyTo(Path obj, CopyOption... options) throws IOException { + WindowsPath target = (WindowsPath)obj; + WindowsFileCopy.copy(this, target, options); + } + + @Override + public void implMoveTo(Path obj, CopyOption... options) throws IOException { + WindowsPath target = (WindowsPath)obj; + WindowsFileCopy.move(this, target, options); + } + + private boolean followLinks(LinkOption... options) { + boolean followLinks = true; + for (LinkOption option: options) { + if (option == LinkOption.NOFOLLOW_LINKS) { + followLinks = false; + continue; + } + if (option == null) + throw new NullPointerException(); + throw new AssertionError("Should not get here"); + } + return followLinks; + } + + @Override + @SuppressWarnings("unchecked") + public <V extends FileAttributeView> V + getFileAttributeView(Class<V> view, LinkOption... options) + { + if (view == null) + throw new NullPointerException(); + boolean followLinks = followLinks(options); + if (view == BasicFileAttributeView.class) + return (V) WindowsFileAttributeViews.createBasicView(this, followLinks); + if (view == DosFileAttributeView.class) + return (V) WindowsFileAttributeViews.createDosView(this, followLinks); + if (view == AclFileAttributeView.class) + return (V) new WindowsAclFileAttributeView(this, followLinks); + if (view == FileOwnerAttributeView.class) + return (V) new FileOwnerAttributeViewImpl( + new WindowsAclFileAttributeView(this, followLinks)); + if (view == UserDefinedFileAttributeView.class) + return (V) new WindowsUserDefinedFileAttributeView(this, followLinks); + return (V) null; + } + + @Override + public FileAttributeView getFileAttributeView(String name, LinkOption... options) { + boolean followLinks = followLinks(options); + if (name.equals("basic")) + return WindowsFileAttributeViews.createBasicView(this, followLinks); + if (name.equals("dos")) + return WindowsFileAttributeViews.createDosView(this, followLinks); + if (name.equals("acl")) + return new WindowsAclFileAttributeView(this, followLinks); + if (name.equals("owner")) + return new FileOwnerAttributeViewImpl( + new WindowsAclFileAttributeView(this, followLinks)); + if (name.equals("xattr")) + return new WindowsUserDefinedFileAttributeView(this, followLinks); + return null; + } + + @Override + public WindowsPath createDirectory(FileAttribute<?>... attrs) + throws IOException + { + checkWrite(); + WindowsSecurityDescriptor sd = WindowsSecurityDescriptor.fromAttribute(attrs); + try { + CreateDirectory(getPathForWin32Calls(), sd.address()); + } catch (WindowsException x) { + x.rethrowAsIOException(this); + } finally { + sd.release(); + } + return this; + } + + @Override + public InputStream newInputStream()throws IOException { + try { + Set<OpenOption> options = Collections.emptySet(); + FileChannel fc = WindowsChannelFactory + .newFileChannel(getPathForWin32Calls(), + getPathForPermissionCheck(), + options, + 0L); + return Channels.newInputStream(fc); + } catch (WindowsException x) { + x.rethrowAsIOException(this); + return null; // keep compiler happy + } + } + + @Override + public SeekableByteChannel newByteChannel(Set<? extends OpenOption> options, + FileAttribute<?>... attrs) + throws IOException + { + WindowsSecurityDescriptor sd = + WindowsSecurityDescriptor.fromAttribute(attrs); + try { + return WindowsChannelFactory + .newFileChannel(getPathForWin32Calls(), + getPathForPermissionCheck(), + options, + sd.address()); + } catch (WindowsException x) { + x.rethrowAsIOException(this); + return null; // keep compiler happy + } finally { + sd.release(); + } + } + + @Override + public OutputStream newOutputStream(Set<? extends OpenOption> options, + FileAttribute<?>... attrs) + throws IOException + { + // need to copy options to add WRITE + Set<OpenOption> opts = new HashSet<OpenOption>(options); + if (opts.contains(StandardOpenOption.READ)) + throw new IllegalArgumentException("READ not allowed"); + opts.add(StandardOpenOption.WRITE); + + WindowsSecurityDescriptor sd = + WindowsSecurityDescriptor.fromAttribute(attrs); + FileChannel fc; + try { + fc = WindowsChannelFactory + .newFileChannel(getPathForWin32Calls(), + getPathForPermissionCheck(), + opts, + sd.address()); + return Channels.newOutputStream(fc); + } catch (WindowsException x) { + x.rethrowAsIOException(this); + return null; // keep compiler happy + } finally { + sd.release(); + } + } + + @Override + public boolean isSameFile(FileRef obj) throws IOException { + if (this.equals(obj)) + return true; + if (!(obj instanceof WindowsPath)) // includes null check + return false; + WindowsPath other = (WindowsPath)obj; + + // check security manager access to both files + this.checkRead(); + other.checkRead(); + + // open both files and see if they are the same + long h1 = 0L; + try { + h1 = this.openForReadAttributeAccess(true); + } catch (WindowsException x) { + x.rethrowAsIOException(this); + } + try { + WindowsFileAttributes attrs1 = null; + try { + attrs1 = WindowsFileAttributes.readAttributes(h1); + } catch (WindowsException x) { + x.rethrowAsIOException(this); + } + long h2 = 0L; + try { + h2 = other.openForReadAttributeAccess(true); + } catch (WindowsException x) { + x.rethrowAsIOException(other); + } + try { + WindowsFileAttributes attrs2 = null; + try { + attrs2 = WindowsFileAttributes.readAttributes(h2); + } catch (WindowsException x) { + x.rethrowAsIOException(other); + } + return WindowsFileAttributes.isSameFile(attrs1, attrs2); + } finally { + CloseHandle(h2); + } + } finally { + CloseHandle(h1); + } + } + + @Override + public WindowsPath createSymbolicLink(Path obj, FileAttribute<?>... attrs) + throws IOException + { + if (!getFileSystem().supportsLinks()) { + throw new UnsupportedOperationException("Symbolic links not supported " + + "on this operating system"); + } + + WindowsPath target = checkPath(obj); + + // no attributes allowed + if (attrs.length > 0) { + WindowsSecurityDescriptor.fromAttribute(attrs); // may throw NPE or UOE + throw new UnsupportedOperationException("Initial file attributes" + + "not supported when creating symbolic link"); + } + + // permission check + SecurityManager sm = System.getSecurityManager(); + if (sm != null) { + sm.checkPermission(new LinkPermission("symbolic")); + this.checkWrite(); + } + + /** + * Throw I/O exception for the drive-relative case because Windows + * creates a link with the resolved target for this case. + */ + if (target.type == WindowsPathType.DRIVE_RELATIVE) { + throw new IOException("Cannot create symbolic link to drive-relative target"); + } + + /* + * Windows treates symbolic links to directories differently than it + * does to other file types. For that reason we check if the exists and + * is a directory. + */ + int flags = 0; + WindowsPath resolvedTarget = + WindowsPath.createFromNormalizedPath(getFileSystem(), resolve(target).path); + try { + if (WindowsFileAttributes.get(resolvedTarget, true).isDirectory()) + flags |= SYMBOLIC_LINK_FLAG_DIRECTORY; + } catch (WindowsException x) { + // unable to access target so assume target is not a directory + } + + // create the link + try { + CreateSymbolicLink(getPathForWin32Calls(), + addPrefixIfNeeded(target.toString()), + flags); + } catch (WindowsException x) { + if (x.lastError() == ERROR_INVALID_REPARSE_DATA) { + x.rethrowAsIOException(this, target); + } else { + x.rethrowAsIOException(this); + } + } + return this; + } + + @Override + public Path createLink(Path obj) throws IOException { + WindowsPath existing = checkPath(obj); + + // permission check + SecurityManager sm = System.getSecurityManager(); + if (sm != null) { + sm.checkPermission(new LinkPermission("hard")); + this.checkWrite(); + existing.checkWrite(); + } + + // create hard link + try { + CreateHardLink(this.getPathForWin32Calls(), + existing.getPathForWin32Calls()); + } catch (WindowsException x) { + x.rethrowAsIOException(this, existing); + } + + return this; + } + + @Override + public WindowsPath readSymbolicLink() throws IOException { + if (!getFileSystem().supportsLinks()) { + throw new UnsupportedOperationException("symbolic links not supported"); + } + + // permission check + SecurityManager sm = System.getSecurityManager(); + if (sm != null) { + FilePermission perm = new FilePermission(getPathForPermissionCheck(), + SecurityConstants.FILE_READLINK_ACTION); + AccessController.checkPermission(perm); + } + + String target = WindowsLinkSupport.readLink(this); + return createFromNormalizedPath(getFileSystem(), target); + } + + @Override + public URI toUri() { + return WindowsUriSupport.toUri(this); + } + + @Override + public WindowsPath toAbsolutePath() { + if (isAbsolute()) + return this; + + // permission check as per spec + SecurityManager sm = System.getSecurityManager(); + if (sm != null) { + sm.checkPropertyAccess("user.dir"); + } + + try { + return createFromNormalizedPath(getFileSystem(), getAbsolutePath()); + } catch (WindowsException x) { + throw new IOError(new IOException(x.getMessage())); + } + } + + @Override + public WindowsPath toRealPath(boolean resolveLinks) throws IOException { + checkRead(); + String rp = WindowsLinkSupport.getRealPath(this, resolveLinks); + return createFromNormalizedPath(getFileSystem(), rp); + } + + @Override + public boolean isHidden() throws IOException { + checkRead(); + WindowsFileAttributes attrs = null; + try { + attrs = WindowsFileAttributes.get(this, true); + } catch (WindowsException x) { + x.rethrowAsIOException(this); + } + // DOS hidden attribute not meaningful when set on directories + if (attrs.isDirectory()) + return false; + return attrs.isHidden(); + } + + @Override + public WatchKey register(WatchService watcher, + WatchEvent.Kind<?>[] events, + WatchEvent.Modifier... modifiers) + throws IOException + { + if (watcher == null) + throw new NullPointerException(); + if (!(watcher instanceof WindowsWatchService)) + throw new ProviderMismatchException(); + + // When a security manager is set then we need to make a defensive + // copy of the modifiers and check for the Windows specific FILE_TREE + // modifier. When the modifier is present then check that permission + // has been granted recursively. + SecurityManager sm = System.getSecurityManager(); + if (sm != null) { + boolean watchSubtree = false; + final int ml = modifiers.length; + if (ml > 0) { + modifiers = Arrays.copyOf(modifiers, ml); + int i=0; + while (i < ml) { + if (modifiers[i++] == ExtendedWatchEventModifier.FILE_TREE) { + watchSubtree = true; + break; + } + } + } + String s = getPathForPermissionCheck(); + sm.checkRead(s); + if (watchSubtree) + sm.checkRead(s + "\\-"); + } + + return ((WindowsWatchService)watcher).register(this, events, modifiers); + } +} diff --git a/src/windows/classes/sun/nio/fs/WindowsPathParser.java b/src/windows/classes/sun/nio/fs/WindowsPathParser.java new file mode 100644 index 0000000000000000000000000000000000000000..411b91b1c47301f916967d42d7f5171a3d8de692 --- /dev/null +++ b/src/windows/classes/sun/nio/fs/WindowsPathParser.java @@ -0,0 +1,225 @@ +/* + * Copyright 2008-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 sun.nio.fs; + +import java.nio.file.InvalidPathException; + +/** + * A parser of Windows path strings + */ + +class WindowsPathParser { + private WindowsPathParser() { } + + /** + * The result of a parse operation + */ + static class Result { + private final WindowsPathType type; + private final String root; + private final String path; + + Result(WindowsPathType type, String root, String path) { + this.type = type; + this.root = root; + this.path = path; + } + + /** + * The path type + */ + WindowsPathType type() { + return type; + } + + /** + * The root component + */ + String root() { + return root; + } + + /** + * The normalized path (includes root) + */ + String path() { + return path; + } + } + + /** + * Parses the given input as a Windows path + */ + static Result parse(String input) { + if (input == null || input.length() == 0) + throw new InvalidPathException(input, "Empty or null path"); + return parse(input, true); + } + + /** + * Parses the given input as a Windows path where it is known that the + * path is already normalized. + */ + static Result parseNormalizedPath(String input) { + return parse(input, false); + } + + /** + * Parses the given input as a Windows path. + * + * @param requireToNormalize + * Indicates if the path requires to be normalized + */ + private static Result parse(String input, boolean requireToNormalize) { + String root = ""; + WindowsPathType type = null; + + int len = input.length(); + int off = 0; + if (len > 1) { + char c0 = input.charAt(0); + char c1 = input.charAt(1); + char c = 0; + int next = 2; + if (isSlash(c0) && isSlash(c1)) { + // UNC: We keep the first two slash, collapse all the + // following, then take the hostname and share name out, + // meanwhile collapsing all the redundant slashes. + type = WindowsPathType.UNC; + off = nextNonSlash(input, next, len); + next = nextSlash(input, off, len); + if (off == next) + throw new InvalidPathException(input, "UNC path is missing hostname"); + String host = input.substring(off, next); //host + off = nextNonSlash(input, next, len); + next = nextSlash(input, off, len); + if (off == next) + throw new InvalidPathException(input, "UNC path is missing sharename"); + root = "\\\\" + host + "\\" + input.substring(off, next) + "\\"; + off = next; + } else { + if (isLetter(c0) && c1 == ':') { + root = input.substring(0, 2); + if (len > 2 && isSlash(input.charAt(2))) { + off = 3; + root += "\\"; + type = WindowsPathType.ABSOLUTE; + } else { + off = 2; + type = WindowsPathType.DRIVE_RELATIVE; + } + } + } + } + if (off == 0) { + if (isSlash(input.charAt(0))) { + type = WindowsPathType.DIRECTORY_RELATIVE; + root = "\\"; + } else { + type = WindowsPathType.RELATIVE; + } + } + + if (requireToNormalize) { + StringBuilder sb = new StringBuilder(input.length()); + sb.append(root); + return new Result(type, root, normalize(sb, input, off)); + } else { + return new Result(type, root, input); + } + } + + /** + * Remove redundant slashes from the rest of the path, forcing all slashes + * into the preferred slash. + */ + private static String normalize(StringBuilder sb, String path, int off) { + int len = path.length(); + off = nextNonSlash(path, off, len); + int start = off; + char lastC = 0; + while (off < len) { + char c = path.charAt(off); + if (isSlash(c)) { + if (lastC == ' ') + throw new InvalidPathException(path, + "Trailing char <" + lastC + ">", + off - 1); + sb.append(path, start, off); + off = nextNonSlash(path, off, len); + if (off != len) //no slash at the end of normalized path + sb.append('\\'); + start = off; + } else { + if (isInvalidPathChar(c)) + throw new InvalidPathException(path, + "Illegal char <" + c + ">", + off); + lastC = c; + off++; + } + } + if (start != off) { + if (lastC == ' ') + throw new InvalidPathException(path, + "Trailing char <" + lastC + ">", + off - 1); + sb.append(path, start, off); + } + return sb.toString(); + } + + private static final boolean isSlash(char c) { + return (c == '\\') || (c == '/'); + } + + private static final int nextNonSlash(String path, int off, int end) { + while (off < end && isSlash(path.charAt(off))) { off++; } + return off; + } + + private static final int nextSlash(String path, int off, int end) { + char c; + while (off < end && !isSlash(c=path.charAt(off))) { + if (isInvalidPathChar(c)) + throw new InvalidPathException(path, + "Illegal character [" + c + "] in path", + off); + off++; + } + return off; + } + + private static final boolean isLetter(char c) { + return ((c >= 'a') && (c <= 'z')) || ((c >= 'A') && (c <= 'Z')); + } + + // Reserved characters for window path name + private static final String reservedChars = "<>:\"|?*"; + private static final boolean isInvalidPathChar(char ch) { + return ch < '\u0020' || reservedChars.indexOf(ch) != -1; + } +} diff --git a/src/windows/classes/sun/nio/fs/WindowsPathType.java b/src/windows/classes/sun/nio/fs/WindowsPathType.java new file mode 100644 index 0000000000000000000000000000000000000000..ae3651f1f2dc3b5cb435c4bbc23b74d6297c4d06 --- /dev/null +++ b/src/windows/classes/sun/nio/fs/WindowsPathType.java @@ -0,0 +1,38 @@ +/* + * Copyright 2008-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 sun.nio.fs; + +/** + * A type safe enum of Windows path types. + */ + +enum WindowsPathType { + ABSOLUTE, // C:\foo + UNC, // \\server\share\foo + RELATIVE, // foo + DIRECTORY_RELATIVE, // \foo + DRIVE_RELATIVE // C:foo +} diff --git a/src/windows/classes/sun/nio/fs/WindowsSecurity.java b/src/windows/classes/sun/nio/fs/WindowsSecurity.java new file mode 100644 index 0000000000000000000000000000000000000000..9d44257b5ad4ff0f19390910a95313ce72912373 --- /dev/null +++ b/src/windows/classes/sun/nio/fs/WindowsSecurity.java @@ -0,0 +1,123 @@ +/* + * Copyright 2008-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 sun.nio.fs; + +import static sun.nio.fs.WindowsNativeDispatcher.*; +import static sun.nio.fs.WindowsConstants.*; + +/** + * Security related utility methods. + */ + +class WindowsSecurity { + private WindowsSecurity() { } + + // opens process token for given access + private static long openProcessToken(int access) { + try { + return OpenProcessToken(GetCurrentProcess(), access); + } catch (WindowsException x) { + return 0L; + } + } + + /** + * Returns the access token for this process with TOKEN_DUPLICATE access + */ + static final long processTokenWithDuplicateAccess = + openProcessToken(TOKEN_DUPLICATE); + + /** + * Returns the access token for this process with TOKEN_QUERY access + */ + static final long processTokenWithQueryAccess = + openProcessToken(TOKEN_QUERY); + + /** + * Returned by enablePrivilege when code may require a given privilege. + * The drop method should be invoked after the operation completes so as + * to revert the privilege. + */ + static interface Privilege { + void drop(); + } + + /** + * Attempts to enable the given privilege for this method. + */ + static Privilege enablePrivilege(String priv) { + final long pLuid; + try { + pLuid = LookupPrivilegeValue(priv); + } catch (WindowsException x) { + // indicates bug in caller + throw new AssertionError(x); + } + + long hToken = 0L; + boolean impersontating = false; + boolean elevated = false; + try { + hToken = OpenThreadToken(GetCurrentThread(), + TOKEN_ADJUST_PRIVILEGES, false); + if (hToken == 0L && processTokenWithDuplicateAccess != 0L) { + hToken = DuplicateTokenEx(processTokenWithDuplicateAccess, + (TOKEN_ADJUST_PRIVILEGES|TOKEN_IMPERSONATE)); + SetThreadToken(0L, hToken); + impersontating = true; + } + + if (hToken != 0L) { + AdjustTokenPrivileges(hToken, pLuid, SE_PRIVILEGE_ENABLED); + elevated = true; + } + } catch (WindowsException x) { + // nothing to do, privilege not enabled + } + + final long token = hToken; + final boolean stopImpersontating = impersontating; + final boolean needToRevert = elevated; + + return new Privilege() { + @Override + public void drop() { + try { + if (stopImpersontating) { + SetThreadToken(0L, 0L); + } else { + if (needToRevert) { + AdjustTokenPrivileges(token, pLuid, 0); + } + } + } catch (WindowsException x) { + // should not happen + throw new AssertionError(x); + } + } + }; + } +} diff --git a/src/windows/classes/sun/nio/fs/WindowsSecurityDescriptor.java b/src/windows/classes/sun/nio/fs/WindowsSecurityDescriptor.java new file mode 100644 index 0000000000000000000000000000000000000000..0fa0725c5db40edf604922cfd58b764198fb86ce --- /dev/null +++ b/src/windows/classes/sun/nio/fs/WindowsSecurityDescriptor.java @@ -0,0 +1,392 @@ +/* + * Copyright 2008-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 sun.nio.fs; + +import java.nio.file.ProviderMismatchException; +import java.nio.file.attribute.*; +import java.util.*; +import java.io.IOException; +import sun.misc.Unsafe; + +import static sun.nio.fs.WindowsNativeDispatcher.*; +import static sun.nio.fs.WindowsConstants.*; + +/** + * A SecurityDescriptor for use when setting a file's ACL or creating a file + * with an initial ACL. + */ + +class WindowsSecurityDescriptor { + private static final Unsafe unsafe = Unsafe.getUnsafe(); + + /** + * typedef struct _ACL { + * BYTE AclRevision; + * BYTE Sbz1; + * WORD AclSize; + * WORD AceCount; + * WORD Sbz2; + * } ACL; + * + * typedef struct _ACE_HEADER { + * BYTE AceType; + * BYTE AceFlags; + * WORD AceSize; + * } ACE_HEADER; + * + * typedef struct _ACCESS_ALLOWED_ACE { + * ACE_HEADER Header; + * ACCESS_MASK Mask; + * DWORD SidStart; + * } ACCESS_ALLOWED_ACE; + * + * typedef struct _ACCESS_DENIED_ACE { + * ACE_HEADER Header; + * ACCESS_MASK Mask; + * DWORD SidStart; + * } ACCESS_DENIED_ACE; + * + * typedef struct _SECURITY_DESCRIPTOR { + * BYTE Revision; + * BYTE Sbz1; + * SECURITY_DESCRIPTOR_CONTROL Control; + * PSID Owner; + * PSID Group; + * PACL Sacl; + * PACL Dacl; + * } SECURITY_DESCRIPTOR; + */ + private static final short SIZEOF_ACL = 8; + private static final short SIZEOF_ACCESS_ALLOWED_ACE = 12; + private static final short SIZEOF_ACCESS_DENIED_ACE = 12; + private static final short SIZEOF_SECURITY_DESCRIPTOR = 20; + + private static final short OFFSETOF_TYPE = 0; + private static final short OFFSETOF_FLAGS = 1; + private static final short OFFSETOF_ACCESS_MASK = 4; + private static final short OFFSETOF_SID = 8; + + // null security descriptor + private static final WindowsSecurityDescriptor NULL_DESCRIPTOR = + new WindowsSecurityDescriptor(); + + // native resources + private final List<Long> sidList; + private final NativeBuffer aclBuffer, sdBuffer; + + /** + * Creates the "null" SecurityDescriptor + */ + private WindowsSecurityDescriptor() { + this.sidList = null; + this.aclBuffer = null; + this.sdBuffer = null; + } + + /** + * Creates a SecurityDescriptor from the given ACL + */ + private WindowsSecurityDescriptor(List<AclEntry> acl) throws IOException { + boolean initialized = false; + + // SECURITY: need to copy list in case size changes during processing + acl = new ArrayList<AclEntry>(acl); + + // list of SIDs + sidList = new ArrayList<Long>(acl.size()); + try { + // initial size of ACL + int size = SIZEOF_ACL; + + // get the SID for each entry + for (AclEntry entry: acl) { + UserPrincipal user = entry.principal(); + if (!(user instanceof WindowsUserPrincipals.User)) + throw new ProviderMismatchException(); + String sidString = ((WindowsUserPrincipals.User)user).sidString(); + try { + long pSid = ConvertStringSidToSid(sidString); + sidList.add(pSid); + + // increase size to allow for entry + size += GetLengthSid(pSid) + + Math.max(SIZEOF_ACCESS_ALLOWED_ACE, SIZEOF_ACCESS_DENIED_ACE); + + } catch (WindowsException x) { + throw new IOException("Failed to get SID for " + user.getName() + + ": " + x.errorString()); + } + } + + // allocate memory for the ACL + aclBuffer = NativeBuffers.getNativeBuffer(size); + sdBuffer = NativeBuffers.getNativeBuffer(SIZEOF_SECURITY_DESCRIPTOR); + + InitializeAcl(aclBuffer.address(), size); + + // Add entry ACE to the ACL + int i = 0; + while (i < acl.size()) { + AclEntry entry = acl.get(i); + long pSid = sidList.get(i); + try { + encode(entry, pSid, aclBuffer.address()); + } catch (WindowsException x) { + throw new IOException("Failed to encode ACE: " + + x.errorString()); + } + i++; + } + + // initialize security descriptor and set DACL + InitializeSecurityDescriptor(sdBuffer.address()); + SetSecurityDescriptorDacl(sdBuffer.address(), aclBuffer.address()); + initialized = true; + } catch (WindowsException x) { + throw new IOException(x.getMessage()); + } finally { + // release resources if not completely initialized + if (!initialized) + release(); + } + } + + /** + * Releases memory associated with SecurityDescriptor + */ + void release() { + if (sdBuffer != null) + sdBuffer.release(); + if (aclBuffer != null) + aclBuffer.release(); + if (sidList != null) { + // release memory for SIDs + for (Long sid: sidList) { + LocalFree(sid); + } + } + } + + /** + * Returns address of SecurityDescriptor + */ + long address() { + return (sdBuffer == null) ? 0L : sdBuffer.address(); + } + + // decode Windows ACE to NFSv4 AclEntry + private static AclEntry decode(long aceAddress) + throws IOException + { + // map type + byte aceType = unsafe.getByte(aceAddress + OFFSETOF_TYPE); + if (aceType != ACCESS_ALLOWED_ACE_TYPE && aceType != ACCESS_DENIED_ACE_TYPE) + return null; + AclEntryType type; + if (aceType == ACCESS_ALLOWED_ACE_TYPE) { + type = AclEntryType.ALLOW; + } else { + type = AclEntryType.DENY; + } + + // map flags + byte aceFlags = unsafe.getByte(aceAddress + OFFSETOF_FLAGS); + Set<AclEntryFlag> flags = new HashSet<AclEntryFlag>(); + if ((aceFlags & OBJECT_INHERIT_ACE) != 0) + flags.add(AclEntryFlag.FILE_INHERIT); + if ((aceFlags & CONTAINER_INHERIT_ACE) != 0) + flags.add(AclEntryFlag.DIRECTORY_INHERIT); + if ((aceFlags & NO_PROPAGATE_INHERIT_ACE) != 0) + flags.add(AclEntryFlag.NO_PROPAGATE_INHERIT); + if ((aceFlags & INHERIT_ONLY_ACE) != 0) + flags.add(AclEntryFlag.INHERIT_ONLY); + + // map access mask + int mask = unsafe.getInt(aceAddress + OFFSETOF_ACCESS_MASK); + Set<AclEntryPermission> perms = new HashSet<AclEntryPermission>(); + if ((mask & FILE_READ_DATA) > 0) + perms.add(AclEntryPermission.READ_DATA); + if ((mask & FILE_WRITE_DATA) > 0) + perms.add(AclEntryPermission.WRITE_DATA); + if ((mask & FILE_APPEND_DATA ) > 0) + perms.add(AclEntryPermission.APPEND_DATA); + if ((mask & FILE_READ_EA) > 0) + perms.add(AclEntryPermission.READ_NAMED_ATTRS); + if ((mask & FILE_WRITE_EA) > 0) + perms.add(AclEntryPermission.WRITE_NAMED_ATTRS); + if ((mask & FILE_EXECUTE) > 0) + perms.add(AclEntryPermission.EXECUTE); + if ((mask & FILE_DELETE_CHILD ) > 0) + perms.add(AclEntryPermission.DELETE_CHILD); + if ((mask & FILE_READ_ATTRIBUTES) > 0) + perms.add(AclEntryPermission.READ_ATTRIBUTES); + if ((mask & FILE_WRITE_ATTRIBUTES) > 0) + perms.add(AclEntryPermission.WRITE_ATTRIBUTES); + if ((mask & DELETE) > 0) + perms.add(AclEntryPermission.DELETE); + if ((mask & READ_CONTROL) > 0) + perms.add(AclEntryPermission.READ_ACL); + if ((mask & WRITE_DAC) > 0) + perms.add(AclEntryPermission.WRITE_ACL); + if ((mask & WRITE_OWNER) > 0) + perms.add(AclEntryPermission.WRITE_OWNER); + if ((mask & SYNCHRONIZE) > 0) + perms.add(AclEntryPermission.SYNCHRONIZE); + + // lookup SID to create UserPrincipal + long sidAddress = aceAddress + OFFSETOF_SID; + UserPrincipal user = WindowsUserPrincipals.fromSid(sidAddress); + + return AclEntry.newBuilder() + .setType(type) + .setPrincipal(user) + .setFlags(flags).setPermissions(perms).build(); + } + + // encode NFSv4 AclEntry as Windows ACE to given ACL + private static void encode(AclEntry ace, long sidAddress, long aclAddress) + throws WindowsException + { + // ignore non-allow/deny entries for now + if (ace.type() != AclEntryType.ALLOW && ace.type() != AclEntryType.DENY) + return; + boolean allow = (ace.type() == AclEntryType.ALLOW); + + // map access mask + Set<AclEntryPermission> aceMask = ace.permissions(); + int mask = 0; + if (aceMask.contains(AclEntryPermission.READ_DATA)) + mask |= FILE_READ_DATA; + if (aceMask.contains(AclEntryPermission.WRITE_DATA)) + mask |= FILE_WRITE_DATA; + if (aceMask.contains(AclEntryPermission.APPEND_DATA)) + mask |= FILE_APPEND_DATA; + if (aceMask.contains(AclEntryPermission.READ_NAMED_ATTRS)) + mask |= FILE_READ_EA; + if (aceMask.contains(AclEntryPermission.WRITE_NAMED_ATTRS)) + mask |= FILE_WRITE_EA; + if (aceMask.contains(AclEntryPermission.EXECUTE)) + mask |= FILE_EXECUTE; + if (aceMask.contains(AclEntryPermission.DELETE_CHILD)) + mask |= FILE_DELETE_CHILD; + if (aceMask.contains(AclEntryPermission.READ_ATTRIBUTES)) + mask |= FILE_READ_ATTRIBUTES; + if (aceMask.contains(AclEntryPermission.WRITE_ATTRIBUTES)) + mask |= FILE_WRITE_ATTRIBUTES; + if (aceMask.contains(AclEntryPermission.DELETE)) + mask |= DELETE; + if (aceMask.contains(AclEntryPermission.READ_ACL)) + mask |= READ_CONTROL; + if (aceMask.contains(AclEntryPermission.WRITE_ACL)) + mask |= WRITE_DAC; + if (aceMask.contains(AclEntryPermission.WRITE_OWNER)) + mask |= WRITE_OWNER; + if (aceMask.contains(AclEntryPermission.SYNCHRONIZE)) + mask |= SYNCHRONIZE; + + // map flags + Set<AclEntryFlag> aceFlags = ace.flags(); + byte flags = 0; + if (aceFlags.contains(AclEntryFlag.FILE_INHERIT)) + flags |= OBJECT_INHERIT_ACE; + if (aceFlags.contains(AclEntryFlag.DIRECTORY_INHERIT)) + flags |= CONTAINER_INHERIT_ACE; + if (aceFlags.contains(AclEntryFlag.NO_PROPAGATE_INHERIT)) + flags |= NO_PROPAGATE_INHERIT_ACE; + if (aceFlags.contains(AclEntryFlag.INHERIT_ONLY)) + flags |= INHERIT_ONLY_ACE; + + if (allow) { + AddAccessAllowedAceEx(aclAddress, flags, mask, sidAddress); + } else { + AddAccessDeniedAceEx(aclAddress, flags, mask, sidAddress); + } + } + + /** + * Creates a security descriptor with a DACL representing the given ACL. + */ + static WindowsSecurityDescriptor create(List<AclEntry> acl) + throws IOException + { + return new WindowsSecurityDescriptor(acl); + } + + /** + * Processes the array of attributes looking for the attribute "acl:acl". + * Returns security descriptor representing the ACL or the "null" security + * descriptor if the attribute is not in the array. + */ + @SuppressWarnings("unchecked") + static WindowsSecurityDescriptor fromAttribute(FileAttribute<?>... attrs) + throws IOException + { + WindowsSecurityDescriptor sd = NULL_DESCRIPTOR; + for (FileAttribute<?> attr: attrs) { + // if more than one ACL specified then last one wins + if (sd != NULL_DESCRIPTOR) + sd.release(); + if (attr == null) + throw new NullPointerException(); + if (attr.name().equals("acl:acl")) { + List<AclEntry> acl = (List<AclEntry>)attr.value(); + sd = new WindowsSecurityDescriptor(acl); + } else { + throw new UnsupportedOperationException("'" + attr.name() + + "' not supported as initial attribute"); + } + } + return sd; + } + + /** + * Extracts DACL from security descriptor. + */ + static List<AclEntry> getAcl(long pSecurityDescriptor) throws IOException { + // get address of DACL + long aclAddress = GetSecurityDescriptorDacl(pSecurityDescriptor); + + // get ACE count + int aceCount = 0; + if (aclAddress == 0L) { + // no ACEs + aceCount = 0; + } else { + AclInformation aclInfo = GetAclInformation(aclAddress); + aceCount = aclInfo.aceCount(); + } + ArrayList<AclEntry> result = new ArrayList<AclEntry>(aceCount); + + // decode each of the ACEs to AclEntry objects + for (int i=0; i<aceCount; i++) { + long aceAddress = GetAce(aclAddress, i); + AclEntry entry = decode(aceAddress); + if (entry != null) + result.add(entry); + } + return result; + } +} diff --git a/src/windows/classes/sun/nio/fs/WindowsUriSupport.java b/src/windows/classes/sun/nio/fs/WindowsUriSupport.java new file mode 100644 index 0000000000000000000000000000000000000000..d87ba82b7320a1e07a5afa7cee1f431a10272d3b --- /dev/null +++ b/src/windows/classes/sun/nio/fs/WindowsUriSupport.java @@ -0,0 +1,167 @@ +/* + * Copyright 2008-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 sun.nio.fs; + +import java.net.URI; +import java.net.URISyntaxException; + +/** + * Utility methods to convert between Path and URIs. + */ + +class WindowsUriSupport { + private WindowsUriSupport() { + } + + // suffix for IPv6 literal address + private static final String IPV6_LITERAL_SUFFIX = ".ipv6-literal.net"; + + /** + * Returns URI to represent the given (absolute) path + */ + private static URI toUri(String path, boolean isUnc, boolean addSlash) { + String uriHost; + String uriPath; + + if (isUnc) { + int slash = path.indexOf('\\', 2); + uriHost = path.substring(2, slash); + uriPath = path.substring(slash).replace('\\', '/'); + + // handle IPv6 literal addresses + // 1. drop .ivp6-literal.net + // 2. replace "-" with ":" + // 3. replace "s" with "%" (zone/scopeID delimiter) + if (uriHost.endsWith(IPV6_LITERAL_SUFFIX)) { + uriHost = uriHost + .substring(0, uriHost.length() - IPV6_LITERAL_SUFFIX.length()) + .replace('-', ':') + .replace('s', '%'); + } + } else { + uriHost = ""; + uriPath = "/" + path.replace('\\', '/'); + } + + // append slash if known to be directory + if (addSlash) + uriPath += "/"; + + // return file:///C:/My%20Documents or file://server/share/foo + try { + return new URI("file", uriHost, uriPath, null); + } catch (URISyntaxException x) { + if (!isUnc) + throw new AssertionError(x); + } + + // if we get here it means we've got a UNC with reserved characters + // in the server name. The authority component cannot contain escaped + // octets so fallback to encoding the server name into the URI path + // component. + uriPath = "//" + path.replace('\\', '/'); + if (addSlash) + uriPath += "/"; + try { + return new URI("file", null, uriPath, null); + } catch (URISyntaxException x) { + throw new AssertionError(x); + } + } + + /** + * Converts given Path to a URI + */ + static URI toUri(WindowsPath path) { + path = path.toAbsolutePath(); + String s = path.toString(); + + // trailing slash will be added if file is a directory. Skip check if + // already have trailing space + boolean addSlash = false; + if (!s.endsWith("\\")) { + try { + addSlash = WindowsFileAttributes.get(path, true).isDirectory(); + } catch (WindowsException x) { + } + } + + return toUri(s, path.isUnc(), addSlash); + } + + /** + * Converts given URI to a Path + */ + static WindowsPath fromUri(WindowsFileSystem fs, URI uri) { + if (!uri.isAbsolute()) + throw new IllegalArgumentException("URI is not absolute"); + if (uri.isOpaque()) + throw new IllegalArgumentException("URI is not hierarchical"); + String scheme = uri.getScheme(); + if ((scheme == null) || !scheme.equalsIgnoreCase("file")) + throw new IllegalArgumentException("URI scheme is not \"file\""); + if (uri.getFragment() != null) + throw new IllegalArgumentException("URI has a fragment component"); + if (uri.getQuery() != null) + throw new IllegalArgumentException("URI has a query component"); + String path = uri.getPath(); + if (path.equals("")) + throw new IllegalArgumentException("URI path component is empty"); + + // UNC + String auth = uri.getAuthority(); + if (auth != null && !auth.equals("")) { + String host = uri.getHost(); + if (host == null) + throw new IllegalArgumentException("URI authority component has undefined host"); + if (uri.getUserInfo() != null) + throw new IllegalArgumentException("URI authority component has user-info"); + if (uri.getPort() != -1) + throw new IllegalArgumentException("URI authority component has port number"); + + // IPv6 literal + // 1. drop enclosing brackets + // 2. replace ":" with "-" + // 3. replace "%" with "s" (zone/scopeID delimiter) + // 4. Append .ivp6-literal.net + if (host.startsWith("[")) { + host = host.substring(1, host.length()-1) + .replace(':', '-') + .replace('%', 's'); + host += IPV6_LITERAL_SUFFIX; + } + + // reconstitute the UNC + path = "\\\\" + host + path; + } else { + if ((path.length() > 2) && (path.charAt(2) == ':')) { + // "/c:/foo" --> "c:/foo" + path = path.substring(1); + } + } + return WindowsPath.parse(fs, path); + } +} diff --git a/src/windows/classes/sun/nio/fs/WindowsUserDefinedFileAttributeView.java b/src/windows/classes/sun/nio/fs/WindowsUserDefinedFileAttributeView.java new file mode 100644 index 0000000000000000000000000000000000000000..db361c97e0d7e327ccba9346895c169d33128888 --- /dev/null +++ b/src/windows/classes/sun/nio/fs/WindowsUserDefinedFileAttributeView.java @@ -0,0 +1,342 @@ +/* + * Copyright 2008-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 sun.nio.fs; + +import java.nio.file.*; +import static java.nio.file.StandardOpenOption.*; +import java.nio.ByteBuffer; +import java.nio.channels.FileChannel; +import java.io.IOException; +import java.util.*; +import sun.misc.Unsafe; + +import static sun.nio.fs.WindowsNativeDispatcher.*; +import static sun.nio.fs.WindowsConstants.*; + +/** + * Windows emulation of NamedAttributeView using Alternative Data Streams + */ + +class WindowsUserDefinedFileAttributeView + extends AbstractUserDefinedFileAttributeView +{ + private static final Unsafe unsafe = Unsafe.getUnsafe(); + + // syntax to address named streams + private String join(String file, String name) { + if (name == null) + throw new NullPointerException("'name' is null"); + return file + ":" + name; + } + private String join(WindowsPath file, String name) throws WindowsException { + return join(file.getPathForWin32Calls(), name); + } + + private final WindowsPath file; + private final boolean followLinks; + + WindowsUserDefinedFileAttributeView(WindowsPath file, boolean followLinks) { + this.file = file; + this.followLinks = followLinks; + } + + // enumerates the file streams using FindFirstStream/FindNextStream APIs. + private List<String> listUsingStreamEnumeration() throws IOException { + List<String> list = new ArrayList<String>(); + try { + FirstStream first = FindFirstStream(file.getPathForWin32Calls()); + if (first != null) { + long handle = first.handle(); + try { + // first stream is always ::$DATA for files + String name = first.name(); + if (!name.equals("::$DATA")) { + String[] segs = name.split(":"); + list.add(segs[1]); + } + while ((name = FindNextStream(handle)) != null) { + String[] segs = name.split(":"); + list.add(segs[1]); + } + } finally { + FindClose(handle); + } + } + } catch (WindowsException x) { + x.rethrowAsIOException(file); + } + return Collections.unmodifiableList(list); + } + + // enumerates the file streams by reading the stream headers using + // BackupRead + private List<String> listUsingBackupRead() throws IOException { + long handle = -1L; + try { + int flags = FILE_FLAG_BACKUP_SEMANTICS; + if (!followLinks && file.getFileSystem().supportsLinks()) + flags |= FILE_FLAG_OPEN_REPARSE_POINT; + + handle = CreateFile(file.getPathForWin32Calls(), + GENERIC_READ, + FILE_SHARE_READ, // no write as we depend on file size + OPEN_EXISTING, + flags); + } catch (WindowsException x) { + x.rethrowAsIOException(file); + } + + // buffer to read stream header and stream name. + final int BUFFER_SIZE = 4096; + NativeBuffer buffer = null; + + // result with names of alternative data streams + final List<String> list = new ArrayList<String>(); + + try { + buffer = NativeBuffers.getNativeBuffer(BUFFER_SIZE); + long address = buffer.address(); + + /** + * typedef struct _WIN32_STREAM_ID { + * DWORD dwStreamId; + * DWORD dwStreamAttributes; + * LARGE_INTEGER Size; + * DWORD dwStreamNameSize; + * WCHAR cStreamName[ANYSIZE_ARRAY]; + * } WIN32_STREAM_ID; + */ + final int SIZEOF_STREAM_HEADER = 20; + final int OFFSETOF_STREAM_ID = 0; + final int OFFSETOF_STREAM_SIZE = 8; + final int OFFSETOF_STREAM_NAME_SIZE = 16; + + long context = 0L; + try { + for (;;) { + // read stream header + BackupResult result = BackupRead(handle, address, + SIZEOF_STREAM_HEADER, false, context); + context = result.context(); + if (result.bytesTransferred() == 0) + break; + + int streamId = unsafe.getInt(address + OFFSETOF_STREAM_ID); + long streamSize = unsafe.getLong(address + OFFSETOF_STREAM_SIZE); + int nameSize = unsafe.getInt(address + OFFSETOF_STREAM_NAME_SIZE); + + // read stream name + if (nameSize > 0) { + result = BackupRead(handle, address, nameSize, false, context); + if (result.bytesTransferred() != nameSize) + break; + } + + // check for alternative data stream + if (streamId == BACKUP_ALTERNATE_DATA) { + char[] nameAsArray = new char[nameSize/2]; + unsafe.copyMemory(null, address, nameAsArray, + Unsafe.ARRAY_CHAR_BASE_OFFSET, nameSize); + + String[] segs = new String(nameAsArray).split(":"); + if (segs.length == 3) + list.add(segs[1]); + } + + // sparse blocks not currently handled as documentation + // is not sufficient on how the spase block can be skipped. + if (streamId == BACKUP_SPARSE_BLOCK) { + throw new IOException("Spare blocks not handled"); + } + + // seek to end of stream + if (streamSize > 0L) { + BackupSeek(handle, streamSize, context); + } + } + } catch (WindowsException x) { + // failed to read or seek + throw new IOException(x.errorString()); + } finally { + // release context + if (context != 0L) { + try { + BackupRead(handle, 0L, 0, true, context); + } catch (WindowsException ignore) { } + } + } + } finally { + if (buffer != null) + buffer.release(); + CloseHandle(handle); + } + return Collections.unmodifiableList(list); + } + + @Override + public List<String> list() throws IOException { + if (System.getSecurityManager() != null) + checkAccess(file.getPathForPermissionCheck(), true, false); + // use stream APIs on Windwos Server 2003 and newer + if (file.getFileSystem().supportsStreamEnumeration()) { + return listUsingStreamEnumeration(); + } else { + return listUsingBackupRead(); + } + } + + @Override + public int size(String name) throws IOException { + if (System.getSecurityManager() != null) + checkAccess(file.getPathForPermissionCheck(), true, false); + + // wrap with channel + FileChannel fc = null; + try { + Set<OpenOption> opts = new HashSet<OpenOption>(); + opts.add(READ); + if (!followLinks) + opts.add(WindowsChannelFactory.OPEN_REPARSE_POINT); + fc = WindowsChannelFactory + .newFileChannel(join(file, name), null, opts, 0L); + } catch (WindowsException x) { + x.rethrowAsIOException(join(file.getPathForPermissionCheck(), name)); + } + try { + long size = fc.size(); + if (size > Integer.MAX_VALUE) + throw new ArithmeticException("Stream too large"); + return (int)size; + } finally { + fc.close(); + } + } + + @Override + public int read(String name, ByteBuffer dst) throws IOException { + if (System.getSecurityManager() != null) + checkAccess(file.getPathForPermissionCheck(), true, false); + + // wrap with channel + FileChannel fc = null; + try { + Set<OpenOption> opts = new HashSet<OpenOption>(); + opts.add(READ); + if (!followLinks) + opts.add(WindowsChannelFactory.OPEN_REPARSE_POINT); + fc = WindowsChannelFactory + .newFileChannel(join(file, name), null, opts, 0L); + } catch (WindowsException x) { + x.rethrowAsIOException(join(file.getPathForPermissionCheck(), name)); + } + + // read to EOF (nothing we can do if I/O error occurs) + try { + if (fc.size() > dst.remaining()) + throw new IOException("Stream too large"); + int total = 0; + while (dst.hasRemaining()) { + int n = fc.read(dst); + if (n < 0) + break; + total += n; + } + return total; + } finally { + fc.close(); + } + } + + @Override + public int write(String name, ByteBuffer src) throws IOException { + if (System.getSecurityManager() != null) + checkAccess(file.getPathForPermissionCheck(), false, true); + + /** + * Creating a named stream will cause the unnamed stream to be created + * if it doesn't already exist. To avoid this we open the unnamed stream + * for reading and hope it isn't deleted/moved while we create or + * replace the named stream. Opening the file without sharing options + * may cause sharing violations with other programs that are accessing + * the unnamed stream. + */ + long handle = -1L; + try { + int flags = FILE_FLAG_BACKUP_SEMANTICS; + if (!followLinks) + flags |= FILE_FLAG_OPEN_REPARSE_POINT; + + handle = CreateFile(file.getPathForWin32Calls(), + GENERIC_READ, + (FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE), + OPEN_EXISTING, + flags); + } catch (WindowsException x) { + x.rethrowAsIOException(file); + } + try { + Set<OpenOption> opts = new HashSet<OpenOption>(); + if (!followLinks) + opts.add(WindowsChannelFactory.OPEN_REPARSE_POINT); + opts.add(CREATE); + opts.add(WRITE); + opts.add(StandardOpenOption.TRUNCATE_EXISTING); + FileChannel named = null; + try { + named = WindowsChannelFactory + .newFileChannel(join(file, name), null, opts, 0L); + } catch (WindowsException x) { + x.rethrowAsIOException(join(file.getPathForPermissionCheck(), name)); + } + // write value (nothing we can do if I/O error occurs) + try { + int rem = src.remaining(); + while (src.hasRemaining()) { + named.write(src); + } + return rem; + } finally { + named.close(); + } + } finally { + CloseHandle(handle); + } + } + + @Override + public void delete(String name) throws IOException { + if (System.getSecurityManager() != null) + checkAccess(file.getPathForPermissionCheck(), false, true); + + String path = WindowsLinkSupport.getFinalPath(file, followLinks); + String toDelete = join(path, name); + try { + DeleteFile(toDelete); + } catch (WindowsException x) { + x.rethrowAsIOException(toDelete); + } + } +} diff --git a/src/windows/classes/sun/nio/fs/WindowsUserPrincipals.java b/src/windows/classes/sun/nio/fs/WindowsUserPrincipals.java new file mode 100644 index 0000000000000000000000000000000000000000..caf36f17c12fe4cac600e2a0e24e798a991ce2fc --- /dev/null +++ b/src/windows/classes/sun/nio/fs/WindowsUserPrincipals.java @@ -0,0 +1,169 @@ +/* + * Copyright 2008-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 sun.nio.fs; + +import java.nio.file.attribute.*; +import java.io.IOException; + +import static sun.nio.fs.WindowsConstants.*; +import static sun.nio.fs.WindowsNativeDispatcher.*; + +class WindowsUserPrincipals { + private WindowsUserPrincipals() { } + + static class User implements UserPrincipal { + // String representation of SID + private final String sidString; + + // SID type + private final int sidType; + + // Account name (if available) or SID + private final String accountName; + + User(String sidString, int sidType, String accountName) { + this.sidString = sidString; + this.sidType = sidType; + this.accountName = accountName; + } + + // package-private + String sidString() { + return sidString; + } + + @Override + public String getName() { + return accountName; + } + + @Override + public String toString() { + String type; + switch (sidType) { + case SidTypeUser : type = "User"; break; + case SidTypeGroup : type = "Group"; break; + case SidTypeDomain : type = "Domain"; break; + case SidTypeAlias : type = "Alias"; break; + case SidTypeWellKnownGroup : type = "Well-known group"; break; + case SidTypeDeletedAccount : type = "Deleted"; break; + case SidTypeInvalid : type = "Invalid"; break; + case SidTypeComputer : type = "Computer"; break; + default: type = "Unknown"; + } + return accountName + " (" + type + ")"; + } + + @Override + public boolean equals(Object obj) { + if (obj == this) + return true; + if (!(obj instanceof WindowsUserPrincipals.User)) + return false; + WindowsUserPrincipals.User other = (WindowsUserPrincipals.User)obj; + return this.sidString.equals(other.sidString); + } + + @Override + public int hashCode() { + return sidString.hashCode(); + } + } + + static class Group extends User implements GroupPrincipal { + Group(String sidString, int sidType, String accountName) { + super(sidString, sidType, accountName); + } + } + + static UserPrincipal fromSid(long sidAddress) throws IOException { + String sidString; + try { + sidString = ConvertSidToStringSid(sidAddress); + if (sidString == null) { + // pre-Windows XP system? + throw new AssertionError(); + } + } catch (WindowsException x) { + throw new IOException("Unable to convert SID to String: " + + x.errorString()); + } + + // lookup account; if not available then use the SID as the name + Account account = null; + String name; + try { + account = LookupAccountSid(sidAddress); + name = account.domain() + "\\" + account.name(); + } catch (WindowsException x) { + name = sidString; + } + + int sidType = (account == null) ? SidTypeUnknown : account.use(); + if ((sidType == SidTypeGroup) || + (sidType == SidTypeWellKnownGroup) || + (sidType == SidTypeAlias)) // alias for local group + { + return new Group(sidString, sidType, name); + } else { + return new User(sidString, sidType, name); + } + } + + static UserPrincipal lookup(String name) throws IOException { + SecurityManager sm = System.getSecurityManager(); + if (sm != null) { + sm.checkPermission(new RuntimePermission("lookupUserInformation")); + } + + // invoke LookupAccountName to get buffer size needed for SID + int size = 0; + try { + size = LookupAccountName(name, 0L, 0); + } catch (WindowsException x) { + if (x.lastError() == ERROR_NONE_MAPPED) + throw new UserPrincipalNotFoundException(name); + throw new IOException(name + ": " + x.errorString()); + } + assert size > 0; + + // allocate buffer and re-invoke LookupAccountName get SID + NativeBuffer sidBuffer = NativeBuffers.getNativeBuffer(size); + try { + int newSize = LookupAccountName(name, sidBuffer.address(), size); + if (newSize != size) { + // can this happen? + throw new AssertionError("SID change during lookup"); + } + + // return user principal + return fromSid(sidBuffer.address()); + } catch (WindowsException x) { + throw new IOException(name + ": " + x.errorString()); + } finally { + sidBuffer.release(); + } + } +} diff --git a/src/windows/classes/sun/nio/fs/WindowsWatchService.java b/src/windows/classes/sun/nio/fs/WindowsWatchService.java new file mode 100644 index 0000000000000000000000000000000000000000..6a5190784dc14a173c1859069f59619705a40fbc --- /dev/null +++ b/src/windows/classes/sun/nio/fs/WindowsWatchService.java @@ -0,0 +1,582 @@ +/* + * Copyright 2008-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 sun.nio.fs; + +import java.nio.file.*; +import java.io.IOException; +import java.util.*; +import com.sun.nio.file.ExtendedWatchEventModifier; +import sun.misc.Unsafe; + +import static sun.nio.fs.WindowsNativeDispatcher.*; +import static sun.nio.fs.WindowsConstants.*; + +/* + * Win32 implementation of WatchService based on ReadDirectoryChangesW. + */ + +class WindowsWatchService + extends AbstractWatchService +{ + private final Unsafe unsafe = Unsafe.getUnsafe(); + + // background thread to service I/O completion port + private final Poller poller; + + /** + * Creates an I/O completion port and a daemon thread to service it + */ + WindowsWatchService(WindowsFileSystem fs) throws IOException { + // create I/O completion port + long port = 0L; + try { + port = CreateIoCompletionPort(INVALID_HANDLE_VALUE, 0, 0); + } catch (WindowsException x) { + throw new IOException(x.getMessage()); + } + + this.poller = new Poller(fs, this, port); + this.poller.start(); + } + + @Override + WatchKey register(Path path, + WatchEvent.Kind<?>[] events, + WatchEvent.Modifier... modifiers) + throws IOException + { + // delegate to poller + return poller.register(path, events, modifiers); + } + + @Override + void implClose() throws IOException { + // delegate to poller + poller.close(); + } + + /** + * Windows implementation of WatchKey. + */ + private class WindowsWatchKey extends AbstractWatchKey { + // file key (used to detect existing registrations) + private FileKey fileKey; + + // handle to directory + private volatile long handle = INVALID_HANDLE_VALUE; + + // interest events + private Set<? extends WatchEvent.Kind<?>> events; + + // subtree + private boolean watchSubtree; + + // buffer for change events + private NativeBuffer buffer; + + // pointer to bytes returned (in buffer) + private long countAddress; + + // pointer to overlapped structure (in buffer) + private long overlappedAddress; + + // completion key (used to map I/O completion to WatchKey) + private int completionKey; + + WindowsWatchKey(AbstractWatchService watcher, FileKey fileKey) { + super(watcher); + this.fileKey = fileKey; + } + + WindowsWatchKey init(long handle, + Set<? extends WatchEvent.Kind<?>> events, + boolean watchSubtree, + NativeBuffer buffer, + long countAddress, + long overlappedAddress, + int completionKey) + { + this.handle = handle; + this.events = events; + this.watchSubtree = watchSubtree; + this.buffer = buffer; + this.countAddress = countAddress; + this.overlappedAddress = overlappedAddress; + this.completionKey = completionKey; + return this; + } + + long handle() { + return handle; + } + + Set<? extends WatchEvent.Kind<?>> events() { + return events; + } + + void setEvents(Set<? extends WatchEvent.Kind<?>> events) { + this.events = events; + } + + boolean watchSubtree() { + return watchSubtree; + } + + NativeBuffer buffer() { + return buffer; + } + + long countAddress() { + return countAddress; + } + + long overlappedAddress() { + return overlappedAddress; + } + + FileKey fileKey() { + return fileKey; + } + + int completionKey() { + return completionKey; + } + + // close directory and release buffer + void releaseResources() { + CloseHandle(handle); + buffer.cleaner().clean(); + } + + // Invalidate key by closing directory and releasing buffer + void invalidate() { + releaseResources(); + handle = INVALID_HANDLE_VALUE; + buffer = null; + countAddress = 0; + overlappedAddress = 0; + } + + @Override + public boolean isValid() { + return handle != INVALID_HANDLE_VALUE; + } + + @Override + public void cancel() { + if (isValid()) { + // delegate to poller + poller.cancel(this); + } + } + } + + // file key to unique identify (open) directory + private static class FileKey { + private final int volSerialNumber; + private final int fileIndexHigh; + private final int fileIndexLow; + + FileKey(int volSerialNumber, int fileIndexHigh, int fileIndexLow) { + this.volSerialNumber = volSerialNumber; + this.fileIndexHigh = fileIndexHigh; + this.fileIndexLow = fileIndexLow; + } + + @Override + public int hashCode() { + return volSerialNumber ^ fileIndexHigh ^ fileIndexLow; + } + + @Override + public boolean equals(Object obj) { + if (obj == this) + return true; + if (!(obj instanceof FileKey)) + return false; + FileKey other = (FileKey)obj; + if (this.volSerialNumber != other.volSerialNumber) return false; + if (this.fileIndexHigh != other.fileIndexHigh) return false; + if (this.fileIndexLow != other.fileIndexLow) return false; + return true; + } + } + + // all change events + private static final int ALL_FILE_NOTIFY_EVENTS = + FILE_NOTIFY_CHANGE_FILE_NAME | + FILE_NOTIFY_CHANGE_DIR_NAME | + FILE_NOTIFY_CHANGE_ATTRIBUTES | + FILE_NOTIFY_CHANGE_SIZE | + FILE_NOTIFY_CHANGE_LAST_WRITE | + FILE_NOTIFY_CHANGE_CREATION | + FILE_NOTIFY_CHANGE_SECURITY; + + /** + * Background thread to service I/O completion port. + */ + private class Poller extends AbstractPoller { + /* + * typedef struct _OVERLAPPED { + * DWORD Internal; + * DWORD InternalHigh; + * DWORD Offset; + * DWORD OffsetHigh; + * HANDLE hEvent; + * } OVERLAPPED; + */ + private static final short SIZEOF_DWORD = 4; + private static final short SIZEOF_OVERLAPPED = 32; // 20 on 32-bit + + /* + * typedef struct _FILE_NOTIFY_INFORMATION { + * DWORD NextEntryOffset; + * DWORD Action; + * DWORD FileNameLength; + * WCHAR FileName[1]; + * } FileNameLength; + */ + private static final short OFFSETOF_NEXTENTRYOFFSET = 0; + private static final short OFFSETOF_ACTION = 4; + private static final short OFFSETOF_FILENAMELENGTH = 8; + private static final short OFFSETOF_FILENAME = 12; + + // size of per-directory buffer for events (FIXME - make this configurable) + private static final int CHANGES_BUFFER_SIZE = 16 * 1024; + + private final WindowsFileSystem fs; + private final WindowsWatchService watcher; + private final long port; + + // maps completion key to WatchKey + private final Map<Integer,WindowsWatchKey> int2key; + + // maps file key to WatchKey + private final Map<FileKey,WindowsWatchKey> fk2key; + + // unique completion key for each directory + private int lastCompletionKey; + + Poller(WindowsFileSystem fs, WindowsWatchService watcher, long port) { + this.fs = fs; + this.watcher = watcher; + this.port = port; + this.int2key = new HashMap<Integer,WindowsWatchKey>(); + this.fk2key = new HashMap<FileKey,WindowsWatchKey>(); + this.lastCompletionKey = 0; + } + + @Override + void wakeup() throws IOException { + try { + PostQueuedCompletionStatus(port, 0); + } catch (WindowsException x) { + throw new IOException(x.getMessage()); + } + } + + /** + * Register a directory for changes as follows: + * + * 1. Open directory + * 2. Read its attributes (and check it really is a directory) + * 3. Assign completion key and associated handle with completion port + * 4. Call ReadDirectoryChangesW to start (async) read of changes + * 5. Create or return existing key representing registration + */ + @Override + Object implRegister(Path obj, + Set<? extends WatchEvent.Kind<?>> events, + WatchEvent.Modifier... modifiers) + { + WindowsPath dir = (WindowsPath)obj; + boolean watchSubtree = false; + + // FILE_TREE modifier allowed + for (WatchEvent.Modifier modifier: modifiers) { + if (modifier == ExtendedWatchEventModifier.FILE_TREE) { + watchSubtree = true; + continue; + } else { + if (modifier == null) + return new NullPointerException(); + if (modifier instanceof com.sun.nio.file.SensitivityWatchEventModifier) + continue; // ignore + return new UnsupportedOperationException("Modifier not supported"); + } + } + + // open directory + long handle = -1L; + try { + handle = CreateFile(dir.getPathForWin32Calls(), + FILE_LIST_DIRECTORY, + (FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE), + OPEN_EXISTING, + FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED); + } catch (WindowsException x) { + return x.asIOException(dir); + } + + boolean registered = false; + try { + // read attributes and check file is a directory + WindowsFileAttributes attrs = null; + try { + attrs = WindowsFileAttributes.readAttributes(handle); + } catch (WindowsException x) { + return x.asIOException(dir); + } + if (!attrs.isDirectory()) { + return new NotDirectoryException(dir.getPathForExceptionMessage()); + } + + // check if this directory is already registered + FileKey fk = new FileKey(attrs.volSerialNumber(), + attrs.fileIndexHigh(), + attrs.fileIndexLow()); + WindowsWatchKey existing = fk2key.get(fk); + + // if already registered and we're not changing the subtree + // modifier then simply update the event and return the key. + if (existing != null && watchSubtree == existing.watchSubtree()) { + existing.setEvents(events); + return existing; + } + + // unique completion key (skip 0) + int completionKey = ++lastCompletionKey; + if (completionKey == 0) + completionKey = ++lastCompletionKey; + + // associate handle with completion port + try { + CreateIoCompletionPort(handle, port, completionKey); + } catch (WindowsException x) { + return new IOException(x.getMessage()); + } + + // allocate memory for events, including space for other structures + // needed to do overlapped I/O + int size = CHANGES_BUFFER_SIZE + SIZEOF_DWORD + SIZEOF_OVERLAPPED; + NativeBuffer buffer = NativeBuffers.getNativeBuffer(size); + + long bufferAddress = buffer.address(); + long overlappedAddress = bufferAddress + size - SIZEOF_OVERLAPPED; + long countAddress = overlappedAddress - SIZEOF_DWORD; + + // start async read of changes to directory + try { + ReadDirectoryChangesW(handle, + bufferAddress, + CHANGES_BUFFER_SIZE, + watchSubtree, + ALL_FILE_NOTIFY_EVENTS, + countAddress, + overlappedAddress); + } catch (WindowsException x) { + buffer.release(); + return new IOException(x.getMessage()); + } + + WindowsWatchKey watchKey; + if (existing == null) { + // not registered so create new watch key + watchKey = new WindowsWatchKey(watcher, fk) + .init(handle, events, watchSubtree, buffer, countAddress, + overlappedAddress, completionKey); + // map file key to watch key + fk2key.put(fk, watchKey); + } else { + // directory already registered so need to: + // 1. remove mapping from old completion key to existing watch key + // 2. release existing key's resources (handle/buffer) + // 3. re-initialize key with new handle/buffer + int2key.remove(existing.completionKey()); + existing.releaseResources(); + watchKey = existing.init(handle, events, watchSubtree, buffer, + countAddress, overlappedAddress, completionKey); + } + // map completion map to watch key + int2key.put(completionKey, watchKey); + + registered = true; + return watchKey; + + } finally { + if (!registered) CloseHandle(handle); + } + } + + // cancel single key + @Override + void implCancelKey(WatchKey obj) { + WindowsWatchKey key = (WindowsWatchKey)obj; + if (key.isValid()) { + fk2key.remove(key.fileKey()); + int2key.remove(key.completionKey()); + key.invalidate(); + } + } + + // close watch service + @Override + void implCloseAll() { + // cancel all keys + for (Map.Entry<Integer,WindowsWatchKey> entry: int2key.entrySet()) { + entry.getValue().invalidate(); + } + fk2key.clear(); + int2key.clear(); + + // close I/O completion port + CloseHandle(port); + } + + // Translate file change action into watch event + private WatchEvent.Kind<?> translateActionToEvent(int action) + { + switch (action) { + case FILE_ACTION_MODIFIED : + return StandardWatchEventKind.ENTRY_MODIFY; + + case FILE_ACTION_ADDED : + case FILE_ACTION_RENAMED_NEW_NAME : + return StandardWatchEventKind.ENTRY_CREATE; + + case FILE_ACTION_REMOVED : + case FILE_ACTION_RENAMED_OLD_NAME : + return StandardWatchEventKind.ENTRY_DELETE; + + default : + return null; // action not recognized + } + } + + // process events (list of FILE_NOTIFY_INFORMATION structures) + private void processEvents(WindowsWatchKey key, int size) { + long address = key.buffer().address(); + + int nextOffset; + do { + int action = unsafe.getInt(address + OFFSETOF_ACTION); + + // map action to event + WatchEvent.Kind<?> kind = translateActionToEvent(action); + if (key.events().contains(kind)) { + // copy the name + int nameLengthInBytes = unsafe.getInt(address + OFFSETOF_FILENAMELENGTH); + if ((nameLengthInBytes % 2) != 0) { + throw new AssertionError("FileNameLength.FileNameLength is not a multiple of 2"); + } + char[] nameAsArray = new char[nameLengthInBytes/2]; + unsafe.copyMemory(null, address + OFFSETOF_FILENAME, nameAsArray, + Unsafe.ARRAY_CHAR_BASE_OFFSET, nameLengthInBytes); + + // create FileName and queue event + WindowsPath name = WindowsPath + .createFromNormalizedPath(fs, new String(nameAsArray)); + key.signalEvent(kind, name); + } + + // next event + nextOffset = unsafe.getInt(address + OFFSETOF_NEXTENTRYOFFSET); + address += (long)nextOffset; + } while (nextOffset != 0); + } + + /** + * Poller main loop + */ + @Override + public void run() { + for (;;) { + CompletionStatus info = null; + try { + info = GetQueuedCompletionStatus(port); + } catch (WindowsException x) { + // this should not happen + x.printStackTrace(); + return; + } + + // wakeup + if (info.completionKey() == 0) { + boolean shutdown = processRequests(); + if (shutdown) { + return; + } + continue; + } + + // map completionKey to get WatchKey + WindowsWatchKey key = int2key.get(info.completionKey()); + if (key == null) { + // We get here when a registration is changed. In that case + // the directory is closed which causes an event with the + // old completion key. + continue; + } + + // ReadDirectoryChangesW failed + if (info.error() != 0) { + // buffer overflow + if (info.error() == ERROR_NOTIFY_ENUM_DIR) { + key.signalEvent(StandardWatchEventKind.OVERFLOW, null); + } else { + // other error so cancel key + implCancelKey(key); + key.signal(); + } + continue; + } + + // process the events + if (info.bytesTransferred() > 0) { + processEvents(key, info.bytesTransferred()); + } else { + // insufficient buffer size + key.signalEvent(StandardWatchEventKind.OVERFLOW, null); + } + + // start read for next batch of changes + try { + ReadDirectoryChangesW(key.handle(), + key.buffer().address(), + CHANGES_BUFFER_SIZE, + key.watchSubtree(), + ALL_FILE_NOTIFY_EVENTS, + key.countAddress(), + key.overlappedAddress()); + } catch (WindowsException x) { + // no choice but to cancel key + implCancelKey(key); + key.signal(); + } + } + } + } +} diff --git a/src/windows/native/java/io/WinNTFileSystem_md.c b/src/windows/native/java/io/WinNTFileSystem_md.c index 13d4c7e919bc6b103e2c42ccfdd931ed969b3103..f4cc691115b1be94e027188a15b831debdd9524b 100644 --- a/src/windows/native/java/io/WinNTFileSystem_md.c +++ b/src/windows/native/java/io/WinNTFileSystem_md.c @@ -309,12 +309,13 @@ Java_java_io_WinNTFileSystem_getLastModifiedTime(JNIEnv *env, jobject this, /* No template file */ NULL); if (h != INVALID_HANDLE_VALUE) { - GetFileTime(h, NULL, NULL, &t); + if (GetFileTime(h, NULL, NULL, &t)) { + modTime.LowPart = (DWORD) t.dwLowDateTime; + modTime.HighPart = (LONG) t.dwHighDateTime; + rv = modTime.QuadPart / 10000; + rv -= 11644473600000; + } CloseHandle(h); - modTime.LowPart = (DWORD) t.dwLowDateTime; - modTime.HighPart = (LONG) t.dwHighDateTime; - rv = modTime.QuadPart / 10000; - rv -= 11644473600000; } free(pathbuf); return rv; diff --git a/src/windows/native/java/lang/java_props_md.c b/src/windows/native/java/lang/java_props_md.c index f75721f9f71c9b91c32fab9ef9a6d38c7634c0b7..b15a9bafac05d8ffd40f97b51207eff2f052322b 100644 --- a/src/windows/native/java/lang/java_props_md.c +++ b/src/windows/native/java/lang/java_props_md.c @@ -717,6 +717,7 @@ GetJavaProperties(JNIEnv* env) * Windows Vista family 6 0 * Windows 2008 6 0 * where ((&ver.wServicePackMinor) + 2) = 1 + * Windows 7 6 1 * * This mapping will presumably be augmented as new Windows * versions are released. @@ -773,13 +774,18 @@ GetJavaProperties(JNIEnv* env) * and Windows Vista are identical, you must also test * whether the wProductType member is VER_NT_WORKSTATION. * If wProductType is VER_NT_WORKSTATION, the operating - * system is Windows Vista; otherwise, it is Windows + * system is Windows Vista or 7; otherwise, it is Windows * Server 2008." */ - if (ver.wProductType == VER_NT_WORKSTATION) - sprops.os_name = "Windows Vista"; - else + if (ver.wProductType == VER_NT_WORKSTATION) { + switch (ver.dwMinorVersion) { + case 0: sprops.os_name = "Windows Vista"; break; + case 1: sprops.os_name = "Windows 7"; break; + default: sprops.os_name = "Windows NT (unknown)"; + } + } else { sprops.os_name = "Windows Server 2008"; + } } else { sprops.os_name = "Windows NT (unknown)"; } diff --git a/src/windows/native/sun/nio/ch/FileChannelImpl.c b/src/windows/native/sun/nio/ch/FileChannelImpl.c index da96a109a7ff2440286018102617fcd6b5015b29..d1056b883b3d0c5d91694a906d3e4daa5f3a252a 100644 --- a/src/windows/native/sun/nio/ch/FileChannelImpl.c +++ b/src/windows/native/sun/nio/ch/FileChannelImpl.c @@ -1,5 +1,5 @@ /* - * 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. * * This code is free software; you can redistribute it and/or modify it @@ -34,10 +34,6 @@ static jfieldID chan_fd; /* id for jobject 'fd' in java.io.FileChannel */ - -/* false for 95/98/ME, true for NT/W2K */ -static jboolean onNT = JNI_FALSE; - /************************************************************** * static method to store field ID's in initializers * and retrieve the allocation granularity @@ -47,15 +43,9 @@ Java_sun_nio_ch_FileChannelImpl_initIDs(JNIEnv *env, jclass clazz) { SYSTEM_INFO si; jint align; - OSVERSIONINFO ver; GetSystemInfo(&si); align = si.dwAllocationGranularity; chan_fd = (*env)->GetFieldID(env, clazz, "fd", "Ljava/io/FileDescriptor;"); - ver.dwOSVersionInfoSize = sizeof(ver); - GetVersionEx(&ver); - if (ver.dwPlatformId == VER_PLATFORM_WIN32_NT) { - onNT = JNI_TRUE; - } return align; } @@ -146,56 +136,6 @@ Java_sun_nio_ch_FileChannelImpl_unmap0(JNIEnv *env, jobject this, return 0; } -JNIEXPORT jint JNICALL -Java_sun_nio_ch_FileChannelImpl_truncate0(JNIEnv *env, jobject this, - jobject fdo, jlong size) -{ - DWORD lowPos = 0; - long highPos = 0; - BOOL result = 0; - HANDLE h = (HANDLE)(handleval(env, fdo)); - - lowPos = (DWORD)size; - highPos = (long)(size >> 32); - lowPos = SetFilePointer(h, lowPos, &highPos, FILE_BEGIN); - if (lowPos == ((DWORD)-1)) { - if (GetLastError() != ERROR_SUCCESS) { - JNU_ThrowIOExceptionWithLastError(env, "Truncation failed"); - return IOS_THROWN; - } - } - result = SetEndOfFile(h); - if (result == 0) { - JNU_ThrowIOExceptionWithLastError(env, "Truncation failed"); - return IOS_THROWN; - } - return 0; -} - - -JNIEXPORT jint JNICALL -Java_sun_nio_ch_FileChannelImpl_force0(JNIEnv *env, jobject this, - jobject fdo, jboolean md) -{ - int result = 0; - HANDLE h = (HANDLE)(handleval(env, fdo)); - - if (h != INVALID_HANDLE_VALUE) { - result = FlushFileBuffers(h); - if (result == 0) { - int error = GetLastError(); - if (error != ERROR_ACCESS_DENIED) { - JNU_ThrowIOExceptionWithLastError(env, "Force failed"); - return IOS_THROWN; - } - } - } else { - JNU_ThrowIOExceptionWithLastError(env, "Force failed"); - return IOS_THROWN; - } - return 0; -} - JNIEXPORT jlong JNICALL Java_sun_nio_ch_FileChannelImpl_position0(JNIEnv *env, jobject this, jobject fdo, jlong offset) @@ -220,23 +160,6 @@ Java_sun_nio_ch_FileChannelImpl_position0(JNIEnv *env, jobject this, return (((jlong)highPos) << 32) | lowPos; } -JNIEXPORT jlong JNICALL -Java_sun_nio_ch_FileChannelImpl_size0(JNIEnv *env, jobject this, jobject fdo) -{ - DWORD sizeLow = 0; - DWORD sizeHigh = 0; - HANDLE h = (HANDLE)(handleval(env, fdo)); - - sizeLow = GetFileSize(h, &sizeHigh); - if (sizeLow == ((DWORD)-1)) { - if (GetLastError() != ERROR_SUCCESS) { - JNU_ThrowIOExceptionWithLastError(env, "Size failed"); - return IOS_THROWN; - } - } - return (((jlong)sizeHigh) << 32) | sizeLow; -} - JNIEXPORT void JNICALL Java_sun_nio_ch_FileChannelImpl_close0(JNIEnv *env, jobject this, jobject fdo) { @@ -257,99 +180,3 @@ Java_sun_nio_ch_FileChannelImpl_transferTo0(JNIEnv *env, jobject this, { return IOS_UNSUPPORTED; } - -JNIEXPORT jint JNICALL -Java_sun_nio_ch_FileChannelImpl_lock0(JNIEnv *env, jobject this, jobject fdo, - jboolean block, jlong pos, jlong size, - jboolean shared) -{ - HANDLE h = (HANDLE)(handleval(env, fdo)); - DWORD lowPos = (DWORD)pos; - long highPos = (long)(pos >> 32); - DWORD lowNumBytes = (DWORD)size; - DWORD highNumBytes = (DWORD)(size >> 32); - jint result = 0; - if (onNT) { - DWORD flags = 0; - OVERLAPPED o; - o.hEvent = 0; - o.Offset = lowPos; - o.OffsetHigh = highPos; - if (block == JNI_FALSE) { - flags |= LOCKFILE_FAIL_IMMEDIATELY; - } - if (shared == JNI_FALSE) { - flags |= LOCKFILE_EXCLUSIVE_LOCK; - } - result = LockFileEx(h, flags, 0, lowNumBytes, highNumBytes, &o); - if (result == 0) { - int error = GetLastError(); - if (error != ERROR_LOCK_VIOLATION) { - JNU_ThrowIOExceptionWithLastError(env, "Lock failed"); - return sun_nio_ch_FileChannelImpl_NO_LOCK; - } - if (flags & LOCKFILE_FAIL_IMMEDIATELY) { - return sun_nio_ch_FileChannelImpl_NO_LOCK; - } - JNU_ThrowIOExceptionWithLastError(env, "Lock failed"); - return sun_nio_ch_FileChannelImpl_NO_LOCK; - } - return sun_nio_ch_FileChannelImpl_LOCKED; - } else { - for(;;) { - if (size > 0x7fffffff) { - size = 0x7fffffff; - } - lowNumBytes = (DWORD)size; - highNumBytes = 0; - result = LockFile(h, lowPos, highPos, lowNumBytes, highNumBytes); - if (result != 0) { - if (shared == JNI_TRUE) { - return sun_nio_ch_FileChannelImpl_RET_EX_LOCK; - } else { - return sun_nio_ch_FileChannelImpl_LOCKED; - } - } else { - int error = GetLastError(); - if (error != ERROR_LOCK_VIOLATION) { - JNU_ThrowIOExceptionWithLastError(env, "Lock failed"); - return sun_nio_ch_FileChannelImpl_NO_LOCK; - } - if (block == JNI_FALSE) { - return sun_nio_ch_FileChannelImpl_NO_LOCK; - } - } - Sleep(100); - } - } - return sun_nio_ch_FileChannelImpl_NO_LOCK; -} - -JNIEXPORT void JNICALL -Java_sun_nio_ch_FileChannelImpl_release0(JNIEnv *env, jobject this, - jobject fdo, jlong pos, jlong size) -{ - HANDLE h = (HANDLE)(handleval(env, fdo)); - DWORD lowPos = (DWORD)pos; - long highPos = (long)(pos >> 32); - DWORD lowNumBytes = (DWORD)size; - DWORD highNumBytes = (DWORD)(size >> 32); - jint result = 0; - if (onNT) { - OVERLAPPED o; - o.hEvent = 0; - o.Offset = lowPos; - o.OffsetHigh = highPos; - result = UnlockFileEx(h, 0, lowNumBytes, highNumBytes, &o); - } else { - if (size > 0x7fffffff) { - size = 0x7fffffff; - } - lowNumBytes = (DWORD)size; - highNumBytes = 0; - result = UnlockFile(h, lowPos, highPos, lowNumBytes, highNumBytes); - } - if (result == 0) { - JNU_ThrowIOExceptionWithLastError(env, "Release failed"); - } -} diff --git a/src/windows/native/sun/nio/ch/FileDispatcher.c b/src/windows/native/sun/nio/ch/FileDispatcherImpl.c similarity index 67% rename from src/windows/native/sun/nio/ch/FileDispatcher.c rename to src/windows/native/sun/nio/ch/FileDispatcherImpl.c index a3c3985e7a04900bd55511ede5098db5698b950d..a65ad90e24d54e2326522794c027b7d23282b52c 100644 --- a/src/windows/native/sun/nio/ch/FileDispatcher.c +++ b/src/windows/native/sun/nio/ch/FileDispatcherImpl.c @@ -1,5 +1,5 @@ /* - * 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. * * This code is free software; you can redistribute it and/or modify it @@ -28,18 +28,18 @@ #include "jni_util.h" #include "jvm.h" #include "jlong.h" -#include "sun_nio_ch_FileDispatcher.h" +#include "sun_nio_ch_FileDispatcherImpl.h" #include <io.h> #include "nio.h" #include "nio_util.h" /************************************************************** - * FileDispatcher.c + * FileDispatcherImpl.c */ JNIEXPORT jint JNICALL -Java_sun_nio_ch_FileDispatcher_read0(JNIEnv *env, jclass clazz, jobject fdo, +Java_sun_nio_ch_FileDispatcherImpl_read0(JNIEnv *env, jclass clazz, jobject fdo, jlong address, jint len) { DWORD read = 0; @@ -70,7 +70,7 @@ Java_sun_nio_ch_FileDispatcher_read0(JNIEnv *env, jclass clazz, jobject fdo, } JNIEXPORT jlong JNICALL -Java_sun_nio_ch_FileDispatcher_readv0(JNIEnv *env, jclass clazz, jobject fdo, +Java_sun_nio_ch_FileDispatcherImpl_readv0(JNIEnv *env, jclass clazz, jobject fdo, jlong address, jint len) { DWORD read = 0; @@ -119,7 +119,7 @@ Java_sun_nio_ch_FileDispatcher_readv0(JNIEnv *env, jclass clazz, jobject fdo, } JNIEXPORT jint JNICALL -Java_sun_nio_ch_FileDispatcher_pread0(JNIEnv *env, jclass clazz, jobject fdo, +Java_sun_nio_ch_FileDispatcherImpl_pread0(JNIEnv *env, jclass clazz, jobject fdo, jlong address, jint len, jlong offset) { DWORD read = 0; @@ -182,7 +182,7 @@ Java_sun_nio_ch_FileDispatcher_pread0(JNIEnv *env, jclass clazz, jobject fdo, } JNIEXPORT jint JNICALL -Java_sun_nio_ch_FileDispatcher_write0(JNIEnv *env, jclass clazz, jobject fdo, +Java_sun_nio_ch_FileDispatcherImpl_write0(JNIEnv *env, jclass clazz, jobject fdo, jlong address, jint len) { BOOL result = 0; @@ -205,7 +205,7 @@ Java_sun_nio_ch_FileDispatcher_write0(JNIEnv *env, jclass clazz, jobject fdo, } JNIEXPORT jlong JNICALL -Java_sun_nio_ch_FileDispatcher_writev0(JNIEnv *env, jclass clazz, jobject fdo, +Java_sun_nio_ch_FileDispatcherImpl_writev0(JNIEnv *env, jclass clazz, jobject fdo, jlong address, jint len) { BOOL result = 0; @@ -244,7 +244,7 @@ Java_sun_nio_ch_FileDispatcher_writev0(JNIEnv *env, jclass clazz, jobject fdo, } JNIEXPORT jint JNICALL -Java_sun_nio_ch_FileDispatcher_pwrite0(JNIEnv *env, jclass clazz, jobject fdo, +Java_sun_nio_ch_FileDispatcherImpl_pwrite0(JNIEnv *env, jclass clazz, jobject fdo, jlong address, jint len, jlong offset) { BOOL result = 0; @@ -295,6 +295,130 @@ Java_sun_nio_ch_FileDispatcher_pwrite0(JNIEnv *env, jclass clazz, jobject fdo, return convertReturnVal(env, (jint)written, JNI_FALSE); } +JNIEXPORT jint JNICALL +Java_sun_nio_ch_FileDispatcherImpl_force0(JNIEnv *env, jobject this, + jobject fdo, jboolean md) +{ + int result = 0; + HANDLE h = (HANDLE)(handleval(env, fdo)); + + if (h != INVALID_HANDLE_VALUE) { + result = FlushFileBuffers(h); + if (result == 0) { + int error = GetLastError(); + if (error != ERROR_ACCESS_DENIED) { + JNU_ThrowIOExceptionWithLastError(env, "Force failed"); + return IOS_THROWN; + } + } + } else { + JNU_ThrowIOExceptionWithLastError(env, "Force failed"); + return IOS_THROWN; + } + return 0; +} + +JNIEXPORT jint JNICALL +Java_sun_nio_ch_FileDispatcherImpl_truncate0(JNIEnv *env, jobject this, + jobject fdo, jlong size) +{ + DWORD lowPos = 0; + long highPos = 0; + BOOL result = 0; + HANDLE h = (HANDLE)(handleval(env, fdo)); + + lowPos = (DWORD)size; + highPos = (long)(size >> 32); + lowPos = SetFilePointer(h, lowPos, &highPos, FILE_BEGIN); + if (lowPos == ((DWORD)-1)) { + if (GetLastError() != ERROR_SUCCESS) { + JNU_ThrowIOExceptionWithLastError(env, "Truncation failed"); + return IOS_THROWN; + } + } + result = SetEndOfFile(h); + if (result == 0) { + JNU_ThrowIOExceptionWithLastError(env, "Truncation failed"); + return IOS_THROWN; + } + return 0; +} + +JNIEXPORT jlong JNICALL +Java_sun_nio_ch_FileDispatcherImpl_size0(JNIEnv *env, jobject this, jobject fdo) +{ + DWORD sizeLow = 0; + DWORD sizeHigh = 0; + HANDLE h = (HANDLE)(handleval(env, fdo)); + + sizeLow = GetFileSize(h, &sizeHigh); + if (sizeLow == ((DWORD)-1)) { + if (GetLastError() != ERROR_SUCCESS) { + JNU_ThrowIOExceptionWithLastError(env, "Size failed"); + return IOS_THROWN; + } + } + return (((jlong)sizeHigh) << 32) | sizeLow; +} + +JNIEXPORT jint JNICALL +Java_sun_nio_ch_FileDispatcherImpl_lock0(JNIEnv *env, jobject this, jobject fdo, + jboolean block, jlong pos, jlong size, + jboolean shared) +{ + HANDLE h = (HANDLE)(handleval(env, fdo)); + DWORD lowPos = (DWORD)pos; + long highPos = (long)(pos >> 32); + DWORD lowNumBytes = (DWORD)size; + DWORD highNumBytes = (DWORD)(size >> 32); + BOOL result; + DWORD flags = 0; + OVERLAPPED o; + o.hEvent = 0; + o.Offset = lowPos; + o.OffsetHigh = highPos; + if (block == JNI_FALSE) { + flags |= LOCKFILE_FAIL_IMMEDIATELY; + } + if (shared == JNI_FALSE) { + flags |= LOCKFILE_EXCLUSIVE_LOCK; + } + result = LockFileEx(h, flags, 0, lowNumBytes, highNumBytes, &o); + if (result == 0) { + int error = GetLastError(); + if (error != ERROR_LOCK_VIOLATION) { + JNU_ThrowIOExceptionWithLastError(env, "Lock failed"); + return sun_nio_ch_FileDispatcherImpl_NO_LOCK; + } + if (flags & LOCKFILE_FAIL_IMMEDIATELY) { + return sun_nio_ch_FileDispatcherImpl_NO_LOCK; + } + JNU_ThrowIOExceptionWithLastError(env, "Lock failed"); + return sun_nio_ch_FileDispatcherImpl_NO_LOCK; + } + return sun_nio_ch_FileDispatcherImpl_LOCKED; +} + +JNIEXPORT void JNICALL +Java_sun_nio_ch_FileDispatcherImpl_release0(JNIEnv *env, jobject this, + jobject fdo, jlong pos, jlong size) +{ + HANDLE h = (HANDLE)(handleval(env, fdo)); + DWORD lowPos = (DWORD)pos; + long highPos = (long)(pos >> 32); + DWORD lowNumBytes = (DWORD)size; + DWORD highNumBytes = (DWORD)(size >> 32); + jint result = 0; + OVERLAPPED o; + o.hEvent = 0; + o.Offset = lowPos; + o.OffsetHigh = highPos; + result = UnlockFileEx(h, 0, lowNumBytes, highNumBytes, &o); + if (result == 0) { + JNU_ThrowIOExceptionWithLastError(env, "Release failed"); + } +} + static void closeFile(JNIEnv *env, jlong fd) { HANDLE h = (HANDLE)fd; if (h != INVALID_HANDLE_VALUE) { @@ -305,14 +429,14 @@ static void closeFile(JNIEnv *env, jlong fd) { } JNIEXPORT void JNICALL -Java_sun_nio_ch_FileDispatcher_close0(JNIEnv *env, jclass clazz, jobject fdo) +Java_sun_nio_ch_FileDispatcherImpl_close0(JNIEnv *env, jclass clazz, jobject fdo) { jlong fd = handleval(env, fdo); closeFile(env, fd); } JNIEXPORT void JNICALL -Java_sun_nio_ch_FileDispatcher_closeByHandle(JNIEnv *env, jclass clazz, +Java_sun_nio_ch_FileDispatcherImpl_closeByHandle(JNIEnv *env, jclass clazz, jlong fd) { closeFile(env, fd); diff --git a/src/windows/native/sun/nio/ch/Iocp.c b/src/windows/native/sun/nio/ch/Iocp.c new file mode 100644 index 0000000000000000000000000000000000000000..9568189ee6be866ce60dc9053346bcd15be16108 --- /dev/null +++ b/src/windows/native/sun/nio/ch/Iocp.c @@ -0,0 +1,147 @@ +/* + * Copyright 2008-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. + */ + +#include <windows.h> + +#include "jni.h" +#include "jni_util.h" +#include "jlong.h" +#include "nio.h" +#include "nio_util.h" + +#include "sun_nio_ch_Iocp.h" + + +static jfieldID completionStatus_error; +static jfieldID completionStatus_bytesTransferred; +static jfieldID completionStatus_completionKey; +static jfieldID completionStatus_overlapped; + + +JNIEXPORT void JNICALL +Java_sun_nio_ch_Iocp_initIDs(JNIEnv* env, jclass this) +{ + jclass clazz; + + clazz = (*env)->FindClass(env, "sun/nio/ch/Iocp$CompletionStatus"); + if (clazz == NULL) { + return; + } + completionStatus_error = (*env)->GetFieldID(env, clazz, "error", "I"); + if (completionStatus_error == NULL) return; + completionStatus_bytesTransferred = (*env)->GetFieldID(env, clazz, "bytesTransferred", "I"); + if (completionStatus_bytesTransferred == NULL) return; + completionStatus_completionKey = (*env)->GetFieldID(env, clazz, "completionKey", "I"); + if (completionStatus_completionKey == NULL) return; + completionStatus_overlapped = (*env)->GetFieldID(env, clazz, "overlapped", "J"); +} + +JNIEXPORT jlong JNICALL +Java_sun_nio_ch_Iocp_createIoCompletionPort(JNIEnv* env, jclass this, + jlong handle, jlong existingPort, jint completionKey, jint concurrency) +{ + HANDLE port = CreateIoCompletionPort((HANDLE)jlong_to_ptr(handle), + (HANDLE)jlong_to_ptr(existingPort), + (DWORD)completionKey, + (DWORD)concurrency); + if (port == NULL) { + JNU_ThrowIOExceptionWithLastError(env, "CreateIoCompletionPort failed"); + } + return ptr_to_jlong(port); +} + +JNIEXPORT void JNICALL +Java_sun_nio_ch_Iocp_close0(JNIEnv* env, jclass this, + jlong handle) +{ + HANDLE h = (HANDLE)jlong_to_ptr(handle); + CloseHandle(h); +} + + +JNIEXPORT void JNICALL +Java_sun_nio_ch_Iocp_getQueuedCompletionStatus(JNIEnv* env, jclass this, + jlong completionPort, jobject obj) +{ + DWORD bytesTransferred; + DWORD completionKey; + OVERLAPPED *lpOverlapped; + BOOL res; + + res = GetQueuedCompletionStatus((HANDLE)jlong_to_ptr(completionPort), + &bytesTransferred, + &completionKey, + &lpOverlapped, + INFINITE); + if (res == 0 && lpOverlapped == NULL) { + JNU_ThrowIOExceptionWithLastError(env, "GetQueuedCompletionStatus failed"); + } else { + DWORD ioResult = (res == 0) ? GetLastError() : 0; + (*env)->SetIntField(env, obj, completionStatus_error, ioResult); + (*env)->SetIntField(env, obj, completionStatus_bytesTransferred, + (jint)bytesTransferred); + (*env)->SetIntField(env, obj, completionStatus_completionKey, + (jint)completionKey); + (*env)->SetLongField(env, obj, completionStatus_overlapped, + ptr_to_jlong(lpOverlapped)); + + } +} + +JNIEXPORT void JNICALL +Java_sun_nio_ch_Iocp_postQueuedCompletionStatus(JNIEnv* env, jclass this, + jlong completionPort, jint completionKey) +{ + BOOL res; + + res = PostQueuedCompletionStatus((HANDLE)jlong_to_ptr(completionPort), + (DWORD)0, + (DWORD)completionKey, + NULL); + if (res == 0) { + JNU_ThrowIOExceptionWithLastError(env, "PostQueuedCompletionStatus"); + } +} + +JNIEXPORT jstring JNICALL +Java_sun_nio_ch_Iocp_getErrorMessage(JNIEnv* env, jclass this, jint errorCode) +{ + WCHAR message[255]; + + DWORD len = FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM, + NULL, + (DWORD)errorCode, + 0, + &message[0], + 255, + NULL); + + + if (len == 0) { + return NULL; + } else { + return (*env)->NewString(env, (const jchar *)message, (jsize)wcslen(message)); + } +} diff --git a/src/windows/native/sun/nio/ch/WindowsAsynchronousFileChannelImpl.c b/src/windows/native/sun/nio/ch/WindowsAsynchronousFileChannelImpl.c new file mode 100644 index 0000000000000000000000000000000000000000..d8346ba3e7a14c97ece8f55ad563eeb025647b25 --- /dev/null +++ b/src/windows/native/sun/nio/ch/WindowsAsynchronousFileChannelImpl.c @@ -0,0 +1,132 @@ +/* + * Copyright 2008-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. + */ + +#include <windows.h> + +#include "jni.h" +#include "jni_util.h" +#include "jlong.h" +#include "nio.h" +#include "nio_util.h" + +#include "sun_nio_ch_WindowsAsynchronousFileChannelImpl.h" + + +JNIEXPORT jint JNICALL +Java_sun_nio_ch_WindowsAsynchronousFileChannelImpl_readFile(JNIEnv* env, jclass this, + jlong handle, jlong address, jint len, jlong offset, jlong ov) +{ + BOOL res; + DWORD nread = 0; + + OVERLAPPED* lpOverlapped = (OVERLAPPED*)jlong_to_ptr(ov); + lpOverlapped->Offset = (DWORD)offset; + lpOverlapped->OffsetHigh = (DWORD)((long)(offset >> 32)); + lpOverlapped->hEvent = NULL; + + res = ReadFile((HANDLE) jlong_to_ptr(handle), + (LPVOID) jlong_to_ptr(address), + (DWORD)len, + &nread, + lpOverlapped); + + if (res == 0) { + int error = GetLastError(); + if (error == ERROR_IO_PENDING) + return IOS_UNAVAILABLE; + if (error == ERROR_HANDLE_EOF) + return IOS_EOF; + JNU_ThrowIOExceptionWithLastError(env, "ReadFile failed"); + return IOS_THROWN; + } + + return (jint)nread; +} + +JNIEXPORT jint JNICALL +Java_sun_nio_ch_WindowsAsynchronousFileChannelImpl_writeFile(JNIEnv* env, jclass this, + jlong handle, jlong address, jint len, jlong offset, jlong ov) +{ + BOOL res; + DWORD nwritten = 0; + + OVERLAPPED* lpOverlapped = (OVERLAPPED*)jlong_to_ptr(ov); + lpOverlapped->Offset = (DWORD)offset; + lpOverlapped->OffsetHigh = (DWORD)((long)(offset >> 32)); + lpOverlapped->hEvent = NULL; + + res = WriteFile((HANDLE)jlong_to_ptr(handle), + (LPVOID) jlong_to_ptr(address), + (DWORD)len, + &nwritten, + lpOverlapped); + + if (res == 0) { + int error = GetLastError(); + if (error == ERROR_IO_PENDING) { + return IOS_UNAVAILABLE; + } + JNU_ThrowIOExceptionWithLastError(env, "WriteFile failed"); + return IOS_THROWN; + } + return (jint)nwritten; +} + +JNIEXPORT jint JNICALL +Java_sun_nio_ch_WindowsAsynchronousFileChannelImpl_lockFile(JNIEnv *env, jobject this, jlong handle, + jlong pos, jlong size, jboolean shared, jlong ov) +{ + BOOL res; + HANDLE h = jlong_to_ptr(handle); + DWORD lowPos = (DWORD)pos; + long highPos = (long)(pos >> 32); + DWORD lowNumBytes = (DWORD)size; + DWORD highNumBytes = (DWORD)(size >> 32); + DWORD flags = (shared == JNI_TRUE) ? 0 : LOCKFILE_EXCLUSIVE_LOCK; + OVERLAPPED* lpOverlapped = (OVERLAPPED*)jlong_to_ptr(ov); + + lpOverlapped->Offset = lowPos; + lpOverlapped->OffsetHigh = highPos; + lpOverlapped->hEvent = NULL; + + res = LockFileEx(h, flags, 0, lowNumBytes, highNumBytes, lpOverlapped); + if (res == 0) { + int error = GetLastError(); + if (error == ERROR_IO_PENDING) { + return IOS_UNAVAILABLE; + } + JNU_ThrowIOExceptionWithLastError(env, "WriteFile failed"); + return IOS_THROWN; + } + return 0; +} + +JNIEXPORT void JNICALL +Java_sun_nio_ch_WindowsAsynchronousFileChannelImpl_close0(JNIEnv* env, jclass this, + jlong handle) +{ + HANDLE h = (HANDLE)jlong_to_ptr(handle); + CloseHandle(h); +} diff --git a/src/windows/native/sun/nio/ch/WindowsAsynchronousServerSocketChannelImpl.c b/src/windows/native/sun/nio/ch/WindowsAsynchronousServerSocketChannelImpl.c new file mode 100644 index 0000000000000000000000000000000000000000..ba706a4d86b158273dc3791eca2400eb1b90e4f9 --- /dev/null +++ b/src/windows/native/sun/nio/ch/WindowsAsynchronousServerSocketChannelImpl.c @@ -0,0 +1,142 @@ +/* + * Copyright 2008-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. + */ + +#include <windows.h> +#include <winsock2.h> + +#include "jni.h" +#include "jni_util.h" +#include "jlong.h" +#include "nio.h" +#include "nio_util.h" +#include "net_util.h" + +#include "sun_nio_ch_WindowsAsynchronousServerSocketChannelImpl.h" + + +#ifndef WSAID_ACCEPTEX +#define WSAID_ACCEPTEX {0xb5367df1,0xcbac,0x11cf,{0x95,0xca,0x00,0x80,0x5f,0x48,0xa1,0x92}} +#endif + +#ifndef SO_UPDATE_ACCEPT_CONTEXT +#define SO_UPDATE_ACCEPT_CONTEXT 0x700B +#endif + + +typedef BOOL (*AcceptEx_t) +( + SOCKET sListenSocket, + SOCKET sAcceptSocket, + PVOID lpOutputBuffer, + DWORD dwReceiveDataLength, + DWORD dwLocalAddressLength, + DWORD dwRemoteAddressLength, + LPDWORD lpdwBytesReceived, + LPOVERLAPPED lpOverlapped +); + + +static AcceptEx_t AcceptEx_func; + + +JNIEXPORT void JNICALL +Java_sun_nio_ch_WindowsAsynchronousServerSocketChannelImpl_initIDs(JNIEnv* env, jclass this) { + GUID GuidAcceptEx = WSAID_ACCEPTEX; + SOCKET s; + int rv; + DWORD dwBytes; + + s = socket(AF_INET, SOCK_STREAM, 0); + if (s == INVALID_SOCKET) { + JNU_ThrowIOExceptionWithLastError(env, "socket failed"); + return; + } + rv = WSAIoctl(s, + SIO_GET_EXTENSION_FUNCTION_POINTER, + (LPVOID)&GuidAcceptEx, + sizeof(GuidAcceptEx), + &AcceptEx_func, + sizeof(AcceptEx_func), + &dwBytes, + NULL, + NULL); + if (rv != 0) + JNU_ThrowIOExceptionWithLastError(env, "WSAIoctl failed"); + closesocket(s); +} + +JNIEXPORT jint JNICALL +Java_sun_nio_ch_WindowsAsynchronousServerSocketChannelImpl_accept0(JNIEnv* env, jclass this, + jlong listenSocket, jlong acceptSocket, jlong ov, jlong buf) +{ + BOOL res; + SOCKET s1 = (SOCKET)jlong_to_ptr(listenSocket); + SOCKET s2 = (SOCKET)jlong_to_ptr(acceptSocket); + PVOID outputBuffer = (PVOID)jlong_to_ptr(buf); + + DWORD nread = 0; + OVERLAPPED* lpOverlapped = (OVERLAPPED*)jlong_to_ptr(ov); + ZeroMemory((PVOID)lpOverlapped, sizeof(OVERLAPPED)); + + res = (*AcceptEx_func)(s1, + s2, + outputBuffer, + 0, + sizeof(SOCKETADDRESS)+16, + sizeof(SOCKETADDRESS)+16, + &nread, + lpOverlapped); + if (res == 0) { + int error = WSAGetLastError(); + if (error == ERROR_IO_PENDING) { + return IOS_UNAVAILABLE; + } + JNU_ThrowIOExceptionWithLastError(env, "AcceptEx failed"); + return IOS_THROWN; + } + + return 0; +} + +JNIEXPORT void JNICALL +Java_sun_nio_ch_WindowsAsynchronousServerSocketChannelImpl_updateAcceptContext(JNIEnv* env, jclass this, + jlong listenSocket, jlong acceptSocket) +{ + SOCKET s1 = (SOCKET)jlong_to_ptr(listenSocket); + SOCKET s2 = (SOCKET)jlong_to_ptr(acceptSocket); + + setsockopt(s2, SOL_SOCKET, SO_UPDATE_ACCEPT_CONTEXT, (char *)&s1, sizeof(s1)); +} + + +JNIEXPORT void JNICALL +Java_sun_nio_ch_WindowsAsynchronousServerSocketChannelImpl_closesocket0(JNIEnv* env, jclass this, + jlong socket) +{ + SOCKET s = (SOCKET)jlong_to_ptr(socket); + + if (closesocket(s) == SOCKET_ERROR) + JNU_ThrowIOExceptionWithLastError(env, "closesocket failed"); +} diff --git a/src/windows/native/sun/nio/ch/WindowsAsynchronousSocketChannelImpl.c b/src/windows/native/sun/nio/ch/WindowsAsynchronousSocketChannelImpl.c new file mode 100644 index 0000000000000000000000000000000000000000..97c49f60a7107a2f2309313e95b6c69b2470b37c --- /dev/null +++ b/src/windows/native/sun/nio/ch/WindowsAsynchronousSocketChannelImpl.c @@ -0,0 +1,222 @@ +/* + * Copyright 2008-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. + */ + +#include <windows.h> +#include <winsock2.h> +#include <stddef.h> + +#include "jni.h" +#include "jni_util.h" +#include "jlong.h" +#include "nio.h" +#include "nio_util.h" +#include "net_util.h" + +#include "sun_nio_ch_WindowsAsynchronousSocketChannelImpl.h" + +#ifndef WSAID_CONNECTEX +#define WSAID_CONNECTEX {0x25a207b9,0xddf3,0x4660,{0x8e,0xe9,0x76,0xe5,0x8c,0x74,0x06,0x3e}} +#endif + +#ifndef SO_UPDATE_CONNECT_CONTEXT +#define SO_UPDATE_CONNECT_CONTEXT 0x7010 +#endif + +typedef BOOL (*ConnectEx_t) +( + SOCKET s, + const struct sockaddr* name, + int namelen, + PVOID lpSendBuffer, + DWORD dwSendDataLength, + LPDWORD lpdwBytesSent, + LPOVERLAPPED lpOverlapped +); + +static ConnectEx_t ConnectEx_func; + + +JNIEXPORT void JNICALL +Java_sun_nio_ch_WindowsAsynchronousSocketChannelImpl_initIDs(JNIEnv* env, jclass this) { + GUID GuidConnectEx = WSAID_CONNECTEX; + SOCKET s; + int rv; + DWORD dwBytes; + + s = socket(AF_INET, SOCK_STREAM, 0); + if (s == INVALID_SOCKET) { + JNU_ThrowIOExceptionWithLastError(env, "socket failed"); + return; + } + rv = WSAIoctl(s, + SIO_GET_EXTENSION_FUNCTION_POINTER, + (LPVOID)&GuidConnectEx, + sizeof(GuidConnectEx), + &ConnectEx_func, + sizeof(ConnectEx_func), + &dwBytes, + NULL, + NULL); + if (rv != 0) + JNU_ThrowIOExceptionWithLastError(env, "WSAIoctl failed"); + closesocket(s); +} + +JNIEXPORT jint JNICALL +Java_sun_nio_ch_WindowsAsynchronousSocketChannelImpl_connect0(JNIEnv* env, jclass this, + jlong socket, jboolean preferIPv6, jobject iao, jint port, jlong ov) +{ + SOCKET s = (SOCKET) jlong_to_ptr(socket); + OVERLAPPED* lpOverlapped = (OVERLAPPED*) jlong_to_ptr(ov); + + SOCKETADDRESS sa; + int sa_len; + BOOL res; + + if (NET_InetAddressToSockaddr(env, iao, port, (struct sockaddr *)&sa, &sa_len, preferIPv6) != 0) { + return IOS_THROWN; + } + + ZeroMemory((PVOID)lpOverlapped, sizeof(OVERLAPPED)); + + res = (*ConnectEx_func)(s, + (struct sockaddr *)&sa, + sa_len, + NULL, + 0, + NULL, + lpOverlapped); + if (res == 0) { + int error = GetLastError(); + if (error == ERROR_IO_PENDING) { + return IOS_UNAVAILABLE; + } + JNU_ThrowIOExceptionWithLastError(env, "ConnectEx failed"); + return IOS_THROWN; + } + return 0; +} + +JNIEXPORT void JNICALL +Java_sun_nio_ch_WindowsAsynchronousSocketChannelImpl_updateConnectContext(JNIEnv* env, jclass this, + jlong socket) +{ + SOCKET s = (SOCKET)jlong_to_ptr(socket); + setsockopt(s, SOL_SOCKET, SO_UPDATE_CONNECT_CONTEXT, NULL, 0); +} + + +JNIEXPORT void JNICALL +Java_sun_nio_ch_WindowsAsynchronousSocketChannelImpl_shutdown0(JNIEnv *env, jclass cl, + jlong socket, jint how) +{ + SOCKET s =(SOCKET) jlong_to_ptr(socket); + if (shutdown(s, how) == SOCKET_ERROR) { + JNU_ThrowIOExceptionWithLastError(env, "shutdown failed"); + } +} + + +JNIEXPORT void JNICALL +Java_sun_nio_ch_WindowsAsynchronousSocketChannelImpl_closesocket0(JNIEnv* env, jclass this, + jlong socket) +{ + SOCKET s = (SOCKET)jlong_to_ptr(socket); + if (closesocket(s) == SOCKET_ERROR) + JNU_ThrowIOExceptionWithLastError(env, "closesocket failed"); +} + + +JNIEXPORT jint JNICALL +Java_sun_nio_ch_WindowsAsynchronousSocketChannelImpl_read0(JNIEnv* env, jclass this, + jlong socket, jint count, jlong address, jlong ov) +{ + SOCKET s = (SOCKET) jlong_to_ptr(socket); + WSABUF* lpWsaBuf = (WSABUF*) jlong_to_ptr(address); + OVERLAPPED* lpOverlapped = (OVERLAPPED*) jlong_to_ptr(ov); + BOOL res; + DWORD nread = 0; + DWORD flags = 0; + + ZeroMemory((PVOID)lpOverlapped, sizeof(OVERLAPPED)); + res = WSARecv(s, + lpWsaBuf, + (DWORD)count, + &nread, + &flags, + lpOverlapped, + NULL); + + if (res == SOCKET_ERROR) { + int error = WSAGetLastError(); + if (error == WSA_IO_PENDING) { + return IOS_UNAVAILABLE; + } + if (error == WSAESHUTDOWN) { + return 0; // input shutdown + } + JNU_ThrowIOExceptionWithLastError(env, "WSARecv failed"); + return IOS_THROWN; + } + if (nread == 0) { + // Handle graceful close or bytes not yet available cases + // via completion port notification. + return IOS_UNAVAILABLE; + } + return (jint)nread; +} + +JNIEXPORT jint JNICALL +Java_sun_nio_ch_WindowsAsynchronousSocketChannelImpl_write0(JNIEnv* env, jclass this, + jlong socket, jint count, jlong address, jlong ov) +{ + SOCKET s = (SOCKET) jlong_to_ptr(socket); + WSABUF* lpWsaBuf = (WSABUF*) jlong_to_ptr(address); + OVERLAPPED* lpOverlapped = (OVERLAPPED*) jlong_to_ptr(ov); + BOOL res; + DWORD nwritten; + + ZeroMemory((PVOID)lpOverlapped, sizeof(OVERLAPPED)); + res = WSASend(s, + lpWsaBuf, + (DWORD)count, + &nwritten, + 0, + lpOverlapped, + NULL); + + if (res == SOCKET_ERROR) { + int error = WSAGetLastError(); + if (error == WSA_IO_PENDING) { + return IOS_UNAVAILABLE; + } + if (error == WSAESHUTDOWN) { + return IOS_EOF; // output shutdown + } + JNU_ThrowIOExceptionWithLastError(env, "WSASend failed"); + return IOS_THROWN; + } + return (jint)nwritten; +} diff --git a/src/windows/native/sun/nio/fs/RegistryFileTypeDetector.c b/src/windows/native/sun/nio/fs/RegistryFileTypeDetector.c new file mode 100644 index 0000000000000000000000000000000000000000..14c7f6af948c568c00c1cb6396bbb5566a77370a --- /dev/null +++ b/src/windows/native/sun/nio/fs/RegistryFileTypeDetector.c @@ -0,0 +1,62 @@ +/* + * Copyright 2008-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. + */ + +#include <windows.h> + +#include "jni.h" +#include "jni_util.h" +#include "jlong.h" + +#include "sun_nio_fs_RegistryFileTypeDetector.h" + + +JNIEXPORT jstring JNICALL +Java_sun_nio_fs_RegistryFileTypeDetector_queryStringValue(JNIEnv* env, jclass this, + jlong keyAddress, jlong nameAddress) +{ + LPCWSTR lpSubKey= (LPCWSTR)jlong_to_ptr(keyAddress); + LPWSTR lpValueName = (LPWSTR)jlong_to_ptr(nameAddress); + LONG res; + HKEY hKey; + jstring result = NULL; + + res = RegOpenKeyExW(HKEY_CLASSES_ROOT, lpSubKey, 0, KEY_READ, &hKey); + if (res == ERROR_SUCCESS) { + DWORD type; + BYTE data[255]; + DWORD size = sizeof(data); + + res = RegQueryValueExW(hKey, lpValueName, NULL, &type, (LPBYTE)&data, &size); + if (res == ERROR_SUCCESS) { + if (type == REG_SZ) { + jsize len = wcslen((WCHAR*)data); + result = (*env)->NewString(env, (const jchar*)&data, len); + } + } + + RegCloseKey(hKey); + } + return result; +} diff --git a/src/windows/native/sun/nio/fs/WindowsNativeDispatcher.c b/src/windows/native/sun/nio/fs/WindowsNativeDispatcher.c new file mode 100644 index 0000000000000000000000000000000000000000..45a3646275c35cb02db41a2befd05c2773f8840a --- /dev/null +++ b/src/windows/native/sun/nio/fs/WindowsNativeDispatcher.c @@ -0,0 +1,1345 @@ +/* + * Copyright 2008-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. + */ + +#ifndef _WIN32_WINNT +#define _WIN32_WINNT 0x0500 +#endif + +#include <stdio.h> +#include <stdlib.h> +#include <ctype.h> +#include <direct.h> +#include <malloc.h> +#include <io.h> +#include <windows.h> +#include <aclapi.h> +#include <winioctl.h> + +#include "jni.h" +#include "jni_util.h" +#include "jlong.h" + +#include "sun_nio_fs_WindowsNativeDispatcher.h" + +/** + * jfieldIDs + */ +static jfieldID findFirst_handle; +static jfieldID findFirst_name; + +static jfieldID findStream_handle; +static jfieldID findStream_name; + +static jfieldID volumeInfo_fsName; +static jfieldID volumeInfo_volName; +static jfieldID volumeInfo_volSN; +static jfieldID volumeInfo_flags; + +static jfieldID diskSpace_bytesAvailable; +static jfieldID diskSpace_totalBytes; +static jfieldID diskSpace_totalFree; + +static jfieldID account_domain; +static jfieldID account_name; +static jfieldID account_use; + +static jfieldID aclInfo_aceCount; + +static jfieldID completionStatus_error; +static jfieldID completionStatus_bytesTransferred; +static jfieldID completionStatus_completionKey; + +static jfieldID backupResult_bytesTransferred; +static jfieldID backupResult_context; + + +/** + * Win32 APIs not defined in Visual Studio 2003 header files + */ + +typedef enum { + FindStreamInfoStandard +} MY_STREAM_INFO_LEVELS; + +typedef struct _MY_WIN32_FIND_STREAM_DATA { + LARGE_INTEGER StreamSize; + WCHAR cStreamName[MAX_PATH + 36]; +} MY_WIN32_FIND_STREAM_DATA; + +typedef HANDLE (WINAPI* FindFirstStream_Proc)(LPCWSTR, MY_STREAM_INFO_LEVELS, LPVOID, DWORD); +typedef BOOL (WINAPI* FindNextStream_Proc)(HANDLE, LPVOID); + +typedef BOOLEAN (WINAPI* CreateSymbolicLinkProc) (LPCWSTR, LPCWSTR, DWORD); +typedef BOOL (WINAPI* CreateHardLinkProc) (LPCWSTR, LPCWSTR, LPSECURITY_ATTRIBUTES); +typedef BOOL (WINAPI* GetFinalPathNameByHandleProc) (HANDLE, LPWSTR, DWORD, DWORD); + +typedef BOOL (WINAPI* ConvertSidToStringSidProc) (PSID, LPWSTR*); +typedef BOOL (WINAPI* ConvertStringSidToSidProc) (LPWSTR, PSID*); +typedef DWORD (WINAPI* GetLengthSidProc) (PSID); + +static FindFirstStream_Proc FindFirstStream_func; +static FindNextStream_Proc FindNextStream_func; + +static CreateSymbolicLinkProc CreateSymbolicLink_func; +static CreateHardLinkProc CreateHardLink_func; +static GetFinalPathNameByHandleProc GetFinalPathNameByHandle_func; + +static ConvertSidToStringSidProc ConvertSidToStringSid_func; +static ConvertStringSidToSidProc ConvertStringSidToSid_func; +static GetLengthSidProc GetLengthSid_func; + +static void throwWindowsException(JNIEnv* env, DWORD lastError) { + jobject x = JNU_NewObjectByName(env, "sun/nio/fs/WindowsException", + "(I)V", lastError); + if (x != NULL) { + (*env)->Throw(env, x); + } +} + +/** + * Initializes jfieldIDs and get address of Win32 calls that are located + * at runtime. + */ +JNIEXPORT void JNICALL +Java_sun_nio_fs_WindowsNativeDispatcher_initIDs(JNIEnv* env, jclass this) +{ + jclass clazz; + HMODULE h; + + clazz = (*env)->FindClass(env, "sun/nio/fs/WindowsNativeDispatcher$FirstFile"); + if (clazz == NULL) { + return; + } + findFirst_handle = (*env)->GetFieldID(env, clazz, "handle", "J"); + findFirst_name = (*env)->GetFieldID(env, clazz, "name", "Ljava/lang/String;"); + + clazz = (*env)->FindClass(env, "sun/nio/fs/WindowsNativeDispatcher$FirstStream"); + if (clazz == NULL) { + return; + } + findStream_handle = (*env)->GetFieldID(env, clazz, "handle", "J"); + findStream_name = (*env)->GetFieldID(env, clazz, "name", "Ljava/lang/String;"); + + clazz = (*env)->FindClass(env, "sun/nio/fs/WindowsNativeDispatcher$VolumeInformation"); + if (clazz == NULL) { + return; + } + volumeInfo_fsName = (*env)->GetFieldID(env, clazz, "fileSystemName", "Ljava/lang/String;"); + volumeInfo_volName = (*env)->GetFieldID(env, clazz, "volumeName", "Ljava/lang/String;"); + volumeInfo_volSN = (*env)->GetFieldID(env, clazz, "volumeSerialNumber", "I"); + volumeInfo_flags = (*env)->GetFieldID(env, clazz, "flags", "I"); + + clazz = (*env)->FindClass(env, "sun/nio/fs/WindowsNativeDispatcher$DiskFreeSpace"); + if (clazz == NULL) { + return; + } + diskSpace_bytesAvailable = (*env)->GetFieldID(env, clazz, "freeBytesAvailable", "J"); + diskSpace_totalBytes = (*env)->GetFieldID(env, clazz, "totalNumberOfBytes", "J"); + diskSpace_totalFree = (*env)->GetFieldID(env, clazz, "totalNumberOfFreeBytes", "J"); + + clazz = (*env)->FindClass(env, "sun/nio/fs/WindowsNativeDispatcher$Account"); + if (clazz == NULL) { + return; + } + account_domain = (*env)->GetFieldID(env, clazz, "domain", "Ljava/lang/String;"); + account_name = (*env)->GetFieldID(env, clazz, "name", "Ljava/lang/String;"); + account_use = (*env)->GetFieldID(env, clazz, "use", "I"); + + clazz = (*env)->FindClass(env, "sun/nio/fs/WindowsNativeDispatcher$AclInformation"); + if (clazz == NULL) { + return; + } + aclInfo_aceCount = (*env)->GetFieldID(env, clazz, "aceCount", "I"); + + clazz = (*env)->FindClass(env, "sun/nio/fs/WindowsNativeDispatcher$CompletionStatus"); + if (clazz == NULL) { + return; + } + completionStatus_error = (*env)->GetFieldID(env, clazz, "error", "I"); + completionStatus_bytesTransferred = (*env)->GetFieldID(env, clazz, "bytesTransferred", "I"); + completionStatus_completionKey = (*env)->GetFieldID(env, clazz, "completionKey", "I"); + + clazz = (*env)->FindClass(env, "sun/nio/fs/WindowsNativeDispatcher$BackupResult"); + if (clazz == NULL) { + return; + } + backupResult_bytesTransferred = (*env)->GetFieldID(env, clazz, "bytesTransferred", "I"); + backupResult_context = (*env)->GetFieldID(env, clazz, "context", "J"); + + + h = LoadLibrary("kernel32"); + if (h != INVALID_HANDLE_VALUE) { + FindFirstStream_func = + (FindFirstStream_Proc)GetProcAddress(h, "FindFirstStreamW"); + FindNextStream_func = + (FindNextStream_Proc)GetProcAddress(h, "FindNextStreamW"); + CreateSymbolicLink_func = + (CreateSymbolicLinkProc)GetProcAddress(h, "CreateSymbolicLinkW"); + CreateHardLink_func = + (CreateHardLinkProc)GetProcAddress(h, "CreateHardLinkW"); + GetFinalPathNameByHandle_func = + (GetFinalPathNameByHandleProc)GetProcAddress(h, "GetFinalPathNameByHandleW"); + FreeLibrary(h); + } + + h = LoadLibrary("advapi32"); + if (h != INVALID_HANDLE_VALUE) { + ConvertSidToStringSid_func = + (ConvertSidToStringSidProc)GetProcAddress(h, "ConvertSidToStringSidW"); + ConvertStringSidToSid_func = + (ConvertStringSidToSidProc)GetProcAddress(h, "ConvertStringSidToSidW"); + GetLengthSid_func = + (GetLengthSidProc)GetProcAddress(h, "GetLengthSid"); + FreeLibrary(h); + } + +} + +JNIEXPORT jstring JNICALL +Java_sun_nio_fs_WindowsNativeDispatcher_FormatMessage(JNIEnv* env, jclass this, jint errorCode) { + WCHAR message[255]; + + DWORD len = FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM, + NULL, + (DWORD)errorCode, + 0, + &message[0], + 255, + NULL); + + + if (len == 0) { + return NULL; + } else { + return (*env)->NewString(env, (const jchar *)message, (jsize)wcslen(message)); + } +} + +JNIEXPORT void JNICALL +Java_sun_nio_fs_WindowsNativeDispatcher_LocalFree(JNIEnv* env, jclass this, jlong address) +{ + HLOCAL hMem = (HLOCAL)jlong_to_ptr(address); + LocalFree(hMem); +} + +JNIEXPORT jlong JNICALL +Java_sun_nio_fs_WindowsNativeDispatcher_CreateFile0(JNIEnv* env, jclass this, + jlong address, jint dwDesiredAccess, jint dwShareMode, jlong sdAddress, + jint dwCreationDisposition, jint dwFlagsAndAttributes) +{ + HANDLE handle; + LPCWSTR lpFileName = jlong_to_ptr(address); + + SECURITY_ATTRIBUTES securityAttributes; + LPSECURITY_ATTRIBUTES lpSecurityAttributes; + PSECURITY_DESCRIPTOR lpSecurityDescriptor = jlong_to_ptr(sdAddress); + + + if (lpSecurityDescriptor == NULL) { + lpSecurityAttributes = NULL; + } else { + securityAttributes.nLength = sizeof(SECURITY_ATTRIBUTES); + securityAttributes.lpSecurityDescriptor = lpSecurityDescriptor; + securityAttributes.bInheritHandle = FALSE; + lpSecurityAttributes = &securityAttributes; + } + + handle = CreateFileW(lpFileName, + (DWORD)dwDesiredAccess, + (DWORD)dwShareMode, + lpSecurityAttributes, + (DWORD)dwCreationDisposition, + (DWORD)dwFlagsAndAttributes, + NULL); + if (handle == INVALID_HANDLE_VALUE) { + throwWindowsException(env, GetLastError()); + } + return ptr_to_jlong(handle); +} + + +JNIEXPORT void JNICALL +Java_sun_nio_fs_WindowsNativeDispatcher_DeviceIoControlSetSparse(JNIEnv* env, jclass this, + jlong handle) +{ + DWORD bytesReturned; + HANDLE h = (HANDLE)jlong_to_ptr(handle); + if (DeviceIoControl(h, FSCTL_SET_SPARSE, NULL, 0, NULL, 0, &bytesReturned, NULL) == 0) { + throwWindowsException(env, GetLastError()); + } +} + +JNIEXPORT void JNICALL +Java_sun_nio_fs_WindowsNativeDispatcher_DeviceIoControlGetReparsePoint(JNIEnv* env, jclass this, + jlong handle, jlong bufferAddress, jint bufferSize) +{ + DWORD bytesReturned; + HANDLE h = (HANDLE)jlong_to_ptr(handle); + LPVOID outBuffer = (LPVOID)jlong_to_ptr(bufferAddress); + + if (DeviceIoControl(h, FSCTL_GET_REPARSE_POINT, NULL, 0, outBuffer, (DWORD)bufferSize, + &bytesReturned, NULL) == 0) + { + throwWindowsException(env, GetLastError()); + } +} + +JNIEXPORT void JNICALL +Java_sun_nio_fs_WindowsNativeDispatcher_DeleteFile0(JNIEnv* env, jclass this, jlong address) +{ + LPCWSTR lpFileName = jlong_to_ptr(address); + if (DeleteFileW(lpFileName) == 0) { + throwWindowsException(env, GetLastError()); + } +} + +JNIEXPORT void JNICALL +Java_sun_nio_fs_WindowsNativeDispatcher_CreateDirectory0(JNIEnv* env, jclass this, + jlong address, jlong sdAddress) +{ + LPCWSTR lpFileName = jlong_to_ptr(address); + + SECURITY_ATTRIBUTES securityAttributes; + LPSECURITY_ATTRIBUTES lpSecurityAttributes; + PSECURITY_DESCRIPTOR lpSecurityDescriptor = jlong_to_ptr(sdAddress); + + + if (lpSecurityDescriptor == NULL) { + lpSecurityAttributes = NULL; + } else { + securityAttributes.nLength = sizeof(SECURITY_ATTRIBUTES); + securityAttributes.lpSecurityDescriptor = lpSecurityDescriptor; + securityAttributes.bInheritHandle = FALSE; + lpSecurityAttributes = &securityAttributes; + } + + if (CreateDirectoryW(lpFileName, lpSecurityAttributes) == 0) { + throwWindowsException(env, GetLastError()); + } +} + +JNIEXPORT void JNICALL +Java_sun_nio_fs_WindowsNativeDispatcher_RemoveDirectory0(JNIEnv* env, jclass this, jlong address) +{ + LPCWSTR lpFileName = jlong_to_ptr(address); + if (RemoveDirectoryW(lpFileName) == 0) { + throwWindowsException(env, GetLastError()); + } +} + +JNIEXPORT void JNICALL +Java_sun_nio_fs_WindowsNativeDispatcher_CloseHandle(JNIEnv* env, jclass this, + jlong handle) +{ + HANDLE h = (HANDLE)jlong_to_ptr(handle); + CloseHandle(h); +} + +JNIEXPORT void JNICALL +Java_sun_nio_fs_WindowsNativeDispatcher_FindFirstFile0(JNIEnv* env, jclass this, + jlong address, jobject obj) +{ + WIN32_FIND_DATAW data; + LPCWSTR lpFileName = jlong_to_ptr(address); + + HANDLE handle = FindFirstFileW(lpFileName, &data); + if (handle != INVALID_HANDLE_VALUE) { + jstring name = (*env)->NewString(env, data.cFileName, wcslen(data.cFileName)); + if (name == NULL) + return; + (*env)->SetLongField(env, obj, findFirst_handle, ptr_to_jlong(handle)); + (*env)->SetObjectField(env, obj, findFirst_name, name); + } else { + throwWindowsException(env, GetLastError()); + } +} + +JNIEXPORT jlong JNICALL +Java_sun_nio_fs_WindowsNativeDispatcher_FindFirstFile1(JNIEnv* env, jclass this, + jlong pathAddress, jlong dataAddress) +{ + LPCWSTR lpFileName = jlong_to_ptr(pathAddress); + WIN32_FIND_DATAW* data = (WIN32_FIND_DATAW*)jlong_to_ptr(dataAddress); + + HANDLE handle = FindFirstFileW(lpFileName, data); + if (handle == INVALID_HANDLE_VALUE) { + throwWindowsException(env, GetLastError()); + } + return ptr_to_jlong(handle); +} + +JNIEXPORT jstring JNICALL +Java_sun_nio_fs_WindowsNativeDispatcher_FindNextFile(JNIEnv* env, jclass this, + jlong handle, jlong dataAddress) +{ + HANDLE h = (HANDLE)jlong_to_ptr(handle); + WIN32_FIND_DATAW* data = (WIN32_FIND_DATAW*)jlong_to_ptr(dataAddress); + + if (FindNextFileW(h, data) != 0) { + return (*env)->NewString(env, data->cFileName, wcslen(data->cFileName)); + } else { + if (GetLastError() != ERROR_NO_MORE_FILES) + throwWindowsException(env, GetLastError()); + return NULL; + } +} + +JNIEXPORT void JNICALL +Java_sun_nio_fs_WindowsNativeDispatcher_FindFirstStream0(JNIEnv* env, jclass this, + jlong address, jobject obj) +{ + MY_WIN32_FIND_STREAM_DATA data; + LPCWSTR lpFileName = jlong_to_ptr(address); + HANDLE handle; + + if (FindFirstStream_func == NULL) { + JNU_ThrowInternalError(env, "Should not get here"); + return; + } + + handle = (*FindFirstStream_func)(lpFileName, FindStreamInfoStandard, &data, 0); + if (handle != INVALID_HANDLE_VALUE) { + jstring name = (*env)->NewString(env, data.cStreamName, wcslen(data.cStreamName)); + if (name == NULL) + return; + (*env)->SetLongField(env, obj, findStream_handle, ptr_to_jlong(handle)); + (*env)->SetObjectField(env, obj, findStream_name, name); + } else { + if (GetLastError() == ERROR_HANDLE_EOF) { + (*env)->SetLongField(env, obj, findStream_handle, ptr_to_jlong(handle)); + } else { + throwWindowsException(env, GetLastError()); + } + } + +} + +JNIEXPORT jstring JNICALL +Java_sun_nio_fs_WindowsNativeDispatcher_FindNextStream(JNIEnv* env, jclass this, + jlong handle) +{ + MY_WIN32_FIND_STREAM_DATA data; + HANDLE h = (HANDLE)jlong_to_ptr(handle); + + if (FindNextStream_func == NULL) { + JNU_ThrowInternalError(env, "Should not get here"); + return NULL; + } + + if ((*FindNextStream_func)(h, &data) != 0) { + return (*env)->NewString(env, data.cStreamName, wcslen(data.cStreamName)); + } else { + if (GetLastError() != ERROR_HANDLE_EOF) + throwWindowsException(env, GetLastError()); + return NULL; + } +} + + +JNIEXPORT void JNICALL +Java_sun_nio_fs_WindowsNativeDispatcher_FindClose(JNIEnv* env, jclass this, + jlong handle) +{ + HANDLE h = (HANDLE)jlong_to_ptr(handle); + if (FindClose(h) == 0) { + throwWindowsException(env, GetLastError()); + } +} + + +JNIEXPORT void JNICALL +Java_sun_nio_fs_WindowsNativeDispatcher_GetFileInformationByHandle(JNIEnv* env, jclass this, + jlong handle, jlong address) +{ + HANDLE h = (HANDLE)jlong_to_ptr(handle); + BY_HANDLE_FILE_INFORMATION* info = + (BY_HANDLE_FILE_INFORMATION*)jlong_to_ptr(address); + if (GetFileInformationByHandle(h, info) == 0) { + throwWindowsException(env, GetLastError()); + } +} + + +JNIEXPORT void JNICALL +Java_sun_nio_fs_WindowsNativeDispatcher_CopyFileEx0(JNIEnv* env, jclass this, + jlong existingAddress, jlong newAddress, jint flags, jlong cancelAddress) +{ + LPCWSTR lpExistingFileName = jlong_to_ptr(existingAddress); + LPCWSTR lpNewFileName = jlong_to_ptr(newAddress); + LPBOOL cancel = (LPBOOL)jlong_to_ptr(cancelAddress); + if (CopyFileExW(lpExistingFileName, lpNewFileName, NULL, NULL, cancel, + (DWORD)flags) == 0) + { + throwWindowsException(env, GetLastError()); + } +} + +JNIEXPORT void JNICALL +Java_sun_nio_fs_WindowsNativeDispatcher_MoveFileEx0(JNIEnv* env, jclass this, + jlong existingAddress, jlong newAddress, jint flags) +{ + LPCWSTR lpExistingFileName = jlong_to_ptr(existingAddress); + LPCWSTR lpNewFileName = jlong_to_ptr(newAddress); + if (MoveFileExW(lpExistingFileName, lpNewFileName, (DWORD)flags) == 0) { + throwWindowsException(env, GetLastError()); + } +} + +JNIEXPORT jint JNICALL +Java_sun_nio_fs_WindowsNativeDispatcher_GetLogicalDrives(JNIEnv* env, jclass this) +{ + DWORD res = GetLogicalDrives(); + if (res == 0) { + throwWindowsException(env, GetLastError()); + } + return (jint)res; +} + +JNIEXPORT jint JNICALL +Java_sun_nio_fs_WindowsNativeDispatcher_GetFileAttributes0(JNIEnv* env, jclass this, + jlong address) +{ + LPCWSTR lpFileName = jlong_to_ptr(address); + DWORD value = GetFileAttributesW(lpFileName); + + if (value == INVALID_FILE_ATTRIBUTES) { + throwWindowsException(env, GetLastError()); + } + return (jint)value; +} + +JNIEXPORT void JNICALL +Java_sun_nio_fs_WindowsNativeDispatcher_SetFileAttributes0(JNIEnv* env, jclass this, + jlong address, jint value) +{ + LPCWSTR lpFileName = jlong_to_ptr(address); + if (SetFileAttributesW(lpFileName, (DWORD)value) == 0) { + throwWindowsException(env, GetLastError()); + } +} + +JNIEXPORT void JNICALL +Java_sun_nio_fs_WindowsNativeDispatcher_GetFileAttributesEx0(JNIEnv* env, jclass this, + jlong pathAddress, jlong dataAddress) +{ + LPCWSTR lpFileName = jlong_to_ptr(pathAddress); + WIN32_FILE_ATTRIBUTE_DATA* data = (WIN32_FILE_ATTRIBUTE_DATA*)jlong_to_ptr(dataAddress); + + BOOL res = GetFileAttributesExW(lpFileName, GetFileExInfoStandard, (LPVOID)data); + if (res == 0) + throwWindowsException(env, GetLastError()); +} + + +JNIEXPORT void JNICALL +Java_sun_nio_fs_WindowsNativeDispatcher_SetFileTime(JNIEnv* env, jclass this, + jlong handle, jlong createTime, jlong lastAccessTime, jlong lastWriteTime) +{ + HANDLE h = (HANDLE)jlong_to_ptr(handle); + + if (SetFileTime(h, + (createTime == (jlong)0) ? NULL : (CONST FILETIME *)&createTime, + (lastAccessTime == (jlong)0) ? NULL : (CONST FILETIME *)&lastAccessTime, + (lastWriteTime == (jlong)0) ? NULL : (CONST FILETIME *)&lastWriteTime) == 0) + { + throwWindowsException(env, GetLastError()); + } +} + +JNIEXPORT void JNICALL +Java_sun_nio_fs_WindowsNativeDispatcher_SetEndOfFile(JNIEnv* env, jclass this, + jlong handle) +{ + HANDLE h = (HANDLE)jlong_to_ptr(handle); + + if (SetEndOfFile(h) == 0) + throwWindowsException(env, GetLastError()); +} + + +JNIEXPORT void JNICALL +Java_sun_nio_fs_WindowsNativeDispatcher_GetVolumeInformation0(JNIEnv* env, jclass this, + jlong address, jobject obj) +{ + WCHAR volumeName[MAX_PATH+1]; + DWORD volumeSerialNumber; + DWORD maxComponentLength; + DWORD flags; + WCHAR fileSystemName[MAX_PATH+1]; + LPCWSTR lpFileName = jlong_to_ptr(address); + jstring str; + + BOOL res = GetVolumeInformationW(lpFileName, + &volumeName[0], + MAX_PATH+1, + &volumeSerialNumber, + &maxComponentLength, + &flags, + &fileSystemName[0], + MAX_PATH+1); + if (res == 0) { + throwWindowsException(env, GetLastError()); + return; + } + + str = (*env)->NewString(env, (const jchar *)fileSystemName, (jsize)wcslen(fileSystemName)); + if (str == NULL) return; + (*env)->SetObjectField(env, obj, volumeInfo_fsName, str); + + str = (*env)->NewString(env, (const jchar *)volumeName, (jsize)wcslen(volumeName)); + if (str == NULL) return; + (*env)->SetObjectField(env, obj, volumeInfo_volName, str); + + (*env)->SetIntField(env, obj, volumeInfo_volSN, (jint)volumeSerialNumber); + (*env)->SetIntField(env, obj, volumeInfo_flags, (jint)flags); +} + + +JNIEXPORT jint JNICALL +Java_sun_nio_fs_WindowsNativeDispatcher_GetDriveType0(JNIEnv* env, jclass this, jlong address) { + LPCWSTR lpRootPathName = jlong_to_ptr(address); + return (jint)GetDriveTypeW(lpRootPathName); +} + + +JNIEXPORT void JNICALL +Java_sun_nio_fs_WindowsNativeDispatcher_GetDiskFreeSpaceEx0(JNIEnv* env, jclass this, + jlong address, jobject obj) +{ + ULARGE_INTEGER freeBytesAvailable; + ULARGE_INTEGER totalNumberOfBytes; + ULARGE_INTEGER totalNumberOfFreeBytes; + LPCWSTR lpDirName = jlong_to_ptr(address); + + + BOOL res = GetDiskFreeSpaceExW(lpDirName, + &freeBytesAvailable, + &totalNumberOfBytes, + &totalNumberOfFreeBytes); + if (res == 0) { + throwWindowsException(env, GetLastError()); + return; + } + + (*env)->SetLongField(env, obj, diskSpace_bytesAvailable, + long_to_jlong(freeBytesAvailable.QuadPart)); + (*env)->SetLongField(env, obj, diskSpace_totalBytes, + long_to_jlong(totalNumberOfBytes.QuadPart)); + (*env)->SetLongField(env, obj, diskSpace_totalFree, + long_to_jlong(totalNumberOfFreeBytes.QuadPart)); +} + + +JNIEXPORT jstring JNICALL +Java_sun_nio_fs_WindowsNativeDispatcher_GetVolumePathName0(JNIEnv* env, jclass this, + jlong address) +{ + WCHAR volumeName[MAX_PATH+1]; + LPCWSTR lpFileName = jlong_to_ptr(address); + + + BOOL res = GetVolumePathNameW(lpFileName, + &volumeName[0], + MAX_PATH+1); + if (res == 0) { + throwWindowsException(env, GetLastError()); + return NULL; + } else { + return (*env)->NewString(env, (const jchar *)volumeName, (jsize)wcslen(volumeName)); + } +} + +JNIEXPORT void JNICALL +Java_sun_nio_fs_WindowsNativeDispatcher_InitializeSecurityDescriptor(JNIEnv* env, jclass this, + jlong address) +{ + PSECURITY_DESCRIPTOR pSecurityDescriptor = + (PSECURITY_DESCRIPTOR)jlong_to_ptr(address); + + if (InitializeSecurityDescriptor(pSecurityDescriptor, SECURITY_DESCRIPTOR_REVISION) == 0) { + throwWindowsException(env, GetLastError()); + } +} + +JNIEXPORT void JNICALL +Java_sun_nio_fs_WindowsNativeDispatcher_InitializeAcl(JNIEnv* env, jclass this, + jlong address, jint size) +{ + PACL pAcl = (PACL)jlong_to_ptr(address); + + if (InitializeAcl(pAcl, (DWORD)size, ACL_REVISION) == 0) { + throwWindowsException(env, GetLastError()); + } +} + + +JNIEXPORT void JNICALL +Java_sun_nio_fs_WindowsNativeDispatcher_SetFileSecurity0(JNIEnv* env, jclass this, + jlong pathAddress, jint requestedInformation, jlong descAddress) +{ + LPCWSTR lpFileName = jlong_to_ptr(pathAddress); + PSECURITY_DESCRIPTOR pSecurityDescriptor = jlong_to_ptr(descAddress); + DWORD lengthNeeded = 0; + + BOOL res = SetFileSecurityW(lpFileName, + (SECURITY_INFORMATION)requestedInformation, + pSecurityDescriptor); + + if (res == 0) { + throwWindowsException(env, GetLastError()); + } +} + +JNIEXPORT jint JNICALL +Java_sun_nio_fs_WindowsNativeDispatcher_GetFileSecurity0(JNIEnv* env, jclass this, + jlong pathAddress, jint requestedInformation, jlong descAddress, jint nLength) +{ + LPCWSTR lpFileName = jlong_to_ptr(pathAddress); + PSECURITY_DESCRIPTOR pSecurityDescriptor = jlong_to_ptr(descAddress); + DWORD lengthNeeded = 0; + + BOOL res = GetFileSecurityW(lpFileName, + (SECURITY_INFORMATION)requestedInformation, + pSecurityDescriptor, + (DWORD)nLength, + &lengthNeeded); + + if (res == 0) { + if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) { + return (jint)lengthNeeded; + } else { + throwWindowsException(env, GetLastError()); + return 0; + } + } else { + return (jint)nLength; + } +} + +JNIEXPORT jlong JNICALL +Java_sun_nio_fs_WindowsNativeDispatcher_GetSecurityDescriptorOwner(JNIEnv* env, + jclass this, jlong address) +{ + PSECURITY_DESCRIPTOR pSecurityDescriptor = jlong_to_ptr(address); + PSID pOwner; + BOOL bOwnerDefaulted; + + + if (GetSecurityDescriptorOwner(pSecurityDescriptor, &pOwner, &bOwnerDefaulted) == 0) { + throwWindowsException(env, GetLastError()); + } + return ptr_to_jlong(pOwner); +} + +JNIEXPORT void JNICALL +Java_sun_nio_fs_WindowsNativeDispatcher_SetSecurityDescriptorOwner(JNIEnv* env, + jclass this, jlong descAddress, jlong ownerAddress) +{ + PSECURITY_DESCRIPTOR pSecurityDescriptor = jlong_to_ptr(descAddress); + PSID pOwner = jlong_to_ptr(ownerAddress); + + if (SetSecurityDescriptorOwner(pSecurityDescriptor, pOwner, FALSE) == 0) { + throwWindowsException(env, GetLastError()); + } +} + + +JNIEXPORT jlong JNICALL +Java_sun_nio_fs_WindowsNativeDispatcher_GetSecurityDescriptorDacl(JNIEnv* env, + jclass this, jlong address) +{ + PSECURITY_DESCRIPTOR pSecurityDescriptor = jlong_to_ptr(address); + BOOL bDaclPresent; + PACL pDacl; + BOOL bDaclDefaulted; + + if (GetSecurityDescriptorDacl(pSecurityDescriptor, &bDaclPresent, &pDacl, &bDaclDefaulted) == 0) { + throwWindowsException(env, GetLastError()); + return (jlong)0; + } else { + return (bDaclPresent) ? ptr_to_jlong(pDacl) : (jlong)0; + } +} + +JNIEXPORT void JNICALL +Java_sun_nio_fs_WindowsNativeDispatcher_SetSecurityDescriptorDacl(JNIEnv* env, + jclass this, jlong descAddress, jlong aclAddress) +{ + PSECURITY_DESCRIPTOR pSecurityDescriptor = (PSECURITY_DESCRIPTOR)jlong_to_ptr(descAddress); + PACL pAcl = (PACL)jlong_to_ptr(aclAddress); + + if (SetSecurityDescriptorDacl(pSecurityDescriptor, TRUE, pAcl, FALSE) == 0) { + throwWindowsException(env, GetLastError()); + } +} + + +JNIEXPORT void JNICALL +Java_sun_nio_fs_WindowsNativeDispatcher_GetAclInformation0(JNIEnv* env, + jclass this, jlong address, jobject obj) +{ + PACL pAcl = (PACL)jlong_to_ptr(address); + ACL_SIZE_INFORMATION acl_size_info; + + if (GetAclInformation(pAcl, (void *) &acl_size_info, sizeof(acl_size_info), AclSizeInformation) == 0) { + throwWindowsException(env, GetLastError()); + } else { + (*env)->SetIntField(env, obj, aclInfo_aceCount, (jint)acl_size_info.AceCount); + } +} + +JNIEXPORT jlong JNICALL +Java_sun_nio_fs_WindowsNativeDispatcher_GetAce(JNIEnv* env, jclass this, jlong address, + jint aceIndex) +{ + PACL pAcl = (PACL)jlong_to_ptr(address); + LPVOID pAce; + + if (GetAce(pAcl, (DWORD)aceIndex, &pAce) == 0) { + throwWindowsException(env, GetLastError()); + return (jlong)0; + } else { + return ptr_to_jlong(pAce); + } +} + +JNIEXPORT void JNICALL +Java_sun_nio_fs_WindowsNativeDispatcher_AddAccessAllowedAceEx(JNIEnv* env, + jclass this, jlong aclAddress, jint flags, jint mask, jlong sidAddress) +{ + PACL pAcl = (PACL)jlong_to_ptr(aclAddress); + PSID pSid = (PSID)jlong_to_ptr(sidAddress); + + if (AddAccessAllowedAceEx(pAcl, ACL_REVISION, (DWORD)flags, (DWORD)mask, pSid) == 0) { + throwWindowsException(env, GetLastError()); + } +} + +JNIEXPORT void JNICALL +Java_sun_nio_fs_WindowsNativeDispatcher_AddAccessDeniedAceEx(JNIEnv* env, + jclass this, jlong aclAddress, jint flags, jint mask, jlong sidAddress) +{ + PACL pAcl = (PACL)jlong_to_ptr(aclAddress); + PSID pSid = (PSID)jlong_to_ptr(sidAddress); + + if (AddAccessDeniedAceEx(pAcl, ACL_REVISION, (DWORD)flags, (DWORD)mask, pSid) == 0) { + throwWindowsException(env, GetLastError()); + } +} + + +JNIEXPORT void JNICALL +Java_sun_nio_fs_WindowsNativeDispatcher_LookupAccountSid0(JNIEnv* env, + jclass this, jlong address, jobject obj) +{ + WCHAR domain[255]; + WCHAR name[255]; + DWORD domainLen = sizeof(domain); + DWORD nameLen = sizeof(name); + SID_NAME_USE use; + PSID sid = jlong_to_ptr(address); + jstring s; + + if (LookupAccountSidW(NULL, sid, &name[0], &nameLen, &domain[0], &domainLen, &use) == 0) { + throwWindowsException(env, GetLastError()); + return; + } + + s = (*env)->NewString(env, (const jchar *)domain, (jsize)wcslen(domain)); + if (s == NULL) + return; + (*env)->SetObjectField(env, obj, account_domain, s); + + s = (*env)->NewString(env, (const jchar *)name, (jsize)wcslen(name)); + if (s == NULL) + return; + (*env)->SetObjectField(env, obj, account_name, s); + (*env)->SetIntField(env, obj, account_use, (jint)use); +} + +JNIEXPORT jint JNICALL +Java_sun_nio_fs_WindowsNativeDispatcher_LookupAccountName0(JNIEnv* env, + jclass this, jlong nameAddress, jlong sidAddress, jint cbSid) +{ + + LPCWSTR accountName = jlong_to_ptr(nameAddress); + PSID sid = jlong_to_ptr(sidAddress); + WCHAR domain[255]; + DWORD domainLen = sizeof(domain); + SID_NAME_USE use; + + if (LookupAccountNameW(NULL, accountName, sid, (LPDWORD)&cbSid, + &domain[0], &domainLen, &use) == 0) + { + if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) { + throwWindowsException(env, GetLastError()); + } + } + + return cbSid; +} + +JNIEXPORT jint JNICALL +Java_sun_nio_fs_WindowsNativeDispatcher_GetLengthSid(JNIEnv* env, + jclass this, jlong address) +{ + PSID sid = jlong_to_ptr(address); + + if (GetLengthSid_func == NULL) { + JNU_ThrowInternalError(env, "Should not get here"); + return 0; + } + return (jint)(*GetLengthSid_func)(sid); +} + + +JNIEXPORT jstring JNICALL +Java_sun_nio_fs_WindowsNativeDispatcher_ConvertSidToStringSid(JNIEnv* env, + jclass this, jlong address) +{ + PSID sid = jlong_to_ptr(address); + LPWSTR string; + + if (ConvertSidToStringSid_func == NULL) { + JNU_ThrowInternalError(env, "Should not get here"); + return NULL; + } + + if ((*ConvertSidToStringSid_func)(sid, &string) == 0) { + throwWindowsException(env, GetLastError()); + return NULL; + } else { + jstring s = (*env)->NewString(env, (const jchar *)string, + (jsize)wcslen(string)); + LocalFree(string); + return s; + } +} + +JNIEXPORT jlong JNICALL +Java_sun_nio_fs_WindowsNativeDispatcher_ConvertStringSidToSid0(JNIEnv* env, + jclass this, jlong address) +{ + LPWSTR lpStringSid = jlong_to_ptr(address); + PSID pSid; + + if (ConvertStringSidToSid_func == NULL) { + JNU_ThrowInternalError(env, "Should not get here"); + return (jlong)0; + } + + if ((*ConvertStringSidToSid_func)(lpStringSid, &pSid) == 0) + throwWindowsException(env, GetLastError()); + + return ptr_to_jlong(pSid); +} + +JNIEXPORT jlong JNICALL +Java_sun_nio_fs_WindowsNativeDispatcher_GetCurrentProcess(JNIEnv* env, jclass this) { + HANDLE hProcess = GetCurrentProcess(); + return ptr_to_jlong(hProcess); +} + +JNIEXPORT jlong JNICALL +Java_sun_nio_fs_WindowsNativeDispatcher_GetCurrentThread(JNIEnv* env, jclass this) { + HANDLE hThread = GetCurrentThread(); + return ptr_to_jlong(hThread); +} + +JNIEXPORT jlong JNICALL +Java_sun_nio_fs_WindowsNativeDispatcher_OpenProcessToken(JNIEnv* env, + jclass this, jlong process, jint desiredAccess) +{ + HANDLE hProcess = (HANDLE)jlong_to_ptr(process); + HANDLE hToken; + + if (OpenProcessToken(hProcess, (DWORD)desiredAccess, &hToken) == 0) + throwWindowsException(env, GetLastError()); + return ptr_to_jlong(hToken); +} + +JNIEXPORT jlong JNICALL +Java_sun_nio_fs_WindowsNativeDispatcher_OpenThreadToken(JNIEnv* env, + jclass this, jlong thread, jint desiredAccess, jboolean openAsSelf) +{ + HANDLE hThread = (HANDLE)jlong_to_ptr(thread); + HANDLE hToken; + BOOL bOpenAsSelf = (openAsSelf == JNI_TRUE) ? TRUE : FALSE; + + if (OpenThreadToken(hThread, (DWORD)desiredAccess, bOpenAsSelf, &hToken) == 0) { + if (GetLastError() == ERROR_NO_TOKEN) + return (jlong)0; + throwWindowsException(env, GetLastError()); + } + return ptr_to_jlong(hToken); +} + +JNIEXPORT jlong JNICALL +Java_sun_nio_fs_WindowsNativeDispatcher_DuplicateTokenEx(JNIEnv* env, + jclass this, jlong token, jint desiredAccess) +{ + HANDLE hToken = (HANDLE)jlong_to_ptr(token); + HANDLE resultToken; + BOOL res; + + res = DuplicateTokenEx(hToken, + (DWORD)desiredAccess, + NULL, + SecurityImpersonation, + TokenImpersonation, + &resultToken); + if (res == 0) + throwWindowsException(env, GetLastError()); + return ptr_to_jlong(resultToken); +} + +JNIEXPORT void JNICALL +Java_sun_nio_fs_WindowsNativeDispatcher_SetThreadToken(JNIEnv* env, + jclass this, jlong thread, jlong token) +{ + HANDLE hThread = (HANDLE)jlong_to_ptr(thread); + HANDLE hToken = (HANDLE)jlong_to_ptr(token); + + if (SetThreadToken(hThread, hToken) == 0) + throwWindowsException(env, GetLastError()); +} + +JNIEXPORT jint JNICALL +Java_sun_nio_fs_WindowsNativeDispatcher_GetTokenInformation(JNIEnv* env, + jclass this, jlong token, jint tokenInfoClass, jlong tokenInfo, jint tokenInfoLength) +{ + BOOL res; + DWORD lengthNeeded; + HANDLE hToken = (HANDLE)jlong_to_ptr(token); + LPVOID result = (LPVOID)jlong_to_ptr(tokenInfo); + + res = GetTokenInformation(hToken, (TOKEN_INFORMATION_CLASS)tokenInfoClass, (LPVOID)result, + tokenInfoLength, &lengthNeeded); + if (res == 0) { + if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) { + return (jint)lengthNeeded; + } else { + throwWindowsException(env, GetLastError()); + return 0; + } + } else { + return tokenInfoLength; + } +} + +JNIEXPORT void JNICALL +Java_sun_nio_fs_WindowsNativeDispatcher_AdjustTokenPrivileges(JNIEnv* env, + jclass this, jlong token, jlong luid, jint attributes) +{ + TOKEN_PRIVILEGES privs[1]; + HANDLE hToken = (HANDLE)jlong_to_ptr(token); + PLUID pLuid = (PLUID)jlong_to_ptr(luid); + + privs[0].PrivilegeCount = 1; + privs[0].Privileges[0].Luid = *pLuid; + privs[0].Privileges[0].Attributes = (DWORD)attributes; + + if (AdjustTokenPrivileges(hToken, FALSE, &privs[0], 1, NULL, NULL) == 0) + throwWindowsException(env, GetLastError()); +} + +JNIEXPORT jlong JNICALL +Java_sun_nio_fs_WindowsNativeDispatcher_LookupPrivilegeValue0(JNIEnv* env, + jclass this, jlong name) +{ + LPCWSTR lpName = (LPCWSTR)jlong_to_ptr(name); + PLUID pLuid = LocalAlloc(0, sizeof(LUID)); + + if (pLuid == NULL) { + JNU_ThrowInternalError(env, "Unable to allocate LUID structure"); + } else { + if (LookupPrivilegeValueW(NULL, lpName, pLuid) == 0) + throwWindowsException(env, GetLastError()); + } + return ptr_to_jlong(pLuid); +} + +JNIEXPORT jlong JNICALL +Java_sun_nio_fs_WindowsNativeDispatcher_BuildTrusteeWithSid(JNIEnv* env, + jclass this, jlong sid) +{ + PSID pSid = (HANDLE)jlong_to_ptr(sid); + PTRUSTEE_W pTrustee = LocalAlloc(0, sizeof(TRUSTEE_W)); + + if (pTrustee == NULL) { + JNU_ThrowInternalError(env, "Unable to allocate TRUSTEE_W structure"); + } else { + BuildTrusteeWithSidW(pTrustee, pSid); + } + return ptr_to_jlong(pTrustee); +} + +JNIEXPORT jint JNICALL +Java_sun_nio_fs_WindowsNativeDispatcher_GetEffectiveRightsFromAcl(JNIEnv* env, + jclass this, jlong acl, jlong trustee) +{ + ACCESS_MASK access; + PACL pAcl = (PACL)jlong_to_ptr(acl); + PTRUSTEE pTrustee = (PTRUSTEE)jlong_to_ptr(trustee); + + if (GetEffectiveRightsFromAcl(pAcl, pTrustee, &access) != ERROR_SUCCESS) { + throwWindowsException(env, GetLastError()); + } + return (jint)access; +} + +JNIEXPORT void JNICALL +Java_sun_nio_fs_WindowsNativeDispatcher_CreateSymbolicLink0(JNIEnv* env, + jclass this, jlong linkAddress, jlong targetAddress, jint flags) +{ + LPCWSTR link = jlong_to_ptr(linkAddress); + LPCWSTR target = jlong_to_ptr(targetAddress); + + if (CreateSymbolicLink_func == NULL) { + JNU_ThrowInternalError(env, "Should not get here"); + return; + } + + /* On Windows 64-bit this appears to succeed even when there is insufficient privileges */ + if ((*CreateSymbolicLink_func)(link, target, (DWORD)flags) == 0) + throwWindowsException(env, GetLastError()); +} + +JNIEXPORT void JNICALL +Java_sun_nio_fs_WindowsNativeDispatcher_CreateHardLink0(JNIEnv* env, + jclass this, jlong newFileAddress, jlong existingFileAddress) +{ + LPCWSTR newFile = jlong_to_ptr(newFileAddress); + LPCWSTR existingFile = jlong_to_ptr(existingFileAddress); + + if (CreateHardLink_func == NULL) { + JNU_ThrowInternalError(env, "Should not get here"); + return; + } + if ((*CreateHardLink_func)(newFile, existingFile, NULL) == 0) + throwWindowsException(env, GetLastError()); +} + +JNIEXPORT jstring JNICALL +Java_sun_nio_fs_WindowsNativeDispatcher_GetFullPathName0(JNIEnv *env, + jclass clz, + jlong pathAddress) +{ + jstring rv = NULL; + WCHAR *lpBuf = NULL; + WCHAR buf[MAX_PATH]; + DWORD len; + LPCWSTR lpFileName = jlong_to_ptr(pathAddress); + + len = GetFullPathNameW(lpFileName, MAX_PATH, buf, NULL); + if (len > 0) { + if (len < MAX_PATH) { + rv = (*env)->NewString(env, buf, len); + } else { + len += 1; /* return length does not include terminator */ + lpBuf = (WCHAR*)malloc(len * sizeof(WCHAR)); + if (lpBuf != NULL) { + len = GetFullPathNameW(lpFileName, len, lpBuf, NULL); + if (len > 0) { + rv = (*env)->NewString(env, lpBuf, len); + } else { + JNU_ThrowInternalError(env, "GetFullPathNameW failed"); + } + free(lpBuf); + } + } + } + if (len == 0) + throwWindowsException(env, GetLastError()); + + return rv; +} + +JNIEXPORT jstring JNICALL +Java_sun_nio_fs_WindowsNativeDispatcher_GetFinalPathNameByHandle(JNIEnv* env, + jclass this, jlong handle) +{ + jstring rv = NULL; + WCHAR *lpBuf = NULL; + WCHAR path[MAX_PATH]; + HANDLE h = (HANDLE)jlong_to_ptr(handle); + DWORD len; + + if (GetFinalPathNameByHandle_func == NULL) { + JNU_ThrowInternalError(env, "Should not get here"); + return NULL; + } + + len = (*GetFinalPathNameByHandle_func)(h, path, MAX_PATH, 0); + if (len > 0) { + if (len < MAX_PATH) { + rv = (*env)->NewString(env, (const jchar *)path, (jsize)len); + } else { + len += 1; /* return length does not include terminator */ + lpBuf = (WCHAR*)malloc(len * sizeof(WCHAR)); + if (lpBuf != NULL) { + len = (*GetFinalPathNameByHandle_func)(h, lpBuf, len, 0); + if (len > 0) { + rv = (*env)->NewString(env, (const jchar *)lpBuf, (jsize)len); + } else { + JNU_ThrowInternalError(env, "GetFinalPathNameByHandleW failed"); + } + free(lpBuf); + } + } + } + + if (len == 0) + throwWindowsException(env, GetLastError()); + + return rv; +} + +JNIEXPORT jlong JNICALL +Java_sun_nio_fs_WindowsNativeDispatcher_CreateIoCompletionPort(JNIEnv* env, jclass this, + jlong fileHandle, jlong existingPort, jint completionKey) +{ + HANDLE port = CreateIoCompletionPort((HANDLE)jlong_to_ptr(fileHandle), + (HANDLE)jlong_to_ptr(existingPort), + (DWORD)completionKey, + 0); + if (port == NULL) { + throwWindowsException(env, GetLastError()); + } + return ptr_to_jlong(port); +} + +JNIEXPORT void JNICALL +Java_sun_nio_fs_WindowsNativeDispatcher_GetQueuedCompletionStatus0(JNIEnv* env, jclass this, + jlong completionPort, jobject obj) +{ + DWORD bytesTransferred; + DWORD completionKey; + OVERLAPPED *lpOverlapped; + BOOL res; + + res = GetQueuedCompletionStatus((HANDLE)jlong_to_ptr(completionPort), + &bytesTransferred, + &completionKey, + &lpOverlapped, + INFINITE); + if (res == 0 && lpOverlapped == NULL) { + throwWindowsException(env, GetLastError()); + } else { + DWORD ioResult = (res == 0) ? GetLastError() : 0; + (*env)->SetIntField(env, obj, completionStatus_error, ioResult); + (*env)->SetIntField(env, obj, completionStatus_bytesTransferred, + (jint)bytesTransferred); + (*env)->SetIntField(env, obj, completionStatus_completionKey, + (jint)completionKey); + + } +} + +JNIEXPORT void JNICALL +Java_sun_nio_fs_WindowsNativeDispatcher_PostQueuedCompletionStatus(JNIEnv* env, jclass this, + jlong completionPort, jint completionKey) +{ + BOOL res; + + res = PostQueuedCompletionStatus((HANDLE)jlong_to_ptr(completionPort), + (DWORD)0, /* dwNumberOfBytesTransferred */ + (DWORD)completionKey, + NULL); /* lpOverlapped */ + if (res == 0) { + throwWindowsException(env, GetLastError()); + } +} + +JNIEXPORT void JNICALL +Java_sun_nio_fs_WindowsNativeDispatcher_ReadDirectoryChangesW(JNIEnv* env, jclass this, + jlong hDirectory, jlong bufferAddress, jint bufferLength, jboolean watchSubTree, jint filter, + jlong bytesReturnedAddress, jlong pOverlapped) +{ + BOOL res; + BOOL subtree = (watchSubTree == JNI_TRUE) ? TRUE : FALSE; + + ((LPOVERLAPPED)jlong_to_ptr(pOverlapped))->hEvent = NULL; + res = ReadDirectoryChangesW((HANDLE)jlong_to_ptr(hDirectory), + (LPVOID)jlong_to_ptr(bufferAddress), + (DWORD)bufferLength, + subtree, + (DWORD)filter, + (LPDWORD)jlong_to_ptr(bytesReturnedAddress), + (LPOVERLAPPED)jlong_to_ptr(pOverlapped), + NULL); + if (res == 0) { + throwWindowsException(env, GetLastError()); + } +} + +JNIEXPORT void JNICALL +Java_sun_nio_fs_WindowsNativeDispatcher_BackupRead0(JNIEnv* env, jclass this, + jlong hFile, jlong bufferAddress, jint bufferSize, jboolean abort, + jlong context, jobject obj) +{ + BOOL res; + DWORD bytesTransferred; + BOOL a = (abort == JNI_TRUE) ? TRUE : FALSE; + VOID* pContext = (VOID*)jlong_to_ptr(context); + + res = BackupRead((HANDLE)jlong_to_ptr(hFile), + (LPBYTE)jlong_to_ptr(bufferAddress), + (DWORD)bufferSize, + &bytesTransferred, + a, + FALSE, + &pContext); + if (res == 0) { + throwWindowsException(env, GetLastError()); + } else { + (*env)->SetIntField(env, obj, backupResult_bytesTransferred, + bytesTransferred); + (*env)->SetLongField(env, obj, backupResult_context, + ptr_to_jlong(pContext)); + } +} + +JNIEXPORT void JNICALL +Java_sun_nio_fs_WindowsNativeDispatcher_BackupSeek(JNIEnv* env, jclass this, + jlong hFile, jlong bytesToSeek, jlong context) +{ + BOOL res; + jint lowBytesToSeek = (jint)bytesToSeek; + jint highBytesToSeek = (jint)(bytesToSeek >> 32); + DWORD lowBytesSeeked; + DWORD highBytesSeeked; + VOID* pContext = jlong_to_ptr(context); + + res = BackupSeek((HANDLE)jlong_to_ptr(hFile), + (DWORD)lowBytesToSeek, + (DWORD)highBytesToSeek, + &lowBytesSeeked, + &highBytesSeeked, + &pContext); + if (res == 0) { + throwWindowsException(env, GetLastError()); + } +} diff --git a/src/windows/native/sun/windows/ShellFolder2.cpp b/src/windows/native/sun/windows/ShellFolder2.cpp index 3baf5bcf9b907ccce53ec718404d0b607ffcfea9..6799b098218e96c19672b25447d8c2f88485856f 100644 --- a/src/windows/native/sun/windows/ShellFolder2.cpp +++ b/src/windows/native/sun/windows/ShellFolder2.cpp @@ -225,6 +225,34 @@ JNIEXPORT void JNICALL Java_sun_awt_shell_Win32ShellFolder2_initIDs FID_folderType = env->GetFieldID(cls, "folderType", "Ljava/lang/String;"); } + +/* +* Class: sun_awt_shell_Win32ShellFolderManager2 +* Method: initializeCom +* Signature: ()V +*/ +JNIEXPORT void JNICALL Java_sun_awt_shell_Win32ShellFolderManager2_initializeCom + (JNIEnv* env, jclass cls) +{ + HRESULT hr = ::CoInitialize(NULL); + if (FAILED(hr)) { + char c[64]; + sprintf(c, "Could not initialize COM: HRESULT=0x%08X", hr); + JNU_ThrowInternalError(env, c); + } +} + +/* +* Class: sun_awt_shell_Win32ShellFolderManager2 +* Method: uninitializeCom +* Signature: ()V +*/ +JNIEXPORT void JNICALL Java_sun_awt_shell_Win32ShellFolderManager2_uninitializeCom + (JNIEnv* env, jclass cls) +{ + ::CoUninitialize(); +} + static IShellIcon* getIShellIcon(IShellFolder* pIShellFolder) { // http://msdn.microsoft.com/library/en-us/shellcc/platform/Shell/programmersguide/shell_int/shell_int_programming/std_ifaces.asp HRESULT hres; @@ -239,29 +267,6 @@ static IShellIcon* getIShellIcon(IShellFolder* pIShellFolder) { return (IShellIcon*)NULL; } -// Fixed 6263669 -// -// CoInitialize wrapper -// call CoInitialize to initialize COM in STA mode and check result -// RPC_E_CHANGED_MODE means COM has already been initialized in MTA mode, -// so don't set the flag to call CoUninitialize later - -BOOL CoInit(BOOL& doCoUninit) { // returns TRUE if initialized successfully - switch(::CoInitialize(NULL)) { - case S_OK: - case S_FALSE: - doCoUninit = TRUE; - return TRUE; - break; - case RPC_E_CHANGED_MODE: - doCoUninit = FALSE; - return TRUE; - break; - default: - return FALSE; - } -} - /* * Class: sun_awt_shell_Win32ShellFolder2 @@ -507,10 +512,10 @@ JNIEXPORT jint JNICALL Java_sun_awt_shell_Win32ShellFolder2_getAttributes0 /* * Class: sun_awt_shell_Win32ShellFolder2 - * Method: getFileSystemPath + * Method: getFileSystemPath0 * Signature: (I)Ljava/lang/String; */ -JNIEXPORT jstring JNICALL Java_sun_awt_shell_Win32ShellFolder2_getFileSystemPath__I +JNIEXPORT jstring JNICALL Java_sun_awt_shell_Win32ShellFolder2_getFileSystemPath0 (JNIEnv* env, jclass cls, jint csidl) { LPITEMIDLIST relPIDL; @@ -611,18 +616,6 @@ JNIEXPORT jlong JNICALL Java_sun_awt_shell_Win32ShellFolder2_bindToObject if (SUCCEEDED (hr)) { return (jlong)pFolder; } - if (IS_WINVISTA) { - BOOL doCoUninit; - if (CoInit(doCoUninit)) { - hr = pParent->BindToObject(pidl, NULL, IID_IShellFolder, (void**)&pFolder); - if (doCoUninit) { - ::CoUninitialize(); - } - if (SUCCEEDED (hr)) { - return (jlong)pFolder; - } - } - } return 0; } @@ -650,7 +643,10 @@ JNIEXPORT jlong JNICALL Java_sun_awt_shell_Win32ShellFolder2_getLinkLocation return NULL; } - pParent->GetDisplayNameOf(pidl, SHGDN_NORMAL | SHGDN_FORPARSING, &strret); + hres = pParent->GetDisplayNameOf(pidl, SHGDN_NORMAL | SHGDN_FORPARSING, &strret); + if (FAILED(hres)) { + return NULL; + } switch (strret.uType) { case STRRET_CSTR : @@ -669,10 +665,6 @@ JNIEXPORT jlong JNICALL Java_sun_awt_shell_Win32ShellFolder2_getLinkLocation break; } - BOOL doCoUninit; - if (!CoInit(doCoUninit)) { - return 0; - } IShellLinkW* psl; hres = ::CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLinkW, (LPVOID *)&psl); if (SUCCEEDED(hres)) { @@ -692,10 +684,10 @@ JNIEXPORT jlong JNICALL Java_sun_awt_shell_Win32ShellFolder2_getLinkLocation } psl->Release(); } - if (doCoUninit) { - ::CoUninitialize(); - } + if (strret.uType == STRRET_WSTR) { + CoTaskMemFree(strret.pOleStr); + } if (SUCCEEDED(hres)) { return (jlong)pidl; } else { @@ -741,7 +733,7 @@ JNIEXPORT jlong JNICALL Java_sun_awt_shell_Win32ShellFolder2_parseDisplayName0 /* * Class: sun_awt_shell_Win32ShellFolder2 * Method: getDisplayNameOf - * Signature: (JJ)Ljava/lang/String; + * Signature: (JJI)Ljava/lang/String; */ JNIEXPORT jstring JNICALL Java_sun_awt_shell_Win32ShellFolder2_getDisplayNameOf (JNIEnv* env, jclass cls, jlong parentIShellFolder, jlong relativePIDL, jint attrs) @@ -758,7 +750,11 @@ JNIEXPORT jstring JNICALL Java_sun_awt_shell_Win32ShellFolder2_getDisplayNameOf if (pParent->GetDisplayNameOf(pidl, attrs, &strret) != S_OK) { return NULL; } - return jstringFromSTRRET(env, pidl, &strret); + jstring result = jstringFromSTRRET(env, pidl, &strret); + if (strret.uType == STRRET_WSTR) { + CoTaskMemFree(strret.pOleStr); + } + return result; } /* @@ -833,10 +829,6 @@ JNIEXPORT jint JNICALL Java_sun_awt_shell_Win32ShellFolder2_getIconIndex } INT index = -1; - BOOL doCoUninit; - if (!CoInit(doCoUninit)) { - return (jint)index; - } HRESULT hres; // http://msdn.microsoft.com/library/en-us/shellcc/platform/Shell/programmersguide/shell_int/shell_int_programming/std_ifaces.asp @@ -844,9 +836,6 @@ JNIEXPORT jint JNICALL Java_sun_awt_shell_Win32ShellFolder2_getIconIndex hres = pIShellIcon->GetIconOf(pidl, GIL_FORSHELL, &index); } - if (doCoUninit) { - ::CoUninitialize(); - } return (jint)index; } @@ -866,10 +855,6 @@ JNIEXPORT jlong JNICALL Java_sun_awt_shell_Win32ShellFolder2_extractIcon } HICON hIcon = NULL; - BOOL doCoUninit; - if (!CoInit(doCoUninit)) { - return (jlong)hIcon; - } HRESULT hres; IExtractIconW* pIcon; @@ -894,9 +879,6 @@ JNIEXPORT jlong JNICALL Java_sun_awt_shell_Win32ShellFolder2_extractIcon } pIcon->Release(); } - if (doCoUninit) { - ::CoUninitialize(); - } return (jlong)hIcon; } @@ -994,14 +976,10 @@ JNIEXPORT jintArray JNICALL Java_sun_awt_shell_Win32ShellFolder2_getFileChooserB HINSTANCE libComCtl32; HINSTANCE libShell32; - libShell32 = LoadLibrary(TEXT("shell32.dll")); if (libShell32 != NULL) { - long osVersion = GetVersion(); - BOOL isVista = (!(osVersion & 0x80000000) && (LOBYTE(LOWORD(osVersion)) >= 6)); - hBitmap = (HBITMAP)LoadImage(libShell32, - isVista ? TEXT("IDB_TB_SH_DEF_16") : MAKEINTRESOURCE(216), + IS_WINVISTA ? TEXT("IDB_TB_SH_DEF_16") : MAKEINTRESOURCE(216), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION); } if (hBitmap == NULL) { @@ -1095,46 +1073,6 @@ JNIEXPORT jlong JNICALL Java_sun_awt_shell_Win32ShellFolder2_getIconResource } -// Helper functions for workaround COM initialization: - -static HRESULT GetDetailsOfFolder( - IShellFolder2 *folder, - LPCITEMIDLIST pidl, - UINT column, - SHELLDETAILS *psd) -{ - HRESULT hr = folder->GetDetailsOf(pidl, column, psd); - if (IS_WINVISTA && FAILED (hr)) { - BOOL doCoUninit; - if (CoInit(doCoUninit)) { - hr = folder->GetDetailsOf(pidl, column, psd); - if (doCoUninit) { - ::CoUninitialize(); - } - } - } - return hr; -} - -static HRESULT GetDetailsOf( - IShellDetails *details, - LPCITEMIDLIST pidl, - UINT column, - SHELLDETAILS *psd) -{ - HRESULT hr = details->GetDetailsOf(pidl, column, psd); - if (IS_WINVISTA && FAILED (hr)) { - BOOL doCoUninit; - if (CoInit(doCoUninit)) { - hr = details->GetDetailsOf(pidl, column, psd); - if (doCoUninit) { - ::CoUninitialize(); - } - } - } - return hr; -} - /* * Helper function for creating Java column info object */ @@ -1187,7 +1125,7 @@ JNIEXPORT jobjectArray JNICALL int colNum = -1; hr = S_OK; do{ - hr = GetDetailsOfFolder(pIShellFolder2, NULL, ++colNum, &sd); + hr = pIShellFolder2->GetDetailsOf(NULL, ++colNum, &sd); } while (SUCCEEDED (hr)); jobjectArray columns = @@ -1202,7 +1140,7 @@ JNIEXPORT jobjectArray JNICALL colNum = 0; hr = S_OK; while (SUCCEEDED (hr)) { - hr = GetDetailsOfFolder(pIShellFolder2, NULL, colNum, &sd); + hr = pIShellFolder2->GetDetailsOf(NULL, colNum, &sd); if (SUCCEEDED (hr)) { hr = pIShellFolder2->GetDefaultColumnState(colNum, &csFlags); @@ -1232,7 +1170,7 @@ JNIEXPORT jobjectArray JNICALL int colNum = -1; hr = S_OK; do{ - hr = GetDetailsOf(pIShellDetails, NULL, ++colNum, &sd); + hr = pIShellDetails->GetDetailsOf(NULL, ++colNum, &sd); } while (SUCCEEDED (hr)); jobjectArray columns = @@ -1246,7 +1184,7 @@ JNIEXPORT jobjectArray JNICALL colNum = 0; hr = S_OK; while (SUCCEEDED (hr)) { - hr = GetDetailsOf(pIShellDetails, NULL, colNum, &sd); + hr = pIShellDetails->GetDetailsOf(NULL, colNum, &sd); if (SUCCEEDED (hr)) { jobject column = CreateColumnInfo(env, &columnClass, &columnConstructor, @@ -1288,7 +1226,7 @@ JNIEXPORT jobject JNICALL if(SUCCEEDED (hr)) { // The folder exposes IShellFolder2 interface IShellFolder2 *pIShellFolder2 = (IShellFolder2*) pIUnknown; - hr = GetDetailsOfFolder(pIShellFolder2, pidl, (UINT)columnIdx, &sd); + hr = pIShellFolder2->GetDetailsOf(pidl, (UINT)columnIdx, &sd); pIShellFolder2->Release(); if (SUCCEEDED (hr)) { STRRET strRet = sd.str; @@ -1300,7 +1238,7 @@ JNIEXPORT jobject JNICALL if(SUCCEEDED (hr)) { // The folder exposes IShellDetails interface IShellDetails *pIShellDetails = (IShellDetails*) pIUnknown; - hr = GetDetailsOf(pIShellDetails, pidl, (UINT)columnIdx, &sd); + hr = pIShellDetails->GetDetailsOf(pidl, (UINT)columnIdx, &sd); pIShellDetails->Release(); if (SUCCEEDED (hr)) { STRRET strRet = sd.str; diff --git a/src/windows/native/sun/windows/awt.rc b/src/windows/native/sun/windows/awt.rc index 2393b398cfca3f76c2ba2b93b4856451c37a5bfd..7eb4d41afb11ef46b9ea5d6adf2de1ec3c4b25fd 100644 --- a/src/windows/native/sun/windows/awt.rc +++ b/src/windows/native/sun/windows/awt.rc @@ -23,7 +23,7 @@ // have any questions. // -#include "afxres.h" +#include "windows.h" // Need 2 defines so macro argument to XSTR will get expanded before quoting. #define XSTR(x) STR(x) diff --git a/src/windows/resource/version.rc b/src/windows/resource/version.rc index 61311efabcfc33afdfd0e489ab2eeb46c631b600..41479562435315d4dfc528f9f9e658b5b14c125c 100644 --- a/src/windows/resource/version.rc +++ b/src/windows/resource/version.rc @@ -23,7 +23,7 @@ // have any questions. // -#include "afxres.h" +#include "windows.h" // Need 2 defines so macro argument to XSTR will get expanded before quoting. #define XSTR(x) STR(x) diff --git a/test/Makefile b/test/Makefile index 5435bf0a6148de008e9b2939552d67332f8d0ad0..775e7cbc91367fbd162fbf6ab331140071386771 100644 --- a/test/Makefile +++ b/test/Makefile @@ -1,12 +1,44 @@ # -# Makefile to run jtreg +# Copyright 1995-2008 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 to run various jdk tests # # Get OS/ARCH specifics OSNAME = $(shell uname -s) + +# Commands to run on paths to make mixed paths for java on windows +GETMIXEDPATH=echo + +# Location of developer shared files +SLASH_JAVA = /java + +# Platform specific settings ifeq ($(OSNAME), SunOS) PLATFORM = solaris - JCT_PLATFORM = solaris ARCH = $(shell uname -p) ifeq ($(ARCH), i386) ARCH=i586 @@ -14,97 +46,403 @@ ifeq ($(OSNAME), SunOS) endif ifeq ($(OSNAME), Linux) PLATFORM = linux - JCT_PLATFORM = linux ARCH = $(shell uname -m) ifeq ($(ARCH), i386) ARCH=i586 endif endif -ifeq ($(OSNAME), Windows_NT) + +# Cannot trust uname output +ifneq ($(PROCESSOR_IDENTIFIER), ) PLATFORM = windows - JCT_PLATFORM = win32 - ifeq ($(word 1, $(PROCESSOR_IDENTIFIER)),ia64) - ARCH=ia64 + SLASH_JAVA = J: + # A variety of ways to say X64 arch :^( + PROC_ARCH:=$(word 1, $(PROCESSOR_IDENTIFIER)) + PROC_ARCH:=$(subst x86,X86,$(PROC_ARCH)) + PROC_ARCH:=$(subst x64,X64,$(PROC_ARCH)) + PROC_ARCH:=$(subst AMD64,X64,$(PROC_ARCH)) + PROC_ARCH:=$(subst amd64,X64,$(PROC_ARCH)) + PROC_ARCH:=$(subst EM64T,X64,$(PROC_ARCH)) + PROC_ARCH:=$(subst em64t,X64,$(PROC_ARCH)) + PROC_ARCH:=$(subst intel64,X64,$(PROC_ARCH)) + PROC_ARCH:=$(subst Intel64,X64,$(PROC_ARCH)) + PROC_ARCH:=$(subst INTEL64,X64,$(PROC_ARCH)) + PROC_ARCH:=$(subst ia64,IA64,$(PROC_ARCH)) + ifeq ($(PROC_ARCH),IA64) + ARCH = ia64 else - ifeq ($(word 1, $(PROCESSOR_IDENTIFIER)),AMD64) - ARCH=x64 + ifeq ($(PROC_ARCH),X64) + ARCH = x64 else - ifeq ($(word 1, $(PROCESSOR_IDENTIFIER)),EM64T) - ARCH=x64 - else - ARCH=i586 - endif + ARCH = i586 endif endif + EXESUFFIX = .exe + # These need to be different depending on MKS or CYGWIN + ifeq ($(findstring cygdrive,$(shell (cd C:/ && pwd))), ) + GETMIXEDPATH=dosname -s + else + GETMIXEDPATH=cygpath -m -s + endif endif +# Utilities used +CD = cd +CP = cp +ECHO = echo +MKDIR = mkdir +ZIP = zip + # Root of this test area (important to use full paths in some places) TEST_ROOT := $(shell pwd) -# Default bundle of all test results (passed or not) -JPRT_ARCHIVE_BUNDLE=$(TEST_ROOT)/JPRT_ARCHIVE_BUNDLE.zip - -# Default home for JTREG -ifeq ($(PLATFORM), windows) - JT_HOME = J:/svc/jct-tools3.2.2_02 - JTREG_KEY_OPTION=-k:!ignore +# Root of all test results +ifdef ALT_OUTPUTDIR + ABS_OUTPUTDIR = $(ALT_OUTPUTDIR) else - JT_HOME = /java/svc/jct-tools3.2.2_02 - JTREG_KEY_OPTION=-k:\!ignore + ABS_OUTPUTDIR = $(TEST_ROOT)/../build/$(PLATFORM)-$(ARCH) endif +ABS_BUILD_ROOT = $(ABS_OUTPUTDIR) +ABS_TEST_OUTPUT_DIR := $(ABS_BUILD_ROOT)/testoutput -# Default JTREG to run -JTREG = $(JT_HOME)/$(JCT_PLATFORM)/bin/jtreg +# Expect JPRT to set PRODUCT_HOME (the product or jdk in this case to test) +ifndef PRODUCT_HOME + # Try to use j2sdk-image if it exists + ABS_JDK_IMAGE = $(ABS_BUILD_ROOT)/j2sdk-image + PRODUCT_HOME := \ + $(shell \ + if [ -d $(ABS_JDK_IMAGE) ] ; then \ + $(ECHO) "$(ABS_JDK_IMAGE)"; \ + else \ + $(ECHO) "$(ABS_BUILD_ROOT)" ; \ + fi) + PRODUCT_HOME := $(PRODUCT_HOME) +endif -# Default JDK to test -JAVA_HOME = $(TEST_ROOT)/../build/$(PLATFORM)-$(ARCH) +# Expect JPRT to set JPRT_PRODUCT_ARGS (e.g. -server etc.) +# Should be passed into 'java' only. +ifdef JPRT_PRODUCT_ARGS + JAVA_ARGS = $(JPRT_PRODUCT_ARGS) +endif -# The test directories to run -DEFAULT_TESTDIRS = demo/jvmti/gctest demo/jvmti/hprof -TESTDIRS = $(DEFAULT_TESTDIRS) +# Expect JPRT to set JPRT_PRODUCT_VM_ARGS (e.g. -Xcomp etc.) +# Should be passed into anything running the vm (java, javac, javadoc, ...). +ifdef JPRT_PRODUCT_VM_ARGS + JAVA_VM_ARGS = $(JPRT_PRODUCT_VM_ARGS) +endif -# Root of all test results -JTREG_OUTPUT_DIR = $(TEST_ROOT)/o_$(PLATFORM)-$(ARCH) - -# Export this setting and pass it in. -#JAVA_TOOL_OPTIONS = -Djava.awt.headless=true -#export JAVA_TOOL_OPTIONS - -# Default make rule -all: clean check tests $(JPRT_ARCHIVE_BUNDLE) - @echo "Testing completed successfully" - -# Chaeck to make sure these directories exist -check: $(JT_HOME) $(JAVA_HOME) $(JTREG) - -# Run the tests -tests: FRC - @echo "Using export JAVA_TOOL_OPTIONS=$(JAVA_TOOL_OPTIONS)" - @rm -f -r $(JTREG_OUTPUT_DIR) - @mkdir -p $(JTREG_OUTPUT_DIR) - $(JTREG) -a -v:fail,error \ - $(JTREG_KEY_OPTION) \ - -r:$(JTREG_OUTPUT_DIR)/JTreport \ - -w:$(JTREG_OUTPUT_DIR)/JTwork \ - -jdk:$(JAVA_HOME) \ - $(JAVA_TOOL_OPTIONS:%=-vmoption:%) \ - $(JAVA_ARGS:%=-vmoption:%) \ - $(TESTDIRS) - -# Bundle up the results -$(JPRT_ARCHIVE_BUNDLE): FRC - @rm -f $@ - @mkdir -p $(@D) - ( cd $(JTREG_OUTPUT_DIR) && zip -q -r $@ . ) +# Expect JPRT to set JPRT_ARCHIVE_BUNDLE (path to zip bundle for results) +ARCHIVE_BUNDLE = $(ABS_TEST_OUTPUT_DIR)/ARCHIVE_BUNDLE.zip +ifdef JPRT_ARCHIVE_BUNDLE + ARCHIVE_BUNDLE = $(JPRT_ARCHIVE_BUNDLE) +endif + +# How to create the test bundle (pass or fail, we want to create this) +# Follow command with ";$(BUNDLE_UP_AND_EXIT)", so it always gets executed. +ZIP_UP_RESULTS = ( $(MKDIR) -p `dirname $(ARCHIVE_BUNDLE)` \ + && $(CD) $(ABS_TEST_OUTPUT_DIR) \ + && $(ZIP) -q -r $(ARCHIVE_BUNDLE) . ) +BUNDLE_UP_AND_EXIT = ( exitCode=$$? && $(ZIP_UP_RESULTS) && exit $${exitCode} ) + +################################################################ + +# Default make rule (runs jtreg_tests) +all: jtreg_tests + @$(ECHO) "Testing completed successfully" + +# Prep for output +prep: clean + @$(MKDIR) -p $(ABS_TEST_OUTPUT_DIR) + @$(MKDIR) -p `dirname $(ARCHIVE_BUNDLE)` # Cleanup clean: - rm -f -r $(JTREG_OUTPUT_DIR) - rm -f $(JPRT_ARCHIVE_BUNDLE) + $(RM) -r $(ABS_TEST_OUTPUT_DIR) + $(RM) $(ARCHIVE_BUNDLE) + +################################################################ + +# jtreg tests + +# Expect JT_HOME to be set for jtreg tests. (home for jtreg) +JT_HOME = $(SLASH_JAVA)/re/jtreg/4.0/promoted/latest/binaries/jtreg +ifdef JPRT_JTREG_HOME + JT_HOME = $(JPRT_JTREG_HOME) +endif + +# Expect JPRT to set TESTDIRS to the jtreg test dirs +ifndef TESTDIRS + TESTDIRS = demo/jvmti/gctest demo/jvmti/hprof +endif + +# Default JTREG to run (win32 script works for everybody) +JTREG = $(JT_HOME)/win32/bin/jtreg + +jtreg_tests: prep $(JT_HOME) $(PRODUCT_HOME) $(JTREG) + $(RM) $(JTREG).orig + cp $(JTREG) $(JTREG).orig + $(RM) $(JTREG) + sed -e 's@-J\*@-J-*@' $(JTREG).orig > $(JTREG) + chmod a+x $(JTREG) + ( JT_HOME=$(shell $(GETMIXEDPATH) "$(JT_HOME)"); \ + export JT_HOME; \ + $(shell $(GETMIXEDPATH) "$(JTREG)") \ + -a -v:fail,error \ + -ignore:quiet \ + $(EXTRA_JTREG_OPTIONS) \ + -r:$(shell $(GETMIXEDPATH) "$(ABS_TEST_OUTPUT_DIR)")/JTreport \ + -w:$(shell $(GETMIXEDPATH) "$(ABS_TEST_OUTPUT_DIR)")/JTwork \ + -jdk:$(shell $(GETMIXEDPATH) "$(PRODUCT_HOME)") \ + $(JAVA_ARGS:%=-javaoptions:%) \ + $(JAVA_VM_ARGS:%=-vmoption:%) \ + $(TESTDIRS) \ + ) ; $(BUNDLE_UP_AND_EXIT) + +PHONY_LIST += jtreg_tests + +################################################################ + +# packtest + +# Expect JPRT to set JPRT_PACKTEST_HOME. +PACKTEST_HOME = /net/jprt-web.sfbay.sun.com/jprt/allproducts/packtest +ifdef JPRT_PACKTEST_HOME + PACKTEST_HOME = $(JPRT_PACKTEST_HOME) +endif + +packtest: prep $(PACKTEST_HOME)/ptest $(PRODUCT_HOME) + ( $(CD) $(PACKTEST_HOME) && \ + $(PACKTEST_HOME)/ptest \ + -t "$(PRODUCT_HOME)" \ + $(PACKTEST_STRESS_OPTION) \ + $(EXTRA_PACKTEST_OPTIONS) \ + -W $(ABS_TEST_OUTPUT_DIR) \ + $(JAVA_ARGS:%=-J %) \ + $(JAVA_VM_ARGS:%=-J %) \ + ) ; $(BUNDLE_UP_AND_EXIT) + +packtest_stress: PACKTEST_STRESS_OPTION=-s +packtest_stress: packtest + +PHONY_LIST += packtest packtest_stress + +################################################################ + +# vmsqe tests + +# Expect JPRT to set JPRT_VMSQE_HOME. +VMSQE_HOME = /java/sqe/comp/vm/testbase/sqe/vm/current/build/latest/vm +ifdef JPRT_VMSQE_HOME + VMSQE_HOME = $(JPRT_VMSQE_HOME) +endif + +# Expect JPRT to set JPRT_RUNVMSQE_HOME. +RUNVMSQE_HOME = /net/jprt-web.sfbay.sun.com/jprt/allproducts/runvmsqe +ifdef JPRT_RUNVMSQE_HOME + RUNVMSQE_HOME = $(JPRT_RUNVMSQE_HOME) +endif + +# Expect JPRT to set JPRT_TONGA3_HOME. +TONGA3_HOME = /java/sqe//tools/gtee/harness/tonga +ifdef JPRT_TONGA3_HOME + TONGA3_HOME = $(JPRT_TONGA3_HOME) +endif + +RUNVMSQE_BIN = $(RUNVMSQE_HOME)/bin/runvmsqe + +vmsqe_tests: prep $(VMSQE_HOME)/vm $(TONGA3_HOME) $(RUNVMSQE_BIN) $(PRODUCT_HOME) + $(RM) -r $(ABS_TEST_OUTPUT_DIR)/vmsqe + ( $(CD) $(ABS_TEST_OUTPUT_DIR) && \ + $(RUNVMSQE_BIN) \ + -jdk "$(PRODUCT_HOME)" \ + -o "$(ABS_TEST_OUTPUT_DIR)/vmsqe" \ + -testbase "$(VMSQE_HOME)/vm" \ + -tonga "$(TONGA3_HOME)" \ + -tongajdk "$(ALT_BOOTDIR)" \ + $(JAVA_ARGS) \ + $(JAVA_VM_ARGS) \ + $(RUNVMSQE_TEST_OPTION) \ + $(EXTRA_RUNVMSQE_OPTIONS) \ + ) ; $(BUNDLE_UP_AND_EXIT) + +vmsqe_jdwp: RUNVMSQE_TEST_OPTION=-jdwp +vmsqe_jdwp: vmsqe_tests -# Used to force a target rules to run -FRC: +vmsqe_jdi: RUNVMSQE_TEST_OPTION=-jdi +vmsqe_jdi: vmsqe_tests + +vmsqe_jdb: RUNVMSQE_TEST_OPTION=-jdb +vmsqe_jdb: vmsqe_tests + +vmsqe_quick-jdi: RUNVMSQE_TEST_OPTION=-quick-jdi +vmsqe_quick-jdi: vmsqe_tests + +vmsqe_sajdi: RUNVMSQE_TEST_OPTION=-sajdi +vmsqe_sajdi: vmsqe_tests + +vmsqe_jvmti: RUNVMSQE_TEST_OPTION=-jvmti +vmsqe_jvmti: vmsqe_tests + +vmsqe_hprof: RUNVMSQE_TEST_OPTION=-hprof +vmsqe_hprof: vmsqe_tests + +vmsqe_monitoring: RUNVMSQE_TEST_OPTION=-monitoring +vmsqe_monitoring: vmsqe_tests + +PHONY_LIST += vmsqe_jdwp vmsqe_jdi vmsqe_jdb vmsqe_quick-jdi vmsqe_sajdi \ + vmsqe_jvmti vmsqe_hprof vmsqe_monitoring vmsqe_tests + +################################################################ + +# jck tests + +JCK_WORK_DIR = $(ABS_TEST_OUTPUT_DIR)/JCKwork +JCK_REPORT_DIR = $(ABS_TEST_OUTPUT_DIR)/JCKreport +JCK_PROPERTIES = $(ABS_TEST_OUTPUT_DIR)/jck.properties +JCK_CONFIG = $(ABS_TEST_OUTPUT_DIR)/jck.config + +JCK_JAVA_EXE = $(PRODUCT_HOME)/bin/java$(EXESUFFIX) + +JCK_JAVATEST_JAR = $(JCK_HOME)/lib/javatest.jar +JCK_JAVATEST = $(ALT_BOOTDIR)/bin/java -jar $(JCK_JAVATEST_JAR) + +$(JCK_CONFIG): $(TEST_ROOT)/JCK-$(JCK_BUNDLE_NAME)-$(JCK_RELEASE)-base.jti + $(RM) $@ + $(MKDIR) -p $(@D) + $(CP) $< $@ + +$(JCK_PROPERTIES): $(PRODUCT_HOME) $(JCK_JAVA_EXE) + $(RM) $@ + $(MKDIR) -p $(@D) + $(ECHO) "jck.env.compiler.compRefExecute.cmdAsFile=$(JCK_JAVA_EXE)" >> $@ + $(ECHO) "jck.env.compiler.compRefExecute.systemRoot=$(SYSTEMROOT)" >> $@ + $(ECHO) "jck.env.compiler.testCompile.testCompileAPImultiJVM.cmdAsFile=$(JCK_JAVA_EXE)" >> $@ + $(ECHO) "jck.tests.tests=$(JCK_BUNDLE_TESTDIRS)" >> $@ + +jck_tests: prep $(JCK_HOME) $(JCK_PROPERTIES) $(JCK_CONFIG) $(JCK_JAVATEST_JAR) + $(MKDIR) -p $(JCK_WORK_DIR) + ( $(JCK_JAVATEST) \ + -verbose:commands,non-pass \ + -testSuite $(JCK_HOME) \ + -workDir $(JCK_WORK_DIR) \ + -config $(JCK_CONFIG) \ + -set -file $(JCK_PROPERTIES) \ + -runtests \ + -writeReport $(JCK_REPORT_DIR) \ + ) ; $(BUNDLE_UP_AND_EXIT) + +PHONY_LIST += jck_tests + +################################################################ + +# jck6 tests + +JCK6_RELEASE = 6b +JCK6_DEFAULT_HOME = $(SLASH_JAVA)/re/jck/$(JCK6_RELEASE)/archive/fcs/binaries + +# Expect JPRT to set JPRT_JCK6COMPILER_HOME. +JCK6COMPILER_HOME = $(JCK6_DEFAULT_HOME)/JCK-compiler-$(JCK6_RELEASE) +ifdef JPRT_JCK6COMPILER_HOME + JCK6COMPILER_HOME = $(JPRT_JCK6COMPILER_HOME) +endif + +# Expect JPRT to set JPRT_JCK6RUNTIME_HOME. +JCK6RUNTIME_HOME = $(JCK6_DEFAULT_HOME)/JCK-runtime-$(JCK6_RELEASE) +ifdef JPRT_JCK6RUNTIME_HOME + JCK6RUNTIME_HOME = $(JPRT_JCK6RUNTIME_HOME) +endif + +# Expect JPRT to set JPRT_JCK6DEVTOOLS_HOME. +JCK6DEVTOOLS_HOME = $(JCK6_DEFAULT_HOME)/JCK-devtools-$(JCK6_RELEASE) +ifdef JPRT_JCK6DEVTOOLS_HOME + JCK6DEVTOOLS_HOME = $(JPRT_JCK6DEVTOOLS_HOME) +endif + +jck6_tests: JCK_HOME=$(JCK6_HOME) +jck6_tests: JCK_RELEASE=$(JCK6_RELEASE) +jck6_tests: jck_tests + +jck6compiler: JCK6_HOME=$(JCK6COMPILER_HOME) +jck6compiler: JCK_BUNDLE_NAME=compiler +jck6compiler: jck6_tests + +jck6compiler_lang: JCK_BUNDLE_TESTDIRS=lang +jck6compiler_lang: jck6compiler + +jck6runtime: JCK6_HOME=$(JCK6RUNTIME_HOME) +jck6runtime: JCK_BUNDLE_NAME=runtime +jck6runtime: jck6_tests + +jck6runtime_lang: JCK_BUNDLE_TESTDIRS=lang +jck6runtime_lang: jck6runtime + +jck6devtools: JCK6_HOME=$(JCK6DEVTOOLS_HOME) +jck6devtools: JCK_BUNDLE_NAME=devtools +jck6devtools: jck6_tests + +jck6devtools_lang: JCK_BUNDLE_TESTDIRS=lang +jck6devtools_lang: jck6devtools + +PHONY_LIST += jck6compiler jck6runtime jck6devtools jck6_tests \ + jck6compiler_lang jck6runtime_lang jck6devtools_lang + +################################################################ + +# jck7 tests + +JCK7_RELEASE = 7 +JCK7_DEFAULT_HOME = $(SLASH_JAVA)/re/jck/$(JCK7_RELEASE)/archive/fcs/binaries + +# Expect JPRT to set JPRT_JCK7COMPILER_HOME. +JCK7COMPILER_HOME = $(JCK7_DEFAULT_HOME)/JCK-compiler-$(JCK7_RELEASE) +ifdef JPRT_JCK7COMPILER_HOME + JCK7COMPILER_HOME = $(JPRT_JCK7COMPILER_HOME) +endif + +# Expect JPRT to set JPRT_JCK7RUNTIME_HOME. +JCK7RUNTIME_HOME = $(JCK7_DEFAULT_HOME)/JCK-runtime-$(JCK7_RELEASE) +ifdef JPRT_JCK7RUNTIME_HOME + JCK7RUNTIME_HOME = $(JPRT_JCK7RUNTIME_HOME) +endif + +# Expect JPRT to set JPRT_JCK7DEVTOOLS_HOME. +JCK7DEVTOOLS_HOME = $(JCK7_DEFAULT_HOME)/JCK-devtools-$(JCK7_RELEASE) +ifdef JPRT_JCK7DEVTOOLS_HOME + JCK7DEVTOOLS_HOME = $(JPRT_JCK7DEVTOOLS_HOME) +endif + +jck7_tests: JCK_HOME=$(JCK7_HOME) +jck7_tests: JCK_RELEASE=$(JCK7_RELEASE) +jck7_tests: jck_tests + +jck7compiler: JCK7_HOME=$(JCK7COMPILER_HOME) +jck7compiler: JCK_BUNDLE_NAME=compiler +jck7compiler: jck7_tests + +jck7compiler_lang: JCK_BUNDLE_TESTDIRS=lang +jck7compiler_lang: jck7compiler + +jck7runtime: JCK7_HOME=$(JCK7RUNTIME_HOME) +jck7runtime: JCK_BUNDLE_NAME=runtime +jck7runtime: jck7_tests + +jck7runtime_lang: JCK_BUNDLE_TESTDIRS=lang +jck7runtime_lang: jck7runtime + +jck7devtools: JCK7_HOME=$(JCK7DEVTOOLS_HOME) +jck7devtools: JCK_BUNDLE_NAME=devtools +jck7devtools: jck7_tests + +jck7devtools_lang: JCK_BUNDLE_TESTDIRS=lang +jck7devtools_lang: jck7devtools + +PHONY_LIST += jck7compiler jck7runtime jck7devtools jck7_tests \ + jck7compiler_lang jck7runtime_lang jck7devtools_lang + +################################################################ # Phony targets (e.g. these are not filenames) -.PHONY: all tests clean check +.PHONY: all clean prep $(PHONY_LIST) + +################################################################ diff --git a/test/com/sun/java/swing/plaf/gtk/Test6635110.java b/test/com/sun/java/swing/plaf/gtk/Test6635110.java new file mode 100644 index 0000000000000000000000000000000000000000..c82cf1268936c88c4e525b3fcc5950d4cbb49b0e --- /dev/null +++ b/test/com/sun/java/swing/plaf/gtk/Test6635110.java @@ -0,0 +1,65 @@ +/* + * Copyright 2008 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. + * + * 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. + */ + +/* @test + @bug 6635110 + @summary GTK icons should not throw NPE when called by non-GTK UI + @author Peter Zhelezniakov + @run main Test6635110 +*/ + +import com.sun.java.swing.plaf.gtk.GTKLookAndFeel; +import javax.swing.*; +import java.awt.*; +import java.awt.image.BufferedImage; +import javax.swing.plaf.basic.*; + + +public class Test6635110 implements Runnable { + + static final int WIDTH = 160; + static final int HEIGHT = 80; + final BufferedImage IMAGE = + new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_ARGB); + + @Override public void run() { + JMenu menu = new JMenu("menu"); + menu.setUI(new BasicMenuUI()); + paint(menu); + + JToolBar tb = new JToolBar(); + tb.setFloatable(true); + tb.setUI(new BasicToolBarUI()); + paint(tb); + } + + void paint(Component c) { + c.setSize(WIDTH, HEIGHT); + c.paint(IMAGE.getGraphics()); + } + + public static void main(String[] args) throws Exception { + UIManager.setLookAndFeel(new GTKLookAndFeel()); + SwingUtilities.invokeAndWait(new Test6635110()); + } +} diff --git a/test/com/sun/jmx/snmp/SnmpOidHashCode.java b/test/com/sun/jmx/snmp/SnmpOidHashCode.java index 907d00913f42d8210cabf67b8948f8c415304ca7..4a815de0386d282080e30915132283d5c5206a06 100644 --- a/test/com/sun/jmx/snmp/SnmpOidHashCode.java +++ b/test/com/sun/jmx/snmp/SnmpOidHashCode.java @@ -1,5 +1,5 @@ /* - * Copyright 2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2003-2008 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 @@ -28,7 +28,8 @@ * @build SnmpOidHashCode * @run main SnmpOidHashCode */ -import com.sun.jmx.snmp.SnmpOid; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; public class SnmpOidHashCode { public static final String[] oids = { @@ -57,16 +58,81 @@ public class SnmpOidHashCode { ".39."+0xFFFFFFFFL }; + // We use an SnmpOidBuilder in order to adapt this test case to a + // configuration where the SNMP packages are not present in rt.jar. + // + public static final class SnmpOidBuilder { + public static final String SNMP_OID_CLASS_NAME = + "com.sun.jmx.snmp.SnmpOid"; + private static final Class<?> SNMP_OID_CLASS; + private static final Constructor<?> SNMP_OID_CTOR; + static { + Class<?> snmpOidClass; + try { + snmpOidClass = + Class.forName(SNMP_OID_CLASS_NAME, true, null); + } catch (ClassNotFoundException x) { + snmpOidClass = null; + System.err.println("WARNING: can't load "+SNMP_OID_CLASS_NAME); + } catch (NoClassDefFoundError x) { + snmpOidClass = null; + System.err.println("WARNING: can't load "+SNMP_OID_CLASS_NAME); + } + SNMP_OID_CLASS = snmpOidClass; + if (SNMP_OID_CLASS != null) { + try { + SNMP_OID_CTOR = snmpOidClass.getConstructor(String.class); + } catch (Exception x) { + throw new ExceptionInInitializerError(x); + } + } else { + SNMP_OID_CTOR = null; + } + } + + public static boolean isSnmpPresent() { + System.out.println(SnmpOidHashCode.class.getName()+ + ": Testing for SNMP Packages..."); + return SNMP_OID_CLASS != null; + } + + public static Object newSnmpOid(String oid) + throws InstantiationException, + IllegalAccessException, + InvocationTargetException { + return SNMP_OID_CTOR.newInstance(oid); + } + + } + + private static Object newSnmpOid(String oid) throws Exception { + try { + return SnmpOidBuilder.newSnmpOid(oid); + } catch (InvocationTargetException x) { + final Throwable cause = x.getCause(); + if (cause instanceof Exception) throw (Exception)cause; + if (cause instanceof Error) throw (Error)cause; + throw x; + } + } + public static void main(String args[]) { + if (!SnmpOidBuilder.isSnmpPresent()) { + System.err.println("WARNING: "+ + SnmpOidBuilder.SNMP_OID_CLASS_NAME+" not present."); + System.err.println(SnmpOidHashCode.class.getName()+ + ": test skipped."); + return; + } try { int errCount=0; int collisions=0; for (int i=0;i<oids.length;i++) { System.out.println("Testing " + oids[i]); - final SnmpOid o1 = new SnmpOid(oids[i]); + final Object o1 = newSnmpOid(oids[i]); final int startCount=errCount; for (int j=0;j<oids.length;j++) { - final SnmpOid o2 = new SnmpOid(oids[j]); + final Object o2 = newSnmpOid(oids[j]); if (o1.equals(o2)) { if (!(oids[i].equals(oids[j]))) { System.err.println("OIDs differ but " + diff --git a/test/com/sun/jmx/snmp/TimeTicksWrapping.java b/test/com/sun/jmx/snmp/TimeTicksWrapping.java index 23a87b662f400065e493ac53a78ddcbda9e8a688..0776052c53f896d70993afdc1bb990a5e0e4de2f 100644 --- a/test/com/sun/jmx/snmp/TimeTicksWrapping.java +++ b/test/com/sun/jmx/snmp/TimeTicksWrapping.java @@ -1,5 +1,5 @@ /* - * Copyright 2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2003-2008 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 @@ -29,33 +29,158 @@ * @build TimeTicksWrapping * @run main TimeTicksWrapping */ -import com.sun.jmx.snmp.SnmpTimeticks; -import com.sun.jmx.snmp.SnmpUnsignedInt; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; public class TimeTicksWrapping { + // We use an SnmpTimeticksBuilder in order to adapt this test case to a + // configuration where the SNMP packages are not present in rt.jar. + // + public static final class SnmpTimeticksBuilder { + public static final long MAX_VALUE = 0x0ffffffffL; + public static final String SNMP_TIME_TICKS_CLASS_NAME = + "com.sun.jmx.snmp.SnmpTimeticks"; + private static final Class<?> SNMP_TIME_TICKS_CLASS; + private static final Constructor<?> SNMP_long_CTOR; + private static final Constructor<?> SNMP_LONG_CTOR; + private static final Method SNMP_LONG_VALUE; + static { + Class<?> snmpTimeTicksClass; + try { + snmpTimeTicksClass = + Class.forName(SNMP_TIME_TICKS_CLASS_NAME, true, null); + } catch (ClassNotFoundException x) { + snmpTimeTicksClass = null; + System.err.println("WARNING: can't load "+ + SNMP_TIME_TICKS_CLASS_NAME); + } catch (NoClassDefFoundError x) { + snmpTimeTicksClass = null; + System.err.println("WARNING: can't load "+ + SNMP_TIME_TICKS_CLASS_NAME); + } + SNMP_TIME_TICKS_CLASS = snmpTimeTicksClass; + if (SNMP_TIME_TICKS_CLASS != null) { + try { + SNMP_long_CTOR = + SNMP_TIME_TICKS_CLASS.getConstructor(long.class); + } catch (Exception x) { + throw new ExceptionInInitializerError(x); + } + } else { + SNMP_long_CTOR = null; + } + if (SNMP_TIME_TICKS_CLASS != null) { + try { + SNMP_LONG_CTOR = + SNMP_TIME_TICKS_CLASS.getConstructor(Long.class); + } catch (Exception x) { + throw new ExceptionInInitializerError(x); + } + } else { + SNMP_LONG_CTOR = null; + } + if (SNMP_TIME_TICKS_CLASS != null) { + try { + SNMP_LONG_VALUE = + SNMP_TIME_TICKS_CLASS.getMethod("longValue"); + } catch (Exception x) { + throw new ExceptionInInitializerError(x); + } + } else { + SNMP_LONG_VALUE = null; + } + + } + + private final Object timeticks; + + public SnmpTimeticksBuilder(long ticks) throws Exception { + timeticks = newSnmpTimeticks(ticks); + } + public SnmpTimeticksBuilder(Long ticks) throws Exception { + timeticks = newSnmpTimeticks(ticks); + } + public long longValue() throws Exception { + return longValue(timeticks); + } + + public static boolean isSnmpPresent() { + System.out.println(TimeTicksWrapping.class.getName()+ + ": Testing for SNMP Packages..."); + return SNMP_TIME_TICKS_CLASS != null; + } + + private static Object newSnmpTimeticks(long time) + throws Exception { + try { + return SNMP_long_CTOR.newInstance(time); + } catch (InvocationTargetException x) { + final Throwable cause = x.getCause(); + if (cause instanceof Exception) throw (Exception) cause; + if (cause instanceof Error) throw (Error) cause; + throw x; + } + } + + private static Object newSnmpTimeticks(Long time) + throws Exception { + try { + return SNMP_LONG_CTOR.newInstance(time); + } catch (InvocationTargetException x) { + final Throwable cause = x.getCause(); + if (cause instanceof Exception) throw (Exception) cause; + if (cause instanceof Error) throw (Error) cause; + throw x; + } + } + + private static long longValue(Object o) + throws Exception { + try { + return ((Long)SNMP_LONG_VALUE.invoke(o)).longValue(); + } catch (InvocationTargetException x) { + final Throwable cause = x.getCause(); + if (cause instanceof Exception) throw (Exception) cause; + if (cause instanceof Error) throw (Error) cause; + throw x; + } + } + + } + public static final long[] oks = { 0L, 1L, (long)Integer.MAX_VALUE, (long)Integer.MAX_VALUE*2, (long)Integer.MAX_VALUE*2+1L, (long)Integer.MAX_VALUE*2+2L, (long)Integer.MAX_VALUE*3, - SnmpUnsignedInt.MAX_VALUE, SnmpUnsignedInt.MAX_VALUE+1L, - SnmpUnsignedInt.MAX_VALUE*3-1L, Long.MAX_VALUE + SnmpTimeticksBuilder.MAX_VALUE, SnmpTimeticksBuilder.MAX_VALUE+1L, + SnmpTimeticksBuilder.MAX_VALUE*3-1L, Long.MAX_VALUE }; public static final long[] kos = { -1L, (long)Integer.MIN_VALUE, (long)Integer.MIN_VALUE*2, (long)Integer.MIN_VALUE*2-1L, (long)Integer.MIN_VALUE*3, - -SnmpUnsignedInt.MAX_VALUE, -(SnmpUnsignedInt.MAX_VALUE+1L), - -(SnmpUnsignedInt.MAX_VALUE*3-1L), Long.MIN_VALUE + -SnmpTimeticksBuilder.MAX_VALUE, -(SnmpTimeticksBuilder.MAX_VALUE+1L), + -(SnmpTimeticksBuilder.MAX_VALUE*3-1L), Long.MIN_VALUE }; + public static void main(String args[]) { + if (!SnmpTimeticksBuilder.isSnmpPresent()) { + System.err.println("WARNING: "+ + SnmpTimeticksBuilder.SNMP_TIME_TICKS_CLASS_NAME+ + " not present."); + System.err.println(TimeTicksWrapping.class.getName()+ + ": test skipped."); + return; + } try { - SnmpTimeticks t; + SnmpTimeticksBuilder t = null; for (int i=0;i<oks.length;i++) { final long t1,t2,t3; - t1 = (new SnmpTimeticks(oks[i])).longValue(); - t2 = (new SnmpTimeticks(new Long(oks[i]))).longValue(); + t1 = (new SnmpTimeticksBuilder(oks[i])).longValue(); + t2 = (new SnmpTimeticksBuilder(new Long(oks[i]))).longValue(); t3 = oks[i]%0x0100000000L; if (t1 != t3) throw new Exception("Value should have wrapped: " + @@ -64,16 +189,16 @@ public class TimeTicksWrapping { throw new Exception("Value should have wrapped: " + "Long("+oks[i]+") expected: " + t3); - if (t1 > SnmpUnsignedInt.MAX_VALUE) + if (t1 > SnmpTimeticksBuilder.MAX_VALUE) throw new Exception("Value should have wrapped " + "for " + oks[i] + ": " + t1 + " exceeds max: " + - SnmpUnsignedInt.MAX_VALUE); - if (t2 > SnmpUnsignedInt.MAX_VALUE) + SnmpTimeticksBuilder.MAX_VALUE); + if (t2 > SnmpTimeticksBuilder.MAX_VALUE) throw new Exception("Value should have wrapped " + "for " + oks[i] + ": " + t2 + " exceeds max: " + - SnmpUnsignedInt.MAX_VALUE); + SnmpTimeticksBuilder.MAX_VALUE); if (t1 < 0) throw new Exception("Value should have wrapped: " + @@ -90,14 +215,14 @@ public class TimeTicksWrapping { for (int i=0;i<kos.length;i++) { try { - t = new SnmpTimeticks(kos[i]); + t = new SnmpTimeticksBuilder(kos[i]); throw new Exception("Value should have been rejected: " + kos[i]); } catch (IllegalArgumentException x) { // OK! } try { - t = new SnmpTimeticks(new Long(kos[i])); + t = new SnmpTimeticksBuilder(new Long(kos[i])); throw new Exception("Value should have been rejected: " + "Long("+kos[i]+")"); } catch (IllegalArgumentException x) { diff --git a/test/java/awt/FontClass/FontAccess.java b/test/java/awt/FontClass/FontAccess.java new file mode 100644 index 0000000000000000000000000000000000000000..3e965059ef75a235bbb5540c82921e636f8f19d0 --- /dev/null +++ b/test/java/awt/FontClass/FontAccess.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 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. + * + * 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. + */ + +/* + * @test + * @bug 6785424 + * @summary Test no SecurityException searching for a font. + * @run main FontAccess + * + * This can only test the specific bug if run on something like + * Windows Citrix Server where SystemDirectory and WindowsDirectory + * are different locations. + */ + +import java.awt.*; +import java.awt.image.*; + +public class FontAccess { + + public static void main(String[] args) { + System.setSecurityManager(new SecurityManager()); + Font f = new Font("Verdana", Font.PLAIN, 12); + BufferedImage bi = new BufferedImage(1,1,1); + Graphics2D g = bi.createGraphics(); + g.setFont(f); + System.out.println(g.getFontMetrics()); + } +} diff --git a/test/java/awt/Frame/FrameSize/TestFrameSize.java b/test/java/awt/Frame/FrameSize/TestFrameSize.java index f8a98ea3216c32ec0e43ddfb878c91f4f94b15cf..b220ec5cc010f9e8d60594eec6634f633c3457c9 100644 --- a/test/java/awt/Frame/FrameSize/TestFrameSize.java +++ b/test/java/awt/Frame/FrameSize/TestFrameSize.java @@ -15,6 +15,10 @@ * 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. */ /* diff --git a/test/java/awt/GraphicsEnvironment/PreferLocaleFonts.java b/test/java/awt/GraphicsEnvironment/PreferLocaleFonts.java new file mode 100644 index 0000000000000000000000000000000000000000..3d8cb5934f5d8d083db9fbb03794a687f4f1fe76 --- /dev/null +++ b/test/java/awt/GraphicsEnvironment/PreferLocaleFonts.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2008 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. + * + * 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. + */ + +/* + * @test + * @bug 6752638 + * @summary Test no NPE calling preferLocaleFonts() on custom GE. + * @run main PreferLocaleFonts + */ + +import java.util.*; +import java.awt.*; +import java.awt.image.*; + +public class PreferLocaleFonts extends GraphicsEnvironment { + + public static void main(String args[]) { +(new PreferLocaleFonts()).preferLocaleFonts(); + } + public PreferLocaleFonts() { + super(); + } + public Graphics2D createGraphics(BufferedImage image) { + return null; + } + public String[] getAvailableFontFamilyNames(Locale locale) { + return null; + } + public String[] getAvailableFontFamilyNames() { + return null; + } + public Font[] getAllFonts() { + return null; + } + public GraphicsDevice getDefaultScreenDevice() throws HeadlessException { + return null; + } + public GraphicsDevice[] getScreenDevices() throws HeadlessException { + return null; + } +} + diff --git a/test/java/awt/font/LineBreakMeasurer/FRCTest.java b/test/java/awt/font/LineBreakMeasurer/FRCTest.java new file mode 100644 index 0000000000000000000000000000000000000000..d65037e2ec3685742940fd0b2429e2db27459cbf --- /dev/null +++ b/test/java/awt/font/LineBreakMeasurer/FRCTest.java @@ -0,0 +1,90 @@ +/* + * Copyright 2008-9 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. + * + * 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. + */ + +/* + * @test + * @bug 6448405 6519513 6745225 + * @summary static HashMap cache in LineBreakMeasurer can grow wihout bounds + * @run main/othervm/timeout=600 -client -Xms16m -Xmx16m FRCTest + */ +import java.awt.*; +import java.awt.image.*; +import java.awt.font.*; +import java.awt.geom.*; +import java.text.*; +import java.util.Hashtable; + +public class FRCTest { + + static AttributedString vanGogh = new AttributedString( + "Many people believe that Vincent van Gogh painted his best works " + + "during the two-year period he spent in Provence. Here is where he " + + "painted The Starry Night--which some consider to be his greatest " + + "work of all. However, as his artistic brilliance reached new " + + "heights in Provence, his physical and mental health plummeted. ", + new Hashtable()); + + public static void main(String[] args) { + + // First test the behaviour of Graphics2D.getFontRenderContext(); + BufferedImage bi = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB); + Graphics2D g2d = bi.createGraphics(); + AffineTransform g2dTx = new AffineTransform(2,0,2,0,1,1); + g2d.setTransform(g2dTx); + AffineTransform frcTx = g2d.getFontRenderContext().getTransform(); + AffineTransform frcExpected = new AffineTransform(2,0,2,0,0,0); + if (!frcTx.equals(frcExpected)) { + throw new RuntimeException("FRC Tx may have translate?"); + } + + // Now test that using different translates with LBM is OK + // This test doesn't prove a lot since showing a leak really + // requires a basher test that can run for a long time. + for (int x=0;x<100;x++) { + for (int y=0;y<100;y++) { + AttributedCharacterIterator aci = vanGogh.getIterator(); + AffineTransform tx = AffineTransform.getTranslateInstance(x, y); + FontRenderContext frc = new FontRenderContext(tx, false, false); + LineBreakMeasurer lbm = new LineBreakMeasurer(aci, frc); + lbm.setPosition(aci.getBeginIndex()); + while (lbm.getPosition() < aci.getEndIndex()) { + lbm.nextLayout(100f); + } + } + } + + for (int x=0;x<25;x++) { + for (int y=0;y<25;y++) { + AttributedCharacterIterator aci = vanGogh.getIterator(); + double rot = Math.random()*.4*Math.PI - .2*Math.PI; + AffineTransform tx = AffineTransform.getRotateInstance(rot); + FontRenderContext frc = new FontRenderContext(tx, false, false); + LineBreakMeasurer lbm = new LineBreakMeasurer(aci, frc); + lbm.setPosition(aci.getBeginIndex()); + while (lbm.getPosition() < aci.getEndIndex()) { + lbm.nextLayout(100f); + } + } + } + } +} diff --git a/test/java/beans/Beans/6669869/TestDesignTime.java b/test/java/beans/Beans/6669869/TestDesignTime.java new file mode 100644 index 0000000000000000000000000000000000000000..e78142a2b90caae0a796732356d1bd7662657789 --- /dev/null +++ b/test/java/beans/Beans/6669869/TestDesignTime.java @@ -0,0 +1,52 @@ +/* + * 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. + * + * 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. + */ + +/* + * @test + * @bug 6669869 + * @summary Tests DesignTime property in different application contexts + * @author Sergey Malenkov + */ + +import java.beans.Beans; +import sun.awt.SunToolkit; + +public class TestDesignTime implements Runnable { + public static void main(String[] args) throws InterruptedException { + if (Beans.isDesignTime()) { + throw new Error("unexpected DesignTime property"); + } + Beans.setDesignTime(!Beans.isDesignTime()); + ThreadGroup group = new ThreadGroup("$$$"); + Thread thread = new Thread(group, new TestDesignTime()); + thread.start(); + thread.join(); + } + + public void run() { + SunToolkit.createNewAppContext(); + if (Beans.isDesignTime()) { + throw new Error("shared DesignTime property"); + } + } +} diff --git a/test/java/beans/Beans/6669869/TestGuiAvailable.java b/test/java/beans/Beans/6669869/TestGuiAvailable.java new file mode 100644 index 0000000000000000000000000000000000000000..7144b6fad3bd42c5e5fc8ca53d1ff8e9f77e4d20 --- /dev/null +++ b/test/java/beans/Beans/6669869/TestGuiAvailable.java @@ -0,0 +1,53 @@ +/* + * 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. + * + * 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. + */ + +/* + * @test + * @bug 6669869 + * @summary Tests GuiAvailable property in different application contexts + * @author Sergey Malenkov + */ + +import java.awt.GraphicsEnvironment; +import java.beans.Beans; +import sun.awt.SunToolkit; + +public class TestGuiAvailable implements Runnable { + public static void main(String[] args) throws InterruptedException { + if (Beans.isGuiAvailable() == GraphicsEnvironment.isHeadless()) { + throw new Error("unexpected GuiAvailable property"); + } + Beans.setGuiAvailable(!Beans.isGuiAvailable()); + ThreadGroup group = new ThreadGroup("$$$"); + Thread thread = new Thread(group, new TestGuiAvailable()); + thread.start(); + thread.join(); + } + + public void run() { + SunToolkit.createNewAppContext(); + if (Beans.isGuiAvailable() == GraphicsEnvironment.isHeadless()) { + throw new Error("shared GuiAvailable property"); + } + } +} diff --git a/test/java/io/File/GetXSpace.java b/test/java/io/File/GetXSpace.java index a2855e7b3726858abd7a41c87ac2118a7865d4b1..345c3384668bb1042c0b2703f7f34f6ddbf2473d 100644 --- a/test/java/io/File/GetXSpace.java +++ b/test/java/io/File/GetXSpace.java @@ -24,6 +24,7 @@ /** * @test * @bug 4057701 6286712 6364377 + * @ignore until 6492634 and 6501010 is fixed * @run build GetXSpace * @run shell GetXSpace.sh * @summary Basic functionality of File.get-X-Space methods. diff --git a/test/java/lang/ClassLoader/deadlock/Alice.java b/test/java/lang/ClassLoader/deadlock/Alice.java new file mode 100644 index 0000000000000000000000000000000000000000..9fae5e411a8ec8699582c0f08389bc6642030b60 --- /dev/null +++ b/test/java/lang/ClassLoader/deadlock/Alice.java @@ -0,0 +1,29 @@ +/* + * 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. + * + * 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 comSA; + +public class Alice extends comSB.SupAlice { + static { + System.out.println("comSA.Alice loaded"); + } +} diff --git a/test/java/lang/ClassLoader/deadlock/Bob.java b/test/java/lang/ClassLoader/deadlock/Bob.java new file mode 100644 index 0000000000000000000000000000000000000000..ca0c279ec91fd3e8c2310ca9bc7b2674b8d8f5c2 --- /dev/null +++ b/test/java/lang/ClassLoader/deadlock/Bob.java @@ -0,0 +1,29 @@ +/* + * 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. + * + * 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 comSB; + +public class Bob extends comSA.SupBob { + static { + System.out.println("comSB.Bob loaded"); + } +} diff --git a/test/java/lang/ClassLoader/deadlock/DelegatingLoader.java b/test/java/lang/ClassLoader/deadlock/DelegatingLoader.java new file mode 100644 index 0000000000000000000000000000000000000000..def58c9e53c5e0945740fc3fc9ce31c42a2bd1fe --- /dev/null +++ b/test/java/lang/ClassLoader/deadlock/DelegatingLoader.java @@ -0,0 +1,93 @@ +/* + * 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. + * + * 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. + */ + +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.locks.*; +import java.lang.reflect.*; + +public class DelegatingLoader extends URLClassLoader { + + private DelegatingLoader delLoader; + private String[] delClasses; + + static { + boolean supportParallel = false; + try { + Class c = Class.forName("java.lang.ClassLoader"); + Method m = c.getDeclaredMethod("registerAsParallelCapable", + new Class[0]); + m.setAccessible(true); + Object result = (Boolean) m.invoke(null); + if (result instanceof Boolean) { + supportParallel = ((Boolean) result).booleanValue(); + } else { + // Should never happen + System.out.println("Error: ClassLoader.registerAsParallelCapable() did not return a boolean!"); + System.exit(1); + } + } catch (NoSuchMethodException nsme) { + System.out.println("No ClassLoader.registerAsParallelCapable() API"); + } catch (NoSuchMethodError nsme2) { + System.out.println("No ClassLoader.registerAsParallelCapable() API"); + } catch (Exception ex) { + ex.printStackTrace(); + // Exit immediately to indicate an error + System.exit(1); + } + System.out.println("Parallel ClassLoader registration: " + + supportParallel); + } + + public DelegatingLoader(URL urls[]) { + super(urls); + System.out.println("DelegatingLoader using URL " + urls[0]); + } + + public void setDelegate(String[] delClasses, DelegatingLoader delLoader) { + this.delClasses = delClasses; + this.delLoader = delLoader; + } + + public Class loadClass(String className, boolean resolve) + throws ClassNotFoundException { + for (int i = 0; i < delClasses.length; i++) { + if (delClasses[i].equals(className)) { + Starter.log("Delegating class loading for " + className); + try { + Thread.sleep(500); + } catch (InterruptedException ie) { + return null; + } + return delLoader.loadClass(className, resolve); + } + } + + Starter.log("Loading local class " + className); +// synchronized (getClassLoadingLock(className)) { + return super.loadClass(className, resolve); +// } + } +} diff --git a/test/java/lang/ClassLoader/deadlock/Starter.java b/test/java/lang/ClassLoader/deadlock/Starter.java new file mode 100644 index 0000000000000000000000000000000000000000..c23edb92d31786b531219123a8481091d0bf66cb --- /dev/null +++ b/test/java/lang/ClassLoader/deadlock/Starter.java @@ -0,0 +1,105 @@ +/* + * 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. + * + * 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. + */ + +import java.net.MalformedURLException; +import java.net.URL; + +public class Starter implements Runnable { + + private String id; + private DelegatingLoader dl; + private String startClass; + + private static DelegatingLoader saLoader, sbLoader; + + public static void log(String line) { + System.out.println(line); + } + + public static void main(String[] args) { + URL[] urlsa = new URL[1]; + URL[] urlsb = new URL[1]; + try { + String testDir = System.getProperty("test.classes", "."); + String sep = System.getProperty("file.separator"); + urlsa[0] = new URL("file://" + testDir + sep + "SA" + sep); + urlsb[0] = new URL("file://" + testDir + sep + "SB" + sep); + } catch (MalformedURLException e) { + e.printStackTrace(); + } + // Set up Classloader delegation hierarchy + saLoader = new DelegatingLoader(urlsa); + sbLoader = new DelegatingLoader(urlsb); + + String[] saClasses = { "comSA.SupBob", "comSA.Alice" }; + String[] sbClasses = { "comSB.SupAlice", "comSB.Bob" }; + + saLoader.setDelegate(sbClasses, sbLoader); + sbLoader.setDelegate(saClasses, saLoader); + + // test one-way delegate + String testType = args[0]; + if (testType.equals("one-way")) { + test("comSA.Alice", "comSA.SupBob"); + } else if (testType.equals("cross")) { + // test cross delegate + test("comSA.Alice", "comSB.Bob"); + } else { + System.out.println("ERROR: unsupported - " + testType); + } + } + + private static void test(String clsForSA, String clsForSB) { + Starter ia = new Starter("SA", saLoader, clsForSA); + Starter ib = new Starter("SB", sbLoader, clsForSB); + new Thread(ia).start(); + new Thread(ib).start(); + } + + public static void sleep() { + try { + Thread.sleep(500); + } catch (InterruptedException e) { + e.printStackTrace(); + log("Thread interrupted"); + } + } + + private Starter(String id, DelegatingLoader dl, String startClass) { + this.id = id; + this.dl = dl; + this.startClass = startClass; + } + + public void run() { + log("Spawned thread " + id + " running"); + try { + // To mirror the WAS deadlock, need to ensure class load + // is routed via the VM. + Class.forName(startClass, true, dl); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } + log("Thread " + id + " terminating"); + } +} diff --git a/test/java/lang/ClassLoader/deadlock/SupAlice.java b/test/java/lang/ClassLoader/deadlock/SupAlice.java new file mode 100644 index 0000000000000000000000000000000000000000..4b04580e01bba85320409f2e77fe0a20030d406f --- /dev/null +++ b/test/java/lang/ClassLoader/deadlock/SupAlice.java @@ -0,0 +1,29 @@ +/* + * 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. + * + * 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 comSB; + +public class SupAlice { + static { + System.out.println("comSB.SupAlice loaded"); + } +} diff --git a/test/java/lang/ClassLoader/deadlock/SupBob.java b/test/java/lang/ClassLoader/deadlock/SupBob.java new file mode 100644 index 0000000000000000000000000000000000000000..05cfde319fd606d9d738446b4aa569396f61cb4e --- /dev/null +++ b/test/java/lang/ClassLoader/deadlock/SupBob.java @@ -0,0 +1,29 @@ +/* + * 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. + * + * 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 comSA; + +public class SupBob { + static { + System.out.println("comSA.SupBob loaded"); + } +} diff --git a/test/java/lang/ClassLoader/deadlock/TestCrossDelegate.sh b/test/java/lang/ClassLoader/deadlock/TestCrossDelegate.sh new file mode 100644 index 0000000000000000000000000000000000000000..5c1a1aeb65352887da5d95aa58ecc885be294aae --- /dev/null +++ b/test/java/lang/ClassLoader/deadlock/TestCrossDelegate.sh @@ -0,0 +1,105 @@ +# +# 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. +# +# 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. +# +# @test +# @bug 4735126 +# @summary (cl) ClassLoader.loadClass locks all instances in chain +# when delegating +# +# @run shell/timeout=10 TestCrossDelegate.sh + +# if running by hand on windows, change TESTSRC and TESTCLASSES to "." +if [ "${TESTSRC}" = "" ] ; then + TESTSRC=`pwd` +fi +if [ "${TESTCLASSES}" = "" ] ; then + TESTCLASSES=`pwd` +fi + +# if running by hand on windows, change this to appropriate value +if [ "${TESTJAVA}" = "" ] ; then + echo "TESTJAVA not set. Test cannot execute." + echo "FAILED!!!" + exit 1 +fi +echo TESTSRC=${TESTSRC} +echo TESTCLASSES=${TESTCLASSES} +echo TESTJAVA=${TESTJAVA} +echo "" + +# set platform-specific variables +OS=`uname -s` +case "$OS" in + SunOS ) + FS="/" + ;; + Linux ) + FS="/" + ;; + Windows* ) + FS="\\" + ;; +esac + +# compile test +${TESTJAVA}${FS}bin${FS}javac \ + -d ${TESTCLASSES} \ + ${TESTSRC}${FS}Starter.java ${TESTSRC}${FS}DelegatingLoader.java + +STATUS=$? +if [ ${STATUS} -ne 0 ] +then + exit ${STATUS} +fi + +# set up test +${TESTJAVA}${FS}bin${FS}javac \ + -d ${TESTCLASSES}${FS} \ + ${TESTSRC}${FS}Alice.java ${TESTSRC}${FS}SupBob.java \ + ${TESTSRC}${FS}Bob.java ${TESTSRC}${FS}SupAlice.java + +cd ${TESTCLASSES} +DIRS="SA SB" +for dir in $DIRS +do + if [ -d ${dir} ]; then + rm -rf ${dir} + fi + mkdir ${dir} + mv com${dir} ${dir} +done + +# run test +${TESTJAVA}${FS}bin${FS}java \ + -verbose:class -XX:+TraceClassLoading -cp . \ + -Dtest.classes=${TESTCLASSES} \ + Starter cross +# -XX:+UnlockDiagnosticVMOptions -XX:+UnsyncloadClass \ + +# save error status +STATUS=$? + +# clean up +rm -rf ${TESTCLASSES}${FS}SA ${TESTCLASSES}${FS}SB + +# return +exit ${STATUS} diff --git a/test/java/lang/ClassLoader/deadlock/TestOneWayDelegate.sh b/test/java/lang/ClassLoader/deadlock/TestOneWayDelegate.sh new file mode 100644 index 0000000000000000000000000000000000000000..1f6a08ff34252113a977b07bb5d6c6ee717773f0 --- /dev/null +++ b/test/java/lang/ClassLoader/deadlock/TestOneWayDelegate.sh @@ -0,0 +1,105 @@ +# +# 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. +# +# 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. +# +# @test +# @bug 4735126 +# @summary (cl) ClassLoader.loadClass locks all instances in chain +# when delegating +# +# @run shell/timeout=10 TestOneWayDelegate.sh + +# if running by hand on windows, change TESTSRC and TESTCLASSES to "." +if [ "${TESTSRC}" = "" ] ; then + TESTSRC=`pwd` +fi +if [ "${TESTCLASSES}" = "" ] ; then + TESTCLASSES=`pwd` +fi + +# if running by hand on windows, change this to appropriate value +if [ "${TESTJAVA}" = "" ] ; then + echo "TESTJAVA not set. Test cannot execute." + echo "FAILED!!!" + exit 1 +fi +echo TESTSRC=${TESTSRC} +echo TESTCLASSES=${TESTCLASSES} +echo TESTJAVA=${TESTJAVA} +echo "" + +# set platform-specific variables +OS=`uname -s` +case "$OS" in + SunOS ) + FS="/" + ;; + Linux ) + FS="/" + ;; + Windows* ) + FS="\\" + ;; +esac + +# compile test +${TESTJAVA}${FS}bin${FS}javac \ + -d ${TESTCLASSES} \ + ${TESTSRC}${FS}Starter.java ${TESTSRC}${FS}DelegatingLoader.java + +STATUS=$? +if [ ${STATUS} -ne 0 ] +then + exit ${STATUS} +fi + +# set up test +${TESTJAVA}${FS}bin${FS}javac \ + -d ${TESTCLASSES}${FS} \ + ${TESTSRC}${FS}Alice.java ${TESTSRC}${FS}SupBob.java \ + ${TESTSRC}${FS}Bob.java ${TESTSRC}${FS}SupAlice.java + +cd ${TESTCLASSES} +DIRS="SA SB" +for dir in $DIRS +do + if [ -d ${dir} ]; then + rm -rf ${dir} + fi + mkdir ${dir} + mv com${dir} ${dir} +done + +# run test +${TESTJAVA}${FS}bin${FS}java \ + -verbose:class -XX:+TraceClassLoading -cp . \ + -Dtest.classes=${TESTCLASSES} \ + Starter one-way +# -XX:+UnlockDiagnosticVMOptions -XX:+UnsyncloadClass \ + +# save error status +STATUS=$? + +# clean up +rm -rf ${TESTCLASSES}${FS}SA ${TESTCLASSES}${FS}SB + +# return +exit ${STATUS} diff --git a/test/java/lang/Integer/ValueOf.java b/test/java/lang/Integer/ValueOf.java new file mode 100644 index 0000000000000000000000000000000000000000..c6f47f571eeef1a0b443ff19190fc5ab499384b0 --- /dev/null +++ b/test/java/lang/Integer/ValueOf.java @@ -0,0 +1,55 @@ +/* + * 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. + * + * 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. + */ + +/** + * @test + * @bug 6807702 + * @summary Basic test for Integer.valueOf + * @run main ValueOf + * @run main/othervm -esa -XX:+AggressiveOpts ValueOf + */ + +public class ValueOf { + + // test Integer.valueOf over this range (inclusive) + private static final int TEST_LOW = -1024; + private static final int TEST_HIGH = 24576; + + public static void main(String[] args) { + int i = TEST_LOW; + while (i <= TEST_HIGH) { + // check that valueOf stores i + if (Integer.valueOf(i).intValue() != i) + throw new RuntimeException(); + + // check that the same object is returned for integral values + // in the range -128 to 127 (inclusive) + if (i >= -128 && i <= 127) { + if (Integer.valueOf(i) != Integer.valueOf(i)) + throw new RuntimeException(); + } + + i++; + } + } +} diff --git a/test/java/lang/String/ToLowerCase.java b/test/java/lang/String/ToLowerCase.java index 84d5d5af208f80fb45d0c310203a13c373ffee71..5d43b45ee0628cac37a4c819ee5acf77beb8c571 100644 --- a/test/java/lang/String/ToLowerCase.java +++ b/test/java/lang/String/ToLowerCase.java @@ -72,7 +72,7 @@ public class ToLowerCase { // I-dot tests (Turkish and Azeri) test("\u0130", turkish, "i"); test("\u0130", az, "i"); - test("\u0130", Locale.US, "i"); + test("\u0130", Locale.US, "i\u0307"); // Remove dot_above in the sequence I + dot_above (Turkish and Azeri) test("I\u0307", turkish, "i"); diff --git a/test/java/lang/Thread/StartOOMTest.java b/test/java/lang/Thread/StartOOMTest.java index dd8b519453e599b65836a6fcfc486c1f86f20b6e..260d0929703c6190a9309b8e8ea7f0b15d4059e9 100644 --- a/test/java/lang/Thread/StartOOMTest.java +++ b/test/java/lang/Thread/StartOOMTest.java @@ -24,6 +24,7 @@ /* * @test * @bug 6379235 + * @ignore until 6721694 is fixed * @run main/othervm -server -Xmx32m -Xms32m -Xss256m StartOOMTest * @summary ThreadGroup accounting mistake possible with failure of Thread.start() */ diff --git a/test/java/lang/reflect/Method/InheritedMethods.java b/test/java/lang/reflect/Method/InheritedMethods.java index 943767fb85f64f3ce427b81cbe1bed8f2991eadd..7b54f7b1edc6fdae7efece197ad28cdf1fe440d4 100644 --- a/test/java/lang/reflect/Method/InheritedMethods.java +++ b/test/java/lang/reflect/Method/InheritedMethods.java @@ -23,6 +23,7 @@ /* @test @bug 4471738 + @ignore until 6825739 fixed @summary Failure to properly traverse class hierarchy in Class.getMethod() */ diff --git a/test/java/nio/channels/AsyncCloseAndInterrupt.java b/test/java/nio/channels/AsyncCloseAndInterrupt.java index 834e7431eb64c5627361b0c8c33f9b94d96d5273..1755d0170dc3b42a554eb8e47ce0e5f77acb82be 100644 --- a/test/java/nio/channels/AsyncCloseAndInterrupt.java +++ b/test/java/nio/channels/AsyncCloseAndInterrupt.java @@ -22,7 +22,7 @@ */ /* @test - * @bug 4460583 4470470 4840199 6419424 6710579 6596323 + * @bug 4460583 4470470 4840199 6419424 6710579 6596323 6824135 * @summary Comprehensive test of asynchronous closing and interruption * @author Mark Reinhold */ diff --git a/test/java/nio/channels/AsynchronousChannelGroup/AsExecutor.java b/test/java/nio/channels/AsynchronousChannelGroup/AsExecutor.java new file mode 100644 index 0000000000000000000000000000000000000000..995c00ffd1eff2151ec1b897cf95224e35e08f7f --- /dev/null +++ b/test/java/nio/channels/AsynchronousChannelGroup/AsExecutor.java @@ -0,0 +1,81 @@ +/* + * Copyright 2008-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. + * + * 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. + */ + +import java.nio.channels.AsynchronousChannelGroup; +import java.util.concurrent.*; + +/** + * Test that arbitrary tasks can be submitted to a channel group's thread pool. + */ + +public class AsExecutor { + + public static void main(String[] args) throws Exception { + // create channel groups + ThreadFactory factory = new PrivilegedThreadFactory(); + AsynchronousChannelGroup group1 = AsynchronousChannelGroup + .withFixedThreadPool(5, factory); + AsynchronousChannelGroup group2 = AsynchronousChannelGroup + .withCachedThreadPool(Executors.newCachedThreadPool(factory), 0); + + try { + // execute simple tasks + testSimpleTask(group1); + testSimpleTask(group2); + + // install security manager and test again + System.setSecurityManager( new SecurityManager() ); + testSimpleTask(group1); + testSimpleTask(group2); + + // attempt to execute tasks that run with only frames from boot + // class loader on the stack. + testAttackingTask(group1); + testAttackingTask(group2); + } finally { + group1.shutdown(); + group2.shutdown(); + } + } + + static void testSimpleTask(AsynchronousChannelGroup group) throws Exception { + Executor executor = (Executor)group; + final CountDownLatch latch = new CountDownLatch(1); + executor.execute(new Runnable() { + public void run() { + latch.countDown(); + } + }); + latch.await(); + } + + static void testAttackingTask(AsynchronousChannelGroup group) throws Exception { + Executor executor = (Executor)group; + Attack task = new Attack(); + executor.execute(task); + task.waitUntilDone(); + if (!task.failedDueToSecurityException()) + throw new RuntimeException("SecurityException expected"); + } + +} diff --git a/test/java/nio/channels/AsynchronousChannelGroup/Attack.java b/test/java/nio/channels/AsynchronousChannelGroup/Attack.java new file mode 100644 index 0000000000000000000000000000000000000000..491926c86f4da348993d6ee8733fb5cfc3063c77 --- /dev/null +++ b/test/java/nio/channels/AsynchronousChannelGroup/Attack.java @@ -0,0 +1,63 @@ +/* + * Copyright 2008-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. + * + * 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. + */ + +import java.net.*; +import java.io.IOException; +import java.util.concurrent.CountDownLatch; + +/** + * A task that attempts to attack the current host. + */ + +public class Attack implements Runnable { + private final CountDownLatch latch = new CountDownLatch(1); + private volatile boolean failedDueToSecurityException; + + public void Attack() { + // check class is on boot class path + if (Attack.class.getClassLoader() != null) + throw new RuntimeException("Attack class not on boot class path"); + } + + @Override + public void run() { + try { + new Socket("127.0.0.1", 9999).close(); + throw new RuntimeException("Connected (not expected)"); + } catch (IOException e) { + throw new RuntimeException("IOException (not expected)"); + } catch (SecurityException e) { + failedDueToSecurityException = true; + } finally { + latch.countDown(); + } + } + + public void waitUntilDone() throws InterruptedException { + latch.await(); + } + + public boolean failedDueToSecurityException() { + return failedDueToSecurityException; + } +} diff --git a/test/java/nio/channels/AsynchronousChannelGroup/BadProperties.java b/test/java/nio/channels/AsynchronousChannelGroup/BadProperties.java new file mode 100644 index 0000000000000000000000000000000000000000..7c109b1fe193f3c2926a4b180a0863ef0a21efcd --- /dev/null +++ b/test/java/nio/channels/AsynchronousChannelGroup/BadProperties.java @@ -0,0 +1,41 @@ +/* + * Copyright 2008-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. + * + * 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. + */ + +/* @test + * @bug 4607272 + * @summary Unit test for AsynchronousChannelGroup + * @build BadProperties + * @run main/othervm/fail -Djava.nio.channels.DefaultThreadPool.threadFactory BadProperties + * @run main/othervm/fail -Djava.nio.channels.DefaultThreadPool.threadFactory=Missing BadProperties + * @run main/othervm/fail -Djava.nio.channels.DefaultThreadPool.initialSize BadProperties + * @run main/othervm/fail -Djava.nio.channels.DefaultThreadPool.initialSize=NaN BadProperties + */ + +import java.nio.channels.AsynchronousSocketChannel; +import java.io.IOException; + +public class BadProperties { + public static void main(String[] args) throws IOException { + AsynchronousSocketChannel.open(); + } +} diff --git a/test/java/nio/channels/AsynchronousChannelGroup/Basic.java b/test/java/nio/channels/AsynchronousChannelGroup/Basic.java new file mode 100644 index 0000000000000000000000000000000000000000..f26ed171d71d689934366c3e5d7771fe3c97429c --- /dev/null +++ b/test/java/nio/channels/AsynchronousChannelGroup/Basic.java @@ -0,0 +1,259 @@ +/* + * Copyright 2008-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. + * + * 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. + */ + +/* @test + * @bug 4607272 + * @summary Unit test for AsynchronousChannelGroup + * @build Basic + * @run main/othervm -XX:-UseVMInterruptibleIO Basic + */ + +import java.nio.ByteBuffer; +import java.nio.channels.*; +import java.net.*; +import java.util.*; +import java.util.concurrent.*; +import java.io.IOException; + +public class Basic { + static final Random rand = new Random(); + static final ThreadFactory threadFactory = new ThreadFactory() { + @Override + public Thread newThread(final Runnable r) { + return new Thread(r); + }}; + + + public static void main(String[] args) throws Exception { + shutdownTests(); + shutdownNowTests(); + afterShutdownTests(); + miscTests(); + } + + static void shutdownTests() throws Exception { + System.out.println("-- test shutdown --"); + + // test shutdown with no channels in groups + for (int i=0; i<500; i++) { + ExecutorService pool = null; + AsynchronousChannelGroup group; + if (rand.nextBoolean()) { + pool = Executors.newCachedThreadPool(); + group = AsynchronousChannelGroup.withCachedThreadPool(pool, rand.nextInt(5)); + } else { + int nThreads = 1 + rand.nextInt(8); + group = AsynchronousChannelGroup.withFixedThreadPool(nThreads, threadFactory); + } + group.shutdown(); + if (!group.isShutdown()) + throw new RuntimeException("Group should be shutdown"); + // group should terminate quickly + boolean terminated = group.awaitTermination(3, TimeUnit.SECONDS); + if (!terminated) + throw new RuntimeException("Group should have terminated"); + if (pool != null && !pool.isTerminated()) + throw new RuntimeException("Executor should have terminated"); + } + + // shutdown with channel in group + for (int i=0; i<500; i++) { + ExecutorService pool = null; + AsynchronousChannelGroup group; + if (rand.nextBoolean()) { + pool = Executors.newCachedThreadPool(); + group = AsynchronousChannelGroup.withCachedThreadPool(pool, rand.nextInt(10)); + } else { + int nThreads = 1 + rand.nextInt(8); + group = AsynchronousChannelGroup.withFixedThreadPool(nThreads, threadFactory); + } + // create channel that is bound to group + AsynchronousChannel ch; + switch (rand.nextInt(3)) { + case 0 : ch = AsynchronousSocketChannel.open(group); break; + case 1 : ch = AsynchronousServerSocketChannel.open(group); break; + case 2 : ch = AsynchronousDatagramChannel.open(null, group); break; + default : throw new AssertionError(); + } + group.shutdown(); + if (!group.isShutdown()) + throw new RuntimeException("Group should be shutdown"); + + // last channel so should terminate after this channel is closed + ch.close(); + + // group should terminate quickly + boolean terminated = group.awaitTermination(3, TimeUnit.SECONDS); + if (!terminated) + throw new RuntimeException("Group should have terminated"); + if (pool != null && !pool.isTerminated()) + throw new RuntimeException("Executor should have terminated"); + } + } + + static void shutdownNowTests() throws Exception { + System.out.println("-- test shutdownNow --"); + + for (int i=0; i< 10; i++) { + ExecutorService pool = null; + AsynchronousChannelGroup group; + if (rand.nextBoolean()) { + pool = Executors.newCachedThreadPool(); + group = AsynchronousChannelGroup + .withCachedThreadPool(pool, rand.nextInt(5)); + } else { + int nThreads = 1 + rand.nextInt(8); + group = AsynchronousChannelGroup + .withFixedThreadPool(nThreads, threadFactory); + } + + // I/O in progress + AsynchronousChannel ch; + if (rand.nextBoolean()) { + AsynchronousServerSocketChannel listener = AsynchronousServerSocketChannel + .open(group).bind(new InetSocketAddress(0)); + listener.accept(); + ch = listener; + } else { + AsynchronousDatagramChannel adc = + AsynchronousDatagramChannel.open(null, group); + adc.receive(ByteBuffer.allocate(100)); + ch = adc; + } + + // forceful shutdown + group.shutdownNow(); + + // shutdownNow is required to close all channels + if (ch.isOpen()) + throw new RuntimeException("Channel should be closed"); + + boolean terminated = group.awaitTermination(3, TimeUnit.SECONDS); + if (!terminated) + throw new RuntimeException("Group should have terminated"); + if (pool != null && !pool.isTerminated()) + throw new RuntimeException("Executor should have terminated"); + } + } + + // test creating channels in group after group is shutdown + static void afterShutdownTests() throws Exception { + System.out.println("-- test operations after group is shutdown --"); + AsynchronousChannelGroup group = + AsynchronousChannelGroup.withFixedThreadPool(1, threadFactory); + + AsynchronousSocketChannel ch = AsynchronousSocketChannel.open(group); + AsynchronousServerSocketChannel listener = AsynchronousServerSocketChannel.open(group); + + // initiate accept + listener.bind(new InetSocketAddress(0)); + Future<AsynchronousSocketChannel> result = listener.accept(); + + // shutdown group + group.shutdown(); + if (!group.isShutdown()) + throw new RuntimeException("Group should be shutdown"); + + // attempt to create another channel + try { + AsynchronousSocketChannel.open(group); + throw new RuntimeException("ShutdownChannelGroupException expected"); + } catch (ShutdownChannelGroupException x) { + } + try { + AsynchronousServerSocketChannel.open(group); + throw new RuntimeException("ShutdownChannelGroupException expected"); + } catch (ShutdownChannelGroupException x) { + } + + // attempt to create another channel by connecting. This should cause + // the accept operation to fail. + InetAddress lh = InetAddress.getLocalHost(); + int port = ((InetSocketAddress)listener.getLocalAddress()).getPort(); + InetSocketAddress isa = new InetSocketAddress(lh, port); + ch.connect(isa).get(); + try { + result.get(); + throw new RuntimeException("Connection was accepted"); + } catch (ExecutionException x) { + Throwable cause = x.getCause(); + if (!(cause instanceof IOException)) + throw new RuntimeException("Cause should be IOException"); + cause = cause.getCause(); + if (!(cause instanceof ShutdownChannelGroupException)) + throw new RuntimeException("IOException cause should be ShutdownChannelGroupException"); + } + + // initiate another accept even though channel group is shutdown. + Future<AsynchronousSocketChannel> res = listener.accept(); + try { + res.get(3, TimeUnit.SECONDS); + throw new RuntimeException("TimeoutException expected"); + } catch (TimeoutException x) { + } + // connect to the listener which should cause the accept to complete + AsynchronousSocketChannel.open().connect(isa); + try { + res.get(); + throw new RuntimeException("Connection was accepted"); + } catch (ExecutionException x) { + Throwable cause = x.getCause(); + if (!(cause instanceof IOException)) + throw new RuntimeException("Cause should be IOException"); + cause = cause.getCause(); + if (!(cause instanceof ShutdownChannelGroupException)) + throw new RuntimeException("IOException cause should be ShutdownChannelGroupException"); + } + + // group should *not* terminate as channels are open + boolean terminated = group.awaitTermination(3, TimeUnit.SECONDS); + if (terminated) + throw new RuntimeException("Group should not have terminated"); + + // close channel; group should terminate quickly + ch.close(); + listener.close(); + terminated = group.awaitTermination(3, TimeUnit.SECONDS); + if (!terminated) + throw new RuntimeException("Group should have terminated"); + } + + static void miscTests() throws Exception { + System.out.println("-- miscellenous tests --"); + try { + AsynchronousChannelGroup.withFixedThreadPool(1, null); + throw new RuntimeException("NPE expected"); + } catch (NullPointerException x) { + } + try { + AsynchronousChannelGroup.withFixedThreadPool(0, threadFactory); + throw new RuntimeException("IAE expected"); + } catch (IllegalArgumentException e) { + } + try { + AsynchronousChannelGroup.withCachedThreadPool(null, 0); + throw new RuntimeException("NPE expected"); + } catch (NullPointerException x) { + } + } +} diff --git a/test/java/nio/channels/AsynchronousChannelGroup/GroupOfOne.java b/test/java/nio/channels/AsynchronousChannelGroup/GroupOfOne.java new file mode 100644 index 0000000000000000000000000000000000000000..b116245ceaf6cb2aebe9a8ca74975e7b93462b07 --- /dev/null +++ b/test/java/nio/channels/AsynchronousChannelGroup/GroupOfOne.java @@ -0,0 +1,140 @@ +/* + * Copyright 2008-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. + * + * 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. + */ + +/* @test + * @bug 4607272 + * @summary Unit test for AsynchronousChannelGroup + */ + +import java.nio.ByteBuffer; +import java.nio.channels.*; +import java.net.*; +import java.util.concurrent.*; +import java.io.IOException; + +/** + * This test verifies that a channel or channel group can be closed from a + * completion handler when there are no threads available to handle I/O events. + */ + +public class GroupOfOne { + + public static void main(String[] args) throws Exception { + // create listener to accept connections + final AsynchronousServerSocketChannel listener = + AsynchronousServerSocketChannel.open() + .bind(new InetSocketAddress(0)); + listener.accept(null, new CompletionHandler<AsynchronousSocketChannel,Void>() { + public void completed(AsynchronousSocketChannel ch, Void att) { + listener.accept(null, this); + } + public void failed(Throwable exc, Void att) { + } + public void cancelled(Void att) { + } + }); + + int port = ((InetSocketAddress)(listener.getLocalAddress())).getPort(); + SocketAddress sa = new InetSocketAddress(InetAddress.getLocalHost(), port); + + test(sa, true, false); + test(sa, false, true); + test(sa, true, true); + } + + static void test(SocketAddress sa, + final boolean closeChannel, + final boolean shutdownGroup) + throws Exception + { + // group with 1 thread + final AsynchronousChannelGroup group = AsynchronousChannelGroup + .withFixedThreadPool(1, new ThreadFactory() { + @Override + public Thread newThread(final Runnable r) { + return new Thread(r); + }}); + final AsynchronousSocketChannel ch = AsynchronousSocketChannel.open(group); + + // the latch counts down when: + // 1. The read operation fails (expected) + // 2. the close/shutdown completes + final CountDownLatch latch = new CountDownLatch(2); + + ch.connect(sa, null, new CompletionHandler<Void,Void>() { + public void completed(Void result, Void att) { + System.out.println("Connected"); + + // initiate I/O operation that does not complete (successfully) + ByteBuffer buf = ByteBuffer.allocate(100); + ch.read(buf, null, new CompletionHandler<Integer,Void>() { + public void completed(Integer bytesRead, Void att) { + throw new RuntimeException(); + } + public void failed(Throwable exc, Void att) { + if (!(exc instanceof AsynchronousCloseException)) + throw new RuntimeException(exc); + System.out.println("Read failed (expected)"); + latch.countDown(); + } + public void cancelled(Void att) { + throw new RuntimeException(); + } + }); + + // close channel or shutdown group + try { + if (closeChannel) { + System.out.print("Close channel ..."); + ch.close(); + System.out.println(" done."); + } + if (shutdownGroup) { + System.out.print("Shutdown group ..."); + group.shutdownNow(); + System.out.println(" done."); + } + latch.countDown(); + } catch (IOException e) { + throw new RuntimeException(); + } + } + public void failed(Throwable exc, Void att) { + throw new RuntimeException(exc); + } + public void cancelled(Void att) { + throw new RuntimeException(); + } + }); + + latch.await(); + + // clean-up + group.shutdown(); + boolean terminated = group.awaitTermination(5, TimeUnit.SECONDS); + if (!terminated) + throw new RuntimeException("Group did not terminate"); + + System.out.println("TEST OKAY"); + } +} diff --git a/test/java/nio/channels/AsynchronousChannelGroup/Identity.java b/test/java/nio/channels/AsynchronousChannelGroup/Identity.java new file mode 100644 index 0000000000000000000000000000000000000000..f41c12c807f7265fca2fe1708f9453243c3c0e9b --- /dev/null +++ b/test/java/nio/channels/AsynchronousChannelGroup/Identity.java @@ -0,0 +1,166 @@ +/* + * Copyright 2008-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. + * + * 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. + */ + +/* @test + * @bug 4607272 + * @summary Unit test for AsynchronousChannelGroup + */ + +import java.nio.ByteBuffer; +import java.nio.channels.*; +import java.net.*; +import java.util.*; +import java.util.concurrent.*; +import java.util.concurrent.atomic.*; + +/** + * Tests that the completion handler is invoked by a thread with + * the expected identity. + */ + +public class Identity { + static final Random rand = new Random(); + static final CountDownLatch done = new CountDownLatch(1); + static final AtomicBoolean failed = new AtomicBoolean(false); + + static void fail(String msg) { + failed.set(true); + done.countDown(); + throw new RuntimeException(msg); + } + + // thread-local identifies the thread + private static final ThreadLocal<Integer> myGroup = + new ThreadLocal<Integer>() { + @Override protected Integer initialValue() { + return Integer.valueOf(-1); + } + }; + + // creates a ThreadFactory that constructs groups with the given identity + static final ThreadFactory createThreadFactory(final int groupId) { + return new ThreadFactory() { + @Override + public Thread newThread(final Runnable r) { + Thread t = new Thread(new Runnable() { + public void run() { + myGroup.set(groupId); + r.run(); + }}); + t.setDaemon(true); + return t; + } + }; + } + + public static void main(String[] args) throws Exception { + // create listener to accept connections + final AsynchronousServerSocketChannel listener = + AsynchronousServerSocketChannel.open() + .bind(new InetSocketAddress(0)); + listener.accept(null, new CompletionHandler<AsynchronousSocketChannel,Void>() { + public void completed(final AsynchronousSocketChannel ch, Void att) { + listener.accept(null, this); + + final ByteBuffer buf = ByteBuffer.allocate(100); + ch.read(buf, null, new CompletionHandler<Integer,Void>() { + public void completed(Integer bytesRead, Void att) { + buf.clear(); + ch.read(buf, null, this); + } + public void failed(Throwable exc, Void att) { + } + public void cancelled(Void att) { + } + }); + } + public void failed(Throwable exc, Void att) { + } + public void cancelled(Void att) { + } + }); + int port = ((InetSocketAddress)(listener.getLocalAddress())).getPort(); + SocketAddress sa = new InetSocketAddress(InetAddress.getLocalHost(), port); + + // create 3-10 channels, each in its own group + final int groupCount = 3 + rand.nextInt(8); + final AsynchronousSocketChannel[] channel = new AsynchronousSocketChannel[groupCount]; + for (int i=0; i<groupCount; i++) { + ThreadFactory factory = createThreadFactory(i); + AsynchronousChannelGroup group; + if (rand.nextBoolean()) { + int nThreads = 1 + rand.nextInt(10); + group = AsynchronousChannelGroup.withFixedThreadPool(nThreads, factory); + } else { + ExecutorService pool = Executors.newCachedThreadPool(factory); + group = AsynchronousChannelGroup.withCachedThreadPool(pool, rand.nextInt(5)); + } + + // create channel in group and connect it to the server + AsynchronousSocketChannel ch = AsynchronousSocketChannel.open(group); + ch.connect(sa).get(); + channel[i] = ch; + } + + // randomly write to each channel, ensuring that the completion handler + // is always invoked by a thread with the right identity. + final AtomicInteger writeCount = new AtomicInteger(100); + channel[0].write(getBuffer(), 0, new CompletionHandler<Integer,Integer>() { + public void completed(Integer bytesWritten, Integer groupId) { + if (bytesWritten != 1) + fail("Expected 1 byte to be written"); + if (!myGroup.get().equals(groupId)) + fail("Handler invoked by thread with the wrong identity"); + if (writeCount.decrementAndGet() > 0) { + int id = rand.nextInt(groupCount); + channel[id].write(getBuffer(), id, this); + } else { + done.countDown(); + } + } + public void failed(Throwable exc, Integer groupId) { + fail(exc.getMessage()); + } + public void cancelled(Integer groupId) { + fail("I/O operation was cancelled"); + } + }); + + // wait until + done.await(); + if (failed.get()) + throw new RuntimeException("Test failed - see log for details"); + } + + static ByteBuffer getBuffer() { + ByteBuffer buf; + if (rand.nextBoolean()) { + buf = ByteBuffer.allocateDirect(1); + } else { + buf = ByteBuffer.allocate(1); + } + buf.put((byte)0); + buf.flip(); + return buf; + } +} diff --git a/test/java/nio/channels/AsynchronousChannelGroup/PrivilegedThreadFactory.java b/test/java/nio/channels/AsynchronousChannelGroup/PrivilegedThreadFactory.java new file mode 100644 index 0000000000000000000000000000000000000000..e2c4575c72d727f9bdf807ae5a63487a7760b6e2 --- /dev/null +++ b/test/java/nio/channels/AsynchronousChannelGroup/PrivilegedThreadFactory.java @@ -0,0 +1,50 @@ +/* + * Copyright 2008-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. + * + * 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. + */ + +import java.util.concurrent.ThreadFactory; +import java.security.AccessController; +import java.security.PrivilegedAction; + +/** + * The "privileged" ThreadFactory used by the AsExecutor test. + */ + +public class PrivilegedThreadFactory implements ThreadFactory { + public void PrivilegedThreadPoolFactory() { + // check class is on boot class path + if (PrivilegedThreadFactory.class.getClassLoader() != null) + throw new RuntimeException("PrivilegedThreadFactory class not on boot class path"); + } + + @Override + public Thread newThread(final Runnable r) { + return AccessController.doPrivileged(new PrivilegedAction<Thread>() { + @Override + public Thread run() { + Thread t = new Thread(r); + t.setDaemon(true); + return t; + } + }); + } +} diff --git a/test/java/nio/channels/AsynchronousChannelGroup/Restart.java b/test/java/nio/channels/AsynchronousChannelGroup/Restart.java new file mode 100644 index 0000000000000000000000000000000000000000..567321e300855a6e2c1c5bbbe0b297ad8c86c718 --- /dev/null +++ b/test/java/nio/channels/AsynchronousChannelGroup/Restart.java @@ -0,0 +1,133 @@ +/* + * Copyright 2008-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. + * + * 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. + */ + +/* @test + * @bug 4607272 + * @summary Unit test for AsynchronousChannelGroup + * @build Restart + * @run main/othervm -XX:-UseVMInterruptibleIO Restart + */ + +import java.nio.channels.*; +import java.net.*; +import java.util.*; +import java.util.concurrent.*; +import java.util.concurrent.atomic.*; +import java.io.IOException; + +/** + * Exercise replacement of threads in the thread pool when completion handlers + * terminate due to errors or runtime exceptions. + */ + +public class Restart { + static final Random rand = new Random(); + + public static void main(String[] args) throws Exception { + // thread group for thread pools + final ThreadGroup tg = new ThreadGroup("test"); + + // keep track of the number of threads that terminate + final AtomicInteger exceptionCount = new AtomicInteger(0); + final Thread.UncaughtExceptionHandler ueh = + new Thread.UncaughtExceptionHandler() { + public void uncaughtException(Thread t, Throwable e) { + exceptionCount.incrementAndGet(); + } + }; + ThreadFactory factory = new ThreadFactory() { + @Override + public Thread newThread(Runnable r) { + Thread t = new Thread(tg, r); + t.setUncaughtExceptionHandler(ueh); + return t; + } + }; + + // group with fixed thread pool + int nThreads = 1 + rand.nextInt(4); + AsynchronousChannelGroup group = + AsynchronousChannelGroup.withFixedThreadPool(nThreads, factory); + testRestart(group, 100); + group.shutdown(); + + // group with custom thread pool + ExecutorService pool = Executors.newCachedThreadPool(factory); + group = AsynchronousChannelGroup.withCachedThreadPool(pool, rand.nextInt(5)); + testRestart(group, 100); + group.shutdown(); + + // give time for threads to terminate + Thread.sleep(3000); + int actual = exceptionCount.get(); + if (actual != 200) + throw new RuntimeException(actual + " exceptions, expected: " + 200); + } + + static void testRestart(AsynchronousChannelGroup group, int count) + throws Exception + { + AsynchronousServerSocketChannel listener = + AsynchronousServerSocketChannel.open(group) + .bind(new InetSocketAddress(0)); + + for (int i=0; i<count; i++) { + final CountDownLatch latch = new CountDownLatch(1); + + listener.accept(null, new CompletionHandler<AsynchronousSocketChannel,Void>() { + public void completed(AsynchronousSocketChannel ch, Void att) { + try { + ch.close(); + } catch (IOException ignore) { } + + latch.countDown(); + + // throw error or runtime exception + if (rand.nextBoolean()) { + throw new Error(); + } else { + throw new RuntimeException(); + } + } + public void failed(Throwable exc, Void att) { + } + public void cancelled(Void att) { + } + }); + + // establish loopback connection which should cause completion + // handler to be invoked. + int port = ((InetSocketAddress)(listener.getLocalAddress())).getPort(); + AsynchronousSocketChannel ch = AsynchronousSocketChannel.open(); + InetAddress lh = InetAddress.getLocalHost(); + ch.connect(new InetSocketAddress(lh, port)).get(); + ch.close(); + + // wait for handler to be invoked + latch.await(); + } + + // clean-up + listener.close(); + } +} diff --git a/test/java/nio/channels/AsynchronousChannelGroup/Unbounded.java b/test/java/nio/channels/AsynchronousChannelGroup/Unbounded.java new file mode 100644 index 0000000000000000000000000000000000000000..f615c3c5063b823da49378c317880f204a6e9cac --- /dev/null +++ b/test/java/nio/channels/AsynchronousChannelGroup/Unbounded.java @@ -0,0 +1,120 @@ +/* + * Copyright 2008-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. + * + * 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. + */ + +/* @test + * @bug 4607272 + * @summary Unit test for AsynchronousChannelGroup + */ + +import java.nio.ByteBuffer; +import java.nio.channels.*; +import java.net.*; +import java.util.concurrent.*; +import java.io.IOException; + +public class Unbounded { + // number of concurrent completion handlers + static final int CONCURRENCY_COUNT = 512; + + public static void main(String[] args) throws Exception { + // all accepted connections are added to a queue + final ArrayBlockingQueue<AsynchronousSocketChannel> queue = + new ArrayBlockingQueue<AsynchronousSocketChannel>(CONCURRENCY_COUNT); + + // create listener to accept connections + final AsynchronousServerSocketChannel listener = + AsynchronousServerSocketChannel.open() + .bind(new InetSocketAddress(0)); + listener.accept(null, new CompletionHandler<AsynchronousSocketChannel,Void>() { + public void completed(AsynchronousSocketChannel ch, Void att) { + queue.add(ch); + listener.accept(null, this); + } + public void failed(Throwable exc, Void att) { + } + public void cancelled(Void att) { + } + }); + System.out.println("Listener created."); + + // establish lots of connections + int port = ((InetSocketAddress)(listener.getLocalAddress())).getPort(); + SocketAddress sa = new InetSocketAddress(InetAddress.getLocalHost(), port); + AsynchronousSocketChannel[] channels = + new AsynchronousSocketChannel[CONCURRENCY_COUNT]; + for (int i=0; i<CONCURRENCY_COUNT; i++) { + int attempts = 0; + for (;;) { + try { + channels[i] = AsynchronousSocketChannel.open(); + channels[i].connect(sa).get(); + break; + } catch (IOException x) { + // probably resource issue so back off and retry + if (++attempts >= 3) + throw x; + Thread.sleep(50); + } + } + } + System.out.println("All connection established."); + + // the barrier where all threads (plus the main thread) wait + final CyclicBarrier barrier = new CyclicBarrier(CONCURRENCY_COUNT+1); + + // initiate a read operation on each channel. + for (int i=0; i<CONCURRENCY_COUNT; i++) { + ByteBuffer buf = ByteBuffer.allocateDirect(100); + channels[i].read( buf, channels[i], + new CompletionHandler<Integer,AsynchronousSocketChannel>() { + public void completed(Integer bytesRead, AsynchronousSocketChannel ch) { + try { + ch.close(); + barrier.await(); + } catch (Exception x) { + throw new AssertionError(x); + } + } + public void failed(Throwable exc, AsynchronousSocketChannel ch) { + } + public void cancelled(AsynchronousSocketChannel ch) { + } + }); + } + System.out.println("All read operations outstanding."); + + // write data to each of the accepted connections + int remaining = CONCURRENCY_COUNT; + while (remaining > 0) { + AsynchronousSocketChannel ch = queue.take(); + ch.write(ByteBuffer.wrap("welcome".getBytes())).get(); + ch.close(); + remaining--; + } + + // wait for all threads to reach the barrier + System.out.println("Waiting for all threads to reach barrier"); + barrier.await(); + listener.close(); + } +} diff --git a/test/java/nio/channels/AsynchronousChannelGroup/run_any_task.sh b/test/java/nio/channels/AsynchronousChannelGroup/run_any_task.sh new file mode 100644 index 0000000000000000000000000000000000000000..97f4f968a7652e52407ce7071a4738f3ff6184e6 --- /dev/null +++ b/test/java/nio/channels/AsynchronousChannelGroup/run_any_task.sh @@ -0,0 +1,52 @@ +# +# Copyright 2008-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. +# +# 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. +# + +# @test +# @bug 4607272 +# @summary Unit test for AsynchronousChannelGrou#execute +# @build AsExecutor PrivilegedThreadFactory Attack +# @run shell run_any_task.sh + +# if TESTJAVA isn't set then we assume an interactive run. + +if [ -z "$TESTJAVA" ]; then + TESTSRC=. + TESTCLASSES=. + JAVA=java + JAR=jar +else + JAVA="${TESTJAVA}/bin/java" + JAR="${TESTJAVA}/bin/jar" +fi + +echo "Creating JAR file ..." +$JAR -cf "${TESTCLASSES}/Privileged.jar" \ + -C "${TESTCLASSES}" PrivilegedThreadFactory.class \ + -C "${TESTCLASSES}" PrivilegedThreadFactory\$1.class \ + -C "${TESTCLASSES}" Attack.class + +echo "Running test ..." +$JAVA -XX:-UseVMInterruptibleIO \ + -Xbootclasspath/a:"${TESTCLASSES}/Privileged.jar" \ + -classpath "${TESTCLASSES}" \ + AsExecutor diff --git a/test/java/nio/channels/AsynchronousDatagramChannel/Basic.java b/test/java/nio/channels/AsynchronousDatagramChannel/Basic.java new file mode 100644 index 0000000000000000000000000000000000000000..5ed3d83a90dafa7dd70bc62f6e804777cdbe6835 --- /dev/null +++ b/test/java/nio/channels/AsynchronousDatagramChannel/Basic.java @@ -0,0 +1,448 @@ +/* + * Copyright 2008-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. + * + * 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. + */ + +/* @test + * @bug 4527345 + * @summary Unit test for AsynchronousDatagramChannel + */ + +import java.nio.ByteBuffer; +import java.nio.channels.*; +import java.net.*; +import java.util.concurrent.*; +import java.util.concurrent.atomic.*; + +public class Basic { + + public static void main(String[] args) throws Exception { + doReceiveTests(); + doReadTests(); + doSendTests(); + doWriteTests(); + doCancelTests(); + doMulticastTests(); + } + + // basic receive tests + static void doReceiveTests() throws Exception { + final byte[] msg = "hello".getBytes(); + + AsynchronousDatagramChannel ch = AsynchronousDatagramChannel.open() + .bind(new InetSocketAddress(0)); + int port = ((InetSocketAddress)(ch.getLocalAddress())).getPort(); + InetAddress rh = InetAddress.getLocalHost(); + final SocketAddress sa = new InetSocketAddress(rh, port); + + DatagramChannel sender = DatagramChannel.open(); + ByteBuffer dst = ByteBuffer.allocateDirect(100); + + // Test: datagram packet received immediately + sender.send(ByteBuffer.wrap(msg), sa); + dst.clear(); + ch.receive(dst).get(1, TimeUnit.SECONDS); + if (dst.flip().remaining() != msg.length) + throw new RuntimeException("Unexpected number of bytes read"); + + // Test: datagram packet not received immediately + dst.clear(); + final CountDownLatch latch = new CountDownLatch(1); + ch.receive(dst, null, new CompletionHandler<SocketAddress,Void>() { + public void completed(SocketAddress source, Void att) { + latch.countDown(); + } + public void failed (Throwable exc, Void att) { + } + public void cancelled(Void att) { + } + }); + Thread.sleep(2000); + sender.send(ByteBuffer.wrap(msg), sa); + latch.await(2, TimeUnit.SECONDS); // wait for completion handler + + // Test: timeout + dst.clear(); + final AtomicReference<Throwable> exception = new AtomicReference<Throwable>(); + ch.receive(dst, 2, TimeUnit.SECONDS, null, new CompletionHandler<SocketAddress,Void>() { + public void completed(SocketAddress source, Void att) { + } + public void failed (Throwable exc, Void att) { + exception.set(exc); + } + public void cancelled(Void att) { + } + }); + Throwable result; + while ((result = exception.get()) == null) { + Thread.sleep(100); + } + if (!(result instanceof InterruptedByTimeoutException)) + throw new RuntimeException("InterruptedByTimeoutException expected"); + + // AsynchronousCloseException + dst = ByteBuffer.allocateDirect(100); + exception.set(null); + ch.receive(dst, null, new CompletionHandler<SocketAddress,Void>() { + public void completed(SocketAddress source, Void att) { + } + public void failed (Throwable exc, Void att) { + exception.set(exc); + } + public void cancelled(Void att) { + } + }); + ch.close(); + while ((result = exception.get()) == null) { + Thread.sleep(100); + } + if (!(result instanceof AsynchronousCloseException)) + throw new RuntimeException("AsynchronousCloseException expected"); + + // done + sender.close(); + } + + // basic read tests + static void doReadTests() throws Exception { + final byte[] msg = "hello".getBytes(); + + AsynchronousDatagramChannel ch = AsynchronousDatagramChannel.open() + .bind(new InetSocketAddress(0)); + int port = ((InetSocketAddress)(ch.getLocalAddress())).getPort(); + InetAddress lh = InetAddress.getLocalHost(); + final SocketAddress sa = new InetSocketAddress(lh, port); + + DatagramChannel sender = DatagramChannel.open(); + ByteBuffer dst = ByteBuffer.allocateDirect(100); + + // Test: not connected + try { + ch.read(dst); + throw new RuntimeException("NotYetConnectedException expected"); + } catch (NotYetConnectedException e) { + } + + // connect the channel + sender.bind(new InetSocketAddress(0)); + ch.connect(new InetSocketAddress(lh, + ((InetSocketAddress)(sender.getLocalAddress())).getPort())); + + // Test: datagram packet received immediately + sender.send(ByteBuffer.wrap(msg), sa); + dst.clear(); + ch.read(dst).get(1, TimeUnit.SECONDS); + if (dst.flip().remaining() != msg.length) + throw new RuntimeException("Unexpected number of bytes read"); + + // Test: datagram packet not received immediately + dst.clear(); + final CountDownLatch l1 = new CountDownLatch(1); + ch.read(dst, null, new CompletionHandler<Integer,Void>() { + public void completed(Integer bytesRead, Void att) { + l1.countDown(); + } + public void failed (Throwable exc, Void att) { + } + public void cancelled(Void att) { + } + }); + Thread.sleep(2000); + sender.send(ByteBuffer.wrap(msg), sa); + l1.await(2, TimeUnit.SECONDS); + + // Test: timeout + dst.clear(); + final AtomicReference<Throwable> exception = new AtomicReference<Throwable>(); + ch.read(dst, 2, TimeUnit.SECONDS, null, new CompletionHandler<Integer,Void>() { + public void completed(Integer bytesRead, Void att) { + } + public void failed (Throwable exc, Void att) { + exception.set(exc); + } + public void cancelled(Void att) { + } + }); + Throwable result; + while ((result = exception.get()) == null) { + Thread.sleep(100); + } + if (!(result instanceof InterruptedByTimeoutException)) + throw new RuntimeException("InterruptedByTimeoutException expected"); + + // AsynchronousCloseException + dst.clear(); + exception.set(null); + ch.read(dst, null, new CompletionHandler<Integer,Void>() { + public void completed(Integer bytesRead, Void att) { + } + public void failed (Throwable exc, Void att) { + exception.set(exc); + } + public void cancelled(Void att) { + } + }); + ch.close(); + while ((result = exception.get()) == null) { + Thread.sleep(100); + } + if (!(result instanceof AsynchronousCloseException)) + throw new RuntimeException("AsynchronousCloseException expected"); + + // done + sender.close(); + } + + // basic send tests + static void doSendTests() throws Exception { + final byte[] msg = "hello".getBytes(); + + DatagramChannel reader = DatagramChannel.open() + .bind(new InetSocketAddress(0)); + int port = ((InetSocketAddress)(reader.getLocalAddress())).getPort(); + InetAddress rh = InetAddress.getLocalHost(); + SocketAddress sa = new InetSocketAddress(rh, port); + + AsynchronousDatagramChannel ch = AsynchronousDatagramChannel.open(); + + // Test: send datagram packet to reader + int bytesSent = ch.send(ByteBuffer.wrap(msg), sa).get(); + if (bytesSent != msg.length) + throw new RuntimeException("Unexpected number of bytes sent"); + + // check received + ByteBuffer dst = ByteBuffer.allocateDirect(100); + reader.receive(dst); + dst.flip(); + if (dst.remaining() != msg.length) + throw new RuntimeException("Unexpected number of bytes received"); + + // Test: send datagram packet to reader and check completion handler + // is invoked + final CountDownLatch l2 = new CountDownLatch(1); + ch.send(ByteBuffer.wrap(msg), sa, null, new CompletionHandler<Integer,Void>() { + public void completed(Integer bytesSent, Void att) { + if (bytesSent != msg.length) + throw new RuntimeException("Unexpected number of bytes received"); + l2.countDown(); + } + public void failed (Throwable exc, Void att) { + } + public void cancelled(Void att) { + } + }); + l2.await(5, TimeUnit.SECONDS); + + // check received + dst.clear(); + reader.receive(dst); + dst.flip(); + if (dst.remaining() != msg.length) + throw new RuntimeException("Unexpected number of bytes received"); + + // Test: check that failed method is invoked + ch.close(); + final CountDownLatch l3 = new CountDownLatch(1); + ch.send(ByteBuffer.wrap(msg), sa, null, new CompletionHandler<Integer,Void>() { + public void completed(Integer bytesSent, Void att) { + throw new RuntimeException("completed method invoked"); + } + public void failed (Throwable exc, Void att) { + if (exc instanceof ClosedChannelException) { + l3.countDown(); + } else { + throw new RuntimeException(exc); + } + } + public void cancelled(Void att) { + } + }); + l3.await(5, TimeUnit.SECONDS); + + // done + reader.close(); + } + + // basic write tests + static void doWriteTests() throws Exception { + final byte[] msg = "hello".getBytes(); + + DatagramChannel reader = DatagramChannel.open() + .bind(new InetSocketAddress(0)); + int port = ((InetSocketAddress)(reader.getLocalAddress())).getPort(); + InetAddress rh = InetAddress.getLocalHost(); + SocketAddress sa = new InetSocketAddress(rh, port); + + AsynchronousDatagramChannel ch = AsynchronousDatagramChannel.open(); + + // Test: unconnected + try { + ch.write(ByteBuffer.wrap(msg)).get(); + throw new RuntimeException("NotYetConnectedException expected"); + } catch (NotYetConnectedException e) { + } + + // Test: connect, and write datagram + ch.connect(sa); + int bytesSent = ch.write(ByteBuffer.wrap(msg)).get(); + if (bytesSent != msg.length) + throw new RuntimeException("Unexpected number of bytes sent"); + + // check received + ByteBuffer dst = ByteBuffer.allocateDirect(100); + reader.receive(dst); + dst.flip(); + if (dst.remaining() != msg.length) + throw new RuntimeException("Unexpected number of bytes received"); + + // Test: write datagram and check completion handler is invoked + final CountDownLatch l2 = new CountDownLatch(1); + ch.write(ByteBuffer.wrap(msg), null, new CompletionHandler<Integer,Void>() { + public void completed(Integer bytesSent, Void att) { + if (bytesSent != msg.length) + throw new RuntimeException("Unexpected number of bytes received"); + l2.countDown(); + } + public void failed (Throwable exc, Void att) { + } + public void cancelled(Void att) { + } + }); + l2.await(5, TimeUnit.SECONDS); + + // check received + dst.clear(); + reader.receive(dst); + dst.flip(); + if (dst.remaining() != msg.length) + throw new RuntimeException("Unexpected number of bytes received"); + + // done + ch.close(); + reader.close(); + } + + static void cancelAndCheck(Future<?> result, CountDownLatch latch) + throws InterruptedException + { + boolean cancelled = result.cancel(false); + if (!cancelled) + throw new RuntimeException("Not cancelled"); + if (!result.isDone()) + throw new RuntimeException("Should be done"); + try { + result.get(); + throw new RuntimeException("Result not expected"); + } catch (CancellationException e) { + // expected + } catch (ExecutionException e) { + throw new RuntimeException("Should not fail"); + } + + // make sure that completion handler is invoked + latch.await(); + } + + // basic cancel tests + static void doCancelTests() throws Exception { + InetAddress lh = InetAddress.getLocalHost(); + + // timed and non-timed receive + for (int i=0; i<2; i++) { + AsynchronousDatagramChannel ch = + AsynchronousDatagramChannel.open().bind(new InetSocketAddress(0)); + final CountDownLatch latch = new CountDownLatch(1); + long timeout = (i == 0) ? 0L : 60L; + Future<SocketAddress> remote = ch + .receive(ByteBuffer.allocate(100), timeout, TimeUnit.SECONDS, null, + new CompletionHandler<SocketAddress,Void>() { + public void completed(SocketAddress source, Void att) { + } + public void failed (Throwable exc, Void att) { + } + public void cancelled(Void att) { + latch.countDown(); + } + }); + cancelAndCheck(remote, latch); + ch.close(); + } + + // timed and non-timed read + for (int i=0; i<2; i++) { + AsynchronousDatagramChannel ch = + AsynchronousDatagramChannel.open().bind(new InetSocketAddress(0)); + ch.connect(new InetSocketAddress(lh, + ((InetSocketAddress)(ch.getLocalAddress())).getPort())); + final CountDownLatch latch = new CountDownLatch(1); + long timeout = (i == 0) ? 0L : 60L; + Future<Integer> result = ch + .read(ByteBuffer.allocate(100), timeout, TimeUnit.SECONDS, null, + new CompletionHandler<Integer,Void>() { + public void completed(Integer bytesRead, Void att) { + } + public void failed (Throwable exc, Void att) { + } + public void cancelled(Void att) { + latch.countDown(); + } + }); + cancelAndCheck(result, latch); + ch.close(); + } + } + + // basic multicast test + static void doMulticastTests() throws Exception { + final byte[] msg = "hello".getBytes(); + + AsynchronousDatagramChannel ch = AsynchronousDatagramChannel + .open(StandardProtocolFamily.INET, null) + .setOption(StandardSocketOption.SO_REUSEADDR, true) + .bind(new InetSocketAddress(0)); + + InetAddress lh = InetAddress.getLocalHost(); + int port = ((InetSocketAddress)(ch.getLocalAddress())).getPort(); + + // join group + InetAddress group = InetAddress.getByName("225.4.5.6"); + NetworkInterface interf = NetworkInterface.getByInetAddress(lh); + MembershipKey key = ch.join(group, interf); + + // check key + if (key.channel() != ch) + throw new RuntimeException("Not the expected channel"); + + // send message to group + DatagramChannel sender = DatagramChannel.open(); + sender.send(ByteBuffer.wrap(msg), new InetSocketAddress(group, port)); + sender.close(); + + // check message received + ByteBuffer dst = ByteBuffer.allocate(200); + SocketAddress source = ch.receive(dst).get(2, TimeUnit.SECONDS); + if (!((InetSocketAddress)source).getAddress().equals(lh)) + throw new RuntimeException("Unexpected source"); + + // done + ch.close(); + } +} diff --git a/test/java/nio/channels/AsynchronousFileChannel/Basic.java b/test/java/nio/channels/AsynchronousFileChannel/Basic.java new file mode 100644 index 0000000000000000000000000000000000000000..5ffb42c0b8bb85d3b58cfcc6e8ddfa0ca6a6cd1c --- /dev/null +++ b/test/java/nio/channels/AsynchronousFileChannel/Basic.java @@ -0,0 +1,585 @@ +/* + * Copyright 2008-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. + * + * 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. + */ + +/* @test + * @bug 4607272 + * @summary Unit test for AsynchronousFileChannel + */ + +import java.nio.file.*; +import java.nio.channels.*; +import java.nio.ByteBuffer; +import java.io.File; +import java.io.IOException; +import java.util.*; +import java.util.concurrent.*; +import java.util.concurrent.atomic.AtomicReference; +import static java.nio.file.StandardOpenOption.*; + +public class Basic { + + private static final Random rand = new Random(); + + public static void main(String[] args) throws IOException { + // create temporary file + File blah = File.createTempFile("blah", null); + blah.deleteOnExit(); + + final AsynchronousFileChannel ch = AsynchronousFileChannel + .open(blah.toPath(), READ, WRITE); + + // run tests + testUsingCompletionHandlers(ch); + testUsingWaitOnResult(ch); + testLocking(ch); + testInterruptHandlerThread(ch); + + // close channel and invoke test that expects channel to be closed + ch.close(); + testClosedChannel(ch); + + // these tests open the file themselves + testCustomThreadPool(blah.toPath()); + testAsynchronousClose(blah.toPath()); + testCancel(blah.toPath()); + testTruncate(blah.toPath()); + } + + /* + * Generate buffer with random contents + * Writes buffer to file using a CompletionHandler to consume the result + * of each write operation + * Reads file to EOF to a new buffer using a CompletionHandler to consume + * the result of each read operation + * Compares buffer contents + */ + static void testUsingCompletionHandlers(AsynchronousFileChannel ch) + throws IOException + { + System.out.println("testUsingCompletionHandlers"); + + ch.truncate(0L); + + // generate buffer with random elements and write it to file + ByteBuffer src = genBuffer(); + writeFully(ch, src, 0L); + + // read to EOF or buffer is full + ByteBuffer dst = (rand.nextBoolean()) ? + ByteBuffer.allocateDirect(src.capacity()) : + ByteBuffer.allocate(src.capacity()); + readAll(ch, dst, 0L); + + // check buffers are the same + src.flip(); + dst.flip(); + if (!src.equals(dst)) { + throw new RuntimeException("Contents differ"); + } + } + + /* + * Generate buffer with random contents + * Writes buffer to file, invoking the Future's get method to wait for + * each write operation to complete + * Reads file to EOF to a new buffer, invoking the Future's get method to + * wait for each write operation to complete + * Compares buffer contents + */ + static void testUsingWaitOnResult(AsynchronousFileChannel ch) + throws IOException + { + System.out.println("testUsingWaitOnResult"); + + ch.truncate(0L); + + // generate buffer + ByteBuffer src = genBuffer(); + + // write buffer completely to file + long position = 0L; + while (src.hasRemaining()) { + Future<Integer> result = ch.write(src, position); + try { + int n = result.get(); + // update position + position += n; + } catch (ExecutionException x) { + throw new RuntimeException(x.getCause()); + } catch (InterruptedException x) { + throw new RuntimeException(x); + } + } + + // read file into new buffer + ByteBuffer dst = (rand.nextBoolean()) ? + ByteBuffer.allocateDirect(src.capacity()) : + ByteBuffer.allocate(src.capacity()); + position = 0L; + int n; + do { + Future<Integer> result = ch.read(dst, position); + try { + n = result.get(); + + // update position + if (n > 0) position += n; + } catch (ExecutionException x) { + throw new RuntimeException(x.getCause()); + } catch (InterruptedException x) { + throw new RuntimeException(x); + } + } while (n > 0); + + // check buffers are the same + src.flip(); + dst.flip(); + if (!src.equals(dst)) { + throw new RuntimeException("Contents differ"); + } + } + + // exercise lock methods + static void testLocking(AsynchronousFileChannel ch) + throws IOException + { + System.out.println("testLocking"); + + // test 1 - acquire lock and check that tryLock throws + // OverlappingFileLockException + FileLock fl; + try { + fl = ch.lock().get(); + } catch (ExecutionException x) { + throw new RuntimeException(x); + } catch (InterruptedException x) { + throw new RuntimeException("Should not be interrupted"); + } + if (!fl.acquiredBy().equals(ch)) + throw new RuntimeException("FileLock#acquiredBy returned incorrect channel"); + try { + ch.tryLock(); + throw new RuntimeException("OverlappingFileLockException expected"); + } catch (OverlappingFileLockException x) { + } + fl.release(); + + // test 2 - acquire try and check that lock throws OverlappingFileLockException + fl = ch.tryLock(); + if (fl == null) + throw new RuntimeException("Unable to acquire lock"); + try { + ch.lock(null, new CompletionHandler<FileLock,Void> () { + public void completed(FileLock result, Void att) { + } + public void failed(Throwable exc, Void att) { + } + public void cancelled(Void att) { + } + }); + throw new RuntimeException("OverlappingFileLockException expected"); + } catch (OverlappingFileLockException x) { + } + fl.release(); + } + + // interrupt should not close channel + static void testInterruptHandlerThread(final AsynchronousFileChannel ch) { + System.out.println("testInterruptHandlerThread"); + + ByteBuffer buf = ByteBuffer.allocateDirect(100); + final CountDownLatch latch = new CountDownLatch(1); + + ch.read(buf, 0L, null, new CompletionHandler<Integer,Void>() { + public void completed(Integer result, Void att) { + try { + Thread.currentThread().interrupt(); + long size = ch.size(); + latch.countDown(); + } catch (IOException x) { + x.printStackTrace(); + } + } + public void failed(Throwable exc, Void att) { + } + public void cancelled(Void att) { + } + }); + + // wait for handler to complete + await(latch); + } + + // invoke method on closed channel + static void testClosedChannel(AsynchronousFileChannel ch) { + System.out.println("testClosedChannel"); + + if (ch.isOpen()) + throw new RuntimeException("Channel should be closed"); + + ByteBuffer buf = ByteBuffer.allocateDirect(100); + + // check read fails with ClosedChannelException + try { + ch.read(buf, 0L).get(); + throw new RuntimeException("ExecutionException expected"); + } catch (ExecutionException x) { + if (!(x.getCause() instanceof ClosedChannelException)) + throw new RuntimeException("Cause of ClosedChannelException expected"); + } catch (InterruptedException x) { + } + + // check write fails with ClosedChannelException + try { + ch.write(buf, 0L).get(); + throw new RuntimeException("ExecutionException expected"); + } catch (ExecutionException x) { + if (!(x.getCause() instanceof ClosedChannelException)) + throw new RuntimeException("Cause of ClosedChannelException expected"); + } catch (InterruptedException x) { + } + + // check lock fails with ClosedChannelException + try { + ch.lock().get(); + throw new RuntimeException("ExecutionException expected"); + } catch (ExecutionException x) { + if (!(x.getCause() instanceof ClosedChannelException)) + throw new RuntimeException("Cause of ClosedChannelException expected"); + } catch (InterruptedException x) { + } + } + + + // exercise custom thread pool + static void testCustomThreadPool(Path file) throws IOException { + System.out.println("testCustomThreadPool"); + + // records threads that are created + final List<Thread> threads = new ArrayList<Thread>(); + + ThreadFactory threadFactory = new ThreadFactory() { + @Override + public Thread newThread(Runnable r) { + Thread t = new Thread(r); + t.setDaemon(true); + synchronized (threads) { + threads.add(t); + } + return t; + } + }; + + // exercise tests with varied number of threads + for (int nThreads=1; nThreads<=5; nThreads++) { + synchronized (threads) { + threads.clear(); + } + ExecutorService executor = Executors.newFixedThreadPool(nThreads, threadFactory); + Set<StandardOpenOption> opts = EnumSet.of(WRITE); + AsynchronousFileChannel ch = AsynchronousFileChannel.open(file, opts, executor); + try { + for (int i=0; i<10; i++) { + // do I/O operation to see which thread invokes the completion handler + final AtomicReference<Thread> invoker = new AtomicReference<Thread>(); + final CountDownLatch latch = new CountDownLatch(1); + + ch.write(genBuffer(), 0L, null, new CompletionHandler<Integer,Void>() { + public void completed(Integer result, Void att) { + invoker.set(Thread.currentThread()); + latch.countDown(); + } + public void failed(Throwable exc, Void att) { + } + public void cancelled(Void att) { + } + }); + await(latch); + + // check invoker + boolean found = false; + synchronized (threads) { + for (Thread t: threads) { + if (t == invoker.get()) { + found = true; + break; + } + } + } + if (!found) + throw new RuntimeException("Invoker thread not found"); + } + } finally { + ch.close(); + } + } + } + + // exercise asynchronous close + static void testAsynchronousClose(Path file) throws IOException { + System.out.println("testAsynchronousClose"); + + // create file + AsynchronousFileChannel ch = AsynchronousFileChannel + .open(file, WRITE, TRUNCATE_EXISTING); + long size = 0L; + do { + ByteBuffer buf = genBuffer(); + int n = buf.remaining(); + writeFully(ch, buf, size); + size += n; + } while (size < (50L * 1024L * 1024L)); + + ch.close(); + + ch = AsynchronousFileChannel.open(file, WRITE, SYNC); + + // randomize number of writers, buffer size, and positions + + int nwriters = 1 + rand.nextInt(8); + ByteBuffer[] buf = new ByteBuffer[nwriters]; + long[] position = new long[nwriters]; + for (int i=0; i<nwriters; i++) { + buf[i] = genBuffer(); + position[i] = rand.nextInt((int)size); + } + + // initiate I/O + Future[] result = new Future[nwriters]; + for (int i=0; i<nwriters; i++) { + result[i] = ch.write(buf[i], position[i]); + } + + // close file + ch.close(); + + // write operations should complete or fail with AsynchronousCloseException + for (int i=0; i<nwriters; i++) { + try { + result[i].get(); + } catch (ExecutionException x) { + Throwable cause = x.getCause(); + if (!(cause instanceof AsynchronousCloseException)) + throw new RuntimeException(cause); + } catch (CancellationException x) { + throw new RuntimeException(x); // should not happen + } catch (InterruptedException x) { + throw new RuntimeException(x); // should not happen + } + } + } + + // exercise cancel method + static void testCancel(Path file) throws IOException { + System.out.println("testCancel"); + + for (int i=0; i<2; i++) { + boolean mayInterruptIfRunning = (i == 0) ? false : true; + + // open with SYNC option to improve chances that write will not + // complete immediately + AsynchronousFileChannel ch = AsynchronousFileChannel + .open(file, WRITE, SYNC); + + // start write operation + final CountDownLatch latch = new CountDownLatch(1); + Future<Integer> res = ch.write(genBuffer(), 0L, null, + new CompletionHandler<Integer,Void>() { + public void completed(Integer result, Void att) { + } + public void failed(Throwable exc, Void att) { + } + public void cancelled(Void att) { + latch.countDown(); + } + }); + + // cancel operation + boolean cancelled = res.cancel(mayInterruptIfRunning); + + // check post-conditions + if (!res.isDone()) + throw new RuntimeException("isDone should return true"); + if (res.isCancelled() != cancelled) + throw new RuntimeException("isCancelled not consistent"); + try { + res.get(); + if (!cancelled) + throw new RuntimeException("CancellationException expected"); + } catch (CancellationException x) { + // expected + } catch (ExecutionException x) { + throw new RuntimeException(x); + } catch (InterruptedException x) { + throw new RuntimeException(x); + } + try { + res.get(1, TimeUnit.SECONDS); + throw new RuntimeException("CancellationException expected"); + } catch (CancellationException x) { + // expected + } catch (ExecutionException x) { + throw new RuntimeException(x); + } catch (TimeoutException x) { + throw new RuntimeException(x); + } catch (InterruptedException x) { + throw new RuntimeException(x); + } + + // check that cancelled method is invoked + if (cancelled) + await(latch); + + ch.close(); + } + } + + // exercise truncate method + static void testTruncate(Path file) throws IOException { + System.out.println("testTruncate"); + + // basic tests + AsynchronousFileChannel ch = AsynchronousFileChannel + .open(file, CREATE, WRITE, TRUNCATE_EXISTING); + try { + writeFully(ch, genBuffer(), 0L); + long size = ch.size(); + + // attempt to truncate to a size greater than the current size + if (ch.truncate(size + 1L).size() != size) + throw new RuntimeException("Unexpected size after truncation"); + + // truncate file + if (ch.truncate(size - 1L).size() != (size - 1L)) + throw new RuntimeException("Unexpected size after truncation"); + + // invalid size + try { + ch.truncate(-1L); + throw new RuntimeException("IllegalArgumentException expected"); + } catch (IllegalArgumentException e) { } + + } finally { + ch.close(); + } + + // channel is closed + try { + ch.truncate(0L); + throw new RuntimeException("ClosedChannelException expected"); + } catch (ClosedChannelException e) { } + + // channel is read-only + ch = AsynchronousFileChannel.open(file, READ); + try { + try { + ch.truncate(0L); + throw new RuntimeException("NonWritableChannelException expected"); + } catch (NonWritableChannelException e) { } + } finally { + ch.close(); + } + } + + // returns ByteBuffer with random bytes + static ByteBuffer genBuffer() { + int size = 1024 + rand.nextInt(16000); + byte[] buf = new byte[size]; + boolean useDirect = rand.nextBoolean(); + if (useDirect) { + ByteBuffer bb = ByteBuffer.allocateDirect(buf.length); + bb.put(buf); + bb.flip(); + return bb; + } else { + return ByteBuffer.wrap(buf); + } + } + + // writes all remaining bytes in the buffer to the given channel at the + // given position + static void writeFully(final AsynchronousFileChannel ch, + final ByteBuffer src, + long position) + { + final CountDownLatch latch = new CountDownLatch(1); + + // use position as attachment + ch.write(src, position, position, new CompletionHandler<Integer,Long>() { + public void completed(Integer result, Long position) { + int n = result; + if (src.hasRemaining()) { + long p = position + n; + ch.write(src, p, p, this); + } else { + latch.countDown(); + } + } + public void failed(Throwable exc, Long position) { + } + public void cancelled(Long position) { + } + }); + + // wait for writes to complete + await(latch); + } + + static void readAll(final AsynchronousFileChannel ch, + final ByteBuffer dst, + long position) + { + final CountDownLatch latch = new CountDownLatch(1); + + // use position as attachment + ch.read(dst, position, position, new CompletionHandler<Integer,Long>() { + public void completed(Integer result, Long position) { + int n = result; + if (n > 0) { + long p = position + n; + ch.read(dst, p, p, this); + } else { + latch.countDown(); + } + } + public void failed(Throwable exc, Long position) { + } + public void cancelled(Long position) { + } + }); + + // wait for reads to complete + await(latch); + } + + static void await(CountDownLatch latch) { + // wait until done + boolean done = false; + while (!done) { + try { + latch.await(); + done = true; + } catch (InterruptedException x) { } + } + } +} diff --git a/test/java/nio/channels/AsynchronousFileChannel/CustomThreadPool.java b/test/java/nio/channels/AsynchronousFileChannel/CustomThreadPool.java new file mode 100644 index 0000000000000000000000000000000000000000..9f9025dd232bedaee786d8efdb21bfbf03f216f4 --- /dev/null +++ b/test/java/nio/channels/AsynchronousFileChannel/CustomThreadPool.java @@ -0,0 +1,67 @@ +/* + * Copyright 2008-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. + * + * 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. + */ + +/* @test + * @bug 4607272 + * @summary Unit test for java.nio.channels.AsynchronousFileChannel + * @build CustomThreadPool MyThreadFactory + * @run main/othervm -Djava.nio.channels.DefaultThreadPool.threadFactory=MyThreadFactory CustomThreadPool + */ + +import java.io.File; +import static java.nio.file.StandardOpenOption.*; +import java.nio.ByteBuffer; +import java.nio.channels.*; +import java.util.concurrent.atomic.AtomicReference; + +public class CustomThreadPool { + + public static void main(String[] args) throws Exception { + File blah = File.createTempFile("blah", null); + blah.deleteOnExit(); + AsynchronousFileChannel ch = + AsynchronousFileChannel.open(blah.toPath(), READ, WRITE); + ByteBuffer src = ByteBuffer.wrap("Scooby Snacks".getBytes()); + + final AtomicReference<Thread> invoker = new AtomicReference<Thread>(); + ch.write(src, 0, invoker, + new CompletionHandler<Integer,AtomicReference<Thread>>() { + public void completed(Integer result, AtomicReference<Thread> invoker) { + invoker.set(Thread.currentThread()); + } + public void failed(Throwable exc, AtomicReference<Thread> invoker) { + } + public void cancelled(AtomicReference<Thread> invoker) { + } + }); + Thread t; + while ((t = invoker.get()) == null) { + Thread.sleep(100); + } + ch.close(); + + // check handler was run by known thread + if (!MyThreadFactory.created(t)) + throw new RuntimeException("Handler invoked by unknown thread"); + } +} diff --git a/test/java/nio/channels/AsynchronousFileChannel/Lock.java b/test/java/nio/channels/AsynchronousFileChannel/Lock.java new file mode 100644 index 0000000000000000000000000000000000000000..38c0f7d0c6e39c735e622750f419aef110acaed6 --- /dev/null +++ b/test/java/nio/channels/AsynchronousFileChannel/Lock.java @@ -0,0 +1,340 @@ +/* + * Copyright 2008-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. + * + * 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. + */ + + +/* @test + * @bug 4607272 + * @summary Unit test for AsynchronousFileChannel#lock method + */ + +import java.net.*; +import java.nio.ByteBuffer; +import java.nio.charset.Charset; +import java.nio.file.*; +import static java.nio.file.StandardOpenOption.*; +import java.nio.channels.*; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.util.Random; +import java.util.concurrent.*; + +public class Lock { + + static final Random rand = new Random(); + + public static void main(String[] args) throws Exception { + if (args.length > 0 && args[0].equals("-lockslave")) { + int port = Integer.parseInt(args[1]); + runLockSlave(port); + System.exit(0); + } + + LockSlaveMirror slave = startLockSlave(); + try { + + // create temporary file + File blah = File.createTempFile("blah", null); + blah.deleteOnExit(); + + testLockProtocol(blah, slave); + testAsyncClose(blah, slave); + + } finally { + slave.shutdown(); + } + } + + // test locking protocol + static void testLockProtocol(File file, LockSlaveMirror slave) + throws Exception + { + FileLock fl; + + // slave VM opens file and acquires exclusive lock + slave.open(file.getPath()).lock(); + + AsynchronousFileChannel ch = AsynchronousFileChannel + .open(file.toPath(), READ, WRITE); + + // this VM tries to acquire lock + // (lock should not be acquire until released by slave VM) + Future<FileLock> result = ch.lock(); + try { + result.get(2, TimeUnit.SECONDS); + throw new RuntimeException("Timeout expected"); + } catch (TimeoutException x) { + } + + // slave VM releases lock + slave.unlock(); + + // this VM should now acquire lock + fl = result.get(); + fl.release(); + + // slave VM acquires lock on range + slave.lock(0, 10, false); + + // this VM acquires lock on non-overlapping range + fl = ch.lock(10, 10, false, null, null).get(); + fl.release(); + + // done + ch.close(); + slave.close(); + } + + // test close of channel with outstanding lock operation + static void testAsyncClose(File file, LockSlaveMirror slave) throws Exception { + // slave VM opens file and acquires exclusive lock + slave.open(file.getPath()).lock(); + + for (int i=0; i<100; i++) { + AsynchronousFileChannel ch = AsynchronousFileChannel + .open(file.toPath(), READ, WRITE); + + // try to lock file (should not complete because file is locked by slave) + Future<FileLock> result = ch.lock(); + try { + result.get(rand.nextInt(100), TimeUnit.MILLISECONDS); + throw new RuntimeException("Timeout expected"); + } catch (TimeoutException x) { + } + + // close channel with lock operation outstanding + ch.close(); + + // operation should complete with AsynchronousCloseException + try { + result.get(); + throw new RuntimeException("ExecutionException expected"); + } catch (ExecutionException x) { + if (!(x.getCause() instanceof AsynchronousCloseException)) { + x.getCause().printStackTrace(); + throw new RuntimeException("AsynchronousCloseException expected"); + } + } + } + + slave.close(); + } + + // starts a "lock slave" in another process, returning a mirror object to + // control the slave + static LockSlaveMirror startLockSlave() throws Exception { + ServerSocketChannel ssc = ServerSocketChannel.open() + .bind(new InetSocketAddress(0)); + int port = ((InetSocketAddress)(ssc.getLocalAddress())).getPort(); + + String sep = FileSystems.getDefault().getSeparator(); + + String command = System.getProperty("java.home") + + sep + "bin" + sep + "java Lock -lockslave " + port; + Process p = Runtime.getRuntime().exec(command); + IOHandler.handle(p.getInputStream()); + IOHandler.handle(p.getErrorStream()); + + // wait for slave to connect + SocketChannel sc = ssc.accept(); + return new LockSlaveMirror(sc); + } + + // commands that the slave understands + static final String OPEN_CMD = "open"; + static final String CLOSE_CMD = "close"; + static final String LOCK_CMD = "lock"; + static final String UNLOCK_CMD = "unlock"; + static final char TERMINATOR = ';'; + + // provides a proxy to a "lock slave" + static class LockSlaveMirror { + private final SocketChannel sc; + + LockSlaveMirror(SocketChannel sc) { + this.sc = sc; + } + + private void sendCommand(String cmd, String... params) + throws IOException + { + for (String s: params) { + cmd += " " + s; + } + cmd += TERMINATOR; + + ByteBuffer buf = Charset.defaultCharset().encode(cmd); + while (buf.hasRemaining()) { + sc.write(buf); + } + + // wait for ack + buf = ByteBuffer.allocate(1); + int n = sc.read(buf); + if (n != 1) + throw new RuntimeException("Reply expected"); + if (buf.get(0) != TERMINATOR) + throw new RuntimeException("Terminated expected"); + } + + LockSlaveMirror open(String file) throws IOException { + sendCommand(OPEN_CMD, file); + return this; + } + + void close() throws IOException { + sendCommand(CLOSE_CMD); + } + + LockSlaveMirror lock() throws IOException { + sendCommand(LOCK_CMD); + return this; + } + + + LockSlaveMirror lock(long position, long size, boolean shared) + throws IOException + { + sendCommand(LOCK_CMD, position + "," + size + "," + shared); + return this; + } + + LockSlaveMirror unlock() throws IOException { + sendCommand(UNLOCK_CMD); + return this; + } + + void shutdown() throws IOException { + sc.close(); + } + } + + // Helper class to direct process output to the parent System.out + static class IOHandler implements Runnable { + private final InputStream in; + + IOHandler(InputStream in) { + this.in = in; + } + + static void handle(InputStream in) { + IOHandler handler = new IOHandler(in); + Thread thr = new Thread(handler); + thr.setDaemon(true); + thr.start(); + } + + public void run() { + try { + byte b[] = new byte[100]; + for (;;) { + int n = in.read(b); + if (n < 0) return; + for (int i=0; i<n; i++) { + System.out.print((char)b[i]); + } + } + } catch (IOException ioe) { } + } + } + + // slave process that responds to simple commands a socket connection + static void runLockSlave(int port) throws Exception { + + // establish connection to parent + SocketChannel sc = SocketChannel.open(new InetSocketAddress(port)); + ByteBuffer buf = ByteBuffer.allocateDirect(1024); + + FileChannel fc = null; + FileLock fl = null; + try { + for (;;) { + + // read command (ends with ";") + buf.clear(); + int n, last = 0; + do { + n = sc.read(buf); + if (n < 0) + return; + if (n == 0) + throw new AssertionError(); + last += n; + } while (buf.get(last-1) != TERMINATOR); + + // decode into command and optional parameter + buf.flip(); + String s = Charset.defaultCharset().decode(buf).toString(); + int sp = s.indexOf(" "); + String cmd = (sp < 0) ? s.substring(0, s.length()-1) : + s.substring(0, sp); + String param = (sp < 0) ? "" : s.substring(sp+1, s.length()-1); + + // execute + if (cmd.equals(OPEN_CMD)) { + if (fc != null) + throw new RuntimeException("File already open"); + fc = FileChannel.open(Paths.get(param),READ, WRITE); + } + if (cmd.equals(CLOSE_CMD)) { + if (fc == null) + throw new RuntimeException("No file open"); + fc.close(); + fc = null; + fl = null; + } + if (cmd.equals(LOCK_CMD)) { + if (fl != null) + throw new RuntimeException("Already holding lock"); + + if (param.length() == 0) { + fl = fc.lock(); + } else { + String[] values = param.split(","); + if (values.length != 3) + throw new RuntimeException("Lock parameter invalid"); + long position = Long.parseLong(values[0]); + long size = Long.parseLong(values[1]); + boolean shared = Boolean.parseBoolean(values[2]); + fl = fc.lock(position, size, shared); + } + } + + if (cmd.equals(UNLOCK_CMD)) { + if (fl == null) + throw new RuntimeException("Not holding lock"); + fl.release(); + fl = null; + } + + // send reply + byte[] reply = { TERMINATOR }; + n = sc.write(ByteBuffer.wrap(reply)); + } + + } finally { + sc.close(); + if (fc != null) fc.close(); + } + } +} diff --git a/test/java/nio/channels/AsynchronousFileChannel/MyThreadFactory.java b/test/java/nio/channels/AsynchronousFileChannel/MyThreadFactory.java new file mode 100644 index 0000000000000000000000000000000000000000..fe6f00c25b17aec83c0f642f6e2c3bd5fec6cdf1 --- /dev/null +++ b/test/java/nio/channels/AsynchronousFileChannel/MyThreadFactory.java @@ -0,0 +1,49 @@ +/* + * Copyright 2008-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. + * + * 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. + */ + +import java.util.concurrent.ThreadFactory; +import java.util.*; + +public class MyThreadFactory implements ThreadFactory { + + private static final Set<Thread> threads = new HashSet<Thread>(); + + static boolean created(Thread t) { + synchronized (threads) { + return threads.contains(t); + } + } + + public MyThreadFactory() { + } + + @Override + public Thread newThread(Runnable r) { + Thread t = new Thread(r); + t.setDaemon(true); + synchronized (threads) { + threads.add(t); + } + return t; + } +} diff --git a/test/java/nio/channels/AsynchronousServerSocketChannel/Basic.java b/test/java/nio/channels/AsynchronousServerSocketChannel/Basic.java new file mode 100644 index 0000000000000000000000000000000000000000..e0965fb6e74c09628c129ec25de9b177f702f48e --- /dev/null +++ b/test/java/nio/channels/AsynchronousServerSocketChannel/Basic.java @@ -0,0 +1,136 @@ +/* + * Copyright 2008-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. + * + * 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. + */ + +/* @test + * @bug 4607272 + * @summary Unit test for AsynchronousServerSocketChannel + * @run main/timeout=180 Basic + */ + +import java.nio.channels.*; +import java.net.*; +import java.io.IOException; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; +import java.util.concurrent.atomic.AtomicReference; + +public class Basic { + + public static void main(String[] args) throws Exception { + testBind(); + testAccept(); + } + + static void testBind() throws Exception { + System.out.println("-- bind --"); + + AsynchronousServerSocketChannel ch = AsynchronousServerSocketChannel.open(); + if (ch.getLocalAddress() != null) + throw new RuntimeException("Local address should be 'null'"); + ch.bind(new InetSocketAddress(0), 20); + + // check local address after binding + InetSocketAddress local = (InetSocketAddress)ch.getLocalAddress(); + if (local.getPort() == 0) + throw new RuntimeException("Unexpected port"); + if (!local.getAddress().isAnyLocalAddress()) + throw new RuntimeException("Not bound to a wildcard address"); + + // try to re-bind + try { + ch.bind(new InetSocketAddress(0)); + throw new RuntimeException("AlreadyBoundException expected"); + } catch (AlreadyBoundException x) { + } + ch.close(); + + // check ClosedChannelException + ch = AsynchronousServerSocketChannel.open(); + ch.close(); + try { + ch.bind(new InetSocketAddress(0)); + throw new RuntimeException("ClosedChannelException expected"); + } catch (ClosedChannelException x) { + } + } + + static void testAccept() throws Exception { + System.out.println("-- accept --"); + + final AsynchronousServerSocketChannel listener = + AsynchronousServerSocketChannel.open().bind(new InetSocketAddress(0)); + + InetAddress lh = InetAddress.getLocalHost(); + int port = ((InetSocketAddress)(listener.getLocalAddress())).getPort(); + final InetSocketAddress isa = new InetSocketAddress(lh, port); + + // establish a few loopback connections + for (int i=0; i<100; i++) { + SocketChannel sc = SocketChannel.open(isa); + AsynchronousSocketChannel ch = listener.accept().get(); + sc.close(); + ch.close(); + } + + final AtomicReference<Throwable> exception = new AtomicReference<Throwable>(); + + // start accepting + listener.accept(null, new CompletionHandler<AsynchronousSocketChannel,Void>() { + public void completed(AsynchronousSocketChannel ch, Void att) { + try { + ch.close(); + } catch (IOException ignore) { } + } + public void failed(Throwable exc, Void att) { + exception.set(exc); + } + public void cancelled(Void att) { + } + }); + + // check AcceptPendingException + try { + listener.accept(); + throw new RuntimeException("AcceptPendingException expected"); + } catch (AcceptPendingException x) { + } + + // asynchronous close + listener.close(); + while (exception.get() == null) + Thread.sleep(100); + if (!(exception.get() instanceof AsynchronousCloseException)) + throw new RuntimeException("AsynchronousCloseException expected"); + + // once closed when a further attemt should throw ClosedChannelException + try { + listener.accept().get(); + throw new RuntimeException("ExecutionException expected"); + } catch (ExecutionException x) { + if (!(x.getCause() instanceof ClosedChannelException)) + throw new RuntimeException("Cause of ClosedChannelException expected"); + } catch (InterruptedException x) { + } + + } +} diff --git a/test/java/nio/channels/AsynchronousServerSocketChannel/WithSecurityManager.java b/test/java/nio/channels/AsynchronousServerSocketChannel/WithSecurityManager.java new file mode 100644 index 0000000000000000000000000000000000000000..86c76cf1dda709b6fed2158ebe9a8cfc42574547 --- /dev/null +++ b/test/java/nio/channels/AsynchronousServerSocketChannel/WithSecurityManager.java @@ -0,0 +1,76 @@ +/* + * Copyright 2008-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. + * + * 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. + */ + +/* @test + * @bug 4607272 + * @summary Unit test for AsynchronousServerServerSocketChannel + * @build WithSecurityManager + * @run main/othervm WithSecurityManager allow + * @run main/othervm WithSecurityManager deny + */ + +import java.nio.file.Paths; +import java.nio.channels.*; +import java.net.*; +import java.util.concurrent.*; + +public class WithSecurityManager { + public static void main(String[] args) throws Exception { + boolean allow = false; + String policy = (args[0].equals("allow")) ? "java.policy.allow" : + "java.policy.deny"; + + String testSrc = System.getProperty("test.src"); + if (testSrc == null) + testSrc = "."; + + System.setProperty("java.security.policy", + Paths.get(testSrc).resolve(policy).toString()); + System.setSecurityManager(new SecurityManager()); + + AsynchronousServerSocketChannel listener = + AsynchronousServerSocketChannel.open().bind(new InetSocketAddress(0)); + + InetAddress lh = InetAddress.getLocalHost(); + int port = ((InetSocketAddress)(listener.getLocalAddress())).getPort(); + + // establish and accept connection + SocketChannel sc = SocketChannel.open(new InetSocketAddress(lh, port)); + Future<AsynchronousSocketChannel> result = listener.accept(); + + if (allow) { + // no security exception + result.get().close(); + } else { + try { + result.get(); + } catch (ExecutionException x) { + if (!(x.getCause() instanceof SecurityException)) + throw new RuntimeException("SecurityException expected"); + } + } + + sc.close(); + listener.close(); + } +} diff --git a/test/java/nio/channels/AsynchronousServerSocketChannel/java.policy.allow b/test/java/nio/channels/AsynchronousServerSocketChannel/java.policy.allow new file mode 100644 index 0000000000000000000000000000000000000000..73da4b089ec250118fd5169f9f093f648c11adbb --- /dev/null +++ b/test/java/nio/channels/AsynchronousServerSocketChannel/java.policy.allow @@ -0,0 +1,3 @@ +grant { + permission java.net.SocketPermission "*:1024-", "accept,connect,resolve"; +}; diff --git a/test/java/nio/channels/AsynchronousServerSocketChannel/java.policy.deny b/test/java/nio/channels/AsynchronousServerSocketChannel/java.policy.deny new file mode 100644 index 0000000000000000000000000000000000000000..00b9cb0685d82916f9fa102d24e6bd4da5450920 --- /dev/null +++ b/test/java/nio/channels/AsynchronousServerSocketChannel/java.policy.deny @@ -0,0 +1,3 @@ +grant { + permission java.net.SocketPermission "*:1024-", "connect,resolve"; +}; diff --git a/test/java/nio/channels/AsynchronousSocketChannel/Basic.java b/test/java/nio/channels/AsynchronousSocketChannel/Basic.java new file mode 100644 index 0000000000000000000000000000000000000000..8b140f17bbf9326f2ccc5c98fb299f6f468019c9 --- /dev/null +++ b/test/java/nio/channels/AsynchronousSocketChannel/Basic.java @@ -0,0 +1,805 @@ +/* + * Copyright 2008-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. + * + * 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. + */ + +/* @test + * @bug 4607272 + * @summary Unit test for AsynchronousSocketChannel + * @run main/timeout=600 Basic + */ + +import java.nio.ByteBuffer; +import java.nio.channels.*; +import static java.net.StandardSocketOption.*; +import java.net.*; +import java.util.Random; +import java.util.concurrent.*; +import java.util.concurrent.atomic.*; +import java.io.IOException; + +public class Basic { + static final Random rand = new Random(); + + public static void main(String[] args) throws Exception { + testBind(); + testSocketOptions(); + testConnect(); + testCloseWhenPending(); + testCancel(); + testRead1(); + testRead2(); + testRead3(); + testWrite1(); + testWrite2(); + testTimeout(); + testShutdown(); + } + + static class Server { + private final ServerSocketChannel ssc; + private final InetSocketAddress address; + + Server() throws IOException { + ssc = ServerSocketChannel.open().bind(new InetSocketAddress(0)); + + InetAddress lh = InetAddress.getLocalHost(); + int port = ((InetSocketAddress)(ssc.getLocalAddress())).getPort(); + address = new InetSocketAddress(lh, port); + } + + InetSocketAddress address() { + return address; + } + + SocketChannel accept() throws IOException { + return ssc.accept(); + } + + void close() { + try { + ssc.close(); + } catch (IOException ignore) { } + } + + } + + static void testBind() throws Exception { + System.out.println("-- bind --"); + + AsynchronousSocketChannel ch = AsynchronousSocketChannel.open(); + if (ch.getLocalAddress() != null) + throw new RuntimeException("Local address should be 'null'"); + ch.bind(new InetSocketAddress(0)); + + // check local address after binding + InetSocketAddress local = (InetSocketAddress)ch.getLocalAddress(); + if (local.getPort() == 0) + throw new RuntimeException("Unexpected port"); + if (!local.getAddress().isAnyLocalAddress()) + throw new RuntimeException("Not bound to a wildcard address"); + + // try to re-bind + try { + ch.bind(new InetSocketAddress(0)); + throw new RuntimeException("AlreadyBoundException expected"); + } catch (AlreadyBoundException x) { + } + ch.close(); + + // check ClosedChannelException + ch = AsynchronousSocketChannel.open(); + ch.close(); + try { + ch.bind(new InetSocketAddress(0)); + throw new RuntimeException("ClosedChannelException expected"); + } catch (ClosedChannelException x) { + } + } + + static void testSocketOptions() throws Exception { + System.out.println("-- socket options --"); + + AsynchronousSocketChannel ch = AsynchronousSocketChannel.open() + .setOption(SO_RCVBUF, 128*1024) + .setOption(SO_SNDBUF, 128*1024) + .setOption(SO_REUSEADDR, true) + .bind(new InetSocketAddress(0)); + + // default values + if ((Boolean)ch.getOption(SO_KEEPALIVE)) + throw new RuntimeException("Default of SO_KEEPALIVE should be 'false'"); + if ((Boolean)ch.getOption(TCP_NODELAY)) + throw new RuntimeException("Default of TCP_NODELAY should be 'false'"); + + // set and check + if (!(Boolean)ch.setOption(SO_KEEPALIVE, true).getOption(SO_KEEPALIVE)) + throw new RuntimeException("SO_KEEPALIVE did not change"); + if (!(Boolean)ch.setOption(TCP_NODELAY, true).getOption(TCP_NODELAY)) + throw new RuntimeException("SO_KEEPALIVE did not change"); + + // read others (can't check as actual value is implementation dependent) + ch.getOption(SO_RCVBUF); + ch.getOption(SO_SNDBUF); + + ch.close(); + } + + static void testConnect() throws Exception { + System.out.println("-- connect --"); + + Server server = new Server(); + AsynchronousSocketChannel ch = AsynchronousSocketChannel.open(); + ch.connect(server.address()).get(); + + // check local address + if (ch.getLocalAddress() == null) + throw new RuntimeException("Not bound to local address"); + + // check remote address + InetSocketAddress remote = (InetSocketAddress)ch.getRemoteAddress(); + if (remote.getPort() != server.address().getPort()) + throw new RuntimeException("Connected to unexpected port"); + if (!remote.getAddress().equals(server.address().getAddress())) + throw new RuntimeException("Connected to unexpected address"); + + // try to connect again + try { + ch.connect(server.address()).get(); + throw new RuntimeException("AlreadyConnectedException expected"); + } catch (AlreadyConnectedException x) { + } + ch.close(); + + // check that connect fails with ClosedChannelException) + ch = AsynchronousSocketChannel.open(); + ch.close(); + try { + ch.connect(server.address()).get(); + throw new RuntimeException("ExecutionException expected"); + } catch (ExecutionException x) { + if (!(x.getCause() instanceof ClosedChannelException)) + throw new RuntimeException("Cause of ClosedChannelException expected"); + } + final AtomicReference<Throwable> connectException = + new AtomicReference<Throwable>(); + ch.connect(server.address(), null, new CompletionHandler<Void,Void>() { + public void completed(Void result, Void att) { + } + public void failed(Throwable exc, Void att) { + connectException.set(exc); + } + public void cancelled(Void att) { + } + }); + while (connectException.get() == null) { + Thread.sleep(100); + } + if (!(connectException.get() instanceof ClosedChannelException)) + throw new RuntimeException("ClosedChannelException expected"); + + System.out.println("-- connect to non-existent host --"); + + // test failure + InetAddress badHost = InetAddress.getByName("1.2.3.4"); + if (!badHost.isReachable(10*1000)) { + + ch = AsynchronousSocketChannel.open(); + try { + ch.connect(new InetSocketAddress(badHost, 9876)).get(); + throw new RuntimeException("Connection should not be established"); + } catch (ExecutionException x) { + } + if (ch.isOpen()) + throw new RuntimeException("Channel should be closed"); + } + + server.close(); + } + + static void testCloseWhenPending() throws Exception { + System.out.println("-- asynchronous close when connecting --"); + + AsynchronousSocketChannel ch; + + // asynchronous close while connecting + InetAddress rh = InetAddress.getByName("1.2.3.4"); + if (!rh.isReachable(3000)) { + InetSocketAddress isa = new InetSocketAddress(rh, 1234); + + ch = AsynchronousSocketChannel.open(); + Future<Void> result = ch.connect(isa); + + // give time to initiate the connect (SYN) + Thread.sleep(50); + + // close + ch.close(); + + // check that AsynchronousCloseException is thrown + try { + result.get(); + throw new RuntimeException("Should not connect"); + } catch (ExecutionException x) { + if (!(x.getCause() instanceof AsynchronousCloseException)) + throw new RuntimeException(x); + } + } + + System.out.println("-- asynchronous close when reading --"); + + Server server = new Server(); + ch = AsynchronousSocketChannel.open(); + ch.connect(server.address()).get(); + + ByteBuffer dst = ByteBuffer.allocateDirect(100); + Future<Integer> result = ch.read(dst); + + // attempt a second read - should fail with ReadPendingException + ByteBuffer buf = ByteBuffer.allocateDirect(100); + try { + ch.read(buf); + throw new RuntimeException("ReadPendingException expected"); + } catch (ReadPendingException x) { + } + + // close channel (should cause initial read to complete) + ch.close(); + + // check that AsynchronousCloseException is thrown + try { + result.get(); + throw new RuntimeException("Should not read"); + } catch (ExecutionException x) { + if (!(x.getCause() instanceof AsynchronousCloseException)) + throw new RuntimeException(x); + } + + System.out.println("-- asynchronous close when writing --"); + + ch = AsynchronousSocketChannel.open(); + ch.connect(server.address()).get(); + + final AtomicReference<Throwable> writeException = + new AtomicReference<Throwable>(); + + // write bytes to fill socket buffer + ch.write(genBuffer(), ch, new CompletionHandler<Integer,AsynchronousSocketChannel>() { + public void completed(Integer result, AsynchronousSocketChannel ch) { + ch.write(genBuffer(), ch, this); + } + public void failed(Throwable x, AsynchronousSocketChannel ch) { + writeException.set(x); + } + public void cancelled(AsynchronousSocketChannel ch) { + } + }); + + // give time for socket buffer to fill up. + Thread.sleep(5*1000); + + // attempt a concurrent write - should fail with WritePendingException + try { + ch.write(genBuffer()); + throw new RuntimeException("WritePendingException expected"); + } catch (WritePendingException x) { + } + + // close channel - should cause initial write to complete + ch.close(); + + // wait for exception + while (writeException.get() == null) { + Thread.sleep(100); + } + if (!(writeException.get() instanceof AsynchronousCloseException)) + throw new RuntimeException("AsynchronousCloseException expected"); + + server.close(); + } + + static void testCancel() throws Exception { + System.out.println("-- cancel --"); + + Server server = new Server(); + + for (int i=0; i<2; i++) { + boolean mayInterruptIfRunning = (i == 0) ? false : true; + + // establish loopback connection + AsynchronousSocketChannel ch = AsynchronousSocketChannel.open(); + ch.connect(server.address()).get(); + SocketChannel peer = server.accept(); + + // start read operation + final CountDownLatch latch = new CountDownLatch(1); + ByteBuffer buf = ByteBuffer.allocate(1); + Future<Integer> res = ch.read(buf, null, + new CompletionHandler<Integer,Void>() { + public void completed(Integer result, Void att) { + } + public void failed(Throwable exc, Void att) { + } + public void cancelled(Void att) { + latch.countDown(); + } + }); + + // cancel operation + boolean cancelled = res.cancel(mayInterruptIfRunning); + + // check post-conditions + if (!res.isDone()) + throw new RuntimeException("isDone should return true"); + if (res.isCancelled() != cancelled) + throw new RuntimeException("isCancelled not consistent"); + try { + res.get(); + throw new RuntimeException("CancellationException expected"); + } catch (CancellationException x) { + } + try { + res.get(1, TimeUnit.SECONDS); + throw new RuntimeException("CancellationException expected"); + } catch (CancellationException x) { + } + + // check that completion handler executed. + latch.await(); + + ch.close(); + peer.close(); + } + + server.close(); + } + + static void testRead1() throws Exception { + System.out.println("-- read (1) --"); + + Server server = new Server(); + final AsynchronousSocketChannel ch = AsynchronousSocketChannel.open(); + ch.connect(server.address()).get(); + + // read with 0 bytes remaining should complete immediately + ByteBuffer buf = ByteBuffer.allocate(1); + buf.put((byte)0); + int n = ch.read(buf).get(); + if (n != 0) + throw new RuntimeException("0 expected"); + + // write bytes and close connection + SocketChannel sc = server.accept(); + ByteBuffer src = genBuffer(); + sc.setOption(StandardSocketOption.SO_SNDBUF, src.remaining()); + while (src.hasRemaining()) + sc.write(src); + sc.close(); + + // reads should complete immediately + final ByteBuffer dst = ByteBuffer.allocateDirect(src.capacity() + 100); + final CountDownLatch latch = new CountDownLatch(1); + ch.read(dst, null, new CompletionHandler<Integer,Void>() { + public void completed(Integer result, Void att) { + int n = result; + if (n > 0) { + ch.read(dst, null, this); + } else { + latch.countDown(); + } + } + public void failed(Throwable exc, Void att) { + } + public void cancelled(Void att) { + } + }); + + latch.await(); + + // check buffers + src.flip(); + dst.flip(); + if (!src.equals(dst)) { + throw new RuntimeException("Contents differ"); + } + + // close channel + ch.close(); + + // check read fails with ClosedChannelException + try { + ch.read(dst).get(); + throw new RuntimeException("ExecutionException expected"); + } catch (ExecutionException x) { + if (!(x.getCause() instanceof ClosedChannelException)) + throw new RuntimeException("Cause of ClosedChannelException expected"); + } + + server.close(); + } + + static void testRead2() throws Exception { + System.out.println("-- read (2) --"); + + Server server = new Server(); + + final AsynchronousSocketChannel ch = AsynchronousSocketChannel.open(); + ch.connect(server.address()).get(); + SocketChannel sc = server.accept(); + + ByteBuffer src = genBuffer(); + + // read until the buffer is full + final ByteBuffer dst = ByteBuffer.allocateDirect(src.capacity()); + final CountDownLatch latch = new CountDownLatch(1); + ch.read(dst, null, new CompletionHandler<Integer,Void>() { + public void completed(Integer result, Void att) { + if (dst.hasRemaining()) { + ch.read(dst, null, this); + } else { + latch.countDown(); + } + } + public void failed(Throwable exc, Void att) { + } + public void cancelled(Void att) { + } + }); + + // trickle the writing + do { + int rem = src.remaining(); + int size = (rem <= 100) ? rem : 50 + rand.nextInt(rem - 100); + ByteBuffer buf = ByteBuffer.allocate(size); + for (int i=0; i<size; i++) + buf.put(src.get()); + buf.flip(); + Thread.sleep(50 + rand.nextInt(1500)); + while (buf.hasRemaining()) + sc.write(buf); + } while (src.hasRemaining()); + + // wait until ascynrhonous reading has completed + latch.await(); + + // check buffers + src.flip(); + dst.flip(); + if (!src.equals(dst)) { + throw new RuntimeException("Contents differ"); + } + + sc.close(); + ch.close(); + server.close(); + } + + // exercise scattering read + static void testRead3() throws Exception { + System.out.println("-- read (3) --"); + + Server server = new Server(); + final AsynchronousSocketChannel ch = AsynchronousSocketChannel.open(); + ch.connect(server.address()).get(); + SocketChannel sc = server.accept(); + + ByteBuffer[] dsts = new ByteBuffer[3]; + for (int i=0; i<dsts.length; i++) { + dsts[i] = ByteBuffer.allocateDirect(100); + } + + // scattering read that completes ascynhronously + final CountDownLatch latch = new CountDownLatch(1); + ch.read(dsts, 0, dsts.length, 0L, TimeUnit.SECONDS, null, + new CompletionHandler<Long,Void>() { + public void completed(Long result, Void att) { + long n = result; + if (n <= 0) + throw new RuntimeException("No bytes read"); + latch.countDown(); + } + public void failed(Throwable exc, Void att) { + } + public void cancelled(Void att) { + } + }); + + // write some bytes + sc.write(genBuffer()); + + // read should now complete + latch.await(); + + // write more bytes + sc.write(genBuffer()); + + // read should complete immediately + for (int i=0; i<dsts.length; i++) { + dsts[i].rewind(); + } + long n = ch + .read(dsts, 0, dsts.length, 0L, TimeUnit.SECONDS, null, null).get(); + if (n <= 0) + throw new RuntimeException("No bytes read"); + + ch.close(); + sc.close(); + server.close(); + } + + static void testWrite1() throws Exception { + System.out.println("-- write (1) --"); + + Server server = new Server(); + final AsynchronousSocketChannel ch = AsynchronousSocketChannel.open(); + ch.connect(server.address()).get(); + SocketChannel sc = server.accept(); + + // write with 0 bytes remaining should complete immediately + ByteBuffer buf = ByteBuffer.allocate(1); + buf.put((byte)0); + int n = ch.write(buf).get(); + if (n != 0) + throw new RuntimeException("0 expected"); + + // write all bytes and close connection when done + final ByteBuffer src = genBuffer(); + ch.write(src, null, new CompletionHandler<Integer,Void>() { + public void completed(Integer result, Void att) { + if (src.hasRemaining()) { + ch.write(src, null, this); + } else { + try { + ch.close(); + } catch (IOException ignore) { } + } + } + public void failed(Throwable exc, Void att) { + } + public void cancelled(Void att) { + } + }); + + // read to EOF or buffer full + ByteBuffer dst = ByteBuffer.allocateDirect(src.capacity() + 100); + do { + n = sc.read(dst); + } while (n > 0); + sc.close(); + + // check buffers + src.flip(); + dst.flip(); + if (!src.equals(dst)) { + throw new RuntimeException("Contents differ"); + } + + // check write fails with ClosedChannelException + try { + ch.read(dst).get(); + throw new RuntimeException("ExecutionException expected"); + } catch (ExecutionException x) { + if (!(x.getCause() instanceof ClosedChannelException)) + throw new RuntimeException("Cause of ClosedChannelException expected"); + } + + server.close(); + } + + // exercise gathering write + static void testWrite2() throws Exception { + System.out.println("-- write (2) --"); + + Server server = new Server(); + final AsynchronousSocketChannel ch = AsynchronousSocketChannel.open(); + ch.connect(server.address()).get(); + SocketChannel sc = server.accept(); + + // write buffers (should complete immediately) + ByteBuffer[] srcs = genBuffers(1); + long n = ch + .write(srcs, 0, srcs.length, 0L, TimeUnit.SECONDS, null, null).get(); + if (n <= 0) + throw new RuntimeException("No bytes written"); + + // set to true to signal that no more buffers should be written + final AtomicBoolean continueWriting = new AtomicBoolean(true); + + // number of bytes written + final AtomicLong bytesWritten = new AtomicLong(n); + + // write until socket buffer is full so as to create the conditions + // for when a write does not complete immediately + srcs = genBuffers(1); + ch.write(srcs, 0, srcs.length, 0L, TimeUnit.SECONDS, null, + new CompletionHandler<Long,Void>() { + public void completed(Long result, Void att) { + long n = result; + if (n <= 0) + throw new RuntimeException("No bytes written"); + bytesWritten.addAndGet(n); + if (continueWriting.get()) { + ByteBuffer[] srcs = genBuffers(8); + ch.write(srcs, 0, srcs.length, 0L, TimeUnit.SECONDS, + null, this); + } + } + public void failed(Throwable exc, Void att) { + } + public void cancelled(Void att) { + } + }); + + // give time for socket buffer to fill up. + Thread.sleep(5*1000); + + // signal handler to stop further writing + continueWriting.set(false); + + // read until done + ByteBuffer buf = ByteBuffer.allocateDirect(4096); + long total = 0L; + do { + n = sc.read(buf); + if (n <= 0) + throw new RuntimeException("No bytes read"); + buf.rewind(); + total += n; + } while (total < bytesWritten.get()); + + ch.close(); + sc.close(); + server.close(); + } + + static void testShutdown() throws Exception { + System.out.println("-- shutdown--"); + + Server server = new Server(); + AsynchronousSocketChannel ch = AsynchronousSocketChannel.open(); + ch.connect(server.address()).get(); + SocketChannel sc = server.accept(); + + ByteBuffer buf = ByteBuffer.allocateDirect(1000); + int n; + + // check read + ch.shutdownInput(); + n = ch.read(buf).get(); + if (n != -1) + throw new RuntimeException("-1 expected"); + // check full with full buffer + buf.put(new byte[100]); + n = ch.read(buf).get(); + if (n != -1) + throw new RuntimeException("-1 expected"); + + // check write + ch.shutdownOutput(); + try { + ch.write(buf).get(); + throw new RuntimeException("ClosedChannelException expected"); + } catch (ExecutionException x) { + if (!(x.getCause() instanceof ClosedChannelException)) + throw new RuntimeException("ClosedChannelException expected"); + } + + sc.close(); + ch.close(); + server.close(); + } + + static void testTimeout() throws Exception { + Server server = new Server(); + AsynchronousSocketChannel ch = AsynchronousSocketChannel.open(); + ch.connect(server.address()).get(); + + System.out.println("-- timeout when reading --"); + + // this read should timeout + ByteBuffer dst = ByteBuffer.allocate(512); + try { + ch.read(dst, 3, TimeUnit.SECONDS, null, null).get(); + throw new RuntimeException("Read did not timeout"); + } catch (ExecutionException x) { + if (!(x.getCause() instanceof InterruptedByTimeoutException)) + throw new RuntimeException("InterruptedByTimeoutException expected"); + } + + // after a timeout then further reading should throw unspecified runtime exception + boolean exceptionThrown = false; + try { + ch.read(dst); + } catch (RuntimeException x) { + exceptionThrown = true; + } + if (!exceptionThrown) + throw new RuntimeException("RuntimeException expected after timeout."); + + + System.out.println("-- timeout when writing --"); + + final AtomicReference<Throwable> writeException = new AtomicReference<Throwable>(); + + final long timeout = 5; + final TimeUnit unit = TimeUnit.SECONDS; + + // write bytes to fill socket buffer + ch.write(genBuffer(), timeout, unit, ch, + new CompletionHandler<Integer,AsynchronousSocketChannel>() + { + public void completed(Integer result, AsynchronousSocketChannel ch) { + ch.write(genBuffer(), timeout, unit, ch, this); + } + public void failed(Throwable exc, AsynchronousSocketChannel ch) { + writeException.set(exc); + } + public void cancelled(AsynchronousSocketChannel ch) { + } + }); + + // wait for exception + while (writeException.get() == null) { + Thread.sleep(100); + } + if (!(writeException.get() instanceof InterruptedByTimeoutException)) + throw new RuntimeException("InterruptedByTimeoutException expected"); + + // after a timeout then further writing should throw unspecified runtime exception + exceptionThrown = false; + try { + ch.write(genBuffer()); + } catch (RuntimeException x) { + exceptionThrown = true; + } + if (!exceptionThrown) + throw new RuntimeException("RuntimeException expected after timeout."); + + ch.close(); + } + + // returns ByteBuffer with random bytes + static ByteBuffer genBuffer() { + int size = 1024 + rand.nextInt(16000); + byte[] buf = new byte[size]; + rand.nextBytes(buf); + boolean useDirect = rand.nextBoolean(); + if (useDirect) { + ByteBuffer bb = ByteBuffer.allocateDirect(buf.length); + bb.put(buf); + bb.flip(); + return bb; + } else { + return ByteBuffer.wrap(buf); + } + } + + // return ByteBuffer[] with random bytes + static ByteBuffer[] genBuffers(int max) { + int len = 1; + if (max > 1) + len += rand.nextInt(max); + ByteBuffer[] bufs = new ByteBuffer[len]; + for (int i=0; i<len; i++) + bufs[i] = genBuffer(); + return bufs; + } +} diff --git a/test/java/nio/channels/AsynchronousSocketChannel/Leaky.java b/test/java/nio/channels/AsynchronousSocketChannel/Leaky.java new file mode 100644 index 0000000000000000000000000000000000000000..3ac18211c5889f84f28579bbae670aac8afd95b1 --- /dev/null +++ b/test/java/nio/channels/AsynchronousSocketChannel/Leaky.java @@ -0,0 +1,104 @@ +/* + * Copyright 2008-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. + * + * 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. + */ + +/* @test + * @bug 4607272 + * @summary Unit test for AsynchronousSocketChannel + * @run main/othervm -XX:+DisableExplicitGC -mx64m Leaky + */ + +import java.nio.ByteBuffer; +import java.nio.channels.*; +import java.net.*; +import java.util.concurrent.Future; + +/** + * Heap buffers must be substituted with direct buffers when doing I/O. This + * test creates a scenario on Windows that challenges the per-thread buffer + * cache and quickly leads to an OutOfMemoryError if temporary buffers are + * not returned to the native heap. + */ + +public class Leaky { + + static final int K = 1024; + + static class Connection { + private final AsynchronousSocketChannel client; + private final SocketChannel peer; + private final ByteBuffer dst; + private Future<Integer> readResult; + + Connection() throws Exception { + ServerSocketChannel ssc = + ServerSocketChannel.open().bind(new InetSocketAddress(0)); + InetAddress lh = InetAddress.getLocalHost(); + int port = ((InetSocketAddress)(ssc.getLocalAddress())).getPort(); + SocketAddress remote = new InetSocketAddress(lh, port); + client = AsynchronousSocketChannel.open(); + client.connect(remote).get(); + peer = ssc.accept(); + ssc.close(); + dst = ByteBuffer.allocate(K*K); + } + + void startRead() { + dst.clear(); + readResult = client.read(dst); + } + + void write() throws Exception { + peer.write(ByteBuffer.wrap("X".getBytes())); + } + + void finishRead() throws Exception { + readResult.get(); + } + } + + public static void main(String[] args) throws Exception { + + final int CONNECTION_COUNT = 10; + Connection[] connections = new Connection[CONNECTION_COUNT]; + for (int i=0; i<CONNECTION_COUNT; i++) { + connections[i] = new Connection(); + } + + for (int i=0; i<1024; i++) { + // initiate reads + for (Connection conn: connections) { + conn.startRead(); + } + + // write data so that the read can complete + for (Connection conn: connections) { + conn.write(); + } + + // complete read + for (Connection conn: connections) { + conn.finishRead(); + } + } + } +} diff --git a/test/java/nio/channels/Channels/Basic2.java b/test/java/nio/channels/Channels/Basic2.java new file mode 100644 index 0000000000000000000000000000000000000000..46a1b028ccab2694caaaf8ecf1d64d19d2da58ff --- /dev/null +++ b/test/java/nio/channels/Channels/Basic2.java @@ -0,0 +1,172 @@ +/* + * Copyright 2008-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. + * + * 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. + */ + +/* @test + * @bug 4607272 + * @summary Test Channels methods for interoperability between streams and + * asynchronous byte channels + */ + +import java.net.*; +import java.io.*; +import java.nio.channels.*; +import java.util.Random; + +public class Basic2 { + + static final Random rand = new Random(); + + public static void main(String[] args) throws Exception { + // establish loopback connection + AsynchronousServerSocketChannel listener = + AsynchronousServerSocketChannel.open().bind(new InetSocketAddress(0)); + int port = ((InetSocketAddress)(listener.getLocalAddress())).getPort(); + InetSocketAddress isa = + new InetSocketAddress(InetAddress.getLocalHost(), port); + AsynchronousSocketChannel ch1 = AsynchronousSocketChannel.open(); + ch1.connect(isa).get(); + AsynchronousSocketChannel ch2 = listener.accept().get(); + + // start thread to write to stream + Writer writer = new Writer(Channels.newOutputStream(ch1)); + Thread writerThread = new Thread(writer); + writerThread.start(); + + // start thread to read from stream + Reader reader = new Reader(Channels.newInputStream(ch2)); + Thread readerThread = new Thread(reader); + readerThread.start(); + + // wait for threads to complete + writerThread.join(); + readerThread.join(); + + // check that reader received what we expected + if (reader.total() != writer.total()) + throw new RuntimeException("Unexpected number of bytes read"); + if (reader.hash() != writer.hash()) + throw new RuntimeException("Hash incorrect for bytes read"); + + // channels should be closed + if (ch1.isOpen() || ch2.isOpen()) + throw new RuntimeException("Channels should be closed"); + } + + static class Reader implements Runnable { + private final InputStream in; + private volatile int total; + private volatile int hash; + + Reader(InputStream in) { + this.in = in; + } + + public void run() { + try { + int n; + do { + // random offset/len + byte[] buf = new byte[128 + rand.nextInt(128)]; + int len, off; + if (rand.nextBoolean()) { + len = buf.length; + off = 0; + n = in.read(buf); + } else { + len = 1 + rand.nextInt(64); + off = rand.nextInt(64); + n = in.read(buf, off, len); + } + if (n > len) + throw new RuntimeException("Too many bytes read"); + if (n > 0) { + total += n; + for (int i=0; i<n; i++) { + int value = buf[off + i]; + hash = hash ^ value; + } + } + } while (n > 0); + in.close(); + + } catch (IOException x) { + x.printStackTrace(); + } + } + + int total() { return total; } + int hash() { return hash; } + } + + static class Writer implements Runnable { + private final OutputStream out; + private final int total; + private volatile int hash; + + Writer(OutputStream out) { + this.out = out; + this.total = 50*1000 + rand.nextInt(50*1000); + } + + public void run() { + hash = 0; + int rem = total; + try { + do { + byte[] buf = new byte[1 + rand.nextInt(rem)]; + int off, len; + + // write random bytes + if (rand.nextBoolean()) { + off = 0; + len = buf.length; + } else { + off = rand.nextInt(buf.length); + int r = buf.length - off; + len = (r <= 1) ? 1 : (1 + rand.nextInt(r)); + } + for (int i=0; i<len; i++) { + byte value = (byte)rand.nextInt(256); + buf[off + i] = value; + hash = hash ^ value; + } + if ((off == 0) && (len == buf.length)) { + out.write(buf); + } else { + out.write(buf, off, len); + } + rem -= len; + } while (rem > 0); + + // close stream when done + out.close(); + + } catch (IOException x) { + x.printStackTrace(); + } + } + + int total() { return total; } + int hash() { return hash; } + } +} diff --git a/test/java/nio/channels/DatagramChannel/BasicMulticastTests.java b/test/java/nio/channels/DatagramChannel/BasicMulticastTests.java index 03b5daa68f10126f1675fbe68fece8ced9ce3b03..6928bcded3edcb894073ce523a094dec1db01d64 100644 --- a/test/java/nio/channels/DatagramChannel/BasicMulticastTests.java +++ b/test/java/nio/channels/DatagramChannel/BasicMulticastTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2007-2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2007-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 @@ -64,11 +64,11 @@ public class BasicMulticastTests { // check key if (!key.isValid()) throw new RuntimeException("key is not valid"); - if (!key.getGroup().equals(group)) + if (!key.group().equals(group)) throw new RuntimeException("group is incorrect"); - if (!key.getNetworkInterface().equals(nif)) + if (!key.networkInterface().equals(nif)) throw new RuntimeException("network interface is incorrect"); - if (key.getSourceAddress() != null) + if (key.sourceAddress() != null) throw new RuntimeException("key is source specific"); // drop membership @@ -86,11 +86,11 @@ public class BasicMulticastTests { } if (!key.isValid()) throw new RuntimeException("key is not valid"); - if (!key.getGroup().equals(group)) + if (!key.group().equals(group)) throw new RuntimeException("group is incorrect"); - if (!key.getNetworkInterface().equals(nif)) + if (!key.networkInterface().equals(nif)) throw new RuntimeException("network interface is incorrect"); - if (!key.getSourceAddress().equals(source)) + if (!key.sourceAddress().equals(source)) throw new RuntimeException("key's source address incorrect"); // drop membership diff --git a/test/java/nio/channels/DatagramChannel/NotBound.java b/test/java/nio/channels/DatagramChannel/NotBound.java index 9a58fe64d18e96c6474f615435ffa6552c0e043c..d9fbd7b5efa66a795d8dd361db3c97746ca30c0f 100644 --- a/test/java/nio/channels/DatagramChannel/NotBound.java +++ b/test/java/nio/channels/DatagramChannel/NotBound.java @@ -22,27 +22,110 @@ */ /* @test - * @bug 4512723 - * @summary Unit test for datagram-socket-channel adaptors + * @bug 4512723 6621689 + * @summary Test that connect/send/receive with unbound DatagramChannel causes + * the channel's socket to be bound to a local address */ import java.net.*; -import java.nio.*; -import java.nio.channels.*; +import java.nio.ByteBuffer; +import java.nio.channels.DatagramChannel; +import java.io.IOException; -class NotBound { - public static void main(String[] args) throws Exception { - test1(false); - test1(true); +public class NotBound { + + static void checkBound(DatagramChannel dc) throws IOException { + if (dc.getLocalAddress() == null) + throw new RuntimeException("Not bound??"); + } + + // starts a thread to send a datagram to the given channel once the channel + // is bound to a local address + static void wakeupWhenBound(final DatagramChannel dc) { + Runnable wakeupTask = new Runnable() { + public void run() { + try { + // poll for local address + InetSocketAddress local; + do { + Thread.sleep(50); + local = (InetSocketAddress)dc.getLocalAddress(); + } while (local == null); + + // send message to channel to wakeup receiver + DatagramChannel sender = DatagramChannel.open(); + try { + ByteBuffer bb = ByteBuffer.wrap("hello".getBytes()); + InetAddress lh = InetAddress.getLocalHost(); + SocketAddress target = + new InetSocketAddress(lh, local.getPort()); + sender.send(bb, target); + } finally { + sender.close(); + } + + } catch (Exception x) { + x.printStackTrace(); + } + }}; + new Thread(wakeupTask).start(); } - static void test1(boolean blocking) throws Exception { - ByteBuffer bb = ByteBuffer.allocateDirect(256); - DatagramChannel dc1 = DatagramChannel.open(); - dc1.configureBlocking(false); - SocketAddress isa = dc1.receive(bb); - if (isa != null) - throw new Exception("Unbound dc returned non-null"); - dc1.close(); + public static void main(String[] args) throws IOException { + DatagramChannel dc; + + // connect + dc = DatagramChannel.open(); + try { + DatagramChannel peer = DatagramChannel.open() + .bind(new InetSocketAddress(0)); + int peerPort = ((InetSocketAddress)(peer.getLocalAddress())).getPort(); + try { + dc.connect(new InetSocketAddress(InetAddress.getLocalHost(), peerPort)); + checkBound(dc); + } finally { + peer.close(); + } + } finally { + dc.close(); + } + + // send + dc = DatagramChannel.open(); + try { + ByteBuffer bb = ByteBuffer.wrap("ignore this".getBytes()); + SocketAddress target = + new InetSocketAddress(InetAddress.getLocalHost(), 5000); + dc.send(bb, target); + checkBound(dc); + } finally { + dc.close(); + } + + // receive (blocking) + dc = DatagramChannel.open(); + try { + ByteBuffer bb = ByteBuffer.allocateDirect(128); + wakeupWhenBound(dc); + SocketAddress sender = dc.receive(bb); + if (sender == null) + throw new RuntimeException("Sender should not be null"); + checkBound(dc); + } finally { + dc.close(); + } + + // receive (non-blocking) + dc = DatagramChannel.open(); + try { + dc.configureBlocking(false); + ByteBuffer bb = ByteBuffer.allocateDirect(128); + SocketAddress sender = dc.receive(bb); + if (sender != null) + throw new RuntimeException("Sender should be null"); + checkBound(dc); + } finally { + dc.close(); + } } } diff --git a/test/java/nio/channels/DatagramChannel/SocketOptionTests.java b/test/java/nio/channels/DatagramChannel/SocketOptionTests.java index e4e85b11fb45a9c05045cc2ed571bc6bfe7172fc..3df7bbbda45e26c036c5337e46253a93e1703e54 100644 --- a/test/java/nio/channels/DatagramChannel/SocketOptionTests.java +++ b/test/java/nio/channels/DatagramChannel/SocketOptionTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2007-2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2007-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 @@ -49,7 +49,7 @@ public class SocketOptionTests { DatagramChannel dc = DatagramChannel.open(); // check supported options - Set<SocketOption<?>> options = dc.options(); + Set<SocketOption<?>> options = dc.supportedOptions(); List<? extends SocketOption<?>> expected = Arrays.asList(SO_SNDBUF, SO_RCVBUF, SO_REUSEADDR, SO_BROADCAST, IP_TOS, IP_MULTICAST_IF, IP_MULTICAST_TTL, IP_MULTICAST_LOOP); diff --git a/test/java/nio/channels/Selector/HelperSlowToDie.java b/test/java/nio/channels/Selector/HelperSlowToDie.java new file mode 100644 index 0000000000000000000000000000000000000000..d3cb7e64efc9ea5cb16411c32e1cab4c6facf30f --- /dev/null +++ b/test/java/nio/channels/Selector/HelperSlowToDie.java @@ -0,0 +1,75 @@ +/* + * 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. + * + * 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. + */ + +/* + * @test + * @bug 6823609 + * @summary Selector.select can hangs on Windows for cases where a helper thread + * becomes redudant but a new helper is immediately needed. + */ + +import java.nio.channels.*; +import java.io.IOException; + +public class HelperSlowToDie { + private static final int CHANNELS_PER_THREAD = 1023; + private static volatile boolean done; + + public static void main(String[] args) throws IOException { + Selector sel = Selector.open(); + + // register channels + SocketChannel[] channels = new SocketChannel[CHANNELS_PER_THREAD]; + for (int i=0; i<CHANNELS_PER_THREAD; i++) { + SocketChannel sc = SocketChannel.open(); + sc.configureBlocking(false); + sc.register(sel, SelectionKey.OP_CONNECT); + channels[i] = sc; + } + sel.selectNow(); + + // Start threads to swamp all cores but one. This improves the chances + // of duplicating the bug. + Runnable busy = new Runnable() { + public void run() { + while (!done) ; // no nothing + } + }; + int ncores = Runtime.getRuntime().availableProcessors(); + for (int i=0; i<ncores-1; i++) + new Thread(busy).start(); + + // Loop changing the number of channels from 1023 to 1024 and back. + for (int i=0; i<1000; i++) { + SocketChannel sc = SocketChannel.open(); + sc.configureBlocking(false); + sc.register(sel, SelectionKey.OP_CONNECT); + sel.selectNow(); // cause helper to spin up + sc.close(); + sel.selectNow(); // cause helper to retire + } + + // terminate busy threads + done = true; + } +} diff --git a/test/java/nio/channels/Selector/LotsOfUpdates.java b/test/java/nio/channels/Selector/LotsOfUpdates.java new file mode 100644 index 0000000000000000000000000000000000000000..71018fa8d32bc98169797f19f56dd19b5b5d0d4e --- /dev/null +++ b/test/java/nio/channels/Selector/LotsOfUpdates.java @@ -0,0 +1,38 @@ +/* + * 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. + * + * 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. + */ + +import java.nio.channels.*; +import java.io.IOException; + +public class LotsOfUpdates { + public static void main(String[] args) throws IOException { + Selector sel = Selector.open(); + SocketChannel sc = SocketChannel.open(); + sc.configureBlocking(false); + SelectionKey key = sc.register(sel, 0); + for (int i=0; i<50000; i++) { + key.interestOps(0); + } + sel.selectNow(); + } +} diff --git a/test/java/nio/channels/Selector/RegAfterPreClose.java b/test/java/nio/channels/Selector/RegAfterPreClose.java new file mode 100644 index 0000000000000000000000000000000000000000..c5f6be1d60c38c1c6045434a41c34f474241c4f8 --- /dev/null +++ b/test/java/nio/channels/Selector/RegAfterPreClose.java @@ -0,0 +1,127 @@ +/* + * 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. + * + * 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. + */ + +/* @test + * @bug 6693490 + * @summary Pre-close file descriptor may inadvertently get registered with + * epoll during close + */ + +import java.net.*; +import java.nio.channels.*; +import java.util.concurrent.*; +import java.util.*; +import java.io.IOException; + +public class RegAfterPreClose { + + static volatile boolean done; + + /** + * A task that continuously connects to a given address and immediately + * closes the connection. + */ + static class Connector implements Runnable { + private final SocketAddress sa; + Connector(int port) throws IOException { + InetAddress lh = InetAddress.getLocalHost(); + this.sa = new InetSocketAddress(lh, port); + } + public void run() { + while (!done) { + try { + SocketChannel.open(sa).close(); + } catch (IOException x) { + // back-off as probably resource related + try { + Thread.sleep(10); + } catch (InterruptedException ignore) { } + } + } + } + } + + /** + * A task that closes a channel. + */ + static class Closer implements Runnable { + private final Channel channel; + Closer(Channel sc) { + this.channel = sc; + } + public void run() { + try { + channel.close(); + } catch (IOException ignore) { } + } + } + + public static void main(String[] args) throws Exception { + // create listener + InetSocketAddress isa = new InetSocketAddress(0); + ServerSocketChannel ssc = ServerSocketChannel.open(); + ssc.socket().bind(isa); + + // register with Selector + final Selector sel = Selector.open(); + ssc.configureBlocking(false); + SelectionKey key = ssc.register(sel, SelectionKey.OP_ACCEPT); + + ThreadFactory factory = new ThreadFactory() { + @Override + public Thread newThread(Runnable r) { + Thread t = new Thread(r); + t.setDaemon(true); + return t; + } + }; + + // schedule test to run for 1 minute + Executors.newScheduledThreadPool(1, factory).schedule(new Runnable() { + public void run() { + done = true; + sel.wakeup(); + }}, 1, TimeUnit.MINUTES); + + // create Executor that handles tasks that closes channels + // "asynchronously" - this creates the conditions to provoke the bug. + Executor executor = Executors.newFixedThreadPool(2, factory); + + // submit task that connects to listener + executor.execute(new Connector(ssc.socket().getLocalPort())); + + // loop accepting connections until done (or an IOException is thrown) + while (!done) { + sel.select(); + if (key.isAcceptable()) { + SocketChannel sc = ssc.accept(); + if (sc != null) { + sc.configureBlocking(false); + sc.register(sel, SelectionKey.OP_READ); + executor.execute(new Closer(sc)); + } + } + sel.selectedKeys().clear(); + } + } +} diff --git a/test/java/nio/channels/Selector/lots_of_updates.sh b/test/java/nio/channels/Selector/lots_of_updates.sh new file mode 100644 index 0000000000000000000000000000000000000000..5054f18cc323ce5b54d3af0c8c759d4ef624ddd1 --- /dev/null +++ b/test/java/nio/channels/Selector/lots_of_updates.sh @@ -0,0 +1,49 @@ +# +# 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. +# +# 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. +# + +# @test +# @bug 6824477 +# @summary Selector.select can fail with IOException "Invalid argument" on +# Solaris if maximum number of file descriptors is less than 10000 +# @build LotsOfUpdates +# @run shell lots_of_updates.sh + +OS=`uname -s` +case "$OS" in + Windows_* ) + echo "ulimit not on Windows" + exit 0 + ;; + * ) + CLASSPATH=${TESTCLASSES}:${TESTSRC} + ;; +esac +export CLASSPATH + +# hard limit needs to be less than 10000 for this bug +NOFILES=`ulimit -n -H` +if [ "$NOFILES" = "unlimited" ] || [ $NOFILES -ge 10000 ]; then + ulimit -n 2048 +fi + +${TESTJAVA}/bin/java LotsOfUpdates diff --git a/test/java/nio/channels/ServerSocketChannel/SocketOptionTests.java b/test/java/nio/channels/ServerSocketChannel/SocketOptionTests.java index 6c4a443ed0af23949405e9e17f084c20332fe5dd..cba99e0f285683493e89322e61d91586022235f6 100644 --- a/test/java/nio/channels/ServerSocketChannel/SocketOptionTests.java +++ b/test/java/nio/channels/ServerSocketChannel/SocketOptionTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2007-2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2007-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 @@ -48,7 +48,7 @@ public class SocketOptionTests { ServerSocketChannel ssc = ServerSocketChannel.open(); // check supported options - Set<SocketOption<?>> options = ssc.options(); + Set<SocketOption<?>> options = ssc.supportedOptions(); if (!options.contains(SO_REUSEADDR)) throw new RuntimeException("SO_REUSEADDR should be supported"); if (!options.contains(SO_RCVBUF)) diff --git a/test/java/nio/channels/SocketChannel/SocketOptionTests.java b/test/java/nio/channels/SocketChannel/SocketOptionTests.java index b6fadced8e28c69ed078dd4609f75b5f8ecc429b..abcb97476ef1f090bbfe59f89b7e1002aa41fe65 100644 --- a/test/java/nio/channels/SocketChannel/SocketOptionTests.java +++ b/test/java/nio/channels/SocketChannel/SocketOptionTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2007-2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2007-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 @@ -48,7 +48,7 @@ public class SocketOptionTests { SocketChannel sc = SocketChannel.open(); // check supported options - Set<SocketOption<?>> options = sc.options(); + Set<SocketOption<?>> options = sc.supportedOptions(); List<? extends SocketOption> expected = Arrays.asList(SO_SNDBUF, SO_RCVBUF, SO_KEEPALIVE, SO_REUSEADDR, SO_LINGER, TCP_NODELAY); for (SocketOption opt: expected) { diff --git a/test/java/nio/channels/etc/NetworkChannelTests.java b/test/java/nio/channels/etc/NetworkChannelTests.java index 5f03453ca11aba193c5c0f8299f6b589956f4ea9..2a29bcebbd6271c8c1c46e63991042564ad18de1 100644 --- a/test/java/nio/channels/etc/NetworkChannelTests.java +++ b/test/java/nio/channels/etc/NetworkChannelTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2007-2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2007-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 @@ -103,13 +103,14 @@ public class NetworkChannelTests { // closed ch.close(); - if (ch.getLocalAddress() != null) { - throw new RuntimeException("Local address return when closed"); - } + try { + ch.getLocalAddress(); + throw new RuntimeException("ClosedChannelException expected"); + } catch (ClosedChannelException e) { } } /** - * Exercise getConnectedAddress method (SocketChannel only) + * Exercise getRemoteAddress method (SocketChannel only) */ static void connectedAddressTests() throws IOException { ServerSocketChannel ssc = ServerSocketChannel.open() @@ -121,19 +122,21 @@ public class NetworkChannelTests { SocketChannel sc = SocketChannel.open(); // not connected - if (sc.getConnectedAddress() != null) - throw new RuntimeException("getConnectedAddress returned address when not connected"); + if (sc.getRemoteAddress() != null) + throw new RuntimeException("getRemoteAddress returned address when not connected"); // connected sc.connect(server); - SocketAddress remote = sc.getConnectedAddress(); + SocketAddress remote = sc.getRemoteAddress(); if (!remote.equals(server)) - throw new RuntimeException("getConnectedAddress returned incorrect address"); + throw new RuntimeException("getRemoteAddress returned incorrect address"); // closed sc.close(); - if (sc.getConnectedAddress() != null) - throw new RuntimeException("getConnectedAddress returned address when closed"); + try { + sc.getRemoteAddress(); + throw new RuntimeException("ClosedChannelException expected"); + } catch (ClosedChannelException e) { } ssc.close(); } diff --git a/test/java/nio/channels/spi/AsynchronousChannelProvider/CheckProvider.java b/test/java/nio/channels/spi/AsynchronousChannelProvider/CheckProvider.java new file mode 100644 index 0000000000000000000000000000000000000000..4f6d8483807b933d3d6174f69c9d18e0f7e4595d --- /dev/null +++ b/test/java/nio/channels/spi/AsynchronousChannelProvider/CheckProvider.java @@ -0,0 +1,38 @@ +/* + * Copyright 2008-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. + * + * 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. + */ + +import java.nio.channels.spi.AsynchronousChannelProvider; + +public class CheckProvider { + public static void main(String[] args) { + Class<?> c = AsynchronousChannelProvider.provider().getClass(); + + String expected = args[0]; + String actual = c.getName(); + + if (!actual.equals(expected)) + throw new RuntimeException("Provider is of type '" + actual + + "', expected '" + expected + "'"); + + } +} diff --git a/test/java/nio/channels/spi/AsynchronousChannelProvider/META-INF/services/java.nio.channels.spi.AsynchronousChannelProvider b/test/java/nio/channels/spi/AsynchronousChannelProvider/META-INF/services/java.nio.channels.spi.AsynchronousChannelProvider new file mode 100644 index 0000000000000000000000000000000000000000..6b3e87eb404b0d725823b442da3e6c4a1b59cf71 --- /dev/null +++ b/test/java/nio/channels/spi/AsynchronousChannelProvider/META-INF/services/java.nio.channels.spi.AsynchronousChannelProvider @@ -0,0 +1 @@ +Provider1 diff --git a/test/java/nio/channels/spi/AsynchronousChannelProvider/Provider1.java b/test/java/nio/channels/spi/AsynchronousChannelProvider/Provider1.java new file mode 100644 index 0000000000000000000000000000000000000000..fc6036a1ea92b9e4e3435aa987c1f0d56a88536c --- /dev/null +++ b/test/java/nio/channels/spi/AsynchronousChannelProvider/Provider1.java @@ -0,0 +1,69 @@ +/* + * Copyright 2008-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. + * + * 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. + */ + +import java.nio.channels.spi.AsynchronousChannelProvider; +import java.nio.channels.*; +import java.net.ProtocolFamily; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.ThreadFactory; +import java.io.IOException; + +public class Provider1 extends AsynchronousChannelProvider { + public Provider1() { + } + + @Override + public AsynchronousChannelGroup openAsynchronousChannelGroup(int nThreads, ThreadFactory factorry) + throws IOException + { + throw new RuntimeException(); + } + + @Override + public AsynchronousChannelGroup openAsynchronousChannelGroup(ExecutorService executor, int initialSize) + throws IOException + { + throw new RuntimeException(); + } + + @Override + public AsynchronousSocketChannel openAsynchronousSocketChannel + (AsynchronousChannelGroup group) throws IOException + { + throw new RuntimeException(); + } + + @Override + public AsynchronousServerSocketChannel openAsynchronousServerSocketChannel + (AsynchronousChannelGroup group) throws IOException + { + throw new RuntimeException(); + } + + @Override + public AsynchronousDatagramChannel openAsynchronousDatagramChannel + (ProtocolFamily family, AsynchronousChannelGroup group) throws IOException + { + throw new RuntimeException(); + } +} diff --git a/test/java/nio/channels/spi/AsynchronousChannelProvider/Provider2.java b/test/java/nio/channels/spi/AsynchronousChannelProvider/Provider2.java new file mode 100644 index 0000000000000000000000000000000000000000..a42c12ff9def5aabcb371a93a363895c0e3fa095 --- /dev/null +++ b/test/java/nio/channels/spi/AsynchronousChannelProvider/Provider2.java @@ -0,0 +1,69 @@ +/* + * Copyright 2008-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. + * + * 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. + */ + +import java.nio.channels.spi.AsynchronousChannelProvider; +import java.nio.channels.*; +import java.net.ProtocolFamily; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.ThreadFactory; +import java.io.IOException; + +public class Provider2 extends AsynchronousChannelProvider { + public Provider2() { + } + + @Override + public AsynchronousChannelGroup openAsynchronousChannelGroup + (int nThreads, ThreadFactory threadFactory) throws IOException + { + throw new RuntimeException(); + } + + @Override + public AsynchronousChannelGroup openAsynchronousChannelGroup + (ExecutorService executor, int initialSize) throws IOException + { + throw new RuntimeException(); + } + + @Override + public AsynchronousSocketChannel openAsynchronousSocketChannel + (AsynchronousChannelGroup group) throws IOException + { + throw new RuntimeException(); + } + + @Override + public AsynchronousServerSocketChannel openAsynchronousServerSocketChannel + (AsynchronousChannelGroup group) throws IOException + { + throw new RuntimeException(); + } + + @Override + public AsynchronousDatagramChannel openAsynchronousDatagramChannel + (ProtocolFamily family, AsynchronousChannelGroup group) throws IOException + { + throw new RuntimeException(); + } +} diff --git a/test/java/nio/channels/spi/AsynchronousChannelProvider/custom_provider.sh b/test/java/nio/channels/spi/AsynchronousChannelProvider/custom_provider.sh new file mode 100644 index 0000000000000000000000000000000000000000..13fb2a2fae0e1ad8826ed516c3cc35feae3d839a --- /dev/null +++ b/test/java/nio/channels/spi/AsynchronousChannelProvider/custom_provider.sh @@ -0,0 +1,71 @@ +# +# Copyright 2008-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. +# +# 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. +# + +# @test +# @summary Unit test for java.nio.channels.spi.AsynchronousChannelProvider +# @build Provider1 Provider2 CheckProvider +# @run shell custom_provider.sh + +# if TESTJAVA isn't set then we assume an interactive run. + +if [ -z "$TESTJAVA" ]; then + TESTSRC=. + TESTCLASSES=. + JAVA=java +else + JAVA="${TESTJAVA}/bin/java" +fi + +OS=`uname -s` +case "$OS" in + Windows_* ) + CLASSPATH="${TESTCLASSES};${TESTSRC}" + ;; + * ) + CLASSPATH=${TESTCLASSES}:${TESTSRC} + ;; +esac +export CLASSPATH + +failures=0 + +go() { + echo '' + $JAVA $1 $2 $3 2>&1 + if [ $? != 0 ]; then failures=`expr $failures + 1`; fi +} + +# Run the tests + +go CheckProvider Provider1 +go -Djava.nio.channels.spi.AsynchronousChannelProvider=Provider2 CheckProvider \ + Provider2 + +# +# Results +# +echo '' +if [ $failures -gt 0 ]; + then echo "$failures test(s) failed"; + else echo "All test(s) passed"; fi +exit $failures diff --git a/test/java/nio/file/DirectoryStream/Basic.java b/test/java/nio/file/DirectoryStream/Basic.java new file mode 100644 index 0000000000000000000000000000000000000000..b92447d70f63c43ac9e03bb9b208477bead34beb --- /dev/null +++ b/test/java/nio/file/DirectoryStream/Basic.java @@ -0,0 +1,168 @@ +/* + * Copyright 2008-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. + * + * 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. + */ + +/* @test + * @bug 4313887 + * @summary Unit test for java.nio.file.DirectoryStream + * @library .. + */ + +import java.nio.file.*; +import java.util.*; +import java.io.IOException; + +public class Basic { + static boolean found; + + static void doTest(final Path dir) throws IOException { + DirectoryStream<Path> stream; + + // test that directory is empty + Files.withDirectory(dir, new FileAction<FileRef>() { + public void invoke(FileRef entry) { + throw new RuntimeException("directory not empty"); + } + }); + + // create file in directory + final Path foo = Paths.get("foo"); + dir.resolve(foo).createFile(); + + // iterate over directory and check there is one entry + found = false; + Files.withDirectory(dir, new FileAction<Path>() { + public void invoke(Path entry) { + if (entry.getName().equals(foo)) { + if (found) + throw new RuntimeException("entry already found"); + found = true; + } else { + throw new RuntimeException("entry " + entry.getName() + + " not expected"); + } + } + }); + if (!found) + throw new RuntimeException("entry not found"); + + // check filtering: f* should match foo + DirectoryStream.Filter<Path> filter = new DirectoryStream.Filter<Path>() { + private PathMatcher matcher = + dir.getFileSystem().getPathMatcher("glob:f*"); + public boolean accept(Path file) { + return matcher.matches(file); + } + }; + Files.withDirectory(dir, filter, new FileAction<Path>() { + public void invoke(Path entry) { + if (!entry.getName().equals(foo)) + throw new RuntimeException("entry not expected"); + } + }); + + // check filtering: z* should not match any files + filter = new DirectoryStream.Filter<Path>() { + private PathMatcher matcher = + dir.getFileSystem().getPathMatcher("glob:z*"); + public boolean accept(Path file) { + return matcher.matches(file); + } + }; + Files.withDirectory(dir, filter, new FileAction<FileRef>() { + public void invoke(FileRef entry) { + throw new RuntimeException("no matching entries expected"); + } + }); + + // check that exception or error thrown by filter is not thrown + // by newDirectoryStream or iterator method. + stream = dir.newDirectoryStream(new DirectoryStream.Filter<Path>() { + public boolean accept(Path file) { + throw new RuntimeException("Should not be visible"); + } + }); + try { + stream.iterator(); + } finally { + stream.close(); + } + + // test NotDirectoryException + try { + dir.resolve(foo).newDirectoryStream(); + throw new RuntimeException("NotDirectoryException not thrown"); + } catch (NotDirectoryException x) { + } + + // test iterator remove method + stream = dir.newDirectoryStream(); + Iterator<Path> i = stream.iterator(); + while (i.hasNext()) { + Path entry = i.next(); + if (!entry.getName().equals(foo)) + throw new RuntimeException("entry not expected"); + i.remove(); + } + stream.close(); + + // test IllegalStateException + stream = dir.newDirectoryStream(); + i = stream.iterator(); + try { + stream.iterator(); + throw new RuntimeException("IllegalStateException not thrown as expected"); + } catch (IllegalStateException x) { + } + stream.close(); + try { + stream.iterator(); + throw new RuntimeException("IllegalStateException not thrown as expected"); + } catch (IllegalStateException x) { + } + try { + i.hasNext(); + throw new RuntimeException("ConcurrentModificationException not thrown as expected"); + } catch (ConcurrentModificationException x) { + Throwable t = x.getCause(); + if (!(t instanceof IllegalStateException)) + throw new RuntimeException("Cause is not IllegalStateException as expected"); + } + try { + i.next(); + throw new RuntimeException("IllegalStateException not thrown as expected"); + } catch (ConcurrentModificationException x) { + Throwable t = x.getCause(); + if (!(t instanceof IllegalStateException)) + throw new RuntimeException("Cause is not IllegalStateException as expected"); + } + } + + public static void main(String[] args) throws IOException { + Path dir = TestUtil.createTemporaryDirectory(); + try { + doTest(dir); + } finally { + TestUtil.removeAll(dir); + } + } +} diff --git a/test/java/nio/file/DirectoryStream/DriveLetter.java b/test/java/nio/file/DirectoryStream/DriveLetter.java new file mode 100644 index 0000000000000000000000000000000000000000..92159f5df5fd8598a547eede3fa741756dc4cb29 --- /dev/null +++ b/test/java/nio/file/DirectoryStream/DriveLetter.java @@ -0,0 +1,73 @@ +/* + * Copyright 2008-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. + * + * 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. + */ + +/* @test + * @bug 6808647 + * @summary Checks that a DirectoryStream's iterator returns the expected + * path when opening a directory by specifying only the drive letter. + * @library .. + */ + +import java.nio.file.*; +import java.io.File; +import java.io.IOException; + +public class DriveLetter { + + public static void main(String[] args) throws IOException { + String os = System.getProperty("os.name"); + if (!os.startsWith("Windows")) { + System.out.println("This is Windows specific test"); + return; + } + String here = System.getProperty("user.dir"); + if (here.length() < 2 || here.charAt(1) != ':') + throw new RuntimeException("Unable to determine drive letter"); + + // create temporary file in current directory + File tempFile = File.createTempFile("foo", "tmp", new File(here)); + try { + // we should expect C:foo.tmp to be returned by iterator + String drive = here.substring(0, 2); + Path expected = Paths.get(drive).resolve(tempFile.getName()); + + boolean found = false; + DirectoryStream<Path> stream = Paths.get(drive).newDirectoryStream(); + try { + for (Path file : stream) { + if (file.equals(expected)) { + found = true; + break; + } + } + } finally { + stream.close(); + } + if (!found) + throw new RuntimeException("Temporary file not found???"); + + } finally { + tempFile.delete(); + } + } +} diff --git a/test/java/nio/file/DirectoryStream/Filters.java b/test/java/nio/file/DirectoryStream/Filters.java new file mode 100644 index 0000000000000000000000000000000000000000..ea539c95df369afdb58bff1d5afa768a835f7ada --- /dev/null +++ b/test/java/nio/file/DirectoryStream/Filters.java @@ -0,0 +1,241 @@ +/* + * Copyright 2008-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. + * + * 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. + */ + +/* @test + * @bug 4313887 + * @summary Unit test for java.nio.file.DirectoryStreamFilters + * @library .. + */ + +import java.nio.file.*; +import static java.nio.file.DirectoryStreamFilters.*; +import java.nio.file.attribute.Attributes; +import java.io.*; +import java.util.*; + +public class Filters { + static final Random rand = new Random(); + + // returns a filter that only accepts files that are larger than a given size + static DirectoryStream.Filter<FileRef> newMinimumSizeFilter(final long min) { + return new DirectoryStream.Filter<FileRef>() { + public boolean accept(FileRef file) { + try { + long size = Attributes.readBasicFileAttributes(file).size(); + return size >= min; + } catch (IOException e) { + throw new IOError(e); + } + } + }; + } + + // returns a filter that only accepts files that are matched by a given glob + static DirectoryStream.Filter<Path> newGlobFilter(final String glob) { + return new DirectoryStream.Filter<Path>() { + PathMatcher matcher = FileSystems.getDefault().getPathMatcher("glob:"+ glob); + public boolean accept(Path file) { + return matcher.matches(file.getName()); + } + }; + } + + static final int BIG_FILE_THRESHOLD = 8192; + + static int totalCount; + static int htmlCount; + static int bigAndHtmlCount; + static int bigOrHtmlCount; + + // generates random files in the test directory and initializes the counts + static void setup(Path dir) throws IOException { + // create 10-26 files. + totalCount = 10 + rand.nextInt(17); + char firstChar = 'A'; + for (int i=0; i<totalCount; i++) { + boolean isHtml = rand.nextBoolean(); + boolean isBig = rand.nextBoolean(); + if (isHtml) { + htmlCount++; + if (isBig) bigAndHtmlCount++; + } + if (isHtml || isBig) + bigOrHtmlCount++; + String name; + if (isHtml) { + name = firstChar + ".html"; + } else { + name = firstChar + ".tmp"; + } + firstChar++; + int size = rand.nextInt(BIG_FILE_THRESHOLD); + if (isBig) + size += BIG_FILE_THRESHOLD; + Path file = dir.resolve(name); + OutputStream out = file.newOutputStream(); + try { + if (size > 0) + out.write(new byte[size]); + } finally { + out.close(); + } + System.out.format("Created %s, size %d byte(s)\n", name, size); + } + } + + static boolean isHtml(Path file) { + return file.toString().endsWith(".html"); + } + + static boolean isBig(Path file) throws IOException { + long size = Attributes.readBasicFileAttributes(file).size(); + return size >= BIG_FILE_THRESHOLD; + } + + static void checkCount(int expected, int actual) { + if (actual != expected) + throw new RuntimeException("'" + expected + + "' entries expected, actual: " + actual); + } + + static void doTests(Path dir) throws IOException { + final List<DirectoryStream.Filter<Path>> emptyList = Collections.emptyList(); + + // list containing two filters + List<DirectoryStream.Filter<? super Path>> filters = + new ArrayList<DirectoryStream.Filter<? super Path>>(); + filters.add(newMinimumSizeFilter(BIG_FILE_THRESHOLD)); + filters.add(newGlobFilter("*.html")); + + int accepted; + DirectoryStream<Path> stream; + + System.out.println("Test: newContentTypeFilter"); + accepted = 0; + stream = dir.newDirectoryStream(newContentTypeFilter("text/html")); + try { + for (Path entry: stream) { + if (!isHtml(entry)) + throw new RuntimeException("html file expected"); + accepted++; + } + } finally { + stream.close(); + } + checkCount(htmlCount, accepted); + + System.out.println("Test: allOf with list of filters"); + accepted = 0; + stream = dir.newDirectoryStream(allOf(filters)); + try { + for (Path entry: stream) { + if (!isHtml(entry)) + throw new RuntimeException("html file expected"); + if (!isBig(entry)) + throw new RuntimeException("big file expected"); + accepted++; + } + } finally { + stream.close(); + } + checkCount(bigAndHtmlCount, accepted); + + System.out.println("Test: allOf with empty list"); + accepted = 0; + stream = dir.newDirectoryStream(allOf(emptyList)); + try { + for (Path entry: stream) { + accepted++; + } + } finally { + stream.close(); + } + checkCount(totalCount, accepted); + + System.out.println("Test: anyOf with list of filters"); + accepted = 0; + stream = dir.newDirectoryStream(anyOf(filters)); + try { + for (Path entry: stream) { + if (!isHtml(entry) && !isBig(entry)) + throw new RuntimeException("html or big file expected"); + accepted++; + } + } finally { + stream.close(); + } + checkCount(bigOrHtmlCount, accepted); + + System.out.println("Test: anyOf with empty list"); + accepted = 0; + stream = dir.newDirectoryStream(anyOf(emptyList)); + try { + for (Path entry: stream) { + accepted++; + } + } finally { + stream.close(); + } + checkCount(0, accepted); + + System.out.println("Test: complementOf"); + accepted = 0; + stream = dir.newDirectoryStream(complementOf(newGlobFilter("*.html"))); + try { + for (Path entry: stream) { + accepted++; + } + } finally { + stream.close(); + } + checkCount(totalCount-htmlCount, accepted); + + System.out.println("Test: nulls"); + try { + newContentTypeFilter(null); + throw new RuntimeException("NullPointerException expected"); + } catch (NullPointerException npe) { } + try { + allOf(null); + throw new RuntimeException("NullPointerException expected"); + } catch (NullPointerException npe) { } + try { + anyOf(null); + throw new RuntimeException("NullPointerException expected"); + } catch (NullPointerException npe) { } + try { + complementOf(null); + throw new RuntimeException("NullPointerException expected"); + } catch (NullPointerException npe) { } + } + + public static void main(String[] args) throws IOException { + Path dir = TestUtil.createTemporaryDirectory(); + try { + setup(dir); + doTests(dir); + } finally { + TestUtil.removeAll(dir); + } + } +} diff --git a/test/java/nio/file/DirectoryStream/SecureDS.java b/test/java/nio/file/DirectoryStream/SecureDS.java new file mode 100644 index 0000000000000000000000000000000000000000..98367d8958c0e016681fb1876a5f11eba670dcfd --- /dev/null +++ b/test/java/nio/file/DirectoryStream/SecureDS.java @@ -0,0 +1,370 @@ +/* + * Copyright 2008-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. + * + * 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. + */ + +/* @test + * @bug 4313887 + * @summary Unit test for java.nio.file.SecureDirectoryStream + * @library .. + */ + +import java.nio.file.*; +import static java.nio.file.StandardOpenOption.*; +import static java.nio.file.LinkOption.*; +import java.nio.file.attribute.*; +import java.nio.channels.*; +import java.io.IOException; +import java.util.*; + +public class SecureDS { + static boolean supportsLinks; + + public static void main(String[] args) throws IOException { + Path dir = TestUtil.createTemporaryDirectory(); + try { + DirectoryStream stream = dir.newDirectoryStream(); + stream.close(); + if (!(stream instanceof SecureDirectoryStream)) { + System.out.println("SecureDirectoryStream not supported."); + return; + } + + supportsLinks = TestUtil.supportsLinks(dir); + + // run tests + doBasicTests(dir); + doMoveTests(dir); + miscTests(dir); + + } finally { + TestUtil.removeAll(dir); + } + } + + // Exercise each of SecureDirectoryStream's method (except move) + static void doBasicTests(Path dir) throws IOException { + Path dir1 = dir.resolve("dir1").createDirectory(); + Path dir2 = dir.resolve("dir2"); + + // create a file, directory, and two sym links in the directory + Path fileEntry = Paths.get("myfile"); + dir1.resolve(fileEntry).createFile(); + Path dirEntry = Paths.get("mydir"); + dir1.resolve(dirEntry).createDirectory(); + // myfilelink -> myfile + Path link1Entry = Paths.get("myfilelink"); + if (supportsLinks) + dir1.resolve(link1Entry).createSymbolicLink(fileEntry); + // mydirlink -> mydir + Path link2Entry = Paths.get("mydirlink"); + if (supportsLinks) + dir1.resolve(link2Entry).createSymbolicLink(dirEntry); + + // open directory and then move it so that it is no longer accessible + // via its original path. + SecureDirectoryStream stream = + (SecureDirectoryStream)dir1.newDirectoryStream(); + dir1.moveTo(dir2); + + // Test: iterate over all entries + int count = 0; + for (Path entry: stream) { count++; } + assertTrue(count == (supportsLinks ? 4 : 2)); + + // Test: getFileAttributeView to access directory's attributes + assertTrue(stream + .getFileAttributeView(BasicFileAttributeView.class) + .readAttributes() + .isDirectory()); + + // Test: dynamic access to directory's attributes + BasicFileAttributeView view = stream. + getFileAttributeView(BasicFileAttributeView.class); + Map<String,?> attrs = view.readAttributes("*"); + assertTrue((Boolean)attrs.get("isDirectory")); + attrs = view.readAttributes("isRegularFile", "size"); + assertTrue(!(Boolean)attrs.get("isRegularFile")); + assertTrue((Long)attrs.get("size") >= 0); + int linkCount = (Integer)view.getAttribute("linkCount"); + assertTrue(linkCount > 0); + view.setAttribute("lastModifiedTime", 0L); + + // Test: getFileAttributeView to access attributes of entries + assertTrue(stream + .getFileAttributeView(fileEntry, BasicFileAttributeView.class) + .readAttributes() + .isRegularFile()); + assertTrue(stream + .getFileAttributeView(fileEntry, BasicFileAttributeView.class, NOFOLLOW_LINKS) + .readAttributes() + .isRegularFile()); + assertTrue(stream + .getFileAttributeView(dirEntry, BasicFileAttributeView.class) + .readAttributes() + .isDirectory()); + assertTrue(stream + .getFileAttributeView(dirEntry, BasicFileAttributeView.class, NOFOLLOW_LINKS) + .readAttributes() + .isDirectory()); + if (supportsLinks) { + assertTrue(stream + .getFileAttributeView(link1Entry, BasicFileAttributeView.class) + .readAttributes() + .isRegularFile()); + assertTrue(stream + .getFileAttributeView(link1Entry, BasicFileAttributeView.class, NOFOLLOW_LINKS) + .readAttributes() + .isSymbolicLink()); + assertTrue(stream + .getFileAttributeView(link2Entry, BasicFileAttributeView.class) + .readAttributes() + .isDirectory()); + assertTrue(stream + .getFileAttributeView(link2Entry, BasicFileAttributeView.class, NOFOLLOW_LINKS) + .readAttributes() + .isSymbolicLink()); + } + + // Test: dynamic access to entry attributes + view = stream + .getFileAttributeView(fileEntry, PosixFileAttributeView.class, NOFOLLOW_LINKS); + if (view != null) { + attrs = view.readAttributes("owner", "size"); + UserPrincipal owner = (UserPrincipal)attrs.get("owner"); + assertTrue(owner != null); + assertTrue((Long)attrs.get("size") >= 0L); + view.setAttribute("lastAccessTime", 0L); + } + + // Test: newByteChannel + Set<StandardOpenOption> opts = Collections.emptySet(); + stream.newByteChannel(fileEntry, opts).close(); + if (supportsLinks) { + stream.newByteChannel(link1Entry, opts).close(); + try { + Set<OpenOption> mixed = new HashSet<OpenOption>(); + mixed.add(READ); + mixed.add(NOFOLLOW_LINKS); + stream.newByteChannel(link1Entry, mixed).close(); + shouldNotGetHere(); + } catch (IOException x) { } + } + + // Test: newDirectoryStream + stream.newDirectoryStream(dirEntry, true, null).close(); + stream.newDirectoryStream(dirEntry, false, null).close(); + if (supportsLinks) { + stream.newDirectoryStream(link2Entry, true, null).close(); + try { + stream.newDirectoryStream(link2Entry, false, null).close(); + shouldNotGetHere(); + } catch (IOException x) { } + } + + // Test: delete + if (supportsLinks) { + stream.deleteFile(link1Entry); + stream.deleteFile(link2Entry); + } + stream.deleteDirectory(dirEntry); + stream.deleteFile(fileEntry); + + // Test: remove + // (requires resetting environment to get new iterator) + stream.close(); + dir2.moveTo(dir1); + dir1.resolve(fileEntry).createFile(); + stream = (SecureDirectoryStream)dir1.newDirectoryStream(); + dir1.moveTo(dir2); + Iterator<Path> iter = stream.iterator(); + int removed = 0; + while (iter.hasNext()) { + iter.next(); + iter.remove(); + removed++; + } + assertTrue(removed == 1); + + // clean-up + stream.close(); + dir2.delete(); + } + + // Exercise SecureDirectoryStream's move method + static void doMoveTests(Path dir) throws IOException { + Path dir1 = dir.resolve("dir1").createDirectory(); + Path dir2 = dir.resolve("dir2").createDirectory(); + + // create dir1/myfile, dir1/mydir, dir1/mylink + Path fileEntry = Paths.get("myfile"); + dir1.resolve(fileEntry).createFile(); + Path dirEntry = Paths.get("mydir"); + dir1.resolve(dirEntry).createDirectory(); + Path linkEntry = Paths.get("mylink"); + if (supportsLinks) + dir1.resolve(linkEntry).createSymbolicLink(Paths.get("missing")); + + // target name + Path target = Paths.get("newfile"); + + // open stream to both directories + SecureDirectoryStream stream1 = + (SecureDirectoryStream)dir1.newDirectoryStream(); + SecureDirectoryStream stream2 = + (SecureDirectoryStream)dir2.newDirectoryStream(); + + // Test: move dir1/myfile -> dir2/newfile + stream1.move(fileEntry, stream2, target); + assertTrue(dir1.resolve(fileEntry).notExists()); + assertTrue(dir2.resolve(target).exists()); + stream2.deleteFile(target); + + // Test: move dir1/mydir -> dir2/newfile + stream1.move(dirEntry, stream2, target); + assertTrue(dir1.resolve(dirEntry).notExists()); + assertTrue(dir2.resolve(target).exists()); + stream2.deleteDirectory(target); + + // Test: move dir1/mylink -> dir2/newfile + if (supportsLinks) { + stream1.move(linkEntry, stream2, target); + assertTrue(dir2.resolve(target) + .getFileAttributeView(BasicFileAttributeView.class, NOFOLLOW_LINKS) + .readAttributes() + .isSymbolicLink()); + stream2.deleteFile(target); + } + + // Test: move between devices + String testDirAsString = System.getProperty("test.dir"); + if (testDirAsString != null) { + Path testDir = Paths.get(testDirAsString); + if (!dir1.getFileStore().equals(testDir.getFileStore())) { + SecureDirectoryStream ts = + (SecureDirectoryStream)testDir.newDirectoryStream(); + dir1.resolve(fileEntry).createFile(); + try { + stream1.move(fileEntry, ts, target); + shouldNotGetHere(); + } catch (AtomicMoveNotSupportedException x) { } + ts.close(); + stream1.deleteFile(fileEntry); + } + } + + // clean-up + dir1.delete(); + dir2.delete(); + } + + // null and ClosedDirectoryStreamException + static void miscTests(Path dir) throws IOException { + Path file = Paths.get("file"); + dir.resolve(file).createFile(); + + SecureDirectoryStream stream = + (SecureDirectoryStream)dir.newDirectoryStream(); + + // NullPointerException + try { + stream.getFileAttributeView(null); + shouldNotGetHere(); + } catch (NullPointerException x) { } + try { + stream.getFileAttributeView(null, BasicFileAttributeView.class); + shouldNotGetHere(); + } catch (NullPointerException x) { } + try { + stream.getFileAttributeView(file, null); + shouldNotGetHere(); + } catch (NullPointerException x) { } + try { + stream.newByteChannel(null, EnumSet.of(CREATE,WRITE)); + shouldNotGetHere(); + } catch (NullPointerException x) { } + try { + stream.newByteChannel(null, EnumSet.of(CREATE,WRITE,null)); + shouldNotGetHere(); + } catch (NullPointerException x) { } + try { + stream.newByteChannel(file, null); + shouldNotGetHere(); + } catch (NullPointerException x) { } + try { + stream.move(null, stream, file); + shouldNotGetHere(); + } catch (NullPointerException x) { } + try { + stream.move(file, null, file); + shouldNotGetHere(); + } catch (NullPointerException x) { } + try { + stream.move(file, stream, null); + shouldNotGetHere(); + } catch (NullPointerException x) { } + try { + stream.newDirectoryStream(null, true, null); + shouldNotGetHere(); + } catch (NullPointerException x) { } + try { + stream.deleteFile(null); + shouldNotGetHere(); + } catch (NullPointerException x) { } + try { + stream.deleteDirectory(null); + shouldNotGetHere(); + } catch (NullPointerException x) { } + + // close stream + stream.close(); + stream.close(); // should be no-op + + // ClosedDirectoryStreamException + try { + stream.newDirectoryStream(file, true, null); + shouldNotGetHere(); + } catch (ClosedDirectoryStreamException x) { } + try { + stream.newByteChannel(file, EnumSet.of(READ)); + shouldNotGetHere(); + } catch (ClosedDirectoryStreamException x) { } + try { + stream.move(file, stream, file); + shouldNotGetHere(); + } catch (ClosedDirectoryStreamException x) { } + try { + stream.deleteFile(file); + shouldNotGetHere(); + } catch (ClosedDirectoryStreamException x) { } + + // clean-up + dir.resolve(file).delete(); + } + + static void assertTrue(boolean b) { + if (!b) throw new RuntimeException("Assertion failed"); + } + + static void shouldNotGetHere() { + assertTrue(false); + } +} diff --git a/test/java/nio/file/FileStore/Basic.java b/test/java/nio/file/FileStore/Basic.java new file mode 100644 index 0000000000000000000000000000000000000000..604795db43591870b97ec35a27dda563ebd0c4a6 --- /dev/null +++ b/test/java/nio/file/FileStore/Basic.java @@ -0,0 +1,87 @@ +/* + * Copyright 2008-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. + * + * 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. + */ + +/* @test + * @bug 4313887 + * @summary Unit test for java.nio.file.FileStore + * @library .. + */ + +import java.nio.file.*; +import java.nio.file.attribute.*; +import java.io.IOException; +import java.util.*; + +public class Basic { + + public static void main(String[] args) throws IOException { + Path dir = TestUtil.createTemporaryDirectory(); + try { + doTests(dir); + } finally { + TestUtil.removeAll(dir); + } + } + + static void assertTrue(boolean okay) { + if (!okay) + throw new RuntimeException("Assertion failed"); + } + + static void doTests(Path dir) throws IOException { + /** + * Test: Directory should be on FileStore that is writable + */ + assertTrue(!dir.getFileStore().isReadOnly()); + + /** + * Test: Two files should have the same FileStore + */ + FileStore store1 = dir.resolve("foo").createFile().getFileStore(); + FileStore store2 = dir.resolve("bar").createFile().getFileStore(); + assertTrue(store1.equals(store2)); + assertTrue(store2.equals(store1)); + assertTrue(store1.hashCode() == store2.hashCode()); + + /** + * Test: File and FileStore attributes + */ + assertTrue(store1.supportsFileAttributeView("basic")); + + /** + * Test: Enumerate all FileStores + */ + FileStore prev = null; + for (FileStore store: FileSystems.getDefault().getFileStores()) { + System.out.format("%s (name=%s type=%s)\n", store, store.name(), + store.type()); + + // check space attributes + Attributes.readFileStoreSpaceAttributes(store); + + // two distinct FileStores should not be equal + assertTrue(!store.equals(prev)); + prev = store; + } + } +} diff --git a/test/java/nio/file/FileSystem/Basic.java b/test/java/nio/file/FileSystem/Basic.java new file mode 100644 index 0000000000000000000000000000000000000000..8df7c1e8de60405d3ef86e7c62f692ccbd86d725 --- /dev/null +++ b/test/java/nio/file/FileSystem/Basic.java @@ -0,0 +1,82 @@ +/* + * Copyright 2008-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. + * + * 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. + */ + +/* @test + * @bug 4313887 + * @summary Unit test for java.nio.file.FileSystem + * @library .. + */ + +import java.nio.file.*; +import java.nio.file.attribute.*; +import java.io.IOException; + +/** + * Simple santity checks for java.nio.file.FileSystem + */ +public class Basic { + + static void check(boolean okay, String msg) { + if (!okay) + throw new RuntimeException(msg); + } + + static void checkSupported(FileSystem fs, String... views) { + for (String view: views) { + check(fs.supportedFileAttributeViews().contains(view), + "support for '" + view + "' expected"); + } + } + + public static void main(String[] args) throws IOException { + FileSystem fs = FileSystems.getDefault(); + + // close should throw UOE + try { + fs.close(); + throw new RuntimeException("UnsupportedOperationException expected"); + } catch (UnsupportedOperationException e) { } + check(fs.isOpen(), "should be open"); + + check(!fs.isReadOnly(), "should provide read-write access"); + + check(fs.provider().getScheme().equals("file"), + "should use 'file' scheme"); + + // santity check method - need to re-visit this in future as I/O errors + // are possible + for (FileStore store: fs.getFileStores()) { + System.out.println(store); + } + + // sanity check supportedFileAttributeViews + checkSupported(fs, "basic"); + String os = System.getProperty("os.name"); + if (os.equals("SunOS")) + checkSupported(fs, "posix", "unix", "owner", "acl", "xattr"); + if (os.equals("Linux")) + checkSupported(fs, "posix", "unix", "owner", "dos", "xattr"); + if (os.equals("Windows")) + checkSupported(fs, "owner", "dos", "acl", "xattr"); + } +} diff --git a/test/java/nio/file/Files/ContentType.java b/test/java/nio/file/Files/ContentType.java new file mode 100644 index 0000000000000000000000000000000000000000..a0a5afc22b7311f8de17ae262a221afd2bd96ebe --- /dev/null +++ b/test/java/nio/file/Files/ContentType.java @@ -0,0 +1,91 @@ +/* + * Copyright 2008-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. + * + * 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. + */ + +import java.nio.file.*; +import java.io.*; + +/** + * Uses Files.probeContentType to probe html file and custom file type. + */ + +public class ContentType { + + static FileRef createHtmlFile() throws IOException { + Path file = File.createTempFile("foo", ".html").toPath(); + OutputStream out = file.newOutputStream(); + try { + out.write("<html><body>foo</body></html>".getBytes()); + } finally { + out.close(); + } + + return file; + } + + static FileRef createUnknownFile() throws IOException { + return File.createTempFile("unknown", "unknown-file-type-789").toPath(); + } + + static FileRef createGrapeFile() throws IOException { + return File.createTempFile("red", ".grape").toPath(); + } + + public static void main(String[] args) throws IOException { + + // exercise default file type detector + FileRef file = createHtmlFile(); + try { + String type = Files.probeContentType(file); + if (type == null) { + System.err.println("Content type cannot be determined - test skipped"); + } else { + if (!type.equals("text/html")) + throw new RuntimeException("Unexpected type: " + type); + } + } finally { + TestUtil.deleteUnchecked(file); + } + file = createUnknownFile(); + try { + String type = Files.probeContentType(file); + if (type != null) + throw new RuntimeException(file + " should not be recognized as:" + + type); + } finally { + TestUtil.deleteUnchecked(file); + } + + // exercise custom file type detector + file = createGrapeFile(); + try { + String type = Files.probeContentType(file); + if (type == null) + throw new RuntimeException("Custom file type detector not installed?"); + if (!type.equals("grape/unknown")) + throw new RuntimeException("Unexpected type: " + type); + } finally { + TestUtil.deleteUnchecked(file); + } + + } +} diff --git a/test/java/nio/file/Files/CreateFileTree.java b/test/java/nio/file/Files/CreateFileTree.java new file mode 100644 index 0000000000000000000000000000000000000000..17549a7e350dc25ed6fd83e837ecd0d93633ac73 --- /dev/null +++ b/test/java/nio/file/Files/CreateFileTree.java @@ -0,0 +1,96 @@ +/* + * Copyright 2008-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. + * + * 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. + */ + +import java.nio.file.*; +import java.io.IOException; +import java.util.*; + +/** + * Creates a file tree with possible cycles caused by symbolic links + * to ancestor directories. + */ + +public class CreateFileTree { + + static final Random rand = new Random(); + + public static Path createTemporaryDirectory() throws IOException { + Path tmpdir = Paths.get(System.getProperty("java.io.tmpdir")); + Path dir; + do { + dir = tmpdir.resolve("name" + rand.nextInt()); + } while (dir.exists()); + dir.createDirectory(); + return dir; + } + + public static void main(String[] args) throws IOException { + Path top = createTemporaryDirectory(); + if (!top.isAbsolute()) + top = top.toAbsolutePath(); + + List<Path> dirs = new ArrayList<Path>(); + + // create tree + Queue<Path> queue = new ArrayDeque<Path>(); + queue.add(top); + int total = 1 + rand.nextInt(20); + int n = 0; + Path dir; + while (((dir = queue.poll()) != null) && (n < total)) { + int r = Math.min((total-n), (1+rand.nextInt(3))); + for (int i=0; i<r; i++) { + String name = "dir" + (++n); + Path subdir = dir.resolve(name).createDirectory(); + queue.offer(subdir); + dirs.add(subdir); + } + } + assert dirs.size() >= 2; + + // create a few regular files in the file tree + int files = dirs.size() * 3; + for (int i=0; i<files; i++) { + String name = "file" + (i+1); + int x = rand.nextInt(dirs.size()); + dirs.get(x).resolve(name).createFile(); + } + + // create a few sym links in the file tree so as to create cycles + int links = 1 + rand.nextInt(5); + for (int i=0; i<links; i++) { + int x = rand.nextInt(dirs.size()); + int y; + do { + y = rand.nextInt(dirs.size()); + } while (y != x); + String name = "link" + (i+1); + Path link = dirs.get(x).resolve(name); + Path target = dirs.get(y); + link.createSymbolicLink(target); + } + + // done + System.out.println(top); + } +} diff --git a/test/java/nio/file/Files/ForceLoad.java b/test/java/nio/file/Files/ForceLoad.java new file mode 100644 index 0000000000000000000000000000000000000000..b6fe84c34965209d85e5f2eeb92b57adc98180bf --- /dev/null +++ b/test/java/nio/file/Files/ForceLoad.java @@ -0,0 +1,38 @@ +/* + * Copyright 2008-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. + * + * 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. + */ + +/* @test + * @bug 4313887 + * @summary Test library dependencies by invoking Files.probeContentType + * before other methods that would cause nio.dll to be loaded. + */ + +import java.nio.file.*; +import java.io.IOException; + +public class ForceLoad { + + public static void main(String[] args) throws IOException { + Files.probeContentType(Paths.get(".")); + } +} diff --git a/test/java/nio/file/Files/META-INF/services/java.nio.file.spi.FileTypeDetector b/test/java/nio/file/Files/META-INF/services/java.nio.file.spi.FileTypeDetector new file mode 100644 index 0000000000000000000000000000000000000000..ccd6ac7b604c2570770ab51e1054b22f5c12d140 --- /dev/null +++ b/test/java/nio/file/Files/META-INF/services/java.nio.file.spi.FileTypeDetector @@ -0,0 +1 @@ +SimpleFileTypeDetector diff --git a/test/java/nio/file/Files/Misc.java b/test/java/nio/file/Files/Misc.java new file mode 100644 index 0000000000000000000000000000000000000000..dde74a4b546d0122940a48c72592a8d490b0505b --- /dev/null +++ b/test/java/nio/file/Files/Misc.java @@ -0,0 +1,126 @@ +/* + * Copyright 2008-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. + * + * 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. + */ + +/* @test + * @bug 4313887 + * @summary Unit test for java.nio.file.Files for miscellenous cases not + * covered by other tests + * @library .. + */ + +import java.nio.file.*; +import java.io.IOException; +import java.util.*; + +public class Misc { + + static void npeExpected() { + throw new RuntimeException("NullPointerException expected"); + } + + public static void main(String[] args) throws IOException { + try { + Files.probeContentType(null); + npeExpected(); + } catch (NullPointerException e) { + } + + try { + Files.withDirectory(null, "*", new FileAction<Path>() { + public void invoke(Path entry) { + } + }); + npeExpected(); + } catch (NullPointerException e) { + } + + try { + Files.withDirectory(Paths.get("."), (String)null, new FileAction<Path>() { + public void invoke(Path entry) { + } + }); + npeExpected(); + } catch (NullPointerException e) { + } + + try { + Files.withDirectory(Paths.get("."), "*", null); + npeExpected(); + } catch (NullPointerException e) { + } + + // test propogation of IOException + Path tmpdir = TestUtil.createTemporaryDirectory(); + try { + tmpdir.resolve("foo").createFile(); + try { + Files.withDirectory(tmpdir, new FileAction<Path>() { + public void invoke(Path entry) throws IOException { + throw new IOException(); + } + }); + throw new RuntimeException("IOException expected"); + } catch (IOException e) { + } + } finally { + TestUtil.removeAll(tmpdir); + } + + try { + Files.walkFileTree(null, EnumSet.noneOf(FileVisitOption.class), + Integer.MAX_VALUE, new SimpleFileVisitor<Path>(){}); + npeExpected(); + } catch (NullPointerException e) { + } + + try { + Files.walkFileTree(Paths.get("."), null, Integer.MAX_VALUE, + new SimpleFileVisitor<Path>(){}); + npeExpected(); + } catch (NullPointerException e) { + } + + try { + Files.walkFileTree(Paths.get("."), EnumSet.noneOf(FileVisitOption.class), + -1, new SimpleFileVisitor<Path>(){}); + throw new RuntimeException("IllegalArgumentExpected expected"); + } catch (IllegalArgumentException e) { + } + + try { + Set<FileVisitOption> opts = new HashSet<FileVisitOption>(1); + opts.add(null); + Files.walkFileTree(Paths.get("."), opts, Integer.MAX_VALUE, + new SimpleFileVisitor<Path>(){}); + npeExpected(); + } catch (NullPointerException e) { + } + + try { + Files.walkFileTree(Paths.get("."), EnumSet.noneOf(FileVisitOption.class), + Integer.MAX_VALUE, null); + npeExpected(); + } catch (NullPointerException e) { + } + } +} diff --git a/test/java/nio/file/Files/PrintFileTree.java b/test/java/nio/file/Files/PrintFileTree.java new file mode 100644 index 0000000000000000000000000000000000000000..dc2c49f8db105fa234582e38126ecaae9012a580 --- /dev/null +++ b/test/java/nio/file/Files/PrintFileTree.java @@ -0,0 +1,78 @@ +/* + * Copyright 2008-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. + * + * 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. + */ + +import java.nio.file.*; +import java.nio.file.attribute.*; +import java.io.IOException; +import java.util.*; + +/** + * Invokes Files.walkFileTree to traverse a file tree and prints + * each of the directories and files. The -L option causes symbolic + * links to be followed. + */ + +public class PrintFileTree { + + public static void main(String[] args) throws Exception { + boolean followLinks = false; + Path dir; + + if (args[0].equals("-L")) { + followLinks = true; + dir = Paths.get(args[1]); + } else { + dir = Paths.get(args[0]); + } + + Set<FileVisitOption> options = new HashSet<FileVisitOption>(); + if (followLinks) + options.add(FileVisitOption.FOLLOW_LINKS); + + Files.walkFileTree(dir, options, Integer.MAX_VALUE, new FileVisitor<FileRef>() { + public FileVisitResult preVisitDirectory(FileRef dir) { + System.out.println(dir); + return FileVisitResult.CONTINUE; + } + public FileVisitResult preVisitDirectoryFailed(FileRef dir, IOException exc) { + exc.printStackTrace(); + return FileVisitResult.CONTINUE; + } + public FileVisitResult visitFile(FileRef file, BasicFileAttributes attrs) { + System.out.println(file); + return FileVisitResult.CONTINUE; + } + public FileVisitResult postVisitDirectory(FileRef dir, IOException exc) { + if (exc != null) { + exc.printStackTrace(); + return FileVisitResult.TERMINATE; + } + return FileVisitResult.CONTINUE; + } + public FileVisitResult visitFileFailed(FileRef file, IOException exc) { + exc.printStackTrace(); + return FileVisitResult.TERMINATE; + } + }); + } +} diff --git a/test/java/nio/file/Files/SimpleFileTypeDetector.java b/test/java/nio/file/Files/SimpleFileTypeDetector.java new file mode 100644 index 0000000000000000000000000000000000000000..0b66706d6368cb851d3fb2626dc4d59dc7799f5e --- /dev/null +++ b/test/java/nio/file/Files/SimpleFileTypeDetector.java @@ -0,0 +1,47 @@ +/* + * Copyright 2008-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. + * + * 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. + */ + +import java.nio.file.*; +import java.nio.file.spi.FileTypeDetector; +import java.io.*; + + +public class SimpleFileTypeDetector extends FileTypeDetector { + public SimpleFileTypeDetector() { + } + + public String probeContentType(FileRef file) throws IOException { + + System.out.println("probe " + file + "..."); + + if (file instanceof Path) { + String name = ((Path)file).toString(); + if (name.endsWith(".grape")) { + return "grape/unknown"; + } + } + + // unknown + return null; + } +} diff --git a/test/java/nio/file/Files/SkipSiblings.java b/test/java/nio/file/Files/SkipSiblings.java new file mode 100644 index 0000000000000000000000000000000000000000..e8524552012e49253ac6580ea69c9a0ed9493e47 --- /dev/null +++ b/test/java/nio/file/Files/SkipSiblings.java @@ -0,0 +1,85 @@ +/* + * Copyright 2008-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. + * + * 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. + */ + +import java.nio.file.*; +import java.nio.file.attribute.*; +import java.io.IOException; +import java.util.*; + +/** + * Unit test for Files.walkFileTree to test SKIP_SIBLINGS return value. + */ + +public class SkipSiblings { + + static final Random rand = new Random(); + static final Set<Path> skipped = new HashSet<Path>(); + + // check if this path's directory has been skipped + static void check(Path path) { + if (skipped.contains(path.getParent())) + throw new RuntimeException(path + " should not have been visited"); + } + + // indicates if the siblings of this path should be skipped + static boolean skip(Path path) { + Path parent = path.getParent(); + if (parent != null && rand.nextBoolean()) { + skipped.add(parent); + return true; + } + return false; + } + + public static void main(String[] args) throws Exception { + Path dir = Paths.get(args[0]); + + Files.walkFileTree(dir, new FileVisitor<Path>() { + public FileVisitResult preVisitDirectory(Path dir) { + check(dir); + if (skip(dir)) + return FileVisitResult.SKIP_SIBLINGS; + return FileVisitResult.CONTINUE; + } + public FileVisitResult preVisitDirectoryFailed(Path dir, IOException exc) { + throw new RuntimeException(exc); + } + + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) { + check(file); + if (skip(file)) + return FileVisitResult.SKIP_SIBLINGS; + return FileVisitResult.CONTINUE; + } + public FileVisitResult postVisitDirectory(Path dir, IOException x) { + if (x != null) + throw new RuntimeException(x); + check(dir); + return FileVisitResult.CONTINUE; + } + public FileVisitResult visitFileFailed(Path file, IOException x) { + throw new RuntimeException(x); + } + }); + } +} diff --git a/test/java/nio/file/Files/TerminateWalk.java b/test/java/nio/file/Files/TerminateWalk.java new file mode 100644 index 0000000000000000000000000000000000000000..82fc8ed579fdc50fe09ba1c53eba2aa27afc12db --- /dev/null +++ b/test/java/nio/file/Files/TerminateWalk.java @@ -0,0 +1,70 @@ +/* + * Copyright 2008-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. + * + * 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. + */ + +import java.nio.file.*; +import java.nio.file.attribute.*; +import java.io.IOException; +import java.util.*; + +/** + * Unit test for Files.walkFileTree to test TERMINATE return value + */ + +public class TerminateWalk { + + static final Random rand = new Random(); + static boolean terminated; + + static FileVisitResult maybeTerminate() { + if (terminated) + throw new RuntimeException("FileVisitor invoked after termination"); + if (rand.nextInt(10) == 0) { + terminated = true; + return FileVisitResult.TERMINATE; + } else { + return FileVisitResult.CONTINUE; + } + } + + public static void main(String[] args) throws Exception { + Path dir = Paths.get(args[0]); + + Files.walkFileTree(dir, new FileVisitor<Path>() { + public FileVisitResult preVisitDirectory(Path dir) { + return maybeTerminate(); + } + public FileVisitResult preVisitDirectoryFailed(Path dir, IOException exc) { + return maybeTerminate(); + } + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) { + return maybeTerminate(); + } + public FileVisitResult postVisitDirectory(Path dir, IOException x) { + return maybeTerminate(); + } + public FileVisitResult visitFileFailed(Path file, IOException x) { + return maybeTerminate(); + } + }); + } +} diff --git a/test/java/nio/file/Files/content_type.sh b/test/java/nio/file/Files/content_type.sh new file mode 100644 index 0000000000000000000000000000000000000000..46f4626c72a7c6536e63a383b928c2f783e0856d --- /dev/null +++ b/test/java/nio/file/Files/content_type.sh @@ -0,0 +1,71 @@ +# +# Copyright 2008-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. +# +# 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. +# + +# @test +# @bug 4313887 +# @summary Unit test for probeContentType method +# @library .. +# @build ContentType SimpleFileTypeDetector +# @run shell content_type.sh + +# if TESTJAVA isn't set then we assume an interactive run. + +if [ -z "$TESTJAVA" ]; then + TESTSRC=. + TESTCLASSES=. + JAVA=java +else + JAVA="${TESTJAVA}/bin/java" +fi + +OS=`uname -s` +case "$OS" in + Windows_* ) + CLASSPATH="${TESTCLASSES};${TESTSRC}" + ;; + * ) + CLASSPATH=${TESTCLASSES}:${TESTSRC} + ;; +esac +export CLASSPATH + +failures=0 + +go() { + echo '' + $JAVA $1 $2 $3 2>&1 + if [ $? != 0 ]; then failures=`expr $failures + 1`; fi +} + +# Run the test + +go ContentType + +# +# Results +# +echo '' +if [ $failures -gt 0 ]; + then echo "$failures test(s) failed"; + else echo "All test(s) passed"; fi +exit $failures diff --git a/test/java/nio/file/Files/walk_file_tree.sh b/test/java/nio/file/Files/walk_file_tree.sh new file mode 100644 index 0000000000000000000000000000000000000000..73022d31d586e943d9733edb5b924f644805ddf4 --- /dev/null +++ b/test/java/nio/file/Files/walk_file_tree.sh @@ -0,0 +1,86 @@ +# +# Copyright 2008-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. +# +# 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. +# + +# @test +# @bug 4313887 +# @summary Unit test for walkFileTree method +# @build CreateFileTree PrintFileTree SkipSiblings TerminateWalk +# @run shell walk_file_tree.sh + +# if TESTJAVA isn't set then we assume an interactive run. + +if [ -z "$TESTJAVA" ]; then + TESTSRC=. + TESTCLASSES=. + JAVA=java +else + JAVA="${TESTJAVA}/bin/java" +fi + +OS=`uname -s` +case "$OS" in + Windows_* ) + echo "This test does not run on Windows" + exit 0 + ;; + * ) + CLASSPATH=${TESTCLASSES}:${TESTSRC} + ;; +esac +export CLASSPATH + +# create the file tree +ROOT=`$JAVA CreateFileTree` +if [ $? != 0 ]; then exit 1; fi + +failures=0 + +# print the file tree and compare output with find(1) +$JAVA PrintFileTree "$ROOT" > out1 +find "$ROOT" > out2 +diff out1 out2 +if [ $? != 0 ]; then failures=`expr $failures + 1`; fi + +# repeat test following links (use -follow instead of -L +# to allow running on older systems) +$JAVA PrintFileTree -L "$ROOT" > out1 +find "$ROOT" -follow > out2 +diff out1 out2 +if [ $? != 0 ]; then failures=`expr $failures + 1`; fi + +# test SKIP_SIBLINGS +$JAVA SkipSiblings "$ROOT" +if [ $? != 0 ]; then failures=`expr $failures + 1`; fi + +# test TERMINATE +$JAVA TerminateWalk "$ROOT" +if [ $? != 0 ]; then failures=`expr $failures + 1`; fi + +# clean-up +rm -r "$ROOT" + +echo '' +if [ $failures -gt 0 ]; + then echo "$failures test(s) failed"; + else echo "Test passed"; fi +exit $failures diff --git a/test/java/nio/file/Path/CopyAndMove.java b/test/java/nio/file/Path/CopyAndMove.java new file mode 100644 index 0000000000000000000000000000000000000000..4e4c75fd2aa4e12bd9306bf44b55dd7ab6c6ef3a --- /dev/null +++ b/test/java/nio/file/Path/CopyAndMove.java @@ -0,0 +1,983 @@ +/* + * Copyright 2008-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. + * + * 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. + */ + +/* @test + * @bug 4313887 + * @summary Unit test for java.nio.file.Path copyTo/moveTo methods + * @library .. + */ + +import java.nio.ByteBuffer; +import java.nio.file.*; +import static java.nio.file.StandardCopyOption.*; +import static java.nio.file.LinkOption.*; +import java.nio.file.attribute.*; +import java.io.*; +import java.util.*; + +public class CopyAndMove { + static final Random rand = new Random(); + static boolean heads() { return rand.nextBoolean(); } + static boolean supportsLinks; + + public static void main(String[] args) throws Exception { + Path dir1 = TestUtil.createTemporaryDirectory(); + try { + supportsLinks = TestUtil.supportsLinks(dir1); + + // Exercise copyTo + doCopyTests(dir1); + + // Exercise moveTo + // if test.dir differs to temporary file system then can test + // moving between devices + String testDir = System.getProperty("test.dir"); + Path dir2 = (testDir != null) ? Paths.get(testDir) : dir1; + doMoveTests(dir1, dir2); + + } finally { + TestUtil.removeAll(dir1); + } + } + + static void checkBasicAttributes(BasicFileAttributes attrs1, + BasicFileAttributes attrs2) + { + // check file type + assertTrue(attrs1.isRegularFile() == attrs2.isRegularFile()); + assertTrue(attrs1.isDirectory() == attrs2.isDirectory()); + assertTrue(attrs1.isSymbolicLink() == attrs2.isSymbolicLink()); + assertTrue(attrs1.isOther() == attrs2.isOther()); + + // check last modified time (assume millisecond precision) + long time1 = attrs1.resolution().toMillis(attrs1.lastModifiedTime()); + long time2 = attrs1.resolution().toMillis(attrs2.lastModifiedTime()); + assertTrue(time1 == time2); + + // check size + if (attrs1.isRegularFile()) + assertTrue(attrs1.size() == attrs2.size()); + } + + static void checkPosixAttributes(PosixFileAttributes attrs1, + PosixFileAttributes attrs2) + { + assertTrue(attrs1.permissions().equals(attrs2.permissions())); + assertTrue(attrs1.owner().equals(attrs2.owner())); + assertTrue(attrs1.group().equals(attrs2.group())); + } + + static void checkDosAttributes(DosFileAttributes attrs1, + DosFileAttributes attrs2) + { + assertTrue(attrs1.isReadOnly() == attrs2.isReadOnly()); + assertTrue(attrs1.isHidden() == attrs2.isHidden()); + assertTrue(attrs1.isArchive() == attrs2.isArchive()); + assertTrue(attrs1.isSystem() == attrs2.isSystem()); + } + + static void checkUserDefinedFileAttributes(Map<String,ByteBuffer> attrs1, + Map<String,ByteBuffer> attrs2) + { + assert attrs1.size() == attrs2.size(); + for (String name: attrs1.keySet()) { + ByteBuffer bb1 = attrs1.get(name); + ByteBuffer bb2 = attrs2.get(name); + assertTrue(bb2 != null); + assertTrue(bb1.equals(bb2)); + } + } + + static Map<String,ByteBuffer> readUserDefinedFileAttributes(Path file) + throws IOException + { + UserDefinedFileAttributeView view = file + .getFileAttributeView(UserDefinedFileAttributeView.class); + Map<String,ByteBuffer> result = new HashMap<String,ByteBuffer>(); + for (String name: view.list()) { + int size = view.size(name); + ByteBuffer bb = ByteBuffer.allocate(size); + int n = view.read(name, bb); + assertTrue(n == size); + bb.flip(); + result.put(name, bb); + } + return result; + } + + // move source to target with verification + static void moveAndVerify(Path source, Path target, CopyOption... options) + throws IOException + { + // read attributes before file is moved + BasicFileAttributes basicAttributes = null; + PosixFileAttributes posixAttributes = null; + DosFileAttributes dosAttributes = null; + Map<String,ByteBuffer> namedAttributes = null; + + // get file attributes of source file + String os = System.getProperty("os.name"); + if (os.equals("SunOS") || os.equals("Linux")) { + posixAttributes = Attributes.readPosixFileAttributes(source, NOFOLLOW_LINKS); + basicAttributes = posixAttributes; + } + if (os.startsWith("Windows")) { + dosAttributes = Attributes.readDosFileAttributes(source, NOFOLLOW_LINKS); + basicAttributes = dosAttributes; + } + if (basicAttributes == null) + basicAttributes = Attributes.readBasicFileAttributes(source, NOFOLLOW_LINKS); + + // hash file contents if regular file + int hash = (basicAttributes.isRegularFile()) ? computeHash(source) : 0; + + // record link target if symbolic link + Path linkTarget = null; + if (basicAttributes.isSymbolicLink()) + linkTarget = source.readSymbolicLink(); + + // read named attributes if available (and file is not a sym link) + if (!basicAttributes.isSymbolicLink() && + source.getFileStore().supportsFileAttributeView("xattr")) + { + namedAttributes = readUserDefinedFileAttributes(source); + } + + // move file + source.moveTo(target, options); + + // verify source does not exist + assertTrue(source.notExists()); + + // verify file contents + if (basicAttributes.isRegularFile()) { + if (computeHash(target) != hash) + throw new RuntimeException("Failed to verify move of regular file"); + } + + // verify link target + if (basicAttributes.isSymbolicLink()) { + if (!target.readSymbolicLink().equals(linkTarget)) + throw new RuntimeException("Failed to verify move of symbolic link"); + } + + // verify basic attributes + checkBasicAttributes(basicAttributes, + Attributes.readBasicFileAttributes(target, NOFOLLOW_LINKS)); + + // verify POSIX attributes + if (posixAttributes != null && !basicAttributes.isSymbolicLink()) { + checkPosixAttributes(posixAttributes, + Attributes.readPosixFileAttributes(target, NOFOLLOW_LINKS)); + } + + // verify DOS attributes + if (dosAttributes != null && !basicAttributes.isSymbolicLink()) { + checkDosAttributes(dosAttributes, + Attributes.readDosFileAttributes(target, NOFOLLOW_LINKS)); + } + + // verify named attributes + if (namedAttributes != null && + target.getFileStore().supportsFileAttributeView("xattr")) + { + checkUserDefinedFileAttributes(namedAttributes, readUserDefinedFileAttributes(target)); + } + } + + /** + * Tests all possible ways to invoke moveTo + */ + static void doMoveTests(Path dir1, Path dir2) throws IOException { + Path source, target, entry; + + boolean sameDevice = dir1.getFileStore().equals(dir2.getFileStore()); + + // -- regular file -- + + /** + * Test: move regular file, target does not exist + */ + source = createSourceFile(dir1); + target = getTargetFile(dir1); + moveAndVerify(source, target); + target.delete(); + + /** + * Test: move regular file, target exists + */ + source = createSourceFile(dir1); + target = getTargetFile(dir1).createFile(); + try { + moveAndVerify(source, target); + throw new RuntimeException("FileAlreadyExistsException expected"); + } catch (FileAlreadyExistsException x) { + } + target.delete(); + target.createDirectory(); + try { + moveAndVerify(source, target); + throw new RuntimeException("FileAlreadyExistsException expected"); + } catch (FileAlreadyExistsException x) { + } + source.delete(); + target.delete(); + + /** + * Test: move regular file, target does not exist + */ + source = createSourceFile(dir1); + target = getTargetFile(dir1); + moveAndVerify(source, target, REPLACE_EXISTING); + target.delete(); + + /** + * Test: move regular file, target exists + */ + source = createSourceFile(dir1); + target = getTargetFile(dir1).createFile(); + moveAndVerify(source, target, REPLACE_EXISTING); + target.delete(); + + /** + * Test: move regular file, target exists and is empty directory + */ + source = createSourceFile(dir1); + target = getTargetFile(dir1).createDirectory(); + moveAndVerify(source, target, REPLACE_EXISTING); + target.delete(); + + /** + * Test: move regular file, target exists and is non-empty directory + */ + source = createSourceFile(dir1); + target = getTargetFile(dir1).createDirectory(); + entry = target.resolve("foo").createFile(); + try { + moveAndVerify(source, target); + throw new RuntimeException("FileAlreadyExistsException expected"); + } catch (FileAlreadyExistsException x) { + } + entry.delete(); + source.delete(); + target.delete(); + + /** + * Test atomic move of regular file (same file store) + */ + source = createSourceFile(dir1); + target = getTargetFile(dir1); + moveAndVerify(source, target, ATOMIC_MOVE); + target.delete(); + + /** + * Test atomic move of regular file (different file store) + */ + if (!sameDevice) { + source = createSourceFile(dir1); + target = getTargetFile(dir2); + try { + moveAndVerify(source, target, ATOMIC_MOVE); + throw new RuntimeException("AtomicMoveNotSupportedException expected"); + } catch (AtomicMoveNotSupportedException x) { + } + source.delete(); + } + + // -- directories -- + + /* + * Test: move empty directory, target does not exist + */ + source = createSourceDirectory(dir1); + target = getTargetFile(dir1); + moveAndVerify(source, target); + target.delete(); + + /** + * Test: move empty directory, target exists + */ + source = createSourceDirectory(dir1); + target = getTargetFile(dir1).createFile(); + try { + moveAndVerify(source, target); + throw new RuntimeException("FileAlreadyExistsException expected"); + } catch (FileAlreadyExistsException x) { + } + target.delete(); + target.createDirectory(); + try { + moveAndVerify(source, target); + throw new RuntimeException("FileAlreadyExistsException expected"); + } catch (FileAlreadyExistsException x) { + } + source.delete(); + target.delete(); + + /** + * Test: move empty directory, target does not exist + */ + source = createSourceDirectory(dir1); + target = getTargetFile(dir1); + moveAndVerify(source, target, REPLACE_EXISTING); + target.delete(); + + /** + * Test: move empty directory, target exists + */ + source = createSourceDirectory(dir1); + target = getTargetFile(dir1).createFile(); + moveAndVerify(source, target, REPLACE_EXISTING); + target.delete(); + + /** + * Test: move empty, target exists and is empty directory + */ + source = createSourceDirectory(dir1); + target = getTargetFile(dir1).createDirectory(); + moveAndVerify(source, target, REPLACE_EXISTING); + target.delete(); + + /** + * Test: move empty directory, target exists and is non-empty directory + */ + source = createSourceDirectory(dir1); + target = getTargetFile(dir1).createDirectory(); + entry = target.resolve("foo").createFile(); + try { + moveAndVerify(source, target, REPLACE_EXISTING); + throw new RuntimeException("FileAlreadyExistsException expected"); + } catch (FileAlreadyExistsException x) { + } + entry.delete(); + source.delete(); + target.delete(); + + /** + * Test: move non-empty directory (same file system) + */ + source = createSourceDirectory(dir1); + source.resolve("foo").createFile(); + target = getTargetFile(dir1); + moveAndVerify(source, target); + target.resolve("foo").delete(); + target.delete(); + + /** + * Test: move non-empty directory (different file store) + */ + if (!sameDevice) { + source = createSourceDirectory(dir1); + source.resolve("foo").createFile(); + target = getTargetFile(dir2); + try { + moveAndVerify(source, target); + throw new RuntimeException("IOException expected"); + } catch (IOException x) { + } + source.resolve("foo").delete(); + source.delete(); + } + + /** + * Test atomic move of directory (same file store) + */ + source = createSourceDirectory(dir1); + source.resolve("foo").createFile(); + target = getTargetFile(dir1); + moveAndVerify(source, target, ATOMIC_MOVE); + target.resolve("foo").delete(); + target.delete(); + + // -- symbolic links -- + + /** + * Test: Move symbolic link to file, target does not exist + */ + if (supportsLinks) { + Path tmp = createSourceFile(dir1); + source = dir1.resolve("link").createSymbolicLink(tmp); + target = getTargetFile(dir1); + moveAndVerify(source, target); + target.delete(); + tmp.delete(); + } + + /** + * Test: Move symbolic link to directory, target does not exist + */ + if (supportsLinks) { + source = dir1.resolve("link").createSymbolicLink(dir2); + target = getTargetFile(dir1); + moveAndVerify(source, target); + target.delete(); + } + + /** + * Test: Move broken symbolic link, target does not exists + */ + if (supportsLinks) { + Path tmp = Paths.get("doesnotexist"); + source = dir1.resolve("link").createSymbolicLink(tmp); + target = getTargetFile(dir1); + moveAndVerify(source, target); + target.delete(); + } + + /** + * Test: Move symbolic link, target exists + */ + if (supportsLinks) { + source = dir1.resolve("link").createSymbolicLink(dir2); + target = getTargetFile(dir1).createFile(); + try { + moveAndVerify(source, target); + throw new RuntimeException("FileAlreadyExistsException expected"); + } catch (FileAlreadyExistsException x) { + } + source.delete(); + target.delete(); + } + + /** + * Test: Move regular file, target exists + */ + if (supportsLinks) { + source = dir1.resolve("link").createSymbolicLink(dir2); + target = getTargetFile(dir1).createFile(); + moveAndVerify(source, target, REPLACE_EXISTING); + target.delete(); + } + + /** + * Test: move symbolic link, target exists and is empty directory + */ + if (supportsLinks) { + source = dir1.resolve("link").createSymbolicLink(dir2); + target = getTargetFile(dir1).createDirectory(); + moveAndVerify(source, target, REPLACE_EXISTING); + target.delete(); + } + + /** + * Test: symbolic link, target exists and is non-empty directory + */ + if (supportsLinks) { + source = dir1.resolve("link").createSymbolicLink(dir2); + target = getTargetFile(dir1).createDirectory(); + entry = target.resolve("foo").createFile(); + try { + moveAndVerify(source, target); + throw new RuntimeException("FileAlreadyExistsException expected"); + } catch (FileAlreadyExistsException x) { + } + entry.delete(); + source.delete(); + target.delete(); + } + + /** + * Test atomic move of symbolic link (same file store) + */ + if (supportsLinks) { + source = dir1.resolve("link").createSymbolicLink(dir1); + target = getTargetFile(dir1).createFile(); + moveAndVerify(source, target, REPLACE_EXISTING); + target.delete(); + } + + // -- misc. tests -- + + /** + * Test nulls + */ + source = createSourceFile(dir1); + target = getTargetFile(dir1); + try { + source.moveTo(null); + throw new RuntimeException("NullPointerException expected"); + } catch (NullPointerException x) { } + try { + source.moveTo(target, (CopyOption[])null); + throw new RuntimeException("NullPointerException expected"); + } catch (NullPointerException x) { } + try { + CopyOption[] opts = { REPLACE_EXISTING, null }; + source.moveTo(target, opts); + throw new RuntimeException("NullPointerException expected"); + } catch (NullPointerException x) { } + source.delete(); + + /** + * Test UOE + */ + source = createSourceFile(dir1); + target = getTargetFile(dir1); + try { + source.moveTo(target, new CopyOption() { }); + } catch (UnsupportedOperationException x) { } + try { + source.moveTo(target, REPLACE_EXISTING, new CopyOption() { }); + } catch (UnsupportedOperationException x) { } + source.delete(); + } + + // copy source to target with verification + static void copyAndVerify(Path source, Path target, CopyOption... options) + throws IOException + { + source.copyTo(target, options); + + // get attributes of source and target file to verify copy + boolean followLinks = true; + LinkOption[] linkOptions = new LinkOption[0]; + boolean copyAttributes = false; + for (CopyOption opt : options) { + if (opt == NOFOLLOW_LINKS) { + followLinks = false; + linkOptions = new LinkOption[] { NOFOLLOW_LINKS }; + } + if (opt == COPY_ATTRIBUTES) + copyAttributes = true; + } + BasicFileAttributes basicAttributes = Attributes + .readBasicFileAttributes(source, linkOptions); + + // check hash if regular file + if (basicAttributes.isRegularFile()) + assertTrue(computeHash(source) == computeHash(target)); + + // check link target if symbolic link + if (basicAttributes.isSymbolicLink()) + assert( source.readSymbolicLink().equals(target.readSymbolicLink())); + + // check that attributes are copied + if (copyAttributes && followLinks) { + checkBasicAttributes(basicAttributes, + Attributes.readBasicFileAttributes(source, linkOptions)); + + // check POSIX attributes are copied + String os = System.getProperty("os.name"); + if (os.equals("SunOS") || os.equals("Linux")) { + checkPosixAttributes( + Attributes.readPosixFileAttributes(source, linkOptions), + Attributes.readPosixFileAttributes(target, linkOptions)); + } + + // check DOS attributes are copied + if (os.startsWith("Windows")) { + checkDosAttributes( + Attributes.readDosFileAttributes(source, linkOptions), + Attributes.readDosFileAttributes(target, linkOptions)); + } + + // check named attributes are copied + if (followLinks && + source.getFileStore().supportsFileAttributeView("xattr") && + target.getFileStore().supportsFileAttributeView("xattr")) + { + checkUserDefinedFileAttributes(readUserDefinedFileAttributes(source), + readUserDefinedFileAttributes(target)); + } + } + } + + /** + * Tests all possible ways to invoke copyTo + */ + static void doCopyTests(Path dir) throws IOException { + Path source, target, link, entry; + + // -- regular file -- + + /** + * Test: move regular file, target does not exist + */ + source = createSourceFile(dir); + target = getTargetFile(dir); + copyAndVerify(source, target); + source.delete(); + target.delete(); + + /** + * Test: copy regular file, target exists + */ + source = createSourceFile(dir); + target = getTargetFile(dir).createFile(); + try { + copyAndVerify(source, target); + throw new RuntimeException("FileAlreadyExistsException expected"); + } catch (FileAlreadyExistsException x) { + } + target.delete(); + target.createDirectory(); + try { + copyAndVerify(source, target); + throw new RuntimeException("FileAlreadyExistsException expected"); + } catch (FileAlreadyExistsException x) { + } + source.delete(); + target.delete(); + + /** + * Test: copy regular file, target does not exist + */ + source = createSourceFile(dir); + target = getTargetFile(dir); + copyAndVerify(source, target, REPLACE_EXISTING); + source.delete(); + target.delete(); + + /** + * Test: copy regular file, target exists + */ + source = createSourceFile(dir); + target = getTargetFile(dir).createFile(); + copyAndVerify(source, target, REPLACE_EXISTING); + source.delete(); + target.delete(); + + /** + * Test: copy regular file, target exists and is empty directory + */ + source = createSourceFile(dir); + target = getTargetFile(dir).createDirectory(); + copyAndVerify(source, target, REPLACE_EXISTING); + source.delete(); + target.delete(); + + /** + * Test: copy regular file, target exists and is non-empty directory + */ + source = createSourceFile(dir); + target = getTargetFile(dir).createDirectory(); + entry = target.resolve("foo").createFile(); + try { + copyAndVerify(source, target); + throw new RuntimeException("FileAlreadyExistsException expected"); + } catch (FileAlreadyExistsException x) { + } + entry.delete(); + source.delete(); + target.delete(); + + /** + * Test: copy regular file + attributes + */ + source = createSourceFile(dir); + target = getTargetFile(dir); + copyAndVerify(source, target, COPY_ATTRIBUTES); + source.delete(); + target.delete(); + + + // -- directory -- + + /* + * Test: copy directory, target does not exist + */ + source = createSourceDirectory(dir); + target = getTargetFile(dir); + copyAndVerify(source, target); + source.delete(); + target.delete(); + + /** + * Test: copy directory, target exists + */ + source = createSourceDirectory(dir); + target = getTargetFile(dir).createFile(); + try { + copyAndVerify(source, target); + throw new RuntimeException("FileAlreadyExistsException expected"); + } catch (FileAlreadyExistsException x) { + } + target.delete(); + target.createDirectory(); + try { + copyAndVerify(source, target); + throw new RuntimeException("FileAlreadyExistsException expected"); + } catch (FileAlreadyExistsException x) { + } + source.delete(); + target.delete(); + + /** + * Test: copy directory, target does not exist + */ + source = createSourceDirectory(dir); + target = getTargetFile(dir); + copyAndVerify(source, target, REPLACE_EXISTING); + source.delete(); + target.delete(); + + /** + * Test: copy directory, target exists + */ + source = createSourceDirectory(dir); + target = getTargetFile(dir).createFile(); + copyAndVerify(source, target, REPLACE_EXISTING); + source.delete(); + target.delete(); + + /** + * Test: copy directory, target exists and is empty directory + */ + source = createSourceDirectory(dir); + target = getTargetFile(dir).createDirectory(); + copyAndVerify(source, target, REPLACE_EXISTING); + source.delete(); + target.delete(); + + /** + * Test: copy directory, target exists and is non-empty directory + */ + source = createSourceDirectory(dir); + target = getTargetFile(dir).createDirectory(); + entry = target.resolve("foo").createFile(); + try { + copyAndVerify(source, target, REPLACE_EXISTING); + throw new RuntimeException("FileAlreadyExistsException expected"); + } catch (FileAlreadyExistsException x) { + } + entry.delete(); + source.delete(); + target.delete(); + + /* + * Test: copy directory + attributes + */ + source = createSourceDirectory(dir); + target = getTargetFile(dir); + copyAndVerify(source, target, COPY_ATTRIBUTES); + source.delete(); + target.delete(); + + // -- symbolic links -- + + /** + * Test: Follow link + */ + if (supportsLinks) { + source = createSourceFile(dir); + link = dir.resolve("link").createSymbolicLink(source); + target = getTargetFile(dir); + copyAndVerify(link, target); + link.delete(); + source.delete(); + } + + /** + * Test: Copy link (to file) + */ + if (supportsLinks) { + source = createSourceFile(dir); + link = dir.resolve("link").createSymbolicLink(source); + target = getTargetFile(dir); + copyAndVerify(link, target, NOFOLLOW_LINKS); + link.delete(); + source.delete(); + } + + /** + * Test: Copy link (to directory) + */ + if (supportsLinks) { + source = dir.resolve("mydir").createDirectory(); + link = dir.resolve("link").createSymbolicLink(source); + target = getTargetFile(dir); + copyAndVerify(link, target, NOFOLLOW_LINKS); + link.delete(); + source.delete(); + } + + /** + * Test: Copy broken link + */ + if (supportsLinks) { + assertTrue(source.notExists()); + link = dir.resolve("link").createSymbolicLink(source); + target = getTargetFile(dir); + copyAndVerify(link, target, NOFOLLOW_LINKS); + link.delete(); + } + + /** + * Test: Copy link to UNC (Windows only) + */ + if (supportsLinks && + System.getProperty("os.name").startsWith("Windows")) + { + Path unc = Paths.get("\\\\rialto\\share\\file"); + link = dir.resolve("link").createSymbolicLink(unc); + target = getTargetFile(dir); + copyAndVerify(link, target, NOFOLLOW_LINKS); + link.delete(); + } + + // -- misc. tests -- + + /** + * Test nulls + */ + source = createSourceFile(dir); + target = getTargetFile(dir); + try { + source.copyTo(null); + throw new RuntimeException("NullPointerException expected"); + } catch (NullPointerException x) { } + try { + source.copyTo(target, (CopyOption[])null); + throw new RuntimeException("NullPointerException expected"); + } catch (NullPointerException x) { } + try { + CopyOption[] opts = { REPLACE_EXISTING, null }; + source.copyTo(target, opts); + throw new RuntimeException("NullPointerException expected"); + } catch (NullPointerException x) { } + source.delete(); + + /** + * Test UOE + */ + source = createSourceFile(dir); + target = getTargetFile(dir); + try { + source.copyTo(target, new CopyOption() { }); + } catch (UnsupportedOperationException x) { } + try { + source.copyTo(target, REPLACE_EXISTING, new CopyOption() { }); + } catch (UnsupportedOperationException x) { } + source.delete(); + } + + + static void assertTrue(boolean value) { + if (!value) + throw new RuntimeException("Assertion failed"); + } + + // computes simple hash of the given file + static int computeHash(Path file) throws IOException { + int h = 0; + + InputStream in = file.newInputStream(); + try { + byte[] buf = new byte[1024]; + int n; + do { + n = in.read(buf); + for (int i=0; i<n; i++) { + h = 31*h + (buf[i] & 0xff); + } + } while (n > 0); + } finally { + in.close(); + } + return h; + } + + // create file of random size in given directory + static Path createSourceFile(Path dir) throws IOException { + String name = "source" + Integer.toString(rand.nextInt()); + Path file = dir.resolve(name).createFile(); + byte[] bytes = new byte[rand.nextInt(128*1024)]; + rand.nextBytes(bytes); + OutputStream out = file.newOutputStream(); + try { + out.write(bytes); + } finally { + out.close(); + } + randomizeAttributes(file); + return file; + } + + // create directory in the given directory + static Path createSourceDirectory(Path dir) throws IOException { + String name = "sourcedir" + Integer.toString(rand.nextInt()); + Path subdir = dir.resolve(name).createDirectory(); + randomizeAttributes(subdir); + return subdir; + } + + // "randomize" the file attributes of the given file. + static void randomizeAttributes(Path file) throws IOException { + String os = System.getProperty("os.name"); + boolean isWindows = os.startsWith("Windows"); + boolean isUnix = os.equals("SunOS") || os.equals("Linux"); + boolean isDirectory = Attributes.readBasicFileAttributes(file, NOFOLLOW_LINKS) + .isDirectory(); + + if (isUnix) { + Set<PosixFilePermission> perms = Attributes + .readPosixFileAttributes(file, NOFOLLOW_LINKS).permissions(); + PosixFilePermission[] toChange = { + PosixFilePermission.GROUP_READ, + PosixFilePermission.GROUP_WRITE, + PosixFilePermission.GROUP_EXECUTE, + PosixFilePermission.OTHERS_READ, + PosixFilePermission.OTHERS_WRITE, + PosixFilePermission.OTHERS_EXECUTE + }; + for (PosixFilePermission perm: toChange) { + if (heads()) { + perms.add(perm); + } else { + perms.remove(perm); + } + } + Attributes.setPosixFilePermissions(file, perms); + } + + if (isWindows) { + DosFileAttributeView view = file + .getFileAttributeView(DosFileAttributeView.class, NOFOLLOW_LINKS); + // only set or unset the hidden attribute + view.setHidden(heads()); + } + + boolean addUserDefinedFileAttributes = heads() && + file.getFileStore().supportsFileAttributeView("xattr"); + + // remove this when copying a direcory copies its named streams + if (isWindows && isDirectory) addUserDefinedFileAttributes = false; + + if (addUserDefinedFileAttributes) { + UserDefinedFileAttributeView view = file + .getFileAttributeView(UserDefinedFileAttributeView.class); + int n = rand.nextInt(16); + while (n > 0) { + byte[] value = new byte[1 + rand.nextInt(100)]; + view.write("user." + Integer.toString(n), ByteBuffer.wrap(value)); + n--; + } + } + } + + // create name for file in given directory + static Path getTargetFile(Path dir) throws IOException { + String name = "target" + Integer.toString(rand.nextInt()); + return dir.resolve(name); + } + } diff --git a/test/java/nio/file/Path/DeleteOnClose.java b/test/java/nio/file/Path/DeleteOnClose.java new file mode 100644 index 0000000000000000000000000000000000000000..8bc0e852c3e6f73616c5fcf26504da0876abe970 --- /dev/null +++ b/test/java/nio/file/Path/DeleteOnClose.java @@ -0,0 +1,77 @@ +/* + * Copyright 2008-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. + * + * 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. + */ + +import java.nio.file.*; +import static java.nio.file.StandardOpenOption.*; +import java.io.*; +import java.util.*; + +public class DeleteOnClose { + + public static void main(String[] args) throws IOException { + // open file but do not close it. Its existance will be checked by + // the calling script. + Paths.get(args[0]).newByteChannel(READ, WRITE, DELETE_ON_CLOSE); + + // check temporary file has been deleted after closing it + Path file = File.createTempFile("blah", "tmp").toPath(); + file.newByteChannel(READ, WRITE, DELETE_ON_CLOSE).close(); + if (file.exists()) + throw new RuntimeException("Temporary file was not deleted"); + + Path dir = TestUtil.createTemporaryDirectory(); + try { + // check that DELETE_ON_CLOSE fails when file is a sym link + if (TestUtil.supportsLinks(dir)) { + file = dir.resolve("foo").createFile(); + Path link = dir.resolve("link").createSymbolicLink(file); + try { + link.newByteChannel(READ, WRITE, DELETE_ON_CLOSE); + throw new RuntimeException("IOException expected"); + } catch (IOException ignore) { } + } + + // check that DELETE_ON_CLOSE works with files created via open + // directories + DirectoryStream stream = dir.newDirectoryStream(); + try { + if (stream instanceof SecureDirectoryStream) { + SecureDirectoryStream secure = (SecureDirectoryStream)stream; + file = Paths.get("foo"); + + Set<OpenOption> opts = new HashSet<OpenOption>(); + opts.add(WRITE); + opts.add(DELETE_ON_CLOSE); + secure.newByteChannel(file, opts).close(); + + if (dir.resolve(file).exists()) + throw new RuntimeException("File not deleted"); + } + } finally { + stream.close(); + } + } finally { + TestUtil.removeAll(dir); + } + } +} diff --git a/test/java/nio/file/Path/InterruptCopy.java b/test/java/nio/file/Path/InterruptCopy.java new file mode 100644 index 0000000000000000000000000000000000000000..d7962224eb183f3b272a26ceb964755313580579 --- /dev/null +++ b/test/java/nio/file/Path/InterruptCopy.java @@ -0,0 +1,119 @@ +/* + * Copyright 2008-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. + * + * 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. + */ + +/* @test + * @bug 4313887 + * @summary Unit test for Sun-specific ExtendedCopyOption.INTERRUPTIBLE option + * @library .. + * @run main/othervm -XX:-UseVMInterruptibleIO InterruptCopy + */ + +import java.nio.file.*; +import java.nio.file.attribute.Attributes; +import java.io.*; +import java.util.concurrent.*; +import com.sun.nio.file.ExtendedCopyOption; + +public class InterruptCopy { + + private static final long FILE_SIZE_TO_COPY = 512 * 1024 * 1024; + private static final int DELAY_IN_MS = 500; + + public static void main(String[] args) throws Exception { + Path dir = TestUtil.createTemporaryDirectory(); + try { + FileStore store = dir.getFileStore(); + System.out.format("Checking space (%s)\n", store); + long usableSpace = Attributes + .readFileStoreSpaceAttributes(store).usableSpace(); + if (usableSpace < 2*FILE_SIZE_TO_COPY) { + System.out.println("Insufficient disk space to run test."); + return; + } + doTest(dir); + } finally { + TestUtil.removeAll(dir); + } + } + + static void doTest(Path dir) throws Exception { + final Path source = dir.resolve("foo"); + final Path target = dir.resolve("bar"); + + // create source file (don't create it as sparse file because we + // require the copy to take a long time) + System.out.println("Creating source file..."); + byte[] buf = new byte[32*1024]; + long total = 0; + OutputStream out = source.newOutputStream(); + try { + do { + out.write(buf); + total += buf.length; + } while (total < FILE_SIZE_TO_COPY); + } finally { + out.close(); + } + System.out.println("Source file created."); + + ScheduledExecutorService pool = + Executors.newSingleThreadScheduledExecutor(); + try { + // copy source to target in main thread, interrupting it after a delay + final Thread me = Thread.currentThread(); + pool.schedule(new Runnable() { + public void run() { + me.interrupt(); + }}, DELAY_IN_MS, TimeUnit.MILLISECONDS); + System.out.println("Copying file..."); + try { + source.copyTo(target, ExtendedCopyOption.INTERRUPTIBLE); + throw new RuntimeException("Copy completed (this is not expected)"); + } catch (IOException e) { + boolean interrupted = Thread.interrupted(); + if (!interrupted) + throw new RuntimeException("Interrupt status was not set"); + System.out.println("Copy failed (this is expected)"); + } + + // copy source to target via task in thread pool, interrupting it after + // a delay using cancel(true) + Future<Void> result = pool.submit(new Callable<Void>() { + public Void call() throws IOException { + System.out.println("Copying file..."); + source.copyTo(target, ExtendedCopyOption.INTERRUPTIBLE, + StandardCopyOption.REPLACE_EXISTING); + return null; + } + }); + Thread.sleep(DELAY_IN_MS); + boolean cancelled = result.cancel(true); + if (!cancelled) + result.get(); + System.out.println("Copy cancelled."); + } finally { + pool.shutdown(); + pool.awaitTermination(Long.MAX_VALUE, TimeUnit.MILLISECONDS); + } + } +} diff --git a/test/java/nio/file/Path/Links.java b/test/java/nio/file/Path/Links.java new file mode 100644 index 0000000000000000000000000000000000000000..3b0d6daeaa85675bb2420e45db8e4d266309c8d7 --- /dev/null +++ b/test/java/nio/file/Path/Links.java @@ -0,0 +1,147 @@ +/* + * Copyright 2008-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. + * + * 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. + */ + +/* @test + * @bug 4313887 + * @summary Unit test for java.nio.file.Path createSymbolicLink, + * readSymbolicLink, and createLink methods + * @library .. + */ + +import java.nio.file.*; +import java.nio.file.attribute.*; +import java.io.*; +import java.util.*; + +public class Links { + + static final boolean isWindows = + System.getProperty("os.name").startsWith("Windows"); + + static void assertTrue(boolean okay) { + if (!okay) + throw new RuntimeException("Assertion failed"); + } + + /** + * Exercise createSymbolicLink and readLink methods + */ + static void testSymLinks(Path dir) throws IOException { + Path link = dir.resolve("link"); + + // Check if sym links are supported + try { + link.createSymbolicLink(Paths.get("foo")); + link.delete(); + } catch (UnsupportedOperationException x) { + // sym links not supported + return; + } catch (IOException x) { + // probably insufficient privileges to create sym links (Windows) + return; + } + + // Test links to various targets + String[] windowsTargets = + { "foo", "C:\\foo", "\\foo", "\\\\server\\share\\foo" }; + String[] otherTargets = { "relative", "/absolute" }; + + String[] targets = (isWindows) ? windowsTargets : otherTargets; + for (String s: targets) { + Path target = Paths.get(s); + link.createSymbolicLink(target); + try { + assertTrue(link.readSymbolicLink().equals(target)); + } finally { + link.delete(); + } + } + } + + /** + * Exercise createLink method + */ + static void testHardLinks(Path dir) throws IOException { + Path foo = dir.resolve("foo").createFile(); + try { + Path bar; + try { + bar = dir.resolve("bar").createLink(foo); + } catch (UnsupportedOperationException x) { + return; + } catch (IOException x) { + // probably insufficient privileges (Windows) + return; + } + try { + Object key1 = Attributes + .readBasicFileAttributes(foo).fileKey(); + Object key2 = Attributes + .readBasicFileAttributes(bar).fileKey(); + assertTrue((key1 == null) || (key1.equals(key2))); + +// Testing of linkCount disabled until linkCount method removed frmo +// BasicFileAttributes +/* + assertTrue(Attributes + .readBasicFileAttributes(foo).linkCount() >= 2); + assertTrue(Attributes + .readBasicFileAttributes(bar).linkCount() >= 2); +*/ + + } finally { + bar.delete(); + } + + + } finally { + foo.delete(); + } + } + + public static void main(String[] args) throws IOException { + Path dir = TestUtil.createTemporaryDirectory(); + try { + testSymLinks(dir); + testHardLinks(dir); + + // repeat tests on Windows with long path + if (isWindows) { + Path dirWithLongPath = null; + try { + dirWithLongPath = TestUtil.createDirectoryWithLongPath(dir); + } catch (IOException x) { + System.out.println("Unable to create long path: " + x); + } + if (dirWithLongPath != null) { + System.out.println(""); + System.out.println("** REPEAT TESTS WITH LONG PATH **"); + testSymLinks(dirWithLongPath); + testHardLinks(dirWithLongPath); + } + } + } finally { + TestUtil.removeAll(dir); + } + } +} diff --git a/test/java/nio/file/Path/Misc.java b/test/java/nio/file/Path/Misc.java new file mode 100644 index 0000000000000000000000000000000000000000..ba6640f7f34eb7ff70e2fbdaa6dabefd6ad4cb26 --- /dev/null +++ b/test/java/nio/file/Path/Misc.java @@ -0,0 +1,389 @@ +/* + * Copyright 2008-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. + * + * 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. + */ + +/* @test + * @bug 4313887 + * @summary Unit test for java.nio.file.Path for miscellenous methods not + * covered by other tests + * @library .. + */ + +import java.nio.file.*; +import static java.nio.file.LinkOption.*; +import java.nio.file.attribute.*; +import java.io.*; +import java.util.*; + +public class Misc { + static final boolean isWindows = + System.getProperty("os.name").startsWith("Windows"); + static boolean supportsLinks; + + public static void main(String[] args) throws IOException { + Path dir = TestUtil.createTemporaryDirectory(); + try { + supportsLinks = TestUtil.supportsLinks(dir); + + // equals and hashCode methods + equalsAndHashCode(); + + // checkAccess method + checkAccessTests(dir); + + // getFileAttributeView methods + getFileAttributeViewTests(dir); + + // toRealPath method + toRealPathTests(dir); + + // isSameFile method + isSameFileTests(dir); + + // isHidden method + isHiddenTests(dir); + + } finally { + TestUtil.removeAll(dir); + } + } + + /** + * Exercise equals and hashCode methods + */ + static void equalsAndHashCode() { + + Path thisFile = Paths.get("this"); + Path thatFile = Paths.get("that"); + + assertTrue(thisFile.equals(thisFile)); + assertTrue(!thisFile.equals(thatFile)); + + assertTrue(!thisFile.equals(null)); + assertTrue(!thisFile.equals(new Object())); + + Path likeThis = Paths.get("This"); + if (isWindows) { + // case insensitive + assertTrue(thisFile.equals(likeThis)); + assertTrue(thisFile.hashCode() == likeThis.hashCode()); + } else { + // case senstive + assertTrue(!thisFile.equals(likeThis)); + } + } + + /** + * Exercise checkAccess method + */ + static void checkAccessTests(Path dir) throws IOException { + final Path file = dir.resolve("foo").createFile(); + + /** + * Test: This directory should readable and writable + */ + dir.checkAccess(); + dir.checkAccess(AccessMode.READ); + dir.checkAccess(AccessMode.WRITE); + dir.checkAccess(AccessMode.READ, AccessMode.WRITE); + + /** + * Test: File does not exist + */ + Path doesNotExist = dir.resolve("thisDoesNotExists"); + try { + doesNotExist.checkAccess(); + throw new RuntimeException("NoSuchFileException expected"); + } catch (NoSuchFileException x) { + } + try { + doesNotExist.checkAccess(AccessMode.READ); + throw new RuntimeException("NoSuchFileException expected"); + } catch (NoSuchFileException x) { + } + try { + doesNotExist.checkAccess(AccessMode.WRITE); + throw new RuntimeException("NoSuchFileException expected"); + } catch (NoSuchFileException x) { + } + try { + doesNotExist.checkAccess(AccessMode.EXECUTE); + throw new RuntimeException("NoSuchFileException expected"); + } catch (NoSuchFileException x) { + } + + /** + * Test: Edit ACL to deny WRITE and EXECUTE + */ + AclFileAttributeView view = file + .getFileAttributeView(AclFileAttributeView.class); + if (view != null && + file.getFileStore().supportsFileAttributeView("acl")) + { + UserPrincipal owner = view.getOwner(); + List<AclEntry> acl = view.getAcl(); + + // Insert entry to deny WRITE and EXECUTE + AclEntry entry = AclEntry.newBuilder() + .setType(AclEntryType.DENY) + .setPrincipal(owner) + .setPermissions(AclEntryPermission.WRITE_DATA, + AclEntryPermission.EXECUTE) + .build(); + acl.add(0, entry); + view.setAcl(acl); + + try { + file.checkAccess(AccessMode.WRITE); + throw new RuntimeException("AccessDeniedException expected"); + } catch (AccessDeniedException x) { + } + + try { + file.checkAccess(AccessMode.EXECUTE); + throw new RuntimeException("AccessDeniedException expected"); + } catch (AccessDeniedException x) { + } + + + // Restore ACL + acl.remove(0); + view.setAcl(acl); + } + + /** + * Test: Windows DOS read-only attribute + */ + if (isWindows) { + DosFileAttributeView dview = + file.getFileAttributeView(DosFileAttributeView.class); + dview.setReadOnly(true); + try { + file.checkAccess(AccessMode.WRITE); + throw new RuntimeException("AccessDeniedException expected"); + } catch (AccessDeniedException x) { + } + dview.setReadOnly(false); + + // Read-only attribute does not make direcory read-only + dview = dir.getFileAttributeView(DosFileAttributeView.class); + boolean save = dview.readAttributes().isReadOnly(); + dview.setReadOnly(true); + dir.checkAccess(AccessMode.WRITE); + dview.setReadOnly(save); + } + + /** + * Test: null + */ + try { + file.checkAccess((AccessMode)null); + throw new RuntimeException("NullPointerException expected"); + } catch (NullPointerException ignore) { } + + // clean-up + file.delete(); + } + + /** + * Exercise getFileAttributeFile methods + */ + static void getFileAttributeViewTests(Path dir) { + assertTrue(dir.getFileAttributeView(BasicFileAttributeView.class) + instanceof BasicFileAttributeView); + assertTrue(dir.getFileAttributeView(BasicFileAttributeView.class, NOFOLLOW_LINKS) + instanceof BasicFileAttributeView); + assertTrue(dir.getFileAttributeView("basic") + instanceof BasicFileAttributeView); + assertTrue(dir.getFileAttributeView("basic", NOFOLLOW_LINKS) + instanceof BasicFileAttributeView); + assertTrue(dir.getFileAttributeView(BogusFileAttributeView.class) == null); + assertTrue(dir.getFileAttributeView("bogus") == null); + try { + dir.getFileAttributeView((Class<FileAttributeView>)null); + } catch (NullPointerException ignore) { } + try { + dir.getFileAttributeView(BasicFileAttributeView.class, (LinkOption[])null); + } catch (NullPointerException ignore) { } + try { + dir.getFileAttributeView(BasicFileAttributeView.class, (LinkOption)null); + } catch (NullPointerException ignore) { } + try { + dir.getFileAttributeView((String)null); + } catch (NullPointerException ignore) { } + try { + dir.getFileAttributeView("basic", (LinkOption[])null); + } catch (NullPointerException ignore) { } + try { + dir.getFileAttributeView("basic", (LinkOption)null); + } catch (NullPointerException ignore) { } + + } + interface BogusFileAttributeView extends FileAttributeView { } + + /** + * Exercise toRealPath method + */ + static void toRealPathTests(Path dir) throws IOException { + final Path file = dir.resolve("foo").createFile(); + final Path link = dir.resolve("link"); + + /** + * Test: toRealPath(true) will access same file as toRealPath(false) + */ + assertTrue(file.toRealPath(true).isSameFile(file.toRealPath(false))); + + /** + * Test: toRealPath(true) should resolve links + */ + if (supportsLinks) { + link.createSymbolicLink(file.toAbsolutePath()); + assertTrue(link.toRealPath(true).equals(file.toRealPath(true))); + link.delete(); + } + + + /** + * Test: toRealPath(false) should not resolve links + */ + if (supportsLinks) { + link.createSymbolicLink(file.toAbsolutePath()); + assertTrue(link.toRealPath(false).getName().equals(link.getName())); + link.delete(); + } + + /** + * Test: toRealPath should eliminate "." + */ + assertTrue(dir.resolve(".").toRealPath(true).equals(dir.toRealPath(true))); + assertTrue(dir.resolve(".").toRealPath(false).equals(dir.toRealPath(false))); + + /** + * Test: toRealPath should eliminate ".." when it doesn't follow a + * symbolic link + */ + Path subdir = dir.resolve("subdir").createDirectory(); + assertTrue(subdir.resolve("..").toRealPath(true).equals(dir.toRealPath(true))); + assertTrue(subdir.resolve("..").toRealPath(false).equals(dir.toRealPath(false))); + subdir.delete(); + + // clean-up + file.delete(); + } + + /** + * Exercise isSameFile method + */ + static void isSameFileTests(Path dir) throws IOException { + Path thisFile = dir.resolve("thisFile"); + Path thatFile = dir.resolve("thatFile"); + + /** + * Test: isSameFile for self and null + */ + assertTrue(thisFile.isSameFile(thisFile)); + assertTrue(!thisFile.isSameFile(null)); + + /** + * Test: Neither files exist + */ + try { + thisFile.isSameFile(thatFile); + throw new RuntimeException("IOException not thrown"); + } catch (IOException x) { + } + try { + thatFile.isSameFile(thisFile); + throw new RuntimeException("IOException not thrown"); + } catch (IOException x) { + } + + thisFile.createFile(); + try { + /** + * Test: One file exists + */ + try { + thisFile.isSameFile(thatFile); + throw new RuntimeException("IOException not thrown"); + } catch (IOException x) { + } + try { + thatFile.isSameFile(thisFile); + throw new RuntimeException("IOException not thrown"); + } catch (IOException x) { + } + + thatFile.createFile(); + + /** + * Test: Both file exists + */ + try { + assertTrue(!thisFile.isSameFile(thatFile)); + assertTrue(!thatFile.isSameFile(thisFile)); + } finally { + TestUtil.deleteUnchecked(thatFile); + } + + /** + * Test: Symbolic links + */ + if (supportsLinks) { + thatFile.createSymbolicLink(thisFile); + try { + assertTrue(thisFile.isSameFile(thatFile)); + assertTrue(thatFile.isSameFile(thisFile)); + } finally { + TestUtil.deleteUnchecked(thatFile); + } + } + } finally { + thisFile.delete(false); + } + } + + /** + * Exercise isHidden method + */ + static void isHiddenTests(Path dir) throws IOException { + assertTrue(!dir.isHidden()); + + Path file = dir.resolve(".foo"); + if (isWindows) { + file.createFile(); + try { + Attributes.setAttribute(file, "dos:hidden", true); + assertTrue(file.isHidden()); + } finally { + file.delete(); + } + } else { + assertTrue(file.isHidden()); + } + } + + static void assertTrue(boolean okay) { + if (!okay) + throw new RuntimeException("Assertion Failed"); + } +} diff --git a/test/java/nio/file/Path/PathOps.java b/test/java/nio/file/Path/PathOps.java new file mode 100644 index 0000000000000000000000000000000000000000..231123c7d9a442ea3c95111e14c31b95b6125293 --- /dev/null +++ b/test/java/nio/file/Path/PathOps.java @@ -0,0 +1,752 @@ +/* + * Copyright 2008-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. + * + * 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. + */ + +/* @test + * @bug 4313887 + * @summary Unit test for java.nio.file.Path path operations + */ + +import java.nio.file.*; + +public class PathOps { + + static final java.io.PrintStream out = System.out; + + private String input; + private Path path; + private Exception exc; + + private PathOps(String s) { + out.println(); + input = s; + try { + path = FileSystems.getDefault().getPath(s); + out.format("%s -> %s", s, path); + } catch (Exception x) { + exc = x; + out.format("%s -> %s", s, x); + } + out.println(); + } + + Path path() { + return path; + } + + void fail() { + throw new RuntimeException("PathOps failed"); + } + + void checkPath() { + if (path == null) { + throw new InternalError("path is null"); + } + } + + void check(Object result, String expected) { + out.format("\tExpected: %s\n", expected); + out.format("\tActual: %s\n", result); + if (result == null) { + if (expected == null) return; + } else { + // compare string representations + if (expected != null && result.toString().equals(expected.toString())) + return; + } + fail(); + } + + void check(Object result, boolean expected) { + check(result, Boolean.toString(expected)); + } + + PathOps root(String expected) { + out.println("check root"); + checkPath(); + check(path.getRoot(), expected); + return this; + } + + PathOps parent(String expected) { + out.println("check parent"); + checkPath(); + check(path.getParent(), expected); + return this; + } + + PathOps name(String expected) { + out.println("check name"); + checkPath(); + check(path.getName(), expected); + return this; + } + + PathOps element(int index, String expected) { + out.format("check element %d\n", index); + checkPath(); + check(path.getName(index), expected); + return this; + } + + PathOps subpath(int startIndex, int endIndex, String expected) { + out.format("test subpath(%d,%d)\n", startIndex, endIndex); + checkPath(); + check(path.subpath(startIndex, endIndex), expected); + return this; + } + + PathOps starts(String prefix) { + out.format("test startsWith with %s\n", prefix); + checkPath(); + Path s = FileSystems.getDefault().getPath(prefix); + check(path.startsWith(s), true); + return this; + } + + PathOps notStarts(String prefix) { + out.format("test not startsWith with %s\n", prefix); + checkPath(); + Path s = FileSystems.getDefault().getPath(prefix); + check(path.startsWith(s), false); + return this; + } + + PathOps ends(String suffix) { + out.format("test endsWith %s\n", suffix); + checkPath(); + Path s = FileSystems.getDefault().getPath(suffix); + check(path.endsWith(s), true); + return this; + } + + PathOps notEnds(String suffix) { + out.format("test not endsWith %s\n", suffix); + checkPath(); + Path s = FileSystems.getDefault().getPath(suffix); + check(path.endsWith(s), false); + return this; + } + + PathOps absolute() { + out.println("check path is absolute"); + checkPath(); + check(path.isAbsolute(), true); + return this; + } + + PathOps notAbsolute() { + out.println("check path is not absolute"); + checkPath(); + check(path.isAbsolute(), false); + return this; + } + + PathOps resolve(String other, String expected) { + out.format("test resolve %s\n", other); + checkPath(); + check(path.resolve(other), expected); + return this; + } + + PathOps relativize(String other, String expected) { + out.format("test relativize %s\n", other); + checkPath(); + Path that = FileSystems.getDefault().getPath(other); + check(path.relativize(that), expected); + return this; + } + + PathOps normalize(String expected) { + out.println("check normalized path"); + checkPath(); + check(path.normalize(), expected); + return this; + } + + PathOps string(String expected) { + out.println("check string representation"); + checkPath(); + check(path, expected); + return this; + } + + PathOps invalid() { + if (!(exc instanceof InvalidPathException)) { + out.println("InvalidPathException not thrown as expected"); + fail(); + } + return this; + } + + static PathOps test(String s) { + return new PathOps(s); + } + + // -- PathOpss -- + + static void header(String s) { + out.println(); + out.println(); + out.println("-- " + s + " --"); + } + + static void doWindowsTests() { + header("Windows specific tests"); + + // all components present + test("C:\\a\\b\\c") + .root("C:\\") + .parent("C:\\a\\b") + .name("c"); + test("C:a\\b\\c") + .root("C:") + .parent("C:a\\b") + .name("c"); + test("\\\\server\\share\\a") + .root("\\\\server\\share\\") + .parent("\\\\server\\share\\") + .name("a"); + + // root component only + test("C:\\") + .root("C:\\") + .parent(null) + .name(null); + test("C:") + .root("C:") + .parent(null) + .name(null); + test("\\\\server\\share\\") + .root("\\\\server\\share\\") + .parent(null) + .name(null); + + // no root component + test("a\\b") + .root(null) + .parent("a") + .name("b"); + + // name component only + test("foo") + .root(null) + .parent(null) + .name("foo"); + + // startsWith + test("C:\\") + .starts("C:\\") + .starts("c:\\") + .notStarts("C") + .notStarts("C:"); + test("C:") + .starts("C:") + .starts("c:") + .notStarts("C"); + test("\\") + .starts("\\"); + test("C:\\foo\\bar") + .starts("C:\\") + .starts("C:\\foo") + .starts("C:\\FOO") + .starts("C:\\foo\\bar") + .starts("C:\\Foo\\Bar") + .notStarts("C:") + .notStarts("C") + .notStarts("C:foo"); + test("\\foo\\bar") + .starts("\\") + .starts("\\foo") + .starts("\\foO") + .starts("\\foo\\bar") + .starts("\\fOo\\BaR") + .notStarts("foo") + .notStarts("foo\\bar"); + test("foo\\bar") + .starts("foo") + .starts("foo\\bar") + .notStarts("\\"); + test("\\\\server\\share") + .starts("\\\\server\\share") + .starts("\\\\server\\share\\") + .notStarts("\\"); + + // endsWith + test("C:\\") + .ends("C:\\") + .ends("c:\\") + .notEnds("\\"); + test("C:") + .ends("C:") + .ends("c:"); + test("\\") + .ends("\\"); + test("C:\\foo\\bar") + .ends("bar") + .ends("BAR") + .ends("foo\\bar") + .ends("Foo\\Bar") + .ends("C:\\foo\\bar") + .ends("c:\\foO\\baR") + .notEnds("r") + .notEnds("\\foo\\bar"); + test("\\foo\\bar") + .ends("bar") + .ends("BaR") + .ends("foo\\bar") + .ends("foO\\baR") + .ends("\\foo\\bar") + .ends("\\Foo\\Bar") + .notEnds("oo\\bar"); + test("foo\\bar") + .ends("bar") + .ends("BAR") + .ends("foo\\bar") + .ends("Foo\\Bar") + .notEnds("ar"); + test("\\\\server\\share") + .ends("\\\\server\\share") + .ends("\\\\server\\share\\") + .notEnds("shared") + .notEnds("\\"); + + // elements + test("C:\\a\\b\\c") + .element(0, "a") + .element(1, "b") + .element(2, "c"); + test("foo.bar\\gus.alice") + .element(0, "foo.bar") + .element(1, "gus.alice"); + + // subpath + test("C:\\foo") + .subpath(0, 1, "foo"); + test("C:foo") + .subpath(0, 1, "foo"); + test("foo") + .subpath(0, 1, "foo"); + test("C:\\foo\\bar\\gus") + .subpath(0, 1, "foo") + .subpath(0, 2, "foo\\bar") + .subpath(0, 3, "foo\\bar\\gus") + .subpath(1, 2, "bar") + .subpath(1, 3, "bar\\gus") + .subpath(2, 3, "gus"); + test("\\\\server\\share\\foo") + .subpath(0, 1, "foo"); + + // isAbsolute + test("foo").notAbsolute(); + test("C:").notAbsolute(); + test("C:\\").absolute(); + test("C:\\abc").absolute(); + test("\\\\server\\share\\").absolute(); + + // resolve + test("C:\\") + .resolve("foo", "C:\\foo") + .resolve("D:\\bar", "D:\\bar") + .resolve("\\\\server\\share\\bar", "\\\\server\\share\\bar") + .resolve("C:foo", "C:\\foo") + .resolve("D:foo", "D:foo"); + test("\\") + .resolve("foo", "\\foo") + .resolve("D:bar", "D:bar") + .resolve("C:\\bar", "C:\\bar") + .resolve("\\\\server\\share\\bar", "\\\\server\\share\\bar") + .resolve("\\foo", "\\foo"); + test("\\foo") + .resolve("bar", "\\foo\\bar") + .resolve("D:bar", "D:bar") + .resolve("C:\\bar", "C:\\bar") + .resolve("\\\\server\\share\\bar", "\\\\server\\share\\bar") + .resolve("\\bar", "\\bar"); + test("foo") + .resolve("bar", "foo\\bar") + .resolve("D:\\bar", "D:\\bar") + .resolve("\\\\server\\share\\bar", "\\\\server\\share\\bar") + .resolve("C:bar", "C:bar") + .resolve("D:foo", "D:foo"); + test("C:") + .resolve("foo", "C:foo"); + test("\\\\server\\share\\foo") + .resolve("bar", "\\\\server\\share\\foo\\bar") + .resolve("\\bar", "\\\\server\\share\\bar") + .resolve("D:\\bar", "D:\\bar") + .resolve("\\\\other\\share\\bar", "\\\\other\\share\\bar") + .resolve("D:bar", "D:bar"); + + // relativize + test("foo\\bar") + .relativize("foo\\bar", null) + .relativize("foo", ".."); + test("C:\\a\\b\\c") + .relativize("C:\\a", "..\\.."); + test("\\\\server\\share\\foo") + .relativize("\\\\server\\share\\bar", "..\\bar"); + + // normalize + test("C:\\") + .normalize("C:\\"); + test("C:\\.") + .normalize("C:\\"); + test("C:\\..") + .normalize("C:\\"); + test("\\\\server\\share") + .normalize("\\\\server\\share\\"); + test("\\\\server\\share\\.") + .normalize("\\\\server\\share\\"); + test("\\\\server\\share\\..") + .normalize("\\\\server\\share\\"); + test("C:") + .normalize("C:"); + test("C:.") + .normalize("C:"); + test("C:..") + .normalize("C:.."); + test("\\") + .normalize("\\"); + test("\\.") + .normalize("\\"); + test("\\..") + .normalize("\\"); + test("foo") + .normalize("foo"); + test("foo\\.") + .normalize("foo"); + test("foo\\..") + .normalize(null); + test("C:\\foo") + .normalize("C:\\foo"); + test("C:\\foo\\.") + .normalize("C:\\foo"); + test("C:\\.\\foo") + .normalize("C:\\foo"); + test("C:\\foo\\..") + .normalize("C:\\"); + test("C:\\..\\foo") + .normalize("C:\\foo"); + test("\\\\server\\share\\foo") + .normalize("\\\\server\\share\\foo"); + test("\\\\server\\share\\foo\\.") + .normalize("\\\\server\\share\\foo"); + test("\\\\server\\share\\.\\foo") + .normalize("\\\\server\\share\\foo"); + test("\\\\server\\share\\foo\\..") + .normalize("\\\\server\\share\\"); + test("\\\\server\\share\\..\\foo") + .normalize("\\\\server\\share\\foo"); + test("C:foo") + .normalize("C:foo"); + test("C:foo\\.") + .normalize("C:foo"); + test("C:.\\foo") + .normalize("C:foo"); + test("C:foo\\..") + .normalize("C:"); + test("C:..\\foo") + .normalize("C:..\\foo"); + test("\\foo") + .normalize("\\foo"); + test("\\foo\\.") + .normalize("\\foo"); + test("\\.\\foo") + .normalize("\\foo"); + test("\\foo\\..") + .normalize("\\"); + test("\\..\\foo") + .normalize("\\foo"); + test(".") + .normalize(null); + test("..") + .normalize(".."); + test("\\..\\..") + .normalize("\\"); + test("..\\..\\foo") + .normalize("..\\..\\foo"); + test("foo\\bar\\..") + .normalize("foo"); + test("foo\\bar\\.\\..") + .normalize("foo"); + test("foo\\bar\\gus\\..\\..") + .normalize("foo"); + test(".\\foo\\.\\bar\\.\\gus\\..\\.\\..") + .normalize("foo"); + + // UNC corner cases + test("\\\\server\\share\\") + .root("\\\\server\\share\\") + .parent(null) + .name(null); + test("\\\\server") + .invalid(); + test("\\\\server\\") + .invalid(); + test("\\\\server\\share") + .root("\\\\server\\share\\") + .parent(null) + .name(null); + + // invalid + test(":\\foo") + .invalid(); + test("C::") + .invalid(); + test("C:\\?") // invalid character + .invalid(); + test("C:\\*") // invalid character + .invalid(); + test("C:\\abc\u0001\\foo") + .invalid(); + test("C:\\\u0019\\foo") + .invalid(); + test("\\\\server\u0019\\share") + .invalid(); + test("\\\\server\\share\u0019") + .invalid(); + test("foo\u0000\bar") + .invalid(); + test("C:\\foo ") // trailing space + .invalid(); + test("C:\\foo \\bar") + .invalid(); + //test("C:\\foo.") // trailing dot + //.invalid(); + //test("C:\\foo...\\bar") + //.invalid(); + + // normalization at construction time (remove redundant and replace slashes) + test("C:/a/b/c") + .string("C:\\a\\b\\c") + .root("C:\\") + .parent("C:\\a\\b"); + test("C://a//b//c") + .string("C:\\a\\b\\c") + .root("C:\\") + .parent("C:\\a\\b"); + + // hashCode + header("hashCode"); + int h1 = test("C:\\foo").path().hashCode(); + int h2 = test("c:\\FOO").path().hashCode(); + if (h1 != h2) + throw new RuntimeException("PathOps failed"); + } + + static void doUnixTests() { + header("Unix specific tests"); + + // all components + test("/a/b/c") + .root("/") + .parent("/a/b") + .name("c"); + + // root component only + test("/") + .root("/") + .parent(null) + .name(null); + + // no root component + test("a/b") + .root(null) + .parent("a") + .name("b"); + + // name component only + test("foo") + .root(null) + .parent(null) + .name("foo"); + + // startsWith + test("/") + .starts("/") + .notStarts("/foo"); + test("/foo") + .starts("/") + .starts("/foo") + .notStarts("/f"); + test("/foo/bar") + .starts("/") + .starts("/foo") + .starts("/foo/bar") + .notStarts("/f") + .notStarts("foo") + .notStarts("foo/bar"); + test("foo") + .starts("foo") + .notStarts("f"); + test("foo/bar") + .starts("foo") + .starts("foo/bar") + .notStarts("f") + .notStarts("/foo") + .notStarts("/foo/bar"); + + // endsWith + test("/") + .ends("/") + .notEnds("foo") + .notEnds("/foo"); + test("/foo") + .ends("foo") + .ends("/foo") + .notEnds("/"); + test("/foo/bar") + .ends("bar") + .ends("foo/bar") + .ends("/foo/bar") + .notEnds("/bar"); + test("foo") + .ends("foo"); + test("foo/bar") + .ends("bar") + .ends("foo/bar"); + + // elements + test("a/b/c") + .element(0,"a") + .element(1,"b") + .element(2,"c"); + + // isAbsolute + test("/") + .absolute(); + test("/tmp") + .absolute(); + test("tmp") + .notAbsolute(); + + // resolve + test("/tmp") + .resolve("foo", "/tmp/foo") + .resolve("/foo", "/foo"); + test("tmp") + .resolve("foo", "tmp/foo") + .resolve("/foo", "/foo"); + + // relativize + test("/a/b/c") + .relativize("/a/b/c", null) + .relativize("/a/b/c/d/e", "d/e") + .relativize("/a/x", "../../x"); + + // normalize + test("/") + .normalize("/"); + test("foo") + .normalize("foo"); + test("/foo") + .normalize("/foo"); + test(".") + .normalize(null); + test("..") + .normalize(".."); + test("/..") + .normalize("/"); + test("/../..") + .normalize("/"); + test("foo/.") + .normalize("foo"); + test("./foo") + .normalize("foo"); + test("foo/..") + .normalize(null); + test("../foo") + .normalize("../foo"); + test("../../foo") + .normalize("../../foo"); + test("foo/bar/..") + .normalize("foo"); + test("foo/bar/gus/../..") + .normalize("foo"); + test("/foo/bar/gus/../..") + .normalize("/foo"); + + // invalid + test("foo\u0000\bar") + .invalid(); + + // normalization + test("//foo//bar") + .string("/foo/bar") + .root("/") + .parent("/foo") + .name("bar"); + } + + static void npes() { + header("NullPointerException"); + + Path path = FileSystems.getDefault().getPath("foo"); + + try { + path.resolve((String)null); + throw new RuntimeException("NullPointerException not thrown"); + } catch (NullPointerException npe) { + } + + try { + path.relativize(null); + throw new RuntimeException("NullPointerException not thrown"); + } catch (NullPointerException npe) { + } + + try { + path.compareTo(null); + throw new RuntimeException("NullPointerException not thrown"); + } catch (NullPointerException npe) { + } + + try { + path.startsWith(null); + throw new RuntimeException("NullPointerException not thrown"); + } catch (NullPointerException npe) { + } + + try { + path.endsWith(null); + throw new RuntimeException("NullPointerException not thrown"); + } catch (NullPointerException npe) { + } + + } + + public static void main(String[] args) { + // all platforms + npes(); + + // operating system specific + String osname = System.getProperty("os.name"); + if (osname.startsWith("Windows")) { + doWindowsTests(); + } + if (osname.equals("SunOS") || osname.equals("Linux")) { + doUnixTests(); + } + + } +} diff --git a/test/java/nio/file/Path/SBC.java b/test/java/nio/file/Path/SBC.java new file mode 100644 index 0000000000000000000000000000000000000000..724c8706a268c7bfd458110be633d9fee070f98c --- /dev/null +++ b/test/java/nio/file/Path/SBC.java @@ -0,0 +1,468 @@ +/* + * Copyright 2008-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. + * + * 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. + */ + +/* @test + * @bug 4313887 + * @summary Unit test for java.nio.file.Path.newByteChannel + * @library .. + */ + +import java.nio.ByteBuffer; +import java.nio.file.*; +import static java.nio.file.StandardOpenOption.*; +import static com.sun.nio.file.ExtendedOpenOption.*; +import java.nio.file.attribute.FileAttribute; +import java.nio.channels.*; +import java.io.IOException; +import java.util.*; + +public class SBC { + + static boolean supportsLinks; + + public static void main(String[] args) throws Exception { + Path dir = TestUtil.createTemporaryDirectory(); + try { + supportsLinks = TestUtil.supportsLinks(dir); + + // open options + createTests(dir); + appendTests(dir); + truncateExistingTests(dir); + noFollowLinksTests(dir); + + // SeekableByteChannel methods + sizeTruncatePositionTests(dir); + + // platform specific + if (System.getProperty("os.name").startsWith("Windows")) + dosSharingOptionTests(dir); + + // misc. tests + badCombinations(dir); + unsupportedOptions(dir); + nullTests(dir); + + } finally { + TestUtil.removeAll(dir); + } + } + + // test CREATE and CREATE_NEW options + static void createTests(Path dir) throws Exception { + Path file = dir.resolve("foo"); + + // CREATE + try { + // create file (no existing file) + file.newByteChannel(CREATE, WRITE).close(); + if (file.notExists()) + throw new RuntimeException("File not created"); + + // create file (existing file) + file.newByteChannel(CREATE, WRITE).close(); + + // create file where existing file is a sym link + if (supportsLinks) { + Path link = dir.resolve("link").createSymbolicLink(file); + try { + // file already exists + link.newByteChannel(CREATE, WRITE).close(); + + // file does not exist + file.delete(); + link.newByteChannel(CREATE, WRITE).close(); + if (file.notExists()) + throw new RuntimeException("File not created"); + + } finally { + TestUtil.deleteUnchecked(link); + } + } + + } finally { + TestUtil.deleteUnchecked(file); + } + + // CREATE_NEW + try { + // create file + file.newByteChannel(CREATE_NEW, WRITE).close(); + if (file.notExists()) + throw new RuntimeException("File not created"); + + // create should fail + try { + SeekableByteChannel sbc = + file.newByteChannel(CREATE_NEW, WRITE); + sbc.close(); + throw new RuntimeException("FileAlreadyExistsException not thrown"); + } catch (FileAlreadyExistsException x) { } + + // create should fail + if (supportsLinks) { + Path link = dir.resolve("link"); + Path target = dir.resolve("thisDoesNotExist"); + link.createSymbolicLink(target); + try { + + try { + SeekableByteChannel sbc = + file.newByteChannel(CREATE_NEW, WRITE); + sbc.close(); + throw new RuntimeException("FileAlreadyExistsException not thrown"); + } catch (FileAlreadyExistsException x) { } + + } finally { + TestUtil.deleteUnchecked(link); + } + } + + + } finally { + TestUtil.deleteUnchecked(file); + } + + // CREATE_NEW + SPARSE + try { + SeekableByteChannel sbc = file + .newByteChannel(CREATE_NEW, WRITE, SPARSE); + try { + final long hole = 2L * 1024L * 1024L * 1024L; + sbc.position(hole); + write(sbc, "hello"); + long size = sbc.size(); + if (size != (hole + 5)) + throw new RuntimeException("Unexpected size"); + } finally { + sbc.close(); + } + } finally { + TestUtil.deleteUnchecked(file); + } + } + + // test APPEND option + static void appendTests(Path dir) throws Exception { + Path file = dir.resolve("foo"); + try { + // "hello there" should be written to file + SeekableByteChannel sbc = file + .newByteChannel(CREATE_NEW, WRITE, APPEND); + try { + write(sbc, "hello "); + sbc.position(0L); + write(sbc, "there"); + } finally { + sbc.close(); + } + + // check file + Scanner s = new Scanner(file); + try { + String line = s.nextLine(); + if (!line.equals("hello there")) + throw new RuntimeException("Unexpected file contents"); + } finally { + s.close(); + } + + // check that read is not allowed + sbc = file.newByteChannel(APPEND); + try { + sbc.read(ByteBuffer.allocate(100)); + } catch (NonReadableChannelException x) { + } finally { + sbc.close(); + } + } finally { + // clean-up + TestUtil.deleteUnchecked(file); + } + } + + // test TRUNCATE_EXISTING option + static void truncateExistingTests(Path dir) throws Exception { + Path file = dir.resolve("foo"); + try { + SeekableByteChannel sbc = + file.newByteChannel(CREATE_NEW, WRITE); + try { + write(sbc, "Have a nice day!"); + } finally { + sbc.close(); + } + + // re-open with truncate option + // write short message and check + sbc = file.newByteChannel(WRITE, TRUNCATE_EXISTING); + try { + write(sbc, "Hello there!"); + } finally { + sbc.close(); + } + Scanner s = new Scanner(file); + try { + String line = s.nextLine(); + if (!line.equals("Hello there!")) + throw new RuntimeException("Unexpected file contents"); + } finally { + s.close(); + } + + // re-open with create + truncate option + // check file is of size 0L + sbc = file.newByteChannel(WRITE, CREATE, TRUNCATE_EXISTING); + try { + long size = ((FileChannel)sbc).size(); + if (size != 0L) + throw new RuntimeException("File not truncated"); + } finally { + sbc.close(); + } + + } finally { + // clean-up + TestUtil.deleteUnchecked(file); + } + + } + + // test NOFOLLOW_LINKS option + static void noFollowLinksTests(Path dir) throws Exception { + if (!supportsLinks) + return; + Path file = dir.resolve("foo").createFile(); + try { + // ln -s foo link + Path link = dir.resolve("link").createSymbolicLink(file); + + // open with NOFOLLOW_LINKS option + try { + link.newByteChannel(READ, LinkOption.NOFOLLOW_LINKS); + throw new RuntimeException(); + } catch (IOException x) { + } finally { + TestUtil.deleteUnchecked(link); + } + + } finally { + // clean-up + TestUtil.deleteUnchecked(file); + } + } + + // test size/truncate/position methods + static void sizeTruncatePositionTests(Path dir) throws Exception { + Path file = dir.resolve("foo"); + try { + SeekableByteChannel sbc = file + .newByteChannel(CREATE_NEW, READ, WRITE); + try { + if (sbc.size() != 0L) + throw new RuntimeException("Unexpected size"); + + // check size + write(sbc, "hello"); + if (sbc.size() != 5L) + throw new RuntimeException("Unexpected size"); + + // truncate (size and position should change) + sbc.truncate(4L); + if (sbc.size() != 4L) + throw new RuntimeException("Unexpected size"); + if (sbc.position() != 4L) + throw new RuntimeException("Unexpected position"); + + // truncate (position should not change) + sbc.position(2L).truncate(3L); + if (sbc.size() != 3L) + throw new RuntimeException("Unexpected size"); + if (sbc.position() != 2L) + throw new RuntimeException("Unexpected position"); + } finally { + sbc.close(); + } + } finally { + TestUtil.deleteUnchecked(file); + } + } + + // Windows specific options for the use by applications that really want + // to use legacy DOS sharing options + static void dosSharingOptionTests(Path dir) throws Exception { + Path file = dir.resolve("foo").createFile(); + try { + SeekableByteChannel ch; + + // no sharing + ch = file.newByteChannel(READ, + NOSHARE_READ, NOSHARE_WRITE, NOSHARE_DELETE); + try { + try { + file.newByteChannel(READ); + throw new RuntimeException("Sharing violation expected"); + } catch (IOException ignore) { } + try { + file.newByteChannel(WRITE); + throw new RuntimeException("Sharing violation expected"); + } catch (IOException ignore) { } + try { + file.delete(); + throw new RuntimeException("Sharing violation expected"); + } catch (IOException ignore) { } + } finally { + ch.close(); + } + + // read allowed + ch = file.newByteChannel(READ, NOSHARE_WRITE, NOSHARE_DELETE); + try { + file.newByteChannel(READ).close(); + try { + file.newByteChannel(WRITE); + throw new RuntimeException("Sharing violation expected"); + } catch (IOException ignore) { } + try { + file.delete(); + throw new RuntimeException("Sharing violation expected"); + } catch (IOException ignore) { } + } finally { + ch.close(); + } + + // write allowed + ch = file.newByteChannel(READ, NOSHARE_READ, NOSHARE_DELETE); + try { + try { + file.newByteChannel(READ); + throw new RuntimeException("Sharing violation expected"); + } catch (IOException ignore) { } + file.newByteChannel(WRITE).close(); + try { + file.delete(); + throw new RuntimeException("Sharing violation expected"); + } catch (IOException ignore) { } + } finally { + ch.close(); + } + + // delete allowed + ch = file.newByteChannel(READ, NOSHARE_READ, NOSHARE_WRITE); + try { + try { + file.newByteChannel(READ); + throw new RuntimeException("Sharing violation expected"); + } catch (IOException ignore) { } + try { + file.newByteChannel(WRITE); + throw new RuntimeException("Sharing violation expected"); + } catch (IOException ignore) { } + file.delete(); + } finally { + ch.close(); + } + + } finally { + TestUtil.deleteUnchecked(file); + } + } + + // invalid combinations of options + static void badCombinations(Path dir) throws Exception { + Path file = dir.resolve("bad"); + + try { + file.newByteChannel(READ, APPEND); + throw new RuntimeException("IllegalArgumentException expected"); + } catch (IllegalArgumentException x) { } + + try { + file.newByteChannel(WRITE, APPEND, TRUNCATE_EXISTING); + throw new RuntimeException("IllegalArgumentException expected"); + } catch (IllegalArgumentException x) { } + } + + // unsupported operations + static void unsupportedOptions(Path dir) throws Exception { + Path file = dir.resolve("bad"); + + OpenOption badOption = new OpenOption() { }; + try { + file.newByteChannel(badOption); + throw new RuntimeException("UnsupportedOperationException expected"); + } catch (UnsupportedOperationException e) { } + try { + file.newByteChannel(READ, WRITE, badOption); + throw new RuntimeException("UnsupportedOperationException expected"); + } catch (UnsupportedOperationException e) { } + } + + // null handling + static void nullTests(Path dir) throws Exception { + Path file = dir.resolve("foo"); + + try { + file.newByteChannel((OpenOption[])null); + throw new RuntimeException("NullPointerException expected"); + } catch (NullPointerException x) { } + + try { + OpenOption[] opts = { READ, null }; + file.newByteChannel(opts); + throw new RuntimeException("NullPointerException expected"); + } catch (NullPointerException x) { } + + try { + file.newByteChannel((Set<OpenOption>)null); + throw new RuntimeException("NullPointerException expected"); + } catch (NullPointerException x) { } + + try { + Set<OpenOption> opts = new HashSet<OpenOption>(); + opts.add(READ); + opts.add(null); + file.newByteChannel(opts); + throw new RuntimeException("NullPointerException expected"); + } catch (NullPointerException x) { } + + try { + EnumSet<StandardOpenOption> opts = EnumSet.of(READ); + file.newByteChannel(opts, (FileAttribute[])null); + throw new RuntimeException("NullPointerException expected"); + } catch (NullPointerException x) { } + + try { + EnumSet<StandardOpenOption> opts = EnumSet.of(READ); + FileAttribute[] attrs = { null }; + file.newByteChannel(opts, attrs); + throw new RuntimeException("NullPointerException expected"); + } catch (NullPointerException x) { } + } + + static void write(WritableByteChannel wbc, String msg) throws IOException { + ByteBuffer buf = ByteBuffer.wrap(msg.getBytes()); + while (buf.hasRemaining()) + wbc.write(buf); + } +} diff --git a/test/java/nio/file/Path/TemporaryFiles.java b/test/java/nio/file/Path/TemporaryFiles.java new file mode 100644 index 0000000000000000000000000000000000000000..6a9d28d9782d9d6716d9e1d5a76cc1595f2113c9 --- /dev/null +++ b/test/java/nio/file/Path/TemporaryFiles.java @@ -0,0 +1,76 @@ +/* + * Copyright 2008-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. + * + * 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. + */ + +import java.nio.file.*; +import static java.nio.file.StandardOpenOption.*; +import java.nio.file.attribute.*; +import java.io.File; +import java.io.IOException; +import java.io.OutputStream; +import java.util.Set; + +public class TemporaryFiles { + + static void checkFile(Path file) throws IOException { + // check file is in temporary directory + Path tmpdir = Paths.get(System.getProperty("java.io.tmpdir")); + if (!file.getParent().equals(tmpdir)) + throw new RuntimeException("Not in temporary directory"); + + // check that file can be opened for reading and writing + file.newByteChannel(READ).close(); + file.newByteChannel(WRITE).close(); + file.newByteChannel(READ,WRITE).close(); + + // check file permissions are 0600 or more secure + if (file.getFileStore().supportsFileAttributeView("posix")) { + Set<PosixFilePermission> perms = Attributes + .readPosixFileAttributes(file).permissions(); + perms.remove(PosixFilePermission.OWNER_READ); + perms.remove(PosixFilePermission.OWNER_WRITE); + if (!perms.isEmpty()) + throw new RuntimeException("Temporary file is not secure"); + } + } + + public static void main(String[] args) throws IOException { + Path file = File.createTempFile("blah", null, false).toPath(); + try { + checkFile(file); + } finally { + TestUtil.deleteUnchecked(file); + } + + // temporary file with deleteOnExit + file = File.createTempFile("blah", "tmp", true).toPath(); + checkFile(file); + // write path to temporary file to file so that calling script can + // check that it is deleted + OutputStream out = Paths.get(args[0]).newOutputStream(); + try { + out.write(file.toString().getBytes()); + } finally { + out.close(); + } + } +} diff --git a/test/java/nio/file/Path/UriImportExport.java b/test/java/nio/file/Path/UriImportExport.java new file mode 100644 index 0000000000000000000000000000000000000000..560423195ed6f3e7ed5d94a57d96bae54b54a866 --- /dev/null +++ b/test/java/nio/file/Path/UriImportExport.java @@ -0,0 +1,80 @@ +/* + * Copyright 2008-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. + * + * 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. + */ + +/* @test + * @bug 4313887 + * @summary Unit test for java.nio.file.Path + */ + +import java.nio.file.*; +import java.net.URI; +import java.net.URISyntaxException; +import java.io.PrintStream; + +public class UriImportExport { + + static final PrintStream log = System.out; + static int failures = 0; + + static void test(String fn, String expected) { + log.println(); + Path p = Paths.get(fn); + log.println(p); + URI u = p.toUri(); + log.println(" --> " + u); + if (expected != null && !(u.toString().equals(expected))) { + log.println("FAIL: Expected " + expected); + failures++; + return; + } + Path q = Paths.get(u); + log.println(" --> " + q); + if (!p.toAbsolutePath().equals(q)) { + log.println("FAIL: Expected " + p + ", got " + q); + failures++; + return; + } + } + + static void test(String fn) { + test(fn, null); + } + + public static void main(String[] args) throws Exception { + test("foo"); + test("/foo"); + test("/foo bar"); + + String osname = System.getProperty("os.name"); + if (osname.startsWith("Windows")) { + test("C:\\foo"); + test("C:foo"); + test("\\\\rialto.dublin.com\\share\\"); + test("\\\\fe80--203-baff-fe5a-749ds1.ipv6-literal.net\\share\\missing", + "file://[fe80::203:baff:fe5a:749d%1]/share/missing"); + } + + if (failures > 0) + throw new RuntimeException(failures + " test(s) failed"); + } +} diff --git a/test/java/nio/file/Path/delete_on_close.sh b/test/java/nio/file/Path/delete_on_close.sh new file mode 100644 index 0000000000000000000000000000000000000000..198e99d7201a422d99f6a73e22b5871792990d35 --- /dev/null +++ b/test/java/nio/file/Path/delete_on_close.sh @@ -0,0 +1,61 @@ +# +# Copyright 2008-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. +# +# 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. +# + +# @test +# @bug 4313887 +# @summary Unit test for DELETE_ON_CLOSE open option +# @library .. +# @build DeleteOnClose +# @run shell delete_on_close.sh + +# if TESTJAVA isn't set then we assume an interactive run. + +if [ -z "$TESTJAVA" ]; then + TESTSRC=. + TESTCLASSES=. + JAVA=java +else + JAVA="${TESTJAVA}/bin/java" +fi + +OS=`uname -s` +case "$OS" in + Windows_* ) + CLASSPATH="${TESTCLASSES};${TESTSRC}" + ;; + * ) + CLASSPATH=${TESTCLASSES}:${TESTSRC} + ;; +esac +export CLASSPATH + +TMPFILE="$$.tmp" +touch $TMPFILE +$JAVA DeleteOnClose $TMPFILE 2>&1 +if [ $? != 0 ]; then exit 1; fi +if [ -f $TMPFILE ]; then + echo "$TMPFILE was not deleted" + exit 1 +fi + +exit 0 diff --git a/test/java/nio/file/Path/temporary_files.sh b/test/java/nio/file/Path/temporary_files.sh new file mode 100644 index 0000000000000000000000000000000000000000..552dcfdab4694e518aa5cb233f07f9567a08244f --- /dev/null +++ b/test/java/nio/file/Path/temporary_files.sh @@ -0,0 +1,65 @@ +# +# Copyright 2008-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. +# +# 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. +# + +# @test +# @bug 4313887 +# @summary Unit test for File.createTempFile (to be be moved to test/java/io/File) +# @library .. +# @build TemporaryFiles +# @run shell temporary_files.sh + +# if TESTJAVA isn't set then we assume an interactive run. + +if [ -z "$TESTJAVA" ]; then + TESTSRC=. + TESTCLASSES=. + JAVA=java +else + JAVA="${TESTJAVA}/bin/java" +fi + +OS=`uname -s` +case "$OS" in + Windows_* ) + CLASSPATH="${TESTCLASSES};${TESTSRC}" + ;; + * ) + CLASSPATH=${TESTCLASSES}:${TESTSRC} + ;; +esac +export CLASSPATH + +TMPFILENAME="$$.tmp" +$JAVA TemporaryFiles $TMPFILENAME 2>&1 +if [ $? != 0 ]; then exit 1; fi +if [ ! -f $TMPFILENAME ]; then + echo "$TMPFILENAME not found" + exit 1 +fi +TMPFILE=`cat $TMPFILENAME` +if [ -f $TMPFILE ]; then + echo "$TMPFILE not deleted" + exit 1 +fi + +exit 0 diff --git a/test/java/nio/file/PathMatcher/Basic.java b/test/java/nio/file/PathMatcher/Basic.java new file mode 100644 index 0000000000000000000000000000000000000000..16efcf099d08e41f7257cf79151ae5c154a72167 --- /dev/null +++ b/test/java/nio/file/PathMatcher/Basic.java @@ -0,0 +1,174 @@ +/* + * Copyright 2008-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. + * + * 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. + */ + +/* @test + * @bug 4313887 + * @summary Unit test for java.nio.file.PathMatcher + */ + +import java.nio.file.*; +import java.util.regex.PatternSyntaxException; + +public class Basic { + static int failures; + + static void match(String name, String pattern, boolean expectedToMatch) { + System.out.format("%s -> %s", name, pattern); + Path file = Paths.get(name); + boolean matched = file.getFileSystem() + .getPathMatcher("glob:" + pattern).matches(file); + if (matched) + System.out.print(" (matched)"); + else + System.out.print(" (no match)"); + if (matched != expectedToMatch) { + System.out.println(" ==> UNEXPECTED RESULT!"); + failures++; + } else { + System.out.println(" OKAY"); + } + } + + static void assertMatch(String path, String pattern) { + match(path, pattern, true); + } + + static void assertNotMatch(String path, String pattern) { + match(path, pattern, false); + } + + static void assertBadPattern(String path, String pattern) { + System.out.format("Compile bad pattern %s\t", pattern); + try { + FileSystems.getDefault().getPathMatcher("glob:" + pattern); + System.out.println("Compiled ==> UNEXPECTED RESULT!"); + failures++; + } catch (PatternSyntaxException e) { + System.out.println("Failed to compile ==> OKAY"); + } + } + + public static void main(String[] args) { + // basic + assertMatch("foo.html", "foo.html"); + assertNotMatch("foo.html", "foo.htm"); + assertNotMatch("foo.html", "bar.html"); + + // match zero or more characters + assertMatch("foo.html", "f*"); + assertMatch("foo.html", "*.html"); + assertMatch("foo.html", "foo.html*"); + assertMatch("foo.html", "*foo.html"); + assertMatch("foo.html", "*foo.html*"); + assertNotMatch("foo.html", "*.htm"); + assertNotMatch("foo.html", "f.*"); + + // match one character + assertMatch("foo.html", "?oo.html"); + assertMatch("foo.html", "??o.html"); + assertMatch("foo.html", "???.html"); + assertMatch("foo.html", "???.htm?"); + assertNotMatch("foo.html", "foo.???"); + + // group of subpatterns + assertMatch("foo.html", "foo{.html,.class}"); + assertMatch("foo.html", "foo.{class,html}"); + assertNotMatch("foo.html", "foo{.htm,.class}"); + + // bracket expressions + assertMatch("foo.html", "[f]oo.html"); + assertMatch("foo.html", "[e-g]oo.html"); + assertMatch("foo.html", "[abcde-g]oo.html"); + assertMatch("foo.html", "[abcdefx-z]oo.html"); + assertMatch("foo.html", "[!a]oo.html"); + assertMatch("foo.html", "[!a-e]oo.html"); + assertMatch("foo-bar", "foo[-a-z]bar"); // match dash + assertMatch("foo.html", "foo[!-]html"); // match !dash + + // groups of subpattern with bracket expressions + assertMatch("foo.html", "[f]oo.{[h]tml,class}"); + assertMatch("foo.html", "foo.{[a-z]tml,class}"); + assertMatch("foo.html", "foo.{[!a-e]tml,.class}"); + + // assume special characters are allowed in file names + assertMatch("{foo}.html", "\\{foo*"); + assertMatch("{foo}.html", "*\\}.html"); + assertMatch("[foo].html", "\\[foo*"); + assertMatch("[foo].html", "*\\].html"); + + // errors + assertBadPattern("foo.html", "*[a--z]"); // bad range + assertBadPattern("foo.html", "*[a--]"); // bad range + assertBadPattern("foo.html", "*[a-z"); // missing ] + assertBadPattern("foo.html", "*{class,java"); // missing } + assertBadPattern("foo.html", "*.{class,{.java}}"); // nested group + assertBadPattern("foo.html", "*.html\\"); // nothing to escape + + // platform specific + if (System.getProperty("os.name").startsWith("Windows")) { + assertMatch("C:\\foo", "C:\\\\f*"); + assertMatch("C:\\FOO", "c:\\\\f*"); + assertMatch("C:\\foo\\bar\\gus", "C:\\\\**\\\\gus"); + assertMatch("C:\\foo\\bar\\gus", "C:\\\\**"); + } else { + assertMatch("/tmp/foo", "/tmp/*"); + assertMatch("/tmp/foo/bar", "/tmp/**"); + + // some special characters not allowed on Windows + assertMatch("myfile?", "myfile\\?"); + assertMatch("one\\two", "one\\\\two"); + assertMatch("one*two", "one\\*two"); + } + + + + // regex syntax + { + String pattern = ".*\\.html"; + System.out.format("Test regex pattern: %s", pattern); + Path file = Paths.get("foo.html"); + boolean matched = file.getFileSystem() + .getPathMatcher("regex:" + pattern).matches(file); + if (matched) { + System.out.println(" OKAY"); + } else { + System.out.println(" ==> UNEXPECTED RESULT!"); + failures++; + } + } + + // unknown syntax + try { + System.out.format("Test unknown syntax"); + FileSystems.getDefault().getPathMatcher("grep:foo"); + System.out.println(" ==> NOT EXPECTED TO COMPILE"); + failures++; + } catch (UnsupportedOperationException e) { + System.out.println(" OKAY"); + } + + if (failures > 0) + throw new RuntimeException(failures + + " sub-test(s) failed - see log for details"); + } +} diff --git a/test/java/nio/file/TestUtil.java b/test/java/nio/file/TestUtil.java new file mode 100644 index 0000000000000000000000000000000000000000..c19e28fbdc4b61c46a321e07eb7f1392f2f68e56 --- /dev/null +++ b/test/java/nio/file/TestUtil.java @@ -0,0 +1,125 @@ +/* + * Copyright 2008-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. + * + * 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. + */ + +import java.nio.file.*; +import java.nio.file.attribute.BasicFileAttributes; +import java.util.Random; +import java.io.IOException; + +public class TestUtil { + private TestUtil() { + } + + public static Path createTemporaryDirectory() throws IOException { + Path tmpdir = Paths.get(System.getProperty("java.io.tmpdir")); + Random r = new Random(); + + Path dir; + do { + dir = tmpdir.resolve("name" + r.nextInt()); + } while (dir.exists()); + return dir.createDirectory(); + } + + static void removeAll(Path dir) { + Files.walkFileTree(dir, new FileVisitor<Path>() { + @Override + public FileVisitResult preVisitDirectory(Path dir) { + return FileVisitResult.CONTINUE; + } + @Override + public FileVisitResult preVisitDirectoryFailed(Path dir, IOException exc) { + System.err.format("Error occured accessing directory %s\n", dir, exc); + return FileVisitResult.CONTINUE; + } + @Override + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) { + try { + file.delete(false); + } catch (IOException x) { + System.err.format("Unable to delete %s: %s\n", file, x); + } + return FileVisitResult.CONTINUE; + } + @Override + public FileVisitResult postVisitDirectory(Path dir, IOException exc) { + try { + dir.delete(false); + } catch (IOException x) { + System.err.format("Unable to delete %s: %s\n", dir, x); + } + return FileVisitResult.CONTINUE; + } + @Override + public FileVisitResult visitFileFailed(Path file, IOException exc) { + System.err.format("Unable to visit %s: %s\n", file, exc); + return FileVisitResult.CONTINUE; + } + }); + } + + static void deleteUnchecked(FileRef file) { + try { + file.delete(); + } catch (IOException exc) { + System.err.format("Unable to delete %s: %s\n", file, exc); + } + } + + /** + * Creates a directory tree in the given directory so that the total + * size of the path is more than 2k in size. This is used for long + * path tests on Windows. + */ + static Path createDirectoryWithLongPath(Path dir) + throws IOException + { + StringBuilder sb = new StringBuilder(); + for (int i=0; i<240; i++) { + sb.append('A'); + } + String name = sb.toString(); + do { + dir = dir.resolve(name).resolve("."); + dir.createDirectory(); + } while (dir.toString().length() < 2048); + return dir; + } + + /** + * Returns true if symbolic links are supported + */ + static boolean supportsLinks(Path dir) { + Path link = dir.resolve("testlink"); + Path target = dir.resolve("testtarget"); + try { + link.createSymbolicLink(target); + target.delete(false); + return true; + } catch (UnsupportedOperationException x) { + return false; + } catch (IOException x) { + return false; + } + } +} diff --git a/test/java/nio/file/WatchService/Basic.java b/test/java/nio/file/WatchService/Basic.java new file mode 100644 index 0000000000000000000000000000000000000000..60c18d74b9bf48755894c0437209e937fcfd7435 --- /dev/null +++ b/test/java/nio/file/WatchService/Basic.java @@ -0,0 +1,493 @@ +/* + * Copyright 2008-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. + * + * 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. + */ + +/* @test + * @bug 4313887 + * @summary Unit test for java.nio.file.WatchService + * @library .. + * @run main/timeout=120 Basic + */ + +import java.nio.file.*; +import static java.nio.file.StandardWatchEventKind.*; +import java.nio.file.attribute.*; +import java.io.*; +import java.util.*; +import java.util.concurrent.TimeUnit; + +/** + * Unit test for WatchService that exercises all methods in various scenarios. + */ + +public class Basic { + + static void createFile(Path file) throws IOException { + file.newOutputStream().close(); + } + + static void takeExpectedKey(WatchService watcher, WatchKey expected) { + System.out.println("take events..."); + WatchKey key; + try { + key = watcher.take(); + } catch (InterruptedException x) { + // not expected + throw new RuntimeException(x); + } + if (key != expected) + throw new RuntimeException("removed unexpected key"); + } + + static void checkExpectedEvent(Iterable<WatchEvent<?>> events, + WatchEvent.Kind<?> expectedKind, + Object expectedContext) + { + WatchEvent<?> event = events.iterator().next(); + System.out.format("got event: type=%s, count=%d, context=%s\n", + event.kind(), event.count(), event.context()); + if (event.kind() != expectedKind) + throw new RuntimeException("unexpected event"); + if (!expectedContext.equals(event.context())) + throw new RuntimeException("unexpected context"); + } + + /** + * Simple test of each of the standard events + */ + static void testEvents(Path dir) throws IOException { + System.out.println("-- Standard Events --"); + + FileSystem fs = FileSystems.getDefault(); + Path name = fs.getPath("foo"); + + WatchService watcher = fs.newWatchService(); + try { + // --- ENTRY_CREATE --- + + // register for event + System.out.format("register %s for ENTRY_CREATE\n", dir); + WatchKey myKey = dir.register(watcher, + new WatchEvent.Kind<?>[]{ ENTRY_CREATE }); + + // create file + Path file = dir.resolve("foo"); + System.out.format("create %s\n", file); + createFile(file); + + // remove key and check that we got the ENTRY_CREATE event + takeExpectedKey(watcher, myKey); + checkExpectedEvent(myKey.pollEvents(), + StandardWatchEventKind.ENTRY_CREATE, name); + + System.out.println("reset key"); + if (!myKey.reset()) + throw new RuntimeException("key has been cancalled"); + + System.out.println("OKAY"); + + // --- ENTRY_DELETE --- + + System.out.format("register %s for ENTRY_DELETE\n", dir); + WatchKey deleteKey = dir.register(watcher, + new WatchEvent.Kind<?>[]{ ENTRY_DELETE }); + if (deleteKey != myKey) + throw new RuntimeException("register did not return existing key"); + + System.out.format("delete %s\n", file); + file.delete(false); + takeExpectedKey(watcher, myKey); + checkExpectedEvent(myKey.pollEvents(), + StandardWatchEventKind.ENTRY_DELETE, name); + + System.out.println("reset key"); + if (!myKey.reset()) + throw new RuntimeException("key has been cancalled"); + + System.out.println("OKAY"); + + // create the file for the next test + createFile(file); + + // --- ENTRY_MODIFY --- + + System.out.format("register %s for ENTRY_MODIFY\n", dir); + WatchKey newKey = dir.register(watcher, + new WatchEvent.Kind<?>[]{ ENTRY_MODIFY }); + if (newKey != myKey) + throw new RuntimeException("register did not return existing key"); + + System.out.format("update: %s\n", file); + OutputStream out = file.newOutputStream(EnumSet.of(StandardOpenOption.APPEND)); + try { + out.write("I am a small file".getBytes("UTF-8")); + } finally { + out.close(); + } + + // remove key and check that we got the ENTRY_MODIFY event + takeExpectedKey(watcher, myKey); + checkExpectedEvent(myKey.pollEvents(), + StandardWatchEventKind.ENTRY_MODIFY, name); + System.out.println("OKAY"); + + // done + file.delete(false); + + } finally { + watcher.close(); + } + } + + /** + * Check that a cancelled key will never be queued + */ + static void testCancel(Path dir) throws IOException { + System.out.println("-- Cancel --"); + + WatchService watcher = FileSystems.getDefault().newWatchService(); + try { + + System.out.format("register %s for events\n", dir); + WatchKey myKey = dir.register(watcher, + new WatchEvent.Kind<?>[]{ ENTRY_CREATE }); + + System.out.println("cancel key"); + myKey.cancel(); + + // create a file in the directory + Path file = dir.resolve("mars"); + System.out.format("create: %s\n", file); + createFile(file); + + // poll for keys - there will be none + System.out.println("poll..."); + try { + WatchKey key = watcher.poll(3000, TimeUnit.MILLISECONDS); + if (key != null) + throw new RuntimeException("key should not be queued"); + } catch (InterruptedException x) { + throw new RuntimeException(x); + } + + // done + file.delete(false); + + System.out.println("OKAY"); + + } finally { + watcher.close(); + } + } + + /** + * Check that deleting a registered directory causes the key to be + * cancelled and queued. + */ + static void testAutomaticCancel(Path dir) throws IOException { + System.out.println("-- Automatic Cancel --"); + + Path subdir = dir.resolve("bar").createDirectory(); + + WatchService watcher = FileSystems.getDefault().newWatchService(); + try { + + System.out.format("register %s for events\n", subdir); + WatchKey myKey = subdir.register(watcher, + new WatchEvent.Kind<?>[]{ ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY }); + + System.out.format("delete: %s\n", subdir); + subdir.delete(false); + takeExpectedKey(watcher, myKey); + + System.out.println("reset key"); + if (myKey.reset()) + throw new RuntimeException("Key was not cancelled"); + if (myKey.isValid()) + throw new RuntimeException("Key is still valid"); + + System.out.println("OKAY"); + + } finally { + watcher.close(); + } + } + + /** + * Asynchronous close of watcher causes blocked threads to wakeup + */ + static void testWakeup(Path dir) throws IOException { + System.out.println("-- Wakeup Tests --"); + final WatchService watcher = FileSystems.getDefault().newWatchService(); + Runnable r = new Runnable() { + public void run() { + try { + Thread.sleep(5000); + System.out.println("close WatchService..."); + watcher.close(); + } catch (InterruptedException x) { + x.printStackTrace(); + } catch (IOException x) { + x.printStackTrace(); + } + } + }; + + // start thread to close watch service after delay + new Thread(r).start(); + + try { + System.out.println("take..."); + watcher.take(); + throw new RuntimeException("ClosedWatchServiceException not thrown"); + } catch (InterruptedException x) { + throw new RuntimeException(x); + } catch (ClosedWatchServiceException x) { + System.out.println("ClosedWatchServiceException thrown"); + } + + System.out.println("OKAY"); + } + + /** + * Simple test to check exceptions and other cases + */ + @SuppressWarnings("unchecked") + static void testExceptions(Path dir) throws IOException { + System.out.println("-- Exceptions and other simple tests --"); + + WatchService watcher = FileSystems.getDefault().newWatchService(); + try { + + // Poll tests + + WatchKey key; + System.out.println("poll..."); + key = watcher.poll(); + if (key != null) + throw new RuntimeException("no keys registered"); + + System.out.println("poll with timeout..."); + try { + long start = System.currentTimeMillis(); + key = watcher.poll(3000, TimeUnit.MILLISECONDS); + if (key != null) + throw new RuntimeException("no keys registered"); + long waited = System.currentTimeMillis() - start; + if (waited < 2900) + throw new RuntimeException("poll was too short"); + } catch (InterruptedException x) { + throw new RuntimeException(x); + } + + // IllegalArgumentException + System.out.println("IllegalArgumentException tests..."); + try { + dir.register(watcher, new WatchEvent.Kind<?>[]{ } ); + throw new RuntimeException("IllegalArgumentException not thrown"); + } catch (IllegalArgumentException x) { + } + try { + // OVERFLOW is ignored so this is equivalent to the empty set + dir.register(watcher, new WatchEvent.Kind<?>[]{ OVERFLOW }); + throw new RuntimeException("IllegalArgumentException not thrown"); + } catch (IllegalArgumentException x) { + } + + // UnsupportedOperationException + try { + dir.register(watcher, new WatchEvent.Kind<?>[]{ + new WatchEvent.Kind<Object>() { + @Override public String name() { return "custom"; } + @Override public Class<Object> type() { return Object.class; } + }}); + } catch (UnsupportedOperationException x) { + } + try { + dir.register(watcher, + new WatchEvent.Kind<?>[]{ ENTRY_CREATE }, + new WatchEvent.Modifier() { + @Override public String name() { return "custom"; } + }); + throw new RuntimeException("UnsupportedOperationException not thrown"); + } catch (UnsupportedOperationException x) { + } + + // NullPointerException + System.out.println("NullPointerException tests..."); + try { + dir.register(null, new WatchEvent.Kind<?>[]{ ENTRY_CREATE }); + throw new RuntimeException("NullPointerException not thrown"); + } catch (NullPointerException x) { + } + try { + dir.register(watcher, new WatchEvent.Kind<?>[]{ null }); + throw new RuntimeException("NullPointerException not thrown"); + } catch (NullPointerException x) { + } + try { + dir.register(watcher, new WatchEvent.Kind<?>[]{ ENTRY_CREATE }, + (WatchEvent.Modifier)null); + throw new RuntimeException("NullPointerException not thrown"); + } catch (NullPointerException x) { + } + } finally { + watcher.close(); + } + + // -- ClosedWatchServiceException -- + + System.out.println("ClosedWatchServiceException tests..."); + + try { + watcher.poll(); + throw new RuntimeException("ClosedWatchServiceException not thrown"); + } catch (ClosedWatchServiceException x) { + } + + // assume that poll throws exception immediately + long start = System.currentTimeMillis(); + try { + watcher.poll(10000, TimeUnit.MILLISECONDS); + throw new RuntimeException("ClosedWatchServiceException not thrown"); + } catch (InterruptedException x) { + throw new RuntimeException(x); + } catch (ClosedWatchServiceException x) { + long waited = System.currentTimeMillis() - start; + if (waited > 5000) + throw new RuntimeException("poll was too long"); + } + + try { + watcher.take(); + throw new RuntimeException("ClosedWatchServiceException not thrown"); + } catch (InterruptedException x) { + throw new RuntimeException(x); + } catch (ClosedWatchServiceException x) { + } + + try { + dir.register(watcher, new WatchEvent.Kind<?>[]{ ENTRY_CREATE }); + throw new RuntimeException("ClosedWatchServiceException not thrown"); + } catch (ClosedWatchServiceException x) { + } + + System.out.println("OKAY"); + } + + /** + * Test that directory can be registered with more than one watch service + * and that events don't interfere with each other + */ + static void testTwoWatchers(Path dir) throws IOException { + System.out.println("-- Two watchers test --"); + + FileSystem fs = FileSystems.getDefault(); + WatchService watcher1 = fs.newWatchService(); + WatchService watcher2 = fs.newWatchService(); + try { + Path name1 = fs.getPath("gus1"); + Path name2 = fs.getPath("gus2"); + + // create gus1 + Path file1 = dir.resolve(name1); + System.out.format("create %s\n", file1); + createFile(file1); + + // register with both watch services (different events) + System.out.println("register for different events"); + WatchKey key1 = dir.register(watcher1, + new WatchEvent.Kind<?>[]{ ENTRY_CREATE }); + WatchKey key2 = dir.register(watcher2, + new WatchEvent.Kind<?>[]{ ENTRY_DELETE }); + + if (key1 == key2) + throw new RuntimeException("keys should be different"); + + // create gus2 + Path file2 = dir.resolve(name2); + System.out.format("create %s\n", file2); + createFile(file2); + + // check that key1 got ENTRY_CREATE + takeExpectedKey(watcher1, key1); + checkExpectedEvent(key1.pollEvents(), + StandardWatchEventKind.ENTRY_CREATE, name2); + + // check that key2 got zero events + WatchKey key = watcher2.poll(); + if (key != null) + throw new RuntimeException("key not expected"); + + // delete gus1 + file1.delete(false); + + // check that key2 got ENTRY_DELETE + takeExpectedKey(watcher2, key2); + checkExpectedEvent(key2.pollEvents(), + StandardWatchEventKind.ENTRY_DELETE, name1); + + // check that key1 got zero events + key = watcher1.poll(); + if (key != null) + throw new RuntimeException("key not expected"); + + // reset for next test + key1.reset(); + key2.reset(); + + // change registration with watcher2 so that they are both + // registered for the same event + System.out.println("register for same event"); + key2 = dir.register(watcher2, new WatchEvent.Kind<?>[]{ ENTRY_CREATE }); + + // create file and key2 should be queued + System.out.format("create %s\n", file1); + createFile(file1); + takeExpectedKey(watcher2, key2); + checkExpectedEvent(key2.pollEvents(), + StandardWatchEventKind.ENTRY_CREATE, name1); + + System.out.println("OKAY"); + + } finally { + watcher2.close(); + watcher1.close(); + } + } + + public static void main(String[] args) throws IOException { + Path dir = TestUtil.createTemporaryDirectory(); + try { + + testEvents(dir); + testCancel(dir); + testAutomaticCancel(dir); + testWakeup(dir); + testExceptions(dir); + testTwoWatchers(dir); + + } finally { + TestUtil.removeAll(dir); + } + } +} diff --git a/test/java/nio/file/WatchService/FileTreeModifier.java b/test/java/nio/file/WatchService/FileTreeModifier.java new file mode 100644 index 0000000000000000000000000000000000000000..741c86df0942058b13dbe9b1a70a95687220a6f1 --- /dev/null +++ b/test/java/nio/file/WatchService/FileTreeModifier.java @@ -0,0 +1,148 @@ +/* + * Copyright 2008-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. + * + * 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. + */ + +/* @test + * @bug 4313887 + * @summary Sanity test for Sun-specific FILE_TREE watch event modifier + * @library .. + */ + +import java.nio.file.*; +import static java.nio.file.StandardWatchEventKind.*; +import java.io.IOException; +import java.io.OutputStream; +import java.util.*; +import java.util.concurrent.*; +import static com.sun.nio.file.ExtendedWatchEventModifier.*; + +public class FileTreeModifier { + + static void checkExpectedEvent(WatchService watcher, + WatchEvent.Kind<?> expectedType, + Object expectedContext) + { + WatchKey key; + try { + key = watcher.take(); + } catch (InterruptedException x) { + // should not happen + throw new RuntimeException(x); + } + WatchEvent<?> event = key.pollEvents().iterator().next(); + System.out.format("Event: type=%s, count=%d, context=%s\n", + event.kind(), event.count(), event.context()); + if (event.kind() != expectedType) + throw new RuntimeException("unexpected event"); + if (!expectedContext.equals(event.context())) + throw new RuntimeException("unexpected context"); + } + + static void doTest(Path top) throws IOException { + FileSystem fs = top.getFileSystem(); + WatchService watcher = fs.newWatchService(); + + // create directories + Path subdir = top + .resolve("a").createDirectory() + .resolve("b").createDirectory() + .resolve("c").createDirectory(); + + // Test ENTRY_CREATE with FILE_TREE modifier. + + WatchKey key = top.register(watcher, + new WatchEvent.Kind<?>[]{ ENTRY_CREATE }, FILE_TREE); + + // create file in a/b/c and check we get create event + Path file = subdir.resolve("foo").createFile(); + checkExpectedEvent(watcher, ENTRY_CREATE, top.relativize(file)); + key.reset(); + + // Test ENTRY_DELETE with FILE_TREE modifier. + + WatchKey k = top.register(watcher, + new WatchEvent.Kind<?>[]{ ENTRY_DELETE }, FILE_TREE); + if (k != key) + throw new RuntimeException("Existing key not returned"); + + // delete a/b/c/foo and check we get delete event + file.delete(false); + checkExpectedEvent(watcher, ENTRY_DELETE, top.relativize(file)); + key.reset(); + + // Test changing registration to ENTRY_CREATE without modifier + + k = top.register(watcher, new WatchEvent.Kind<?>[]{ ENTRY_CREATE }); + if (k != key) + throw new RuntimeException("Existing key not returned"); + + // create a/b/c/foo + file.createFile(); + + // check that key is not queued + try { + k = watcher.poll(3, TimeUnit.SECONDS); + } catch (InterruptedException e) { + throw new RuntimeException(); + } + if (k != null) + throw new RuntimeException("WatchKey not expected to be polled"); + + // create bar and check we get create event + file = top.resolve("bar").createFile(); + checkExpectedEvent(watcher, ENTRY_CREATE, top.relativize(file)); + key.reset(); + + // Test changing registration to <all> with FILE_TREE modifier + + k = top.register(watcher, + new WatchEvent.Kind<?>[]{ ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY }, + FILE_TREE); + if (k != key) + throw new RuntimeException("Existing key not returned"); + + // modify bar and check we get modify event + OutputStream out = file.newOutputStream(); + try { + out.write("Double shot expresso please".getBytes("UTF-8")); + } finally { + out.close(); + } + checkExpectedEvent(watcher, ENTRY_MODIFY, top.relativize(file)); + key.reset(); + } + + + public static void main(String[] args) throws IOException { + if (!System.getProperty("os.name").startsWith("Windows")) { + System.out.println("This is Windows-only test at this time!"); + return; + } + + Path dir = TestUtil.createTemporaryDirectory(); + try { + doTest(dir); + } finally { + TestUtil.removeAll(dir); + } + } +} diff --git a/test/java/nio/file/WatchService/SensitivityModifier.java b/test/java/nio/file/WatchService/SensitivityModifier.java new file mode 100644 index 0000000000000000000000000000000000000000..62aedeeac0a8dfe26a78fdd7b223f0a089ee63a7 --- /dev/null +++ b/test/java/nio/file/WatchService/SensitivityModifier.java @@ -0,0 +1,122 @@ +/* + * Copyright 2008-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. + * + * 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. + */ + +/* @test + * @bug 4313887 + * @summary Sanity test for Sun-specific sensitivyt level watch event modifier + * @library .. + * @run main/timeout=330 Basic + */ + +import java.nio.file.*; +import static java.nio.file.StandardWatchEventKind.*; +import java.io.OutputStream; +import java.io.IOException; +import java.util.Random; +import java.util.concurrent.TimeUnit; +import com.sun.nio.file.SensitivityWatchEventModifier; + +public class SensitivityModifier { + + static final Random rand = new Random(); + + static void register(Path[] dirs, WatchService watcher) throws IOException { + SensitivityWatchEventModifier[] sensitivtives = + SensitivityWatchEventModifier.values(); + for (int i=0; i<dirs.length; i++) { + SensitivityWatchEventModifier sensivity = + sensitivtives[ rand.nextInt(sensitivtives.length) ]; + Path dir = dirs[i]; + dir.register(watcher, new WatchEvent.Kind<?>[]{ ENTRY_MODIFY }, sensivity); + } + } + + static void doTest(Path top) throws Exception { + FileSystem fs = top.getFileSystem(); + WatchService watcher = fs.newWatchService(); + + // create directories and files + int nDirs = 5 + rand.nextInt(20); + int nFiles = 50 + rand.nextInt(50); + Path[] dirs = new Path[nDirs]; + Path[] files = new Path[nFiles]; + for (int i=0; i<nDirs; i++) { + dirs[i] = top.resolve("dir" + i).createDirectory(); + } + for (int i=0; i<nFiles; i++) { + Path dir = dirs[rand.nextInt(nDirs)]; + files[i] = dir.resolve("file" + i).createFile(); + } + + // register the directories (random sensitivity) + register(dirs, watcher); + + // sleep a bit here to ensure that modification to the first file + // can be detected by polling implementations (ie: last modified time + // may not change otherwise). + try { Thread.sleep(1000); } catch (InterruptedException e) { } + + // modify files and check that events are received + for (int i=0; i<10; i++) { + Path file = files[rand.nextInt(nFiles)]; + System.out.println("Modify: " + file); + OutputStream out = file.newOutputStream(); + try { + out.write(new byte[100]); + } finally { + out.close(); + } + System.out.println("Waiting for event..."); + WatchKey key = watcher.take(); + WatchEvent<?> event = key.pollEvents().iterator().next(); + if (event.kind() != ENTRY_MODIFY) + throw new RuntimeException("Unexpected event: " + event); + Path name = ((WatchEvent<Path>)event).context(); + if (!name.equals(file.getName())) + throw new RuntimeException("Unexpected context: " + name); + System.out.println("Event OK"); + + // drain events (to avoid interference) + do { + key.reset(); + key = watcher.poll(1, TimeUnit.SECONDS); + } while (key != null); + + // re-register the directories to force changing their sensitivity + // level + register(dirs, watcher); + } + + // done + watcher.close(); + } + + public static void main(String[] args) throws Exception { + Path dir = TestUtil.createTemporaryDirectory(); + try { + doTest(dir); + } finally { + TestUtil.removeAll(dir); + } + } +} diff --git a/test/java/nio/file/WatchService/WithSecurityManager.java b/test/java/nio/file/WatchService/WithSecurityManager.java new file mode 100644 index 0000000000000000000000000000000000000000..c227585eef71d3cb5b15d562e1faa172e1d397f8 --- /dev/null +++ b/test/java/nio/file/WatchService/WithSecurityManager.java @@ -0,0 +1,83 @@ +/* + * Copyright 2008-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. + * + * 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. + */ + +/* @test + * @bug 4313887 + * @summary Unit test for Watchable#register's permission checks + * @build WithSecurityManager + * @run main/othervm WithSecurityManager denyAll.policy - fail + * @run main/othervm WithSecurityManager denyAll.policy tree fail + * @run main/othervm WithSecurityManager grantDirOnly.policy - pass + * @run main/othervm WithSecurityManager grantDirOnly.policy tree fail + * @run main/othervm WithSecurityManager grantDirAndOneLevel.policy - pass + * @run main/othervm WithSecurityManager grantDirAndOneLevel.policy tree fail + * @run main/othervm WithSecurityManager grantDirAndTree.policy - pass + * @run main/othervm WithSecurityManager grantDirAndTree.policy tree pass + */ + +import java.nio.file.*; +import java.io.IOException; +import com.sun.nio.file.ExtendedWatchEventModifier; + +public class WithSecurityManager { + + public static void main(String[] args) throws IOException { + String policyFile = args[0]; + boolean recursive = args[1].equals("tree"); + boolean expectedToFail = args[2].equals("fail"); + + // install security manager with the given policy file + String testSrc = System.getProperty("test.src"); + if (testSrc == null) + throw new RuntimeException("This test must be run by jtreg"); + Path dir = Paths.get(testSrc); + System.setProperty("java.security.policy", dir.resolve(policyFile).toString()); + System.setSecurityManager(new SecurityManager()); + + // initialize optional modifier + WatchEvent.Modifier[] modifiers; + if (recursive) { + modifiers = new WatchEvent.Modifier[1]; + modifiers[0] = ExtendedWatchEventModifier.FILE_TREE; + } else { + modifiers = new WatchEvent.Modifier[0]; + } + + // attempt to register directory + try { + dir.register(dir.getFileSystem().newWatchService(), + new WatchEvent.Kind<?>[]{ StandardWatchEventKind.ENTRY_CREATE }, + modifiers); + if (expectedToFail) + throw new RuntimeException("SecurityException not thrown"); + } catch (SecurityException e) { + if (!expectedToFail) + throw e; + } catch (UnsupportedOperationException e) { + // FILE_TREE modifier only supported on some platforms + if (!recursive) + throw new RuntimeException(e); + System.out.println("FILE_TREE option not supported"); + } + } +} diff --git a/test/java/nio/file/WatchService/denyAll.policy b/test/java/nio/file/WatchService/denyAll.policy new file mode 100644 index 0000000000000000000000000000000000000000..32500947791001ea25267a6f5c54d95ec0075172 --- /dev/null +++ b/test/java/nio/file/WatchService/denyAll.policy @@ -0,0 +1,3 @@ +// policy file that does not grant any permissions +grant { +}; diff --git a/test/java/nio/file/WatchService/grantDirAndOneLevel.policy b/test/java/nio/file/WatchService/grantDirAndOneLevel.policy new file mode 100644 index 0000000000000000000000000000000000000000..1a34646464a1910678ad9d06524555086b412cb8 --- /dev/null +++ b/test/java/nio/file/WatchService/grantDirAndOneLevel.policy @@ -0,0 +1,5 @@ +// policy file that grants read access to source directory and its entries +grant { + permission java.io.FilePermission "${test.src}", "read"; + permission java.io.FilePermission "${test.src}${file.separator}*", "read"; +}; diff --git a/test/java/nio/file/WatchService/grantDirAndTree.policy b/test/java/nio/file/WatchService/grantDirAndTree.policy new file mode 100644 index 0000000000000000000000000000000000000000..85bc0d0fb51f23eea23c226cb8a1f7f79af92901 --- /dev/null +++ b/test/java/nio/file/WatchService/grantDirAndTree.policy @@ -0,0 +1,5 @@ +// policy file that grants read access to source directory and all descendants +grant { + permission java.io.FilePermission "${test.src}", "read"; + permission java.io.FilePermission "${test.src}${file.separator}-", "read"; +}; diff --git a/test/java/nio/file/WatchService/grantDirOnly.policy b/test/java/nio/file/WatchService/grantDirOnly.policy new file mode 100644 index 0000000000000000000000000000000000000000..fca1539416feb5a502dfacbff39fe0bc7e14a763 --- /dev/null +++ b/test/java/nio/file/WatchService/grantDirOnly.policy @@ -0,0 +1,4 @@ +// policy file that grants read access to source directory +grant { + permission java.io.FilePermission "${test.src}", "read"; +}; diff --git a/test/java/nio/file/attribute/AclFileAttributeView/Basic.java b/test/java/nio/file/attribute/AclFileAttributeView/Basic.java new file mode 100644 index 0000000000000000000000000000000000000000..3a9960702f9e8c6901aea473ee5951bafca21fdf --- /dev/null +++ b/test/java/nio/file/attribute/AclFileAttributeView/Basic.java @@ -0,0 +1,166 @@ +/* + * Copyright 2008-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. + * + * 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. + */ + +/* @test + * @bug 4313887 + * @summary Unit test for java.nio.file.attribute.AclFileAttribueView + * @library ../.. + */ + +import java.nio.file.*; +import java.nio.file.attribute.*; +import java.io.IOException; +import java.util.*; + +import static java.nio.file.attribute.AclEntryType.*; +import static java.nio.file.attribute.AclEntryPermission.*; +import static java.nio.file.attribute.AclEntryFlag.*; + +public class Basic { + + static void printAcl(List<AclEntry> acl) { + for (AclEntry entry: acl) { + System.out.format(" %s%n", entry); + } + } + + // sanity check read and writing ACL + static void testReadWrite(Path dir) throws IOException { + Path file = dir.resolve("foo"); + if (file.notExists()) + file.createFile(); + + AclFileAttributeView view = file + .getFileAttributeView(AclFileAttributeView.class); + + // print existing ACL + List<AclEntry> acl = view.getAcl(); + System.out.println(" -- current ACL --"); + printAcl(acl); + + // insert entry to grant owner read access + UserPrincipal owner = view.getOwner(); + AclEntry entry = AclEntry.newBuilder() + .setType(ALLOW) + .setPrincipal(owner) + .setPermissions(READ_DATA, READ_ATTRIBUTES) + .build(); + System.out.println(" -- insert (entry 0) --"); + System.out.format(" %s%n", entry); + acl.add(0, entry); + view.setAcl(acl); + + // re-ACL and check entry + List<AclEntry> newacl = view.getAcl(); + System.out.println(" -- current ACL --"); + printAcl(acl); + if (!newacl.get(0).equals(entry)) { + throw new RuntimeException("Entry 0 is not expected"); + } + + // if PosixFileAttributeView then repeat test with OWNER@ + if (file.getFileStore().supportsFileAttributeView("posix")) { + owner = file.getFileSystem().getUserPrincipalLookupService() + .lookupPrincipalByName("OWNER@"); + entry = AclEntry.newBuilder(entry).setPrincipal(owner).build(); + + System.out.println(" -- replace (entry 0) --"); + System.out.format(" %s%n", entry); + + acl.set(0, entry); + view.setAcl(acl); + newacl = view.getAcl(); + System.out.println(" -- current ACL --"); + printAcl(acl); + if (!newacl.get(0).equals(entry)) { + throw new RuntimeException("Entry 0 is not expected"); + } + } + } + + static FileAttribute<List<AclEntry>> asAclAttribute(final List<AclEntry> acl) { + return new FileAttribute<List<AclEntry>>() { + public String name() { return "acl:acl"; } + public List<AclEntry> value() { return acl; } + }; + } + + static void assertEquals(List<AclEntry> actual, List<AclEntry> expected) { + if (!actual.equals(expected)) { + System.err.format("Actual: %s\n", actual); + System.err.format("Expected: %s\n", expected); + throw new RuntimeException("ACL not expected"); + } + } + + // sanity check create a file or directory with initial ACL + static void testCreateFile(Path dir) throws IOException { + UserPrincipal user = Attributes.getOwner(dir); + + // create file with initial ACL + System.out.println("-- create file with initial ACL --"); + Path file = dir.resolve("gus"); + List<AclEntry> fileAcl = Arrays.asList( + AclEntry.newBuilder() + .setType(AclEntryType.ALLOW) + .setPrincipal(user) + .setPermissions(SYNCHRONIZE, READ_DATA, WRITE_DATA, + READ_ATTRIBUTES, READ_ACL, WRITE_ATTRIBUTES, DELETE) + .build()); + file.createFile(asAclAttribute(fileAcl)); + assertEquals(Attributes.getAcl(file), fileAcl); + + // create directory with initial ACL + System.out.println("-- create directory with initial ACL --"); + Path subdir = dir.resolve("stuff"); + List<AclEntry> dirAcl = Arrays.asList( + AclEntry.newBuilder() + .setType(AclEntryType.ALLOW) + .setPrincipal(user) + .setPermissions(SYNCHRONIZE, ADD_FILE, DELETE) + .build(), + AclEntry.newBuilder(fileAcl.get(0)) + .setFlags(FILE_INHERIT) + .build()); + subdir.createDirectory(asAclAttribute(dirAcl)); + assertEquals(Attributes.getAcl(subdir), dirAcl); + } + + public static void main(String[] args) throws IOException { + Path dir = TestUtil.createTemporaryDirectory(); + try { + if (!dir.getFileStore().supportsFileAttributeView("acl")) { + System.out.println("ACLs not supported - test skipped!"); + return; + } + testReadWrite(dir); + + // only currently feasible on Windows + if (System.getProperty("os.name").startsWith("Windows")) + testCreateFile(dir); + + } finally { + TestUtil.removeAll(dir); + } + } +} diff --git a/test/java/nio/file/attribute/Attributes/Basic.java b/test/java/nio/file/attribute/Attributes/Basic.java new file mode 100644 index 0000000000000000000000000000000000000000..8dfde80d9a5691e34e18770ec0009efb48127527 --- /dev/null +++ b/test/java/nio/file/attribute/Attributes/Basic.java @@ -0,0 +1,254 @@ +/* + * Copyright 2008-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. + * + * 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. + */ + +/* @test + * @bug 4313887 + * @summary Unit test for java.nio.file.attribute.Attributes + * @library ../.. + */ + +import java.nio.file.*; +import java.nio.file.attribute.*; +import java.io.IOException; +import java.util.*; +import java.util.concurrent.TimeUnit; + +/** + * Exercises getAttribute/setAttribute/readAttributes methods. + */ + +public class Basic { + + static void assertTrue(boolean okay) { + if (!okay) + throw new RuntimeException("Assertion Failed"); + } + + static void checkEqual(Object o1, Object o2) { + if (o1 == null) { + assertTrue(o2 == null); + } else { + assertTrue (o1.equals(o2)); + } + } + + // Exercise getAttribute/setAttribute/readAttributes on basic attributes + static void checkBasicAttributes(FileRef file, BasicFileAttributes attrs) + throws IOException + { + // getAttribute + checkEqual(attrs.size(), Attributes.getAttribute(file, "size")); + checkEqual(attrs.lastModifiedTime(), + Attributes.getAttribute(file, "basic:lastModifiedTime")); + checkEqual(attrs.lastAccessTime(), + Attributes.getAttribute(file, "lastAccessTime")); + checkEqual(attrs.creationTime(), + Attributes.getAttribute(file, "basic:creationTime")); + assertTrue((Boolean)Attributes.getAttribute(file, "isRegularFile")); + assertTrue(!(Boolean)Attributes.getAttribute(file, "basic:isDirectory")); + assertTrue(!(Boolean)Attributes.getAttribute(file, "isSymbolicLink")); + assertTrue(!(Boolean)Attributes.getAttribute(file, "basic:isOther")); + checkEqual(attrs.linkCount(), + (Integer)Attributes.getAttribute(file, "linkCount")); + checkEqual(attrs.fileKey(), Attributes.getAttribute(file, "basic:fileKey")); + + // setAttribute + if (attrs.resolution() == TimeUnit.MILLISECONDS) { + long modTime = attrs.lastModifiedTime(); + Attributes.setAttribute(file, "basic:lastModifiedTime", 0L); + assertTrue(Attributes.readBasicFileAttributes(file).lastModifiedTime() == 0L); + Attributes.setAttribute(file, "lastModifiedTime", modTime); + assertTrue(Attributes.readBasicFileAttributes(file).lastModifiedTime() == modTime); + } + + // readAttributes + Map<String,?> map; + map = Attributes.readAttributes(file, "*"); + assertTrue(map.size() >= 11); + checkEqual(attrs.isRegularFile(), map.get("isRegularFile")); // check one + + map = Attributes.readAttributes(file, "basic:*"); + assertTrue(map.size() >= 11); + checkEqual(attrs.lastAccessTime(), map.get("lastAccessTime")); // check one + + map = Attributes.readAttributes(file, "size,lastModifiedTime"); + assertTrue(map.size() == 2); + checkEqual(attrs.size(), map.get("size")); + checkEqual(attrs.lastModifiedTime(), map.get("lastModifiedTime")); + + map = Attributes.readAttributes(file, + "basic:lastModifiedTime,lastAccessTime,linkCount,ShouldNotExist"); + assertTrue(map.size() == 3); + checkEqual(attrs.lastModifiedTime(), map.get("lastModifiedTime")); + checkEqual(attrs.lastAccessTime(), map.get("lastAccessTime")); + checkEqual(attrs.lastAccessTime(), map.get("lastAccessTime")); + } + + // Exercise getAttribute/setAttribute/readAttributes on posix attributes + static void checkPosixAttributes(FileRef file, PosixFileAttributes attrs) + throws IOException + { + checkBasicAttributes(file, attrs); + + // getAttribute + checkEqual(attrs.permissions(), + Attributes.getAttribute(file, "posix:permissions")); + checkEqual(attrs.owner(), + Attributes.getAttribute(file, "posix:owner")); + checkEqual(attrs.group(), + Attributes.getAttribute(file, "posix:group")); + + // setAttribute + Set<PosixFilePermission> orig = attrs.permissions(); + Set<PosixFilePermission> newPerms = new HashSet<PosixFilePermission>(orig); + newPerms.remove(PosixFilePermission.OTHERS_READ); + newPerms.remove(PosixFilePermission.OTHERS_WRITE); + newPerms.remove(PosixFilePermission.OTHERS_EXECUTE); + Attributes.setAttribute(file, "posix:permissions", newPerms); + checkEqual(Attributes.readPosixFileAttributes(file).permissions(), newPerms); + Attributes.setAttribute(file, "posix:permissions", orig); + checkEqual(Attributes.readPosixFileAttributes(file).permissions(), orig); + Attributes.setAttribute(file, "posix:owner", attrs.owner()); + Attributes.setAttribute(file, "posix:group", attrs.group()); + + // readAttributes + Map<String,?> map; + map = Attributes.readAttributes(file, "posix:*"); + assertTrue(map.size() >= 14); + checkEqual(attrs.permissions(), map.get("permissions")); // check one + + map = Attributes.readAttributes(file, "posix:size,owner,ShouldNotExist"); + assertTrue(map.size() == 2); + checkEqual(attrs.size(), map.get("size")); + checkEqual(attrs.owner(), map.get("owner")); + } + + // Exercise getAttribute/setAttribute/readAttributes on unix attributes + static void checkUnixAttributes(FileRef file) throws IOException { + // getAttribute + int mode = (Integer)Attributes.getAttribute(file, "unix:mode"); + long ino = (Long)Attributes.getAttribute(file, "unix:ino"); + long dev = (Long)Attributes.getAttribute(file, "unix:dev"); + long rdev = (Long)Attributes.getAttribute(file, "unix:rdev"); + int uid = (Integer)Attributes.getAttribute(file, "unix:uid"); + int gid = (Integer)Attributes.getAttribute(file, "unix:gid"); + long ctime = (Long)Attributes.getAttribute(file, "unix:ctime"); + + // readAttributes + Map<String,?> map; + map = Attributes.readAttributes(file, "unix:*"); + assertTrue(map.size() >= 21); + + map = Attributes.readAttributes(file, "unix:size,uid,gid,ShouldNotExist"); + assertTrue(map.size() == 3); + checkEqual(map.get("size"), + Attributes.readBasicFileAttributes(file).size()); + } + + // Exercise getAttribute/setAttribute/readAttributes on dos attributes + static void checkDosAttributes(FileRef file, DosFileAttributes attrs) + throws IOException + { + checkBasicAttributes(file, attrs); + + // getAttribute + checkEqual(attrs.isReadOnly(), + Attributes.getAttribute(file, "dos:readonly")); + checkEqual(attrs.isHidden(), + Attributes.getAttribute(file, "dos:hidden")); + checkEqual(attrs.isSystem(), + Attributes.getAttribute(file, "dos:system")); + checkEqual(attrs.isArchive(), + Attributes.getAttribute(file, "dos:archive")); + + // setAttribute + boolean value; + + value = attrs.isReadOnly(); + Attributes.setAttribute(file, "dos:readonly", !value); + checkEqual(Attributes.readDosFileAttributes(file).isReadOnly(), !value); + Attributes.setAttribute(file, "dos:readonly", value); + checkEqual(Attributes.readDosFileAttributes(file).isReadOnly(), value); + + value = attrs.isHidden(); + Attributes.setAttribute(file, "dos:hidden", !value); + checkEqual(Attributes.readDosFileAttributes(file).isHidden(), !value); + Attributes.setAttribute(file, "dos:hidden", value); + checkEqual(Attributes.readDosFileAttributes(file).isHidden(), value); + + value = attrs.isSystem(); + Attributes.setAttribute(file, "dos:system", !value); + checkEqual(Attributes.readDosFileAttributes(file).isSystem(), !value); + Attributes.setAttribute(file, "dos:system", value); + checkEqual(Attributes.readDosFileAttributes(file).isSystem(), value); + + value = attrs.isArchive(); + Attributes.setAttribute(file, "dos:archive", !value); + checkEqual(Attributes.readDosFileAttributes(file).isArchive(), !value); + Attributes.setAttribute(file, "dos:archive", value); + checkEqual(Attributes.readDosFileAttributes(file).isArchive(), value); + + // readAttributes + Map<String,?> map; + map = Attributes.readAttributes(file, "dos:*"); + assertTrue(map.size() >= 15); + checkEqual(attrs.isReadOnly(), map.get("readonly")); // check one + + map = Attributes.readAttributes(file, "dos:size,hidden,ShouldNotExist"); + assertTrue(map.size() == 2); + checkEqual(attrs.size(), map.get("size")); + checkEqual(attrs.isHidden(), map.get("hidden")); + } + + static void doTests(Path dir) throws IOException { + Path file = dir.resolve("foo").createFile(); + FileStore store = file.getFileStore(); + try { + checkBasicAttributes(file, + Attributes.readBasicFileAttributes(file)); + + if (store.supportsFileAttributeView("posix")) + checkPosixAttributes(file, + Attributes.readPosixFileAttributes(file)); + + if (store.supportsFileAttributeView("unix")) + checkUnixAttributes(file); + + if (store.supportsFileAttributeView("dos")) + checkDosAttributes(file, + Attributes.readDosFileAttributes(file)); + } finally { + file.delete(); + } + } + + + public static void main(String[] args) throws IOException { + Path dir = TestUtil.createTemporaryDirectory(); + try { + doTests(dir); + } finally { + TestUtil.removeAll(dir); + } + } +} diff --git a/test/java/nio/file/attribute/BasicFileAttributeView/Basic.java b/test/java/nio/file/attribute/BasicFileAttributeView/Basic.java new file mode 100644 index 0000000000000000000000000000000000000000..1cc192f2a4502b1acb561a91ceeba0f631974e6c --- /dev/null +++ b/test/java/nio/file/attribute/BasicFileAttributeView/Basic.java @@ -0,0 +1,150 @@ +/* + * Copyright 2008-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. + * + * 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. + */ + +/* @test + * @bug 4313887 + * @summary Unit test for java.nio.file.attribute.BasicFileAttributeView + * @library ../.. + */ + +import java.nio.file.*; +import java.nio.file.attribute.*; +import java.util.*; +import java.util.concurrent.TimeUnit; +import java.io.*; + +public class Basic { + + static void check(boolean okay, String msg) { + if (!okay) + throw new RuntimeException(msg); + } + + static void checkAttributesOfDirectory(Path dir) + throws IOException + { + BasicFileAttributes attrs = Attributes.readBasicFileAttributes(dir); + check(attrs.isDirectory(), "is a directory"); + check(!attrs.isRegularFile(), "is not a regular file"); + check(!attrs.isSymbolicLink(), "is not a link"); + check(!attrs.isOther(), "is not other"); + check(attrs.linkCount() >= 1, "should be at least 1"); + + // last-modified-time should match java.io.File + if (attrs.resolution() == TimeUnit.MILLISECONDS) { + File f = new File(dir.toString()); + check(f.lastModified() == attrs.lastModifiedTime(), + "last-modified time should be the same"); + } + } + + static void checkAttributesOfFile(Path dir, Path file) + throws IOException + { + BasicFileAttributes attrs = Attributes.readBasicFileAttributes(file); + check(attrs.isRegularFile(), "is a regular file"); + check(!attrs.isDirectory(), "is not a directory"); + check(!attrs.isSymbolicLink(), "is not a link"); + check(!attrs.isOther(), "is not other"); + check(attrs.linkCount() >= 1, "should be at least 1"); + + // size and last-modified-time should match java.io.File + File f = new File(file.toString()); + check(f.length() == attrs.size(), "size should be the same"); + if (attrs.resolution() == TimeUnit.MILLISECONDS) { + check(f.lastModified() == attrs.lastModifiedTime(), + "last-modified time should be the same"); + } + + // copy last-modified time and file create time from directory to file, + // re-read attribtues, and check they match + BasicFileAttributeView view = + file.getFileAttributeView(BasicFileAttributeView.class); + BasicFileAttributes dirAttrs = Attributes.readBasicFileAttributes(dir); + view.setTimes(dirAttrs.lastModifiedTime(), null, null, dirAttrs.resolution()); + if (dirAttrs.creationTime() != -1L) { + view.setTimes(null, null, dirAttrs.creationTime(), dirAttrs.resolution()); + } + attrs = view.readAttributes(); + check(attrs.lastModifiedTime() == dirAttrs.lastModifiedTime(), + "last-modified time should be equal"); + if (dirAttrs.creationTime() != -1L) { + check(attrs.creationTime() == dirAttrs.creationTime(), + "create time should be the same"); + } + + // security tests + check (!(attrs instanceof PosixFileAttributes), + "should not be able to cast to PosixFileAttributes"); + } + + static void checkAttributesOfLink(Path link) + throws IOException + { + BasicFileAttributes attrs = Attributes + .readBasicFileAttributes(link, LinkOption.NOFOLLOW_LINKS); + check(attrs.isSymbolicLink(), "is a link"); + check(!attrs.isDirectory(), "is a directory"); + check(!attrs.isRegularFile(), "is not a regular file"); + check(!attrs.isOther(), "is not other"); + check(attrs.linkCount() >= 1, "should be at least 1"); + } + + static void attributeReadWriteTests(Path dir) + throws IOException + { + // create file + Path file = dir.resolve("foo"); + OutputStream out = file.newOutputStream(); + try { + out.write("this is not an empty file".getBytes("UTF-8")); + } finally { + out.close(); + } + + // check attributes of directory and file + checkAttributesOfDirectory(dir); + checkAttributesOfFile(dir, file); + + // symbolic links may be supported + Path link = dir.resolve("link"); + try { + link.createSymbolicLink( file ); + } catch (UnsupportedOperationException x) { + return; + } catch (IOException x) { + return; + } + checkAttributesOfLink(link); + } + + public static void main(String[] args) throws IOException { + // create temporary directory to run tests + Path dir = TestUtil.createTemporaryDirectory(); + try { + attributeReadWriteTests(dir); + } finally { + TestUtil.removeAll(dir); + } + } +} diff --git a/test/java/nio/file/attribute/DosFileAttributeView/Basic.java b/test/java/nio/file/attribute/DosFileAttributeView/Basic.java new file mode 100644 index 0000000000000000000000000000000000000000..3c8a296188b7b70c2a7ce039c83aaa1c4bab8636 --- /dev/null +++ b/test/java/nio/file/attribute/DosFileAttributeView/Basic.java @@ -0,0 +1,155 @@ +/* + * Copyright 2008-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. + * + * 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. + */ + +/* @test + * @bug 4313887 + * @summary Unit test for java.nio.file.attribute.DosFileAttributeView + * @library ../.. + */ + +import java.nio.file.*; +import static java.nio.file.LinkOption.*; +import java.nio.file.attribute.*; +import java.util.*; +import java.io.IOException; + +public class Basic { + + static void check(boolean okay) { + if (!okay) + throw new RuntimeException("Test failed"); + } + + // exercise each setter/getter method, leaving all attributes unset + static void testAttributes(DosFileAttributeView view) throws IOException { + view.setReadOnly(true); + check(view.readAttributes().isReadOnly()); + view.setReadOnly(false); + check(!view.readAttributes().isReadOnly()); + view.setHidden(true); + check(view.readAttributes().isHidden()); + view.setHidden(false); + check(!view.readAttributes().isHidden()); + view.setArchive(true); + check(view.readAttributes().isArchive()); + view.setArchive(false); + check(!view.readAttributes().isArchive()); + view.setSystem(true); + check(view.readAttributes().isSystem()); + view.setSystem(false); + check(!view.readAttributes().isSystem()); + } + + // set the value of all attributes + static void setAll(DosFileAttributeView view, boolean value) + throws IOException + { + view.setReadOnly(value); + view.setHidden(value); + view.setArchive(value); + view.setSystem(value); + } + + // read and write FAT attributes + static void readWriteTests(Path dir) throws IOException { + + // create "foo" and test that we can read/write each FAT attribute + Path file = dir.resolve("foo"); + file.newOutputStream().close(); + try { + testAttributes(file + .getFileAttributeView(DosFileAttributeView.class)); + + // Following tests use a symbolic link so skip if not supported + if (!TestUtil.supportsLinks(dir)) + return; + + Path link = dir.resolve("link").createSymbolicLink(file); + + // test following links + testAttributes(link + .getFileAttributeView(DosFileAttributeView.class)); + + // test not following links + try { + try { + testAttributes(link + .getFileAttributeView(DosFileAttributeView.class, NOFOLLOW_LINKS)); + } catch (IOException x) { + // access to link attributes not supported + return; + } + + // set all attributes on link + // run test on target of link (which leaves them all un-set) + // check that attributes of link remain all set + setAll(link + .getFileAttributeView(DosFileAttributeView.class, NOFOLLOW_LINKS), true); + testAttributes(link + .getFileAttributeView(DosFileAttributeView.class)); + DosFileAttributes attrs = Attributes.readDosFileAttributes(link, NOFOLLOW_LINKS); + check(attrs.isReadOnly()); + check(attrs.isHidden()); + check(attrs.isArchive()); + check(attrs.isSystem()); + setAll(link + .getFileAttributeView(DosFileAttributeView.class, NOFOLLOW_LINKS), false); + + // set all attributes on target + // run test on link (which leaves them all un-set) + // check that attributes of target remain all set + setAll(link + .getFileAttributeView(DosFileAttributeView.class), true); + testAttributes(link + .getFileAttributeView(DosFileAttributeView.class, NOFOLLOW_LINKS)); + attrs = Attributes.readDosFileAttributes(link); + check(attrs.isReadOnly()); + check(attrs.isHidden()); + check(attrs.isArchive()); + check(attrs.isSystem()); + setAll(link + .getFileAttributeView(DosFileAttributeView.class), false); + } finally { + TestUtil.deleteUnchecked(link); + } + } finally { + TestUtil.deleteUnchecked(file); + } + } + + public static void main(String[] args) throws IOException { + // create temporary directory to run tests + Path dir = TestUtil.createTemporaryDirectory(); + + try { + // skip test if DOS file attributes not supported + if (!dir.getFileStore().supportsFileAttributeView("dos")) { + System.out.println("DOS file attribute not supported."); + return; + } + readWriteTests(dir); + } finally { + TestUtil.removeAll(dir); + } + } +} diff --git a/test/java/nio/file/attribute/FileStoreAttributeView/Basic.java b/test/java/nio/file/attribute/FileStoreAttributeView/Basic.java new file mode 100644 index 0000000000000000000000000000000000000000..993e8c1ddec2b0d697fe42ed3d942e143a94b08f --- /dev/null +++ b/test/java/nio/file/attribute/FileStoreAttributeView/Basic.java @@ -0,0 +1,171 @@ +/* + * Copyright 2008-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. + * + * 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. + */ + +/* @test + * @bug 4313887 + * @summary Unit test for java.nio.file.attribute.FileStoreAttributeView + * @library ../.. + */ + +import java.nio.file.*; +import java.nio.file.attribute.*; +import java.io.File; +import java.io.IOException; +import java.util.*; + +/** + * Simple unit test for FileStoreAttributeView that checks that the disk space + * attribtues are "close" to the equivalent values reported by java.io.File. + */ + +public class Basic { + + static final long K = 1024L; + static final long G = 1024L * 1024L * 1024L; + + /** + * Print out the disk space information for the given file system + */ + static void printFileStore(FileStore fs) throws IOException { + FileStoreSpaceAttributeView view = + fs.getFileStoreAttributeView(FileStoreSpaceAttributeView.class); + FileStoreSpaceAttributes attrs = view.readAttributes(); + + long total = attrs.totalSpace() / K; + long used = (attrs.totalSpace() - attrs.unallocatedSpace()) / K; + long avail = attrs.usableSpace() / K; + + String s = fs.toString(); + if (s.length() > 20) { + System.out.println(s); + s = ""; + } + System.out.format("%-20s %12d %12d %12d\n", s, total, used, avail); + } + + /** + * Check that two values are within 1GB of each other + */ + static void checkWithin1GB(long value1, long value2) { + long diff = Math.abs(value1 - value2); + if (diff > G) + throw new RuntimeException("values differ by more than 1GB"); + } + + /** + * Check disk space on the file system of the given file + */ + static void checkSpace(Path file) throws IOException { + System.out.println(" -- check space -- "); + System.out.println(file); + + FileStore fs = file.getFileStore(); + System.out.format("Filesystem: %s\n", fs); + + // get values reported by java.io.File + File f = new File(file.toString()); + long total = f.getTotalSpace(); + long free = f.getFreeSpace(); + long usable = f.getUsableSpace(); + System.out.println("java.io.File"); + System.out.format(" Total: %d\n", total); + System.out.format(" Free: %d\n", free); + System.out.format(" Usable: %d\n", usable); + + // get values reported by the FileStoreSpaceAttributeView + FileStoreSpaceAttributes attrs = fs + .getFileStoreAttributeView(FileStoreSpaceAttributeView.class) + .readAttributes(); + System.out.println("java.nio.file.FileStoreSpaceAttributeView:"); + System.out.format(" Total: %d\n", attrs.totalSpace()); + System.out.format(" Free: %d\n", attrs.unallocatedSpace()); + System.out.format(" Usable: %d\n", attrs.usableSpace()); + + // check values are "close" + checkWithin1GB(total, attrs.totalSpace()); + checkWithin1GB(free, attrs.unallocatedSpace()); + checkWithin1GB(usable, attrs.usableSpace()); + + // get values by name (and in bulk) + FileStoreAttributeView view = fs.getFileStoreAttributeView("space"); + checkWithin1GB(total, (Long)view.getAttribute("totalSpace")); + checkWithin1GB(free, (Long)view.getAttribute("unallocatedSpace")); + checkWithin1GB(usable, (Long)view.getAttribute("usableSpace")); + Map<String,?> map = view.readAttributes("*"); + checkWithin1GB(total, (Long)map.get("totalSpace")); + checkWithin1GB(free, (Long)map.get("unallocatedSpace")); + checkWithin1GB(usable, (Long)map.get("usableSpace")); + map = view.readAttributes("totalSpace", "unallocatedSpace", "usableSpace"); + checkWithin1GB(total, (Long)map.get("totalSpace")); + checkWithin1GB(free, (Long)map.get("unallocatedSpace")); + checkWithin1GB(usable, (Long)map.get("usableSpace")); + } + + /** + * Check (Windows-specific) volume attributes + */ + static void checkVolumeAttributes() throws IOException { + System.out.println(" -- volumes -- "); + for (FileStore store: FileSystems.getDefault().getFileStores()) { + FileStoreAttributeView view = store.getFileStoreAttributeView("volume"); + if (view == null) + continue; + Map<String,?> attrs = view.readAttributes("*"); + int vsn = (Integer)attrs.get("vsn"); + boolean compressed = (Boolean)attrs.get("compressed"); + boolean removable = (Boolean)attrs.get("removable"); + boolean cdrom = (Boolean)attrs.get("cdrom"); + String type; + if (removable) type = "removable"; + else if (cdrom) type = "cdrom"; + else type = "unknown"; + System.out.format("%s (%s) vsn:%x compressed:%b%n", store.name(), + type, vsn, compressed); + } + + } + + public static void main(String[] args) throws IOException { + // print out the disk space information for all file systems + FileSystem fs = FileSystems.getDefault(); + for (FileStore store: fs.getFileStores()) { + printFileStore(store); + } + + Path dir = TestUtil.createTemporaryDirectory(); + try { + // check space using directory + checkSpace(dir); + + // check space using file + Path file = dir.resolve("foo").createFile(); + checkSpace(file); + + // volume attributes (Windows specific) + checkVolumeAttributes(); + + } finally { + TestUtil.removeAll(dir); + } + } +} diff --git a/test/java/nio/file/attribute/PosixFileAttributeView/Basic.java b/test/java/nio/file/attribute/PosixFileAttributeView/Basic.java new file mode 100644 index 0000000000000000000000000000000000000000..2ee059bb95d1c671929db2584b7a9ea6bff61b6f --- /dev/null +++ b/test/java/nio/file/attribute/PosixFileAttributeView/Basic.java @@ -0,0 +1,398 @@ +/* + * Copyright 2008-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. + * + * 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. + */ + +/* @test + * @bug 4313887 + * @summary Unit test for java.nio.file.attribute.PosixFileAttributeView + * @library ../.. + */ + +import java.nio.file.*; +import static java.nio.file.LinkOption.*; +import java.nio.file.attribute.*; +import java.io.IOException; +import java.util.*; + +/** + * Unit test for PosixFileAttributeView, passing silently if this attribute + * view is not available. + */ + +public class Basic { + + /** + * Use view to update permission to the given mode and check that the + * permissions have been updated. + */ + static void testPermissions(PosixFileAttributeView view, String mode) + throws IOException + { + System.out.format("change mode: %s\n", mode); + Set<PosixFilePermission> perms = PosixFilePermissions.fromString(mode); + + // change permissions and re-read them. + view.setPermissions(perms); + Set<PosixFilePermission> current = view.readAttributes().permissions(); + if (!current.equals(perms)) { + throw new RuntimeException("Actual permissions: " + + PosixFilePermissions.toString(current) + ", expected: " + + PosixFilePermissions.toString(perms)); + } + + // repeat test using setAttribute/getAttribute + view.setAttribute("permissions", perms); + current = (Set<PosixFilePermission>)view.getAttribute("permissions"); + if (!current.equals(perms)) { + throw new RuntimeException("Actual permissions: " + + PosixFilePermissions.toString(current) + ", expected: " + + PosixFilePermissions.toString(perms)); + } + } + + /** + * Check that the actual permissions of a file match or make it more + * secure than requested + */ + static void checkSecure(Set<PosixFilePermission> requested, + Set<PosixFilePermission> actual) + { + for (PosixFilePermission perm: actual) { + if (!requested.contains(perm)) { + throw new RuntimeException("Actual permissions: " + + PosixFilePermissions.toString(actual) + ", requested: " + + PosixFilePermissions.toString(requested) + + " - file is less secure than requested"); + } + } + } + + /** + * Create file with given mode and check that the file is created with a + * mode that is not less secure + */ + static void createWithPermissions(Path file, + String mode) + throws IOException + { + Set<PosixFilePermission> requested = PosixFilePermissions.fromString(mode); + FileAttribute<Set<PosixFilePermission>> attr = + PosixFilePermissions.asFileAttribute(requested); + System.out.format("create file with mode: %s\n", mode); + + EnumSet<StandardOpenOption> options = EnumSet.of(StandardOpenOption.CREATE_NEW, + StandardOpenOption.WRITE); + file.newOutputStream(options, attr).close(); + try { + checkSecure(requested, file + .getFileAttributeView(PosixFileAttributeView.class) + .readAttributes() + .permissions()); + } finally { + file.delete(false); + } + + System.out.format("create directory with mode: %s\n", mode); + file.createDirectory(attr); + try { + checkSecure(requested, file + .getFileAttributeView(PosixFileAttributeView.class) + .readAttributes() + .permissions()); + } finally { + file.delete(false); + } + } + + /** + * Test the setPermissions/permissions methods. + */ + static void permissionTests(Path dir) + throws IOException + { + System.out.println("-- Permission Tests --"); + + // create file and test updating and reading its permissions + Path file = dir.resolve("foo"); + System.out.format("create %s\n", file); + file.newOutputStream().close(); + try { + // get initial permissions so that we can restore them later + PosixFileAttributeView view = file + .getFileAttributeView(PosixFileAttributeView.class); + Set<PosixFilePermission> save = view.readAttributes() + .permissions(); + + // test various modes + try { + testPermissions(view, "---------"); + testPermissions(view, "r--------"); + testPermissions(view, "-w-------"); + testPermissions(view, "--x------"); + testPermissions(view, "rwx------"); + testPermissions(view, "---r-----"); + testPermissions(view, "----w----"); + testPermissions(view, "-----x---"); + testPermissions(view, "---rwx---"); + testPermissions(view, "------r--"); + testPermissions(view, "-------w-"); + testPermissions(view, "--------x"); + testPermissions(view, "------rwx"); + testPermissions(view, "r--r-----"); + testPermissions(view, "r--r--r--"); + testPermissions(view, "rw-rw----"); + testPermissions(view, "rwxrwx---"); + testPermissions(view, "rw-rw-r--"); + testPermissions(view, "r-xr-x---"); + testPermissions(view, "r-xr-xr-x"); + testPermissions(view, "rwxrwxrwx"); + } finally { + view.setPermissions(save); + } + } finally { + file.delete(false); + } + + // create link (to file that doesn't exist) and test reading of + // permissions + if (TestUtil.supportsLinks(dir)) { + Path link = dir.resolve("link"); + System.out.format("create link %s\n", link); + link.createSymbolicLink(file); + try { + PosixFileAttributes attrs = Attributes + .readPosixFileAttributes(link, NOFOLLOW_LINKS); + if (!attrs.isSymbolicLink()) { + throw new RuntimeException("not a link"); + } + } finally { + link.delete(false); + } + } + + System.out.println("OKAY"); + } + + /** + * Test creating a file and directory with initial permissios + */ + static void createTests(Path dir) + throws IOException + { + System.out.println("-- Create Tests --"); + + Path file = dir.resolve("foo"); + + createWithPermissions(file, "---------"); + createWithPermissions(file, "r--------"); + createWithPermissions(file, "-w-------"); + createWithPermissions(file, "--x------"); + createWithPermissions(file, "rwx------"); + createWithPermissions(file, "---r-----"); + createWithPermissions(file, "----w----"); + createWithPermissions(file, "-----x---"); + createWithPermissions(file, "---rwx---"); + createWithPermissions(file, "------r--"); + createWithPermissions(file, "-------w-"); + createWithPermissions(file, "--------x"); + createWithPermissions(file, "------rwx"); + createWithPermissions(file, "r--r-----"); + createWithPermissions(file, "r--r--r--"); + createWithPermissions(file, "rw-rw----"); + createWithPermissions(file, "rwxrwx---"); + createWithPermissions(file, "rw-rw-r--"); + createWithPermissions(file, "r-xr-x---"); + createWithPermissions(file, "r-xr-xr-x"); + createWithPermissions(file, "rwxrwxrwx"); + + System.out.println("OKAY"); + } + + /** + * Test setOwner/setGroup methods - this test simply exercises the + * methods to avoid configuration. + */ + static void ownerTests(Path dir) + throws IOException + { + System.out.println("-- Owner Tests --"); + + Path file = dir.resolve("gus"); + System.out.format("create %s\n", file); + + file.newOutputStream().close(); + try { + + // read attributes of directory to get owner/group + PosixFileAttributeView view = file + .getFileAttributeView(PosixFileAttributeView.class); + PosixFileAttributes attrs = view.readAttributes(); + + // set to existing owner/group + view.setOwner(attrs.owner()); + view.setGroup(attrs.group()); + + // repeat test using setAttribute + Map<String,?> map = view.readAttributes("owner","group"); + view.setAttribute("owner", map.get("owner")); + view.setAttribute("group", map.get("group")); + + } finally { + file.delete(false); + } + + System.out.println("OKAY"); + } + + /** + * Test the lookupPrincipalByName/lookupPrincipalByGroupName methods + */ + static void lookupPrincipalTests(Path dir) + throws IOException + { + System.out.println("-- Lookup UserPrincipal Tests --"); + + UserPrincipalLookupService lookupService = dir.getFileSystem() + .getUserPrincipalLookupService(); + + // read attributes of directory to get owner/group + PosixFileAttributes attrs = Attributes.readPosixFileAttributes(dir); + + // lookup owner and check it matches file's owner + System.out.format("lookup: %s\n", attrs.owner().getName()); + try { + UserPrincipal owner = lookupService.lookupPrincipalByName(attrs.owner().getName()); + if (owner instanceof GroupPrincipal) + throw new RuntimeException("owner is a group?"); + if (!owner.equals(attrs.owner())) + throw new RuntimeException("owner different from file owner"); + } catch (UserPrincipalNotFoundException x) { + System.out.println("user not found - test skipped"); + } + + // lookup group and check it matches file's group-owner + System.out.format("lookup group: %s\n", attrs.group().getName()); + try { + GroupPrincipal group = lookupService.lookupPrincipalByGroupName(attrs.group().getName()); + if (!group.equals(attrs.group())) + throw new RuntimeException("group different from file group-owner"); + } catch (UserPrincipalNotFoundException x) { + System.out.println("group not found - test skipped"); + } + + // test that UserPrincipalNotFoundException is thrown + String invalidPrincipal = "scumbag99"; + try { + System.out.format("lookup: %s\n", invalidPrincipal); + lookupService.lookupPrincipalByName(invalidPrincipal); + throw new RuntimeException("'" + invalidPrincipal + "' is a valid user?"); + } catch (UserPrincipalNotFoundException x) { + } + try { + System.out.format("lookup group: %s\n", invalidPrincipal); + lookupService.lookupPrincipalByGroupName("idonotexist"); + throw new RuntimeException("'" + invalidPrincipal + "' is a valid group?"); + } catch (UserPrincipalNotFoundException x) { + } + System.out.println("OKAY"); + } + + /** + * Test various exceptions are thrown as expected + */ + @SuppressWarnings("unchecked") + static void exceptionsTests(Path dir) + throws IOException + { + System.out.println("-- Exceptions --"); + + PosixFileAttributeView view = dir + .getFileAttributeView(PosixFileAttributeView.class); + + // NullPointerException + try { + view.setOwner(null); + throw new RuntimeException("NullPointerException not thrown"); + } catch (NullPointerException x) { + } + try { + view.setGroup(null); + throw new RuntimeException("NullPointerException not thrown"); + } catch (NullPointerException x) { + } + + UserPrincipalLookupService lookupService = dir.getFileSystem() + .getUserPrincipalLookupService(); + try { + lookupService.lookupPrincipalByName(null); + throw new RuntimeException("NullPointerException not thrown"); + } catch (NullPointerException x) { + } + try { + lookupService.lookupPrincipalByGroupName(null); + throw new RuntimeException("NullPointerException not thrown"); + } catch (NullPointerException x) { + } + try { + view.setPermissions(null); + throw new RuntimeException("NullPointerException not thrown"); + } catch (NullPointerException x) { + } + try { + Set<PosixFilePermission> perms = new HashSet<PosixFilePermission>(); + perms.add(null); + view.setPermissions(perms); + throw new RuntimeException("NullPointerException not thrown"); + } catch (NullPointerException x) { + } + + // ClassCastException + try { + Set perms = new HashSet(); // raw type + perms.add(new Object()); + view.setPermissions(perms); + throw new RuntimeException("ClassCastException not thrown"); + } catch (ClassCastException x) { + } + + System.out.println("OKAY"); + } + + public static void main(String[] args) throws IOException { + Path dir = TestUtil.createTemporaryDirectory(); + try { + if (!dir.getFileStore().supportsFileAttributeView("posix")) { + System.out.println("PosixFileAttributeView not supported"); + return; + } + + permissionTests(dir); + createTests(dir); + ownerTests(dir); + lookupPrincipalTests(dir); + exceptionsTests(dir); + + } finally { + TestUtil.removeAll(dir); + } + } +} diff --git a/test/java/nio/file/attribute/UserDefinedFileAttributeView/Basic.java b/test/java/nio/file/attribute/UserDefinedFileAttributeView/Basic.java new file mode 100644 index 0000000000000000000000000000000000000000..ffdb5b86e8971698ffebd2b2456d75b2196820a7 --- /dev/null +++ b/test/java/nio/file/attribute/UserDefinedFileAttributeView/Basic.java @@ -0,0 +1,273 @@ +/* + * Copyright 2008-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. + * + * 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. + */ + +/* @test + * @bug 4313887 + * @summary Unit test for java.nio.file.attribute.UserDefinedFileAttributeView + * @library ../.. + */ + +import java.nio.ByteBuffer; +import java.nio.charset.Charset; +import java.nio.file.*; +import static java.nio.file.LinkOption.*; +import java.nio.file.attribute.*; +import java.util.Arrays; +import java.util.Map; +import java.util.Random; +import java.io.IOException; + +public class Basic { + + private static Random rand = new Random(); + + private static final String ATTR_NAME = "mime_type"; + private static final String ATTR_VALUE = "text/plain"; + private static final String ATTR_VALUE2 = "text/html"; + + static interface Task { + void run() throws Exception; + } + + static void tryCatch(Class<? extends Throwable> ex, Task task) { + boolean caught = false; + try { + task.run(); + } catch (Throwable x) { + if (ex.isAssignableFrom(x.getClass())) { + caught = true; + } else { + throw new RuntimeException(x); + } + } + if (!caught) + throw new RuntimeException(ex.getName() + " expected"); + } + + static void expectNullPointerException(Task task) { + tryCatch(NullPointerException.class, task); + } + + static boolean hasAttribute(UserDefinedFileAttributeView view, String attr) + throws IOException + { + for (String name: view.list()) { + if (name.equals(ATTR_NAME)) + return true; + } + return false; + } + + static void test(Path file, LinkOption... options) throws IOException { + final UserDefinedFileAttributeView view = file + .getFileAttributeView(UserDefinedFileAttributeView.class, options); + ByteBuffer buf = rand.nextBoolean() ? + ByteBuffer.allocate(100) : ByteBuffer.allocateDirect(100); + + // Test: write + buf.put(ATTR_VALUE.getBytes()).flip(); + int size = buf.remaining(); + int nwrote = view.write(ATTR_NAME, buf); + if (nwrote != size) + throw new RuntimeException("Unexpected number of bytes written"); + + // Test: size + if (view.size(ATTR_NAME) != size) + throw new RuntimeException("Unexpected size"); + + // Test: read + buf.clear(); + int nread = view.read(ATTR_NAME, buf); + if (nread != size) + throw new RuntimeException("Unexpected number of bytes read"); + buf.flip(); + String value = Charset.defaultCharset().decode(buf).toString(); + if (!value.equals(ATTR_VALUE)) + throw new RuntimeException("Unexpected attribute value"); + + // Test: read with insufficient space + tryCatch(IOException.class, new Task() { + public void run() throws IOException { + view.read(ATTR_NAME, ByteBuffer.allocateDirect(1)); + }}); + + // Test: replace value + buf.clear(); + buf.put(ATTR_VALUE2.getBytes()).flip(); + size = buf.remaining(); + view.write(ATTR_NAME, buf); + if (view.size(ATTR_NAME) != size) + throw new RuntimeException("Unexpected size"); + + // Test: list + if (!hasAttribute(view, ATTR_NAME)) + throw new RuntimeException("Attribute name not in list"); + + // Test: delete + view.delete(ATTR_NAME); + if (hasAttribute(view, ATTR_NAME)) + throw new RuntimeException("Attribute name in list"); + + // Test: dynamic access + byte[] valueAsBytes = ATTR_VALUE.getBytes(); + view.setAttribute(ATTR_NAME, valueAsBytes); + byte[] actualAsBytes = (byte[])view.getAttribute(ATTR_NAME); + if (!Arrays.equals(valueAsBytes, actualAsBytes)) + throw new RuntimeException("Unexpected attribute value"); + Map<String,?> map = view.readAttributes(ATTR_NAME); + if (!Arrays.equals(valueAsBytes, (byte[])map.get(ATTR_NAME))) + throw new RuntimeException("Unexpected attribute value"); + map = view.readAttributes(ATTR_NAME, "*"); + if (!Arrays.equals(valueAsBytes, (byte[])map.get(ATTR_NAME))) + throw new RuntimeException("Unexpected attribute value"); + map = view.readAttributes("DoesNotExist"); + if (!map.isEmpty()) + throw new RuntimeException("Map expected to be empty"); + } + + static void miscTests(Path file) throws IOException { + final UserDefinedFileAttributeView view = file + .getFileAttributeView(UserDefinedFileAttributeView.class); + view.write(ATTR_NAME, ByteBuffer.wrap(ATTR_VALUE.getBytes())); + + // NullPointerException + final ByteBuffer buf = ByteBuffer.allocate(100); + + expectNullPointerException(new Task() { + public void run() throws IOException { + view.read(null, buf); + }}); + expectNullPointerException(new Task() { + public void run() throws IOException { + view.read(ATTR_NAME, null); + }}); + expectNullPointerException(new Task() { + public void run() throws IOException { + view.write(null, buf); + }}); + expectNullPointerException(new Task() { + public void run() throws IOException { + view.write(ATTR_NAME, null); + }}); + expectNullPointerException(new Task() { + public void run() throws IOException { + view.size(null); + }}); + expectNullPointerException(new Task() { + public void run() throws IOException { + view.delete(null); + }}); + expectNullPointerException(new Task() { + public void run() throws IOException { + view.getAttribute(null); + }}); + expectNullPointerException(new Task() { + public void run() throws IOException { + view.setAttribute(ATTR_NAME, null); + }}); + expectNullPointerException(new Task() { + public void run() throws IOException { + view.setAttribute(null, new byte[0]); + }}); + expectNullPointerException(new Task() { + public void run() throws IOException { + view.readAttributes(null); + }}); + expectNullPointerException(new Task() { + public void run() throws IOException { + view.readAttributes("*", (String[])null); + }}); + expectNullPointerException(new Task() { + public void run() throws IOException { + view.readAttributes("*", ATTR_NAME, null); + }}); + + // Read-only buffer + tryCatch(IllegalArgumentException.class, new Task() { + public void run() throws IOException { + ByteBuffer buf = ByteBuffer.wrap(ATTR_VALUE.getBytes()).asReadOnlyBuffer(); + view.write(ATTR_NAME, buf); + buf.flip(); + view.read(ATTR_NAME, buf); + }}); + + // Zero bytes remaining + tryCatch(IOException.class, new Task() { + public void run() throws IOException { + ByteBuffer buf = buf = ByteBuffer.allocateDirect(100); + buf.position(buf.capacity()); + view.read(ATTR_NAME, buf); + }}); + } + + public static void main(String[] args) throws IOException { + // create temporary directory to run tests + Path dir = TestUtil.createTemporaryDirectory(); + try { + if (!dir.getFileStore().supportsFileAttributeView("xattr")) { + System.out.println("UserDefinedFileAttributeView not supported - skip test"); + return; + } + + // test access to user defined attributes of regular file + Path file = dir.resolve("foo.html").createFile(); + try { + test(file); + } finally { + file.delete(); + } + + // test access to user define attributes of directory + file = dir.resolve("foo").createDirectory(); + try { + test(file); + } finally { + file.delete(); + } + + // test access to user defined attributes of sym link + if (TestUtil.supportsLinks(dir)) { + Path target = dir.resolve("doesnotexist"); + Path link = dir.resolve("link").createSymbolicLink(target); + try { + test(link, NOFOLLOW_LINKS); + } catch (IOException x) { + // access to attributes of sym link may not be supported + } finally { + link.delete(); + } + } + + // misc. tests + try { + file = dir.resolve("foo.txt").createFile(); + miscTests(dir); + } finally { + file.delete(); + } + + } finally { + TestUtil.removeAll(dir); + } + } + } diff --git a/test/java/nio/file/spi/SetDefaultProvider.java b/test/java/nio/file/spi/SetDefaultProvider.java new file mode 100644 index 0000000000000000000000000000000000000000..fa600b05c9ba704b733fa802380bf5f9699e38ea --- /dev/null +++ b/test/java/nio/file/spi/SetDefaultProvider.java @@ -0,0 +1,44 @@ +/* + * Copyright 2008-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. + * + * 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. + */ + +/* @test + * @bug 4313887 + * @summary Unit test for java.nio.file.spi.FileSystemProvider + * @build TestProvider SetDefaultProvider + * @run main/othervm -Djava.nio.file.spi.DefaultFileSystemProvider=TestProvider SetDefaultProvider + */ + +import java.nio.file.*; +import java.nio.file.spi.*; + +public class SetDefaultProvider { + public static void main(String[] args) throws Exception { + Class<?> c = FileSystems.getDefault().provider().getClass(); + + Class<?> expected = Class.forName("TestProvider", false, + ClassLoader.getSystemClassLoader()); + + if (c != expected) + throw new RuntimeException(); + } +} diff --git a/test/java/nio/file/spi/TestProvider.java b/test/java/nio/file/spi/TestProvider.java new file mode 100644 index 0000000000000000000000000000000000000000..a6868acb63cf70bb5d615b2768d4fe77eeeafbe5 --- /dev/null +++ b/test/java/nio/file/spi/TestProvider.java @@ -0,0 +1,128 @@ +/* + * Copyright 2008-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. + * + * 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. + */ + +import java.nio.file.spi.FileSystemProvider; +import java.nio.file.*; +import java.nio.file.attribute.*; +import java.net.URI; +import java.util.*; +import java.io.IOException; + +public class TestProvider extends FileSystemProvider { + + private final FileSystem theFileSystem; + + public TestProvider(FileSystemProvider defaultProvider) { + theFileSystem = new TestFileSystem(this); + + } + + @Override + public String getScheme() { + return "file"; + } + + @Override + public FileSystem newFileSystem(URI uri, Map<String,?> env) { + throw new RuntimeException("not implemented"); + } + + @Override + public FileSystem getFileSystem(URI uri) { + return theFileSystem; + } + + @Override + public Path getPath(URI uri) { + throw new RuntimeException("not implemented"); + } + + static class TestFileSystem extends FileSystem { + private final TestProvider provider; + + TestFileSystem(TestProvider provider) { + this.provider = provider; + } + + @Override + public FileSystemProvider provider() { + return provider; + } + + @Override + public void close() throws IOException { + throw new RuntimeException("not implemented"); + } + + @Override + public boolean isOpen() { + throw new RuntimeException("not implemented"); + } + + @Override + public boolean isReadOnly() { + throw new RuntimeException("not implemented"); + } + + @Override + public String getSeparator() { + throw new RuntimeException("not implemented"); + } + + @Override + public Iterable<Path> getRootDirectories() { + throw new RuntimeException("not implemented"); + } + + @Override + public Iterable<FileStore> getFileStores() { + throw new RuntimeException("not implemented"); + } + + @Override + public Set<String> supportedFileAttributeViews() { + throw new RuntimeException("not implemented"); + } + + @Override + public Path getPath(String path) { + throw new RuntimeException("not implemented"); + } + + @Override + public PathMatcher getPathMatcher(String syntaxAndPattern) { + throw new RuntimeException("not implemented"); + } + + @Override + public UserPrincipalLookupService getUserPrincipalLookupService() { + throw new RuntimeException("not implemented"); + } + + @Override + public WatchService newWatchService() throws IOException { + throw new RuntimeException("not implemented"); + } + } + +} diff --git a/test/java/rmi/activation/rmidViaInheritedChannel/InheritedChannelNotServerSocket.java b/test/java/rmi/activation/rmidViaInheritedChannel/InheritedChannelNotServerSocket.java index 301c6a66f4cbd2f13f92f52fdf532df81993969b..0faa5ed7ea6a56867b252aaad58ce105ebc4a1ed 100644 --- a/test/java/rmi/activation/rmidViaInheritedChannel/InheritedChannelNotServerSocket.java +++ b/test/java/rmi/activation/rmidViaInheritedChannel/InheritedChannelNotServerSocket.java @@ -22,7 +22,7 @@ */ /* @test - * @bug 6261402 + * @bug 6261402 6824141 * @summary If rmid has an inherited channel that is not a server * socket (such as it if was started using rsh/rcmd), then it should * function normally. @@ -37,6 +37,7 @@ import java.io.IOException; import java.net.Socket; +import java.net.ProtocolFamily; import java.nio.channels.Channel; import java.nio.channels.DatagramChannel; import java.nio.channels.Pipe; @@ -137,6 +138,12 @@ public class InheritedChannelNotServerSocket { return provider.openDatagramChannel(); } + public DatagramChannel openDatagramChannel(ProtocolFamily family) + throws IOException + { + return provider.openDatagramChannel(family); + } + public Pipe openPipe() throws IOException { return provider.openPipe(); } diff --git a/test/java/rmi/activation/rmidViaInheritedChannel/RmidViaInheritedChannel.java b/test/java/rmi/activation/rmidViaInheritedChannel/RmidViaInheritedChannel.java index c37dd6250c526c333849d186a6898c9a55df5d40..79265dd8e4a6ce4e21b22f3c2d5a7a80a7e4b334 100644 --- a/test/java/rmi/activation/rmidViaInheritedChannel/RmidViaInheritedChannel.java +++ b/test/java/rmi/activation/rmidViaInheritedChannel/RmidViaInheritedChannel.java @@ -22,7 +22,7 @@ */ /* @test - * @bug 4295885 + * @bug 4295885 6824141 * @summary rmid should be startable from inetd * @author Ann Wollrath * @@ -36,6 +36,7 @@ import java.io.IOException; import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.ServerSocket; +import java.net.ProtocolFamily; import java.nio.channels.*; import java.nio.channels.spi.*; import java.rmi.Remote; @@ -126,6 +127,12 @@ public class RmidViaInheritedChannel implements Callback { return provider.openDatagramChannel(); } + public DatagramChannel openDatagramChannel(ProtocolFamily family) + throws IOException + { + return provider.openDatagramChannel(family); + } + public Pipe openPipe() throws IOException { diff --git a/test/java/security/Permission/ToString.java b/test/java/security/Permission/ToString.java new file mode 100644 index 0000000000000000000000000000000000000000..cf2ffa11dbda446d2a7bc56aa25c9e11dc95c2c7 --- /dev/null +++ b/test/java/security/Permission/ToString.java @@ -0,0 +1,101 @@ +/* + * 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. + * + * 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. + */ + +/* + * @test + * @bug 6549506 + * @summary Specification of Permission.toString() method contradicts with + * JDK implementation + */ + +import java.security.*; + +public class ToString { + + public static void main(String[]args) throws Exception { + DummyWritePermission dummyPerm = new DummyWritePermission(); + NullActionPermission nullActionPerm = new NullActionPermission(); + System.out.println(dummyPerm.toString()); + System.out.println(dummyPerm.getDescription()); + System.out.println(nullActionPerm.toString()); + System.out.println(nullActionPerm.getDescription()); + if (!dummyPerm.toString().equals(dummyPerm.getDescription())) { + throw new Exception("The expected permission.toString() is " + + dummyPerm.getDescription() + ", but " + + dummyPerm.toString() + " returned!"); + } + + if (!nullActionPerm.toString().equals(nullActionPerm.getDescription())) { + throw new Exception("The expected permission.toString() is " + + nullActionPerm.getDescription() + ", but " + + nullActionPerm.toString() + " returned!"); + } + } + + private static abstract class SimplePermission extends Permission { + public SimplePermission(String name) { + super(name); + } + + public boolean implies(Permission permission) { + return false; + } + + public boolean equals(Object obj) { + return false; + } + + public int hashCode() { + return 13; + } + } + + private static class DummyWritePermission extends SimplePermission { + public DummyWritePermission() { + super("permit to"); + } + + public String getActions() { + return "write"; + } + + public String getDescription() { + return "(\"ToString$DummyWritePermission\" \"permit to\" \"write\")"; + } + } + + private static class NullActionPermission extends SimplePermission { + public NullActionPermission() { + super("permit to"); + } + + public String getActions() { + return null; + } + + public String getDescription() { + return "(\"ToString$NullActionPermission\" \"permit to\")"; + } + } + +} diff --git a/test/java/security/Security/ClassLoaderDeadlock/CreateSerialized.java b/test/java/security/Security/ClassLoaderDeadlock/CreateSerialized.java new file mode 100644 index 0000000000000000000000000000000000000000..89595ed428efd48b4f64f847e6ba4e444ba9ab29 --- /dev/null +++ b/test/java/security/Security/ClassLoaderDeadlock/CreateSerialized.java @@ -0,0 +1,35 @@ +/* + * 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. + * + * 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. + */ +import java.io.*; +import sun.misc.*; + +public class CreateSerialized { + public static void main(String[] args) throws Exception { + Object o = new com.sun.crypto.provider.SunJCE(); + + FileOutputStream fos = new FileOutputStream("object.tmp"); + ObjectOutputStream objectOutputStream = new ObjectOutputStream(fos); + objectOutputStream.writeObject(o); + fos.close(); + } +} diff --git a/test/java/security/Security/ClassLoaderDeadlock/Deadlock2.java b/test/java/security/Security/ClassLoaderDeadlock/Deadlock2.java new file mode 100644 index 0000000000000000000000000000000000000000..b5938d1de88380de96bcde3617ae95adcc76a0d1 --- /dev/null +++ b/test/java/security/Security/ClassLoaderDeadlock/Deadlock2.java @@ -0,0 +1,70 @@ +/* + * 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. + * + * 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. + */ +import java.io.*; +import javax.xml.parsers.DocumentBuilderFactory; +import java.security.*; + +public class Deadlock2 { + public static void main(String[] args) throws Exception { + File file = new File("object.tmp"); + final byte[] bytes = new byte[(int) file.length()]; + FileInputStream fileInputStream = new FileInputStream(file); + int read = fileInputStream.read(bytes); + if (read != file.length()) { + throw new Exception("Didn't read all"); + } + Thread.sleep(1000); + + Runnable xmlRunnable = new Runnable() { + public void run() { + try { + DocumentBuilderFactory.newInstance(); + } catch (Exception e) { + e.printStackTrace(); + } + } + }; + + Runnable readObjectRunnable = new Runnable() { + public void run() { + try { + ObjectInputStream objectInputStream = + new ObjectInputStream(new ByteArrayInputStream(bytes)); + Object o = objectInputStream.readObject(); + System.out.println(o.getClass()); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + + Thread thread1 = new Thread(readObjectRunnable, "Read Object"); + Thread thread2 = new Thread(xmlRunnable, "XML"); + + thread1.start(); + thread2.start(); + + thread1.join(); + thread2.join(); + } +} diff --git a/test/java/security/Security/ClassLoaderDeadlock/Deadlock2.sh b/test/java/security/Security/ClassLoaderDeadlock/Deadlock2.sh new file mode 100644 index 0000000000000000000000000000000000000000..750e2a7d3a17f4355301e64200ecd9a42208df24 --- /dev/null +++ b/test/java/security/Security/ClassLoaderDeadlock/Deadlock2.sh @@ -0,0 +1,99 @@ +#!/bin/sh + +# +# 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. +# +# 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. +# + + +# @test +# @bug 6440846 +# @summary make sure we do not deadlock between ExtClassLoader and AppClassLoader +# @author Valerie Peng +# @run shell/timeout=20 Deadlock2.sh + +# set a few environment variables so that the shell-script can run stand-alone +# in the source directory + +if [ "${TESTSRC}" = "" ] ; then + TESTSRC="." +fi + +if [ "${TESTCLASSES}" = "" ] ; then + TESTCLASSES="." +fi + +if [ "${TESTJAVA}" = "" ] ; then + echo "TESTJAVA not set. Test cannot execute." + echo "FAILED!!!" + exit 1 +fi + +# set platform-dependent variables +OS=`uname -s` +case "$OS" in + SunOS ) + PATHSEP=":" + FILESEP="/" + ;; + Linux ) + PATHSEP=":" + FILESEP="/" + ;; + Windows* ) + PATHSEP=";" + FILESEP="\\" + ;; + * ) + echo "Unrecognized system!" + exit 1; + ;; +esac + +# remove old class files +cd ${TESTCLASSES} +rm -f Deadlock2*.class +if [ -d testlib ] ; then + rm -rf testlib +fi +cp -r ${TESTJAVA}${FILESEP}lib${FILESEP}ext testlib + +# compile and package the test program +${TESTJAVA}${FILESEP}bin${FILESEP}javac \ + -d ${TESTCLASSES} \ + ${TESTSRC}${FILESEP}CreateSerialized.java \ + ${TESTSRC}${FILESEP}Deadlock2.java + +${TESTJAVA}${FILESEP}bin${FILESEP}jar \ + -cvf testlib${FILESEP}Deadlock2.jar \ + Deadlock2*.class + +rm Deadlock2*.class + +# create serialized object and run the test +${TESTJAVA}${FILESEP}bin${FILESEP}java CreateSerialized +${TESTJAVA}${FILESEP}bin${FILESEP}java -Djava.ext.dirs=${TESTCLASSES}${FILESEP}testlib Deadlock2 +STATUS=$? + +# clean up +rm object.tmp CreateSerialized.class +rm -rf testlib +exit ${STATUS} diff --git a/test/java/security/cert/CertPathValidator/OCSP/FailoverToCRL.java b/test/java/security/cert/CertPathValidator/OCSP/FailoverToCRL.java new file mode 100644 index 0000000000000000000000000000000000000000..56367cd2ae388d04d2bdaaf5199e42b10a2a7616 --- /dev/null +++ b/test/java/security/cert/CertPathValidator/OCSP/FailoverToCRL.java @@ -0,0 +1,265 @@ +/* + * 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. + * + * 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. + */ + +/** + * @test + * @bug 6383095 + * @summary CRL revoked certificate failures masked by OCSP failures + * + * Note that the certificate validity is from Mar 16 14:55:35 2009 GMT to + * Dec 1 14:55:35 2028 GMT, please update it with newer certificate if + * expires. + * + * @author Xuelei Fan + */ + +/* + * Certificates used in the test. + * + * end entity certificate: + * Data: + * Version: 3 (0x2) + * Serial Number: 25 (0x19) + * Signature Algorithm: md5WithRSAEncryption + * Issuer: C=US, ST=Some-State, L=Some-City, O=Some-Org + * Validity + * Not Before: Mar 16 14:55:35 2009 GMT + * Not After : Dec 1 14:55:35 2028 GMT + * Subject: C=US, ST=Some-State, L=Some-City, O=Some-Org, OU=SSL-Client, + * CN=localhost + * Subject Public Key Info: + * Public Key Algorithm: rsaEncryption + * RSA Public Key: (1024 bit) + * Modulus (1024 bit): + * 00:bb:f0:40:36:ac:26:54:4e:f4:a3:5a:00:2f:69: + * 21:6f:b9:7a:3a:93:ec:a2:f6:e1:8e:c7:63:d8:2f: + * 12:30:99:2e:b0:f2:8f:f8:27:2d:24:78:28:84:f7: + * 01:bf:8d:44:79:dd:3b:d2:55:f3:ce:3c:b2:5b:21: + * 7d:ef:fd:33:4a:b1:a3:ff:c6:c8:9b:b9:0f:7c:41: + * 35:97:f9:db:3a:05:60:05:15:af:59:17:92:a3:10: + * ad:16:1c:e4:07:53:af:a8:76:a2:56:2a:92:d3:f9: + * 28:e0:78:cf:5e:1f:48:ab:5c:19:dd:e1:67:43:ba: + * 75:8d:f5:82:ac:43:92:44:1b + * Exponent: 65537 (0x10001) + * X509v3 extensions: + * X509v3 Basic Constraints: + * CA:FALSE + * X509v3 Key Usage: + * Digital Signature, Non Repudiation, Key Encipherment + * X509v3 Subject Key Identifier: + * CD:BB:C8:85:AA:91:BD:FD:1D:BE:CD:67:7C:FF:B3:E9:4C:A8:22:E6 + * X509v3 Authority Key Identifier: + * keyid:FA:B9:51:BF:4C:E7:D9:86:98:33:F9:E7:CB:1E:F1:33:49:F7:A8:14 + * Signature Algorithm: md5WithRSAEncryption + * + * + * trusted certificate authority: + * Data: + * Version: 3 (0x2) + * Serial Number: 0 (0x0) + * Signature Algorithm: md5WithRSAEncryption + * Issuer: C=US, ST=Some-State, L=Some-City, O=Some-Org + * Validity + * Not Before: Dec 8 02:43:36 2008 GMT + * Not After : Aug 25 02:43:36 2028 GMT + * Subject: C=US, ST=Some-State, L=Some-City, O=Some-Org + * Subject Public Key Info: + * Public Key Algorithm: rsaEncryption + * RSA Public Key: (1024 bit) + * Modulus (1024 bit): + * 00:cb:c4:38:20:07:be:88:a7:93:b0:a1:43:51:2d: + * d7:8e:85:af:54:dd:ad:a2:7b:23:5b:cf:99:13:53: + * 99:45:7d:ee:6d:ba:2d:bf:e3:ad:6e:3d:9f:1a:f9: + * 03:97:e0:17:55:ae:11:26:57:de:01:29:8e:05:3f: + * 21:f7:e7:36:e8:2e:37:d7:48:ac:53:d6:60:0e:c7: + * 50:6d:f6:c5:85:f7:8b:a6:c5:91:35:72:3c:94:ee: + * f1:17:f0:71:e3:ec:1b:ce:ca:4e:40:42:b0:6d:ee: + * 6a:0e:d6:e5:ad:3c:0f:c9:ba:82:4f:78:f8:89:97: + * 89:2a:95:12:4c:d8:09:2a:e9 + * Exponent: 65537 (0x10001) + * X509v3 extensions: + * X509v3 Subject Key Identifier: + * FA:B9:51:BF:4C:E7:D9:86:98:33:F9:E7:CB:1E:F1:33:49:F7:A8:14 + * X509v3 Authority Key Identifier: + * keyid:FA:B9:51:BF:4C:E7:D9:86:98:33:F9:E7:CB:1E:F1:33:49:F7:A8:14 + * DirName:/C=US/ST=Some-State/L=Some-City/O=Some-Org + * X509v3 Basic Constraints: + * CA:TRUE + * Signature Algorithm: md5WithRSAEncryption + * + * CRL: + * Certificate Revocation List (CRL): + * Version 2 (0x1) + * Signature Algorithm: md5WithRSAEncryption + * Issuer: /C=US/ST=Some-State/L=Some-City/O=Some-Org + * Last Update: Mar 16 16:27:14 2009 GMT + * Next Update: May 15 16:27:14 2028 GMT + * CRL extensions: + * X509v3 CRL Number: + * 2 + * Revoked Certificates: + * Serial Number: 19 + * Revocation Date: Mar 16 16:22:08 2009 GMT + * CRL entry extensions: + * X509v3 CRL Reason Code: + * Superseded + * Signature Algorithm: md5WithRSAEncryption + */ + +import java.io.*; +import java.net.SocketException; +import java.util.*; +import java.security.Security; +import java.security.cert.*; +import java.security.InvalidAlgorithmParameterException; +import java.security.cert.CertPathValidatorException.BasicReason; + +public class FailoverToCRL { + + static String trusedCertStr = + "-----BEGIN CERTIFICATE-----\n" + + "MIICrDCCAhWgAwIBAgIBADANBgkqhkiG9w0BAQQFADBJMQswCQYDVQQGEwJVUzET\n" + + "MBEGA1UECBMKU29tZS1TdGF0ZTESMBAGA1UEBxMJU29tZS1DaXR5MREwDwYDVQQK\n" + + "EwhTb21lLU9yZzAeFw0wODEyMDgwMjQzMzZaFw0yODA4MjUwMjQzMzZaMEkxCzAJ\n" + + "BgNVBAYTAlVTMRMwEQYDVQQIEwpTb21lLVN0YXRlMRIwEAYDVQQHEwlTb21lLUNp\n" + + "dHkxETAPBgNVBAoTCFNvbWUtT3JnMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKB\n" + + "gQDLxDggB76Ip5OwoUNRLdeOha9U3a2ieyNbz5kTU5lFfe5tui2/461uPZ8a+QOX\n" + + "4BdVrhEmV94BKY4FPyH35zboLjfXSKxT1mAOx1Bt9sWF94umxZE1cjyU7vEX8HHj\n" + + "7BvOyk5AQrBt7moO1uWtPA/JuoJPePiJl4kqlRJM2Akq6QIDAQABo4GjMIGgMB0G\n" + + "A1UdDgQWBBT6uVG/TOfZhpgz+efLHvEzSfeoFDBxBgNVHSMEajBogBT6uVG/TOfZ\n" + + "hpgz+efLHvEzSfeoFKFNpEswSTELMAkGA1UEBhMCVVMxEzARBgNVBAgTClNvbWUt\n" + + "U3RhdGUxEjAQBgNVBAcTCVNvbWUtQ2l0eTERMA8GA1UEChMIU29tZS1PcmeCAQAw\n" + + "DAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQQFAAOBgQBcIm534U123Hz+rtyYO5uA\n" + + "ofd81G6FnTfEAV8Kw9fGyyEbQZclBv34A9JsFKeMvU4OFIaixD7nLZ/NZ+IWbhmZ\n" + + "LovmJXyCkOufea73pNiZ+f/4/ScZaIlM/PRycQSqbFNd4j9Wott+08qxHPLpsf3P\n" + + "6Mvf0r1PNTY2hwTJLJmKtg==\n" + + "-----END CERTIFICATE-----"; + + static String targetCertStr = + "-----BEGIN CERTIFICATE-----\n" + + "MIICizCCAfSgAwIBAgIBGTANBgkqhkiG9w0BAQQFADBJMQswCQYDVQQGEwJVUzET\n" + + "MBEGA1UECBMKU29tZS1TdGF0ZTESMBAGA1UEBxMJU29tZS1DaXR5MREwDwYDVQQK\n" + + "EwhTb21lLU9yZzAeFw0wOTAzMTYxNDU1MzVaFw0yODEyMDExNDU1MzVaMHIxCzAJ\n" + + "BgNVBAYTAlVTMRMwEQYDVQQIEwpTb21lLVN0YXRlMRIwEAYDVQQHEwlTb21lLUNp\n" + + "dHkxETAPBgNVBAoTCFNvbWUtT3JnMRMwEQYDVQQLEwpTU0wtQ2xpZW50MRIwEAYD\n" + + "VQQDEwlsb2NhbGhvc3QwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBALvwQDas\n" + + "JlRO9KNaAC9pIW+5ejqT7KL24Y7HY9gvEjCZLrDyj/gnLSR4KIT3Ab+NRHndO9JV\n" + + "8848slshfe/9M0qxo//GyJu5D3xBNZf52zoFYAUVr1kXkqMQrRYc5AdTr6h2olYq\n" + + "ktP5KOB4z14fSKtcGd3hZ0O6dY31gqxDkkQbAgMBAAGjWjBYMAkGA1UdEwQCMAAw\n" + + "CwYDVR0PBAQDAgXgMB0GA1UdDgQWBBTNu8iFqpG9/R2+zWd8/7PpTKgi5jAfBgNV\n" + + "HSMEGDAWgBT6uVG/TOfZhpgz+efLHvEzSfeoFDANBgkqhkiG9w0BAQQFAAOBgQBv\n" + + "p7JjCDOrMBNun46xs4Gz7Y4ygM5VHaFP0oO7369twvRSu0pCuIdZd5OIMPFeRqQw\n" + + "PA68ZdhYVR0pG5W7isV+jB+Dfge/IOgOA85sZ/6FlP3PBRW+YMQKKdRr5So3ook9\n" + + "PimQ7rbxRAofPECv20IUKFBbOUkU+gFcn+WbTKYxBw==\n" + + "-----END CERTIFICATE-----"; + + static String crlStr = + "-----BEGIN X509 CRL-----\n" + + "MIIBRTCBrwIBATANBgkqhkiG9w0BAQQFADBJMQswCQYDVQQGEwJVUzETMBEGA1UE\n" + + "CBMKU29tZS1TdGF0ZTESMBAGA1UEBxMJU29tZS1DaXR5MREwDwYDVQQKEwhTb21l\n" + + "LU9yZxcNMDkwMzE2MTYyNzE0WhcNMjgwNTE1MTYyNzE0WjAiMCACARkXDTA5MDMx\n" + + "NjE2MjIwOFowDDAKBgNVHRUEAwoBBKAOMAwwCgYDVR0UBAMCAQIwDQYJKoZIhvcN\n" + + "AQEEBQADgYEAMixJI9vBwYpOGosn46+T/MTEtlm2S5pIVT/xPDrHkCPfw8l4Zrgp\n" + + "dGPuUkglWdrGdxY9MNRUj2YFNfdZi6zZ7JF6XbkDHYOAKYgPDJRjS/0VcBntn5RJ\n" + + "sQfZsBqc9fFSP8gknRRn3LT41kr9xNRxTT1t3YYjv7J3zkMYyInqeUA=\n" + + "-----END X509 CRL-----"; + + + private static CertPath generateCertificatePath() + throws CertificateException { + // generate certificate from cert strings + CertificateFactory cf = CertificateFactory.getInstance("X.509"); + + ByteArrayInputStream is = + new ByteArrayInputStream(targetCertStr.getBytes()); + Certificate targetCert = cf.generateCertificate(is); + + // generate certification path + List<Certificate> list = Arrays.asList(new Certificate[] {targetCert}); + + return cf.generateCertPath(list); + } + + private static Set<TrustAnchor> generateTrustAnchors() + throws CertificateException { + // generate certificate from cert string + CertificateFactory cf = CertificateFactory.getInstance("X.509"); + + ByteArrayInputStream is = + new ByteArrayInputStream(trusedCertStr.getBytes()); + Certificate trusedCert = cf.generateCertificate(is); + + // generate a trust anchor + TrustAnchor anchor = new TrustAnchor((X509Certificate)trusedCert, null); + + return Collections.singleton(anchor); + } + + private static CertStore generateCertificateStore() throws Exception { + // generate CRL from CRL string + CertificateFactory cf = CertificateFactory.getInstance("X.509"); + + ByteArrayInputStream is = + new ByteArrayInputStream(crlStr.getBytes()); + + // generate a cert store + Collection<? extends CRL> crls = cf.generateCRLs(is); + return CertStore.getInstance("Collection", + new CollectionCertStoreParameters(crls)); + } + + public static void main(String args[]) throws Exception { + CertPath path = generateCertificatePath(); + Set<TrustAnchor> anchors = generateTrustAnchors(); + CertStore crls = generateCertificateStore(); + + PKIXParameters params = new PKIXParameters(anchors); + + // add the CRL store + params.addCertStore(crls); + + // Activate certificate revocation checking + params.setRevocationEnabled(true); + + // Activate OCSP + Security.setProperty("ocsp.enable", "true"); + System.setProperty("com.sun.security.enableCRLDP", "true"); + + // Ensure that the ocsp.responderURL property is not set. + if (Security.getProperty("ocsp.responderURL") != null) { + throw new + Exception("The ocsp.responderURL property must not be set"); + } + + CertPathValidator validator = CertPathValidator.getInstance("PKIX"); + + try { + validator.validate(path, params); + } catch (CertPathValidatorException cpve) { + if (cpve.getReason() != BasicReason.REVOKED) { + throw new Exception( + "unexpect exception, should be a REVOKED CPVE", cpve); + } + } + } +} diff --git a/test/java/security/cert/CertificateFactory/BadX509CertData.java b/test/java/security/cert/CertificateFactory/BadX509CertData.java index 6141afd9adeb901534d0a93c4f03fdeda0b110e9..87f81314578e61384837029a679577f091962077 100644 --- a/test/java/security/cert/CertificateFactory/BadX509CertData.java +++ b/test/java/security/cert/CertificateFactory/BadX509CertData.java @@ -1,5 +1,5 @@ /* - * Copyright 2000 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. * * This code is free software; you can redistribute it and/or modify it @@ -40,7 +40,7 @@ public class BadX509CertData { InputStream is = new ByteArrayInputStream(data.getBytes("ISO8859_1")); try { Certificate cert = factory.generateCertificate(is); - } catch (CertificateParsingException ce) { + } catch (CertificateException ce) { return; } throw new Exception("CertificateFactory.generateCertificate() did " diff --git a/test/java/security/cert/CertificateFactory/openssl/OpenSSLCert.java b/test/java/security/cert/CertificateFactory/openssl/OpenSSLCert.java new file mode 100644 index 0000000000000000000000000000000000000000..5ea5b0bade18acbad157d51214766d2ac2c81fbe --- /dev/null +++ b/test/java/security/cert/CertificateFactory/openssl/OpenSSLCert.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) 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. + * + * 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. + */ +/* + * @test + * @bug 6535697 + * @summary keytool can be more flexible on format of PEM-encoded + * X.509 certificates + */ + +import java.io.*; +import java.util.Arrays; +import java.security.cert.CertificateFactory; + +public class OpenSSLCert { + static final String OUTFILE = "6535697.test"; + + public static void main(String[] args) throws Exception { + test("open"); + test("pem"); + test("open", "open"); + test("open", "pem"); + test("pem", "pem"); + test("pem", "open"); + test("open", "pem", "open"); + test("pem", "open", "pem"); + } + + static void test(String... files) throws Exception { + FileOutputStream fout = new FileOutputStream(OUTFILE); + for (String file: files) { + FileInputStream fin = new FileInputStream( + new File(System.getProperty("test.src", "."), file)); + byte[] buffer = new byte[4096]; + while (true) { + int len = fin.read(buffer); + if (len < 0) break; + fout.write(buffer, 0, len); + } + fin.close(); + } + fout.close(); + System.out.println("Testing " + Arrays.toString(files) + "..."); + if (CertificateFactory.getInstance("X509") + .generateCertificates(new FileInputStream(OUTFILE)) + .size() != files.length) { + throw new Exception("Not same number"); + } + } +} diff --git a/test/java/security/cert/CertificateFactory/openssl/open b/test/java/security/cert/CertificateFactory/openssl/open new file mode 100644 index 0000000000000000000000000000000000000000..c9b0d5e5aa0c29fc2a3a4c1f68ddad504db42e66 --- /dev/null +++ b/test/java/security/cert/CertificateFactory/openssl/open @@ -0,0 +1,72 @@ +Certificate: + Data: + Version: 3 (0x2) + Serial Number: 1174535938 (0x4601ff02) + Signature Algorithm: dsaWithSHA1 + Issuer: C=EA, ST=Moon, L=Backside, O=A-B-C, OU=Office, CN=Me + Validity + Not Before: Mar 22 03:58:58 2007 GMT + Not After : Jun 20 03:58:58 2007 GMT + Subject: C=EA, ST=Moon, L=Backside, O=A-B-C, OU=Office, CN=Me + Subject Public Key Info: + Public Key Algorithm: dsaEncryption + DSA Public Key: + pub: + 00:c5:ce:e8:be:f0:de:27:9c:88:92:21:28:cf:a5: + 38:8d:c1:5f:e5:90:d2:0b:ea:d4:12:ca:86:b8:04: + 57:1d:41:74:3e:52:2d:87:b8:76:7b:d2:95:d7:67: + 30:76:35:47:fb:e9:86:bf:05:3f:9b:f2:6e:3a:96: + 9a:58:e1:05:44:78:02:31:ee:5f:67:6c:44:d2:95: + 8f:72:62:a4:3e:27:1c:f3:94:8a:1e:0b:98:4c:c0: + 9c:f4:3d:17:6d:36:e4:a0:12:04:01:e4:38:9e:bd: + 86:99:7b:84:43:9b:58:68:ef:ce:3d:85:e3:93:d1: + 1f:1a:18:a4:1e:59:ca:80:2e + P: + 00:fd:7f:53:81:1d:75:12:29:52:df:4a:9c:2e:ec: + e4:e7:f6:11:b7:52:3c:ef:44:00:c3:1e:3f:80:b6: + 51:26:69:45:5d:40:22:51:fb:59:3d:8d:58:fa:bf: + c5:f5:ba:30:f6:cb:9b:55:6c:d7:81:3b:80:1d:34: + 6f:f2:66:60:b7:6b:99:50:a5:a4:9f:9f:e8:04:7b: + 10:22:c2:4f:bb:a9:d7:fe:b7:c6:1b:f8:3b:57:e7: + c6:a8:a6:15:0f:04:fb:83:f6:d3:c5:1e:c3:02:35: + 54:13:5a:16:91:32:f6:75:f3:ae:2b:61:d7:2a:ef: + f2:22:03:19:9d:d1:48:01:c7 + Q: + 00:97:60:50:8f:15:23:0b:cc:b2:92:b9:82:a2:eb: + 84:0b:f0:58:1c:f5 + G: + 00:f7:e1:a0:85:d6:9b:3d:de:cb:bc:ab:5c:36:b8: + 57:b9:79:94:af:bb:fa:3a:ea:82:f9:57:4c:0b:3d: + 07:82:67:51:59:57:8e:ba:d4:59:4f:e6:71:07:10: + 81:80:b4:49:16:71:23:e8:4c:28:16:13:b7:cf:09: + 32:8c:c8:a6:e1:3c:16:7a:8b:54:7c:8d:28:e0:a3: + ae:1e:2b:b3:a6:75:91:6e:a3:7f:0b:fa:21:35:62: + f1:fb:62:7a:01:24:3b:cc:a4:f1:be:a8:51:90:89: + a8:83:df:e1:5a:e5:9f:06:92:8b:66:5e:80:7b:55: + 25:64:01:4c:3b:fe:cf:49:2a + X509v3 extensions: + X509v3 Subject Key Identifier: + ED:BF:8A:CA:57:05:ED:5C:9A:72:65:69:6C:C1:02:F8:30:02:A4:6B + Signature Algorithm: dsaWithSHA1 + 30:2d:02:15:00:85:38:a6:79:d4:70:c8:e1:d8:25:2f:87:f0: + 74:3d:26:59:4c:71:ef:02:14:15:32:10:1d:c0:d1:ce:18:f4: + 8b:ea:c0:8b:d7:da:ba:52:3a:0d:f7 +-----BEGIN CERTIFICATE----- +MIIDGDCCAtWgAwIBAgIERgH/AjALBgcqhkjOOAQDBQAwXTELMAkGA1UEBhMCRUEx +DTALBgNVBAgTBE1vb24xETAPBgNVBAcTCEJhY2tzaWRlMQ4wDAYDVQQKEwVBLUIt +QzEPMA0GA1UECxMGT2ZmaWNlMQswCQYDVQQDEwJNZTAeFw0wNzAzMjIwMzU4NTha +Fw0wNzA2MjAwMzU4NThaMF0xCzAJBgNVBAYTAkVBMQ0wCwYDVQQIEwRNb29uMREw +DwYDVQQHEwhCYWNrc2lkZTEOMAwGA1UEChMFQS1CLUMxDzANBgNVBAsTBk9mZmlj +ZTELMAkGA1UEAxMCTWUwggG4MIIBLAYHKoZIzjgEATCCAR8CgYEA/X9TgR11EilS +30qcLuzk5/YRt1I870QAwx4/gLZRJmlFXUAiUftZPY1Y+r/F9bow9subVWzXgTuA +HTRv8mZgt2uZUKWkn5/oBHsQIsJPu6nX/rfGG/g7V+fGqKYVDwT7g/bTxR7DAjVU +E1oWkTL2dfOuK2HXKu/yIgMZndFIAccCFQCXYFCPFSMLzLKSuYKi64QL8Fgc9QKB +gQD34aCF1ps93su8q1w2uFe5eZSvu/o66oL5V0wLPQeCZ1FZV4661FlP5nEHEIGA +tEkWcSPoTCgWE7fPCTKMyKbhPBZ6i1R8jSjgo64eK7OmdZFuo38L+iE1YvH7YnoB +JDvMpPG+qFGQiaiD3+Fa5Z8GkotmXoB7VSVkAUw7/s9JKgOBhQACgYEAxc7ovvDe +J5yIkiEoz6U4jcFf5ZDSC+rUEsqGuARXHUF0PlIth7h2e9KV12cwdjVH++mGvwU/ +m/JuOpaaWOEFRHgCMe5fZ2xE0pWPcmKkPicc85SKHguYTMCc9D0XbTbkoBIEAeQ4 +nr2GmXuEQ5tYaO/OPYXjk9EfGhikHlnKgC6jITAfMB0GA1UdDgQWBBTtv4rKVwXt +XJpyZWlswQL4MAKkazALBgcqhkjOOAQDBQADMAAwLQIVAIU4pnnUcMjh2CUvh/B0 +PSZZTHHvAhQVMhAdwNHOGPSL6sCL19q6UjoN9w== +-----END CERTIFICATE----- diff --git a/test/java/security/cert/CertificateFactory/openssl/pem b/test/java/security/cert/CertificateFactory/openssl/pem new file mode 100644 index 0000000000000000000000000000000000000000..8601bf37256595443da16af0dbe525bfaa93b7ca --- /dev/null +++ b/test/java/security/cert/CertificateFactory/openssl/pem @@ -0,0 +1,16 @@ +-----BEGIN CERTIFICATE----- +MIIDGDCCAtWgAwIBAgIERgH/AjALBgcqhkjOOAQDBQAwXTELMAkGA1UEBhMCRUExDTALBgNVBAgT +BE1vb24xETAPBgNVBAcTCEJhY2tzaWRlMQ4wDAYDVQQKEwVBLUItQzEPMA0GA1UECxMGT2ZmaWNl +MQswCQYDVQQDEwJNZTAeFw0wNzAzMjIwMzU4NThaFw0wNzA2MjAwMzU4NThaMF0xCzAJBgNVBAYT +AkVBMQ0wCwYDVQQIEwRNb29uMREwDwYDVQQHEwhCYWNrc2lkZTEOMAwGA1UEChMFQS1CLUMxDzAN +BgNVBAsTBk9mZmljZTELMAkGA1UEAxMCTWUwggG4MIIBLAYHKoZIzjgEATCCAR8CgYEA/X9TgR11 +EilS30qcLuzk5/YRt1I870QAwx4/gLZRJmlFXUAiUftZPY1Y+r/F9bow9subVWzXgTuAHTRv8mZg +t2uZUKWkn5/oBHsQIsJPu6nX/rfGG/g7V+fGqKYVDwT7g/bTxR7DAjVUE1oWkTL2dfOuK2HXKu/y +IgMZndFIAccCFQCXYFCPFSMLzLKSuYKi64QL8Fgc9QKBgQD34aCF1ps93su8q1w2uFe5eZSvu/o6 +6oL5V0wLPQeCZ1FZV4661FlP5nEHEIGAtEkWcSPoTCgWE7fPCTKMyKbhPBZ6i1R8jSjgo64eK7Om +dZFuo38L+iE1YvH7YnoBJDvMpPG+qFGQiaiD3+Fa5Z8GkotmXoB7VSVkAUw7/s9JKgOBhQACgYEA +xc7ovvDeJ5yIkiEoz6U4jcFf5ZDSC+rUEsqGuARXHUF0PlIth7h2e9KV12cwdjVH++mGvwU/m/Ju +OpaaWOEFRHgCMe5fZ2xE0pWPcmKkPicc85SKHguYTMCc9D0XbTbkoBIEAeQ4nr2GmXuEQ5tYaO/O +PYXjk9EfGhikHlnKgC6jITAfMB0GA1UdDgQWBBTtv4rKVwXtXJpyZWlswQL4MAKkazALBgcqhkjO +OAQDBQADMAAwLQIVAIU4pnnUcMjh2CUvh/B0PSZZTHHvAhQVMhAdwNHOGPSL6sCL19q6UjoN9w== +-----END CERTIFICATE----- diff --git a/test/java/util/Collection/MOAT.java b/test/java/util/Collection/MOAT.java index 0dd89f355005d6baeaab7b6dff87f366c5dcd09f..f9d30f56217d23ab6ba2597f41b073f88ef6b670 100644 --- a/test/java/util/Collection/MOAT.java +++ b/test/java/util/Collection/MOAT.java @@ -555,6 +555,7 @@ public class MOAT { NavigableMap<Integer,Integer> nm = (NavigableMap<Integer,Integer>) m; + testNavigableMapRemovers(nm); testNavigableMap(nm); testNavigableMap(nm.headMap(6, false)); testNavigableMap(nm.headMap(5, true)); @@ -742,6 +743,97 @@ public class MOAT { equal(it.next(), expected); } + static void equalMaps(Map m1, Map m2) { + equal(m1, m2); + equal(m2, m1); + equal(m1.size(), m2.size()); + equal(m1.isEmpty(), m2.isEmpty()); + equal(m1.toString(), m2.toString()); + check(Arrays.equals(m1.entrySet().toArray(), m2.entrySet().toArray())); + } + + @SuppressWarnings({"unchecked", "rawtypes"}) + static void testNavigableMapRemovers(NavigableMap m) + { + final Map emptyMap = new HashMap(); + + final Map singletonMap = new HashMap(); + singletonMap.put(1, 2); + + abstract class NavigableMapView { + abstract NavigableMap view(NavigableMap m); + } + + NavigableMapView[] views = { + new NavigableMapView() { NavigableMap view(NavigableMap m) { + return m; }}, + new NavigableMapView() { NavigableMap view(NavigableMap m) { + return m.headMap(99, true); }}, + new NavigableMapView() { NavigableMap view(NavigableMap m) { + return m.tailMap(-99, false); }}, + new NavigableMapView() { NavigableMap view(NavigableMap m) { + return m.subMap(-99, true, 99, false); }}, + }; + + abstract class Remover { + abstract void remove(NavigableMap m, Object k, Object v); + } + + Remover[] removers = { + new Remover() { void remove(NavigableMap m, Object k, Object v) { + equal(m.remove(k), v); }}, + + new Remover() { void remove(NavigableMap m, Object k, Object v) { + equal(m.descendingMap().remove(k), v); }}, + new Remover() { void remove(NavigableMap m, Object k, Object v) { + equal(m.descendingMap().headMap(-86, false).remove(k), v); }}, + new Remover() { void remove(NavigableMap m, Object k, Object v) { + equal(m.descendingMap().tailMap(86, true).remove(k), v); }}, + + new Remover() { void remove(NavigableMap m, Object k, Object v) { + equal(m.headMap(86, true).remove(k), v); }}, + new Remover() { void remove(NavigableMap m, Object k, Object v) { + equal(m.tailMap(-86, true).remove(k), v); }}, + new Remover() { void remove(NavigableMap m, Object k, Object v) { + equal(m.subMap(-86, false, 86, true).remove(k), v); }}, + + new Remover() { void remove(NavigableMap m, Object k, Object v) { + check(m.keySet().remove(k)); }}, + new Remover() { void remove(NavigableMap m, Object k, Object v) { + check(m.navigableKeySet().remove(k)); }}, + + new Remover() { void remove(NavigableMap m, Object k, Object v) { + check(m.navigableKeySet().headSet(86, true).remove(k)); }}, + new Remover() { void remove(NavigableMap m, Object k, Object v) { + check(m.navigableKeySet().tailSet(-86, false).remove(k)); }}, + new Remover() { void remove(NavigableMap m, Object k, Object v) { + check(m.navigableKeySet().subSet(-86, true, 86, false) + .remove(k)); }}, + + new Remover() { void remove(NavigableMap m, Object k, Object v) { + check(m.descendingKeySet().headSet(-86, false).remove(k)); }}, + new Remover() { void remove(NavigableMap m, Object k, Object v) { + check(m.descendingKeySet().tailSet(86, true).remove(k)); }}, + new Remover() { void remove(NavigableMap m, Object k, Object v) { + check(m.descendingKeySet().subSet(86, true, -86, false) + .remove(k)); }}, + }; + + for (NavigableMapView view : views) { + for (Remover remover : removers) { + try { + m.clear(); + equalMaps(m, emptyMap); + equal(m.put(1, 2), null); + equalMaps(m, singletonMap); + NavigableMap v = view.view(m); + remover.remove(v, 1, 2); + equalMaps(m, emptyMap); + } catch (Throwable t) { unexpected(t); } + } + } + } + private static void testNavigableMap(NavigableMap<Integer,Integer> m) { clear(m); diff --git a/test/java/util/concurrent/Semaphore/RacingReleases.java b/test/java/util/concurrent/Semaphore/RacingReleases.java new file mode 100644 index 0000000000000000000000000000000000000000..c1c573f443fb00eab3b7f70d9bfd81c721c24354 --- /dev/null +++ b/test/java/util/concurrent/Semaphore/RacingReleases.java @@ -0,0 +1,116 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact 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. + */ + +/* + * This file is available under and governed by the GNU General Public + * License version 2 only, as published by the Free Software Foundation. + * However, the following notice accompanied the original version of this + * file: + * + * Written by Doug Lea with assistance from members of JCP JSR-166 + * Expert Group and released to the public domain, as explained at + * http://creativecommons.org/licenses/publicdomain + */ + +/* + * @test + * @bug 6801020 6803402 + * @summary Try to tickle race conditions in + * AbstractQueuedSynchronizer "shared" code + */ + +import java.util.concurrent.Semaphore; + +public class RacingReleases { + + /** Increase this for better chance of tickling races */ + static final int iterations = 1000; + + public static void test(final boolean fair, + final boolean interruptibly) + throws Throwable { + for (int i = 0; i < iterations; i++) { + final Semaphore sem = new Semaphore(0, fair); + final Throwable[] badness = new Throwable[1]; + Runnable blocker = interruptibly ? + new Runnable() { + public void run() { + try { + sem.acquire(); + } catch (Throwable t) { + badness[0] = t; + throw new Error(t); + }}} + : + new Runnable() { + public void run() { + try { + sem.acquireUninterruptibly(); + } catch (Throwable t) { + badness[0] = t; + throw new Error(t); + }}}; + + Thread b1 = new Thread(blocker); + Thread b2 = new Thread(blocker); + Runnable signaller = new Runnable() { + public void run() { + try { + sem.release(); + } catch (Throwable t) { + badness[0] = t; + throw new Error(t); + }}}; + Thread s1 = new Thread(signaller); + Thread s2 = new Thread(signaller); + Thread[] threads = { b1, b2, s1, s2 }; + java.util.Collections.shuffle(java.util.Arrays.asList(threads)); + for (Thread thread : threads) + thread.start(); + for (Thread thread : threads) { + thread.join(60 * 1000); + if (thread.isAlive()) + throw new Error + (String.format + ("Semaphore stuck: permits %d, thread waiting %s%n", + sem.availablePermits(), + sem.hasQueuedThreads() ? "true" : "false")); + } + if (badness[0] != null) + throw new Error(badness[0]); + if (sem.availablePermits() != 0) + throw new Error(String.valueOf(sem.availablePermits())); + if (sem.hasQueuedThreads()) + throw new Error(String.valueOf(sem.hasQueuedThreads())); + if (sem.getQueueLength() != 0) + throw new Error(String.valueOf(sem.getQueueLength())); + if (sem.isFair() != fair) + throw new Error(String.valueOf(sem.isFair())); + } + } + + public static void main(String[] args) throws Throwable { + for (boolean fair : new boolean[] { true, false }) + for (boolean interruptibly : new boolean[] { true, false }) + test(fair, interruptibly); + } +} diff --git a/test/java/util/concurrent/TimeUnit/Basic.java b/test/java/util/concurrent/TimeUnit/Basic.java index 7a9564102319e154f85f539faaa0b688b1e6ec98..bae284d6c8862e6eea7dee700d577a7b5a12b374 100644 --- a/test/java/util/concurrent/TimeUnit/Basic.java +++ b/test/java/util/concurrent/TimeUnit/Basic.java @@ -60,10 +60,11 @@ public class Basic { equal(1000L, MICROSECONDS.toNanos(1)); long t0 = System.nanoTime(); - MILLISECONDS.sleep(3); + MILLISECONDS.sleep(3); /* See windows bug 6313903, might not sleep */ long elapsedMillis = (System.nanoTime() - t0)/(1000L * 1000L); System.out.printf("elapsed=%d%n", elapsedMillis); - check(elapsedMillis >= 3); + check(elapsedMillis >= 0); + /* Might not sleep on windows: check(elapsedMillis >= 3); */ check(elapsedMillis < 1000); //---------------------------------------------------------------- diff --git a/test/java/util/logging/ClassLoaderLeakTest.java b/test/java/util/logging/ClassLoaderLeakTest.java new file mode 100644 index 0000000000000000000000000000000000000000..988041472fcff53a2fb23b5bb3bb29915be9e63c --- /dev/null +++ b/test/java/util/logging/ClassLoaderLeakTest.java @@ -0,0 +1,190 @@ +/* + * 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. + * + * 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. + */ + +/** + * @test + * @bug 6799583 + * + * @summary Test verifes that LogManager shutdown hook does not cause + * an application classloader leaks. + * + * @run main/othervm ClassLoaderLeakTest + */ + +import java.io.File; +import java.lang.ref.WeakReference; +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.concurrent.CountDownLatch; +import java.util.logging.Logger; +import java.util.logging.Logger; + +public class ClassLoaderLeakTest { + + private static CountDownLatch doneSignal; + private static CountDownLatch launchSignal; + private static ThreadGroup appsThreadGroup; + private static Throwable launchFailure = null; + + public static void main(String[] args) { + appsThreadGroup = new ThreadGroup("MyAppsThreadGroup"); + doneSignal = new CountDownLatch(1); + launchSignal = new CountDownLatch(1); + + Runnable launcher = new Runnable() { + public void run() { + try { + ClassLoader cl = + Thread.currentThread().getContextClassLoader(); + Class appMain = cl.loadClass("AppTest"); + Method launch = + appMain.getDeclaredMethod("launch", doneSignal.getClass()); + + Constructor c = appMain.getConstructor(); + + Object o = c.newInstance(); + + launch.invoke(o, doneSignal); + + } catch (Throwable e) { + launchFailure = e; + } finally { + launchSignal.countDown(); + } + } + }; + + /* prepare test class loader */ + URL pwd = null; + try { + + pwd = new File(System.getProperty("test.classes",".")).toURL(); + } catch (MalformedURLException e) { + throw new RuntimeException("Test failed.", e); + } + URL[] urls = new URL[] { pwd }; + + MyClassLoader appClassLoader = new MyClassLoader(urls, "test0"); + WeakReference<MyClassLoader> ref = + new WeakReference<MyClassLoader>(appClassLoader); + + + Thread appThread = new Thread(appsThreadGroup, launcher, "AppThread-0"); + appThread.setContextClassLoader(appClassLoader); + + appThread.start(); + appClassLoader = null; + launcher = null; + appThread = null; + + /* wait for laucnh completion */ + try { + launchSignal.await(); + } catch (InterruptedException e) { + } + + /* check if launch failed */ + if (launchFailure != null) { + throw new RuntimeException("Test failed.", launchFailure); + } + + /* wait for test app excution completion */ + try { + doneSignal.await(); + } catch (InterruptedException e) { + } + + /* give a chence to GC */ + waitAndGC(5); + + if (ref.get() != null) { + throw new RuntimeException("Test failed: classloader is still alive"); + } + + System.out.println("Test passed."); + } + + private static class MyClassLoader extends URLClassLoader { + + private static boolean verbose = + Boolean.getBoolean("verboseClassLoading"); + private String uniqClassName; + + public MyClassLoader(URL[] urls, String uniq) { + super(urls); + + uniqClassName = uniq; + } + + public Class loadClass(String name) throws ClassNotFoundException { + if (verbose) { + System.out.printf("%s: load class %s\n", uniqClassName, name); + } + if (uniqClassName.equals(name)) { + return Object.class; + } + return super.loadClass(name); + } + + public String toString() { + return "MyClassLoader(" + uniqClassName + ")"; + } + } + + private static void waitAndGC(int sec) { + int cnt = sec; + System.out.print("Wait "); + while (cnt-- > 0) { + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + } + // do GC every 3 seconds + if (cnt % 3 == 2) { + System.gc(); + System.out.print("+"); + } else { + System.out.print("."); + } + //checkErrors(); + } + System.out.println(""); + } +} + + +class AppTest { + public AppTest() { + + } + + public void launch(CountDownLatch done) { + Logger log = Logger.getLogger("app_test_logger"); + log.fine("Test app is launched"); + + done.countDown(); + } +} diff --git a/test/java/util/logging/LoggingDeadlock2.java b/test/java/util/logging/LoggingDeadlock2.java index 47831935226ad974b9ffb461c3e37d6eaaf39a02..50de62abfccd1966c2532e783359da4a5c0e2e96 100644 --- a/test/java/util/logging/LoggingDeadlock2.java +++ b/test/java/util/logging/LoggingDeadlock2.java @@ -24,7 +24,7 @@ /* * @test * @bug 6467152 - * + * @ignore until 6716076 is fixed * @summary deadlock occurs in LogManager initialization and JVM termination * @author Serguei Spitsyn / Hittachi * diff --git a/test/java/util/regex/BMPTestCases.txt b/test/java/util/regex/BMPTestCases.txt new file mode 100644 index 0000000000000000000000000000000000000000..c50f49628e3d22a82bc7ed1af77423b02155b338 --- /dev/null +++ b/test/java/util/regex/BMPTestCases.txt @@ -0,0 +1,951 @@ +// +// Copyright 1999-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. +// +// 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. +// +// +// This file contains test cases with BMP characters for regular expressions. +// A test case consists of three lines: +// The first line is a pattern used in the test +// The second line is the input to search for the pattern in +// The third line is a concatentation of the match, the number of groups, +// and the contents of the first four subexpressions. +// Empty lines and lines beginning with comment slashes are ignored. + +// Test unsetting of backed off groups +^(\u3042)?\u3042 +\u3042 +true \u3042 1 + +^(\u3042\u3042(\u3043\u3043)?)+$ +\u3042\u3042\u3043\u3043\u3042\u3042 +true \u3042\u3042\u3043\u3043\u3042\u3042 2 \u3042\u3042 \u3043\u3043 + +((\u3042|\u3043)?\u3043)+ +\u3043 +true \u3043 2 \u3043 + +(\u3042\u3042\u3042)?\u3042\u3042\u3042 +\u3042\u3042\u3042 +true \u3042\u3042\u3042 1 + +^(\u3042(\u3043)?)+$ +\u3042\u3043\u3042 +true \u3042\u3043\u3042 2 \u3042 \u3043 + +^(\u3042(\u3043(\u3044)?)?)?\u3042\u3043\u3044 +\u3042\u3043\u3044 +true \u3042\u3043\u3044 3 + +^(\u3042(\u3043(\u3044))).* +\u3042\u3043\u3044 +true \u3042\u3043\u3044 3 \u3042\u3043\u3044 \u3043\u3044 \u3044 + +// use of x modifier +\u3042\u3043\u3044(?x)\u3043la\u3049 +\u3042\u3043\u3044\u3043la\u3049 +true \u3042\u3043\u3044\u3043la\u3049 0 + +\u3042\u3043\u3044(?x) bla\u3049 +\u3042\u3043\u3044bla\u3049 +true \u3042\u3043\u3044bla\u3049 0 + +\u3042\u3043\u3044(?x) bla\u3049 ble\u3044\u3049 +\u3042\u3043\u3044bla\u3049ble\u3044\u3049 +true \u3042\u3043\u3044bla\u3049ble\u3044\u3049 0 + +\u3042\u3043\u3044(?x) bla\u3049 # ignore comment +\u3042\u3043\u3044bla\u3049 +true \u3042\u3043\u3044bla\u3049 0 + +// Simple alternation +\u3042|\u3043 +\u3042 +true \u3042 0 + +\u3042|\u3043 +\u305B +false 0 + +\u3042|\u3043 +\u3043 +true \u3043 0 + +\u3042|\u3043|\u3044\u3045 +\u3044\u3045 +true \u3044\u3045 0 + +\u3042|\u3042\u3045 +\u3042\u3045 +true \u3042 0 + +\u305B(\u3042|\u3042\u3044)\u3043 +\u305B\u3042\u3044\u3043 +true \u305B\u3042\u3044\u3043 1 \u3042\u3044 + +// Simple char class +[\u3042\u3043\u3044]+ +\u3042\u3043\u3042\u3043\u3042\u3043 +true \u3042\u3043\u3042\u3043\u3042\u3043 0 + +[\u3042\u3043\u3044]+ +\u3045\u3046\u3047\u3048 +false 0 + +[\u3042\u3043\u3044]+[\u3045\u3046\u3047]+[\u3048\u3049\u304A]+ +\u305B\u305B\u305B\u3042\u3042\u3045\u3045\u3048\u3048\u305B\u305B\u305B +true \u3042\u3042\u3045\u3045\u3048\u3048 0 + +// Range char class +[\u3042-\u3048]+ +\u305B\u305B\u305B\u3048\u3048\u3048 +true \u3048\u3048\u3048 0 + +[\u3042-\u3048]+ +mmm +false 0 + +[\u3042-]+ +\u305B\u3042-9\u305B +true \u3042- 0 + +[\u3042-\\u4444]+ +\u305B\u3042-9\u305B +true \u305B\u3042 0 + +// Negated char class +[^\u3042\u3043\u3044]+ +\u3042\u3043\u3042\u3043\u3042\u3043 +false 0 + +[^\u3042\u3043\u3044]+ +\u3042\u3042\u3042\u3043\u3043\u3043\u3044\u3044\u3044\u3045\u3046\u3047\u3048 +true \u3045\u3046\u3047\u3048 0 + +// Making sure a ^ not in first position matches literal ^ +[\u3042\u3043\u3044^\u3043] +\u3043 +true \u3043 0 + +[\u3042\u3043\u3044^\u3043] +^ +true ^ 0 + +// Class union and intersection +[\u3042\u3043\u3044[\u3045\u3046\u3047]] +\u3043 +true \u3043 0 + +[\u3042\u3043\u3044[\u3045\u3046\u3047]] +\u3046 +true \u3046 0 + +[\u3042-\u3045[0-9][\u304e-\u3051]] +\u3042 +true \u3042 0 + +[\u3042-\u3045[0-9][\u304e-\u3051]] +\u3050 +true \u3050 0 + +[\u3042-\u3045[0-9][\u304e-\u3051]] +4 +true 4 0 + +[\u3042-\u3045[0-9][\u304e-\u3051]] +\u3046 +false 0 + +[\u3042-\u3045[0-9][\u304e-\u3051]] +\u3056 +false 0 + +[[\u3042-\u3045][0-9][\u304e-\u3051]] +\u3043 +true \u3043 0 + +[[\u3042-\u3045][0-9][\u304e-\u3051]] +\u305B +false 0 + +[\u3042-\u3044[\u3045-\u3047[\u3048-\u304A]]] +\u3042 +true \u3042 0 + +[\u3042-\u3044[\u3045-\u3047[\u3048-\u304A]]] +\u3046 +true \u3046 0 + +[\u3042-\u3044[\u3045-\u3047[\u3048-\u304A]]] +\u3049 +true \u3049 0 + +[\u3042-\u3044[\u3045-\u3047[\u3048-\u304A]]] +m +false 0 + +[\u3042-\u3044[\u3045-\u3047[\u3048-\u304A]]m] +m +true m 0 + +[\u3042\u3043\u3044[\u3045\u3046\u3047]\u3048\u3049\u304A] +\u3042 +true \u3042 0 + +[\u3042\u3043\u3044[\u3045\u3046\u3047]\u3048\u3049\u304A] +\u3045 +true \u3045 0 + +[\u3042\u3043\u3044[\u3045\u3046\u3047]\u3048\u3049\u304A] +\u3049 +true \u3049 0 + +[\u3042\u3043\u3044[\u3045\u3046\u3047]\u3048\u3049\u304A] +w +false 0 + +[\u3042-\u3044&&[\u3045-\u3047]] +\u3042 +false 0 + +[\u3042-\u3044&&[\u3045-\u3047]] +\u3046 +false 0 + +[\u3042-\u3044&&[\u3045-\u3047]] +\u305B +false 0 + +[[\u3042-\u3044]&&[\u3045-\u3047]] +\u3042 +false 0 + +[[\u3042-\u3044]&&[\u3045-\u3047]] +\u3046 +false 0 + +[[\u3042-\u3044]&&[\u3045-\u3047]] +\u305B +false 0 + +[\u3042-\u3044&&\u3045-\u3047] +\u3042 +false 0 + +[\u3042-\u304e&&\u304e-\u305B] +\u304e +true \u304e 0 + +[\u3042-\u304e&&\u304e-\u305B&&\u3042-\u3044] +\u304e +false 0 + +[\u3042-\u304e&&\u304e-\u305B&&\u3042-\u305B] +\u304e +true \u304e 0 + +[[\u3042-\u304e]&&[\u304e-\u305B]] +\u3042 +false 0 + +[[\u3042-\u304e]&&[\u304e-\u305B]] +\u304e +true \u304e 0 + +[[\u3042-\u304e]&&[\u304e-\u305B]] +\u305B +false 0 + +[[\u3042-\u304e]&&[^\u3042-\u3044]] +\u3042 +false 0 + +[[\u3042-\u304e]&&[^\u3042-\u3044]] +\u3045 +true \u3045 0 + +[\u3042-\u304e&&[^\u3042-\u3044]] +\u3042 +false 0 + +[\u3042-\u304e&&[^\u3042-\u3044]] +\u3045 +true \u3045 0 + +[\u3042-\u3044\u3045-\u3047&&[\u3045-\u3047]] +\u3042 +false 0 + +[\u3042-\u3044\u3045-\u3047&&[\u3045-\u3047]] +\u3046 +true \u3046 0 + +[[\u3042-\u3044]&&\u3045-\u3047\u3042-\u3044] +\u3042 +true \u3042 0 + +[[\u3042-\u3044]&&[\u3045-\u3047][\u3042-\u3044]] +\u3042 +true \u3042 0 + +[[\u3042-\u3044][\u3045-\u3047]&&\u3042\u3043\u3044] +\u3042 +true \u3042 0 + +[[\u3042-\u3044][\u3045-\u3047]&&\u3042\u3043\u3044[\u3045\u3046\u3047]] +\u3046 +true \u3046 0 + +[[\u3042-\u3044]&&[\u3043-\u3045]&&[\u3044-\u3046]] +\u3042 +false 0 + +[[\u3042-\u3044]&&[\u3043-\u3045]&&[\u3044-\u3046]] +\u3044 +true \u3044 0 + +[[\u3042-\u3044]&&[\u3043-\u3045][\u3044-\u3046]&&[\u3056-\u305B]] +\u3044 +false 0 + +[\u3042\u3043\u3044[^\u3043\u3044\u3045]] +\u3042 +true \u3042 0 + +[\u3042\u3043\u3044[^\u3043\u3044\u3045]] +\u3045 +false 0 + +[\u3042-\u3044&&\u3042-\u3045&&\u3042-\u3046\u3048\u3049\u304A] +\u3043 +true \u3043 0 + +[\u3042-\u3044&&\u3042-\u3045&&\u3042-\u3046\u3048\u3049\u304A] +\u3048 +false 0 + +[[\u3042[\u3043]]&&[\u3043[\u3042]]] +\u3042 +true \u3042 0 + +[[\u3042]&&[\u3043][\u3044][\u3042]&&[^\u3045]] +\u3042 +true \u3042 0 + +[[\u3042]&&[b][c][\u3042]&&[^d]] +\u3042 +true \u3042 0 + +[[\u3042]&&[\u3043][\u3044][\u3042]&&[^\u3045]] +\u3045 +false 0 + +[[[\u3042-\u3045]&&[\u3044-\u3047]]] +\u3042 +false 0 + +[[[\u3042-\u3045]&&[\u3044-\u3047]]] +\u3044 +true \u3044 0 + +[[[\u3042-\u3045]&&[\u3044-\u3047]]&&[\u3044]] +\u3044 +true \u3044 0 + +[[[\u3042-\u3045]&&[\u3044-\u3047]]&&[\u3044]&&\u3044] +\u3044 +true \u3044 0 + +[[[\u3042-\u3045]&&[\u3044-\u3047]]&&[\u3044]&&\u3044&&\u3044] +\u3044 +true \u3044 0 + +[[[\u3042-\u3045]&&[\u3044-\u3047]]&&[\u3044]&&\u3044&&[\u3044\u3045\u3046]] +\u3044 +true \u3044 0 + +[\u305B[\u3042\u3043\u3044&&\u3043\u3044\u3045]] +\u3044 +true \u3044 0 + +[\u305B[\u3042\u3043\u3044&&\u3043\u3044\u3045]&&[\u3056-\u305B]] +\u305B +true \u305B 0 + +[\u3059[\u3042\u3043\u3044&&\u3043\u3044\u3045[\u305B]]&&[\u3056-\u305B]] +\u305B +false 0 + +[\u3059[[w\u305B]\u3042\u3043\u3044&&\u3043\u3044\u3045[\u305B]]&&[\u3056-\u305B]] +\u305B +true \u305B 0 + +[[\u3042\u3043\u3044]&&[\u3045\u3046\u3047]\u3042\u3043\u3044] +\u3042 +true \u3042 0 + +[[\u3042\u3043\u3044]&&[\u3045\u3046\u3047]\u3059\u305A\u305B[\u3042\u3043\u3044]] +\u3042 +true \u3042 0 + +\pL +\u3042 +true \u3042 0 + +\pL +7 +false 0 + +\p{L} +\u3042 +true \u3042 0 + +\p{IsL} +\u3042 +true \u3042 0 + +\p{InHiragana} +\u3042 +true \u3042 0 + +\p{InHiragana} +\u0370 +false 0 + +\pL\u3043\u3044 +\u3042\u3043\u3044 +true \u3042\u3043\u3044 0 + +\u3042[r\p{InGreek}]\u3044 +\u3042\u0370\u3044 +true \u3042\u0370\u3044 0 + +\u3042\p{InGreek} +\u3042\u0370 +true \u3042\u0370 0 + +\u3042\P{InGreek} +\u3042\u0370 +false 0 + +\u3042\P{InGreek} +\u3042\u3043 +true \u3042\u3043 0 + +\u3042{^InGreek} +- +error + +\u3042\p{^InGreek} +- +error + +\u3042\P{^InGreek} +- +error + +\u3042\p{InGreek} +\u3042\u0370 +true \u3042\u0370 0 + +\u3042[\p{InGreek}]\u3044 +\u3042\u0370\u3044 +true \u3042\u0370\u3044 0 + +\u3042[\P{InGreek}]\u3044 +\u3042\u0370\u3044 +false 0 + +\u3042[\P{InGreek}]\u3044 +\u3042\u3043\u3044 +true \u3042\u3043\u3044 0 + +\u3042[{^InGreek}]\u3044 +\u3042n\u3044 +true \u3042n\u3044 0 + +\u3042[{^InGreek}]\u3044 +\u3042\u305B\u3044 +false 0 + +\u3042[\p{^InGreek}]\u3044 +- +error + +\u3042[\P{^InGreek}]\u3044 +- +error + +\u3042[\p{InGreek}] +\u3042\u0370 +true \u3042\u0370 0 + +\u3042[r\p{InGreek}]\u3044 +\u3042r\u3044 +true \u3042r\u3044 0 + +\u3042[\p{InGreek}r]\u3044 +\u3042r\u3044 +true \u3042r\u3044 0 + +\u3042[r\p{InGreek}]\u3044 +\u3042r\u3044 +true \u3042r\u3044 0 + +\u3042[^\p{InGreek}]\u3044 +\u3042\u0370\u3044 +false 0 + +\u3042[^\P{InGreek}]\u3044 +\u3042\u0370\u3044 +true \u3042\u0370\u3044 0 + +\u3042[\p{InGreek}&&[^\u0370]]\u3044 +\u3042\u0370\u3044 +false 0 + +// Test the dot metacharacter +\u3042.\u3044.+ +\u3042#\u3044%& +true \u3042#\u3044%& 0 + +\u3042\u3043. +\u3042\u3043\n +false 0 + +(?s)\u3042\u3043. +\u3042\u3043\n +true \u3042\u3043\n 0 + +\u3042[\p{L}&&[\P{InGreek}]]\u3044 +\u3042\u6000\u3044 +true \u3042\u6000\u3044 0 + +\u3042[\p{L}&&[\P{InGreek}]]\u3044 +\u3042r\u3044 +true \u3042r\u3044 0 + +\u3042[\p{L}&&[\P{InGreek}]]\u3044 +\u3042\u0370\u3044 +false 0 + +\u3042\p{InGreek}\u3044 +\u3042\u0370\u3044 +true \u3042\u0370\u3044 0 + +\u3042\p{Sc} +\u3042$ +true \u3042$ 0 + +\W\w\W +rrrr#\u3048\u3048\u3048 +false 0 + +\u3042\u3043\u3044[\s\u3045\u3046\u3047]* +\u3042\u3043\u3044 \u3045\u3046\u3047 +true \u3042\u3043\u3044 \u3045\u3046\u3047 0 + +\u3042\u3043\u3044[\s\u305A-\u305B]* +\u3042\u3043\u3044 \u305A \u305B +true \u3042\u3043\u3044 \u305A \u305B 0 + +\u3042\u3043\u3044[\u3042-\u3045\s\u304e-\u3051]* +\u3042\u3043\u3044\u3042\u3042 \u304e\u304f \u3051 +true \u3042\u3043\u3044\u3042\u3042 \u304e\u304f \u3051 0 + +// Test the whitespace escape sequence +\u3042\u3043\s\u3044 +\u3042\u3043 \u3044 +true \u3042\u3043 \u3044 0 + +\s\s\s +\u3043l\u3042\u3049 \u3046rr +false 0 + +\S\S\s +\u3043l\u3042\u3049 \u3046rr +true \u3042\u3049 0 + +// Test the digit escape sequence +\u3042\u3043\d\u3044 +\u3042\u30439\u3044 +true \u3042\u30439\u3044 0 + +\d\d\d +\u3043l\u3042\u304945 +false 0 + +// Test the caret metacharacter +^\u3042\u3043\u3044 +\u3042\u3043\u3044\u3045\u3046\u3047 +true \u3042\u3043\u3044 0 + +^\u3042\u3043\u3044 +\u3043\u3044\u3045\u3042\u3043\u3044 +false 0 + +// Greedy ? metacharacter +\u3042?\u3043 +\u3042\u3042\u3042\u3042\u3043 +true \u3042\u3043 0 + +\u3042?\u3043 +\u3043 +true \u3043 0 + +\u3042?\u3043 +\u3042\u3042\u3042\u3044\u3044\u3044 +false 0 + +.?\u3043 +\u3042\u3042\u3042\u3042\u3043 +true \u3042\u3043 0 + +// Reluctant ? metacharacter +\u3042??\u3043 +\u3042\u3042\u3042\u3042\u3043 +true \u3042\u3043 0 + +\u3042??\u3043 +\u3043 +true \u3043 0 + +\u3042??\u3043 +\u3042\u3042\u3042\u3044\u3044\u3044 +false 0 + +.??\u3043 +\u3042\u3042\u3042\u3042\u3043 +true \u3042\u3043 0 + +// Possessive ? metacharacter +\u3042?+\u3043 +\u3042\u3042\u3042\u3042\u3043 +true \u3042\u3043 0 + +\u3042?+\u3043 +\u3043 +true \u3043 0 + +\u3042?+\u3043 +\u3042\u3042\u3042\u3044\u3044\u3044 +false 0 + +.?+\u3043 +\u3042\u3042\u3042\u3042\u3043 +true \u3042\u3043 0 + +// Greedy + metacharacter +\u3042+\u3043 +\u3042\u3042\u3042\u3042\u3043 +true \u3042\u3042\u3042\u3042\u3043 0 + +\u3042+\u3043 +\u3043 +false 0 + +\u3042+\u3043 +\u3042\u3042\u3042\u3044\u3044\u3044 +false 0 + +.+\u3043 +\u3042\u3042\u3042\u3042\u3043 +true \u3042\u3042\u3042\u3042\u3043 0 + +// Reluctant + metacharacter +\u3042+?\u3043 +\u3042\u3042\u3042\u3042\u3043 +true \u3042\u3042\u3042\u3042\u3043 0 + +\u3042+?\u3043 +\u3043 +false 0 + +\u3042+?\u3043 +\u3042\u3042\u3042\u3044\u3044\u3044 +false 0 + +.+?\u3043 +\u3042\u3042\u3042\u3042\u3043 +true \u3042\u3042\u3042\u3042\u3043 0 + +// Possessive + metacharacter +\u3042++\u3043 +\u3042\u3042\u3042\u3042\u3043 +true \u3042\u3042\u3042\u3042\u3043 0 + +\u3042++\u3043 +\u3043 +false 0 + +\u3042++\u3043 +\u3042\u3042\u3042\u3044\u3044\u3044 +false 0 + +.++\u3043 +\u3042\u3042\u3042\u3042\u3043 +false 0 + +// Greedy Repetition +\u3042{2,3} +\u3042 +false 0 + +\u3042{2,3} +\u3042\u3042 +true \u3042\u3042 0 + +\u3042{2,3} +\u3042\u3042\u3042 +true \u3042\u3042\u3042 0 + +\u3042{2,3} +\u3042\u3042\u3042\u3042 +true \u3042\u3042\u3042 0 + +\u3042{3,} +\u305B\u305B\u305B\u3042\u3042\u3042\u3042\u305B\u305B\u305B +true \u3042\u3042\u3042\u3042 0 + +\u3042{3,} +\u305B\u305B\u305B\u3042\u3042\u305B\u305B\u305B +false 0 + +// Reluctant Repetition +\u3042{2,3}? +\u3042 +false 0 + +\u3042{2,3}? +\u3042\u3042 +true \u3042\u3042 0 + +\u3042{2,3}? +\u3042\u3042\u3042 +true \u3042\u3042 0 + +\u3042{2,3}? +\u3042\u3042\u3042\u3042 +true \u3042\u3042 0 + +// Zero width Positive lookahead +\u3042\u3043\u3044(?=\u3045) +\u305B\u305B\u305B\u3042\u3043\u3044\u3045 +true \u3042\u3043\u3044 0 + +\u3042\u3043\u3044(?=\u3045) +\u305B\u305B\u305B\u3042\u3043\u3044\u3046\u3045 +false 0 + +// Zero width Negative lookahead +\u3042\u3043\u3044(?!\u3045) +\u305B\u305B\u3042\u3043\u3044\u3045 +false 0 + +\u3042\u3043\u3044(?!\u3045) +\u305B\u305B\u3042\u3043\u3044\u3046\u3045 +true \u3042\u3043\u3044 0 + +// Zero width Positive lookbehind +\u3042(?<=\u3042) +###\u3042\u3043\u3044 +true \u3042 0 + +\u3042(?<=\u3042) +###\u3043\u3044### +false 0 + +// Zero width Negative lookbehind +(?<!\u3042)\w +###\u3042\u3043\u3044a### +true a 0 + +(?<!\u3042)\u3044 +\u3043\u3044 +true \u3044 0 + +(?<!\u3042)\u3044 +\u3042\u3044 +false 0 + +// Nondeterministic group +(\u3042+\u3043)+ +\u3042\u3043\u3042\u3043\u3042\u3043 +true \u3042\u3043\u3042\u3043\u3042\u3043 1 \u3042\u3043 + +(\u3042|\u3043)+ +\u3044\u3044\u3044\u3044\u3045 +false 1 + +// Deterministic group +(\u3042\u3043)+ +\u3042\u3043\u3042\u3043\u3042\u3043 +true \u3042\u3043\u3042\u3043\u3042\u3043 1 \u3042\u3043 + +(\u3042\u3043)+ +\u3042\u3044\u3044\u3044\u3044\u3045 +false 1 + +(\u3042\u3043)* +\u3042\u3043\u3042\u3043\u3042\u3043 +true \u3042\u3043\u3042\u3043\u3042\u3043 1 \u3042\u3043 + +(\u3042\u3043)(\u3044\u3045*) +\u305B\u305B\u305B\u3042\u3043\u3044\u305B\u305B\u305B +true \u3042\u3043\u3044 2 \u3042\u3043 \u3044 + +\u3042\u3043\u3044(\u3045)*\u3042\u3043\u3044 +\u3042\u3043\u3044\u3045\u3045\u3045\u3045\u3045\u3042\u3043\u3044 +true \u3042\u3043\u3044\u3045\u3045\u3045\u3045\u3045\u3042\u3043\u3044 1 \u3045 + +// Back references +(\u3042*)\u3043\u3044\1 +\u305B\u305B\u305B\u3042\u3042\u3043\u3044\u3042\u3042\u305B\u305B\u305B +true \u3042\u3042\u3043\u3044\u3042\u3042 1 \u3042\u3042 + +(\u3042*)\u3043\u3044\1 +\u305B\u305B\u305B\u3042\u3042\u3043\u3044\u3042\u305B\u305B\u305B +true \u3042\u3043\u3044\u3042 1 \u3042 + +(\u3048t*)(\u3045\u3045\u3046)*(\u305A\u3056)\1\3(\u3057\u3057) +\u305B\u305B\u305B\u3048tt\u3045\u3045\u3046\u3045\u3045\u3046\u305A\u3056\u3048tt\u305A\u3056\u3057\u3057\u305B\u305B\u305B +true \u3048tt\u3045\u3045\u3046\u3045\u3045\u3046\u305A\u3056\u3048tt\u305A\u3056\u3057\u3057 4 \u3048tt \u3045\u3045\u3046 \u305A\u3056 \u3057\u3057 + +// Greedy * metacharacter +\u3042*\u3043 +\u3042\u3042\u3042\u3042\u3043 +true \u3042\u3042\u3042\u3042\u3043 0 + +\u3042*\u3043 +\u3043 +true \u3043 0 + +\u3042*\u3043 +\u3042\u3042\u3042\u3044\u3044\u3044 +false 0 + +.*\u3043 +\u3042\u3042\u3042\u3042\u3043 +true \u3042\u3042\u3042\u3042\u3043 0 + +// Reluctant * metacharacter +\u3042*?\u3043 +\u3042\u3042\u3042\u3042\u3043 +true \u3042\u3042\u3042\u3042\u3043 0 + +\u3042*?\u3043 +\u3043 +true \u3043 0 + +\u3042*?\u3043 +\u3042\u3042\u3042\u3044\u3044\u3044 +false 0 + +.*?\u3043 +\u3042\u3042\u3042\u3042\u3043 +true \u3042\u3042\u3042\u3042\u3043 0 + +// Possessive * metacharacter +\u3042*+\u3043 +\u3042\u3042\u3042\u3042\u3043 +true \u3042\u3042\u3042\u3042\u3043 0 + +\u3042*+\u3043 +\u3043 +true \u3043 0 + +\u3042*+\u3043 +\u3042\u3042\u3042\u3044\u3044\u3044 +false 0 + +.*+\u3043 +\u3042\u3042\u3042\u3042\u3043 +false 0 + +// Case insensitivity +(?iu)\uFF46\uFF4F\uFF4F\uFF42\uFF41\uFF52 +\uFF46\uFF2F\uFF4F\uFF42\uFF21\uFF52 +true \uFF46\uFF2F\uFF4F\uFF42\uFF21\uFF52 0 + +\uFF46(?iu)\uFF4F\uFF4F\uFF42\uFF41\uFF52 +\uFF46\uFF2F\uFF4F\uFF42\uFF21\uFF52 +true \uFF46\uFF2F\uFF4F\uFF42\uFF21\uFF52 0 + +\uFF46\uFF4F\uFF4F(?iu)\uFF42\uFF41\uFF52 +\uFF46\uFF2F\uFF4F\uFF42\uFF21\uFF52 +false 0 + +(?iu)\uFF46\uFF4F\uFF4F[\uFF42\uFF41\uFF52]+ +\uFF46\uFF4F\uFF2F\uFF42\uFF21\uFF52 +true \uFF46\uFF4F\uFF2F\uFF42\uFF21\uFF52 0 + +(?iu)\uFF46\uFF4F\uFF4F[\uFF41-\uFF52]+ +\uFF46\uFF4F\uFF2F\uFF42\uFF21\uFF52 +true \uFF46\uFF4F\uFF2F\uFF42\uFF21\uFF52 0 + +// Disable metacharacters- test both length <=3 and >3 +// So that the BM optimization is part of test +\Q***\E\u3042\u3043\u3044 +***\u3042\u3043\u3044 +true ***\u3042\u3043\u3044 0 + +\u3043l\Q***\E\u3042\u3043\u3044 +\u3043l***\u3042\u3043\u3044 +true \u3043l***\u3042\u3043\u3044 0 + +\Q***\u3042\u3043\u3044 +***\u3042\u3043\u3044 +true ***\u3042\u3043\u3044 0 + +\u3043l\u3042\u3049\Q***\E\u3042\u3043\u3044 +\u3043l\u3042\u3049***\u3042\u3043\u3044 +true \u3043l\u3042\u3049***\u3042\u3043\u3044 0 + +\Q***\u3042\u3043\u3044 +***\u3042\u3043\u3044 +true ***\u3042\u3043\u3044 0 + +\Q*\u3042\u3043 +*\u3042\u3043 +true *\u3042\u3043 0 + +\u3043l\u3042\u3049\Q***\u3042\u3043\u3044 +\u3043l\u3042\u3049***\u3042\u3043\u3044 +true \u3043l\u3042\u3049***\u3042\u3043\u3044 0 + +\u3043l\u3042\Q***\u3042\u3043\u3044 +\u3043l\u3042***\u3042\u3043\u3044 +true \u3043l\u3042***\u3042\u3043\u3044 0 + +[\043]+ +\u3043l\u3042\u3049\u3043l\u3042\u3049#\u3043le\u3044\u3049 +true # 0 + +[\042-\044]+ +\u3043l\u3042\u3049\u3043l\u3042\u3049#\u3043le\u3044\u3049 +true # 0 + +[\u1234-\u1236] +\u3043l\u3042\u3049\u3043l\u3042\u3049\u1235\u3043le\u3044\u3049 +true \u1235 0 + +[^\043]* +\u3043l\u3042\u3049\u3043l\u3042\u3049#\u3043le\u3044\u3049 +true \u3043l\u3042\u3049\u3043l\u3042\u3049 0 diff --git a/test/java/util/regex/RegExTest.java b/test/java/util/regex/RegExTest.java new file mode 100644 index 0000000000000000000000000000000000000000..17621184a5366a8bb59d3f01891262d28e1eeef2 --- /dev/null +++ b/test/java/util/regex/RegExTest.java @@ -0,0 +1,3516 @@ +/* + * Copyright 1999-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. + */ + +/** + * @test + * @summary tests RegExp framework + * @author Mike McCloskey + * @bug 4481568 4482696 4495089 4504687 4527731 4599621 4631553 4619345 + * 4630911 4672616 4711773 4727935 4750573 4792284 4803197 4757029 4808962 + * 4872664 4803179 4892980 4900747 4945394 4938995 4979006 4994840 4997476 + * 5013885 5003322 4988891 5098443 5110268 6173522 4829857 5027748 6376940 + * 6358731 6178785 6284152 6231989 6497148 6486934 6233084 6504326 6635133 + * 6350801 6676425 + */ + +import java.util.regex.*; +import java.util.Random; +import java.io.*; +import java.util.*; +import java.nio.CharBuffer; + +/** + * This is a test class created to check the operation of + * the Pattern and Matcher classes. + */ +public class RegExTest { + + private static Random generator = new Random(); + private static boolean failure = false; + private static int failCount = 0; + + /** + * Main to interpret arguments and run several tests. + * + */ + public static void main(String[] args) throws Exception { + // Most of the tests are in a file + processFile("TestCases.txt"); + //processFile("PerlCases.txt"); + processFile("BMPTestCases.txt"); + processFile("SupplementaryTestCases.txt"); + + // These test many randomly generated char patterns + bm(); + slice(); + + // These are hard to put into the file + escapes(); + blankInput(); + + // Substitition tests on randomly generated sequences + globalSubstitute(); + stringbufferSubstitute(); + substitutionBasher(); + + // Canonical Equivalence + ceTest(); + + // Anchors + anchorTest(); + + // boolean match calls + matchesTest(); + lookingAtTest(); + + // Pattern API + patternMatchesTest(); + + // Misc + lookbehindTest(); + nullArgumentTest(); + backRefTest(); + groupCaptureTest(); + caretTest(); + charClassTest(); + emptyPatternTest(); + findIntTest(); + group0Test(); + longPatternTest(); + octalTest(); + ampersandTest(); + negationTest(); + splitTest(); + appendTest(); + caseFoldingTest(); + commentsTest(); + unixLinesTest(); + replaceFirstTest(); + gTest(); + zTest(); + serializeTest(); + reluctantRepetitionTest(); + multilineDollarTest(); + dollarAtEndTest(); + caretBetweenTerminatorsTest(); + // This RFE rejected in Tiger numOccurrencesTest(); + javaCharClassTest(); + nonCaptureRepetitionTest(); + notCapturedGroupCurlyMatchTest(); + escapedSegmentTest(); + literalPatternTest(); + literalReplacementTest(); + regionTest(); + toStringTest(); + negatedCharClassTest(); + findFromTest(); + boundsTest(); + unicodeWordBoundsTest(); + caretAtEndTest(); + wordSearchTest(); + hitEndTest(); + toMatchResultTest(); + surrogatesInClassTest(); + namedGroupCaptureTest(); + + if (failure) + throw new RuntimeException("Failure in the RE handling."); + else + System.err.println("OKAY: All tests passed."); + } + + // Utility functions + + private static String getRandomAlphaString(int length) { + StringBuffer buf = new StringBuffer(length); + for (int i=0; i<length; i++) { + char randChar = (char)(97 + generator.nextInt(26)); + buf.append(randChar); + } + return buf.toString(); + } + + private static void check(Matcher m, String expected) { + m.find(); + if (!m.group().equals(expected)) + failCount++; + } + + private static void check(Matcher m, String result, boolean expected) { + m.find(); + if (m.group().equals(result)) + failCount += (expected) ? 0 : 1; + else + failCount += (expected) ? 1 : 0; + } + + private static void check(Pattern p, String s, boolean expected) { + Matcher matcher = p.matcher(s); + if (matcher.find()) + failCount += (expected) ? 0 : 1; + else + failCount += (expected) ? 1 : 0; + } + + private static void check(String p, char c, boolean expected) { + String propertyPattern = expected ? "\\p" + p : "\\P" + p; + Pattern pattern = Pattern.compile(propertyPattern); + char[] ca = new char[1]; ca[0] = c; + Matcher matcher = pattern.matcher(new String(ca)); + if (!matcher.find()) + failCount++; + } + + private static void check(String p, int codePoint, boolean expected) { + String propertyPattern = expected ? "\\p" + p : "\\P" + p; + Pattern pattern = Pattern.compile(propertyPattern); + char[] ca = Character.toChars(codePoint); + Matcher matcher = pattern.matcher(new String(ca)); + if (!matcher.find()) + failCount++; + } + + private static void check(String p, int flag, String input, String s, + boolean expected) + { + Pattern pattern = Pattern.compile(p, flag); + Matcher matcher = pattern.matcher(input); + if (expected) + check(matcher, s, expected); + else + check(pattern, input, false); + } + + private static void report(String testName) { + int spacesToAdd = 30 - testName.length(); + StringBuffer paddedNameBuffer = new StringBuffer(testName); + for (int i=0; i<spacesToAdd; i++) + paddedNameBuffer.append(" "); + String paddedName = paddedNameBuffer.toString(); + System.err.println(paddedName + ": " + + (failCount==0 ? "Passed":"Failed("+failCount+")")); + if (failCount > 0) + failure = true; + failCount = 0; + } + + /** + * Converts ASCII alphabet characters [A-Za-z] in the given 's' to + * supplementary characters. This method does NOT fully take care + * of the regex syntax. + */ + private static String toSupplementaries(String s) { + int length = s.length(); + StringBuffer sb = new StringBuffer(length * 2); + + for (int i = 0; i < length; ) { + char c = s.charAt(i++); + if (c == '\\') { + sb.append(c); + if (i < length) { + c = s.charAt(i++); + sb.append(c); + if (c == 'u') { + // assume no syntax error + sb.append(s.charAt(i++)); + sb.append(s.charAt(i++)); + sb.append(s.charAt(i++)); + sb.append(s.charAt(i++)); + } + } + } else if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')) { + sb.append('\ud800').append((char)('\udc00'+c)); + } else { + sb.append(c); + } + } + return sb.toString(); + } + + // Regular expression tests + + // This is for bug 6178785 + // Test if an expected NPE gets thrown when passing in a null argument + private static boolean check(Runnable test) { + try { + test.run(); + failCount++; + return false; + } catch (NullPointerException npe) { + return true; + } + } + + private static void nullArgumentTest() { + check(new Runnable() { public void run() { Pattern.compile(null); }}); + check(new Runnable() { public void run() { Pattern.matches(null, null); }}); + check(new Runnable() { public void run() { Pattern.matches("xyz", null);}}); + check(new Runnable() { public void run() { Pattern.quote(null);}}); + check(new Runnable() { public void run() { Pattern.compile("xyz").split(null);}}); + check(new Runnable() { public void run() { Pattern.compile("xyz").matcher(null);}}); + + final Matcher m = Pattern.compile("xyz").matcher("xyz"); + m.matches(); + check(new Runnable() { public void run() { m.appendTail(null);}}); + check(new Runnable() { public void run() { m.replaceAll(null);}}); + check(new Runnable() { public void run() { m.replaceFirst(null);}}); + check(new Runnable() { public void run() { m.appendReplacement(null, null);}}); + check(new Runnable() { public void run() { m.reset(null);}}); + check(new Runnable() { public void run() { Matcher.quoteReplacement(null);}}); + //check(new Runnable() { public void run() { m.usePattern(null);}}); + + report("Null Argument"); + } + + // This is for bug6635133 + // Test if surrogate pair in Unicode escapes can be handled correctly. + private static void surrogatesInClassTest() throws Exception { + Pattern pattern = Pattern.compile("[\\ud834\\udd21-\\ud834\\udd24]"); + Matcher matcher = pattern.matcher("\ud834\udd22"); + if (!matcher.find()) + failCount++; + } + + // This is for bug 4988891 + // Test toMatchResult to see that it is a copy of the Matcher + // that is not affected by subsequent operations on the original + private static void toMatchResultTest() throws Exception { + Pattern pattern = Pattern.compile("squid"); + Matcher matcher = pattern.matcher( + "agiantsquidofdestinyasmallsquidoffate"); + matcher.find(); + int matcherStart1 = matcher.start(); + MatchResult mr = matcher.toMatchResult(); + if (mr == matcher) + failCount++; + int resultStart1 = mr.start(); + if (matcherStart1 != resultStart1) + failCount++; + matcher.find(); + int matcherStart2 = matcher.start(); + int resultStart2 = mr.start(); + if (matcherStart2 == resultStart2) + failCount++; + if (resultStart1 != resultStart2) + failCount++; + MatchResult mr2 = matcher.toMatchResult(); + if (mr == mr2) + failCount++; + if (mr2.start() != matcherStart2) + failCount++; + report("toMatchResult is a copy"); + } + + // This is for bug 5013885 + // Must test a slice to see if it reports hitEnd correctly + private static void hitEndTest() throws Exception { + // Basic test of Slice node + Pattern p = Pattern.compile("^squidattack"); + Matcher m = p.matcher("squack"); + m.find(); + if (m.hitEnd()) + failCount++; + m.reset("squid"); + m.find(); + if (!m.hitEnd()) + failCount++; + + // Test Slice, SliceA and SliceU nodes + for (int i=0; i<3; i++) { + int flags = 0; + if (i==1) flags = Pattern.CASE_INSENSITIVE; + if (i==2) flags = Pattern.UNICODE_CASE; + p = Pattern.compile("^abc", flags); + m = p.matcher("ad"); + m.find(); + if (m.hitEnd()) + failCount++; + m.reset("ab"); + m.find(); + if (!m.hitEnd()) + failCount++; + } + + // Test Boyer-Moore node + p = Pattern.compile("catattack"); + m = p.matcher("attack"); + m.find(); + if (!m.hitEnd()) + failCount++; + + p = Pattern.compile("catattack"); + m = p.matcher("attackattackattackcatatta"); + m.find(); + if (!m.hitEnd()) + failCount++; + + report("hitEnd from a Slice"); + } + + // This is for bug 4997476 + // It is weird code submitted by customer demonstrating a regression + private static void wordSearchTest() throws Exception { + String testString = new String("word1 word2 word3"); + Pattern p = Pattern.compile("\\b"); + Matcher m = p.matcher(testString); + int position = 0; + int start = 0; + while (m.find(position)) { + start = m.start(); + if (start == testString.length()) + break; + if (m.find(start+1)) { + position = m.start(); + } else { + position = testString.length(); + } + if (testString.substring(start, position).equals(" ")) + continue; + if (!testString.substring(start, position-1).startsWith("word")) + failCount++; + } + report("Customer word search"); + } + + // This is for bug 4994840 + private static void caretAtEndTest() throws Exception { + // Problem only occurs with multiline patterns + // containing a beginning-of-line caret "^" followed + // by an expression that also matches the empty string. + Pattern pattern = Pattern.compile("^x?", Pattern.MULTILINE); + Matcher matcher = pattern.matcher("\r"); + matcher.find(); + matcher.find(); + report("Caret at end"); + } + + // This test is for 4979006 + // Check to see if word boundary construct properly handles unicode + // non spacing marks + private static void unicodeWordBoundsTest() throws Exception { + String spaces = " "; + String wordChar = "a"; + String nsm = "\u030a"; + + assert (Character.getType('\u030a') == Character.NON_SPACING_MARK); + + Pattern pattern = Pattern.compile("\\b"); + Matcher matcher = pattern.matcher(""); + // S=other B=word character N=non spacing mark .=word boundary + // SS.BB.SS + String input = spaces + wordChar + wordChar + spaces; + twoFindIndexes(input, matcher, 2, 4); + // SS.BBN.SS + input = spaces + wordChar +wordChar + nsm + spaces; + twoFindIndexes(input, matcher, 2, 5); + // SS.BN.SS + input = spaces + wordChar + nsm + spaces; + twoFindIndexes(input, matcher, 2, 4); + // SS.BNN.SS + input = spaces + wordChar + nsm + nsm + spaces; + twoFindIndexes(input, matcher, 2, 5); + // SSN.BB.SS + input = spaces + nsm + wordChar + wordChar + spaces; + twoFindIndexes(input, matcher, 3, 5); + // SS.BNB.SS + input = spaces + wordChar + nsm + wordChar + spaces; + twoFindIndexes(input, matcher, 2, 5); + // SSNNSS + input = spaces + nsm + nsm + spaces; + matcher.reset(input); + if (matcher.find()) + failCount++; + // SSN.BBN.SS + input = spaces + nsm + wordChar + wordChar + nsm + spaces; + twoFindIndexes(input, matcher, 3, 6); + + report("Unicode word boundary"); + } + + private static void twoFindIndexes(String input, Matcher matcher, int a, + int b) throws Exception + { + matcher.reset(input); + matcher.find(); + if (matcher.start() != a) + failCount++; + matcher.find(); + if (matcher.start() != b) + failCount++; + } + + // This test is for 6284152 + static void check(String regex, String input, String[] expected) { + List<String> result = new ArrayList<String>(); + Pattern p = Pattern.compile(regex); + Matcher m = p.matcher(input); + while (m.find()) { + result.add(m.group()); + } + if (!Arrays.asList(expected).equals(result)) + failCount++; + } + + private static void lookbehindTest() throws Exception { + //Positive + check("(?<=%.{0,5})foo\\d", + "%foo1\n%bar foo2\n%bar foo3\n%blahblah foo4\nfoo5", + new String[]{"foo1", "foo2", "foo3"}); + + //boundary at end of the lookbehind sub-regex should work consistently + //with the boundary just after the lookbehind sub-regex + check("(?<=.*\\b)foo", "abcd foo", new String[]{"foo"}); + check("(?<=.*)\\bfoo", "abcd foo", new String[]{"foo"}); + check("(?<!abc )\\bfoo", "abc foo", new String[0]); + check("(?<!abc \\b)foo", "abc foo", new String[0]); + + //Negative + check("(?<!%.{0,5})foo\\d", + "%foo1\n%bar foo2\n%bar foo3\n%blahblah foo4\nfoo5", + new String[] {"foo4", "foo5"}); + + //Positive greedy + check("(?<=%b{1,4})foo", "%bbbbfoo", new String[] {"foo"}); + + //Positive reluctant + check("(?<=%b{1,4}?)foo", "%bbbbfoo", new String[] {"foo"}); + + //supplementary + check("(?<=%b{1,4})fo\ud800\udc00o", "%bbbbfo\ud800\udc00o", + new String[] {"fo\ud800\udc00o"}); + check("(?<=%b{1,4}?)fo\ud800\udc00o", "%bbbbfo\ud800\udc00o", + new String[] {"fo\ud800\udc00o"}); + check("(?<!%b{1,4})fo\ud800\udc00o", "%afo\ud800\udc00o", + new String[] {"fo\ud800\udc00o"}); + check("(?<!%b{1,4}?)fo\ud800\udc00o", "%afo\ud800\udc00o", + new String[] {"fo\ud800\udc00o"}); + report("Lookbehind"); + } + + // This test is for 4938995 + // Check to see if weak region boundaries are transparent to + // lookahead and lookbehind constructs + private static void boundsTest() throws Exception { + String fullMessage = "catdogcat"; + Pattern pattern = Pattern.compile("(?<=cat)dog(?=cat)"); + Matcher matcher = pattern.matcher("catdogca"); + matcher.useTransparentBounds(true); + if (matcher.find()) + failCount++; + matcher.reset("atdogcat"); + if (matcher.find()) + failCount++; + matcher.reset(fullMessage); + if (!matcher.find()) + failCount++; + matcher.reset(fullMessage); + matcher.region(0,9); + if (!matcher.find()) + failCount++; + matcher.reset(fullMessage); + matcher.region(0,6); + if (!matcher.find()) + failCount++; + matcher.reset(fullMessage); + matcher.region(3,6); + if (!matcher.find()) + failCount++; + matcher.useTransparentBounds(false); + if (matcher.find()) + failCount++; + + // Negative lookahead/lookbehind + pattern = Pattern.compile("(?<!cat)dog(?!cat)"); + matcher = pattern.matcher("dogcat"); + matcher.useTransparentBounds(true); + matcher.region(0,3); + if (matcher.find()) + failCount++; + matcher.reset("catdog"); + matcher.region(3,6); + if (matcher.find()) + failCount++; + matcher.useTransparentBounds(false); + matcher.reset("dogcat"); + matcher.region(0,3); + if (!matcher.find()) + failCount++; + matcher.reset("catdog"); + matcher.region(3,6); + if (!matcher.find()) + failCount++; + + report("Region bounds transparency"); + } + + // This test is for 4945394 + private static void findFromTest() throws Exception { + String message = "This is 40 $0 message."; + Pattern pat = Pattern.compile("\\$0"); + Matcher match = pat.matcher(message); + if (!match.find()) + failCount++; + if (match.find()) + failCount++; + if (match.find()) + failCount++; + report("Check for alternating find"); + } + + // This test is for 4872664 and 4892980 + private static void negatedCharClassTest() throws Exception { + Pattern pattern = Pattern.compile("[^>]"); + Matcher matcher = pattern.matcher("\u203A"); + if (!matcher.matches()) + failCount++; + pattern = Pattern.compile("[^fr]"); + matcher = pattern.matcher("a"); + if (!matcher.find()) + failCount++; + matcher.reset("\u203A"); + if (!matcher.find()) + failCount++; + String s = "for"; + String result[] = s.split("[^fr]"); + if (!result[0].equals("f")) + failCount++; + if (!result[1].equals("r")) + failCount++; + s = "f\u203Ar"; + result = s.split("[^fr]"); + if (!result[0].equals("f")) + failCount++; + if (!result[1].equals("r")) + failCount++; + + // Test adding to bits, subtracting a node, then adding to bits again + pattern = Pattern.compile("[^f\u203Ar]"); + matcher = pattern.matcher("a"); + if (!matcher.find()) + failCount++; + matcher.reset("f"); + if (matcher.find()) + failCount++; + matcher.reset("\u203A"); + if (matcher.find()) + failCount++; + matcher.reset("r"); + if (matcher.find()) + failCount++; + matcher.reset("\u203B"); + if (!matcher.find()) + failCount++; + + // Test subtracting a node, adding to bits, subtracting again + pattern = Pattern.compile("[^\u203Ar\u203B]"); + matcher = pattern.matcher("a"); + if (!matcher.find()) + failCount++; + matcher.reset("\u203A"); + if (matcher.find()) + failCount++; + matcher.reset("r"); + if (matcher.find()) + failCount++; + matcher.reset("\u203B"); + if (matcher.find()) + failCount++; + matcher.reset("\u203C"); + if (!matcher.find()) + failCount++; + + report("Negated Character Class"); + } + + // This test is for 4628291 + private static void toStringTest() throws Exception { + Pattern pattern = Pattern.compile("b+"); + if (pattern.toString() != "b+") + failCount++; + Matcher matcher = pattern.matcher("aaabbbccc"); + String matcherString = matcher.toString(); // unspecified + matcher.find(); + matcherString = matcher.toString(); // unspecified + matcher.region(0,3); + matcherString = matcher.toString(); // unspecified + matcher.reset(); + matcherString = matcher.toString(); // unspecified + report("toString"); + } + + // This test is for 4808962 + private static void literalPatternTest() throws Exception { + int flags = Pattern.LITERAL; + + Pattern pattern = Pattern.compile("abc\\t$^", flags); + check(pattern, "abc\\t$^", true); + + pattern = Pattern.compile(Pattern.quote("abc\\t$^")); + check(pattern, "abc\\t$^", true); + + pattern = Pattern.compile("\\Qa^$bcabc\\E", flags); + check(pattern, "\\Qa^$bcabc\\E", true); + check(pattern, "a^$bcabc", false); + + pattern = Pattern.compile("\\\\Q\\\\E"); + check(pattern, "\\Q\\E", true); + + pattern = Pattern.compile("\\Qabc\\Eefg\\\\Q\\\\Ehij"); + check(pattern, "abcefg\\Q\\Ehij", true); + + pattern = Pattern.compile("\\\\\\Q\\\\E"); + check(pattern, "\\\\\\\\", true); + + pattern = Pattern.compile(Pattern.quote("\\Qa^$bcabc\\E")); + check(pattern, "\\Qa^$bcabc\\E", true); + check(pattern, "a^$bcabc", false); + + pattern = Pattern.compile(Pattern.quote("\\Qabc\\Edef")); + check(pattern, "\\Qabc\\Edef", true); + check(pattern, "abcdef", false); + + pattern = Pattern.compile(Pattern.quote("abc\\Edef")); + check(pattern, "abc\\Edef", true); + check(pattern, "abcdef", false); + + pattern = Pattern.compile(Pattern.quote("\\E")); + check(pattern, "\\E", true); + + pattern = Pattern.compile("((((abc.+?:)", flags); + check(pattern, "((((abc.+?:)", true); + + flags |= Pattern.MULTILINE; + + pattern = Pattern.compile("^cat$", flags); + check(pattern, "abc^cat$def", true); + check(pattern, "cat", false); + + flags |= Pattern.CASE_INSENSITIVE; + + pattern = Pattern.compile("abcdef", flags); + check(pattern, "ABCDEF", true); + check(pattern, "AbCdEf", true); + + flags |= Pattern.DOTALL; + + pattern = Pattern.compile("a...b", flags); + check(pattern, "A...b", true); + check(pattern, "Axxxb", false); + + flags |= Pattern.CANON_EQ; + + Pattern p = Pattern.compile("testa\u030a", flags); + check(pattern, "testa\u030a", false); + check(pattern, "test\u00e5", false); + + // Supplementary character test + flags = Pattern.LITERAL; + + pattern = Pattern.compile(toSupplementaries("abc\\t$^"), flags); + check(pattern, toSupplementaries("abc\\t$^"), true); + + pattern = Pattern.compile(Pattern.quote(toSupplementaries("abc\\t$^"))); + check(pattern, toSupplementaries("abc\\t$^"), true); + + pattern = Pattern.compile(toSupplementaries("\\Qa^$bcabc\\E"), flags); + check(pattern, toSupplementaries("\\Qa^$bcabc\\E"), true); + check(pattern, toSupplementaries("a^$bcabc"), false); + + pattern = Pattern.compile(Pattern.quote(toSupplementaries("\\Qa^$bcabc\\E"))); + check(pattern, toSupplementaries("\\Qa^$bcabc\\E"), true); + check(pattern, toSupplementaries("a^$bcabc"), false); + + pattern = Pattern.compile(Pattern.quote(toSupplementaries("\\Qabc\\Edef"))); + check(pattern, toSupplementaries("\\Qabc\\Edef"), true); + check(pattern, toSupplementaries("abcdef"), false); + + pattern = Pattern.compile(Pattern.quote(toSupplementaries("abc\\Edef"))); + check(pattern, toSupplementaries("abc\\Edef"), true); + check(pattern, toSupplementaries("abcdef"), false); + + pattern = Pattern.compile(toSupplementaries("((((abc.+?:)"), flags); + check(pattern, toSupplementaries("((((abc.+?:)"), true); + + flags |= Pattern.MULTILINE; + + pattern = Pattern.compile(toSupplementaries("^cat$"), flags); + check(pattern, toSupplementaries("abc^cat$def"), true); + check(pattern, toSupplementaries("cat"), false); + + flags |= Pattern.DOTALL; + + // note: this is case-sensitive. + pattern = Pattern.compile(toSupplementaries("a...b"), flags); + check(pattern, toSupplementaries("a...b"), true); + check(pattern, toSupplementaries("axxxb"), false); + + flags |= Pattern.CANON_EQ; + + String t = toSupplementaries("test"); + p = Pattern.compile(t + "a\u030a", flags); + check(pattern, t + "a\u030a", false); + check(pattern, t + "\u00e5", false); + + report("Literal pattern"); + } + + // This test is for 4803179 + // This test is also for 4808962, replacement parts + private static void literalReplacementTest() throws Exception { + int flags = Pattern.LITERAL; + + Pattern pattern = Pattern.compile("abc", flags); + Matcher matcher = pattern.matcher("zzzabczzz"); + String replaceTest = "$0"; + String result = matcher.replaceAll(replaceTest); + if (!result.equals("zzzabczzz")) + failCount++; + + matcher.reset(); + String literalReplacement = matcher.quoteReplacement(replaceTest); + result = matcher.replaceAll(literalReplacement); + if (!result.equals("zzz$0zzz")) + failCount++; + + matcher.reset(); + replaceTest = "\\t$\\$"; + literalReplacement = matcher.quoteReplacement(replaceTest); + result = matcher.replaceAll(literalReplacement); + if (!result.equals("zzz\\t$\\$zzz")) + failCount++; + + // Supplementary character test + pattern = Pattern.compile(toSupplementaries("abc"), flags); + matcher = pattern.matcher(toSupplementaries("zzzabczzz")); + replaceTest = "$0"; + result = matcher.replaceAll(replaceTest); + if (!result.equals(toSupplementaries("zzzabczzz"))) + failCount++; + + matcher.reset(); + literalReplacement = matcher.quoteReplacement(replaceTest); + result = matcher.replaceAll(literalReplacement); + if (!result.equals(toSupplementaries("zzz$0zzz"))) + failCount++; + + matcher.reset(); + replaceTest = "\\t$\\$"; + literalReplacement = matcher.quoteReplacement(replaceTest); + result = matcher.replaceAll(literalReplacement); + if (!result.equals(toSupplementaries("zzz\\t$\\$zzz"))) + failCount++; + + report("Literal replacement"); + } + + // This test is for 4757029 + private static void regionTest() throws Exception { + Pattern pattern = Pattern.compile("abc"); + Matcher matcher = pattern.matcher("abcdefabc"); + + matcher.region(0,9); + if (!matcher.find()) + failCount++; + if (!matcher.find()) + failCount++; + matcher.region(0,3); + if (!matcher.find()) + failCount++; + matcher.region(3,6); + if (matcher.find()) + failCount++; + matcher.region(0,2); + if (matcher.find()) + failCount++; + + expectRegionFail(matcher, 1, -1); + expectRegionFail(matcher, -1, -1); + expectRegionFail(matcher, -1, 1); + expectRegionFail(matcher, 5, 3); + expectRegionFail(matcher, 5, 12); + expectRegionFail(matcher, 12, 12); + + pattern = Pattern.compile("^abc$"); + matcher = pattern.matcher("zzzabczzz"); + matcher.region(0,9); + if (matcher.find()) + failCount++; + matcher.region(3,6); + if (!matcher.find()) + failCount++; + matcher.region(3,6); + matcher.useAnchoringBounds(false); + if (matcher.find()) + failCount++; + + // Supplementary character test + pattern = Pattern.compile(toSupplementaries("abc")); + matcher = pattern.matcher(toSupplementaries("abcdefabc")); + matcher.region(0,9*2); + if (!matcher.find()) + failCount++; + if (!matcher.find()) + failCount++; + matcher.region(0,3*2); + if (!matcher.find()) + failCount++; + matcher.region(1,3*2); + if (matcher.find()) + failCount++; + matcher.region(3*2,6*2); + if (matcher.find()) + failCount++; + matcher.region(0,2*2); + if (matcher.find()) + failCount++; + matcher.region(0,2*2+1); + if (matcher.find()) + failCount++; + + expectRegionFail(matcher, 1*2, -1); + expectRegionFail(matcher, -1, -1); + expectRegionFail(matcher, -1, 1*2); + expectRegionFail(matcher, 5*2, 3*2); + expectRegionFail(matcher, 5*2, 12*2); + expectRegionFail(matcher, 12*2, 12*2); + + pattern = Pattern.compile(toSupplementaries("^abc$")); + matcher = pattern.matcher(toSupplementaries("zzzabczzz")); + matcher.region(0,9*2); + if (matcher.find()) + failCount++; + matcher.region(3*2,6*2); + if (!matcher.find()) + failCount++; + matcher.region(3*2+1,6*2); + if (matcher.find()) + failCount++; + matcher.region(3*2,6*2-1); + if (matcher.find()) + failCount++; + matcher.region(3*2,6*2); + matcher.useAnchoringBounds(false); + if (matcher.find()) + failCount++; + report("Regions"); + } + + private static void expectRegionFail(Matcher matcher, int index1, + int index2) + { + try { + matcher.region(index1, index2); + failCount++; + } catch (IndexOutOfBoundsException ioobe) { + // Correct result + } catch (IllegalStateException ise) { + // Correct result + } + } + + // This test is for 4803197 + private static void escapedSegmentTest() throws Exception { + + Pattern pattern = Pattern.compile("\\Qdir1\\dir2\\E"); + check(pattern, "dir1\\dir2", true); + + pattern = Pattern.compile("\\Qdir1\\dir2\\\\E"); + check(pattern, "dir1\\dir2\\", true); + + pattern = Pattern.compile("(\\Qdir1\\dir2\\\\E)"); + check(pattern, "dir1\\dir2\\", true); + + // Supplementary character test + pattern = Pattern.compile(toSupplementaries("\\Qdir1\\dir2\\E")); + check(pattern, toSupplementaries("dir1\\dir2"), true); + + pattern = Pattern.compile(toSupplementaries("\\Qdir1\\dir2")+"\\\\E"); + check(pattern, toSupplementaries("dir1\\dir2\\"), true); + + pattern = Pattern.compile(toSupplementaries("(\\Qdir1\\dir2")+"\\\\E)"); + check(pattern, toSupplementaries("dir1\\dir2\\"), true); + + report("Escaped segment"); + } + + // This test is for 4792284 + private static void nonCaptureRepetitionTest() throws Exception { + String input = "abcdefgh;"; + + String[] patterns = new String[] { + "(?:\\w{4})+;", + "(?:\\w{8})*;", + "(?:\\w{2}){2,4};", + "(?:\\w{4}){2,};", // only matches the + ".*?(?:\\w{5})+;", // specified minimum + ".*?(?:\\w{9})*;", // number of reps - OK + "(?:\\w{4})+?;", // lazy repetition - OK + "(?:\\w{4})++;", // possessive repetition - OK + "(?:\\w{2,}?)+;", // non-deterministic - OK + "(\\w{4})+;", // capturing group - OK + }; + + for (int i = 0; i < patterns.length; i++) { + // Check find() + check(patterns[i], 0, input, input, true); + // Check matches() + Pattern p = Pattern.compile(patterns[i]); + Matcher m = p.matcher(input); + + if (m.matches()) { + if (!m.group(0).equals(input)) + failCount++; + } else { + failCount++; + } + } + + report("Non capturing repetition"); + } + + // This test is for 6358731 + private static void notCapturedGroupCurlyMatchTest() throws Exception { + Pattern pattern = Pattern.compile("(abc)+|(abcd)+"); + Matcher matcher = pattern.matcher("abcd"); + if (!matcher.matches() || + matcher.group(1) != null || + !matcher.group(2).equals("abcd")) { + failCount++; + } + report("Not captured GroupCurly"); + } + + // This test is for 4706545 + private static void javaCharClassTest() throws Exception { + for (int i=0; i<1000; i++) { + char c = (char)generator.nextInt(); + check("{javaLowerCase}", c, Character.isLowerCase(c)); + check("{javaUpperCase}", c, Character.isUpperCase(c)); + check("{javaUpperCase}+", c, Character.isUpperCase(c)); + check("{javaTitleCase}", c, Character.isTitleCase(c)); + check("{javaDigit}", c, Character.isDigit(c)); + check("{javaDefined}", c, Character.isDefined(c)); + check("{javaLetter}", c, Character.isLetter(c)); + check("{javaLetterOrDigit}", c, Character.isLetterOrDigit(c)); + check("{javaJavaIdentifierStart}", c, + Character.isJavaIdentifierStart(c)); + check("{javaJavaIdentifierPart}", c, + Character.isJavaIdentifierPart(c)); + check("{javaUnicodeIdentifierStart}", c, + Character.isUnicodeIdentifierStart(c)); + check("{javaUnicodeIdentifierPart}", c, + Character.isUnicodeIdentifierPart(c)); + check("{javaIdentifierIgnorable}", c, + Character.isIdentifierIgnorable(c)); + check("{javaSpaceChar}", c, Character.isSpaceChar(c)); + check("{javaWhitespace}", c, Character.isWhitespace(c)); + check("{javaISOControl}", c, Character.isISOControl(c)); + check("{javaMirrored}", c, Character.isMirrored(c)); + + } + + // Supplementary character test + for (int i=0; i<1000; i++) { + int c = generator.nextInt(Character.MAX_CODE_POINT + - Character.MIN_SUPPLEMENTARY_CODE_POINT) + + Character.MIN_SUPPLEMENTARY_CODE_POINT; + check("{javaLowerCase}", c, Character.isLowerCase(c)); + check("{javaUpperCase}", c, Character.isUpperCase(c)); + check("{javaUpperCase}+", c, Character.isUpperCase(c)); + check("{javaTitleCase}", c, Character.isTitleCase(c)); + check("{javaDigit}", c, Character.isDigit(c)); + check("{javaDefined}", c, Character.isDefined(c)); + check("{javaLetter}", c, Character.isLetter(c)); + check("{javaLetterOrDigit}", c, Character.isLetterOrDigit(c)); + check("{javaJavaIdentifierStart}", c, + Character.isJavaIdentifierStart(c)); + check("{javaJavaIdentifierPart}", c, + Character.isJavaIdentifierPart(c)); + check("{javaUnicodeIdentifierStart}", c, + Character.isUnicodeIdentifierStart(c)); + check("{javaUnicodeIdentifierPart}", c, + Character.isUnicodeIdentifierPart(c)); + check("{javaIdentifierIgnorable}", c, + Character.isIdentifierIgnorable(c)); + check("{javaSpaceChar}", c, Character.isSpaceChar(c)); + check("{javaWhitespace}", c, Character.isWhitespace(c)); + check("{javaISOControl}", c, Character.isISOControl(c)); + check("{javaMirrored}", c, Character.isMirrored(c)); + } + + report("Java character classes"); + } + + // This test is for 4523620 + /* + private static void numOccurrencesTest() throws Exception { + Pattern pattern = Pattern.compile("aaa"); + + if (pattern.numOccurrences("aaaaaa", false) != 2) + failCount++; + if (pattern.numOccurrences("aaaaaa", true) != 4) + failCount++; + + pattern = Pattern.compile("^"); + if (pattern.numOccurrences("aaaaaa", false) != 1) + failCount++; + if (pattern.numOccurrences("aaaaaa", true) != 1) + failCount++; + + report("Number of Occurrences"); + } + */ + + // This test is for 4776374 + private static void caretBetweenTerminatorsTest() throws Exception { + int flags1 = Pattern.DOTALL; + int flags2 = Pattern.DOTALL | Pattern.UNIX_LINES; + int flags3 = Pattern.DOTALL | Pattern.UNIX_LINES | Pattern.MULTILINE; + int flags4 = Pattern.DOTALL | Pattern.MULTILINE; + + check("^....", flags1, "test\ntest", "test", true); + check(".....^", flags1, "test\ntest", "test", false); + check(".....^", flags1, "test\n", "test", false); + check("....^", flags1, "test\r\n", "test", false); + + check("^....", flags2, "test\ntest", "test", true); + check("....^", flags2, "test\ntest", "test", false); + check(".....^", flags2, "test\n", "test", false); + check("....^", flags2, "test\r\n", "test", false); + + check("^....", flags3, "test\ntest", "test", true); + check(".....^", flags3, "test\ntest", "test\n", true); + check(".....^", flags3, "test\u0085test", "test\u0085", false); + check(".....^", flags3, "test\n", "test", false); + check(".....^", flags3, "test\r\n", "test", false); + check("......^", flags3, "test\r\ntest", "test\r\n", true); + + check("^....", flags4, "test\ntest", "test", true); + check(".....^", flags3, "test\ntest", "test\n", true); + check(".....^", flags4, "test\u0085test", "test\u0085", true); + check(".....^", flags4, "test\n", "test\n", false); + check(".....^", flags4, "test\r\n", "test\r", false); + + // Supplementary character test + String t = toSupplementaries("test"); + check("^....", flags1, t+"\n"+t, t, true); + check(".....^", flags1, t+"\n"+t, t, false); + check(".....^", flags1, t+"\n", t, false); + check("....^", flags1, t+"\r\n", t, false); + + check("^....", flags2, t+"\n"+t, t, true); + check("....^", flags2, t+"\n"+t, t, false); + check(".....^", flags2, t+"\n", t, false); + check("....^", flags2, t+"\r\n", t, false); + + check("^....", flags3, t+"\n"+t, t, true); + check(".....^", flags3, t+"\n"+t, t+"\n", true); + check(".....^", flags3, t+"\u0085"+t, t+"\u0085", false); + check(".....^", flags3, t+"\n", t, false); + check(".....^", flags3, t+"\r\n", t, false); + check("......^", flags3, t+"\r\n"+t, t+"\r\n", true); + + check("^....", flags4, t+"\n"+t, t, true); + check(".....^", flags3, t+"\n"+t, t+"\n", true); + check(".....^", flags4, t+"\u0085"+t, t+"\u0085", true); + check(".....^", flags4, t+"\n", t+"\n", false); + check(".....^", flags4, t+"\r\n", t+"\r", false); + + report("Caret between terminators"); + } + + // This test is for 4727935 + private static void dollarAtEndTest() throws Exception { + int flags1 = Pattern.DOTALL; + int flags2 = Pattern.DOTALL | Pattern.UNIX_LINES; + int flags3 = Pattern.DOTALL | Pattern.MULTILINE; + + check("....$", flags1, "test\n", "test", true); + check("....$", flags1, "test\r\n", "test", true); + check(".....$", flags1, "test\n", "test\n", true); + check(".....$", flags1, "test\u0085", "test\u0085", true); + check("....$", flags1, "test\u0085", "test", true); + + check("....$", flags2, "test\n", "test", true); + check(".....$", flags2, "test\n", "test\n", true); + check(".....$", flags2, "test\u0085", "test\u0085", true); + check("....$", flags2, "test\u0085", "est\u0085", true); + + check("....$.blah", flags3, "test\nblah", "test\nblah", true); + check(".....$.blah", flags3, "test\n\nblah", "test\n\nblah", true); + check("....$blah", flags3, "test\nblah", "!!!!", false); + check(".....$blah", flags3, "test\nblah", "!!!!", false); + + // Supplementary character test + String t = toSupplementaries("test"); + String b = toSupplementaries("blah"); + check("....$", flags1, t+"\n", t, true); + check("....$", flags1, t+"\r\n", t, true); + check(".....$", flags1, t+"\n", t+"\n", true); + check(".....$", flags1, t+"\u0085", t+"\u0085", true); + check("....$", flags1, t+"\u0085", t, true); + + check("....$", flags2, t+"\n", t, true); + check(".....$", flags2, t+"\n", t+"\n", true); + check(".....$", flags2, t+"\u0085", t+"\u0085", true); + check("....$", flags2, t+"\u0085", toSupplementaries("est\u0085"), true); + + check("....$."+b, flags3, t+"\n"+b, t+"\n"+b, true); + check(".....$."+b, flags3, t+"\n\n"+b, t+"\n\n"+b, true); + check("....$"+b, flags3, t+"\n"+b, "!!!!", false); + check(".....$"+b, flags3, t+"\n"+b, "!!!!", false); + + report("Dollar at End"); + } + + // This test is for 4711773 + private static void multilineDollarTest() throws Exception { + Pattern findCR = Pattern.compile("$", Pattern.MULTILINE); + Matcher matcher = findCR.matcher("first bit\nsecond bit"); + matcher.find(); + if (matcher.start(0) != 9) + failCount++; + matcher.find(); + if (matcher.start(0) != 20) + failCount++; + + // Supplementary character test + matcher = findCR.matcher(toSupplementaries("first bit\n second bit")); // double BMP chars + matcher.find(); + if (matcher.start(0) != 9*2) + failCount++; + matcher.find(); + if (matcher.start(0) != 20*2) + failCount++; + + report("Multiline Dollar"); + } + + private static void reluctantRepetitionTest() throws Exception { + Pattern p = Pattern.compile("1(\\s\\S+?){1,3}?[\\s,]2"); + check(p, "1 word word word 2", true); + check(p, "1 wor wo w 2", true); + check(p, "1 word word 2", true); + check(p, "1 word 2", true); + check(p, "1 wo w w 2", true); + check(p, "1 wo w 2", true); + check(p, "1 wor w 2", true); + + p = Pattern.compile("([a-z])+?c"); + Matcher m = p.matcher("ababcdefdec"); + check(m, "ababc"); + + // Supplementary character test + p = Pattern.compile(toSupplementaries("([a-z])+?c")); + m = p.matcher(toSupplementaries("ababcdefdec")); + check(m, toSupplementaries("ababc")); + + report("Reluctant Repetition"); + } + + private static void serializeTest() throws Exception { + String patternStr = "(b)"; + String matchStr = "b"; + Pattern pattern = Pattern.compile(patternStr); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + ObjectOutputStream oos = new ObjectOutputStream(baos); + oos.writeObject(pattern); + oos.close(); + ObjectInputStream ois = new ObjectInputStream( + new ByteArrayInputStream(baos.toByteArray())); + Pattern serializedPattern = (Pattern)ois.readObject(); + ois.close(); + Matcher matcher = serializedPattern.matcher(matchStr); + if (!matcher.matches()) + failCount++; + if (matcher.groupCount() != 1) + failCount++; + + report("Serialization"); + } + + private static void gTest() { + Pattern pattern = Pattern.compile("\\G\\w"); + Matcher matcher = pattern.matcher("abc#x#x"); + matcher.find(); + matcher.find(); + matcher.find(); + if (matcher.find()) + failCount++; + + pattern = Pattern.compile("\\GA*"); + matcher = pattern.matcher("1A2AA3"); + matcher.find(); + if (matcher.find()) + failCount++; + + pattern = Pattern.compile("\\GA*"); + matcher = pattern.matcher("1A2AA3"); + if (!matcher.find(1)) + failCount++; + matcher.find(); + if (matcher.find()) + failCount++; + + report("\\G"); + } + + private static void zTest() { + Pattern pattern = Pattern.compile("foo\\Z"); + // Positives + check(pattern, "foo\u0085", true); + check(pattern, "foo\u2028", true); + check(pattern, "foo\u2029", true); + check(pattern, "foo\n", true); + check(pattern, "foo\r", true); + check(pattern, "foo\r\n", true); + // Negatives + check(pattern, "fooo", false); + check(pattern, "foo\n\r", false); + + pattern = Pattern.compile("foo\\Z", Pattern.UNIX_LINES); + // Positives + check(pattern, "foo", true); + check(pattern, "foo\n", true); + // Negatives + check(pattern, "foo\r", false); + check(pattern, "foo\u0085", false); + check(pattern, "foo\u2028", false); + check(pattern, "foo\u2029", false); + + report("\\Z"); + } + + private static void replaceFirstTest() { + Pattern pattern = Pattern.compile("(ab)(c*)"); + Matcher matcher = pattern.matcher("abccczzzabcczzzabccc"); + if (!matcher.replaceFirst("test").equals("testzzzabcczzzabccc")) + failCount++; + + matcher.reset("zzzabccczzzabcczzzabccczzz"); + if (!matcher.replaceFirst("test").equals("zzztestzzzabcczzzabccczzz")) + failCount++; + + matcher.reset("zzzabccczzzabcczzzabccczzz"); + String result = matcher.replaceFirst("$1"); + if (!result.equals("zzzabzzzabcczzzabccczzz")) + failCount++; + + matcher.reset("zzzabccczzzabcczzzabccczzz"); + result = matcher.replaceFirst("$2"); + if (!result.equals("zzzccczzzabcczzzabccczzz")) + failCount++; + + pattern = Pattern.compile("a*"); + matcher = pattern.matcher("aaaaaaaaaa"); + if (!matcher.replaceFirst("test").equals("test")) + failCount++; + + pattern = Pattern.compile("a+"); + matcher = pattern.matcher("zzzaaaaaaaaaa"); + if (!matcher.replaceFirst("test").equals("zzztest")) + failCount++; + + // Supplementary character test + pattern = Pattern.compile(toSupplementaries("(ab)(c*)")); + matcher = pattern.matcher(toSupplementaries("abccczzzabcczzzabccc")); + if (!matcher.replaceFirst(toSupplementaries("test")) + .equals(toSupplementaries("testzzzabcczzzabccc"))) + failCount++; + + matcher.reset(toSupplementaries("zzzabccczzzabcczzzabccczzz")); + if (!matcher.replaceFirst(toSupplementaries("test")). + equals(toSupplementaries("zzztestzzzabcczzzabccczzz"))) + failCount++; + + matcher.reset(toSupplementaries("zzzabccczzzabcczzzabccczzz")); + result = matcher.replaceFirst("$1"); + if (!result.equals(toSupplementaries("zzzabzzzabcczzzabccczzz"))) + failCount++; + + matcher.reset(toSupplementaries("zzzabccczzzabcczzzabccczzz")); + result = matcher.replaceFirst("$2"); + if (!result.equals(toSupplementaries("zzzccczzzabcczzzabccczzz"))) + failCount++; + + pattern = Pattern.compile(toSupplementaries("a*")); + matcher = pattern.matcher(toSupplementaries("aaaaaaaaaa")); + if (!matcher.replaceFirst(toSupplementaries("test")).equals(toSupplementaries("test"))) + failCount++; + + pattern = Pattern.compile(toSupplementaries("a+")); + matcher = pattern.matcher(toSupplementaries("zzzaaaaaaaaaa")); + if (!matcher.replaceFirst(toSupplementaries("test")).equals(toSupplementaries("zzztest"))) + failCount++; + + report("Replace First"); + } + + private static void unixLinesTest() { + Pattern pattern = Pattern.compile(".*"); + Matcher matcher = pattern.matcher("aa\u2028blah"); + matcher.find(); + if (!matcher.group(0).equals("aa")) + failCount++; + + pattern = Pattern.compile(".*", Pattern.UNIX_LINES); + matcher = pattern.matcher("aa\u2028blah"); + matcher.find(); + if (!matcher.group(0).equals("aa\u2028blah")) + failCount++; + + pattern = Pattern.compile("[az]$", + Pattern.MULTILINE | Pattern.UNIX_LINES); + matcher = pattern.matcher("aa\u2028zz"); + check(matcher, "a\u2028", false); + + // Supplementary character test + pattern = Pattern.compile(".*"); + matcher = pattern.matcher(toSupplementaries("aa\u2028blah")); + matcher.find(); + if (!matcher.group(0).equals(toSupplementaries("aa"))) + failCount++; + + pattern = Pattern.compile(".*", Pattern.UNIX_LINES); + matcher = pattern.matcher(toSupplementaries("aa\u2028blah")); + matcher.find(); + if (!matcher.group(0).equals(toSupplementaries("aa\u2028blah"))) + failCount++; + + pattern = Pattern.compile(toSupplementaries("[az]$"), + Pattern.MULTILINE | Pattern.UNIX_LINES); + matcher = pattern.matcher(toSupplementaries("aa\u2028zz")); + check(matcher, toSupplementaries("a\u2028"), false); + + report("Unix Lines"); + } + + private static void commentsTest() { + int flags = Pattern.COMMENTS; + + Pattern pattern = Pattern.compile("aa \\# aa", flags); + Matcher matcher = pattern.matcher("aa#aa"); + if (!matcher.matches()) + failCount++; + + pattern = Pattern.compile("aa # blah", flags); + matcher = pattern.matcher("aa"); + if (!matcher.matches()) + failCount++; + + pattern = Pattern.compile("aa blah", flags); + matcher = pattern.matcher("aablah"); + if (!matcher.matches()) + failCount++; + + pattern = Pattern.compile("aa # blah blech ", flags); + matcher = pattern.matcher("aa"); + if (!matcher.matches()) + failCount++; + + pattern = Pattern.compile("aa # blah\n ", flags); + matcher = pattern.matcher("aa"); + if (!matcher.matches()) + failCount++; + + pattern = Pattern.compile("aa # blah\nbc # blech", flags); + matcher = pattern.matcher("aabc"); + if (!matcher.matches()) + failCount++; + + pattern = Pattern.compile("aa # blah\nbc# blech", flags); + matcher = pattern.matcher("aabc"); + if (!matcher.matches()) + failCount++; + + pattern = Pattern.compile("aa # blah\nbc\\# blech", flags); + matcher = pattern.matcher("aabc#blech"); + if (!matcher.matches()) + failCount++; + + // Supplementary character test + pattern = Pattern.compile(toSupplementaries("aa \\# aa"), flags); + matcher = pattern.matcher(toSupplementaries("aa#aa")); + if (!matcher.matches()) + failCount++; + + pattern = Pattern.compile(toSupplementaries("aa # blah"), flags); + matcher = pattern.matcher(toSupplementaries("aa")); + if (!matcher.matches()) + failCount++; + + pattern = Pattern.compile(toSupplementaries("aa blah"), flags); + matcher = pattern.matcher(toSupplementaries("aablah")); + if (!matcher.matches()) + failCount++; + + pattern = Pattern.compile(toSupplementaries("aa # blah blech "), flags); + matcher = pattern.matcher(toSupplementaries("aa")); + if (!matcher.matches()) + failCount++; + + pattern = Pattern.compile(toSupplementaries("aa # blah\n "), flags); + matcher = pattern.matcher(toSupplementaries("aa")); + if (!matcher.matches()) + failCount++; + + pattern = Pattern.compile(toSupplementaries("aa # blah\nbc # blech"), flags); + matcher = pattern.matcher(toSupplementaries("aabc")); + if (!matcher.matches()) + failCount++; + + pattern = Pattern.compile(toSupplementaries("aa # blah\nbc# blech"), flags); + matcher = pattern.matcher(toSupplementaries("aabc")); + if (!matcher.matches()) + failCount++; + + pattern = Pattern.compile(toSupplementaries("aa # blah\nbc\\# blech"), flags); + matcher = pattern.matcher(toSupplementaries("aabc#blech")); + if (!matcher.matches()) + failCount++; + + report("Comments"); + } + + private static void caseFoldingTest() { // bug 4504687 + int flags = Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE; + Pattern pattern = Pattern.compile("aa", flags); + Matcher matcher = pattern.matcher("ab"); + if (matcher.matches()) + failCount++; + + pattern = Pattern.compile("aA", flags); + matcher = pattern.matcher("ab"); + if (matcher.matches()) + failCount++; + + pattern = Pattern.compile("aa", flags); + matcher = pattern.matcher("aB"); + if (matcher.matches()) + failCount++; + matcher = pattern.matcher("Ab"); + if (matcher.matches()) + failCount++; + + // ASCII "a" + // Latin-1 Supplement "a" + grave + // Cyrillic "a" + String[] patterns = new String[] { + //single + "a", "\u00e0", "\u0430", + //slice + "ab", "\u00e0\u00e1", "\u0430\u0431", + //class single + "[a]", "[\u00e0]", "[\u0430]", + //class range + "[a-b]", "[\u00e0-\u00e5]", "[\u0430-\u0431]", + //back reference + "(a)\\1", "(\u00e0)\\1", "(\u0430)\\1" + }; + + String[] texts = new String[] { + "A", "\u00c0", "\u0410", + "AB", "\u00c0\u00c1", "\u0410\u0411", + "A", "\u00c0", "\u0410", + "B", "\u00c2", "\u0411", + "aA", "\u00e0\u00c0", "\u0430\u0410" + }; + + boolean[] expected = new boolean[] { + true, false, false, + true, false, false, + true, false, false, + true, false, false, + true, false, false + }; + + flags = Pattern.CASE_INSENSITIVE; + for (int i = 0; i < patterns.length; i++) { + pattern = Pattern.compile(patterns[i], flags); + matcher = pattern.matcher(texts[i]); + if (matcher.matches() != expected[i]) { + System.out.println("<1> Failed at " + i); + failCount++; + } + } + + flags = Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE; + for (int i = 0; i < patterns.length; i++) { + pattern = Pattern.compile(patterns[i], flags); + matcher = pattern.matcher(texts[i]); + if (!matcher.matches()) { + System.out.println("<2> Failed at " + i); + failCount++; + } + } + // flag unicode_case alone should do nothing + flags = Pattern.UNICODE_CASE; + for (int i = 0; i < patterns.length; i++) { + pattern = Pattern.compile(patterns[i], flags); + matcher = pattern.matcher(texts[i]); + if (matcher.matches()) { + System.out.println("<3> Failed at " + i); + failCount++; + } + } + + // Special cases: i, I, u+0131 and u+0130 + flags = Pattern.UNICODE_CASE | Pattern.CASE_INSENSITIVE; + pattern = Pattern.compile("[h-j]+", flags); + if (!pattern.matcher("\u0131\u0130").matches()) + failCount++; + report("Case Folding"); + } + + private static void appendTest() { + Pattern pattern = Pattern.compile("(ab)(cd)"); + Matcher matcher = pattern.matcher("abcd"); + String result = matcher.replaceAll("$2$1"); + if (!result.equals("cdab")) + failCount++; + + String s1 = "Swap all: first = 123, second = 456"; + String s2 = "Swap one: first = 123, second = 456"; + String r = "$3$2$1"; + pattern = Pattern.compile("([a-z]+)( *= *)([0-9]+)"); + matcher = pattern.matcher(s1); + + result = matcher.replaceAll(r); + if (!result.equals("Swap all: 123 = first, 456 = second")) + failCount++; + + matcher = pattern.matcher(s2); + + if (matcher.find()) { + StringBuffer sb = new StringBuffer(); + matcher.appendReplacement(sb, r); + matcher.appendTail(sb); + result = sb.toString(); + if (!result.equals("Swap one: 123 = first, second = 456")) + failCount++; + } + + // Supplementary character test + pattern = Pattern.compile(toSupplementaries("(ab)(cd)")); + matcher = pattern.matcher(toSupplementaries("abcd")); + result = matcher.replaceAll("$2$1"); + if (!result.equals(toSupplementaries("cdab"))) + failCount++; + + s1 = toSupplementaries("Swap all: first = 123, second = 456"); + s2 = toSupplementaries("Swap one: first = 123, second = 456"); + r = toSupplementaries("$3$2$1"); + pattern = Pattern.compile(toSupplementaries("([a-z]+)( *= *)([0-9]+)")); + matcher = pattern.matcher(s1); + + result = matcher.replaceAll(r); + if (!result.equals(toSupplementaries("Swap all: 123 = first, 456 = second"))) + failCount++; + + matcher = pattern.matcher(s2); + + if (matcher.find()) { + StringBuffer sb = new StringBuffer(); + matcher.appendReplacement(sb, r); + matcher.appendTail(sb); + result = sb.toString(); + if (!result.equals(toSupplementaries("Swap one: 123 = first, second = 456"))) + failCount++; + } + report("Append"); + } + + private static void splitTest() { + Pattern pattern = Pattern.compile(":"); + String[] result = pattern.split("foo:and:boo", 2); + if (!result[0].equals("foo")) + failCount++; + if (!result[1].equals("and:boo")) + failCount++; + // Supplementary character test + Pattern patternX = Pattern.compile(toSupplementaries("X")); + result = patternX.split(toSupplementaries("fooXandXboo"), 2); + if (!result[0].equals(toSupplementaries("foo"))) + failCount++; + if (!result[1].equals(toSupplementaries("andXboo"))) + failCount++; + + CharBuffer cb = CharBuffer.allocate(100); + cb.put("foo:and:boo"); + cb.flip(); + result = pattern.split(cb); + if (!result[0].equals("foo")) + failCount++; + if (!result[1].equals("and")) + failCount++; + if (!result[2].equals("boo")) + failCount++; + + // Supplementary character test + CharBuffer cbs = CharBuffer.allocate(100); + cbs.put(toSupplementaries("fooXandXboo")); + cbs.flip(); + result = patternX.split(cbs); + if (!result[0].equals(toSupplementaries("foo"))) + failCount++; + if (!result[1].equals(toSupplementaries("and"))) + failCount++; + if (!result[2].equals(toSupplementaries("boo"))) + failCount++; + + String source = "0123456789"; + for (int limit=-2; limit<3; limit++) { + for (int x=0; x<10; x++) { + result = source.split(Integer.toString(x), limit); + int expectedLength = limit < 1 ? 2 : limit; + + if ((limit == 0) && (x == 9)) { + // expected dropping of "" + if (result.length != 1) + failCount++; + if (!result[0].equals("012345678")) { + failCount++; + } + } else { + if (result.length != expectedLength) { + failCount++; + } + if (!result[0].equals(source.substring(0,x))) { + if (limit != 1) { + failCount++; + } else { + if (!result[0].equals(source.substring(0,10))) { + failCount++; + } + } + } + if (expectedLength > 1) { // Check segment 2 + if (!result[1].equals(source.substring(x+1,10))) + failCount++; + } + } + } + } + // Check the case for no match found + for (int limit=-2; limit<3; limit++) { + result = source.split("e", limit); + if (result.length != 1) + failCount++; + if (!result[0].equals(source)) + failCount++; + } + // Check the case for limit == 0, source = ""; + source = ""; + result = source.split("e", 0); + if (result.length != 1) + failCount++; + if (!result[0].equals(source)) + failCount++; + + report("Split"); + } + + private static void negationTest() { + Pattern pattern = Pattern.compile("[\\[@^]+"); + Matcher matcher = pattern.matcher("@@@@[[[[^^^^"); + if (!matcher.find()) + failCount++; + if (!matcher.group(0).equals("@@@@[[[[^^^^")) + failCount++; + pattern = Pattern.compile("[@\\[^]+"); + matcher = pattern.matcher("@@@@[[[[^^^^"); + if (!matcher.find()) + failCount++; + if (!matcher.group(0).equals("@@@@[[[[^^^^")) + failCount++; + pattern = Pattern.compile("[@\\[^@]+"); + matcher = pattern.matcher("@@@@[[[[^^^^"); + if (!matcher.find()) + failCount++; + if (!matcher.group(0).equals("@@@@[[[[^^^^")) + failCount++; + + pattern = Pattern.compile("\\)"); + matcher = pattern.matcher("xxx)xxx"); + if (!matcher.find()) + failCount++; + + report("Negation"); + } + + private static void ampersandTest() { + Pattern pattern = Pattern.compile("[&@]+"); + check(pattern, "@@@@&&&&", true); + + pattern = Pattern.compile("[@&]+"); + check(pattern, "@@@@&&&&", true); + + pattern = Pattern.compile("[@\\&]+"); + check(pattern, "@@@@&&&&", true); + + report("Ampersand"); + } + + private static void octalTest() throws Exception { + Pattern pattern = Pattern.compile("\\u0007"); + Matcher matcher = pattern.matcher("\u0007"); + if (!matcher.matches()) + failCount++; + pattern = Pattern.compile("\\07"); + matcher = pattern.matcher("\u0007"); + if (!matcher.matches()) + failCount++; + pattern = Pattern.compile("\\007"); + matcher = pattern.matcher("\u0007"); + if (!matcher.matches()) + failCount++; + pattern = Pattern.compile("\\0007"); + matcher = pattern.matcher("\u0007"); + if (!matcher.matches()) + failCount++; + pattern = Pattern.compile("\\040"); + matcher = pattern.matcher("\u0020"); + if (!matcher.matches()) + failCount++; + pattern = Pattern.compile("\\0403"); + matcher = pattern.matcher("\u00203"); + if (!matcher.matches()) + failCount++; + pattern = Pattern.compile("\\0103"); + matcher = pattern.matcher("\u0043"); + if (!matcher.matches()) + failCount++; + + report("Octal"); + } + + private static void longPatternTest() throws Exception { + try { + Pattern pattern = Pattern.compile( + "a 32-character-long pattern xxxx"); + pattern = Pattern.compile("a 33-character-long pattern xxxxx"); + pattern = Pattern.compile("a thirty four character long regex"); + StringBuffer patternToBe = new StringBuffer(101); + for (int i=0; i<100; i++) + patternToBe.append((char)(97 + i%26)); + pattern = Pattern.compile(patternToBe.toString()); + } catch (PatternSyntaxException e) { + failCount++; + } + + // Supplementary character test + try { + Pattern pattern = Pattern.compile( + toSupplementaries("a 32-character-long pattern xxxx")); + pattern = Pattern.compile(toSupplementaries("a 33-character-long pattern xxxxx")); + pattern = Pattern.compile(toSupplementaries("a thirty four character long regex")); + StringBuffer patternToBe = new StringBuffer(101*2); + for (int i=0; i<100; i++) + patternToBe.append(Character.toChars(Character.MIN_SUPPLEMENTARY_CODE_POINT + + 97 + i%26)); + pattern = Pattern.compile(patternToBe.toString()); + } catch (PatternSyntaxException e) { + failCount++; + } + report("LongPattern"); + } + + private static void group0Test() throws Exception { + Pattern pattern = Pattern.compile("(tes)ting"); + Matcher matcher = pattern.matcher("testing"); + check(matcher, "testing"); + + matcher.reset("testing"); + if (matcher.lookingAt()) { + if (!matcher.group(0).equals("testing")) + failCount++; + } else { + failCount++; + } + + matcher.reset("testing"); + if (matcher.matches()) { + if (!matcher.group(0).equals("testing")) + failCount++; + } else { + failCount++; + } + + pattern = Pattern.compile("(tes)ting"); + matcher = pattern.matcher("testing"); + if (matcher.lookingAt()) { + if (!matcher.group(0).equals("testing")) + failCount++; + } else { + failCount++; + } + + pattern = Pattern.compile("^(tes)ting"); + matcher = pattern.matcher("testing"); + if (matcher.matches()) { + if (!matcher.group(0).equals("testing")) + failCount++; + } else { + failCount++; + } + + // Supplementary character test + pattern = Pattern.compile(toSupplementaries("(tes)ting")); + matcher = pattern.matcher(toSupplementaries("testing")); + check(matcher, toSupplementaries("testing")); + + matcher.reset(toSupplementaries("testing")); + if (matcher.lookingAt()) { + if (!matcher.group(0).equals(toSupplementaries("testing"))) + failCount++; + } else { + failCount++; + } + + matcher.reset(toSupplementaries("testing")); + if (matcher.matches()) { + if (!matcher.group(0).equals(toSupplementaries("testing"))) + failCount++; + } else { + failCount++; + } + + pattern = Pattern.compile(toSupplementaries("(tes)ting")); + matcher = pattern.matcher(toSupplementaries("testing")); + if (matcher.lookingAt()) { + if (!matcher.group(0).equals(toSupplementaries("testing"))) + failCount++; + } else { + failCount++; + } + + pattern = Pattern.compile(toSupplementaries("^(tes)ting")); + matcher = pattern.matcher(toSupplementaries("testing")); + if (matcher.matches()) { + if (!matcher.group(0).equals(toSupplementaries("testing"))) + failCount++; + } else { + failCount++; + } + + report("Group0"); + } + + private static void findIntTest() throws Exception { + Pattern p = Pattern.compile("blah"); + Matcher m = p.matcher("zzzzblahzzzzzblah"); + boolean result = m.find(2); + if (!result) + failCount++; + + p = Pattern.compile("$"); + m = p.matcher("1234567890"); + result = m.find(10); + if (!result) + failCount++; + try { + result = m.find(11); + failCount++; + } catch (IndexOutOfBoundsException e) { + // correct result + } + + // Supplementary character test + p = Pattern.compile(toSupplementaries("blah")); + m = p.matcher(toSupplementaries("zzzzblahzzzzzblah")); + result = m.find(2); + if (!result) + failCount++; + + report("FindInt"); + } + + private static void emptyPatternTest() throws Exception { + Pattern p = Pattern.compile(""); + Matcher m = p.matcher("foo"); + + // Should find empty pattern at beginning of input + boolean result = m.find(); + if (result != true) + failCount++; + if (m.start() != 0) + failCount++; + + // Should not match entire input if input is not empty + m.reset(); + result = m.matches(); + if (result == true) + failCount++; + + try { + m.start(0); + failCount++; + } catch (IllegalStateException e) { + // Correct result + } + + // Should match entire input if input is empty + m.reset(""); + result = m.matches(); + if (result != true) + failCount++; + + result = Pattern.matches("", ""); + if (result != true) + failCount++; + + result = Pattern.matches("", "foo"); + if (result == true) + failCount++; + report("EmptyPattern"); + } + + private static void charClassTest() throws Exception { + Pattern pattern = Pattern.compile("blah[ab]]blech"); + check(pattern, "blahb]blech", true); + + pattern = Pattern.compile("[abc[def]]"); + check(pattern, "b", true); + + // Supplementary character tests + pattern = Pattern.compile(toSupplementaries("blah[ab]]blech")); + check(pattern, toSupplementaries("blahb]blech"), true); + + pattern = Pattern.compile(toSupplementaries("[abc[def]]")); + check(pattern, toSupplementaries("b"), true); + + try { + // u00ff when UNICODE_CASE + pattern = Pattern.compile("[ab\u00ffcd]", + Pattern.CASE_INSENSITIVE| + Pattern.UNICODE_CASE); + check(pattern, "ab\u00ffcd", true); + check(pattern, "Ab\u0178Cd", true); + + // u00b5 when UNICODE_CASE + pattern = Pattern.compile("[ab\u00b5cd]", + Pattern.CASE_INSENSITIVE| + Pattern.UNICODE_CASE); + check(pattern, "ab\u00b5cd", true); + check(pattern, "Ab\u039cCd", true); + } catch (Exception e) { failCount++; } + + /* Special cases + (1)LatinSmallLetterLongS u+017f + (2)LatinSmallLetterDotlessI u+0131 + (3)LatineCapitalLetterIWithDotAbove u+0130 + (4)KelvinSign u+212a + (5)AngstromSign u+212b + */ + int flags = Pattern.UNICODE_CASE | Pattern.CASE_INSENSITIVE; + pattern = Pattern.compile("[sik\u00c5]+", flags); + if (!pattern.matcher("\u017f\u0130\u0131\u212a\u212b").matches()) + failCount++; + + report("CharClass"); + } + + private static void caretTest() throws Exception { + Pattern pattern = Pattern.compile("\\w*"); + Matcher matcher = pattern.matcher("a#bc#def##g"); + check(matcher, "a"); + check(matcher, ""); + check(matcher, "bc"); + check(matcher, ""); + check(matcher, "def"); + check(matcher, ""); + check(matcher, ""); + check(matcher, "g"); + check(matcher, ""); + if (matcher.find()) + failCount++; + + pattern = Pattern.compile("^\\w*"); + matcher = pattern.matcher("a#bc#def##g"); + check(matcher, "a"); + if (matcher.find()) + failCount++; + + pattern = Pattern.compile("\\w"); + matcher = pattern.matcher("abc##x"); + check(matcher, "a"); + check(matcher, "b"); + check(matcher, "c"); + check(matcher, "x"); + if (matcher.find()) + failCount++; + + pattern = Pattern.compile("^\\w"); + matcher = pattern.matcher("abc##x"); + check(matcher, "a"); + if (matcher.find()) + failCount++; + + pattern = Pattern.compile("\\A\\p{Alpha}{3}"); + matcher = pattern.matcher("abcdef-ghi\njklmno"); + check(matcher, "abc"); + if (matcher.find()) + failCount++; + + pattern = Pattern.compile("^\\p{Alpha}{3}", Pattern.MULTILINE); + matcher = pattern.matcher("abcdef-ghi\njklmno"); + check(matcher, "abc"); + check(matcher, "jkl"); + if (matcher.find()) + failCount++; + + pattern = Pattern.compile("^", Pattern.MULTILINE); + matcher = pattern.matcher("this is some text"); + String result = matcher.replaceAll("X"); + if (!result.equals("Xthis is some text")) + failCount++; + + pattern = Pattern.compile("^"); + matcher = pattern.matcher("this is some text"); + result = matcher.replaceAll("X"); + if (!result.equals("Xthis is some text")) + failCount++; + + pattern = Pattern.compile("^", Pattern.MULTILINE | Pattern.UNIX_LINES); + matcher = pattern.matcher("this is some text\n"); + result = matcher.replaceAll("X"); + if (!result.equals("Xthis is some text\n")) + failCount++; + + report("Caret"); + } + + private static void groupCaptureTest() throws Exception { + // Independent group + Pattern pattern = Pattern.compile("x+(?>y+)z+"); + Matcher matcher = pattern.matcher("xxxyyyzzz"); + matcher.find(); + try { + String blah = matcher.group(1); + failCount++; + } catch (IndexOutOfBoundsException ioobe) { + // Good result + } + // Pure group + pattern = Pattern.compile("x+(?:y+)z+"); + matcher = pattern.matcher("xxxyyyzzz"); + matcher.find(); + try { + String blah = matcher.group(1); + failCount++; + } catch (IndexOutOfBoundsException ioobe) { + // Good result + } + + // Supplementary character tests + // Independent group + pattern = Pattern.compile(toSupplementaries("x+(?>y+)z+")); + matcher = pattern.matcher(toSupplementaries("xxxyyyzzz")); + matcher.find(); + try { + String blah = matcher.group(1); + failCount++; + } catch (IndexOutOfBoundsException ioobe) { + // Good result + } + // Pure group + pattern = Pattern.compile(toSupplementaries("x+(?:y+)z+")); + matcher = pattern.matcher(toSupplementaries("xxxyyyzzz")); + matcher.find(); + try { + String blah = matcher.group(1); + failCount++; + } catch (IndexOutOfBoundsException ioobe) { + // Good result + } + + report("GroupCapture"); + } + + private static void backRefTest() throws Exception { + Pattern pattern = Pattern.compile("(a*)bc\\1"); + check(pattern, "zzzaabcazzz", true); + + pattern = Pattern.compile("(a*)bc\\1"); + check(pattern, "zzzaabcaazzz", true); + + pattern = Pattern.compile("(abc)(def)\\1"); + check(pattern, "abcdefabc", true); + + pattern = Pattern.compile("(abc)(def)\\3"); + check(pattern, "abcdefabc", false); + + try { + for (int i = 1; i < 10; i++) { + // Make sure backref 1-9 are always accepted + pattern = Pattern.compile("abcdef\\" + i); + // and fail to match if the target group does not exit + check(pattern, "abcdef", false); + } + } catch(PatternSyntaxException e) { + failCount++; + } + + pattern = Pattern.compile("(a)(b)(c)(d)(e)(f)(g)(h)(i)(j)\\11"); + check(pattern, "abcdefghija", false); + check(pattern, "abcdefghija1", true); + + pattern = Pattern.compile("(a)(b)(c)(d)(e)(f)(g)(h)(i)(j)(k)\\11"); + check(pattern, "abcdefghijkk", true); + + pattern = Pattern.compile("(a)bcdefghij\\11"); + check(pattern, "abcdefghija1", true); + + // Supplementary character tests + pattern = Pattern.compile(toSupplementaries("(a*)bc\\1")); + check(pattern, toSupplementaries("zzzaabcazzz"), true); + + pattern = Pattern.compile(toSupplementaries("(a*)bc\\1")); + check(pattern, toSupplementaries("zzzaabcaazzz"), true); + + pattern = Pattern.compile(toSupplementaries("(abc)(def)\\1")); + check(pattern, toSupplementaries("abcdefabc"), true); + + pattern = Pattern.compile(toSupplementaries("(abc)(def)\\3")); + check(pattern, toSupplementaries("abcdefabc"), false); + + pattern = Pattern.compile(toSupplementaries("(a)(b)(c)(d)(e)(f)(g)(h)(i)(j)\\11")); + check(pattern, toSupplementaries("abcdefghija"), false); + check(pattern, toSupplementaries("abcdefghija1"), true); + + pattern = Pattern.compile(toSupplementaries("(a)(b)(c)(d)(e)(f)(g)(h)(i)(j)(k)\\11")); + check(pattern, toSupplementaries("abcdefghijkk"), true); + + report("BackRef"); + } + + /** + * Unicode Technical Report #18, section 2.6 End of Line + * There is no empty line to be matched in the sequence \u000D\u000A + * but there is an empty line in the sequence \u000A\u000D. + */ + private static void anchorTest() throws Exception { + Pattern p = Pattern.compile("^.*$", Pattern.MULTILINE); + Matcher m = p.matcher("blah1\r\nblah2"); + m.find(); + m.find(); + if (!m.group().equals("blah2")) + failCount++; + + m.reset("blah1\n\rblah2"); + m.find(); + m.find(); + m.find(); + if (!m.group().equals("blah2")) + failCount++; + + // Test behavior of $ with \r\n at end of input + p = Pattern.compile(".+$"); + m = p.matcher("blah1\r\n"); + if (!m.find()) + failCount++; + if (!m.group().equals("blah1")) + failCount++; + if (m.find()) + failCount++; + + // Test behavior of $ with \r\n at end of input in multiline + p = Pattern.compile(".+$", Pattern.MULTILINE); + m = p.matcher("blah1\r\n"); + if (!m.find()) + failCount++; + if (m.find()) + failCount++; + + // Test for $ recognition of \u0085 for bug 4527731 + p = Pattern.compile(".+$", Pattern.MULTILINE); + m = p.matcher("blah1\u0085"); + if (!m.find()) + failCount++; + + // Supplementary character test + p = Pattern.compile("^.*$", Pattern.MULTILINE); + m = p.matcher(toSupplementaries("blah1\r\nblah2")); + m.find(); + m.find(); + if (!m.group().equals(toSupplementaries("blah2"))) + failCount++; + + m.reset(toSupplementaries("blah1\n\rblah2")); + m.find(); + m.find(); + m.find(); + if (!m.group().equals(toSupplementaries("blah2"))) + failCount++; + + // Test behavior of $ with \r\n at end of input + p = Pattern.compile(".+$"); + m = p.matcher(toSupplementaries("blah1\r\n")); + if (!m.find()) + failCount++; + if (!m.group().equals(toSupplementaries("blah1"))) + failCount++; + if (m.find()) + failCount++; + + // Test behavior of $ with \r\n at end of input in multiline + p = Pattern.compile(".+$", Pattern.MULTILINE); + m = p.matcher(toSupplementaries("blah1\r\n")); + if (!m.find()) + failCount++; + if (m.find()) + failCount++; + + // Test for $ recognition of \u0085 for bug 4527731 + p = Pattern.compile(".+$", Pattern.MULTILINE); + m = p.matcher(toSupplementaries("blah1\u0085")); + if (!m.find()) + failCount++; + + report("Anchors"); + } + + /** + * A basic sanity test of Matcher.lookingAt(). + */ + private static void lookingAtTest() throws Exception { + Pattern p = Pattern.compile("(ab)(c*)"); + Matcher m = p.matcher("abccczzzabcczzzabccc"); + + if (!m.lookingAt()) + failCount++; + + if (!m.group().equals(m.group(0))) + failCount++; + + m = p.matcher("zzzabccczzzabcczzzabccczzz"); + if (m.lookingAt()) + failCount++; + + // Supplementary character test + p = Pattern.compile(toSupplementaries("(ab)(c*)")); + m = p.matcher(toSupplementaries("abccczzzabcczzzabccc")); + + if (!m.lookingAt()) + failCount++; + + if (!m.group().equals(m.group(0))) + failCount++; + + m = p.matcher(toSupplementaries("zzzabccczzzabcczzzabccczzz")); + if (m.lookingAt()) + failCount++; + + report("Looking At"); + } + + /** + * A basic sanity test of Matcher.matches(). + */ + private static void matchesTest() throws Exception { + // matches() + Pattern p = Pattern.compile("ulb(c*)"); + Matcher m = p.matcher("ulbcccccc"); + if (!m.matches()) + failCount++; + + // find() but not matches() + m.reset("zzzulbcccccc"); + if (m.matches()) + failCount++; + + // lookingAt() but not matches() + m.reset("ulbccccccdef"); + if (m.matches()) + failCount++; + + // matches() + p = Pattern.compile("a|ad"); + m = p.matcher("ad"); + if (!m.matches()) + failCount++; + + // Supplementary character test + // matches() + p = Pattern.compile(toSupplementaries("ulb(c*)")); + m = p.matcher(toSupplementaries("ulbcccccc")); + if (!m.matches()) + failCount++; + + // find() but not matches() + m.reset(toSupplementaries("zzzulbcccccc")); + if (m.matches()) + failCount++; + + // lookingAt() but not matches() + m.reset(toSupplementaries("ulbccccccdef")); + if (m.matches()) + failCount++; + + // matches() + p = Pattern.compile(toSupplementaries("a|ad")); + m = p.matcher(toSupplementaries("ad")); + if (!m.matches()) + failCount++; + + report("Matches"); + } + + /** + * A basic sanity test of Pattern.matches(). + */ + private static void patternMatchesTest() throws Exception { + // matches() + if (!Pattern.matches(toSupplementaries("ulb(c*)"), + toSupplementaries("ulbcccccc"))) + failCount++; + + // find() but not matches() + if (Pattern.matches(toSupplementaries("ulb(c*)"), + toSupplementaries("zzzulbcccccc"))) + failCount++; + + // lookingAt() but not matches() + if (Pattern.matches(toSupplementaries("ulb(c*)"), + toSupplementaries("ulbccccccdef"))) + failCount++; + + // Supplementary character test + // matches() + if (!Pattern.matches(toSupplementaries("ulb(c*)"), + toSupplementaries("ulbcccccc"))) + failCount++; + + // find() but not matches() + if (Pattern.matches(toSupplementaries("ulb(c*)"), + toSupplementaries("zzzulbcccccc"))) + failCount++; + + // lookingAt() but not matches() + if (Pattern.matches(toSupplementaries("ulb(c*)"), + toSupplementaries("ulbccccccdef"))) + failCount++; + + report("Pattern Matches"); + } + + /** + * Canonical equivalence testing. Tests the ability of the engine + * to match sequences that are not explicitly specified in the + * pattern when they are considered equivalent by the Unicode Standard. + */ + private static void ceTest() throws Exception { + // Decomposed char outside char classes + Pattern p = Pattern.compile("testa\u030a", Pattern.CANON_EQ); + Matcher m = p.matcher("test\u00e5"); + if (!m.matches()) + failCount++; + + m.reset("testa\u030a"); + if (!m.matches()) + failCount++; + + // Composed char outside char classes + p = Pattern.compile("test\u00e5", Pattern.CANON_EQ); + m = p.matcher("test\u00e5"); + if (!m.matches()) + failCount++; + + m.reset("testa\u030a"); + if (!m.find()) + failCount++; + + // Decomposed char inside a char class + p = Pattern.compile("test[abca\u030a]", Pattern.CANON_EQ); + m = p.matcher("test\u00e5"); + if (!m.find()) + failCount++; + + m.reset("testa\u030a"); + if (!m.find()) + failCount++; + + // Composed char inside a char class + p = Pattern.compile("test[abc\u00e5def\u00e0]", Pattern.CANON_EQ); + m = p.matcher("test\u00e5"); + if (!m.find()) + failCount++; + + m.reset("testa\u0300"); + if (!m.find()) + failCount++; + + m.reset("testa\u030a"); + if (!m.find()) + failCount++; + + // Marks that cannot legally change order and be equivalent + p = Pattern.compile("testa\u0308\u0300", Pattern.CANON_EQ); + check(p, "testa\u0308\u0300", true); + check(p, "testa\u0300\u0308", false); + + // Marks that can legally change order and be equivalent + p = Pattern.compile("testa\u0308\u0323", Pattern.CANON_EQ); + check(p, "testa\u0308\u0323", true); + check(p, "testa\u0323\u0308", true); + + // Test all equivalences of the sequence a\u0308\u0323\u0300 + p = Pattern.compile("testa\u0308\u0323\u0300", Pattern.CANON_EQ); + check(p, "testa\u0308\u0323\u0300", true); + check(p, "testa\u0323\u0308\u0300", true); + check(p, "testa\u0308\u0300\u0323", true); + check(p, "test\u00e4\u0323\u0300", true); + check(p, "test\u00e4\u0300\u0323", true); + + /* + * The following canonical equivalence tests don't work. Bug id: 4916384. + * + // Decomposed hangul (jamos) + p = Pattern.compile("\u1100\u1161", Pattern.CANON_EQ); + m = p.matcher("\u1100\u1161"); + if (!m.matches()) + failCount++; + + m.reset("\uac00"); + if (!m.matches()) + failCount++; + + // Composed hangul + p = Pattern.compile("\uac00", Pattern.CANON_EQ); + m = p.matcher("\u1100\u1161"); + if (!m.matches()) + failCount++; + + m.reset("\uac00"); + if (!m.matches()) + failCount++; + + // Decomposed supplementary outside char classes + p = Pattern.compile("test\ud834\uddbc\ud834\udd6f", Pattern.CANON_EQ); + m = p.matcher("test\ud834\uddc0"); + if (!m.matches()) + failCount++; + + m.reset("test\ud834\uddbc\ud834\udd6f"); + if (!m.matches()) + failCount++; + + // Composed supplementary outside char classes + p = Pattern.compile("test\ud834\uddc0", Pattern.CANON_EQ); + m.reset("test\ud834\uddbc\ud834\udd6f"); + if (!m.matches()) + failCount++; + + m = p.matcher("test\ud834\uddc0"); + if (!m.matches()) + failCount++; + + */ + + report("Canonical Equivalence"); + } + + /** + * A basic sanity test of Matcher.replaceAll(). + */ + private static void globalSubstitute() throws Exception { + // Global substitution with a literal + Pattern p = Pattern.compile("(ab)(c*)"); + Matcher m = p.matcher("abccczzzabcczzzabccc"); + if (!m.replaceAll("test").equals("testzzztestzzztest")) + failCount++; + + m.reset("zzzabccczzzabcczzzabccczzz"); + if (!m.replaceAll("test").equals("zzztestzzztestzzztestzzz")) + failCount++; + + // Global substitution with groups + m.reset("zzzabccczzzabcczzzabccczzz"); + String result = m.replaceAll("$1"); + if (!result.equals("zzzabzzzabzzzabzzz")) + failCount++; + + // Supplementary character test + // Global substitution with a literal + p = Pattern.compile(toSupplementaries("(ab)(c*)")); + m = p.matcher(toSupplementaries("abccczzzabcczzzabccc")); + if (!m.replaceAll(toSupplementaries("test")). + equals(toSupplementaries("testzzztestzzztest"))) + failCount++; + + m.reset(toSupplementaries("zzzabccczzzabcczzzabccczzz")); + if (!m.replaceAll(toSupplementaries("test")). + equals(toSupplementaries("zzztestzzztestzzztestzzz"))) + failCount++; + + // Global substitution with groups + m.reset(toSupplementaries("zzzabccczzzabcczzzabccczzz")); + result = m.replaceAll("$1"); + if (!result.equals(toSupplementaries("zzzabzzzabzzzabzzz"))) + failCount++; + + report("Global Substitution"); + } + + /** + * Tests the usage of Matcher.appendReplacement() with literal + * and group substitutions. + */ + private static void stringbufferSubstitute() throws Exception { + // SB substitution with literal + String blah = "zzzblahzzz"; + Pattern p = Pattern.compile("blah"); + Matcher m = p.matcher(blah); + StringBuffer result = new StringBuffer(); + try { + m.appendReplacement(result, "blech"); + failCount++; + } catch (IllegalStateException e) { + } + m.find(); + m.appendReplacement(result, "blech"); + if (!result.toString().equals("zzzblech")) + failCount++; + + m.appendTail(result); + if (!result.toString().equals("zzzblechzzz")) + failCount++; + + // SB substitution with groups + blah = "zzzabcdzzz"; + p = Pattern.compile("(ab)(cd)*"); + m = p.matcher(blah); + result = new StringBuffer(); + try { + m.appendReplacement(result, "$1"); + failCount++; + } catch (IllegalStateException e) { + } + m.find(); + m.appendReplacement(result, "$1"); + if (!result.toString().equals("zzzab")) + failCount++; + + m.appendTail(result); + if (!result.toString().equals("zzzabzzz")) + failCount++; + + // SB substitution with 3 groups + blah = "zzzabcdcdefzzz"; + p = Pattern.compile("(ab)(cd)*(ef)"); + m = p.matcher(blah); + result = new StringBuffer(); + try { + m.appendReplacement(result, "$1w$2w$3"); + failCount++; + } catch (IllegalStateException e) { + } + m.find(); + m.appendReplacement(result, "$1w$2w$3"); + if (!result.toString().equals("zzzabwcdwef")) + failCount++; + + m.appendTail(result); + if (!result.toString().equals("zzzabwcdwefzzz")) + failCount++; + + // SB substitution with groups and three matches + // skipping middle match + blah = "zzzabcdzzzabcddzzzabcdzzz"; + p = Pattern.compile("(ab)(cd*)"); + m = p.matcher(blah); + result = new StringBuffer(); + try { + m.appendReplacement(result, "$1"); + failCount++; + } catch (IllegalStateException e) { + } + m.find(); + m.appendReplacement(result, "$1"); + if (!result.toString().equals("zzzab")) + failCount++; + + m.find(); + m.find(); + m.appendReplacement(result, "$2"); + if (!result.toString().equals("zzzabzzzabcddzzzcd")) + failCount++; + + m.appendTail(result); + if (!result.toString().equals("zzzabzzzabcddzzzcdzzz")) + failCount++; + + // Check to make sure escaped $ is ignored + blah = "zzzabcdcdefzzz"; + p = Pattern.compile("(ab)(cd)*(ef)"); + m = p.matcher(blah); + result = new StringBuffer(); + m.find(); + m.appendReplacement(result, "$1w\\$2w$3"); + if (!result.toString().equals("zzzabw$2wef")) + failCount++; + + m.appendTail(result); + if (!result.toString().equals("zzzabw$2wefzzz")) + failCount++; + + // Check to make sure a reference to nonexistent group causes error + blah = "zzzabcdcdefzzz"; + p = Pattern.compile("(ab)(cd)*(ef)"); + m = p.matcher(blah); + result = new StringBuffer(); + m.find(); + try { + m.appendReplacement(result, "$1w$5w$3"); + failCount++; + } catch (IndexOutOfBoundsException ioobe) { + // Correct result + } + + // Check double digit group references + blah = "zzz123456789101112zzz"; + p = Pattern.compile("(1)(2)(3)(4)(5)(6)(7)(8)(9)(10)(11)"); + m = p.matcher(blah); + result = new StringBuffer(); + m.find(); + m.appendReplacement(result, "$1w$11w$3"); + if (!result.toString().equals("zzz1w11w3")) + failCount++; + + // Check to make sure it backs off $15 to $1 if only three groups + blah = "zzzabcdcdefzzz"; + p = Pattern.compile("(ab)(cd)*(ef)"); + m = p.matcher(blah); + result = new StringBuffer(); + m.find(); + m.appendReplacement(result, "$1w$15w$3"); + if (!result.toString().equals("zzzabwab5wef")) + failCount++; + + + // Supplementary character test + // SB substitution with literal + blah = toSupplementaries("zzzblahzzz"); + p = Pattern.compile(toSupplementaries("blah")); + m = p.matcher(blah); + result = new StringBuffer(); + try { + m.appendReplacement(result, toSupplementaries("blech")); + failCount++; + } catch (IllegalStateException e) { + } + m.find(); + m.appendReplacement(result, toSupplementaries("blech")); + if (!result.toString().equals(toSupplementaries("zzzblech"))) + failCount++; + + m.appendTail(result); + if (!result.toString().equals(toSupplementaries("zzzblechzzz"))) + failCount++; + + // SB substitution with groups + blah = toSupplementaries("zzzabcdzzz"); + p = Pattern.compile(toSupplementaries("(ab)(cd)*")); + m = p.matcher(blah); + result = new StringBuffer(); + try { + m.appendReplacement(result, "$1"); + failCount++; + } catch (IllegalStateException e) { + } + m.find(); + m.appendReplacement(result, "$1"); + if (!result.toString().equals(toSupplementaries("zzzab"))) + failCount++; + + m.appendTail(result); + if (!result.toString().equals(toSupplementaries("zzzabzzz"))) + failCount++; + + // SB substitution with 3 groups + blah = toSupplementaries("zzzabcdcdefzzz"); + p = Pattern.compile(toSupplementaries("(ab)(cd)*(ef)")); + m = p.matcher(blah); + result = new StringBuffer(); + try { + m.appendReplacement(result, toSupplementaries("$1w$2w$3")); + failCount++; + } catch (IllegalStateException e) { + } + m.find(); + m.appendReplacement(result, toSupplementaries("$1w$2w$3")); + if (!result.toString().equals(toSupplementaries("zzzabwcdwef"))) + failCount++; + + m.appendTail(result); + if (!result.toString().equals(toSupplementaries("zzzabwcdwefzzz"))) + failCount++; + + // SB substitution with groups and three matches + // skipping middle match + blah = toSupplementaries("zzzabcdzzzabcddzzzabcdzzz"); + p = Pattern.compile(toSupplementaries("(ab)(cd*)")); + m = p.matcher(blah); + result = new StringBuffer(); + try { + m.appendReplacement(result, "$1"); + failCount++; + } catch (IllegalStateException e) { + } + m.find(); + m.appendReplacement(result, "$1"); + if (!result.toString().equals(toSupplementaries("zzzab"))) + failCount++; + + m.find(); + m.find(); + m.appendReplacement(result, "$2"); + if (!result.toString().equals(toSupplementaries("zzzabzzzabcddzzzcd"))) + failCount++; + + m.appendTail(result); + if (!result.toString().equals(toSupplementaries("zzzabzzzabcddzzzcdzzz"))) + failCount++; + + // Check to make sure escaped $ is ignored + blah = toSupplementaries("zzzabcdcdefzzz"); + p = Pattern.compile(toSupplementaries("(ab)(cd)*(ef)")); + m = p.matcher(blah); + result = new StringBuffer(); + m.find(); + m.appendReplacement(result, toSupplementaries("$1w\\$2w$3")); + if (!result.toString().equals(toSupplementaries("zzzabw$2wef"))) + failCount++; + + m.appendTail(result); + if (!result.toString().equals(toSupplementaries("zzzabw$2wefzzz"))) + failCount++; + + // Check to make sure a reference to nonexistent group causes error + blah = toSupplementaries("zzzabcdcdefzzz"); + p = Pattern.compile(toSupplementaries("(ab)(cd)*(ef)")); + m = p.matcher(blah); + result = new StringBuffer(); + m.find(); + try { + m.appendReplacement(result, toSupplementaries("$1w$5w$3")); + failCount++; + } catch (IndexOutOfBoundsException ioobe) { + // Correct result + } + + // Check double digit group references + blah = toSupplementaries("zzz123456789101112zzz"); + p = Pattern.compile("(1)(2)(3)(4)(5)(6)(7)(8)(9)(10)(11)"); + m = p.matcher(blah); + result = new StringBuffer(); + m.find(); + m.appendReplacement(result, toSupplementaries("$1w$11w$3")); + if (!result.toString().equals(toSupplementaries("zzz1w11w3"))) + failCount++; + + // Check to make sure it backs off $15 to $1 if only three groups + blah = toSupplementaries("zzzabcdcdefzzz"); + p = Pattern.compile(toSupplementaries("(ab)(cd)*(ef)")); + m = p.matcher(blah); + result = new StringBuffer(); + m.find(); + m.appendReplacement(result, toSupplementaries("$1w$15w$3")); + if (!result.toString().equals(toSupplementaries("zzzabwab5wef"))) + failCount++; + + // Check nothing has been appended into the output buffer if + // the replacement string triggers IllegalArgumentException. + p = Pattern.compile("(abc)"); + m = p.matcher("abcd"); + result = new StringBuffer(); + m.find(); + try { + m.appendReplacement(result, ("xyz$g")); + failCount++; + } catch (IllegalArgumentException iae) { + if (result.length() != 0) + failCount++; + } + + report("SB Substitution"); + } + + /* + * 5 groups of characters are created to make a substitution string. + * A base string will be created including random lead chars, the + * substitution string, and random trailing chars. + * A pattern containing the 5 groups is searched for and replaced with: + * random group + random string + random group. + * The results are checked for correctness. + */ + private static void substitutionBasher() { + for (int runs = 0; runs<1000; runs++) { + // Create a base string to work in + int leadingChars = generator.nextInt(10); + StringBuffer baseBuffer = new StringBuffer(100); + String leadingString = getRandomAlphaString(leadingChars); + baseBuffer.append(leadingString); + + // Create 5 groups of random number of random chars + // Create the string to substitute + // Create the pattern string to search for + StringBuffer bufferToSub = new StringBuffer(25); + StringBuffer bufferToPat = new StringBuffer(50); + String[] groups = new String[5]; + for(int i=0; i<5; i++) { + int aGroupSize = generator.nextInt(5)+1; + groups[i] = getRandomAlphaString(aGroupSize); + bufferToSub.append(groups[i]); + bufferToPat.append('('); + bufferToPat.append(groups[i]); + bufferToPat.append(')'); + } + String stringToSub = bufferToSub.toString(); + String pattern = bufferToPat.toString(); + + // Place sub string into working string at random index + baseBuffer.append(stringToSub); + + // Append random chars to end + int trailingChars = generator.nextInt(10); + String trailingString = getRandomAlphaString(trailingChars); + baseBuffer.append(trailingString); + String baseString = baseBuffer.toString(); + + // Create test pattern and matcher + Pattern p = Pattern.compile(pattern); + Matcher m = p.matcher(baseString); + + // Reject candidate if pattern happens to start early + m.find(); + if (m.start() < leadingChars) + continue; + + // Reject candidate if more than one match + if (m.find()) + continue; + + // Construct a replacement string with : + // random group + random string + random group + StringBuffer bufferToRep = new StringBuffer(); + int groupIndex1 = generator.nextInt(5); + bufferToRep.append("$" + (groupIndex1 + 1)); + String randomMidString = getRandomAlphaString(5); + bufferToRep.append(randomMidString); + int groupIndex2 = generator.nextInt(5); + bufferToRep.append("$" + (groupIndex2 + 1)); + String replacement = bufferToRep.toString(); + + // Do the replacement + String result = m.replaceAll(replacement); + + // Construct expected result + StringBuffer bufferToRes = new StringBuffer(); + bufferToRes.append(leadingString); + bufferToRes.append(groups[groupIndex1]); + bufferToRes.append(randomMidString); + bufferToRes.append(groups[groupIndex2]); + bufferToRes.append(trailingString); + String expectedResult = bufferToRes.toString(); + + // Check results + if (!result.equals(expectedResult)) + failCount++; + } + + report("Substitution Basher"); + } + + /** + * Checks the handling of some escape sequences that the Pattern + * class should process instead of the java compiler. These are + * not in the file because the escapes should be be processed + * by the Pattern class when the regex is compiled. + */ + private static void escapes() throws Exception { + Pattern p = Pattern.compile("\\043"); + Matcher m = p.matcher("#"); + if (!m.find()) + failCount++; + + p = Pattern.compile("\\x23"); + m = p.matcher("#"); + if (!m.find()) + failCount++; + + p = Pattern.compile("\\u0023"); + m = p.matcher("#"); + if (!m.find()) + failCount++; + + report("Escape sequences"); + } + + /** + * Checks the handling of blank input situations. These + * tests are incompatible with my test file format. + */ + private static void blankInput() throws Exception { + Pattern p = Pattern.compile("abc", Pattern.CASE_INSENSITIVE); + Matcher m = p.matcher(""); + if (m.find()) + failCount++; + + p = Pattern.compile("a*", Pattern.CASE_INSENSITIVE); + m = p.matcher(""); + if (!m.find()) + failCount++; + + p = Pattern.compile("abc"); + m = p.matcher(""); + if (m.find()) + failCount++; + + p = Pattern.compile("a*"); + m = p.matcher(""); + if (!m.find()) + failCount++; + + report("Blank input"); + } + + /** + * Tests the Boyer-Moore pattern matching of a character sequence + * on randomly generated patterns. + */ + private static void bm() throws Exception { + doBnM('a'); + report("Boyer Moore (ASCII)"); + + doBnM(Character.MIN_SUPPLEMENTARY_CODE_POINT - 10); + report("Boyer Moore (Supplementary)"); + } + + private static void doBnM(int baseCharacter) throws Exception { + int achar=0; + + for (int i=0; i<100; i++) { + // Create a short pattern to search for + int patternLength = generator.nextInt(7) + 4; + StringBuffer patternBuffer = new StringBuffer(patternLength); + for (int x=0; x<patternLength; x++) { + int ch = baseCharacter + generator.nextInt(26); + if (Character.isSupplementaryCodePoint(ch)) { + patternBuffer.append(Character.toChars(ch)); + } else { + patternBuffer.append((char)ch); + } + } + String pattern = patternBuffer.toString(); + Pattern p = Pattern.compile(pattern); + + // Create a buffer with random ASCII chars that does + // not match the sample + String toSearch = null; + StringBuffer s = null; + Matcher m = p.matcher(""); + do { + s = new StringBuffer(100); + for (int x=0; x<100; x++) { + int ch = baseCharacter + generator.nextInt(26); + if (Character.isSupplementaryCodePoint(ch)) { + s.append(Character.toChars(ch)); + } else { + s.append((char)ch); + } + } + toSearch = s.toString(); + m.reset(toSearch); + } while (m.find()); + + // Insert the pattern at a random spot + int insertIndex = generator.nextInt(99); + if (Character.isLowSurrogate(s.charAt(insertIndex))) + insertIndex++; + s = s.insert(insertIndex, pattern); + toSearch = s.toString(); + + // Make sure that the pattern is found + m.reset(toSearch); + if (!m.find()) + failCount++; + + // Make sure that the match text is the pattern + if (!m.group().equals(pattern)) + failCount++; + + // Make sure match occured at insertion point + if (m.start() != insertIndex) + failCount++; + } + } + + /** + * Tests the matching of slices on randomly generated patterns. + * The Boyer-Moore optimization is not done on these patterns + * because it uses unicode case folding. + */ + private static void slice() throws Exception { + doSlice(Character.MAX_VALUE); + report("Slice"); + + doSlice(Character.MAX_CODE_POINT); + report("Slice (Supplementary)"); + } + + private static void doSlice(int maxCharacter) throws Exception { + Random generator = new Random(); + int achar=0; + + for (int i=0; i<100; i++) { + // Create a short pattern to search for + int patternLength = generator.nextInt(7) + 4; + StringBuffer patternBuffer = new StringBuffer(patternLength); + for (int x=0; x<patternLength; x++) { + int randomChar = 0; + while (!Character.isLetterOrDigit(randomChar)) + randomChar = generator.nextInt(maxCharacter); + if (Character.isSupplementaryCodePoint(randomChar)) { + patternBuffer.append(Character.toChars(randomChar)); + } else { + patternBuffer.append((char) randomChar); + } + } + String pattern = patternBuffer.toString(); + Pattern p = Pattern.compile(pattern, Pattern.UNICODE_CASE); + + // Create a buffer with random chars that does not match the sample + String toSearch = null; + StringBuffer s = null; + Matcher m = p.matcher(""); + do { + s = new StringBuffer(100); + for (int x=0; x<100; x++) { + int randomChar = 0; + while (!Character.isLetterOrDigit(randomChar)) + randomChar = generator.nextInt(maxCharacter); + if (Character.isSupplementaryCodePoint(randomChar)) { + s.append(Character.toChars(randomChar)); + } else { + s.append((char) randomChar); + } + } + toSearch = s.toString(); + m.reset(toSearch); + } while (m.find()); + + // Insert the pattern at a random spot + int insertIndex = generator.nextInt(99); + if (Character.isLowSurrogate(s.charAt(insertIndex))) + insertIndex++; + s = s.insert(insertIndex, pattern); + toSearch = s.toString(); + + // Make sure that the pattern is found + m.reset(toSearch); + if (!m.find()) + failCount++; + + // Make sure that the match text is the pattern + if (!m.group().equals(pattern)) + failCount++; + + // Make sure match occured at insertion point + if (m.start() != insertIndex) + failCount++; + } + } + + private static void explainFailure(String pattern, String data, + String expected, String actual) { + System.err.println("----------------------------------------"); + System.err.println("Pattern = "+pattern); + System.err.println("Data = "+data); + System.err.println("Expected = " + expected); + System.err.println("Actual = " + actual); + } + + private static void explainFailure(String pattern, String data, + Throwable t) { + System.err.println("----------------------------------------"); + System.err.println("Pattern = "+pattern); + System.err.println("Data = "+data); + t.printStackTrace(System.err); + } + + // Testing examples from a file + + /** + * Goes through the file "TestCases.txt" and creates many patterns + * described in the file, matching the patterns against input lines in + * the file, and comparing the results against the correct results + * also found in the file. The file format is described in comments + * at the head of the file. + */ + private static void processFile(String fileName) throws Exception { + File testCases = new File(System.getProperty("test.src", "."), + fileName); + FileInputStream in = new FileInputStream(testCases); + BufferedReader r = new BufferedReader(new InputStreamReader(in)); + + // Process next test case. + String aLine; + while((aLine = r.readLine()) != null) { + // Read a line for pattern + String patternString = grabLine(r); + Pattern p = null; + try { + p = compileTestPattern(patternString); + } catch (PatternSyntaxException e) { + String dataString = grabLine(r); + String expectedResult = grabLine(r); + if (expectedResult.startsWith("error")) + continue; + explainFailure(patternString, dataString, e); + failCount++; + continue; + } + + // Read a line for input string + String dataString = grabLine(r); + Matcher m = p.matcher(dataString); + StringBuffer result = new StringBuffer(); + + // Check for IllegalStateExceptions before a match + failCount += preMatchInvariants(m); + + boolean found = m.find(); + + if (found) + failCount += postTrueMatchInvariants(m); + else + failCount += postFalseMatchInvariants(m); + + if (found) { + result.append("true "); + result.append(m.group(0) + " "); + } else { + result.append("false "); + } + + result.append(m.groupCount()); + + if (found) { + for (int i=1; i<m.groupCount()+1; i++) + if (m.group(i) != null) + result.append(" " +m.group(i)); + } + + // Read a line for the expected result + String expectedResult = grabLine(r); + + if (!result.toString().equals(expectedResult)) { + explainFailure(patternString, dataString, expectedResult, result.toString()); + failCount++; + } + } + + report(fileName); + } + + private static int preMatchInvariants(Matcher m) { + int failCount = 0; + try { + m.start(); + failCount++; + } catch (IllegalStateException ise) {} + try { + m.end(); + failCount++; + } catch (IllegalStateException ise) {} + try { + m.group(); + failCount++; + } catch (IllegalStateException ise) {} + return failCount; + } + + private static int postFalseMatchInvariants(Matcher m) { + int failCount = 0; + try { + m.group(); + failCount++; + } catch (IllegalStateException ise) {} + try { + m.start(); + failCount++; + } catch (IllegalStateException ise) {} + try { + m.end(); + failCount++; + } catch (IllegalStateException ise) {} + return failCount; + } + + private static int postTrueMatchInvariants(Matcher m) { + int failCount = 0; + //assert(m.start() = m.start(0); + if (m.start() != m.start(0)) + failCount++; + //assert(m.end() = m.end(0); + if (m.start() != m.start(0)) + failCount++; + //assert(m.group() = m.group(0); + if (!m.group().equals(m.group(0))) + failCount++; + try { + m.group(50); + failCount++; + } catch (IndexOutOfBoundsException ise) {} + + return failCount; + } + + private static Pattern compileTestPattern(String patternString) { + if (!patternString.startsWith("'")) { + return Pattern.compile(patternString); + } + + int break1 = patternString.lastIndexOf("'"); + String flagString = patternString.substring( + break1+1, patternString.length()); + patternString = patternString.substring(1, break1); + + if (flagString.equals("i")) + return Pattern.compile(patternString, Pattern.CASE_INSENSITIVE); + + if (flagString.equals("m")) + return Pattern.compile(patternString, Pattern.MULTILINE); + + return Pattern.compile(patternString); + } + + /** + * Reads a line from the input file. Keeps reading lines until a non + * empty non comment line is read. If the line contains a \n then + * these two characters are replaced by a newline char. If a \\uxxxx + * sequence is read then the sequence is replaced by the unicode char. + */ + private static String grabLine(BufferedReader r) throws Exception { + int index = 0; + String line = r.readLine(); + while (line.startsWith("//") || line.length() < 1) + line = r.readLine(); + while ((index = line.indexOf("\\n")) != -1) { + StringBuffer temp = new StringBuffer(line); + temp.replace(index, index+2, "\n"); + line = temp.toString(); + } + while ((index = line.indexOf("\\u")) != -1) { + StringBuffer temp = new StringBuffer(line); + String value = temp.substring(index+2, index+6); + char aChar = (char)Integer.parseInt(value, 16); + String unicodeChar = "" + aChar; + temp.replace(index, index+6, unicodeChar); + line = temp.toString(); + } + + return line; + } + + private static void check(Pattern p, String s, String g, String expected) { + Matcher m = p.matcher(s); + m.find(); + if (!m.group(g).equals(expected)) + failCount++; + } + + private static void checkReplaceFirst(String p, String s, String r, String expected) + { + if (!expected.equals(Pattern.compile(p) + .matcher(s) + .replaceFirst(r))) + failCount++; + } + + private static void checkReplaceAll(String p, String s, String r, String expected) + { + if (!expected.equals(Pattern.compile(p) + .matcher(s) + .replaceAll(r))) + failCount++; + } + + private static void checkExpectedFail(String p) { + try { + Pattern.compile(p); + } catch (PatternSyntaxException pse) { + //pse.printStackTrace(); + return; + } + failCount++; + } + + private static void checkExpectedFail(Matcher m, String g) { + m.find(); + try { + m.group(g); + } catch (IllegalArgumentException iae) { + //iae.printStackTrace(); + return; + } catch (NullPointerException npe) { + return; + } + failCount++; + } + + + private static void namedGroupCaptureTest() throws Exception { + check(Pattern.compile("x+(?<gname>y+)z+"), + "xxxyyyzzz", + "gname", + "yyy"); + + check(Pattern.compile("x+(?<8gname>y+)z+"), + "xxxyyyzzz", + "8gname", + "yyy"); + + //backref + Pattern pattern = Pattern.compile("(a*)bc\\1"); + check(pattern, "zzzaabcazzz", true); // found "abca" + + check(Pattern.compile("(?<gname>a*)bc\\k<gname>"), + "zzzaabcaazzz", true); + + check(Pattern.compile("(?<gname>abc)(def)\\k<gname>"), + "abcdefabc", true); + + check(Pattern.compile("(a)(b)(c)(d)(e)(f)(g)(h)(i)(j)(?<gname>k)\\k<gname>"), + "abcdefghijkk", true); + + // Supplementary character tests + check(Pattern.compile("(?<gname>" + toSupplementaries("a*)bc") + "\\k<gname>"), + toSupplementaries("zzzaabcazzz"), true); + + check(Pattern.compile("(?<gname>" + toSupplementaries("a*)bc") + "\\k<gname>"), + toSupplementaries("zzzaabcaazzz"), true); + + check(Pattern.compile("(?<gname>" + toSupplementaries("abc)(def)") + "\\k<gname>"), + toSupplementaries("abcdefabc"), true); + + check(Pattern.compile(toSupplementaries("(a)(b)(c)(d)(e)(f)(g)(h)(i)(j)") + + "(?<gname>" + + toSupplementaries("k)") + "\\k<gname>"), + toSupplementaries("abcdefghijkk"), true); + + check(Pattern.compile("x+(?<gname>y+)z+\\k<gname>"), + "xxxyyyzzzyyy", + "gname", + "yyy"); + + //replaceFirst/All + checkReplaceFirst("(?<gn>ab)(c*)", + "abccczzzabcczzzabccc", + "$<gn>", + "abzzzabcczzzabccc"); + + checkReplaceAll("(?<gn>ab)(c*)", + "abccczzzabcczzzabccc", + "$<gn>", + "abzzzabzzzab"); + + + checkReplaceFirst("(?<gn>ab)(c*)", + "zzzabccczzzabcczzzabccczzz", + "$<gn>", + "zzzabzzzabcczzzabccczzz"); + + checkReplaceAll("(?<gn>ab)(c*)", + "zzzabccczzzabcczzzabccczzz", + "$<gn>", + "zzzabzzzabzzzabzzz"); + + checkReplaceFirst("(?<gn1>ab)(?<gn2>c*)", + "zzzabccczzzabcczzzabccczzz", + "$<gn2>", + "zzzccczzzabcczzzabccczzz"); + + checkReplaceAll("(?<gn1>ab)(?<gn2>c*)", + "zzzabccczzzabcczzzabccczzz", + "$<gn2>", + "zzzccczzzcczzzccczzz"); + + //toSupplementaries("(ab)(c*)")); + checkReplaceFirst("(?<gn1>" + toSupplementaries("ab") + + ")(?<gn2>" + toSupplementaries("c") + "*)", + toSupplementaries("abccczzzabcczzzabccc"), + "$<gn1>", + toSupplementaries("abzzzabcczzzabccc")); + + + checkReplaceAll("(?<gn1>" + toSupplementaries("ab") + + ")(?<gn2>" + toSupplementaries("c") + "*)", + toSupplementaries("abccczzzabcczzzabccc"), + "$<gn1>", + toSupplementaries("abzzzabzzzab")); + + checkReplaceFirst("(?<gn1>" + toSupplementaries("ab") + + ")(?<gn2>" + toSupplementaries("c") + "*)", + toSupplementaries("abccczzzabcczzzabccc"), + "$<gn2>", + toSupplementaries("ccczzzabcczzzabccc")); + + + checkReplaceAll("(?<gn1>" + toSupplementaries("ab") + + ")(?<gn2>" + toSupplementaries("c") + "*)", + toSupplementaries("abccczzzabcczzzabccc"), + "$<gn2>", + toSupplementaries("ccczzzcczzzccc")); + + checkReplaceFirst("(?<dog>Dog)AndCat", + "zzzDogAndCatzzzDogAndCatzzz", + "$<dog>", + "zzzDogzzzDogAndCatzzz"); + + + checkReplaceAll("(?<dog>Dog)AndCat", + "zzzDogAndCatzzzDogAndCatzzz", + "$<dog>", + "zzzDogzzzDogzzz"); + + // backref in Matcher & String + if (!"abcdefghij".replaceFirst("cd(?<gn>ef)gh", "$<gn>").equals("abefij") || + !"abbbcbdbefgh".replaceAll("(?<gn>[a-e])b", "$<gn>").equals("abcdefgh")) + failCount++; + + // negative + checkExpectedFail("(?<groupnamehasnoascii.in>abc)(def)"); + checkExpectedFail("(?<groupnamehasnoascii_in>abc)(def)"); + checkExpectedFail("(?<gname>abc)(def)\\k<gnameX>"); + checkExpectedFail("(?<gname>abc)(?<gname>def)\\k<gnameX>"); + checkExpectedFail(Pattern.compile("(?<gname>abc)(def)").matcher("abcdef"), + "gnameX"); + checkExpectedFail(Pattern.compile("(?<gname>abc)(def)").matcher("abcdef"), + null); + report("NamedGroupCapture"); + } +} diff --git a/test/java/util/regex/SupplementaryTestCases.txt b/test/java/util/regex/SupplementaryTestCases.txt new file mode 100644 index 0000000000000000000000000000000000000000..2f05d4fed4604ea53fd1f38c16bb733ff562d36e --- /dev/null +++ b/test/java/util/regex/SupplementaryTestCases.txt @@ -0,0 +1,1434 @@ +// +// Copyright 1999-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. +// +// 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. +// +// -------------------------------------------------------- +// This file contains test cases with supplementary characters for regular expressions. +// A test case consists of three lines: +// The first line is a pattern used in the test +// The second line is the input to search for the pattern in +// The third line is a concatentation of the match, the number of groups, +// and the contents of the first four subexpressions. +// Empty lines and lines beginning with comment slashes are ignored. + +// Test unsetting of backed off groups +^(\ud800\udc61)?\ud800\udc61 +\ud800\udc61 +true \ud800\udc61 1 + +^(\ud800\udc61\ud800)?\ud800\udc61\ud800 +\ud800\udc61\ud800 +true \ud800\udc61\ud800 1 + +^(\ud800\udc61\ud800\udc61(\ud800\udc62\ud800\udc62)?)+$ +\ud800\udc61\ud800\udc61\ud800\udc62\ud800\udc62\ud800\udc61\ud800\udc61 +true \ud800\udc61\ud800\udc61\ud800\udc62\ud800\udc62\ud800\udc61\ud800\udc61 2 \ud800\udc61\ud800\udc61 \ud800\udc62\ud800\udc62 + +^(\ud800\udc61\ud800\udc61\ud800(\ud800\udc62\ud800\udc62\ud800)?)+$ +\ud800\udc61\ud800\udc61\ud800\ud800\udc62\ud800\udc62\ud800\ud800\udc61\ud800\udc61\ud800 +true \ud800\udc61\ud800\udc61\ud800\ud800\udc62\ud800\udc62\ud800\ud800\udc61\ud800\udc61\ud800 2 \ud800\udc61\ud800\udc61\ud800 \ud800\udc62\ud800\udc62\ud800 + +((\ud800\udc61|\ud800\udc62)?\ud800\udc62)+ +\ud800\udc62 +true \ud800\udc62 2 \ud800\udc62 + +((\ud800|\ud800\udc62)?\ud800\udc62)+ +\ud800\udc62 +true \ud800\udc62 2 \ud800\udc62 + +(\ud800\udc61\ud800\udc61\ud800\udc61)?\ud800\udc61\ud800\udc61\ud800\udc61 +\ud800\udc61\ud800\udc61\ud800\udc61 +true \ud800\udc61\ud800\udc61\ud800\udc61 1 + +(\ud800\udc61\ud800\udc61\ud800\ud800\udc61)?\ud800\udc61\ud800\udc61\ud800\ud800\udc61 +\ud800\udc61\ud800\udc61\ud800\ud800\udc61 +true \ud800\udc61\ud800\udc61\ud800\ud800\udc61 1 + +^(\ud800\udc61\ud800(\ud800\udc62\ud800)?)+$ +\ud800\udc61\ud800\ud800\udc62\ud800\ud800\udc61\ud800 +true \ud800\udc61\ud800\ud800\udc62\ud800\ud800\udc61\ud800 2 \ud800\udc61\ud800 \ud800\udc62\ud800 + +^(\ud800\udc61(\ud800\udc62)?)+$ +\ud800\udc61\ud800\udc62\ud800\udc61 +true \ud800\udc61\ud800\udc62\ud800\udc61 2 \ud800\udc61 \ud800\udc62 + +^(\ud800\udc61\ud800(\ud800\udc62\ud800)?)+$ +\ud800\udc61\ud800\ud800\udc62\ud800\ud800\udc61\ud800 +true \ud800\udc61\ud800\ud800\udc62\ud800\ud800\udc61\ud800 2 \ud800\udc61\ud800 \ud800\udc62\ud800 + +^(\ud800\udc61(\ud800\udc62(\ud800\udc63)?)?)?\ud800\udc61\ud800\udc62\ud800\udc63 +\ud800\udc61\ud800\udc62\ud800\udc63 +true \ud800\udc61\ud800\udc62\ud800\udc63 3 + +^(\ud800\udc61\ud800(\ud800\udc62(\ud800\udc63)?)?)?\ud800\udc61\ud800\ud800\udc62\ud800\udc63 +\ud800\udc61\ud800\ud800\udc62\ud800\udc63 +true \ud800\udc61\ud800\ud800\udc62\ud800\udc63 3 + +^(\ud800\udc61(\ud800\udc02(\ud800\udc63))).* +\ud800\udc61\ud800\udc02\ud800\udc63 +true \ud800\udc61\ud800\udc02\ud800\udc63 3 \ud800\udc61\ud800\udc02\ud800\udc63 \ud800\udc02\ud800\udc63 \ud800\udc63 + +^(\ud800\udc61(\ud800(\ud800\udc63))).* +\ud800\udc61\ud800\ud800\udc63 +true \ud800\udc61\ud800\ud800\udc63 3 \ud800\udc61\ud800\ud800\udc63 \ud800\ud800\udc63 \ud800\udc63 + +// Patterns including no surrogates +(.)([^a])xyz +\ud801\ud800\udc00xyz +true \ud801\ud800\udc00xyz 2 \ud801 \ud800\udc00 + +[^a-z].. +\ud801\ud800\udc00xyz +true \ud801\ud800\udc00x 0 + +.$ +\ud801\ud800\udc00 +true \ud800\udc00 0 + +.$ +\ud801\udc01\ud800\udc00 +true \ud800\udc00 0 + +.$ +\ud801\udc01\ud800\udc00\udcff +true \udcff 0 + +[^x-\uffff][^y-\uffff] +\ud800\udc00pqr +true \ud800\udc00p 0 + +[^x-\uffff]+ +\ud800\udc00pqrx +true \ud800\udc00pqr 0 + +/// The following test cases fail due to use of Start rather than +/// StartS. Disabled for now. +///[a-\uffff] +///\ud800\udc00x +///true x 0 +/// +///[a-\uffff] +///\ud800\udc00 +///false 0 + +// use of x modifier +\ud800\udc61bc(?x)bl\ud800\udc61h +\ud800\udc61bcbl\ud800\udc61h +true \ud800\udc61bcbl\ud800\udc61h 0 + +\ud800\udc61bc(?x) bl\ud800\udc61h +\ud800\udc61bcbl\ud800\udc61h +true \ud800\udc61bcbl\ud800\udc61h 0 + +\ud800\udc61bc(?x) bl\ud800\udc61h blech +\ud800\udc61bcbl\ud800\udc61hblech +true \ud800\udc61bcbl\ud800\udc61hblech 0 + +\ud800\udc61bc(?x) bl\ud800\udc61h # ignore comment +\ud800\udc61bcbl\ud800\udc61h +true \ud800\udc61bcbl\ud800\udc61h 0 + +// Simple alternation +\ud800\udc61|\ud800\udc62 +\ud800\udc61 +true \ud800\udc61 0 + +\ud800\udc61|\ud800\udc62|\ud800 +\ud800\udc61 +true \ud800\udc61 0 + +\ud800\udc61|\ud800 +\ud800\udc62 +false 0 + +\ud800\udc62|\ud800 +\ud800 +true \ud800 0 + +\ud800\udc61|\ud802\udc02 +z +false 0 + +\ud800\udc61|\ud802\udc02 +\ud802\udc02 +true \ud802\udc02 0 + +\ud800\udc61|\ud802\udc02|\ud803\udc03\ud804\udc04 +\ud803\udc03\ud804\udc04 +true \ud803\udc03\ud804\udc04 0 + +\ud800\udc61|\ud800\udc61d +\ud800\udc61d +true \ud800\udc61 0 + +z(\ud800\udc61|\ud800\udc61c)\ud802\udc02 +z\ud800\udc61c\ud802\udc02 +true z\ud800\udc61c\ud802\udc02 1 \ud800\udc61c + +z(\ud800\udc61|\ud800\udc61c|\udc61c)\ud802\udc02 +z\udc61c\ud802\udc02 +true z\udc61c\ud802\udc02 1 \udc61c + +// Simple codepoint class +[\ud800\udc61\ud802\udc02c]+ +\ud800\udc61\ud802\udc02\ud800\udc61\ud802\udc02\ud800\udc61\ud802\udc02 +true \ud800\udc61\ud802\udc02\ud800\udc61\ud802\udc02\ud800\udc61\ud802\udc02 0 + +[\ud800\udc61\ud802\udc02c]+ +\ud800\udc61\ud802\udc02\ud800\udc61\ud802\udc02\ud800\udc61\ud802\udc02 +true \ud800\udc61\ud802\udc02\ud800\udc61\ud802\udc02\ud800\udc61\ud802\udc02 0 + +[\ud800\udc61\ud802\udc02c\ud800]+ +\ud800\udc61\ud802\udc02\ud800\ud800\udc61\ud802\udc02\ud800\udc61\ud802\udc02 +true \ud800\udc61\ud802\udc02\ud800\ud800\udc61\ud802\udc02\ud800\udc61\ud802\udc02 0 + +[\ud800\udc61bc]+ +d\ud800\udc62fg +false 0 + +[\ud800\udc61bc]+[\ud804\udc04ef]+[\ud807\udc07hi]+ +zzz\ud800\udc61\ud800\udc61\ud804\udc04\ud804\udc04\ud807\udc07\ud807\udc07zzz +true \ud800\udc61\ud800\udc61\ud804\udc04\ud804\udc04\ud807\udc07\ud807\udc07 0 + +// Range codepoint class +[\ud801\udc01-\ud807\udc07]+ +\ud8ff\udcff\ud8ff\udcff\ud8ff\udcff\ud807\udc07\ud807\udc07\ud807\udc07 +true \ud807\udc07\ud807\udc07\ud807\udc07 0 + +[\ud801\udc01-\ud807\udc07]+ +mmm +false 0 + +[\ud800\udc61-]+ +z\ud800\udc61-9z +true \ud800\udc61- 0 + +// Negated char class +[^\ud800\udc61\ud802\udc02c]+ +\ud800\udc61\ud802\udc02\ud800\udc61\ud802\udc02\ud800\udc61\ud802\udc02 +false 0 + +[^\ud800\udc61\ud802\udc02\ud803\udc03]+ +\ud800\udc61\ud800\udc61\ud800\udc61\ud802\udc02\ud802\udc02\ud802\udc02\ud803\udc03\ud803\udc03\ud803\udc03\ud804\udc04efg +true \ud804\udc04efg 0 + +[^\ud800\udc61\ud802\udc02\ud803\udc03\ud800]+ +\ud800\udc61\ud800\udc61\ud800\udc61\ud802\udc02\ud802\udc02\ud802\udc02\ud803\udc03\ud803\udc03\ud803\udc03\ud804\udc04efg +true \ud804\udc04efg 0 + +// Making sure a ^ not in first position matches literal ^ +[\ud801\udc01\ud802\udc02\ud803\udc03^\ud802\udc02] +\ud802\udc02 +true \ud802\udc02 0 + +[\ud801\udc01\ud802\udc02\ud803\udc03^\ud802\udc02] +^ +true ^ 0 + +// Class union and intersection +[\ud801\udc01\ud802\udc02\ud803\udc03[\ud804\udc04\ud805\udc05\ud806\udc06]] +\ud802\udc02 +true \ud802\udc02 0 + +[\ud800\udc61\ud802\udc02\ud803\udc03[\ud804\udc04\ud805\udc05\ud806\udc06]] +\ud805\udc05 +true \ud805\udc05 0 + +[\ud801\udc01-\ud804\udc04[0-9][\ud80b\udc0b-\ud80d\udc0d]] +\ud801\udc01 +true \ud801\udc01 0 + +[\ud801\udc01-\ud804\udc04[0-9][\ud80b\udc0b-\ud80d\udc0d]] +\ud80c\udc0c +true \ud80c\udc0c 0 + +[\ud801\udc01-\ud804\udc04[0-9][\ud80b\udc0b-\ud80d\udc0d]] +4 +true 4 0 + +[\ud801\udc01-\ud804\udc04[0-9][\ud80b\udc0b-\ud80d\udc0d]] +\ud805\udc05 +false 0 + +[\ud801\udc01-\ud804\udc04[0-9][\ud80b\udc0b-\ud80d\udc0d]] +\ud816\udc16 +false 0 + +[[\ud801\udc01-\ud804\udc04][0-9][\ud80b\udc0b-\ud80d\udc0d]] +\ud802\udc02 +true \ud802\udc02 0 + +[[\ud801\udc01-\ud804\udc04][0-9][\ud80b\udc0b-\ud80d\udc0d]] +\ud81a\udc1a +false 0 + +[\ud801\udc01-\ud803\udc03[\ud804\udc04-\ud806\udc06[\ud807\udc07-\ud809\udc09]]] +\ud801\udc01 +true \ud801\udc01 0 + +[\ud801\udc01-\ud803\udc03[\ud804\udc04-\ud806\udc06[\ud807\udc07-\ud809\udc09]]] +\ud805\udc05 +true \ud805\udc05 0 + +[\ud801\udc01-\ud803\udc03[\ud804\udc04-\ud806\udc06[\ud807\udc07-\ud809\udc09]]] +\ud808\udc08 +true \ud808\udc08 0 + +[\ud801\udc01-\ud803\udc03[\ud804\udc04-\ud806\udc06[\ud807\udc07-\ud809\udc09]]] +\ud80d\udc0d +false 0 + +[\ud801\udc01-\ud803\udc03[\ud804\udc04-\ud806\udc06[\ud807\udc07-\ud809\udc09]]\ud80d\udc0d] +\ud80d\udc0d +true \ud80d\udc0d 0 + +[\ud801\udc01\ud802\udc02\ud803\udc03[\ud804\udc04\ud805\udc05\ud806\udc06]\ud807\udc07\ud808\udc08\ud809\udc09] +\ud801\udc01 +true \ud801\udc01 0 + +[\ud800\udc61\ud802\udc02\ud803\udc03[\ud804\udc04\ud805\udc05\ud806\udc06]\ud807\udc07\ud808\udc08\ud809\udc09] +\ud804\udc04 +true \ud804\udc04 0 + +[\ud800\udc61\ud802\udc02\ud803\udc03[\ud804\udc04\ud805\udc05\ud806\udc06]\ud807\udc07\ud808\udc08\ud809\udc09] +\ud808\udc08 +true \ud808\udc08 0 + +[\ud800\udc61\ud802\udc02\ud803\udc03[\ud804\udc04\ud805\udc05\ud806\udc06]\ud807\udc07\ud808\udc08\ud809\udc09] +\ud816\udc16 +false 0 + +[\ud801\udc01-\ud803\udc03&&[\ud804\udc04-\ud806\udc06]] +\ud801\udc01 +false 0 + +[\ud801\udc01-\ud803\udc03&&[\ud804\udc04-\ud806\udc06]] +\ud805\udc05 +false 0 + +[\ud801\udc01-\ud803\udc03&&[\ud804\udc04-\ud806\udc06]] +\ud81a\udc1a +false 0 + +[[\ud801\udc01-\ud803\udc03]&&[\ud804\udc04-\ud806\udc06]] +\ud801\udc01 +false 0 + +[[\ud801\udc01-\ud803\udc03]&&[\ud804\udc04-\ud806\udc06]] +\ud805\udc05 +false 0 + +[[\ud801\udc01-\ud803\udc03]&&[\ud804\udc04-\ud806\udc06]] +\ud81a\udc1a +false 0 + +[\ud801\udc01-\ud803\udc03&&\ud804\udc04-\ud806\udc06] +\ud801\udc01 +false 0 + +[\ud801\udc01-\ud80d\udc0d&&\ud80d\udc0d-\ud81a\udc1a] +\ud80d\udc0d +true \ud80d\udc0d 0 + +[\ud801\udc01-\ud80d\udc0d&&\ud80d\udc0d-\ud81a\udc1a&&\ud801\udc01-\ud803\udc03] +\ud80d\udc0d +false 0 + +[\ud801\udc01-\ud80d\udc0d&&\ud80d\udc0d-\ud81a\udc1a&&\ud801\udc01-\ud81a\udc1a] +\ud80d\udc0d +true \ud80d\udc0d 0 + +[[\ud801\udc01-\ud80d\udc0d]&&[\ud80d\udc0d-\ud81a\udc1a]] +\ud801\udc01 +false 0 + +[[\ud801\udc01-\ud80d\udc0d]&&[\ud80d\udc0d-\ud81a\udc1a]] +\ud80d\udc0d +true \ud80d\udc0d 0 + +[[\ud801\udc01-\ud80d\udc0d]&&[\ud80d\udc0d-\ud81a\udc1a]] +\ud81a\udc1a +false 0 + +[[\ud801\udc01-\ud80d\udc0d]&&[^\ud801\udc01-\ud803\udc03]] +\ud801\udc01 +false 0 + +[[\ud801\udc01-\ud80d\udc0d]&&[^\ud801\udc01-\ud803\udc03]] +\ud804\udc04 +true \ud804\udc04 0 + +[\ud801\udc01-\ud80d\udc0d&&[^\ud801\udc01-\ud803\udc03]] +\ud801\udc01 +false 0 + +[\ud801\udc01-\ud80d\udc0d&&[^\ud801\udc01-\ud803\udc03]] +\ud804\udc04 +true \ud804\udc04 0 + +[\ud801\udc01-\ud803\udc03\ud804\udc04-\ud806\udc06&&[\ud804\udc04-\ud806\udc06]] +\ud801\udc01 +false 0 + +[\ud801\udc01-\ud803\udc03\ud804\udc04-\ud806\udc06&&[\ud804\udc04-\ud806\udc06]] +\ud805\udc05 +true \ud805\udc05 0 + +[[\ud801\udc01-\ud803\udc03]&&\ud804\udc04-\ud806\udc06\ud801\udc01-\ud803\udc03] +\ud801\udc01 +true \ud801\udc01 0 + +[[\ud801\udc01-\ud803\udc03]&&[\ud804\udc04-\ud806\udc06][\ud801\udc01-\ud803\udc03]] +\ud801\udc01 +true \ud801\udc01 0 + +[[\ud801\udc01-\ud803\udc03][\ud804\udc04-\ud806\udc06]&&\ud801\udc01\ud802\udc02\ud803\udc03] +\ud801\udc01 +true \ud801\udc01 0 + +[[\ud801\udc01-\ud803\udc03][\ud804\udc04-\ud806\udc06]&&\ud801\udc01\ud802\udc02\ud803\udc03[\ud804\udc04\ud805\udc05\ud806\udc06]] +\ud805\udc05 +true \ud805\udc05 0 + +[[\ud801\udc01-\ud803\udc03]&&[\ud802\udc02-\ud804\udc04]&&[\ud803\udc03-\ud805\udc05]] +\ud801\udc01 +false 0 + +[[\ud801\udc01-\ud803\udc03]&&[\ud802\udc02-\ud804\udc04]&&[\ud803\udc03-\ud805\udc05]] +\ud803\udc03 +true \ud803\udc03 0 + +[[\ud801\udc01-\ud803\udc03]&&[\ud802\udc02-\ud804\udc04][\ud803\udc03-\ud805\udc05]&&[\ud815\udc15-\ud81a\udc1a]] +\ud803\udc03 +false 0 + +[\ud801\udc01\ud802\udc02\ud803\udc03[^\ud802\udc02\ud803\udc03\ud804\udc04]] +\ud801\udc01 +true \ud801\udc01 0 + +[\ud800\udc61\ud802\udc02\ud803\udc03[^\ud802\udc02\ud803\udc03\ud804\udc04]] +\ud804\udc04 +false 0 + +[\ud801\udc01-\ud803\udc03&&\ud801\udc01-\ud804\udc04&&\ud801\udc01-\ud805\udc05\ud807\udc07\ud808\udc08\ud809\udc09] +\ud802\udc02 +true \ud802\udc02 0 + +[\ud801\udc01-\ud803\udc03&&\ud801\udc01-\ud804\udc04&&\ud801\udc01-\ud805\udc05\ud807\udc07\ud808\udc08\ud809\udc09] +\ud807\udc07 +false 0 + +[[\ud801\udc01[\ud802\udc02]]&&[\ud802\udc02[\ud801\udc01]]] +\ud801\udc01 +true \ud801\udc01 0 + +// Unicode isn't supported in clazz() +[[\ud800\udc61]&&[b][c][\ud800\udc61]&&[^d]] +\ud800\udc61 +true \ud800\udc61 0 + +[[\ud800\udc61]&&[\ud802\udc02][\ud800][\ud800\udc61]&&[^\ud804\udc04]] +\ud800\udc61 +true \ud800\udc61 0 + +[[\ud800\udc61]&&[b][\ud800][\ud800\udc61]&&[^\ud804\udc04]] +\ud804\udc04 +false 0 + +[[\ud800\udc61]&&[b][c][\ud800\udc61]&&[^d]] +d +false 0 + +[[[\ud800\udc01-\ud800\udc04]&&[\ud800\udc03-\ud800\udc06]]] +\ud800\udc01 +false 0 + +[[[\ud800\udc01-\ud800\udc04]&&[\ud800\udc03-\ud800\udc06]]] +\ud800\udc03 +true \ud800\udc03 0 + +[[[\ud800\udc01-\ud800\udc04]&&[\ud800\udc03-\ud800\udc06]]&&[\ud800\udc03]] +\ud800\udc03 +true \ud800\udc03 0 + +[[[\ud800\udc01-\ud800\udc04]&&[\ud800\udc03-\ud800\udc06]]&&[\ud800\udc03]&&\ud800\udc03] +\ud800\udc03 +true \ud800\udc03 0 + +[[[\ud800\udc01-\ud800\udc04]&&[\ud800\udc03-\ud800\udc06]]&&[\ud800\udc03]&&\ud800\udc03&&\ud800\udc03] +\ud800\udc03 +true \ud800\udc03 0 + +[[[\ud800\udc01-\ud800\udc04]&&[\ud800\udc03-\ud800\udc06]]&&[\ud800\udc03]&&\ud800\udc03&&[\ud800\udc03\ud800\udc04\ud800\udc05]] +\ud800\udc03 +true \ud800\udc03 0 + +[z[\ud800\udc61b\ud800\udc03&&b\ud800\udc03\ud800\udc04]] +\ud800\udc03 +true \ud800\udc03 0 + +[z[\ud800\udc61b\ud800\udc03&&b\ud800\udc03\ud800\udc04]&&[u-z]] +z +true z 0 + +[x[\ud800\udc61b\ud800\udc03&&b\ud800\udc03\ud800\udc04[z]]&&[u-z]] +z +false 0 + +[x[[wz]\ud800\udc61b\ud800\udc03&&b\ud800\udc03\ud800\udc04[z]]&&[u-z]] +z +true z 0 + +[[\ud800\udc61b\ud800\udc03]&&[\ud800\udc04\ud800\udc05f]\ud800\udc61b\ud800\udc03] +\ud800\udc61 +true \ud800\udc61 0 + +[[\ud800\udc61b\ud800\udc03]&&[\ud800\udc04\ud800\udc05f]xyz[\ud800\udc61b\ud800\udc03]] +\ud800\udc61 +true \ud800\udc61 0 + +\pL +\ud800\udc00 +true \ud800\udc00 0 + +\p{IsASCII} +\ud800\udc00 +false 0 + +\pLbc +\ud800\udc00bc +true \ud800\udc00bc 0 + +\ud800\udc61[r\p{InGreek}]c +\ud800\udc61\u0370c +true \ud800\udc61\u0370c 0 + +\ud800\udc61\p{InGreek} +\ud800\udc61\u0370 +true \ud800\udc61\u0370 0 + +\ud800\udc61\P{InGreek} +\ud800\udc61\u0370 +false 0 + +\ud800\udc61\P{InGreek} +\ud800\udc61b +true \ud800\udc61b 0 + +\ud800\udc61{^InGreek} +- +error + +\ud800\udc61\p{^InGreek} +- +error + +\ud800\udc61\P{^InGreek} +- +error + +\ud800\udc61\p{InGreek} +\ud800\udc61\u0370 +true \ud800\udc61\u0370 0 + +\ud800\udc61[\p{InGreek}]c +\ud800\udc61\u0370c +true \ud800\udc61\u0370c 0 + +\ud800\udc61[\P{InGreek}]c +\ud800\udc61\u0370c +false 0 + +\ud800\udc61[\P{InGreek}]c +\ud800\udc61bc +true \ud800\udc61bc 0 + +\ud800\udc61[{^InGreek}]c +\ud800\udc61nc +true \ud800\udc61nc 0 + +\ud800\udc61[{^InGreek}]c +\ud800\udc61zc +false 0 + +\ud800\udc61[\p{^InGreek}]c +- +error + +\ud800\udc61[\P{^InGreek}]c +- +error + +\ud800\udc61[\p{InGreek}] +\ud800\udc61\u0370 +true \ud800\udc61\u0370 0 + +\ud800\udc61[r\p{InGreek}]c +\ud800\udc61rc +true \ud800\udc61rc 0 + +\ud800\udc61[\p{InGreek}r]c +\ud800\udc61rc +true \ud800\udc61rc 0 + +\ud800\udc61[r\p{InGreek}]c +\ud800\udc61rc +true \ud800\udc61rc 0 + +\ud800\udc61[^\p{InGreek}]c +\ud800\udc61\u0370c +false 0 + +\ud800\udc61[^\P{InGreek}]c +\ud800\udc61\u0370c +true \ud800\udc61\u0370c 0 + +\ud800\udc61[\p{InGreek}&&[^\u0370]]c +\ud800\udc61\u0370c +false 0 + +// Test the dot metacharacter +\ud800\udc61.c.+ +\ud800\udc61#c%& +true \ud800\udc61#c%& 0 + +\ud800\udc61b. +\ud800\udc61b\n +false 0 + +(?s)\ud800\udc61b. +\ud800\udc61b\n +true \ud800\udc61b\n 0 + +\ud800\udc61[\p{L}&&[\P{InGreek}]]c +\ud800\udc61\u6000c +true \ud800\udc61\u6000c 0 + +\ud800\udc61[\p{L}&&[\P{InGreek}]]c +\ud800\udc61rc +true \ud800\udc61rc 0 + +\ud800\udc61[\p{L}&&[\P{InGreek}]]c +\ud800\udc61\u0370c +false 0 + +\ud800\udc61\p{InGreek}c +\ud800\udc61\u0370c +true \ud800\udc61\u0370c 0 + +\ud800\udc61\p{Sc} +\ud800\udc61$ +true \ud800\udc61$ 0 + +// Test \p{L} +\p{L} +\ud800\udf1e +true \ud800\udf1e 0 + +^a\p{L}z$ +a\ud800\udf1ez +true a\ud800\udf1ez 0 + +// Test \P{InDeseret} + +\ud800\udf00\p{L}{2,3}\P{L}*supp->\ud900\udc00<-\P{InDeseret} +\ud800\udf00\ud800\udf1e\ud800\udf1esupp->\ud900\udc00<-\ud901\udf00 +true \ud800\udf00\ud800\udf1e\ud800\udf1esupp->\ud900\udc00<-\ud901\udf00 0 + +\ud800\udf00\p{L}{2,3}\P{L}*supp->\ud900\udc00<-\P{InDeseret} +\ud800\udf00\ud800\udf1e\ud800\udf1e\ud901\udf00supp->\ud900\udc00<-\ud901\udf00 +true \ud800\udf00\ud800\udf1e\ud800\udf1e\ud901\udf00supp->\ud900\udc00<-\ud901\udf00 0 + +// Test \p{InDeseret} +\ud800\udf00\p{L}{2,3}\P{L}*supp->\ud900\udc00<-\p{InDeseret} +\ud800\udf00\ud800\udf1e\ud800\udf1e\ud901\udf00supp->\ud900\udc00<-\ud801\udc00 +true \ud800\udf00\ud800\udf1e\ud800\udf1e\ud901\udf00supp->\ud900\udc00<-\ud801\udc00 0 + +// Test the word char escape sequence +\ud800\udc61b\wc +\ud800\udc61bcc +true \ud800\udc61bcc 0 + +\ud800\udc61bc[\w] +\ud800\udc61bcd +true \ud800\udc61bcd 0 + +\ud800\udc61bc[\sdef]* +\ud800\udc61bc def +true \ud800\udc61bc def 0 + +\ud800\udc61bc[\sy-z]* +\ud800\udc61bc y z +true \ud800\udc61bc y z 0 + +\ud800\udc01bc[\ud800\udc01-\ud800\udc04\sm-p]* +\ud800\udc01bc\ud800\udc01\ud800\udc01 mn p +true \ud800\udc01bc\ud800\udc01\ud800\udc01 mn p 0 + +// Test the whitespace escape sequence +\ud800\udc61b\s\ud800\udc03 +\ud800\udc61b \ud800\udc03 +true \ud800\udc61b \ud800\udc03 0 + +\s\s\s +bl\ud800\udc61h err +false 0 + +\S\S\s +bl\ud800\udc61h err +true \ud800\udc61h 0 + +// Test the digit escape sequence +\ud800\udc61b\d\ud800\udc03 +\ud800\udc61b9\ud800\udc03 +true \ud800\udc61b9\ud800\udc03 0 + +\d\d\d +bl\ud800\udc61h45 +false 0 + +// Test the caret metacharacter +^\ud800\udc61bc +\ud800\udc61bcdef +true \ud800\udc61bc 0 + +^\ud800\udc61bc +bcd\ud800\udc61bc +false 0 + +// Greedy ? metacharacter +\ud800\udc61?\ud800\udc02 +\ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc02 +true \ud800\udc61\ud800\udc02 0 + +\udc61?\ud800\udc02 +\ud800\udc61\udc61\udc61\ud800\udc02 +true \udc61\ud800\udc02 0 + +\ud800\udc61?\ud800\udc02 +\ud800\udc02 +true \ud800\udc02 0 + +\ud800?\ud800\udc02 +\ud800\udc02 +true \ud800\udc02 0 + +\ud800\udc61?\ud800\udc02 +\ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc03\ud800\udc03\ud800\udc03 +false 0 + +.?\ud800\udc02 +\ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc02 +true \ud800\udc61\ud800\udc02 0 + +// Reluctant ? metacharacter +\ud800\udc61??\ud800\udc02 +\ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc02 +true \ud800\udc61\ud800\udc02 0 + +\ud800??\ud800\udc02 +\ud800\ud800\ud8001\ud800\ud800\udc02 +true \ud800\ud800\udc02 0 + +\ud800\udc61??\ud800\udc02 +\ud800\udc02 +true \ud800\udc02 0 + +\ud800??\ud800\udc02 +\ud800\udc02 +true \ud800\udc02 0 + +\ud800\udc61??\ud800\udc02 +\ud800\udc61\ud800\udc61\ud800\udc61ccc +false 0 + +.??\ud800\udc02 +\ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc02 +true \ud800\udc61\ud800\udc02 0 + +// Possessive ? metacharacter +\ud800\udc61?+\ud800\udc02 +\ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc02 +true \ud800\udc61\ud800\udc02 0 + +\ud800\udc61?+\ud800\udc02 +\ud800\udc02 +true \ud800\udc02 0 + +\ud800\udc61?+\ud800\udc02 +\ud800\udc61\ud800\udc61\ud800\udc61ccc +false 0 + +.?+\ud800\udc02 +\ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc02 +true \ud800\udc61\ud800\udc02 0 + +// Greedy + metacharacter +\ud800\udc61+\ud800\udc02 +\ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc02 +true \ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc02 0 + +\udc61+\ud800\udc02 +\ud800\udc61\udc61\udc61\udc61\ud800\udc02 +true \udc61\udc61\udc61\ud800\udc02 0 + +\ud800\udc61+\ud800\udc02 +\ud800\udc02 +false 0 + +\ud800+\ud800\udc02 +\ud800\udc02 +false 0 + +\ud800\udc61+\ud800\udc02 +\ud800\udc61\ud800\udc61\ud800\udc61ccc +false 0 + +.+\ud800\udc02 +\ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc02 +true \ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc02 0 + +.+\ud800\udc02 +\ud800\udc61\udc61\udc61\udc61\ud800\udc02 +true \ud800\udc61\udc61\udc61\udc61\ud800\udc02 0 + +// Reluctant + metacharacter +\ud800\udc61+?\ud800\udc02 +\ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc02 +true \ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc02 0 + +\udc61+?\ud800\udc02 +\udc61\udc61\udc61\udc61\ud800\udc02 +true \udc61\udc61\udc61\udc61\ud800\udc02 0 + +\ud800\udc61+?\ud800\udc02 +\ud800\udc02 +false 0 + +\ud800+?\ud800\udc02 +\ud800\udc02 +false 0 + +\ud800\udc61+?\ud800\udc02 +\ud800\udc61\ud800\udc61\ud800\udc61ccc +false 0 + +.+?\ud800\udc02 +\ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc02 +true \ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc02 0 + +// Possessive + metacharacter +\ud800\udc61++\ud800\udc02 +\ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc02 +true \ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc02 0 + +\ud800\udc61++\ud800\udc02 +\ud800\udc02 +false 0 + +\ud800\udc61++\ud800\udc02 +\ud800\udc61\ud800\udc61\ud800\udc61ccc +false 0 + +.++\ud800\udc02 +\ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc02 +false 0 + +// Greedy Repetition +\ud800\udc61{2,3} +\ud800\udc61 +false 0 + +\ud800\udc61{2,3} +\ud800\udc61\ud800\udc61 +true \ud800\udc61\ud800\udc61 0 + +\ud800\udc61{2,3} +\ud800\udc61\ud800\udc61\ud800\udc61 +true \ud800\udc61\ud800\udc61\ud800\udc61 0 + +\ud800\udc61{2,3} +\ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc61 +true \ud800\udc61\ud800\udc61\ud800\udc61 0 + +\ud800\udc61{3,} +zzz\ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc61zzz +true \ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc61 0 + +\ud800\udc61{3,} +zzz\ud800\udc61\ud800\udc61zzz +false 0 + +// Reluctant Repetition +\ud800\udc61{2,3}? +\ud800\udc61 +false 0 + +\ud800\udc61{2,3}? +\ud800\udc61\ud800\udc61 +true \ud800\udc61\ud800\udc61 0 + +\ud800\udc61{2,3}? +\ud800\udc61\ud800\udc61\ud800\udc61 +true \ud800\udc61\ud800\udc61 0 + +\ud800\udc61{2,3}? +\ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc61 +true \ud800\udc61\ud800\udc61 0 + +// Zero width Positive lookahead +\ud800\udc61\ud802\udc02\ud803\udc03(?=\ud804\udc04) +zzz\ud800\udc61\ud802\udc02\ud803\udc03\ud804\udc04 +true \ud800\udc61\ud802\udc02\ud803\udc03 0 + +\ud800\udc61\ud802\udc02\ud803\udc03(?=\ud804\udc04) +zzz\ud800\udc61\ud802\udc02\ud803\udc03e\ud804\udc04 +false 0 + +\ud800\udc61\ud802\udc02\ud803\udc03(?=\udcff\ud804\udc04) +zzz\ud800\udc61\ud802\udc02\ud803\udc03\udcff\ud804\udc04 +true \ud800\udc61\ud802\udc02\ud803\udc03 0 + +\ud800\udc61\ud802\udc02\ud803\udc03(?=\udcff\ud804\udc04) +zzz\ud800\udc61\ud802\udc02\ud803\udc03\ud8ff\udcff\ud804\udc04 +false 0 + +// Zero width Negative lookahead +\ud800\udc61\ud802\udc02\ud803\udc03(?!\ud804\udc04) +zz\ud800\udc61\ud802\udc02\ud803\udc03\ud804\udc04 +false 0 + +a\ud802\udc02\ud803\udc03(?!\ud804\udc04) +zza\ud802\udc02\ud803\udc03\udc04\ud804\udc04 +true a\ud802\udc02\ud803\udc03 0 + +\ud800\udc61\ud802\udc02\ud803\udc03(?!\ud804\udc04\ud8ff) +zz\ud800\udc61\ud802\udc02\ud803\udc03\ud804\udc04\ud8ffX +false 0 + +a\ud802\udc02\ud803\udc03(?!\ud804\udc04\ud8ff) +zza\ud802\udc02\ud803\udc03e\ud804\udc04\ud8ff\udcff +true a\ud802\udc02\ud803\udc03 0 + +// Zero width Positive lookbehind +(?<=\ud801\udc01\ud802\udc02)\ud803\udc03 +\ud801\udc01\ud802\udc02\ud803\udc03 +true \ud803\udc03 0 + +// Zero width Negative lookbehind +(?<!\ud801\udc01)\ud802\udc02\ud803\udc03 +###\ud800\udc00\ud802\udc02\ud803\udc03 +true \ud802\udc02\ud803\udc03 0 + +(?<![\ud801\udc01\ud802\udc02])\ud803\udc03. +\ud801\udc01\ud803\udc03x\ud800\udc00\ud803\udc03y +true \ud803\udc03y 0 + +(?<!\ud801\udc01)\ud803\udc03 +\ud801\udc01\ud803\udc03 +false 0 + +// Nondeterministic group +(\ud800\udc61+\ud802)+ +\ud800\udc61\ud802\ud800\udc61\ud802\ud800\udc61\ud802 +true \ud800\udc61\ud802\ud800\udc61\ud802\ud800\udc61\ud802 1 \ud800\udc61\ud802 + +(\ud800\udc61|\ud802)+ +\ud800\ud802\udc61\ud803\ud802\udc61 +false 1 + +// Deterministic group +(\ud800\udc61\ud802)+ +\ud800\udc61\ud802\ud800\udc61\ud802\ud800\udc61\ud802 +true \ud800\udc61\ud802\ud800\udc61\ud802\ud800\udc61\ud802 1 \ud800\udc61\ud802 + +(\ud800\udc61\ud802)+ +\ud800\udc61ccccd +false 1 + +(\ud800\udc61\ud802)* +\ud800\udc61\ud802\ud800\udc61\ud802\ud800\udc61\ud802 +true \ud800\udc61\ud802\ud800\udc61\ud802\ud800\udc61\ud802 1 \ud800\udc61\ud802 + +(\ud800\udc61b)(cd*) +zzz\ud800\udc61bczzz +true \ud800\udc61bc 2 \ud800\udc61b c + +\ud800\udc61bc(\ud804\udc04)*\ud800\udc61bc +\ud800\udc61bc\ud804\udc04\ud804\udc04\ud804\udc04\ud804\udc04\ud804\udc04\ud800\udc61bc +true \ud800\udc61bc\ud804\udc04\ud804\udc04\ud804\udc04\ud804\udc04\ud804\udc04\ud800\udc61bc 1 \ud804\udc04 + +// Back references +(\ud800\udc61*)\ud802\udc02c\1 +zzz\ud800\udc61\ud800\udc61\ud802\udc02c\ud800\udc61\ud800\udc61zzz +true \ud800\udc61\ud800\udc61\ud802\udc02c\ud800\udc61\ud800\udc61 1 \ud800\udc61\ud800\udc61 + +(\ud800\udc61*)\ud802\udc02c\1 +zzz\ud800\udc61\ud800\udc61\ud802\udc02c\ud800\udc61zzz +true \ud800\udc61\ud802\udc02c\ud800\udc61 1 \ud800\udc61 + +(\ud800\udc07\ud800\udc14*)(\ud804\udc04\ud804\udc04e)*(yu)\1\3(vv) +zzz\ud800\udc07\ud800\udc14\ud800\udc14\ud804\udc04\ud804\udc04e\ud804\udc04\ud804\udc04eyu\ud800\udc07\ud800\udc14\ud800\udc14yuvvzzz +true \ud800\udc07\ud800\udc14\ud800\udc14\ud804\udc04\ud804\udc04e\ud804\udc04\ud804\udc04eyu\ud800\udc07\ud800\udc14\ud800\udc14yuvv 4 \ud800\udc07\ud800\udc14\ud800\udc14 \ud804\udc04\ud804\udc04e yu vv + +// Greedy * metacharacter +\ud800\udc61*\ud802\udc02 +\ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc61\ud802\udc02 +true \ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc61\ud802\udc02 0 + +\ud800\udc61*\ud802\udc02 +\ud802\udc02 +true \ud802\udc02 0 + +\ud800\udc61*\ud802\udc02 +\ud800\udc61\ud800\udc61\ud800\udc61ccc +false 0 + +.*\ud802\udc02 +\ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc61\ud802\udc02 +true \ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc61\ud802\udc02 0 + +// Reluctant * metacharacter +\ud800\udc61*?\ud802\udc02 +\ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc61\ud802\udc02 +true \ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc61\ud802\udc02 0 + +\ud800\udc61*?\ud802\udc02 +\ud802\udc02 +true \ud802\udc02 0 + +\ud800\udc61*?\ud802\udc02 +\ud800\udc61\ud800\udc61\ud800\udc61ccc +false 0 + +.*?\ud802\udc02 +\ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc61\ud802\udc02 +true \ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc61\ud802\udc02 0 + +// Possessive * metacharacter +\ud800\udc61*+\ud802\udc02 +\ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc61\ud802\udc02 +true \ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc61\ud802\udc02 0 + +\ud800\udc61*+\ud802\udc02 +\ud802\udc02 +true \ud802\udc02 0 + +\ud800\udc61*+\ud802\udc02 +\ud800\udc61\ud800\udc61\ud800\udc61ccc +false 0 + +.*+\ud802\udc02 +\ud800\udc61\ud800\udc61\ud800\udc61\ud800\udc61\ud802\udc02 +false 0 + +// Case insensitivity +(?iu)\ud801\udc00\ud801\udc01\ud801\udc02x +\ud801\udc28\ud801\udc29\ud801\udc2aX +true \ud801\udc28\ud801\udc29\ud801\udc2aX 0 + +\ud801\udc00(?iu)\ud801\udc01\ud801\udc02 +\ud801\udc00\ud801\udc29\ud801\udc2a +true \ud801\udc00\ud801\udc29\ud801\udc2a 0 + +\ud801\udc00(?iu)\ud801\udc01\ud801\udc02 +\ud801\udc28\ud801\udc29\ud801\udc2a +false 0 + +(?iu)\ud801\udc00[\ud801\udc01\ud801\udc02]+ +\ud801\udc28\ud801\udc29\ud801\udc2a +true \ud801\udc28\ud801\udc29\ud801\udc2a 0 + +(?iu)[\ud801\udc00-\ud801\udc02]+ +\ud801\udc28\ud801\udc29\ud801\udc2a +true \ud801\udc28\ud801\udc29\ud801\udc2a 0 + +// Disable metacharacters- test both length <=3 and >3 +// So that the BM optimization is part of test +\Q***\E\ud801\udc01\ud802\udc02\ud800\udc03 +***\ud801\udc01\ud802\udc02\ud800\udc03 +true ***\ud801\udc01\ud802\udc02\ud800\udc03 0 + +\ud802\udc02l\Q***\E\ud801\udc01\ud802\udc02\ud800\udc03 +\ud802\udc02l***\ud801\udc01\ud802\udc02\ud800\udc03 +true \ud802\udc02l***\ud801\udc01\ud802\udc02\ud800\udc03 0 + +\Q***\ud801\udc01\ud802\udc02\ud800\udc03 +***\ud801\udc01\ud802\udc02\ud800\udc03 +true ***\ud801\udc01\ud802\udc02\ud800\udc03 0 + +\ud802\udc02l\ud801\udc01h\Q***\E\ud801\udc01\ud802\udc02\ud800\udc03 +\ud802\udc02l\ud801\udc01h***\ud801\udc01\ud802\udc02\ud800\udc03 +true \ud802\udc02l\ud801\udc01h***\ud801\udc01\ud802\udc02\ud800\udc03 0 + +\Q***\ud801\udc01\ud802\udc02\ud800\udc03 +***\ud801\udc01\ud802\udc02\ud800\udc03 +true ***\ud801\udc01\ud802\udc02\ud800\udc03 0 + +\Q*\ud801\udc01\ud802\udc02 +*\ud801\udc01\ud802\udc02 +true *\ud801\udc01\ud802\udc02 0 + +\ud802\udc02l\ud801\udc01h\Q***\ud801\udc01\ud802\udc02\ud800\udc03 +\ud802\udc02l\ud801\udc01h***\ud801\udc01\ud802\udc02\ud800\udc03 +true \ud802\udc02l\ud801\udc01h***\ud801\udc01\ud802\udc02\ud800\udc03 0 + +\ud802\udc02l\ud801\udc01\Q***\ud801\udc01\ud802\udc02\ud800\udc03 +\ud802\udc02l\ud801\udc01***\ud801\udc01\ud802\udc02\ud800\udc03 +true \ud802\udc02l\ud801\udc01***\ud801\udc01\ud802\udc02\ud800\udc03 0 + +//Test cases below copied from i18n QE's RegexSupplementaryTests.txt +\uD800\uDFFF\uD801\uDFF1\uDB00\uDC00 +\uD800\uDFFF\uD801\uDFF1\uDB00\uDC00 +true \uD800\uDFFF\uD801\uDFF1\uDB00\uDC00 0 + +\uD800\uDFFF\uD801\uDFF1\uDB00\uDC00 +\u1000\uD801\uDFF1\uDB00\uDC00 +false 0 + +\uD800\uDFFF\uD801\uDFF1\uDB00\uDC00 +\uD800\uDFFF\uFFFF\uDB00\uDC00 +false 0 + +\uD800\uDFFF\uD801\uDFF1\uDB00\uDC00 +\uD800\uDFFF\uD801\uDFF1\uFFFF +false 0 + +\u1000.\uFFFF +\u1000\uD800\uDFFF\uFFFF +true \u1000\uD800\uDFFF\uFFFF 0 + +//======= +// Ranges +//======= +[a-\uD800\uDFFF] +\uDFFF +true \uDFFF 0 + +[a-\uD800\uDFFF] +\uD800 +true \uD800 0 + +[a-\uD800\uDFFF] +\uD800\uDFFF +true \uD800\uDFFF 0 + +[\uD800\uDC00-\uDBFF\uDFFF] +\uDBFF +false 0 + +[\uD800\uDC00-\uDBFF\uDFFF] +\uDC00 +false 0 + +[\uD800-\uDFFF] +\uD800\uDFFF +false 0 + +[\uD800-\uDFFF] +\uDFFF\uD800 +true \uDFFF 0 + +foo[^\uD800-\uDFFF] +foo\uD800\uDFFF +true foo\uD800\uDFFF 0 + +foo[^\uD800-\uDFFF] +foo\uDFFF\uD800 +false 0 + +//fo\uD800[\uDC00-\uDFFF] + +//================== +// Character Classes +//================== +// Simple class +[ab\uD800\uDFFFcd]at +\uD800at +false 0 + +[ab\uD800\uDFFFcd]at +\uD800\uDFFFat +true \uD800\uDFFFat 0 + +// Negation +[^\uD800\uDFFFcd]at +\uD800at +true \uD800at 0 + +[^\uD800\uDFFFcd]at +\uDFFFat +true \uDFFFat 0 + +// Inclusive range +[\u0000-\uD800\uDFFF-\uFFFF] +\uD800\uDFFF +true \uD800\uDFFF 0 + +// Unions +[\u0000-\uD800[\uDFFF-\uFFFF]] +\uD800\uDFFF +false 0 + + +// Intersection +[\u0000-\uFFFF&&[\uD800\uDFFF]] +\uD800\uDFFF +false 0 + +[\u0000-\uFFFF&&[\uD800\uDFFF]] +\uD800 +false 0 + +[\u0000-\uFFFF&&[\uDFFF\uD800]] +\uD800 +true \uD800 0 + +[\u0000-\uFFFF&&[\uDFFF\uD800\uDC00]] +\uDC00 +false 0 + +[\u0000-\uDFFF&&[\uD800-\uFFFF]] +\uD800\uDFFF +false 0 + +[\u0000-\uDFFF&&[\uD800-\uFFFF]] +\uDFFF\uD800 +true \uDFFF 0 + +// Subtraction +[\u0000-\uD800\uDFFF&&[^\uD800\uDC00]] +\uD800 +true \uD800 0 + +[\u0000-\uD800\uDFFF&&[^\uD800\uDC00]] +\uDC00 +true \uDC00 0 + +[\u0000-\uD800\uDFFF&&[^\uD800\uDC00]] +\uD800\uDFFF +true \uD800\uDFFF 0 + +[\u0000-\uD800\uDFFF&&[^\uD800\uDBFF\uDC00]] +\uD800 +false 0 + +[\u0000-\uD800\uDFFF&&[^\uDC00\uD800\uDBFF]] +\uD800\uDC00 +true \uD800\uDC00 0 + +// Quantifiers +a\uD800\uDFFF? +a\uD800 +true a 0 + +a\uD800\uDFFF? +a\uDFFF +true a 0 + +a\uD800\uDFFF? +a\uD800\uDFFF +true a\uD800\uDFFF 0 + +a\uDFFF\uD800? +a\uDFFF +true a\uDFFF 0 + +a\uDFFF\uD800? +a\uD800 +false 0 + +\uD800\uDFFF\uDC00? +\uD800 +false 0 + +\uD800\uDFFF\uDC00? +\uD800\uDFFF +true \uD800\uDFFF 0 + +a\uD800\uDFFF?? +a\uDFFF +true a 0 + +a\uD800\uDFFF* +a +true a 0 + +a\uD800\uDFFF* +a\uD800 +true a 0 + +\uD800\uDFFF* +\uD800\uDFFF\uD800\uDFFF\uD800\uDFFF\uD800\uDFFF +true \uD800\uDFFF\uD800\uDFFF\uD800\uDFFF\uD800\uDFFF 0 + +\uD800\uDFFF* +\uD800\uDFFF\uDFFF\uDFFF\uDFFF +true \uD800\uDFFF 0 + +\uD800*\uDFFF +\uD800\uDFFF +false 0 + +a\uD800\uDFFF* +a\uD800 +true a 0 + +\uDFFF\uD800* +\uDFFF +true \uDFFF 0 + +\uDFFF\uD800* +\uDFFF\uD800\uD800\uD800 +true \uDFFF\uD800\uD800\uD800 0 + +\uD800\uDFFF+ +\uD800\uDFFF\uDFFF\uDFFF +true \uD800\uDFFF 0 + +\uD800\uDFFF+ +\uD800 +false 0 + +\uD800\uDFFF+ +\uD800\uDFFF +true \uD800\uDFFF 0 + +\uD800\uDFFF+ +\uD800\uDFFF\uD800\uDFFF\uD800\uDFFF +true \uD800\uDFFF\uD800\uDFFF\uD800\uDFFF 0 + +\uDFFF\uD800+ +\uDFFF\uD800\uDFFF\uD800 +false 0 + +\uD800+\uDFFF +\uD800\uDFFF +false 0 + +\uD800+\uDFFF +\uD800 +false 0 + +\uDFFF+\uD800 +\uD800 +false 0 + +\uDFFF+\uD800 +\uDFFF\uD800 +true \uDFFF\uD800 0 + +\uD800\uDFFF{3} +\uD800\uDFFF\uDFFF\uDFFF +false 0 + +\uD800\uDFFF{3} +\uD800\uDFFF\uD800\uDFFF\uD800\uDFFF +true \uD800\uDFFF\uD800\uDFFF\uD800\uDFFF 0 + +\uDFFF\uD800{3} +\uDFFF\uD800\uDFFF\uD800\uDFFF\uD800 +false 0 + +\uDFFF\uD800{3} +\uDFFF\uD800\uD800\uD800 +true \uDFFF\uD800\uD800\uD800 0 + +\uD800\uDFFF{2,} +\uD800\uDFFF +false 0 + +\uD800\uDFFF{2,} +\uD800\uDFFF\uDFFF +false 0 + +\uD800\uDFFF{2,} +\uD800\uDFFF\uD800\uDFFF +true \uD800\uDFFF\uD800\uDFFF 0 + +\uDFFF\uD800{2,} +\uDFFF\uD800\uDFFF\uD800 +false 0 + +\uDFFF\uD800{2,} +\uDFFF\uD800\uD800\uD800 +true \uDFFF\uD800\uD800\uD800 0 + +\uD800\uDFFF{3,4} +\uD800\uDFFF\uD800\uDFFF\uD800\uDFFF\uD800\uDFFF +true \uD800\uDFFF\uD800\uDFFF\uD800\uDFFF\uD800\uDFFF 0 + +\uD800\uDFFF{3,4} +\uD800\uDFFF\uD800\uDFFF\uD800\uDFFF\uD800 +true \uD800\uDFFF\uD800\uDFFF\uD800\uDFFF 0 + +\uD800\uDFFF{3,4} +\uD800\uDFFF\uD800\uD800\uDFFF\uD800\uDFFF +false 0 + +\uDFFF\uD800{3,5} +\uDFFF\uD800\uD800\uD800\uD800\uD800\uD800\uD800 +true \uDFFF\uD800\uD800\uD800\uD800\uD800 0 + +\uD800\uDFFF{3,5} +\uD800\uDFFF\uDFFF\uDFFF +false 0 + +\uD800\uDFFF{3,5} +\uD800\uDFFF\uD800\uD800\uDFFF\uD800\uDFFF\uD800\uDFFF +true \uD800\uDFFF\uD800\uDFFF\uD800\uDFFF 0 + +// Groupings +(\uD800(\uDFFF)) +\uD800\uDFFF +false 2 + +(\uD800(\uDC00)(\uDFFF)) +\uD800\uDC00\uDFFF +false 3 + +((\uD800)(\uDFFF)) +\uD800\uDFFF +false 3 + +(\uD800(\uDFFF)\uDFFF) +\uD800\uDFFF +false 2 + +(\uDFFF(\uD800)(\uDBFF)) +\uDFFF\uD800\uDBFF +true \uDFFF\uD800\uDBFF 3 \uDFFF\uD800\uDBFF \uD800 \uDBFF + +(\uDFFF(\uD800)(\uDC00)) +\uDFFF\uD800\uDC00 +false 3 + +(\uDFFF\uD800(\uDC00\uDBFF)) +\uDFFF\uD800\uDC00\uDBFF +false 2 + +(\uD800\uDFFF(\uDBFF)(\uDC00)) +\uD800\uDFFF\uDBFF\uDC00 +false 3 + +(\uD800\uDFFF(\uDBFF\uDC00)) +\uD800\uDFFF\uDBFF\uDC00 +true \uD800\uDFFF\uDBFF\uDC00 2 \uD800\uDFFF\uDBFF\uDC00 \uDBFF\uDC00 diff --git a/test/java/util/regex/TestCases.txt b/test/java/util/regex/TestCases.txt new file mode 100644 index 0000000000000000000000000000000000000000..fd41df33f7683018b13f940f7f593ceeb1949633 --- /dev/null +++ b/test/java/util/regex/TestCases.txt @@ -0,0 +1,1092 @@ +// +// Copyright 1999-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. +// +// 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. +// +// +// This file contains test cases for regular expressions. +// A test case consists of three lines: +// The first line is a pattern used in the test +// The second line is the input to search for the pattern in +// The third line is a concatentation of the match, the number of groups, +// and the contents of the first four subexpressions. +// Empty lines and lines beginning with comment slashes are ignored. +// +// Test unsetting of backed off groups +^(a)?a +a +true a 1 + +^(aa(bb)?)+$ +aabbaa +true aabbaa 2 aa bb + +((a|b)?b)+ +b +true b 2 b + +(aaa)?aaa +aaa +true aaa 1 + +^(a(b)?)+$ +aba +true aba 2 a b + +^(a(b(c)?)?)?abc +abc +true abc 3 + +^(a(b(c))).* +abc +true abc 3 abc bc c + +// use of x modifier +abc(?x)blah +abcblah +true abcblah 0 + +abc(?x) blah +abcblah +true abcblah 0 + +abc(?x) blah blech +abcblahblech +true abcblahblech 0 + +abc(?x) blah # ignore comment +abcblah +true abcblah 0 + +// Simple alternation +a|b +a +true a 0 + +a|b +z +false 0 + +a|b +b +true b 0 + +a|b|cd +cd +true cd 0 + +a|ad +ad +true a 0 + +z(a|ac)b +zacb +true zacb 1 ac + +// Simple char class +[abc]+ +ababab +true ababab 0 + +[abc]+ +defg +false 0 + +[abc]+[def]+[ghi]+ +zzzaaddggzzz +true aaddgg 0 + +// Range char class +[a-g]+ +zzzggg +true ggg 0 + +[a-g]+ +mmm +false 0 + +[a-]+ +za-9z +true a- 0 + +[a-\\u4444]+ +za-9z +true za 0 + +// Negated char class +[^abc]+ +ababab +false 0 + +[^abc]+ +aaabbbcccdefg +true defg 0 + +// Making sure a ^ not in first position matches literal ^ +[abc^b] +b +true b 0 + +[abc^b] +^ +true ^ 0 + +// Class union and intersection +[abc[def]] +b +true b 0 + +[abc[def]] +e +true e 0 + +[a-d[0-9][m-p]] +a +true a 0 + +[a-d[0-9][m-p]] +o +true o 0 + +[a-d[0-9][m-p]] +4 +true 4 0 + +[a-d[0-9][m-p]] +e +false 0 + +[a-d[0-9][m-p]] +u +false 0 + +[[a-d][0-9][m-p]] +b +true b 0 + +[[a-d][0-9][m-p]] +z +false 0 + +[a-c[d-f[g-i]]] +a +true a 0 + +[a-c[d-f[g-i]]] +e +true e 0 + +[a-c[d-f[g-i]]] +h +true h 0 + +[a-c[d-f[g-i]]] +m +false 0 + +[a-c[d-f[g-i]]m] +m +true m 0 + +[abc[def]ghi] +a +true a 0 + +[abc[def]ghi] +d +true d 0 + +[abc[def]ghi] +h +true h 0 + +[abc[def]ghi] +w +false 0 + +[a-c&&[d-f]] +a +false 0 + +[a-c&&[d-f]] +e +false 0 + +[a-c&&[d-f]] +z +false 0 + +[[a-c]&&[d-f]] +a +false 0 + +[[a-c]&&[d-f]] +e +false 0 + +[[a-c]&&[d-f]] +z +false 0 + +[a-c&&d-f] +a +false 0 + +[a-m&&m-z] +m +true m 0 + +[a-m&&m-z&&a-c] +m +false 0 + +[a-m&&m-z&&a-z] +m +true m 0 + +[[a-m]&&[m-z]] +a +false 0 + +[[a-m]&&[m-z]] +m +true m 0 + +[[a-m]&&[m-z]] +z +false 0 + +[[a-m]&&[^a-c]] +a +false 0 + +[[a-m]&&[^a-c]] +d +true d 0 + +[a-m&&[^a-c]] +a +false 0 + +[a-m&&[^a-c]] +d +true d 0 + +[a-cd-f&&[d-f]] +a +false 0 + +[a-cd-f&&[d-f]] +e +true e 0 + +[[a-c]&&d-fa-c] +a +true a 0 + +[[a-c]&&[d-f][a-c]] +a +true a 0 + +[[a-c][d-f]&&abc] +a +true a 0 + +[[a-c][d-f]&&abc[def]] +e +true e 0 + +[[a-c]&&[b-d]&&[c-e]] +a +false 0 + +[[a-c]&&[b-d]&&[c-e]] +c +true c 0 + +[[a-c]&&[b-d][c-e]&&[u-z]] +c +false 0 + +[abc[^bcd]] +a +true a 0 + +[abc[^bcd]] +d +false 0 + +[a-c&&a-d&&a-eghi] +b +true b 0 + +[a-c&&a-d&&a-eghi] +g +false 0 + +[[a[b]]&&[b[a]]] +a +true a 0 + +[[a]&&[b][c][a]&&[^d]] +a +true a 0 + +[[a]&&[b][c][a]&&[^d]] +d +false 0 + +[[[a-d]&&[c-f]]] +a +false 0 + +[[[a-d]&&[c-f]]] +c +true c 0 + +[[[a-d]&&[c-f]]&&[c]] +c +true c 0 + +[[[a-d]&&[c-f]]&&[c]&&c] +c +true c 0 + +[[[a-d]&&[c-f]]&&[c]&&c&&c] +c +true c 0 + +[[[a-d]&&[c-f]]&&[c]&&c&&[cde]] +c +true c 0 + +[z[abc&&bcd]] +c +true c 0 + +[z[abc&&bcd]&&[u-z]] +z +true z 0 + +[x[abc&&bcd[z]]&&[u-z]] +z +false 0 + +[x[[wz]abc&&bcd[z]]&&[u-z]] +z +true z 0 + +[[abc]&&[def]abc] +a +true a 0 + +[[abc]&&[def]xyz[abc]] +a +true a 0 + +\pL +a +true a 0 + +\pL +7 +false 0 + +\p{L} +a +true a 0 + +\p{LC} +a +true a 0 + +\p{LC} +A +true A 0 + +\p{IsL} +a +true a 0 + +\p{IsLC} +a +true a 0 + +\p{IsLC} +A +true A 0 + +\p{IsLC} +9 +false 0 + +\P{IsLC} +9 +true 9 0 + +// Guillemet left is initial quote punctuation +\p{Pi} +\u00ab +true \u00ab 0 + +\P{Pi} +\u00ac +true \u00ac 0 + +// Guillemet right is final quote punctuation +\p{IsPf} +\u00bb +true \u00bb 0 + +\p{P} +\u00bb +true \u00bb 0 + +\p{P}+ +\u00bb +true \u00bb 0 + +\P{IsPf} +\u00bc +true \u00bc 0 + +\P{IsP} +\u00bc +true \u00bc 0 + +\p{L1} +\u00bc +true \u00bc 0 + +\p{L1}+ +\u00bc +true \u00bc 0 + +\p{L1} +\u02bc +false 0 + +\p{ASCII} +a +true a 0 + +\p{IsASCII} +a +true a 0 + +\p{IsASCII} +\u0370 +false 0 + +\pLbc +abc +true abc 0 + +a[r\p{InGreek}]c +a\u0370c +true a\u0370c 0 + +a\p{InGreek} +a\u0370 +true a\u0370 0 + +a\P{InGreek} +a\u0370 +false 0 + +a\P{InGreek} +ab +true ab 0 + +a{^InGreek} +- +error + +a\p{^InGreek} +- +error + +a\P{^InGreek} +- +error + +a\p{InGreek} +a\u0370 +true a\u0370 0 + +a[\p{InGreek}]c +a\u0370c +true a\u0370c 0 + +a[\P{InGreek}]c +a\u0370c +false 0 + +a[\P{InGreek}]c +abc +true abc 0 + +a[{^InGreek}]c +anc +true anc 0 + +a[{^InGreek}]c +azc +false 0 + +a[\p{^InGreek}]c +- +error + +a[\P{^InGreek}]c +- +error + +a[\p{InGreek}] +a\u0370 +true a\u0370 0 + +a[r\p{InGreek}]c +arc +true arc 0 + +a[\p{InGreek}r]c +arc +true arc 0 + +a[r\p{InGreek}]c +arc +true arc 0 + +a[^\p{InGreek}]c +a\u0370c +false 0 + +a[^\P{InGreek}]c +a\u0370c +true a\u0370c 0 + +a[\p{InGreek}&&[^\u0370]]c +a\u0370c +false 0 + +// Test the dot metacharacter +a.c.+ +a#c%& +true a#c%& 0 + +ab. +ab\n +false 0 + +(?s)ab. +ab\n +true ab\n 0 + +a[\p{L}&&[\P{InGreek}]]c +a\u6000c +true a\u6000c 0 + +a[\p{L}&&[\P{InGreek}]]c +arc +true arc 0 + +a[\p{L}&&[\P{InGreek}]]c +a\u0370c +false 0 + +a\p{InGreek}c +a\u0370c +true a\u0370c 0 + +a\p{Sc} +a$ +true a$ 0 + +// Test the word char escape sequence +ab\wc +abcc +true abcc 0 + +\W\w\W +#r# +true #r# 0 + +\W\w\W +rrrr#ggg +false 0 + +abc[\w] +abcd +true abcd 0 + +abc[\sdef]* +abc def +true abc def 0 + +abc[\sy-z]* +abc y z +true abc y z 0 + +abc[a-d\sm-p]* +abcaa mn p +true abcaa mn p 0 + +// Test the whitespace escape sequence +ab\sc +ab c +true ab c 0 + +\s\s\s +blah err +false 0 + +\S\S\s +blah err +true ah 0 + +// Test the digit escape sequence +ab\dc +ab9c +true ab9c 0 + +\d\d\d +blah45 +false 0 + +// Test the caret metacharacter +^abc +abcdef +true abc 0 + +^abc +bcdabc +false 0 + +// Greedy ? metacharacter +a?b +aaaab +true ab 0 + +a?b +b +true b 0 + +a?b +aaaccc +false 0 + +.?b +aaaab +true ab 0 + +// Reluctant ? metacharacter +a??b +aaaab +true ab 0 + +a??b +b +true b 0 + +a??b +aaaccc +false 0 + +.??b +aaaab +true ab 0 + +// Possessive ? metacharacter +a?+b +aaaab +true ab 0 + +a?+b +b +true b 0 + +a?+b +aaaccc +false 0 + +.?+b +aaaab +true ab 0 + +// Greedy + metacharacter +a+b +aaaab +true aaaab 0 + +a+b +b +false 0 + +a+b +aaaccc +false 0 + +.+b +aaaab +true aaaab 0 + +// Reluctant + metacharacter +a+?b +aaaab +true aaaab 0 + +a+?b +b +false 0 + +a+?b +aaaccc +false 0 + +.+?b +aaaab +true aaaab 0 + +// Possessive + metacharacter +a++b +aaaab +true aaaab 0 + +a++b +b +false 0 + +a++b +aaaccc +false 0 + +.++b +aaaab +false 0 + +// Greedy Repetition +a{2,3} +a +false 0 + +a{2,3} +aa +true aa 0 + +a{2,3} +aaa +true aaa 0 + +a{2,3} +aaaa +true aaa 0 + +a{3,} +zzzaaaazzz +true aaaa 0 + +a{3,} +zzzaazzz +false 0 + +// Reluctant Repetition +a{2,3}? +a +false 0 + +a{2,3}? +aa +true aa 0 + +a{2,3}? +aaa +true aa 0 + +a{2,3}? +aaaa +true aa 0 + +// Zero width Positive lookahead +abc(?=d) +zzzabcd +true abc 0 + +abc(?=d) +zzzabced +false 0 + +// Zero width Negative lookahead +abc(?!d) +zzabcd +false 0 + +abc(?!d) +zzabced +true abc 0 + +// Zero width Positive lookbehind +\w(?<=a) +###abc### +true a 0 + +\w(?<=a) +###ert### +false 0 + +// Zero width Negative lookbehind +(?<!a)\w +###abc### +true a 0 + +(?<!a)c +bc +true c 0 + +(?<!a)c +ac +false 0 + +// Nondeterministic group +(a+b)+ +ababab +true ababab 1 ab + +(a|b)+ +ccccd +false 1 + +// Deterministic group +(ab)+ +ababab +true ababab 1 ab + +(ab)+ +accccd +false 1 + +(ab)* +ababab +true ababab 1 ab + +(ab)(cd*) +zzzabczzz +true abc 2 ab c + +abc(d)*abc +abcdddddabc +true abcdddddabc 1 d + +// Escaped metacharacter +\* +* +true * 0 + +\\ +\ +true \ 0 + +\\ +\\\\ +true \ 0 + +// Back references +(a*)bc\1 +zzzaabcaazzz +true aabcaa 1 aa + +(a*)bc\1 +zzzaabcazzz +true abca 1 a + +(gt*)(dde)*(yu)\1\3(vv) +zzzgttddeddeyugttyuvvzzz +true gttddeddeyugttyuvv 4 gtt dde yu vv + +// Greedy * metacharacter +a*b +aaaab +true aaaab 0 + +a*b +b +true b 0 + +a*b +aaaccc +false 0 + +.*b +aaaab +true aaaab 0 + +// Reluctant * metacharacter +a*?b +aaaab +true aaaab 0 + +a*?b +b +true b 0 + +a*?b +aaaccc +false 0 + +.*?b +aaaab +true aaaab 0 + +// Possessive * metacharacter +a*+b +aaaab +true aaaab 0 + +a*+b +b +true b 0 + +a*+b +aaaccc +false 0 + +.*+b +aaaab +false 0 + +// Case insensitivity +(?i)foobar +fOobAr +true fOobAr 0 + +f(?i)oobar +fOobAr +true fOobAr 0 + +foo(?i)bar +fOobAr +false 0 + +(?i)foo[bar]+ +foObAr +true foObAr 0 + +(?i)foo[a-r]+ +foObAr +true foObAr 0 + +// Disable metacharacters- test both length <=3 and >3 +// So that the BM optimization is part of test +\Q***\Eabc +***abc +true ***abc 0 + +bl\Q***\Eabc +bl***abc +true bl***abc 0 + +\Q***abc +***abc +true ***abc 0 + +blah\Q***\Eabc +blah***abc +true blah***abc 0 + +\Q***abc +***abc +true ***abc 0 + +\Q*ab +*ab +true *ab 0 + +blah\Q***abc +blah***abc +true blah***abc 0 + +bla\Q***abc +bla***abc +true bla***abc 0 + +// Escapes in char classes +[ab\Qdef\E] +d +true d 0 + +[ab\Q[\E] +[ +true [ 0 + +[\Q]\E] +] +true ] 0 + +[\Q\\E] +\ +true \ 0 + +[\Q(\E] +( +true ( 0 + +[\n-#] +! +true ! 0 + +[\n-#] +- +false 0 + +[\w-#] +! +false 0 + +[\w-#] +a +true a 0 + +[\w-#] +- +true - 0 + +[\w-#] +# +true # 0 + +[\043]+ +blahblah#blech +true # 0 + +[\042-\044]+ +blahblah#blech +true # 0 + +[\u1234-\u1236] +blahblah\u1235blech +true \u1235 0 + +[^\043]* +blahblah#blech +true blahblah 0 + +(|f)?+ +foo +true 1 diff --git a/test/java/util/zip/LargeZip.java b/test/java/util/zip/LargeZip.java new file mode 100644 index 0000000000000000000000000000000000000000..e49950261b61b727adcf7cad02d1e974b55280cb --- /dev/null +++ b/test/java/util/zip/LargeZip.java @@ -0,0 +1,193 @@ +/* + * 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. + */ + +import java.io.*; +import java.nio.*; +import java.util.*; +import java.util.zip.*; + +public class LargeZip { + // If true, don't delete large ZIP file created for test. + static final boolean debug = System.getProperty("debug") != null; + + //static final int DATA_LEN = 1024 * 1024; + static final int DATA_LEN = 80 * 1024; + static final int DATA_SIZE = 8; + + static long fileSize = 6L * 1024L * 1024L * 1024L; // 6GB + + static boolean userFile = false; + + static byte[] data; + static File largeFile; + static String lastEntryName; + + /* args can be empty, in which case check a 3 GB file which is created for + * this test (and then deleted). Or it can be a number, in which case + * that designates the size of the file that's created for this test (and + * then deleted). Or it can be the name of a file to use for the test, in + * which case it is *not* deleted. Note that in this last case, the data + * comparison might fail. + */ + static void realMain (String[] args) throws Throwable { + if (args.length > 0) { + try { + fileSize = Long.parseLong(args[0]); + System.out.println("Testing with file of size " + fileSize); + } catch (NumberFormatException ex) { + largeFile = new File(args[0]); + if (!largeFile.exists()) { + throw new Exception("Specified file " + args[0] + " does not exist"); + } + userFile = true; + System.out.println("Testing with user-provided file " + largeFile); + } + } + File testDir = null; + if (largeFile == null) { + testDir = new File(System.getProperty("test.scratch", "."), + "LargeZip"); + if (testDir.exists()) { + if (!testDir.delete()) { + throw new Exception("Cannot delete already-existing test directory"); + } + } + check(!testDir.exists() && testDir.mkdirs()); + largeFile = new File(testDir, "largezip.zip"); + createLargeZip(); + } + + readLargeZip1(); + readLargeZip2(); + + if (!userFile && !debug) { + check(largeFile.delete()); + check(testDir.delete()); + } + } + + static void createLargeZip() throws Throwable { + int iterations = DATA_LEN / DATA_SIZE; + ByteBuffer bb = ByteBuffer.allocate(DATA_SIZE); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + for (int i = 0; i < iterations; i++) { + bb.putDouble(0, Math.random()); + baos.write(bb.array(), 0, DATA_SIZE); + } + data = baos.toByteArray(); + + ZipOutputStream zos = new ZipOutputStream( + new BufferedOutputStream(new FileOutputStream(largeFile))); + long length = 0; + while (length < fileSize) { + ZipEntry ze = new ZipEntry("entry-" + length); + lastEntryName = ze.getName(); + zos.putNextEntry(ze); + zos.write(data, 0, data.length); + zos.closeEntry(); + length = largeFile.length(); + } + System.out.println("Last entry written is " + lastEntryName); + zos.close(); + } + + static void readLargeZip1() throws Throwable { + ZipFile zipFile = new ZipFile(largeFile); + ZipEntry entry = null; + String entryName = null; + int count = 0; + Enumeration<? extends ZipEntry> entries = zipFile.entries(); + while (entries.hasMoreElements()) { + entry = entries.nextElement(); + entryName = entry.getName(); + count++; + } + System.out.println("Number of entries read: " + count); + System.out.println("Last entry read is " + entryName); + check(!entry.isDirectory()); + if (check(entryName.equals(lastEntryName))) { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + InputStream is = zipFile.getInputStream(entry); + byte buf[] = new byte[4096]; + int len; + while ((len = is.read(buf)) >= 0) { + baos.write(buf, 0, len); + } + baos.close(); + is.close(); + check(Arrays.equals(data, baos.toByteArray())); + } + } + + + static void readLargeZip2() throws Throwable { + ZipInputStream zis = new ZipInputStream( + new BufferedInputStream(new FileInputStream(largeFile))); + ZipEntry entry = null; + String entryName = null; + int count = 0; + while ((entry = zis.getNextEntry()) != null) { + entryName = entry.getName(); + if (entryName.equals(lastEntryName)) { + break; + } + count++; + } + System.out.println("Number of entries read: " + count); + System.out.println("Last entry read is " + entryName); + check(!entry.isDirectory()); + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + + byte buf[] = new byte[4096]; + int len; + while ((len = zis.read(buf)) >= 0) { + baos.write(buf, 0, len); + } + baos.close(); + check(Arrays.equals(data, baos.toByteArray())); + check(zis.getNextEntry() == null); + zis.close(); + } + + + //--------------------- Infrastructure --------------------------- + static volatile int passed = 0, failed = 0; + static void pass() {passed++;} + static void pass(String msg) {System.out.println(msg); passed++;} + static void fail() {failed++; Thread.dumpStack();} + static void fail(String msg) {System.out.println(msg); fail();} + static void unexpected(Throwable t) {failed++; t.printStackTrace();} + static void unexpected(Throwable t, String msg) { + System.out.println(msg); failed++; t.printStackTrace();} + static boolean check(boolean cond) {if (cond) pass(); else fail(); return cond;} + static void equal(Object x, Object y) { + if (x == null ? y == null : x.equals(y)) pass(); + else fail(x + " not equal to " + y);} + public static void main(String[] args) throws Throwable { + try {realMain(args);} catch (Throwable t) {unexpected(t);} + System.out.println("\nPassed = " + passed + " failed = " + failed); + if (failed > 0) throw new AssertionError("Some tests failed");} +} diff --git a/test/java/util/zip/ZipFile/LargeZipFile.java b/test/java/util/zip/ZipFile/LargeZipFile.java new file mode 100644 index 0000000000000000000000000000000000000000..d228a5f93e334de29b952d36a8c5b9dd7e735672 --- /dev/null +++ b/test/java/util/zip/ZipFile/LargeZipFile.java @@ -0,0 +1,160 @@ +/* + * 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. + * + * 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. + */ + +import java.io.*; +import java.nio.*; +import java.util.*; +import java.util.zip.*; + +public class LargeZipFile { + // If true, don't delete large ZIP file created for test. + static final boolean debug = System.getProperty("debug") != null; + + static final int DATA_LEN = 1024 * 1024; + static final int DATA_SIZE = 8; + + static long fileSize = 3L * 1024L * 1024L * 1024L; // 3GB + + static boolean userFile = false; + + static byte[] data; + static File largeFile; + static String lastEntryName; + + /* args can be empty, in which case check a 3 GB file which is created for + * this test (and then deleted). Or it can be a number, in which case + * that designates the size of the file that's created for this test (and + * then deleted). Or it can be the name of a file to use for the test, in + * which case it is *not* deleted. Note that in this last case, the data + * comparison might fail. + */ + static void realMain (String[] args) throws Throwable { + if (args.length > 0) { + try { + fileSize = Long.parseLong(args[0]); + System.out.println("Testing with file of size " + fileSize); + } catch (NumberFormatException ex) { + largeFile = new File(args[0]); + if (!largeFile.exists()) { + throw new Exception("Specified file " + args[0] + " does not exist"); + } + userFile = true; + System.out.println("Testing with user-provided file " + largeFile); + } + } + File testDir = null; + if (largeFile == null) { + testDir = new File(System.getProperty("test.scratch", "."), + "LargeZip"); + if (testDir.exists()) { + if (!testDir.delete()) { + throw new Exception("Cannot delete already-existing test directory"); + } + } + check(!testDir.exists() && testDir.mkdirs()); + largeFile = new File(testDir, "largezip.zip"); + createLargeZip(); + } + + readLargeZip(); + + if (!userFile && !debug) { + check(largeFile.delete()); + check(testDir.delete()); + } + } + + static void createLargeZip() throws Throwable { + int iterations = DATA_LEN / DATA_SIZE; + ByteBuffer bb = ByteBuffer.allocate(DATA_SIZE); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + for (int i = 0; i < iterations; i++) { + bb.putDouble(0, Math.random()); + baos.write(bb.array(), 0, DATA_SIZE); + } + data = baos.toByteArray(); + + ZipOutputStream zos = new ZipOutputStream( + new BufferedOutputStream(new FileOutputStream(largeFile))); + long length = 0; + while (length < fileSize) { + ZipEntry ze = new ZipEntry("entry-" + length); + lastEntryName = ze.getName(); + zos.putNextEntry(ze); + zos.write(data, 0, data.length); + zos.closeEntry(); + length = largeFile.length(); + } + System.out.println("Last entry written is " + lastEntryName); + zos.close(); + } + + static void readLargeZip() throws Throwable { + ZipFile zipFile = new ZipFile(largeFile); + ZipEntry entry = null; + String entryName = null; + int count = 0; + Enumeration<? extends ZipEntry> entries = zipFile.entries(); + while (entries.hasMoreElements()) { + entry = entries.nextElement(); + entryName = entry.getName(); + count++; + } + System.out.println("Number of entries read: " + count); + System.out.println("Last entry read is " + entryName); + check(!entry.isDirectory()); + if (check(entryName.equals(lastEntryName))) { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + InputStream is = zipFile.getInputStream(entry); + byte buf[] = new byte[4096]; + int len; + while ((len = is.read(buf)) >= 0) { + baos.write(buf, 0, len); + } + baos.close(); + is.close(); + check(Arrays.equals(data, baos.toByteArray())); + } + try { + zipFile.close(); + } catch (IOException ioe) {/* what can you do */ } + } + + //--------------------- Infrastructure --------------------------- + static volatile int passed = 0, failed = 0; + static void pass() {passed++;} + static void pass(String msg) {System.out.println(msg); passed++;} + static void fail() {failed++; Thread.dumpStack();} + static void fail(String msg) {System.out.println(msg); fail();} + static void unexpected(Throwable t) {failed++; t.printStackTrace();} + static void unexpected(Throwable t, String msg) { + System.out.println(msg); failed++; t.printStackTrace();} + static boolean check(boolean cond) {if (cond) pass(); else fail(); return cond;} + static void equal(Object x, Object y) { + if (x == null ? y == null : x.equals(y)) pass(); + else fail(x + " not equal to " + y);} + public static void main(String[] args) throws Throwable { + try {realMain(args);} catch (Throwable t) {unexpected(t);} + System.out.println("\nPassed = " + passed + " failed = " + failed); + if (failed > 0) throw new AssertionError("Some tests failed");} +} diff --git a/test/javax/imageio/metadata/BooleanAttributes.java b/test/javax/imageio/metadata/BooleanAttributes.java new file mode 100644 index 0000000000000000000000000000000000000000..104b12432c8583d1ccb9d93693bb43c7ecd0326b --- /dev/null +++ b/test/javax/imageio/metadata/BooleanAttributes.java @@ -0,0 +1,202 @@ +/* + * Copyright 2008 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. + */ + +/** + * @test + * @bug 5082756 + * @summary ensure that boolean attributes follow ( "TRUE" | "FALSE" ) + * including correct (i.e. upper) case + * + * @run main BooleanAttributes + */ + +import java.awt.image.BufferedImage; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.StringReader; +import java.util.Arrays; +import java.util.List; +import javax.imageio.IIOImage; +import javax.imageio.ImageIO; +import javax.imageio.ImageReader; +import javax.imageio.ImageTypeSpecifier; +import javax.imageio.ImageWriteParam; +import javax.imageio.ImageWriter; +import javax.imageio.metadata.IIOMetadata; +import javax.imageio.stream.ImageInputStream; +import javax.imageio.stream.ImageOutputStream; +import javax.imageio.stream.MemoryCacheImageInputStream; +import javax.imageio.stream.MemoryCacheImageOutputStream; +import javax.xml.transform.Result; +import javax.xml.transform.Source; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMResult; +import javax.xml.transform.stream.StreamSource; +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathConstants; +import javax.xml.xpath.XPathFactory; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +public class BooleanAttributes { + + private static TransformerFactory transformerFactory = + TransformerFactory.newInstance(); + + private static XPath xpathEngine = XPathFactory.newInstance().newXPath(); + + public static void main(String[] args) throws Exception { + test("image/png", false, "<javax_imageio_1.0 />", + "Chroma/BlackIsZero/@value", + "Compression/Lossless/@value"); + + test("image/png", false, + "<javax_imageio_png_1.0>" + + "<iTXt><iTXtEntry keyword='Comment' compressionFlag='TRUE' " + + "compressionMethod='0' languageTag='en' " + + "translatedKeyword='comment' text='foo'/></iTXt>" + + "</javax_imageio_png_1.0>", + "iTXt/iTXtEntry/@compressionFlag"); + + test("image/png", false, + "<javax_imageio_png_1.0>" + + "<iTXt><iTXtEntry keyword='Comment' compressionFlag='FALSE' " + + "compressionMethod='0' languageTag='en' " + + "translatedKeyword='comment' text='foo'/></iTXt>" + + "</javax_imageio_png_1.0>", + "iTXt/iTXtEntry/@compressionFlag"); + + test("image/gif", false, "<javax_imageio_1.0 />", + "Chroma/BlackIsZero/@value", + "Compression/Lossless/@value"); + + test("image/gif", false, + "<javax_imageio_gif_image_1.0>" + + "<ImageDescriptor imageLeftPosition='0' imageTopPosition='0' " + + "imageWidth='16' imageHeight='16' interlaceFlag='TRUE' />" + + "<LocalColorTable sizeOfLocalColorTable='2' " + + "backgroundColorIndex='1' sortFlag='TRUE'>" + + "<ColorTableEntry index='0' red='0' green='0' blue='0' />" + + "<ColorTableEntry index='1' red='255' green='255' blue='255' />" + + "</LocalColorTable>" + + "<GraphicControlExtension disposalMethod='doNotDispose' " + + "userInputFlag='FALSE' transparentColorFlag='TRUE' " + + "delayTime='100' transparentColorIndex='1' />" + + "</javax_imageio_gif_image_1.0>", + "ImageDescriptor/@interlaceFlag", + "LocalColorTable/@sortFlag", + "GraphicControlExtension/@userInputFlag", + "GraphicControlExtension/@transparentColorFlag"); + + test("image/gif", true, + "<javax_imageio_gif_stream_1.0>" + + "<GlobalColorTable sizeOfGlobalColorTable='2' " + + "backgroundColorIndex='1' sortFlag='TRUE'>" + + "<ColorTableEntry index='0' red='0' green='0' blue='0' />" + + "<ColorTableEntry index='1' red='255' green='255' blue='255' />" + + "</GlobalColorTable>" + + "</javax_imageio_gif_stream_1.0>", + "GlobalColorTable/@sortFlag"); + + test("image/jpeg", false, "<javax_imageio_1.0 />", + "Compression/Lossless/@value"); + } + + private static void transform(Source src, Result dst) + throws Exception + { + transformerFactory.newTransformer().transform(src, dst); + } + + private static void verify(Node meta, String[] xpaths, boolean required) + throws Exception + { + for (String xpath: xpaths) { + NodeList list = (NodeList) + xpathEngine.evaluate(xpath, meta, XPathConstants.NODESET); + if (list.getLength() == 0 && required) + throw new AssertionError("Missing value: " + xpath); + for (int i = 0; i < list.getLength(); ++i) { + String value = list.item(i).getNodeValue(); + if (!(value.equals("TRUE") || value.equals("FALSE"))) + throw new AssertionError(xpath + " has value " + value); + } + } + } + + public static void test(String mimeType, boolean useStreamMeta, + String metaXml, String... boolXpaths) + throws Exception + { + BufferedImage img = + new BufferedImage(16, 16, BufferedImage.TYPE_INT_RGB); + ImageWriter iw = ImageIO.getImageWritersByMIMEType(mimeType).next(); + ByteArrayOutputStream os = new ByteArrayOutputStream(); + ImageOutputStream ios = new MemoryCacheImageOutputStream(os); + iw.setOutput(ios); + ImageWriteParam param = null; + IIOMetadata streamMeta = iw.getDefaultStreamMetadata(param); + IIOMetadata imageMeta = + iw.getDefaultImageMetadata(new ImageTypeSpecifier(img), param); + IIOMetadata meta = useStreamMeta ? streamMeta : imageMeta; + Source src = new StreamSource(new StringReader(metaXml)); + DOMResult dst = new DOMResult(); + transform(src, dst); + Document doc = (Document)dst.getNode(); + Element node = doc.getDocumentElement(); + String metaFormat = node.getNodeName(); + + // Verify that the default metadata gets formatted correctly. + verify(meta.getAsTree(metaFormat), boolXpaths, false); + + meta.mergeTree(metaFormat, node); + + // Verify that the merged metadata gets formatte correctly. + verify(meta.getAsTree(metaFormat), boolXpaths, true); + + iw.write(streamMeta, new IIOImage(img, null, imageMeta), param); + iw.dispose(); + ios.close(); + ImageReader ir = ImageIO.getImageReader(iw); + byte[] bytes = os.toByteArray(); + if (bytes.length == 0) + throw new AssertionError("Zero length image file"); + ByteArrayInputStream is = new ByteArrayInputStream(bytes); + ImageInputStream iis = new MemoryCacheImageInputStream(is); + ir.setInput(iis); + if (useStreamMeta) meta = ir.getStreamMetadata(); + else meta = ir.getImageMetadata(0); + + // Verify again after writing and re-reading the image + verify(meta.getAsTree(metaFormat), boolXpaths, true); + } + + public static void xtest(Object... eatAnyArguments) { + System.err.println("Disabled test! Change xtest back into test!"); + } + +} diff --git a/test/javax/imageio/plugins/gif/EncodeSubImageTest.java b/test/javax/imageio/plugins/gif/EncodeSubImageTest.java new file mode 100644 index 0000000000000000000000000000000000000000..407242161c223c36f1c6e923400f5c2bdc96353b --- /dev/null +++ b/test/javax/imageio/plugins/gif/EncodeSubImageTest.java @@ -0,0 +1,161 @@ +/* + * 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. + * + * 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. + */ + +/** + * @test + * @bug 6795544 + * + * @summary Test verifes that Image I/O gif writer correctly handles + * buffered images based on translated reasters (typically + * produced by getSubImage() method). + * + * @run main EncodeSubImageTest gif + */ + +import java.awt.Color; +import java.awt.Graphics; +import java.awt.image.BufferedImage; +import java.awt.image.Raster; +import java.io.File; +import java.io.IOException; +import javax.imageio.IIOImage; +import javax.imageio.ImageIO; +import javax.imageio.ImageWriteParam; +import javax.imageio.ImageWriter; +import javax.imageio.stream.ImageOutputStream; + +public class EncodeSubImageTest { + private static String format = "gif"; + private static ImageWriter writer; + private static String file_suffix; + private static final int subSampleX = 2; + private static final int subSampleY = 2; + + public static void main(String[] args) throws IOException { + if (args.length > 0) { + format = args[0]; + } + + writer = ImageIO.getImageWritersByFormatName(format).next(); + + file_suffix =writer.getOriginatingProvider().getFileSuffixes()[0]; + + BufferedImage src = createTestImage(); + EncodeSubImageTest m1 = new EncodeSubImageTest(src); + m1.doTest("test_src"); + + BufferedImage sub = src.getSubimage(subImageOffset, subImageOffset, + src.getWidth() - 2 * subImageOffset, + src.getHeight() - 2 * subImageOffset); + EncodeSubImageTest m2 = new EncodeSubImageTest(sub); + m2.doTest("test_sub"); + } + + BufferedImage img; + + public EncodeSubImageTest(BufferedImage img) { + this.img = img; + } + + public void doTest(String prefix) throws IOException { + System.out.println(prefix); + File f = new File(prefix + file_suffix); + write(f, false); + verify(f, false); + + System.out.println(prefix + "_subsampled"); + f = new File(prefix + "_subsampled"); + write(f, true); + verify(f, true); + + System.out.println(prefix + ": Test PASSED."); + } + + private static final int subImageOffset = 10; + + private void verify(File f, boolean isSubsampled) { + BufferedImage dst = null; + try { + dst = ImageIO.read(f); + } catch (IOException e) { + throw new RuntimeException("Test FAILED: can't readin test image " + + f.getAbsolutePath(), e); + } + if (dst == null) { + throw new RuntimeException("Test FAILED: no dst image available."); + } + + checkPixel(dst, 0, 0, isSubsampled); + + checkPixel(dst, img.getWidth() / 2, img.getHeight() / 2, isSubsampled); + } + + private void checkPixel(BufferedImage dst, int x, int y, + boolean isSubsampled) + { + int dx = isSubsampled ? x / subSampleX : x; + int dy = isSubsampled ? y / subSampleY : y; + int src_rgb = img.getRGB(x, y); + System.out.printf("src_rgb: %x\n", src_rgb); + + int dst_rgb = dst.getRGB(dx, dy); + System.out.printf("dst_rgb: %x\n", dst_rgb); + + if (src_rgb != dst_rgb) { + throw new RuntimeException("Test FAILED: invalid color in dst"); + } + } + + private static BufferedImage createTestImage() { + int w = 100; + int h = 100; + + BufferedImage src = new BufferedImage(w, h, + BufferedImage.TYPE_BYTE_INDEXED); + Graphics g = src.createGraphics(); + g.setColor(Color.red); + g.fillRect(0, 0, w, h); + g.setColor(Color.green); + g.fillRect(subImageOffset, subImageOffset, + w - 2 * subImageOffset, h - 2* subImageOffset); + g.setColor(Color.blue); + g.fillRect(2 * subImageOffset, 2 * subImageOffset, + w - 4 * subImageOffset, h - 4 * subImageOffset); + g.dispose(); + + return src; + } + + private void write(File f, boolean subsample) throws IOException { + ImageOutputStream ios = ImageIO.createImageOutputStream(f); + + writer.setOutput(ios); + ImageWriteParam p = writer.getDefaultWriteParam(); + if (subsample) { + p.setSourceSubsampling(subSampleX, subSampleY, 0, 0); + } + writer.write(null, new IIOImage(img, null, null), p); + ios.close(); + writer.reset(); + } +} diff --git a/test/javax/imageio/plugins/png/ITXtTest.java b/test/javax/imageio/plugins/png/ITXtTest.java index 9bace7462272070e98ebcb8542ad7b9f6c2fee72..ec81bd874ac8363183678923c045b0322188f91f 100644 --- a/test/javax/imageio/plugins/png/ITXtTest.java +++ b/test/javax/imageio/plugins/png/ITXtTest.java @@ -123,7 +123,7 @@ public class ITXtTest { } t.keyword = e.getAttribute("keyword"); t.isCompressed = - (Integer.valueOf(e.getAttribute("compressionFlag")).intValue() == 1); + Boolean.valueOf(e.getAttribute("compressionFlag")).booleanValue(); t.compression = Integer.valueOf(e.getAttribute("compressionMethod")).intValue(); t.language = e.getAttribute("languageTag"); diff --git a/test/javax/imageio/plugins/png/ItxtUtf8Test.java b/test/javax/imageio/plugins/png/ItxtUtf8Test.java new file mode 100644 index 0000000000000000000000000000000000000000..e35495bdee1ebcc4243a17b14e20f44b43b45676 --- /dev/null +++ b/test/javax/imageio/plugins/png/ItxtUtf8Test.java @@ -0,0 +1,241 @@ +/* + * Copyright 2008 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. + * + * 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. + */ + +/** + * @test + * @bug 6541476 6782079 + * @summary Write and read a PNG file including an non-latin1 iTXt chunk + * Test also verifies that trunkated png images does not cause + * an OoutOfMemory error. + * + * @run main ItxtUtf8Test + * + * @run main/othervm/timeout=10 -Xmx2m ItxtUtf8Test truncate + */ + +import java.awt.image.BufferedImage; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.OutputStream; +import java.util.Arrays; +import java.util.List; +import javax.imageio.IIOException; +import javax.imageio.IIOImage; +import javax.imageio.ImageIO; +import javax.imageio.ImageReader; +import javax.imageio.ImageTypeSpecifier; +import javax.imageio.ImageWriter; +import javax.imageio.metadata.IIOMetadata; +import javax.imageio.stream.ImageInputStream; +import javax.imageio.stream.ImageOutputStream; +import javax.imageio.stream.MemoryCacheImageInputStream; +import javax.imageio.stream.MemoryCacheImageOutputStream; +import org.w3c.dom.DOMImplementation; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.bootstrap.DOMImplementationRegistry; + +public class ItxtUtf8Test { + + public static final String + TEXT = "\u24c9\u24d4\u24e7\u24e3" + + "\ud835\udc13\ud835\udc1e\ud835\udc31\ud835\udc2d" + + "\u24c9\u24d4\u24e7\u24e3", // a repetition for compression + VERBATIM = "\u24e5\u24d4\u24e1\u24d1\u24d0\u24e3\u24d8\u24dc", + COMPRESSED = "\u24d2\u24de\u24dc\u24df\u24e1\u24d4\u24e2\u24e2\u24d4\u24d3"; + + public static final byte[] + VBYTES = { + (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x56, // chunk length + (byte)0x69, (byte)0x54, (byte)0x58, (byte)0x74, // chunk type "iTXt" + (byte)0x76, (byte)0x65, (byte)0x72, (byte)0x62, + (byte)0x61, (byte)0x74, (byte)0x69, (byte)0x6d, // keyword "verbatim" + (byte)0x00, // separator terminating keyword + (byte)0x00, // compression flag + (byte)0x00, // compression method, must be zero + (byte)0x78, (byte)0x2d, (byte)0x63, (byte)0x69, + (byte)0x72, (byte)0x63, (byte)0x6c, (byte)0x65, + (byte)0x64, // language tag "x-circled" + (byte)0x00, // separator terminating language tag + (byte)0xe2, (byte)0x93, (byte)0xa5, // '\u24e5' + (byte)0xe2, (byte)0x93, (byte)0x94, // '\u24d4' + (byte)0xe2, (byte)0x93, (byte)0xa1, // '\u24e1' + (byte)0xe2, (byte)0x93, (byte)0x91, // '\u24d1' + (byte)0xe2, (byte)0x93, (byte)0x90, // '\u24d0' + (byte)0xe2, (byte)0x93, (byte)0xa3, // '\u24e3' + (byte)0xe2, (byte)0x93, (byte)0x98, // '\u24d8' + (byte)0xe2, (byte)0x93, (byte)0x9c, // '\u24dc' + (byte)0x00, // separator terminating the translated keyword + (byte)0xe2, (byte)0x93, (byte)0x89, // '\u24c9' + (byte)0xe2, (byte)0x93, (byte)0x94, // '\u24d4' + (byte)0xe2, (byte)0x93, (byte)0xa7, // '\u24e7' + (byte)0xe2, (byte)0x93, (byte)0xa3, // '\u24e3' + (byte)0xf0, (byte)0x9d, (byte)0x90, (byte)0x93, // '\ud835\udc13' + (byte)0xf0, (byte)0x9d, (byte)0x90, (byte)0x9e, // '\ud835\udc1e' + (byte)0xf0, (byte)0x9d, (byte)0x90, (byte)0xb1, // '\ud835\udc31' + (byte)0xf0, (byte)0x9d, (byte)0x90, (byte)0xad, // '\ud835\udc2d' + (byte)0xe2, (byte)0x93, (byte)0x89, // '\u24c9' + (byte)0xe2, (byte)0x93, (byte)0x94, // '\u24d4' + (byte)0xe2, (byte)0x93, (byte)0xa7, // '\u24e7' + (byte)0xe2, (byte)0x93, (byte)0xa3, // '\u24e3' + (byte)0xb5, (byte)0xcc, (byte)0x97, (byte)0x56 // CRC + }, + CBYTES = { + // we don't want to check the chunk length, + // as this might depend on implementation. + (byte)0x69, (byte)0x54, (byte)0x58, (byte)0x74, // chunk type "iTXt" + (byte)0x63, (byte)0x6f, (byte)0x6d, (byte)0x70, + (byte)0x72, (byte)0x65, (byte)0x73, (byte)0x73, + (byte)0x65, (byte)0x64, // keyword "compressed" + (byte)0x00, // separator terminating keyword + (byte)0x01, // compression flag + (byte)0x00, // compression method, 0=deflate + (byte)0x78, (byte)0x2d, (byte)0x63, (byte)0x69, + (byte)0x72, (byte)0x63, (byte)0x6c, (byte)0x65, + (byte)0x64, // language tag "x-circled" + (byte)0x00, // separator terminating language tag + // we don't want to check the actual compressed data, + // as this might depend on implementation. + }; +/* +*/ + + public static void main(String[] args) throws Exception { + List argList = Arrays.asList(args); + if (argList.contains("truncate")) { + try { + runTest(false, true); + throw new AssertionError("Expect an error for truncated file"); + } + catch (IIOException e) { + // expected an error for a truncated image file. + } + } + else { + runTest(argList.contains("dump"), false); + } + } + + public static void runTest(boolean dump, boolean truncate) + throws Exception + { + String format = "javax_imageio_png_1.0"; + BufferedImage img = + new BufferedImage(16, 16, BufferedImage.TYPE_INT_RGB); + ImageWriter iw = ImageIO.getImageWritersByMIMEType("image/png").next(); + ByteArrayOutputStream os = new ByteArrayOutputStream(); + ImageOutputStream ios = new MemoryCacheImageOutputStream(os); + iw.setOutput(ios); + IIOMetadata meta = + iw.getDefaultImageMetadata(new ImageTypeSpecifier(img), null); + DOMImplementationRegistry registry; + registry = DOMImplementationRegistry.newInstance(); + DOMImplementation impl = registry.getDOMImplementation("XML 3.0"); + Document doc = impl.createDocument(null, format, null); + Element root, itxt, entry; + root = doc.getDocumentElement(); + root.appendChild(itxt = doc.createElement("iTXt")); + itxt.appendChild(entry = doc.createElement("iTXtEntry")); + entry.setAttribute("keyword", "verbatim"); + entry.setAttribute("compressionFlag", "false"); + entry.setAttribute("compressionMethod", "0"); + entry.setAttribute("languageTag", "x-circled"); + entry.setAttribute("translatedKeyword", VERBATIM); + entry.setAttribute("text", TEXT); + itxt.appendChild(entry = doc.createElement("iTXtEntry")); + entry.setAttribute("keyword", "compressed"); + entry.setAttribute("compressionFlag", "true"); + entry.setAttribute("compressionMethod", "0"); + entry.setAttribute("languageTag", "x-circled"); + entry.setAttribute("translatedKeyword", COMPRESSED); + entry.setAttribute("text", TEXT); + meta.mergeTree(format, root); + iw.write(new IIOImage(img, null, meta)); + iw.dispose(); + + byte[] bytes = os.toByteArray(); + if (dump) + System.out.write(bytes); + if (findBytes(VBYTES, bytes) < 0) + throw new AssertionError("verbatim block not found"); + if (findBytes(CBYTES, bytes) < 0) + throw new AssertionError("compressed block not found"); + int length = bytes.length; + if (truncate) + length = findBytes(VBYTES, bytes) + 32; + + ImageReader ir = ImageIO.getImageReader(iw); + ByteArrayInputStream is = new ByteArrayInputStream(bytes, 0, length); + ImageInputStream iis = new MemoryCacheImageInputStream(is); + ir.setInput(iis); + meta = ir.getImageMetadata(0); + Node node = meta.getAsTree(format); + for (node = node.getFirstChild(); + !"iTXt".equals(node.getNodeName()); + node = node.getNextSibling()); + boolean verbatimSeen = false, compressedSeen = false; + for (node = node.getFirstChild(); + node != null; + node = node.getNextSibling()) { + entry = (Element)node; + String keyword = entry.getAttribute("keyword"); + String translatedKeyword = entry.getAttribute("translatedKeyword"); + String text = entry.getAttribute("text"); + if ("verbatim".equals(keyword)) { + if (verbatimSeen) throw new AssertionError("Duplicate"); + verbatimSeen = true; + if (!VERBATIM.equals(translatedKeyword)) + throw new AssertionError("Wrong translated keyword"); + if (!TEXT.equals(text)) + throw new AssertionError("Wrong text"); + } + else if ("compressed".equals(keyword)) { + if (compressedSeen) throw new AssertionError("Duplicate"); + compressedSeen = true; + if (!COMPRESSED.equals(translatedKeyword)) + throw new AssertionError("Wrong translated keyword"); + if (!TEXT.equals(text)) + throw new AssertionError("Wrong text"); + } + else { + throw new AssertionError("Unexpected keyword"); + } + } + if (!(verbatimSeen && compressedSeen)) + throw new AssertionError("Missing chunk"); + } + + private static final int findBytes(byte[] needle, byte[] haystack) { + HAYSTACK: for (int h = 0; h <= haystack.length - needle.length; ++h) { + for (int n = 0; n < needle.length; ++n) { + if (needle[n] != haystack[h + n]) { + continue HAYSTACK; + } + } + return h; + } + return -1; + } + +} diff --git a/test/javax/imageio/plugins/png/MergeStdCommentTest.java b/test/javax/imageio/plugins/png/MergeStdCommentTest.java new file mode 100644 index 0000000000000000000000000000000000000000..21a7c5f10d00ea5393e02ec47cf0d6b9a66f7ac7 --- /dev/null +++ b/test/javax/imageio/plugins/png/MergeStdCommentTest.java @@ -0,0 +1,64 @@ +/* + * Copyright 2008 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. + * + * 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. + */ + +/** + * @test + * @bug 5106550 + * @summary Merge a comment using the standard metdata format + * and only a minimal set of attributes + */ + +import java.awt.image.BufferedImage; +import javax.imageio.ImageIO; +import javax.imageio.ImageTypeSpecifier; +import javax.imageio.ImageWriter; +import javax.imageio.metadata.IIOMetadata; +import org.w3c.dom.DOMImplementation; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.bootstrap.DOMImplementationRegistry; + +public class MergeStdCommentTest { + + public static void main(String[] args) throws Exception { + String format = "javax_imageio_1.0"; + BufferedImage img = + new BufferedImage(16, 16, BufferedImage.TYPE_INT_RGB); + ImageWriter iw = ImageIO.getImageWritersByMIMEType("image/png").next(); + IIOMetadata meta = + iw.getDefaultImageMetadata(new ImageTypeSpecifier(img), null); + DOMImplementationRegistry registry; + registry = DOMImplementationRegistry.newInstance(); + DOMImplementation impl = registry.getDOMImplementation("XML 3.0"); + Document doc = impl.createDocument(null, format, null); + Element root, text, entry; + root = doc.getDocumentElement(); + root.appendChild(text = doc.createElement("Text")); + text.appendChild(entry = doc.createElement("TextEntry")); + // keyword isn't #REQUIRED by the standard metadata format. + // However, it is required by the PNG format, so we include it here. + entry.setAttribute("keyword", "Comment"); + entry.setAttribute("value", "Some demo comment"); + meta.mergeTree(format, root); + } +} diff --git a/test/javax/imageio/stream/StreamCloserLeak/run_test.sh b/test/javax/imageio/stream/StreamCloserLeak/run_test.sh new file mode 100644 index 0000000000000000000000000000000000000000..af3e428cb30a98664d4ad96f4a33998b8897d0dc --- /dev/null +++ b/test/javax/imageio/stream/StreamCloserLeak/run_test.sh @@ -0,0 +1,205 @@ +#!/bin/ksh -p +# +# 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. +# +# 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. +# + +# +# @test +# @bug 6788096 +# @summary Test simulates the case of multiple applets executed in +# the same VM and verifies that ImageIO shutdown hook +# StreamCloser does not cause a leak of classloaders. +# +# @build test.Main +# @build testapp.Main +# @run shell run_test.sh + +# There are several resources which need to be present before many +# shell scripts can run. Following are examples of how to check for +# many common ones. +# +# Note that the shell used is the Korn Shell, KSH +# +# Also note, it is recommended that make files NOT be used. Rather, +# put the individual commands directly into this file. That way, +# it is possible to use command line arguments and other shell tech- +# niques to find the compiler, etc on different systems. For example, +# a different path could be used depending on whether this were a +# Solaris or Win32 machine, which is more difficult (if even possible) +# in a make file. + + +# Beginning of subroutines: +status=1 + +#Call this from anywhere to fail the test with an error message +# usage: fail "reason why the test failed" +fail() + { echo "The test failed :-(" + echo "$*" 1>&2 + echo "exit status was $status" + exit $status + } #end of fail() + +#Call this from anywhere to pass the test with a message +# usage: pass "reason why the test passed if applicable" +pass() + { echo "The test passed!!!" + echo "$*" 1>&2 + exit 0 + } #end of pass() + +# end of subroutines + + +# The beginning of the script proper + +# Checking for proper OS +OS=`uname -s` +case "$OS" in + SunOS ) + VAR="One value for Sun" + DEFAULT_JDK=/usr/local/java/jdk1.2/solaris + FILESEP="/" + PATHSEP=":" + TMP="/tmp" + ;; + + Linux ) + VAR="A different value for Linux" + DEFAULT_JDK=/usr/local/java/jdk1.4/linux-i386 + FILESEP="/" + PATHSEP=":" + TMP="/tmp" + ;; + + Windows_95 | Windows_98 | Windows_NT | Windows_ME ) + VAR="A different value for Win32" + DEFAULT_JDK=/usr/local/java/jdk1.2/win32 + FILESEP="\\" + PATHSEP=";" + TMP=`cd "${SystemRoot}/Temp"; echo ${PWD}` + ;; + + # catch all other OSs + * ) + echo "Unrecognized system! $OS" + fail "Unrecognized system! $OS" + ;; +esac + +# Want this test to run standalone as well as in the harness, so do the +# following to copy the test's directory into the harness's scratch directory +# and set all appropriate variables: + +if [ -z "${TESTJAVA}" ] ; then + # TESTJAVA is not set, so the test is running stand-alone. + # TESTJAVA holds the path to the root directory of the build of the JDK + # to be tested. That is, any java files run explicitly in this shell + # should use TESTJAVA in the path to the java interpreter. + # So, we'll set this to the JDK spec'd on the command line. If none + # is given on the command line, tell the user that and use a cheesy + # default. + # THIS IS THE JDK BEING TESTED. + if [ -n "$1" ] ; + then TESTJAVA=$1 + else echo "no JDK specified on command line so using default!" + TESTJAVA=$DEFAULT_JDK + fi + TESTSRC=. + TESTCLASSES=. + STANDALONE=1; +fi +echo "JDK under test is: $TESTJAVA" + + +############### YOUR TEST CODE HERE!!!!!!! ############# + +#All files required for the test should be in the same directory with +# this file. If converting a standalone test to run with the harness, +# as long as all files are in the same directory and it returns 0 for +# pass, you should be able to cut and paste it into here and it will +# run with the test harness. + +# This is an example of running something -- test +# The stuff below catches the exit status of test then passes or fails +# this shell test as appropriate ( 0 status is considered a pass here ) + +echo "Create TestApp.jar..." + +if [ -f TestApp.jar ] ; then + rm -f TestApp.jar +fi + +${TESTJAVA}/bin/jar -cvf TestApp.jar -C ${TESTCLASSES} testapp + +if [ $? -ne "0" ] ; then + fail "Failed to create TestApp.jar" +fi + +echo "Create Test.jar..." +if [ -f Test.jar ] ; then + rm -f Test.jar +fi + +${TESTJAVA}/bin/jar -cvf Test.jar -C ${TESTCLASSES} test + +if [ $? -ne 0 ] ; then + fail "Failed to create Test.jar" +fi + +# Prepare temp dir for cahce files +mkdir ./tmp +if [ $? -ne 0 ] ; then + fail "Unable to create temp directory." +fi + +# Verify that all classoladers are destroyed +${TESTJAVA}/bin/java -cp Test.jar test.Main +if [ $? -ne 0 ] ; then + fail "Test FAILED: some classloaders weren't destroyed." +fi + + +# Verify that ImageIO shutdown hook works correcly +${TESTJAVA}/bin/java -cp Test.jar -DforgetSomeStreams=true test.Main +if [ $? -ne 0 ] ; then + fail "Test FAILED: some classloaders weren't destroyed of shutdown hook failed." +fi + +# sanity check: verify that all cache files were deleted +cache_files=`ls tmp` + +if [ "x${cache_files}" != "x" ] ; then + echo "WARNING: some cache files was not deleted: ${cache_files}" +fi + +echo "Test done." + +status=$? + +if [ $status -eq "0" ] ; then + pass "" +else + fail "Test failed due to test plugin was not found." +fi + diff --git a/test/javax/imageio/stream/StreamCloserLeak/test/Main.java b/test/javax/imageio/stream/StreamCloserLeak/test/Main.java new file mode 100644 index 0000000000000000000000000000000000000000..b87299967c69de94124b98dafff77f9fb3445b61 --- /dev/null +++ b/test/javax/imageio/stream/StreamCloserLeak/test/Main.java @@ -0,0 +1,284 @@ +/* + * 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. + * + * 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 test; + +import java.io.File; +import java.io.IOException; +import java.lang.ref.Reference; +import java.lang.ref.ReferenceQueue; +import java.lang.ref.WeakReference; +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.HashMap; +import java.util.Map.Entry; +import java.util.Set; +import java.util.WeakHashMap; +import java.util.concurrent.ConcurrentLinkedQueue; +import java.util.concurrent.CountDownLatch; +import javax.imageio.stream.ImageInputStream; +import sun.awt.AppContext; +import sun.awt.SunToolkit; + +public class Main { + + private static ThreadGroup appsThreadGroup; + + private static WeakHashMap<MyClassLoader, String> refs = + new WeakHashMap<MyClassLoader, String>(); + + /** Collection to simulate forgrotten streams **/ + private static HashMap<String, ImageInputStream> strongRefs = + new HashMap<String, ImageInputStream>(); + + private static ConcurrentLinkedQueue<Throwable> problems = + new ConcurrentLinkedQueue<Throwable>(); + + private static AppContext mainAppContext = null; + + private static CountDownLatch doneSignal; + + private static final int gcTimeout = + Integer.getInteger("gcTimeout", 10).intValue(); + + private static boolean forgetSomeStreams = + Boolean.getBoolean("forgetSomeStreams"); + + public static void main(String[] args) throws IOException { + mainAppContext = SunToolkit.createNewAppContext(); + System.out.println("Current context class loader: " + + Thread.currentThread().getContextClassLoader()); + + appsThreadGroup = new ThreadGroup("MyAppsThreadGroup"); + + File jar = new File("TestApp.jar"); + if (!jar.exists()) { + System.out.println(jar.getAbsolutePath() + " was not found!\n" + + "Please install the jar with test application correctly!"); + throw new RuntimeException("Test failed: no TestApp.jar"); + } + + URL[] urls = new URL[]{jar.toURL()}; + + int numApps = Integer.getInteger("numApps", 20).intValue(); + + doneSignal = new CountDownLatch(numApps); + int cnt = 0; + while (cnt++ < numApps) { + launch(urls, "testapp.Main", "launch"); + + checkErrors(); + } + + System.out.println("Wait for apps completion...."); + + try { + doneSignal.await(); + } catch (InterruptedException e) { + } + + System.out.println("All apps finished."); + + System.gc(); + + System.out.flush(); + + System.out.println("Enumerate strong refs:"); + for (String is : strongRefs.keySet()) { + System.out.println("-> " + is); + } + + System.out.println("======================="); + + // wait few seconds + waitAndGC(gcTimeout); + + doneSignal = new CountDownLatch(1); + + Runnable workaround = new Runnable() { + + public void run() { + AppContext ctx = null; + try { + ctx = SunToolkit.createNewAppContext(); + } catch (Throwable e) { + // ignore... + } finally { + doneSignal.countDown(); + } + } + }; + + Thread wt = new Thread(appsThreadGroup, workaround, "Workaround"); + wt.setContextClassLoader(new MyClassLoader(urls, "workaround")); + wt.start(); + wt = null; + workaround = null; + + System.out.println("Wait for workaround completion..."); + + try { + doneSignal.await(); + } catch (InterruptedException e) { + } + + // give a chance to GC + waitAndGC(gcTimeout); + + if (!refs.isEmpty()) { + System.out.println("Classloaders still alive:"); + + for (MyClassLoader l : refs.keySet()) { + String val = refs.get(l); + + if (val == null) { + throw new RuntimeException("Test FAILED: Invalid classloader name"); + } + System.out.println("->" + val + (strongRefs.get(val) != null ? + " (has strong ref)" : "")); + if (strongRefs.get(val) == null) { + throw new RuntimeException("Test FAILED: exta class loader is detected! "); + } + } + } else { + System.out.println("No alive class loaders!!"); + } + System.out.println("Test PASSED."); + } + + private static void waitAndGC(int sec) { + int cnt = sec; + System.out.print("Wait "); + while (cnt-- > 0) { + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + } + // do GC every 3 seconds + if (cnt % 3 == 2) { + System.gc(); + System.out.print("+"); + } else { + System.out.print("."); + } + checkErrors(); + } + System.out.println(""); + } + + private static void checkErrors() { + while (!problems.isEmpty()) { + Throwable theProblem = problems.poll(); + System.out.println("Test FAILED!"); + do { + theProblem.printStackTrace(System.out); + theProblem = theProblem.getCause(); + } while (theProblem != null); + throw new RuntimeException("Test FAILED"); + } + } + static int counter = 0; + + private static void launch(URL[] urls, final String className, + final String methodName) + { + final String uniqClassName = "testapp/Uniq" + counter; + final boolean saveStrongRef = forgetSomeStreams ? (counter % 5 == 4) : false; + + System.out.printf("%s: launch the app\n", uniqClassName); + Runnable launchIt = new Runnable() { + public void run() { + AppContext ctx = SunToolkit.createNewAppContext(); + + try { + Class appMain = + ctx.getContextClassLoader().loadClass(className); + Method launch = appMain.getDeclaredMethod(methodName, + strongRefs.getClass()); + + Constructor c = appMain.getConstructor(String.class, + problems.getClass()); + + Object o = c.newInstance(uniqClassName, problems); + + if (saveStrongRef) { + System.out.printf("%s: force strong ref\n", + uniqClassName); + launch.invoke(o, strongRefs); + } else { + HashMap<String, ImageInputStream> empty = null; + launch.invoke(o, empty); + } + + ctx = null; + } catch (Throwable e) { + problems.add(e); + } finally { + doneSignal.countDown(); + } + } + }; + + MyClassLoader appClassLoader = new MyClassLoader(urls, uniqClassName); + + refs.put(appClassLoader, uniqClassName); + + Thread appThread = new Thread(appsThreadGroup, launchIt, + "AppThread" + counter++); + appThread.setContextClassLoader(appClassLoader); + + appThread.start(); + launchIt = null; + appThread = null; + appClassLoader = null; + } + + private static class MyClassLoader extends URLClassLoader { + + private static boolean verbose = + Boolean.getBoolean("verboseClassLoading"); + private String uniqClassName; + + public MyClassLoader(URL[] urls, String uniq) { + super(urls); + + uniqClassName = uniq; + } + + public Class loadClass(String name) throws ClassNotFoundException { + if (verbose) { + System.out.printf("%s: load class %s\n", uniqClassName, name); + } + if (uniqClassName.equals(name)) { + return Object.class; + } + return super.loadClass(name); + } + + public String toString() { + return "MyClassLoader(" + uniqClassName + ")"; + } + } +} diff --git a/test/javax/imageio/stream/StreamCloserLeak/testapp/Main.java b/test/javax/imageio/stream/StreamCloserLeak/testapp/Main.java new file mode 100644 index 0000000000000000000000000000000000000000..3c4bb5ec3ff38dd735fa95da9ceec706e2587f8f --- /dev/null +++ b/test/javax/imageio/stream/StreamCloserLeak/testapp/Main.java @@ -0,0 +1,109 @@ +/* + * 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. + * + * 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 testapp; + +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.util.HashMap; +import java.util.concurrent.ConcurrentLinkedQueue; +import javax.imageio.stream.FileCacheImageInputStream; +import javax.imageio.stream.ImageInputStream; + +public class Main { + + public static void main(String[] args) { + Main o = new Main("testapp.some.class", null); + o.launch(null); + } + + private final String uniqClassName; + private final ConcurrentLinkedQueue<Throwable> problems; + + public Main(String uniq, ConcurrentLinkedQueue<Throwable> p) { + uniqClassName = uniq; + problems = p; + } + + public void launch(HashMap<String, ImageInputStream> refs) { + System.out.printf("%s: current context class loader: %s\n", + uniqClassName, + Thread.currentThread().getContextClassLoader()); + try { + byte[] data = new byte[1024]; + ByteArrayInputStream bais = new ByteArrayInputStream(data); + MyImageInputStream iis = new MyImageInputStream(bais, + uniqClassName, + problems); + if (refs != null) { + System.out.printf("%s: added to strong store\n", + uniqClassName); + refs.put(uniqClassName, iis); + } + iis.read(); + //leave stream open : let's shutdown hook work! + } catch (IOException e) { + problems.add(e); + } + } + + private static class MyImageInputStream extends FileCacheImageInputStream { + private final String uniqClassName; + private ConcurrentLinkedQueue<Throwable> problems; + public MyImageInputStream(InputStream is, String uniq, + ConcurrentLinkedQueue<Throwable> p) throws IOException + { + super(is, new File("tmp")); + uniqClassName = uniq; + problems = p; + } + + @Override + public void close() throws IOException { + Test t = new Test(); + try { + t.doTest(uniqClassName); + } catch (Throwable e) { + problems.add(e); + } + + super.close(); + + problems = null; + } + } +} + +class Test { + public void doTest(String uniqClassName) throws ClassNotFoundException { + System.out.printf("%s: Current thread: %s\n", uniqClassName, + Thread.currentThread()); + + ClassLoader thisCL = this.getClass().getClassLoader(); + Class uniq = thisCL.loadClass(uniqClassName); + + System.out.printf("%s: test is done!\n",uniqClassName); + } +} diff --git a/test/javax/script/Test3.java b/test/javax/script/Test3.java index 8aa876ba24a34840f9d91552eea61e6d72b2c1ea..66fa23af07a160552d65348fec914b1af5c197c1 100644 --- a/test/javax/script/Test3.java +++ b/test/javax/script/Test3.java @@ -4,7 +4,6 @@ * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT diff --git a/test/javax/swing/JFileChooser/6570445/bug6570445.java b/test/javax/swing/JFileChooser/6570445/bug6570445.java new file mode 100644 index 0000000000000000000000000000000000000000..f746edaee5468688b6fcef5028555c537ae7d28d --- /dev/null +++ b/test/javax/swing/JFileChooser/6570445/bug6570445.java @@ -0,0 +1,20 @@ +/* + * @test + * @bug 6570445 + * @summary Checks if Win32ShellFolder2's COM-using methods work under a security manager + * @author Leonid Popov + */ + +import javax.swing.filechooser.FileSystemView; + +public class bug6570445 { + public static void main(String[] args) { + System.setSecurityManager(new SecurityManager()); + + // The next line of code forces FileSystemView to request data from Win32ShellFolder2, + // what causes an exception if a security manager installed (see the bug 6570445 description) + FileSystemView.getFileSystemView().getRoots(); + + System.out.println("Passed."); + } +} diff --git a/test/javax/swing/JFileChooser/6738668/bug6738668.java b/test/javax/swing/JFileChooser/6738668/bug6738668.java new file mode 100644 index 0000000000000000000000000000000000000000..f54515e7e4ee93fbf584f03129cb3d5558fdcf24 --- /dev/null +++ b/test/javax/swing/JFileChooser/6738668/bug6738668.java @@ -0,0 +1,44 @@ +/* + * 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. + * + * 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. + */ + +/* @test + @bug 6738668 + @summary JFileChooser cannot be created under SecurityManager + @author Pavel Porvatov + @run main/othervm/policy=security.policy bug6738668 +*/ + +import javax.swing.*; +import java.io.File; + +public class bug6738668 { + public static void main(String[] args) throws Exception { + for (UIManager.LookAndFeelInfo lookAndFeelInfo : UIManager.getInstalledLookAndFeels()) { + UIManager.setLookAndFeel(lookAndFeelInfo.getClassName()); + + new JFileChooser(new File("c:/temp")); + + System.out.println("Test passed for LookAndFeel " + lookAndFeelInfo.getClassName()); + } + } +} diff --git a/test/javax/swing/JFileChooser/6738668/security.policy b/test/javax/swing/JFileChooser/6738668/security.policy new file mode 100644 index 0000000000000000000000000000000000000000..fd3aa757c563c174f93b047454feb446e9df360f --- /dev/null +++ b/test/javax/swing/JFileChooser/6738668/security.policy @@ -0,0 +1,5 @@ +grant { + permission java.io.FilePermission "C:\\temp\\*", "read"; + permission java.io.FilePermission "C:\\temp", "read"; + permission java.util.PropertyPermission "*", "read"; +}; diff --git a/test/javax/swing/JFileChooser/6798062/bug6798062.html b/test/javax/swing/JFileChooser/6798062/bug6798062.html new file mode 100644 index 0000000000000000000000000000000000000000..12955f6eee722d6892e1bdc337140d5c3e5746ee --- /dev/null +++ b/test/javax/swing/JFileChooser/6798062/bug6798062.html @@ -0,0 +1,11 @@ +<html> +<body> +<applet code="bug6798062.class" width=400 height=300></applet> +1. Create a link +2. Copy path to the link into TextField +3. Run the Windows Task Manager. Select the Processes tab and find the java process +4. Press the Start button in the test window +5. Wait several minutes and observe in the Windows Task Manager +that Memory Usage of java process is not increasing +</body> +</html> diff --git a/test/javax/swing/JFileChooser/6798062/bug6798062.java b/test/javax/swing/JFileChooser/6798062/bug6798062.java new file mode 100644 index 0000000000000000000000000000000000000000..ee4d333fc8508f5de5abd9128f07b354c3b87d9f --- /dev/null +++ b/test/javax/swing/JFileChooser/6798062/bug6798062.java @@ -0,0 +1,189 @@ +/* + * 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. + * + * 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. + */ + +/* @test %W% %E% + @bug 6798062 + @summary Memory Leak on using getFiles of FileSystemView + @author Pavel Porvatov + @run applet/manual=done bug6798062.html +*/ + +import sun.awt.shell.ShellFolder; + +import javax.swing.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.*; +import java.io.File; +import java.io.FileNotFoundException; + +public class bug6798062 extends JApplet { + + private final JSlider slider = new JSlider(0, 100); + + private final JTextField tfLink = new JTextField(); + + private final JButton btnStart = new JButton("Start"); + + private final JButton btnStop = new JButton("Stop"); + + private final JButton btnGC = new JButton("Run System.gc()"); + + private ShellFolder folder; + + private Thread thread; + + public static void main(String[] args) { + JFrame frame = new JFrame("bug6798062"); + + frame.setSize(400, 300); + frame.setLocationRelativeTo(null); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.add(new bug6798062().initialize()); + + frame.setVisible(true); + } + + public void init() { + add(initialize()); + } + + private JPanel initialize() { + File file = new File("c:/"); + + try { + folder = ShellFolder.getShellFolder(file); + } catch (FileNotFoundException e) { + fail("Directory " + file.getPath() + " not found"); + } + + slider.setMajorTickSpacing(10); + slider.setPaintTicks(true); + slider.setPaintLabels(true); + slider.setSnapToTicks(true); + slider.setValue(10); + + btnStart.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + setEnabledState(false); + + thread = new MyThread(slider.getValue(), tfLink.getText()); + thread.start(); + } + }); + + btnStop.setEnabled(false); + + btnStop.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + thread.interrupt(); + thread = null; + + setEnabledState(true); + } + }); + + btnGC.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + System.gc(); + } + }); + + setEnabledState(true); + + JPanel pnButtons = new JPanel(); + + pnButtons.setLayout(new BoxLayout(pnButtons, BoxLayout.X_AXIS)); + + pnButtons.add(btnStart); + pnButtons.add(btnStop); + pnButtons.add(btnGC); + + tfLink.setMaximumSize(new Dimension(300, 20)); + + JPanel pnContent = new JPanel(); + + pnContent.setLayout(new BoxLayout(pnContent, BoxLayout.Y_AXIS)); + pnContent.add(new JLabel("Delay between listFiles() invocation (ms):")); + pnContent.add(slider); + pnContent.add(new JLabel("Provide link here:")); + pnContent.add(tfLink); + pnContent.add(pnButtons); + + return pnContent; + } + + private void setEnabledState(boolean enabled) { + slider.setEnabled(enabled); + btnStart.setEnabled(enabled); + btnStop.setEnabled(!enabled); + } + + private static void fail(String msg) { + throw new RuntimeException(msg); + } + + private class MyThread extends Thread { + private final int delay; + + private final ShellFolder link; + + private MyThread(int delay, String link) { + this.delay = delay; + + ShellFolder linkFolder; + + try { + linkFolder = ShellFolder.getShellFolder(new File(link)); + } catch (FileNotFoundException e) { + e.printStackTrace(); + + linkFolder = null; + } + + this.link = linkFolder; + } + + public void run() { + while (!isInterrupted()) { + folder.listFiles(); + if (link != null) { + try { + link.getLinkLocation(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + } + + if (delay > 0) { + try { + Thread.sleep(delay); + } catch (InterruptedException e1) { + // The thread was interrupted + return; + } + } + } + } + } +} diff --git a/test/javax/swing/JSlider/6794831/bug6794831.java b/test/javax/swing/JSlider/6794831/bug6794831.java new file mode 100644 index 0000000000000000000000000000000000000000..a147987d417852fe8b719f612ff974b1cb0eb7f0 --- /dev/null +++ b/test/javax/swing/JSlider/6794831/bug6794831.java @@ -0,0 +1,105 @@ +/* + * 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. + * + * 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. + */ + +/* @test + * @bug 6794831 + * @summary Infinite loop while painting ticks on Slider with maximum=MAX_INT + * @author Pavel Porvatov + @run main bug6794831 + */ + +import javax.swing.*; +import javax.swing.plaf.basic.BasicSliderUI; +import java.awt.image.BufferedImage; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +public class bug6794831 { + private final CountDownLatch countDownLatch = new CountDownLatch(1); + + public static void main(String args[]) throws InterruptedException { + new bug6794831().run(); + } + + private void run() throws InterruptedException { + SwingUtilities.invokeLater(new Runnable() { + public void run() { + for (UIManager.LookAndFeelInfo lookAndFeelInfo : UIManager.getInstalledLookAndFeels()) { + try { + UIManager.setLookAndFeel(lookAndFeelInfo.getClassName()); + } catch (Exception e) { + fail(e.getMessage()); + } + + BufferedImage image = new BufferedImage(300, 200, BufferedImage.TYPE_INT_ARGB); + + // Test 1 + JSlider slider = new JSlider(0, Integer.MAX_VALUE - 1, 0); + + slider.setMajorTickSpacing((Integer.MAX_VALUE - 1) / 4); + slider.setPaintTicks(true); + + ((BasicSliderUI) slider.getUI()).paintTicks(image.getGraphics()); + + // Test 2 + slider = new JSlider(0, Integer.MAX_VALUE - 1, 0); + + slider.setMinorTickSpacing((Integer.MAX_VALUE - 1) / 4); + slider.setPaintTicks(true); + + ((BasicSliderUI) slider.getUI()).paintTicks(image.getGraphics()); + + // Test 3 + slider = new JSlider(0, Integer.MAX_VALUE - 1, 0); + + slider.setOrientation(JSlider.VERTICAL); + slider.setMajorTickSpacing((Integer.MAX_VALUE - 1) / 4); + slider.setPaintTicks(true); + + ((BasicSliderUI) slider.getUI()).paintTicks(image.getGraphics()); + + // Test 4 + slider = new JSlider(0, Integer.MAX_VALUE - 1, 0); + + slider.setOrientation(JSlider.VERTICAL); + slider.setMinorTickSpacing((Integer.MAX_VALUE - 1) / 4); + slider.setPaintTicks(true); + + ((BasicSliderUI) slider.getUI()).paintTicks(image.getGraphics()); + + countDownLatch.countDown(); + } + } + }); + + if (countDownLatch.await(3000, TimeUnit.MILLISECONDS)) { + System.out.println("bug6794831 passed"); + } else { + fail("bug6794831 failed"); + } + } + + private static void fail(String msg) { + throw new RuntimeException(msg); + } +} diff --git a/test/javax/swing/system/6799345/TestShutdown.java b/test/javax/swing/system/6799345/TestShutdown.java new file mode 100644 index 0000000000000000000000000000000000000000..694df3eac013d4065c2296553251ed218833afcb --- /dev/null +++ b/test/javax/swing/system/6799345/TestShutdown.java @@ -0,0 +1,203 @@ +/* + * 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. + * + * 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. + */ + +/* @test + @bug 6799345 + @summary Tests that no exceptions are thrown from TimerQueue and +SwingWorker on AppContext shutdown + @author art + @run main TestShutdown +*/ + +import java.awt.*; +import java.awt.event.*; + +import java.util.*; + +import javax.swing.*; + +import sun.awt.*; + +public class TestShutdown +{ + private static AppContext targetAppContext; + + private static JFrame f; + private static JTextField tf; + + private static volatile boolean exceptionsOccurred = false; + private static volatile boolean appcontextInitDone = false; + + private static int timerValue = 0; + + public static void main(String[] args) + throws Exception + { + ThreadGroup tg = new TestThreadGroup("TTG"); + Thread t = new Thread(tg, new TestRunnable(), "InitThread"); + t.start(); + + while (!appcontextInitDone) + { + Thread.sleep(500); + } + + targetAppContext.dispose(); + + if (exceptionsOccurred) + { + throw new RuntimeException("Test FAILED: some exceptions occurred"); + } + } + + static void initGUI() + { + f = new JFrame("F"); + f.setBounds(100, 100, 200, 100); + tf = new JTextField("Test"); + f.add(tf); + f.setVisible(true); + } + + static void startGUI() + { + // caret blink Timer + tf.requestFocusInWindow(); + + // misc Timer + ActionListener al = new ActionListener() + { + @Override + public void actionPerformed(ActionEvent ae) + { + System.out.println("Timer tick: " + timerValue++); + } + }; + new javax.swing.Timer(30, al).start(); + } + + static class TestThreadGroup extends ThreadGroup + { + public TestThreadGroup(String name) + { + super(name); + } + + @Override + public synchronized void uncaughtException(Thread thread, Throwable t) + { + if (t instanceof ThreadDeath) + { + // this one is expected, rethrow + throw (ThreadDeath)t; + } + System.err.println("Test FAILED: an exception is caught in the " + + "target thread group on thread " + thread.getName()); + t.printStackTrace(System.err); + exceptionsOccurred = true; + } + } + + static class TestRunnable implements Runnable + { + @Override + public void run() + { + SunToolkit stk = (SunToolkit)Toolkit.getDefaultToolkit(); + targetAppContext = stk.createNewAppContext(); + + // create and show frame and text field + SwingUtilities.invokeLater(new Runnable() + { + @Override + public void run() + { + initGUI(); + } + }); + stk.realSync(); + + // start some Timers + SwingUtilities.invokeLater(new Runnable() + { + @Override + public void run() + { + startGUI(); + } + }); + stk.realSync(); + + // start multiple SwingWorkers + while (!Thread.interrupted()) + { + try + { + new TestSwingWorker().execute(); + Thread.sleep(40); + } + catch (Exception e) + { + // exception here is expected, skip + break; + } + } + } + } + + static class TestSwingWorker extends SwingWorker<String, Integer> + { + @Override + public String doInBackground() + { + Random r = new Random(); + for (int i = 0; i < 10; i++) + { + try + { + int delay = r.nextInt() % 50; + Thread.sleep(delay); + publish(delay); + } + catch (Exception z) + { + break; + } + } + if (!appcontextInitDone) + { + appcontextInitDone = true; + } + return "Done"; + } + + @Override + public void process(java.util.List<Integer> chunks) + { + for (Integer i : chunks) + { + System.err.println("Processed: " + i); + } + } + } +} diff --git a/test/javax/swing/text/LayoutQueue/Test6588003.java b/test/javax/swing/text/LayoutQueue/Test6588003.java new file mode 100644 index 0000000000000000000000000000000000000000..d14d6a56a95e08ddec5c7591d4a99cfb50dafc84 --- /dev/null +++ b/test/javax/swing/text/LayoutQueue/Test6588003.java @@ -0,0 +1,59 @@ +/* + * Copyright 2007 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. + * + * 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. + */ + +/* @test + @bug 6588003 + @summary LayoutQueue should not share its DefaultQueue across AppContexts + @author Peter Zhelezniakov + @run main Test6588003 +*/ + +import javax.swing.text.LayoutQueue; +import sun.awt.SunToolkit; + +public class Test6588003 implements Runnable { + private static final LayoutQueue DEFAULT = new LayoutQueue(); + + public static void main(String[] args) throws InterruptedException { + LayoutQueue.setDefaultQueue(DEFAULT); + + ThreadGroup group = new ThreadGroup("Test6588003"); + Thread thread = new Thread(group, new Test6588003()); + thread.start(); + thread.join(); + + if (LayoutQueue.getDefaultQueue() != DEFAULT) { + throw new RuntimeException("Sharing detected"); + } + } + + public void run() { + SunToolkit.createNewAppContext(); + + if (LayoutQueue.getDefaultQueue() == DEFAULT) { + throw new RuntimeException("Sharing detected"); + } + + LayoutQueue.setDefaultQueue(new LayoutQueue()); + } +} diff --git a/test/javax/swing/text/html/Test4783068.java b/test/javax/swing/text/html/Test4783068.java new file mode 100644 index 0000000000000000000000000000000000000000..08859788e05596697442dc6971c83cbbae645516 --- /dev/null +++ b/test/javax/swing/text/html/Test4783068.java @@ -0,0 +1,93 @@ +/* + * Copyright 2007 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. + * + * 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. + */ + +/* @test + @bug 4783068 + @summary Disabled components should render grayed-out HTML + @author Peter Zhelezniakov + @run main Test4783068 +*/ + +import java.awt.*; +import java.awt.image.BufferedImage; +import javax.swing.*; +import javax.swing.plaf.metal.MetalLookAndFeel; + +public class Test4783068 { + final static Color TEST_COLOR = Color.WHITE; + + final static String html = "<html>" + + "This is a <font color='red'>colored</font> <b>text</b>" + + "<p>with a <a href='http://ru.sun.com'>link</a>" + + "<ul><li>an unordered<li>list</ul>" + + "<ol><li>and an ordered<li>list</ol>" + + "</html>"; + + + void test() { + try { + UIManager.setLookAndFeel(new MetalLookAndFeel()); + } catch (UnsupportedLookAndFeelException e) { + throw new Error("Cannot set Metal LAF"); + } + // Render text using background color + UIManager.put("textInactiveText", TEST_COLOR); + + test(new JLabel(html)); + test(new JButton(html)); + + JEditorPane pane = new JEditorPane("text/html", html); + pane.setDisabledTextColor(TEST_COLOR); + test(pane); + } + + void test(JComponent c) { + c.setEnabled(false); + c.setOpaque(true); + c.setBackground(TEST_COLOR); + c.setBorder(null); + Dimension size = c.getPreferredSize(); + c.setBounds(0, 0, size.width, size.height); + + BufferedImage image = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_ARGB); + c.paint(image.getGraphics()); + + int rgb = TEST_COLOR.getRGB(); + for (int i = 0; i < size.height; i++) { + for (int j = 0; j < size.width; j++) { + if (image.getRGB(j, i) != rgb) { + throw new RuntimeException( + String.format("Color mismatch at [%d, %d]", j, i)); + } + } + } + } + + public static void main(String[] args) throws Exception { + SwingUtilities.invokeAndWait(new Runnable() { + @Override public void run() { + new Test4783068().test(); + } + }); + } +} diff --git a/test/sun/awt/image/DrawByteBinary.java b/test/sun/awt/image/DrawByteBinary.java new file mode 100644 index 0000000000000000000000000000000000000000..e9db5c63f2336f7f99feee02c427827e0a3f51d0 --- /dev/null +++ b/test/sun/awt/image/DrawByteBinary.java @@ -0,0 +1,75 @@ +/* + * 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. + * + * 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. + */ + +/** + * @test + * @bug 6800846 + * + * @summary Test verifes that images with short palette are rendered + * withourt artifacts. + * + * @run main DrawByteBinary + */ + + +import java.awt.*; +import java.awt.color.*; +import java.awt.image.*; +import static java.awt.image.BufferedImage.*; + + +public class DrawByteBinary { + + public static void main(String args[]) { + int w = 100, h = 30; + int x = 10; + byte[] arr = {(byte)0xff, (byte)0x0, (byte)0x00}; + + IndexColorModel newCM = new IndexColorModel(1, 2, arr, arr, arr); + BufferedImage orig = new BufferedImage(w, h, TYPE_BYTE_BINARY, newCM); + Graphics2D g2d = orig.createGraphics(); + g2d.setColor(Color.white); + g2d.fillRect(0, 0, w, h); + g2d.setColor(Color.black); + g2d.drawLine(x, 0, x, h); + g2d.dispose(); + + IndexColorModel origCM = (IndexColorModel)orig.getColorModel(); + BufferedImage test = new BufferedImage(w, h, TYPE_BYTE_BINARY,origCM); + g2d = test.createGraphics(); + g2d.drawImage(orig, 0, 0, null); + g2d.dispose(); + + int y = h / 2; + + // we expect white color outside the line + if (test.getRGB(x - 1, y) != 0xffffffff) { + throw new RuntimeException("Invalid color outside the line."); + } + + // we expect black color on the line + if (test.getRGB(x, y) != 0xff000000) { + throw new RuntimeException("Invalid color on the line."); + } + } +} diff --git a/test/sun/java2d/cmm/ProfileOp/ReadWriteProfileTest.java b/test/sun/java2d/cmm/ProfileOp/ReadWriteProfileTest.java new file mode 100644 index 0000000000000000000000000000000000000000..dc54d94ab45b9ef021a7754513e29f520bfc824b --- /dev/null +++ b/test/sun/java2d/cmm/ProfileOp/ReadWriteProfileTest.java @@ -0,0 +1,120 @@ +/* + * Copyright 2007-2008 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. + * + * 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. + */ + +/** + * @test + * @bug 6476665 6523403 6733501 + * @summary Verifies reading and writing profiles and tags of the standard color + * spaces + * @run main ReadWriteProfileTest + */ +import java.awt.color.ColorSpace; +import java.awt.color.ICC_Profile; +import java.util.*; +import java.nio.*; +import java.util.Hashtable; + +public class ReadWriteProfileTest implements Runnable { + /* Location of the tag sig counter in 4-byte words */ + final static int TAG_COUNT_OFFSET = 32; + + /* Location of the tag sig table in 4-byte words */ + final static int TAG_ELEM_OFFSET = 33; + + static byte[][] profiles; + static int [][] tagSigs; + static Hashtable<Integer,byte[]> [] tags; + + static int [] cspaces = {ColorSpace.CS_sRGB, ColorSpace.CS_PYCC, + ColorSpace.CS_LINEAR_RGB, ColorSpace.CS_CIEXYZ, + ColorSpace.CS_GRAY}; + + static String [] csNames = {"sRGB", "PYCC", "LINEAR_RGB", "CIEXYZ", "GRAY"}; + + static void getProfileTags(byte [] data, Hashtable tags) { + ByteBuffer byteBuf = ByteBuffer.wrap(data); + IntBuffer intBuf = byteBuf.asIntBuffer(); + int tagCount = intBuf.get(TAG_COUNT_OFFSET); + intBuf.position(TAG_ELEM_OFFSET); + for (int i = 0; i < tagCount; i++) { + int tagSig = intBuf.get(); + int tagDataOff = intBuf.get(); + int tagSize = intBuf.get(); + + byte [] tagData = new byte[tagSize]; + byteBuf.position(tagDataOff); + byteBuf.get(tagData); + tags.put(tagSig, tagData); + } + } + + static { + profiles = new byte[cspaces.length][]; + tags = new Hashtable[cspaces.length]; + + for (int i = 0; i < cspaces.length; i++) { + ICC_Profile pf = ICC_Profile.getInstance(cspaces[i]); + profiles[i] = pf.getData(); + tags[i] = new Hashtable(); + getProfileTags(profiles[i], tags[i]); + } + } + + public void run() { + for (int i = 0; i < cspaces.length; i++) { + ICC_Profile pf = ICC_Profile.getInstance(cspaces[i]); + byte [] data = pf.getData(); + pf = ICC_Profile.getInstance(data); + if (!Arrays.equals(data, profiles[i])) { + System.err.println("Incorrect result of getData() " + "with " + + csNames[i] + " profile"); + throw new RuntimeException("Incorrect result of getData()"); + } + + for (int tagSig : tags[i].keySet()) { + byte [] tagData = pf.getData(tagSig); + byte [] empty = new byte[tagData.length]; + pf.setData(tagSig, empty); + pf.setData(tagSig, tagData); + + byte [] tagData1 = pf.getData(tagSig); + + if (!Arrays.equals(tagData1, tags[i].get(tagSig))) + { + System.err.println("Incorrect result of getData(int) with" + + " tag " + + Integer.toHexString(tagSig) + + " of " + csNames[i] + " profile"); + + throw new RuntimeException("Incorrect result of " + + "getData(int)"); + } + } + } + } + + public static void main(String [] args) { + ReadWriteProfileTest test = new ReadWriteProfileTest(); + test.run(); + } +} diff --git a/test/sun/net/sdp/ProbeIB.java b/test/sun/net/sdp/ProbeIB.java new file mode 100644 index 0000000000000000000000000000000000000000..ac2a4b72d74436cfb81f1db6e2e25f4e4fbbf322 --- /dev/null +++ b/test/sun/net/sdp/ProbeIB.java @@ -0,0 +1,59 @@ +/* + * 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. + * + * 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. + */ + +import java.io.File; +import java.io.IOException; +import java.net.NetworkInterface; +import java.net.InetAddress; +import java.util.Scanner; +import java.util.Enumeration; + +/** + * Probes for InfiniBand devices plumbed with IP addresses. + */ + +public class ProbeIB { + public static void main(String[] args) throws IOException { + Scanner s = new Scanner(new File("/etc/path_to_inst")); + try { + while (s.hasNextLine()) { + String line = s.nextLine(); + if (line.startsWith("#")) + continue; + String[] fields = line.split("\\s+"); + if (!fields[2].equals("\"ibd\"")) + continue; + String name = fields[2].substring(1, fields[2].length()-1) + fields[1]; + NetworkInterface ni = NetworkInterface.getByName(name); + if (ni != null) { + Enumeration<InetAddress> addrs = ni.getInetAddresses(); + while (addrs.hasMoreElements()) { + System.out.println(addrs.nextElement().getHostAddress()); + } + } + } + } finally { + s.close(); + } + } +} diff --git a/test/sun/net/sdp/Sanity.java b/test/sun/net/sdp/Sanity.java new file mode 100644 index 0000000000000000000000000000000000000000..2c8d55e00afa3fa54a11a292f59f332ec77f1e0f --- /dev/null +++ b/test/sun/net/sdp/Sanity.java @@ -0,0 +1,168 @@ +/* + * 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. + * + * 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. + */ + +import java.net.*; +import java.io.*; +import java.nio.channels.*; +import java.util.Enumeration; + +/** + * Sanity check Socket/ServerSocket and each of the stream-oriented channels + * on each IP address plumbed to the network adapters. + */ + +public class Sanity { + public static void main(String[] args) throws Exception { + Enumeration<NetworkInterface> nifs = NetworkInterface.getNetworkInterfaces(); + while (nifs.hasMoreElements()) { + NetworkInterface ni = nifs.nextElement(); + Enumeration<InetAddress> addrs = ni.getInetAddresses(); + while (addrs.hasMoreElements()) { + InetAddress addr = addrs.nextElement(); + test(addr); + } + } + } + + static void test(InetAddress addr) throws Exception { + System.out.println(addr.getHostAddress()); + + // ServerSocketChannel.bind + ServerSocketChannel ssc = ServerSocketChannel.open(); + try { + ssc.bind(new InetSocketAddress(addr, 0)); + int port = ((InetSocketAddress)(ssc.getLocalAddress())).getPort(); + + // SocketChannel.connect (implicit bind) + SocketChannel client = SocketChannel.open(); + try { + client.connect(new InetSocketAddress(addr, port)); + SocketChannel peer = ssc.accept(); + try { + testConnection(Channels.newOutputStream(client), + Channels.newInputStream(peer)); + } finally { + peer.close(); + } + } finally { + client.close(); + } + + // SocketChannel.connect (explicit bind) + client = SocketChannel.open(); + try { + client.bind(new InetSocketAddress(addr, 0)) + .connect(new InetSocketAddress(addr, port)); + ssc.accept().close(); + } finally { + client.close(); + } + } finally { + ssc.close(); + } + + // AsynchronousServerSocketChannel.bind + AsynchronousServerSocketChannel server = + AsynchronousServerSocketChannel.open(); + try { + server.bind(new InetSocketAddress(addr, 0)); + int port = ((InetSocketAddress)(server.getLocalAddress())).getPort(); + + // AsynchronousSocketChannel.connect (implicit bind) + AsynchronousSocketChannel client = AsynchronousSocketChannel.open(); + try { + client.connect(new InetSocketAddress(addr, port)).get(); + AsynchronousSocketChannel peer = server.accept().get(); + try { + testConnection(Channels.newOutputStream(client), + Channels.newInputStream(peer)); + } finally { + peer.close(); + } + } finally { + client.close(); + } + + // AsynchronousSocketChannel.connect (explicit bind) + client = AsynchronousSocketChannel.open(); + try { + client.bind(new InetSocketAddress(addr, 0)) + .connect(new InetSocketAddress(addr, port)).get(); + server.accept().get().close(); + } finally { + client.close(); + } + } finally { + server.close(); + } + + // ServerSocket.bind + ServerSocket ss = new ServerSocket(); + try { + ss.bind(new InetSocketAddress(addr, 0)); + int port = ss.getLocalPort(); + + // Socket.connect (implicit bind) + Socket s = new Socket(); + try { + s.connect(new InetSocketAddress(addr, port)); + Socket peer = ss.accept(); + try { + testConnection(s.getOutputStream(), peer.getInputStream()); + } finally { + peer.close(); + } + } finally { + s.close(); + } + + // Socket.connect (explicit bind) + s = new Socket(); + try { + s.bind(new InetSocketAddress(addr, 0)); + s.connect(new InetSocketAddress(addr, port)); + ss.accept().close(); + } finally { + s.close(); + } + } finally { + ss.close(); + } + } + + static void testConnection(OutputStream out, InputStream in) + throws IOException + { + byte[] msg = "hello".getBytes(); + out.write(msg); + + byte[] ba = new byte[100]; + int nread = 0; + while (nread < msg.length) { + int n = in.read(ba); + if (n < 0) + throw new IOException("EOF not expected!"); + nread += n; + } + } +} diff --git a/test/sun/net/sdp/sanity.sh b/test/sun/net/sdp/sanity.sh new file mode 100644 index 0000000000000000000000000000000000000000..baca9feccef476f71f2aa6fe6c59c7d72c3607ce --- /dev/null +++ b/test/sun/net/sdp/sanity.sh @@ -0,0 +1,72 @@ +# +# 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. +# +# 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. +# + +# @test +# @bug 4890703 +# @summary Unit test for Solaris SDP support +# @build ProbeIB Sanity +# @run shell sanity.sh + +# Check we are on Solaris and that SDP is enabled +OS=`uname -s` +if [ "$OS" != "SunOS" ]; then + echo "This is a Solaris-only test" + exit 0 +fi +SDPADM=/usr/sbin/sdpadm +if [ ! -f ${SDPADM} ]; then + echo "SDP not available" + exit 0 +fi +${SDPADM} status|grep Enabled +if [ $? != 0 ]; then + echo "SDP not enabled" + exit 0 +fi + +if [ -z "$TESTJAVA" ]; then + JAVA=java + TESTCLASSES=. + TESTSRC=. +else + JAVA="${TESTJAVA}/bin/java" +fi + +CLASSPATH=${TESTCLASSES}:${TESTSRC} +export CLASSPATH + +# Probe for IP addresses plumbed to IB interfaces +$JAVA -Djava.net.preferIPv4Stack=true ProbeIB > ib_addrs + +# Create sdp.conf +SDPCONF=sdp.conf +rm ${SDPCONF} +touch ${SDPCONF} +cat ib_addrs | while read ADDR +do + echo "bind ${ADDR} *" > ${SDPCONF} + echo "connect ${ADDR} *" >> ${SDPCONF} +done + +# Sanity check +$JAVA -Djava.net.preferIPv4Stack=true -Dcom.sun.sdp.conf=${SDPCONF} -Dcom.sun.sdp.debug Sanity diff --git a/test/sun/nio/cs/FindEncoderBugs.java b/test/sun/nio/cs/FindEncoderBugs.java index 0f4c406d453e7793d8b3e9c528606f4d5e116f9f..54bc5b268a0da580640e9b66985f9c6a2b211337 100644 --- a/test/sun/nio/cs/FindEncoderBugs.java +++ b/test/sun/nio/cs/FindEncoderBugs.java @@ -526,4 +526,3 @@ public class FindEncoderBugs { System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed); if (failed > 0) throw new AssertionError("Some tests failed");} } - diff --git a/test/sun/nio/cs/StrCodingBenchmark.java b/test/sun/nio/cs/StrCodingBenchmark.java new file mode 100644 index 0000000000000000000000000000000000000000..73256eb2b43434577f9788634cb2133e3b2c5a75 --- /dev/null +++ b/test/sun/nio/cs/StrCodingBenchmark.java @@ -0,0 +1,200 @@ +/* + * Copyright (c) 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. + * + * 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. + */ + +import java.util.*; +import java.nio.*; +import java.nio.charset.*; +import java.util.concurrent.*; +import java.util.regex.Pattern; + +/** + * Usage: java StringCodingBenchmark + * [-Diterations=N] [-Dsize=N] [-Dsubsize=N] [-Dmaxchar=N] + * [-Dfilter=REGEXP] [-DSecurityManager=true] + */ +public class StrCodingBenchmark { + abstract static class Job { + private final String name; + public Job(String name) { this.name = name; } + public String name() { return name; } + public abstract void work() throws Throwable; + } + + private static void collectAllGarbage() { + final java.util.concurrent.CountDownLatch drained + = new java.util.concurrent.CountDownLatch(1); + try { + System.gc(); // enqueue finalizable objects + new Object() { protected void finalize() { + drained.countDown(); }}; + System.gc(); // enqueue detector + drained.await(); // wait for finalizer queue to drain + System.gc(); // cleanup finalized objects + } catch (InterruptedException e) { throw new Error(e); } + } + + /** + * Runs each job for long enough that all the runtime compilers + * have had plenty of time to warm up, i.e. get around to + * compiling everything worth compiling. + * Returns array of average times per job per run. + */ + public static long[] time0(Job ... jobs) throws Throwable { + //final long warmupNanos = 10L * 1000L * 1000L * 1000L; + final long warmupNanos = 100L * 100L; + long[] nanoss = new long[jobs.length]; + for (int i = 0; i < jobs.length; i++) { + collectAllGarbage(); + long t0 = System.nanoTime(); + long t; + int j = 0; + do { jobs[i].work(); j++; } + while ((t = System.nanoTime() - t0) < warmupNanos); + nanoss[i] = t/j; + } + return nanoss; + } + + public static void time(Job ... jobs) throws Throwable { + + long[] warmup = time0(jobs); // Warm up run + long[] nanoss = time0(jobs); // Real timing run + long[] milliss = new long[jobs.length]; + double[] ratios = new double[jobs.length]; + + final String nameHeader = "Method"; + final String millisHeader = "Millis"; + final String ratioHeader = "Ratio"; + + int nameWidth = nameHeader.length(); + int millisWidth = millisHeader.length(); + int ratioWidth = ratioHeader.length(); + + for (int i = 0; i < jobs.length; i++) { + nameWidth = Math.max(nameWidth, jobs[i].name().length()); + + milliss[i] = nanoss[i]/(1000L * 1000L); + millisWidth = Math.max(millisWidth, + String.format("%d", milliss[i]).length()); + + ratios[i] = (double) nanoss[i] / (double) nanoss[0]; + ratioWidth = Math.max(ratioWidth, + String.format("%.3f", ratios[i]).length()); + } + String format = String.format("%%-%ds %%%dd %n", + nameWidth, millisWidth); + String headerFormat = String.format("%%-%ds %%%ds%n", + nameWidth, millisWidth); + System.out.printf(headerFormat, "Method", "Millis"); + + // Print out absolute and relative times, calibrated against first job + for (int i = 0; i < jobs.length; i++) + System.out.printf(format, jobs[i].name(), milliss[i], ratios[i]); + } + + public static Job[] filter(Pattern filter, Job[] jobs) { + if (filter == null) return jobs; + Job[] newJobs = new Job[jobs.length]; + int n = 0; + for (Job job : jobs) + if (filter.matcher(job.name()).find()) + newJobs[n++] = job; + // Arrays.copyOf not available in JDK 5 + Job[] ret = new Job[n]; + System.arraycopy(newJobs, 0, ret, 0, n); + return ret; + } + + static class PermissiveSecurityManger extends SecurityManager { + @Override public void checkPermission(java.security.Permission p) { + } + } + + public static void main(String[] args) throws Throwable { + final int itrs = Integer.getInteger("iterations", 100000); + final int size = Integer.getInteger("size", 2048); + final int subsize = Integer.getInteger("subsize", 128); + final int maxchar = Integer.getInteger("maxchar", 128); + final String regex = System.getProperty("filter"); + final Pattern filter = (regex == null) ? null : Pattern.compile(regex); + final boolean useSecurityManager = Boolean.getBoolean("SecurityManager"); + if (useSecurityManager) + System.setSecurityManager(new PermissiveSecurityManger()); + final Random rnd = new Random(); + + for (Charset charset: Charset.availableCharsets().values()) { + if (!("ISO-8859-1".equals(charset.name()) || + "US-ASCII".equals(charset.name()) || + charset.newDecoder() instanceof sun.nio.cs.SingleByte.Decoder)) + continue; + final String csn = charset.name(); + final Charset cs = charset; + final StringBuilder sb = new StringBuilder(); + { + final CharsetEncoder enc = cs.newEncoder(); + for (int i = 0; i < size; ) { + char c = (char) rnd.nextInt(maxchar); + if (enc.canEncode(c)) { + sb.append(c); + i++; + } + } + } + final String string = sb.toString(); + final byte[] bytes = string.getBytes(cs); + + System.out.printf("%n--------%s---------%n", csn); + for (int sz = 4; sz <= 2048; sz *= 2) { + System.out.printf(" [len=%d]%n", sz); + final byte[] bs = Arrays.copyOf(bytes, sz); + final String str = new String(bs, csn); + Job[] jobs = { + new Job("String decode: csn") { + public void work() throws Throwable { + for (int i = 0; i < itrs; i++) + new String(bs, csn); + }}, + + new Job("String decode: cs") { + public void work() throws Throwable { + for (int i = 0; i < itrs; i++) + new String(bs, cs); + }}, + + new Job("String encode: csn") { + public void work() throws Throwable { + for (int i = 0; i < itrs; i++) + str.getBytes(csn); + }}, + + new Job("String encode: cs") { + public void work() throws Throwable { + for (int i = 0; i < itrs; i++) + str.getBytes(cs); + }}, + }; + time(filter(filter, jobs)); + } + } + } +} diff --git a/test/sun/nio/cs/TestStringCoding.java b/test/sun/nio/cs/TestStringCoding.java new file mode 100644 index 0000000000000000000000000000000000000000..8d0c8f94f240aeeb66a331794769555c825a24cf --- /dev/null +++ b/test/sun/nio/cs/TestStringCoding.java @@ -0,0 +1,151 @@ +/* + * Copyright 2000-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. + */ + +/* @test + @bug 6636323 6636319 + @summary Test if StringCoding and NIO result have the same de/encoding result + * @run main/timeout=2000 TestStringCoding + */ + +import java.util.*; +import java.nio.*; +import java.nio.charset.*; + +public class TestStringCoding { + public static void main(String[] args) throws Throwable { + + for (Boolean hasSM: new boolean[] { false, true }) { + if (hasSM) + System.setSecurityManager(new PermissiveSecurityManger()); + for (Charset cs: Charset.availableCharsets().values()) { + if ("ISO-2022-CN".equals(cs.name()) || + "x-COMPOUND_TEXT".equals(cs.name()) || + "x-JISAutoDetect".equals(cs.name())) + continue; + System.out.printf("Testing(sm=%b) " + cs.name() + "....", hasSM); + // full bmp first + char[] bmpCA = new char[0x10000]; + for (int i = 0; i < 0x10000; i++) { + bmpCA[i] = (char)i; + } + byte[] sbBA = new byte[0x100]; + for (int i = 0; i < 0x100; i++) { + sbBA[i] = (byte)i; + } + test(cs, bmpCA, sbBA); + // "randomed" sizes + Random rnd = new Random(); + for (int i = 0; i < 10; i++) { + int clen = rnd.nextInt(0x10000); + int blen = rnd.nextInt(0x100); + //System.out.printf(" blen=%d, clen=%d%n", blen, clen); + test(cs, Arrays.copyOf(bmpCA, clen), Arrays.copyOf(sbBA, blen)); + //add a pair of surrogates + int pos = clen / 2; + if ((pos + 1) < blen) { + bmpCA[pos] = '\uD800'; + bmpCA[pos+1] = '\uDC00'; + } + test(cs, Arrays.copyOf(bmpCA, clen), Arrays.copyOf(sbBA, blen)); + } + System.out.println("done!"); + } + } + } + + static void test(Charset cs, char[] bmpCA, byte[] sbBA) throws Throwable { + String bmpStr = new String(bmpCA); + CharsetDecoder dec = cs.newDecoder() + .onMalformedInput(CodingErrorAction.REPLACE) + .onUnmappableCharacter(CodingErrorAction.REPLACE); + CharsetEncoder enc = cs.newEncoder() + .onMalformedInput(CodingErrorAction.REPLACE) + .onUnmappableCharacter(CodingErrorAction.REPLACE); + + //getBytes(csn); + byte[] baSC = bmpStr.getBytes(cs.name()); + ByteBuffer bf = enc.reset().encode(CharBuffer.wrap(bmpCA)); + byte[] baNIO = new byte[bf.limit()]; + bf.get(baNIO, 0, baNIO.length); + if (!Arrays.equals(baSC, baNIO)) + throw new RuntimeException("getBytes(csn) failed -> " + cs.name()); + + //getBytes(cs); + baSC = bmpStr.getBytes(cs); + if (!Arrays.equals(baSC, baNIO)) + throw new RuntimeException("getBytes(cs) failed -> " + cs.name()); + + //new String(csn); + String strSC = new String(sbBA, cs.name()); + String strNIO = dec.reset().decode(ByteBuffer.wrap(sbBA)).toString(); + if(!strNIO.equals(strSC)) + throw new RuntimeException("new String(csn) failed -> " + cs.name()); + + //new String(cs); + strSC = new String(sbBA, cs); + if (!strNIO.equals(strSC)) + throw new RuntimeException("new String(cs) failed -> " + cs.name()); + + //encode unmappable surrogates + if (enc instanceof sun.nio.cs.ArrayEncoder && + cs.contains(Charset.forName("ASCII"))) { + enc.replaceWith(new byte[] { (byte)'A'}); + sun.nio.cs.ArrayEncoder cae = (sun.nio.cs.ArrayEncoder)enc; + + String str = "ab\uD800\uDC00\uD800\uDC00cd"; + byte[] ba = new byte[str.length() - 2]; + int n = cae.encode(str.toCharArray(), 0, str.length(), ba); + if (n != 6 || !"abAAcd".equals(new String(ba, cs.name()))) + throw new RuntimeException("encode1(surrogates) failed -> " + + cs.name()); + + ba = new byte[str.length()]; + n = cae.encode(str.toCharArray(), 0, str.length(), ba); + if (n != 6 || !"abAAcd".equals(new String(ba, 0, n, + cs.name()))) + throw new RuntimeException("encode2(surrogates) failed -> " + + cs.name()); + str = "ab\uD800B\uDC00Bcd"; + ba = new byte[str.length()]; + n = cae.encode(str.toCharArray(), 0, str.length(), ba); + if (n != 8 || !"abABABcd".equals(new String(ba, 0, n, + cs.name()))) + throw new RuntimeException("encode3(surrogates) failed -> " + + cs.name()); + + ba = new byte[str.length() - 1]; + n = cae.encode(str.toCharArray(), 0, str.length(), ba); + if (n != 7 || !"abABABc".equals(new String(ba, 0, n, + cs.name()))) + throw new RuntimeException("encode4(surrogates) failed -> " + + cs.name()); + } + + } + + static class PermissiveSecurityManger extends SecurityManager { + @Override public void checkPermission(java.security.Permission p) {} + } +} diff --git a/test/sun/pisces/DashStrokeTest.java b/test/sun/pisces/DashStrokeTest.java new file mode 100644 index 0000000000000000000000000000000000000000..f77acbeacfe95be2e0ace30c9814205d60fe3000 --- /dev/null +++ b/test/sun/pisces/DashStrokeTest.java @@ -0,0 +1,86 @@ +/* + * 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. + * + * 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. + */ + +/* @test + * @summary verify that first element is a dash + * @bug 6793344 + */ + +import java.awt.*; +import java.awt.image.*; + +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.SwingUtilities; +import javax.swing.WindowConstants; + +public class DashStrokeTest extends Component { + + static BufferedImage bi; + static boolean printed = false; + + public Dimension getPreferredSize() { + return new Dimension(200,200); + } + + public static void drawGui() { + bi = new BufferedImage(200, 20, BufferedImage.TYPE_INT_RGB); + Graphics2D g2d = bi.createGraphics(); + BasicStroke dashStroke = new BasicStroke(1.0f, BasicStroke.CAP_ROUND, + BasicStroke.JOIN_ROUND, 1.0f, new float[] { 0.0f, 200 }, + 1.0f); + + g2d.setStroke(dashStroke); + g2d.setColor(Color.RED); + g2d.drawLine(5,10, 100,10); + printed =true; + } + + public static void main(String[] args) { + try { + SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + drawGui(); + } + + }); + } catch (Exception e) { + } + + if (printed) { + checkBI(bi, Color.RED); + } + } + + static void checkBI(BufferedImage bi, Color badColor) { + int badrgb = badColor.getRGB(); + + int col = bi.getRGB(6, 9); + if (col == badrgb) { + throw new RuntimeException("A pixel was turned on. "); + } + } +} + diff --git a/test/sun/pisces/JoinMiterTest.java b/test/sun/pisces/JoinMiterTest.java new file mode 100644 index 0000000000000000000000000000000000000000..567526b66e91543baeda4ce394a352ca139b69ac --- /dev/null +++ b/test/sun/pisces/JoinMiterTest.java @@ -0,0 +1,48 @@ +/* + * 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. + * + * 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. + */ + +/* @test + * @summary Pass if no RuntimeException. + * @bug 6812600 + */ +import java.awt.*; +import java.awt.image.BufferedImage; + +public class JoinMiterTest { + + public static void main(String[] args) throws Exception { + BufferedImage image = new BufferedImage(200, 200, +BufferedImage.TYPE_INT_RGB); + Graphics2D g = image.createGraphics(); + g.setPaint(Color.WHITE); + g.fill(new Rectangle(image.getWidth(), image.getHeight())); + g.translate(25, 100); + g.setPaint(Color.BLACK); + g.setStroke(new BasicStroke(20, BasicStroke.CAP_BUTT, + BasicStroke.JOIN_MITER)); + g.draw(new Polygon(new int[] {0, 150, 0}, new int[] {75, 0, -75}, 3)); + if (image.getRGB(16, 10) == Color.WHITE.getRGB()) { + throw new RuntimeException("Miter is not rendered."); + } + } +} diff --git a/test/sun/security/krb5/ParseCAPaths.java b/test/sun/security/krb5/ParseCAPaths.java new file mode 100644 index 0000000000000000000000000000000000000000..9f6772d4fca4e90b3ac8ec8690ec6d577f7c844f --- /dev/null +++ b/test/sun/security/krb5/ParseCAPaths.java @@ -0,0 +1,98 @@ +/* + * 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. + * + * 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. + */ +/* + * @test + * @bug 6789935 + * @summary cross-realm capath search error + */ + +import java.util.Arrays; +import sun.security.krb5.Realm; + +public class ParseCAPaths { + static boolean failed = false; + public static void main(String[] args) throws Exception { + System.setProperty("java.security.krb5.conf", System.getProperty("test.src", ".") +"/krb5-capaths.conf"); + //System.setProperty("sun.security.krb5.debug", "true"); + + // Standard example + check("ANL.GOV", "TEST.ANL.GOV", "ANL.GOV"); + check("ANL.GOV", "ES.NET", "ANL.GOV"); + check("ANL.GOV", "PNL.GOV", "ANL.GOV", "ES.NET"); + check("ANL.GOV", "NERSC.GOV", "ANL.GOV", "ES.NET"); + // Hierachical + check("N1.N.COM", "N2.N.COM", "N1.N.COM", "N.COM"); // 2 common + check("N1.N.COM", "N2.N3.COM", "N1.N.COM", "N.COM", // 1 common + "COM", "N3.COM"); + check("N1.COM", "N2.COM", "N1.COM", "COM"); // 1 common + check("N1", "N2", "N1"); // 0 common + // Extra garbages + check("A1.COM", "A4.COM", "A1.COM", "A2.COM"); + check("B1.COM", "B3.COM", "B1.COM", "B2.COM"); + // Missing is "." + check("C1.COM", "C3.COM", "C1.COM", "C2.COM"); + // Multiple path + check("D1.COM", "D4.COM", "D1.COM", "D2.COM"); + check("E1.COM", "E4.COM", "E1.COM", "E2.COM"); + check("F1.COM", "F4.COM", "F1.COM", "F9.COM"); + // Infinite loop + check("G1.COM", "G3.COM", "G1.COM", "COM"); + check("H1.COM", "H3.COM", "H1.COM"); + check("I1.COM", "I4.COM", "I1.COM", "I5.COM"); + + if (failed) { + throw new Exception("Failed somewhere."); + } + } + + static void check(String from, String to, String... paths) { + try { + check2(from, to, paths); + } catch (Exception e) { + failed = true; + e.printStackTrace(); + } + } + static void check2(String from, String to, String... paths) + throws Exception { + System.out.println(from + " -> " + to); + System.out.println(" expected: " + Arrays.toString(paths)); + String[] result = Realm.getRealmsList(from, to); + System.out.println(" result: " + Arrays.toString(result)); + if (result == null) { + if (paths.length == 0) { + // OK + } else { + throw new Exception("Shouldn't have a valid path."); + } + } else if(result.length != paths.length) { + throw new Exception("Length of path not correct"); + } else { + for (int i=0; i<result.length; i++) { + if (!result[i].equals(paths[i])) { + throw new Exception("Path not same"); + } + } + } + } +} diff --git a/test/sun/security/krb5/auto/SpnegoReqFlags.java b/test/sun/security/krb5/auto/SpnegoReqFlags.java new file mode 100644 index 0000000000000000000000000000000000000000..a94a2b5d1ac8dcb7ef83241a813504461f74d3a7 --- /dev/null +++ b/test/sun/security/krb5/auto/SpnegoReqFlags.java @@ -0,0 +1,92 @@ +/* + * 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. + * + * 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. + */ + +/* + * @test + * @bug 6815182 + * @summary GSSAPI/SPNEGO does not work with server using MIT Kerberos library + */ + +import sun.security.jgss.GSSUtil; +import sun.security.util.BitArray; +import sun.security.util.DerInputStream; +import sun.security.util.DerValue; + +public class SpnegoReqFlags { + + public static void main(String[] args) + throws Exception { + + // Create and start the KDC + new OneKDC(null).writeJAASConf(); + new SpnegoReqFlags().go(); + } + + void go() throws Exception { + Context c = Context.fromJAAS("client"); + c.startAsClient(OneKDC.SERVER, GSSUtil.GSS_SPNEGO_MECH_OID); + + byte[] token = c.doAs(new Action() { + @Override + public byte[] run(Context me, byte[] input) throws Exception { + me.x().requestCredDeleg(true); + me.x().requestReplayDet(false); + me.x().requestSequenceDet(false); + return me.x().initSecContext(new byte[0], 0, 0); + } + }, null); + + DerValue d = new DerValue(token); // GSSToken + DerInputStream ins = d.data; // OID + mech token + d.data.getDerValue(); // skip OID + d = d.data.getDerValue(); // NegTokenInit + d = d.data.getDerValue(); // The SEQUENCE inside + + boolean found = false; + + // Go through all fields inside NegTokenInit. The reqFlags field + // is optional. It's even not recommended in RFC 4178. + while (d.data.available() > 0) { + DerValue d2 = d.data.getDerValue(); + if (d2.isContextSpecific((byte)1)) { + found = true; + System.out.println("regFlags field located."); + BitArray ba = d2.data.getUnalignedBitString(); + if (ba.length() != 7) { + throw new Exception("reqFlags should contain 7 bits"); + } + if (!ba.get(0)) { + throw new Exception("delegFlag should be true"); + } + if (ba.get(2) || ba.get(3)) { + throw new Exception("replay/sequenceFlag should be false"); + } + } + } + + if (!found) { + System.out.println("Warning: regFlags field not found, too new?"); + } + c.dispose(); + } +} diff --git a/test/sun/security/krb5/krb5-capaths.conf b/test/sun/security/krb5/krb5-capaths.conf new file mode 100644 index 0000000000000000000000000000000000000000..db672820b7d84841ae07dc188c3766d1ed115800 --- /dev/null +++ b/test/sun/security/krb5/krb5-capaths.conf @@ -0,0 +1,87 @@ +[capaths] + +# Standard + +ANL.GOV = { + TEST.ANL.GOV = . + PNL.GOV = ES.NET + NERSC.GOV = ES.NET + ES.NET = . +} +TEST.ANL.GOV = { + ANL.GOV = . +} +PNL.GOV = { + ANL.GOV = ES.NET +} +NERSC.GOV = { + ANL.GOV = ES.NET +} +ES.NET = { + ANL.GOV = . +} + +# Extra garbages + +A1.COM = { + A2.COM = . + A4.COM = A2.COM + A3.COM = A4.COM + A3.COM = A2.COM +} + +B1.COM = { + B2.COM = . + B3.COM = B2.COM + B3.COM = B4.COM +} + +# Missing is "." + +C1.COM = { + C3.COM = C2.COM +} + +# Multiple paths + +D1.COM = { + D2.COM = . + D3.COM = . + D4.COM = D2.COM + D4.COM = D3.COM +} + +E1.COM = { + E2.COM = . + E3.COM = . + E4.COM = E2.COM E3.COM E2.COM +} + +# Shortest or First? + +F1.COM = { + F2.COM = . + F3.COM = F2.COM + F4.COM = F9.COM + F4.COM = F3.COM + F4.COM = F2.COM +} + +# Infinite loop + +G1.COM = { + G2.COM = G3.COM + G3.COM = G2.COM +} + +H1.COM = { + H2.COM = H3.COM + H3.COM = H2.COM + H3.COM = . +} + +I1.COM = { + I2.COM = I3.COM + I3.COM = I2.COM + I4.COM = I2.COM I5.COM +} diff --git a/test/sun/security/ssl/com/sun/net/ssl/internal/ssl/AppInputStream/ReadZeroBytes.java b/test/sun/security/ssl/com/sun/net/ssl/internal/ssl/AppInputStream/ReadZeroBytes.java new file mode 100644 index 0000000000000000000000000000000000000000..56134e0e773a8d1e36b61caebba79833e213cef7 --- /dev/null +++ b/test/sun/security/ssl/com/sun/net/ssl/internal/ssl/AppInputStream/ReadZeroBytes.java @@ -0,0 +1,254 @@ +/* + * 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. + * + * 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. + */ + +/* + * @test + * @bug 6697270 + * @summary Inputstream dosent behave correct + */ + +import java.io.*; +import java.net.*; +import javax.net.ssl.*; + +public class ReadZeroBytes { + + /* + * ============================================================= + * Set the various variables needed for the tests, then + * specify what tests to run on each side. + */ + + /* + * Should we run the client or server in a separate thread? + * Both sides can throw exceptions, but do you have a preference + * as to which side should be the main thread. + */ + static boolean separateServerThread = false; + + /* + * Where do we find the keystores? + */ + static String pathToStores = "../../../../../../../etc"; + static String keyStoreFile = "keystore"; + static String trustStoreFile = "truststore"; + static String passwd = "passphrase"; + + /* + * Is the server ready to serve? + */ + volatile static boolean serverReady = false; + + /* + * Turn on SSL debugging? + */ + static boolean debug = false; + + /* + * Define the server side of the test. + */ + void doServerSide() throws Exception { + SSLServerSocketFactory sslssf = + (SSLServerSocketFactory) SSLServerSocketFactory.getDefault(); + SSLServerSocket sslServerSocket = + (SSLServerSocket) sslssf.createServerSocket(serverPort); + + serverPort = sslServerSocket.getLocalPort(); + + /* + * Signal Client, we're ready for his connect. + */ + serverReady = true; + + SSLSocket sslSocket = (SSLSocket) sslServerSocket.accept(); + InputStream sslIS = sslSocket.getInputStream(); + OutputStream sslOS = sslSocket.getOutputStream(); + + // no read, no write. + SSLSession sess = sslSocket.getSession(); + if (!sess.isValid()) { + throw new Exception("Error occurs during the initial handshake"); + } + + sslIS.close(); + sslOS.close(); + sslSocket.close(); + } + + /* + * Define the client side of the test. + */ + void doClientSide() throws Exception { + + /* + * Wait for server to get started. + */ + while (!serverReady) { + Thread.sleep(50); + } + + SSLSocketFactory sslsf = + (SSLSocketFactory) SSLSocketFactory.getDefault(); + SSLSocket sslSocket = (SSLSocket) + sslsf.createSocket("localhost", serverPort); + + InputStream sslIS = sslSocket.getInputStream(); + OutputStream sslOS = sslSocket.getOutputStream(); + + // read zero byte, write zero byte. + sslIS.read(new byte[0], 0, 0); + sslOS.write(new byte[0], 0, 0); + + // if byte array length matters. + sslIS.read(new byte[1], 0, 0); + sslOS.write(new byte[1], 0, 0); + + // note that the above read/write should not kickoff handshaking. + SSLSession sess = sslSocket.getSession(); + if (!sess.isValid()) { + throw new Exception("Error occurs during the initial handshake"); + } + + sslIS.close(); + sslOS.close(); + sslSocket.close(); + } + + /* + * ============================================================= + * The remainder is just support stuff + */ + + // use any free port by default + volatile int serverPort = 0; + + volatile Exception serverException = null; + volatile Exception clientException = null; + + public static void main(String[] args) throws Exception { + String keyFilename = + System.getProperty("test.src", "./") + "/" + pathToStores + + "/" + keyStoreFile; + String trustFilename = + System.getProperty("test.src", "./") + "/" + pathToStores + + "/" + trustStoreFile; + + System.setProperty("javax.net.ssl.keyStore", keyFilename); + System.setProperty("javax.net.ssl.keyStorePassword", passwd); + System.setProperty("javax.net.ssl.trustStore", trustFilename); + System.setProperty("javax.net.ssl.trustStorePassword", passwd); + + if (debug) + System.setProperty("javax.net.debug", "all"); + + /* + * Start the tests. + */ + new ReadZeroBytes(); + } + + Thread clientThread = null; + Thread serverThread = null; + + /* + * Primary constructor, used to drive remainder of the test. + * + * Fork off the other side, then do your work. + */ + ReadZeroBytes () throws Exception { + if (separateServerThread) { + startServer(true); + startClient(false); + } else { + startClient(true); + startServer(false); + } + + /* + * Wait for other side to close down. + */ + if (separateServerThread) { + serverThread.join(); + } else { + clientThread.join(); + } + + /* + * When we get here, the test is pretty much over. + * + * If the main thread excepted, that propagates back + * immediately. If the other thread threw an exception, we + * should report back. + */ + if (serverException != null) + throw serverException; + if (clientException != null) + throw clientException; + } + + void startServer(boolean newThread) throws Exception { + if (newThread) { + serverThread = new Thread() { + public void run() { + try { + doServerSide(); + } catch (Exception e) { + /* + * Our server thread just died. + * + * Release the client, if not already active... + */ + System.out.println("Server died..."); + serverReady = true; + serverException = e; + } + } + }; + serverThread.start(); + } else { + doServerSide(); + } + } + + void startClient(boolean newThread) throws Exception { + if (newThread) { + clientThread = new Thread() { + public void run() { + try { + doClientSide(); + } catch (Exception e) { + /* + * Our client thread just died. + */ + System.out.println("Client died..."); + clientException = e; + } + } + }; + clientThread.start(); + } else { + doClientSide(); + } + } +} + diff --git a/test/sun/security/ssl/com/sun/net/ssl/internal/ssl/SSLSocketImpl/LoopbackSSLSocket.java b/test/sun/security/ssl/com/sun/net/ssl/internal/ssl/SSLSocketImpl/LoopbackSSLSocket.java new file mode 100644 index 0000000000000000000000000000000000000000..d97f20da7aab62b547263d0258dcd75d05a27ce5 --- /dev/null +++ b/test/sun/security/ssl/com/sun/net/ssl/internal/ssl/SSLSocketImpl/LoopbackSSLSocket.java @@ -0,0 +1,50 @@ +/* + * 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. + * + * 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. + */ + +/* + * @test + * @bug 5067458 + * @summary Loopback SSLSocketImpl createSocket is throwing an exception. + * @author Xuelei Fan + */ + +import java.io.*; +import java.net.*; + +import javax.net.ssl.*; + +public class LoopbackSSLSocket { + + public static void main(String[] args) throws Exception { + SSLSocketFactory sf = (SSLSocketFactory)SSLSocketFactory.getDefault(); + // we won't expect a IllegalArgumentException: hostname can't be null. + try { + SSLSocket s = (SSLSocket)sf.createSocket((String)null, 0); + s.close(); + } catch (IOException ioe) { + // would catch a IOException because there is no listener on + // that socket. + } + } + +} diff --git a/test/sun/security/tools/jarsigner/concise_jarsigner.sh b/test/sun/security/tools/jarsigner/concise_jarsigner.sh new file mode 100644 index 0000000000000000000000000000000000000000..1c9eaabe3967eb7d42d7ce6691694f4aa8c19c45 --- /dev/null +++ b/test/sun/security/tools/jarsigner/concise_jarsigner.sh @@ -0,0 +1,200 @@ +# +# 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. +# +# 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. +# + +# @test +# @bug 6802846 +# @summary jarsigner needs enhanced cert validation(options) +# +# @run shell concise_jarsigner.sh +# + +if [ "${TESTJAVA}" = "" ] ; then + JAVAC_CMD=`which javac` + TESTJAVA=`dirname $JAVAC_CMD`/.. +fi + +# set platform-dependent variables +OS=`uname -s` +case "$OS" in + Windows_* ) + FS="\\" + ;; + * ) + FS="/" + ;; +esac + +KT="$TESTJAVA${FS}bin${FS}keytool -storepass changeit -keypass changeit -keystore js.jks" +JAR=$TESTJAVA${FS}bin${FS}jar +JARSIGNER=$TESTJAVA${FS}bin${FS}jarsigner +JAVAC=$TESTJAVA${FS}bin${FS}javac + +rm js.jks + +echo class A1 {} > A1.java +echo class A2 {} > A2.java +echo class A3 {} > A3.java +echo class A4 {} > A4.java +echo class A5 {} > A5.java +echo class A6 {} > A6.java + +$JAVAC A1.java A2.java A3.java A4.java A5.java A6.java +YEAR=`date +%Y` + +# ========================================================== +# First part: output format +# ========================================================== + +$KT -genkeypair -alias a1 -dname CN=a1 -validity 365 +$KT -genkeypair -alias a2 -dname CN=a2 -validity 365 + +# a.jar includes 8 unsigned, 2 signed by a1 and a2, 2 signed by a3 +$JAR cvf a.jar A1.class A2.class +$JARSIGNER -keystore js.jks -storepass changeit a.jar a1 +$JAR uvf a.jar A3.class A4.class +$JARSIGNER -keystore js.jks -storepass changeit a.jar a2 +$JAR uvf a.jar A5.class A6.class + +# Verify OK +$JARSIGNER -verify a.jar +[ $? = 0 ] || exit $LINENO + +# 4(chainNotValidated)+16(hasUnsignedEntry)+32(aliasNotInStore) +$JARSIGNER -verify a.jar -strict +[ $? = 52 ] || exit $LINENO + +# 16(hasUnsignedEntry) +$JARSIGNER -verify a.jar -strict -keystore js.jks +[ $? = 16 ] || exit $LINENO + +# 16(hasUnsignedEntry)+32(notSignedByAlias) +$JARSIGNER -verify a.jar a1 -strict -keystore js.jks +[ $? = 48 ] || exit $LINENO + +# 16(hasUnsignedEntry) +$JARSIGNER -verify a.jar a1 a2 -strict -keystore js.jks +[ $? = 16 ] || exit $LINENO + +# 12 entries all together +LINES=`$JARSIGNER -verify a.jar -verbose | grep $YEAR | wc -l` +[ $LINES = 12 ] || exit $LINENO + +# 12 entries all listed +LINES=`$JARSIGNER -verify a.jar -verbose:grouped | grep $YEAR | wc -l` +[ $LINES = 12 ] || exit $LINENO + +# 3 groups: unrelated, signed, unsigned +LINES=`$JARSIGNER -verify a.jar -verbose:summary | grep $YEAR | wc -l` +[ $LINES = 3 ] || exit $LINENO + +# 4 groups: unrelated, signed by a1/a2, signed by a2, unsigned +LINES=`$JARSIGNER -verify a.jar -verbose:summary -certs | grep $YEAR | wc -l` +[ $LINES = 4 ] || exit $LINENO + +# 2*2 for A1/A2, 2 for A3/A4 +LINES=`$JARSIGNER -verify a.jar -verbose -certs | grep "\[certificate" | wc -l` +[ $LINES = 6 ] || exit $LINENO + +# a1,a2 for A1/A2, a2 for A3/A4 +LINES=`$JARSIGNER -verify a.jar -verbose:grouped -certs | grep "\[certificate" | wc -l` +[ $LINES = 3 ] || exit $LINENO + +# a1,a2 for A1/A2, a2 for A3/A4 +LINES=`$JARSIGNER -verify a.jar -verbose:summary -certs | grep "\[certificate" | wc -l` +[ $LINES = 3 ] || exit $LINENO + +# 4 groups +LINES=`$JARSIGNER -verify a.jar -verbose:summary -certs | grep "more)" | wc -l` +[ $LINES = 4 ] || exit $LINENO + +# ========================================================== +# Second part: exit code 2, 4, 8 +# 16 and 32 already covered in the first part +# ========================================================== + +$KT -genkeypair -alias expiring -dname CN=expiring -startdate -1m +$KT -genkeypair -alias expired -dname CN=expired -startdate -10m +$KT -genkeypair -alias notyetvalid -dname CN=notyetvalid -startdate +1m +$KT -genkeypair -alias badku -dname CN=badku -ext KU=cRLSign -validity 365 +$KT -genkeypair -alias badeku -dname CN=badeku -ext EKU=sa -validity 365 +$KT -genkeypair -alias goodku -dname CN=goodku -ext KU=dig -validity 365 +$KT -genkeypair -alias goodeku -dname CN=goodeku -ext EKU=codesign -validity 365 + +# badchain signed by ca, but ca is removed later +$KT -genkeypair -alias badchain -dname CN=badchain -validity 365 +$KT -genkeypair -alias ca -dname CN=ca -ext bc -validity 365 +$KT -certreq -alias badchain | $KT -gencert -alias ca -validity 365 | \ + $KT -importcert -alias badchain +$KT -delete -alias ca + +$JARSIGNER -strict -keystore js.jks -storepass changeit a.jar expiring +[ $? = 2 ] || exit $LINENO + +$JARSIGNER -strict -keystore js.jks -storepass changeit a.jar expired +[ $? = 4 ] || exit $LINENO + +$JARSIGNER -strict -keystore js.jks -storepass changeit a.jar notyetvalid +[ $? = 4 ] || exit $LINENO + +$JARSIGNER -strict -keystore js.jks -storepass changeit a.jar badku +[ $? = 8 ] || exit $LINENO + +$JARSIGNER -strict -keystore js.jks -storepass changeit a.jar badeku +[ $? = 8 ] || exit $LINENO + +$JARSIGNER -strict -keystore js.jks -storepass changeit a.jar goodku +[ $? = 0 ] || exit $LINENO + +$JARSIGNER -strict -keystore js.jks -storepass changeit a.jar goodeku +[ $? = 0 ] || exit $LINENO + +$JARSIGNER -strict -keystore js.jks -storepass changeit a.jar badchain +[ $? = 4 ] || exit $LINENO + +$JARSIGNER -verify a.jar +[ $? = 0 ] || exit $LINENO + +# ========================================================== +# Third part: -certchain test +# ========================================================== + +# altchain signed by ca2, but ca2 is removed later +$KT -genkeypair -alias altchain -dname CN=altchain -validity 365 +$KT -genkeypair -alias ca2 -dname CN=ca2 -ext bc -validity 365 +$KT -certreq -alias altchain | $KT -gencert -alias ca2 -validity 365 -rfc > certchain +$KT -exportcert -alias ca2 -rfc >> certchain +$KT -delete -alias ca2 + +# Now altchain is still self-signed +$JARSIGNER -strict -keystore js.jks -storepass changeit a.jar altchain +[ $? = 0 ] || exit $LINENO + +# If -certchain is used, then it's bad +$JARSIGNER -strict -keystore js.jks -storepass changeit -certchain certchain a.jar altchain +[ $? = 4 ] || exit $LINENO + +$JARSIGNER -verify a.jar +[ $? = 0 ] || exit $LINENO + +echo OK +exit 0 diff --git a/test/sun/security/tools/keytool/KeyToolTest.java b/test/sun/security/tools/keytool/KeyToolTest.java index e25c3766b5040b540f56bfc0cc57503a9df1a5e1..e1edebedfa5081916e73fe56489bc378cef6c715 100644 --- a/test/sun/security/tools/keytool/KeyToolTest.java +++ b/test/sun/security/tools/keytool/KeyToolTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2007 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2005-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 @@ -56,11 +56,14 @@ */ import java.security.KeyStore; -import java.util.Locale; -import java.util.MissingResourceException; import sun.security.tools.KeyTool; import sun.security.x509.*; import java.io.*; +import java.security.KeyPairGenerator; +import java.security.NoSuchAlgorithmException; +import java.util.*; +import java.security.cert.X509Certificate; +import sun.security.util.ObjectIdentifier; public class KeyToolTest { @@ -118,7 +121,7 @@ public class KeyToolTest { lastInput = input; lastCommand = cmd; - // "X" is appened so that we can precisely test how input is consumed + // "X" is appended so that we can precisely test how input is consumed HumanInputStream in = new HumanInputStream(input+"X"); test(in, cmd); // make sure the input string is no more no less @@ -264,12 +267,21 @@ public class KeyToolTest { } void assertTrue(boolean bool, String msg) { + if (debug) { + System.err.println("If not " + bool + ", " + msg); + } else { + System.err.print("v"); + } if(!bool) { afterFail(lastInput, lastCommand, "TRUE"); + System.err.println(msg); throw new RuntimeException(msg); } } + void assertTrue(boolean bool) { + assertTrue(bool, "well..."); + } /** * Helper method, load a keystore * @param file file for keystore, null or "NONE" for PKCS11 @@ -827,32 +839,363 @@ public class KeyToolTest { remove("mykey.cert"); } + void v3extTest(String keyAlg) throws Exception { + KeyStore ks; + remove("x.jks"); + String simple = "-keystore x.jks -storepass changeit -keypass changeit -noprompt -keyalg " + keyAlg + " "; + String pre = simple + "-genkeypair -dname CN=Olala -alias "; + + // Version and SKID + testOK("", pre + "o1"); + + ks = loadStore("x.jks", "changeit", "JKS"); + assertTrue(((X509Certificate)ks.getCertificate("o1")).getVersion() == 3); + assertTrue(((X509CertImpl)ks.getCertificate("o1")).getSubjectKeyIdentifierExtension() != null); + + // BC + testOK("", pre + "b1 -ext BC:critical"); + testOK("", pre + "b2 -ext BC"); + testOK("", pre + "b3 -ext bc"); + testOK("", pre + "b4 -ext BasicConstraints"); + testOK("", pre + "b5 -ext basicconstraints"); + testOK("", pre + "b6 -ext BC=ca:true,pathlen:12"); + testOK("", pre + "b7 -ext BC=ca:false"); + testOK("", pre + "b8 -ext BC:critical=ca:false"); + testOK("", pre + "b9 -ext BC=12"); + + ks = loadStore("x.jks", "changeit", "JKS"); + assertTrue(((X509CertImpl)ks.getCertificate("b1")).getBasicConstraintsExtension().isCritical()); + assertTrue(!((X509CertImpl)ks.getCertificate("b2")).getBasicConstraintsExtension().isCritical()); + assertTrue(((X509CertImpl)ks.getCertificate("b8")).getBasicConstraintsExtension().isCritical()); + assertTrue(((X509Certificate)ks.getCertificate("b1")).getBasicConstraints() == Integer.MAX_VALUE); + assertTrue(((X509Certificate)ks.getCertificate("b2")).getBasicConstraints() == Integer.MAX_VALUE); + assertTrue(((X509Certificate)ks.getCertificate("b3")).getBasicConstraints() == Integer.MAX_VALUE); + assertTrue(((X509Certificate)ks.getCertificate("b4")).getBasicConstraints() == Integer.MAX_VALUE); + assertTrue(((X509Certificate)ks.getCertificate("b5")).getBasicConstraints() == Integer.MAX_VALUE); + assertTrue(((X509Certificate)ks.getCertificate("b6")).getBasicConstraints() == 12); + assertTrue(((X509Certificate)ks.getCertificate("b7")).getBasicConstraints() == -1); + assertTrue(((X509Certificate)ks.getCertificate("b9")).getBasicConstraints() == 12); + + // KU + testOK("", pre + "ku1 -ext KeyUsage:critical=digitalsignature"); + testOK("", pre + "ku2 -ext KU=digitalSignature"); + testOK("", pre + "ku3 -ext KU=ds"); + testOK("", pre + "ku4 -ext KU=dig"); + testFail("", pre + "ku5 -ext KU=d"); // ambigous value + testFail("", pre + "ku6 -ext KU=cs"); // cRLSign cannot be cs + testOK("", pre + "ku11 -ext KU=nr"); + testFail("", pre + "ku12 -ext KU=ke"); // ke also means keyAgreement + testOK("", pre + "ku12 -ext KU=keyE"); + testFail("", pre + "ku13 -ext KU=de"); // de also means decipherOnly + testOK("", pre + "ku13 -ext KU=dataE"); + testOK("", pre + "ku14 -ext KU=ka"); + testOK("", pre + "ku15 -ext KU=kcs"); + testOK("", pre + "ku16 -ext KU=crls"); + testOK("", pre + "ku17 -ext KU=eo"); + testOK("", pre + "ku18 -ext KU=do"); + testOK("", pre + "ku19 -ext KU=cc"); + + testOK("", pre + "ku017 -ext KU=ds,cc,eo"); + testOK("", pre + "ku135 -ext KU=nr,dataEncipherment,keyCertSign"); + testOK("", pre + "ku246 -ext KU=keyEnc,cRL,keyA"); + testOK("", pre + "ku1234 -ext KU=ka,da,keyE,nonR"); + + ks = loadStore("x.jks", "changeit", "JKS"); + class CheckKU { + void check(KeyStore ks, String alias, int... pos) throws Exception { + System.err.print("x"); + boolean[] bs = ((X509Certificate)ks.getCertificate(alias)).getKeyUsage(); + bs = Arrays.copyOf(bs, 9); + for (int i=0; i<bs.length; i++) { + boolean found = false; + for (int p: pos) { + if (p == i) found = true; + } + if (!found ^ bs[i]) { + // OK + } else { + throw new RuntimeException("KU not match at " + i + + ": " + found + " vs " + bs[i]); + } + } + } + } + CheckKU c = new CheckKU(); + assertTrue(((X509CertImpl)ks.getCertificate("ku1")).getExtension(PKIXExtensions.KeyUsage_Id).isCritical()); + assertTrue(!((X509CertImpl)ks.getCertificate("ku2")).getExtension(PKIXExtensions.KeyUsage_Id).isCritical()); + c.check(ks, "ku1", 0); + c.check(ks, "ku2", 0); + c.check(ks, "ku3", 0); + c.check(ks, "ku4", 0); + c.check(ks, "ku11", 1); + c.check(ks, "ku12", 2); + c.check(ks, "ku13", 3); + c.check(ks, "ku14", 4); + c.check(ks, "ku15", 5); + c.check(ks, "ku16", 6); + c.check(ks, "ku17", 7); + c.check(ks, "ku18", 8); + c.check(ks, "ku19", 1); + c.check(ks, "ku11", 1); + c.check(ks, "ku11", 1); + c.check(ks, "ku11", 1); + c.check(ks, "ku017", 0, 1, 7); + c.check(ks, "ku135", 1, 3, 5); + c.check(ks, "ku246", 6, 2, 4); + c.check(ks, "ku1234", 1, 2, 3, 4); + + // EKU + testOK("", pre + "eku1 -ext EKU:critical=sa"); + testOK("", pre + "eku2 -ext ExtendedKeyUsage=ca"); + testOK("", pre + "eku3 -ext EKU=cs"); + testOK("", pre + "eku4 -ext EKU=ep"); + testOK("", pre + "eku8 -ext EKU=ts"); + testFail("", pre + "eku9 -ext EKU=os"); + testOK("", pre + "eku9 -ext EKU=ocsps"); + testOK("", pre + "eku10 -ext EKU=any"); + testOK("", pre + "eku11 -ext EKU=1.2.3.4,1.3.5.7,ep"); + testFail("", pre + "eku12 -ext EKU=c"); + testFail("", pre + "eku12 -ext EKU=nothing"); + + ks = loadStore("x.jks", "changeit", "JKS"); + class CheckEKU { + void check(KeyStore ks, String alias, String... pos) throws Exception { + System.err.print("x"); + List<String> bs = ((X509Certificate)ks.getCertificate(alias)).getExtendedKeyUsage(); + int found = 0; + for (String p: pos) { + if (bs.contains(p)) { + found++; + } else { + throw new RuntimeException("EKU: not included " + p); + } + } + if (found != bs.size()) { + throw new RuntimeException("EKU: more items than expected"); + } + } + } + CheckEKU cx = new CheckEKU(); + assertTrue(((X509CertImpl)ks.getCertificate("eku1")).getExtension(PKIXExtensions.ExtendedKeyUsage_Id).isCritical()); + assertTrue(!((X509CertImpl)ks.getCertificate("eku2")).getExtension(PKIXExtensions.ExtendedKeyUsage_Id).isCritical()); + cx.check(ks, "eku1", "1.3.6.1.5.5.7.3.1"); + cx.check(ks, "eku2", "1.3.6.1.5.5.7.3.2"); + cx.check(ks, "eku3", "1.3.6.1.5.5.7.3.3"); + cx.check(ks, "eku4", "1.3.6.1.5.5.7.3.4"); + cx.check(ks, "eku8", "1.3.6.1.5.5.7.3.8"); + cx.check(ks, "eku9", "1.3.6.1.5.5.7.3.9"); + cx.check(ks, "eku10", "2.5.29.37.0"); + cx.check(ks, "eku11", "1.3.6.1.5.5.7.3.4", "1.2.3.4", "1.3.5.7"); + + // SAN + testOK("", pre+"san1 -ext san:critical=email:me@me.org"); + testOK("", pre+"san2 -ext san=uri:http://me.org"); + testOK("", pre+"san3 -ext san=dns:me.org"); + testOK("", pre+"san4 -ext san=ip:192.168.0.1"); + testOK("", pre+"san5 -ext san=oid:1.2.3.4"); + testOK("", pre+"san235 -ext san=uri:http://me.org,dns:me.org,oid:1.2.3.4"); + + ks = loadStore("x.jks", "changeit", "JKS"); + class CheckSAN { + // Please sort items with name type + void check(KeyStore ks, String alias, int type, Object... items) throws Exception { + int pos = 0; + System.err.print("x"); + Object[] names = null; + if (type == 0) names = ((X509Certificate)ks.getCertificate(alias)).getSubjectAlternativeNames().toArray(); + else names = ((X509Certificate)ks.getCertificate(alias)).getIssuerAlternativeNames().toArray(); + Arrays.sort(names, new Comparator() { + public int compare(Object o1, Object o2) { + int i1 = (Integer)((List)o1).get(0); + int i2 = (Integer)((List)o2).get(0); + return i1 - i2; + } + }); + for (Object o: names) { + List l = (List)o; + for (Object o2: l) { + if (!items[pos++].equals(o2)) { + throw new RuntimeException("Not equals at " + pos + + ": " + items[pos-1] + " vs " + o2); + } + } + } + if (pos != items.length) { + throw new RuntimeException("Extra items, pos is " + pos); + } + } + } + CheckSAN csan = new CheckSAN(); + assertTrue(((X509CertImpl)ks.getCertificate("san1")).getSubjectAlternativeNameExtension().isCritical()); + assertTrue(!((X509CertImpl)ks.getCertificate("san2")).getSubjectAlternativeNameExtension().isCritical()); + csan.check(ks, "san1", 0, 1, "me@me.org"); + csan.check(ks, "san2", 0, 6, "http://me.org"); + csan.check(ks, "san3", 0, 2, "me.org"); + csan.check(ks, "san4", 0, 7, "192.168.0.1"); + csan.check(ks, "san5", 0, 8, "1.2.3.4"); + csan.check(ks, "san235", 0, 2, "me.org", 6, "http://me.org", 8, "1.2.3.4"); + + // IAN + testOK("", pre+"ian1 -ext ian:critical=email:me@me.org"); + testOK("", pre+"ian2 -ext ian=uri:http://me.org"); + testOK("", pre+"ian3 -ext ian=dns:me.org"); + testOK("", pre+"ian4 -ext ian=ip:192.168.0.1"); + testOK("", pre+"ian5 -ext ian=oid:1.2.3.4"); + testOK("", pre+"ian235 -ext ian=uri:http://me.org,dns:me.org,oid:1.2.3.4"); + + ks = loadStore("x.jks", "changeit", "JKS"); + assertTrue(((X509CertImpl)ks.getCertificate("ian1")).getIssuerAlternativeNameExtension().isCritical()); + assertTrue(!((X509CertImpl)ks.getCertificate("ian2")).getIssuerAlternativeNameExtension().isCritical()); + csan.check(ks, "ian1", 1, 1, "me@me.org"); + csan.check(ks, "ian2", 1, 6, "http://me.org"); + csan.check(ks, "ian3", 1, 2, "me.org"); + csan.check(ks, "ian4", 1, 7, "192.168.0.1"); + csan.check(ks, "ian5", 1, 8, "1.2.3.4"); + csan.check(ks, "ian235", 1, 2, "me.org", 6, "http://me.org", 8, "1.2.3.4"); + + // SIA + testOK("", pre+"sia1 -ext sia=care:uri:ldap://ca.com/cn=CA"); + testOK("", pre+"sia2 -ext sia=ts:email:ts@ca.com"); + testFail("SIA never critical", pre+"sia3 -ext sia:critical=ts:email:ts@ca.com"); + + ks = loadStore("x.jks", "changeit", "JKS"); + class CheckSia { + void check(KeyStore ks, String alias, int type, Object... items) throws Exception { + int pos = 0; + System.err.print("x"); + AccessDescription[] ads = null; + if (type == 0) { + SubjectInfoAccessExtension siae = (SubjectInfoAccessExtension)((X509CertImpl)ks.getCertificate(alias)).getExtension(PKIXExtensions.SubjectInfoAccess_Id); + ads = siae.getAccessDescriptions().toArray(new AccessDescription[0]); + } else { + AuthorityInfoAccessExtension aiae = (AuthorityInfoAccessExtension)((X509CertImpl)ks.getCertificate(alias)).getExtension(PKIXExtensions.AuthInfoAccess_Id); + ads = aiae.getAccessDescriptions().toArray(new AccessDescription[0]); + } + Arrays.sort(ads, new Comparator<AccessDescription>() { + @Override + public int compare(AccessDescription o1, AccessDescription o2) { + return o1.getAccessMethod().toString().compareTo(o2.getAccessMethod().toString()); + } + }); + for (AccessDescription ad: ads) { + if (!ad.getAccessMethod().equals(items[pos++]) || + !new Integer(ad.getAccessLocation().getType()).equals(items[pos++])) { + throw new RuntimeException("Not same type at " + pos); + } + String name = null; + switch (ad.getAccessLocation().getType()) { + case 1: + name = ((RFC822Name)ad.getAccessLocation().getName()).getName(); + break; + case 6: + name = ((URIName)ad.getAccessLocation().getName()).getURI().toString(); + break; + default: + throw new RuntimeException("Not implemented: " + ad); + } + if (!name.equals(items[pos++])) { + throw new Exception("Name not same for " + ad + " at pos " + pos); + } + } + } + } + CheckSia csia = new CheckSia(); + assertTrue(!((X509CertImpl)ks.getCertificate("sia1")).getExtension(PKIXExtensions.SubjectInfoAccess_Id).isCritical()); + csia.check(ks, "sia1", 0, AccessDescription.Ad_CAREPOSITORY_Id, 6, "ldap://ca.com/cn=CA"); + csia.check(ks, "sia2", 0, AccessDescription.Ad_TIMESTAMPING_Id, 1, "ts@ca.com"); + + // AIA + testOK("", pre+"aia1 -ext aia=cai:uri:ldap://ca.com/cn=CA"); + testOK("", pre+"aia2 -ext aia=ocsp:email:ocsp@ca.com"); + testFail("AIA never critical", pre+"aia3 -ext aia:critical=ts:email:ts@ca.com"); + + ks = loadStore("x.jks", "changeit", "JKS"); + assertTrue(!((X509CertImpl)ks.getCertificate("aia1")).getExtension(PKIXExtensions.AuthInfoAccess_Id).isCritical()); + csia.check(ks, "aia1", 1, AccessDescription.Ad_CAISSUERS_Id, 6, "ldap://ca.com/cn=CA"); + csia.check(ks, "aia2", 1, AccessDescription.Ad_OCSP_Id, 1, "ocsp@ca.com"); + + // OID + testOK("", pre+"oid1 -ext 1.2.3:critical=0102"); + testOK("", pre+"oid2 -ext 1.2.3"); + testOK("", pre+"oid12 -ext 1.2.3 -ext 1.2.4=01:02:03"); + + ks = loadStore("x.jks", "changeit", "JKS"); + class CheckOid { + void check(KeyStore ks, String alias, String oid, byte[] value) throws Exception { + int pos = 0; + System.err.print("x"); + Extension ex = ((X509CertImpl)ks.getCertificate(alias)).getExtension(new ObjectIdentifier(oid)); + if (!Arrays.equals(value, ex.getValue())) { + throw new RuntimeException("Not same content in " + alias + " for " + oid); + } + } + } + CheckOid coid = new CheckOid(); + assertTrue(((X509CertImpl)ks.getCertificate("oid1")).getExtension(new ObjectIdentifier("1.2.3")).isCritical()); + assertTrue(!((X509CertImpl)ks.getCertificate("oid2")).getExtension(new ObjectIdentifier("1.2.3")).isCritical()); + coid.check(ks, "oid1", "1.2.3", new byte[]{1,2}); + coid.check(ks, "oid2", "1.2.3", new byte[]{}); + coid.check(ks, "oid12", "1.2.3", new byte[]{}); + coid.check(ks, "oid12", "1.2.4", new byte[]{1,2,3}); + + // honored + testOK("", pre+"ca"); + testOK("", pre+"a"); + // request: BC,KU,1.2.3,1.2.4,1.2.5 + testOK("", simple+"-alias a -certreq " + + "-ext BC=1 -ext KU=crl " + + "-ext 1.2.3=01 -ext 1.2.4:critical=0102 -ext 1.2.5=010203 " + + "-rfc -file test.req"); + // printcertreq + testOK("", "-printcertreq -file test.req"); + // issue: deny KU, change criticality of 1.2.3 and 1.2.4, change content of BC, add 2.3.4 + testOK("", simple+"-gencert -alias ca -infile test.req -ext " + + "honored=all,-KU,1.2.3:critical,1.2.4:non-critical " + + "-ext BC=2 -ext 2.3.4=01020304 " + + "-debug -rfc -outfile test.cert"); + testOK("", simple+"-importcert -file test.cert -alias a"); + ks = loadStore("x.jks", "changeit", "JKS"); + X509CertImpl a = (X509CertImpl)ks.getCertificate("a"); + assertTrue(a.getAuthorityKeyIdentifierExtension() != null); + assertTrue(a.getSubjectKeyIdentifierExtension() != null); + assertTrue(a.getKeyUsage() == null); + assertTrue(a.getExtension(new ObjectIdentifier("1.2.3")).isCritical()); + assertTrue(!a.getExtension(new ObjectIdentifier("1.2.4")).isCritical()); + assertTrue(!a.getExtension(new ObjectIdentifier("1.2.5")).isCritical()); + assertTrue(a.getExtensionValue("1.2.3").length == 3); + assertTrue(a.getExtensionValue("1.2.4").length == 4); + assertTrue(a.getExtensionValue("1.2.5").length == 5); + assertTrue(a.getBasicConstraints() == 2); + assertTrue(!a.getExtension(new ObjectIdentifier("2.3.4")).isCritical()); + assertTrue(a.getExtensionValue("2.3.4").length == 6); + + remove("x.jks"); + remove("test.req"); + remove("test.cert"); + } + void i18nTest() throws Exception { // 1. keytool -help remove("x.jks"); - try { - test("", "-help"); - assertTrue(false, "Cannot come here"); - } catch(RuntimeException e) { - assertTrue(e.getMessage().indexOf("NO ERROR, SORRY") != -1, "No error"); - } + testOK("", "-help"); + // 2. keytool -genkey -v -keysize 512 Enter "a" for the keystore password. Check error (password too short). Enter "password" for the keystore password. Hit 'return' for "first and last name", "organizational unit", "City", "State", and "Country Code". Type "yes" when they ask you if everything is correct. Type 'return' for new key password. testOK("a\npassword\npassword\nMe\nHere\nNow\nPlace\nPlace\nUS\nyes\n\n", "-genkey -v -keysize 512 -keystore x.jks"); // 3. keytool -list -v -storepass password testOK("", "-list -v -storepass password -keystore x.jks"); // 4. keytool -list -v Type "a" for the keystore password. Check error (wrong keystore password). testFail("a\n", "-list -v -keystore x.jks"); - assertTrue(ex.indexOf("password was incorrect") != -1, ""); + assertTrue(ex.indexOf("password was incorrect") != -1); // 5. keytool -genkey -v -keysize 512 Enter "password" as the password. Check error (alias 'mykey' already exists). testFail("password\n", "-genkey -v -keysize 512 -keystore x.jks"); - assertTrue(ex.indexOf("alias <mykey> already exists") != -1, ""); + assertTrue(ex.indexOf("alias <mykey> already exists") != -1); // 6. keytool -genkey -v -keysize 512 -alias mykey2 -storepass password Hit 'return' for "first and last name", "organizational unit", "City", "State", and "Country Code". Type "yes" when they ask you if everything is correct. Type 'return' for new key password. testOK("\n\n\n\n\n\nyes\n\n", "-genkey -v -keysize 512 -alias mykey2 -storepass password -keystore x.jks"); // 7. keytool -list -v Type 'password' for the store password. testOK("password\n", "-list -v -keystore x.jks"); // 8. keytool -keypasswd -v -alias mykey2 -storepass password Type "a" for the new key password. Type "aaaaaa" for the new key password. Type "bbbbbb" when re-entering the new key password. Type "a" for the new key password. Check Error (too many failures). testFail("a\naaaaaa\nbbbbbb\na\n", "-keypasswd -v -alias mykey2 -storepass password -keystore x.jks"); - assertTrue(ex.indexOf("Too many failures - try later") != -1, ""); + assertTrue(ex.indexOf("Too many failures - try later") != -1); // 9. keytool -keypasswd -v -alias mykey2 -storepass password Type "aaaaaa" for the new key password. Type "aaaaaa" when re-entering the new key password. testOK("aaaaaa\naaaaaa\n", "-keypasswd -v -alias mykey2 -storepass password -keystore x.jks"); // 10. keytool -selfcert -v -alias mykey -storepass password @@ -864,7 +1207,7 @@ public class KeyToolTest { testOK("", "-export -v -alias mykey -file cert -storepass password -keystore x.jks"); // 13. keytool -import -v -file cert -storepass password Check error (Certificate reply and cert are the same) testFail("", "-import -v -file cert -storepass password -keystore x.jks"); - assertTrue(ex.indexOf("Certificate reply and certificate in keystore are identical") != -1, ""); + assertTrue(ex.indexOf("Certificate reply and certificate in keystore are identical") != -1); // 14. keytool -printcert -file cert testOK("", "-printcert -file cert -keystore x.jks"); remove("cert"); @@ -875,26 +1218,26 @@ public class KeyToolTest { // 1. keytool -storepasswd -storepass password -new abc Check error (password too short) testFail("", "-storepasswd -storepass password -new abc"); - assertTrue(ex.indexOf("New password must be at least 6 characters") != -1, ""); + assertTrue(ex.indexOf("New password must be at least 6 characters") != -1); // Changed, no NONE needed now // 2. keytool -list -storetype PKCS11 Check error (-keystore must be NONE) //testFail("", "-list -storetype PKCS11"); - //assertTrue(err.indexOf("keystore must be NONE") != -1, ""); + //assertTrue(err.indexOf("keystore must be NONE") != -1); // 3. keytool -storepasswd -storetype PKCS11 -keystore NONE Check error (unsupported operation) testFail("", "-storepasswd -storetype PKCS11 -keystore NONE"); - assertTrue(ex.indexOf("UnsupportedOperationException") != -1, ""); + assertTrue(ex.indexOf("UnsupportedOperationException") != -1); // 4. keytool -keypasswd -storetype PKCS11 -keystore NONE Check error (unsupported operation) testFail("", "-keypasswd -storetype PKCS11 -keystore NONE"); - assertTrue(ex.indexOf("UnsupportedOperationException") != -1, ""); + assertTrue(ex.indexOf("UnsupportedOperationException") != -1); // 5. keytool -list -protected -storepass password Check error (password can not be specified with -protected) testFail("", "-list -protected -storepass password -keystore x.jks"); - assertTrue(ex.indexOf("if -protected is specified, then") != -1, ""); + assertTrue(ex.indexOf("if -protected is specified, then") != -1); // 6. keytool -keypasswd -protected -keypass password Check error (password can not be specified with -protected) testFail("", "-keypasswd -protected -keypass password -keystore x.jks"); - assertTrue(ex.indexOf("if -protected is specified, then") != -1, ""); + assertTrue(ex.indexOf("if -protected is specified, then") != -1); // 7. keytool -keypasswd -protected -new password Check error (password can not be specified with -protected) testFail("", "-keypasswd -protected -new password -keystore x.jks"); - assertTrue(ex.indexOf("if -protected is specified, then") != -1, ""); + assertTrue(ex.indexOf("if -protected is specified, then") != -1); remove("x.jks"); } @@ -911,11 +1254,11 @@ public class KeyToolTest { testOK("", "-printcert -file genkey.cert"); testOK("", p11Arg + "-storepass test12 -selfcert -alias genkey -dname cn=selfCert"); testOK("", p11Arg + "-storepass test12 -list -alias genkey -v"); - assertTrue(out.indexOf("Owner: CN=selfCert") != -1, ""); + assertTrue(out.indexOf("Owner: CN=selfCert") != -1); //(check that cert subject DN is [cn=selfCert]) testOK("", p11Arg + "-storepass test12 -delete -alias genkey"); testOK("", p11Arg + "-storepass test12 -list"); - assertTrue(out.indexOf("Your keystore contains 0 entries") != -1, ""); + assertTrue(out.indexOf("Your keystore contains 0 entries") != -1); //(check for empty database listing) //Runtime.getRuntime().exec("/usr/ccs/bin/sccs unedit cert8.db key3.db"); remove("genkey.cert"); @@ -943,6 +1286,15 @@ public class KeyToolTest { t.sqeTest(); t.testAll(); t.i18nTest(); + t.v3extTest("RSA"); + t.v3extTest("DSA"); + boolean testEC = true; + try { + KeyPairGenerator.getInstance("EC"); + } catch (NoSuchAlgorithmException nae) { + testEC = false; + } + if (testEC) t.v3extTest("EC"); } if (System.getProperty("nss") != null) { diff --git a/test/sun/security/tools/keytool/NoExtNPE.sh b/test/sun/security/tools/keytool/NoExtNPE.sh new file mode 100644 index 0000000000000000000000000000000000000000..3e929b5354f8040c008ca88e56151171ea13d1e6 --- /dev/null +++ b/test/sun/security/tools/keytool/NoExtNPE.sh @@ -0,0 +1,65 @@ +# +# 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. +# +# 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. +# + +# @test +# @bug 6813402 +# @summary keytool cannot -printcert entries without extensions +# +# @run shell NoExtNPE.sh + +# set a few environment variables so that the shell-script can run stand-alone +# in the source directory +if [ "${TESTSRC}" = "" ] ; then + TESTSRC="." +fi + +if [ "${TESTJAVA}" = "" ] ; then + echo "TESTJAVA not set. Test cannot execute." + echo "FAILED!!!" + exit 1 +fi + +# set platform-dependent variables +OS=`uname -s` +case "$OS" in + SunOS ) + FILESEP="/" + ;; + Linux ) + FILESEP="/" + ;; + Windows* ) + FILESEP="\\" + ;; + * ) + echo "Unrecognized system!" + exit 1; + ;; +esac + +${TESTJAVA}${FILESEP}bin${FILESEP}keytool \ + -list -v \ + -keystore ${TESTSRC}${FILESEP}CloneKeyAskPassword.jks \ + -storepass test123 + +exit $? diff --git a/test/sun/security/tools/keytool/autotest.sh b/test/sun/security/tools/keytool/autotest.sh index 04c00c14ebfe9484e69f44795e1c60352da4387a..e3431836b1a88146280551abed51ec3c4c6c2914 100644 --- a/test/sun/security/tools/keytool/autotest.sh +++ b/test/sun/security/tools/keytool/autotest.sh @@ -1,5 +1,5 @@ # -# Copyright 2006-2008 Sun Microsystems, Inc. All Rights Reserved. +# Copyright 2006-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 @@ -25,6 +25,8 @@ # @summary (almost) all keytool behaviors # @author Weijun Wang # +# This test is only executed on several platforms +# # set a few environment variables so that the shell-script can run stand-alone # in the source directory if [ "${TESTSRC}" = "" ] ; then @@ -88,7 +90,7 @@ cp ${NSS}${FS}db${FS}secmod.db . chmod u+w key3.db chmod u+w cert8.db -echo | ${TESTJAVA}${FS}bin${FS}java -Dfile -Dnss \ +echo | ${TESTJAVA}${FS}bin${FS}java -Dnss \ -Dnss.lib=${NSS}${FS}lib${FS}${PF}${FS}${LIBNAME} \ KeyToolTest status=$? @@ -99,8 +101,8 @@ rm -f key3.db rm -f secmod.db rm HumanInputStream*.class -rm KeyToolTest.class -rm TestException.class +rm KeyToolTest*.class +rm TestException.class exit $status diff --git a/test/sun/security/tools/keytool/importreadall.sh b/test/sun/security/tools/keytool/importreadall.sh new file mode 100644 index 0000000000000000000000000000000000000000..6c0c65dedc7a11e95d3db1bd5cffe54fcc778d45 --- /dev/null +++ b/test/sun/security/tools/keytool/importreadall.sh @@ -0,0 +1,62 @@ +# +# 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. +# +# 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. +# + +# @test +# @bug 6819272 +# @summary keytool -importcert should read the whole input +# +# @run shell importreadall.sh + +# set a few environment variables so that the shell-script can run stand-alone +# in the source directory +if [ "${TESTSRC}" = "" ] ; then + TESTSRC="." +fi + +if [ "${TESTJAVA}" = "" ] ; then + JAVA_CMD=`which java` + TESTJAVA=`dirname $JAVA_CMD`/.. +fi + +# set platform-dependent variables +OS=`uname -s` +case "$OS" in + Windows_* ) + FS="\\" + ;; + * ) + FS="/" + ;; +esac + +KEYTOOL="${TESTJAVA}${FS}bin${FS}keytool -keystore importreadall.jks -storepass changeit -keypass changeit" + +# In case the test is run twice in the same directory + +$KEYTOOL -delete -alias a +$KEYTOOL -delete -alias ca +$KEYTOOL -genkeypair -alias a -dname CN=a || exit 1 +$KEYTOOL -genkeypair -alias ca -dname CN=ca || exit 2 +$KEYTOOL -certreq -alias a | $KEYTOOL -gencert -alias ca | $KEYTOOL -importcert -alias a + +exit $? diff --git a/test/sun/security/tools/keytool/selfissued.sh b/test/sun/security/tools/keytool/selfissued.sh new file mode 100644 index 0000000000000000000000000000000000000000..e6e06c040b38ce3a40cacafe70be711eacab9518 --- /dev/null +++ b/test/sun/security/tools/keytool/selfissued.sh @@ -0,0 +1,69 @@ +# +# 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. +# +# 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. +# + +# @test +# @bug 6825352 +# @summary support self-issued certificate in keytool +# +# @run shell selfissued.sh +# + +if [ "${TESTJAVA}" = "" ] ; then + JAVAC_CMD=`which javac` + TESTJAVA=`dirname $JAVAC_CMD`/.. +fi + +# set platform-dependent variables +OS=`uname -s` +case "$OS" in + Windows_* ) + FS="\\" + ;; + * ) + FS="/" + ;; +esac + +KS=selfsigned.jks +KT="$TESTJAVA${FS}bin${FS}keytool -storepass changeit -keypass changeit -keystore $KS" + +rm $KS + +$KT -alias ca -dname CN=CA -genkeypair +$KT -alias me -dname CN=CA -genkeypair +$KT -alias e1 -dname CN=E1 -genkeypair +$KT -alias e2 -dname CN=E2 -genkeypair + +# me signed by ca, self-issued +$KT -alias me -certreq | $KT -alias ca -gencert | $KT -alias me -importcert + +# Import e1 signed by me, should add me and ca +$KT -alias e1 -certreq | $KT -alias me -gencert | $KT -alias e1 -importcert +$KT -alias e1 -list -v | grep '\[3\]' || { echo Bad E1; exit 1; } + +# Import (e2 signed by me,ca,me), should reorder to (e2,me,ca) +( $KT -alias e2 -certreq | $KT -alias me -gencert; $KT -exportcert -alias ca; $KT -exportcert -alias me ) | $KT -alias e2 -importcert +$KT -alias e2 -list -v | grep '\[3\]' || { echo Bad E2; exit 1; } + +echo Good + diff --git a/test/sun/security/tools/keytool/standard.sh b/test/sun/security/tools/keytool/standard.sh new file mode 100644 index 0000000000000000000000000000000000000000..fe4a0a813128676f18ff61bbd65f1d0f0c4579bb --- /dev/null +++ b/test/sun/security/tools/keytool/standard.sh @@ -0,0 +1,64 @@ +# +# 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. +# +# 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. +# + +# @test +# @summary (almost) all keytool behaviors +# @author Weijun Wang +# +# This test is always excecuted. +# +# set a few environment variables so that the shell-script can run stand-alone +# in the source directory +if [ "${TESTSRC}" = "" ] ; then + TESTSRC="." +fi +if [ "${TESTCLASSES}" = "" ] ; then + TESTCLASSES="." +fi +if [ "${TESTJAVA}" = "" ] ; then + JAVAC_CMD=`which javac` + TESTJAVA=`dirname $JAVAC_CMD`/.. +fi + +# set platform-dependent variables +OS=`uname -s` +case "$OS" in + Windows_* ) + FS="\\" + ;; + * ) + FS="/" + ;; +esac + +${TESTJAVA}${FS}bin${FS}javac -d . ${TESTSRC}${FS}KeyToolTest.java || exit 10 + +echo | ${TESTJAVA}${FS}bin${FS}java -Dfile KeyToolTest +status=$? + +rm HumanInputStream*.class +rm KeyToolTest*.class +rm TestException.class + +exit $status + diff --git a/test/sun/security/util/DerValue/EmptyValue.java b/test/sun/security/util/DerValue/EmptyValue.java new file mode 100644 index 0000000000000000000000000000000000000000..b2803802957a4632dc4e7b19d3ee9ff4c1f74398 --- /dev/null +++ b/test/sun/security/util/DerValue/EmptyValue.java @@ -0,0 +1,44 @@ +/* + * 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. + * + * 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. + */ + +/* + * @test + * @bug 6804045 + * @summary DerValue does not accept empty OCTET STRING + */ + +import sun.security.util.DerValue; + +public class EmptyValue { + + public static void main(String[] args) throws Exception { + DerValue v = new DerValue(new byte[]{4,0}); + if (v.getOctetString().length != 0) { + throw new Exception("Get octet string error"); + } + v = new DerValue(new byte[]{0x30,0}); + if (v.data.available() != 0) { + throw new Exception("Get sequence error"); + } + } +} diff --git a/test/sun/security/x509/Extensions/BCNull.java b/test/sun/security/x509/Extensions/BCNull.java new file mode 100644 index 0000000000000000000000000000000000000000..e906f576992694e64501596336a3f0c184f793d8 --- /dev/null +++ b/test/sun/security/x509/Extensions/BCNull.java @@ -0,0 +1,37 @@ +/* + * 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. + * + * 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. + */ + +/* + * @test + * @summary BasicConstraintsExtension does not encode when (ca==false && pathLen<0) + * @bug 6803376 + */ + +import sun.security.x509.BasicConstraintsExtension; +import java.io.ByteArrayOutputStream; + +public class BCNull { + public static void main(String [] args) throws Exception { + new BasicConstraintsExtension(false, -1).encode(new ByteArrayOutputStream()); + } +}