Merge
authorwetmore
Mon, 17 Mar 2008 12:27:58 -0700
changeset 103 2ccefd4e038f
parent 102 d8184c1c3120 (current diff)
parent 70 01cbfebae878 (diff)
child 104 94a4cf011510
child 263 db2a63668df3
child 264 2d63554b2562
child 288 ea538d348fe8
child 289 b1c8ad73578f
Merge
--- a/jdk/src/share/classes/java/nio/StringCharBuffer.java	Mon Mar 17 11:53:36 2008 -0700
+++ b/jdk/src/share/classes/java/nio/StringCharBuffer.java	Mon Mar 17 12:27:58 2008 -0700
@@ -60,16 +60,9 @@
         str = s;
     }
 
-    private StringCharBuffer(CharSequence s, int mark,
-                             int pos, int limit, int cap)
-    {
-        super(mark, pos, limit, cap);
-        str = s;
-    }
-
     public CharBuffer duplicate() {
         return new StringCharBuffer(str, markValue(),
-                                    position(), limit(), capacity());
+                                    position(), limit(), capacity(), offset);
     }
 
     public CharBuffer asReadOnlyBuffer() {
@@ -77,11 +70,11 @@
     }
 
     public final char get() {
-        return str.charAt(nextGetIndex());
+        return str.charAt(nextGetIndex() + offset);
     }
 
     public final char get(int index) {
-        return str.charAt(checkIndex(index));
+        return str.charAt(checkIndex(index) + offset);
     }
 
     // ## Override bulk get methods for better performance
@@ -103,15 +96,16 @@
     }
 
     final String toString(int start, int end) {
-        return str.toString().substring(start, end);
+        return str.toString().substring(start + offset, end + offset);
     }
 
     public final CharSequence subSequence(int start, int end) {
         try {
             int pos = position();
-            return new StringCharBuffer(str,
+            return new StringCharBuffer(str, -1,
                                         pos + checkIndex(start, pos),
-                                        pos + checkIndex(end, pos));
+                                        pos + checkIndex(end, pos),
+                                        remaining(), offset);
         } catch (IllegalArgumentException x) {
             throw new IndexOutOfBoundsException();
         }
--- a/jdk/src/share/classes/java/util/prefs/Preferences.java	Mon Mar 17 11:53:36 2008 -0700
+++ b/jdk/src/share/classes/java/util/prefs/Preferences.java	Mon Mar 17 12:27:58 2008 -0700
@@ -32,9 +32,8 @@
 import java.security.Permission;
 import java.security.PrivilegedAction;
 import java.util.Iterator;
-import sun.misc.Service;
-import sun.misc.ServiceConfigurationError;
-
+import java.util.ServiceLoader;
+import java.util.ServiceConfigurationError;
 
 // These imports needed only as a workaround for a JavaDoc bug
 import java.lang.RuntimePermission;
@@ -274,12 +273,14 @@
 
     private static PreferencesFactory factory1() {
         // 2. Try service provider interface
-        Iterator i = Service.providers(PreferencesFactory.class,
-                                       ClassLoader.getSystemClassLoader());
+        Iterator<PreferencesFactory> itr = ServiceLoader
+            .load(PreferencesFactory.class, ClassLoader.getSystemClassLoader())
+            .iterator();
+
         // choose first provider instance
-        while (i.hasNext()) {
+        while (itr.hasNext()) {
             try {
-                return (PreferencesFactory) i.next();
+                return itr.next();
             } catch (ServiceConfigurationError sce) {
                 if (sce.getCause() instanceof SecurityException) {
                     // Ignore the security exception, try the next provider
--- a/jdk/src/solaris/native/sun/nio/ch/FileChannelImpl.c	Mon Mar 17 11:53:36 2008 -0700
+++ b/jdk/src/solaris/native/sun/nio/ch/FileChannelImpl.c	Mon Mar 17 12:27:58 2008 -0700
@@ -31,6 +31,7 @@
 #include <sys/stat.h>
 #include "sun_nio_ch_FileChannelImpl.h"
 #include "java_lang_Integer.h"
+#include "java_lang_Long.h"
 #include "nio.h"
 #include "nio_util.h"
 #include <dlfcn.h>
@@ -291,7 +292,11 @@
     struct flock64 fl;
 
     fl.l_whence = SEEK_SET;
-    fl.l_len = (off64_t)size;
+    if (size == (jlong)java_lang_Long_MAX_VALUE) {
+        fl.l_len = (off64_t)0;
+    } else {
+        fl.l_len = (off64_t)size;
+    }
     fl.l_start = (off64_t)pos;
     if (shared == JNI_TRUE) {
         fl.l_type = F_RDLCK;
@@ -325,7 +330,11 @@
     int cmd = F_SETLK64;
 
     fl.l_whence = SEEK_SET;
-    fl.l_len = (off64_t)size;
+    if (size == (jlong)java_lang_Long_MAX_VALUE) {
+        fl.l_len = (off64_t)0;
+    } else {
+        fl.l_len = (off64_t)size;
+    }
     fl.l_start = (off64_t)pos;
     fl.l_type = F_UNLCK;
     lockResult = fcntl(fd, cmd, &fl);
--- a/jdk/test/java/nio/Buffer/StringCharBufferSliceTest.java	Mon Mar 17 11:53:36 2008 -0700
+++ b/jdk/test/java/nio/Buffer/StringCharBufferSliceTest.java	Mon Mar 17 12:27:58 2008 -0700
@@ -53,6 +53,57 @@
         buff = CharBuffer.wrap(in, 3, in.length());
         test(buff, buff.slice());
 
+        System.out.println(
+            ">>> StringCharBufferSliceTest-main: testing slice result with get()");
+        buff.position(4);
+        buff.limit(7);
+        CharBuffer slice = buff.slice();
+        for (int i = 0; i < 3; i++) {
+            if (slice.get() != buff.get()) {
+                throw new RuntimeException("Wrong characters in slice result.");
+            }
+        }
+
+        System.out.println(
+            ">>> StringCharBufferSliceTest-main: testing slice result with get(int)");
+        buff.position(4);
+        buff.limit(7);
+        slice = buff.slice();
+        for (int i = 0; i < 3; i++) {
+            if (slice.get(i) != buff.get(4 + i)) {
+                throw new RuntimeException("Wrong characters in slice result.");
+            }
+        }
+
+        System.out.println(
+          ">>> StringCharBufferSliceTest-main: testing toString.");
+        buff.position(4);
+        buff.limit(7);
+        slice = buff.slice();
+        if (! slice.toString().equals("tes")) {
+            throw new RuntimeException("bad toString() after slice(): " + slice.toString());
+        }
+
+        System.out.println(
+          ">>> StringCharBufferSliceTest-main: testing subSequence.");
+        buff.position(4);
+        buff.limit(8);
+        slice = buff.slice();
+        CharSequence subSeq = slice.subSequence(1, 3);
+        if (subSeq.charAt(0) != 'e' || subSeq.charAt(1) != 's') {
+            throw new RuntimeException("bad subSequence() after slice(): '" + subSeq + "'");
+        }
+
+        System.out.println(
+          ">>> StringCharBufferSliceTest-main: testing duplicate.");
+        buff.position(4);
+        buff.limit(8);
+        slice = buff.slice();
+        CharBuffer dupe = slice.duplicate();
+        if (dupe.charAt(0) != 't' || dupe.charAt(1) != 'e'
+            || dupe.charAt(2) != 's' || dupe.charAt(3) != 't') {
+            throw new RuntimeException("bad duplicate() after slice(): '" + dupe + "'");
+        }
         System.out.println(">>> StringCharBufferSliceTest-main: done!");
     }