--- a/jdk/make/common/Defs.gmk Wed Oct 28 16:26:52 2009 -0700
+++ b/jdk/make/common/Defs.gmk Wed Oct 28 16:54:50 2009 -0700
@@ -667,12 +667,7 @@
LINTFLAGS = $(LINTFLAGS_$(VARIANT)) $(LINTFLAGS_COMMON) \
$(OTHER_LINTFLAGS)
-# this should be moved into Defs-<platform>.gmk.....
-ifeq ($(PLATFORM), windows)
- VERSION_DEFINES = -DRELEASE="\"$(RELEASE)\""
-else
- VERSION_DEFINES = -DRELEASE='"$(RELEASE)"'
-endif
+VERSION_DEFINES = -DRELEASE='"$(RELEASE)"'
# Note: As a rule, GNU Make rules should not appear in any of the
# Defs*.gmk files. These were added for Kestrel-Solaris and do address
--- a/jdk/make/common/Program.gmk Wed Oct 28 16:26:52 2009 -0700
+++ b/jdk/make/common/Program.gmk Wed Oct 28 16:54:50 2009 -0700
@@ -236,13 +236,13 @@
endif # INCREMENTAL_BUILD
ifdef JAVA_ARGS
-OTHER_CPPFLAGS += -DJAVA_ARGS=$(JAVA_ARGS)
-OTHER_CPPFLAGS += -DLAUNCHER_NAME=\"$(LAUNCHER_NAME)\"
+OTHER_CPPFLAGS += -DJAVA_ARGS='$(JAVA_ARGS)'
+OTHER_CPPFLAGS += -DLAUNCHER_NAME='"$(LAUNCHER_NAME)"'
endif
ifeq ($(PLATFORM), windows)
ifdef RELEASE
-OTHER_CPPFLAGS += -DVERSION="$(RELEASE)"
+OTHER_CPPFLAGS += -DVERSION='"$(RELEASE)"'
endif
endif
@@ -258,14 +258,8 @@
OTHER_INCLUDES += -I$(LAUNCHER_SHARE_SRC)/bin -I$(LAUNCHER_PLATFORM_SRC)/bin
OTHER_INCLUDES += -I$(SHARE_SRC)/native/java/util/zip/zlib-1.1.3
-# this may not be necessary...
-ifeq ($(PLATFORM), windows)
-OTHER_CPPFLAGS += -DPROGNAME="\"$(PROGRAM)\""
-VERSION_DEFINES += -DFULL_VERSION="\"$(FULL_VERSION)\""
-else
OTHER_CPPFLAGS += -DPROGNAME='"$(PROGRAM)"'
VERSION_DEFINES += -DFULL_VERSION='"$(FULL_VERSION)"'
-endif
VERSION_DEFINES += -DJDK_MAJOR_VERSION='"$(JDK_MAJOR_VERSION)"' \
-DJDK_MINOR_VERSION='"$(JDK_MINOR_VERSION)"'
--- a/jdk/make/common/Release.gmk Wed Oct 28 16:26:52 2009 -0700
+++ b/jdk/make/common/Release.gmk Wed Oct 28 16:54:50 2009 -0700
@@ -330,7 +330,7 @@
#
# Specific files and directories that will be filtered out from above areas.
#
-SOURCE_FILTERs = $(SCM_DIRs) 'X-*' '*-X-*' '*-template.java' ',*'
+SOURCE_FILTERs = $(SCM_DIRs) ',*'
SOURCE_FILES_filter = $(SOURCE_FILTERs:%=-name % -prune -o)
#
--- a/jdk/make/common/Rules.gmk Wed Oct 28 16:26:52 2009 -0700
+++ b/jdk/make/common/Rules.gmk Wed Oct 28 16:54:50 2009 -0700
@@ -63,7 +63,7 @@
# If AUTO_FILES_PROPERTIES_DIRS used, automatically find properties files
#
ifdef AUTO_FILES_PROPERTIES_DIRS
- AUTO_FILES_PROPERTIES_FILTERS1 = $(SCM_DIRs) 'X-*' '*-X-*' ',*'
+ AUTO_FILES_PROPERTIES_FILTERS1 = $(SCM_DIRs) ',*'
AUTO_FILES_PROPERTIES_FILTERS1 += $(AUTO_PROPERTIES_PRUNE)
FILES_properties_find_filters1 = $(AUTO_FILES_PROPERTIES_FILTERS1:%=-name % -prune -o)
FILES_properties_auto1 := \
@@ -111,7 +111,7 @@
ifdef AUTO_FILES_JAVA_DIRS
# Filter out these files or directories
- AUTO_FILES_JAVA_SOURCE_FILTERS1 = $(SCM_DIRs) 'X-*' '*-X-*' '*-template.java' ',*'
+ AUTO_FILES_JAVA_SOURCE_FILTERS1 = $(SCM_DIRs) ',*'
AUTO_FILES_JAVA_SOURCE_FILTERS2 =
AUTO_FILES_JAVA_SOURCE_FILTERS1 += $(AUTO_JAVA_PRUNE)
AUTO_FILES_JAVA_SOURCE_FILTERS2 += $(AUTO_JAVA_PRUNE)
--- a/jdk/make/java/main/java/Makefile Wed Oct 28 16:26:52 2009 -0700
+++ b/jdk/make/java/main/java/Makefile Wed Oct 28 16:54:50 2009 -0700
@@ -57,7 +57,7 @@
#
include $(BUILDDIR)/common/Program.gmk
OTHER_CPPFLAGS += -DEXPAND_CLASSPATH_WILDCARDS
-OTHER_CPPFLAGS += -DLAUNCHER_NAME=\"$(LAUNCHER_NAME)\"
+OTHER_CPPFLAGS += -DLAUNCHER_NAME='"$(LAUNCHER_NAME)"'
ifeq ($(PLATFORM), solaris)
LDFLAGS += -R$(OPENWIN_LIB)
--- a/jdk/make/java/main/javaw/Makefile Wed Oct 28 16:26:52 2009 -0700
+++ b/jdk/make/java/main/javaw/Makefile Wed Oct 28 16:54:50 2009 -0700
@@ -62,4 +62,5 @@
#
include $(BUILDDIR)/common/Program.gmk
OTHER_CPPFLAGS += -DEXPAND_CLASSPATH_WILDCARDS
-OTHER_CPPFLAGS += -DLAUNCHER_NAME=\"$(LAUNCHER_NAME)\"
+OTHER_CPPFLAGS += -DLAUNCHER_NAME='"$(LAUNCHER_NAME)"'
+
--- a/jdk/make/java/nio/Makefile Wed Oct 28 16:26:52 2009 -0700
+++ b/jdk/make/java/nio/Makefile Wed Oct 28 16:54:50 2009 -0700
@@ -335,6 +335,15 @@
SCS_SRC=$(SNIO_SRC)/cs
SFS_SRC=$(SNIO_SRC)/fs
+# Template files
+HEAP_X_BUF_TEMPLATE=$(BUF_SRC)/Heap-X-Buffer.java.template
+BYTE_X_BUF_TEMPLATE=$(BUF_SRC)/ByteBufferAs-X-Buffer.java.template
+X_BUF_TEMPLATE=$(BUF_SRC)/X-Buffer.java.template
+X_BUF_BIN_TEMPLATE=$(BUF_SRC)/X-Buffer-bin.java.template
+DIRECT_X_BUF_TEMPLATE=$(BUF_SRC)/Direct-X-Buffer.java.template
+DIRECT_X_BUF_BIN_TEMPLATE=$(BUF_SRC)/Direct-X-Buffer-bin.java.template
+CHARSET_X_CODER_TEMPLATE=$(CS_SRC)/Charset-X-Coder.java.template
+
BUF_GEN=$(NIO_GEN)
CH_GEN=$(NIO_GEN)/channels
CS_GEN=$(NIO_GEN)/charset
@@ -357,39 +366,39 @@
# Public abstract buffer classes
#
-$(BUF_GEN)/ByteBuffer.java: $(BUF_SRC)/X-Buffer.java \
- $(BUF_SRC)/X-Buffer-bin.java \
+$(BUF_GEN)/ByteBuffer.java: $(X_BUF_TEMPLATE) \
+ $(X_BUF_BIN_TEMPLATE) \
$(GEN_BUFFER_SH)
$(prep-target)
@$(RM) $@.temp
TYPE=byte BIN=1 SRC=$< DST=$@.temp $(GEN_BUFFER_CMD)
$(MV) $@.temp $@
-$(BUF_GEN)/CharBuffer.java: $(BUF_SRC)/X-Buffer.java $(GEN_BUFFER_SH)
+$(BUF_GEN)/CharBuffer.java: $(X_BUF_TEMPLATE) $(GEN_BUFFER_SH)
$(prep-target)
@$(RM) $@.temp
TYPE=char SRC=$< DST=$@.temp $(GEN_BUFFER_CMD)
$(MV) $@.temp $@
-$(BUF_GEN)/ShortBuffer.java: $(BUF_SRC)/X-Buffer.java $(GEN_BUFFER_SH)
+$(BUF_GEN)/ShortBuffer.java: $(X_BUF_TEMPLATE) $(GEN_BUFFER_SH)
$(prep-target)
@$(RM) $@.temp
TYPE=short SRC=$< DST=$@.temp $(GEN_BUFFER_CMD)
$(MV) $@.temp $@
-$(BUF_GEN)/IntBuffer.java: $(BUF_SRC)/X-Buffer.java $(GEN_BUFFER_SH)
+$(BUF_GEN)/IntBuffer.java: $(X_BUF_TEMPLATE) $(GEN_BUFFER_SH)
$(prep-target)
@$(RM) $@.temp
TYPE=int SRC=$< DST=$@.temp $(GEN_BUFFER_CMD)
$(MV) $@.temp $@
-$(BUF_GEN)/LongBuffer.java: $(BUF_SRC)/X-Buffer.java $(GEN_BUFFER_SH)
+$(BUF_GEN)/LongBuffer.java: $(X_BUF_TEMPLATE) $(GEN_BUFFER_SH)
$(prep-target)
@$(RM) $@.temp
TYPE=long SRC=$< DST=$@.temp $(GEN_BUFFER_CMD)
$(MV) $@.temp $@
-$(BUF_GEN)/FloatBuffer.java: $(BUF_SRC)/X-Buffer.java $(GEN_BUFFER_SH)
+$(BUF_GEN)/FloatBuffer.java: $(X_BUF_TEMPLATE) $(GEN_BUFFER_SH)
$(prep-target)
@$(RM) $@.temp
TYPE=float SRC=$< DST=$@.temp $(GEN_BUFFER_CMD)
$(MV) $@.temp $@
-$(BUF_GEN)/DoubleBuffer.java: $(BUF_SRC)/X-Buffer.java $(GEN_BUFFER_SH)
+$(BUF_GEN)/DoubleBuffer.java: $(X_BUF_TEMPLATE) $(GEN_BUFFER_SH)
$(prep-target)
@$(RM) $@.temp
TYPE=double SRC=$< DST=$@.temp $(GEN_BUFFER_CMD)
@@ -397,72 +406,72 @@
# Buffers whose contents are heap-allocated
#
-$(BUF_GEN)/HeapByteBuffer.java: $(BUF_SRC)/Heap-X-Buffer.java $(GEN_BUFFER_SH)
+$(BUF_GEN)/HeapByteBuffer.java: $(HEAP_X_BUF_TEMPLATE) $(GEN_BUFFER_SH)
$(prep-target)
@$(RM) $@.temp
TYPE=byte SRC=$< DST=$@.temp $(GEN_BUFFER_CMD)
$(MV) $@.temp $@
-$(BUF_GEN)/HeapByteBuffer%.java: $(BUF_SRC)/Heap-X-Buffer.java $(GEN_BUFFER_SH)
+$(BUF_GEN)/HeapByteBuffer%.java: $(HEAP_X_BUF_TEMPLATE) $(GEN_BUFFER_SH)
$(prep-target)
@$(RM) $@.temp
TYPE=byte RW=$* SRC=$< DST=$@.temp $(GEN_BUFFER_CMD)
$(MV) $@.temp $@
-$(BUF_GEN)/HeapCharBuffer.java: $(BUF_SRC)/Heap-X-Buffer.java $(GEN_BUFFER_SH)
+$(BUF_GEN)/HeapCharBuffer.java: $(HEAP_X_BUF_TEMPLATE) $(GEN_BUFFER_SH)
$(prep-target)
@$(RM) $@.temp
TYPE=char SRC=$< DST=$@.temp $(GEN_BUFFER_CMD)
$(MV) $@.temp $@
-$(BUF_GEN)/HeapCharBuffer%.java: $(BUF_SRC)/Heap-X-Buffer.java $(GEN_BUFFER_SH)
+$(BUF_GEN)/HeapCharBuffer%.java: $(HEAP_X_BUF_TEMPLATE) $(GEN_BUFFER_SH)
$(prep-target)
@$(RM) $@.temp
TYPE=char RW=$* SRC=$< DST=$@.temp $(GEN_BUFFER_CMD)
$(MV) $@.temp $@
-$(BUF_GEN)/HeapShortBuffer.java: $(BUF_SRC)/Heap-X-Buffer.java $(GEN_BUFFER_SH)
+$(BUF_GEN)/HeapShortBuffer.java: $(HEAP_X_BUF_TEMPLATE) $(GEN_BUFFER_SH)
$(prep-target)
@$(RM) $@.temp
TYPE=short SRC=$< DST=$@.temp $(GEN_BUFFER_CMD)
$(MV) $@.temp $@
-$(BUF_GEN)/HeapShortBuffer%.java: $(BUF_SRC)/Heap-X-Buffer.java $(GEN_BUFFER_SH)
+$(BUF_GEN)/HeapShortBuffer%.java: $(HEAP_X_BUF_TEMPLATE) $(GEN_BUFFER_SH)
$(prep-target)
@$(RM) $@.temp
TYPE=short RW=$* SRC=$< DST=$@.temp $(GEN_BUFFER_CMD)
$(MV) $@.temp $@
-$(BUF_GEN)/HeapIntBuffer.java: $(BUF_SRC)/Heap-X-Buffer.java $(GEN_BUFFER_SH)
+$(BUF_GEN)/HeapIntBuffer.java: $(HEAP_X_BUF_TEMPLATE) $(GEN_BUFFER_SH)
$(prep-target)
@$(RM) $@.temp
TYPE=int SRC=$< DST=$@.temp $(GEN_BUFFER_CMD)
$(MV) $@.temp $@
-$(BUF_GEN)/HeapIntBuffer%.java: $(BUF_SRC)/Heap-X-Buffer.java $(GEN_BUFFER_SH)
+$(BUF_GEN)/HeapIntBuffer%.java: $(HEAP_X_BUF_TEMPLATE) $(GEN_BUFFER_SH)
$(prep-target)
@$(RM) $@.temp
TYPE=int RW=$* SRC=$< DST=$@.temp $(GEN_BUFFER_CMD)
$(MV) $@.temp $@
-$(BUF_GEN)/HeapLongBuffer.java: $(BUF_SRC)/Heap-X-Buffer.java $(GEN_BUFFER_SH)
+$(BUF_GEN)/HeapLongBuffer.java: $(HEAP_X_BUF_TEMPLATE) $(GEN_BUFFER_SH)
$(prep-target)
@$(RM) $@.temp
TYPE=long SRC=$< DST=$@.temp $(GEN_BUFFER_CMD)
$(MV) $@.temp $@
-$(BUF_GEN)/HeapLongBuffer%.java: $(BUF_SRC)/Heap-X-Buffer.java $(GEN_BUFFER_SH)
+$(BUF_GEN)/HeapLongBuffer%.java: $(HEAP_X_BUF_TEMPLATE) $(GEN_BUFFER_SH)
$(prep-target)
@$(RM) $@.temp
TYPE=long RW=$* SRC=$< DST=$@.temp $(GEN_BUFFER_CMD)
$(MV) $@.temp $@
-$(BUF_GEN)/HeapFloatBuffer.java: $(BUF_SRC)/Heap-X-Buffer.java $(GEN_BUFFER_SH)
+$(BUF_GEN)/HeapFloatBuffer.java: $(HEAP_X_BUF_TEMPLATE) $(GEN_BUFFER_SH)
$(prep-target)
@$(RM) $@.temp
TYPE=float SRC=$< DST=$@.temp $(GEN_BUFFER_CMD)
$(MV) $@.temp $@
-$(BUF_GEN)/HeapFloatBuffer%.java: $(BUF_SRC)/Heap-X-Buffer.java $(GEN_BUFFER_SH)
+$(BUF_GEN)/HeapFloatBuffer%.java: $(HEAP_X_BUF_TEMPLATE) $(GEN_BUFFER_SH)
$(prep-target)
@$(RM) $@.temp
TYPE=float RW=$* SRC=$< DST=$@.temp $(GEN_BUFFER_CMD)
$(MV) $@.temp $@
-$(BUF_GEN)/HeapDoubleBuffer.java: $(BUF_SRC)/Heap-X-Buffer.java $(GEN_BUFFER_SH)
+$(BUF_GEN)/HeapDoubleBuffer.java: $(HEAP_X_BUF_TEMPLATE) $(GEN_BUFFER_SH)
$(prep-target)
@$(RM) $@.temp
TYPE=double SRC=$< DST=$@.temp $(GEN_BUFFER_CMD)
$(MV) $@.temp $@
-$(BUF_GEN)/HeapDoubleBuffer%.java: $(BUF_SRC)/Heap-X-Buffer.java $(GEN_BUFFER_SH)
+$(BUF_GEN)/HeapDoubleBuffer%.java: $(HEAP_X_BUF_TEMPLATE) $(GEN_BUFFER_SH)
$(prep-target)
@$(RM) $@.temp
TYPE=double RW=$* SRC=$< DST=$@.temp $(GEN_BUFFER_CMD)
@@ -470,15 +479,15 @@
# Direct byte buffer
#
-$(BUF_GEN)/DirectByteBuffer.java: $(BUF_SRC)/Direct-X-Buffer.java \
- $(BUF_SRC)/Direct-X-Buffer.java \
+$(BUF_GEN)/DirectByteBuffer.java: $(DIRECT_X_BUF_TEMPLATE) \
+ $(DIRECT_X_BUF_TEMPLATE) \
$(GEN_BUFFER_SH)
$(prep-target)
@$(RM) $@.temp
TYPE=byte BIN=1 SRC=$< DST=$@.temp $(GEN_BUFFER_CMD)
$(MV) $@.temp $@
-$(BUF_GEN)/DirectByteBuffer%.java: $(BUF_SRC)/Direct-X-Buffer.java \
- $(BUF_SRC)/Direct-X-Buffer.java \
+$(BUF_GEN)/DirectByteBuffer%.java: $(DIRECT_X_BUF_TEMPLATE) \
+ $(DIRECT_X_BUF_TEMPLATE) \
$(GEN_BUFFER_SH)
$(prep-target)
@$(RM) $@.temp
@@ -487,62 +496,62 @@
# Unswapped views of direct byte buffers
#
-$(BUF_GEN)/DirectCharBufferU.java: $(BUF_SRC)/Direct-X-Buffer.java $(GEN_BUFFER_SH)
+$(BUF_GEN)/DirectCharBufferU.java: $(DIRECT_X_BUF_TEMPLATE) $(GEN_BUFFER_SH)
$(prep-target)
@$(RM) $@.temp
TYPE=char BO=U SRC=$< DST=$@.temp $(GEN_BUFFER_CMD)
$(MV) $@.temp $@
-$(BUF_GEN)/DirectCharBuffer%U.java: $(BUF_SRC)/Direct-X-Buffer.java $(GEN_BUFFER_SH)
+$(BUF_GEN)/DirectCharBuffer%U.java: $(DIRECT_X_BUF_TEMPLATE) $(GEN_BUFFER_SH)
$(prep-target)
@$(RM) $@.temp
TYPE=char RW=$* BO=U SRC=$< DST=$@.temp $(GEN_BUFFER_CMD)
$(MV) $@.temp $@
-$(BUF_GEN)/DirectShortBufferU.java: $(BUF_SRC)/Direct-X-Buffer.java $(GEN_BUFFER_SH)
+$(BUF_GEN)/DirectShortBufferU.java: $(DIRECT_X_BUF_TEMPLATE) $(GEN_BUFFER_SH)
$(prep-target)
@$(RM) $@.temp
TYPE=short BO=U SRC=$< DST=$@.temp $(GEN_BUFFER_CMD)
$(MV) $@.temp $@
-$(BUF_GEN)/DirectShortBuffer%U.java: $(BUF_SRC)/Direct-X-Buffer.java $(GEN_BUFFER_SH)
+$(BUF_GEN)/DirectShortBuffer%U.java: $(DIRECT_X_BUF_TEMPLATE) $(GEN_BUFFER_SH)
$(prep-target)
@$(RM) $@.temp
TYPE=short RW=$* BO=U SRC=$< DST=$@.temp $(GEN_BUFFER_CMD)
$(MV) $@.temp $@
-$(BUF_GEN)/DirectIntBufferU.java: $(BUF_SRC)/Direct-X-Buffer.java $(GEN_BUFFER_SH)
+$(BUF_GEN)/DirectIntBufferU.java: $(DIRECT_X_BUF_TEMPLATE) $(GEN_BUFFER_SH)
$(prep-target)
@$(RM) $@.temp
TYPE=int BO=U SRC=$< DST=$@.temp $(GEN_BUFFER_CMD)
$(MV) $@.temp $@
-$(BUF_GEN)/DirectIntBuffer%U.java: $(BUF_SRC)/Direct-X-Buffer.java $(GEN_BUFFER_SH)
+$(BUF_GEN)/DirectIntBuffer%U.java: $(DIRECT_X_BUF_TEMPLATE) $(GEN_BUFFER_SH)
$(prep-target)
@$(RM) $@.temp
TYPE=int RW=$* BO=U SRC=$< DST=$@.temp $(GEN_BUFFER_CMD)
$(MV) $@.temp $@
-$(BUF_GEN)/DirectLongBufferU.java: $(BUF_SRC)/Direct-X-Buffer.java $(GEN_BUFFER_SH)
+$(BUF_GEN)/DirectLongBufferU.java: $(DIRECT_X_BUF_TEMPLATE) $(GEN_BUFFER_SH)
$(prep-target)
@$(RM) $@.temp
TYPE=long BO=U SRC=$< DST=$@.temp $(GEN_BUFFER_CMD)
$(MV) $@.temp $@
-$(BUF_GEN)/DirectLongBuffer%U.java: $(BUF_SRC)/Direct-X-Buffer.java $(GEN_BUFFER_SH)
+$(BUF_GEN)/DirectLongBuffer%U.java: $(DIRECT_X_BUF_TEMPLATE) $(GEN_BUFFER_SH)
$(prep-target)
@$(RM) $@.temp
TYPE=long RW=$* BO=U SRC=$< DST=$@.temp $(GEN_BUFFER_CMD)
$(MV) $@.temp $@
-$(BUF_GEN)/DirectFloatBufferU.java: $(BUF_SRC)/Direct-X-Buffer.java $(GEN_BUFFER_SH)
+$(BUF_GEN)/DirectFloatBufferU.java: $(DIRECT_X_BUF_TEMPLATE) $(GEN_BUFFER_SH)
$(prep-target)
@$(RM) $@.temp
TYPE=float BO=U SRC=$< DST=$@.temp $(GEN_BUFFER_CMD)
$(MV) $@.temp $@
-$(BUF_GEN)/DirectFloatBuffer%U.java: $(BUF_SRC)/Direct-X-Buffer.java $(GEN_BUFFER_SH)
+$(BUF_GEN)/DirectFloatBuffer%U.java: $(DIRECT_X_BUF_TEMPLATE) $(GEN_BUFFER_SH)
$(prep-target)
@$(RM) $@.temp
TYPE=float RW=$* BO=U SRC=$< DST=$@.temp $(GEN_BUFFER_CMD)
$(MV) $@.temp $@
-$(BUF_GEN)/DirectDoubleBufferU.java: $(BUF_SRC)/Direct-X-Buffer.java $(GEN_BUFFER_SH)
+$(BUF_GEN)/DirectDoubleBufferU.java: $(DIRECT_X_BUF_TEMPLATE) $(GEN_BUFFER_SH)
$(prep-target)
@$(RM) $@.temp
TYPE=double BO=U SRC=$< DST=$@.temp $(GEN_BUFFER_CMD)
$(MV) $@.temp $@
-$(BUF_GEN)/DirectDoubleBuffer%U.java: $(BUF_SRC)/Direct-X-Buffer.java $(GEN_BUFFER_SH)
+$(BUF_GEN)/DirectDoubleBuffer%U.java: $(DIRECT_X_BUF_TEMPLATE) $(GEN_BUFFER_SH)
$(prep-target)
@$(RM) $@.temp
TYPE=double RW=$* BO=U SRC=$< DST=$@.temp $(GEN_BUFFER_CMD)
@@ -550,62 +559,62 @@
# Swapped views of direct byte buffers
#
-$(BUF_GEN)/DirectCharBufferS.java: $(BUF_SRC)/Direct-X-Buffer.java $(GEN_BUFFER_SH)
+$(BUF_GEN)/DirectCharBufferS.java: $(DIRECT_X_BUF_TEMPLATE) $(GEN_BUFFER_SH)
$(prep-target)
@$(RM) $@.temp
TYPE=char BO=S SRC=$< DST=$@.temp $(GEN_BUFFER_CMD)
$(MV) $@.temp $@
-$(BUF_GEN)/DirectCharBuffer%S.java: $(BUF_SRC)/Direct-X-Buffer.java $(GEN_BUFFER_SH)
+$(BUF_GEN)/DirectCharBuffer%S.java: $(DIRECT_X_BUF_TEMPLATE) $(GEN_BUFFER_SH)
$(prep-target)
@$(RM) $@.temp
TYPE=char RW=$* BO=S SRC=$< DST=$@.temp $(GEN_BUFFER_CMD)
$(MV) $@.temp $@
-$(BUF_GEN)/DirectShortBufferS.java: $(BUF_SRC)/Direct-X-Buffer.java $(GEN_BUFFER_SH)
+$(BUF_GEN)/DirectShortBufferS.java: $(DIRECT_X_BUF_TEMPLATE) $(GEN_BUFFER_SH)
$(prep-target)
@$(RM) $@.temp
TYPE=short BO=S SRC=$< DST=$@.temp $(GEN_BUFFER_CMD)
$(MV) $@.temp $@
-$(BUF_GEN)/DirectShortBuffer%S.java: $(BUF_SRC)/Direct-X-Buffer.java $(GEN_BUFFER_SH)
+$(BUF_GEN)/DirectShortBuffer%S.java: $(DIRECT_X_BUF_TEMPLATE) $(GEN_BUFFER_SH)
$(prep-target)
@$(RM) $@.temp
TYPE=short RW=$* BO=S SRC=$< DST=$@.temp $(GEN_BUFFER_CMD)
$(MV) $@.temp $@
-$(BUF_GEN)/DirectIntBufferS.java: $(BUF_SRC)/Direct-X-Buffer.java $(GEN_BUFFER_SH)
+$(BUF_GEN)/DirectIntBufferS.java: $(DIRECT_X_BUF_TEMPLATE) $(GEN_BUFFER_SH)
$(prep-target)
@$(RM) $@.temp
TYPE=int BO=S SRC=$< DST=$@.temp $(GEN_BUFFER_CMD)
$(MV) $@.temp $@
-$(BUF_GEN)/DirectIntBuffer%S.java: $(BUF_SRC)/Direct-X-Buffer.java $(GEN_BUFFER_SH)
+$(BUF_GEN)/DirectIntBuffer%S.java: $(DIRECT_X_BUF_TEMPLATE) $(GEN_BUFFER_SH)
$(prep-target)
@$(RM) $@.temp
TYPE=int RW=$* BO=S SRC=$< DST=$@.temp $(GEN_BUFFER_CMD)
$(MV) $@.temp $@
-$(BUF_GEN)/DirectLongBufferS.java: $(BUF_SRC)/Direct-X-Buffer.java $(GEN_BUFFER_SH)
+$(BUF_GEN)/DirectLongBufferS.java: $(DIRECT_X_BUF_TEMPLATE) $(GEN_BUFFER_SH)
$(prep-target)
@$(RM) $@.temp
TYPE=long BO=S SRC=$< DST=$@.temp $(GEN_BUFFER_CMD)
$(MV) $@.temp $@
-$(BUF_GEN)/DirectLongBuffer%S.java: $(BUF_SRC)/Direct-X-Buffer.java $(GEN_BUFFER_SH)
+$(BUF_GEN)/DirectLongBuffer%S.java: $(DIRECT_X_BUF_TEMPLATE) $(GEN_BUFFER_SH)
$(prep-target)
@$(RM) $@.temp
TYPE=long RW=$* BO=S SRC=$< DST=$@.temp $(GEN_BUFFER_CMD)
$(MV) $@.temp $@
-$(BUF_GEN)/DirectFloatBufferS.java: $(BUF_SRC)/Direct-X-Buffer.java $(GEN_BUFFER_SH)
+$(BUF_GEN)/DirectFloatBufferS.java: $(DIRECT_X_BUF_TEMPLATE) $(GEN_BUFFER_SH)
$(prep-target)
@$(RM) $@.temp
TYPE=float BO=S SRC=$< DST=$@.temp $(GEN_BUFFER_CMD)
$(MV) $@.temp $@
-$(BUF_GEN)/DirectFloatBuffer%S.java: $(BUF_SRC)/Direct-X-Buffer.java $(GEN_BUFFER_SH)
+$(BUF_GEN)/DirectFloatBuffer%S.java: $(DIRECT_X_BUF_TEMPLATE) $(GEN_BUFFER_SH)
$(prep-target)
@$(RM) $@.temp
TYPE=float RW=$* BO=S SRC=$< DST=$@.temp $(GEN_BUFFER_CMD)
$(MV) $@.temp $@
-$(BUF_GEN)/DirectDoubleBufferS.java: $(BUF_SRC)/Direct-X-Buffer.java $(GEN_BUFFER_SH)
+$(BUF_GEN)/DirectDoubleBufferS.java: $(DIRECT_X_BUF_TEMPLATE) $(GEN_BUFFER_SH)
$(prep-target)
@$(RM) $@.temp
TYPE=double BO=S SRC=$< DST=$@.temp $(GEN_BUFFER_CMD)
$(MV) $@.temp $@
-$(BUF_GEN)/DirectDoubleBuffer%S.java: $(BUF_SRC)/Direct-X-Buffer.java $(GEN_BUFFER_SH)
+$(BUF_GEN)/DirectDoubleBuffer%S.java: $(DIRECT_X_BUF_TEMPLATE) $(GEN_BUFFER_SH)
$(prep-target)
@$(RM) $@.temp
TYPE=double RW=$* BO=S SRC=$< DST=$@.temp $(GEN_BUFFER_CMD)
@@ -613,62 +622,62 @@
# Big-endian views of byte buffers
#
-$(BUF_GEN)/ByteBufferAsCharBufferB.java: $(BUF_SRC)/ByteBufferAs-X-Buffer.java $(GEN_BUFFER_SH)
+$(BUF_GEN)/ByteBufferAsCharBufferB.java: $(BYTE_X_BUF_TEMPLATE) $(GEN_BUFFER_SH)
$(prep-target)
@$(RM) $@.temp
TYPE=char BO=B SRC=$< DST=$@.temp $(GEN_BUFFER_CMD)
$(MV) $@.temp $@
-$(BUF_GEN)/ByteBufferAsCharBuffer%B.java: $(BUF_SRC)/ByteBufferAs-X-Buffer.java $(GEN_BUFFER_SH)
+$(BUF_GEN)/ByteBufferAsCharBuffer%B.java: $(BYTE_X_BUF_TEMPLATE) $(GEN_BUFFER_SH)
$(prep-target)
@$(RM) $@.temp
TYPE=char RW=$* BO=B SRC=$< DST=$@.temp $(GEN_BUFFER_CMD)
$(MV) $@.temp $@
-$(BUF_GEN)/ByteBufferAsShortBufferB.java: $(BUF_SRC)/ByteBufferAs-X-Buffer.java $(GEN_BUFFER_SH)
+$(BUF_GEN)/ByteBufferAsShortBufferB.java: $(BYTE_X_BUF_TEMPLATE) $(GEN_BUFFER_SH)
$(prep-target)
@$(RM) $@.temp
TYPE=short BO=B SRC=$< DST=$@.temp $(GEN_BUFFER_CMD)
$(MV) $@.temp $@
-$(BUF_GEN)/ByteBufferAsShortBuffer%B.java: $(BUF_SRC)/ByteBufferAs-X-Buffer.java $(GEN_BUFFER_SH)
+$(BUF_GEN)/ByteBufferAsShortBuffer%B.java: $(BYTE_X_BUF_TEMPLATE) $(GEN_BUFFER_SH)
$(prep-target)
@$(RM) $@.temp
TYPE=short RW=$* BO=B SRC=$< DST=$@.temp $(GEN_BUFFER_CMD)
$(MV) $@.temp $@
-$(BUF_GEN)/ByteBufferAsIntBufferB.java: $(BUF_SRC)/ByteBufferAs-X-Buffer.java $(GEN_BUFFER_SH)
+$(BUF_GEN)/ByteBufferAsIntBufferB.java: $(BYTE_X_BUF_TEMPLATE) $(GEN_BUFFER_SH)
$(prep-target)
@$(RM) $@.temp
TYPE=int BO=B SRC=$< DST=$@.temp $(GEN_BUFFER_CMD)
$(MV) $@.temp $@
-$(BUF_GEN)/ByteBufferAsIntBuffer%B.java: $(BUF_SRC)/ByteBufferAs-X-Buffer.java $(GEN_BUFFER_SH)
+$(BUF_GEN)/ByteBufferAsIntBuffer%B.java: $(BYTE_X_BUF_TEMPLATE) $(GEN_BUFFER_SH)
$(prep-target)
@$(RM) $@.temp
TYPE=int RW=$* BO=B SRC=$< DST=$@.temp $(GEN_BUFFER_CMD)
$(MV) $@.temp $@
-$(BUF_GEN)/ByteBufferAsLongBufferB.java: $(BUF_SRC)/ByteBufferAs-X-Buffer.java $(GEN_BUFFER_SH)
+$(BUF_GEN)/ByteBufferAsLongBufferB.java: $(BYTE_X_BUF_TEMPLATE) $(GEN_BUFFER_SH)
$(prep-target)
@$(RM) $@.temp
TYPE=long BO=B SRC=$< DST=$@.temp $(GEN_BUFFER_CMD)
$(MV) $@.temp $@
-$(BUF_GEN)/ByteBufferAsLongBuffer%B.java: $(BUF_SRC)/ByteBufferAs-X-Buffer.java $(GEN_BUFFER_SH)
+$(BUF_GEN)/ByteBufferAsLongBuffer%B.java: $(BYTE_X_BUF_TEMPLATE) $(GEN_BUFFER_SH)
$(prep-target)
@$(RM) $@.temp
TYPE=long RW=$* BO=B SRC=$< DST=$@.temp $(GEN_BUFFER_CMD)
$(MV) $@.temp $@
-$(BUF_GEN)/ByteBufferAsFloatBufferB.java: $(BUF_SRC)/ByteBufferAs-X-Buffer.java $(GEN_BUFFER_SH)
+$(BUF_GEN)/ByteBufferAsFloatBufferB.java: $(BYTE_X_BUF_TEMPLATE) $(GEN_BUFFER_SH)
$(prep-target)
@$(RM) $@.temp
TYPE=float BO=B SRC=$< DST=$@.temp $(GEN_BUFFER_CMD)
$(MV) $@.temp $@
-$(BUF_GEN)/ByteBufferAsFloatBuffer%B.java: $(BUF_SRC)/ByteBufferAs-X-Buffer.java $(GEN_BUFFER_SH)
+$(BUF_GEN)/ByteBufferAsFloatBuffer%B.java: $(BYTE_X_BUF_TEMPLATE) $(GEN_BUFFER_SH)
$(prep-target)
@$(RM) $@.temp
TYPE=float RW=$* BO=B SRC=$< DST=$@.temp $(GEN_BUFFER_CMD)
$(MV) $@.temp $@
-$(BUF_GEN)/ByteBufferAsDoubleBufferB.java: $(BUF_SRC)/ByteBufferAs-X-Buffer.java $(GEN_BUFFER_SH)
+$(BUF_GEN)/ByteBufferAsDoubleBufferB.java: $(BYTE_X_BUF_TEMPLATE) $(GEN_BUFFER_SH)
$(prep-target)
@$(RM) $@.temp
TYPE=double BO=B SRC=$< DST=$@.temp $(GEN_BUFFER_CMD)
$(MV) $@.temp $@
-$(BUF_GEN)/ByteBufferAsDoubleBuffer%B.java: $(BUF_SRC)/ByteBufferAs-X-Buffer.java $(GEN_BUFFER_SH)
+$(BUF_GEN)/ByteBufferAsDoubleBuffer%B.java: $(BYTE_X_BUF_TEMPLATE) $(GEN_BUFFER_SH)
$(prep-target)
@$(RM) $@.temp
TYPE=double RW=$* BO=B SRC=$< DST=$@.temp $(GEN_BUFFER_CMD)
@@ -676,62 +685,62 @@
# Little-endian views of byte buffers
#
-$(BUF_GEN)/ByteBufferAsCharBufferL.java: $(BUF_SRC)/ByteBufferAs-X-Buffer.java $(GEN_BUFFER_SH)
+$(BUF_GEN)/ByteBufferAsCharBufferL.java: $(BYTE_X_BUF_TEMPLATE) $(GEN_BUFFER_SH)
$(prep-target)
@$(RM) $@.temp
TYPE=char BO=L SRC=$< DST=$@.temp $(GEN_BUFFER_CMD)
$(MV) $@.temp $@
-$(BUF_GEN)/ByteBufferAsCharBuffer%L.java: $(BUF_SRC)/ByteBufferAs-X-Buffer.java $(GEN_BUFFER_SH)
+$(BUF_GEN)/ByteBufferAsCharBuffer%L.java: $(BYTE_X_BUF_TEMPLATE) $(GEN_BUFFER_SH)
$(prep-target)
@$(RM) $@.temp
TYPE=char RW=$* BO=L SRC=$< DST=$@.temp $(GEN_BUFFER_CMD)
$(MV) $@.temp $@
-$(BUF_GEN)/ByteBufferAsShortBufferL.java: $(BUF_SRC)/ByteBufferAs-X-Buffer.java $(GEN_BUFFER_SH)
+$(BUF_GEN)/ByteBufferAsShortBufferL.java: $(BYTE_X_BUF_TEMPLATE) $(GEN_BUFFER_SH)
$(prep-target)
@$(RM) $@.temp
TYPE=short BO=L SRC=$< DST=$@.temp $(GEN_BUFFER_CMD)
$(MV) $@.temp $@
-$(BUF_GEN)/ByteBufferAsShortBuffer%L.java: $(BUF_SRC)/ByteBufferAs-X-Buffer.java $(GEN_BUFFER_SH)
+$(BUF_GEN)/ByteBufferAsShortBuffer%L.java: $(BYTE_X_BUF_TEMPLATE) $(GEN_BUFFER_SH)
$(prep-target)
@$(RM) $@.temp
TYPE=short RW=$* BO=L SRC=$< DST=$@.temp $(GEN_BUFFER_CMD)
$(MV) $@.temp $@
-$(BUF_GEN)/ByteBufferAsIntBufferL.java: $(BUF_SRC)/ByteBufferAs-X-Buffer.java $(GEN_BUFFER_SH)
+$(BUF_GEN)/ByteBufferAsIntBufferL.java: $(BYTE_X_BUF_TEMPLATE) $(GEN_BUFFER_SH)
$(prep-target)
@$(RM) $@.temp
TYPE=int BO=L SRC=$< DST=$@.temp $(GEN_BUFFER_CMD)
$(MV) $@.temp $@
-$(BUF_GEN)/ByteBufferAsIntBuffer%L.java: $(BUF_SRC)/ByteBufferAs-X-Buffer.java $(GEN_BUFFER_SH)
+$(BUF_GEN)/ByteBufferAsIntBuffer%L.java: $(BYTE_X_BUF_TEMPLATE) $(GEN_BUFFER_SH)
$(prep-target)
@$(RM) $@.temp
TYPE=int RW=$* BO=L SRC=$< DST=$@.temp $(GEN_BUFFER_CMD)
$(MV) $@.temp $@
-$(BUF_GEN)/ByteBufferAsLongBufferL.java: $(BUF_SRC)/ByteBufferAs-X-Buffer.java $(GEN_BUFFER_SH)
+$(BUF_GEN)/ByteBufferAsLongBufferL.java: $(BYTE_X_BUF_TEMPLATE) $(GEN_BUFFER_SH)
$(prep-target)
@$(RM) $@.temp
TYPE=long BO=L SRC=$< DST=$@.temp $(GEN_BUFFER_CMD)
$(MV) $@.temp $@
-$(BUF_GEN)/ByteBufferAsLongBuffer%L.java: $(BUF_SRC)/ByteBufferAs-X-Buffer.java $(GEN_BUFFER_SH)
+$(BUF_GEN)/ByteBufferAsLongBuffer%L.java: $(BYTE_X_BUF_TEMPLATE) $(GEN_BUFFER_SH)
$(prep-target)
@$(RM) $@.temp
TYPE=long RW=$* BO=L SRC=$< DST=$@.temp $(GEN_BUFFER_CMD)
$(MV) $@.temp $@
-$(BUF_GEN)/ByteBufferAsFloatBufferL.java: $(BUF_SRC)/ByteBufferAs-X-Buffer.java $(GEN_BUFFER_SH)
+$(BUF_GEN)/ByteBufferAsFloatBufferL.java: $(BYTE_X_BUF_TEMPLATE) $(GEN_BUFFER_SH)
$(prep-target)
@$(RM) $@.temp
TYPE=float BO=L SRC=$< DST=$@.temp $(GEN_BUFFER_CMD)
$(MV) $@.temp $@
-$(BUF_GEN)/ByteBufferAsFloatBuffer%L.java: $(BUF_SRC)/ByteBufferAs-X-Buffer.java $(GEN_BUFFER_SH)
+$(BUF_GEN)/ByteBufferAsFloatBuffer%L.java: $(BYTE_X_BUF_TEMPLATE) $(GEN_BUFFER_SH)
$(prep-target)
@$(RM) $@.temp
TYPE=float RW=$* BO=L SRC=$< DST=$@.temp $(GEN_BUFFER_CMD)
$(MV) $@.temp $@
-$(BUF_GEN)/ByteBufferAsDoubleBufferL.java: $(BUF_SRC)/ByteBufferAs-X-Buffer.java $(GEN_BUFFER_SH)
+$(BUF_GEN)/ByteBufferAsDoubleBufferL.java: $(BYTE_X_BUF_TEMPLATE) $(GEN_BUFFER_SH)
$(prep-target)
@$(RM) $@.temp
TYPE=double BO=L SRC=$< DST=$@.temp $(GEN_BUFFER_CMD)
$(MV) $@.temp $@
-$(BUF_GEN)/ByteBufferAsDoubleBuffer%L.java: $(BUF_SRC)/ByteBufferAs-X-Buffer.java $(GEN_BUFFER_SH)
+$(BUF_GEN)/ByteBufferAsDoubleBuffer%L.java: $(BYTE_X_BUF_TEMPLATE) $(GEN_BUFFER_SH)
$(prep-target)
@$(RM) $@.temp
TYPE=double RW=$* BO=L SRC=$< DST=$@.temp $(GEN_BUFFER_CMD)
@@ -745,13 +754,13 @@
GEN_CODER_CMD = SPP="$(SPP_CMD)" SED="$(SED)" NAWK="$(NAWK)" SH="$(SH)" $(SH) $(GEN_CODER_SH)
-$(CS_GEN)/CharsetDecoder.java: $(CS_SRC)/Charset-X-Coder.java $(GEN_CODER_SH)
+$(CS_GEN)/CharsetDecoder.java: $(CHARSET_X_CODER_TEMPLATE) $(GEN_CODER_SH)
$(prep-target)
@$(RM) $@.temp
$(GEN_CODER_CMD) decoder $< $@.temp
$(MV) $@.temp $@
-$(CS_GEN)/CharsetEncoder.java: $(CS_SRC)/Charset-X-Coder.java $(GEN_CODER_SH)
+$(CS_GEN)/CharsetEncoder.java: $(CHARSET_X_CODER_TEMPLATE) $(GEN_CODER_SH)
$(prep-target)
@$(RM) $@.temp
$(GEN_CODER_CMD) encoder $< $@.temp
--- a/jdk/make/java/nio/genBuffer.sh Wed Oct 28 16:26:52 2009 -0700
+++ b/jdk/make/java/nio/genBuffer.sh Wed Oct 28 16:54:50 2009 -0700
@@ -154,7 +154,7 @@
mv $DST $DST.tmp
sed -e '/#BIN/,$d' <$DST.tmp >$DST
rm -f $DST.tmp
- binops=`dirname $SRC`/`basename $SRC .java`-bin.java
+ binops=`dirname $SRC`/`basename $SRC .java.template`-bin.java.template
genBinOps char character 1 two one $binops >>$DST
genBinOps short short 1 two one $binops >>$DST
genBinOps int integer 2 four three $binops >>$DST
--- a/jdk/make/java/version/Makefile Wed Oct 28 16:26:52 2009 -0700
+++ b/jdk/make/java/version/Makefile Wed Oct 28 16:54:50 2009 -0700
@@ -33,7 +33,7 @@
all build: $(GENSRCDIR)/sun/misc/Version.java
$(GENSRCDIR)/sun/misc/Version.java: \
- $(SHARE_SRC)/classes/sun/misc/Version-template.java
+ $(SHARE_SRC)/classes/sun/misc/Version.java.template
$(prep-target)
$(RM) $@.temp
$(SED) -e 's/@@launcher_name@@/$(LAUNCHER_NAME)/g' \
--- a/jdk/make/javax/sound/Makefile Wed Oct 28 16:26:52 2009 -0700
+++ b/jdk/make/javax/sound/Makefile Wed Oct 28 16:54:50 2009 -0700
@@ -128,7 +128,7 @@
# for dynamic inclusion of extra sound libs: these
# JNI libs will be loaded from Platform.java
-CPPFLAGS += -DEXTRA_SOUND_JNI_LIBS="\"$(EXTRA_SOUND_JNI_LIBS)\""
+CPPFLAGS += -DEXTRA_SOUND_JNI_LIBS='"$(EXTRA_SOUND_JNI_LIBS)"'
# integrate MIDI i/o in jsound lib
ifeq ($(INCLUDE_MIDI),TRUE)
--- a/jdk/make/launchers/Makefile.launcher Wed Oct 28 16:26:52 2009 -0700
+++ b/jdk/make/launchers/Makefile.launcher Wed Oct 28 16:54:50 2009 -0700
@@ -137,15 +137,15 @@
# PROGRAM, JAVA_ARGS, and APP_CLASSPATH are used in src/share/bin/java.c
# SA is currently not available on windows (for any ARCH), or linux-ia64:
ifneq ($(ARCH), ia64)
- JDB_CLASSPATH = "{ \"/lib/tools.jar\", \"/lib/sa-jdi.jar\", \"/classes\" }"
- OTHER_CPPFLAGS += -DAPP_CLASSPATH=$(JDB_CLASSPATH)
+ JDB_CLASSPATH = { "/lib/tools.jar", "/lib/sa-jdi.jar", "/classes" }
+ OTHER_CPPFLAGS += -DAPP_CLASSPATH='$(JDB_CLASSPATH)'
endif
endif
# jconsole only
ifeq ($(PROGRAM),jconsole)
- JCONSOLE_CLASSPATH = "{ \"/lib/jconsole.jar\", \"/lib/tools.jar\", \"/classes\" }"
- OTHER_CPPFLAGS += -DAPP_CLASSPATH=$(JCONSOLE_CLASSPATH)
+ JCONSOLE_CLASSPATH = { "/lib/jconsole.jar", "/lib/tools.jar", "/classes" }
+ OTHER_CPPFLAGS += -DAPP_CLASSPATH='$(JCONSOLE_CLASSPATH)'
ifeq ($(PLATFORM), windows)
OTHER_CPPFLAGS += -DJAVAW
LDLIBS_COMMON += user32.lib
@@ -163,8 +163,8 @@
# SA tools need special app classpath
ifeq ($(SA_TOOL),true)
- SA_CLASSPATH = "{ \"/lib/tools.jar\", \"/lib/sa-jdi.jar\", \"/classes\"}"
- OTHER_CPPFLAGS += -DAPP_CLASSPATH=$(SA_CLASSPATH)
+ SA_CLASSPATH = { "/lib/tools.jar", "/lib/sa-jdi.jar", "/classes" }
+ OTHER_CPPFLAGS += -DAPP_CLASSPATH='$(SA_CLASSPATH)'
endif
# Wildcards
@@ -173,11 +173,11 @@
endif
# Always tell native code what the main class is
-OTHER_CPPFLAGS += -DMAIN_CLASS=\"$(MAIN_CLASS)\"
+OTHER_CPPFLAGS += -DMAIN_CLASS='"$(MAIN_CLASS)"'
# Construct initializer for initial arguments to java
ALL_ARGS = -J-ms8m $(MAIN_JAVA_ARGS) $(MAIN_CLASS) $(MAIN_ARGS)
-JAVA_ARGS = "{ $(ALL_ARGS:%=\"%\",) }"
+JAVA_ARGS = { $(ALL_ARGS:%="%",) }
# Always report launcher info
build: launcher_info
--- a/jdk/make/netbeans/jconsole/build.properties Wed Oct 28 16:26:52 2009 -0700
+++ b/jdk/make/netbeans/jconsole/build.properties Wed Oct 28 16:54:50 2009 -0700
@@ -33,7 +33,7 @@
com/sun/tools/jconsole/ \
sun/tools/jconsole/
excludes=\
- sun/tools/jconsole/Version-template.java
+ sun/tools/jconsole/Version.java.template
jtreg.tests=\
sun/tools/jconsole/
javadoc.packagenames=\
--- a/jdk/make/netbeans/jconsole/build.xml Wed Oct 28 16:26:52 2009 -0700
+++ b/jdk/make/netbeans/jconsole/build.xml Wed Oct 28 16:54:50 2009 -0700
@@ -35,7 +35,7 @@
<target name="-pre-compile">
<copy
- file="${root}/src/share/classes/sun/tools/jconsole/Version-template.java"
+ file="${root}/src/share/classes/sun/tools/jconsole/Version.java.template"
tofile="${gensrc.dir}/sun/tools/jconsole/Version.java"/>
<replace
file="${gensrc.dir}/sun/tools/jconsole/Version.java"
--- a/jdk/make/sun/jconsole/Makefile Wed Oct 28 16:26:52 2009 -0700
+++ b/jdk/make/sun/jconsole/Makefile Wed Oct 28 16:54:50 2009 -0700
@@ -70,7 +70,7 @@
build: $(FILES_png) $(FILES_gif) $(TEMPDIR)/manifest $(JARFILE)
$(GENSRCDIR)/sun/tools/jconsole/Version.java: \
- $(SHARE_SRC)/classes/sun/tools/jconsole/Version-template.java
+ $(SHARE_SRC)/classes/sun/tools/jconsole/Version.java.template
$(MKDIR) -p $(@D)
$(SED) -e 's/@@jconsole_version@@/$(FULL_VERSION)/g' $< > $@
--- a/jdk/make/sun/nio/Makefile Wed Oct 28 16:26:52 2009 -0700
+++ b/jdk/make/sun/nio/Makefile Wed Oct 28 16:54:50 2009 -0700
@@ -44,14 +44,6 @@
include FILES_java.gmk
AUTO_FILES_JAVA_DIRS = sun/nio/cs/ext
-# Exclude a few sources on windows
-ifeq ($(PLATFORM), windows)
- AUTO_JAVA_PRUNE = sun/nio/cs/ext/COMPOUND_TEXT.java \
- sun/nio/cs/ext/COMPOUND_TEXT_Decoder.java \
- sun/nio/cs/ext/COMPOUND_TEXT_Encoder.java \
- sun/nio/cs/ext/CompoundTextSupport.java
-endif # PLATFORM
-
# For Cygwin, command line arguments that are paths must be converted to
# windows style paths. These paths cannot be used as targets, however, because
# the ":" in them will interfere with GNU Make rules, generating "multiple
--- a/jdk/src/share/classes/java/nio/ByteBufferAs-X-Buffer.java Wed Oct 28 16:26:52 2009 -0700
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,219 +0,0 @@
-/*
- * Copyright 2000-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.
- */
-
-#warn This file is preprocessed before being compiled
-
-package java.nio;
-
-
-class ByteBufferAs$Type$Buffer$RW$$BO$ // package-private
- extends {#if[ro]?ByteBufferAs}$Type$Buffer{#if[ro]?$BO$}
-{
-
-#if[rw]
-
- protected final ByteBuffer bb;
- protected final int offset;
-
-#end[rw]
-
- ByteBufferAs$Type$Buffer$RW$$BO$(ByteBuffer bb) { // package-private
-#if[rw]
- super(-1, 0,
- bb.remaining() >> $LG_BYTES_PER_VALUE$,
- bb.remaining() >> $LG_BYTES_PER_VALUE$);
- this.bb = bb;
- // enforce limit == capacity
- int cap = this.capacity();
- this.limit(cap);
- int pos = this.position();
- assert (pos <= cap);
- offset = pos;
-#else[rw]
- super(bb);
-#end[rw]
- }
-
- ByteBufferAs$Type$Buffer$RW$$BO$(ByteBuffer bb,
- int mark, int pos, int lim, int cap,
- int off)
- {
-#if[rw]
- super(mark, pos, lim, cap);
- this.bb = bb;
- offset = off;
-#else[rw]
- super(bb, mark, pos, lim, cap, off);
-#end[rw]
- }
-
- public $Type$Buffer slice() {
- int pos = this.position();
- int lim = this.limit();
- assert (pos <= lim);
- int rem = (pos <= lim ? lim - pos : 0);
- int off = (pos << $LG_BYTES_PER_VALUE$) + offset;
- assert (off >= 0);
- return new ByteBufferAs$Type$Buffer$RW$$BO$(bb, -1, 0, rem, rem, off);
- }
-
- public $Type$Buffer duplicate() {
- return new ByteBufferAs$Type$Buffer$RW$$BO$(bb,
- this.markValue(),
- this.position(),
- this.limit(),
- this.capacity(),
- offset);
- }
-
- public $Type$Buffer asReadOnlyBuffer() {
-#if[rw]
- return new ByteBufferAs$Type$BufferR$BO$(bb,
- this.markValue(),
- this.position(),
- this.limit(),
- this.capacity(),
- offset);
-#else[rw]
- return duplicate();
-#end[rw]
- }
-
-#if[rw]
-
- protected int ix(int i) {
- return (i << $LG_BYTES_PER_VALUE$) + offset;
- }
-
- public $type$ get() {
- return Bits.get$Type$$BO$(bb, ix(nextGetIndex()));
- }
-
- public $type$ get(int i) {
- return Bits.get$Type$$BO$(bb, ix(checkIndex(i)));
- }
-
-#end[rw]
-
- public $Type$Buffer put($type$ x) {
-#if[rw]
- Bits.put$Type$$BO$(bb, ix(nextPutIndex()), x);
- return this;
-#else[rw]
- throw new ReadOnlyBufferException();
-#end[rw]
- }
-
- public $Type$Buffer put(int i, $type$ x) {
-#if[rw]
- Bits.put$Type$$BO$(bb, ix(checkIndex(i)), x);
- return this;
-#else[rw]
- throw new ReadOnlyBufferException();
-#end[rw]
- }
-
- public $Type$Buffer compact() {
-#if[rw]
- int pos = position();
- int lim = limit();
- assert (pos <= lim);
- int rem = (pos <= lim ? lim - pos : 0);
-
- ByteBuffer db = bb.duplicate();
- db.limit(ix(lim));
- db.position(ix(0));
- ByteBuffer sb = db.slice();
- sb.position(pos << $LG_BYTES_PER_VALUE$);
- sb.compact();
- position(rem);
- limit(capacity());
- discardMark();
- return this;
-#else[rw]
- throw new ReadOnlyBufferException();
-#end[rw]
- }
-
- public boolean isDirect() {
- return bb.isDirect();
- }
-
- public boolean isReadOnly() {
- return {#if[rw]?false:true};
- }
-
-#if[char]
-
- public String toString(int start, int end) {
- if ((end > limit()) || (start > end))
- throw new IndexOutOfBoundsException();
- try {
- int len = end - start;
- char[] ca = new char[len];
- CharBuffer cb = CharBuffer.wrap(ca);
- CharBuffer db = this.duplicate();
- db.position(start);
- db.limit(end);
- cb.put(db);
- return new String(ca);
- } catch (StringIndexOutOfBoundsException x) {
- throw new IndexOutOfBoundsException();
- }
- }
-
-
- // --- Methods to support CharSequence ---
-
- public CharBuffer subSequence(int start, int end) {
- int pos = position();
- int lim = limit();
- assert (pos <= lim);
- pos = (pos <= lim ? pos : lim);
- int len = lim - pos;
-
- if ((start < 0) || (end > len) || (start > end))
- throw new IndexOutOfBoundsException();
- return new ByteBufferAsCharBuffer$RW$$BO$(bb,
- -1,
- pos + start,
- pos + end,
- capacity(),
- offset);
- }
-
-#end[char]
-
-
- public ByteOrder order() {
-#if[boB]
- return ByteOrder.BIG_ENDIAN;
-#end[boB]
-#if[boL]
- return ByteOrder.LITTLE_ENDIAN;
-#end[boL]
- }
-
-}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/share/classes/java/nio/ByteBufferAs-X-Buffer.java.template Wed Oct 28 16:54:50 2009 -0700
@@ -0,0 +1,219 @@
+/*
+ * Copyright 2000-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.
+ */
+
+#warn This file is preprocessed before being compiled
+
+package java.nio;
+
+
+class ByteBufferAs$Type$Buffer$RW$$BO$ // package-private
+ extends {#if[ro]?ByteBufferAs}$Type$Buffer{#if[ro]?$BO$}
+{
+
+#if[rw]
+
+ protected final ByteBuffer bb;
+ protected final int offset;
+
+#end[rw]
+
+ ByteBufferAs$Type$Buffer$RW$$BO$(ByteBuffer bb) { // package-private
+#if[rw]
+ super(-1, 0,
+ bb.remaining() >> $LG_BYTES_PER_VALUE$,
+ bb.remaining() >> $LG_BYTES_PER_VALUE$);
+ this.bb = bb;
+ // enforce limit == capacity
+ int cap = this.capacity();
+ this.limit(cap);
+ int pos = this.position();
+ assert (pos <= cap);
+ offset = pos;
+#else[rw]
+ super(bb);
+#end[rw]
+ }
+
+ ByteBufferAs$Type$Buffer$RW$$BO$(ByteBuffer bb,
+ int mark, int pos, int lim, int cap,
+ int off)
+ {
+#if[rw]
+ super(mark, pos, lim, cap);
+ this.bb = bb;
+ offset = off;
+#else[rw]
+ super(bb, mark, pos, lim, cap, off);
+#end[rw]
+ }
+
+ public $Type$Buffer slice() {
+ int pos = this.position();
+ int lim = this.limit();
+ assert (pos <= lim);
+ int rem = (pos <= lim ? lim - pos : 0);
+ int off = (pos << $LG_BYTES_PER_VALUE$) + offset;
+ assert (off >= 0);
+ return new ByteBufferAs$Type$Buffer$RW$$BO$(bb, -1, 0, rem, rem, off);
+ }
+
+ public $Type$Buffer duplicate() {
+ return new ByteBufferAs$Type$Buffer$RW$$BO$(bb,
+ this.markValue(),
+ this.position(),
+ this.limit(),
+ this.capacity(),
+ offset);
+ }
+
+ public $Type$Buffer asReadOnlyBuffer() {
+#if[rw]
+ return new ByteBufferAs$Type$BufferR$BO$(bb,
+ this.markValue(),
+ this.position(),
+ this.limit(),
+ this.capacity(),
+ offset);
+#else[rw]
+ return duplicate();
+#end[rw]
+ }
+
+#if[rw]
+
+ protected int ix(int i) {
+ return (i << $LG_BYTES_PER_VALUE$) + offset;
+ }
+
+ public $type$ get() {
+ return Bits.get$Type$$BO$(bb, ix(nextGetIndex()));
+ }
+
+ public $type$ get(int i) {
+ return Bits.get$Type$$BO$(bb, ix(checkIndex(i)));
+ }
+
+#end[rw]
+
+ public $Type$Buffer put($type$ x) {
+#if[rw]
+ Bits.put$Type$$BO$(bb, ix(nextPutIndex()), x);
+ return this;
+#else[rw]
+ throw new ReadOnlyBufferException();
+#end[rw]
+ }
+
+ public $Type$Buffer put(int i, $type$ x) {
+#if[rw]
+ Bits.put$Type$$BO$(bb, ix(checkIndex(i)), x);
+ return this;
+#else[rw]
+ throw new ReadOnlyBufferException();
+#end[rw]
+ }
+
+ public $Type$Buffer compact() {
+#if[rw]
+ int pos = position();
+ int lim = limit();
+ assert (pos <= lim);
+ int rem = (pos <= lim ? lim - pos : 0);
+
+ ByteBuffer db = bb.duplicate();
+ db.limit(ix(lim));
+ db.position(ix(0));
+ ByteBuffer sb = db.slice();
+ sb.position(pos << $LG_BYTES_PER_VALUE$);
+ sb.compact();
+ position(rem);
+ limit(capacity());
+ discardMark();
+ return this;
+#else[rw]
+ throw new ReadOnlyBufferException();
+#end[rw]
+ }
+
+ public boolean isDirect() {
+ return bb.isDirect();
+ }
+
+ public boolean isReadOnly() {
+ return {#if[rw]?false:true};
+ }
+
+#if[char]
+
+ public String toString(int start, int end) {
+ if ((end > limit()) || (start > end))
+ throw new IndexOutOfBoundsException();
+ try {
+ int len = end - start;
+ char[] ca = new char[len];
+ CharBuffer cb = CharBuffer.wrap(ca);
+ CharBuffer db = this.duplicate();
+ db.position(start);
+ db.limit(end);
+ cb.put(db);
+ return new String(ca);
+ } catch (StringIndexOutOfBoundsException x) {
+ throw new IndexOutOfBoundsException();
+ }
+ }
+
+
+ // --- Methods to support CharSequence ---
+
+ public CharBuffer subSequence(int start, int end) {
+ int pos = position();
+ int lim = limit();
+ assert (pos <= lim);
+ pos = (pos <= lim ? pos : lim);
+ int len = lim - pos;
+
+ if ((start < 0) || (end > len) || (start > end))
+ throw new IndexOutOfBoundsException();
+ return new ByteBufferAsCharBuffer$RW$$BO$(bb,
+ -1,
+ pos + start,
+ pos + end,
+ capacity(),
+ offset);
+ }
+
+#end[char]
+
+
+ public ByteOrder order() {
+#if[boB]
+ return ByteOrder.BIG_ENDIAN;
+#end[boB]
+#if[boL]
+ return ByteOrder.LITTLE_ENDIAN;
+#end[boL]
+ }
+
+}
--- a/jdk/src/share/classes/java/nio/Direct-X-Buffer-bin.java Wed Oct 28 16:26:52 2009 -0700
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,124 +0,0 @@
-/*
- * Copyright 2000-2003 Sun Microsystems, Inc. All Rights Reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute 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.
- */
-
-#warn This file is preprocessed before being compiled
-
-class XXX {
-
-#begin
-
-#if[rw]
-
- private $type$ get$Type$(long a) {
- if (unaligned) {
- $memtype$ x = unsafe.get$Memtype$(a);
- return $fromBits$(nativeByteOrder ? x : Bits.swap(x));
- }
- return Bits.get$Type$(a, bigEndian);
- }
-
- public $type$ get$Type$() {
- return get$Type$(ix(nextGetIndex($BYTES_PER_VALUE$)));
- }
-
- public $type$ get$Type$(int i) {
- return get$Type$(ix(checkIndex(i, $BYTES_PER_VALUE$)));
- }
-
-#end[rw]
-
- private ByteBuffer put$Type$(long a, $type$ x) {
-#if[rw]
- if (unaligned) {
- $memtype$ y = $toBits$(x);
- unsafe.put$Memtype$(a, (nativeByteOrder ? y : Bits.swap(y)));
- } else {
- Bits.put$Type$(a, x, bigEndian);
- }
- return this;
-#else[rw]
- throw new ReadOnlyBufferException();
-#end[rw]
- }
-
- public ByteBuffer put$Type$($type$ x) {
-#if[rw]
- put$Type$(ix(nextPutIndex($BYTES_PER_VALUE$)), x);
- return this;
-#else[rw]
- throw new ReadOnlyBufferException();
-#end[rw]
- }
-
- public ByteBuffer put$Type$(int i, $type$ x) {
-#if[rw]
- put$Type$(ix(checkIndex(i, $BYTES_PER_VALUE$)), x);
- return this;
-#else[rw]
- throw new ReadOnlyBufferException();
-#end[rw]
- }
-
- public $Type$Buffer as$Type$Buffer() {
- int off = this.position();
- int lim = this.limit();
- assert (off <= lim);
- int rem = (off <= lim ? lim - off : 0);
-
- int size = rem >> $LG_BYTES_PER_VALUE$;
- if (!unaligned && ((address + off) % $BYTES_PER_VALUE$ != 0)) {
- return (bigEndian
- ? ($Type$Buffer)(new ByteBufferAs$Type$Buffer$RW$B(this,
- -1,
- 0,
- size,
- size,
- off))
- : ($Type$Buffer)(new ByteBufferAs$Type$Buffer$RW$L(this,
- -1,
- 0,
- size,
- size,
- off)));
- } else {
- return (nativeByteOrder
- ? ($Type$Buffer)(new Direct$Type$Buffer$RW$U(this,
- -1,
- 0,
- size,
- size,
- off))
- : ($Type$Buffer)(new Direct$Type$Buffer$RW$S(this,
- -1,
- 0,
- size,
- size,
- off)));
- }
- }
-
-#end
-
-}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/share/classes/java/nio/Direct-X-Buffer-bin.java.template Wed Oct 28 16:54:50 2009 -0700
@@ -0,0 +1,124 @@
+/*
+ * Copyright 2000-2003 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute 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.
+ */
+
+#warn This file is preprocessed before being compiled
+
+class XXX {
+
+#begin
+
+#if[rw]
+
+ private $type$ get$Type$(long a) {
+ if (unaligned) {
+ $memtype$ x = unsafe.get$Memtype$(a);
+ return $fromBits$(nativeByteOrder ? x : Bits.swap(x));
+ }
+ return Bits.get$Type$(a, bigEndian);
+ }
+
+ public $type$ get$Type$() {
+ return get$Type$(ix(nextGetIndex($BYTES_PER_VALUE$)));
+ }
+
+ public $type$ get$Type$(int i) {
+ return get$Type$(ix(checkIndex(i, $BYTES_PER_VALUE$)));
+ }
+
+#end[rw]
+
+ private ByteBuffer put$Type$(long a, $type$ x) {
+#if[rw]
+ if (unaligned) {
+ $memtype$ y = $toBits$(x);
+ unsafe.put$Memtype$(a, (nativeByteOrder ? y : Bits.swap(y)));
+ } else {
+ Bits.put$Type$(a, x, bigEndian);
+ }
+ return this;
+#else[rw]
+ throw new ReadOnlyBufferException();
+#end[rw]
+ }
+
+ public ByteBuffer put$Type$($type$ x) {
+#if[rw]
+ put$Type$(ix(nextPutIndex($BYTES_PER_VALUE$)), x);
+ return this;
+#else[rw]
+ throw new ReadOnlyBufferException();
+#end[rw]
+ }
+
+ public ByteBuffer put$Type$(int i, $type$ x) {
+#if[rw]
+ put$Type$(ix(checkIndex(i, $BYTES_PER_VALUE$)), x);
+ return this;
+#else[rw]
+ throw new ReadOnlyBufferException();
+#end[rw]
+ }
+
+ public $Type$Buffer as$Type$Buffer() {
+ int off = this.position();
+ int lim = this.limit();
+ assert (off <= lim);
+ int rem = (off <= lim ? lim - off : 0);
+
+ int size = rem >> $LG_BYTES_PER_VALUE$;
+ if (!unaligned && ((address + off) % $BYTES_PER_VALUE$ != 0)) {
+ return (bigEndian
+ ? ($Type$Buffer)(new ByteBufferAs$Type$Buffer$RW$B(this,
+ -1,
+ 0,
+ size,
+ size,
+ off))
+ : ($Type$Buffer)(new ByteBufferAs$Type$Buffer$RW$L(this,
+ -1,
+ 0,
+ size,
+ size,
+ off)));
+ } else {
+ return (nativeByteOrder
+ ? ($Type$Buffer)(new Direct$Type$Buffer$RW$U(this,
+ -1,
+ 0,
+ size,
+ size,
+ off))
+ : ($Type$Buffer)(new Direct$Type$Buffer$RW$S(this,
+ -1,
+ 0,
+ size,
+ size,
+ off)));
+ }
+ }
+
+#end
+
+}
--- a/jdk/src/share/classes/java/nio/Direct-X-Buffer.java Wed Oct 28 16:26:52 2009 -0700
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,464 +0,0 @@
-/*
- * Copyright 2000-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.
- */
-
-#warn This file is preprocessed before being compiled
-
-package java.nio;
-
-import sun.misc.Cleaner;
-import sun.misc.Unsafe;
-import sun.nio.ch.DirectBuffer;
-
-
-class Direct$Type$Buffer$RW$$BO$
-#if[rw]
- extends {#if[byte]?Mapped$Type$Buffer:$Type$Buffer}
-#else[rw]
- extends Direct$Type$Buffer$BO$
-#end[rw]
- implements DirectBuffer
-{
-
-#if[rw]
-
- // Cached unsafe-access object
- protected static final Unsafe unsafe = Bits.unsafe();
-
- // Cached array base offset
- private static final long arrayBaseOffset = (long)unsafe.arrayBaseOffset($type$[].class);
-
- // Cached unaligned-access capability
- protected static final boolean unaligned = Bits.unaligned();
-
- // Base address, used in all indexing calculations
- // NOTE: moved up to Buffer.java for speed in JNI GetDirectBufferAddress
- // protected long address;
-
- // If this buffer is a view of another buffer then we keep a reference to
- // that buffer so that its memory isn't freed before we're done with it
- protected Object viewedBuffer = null;
-
- public Object viewedBuffer() {
- return viewedBuffer;
- }
-
-#if[byte]
-
- private static class Deallocator
- implements Runnable
- {
-
- private static Unsafe unsafe = Unsafe.getUnsafe();
-
- private long address;
- private long size;
- private int capacity;
-
- private Deallocator(long address, long size, int capacity) {
- assert (address != 0);
- this.address = address;
- this.size = size;
- this.capacity = capacity;
- }
-
- public void run() {
- if (address == 0) {
- // Paranoia
- return;
- }
- unsafe.freeMemory(address);
- address = 0;
- Bits.unreserveMemory(size, capacity);
- }
-
- }
-
- private final Cleaner cleaner;
-
- public Cleaner cleaner() { return cleaner; }
-
-#else[byte]
-
- public Cleaner cleaner() { return null; }
-
-#end[byte]
-
-#end[rw]
-
-#if[byte]
-
- // Primary constructor
- //
- Direct$Type$Buffer$RW$(int cap) { // package-private
-#if[rw]
- super(-1, 0, cap, cap, false);
- int ps = Bits.pageSize();
- int size = cap + ps;
- Bits.reserveMemory(size, cap);
-
- long base = 0;
- try {
- base = unsafe.allocateMemory(size);
- } catch (OutOfMemoryError x) {
- Bits.unreserveMemory(size, cap);
- throw x;
- }
- unsafe.setMemory(base, size, (byte) 0);
- if (base % ps != 0) {
- // Round up to page boundary
- address = base + ps - (base & (ps - 1));
- } else {
- address = base;
- }
- cleaner = Cleaner.create(this, new Deallocator(base, size, cap));
-#else[rw]
- super(cap);
-#end[rw]
- }
-
-#if[rw]
-
- // Invoked only by JNI: NewDirectByteBuffer(void*, long)
- //
- private Direct$Type$Buffer(long addr, int cap) {
- super(-1, 0, cap, cap, false);
- address = addr;
- cleaner = null;
- }
-
-#end[rw]
-
- // For memory-mapped buffers -- invoked by FileChannelImpl via reflection
- //
- protected Direct$Type$Buffer$RW$(int cap, long addr, Runnable unmapper) {
-#if[rw]
- super(-1, 0, cap, cap, true);
- address = addr;
- viewedBuffer = null;
- cleaner = Cleaner.create(this, unmapper);
-#else[rw]
- super(cap, addr, unmapper);
-#end[rw]
- }
-
-#end[byte]
-
- // For duplicates and slices
- //
- Direct$Type$Buffer$RW$$BO$(DirectBuffer db, // package-private
- int mark, int pos, int lim, int cap,
- int off)
- {
-#if[rw]
- super(mark, pos, lim, cap);
- address = db.address() + off;
- viewedBuffer = db;
-#if[byte]
- cleaner = null;
-#end[byte]
-#else[rw]
- super(db, mark, pos, lim, cap, off);
-#end[rw]
- }
-
- public $Type$Buffer slice() {
- int pos = this.position();
- int lim = this.limit();
- assert (pos <= lim);
- int rem = (pos <= lim ? lim - pos : 0);
- int off = (pos << $LG_BYTES_PER_VALUE$);
- assert (off >= 0);
- return new Direct$Type$Buffer$RW$$BO$(this, -1, 0, rem, rem, off);
- }
-
- public $Type$Buffer duplicate() {
- return new Direct$Type$Buffer$RW$$BO$(this,
- this.markValue(),
- this.position(),
- this.limit(),
- this.capacity(),
- 0);
- }
-
- public $Type$Buffer asReadOnlyBuffer() {
-#if[rw]
- return new Direct$Type$BufferR$BO$(this,
- this.markValue(),
- this.position(),
- this.limit(),
- this.capacity(),
- 0);
-#else[rw]
- return duplicate();
-#end[rw]
- }
-
-#if[rw]
-
- public long address() {
- return address;
- }
-
- private long ix(int i) {
- return address + (i << $LG_BYTES_PER_VALUE$);
- }
-
- public $type$ get() {
- return $fromBits$($swap$(unsafe.get$Swaptype$(ix(nextGetIndex()))));
- }
-
- public $type$ get(int i) {
- return $fromBits$($swap$(unsafe.get$Swaptype$(ix(checkIndex(i)))));
- }
-
- public $Type$Buffer get($type$[] dst, int offset, int length) {
-#if[rw]
- if ((length << $LG_BYTES_PER_VALUE$) > Bits.JNI_COPY_TO_ARRAY_THRESHOLD) {
- checkBounds(offset, length, dst.length);
- int pos = position();
- int lim = limit();
- assert (pos <= lim);
- int rem = (pos <= lim ? lim - pos : 0);
- if (length > rem)
- throw new BufferUnderflowException();
-
-#if[!byte]
- if (order() != ByteOrder.nativeOrder())
- Bits.copyTo$Memtype$Array(ix(pos), dst,
- offset << $LG_BYTES_PER_VALUE$,
- length << $LG_BYTES_PER_VALUE$);
- else
-#end[!byte]
- Bits.copyToArray(ix(pos), dst, arrayBaseOffset,
- offset << $LG_BYTES_PER_VALUE$,
- length << $LG_BYTES_PER_VALUE$);
- position(pos + length);
- } else {
- super.get(dst, offset, length);
- }
- return this;
-#else[rw]
- throw new ReadOnlyBufferException();
-#end[rw]
- }
-
-#end[rw]
-
- public $Type$Buffer put($type$ x) {
-#if[rw]
- unsafe.put$Swaptype$(ix(nextPutIndex()), $swap$($toBits$(x)));
- return this;
-#else[rw]
- throw new ReadOnlyBufferException();
-#end[rw]
- }
-
- public $Type$Buffer put(int i, $type$ x) {
-#if[rw]
- unsafe.put$Swaptype$(ix(checkIndex(i)), $swap$($toBits$(x)));
- return this;
-#else[rw]
- throw new ReadOnlyBufferException();
-#end[rw]
- }
-
- public $Type$Buffer put($Type$Buffer src) {
-#if[rw]
- if (src instanceof Direct$Type$Buffer$BO$) {
- if (src == this)
- throw new IllegalArgumentException();
- Direct$Type$Buffer$RW$$BO$ sb = (Direct$Type$Buffer$RW$$BO$)src;
-
- int spos = sb.position();
- int slim = sb.limit();
- assert (spos <= slim);
- int srem = (spos <= slim ? slim - spos : 0);
-
- int pos = position();
- int lim = limit();
- assert (pos <= lim);
- int rem = (pos <= lim ? lim - pos : 0);
-
- if (srem > rem)
- throw new BufferOverflowException();
- unsafe.copyMemory(sb.ix(spos), ix(pos), srem << $LG_BYTES_PER_VALUE$);
- sb.position(spos + srem);
- position(pos + srem);
- } else if (src.hb != null) {
-
- int spos = src.position();
- int slim = src.limit();
- assert (spos <= slim);
- int srem = (spos <= slim ? slim - spos : 0);
-
- put(src.hb, src.offset + spos, srem);
- src.position(spos + srem);
-
- } else {
- super.put(src);
- }
- return this;
-#else[rw]
- throw new ReadOnlyBufferException();
-#end[rw]
- }
-
- public $Type$Buffer put($type$[] src, int offset, int length) {
-#if[rw]
- if ((length << $LG_BYTES_PER_VALUE$) > Bits.JNI_COPY_FROM_ARRAY_THRESHOLD) {
- checkBounds(offset, length, src.length);
- int pos = position();
- int lim = limit();
- assert (pos <= lim);
- int rem = (pos <= lim ? lim - pos : 0);
- if (length > rem)
- throw new BufferOverflowException();
-
-#if[!byte]
- if (order() != ByteOrder.nativeOrder())
- Bits.copyFrom$Memtype$Array(src, offset << $LG_BYTES_PER_VALUE$,
- ix(pos), length << $LG_BYTES_PER_VALUE$);
- else
-#end[!byte]
- Bits.copyFromArray(src, arrayBaseOffset, offset << $LG_BYTES_PER_VALUE$,
- ix(pos), length << $LG_BYTES_PER_VALUE$);
- position(pos + length);
- } else {
- super.put(src, offset, length);
- }
- return this;
-#else[rw]
- throw new ReadOnlyBufferException();
-#end[rw]
- }
-
- public $Type$Buffer compact() {
-#if[rw]
- int pos = position();
- int lim = limit();
- assert (pos <= lim);
- int rem = (pos <= lim ? lim - pos : 0);
-
- unsafe.copyMemory(ix(pos), ix(0), rem << $LG_BYTES_PER_VALUE$);
- position(rem);
- limit(capacity());
- discardMark();
- return this;
-#else[rw]
- throw new ReadOnlyBufferException();
-#end[rw]
- }
-
- public boolean isDirect() {
- return true;
- }
-
- public boolean isReadOnly() {
- return {#if[rw]?false:true};
- }
-
-
-#if[char]
-
- public String toString(int start, int end) {
- if ((end > limit()) || (start > end))
- throw new IndexOutOfBoundsException();
- try {
- int len = end - start;
- char[] ca = new char[len];
- CharBuffer cb = CharBuffer.wrap(ca);
- CharBuffer db = this.duplicate();
- db.position(start);
- db.limit(end);
- cb.put(db);
- return new String(ca);
- } catch (StringIndexOutOfBoundsException x) {
- throw new IndexOutOfBoundsException();
- }
- }
-
-
- // --- Methods to support CharSequence ---
-
- public CharBuffer subSequence(int start, int end) {
- int pos = position();
- int lim = limit();
- assert (pos <= lim);
- pos = (pos <= lim ? pos : lim);
- int len = lim - pos;
-
- if ((start < 0) || (end > len) || (start > end))
- throw new IndexOutOfBoundsException();
- return new DirectCharBuffer$RW$$BO$(this,
- -1,
- pos + start,
- pos + end,
- capacity(),
- offset);
- }
-
-#end[char]
-
-
-
-#if[!byte]
-
- public ByteOrder order() {
-#if[boS]
- return ((ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN)
- ? ByteOrder.LITTLE_ENDIAN : ByteOrder.BIG_ENDIAN);
-#end[boS]
-#if[boU]
- return ((ByteOrder.nativeOrder() != ByteOrder.BIG_ENDIAN)
- ? ByteOrder.LITTLE_ENDIAN : ByteOrder.BIG_ENDIAN);
-#end[boU]
- }
-
-#end[!byte]
-
-
-
-#if[byte]
-
- byte _get(int i) { // package-private
- return unsafe.getByte(address + i);
- }
-
- void _put(int i, byte b) { // package-private
-#if[rw]
- unsafe.putByte(address + i, b);
-#else[rw]
- throw new ReadOnlyBufferException();
-#end[rw]
- }
-
- // #BIN
- //
- // Binary-data access methods for short, char, int, long, float,
- // and double will be inserted here
-
-#end[byte]
-
-}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/share/classes/java/nio/Direct-X-Buffer.java.template Wed Oct 28 16:54:50 2009 -0700
@@ -0,0 +1,464 @@
+/*
+ * Copyright 2000-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.
+ */
+
+#warn This file is preprocessed before being compiled
+
+package java.nio;
+
+import sun.misc.Cleaner;
+import sun.misc.Unsafe;
+import sun.nio.ch.DirectBuffer;
+
+
+class Direct$Type$Buffer$RW$$BO$
+#if[rw]
+ extends {#if[byte]?Mapped$Type$Buffer:$Type$Buffer}
+#else[rw]
+ extends Direct$Type$Buffer$BO$
+#end[rw]
+ implements DirectBuffer
+{
+
+#if[rw]
+
+ // Cached unsafe-access object
+ protected static final Unsafe unsafe = Bits.unsafe();
+
+ // Cached array base offset
+ private static final long arrayBaseOffset = (long)unsafe.arrayBaseOffset($type$[].class);
+
+ // Cached unaligned-access capability
+ protected static final boolean unaligned = Bits.unaligned();
+
+ // Base address, used in all indexing calculations
+ // NOTE: moved up to Buffer.java for speed in JNI GetDirectBufferAddress
+ // protected long address;
+
+ // If this buffer is a view of another buffer then we keep a reference to
+ // that buffer so that its memory isn't freed before we're done with it
+ protected Object viewedBuffer = null;
+
+ public Object viewedBuffer() {
+ return viewedBuffer;
+ }
+
+#if[byte]
+
+ private static class Deallocator
+ implements Runnable
+ {
+
+ private static Unsafe unsafe = Unsafe.getUnsafe();
+
+ private long address;
+ private long size;
+ private int capacity;
+
+ private Deallocator(long address, long size, int capacity) {
+ assert (address != 0);
+ this.address = address;
+ this.size = size;
+ this.capacity = capacity;
+ }
+
+ public void run() {
+ if (address == 0) {
+ // Paranoia
+ return;
+ }
+ unsafe.freeMemory(address);
+ address = 0;
+ Bits.unreserveMemory(size, capacity);
+ }
+
+ }
+
+ private final Cleaner cleaner;
+
+ public Cleaner cleaner() { return cleaner; }
+
+#else[byte]
+
+ public Cleaner cleaner() { return null; }
+
+#end[byte]
+
+#end[rw]
+
+#if[byte]
+
+ // Primary constructor
+ //
+ Direct$Type$Buffer$RW$(int cap) { // package-private
+#if[rw]
+ super(-1, 0, cap, cap, false);
+ int ps = Bits.pageSize();
+ int size = cap + ps;
+ Bits.reserveMemory(size, cap);
+
+ long base = 0;
+ try {
+ base = unsafe.allocateMemory(size);
+ } catch (OutOfMemoryError x) {
+ Bits.unreserveMemory(size, cap);
+ throw x;
+ }
+ unsafe.setMemory(base, size, (byte) 0);
+ if (base % ps != 0) {
+ // Round up to page boundary
+ address = base + ps - (base & (ps - 1));
+ } else {
+ address = base;
+ }
+ cleaner = Cleaner.create(this, new Deallocator(base, size, cap));
+#else[rw]
+ super(cap);
+#end[rw]
+ }
+
+#if[rw]
+
+ // Invoked only by JNI: NewDirectByteBuffer(void*, long)
+ //
+ private Direct$Type$Buffer(long addr, int cap) {
+ super(-1, 0, cap, cap, false);
+ address = addr;
+ cleaner = null;
+ }
+
+#end[rw]
+
+ // For memory-mapped buffers -- invoked by FileChannelImpl via reflection
+ //
+ protected Direct$Type$Buffer$RW$(int cap, long addr, Runnable unmapper) {
+#if[rw]
+ super(-1, 0, cap, cap, true);
+ address = addr;
+ viewedBuffer = null;
+ cleaner = Cleaner.create(this, unmapper);
+#else[rw]
+ super(cap, addr, unmapper);
+#end[rw]
+ }
+
+#end[byte]
+
+ // For duplicates and slices
+ //
+ Direct$Type$Buffer$RW$$BO$(DirectBuffer db, // package-private
+ int mark, int pos, int lim, int cap,
+ int off)
+ {
+#if[rw]
+ super(mark, pos, lim, cap);
+ address = db.address() + off;
+ viewedBuffer = db;
+#if[byte]
+ cleaner = null;
+#end[byte]
+#else[rw]
+ super(db, mark, pos, lim, cap, off);
+#end[rw]
+ }
+
+ public $Type$Buffer slice() {
+ int pos = this.position();
+ int lim = this.limit();
+ assert (pos <= lim);
+ int rem = (pos <= lim ? lim - pos : 0);
+ int off = (pos << $LG_BYTES_PER_VALUE$);
+ assert (off >= 0);
+ return new Direct$Type$Buffer$RW$$BO$(this, -1, 0, rem, rem, off);
+ }
+
+ public $Type$Buffer duplicate() {
+ return new Direct$Type$Buffer$RW$$BO$(this,
+ this.markValue(),
+ this.position(),
+ this.limit(),
+ this.capacity(),
+ 0);
+ }
+
+ public $Type$Buffer asReadOnlyBuffer() {
+#if[rw]
+ return new Direct$Type$BufferR$BO$(this,
+ this.markValue(),
+ this.position(),
+ this.limit(),
+ this.capacity(),
+ 0);
+#else[rw]
+ return duplicate();
+#end[rw]
+ }
+
+#if[rw]
+
+ public long address() {
+ return address;
+ }
+
+ private long ix(int i) {
+ return address + (i << $LG_BYTES_PER_VALUE$);
+ }
+
+ public $type$ get() {
+ return $fromBits$($swap$(unsafe.get$Swaptype$(ix(nextGetIndex()))));
+ }
+
+ public $type$ get(int i) {
+ return $fromBits$($swap$(unsafe.get$Swaptype$(ix(checkIndex(i)))));
+ }
+
+ public $Type$Buffer get($type$[] dst, int offset, int length) {
+#if[rw]
+ if ((length << $LG_BYTES_PER_VALUE$) > Bits.JNI_COPY_TO_ARRAY_THRESHOLD) {
+ checkBounds(offset, length, dst.length);
+ int pos = position();
+ int lim = limit();
+ assert (pos <= lim);
+ int rem = (pos <= lim ? lim - pos : 0);
+ if (length > rem)
+ throw new BufferUnderflowException();
+
+#if[!byte]
+ if (order() != ByteOrder.nativeOrder())
+ Bits.copyTo$Memtype$Array(ix(pos), dst,
+ offset << $LG_BYTES_PER_VALUE$,
+ length << $LG_BYTES_PER_VALUE$);
+ else
+#end[!byte]
+ Bits.copyToArray(ix(pos), dst, arrayBaseOffset,
+ offset << $LG_BYTES_PER_VALUE$,
+ length << $LG_BYTES_PER_VALUE$);
+ position(pos + length);
+ } else {
+ super.get(dst, offset, length);
+ }
+ return this;
+#else[rw]
+ throw new ReadOnlyBufferException();
+#end[rw]
+ }
+
+#end[rw]
+
+ public $Type$Buffer put($type$ x) {
+#if[rw]
+ unsafe.put$Swaptype$(ix(nextPutIndex()), $swap$($toBits$(x)));
+ return this;
+#else[rw]
+ throw new ReadOnlyBufferException();
+#end[rw]
+ }
+
+ public $Type$Buffer put(int i, $type$ x) {
+#if[rw]
+ unsafe.put$Swaptype$(ix(checkIndex(i)), $swap$($toBits$(x)));
+ return this;
+#else[rw]
+ throw new ReadOnlyBufferException();
+#end[rw]
+ }
+
+ public $Type$Buffer put($Type$Buffer src) {
+#if[rw]
+ if (src instanceof Direct$Type$Buffer$BO$) {
+ if (src == this)
+ throw new IllegalArgumentException();
+ Direct$Type$Buffer$RW$$BO$ sb = (Direct$Type$Buffer$RW$$BO$)src;
+
+ int spos = sb.position();
+ int slim = sb.limit();
+ assert (spos <= slim);
+ int srem = (spos <= slim ? slim - spos : 0);
+
+ int pos = position();
+ int lim = limit();
+ assert (pos <= lim);
+ int rem = (pos <= lim ? lim - pos : 0);
+
+ if (srem > rem)
+ throw new BufferOverflowException();
+ unsafe.copyMemory(sb.ix(spos), ix(pos), srem << $LG_BYTES_PER_VALUE$);
+ sb.position(spos + srem);
+ position(pos + srem);
+ } else if (src.hb != null) {
+
+ int spos = src.position();
+ int slim = src.limit();
+ assert (spos <= slim);
+ int srem = (spos <= slim ? slim - spos : 0);
+
+ put(src.hb, src.offset + spos, srem);
+ src.position(spos + srem);
+
+ } else {
+ super.put(src);
+ }
+ return this;
+#else[rw]
+ throw new ReadOnlyBufferException();
+#end[rw]
+ }
+
+ public $Type$Buffer put($type$[] src, int offset, int length) {
+#if[rw]
+ if ((length << $LG_BYTES_PER_VALUE$) > Bits.JNI_COPY_FROM_ARRAY_THRESHOLD) {
+ checkBounds(offset, length, src.length);
+ int pos = position();
+ int lim = limit();
+ assert (pos <= lim);
+ int rem = (pos <= lim ? lim - pos : 0);
+ if (length > rem)
+ throw new BufferOverflowException();
+
+#if[!byte]
+ if (order() != ByteOrder.nativeOrder())
+ Bits.copyFrom$Memtype$Array(src, offset << $LG_BYTES_PER_VALUE$,
+ ix(pos), length << $LG_BYTES_PER_VALUE$);
+ else
+#end[!byte]
+ Bits.copyFromArray(src, arrayBaseOffset, offset << $LG_BYTES_PER_VALUE$,
+ ix(pos), length << $LG_BYTES_PER_VALUE$);
+ position(pos + length);
+ } else {
+ super.put(src, offset, length);
+ }
+ return this;
+#else[rw]
+ throw new ReadOnlyBufferException();
+#end[rw]
+ }
+
+ public $Type$Buffer compact() {
+#if[rw]
+ int pos = position();
+ int lim = limit();
+ assert (pos <= lim);
+ int rem = (pos <= lim ? lim - pos : 0);
+
+ unsafe.copyMemory(ix(pos), ix(0), rem << $LG_BYTES_PER_VALUE$);
+ position(rem);
+ limit(capacity());
+ discardMark();
+ return this;
+#else[rw]
+ throw new ReadOnlyBufferException();
+#end[rw]
+ }
+
+ public boolean isDirect() {
+ return true;
+ }
+
+ public boolean isReadOnly() {
+ return {#if[rw]?false:true};
+ }
+
+
+#if[char]
+
+ public String toString(int start, int end) {
+ if ((end > limit()) || (start > end))
+ throw new IndexOutOfBoundsException();
+ try {
+ int len = end - start;
+ char[] ca = new char[len];
+ CharBuffer cb = CharBuffer.wrap(ca);
+ CharBuffer db = this.duplicate();
+ db.position(start);
+ db.limit(end);
+ cb.put(db);
+ return new String(ca);
+ } catch (StringIndexOutOfBoundsException x) {
+ throw new IndexOutOfBoundsException();
+ }
+ }
+
+
+ // --- Methods to support CharSequence ---
+
+ public CharBuffer subSequence(int start, int end) {
+ int pos = position();
+ int lim = limit();
+ assert (pos <= lim);
+ pos = (pos <= lim ? pos : lim);
+ int len = lim - pos;
+
+ if ((start < 0) || (end > len) || (start > end))
+ throw new IndexOutOfBoundsException();
+ return new DirectCharBuffer$RW$$BO$(this,
+ -1,
+ pos + start,
+ pos + end,
+ capacity(),
+ offset);
+ }
+
+#end[char]
+
+
+
+#if[!byte]
+
+ public ByteOrder order() {
+#if[boS]
+ return ((ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN)
+ ? ByteOrder.LITTLE_ENDIAN : ByteOrder.BIG_ENDIAN);
+#end[boS]
+#if[boU]
+ return ((ByteOrder.nativeOrder() != ByteOrder.BIG_ENDIAN)
+ ? ByteOrder.LITTLE_ENDIAN : ByteOrder.BIG_ENDIAN);
+#end[boU]
+ }
+
+#end[!byte]
+
+
+
+#if[byte]
+
+ byte _get(int i) { // package-private
+ return unsafe.getByte(address + i);
+ }
+
+ void _put(int i, byte b) { // package-private
+#if[rw]
+ unsafe.putByte(address + i, b);
+#else[rw]
+ throw new ReadOnlyBufferException();
+#end[rw]
+ }
+
+ // #BIN
+ //
+ // Binary-data access methods for short, char, int, long, float,
+ // and double will be inserted here
+
+#end[byte]
+
+}
--- a/jdk/src/share/classes/java/nio/Heap-X-Buffer.java Wed Oct 28 16:26:52 2009 -0700
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,595 +0,0 @@
-/*
- * Copyright 2000-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.
- */
-
-#warn This file is preprocessed before being compiled
-
-package java.nio;
-
-
-/**
-#if[rw]
- * A read/write Heap$Type$Buffer.
-#else[rw]
- * A read-only Heap$Type$Buffer. This class extends the corresponding
- * read/write class, overriding the mutation methods to throw a {@link
- * ReadOnlyBufferException} and overriding the view-buffer methods to return an
- * instance of this class rather than of the superclass.
-#end[rw]
- */
-
-class Heap$Type$Buffer$RW$
- extends {#if[ro]?Heap}$Type$Buffer
-{
-
- // For speed these fields are actually declared in X-Buffer;
- // these declarations are here as documentation
- /*
-#if[rw]
- protected final $type$[] hb;
- protected final int offset;
-#end[rw]
- */
-
- Heap$Type$Buffer$RW$(int cap, int lim) { // package-private
-#if[rw]
- super(-1, 0, lim, cap, new $type$[cap], 0);
- /*
- hb = new $type$[cap];
- offset = 0;
- */
-#else[rw]
- super(cap, lim);
- this.isReadOnly = true;
-#end[rw]
- }
-
- Heap$Type$Buffer$RW$($type$[] buf, int off, int len) { // package-private
-#if[rw]
- super(-1, off, off + len, buf.length, buf, 0);
- /*
- hb = buf;
- offset = 0;
- */
-#else[rw]
- super(buf, off, len);
- this.isReadOnly = true;
-#end[rw]
- }
-
- protected Heap$Type$Buffer$RW$($type$[] buf,
- int mark, int pos, int lim, int cap,
- int off)
- {
-#if[rw]
- super(mark, pos, lim, cap, buf, off);
- /*
- hb = buf;
- offset = off;
- */
-#else[rw]
- super(buf, mark, pos, lim, cap, off);
- this.isReadOnly = true;
-#end[rw]
- }
-
- public $Type$Buffer slice() {
- return new Heap$Type$Buffer$RW$(hb,
- -1,
- 0,
- this.remaining(),
- this.remaining(),
- this.position() + offset);
- }
-
- public $Type$Buffer duplicate() {
- return new Heap$Type$Buffer$RW$(hb,
- this.markValue(),
- this.position(),
- this.limit(),
- this.capacity(),
- offset);
- }
-
- public $Type$Buffer asReadOnlyBuffer() {
-#if[rw]
- return new Heap$Type$BufferR(hb,
- this.markValue(),
- this.position(),
- this.limit(),
- this.capacity(),
- offset);
-#else[rw]
- return duplicate();
-#end[rw]
- }
-
-#if[rw]
-
- protected int ix(int i) {
- return i + offset;
- }
-
- public $type$ get() {
- return hb[ix(nextGetIndex())];
- }
-
- public $type$ get(int i) {
- return hb[ix(checkIndex(i))];
- }
-
- public $Type$Buffer get($type$[] dst, int offset, int length) {
- checkBounds(offset, length, dst.length);
- if (length > remaining())
- throw new BufferUnderflowException();
- System.arraycopy(hb, ix(position()), dst, offset, length);
- position(position() + length);
- return this;
- }
-
- public boolean isDirect() {
- return false;
- }
-
-#end[rw]
-
- public boolean isReadOnly() {
- return {#if[rw]?false:true};
- }
-
- public $Type$Buffer put($type$ x) {
-#if[rw]
- hb[ix(nextPutIndex())] = x;
- return this;
-#else[rw]
- throw new ReadOnlyBufferException();
-#end[rw]
- }
-
- public $Type$Buffer put(int i, $type$ x) {
-#if[rw]
- hb[ix(checkIndex(i))] = x;
- return this;
-#else[rw]
- throw new ReadOnlyBufferException();
-#end[rw]
- }
-
- public $Type$Buffer put($type$[] src, int offset, int length) {
-#if[rw]
- checkBounds(offset, length, src.length);
- if (length > remaining())
- throw new BufferOverflowException();
- System.arraycopy(src, offset, hb, ix(position()), length);
- position(position() + length);
- return this;
-#else[rw]
- throw new ReadOnlyBufferException();
-#end[rw]
- }
-
- public $Type$Buffer put($Type$Buffer src) {
-#if[rw]
- if (src instanceof Heap$Type$Buffer) {
- if (src == this)
- throw new IllegalArgumentException();
- Heap$Type$Buffer sb = (Heap$Type$Buffer)src;
- int n = sb.remaining();
- if (n > remaining())
- throw new BufferOverflowException();
- System.arraycopy(sb.hb, sb.ix(sb.position()),
- hb, ix(position()), n);
- sb.position(sb.position() + n);
- position(position() + n);
- } else if (src.isDirect()) {
- int n = src.remaining();
- if (n > remaining())
- throw new BufferOverflowException();
- src.get(hb, ix(position()), n);
- position(position() + n);
- } else {
- super.put(src);
- }
- return this;
-#else[rw]
- throw new ReadOnlyBufferException();
-#end[rw]
- }
-
- public $Type$Buffer compact() {
-#if[rw]
- System.arraycopy(hb, ix(position()), hb, ix(0), remaining());
- position(remaining());
- limit(capacity());
- discardMark();
- return this;
-#else[rw]
- throw new ReadOnlyBufferException();
-#end[rw]
- }
-
-
-
-#if[byte]
-
- byte _get(int i) { // package-private
- return hb[i];
- }
-
- void _put(int i, byte b) { // package-private
-#if[rw]
- hb[i] = b;
-#else[rw]
- throw new ReadOnlyBufferException();
-#end[rw]
- }
-
- // char
-
-#if[rw]
-
- public char getChar() {
- return Bits.getChar(this, ix(nextGetIndex(2)), bigEndian);
- }
-
- public char getChar(int i) {
- return Bits.getChar(this, ix(checkIndex(i, 2)), bigEndian);
- }
-
-#end[rw]
-
- public $Type$Buffer putChar(char x) {
-#if[rw]
- Bits.putChar(this, ix(nextPutIndex(2)), x, bigEndian);
- return this;
-#else[rw]
- throw new ReadOnlyBufferException();
-#end[rw]
- }
-
- public $Type$Buffer putChar(int i, char x) {
-#if[rw]
- Bits.putChar(this, ix(checkIndex(i, 2)), x, bigEndian);
- return this;
-#else[rw]
- throw new ReadOnlyBufferException();
-#end[rw]
- }
-
- public CharBuffer asCharBuffer() {
- int size = this.remaining() >> 1;
- int off = offset + position();
- return (bigEndian
- ? (CharBuffer)(new ByteBufferAsCharBuffer$RW$B(this,
- -1,
- 0,
- size,
- size,
- off))
- : (CharBuffer)(new ByteBufferAsCharBuffer$RW$L(this,
- -1,
- 0,
- size,
- size,
- off)));
- }
-
-
- // short
-
-#if[rw]
-
- public short getShort() {
- return Bits.getShort(this, ix(nextGetIndex(2)), bigEndian);
- }
-
- public short getShort(int i) {
- return Bits.getShort(this, ix(checkIndex(i, 2)), bigEndian);
- }
-
-#end[rw]
-
- public $Type$Buffer putShort(short x) {
-#if[rw]
- Bits.putShort(this, ix(nextPutIndex(2)), x, bigEndian);
- return this;
-#else[rw]
- throw new ReadOnlyBufferException();
-#end[rw]
- }
-
- public $Type$Buffer putShort(int i, short x) {
-#if[rw]
- Bits.putShort(this, ix(checkIndex(i, 2)), x, bigEndian);
- return this;
-#else[rw]
- throw new ReadOnlyBufferException();
-#end[rw]
- }
-
- public ShortBuffer asShortBuffer() {
- int size = this.remaining() >> 1;
- int off = offset + position();
- return (bigEndian
- ? (ShortBuffer)(new ByteBufferAsShortBuffer$RW$B(this,
- -1,
- 0,
- size,
- size,
- off))
- : (ShortBuffer)(new ByteBufferAsShortBuffer$RW$L(this,
- -1,
- 0,
- size,
- size,
- off)));
- }
-
-
- // int
-
-#if[rw]
-
- public int getInt() {
- return Bits.getInt(this, ix(nextGetIndex(4)), bigEndian);
- }
-
- public int getInt(int i) {
- return Bits.getInt(this, ix(checkIndex(i, 4)), bigEndian);
- }
-
-#end[rw]
-
- public $Type$Buffer putInt(int x) {
-#if[rw]
- Bits.putInt(this, ix(nextPutIndex(4)), x, bigEndian);
- return this;
-#else[rw]
- throw new ReadOnlyBufferException();
-#end[rw]
- }
-
- public $Type$Buffer putInt(int i, int x) {
-#if[rw]
- Bits.putInt(this, ix(checkIndex(i, 4)), x, bigEndian);
- return this;
-#else[rw]
- throw new ReadOnlyBufferException();
-#end[rw]
- }
-
- public IntBuffer asIntBuffer() {
- int size = this.remaining() >> 2;
- int off = offset + position();
- return (bigEndian
- ? (IntBuffer)(new ByteBufferAsIntBuffer$RW$B(this,
- -1,
- 0,
- size,
- size,
- off))
- : (IntBuffer)(new ByteBufferAsIntBuffer$RW$L(this,
- -1,
- 0,
- size,
- size,
- off)));
- }
-
-
- // long
-
-#if[rw]
-
- public long getLong() {
- return Bits.getLong(this, ix(nextGetIndex(8)), bigEndian);
- }
-
- public long getLong(int i) {
- return Bits.getLong(this, ix(checkIndex(i, 8)), bigEndian);
- }
-
-#end[rw]
-
- public $Type$Buffer putLong(long x) {
-#if[rw]
- Bits.putLong(this, ix(nextPutIndex(8)), x, bigEndian);
- return this;
-#else[rw]
- throw new ReadOnlyBufferException();
-#end[rw]
- }
-
- public $Type$Buffer putLong(int i, long x) {
-#if[rw]
- Bits.putLong(this, ix(checkIndex(i, 8)), x, bigEndian);
- return this;
-#else[rw]
- throw new ReadOnlyBufferException();
-#end[rw]
- }
-
- public LongBuffer asLongBuffer() {
- int size = this.remaining() >> 3;
- int off = offset + position();
- return (bigEndian
- ? (LongBuffer)(new ByteBufferAsLongBuffer$RW$B(this,
- -1,
- 0,
- size,
- size,
- off))
- : (LongBuffer)(new ByteBufferAsLongBuffer$RW$L(this,
- -1,
- 0,
- size,
- size,
- off)));
- }
-
-
- // float
-
-#if[rw]
-
- public float getFloat() {
- return Bits.getFloat(this, ix(nextGetIndex(4)), bigEndian);
- }
-
- public float getFloat(int i) {
- return Bits.getFloat(this, ix(checkIndex(i, 4)), bigEndian);
- }
-
-#end[rw]
-
- public $Type$Buffer putFloat(float x) {
-#if[rw]
- Bits.putFloat(this, ix(nextPutIndex(4)), x, bigEndian);
- return this;
-#else[rw]
- throw new ReadOnlyBufferException();
-#end[rw]
- }
-
- public $Type$Buffer putFloat(int i, float x) {
-#if[rw]
- Bits.putFloat(this, ix(checkIndex(i, 4)), x, bigEndian);
- return this;
-#else[rw]
- throw new ReadOnlyBufferException();
-#end[rw]
- }
-
- public FloatBuffer asFloatBuffer() {
- int size = this.remaining() >> 2;
- int off = offset + position();
- return (bigEndian
- ? (FloatBuffer)(new ByteBufferAsFloatBuffer$RW$B(this,
- -1,
- 0,
- size,
- size,
- off))
- : (FloatBuffer)(new ByteBufferAsFloatBuffer$RW$L(this,
- -1,
- 0,
- size,
- size,
- off)));
- }
-
-
- // double
-
-#if[rw]
-
- public double getDouble() {
- return Bits.getDouble(this, ix(nextGetIndex(8)), bigEndian);
- }
-
- public double getDouble(int i) {
- return Bits.getDouble(this, ix(checkIndex(i, 8)), bigEndian);
- }
-
-#end[rw]
-
- public $Type$Buffer putDouble(double x) {
-#if[rw]
- Bits.putDouble(this, ix(nextPutIndex(8)), x, bigEndian);
- return this;
-#else[rw]
- throw new ReadOnlyBufferException();
-#end[rw]
- }
-
- public $Type$Buffer putDouble(int i, double x) {
-#if[rw]
- Bits.putDouble(this, ix(checkIndex(i, 8)), x, bigEndian);
- return this;
-#else[rw]
- throw new ReadOnlyBufferException();
-#end[rw]
- }
-
- public DoubleBuffer asDoubleBuffer() {
- int size = this.remaining() >> 3;
- int off = offset + position();
- return (bigEndian
- ? (DoubleBuffer)(new ByteBufferAsDoubleBuffer$RW$B(this,
- -1,
- 0,
- size,
- size,
- off))
- : (DoubleBuffer)(new ByteBufferAsDoubleBuffer$RW$L(this,
- -1,
- 0,
- size,
- size,
- off)));
- }
-
-
-#end[byte]
-
-
-#if[char]
-
- String toString(int start, int end) { // package-private
- try {
- return new String(hb, start + offset, end - start);
- } catch (StringIndexOutOfBoundsException x) {
- throw new IndexOutOfBoundsException();
- }
- }
-
-
- // --- Methods to support CharSequence ---
-
- public CharBuffer subSequence(int start, int end) {
- if ((start < 0)
- || (end > length())
- || (start > end))
- throw new IndexOutOfBoundsException();
- int pos = position();
- return new HeapCharBuffer$RW$(hb,
- -1,
- pos + start,
- pos + end,
- capacity(),
- offset);
- }
-
-#end[char]
-
-
-#if[!byte]
-
- public ByteOrder order() {
- return ByteOrder.nativeOrder();
- }
-
-#end[!byte]
-
-}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/share/classes/java/nio/Heap-X-Buffer.java.template Wed Oct 28 16:54:50 2009 -0700
@@ -0,0 +1,595 @@
+/*
+ * Copyright 2000-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.
+ */
+
+#warn This file is preprocessed before being compiled
+
+package java.nio;
+
+
+/**
+#if[rw]
+ * A read/write Heap$Type$Buffer.
+#else[rw]
+ * A read-only Heap$Type$Buffer. This class extends the corresponding
+ * read/write class, overriding the mutation methods to throw a {@link
+ * ReadOnlyBufferException} and overriding the view-buffer methods to return an
+ * instance of this class rather than of the superclass.
+#end[rw]
+ */
+
+class Heap$Type$Buffer$RW$
+ extends {#if[ro]?Heap}$Type$Buffer
+{
+
+ // For speed these fields are actually declared in X-Buffer;
+ // these declarations are here as documentation
+ /*
+#if[rw]
+ protected final $type$[] hb;
+ protected final int offset;
+#end[rw]
+ */
+
+ Heap$Type$Buffer$RW$(int cap, int lim) { // package-private
+#if[rw]
+ super(-1, 0, lim, cap, new $type$[cap], 0);
+ /*
+ hb = new $type$[cap];
+ offset = 0;
+ */
+#else[rw]
+ super(cap, lim);
+ this.isReadOnly = true;
+#end[rw]
+ }
+
+ Heap$Type$Buffer$RW$($type$[] buf, int off, int len) { // package-private
+#if[rw]
+ super(-1, off, off + len, buf.length, buf, 0);
+ /*
+ hb = buf;
+ offset = 0;
+ */
+#else[rw]
+ super(buf, off, len);
+ this.isReadOnly = true;
+#end[rw]
+ }
+
+ protected Heap$Type$Buffer$RW$($type$[] buf,
+ int mark, int pos, int lim, int cap,
+ int off)
+ {
+#if[rw]
+ super(mark, pos, lim, cap, buf, off);
+ /*
+ hb = buf;
+ offset = off;
+ */
+#else[rw]
+ super(buf, mark, pos, lim, cap, off);
+ this.isReadOnly = true;
+#end[rw]
+ }
+
+ public $Type$Buffer slice() {
+ return new Heap$Type$Buffer$RW$(hb,
+ -1,
+ 0,
+ this.remaining(),
+ this.remaining(),
+ this.position() + offset);
+ }
+
+ public $Type$Buffer duplicate() {
+ return new Heap$Type$Buffer$RW$(hb,
+ this.markValue(),
+ this.position(),
+ this.limit(),
+ this.capacity(),
+ offset);
+ }
+
+ public $Type$Buffer asReadOnlyBuffer() {
+#if[rw]
+ return new Heap$Type$BufferR(hb,
+ this.markValue(),
+ this.position(),
+ this.limit(),
+ this.capacity(),
+ offset);
+#else[rw]
+ return duplicate();
+#end[rw]
+ }
+
+#if[rw]
+
+ protected int ix(int i) {
+ return i + offset;
+ }
+
+ public $type$ get() {
+ return hb[ix(nextGetIndex())];
+ }
+
+ public $type$ get(int i) {
+ return hb[ix(checkIndex(i))];
+ }
+
+ public $Type$Buffer get($type$[] dst, int offset, int length) {
+ checkBounds(offset, length, dst.length);
+ if (length > remaining())
+ throw new BufferUnderflowException();
+ System.arraycopy(hb, ix(position()), dst, offset, length);
+ position(position() + length);
+ return this;
+ }
+
+ public boolean isDirect() {
+ return false;
+ }
+
+#end[rw]
+
+ public boolean isReadOnly() {
+ return {#if[rw]?false:true};
+ }
+
+ public $Type$Buffer put($type$ x) {
+#if[rw]
+ hb[ix(nextPutIndex())] = x;
+ return this;
+#else[rw]
+ throw new ReadOnlyBufferException();
+#end[rw]
+ }
+
+ public $Type$Buffer put(int i, $type$ x) {
+#if[rw]
+ hb[ix(checkIndex(i))] = x;
+ return this;
+#else[rw]
+ throw new ReadOnlyBufferException();
+#end[rw]
+ }
+
+ public $Type$Buffer put($type$[] src, int offset, int length) {
+#if[rw]
+ checkBounds(offset, length, src.length);
+ if (length > remaining())
+ throw new BufferOverflowException();
+ System.arraycopy(src, offset, hb, ix(position()), length);
+ position(position() + length);
+ return this;
+#else[rw]
+ throw new ReadOnlyBufferException();
+#end[rw]
+ }
+
+ public $Type$Buffer put($Type$Buffer src) {
+#if[rw]
+ if (src instanceof Heap$Type$Buffer) {
+ if (src == this)
+ throw new IllegalArgumentException();
+ Heap$Type$Buffer sb = (Heap$Type$Buffer)src;
+ int n = sb.remaining();
+ if (n > remaining())
+ throw new BufferOverflowException();
+ System.arraycopy(sb.hb, sb.ix(sb.position()),
+ hb, ix(position()), n);
+ sb.position(sb.position() + n);
+ position(position() + n);
+ } else if (src.isDirect()) {
+ int n = src.remaining();
+ if (n > remaining())
+ throw new BufferOverflowException();
+ src.get(hb, ix(position()), n);
+ position(position() + n);
+ } else {
+ super.put(src);
+ }
+ return this;
+#else[rw]
+ throw new ReadOnlyBufferException();
+#end[rw]
+ }
+
+ public $Type$Buffer compact() {
+#if[rw]
+ System.arraycopy(hb, ix(position()), hb, ix(0), remaining());
+ position(remaining());
+ limit(capacity());
+ discardMark();
+ return this;
+#else[rw]
+ throw new ReadOnlyBufferException();
+#end[rw]
+ }
+
+
+
+#if[byte]
+
+ byte _get(int i) { // package-private
+ return hb[i];
+ }
+
+ void _put(int i, byte b) { // package-private
+#if[rw]
+ hb[i] = b;
+#else[rw]
+ throw new ReadOnlyBufferException();
+#end[rw]
+ }
+
+ // char
+
+#if[rw]
+
+ public char getChar() {
+ return Bits.getChar(this, ix(nextGetIndex(2)), bigEndian);
+ }
+
+ public char getChar(int i) {
+ return Bits.getChar(this, ix(checkIndex(i, 2)), bigEndian);
+ }
+
+#end[rw]
+
+ public $Type$Buffer putChar(char x) {
+#if[rw]
+ Bits.putChar(this, ix(nextPutIndex(2)), x, bigEndian);
+ return this;
+#else[rw]
+ throw new ReadOnlyBufferException();
+#end[rw]
+ }
+
+ public $Type$Buffer putChar(int i, char x) {
+#if[rw]
+ Bits.putChar(this, ix(checkIndex(i, 2)), x, bigEndian);
+ return this;
+#else[rw]
+ throw new ReadOnlyBufferException();
+#end[rw]
+ }
+
+ public CharBuffer asCharBuffer() {
+ int size = this.remaining() >> 1;
+ int off = offset + position();
+ return (bigEndian
+ ? (CharBuffer)(new ByteBufferAsCharBuffer$RW$B(this,
+ -1,
+ 0,
+ size,
+ size,
+ off))
+ : (CharBuffer)(new ByteBufferAsCharBuffer$RW$L(this,
+ -1,
+ 0,
+ size,
+ size,
+ off)));
+ }
+
+
+ // short
+
+#if[rw]
+
+ public short getShort() {
+ return Bits.getShort(this, ix(nextGetIndex(2)), bigEndian);
+ }
+
+ public short getShort(int i) {
+ return Bits.getShort(this, ix(checkIndex(i, 2)), bigEndian);
+ }
+
+#end[rw]
+
+ public $Type$Buffer putShort(short x) {
+#if[rw]
+ Bits.putShort(this, ix(nextPutIndex(2)), x, bigEndian);
+ return this;
+#else[rw]
+ throw new ReadOnlyBufferException();
+#end[rw]
+ }
+
+ public $Type$Buffer putShort(int i, short x) {
+#if[rw]
+ Bits.putShort(this, ix(checkIndex(i, 2)), x, bigEndian);
+ return this;
+#else[rw]
+ throw new ReadOnlyBufferException();
+#end[rw]
+ }
+
+ public ShortBuffer asShortBuffer() {
+ int size = this.remaining() >> 1;
+ int off = offset + position();
+ return (bigEndian
+ ? (ShortBuffer)(new ByteBufferAsShortBuffer$RW$B(this,
+ -1,
+ 0,
+ size,
+ size,
+ off))
+ : (ShortBuffer)(new ByteBufferAsShortBuffer$RW$L(this,
+ -1,
+ 0,
+ size,
+ size,
+ off)));
+ }
+
+
+ // int
+
+#if[rw]
+
+ public int getInt() {
+ return Bits.getInt(this, ix(nextGetIndex(4)), bigEndian);
+ }
+
+ public int getInt(int i) {
+ return Bits.getInt(this, ix(checkIndex(i, 4)), bigEndian);
+ }
+
+#end[rw]
+
+ public $Type$Buffer putInt(int x) {
+#if[rw]
+ Bits.putInt(this, ix(nextPutIndex(4)), x, bigEndian);
+ return this;
+#else[rw]
+ throw new ReadOnlyBufferException();
+#end[rw]
+ }
+
+ public $Type$Buffer putInt(int i, int x) {
+#if[rw]
+ Bits.putInt(this, ix(checkIndex(i, 4)), x, bigEndian);
+ return this;
+#else[rw]
+ throw new ReadOnlyBufferException();
+#end[rw]
+ }
+
+ public IntBuffer asIntBuffer() {
+ int size = this.remaining() >> 2;
+ int off = offset + position();
+ return (bigEndian
+ ? (IntBuffer)(new ByteBufferAsIntBuffer$RW$B(this,
+ -1,
+ 0,
+ size,
+ size,
+ off))
+ : (IntBuffer)(new ByteBufferAsIntBuffer$RW$L(this,
+ -1,
+ 0,
+ size,
+ size,
+ off)));
+ }
+
+
+ // long
+
+#if[rw]
+
+ public long getLong() {
+ return Bits.getLong(this, ix(nextGetIndex(8)), bigEndian);
+ }
+
+ public long getLong(int i) {
+ return Bits.getLong(this, ix(checkIndex(i, 8)), bigEndian);
+ }
+
+#end[rw]
+
+ public $Type$Buffer putLong(long x) {
+#if[rw]
+ Bits.putLong(this, ix(nextPutIndex(8)), x, bigEndian);
+ return this;
+#else[rw]
+ throw new ReadOnlyBufferException();
+#end[rw]
+ }
+
+ public $Type$Buffer putLong(int i, long x) {
+#if[rw]
+ Bits.putLong(this, ix(checkIndex(i, 8)), x, bigEndian);
+ return this;
+#else[rw]
+ throw new ReadOnlyBufferException();
+#end[rw]
+ }
+
+ public LongBuffer asLongBuffer() {
+ int size = this.remaining() >> 3;
+ int off = offset + position();
+ return (bigEndian
+ ? (LongBuffer)(new ByteBufferAsLongBuffer$RW$B(this,
+ -1,
+ 0,
+ size,
+ size,
+ off))
+ : (LongBuffer)(new ByteBufferAsLongBuffer$RW$L(this,
+ -1,
+ 0,
+ size,
+ size,
+ off)));
+ }
+
+
+ // float
+
+#if[rw]
+
+ public float getFloat() {
+ return Bits.getFloat(this, ix(nextGetIndex(4)), bigEndian);
+ }
+
+ public float getFloat(int i) {
+ return Bits.getFloat(this, ix(checkIndex(i, 4)), bigEndian);
+ }
+
+#end[rw]
+
+ public $Type$Buffer putFloat(float x) {
+#if[rw]
+ Bits.putFloat(this, ix(nextPutIndex(4)), x, bigEndian);
+ return this;
+#else[rw]
+ throw new ReadOnlyBufferException();
+#end[rw]
+ }
+
+ public $Type$Buffer putFloat(int i, float x) {
+#if[rw]
+ Bits.putFloat(this, ix(checkIndex(i, 4)), x, bigEndian);
+ return this;
+#else[rw]
+ throw new ReadOnlyBufferException();
+#end[rw]
+ }
+
+ public FloatBuffer asFloatBuffer() {
+ int size = this.remaining() >> 2;
+ int off = offset + position();
+ return (bigEndian
+ ? (FloatBuffer)(new ByteBufferAsFloatBuffer$RW$B(this,
+ -1,
+ 0,
+ size,
+ size,
+ off))
+ : (FloatBuffer)(new ByteBufferAsFloatBuffer$RW$L(this,
+ -1,
+ 0,
+ size,
+ size,
+ off)));
+ }
+
+
+ // double
+
+#if[rw]
+
+ public double getDouble() {
+ return Bits.getDouble(this, ix(nextGetIndex(8)), bigEndian);
+ }
+
+ public double getDouble(int i) {
+ return Bits.getDouble(this, ix(checkIndex(i, 8)), bigEndian);
+ }
+
+#end[rw]
+
+ public $Type$Buffer putDouble(double x) {
+#if[rw]
+ Bits.putDouble(this, ix(nextPutIndex(8)), x, bigEndian);
+ return this;
+#else[rw]
+ throw new ReadOnlyBufferException();
+#end[rw]
+ }
+
+ public $Type$Buffer putDouble(int i, double x) {
+#if[rw]
+ Bits.putDouble(this, ix(checkIndex(i, 8)), x, bigEndian);
+ return this;
+#else[rw]
+ throw new ReadOnlyBufferException();
+#end[rw]
+ }
+
+ public DoubleBuffer asDoubleBuffer() {
+ int size = this.remaining() >> 3;
+ int off = offset + position();
+ return (bigEndian
+ ? (DoubleBuffer)(new ByteBufferAsDoubleBuffer$RW$B(this,
+ -1,
+ 0,
+ size,
+ size,
+ off))
+ : (DoubleBuffer)(new ByteBufferAsDoubleBuffer$RW$L(this,
+ -1,
+ 0,
+ size,
+ size,
+ off)));
+ }
+
+
+#end[byte]
+
+
+#if[char]
+
+ String toString(int start, int end) { // package-private
+ try {
+ return new String(hb, start + offset, end - start);
+ } catch (StringIndexOutOfBoundsException x) {
+ throw new IndexOutOfBoundsException();
+ }
+ }
+
+
+ // --- Methods to support CharSequence ---
+
+ public CharBuffer subSequence(int start, int end) {
+ if ((start < 0)
+ || (end > length())
+ || (start > end))
+ throw new IndexOutOfBoundsException();
+ int pos = position();
+ return new HeapCharBuffer$RW$(hb,
+ -1,
+ pos + start,
+ pos + end,
+ capacity(),
+ offset);
+ }
+
+#end[char]
+
+
+#if[!byte]
+
+ public ByteOrder order() {
+ return ByteOrder.nativeOrder();
+ }
+
+#end[!byte]
+
+}
--- a/jdk/src/share/classes/java/nio/X-Buffer-bin.java Wed Oct 28 16:26:52 2009 -0700
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,132 +0,0 @@
-/*
- * Copyright 2000-2002 Sun Microsystems, Inc. All Rights Reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute 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.
- */
-
-#warn This file is preprocessed before being compiled
-
-class XXX {
-
-#begin
-
- /**
- * Relative <i>get</i> method for reading $a$ $type$ value.
- *
- * <p> Reads the next $nbytes$ bytes at this buffer's current position,
- * composing them into $a$ $type$ value according to the current byte order,
- * and then increments the position by $nbytes$. </p>
- *
- * @return The $type$ value at the buffer's current position
- *
- * @throws BufferUnderflowException
- * If there are fewer than $nbytes$ bytes
- * remaining in this buffer
- */
- public abstract $type$ get$Type$();
-
- /**
- * Relative <i>put</i> method for writing $a$ $type$
- * value <i>(optional operation)</i>.
- *
- * <p> Writes $nbytes$ bytes containing the given $type$ value, in the
- * current byte order, into this buffer at the current position, and then
- * increments the position by $nbytes$. </p>
- *
- * @param value
- * The $type$ value to be written
- *
- * @return This buffer
- *
- * @throws BufferOverflowException
- * If there are fewer than $nbytes$ bytes
- * remaining in this buffer
- *
- * @throws ReadOnlyBufferException
- * If this buffer is read-only
- */
- public abstract ByteBuffer put$Type$($type$ value);
-
- /**
- * Absolute <i>get</i> method for reading $a$ $type$ value.
- *
- * <p> Reads $nbytes$ bytes at the given index, composing them into a
- * $type$ value according to the current byte order. </p>
- *
- * @param index
- * The index from which the bytes will be read
- *
- * @return The $type$ value at the given index
- *
- * @throws IndexOutOfBoundsException
- * If <tt>index</tt> is negative
- * or not smaller than the buffer's limit,
- * minus $nbytesButOne$
- */
- public abstract $type$ get$Type$(int index);
-
- /**
- * Absolute <i>put</i> method for writing $a$ $type$
- * value <i>(optional operation)</i>.
- *
- * <p> Writes $nbytes$ bytes containing the given $type$ value, in the
- * current byte order, into this buffer at the given index. </p>
- *
- * @param index
- * The index at which the bytes will be written
- *
- * @param value
- * The $type$ value to be written
- *
- * @return This buffer
- *
- * @throws IndexOutOfBoundsException
- * If <tt>index</tt> is negative
- * or not smaller than the buffer's limit,
- * minus $nbytesButOne$
- *
- * @throws ReadOnlyBufferException
- * If this buffer is read-only
- */
- public abstract ByteBuffer put$Type$(int index, $type$ value);
-
- /**
- * Creates a view of this byte buffer as $a$ $type$ buffer.
- *
- * <p> The content of the new buffer will start at this buffer's current
- * position. Changes to this buffer's content will be visible in the new
- * buffer, and vice versa; the two buffers' position, limit, and mark
- * values will be independent.
- *
- * <p> The new buffer's position will be zero, its capacity and its limit
- * will be the number of bytes remaining in this buffer divided by
- * $nbytes$, and its mark will be undefined. The new buffer will be direct
- * if, and only if, this buffer is direct, and it will be read-only if, and
- * only if, this buffer is read-only. </p>
- *
- * @return A new $type$ buffer
- */
- public abstract $Type$Buffer as$Type$Buffer();
-
-#end
-
-}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/share/classes/java/nio/X-Buffer-bin.java.template Wed Oct 28 16:54:50 2009 -0700
@@ -0,0 +1,132 @@
+/*
+ * Copyright 2000-2002 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute 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.
+ */
+
+#warn This file is preprocessed before being compiled
+
+class XXX {
+
+#begin
+
+ /**
+ * Relative <i>get</i> method for reading $a$ $type$ value.
+ *
+ * <p> Reads the next $nbytes$ bytes at this buffer's current position,
+ * composing them into $a$ $type$ value according to the current byte order,
+ * and then increments the position by $nbytes$. </p>
+ *
+ * @return The $type$ value at the buffer's current position
+ *
+ * @throws BufferUnderflowException
+ * If there are fewer than $nbytes$ bytes
+ * remaining in this buffer
+ */
+ public abstract $type$ get$Type$();
+
+ /**
+ * Relative <i>put</i> method for writing $a$ $type$
+ * value <i>(optional operation)</i>.
+ *
+ * <p> Writes $nbytes$ bytes containing the given $type$ value, in the
+ * current byte order, into this buffer at the current position, and then
+ * increments the position by $nbytes$. </p>
+ *
+ * @param value
+ * The $type$ value to be written
+ *
+ * @return This buffer
+ *
+ * @throws BufferOverflowException
+ * If there are fewer than $nbytes$ bytes
+ * remaining in this buffer
+ *
+ * @throws ReadOnlyBufferException
+ * If this buffer is read-only
+ */
+ public abstract ByteBuffer put$Type$($type$ value);
+
+ /**
+ * Absolute <i>get</i> method for reading $a$ $type$ value.
+ *
+ * <p> Reads $nbytes$ bytes at the given index, composing them into a
+ * $type$ value according to the current byte order. </p>
+ *
+ * @param index
+ * The index from which the bytes will be read
+ *
+ * @return The $type$ value at the given index
+ *
+ * @throws IndexOutOfBoundsException
+ * If <tt>index</tt> is negative
+ * or not smaller than the buffer's limit,
+ * minus $nbytesButOne$
+ */
+ public abstract $type$ get$Type$(int index);
+
+ /**
+ * Absolute <i>put</i> method for writing $a$ $type$
+ * value <i>(optional operation)</i>.
+ *
+ * <p> Writes $nbytes$ bytes containing the given $type$ value, in the
+ * current byte order, into this buffer at the given index. </p>
+ *
+ * @param index
+ * The index at which the bytes will be written
+ *
+ * @param value
+ * The $type$ value to be written
+ *
+ * @return This buffer
+ *
+ * @throws IndexOutOfBoundsException
+ * If <tt>index</tt> is negative
+ * or not smaller than the buffer's limit,
+ * minus $nbytesButOne$
+ *
+ * @throws ReadOnlyBufferException
+ * If this buffer is read-only
+ */
+ public abstract ByteBuffer put$Type$(int index, $type$ value);
+
+ /**
+ * Creates a view of this byte buffer as $a$ $type$ buffer.
+ *
+ * <p> The content of the new buffer will start at this buffer's current
+ * position. Changes to this buffer's content will be visible in the new
+ * buffer, and vice versa; the two buffers' position, limit, and mark
+ * values will be independent.
+ *
+ * <p> The new buffer's position will be zero, its capacity and its limit
+ * will be the number of bytes remaining in this buffer divided by
+ * $nbytes$, and its mark will be undefined. The new buffer will be direct
+ * if, and only if, this buffer is direct, and it will be read-only if, and
+ * only if, this buffer is read-only. </p>
+ *
+ * @return A new $type$ buffer
+ */
+ public abstract $Type$Buffer as$Type$Buffer();
+
+#end
+
+}
--- a/jdk/src/share/classes/java/nio/X-Buffer.java Wed Oct 28 16:26:52 2009 -0700
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,1428 +0,0 @@
-/*
- * Copyright 2000-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.
- */
-
-#warn This file is preprocessed before being compiled
-
-package java.nio;
-
-#if[char]
-import java.io.IOException;
-#end[char]
-
-/**
- * $A$ $fulltype$ buffer.
- *
- * <p> This class defines {#if[byte]?six:four} categories of operations upon
- * $fulltype$ buffers:
- *
- * <ul>
- *
- * <li><p> Absolute and relative {@link #get() </code><i>get</i><code>} and
- * {@link #put($type$) </code><i>put</i><code>} methods that read and write
- * single $fulltype$s; </p></li>
- *
- * <li><p> Relative {@link #get($type$[]) </code><i>bulk get</i><code>}
- * methods that transfer contiguous sequences of $fulltype$s from this buffer
- * into an array; {#if[!byte]?and}</p></li>
- *
- * <li><p> Relative {@link #put($type$[]) </code><i>bulk put</i><code>}
- * methods that transfer contiguous sequences of $fulltype$s from $a$
- * $fulltype$ array{#if[char]?, a string,} or some other $fulltype$
- * buffer into this buffer;{#if[!byte]? and} </p></li>
- *
-#if[byte]
- *
- * <li><p> Absolute and relative {@link #getChar() </code><i>get</i><code>}
- * and {@link #putChar(char) </code><i>put</i><code>} methods that read and
- * write values of other primitive types, translating them to and from
- * sequences of bytes in a particular byte order; </p></li>
- *
- * <li><p> Methods for creating <i><a href="#views">view buffers</a></i>,
- * which allow a byte buffer to be viewed as a buffer containing values of
- * some other primitive type; and </p></li>
- *
-#end[byte]
- *
- * <li><p> Methods for {@link #compact </code>compacting<code>}, {@link
- * #duplicate </code>duplicating<code>}, and {@link #slice
- * </code>slicing<code>} $a$ $fulltype$ buffer. </p></li>
- *
- * </ul>
- *
- * <p> $Fulltype$ buffers can be created either by {@link #allocate
- * </code><i>allocation</i><code>}, which allocates space for the buffer's
- *
-#if[byte]
- *
- * content, or by {@link #wrap($type$[]) </code><i>wrapping</i><code>} an
- * existing $fulltype$ array {#if[char]?or string} into a buffer.
- *
-#else[byte]
- *
- * content, by {@link #wrap($type$[]) </code><i>wrapping</i><code>} an existing
- * $fulltype$ array {#if[char]?or string} into a buffer, or by creating a
- * <a href="ByteBuffer.html#views"><i>view</i></a> of an existing byte buffer.
- *
-#end[byte]
- *
-#if[byte]
- *
- * <a name="direct">
- * <h4> Direct <i>vs.</i> non-direct buffers </h4>
- *
- * <p> A byte buffer is either <i>direct</i> or <i>non-direct</i>. Given a
- * direct byte buffer, the Java virtual machine will make a best effort to
- * perform native I/O operations directly upon it. That is, it will attempt to
- * avoid copying the buffer's content to (or from) an intermediate buffer
- * before (or after) each invocation of one of the underlying operating
- * system's native I/O operations.
- *
- * <p> A direct byte buffer may be created by invoking the {@link
- * #allocateDirect(int) allocateDirect} factory method of this class. The
- * buffers returned by this method typically have somewhat higher allocation
- * and deallocation costs than non-direct buffers. The contents of direct
- * buffers may reside outside of the normal garbage-collected heap, and so
- * their impact upon the memory footprint of an application might not be
- * obvious. It is therefore recommended that direct buffers be allocated
- * primarily for large, long-lived buffers that are subject to the underlying
- * system's native I/O operations. In general it is best to allocate direct
- * buffers only when they yield a measureable gain in program performance.
- *
- * <p> A direct byte buffer may also be created by {@link
- * java.nio.channels.FileChannel#map </code>mapping<code>} a region of a file
- * directly into memory. An implementation of the Java platform may optionally
- * support the creation of direct byte buffers from native code via JNI. If an
- * instance of one of these kinds of buffers refers to an inaccessible region
- * of memory then an attempt to access that region will not change the buffer's
- * content and will cause an unspecified exception to be thrown either at the
- * time of the access or at some later time.
- *
- * <p> Whether a byte buffer is direct or non-direct may be determined by
- * invoking its {@link #isDirect isDirect} method. This method is provided so
- * that explicit buffer management can be done in performance-critical code.
- *
- *
- * <a name="bin">
- * <h4> Access to binary data </h4>
- *
- * <p> This class defines methods for reading and writing values of all other
- * primitive types, except <tt>boolean</tt>. Primitive values are translated
- * to (or from) sequences of bytes according to the buffer's current byte
- * order, which may be retrieved and modified via the {@link #order order}
- * methods. Specific byte orders are represented by instances of the {@link
- * ByteOrder} class. The initial order of a byte buffer is always {@link
- * ByteOrder#BIG_ENDIAN BIG_ENDIAN}.
- *
- * <p> For access to heterogeneous binary data, that is, sequences of values of
- * different types, this class defines a family of absolute and relative
- * <i>get</i> and <i>put</i> methods for each type. For 32-bit floating-point
- * values, for example, this class defines:
- *
- * <blockquote><pre>
- * float {@link #getFloat()}
- * float {@link #getFloat(int) getFloat(int index)}
- * void {@link #putFloat(float) putFloat(float f)}
- * void {@link #putFloat(int,float) putFloat(int index, float f)}</pre></blockquote>
- *
- * <p> Corresponding methods are defined for the types <tt>char</tt>,
- * <tt>short</tt>, <tt>int</tt>, <tt>long</tt>, and <tt>double</tt>. The index
- * parameters of the absolute <i>get</i> and <i>put</i> methods are in terms of
- * bytes rather than of the type being read or written.
- *
- * <a name="views">
- *
- * <p> For access to homogeneous binary data, that is, sequences of values of
- * the same type, this class defines methods that can create <i>views</i> of a
- * given byte buffer. A <i>view buffer</i> is simply another buffer whose
- * content is backed by the byte buffer. Changes to the byte buffer's content
- * will be visible in the view buffer, and vice versa; the two buffers'
- * position, limit, and mark values are independent. The {@link
- * #asFloatBuffer() asFloatBuffer} method, for example, creates an instance of
- * the {@link FloatBuffer} class that is backed by the byte buffer upon which
- * the method is invoked. Corresponding view-creation methods are defined for
- * the types <tt>char</tt>, <tt>short</tt>, <tt>int</tt>, <tt>long</tt>, and
- * <tt>double</tt>.
- *
- * <p> View buffers have three important advantages over the families of
- * type-specific <i>get</i> and <i>put</i> methods described above:
- *
- * <ul>
- *
- * <li><p> A view buffer is indexed not in terms of bytes but rather in terms
- * of the type-specific size of its values; </p></li>
- *
- * <li><p> A view buffer provides relative bulk <i>get</i> and <i>put</i>
- * methods that can transfer contiguous sequences of values between a buffer
- * and an array or some other buffer of the same type; and </p></li>
- *
- * <li><p> A view buffer is potentially much more efficient because it will
- * be direct if, and only if, its backing byte buffer is direct. </p></li>
- *
- * </ul>
- *
- * <p> The byte order of a view buffer is fixed to be that of its byte buffer
- * at the time that the view is created. </p>
- *
-#end[byte]
-*
-#if[!byte]
- *
- * <p> Like a byte buffer, $a$ $fulltype$ buffer is either <a
- * href="ByteBuffer.html#direct"><i>direct</i> or <i>non-direct</i></a>. A
- * $fulltype$ buffer created via the <tt>wrap</tt> methods of this class will
- * be non-direct. $A$ $fulltype$ buffer created as a view of a byte buffer will
- * be direct if, and only if, the byte buffer itself is direct. Whether or not
- * $a$ $fulltype$ buffer is direct may be determined by invoking the {@link
- * #isDirect isDirect} method. </p>
- *
-#end[!byte]
-*
-#if[char]
- *
- * <p> This class implements the {@link CharSequence} interface so that
- * character buffers may be used wherever character sequences are accepted, for
- * example in the regular-expression package <tt>{@link java.util.regex}</tt>.
- * </p>
- *
-#end[char]
- *
-#if[byte]
- * <h4> Invocation chaining </h4>
-#end[byte]
- *
- * <p> Methods in this class that do not otherwise have a value to return are
- * specified to return the buffer upon which they are invoked. This allows
- * method invocations to be chained.
- *
-#if[byte]
- *
- * The sequence of statements
- *
- * <blockquote><pre>
- * bb.putInt(0xCAFEBABE);
- * bb.putShort(3);
- * bb.putShort(45);</pre></blockquote>
- *
- * can, for example, be replaced by the single statement
- *
- * <blockquote><pre>
- * bb.putInt(0xCAFEBABE).putShort(3).putShort(45);</pre></blockquote>
- *
-#end[byte]
-#if[char]
- *
- * The sequence of statements
- *
- * <blockquote><pre>
- * cb.put("text/");
- * cb.put(subtype);
- * cb.put("; charset=");
- * cb.put(enc);</pre></blockquote>
- *
- * can, for example, be replaced by the single statement
- *
- * <blockquote><pre>
- * cb.put("text/").put(subtype).put("; charset=").put(enc);</pre></blockquote>
- *
-#end[char]
- *
- *
- * @author Mark Reinhold
- * @author JSR-51 Expert Group
- * @since 1.4
- */
-
-public abstract class $Type$Buffer
- extends Buffer
- implements Comparable<$Type$Buffer>{#if[char]?, Appendable, CharSequence, Readable}
-{
-
- // These fields are declared here rather than in Heap-X-Buffer in order to
- // reduce the number of virtual method invocations needed to access these
- // values, which is especially costly when coding small buffers.
- //
- final $type$[] hb; // Non-null only for heap buffers
- final int offset;
- boolean isReadOnly; // Valid only for heap buffers
-
- // Creates a new buffer with the given mark, position, limit, capacity,
- // backing array, and array offset
- //
- $Type$Buffer(int mark, int pos, int lim, int cap, // package-private
- $type$[] hb, int offset)
- {
- super(mark, pos, lim, cap);
- this.hb = hb;
- this.offset = offset;
- }
-
- // Creates a new buffer with the given mark, position, limit, and capacity
- //
- $Type$Buffer(int mark, int pos, int lim, int cap) { // package-private
- this(mark, pos, lim, cap, null, 0);
- }
-
-#if[byte]
-
- /**
- * Allocates a new direct $fulltype$ buffer.
- *
- * <p> The new buffer's position will be zero, its limit will be its
- * capacity, its mark will be undefined, and each of its elements will be
- * initialized to zero. Whether or not it has a
- * {@link #hasArray </code>backing array<code>} is unspecified.
- *
- * @param capacity
- * The new buffer's capacity, in $fulltype$s
- *
- * @return The new $fulltype$ buffer
- *
- * @throws IllegalArgumentException
- * If the <tt>capacity</tt> is a negative integer
- */
- public static $Type$Buffer allocateDirect(int capacity) {
- return new Direct$Type$Buffer(capacity);
- }
-
-#end[byte]
-
- /**
- * Allocates a new $fulltype$ buffer.
- *
- * <p> The new buffer's position will be zero, its limit will be its
- * capacity, its mark will be undefined, and each of its elements will be
- * initialized to zero. It will have a {@link #array
- * </code>backing array<code>}, and its {@link #arrayOffset </code>array
- * offset<code>} will be zero.
- *
- * @param capacity
- * The new buffer's capacity, in $fulltype$s
- *
- * @return The new $fulltype$ buffer
- *
- * @throws IllegalArgumentException
- * If the <tt>capacity</tt> is a negative integer
- */
- public static $Type$Buffer allocate(int capacity) {
- if (capacity < 0)
- throw new IllegalArgumentException();
- return new Heap$Type$Buffer(capacity, capacity);
- }
-
- /**
- * Wraps $a$ $fulltype$ array into a buffer.
- *
- * <p> The new buffer will be backed by the given $fulltype$ array;
- * that is, modifications to the buffer will cause the array to be modified
- * and vice versa. The new buffer's capacity will be
- * <tt>array.length</tt>, its position will be <tt>offset</tt>, its limit
- * will be <tt>offset + length</tt>, and its mark will be undefined. Its
- * {@link #array </code>backing array<code>} will be the given array, and
- * its {@link #arrayOffset </code>array offset<code>} will be zero. </p>
- *
- * @param array
- * The array that will back the new buffer
- *
- * @param offset
- * The offset of the subarray to be used; must be non-negative and
- * no larger than <tt>array.length</tt>. The new buffer's position
- * will be set to this value.
- *
- * @param length
- * The length of the subarray to be used;
- * must be non-negative and no larger than
- * <tt>array.length - offset</tt>.
- * The new buffer's limit will be set to <tt>offset + length</tt>.
- *
- * @return The new $fulltype$ buffer
- *
- * @throws IndexOutOfBoundsException
- * If the preconditions on the <tt>offset</tt> and <tt>length</tt>
- * parameters do not hold
- */
- public static $Type$Buffer wrap($type$[] array,
- int offset, int length)
- {
- try {
- return new Heap$Type$Buffer(array, offset, length);
- } catch (IllegalArgumentException x) {
- throw new IndexOutOfBoundsException();
- }
- }
-
- /**
- * Wraps $a$ $fulltype$ array into a buffer.
- *
- * <p> The new buffer will be backed by the given $fulltype$ array;
- * that is, modifications to the buffer will cause the array to be modified
- * and vice versa. The new buffer's capacity and limit will be
- * <tt>array.length</tt>, its position will be zero, and its mark will be
- * undefined. Its {@link #array </code>backing array<code>} will be the
- * given array, and its {@link #arrayOffset </code>array offset<code>} will
- * be zero. </p>
- *
- * @param array
- * The array that will back this buffer
- *
- * @return The new $fulltype$ buffer
- */
- public static $Type$Buffer wrap($type$[] array) {
- return wrap(array, 0, array.length);
- }
-
-#if[char]
-
- /**
- * Attempts to read characters into the specified character buffer.
- * The buffer is used as a repository of characters as-is: the only
- * changes made are the results of a put operation. No flipping or
- * rewinding of the buffer is performed.
- *
- * @param target the buffer to read characters into
- * @return The number of characters added to the buffer, or
- * -1 if this source of characters is at its end
- * @throws IOException if an I/O error occurs
- * @throws NullPointerException if target is null
- * @throws ReadOnlyBufferException if target is a read only buffer
- * @since 1.5
- */
- public int read(CharBuffer target) throws IOException {
- // Determine the number of bytes n that can be transferred
- int targetRemaining = target.remaining();
- int remaining = remaining();
- if (remaining == 0)
- return -1;
- int n = Math.min(remaining, targetRemaining);
- int limit = limit();
- // Set source limit to prevent target overflow
- if (targetRemaining < remaining)
- limit(position() + n);
- try {
- if (n > 0)
- target.put(this);
- } finally {
- limit(limit); // restore real limit
- }
- return n;
- }
-
- /**
- * Wraps a character sequence into a buffer.
- *
- * <p> The content of the new, read-only buffer will be the content of the
- * given character sequence. The buffer's capacity will be
- * <tt>csq.length()</tt>, its position will be <tt>start</tt>, its limit
- * will be <tt>end</tt>, and its mark will be undefined. </p>
- *
- * @param csq
- * The character sequence from which the new character buffer is to
- * be created
- *
- * @param start
- * The index of the first character to be used;
- * must be non-negative and no larger than <tt>csq.length()</tt>.
- * The new buffer's position will be set to this value.
- *
- * @param end
- * The index of the character following the last character to be
- * used; must be no smaller than <tt>start</tt> and no larger
- * than <tt>csq.length()</tt>.
- * The new buffer's limit will be set to this value.
- *
- * @return The new character buffer
- *
- * @throws IndexOutOfBoundsException
- * If the preconditions on the <tt>start</tt> and <tt>end</tt>
- * parameters do not hold
- */
- public static CharBuffer wrap(CharSequence csq, int start, int end) {
- try {
- return new StringCharBuffer(csq, start, end);
- } catch (IllegalArgumentException x) {
- throw new IndexOutOfBoundsException();
- }
- }
-
- /**
- * Wraps a character sequence into a buffer.
- *
- * <p> The content of the new, read-only buffer will be the content of the
- * given character sequence. The new buffer's capacity and limit will be
- * <tt>csq.length()</tt>, its position will be zero, and its mark will be
- * undefined. </p>
- *
- * @param csq
- * The character sequence from which the new character buffer is to
- * be created
- *
- * @return The new character buffer
- */
- public static CharBuffer wrap(CharSequence csq) {
- return wrap(csq, 0, csq.length());
- }
-
-#end[char]
-
- /**
- * Creates a new $fulltype$ buffer whose content is a shared subsequence of
- * this buffer's content.
- *
- * <p> The content of the new buffer will start at this buffer's current
- * position. Changes to this buffer's content will be visible in the new
- * buffer, and vice versa; the two buffers' position, limit, and mark
- * values will be independent.
- *
- * <p> The new buffer's position will be zero, its capacity and its limit
- * will be the number of $fulltype$s remaining in this buffer, and its mark
- * will be undefined. The new buffer will be direct if, and only if, this
- * buffer is direct, and it will be read-only if, and only if, this buffer
- * is read-only. </p>
- *
- * @return The new $fulltype$ buffer
- */
- public abstract $Type$Buffer slice();
-
- /**
- * Creates a new $fulltype$ buffer that shares this buffer's content.
- *
- * <p> The content of the new buffer will be that of this buffer. Changes
- * to this buffer's content will be visible in the new buffer, and vice
- * versa; the two buffers' position, limit, and mark values will be
- * independent.
- *
- * <p> The new buffer's capacity, limit, position, and mark values will be
- * identical to those of this buffer. The new buffer will be direct if,
- * and only if, this buffer is direct, and it will be read-only if, and
- * only if, this buffer is read-only. </p>
- *
- * @return The new $fulltype$ buffer
- */
- public abstract $Type$Buffer duplicate();
-
- /**
- * Creates a new, read-only $fulltype$ buffer that shares this buffer's
- * content.
- *
- * <p> The content of the new buffer will be that of this buffer. Changes
- * to this buffer's content will be visible in the new buffer; the new
- * buffer itself, however, will be read-only and will not allow the shared
- * content to be modified. The two buffers' position, limit, and mark
- * values will be independent.
- *
- * <p> The new buffer's capacity, limit, position, and mark values will be
- * identical to those of this buffer.
- *
- * <p> If this buffer is itself read-only then this method behaves in
- * exactly the same way as the {@link #duplicate duplicate} method. </p>
- *
- * @return The new, read-only $fulltype$ buffer
- */
- public abstract $Type$Buffer asReadOnlyBuffer();
-
-
- // -- Singleton get/put methods --
-
- /**
- * Relative <i>get</i> method. Reads the $fulltype$ at this buffer's
- * current position, and then increments the position. </p>
- *
- * @return The $fulltype$ at the buffer's current position
- *
- * @throws BufferUnderflowException
- * If the buffer's current position is not smaller than its limit
- */
- public abstract $type$ get();
-
- /**
- * Relative <i>put</i> method <i>(optional operation)</i>.
- *
- * <p> Writes the given $fulltype$ into this buffer at the current
- * position, and then increments the position. </p>
- *
- * @param $x$
- * The $fulltype$ to be written
- *
- * @return This buffer
- *
- * @throws BufferOverflowException
- * If this buffer's current position is not smaller than its limit
- *
- * @throws ReadOnlyBufferException
- * If this buffer is read-only
- */
- public abstract $Type$Buffer put($type$ $x$);
-
- /**
- * Absolute <i>get</i> method. Reads the $fulltype$ at the given
- * index. </p>
- *
- * @param index
- * The index from which the $fulltype$ will be read
- *
- * @return The $fulltype$ at the given index
- *
- * @throws IndexOutOfBoundsException
- * If <tt>index</tt> is negative
- * or not smaller than the buffer's limit
- */
- public abstract $type$ get(int index);
-
- /**
- * Absolute <i>put</i> method <i>(optional operation)</i>.
- *
- * <p> Writes the given $fulltype$ into this buffer at the given
- * index. </p>
- *
- * @param index
- * The index at which the $fulltype$ will be written
- *
- * @param $x$
- * The $fulltype$ value to be written
- *
- * @return This buffer
- *
- * @throws IndexOutOfBoundsException
- * If <tt>index</tt> is negative
- * or not smaller than the buffer's limit
- *
- * @throws ReadOnlyBufferException
- * If this buffer is read-only
- */
- public abstract $Type$Buffer put(int index, $type$ $x$);
-
-
- // -- Bulk get operations --
-
- /**
- * Relative bulk <i>get</i> method.
- *
- * <p> This method transfers $fulltype$s from this buffer into the given
- * destination array. If there are fewer $fulltype$s remaining in the
- * buffer than are required to satisfy the request, that is, if
- * <tt>length</tt> <tt>></tt> <tt>remaining()</tt>, then no
- * $fulltype$s are transferred and a {@link BufferUnderflowException} is
- * thrown.
- *
- * <p> Otherwise, this method copies <tt>length</tt> $fulltype$s from this
- * buffer into the given array, starting at the current position of this
- * buffer and at the given offset in the array. The position of this
- * buffer is then incremented by <tt>length</tt>.
- *
- * <p> In other words, an invocation of this method of the form
- * <tt>src.get(dst, off, len)</tt> has exactly the same effect as
- * the loop
- *
- * <pre>
- * for (int i = off; i < off + len; i++)
- * dst[i] = src.get(); </pre>
- *
- * except that it first checks that there are sufficient $fulltype$s in
- * this buffer and it is potentially much more efficient. </p>
- *
- * @param dst
- * The array into which $fulltype$s are to be written
- *
- * @param offset
- * The offset within the array of the first $fulltype$ to be
- * written; must be non-negative and no larger than
- * <tt>dst.length</tt>
- *
- * @param length
- * The maximum number of $fulltype$s to be written to the given
- * array; must be non-negative and no larger than
- * <tt>dst.length - offset</tt>
- *
- * @return This buffer
- *
- * @throws BufferUnderflowException
- * If there are fewer than <tt>length</tt> $fulltype$s
- * remaining in this buffer
- *
- * @throws IndexOutOfBoundsException
- * If the preconditions on the <tt>offset</tt> and <tt>length</tt>
- * parameters do not hold
- */
- public $Type$Buffer get($type$[] dst, int offset, int length) {
- checkBounds(offset, length, dst.length);
- if (length > remaining())
- throw new BufferUnderflowException();
- int end = offset + length;
- for (int i = offset; i < end; i++)
- dst[i] = get();
- return this;
- }
-
- /**
- * Relative bulk <i>get</i> method.
- *
- * <p> This method transfers $fulltype$s from this buffer into the given
- * destination array. An invocation of this method of the form
- * <tt>src.get(a)</tt> behaves in exactly the same way as the invocation
- *
- * <pre>
- * src.get(a, 0, a.length) </pre>
- *
- * @return This buffer
- *
- * @throws BufferUnderflowException
- * If there are fewer than <tt>length</tt> $fulltype$s
- * remaining in this buffer
- */
- public $Type$Buffer get($type$[] dst) {
- return get(dst, 0, dst.length);
- }
-
-
- // -- Bulk put operations --
-
- /**
- * Relative bulk <i>put</i> method <i>(optional operation)</i>.
- *
- * <p> This method transfers the $fulltype$s remaining in the given source
- * buffer into this buffer. If there are more $fulltype$s remaining in the
- * source buffer than in this buffer, that is, if
- * <tt>src.remaining()</tt> <tt>></tt> <tt>remaining()</tt>,
- * then no $fulltype$s are transferred and a {@link
- * BufferOverflowException} is thrown.
- *
- * <p> Otherwise, this method copies
- * <i>n</i> = <tt>src.remaining()</tt> $fulltype$s from the given
- * buffer into this buffer, starting at each buffer's current position.
- * The positions of both buffers are then incremented by <i>n</i>.
- *
- * <p> In other words, an invocation of this method of the form
- * <tt>dst.put(src)</tt> has exactly the same effect as the loop
- *
- * <pre>
- * while (src.hasRemaining())
- * dst.put(src.get()); </pre>
- *
- * except that it first checks that there is sufficient space in this
- * buffer and it is potentially much more efficient. </p>
- *
- * @param src
- * The source buffer from which $fulltype$s are to be read;
- * must not be this buffer
- *
- * @return This buffer
- *
- * @throws BufferOverflowException
- * If there is insufficient space in this buffer
- * for the remaining $fulltype$s in the source buffer
- *
- * @throws IllegalArgumentException
- * If the source buffer is this buffer
- *
- * @throws ReadOnlyBufferException
- * If this buffer is read-only
- */
- public $Type$Buffer put($Type$Buffer src) {
- if (src == this)
- throw new IllegalArgumentException();
- int n = src.remaining();
- if (n > remaining())
- throw new BufferOverflowException();
- for (int i = 0; i < n; i++)
- put(src.get());
- return this;
- }
-
- /**
- * Relative bulk <i>put</i> method <i>(optional operation)</i>.
- *
- * <p> This method transfers $fulltype$s into this buffer from the given
- * source array. If there are more $fulltype$s to be copied from the array
- * than remain in this buffer, that is, if
- * <tt>length</tt> <tt>></tt> <tt>remaining()</tt>, then no
- * $fulltype$s are transferred and a {@link BufferOverflowException} is
- * thrown.
- *
- * <p> Otherwise, this method copies <tt>length</tt> $fulltype$s from the
- * given array into this buffer, starting at the given offset in the array
- * and at the current position of this buffer. The position of this buffer
- * is then incremented by <tt>length</tt>.
- *
- * <p> In other words, an invocation of this method of the form
- * <tt>dst.put(src, off, len)</tt> has exactly the same effect as
- * the loop
- *
- * <pre>
- * for (int i = off; i < off + len; i++)
- * dst.put(a[i]); </pre>
- *
- * except that it first checks that there is sufficient space in this
- * buffer and it is potentially much more efficient. </p>
- *
- * @param src
- * The array from which $fulltype$s are to be read
- *
- * @param offset
- * The offset within the array of the first $fulltype$ to be read;
- * must be non-negative and no larger than <tt>array.length</tt>
- *
- * @param length
- * The number of $fulltype$s to be read from the given array;
- * must be non-negative and no larger than
- * <tt>array.length - offset</tt>
- *
- * @return This buffer
- *
- * @throws BufferOverflowException
- * If there is insufficient space in this buffer
- *
- * @throws IndexOutOfBoundsException
- * If the preconditions on the <tt>offset</tt> and <tt>length</tt>
- * parameters do not hold
- *
- * @throws ReadOnlyBufferException
- * If this buffer is read-only
- */
- public $Type$Buffer put($type$[] src, int offset, int length) {
- checkBounds(offset, length, src.length);
- if (length > remaining())
- throw new BufferOverflowException();
- int end = offset + length;
- for (int i = offset; i < end; i++)
- this.put(src[i]);
- return this;
- }
-
- /**
- * Relative bulk <i>put</i> method <i>(optional operation)</i>.
- *
- * <p> This method transfers the entire content of the given source
- * $fulltype$ array into this buffer. An invocation of this method of the
- * form <tt>dst.put(a)</tt> behaves in exactly the same way as the
- * invocation
- *
- * <pre>
- * dst.put(a, 0, a.length) </pre>
- *
- * @return This buffer
- *
- * @throws BufferOverflowException
- * If there is insufficient space in this buffer
- *
- * @throws ReadOnlyBufferException
- * If this buffer is read-only
- */
- public final $Type$Buffer put($type$[] src) {
- return put(src, 0, src.length);
- }
-
-#if[char]
-
- /**
- * Relative bulk <i>put</i> method <i>(optional operation)</i>.
- *
- * <p> This method transfers $fulltype$s from the given string into this
- * buffer. If there are more $fulltype$s to be copied from the string than
- * remain in this buffer, that is, if
- * <tt>end - start</tt> <tt>></tt> <tt>remaining()</tt>,
- * then no $fulltype$s are transferred and a {@link
- * BufferOverflowException} is thrown.
- *
- * <p> Otherwise, this method copies
- * <i>n</i> = <tt>end</tt> - <tt>start</tt> $fulltype$s
- * from the given string into this buffer, starting at the given
- * <tt>start</tt> index and at the current position of this buffer. The
- * position of this buffer is then incremented by <i>n</i>.
- *
- * <p> In other words, an invocation of this method of the form
- * <tt>dst.put(src, start, end)</tt> has exactly the same effect
- * as the loop
- *
- * <pre>
- * for (int i = start; i < end; i++)
- * dst.put(src.charAt(i)); </pre>
- *
- * except that it first checks that there is sufficient space in this
- * buffer and it is potentially much more efficient. </p>
- *
- * @param src
- * The string from which $fulltype$s are to be read
- *
- * @param start
- * The offset within the string of the first $fulltype$ to be read;
- * must be non-negative and no larger than
- * <tt>string.length()</tt>
- *
- * @param end
- * The offset within the string of the last $fulltype$ to be read,
- * plus one; must be non-negative and no larger than
- * <tt>string.length()</tt>
- *
- * @return This buffer
- *
- * @throws BufferOverflowException
- * If there is insufficient space in this buffer
- *
- * @throws IndexOutOfBoundsException
- * If the preconditions on the <tt>start</tt> and <tt>end</tt>
- * parameters do not hold
- *
- * @throws ReadOnlyBufferException
- * If this buffer is read-only
- */
- public $Type$Buffer put(String src, int start, int end) {
- checkBounds(start, end - start, src.length());
- for (int i = start; i < end; i++)
- this.put(src.charAt(i));
- return this;
- }
-
- /**
- * Relative bulk <i>put</i> method <i>(optional operation)</i>.
- *
- * <p> This method transfers the entire content of the given source string
- * into this buffer. An invocation of this method of the form
- * <tt>dst.put(s)</tt> behaves in exactly the same way as the invocation
- *
- * <pre>
- * dst.put(s, 0, s.length()) </pre>
- *
- * @return This buffer
- *
- * @throws BufferOverflowException
- * If there is insufficient space in this buffer
- *
- * @throws ReadOnlyBufferException
- * If this buffer is read-only
- */
- public final $Type$Buffer put(String src) {
- return put(src, 0, src.length());
- }
-
-#end[char]
-
-
- // -- Other stuff --
-
- /**
- * Tells whether or not this buffer is backed by an accessible $fulltype$
- * array.
- *
- * <p> If this method returns <tt>true</tt> then the {@link #array() array}
- * and {@link #arrayOffset() arrayOffset} methods may safely be invoked.
- * </p>
- *
- * @return <tt>true</tt> if, and only if, this buffer
- * is backed by an array and is not read-only
- */
- public final boolean hasArray() {
- return (hb != null) && !isReadOnly;
- }
-
- /**
- * Returns the $fulltype$ array that backs this
- * buffer <i>(optional operation)</i>.
- *
- * <p> Modifications to this buffer's content will cause the returned
- * array's content to be modified, and vice versa.
- *
- * <p> Invoke the {@link #hasArray hasArray} method before invoking this
- * method in order to ensure that this buffer has an accessible backing
- * array. </p>
- *
- * @return The array that backs this buffer
- *
- * @throws ReadOnlyBufferException
- * If this buffer is backed by an array but is read-only
- *
- * @throws UnsupportedOperationException
- * If this buffer is not backed by an accessible array
- */
- public final $type$[] array() {
- if (hb == null)
- throw new UnsupportedOperationException();
- if (isReadOnly)
- throw new ReadOnlyBufferException();
- return hb;
- }
-
- /**
- * Returns the offset within this buffer's backing array of the first
- * element of the buffer <i>(optional operation)</i>.
- *
- * <p> If this buffer is backed by an array then buffer position <i>p</i>
- * corresponds to array index <i>p</i> + <tt>arrayOffset()</tt>.
- *
- * <p> Invoke the {@link #hasArray hasArray} method before invoking this
- * method in order to ensure that this buffer has an accessible backing
- * array. </p>
- *
- * @return The offset within this buffer's array
- * of the first element of the buffer
- *
- * @throws ReadOnlyBufferException
- * If this buffer is backed by an array but is read-only
- *
- * @throws UnsupportedOperationException
- * If this buffer is not backed by an accessible array
- */
- public final int arrayOffset() {
- if (hb == null)
- throw new UnsupportedOperationException();
- if (isReadOnly)
- throw new ReadOnlyBufferException();
- return offset;
- }
-
- /**
- * Compacts this buffer <i>(optional operation)</i>.
- *
- * <p> The $fulltype$s between the buffer's current position and its limit,
- * if any, are copied to the beginning of the buffer. That is, the
- * $fulltype$ at index <i>p</i> = <tt>position()</tt> is copied
- * to index zero, the $fulltype$ at index <i>p</i> + 1 is copied
- * to index one, and so forth until the $fulltype$ at index
- * <tt>limit()</tt> - 1 is copied to index
- * <i>n</i> = <tt>limit()</tt> - <tt>1</tt> - <i>p</i>.
- * The buffer's position is then set to <i>n+1</i> and its limit is set to
- * its capacity. The mark, if defined, is discarded.
- *
- * <p> The buffer's position is set to the number of $fulltype$s copied,
- * rather than to zero, so that an invocation of this method can be
- * followed immediately by an invocation of another relative <i>put</i>
- * method. </p>
- *
-#if[byte]
- *
- * <p> Invoke this method after writing data from a buffer in case the
- * write was incomplete. The following loop, for example, copies bytes
- * from one channel to another via the buffer <tt>buf</tt>:
- *
- * <blockquote><pre>
- * buf.clear(); // Prepare buffer for use
- * while (in.read(buf) >= 0 || buf.position != 0) {
- * buf.flip();
- * out.write(buf);
- * buf.compact(); // In case of partial write
- * }</pre></blockquote>
- *
-#end[byte]
- *
- * @return This buffer
- *
- * @throws ReadOnlyBufferException
- * If this buffer is read-only
- */
- public abstract $Type$Buffer compact();
-
- /**
- * Tells whether or not this $fulltype$ buffer is direct. </p>
- *
- * @return <tt>true</tt> if, and only if, this buffer is direct
- */
- public abstract boolean isDirect();
-
-#if[!char]
-
- /**
- * Returns a string summarizing the state of this buffer. </p>
- *
- * @return A summary string
- */
- public String toString() {
- StringBuffer sb = new StringBuffer();
- sb.append(getClass().getName());
- sb.append("[pos=");
- sb.append(position());
- sb.append(" lim=");
- sb.append(limit());
- sb.append(" cap=");
- sb.append(capacity());
- sb.append("]");
- return sb.toString();
- }
-
-#end[!char]
-
-
- // ## Should really use unchecked accessors here for speed
-
- /**
- * Returns the current hash code of this buffer.
- *
- * <p> The hash code of a $type$ buffer depends only upon its remaining
- * elements; that is, upon the elements from <tt>position()</tt> up to, and
- * including, the element at <tt>limit()</tt> - <tt>1</tt>.
- *
- * <p> Because buffer hash codes are content-dependent, it is inadvisable
- * to use buffers as keys in hash maps or similar data structures unless it
- * is known that their contents will not change. </p>
- *
- * @return The current hash code of this buffer
- */
- public int hashCode() {
- int h = 1;
- int p = position();
- for (int i = limit() - 1; i >= p; i--)
- h = 31 * h + (int)get(i);
- return h;
- }
-
- /**
- * Tells whether or not this buffer is equal to another object.
- *
- * <p> Two $type$ buffers are equal if, and only if,
- *
- * <p><ol>
- *
- * <li><p> They have the same element type, </p></li>
- *
- * <li><p> They have the same number of remaining elements, and
- * </p></li>
- *
- * <li><p> The two sequences of remaining elements, considered
- * independently of their starting positions, are pointwise equal.
- * </p></li>
- *
- * </ol>
- *
- * <p> A $type$ buffer is not equal to any other type of object. </p>
- *
- * @param ob The object to which this buffer is to be compared
- *
- * @return <tt>true</tt> if, and only if, this buffer is equal to the
- * given object
- */
- public boolean equals(Object ob) {
- if (this == ob)
- return true;
- if (!(ob instanceof $Type$Buffer))
- return false;
- $Type$Buffer that = ($Type$Buffer)ob;
- if (this.remaining() != that.remaining())
- return false;
- int p = this.position();
- for (int i = this.limit() - 1, j = that.limit() - 1; i >= p; i--, j--) {
- $type$ v1 = this.get(i);
- $type$ v2 = that.get(j);
- if (v1 != v2) {
- if ((v1 != v1) && (v2 != v2)) // For float and double
- continue;
- return false;
- }
- }
- return true;
- }
-
- /**
- * Compares this buffer to another.
- *
- * <p> Two $type$ buffers are compared by comparing their sequences of
- * remaining elements lexicographically, without regard to the starting
- * position of each sequence within its corresponding buffer.
- *
- * <p> A $type$ buffer is not comparable to any other type of object.
- *
- * @return A negative integer, zero, or a positive integer as this buffer
- * is less than, equal to, or greater than the given buffer
- */
- public int compareTo($Type$Buffer that) {
- int n = this.position() + Math.min(this.remaining(), that.remaining());
- for (int i = this.position(), j = that.position(); i < n; i++, j++) {
- $type$ v1 = this.get(i);
- $type$ v2 = that.get(j);
- if (v1 == v2)
- continue;
- if ((v1 != v1) && (v2 != v2)) // For float and double
- continue;
- if (v1 < v2)
- return -1;
- return +1;
- }
- return this.remaining() - that.remaining();
- }
-
-
-
- // -- Other char stuff --
-
-#if[char]
-
- /**
- * Returns a string containing the characters in this buffer.
- *
- * <p> The first character of the resulting string will be the character at
- * this buffer's position, while the last character will be the character
- * at index <tt>limit()</tt> - 1. Invoking this method does not
- * change the buffer's position. </p>
- *
- * @return The specified string
- */
- public String toString() {
- return toString(position(), limit());
- }
-
- abstract String toString(int start, int end); // package-private
-
-
- // --- Methods to support CharSequence ---
-
- /**
- * Returns the length of this character buffer.
- *
- * <p> When viewed as a character sequence, the length of a character
- * buffer is simply the number of characters between the position
- * (inclusive) and the limit (exclusive); that is, it is equivalent to
- * <tt>remaining()</tt>. </p>
- *
- * @return The length of this character buffer
- */
- public final int length() {
- return remaining();
- }
-
- /**
- * Reads the character at the given index relative to the current
- * position. </p>
- *
- * @param index
- * The index of the character to be read, relative to the position;
- * must be non-negative and smaller than <tt>remaining()</tt>
- *
- * @return The character at index
- * <tt>position() + index</tt>
- *
- * @throws IndexOutOfBoundsException
- * If the preconditions on <tt>index</tt> do not hold
- */
- public final char charAt(int index) {
- return get(position() + checkIndex(index, 1));
- }
-
- /**
- * Creates a new character buffer that represents the specified subsequence
- * of this buffer, relative to the current position.
- *
- * <p> The new buffer will share this buffer's content; that is, if the
- * content of this buffer is mutable then modifications to one buffer will
- * cause the other to be modified. The new buffer's capacity will be that
- * of this buffer, its position will be
- * <tt>position()</tt> + <tt>start</tt>, and its limit will be
- * <tt>position()</tt> + <tt>end</tt>. The new buffer will be
- * direct if, and only if, this buffer is direct, and it will be read-only
- * if, and only if, this buffer is read-only. </p>
- *
- * @param start
- * The index, relative to the current position, of the first
- * character in the subsequence; must be non-negative and no larger
- * than <tt>remaining()</tt>
- *
- * @param end
- * The index, relative to the current position, of the character
- * following the last character in the subsequence; must be no
- * smaller than <tt>start</tt> and no larger than
- * <tt>remaining()</tt>
- *
- * @return The new character buffer
- *
- * @throws IndexOutOfBoundsException
- * If the preconditions on <tt>start</tt> and <tt>end</tt>
- * do not hold
- */
- public abstract CharBuffer subSequence(int start, int end);
-
-
- // --- Methods to support Appendable ---
-
- /**
- * Appends the specified character sequence to this
- * buffer <i>(optional operation)</i>.
- *
- * <p> An invocation of this method of the form <tt>dst.append(csq)</tt>
- * behaves in exactly the same way as the invocation
- *
- * <pre>
- * dst.put(csq.toString()) </pre>
- *
- * <p> Depending on the specification of <tt>toString</tt> for the
- * character sequence <tt>csq</tt>, the entire sequence may not be
- * appended. For instance, invoking the {@link $Type$Buffer#toString()
- * toString} method of a character buffer will return a subsequence whose
- * content depends upon the buffer's position and limit.
- *
- * @param csq
- * The character sequence to append. If <tt>csq</tt> is
- * <tt>null</tt>, then the four characters <tt>"null"</tt> are
- * appended to this character buffer.
- *
- * @return This buffer
- *
- * @throws BufferOverflowException
- * If there is insufficient space in this buffer
- *
- * @throws ReadOnlyBufferException
- * If this buffer is read-only
- *
- * @since 1.5
- */
- public $Type$Buffer append(CharSequence csq) {
- if (csq == null)
- return put("null");
- else
- return put(csq.toString());
- }
-
- /**
- * Appends a subsequence of the specified character sequence to this
- * buffer <i>(optional operation)</i>.
- *
- * <p> An invocation of this method of the form <tt>dst.append(csq, start,
- * end)</tt> when <tt>csq</tt> is not <tt>null</tt>, behaves in exactly the
- * same way as the invocation
- *
- * <pre>
- * dst.put(csq.subSequence(start, end).toString()) </pre>
- *
- * @param csq
- * The character sequence from which a subsequence will be
- * appended. If <tt>csq</tt> is <tt>null</tt>, then characters
- * will be appended as if <tt>csq</tt> contained the four
- * characters <tt>"null"</tt>.
- *
- * @return This buffer
- *
- * @throws BufferOverflowException
- * If there is insufficient space in this buffer
- *
- * @throws IndexOutOfBoundsException
- * If <tt>start</tt> or <tt>end</tt> are negative, <tt>start</tt>
- * is greater than <tt>end</tt>, or <tt>end</tt> is greater than
- * <tt>csq.length()</tt>
- *
- * @throws ReadOnlyBufferException
- * If this buffer is read-only
- *
- * @since 1.5
- */
- public $Type$Buffer append(CharSequence csq, int start, int end) {
- CharSequence cs = (csq == null ? "null" : csq);
- return put(cs.subSequence(start, end).toString());
- }
-
- /**
- * Appends the specified $fulltype$ to this
- * buffer <i>(optional operation)</i>.
- *
- * <p> An invocation of this method of the form <tt>dst.append($x$)</tt>
- * behaves in exactly the same way as the invocation
- *
- * <pre>
- * dst.put($x$) </pre>
- *
- * @param $x$
- * The 16-bit $fulltype$ to append
- *
- * @return This buffer
- *
- * @throws BufferOverflowException
- * If there is insufficient space in this buffer
- *
- * @throws ReadOnlyBufferException
- * If this buffer is read-only
- *
- * @since 1.5
- */
- public $Type$Buffer append($type$ $x$) {
- return put($x$);
- }
-
-#end[char]
-
-
- // -- Other byte stuff: Access to binary data --
-
-#if[!byte]
-
- /**
- * Retrieves this buffer's byte order.
- *
- * <p> The byte order of $a$ $fulltype$ buffer created by allocation or by
- * wrapping an existing <tt>$type$</tt> array is the {@link
- * ByteOrder#nativeOrder </code>native order<code>} of the underlying
- * hardware. The byte order of $a$ $fulltype$ buffer created as a <a
- * href="ByteBuffer.html#views">view</a> of a byte buffer is that of the
- * byte buffer at the moment that the view is created. </p>
- *
- * @return This buffer's byte order
- */
- public abstract ByteOrder order();
-
-#end[!byte]
-
-#if[byte]
-
- boolean bigEndian // package-private
- = true;
- boolean nativeByteOrder // package-private
- = (Bits.byteOrder() == ByteOrder.BIG_ENDIAN);
-
- /**
- * Retrieves this buffer's byte order.
- *
- * <p> The byte order is used when reading or writing multibyte values, and
- * when creating buffers that are views of this byte buffer. The order of
- * a newly-created byte buffer is always {@link ByteOrder#BIG_ENDIAN
- * BIG_ENDIAN}. </p>
- *
- * @return This buffer's byte order
- */
- public final ByteOrder order() {
- return bigEndian ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN;
- }
-
- /**
- * Modifies this buffer's byte order. </p>
- *
- * @param bo
- * The new byte order,
- * either {@link ByteOrder#BIG_ENDIAN BIG_ENDIAN}
- * or {@link ByteOrder#LITTLE_ENDIAN LITTLE_ENDIAN}
- *
- * @return This buffer
- */
- public final $Type$Buffer order(ByteOrder bo) {
- bigEndian = (bo == ByteOrder.BIG_ENDIAN);
- nativeByteOrder =
- (bigEndian == (Bits.byteOrder() == ByteOrder.BIG_ENDIAN));
- return this;
- }
-
- // Unchecked accessors, for use by ByteBufferAs-X-Buffer classes
- //
- abstract byte _get(int i); // package-private
- abstract void _put(int i, byte b); // package-private
-
- // #BIN
- //
- // Binary-data access methods for short, char, int, long, float,
- // and double will be inserted here
-
-#end[byte]
-
-}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/share/classes/java/nio/X-Buffer.java.template Wed Oct 28 16:54:50 2009 -0700
@@ -0,0 +1,1428 @@
+/*
+ * Copyright 2000-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.
+ */
+
+#warn This file is preprocessed before being compiled
+
+package java.nio;
+
+#if[char]
+import java.io.IOException;
+#end[char]
+
+/**
+ * $A$ $fulltype$ buffer.
+ *
+ * <p> This class defines {#if[byte]?six:four} categories of operations upon
+ * $fulltype$ buffers:
+ *
+ * <ul>
+ *
+ * <li><p> Absolute and relative {@link #get() </code><i>get</i><code>} and
+ * {@link #put($type$) </code><i>put</i><code>} methods that read and write
+ * single $fulltype$s; </p></li>
+ *
+ * <li><p> Relative {@link #get($type$[]) </code><i>bulk get</i><code>}
+ * methods that transfer contiguous sequences of $fulltype$s from this buffer
+ * into an array; {#if[!byte]?and}</p></li>
+ *
+ * <li><p> Relative {@link #put($type$[]) </code><i>bulk put</i><code>}
+ * methods that transfer contiguous sequences of $fulltype$s from $a$
+ * $fulltype$ array{#if[char]?, a string,} or some other $fulltype$
+ * buffer into this buffer;{#if[!byte]? and} </p></li>
+ *
+#if[byte]
+ *
+ * <li><p> Absolute and relative {@link #getChar() </code><i>get</i><code>}
+ * and {@link #putChar(char) </code><i>put</i><code>} methods that read and
+ * write values of other primitive types, translating them to and from
+ * sequences of bytes in a particular byte order; </p></li>
+ *
+ * <li><p> Methods for creating <i><a href="#views">view buffers</a></i>,
+ * which allow a byte buffer to be viewed as a buffer containing values of
+ * some other primitive type; and </p></li>
+ *
+#end[byte]
+ *
+ * <li><p> Methods for {@link #compact </code>compacting<code>}, {@link
+ * #duplicate </code>duplicating<code>}, and {@link #slice
+ * </code>slicing<code>} $a$ $fulltype$ buffer. </p></li>
+ *
+ * </ul>
+ *
+ * <p> $Fulltype$ buffers can be created either by {@link #allocate
+ * </code><i>allocation</i><code>}, which allocates space for the buffer's
+ *
+#if[byte]
+ *
+ * content, or by {@link #wrap($type$[]) </code><i>wrapping</i><code>} an
+ * existing $fulltype$ array {#if[char]?or string} into a buffer.
+ *
+#else[byte]
+ *
+ * content, by {@link #wrap($type$[]) </code><i>wrapping</i><code>} an existing
+ * $fulltype$ array {#if[char]?or string} into a buffer, or by creating a
+ * <a href="ByteBuffer.html#views"><i>view</i></a> of an existing byte buffer.
+ *
+#end[byte]
+ *
+#if[byte]
+ *
+ * <a name="direct">
+ * <h4> Direct <i>vs.</i> non-direct buffers </h4>
+ *
+ * <p> A byte buffer is either <i>direct</i> or <i>non-direct</i>. Given a
+ * direct byte buffer, the Java virtual machine will make a best effort to
+ * perform native I/O operations directly upon it. That is, it will attempt to
+ * avoid copying the buffer's content to (or from) an intermediate buffer
+ * before (or after) each invocation of one of the underlying operating
+ * system's native I/O operations.
+ *
+ * <p> A direct byte buffer may be created by invoking the {@link
+ * #allocateDirect(int) allocateDirect} factory method of this class. The
+ * buffers returned by this method typically have somewhat higher allocation
+ * and deallocation costs than non-direct buffers. The contents of direct
+ * buffers may reside outside of the normal garbage-collected heap, and so
+ * their impact upon the memory footprint of an application might not be
+ * obvious. It is therefore recommended that direct buffers be allocated
+ * primarily for large, long-lived buffers that are subject to the underlying
+ * system's native I/O operations. In general it is best to allocate direct
+ * buffers only when they yield a measureable gain in program performance.
+ *
+ * <p> A direct byte buffer may also be created by {@link
+ * java.nio.channels.FileChannel#map </code>mapping<code>} a region of a file
+ * directly into memory. An implementation of the Java platform may optionally
+ * support the creation of direct byte buffers from native code via JNI. If an
+ * instance of one of these kinds of buffers refers to an inaccessible region
+ * of memory then an attempt to access that region will not change the buffer's
+ * content and will cause an unspecified exception to be thrown either at the
+ * time of the access or at some later time.
+ *
+ * <p> Whether a byte buffer is direct or non-direct may be determined by
+ * invoking its {@link #isDirect isDirect} method. This method is provided so
+ * that explicit buffer management can be done in performance-critical code.
+ *
+ *
+ * <a name="bin">
+ * <h4> Access to binary data </h4>
+ *
+ * <p> This class defines methods for reading and writing values of all other
+ * primitive types, except <tt>boolean</tt>. Primitive values are translated
+ * to (or from) sequences of bytes according to the buffer's current byte
+ * order, which may be retrieved and modified via the {@link #order order}
+ * methods. Specific byte orders are represented by instances of the {@link
+ * ByteOrder} class. The initial order of a byte buffer is always {@link
+ * ByteOrder#BIG_ENDIAN BIG_ENDIAN}.
+ *
+ * <p> For access to heterogeneous binary data, that is, sequences of values of
+ * different types, this class defines a family of absolute and relative
+ * <i>get</i> and <i>put</i> methods for each type. For 32-bit floating-point
+ * values, for example, this class defines:
+ *
+ * <blockquote><pre>
+ * float {@link #getFloat()}
+ * float {@link #getFloat(int) getFloat(int index)}
+ * void {@link #putFloat(float) putFloat(float f)}
+ * void {@link #putFloat(int,float) putFloat(int index, float f)}</pre></blockquote>
+ *
+ * <p> Corresponding methods are defined for the types <tt>char</tt>,
+ * <tt>short</tt>, <tt>int</tt>, <tt>long</tt>, and <tt>double</tt>. The index
+ * parameters of the absolute <i>get</i> and <i>put</i> methods are in terms of
+ * bytes rather than of the type being read or written.
+ *
+ * <a name="views">
+ *
+ * <p> For access to homogeneous binary data, that is, sequences of values of
+ * the same type, this class defines methods that can create <i>views</i> of a
+ * given byte buffer. A <i>view buffer</i> is simply another buffer whose
+ * content is backed by the byte buffer. Changes to the byte buffer's content
+ * will be visible in the view buffer, and vice versa; the two buffers'
+ * position, limit, and mark values are independent. The {@link
+ * #asFloatBuffer() asFloatBuffer} method, for example, creates an instance of
+ * the {@link FloatBuffer} class that is backed by the byte buffer upon which
+ * the method is invoked. Corresponding view-creation methods are defined for
+ * the types <tt>char</tt>, <tt>short</tt>, <tt>int</tt>, <tt>long</tt>, and
+ * <tt>double</tt>.
+ *
+ * <p> View buffers have three important advantages over the families of
+ * type-specific <i>get</i> and <i>put</i> methods described above:
+ *
+ * <ul>
+ *
+ * <li><p> A view buffer is indexed not in terms of bytes but rather in terms
+ * of the type-specific size of its values; </p></li>
+ *
+ * <li><p> A view buffer provides relative bulk <i>get</i> and <i>put</i>
+ * methods that can transfer contiguous sequences of values between a buffer
+ * and an array or some other buffer of the same type; and </p></li>
+ *
+ * <li><p> A view buffer is potentially much more efficient because it will
+ * be direct if, and only if, its backing byte buffer is direct. </p></li>
+ *
+ * </ul>
+ *
+ * <p> The byte order of a view buffer is fixed to be that of its byte buffer
+ * at the time that the view is created. </p>
+ *
+#end[byte]
+*
+#if[!byte]
+ *
+ * <p> Like a byte buffer, $a$ $fulltype$ buffer is either <a
+ * href="ByteBuffer.html#direct"><i>direct</i> or <i>non-direct</i></a>. A
+ * $fulltype$ buffer created via the <tt>wrap</tt> methods of this class will
+ * be non-direct. $A$ $fulltype$ buffer created as a view of a byte buffer will
+ * be direct if, and only if, the byte buffer itself is direct. Whether or not
+ * $a$ $fulltype$ buffer is direct may be determined by invoking the {@link
+ * #isDirect isDirect} method. </p>
+ *
+#end[!byte]
+*
+#if[char]
+ *
+ * <p> This class implements the {@link CharSequence} interface so that
+ * character buffers may be used wherever character sequences are accepted, for
+ * example in the regular-expression package <tt>{@link java.util.regex}</tt>.
+ * </p>
+ *
+#end[char]
+ *
+#if[byte]
+ * <h4> Invocation chaining </h4>
+#end[byte]
+ *
+ * <p> Methods in this class that do not otherwise have a value to return are
+ * specified to return the buffer upon which they are invoked. This allows
+ * method invocations to be chained.
+ *
+#if[byte]
+ *
+ * The sequence of statements
+ *
+ * <blockquote><pre>
+ * bb.putInt(0xCAFEBABE);
+ * bb.putShort(3);
+ * bb.putShort(45);</pre></blockquote>
+ *
+ * can, for example, be replaced by the single statement
+ *
+ * <blockquote><pre>
+ * bb.putInt(0xCAFEBABE).putShort(3).putShort(45);</pre></blockquote>
+ *
+#end[byte]
+#if[char]
+ *
+ * The sequence of statements
+ *
+ * <blockquote><pre>
+ * cb.put("text/");
+ * cb.put(subtype);
+ * cb.put("; charset=");
+ * cb.put(enc);</pre></blockquote>
+ *
+ * can, for example, be replaced by the single statement
+ *
+ * <blockquote><pre>
+ * cb.put("text/").put(subtype).put("; charset=").put(enc);</pre></blockquote>
+ *
+#end[char]
+ *
+ *
+ * @author Mark Reinhold
+ * @author JSR-51 Expert Group
+ * @since 1.4
+ */
+
+public abstract class $Type$Buffer
+ extends Buffer
+ implements Comparable<$Type$Buffer>{#if[char]?, Appendable, CharSequence, Readable}
+{
+
+ // These fields are declared here rather than in Heap-X-Buffer in order to
+ // reduce the number of virtual method invocations needed to access these
+ // values, which is especially costly when coding small buffers.
+ //
+ final $type$[] hb; // Non-null only for heap buffers
+ final int offset;
+ boolean isReadOnly; // Valid only for heap buffers
+
+ // Creates a new buffer with the given mark, position, limit, capacity,
+ // backing array, and array offset
+ //
+ $Type$Buffer(int mark, int pos, int lim, int cap, // package-private
+ $type$[] hb, int offset)
+ {
+ super(mark, pos, lim, cap);
+ this.hb = hb;
+ this.offset = offset;
+ }
+
+ // Creates a new buffer with the given mark, position, limit, and capacity
+ //
+ $Type$Buffer(int mark, int pos, int lim, int cap) { // package-private
+ this(mark, pos, lim, cap, null, 0);
+ }
+
+#if[byte]
+
+ /**
+ * Allocates a new direct $fulltype$ buffer.
+ *
+ * <p> The new buffer's position will be zero, its limit will be its
+ * capacity, its mark will be undefined, and each of its elements will be
+ * initialized to zero. Whether or not it has a
+ * {@link #hasArray </code>backing array<code>} is unspecified.
+ *
+ * @param capacity
+ * The new buffer's capacity, in $fulltype$s
+ *
+ * @return The new $fulltype$ buffer
+ *
+ * @throws IllegalArgumentException
+ * If the <tt>capacity</tt> is a negative integer
+ */
+ public static $Type$Buffer allocateDirect(int capacity) {
+ return new Direct$Type$Buffer(capacity);
+ }
+
+#end[byte]
+
+ /**
+ * Allocates a new $fulltype$ buffer.
+ *
+ * <p> The new buffer's position will be zero, its limit will be its
+ * capacity, its mark will be undefined, and each of its elements will be
+ * initialized to zero. It will have a {@link #array
+ * </code>backing array<code>}, and its {@link #arrayOffset </code>array
+ * offset<code>} will be zero.
+ *
+ * @param capacity
+ * The new buffer's capacity, in $fulltype$s
+ *
+ * @return The new $fulltype$ buffer
+ *
+ * @throws IllegalArgumentException
+ * If the <tt>capacity</tt> is a negative integer
+ */
+ public static $Type$Buffer allocate(int capacity) {
+ if (capacity < 0)
+ throw new IllegalArgumentException();
+ return new Heap$Type$Buffer(capacity, capacity);
+ }
+
+ /**
+ * Wraps $a$ $fulltype$ array into a buffer.
+ *
+ * <p> The new buffer will be backed by the given $fulltype$ array;
+ * that is, modifications to the buffer will cause the array to be modified
+ * and vice versa. The new buffer's capacity will be
+ * <tt>array.length</tt>, its position will be <tt>offset</tt>, its limit
+ * will be <tt>offset + length</tt>, and its mark will be undefined. Its
+ * {@link #array </code>backing array<code>} will be the given array, and
+ * its {@link #arrayOffset </code>array offset<code>} will be zero. </p>
+ *
+ * @param array
+ * The array that will back the new buffer
+ *
+ * @param offset
+ * The offset of the subarray to be used; must be non-negative and
+ * no larger than <tt>array.length</tt>. The new buffer's position
+ * will be set to this value.
+ *
+ * @param length
+ * The length of the subarray to be used;
+ * must be non-negative and no larger than
+ * <tt>array.length - offset</tt>.
+ * The new buffer's limit will be set to <tt>offset + length</tt>.
+ *
+ * @return The new $fulltype$ buffer
+ *
+ * @throws IndexOutOfBoundsException
+ * If the preconditions on the <tt>offset</tt> and <tt>length</tt>
+ * parameters do not hold
+ */
+ public static $Type$Buffer wrap($type$[] array,
+ int offset, int length)
+ {
+ try {
+ return new Heap$Type$Buffer(array, offset, length);
+ } catch (IllegalArgumentException x) {
+ throw new IndexOutOfBoundsException();
+ }
+ }
+
+ /**
+ * Wraps $a$ $fulltype$ array into a buffer.
+ *
+ * <p> The new buffer will be backed by the given $fulltype$ array;
+ * that is, modifications to the buffer will cause the array to be modified
+ * and vice versa. The new buffer's capacity and limit will be
+ * <tt>array.length</tt>, its position will be zero, and its mark will be
+ * undefined. Its {@link #array </code>backing array<code>} will be the
+ * given array, and its {@link #arrayOffset </code>array offset<code>} will
+ * be zero. </p>
+ *
+ * @param array
+ * The array that will back this buffer
+ *
+ * @return The new $fulltype$ buffer
+ */
+ public static $Type$Buffer wrap($type$[] array) {
+ return wrap(array, 0, array.length);
+ }
+
+#if[char]
+
+ /**
+ * Attempts to read characters into the specified character buffer.
+ * The buffer is used as a repository of characters as-is: the only
+ * changes made are the results of a put operation. No flipping or
+ * rewinding of the buffer is performed.
+ *
+ * @param target the buffer to read characters into
+ * @return The number of characters added to the buffer, or
+ * -1 if this source of characters is at its end
+ * @throws IOException if an I/O error occurs
+ * @throws NullPointerException if target is null
+ * @throws ReadOnlyBufferException if target is a read only buffer
+ * @since 1.5
+ */
+ public int read(CharBuffer target) throws IOException {
+ // Determine the number of bytes n that can be transferred
+ int targetRemaining = target.remaining();
+ int remaining = remaining();
+ if (remaining == 0)
+ return -1;
+ int n = Math.min(remaining, targetRemaining);
+ int limit = limit();
+ // Set source limit to prevent target overflow
+ if (targetRemaining < remaining)
+ limit(position() + n);
+ try {
+ if (n > 0)
+ target.put(this);
+ } finally {
+ limit(limit); // restore real limit
+ }
+ return n;
+ }
+
+ /**
+ * Wraps a character sequence into a buffer.
+ *
+ * <p> The content of the new, read-only buffer will be the content of the
+ * given character sequence. The buffer's capacity will be
+ * <tt>csq.length()</tt>, its position will be <tt>start</tt>, its limit
+ * will be <tt>end</tt>, and its mark will be undefined. </p>
+ *
+ * @param csq
+ * The character sequence from which the new character buffer is to
+ * be created
+ *
+ * @param start
+ * The index of the first character to be used;
+ * must be non-negative and no larger than <tt>csq.length()</tt>.
+ * The new buffer's position will be set to this value.
+ *
+ * @param end
+ * The index of the character following the last character to be
+ * used; must be no smaller than <tt>start</tt> and no larger
+ * than <tt>csq.length()</tt>.
+ * The new buffer's limit will be set to this value.
+ *
+ * @return The new character buffer
+ *
+ * @throws IndexOutOfBoundsException
+ * If the preconditions on the <tt>start</tt> and <tt>end</tt>
+ * parameters do not hold
+ */
+ public static CharBuffer wrap(CharSequence csq, int start, int end) {
+ try {
+ return new StringCharBuffer(csq, start, end);
+ } catch (IllegalArgumentException x) {
+ throw new IndexOutOfBoundsException();
+ }
+ }
+
+ /**
+ * Wraps a character sequence into a buffer.
+ *
+ * <p> The content of the new, read-only buffer will be the content of the
+ * given character sequence. The new buffer's capacity and limit will be
+ * <tt>csq.length()</tt>, its position will be zero, and its mark will be
+ * undefined. </p>
+ *
+ * @param csq
+ * The character sequence from which the new character buffer is to
+ * be created
+ *
+ * @return The new character buffer
+ */
+ public static CharBuffer wrap(CharSequence csq) {
+ return wrap(csq, 0, csq.length());
+ }
+
+#end[char]
+
+ /**
+ * Creates a new $fulltype$ buffer whose content is a shared subsequence of
+ * this buffer's content.
+ *
+ * <p> The content of the new buffer will start at this buffer's current
+ * position. Changes to this buffer's content will be visible in the new
+ * buffer, and vice versa; the two buffers' position, limit, and mark
+ * values will be independent.
+ *
+ * <p> The new buffer's position will be zero, its capacity and its limit
+ * will be the number of $fulltype$s remaining in this buffer, and its mark
+ * will be undefined. The new buffer will be direct if, and only if, this
+ * buffer is direct, and it will be read-only if, and only if, this buffer
+ * is read-only. </p>
+ *
+ * @return The new $fulltype$ buffer
+ */
+ public abstract $Type$Buffer slice();
+
+ /**
+ * Creates a new $fulltype$ buffer that shares this buffer's content.
+ *
+ * <p> The content of the new buffer will be that of this buffer. Changes
+ * to this buffer's content will be visible in the new buffer, and vice
+ * versa; the two buffers' position, limit, and mark values will be
+ * independent.
+ *
+ * <p> The new buffer's capacity, limit, position, and mark values will be
+ * identical to those of this buffer. The new buffer will be direct if,
+ * and only if, this buffer is direct, and it will be read-only if, and
+ * only if, this buffer is read-only. </p>
+ *
+ * @return The new $fulltype$ buffer
+ */
+ public abstract $Type$Buffer duplicate();
+
+ /**
+ * Creates a new, read-only $fulltype$ buffer that shares this buffer's
+ * content.
+ *
+ * <p> The content of the new buffer will be that of this buffer. Changes
+ * to this buffer's content will be visible in the new buffer; the new
+ * buffer itself, however, will be read-only and will not allow the shared
+ * content to be modified. The two buffers' position, limit, and mark
+ * values will be independent.
+ *
+ * <p> The new buffer's capacity, limit, position, and mark values will be
+ * identical to those of this buffer.
+ *
+ * <p> If this buffer is itself read-only then this method behaves in
+ * exactly the same way as the {@link #duplicate duplicate} method. </p>
+ *
+ * @return The new, read-only $fulltype$ buffer
+ */
+ public abstract $Type$Buffer asReadOnlyBuffer();
+
+
+ // -- Singleton get/put methods --
+
+ /**
+ * Relative <i>get</i> method. Reads the $fulltype$ at this buffer's
+ * current position, and then increments the position. </p>
+ *
+ * @return The $fulltype$ at the buffer's current position
+ *
+ * @throws BufferUnderflowException
+ * If the buffer's current position is not smaller than its limit
+ */
+ public abstract $type$ get();
+
+ /**
+ * Relative <i>put</i> method <i>(optional operation)</i>.
+ *
+ * <p> Writes the given $fulltype$ into this buffer at the current
+ * position, and then increments the position. </p>
+ *
+ * @param $x$
+ * The $fulltype$ to be written
+ *
+ * @return This buffer
+ *
+ * @throws BufferOverflowException
+ * If this buffer's current position is not smaller than its limit
+ *
+ * @throws ReadOnlyBufferException
+ * If this buffer is read-only
+ */
+ public abstract $Type$Buffer put($type$ $x$);
+
+ /**
+ * Absolute <i>get</i> method. Reads the $fulltype$ at the given
+ * index. </p>
+ *
+ * @param index
+ * The index from which the $fulltype$ will be read
+ *
+ * @return The $fulltype$ at the given index
+ *
+ * @throws IndexOutOfBoundsException
+ * If <tt>index</tt> is negative
+ * or not smaller than the buffer's limit
+ */
+ public abstract $type$ get(int index);
+
+ /**
+ * Absolute <i>put</i> method <i>(optional operation)</i>.
+ *
+ * <p> Writes the given $fulltype$ into this buffer at the given
+ * index. </p>
+ *
+ * @param index
+ * The index at which the $fulltype$ will be written
+ *
+ * @param $x$
+ * The $fulltype$ value to be written
+ *
+ * @return This buffer
+ *
+ * @throws IndexOutOfBoundsException
+ * If <tt>index</tt> is negative
+ * or not smaller than the buffer's limit
+ *
+ * @throws ReadOnlyBufferException
+ * If this buffer is read-only
+ */
+ public abstract $Type$Buffer put(int index, $type$ $x$);
+
+
+ // -- Bulk get operations --
+
+ /**
+ * Relative bulk <i>get</i> method.
+ *
+ * <p> This method transfers $fulltype$s from this buffer into the given
+ * destination array. If there are fewer $fulltype$s remaining in the
+ * buffer than are required to satisfy the request, that is, if
+ * <tt>length</tt> <tt>></tt> <tt>remaining()</tt>, then no
+ * $fulltype$s are transferred and a {@link BufferUnderflowException} is
+ * thrown.
+ *
+ * <p> Otherwise, this method copies <tt>length</tt> $fulltype$s from this
+ * buffer into the given array, starting at the current position of this
+ * buffer and at the given offset in the array. The position of this
+ * buffer is then incremented by <tt>length</tt>.
+ *
+ * <p> In other words, an invocation of this method of the form
+ * <tt>src.get(dst, off, len)</tt> has exactly the same effect as
+ * the loop
+ *
+ * <pre>
+ * for (int i = off; i < off + len; i++)
+ * dst[i] = src.get(); </pre>
+ *
+ * except that it first checks that there are sufficient $fulltype$s in
+ * this buffer and it is potentially much more efficient. </p>
+ *
+ * @param dst
+ * The array into which $fulltype$s are to be written
+ *
+ * @param offset
+ * The offset within the array of the first $fulltype$ to be
+ * written; must be non-negative and no larger than
+ * <tt>dst.length</tt>
+ *
+ * @param length
+ * The maximum number of $fulltype$s to be written to the given
+ * array; must be non-negative and no larger than
+ * <tt>dst.length - offset</tt>
+ *
+ * @return This buffer
+ *
+ * @throws BufferUnderflowException
+ * If there are fewer than <tt>length</tt> $fulltype$s
+ * remaining in this buffer
+ *
+ * @throws IndexOutOfBoundsException
+ * If the preconditions on the <tt>offset</tt> and <tt>length</tt>
+ * parameters do not hold
+ */
+ public $Type$Buffer get($type$[] dst, int offset, int length) {
+ checkBounds(offset, length, dst.length);
+ if (length > remaining())
+ throw new BufferUnderflowException();
+ int end = offset + length;
+ for (int i = offset; i < end; i++)
+ dst[i] = get();
+ return this;
+ }
+
+ /**
+ * Relative bulk <i>get</i> method.
+ *
+ * <p> This method transfers $fulltype$s from this buffer into the given
+ * destination array. An invocation of this method of the form
+ * <tt>src.get(a)</tt> behaves in exactly the same way as the invocation
+ *
+ * <pre>
+ * src.get(a, 0, a.length) </pre>
+ *
+ * @return This buffer
+ *
+ * @throws BufferUnderflowException
+ * If there are fewer than <tt>length</tt> $fulltype$s
+ * remaining in this buffer
+ */
+ public $Type$Buffer get($type$[] dst) {
+ return get(dst, 0, dst.length);
+ }
+
+
+ // -- Bulk put operations --
+
+ /**
+ * Relative bulk <i>put</i> method <i>(optional operation)</i>.
+ *
+ * <p> This method transfers the $fulltype$s remaining in the given source
+ * buffer into this buffer. If there are more $fulltype$s remaining in the
+ * source buffer than in this buffer, that is, if
+ * <tt>src.remaining()</tt> <tt>></tt> <tt>remaining()</tt>,
+ * then no $fulltype$s are transferred and a {@link
+ * BufferOverflowException} is thrown.
+ *
+ * <p> Otherwise, this method copies
+ * <i>n</i> = <tt>src.remaining()</tt> $fulltype$s from the given
+ * buffer into this buffer, starting at each buffer's current position.
+ * The positions of both buffers are then incremented by <i>n</i>.
+ *
+ * <p> In other words, an invocation of this method of the form
+ * <tt>dst.put(src)</tt> has exactly the same effect as the loop
+ *
+ * <pre>
+ * while (src.hasRemaining())
+ * dst.put(src.get()); </pre>
+ *
+ * except that it first checks that there is sufficient space in this
+ * buffer and it is potentially much more efficient. </p>
+ *
+ * @param src
+ * The source buffer from which $fulltype$s are to be read;
+ * must not be this buffer
+ *
+ * @return This buffer
+ *
+ * @throws BufferOverflowException
+ * If there is insufficient space in this buffer
+ * for the remaining $fulltype$s in the source buffer
+ *
+ * @throws IllegalArgumentException
+ * If the source buffer is this buffer
+ *
+ * @throws ReadOnlyBufferException
+ * If this buffer is read-only
+ */
+ public $Type$Buffer put($Type$Buffer src) {
+ if (src == this)
+ throw new IllegalArgumentException();
+ int n = src.remaining();
+ if (n > remaining())
+ throw new BufferOverflowException();
+ for (int i = 0; i < n; i++)
+ put(src.get());
+ return this;
+ }
+
+ /**
+ * Relative bulk <i>put</i> method <i>(optional operation)</i>.
+ *
+ * <p> This method transfers $fulltype$s into this buffer from the given
+ * source array. If there are more $fulltype$s to be copied from the array
+ * than remain in this buffer, that is, if
+ * <tt>length</tt> <tt>></tt> <tt>remaining()</tt>, then no
+ * $fulltype$s are transferred and a {@link BufferOverflowException} is
+ * thrown.
+ *
+ * <p> Otherwise, this method copies <tt>length</tt> $fulltype$s from the
+ * given array into this buffer, starting at the given offset in the array
+ * and at the current position of this buffer. The position of this buffer
+ * is then incremented by <tt>length</tt>.
+ *
+ * <p> In other words, an invocation of this method of the form
+ * <tt>dst.put(src, off, len)</tt> has exactly the same effect as
+ * the loop
+ *
+ * <pre>
+ * for (int i = off; i < off + len; i++)
+ * dst.put(a[i]); </pre>
+ *
+ * except that it first checks that there is sufficient space in this
+ * buffer and it is potentially much more efficient. </p>
+ *
+ * @param src
+ * The array from which $fulltype$s are to be read
+ *
+ * @param offset
+ * The offset within the array of the first $fulltype$ to be read;
+ * must be non-negative and no larger than <tt>array.length</tt>
+ *
+ * @param length
+ * The number of $fulltype$s to be read from the given array;
+ * must be non-negative and no larger than
+ * <tt>array.length - offset</tt>
+ *
+ * @return This buffer
+ *
+ * @throws BufferOverflowException
+ * If there is insufficient space in this buffer
+ *
+ * @throws IndexOutOfBoundsException
+ * If the preconditions on the <tt>offset</tt> and <tt>length</tt>
+ * parameters do not hold
+ *
+ * @throws ReadOnlyBufferException
+ * If this buffer is read-only
+ */
+ public $Type$Buffer put($type$[] src, int offset, int length) {
+ checkBounds(offset, length, src.length);
+ if (length > remaining())
+ throw new BufferOverflowException();
+ int end = offset + length;
+ for (int i = offset; i < end; i++)
+ this.put(src[i]);
+ return this;
+ }
+
+ /**
+ * Relative bulk <i>put</i> method <i>(optional operation)</i>.
+ *
+ * <p> This method transfers the entire content of the given source
+ * $fulltype$ array into this buffer. An invocation of this method of the
+ * form <tt>dst.put(a)</tt> behaves in exactly the same way as the
+ * invocation
+ *
+ * <pre>
+ * dst.put(a, 0, a.length) </pre>
+ *
+ * @return This buffer
+ *
+ * @throws BufferOverflowException
+ * If there is insufficient space in this buffer
+ *
+ * @throws ReadOnlyBufferException
+ * If this buffer is read-only
+ */
+ public final $Type$Buffer put($type$[] src) {
+ return put(src, 0, src.length);
+ }
+
+#if[char]
+
+ /**
+ * Relative bulk <i>put</i> method <i>(optional operation)</i>.
+ *
+ * <p> This method transfers $fulltype$s from the given string into this
+ * buffer. If there are more $fulltype$s to be copied from the string than
+ * remain in this buffer, that is, if
+ * <tt>end - start</tt> <tt>></tt> <tt>remaining()</tt>,
+ * then no $fulltype$s are transferred and a {@link
+ * BufferOverflowException} is thrown.
+ *
+ * <p> Otherwise, this method copies
+ * <i>n</i> = <tt>end</tt> - <tt>start</tt> $fulltype$s
+ * from the given string into this buffer, starting at the given
+ * <tt>start</tt> index and at the current position of this buffer. The
+ * position of this buffer is then incremented by <i>n</i>.
+ *
+ * <p> In other words, an invocation of this method of the form
+ * <tt>dst.put(src, start, end)</tt> has exactly the same effect
+ * as the loop
+ *
+ * <pre>
+ * for (int i = start; i < end; i++)
+ * dst.put(src.charAt(i)); </pre>
+ *
+ * except that it first checks that there is sufficient space in this
+ * buffer and it is potentially much more efficient. </p>
+ *
+ * @param src
+ * The string from which $fulltype$s are to be read
+ *
+ * @param start
+ * The offset within the string of the first $fulltype$ to be read;
+ * must be non-negative and no larger than
+ * <tt>string.length()</tt>
+ *
+ * @param end
+ * The offset within the string of the last $fulltype$ to be read,
+ * plus one; must be non-negative and no larger than
+ * <tt>string.length()</tt>
+ *
+ * @return This buffer
+ *
+ * @throws BufferOverflowException
+ * If there is insufficient space in this buffer
+ *
+ * @throws IndexOutOfBoundsException
+ * If the preconditions on the <tt>start</tt> and <tt>end</tt>
+ * parameters do not hold
+ *
+ * @throws ReadOnlyBufferException
+ * If this buffer is read-only
+ */
+ public $Type$Buffer put(String src, int start, int end) {
+ checkBounds(start, end - start, src.length());
+ for (int i = start; i < end; i++)
+ this.put(src.charAt(i));
+ return this;
+ }
+
+ /**
+ * Relative bulk <i>put</i> method <i>(optional operation)</i>.
+ *
+ * <p> This method transfers the entire content of the given source string
+ * into this buffer. An invocation of this method of the form
+ * <tt>dst.put(s)</tt> behaves in exactly the same way as the invocation
+ *
+ * <pre>
+ * dst.put(s, 0, s.length()) </pre>
+ *
+ * @return This buffer
+ *
+ * @throws BufferOverflowException
+ * If there is insufficient space in this buffer
+ *
+ * @throws ReadOnlyBufferException
+ * If this buffer is read-only
+ */
+ public final $Type$Buffer put(String src) {
+ return put(src, 0, src.length());
+ }
+
+#end[char]
+
+
+ // -- Other stuff --
+
+ /**
+ * Tells whether or not this buffer is backed by an accessible $fulltype$
+ * array.
+ *
+ * <p> If this method returns <tt>true</tt> then the {@link #array() array}
+ * and {@link #arrayOffset() arrayOffset} methods may safely be invoked.
+ * </p>
+ *
+ * @return <tt>true</tt> if, and only if, this buffer
+ * is backed by an array and is not read-only
+ */
+ public final boolean hasArray() {
+ return (hb != null) && !isReadOnly;
+ }
+
+ /**
+ * Returns the $fulltype$ array that backs this
+ * buffer <i>(optional operation)</i>.
+ *
+ * <p> Modifications to this buffer's content will cause the returned
+ * array's content to be modified, and vice versa.
+ *
+ * <p> Invoke the {@link #hasArray hasArray} method before invoking this
+ * method in order to ensure that this buffer has an accessible backing
+ * array. </p>
+ *
+ * @return The array that backs this buffer
+ *
+ * @throws ReadOnlyBufferException
+ * If this buffer is backed by an array but is read-only
+ *
+ * @throws UnsupportedOperationException
+ * If this buffer is not backed by an accessible array
+ */
+ public final $type$[] array() {
+ if (hb == null)
+ throw new UnsupportedOperationException();
+ if (isReadOnly)
+ throw new ReadOnlyBufferException();
+ return hb;
+ }
+
+ /**
+ * Returns the offset within this buffer's backing array of the first
+ * element of the buffer <i>(optional operation)</i>.
+ *
+ * <p> If this buffer is backed by an array then buffer position <i>p</i>
+ * corresponds to array index <i>p</i> + <tt>arrayOffset()</tt>.
+ *
+ * <p> Invoke the {@link #hasArray hasArray} method before invoking this
+ * method in order to ensure that this buffer has an accessible backing
+ * array. </p>
+ *
+ * @return The offset within this buffer's array
+ * of the first element of the buffer
+ *
+ * @throws ReadOnlyBufferException
+ * If this buffer is backed by an array but is read-only
+ *
+ * @throws UnsupportedOperationException
+ * If this buffer is not backed by an accessible array
+ */
+ public final int arrayOffset() {
+ if (hb == null)
+ throw new UnsupportedOperationException();
+ if (isReadOnly)
+ throw new ReadOnlyBufferException();
+ return offset;
+ }
+
+ /**
+ * Compacts this buffer <i>(optional operation)</i>.
+ *
+ * <p> The $fulltype$s between the buffer's current position and its limit,
+ * if any, are copied to the beginning of the buffer. That is, the
+ * $fulltype$ at index <i>p</i> = <tt>position()</tt> is copied
+ * to index zero, the $fulltype$ at index <i>p</i> + 1 is copied
+ * to index one, and so forth until the $fulltype$ at index
+ * <tt>limit()</tt> - 1 is copied to index
+ * <i>n</i> = <tt>limit()</tt> - <tt>1</tt> - <i>p</i>.
+ * The buffer's position is then set to <i>n+1</i> and its limit is set to
+ * its capacity. The mark, if defined, is discarded.
+ *
+ * <p> The buffer's position is set to the number of $fulltype$s copied,
+ * rather than to zero, so that an invocation of this method can be
+ * followed immediately by an invocation of another relative <i>put</i>
+ * method. </p>
+ *
+#if[byte]
+ *
+ * <p> Invoke this method after writing data from a buffer in case the
+ * write was incomplete. The following loop, for example, copies bytes
+ * from one channel to another via the buffer <tt>buf</tt>:
+ *
+ * <blockquote><pre>
+ * buf.clear(); // Prepare buffer for use
+ * while (in.read(buf) >= 0 || buf.position != 0) {
+ * buf.flip();
+ * out.write(buf);
+ * buf.compact(); // In case of partial write
+ * }</pre></blockquote>
+ *
+#end[byte]
+ *
+ * @return This buffer
+ *
+ * @throws ReadOnlyBufferException
+ * If this buffer is read-only
+ */
+ public abstract $Type$Buffer compact();
+
+ /**
+ * Tells whether or not this $fulltype$ buffer is direct. </p>
+ *
+ * @return <tt>true</tt> if, and only if, this buffer is direct
+ */
+ public abstract boolean isDirect();
+
+#if[!char]
+
+ /**
+ * Returns a string summarizing the state of this buffer. </p>
+ *
+ * @return A summary string
+ */
+ public String toString() {
+ StringBuffer sb = new StringBuffer();
+ sb.append(getClass().getName());
+ sb.append("[pos=");
+ sb.append(position());
+ sb.append(" lim=");
+ sb.append(limit());
+ sb.append(" cap=");
+ sb.append(capacity());
+ sb.append("]");
+ return sb.toString();
+ }
+
+#end[!char]
+
+
+ // ## Should really use unchecked accessors here for speed
+
+ /**
+ * Returns the current hash code of this buffer.
+ *
+ * <p> The hash code of a $type$ buffer depends only upon its remaining
+ * elements; that is, upon the elements from <tt>position()</tt> up to, and
+ * including, the element at <tt>limit()</tt> - <tt>1</tt>.
+ *
+ * <p> Because buffer hash codes are content-dependent, it is inadvisable
+ * to use buffers as keys in hash maps or similar data structures unless it
+ * is known that their contents will not change. </p>
+ *
+ * @return The current hash code of this buffer
+ */
+ public int hashCode() {
+ int h = 1;
+ int p = position();
+ for (int i = limit() - 1; i >= p; i--)
+ h = 31 * h + (int)get(i);
+ return h;
+ }
+
+ /**
+ * Tells whether or not this buffer is equal to another object.
+ *
+ * <p> Two $type$ buffers are equal if, and only if,
+ *
+ * <p><ol>
+ *
+ * <li><p> They have the same element type, </p></li>
+ *
+ * <li><p> They have the same number of remaining elements, and
+ * </p></li>
+ *
+ * <li><p> The two sequences of remaining elements, considered
+ * independently of their starting positions, are pointwise equal.
+ * </p></li>
+ *
+ * </ol>
+ *
+ * <p> A $type$ buffer is not equal to any other type of object. </p>
+ *
+ * @param ob The object to which this buffer is to be compared
+ *
+ * @return <tt>true</tt> if, and only if, this buffer is equal to the
+ * given object
+ */
+ public boolean equals(Object ob) {
+ if (this == ob)
+ return true;
+ if (!(ob instanceof $Type$Buffer))
+ return false;
+ $Type$Buffer that = ($Type$Buffer)ob;
+ if (this.remaining() != that.remaining())
+ return false;
+ int p = this.position();
+ for (int i = this.limit() - 1, j = that.limit() - 1; i >= p; i--, j--) {
+ $type$ v1 = this.get(i);
+ $type$ v2 = that.get(j);
+ if (v1 != v2) {
+ if ((v1 != v1) && (v2 != v2)) // For float and double
+ continue;
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Compares this buffer to another.
+ *
+ * <p> Two $type$ buffers are compared by comparing their sequences of
+ * remaining elements lexicographically, without regard to the starting
+ * position of each sequence within its corresponding buffer.
+ *
+ * <p> A $type$ buffer is not comparable to any other type of object.
+ *
+ * @return A negative integer, zero, or a positive integer as this buffer
+ * is less than, equal to, or greater than the given buffer
+ */
+ public int compareTo($Type$Buffer that) {
+ int n = this.position() + Math.min(this.remaining(), that.remaining());
+ for (int i = this.position(), j = that.position(); i < n; i++, j++) {
+ $type$ v1 = this.get(i);
+ $type$ v2 = that.get(j);
+ if (v1 == v2)
+ continue;
+ if ((v1 != v1) && (v2 != v2)) // For float and double
+ continue;
+ if (v1 < v2)
+ return -1;
+ return +1;
+ }
+ return this.remaining() - that.remaining();
+ }
+
+
+
+ // -- Other char stuff --
+
+#if[char]
+
+ /**
+ * Returns a string containing the characters in this buffer.
+ *
+ * <p> The first character of the resulting string will be the character at
+ * this buffer's position, while the last character will be the character
+ * at index <tt>limit()</tt> - 1. Invoking this method does not
+ * change the buffer's position. </p>
+ *
+ * @return The specified string
+ */
+ public String toString() {
+ return toString(position(), limit());
+ }
+
+ abstract String toString(int start, int end); // package-private
+
+
+ // --- Methods to support CharSequence ---
+
+ /**
+ * Returns the length of this character buffer.
+ *
+ * <p> When viewed as a character sequence, the length of a character
+ * buffer is simply the number of characters between the position
+ * (inclusive) and the limit (exclusive); that is, it is equivalent to
+ * <tt>remaining()</tt>. </p>
+ *
+ * @return The length of this character buffer
+ */
+ public final int length() {
+ return remaining();
+ }
+
+ /**
+ * Reads the character at the given index relative to the current
+ * position. </p>
+ *
+ * @param index
+ * The index of the character to be read, relative to the position;
+ * must be non-negative and smaller than <tt>remaining()</tt>
+ *
+ * @return The character at index
+ * <tt>position() + index</tt>
+ *
+ * @throws IndexOutOfBoundsException
+ * If the preconditions on <tt>index</tt> do not hold
+ */
+ public final char charAt(int index) {
+ return get(position() + checkIndex(index, 1));
+ }
+
+ /**
+ * Creates a new character buffer that represents the specified subsequence
+ * of this buffer, relative to the current position.
+ *
+ * <p> The new buffer will share this buffer's content; that is, if the
+ * content of this buffer is mutable then modifications to one buffer will
+ * cause the other to be modified. The new buffer's capacity will be that
+ * of this buffer, its position will be
+ * <tt>position()</tt> + <tt>start</tt>, and its limit will be
+ * <tt>position()</tt> + <tt>end</tt>. The new buffer will be
+ * direct if, and only if, this buffer is direct, and it will be read-only
+ * if, and only if, this buffer is read-only. </p>
+ *
+ * @param start
+ * The index, relative to the current position, of the first
+ * character in the subsequence; must be non-negative and no larger
+ * than <tt>remaining()</tt>
+ *
+ * @param end
+ * The index, relative to the current position, of the character
+ * following the last character in the subsequence; must be no
+ * smaller than <tt>start</tt> and no larger than
+ * <tt>remaining()</tt>
+ *
+ * @return The new character buffer
+ *
+ * @throws IndexOutOfBoundsException
+ * If the preconditions on <tt>start</tt> and <tt>end</tt>
+ * do not hold
+ */
+ public abstract CharBuffer subSequence(int start, int end);
+
+
+ // --- Methods to support Appendable ---
+
+ /**
+ * Appends the specified character sequence to this
+ * buffer <i>(optional operation)</i>.
+ *
+ * <p> An invocation of this method of the form <tt>dst.append(csq)</tt>
+ * behaves in exactly the same way as the invocation
+ *
+ * <pre>
+ * dst.put(csq.toString()) </pre>
+ *
+ * <p> Depending on the specification of <tt>toString</tt> for the
+ * character sequence <tt>csq</tt>, the entire sequence may not be
+ * appended. For instance, invoking the {@link $Type$Buffer#toString()
+ * toString} method of a character buffer will return a subsequence whose
+ * content depends upon the buffer's position and limit.
+ *
+ * @param csq
+ * The character sequence to append. If <tt>csq</tt> is
+ * <tt>null</tt>, then the four characters <tt>"null"</tt> are
+ * appended to this character buffer.
+ *
+ * @return This buffer
+ *
+ * @throws BufferOverflowException
+ * If there is insufficient space in this buffer
+ *
+ * @throws ReadOnlyBufferException
+ * If this buffer is read-only
+ *
+ * @since 1.5
+ */
+ public $Type$Buffer append(CharSequence csq) {
+ if (csq == null)
+ return put("null");
+ else
+ return put(csq.toString());
+ }
+
+ /**
+ * Appends a subsequence of the specified character sequence to this
+ * buffer <i>(optional operation)</i>.
+ *
+ * <p> An invocation of this method of the form <tt>dst.append(csq, start,
+ * end)</tt> when <tt>csq</tt> is not <tt>null</tt>, behaves in exactly the
+ * same way as the invocation
+ *
+ * <pre>
+ * dst.put(csq.subSequence(start, end).toString()) </pre>
+ *
+ * @param csq
+ * The character sequence from which a subsequence will be
+ * appended. If <tt>csq</tt> is <tt>null</tt>, then characters
+ * will be appended as if <tt>csq</tt> contained the four
+ * characters <tt>"null"</tt>.
+ *
+ * @return This buffer
+ *
+ * @throws BufferOverflowException
+ * If there is insufficient space in this buffer
+ *
+ * @throws IndexOutOfBoundsException
+ * If <tt>start</tt> or <tt>end</tt> are negative, <tt>start</tt>
+ * is greater than <tt>end</tt>, or <tt>end</tt> is greater than
+ * <tt>csq.length()</tt>
+ *
+ * @throws ReadOnlyBufferException
+ * If this buffer is read-only
+ *
+ * @since 1.5
+ */
+ public $Type$Buffer append(CharSequence csq, int start, int end) {
+ CharSequence cs = (csq == null ? "null" : csq);
+ return put(cs.subSequence(start, end).toString());
+ }
+
+ /**
+ * Appends the specified $fulltype$ to this
+ * buffer <i>(optional operation)</i>.
+ *
+ * <p> An invocation of this method of the form <tt>dst.append($x$)</tt>
+ * behaves in exactly the same way as the invocation
+ *
+ * <pre>
+ * dst.put($x$) </pre>
+ *
+ * @param $x$
+ * The 16-bit $fulltype$ to append
+ *
+ * @return This buffer
+ *
+ * @throws BufferOverflowException
+ * If there is insufficient space in this buffer
+ *
+ * @throws ReadOnlyBufferException
+ * If this buffer is read-only
+ *
+ * @since 1.5
+ */
+ public $Type$Buffer append($type$ $x$) {
+ return put($x$);
+ }
+
+#end[char]
+
+
+ // -- Other byte stuff: Access to binary data --
+
+#if[!byte]
+
+ /**
+ * Retrieves this buffer's byte order.
+ *
+ * <p> The byte order of $a$ $fulltype$ buffer created by allocation or by
+ * wrapping an existing <tt>$type$</tt> array is the {@link
+ * ByteOrder#nativeOrder </code>native order<code>} of the underlying
+ * hardware. The byte order of $a$ $fulltype$ buffer created as a <a
+ * href="ByteBuffer.html#views">view</a> of a byte buffer is that of the
+ * byte buffer at the moment that the view is created. </p>
+ *
+ * @return This buffer's byte order
+ */
+ public abstract ByteOrder order();
+
+#end[!byte]
+
+#if[byte]
+
+ boolean bigEndian // package-private
+ = true;
+ boolean nativeByteOrder // package-private
+ = (Bits.byteOrder() == ByteOrder.BIG_ENDIAN);
+
+ /**
+ * Retrieves this buffer's byte order.
+ *
+ * <p> The byte order is used when reading or writing multibyte values, and
+ * when creating buffers that are views of this byte buffer. The order of
+ * a newly-created byte buffer is always {@link ByteOrder#BIG_ENDIAN
+ * BIG_ENDIAN}. </p>
+ *
+ * @return This buffer's byte order
+ */
+ public final ByteOrder order() {
+ return bigEndian ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN;
+ }
+
+ /**
+ * Modifies this buffer's byte order. </p>
+ *
+ * @param bo
+ * The new byte order,
+ * either {@link ByteOrder#BIG_ENDIAN BIG_ENDIAN}
+ * or {@link ByteOrder#LITTLE_ENDIAN LITTLE_ENDIAN}
+ *
+ * @return This buffer
+ */
+ public final $Type$Buffer order(ByteOrder bo) {
+ bigEndian = (bo == ByteOrder.BIG_ENDIAN);
+ nativeByteOrder =
+ (bigEndian == (Bits.byteOrder() == ByteOrder.BIG_ENDIAN));
+ return this;
+ }
+
+ // Unchecked accessors, for use by ByteBufferAs-X-Buffer classes
+ //
+ abstract byte _get(int i); // package-private
+ abstract void _put(int i, byte b); // package-private
+
+ // #BIN
+ //
+ // Binary-data access methods for short, char, int, long, float,
+ // and double will be inserted here
+
+#end[byte]
+
+}
--- a/jdk/src/share/classes/java/nio/charset/Charset-X-Coder.java Wed Oct 28 16:26:52 2009 -0700
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,972 +0,0 @@
-/*
- * Copyright 2000-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.
- */
-
-#warn This file is preprocessed before being compiled
-
-package java.nio.charset;
-
-import java.nio.Buffer;
-import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
-import java.nio.BufferOverflowException;
-import java.nio.BufferUnderflowException;
-import java.lang.ref.WeakReference;
-import java.nio.charset.CoderMalfunctionError; // javadoc
-
-
-/**
- * An engine that can transform a sequence of $itypesPhrase$ into a sequence of
- * $otypesPhrase$.
- *
- * <a name="steps">
- *
- * <p> The input $itype$ sequence is provided in a $itype$ buffer or a series
- * of such buffers. The output $otype$ sequence is written to a $otype$ buffer
- * or a series of such buffers. $A$ $coder$ should always be used by making
- * the following sequence of method invocations, hereinafter referred to as $a$
- * <i>$coding$ operation</i>:
- *
- * <ol>
- *
- * <li><p> Reset the $coder$ via the {@link #reset reset} method, unless it
- * has not been used before; </p></li>
- *
- * <li><p> Invoke the {@link #$code$ $code$} method zero or more times, as
- * long as additional input may be available, passing <tt>false</tt> for the
- * <tt>endOfInput</tt> argument and filling the input buffer and flushing the
- * output buffer between invocations; </p></li>
- *
- * <li><p> Invoke the {@link #$code$ $code$} method one final time, passing
- * <tt>true</tt> for the <tt>endOfInput</tt> argument; and then </p></li>
- *
- * <li><p> Invoke the {@link #flush flush} method so that the $coder$ can
- * flush any internal state to the output buffer. </p></li>
- *
- * </ol>
- *
- * Each invocation of the {@link #$code$ $code$} method will $code$ as many
- * $itype$s as possible from the input buffer, writing the resulting $otype$s
- * to the output buffer. The {@link #$code$ $code$} method returns when more
- * input is required, when there is not enough room in the output buffer, or
- * when $a$ $coding$ error has occurred. In each case a {@link CoderResult}
- * object is returned to describe the reason for termination. An invoker can
- * examine this object and fill the input buffer, flush the output buffer, or
- * attempt to recover from $a$ $coding$ error, as appropriate, and try again.
- *
- * <a name="ce">
- *
- * <p> There are two general types of $coding$ errors. If the input $itype$
- * sequence is $notLegal$ then the input is considered <i>malformed</i>. If
- * the input $itype$ sequence is legal but cannot be mapped to a valid
- * $outSequence$ then an <i>unmappable character</i> has been encountered.
- *
- * <a name="cae">
- *
- * <p> How $a$ $coding$ error is handled depends upon the action requested for
- * that type of error, which is described by an instance of the {@link
- * CodingErrorAction} class. The possible error actions are to {@link
- * CodingErrorAction#IGNORE </code>ignore<code>} the erroneous input, {@link
- * CodingErrorAction#REPORT </code>report<code>} the error to the invoker via
- * the returned {@link CoderResult} object, or {@link CodingErrorAction#REPLACE
- * </code>replace<code>} the erroneous input with the current value of the
- * replacement $replTypeName$. The replacement
- *
-#if[encoder]
- * is initially set to the $coder$'s default replacement, which often
- * (but not always) has the initial value $defaultReplName$;
-#end[encoder]
-#if[decoder]
- * has the initial value $defaultReplName$;
-#end[decoder]
- *
- * its value may be changed via the {@link #replaceWith($replFQType$)
- * replaceWith} method.
- *
- * <p> The default action for malformed-input and unmappable-character errors
- * is to {@link CodingErrorAction#REPORT </code>report<code>} them. The
- * malformed-input error action may be changed via the {@link
- * #onMalformedInput(CodingErrorAction) onMalformedInput} method; the
- * unmappable-character action may be changed via the {@link
- * #onUnmappableCharacter(CodingErrorAction) onUnmappableCharacter} method.
- *
- * <p> This class is designed to handle many of the details of the $coding$
- * process, including the implementation of error actions. $A$ $coder$ for a
- * specific charset, which is a concrete subclass of this class, need only
- * implement the abstract {@link #$code$Loop $code$Loop} method, which
- * encapsulates the basic $coding$ loop. A subclass that maintains internal
- * state should, additionally, override the {@link #implFlush implFlush} and
- * {@link #implReset implReset} methods.
- *
- * <p> Instances of this class are not safe for use by multiple concurrent
- * threads. </p>
- *
- *
- * @author Mark Reinhold
- * @author JSR-51 Expert Group
- * @since 1.4
- *
- * @see ByteBuffer
- * @see CharBuffer
- * @see Charset
- * @see Charset$OtherCoder$
- */
-
-public abstract class Charset$Coder$ {
-
- private final Charset charset;
- private final float average$ItypesPerOtype$;
- private final float max$ItypesPerOtype$;
-
- private $replType$ replacement;
- private CodingErrorAction malformedInputAction
- = CodingErrorAction.REPORT;
- private CodingErrorAction unmappableCharacterAction
- = CodingErrorAction.REPORT;
-
- // Internal states
- //
- private static final int ST_RESET = 0;
- private static final int ST_CODING = 1;
- private static final int ST_END = 2;
- private static final int ST_FLUSHED = 3;
-
- private int state = ST_RESET;
-
- private static String stateNames[]
- = { "RESET", "CODING", "CODING_END", "FLUSHED" };
-
-
- /**
- * Initializes a new $coder$. The new $coder$ will have the given
- * $otypes-per-itype$ and replacement values. </p>
- *
- * @param average$ItypesPerOtype$
- * A positive float value indicating the expected number of
- * $otype$s that will be produced for each input $itype$
- *
- * @param max$ItypesPerOtype$
- * A positive float value indicating the maximum number of
- * $otype$s that will be produced for each input $itype$
- *
- * @param replacement
- * The initial replacement; must not be <tt>null</tt>, must have
- * non-zero length, must not be longer than max$ItypesPerOtype$,
- * and must be {@link #isLegalReplacement </code>legal<code>}
- *
- * @throws IllegalArgumentException
- * If the preconditions on the parameters do not hold
- */
- {#if[encoder]?protected:private}
- Charset$Coder$(Charset cs,
- float average$ItypesPerOtype$,
- float max$ItypesPerOtype$,
- $replType$ replacement)
- {
- this.charset = cs;
- if (average$ItypesPerOtype$ <= 0.0f)
- throw new IllegalArgumentException("Non-positive "
- + "average$ItypesPerOtype$");
- if (max$ItypesPerOtype$ <= 0.0f)
- throw new IllegalArgumentException("Non-positive "
- + "max$ItypesPerOtype$");
- if (!Charset.atBugLevel("1.4")) {
- if (average$ItypesPerOtype$ > max$ItypesPerOtype$)
- throw new IllegalArgumentException("average$ItypesPerOtype$"
- + " exceeds "
- + "max$ItypesPerOtype$");
- }
- this.replacement = replacement;
- this.average$ItypesPerOtype$ = average$ItypesPerOtype$;
- this.max$ItypesPerOtype$ = max$ItypesPerOtype$;
- replaceWith(replacement);
- }
-
- /**
- * Initializes a new $coder$. The new $coder$ will have the given
- * $otypes-per-itype$ values and its replacement will be the
- * $replTypeName$ $defaultReplName$. </p>
- *
- * @param average$ItypesPerOtype$
- * A positive float value indicating the expected number of
- * $otype$s that will be produced for each input $itype$
- *
- * @param max$ItypesPerOtype$
- * A positive float value indicating the maximum number of
- * $otype$s that will be produced for each input $itype$
- *
- * @throws IllegalArgumentException
- * If the preconditions on the parameters do not hold
- */
- protected Charset$Coder$(Charset cs,
- float average$ItypesPerOtype$,
- float max$ItypesPerOtype$)
- {
- this(cs,
- average$ItypesPerOtype$, max$ItypesPerOtype$,
- $defaultRepl$);
- }
-
- /**
- * Returns the charset that created this $coder$. </p>
- *
- * @return This $coder$'s charset
- */
- public final Charset charset() {
- return charset;
- }
-
- /**
- * Returns this $coder$'s replacement value. </p>
- *
- * @return This $coder$'s current replacement,
- * which is never <tt>null</tt> and is never empty
- */
- public final $replType$ replacement() {
- return replacement;
- }
-
- /**
- * Changes this $coder$'s replacement value.
- *
- * <p> This method invokes the {@link #implReplaceWith implReplaceWith}
- * method, passing the new replacement, after checking that the new
- * replacement is acceptable. </p>
- *
- * @param newReplacement
- *
-#if[decoder]
- * The new replacement; must not be <tt>null</tt>
- * and must have non-zero length
-#end[decoder]
-#if[encoder]
- * The new replacement; must not be <tt>null</tt>, must have
- * non-zero length, must not be longer than the value returned by
- * the {@link #max$ItypesPerOtype$() max$ItypesPerOtype$} method, and
- * must be {@link #isLegalReplacement </code>legal<code>}
-#end[encoder]
- *
- * @return This $coder$
- *
- * @throws IllegalArgumentException
- * If the preconditions on the parameter do not hold
- */
- public final Charset$Coder$ replaceWith($replType$ newReplacement) {
- if (newReplacement == null)
- throw new IllegalArgumentException("Null replacement");
- int len = newReplacement.$replLength$;
- if (len == 0)
- throw new IllegalArgumentException("Empty replacement");
- if (len > max$ItypesPerOtype$)
- throw new IllegalArgumentException("Replacement too long");
-#if[encoder]
- if (!isLegalReplacement(newReplacement))
- throw new IllegalArgumentException("Illegal replacement");
-#end[encoder]
- this.replacement = newReplacement;
- implReplaceWith(newReplacement);
- return this;
- }
-
- /**
- * Reports a change to this $coder$'s replacement value.
- *
- * <p> The default implementation of this method does nothing. This method
- * should be overridden by $coder$s that require notification of changes to
- * the replacement. </p>
- *
- * @param newReplacement
- */
- protected void implReplaceWith($replType$ newReplacement) {
- }
-
-#if[encoder]
-
- private WeakReference<CharsetDecoder> cachedDecoder = null;
-
- /**
- * Tells whether or not the given byte array is a legal replacement value
- * for this encoder.
- *
- * <p> A replacement is legal if, and only if, it is a legal sequence of
- * bytes in this encoder's charset; that is, it must be possible to decode
- * the replacement into one or more sixteen-bit Unicode characters.
- *
- * <p> The default implementation of this method is not very efficient; it
- * should generally be overridden to improve performance. </p>
- *
- * @param repl The byte array to be tested
- *
- * @return <tt>true</tt> if, and only if, the given byte array
- * is a legal replacement value for this encoder
- */
- public boolean isLegalReplacement(byte[] repl) {
- WeakReference<CharsetDecoder> wr = cachedDecoder;
- CharsetDecoder dec = null;
- if ((wr == null) || ((dec = wr.get()) == null)) {
- dec = charset().newDecoder();
- dec.onMalformedInput(CodingErrorAction.REPORT);
- dec.onUnmappableCharacter(CodingErrorAction.REPORT);
- cachedDecoder = new WeakReference<CharsetDecoder>(dec);
- } else {
- dec.reset();
- }
- ByteBuffer bb = ByteBuffer.wrap(repl);
- CharBuffer cb = CharBuffer.allocate((int)(bb.remaining()
- * dec.maxCharsPerByte()));
- CoderResult cr = dec.decode(bb, cb, true);
- return !cr.isError();
- }
-
-#end[encoder]
-
- /**
- * Returns this $coder$'s current action for malformed-input errors. </p>
- *
- * @return The current malformed-input action, which is never <tt>null</tt>
- */
- public CodingErrorAction malformedInputAction() {
- return malformedInputAction;
- }
-
- /**
- * Changes this $coder$'s action for malformed-input errors. </p>
- *
- * <p> This method invokes the {@link #implOnMalformedInput
- * implOnMalformedInput} method, passing the new action. </p>
- *
- * @param newAction The new action; must not be <tt>null</tt>
- *
- * @return This $coder$
- *
- * @throws IllegalArgumentException
- * If the precondition on the parameter does not hold
- */
- public final Charset$Coder$ onMalformedInput(CodingErrorAction newAction) {
- if (newAction == null)
- throw new IllegalArgumentException("Null action");
- malformedInputAction = newAction;
- implOnMalformedInput(newAction);
- return this;
- }
-
- /**
- * Reports a change to this $coder$'s malformed-input action.
- *
- * <p> The default implementation of this method does nothing. This method
- * should be overridden by $coder$s that require notification of changes to
- * the malformed-input action. </p>
- */
- protected void implOnMalformedInput(CodingErrorAction newAction) { }
-
- /**
- * Returns this $coder$'s current action for unmappable-character errors.
- * </p>
- *
- * @return The current unmappable-character action, which is never
- * <tt>null</tt>
- */
- public CodingErrorAction unmappableCharacterAction() {
- return unmappableCharacterAction;
- }
-
- /**
- * Changes this $coder$'s action for unmappable-character errors.
- *
- * <p> This method invokes the {@link #implOnUnmappableCharacter
- * implOnUnmappableCharacter} method, passing the new action. </p>
- *
- * @param newAction The new action; must not be <tt>null</tt>
- *
- * @return This $coder$
- *
- * @throws IllegalArgumentException
- * If the precondition on the parameter does not hold
- */
- public final Charset$Coder$ onUnmappableCharacter(CodingErrorAction
- newAction)
- {
- if (newAction == null)
- throw new IllegalArgumentException("Null action");
- unmappableCharacterAction = newAction;
- implOnUnmappableCharacter(newAction);
- return this;
- }
-
- /**
- * Reports a change to this $coder$'s unmappable-character action.
- *
- * <p> The default implementation of this method does nothing. This method
- * should be overridden by $coder$s that require notification of changes to
- * the unmappable-character action. </p>
- */
- protected void implOnUnmappableCharacter(CodingErrorAction newAction) { }
-
- /**
- * Returns the average number of $otype$s that will be produced for each
- * $itype$ of input. This heuristic value may be used to estimate the size
- * of the output buffer required for a given input sequence. </p>
- *
- * @return The average number of $otype$s produced
- * per $itype$ of input
- */
- public final float average$ItypesPerOtype$() {
- return average$ItypesPerOtype$;
- }
-
- /**
- * Returns the maximum number of $otype$s that will be produced for each
- * $itype$ of input. This value may be used to compute the worst-case size
- * of the output buffer required for a given input sequence. </p>
- *
- * @return The maximum number of $otype$s that will be produced per
- * $itype$ of input
- */
- public final float max$ItypesPerOtype$() {
- return max$ItypesPerOtype$;
- }
-
- /**
- * $Code$s as many $itype$s as possible from the given input buffer,
- * writing the results to the given output buffer.
- *
- * <p> The buffers are read from, and written to, starting at their current
- * positions. At most {@link Buffer#remaining in.remaining()} $itype$s
- * will be read and at most {@link Buffer#remaining out.remaining()}
- * $otype$s will be written. The buffers' positions will be advanced to
- * reflect the $itype$s read and the $otype$s written, but their marks and
- * limits will not be modified.
- *
- * <p> In addition to reading $itype$s from the input buffer and writing
- * $otype$s to the output buffer, this method returns a {@link CoderResult}
- * object to describe its reason for termination:
- *
- * <ul>
- *
- * <li><p> {@link CoderResult#UNDERFLOW} indicates that as much of the
- * input buffer as possible has been $code$d. If there is no further
- * input then the invoker can proceed to the next step of the
- * <a href="#steps">$coding$ operation</a>. Otherwise this method
- * should be invoked again with further input. </p></li>
- *
- * <li><p> {@link CoderResult#OVERFLOW} indicates that there is
- * insufficient space in the output buffer to $code$ any more $itype$s.
- * This method should be invoked again with an output buffer that has
- * more {@linkplain Buffer#remaining remaining} $otype$s. This is
- * typically done by draining any $code$d $otype$s from the output
- * buffer. </p></li>
- *
- * <li><p> A {@link CoderResult#malformedForLength
- * </code>malformed-input<code>} result indicates that a malformed-input
- * error has been detected. The malformed $itype$s begin at the input
- * buffer's (possibly incremented) position; the number of malformed
- * $itype$s may be determined by invoking the result object's {@link
- * CoderResult#length() length} method. This case applies only if the
- * {@link #onMalformedInput </code>malformed action<code>} of this $coder$
- * is {@link CodingErrorAction#REPORT}; otherwise the malformed input
- * will be ignored or replaced, as requested. </p></li>
- *
- * <li><p> An {@link CoderResult#unmappableForLength
- * </code>unmappable-character<code>} result indicates that an
- * unmappable-character error has been detected. The $itype$s that
- * $code$ the unmappable character begin at the input buffer's (possibly
- * incremented) position; the number of such $itype$s may be determined
- * by invoking the result object's {@link CoderResult#length() length}
- * method. This case applies only if the {@link #onUnmappableCharacter
- * </code>unmappable action<code>} of this $coder$ is {@link
- * CodingErrorAction#REPORT}; otherwise the unmappable character will be
- * ignored or replaced, as requested. </p></li>
- *
- * </ul>
- *
- * In any case, if this method is to be reinvoked in the same $coding$
- * operation then care should be taken to preserve any $itype$s remaining
- * in the input buffer so that they are available to the next invocation.
- *
- * <p> The <tt>endOfInput</tt> parameter advises this method as to whether
- * the invoker can provide further input beyond that contained in the given
- * input buffer. If there is a possibility of providing additional input
- * then the invoker should pass <tt>false</tt> for this parameter; if there
- * is no possibility of providing further input then the invoker should
- * pass <tt>true</tt>. It is not erroneous, and in fact it is quite
- * common, to pass <tt>false</tt> in one invocation and later discover that
- * no further input was actually available. It is critical, however, that
- * the final invocation of this method in a sequence of invocations always
- * pass <tt>true</tt> so that any remaining un$code$d input will be treated
- * as being malformed.
- *
- * <p> This method works by invoking the {@link #$code$Loop $code$Loop}
- * method, interpreting its results, handling error conditions, and
- * reinvoking it as necessary. </p>
- *
- *
- * @param in
- * The input $itype$ buffer
- *
- * @param out
- * The output $otype$ buffer
- *
- * @param endOfInput
- * <tt>true</tt> if, and only if, the invoker can provide no
- * additional input $itype$s beyond those in the given buffer
- *
- * @return A coder-result object describing the reason for termination
- *
- * @throws IllegalStateException
- * If $a$ $coding$ operation is already in progress and the previous
- * step was an invocation neither of the {@link #reset reset}
- * method, nor of this method with a value of <tt>false</tt> for
- * the <tt>endOfInput</tt> parameter, nor of this method with a
- * value of <tt>true</tt> for the <tt>endOfInput</tt> parameter
- * but a return value indicating an incomplete $coding$ operation
- *
- * @throws CoderMalfunctionError
- * If an invocation of the $code$Loop method threw
- * an unexpected exception
- */
- public final CoderResult $code$($Itype$Buffer in, $Otype$Buffer out,
- boolean endOfInput)
- {
- int newState = endOfInput ? ST_END : ST_CODING;
- if ((state != ST_RESET) && (state != ST_CODING)
- && !(endOfInput && (state == ST_END)))
- throwIllegalStateException(state, newState);
- state = newState;
-
- for (;;) {
-
- CoderResult cr;
- try {
- cr = $code$Loop(in, out);
- } catch (BufferUnderflowException x) {
- throw new CoderMalfunctionError(x);
- } catch (BufferOverflowException x) {
- throw new CoderMalfunctionError(x);
- }
-
- if (cr.isOverflow())
- return cr;
-
- if (cr.isUnderflow()) {
- if (endOfInput && in.hasRemaining()) {
- cr = CoderResult.malformedForLength(in.remaining());
- // Fall through to malformed-input case
- } else {
- return cr;
- }
- }
-
- CodingErrorAction action = null;
- if (cr.isMalformed())
- action = malformedInputAction;
- else if (cr.isUnmappable())
- action = unmappableCharacterAction;
- else
- assert false : cr.toString();
-
- if (action == CodingErrorAction.REPORT)
- return cr;
-
- if (action == CodingErrorAction.REPLACE) {
- if (out.remaining() < replacement.$replLength$)
- return CoderResult.OVERFLOW;
- out.put(replacement);
- }
-
- if ((action == CodingErrorAction.IGNORE)
- || (action == CodingErrorAction.REPLACE)) {
- // Skip erroneous input either way
- in.position(in.position() + cr.length());
- continue;
- }
-
- assert false;
- }
-
- }
-
- /**
- * Flushes this $coder$.
- *
- * <p> Some $coder$s maintain internal state and may need to write some
- * final $otype$s to the output buffer once the overall input sequence has
- * been read.
- *
- * <p> Any additional output is written to the output buffer beginning at
- * its current position. At most {@link Buffer#remaining out.remaining()}
- * $otype$s will be written. The buffer's position will be advanced
- * appropriately, but its mark and limit will not be modified.
- *
- * <p> If this method completes successfully then it returns {@link
- * CoderResult#UNDERFLOW}. If there is insufficient room in the output
- * buffer then it returns {@link CoderResult#OVERFLOW}. If this happens
- * then this method must be invoked again, with an output buffer that has
- * more room, in order to complete the current <a href="#steps">$coding$
- * operation</a>.
- *
- * <p> If this $coder$ has already been flushed then invoking this method
- * has no effect.
- *
- * <p> This method invokes the {@link #implFlush implFlush} method to
- * perform the actual flushing operation. </p>
- *
- * @param out
- * The output $otype$ buffer
- *
- * @return A coder-result object, either {@link CoderResult#UNDERFLOW} or
- * {@link CoderResult#OVERFLOW}
- *
- * @throws IllegalStateException
- * If the previous step of the current $coding$ operation was an
- * invocation neither of the {@link #flush flush} method nor of
- * the three-argument {@link
- * #$code$($Itype$Buffer,$Otype$Buffer,boolean) $code$} method
- * with a value of <tt>true</tt> for the <tt>endOfInput</tt>
- * parameter
- */
- public final CoderResult flush($Otype$Buffer out) {
- if (state == ST_END) {
- CoderResult cr = implFlush(out);
- if (cr.isUnderflow())
- state = ST_FLUSHED;
- return cr;
- }
-
- if (state != ST_FLUSHED)
- throwIllegalStateException(state, ST_FLUSHED);
-
- return CoderResult.UNDERFLOW; // Already flushed
- }
-
- /**
- * Flushes this $coder$.
- *
- * <p> The default implementation of this method does nothing, and always
- * returns {@link CoderResult#UNDERFLOW}. This method should be overridden
- * by $coder$s that may need to write final $otype$s to the output buffer
- * once the entire input sequence has been read. </p>
- *
- * @param out
- * The output $otype$ buffer
- *
- * @return A coder-result object, either {@link CoderResult#UNDERFLOW} or
- * {@link CoderResult#OVERFLOW}
- */
- protected CoderResult implFlush($Otype$Buffer out) {
- return CoderResult.UNDERFLOW;
- }
-
- /**
- * Resets this $coder$, clearing any internal state.
- *
- * <p> This method resets charset-independent state and also invokes the
- * {@link #implReset() implReset} method in order to perform any
- * charset-specific reset actions. </p>
- *
- * @return This $coder$
- *
- */
- public final Charset$Coder$ reset() {
- implReset();
- state = ST_RESET;
- return this;
- }
-
- /**
- * Resets this $coder$, clearing any charset-specific internal state.
- *
- * <p> The default implementation of this method does nothing. This method
- * should be overridden by $coder$s that maintain internal state. </p>
- */
- protected void implReset() { }
-
- /**
- * $Code$s one or more $itype$s into one or more $otype$s.
- *
- * <p> This method encapsulates the basic $coding$ loop, $coding$ as many
- * $itype$s as possible until it either runs out of input, runs out of room
- * in the output buffer, or encounters $a$ $coding$ error. This method is
- * invoked by the {@link #$code$ $code$} method, which handles result
- * interpretation and error recovery.
- *
- * <p> The buffers are read from, and written to, starting at their current
- * positions. At most {@link Buffer#remaining in.remaining()} $itype$s
- * will be read, and at most {@link Buffer#remaining out.remaining()}
- * $otype$s will be written. The buffers' positions will be advanced to
- * reflect the $itype$s read and the $otype$s written, but their marks and
- * limits will not be modified.
- *
- * <p> This method returns a {@link CoderResult} object to describe its
- * reason for termination, in the same manner as the {@link #$code$ $code$}
- * method. Most implementations of this method will handle $coding$ errors
- * by returning an appropriate result object for interpretation by the
- * {@link #$code$ $code$} method. An optimized implementation may instead
- * examine the relevant error action and implement that action itself.
- *
- * <p> An implementation of this method may perform arbitrary lookahead by
- * returning {@link CoderResult#UNDERFLOW} until it receives sufficient
- * input. </p>
- *
- * @param in
- * The input $itype$ buffer
- *
- * @param out
- * The output $otype$ buffer
- *
- * @return A coder-result object describing the reason for termination
- */
- protected abstract CoderResult $code$Loop($Itype$Buffer in,
- $Otype$Buffer out);
-
- /**
- * Convenience method that $code$s the remaining content of a single input
- * $itype$ buffer into a newly-allocated $otype$ buffer.
- *
- * <p> This method implements an entire <a href="#steps">$coding$
- * operation</a>; that is, it resets this $coder$, then it $code$s the
- * $itype$s in the given $itype$ buffer, and finally it flushes this
- * $coder$. This method should therefore not be invoked if $a$ $coding$
- * operation is already in progress. </p>
- *
- * @param in
- * The input $itype$ buffer
- *
- * @return A newly-allocated $otype$ buffer containing the result of the
- * $coding$ operation. The buffer's position will be zero and its
- * limit will follow the last $otype$ written.
- *
- * @throws IllegalStateException
- * If $a$ $coding$ operation is already in progress
- *
- * @throws MalformedInputException
- * If the $itype$ sequence starting at the input buffer's current
- * position is $notLegal$ and the current malformed-input action
- * is {@link CodingErrorAction#REPORT}
- *
- * @throws UnmappableCharacterException
- * If the $itype$ sequence starting at the input buffer's current
- * position cannot be mapped to an equivalent $otype$ sequence and
- * the current unmappable-character action is {@link
- * CodingErrorAction#REPORT}
- */
- public final $Otype$Buffer $code$($Itype$Buffer in)
- throws CharacterCodingException
- {
- int n = (int)(in.remaining() * average$ItypesPerOtype$());
- $Otype$Buffer out = $Otype$Buffer.allocate(n);
-
- if ((n == 0) && (in.remaining() == 0))
- return out;
- reset();
- for (;;) {
- CoderResult cr = in.hasRemaining() ?
- $code$(in, out, true) : CoderResult.UNDERFLOW;
- if (cr.isUnderflow())
- cr = flush(out);
-
- if (cr.isUnderflow())
- break;
- if (cr.isOverflow()) {
- n = 2*n + 1; // Ensure progress; n might be 0!
- $Otype$Buffer o = $Otype$Buffer.allocate(n);
- out.flip();
- o.put(out);
- out = o;
- continue;
- }
- cr.throwException();
- }
- out.flip();
- return out;
- }
-
-#if[decoder]
-
- /**
- * Tells whether or not this decoder implements an auto-detecting charset.
- *
- * <p> The default implementation of this method always returns
- * <tt>false</tt>; it should be overridden by auto-detecting decoders to
- * return <tt>true</tt>. </p>
- *
- * @return <tt>true</tt> if, and only if, this decoder implements an
- * auto-detecting charset
- */
- public boolean isAutoDetecting() {
- return false;
- }
-
- /**
- * Tells whether or not this decoder has yet detected a
- * charset <i>(optional operation)</i>.
- *
- * <p> If this decoder implements an auto-detecting charset then at a
- * single point during a decoding operation this method may start returning
- * <tt>true</tt> to indicate that a specific charset has been detected in
- * the input byte sequence. Once this occurs, the {@link #detectedCharset
- * detectedCharset} method may be invoked to retrieve the detected charset.
- *
- * <p> That this method returns <tt>false</tt> does not imply that no bytes
- * have yet been decoded. Some auto-detecting decoders are capable of
- * decoding some, or even all, of an input byte sequence without fixing on
- * a particular charset.
- *
- * <p> The default implementation of this method always throws an {@link
- * UnsupportedOperationException}; it should be overridden by
- * auto-detecting decoders to return <tt>true</tt> once the input charset
- * has been determined. </p>
- *
- * @return <tt>true</tt> if, and only if, this decoder has detected a
- * specific charset
- *
- * @throws UnsupportedOperationException
- * If this decoder does not implement an auto-detecting charset
- */
- public boolean isCharsetDetected() {
- throw new UnsupportedOperationException();
- }
-
- /**
- * Retrieves the charset that was detected by this
- * decoder <i>(optional operation)</i>.
- *
- * <p> If this decoder implements an auto-detecting charset then this
- * method returns the actual charset once it has been detected. After that
- * point, this method returns the same value for the duration of the
- * current decoding operation. If not enough input bytes have yet been
- * read to determine the actual charset then this method throws an {@link
- * IllegalStateException}.
- *
- * <p> The default implementation of this method always throws an {@link
- * UnsupportedOperationException}; it should be overridden by
- * auto-detecting decoders to return the appropriate value. </p>
- *
- * @return The charset detected by this auto-detecting decoder,
- * or <tt>null</tt> if the charset has not yet been determined
- *
- * @throws IllegalStateException
- * If insufficient bytes have been read to determine a charset
- *
- * @throws UnsupportedOperationException
- * If this decoder does not implement an auto-detecting charset
- */
- public Charset detectedCharset() {
- throw new UnsupportedOperationException();
- }
-
-#end[decoder]
-
-#if[encoder]
-
- private boolean canEncode(CharBuffer cb) {
- if (state == ST_FLUSHED)
- reset();
- else if (state != ST_RESET)
- throwIllegalStateException(state, ST_CODING);
- CodingErrorAction ma = malformedInputAction();
- CodingErrorAction ua = unmappableCharacterAction();
- try {
- onMalformedInput(CodingErrorAction.REPORT);
- onUnmappableCharacter(CodingErrorAction.REPORT);
- encode(cb);
- } catch (CharacterCodingException x) {
- return false;
- } finally {
- onMalformedInput(ma);
- onUnmappableCharacter(ua);
- reset();
- }
- return true;
- }
-
- /**
- * Tells whether or not this encoder can encode the given character.
- *
- * <p> This method returns <tt>false</tt> if the given character is a
- * surrogate character; such characters can be interpreted only when they
- * are members of a pair consisting of a high surrogate followed by a low
- * surrogate. The {@link #canEncode(java.lang.CharSequence)
- * canEncode(CharSequence)} method may be used to test whether or not a
- * character sequence can be encoded.
- *
- * <p> This method may modify this encoder's state; it should therefore not
- * be invoked if an <a href="#steps">encoding operation</a> is already in
- * progress.
- *
- * <p> The default implementation of this method is not very efficient; it
- * should generally be overridden to improve performance. </p>
- *
- * @return <tt>true</tt> if, and only if, this encoder can encode
- * the given character
- *
- * @throws IllegalStateException
- * If $a$ $coding$ operation is already in progress
- */
- public boolean canEncode(char c) {
- CharBuffer cb = CharBuffer.allocate(1);
- cb.put(c);
- cb.flip();
- return canEncode(cb);
- }
-
- /**
- * Tells whether or not this encoder can encode the given character
- * sequence.
- *
- * <p> If this method returns <tt>false</tt> for a particular character
- * sequence then more information about why the sequence cannot be encoded
- * may be obtained by performing a full <a href="#steps">encoding
- * operation</a>.
- *
- * <p> This method may modify this encoder's state; it should therefore not
- * be invoked if an encoding operation is already in progress.
- *
- * <p> The default implementation of this method is not very efficient; it
- * should generally be overridden to improve performance. </p>
- *
- * @return <tt>true</tt> if, and only if, this encoder can encode
- * the given character without throwing any exceptions and without
- * performing any replacements
- *
- * @throws IllegalStateException
- * If $a$ $coding$ operation is already in progress
- */
- public boolean canEncode(CharSequence cs) {
- CharBuffer cb;
- if (cs instanceof CharBuffer)
- cb = ((CharBuffer)cs).duplicate();
- else
- cb = CharBuffer.wrap(cs.toString());
- return canEncode(cb);
- }
-
-#end[encoder]
-
-
- private void throwIllegalStateException(int from, int to) {
- throw new IllegalStateException("Current state = " + stateNames[from]
- + ", new state = " + stateNames[to]);
- }
-
-}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/share/classes/java/nio/charset/Charset-X-Coder.java.template Wed Oct 28 16:54:50 2009 -0700
@@ -0,0 +1,972 @@
+/*
+ * Copyright 2000-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.
+ */
+
+#warn This file is preprocessed before being compiled
+
+package java.nio.charset;
+
+import java.nio.Buffer;
+import java.nio.ByteBuffer;
+import java.nio.CharBuffer;
+import java.nio.BufferOverflowException;
+import java.nio.BufferUnderflowException;
+import java.lang.ref.WeakReference;
+import java.nio.charset.CoderMalfunctionError; // javadoc
+
+
+/**
+ * An engine that can transform a sequence of $itypesPhrase$ into a sequence of
+ * $otypesPhrase$.
+ *
+ * <a name="steps">
+ *
+ * <p> The input $itype$ sequence is provided in a $itype$ buffer or a series
+ * of such buffers. The output $otype$ sequence is written to a $otype$ buffer
+ * or a series of such buffers. $A$ $coder$ should always be used by making
+ * the following sequence of method invocations, hereinafter referred to as $a$
+ * <i>$coding$ operation</i>:
+ *
+ * <ol>
+ *
+ * <li><p> Reset the $coder$ via the {@link #reset reset} method, unless it
+ * has not been used before; </p></li>
+ *
+ * <li><p> Invoke the {@link #$code$ $code$} method zero or more times, as
+ * long as additional input may be available, passing <tt>false</tt> for the
+ * <tt>endOfInput</tt> argument and filling the input buffer and flushing the
+ * output buffer between invocations; </p></li>
+ *
+ * <li><p> Invoke the {@link #$code$ $code$} method one final time, passing
+ * <tt>true</tt> for the <tt>endOfInput</tt> argument; and then </p></li>
+ *
+ * <li><p> Invoke the {@link #flush flush} method so that the $coder$ can
+ * flush any internal state to the output buffer. </p></li>
+ *
+ * </ol>
+ *
+ * Each invocation of the {@link #$code$ $code$} method will $code$ as many
+ * $itype$s as possible from the input buffer, writing the resulting $otype$s
+ * to the output buffer. The {@link #$code$ $code$} method returns when more
+ * input is required, when there is not enough room in the output buffer, or
+ * when $a$ $coding$ error has occurred. In each case a {@link CoderResult}
+ * object is returned to describe the reason for termination. An invoker can
+ * examine this object and fill the input buffer, flush the output buffer, or
+ * attempt to recover from $a$ $coding$ error, as appropriate, and try again.
+ *
+ * <a name="ce">
+ *
+ * <p> There are two general types of $coding$ errors. If the input $itype$
+ * sequence is $notLegal$ then the input is considered <i>malformed</i>. If
+ * the input $itype$ sequence is legal but cannot be mapped to a valid
+ * $outSequence$ then an <i>unmappable character</i> has been encountered.
+ *
+ * <a name="cae">
+ *
+ * <p> How $a$ $coding$ error is handled depends upon the action requested for
+ * that type of error, which is described by an instance of the {@link
+ * CodingErrorAction} class. The possible error actions are to {@link
+ * CodingErrorAction#IGNORE </code>ignore<code>} the erroneous input, {@link
+ * CodingErrorAction#REPORT </code>report<code>} the error to the invoker via
+ * the returned {@link CoderResult} object, or {@link CodingErrorAction#REPLACE
+ * </code>replace<code>} the erroneous input with the current value of the
+ * replacement $replTypeName$. The replacement
+ *
+#if[encoder]
+ * is initially set to the $coder$'s default replacement, which often
+ * (but not always) has the initial value $defaultReplName$;
+#end[encoder]
+#if[decoder]
+ * has the initial value $defaultReplName$;
+#end[decoder]
+ *
+ * its value may be changed via the {@link #replaceWith($replFQType$)
+ * replaceWith} method.
+ *
+ * <p> The default action for malformed-input and unmappable-character errors
+ * is to {@link CodingErrorAction#REPORT </code>report<code>} them. The
+ * malformed-input error action may be changed via the {@link
+ * #onMalformedInput(CodingErrorAction) onMalformedInput} method; the
+ * unmappable-character action may be changed via the {@link
+ * #onUnmappableCharacter(CodingErrorAction) onUnmappableCharacter} method.
+ *
+ * <p> This class is designed to handle many of the details of the $coding$
+ * process, including the implementation of error actions. $A$ $coder$ for a
+ * specific charset, which is a concrete subclass of this class, need only
+ * implement the abstract {@link #$code$Loop $code$Loop} method, which
+ * encapsulates the basic $coding$ loop. A subclass that maintains internal
+ * state should, additionally, override the {@link #implFlush implFlush} and
+ * {@link #implReset implReset} methods.
+ *
+ * <p> Instances of this class are not safe for use by multiple concurrent
+ * threads. </p>
+ *
+ *
+ * @author Mark Reinhold
+ * @author JSR-51 Expert Group
+ * @since 1.4
+ *
+ * @see ByteBuffer
+ * @see CharBuffer
+ * @see Charset
+ * @see Charset$OtherCoder$
+ */
+
+public abstract class Charset$Coder$ {
+
+ private final Charset charset;
+ private final float average$ItypesPerOtype$;
+ private final float max$ItypesPerOtype$;
+
+ private $replType$ replacement;
+ private CodingErrorAction malformedInputAction
+ = CodingErrorAction.REPORT;
+ private CodingErrorAction unmappableCharacterAction
+ = CodingErrorAction.REPORT;
+
+ // Internal states
+ //
+ private static final int ST_RESET = 0;
+ private static final int ST_CODING = 1;
+ private static final int ST_END = 2;
+ private static final int ST_FLUSHED = 3;
+
+ private int state = ST_RESET;
+
+ private static String stateNames[]
+ = { "RESET", "CODING", "CODING_END", "FLUSHED" };
+
+
+ /**
+ * Initializes a new $coder$. The new $coder$ will have the given
+ * $otypes-per-itype$ and replacement values. </p>
+ *
+ * @param average$ItypesPerOtype$
+ * A positive float value indicating the expected number of
+ * $otype$s that will be produced for each input $itype$
+ *
+ * @param max$ItypesPerOtype$
+ * A positive float value indicating the maximum number of
+ * $otype$s that will be produced for each input $itype$
+ *
+ * @param replacement
+ * The initial replacement; must not be <tt>null</tt>, must have
+ * non-zero length, must not be longer than max$ItypesPerOtype$,
+ * and must be {@link #isLegalReplacement </code>legal<code>}
+ *
+ * @throws IllegalArgumentException
+ * If the preconditions on the parameters do not hold
+ */
+ {#if[encoder]?protected:private}
+ Charset$Coder$(Charset cs,
+ float average$ItypesPerOtype$,
+ float max$ItypesPerOtype$,
+ $replType$ replacement)
+ {
+ this.charset = cs;
+ if (average$ItypesPerOtype$ <= 0.0f)
+ throw new IllegalArgumentException("Non-positive "
+ + "average$ItypesPerOtype$");
+ if (max$ItypesPerOtype$ <= 0.0f)
+ throw new IllegalArgumentException("Non-positive "
+ + "max$ItypesPerOtype$");
+ if (!Charset.atBugLevel("1.4")) {
+ if (average$ItypesPerOtype$ > max$ItypesPerOtype$)
+ throw new IllegalArgumentException("average$ItypesPerOtype$"
+ + " exceeds "
+ + "max$ItypesPerOtype$");
+ }
+ this.replacement = replacement;
+ this.average$ItypesPerOtype$ = average$ItypesPerOtype$;
+ this.max$ItypesPerOtype$ = max$ItypesPerOtype$;
+ replaceWith(replacement);
+ }
+
+ /**
+ * Initializes a new $coder$. The new $coder$ will have the given
+ * $otypes-per-itype$ values and its replacement will be the
+ * $replTypeName$ $defaultReplName$. </p>
+ *
+ * @param average$ItypesPerOtype$
+ * A positive float value indicating the expected number of
+ * $otype$s that will be produced for each input $itype$
+ *
+ * @param max$ItypesPerOtype$
+ * A positive float value indicating the maximum number of
+ * $otype$s that will be produced for each input $itype$
+ *
+ * @throws IllegalArgumentException
+ * If the preconditions on the parameters do not hold
+ */
+ protected Charset$Coder$(Charset cs,
+ float average$ItypesPerOtype$,
+ float max$ItypesPerOtype$)
+ {
+ this(cs,
+ average$ItypesPerOtype$, max$ItypesPerOtype$,
+ $defaultRepl$);
+ }
+
+ /**
+ * Returns the charset that created this $coder$. </p>
+ *
+ * @return This $coder$'s charset
+ */
+ public final Charset charset() {
+ return charset;
+ }
+
+ /**
+ * Returns this $coder$'s replacement value. </p>
+ *
+ * @return This $coder$'s current replacement,
+ * which is never <tt>null</tt> and is never empty
+ */
+ public final $replType$ replacement() {
+ return replacement;
+ }
+
+ /**
+ * Changes this $coder$'s replacement value.
+ *
+ * <p> This method invokes the {@link #implReplaceWith implReplaceWith}
+ * method, passing the new replacement, after checking that the new
+ * replacement is acceptable. </p>
+ *
+ * @param newReplacement
+ *
+#if[decoder]
+ * The new replacement; must not be <tt>null</tt>
+ * and must have non-zero length
+#end[decoder]
+#if[encoder]
+ * The new replacement; must not be <tt>null</tt>, must have
+ * non-zero length, must not be longer than the value returned by
+ * the {@link #max$ItypesPerOtype$() max$ItypesPerOtype$} method, and
+ * must be {@link #isLegalReplacement </code>legal<code>}
+#end[encoder]
+ *
+ * @return This $coder$
+ *
+ * @throws IllegalArgumentException
+ * If the preconditions on the parameter do not hold
+ */
+ public final Charset$Coder$ replaceWith($replType$ newReplacement) {
+ if (newReplacement == null)
+ throw new IllegalArgumentException("Null replacement");
+ int len = newReplacement.$replLength$;
+ if (len == 0)
+ throw new IllegalArgumentException("Empty replacement");
+ if (len > max$ItypesPerOtype$)
+ throw new IllegalArgumentException("Replacement too long");
+#if[encoder]
+ if (!isLegalReplacement(newReplacement))
+ throw new IllegalArgumentException("Illegal replacement");
+#end[encoder]
+ this.replacement = newReplacement;
+ implReplaceWith(newReplacement);
+ return this;
+ }
+
+ /**
+ * Reports a change to this $coder$'s replacement value.
+ *
+ * <p> The default implementation of this method does nothing. This method
+ * should be overridden by $coder$s that require notification of changes to
+ * the replacement. </p>
+ *
+ * @param newReplacement
+ */
+ protected void implReplaceWith($replType$ newReplacement) {
+ }
+
+#if[encoder]
+
+ private WeakReference<CharsetDecoder> cachedDecoder = null;
+
+ /**
+ * Tells whether or not the given byte array is a legal replacement value
+ * for this encoder.
+ *
+ * <p> A replacement is legal if, and only if, it is a legal sequence of
+ * bytes in this encoder's charset; that is, it must be possible to decode
+ * the replacement into one or more sixteen-bit Unicode characters.
+ *
+ * <p> The default implementation of this method is not very efficient; it
+ * should generally be overridden to improve performance. </p>
+ *
+ * @param repl The byte array to be tested
+ *
+ * @return <tt>true</tt> if, and only if, the given byte array
+ * is a legal replacement value for this encoder
+ */
+ public boolean isLegalReplacement(byte[] repl) {
+ WeakReference<CharsetDecoder> wr = cachedDecoder;
+ CharsetDecoder dec = null;
+ if ((wr == null) || ((dec = wr.get()) == null)) {
+ dec = charset().newDecoder();
+ dec.onMalformedInput(CodingErrorAction.REPORT);
+ dec.onUnmappableCharacter(CodingErrorAction.REPORT);
+ cachedDecoder = new WeakReference<CharsetDecoder>(dec);
+ } else {
+ dec.reset();
+ }
+ ByteBuffer bb = ByteBuffer.wrap(repl);
+ CharBuffer cb = CharBuffer.allocate((int)(bb.remaining()
+ * dec.maxCharsPerByte()));
+ CoderResult cr = dec.decode(bb, cb, true);
+ return !cr.isError();
+ }
+
+#end[encoder]
+
+ /**
+ * Returns this $coder$'s current action for malformed-input errors. </p>
+ *
+ * @return The current malformed-input action, which is never <tt>null</tt>
+ */
+ public CodingErrorAction malformedInputAction() {
+ return malformedInputAction;
+ }
+
+ /**
+ * Changes this $coder$'s action for malformed-input errors. </p>
+ *
+ * <p> This method invokes the {@link #implOnMalformedInput
+ * implOnMalformedInput} method, passing the new action. </p>
+ *
+ * @param newAction The new action; must not be <tt>null</tt>
+ *
+ * @return This $coder$
+ *
+ * @throws IllegalArgumentException
+ * If the precondition on the parameter does not hold
+ */
+ public final Charset$Coder$ onMalformedInput(CodingErrorAction newAction) {
+ if (newAction == null)
+ throw new IllegalArgumentException("Null action");
+ malformedInputAction = newAction;
+ implOnMalformedInput(newAction);
+ return this;
+ }
+
+ /**
+ * Reports a change to this $coder$'s malformed-input action.
+ *
+ * <p> The default implementation of this method does nothing. This method
+ * should be overridden by $coder$s that require notification of changes to
+ * the malformed-input action. </p>
+ */
+ protected void implOnMalformedInput(CodingErrorAction newAction) { }
+
+ /**
+ * Returns this $coder$'s current action for unmappable-character errors.
+ * </p>
+ *
+ * @return The current unmappable-character action, which is never
+ * <tt>null</tt>
+ */
+ public CodingErrorAction unmappableCharacterAction() {
+ return unmappableCharacterAction;
+ }
+
+ /**
+ * Changes this $coder$'s action for unmappable-character errors.
+ *
+ * <p> This method invokes the {@link #implOnUnmappableCharacter
+ * implOnUnmappableCharacter} method, passing the new action. </p>
+ *
+ * @param newAction The new action; must not be <tt>null</tt>
+ *
+ * @return This $coder$
+ *
+ * @throws IllegalArgumentException
+ * If the precondition on the parameter does not hold
+ */
+ public final Charset$Coder$ onUnmappableCharacter(CodingErrorAction
+ newAction)
+ {
+ if (newAction == null)
+ throw new IllegalArgumentException("Null action");
+ unmappableCharacterAction = newAction;
+ implOnUnmappableCharacter(newAction);
+ return this;
+ }
+
+ /**
+ * Reports a change to this $coder$'s unmappable-character action.
+ *
+ * <p> The default implementation of this method does nothing. This method
+ * should be overridden by $coder$s that require notification of changes to
+ * the unmappable-character action. </p>
+ */
+ protected void implOnUnmappableCharacter(CodingErrorAction newAction) { }
+
+ /**
+ * Returns the average number of $otype$s that will be produced for each
+ * $itype$ of input. This heuristic value may be used to estimate the size
+ * of the output buffer required for a given input sequence. </p>
+ *
+ * @return The average number of $otype$s produced
+ * per $itype$ of input
+ */
+ public final float average$ItypesPerOtype$() {
+ return average$ItypesPerOtype$;
+ }
+
+ /**
+ * Returns the maximum number of $otype$s that will be produced for each
+ * $itype$ of input. This value may be used to compute the worst-case size
+ * of the output buffer required for a given input sequence. </p>
+ *
+ * @return The maximum number of $otype$s that will be produced per
+ * $itype$ of input
+ */
+ public final float max$ItypesPerOtype$() {
+ return max$ItypesPerOtype$;
+ }
+
+ /**
+ * $Code$s as many $itype$s as possible from the given input buffer,
+ * writing the results to the given output buffer.
+ *
+ * <p> The buffers are read from, and written to, starting at their current
+ * positions. At most {@link Buffer#remaining in.remaining()} $itype$s
+ * will be read and at most {@link Buffer#remaining out.remaining()}
+ * $otype$s will be written. The buffers' positions will be advanced to
+ * reflect the $itype$s read and the $otype$s written, but their marks and
+ * limits will not be modified.
+ *
+ * <p> In addition to reading $itype$s from the input buffer and writing
+ * $otype$s to the output buffer, this method returns a {@link CoderResult}
+ * object to describe its reason for termination:
+ *
+ * <ul>
+ *
+ * <li><p> {@link CoderResult#UNDERFLOW} indicates that as much of the
+ * input buffer as possible has been $code$d. If there is no further
+ * input then the invoker can proceed to the next step of the
+ * <a href="#steps">$coding$ operation</a>. Otherwise this method
+ * should be invoked again with further input. </p></li>
+ *
+ * <li><p> {@link CoderResult#OVERFLOW} indicates that there is
+ * insufficient space in the output buffer to $code$ any more $itype$s.
+ * This method should be invoked again with an output buffer that has
+ * more {@linkplain Buffer#remaining remaining} $otype$s. This is
+ * typically done by draining any $code$d $otype$s from the output
+ * buffer. </p></li>
+ *
+ * <li><p> A {@link CoderResult#malformedForLength
+ * </code>malformed-input<code>} result indicates that a malformed-input
+ * error has been detected. The malformed $itype$s begin at the input
+ * buffer's (possibly incremented) position; the number of malformed
+ * $itype$s may be determined by invoking the result object's {@link
+ * CoderResult#length() length} method. This case applies only if the
+ * {@link #onMalformedInput </code>malformed action<code>} of this $coder$
+ * is {@link CodingErrorAction#REPORT}; otherwise the malformed input
+ * will be ignored or replaced, as requested. </p></li>
+ *
+ * <li><p> An {@link CoderResult#unmappableForLength
+ * </code>unmappable-character<code>} result indicates that an
+ * unmappable-character error has been detected. The $itype$s that
+ * $code$ the unmappable character begin at the input buffer's (possibly
+ * incremented) position; the number of such $itype$s may be determined
+ * by invoking the result object's {@link CoderResult#length() length}
+ * method. This case applies only if the {@link #onUnmappableCharacter
+ * </code>unmappable action<code>} of this $coder$ is {@link
+ * CodingErrorAction#REPORT}; otherwise the unmappable character will be
+ * ignored or replaced, as requested. </p></li>
+ *
+ * </ul>
+ *
+ * In any case, if this method is to be reinvoked in the same $coding$
+ * operation then care should be taken to preserve any $itype$s remaining
+ * in the input buffer so that they are available to the next invocation.
+ *
+ * <p> The <tt>endOfInput</tt> parameter advises this method as to whether
+ * the invoker can provide further input beyond that contained in the given
+ * input buffer. If there is a possibility of providing additional input
+ * then the invoker should pass <tt>false</tt> for this parameter; if there
+ * is no possibility of providing further input then the invoker should
+ * pass <tt>true</tt>. It is not erroneous, and in fact it is quite
+ * common, to pass <tt>false</tt> in one invocation and later discover that
+ * no further input was actually available. It is critical, however, that
+ * the final invocation of this method in a sequence of invocations always
+ * pass <tt>true</tt> so that any remaining un$code$d input will be treated
+ * as being malformed.
+ *
+ * <p> This method works by invoking the {@link #$code$Loop $code$Loop}
+ * method, interpreting its results, handling error conditions, and
+ * reinvoking it as necessary. </p>
+ *
+ *
+ * @param in
+ * The input $itype$ buffer
+ *
+ * @param out
+ * The output $otype$ buffer
+ *
+ * @param endOfInput
+ * <tt>true</tt> if, and only if, the invoker can provide no
+ * additional input $itype$s beyond those in the given buffer
+ *
+ * @return A coder-result object describing the reason for termination
+ *
+ * @throws IllegalStateException
+ * If $a$ $coding$ operation is already in progress and the previous
+ * step was an invocation neither of the {@link #reset reset}
+ * method, nor of this method with a value of <tt>false</tt> for
+ * the <tt>endOfInput</tt> parameter, nor of this method with a
+ * value of <tt>true</tt> for the <tt>endOfInput</tt> parameter
+ * but a return value indicating an incomplete $coding$ operation
+ *
+ * @throws CoderMalfunctionError
+ * If an invocation of the $code$Loop method threw
+ * an unexpected exception
+ */
+ public final CoderResult $code$($Itype$Buffer in, $Otype$Buffer out,
+ boolean endOfInput)
+ {
+ int newState = endOfInput ? ST_END : ST_CODING;
+ if ((state != ST_RESET) && (state != ST_CODING)
+ && !(endOfInput && (state == ST_END)))
+ throwIllegalStateException(state, newState);
+ state = newState;
+
+ for (;;) {
+
+ CoderResult cr;
+ try {
+ cr = $code$Loop(in, out);
+ } catch (BufferUnderflowException x) {
+ throw new CoderMalfunctionError(x);
+ } catch (BufferOverflowException x) {
+ throw new CoderMalfunctionError(x);
+ }
+
+ if (cr.isOverflow())
+ return cr;
+
+ if (cr.isUnderflow()) {
+ if (endOfInput && in.hasRemaining()) {
+ cr = CoderResult.malformedForLength(in.remaining());
+ // Fall through to malformed-input case
+ } else {
+ return cr;
+ }
+ }
+
+ CodingErrorAction action = null;
+ if (cr.isMalformed())
+ action = malformedInputAction;
+ else if (cr.isUnmappable())
+ action = unmappableCharacterAction;
+ else
+ assert false : cr.toString();
+
+ if (action == CodingErrorAction.REPORT)
+ return cr;
+
+ if (action == CodingErrorAction.REPLACE) {
+ if (out.remaining() < replacement.$replLength$)
+ return CoderResult.OVERFLOW;
+ out.put(replacement);
+ }
+
+ if ((action == CodingErrorAction.IGNORE)
+ || (action == CodingErrorAction.REPLACE)) {
+ // Skip erroneous input either way
+ in.position(in.position() + cr.length());
+ continue;
+ }
+
+ assert false;
+ }
+
+ }
+
+ /**
+ * Flushes this $coder$.
+ *
+ * <p> Some $coder$s maintain internal state and may need to write some
+ * final $otype$s to the output buffer once the overall input sequence has
+ * been read.
+ *
+ * <p> Any additional output is written to the output buffer beginning at
+ * its current position. At most {@link Buffer#remaining out.remaining()}
+ * $otype$s will be written. The buffer's position will be advanced
+ * appropriately, but its mark and limit will not be modified.
+ *
+ * <p> If this method completes successfully then it returns {@link
+ * CoderResult#UNDERFLOW}. If there is insufficient room in the output
+ * buffer then it returns {@link CoderResult#OVERFLOW}. If this happens
+ * then this method must be invoked again, with an output buffer that has
+ * more room, in order to complete the current <a href="#steps">$coding$
+ * operation</a>.
+ *
+ * <p> If this $coder$ has already been flushed then invoking this method
+ * has no effect.
+ *
+ * <p> This method invokes the {@link #implFlush implFlush} method to
+ * perform the actual flushing operation. </p>
+ *
+ * @param out
+ * The output $otype$ buffer
+ *
+ * @return A coder-result object, either {@link CoderResult#UNDERFLOW} or
+ * {@link CoderResult#OVERFLOW}
+ *
+ * @throws IllegalStateException
+ * If the previous step of the current $coding$ operation was an
+ * invocation neither of the {@link #flush flush} method nor of
+ * the three-argument {@link
+ * #$code$($Itype$Buffer,$Otype$Buffer,boolean) $code$} method
+ * with a value of <tt>true</tt> for the <tt>endOfInput</tt>
+ * parameter
+ */
+ public final CoderResult flush($Otype$Buffer out) {
+ if (state == ST_END) {
+ CoderResult cr = implFlush(out);
+ if (cr.isUnderflow())
+ state = ST_FLUSHED;
+ return cr;
+ }
+
+ if (state != ST_FLUSHED)
+ throwIllegalStateException(state, ST_FLUSHED);
+
+ return CoderResult.UNDERFLOW; // Already flushed
+ }
+
+ /**
+ * Flushes this $coder$.
+ *
+ * <p> The default implementation of this method does nothing, and always
+ * returns {@link CoderResult#UNDERFLOW}. This method should be overridden
+ * by $coder$s that may need to write final $otype$s to the output buffer
+ * once the entire input sequence has been read. </p>
+ *
+ * @param out
+ * The output $otype$ buffer
+ *
+ * @return A coder-result object, either {@link CoderResult#UNDERFLOW} or
+ * {@link CoderResult#OVERFLOW}
+ */
+ protected CoderResult implFlush($Otype$Buffer out) {
+ return CoderResult.UNDERFLOW;
+ }
+
+ /**
+ * Resets this $coder$, clearing any internal state.
+ *
+ * <p> This method resets charset-independent state and also invokes the
+ * {@link #implReset() implReset} method in order to perform any
+ * charset-specific reset actions. </p>
+ *
+ * @return This $coder$
+ *
+ */
+ public final Charset$Coder$ reset() {
+ implReset();
+ state = ST_RESET;
+ return this;
+ }
+
+ /**
+ * Resets this $coder$, clearing any charset-specific internal state.
+ *
+ * <p> The default implementation of this method does nothing. This method
+ * should be overridden by $coder$s that maintain internal state. </p>
+ */
+ protected void implReset() { }
+
+ /**
+ * $Code$s one or more $itype$s into one or more $otype$s.
+ *
+ * <p> This method encapsulates the basic $coding$ loop, $coding$ as many
+ * $itype$s as possible until it either runs out of input, runs out of room
+ * in the output buffer, or encounters $a$ $coding$ error. This method is
+ * invoked by the {@link #$code$ $code$} method, which handles result
+ * interpretation and error recovery.
+ *
+ * <p> The buffers are read from, and written to, starting at their current
+ * positions. At most {@link Buffer#remaining in.remaining()} $itype$s
+ * will be read, and at most {@link Buffer#remaining out.remaining()}
+ * $otype$s will be written. The buffers' positions will be advanced to
+ * reflect the $itype$s read and the $otype$s written, but their marks and
+ * limits will not be modified.
+ *
+ * <p> This method returns a {@link CoderResult} object to describe its
+ * reason for termination, in the same manner as the {@link #$code$ $code$}
+ * method. Most implementations of this method will handle $coding$ errors
+ * by returning an appropriate result object for interpretation by the
+ * {@link #$code$ $code$} method. An optimized implementation may instead
+ * examine the relevant error action and implement that action itself.
+ *
+ * <p> An implementation of this method may perform arbitrary lookahead by
+ * returning {@link CoderResult#UNDERFLOW} until it receives sufficient
+ * input. </p>
+ *
+ * @param in
+ * The input $itype$ buffer
+ *
+ * @param out
+ * The output $otype$ buffer
+ *
+ * @return A coder-result object describing the reason for termination
+ */
+ protected abstract CoderResult $code$Loop($Itype$Buffer in,
+ $Otype$Buffer out);
+
+ /**
+ * Convenience method that $code$s the remaining content of a single input
+ * $itype$ buffer into a newly-allocated $otype$ buffer.
+ *
+ * <p> This method implements an entire <a href="#steps">$coding$
+ * operation</a>; that is, it resets this $coder$, then it $code$s the
+ * $itype$s in the given $itype$ buffer, and finally it flushes this
+ * $coder$. This method should therefore not be invoked if $a$ $coding$
+ * operation is already in progress. </p>
+ *
+ * @param in
+ * The input $itype$ buffer
+ *
+ * @return A newly-allocated $otype$ buffer containing the result of the
+ * $coding$ operation. The buffer's position will be zero and its
+ * limit will follow the last $otype$ written.
+ *
+ * @throws IllegalStateException
+ * If $a$ $coding$ operation is already in progress
+ *
+ * @throws MalformedInputException
+ * If the $itype$ sequence starting at the input buffer's current
+ * position is $notLegal$ and the current malformed-input action
+ * is {@link CodingErrorAction#REPORT}
+ *
+ * @throws UnmappableCharacterException
+ * If the $itype$ sequence starting at the input buffer's current
+ * position cannot be mapped to an equivalent $otype$ sequence and
+ * the current unmappable-character action is {@link
+ * CodingErrorAction#REPORT}
+ */
+ public final $Otype$Buffer $code$($Itype$Buffer in)
+ throws CharacterCodingException
+ {
+ int n = (int)(in.remaining() * average$ItypesPerOtype$());
+ $Otype$Buffer out = $Otype$Buffer.allocate(n);
+
+ if ((n == 0) && (in.remaining() == 0))
+ return out;
+ reset();
+ for (;;) {
+ CoderResult cr = in.hasRemaining() ?
+ $code$(in, out, true) : CoderResult.UNDERFLOW;
+ if (cr.isUnderflow())
+ cr = flush(out);
+
+ if (cr.isUnderflow())
+ break;
+ if (cr.isOverflow()) {
+ n = 2*n + 1; // Ensure progress; n might be 0!
+ $Otype$Buffer o = $Otype$Buffer.allocate(n);
+ out.flip();
+ o.put(out);
+ out = o;
+ continue;
+ }
+ cr.throwException();
+ }
+ out.flip();
+ return out;
+ }
+
+#if[decoder]
+
+ /**
+ * Tells whether or not this decoder implements an auto-detecting charset.
+ *
+ * <p> The default implementation of this method always returns
+ * <tt>false</tt>; it should be overridden by auto-detecting decoders to
+ * return <tt>true</tt>. </p>
+ *
+ * @return <tt>true</tt> if, and only if, this decoder implements an
+ * auto-detecting charset
+ */
+ public boolean isAutoDetecting() {
+ return false;
+ }
+
+ /**
+ * Tells whether or not this decoder has yet detected a
+ * charset <i>(optional operation)</i>.
+ *
+ * <p> If this decoder implements an auto-detecting charset then at a
+ * single point during a decoding operation this method may start returning
+ * <tt>true</tt> to indicate that a specific charset has been detected in
+ * the input byte sequence. Once this occurs, the {@link #detectedCharset
+ * detectedCharset} method may be invoked to retrieve the detected charset.
+ *
+ * <p> That this method returns <tt>false</tt> does not imply that no bytes
+ * have yet been decoded. Some auto-detecting decoders are capable of
+ * decoding some, or even all, of an input byte sequence without fixing on
+ * a particular charset.
+ *
+ * <p> The default implementation of this method always throws an {@link
+ * UnsupportedOperationException}; it should be overridden by
+ * auto-detecting decoders to return <tt>true</tt> once the input charset
+ * has been determined. </p>
+ *
+ * @return <tt>true</tt> if, and only if, this decoder has detected a
+ * specific charset
+ *
+ * @throws UnsupportedOperationException
+ * If this decoder does not implement an auto-detecting charset
+ */
+ public boolean isCharsetDetected() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * Retrieves the charset that was detected by this
+ * decoder <i>(optional operation)</i>.
+ *
+ * <p> If this decoder implements an auto-detecting charset then this
+ * method returns the actual charset once it has been detected. After that
+ * point, this method returns the same value for the duration of the
+ * current decoding operation. If not enough input bytes have yet been
+ * read to determine the actual charset then this method throws an {@link
+ * IllegalStateException}.
+ *
+ * <p> The default implementation of this method always throws an {@link
+ * UnsupportedOperationException}; it should be overridden by
+ * auto-detecting decoders to return the appropriate value. </p>
+ *
+ * @return The charset detected by this auto-detecting decoder,
+ * or <tt>null</tt> if the charset has not yet been determined
+ *
+ * @throws IllegalStateException
+ * If insufficient bytes have been read to determine a charset
+ *
+ * @throws UnsupportedOperationException
+ * If this decoder does not implement an auto-detecting charset
+ */
+ public Charset detectedCharset() {
+ throw new UnsupportedOperationException();
+ }
+
+#end[decoder]
+
+#if[encoder]
+
+ private boolean canEncode(CharBuffer cb) {
+ if (state == ST_FLUSHED)
+ reset();
+ else if (state != ST_RESET)
+ throwIllegalStateException(state, ST_CODING);
+ CodingErrorAction ma = malformedInputAction();
+ CodingErrorAction ua = unmappableCharacterAction();
+ try {
+ onMalformedInput(CodingErrorAction.REPORT);
+ onUnmappableCharacter(CodingErrorAction.REPORT);
+ encode(cb);
+ } catch (CharacterCodingException x) {
+ return false;
+ } finally {
+ onMalformedInput(ma);
+ onUnmappableCharacter(ua);
+ reset();
+ }
+ return true;
+ }
+
+ /**
+ * Tells whether or not this encoder can encode the given character.
+ *
+ * <p> This method returns <tt>false</tt> if the given character is a
+ * surrogate character; such characters can be interpreted only when they
+ * are members of a pair consisting of a high surrogate followed by a low
+ * surrogate. The {@link #canEncode(java.lang.CharSequence)
+ * canEncode(CharSequence)} method may be used to test whether or not a
+ * character sequence can be encoded.
+ *
+ * <p> This method may modify this encoder's state; it should therefore not
+ * be invoked if an <a href="#steps">encoding operation</a> is already in
+ * progress.
+ *
+ * <p> The default implementation of this method is not very efficient; it
+ * should generally be overridden to improve performance. </p>
+ *
+ * @return <tt>true</tt> if, and only if, this encoder can encode
+ * the given character
+ *
+ * @throws IllegalStateException
+ * If $a$ $coding$ operation is already in progress
+ */
+ public boolean canEncode(char c) {
+ CharBuffer cb = CharBuffer.allocate(1);
+ cb.put(c);
+ cb.flip();
+ return canEncode(cb);
+ }
+
+ /**
+ * Tells whether or not this encoder can encode the given character
+ * sequence.
+ *
+ * <p> If this method returns <tt>false</tt> for a particular character
+ * sequence then more information about why the sequence cannot be encoded
+ * may be obtained by performing a full <a href="#steps">encoding
+ * operation</a>.
+ *
+ * <p> This method may modify this encoder's state; it should therefore not
+ * be invoked if an encoding operation is already in progress.
+ *
+ * <p> The default implementation of this method is not very efficient; it
+ * should generally be overridden to improve performance. </p>
+ *
+ * @return <tt>true</tt> if, and only if, this encoder can encode
+ * the given character without throwing any exceptions and without
+ * performing any replacements
+ *
+ * @throws IllegalStateException
+ * If $a$ $coding$ operation is already in progress
+ */
+ public boolean canEncode(CharSequence cs) {
+ CharBuffer cb;
+ if (cs instanceof CharBuffer)
+ cb = ((CharBuffer)cs).duplicate();
+ else
+ cb = CharBuffer.wrap(cs.toString());
+ return canEncode(cb);
+ }
+
+#end[encoder]
+
+
+ private void throwIllegalStateException(int from, int to) {
+ throw new IllegalStateException("Current state = " + stateNames[from]
+ + ", new state = " + stateNames[to]);
+ }
+
+}
--- a/jdk/src/share/classes/sun/misc/Version-template.java Wed Oct 28 16:26:52 2009 -0700
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,327 +0,0 @@
-/*
- * Copyright 1999-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. 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.misc;
-import java.io.PrintStream;
-
-public class Version {
-
-
- private static final String launcher_name =
- "@@launcher_name@@";
-
- private static final String java_version =
- "@@java_version@@";
-
- private static final String java_runtime_name =
- "@@java_runtime_name@@";
-
- private static final String java_runtime_version =
- "@@java_runtime_version@@";
-
- static {
- init();
- }
-
- public static void init() {
- System.setProperty("java.version", java_version);
- System.setProperty("java.runtime.version", java_runtime_version);
- System.setProperty("java.runtime.name", java_runtime_name);
- }
-
- private static boolean versionsInitialized = false;
- private static int jvm_major_version = 0;
- private static int jvm_minor_version = 0;
- private static int jvm_micro_version = 0;
- private static int jvm_update_version = 0;
- private static int jvm_build_number = 0;
- private static String jvm_special_version = null;
- private static int jdk_major_version = 0;
- private static int jdk_minor_version = 0;
- private static int jdk_micro_version = 0;
- private static int jdk_update_version = 0;
- private static int jdk_build_number = 0;
- private static String jdk_special_version = null;
-
- /**
- * In case you were wondering this method is called by java -version.
- * Sad that it prints to stderr; would be nicer if default printed on
- * stdout.
- */
- public static void print() {
- print(System.err);
- }
-
- /**
- * This is the same as print except that it adds an extra line-feed
- * at the end, typically used by the -showversion in the launcher
- */
- public static void println() {
- print(System.err);
- System.err.println();
- }
-
- /**
- * Give a stream, it will print version info on it.
- */
- public static void print(PrintStream ps) {
- /* First line: platform version. */
- ps.println(launcher_name + " version \"" + java_version + "\"");
-
- /* Second line: runtime version (ie, libraries). */
- ps.println(java_runtime_name + " (build " +
- java_runtime_version + ")");
-
- /* Third line: JVM information. */
- String java_vm_name = System.getProperty("java.vm.name");
- String java_vm_version = System.getProperty("java.vm.version");
- String java_vm_info = System.getProperty("java.vm.info");
- ps.println(java_vm_name + " (build " + java_vm_version + ", " +
- java_vm_info + ")");
- }
-
-
- /**
- * Returns the major version of the running JVM if it's 1.6 or newer
- * or any RE VM build. It will return 0 if it's an internal 1.5 or
- * 1.4.x build.
- *
- * @since 1.6
- */
- public static synchronized int jvmMajorVersion() {
- if (!versionsInitialized) {
- initVersions();
- }
- return jvm_major_version;
- }
-
- /**
- * Returns the minor version of the running JVM if it's 1.6 or newer
- * or any RE VM build. It will return 0 if it's an internal 1.5 or
- * 1.4.x build.
- * @since 1.6
- */
- public static synchronized int jvmMinorVersion() {
- if (!versionsInitialized) {
- initVersions();
- }
- return jvm_minor_version;
- }
-
-
- /**
- * Returns the micro version of the running JVM if it's 1.6 or newer
- * or any RE VM build. It will return 0 if it's an internal 1.5 or
- * 1.4.x build.
- * @since 1.6
- */
- public static synchronized int jvmMicroVersion() {
- if (!versionsInitialized) {
- initVersions();
- }
- return jvm_micro_version;
- }
-
- /**
- * Returns the update release version of the running JVM if it's
- * a RE build. It will return 0 if it's an internal build.
- * @since 1.6
- */
- public static synchronized int jvmUpdateVersion() {
- if (!versionsInitialized) {
- initVersions();
- }
- return jvm_update_version;
- }
-
- public static synchronized String jvmSpecialVersion() {
- if (!versionsInitialized) {
- initVersions();
- }
- if (jvm_special_version == null) {
- jvm_special_version = getJvmSpecialVersion();
- }
- return jvm_special_version;
- }
- public static native String getJvmSpecialVersion();
-
- /**
- * Returns the build number of the running JVM if it's a RE build
- * It will return 0 if it's an internal build.
- * @since 1.6
- */
- public static synchronized int jvmBuildNumber() {
- if (!versionsInitialized) {
- initVersions();
- }
- return jvm_build_number;
- }
-
- /**
- * Returns the major version of the running JDK.
- *
- * @since 1.6
- */
- public static synchronized int jdkMajorVersion() {
- if (!versionsInitialized) {
- initVersions();
- }
- return jdk_major_version;
- }
-
- /**
- * Returns the minor version of the running JDK.
- * @since 1.6
- */
- public static synchronized int jdkMinorVersion() {
- if (!versionsInitialized) {
- initVersions();
- }
- return jdk_minor_version;
- }
-
- /**
- * Returns the micro version of the running JDK.
- * @since 1.6
- */
- public static synchronized int jdkMicroVersion() {
- if (!versionsInitialized) {
- initVersions();
- }
- return jdk_micro_version;
- }
-
- /**
- * Returns the update release version of the running JDK if it's
- * a RE build. It will return 0 if it's an internal build.
- * @since 1.6
- */
- public static synchronized int jdkUpdateVersion() {
- if (!versionsInitialized) {
- initVersions();
- }
- return jdk_update_version;
- }
-
- public static synchronized String jdkSpecialVersion() {
- if (!versionsInitialized) {
- initVersions();
- }
- if (jdk_special_version == null) {
- jdk_special_version = getJdkSpecialVersion();
- }
- return jdk_special_version;
- }
- public static native String getJdkSpecialVersion();
-
- /**
- * Returns the build number of the running JDK if it's a RE build
- * It will return 0 if it's an internal build.
- * @since 1.6
- */
- public static synchronized int jdkBuildNumber() {
- if (!versionsInitialized) {
- initVersions();
- }
- return jdk_build_number;
- }
-
- // true if JVM exports the version info including the capabilities
- private static boolean jvmVersionInfoAvailable;
- private static synchronized void initVersions() {
- if (versionsInitialized) {
- return;
- }
- jvmVersionInfoAvailable = getJvmVersionInfo();
- if (!jvmVersionInfoAvailable) {
- // parse java.vm.version for older JVM before the
- // new JVM_GetVersionInfo is added.
- // valid format of the version string is:
- // n.n.n[_uu[c]][-<identifer>]-bxx
- CharSequence cs = System.getProperty("java.vm.version");
- if (cs.length() >= 5 &&
- Character.isDigit(cs.charAt(0)) && cs.charAt(1) == '.' &&
- Character.isDigit(cs.charAt(2)) && cs.charAt(3) == '.' &&
- Character.isDigit(cs.charAt(4))) {
- jvm_major_version = Character.digit(cs.charAt(0), 10);
- jvm_minor_version = Character.digit(cs.charAt(2), 10);
- jvm_micro_version = Character.digit(cs.charAt(4), 10);
- cs = cs.subSequence(5, cs.length());
- if (cs.charAt(0) == '_' && cs.length() >= 3 &&
- Character.isDigit(cs.charAt(1)) &&
- Character.isDigit(cs.charAt(2))) {
- int nextChar = 3;
- try {
- String uu = cs.subSequence(1, 3).toString();
- jvm_update_version = Integer.valueOf(uu).intValue();
- if (cs.length() >= 4) {
- char c = cs.charAt(3);
- if (c >= 'a' && c <= 'z') {
- jvm_special_version = Character.toString(c);
- nextChar++;
- }
- }
- } catch (NumberFormatException e) {
- // not conforming to the naming convention
- return;
- }
- cs = cs.subSequence(nextChar, cs.length());
- }
- if (cs.charAt(0) == '-') {
- // skip the first character
- // valid format: <identifier>-bxx or bxx
- // non-product VM will have -debug|-release appended
- cs = cs.subSequence(1, cs.length());
- String[] res = cs.toString().split("-");
- for (String s : res) {
- if (s.charAt(0) == 'b' && s.length() == 3 &&
- Character.isDigit(s.charAt(1)) &&
- Character.isDigit(s.charAt(2))) {
- jvm_build_number =
- Integer.valueOf(s.substring(1, 3)).intValue();
- break;
- }
- }
- }
- }
- }
- getJdkVersionInfo();
- versionsInitialized = true;
- }
-
- // Gets the JVM version info if available and sets the jvm_*_version fields
- // and its capabilities.
- //
- // Return false if not available which implies an old VM (Tiger or before).
- private static native boolean getJvmVersionInfo();
- private static native void getJdkVersionInfo();
-
-}
-
-// Help Emacs a little because this file doesn't end in .java.
-//
-// Local Variables: ***
-// mode: java ***
-// End: ***
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/share/classes/sun/misc/Version.java.template Wed Oct 28 16:54:50 2009 -0700
@@ -0,0 +1,327 @@
+/*
+ * Copyright 1999-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. 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.misc;
+import java.io.PrintStream;
+
+public class Version {
+
+
+ private static final String launcher_name =
+ "@@launcher_name@@";
+
+ private static final String java_version =
+ "@@java_version@@";
+
+ private static final String java_runtime_name =
+ "@@java_runtime_name@@";
+
+ private static final String java_runtime_version =
+ "@@java_runtime_version@@";
+
+ static {
+ init();
+ }
+
+ public static void init() {
+ System.setProperty("java.version", java_version);
+ System.setProperty("java.runtime.version", java_runtime_version);
+ System.setProperty("java.runtime.name", java_runtime_name);
+ }
+
+ private static boolean versionsInitialized = false;
+ private static int jvm_major_version = 0;
+ private static int jvm_minor_version = 0;
+ private static int jvm_micro_version = 0;
+ private static int jvm_update_version = 0;
+ private static int jvm_build_number = 0;
+ private static String jvm_special_version = null;
+ private static int jdk_major_version = 0;
+ private static int jdk_minor_version = 0;
+ private static int jdk_micro_version = 0;
+ private static int jdk_update_version = 0;
+ private static int jdk_build_number = 0;
+ private static String jdk_special_version = null;
+
+ /**
+ * In case you were wondering this method is called by java -version.
+ * Sad that it prints to stderr; would be nicer if default printed on
+ * stdout.
+ */
+ public static void print() {
+ print(System.err);
+ }
+
+ /**
+ * This is the same as print except that it adds an extra line-feed
+ * at the end, typically used by the -showversion in the launcher
+ */
+ public static void println() {
+ print(System.err);
+ System.err.println();
+ }
+
+ /**
+ * Give a stream, it will print version info on it.
+ */
+ public static void print(PrintStream ps) {
+ /* First line: platform version. */
+ ps.println(launcher_name + " version \"" + java_version + "\"");
+
+ /* Second line: runtime version (ie, libraries). */
+ ps.println(java_runtime_name + " (build " +
+ java_runtime_version + ")");
+
+ /* Third line: JVM information. */
+ String java_vm_name = System.getProperty("java.vm.name");
+ String java_vm_version = System.getProperty("java.vm.version");
+ String java_vm_info = System.getProperty("java.vm.info");
+ ps.println(java_vm_name + " (build " + java_vm_version + ", " +
+ java_vm_info + ")");
+ }
+
+
+ /**
+ * Returns the major version of the running JVM if it's 1.6 or newer
+ * or any RE VM build. It will return 0 if it's an internal 1.5 or
+ * 1.4.x build.
+ *
+ * @since 1.6
+ */
+ public static synchronized int jvmMajorVersion() {
+ if (!versionsInitialized) {
+ initVersions();
+ }
+ return jvm_major_version;
+ }
+
+ /**
+ * Returns the minor version of the running JVM if it's 1.6 or newer
+ * or any RE VM build. It will return 0 if it's an internal 1.5 or
+ * 1.4.x build.
+ * @since 1.6
+ */
+ public static synchronized int jvmMinorVersion() {
+ if (!versionsInitialized) {
+ initVersions();
+ }
+ return jvm_minor_version;
+ }
+
+
+ /**
+ * Returns the micro version of the running JVM if it's 1.6 or newer
+ * or any RE VM build. It will return 0 if it's an internal 1.5 or
+ * 1.4.x build.
+ * @since 1.6
+ */
+ public static synchronized int jvmMicroVersion() {
+ if (!versionsInitialized) {
+ initVersions();
+ }
+ return jvm_micro_version;
+ }
+
+ /**
+ * Returns the update release version of the running JVM if it's
+ * a RE build. It will return 0 if it's an internal build.
+ * @since 1.6
+ */
+ public static synchronized int jvmUpdateVersion() {
+ if (!versionsInitialized) {
+ initVersions();
+ }
+ return jvm_update_version;
+ }
+
+ public static synchronized String jvmSpecialVersion() {
+ if (!versionsInitialized) {
+ initVersions();
+ }
+ if (jvm_special_version == null) {
+ jvm_special_version = getJvmSpecialVersion();
+ }
+ return jvm_special_version;
+ }
+ public static native String getJvmSpecialVersion();
+
+ /**
+ * Returns the build number of the running JVM if it's a RE build
+ * It will return 0 if it's an internal build.
+ * @since 1.6
+ */
+ public static synchronized int jvmBuildNumber() {
+ if (!versionsInitialized) {
+ initVersions();
+ }
+ return jvm_build_number;
+ }
+
+ /**
+ * Returns the major version of the running JDK.
+ *
+ * @since 1.6
+ */
+ public static synchronized int jdkMajorVersion() {
+ if (!versionsInitialized) {
+ initVersions();
+ }
+ return jdk_major_version;
+ }
+
+ /**
+ * Returns the minor version of the running JDK.
+ * @since 1.6
+ */
+ public static synchronized int jdkMinorVersion() {
+ if (!versionsInitialized) {
+ initVersions();
+ }
+ return jdk_minor_version;
+ }
+
+ /**
+ * Returns the micro version of the running JDK.
+ * @since 1.6
+ */
+ public static synchronized int jdkMicroVersion() {
+ if (!versionsInitialized) {
+ initVersions();
+ }
+ return jdk_micro_version;
+ }
+
+ /**
+ * Returns the update release version of the running JDK if it's
+ * a RE build. It will return 0 if it's an internal build.
+ * @since 1.6
+ */
+ public static synchronized int jdkUpdateVersion() {
+ if (!versionsInitialized) {
+ initVersions();
+ }
+ return jdk_update_version;
+ }
+
+ public static synchronized String jdkSpecialVersion() {
+ if (!versionsInitialized) {
+ initVersions();
+ }
+ if (jdk_special_version == null) {
+ jdk_special_version = getJdkSpecialVersion();
+ }
+ return jdk_special_version;
+ }
+ public static native String getJdkSpecialVersion();
+
+ /**
+ * Returns the build number of the running JDK if it's a RE build
+ * It will return 0 if it's an internal build.
+ * @since 1.6
+ */
+ public static synchronized int jdkBuildNumber() {
+ if (!versionsInitialized) {
+ initVersions();
+ }
+ return jdk_build_number;
+ }
+
+ // true if JVM exports the version info including the capabilities
+ private static boolean jvmVersionInfoAvailable;
+ private static synchronized void initVersions() {
+ if (versionsInitialized) {
+ return;
+ }
+ jvmVersionInfoAvailable = getJvmVersionInfo();
+ if (!jvmVersionInfoAvailable) {
+ // parse java.vm.version for older JVM before the
+ // new JVM_GetVersionInfo is added.
+ // valid format of the version string is:
+ // n.n.n[_uu[c]][-<identifer>]-bxx
+ CharSequence cs = System.getProperty("java.vm.version");
+ if (cs.length() >= 5 &&
+ Character.isDigit(cs.charAt(0)) && cs.charAt(1) == '.' &&
+ Character.isDigit(cs.charAt(2)) && cs.charAt(3) == '.' &&
+ Character.isDigit(cs.charAt(4))) {
+ jvm_major_version = Character.digit(cs.charAt(0), 10);
+ jvm_minor_version = Character.digit(cs.charAt(2), 10);
+ jvm_micro_version = Character.digit(cs.charAt(4), 10);
+ cs = cs.subSequence(5, cs.length());
+ if (cs.charAt(0) == '_' && cs.length() >= 3 &&
+ Character.isDigit(cs.charAt(1)) &&
+ Character.isDigit(cs.charAt(2))) {
+ int nextChar = 3;
+ try {
+ String uu = cs.subSequence(1, 3).toString();
+ jvm_update_version = Integer.valueOf(uu).intValue();
+ if (cs.length() >= 4) {
+ char c = cs.charAt(3);
+ if (c >= 'a' && c <= 'z') {
+ jvm_special_version = Character.toString(c);
+ nextChar++;
+ }
+ }
+ } catch (NumberFormatException e) {
+ // not conforming to the naming convention
+ return;
+ }
+ cs = cs.subSequence(nextChar, cs.length());
+ }
+ if (cs.charAt(0) == '-') {
+ // skip the first character
+ // valid format: <identifier>-bxx or bxx
+ // non-product VM will have -debug|-release appended
+ cs = cs.subSequence(1, cs.length());
+ String[] res = cs.toString().split("-");
+ for (String s : res) {
+ if (s.charAt(0) == 'b' && s.length() == 3 &&
+ Character.isDigit(s.charAt(1)) &&
+ Character.isDigit(s.charAt(2))) {
+ jvm_build_number =
+ Integer.valueOf(s.substring(1, 3)).intValue();
+ break;
+ }
+ }
+ }
+ }
+ }
+ getJdkVersionInfo();
+ versionsInitialized = true;
+ }
+
+ // Gets the JVM version info if available and sets the jvm_*_version fields
+ // and its capabilities.
+ //
+ // Return false if not available which implies an old VM (Tiger or before).
+ private static native boolean getJvmVersionInfo();
+ private static native void getJdkVersionInfo();
+
+}
+
+// Help Emacs a little because this file doesn't end in .java.
+//
+// Local Variables: ***
+// mode: java ***
+// End: ***
--- a/jdk/src/share/classes/sun/tools/jconsole/Version-template.java Wed Oct 28 16:26:52 2009 -0700
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,55 +0,0 @@
-/*
- * Copyright 2004-2006 Sun Microsystems, Inc. All Rights Reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute 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.tools.jconsole;
-
-import java.io.PrintStream;
-
-public class Version {
- private static final String jconsole_version =
- "@@jconsole_version@@";
-
- public static void print(PrintStream ps) {
- printFullVersion(ps);
-
- ps.println(Resources.getText("Name and Build",
- System.getProperty("java.runtime.name"),
- System.getProperty("java.runtime.version")));
-
- ps.println(Resources.getText("Name Build and Mode",
- System.getProperty("java.vm.name"),
- System.getProperty("java.vm.version"),
- System.getProperty("java.vm.info")));
-
- }
-
- public static void printFullVersion(PrintStream ps) {
- ps.println(Resources.getText("JConsole version", jconsole_version));
- }
-
- static String getVersion() {
- return jconsole_version;
- }
-}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/share/classes/sun/tools/jconsole/Version.java.template Wed Oct 28 16:54:50 2009 -0700
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2004-2006 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute 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.tools.jconsole;
+
+import java.io.PrintStream;
+
+public class Version {
+ private static final String jconsole_version =
+ "@@jconsole_version@@";
+
+ public static void print(PrintStream ps) {
+ printFullVersion(ps);
+
+ ps.println(Resources.getText("Name and Build",
+ System.getProperty("java.runtime.name"),
+ System.getProperty("java.runtime.version")));
+
+ ps.println(Resources.getText("Name Build and Mode",
+ System.getProperty("java.vm.name"),
+ System.getProperty("java.vm.version"),
+ System.getProperty("java.vm.info")));
+
+ }
+
+ public static void printFullVersion(PrintStream ps) {
+ ps.println(Resources.getText("JConsole version", jconsole_version));
+ }
+
+ static String getVersion() {
+ return jconsole_version;
+ }
+}
--- a/jdk/test/java/nio/Buffer/Basic-X.java Wed Oct 28 16:26:52 2009 -0700
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,869 +0,0 @@
-/*
- * Copyright 2000-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.
- */
-
-/* Type-specific source code for unit test
- *
- * Regenerate the BasicX classes via genBasic.sh whenever this file changes.
- * We check in the generated source files so that the test tree can be used
- * independently of the rest of the source tree.
- */
-
-#warn This file is preprocessed before being compiled
-
-import java.nio.*;
-import java.lang.reflect.Method;
-
-
-public class Basic$Type$
- extends Basic
-{
-
- private static void relGet($Type$Buffer b) {
- int n = b.capacity();
- $type$ v;
- for (int i = 0; i < n; i++)
- ck(b, (long)b.get(), (long)(($type$)ic(i)));
- b.rewind();
- }
-
- private static void relGet($Type$Buffer b, int start) {
- int n = b.remaining();
- $type$ v;
- for (int i = start; i < n; i++)
- ck(b, (long)b.get(), (long)(($type$)ic(i)));
- b.rewind();
- }
-
- private static void absGet($Type$Buffer b) {
- int n = b.capacity();
- $type$ v;
- for (int i = 0; i < n; i++)
- ck(b, (long)b.get(), (long)(($type$)ic(i)));
- b.rewind();
- }
-
- private static void bulkGet($Type$Buffer b) {
- int n = b.capacity();
- $type$[] a = new $type$[n + 7];
- b.get(a, 7, n);
- for (int i = 0; i < n; i++)
- ck(b, (long)a[i + 7], (long)(($type$)ic(i)));
- }
-
- private static void relPut($Type$Buffer b) {
- int n = b.capacity();
- b.clear();
- for (int i = 0; i < n; i++)
- b.put(($type$)ic(i));
- b.flip();
- }
-
- private static void absPut($Type$Buffer b) {
- int n = b.capacity();
- b.clear();
- for (int i = 0; i < n; i++)
- b.put(i, ($type$)ic(i));
- b.limit(n);
- b.position(0);
- }
-
- private static void bulkPutArray($Type$Buffer b) {
- int n = b.capacity();
- b.clear();
- $type$[] a = new $type$[n + 7];
- for (int i = 0; i < n; i++)
- a[i + 7] = ($type$)ic(i);
- b.put(a, 7, n);
- b.flip();
- }
-
- private static void bulkPutBuffer($Type$Buffer b) {
- int n = b.capacity();
- b.clear();
- $Type$Buffer c = $Type$Buffer.allocate(n + 7);
- c.position(7);
- for (int i = 0; i < n; i++)
- c.put(($type$)ic(i));
- c.flip();
- c.position(7);
- b.put(c);
- b.flip();
- }
-
- //6231529
- private static void callReset($Type$Buffer b) {
- b.position(0);
- b.mark();
-
- b.duplicate().reset();
- b.asReadOnlyBuffer().reset();
- }
-
-#if[byte]
-#else[byte]
- // 6221101-6234263
-
- private static void putBuffer() {
- final int cap = 10;
-
- $Type$Buffer direct1 = ByteBuffer.allocateDirect(cap).as$Type$Buffer();
- $Type$Buffer nondirect1 = ByteBuffer.allocate(cap).as$Type$Buffer();
- direct1.put(nondirect1);
-
- $Type$Buffer direct2 = ByteBuffer.allocateDirect(cap).as$Type$Buffer();
- $Type$Buffer nondirect2 = ByteBuffer.allocate(cap).as$Type$Buffer();
- nondirect2.put(direct2);
-
- $Type$Buffer direct3 = ByteBuffer.allocateDirect(cap).as$Type$Buffer();
- $Type$Buffer direct4 = ByteBuffer.allocateDirect(cap).as$Type$Buffer();
- direct3.put(direct4);
-
- $Type$Buffer nondirect3 = ByteBuffer.allocate(cap).as$Type$Buffer();
- $Type$Buffer nondirect4 = ByteBuffer.allocate(cap).as$Type$Buffer();
- nondirect3.put(nondirect4);
- }
-#end[byte]
-
-#if[char]
-
- private static void bulkPutString($Type$Buffer b) {
- int n = b.capacity();
- b.clear();
- StringBuffer sb = new StringBuffer(n + 7);
- sb.append("1234567");
- for (int i = 0; i < n; i++)
- sb.append((char)ic(i));
- b.put(sb.toString(), 7, 7 + n);
- b.flip();
- }
-
-#end[char]
-
- private static void checkSlice($Type$Buffer b, $Type$Buffer slice) {
- ck(slice, 0, slice.position());
- ck(slice, b.remaining(), slice.limit());
- ck(slice, b.remaining(), slice.capacity());
- if (b.isDirect() != slice.isDirect())
- fail("Lost direction", slice);
- if (b.isReadOnly() != slice.isReadOnly())
- fail("Lost read-only", slice);
- }
-
-#if[byte]
-
- private static void checkBytes(ByteBuffer b, byte[] bs) {
- int n = bs.length;
- int p = b.position();
- byte v;
- if (b.order() == ByteOrder.BIG_ENDIAN) {
- for (int i = 0; i < n; i++)
- ck(b, b.get(), bs[i]);
- } else {
- for (int i = n - 1; i >= 0; i--)
- ck(b, b.get(), bs[i]);
- }
- b.position(p);
- }
-
- private static void compact(Buffer b) {
- try {
- Class<?> cl = b.getClass();
- Method m = cl.getDeclaredMethod("compact");
- m.setAccessible(true);
- m.invoke(b);
- } catch (Exception e) {
- fail(e.getMessage(), b);
- }
- }
-
- private static void checkInvalidMarkException(final Buffer b) {
- tryCatch(b, InvalidMarkException.class, new Runnable() {
- public void run() {
- b.mark();
- compact(b);
- b.reset();
- }});
- }
-
- private static void testViews(int level, ByteBuffer b, boolean direct) {
-
- ShortBuffer sb = b.asShortBuffer();
- BasicShort.test(level, sb, direct);
- checkBytes(b, new byte[] { 0, (byte)ic(0) });
- checkInvalidMarkException(sb);
-
- CharBuffer cb = b.asCharBuffer();
- BasicChar.test(level, cb, direct);
- checkBytes(b, new byte[] { 0, (byte)ic(0) });
- checkInvalidMarkException(cb);
-
- IntBuffer ib = b.asIntBuffer();
- BasicInt.test(level, ib, direct);
- checkBytes(b, new byte[] { 0, 0, 0, (byte)ic(0) });
- checkInvalidMarkException(ib);
-
- LongBuffer lb = b.asLongBuffer();
- BasicLong.test(level, lb, direct);
- checkBytes(b, new byte[] { 0, 0, 0, 0, 0, 0, 0, (byte)ic(0) });
- checkInvalidMarkException(lb);
-
- FloatBuffer fb = b.asFloatBuffer();
- BasicFloat.test(level, fb, direct);
- checkBytes(b, new byte[] { 0x42, (byte)0xc2, 0, 0 });
- checkInvalidMarkException(fb);
-
- DoubleBuffer db = b.asDoubleBuffer();
- BasicDouble.test(level, db, direct);
- checkBytes(b, new byte[] { 0x40, 0x58, 0x40, 0, 0, 0, 0, 0 });
- checkInvalidMarkException(db);
- }
-
- private static void testHet(int level, ByteBuffer b) {
-
- int p = b.position();
- b.limit(b.capacity());
- show(level, b);
- out.print(" put:");
-
- b.putChar((char)1);
- b.putChar((char)Character.MAX_VALUE);
- out.print(" char");
-
- b.putShort((short)1);
- b.putShort((short)Short.MAX_VALUE);
- out.print(" short");
-
- b.putInt(1);
- b.putInt(Integer.MAX_VALUE);
- out.print(" int");
-
- b.putLong((long)1);
- b.putLong((long)Long.MAX_VALUE);
- out.print(" long");
-
- b.putFloat((float)1);
- b.putFloat((float)Float.MIN_VALUE);
- b.putFloat((float)Float.MAX_VALUE);
- out.print(" float");
-
- b.putDouble((double)1);
- b.putDouble((double)Double.MIN_VALUE);
- b.putDouble((double)Double.MAX_VALUE);
- out.print(" double");
-
- out.println();
- b.limit(b.position());
- b.position(p);
- show(level, b);
- out.print(" get:");
-
- ck(b, b.getChar(), 1);
- ck(b, b.getChar(), Character.MAX_VALUE);
- out.print(" char");
-
- ck(b, b.getShort(), 1);
- ck(b, b.getShort(), Short.MAX_VALUE);
- out.print(" short");
-
- ck(b, b.getInt(), 1);
- ck(b, b.getInt(), Integer.MAX_VALUE);
- out.print(" int");
-
- ck(b, b.getLong(), 1);
- ck(b, b.getLong(), Long.MAX_VALUE);
- out.print(" long");
-
- ck(b, (long)b.getFloat(), 1);
- ck(b, (long)b.getFloat(), (long)Float.MIN_VALUE);
- ck(b, (long)b.getFloat(), (long)Float.MAX_VALUE);
- out.print(" float");
-
- ck(b, (long)b.getDouble(), 1);
- ck(b, (long)b.getDouble(), (long)Double.MIN_VALUE);
- ck(b, (long)b.getDouble(), (long)Double.MAX_VALUE);
- out.print(" double");
-
- out.println();
-
- }
-
-#end[byte]
-
- private static void tryCatch(Buffer b, Class ex, Runnable thunk) {
- boolean caught = false;
- try {
- thunk.run();
- } catch (Throwable x) {
- if (ex.isAssignableFrom(x.getClass())) {
- caught = true;
- } else {
- fail(x.getMessage() + " not expected");
- }
- }
- if (!caught)
- fail(ex.getName() + " not thrown", b);
- }
-
- private static void tryCatch($type$ [] t, Class ex, Runnable thunk) {
- tryCatch($Type$Buffer.wrap(t), ex, thunk);
- }
-
- public static void test(int level, final $Type$Buffer b, boolean direct) {
-
- show(level, b);
-
- if (direct != b.isDirect())
- fail("Wrong direction", b);
-
- // Gets and puts
-
- relPut(b);
- relGet(b);
- absGet(b);
- bulkGet(b);
-
- absPut(b);
- relGet(b);
- absGet(b);
- bulkGet(b);
-
- bulkPutArray(b);
- relGet(b);
-
- bulkPutBuffer(b);
- relGet(b);
-
-#if[char]
-
- bulkPutString(b);
- relGet(b);
- b.position(1);
- b.limit(7);
- ck(b, b.toString().equals("bcdefg"));
-
- // CharSequence ops
-
- b.position(2);
- ck(b, b.charAt(1), 'd');
- CharBuffer c = b.subSequence(1, 4);
- ck(c, c.capacity(), b.capacity());
- ck(c, c.position(), b.position()+1);
- ck(c, c.limit(), b.position()+4);
- ck(c, b.subSequence(1, 4).toString().equals("def"));
-
- // 4938424
- b.position(4);
- ck(b, b.charAt(1), 'f');
- ck(b, b.subSequence(1, 3).toString().equals("fg"));
-
-#end[char]
-
- // Compact
-
- relPut(b);
- b.position(13);
- b.compact();
- b.flip();
- relGet(b, 13);
-
- // Exceptions
-
- relPut(b);
- b.limit(b.capacity() / 2);
- b.position(b.limit());
-
- tryCatch(b, BufferUnderflowException.class, new Runnable() {
- public void run() {
- b.get();
- }});
-
- tryCatch(b, BufferOverflowException.class, new Runnable() {
- public void run() {
- b.put(($type$)42);
- }});
-
- // The index must be non-negative and lesss than the buffer's limit.
- tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
- public void run() {
- b.get(b.limit());
- }});
- tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
- public void run() {
- b.get(-1);
- }});
-
- tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
- public void run() {
- b.put(b.limit(), ($type$)42);
- }});
-
- tryCatch(b, InvalidMarkException.class, new Runnable() {
- public void run() {
- b.position(0);
- b.mark();
- b.compact();
- b.reset();
- }});
-
- // Values
-
- b.clear();
- b.put(($type$)0);
- b.put(($type$)-1);
- b.put(($type$)1);
- b.put($Fulltype$.MAX_VALUE);
- b.put($Fulltype$.MIN_VALUE);
-#if[float]
- b.put(-Float.MAX_VALUE);
- b.put(-Float.MIN_VALUE);
- b.put(Float.NEGATIVE_INFINITY);
- b.put(Float.POSITIVE_INFINITY);
- b.put(Float.NaN);
- b.put(0.91697687f); // Changes value if incorrectly swapped
-#end[float]
-#if[double]
- b.put(-Double.MAX_VALUE);
- b.put(-Double.MIN_VALUE);
- b.put(Double.NEGATIVE_INFINITY);
- b.put(Double.POSITIVE_INFINITY);
- b.put(Double.NaN);
- b.put(0.5121609353879392); // Changes value if incorrectly swapped
-#end[double]
-
- $type$ v;
- b.flip();
- ck(b, b.get(), 0);
- ck(b, b.get(), ($type$)-1);
- ck(b, b.get(), 1);
- ck(b, b.get(), $Fulltype$.MAX_VALUE);
- ck(b, b.get(), $Fulltype$.MIN_VALUE);
-
-#if[float]
- ck(b, b.get(), -Float.MAX_VALUE);
- ck(b, b.get(), -Float.MIN_VALUE);
- ck(b, b.get(), Float.NEGATIVE_INFINITY);
- ck(b, b.get(), Float.POSITIVE_INFINITY);
- if (Float.floatToRawIntBits(v = b.get()) != Float.floatToRawIntBits(Float.NaN))
- fail(b, (long)Float.NaN, (long)v);
- ck(b, b.get(), 0.91697687f);
-#end[float]
-#if[double]
- ck(b, b.get(), -Double.MAX_VALUE);
- ck(b, b.get(), -Double.MIN_VALUE);
- ck(b, b.get(), Double.NEGATIVE_INFINITY);
- ck(b, b.get(), Double.POSITIVE_INFINITY);
- if (Double.doubleToRawLongBits(v = b.get())
- != Double.doubleToRawLongBits(Double.NaN))
- fail(b, (long)Double.NaN, (long)v);
- ck(b, b.get(), 0.5121609353879392);
-#end[double]
-
-
- // Comparison
- b.rewind();
- $Type$Buffer b2 = $Type$Buffer.allocate(b.capacity());
- b2.put(b);
- b2.flip();
- b.position(2);
- b2.position(2);
- if (!b.equals(b2)) {
- for (int i = 2; i < b.limit(); i++) {
- $type$ x = b.get(i);
- $type$ y = b2.get(i);
- if (x != y
-#if[double]
- || Double.compare(x, y) != 0
-#end[double]
-#if[float]
- || Float.compare(x, y) != 0
-#end[float]
- )
- out.println("[" + i + "] " + x + " != " + y);
- }
- fail("Identical buffers not equal", b, b2);
- }
- if (b.compareTo(b2) != 0)
- fail("Comparison to identical buffer != 0", b, b2);
-
- b.limit(b.limit() + 1);
- b.position(b.limit() - 1);
- b.put(($type$)99);
- b.rewind();
- b2.rewind();
- if (b.equals(b2))
- fail("Non-identical buffers equal", b, b2);
- if (b.compareTo(b2) <= 0)
- fail("Comparison to shorter buffer <= 0", b, b2);
- b.limit(b.limit() - 1);
-
- b.put(2, ($type$)42);
- if (b.equals(b2))
- fail("Non-identical buffers equal", b, b2);
- if (b.compareTo(b2) <= 0)
- fail("Comparison to lesser buffer <= 0", b, b2);
-
- // Sub, dup
-
- relPut(b);
- relGet(b.duplicate());
- b.position(13);
- relGet(b.duplicate(), 13);
- relGet(b.duplicate().slice(), 13);
- relGet(b.slice(), 13);
- relGet(b.slice().duplicate(), 13);
-
- // Slice
-
- b.position(5);
- $Type$Buffer sb = b.slice();
- checkSlice(b, sb);
- b.position(0);
- $Type$Buffer sb2 = sb.slice();
- checkSlice(sb, sb2);
-
- if (!sb.equals(sb2))
- fail("Sliced slices do not match", sb, sb2);
- if ((sb.hasArray()) && (sb.arrayOffset() != sb2.arrayOffset()))
- fail("Array offsets do not match: "
- + sb.arrayOffset() + " != " + sb2.arrayOffset(), sb, sb2);
-
-#if[byte]
-
- // Views
-
- b.clear();
- b.order(ByteOrder.BIG_ENDIAN);
- testViews(level + 1, b, direct);
-
- for (int i = 1; i <= 9; i++) {
- b.position(i);
- show(level + 1, b);
- testViews(level + 2, b, direct);
- }
-
- b.position(0);
- b.order(ByteOrder.LITTLE_ENDIAN);
- testViews(level + 1, b, direct);
-
- // Heterogeneous accessors
-
- b.order(ByteOrder.BIG_ENDIAN);
- for (int i = 0; i <= 9; i++) {
- b.position(i);
- testHet(level + 1, b);
- }
- b.order(ByteOrder.LITTLE_ENDIAN);
- b.position(3);
- testHet(level + 1, b);
-
-#end[byte]
-
- // Read-only views
-
- b.rewind();
- final $Type$Buffer rb = b.asReadOnlyBuffer();
- if (!b.equals(rb))
- fail("Buffer not equal to read-only view", b, rb);
- show(level + 1, rb);
-
- tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
- public void run() {
- relPut(rb);
- }});
-
- tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
- public void run() {
- absPut(rb);
- }});
-
- tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
- public void run() {
- bulkPutArray(rb);
- }});
-
- tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
- public void run() {
- bulkPutBuffer(rb);
- }});
-
- tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
- public void run() {
- rb.compact();
- }});
-
-#if[byte]
-
- tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
- public void run() {
- rb.putChar((char)1);
- }});
- tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
- public void run() {
- rb.putChar(0, (char)1);
- }});
-
- tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
- public void run() {
- rb.putShort((short)1);
- }});
- tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
- public void run() {
- rb.putShort(0, (short)1);
- }});
-
- tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
- public void run() {
- rb.putInt(1);
- }});
- tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
- public void run() {
- rb.putInt(0, 1);
- }});
-
- tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
- public void run() {
- rb.putLong((long)1);
- }});
- tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
- public void run() {
- rb.putLong(0, (long)1);
- }});
-
- tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
- public void run() {
- rb.putFloat((float)1);
- }});
- tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
- public void run() {
- rb.putFloat(0, (float)1);
- }});
-
- tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
- public void run() {
- rb.putDouble((double)1);
- }});
- tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
- public void run() {
- rb.putDouble(0, (double)1);
- }});
-
-#end[byte]
-
- if (rb.getClass().getName().startsWith("java.nio.Heap")) {
-
- tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
- public void run() {
- rb.array();
- }});
-
- tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
- public void run() {
- rb.arrayOffset();
- }});
-
- if (rb.hasArray())
- fail("Read-only heap buffer's backing array is accessible",
- rb);
-
- }
-
- // Bulk puts from read-only buffers
-
- b.clear();
- rb.rewind();
- b.put(rb);
-
-#if[byte]
- // For byte buffers, test both the direct and non-direct cases
- $Type$Buffer ob
- = (b.isDirect()
- ? $Type$Buffer.allocate(rb.capacity())
- : $Type$Buffer.allocateDirect(rb.capacity()));
- rb.rewind();
- ob.put(rb);
-#end[byte]
-
- relPut(b); // Required by testViews
-
- }
-
-#if[char]
-
- private static void testStr() {
- final String s = "abcdefghijklm";
- int start = 3;
- int end = 9;
- final CharBuffer b = CharBuffer.wrap(s, start, end);
- show(0, b);
- ck(b, b.toString().equals(s.substring(start, end)));
- ck(b, b.toString().equals("defghi"));
- ck(b, b.isReadOnly());
- tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
- public void run() {
- b.put('x');
- }});
- ck(b, start, b.position());
- ck(b, end, b.limit());
- ck(b, s.length(), b.capacity());
- b.position(6);
- ck(b, b.subSequence(0,3).toString().equals("ghi"));
-
- // The index, relative to the position, must be non-negative and
- // smaller than remaining().
- tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
- public void run() {
- b.charAt(-1);
- }});
- tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
- public void run() {
- b.charAt(b.remaining());
- }});
-
- // The index must be non-negative and less than the buffer's limit.
- tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
- public void run() {
- b.get(b.limit());
- }});
- tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
- public void run() {
- b.get(-1);
- }});
-
- // The start must be non-negative and no larger than remaining().
- tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
- public void run() {
- b.subSequence(-1, b.remaining());
- }});
- tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
- public void run() {
- b.subSequence(b.remaining() + 1, b.remaining());
- }});
-
- // The end must be no smaller than start and no larger than
- // remaining().
- tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
- public void run() {
- b.subSequence(2, 1);
- }});
- tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
- public void run() {
- b.subSequence(0, b.remaining() + 1);
- }});
-
- // The offset must be non-negative and no larger than <array.length>.
- tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
- public void run() {
- $Type$Buffer.wrap(s, -1, s.length());
- }});
- tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
- public void run() {
- $Type$Buffer.wrap(s, s.length() + 1, s.length());
- }});
- tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
- public void run() {
- $Type$Buffer.wrap(s, 1, 0);
- }});
- tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
- public void run() {
- $Type$Buffer.wrap(s, 0, s.length() + 1);
- }});
- }
-
-#end[char]
-
- public static void test(final $type$ [] ba) {
- int offset = 47;
- int length = 900;
- final $Type$Buffer b = $Type$Buffer.wrap(ba, offset, length);
- show(0, b);
- ck(b, b.capacity(), ba.length);
- ck(b, b.position(), offset);
- ck(b, b.limit(), offset + length);
-
- // The offset must be non-negative and no larger than <array.length>.
- tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
- public void run() {
- $Type$Buffer.wrap(ba, -1, ba.length);
- }});
- tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
- public void run() {
- $Type$Buffer.wrap(ba, ba.length + 1, ba.length);
- }});
- tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
- public void run() {
- $Type$Buffer.wrap(ba, 0, -1);
- }});
- tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
- public void run() {
- $Type$Buffer.wrap(ba, 0, ba.length + 1);
- }});
-
- // A NullPointerException will be thrown if the array is null.
- tryCatch(ba, NullPointerException.class, new Runnable() {
- public void run() {
- $Type$Buffer.wrap(($type$ []) null, 0, 5);
- }});
- tryCatch(ba, NullPointerException.class, new Runnable() {
- public void run() {
- $Type$Buffer.wrap(($type$ []) null);
- }});
- }
-
- private static void testAllocate() {
- // An IllegalArgumentException will be thrown for negative capacities.
- tryCatch((Buffer) null, IllegalArgumentException.class, new Runnable() {
- public void run() {
- $Type$Buffer.allocate(-1);
- }});
-#if[byte]
- tryCatch((Buffer) null, IllegalArgumentException.class, new Runnable() {
- public void run() {
- $Type$Buffer.allocateDirect(-1);
- }});
-#end[byte]
- }
-
- public static void test() {
- testAllocate();
- test(0, $Type$Buffer.allocate(7 * 1024), false);
- test(0, $Type$Buffer.wrap(new $type$[7 * 1024], 0, 7 * 1024), false);
- test(new $type$[1024]);
-#if[byte]
- $Type$Buffer b = $Type$Buffer.allocateDirect(7 * 1024);
- for (b.position(0); b.position() < b.limit(); )
- ck(b, b.get(), 0);
- test(0, b, true);
-#end[byte]
-#if[char]
- testStr();
-#end[char]
-
- callReset($Type$Buffer.allocate(10));
-
-#if[byte]
-#else[byte]
- putBuffer();
-#end[byte]
- }
-
-}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/nio/Buffer/Basic-X.java.template Wed Oct 28 16:54:50 2009 -0700
@@ -0,0 +1,869 @@
+/*
+ * Copyright 2000-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.
+ */
+
+/* Type-specific source code for unit test
+ *
+ * Regenerate the BasicX classes via genBasic.sh whenever this file changes.
+ * We check in the generated source files so that the test tree can be used
+ * independently of the rest of the source tree.
+ */
+
+#warn This file is preprocessed before being compiled
+
+import java.nio.*;
+import java.lang.reflect.Method;
+
+
+public class Basic$Type$
+ extends Basic
+{
+
+ private static void relGet($Type$Buffer b) {
+ int n = b.capacity();
+ $type$ v;
+ for (int i = 0; i < n; i++)
+ ck(b, (long)b.get(), (long)(($type$)ic(i)));
+ b.rewind();
+ }
+
+ private static void relGet($Type$Buffer b, int start) {
+ int n = b.remaining();
+ $type$ v;
+ for (int i = start; i < n; i++)
+ ck(b, (long)b.get(), (long)(($type$)ic(i)));
+ b.rewind();
+ }
+
+ private static void absGet($Type$Buffer b) {
+ int n = b.capacity();
+ $type$ v;
+ for (int i = 0; i < n; i++)
+ ck(b, (long)b.get(), (long)(($type$)ic(i)));
+ b.rewind();
+ }
+
+ private static void bulkGet($Type$Buffer b) {
+ int n = b.capacity();
+ $type$[] a = new $type$[n + 7];
+ b.get(a, 7, n);
+ for (int i = 0; i < n; i++)
+ ck(b, (long)a[i + 7], (long)(($type$)ic(i)));
+ }
+
+ private static void relPut($Type$Buffer b) {
+ int n = b.capacity();
+ b.clear();
+ for (int i = 0; i < n; i++)
+ b.put(($type$)ic(i));
+ b.flip();
+ }
+
+ private static void absPut($Type$Buffer b) {
+ int n = b.capacity();
+ b.clear();
+ for (int i = 0; i < n; i++)
+ b.put(i, ($type$)ic(i));
+ b.limit(n);
+ b.position(0);
+ }
+
+ private static void bulkPutArray($Type$Buffer b) {
+ int n = b.capacity();
+ b.clear();
+ $type$[] a = new $type$[n + 7];
+ for (int i = 0; i < n; i++)
+ a[i + 7] = ($type$)ic(i);
+ b.put(a, 7, n);
+ b.flip();
+ }
+
+ private static void bulkPutBuffer($Type$Buffer b) {
+ int n = b.capacity();
+ b.clear();
+ $Type$Buffer c = $Type$Buffer.allocate(n + 7);
+ c.position(7);
+ for (int i = 0; i < n; i++)
+ c.put(($type$)ic(i));
+ c.flip();
+ c.position(7);
+ b.put(c);
+ b.flip();
+ }
+
+ //6231529
+ private static void callReset($Type$Buffer b) {
+ b.position(0);
+ b.mark();
+
+ b.duplicate().reset();
+ b.asReadOnlyBuffer().reset();
+ }
+
+#if[byte]
+#else[byte]
+ // 6221101-6234263
+
+ private static void putBuffer() {
+ final int cap = 10;
+
+ $Type$Buffer direct1 = ByteBuffer.allocateDirect(cap).as$Type$Buffer();
+ $Type$Buffer nondirect1 = ByteBuffer.allocate(cap).as$Type$Buffer();
+ direct1.put(nondirect1);
+
+ $Type$Buffer direct2 = ByteBuffer.allocateDirect(cap).as$Type$Buffer();
+ $Type$Buffer nondirect2 = ByteBuffer.allocate(cap).as$Type$Buffer();
+ nondirect2.put(direct2);
+
+ $Type$Buffer direct3 = ByteBuffer.allocateDirect(cap).as$Type$Buffer();
+ $Type$Buffer direct4 = ByteBuffer.allocateDirect(cap).as$Type$Buffer();
+ direct3.put(direct4);
+
+ $Type$Buffer nondirect3 = ByteBuffer.allocate(cap).as$Type$Buffer();
+ $Type$Buffer nondirect4 = ByteBuffer.allocate(cap).as$Type$Buffer();
+ nondirect3.put(nondirect4);
+ }
+#end[byte]
+
+#if[char]
+
+ private static void bulkPutString($Type$Buffer b) {
+ int n = b.capacity();
+ b.clear();
+ StringBuffer sb = new StringBuffer(n + 7);
+ sb.append("1234567");
+ for (int i = 0; i < n; i++)
+ sb.append((char)ic(i));
+ b.put(sb.toString(), 7, 7 + n);
+ b.flip();
+ }
+
+#end[char]
+
+ private static void checkSlice($Type$Buffer b, $Type$Buffer slice) {
+ ck(slice, 0, slice.position());
+ ck(slice, b.remaining(), slice.limit());
+ ck(slice, b.remaining(), slice.capacity());
+ if (b.isDirect() != slice.isDirect())
+ fail("Lost direction", slice);
+ if (b.isReadOnly() != slice.isReadOnly())
+ fail("Lost read-only", slice);
+ }
+
+#if[byte]
+
+ private static void checkBytes(ByteBuffer b, byte[] bs) {
+ int n = bs.length;
+ int p = b.position();
+ byte v;
+ if (b.order() == ByteOrder.BIG_ENDIAN) {
+ for (int i = 0; i < n; i++)
+ ck(b, b.get(), bs[i]);
+ } else {
+ for (int i = n - 1; i >= 0; i--)
+ ck(b, b.get(), bs[i]);
+ }
+ b.position(p);
+ }
+
+ private static void compact(Buffer b) {
+ try {
+ Class<?> cl = b.getClass();
+ Method m = cl.getDeclaredMethod("compact");
+ m.setAccessible(true);
+ m.invoke(b);
+ } catch (Exception e) {
+ fail(e.getMessage(), b);
+ }
+ }
+
+ private static void checkInvalidMarkException(final Buffer b) {
+ tryCatch(b, InvalidMarkException.class, new Runnable() {
+ public void run() {
+ b.mark();
+ compact(b);
+ b.reset();
+ }});
+ }
+
+ private static void testViews(int level, ByteBuffer b, boolean direct) {
+
+ ShortBuffer sb = b.asShortBuffer();
+ BasicShort.test(level, sb, direct);
+ checkBytes(b, new byte[] { 0, (byte)ic(0) });
+ checkInvalidMarkException(sb);
+
+ CharBuffer cb = b.asCharBuffer();
+ BasicChar.test(level, cb, direct);
+ checkBytes(b, new byte[] { 0, (byte)ic(0) });
+ checkInvalidMarkException(cb);
+
+ IntBuffer ib = b.asIntBuffer();
+ BasicInt.test(level, ib, direct);
+ checkBytes(b, new byte[] { 0, 0, 0, (byte)ic(0) });
+ checkInvalidMarkException(ib);
+
+ LongBuffer lb = b.asLongBuffer();
+ BasicLong.test(level, lb, direct);
+ checkBytes(b, new byte[] { 0, 0, 0, 0, 0, 0, 0, (byte)ic(0) });
+ checkInvalidMarkException(lb);
+
+ FloatBuffer fb = b.asFloatBuffer();
+ BasicFloat.test(level, fb, direct);
+ checkBytes(b, new byte[] { 0x42, (byte)0xc2, 0, 0 });
+ checkInvalidMarkException(fb);
+
+ DoubleBuffer db = b.asDoubleBuffer();
+ BasicDouble.test(level, db, direct);
+ checkBytes(b, new byte[] { 0x40, 0x58, 0x40, 0, 0, 0, 0, 0 });
+ checkInvalidMarkException(db);
+ }
+
+ private static void testHet(int level, ByteBuffer b) {
+
+ int p = b.position();
+ b.limit(b.capacity());
+ show(level, b);
+ out.print(" put:");
+
+ b.putChar((char)1);
+ b.putChar((char)Character.MAX_VALUE);
+ out.print(" char");
+
+ b.putShort((short)1);
+ b.putShort((short)Short.MAX_VALUE);
+ out.print(" short");
+
+ b.putInt(1);
+ b.putInt(Integer.MAX_VALUE);
+ out.print(" int");
+
+ b.putLong((long)1);
+ b.putLong((long)Long.MAX_VALUE);
+ out.print(" long");
+
+ b.putFloat((float)1);
+ b.putFloat((float)Float.MIN_VALUE);
+ b.putFloat((float)Float.MAX_VALUE);
+ out.print(" float");
+
+ b.putDouble((double)1);
+ b.putDouble((double)Double.MIN_VALUE);
+ b.putDouble((double)Double.MAX_VALUE);
+ out.print(" double");
+
+ out.println();
+ b.limit(b.position());
+ b.position(p);
+ show(level, b);
+ out.print(" get:");
+
+ ck(b, b.getChar(), 1);
+ ck(b, b.getChar(), Character.MAX_VALUE);
+ out.print(" char");
+
+ ck(b, b.getShort(), 1);
+ ck(b, b.getShort(), Short.MAX_VALUE);
+ out.print(" short");
+
+ ck(b, b.getInt(), 1);
+ ck(b, b.getInt(), Integer.MAX_VALUE);
+ out.print(" int");
+
+ ck(b, b.getLong(), 1);
+ ck(b, b.getLong(), Long.MAX_VALUE);
+ out.print(" long");
+
+ ck(b, (long)b.getFloat(), 1);
+ ck(b, (long)b.getFloat(), (long)Float.MIN_VALUE);
+ ck(b, (long)b.getFloat(), (long)Float.MAX_VALUE);
+ out.print(" float");
+
+ ck(b, (long)b.getDouble(), 1);
+ ck(b, (long)b.getDouble(), (long)Double.MIN_VALUE);
+ ck(b, (long)b.getDouble(), (long)Double.MAX_VALUE);
+ out.print(" double");
+
+ out.println();
+
+ }
+
+#end[byte]
+
+ private static void tryCatch(Buffer b, Class ex, Runnable thunk) {
+ boolean caught = false;
+ try {
+ thunk.run();
+ } catch (Throwable x) {
+ if (ex.isAssignableFrom(x.getClass())) {
+ caught = true;
+ } else {
+ fail(x.getMessage() + " not expected");
+ }
+ }
+ if (!caught)
+ fail(ex.getName() + " not thrown", b);
+ }
+
+ private static void tryCatch($type$ [] t, Class ex, Runnable thunk) {
+ tryCatch($Type$Buffer.wrap(t), ex, thunk);
+ }
+
+ public static void test(int level, final $Type$Buffer b, boolean direct) {
+
+ show(level, b);
+
+ if (direct != b.isDirect())
+ fail("Wrong direction", b);
+
+ // Gets and puts
+
+ relPut(b);
+ relGet(b);
+ absGet(b);
+ bulkGet(b);
+
+ absPut(b);
+ relGet(b);
+ absGet(b);
+ bulkGet(b);
+
+ bulkPutArray(b);
+ relGet(b);
+
+ bulkPutBuffer(b);
+ relGet(b);
+
+#if[char]
+
+ bulkPutString(b);
+ relGet(b);
+ b.position(1);
+ b.limit(7);
+ ck(b, b.toString().equals("bcdefg"));
+
+ // CharSequence ops
+
+ b.position(2);
+ ck(b, b.charAt(1), 'd');
+ CharBuffer c = b.subSequence(1, 4);
+ ck(c, c.capacity(), b.capacity());
+ ck(c, c.position(), b.position()+1);
+ ck(c, c.limit(), b.position()+4);
+ ck(c, b.subSequence(1, 4).toString().equals("def"));
+
+ // 4938424
+ b.position(4);
+ ck(b, b.charAt(1), 'f');
+ ck(b, b.subSequence(1, 3).toString().equals("fg"));
+
+#end[char]
+
+ // Compact
+
+ relPut(b);
+ b.position(13);
+ b.compact();
+ b.flip();
+ relGet(b, 13);
+
+ // Exceptions
+
+ relPut(b);
+ b.limit(b.capacity() / 2);
+ b.position(b.limit());
+
+ tryCatch(b, BufferUnderflowException.class, new Runnable() {
+ public void run() {
+ b.get();
+ }});
+
+ tryCatch(b, BufferOverflowException.class, new Runnable() {
+ public void run() {
+ b.put(($type$)42);
+ }});
+
+ // The index must be non-negative and lesss than the buffer's limit.
+ tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ b.get(b.limit());
+ }});
+ tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ b.get(-1);
+ }});
+
+ tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ b.put(b.limit(), ($type$)42);
+ }});
+
+ tryCatch(b, InvalidMarkException.class, new Runnable() {
+ public void run() {
+ b.position(0);
+ b.mark();
+ b.compact();
+ b.reset();
+ }});
+
+ // Values
+
+ b.clear();
+ b.put(($type$)0);
+ b.put(($type$)-1);
+ b.put(($type$)1);
+ b.put($Fulltype$.MAX_VALUE);
+ b.put($Fulltype$.MIN_VALUE);
+#if[float]
+ b.put(-Float.MAX_VALUE);
+ b.put(-Float.MIN_VALUE);
+ b.put(Float.NEGATIVE_INFINITY);
+ b.put(Float.POSITIVE_INFINITY);
+ b.put(Float.NaN);
+ b.put(0.91697687f); // Changes value if incorrectly swapped
+#end[float]
+#if[double]
+ b.put(-Double.MAX_VALUE);
+ b.put(-Double.MIN_VALUE);
+ b.put(Double.NEGATIVE_INFINITY);
+ b.put(Double.POSITIVE_INFINITY);
+ b.put(Double.NaN);
+ b.put(0.5121609353879392); // Changes value if incorrectly swapped
+#end[double]
+
+ $type$ v;
+ b.flip();
+ ck(b, b.get(), 0);
+ ck(b, b.get(), ($type$)-1);
+ ck(b, b.get(), 1);
+ ck(b, b.get(), $Fulltype$.MAX_VALUE);
+ ck(b, b.get(), $Fulltype$.MIN_VALUE);
+
+#if[float]
+ ck(b, b.get(), -Float.MAX_VALUE);
+ ck(b, b.get(), -Float.MIN_VALUE);
+ ck(b, b.get(), Float.NEGATIVE_INFINITY);
+ ck(b, b.get(), Float.POSITIVE_INFINITY);
+ if (Float.floatToRawIntBits(v = b.get()) != Float.floatToRawIntBits(Float.NaN))
+ fail(b, (long)Float.NaN, (long)v);
+ ck(b, b.get(), 0.91697687f);
+#end[float]
+#if[double]
+ ck(b, b.get(), -Double.MAX_VALUE);
+ ck(b, b.get(), -Double.MIN_VALUE);
+ ck(b, b.get(), Double.NEGATIVE_INFINITY);
+ ck(b, b.get(), Double.POSITIVE_INFINITY);
+ if (Double.doubleToRawLongBits(v = b.get())
+ != Double.doubleToRawLongBits(Double.NaN))
+ fail(b, (long)Double.NaN, (long)v);
+ ck(b, b.get(), 0.5121609353879392);
+#end[double]
+
+
+ // Comparison
+ b.rewind();
+ $Type$Buffer b2 = $Type$Buffer.allocate(b.capacity());
+ b2.put(b);
+ b2.flip();
+ b.position(2);
+ b2.position(2);
+ if (!b.equals(b2)) {
+ for (int i = 2; i < b.limit(); i++) {
+ $type$ x = b.get(i);
+ $type$ y = b2.get(i);
+ if (x != y
+#if[double]
+ || Double.compare(x, y) != 0
+#end[double]
+#if[float]
+ || Float.compare(x, y) != 0
+#end[float]
+ )
+ out.println("[" + i + "] " + x + " != " + y);
+ }
+ fail("Identical buffers not equal", b, b2);
+ }
+ if (b.compareTo(b2) != 0)
+ fail("Comparison to identical buffer != 0", b, b2);
+
+ b.limit(b.limit() + 1);
+ b.position(b.limit() - 1);
+ b.put(($type$)99);
+ b.rewind();
+ b2.rewind();
+ if (b.equals(b2))
+ fail("Non-identical buffers equal", b, b2);
+ if (b.compareTo(b2) <= 0)
+ fail("Comparison to shorter buffer <= 0", b, b2);
+ b.limit(b.limit() - 1);
+
+ b.put(2, ($type$)42);
+ if (b.equals(b2))
+ fail("Non-identical buffers equal", b, b2);
+ if (b.compareTo(b2) <= 0)
+ fail("Comparison to lesser buffer <= 0", b, b2);
+
+ // Sub, dup
+
+ relPut(b);
+ relGet(b.duplicate());
+ b.position(13);
+ relGet(b.duplicate(), 13);
+ relGet(b.duplicate().slice(), 13);
+ relGet(b.slice(), 13);
+ relGet(b.slice().duplicate(), 13);
+
+ // Slice
+
+ b.position(5);
+ $Type$Buffer sb = b.slice();
+ checkSlice(b, sb);
+ b.position(0);
+ $Type$Buffer sb2 = sb.slice();
+ checkSlice(sb, sb2);
+
+ if (!sb.equals(sb2))
+ fail("Sliced slices do not match", sb, sb2);
+ if ((sb.hasArray()) && (sb.arrayOffset() != sb2.arrayOffset()))
+ fail("Array offsets do not match: "
+ + sb.arrayOffset() + " != " + sb2.arrayOffset(), sb, sb2);
+
+#if[byte]
+
+ // Views
+
+ b.clear();
+ b.order(ByteOrder.BIG_ENDIAN);
+ testViews(level + 1, b, direct);
+
+ for (int i = 1; i <= 9; i++) {
+ b.position(i);
+ show(level + 1, b);
+ testViews(level + 2, b, direct);
+ }
+
+ b.position(0);
+ b.order(ByteOrder.LITTLE_ENDIAN);
+ testViews(level + 1, b, direct);
+
+ // Heterogeneous accessors
+
+ b.order(ByteOrder.BIG_ENDIAN);
+ for (int i = 0; i <= 9; i++) {
+ b.position(i);
+ testHet(level + 1, b);
+ }
+ b.order(ByteOrder.LITTLE_ENDIAN);
+ b.position(3);
+ testHet(level + 1, b);
+
+#end[byte]
+
+ // Read-only views
+
+ b.rewind();
+ final $Type$Buffer rb = b.asReadOnlyBuffer();
+ if (!b.equals(rb))
+ fail("Buffer not equal to read-only view", b, rb);
+ show(level + 1, rb);
+
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ relPut(rb);
+ }});
+
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ absPut(rb);
+ }});
+
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ bulkPutArray(rb);
+ }});
+
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ bulkPutBuffer(rb);
+ }});
+
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ rb.compact();
+ }});
+
+#if[byte]
+
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ rb.putChar((char)1);
+ }});
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ rb.putChar(0, (char)1);
+ }});
+
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ rb.putShort((short)1);
+ }});
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ rb.putShort(0, (short)1);
+ }});
+
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ rb.putInt(1);
+ }});
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ rb.putInt(0, 1);
+ }});
+
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ rb.putLong((long)1);
+ }});
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ rb.putLong(0, (long)1);
+ }});
+
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ rb.putFloat((float)1);
+ }});
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ rb.putFloat(0, (float)1);
+ }});
+
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ rb.putDouble((double)1);
+ }});
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ rb.putDouble(0, (double)1);
+ }});
+
+#end[byte]
+
+ if (rb.getClass().getName().startsWith("java.nio.Heap")) {
+
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ rb.array();
+ }});
+
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ rb.arrayOffset();
+ }});
+
+ if (rb.hasArray())
+ fail("Read-only heap buffer's backing array is accessible",
+ rb);
+
+ }
+
+ // Bulk puts from read-only buffers
+
+ b.clear();
+ rb.rewind();
+ b.put(rb);
+
+#if[byte]
+ // For byte buffers, test both the direct and non-direct cases
+ $Type$Buffer ob
+ = (b.isDirect()
+ ? $Type$Buffer.allocate(rb.capacity())
+ : $Type$Buffer.allocateDirect(rb.capacity()));
+ rb.rewind();
+ ob.put(rb);
+#end[byte]
+
+ relPut(b); // Required by testViews
+
+ }
+
+#if[char]
+
+ private static void testStr() {
+ final String s = "abcdefghijklm";
+ int start = 3;
+ int end = 9;
+ final CharBuffer b = CharBuffer.wrap(s, start, end);
+ show(0, b);
+ ck(b, b.toString().equals(s.substring(start, end)));
+ ck(b, b.toString().equals("defghi"));
+ ck(b, b.isReadOnly());
+ tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
+ public void run() {
+ b.put('x');
+ }});
+ ck(b, start, b.position());
+ ck(b, end, b.limit());
+ ck(b, s.length(), b.capacity());
+ b.position(6);
+ ck(b, b.subSequence(0,3).toString().equals("ghi"));
+
+ // The index, relative to the position, must be non-negative and
+ // smaller than remaining().
+ tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ b.charAt(-1);
+ }});
+ tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ b.charAt(b.remaining());
+ }});
+
+ // The index must be non-negative and less than the buffer's limit.
+ tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ b.get(b.limit());
+ }});
+ tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ b.get(-1);
+ }});
+
+ // The start must be non-negative and no larger than remaining().
+ tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ b.subSequence(-1, b.remaining());
+ }});
+ tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ b.subSequence(b.remaining() + 1, b.remaining());
+ }});
+
+ // The end must be no smaller than start and no larger than
+ // remaining().
+ tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ b.subSequence(2, 1);
+ }});
+ tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ b.subSequence(0, b.remaining() + 1);
+ }});
+
+ // The offset must be non-negative and no larger than <array.length>.
+ tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ $Type$Buffer.wrap(s, -1, s.length());
+ }});
+ tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ $Type$Buffer.wrap(s, s.length() + 1, s.length());
+ }});
+ tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ $Type$Buffer.wrap(s, 1, 0);
+ }});
+ tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ $Type$Buffer.wrap(s, 0, s.length() + 1);
+ }});
+ }
+
+#end[char]
+
+ public static void test(final $type$ [] ba) {
+ int offset = 47;
+ int length = 900;
+ final $Type$Buffer b = $Type$Buffer.wrap(ba, offset, length);
+ show(0, b);
+ ck(b, b.capacity(), ba.length);
+ ck(b, b.position(), offset);
+ ck(b, b.limit(), offset + length);
+
+ // The offset must be non-negative and no larger than <array.length>.
+ tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ $Type$Buffer.wrap(ba, -1, ba.length);
+ }});
+ tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ $Type$Buffer.wrap(ba, ba.length + 1, ba.length);
+ }});
+ tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ $Type$Buffer.wrap(ba, 0, -1);
+ }});
+ tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
+ public void run() {
+ $Type$Buffer.wrap(ba, 0, ba.length + 1);
+ }});
+
+ // A NullPointerException will be thrown if the array is null.
+ tryCatch(ba, NullPointerException.class, new Runnable() {
+ public void run() {
+ $Type$Buffer.wrap(($type$ []) null, 0, 5);
+ }});
+ tryCatch(ba, NullPointerException.class, new Runnable() {
+ public void run() {
+ $Type$Buffer.wrap(($type$ []) null);
+ }});
+ }
+
+ private static void testAllocate() {
+ // An IllegalArgumentException will be thrown for negative capacities.
+ tryCatch((Buffer) null, IllegalArgumentException.class, new Runnable() {
+ public void run() {
+ $Type$Buffer.allocate(-1);
+ }});
+#if[byte]
+ tryCatch((Buffer) null, IllegalArgumentException.class, new Runnable() {
+ public void run() {
+ $Type$Buffer.allocateDirect(-1);
+ }});
+#end[byte]
+ }
+
+ public static void test() {
+ testAllocate();
+ test(0, $Type$Buffer.allocate(7 * 1024), false);
+ test(0, $Type$Buffer.wrap(new $type$[7 * 1024], 0, 7 * 1024), false);
+ test(new $type$[1024]);
+#if[byte]
+ $Type$Buffer b = $Type$Buffer.allocateDirect(7 * 1024);
+ for (b.position(0); b.position() < b.limit(); )
+ ck(b, b.get(), 0);
+ test(0, b, true);
+#end[byte]
+#if[char]
+ testStr();
+#end[char]
+
+ callReset($Type$Buffer.allocate(10));
+
+#if[byte]
+#else[byte]
+ putBuffer();
+#end[byte]
+ }
+
+}
--- a/jdk/test/java/nio/Buffer/CopyDirect-X-Memory.java Wed Oct 28 16:26:52 2009 -0700
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,70 +0,0 @@
-/*
- * Copyright 2002-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.
- */
-
-#warn This file is preprocessed before being compiled
-
-import java.nio.*;
-
-public class CopyDirect$Type$Memory
- extends CopyDirectMemory
-{
- private static void init($Type$Buffer b) {
- int n = b.capacity();
- b.clear();
- for (int i = 0; i < n; i++)
- b.put(i, ($type$)ic(i));
- b.limit(n);
- b.position(0);
- }
-
- private static void init($type$ [] a) {
- for (int i = 0; i < a.length; i++)
- a[i] = ($type$)ic(i + 1);
- }
-
- public static void test() {
-#if[byte]
- ByteBuffer b = ByteBuffer.allocateDirect(1024 * 1024 + 1024);
-#else[byte]
- ByteBuffer bb = ByteBuffer.allocateDirect(1024 * 1024 + 1024);
- $Type$Buffer b = bb.as$Type$Buffer();
-#end[byte]
- init(b);
- $type$ [] a = new $type$[b.capacity()];
- init(a);
-
- // copyFrom$Type$Array (a -> b)
- b.put(a);
- for (int i = 0; i < a.length; i++)
- ck(b, b.get(i), ($type$)ic(i + 1));
-
- // copyTo$Type$Array (b -> a)
- init(b);
- init(a);
- b.get(a);
- for (int i = 0; i < a.length; i++)
- if (a[i] != b.get(i))
- fail("Copy failed at " + i + ": '"
- + a[i] + "' != '" + b.get(i) + "'");
- }
-}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/nio/Buffer/CopyDirect-X-Memory.java.template Wed Oct 28 16:54:50 2009 -0700
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2002-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.
+ */
+
+#warn This file is preprocessed before being compiled
+
+import java.nio.*;
+
+public class CopyDirect$Type$Memory
+ extends CopyDirectMemory
+{
+ private static void init($Type$Buffer b) {
+ int n = b.capacity();
+ b.clear();
+ for (int i = 0; i < n; i++)
+ b.put(i, ($type$)ic(i));
+ b.limit(n);
+ b.position(0);
+ }
+
+ private static void init($type$ [] a) {
+ for (int i = 0; i < a.length; i++)
+ a[i] = ($type$)ic(i + 1);
+ }
+
+ public static void test() {
+#if[byte]
+ ByteBuffer b = ByteBuffer.allocateDirect(1024 * 1024 + 1024);
+#else[byte]
+ ByteBuffer bb = ByteBuffer.allocateDirect(1024 * 1024 + 1024);
+ $Type$Buffer b = bb.as$Type$Buffer();
+#end[byte]
+ init(b);
+ $type$ [] a = new $type$[b.capacity()];
+ init(a);
+
+ // copyFrom$Type$Array (a -> b)
+ b.put(a);
+ for (int i = 0; i < a.length; i++)
+ ck(b, b.get(i), ($type$)ic(i + 1));
+
+ // copyTo$Type$Array (b -> a)
+ init(b);
+ init(a);
+ b.get(a);
+ for (int i = 0; i < a.length; i++)
+ if (a[i] != b.get(i))
+ fail("Copy failed at " + i + ": '"
+ + a[i] + "' != '" + b.get(i) + "'");
+ }
+}
--- a/jdk/test/java/nio/Buffer/genBasic.sh Wed Oct 28 16:26:52 2009 -0700
+++ b/jdk/test/java/nio/Buffer/genBasic.sh Wed Oct 28 16:54:50 2009 -0700
@@ -26,7 +26,7 @@
javac -d . ../../../../make/tools/src/build/tools/spp/Spp.java
gen() {
- java build.tools.spp.Spp -K$1 -Dtype=$1 -DType=$2 -DFulltype=$3 <Basic-X.java >Basic$2.java
+ java build.tools.spp.Spp -K$1 -Dtype=$1 -DType=$2 -DFulltype=$3 <Basic-X.java.template >Basic$2.java
}
gen byte Byte Byte
--- a/jdk/test/java/nio/Buffer/genCopyDirectMemory.sh Wed Oct 28 16:26:52 2009 -0700
+++ b/jdk/test/java/nio/Buffer/genCopyDirectMemory.sh Wed Oct 28 16:54:50 2009 -0700
@@ -26,7 +26,7 @@
javac -d . ../../../../make/tools/src/build/tools/spp/Spp.java > Spp.java
gen() {
- java build.tools.spp.Spp -K$1 -Dtype=$1 -DType=$2 -DFulltype=$3<CopyDirect-X-Memory.java >CopyDirect$2Memory.java
+ java build.tools.spp.Spp -K$1 -Dtype=$1 -DType=$2 -DFulltype=$3<CopyDirect-X-Memory.java.template >CopyDirect$2Memory.java
}
gen byte Byte Byte