Merge
authormullan
Mon, 16 May 2016 13:54:55 -0400
changeset 38325 ff2c8e648ca5
parent 38324 1ecea77815a8 (current diff)
parent 38323 9653a8faa2b9 (diff)
child 38326 9e4be8e12bac
Merge
jdk/src/java.httpclient/share/classes/java/net/http/HttpHeaders1.java
--- a/jdk/src/java.base/share/classes/java/nio/Buffer.java	Mon May 16 13:53:46 2016 -0400
+++ b/jdk/src/java.base/share/classes/java/nio/Buffer.java	Mon May 16 13:54:55 2016 -0400
@@ -111,7 +111,7 @@
  * to zero.
  *
  *
- * <h2> Clearing, flipping, and rewinding </h2>
+ * <h2> Additional operations </h2>
  *
  * <p> In addition to methods for accessing the position, limit, and capacity
  * values and for marking and resetting, this class also defines the following
@@ -131,6 +131,12 @@
  *   it already contains: It leaves the limit unchanged and sets the position
  *   to zero.  </p></li>
  *
+ *   <li><p> {@link #slice} creates a subsequence of a buffer: It leaves the
+ *   limit and the position unchanged. </p></li>
+ *
+ *   <li><p> {@link #duplicate} creates a shallow copy of a buffer: It leaves
+ *   the limit and the position unchanged. </p></li>
+ *
  * </ul>
  *
  *
@@ -567,6 +573,46 @@
      */
     public abstract boolean isDirect();
 
+    /**
+     * Creates a new 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 elements remaining in this buffer, 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 buffer
+     *
+     * @since 9
+     */
+    public abstract Buffer slice();
+
+    /**
+     * Creates a new 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 buffer
+     *
+     * @since 9
+     */
+    public abstract Buffer duplicate();
+
 
     // -- Package-private methods for bounds checking, etc. --
 
--- a/jdk/src/java.base/share/classes/java/nio/X-Buffer.java.template	Mon May 16 13:53:46 2016 -0400
+++ b/jdk/src/java.base/share/classes/java/nio/X-Buffer.java.template	Mon May 16 13:54:55 2016 -0400
@@ -70,8 +70,7 @@
  *
 #end[byte]
  *
- *   <li><p> Methods for {@link #compact compacting}, {@link
- *   #duplicate duplicating}, and {@link #slice slicing}
+ *   <li><p> A method for {@link #compact compacting}
  *   $a$ $type$ buffer.  </p></li>
  *
  * </ul>
@@ -535,6 +534,7 @@
      * @see #alignedSlice(int)
 #end[byte]
      */
+    @Override
     public abstract $Type$Buffer slice();
 
     /**
@@ -557,6 +557,7 @@
      *
      * @return  The new $type$ buffer
      */
+    @Override
     public abstract $Type$Buffer duplicate();
 
     /**
--- a/jdk/src/java.httpclient/share/classes/java/net/http/HttpClientImpl.java	Mon May 16 13:53:46 2016 -0400
+++ b/jdk/src/java.httpclient/share/classes/java/net/http/HttpClientImpl.java	Mon May 16 13:54:55 2016 -0400
@@ -35,6 +35,7 @@
 import java.nio.channels.SelectableChannel;
 import java.nio.channels.SelectionKey;
 import java.nio.channels.Selector;
+import java.nio.channels.SocketChannel;
 import java.security.NoSuchAlgorithmException;
 import java.util.ArrayList;
 import java.util.Iterator;
@@ -155,6 +156,15 @@
         selmgr.register(exchange);
     }
 
+    /**
+     * Only used from RawChannel to disconnect the channel from
+     * the selector
+     */
+    void cancelRegistration(SocketChannel s) {
+        selmgr.cancel(s);
+    }
+
+
     Http2ClientImpl client2() {
         return client2;
     }
@@ -220,6 +230,13 @@
             selector.wakeup();
         }
 
+        synchronized void cancel(SocketChannel e) {
+            SelectionKey key = e.keyFor(selector);
+            if (key != null)
+                key.cancel();
+            selector.wakeup();
+        }
+
         void wakeupSelector() {
             selector.wakeup();
         }
--- a/jdk/src/java.httpclient/share/classes/java/net/http/HttpHeaders1.java	Mon May 16 13:53:46 2016 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,29 +0,0 @@
-/*
- * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- */
-
-package java.net.http;
-
-public interface HttpHeaders1 extends HttpHeaders {
-    public void makeUnmodifiable();
-}
--- a/jdk/src/java.httpclient/share/classes/java/net/http/HttpResponseImpl.java	Mon May 16 13:53:46 2016 -0400
+++ b/jdk/src/java.httpclient/share/classes/java/net/http/HttpResponseImpl.java	Mon May 16 13:54:55 2016 -0400
@@ -176,7 +176,7 @@
      *
      * @return
      */
-    RawChannel rawChannel() {
+    RawChannel rawChannel() throws IOException {
         if (rawchan == null) {
             rawchan = new RawChannel(request.client(), connection);
         }
--- a/jdk/src/java.httpclient/share/classes/java/net/http/RawChannel.java	Mon May 16 13:53:46 2016 -0400
+++ b/jdk/src/java.httpclient/share/classes/java/net/http/RawChannel.java	Mon May 16 13:54:55 2016 -0400
@@ -29,6 +29,7 @@
 import java.nio.channels.GatheringByteChannel;
 import java.nio.channels.SelectableChannel;
 import java.nio.channels.SelectionKey;
+import java.nio.channels.SocketChannel;
 
 //
 // Used to implement WebSocket. Each RawChannel corresponds to a TCP connection
@@ -56,9 +57,21 @@
     interface NonBlockingEvent extends RawEvent {
     }
 
-    RawChannel(HttpClientImpl client, HttpConnection connection) {
+    RawChannel(HttpClientImpl client, HttpConnection connection)
+                                                throws IOException {
         this.client = client;
         this.connection = connection;
+        SocketChannel chan = connection.channel();
+        client.cancelRegistration(chan);
+        chan.configureBlocking(false);
+    }
+
+    SocketChannel socketChannel() {
+        return connection.channel();
+    }
+
+    ByteBuffer getRemaining() {
+        return connection.getRemaining();
     }
 
     private class RawAsyncEvent extends AsyncEvent {
--- a/jdk/src/java.httpclient/share/classes/java/net/http/WSOpeningHandshake.java	Mon May 16 13:53:46 2016 -0400
+++ b/jdk/src/java.httpclient/share/classes/java/net/http/WSOpeningHandshake.java	Mon May 16 13:54:55 2016 -0400
@@ -24,6 +24,8 @@
  */
 package java.net.http;
 
+import java.io.UncheckedIOException;
+import java.io.IOException;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.nio.charset.StandardCharsets;
@@ -126,6 +128,8 @@
                         return CompletableFuture.completedFuture(result);
                     } catch (WebSocketHandshakeException e) {
                         return CompletableFuture.failedFuture(e);
+                    } catch (UncheckedIOException ee) {
+                        return CompletableFuture.failedFuture(ee.getCause());
                     }
                 });
     }
@@ -149,7 +153,12 @@
         checkAccept(response, h);
         checkExtensions(response, h);
         String subprotocol = checkAndReturnSubprotocol(response, h);
-        RawChannel channel = ((HttpResponseImpl) response).rawChannel();
+        RawChannel channel = null;
+        try {
+            channel = ((HttpResponseImpl) response).rawChannel();
+        } catch (IOException e) {
+            throw new UncheckedIOException(e);
+        }
         return new Result(subprotocol, channel);
     }
 
--- a/jdk/test/java/nio/Buffer/Order-X.java.template	Mon May 16 13:53:46 2016 -0400
+++ b/jdk/test/java/nio/Buffer/Order-X.java.template	Mon May 16 13:54:55 2016 -0400
@@ -52,8 +52,5 @@
         buf = $Type$Buffer.allocate(LENGTH);
         ck(buf.order(), nord);
         ck$Type$Buffer(buf, nord);
-
-        ck$Type$Buffer(ByteBuffer.allocate(LENGTH).as$Type$Buffer(), be);
-        ck$Type$Buffer(ByteBuffer.allocateDirect(LENGTH).as$Type$Buffer(), be);
     }
 }
--- a/jdk/test/java/nio/Buffer/Order.java	Mon May 16 13:53:46 2016 -0400
+++ b/jdk/test/java/nio/Buffer/Order.java	Mon May 16 13:54:55 2016 -0400
@@ -51,25 +51,31 @@
         ck(bb.asDoubleBuffer().order(), bb.order());
     }
 
+    private static void ckCopyViews(ByteBuffer bb) {
+        ck(bb.asReadOnlyBuffer().order(), be);
+        ck(bb.duplicate().order(), be);
+        ck(bb.slice().order(), be);
+    }
+
     private static void ckByteBuffer(ByteBuffer bb) {
         ckViews(bb);
+        ckCopyViews(bb);
         bb.order(be);
         ckViews(bb);
+        ckCopyViews(bb);
         bb.order(le);
         ckViews(bb);
-
-        if (bb.hasArray()) {
-            byte[] array = bb.array();
-            ck(ByteBuffer.wrap(array, LENGTH/2, LENGTH/2).order(), be);
-            ck(ByteBuffer.wrap(array).order(), be);
-            ck(bb.asReadOnlyBuffer().order(), be);
-            ck(bb.duplicate().order(), be);
-            ck(bb.slice().order(), be);
-        }
+        ckCopyViews(bb);
     }
 
     public static void main(String args[]) throws Exception {
 
+        ck(ByteBuffer.wrap(new byte[LENGTH], LENGTH/2, LENGTH/2).order(), be);
+        ck(ByteBuffer.wrap(new byte[LENGTH]).order(), be);
+        ck(ByteBuffer.wrap(new byte[LENGTH], LENGTH/2, LENGTH/2).order(be).order(), be);
+        ck(ByteBuffer.wrap(new byte[LENGTH]).order(be).order(), be);
+        ck(ByteBuffer.wrap(new byte[LENGTH], LENGTH/2, LENGTH/2).order(le).order(), le);
+        ck(ByteBuffer.wrap(new byte[LENGTH]).order(le).order(), le);
         ck(ByteBuffer.allocate(LENGTH).order(), be);
         ck(ByteBuffer.allocateDirect(LENGTH).order(), be);
         ck(ByteBuffer.allocate(LENGTH).order(be).order(), be);
--- a/jdk/test/java/nio/Buffer/OrderChar.java	Mon May 16 13:53:46 2016 -0400
+++ b/jdk/test/java/nio/Buffer/OrderChar.java	Mon May 16 13:54:55 2016 -0400
@@ -52,8 +52,5 @@
         buf = CharBuffer.allocate(LENGTH);
         ck(buf.order(), nord);
         ckCharBuffer(buf, nord);
-
-        ckCharBuffer(ByteBuffer.allocate(LENGTH).asCharBuffer(), be);
-        ckCharBuffer(ByteBuffer.allocateDirect(LENGTH).asCharBuffer(), be);
     }
 }
--- a/jdk/test/java/nio/Buffer/OrderDouble.java	Mon May 16 13:53:46 2016 -0400
+++ b/jdk/test/java/nio/Buffer/OrderDouble.java	Mon May 16 13:54:55 2016 -0400
@@ -52,8 +52,5 @@
         buf = DoubleBuffer.allocate(LENGTH);
         ck(buf.order(), nord);
         ckDoubleBuffer(buf, nord);
-
-        ckDoubleBuffer(ByteBuffer.allocate(LENGTH).asDoubleBuffer(), be);
-        ckDoubleBuffer(ByteBuffer.allocateDirect(LENGTH).asDoubleBuffer(), be);
     }
 }
--- a/jdk/test/java/nio/Buffer/OrderFloat.java	Mon May 16 13:53:46 2016 -0400
+++ b/jdk/test/java/nio/Buffer/OrderFloat.java	Mon May 16 13:54:55 2016 -0400
@@ -52,8 +52,5 @@
         buf = FloatBuffer.allocate(LENGTH);
         ck(buf.order(), nord);
         ckFloatBuffer(buf, nord);
-
-        ckFloatBuffer(ByteBuffer.allocate(LENGTH).asFloatBuffer(), be);
-        ckFloatBuffer(ByteBuffer.allocateDirect(LENGTH).asFloatBuffer(), be);
     }
 }
--- a/jdk/test/java/nio/Buffer/OrderInt.java	Mon May 16 13:53:46 2016 -0400
+++ b/jdk/test/java/nio/Buffer/OrderInt.java	Mon May 16 13:54:55 2016 -0400
@@ -52,8 +52,5 @@
         buf = IntBuffer.allocate(LENGTH);
         ck(buf.order(), nord);
         ckIntBuffer(buf, nord);
-
-        ckIntBuffer(ByteBuffer.allocate(LENGTH).asIntBuffer(), be);
-        ckIntBuffer(ByteBuffer.allocateDirect(LENGTH).asIntBuffer(), be);
     }
 }
--- a/jdk/test/java/nio/Buffer/OrderLong.java	Mon May 16 13:53:46 2016 -0400
+++ b/jdk/test/java/nio/Buffer/OrderLong.java	Mon May 16 13:54:55 2016 -0400
@@ -52,8 +52,5 @@
         buf = LongBuffer.allocate(LENGTH);
         ck(buf.order(), nord);
         ckLongBuffer(buf, nord);
-
-        ckLongBuffer(ByteBuffer.allocate(LENGTH).asLongBuffer(), be);
-        ckLongBuffer(ByteBuffer.allocateDirect(LENGTH).asLongBuffer(), be);
     }
 }
--- a/jdk/test/java/nio/Buffer/OrderShort.java	Mon May 16 13:53:46 2016 -0400
+++ b/jdk/test/java/nio/Buffer/OrderShort.java	Mon May 16 13:54:55 2016 -0400
@@ -52,8 +52,5 @@
         buf = ShortBuffer.allocate(LENGTH);
         ck(buf.order(), nord);
         ckShortBuffer(buf, nord);
-
-        ckShortBuffer(ByteBuffer.allocate(LENGTH).asShortBuffer(), be);
-        ckShortBuffer(ByteBuffer.allocateDirect(LENGTH).asShortBuffer(), be);
     }
 }
--- a/jdk/test/javax/net/ssl/ServerName/BestEffortOnLazyConnected.java	Mon May 16 13:53:46 2016 -0400
+++ b/jdk/test/javax/net/ssl/ServerName/BestEffortOnLazyConnected.java	Mon May 16 13:54:55 2016 -0400
@@ -34,9 +34,6 @@
  */
 
 import java.io.*;
-import java.nio.*;
-import java.nio.channels.*;
-import java.util.*;
 import java.net.*;
 import javax.net.ssl.*;
 
@@ -197,6 +194,7 @@
                 hostname);
         // Ignore the test if the hostname does not sound like a domain name.
         if ((hostname == null) || hostname.isEmpty() ||
+                !hostname.contains(".") || hostname.endsWith(".") ||
                 hostname.startsWith("localhost") ||
                 Character.isDigit(hostname.charAt(hostname.length() - 1))) {
 
--- a/jdk/test/sun/net/www/protocol/https/HttpsURLConnection/ImpactOnSNI.java	Mon May 16 13:53:46 2016 -0400
+++ b/jdk/test/sun/net/www/protocol/https/HttpsURLConnection/ImpactOnSNI.java	Mon May 16 13:54:55 2016 -0400
@@ -235,6 +235,7 @@
                 hostname);
         // Ignore the test if the hostname does not sound like a domain name.
         if ((hostname == null) || hostname.isEmpty() ||
+                !hostname.contains(".") || hostname.endsWith(".") ||
                 hostname.startsWith("localhost") ||
                 Character.isDigit(hostname.charAt(hostname.length() - 1))) {