src/share/classes/java/nio/X-Buffer.java.template

Print this page

        

@@ -28,10 +28,15 @@
 package java.nio;
 
 #if[char]
 import java.io.IOException;
 #end[char]
+#if[streamableType]
+import java.util.Spliterator;
+import java.util.stream.StreamSupport;
+import java.util.stream.$Streamtype$Stream;
+#end[streamableType]
 
 /**
  * $A$ $type$ buffer.
  *
  * <p> This class defines {#if[byte]?six:four} categories of operations upon

@@ -587,10 +592,23 @@
      *          If <tt>index</tt> is negative
      *          or not smaller than the buffer's limit
      */
     public abstract $type$ get(int index);
 
+#if[streamableType]
+    /**
+     * Absolute <i>get</i> method.  Reads the $type$ at the given
+     * index without any validation of the index.
+     *
+     * @param  index
+     *         The index from which the $type$ will be read
+     *
+     * @return  The $type$ at the given index
+     */
+    abstract $type$ getUnchecked(int index);   // package-private
+#end[streamableType]
+
     /**
      * Absolute <i>put</i> method&nbsp;&nbsp;<i>(optional operation)</i>.
      *
      * <p> Writes the given $type$ into this buffer at the given
      * index. </p>

@@ -1456,6 +1474,18 @@
     // Binary-data access methods  for short, char, int, long, float,
     // and double will be inserted here
 
 #end[byte]
 
+#if[streamableType]
+
+#if[char]
+    @Override
+#end[char]
+    public $Streamtype$Stream $type$s() {
+        return StreamSupport.$streamtype$Stream(() -> new $Type$BufferSpliterator(this),
+            Buffer.SPLITERATOR_CHARACTERISTICS);
+    }
+
+#end[streamableType]
+
 }